📄 halappc.c
字号:
//// Remove this argument from the list// delete argVec[i]; for (int j=i+1; j<argCount; j++) argVec[j-1] = argVec[j]; argCount--; i--; } else if ( argStr.Equals("privateColors", IGNORE_CASE) ) { privateColors = True;//// Remove this argument from the list// delete argVec[i]; for (int j=i+1; j<argCount; j++) argVec[j-1] = argVec[j]; argCount--; i--; } }//// Get default values// screenNum = DefaultScreen(display); screen = DefaultScreenOfDisplay(display); gc = DefaultGC(display, screenNum); font = XQueryFont(display, XGContextFromGC(gc)); unsigned long mask; XGCValues vals; mask = GCFont; XGetGCValues(display, gc, mask, &vals); fid = vals.font;//// See if we need to create our own colormap// if ( privateColors ) { Colormap privMap = XCopyColormapAndFree(display, XDefaultColormapOfScreen(screen)); XtVaSetValues(appShell, XmNcolormap, privMap, NULL); }//// Catch terminating signals// AddSignalCallback(SIGHUP, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGINT, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGTERM, (CallbackFn*)HandleInterrupt, NULL);//// Add a signal handler for SIGPIPE. We can get this if the X server goes// down just before a write attempt.// AddSignalCallback(SIGPIPE, (CallbackFn*)HandleInterrupt, NULL);#if 0//// Temporary// AddSignalCallback(SIGQUIT, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGILL, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGTRAP, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGIOT, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGABRT, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGEMT, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGFPE, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGBUS, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGSEGV, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGSYS, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGALRM, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGURG, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGSTOP, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGTSTP, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGCONT, (CallbackFn*)HandleInterrupt, NULL); //AddSignalCallback(SIGCHLD, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGTTIN, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGTTOU, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGIO, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGXCPU, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGXFSZ, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGVTALRM, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGPROF, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGWINCH, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGLOST, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGUSR1, (CallbackFn*)HandleInterrupt, NULL); AddSignalCallback(SIGUSR2, (CallbackFn*)HandleInterrupt, NULL);#endif//// Create busy cursor// busyCursor = XCreateFontCursor(display, XC_watch); busyCount = 0; busyOn = False; Boolean hasDnD = get_boolean(appShell, "hasDragAndDrop", True); if ( hasDnD ) {//// Create icons for drag and drop states// Widget#if (XmVersion < 2000) || (XmVersion == 2000 && XmUPDATE_LEVEL == 0) validDropIcon = XmCreateDragIcon(appShell, "validDropIcon", 0,0), invalidDropIcon = XmCreateDragIcon(appShell, "invalidDropIcon", 0,0), noDropIcon = XmCreateDragIcon(appShell, "noDropIcon", 0,0);#else validDropIcon = XmCreateDragIcon(appShell, "validDropIcon2", 0,0), invalidDropIcon = XmCreateDragIcon(appShell, "invalidDropIcon2", 0,0), noDropIcon = XmCreateDragIcon(appShell, "noDropIcon2", 0,0);#endif//// Store icons with screen// Widget xmscreen = XmGetXmScreen(XtScreen(appShell)); XtVaSetValues(xmscreen, XmNdefaultValidCursorIcon, validDropIcon, XmNdefaultInvalidCursorIcon, invalidDropIcon, XmNdefaultNoneCursorIcon, noDropIcon, NULL); }//// Create atom used for deleting windows// delWinAtom = XmInternAtom(display, "WM_DELETE_WINDOW", False); exitCalls.AllowDuplicates(TRUE); shellList.AllowDuplicates(FALSE); quickHelpEnabled = get_boolean(appShell, "showQuickHelp", True); msgDialog = NULL; messagePM = errorPM = questionPM = warningPM = (Pixmap)NULL; helpWin = NULL;//// Add callback to detect VUE and CDE desktop termination// Atom saveAtom = XmInternAtom(display, "WM_SAVE_YOURSELF", False); XmAddWMProtocols(appShell, &saveAtom, 1); XmAddWMProtocolCallback(appShell, saveAtom, (XtCallbackProc)DoSaveYourself, this);//// DJL - add a protocol which will allow the program to be shut down using// interclient communication. This should be put in place of using SIGTERM.// It will be up to the applications to handle getting the value of the// appShell between applications.// hglPropAtom = XmInternAtom(display, "_HGL_PROPERTY", False); if (debuglev > 0) cout << "Interned hglPropAtom successfully" << endl; cancelAtom = XmInternAtom(display, "_HGL_CANCEL", False); if (debuglev > 0) cout << "Interned cancelAtom successfully" << endl; windowAtom = XmInternAtom(display, "_HGL_WINDOW", False); if (debuglev > 0) cout << "Interned windowAtom successfully" << endl; XmAddProtocols(appShell, hglPropAtom, &cancelAtom, 1); XmAddProtocolCallback(appShell, hglPropAtom, cancelAtom, (XtCallbackProc)DoExit, (caddr_t)True); if (debuglev > 0) cout << "Added callback for cancelAtom" << endl; XmAddProtocols(appShell, hglPropAtom, &windowAtom, 1); XmAddProtocolCallback(appShell, hglPropAtom, windowAtom, (XtCallbackProc)DoAddFollower, (caddr_t)True); if (debuglev > 0) cout << "Added callback for windowAtom" << endl; InformLeader(); if (debuglev > 0) cout << "Informed the leader window" << endl;//// Initialize help system// if ( debuglev > 0 ) cout <<"Initializing help" <<endl; helpWin = new HelpC(editHelp); hasHelp = helpWin->isActive; if ( hasHelp ) helpCursor = XCreateFontCursor(display, XC_question_arrow);} // End HalAppC constructor/*---------------------------------------------------------------------- * Destructor */HalAppC::~HalAppC(){// Remove the protocols just to be sure. XmRemoveProtocols(appShell, hglPropAtom, &cancelAtom, 1); XmRemoveProtocolCallback(appShell, hglPropAtom, cancelAtom, (XtCallbackProc)DoExit, (caddr_t)True); if (debuglev > 0) cout << "Removed callback for cancelAtom" << endl; XmRemoveProtocols(appShell, hglPropAtom, &windowAtom, 1); XmRemoveProtocolCallback(appShell, hglPropAtom, windowAtom, (XtCallbackProc)DoAddFollower, (caddr_t)True); if (debuglev > 0) cout << "Removed callback for windowAtom" << endl;// Delete callback structures if ( debuglev > 0 ) cout <<"Deleting exit calls" <<endl; DeleteCallbacks(exitCalls);#ifndef NO_HELP if ( debuglev > 0 ) cout <<"Deleting help" <<endl; delete helpWin;#endif if ( workBox ) delete workBox; if ( xRunning ) { if ( debuglev > 0 ) cout <<"Freeing X resources" <<endl; // Don't do this even though purify reports a memory leak // BadFont errors will result // XFreeFont(display, font); Colormap map; XtVaGetValues(appShell, XmNcolormap, &map, NULL); if ( map != XDefaultColormapOfScreen(screen) ) XFreeColormap(display, map); if ( debuglev > 0 ) cout <<"Freed the Colormap" <<endl; XFreeCursor(display, busyCursor); if ( debuglev > 0 ) cout <<"Freed the Cursor" <<endl; // This just doesn't work - because appShell is not mapped?? // XtDestroyWidget(appShell); // if ( debuglev > 0 ) cout <<"Destroyed the appShell" <<endl; XCloseDisplay(display); if ( debuglev > 0 ) cout <<"Closed the display" <<endl; }//// Delete command line arguments// if ( debuglev > 0 ) cout <<"Deleting command line arguments" << endl; for (int i=0; i<argCount; i++) { char *arg = argVec[i]; delete arg; } delete argVec; if ( debuglev > 0 ) cout <<"Leaving HalAppC destructor" << endl;} // End HalAppC destructor/*---------------------------------------------------------------------- * Exit callback */voidHalAppC::DoExit(Widget, Boolean interrupted, XtPointer){ if ( debuglev > 0 ) cout <<"Entering HalAppC::DoExit" <<endl;//// Ignore terminating signals// SIG_PF oldhup = signal(SIGHUP, SIG_IGN); SIG_PF oldint = signal(SIGINT, SIG_IGN); SIG_PF oldterm = signal(SIGTERM, SIG_IGN);//// Loop through exit callbacks from the back to the front. This will// approximate the C++ destoy methods.// HalExitDataT data; data.cancelExit = False; data.interrupted = interrupted; CallbackListC tmpCalls = halApp->exitCalls; // In case a callback // removes itself unsigned count = halApp->exitCalls.size(); for (int i=count-1; !data.cancelExit && i>=0; i--) { if ( debuglev > 0 ) cout <<" Calling callback " <<i <<endl; (*tmpCalls[i])(&data); } if ( data.cancelExit ) {//// Reinstate terminating signals// signal(SIGHUP, oldhup); signal(SIGINT, oldint); signal(SIGTERM, oldterm); if ( debuglev > 0 ) cout <<" Exit cancelled" <<endl; return; } if ( debuglev > 0 ) cout <<" Deleting followers" << endl; StopFollowers(); if ( debuglev > 0 ) cout <<" Deleting app" <<endl; delete halApp; if ( debuglev > 0 ) cout <<" Goodbye" <<endl; exit(0);}/*---------------------------------------------------------------------- * Help menu callbacks */#ifdef NO_HELPvoid HalAppC::DoHelp (Widget, XtPointer, XtPointer) {}void HalAppC::DoIndexHelp(Widget, XtPointer, XtPointer) {}#elsevoidHalAppC::DoHelp(Widget w, XtPointer resource, XtPointer){ if ( resource ) halApp->helpWin->ShowCard(w, (char *)resource, w); else halApp->helpWin->ShowCard(w, "contextHelp", w);}voidHalAppC::DoIndexHelp(Widget w, XtPointer, XtPointer){ halApp->helpWin->ShowIndex(w);}#endif/*--------------------------------------------------------------- * TimeOut used to finish exit processing since there may be X calls in the * user callbacks. */voidDoExit0(XtPointer, XtIntervalId*){ halApp->DoExit(NULL, True/*interrupted*/, NULL);}/*---------------------------------------------------------------------- * Interrupt handler for ctrl-c */voidHalAppC::HandleInterrupt(void *sd, void*){ SignalDataT *sigData = (SignalDataT*)sd; switch (sigData->signum) { case(SIGHUP): case(SIGINT): case(SIGTERM)://// Finish processing in a TimeOut handler in case the user callbacks contain// any X calls.// if ( debuglev > 0 ) cout <<"Adding timeout to do X cleanup" <<endl; halApp->exitSignal = sigData->signum; XtAppAddTimeOut(halApp->context, 0, (XtTimerCallbackProc)DoExit0, 0); break; default: /* Ignore */ break; }}/*---------------------------------------------------------------------- * Interrupt handler for X errors */voidHalAppC::HandleXError(Display *dpy, XErrorEvent *event){ char buffer[BUFSIZ]; XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); char *mtype = "XlibMessage"; char mesg[BUFSIZ]; XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); fprintf(stderr, "\n%s: %s\n ", mesg, buffer); XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); fprintf(stderr, mesg, event->request_code); if ( event->request_code < 128 ) { char number[32]; sprintf(number, "%d", event->request_code); XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); fprintf(stderr, " (%s)\n", buffer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -