⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0533-0536.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Motif Programming</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=26 //-->

<!-- PAGES=0529-0544 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0529-0532.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0537-0540.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-533"><P>Page 533</P></A>













<H4><A NAME="ch26_ 8">

motif-2.0.1-1.i386.rpm

</A></H4>









<P>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.

</P>









<H4><A NAME="ch26_ 9">

motif-mwm-2.0.1-1.i386.rpm

</A></H4>









<P>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.

</P>









<H4><A NAME="ch26_ 10">

motif-demosrc-2.0.1-1.i386.rpm

</A></H4>









<P>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:

</P>









<UL>

<LI>

airport&#151;Demonstrates Motif drag and drop

<LI>

animate&#151;Animates pixel maps in an X window

<LI>

drag_and_drop&#151;A thorough demonstration of drag-and-drop features

<LI>          draw&#151;A simple graphics application

<LI>          earth&#151;The classic rotating earth

<LI>

filemanager&#151;A simple, graphical file manager

<LI>

fileview&#151;A Motif &quot;more&quot; program

<LI>

getsubres&#151;A Motif widget resources viewer

<LI>

hellomotif&#151;The classic &quot;Hello, world!&quot;

<LI>

hellomotifi18n&#151;A better &quot;Hello, world!&quot; in different languages

<LI>

i18ninput&#151;Shows how to handle text input in different languages

<LI>          panner&#151;Shows how

Motif clients can use virtual screen support

<LI>

periodic&#151;Demonstrates displayable Motif widgets

<LI>          piano&#151;A simple Motif MIDI application (you'll need MIDI support)

<LI>          popups&#151;Shows pop-up menu improvements in Motif 2.0

<LI>

sampler2_0&#151;A fairly complete demonstration of Motif 2.0 features

<LI>

setdate&#151;Sets the system's date and demos the Motif SpinBox widget

<LI>

texteditor&#151;A simple editor with split panes, but no Undo, Print, and so on

</UL>





<A NAME="PAGENUM-534"><P>Page 534</P></A>











<UL>

<LI>

transfer&#151;Demonstrates data transfer between Motif clients

<LI>

workspace&#151;Source to Wsm

</UL>









<P>Along with these programs, there are also 10 other examples in a separate

directory.

</P>









<H4><A NAME="ch26_ 11">

motif-demos-2.0.1-1.i386.rpm

</A></H4>









<P>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.

</P>









<H3><A NAME="ch26_ 12">

A Simple Example of Motif Programming Concepts

</A></H3>









<P>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.

</P>









<P>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.

</P>









<P>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.

</P>









<P>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.

</P>









<P>After you install Motif, you'll find the

following libraries under the /usr/X11R6/lib directory:

</P>

<!-- CODE //-->

<PRE>/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

</PRE>

<!-- END CODE //-->



<A NAME="PAGENUM-535"><P>Page 535</P></A>











<P>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 &quot;Using imake and xmkmf,&quot; later in this chapter, for more on

these utilities.)

</P>









<H4><A NAME="ch26_ 13">

Widgets and Event-Driven Programming

</A></H4>









<P>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.

</P>









<P>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.

</P>









<H4><A NAME="ch26_ 14">

The Simple Motif Program

</A></H4>









<P>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.

</P>









<P>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.

</P>









<P>Listing 26.1. motif_skeleton.c.

</P>

<!-- CODE //-->

<PRE>/* a simple skeleton Motif program */

#include &lt;Xm/RowColumn.h&gt;

#include &lt;Xm/MainW.h&gt;

#include &lt;Xm/CascadeB.h&gt;

#include &lt;Xm/MessageB.h&gt;

#include &lt;Xm/SeparatoG.h&gt;

#include &lt;Xm/PushBG.h&gt;



Widget skeleton;    /* our application */

/* what happens when user selects Exit */

void skel_exit_action() {

exit(0);

    }



</PRE>

<!-- END CODE //-->









<PRE>

                                        continues

</PRE>



<A NAME="PAGENUM-536"><P>Page 536</P></A>













<P>Listing 26.1. continued

</P>

<!-- CODE //-->

<PRE>

/* 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(&quot;This is Skeleton v0.1, a simple Motif client.&quot;);



/* build dialog */

skel_dialog = XmCreateMessageDialog (skeleton, &quot;dialog&quot;, 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);

</PRE>

<!-- END CODE //-->





<P><CENTER>

<a href="0529-0532.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0537-0540.html">Next</A>

</CENTER></P>









</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -