Back to XUL: The Interface
(Page 1 of 4 )
This article, the second in a series about the XML variant called XUL, gets you started on creating the main interface for an application. Among other things, it covers sub-menus, toolbars, and the main content window.
Okay, so you have Mozilla installed and a text editor is open and awaiting your input? Great, let’s get started on the main interface file.
<?xml version="1.0"?>
It was XML that put the X into XUL, so the rules that apply to XML documents also apply to XUL documents. The document must be well-formed and you need the XML declaration at the top of your file.
The top level element of XUL is the window element, which serves as a container for all other elements. This must have the XUL namespace as an attribute:
<window
id="xuledit"
title=”XUL Edit Lite 1.0”
height="600"
width="800"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul”>
As a point of interest, the keymaster and gatekeeper used in the namespace are references to the classic movie "Ghostbusters." Anyway, the id attribute is optional; it is used for referencing and scripting. Other attributes include the title attribute, the value of which is displayed in the title bar at the top of the window, and the width and height attributes. The most common screen resolution in use today is 800 x 600, so I've set the height and width attributes to these numbers. When running XUL applications within Mozilla, they won’t have a title bar of their own.
In most Windows applications, the menu bar is right at the top of whichever application you are using. We will follow this tradition, so your next element (or group of elements) will be a menu bar:
<toolbox>
<menubar id="mainmenu">
<menu id="menuFile" label="&fileLabel;" accesskey="F">
The menu is encapsulated within a toolbox element so that it can be expanded or collapsed using a grippy. This is not strictly necessary but I like it, and we want our application to integrate smoothly with Mozilla, so using standard features like this helps retain consistency.
As you can see, the label is an entity reference rather than the actual text that is being displayed. This is partly because XUL experts insist that this is the proper way to do things and partly because it’s a good way of demonstrating how easy it is to provide alternative locale features, like supporting other languages.
The accesskey attribute specifies the keyboard key that can be used as a shortcut in combination with the ALT key. Again, this is universal in Windows applications.
Next: Adding the sub-menu >>
More XML Articles
More By Dan Wellman