Exemple #1
0
Boolean 
_XmGetIconControlInfo(
        Screen  *screen,
	Boolean *useMaskRtn,
        Boolean *useMultiColorIconsRtn,
        Boolean *useIconFileCacheRtn)
{
    return XmeGetIconControlInfo(screen, useMaskRtn, 
			  useMultiColorIconsRtn, useIconFileCacheRtn);
}
Exemple #2
0
/*++++++++++++++++++++++++++++++++++++++*/
int 
main(
        int argc,
        char **argv )
{
    int             n;
    Arg             args[MAX_ARGS];
    XEvent          event;
    XPropertyEvent *pEvent=(XPropertyEvent *)&event;
    long            mwmFunc;
    Boolean         useMaskRtn, useIconFileCacheRtn;    
    char           *dirs = NULL;
    char           *string;
	Visual         *visual;

#ifdef USERHELP
malloc_check(1);
malloc_trace(0);
#endif

    XtSetLanguageProc(NULL, NULL, NULL);
    _DtEnvControl(DT_ENV_SET); 
    

    /* Initialize the toolkit and open the display */
    style.shell = 
        XtInitialize(argv[0], XMCLASS, option_list, 1, (int *)&argc, argv);

#ifdef __osf__
    _XmColorObjCreate(style.shell, NULL, NULL);
#endif

    /* Allow all WS manipulation functions except resize and maximize */
    mwmFunc = MWM_FUNC_ALL ^ (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); 

    n = 0;
    XtSetArg(args[n], XmNmwmFunctions, mwmFunc); n++;
    XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
    XtSetValues(style.shell, args, n);

    /* initialize global style data */

    style.display    = XtDisplay(style.shell);
    style.screen     = DefaultScreenOfDisplay(style.display);
    style.screenNum  = DefaultScreen(style.display);
    style.colormap   = DefaultColormap(style.display, style.screenNum);
    style.root       = DefaultRootWindow(style.display);
    style.execName   = argv[0];
    style.errDialog  = NULL;
    style.tmpXmStr   = NULL;
    style.home = (char *) XtMalloc(strlen((char *) getenv("HOME")) + 1);
    strcpy(style.home, (char *) getenv("HOME"));
    style.colorDialog = NULL;
    style.backdropDialog = NULL;
    style.fontDialog = NULL;
    style.kbdDialog = NULL;
    style.mouseDialog = NULL;
    style.audioDialog = NULL;
    style.screenDialog = NULL;
    style.startupDialog = NULL;
    style.dtwmDialog = NULL;
    style.i18nDialog = NULL;
	visual = XDefaultVisual(style.display,style.screenNum);
	style.visualClass = visual->class;
    
    if (progName = DtStrrchr(argv[0], '/')) progName++;
    else progName = argv[0];

    /* Get the lock established to ensure only one dtstyle process
     * is running per screen .. first malloc enough space*/

    if (_DtGetLock (style.display, STYLE_LOCK) == 0)
    {
        _DtSimpleError (progName, DtError, NULL, "%s",
	     ((char *)GETMESSAGE(2, 5, "Style Manager is already running, second attempt aborted.")));
        exit(1);
    }

    InitDtstyleProtocol();
    SetWindowProperties();

    /* Register error handlers */
    XSetErrorHandler(ErrorHandler);
    XSetIOErrorHandler(IOErrorHandler);
    XtAppSetErrorHandler(XtWidgetToApplicationContext(style.shell),
                         ToolkitErrorHandler);
    XtAddEventHandler(style.shell, StructureNotifyMask, 0,
                         (XtEventHandler)MwmReparentNotify, NULL);

    /* set up resolution dependent layout variables */
    switch (_DtGetDisplayResolution(style.display, style.screenNum))
    {
        case LOW_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 3;
            break;
            
        case MED_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 5;
            break;
            
        case HIGH_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 8;
            break;
    }
    
    GetApplicationResources();
    
    XmeGetIconControlInfo(style.screen, &useMaskRtn,
			  &style.useMultiColorIcons, &useIconFileCacheRtn);
    
    
    /* add the directory $HOME/.dt/backdrops */
    
    string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops:") + 1);
    sprintf(string, "%s/.dt/backdrops:", style.home);

    dirs = (char *)XtCalloc(1, strlen("/etc/dt/backdrops:/usr/dt/backdrops") + 
			    (style.xrdb.backdropDir == NULL ? 2 :
			    strlen(style.xrdb.backdropDir)) + 
			    strlen(string) + 2);
  

    strcpy(dirs, string);
    if (style.xrdb.backdropDir) 
      {
	strcat(dirs, style.xrdb.backdropDir);
	strcat(dirs, ":"); 
      }
    strcat(dirs, "/etc/dt/backdrops:/usr/dt/backdrops");

    _DtWsmSetBackdropSearchPath(style.screen, dirs, style.useMultiColorIcons);

    if (string != NULL)
      XtFree((char *)string);
    
    if (dirs != NULL)
      XtFree((char *)dirs); 
    
    

    style.count = 0;
    /* if this is started from save session we need to set up the BMS
       first, otherwise do it after making the window. (for user perception
       for how long it takes for the dtstyle to come up) */
    if(style.xrdb.session != NULL) {
      DtInitialize (style.display, style.shell, progName, progName);
      /*Restore a session or build and display the main Window.*/
      if(!restoreSession(style.shell,style.xrdb.session))
	init_mainWindow(style.shell);
    }
    else {
      init_mainWindow(style.shell);
      DtInitialize (style.display, style.shell, progName, progName);
      InitializeAtoms();
      CheckMonitor(style.shell);
      GetDefaultPal(style.shell);
    }
    
    signal(SIGINT,(void (*)())activateCB_exitBtn); 
    signal(SIGTERM,(void (*)())activateCB_exitBtn); 

    /* to avoid defunct screen saver processes */    
    signal(SIGCHLD, (void (*)())WaitChildDeath);

    /* backdrop dialog  needs to know when the workspace changes to recolor 
       the bitmap displayed in the dialog */
    ListenForWorkspaceChange();

    /* if using COLOR builtin, style.workProcs is True */

    if ((XmeUseColorObj() != FALSE) && style.workProcs)

        XtAppAddWorkProc(XtWidgetToApplicationContext(style.shell), 
                        NewCreateD, style.shell);

    XtAppMainLoop(XtWidgetToApplicationContext(style.shell));

    return 0;
}
Exemple #3
0
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;
}