1 /*
2 Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 - Neither the name of The Numerical ALgorithms Group Ltd. nor the
18 names of its contributors may be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /******************************************************************************
35 *
36 * titlebar.c: Produces HyperDoc titlebar
37 *
38 * Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
39 *
40 ****************************************************************************/
41
42 #include "fricas_c_macros.h"
43 #include "debug.h"
44
45 #include <stdlib.h>
46
47 #include "hyper.h"
48 #include "parse.h"
49
50 #include "all_hyper_proto.H1"
51
52 static void readTitleBarImages(void);
53
54 extern int y_off; /* y offset for scrolling regions */
55
56 /* Images for the title bar windows */
57
58 static XImage *tw1image = NULL,
59 *tw2image = NULL,
60 *tw3image = NULL,
61 *tw4image = NULL,
62 *noopimage = NULL;
63
64 /* #undef BITMAPS2D to get old style 2d effect */
65
66 #ifdef BITMAPS2D
67
68 static char *tw1file = "exit.bitmap";
69 static char *tw2file = "help2.bitmap";
70 static char *tw3file = "return3.bitmap";
71 static char *tw4file = "up3.bitmap";
72 static char *noopfile = "noop.bitmap";
73
74 #define BACKCOLOR gBackgroundColor
75 #define BUTTGC fStandardGC
76
77 #else
78
79 static char *tw1file = "exit3d.bitmap";
80 static char *tw2file = "help3d.bitmap";
81 static char *tw3file = "home3d.bitmap";
82 static char *tw4file = "up3d.bitmap";
83 static char *noopfile = "noop3d.bitmap";
84
85 #define BACKCOLOR gControlBackgroundColor
86 #define BUTTGC fControlGC
87
88 #endif
89
90
91 int twwidth, twheight; /* the width and height for all windows in the */
92 /* title bar */
93
94 void
makeTitleBarWindows(void)95 makeTitleBarWindows(void)
96 {
97 XSetWindowAttributes at;
98 unsigned long valuemask = 0L;
99
100 /* read the images if we don't have them already */
101
102 if (tw1image == NULL)
103 readTitleBarImages();
104
105 /* set the window attributes */
106
107 at.cursor = gActiveCursor;
108 valuemask |= CWCursor;
109 at.event_mask = ButtonPress;
110 valuemask |= CWEventMask;
111
112 /* create the windows for the buttons */
113
114 gWindow->fTitleBarButton1 = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
115 1, 1, twwidth, twheight,
116 0, gBorderColor, BACKCOLOR);
117 XChangeWindowAttributes(gXDisplay, gWindow->fTitleBarButton1, valuemask, &at);
118
119 gWindow->fTitleBarButton2 = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
120 1, 1, twwidth, twheight,
121 0, gBorderColor, BACKCOLOR);
122 XChangeWindowAttributes(gXDisplay, gWindow->fTitleBarButton2, valuemask, &at);
123
124 gWindow->fTitleBarButton3 = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
125 1, 1, twwidth, twheight,
126 0, gBorderColor, BACKCOLOR);
127 XChangeWindowAttributes(gXDisplay, gWindow->fTitleBarButton3, valuemask, &at);
128
129 gWindow->fTitleBarButton4 = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
130 1, 1, twwidth, twheight,
131 0, gBorderColor, BACKCOLOR);
132 XChangeWindowAttributes(gXDisplay, gWindow->fTitleBarButton4, valuemask, &at);
133 }
134
135 void
showTitleBar(void)136 showTitleBar(void)
137 {
138 XWindowChanges wc;
139 int height, hbw = (int) gWindow->border_width / 2;
140 XImage *image;
141
142 /*
143 * the first thing we do is pop up all the windows and
144 * place them properly
145 */
146
147 if (gWindow->page->title->height != twheight)
148 height = gWindow->page->title->height;
149 else
150 height = twheight;
151
152 push_active_group();
153
154 /* configure and map button number 1 */
155
156 wc.x = 0;
157 wc.y = 0;
158 wc.height = twheight;
159 wc.width = twwidth;
160 XConfigureWindow(gXDisplay, gWindow->fTitleBarButton1, CWX | CWY | CWHeight | CWWidth, &wc);
161 XMapWindow(gXDisplay, gWindow->fTitleBarButton1);
162
163 image = tw1image;
164 XPutImage(gXDisplay, gWindow->fTitleBarButton1, gWindow->BUTTGC,
165 image, 0, 0, 0, 0,
166 image->width,
167 image->height);
168
169 /* configure and map button number 2 */
170
171 wc.x += twwidth + gWindow->border_width;
172 XConfigureWindow(gXDisplay, gWindow->fTitleBarButton2, CWX | CWY | CWHeight | CWWidth, &wc);
173 XMapWindow(gXDisplay, gWindow->fTitleBarButton2);
174
175 image = need_help_button ? tw2image : noopimage;
176 XPutImage(gXDisplay, gWindow->fTitleBarButton2, gWindow->BUTTGC,
177 image, 0, 0, 0, 0,
178 image->width,
179 image->height);
180
181 /* configure and map button number 4 */
182
183 wc.x = gWindow->width - twwidth;
184 XConfigureWindow(gXDisplay, gWindow->fTitleBarButton4, CWX | CWY | CWHeight | CWWidth, &wc);
185 XMapWindow(gXDisplay, gWindow->fTitleBarButton4);
186
187 image = need_up_button ? tw4image : noopimage;
188 XPutImage(gXDisplay, gWindow->fTitleBarButton4, gWindow->BUTTGC,
189 image, 0, 0, 0, 0,
190 image->width,
191 image->height);
192
193 /* configure and map button number 3 */
194
195 wc.x = wc.x - twwidth - gWindow->border_width;
196 XConfigureWindow(gXDisplay, gWindow->fTitleBarButton3, CWX | CWY | CWHeight | CWWidth, &wc);
197 XMapWindow(gXDisplay, gWindow->fTitleBarButton3);
198
199 image = need_return_button ? tw3image : noopimage;
200 XPutImage(gXDisplay, gWindow->fTitleBarButton3, gWindow->BUTTGC,
201 image, 0, 0, 0, 0,
202 image->width,
203 image->height);
204
205 gWindow->fDisplayedWindow = gWindow->fMainWindow;
206 gDisplayRegion = Title;
207 gRegionOffset = 0;
208 y_off = 0;
209
210 pop_group_stack();
211
212 show_text(gWindow->page->title->next, Endheader);
213
214 /* Now draw the box around the title */
215
216 line_top_group();
217
218 #if BITMAPS2D
219 XDrawRectangle(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC, gWindow->page->title->x,
220 -hbw,
221 wc.x - gWindow->page->title->x - hbw,
222 height + 2 * hbw);
223 #endif
224
225 XDrawLine(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC, 0, height + hbw,
226 gWindow->width, height + hbw);
227
228 #if BITMAPS2D
229 /* Now draw the lines down the middle */
230
231 XDrawLine(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC,
232 twwidth + hbw, 0,
233 twwidth + hbw, height);
234 XDrawLine(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC,
235 gWindow->width - twwidth - hbw, 0,
236 gWindow->width - twwidth - hbw, height);
237 #endif
238
239 pop_group_stack();
240
241 #if BITMAPS2D
242 /* now fill the areas under the bitmaps if we have to */
243
244 if (gWindow->page->title->height > twheight) {
245 push_active_group();
246 height = height - twheight;
247
248 XFillRectangle(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC, 0,
249 twheight, twwidth, height);
250 XFillRectangle(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC,
251 twwidth + gWindow->border_width,
252 twheight, twwidth, height);
253 XFillRectangle(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC,
254 gWindow->width - 2 * twwidth - gWindow->border_width,
255 twheight, twwidth, height);
256 XFillRectangle(gXDisplay, gWindow->fMainWindow, gWindow->fStandardGC,
257 gWindow->width - twwidth,
258 twheight, twwidth, height);
259 pop_group_stack();
260 }
261 #endif
262 }
263
264 void
linkTitleBarWindows(void)265 linkTitleBarWindows(void)
266 {
267 HyperLink *tw1link = (HyperLink *) halloc(sizeof(HyperLink), "HyperLink"),
268 *tw2link = (HyperLink *) halloc(sizeof(HyperLink), "HyperLink"),
269 *tw3link = (HyperLink *) halloc(sizeof(HyperLink), "HyperLink"),
270 *tw4link = (HyperLink *) halloc(sizeof(HyperLink), "HyperLink");
271
272 tw1link->win = gWindow->fTitleBarButton1;
273 tw1link->type = Quitbutton;
274 tw1link->reference.node = NULL;
275 tw1link->x = tw1link->y = 0;
276
277 tw2link->win = gWindow->fTitleBarButton2;
278 tw2link->type = Helpbutton;
279 tw2link->reference.node = NULL;
280 tw2link->x = tw2link->y = 0;
281
282 tw3link->win = gWindow->fTitleBarButton3;
283 tw3link->type = Returnbutton;
284 tw3link->reference.node = NULL;
285 tw3link->x = tw3link->y = 0;
286
287 tw4link->win = gWindow->fTitleBarButton4;
288 tw4link->type = Upbutton;
289 tw4link->reference.node = NULL;
290 tw4link->x = tw4link->y = 0;
291
292 hash_insert(gLinkHashTable, (char *)tw1link,(char *) &tw1link->win);
293 hash_insert(gLinkHashTable, (char *)tw2link,(char *) &tw2link->win);
294 hash_insert(gLinkHashTable, (char *)tw3link,(char *) &tw3link->win);
295 hash_insert(gLinkHashTable, (char *)tw4link,(char *) &tw4link->win);
296 }
297
298 static void
readTitleBarImages(void)299 readTitleBarImages(void)
300 {
301 int w, h;
302 char filename[2048];
303 char *fricas_env_var = NULL;
304
305 fricas_env_var = getenv("FRICAS");
306
307 if (fricas_env_var)
308 sprintf(filename, "%s/share/hypertex/bitmaps/%s",
309 fricas_env_var, tw1file);
310 else
311 sprintf(filename, "%s", tw1file);
312 tw1image = HTReadBitmapFile(gXDisplay, gXScreenNumber, filename,
313 &twwidth, &twheight);
314
315 if (fricas_env_var)
316 sprintf(filename, "%s/share/hypertex/bitmaps/%s",
317 fricas_env_var, tw2file);
318 else
319 sprintf(filename, "%s", tw2file);
320 tw2image = HTReadBitmapFile(gXDisplay, gXScreenNumber, filename,
321 &w, &h);
322 twwidth = ((twwidth >= w) ? (twwidth) : (w));
323
324 if (fricas_env_var)
325 sprintf(filename, "%s/share/hypertex/bitmaps/%s",
326 fricas_env_var, tw3file);
327 else
328 sprintf(filename, "%s", tw3file);
329 tw3image = HTReadBitmapFile(gXDisplay, gXScreenNumber, filename,
330 &w, &h);
331 twwidth = ((twwidth >= w) ? (twwidth) : (w));
332
333 if (fricas_env_var)
334 sprintf(filename, "%s/share/hypertex/bitmaps/%s",
335 fricas_env_var, tw4file);
336 else
337 sprintf(filename, "%s", tw4file);
338 tw4image = HTReadBitmapFile(gXDisplay, gXScreenNumber, filename,
339 &w, &h);
340 twwidth = ((twwidth >= w) ? (twwidth) : (w));
341
342
343 if (fricas_env_var)
344 sprintf(filename, "%s/share/hypertex/bitmaps/%s",
345 fricas_env_var, noopfile);
346 else
347 sprintf(filename, "%s", noopfile);
348 noopimage = HTReadBitmapFile(gXDisplay, gXScreenNumber, filename,
349 &twwidth, &twheight);
350 }
351
352 void
getTitleBarMinimumSize(int * width,int * height)353 getTitleBarMinimumSize(int *width, int *height)
354 {
355 (*width) = 4 * twwidth + 40;
356 (*height) = twheight + 2;
357 }
358