Code Generation

X-Designer generates source code in C, C++, Java and UIL, with the resource settings either hard wired into the code, or generated in a matching X Resource file. To write an application using X-Designer, it is necessary to understand the way that code is generated and how to link your application code to it.

In Microsoft Windows mode, you may also generate a Microsoft Windows resource file. If you have created any pixmaps, these will be automatically converted at this point into Microsoft Windows Bitmaps or Icons (depending on whether the selected widget is a Button or Label respectively). Each one is written into a separate file using the name of the pixmap object as the filename.

Each design for which code is generated produces one output file, or module. Each module consists of a number of sections.

Analysis of the Primary Module

From top to bottom, your primary code module contains the following sections:

The optional portions of the file can be included or excluded by setting toggles on the control panel.

The Header Section

The primary module has the following header material, in this order:

Your file does not have a module heading or module prelude. You can specify code to be inserted in these places from within X-Designer.

After some standard X-Designer comments, there is a list of #include statements needed for the Motif code in your module. The #include statements are optional and are controlled by the toggles in the Code Options dialog.

Link Functions or Link Declarations

Next, the module contains code for the link functions. The following code fragment shows a typical link function:


void XDunmanage_link ( Widget w, XtPointer client_data, XtPointer call_data ) { if ( client_data && *(Widget *)client_data ) XtUnmanageChild ( *(Widget *)client_data ); }

Generation of this code is optional and is controlled by the Generate Options dialog.

Variable Declarations

In this section, all globally defined widgets in the design are declared. The following lines are typical:


Widget exit_button = (Widget) NULL; Widget help_cascade = (Widget) NULL;

Only global widgets are declared here. By default, widgets are local in scope. Local widgets are defined in the function which creates their parent Shell and cannot be referenced elsewhere in your application. To make a widget global, you can:

Note that the variable names of Application Shells and Top level Shells are always global in X-Designer and therefore should not be made local. In addition, any widget which is the target of a link must also be global.

Variable Names

Variable names must be unique. If you "Read" or "Paste" widgets into your design whose variable names duplicate names of existing widgets, X-Designer silently removes the duplicate names and assigns new, local, names of the form widget_type, e.g. shell4, form5, etc.

By convention, variable names of widgets should begin with a lower-case letter. This helps avoid conflict with Motif declarations.

Creation Procedures

By default, X-Designer generates a creation procedure for each Shell widget in your design. The creation procedures are the heart of the generated code. Each creation procedure does the following:

The creation procedures do not display the Shell. Usually, windows are displayed by a function call in the main() procedure or in a callback routine.

Callback Procedures

The primary module does not include callback functions themselves. However, it does add any callbacks you have specified to each widget's callback list.

Description of the Main Program

A minimal main() procedure is either generated into a separate file or at the end of your primary module.

X-Designer's main() procedure does the following things:

Generated files for Smart Code

Extensive code files are generated when Smart Code is selected from the Callbacks dialog. More files are generated for "Thin Client" and "Internet" than for "Get/Set" because, in addition to the getters and setters for the Group, all the code for the communication with a server is generated and, in the case of "Thin Client", the server side of your application too.

  1. Groups Generated Code

    If you are using groups but not Smart Code, an array of widgets is defined in the primary source file.

  2. Get/Set Generated Code

    If you have selected "Get/Set" Smart Code for one or more callback, but you have not requested any "Thin Client" or "Internet" Smart Code, the following files are generated into the directory specified at the top of the Callbacks dialog:

    In addition, the following sub-directories are created:

  3. Thin Client/Internet Smart Code Generated Code

    When you generate code from a design containing any Web Active callbacks, all of the files and directories described in the Get/Set Generated Code above are generated. In addition, the following directories are created by X-Designer:

    http_c. This contains the source code for parsing the URL and for sending and receiving data using the HTTP protocol. server_c. This is the server-side of your application.

    The directory "server_c" contains all the files you need to build the server which will connect to the thin client application containing your user interface. The whole of this directory can be taken away to be built and run on a remote web server.

    The Makefile in the top-level directory contains the rules for building both the client (your design) and the server (the Web Active callbacks). To build the client, you need only type:

    make

    at the command line.

    To build the server, type:

    make server

    at the command line.

See also: