📄 unx47.htm
字号:
**/
#define MAX_SCALE 1080
#define MIN_SCALE 800
static void
myfunction(Widget w, XtPointer dclient, XmScaleCallbackStruct *p)
{
int k;
k = p->value;
if ((k & 0x1) == 0) /** % 2 is zero ** check limits & increase **/
{
k++;
if (k >= MAX_SCALE) k = MIN_SCALE + 1;
if (k <= MIN_SCALE) k = MAX_SCALE - 1;
XmScaleSetValue(w,k); /** this will redisplay it too
**/
}
}</PRE>
<H3 ALIGN="CENTER">
<CENTER><A ID="I18" NAME="I18">
<FONT SIZE=4><B>The Text Widget</B>
<BR></FONT></A></CENTER></H3>
<P>The Text widget allows the user to type in text. This text can be multi-line, and the Text widget provides full text editing capabilities. If you are sure you want only single-line input from the user, you can specify the TextField widget. This is
simply a scaled-down version of the Text widget. The resources for both are the same unless explicitly stated. These include:
<BR></P>
<UL>
<LI>XmNvalue: A character string, just like in C. This is different from Motif 1.1 or older, where this value was a compound string. If you have Motif 1.2 or later, this will be C string.
<BR>
<BR></LI>
<LI>XmNmarginHeight and XmNmarginWidth: The number of pixels between the widget border and the text. The default is 5 pixels.
<BR>
<BR></LI>
<LI>XmNmaxLength: This sets the limit on the number of characters in the XmNvalue resource.
<BR>
<BR></LI>
<LI>XmNcolumns: The number of characters per line.
<BR>
<BR></LI>
<LI>XmNcursorPosition: The number of characters at the cursor position from the beginning of the text file.
<BR>
<BR></LI>
<LI>XmNeditable: The Boolean value that, if set to TRUE, will allow the user to insert text.
<BR>
<BR></LI></UL>
<P>The callbacks for this widget are:
<BR></P>
<UL>
<LI>XmNactivateCallback: Called when the user presses the Return key.
<BR>
<BR></LI>
<LI>XmNfocusCallback: Called when the widget receives focus from the pointer.
<BR>
<BR></LI>
<LI>XmNlosingFocusCallback: Called when the widget loses focus from the pointer.
<BR>
<BR></LI></UL>
<P>There are several convenience functions for this widget:
<BR></P>
<UL>
<LI>XmTextGetString(Widget w) returns a C string (char *).
<BR>
<BR></LI>
<LI>XmTextSetString(Widget w, char *s) sets a string for a widget.
<BR>
<BR></LI>
<LI>XmTextSetEditable(Widget w, Boolean trueOrFalse) sets the editable string of the widget.
<BR>
<BR></LI>
<LI>XmTextInsert(Widget w, XmTextPosition pos, char *s) sets the text at the position defined by pos. This XmTextPosition is an opaque item defining the index in the text array.
<BR>
<BR></LI>
<LI>XmTextShowPosition(Widget w, XmTextPosition p) scrolls to show the rest of the string at the position p.
<BR>
<BR></LI>
<LI>XmTextReplace(Widget w, XmTextPosition from, XmTextPosition to, char *s) replaces the string starting from the location from inclusive to the position to, with the characters in string s.
<BR>
<BR></LI>
<LI>XmTextRemove(Widget w) clears the text in a string.
<BR>
<BR></LI>
<LI>XmTextCopy(Widget w, Time t) copies the currently selected text to the Motif clipboard. The Time t value is derived from the most recent XEvent (usually in a callback), which is used by the clipboard to take the most recent entry.
<BR>
<BR></LI>
<LI>XmTextCut(Widget w, Time t) is like XmTextCopy, but removes the selected text from the text's buffer.
<BR>
<BR></LI>
<LI>XmTextPaste(Widget w) pastes the contents of the Motif clipboard onto the text area at the current cursor (insertion) position.
<BR>
<BR></LI>
<LI>XmTextClearSelection(Widget w, XmTextPosition p, XmTextPosition q, Time t) selects the text from location p to location q.
<BR>
<BR></LI></UL>
<P>In the following example, you could construct a sample editor application with the Text widget. For the layout of the buttons, you would use widgets of the XmManager class to manage the layout for you. These manager widgets are:
<BR></P>
<UL>
<LI>XmBulletinBoard
<BR>
<BR></LI>
<LI>XmRowColumn
<BR>
<BR></LI>
<LI>XmForm
<BR>
<BR></LI></UL>
<H3 ALIGN="CENTER">
<CENTER><A ID="I19" NAME="I19">
<FONT SIZE=4><B>The Bulletin Board Widget</B>
<BR></FONT></A></CENTER></H3>
<P>The Bulletin Board widget allows the programmer to lay out widgets by specifying their XmNx and XmNy resources. These values are relative to the top left corner of the Bulletin Board widget. The Bulletin Board widget will not move the children widget
around on itself. If a widget resizes, it's the application's responsibility to resize and restructure its widgets on the Bulletin Board.
<BR></P>
<P>The resources for the widget are:
<BR></P>
<UL>
<LI>XmNshadowType: Specifies the type of shadow for this widget. It can be set to XmSHADOW_OUT (the default), XmSHADOW_ETCHED_IN, XmSHADOW_ETCHED_OUT, or XmSHADOW_IN.
<BR>
<BR></LI>
<LI>XmNshadowThickness: The number of pixels for the shadow. This is defaulted to 0 (no shadow).
<BR>
<BR></LI>
<LI>XmNallowOverlap: Allows the children to be overlapped as they are laid on the widget. This is a Boolean resource and is defaulted to TRUE.
<BR>
<BR></LI>
<LI>XmNresizePolicy: Specifies the resize policy for managing itself. If set to XmRESIZE_NONE, it will not change its size. If set to XmRESIZE_ANY, it will grow or shrink to attempt to accommodate all its children automatically. This is the default. If set
to XmRESIZE_GROW, it will grow, but never shrink, automatically.
<BR>
<BR></LI>
<LI>XmNbuttonFontList: Specifies the font for all XmPushButton children.
<BR>
<BR></LI>
<LI>XmNlabelFontList: Specifies the default font for all widgets derived from XmLabel.
<BR>
<BR></LI>
<LI>XmNtextFontList: Specifies the default font for all Text, TextField, and XmList children.
<BR>
<BR></LI></UL>
<P>It also provides the callback XmNfocusCallback, which is called when any children of the Bulletin Board receives focus.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I20" NAME="I20">
<FONT SIZE=4><B>The </B><B><I>RowColumn </I></B><B>Widget</B>
<BR></FONT></A></CENTER></H3>
<P>The RowColumn widget class orders its children in a row or columnar fashion. This is used to set up menus, menu bars, and radio buttons. The resources provided by this widget include:
<BR></P>
<UL>
<LI>XmNorientation: XmHORIZONTAL for a row major layout of its children; XmVERTICAL for a column major layout.
<BR>
<BR></LI>
<LI>XmNnumColumns: Specifies the number of rows for a vertical widget and the number of columns for a horizontal widget.
<BR>
<BR></LI>
<LI>XmNpacking: Determines how the children are packed. XmPACK_TIGHT allows the children to specify their own size. It fits children in a row (or column if XmHORIZONTAL), and then starts a new row if no space is available. XmPACK_NONE forces Bulletin
Board-like behavior. XmPACK_COLUMN forces all children to be the size of the largest column. This uses the XmNnumColumns resource and places all its children in an organized manner.
<BR>
<BR></LI>
<LI>XmNentryAlignment: Specifies which part of the children to use in its layout alignment. Its default is XmALIGNMENT_CENTER, but it can be set to XmALIGNMENT_BEGINNING for the left side or XmALIGNMENT_END for the right side. This is on a per column
basis.
<BR>
<BR></LI>
<LI>XmNverticalEntryAlignment: Specifies the alignment on a per row basis. It can be assigned a value of XmALIGNMENT_BASELINE_BOTTOM, XmALIGNMENT_BASELINE_TOP, XmALIGNMENT_CONTENTS_BOTTOM, XmALIGNMENT_CONTENTS_TOP, or XmALIGNMENT_CENTER.
<BR>
<BR></LI>
<LI>XmNentryBorder: The thickness of a border drawn around all children, and is defaulted to 0.
<BR>
<BR></LI>
<LI>XmNresizeWidth: A Boolean variable that, if set to TRUE, will allow the RowColumn widget to resize its width when necessary.
<BR>
<BR></LI>
<LI>XmNresizeHeight: A Boolean variable that, if set to TRUE, will allow the RowColumn widget to resize its height when necessary.
<BR>
<BR></LI>
<LI>XmNradioBehaviour: Works with toggle buttons only. It allows only one toggle button in a group of buttons to be active at a time. The default is FALSE.
<BR>
<BR></LI>
<LI>XmNisHomogeneous: If set to TRUE, this specifies that only children of the type Class in XmNentryClass can be children of this widget. The default is FALSE.
<BR>
<BR></LI>
<LI>XmNentryClass: Specifies the class of children allowed in this widget if XmNisHomogeneous is TRUE. A sample radio button application was shown in file 47_5c. To see another example of the same listing but with two columns, see file 47_8c on the CD-ROM.
<BR>
<BR></LI></UL>
<H3 ALIGN="CENTER">
<CENTER><A ID="I21" NAME="I21">
<FONT SIZE=4><B>The Form Widget</B>
<BR></FONT></A></CENTER></H3>
<P>The beginning of the chapter introduced you to the workings of the Form widget. This is the most flexible and most complex widget in Motif. Its resources include:
<BR></P>
<UL>
<LI>XmNtopAttachment
<BR>
<BR></LI>
<LI>XmNleftAttachment
<BR>
<BR></LI>
<LI>XmNrightAttachment
<BR>
<BR></LI>
<LI>XmNbottomAttachment
<BR>
<BR></LI></UL>
<P>These values specify how a child is placed. The following values correspond to each side of the widget:
<BR></P>
<PRE>
<BR>XmATTACH_NONE: Do not attach this side to Form.
<BR>XmATTACH_FORM: Attach to corresponding side on Form.
<BR>XmATTACH_WIDGET: Attach this side to opposite side of a reference widget. For example, attach the right side of this widget to the left side of the reference widget. A reference widget is another child on the same form.
<BR>XmATTACH_OPPOSITE_WIDGET: Attach this side to same side of a reference widget. This is rarely used.
<BR>XmATTACH_POSITION: Attach a side by the number of pixels shown in XmNtopPosition, XmNleftPosition, XmNrightPosition, and XmNbottomPosition resources, respectively.
<BR>XmATTACH_SELF: Use XmNx, XmNy, XmNheight, and XmNwidth.</PRE>
<P>The following resources are set to the corresponding widgets for each side for the XmATTACH_WIDGET setting in an attachment:
<BR></P>
<UL>
<LI>XmNtopWidget
<BR>
<BR></LI>
<LI>XmNleftWidget
<BR>
<BR></LI>
<LI>XmNrightWidget
<BR>
<BR></LI>
<LI>XmNbottomWidget
<BR>
<BR></LI></UL>
<P>The following resources are the number of pixels a side of a child is offset from the corresponding Form side. The offset is used when the attachment is XmATTACH_FORM.
<BR></P>
<UL>
<LI>XmNtopOffset
<BR>
<BR></LI>
<LI>XmNleftOffset
<BR>
<BR></LI>
<LI>XmNrightOffset
<BR>
<BR></LI>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -