| 1 |
/*--------------------------------------------------------------------- |
| 2 |
* $Date: 2009-08-18 15:23:20 $ $Revision: 1.2 $ |
| 3 |
*--------------------------------------------------------------------- |
| 4 |
* |
| 5 |
* |
| 6 |
* Copyright (c) 1988, Visual Edge Software Ltd. |
| 7 |
* |
| 8 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 9 |
* distribute this software and its documentation for any purpose |
| 10 |
* and without fee is hereby granted, provided that the above |
| 11 |
* copyright notice appear in all copies and that both that |
| 12 |
* copyright notice and this permission notice appear in supporting |
| 13 |
* documentation, and that the name of Visual Edge Software not be |
| 14 |
* used in advertising or publicity pertaining to distribution of |
| 15 |
* the software without specific, written prior permission. The year |
| 16 |
* included in the notice is the year of the creation of the work. |
| 17 |
*-------------------------------------------------------------------*/ |
| 18 |
|
| 19 |
/* |
| 20 |
.VERSION |
| 21 |
090813 last modif KB |
| 22 |
*/ |
| 23 |
|
| 24 |
/*--- include files ---*/ |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <string.h> |
| 28 |
#include <ctype.h> |
| 29 |
|
| 30 |
#ifdef USE_STDLIB |
| 31 |
#include <stdlib.h> |
| 32 |
#endif /* USE_STDLIB */ |
| 33 |
|
| 34 |
#ifndef _IBMR2 |
| 35 |
#include <math.h> |
| 36 |
#endif /* _IBMR2 */ |
| 37 |
|
| 38 |
#include <sys/types.h> |
| 39 |
#include <sys/stat.h> |
| 40 |
#include <pwd.h> |
| 41 |
#include <X11/X.h> |
| 42 |
#include <X11/Xlib.h> |
| 43 |
#include <X11/Intrinsic.h> |
| 44 |
#include <X11/Xutil.h> |
| 45 |
#include <X11/StringDefs.h> |
| 46 |
#include "uxproto.h" |
| 47 |
#include "version.h" |
| 48 |
#include "global.h" |
| 49 |
#include "resload.h" |
| 50 |
#include "uimx_cat.h" |
| 51 |
#include "valloc.h" |
| 52 |
#include "vtypes.h" |
| 53 |
#include "getsysmsg.h" |
| 54 |
#ifndef RUNTIME |
| 55 |
#include "misc_ds.h" |
| 56 |
#endif |
| 57 |
|
| 58 |
/*--- macro symbolic constants ---*/ |
| 59 |
|
| 60 |
#ifdef MOTIF_WIDGETS |
| 61 |
#define APPDEF "/usr/lib/X11/app-defaults" |
| 62 |
#define APPDEF2 "/usr/lib/X11/%L/app-defaults" |
| 63 |
#define DEFAULT_BPATH ". ~ /usr/include/X11/bitmaps/$UXAPP /usr/include/X11/bitmaps" |
| 64 |
#endif /* MOTIF_WIDGETS */ |
| 65 |
|
| 66 |
/*--- macro functions ---*/ |
| 67 |
|
| 68 |
/* X/OPEN message catalog macros. These will make the code more compact. */ |
| 69 |
#define CGETS(ms,ds_ms) UxCatGets(MC_SYSTEM_NAME,ms,ds_ms) |
| 70 |
#define MCGETS(ms,ds_ms) UxCatGets(MC_MISC,ms,ds_ms) |
| 71 |
|
| 72 |
/*--- types ---*/ |
| 73 |
|
| 74 |
/*--- external functions ---*/ |
| 75 |
|
| 76 |
/*--- external variables ---*/ |
| 77 |
|
| 78 |
/*--- global variables ---*/ |
| 79 |
|
| 80 |
/*--- file global variables ---*/ |
| 81 |
M_FILE_VERSION("$Header") |
| 82 |
|
| 83 |
pathlist UxResourcePath= NULL, UxBitmapPath= NULL; |
| 84 |
|
| 85 |
char *UxShellNameList[] = { |
| 86 |
"applicationShell", |
| 87 |
"dialogShell", |
| 88 |
"overrideShell", |
| 89 |
"topLevelShell", |
| 90 |
"transientShell", |
| 91 |
"menuShell" }; |
| 92 |
char *UxBrowserType[] = { |
| 93 |
"outline", |
| 94 |
"tree" }; |
| 95 |
|
| 96 |
extern void UxAppend_dstring(); |
| 97 |
|
| 98 |
|
| 99 |
/*--- forward declaration of static functions ---*/ |
| 100 |
|
| 101 |
|
| 102 |
/***************************************************************************** |
| 103 |
NAME: void replace_char_in_string (str, inch, outch) |
| 104 |
INPUT: char *str; - string to be modified |
| 105 |
char inch; - character to replace |
| 106 |
char outch; - replacement char |
| 107 |
RETURN: modified string |
| 108 |
DESCRIPTION: This routine takes a string as input and changes all |
| 109 |
occurences of inch in it with outch. |
| 110 |
CREATION Jan 7 1991 (bug1199) |
| 111 |
-----------------------------------------------------------------------------*/ |
| 112 |
|
| 113 |
void replace_char_in_str(str, inch, outch) |
| 114 |
char *str; |
| 115 |
char inch; |
| 116 |
char outch; |
| 117 |
{ |
| 118 |
char *pntr; |
| 119 |
char previous = 0; |
| 120 |
|
| 121 |
pntr=str; |
| 122 |
do { |
| 123 |
|
| 124 |
if (*pntr == inch && previous != '\\') |
| 125 |
*pntr = outch; |
| 126 |
previous = *pntr; |
| 127 |
} while (*pntr++ != '\0'); |
| 128 |
} |
| 129 |
|
| 130 |
#ifndef RUNTIME |
| 131 |
/***************************************************************************** |
| 132 |
NAME: void UxUpdateScreenSpecificResources() |
| 133 |
void UpdateResource(qualifier, rname) |
| 134 |
void UpdateFontResource(qualifier, rname, font1, font2) |
| 135 |
|
| 136 |
char *qualifier - "HighRes", "MediumRes", "LowRes" |
| 137 |
"Color" or "Mono" |
| 138 |
char *rname - resource name |
| 139 |
char *font1 - first default font name |
| 140 |
char *font2 - second default font name |
| 141 |
|
| 142 |
DESCRIPTION: These functions together get from the resource database |
| 143 |
certain UIM/X screen specific resources for the current type |
| 144 |
of screen and then put them back in the database without the |
| 145 |
screen specification if they are not already defined in the |
| 146 |
database. For example on a high res monitor |
| 147 |
Uimx*HighRes*UxSystem*FontList: |
| 148 |
gets written back to the resource database as |
| 149 |
Uimx*UxSystem*FontList: |
| 150 |
|
| 151 |
For fonts, if the requested ones aren't available, |
| 152 |
we attempt to substitute "variable" or "fixed". |
| 153 |
|
| 154 |
LAST REV: March 15, 1990 See bugfix 2111 |
| 155 |
July 29, 1991 See fix2830 |
| 156 |
September 10, 1991 See fix295 |
| 157 |
January 92 fix3331, fix3364 |
| 158 |
03/04/93 fix4050 removed HP specific code |
| 159 |
-----------------------------------------------------------------------------*/ |
| 160 |
|
| 161 |
void UxUpdateScreenSpecificResources() |
| 162 |
{ |
| 163 |
register char *res; |
| 164 |
register int width, height, pixels; |
| 165 |
extern void UpdateResource(); |
| 166 |
extern void UpdateFontResource(); |
| 167 |
|
| 168 |
res = UxGetAppResource("screenResolution"); |
| 169 |
if (res == NULL) { |
| 170 |
width = DisplayWidth(UxDisplay, UxScreen); |
| 171 |
height = DisplayHeight(UxDisplay, UxScreen); |
| 172 |
pixels = width * height; |
| 173 |
if (pixels >= 1000 * 1000) |
| 174 |
res = "HighRes"; |
| 175 |
else if (pixels >= 800 * 600) |
| 176 |
res = "MediumRes"; |
| 177 |
else |
| 178 |
res = "LowRes"; |
| 179 |
} |
| 180 |
|
| 181 |
UpdateFontResource(res, "UxSystem*SysFont1", |
| 182 |
"variable", "fixed"); |
| 183 |
UpdateFontResource(res, "UxSystem*FontList", |
| 184 |
"variable", "fixed"); |
| 185 |
UpdateFontResource(res, "UxSystem*XmText.fontList", |
| 186 |
"fixed", "variable"); |
| 187 |
UpdateFontResource(res, "UxSystem*XmTextField.fontList", |
| 188 |
"fixed", "variable"); |
| 189 |
UpdateResource(res, "uimxScale"); |
| 190 |
UpdateResource(res, "uimxXScale"); |
| 191 |
UpdateResource(res, "uimxYScale"); |
| 192 |
|
| 193 |
{ |
| 194 |
char *type = UxGetAppResource("screenType"); |
| 195 |
|
| 196 |
if (type == NULL) { |
| 197 |
Visual *vis = DefaultVisual(UxDisplay, UxScreen); |
| 198 |
|
| 199 |
#if defined(__cplusplus) || defined(c_plusplus) |
| 200 |
if( vis->c_class == GrayScale |
| 201 |
|| vis->c_class == StaticGray ) { |
| 202 |
#else |
| 203 |
if( vis->class == GrayScale |
| 204 |
|| vis->class == StaticGray ) { |
| 205 |
#endif |
| 206 |
type = "Mono"; |
| 207 |
} else { |
| 208 |
type = "Color"; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
UpdateResource(type, "UxSystem*foreground"); |
| 213 |
UpdateResource(type, "UxSystem*background"); |
| 214 |
} |
| 215 |
} |
| 216 |
#endif /* ! RUNTIME */ |
| 217 |
|
| 218 |
#ifndef RUNTIME |
| 219 |
static void UpdateResource(qualifier, rname) |
| 220 |
char *qualifier, *rname; |
| 221 |
{ |
| 222 |
dstring res; |
| 223 |
XrmValue value, value2; |
| 224 |
char *type, *type2; |
| 225 |
int found; |
| 226 |
extern char *UxProgramName, *UxProgramClassName; |
| 227 |
extern void UxPutAnyResource(); |
| 228 |
|
| 229 |
res = dcreate(qualifier); |
| 230 |
dappend(res, "."); |
| 231 |
dappend(res, rname); |
| 232 |
|
| 233 |
found = UxGetAnyResource(UxProgramName, dgetstr(res), &type, &value); |
| 234 |
if (found) { |
| 235 |
found = UxGetAnyResource(UxProgramName, rname, &type2, &value2); |
| 236 |
if (!found) { |
| 237 |
/*------------------------------------------- |
| 238 |
* Install the qualified resource |
| 239 |
* under the unqualified name. |
| 240 |
*-------------------------------------------*/ |
| 241 |
|
| 242 |
UxPutAnyResource(UxProgramClassName, rname, type, &value); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
dfree(res); |
| 247 |
} |
| 248 |
#endif /* ! RUNTIME */ |
| 249 |
|
| 250 |
#ifndef RUNTIME |
| 251 |
static void UpdateFontResource (qualifier, rname, font1, font2) |
| 252 |
char *qualifier, *rname, *font1, *font2; |
| 253 |
{ |
| 254 |
int isGeneral; |
| 255 |
int isSpecific = 0; |
| 256 |
char *type; |
| 257 |
XrmValue value, newvalue; |
| 258 |
extern char *UxProgramName; |
| 259 |
|
| 260 |
/*----------------------------------------------------- |
| 261 |
* Get the resource value. |
| 262 |
*-----------------------------------------------------*/ |
| 263 |
isGeneral = UxGetAnyResource (UxProgramName, rname, &type, &value); |
| 264 |
if (!isGeneral) |
| 265 |
{ |
| 266 |
dstring res; |
| 267 |
|
| 268 |
res = dcreate (qualifier); |
| 269 |
dappend (res, "."); |
| 270 |
dappend (res, rname); |
| 271 |
isSpecific = UxGetAnyResource(UxProgramName,dgetstr(res),&type,&value); |
| 272 |
dfree (res); |
| 273 |
} |
| 274 |
|
| 275 |
if (isGeneral || isSpecific) |
| 276 |
{ |
| 277 |
int isNewFont; |
| 278 |
/*----------------------------------------------------- |
| 279 |
* Validate the resource value. |
| 280 |
*-----------------------------------------------------*/ |
| 281 |
if (NO_ERROR == UxLoadOneFont ((char *)value.addr)) { |
| 282 |
newvalue.addr = value.addr; |
| 283 |
newvalue.size = strlen((char *)value.addr)+1; |
| 284 |
isNewFont = 0; |
| 285 |
} else { |
| 286 |
/*----------------------------------------------------- |
| 287 |
* No luck. Try the alternates.... |
| 288 |
*-----------------------------------------------------*/ |
| 289 |
UxStandardError (MCGETS (MS_MISC_FIND_FONT_CHANGE, |
| 290 |
DS_MS_MISC_FIND_FONT_CHANGE), |
| 291 |
font1); |
| 292 |
|
| 293 |
if (NO_ERROR == UxLoadOneFont (font1)) { |
| 294 |
newvalue.addr = (void *) font1; |
| 295 |
newvalue.size = strlen(font1)+1; |
| 296 |
} else { |
| 297 |
UxStandardError (MCGETS (MS_MISC_FIND_FONT_CHANGE, |
| 298 |
DS_MS_MISC_FIND_FONT_CHANGE), |
| 299 |
font2); |
| 300 |
newvalue.addr = (void *) font2; |
| 301 |
newvalue.size = strlen(font2)+1; |
| 302 |
} |
| 303 |
isNewFont = 1; |
| 304 |
} |
| 305 |
|
| 306 |
/*----------------------------------------------------- |
| 307 |
* Install the validated font resource |
| 308 |
* under its unqualified name. |
| 309 |
*-----------------------------------------------------*/ |
| 310 |
if (isSpecific || isNewFont) { |
| 311 |
|
| 312 |
extern char *UxProgramClassName; |
| 313 |
extern void UxPutAnyResource(); |
| 314 |
|
| 315 |
UxPutAnyResource(UxProgramClassName, rname, type, &newvalue); |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
#endif |
| 320 |
|
| 321 |
|
| 322 |
/***************************************************************************** |
| 323 |
NAME: void UxInitializeResourcePath() |
| 324 |
|
| 325 |
DESCRIPTION: initialize the resource file load path |
| 326 |
|
| 327 |
LAST REV: March 13, 1991 See bugfix 2111. |
| 328 |
Modified to conform to X resource path. |
| 329 |
-----------------------------------------------------------------------------*/ |
| 330 |
|
| 331 |
void UxInitializeResourcePath() |
| 332 |
{ |
| 333 |
static Boolean initialized = FALSE; |
| 334 |
dstring path, rdir, screen; |
| 335 |
char res[32]; |
| 336 |
char *getenv(); |
| 337 |
char *appResDir; |
| 338 |
|
| 339 |
if( initialized == TRUE ) { |
| 340 |
return; |
| 341 |
} else { |
| 342 |
initialized = TRUE; |
| 343 |
} |
| 344 |
|
| 345 |
if(UxResourcePath != NULL) |
| 346 |
return; |
| 347 |
|
| 348 |
screen= dcreate(UxGetAppResource("screenType")); |
| 349 |
|
| 350 |
if(dlen(screen) == 0) |
| 351 |
{ |
| 352 |
Visual *vis = DefaultVisual(UxDisplay, UxScreen); |
| 353 |
|
| 354 |
#if defined(__cplusplus) || defined(c_plusplus) |
| 355 |
if( vis->c_class == GrayScale || vis->c_class == StaticGray ) { |
| 356 |
#else |
| 357 |
if( vis->class == GrayScale || vis->class == StaticGray ) { |
| 358 |
#endif |
| 359 |
screen= dcreate("mono/"); |
| 360 |
} else { |
| 361 |
screen= dcreate("color/"); |
| 362 |
} |
| 363 |
} else { |
| 364 |
if (dnstr(screen)[0] == 'C') |
| 365 |
dnstr(screen)[0] = 'c'; |
| 366 |
if (dnstr(screen)[0] == 'M') |
| 367 |
dnstr(screen)[0] = 'm'; |
| 368 |
if( dnstr(screen)[dlen(screen)-1] != '/' ) |
| 369 |
dappend(screen, "/"); |
| 370 |
} |
| 371 |
|
| 372 |
sprintf(res, "%dx%d", DisplayWidth(UxDisplay, UxScreen), |
| 373 |
DisplayHeight(UxDisplay, UxScreen)); |
| 374 |
|
| 375 |
path= dcreate(" "); |
| 376 |
|
| 377 |
/* |
| 378 |
* The path is ordered such that if a file is present in more than |
| 379 |
* one directory, the second copy of the file override the previously |
| 380 |
* loaded copy. The following order is used: |
| 381 |
* |
| 382 |
* /usr/lib/X11/app-defaluts/ |
| 383 |
* /usr/lib/X11/app-defaults/$UXAPP/... |
| 384 |
* /usr/lib/X11/LANG/app-defaluts/ (for MOTIF only) |
| 385 |
* /usr/lib/X11/LANG/app-defaults/$UXAPP/... (for MOTIF only) |
| 386 |
* if XAPPLRESDIR exists |
| 387 |
* XAPPLRESDIR/$UXAPP/... |
| 388 |
* else |
| 389 |
* ~/$UXAPP/... |
| 390 |
* for compatibility with old versions of UIM/X add current directory |
| 391 |
* ./$UXAPP/... |
| 392 |
*/ |
| 393 |
|
| 394 |
/* /usr/lib/X11/app-defaults/ */ |
| 395 |
rdir = dcreate(" "); |
| 396 |
dappend(rdir, APPDEF); |
| 397 |
dappend(rdir, "/"); |
| 398 |
dconcat(path, rdir); |
| 399 |
|
| 400 |
/* /usr/lib/X11/app-defaults/<ClassName> */ |
| 401 |
dappend(rdir, "$UXAPP/"); |
| 402 |
dconcat(path, rdir); |
| 403 |
|
| 404 |
/* /usr/lib/X11/app-defaults/<ClassName>/color */ |
| 405 |
dconcat(path, rdir); |
| 406 |
dconcat(path, screen); |
| 407 |
|
| 408 |
/* /usr/lib/X11/app-defaults/<ClassName>/color/1280x1024 */ |
| 409 |
dconcat(path, rdir); |
| 410 |
dconcat(path, screen); |
| 411 |
dappend(path, res); |
| 412 |
|
| 413 |
dfree(rdir); |
| 414 |
|
| 415 |
#ifdef MOTIF_WIDGETS |
| 416 |
/* /usr/lib/X11/%L/app-defaults/ */ |
| 417 |
rdir = dcreate(" "); |
| 418 |
dappend(rdir, APPDEF2); |
| 419 |
dappend(rdir, "/"); |
| 420 |
dconcat(path, rdir); |
| 421 |
|
| 422 |
/* /usr/lib/X11/%L/app-defaults/<ClassName> */ |
| 423 |
dappend(rdir, "$UXAPP/"); |
| 424 |
dconcat(path, rdir); |
| 425 |
|
| 426 |
/* /usr/lib/X11/%L/app-defaults/<ClassName>/color */ |
| 427 |
dconcat(path, rdir); |
| 428 |
dconcat(path, screen); |
| 429 |
|
| 430 |
/* /usr/lib/X11/%L/app-defaults/<ClassName>/color/1280x1024 */ |
| 431 |
dconcat(path, rdir); |
| 432 |
dconcat(path, screen); |
| 433 |
dappend(path, res); |
| 434 |
|
| 435 |
dfree(rdir); |
| 436 |
#endif /* MOTIF_WIDGETS */ |
| 437 |
|
| 438 |
rdir = dcreate(" "); |
| 439 |
if ( (appResDir = getenv( "XAPPLRESDIR" )) != NULL ) { |
| 440 |
dappend(rdir, appResDir); |
| 441 |
} else { |
| 442 |
dappend(rdir, "~/"); |
| 443 |
} |
| 444 |
|
| 445 |
dappend(rdir, "$UXAPP/"); |
| 446 |
|
| 447 |
/* XAPPLRESDIR/<ClassName> or ~/<ClassName> */ |
| 448 |
dconcat(path, rdir); |
| 449 |
|
| 450 |
/* XAPPLRESDIR/<ClassName>/color or ~/<ClassName>/color */ |
| 451 |
dconcat(path, rdir); |
| 452 |
dconcat(path, screen); |
| 453 |
|
| 454 |
/* XAPPLRESDIR/<ClassName>/color/res or ~/<ClassName>/color/res */ |
| 455 |
dconcat(path, rdir); |
| 456 |
dconcat(path, screen); |
| 457 |
dappend(path, res); |
| 458 |
|
| 459 |
dfree(rdir); |
| 460 |
|
| 461 |
/* |
| 462 |
* Current directory for compatibility with old versions of UIM/X. |
| 463 |
*/ |
| 464 |
rdir = dcreate(" ./$UXAPP/"); |
| 465 |
|
| 466 |
/* ./<ClassName> */ |
| 467 |
dconcat(path, rdir); |
| 468 |
|
| 469 |
/* ./<ClassName>/color */ |
| 470 |
dconcat(path, rdir); |
| 471 |
dconcat(path, screen); |
| 472 |
|
| 473 |
/* ./<ClassName>/color/res */ |
| 474 |
dconcat(path, rdir); |
| 475 |
dconcat(path, screen); |
| 476 |
dappend(path, res); |
| 477 |
|
| 478 |
UxResourcePath= UxInitPath(dnstr(path)); |
| 479 |
|
| 480 |
dfree(rdir); |
| 481 |
dfree(screen); |
| 482 |
dfree(path); |
| 483 |
} |
| 484 |
|
| 485 |
/***************************************************************************** |
| 486 |
NAME: char *UxExpandResourceFilename(fname) |
| 487 |
|
| 488 |
INPUT: char *fname - resource file name |
| 489 |
|
| 490 |
RETURN: expanded name in a static buffer |
| 491 |
|
| 492 |
DESCRIPTION: find the full path to the resource file using the current |
| 493 |
resource file path. |
| 494 |
|
| 495 |
LAST REV: Jan 3/1989 |
| 496 |
-----------------------------------------------------------------------------*/ |
| 497 |
|
| 498 |
char *UxExpandResourceFilename(fname) |
| 499 |
char *fname; |
| 500 |
{ |
| 501 |
UxInitializeResourcePath(); |
| 502 |
|
| 503 |
return(UxExpandFilename(UxResourcePath, fname)); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
/***************************************************************************** |
| 508 |
NAME: void UxInitializeBitmapPath() |
| 509 |
|
| 510 |
DESCRIPTION: initialize the bitmap search path |
| 511 |
|
| 512 |
LAST REV: Feb 25/1989 |
| 513 |
-----------------------------------------------------------------------------*/ |
| 514 |
|
| 515 |
void UxInitializeBitmapPath() |
| 516 |
{ |
| 517 |
if(UxBitmapPath == NULL) { |
| 518 |
#if defined(MOTIF_WIDGETS) & ! defined(RUNTIME) |
| 519 |
char *str, *fmt= "$%s/icons %s", *buf; |
| 520 |
str = UxGetSysMessage( SM_U_TASKDIR, |
| 521 |
CGETS(MS_SYS_U_TASKDIR,DS_MS_SYS_U_TASKDIR)); |
| 522 |
buf = UxMalloc(strlen(fmt) + strlen(str) + strlen(DEFAULT_BPATH) + 1); |
| 523 |
sprintf(buf,fmt,str,DEFAULT_BPATH); |
| 524 |
UxBitmapPath= UxInitPath(buf); |
| 525 |
UxFree(buf); |
| 526 |
#else |
| 527 |
UxBitmapPath= UxInitPath(DEFAULT_BPATH); |
| 528 |
#endif |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
/***************************************************************************** |
| 533 |
NAME: char *UxExpandBitmapFilename(fname) |
| 534 |
|
| 535 |
INPUT: char *fname - filename |
| 536 |
|
| 537 |
RETURN: full path to bitmap file |
| 538 |
|
| 539 |
DESCRIPTION: search for the bitmap file 'fname' in the dirs given in |
| 540 |
UxBitmapPath |
| 541 |
|
| 542 |
LAST REV: Feb 21/1989 |
| 543 |
-----------------------------------------------------------------------------*/ |
| 544 |
|
| 545 |
char *UxExpandBitmapFilename(fname) |
| 546 |
char *fname; |
| 547 |
{ |
| 548 |
UxInitializeBitmapPath(); |
| 549 |
|
| 550 |
return(UxExpandFilename(UxBitmapPath, fname)); |
| 551 |
} |
| 552 |
|
| 553 |
/***************************************************************************** |
| 554 |
NAME: void UxOverrideResources(fname) |
| 555 |
|
| 556 |
INPUT: char *fname - resource file name |
| 557 |
|
| 558 |
DESCRIPTION: Load the resource file 'fname' and don't override its values |
| 559 |
by loading .Xdefaults again. |
| 560 |
|
| 561 |
LAST REV: September 24, 1992 See bugfix 3652. |
| 562 |
Removed XTDATABASE macro and put in new code for X11R5 support |
| 563 |
-----------------------------------------------------------------------------*/ |
| 564 |
|
| 565 |
void UxOverrideResources(fname) |
| 566 |
char *fname; |
| 567 |
{ |
| 568 |
XrmDatabase database = XtDatabase( UxDisplay); |
| 569 |
char *name; |
| 570 |
pathlist cur_dir; |
| 571 |
|
| 572 |
if(fname == NULL) |
| 573 |
return; |
| 574 |
|
| 575 |
cur_dir = UxInitPath("."); |
| 576 |
name = UxExpandFilename(cur_dir, fname); |
| 577 |
dfree(*cur_dir); |
| 578 |
|
| 579 |
if (name == NULL) |
| 580 |
{ |
| 581 |
return; |
| 582 |
} |
| 583 |
|
| 584 |
XrmCombineFileDatabase( name, &database, True); |
| 585 |
} |
| 586 |
|
| 587 |
/***************************************************************************** |
| 588 |
NAME: void UxLoadResources(fname) |
| 589 |
|
| 590 |
INPUT: char *fname - name of resource file |
| 591 |
|
| 592 |
DESCRIPTION: Load 'fname' into the current toolkit resource database |
| 593 |
nondestructively. |
| 594 |
|
| 595 |
LAST REV: September 24, 1992 See bugfix 3652. |
| 596 |
Removed XTDATABASE macro and put in new code for X11R5 support |
| 597 |
-----------------------------------------------------------------------------*/ |
| 598 |
|
| 599 |
void UxLoadResources(fname) |
| 600 |
char *fname; |
| 601 |
{ |
| 602 |
XrmDatabase database = XtDatabase( UxDisplay); |
| 603 |
char *name; |
| 604 |
pathlist cur_dir; |
| 605 |
|
| 606 |
if(fname == NULL) |
| 607 |
return; |
| 608 |
|
| 609 |
cur_dir = UxInitPath("."); |
| 610 |
name = UxExpandFilename(cur_dir, fname); |
| 611 |
dfree(*cur_dir); |
| 612 |
|
| 613 |
if (name == NULL) |
| 614 |
{ |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
XrmCombineFileDatabase( name, &database, False); |
| 619 |
} |
| 620 |
|
| 621 |
/***************************************************************************** |
| 622 |
NAME: char *UxGetResource(prog, rname) |
| 623 |
|
| 624 |
INPUT: char *prog - program name |
| 625 |
*rname - resource name |
| 626 |
|
| 627 |
RETURN: value of the requested resource in string form |
| 628 |
when successful. |
| 629 |
NULL is returned if the resource is not found or |
| 630 |
if the type of the resource is not an XtRString. |
| 631 |
|
| 632 |
DESCRIPTION: given a program 'name' and a resource name, get the |
| 633 |
associated resource from the resource database. |
| 634 |
|
| 635 |
LAST REV: Jan 10/91 - bug2006 |
| 636 |
-----------------------------------------------------------------------------*/ |
| 637 |
|
| 638 |
char *UxGetResource(prog, rname) |
| 639 |
char *prog, *rname; |
| 640 |
{ |
| 641 |
dstring ds; |
| 642 |
XrmString type; |
| 643 |
XrmValue rtrn; |
| 644 |
extern char *UxProgramClassName; |
| 645 |
dstring ds2; |
| 646 |
|
| 647 |
ds= dcreate(prog); |
| 648 |
dappend(ds, "."); |
| 649 |
dappend(ds, rname); |
| 650 |
|
| 651 |
ds2 = dcreate(UxProgramClassName); |
| 652 |
dappend(ds2, "."); |
| 653 |
dappend(ds2, rname); |
| 654 |
|
| 655 |
if( False == XrmGetResource( XtDatabase( UxDisplay), |
| 656 |
dnstr(ds), |
| 657 |
dnstr(ds2), |
| 658 |
&type, |
| 659 |
&rtrn) || |
| 660 |
strcmp (type, XtRString) != 0 ) |
| 661 |
{ |
| 662 |
rtrn.addr = (void *) NULL; |
| 663 |
} |
| 664 |
|
| 665 |
dfree(ds); |
| 666 |
dfree(ds2); |
| 667 |
|
| 668 |
return(rtrn.addr); |
| 669 |
} |
| 670 |
|
| 671 |
/***************************************************************************** |
| 672 |
NAME: char *UxGetAppResource(rname) |
| 673 |
INPUT: char *rname - resource name |
| 674 |
RETURN: resource value |
| 675 |
DESCRIPTION: get a resource for the program with name given by the |
| 676 |
environment variable UXAPP |
| 677 |
LAST REV: 5 Sept 1990 |
| 678 |
-- removed the ifdef's and both now use the MOTIF one; |
| 679 |
-----------------------------------------------------------------------------*/ |
| 680 |
|
| 681 |
char *UxGetAppResource(rname) |
| 682 |
char *rname; |
| 683 |
{ |
| 684 |
char *rtrn; |
| 685 |
extern char *UxProgramName; |
| 686 |
rtrn = UxGetResource(UxProgramName, rname); |
| 687 |
return(rtrn); |
| 688 |
} |
| 689 |
|
| 690 |
char *UxGetUimxResource(rname) |
| 691 |
char *rname; |
| 692 |
{ |
| 693 |
return(UxGetAppResource(rname)); |
| 694 |
} |
| 695 |
|
| 696 |
#ifndef RUNTIME |
| 697 |
/*************************************************************************** |
| 698 |
NAME: UxGetUimxWgtResource(rname) |
| 699 |
INPUT: char *rname : name of resource |
| 700 |
OUTPUT: --- |
| 701 |
RETURN: char * : string value of the resource |
| 702 |
DESCRIPTION: Prepends "UxSystem." to the name of the resource |
| 703 |
and then uses this qualified name to retrieve the value of |
| 704 |
the resource from the database. |
| 705 |
|
| 706 |
This function should be used for obtaining resources that |
| 707 |
apply to the widgets in UIM/X's own interfaces. |
| 708 |
(Such resources should be specified with "UxSystem." |
| 709 |
in the app-defaults file.) |
| 710 |
EXT REFERENCES: --- |
| 711 |
EXT EFFECTS: --- |
| 712 |
CREATION: Jan 13/91 |
| 713 |
|
| 714 |
---------------------------------------------------------------------------*/ |
| 715 |
char *UxGetUimxWgtResource(rname) |
| 716 |
char *rname; |
| 717 |
{ |
| 718 |
char *value; |
| 719 |
dstring ds; |
| 720 |
|
| 721 |
/* Prepend "UxSystem." to the resource name */ |
| 722 |
ds = dcreate("UxSystem."); |
| 723 |
dappend(ds, rname); |
| 724 |
|
| 725 |
value = UxGetAppResource(dnstr(ds)); |
| 726 |
|
| 727 |
dfree(ds); |
| 728 |
return (value); |
| 729 |
} |
| 730 |
#endif /* ! RUNTIME */ |
| 731 |
|
| 732 |
/***************************************************************************** |
| 733 |
NAME: char *UxGetDefault(prog, rname, def) |
| 734 |
|
| 735 |
INPUT: char *prog - program name |
| 736 |
*rname - resource name |
| 737 |
*def - default value |
| 738 |
|
| 739 |
RETURN: resource value |
| 740 |
|
| 741 |
DESCRIPTION: return the resource 'rname'. If not found return 'def' |
| 742 |
|
| 743 |
LAST REV: Feb 25/1989 |
| 744 |
-----------------------------------------------------------------------------*/ |
| 745 |
|
| 746 |
char *UxGetDefault(prog, rname, def) |
| 747 |
char *prog, *rname, *def; |
| 748 |
{ |
| 749 |
char *rtrn; |
| 750 |
|
| 751 |
rtrn= UxGetResource(prog, rname); |
| 752 |
|
| 753 |
if(rtrn == NULL) |
| 754 |
return(def); |
| 755 |
|
| 756 |
return(rtrn); |
| 757 |
} |
| 758 |
|
| 759 |
/***************************************************************************** |
| 760 |
NAME: char *UxGetUimxDefault(rname, def) |
| 761 |
|
| 762 |
INPUT: char *rname - resource name |
| 763 |
*def - default value |
| 764 |
|
| 765 |
RETURN: resource value |
| 766 |
|
| 767 |
DESCRIPTION: return the Uimx resource 'rname'. If not found return 'def' |
| 768 |
|
| 769 |
LAST REV: Feb 25/1989 |
| 770 |
-----------------------------------------------------------------------------*/ |
| 771 |
|
| 772 |
char *UxGetAppDefault(rname, def) |
| 773 |
char *rname, *def; |
| 774 |
{ |
| 775 |
char *rtrn; |
| 776 |
|
| 777 |
rtrn= UxGetUimxResource(rname); |
| 778 |
|
| 779 |
if(rtrn == NULL) |
| 780 |
return(def); |
| 781 |
|
| 782 |
return(rtrn); |
| 783 |
} |
| 784 |
|
| 785 |
char *UxGetUimxDefault(rname, def) |
| 786 |
char *rname, *def; |
| 787 |
{ |
| 788 |
return(UxGetAppDefault(rname, def)); |
| 789 |
} |
| 790 |
|
| 791 |
#ifndef RUNTIME |
| 792 |
/*************************************************************************** |
| 793 |
NAME: UxGetUimxWgtDefault(rname, def) |
| 794 |
INPUT: char *rname : name of resource |
| 795 |
char *def : fallback value |
| 796 |
OUTPUT: --- |
| 797 |
RETURN: char * : string value of the resource |
| 798 |
DESCRIPTION: Prepends "UxSystem." to the name of the resource |
| 799 |
and then uses this qualified name to retrieve the value of |
| 800 |
the resource from the database. If no such resource exists |
| 801 |
in the database, the fallback value is returned. |
| 802 |
|
| 803 |
This function should be used for obtaining resources that |
| 804 |
apply to the widgets in UIM/X's own interfaces. |
| 805 |
(Such resources should be specified with "UxSystem." |
| 806 |
in the app-defaults file.) |
| 807 |
EXT REFERENCES: --- |
| 808 |
EXT EFFECTS: --- |
| 809 |
CREATION: Jan 13/91 |
| 810 |
|
| 811 |
---------------------------------------------------------------------------*/ |
| 812 |
char *UxGetUimxWgtDefault(rname, def) |
| 813 |
char *rname, *def; |
| 814 |
{ |
| 815 |
char *value; |
| 816 |
dstring ds; |
| 817 |
|
| 818 |
/* Prepend "UxSystem." to the resource name */ |
| 819 |
ds = dcreate("UxSystem."); |
| 820 |
dappend(ds, rname); |
| 821 |
|
| 822 |
value = UxGetAppDefault(dnstr(ds), def); |
| 823 |
|
| 824 |
dfree(ds); |
| 825 |
return (value); |
| 826 |
} |
| 827 |
#endif /* ! RUNTIME */ |
| 828 |
|
| 829 |
static int scale_factors_uninitialized = 1; |
| 830 |
static float uimxXScale = 1.0; |
| 831 |
static float uimxYScale = 1.0; |
| 832 |
|
| 833 |
static int InitScaleFactors() |
| 834 |
{ |
| 835 |
float temp; |
| 836 |
|
| 837 |
#ifdef MOTIF_WIDGETS |
| 838 |
temp = atof(UxGetAppDefault("uimxScale", "1.0")); |
| 839 |
uimxXScale = temp * atof(UxGetAppDefault("uimxXScale", "1.0")); |
| 840 |
uimxYScale = temp * atof(UxGetAppDefault("uimxYScale", "1.0")); |
| 841 |
#endif /* MOTIF_WIDGETS */ |
| 842 |
scale_factors_uninitialized = 0; |
| 843 |
return NO_ERROR; |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
int UxScaleUimxX(width) |
| 849 |
int width; |
| 850 |
{ |
| 851 |
if (scale_factors_uninitialized) |
| 852 |
InitScaleFactors(); |
| 853 |
return (width*uimxXScale + 0.5); |
| 854 |
} |
| 855 |
|
| 856 |
int UxScaleUimxY(height) |
| 857 |
int height; |
| 858 |
{ |
| 859 |
if (scale_factors_uninitialized) |
| 860 |
InitScaleFactors(); |
| 861 |
return (height*uimxYScale + 0.5); |
| 862 |
} |
| 863 |
|
| 864 |
/***************************************************************************** |
| 865 |
NAME: int *UxGetAnyResource(prog, rname, type, value) |
| 866 |
|
| 867 |
INPUT: char *prog - program name |
| 868 |
*rname - resource name |
| 869 |
|
| 870 |
OUTPUT: char **type - type of resource value |
| 871 |
XrmValue *value - pointer to resource value |
| 872 |
|
| 873 |
RETURN: True if resource is found, False otherwise. |
| 874 |
|
| 875 |
DESCRIPTION: Given a program 'name' and a resource name, get the |
| 876 |
associated resource from the resource database. |
| 877 |
Handles any type of resource. |
| 878 |
|
| 879 |
LAST REV: March 15, 1991 See bugfix 2111. |
| 880 |
-----------------------------------------------------------------------------*/ |
| 881 |
|
| 882 |
int UxGetAnyResource(prog, rname, type, value) |
| 883 |
char *prog, *rname, **type; |
| 884 |
XrmValue *value; |
| 885 |
{ |
| 886 |
dstring ds, ds2; |
| 887 |
int rc; |
| 888 |
extern char *UxProgramClassName; |
| 889 |
|
| 890 |
ds= dcreate(prog); |
| 891 |
dappend(ds, "."); |
| 892 |
dappend(ds, rname); |
| 893 |
|
| 894 |
ds2 = dcreate(UxProgramClassName); |
| 895 |
dappend(ds2, "."); |
| 896 |
dappend(ds2, rname); |
| 897 |
|
| 898 |
replace_char_in_str( dnstr(ds),'*','.'); |
| 899 |
replace_char_in_str( dnstr(ds2),'*','.'); |
| 900 |
|
| 901 |
rc = XrmGetResource(XtDatabase( UxDisplay), |
| 902 |
dnstr(ds), dnstr(ds2), type, value); |
| 903 |
|
| 904 |
dfree(ds); |
| 905 |
dfree(ds2); |
| 906 |
|
| 907 |
return(rc); |
| 908 |
} |
| 909 |
|
| 910 |
/***************************************************************************** |
| 911 |
NAME: void UxPutAnyResource(prog, rname, type, value) |
| 912 |
|
| 913 |
INPUT: char *prog - program name or class name |
| 914 |
*rname - resource name |
| 915 |
*type - type of value |
| 916 |
XrmValue *value - value for resource |
| 917 |
|
| 918 |
DESCRIPTION: Given a program 'name' and a resource name, put the |
| 919 |
associated resource into the resource database. |
| 920 |
Handles any type of resource. |
| 921 |
|
| 922 |
LAST REV: March 15, 1991 See bugfix 2111. |
| 923 |
-----------------------------------------------------------------------------*/ |
| 924 |
|
| 925 |
void UxPutAnyResource(prog, rname, type, value) |
| 926 |
char *prog, *rname, *type; |
| 927 |
XrmValue *value; |
| 928 |
{ |
| 929 |
XrmDatabase database = XtDatabase( UxDisplay); |
| 930 |
|
| 931 |
dstring ds; |
| 932 |
|
| 933 |
ds = dcreate(prog); |
| 934 |
dappend(ds, "*"); /* Use '*' because rname may not be */ |
| 935 |
dappend(ds, rname); /* fully specified */ |
| 936 |
|
| 937 |
XrmPutResource(&database, dnstr(ds), type, value); |
| 938 |
|
| 939 |
dfree(ds); |
| 940 |
} |
| 941 |
/*--- end of file ---*/ |