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

📄 unx47.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<LI>XmNbottomOffset

<BR>

<BR></LI></UL>

<P>Sometimes it is hard to get the settings for a Form widget just right, or the Form widget does not lay out the widgets in what seems to be the proper setting for a child widget. In these cases, lay the children out in ascending or descending order from 

the origin of the Form widget. That is, create the top left widget first and use it as an &quot;anchor&quot; to create the next child, then the next one to its right, and so on. There is no guarantee that this will work, so try using the bottom right, 
bottom left, or top right for your anchor positions.

<BR></P>

<P>If this technique does not work, try using two forms on top of the form you're working with. Forms are cheap, and your time is not. It's better to just make a form when two or more widgets have to reside in a specific layout.

<BR></P>

<P>When you're trying a new layout on a Form widget, if you get error messages about failing after 10,000 iterations, it means you have conflicting layout requests to one or more child widgets. Check the attachments very carefully before proceeding. This 
error message results from the Form widget trying different layout schemes to accommodate your request.

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="imp.gif" WIDTH = 68 HEIGHT = 35><B>TIP:</B> At times, conflicting requests to a form will cause your application to slow down while it's trying to accommodate your request, not show the form, or both.

<BR></NOTE>

<HR ALIGN=CENTER>

<H3 ALIGN="CENTER">

<CENTER><A ID="I22" NAME="I22">

<FONT SIZE=4><B>Designing Layouts</B>

<BR></FONT></A></CENTER></H3>

<P>When you're designing layouts, think about the layout before you start writing code. Let's try an album search front-end example. See file 47_9c on the CD-ROM.

<BR></P>

<P>The application is shown in Figure 47.9. Notice how the labels do not line up with the Text widget. There is a problem in the hierarchy of the setup. See the hierarchy of the application in Figure 47.10.

<BR></P>

<P>

<BR><B><A HREF="47unx09.gif">Figure 47.9.  The output of Listing 47.9.</A></B>

<BR></P>

<P>

<BR><B><A HREF="47unx10.gif">Figure 47.10. The hierarchy of Listing 47.9.</A></B>

<BR></P>

<P>The Form widgets are created to maintain the relative placements of all widgets that correspond to a type of function. The RowColumn widgets allow items to be placed on them. The best route to take in this example is to lay one text and one label on one 

RowColumn widget and have three RowColumn widgets in all, one for each instance up to NUM_ITEMS. This will ensure that each label lines up with its corresponding Text widget.

<BR></P>

<P>A couple of points to note about laying out applications:

<BR></P>

<UL>

<LI>Think about what you want the form or dialog to do. Draw it on paper if you have to. Coding is the easy part; determining what to do is much harder.

<BR>

<BR></LI>

<LI>Be consistent. Users will love you for it. If Alt+x is a shortcut for &quot;Exit&quot; in one screen, do not make it a cut operator in another. Keep controls on the same side of all dialog boxes and forms. Use separators to separate different functions 

on the same window.

<BR>

<BR></LI>

<LI>Choose a color scheme for your end users. What may be cool to you may be grotesque to the end user. They may not even be using a color monitor in some rare cases. A combination of white, gray, and black may be your best bet if you don't want to deal 
with different color schemes in your code.

<BR>

<BR></LI>

<LI>Colors on your monitor may not be the same on the end user's monitor.

<BR>

<BR></LI>

<LI>Do not assume that the user's monitor has the same resolution as yours. Keep fonts (and buttons) big enough for a large cursor. Allow windows to be resizeable as much as possible to allow the user to customize his desktop.

<BR>

<BR></LI>

<LI>Assume nothing. If the user can size your window to an unworkable size, either limit the size in resizeCallback to the lowest size or don't allow sizing at all.

<BR>

<BR></LI>

<LI>Offer some help for the user. In the future, Help will be required as a standard option on menu bars, so plan ahead.

<BR>

<BR></LI>

<LI>Avoid clutter. Too many options and entries on one huge form tend to confuse and baffle the user. Consider two tiers or more. Default everything as much as possible.

<BR>

<BR></LI>

<LI>Make the program more forgiving. Sometimes an &quot;Are you sure?&quot; dialog with an option to change a list of parameters can be endearing to a user. On the other hand, some users hate this type of checking.

<BR>

<BR></LI></UL>

<H3 ALIGN="CENTER">

<CENTER><A ID="I23" NAME="I23">

<FONT SIZE=4><B>Menus</B>

<BR></FONT></A></CENTER></H3>

<P>The way you design widget hierarchies is especially important when you're working with Motif menus. Motif menus are a collection of widgets, so there is no &quot;menu&quot; widget for a menu. You create menus using a hierarchy of different types of 
widgets: RowColumn, PushButton, CascadeButton, ToggleButton, Label, and Separator.

<BR></P>

<P>There are three kinds of menus in Motif:

<BR></P>

<UL>

<LI>Popup: This appears as a list of items when a pointer button is pressed on a widget.

<BR>

<BR></LI>

<LI>Pulldown: This appears when a button on an existing menu is pressed.

<BR>

<BR></LI>

<LI>Option: This allows the user to select from a list of options, with the current selection visible at all times.

<BR>

<BR></LI></UL>

<P>The procedure to create a menu is different for each type of menu.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I24" NAME="I24">

<FONT SIZE=3><B>Popup</B>

<BR></FONT></A></CENTER></H4>

<P>To create a Popup menu, do the following:

<BR></P>

<OL>

<LI>Include the correct header files. You will need the header files for the menu:

<BR>

<BR>Label.h

<BR>

<BR>RowColumn.h

<BR>

<BR>PushB.h

<BR>

<BR>Separator.h

<BR>

<BR>BulletinB.h

<BR>

<BR>CascadeB.h

<BR>

<BR></LI>

<LI>Create the menu pane with a call to XmCreatePopupMenu. This is a convenience call to create a RowColumn widget and a MenuShell widget with the proper settings.

<BR>

<BR></LI>

<LI>Create the buttons on the menu pane. Use XmPushbuttons, XmToggleButtons, XmSeparator, and XmCascadeButtons.

<BR>

<BR></LI>

<LI>Attach callback functions to the widgets.

<BR>

<BR></LI></OL>

<P>See file 47_10c on the CD-ROM for a listing that sets up a pop-up menu.

<BR></P>

<P>Note three important items about this listing: You can use printf functions within Motif applications. The output goes to the controlling terminal by default. This is invaluable in debugging. The menu is not visible by itself. An event handler on the 
parent of the menu is registered before the menu can be displayed. This allows the menu to be displayed any time a button is pressed. The XmMenuPosition call sets the position of the Popup menu. It is then managed (after placement).

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I25" NAME="I25">

<FONT SIZE=3><B>The Menu Bar</B>

<BR></FONT></A></CENTER></H4>

<P>A menu bar is a horizontal bar that is continually available to the user. Motif uses the RowColumn widget as a bar, with cascading buttons for each option.

<BR></P>

<P>The procedure for creating a menu bar is as follows:

<BR></P>

<OL>

<LI>Include the correct header files. You will need the header files for the menu:

<BR>

<BR>Label.h       RowColumn.h

<BR>

<BR>PushB.h       Separator.h

<BR>

<BR>BulletinB.h   CascadeB.h

<BR>

<BR></LI>

<LI>Create the menu bar with a call to XmCreateMenuBar().

<BR>

<BR></LI>

<LI>Create the pull-down menu panes with a call to XmCreatePulldownMenu().

<BR>

<BR></LI>

<LI>For each pull-down pane, create a cascade button on the menu bar. Use the menu bar as the parent. A cascade button is used to link the items in a menu with the menu bar itself.

<BR>

<BR></LI>

<LI>Attach the menu pane to its corresponding cascade button. Use the XmNsubMenuId resource of the cascade button on the appropriate menu pane.

<BR>

<BR></LI>

<LI>Create the menu entries in the menu panes.

<BR>

<BR></LI></OL>

<P>File 47_1k on the CD-ROM shows how to set up a menu bar and pull-down menus.

<BR></P>

<P>Note that the Motif programming style requires you to make the Help button (if you have one) right-justified on the menu bar. This Help cascade button should then be set to the XmNmenuHelpWidget of a menu bar. The menu bar will automatically position 
this widget at the right-hand side of the visible bar.

<BR></P>

<P>File 47_12c on the CD-ROM is another example of setting up a menu bar and pull-down menus.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I26" NAME="I26">

<FONT SIZE=3><B>The Options Menu</B>

<BR></FONT></A></CENTER></H4>

<P>The Options menu allows the user to select from a list of items, and displays the most recently selected item. The procedure for creating an Options menu is similar to creating a menu bar.

<BR></P>

<OL>

<LI>Include the correct header files. You will need the header files for the menu:

<BR>

<BR>Label.h         Separator.h

<BR>

<BR>RowColumn.h     BulletinB.h

<BR>

<BR>PushB.h         CascadeB.h

<BR>

<BR></LI>

<LI>Create the menu bar with a call to XmCreateOptionMenu().

<BR>

<BR></LI>

<LI>Create the pull-down menu panes with a call to XmCreatePulldownMenu().

<BR>

<BR></LI>

<LI>For each pull-down pane, create a cascade button on the menu bar.

<BR>

<BR></LI>

<LI>Attach the menu pane to its corresponding cascade button. Use the XmNsubMenuId resource of the cascade button on the appropriate menu pane.

<BR>

<BR></LI>

<LI>Create the menu entries in the menu panes.

<BR>

<BR></LI></OL>

<H4 ALIGN="CENTER">

<CENTER><A ID="I27" NAME="I27">

<FONT SIZE=3><B>Accelerators and Mnemonics</B>

<BR></FONT></A></CENTER></H4>

<P>A menu item's accelerator is a keystroke that invokes the callback for that particular item. For example, to open a file you could use Ctrl+O. The resource for this accelerator could be set in the resource file as the following:

<BR></P>

<PRE>*Open*accelerator: Ctrl&lt;Key&gt;O</PRE>

<P>The corresponding menu item should read &quot;Open Ctrl+O&quot; to make the user aware of this shortcut. You can also set this resource through the following command in the .Xresources file:

<BR></P>

<PRE>*Open*acceleratorText: &quot;Ctrl+O&quot;</PRE>

<P>Using the .Xresource file is the preferred way of setting these resources.

<BR></P>

<P>Mnemonics are a shorthand for letting users select menu items without using the mouse. For example, you could use &lt;meta&gt;F for invoking the File menu. These are usually set in the .Xresources file as well. The syntax for the File menu to use the 
&lt;meta&gt;F key would be as follows:

<BR></P>

<PRE>*File*mnemonic: F</PRE>

<H3 ALIGN="CENTER">

<CENTER><A ID="I28" NAME="I28">

<FONT SIZE=4><B>Dialog Boxes</B>

<BR></FONT></A></CENTER></H3>

<P>A dialog box conveys information about something to the user, and receives one of a limited number of responses. For example, a dialog box could read &quot;Go Ahead and Print&quot; with three buttons&#151;OK, Cancel, and Help. The user would then select 

one of the three buttons.

<BR></P>

<P>A typical dialog box displays an icon, a message string, and (usually) three buttons. Motif provides predefined dialog boxes for the following categories: Errors, information, warnings, working, and question.

<BR></P>

<P>Each of the above dialog box types displays a different icon: a question mark for the Question dialog box, an exclamation mark for the Information dialog box, and so on. Convenience functions ease creation of dialog boxes:

<BR></P>

<UL>

<LI>XmCreateErrorsDialog

<BR>

<BR></LI>

<LI>XmCreateInformationDialog

<BR>

<BR></LI>

<LI>XmCreateWarningDialog

<BR>

<BR></LI>

<LI>XmCreateWorkingDialog

<BR>

<BR></LI>

<LI>XmCreateQuestionDialog

<BR>

<BR></LI></UL>

<P>The infamous &quot;Really Quit?&quot; dialog box can be implemented as shown in Listing 47.13. There is another example in file 47_17c on the CD-ROM.

<BR></P>

<P>Append this to the end of any listing to get instant verification before you actually quit the application.

<BR></P>

<P>Note that the quitDlg dialog box is set to NULL when the function is first called. I

⌨️ 快捷键说明

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