Classes and functions: wxColourDialog, wxFontDialog, wxPrintDialog, dialog functions
Common dialog classes and functions encapsulate commonly-needed dialog box requirements. They are mostly 'modal', grabbing the flow of control until the user dismisses the dialog, to make them easy to use within an application.
Some dialogs have both platform-dependent and platform-independent implementations, so that if underlying windowing systems that do not provide the required functionality, the generic classes and functions can stand in. For example, under MS Windows, wxColourDialog uses the standard colour selector. There is also an equivalent called wxGenericColourDialog for other platforms, and a macro defines wxColourDialog to be the same as wxGenericColourDialog on non-MS Windows platforms. However, under MS Windows, the generic dialog can also be used, for testing or other purposes.
Not all common dialogs have classes; some are still in functional form, awaiting an object-oriented make-over, such as the message box and file selector dialogs. A few familiar MS Windows-style common dialogs have yet to be implemented, such as the text search dialog and a directory selector.
wxColourDialog overview
wxFontDialog overview
wxPrintDialog overview
Classes: wxColourDialog, wxColourData
The wxColourDialog presents a colour selector to the user, and returns with colour information.
The MS Windows colour selector
Under Windows, the native colour selector common dialog is used. This presents a dialog box with three main regions: at the top left, a palette of 48 commonly-used colours is shown. Under this, there is a palette of 16 'custom colours' which can be set by the application if desired. Additionally, the user may open up the dialog box to show a right-hand panel containing controls to select a precise colour, and add it to the custom colour palette.
The generic colour selector
Under non-MS Windows platforms, the colour selector is a simulation of most of the features of the MS Windows selector. Two palettes of 48 standard and 16 custom colours are presented, with the right-hand area containing three sliders for the user to select a colour from red, green and blue components. This colour may be added to the custom colour palette, and will replace either the currently selected custom colour, or the first one in the palette if none is selected. The RGB colour sliders are not optional in the generic colour selector. The generic colour selector is also available under MS Windows; use the name wxGenericColourDialog.
wxColourDialog is available under Motif and Windows. Under XView there seem to be some problems, probably related to modal dialogs.
Example
In the samples/dialogs directory, there is an example of using the wxColourDialog class. Here is an excerpt, which sets various parameters of a wxColourData object, including a grey scale for the custom colours. If the user did not cancel the dialog, the application retrieves the selected colour and uses it to set the background of a canvas.
wxColourData data; data.SetChooseFull(TRUE); for (int i = 0; i < 16; i++) { wxColour colour(i*16, i*16, i*16); data.SetCustomColour(i, colour); } wxColourDialog dialog(this, &data); if (dialog.Show(TRUE)) { wxColourData retData = dialog.GetColourData(); wxColour col = retData.GetColour(); wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID); myCanvas->SetBackground(brush); myCanvas->Clear(); myCanvas->Refresh(); }
Classes: wxFontDialog, wxFontData
The wxFontDialog presents a font selector to the user, and returns with font and colour information.
The MS Windows font selector
Under Windows, the native font selector common dialog is used. This presents a dialog box with controls for font name, point size, style, weight, underlining, strikeout and text foreground colour. A sample of the font is shown on a white area of the dialog box. Note that in the translation from full MS Windows fonts to wxWindows font conventions, strikeout is ignored and a font family (such as Swiss or Modern) is deduced from the actual font name (such as Arial or Courier). The full range of Windows fonts cannot be used in wxWindows at present.
wxFontDialog is available under Motif and Windows. Under XView there seem to be some problems, probably related to modal dialogs.
The generic font selector
Under non-MS Windows platforms, the font selector is simpler. Controls for font family, point size, style, weight, underlining and text foreground colour are provided, and a sample is shown upon a white background. The generic font selector is also available under MS Windows; use the name wxGenericFontDialog.
In both cases, the application is responsible for deleting the new font returned from calling wxFontDialog::Show (if any). This returned font is guaranteed to be a new object and not one currently in use in the application.
Example
In the samples/dialogs directory, there is an example of using the wxFontDialog class. The application uses the returned font and colour for drawing text on a canvas. Here is an excerpt:
wxFontData data; data.SetInitialFont(canvasFont); data.SetColour(*canvasTextColour); wxFontDialog dialog(this, &data); if (dialog.Show(TRUE)) { wxFontData retData = dialog.GetFontData(); canvasFont = retData.GetChosenFont(); (*canvasTextColour) = retData.GetColour(); myCanvas->Refresh(); }
Classes: wxPrintDialog, wxPrintData
This class represents the print and print setup common dialogs. You may obtain a wxPrinterDC device context from a successfully dismissed print dialog.
The samples/printing example shows how to use it: see Printing overview for an excerpt from this example.