]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/tsamples.tex
1. fixed small bug with toolbar size updates
[wxWidgets.git] / docs / latex / wx / tsamples.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% Name: tsamples.tex
3 %% Purpose: Samples description
4 %% Author: Vadim Zeitlin
5 %% Modified by:
6 %% Created: 02.11.99
7 %% RCS-ID: $Id$
8 %% Copyright: (c) wxWindows team
9 %% Licence: wxWindows licence
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{wxWindows samples}\label{samples}
13
14 Probably the best way to learn wxWindows is by reading the source of some 50+
15 samples provided with it. Many aspects of wxWindows programming can be learnt
16 from them, but sometimes it is not simple to just choose the right sample to
17 look at. This overview aims at describing what each sample does/demonstrates to
18 make it easier to find the relevant one if a simple grep through all sources
19 didn't help. They also provide some notes about using the samples and what
20 features of wxWindows are they supposed to test.
21
22 There are currently more than 50 different samples as part of wxWindows and
23 this list is not complete.
24
25 \subsection{Minimal sample}\label{sampleminimal}
26
27 The minimal sample is what most people will know under the term Hello World,
28 i.e. a minimal program that doesn't demonstrate anything apart from what is
29 needed to write a program that will display a "hello" dialog. This is usually
30 a good starting point for learning how to use wxWindows.
31
32 \subsection{Calendar sample}\label{samplecalendar}
33
34 This font shows the \helpref{calendar control}{wxcalendarctrl} in action. It
35 shows how to configure the control (see the different options in the calendar
36 menu) and also how to process the notifications from it.
37
38 \subsection{Checklist sample}\label{samplechecklist}
39
40 This sample demonstrates the use of the \helpref{wxCheckListBox}{wxchecklistbox}
41 class intercepting check, select and double click events. It also tests the
42 use of various methods modifiying the control, such as by deleting items
43 from it or inserting new once (these fucntions are actually implememted in
44 the parent class \helpref{wxListBox}{wxlistbox} so the sample tests that class
45 as well). The layout of the dialog is created using a \helpref{wxBoxSizer}{wxboxsizer}
46 demonstrating a simple dynamic layout.
47
48 \subsection{Config sample}\label{sampleconfig}
49
50 This sample demonstrates the \helpref{wxConfig}{wxconfigbase} classes in a platform
51 indepedent way, i.e. it uses text based files to store a given configuration under
52 Unix and uses the Registry under Windows.
53
54 See \helpref{wxConfig overview}{wxconfigoverview} for the descriptions of all
55 features of this class.
56
57 \subsection{Dialogs sample}\label{sampledialogs}
58
59 This sample shows how to use the common dialogs available from wxWindows. These
60 dialogs are desrcibed in details in the \helpref{Common dialogs overview}{commondialogsoverview}.
61
62 \subsection{Dynamic sample}\label{sampledynamic}
63
64 This sample is a very small sample that demonstrates the use of the
65 \helpref{wxEvtHandler::Connect}{wxevthandlerconnect} method. This method
66 should be used whenever it is not known at compile time, which control
67 will receive which event or which controls are actually going to be in
68 a dialog or frame. This is most typically the case for any scripting
69 languge that would work as a wrapper for wxWindows or programs where
70 forms or similar datagrams can be created by the uses.
71
72 \subsection{Exec sample}\label{sampleexec}
73
74 The exec sample demonstrates the \helpref{wxExecute}{wxexecute} and
75 \helpref{wxShell}{wxshell} functions. Both of them are used to execute the
76 external programs and the sample shows how to do this synchronously (waiting
77 until the program terminates) or asynchronously (notification will come later).
78
79 \subsection{Scroll subwindow sample}\label{samplescrollsub}
80
81 This sample demonstrates the use of the \helpref{wxScrolledWindow}{wxscrolledwindow}
82 class including placing subwindows into it and drawing simple graphics. It uses the
83 \helpref{SetTargetWindow}{wxscrolledwindowsettargetwindow} method and thus the effect
84 of scrolling does not show in the scrolled window itself, but in one of its subwindows.
85
86 Additionally, this samples demonstrates how to optimize drawing operations in wxWindows,
87 in particular using the \helpref{wxWindow::IsExposed}{wxwindowisexposed} method with
88 the aim to prevent unnecessary drawing in the window and thus reducing or removing
89 flicker on screen.
90
91 \subsection{Font sample}\label{samplefont}
92
93 The font sample demonstrates \helpref{wxFont}{wxfont},
94 \helpref{wxFontEnumerator}{wxfontenumerator} and
95 \helpref{wxFontMapper}{wxfontmapper} classes. It allows you to see the fonts
96 available (to wxWindows) on the computer and shows all characters of the
97 chosen font as well.
98
99 \subsection{DnD sample}\label{samplednd}
100
101 This sample shows both clipboard and drag and drop in action. It is quite non
102 trivial and may be safely used as a basis for implementing the clipboard and
103 drag and drop operations in a real-life program.
104
105 When you run the sample, its screen is split in several parts. On the top,
106 there are two listboxes which show the standard derivations of
107 \helpref{wxDropTarget}{wxdroptarget}:
108 \helpref{wxTextDropTarget}{wxtextdroptarget} and
109 \helpref{wxFileDropTarget}{wxfiledroptarget}.
110
111 The middle of the sample window is taken by the log window which shows what is
112 going on (of course, this only works in debug builds) and may be helpful to see
113 the sequence of steps of data transfer.
114
115 Finally, the last part is used for dragging text from it to either one of the
116 listboxes (only one will accept it) or another application. The last
117 functionality available from the main frame is to paste a bitmap from the
118 clipboard (or, in the case of Windows version, also a metafile) - it will be
119 shown in a new frame.
120
121 So far, everything we mentioned was implemented with minimal amount of code
122 using standard wxWindows classes. The more advanced features are demonstrated
123 if you create a shape frame from the main frame menu. A shape is a geometric
124 object which has a position, size and color. It models some
125 application-specific data in this sample. A shape object supports its own
126 private \helpref{wxDataFormat}{wxdataformat} which means that you may cut and
127 paste it or drag and drop (between one and the same or different shapes) from
128 one sample instance to another (or the same). However, chances are that no
129 other program supports this format and so shapes can also be rendered as
130 bitmaps which allows them to be pasted/dropped in many other applications
131 (and, under Windows, also as metafiles which are supported by most of Windows
132 programs as well - try Write/Wordpad, for example).
133
134 Take a look at DnDShapeDataObject class to see how you may use
135 \helpref{wxDataObject}{wxdataobject} to achieve this.
136
137 \subsection{HTML samples}\label{samplehtml}
138
139 Eight HTML samples (you can find them in directory {\tt samples/html})
140 cover all features of HTML sub-library.
141
142 {\bf Test} demonstrates how to create \helpref{wxHtmlWindow}{wxhtmlwindow}
143 and also shows most of supported HTML tags.
144
145 {\bf Widget} shows how you can embed ordinary controls or windows within
146 HTML page. It also nicely explains how to write new tag handlers and extend
147 the library to work with unsupported tags.
148
149 {\bf About} may give you an idea how to write good-looking about boxes.
150
151 {\bf Zip} demonstrates use of virtual file systems in wxHTML. The zip archives
152 handler (ships with wxWindows) allows you to access HTML pages stored
153 in compressed archive as if they were ordinary files.
154
155 {\bf Virtual} is yet another VFS demo. This one generates pages at run-time.
156 You may find it useful if you need to display some reports in your application.
157
158 {\bf Printing} explains use of \helpref{wxHtmlEasyPrinting}{wxhtmleasyprinting}
159 class which serves as as-simple-as-possible interface for printing HTML
160 documents without much work. In fact, only few function calls are sufficient.
161
162 {\bf Help} and {\bf Helpview} are variations on displaying HTML help
163 (compatible with MS HTML Help Workshop). {\it Help} shows how to embed
164 \helpref{wxHtmlHelpController}{wxhtmlhelpcontroller} in your application
165 while {\it Helpview} is simple tool that only pops up help window and
166 displays help books given at command line.
167
168 \subsection{Layout sample}\label{samplelayout}
169
170 The layout sample demonstrates the two different layout systems offered
171 by wxWindows. When starting the program, you will see a frame with some
172 controls and some graphics. The controls will change their size whenever
173 you resize the entire frame and the exact behaviour of the size changes
174 is determined using the \helpref{wxLayoutConstraints}{wxlayoutconstraints}
175 class. See also the \helpref{overview}{constraintsoverview} and the
176 \helpref{wxIndividualLayoutConstraint}{wxindividuallayoutconstraint}
177 class for further information.
178
179 The menu in this sample offers two more tests, one showing how to use
180 a \helpref{wxBoxSizer}{wxboxsizer} in a simple dialog and the other one
181 showing how to use sizers in connection with a \helpref{wxNotebook}{wxnotebook}
182 class. See also \helpref{wxNotebookSizer}{wxnotebooksizer} and
183 \helpref{wxSizer}{wxsizer}.
184
185 \subsection{Text sample}\label{sampletext}
186
187 This sample demonstrates four features: firstly the use and many variants of
188 the \helpref{wxTextCtrl}{wxtextctrl} class (single line, multi line, read only,
189 password, ignoring TAB, ignoring ENTER).
190
191 Secondly it shows how to intercept a \helpref{wxKeyEvent}{wxkeyevent} in both
192 the raw form using the {\tt EVT_KEY_UP} and {\tt EVT_KEY_DOWN} macros and the
193 higherlevel from using the {\tt EVT_CHAR} macro. All characters will be logged
194 in a log window at the bottom of the main window. By pressing some of the function
195 keys, you can test some actions in the text ctrl as well as get statitics on the
196 text ctrls, which is useful for testing if these statitics actually are correct.
197
198 Thirdly, on platforms which support it, the sample will offer to copy text to the
199 \helpref{wxClipboard}{wxclipboard} and to paste text from it. The GTK version will
200 use the so called PRIMARY SELECTION, which is the pseudo clipboard under X and
201 best known from pasting text to the XTerm program.
202
203 Last not least: some of the text controls have tooltips and the sample also shows
204 how tooltips can be centrally disabled and their latency controlled.
205
206 \subsection{Thread sample}\label{samplethread}
207
208 This sample demonstrates the use of threads in connection with GUI programs.
209 There are two fundamentally different ways to use threads in GUI programs and
210 either way has to take care of the fact that the GUI library itself usually
211 is not multi-threading safe, i.e. that it might crash if two threads try to
212 access the GUI class simultaneously. One way to prevent that is have a normal
213 GUI program in the main thread and some worker threads which work in the
214 background. In order to make communication between the main thread and the
215 worker threads possible, wxWindows offers the \helpref{wxPostEvent}{wxpostevent}
216 function and this sample makes use of this function.
217
218 The other way to use a so called Mutex (such as those offered in the \helpref{wxMutex}{wxmutex}
219 class) that prevent threads from accessing the GUI classes as long as any other
220 thread accesses them. For this, wxWindows has the \helpref{wxMutexGuiEnter}{wxmutexguienter}
221 and \helpref{wxMutexGuiLeave}{wxmutexguileave} functions, both of which are
222 used and tested in the sample as well.
223
224 See also \helpref{Multithreading overview}{wxthreadoverview} and \helpref{wxThread}{wxthread}.
225
226 \subsection{Toolbar sample}\label{sampletoolbar}
227
228 The toolbar sample shows the \helpref{wxToolBar}{wxtoolbar} class in action.
229
230 The following things are demonstrated:
231
232 \begin{itemize}
233
234 \item Creating the toolbar using \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}
235 and \helpref{wxToolBar::AddControl}{wxtoolbaraddcontrol}: see
236 MyApp::InitToolbar in the sample.
237
238 \item Using {\tt EVT\_UPDATE\_UI} handler for automatically enabling/disabling
239 toolbar buttons without having to explicitly call EnableTool. This is is done
240 in MyFrame::OnUpdateCopyAndCut.
241
242 \item Using \helpref{wxToolBar::DeleteTool}{wxtoolbardeletetool} and
243 \helpref{wxToolBar::InsertTool}{wxtoolbarinserttool} to dynamically update the
244 toolbar.
245
246 \end{itemize}