Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2016, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
/****************************************************************
37
*
38
* initx.h: HyperDoc X Window window initialization code
39
*
40
* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
41
*
42
****************************************************************************/
43
44
/* #define DEBUG 1 */
45
46
#include "openaxiom-c-macros.h"
47
48
#include <unistd.h>
49
#include <sys/signal.h>
50
#include <setjmp.h>
51
#include <X11/cursorfont.h>
52
#include <X11/Xresource.h>
53
#include <X11/Xatom.h>
54
55
#include "debug.h"
56
#include "sockio.h"
57
#include "initx.h"
58
59
#ifdef SUN4OS5platform
60
extern int gethostname(char *, int );
61
#endif
62
63
#include "ht_icon"
64
#include "extent.h"
65
#include "group.h"
66
#include "hyper.h"
67
#include "scrollbar.h"
68
#include "titlebar.h"
69
#include "util.H1"
70
#include "cfuns.h"
71
#include "spadcolors.h"
72
73
#include "mouse11.bitmap"
74
#include "mouse11.mask"
75
76
using namespace OpenAxiom;
77
78
static void get_GCs(HDWindow * window);
79
static int get_border_properties();
80
static int get_color(const char* , const char* , int, Colormap*);
81
static void ingItColors_and_fonts();
82
static void load_font(XFontStruct * * font_info , char * fontname);
83
static void mergeDatabases();
84
static void open_form_window();
85
static void open_window(Window w);
86
static void set_name_and_icon();
87
static void set_size_hints(Window w);
88
89
90
static GContext server_font;
91
unsigned long *spadColors;
92
int scrn; /* used in spad_colors */
93
94
extern int received_window_request; /* true iff Spad wants a pop-up */
95
extern int in_next_event; /* true when in XNextEvent */
96
97
extern int gTtFontIs850;
98
99
#define MIN_WINDOW_SIZE 300
100
101
102
int gActiveColor,
103
gAxiomColor,
104
gBackgroundColor,
105
gBfColor,
106
gControlBackgroundColor,
107
gControlForegroundColor,
108
gEmColor,
109
gInputBackgroundColor,
110
gInputForegroundColor,
111
gItColor,
112
gRmColor,
113
gSlColor,
114
gTtColor;
115
116
XFontStruct *gAxiomFont,
117
*gActiveFont,
118
*gBfFont,
119
*gEmFont,
120
*gInputFont,
121
*gItFont,
122
*gRmFont,
123
*gSlFont,
124
*gTitleFont,
125
*gTtFont;
126
127
XrmDatabase rDB;
128
int gBorderColor; /* The Border Color */
129
130
/* Initialize the X Window System */
131
132
void
133
initializeWindowSystem()
134
{
135
char *display_name = NULL;
136
XColor fg, bg;
137
#if 0
138
XColor rgbdef;
139
#endif
140
Colormap cmap;
141
Pixmap mousebits, mousemask;
142
/* fprintf(stderr,"initx:initializeWindowSystem:entered\n");*/
143
/* Try to open the display */
144
/* fprintf(stderr,"initx:initializeWindowSystem:XOpenDisplay\n");*/
145
if ((gXDisplay = XOpenDisplay(display_name)) == NULL) {
146
fprintf(stderr, "(HyperDoc) Cannot connect to the X11 server!\n");
147
exit(-1);
148
}
149
150
/* Get the screen */
151
/* fprintf(stderr,"initx:initializeWindowSystem:DefaultScreen\n");*/
152
gXScreenNumber = scrn = DefaultScreen(gXDisplay);
153
/* fprintf(stderr,"initx:initializeWindowSystem:XGContextFromGC\n");*/
154
server_font =XGContextFromGC(DefaultGC(gXDisplay, gXScreenNumber));
155
156
/* Get the cursors we need. */
157
158
/* fprintf(stderr,"initx:initializeWindowSystem:DefaultColormap\n");*/
159
cmap = DefaultColormap(gXDisplay, gXScreenNumber);
160
/* fprintf(stderr,"initx:initializeWindowSystem:WhitePixel\n");*/
161
fg.pixel = WhitePixel(gXDisplay,gXScreenNumber);
162
/* fprintf(stderr,"initx:initializeWindowSystem:XQueryColor\n");*/
163
XQueryColor(gXDisplay, cmap, &fg );
164
/* fprintf(stderr,"initx:initializeWindowSystem:BlackPixel\n");*/
165
bg.pixel = BlackPixel(gXDisplay,gXScreenNumber);
166
/* fprintf(stderr,"initx:initializeWindowSystem:XQueryColor2\n");*/
167
XQueryColor(gXDisplay, cmap, &bg );
168
#if 0
169
XAllocNamedColor(gXDisplay, cmap, "Black", &fg, &rgbdef);
170
XAllocNamedColor(gXDisplay, cmap, "White", &bg, &rgbdef);
171
#endif
172
173
#ifdef USE_BORING_OLD_CURSORS
174
gActiveCursor = XCreateFontCursor(gXDisplay, XC_circle);
175
gNormalCursor = XCreateFontCursor(gXDisplay, XC_dot);
176
#else
177
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 1\n");*/
178
mousebits = XCreateBitmapFromData(gXDisplay,
179
RootWindow(gXDisplay, gXScreenNumber),
180
as_chars(mouseBitmap_bits), mouseBitmap_width,mouseBitmap_height);
181
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2\n");*/
182
mousemask = XCreateBitmapFromData(gXDisplay,
183
RootWindow(gXDisplay, gXScreenNumber),
184
as_chars(mouseMask_bits), mouseMask_width,mouseMask_height);
185
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2\n");*/
186
gActiveCursor = XCreatePixmapCursor(gXDisplay,
187
mousebits, mousemask, &fg, &bg,
188
mouseBitmap_x_hot,mouseBitmap_y_hot);
189
190
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor\n");*/
191
gNormalCursor = XCreateFontCursor(gXDisplay, XC_left_ptr);
192
#endif
193
194
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor 2\n");*/
195
gBusyCursor = XCreateFontCursor(gXDisplay, XC_watch);
196
197
/* Now initialize all the colors and fonts */
198
199
/* fprintf(stderr,"initx:initializeWindowSystem:ingItColors_and_fonts\n");*/
200
ingItColors_and_fonts();
201
/* fprintf(stderr,"initx:initializeWindowSystem:init_text\n");*/
202
init_text();
203
/* fprintf(stderr,"initx:initializeWindowSystem:exited\n");*/
204
205
}
206
207
/*
208
* This routine is responsible for initializing a HyperDoc Window. At this
209
* point, all the fonts have been loaded, and X has been initialized. All I
210
* need worry about is starting up the window, and creating some of its
211
* children.
212
*/
213
214
215
/*
216
* init_top_window tries to start up a window with the page name. If the
217
* page name is NULL,
218
* it doesn't try to find it in the Hash Table, but rather just allocates a
219
* page of no name
220
*/
221
222
int
223
init_top_window(const char *name)
224
{
225
HyperDocPage *page;
226
XSetWindowAttributes wa; /* The X attributes structure */
227
HDWindow *old_win = gWindow;
228
229
gWindow = alloc_hd_window();
230
231
if (name == NULL) {
232
/** Then allocate an empty page, and assign it to gWindow->page */
233
page = alloc_page((char *) NULL);
234
}
235
else {
236
/* Try to find the page in the page hash table */
237
page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, name);
238
if (page == NULL) {
239
fprintf(stderr, "(HyperDoc) Couldn\'t find page %s in page hash table \n",
240
name);
241
if (gParentWindow == NULL)
242
/* Gaak, This is a start up error */
243
exit(-1);
244
else {
245
gWindow = old_win;
246
return -1;
247
}
248
}
249
}
250
251
/* First allocate memory for the new window structure */
252
gWindow->page = page;
253
254
if (old_win == NULL)
255
open_window(0);
256
else
257
open_window(old_win->fMainWindow);
258
259
get_GCs(gWindow);
260
XMapWindow(gXDisplay, gWindow->fMainWindow);
261
hash_insert(&gSessionHashTable, (char *)gWindow,(char *) &gWindow->fMainWindow);
262
263
change_text(gRmColor, gRmFont);
264
wa.background_pixel = gBackgroundColor;
265
XChangeWindowAttributes(gXDisplay, gWindow->fMainWindow, CWBackPixel, &wa);
266
XChangeWindowAttributes(gXDisplay, gWindow->fScrollWindow, CWBackPixel,&wa);
267
return 1;
268
}
269
270
/* Create and initialize a form HyperDoc window */
271
272
static void
273
open_form_window()
274
{
275
int x, y, width, height;
276
unsigned int fwidth = 0, fheight = 0;
277
unsigned int xadder = 0, yadder = 0;
278
/*char *window_name = "HyperDoc";*/
279
/*char *icon_name = "HT";*/
280
XrmValue value;
281
char *str_type[50];
282
XSizeHints size_hints;
283
int userSpecified = 0;
284
285
char userdefaults[50], progdefaults[50];
286
287
strcpy(progdefaults, "=950x450+0+0");
288
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.FormGeometry",
289
"OpenAxiom.hyperdoc.FormGeometry", str_type, &value) == True)
290
{
291
strncpy(userdefaults, value.addr, (int) value.size);
292
userSpecified = 1;
293
}
294
else
295
strcpy(userdefaults, progdefaults);
296
297
XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
298
0, fwidth, fheight, xadder, yadder,
299
&x, &y, &width, &height);
300
301
gWindow->border_width = get_border_properties();
302
303
gWindow->width = 1;
304
gWindow->height = 1;
305
306
gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber),
307
x, y, width, height, gWindow->border_width,
308
gBorderColor,
309
WhitePixel(gXDisplay, gXScreenNumber));
310
gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
311
1, 1, 1, 1, 0,
312
BlackPixel(gXDisplay, gXScreenNumber),
313
WhitePixel(gXDisplay, gXScreenNumber));
314
makeScrollBarWindows();
315
makeTitleBarWindows();
316
317
set_name_and_icon();
318
319
XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask);
320
XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask);
321
XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor);
322
323
/* now give the window manager some hints */
324
325
size_hints.flags = 0;
326
327
size_hints.min_width = width;
328
size_hints.min_height = height;
329
size_hints.flags |= PMinSize;
330
331
size_hints.width = width;
332
size_hints.height = height;
333
size_hints.flags |= (userSpecified ? USSize : PSize);
334
335
size_hints.x = x;
336
size_hints.y = y;
337
size_hints.flags |= (userSpecified ? USPosition : PPosition);
338
339
XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints);
340
XFlush(gXDisplay);
341
}
342
343
344
int
345
init_form_window(char *name, int cols)
346
{
347
XSetWindowAttributes wa; /* The X attributes structure */
348
349
/* First allocate memory for the new window structure */
350
351
gWindow = alloc_hd_window();
352
open_form_window();
353
gWindow->width = window_width(cols);
354
355
if (name == NULL) {
356
/** Then allocate an empty page, and assign it to gWindow->page */
357
gWindow->page = alloc_page((char *) NULL);
358
}
359
else {
360
/* Try to find the page in the page hash table */
361
gWindow->page = (HyperDocPage *) hash_find(gWindow->fPageHashTable, name);
362
if (gWindow->page == NULL) {
363
fprintf(stderr, "Couldn't find page %s\n", name);
364
return (-1);
365
}
366
}
367
368
get_GCs(gWindow);
369
hash_insert(&gSessionHashTable, (char *)gWindow,(char *) &gWindow->fMainWindow);
370
371
wa.background_pixel = gBackgroundColor;
372
XChangeWindowAttributes(gXDisplay, gWindow->fMainWindow, CWBackPixel, &wa);
373
XChangeWindowAttributes(gXDisplay, gWindow->fScrollWindow, CWBackPixel,&wa);
374
return 1;
375
}
376
377
378
static void
379
set_name_and_icon()
380
{
381
const char *icon_name = "HyperDoc";
382
char *s;
383
Pixmap icon_pixmap;
384
XWMHints wmhints;
385
XClassHint ch;
386
387
ch.res_name = "HyperDoc";
388
ch.res_class = gArgv[0];
389
for (s = gArgv[0] + strlen(gArgv[0]) - 1; s != gArgv[0]; s--) {
390
if (*s == '/') {
391
ch.res_class = s + 1;
392
break;
393
}
394
}
395
XSetClassHint(gXDisplay, gWindow->fMainWindow, &ch);
396
397
XStoreName(gXDisplay, gWindow->fMainWindow, "HyperDoc");
398
399
/* define and assign the pixmap for the icon */
400
icon_pixmap = XCreateBitmapFromData(gXDisplay, gWindow->fMainWindow,
401
as_chars(ht_icon_bits),
402
ht_icon_width, ht_icon_height);
403
wmhints.icon_pixmap = icon_pixmap;
404
wmhints.flags = IconPixmapHint;
405
406
XSetWMHints(gXDisplay, gWindow->fMainWindow, &wmhints);
407
408
/* name the icon */
409
XSetIconName(gXDisplay, gWindow->fMainWindow, icon_name);
410
}
411
412
static int
413
get_border_properties()
414
{
415
const char *bwidth;
416
/*char *bc = NULL;*/
417
int bw;
418
/*XColor color_def, color_db;*/
419
Colormap cmap;
420
/*int ret_val;*/
421
422
423
bwidth = "2"; /* XGetDefault(gXDisplay, "Axiom.hyperdoc", "BorderWidth") */
424
425
if (bwidth == NULL)
426
bw = 1;
427
else {
428
bw = atoi(bwidth);
429
if (bw < 1) {
430
fprintf(stderr,
431
"%s: The line width value must be greater than zero\n", "OpenAxiom.hyperdoc");
432
bw = 1;
433
}
434
}
435
436
/* Now try to find the user preferred border color */
437
438
if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1)
439
gBorderColor = BlackPixel(gXDisplay, gXScreenNumber);
440
else {
441
cmap = DefaultColormap(gXDisplay, gXScreenNumber);
442
gBorderColor = get_color("BorderColor", "Foreground",
443
BlackPixel(gXDisplay, gXScreenNumber), &cmap);
444
}
445
return bw;
446
}
447
448
449
/* Create and initialize the HyperDoc window */
450
451
static void
452
open_window(Window w)
453
{
454
int x = 0, y = 0;
455
/*int border_width = 2;*/
456
unsigned int width = 1;
457
unsigned int height = 1;
458
unsigned int fwidth = 0, fheight = 0;
459
unsigned int xadder = 0, yadder = 0;
460
char *str_type[50];
461
XrmValue value;
462
463
char userdefaults[50], progdefaults[50];
464
465
strcpy(progdefaults, "=700x450+0+0");
466
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.Geometry",
467
"OpenAxiom.hyperdoc.Geometry", str_type, &value) == True)
468
{
469
strncpy(userdefaults, value.addr, (int) value.size);
470
}
471
else
472
strcpy(userdefaults, progdefaults);
473
474
XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
475
0, fwidth, fheight, xadder, yadder,
476
&x, &y, ( int *)&width,( int *) &height);
477
478
gWindow->border_width = get_border_properties();
479
480
gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber),
481
x, y, width, height, gWindow->border_width,
482
gBorderColor,
483
WhitePixel(gXDisplay, gXScreenNumber));
484
485
gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
486
1, 1, 1, 1, 0,
487
gBorderColor,
488
WhitePixel(gXDisplay, gXScreenNumber));
489
490
491
makeScrollBarWindows();
492
makeTitleBarWindows();
493
494
/* Now set all the little properties for the top level window */
495
496
set_name_and_icon();
497
set_size_hints(w);
498
XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask);
499
XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask);
500
XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor);
501
}
502
503
/***
504
This routine gets and sets the size for a new window. If the w parameter
505
is null, it means that this is the initial window. Thus the user
506
preferences are checked. If this is not the first window, then the
507
window w is used as a guidline, and the new window is placed on top of
508
it.
509
***/
510
511
static void
512
set_size_hints(Window w)
513
{
514
int x, y;
515
unsigned int width, height;
516
char userdefaults[50];
517
char progdefaults[50];
518
char *str_type[50];
519
unsigned int fwidth = 0, fheight = 0;
520
unsigned int xadder = 0, yadder = 0;
521
int geo = 0; /* return flag from XGetGeometry */
522
unsigned int depth, bw=0;
523
Window root;
524
XSizeHints size_hints;
525
XPoint xp;
526
XrmValue value;
527
528
size_hints.flags = 0;
529
530
strcpy(progdefaults, "=600x450+0+0");
531
532
if (w) {
533
/*
534
* The window should be queried for it's size and position. Then the
535
* new window should be given almost the same locations
536
*/
537
538
if (XGetGeometry(gXDisplay, w, &root, &x, &y, &width, &height, &bw, &depth))
539
{
540
xp = getWindowPositionXY(gXDisplay, w);
541
x = xp.x + 40;
542
y = xp.y + 40;
543
if (x < 0)
544
x = 0;
545
if (y < 0)
546
y = 0;
547
size_hints.flags |= (USSize | USPosition);
548
}
549
else {
550
fprintf(stderr, "(HyperDoc) Error Querying window configuration: %ld.\n", w);
551
x = y = 0;
552
width = 600;
553
height = 450;
554
size_hints.flags |= (PSize | PPosition);
555
}
556
}
557
else {
558
/* this is the first window, so lets try to find a nice spot for it */
559
560
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.Geometry", "OpenAxiom.hyperdoc.Geometry",
561
str_type, &value) == True)
562
{
563
strncpy(userdefaults, value.addr, (int) value.size);
564
geo = XParseGeometry(userdefaults, &x, &y, &width, &height);
565
}
566
else
567
strcpy(userdefaults, progdefaults);
568
569
size_hints.flags |= (geo & (WidthValue | HeightValue)) ? USSize : PSize;
570
size_hints.flags |= (geo & (XValue | YValue)) ? USPosition : PPosition;
571
572
geo = XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
573
bw, fwidth, fheight, xadder, yadder,
574
&x, &y, (int *)&width, (int *)&height);
575
}
576
577
size_hints.x = x;
578
size_hints.y = y;
579
size_hints.width = width;
580
size_hints.height = height;
581
582
getTitleBarMinimumSize(&(size_hints.min_width), &(size_hints.min_height));
583
#if 0
584
size_hints.min_width = MIN_WINDOW_SIZE;
585
size_hints.min_height = MIN_WINDOW_SIZE;
586
#endif
587
size_hints.flags |= PMinSize;
588
589
XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints);
590
/* just in case a hint isn't enough ... */
591
XFlush(gXDisplay);
592
/* XMoveResizeWindow(gXDisplay, gWindow->fMainWindow, x, y, width, height); */
593
}
594
595
#define stipple_width 4
596
#define stipple_height 4
597
static unsigned char stipple_bits[] = {
598
0xff, 0xff, 0xff, 0xff};
599
Pixmap stipple;
600
601
/* Create the graphics contexts to be used for all drawing operations */
602
603
static void
604
get_GCs(HDWindow *window)
605
{
606
/*unsigned long valuemask = 0;*/
607
XGCValues values;
608
609
values.background = gBackgroundColor;
610
window->fStandardGC = XCreateGC(gXDisplay, window->fMainWindow, GCBackground, &values);
611
612
XSetLineAttributes(gXDisplay, window->fStandardGC, window->border_width,
613
LineSolid, CapButt, JoinMiter);
614
615
616
/* create the stipple for the gc */
617
618
stipple = XCreateBitmapFromData(gXDisplay,
619
RootWindow(gXDisplay, gXScreenNumber),
620
as_chars(stipple_bits), stipple_width, stipple_height);
621
622
values.background = gInputBackgroundColor;
623
values.foreground = gInputForegroundColor;
624
625
values.font = gInputFont->fid;
626
627
if (values.font == server_font )
628
window->fInputGC = XCreateGC(gXDisplay, window->fMainWindow,
629
GCBackground | GCForeground, &values);
630
else {
631
window->fInputGC = XCreateGC(gXDisplay, window->fMainWindow,
632
GCBackground | GCForeground | GCFont, &values);
633
}
634
635
window->fCursorGC = XCreateGC(gXDisplay, window->fMainWindow, 0, NULL);
636
637
if (values.font != server_font)
638
XSetFont(gXDisplay, window->fCursorGC, gInputFont->fid);
639
640
XSetBackground(gXDisplay, window->fCursorGC, gInputForegroundColor);
641
XSetForeground(gXDisplay, window->fCursorGC, gInputBackgroundColor);
642
643
window->fControlGC = XCreateGC(gXDisplay, window->fMainWindow, 0, NULL);
644
XSetBackground(gXDisplay, window->fControlGC, gControlBackgroundColor);
645
XSetForeground(gXDisplay, window->fControlGC, gControlForegroundColor);
646
}
647
648
/* Load a font and store the information in the font_info parameter */
649
650
static void
651
load_font(XFontStruct **font_info, char *fontname)
652
{
653
if ((*font_info = XLoadQueryFont(gXDisplay, fontname)) == NULL) {
654
fprintf(stderr, "(HyperDoc) Cannot load font %s ; using default.\n",
655
fontname);
656
657
if ((*font_info = XQueryFont(gXDisplay,
658
XGContextFromGC(DefaultGC(gXDisplay, gXScreenNumber)))) == NULL)
659
{
660
fprintf(stderr, "(HyperDoc) Cannot get default font ; exiting.\n");
661
exit(-1);
662
}
663
}
664
}
665
666
667
/*
668
* This routine initializes all the colors and fonts that the user wishes to
669
* use. It checks for all the following properties in $HOME/.Xdefaults.
670
*
671
* OpenAxiom.hyperdoc.ActiveColor:
672
* OpenAxiom.hyperdoc.Background:
673
* OpenAxiom.hyperdoc.EmphasizeColor:
674
* OpenAxiom.hyperdoc.EmphasizeFont:
675
* OpenAxiom.hyperdoc.Foreground:
676
* OpenAxiom.hyperdoc.InputBackground:
677
* OpenAxiom.hyperdoc.InputForeground:
678
* OpenAxiom.hyperdoc.SpadColor:
679
* OpenAxiom.hyperdoc.SpadFont:
680
*/
681
682
static void
683
ingItColors_and_fonts()
684
{
685
char property[256];
686
char *prop = &property[0];
687
char *str_type[50];
688
XrmValue value;
689
Colormap cmap;
690
int ts;
691
692
/** get the color map for the display **/
693
/* fprintf(stderr,"initx:ingItColors_and_fonts:entered\n");*/
694
695
/* fprintf(stderr,"initx:ingItColors_and_fonts:DefaultColorMap\n");*/
696
cmap = DefaultColormap(gXDisplay, gXScreenNumber);
697
698
/* fprintf(stderr,"initx:ingItColors_and_fonts:init_group_stack\n");*/
699
init_group_stack();
700
701
702
/** then start getting the fonts **/
703
704
/* fprintf(stderr,"initx:ingItColors_and_fonts:mergeDatabases\n");*/
705
mergeDatabases();
706
707
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource\n");*/
708
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.RmFont",
709
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
710
strncpy(prop, value.addr, (int) value.size);
711
else
712
strcpy(prop, RmFontDefault);
713
714
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 1\n");*/
715
load_font(&gRmFont, prop);
716
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 2\n");*/
717
load_font(&gInputFont, prop);
718
719
720
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 2\n");*/
721
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.TtFont",
722
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
723
strncpy(prop, value.addr, (int) value.size);
724
else
725
strcpy(prop, TtFontDefault);
726
727
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 3\n");*/
728
load_font(&gTtFont, prop);
729
/* fprintf(stderr,"initx:ingItColors_and_fonts:is_it_850\n");*/
730
gTtFontIs850=is_it_850(gTtFont);
731
732
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 5\n");*/
733
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.ActiveFont",
734
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
735
strncpy(prop, value.addr, (int) value.size);
736
else
737
strcpy(prop, ActiveFontDefault);
738
739
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 4\n");*/
740
load_font(&gActiveFont, prop);
741
742
/* maintain backwards compatibility */
743
744
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 6\n");*/
745
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.AxiomFont",
746
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
747
strncpy(prop, value.addr, (int) value.size);
748
else {
749
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.SpadFont",
750
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
751
{
752
strncpy(prop, value.addr, (int) value.size);
753
}
754
else {
755
strcpy(prop, AxiomFontDefault);
756
}
757
}
758
759
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 5\n");*/
760
load_font(&gAxiomFont, prop);
761
762
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 7\n");*/
763
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.EmphasizeFont",
764
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
765
{
766
strncpy(prop, value.addr, (int) value.size);
767
}
768
else {
769
strcpy(prop, EmphasizeFontDefault);
770
}
771
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 6\n");*/
772
load_font(&gEmFont, prop);
773
774
/* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 8\n");*/
775
if (XrmGetResource(rDB, "OpenAxiom.hyperdoc.BoldFont",
776
"OpenAxiom.hyperdoc.Font", str_type, &value) == True)
777
{
778
strncpy(prop, value.addr, (int) value.size);
779
}
780
else {
781
strcpy(prop, BoldFontDefault);
782
}
783
/* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 7\n");*/
784
load_font(&gBfFont, prop);
785
786
787
/*
788
* If we are on a monochrome screen, then we ignore user preferences, and
789
* set the foreground and background as I wish
790
*/
791
792
/* fprintf(stderr,"initx:ingItColors_and_fonts:DisplayPlanes\n");*/
793
if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1) {
794
gActiveColor = gAxiomColor
795
= gControlBackgroundColor
796
= gInputBackgroundColor
797
= gBfColor
798
= gEmColor
799
= gRmColor
800
= gSlColor
801
= gTtColor
802
= BlackPixel(gXDisplay, gXScreenNumber);
803
804
gBackgroundColor = gInputForegroundColor
805
= gControlForegroundColor
806
= WhitePixel(gXDisplay, gXScreenNumber);
807
}
808
else {
809
810
/*
811
* If I have gotten here, then we must be on a color screen, so see
812
* what the user likes, and set it up
813
*/
814
815
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 1\n");*/
816
gRmColor =
817
get_color("RmColor", "Foreground",
818
BlackPixel(gXDisplay, gXScreenNumber), &cmap);
819
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 2\n");*/
820
gBackgroundColor =
821
get_color("Background", "Background",
822
WhitePixel(gXDisplay, gXScreenNumber), &cmap);
823
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 3\n");*/
824
gActiveColor =
825
get_color("ActiveColor", "Foreground",
826
BlackPixel(gXDisplay, gXScreenNumber), &cmap);
827
828
/*
829
* for next two, I want name arg = class arg, ie do not want
830
* Background and Foreground.
831
*/
832
833
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 4\n");*/
834
gControlBackgroundColor = get_color("ControlBackground",
835
"ControlBackground", WhitePixel(gXDisplay, gXScreenNumber), &cmap);
836
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 5\n");*/
837
gControlForegroundColor = get_color("ControlForeground",
838
"ControlForeground", BlackPixel(gXDisplay, gXScreenNumber), &cmap);
839
840
/* maintain backwards compatibility */
841
842
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 6\n");*/
843
gAxiomColor = get_color("OpenAxiomColor", "Foreground", 0, &cmap);
844
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 7\n");*/
845
if (gAxiomColor == 0)
846
gAxiomColor = get_color("SpadColor", "Foreground",
847
BlackPixel(gXDisplay, gXScreenNumber), &cmap);
848
849
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 8\n");*/
850
gInputBackgroundColor =
851
get_color("InputBackground", "Foreground", gRmColor, &cmap);
852
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 9\n");*/
853
gInputForegroundColor =
854
get_color("InputForeground", "Background", gBackgroundColor, &cmap);
855
856
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 10\n");*/
857
gEmColor =
858
get_color("EmphasizeColor", "Foreground", gRmColor, &cmap);
859
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 11\n");*/
860
gTtColor =
861
get_color("TtColor", "Foreground", gRmColor, &cmap);
862
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 12\n");*/
863
gSlColor =
864
get_color("EmphasizeColor", "Foreground", gRmColor, &cmap);
865
/* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 13\n");*/
866
gBfColor =
867
get_color("BoldColor", "Foreground", gRmColor, &cmap);
868
}
869
870
/* fprintf(stderr,"initx:ingItColors_and_fonts:makeColors\n");*/
871
makeColors(gXDisplay, gXScreenNumber, &cmap, &spadColors, &ts);
872
/*
873
* Now set the current color and font, so I never have to do it again
874
*/
875
876
gTopOfGroupStack->cur_color = gRmColor;
877
gTopOfGroupStack->cur_font = gRmFont;
878
/* fprintf(stderr,"initx:ingItColors_and_fonts:exited\n");*/
879
}
880
881
void
882
change_text(int color, XFontStruct *font)
883
{
884
if (font) {
885
XGCValues gcv;
886
gcv.foreground = color;
887
gcv.background = gBackgroundColor;
888
889
XChangeGC(gXDisplay, gWindow->fStandardGC, GCForeground | GCBackground , &gcv);
890
891
if (font->fid != server_font)
892
XSetFont(gXDisplay, gWindow->fStandardGC, font->fid);
893
}
894
}
895
896
/*
897
* This routine checks the .Xdefaults file of the user for the
898
* specified color. If found it allocates a place in the color map for it. If
899
* not found, or if an error occurrs, it writes an error message, and
900
* uses the given default value
901
*/
902
903
static int
904
get_color(const char *name, const char *klass, int def, Colormap *map)
905
{
906
char fullname[256];
907
char fullclass[256];
908
char property[256];
909
char *prop = &property[0];
910
char *str_type[50];
911
XrmValue value;
912
int ret_val;
913
XColor color_def, color_db;
914
915
#ifdef DEBUG
916
printf("get_color: %s %s %d -> ", name, class, def);
917
#endif
918
919
strcpy(fullname, "OpenAxiom.hyperdoc.");
920
strcat(fullname, name);
921
strcpy(fullclass,"OpenAxiom.hyperdoc.");
922
strcat(fullclass, klass);
923
924
if (XrmGetResource(rDB, fullname, fullclass, str_type, &value) == True) {
925
strncpy(prop, value.addr, (int) value.size);
926
ret_val = XAllocNamedColor(gXDisplay, *map, prop, &color_def, &color_db);
927
if (ret_val) {
928
#ifdef DEBUG
929
printf("%d\n", color_def.pixel);
930
#endif
931
return (color_def.pixel);
932
}
933
else {
934
fprintf(stderr,
935
"(HyperDoc) Defaulting on color for %s. Unknown color is %s.\n",
936
name, prop);
937
#ifdef DEBUG
938
printf("%d\n", def);
939
#endif
940
return (def);
941
}
942
}
943
else {
944
#ifdef DEBUG
945
printf("%d\n", def);
946
#endif
947
return (def);
948
}
949
}
950
951
952
static void
953
mergeDatabases()
954
{
955
XrmDatabase homeDB, serverDB, applicationDB;
956
char filenamebuf[1024];
957
char *filename = &filenamebuf[0];
958
const char *classname = "OpenAxiom";
959
char name[255];
960
961
/* fprintf(stderr,"initx:mergeDatabases:entered\n");*/
962
/* fprintf(stderr,"initx:mergeDatabases:XrmInitialize\n");*/
963
XrmInitialize();
964
strcpy(name, "/usr/lib/X11/app-defaults/");
965
strcat(name, classname);
966
/* fprintf(stderr,"initx:mergeDatabases:XrmGetFileDatabase name=%s\n",name);*/
967
applicationDB = XrmGetFileDatabase(name);
968
/* fprintf(stderr,"initx:mergeDatabases:XrmMergeDatabases\n");*/
969
XrmMergeDatabases(applicationDB, &rDB);
970
971
/* fprintf(stderr,"initx:mergeDatabases:XrmGetStringDatabase\n");*/
972
if (XResourceManagerString(gXDisplay) != NULL) {
973
serverDB = XrmGetStringDatabase(XResourceManagerString(gXDisplay));
974
}
975
else {
976
strcpy(filename, oa_getenv("HOME"));
977
strcat(filename, "/.Xdefaults");
978
/* fprintf(stderr,"initx:mergeDatabases:XrmGetFileDatase\n");*/
979
serverDB = XrmGetFileDatabase(filename);
980
}
981
/* fprintf(stderr,"initx:mergeDatabases:XrmMergeDatabases 2\n");*/
982
XrmMergeDatabases(serverDB, &rDB);
983
if (oa_getenv("XENVIRONMENT") == NULL) {
984
int len;
985
986
strcpy(filename, oa_getenv("HOME"));
987
strcat(filename, "/.Xdefaults-");
988
len = strlen(filename);
989
gethostname(filename + len, 1024 - len);
990
}
991
else {
992
strcpy(filename, oa_getenv("XENVIRONMENT"));
993
}
994
/* fprintf(stderr,"initx:mergeDatabases:filename=%s\n",filename);*/
995
homeDB = XrmGetFileDatabase(filename);
996
/* fprintf(stderr,"initx:mergeDatabases:XrmMergeDatabases 3\n");*/
997
XrmMergeDatabases(homeDB, &rDB);
998
}
999
1000
1001
1002
int
1003
is_it_850(XFontStruct *fontarg)
1004
{
1005
char* s;
1006
int i,val;
1007
static struct {
1008
const char *name;
1009
Atom format;
1010
Atom atom;
1011
} proptbl = { "CHARSET_ENCODING", XA_ATOM };
1012
proptbl.atom = XInternAtom(gXDisplay,proptbl.name,0);
1013
for (i=0;i<fontarg->n_properties;i++)
1014
{
1015
if (fontarg->properties[i].name != proptbl.atom) continue;
1016
1017
1018
/* return 1 if it is 850 */
1019
1020
s = XGetAtomName(gXDisplay,(Atom)fontarg->properties[i].card32);
1021
val = !( strcmp("850",s) * strcmp("ibm-850",s));
1022
XFree(s);
1023
return( val );
1024
}
1025
return(0);
1026
}
1027
1028
1029