static XtCacheRef *GetResources( Widget widget, /* Widget resources are associated with */ char* base, /* Base address of memory to write to */ XrmNameList names, /* Full inheritance name of widget */ XrmClassList classes, /* Full inheritance class of widget */ XrmResourceList* table, /* The list of resources required. */ unsigned num_resources, /* number of items in resource list */ XrmQuarkList quark_args, /* Arg names quarkified */ ArgList args, /* ArgList to override resources */ unsigned num_args, /* number of items in arg list */ XtTypedArgList typed_args, /* Typed arg list to override resources */ Cardinal* pNumTypedArgs, /* number of items in typed arg list */ Boolean tm_hack) /* do baseTranslations */ { /* * assert: *pNumTypedArgs == 0 if num_args > 0 * assert: num_args == 0 if *pNumTypedArgs > 0 */ #define SEARCHLISTLEN 100 #define MAXRESOURCES 400 XrmValue value; XrmQuark rawType; XrmValue convValue; XrmHashTable stackSearchList[SEARCHLISTLEN]; XrmHashTable *searchList = stackSearchList; unsigned int searchListSize = SEARCHLISTLEN; Boolean found[MAXRESOURCES]; int typed[MAXRESOURCES]; XtCacheRef cache_ref[MAXRESOURCES]; XtCacheRef *cache_ptr, *cache_base; Boolean persistent_resources = True; Boolean found_persistence = False; int num_typed_args = *pNumTypedArgs; XrmDatabase db; Boolean do_tm_hack = False; if ((args == NULL) && (num_args != 0)) { XtAppWarningMsg(XtWidgetToApplicationContext(widget), "invalidArgCount","getResources",XtCXtToolkitError, "argument count > 0 on NULL argument list", (String *)NULL, (Cardinal *)NULL); num_args = 0; } if (num_resources == 0) { return NULL; } else if (num_resources >= MAXRESOURCES) { XtAppWarningMsg(XtWidgetToApplicationContext(widget), "invalidResourceCount","getResources",XtCXtToolkitError, "too many resources", (String *)NULL, (Cardinal *)NULL); return NULL; } else if (table == NULL) { XtAppWarningMsg(XtWidgetToApplicationContext(widget), "invalidResourceCount","getResources",XtCXtToolkitError, "resource count > 0 on NULL resource list", (String *)NULL, (Cardinal *)NULL); return NULL; } /* Mark each resource as not found on arg list */ bzero((char *) found, (int) (num_resources * sizeof(Boolean))); bzero((char *) typed, (int) (num_resources * sizeof(int))); /* Copy the args into the resources, mark each as found */ { register ArgList arg; register XtTypedArgList typed_arg; register XrmName argName; register Cardinal j; register int i; register XrmResourceList rx; register XrmResourceList *res; for (arg = args, i = 0; (Cardinal)i < num_args; i++, arg++) { argName = quark_args[i]; if (argName == QinitialResourcesPersistent) { persistent_resources = (Boolean)arg->value; found_persistence = True; continue; } for (j = 0, res = table; j < num_resources; j++, res++) { rx = *res; if (argName == rx->xrm_name) { _XtCopyFromArg( arg->value, base - rx->xrm_offset - 1, rx->xrm_size); found[j] = TRUE; break; } } } for (typed_arg = typed_args, i = 0; i < num_typed_args; i++, typed_arg++) { register XrmRepresentation argType; argName = quark_args[i]; argType = (typed_arg->type == NULL) ? NULLQUARK : XrmStringToRepresentation(typed_arg->type); if (argName == QinitialResourcesPersistent) { persistent_resources = (Boolean)typed_arg->value; found_persistence = True; break; } for (j = 0, res = table; j < num_resources; j++, res++) { rx = *res; if (argName == rx->xrm_name) { if (argType != NULLQUARK && argType != rx->xrm_type) { typed[j] = i + 1; } else { _XtCopyFromArg( typed_arg->value, base - rx->xrm_offset - 1, rx->xrm_size); } found[j] = TRUE; break; } } } } /* Ask resource manager for a list of database levels that we can do a single-level search on each resource */ db = XtScreenDatabase(XtScreenOfObject(widget)); while (!XrmQGetSearchList(db, names, classes, searchList, searchListSize)) { if (searchList == stackSearchList) searchList = NULL; searchList = (XrmHashTable*)XtRealloc((char*)searchList, sizeof(XrmHashTable) * (searchListSize *= 2)); } if (persistent_resources) cache_base = NULL; else cache_base = cache_ref; /* geez, this is an ugly mess */ if (XtIsShell(widget)) { register XrmResourceList *res; register Cardinal j; Screen *oldscreen = widget->core.screen; /* look up screen resource first, since real rdb depends on it */ for (res = table, j = 0; j < num_resources; j++, res++) { if ((*res)->xrm_name != Qscreen) continue; if (typed[j]) { register XtTypedArg* arg = typed_args + typed[j] - 1; XrmQuark from_type; XrmValue from_val, to_val; from_type = StringToQuark(arg->type); from_val.size = arg->size; if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal))) from_val.addr = (XPointer)arg->value; else from_val.addr = (XPointer)&arg->value; to_val.size = sizeof(Screen*); to_val.addr = (XPointer)&widget->core.screen; found[j] = _XtConvert(widget, from_type, &from_val, QScreen, &to_val, cache_base); if (cache_base && *cache_base) cache_base++; } if (!found[j]) { if (XrmQGetSearchResource(searchList, Qscreen, QScreen, &rawType, &value)) { if (rawType != QScreen) { convValue.size = sizeof(Screen*); convValue.addr = (XPointer)&widget->core.screen; (void)_XtConvert(widget, rawType, &value, QScreen, &convValue, cache_base); if (cache_base && *cache_base) cache_base++; } else { widget->core.screen = *((Screen **)value.addr); } } } break; } /* now get the database to use for the rest of the resources */ if (widget->core.screen != oldscreen) { db = XtScreenDatabase(widget->core.screen); while (!XrmQGetSearchList(db, names, classes, searchList, searchListSize)) { if (searchList == stackSearchList) searchList = NULL; searchList = (XrmHashTable*)XtRealloc((char*)searchList, sizeof(XrmHashTable) * (searchListSize *= 2)); } } } /* go to the resource manager for those resources not found yet */ /* if it's not in the resource database use the default value */ { register XrmResourceList rx; register XrmResourceList *res; register Cardinal j; register XrmRepresentation xrm_type; register XrmRepresentation xrm_default_type; char char_val; short short_val; int int_val; long long_val; char* char_ptr; if (!found_persistence) { if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent, QInitialResourcesPersistent, &rawType, &value)) { if (rawType != QBoolean) { convValue.size = sizeof(Boolean); convValue.addr = (XPointer)&persistent_resources; (void)_XtConvert(widget, rawType, &value, QBoolean, &convValue, NULL); } else persistent_resources = *(Boolean*)value.addr; } } if (persistent_resources) cache_ptr = NULL; else if (cache_base) cache_ptr = cache_base; else cache_ptr = cache_ref; for (res = table, j = 0; j < num_resources; j++, res++) { rx = *res; xrm_type = rx->xrm_type; if (typed[j]) { register XtTypedArg* arg = typed_args + typed[j] - 1; /* * This resource value has been specified as a typed arg and * has to be converted. Typed arg conversions are done here * to correctly interpose them with normal resource conversions. */ XrmQuark from_type; XrmValue from_val, to_val; Boolean converted; from_type = StringToQuark(arg->type); from_val.size = arg->size; if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal))) from_val.addr = (XPointer)arg->value; else from_val.addr = (XPointer)&arg->value; to_val.size = rx->xrm_size; to_val.addr = base - rx->xrm_offset - 1; converted = _XtConvert(widget, from_type, &from_val, xrm_type, &to_val, cache_ptr); if (converted) { /* Copy the converted value back into the typed argument. * normally the data should be <= sizeof(XtArgVal) and * is stored directly into the 'value' field .... BUT * if the resource size is greater than sizeof(XtArgVal) * then we dynamically alloc a block of store to hold the * data and zap a copy in there !!! .... freeing it later * the size field in the typed arg is negated to indicate * that the store pointed to by the value field is * dynamic ....... * "freeing" happens in the case of _XtCreate after the * CallInitialize ..... other clients of GetResources * using typed args should be aware of the need to free * this store ..... */ if(rx->xrm_size > sizeof(XtArgVal)) { arg->value = (XtArgVal) __XtMalloc(rx->xrm_size); arg->size = -(arg->size); } else { /* will fit - copy directly into value field */ arg->value = (XtArgVal) NULL; } CopyToArg((char *)(base - rx->xrm_offset - 1), &arg->value, rx->xrm_size); } else { /* Conversion failed. Get default value. */ found[j] = False; } if (cache_ptr && *cache_ptr) cache_ptr++; } if (!found[j]) { Boolean already_copied = False; Boolean have_value = False; if (XrmQGetSearchResource(searchList, rx->xrm_name, rx->xrm_class, &rawType, &value)) { if (rawType != xrm_type) { convValue.size = rx->xrm_size; convValue.addr = (XPointer)(base - rx->xrm_offset - 1); already_copied = have_value = _XtConvert(widget, rawType, &value, xrm_type, &convValue, cache_ptr); if (cache_ptr && *cache_ptr) cache_ptr++; } else have_value = True; if (have_value && rx->xrm_name == Qtranslations) do_tm_hack = True; } LOCK_PROCESS; if (!have_value && ((rx->xrm_default_type == QImmediate) || (rx->xrm_default_type == xrm_type) || (rx->xrm_default_addr != NULL))) { /* Convert default value to proper type */ xrm_default_type = rx->xrm_default_type; if (xrm_default_type == QCallProc) { #ifdef CRAY if ( (int) Cjumpp != (int) Cjump) (*(XtResourceDefaultProc) (((int)(rx->xrm_default_addr))<<2))( widget,-(rx->xrm_offset+1), &value); else #endif (*(XtResourceDefaultProc)(rx->xrm_default_addr))( widget,-(rx->xrm_offset+1), &value); } else if (xrm_default_type == QImmediate) { /* XtRImmediate == XtRString for type XtRString */ if (xrm_type == QString) { value.addr = rx->xrm_default_addr; } else if (rx->xrm_size == sizeof(int)) { int_val = (int)(long)rx->xrm_default_addr; value.addr = (XPointer) &int_val; } else if (rx->xrm_size == sizeof(short)) { short_val = (short)(long)rx->xrm_default_addr; value.addr = (XPointer) &short_val; } else if (rx->xrm_size == sizeof(char)) { char_val = (char)(long)rx->xrm_default_addr; value.addr = (XPointer) &char_val; } else if (rx->xrm_size == sizeof(long)) { long_val = (long)rx->xrm_default_addr; value.addr = (XPointer) &long_val; } else if (rx->xrm_size == sizeof(char*)) { char_ptr = (char*)rx->xrm_default_addr; value.addr = (XPointer) &char_ptr; } else { value.addr = (XPointer) &(rx->xrm_default_addr); } } else if (xrm_default_type == xrm_type) { value.addr = rx->xrm_default_addr; } else { value.addr = rx->xrm_default_addr; if (xrm_default_type == QString) { value.size = strlen((char *)value.addr) + 1; } else { value.size = sizeof(XtPointer); } convValue.size = rx->xrm_size; convValue.addr = (XPointer)(base - rx->xrm_offset - 1); already_copied = _XtConvert(widget, xrm_default_type, &value, xrm_type, &convValue, cache_ptr); if (!already_copied) value.addr = NULL; if (cache_ptr && *cache_ptr) cache_ptr++; } } if (!already_copied) { if (xrm_type == QString) { *((String*)(base - rx->xrm_offset - 1)) = value.addr; } else { if (value.addr != NULL) { XtMemmove(base - rx->xrm_offset - 1, value.addr, rx->xrm_size); } else { /* didn't get value, initialize to NULL... */ XtBZero(base - rx->xrm_offset - 1, rx->xrm_size); } } } UNLOCK_PROCESS; if (typed[j]) { /* * This resource value was specified as a typed arg. * However, the default value is being used here since * type type conversion failed, so we compress the list. */ register XtTypedArg* arg = typed_args + typed[j] - 1; register int i; for (i = num_typed_args - typed[j]; i > 0; i--, arg++) { *arg = *(arg+1); } num_typed_args--; } } } if (tm_hack) widget->core.tm.current_state = NULL; if (tm_hack && (!widget->core.tm.translations || (do_tm_hack && widget->core.tm.translations->operation != XtTableReplace)) && XrmQGetSearchResource(searchList, QbaseTranslations, QTranslations, &rawType, &value)) { if (rawType != QTranslationTable) { convValue.size = sizeof(XtTranslations); convValue.addr = (XPointer)&widget->core.tm.current_state; (void)_XtConvert(widget, rawType, &value, QTranslationTable, &convValue, cache_ptr); if (cache_ptr && *cache_ptr) cache_ptr++; } else { /* value.addr can be NULL see: !already_copied */ if (value.addr) *((XtTranslations *)&widget->core.tm.current_state) = *((XtTranslations *)value.addr); } } } if ((Cardinal)num_typed_args != *pNumTypedArgs) *pNumTypedArgs = num_typed_args; if (searchList != stackSearchList) XtFree((char*)searchList); if (!cache_ptr) cache_ptr = cache_base; if (cache_ptr && cache_ptr != cache_ref) { int cache_ref_size = cache_ptr - cache_ref; XtCacheRef *refs = (XtCacheRef*) __XtMalloc((unsigned)sizeof(XtCacheRef)*(cache_ref_size + 1)); (void) memmove(refs, cache_ref, sizeof(XtCacheRef)*cache_ref_size ); refs[cache_ref_size] = NULL; return refs; } return (XtCacheRef*)NULL; }
/* ARGSUSED */ static void DisplayInitialize( Widget requested_widget, Widget new_widget, ArgList args, Cardinal *num_args ) { XmDisplay xmDisplay = (XmDisplay)new_widget; int dummy1, dummy2; XContext context; xmDisplay->display.shellCount = 0; xmDisplay->display.numModals = 0; xmDisplay->display.modals = NULL; xmDisplay->display.maxModals = 0; xmDisplay->display.userGrabbed = False; xmDisplay->display.activeDC = NULL; xmDisplay->display.dsm = (XmDropSiteManagerObject) NULL; xmDisplay->display.proxyWindow = _XmGetDragProxyWindow(XtDisplay(xmDisplay)); _XmInitByteOrderChar(); xmDisplay->display.xmim_info = NULL; xmDisplay->display.displayInfo = (XtPointer) XtNew(XmDisplayInfo); ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->SashCursor = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->TearOffCursor = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->UniqueStamp = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->destinationWidget= (Widget)NULL; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.pane = (Widget *)NULL; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.pane_list_size = 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.num_panes= 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->resetFocusFlag = 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->traversal_in_progress= FALSE; xmDisplay->display.displayHasShapeExtension = XShapeQueryExtension(XtDisplay(xmDisplay), &dummy1, &dummy2); /* Handle dynamic default of receiver protocol style */ if (xmDisplay->display.dragReceiverProtocolStyle == INVALID_PROTOCOL_VALUE) { if (xmDisplay->display.displayHasShapeExtension) xmDisplay->display.dragReceiverProtocolStyle = XmDRAG_PREFER_DYNAMIC; else xmDisplay->display.dragReceiverProtocolStyle = XmDRAG_PREFER_PREREGISTER; } _XmVirtKeysInitialize (new_widget); /* Solaris 2.6 Motif diff bug #4085003 4 lines */ #ifdef SUN_MOTIF _XmGetKPKeysymToKeycodeList(new_widget); _XmGetModifierMapping(new_widget); #endif /* SUN_MOTIF */ _XmProcessLock(); if (displayContext == 0) displayContext = XUniqueContext(); context = displayContext; _XmProcessUnlock(); if (! XFindContext(XtDisplay(xmDisplay), None, context, (char **) &xmDisplay)) { /* * There's one already created for this display. * What should we do? If we destroy the previous one, we may * wreak havoc with shell modality and screen objects. BUT, * Xt doesn't really give us a way to abort a create. We'll * just let the new one dangle. */ XmeWarning((Widget) xmDisplay, MESSAGE1); } else { XSaveContext(XtDisplayOfObject((Widget)xmDisplay), None, context, (char *)xmDisplay); } if (xmDisplay->display.enable_multi_key_bindings) { Display * display = XtDisplay(new_widget); int i, num_screens = ScreenCount(display); XrmDatabase new_db; for (i = 0; i < num_screens; i++) { Screen * screen = ScreenOfDisplay(display, i); XrmDatabase db = XtScreenDatabase(screen); new_db = XrmGetStringDatabase(_XmDisplay_baseTranslations); XrmCombineDatabase(new_db, &db, False); } } }
/* * ------------------------------------------------------------------------ * Name: PdmShellCreate * * Description: * * This function creates a top level application shell. * * Return value: * * 0 if successful; a PDM_EXIT code if not. * */ static int PdmShellCreate(PdmShell* me, const String* fallback_resources, int* argc_in_out, String* argv_in_out) { String app_class; String app_name; XmPixelSet pixelSets[XmCO_NUM_COLORS]; XrmClass class_list[3]; XrmDatabase db; XrmName name_list[3]; XrmRepresentation rep_type; XrmValue value; int decor; int funcs; short secondary_id; /* * create the application context and open the video display */ XtToolkitInitialize(); XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL, (XtPointer)NULL); me->app_context = XtCreateApplicationContext(); XtAppSetFallbackResources(me->app_context, (String*)fallback_resources); me->display = XtOpenDisplay(me->app_context, (String)NULL, (String)NULL, "Dtpdm", PdmOptions, XtNumber(PdmOptions), argc_in_out, argv_in_out); if((Display*)NULL == me->display) return PDM_EXIT_VXAUTH; XtGetApplicationNameAndClass(me->display, &app_name, &app_class); /* * the fallback resources are only intended for the video display, so * remove them from the application context */ XtAppSetFallbackResources(me->app_context, (String*)NULL); /* * get the parent video window id from the display's resource database */ db = XtDatabase(me->display); name_list[0] = XrmStringToQuark(app_name); name_list[1] = XrmStringToQuark("parentWindowStr"); name_list[2] = NULLQUARK; class_list[0] = XrmStringToQuark(app_class); class_list[1] = XrmStringToQuark("ParentWindowStr"); class_list[2] = NULLQUARK; XrmQGetResource(db, name_list, class_list, &rep_type, &value); if(!value.addr) return PDM_EXIT_ERROR; me->parent_window = (Window)strtoul((char*)value.addr, (char**)NULL, 0); /* * obtain the parent video window's attributes */ if(!XGetWindowAttributes(me->display, me->parent_window, &me->parent_attr)) return PDM_EXIT_ERROR; /* * register interest in the DestroyNotify event for the parent window */ XSelectInput(me->display, me->parent_window, StructureNotifyMask); /* * create the application shell */ decor = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE; funcs = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; me->widget = XtVaAppCreateShell(app_name, app_class, applicationShellWidgetClass, me->display, XmNdeleteResponse, XmDESTROY, XmNmappedWhenManaged, False, XmNmwmDecorations, decor, XmNmwmFunctions, funcs, XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL, XmNscreen, me->parent_attr.screen, XmNtransient, True, NULL); /* * pick up the secondary color set, so that the PDM presents the same * colors as a secondary window. (the XmColorObj is created by the * the XmDisplay object, which is created when the app shell is * created) */ if(XmeGetColorObjData(XtScreen(me->widget), (int*)NULL, pixelSets, XmCO_NUM_COLORS, (short*)NULL, (short*)NULL, (short*)NULL, &secondary_id, (short*)NULL)) { /* * In the Xrm database, reassign primary color resource values * with the corresponding secondary color values. This will cause * subsequently created widgets that utilize colors from the * primary set to actually present secondary colors. */ db = XtScreenDatabase(XtScreen(me->widget)); value.size = sizeof(Pixel); value.addr = (char*)&pixelSets[secondary_id].bg; XrmPutResource (&db, "*background", "Pixel", &value); XrmPutResource (&db, "*frameBackground", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].fg; XrmPutResource (&db, "*foreground", "Pixel", &value); XrmPutResource (&db, "*backPageForeground", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].bs; XrmPutResource (&db, "*bottomShadowColor", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].ts; XrmPutResource (&db, "*topShadowColor", "Pixel", &value); } /* * get the application resources */ XtGetApplicationResources(me->widget, me, PdmResources, XtNumber(PdmResources), NULL, 0); /* * return */ return 0; }