/**************************************************************** * * XmeReplyToQueryGeometry. * * This is the generic handling of Almost, No and Yes replies * based on the intended values and the given desirs. * * This can be used by any widget that really only care about is * width and height dimension. It just has to compute its desired size * using its own private layout routine and resources before calling * this one that will deal with the Xt reply value cuisine. * ****************/ XtGeometryResult XmeReplyToQueryGeometry(Widget widget, XtWidgetGeometry * intended, XtWidgetGeometry * desired) { _XmWidgetToAppContext(widget); /* the caller should have set desired width and height*/ desired->request_mode = (CWWidth | CWHeight) ; /* Accept any x, y, border and stacking. If the proposed geometry matches the desired one, and the parent intends to use these values (flags are set in intended), return Yes. Otherwise, the parent intends to use values for width and height that differ from the desired size, return No if the desired is the current and Almost if the desired size is different from the current size */ if ((IsWidth(intended)) && (intended->width == desired->width) && (IsHeight(intended)) && (intended->height == desired->height)) { return XtGeometryYes ; } _XmAppLock(app); if ((desired->width == XtWidth(widget)) && (desired->height == XtHeight(widget))) { _XmAppUnlock(app); return XtGeometryNo ; } _XmAppUnlock(app); return XtGeometryAlmost ; }
Boolean XmTextFindString(Widget w, XmTextPosition start, char* search_string, XmTextDirection direction, XmTextPosition *position) { XmSourceData data; Boolean ret_val; _XmWidgetToAppContext(w); if (XmIsTextField(w)) return False; _XmAppLock(app); data = ((XmTextWidget)w)->text.source->data; if (start > data->length) start = data->length; else if (start < 0) start = 0; if (direction == XmTEXT_BACKWARD) ret_val = _XmTextFindStringBackwards(w, start, search_string, position); else ret_val = _XmTextFindStringForwards(w, start, search_string, position); _XmAppUnlock(app); return (ret_val); }
Boolean XmTextFindStringWcs(Widget w, XmTextPosition start, wchar_t* wc_string, XmTextDirection direction, XmTextPosition *position) { wchar_t *tmp_wc; char *string; int num_chars = 0; Boolean return_val = False; XmTextWidget tw = (XmTextWidget) w; int wcs_ret_val = 0; _XmWidgetToAppContext(w); _XmAppLock(app); if (!XmIsTextField(w)) { for (num_chars = 0, tmp_wc = wc_string; *tmp_wc != (wchar_t)0L; num_chars++) tmp_wc++; string = XtMalloc ((unsigned) (num_chars + 1) * (int)tw->text.char_size); wcs_ret_val = wcstombs(string, wc_string, (num_chars + 1) * (int)tw->text.char_size); if (wcs_ret_val >= 0) return_val = XmTextFindString(w, start, string, direction, position); XtFree(string); _XmAppUnlock(app); return(return_val); } else { _XmAppUnlock(app); return False; } }
Widget XmCreateSimplePulldownMenu( Widget parent, String name, ArgList args, Cardinal arg_count ) { Widget rc; XmSimpleMenuRec mr; int n, i; Arg local_args[3]; WidgetList buttons; Cardinal num_buttons; _XmWidgetToAppContext(parent); _XmAppLock(app); XtGetSubresources(parent, &mr, name, XmCSimplePulldownMenu, SimpleMenuResources, XtNumber(SimpleMenuResources), args, arg_count); rc = XmCreatePulldownMenu(parent, name, args, arg_count); EvaluateConvenienceStructure(rc, &mr); if (mr.post_from_button >= 0) { n = 0; XtSetArg(local_args[n], XtNchildren, &buttons); n++; XtSetArg(local_args[n], XtNnumChildren, &num_buttons); n++; XtGetValues(parent, local_args, n); if (!num_buttons) { /* error condition */ _XmAppUnlock(app); return(rc); } else { for (i = 0; i < num_buttons; i++) { if (((XmIsCascadeButtonGadget(buttons[i])) || (XmIsCascadeButton(buttons[i]))) && (i == mr.post_from_button)) break; } if ( i < num_buttons) { n = 0; XtSetArg(local_args[n], XmNsubMenuId, rc); n++; XtSetValues(buttons[i], local_args, n); } } } _XmAppUnlock(app); return(rc); }
Widget XmGetDragContext( Widget w, Time time ) { XmDisplay xmDisplay; XmDragContext matchedDC = NULL, dc = NULL; Cardinal i; _XmWidgetToAppContext(w); _XmAppLock(app); xmDisplay = (XmDisplay)XmGetXmDisplay(XtDisplay(w)); for(i = 0; i < xmDisplay->composite.num_children; i++) { dc = (XmDragContext)(xmDisplay->composite.children[i]); if ((XmIsDragContext((Widget) dc)) && (CHECK_TIME(dc, time)) && ((!matchedDC) || (matchedDC->drag.dragStartTime < dc->drag.dragStartTime)) && !dc->core.being_destroyed) matchedDC = dc; } _XmAppUnlock(app); return((Widget)matchedDC); }
/* This public function retrieves the widget saved by _XmSetDestination. */ Widget XmGetDestination (Display *display) { XmDisplay dd = (XmDisplay) XmGetXmDisplay(display); Widget w = (Widget)NULL; _XmDisplayToAppContext(display); _XmAppLock(app); if ((XmDisplay)NULL != dd) w = ((XmDisplayInfo *)(dd->display.displayInfo))->destinationWidget; _XmAppUnlock(app); return w; }
Widget XmMainWindowSep3( Widget w ) { XmMainWindowWidget mw = (XmMainWindowWidget) w; Widget separator; _XmWidgetToAppContext(w); _XmAppLock(app); separator = (Widget) mw->mwindow.Sep3; _XmAppUnlock(app); return separator; }
Boolean XmWidgetGetBaselines( Widget wid, Dimension **baselines, int *line_count) { _XmWidgetToAppContext(wid); _XmAppLock(app); if (XmIsPrimitive(wid)) { XmPrimitiveClassExt *wcePtr; WidgetClass wc = XtClass(wid); wcePtr = _XmGetPrimitiveClassExtPtr(wc, NULLQUARK); if (*wcePtr && (*wcePtr)->widget_baseline) { _XmAppUnlock(app); return( (*((*wcePtr)->widget_baseline)) (wid, baselines, line_count)) ; } } else if (XmIsGadget(wid)) { XmGadgetClassExt *wcePtr; WidgetClass wc = XtClass(wid); wcePtr = _XmGetGadgetClassExtPtr(wc, NULLQUARK); if (*wcePtr && (*wcePtr)->widget_baseline) { _XmAppUnlock(app); return( (*((*wcePtr)->widget_baseline)) (wid, baselines, line_count)) ; } } _XmAppUnlock(app); return (False); }
Boolean XmWidgetGetDisplayRect( Widget wid, XRectangle *displayrect) { _XmWidgetToAppContext(wid); _XmAppLock(app); if (XmIsPrimitive(wid)) { XmPrimitiveClassExt *wcePtr; WidgetClass wc = XtClass(wid); wcePtr = _XmGetPrimitiveClassExtPtr(wc, NULLQUARK); if (*wcePtr && (*wcePtr)->widget_display_rect) (*((*wcePtr)->widget_display_rect)) (wid, displayrect); _XmAppUnlock(app); return (True); } else if (XmIsGadget(wid)) { XmGadgetClassExt *wcePtr; WidgetClass wc = XtClass(wid); wcePtr = _XmGetGadgetClassExtPtr(wc, NULLQUARK); if (*wcePtr && (*wcePtr)->widget_display_rect) (*((*wcePtr)->widget_display_rect)) (wid, displayrect); _XmAppUnlock(app); return (True); } else { _XmAppUnlock(app); return (False); } }
Widget XmCreateSimplePopupMenu( Widget parent, String name, ArgList args, Cardinal arg_count ) { Widget rc; XmSimpleMenuRec mr; _XmWidgetToAppContext(parent); _XmAppLock(app); XtGetSubresources(parent, &mr, name, XmCSimplePopupMenu, SimpleMenuResources, XtNumber(SimpleMenuResources), args, arg_count); rc = XmCreatePopupMenu(parent, name, args, arg_count); EvaluateConvenienceStructure( rc, &mr); _XmAppUnlock(app); return(rc); }
/************************************************************************ * * XmIsMotifWMRunning * ************************************************************************/ Boolean XmIsMotifWMRunning( Widget shell ) { Atom motif_wm_info_atom; Atom actual_type; int actual_format; unsigned long num_items, bytes_after; PropMotifWmInfo *prop = 0; Window root = RootWindowOfScreen(XtScreen(shell)); _XmWidgetToAppContext(shell); _XmAppLock(app); motif_wm_info_atom = XInternAtom(XtDisplay(shell), _XA_MOTIF_WM_INFO, FALSE); _XmProcessLock(); XGetWindowProperty (XtDisplay(shell), root, motif_wm_info_atom, 0, (long)PROP_MOTIF_WM_INFO_ELEMENTS, FALSE, motif_wm_info_atom, &actual_type, &actual_format, &num_items, &bytes_after, (unsigned char **) &prop); _XmProcessUnlock(); if ((actual_type != motif_wm_info_atom) || (actual_format != 32) || (num_items < PROP_MOTIF_WM_INFO_ELEMENTS)) { if (prop != 0) XFree((char *)prop); _XmAppUnlock(app); return (FALSE); } else { Window wm_window = (Window) prop->wmWindow; Window top, parent, *children; unsigned int num_children; Boolean returnVal; Cardinal i; if (XQueryTree(XtDisplay(shell), root, &top, &parent, &children, &num_children)) { i = 0; while ((i < num_children) && (children[i] != wm_window)) i++; returnVal = (i == num_children) ? FALSE : TRUE; } else returnVal = FALSE; if (prop) XFree((char *)prop); if (children) XFree((char *)children); _XmAppUnlock(app); return (returnVal); } }
XtEnum XmPrintPopupPDM(Widget print_shell, Widget transient_for_video_shell) { Atom pdm_selection; Atom type; unsigned char * value; int length; int format; Atom PDM_START ; Display * display_used ; PDMSelectData * pdm_select_data ; Widget widget_for_selection ; XtAppContext app; unsigned long old_timeout; /* get parameter for PDM_START from libXp ask conversion using XtSetSelectionParameters, and then call XtGetSelectionValue, which registers a XtSelectionCallbackProc that will wait for failure (no pdm owner, or timeout) or success. Phase 2 of the pdm (clientmessage) will be handled by a event handler set up from the selection callback on success */ if (!XpGetPdmStartParams (XtDisplay(print_shell), XtWindow(print_shell), XpGetContext(XtDisplay(print_shell)), XtDisplay(transient_for_video_shell), XtWindow(transient_for_video_shell), &display_used, &pdm_selection, &type, &format, &value, &length)) return XmPDM_NOTIFY_FAIL; /* only support XPDMDISPLAY = "print" or "video" */ if (display_used == XtDisplay(print_shell)) widget_for_selection = print_shell ; else if (display_used == XtDisplay(transient_for_video_shell)) widget_for_selection = transient_for_video_shell ; else return XmPDM_NOTIFY_FAIL ; XtSetSelectionParameters(widget_for_selection, pdm_selection, type, (XtPointer)value, length, format); XFree(value); pdm_select_data = (PDMSelectData *) XtMalloc(sizeof(PDMSelectData)); pdm_select_data->pdm_selection = pdm_selection ; pdm_select_data->transient_for_video_shell = transient_for_video_shell ; pdm_select_data->print_shell = (XmPrintShellWidget) print_shell ; /* need this one in all cases */ PDM_START = XInternAtom(XtDisplay(widget_for_selection), XmIPDM_START, False); app = XtWidgetToApplicationContext(widget_for_selection); /* twenty minutes */ #define REALLY_LONG_TIMEOUT (2 * 60 * 1000) _XmAppLock(app); old_timeout = XtAppGetSelectionTimeout(app); XtAppSetSelectionTimeout(app, REALLY_LONG_TIMEOUT); XtGetSelectionValue(widget_for_selection, pdm_selection, PDM_START, PDMSelectionProc, (XtPointer)pdm_select_data, XtLastTimestampProcessed( XtDisplay(widget_for_selection))); XtAppSetSelectionTimeout(app, old_timeout); _XmAppUnlock(app); /* put up a InputOnly window on top of the dialog, so that the end-user cannot muck around with the print setup dialog hile the PDM is trying to come up. This is removed in PDMSelectionProc */ pdm_select_data->transient_for_input_only_window = XCreateWindow(XtDisplay(transient_for_video_shell), XtWindow(transient_for_video_shell), 0, 0, XtWidth(transient_for_video_shell), XtHeight(transient_for_video_shell), 0, CopyFromParent, InputOnly, CopyFromParent, 0, NULL); XMapRaised(XtDisplay(transient_for_video_shell), pdm_select_data->transient_for_input_only_window); return XmPDM_NOTIFY_SUCCESS ; }
String XmGetIconFileName( Screen *screen, String imageInstanceName, String imageClassName, String hostPrefix, unsigned int size) { Display *display = DisplayOfScreen(screen); String fileName = NULL; String names[2]; String names_w_size[2]; XmConst char *bPath, *iPath; Cardinal i; Boolean useColor; Boolean useMask; Boolean useIconFileCache; Boolean absolute = 0; XtFilePredicate testFileFunc; String homedir = NULL ; static String iconPath = NULL; static String bmPath = NULL; static XmHashTable iconNameCache = NULL; char stackString[MAX_DIR_PATH_LEN]; #define B_SUB 0 #define P_SUB 1 #define M_SUB 2 #define H_SUB 3 SubstitutionRec iconSubs[] = { {'B', NULL}, /* bitmap name */ {'P', NULL}, /* alternate bitmap name BC */ {'M', NULL}, /* magnitude */ {'H', NULL}, /* host prefix */ }; XtAppContext app; app = XtDisplayToApplicationContext(display); _XmAppLock(app); /* start by asking some screen state */ (void)XmeGetIconControlInfo(screen, &useMask, /* not used here */ &useColor, &useIconFileCache); _XmProcessLock(); /* generate the icon paths once per application: iconPath and bmPath */ if (!iconNameCache) { Boolean junkBoolean; iconNameCache = _XmAllocHashTable(100, CompareIconNames, HashIconName); cacheList.numDirs = cacheList.maxDirs = 0; cacheList.dirs = NULL; homedir = XmeGetHomeDirName(); strcpy(stackString, homedir) ; if (useColor) { iconPath = _XmOSInitPath(NULL, "XMICONSEARCHPATH", &junkBoolean); } else { iconPath = _XmOSInitPath(NULL, "XMICONBMSEARCHPATH", &junkBoolean); } /* 1.2 path as a fallback */ bmPath = _XmOSInitPath(NULL, "XBMLANGPATH", &junkBoolean); } switch (size) { case XmTINY_ICON_SIZE: iconSubs[M_SUB].substitution = ".t"; break; case XmSMALL_ICON_SIZE: iconSubs[M_SUB].substitution = ".s"; break; case XmMEDIUM_ICON_SIZE: iconSubs[M_SUB].substitution = ".m"; break; case XmLARGE_ICON_SIZE: iconSubs[M_SUB].substitution = ".l"; break; case XmUNSPECIFIED_ICON_SIZE: iconSubs[M_SUB].substitution = NULL; break; } iconSubs[H_SUB].substitution = hostPrefix; if (useIconFileCache) testFileFunc = TestIconFile; else testFileFunc = NULL; names[0] = imageInstanceName; names[1] = imageClassName; names_w_size[0] = names_w_size[1] = (String)NULL; /** loop over the two names */ for (i = 0; i < 2; i++) { if (names[i] == NULL) continue; if ((absolute = _XmOSAbsolutePathName(names[i], &names[i], stackString)) != FALSE) { iPath = ABSOLUTE_IPATH; bPath = ABSOLUTE_PATH; } else { iPath = iconPath; bPath = bmPath; } iconSubs[B_SUB].substitution = names[i]; iconSubs[P_SUB].substitution = names[i]; /* need to add size suffix if size is specified */ if (size != XmUNSPECIFIED_ICON_SIZE) { int basenameLen = strlen(names[i]); int sizeLen = strlen(iconSubs[M_SUB].substitution); char * ext_name = XtMalloc(basenameLen + sizeLen + 1); /* XmosP.h takes care of bcopy translation */ memmove(&ext_name[0], names[i], basenameLen); memmove(&ext_name[basenameLen], iconSubs[M_SUB].substitution, sizeLen); ext_name[basenameLen + sizeLen] = '\0'; names_w_size[i] = ext_name; } else names_w_size[i] = NULL; /* * try to see if its already in the image cache */ if (_XmInImageCache(names[i])) fileName = XtNewString(names[i]); /* * optimization to check all expansions in cache */ if (!fileName) { DtIconNameEntry iNameEntry; DtIconNameEntryRec iNameData ; iNameData.key_name = (names_w_size[i])?names_w_size[i]:names[i]; iNameEntry = (DtIconNameEntry) _XmGetHashEntry(iconNameCache, (XmHashKey)&iNameData); if (iNameEntry) { int dirLen, leafLen; dirLen = strlen(iNameEntry->dirName); leafLen = strlen(iNameEntry->leafName); fileName = XtMalloc(dirLen + leafLen + 2); memmove(&fileName[0], iNameEntry->dirName, dirLen); #ifdef FIX_1427 if (dirLen == 0) { memmove(&fileName[dirLen], iNameEntry->leafName, leafLen); fileName[dirLen + leafLen] = '\0'; } else { #endif fileName[dirLen] = '/'; memmove(&fileName[dirLen + 1], iNameEntry->leafName, leafLen); fileName[dirLen + leafLen + 1] = '\0'; #ifdef FIX_1427 } #endif } } if (fileName) { /* * CDExc20823 (memory leak): free names_w_size[i] * if it is not NULL. * NOTE: This code could be reorganized to do * _XmInImageCache() at the top of this loop * so we could avoid unnecessary malloc's for * names_w_size, but I wanted to minimize the * code impact of this defect for now. */ for (i = 0; i < 2; i++) { if (names_w_size[i] != (String)NULL) XtFree(names_w_size[i]); } _XmProcessUnlock(); _XmAppUnlock(app); return fileName; } /******************************* * first try XPM and then XBM ******************************/ fileName = XtResolvePathname(display, "icons", NULL, NULL, iPath, iconSubs, XtNumber(iconSubs), (XtFilePredicate) testFileFunc); if (fileName == NULL) { fileName = XtResolvePathname(display, "bitmaps", NULL, NULL, bPath, iconSubs, XtNumber(iconSubs), (XtFilePredicate) testFileFunc); } if (fileName) break; } _XmProcessUnlock(); if (fileName && !absolute) { /* register it in name cache */ DtIconNameEntry iNameEntry; String name_used = (names_w_size[i])? names_w_size[i] : names[i] ; /** alloc a icon cache entry **/ iNameEntry = (DtIconNameEntry) XtMalloc(sizeof(DtIconNameEntryRec)); iNameEntry->key_name = XtNewString(name_used); #ifndef XTHREADS if (useIconFileCache) { iNameEntry->dirName = XtNewString(GdirName); iNameEntry->leafName = XtNewString(GleafName); } else #endif { String dirName; String filePtr; String suffixPtr; int dirNameLen; _XmOSFindPathParts(fileName, &filePtr, &suffixPtr); if (fileName == filePtr) dirNameLen = 0; else { /* take the slash into account */ dirNameLen = filePtr - fileName - 1; } dirName = (String)XtMalloc(dirNameLen + 1); strncpy(dirName, fileName, dirNameLen); dirName[dirNameLen] = '\0'; iNameEntry->dirName = dirName; iNameEntry->leafName = XtNewString(filePtr); } _XmProcessLock(); _XmAddHashEntry(iconNameCache, (XmHashKey)iNameEntry, (XtPointer)iNameEntry); _XmProcessUnlock(); } /* * CDExc20823 (memory leak): free names_w_size[i] if not NULL. */ for (i = 0; i < 2; i++) { if (names_w_size[i] != (String)NULL) XtFree(names_w_size[i]); } _XmAppUnlock(app); return fileName; }
Widget XmCreateSimpleOptionMenu( Widget parent, String name, ArgList args, Cardinal arg_count ) { Widget rc, sub_rc; XmSimpleMenuRec mr; int n, i, button_count; Arg local_args[5]; WidgetList buttons; Cardinal num_buttons; _XmWidgetToAppContext(parent); _XmAppLock(app); XtGetSubresources(parent, &mr, name, XmCSimpleOptionMenu, SimpleMenuResources, XtNumber(SimpleMenuResources), args, arg_count); rc = XmCreateOptionMenu(parent, name, args, arg_count); sub_rc = XmCreatePulldownMenu(parent, name, args, arg_count); EvaluateConvenienceStructure(sub_rc, &mr); n = 0; if (mr.option_label) { XtSetArg(local_args[n], XmNlabelString, mr.option_label); n++; } if (mr.option_mnemonic) { XtSetArg(local_args[n], XmNmnemonic, mr.option_mnemonic); n++; } XtSetArg(local_args[n], XmNsubMenuId, sub_rc); n++; XtSetValues(rc, local_args, n); if (mr.button_set >= 0) { n = 0; XtSetArg(local_args[n], XtNchildren, &buttons); n++; XtSetArg(local_args[n], XtNnumChildren, &num_buttons); n++; XtGetValues(sub_rc, local_args, n); if (!num_buttons) { /* error condition */ _XmAppUnlock(app); return(rc); } else { button_count = 0; for (i = 0; i < num_buttons; i++) { /* count only PushB */ if ((XmIsPushButtonGadget(buttons[i])) || (XmIsPushButton(buttons[i]))) { if (button_count == mr.button_set) break; button_count++; } } if ( i < num_buttons) { n = 0; XtSetArg(local_args[n], XmNmenuHistory, buttons[i]); n++; XtSetValues(rc, local_args, n); } } } _XmAppUnlock(app); return(rc); }