Dialog tutorial:
Part 6 Forwards and Backwards buttons for a HTML viewer
This page adds buttons for
forwards and backwards to the
simple HTML viewer. Note that the home button currently occupies all
the space
across the window; we will add other buttons to this toolbar sizer
- Add a back button by selecting toolsizer
and clicking
. Call the control backbutton. This adds the
button and its event handler to the code
- go to the include file and modify
the code line:
dialog.backbutton_SetLabel ( /* const
wxString& */ wxT( "back" ) );
- goto the bottom of the dialog's cpp
file and find the event handler. Add a line so the handler reads:
void html_vew::OnbackbuttonEvent ( wxCommandEvent &
event )
{
if (m_HtmlWindow -> HistoryCanBack()) m_HtmlWindow
-> HistoryBack();
};
- Compile and run
- If you don't like the order of Home
and Back buttons, use the Dialog Editor window to move them up/down and
recompile
A Bitmap button
- A text button is fine, but you may
like to use Buttons with bitmaps on them. For Forward we will add a
wxBitmapbutton button by selecting toolsizer
and clicking
. Call the control fowardbutton.
- go to the include file and modify
the code to load a bitmap onto the button. One way to do this is shown
below, but you can pass any bitmap using one of wxBitmap's
constructors, eg wxBitmap(const wxString& name, long type) to
load it from a file
/* XPM */
static char * forward_xpm[]
= {
"16 16 5 1",
" c None",
". c
#000000",
"+ c
#C0E4CB",
"@ c
#77C490",
"# c
#808080",
"
",
"
",
"
. ",
"
.. ",
" .+.
",
"
........++. ",
" .+++++++@++. ",
" .@@@@@@@@@++. ",
" .@@@@@@@@@+. ",
" ........@+.# ",
"
#######.+.# ",
" #..# ",
" #.#
",
"
## ",
"
# ",
"
"};
dialog.m_BitmapButton_SetBitmapLabel ( /* const
wxBitmap& */ wxBitmap(forward_xpm));
- goto the bottom of the dialog's cpp
file and find the event handler. Add a line so the handler reads:
void html_vew::OnbackbuttonEvent ( wxCommandEvent &
event )
{
if (m_HtmlWindow -> HistoryCanForward()) m_HtmlWindow
-> HistoryForward();
};
- Compile and run
- You might like to add a button to do
Open File and then use Insert Dialog | wxOpenFile Dialog in
the event handler
- Similarly, try Open URL and use a
text entry dialog to give the user a place to enter the URL
Add HTML help viewer to Text Editor
- Go back to the Text editor, enter its menuzone
and
add a new item to the help menu, eg Own Help
- Double click the replica, and you
will be taken to the event handler. Choose Insert Dialog | Own
Dialog and browse for the .inc file you have been working on. The
include file will be added as the body of the event handler.
- Chose Make | Make clean and then
Make | Make to force a complete recompilation of the project, using the
newly generatre makefile
- Run the program, and compare your
own HTML viewer with the wxWindows version
That's all for now, have
fun with wxHatch!
Back
wxHatch
Home 