[ Pobierz całość w formacie PDF ]
.A sample function, myfunction(),follows:/***** Partial listing for not allowing even numbers for FM selection.**/#define MAX_SCALE 1080#define MIN_SCALE 800static void myfunction(Widget w, XtPointer dclient, XmScaleCallbackStruct *p){int k;k = p->value;if ((k & 0x1) == 0) /** % 2 is zero ** check limits and 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 **/}}Text WidgetsThis Widget enables the user to type in text and provides full text-editing capabilities.This text could be multiline or single-line.If you are sure you want only single-lineinput from the user, you can specify the TextField Widget.This is simply a scaled-downversion of the Text Widget.The resources for both are the same unless explicitlystated.They include the following: XmNvalue: A character string, just likein C.This is different from Motif 1.1 or older, in which this value used to be acompound string.If you have Motif 1.2 or later, this will be C string.XmNmarginHeight and XmNmarginWidth: The number of pixels oneither side of the Widget.The default is five pixels.XmNmaxLength: Sets the limit on the number of characters in the XmNvalueresource.XmNcolumns: The number of characters per line.XmNcursorPosition: The number of characters at the cursor position fromthe beginning of the text file.XmNeditable: Boolean value.If set to TRUE, enables the user to insert text.The callbacks for this Widget are XmNactivateCallback: Called when the userpresses the Enter key.XmNfocusCallback: Called when the Widget receives focus from the pointer.XmNlosingFocusCallback: Called when the Widget loses focus from the pointer.This Widget has several convenience functions: XmTextGetString(Widget w)returns a C string (char *).XmTextSetString(Widget w, char *s) sets a string for a Widget.XmTextSetEditable(Widget w, Boolean TRUEOrFALSE) sets the Widget's editablestring.XmTextInsert(Widget w, XmTextPosition pos, char *s) sets the text atthe position defined by pos.This XmTextPosition is an opaque itemdefining the index in the text array.XmTextShowPosition(Widget w, XmTextPosition p) scrolls to show the restof the string at position p.XmTextReplace(Widget w, XmTextPosition from, XmTextPosition to, char *s)replaces the string starting from the location from inclusive to the positionto, inclusive with the characters in string s.XmTextRemove(Widget w) clears the text in a string.XmTextCopy(Widget w, Time t) copies the currently selected text to theMotif 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.XmTextCut(Widget w, Time t) is similar to XmTextCopy but removesthe selected text from the text's buffer.XmTextPaste(Widget w) pastes the contents of the Motif clipboard ontothe text area at the current cursor (insertion) position.XmTextClearSelection(Widget w, XmTextPosition p, XmTextPosition q, Time t)selects the text from location p to location q.In the following example, you could construct a sample editor application using theText Widget.For the layout of the buttons, you would want to use Widgets of theXmManager class to manage the layout for you rather than having to do itin your own application.These Manager Widgets are XmBulletinBoardXmRowColumnXmFormXmBulletinBoardWidgetsThe BulletinBoard class enables the programmer to lay out Widgets ona BulletinBoard by specifying their XmNx and XmNy resources.These values are relative to the top-left corner of the BulletinBoard Widget.The BulletinBoard will not move its child Widgets around by itself.If aWidget resizes, it's the application's responsibility to resize and restructure itsWidgets on the BulletinBoard.The resources for the Widget are as follows: XmNshadowType: Specifiesthe type of shadow for this Widget.It can be set to XmSHADOW_OUT (the default),XmSHADOW_ETCHED_IN, XmSHADOW_ETCHED_OUT, or XmSHADOW_IN.XmNshadowThickness: The number of pixels for the shadow.This is defaultedto 0 to not see a shadow.XmNallowOverlap: Enables the children to be overlapped as they are laidon the Widget.This is a Boolean resource and is defaulted to TRUE.XmNresizePolicy: Specifies the resize policy for managing itself.Ifset to XmRESIZE_NONE, it will not change its size.If set to XmRESIZE_ANY,the default, it will grow or shrink to attempt to accommodate all of its childrenautomatically.If set to XmRESIZE_GROW, it will grow only, never shrink,automatically.XmNbuttonFontList: Specifies the font for all XmPushButton children.XmNlabelFontList: Specifies the default font for all Widgets derivedfrom XmLabel.XmNtextFontList: Specifies the default font for all Text, TextField,and XmList children
[ Pobierz całość w formacie PDF ]