📄 halappc.c
字号:
/* * $Id: HalAppC.C,v 1.11 2001/03/12 20:40:38 evgeny Exp $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "HalAppC.h"#include "HalShellC.h"#include "HglResources.h"#include "WArgList.h"#include "WXmString.h"#include "WorkingBoxC.h"#include "SignalRegistry.h"#include "MimeRichTextC.h"#include "rsrc.h"#include "HelpC.h"#include "CharC.h"#include <Xm/RepType.h>#include <Xm/AtomMgr.h>#include <Xm/Protocols.h>#include <Xm/DragDrop.h>#include <Xm/Screen.h>#include <Xm/Text.h>#include <Xm/MessageB.h>#include <X11/cursorfont.h>#include <X11/Xmu/Converters.h>#include <X11/IntrinsicP.h>#include <X11/CoreP.h>#ifdef WITH_EDITRES# include <X11/Xmu/Editres.h>#endif#include <signal.h>#include <errno.h>#include <fcntl.h>HalAppC *halApp = NULL; // Global application objectint debug1 = 0;int debug2 = 0;int debuglev = 0;#if defined(AIX) || defined(HPUX)Boolean memMapOk = False; // AIX keeps files open and we run out. It // simply doesn't work well on HP.#elseBoolean memMapOk = True;#endifstatic char **origArgv;static int origArgc;static voidDoSaveYourself(Widget, HalAppC*, XtPointer){//// Exit the current application// if ( debuglev > 0 ) cout <<"Got WM_SAVE_YOURSELF message" <<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 = True; CallbackListC tmpCalls = halApp->exitCalls; // In case a callback // removes itself u_int count = halApp->exitCalls.size(); if ( debuglev > 0 ) cout <<" Found " <<count <<" exit callbacks" <<endl; for (int i=count-1; i>=0; i--) { if ( debuglev > 0 ) cout <<" Calling callback " <<i <<endl; (*tmpCalls[i])(&data); }//// Do not delete the followers here. Since you have received the SaveYourself// atom, assume that the other HGL items will receive it as well.////// Set the command to be used next time// XSetCommand(halApp->display, (Window)*halApp, origArgv, origArgc); if ( debuglev > 0 ) cout <<" Goodbye" <<endl; exit(0);}//// DJL - static callbacks used to handle shutdowns of related HGL-based// applications. The "leader" application will have to ensure that// all the "follower" applications are started with the environment// variable HGL_LEAD_WIN set to the window of halApp.//static PtrListC windowList;static Atom hglPropAtom;static Atom cancelAtom;static Atom windowAtom;static voidStopFollowers(){ Window root, parent; Window *children; unsigned int num_children = 0; XQueryTree(halApp->display, RootWindowOfScreen(halApp->screen), &root, &parent, &children, &num_children); for (int i = 0; i < windowList.size(); i++) { Window sendWin = (Window)(*windowList[i]); for (int j = 0; j < num_children; j++) { if (sendWin == children[j]) { XClientMessageEvent clientMsgEvent; clientMsgEvent.type = ClientMessage; clientMsgEvent.window = sendWin; clientMsgEvent.message_type = hglPropAtom; clientMsgEvent.format = 32; clientMsgEvent.data.l[0] = cancelAtom; XSendEvent(halApp->display, sendWin, False, NoEventMask, (XEvent*)&clientMsgEvent); XFlush(halApp->display); } } } windowList.removeAll(); XFree(children);} // End DoStopFollowersstatic voidDoAddFollower(Widget, XtPointer, XtPointer call_data){ XmAnyCallbackStruct *acs = (XmAnyCallbackStruct*)call_data; XClientMessageEvent *event = (XClientMessageEvent*)(acs->event); Window newWin = event->data.l[1]; windowList.append((PtrT)newWin);} static voidInformLeader(){ char *leadWinStr = getenv("HGL_LEAD_WINDOW"); if (leadWinStr == NULL) { return; } Window leadWin = atol(leadWinStr); if (leadWin != 0) { XClientMessageEvent clientMsgEvent; clientMsgEvent.type = ClientMessage; clientMsgEvent.window = leadWin; clientMsgEvent.message_type = hglPropAtom; clientMsgEvent.format = 32; clientMsgEvent.data.l[0] = windowAtom; clientMsgEvent.data.l[1] = (Window)(*halApp); XSendEvent(halApp->display, leadWin, False, NoEventMask, (XEvent*)&clientMsgEvent); XFlush(halApp->display); }} // End InformLeader/*---------------------------------------------------------------------- * Initialize X */HalAppC::HalAppC(int *argc, char **argv, const char *_name, const char *clss, String *fallbackResources, XrmOptionDescRec *options, Cardinal numoptions){//// Save original arguments// origArgc = *argc; origArgv = new char*[origArgc]; int i; for (i=0; i<origArgc; i++) { int len = strlen(argv[i]); origArgv[i] = new char[len+1]; strcpy(origArgv[i], argv[i]); } xRunning = False; halApp = this; name = _name; helpCursor = (Cursor)NULL; helpWin = NULL; hasHelp = False; workBox = NULL; className = clss; exitSignal = 0;#if XtSpecificationRelease > 4 XtSetLanguageProc(NULL, NULL, NULL);#endif XtToolkitInitialize(); context = XtCreateApplicationContext();//// Load the fallback default resources.// if ( !fallbackResources ) { XtAppSetFallbackResources(context, HglFallbackResources); } else {//// Since we can only set the fallback resources 1 time we// need to concatenate the user's resources onto the hgl resources.// String *str; int num_hgl = 0; int num_usr = 0; for ( str=HglFallbackResources; *str!=NULL; str++, num_hgl++ ); for ( str=fallbackResources; *str!=NULL; str++, num_usr++ ); String *resources = new String[num_usr+num_hgl+1]; int j, i=0; for (j=0; j<num_hgl; j++) resources[i++] = HglFallbackResources[j]; for (j=0; j<num_usr; j++) resources[i++] = fallbackResources[j]; resources[i] = NULL; XtAppSetFallbackResources(context, resources); } // End if user supplied resources//// Create the display.// display = XtOpenDisplay(context, NULL, name, clss, options, numoptions, argc, argv); if ( display == NULL) { cerr << name << ": Can't open display\n"; exit(1); } if ( debuglev > 0 ) cout <<"Display opened" <<endl;//// Save command line arguments that weren't removed by X.// Look for debug arguments and remove them.// argCount = *argc - 1; // Don't copy argv[0] argVec = NULL; if ( argCount > 0 ) { argVec = new char*[argCount]; char **arg = argv+1; int j = 0; for (i=0; i<argCount; i++) { if ( strcmp(*arg, "-D") == 0 ) { // Enable debugging if ( i < argCount - 1 ) { i++; arg++; debuglev = atoi(*arg); } else { cerr << name << ": -D implies exactly one argument\n"; exit(1); } debug1 = debuglev >= 1; debug2 = debuglev >= 2; } else { argVec[j] = new char[strlen(*arg)+1]; strcpy(argVec[j], *arg); j++; } arg++; } argCount = j; } xRunning = True;//// Make sure display connection closes during forks// fcntl(ConnectionNumber(display), F_SETFD, 1);//// Add error handlers// XSetErrorHandler((XErrorHandler)HandleXError); XSetIOErrorHandler((XIOErrorHandler)HandleXIOError);//// Add converters// XmRepTypeInstallTearOffModelConverter(); XtAppAddConverter(context, XtRString, XtRGravity, XmuCvtStringToGravity,0,0);//// Initialize resource database// XrmInitialize();//// Create shell// WArgList args; args.Reset(); args.MappedWhenManaged(False); args.X((DisplayWidth(display,0))/2); args.Y((DisplayHeight(display,0))/2); args.Width(1); args.Height(1); if ( debuglev > 0 ) cout <<"Creating app shell" <<endl; appShell = XtAppCreateShell(name, clss, applicationShellWidgetClass, display, ARGS);//// EditRes//#ifdef WITH_EDITRES if ( debuglev > 0 ) cout <<"Registering EditRes protocol" <<endl; XtAddEventHandler(appShell, (EventMask) 0, True, _XEditResCheckMessages, NULL);#endif XtRealizeWidget(appShell);//// See if memory mapping, help editing or private colors is requested// Boolean memMapOkRes = get_boolean(appShell, "memoryMappingOk", memMapOk); Boolean editHelp = get_boolean(appShell, "editHelp", False); Boolean privateColors = get_boolean(appShell, "privateColors", False); memMapOk = memMapOkRes; CharC argStr; for (i=0; i<argCount; i++) { argStr = argVec[i]; if ( argStr.StartsWith('-') ) argStr.CutBeg(1); if ( argStr.Equals("noMemMap", IGNORE_CASE) ) { memMapOk = False;//// 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("editHelp", IGNORE_CASE) ) { editHelp = True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -