// UILApp #include #include "uilapp.h" MrmRegisterArg* UILApp::callback_list = 0; String* UILApp::UIDModules = 0; UILApp::app_data_t UILApp::app_data = { 0 }; XtResource UILApp::resources[] = { { "root", "Root", XmRString, sizeof(String), XtOffsetOf(app_data_t, root_widget_name), XmRString, (XtPointer)"root" } }; XrmOptionDescRec UILApp::options[] = { { "-root", "root", XrmoptionSepArg, NULL } }; void UILApp::AddCallback(char* name, void (*fun)()) { if (callback_list == 0) { callback_list = new MrmRegisterArg[1]; nCallbacks = 0; } else { MrmRegisterArg* temp = callback_list; callback_list = new MrmRegisterArg[nCallbacks + 1]; memcpy(callback_list, temp, nCallbacks * sizeof(MrmRegisterArg)); } MrmRegisterArg str = { name, fun }; callback_list[nCallbacks++] = str; } void UILApp::AddUILModule(char* modName) { if (UIDModules == 0) { UIDModules = new String[1]; nModules = 0; } else { String* temp = UIDModules; UIDModules = new String[nModules + 1]; memcpy(UIDModules, temp, nModules * sizeof(String)); } UIDModules[nModules++] = modName; } void UILApp::run(int argc, char* argv[]) { XtSetLanguageProc(NULL, NULL, NULL); MrmInitialize(); toplevel = XtVaAppInitialize(&app_context, "Domes", options, XtNumber(options), &argc, argv, NULL, NULL); XtGetApplicationResources(toplevel, &app_data, resources, XtNumber(options), NULL, 0); // use argc and argv to obtain UID file name from the command line status = MrmOpenHierarchyPerDisplay(XtDisplay(toplevel), nModules, UIDModules, NULL, &hierarchy); if (status != MrmSUCCESS) { XtAppError(app_context, "MrmOpenHierarchyPerzDisplay failed"); exit(1); } MrmRegisterNames(callback_list, nCallbacks); status = MrmFetchWidget(hierarchy, app_data.root_widget_name, toplevel, &root_widget, &class_code); if (status != MrmSUCCESS) { XtAppError(app_context, "MrmFetchWidget failed"); exit(1); } MrmCloseHierarchy(hierarchy); XtManageChild(root_widget); XtRealizeWidget(toplevel); XtAppMainLoop(app_context); }