1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: Samples description
4 %% Author: Vadim Zeitlin
8 %% Copyright: (c) wxWindows team
9 %% Licence: wxWindows licence
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{wxWindows samples
}\label{samples
}
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.
22 \subsection{Checklist sample
}\label{samplechecklist
}
24 This sample demonstrates the use of the
\helpref{wxCheckListBox
}{wxchecklistbox
}
25 class intercepting check, select and double click events. It also tests the
26 use of various methods modifiying the control, such as by deleting items
27 from it or inserting new once (these fucntions are actually implememted in
28 the parent class
\helpref{wxListBox
}{wxlistbox
} so the sample tests that class
29 as well). The layout of the dialog is created using a
\helpref{wxBoxSizer
}{wxboxsizer
}
30 demonstrating a simple dynamic layout.
32 \subsection{Config sample
}\label{sampleconfig
}
34 This sample demonstrates the
\helpref{wxConfig
}{wxconfigbase
} classes in a platform
35 indepedent way, i.e. it uses text based files to store a given configuration under
36 Unix and uses the Registry under Windows.
38 See
\helpref{wxConfig overview
}{wxconfigoverview
} for the descriptions of all
39 features of this class.
41 \subsection{Dialogs sample
}\label{sampledialogs
}
43 This sample shows how to use the common dialogs available from wxWindows. These
44 dialogs are desrcibed in details in the
\helpref{Common dialogs overview
}{commondialogsoverview
}.
46 \subsection{Scroll subwindow sample
}\label{samplescrollsub
}
48 This sample demonstrates the use of the
\helpref{wxScrolledWindow
}{wxscrolledwindow
}
49 class including placing subwindows into it and drawing simple graphics. It uses the
50 \helpref{SetTargetWindow
}{wxscrolledwindowsettargetwindow
} method and thus the effect
51 of scrolling does not show in the scrolled window itself, but in one of its subwindows.
53 Additionally, this samples demonstrates how to optimize drawing operations in wxWindows,
54 in particular using the
\helpref{wxWindow::IsExposed
}{wxwindowisexposed
} method with
55 the aim to prevent unnecessary drawing in the window and thus reducing or removing
58 \subsection{Font sample
}\label{samplefont
}
60 The font sample demonstrates
\helpref{wxFont
}{wxfont
},
61 \helpref{wxFontEnumerator
}{wxfontenumerator
} and
62 \helpref{wxFontMapper
}{wxfontmapper
} classes. It allows you to see the fonts
63 available (to wxWindows) on the computer and shows all characters of the
66 \subsection{DnD sample
}\label{samplednd
}
68 This sample shows both clipboard and drag and drop in action. It is quite non
69 trivial and may be safely used as a basis for implementing the clipboard and
70 drag and drop operations in a real-life program.
72 When you run the sample, its screen is split in several parts. On the top,
73 there are two listboxes which show the standard derivations of
74 \helpref{wxDropTarget
}{wxdroptarget
}:
75 \helpref{wxTextDropTarget
}{wxtextdroptarget
} and
76 \helpref{wxFileDropTarget
}{wxfiledroptarget
}.
78 The middle of the sample window is taken by the log window which shows what is
79 going on (of course, this only works in debug builds) and may be helpful to see
80 the sequence of steps of data transfer.
82 Finally, the last part is used for two things: you can drag text from it to
83 either one of the listboxes (only one will accept it) or another application
84 and, also, bitmap pasted from clipboard will be shown there.
86 So far, everything we mentioned was implemented with minimal amount of code
87 using standard wxWindows classes. The more advanced features are demonstrated
88 if you create a shape frame from the main frame menu. A shape is a geometric
89 object which has a position, size and
color. It models some
90 application-specific data in this sample. A shape object supports its own
91 private
\helpref{wxDataFormat
}{wxdataformat
} which means that you may cut and
92 paste it or drag and drop (between one and the same or different shapes) from
93 one sample instance to another (or the same). However, chances are that no
94 other program supports this format and so shapes can also be rendered as
95 bitmaps which allows them to be pasted/dropped in many other applications.
97 Take a look at DnDShapeDataObject class to see how you may use
98 \helpref{wxDataObject
}{wxdataobject
} to achieve this.
101 \subsection{HTML samples
}\label{samplehtml
}
103 Eight HTML samples (you can find them in directory
{\tt samples/html
})
104 cover all features of HTML sub-library.
106 {\bf Test
} demonstrates how to create
\helpref{wxHtmlWindow
}{wxhtmlwindow
}
107 and also shows most of supported HTML tags.
109 {\bf Widget
} shows how you can embed ordinary controls or windows within
110 HTML page. It also nicely explains how to write new tag handlers and extend
111 the library to work with unsupported tags.
113 {\bf About
} may give you an idea how to write good-looking about boxes.
115 {\bf Zip
} demonstrates use of virtual file systems in wxHTML. The zip archives
116 handler (ships with wxWindows) allows you to access HTML pages stored
117 in compressed archive as if they were ordinary files.
119 {\bf Virtual
} is yet another VFS demo. This one generates pages at run-time.
120 You may find it useful if you need to display some reports in your application.
122 {\bf Printing
} explains use of
\helpref{wxHtmlEasyPrinting
}{wxhtmleasyprinting
}
123 class which serves as as-simple-as-possible interface for printing HTML
124 documents without much work. In fact, only few function calls are sufficient.
126 {\bf Help
} and
{\bf Helpview
} are variations on displaying HTML help
127 (compatible with MS HTML Help Workshop).
{\it Help
} shows how to embed
128 \helpref{wxHtmlHelpController
}{wxhtmlhelpcontroller
} in your application
129 while
{\it Helpview
} is simple tool that only pops up help window and
130 displays help books given at command line.
132 \subsection{Thread sample
}\label{samplethread
}
134 This sample demonstrates the use of threads in connection with GUI programs.
135 There are two fundamentally different ways to use threads in GUI programs and
136 either way has to take care of the fact that the GUI library itself usually
137 is not multi-threading safe, i.e. that it might crash if two threads try to
138 access the GUI class simultaneously. One way to prevent that is have a normal
139 GUI program in the main thread and some worker threads which work in the
140 background. In order to make communication between the main thread and the
141 worker threads possible, wxWindows offers the
\helpref{wxPostEvent
}{wxpostevent
}
142 function and this sample makes use of this function.
144 The other way to use a so called Mutex (such as those offered in the
\helpref{wxMutex
}{wxmutex
}
145 class) that prevent threads from accessing the GUI classes as long as any other
146 thread accesses them. For this, wxWindows has the
\helpref{wxMutexGuiEnter
}{wxmutexguienter
}
147 and
\helpref{wxMutexGuiLeave
}{wxmutexguileave
} functions, both of which are
148 used and tested in the sample as well.
150 See also
\helpref{Multithreading overview
}{wxthreadoverview
} and
\helpref{wxThread
}{wxthread
}.
152 \subsection{Toolbar sample
}\label{sampletoolbar
}
154 The toolbar sample shows the
\helpref{wxToolBar
}{wxtoolbar
} class in action.
156 The following things are demonstrated:
160 \item Creating the toolbar using
\helpref{wxToolBar::AddTool
}{wxtoolbaraddtool
}
161 and
\helpref{wxToolBar::AddControl
}{wxtoolbaraddcontrol
}: see
162 MyApp::InitToolbar in the sample.
164 \item Using
{\tt EVT
\_UPDATE\_UI} handler for automatically enabling/disabling
165 toolbar buttons without having to explicitly call EnableTool. This is is done
166 in MyFrame::OnUpdateCopyAndCut.
168 \item Using
\helpref{wxToolBar::DeleteTool
}{wxtoolbardeletetool
} and
169 \helpref{wxToolBar::InsertTool
}{wxtoolbarinserttool
} to dynamically update the