]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/mainpages/samples.h
moved the samples in a separate page so it has a summary of all the samples descripti...
[wxWidgets.git] / docs / doxygen / mainpages / samples.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples.h
3 // Purpose: Samples page of the Doxygen manual
4 // Author: wxWidgets team
5 // RCS-ID: $Id: utilities.h 52634 2008-03-20 13:45:17Z VS $
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10
11 @page page_samples Samples supplied with wxWidgets
12
13 Probably the best way to learn wxWidgets is by reading the source of some 70+
14 samples provided with it. Many aspects of wxWidgets programming can be learnt
15 from them, but sometimes it is not simple to just choose the right sample to
16 look at. This overview aims at describing what each sample does/demonstrates to
17 make it easier to find the relevant one if a simple grep through all sources
18 didn't help. They also provide some notes about using the samples and what
19 features of wxWidgets are they supposed to test.
20
21 There are currently more than 50 different samples as part of wxWidgets and
22 this list is not complete. You should start your tour of wxWidgets with the
23 minimal sample which is the wxWidgets version of
24 "Hello, world!". It shows the basic structure of wxWidgets program and is the
25 most commented sample of all - looking at its source code is recommended.
26
27 The next most useful samples are probably widgets
28 and controls which show many of wxWidgets native and
29 generic controls, such as buttons, listboxes, checkboxes, comboboxes etc.
30
31 Other, more complicated controls, have their own samples. In this category you
32 may find the following samples showing the corresponding controls:
33
34 @li wxCalendarCtrl: @ref page_samples_calendar
35 @li wxListCtrl: @ref page_samples_listctrl
36 @li wxTreeCtrl: @ref page_samples_treectrl
37 @li wxGrid: @ref page_samples_grid
38
39 Finally, it might be helpful to do a search in the entire sample directory if
40 you can't find the sample showing the control you are interested in by
41 name. Most classes contained in wxWidgets occur in at least one of the samples.
42
43 @beginInvisibleTable
44 <tr><td>
45 @li @ref page_samples_minimal
46 @li @ref page_samples_animate
47 @li @ref page_samples_artprovider
48 @li @ref page_samples_calendar
49 @li @ref page_samples_config
50 @li @ref page_samples_controls
51 @li @ref page_samples_debugrpt
52 @li @ref page_samples_dialogs
53 @li @ref page_samples_dialup
54 @li @ref page_samples_dnd
55 @li @ref page_samples_event
56 @li @ref page_samples_except
57 @li @ref page_samples_exec
58 @li @ref page_samples_font
59 @li @ref page_samples_grid
60 @li @ref page_samples_html
61 @li @ref page_samples_image
62 </td><td>
63 @li @ref page_samples_internat
64 @li @ref page_samples_layout
65 @li @ref page_samples_listctrl
66 @li @ref page_samples_mediaplayer
67 @li @ref page_samples_notebook
68 @li @ref page_samples_render
69 @li @ref page_samples_scrollsub
70 @li @ref page_samples_sockets
71 @li @ref page_samples_sound
72 @li @ref page_samples_statbar
73 @li @ref page_samples_taborder
74 @li @ref page_samples_text
75 @li @ref page_samples_thread
76 @li @ref page_samples_toolbar
77 @li @ref page_samples_treectrl
78 @li @ref page_samples_widgets
79 @li @ref page_samples_wizard
80 </td></tr>
81 @endTable
82
83
84 <hr>
85
86
87
88 @section page_samples_minimal Minimal sample
89
90 The minimal sample is what most people will know under the term Hello World,
91 i.e. a minimal program that doesn't demonstrate anything apart from what is
92 needed to write a program that will display a "hello" dialog. This is usually
93 a good starting point for learning how to use wxWidgets.
94
95
96 @section page_samples_animate Animate sample
97
98 The @c animate sample shows how you can use wxAnimationCtrl
99 control and shows concept of a platform-dependent animation encapsulated
100 in wxAnimation.
101
102
103 @section page_samples_artprovider Art provider sample
104
105 The @c artprov sample shows how you can customize the look of standard
106 wxWidgets dialogs by replacing default bitmaps/icons with your own versions.
107 It also shows how you can use wxArtProvider to
108 get stock bitmaps for use in your application.
109
110
111 @section page_samples_calendar Calendar sample
112
113 This font shows the calendar control in action. It
114 shows how to configure the control (see the different options in the calendar
115 menu) and also how to process the notifications from it.
116
117
118 @section page_samples_config Config sample
119
120 This sample demonstrates the wxConfig classes in a platform
121 independent way, i.e. it uses text based files to store a given configuration under
122 Unix and uses the Registry under Windows.
123
124 See @ref overview_config for the descriptions of all features of this class.
125
126
127 @section page_samples_controls Controls sample
128
129 The controls sample is the main test program for most simple controls used in
130 wxWidgets. The sample tests their basic functionality, events, placement,
131 modification in terms of colour and font as well as the possibility to change
132 the controls programmatically, such as adding an item to a list box etc. Apart
133 from that, the sample uses a wxNotebook and tests most
134 features of this special control (using bitmap in the tabs, using
135 wxSizer instances and wxLayoutConstraints within notebook pages, advancing pages
136 programmatically and vetoing a page change by intercepting the wxNotebookEvent.
137
138 The various controls tested are listed here:
139
140 @li wxButton
141 @li wxBitmapButton
142 @li wxCheckBox
143 @li wxChoice
144 @li wxComboBox
145 @li wxGauge
146 @li wxStaticBox
147 @li wxListBox
148 @li wxSpinCtrl
149 @li wxSpinButton
150 @li wxStaticText
151 @li wxStaticBitmap
152 @li wxRadioBox
153 @li wxRadioButton
154 @li wxSlider
155
156
157 @section page_samples_debugrpt DebugRpt sample
158
159 This sample shows how to use wxDebugReport class to
160 generate a debug report in case of a program crash or otherwise. On start up,
161 it proposes to either crash itself (by dereferencing a NULL pointer) or
162 generate debug report without doing it. Next it initializes the debug report
163 with standard information adding a custom file to it (just a timestamp) and
164 allows to view the information gathered using
165 wxDebugReportPreview.
166
167 For the report processing part of the sample to work you should make available
168 a Web server accepting form uploads, otherwise
169 wxDebugReportUpload will report an error.
170
171
172 @section page_samples_dialogs Dialogs sample
173
174 This sample shows how to use the common dialogs available from wxWidgets. These
175 dialogs are described in detail in the @ref overview_cmndlg.
176
177
178 @section page_samples_dialup Dialup sample
179
180 This sample shows the wxDialUpManager
181 class. In the status bar, it displays the information gathered through its
182 interface: in particular, the current connection status (online or offline) and
183 whether the connection is permanent (in which case a string `LAN' appears in
184 the third status bar field - but note that you may be on a LAN not
185 connected to the Internet, in which case you will not see this) or not.
186
187 Using the menu entries, you may also dial or hang up the line if you have a
188 modem attached and (this only makes sense for Windows) list the available
189 connections.
190
191
192 @section page_samples_dnd DnD sample
193
194 This sample shows both clipboard and drag and drop in action. It is quite non
195 trivial and may be safely used as a basis for implementing the clipboard and
196 drag and drop operations in a real-life program.
197
198 When you run the sample, its screen is split in several parts. On the top,
199 there are two listboxes which show the standard derivations of
200 wxDropTarget:
201 wxTextDropTarget and
202 wxFileDropTarget.
203
204 The middle of the sample window is taken by the log window which shows what is
205 going on (of course, this only works in debug builds) and may be helpful to see
206 the sequence of steps of data transfer.
207
208 Finally, the last part is used for dragging text from it to either one of the
209 listboxes (only one will accept it) or another application. The last
210 functionality available from the main frame is to paste a bitmap from the
211 clipboard (or, in the case of the Windows version, also a metafile) - it will be
212 shown in a new frame.
213
214 So far, everything we mentioned was implemented with minimal amount of code
215 using standard wxWidgets classes. The more advanced features are demonstrated
216 if you create a shape frame from the main frame menu. A shape is a geometric
217 object which has a position, size and color. It models some
218 application-specific data in this sample. A shape object supports its own
219 private wxDataFormat which means that you may cut and
220 paste it or drag and drop (between one and the same or different shapes) from
221 one sample instance to another (or the same). However, chances are that no
222 other program supports this format and so shapes can also be rendered as
223 bitmaps which allows them to be pasted/dropped in many other applications
224 (and, under Windows, also as metafiles which are supported by most of Windows
225 programs as well - try Write/Wordpad, for example).
226
227 Take a look at DnDShapeDataObject class to see how you may use
228 wxDataObject to achieve this.
229
230
231 @section page_samples_event Event sample
232
233 The event sample demonstrates various features of the wxWidgets events. It
234 shows using dynamic events and connecting/disconnecting the event handlers
235 during run time and also using
236 PushEventHandler() and
237 PopEventHandler().
238
239
240 @section page_samples_except Except(ions) sample
241
242 This very simple sample shows how to use C++ exceptions in wxWidgets programs,
243 i.e. where to catch the exception which may be thrown by the program code. It
244 doesn't do anything very exciting by itself, you need to study its code to
245 understand what goes on.
246
247 You need to build the library with @c wxUSE_EXCEPTIONS being set to @c 1
248 and compile your code with C++ exceptions support to be able to build this
249 sample.
250
251
252 @section page_samples_exec Exec sample
253
254 The exec sample demonstrates the wxExecute and
255 wxShell functions. Both of them are used to execute the
256 external programs and the sample shows how to do this synchronously (waiting
257 until the program terminates) or asynchronously (notification will come later).
258
259 It also shows how to capture the output of the child process in both
260 synchronous and asynchronous cases and how to kill the processes with
261 wxProcess::Kill and test for their existence with
262 wxProcess::Exists.
263
264
265 @section page_samples_font Font sample
266
267 The font sample demonstrates wxFont,
268 wxFontEnumerator and
269 wxFontMapper classes. It allows you to see the fonts
270 available (to wxWidgets) on the computer and shows all characters of the
271 chosen font as well.
272
273
274 @section page_samples_grid Grid sample
275
276 @todo WRITE THIS DESCRIPTION.
277
278
279 @section page_samples_html HTML samples
280
281 Eight HTML samples (you can find them in directory @c samples/html)
282 cover all features of the HTML sub-library.
283
284 @li @b Test demonstrates how to create wxHtmlWindow
285 and also shows most supported HTML tags.
286
287 @li @b Widget shows how you can embed ordinary controls or windows within an
288 HTML page. It also nicely explains how to write new tag handlers and extend
289 the library to work with unsupported tags.
290
291 @li @b About may give you an idea how to write good-looking About boxes.
292
293 @li @b Zip demonstrates use of virtual file systems in wxHTML. The zip archives
294 handler (ships with wxWidgets) allows you to access HTML pages stored
295 in a compressed archive as if they were ordinary files.
296
297 @li @b Virtual is yet another virtual file systems demo. This one generates pages at run-time.
298 You may find it useful if you need to display some reports in your application.
299
300 @li @b Printing explains use of wxHtmlEasyPrinting
301 class which serves as as-simple-as-possible interface for printing HTML
302 documents without much work. In fact, only few function calls are sufficient.
303
304 @li @b Help and @b Helpview are variations on displaying HTML help
305 (compatible with MS HTML Help Workshop). @e Help shows how to embed
306 wxHtmlHelpController in your application
307 while @e Helpview is a simple tool that only pops up the help window and
308 displays help books given at command line.
309
310
311 @section page_samples_image Image sample
312
313 The image sample demonstrates use of the wxImage class
314 and shows how to download images in a variety of formats, currently PNG, GIF,
315 TIFF, JPEG, BMP, PNM and PCX. The top of the sample shows two rectangles, one
316 of which is drawn directly in the window, the other one is drawn into a
317 wxBitmap, converted to a wxImage, saved as a PNG image
318 and then reloaded from the PNG file again so that conversions between wxImage
319 and wxBitmap as well as loading and saving PNG files are tested.
320
321 At the bottom of the main frame there is a test for using a monochrome bitmap by
322 drawing into a wxMemoryDC. The bitmap is then drawn
323 specifying the foreground and background colours with
324 wxDC::SetTextForeground and
325 wxDC::SetTextBackground (on the left). The
326 bitmap is then converted to a wxImage and the foreground colour (black) is
327 replaced with red using wxImage::Replace.
328
329 This sample also contains the code for testing the image rotation and resizing
330 and using raw bitmap access, see the corresponding menu commands.
331
332
333 @section page_samples_internat Internat(ionalization) sample
334
335 The not very clearly named internat sample demonstrates the wxWidgets
336 internationalization (i18n for short from now on) features. To be more
337 precise, it only shows localization support, i.e. support for translating the
338 program messages into another language while true i18n would also involve
339 changing the other aspects of the programs behaviour.
340
341 More information about this sample can be found in the @c readme.txt file in
342 its directory. Please also see the @ref overview_i18n.
343
344
345 @section page_samples_layout Layout sample
346
347 The layout sample demonstrates the two different layout systems offered
348 by wxWidgets. When starting the program, you will see a frame with some
349 controls and some graphics. The controls will change their size whenever
350 you resize the entire frame and the exact behaviour of the size changes
351 is determined using the wxLayoutConstraints
352 class. See also the overview and the
353 wxIndividualLayoutConstraint
354 class for further information.
355
356 The menu in this sample offers two more tests, one showing how to use
357 a wxBoxSizer in a simple dialog and the other one
358 showing how to use sizers in connection with a wxNotebook
359 class. See also wxSizer.
360
361
362 @section page_samples_listctrl Listctrl sample
363
364 This sample shows the wxListCtrl control. Different modes
365 supported by the control (list, icons, small icons, report) may be chosen from
366 the menu.
367
368 The sample also provides some timings for adding/deleting/sorting a lot of
369 (several thousands) items into the control.
370
371
372 @section page_samples_mediaplayer Mediaplayer sample
373
374 This sample demonstrates how to use all the features of
375 wxMediaCtrl and play various types of sound, video,
376 and other files.
377
378 It replaces the old dynamic sample.
379
380
381 @section page_samples_notebook Notebook sample
382
383 This samples shows wxBookCtrl family of controls.
384 Although initially it was written to demonstrate wxNotebook
385 only, it can now be also used to see wxListbook,
386 wxChoicebook and wxTreebook in action.
387 Test each of the controls, their orientation, images and pages using
388 commands through menu.
389
390
391 @section page_samples_render Render sample
392
393 This sample shows how to replace the default wxWidgets
394 renderer and also how to write a shared library
395 (DLL) implementing a renderer and load and unload it during the run-time.
396
397
398 @section page_samples_scrollsub Scroll subwindow sample
399
400 This sample demonstrates use of the wxScrolledWindow
401 class including placing subwindows into it and drawing simple graphics. It uses the
402 SetTargetWindow method and thus the effect
403 of scrolling does not show in the scrolled window itself, but in one of its subwindows.
404
405 Additionally, this samples demonstrates how to optimize drawing operations in wxWidgets,
406 in particular using the wxWindow::IsExposed method with
407 the aim to prevent unnecessary drawing in the window and thus reducing or removing
408 flicker on screen.
409
410
411 @section page_samples_sockets Sockets sample
412
413 The sockets sample demonstrates how to use the communication facilities
414 provided by wxSocket. There are two different
415 applications in this sample: a server, which is implemented using a
416 wxSocketServer object, and a client, which
417 is implemented as a wxSocketClient.
418
419 The server binds to the local address, using TCP port number 3000,
420 sets up an event handler to be notified of incoming connection requests
421 (@b wxSOCKET_CONNECTION events), and sits there, waiting for clients
422 (@e listening, in socket parlance). For each accepted connection,
423 a new wxSocketBase object is created. These
424 socket objects are independent from the server that created them, so
425 they set up their own event handler, and then request to be notified
426 of @b wxSOCKET_INPUT (incoming data) or @b wxSOCKET_LOST
427 (connection closed at the remote end) events. In the sample, the event
428 handler is the same for all connections; to find out which socket the
429 event is addressed to, the GetSocket function
430 is used.
431
432 Although it might take some time to get used to the event-oriented
433 system upon which wxSocket is built, the benefits are many. See, for
434 example, that the server application, while being single-threaded
435 (and of course without using fork() or ugly select() loops) can handle
436 an arbitrary number of connections.
437
438 The client starts up unconnected, so you can use the Connect... option
439 to specify the address of the server you are going to connect to (the
440 TCP port number is hard-coded as 3000). Once connected, a number of
441 tests are possible. Currently, three tests are implemented. They show
442 how to use the basic IO calls in wxSocketBase,
443 such as wxSocketBase::Read, wxSocketBase::Write,
444 wxSocketBase::ReadMsg and wxSocketBase::WriteMsg,
445 and how to set up the correct IO flags depending on what you are going to
446 do. See the comments in the code for more information. Note that because
447 both clients and connection objects in the server set up an event handler
448 to catch @b wxSOCKET_LOST events, each one is immediately notified
449 if the other end closes the connection.
450
451 There is also a URL test which shows how to use
452 the wxURL class to fetch data from a given URL.
453
454 The sockets sample is work in progress. Some things to do:
455
456 @li More tests for basic socket functionality.
457 @li More tests for protocol classes (wxProtocol and its descendants).
458 @li Tests for the recently added (and still in alpha stage) datagram sockets.
459 @li New samples which actually do something useful (suggestions accepted).
460
461
462 @section page_samples_sound Sound sample
463
464 The @c sound sample shows how to use wxSound for simple
465 audio output (e.g. notifications).
466
467
468 @section page_samples_statbar Statbar sample
469
470 This sample shows how to create and use wxStatusBar. Although most of the
471 samples have a statusbar, they usually only create a default one and only
472 do it once.
473
474 Here you can see how to recreate the statusbar (with possibly different number
475 of fields) and how to use it to show icons/bitmaps and/or put arbitrary
476 controls into it.
477
478
479 @section page_samples_taborder Tab order sample
480
481 This sample allows to test keyboard navigation (mostly done using the
482 @c TAB key, hence the sample name) between different controls.
483 It shows the use of wxWindow::MoveBeforeInTabOrder() and
484 MoveAfterInTabOrder() methods to change
485 the default order of the windows in the navigation chain and of
486 wxWindow::Navigate() for moving focus along this
487 chain.
488
489
490 @section page_samples_text Text sample
491
492 This sample demonstrates four features: firstly the use and many variants of
493 the wxTextCtrl class (single line, multi line, read only,
494 password, ignoring TAB, ignoring ENTER).
495
496 Secondly it shows how to intercept a wxKeyEvent in both
497 the raw form using the @c EVT_KEY_UP and @c EVT_KEY_DOWN macros and the
498 higher level from using the @c EVT_CHAR macro. All characters will be logged
499 in a log window at the bottom of the main window. By pressing some of the function
500 keys, you can test some actions in the text ctrl as well as get statistics on the
501 text ctrls, which is useful for testing if these statistics actually are correct.
502
503 Thirdly, on platforms which support it, the sample will offer to copy text to the
504 wxClipboard and to paste text from it. The GTK version will
505 use the so called PRIMARY SELECTION, which is the pseudo clipboard under X and
506 best known from pasting text to the XTerm program.
507
508 Last not least: some of the text controls have tooltips and the sample also shows
509 how tooltips can be centrally disabled and their latency controlled.
510
511
512 @section page_samples_thread Thread sample
513
514 This sample demonstrates use of threads in connection with GUI programs.
515 There are two fundamentally different ways to use threads in GUI programs and
516 either way has to take care of the fact that the GUI library itself usually
517 is not multi-threading safe, i.e. that it might crash if two threads try to
518 access the GUI class simultaneously. One way to prevent that is have a normal
519 GUI program in the main thread and some worker threads which work in the
520 background. In order to make communication between the main thread and the
521 worker threads possible, wxWidgets offers the wxPostEvent
522 function and this sample makes use of this function.
523
524 The other way to use a so called Mutex (such as those offered in the wxMutex
525 class) that prevent threads from accessing the GUI classes as long as any other
526 thread accesses them. For this, wxWidgets has the wxMutexGuiEnter
527 and wxMutexGuiLeave functions, both of which are
528 used and tested in the sample as well.
529
530 See also @ref overview_thread and wxThread.
531
532
533 @section page_samples_toolbar Toolbar sample
534
535 The toolbar sample shows the wxToolBar class in action.
536
537 The following things are demonstrated:
538
539 @li Creating the toolbar using wxToolBar::AddTool and wxToolBar::AddControl: see
540 MyApp::InitToolbar in the sample.
541 @li Using @c EVT_UPDATE_UI handler for automatically enabling/disabling
542 toolbar buttons without having to explicitly call EnableTool. This is done
543 in MyFrame::OnUpdateCopyAndCut.
544 @li Using wxToolBar::DeleteTool and wxToolBar::InsertTool to dynamically update the
545 toolbar.
546
547 Some buttons in the main toolbar are check buttons, i.e. they stay checked when
548 pressed. On the platforms which support it, the sample also adds a combobox
549 to the toolbar showing how you can use arbitrary controls and not only buttons
550 in it.
551
552 If you toggle another toolbar in the sample (using @c Ctrl-A) you will also
553 see the radio toolbar buttons in action: the first three buttons form a radio
554 group, i.e. checking any of them automatically unchecks the previously
555 checked one.
556
557
558 @section page_samples_treectrl Treectrl sample
559
560 This sample demonstrates using the wxTreeCtrl class. Here
561 you may see how to process various notification messages sent by this control
562 and also when they occur (by looking at the messages in the text control in
563 the bottom part of the frame).
564
565 Adding, inserting and deleting items and branches from the tree as well as
566 sorting (in default alphabetical order as well as in custom one) is
567 demonstrated here as well - try the corresponding menu entries.
568
569
570 @section page_samples_widgets Widgets sample
571
572 The widgets sample is the main presentation program for most simple and advanced
573 native controls and complex generic widgets provided by wxWidgets.
574 The sample tests their basic functionality, events, placement, modification
575 in terms of colour and font as well as the possibility to change
576 the controls programmatically, such as adding an item to a list box etc.
577 All widgets are categorized for easy browsing.
578
579
580 @section page_samples_wizard Wizard sample
581
582 This sample shows the so-called wizard dialog (implemented using
583 wxWizard and related classes). It shows almost all
584 features supported:
585
586 @li Using bitmaps with the wizard and changing them depending on the page
587 shown (notice that wxValidationPage in the sample has a different image from
588 the other ones)
589 @li Using TransferDataFromWindow
590 to verify that the data entered is correct before passing to the next page
591 (done in wxValidationPage which forces the user to check a checkbox before
592 continuing).
593 @li Using more elaborated techniques to allow returning to the previous
594 page, but not continuing to the next one or vice versa (in wxRadioboxPage)
595 @li This (wxRadioboxPage) page also shows how the page may process the
596 @e Cancel button itself instead of relying on the wizard parent to do it.
597 @li Normally, the order of the pages in the wizard is known at compile-time,
598 but sometimes it depends on the user choices: wxCheckboxPage shows how to
599 dynamically decide which page to display next (see also
600 wxWizardPage)
601
602 */