Chapter 20. Dialogs


Dialog identifiers
Other dialog creation parameters
File dialogs
Showing and hiding dialogs
Modal dialogs
x::w::main_windows own references on their dialogs
Custom dialogs
Ad-hoc error message dialogs

menu.C from Chapter 17, Menus also demonstrates how to create dialogs. Dialogs are stand-alone, top level windows, represented by x::w::dialog objects.

An x::w::dialog is similar to an x::w::main_window, except that it doesn't have menus and some window managers may not draw a title bar for the dialog. In most other respects a dialog is the same as a main window, and one of its public class members is a:

const x::w::main_window dialog_window;

So, dialog->dialog_window->show_all() shows the dialog, and dialog->dialog_window->show_all() hides it.

Another difference between dialogs and main windows is while x::w::main_windows get created by themselves, x::w::dialogs get created by one of the methods from an existing x::w::main_window or another x::w::dialog (by accessing its dialog_window).

The following x::w::main_window methods create dialogs with a standard, theme-defined layout:


create_ok_dialog() returns a new x::w::dialog with an icon, a text label, and an Ok button.


create_ok_cancel_dialog() returns a new x::w::dialog with an icon, a text label, and Ok and Cancel buttons.


create_input_dialog() returns a new x::w::input_dialog with an icon, a text label, an x::w::input_field, and Ok and Cancel buttons.


create_file_dialog() returns a new x::w::file_dialog which implements a basic interface for selecting a file to open or create.

Dialog identifiers

These methods have several common parameters. The first parameter is a dialog identifier, which is a std::string, and serves as an identifying label. Each x::w::main_window (or a x::w::dialog) can create many dialogs as long as each dialog has a unique identifier label. Creating another dialog with the same identifier label replaces the existing dialog with that label.

Dialog identifiers are opaque, unique labels. For future use, dialog identifier labels should use the following naming conventions. Applications should use identifier labels formatted as Internet hostnames or E-mail addresses using domain names that belong to the application. An application developed by can use, or, as an example. LibCXXW's internal dialog identifiers use to avoid application conflicts.