]>
git.saurik.com Git - wxWidgets.git/blob - samples/htlbox/htlbox.cpp
5c2d7dae6979c54a12a55bb71094071a24a224f4
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)
35 #include "wx/htmllbox.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // the application icon (under Windows and OS/2 it is in resources)
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
43 #include "mondrian.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 class MyApp
: public wxApp
53 virtual bool OnInit();
56 class MyFrame
: public wxFrame
63 void OnQuit(wxCommandEvent
& event
);
64 void OnAbout(wxCommandEvent
& event
);
66 void OnLboxSelect(wxCommandEvent
& event
)
68 wxLogMessage(_T("Listbox selection is now %d."), event
.GetInt());
71 void OnLboxDClick(wxCommandEvent
& event
)
73 wxLogMessage(_T("Listbox item %d double clicked."), event
.GetInt());
77 // any class wishing to process wxWindows events must use this macro
81 // to use wxHtmlListBox you must derive a new class from it as you must
82 // implement pure virtual OnGetItem()
83 class MyHtmlListBox
: public wxHtmlListBox
86 MyHtmlListBox(wxWindow
*parent
) : wxHtmlListBox(parent
)
94 virtual wxString
OnGetItem(size_t n
) const
96 int level
= n
% 6 + 1;
97 return wxString::Format(_T("<h%d><font color=#%2x%2x%2x>")
98 _T("Item</font> <b>%lu</b>")
104 (unsigned long)n
, level
);
107 virtual void OnDrawSeparator(wxDC
& dc
,
109 size_t WXUNUSED(n
)) const
111 dc
.SetPen(*wxBLACK_DASHED_PEN
);
112 dc
.DrawLine(rect
.x
, rect
.y
, rect
.GetRight(), rect
.y
);
113 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight(), rect
.GetBottom());
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 // IDs for the controls and the menu commands
128 // it is important for the id corresponding to the "About" command to have
129 // this standard value as otherwise it won't be handled properly under Mac
130 // (where it is special and put into the "Apple" menu)
131 HtmlLbox_About
= wxID_ABOUT
134 // ----------------------------------------------------------------------------
135 // event tables and other macros for wxWindows
136 // ----------------------------------------------------------------------------
138 // the event tables connect the wxWindows events with the functions (event
139 // handlers) which process them. It can be also done at run-time, but for the
140 // simple menu events like this the static method is much simpler.
141 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
142 EVT_MENU(HtmlLbox_Quit
, MyFrame::OnQuit
)
143 EVT_MENU(HtmlLbox_About
, MyFrame::OnAbout
)
145 EVT_LISTBOX(wxID_ANY
, MyFrame::OnLboxSelect
)
146 EVT_LISTBOX_DCLICK(wxID_ANY
, MyFrame::OnLboxDClick
)
149 // Create a new application object: this macro will allow wxWindows to create
150 // the application object during program execution (it's better than using a
151 // static object for many reasons) and also declares the accessor function
152 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
156 // ============================================================================
158 // ============================================================================
160 // ----------------------------------------------------------------------------
161 // the application class
162 // ----------------------------------------------------------------------------
164 // 'Main program' equivalent: the program execution "starts" here
167 (new MyFrame())->Show();
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
178 : wxFrame(NULL
, -1, _T("HtmlLbox wxWindows Sample"),
179 wxDefaultPosition
, wxSize(400, 500))
181 // set the frame icon
182 SetIcon(wxICON(mondrian
));
186 wxMenu
*menuFile
= new wxMenu
;
188 // the "About" item should be in the help menu
189 wxMenu
*helpMenu
= new wxMenu
;
190 helpMenu
->Append(HtmlLbox_About
, _T("&About...\tF1"), _T("Show about dialog"));
192 menuFile
->Append(HtmlLbox_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
194 // now append the freshly created menu to the menu bar...
195 wxMenuBar
*menuBar
= new wxMenuBar();
196 menuBar
->Append(menuFile
, _T("&File"));
197 menuBar
->Append(helpMenu
, _T("&Help"));
199 // ... and attach this menu bar to the frame
201 #endif // wxUSE_MENUS
204 // create a status bar just for fun (by default with 1 pane only)
206 SetStatusText(_T("Welcome to wxWindows!"));
207 #endif // wxUSE_STATUSBAR
209 // create the child controls
210 MyHtmlListBox
*hlbox
= new MyHtmlListBox(this);
211 wxTextCtrl
*text
= new wxTextCtrl(this, -1, _T(""),
212 wxDefaultPosition
, wxDefaultSize
,
214 delete wxLog::SetActiveTarget(new wxLogTextCtrl(text
));
217 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
218 sizer
->Add(hlbox
, 1, wxGROW
);
219 sizer
->Add(text
, 1, wxGROW
);
226 delete wxLog::SetActiveTarget(NULL
);
230 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
232 // TRUE is to force the frame to close
236 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
238 wxMessageBox(_T("This sample shows wxHtmlListBox class.\n")
240 _T("© 2003 Vadim Zeitlin"),
241 _T("About HtmlLbox"),
242 wxOK
| wxICON_INFORMATION
,