Ejemplo n.º 1
0
/************************************************************************
 * restoreDtwm()
 * /u1/shakib/ncode
 * restore any state information saved with savedtwm.
 * This is called from restoreSession with the application
 * shell and the special xrm database retrieved for restore.
 ************************************************************************/
void 
restoreDtwm(
        Widget shell,
        XrmDatabase db )
{
    XrmName xrm_name[5];
    XrmRepresentation rep_type;
    XrmValue value;

    xrm_name [0] = XrmStringToQuark ("dtwmDlg");
    xrm_name [2] = 0;

    /* get x position */
    xrm_name [1] = XrmStringToQuark ("x");
    if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
      XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
      save.restoreFlag = True;
    }

    /* get y position */
    xrm_name [1] = XrmStringToQuark ("y");
    if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
      XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
    }

    xrm_name [1] = XrmStringToQuark ("ismapped");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    /* Are we supposed to be mapped? */
    if (strcmp(value.addr, "True") == 0) 
      popup_dtwmBB(shell);
}
Ejemplo n.º 2
0
/************************************************************************
 *
 * RestoreMain - 
 *
 ***********************************************************************/
static void
RestoreMain(
        Editor *pPad,
	int padNum,
        XrmDatabase db)
{
    char * iconify = NULL;
    char buf[1024];
    XrmName xrm_name[5];
    XrmRepresentation rep_type;
    XrmValue value;

    sprintf(buf, "mainWindow%d", padNum);
    xrm_name[0] = XrmStringToQuark(buf);
    xrm_name[2] = NULL;

    /* get x position */
    xrm_name[1] = XrmStringToQuark ("x");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    pPad->x = atoi((char *)value.addr);

    /* get y position */
    xrm_name [1] = XrmStringToQuark ("y");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    pPad->y = atoi((char *)value.addr);

    /* get width */
    xrm_name [1] = XrmStringToQuark ("width");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    pPad->width = atoi((char *)value.addr);

    /* get height */
    xrm_name [1] = XrmStringToQuark ("height");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    pPad->height = atoi((char *)value.addr);
 
   /*  Get and set whether the view is iconic  */
   xrm_name [1] = XrmStringToQuark ("iconify");
   XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
   /*  If there is an iconify resource and its value is True,  */
   /*  then mark the window as iconified.                      */
   if ((iconify = (char *) value.addr) != NULL &&
                                    strcmp (iconify, "True") == 0)
      pPad->iconic = True;
   else
      pPad->iconic = False;

    /* get the file name */
    xrm_name [1] = XrmStringToQuark ("fileName");
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    pPad->fileStuff.fileName = strdup((char *) value.addr);

    /* get workspace list */
    xrm_name[1] = XrmStringToQuark("workspaceList");
    XrmQGetResource(db, xrm_name, xrm_name, &rep_type, &value);
    pPad->xrdb.workspaceList = strdup((char *) value.addr);

}
Ejemplo n.º 3
0
/************************************************************************
 * restoreMain()
 *
 * restore any state information saved with saveMain.
 * This is called from restoreSession with the application
 * shell and the special xrm database retrieved for restore.
 ************************************************************************/
void 
restoreMain(
        Widget shell,
        XrmDatabase db )
{
    XrmName xrm_name[5];
    XrmRepresentation rep_type;
    XrmValue value;

    xrm_name [0] = XrmStringToQuark ("mainWindow");
    xrm_name [1] = XrmStringToQuark ("ismapped");
    xrm_name [2] = NULL;

    if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
      /* Are we supposed to be mapped? */
      if (strcmp(value.addr, "True") == 0) {
        save.poscnt = 0;

        /* get x position */
        xrm_name [1] = XrmStringToQuark ("x");
        if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
          XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
	  save.poscnt++;
        }

        /* get y position */
        xrm_name [1] = XrmStringToQuark ("y");
        if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
          XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
	  save.poscnt++;
        }

	save.restoreFlag = True;
        init_mainWindow(shell);
      }
    }
    else
      _DtSimpleError (progName, DtWarning, NULL, ((char *)GETMESSAGE(4,36,
	"No Dtstyle restore information available for current session")), NULL);
}
Ejemplo n.º 4
0
static void
GetResourcePixmapPath(Display *display)
{
    XrmName xrm_name[2];
    XrmClass xrm_class[2];
    XrmRepresentation rep_type;
    XrmValue value;
    static char *default_path =
	"%H/%T/%N:%P/include/X11/%T/%N:/usr/X11R6/include/X11/%T/%N:/usr/include/X11/%T/%N:%N";

    xrm_name[0] = XrmPermStringToQuark("pixmapFilePath");
    xrm_name[1] = NULLQUARK;
    xrm_class[0] = XrmPermStringToQuark("PixmapFilePath");
    xrm_class[1] = NULLQUARK;
    if (!XrmGetDatabase(display))
	(void) XGetDefault(display, "", "");
    if (XrmQGetResource(XrmGetDatabase(display), xrm_name, xrm_class,
			&rep_type, &value) &&
			rep_type == XrmPermStringToQuark("String")) {
	int length = 0;
	char *tok, *buffer = XtNewString(value.addr);

	for (tok = strtok(buffer, ":"); tok; tok = strtok(NULL, ":")) {
	    int toklen = strlen(tok);

	    if (toklen) {
		pixmap_path = XtRealloc(pixmap_path, length + toklen + 5);
		strcpy(pixmap_path + length, tok);
		if (length)
		    pixmap_path[length++] = ':';
		sprintf(pixmap_path + length, "%s/%%N", tok);
		length += strlen(tok) + 3;
	    }
	}
	pixmap_path = XtRealloc(pixmap_path, length + strlen(default_path) + 2);
	if (length)
	    pixmap_path[length++] = ':';
	strcpy(pixmap_path + length, default_path);
    }
    else
	pixmap_path = default_path;
}
Ejemplo n.º 5
0
/*
 * version that reads pixmap data as well as bitmap data
 */
Pixmap
XmuLocatePixmapFile(Screen *screen, _Xconst char *name, 
			    unsigned long fore, unsigned long back, 
			    unsigned int depth, 
			    char *srcname, int srcnamelen,
			    int *widthp, int *heightp, int *xhotp, int *yhotp)
{

#ifndef BITMAPDIR
#define BITMAPDIR "/usr/include/X11/bitmaps"
#endif

    Display *dpy = DisplayOfScreen (screen);
    Window root = RootWindowOfScreen (screen);
    Bool try_plain_name = True;
    XmuCvtCache *cache = _XmuCCLookupDisplay (dpy);
    char **file_paths = (char **) NULL;
    char filename[PATH_MAX];
#if 0
    char* bitmapdir = BITMAPDIR;
#endif
    unsigned int width, height;
    int xhot, yhot;
    int i;

    /*
     * look in cache for bitmap path
     */
    if (cache) {
	if (!cache->string_to_bitmap.bitmapFilePath) {
	    XrmName xrm_name[2];
	    XrmClass xrm_class[2];
	    XrmRepresentation rep_type;
	    XrmValue value;

	    xrm_name[0] = XrmPermStringToQuark ("bitmapFilePath");
	    xrm_name[1] = NULLQUARK;
	    xrm_class[0] = XrmPermStringToQuark ("BitmapFilePath");
	    xrm_class[1] = NULLQUARK;
	    if (!XrmGetDatabase(dpy)) {
		/* what a hack; need to initialize it */
		(void) XGetDefault (dpy, "", "");
	    }
	    if (XrmQGetResource (XrmGetDatabase(dpy), xrm_name, xrm_class, 
				 &rep_type, &value) &&
		rep_type == XrmPermStringToQuark("String")) {
		cache->string_to_bitmap.bitmapFilePath = 
		  split_path_string (value.addr);
	    }
	}
	file_paths = cache->string_to_bitmap.bitmapFilePath;
    }

    /*
     * Search order:
     *    1.  name if it begins with / or ./
     *    2.  "each prefix in file_paths"/name
     *    3.  BITMAPDIR/name
     *    4.  name if didn't begin with / or .
     */

    for (i = 1; i <= 4; i++) {
	char *fn = filename;
	Pixmap pixmap;
	unsigned char *data;

	switch (i) {
	  case 1:
#ifndef __UNIXOS2__
	    if (!(name[0] == '/' || ((name[0] == '.') && name[1] == '/')))
#else
	    if (!(name[0] == '/' || (name[0] == '.' && name[1] == '/') ||
		  (isalpha(name[0]) && name[1] == ':')))
#endif
	      continue;
	    fn = (char *) name;
	    try_plain_name = False;
	    break;
	  case 2:
	    if (file_paths && *file_paths) {
		XmuSnprintf(filename, sizeof(filename),
			    "%s/%s", *file_paths, name);
		file_paths++;
		i--;
		break;
	    }
	    continue;
	  case 3:
	    XmuSnprintf(filename, sizeof(filename), "%s/%s", BITMAPDIR, name);
	    break;
	  case 4:
	    if (!try_plain_name) continue;
	    fn = (char *) name;
	    break;
	}

	data = NULL;
	pixmap = None;
#ifdef __UNIXOS2__
	fn = (char*)__XOS2RedirRoot(fn);
#endif
	if (XmuReadBitmapDataFromFile (fn, &width, &height, &data,
				       &xhot, &yhot) == BitmapSuccess) {
	    pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data,
						  width, height,
						  fore, back, depth);
	    XFree ((char *)data);
	}

	if (pixmap) {
	    if (widthp) *widthp = (int)width;
	    if (heightp) *heightp = (int)height;
	    if (xhotp) *xhotp = xhot;
	    if (yhotp) *yhotp = yhot;
	    if (srcname && srcnamelen > 0) {
		strncpy (srcname, fn, srcnamelen - 1);
		srcname[srcnamelen - 1] = '\0';
	    }
	    return pixmap;
	}
    }

    return None;
}
Ejemplo n.º 6
0
/***********************************************************************
 *
 * restoreSession - gets the valid x and y location of where to put the
 *	Text Edit on the root window.  Sets the global varible
 *	dtpad.saveRestore to True so the rest of the program knows that
 *	a session is being restored.
 *
 ***********************************************************************/
void
restoreSession(
        Editor *pPad)
{
    XrmDatabase db;
    char *tmpStr;
    XrmName xrm_name[5];
    XrmRepresentation rep_type;
    XrmValue value;
    char *fileName = pPad->xrdb.session;
    char *path;
    int numPadsToRestore, i;
    Boolean foundPad;

    if(DtSessionRestorePath(topLevelWithWmCommand, &path, fileName) == False)
	path = fileName;

    /*  Open the file as a resource database */
    if ((db = XrmGetFileDatabase (path)) == NULL) 
    {
      tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(path)+ 1);
      sprintf(tmpStr, MSG2, path);
      _DtSimpleErrnoError(pPad->progname, DtError, MSG1, tmpStr, NULL);
      XtFree(tmpStr);
      return;
    }

    xrm_name[0] = XrmStringToQuark ("pads");
    xrm_name[1] = XrmStringToQuark ("numActivePads");
    xrm_name[2] = NULL;
    XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
    numPadsToRestore = atoi((char *)value.addr);

    if(numPadsToRestore == 0)
    {
	/*
	 * Either it's an old (i.e. 2.01) session file,
	 * or it's bogus.  Either way, we'll create one
	 * window, taking whatever mainWindow: resources
	 * we can find.
	 */
        xrm_name[0] = XrmStringToQuark ("mainWindow");
        xrm_name[2] = NULL;

        /* get x position */
        xrm_name[1] = XrmStringToQuark ("x");
        XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
        pPad->x = atoi((char *)value.addr);

        /* get y position */
        xrm_name[1] = XrmStringToQuark ("y");
        XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
        pPad->y = atoi((char *)value.addr);
 
        pPad->saveRestore = True;

	return;
    }      

    RestorePad(pPad, 0, db);

    for(i = 1; i < numPadsToRestore; i++)
    {
	foundPad = FindOrCreatePad(&pPad);
	RestorePad(pPad, i, db);

	if(foundPad == False)
	    RealizeNewPad(pPad);
	else
	    ManageOldPad(pPad, False);
    }
}
Ejemplo n.º 7
0
char *
XGetDefault(
	Display *dpy,			/* display for defaults.... */
	char _Xconst *prog,		/* name of program for option	*/
	register _Xconst char *name)	/* name of option program wants */
{					/* to get, for example, "font"  */
	XrmName names[3];
	XrmClass classes[3];
	XrmRepresentation fromType;
	XrmValue result;
	char *progname;
#ifdef WIN32
	char *progname2;
#endif
#ifdef __UNIXOS2__
	char *progname2;
	char *dotpos;
#endif

	/*
	 * strip path off of program name (XXX - this is OS specific)
	 */
	progname = strrchr (prog, '/');
#ifdef WIN32
	progname2 = strrchr (prog, '\\');
	if (progname2 && (!progname || progname < progname2))
	    progname = progname2;
#endif
#ifdef __UNIXOS2__  /* Very similar to WIN32 */
	progname2 = strrchr (prog, '\\');
	if (progname2 && (!progname || progname < progname2))
	    progname = progname2;
	dotpos = strrchr (prog, '.');
	if (dotpos && (dotpos>progname2)) *dotpos='\0';
#endif  /* We take out the .exe suffix  */

	if (progname)
	    progname++;
	else
	    progname = (char *)prog;

	/*
	 * see if database has ever been initialized.  Lookups can be done
	 * without locks held.
	 */
	LockDisplay(dpy);
	if (dpy->db == NULL) {
	    dpy->db = InitDefaults(dpy);
	    dpy->flags |= XlibDisplayDfltRMDB;
	}
	UnlockDisplay(dpy);

	names[0] = XrmStringToName(progname);
	names[1] = XrmStringToName(name);
	names[2] = NULLQUARK;
	classes[0] = XrmStringToClass("Program");
	classes[1] = XrmStringToClass("Name");
	classes[2] = NULLQUARK;
	(void)XrmQGetResource(dpy->db, names, classes, &fromType, &result);
	return (result.addr);
}
Ejemplo n.º 8
0
/*
 * ------------------------------------------------------------------------
 * 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;
}