]>
git.saurik.com Git - wxWidgets.git/blob - samples/htlbox/htlbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: HtmlLbox wxWindows sample
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers)
36 #include "wx/msgdlg.h"
37 #include "wx/textctrl.h"
42 #include "wx/htmllbox.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // the application icon (under Windows and OS/2 it is in resources)
49 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
50 #include "mondrian.xpm"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 class MyApp
: public wxApp
60 virtual bool OnInit();
63 class MyFrame
: public wxFrame
70 void OnQuit(wxCommandEvent
& event
);
71 void OnAbout(wxCommandEvent
& event
);
73 void OnLboxSelect(wxCommandEvent
& event
)
75 wxLogMessage(_T("Listbox selection is now %ld."), event
.GetInt());
78 void OnLboxDClick(wxCommandEvent
& event
)
80 wxLogMessage(_T("Listbox item %ld double clicked."), event
.GetInt());
84 // any class wishing to process wxWindows events must use this macro
88 // to use wxHtmlListBox you must derive a new class from it as you must
89 // implement pure virtual OnGetItem()
90 class MyHtmlListBox
: public wxHtmlListBox
93 MyHtmlListBox(wxWindow
*parent
) : wxHtmlListBox(parent
)
101 virtual wxString
OnGetItem(size_t n
) const
103 int level
= n
% 6 + 1;
104 return wxString::Format(_T("<h%d><font color=#%2x%2x%2x>")
105 _T("Item</font> <b>%lu</b>")
111 (unsigned long)n
, level
);
114 virtual void OnDrawSeparator(wxDC
& dc
,
116 size_t WXUNUSED(n
)) const
118 dc
.SetPen(*wxBLACK_DASHED_PEN
);
119 dc
.DrawLine(rect
.x
, rect
.y
, rect
.GetRight(), rect
.y
);
120 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight(), rect
.GetBottom());
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 // IDs for the controls and the menu commands
135 // it is important for the id corresponding to the "About" command to have
136 // this standard value as otherwise it won't be handled properly under Mac
137 // (where it is special and put into the "Apple" menu)
138 HtmlLbox_About
= wxID_ABOUT
141 // ----------------------------------------------------------------------------
142 // event tables and other macros for wxWindows
143 // ----------------------------------------------------------------------------
145 // the event tables connect the wxWindows events with the functions (event
146 // handlers) which process them. It can be also done at run-time, but for the
147 // simple menu events like this the static method is much simpler.
148 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
149 EVT_MENU(HtmlLbox_Quit
, MyFrame::OnQuit
)
150 EVT_MENU(HtmlLbox_About
, MyFrame::OnAbout
)
152 EVT_LISTBOX(wxID_ANY
, MyFrame::OnLboxSelect
)
153 EVT_LISTBOX_DCLICK(wxID_ANY
, MyFrame::OnLboxDClick
)
156 // Create a new application object: this macro will allow wxWindows to create
157 // the application object during program execution (it's better than using a
158 // static object for many reasons) and also declares the accessor function
159 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
163 // ============================================================================
165 // ============================================================================
167 // ----------------------------------------------------------------------------
168 // the application class
169 // ----------------------------------------------------------------------------
171 // 'Main program' equivalent: the program execution "starts" here
174 (new MyFrame())->Show();
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
185 : wxFrame(NULL
, -1, _T("HtmlLbox wxWindows Sample"),
186 wxDefaultPosition
, wxSize(400, 500))
188 // set the frame icon
189 SetIcon(wxICON(mondrian
));
193 wxMenu
*menuFile
= new wxMenu
;
195 // the "About" item should be in the help menu
196 wxMenu
*helpMenu
= new wxMenu
;
197 helpMenu
->Append(HtmlLbox_About
, _T("&About...\tF1"), _T("Show about dialog"));
199 menuFile
->Append(HtmlLbox_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
201 // now append the freshly created menu to the menu bar...
202 wxMenuBar
*menuBar
= new wxMenuBar();
203 menuBar
->Append(menuFile
, _T("&File"));
204 menuBar
->Append(helpMenu
, _T("&Help"));
206 // ... and attach this menu bar to the frame
208 #endif // wxUSE_MENUS
211 // create a status bar just for fun (by default with 1 pane only)
213 SetStatusText(_T("Welcome to wxWindows!"));
214 #endif // wxUSE_STATUSBAR
216 // create the child controls
217 MyHtmlListBox
*hlbox
= new MyHtmlListBox(this);
218 wxTextCtrl
*text
= new wxTextCtrl(this, -1, _T(""),
219 wxDefaultPosition
, wxDefaultSize
,
221 delete wxLog::SetActiveTarget(new wxLogTextCtrl(text
));
224 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
225 sizer
->Add(hlbox
, 1, wxGROW
);
226 sizer
->Add(text
, 1, wxGROW
);
233 delete wxLog::SetActiveTarget(NULL
);
237 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
239 // TRUE is to force the frame to close
243 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
245 wxMessageBox(_T("This sample shows wxHtmlListBox class.\n")
247 _T("© 2003 Vadim Zeitlin"),
248 _T("About HtmlLbox"),
249 wxOK
| wxICON_INFORMATION
,