-->

Previous | Table of Contents | Next

Page 533

motif-2.0.1-1.i386.rpm

If you just want to run mwm or the Motif Workspace Manager, Wsm, you'll need the shared libraries in this package. More than 800 icons are also installed from this file under the /usr/X11R6/include/X11/icons directory.

motif-mwm-2.0.1-1.i386.rpm

Here's where you'll find not only the window manager, mwm, but also Wsm, which demonstrates just some of the new features of Motif 2.0.1. Also included is panner, pixmap, and a handy bitmap browser, xbmbrowser, which transverses directories and shows what .xpm or .xbm graphics look like a directory at a time.

motif-demosrc-2.0.1-1.i386.rpm

If you're interested in exploring the new features of Motif 2.0.1, need source-code examples to help you learn about Motif programming, or want to read the source to the example clients, install this package. You'll also need to install the development libraries in order to build the examples. Some of the concepts these programs demonstrate are discussed later in this chapter, but here's a list of the examples included:

Page 534

Along with these programs, there are also 10 other examples in a separate directory.

motif-demos-2.0.1-1.i386.rpm

If you don't want to spend the time building the sample clients from the source code, and just want to try some of the features of Motif, install this package. You'll also need to install the shared libraries in order to run these clients.

A Simple Example of Motif Programming Concepts

This section presents an extremely simple example of a Motif program. You'll learn just enough to get you started. But before getting into the details, let's cover the basic concepts in an overview of programming for Motif.

Although writing programs for the Linux command line in C is fairly simple, if you're familiar with programming for X, you know that there's a lot more involved in writing a windowing program. You have to consider labels, dialogs, windows, scrolling, colors, buttons, and many other features of how a program works besides the internal algorithms that make a program unique. Along with this unique functionality, when you program for X, you should consider consistency and ease of use for the user.

This is where Motif can help you. By providing a rich variety of functions, Motif can help programmers build attractive and easy-to-use programs. In Motif programming, a lot of the program code, especially for smaller programs, is devoted to the graphical interface.

When you write C programs for the Linux command line, you'll generally use the libc libraries. If you write programs for X, you generally will use the Xlib libraries. When you program for Motif, you use X as the window system, and the X Toolkit, or Xt libraries (and others) for the interface.

After you install Motif, you'll find the following libraries under the /usr/X11R6/lib directory:

/usr/X11R6/lib/libMrm.a

/usr/X11R6/lib/libUil.a

/usr/X11R6/lib/libXm.a

/usr/X11R6/lib/libXmCxx.a

/usr/X11R6/lib/libMrm.so

/usr/X11R6/lib/libMrm.so.2

/usr/X11R6/lib/libMrm.so.2.0

/usr/X11R6/lib/libXm.so

/usr/X11R6/lib/libXm.so.2

/usr/X11R6/lib/libXm.so.2.0

Page 535

The Motif #include files are located under the /usr/X11R6/include/Mrm, /usr/X11R6/include/Xm, and /usr/X11R6/include/uil directories. The location of these libraries and headers is pretty much standard across all computer systems, but if they are located in a different place, this difference will be documented in configuration files and rules files for imake and xmkmf. (See "Using imake and xmkmf," later in this chapter, for more on these utilities.)

Widgets and Event-Driven Programming

An important concept to consider when programming for X and Motif is that these programs usually do not just run and quit; these programs are driven by events such as mouse clicks, button pushes, mouse drags, other programs, and keystrokes. Apple Macintosh programmers will feel right at home in programming for Motif. Some of the interface elements that intercept these events are built with Motif routines called widgets, and as you become more proficient, you'll even write some of your own.

If you're just starting off with Motif programming, don't be put off by some of the new terms and concepts about this subject. You'll learn about callbacks, children, classes, composites, coupled resources, gadgets, hierarchies, initiators, instantiation, modality, properties, receivers, and subclasses. Although there isn't enough room in this book to cover all these subjects, Listing 26.1 contains a simple example to get you started.

The Simple Motif Program

Listing 26.1 creates a small window with File, Edit, and Help menus. The application window is resizable, can be minimized or maximized, and in general, responds like any Motif application. This program demonstrates how to create a window, a menu bar, a pull-down menu, buttons, and a pop-up dialog.

It's not a perfect example, as the interface is in the main() part of the program, it doesn't use resources, and it really doesn't do anything; I'll leave the internals of how the program might work up to you.

Listing 26.1. motif_skeleton.c.

/* a simple skeleton Motif program */

#include <Xm/RowColumn.h>

#include <Xm/MainW.h>

#include <Xm/CascadeB.h>

#include <Xm/MessageB.h>

#include <Xm/SeparatoG.h>

#include <Xm/PushBG.h>



Widget skeleton;    /* our application */

/* what happens when user selects Exit */

void skel_exit_action() {

exit(0);

    }




                                        continues

Page 536

Listing 26.1. continued


/* destroy a dialog */

void skel_dialog_handler(skel_dialog)

Widget skel_dialog;

{

XtUnmanageChild(skel_dialog);

}



/* create a Help action dialog*/

void skel_help_action()

{

    Arg      args[10];

    Widget   skel_dialog;

XmString skel_string;



    /* store help string */

    skel_string =

XmStringCreateLocalized("This is Skeleton v0.1, a simple Motif client.");



/* build dialog */

skel_dialog = XmCreateMessageDialog (skeleton, "dialog", args, 0);

XtVaSetValues(skel_dialog, XmNmessageString, skel_string, NULL, NULL);



/* call skel_dialog_handler() after OK button is pushed */

XtAddCallback(skel_dialog, XmNokCallback, skel_dialog_handler, NULL);



    /* free storage */

    XmStringFree(skel_string);



    /* display the dialog */

    XtManageChild(skel_dialog);

};



/* main program begins here */

main (argc, argv)

int argc;

char *argv[];

{

    /* declare our widgets, including menu actions */

    Widget    skel_window,             /* main window */

              skel_menubar,            /* main window menu bar */

              skel_filepulldown,       /* File menu */

                  skel_new,

                  skel_open,

                  skel_close,

                  skel_save,

                  skel_exit,

              skel_editpulldown,       /* Edit menu */

                  skel_cut,

                  skel_copy,

                  skel_paste,

              skel_helppulldown,       /* Help menu */

                  skel_version;

    XmString  skel_string;             /* temporary storage */

    XtAppContext skel_app;



XtSetLanguageProc (NULL, NULL, NULL);

Previous | Table of Contents | Next