📄 misc.c
字号:
posting, and it is very annoying. See "man VendorShell" for more info. */ XtVaSetValues(shell, XmNuseAsyncGeometry, True, NULL); /* Set desired window position in the DialogShell */ XtVaSetValues(shell, XmNx, x, XmNy, y, NULL); } /* Map the widget */ XtMapWidget(shell); /* Restore the value of XmNmappedWhenManaged */ XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);}/*** Cause dialogs created by libNUtil.a routines (such as DialogF),** and dialogs which use ManageDialogCenteredOnPointer to pop up** over the pointer (state = True), or pop up in their default** positions (state = False)*/void SetPointerCenteredDialogs(int state){ PointerCenteredDialogsEnabled = state;}/*** Raise a window to the top and give it the input focus. Setting input focus** is important on systems which use explict (rather than pointer) focus.**** The X alternatives XMapRaised, and XSetInputFocus both have problems.** XMapRaised only gives the window the focus if it was initially not visible,** and XSetInputFocus sets the input focus, but crashes if the window is not** visible.**** This routine should also be used in the case where a dialog is popped up and** subsequent calls to the dialog function use a flag, or the XtIsManaged, to** decide whether to create a new instance of the dialog, because on slower** systems, events can intervene while a dialog is still on its way up and its** window is still invisible, causing a subtle crash potential if** XSetInputFocus is used.*/void RaiseShellWindow(Widget shell){ RaiseWindow(XtDisplay(shell), XtWindow(shell));}void RaiseWindow(Display *display, Window w){ XWindowAttributes winAttr; XGetWindowAttributes(display, w, &winAttr); if (winAttr.map_state == IsViewable) XSetInputFocus(display, w, RevertToParent, CurrentTime); XMapRaised(display, w);}/*** Add a handler for mnemonics in a dialog (Motif currently only handles** mnemonics in menus) following the example of M.S. Windows. To add** mnemonics to a dialog, set the XmNmnemonic resource, as you would in** a menu, on push buttons or toggle buttons, and call this function** when the dialog is fully constructed. Mnemonics added or changed** after this call will not be noticed. To add a mnemonic to a text field** or list, set the XmNmnemonic resource on the appropriate label and set** the XmNuserData resource of the label to the widget to get the focus** when the mnemonic is typed.*/void AddDialogMnemonicHandler(Widget dialog, int unmodifiedToo){ XtAddEventHandler(dialog, KeyPressMask, False, (XtEventHandler)mnemonicCB, (XtPointer)0); addMnemonicGrabs(dialog, dialog, unmodifiedToo);}/*** Removes the event handler and key-grabs added by AddDialogMnemonicHandler*/void RemoveDialogMnemonicHandler(Widget dialog){ XtUngrabKey(dialog, AnyKey, Mod1Mask); XtRemoveEventHandler(dialog, KeyPressMask, False, (XtEventHandler)mnemonicCB, (XtPointer)0);}/*** Patch around Motif's poor handling of menu accelerator keys. Motif** does not process menu accelerators when the caps lock or num lock** keys are engaged. To enable accelerators in these cases, call this** routine with the completed menu bar widget as "topMenuContainer", and** the top level shell widget as "topWidget". It will add key grabs for** all of the accelerators it finds in the topMenuContainer menu tree, and** an event handler which can process dropped accelerator events by (again)** traversing the menu tree looking for matching accelerators, and invoking** the appropriate button actions. Any dynamic additions to the menus** require a call to UpdateAccelLockPatch to add the additional grabs.** Unfortunately, these grabs can not be removed.*/void AccelLockBugPatch(Widget topWidget, Widget topMenuContainer){ XtAddEventHandler(topWidget, KeyPressMask, False, lockCB, topMenuContainer); addAccelGrabs(topWidget, topMenuContainer);}/*** Add additional key grabs for new menu items added to the menus, for** patching around the Motif Caps/Num Lock problem. "topWidget" must be** the same widget passed in the original call to AccelLockBugPatch.*/void UpdateAccelLockPatch(Widget topWidget, Widget newButton){ addAccelGrab(topWidget, newButton);}/*** PopDownBugPatch**** Under some circumstances, popping down a dialog and its parent in** rapid succession causes a crash. This routine delays and** processs events until receiving a ReparentNotify event.** (I have no idea why a ReparentNotify event occurs at all, but it does** mark the point where it is safe to destroy or pop down the parent, and** it might have something to do with the bug.) There is a failsafe in** the form of a ~1.5 second timeout in case no ReparentNotify arrives.** Use this sparingly, only when real crashes are observed, and periodically** check to make sure that it is still necessary.*/void PopDownBugPatch(Widget w){ time_t stopTime; stopTime = time(NULL) + 1; while (time(NULL) <= stopTime) { XEvent event; XtAppContext context = XtWidgetToApplicationContext(w); XtAppPeekEvent(context, &event); if (event.xany.type == ReparentNotify) return; XtAppProcessEvent(context, XtIMAll); }}/*** Convert a compound string to a C style null terminated string.** Returned string must be freed by the caller.*/char *GetXmStringText(XmString fromString){ XmStringContext context; char *text, *toPtr, *toString, *fromPtr; XmStringCharSet charset; XmStringDirection direction; Boolean separator; /* Malloc a buffer large enough to hold the string. XmStringLength should always be slightly longer than necessary, but won't be shorter than the equivalent null-terminated string */ toString = XtMalloc(XmStringLength(fromString)); /* loop over all of the segments in the string, copying each segment into the output string and converting separators into newlines */ XmStringInitContext(&context, fromString); toPtr = toString; while (XmStringGetNextSegment(context, &text, &charset, &direction, &separator)) { for (fromPtr=text; *fromPtr!='\0'; fromPtr++) *toPtr++ = *fromPtr; if (separator) *toPtr++ = '\n'; } /* terminate the string, free the context, and return the string */ *toPtr++ = '\0'; XmStringFreeContext(context); return toString;}/*** Get the XFontStruct that corresponds to the default (first) font in** a Motif font list. Since Motif stores this, it saves us from storing** it or querying it from the X server.*/XFontStruct *GetDefaultFontStruct(XmFontList font){ XFontStruct *fs; XmFontContext context; XmStringCharSet charset; XmFontListInitFontContext(&context, font); XmFontListGetNextFont(context, &charset, &fs); XmFontListFreeFontContext(context); XtFree(charset); return fs;} /*** Create a string table suitable for passing to XmList widgets*/XmString* StringTable(int count, ... ){ va_list ap; XmString *array; int i; char *str; va_start(ap, count); array = (XmString*)XtMalloc((count+1) * sizeof(XmString)); for(i = 0; i < count; i++ ) { str = va_arg(ap, char *); array[i] = XmStringCreateSimple(str); } array[i] = (XmString)0; va_end(ap); return(array);}void FreeStringTable(XmString *table){ int i; for(i = 0; table[i] != 0; i++) XmStringFree(table[i]); XtFree((char *)table);}/*** Simulate a button press. The purpose of this routine is show users what** is happening when they take an action with a non-obvious side effect,** such as when a user double clicks on a list item. The argument is an** XmPushButton widget to "press"*/ void SimulateButtonPress(Widget widget){ XEvent keyEvent; memset((char *)&keyEvent, 0, sizeof(XKeyPressedEvent)); keyEvent.type = KeyPress; keyEvent.xkey.serial = 1; keyEvent.xkey.send_event = True; if (XtIsSubclass(widget, xmGadgetClass)) { /* On some Motif implementations, asking a gadget for its window will crash, rather than return the window of its parent. */ Widget parent = XtParent(widget); keyEvent.xkey.display = XtDisplay(parent); keyEvent.xkey.window = XtWindow(parent); XtCallActionProc(parent, "ManagerGadgetSelect", &keyEvent, NULL, 0); } else { keyEvent.xkey.display = XtDisplay(widget); keyEvent.xkey.window = XtWindow(widget); XtCallActionProc(widget, "ArmAndActivate", &keyEvent, NULL, 0); }}/*** Add an item to an already established pull-down or pop-up menu, including** mnemonics, accelerators and callbacks.*/Widget AddMenuItem(Widget parent, char *name, char *label, char mnemonic, char *acc, char *accText, XtCallbackProc callback, void *cbArg){ Widget button; XmString st1, st2; button = XtVaCreateManagedWidget(name, xmPushButtonWidgetClass, parent, XmNlabelString, st1=XmStringCreateSimple(label), XmNmnemonic, mnemonic, XmNacceleratorText, st2=XmStringCreateSimple(accText), XmNaccelerator, acc, NULL); XtAddCallback(button, XmNactivateCallback, callback, cbArg); XmStringFree(st1); XmStringFree(st2); return button;}/*** Add a toggle button item to an already established pull-down or pop-up** menu, including mnemonics, accelerators and callbacks.*/Widget AddMenuToggle(Widget parent, char *name, char *label, char mnemonic, char *acc, char *accText, XtCallbackProc callback, void *cbArg, int set){ Widget button; XmString st1, st2; button = XtVaCreateManagedWidget(name, xmToggleButtonWidgetClass, parent, XmNlabelString, st1=XmStringCreateSimple(label), XmNmnemonic, mnemonic, XmNacceleratorText, st2=XmStringCreateSimple(accText), XmNaccelerator, acc, XmNset, set, NULL); XtAddCallback(button, XmNvalueChangedCallback, callback, cbArg); XmStringFree(st1); XmStringFree(st2); return button;}/*** Add a separator line to a menu*/Widget AddMenuSeparator(Widget parent, char *name){ Widget button; button = XmCreateSeparator(parent, name, NULL, 0); XtManageChild(button); return button;}/*** Add a sub-menu to an established pull-down or pop-up menu, including** mnemonics, accelerators and callbacks. Returns the menu pane of the** new sub menu.*/Widget AddSubMenu(Widget parent, char *name, char *label, char mnemonic){ Widget menu; XmString st1; menu = CreatePulldownMenu(parent, name, NULL, 0); XtVaCreateManagedWidget(name, xmCascadeButtonWidgetClass, parent, XmNlabelString, st1=XmStringCreateSimple(label), XmNmnemonic, mnemonic, XmNsubMenuId, menu, NULL); XmStringFree(st1); return menu;}/*** SetIntLabel, SetFloatLabel, SetIntText, SetFloatText**** Set the text of a motif label or text widget to show an integer or** floating number.*/void SetIntLabel(Widget label, int value){ char labelString[20]; XmString s1; sprintf(labelString, "%d", value); s1=XmStringCreateSimple(labelString); XtVaSetValues(label, XmNlabelString, s1, NULL); XmStringFree(s1);}void SetFloatLabel(Widget label, double value){ char labelString[20]; XmString s1; sprintf(labelString, "%g", value); s1=XmStringCreateSimple(labelString); XtVaSetValues(label, XmNlabelString, s1, NULL); XmStringFree(s1);}void SetIntText(Widget text, int value){ char labelString[20]; sprintf(labelString, "%d", value); XmTextSetString(text, labelString);}void SetFloatText(Widget text, double value){ char labelString[20]; sprintf(labelString, "%g", value); XmTextSetString(text, labelString);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -