📄 ch32.htm
字号:
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD ALIGN="LEFT">Menu </TD>
<TD ALIGN="LEFT">Objects derived from <TT>OI_menu</TT> </TD>
</TR>
</TABLE>
</CENTER>
<CENTER>
<H3><A NAME="Heading27<FONT COLOR="#000077">How to Create an Application</FONT></H3>
</CENTER>
<P>The first step to creating an application is to invoke ObjectBuilder in a new
or empty directory. Once the main window appears, move the window to a convenient
area of the screen.</P>
<P>Next, open the Palette menu and select a palette from the Palettes pull-right
menu shown in Figure 32.8. The palette window opens, displaying all possible objects
for that palette. For beginners, the Novice palette is the simplest to use. The Novice
palette window is shown in Figure 32.16.
<P>
<a href="../art/32/32fig16.gif">Figure 32.16.</A> The Novice palette window.
<P>The application window is usually the top-level or root object of an application.
Select the application window object and drag it to an empty location on your screen.
This window can now be resized to what is appropriate for your application.</P>
<P>You can now select and drag each required object into the application window.
Once all the objects needed have been created you can close the Palette window by
selecting Close/Dismiss from the Palette window's File menu.
<CENTER>
<H4><A NAME="Heading28<FONT COLOR="#000077">The Attribute Editor</FONT></H4>
</CENTER>
<P>The Attribute Editor allows you to modify specific attributes or resources for
each object. To invoke the editor, move the pointer to an object you want to modify
and double-click the Select mouse button. An Attribute Editor similar to the one
shown in Figure 32.17 is displayed.
<P>
<a href="../art/32/32fig17.gif">Figure 32.17.</a> The Attribute Editor.
<P>The Attribute Editor appears with the name of the object being modified in the
title bar. Depending on the object that is to be modified, the Attribute Editor displays
different resources.</P>
<P>ObjectBuilder assigns an internal name to all of your objects. If you modify the
Object Name resource (which is recommended because the names that ObjectBuilder assigns
are not very intuitive) ObjectBuilder still maintains its internal name for the object.
This name is displayed in the title bar of the Attribute Editor when you are editing
the object.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading29<FONT COLOR="#000077"><B>NOTE:</B> </FONT>ObjectBuilder may
not interact perfectly with the <TT>fvwm</TT> window manager that comes with Linux.
Some of the windows do not appear with title bars. To see the information, such as
the object name, that is being displayed in the title bar, switch to one of the other
window managers.
<HR>
</DL>
<P>The attributes that are common to all objects are Category, Object Name, Apply
To, and Title. When the Editor appears, the Category is set to <TT>default</TT>.
If the Category is not <TT>default</TT>, or you want another category, press the
abbreviated menu button to display a list of categories from which to choose. The
category tells you what the attributes or resources are for. <TT>Default</TT> is
the object as viewed, and <TT>callback</TT> defines the action that occurs in response
to an event for that object.</P>
<P>The Apply To resource lets you choose whether the modifications apply only to
that object, to the object and its children, or siblings as well. There are numerous
combinations to choose from in this menu.</P>
<P>The Title resource is the title for the window. Modifying this changes what is
seen in the title bar of the window.</P>
<P>To ensure that the objects in an application window remain in the correct place
relative to their siblings, you must set a layout method for that object. Select
the Layout menu from the application window's Attribute Editor and view the layout
options, as shown in Figure 32.18.
<P>
<a href="../art/32/32fig18.gif">Figure 32.18.</a> The Layout menu.
<P>Select an appropriate layout, and the objects in the application are moved. After
this the objects within the application window can still be moved but that movement
is restricted to within the boundaries of their parents.</P>
<P>When modifying resources for menu objects or menu cells, you need to specify whether
ObjectBuilder should perform the action on the menu or the menu cell by making a
selection in the Menu Focus option of the main window.</P>
<P>The Label Resource is the text that appears in a menu cell. The <TT>cbCellAction</TT>
resource assigns callback functions to the cell.</P>
<P>By selecting the Traverse pull-down menu from the menu bar at the top of the Attribute
Editor, you can shift the focus of the editor to a parent, child, or sibling of the
present object. This allows you to modify the resources of a child without affecting
the resources of the parent. The Traverse menu is shown in Figure 32.19.</P>
<P>If the Attribute Editor is open and you wish to modify the attributes of a different
object, place the pointer on the desired object and press the Select mouse button.
This causes the editor to display the resources for the selected object.</P>
<P>Because each object has a unique set of resources available to it that are too
numerous to mention here, they are explained in the Help function of ObjectBuilder.
<P>
<a href="../art/32/32fig19.gif">Figure 32.19.</a> The Traverse menu.
<P><CENTER>
<H4><A NAME="Heading30<FONT COLOR="#000077">Generating Application Files</FONT></H4>
</CENTER>
<CENTER>
<H4><FONT COLOR="#000077"><BR>
Generating Application Files</FONT></H4>
</CENTER>
<P>When you use ObjectBuilder to generate an application, it creates a number of
files for you. It is important to understand what each of these files is and what
they are used for. The files that are created and their purpose are listed here.
Configuration File (<TT>appname.cf</TT>)--This file contains the hierarchical description
of the graphical objects that make up the front end of the application. It also contains
the resource definitions and callback information for the objects.</P>
<P>Help File (<TT>appname.hp</TT>)--This file contains the application's context-sensitive
help.</P>
<P>Main Program (<TT>appname.C</TT>)--This file contains the code to handle the initialization,
user interaction startup, and OI cleanup. This file can be edited after it is generated
and ObjectBuilder will not overwrite any changes made to it.</P>
<P>Main Header File (<TT>appname.H</TT>)--This file is included in all ObjectBuilder-generated
C++ source code files. It can be edited after it is generated and ObjectBuilder will
not overwrite it.</P>
<P>External References Include File (<TT>appname_bd.H</TT>)--This file contains references
to all objects for which you requested user variables.</P>
<P>Binding File (<TT>appname_bd.C</TT>)--This file contains the object variables,
external declarations for all callback stubs, and a binding table that binds the
name of the object listed in the configuration file to the object itself.</P>
<P>Callback Stubs File (<TT>appname_cb.C</TT>)--This file contains fully documented
callback stubs generated by ObjectBuilder for all the callbacks according to the
specifications you entered in the Attribute Editor. The top portion of the file is
declarations and the bottom contains the callback stubs. There is a separator line
between the two sections that must not be removed. If you delete a callback, the
stub is deleted but you have to remove the declaration yourself. This file can be
edited, and ObjectBuilder will not overwrite any changes made.
<BLOCKQUOTE>
<P>Makefile--This file provides instructions on how to build the application at runtime.
It can be edited and ObjectBuilder will not overwrite the changes made.
</BLOCKQUOTE>
<P>Once the application is saved using the Save function from the File menu, the
above files are generated and placed in the same directory that ObjectBuilder was
originally started from. You can then use any text editor to edit those files that
require changes.
<CENTER>
<H4><A NAME="Heading31<FONT COLOR="#000077">Writing Callbacks</FONT></H4>
</CENTER>
<P>Applications created using ObjectBuilder are event driven. This means that code
is executed in response to an event. Here are examples of events:
<UL>
<LI>Pressing a button
<P>
<LI>Selecting from a menu
<P>
<LI>Closing a window
<P>
<LI>Selecting an option
</UL>
<P>For your application to work you have to create the back end. The back end is
the code that tells your application what to do when an event, such as a selection
from a menu, occurs. ObjectBuilder refers to this code as a callback.</P>
<P>ObjectBuilder generates the callback stubs file according to the specifications
you give in the callback category of the Attribute Editor. Each callback has three
parameter entry fields. These fields specify the callback object, function, and argument,
going from left to right in the editor. Only the function is mandatory. The Attribute
Editor for the callback category of a menu cell is shown in Figure 32.20.
<P>
<a href="../art/32/32fig20.gif">Figure
32.20.</A> The callback category.
<P>The <TT>callback</TT> object is the object that is
used when calling a member function for a specific class. It is good practice to
allow runtime resolution of the object needed by a member function. The function
can be a member function or a stand-alone function. The arguments can be strings,
constants, or pointers to objects. Structures, floating point numbers, and pointers
to member functions cannot be passed as arguments. These are the rules for entering
arguments:
<UL>
<LI>Strings are always quoted.
<P>
<LI>Constants are preceded by <TT>#</TT> and must be defined in the header file.
<P>
<LI>Pointers to objects are simply the object's name.
</UL>
<P>Each type of callback requires a different set of parameters. The parameters needed
for each callback are documented in the "OI Programming Guide" available
from ParcPlace Systems.</P>
<P>Once a callback function has been specified and the application is saved, ObjectBuilder
updates the binding table in the binding file. This table tells the application which
external functions to call when the button is pressed or menu item is selected at
runtime. ObjectBuilder generates a function declaration and a callback stub in the
callback<TT> </TT>stubs file. In the configuration file one statement is generated
that states the specific callbacks for an object and a second that provides directions
for satisfying those callbacks when the application runs.</P>
<P>You must add the C code for the functions to the callback stubs file (<TT>appname_cb.C</TT>)
using any text editor.
<CENTER>
<H4><A NAME="Heading32<FONT COLOR="#000077">Compiling and Testing the Application</FONT></H4>
</CENTER>
<P>Once the callback functions have been written you must compile and link the application
to the <TT>OI_Library</TT> files. First make sure that the makefile can find any
include files that are needed, as well as the <TT>OI_Library</TT> files, by editing
the following statements in the makefile. You need to do this only if the include
and OI files are not in the same directory as the application.<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">INC = $$OI_LIB/../../include
OILIB = -L$$OI_LIB/../-1OI
</FONT></PRE>
<P>The <TT>$$</TT> ensures that the environment variable <TT>OI_LIB</TT> is used
to find the libraries and the include files.</P>
<P>Compile and link the application by typing the following command in the directory
where the application was saved:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">make
</FONT></PRE>
<P>When this finishes, you can run the application by typing the application name
at the prompt.</P>
<P>If you want to make any changes, simply load the application into ObjectBuilder
using the following command:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">uib appname
</FONT></PRE>
<CENTER>
<H3><A NAME="Heading33<FONT COLOR="#000077">Summary</FONT></H3>
</CENTER>
<P>The visual aspect of ObjectBuilder enables you to drag and drop objects and their
resources into your application. ObjectBuilder does the rest of your user interface
development by generating C code to produce the behavior and appearance of the objects
that you put into your application. This saves you a great deal of time because a
significant amount of the entire development of an application is spent on the user
interface.</P>
<P>ObjectBuilder further helps you by defining the skeleton for the rest of the application.
Although you still have to write the core of your application, using ObjectBuilder
can save you vast amounts of time. Once you know the basic objects available in the
OI library and their hierarchy, creating a GUI or front end for an X Window application
using ObjectBuilder is simple.
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -