Back to main page

4. Using dialog files

In this part we use dialog files to layout dialogs seperately from the source code. To follow this part, have a look at the tutorials/02 folder.

4.1. What is a dialog file

Dialog file store informations about layout and structure of window contents. It is the easiest way of creating contents. It frees from programming a fixed dialog structure and lets designers change the face of the dialog, without programming a single line.

4.2. The first dialog

The first dialog resembles the simple "Hello world!" from the first example.

Example 2. dialog.xml contents

    <mmsdialog>
        <rootwindow class="" w="100%" h="100%" margin="0" alignment="center" 
                    border.thickness="0" bgcolor="#00000000" opacity="255">

            <label name="label1" text="Hello World" alignment="center" 
			       bgcolor="#00000000" color="#999999ff" font.name="DejaVuSansMono.ttf" font.size="18"/>

        </rootwindow>
    </mmsdialog>
The structure is pretty simple. A <mmsdialog> spans a <rootwindow> which contais only one label as child item.


4.3. Load and show first dialog

To load the dialog into a window the MMSDialogManager is used. As for now we continue to ignore themes for a while.

	/* create dialog manager */
    MMSDialogManager dm;

	/* create a root window */
	MMSWindow *window = dm.loadDialog("./dialog.xml");

Like in the first example, the window is getting show by

    window->show();

4.4. Update dialog contents

Most applications would want to update the text label with some other value. The text of the label is defined in the dialog.xml. How is the label accessed then? The label tag has an attribute name, with the value set to "label1". Using this name the label could be extracted by the dialog manager.

	/* extract the label */
	MMSLabel *label = (MMSLabel *)dm["label1"];	

	/* update the text */
	label->setText("updated hello world!");

This works for all kinds widgets. The naming of the widgets is important. Having two widgets with the same name results in error. Only those widgets that should be acessible through the dialog manager should be named though.

The resulting window should look like this