Commit | Line | Data |
---|---|---|
e745ede7 DL |
1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | ||
3 | #include "copyright.h" | |
4 | ||
f10de189 | 5 | /* |
73b0cd50 | 6 | Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc. |
f10de189 | 7 | |
4eaa4034 | 8 | This program is free software: you can redistribute it and/or modify |
f10de189 | 9 | it under the terms of the GNU General Public License as published by |
4eaa4034 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
f10de189 GM |
12 | |
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
4eaa4034 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
f10de189 GM |
20 | |
21 | ||
e745ede7 DL |
22 | /* |
23 | * XMenu: MIT Project Athena, X Window system menu package | |
24 | * | |
25 | * XMenuCreate - Creates an X window system menu object. | |
26 | * | |
27 | * Author: Tony Della Fera, DEC | |
28 | * January 23, 1986 | |
29 | * | |
30 | */ | |
31 | ||
32 | #include <config.h> | |
33 | #include "XMenuInt.h" | |
34 | ||
35 | ||
36 | #ifdef EMACS_BITMAP_FILES | |
37 | #include "../src/bitmaps/dimple1.xbm" | |
38 | #include "../src/bitmaps/dimple3.xbm" | |
39 | #include "../src/bitmaps/gray1.xbm" | |
40 | #include "../src/bitmaps/gray3.xbm" | |
41 | #include "../src/bitmaps/crosswv.xbm" | |
42 | ||
43 | #include "../src/bitmaps/leftptr.xbm" | |
44 | #include "../src/bitmaps/leftpmsk.xbm" | |
45 | #include "../src/bitmaps/rtptr.xbm" | |
46 | #include "../src/bitmaps/rtpmsk.xbm" | |
47 | #include "../src/bitmaps/cntrptr.xbm" | |
48 | #include "../src/bitmaps/cntrpmsk.xbm" | |
49 | #include "../src/bitmaps/stipple.xbm" | |
50 | ||
51 | #else | |
e745ede7 DL |
52 | |
53 | #include <X11/bitmaps/dimple1> | |
54 | #include <X11/bitmaps/dimple3> | |
55 | #include <X11/bitmaps/gray1> | |
56 | #include <X11/bitmaps/gray3> | |
57 | #include <X11/bitmaps/cross_weave> | |
58 | ||
59 | #include <X11/bitmaps/left_ptr> | |
60 | #include <X11/bitmaps/left_ptrmsk> | |
61 | #include <X11/bitmaps/right_ptr> | |
62 | #include <X11/bitmaps/right_ptrmsk> | |
63 | #include <X11/bitmaps/cntr_ptr> | |
64 | #include <X11/bitmaps/cntr_ptrmsk> | |
65 | #include <X11/bitmaps/stipple> | |
66 | ||
e745ede7 DL |
67 | #endif /* not EMACS_BITMAP_FILES */ |
68 | ||
69 | #define DEF_FREEZE 0 | |
70 | #define DEF_REVERSE 0 | |
71 | #define DEF_MENU_STYLE LEFT | |
72 | #define DEF_MENU_MODE BOX | |
73 | #define DEF_INACT_PNUM 3 | |
74 | #define MAX_INACT_PNUM 4 | |
75 | ||
76 | #define DEF_P_STYLE CENTER | |
77 | ||
78 | #define DEF_P_EVENTS (EnterWindowMask | ExposureMask) | |
79 | #define DEF_P_FNT_NAME "fixed" | |
80 | #define DEF_P_SPREAD 0.5 | |
81 | #define DEF_P_BDR_WIDTH 2 | |
82 | ||
83 | #define DEF_S_STYLE LEFT | |
84 | #define DEF_S_EVENTS (EnterWindowMask | LeaveWindowMask) | |
85 | #define DEF_S_FNT_NAME "fixed" | |
86 | #define DEF_S_SPREAD 0.10 | |
87 | #define DEF_S_BDR_WIDTH 1 | |
88 | ||
89 | #define XASSOC_TABLE_SIZE 64 | |
90 | ||
91 | #define TILE_BUF_SIZE 5 | |
92 | ||
b782e2d7 DN |
93 | int atoi(const char *); |
94 | double atof(const char *); | |
95 | char *x_get_resource_string (char *attribute, char *class); | |
e745ede7 DL |
96 | |
97 | ||
98 | ||
177c0ea7 | 99 | static Status |
b782e2d7 | 100 | XAllocDisplayColor(Display *display, Colormap map, char *colorName, XColor *color, XColor *junk) |
e745ede7 DL |
101 | { |
102 | return (colorName!=0 && | |
103 | XParseColor(display, map, colorName, color) && | |
104 | XAllocColor(display, map, color)); | |
105 | } | |
106 | ||
107 | ||
108 | XMenu * | |
b782e2d7 DN |
109 | XMenuCreate(Display *display, Window parent, register char *def_env) |
110 | /* ID of previously opened display */ | |
111 | /* Window ID of the menu's parent window. */ | |
112 | /* X Defaults program environment name. */ | |
e745ede7 DL |
113 | { |
114 | register int i; /* Loop counter. */ | |
115 | register int j; /* Loop counter. */ | |
116 | register char *def_val; /* X Default value temp variable. */ | |
117 | ||
118 | register XMenu *menu; /* Pointer to the new menu. */ | |
119 | XMStyle menu_style; /* Menu display style. */ | |
120 | XMMode menu_mode; /* Menu display mode. */ | |
121 | XMPane *pane; /* Pane list header. */ | |
122 | XAssocTable *assoc_tab; /* XAssocTable pointer. */ | |
123 | ||
124 | int freeze; /* Freeze server mode. */ | |
125 | int reverse; /* Reverse video mode. */ | |
126 | ||
127 | XMStyle p_style; /* Pane display style. */ | |
128 | char *p_fnt_name; /* Flag font name. */ | |
129 | XFontStruct *p_fnt_info; /* Flag font structure */ | |
130 | int p_fnt_pad; /* Flag font padding in pixels. */ | |
131 | double p_spread; /* Pane spread in flag height fractions. */ | |
132 | int p_fnt_height; /* Pane character height. */ | |
133 | int p_bdr_width; /* Pane border width. */ | |
134 | int flag_height; /* Flag window height. */ | |
135 | int p_height; /* Pane window height. */ | |
136 | int p_x_off; /* Pane X offset. */ | |
137 | int p_y_off; /* Pane Y offset. */ | |
138 | GC pane_GC; /* Pane graphics context. */ | |
139 | ||
140 | XMStyle s_style; /* Selection display style. */ | |
141 | char *s_fnt_name; /* Selection font name. */ | |
142 | XFontStruct *s_fnt_info; /* Selection font structure. */ | |
143 | int s_fnt_pad; /* Selection font padding in pixels. */ | |
144 | int s_fnt_height; /* Selection font character height */ | |
145 | double s_spread; /* Select spread in line height fractions. */ | |
146 | int s_bdr_width; /* Highlight border width. */ | |
147 | int s_height; /* Selection window height. */ | |
148 | int s_x_off; /* Selection window X offset. */ | |
149 | int s_y_off; /* Selection window Y offset. */ | |
150 | GC normal_select_GC; /* GC used for normal video selection. */ | |
151 | GC inverse_select_GC; /* GC used for inverse video selection. */ | |
152 | GC inact_GC; /* GC for inactive pane header and */ | |
153 | /* selections. */ | |
154 | GC inact_GC_noexpose; | |
155 | ||
156 | XColor color_def; /* Temp color definition holder. */ | |
157 | XColor screen_def; /* Temp screen color definition holder */ | |
158 | XColor p_bdr_color; /* Color of border. */ | |
159 | XColor s_bdr_color; /* Color of highlight. */ | |
160 | XColor p_frg_color; /* Color of pane foreground color. */ | |
161 | XColor s_frg_color; /* Color of selection foreground. */ | |
162 | XColor bkgnd_color; /* Color of background.. */ | |
163 | XColor mouse_color; /* Color of mouse cursor. */ | |
164 | Cursor mouse_cursor; /* Mouse cursor. */ | |
165 | Pixmap inact_bitmap; /* Menu inactive pixmap. */ | |
166 | ||
167 | int inact_pnum; /* Inactive background pattern number. */ | |
168 | ||
169 | Pixel p_bdr_pixel; /* Pane border pixel. */ | |
170 | Pixel s_bdr_pixel; /* Selection border pixel. */ | |
171 | Pixel p_frg_pixel; /* Pane foreground pixel. */ | |
172 | Pixel s_frg_pixel; /* Selection foreground pixel. */ | |
173 | Pixel bkgnd_pixel; /* Menu background pixel. */ | |
174 | ||
175 | int *width, *height; | |
176 | Pixmap *bitmap; | |
177 | int *x_hot, *y_hot; | |
178 | int status; /* Return code from XReadBitmapFile. */ | |
179 | ||
180 | Pixmap cursor; /* Cursor pixmap holder. */ | |
181 | Pixmap cursor_mask; /* Cursor mask pixmap holder. */ | |
182 | Pixmap stipple_pixmap; /* Stipple mask for half-tone text. */ | |
183 | unsigned long valuemask; | |
184 | XGCValues *values; | |
177c0ea7 | 185 | |
e745ede7 DL |
186 | Window root = RootWindow (display, DefaultScreen (display)); |
187 | ||
188 | /* | |
189 | * Calloc the XMenu structure and the initial pane. | |
190 | */ | |
191 | menu = (XMenu *)calloc(1, sizeof(XMenu)); | |
192 | if (menu == NULL) { | |
193 | _XMErrorCode = XME_CALLOC; | |
194 | return(NULL); | |
195 | } | |
196 | pane = (XMPane *)calloc(1, sizeof(XMPane)); | |
197 | if (pane == NULL) { | |
198 | _XMErrorCode = XME_CALLOC; | |
199 | return(NULL); | |
200 | } | |
177c0ea7 JB |
201 | |
202 | /* | |
e745ede7 DL |
203 | * Create the XAssocTable |
204 | */ | |
205 | assoc_tab = (XAssocTable *)XCreateAssocTable(XASSOC_TABLE_SIZE); | |
206 | if(assoc_tab == NULL) { | |
207 | _XMErrorCode= XME_CREATE_ASSOC; | |
208 | return(NULL); | |
209 | } | |
210 | ||
211 | /* | |
212 | * Set up the default environment name. | |
213 | */ | |
214 | if (def_env == NULL || *def_env == '\0') def_env = "XMenu"; | |
215 | ||
216 | /* | |
217 | * Set up internal fail-safe defaults. | |
218 | */ | |
219 | freeze = DEF_FREEZE; | |
220 | reverse = DEF_REVERSE; | |
221 | menu_style = DEF_MENU_STYLE; | |
222 | menu_mode = DEF_MENU_MODE; | |
223 | inact_pnum = DEF_INACT_PNUM; | |
224 | ||
225 | p_style = DEF_P_STYLE; | |
226 | p_spread = DEF_P_SPREAD; | |
227 | p_fnt_name = DEF_P_FNT_NAME; | |
228 | p_bdr_width = DEF_P_BDR_WIDTH; | |
229 | ||
230 | s_style = DEF_S_STYLE; | |
231 | s_spread = DEF_S_SPREAD; | |
232 | s_fnt_name = DEF_S_FNT_NAME; | |
233 | s_bdr_width = DEF_S_BDR_WIDTH; | |
234 | ||
235 | /* | |
236 | * Get default values from X. | |
237 | */ | |
238 | def_val = x_get_resource_string ("menuFreeze", "MenuFreeze"); | |
239 | if (def_val != NULL) { | |
240 | if (strcmp(def_val, "on") == 0) freeze = 1; | |
241 | else if (strcmp(def_val, "off") == 0) freeze = 0; | |
242 | } | |
243 | ||
244 | def_val = x_get_resource_string ("menuReverseVideo", "MenuReverseVideo"); | |
245 | if (def_val != NULL) { | |
246 | if (strcmp(def_val, "on") == 0) reverse = 1; | |
247 | else if (strcmp(def_val, "off") == 0) reverse = 0; | |
248 | } | |
249 | ||
250 | def_val = x_get_resource_string ("menuStyle", "MenuStyle"); | |
251 | if (def_val != NULL) { | |
252 | if (strcmp(def_val, "right_hand") == 0) menu_style = RIGHT; | |
253 | else if (strcmp(def_val, "left_hand") == 0) menu_style = LEFT; | |
254 | else if (strcmp(def_val, "center") == 0) menu_style = CENTER; | |
255 | } | |
256 | ||
257 | def_val = x_get_resource_string ("menuMode", "MenuMode"); | |
258 | if (def_val != NULL) { | |
259 | if (strcmp(def_val, "box") == 0) menu_mode = BOX; | |
260 | else if (strcmp(def_val, "invert") == 0) menu_mode = INVERT; | |
261 | } | |
177c0ea7 | 262 | |
e745ede7 DL |
263 | def_val = x_get_resource_string ("menuMouse", "MenuMouse"); |
264 | if ( | |
265 | def_val != NULL && | |
266 | DisplayCells(display, DefaultScreen(display)) > 2 && | |
177c0ea7 JB |
267 | XAllocDisplayColor(display, |
268 | DefaultColormap(display, DefaultScreen(display)), | |
269 | def_val, | |
e745ede7 DL |
270 | &mouse_color, &color_def) |
271 | ); | |
272 | else if (reverse && | |
273 | XAllocDisplayColor(display, | |
274 | DefaultColormap(display, DefaultScreen(display)), | |
275 | "white", | |
276 | &mouse_color, &color_def) | |
277 | ); | |
177c0ea7 | 278 | |
e745ede7 DL |
279 | else if (XAllocDisplayColor(display, |
280 | DefaultColormap(display, DefaultScreen(display)), | |
177c0ea7 | 281 | "black", |
e745ede7 DL |
282 | &mouse_color, &color_def) |
283 | ); | |
177c0ea7 | 284 | |
e745ede7 DL |
285 | else ; |
286 | ||
287 | def_val = x_get_resource_string ("menuBackground", "MenuBackground"); | |
288 | if ( | |
289 | def_val != NULL && | |
290 | DisplayCells(display, DefaultScreen(display)) > 2 && | |
291 | XAllocDisplayColor(display, | |
292 | DefaultColormap(display, DefaultScreen(display)), | |
293 | def_val, | |
294 | &bkgnd_color, &color_def) | |
295 | ); | |
296 | else if (reverse && | |
297 | XAllocDisplayColor(display, | |
298 | DefaultColormap(display, DefaultScreen(display)), | |
299 | "black", | |
300 | &bkgnd_color, &color_def) | |
301 | ); | |
302 | else if (XAllocDisplayColor(display, | |
303 | DefaultColormap(display, DefaultScreen(display)), | |
304 | "white", | |
305 | &bkgnd_color, &color_def) | |
306 | ); | |
307 | else; | |
308 | ||
309 | def_val = x_get_resource_string ("menuInactivePattern", "MenuInactivePattern"); | |
310 | if (def_val != NULL) { | |
311 | if (strcmp(def_val, "dimple1") == 0) inact_pnum = 0; | |
312 | else if (strcmp(def_val, "dimple3") == 0) inact_pnum = 1; | |
313 | else if (strcmp(def_val, "gray1") == 0) inact_pnum = 2; | |
314 | else if (strcmp(def_val, "gray3") == 0) inact_pnum = 3; | |
315 | else if (strcmp(def_val, "cross_weave") == 0) inact_pnum = 4; | |
316 | } | |
317 | ||
318 | def_val = x_get_resource_string ("paneStyle", "PaneStyle"); | |
319 | if (def_val != NULL) { | |
320 | if (strcmp(def_val, "flush_left") == 0) p_style = LEFT; | |
321 | else if (strcmp(def_val, "flush_right") == 0) p_style = RIGHT; | |
322 | else if (strcmp(def_val, "center") == 0) p_style = CENTER; | |
323 | } | |
324 | ||
325 | def_val = x_get_resource_string ("paneFont", "PaneFont"); | |
326 | if (def_val != NULL) p_fnt_name = def_val; | |
327 | ||
328 | def_val = x_get_resource_string ("paneForeground", "PaneForeground"); | |
329 | if ( | |
330 | def_val != NULL && | |
177c0ea7 | 331 | DisplayCells(display, DefaultScreen(display)) > 2 |
e745ede7 DL |
332 | ) |
333 | XAllocDisplayColor(display, DefaultColormap(display, | |
334 | DefaultScreen(display)), | |
335 | def_val, | |
336 | &p_frg_color, &color_def); | |
177c0ea7 | 337 | |
e745ede7 | 338 | else if (reverse) XAllocDisplayColor(display, |
177c0ea7 | 339 | DefaultColormap(display, |
e745ede7 DL |
340 | DefaultScreen(display)), |
341 | "white", | |
342 | &p_frg_color, &color_def); | |
343 | else XAllocDisplayColor(display, | |
344 | DefaultColormap(display, DefaultScreen(display)), | |
345 | "black", | |
346 | &p_frg_color, &color_def); | |
347 | ||
348 | def_val = x_get_resource_string ("paneBorder", "PaneBorder"); | |
349 | if ( | |
350 | def_val != NULL && | |
351 | DisplayCells(display, DefaultScreen(display)) > 2 && | |
352 | XAllocDisplayColor(display, | |
353 | DefaultColormap(display, DefaultScreen(display)), | |
354 | def_val, | |
355 | &p_bdr_color, &color_def) | |
356 | ); | |
357 | else if (reverse && | |
177c0ea7 | 358 | XAllocDisplayColor(display, |
e745ede7 DL |
359 | DefaultColormap(display, DefaultScreen(display)), |
360 | "white", | |
361 | &p_bdr_color, &color_def) | |
362 | ); | |
177c0ea7 | 363 | else XAllocDisplayColor(display, |
e745ede7 DL |
364 | DefaultColormap(display, DefaultScreen(display)), |
365 | "black", | |
366 | &p_bdr_color, &color_def); | |
177c0ea7 | 367 | |
e745ede7 DL |
368 | def_val = x_get_resource_string ("paneBorderWidth", "PaneBorderWidth"); |
369 | if (def_val != NULL) p_bdr_width = atoi(def_val); | |
177c0ea7 | 370 | |
e745ede7 DL |
371 | def_val = x_get_resource_string ("paneSpread", "PaneSpread"); |
372 | if (def_val != NULL) p_spread = atof(def_val); | |
373 | ||
374 | def_val = x_get_resource_string ("selectionStyle", "SelectionStyle"); | |
375 | if (def_val != NULL) { | |
376 | if (strcmp(def_val, "flush_left") == 0) s_style = LEFT; | |
377 | else if (strcmp(def_val, "flush_right") == 0) s_style = RIGHT; | |
378 | else if (strcmp(def_val, "center") == 0) s_style = CENTER; | |
379 | } | |
380 | ||
381 | def_val = x_get_resource_string ("selectionFont", "SelectionFont"); | |
382 | if (def_val != NULL) s_fnt_name = def_val; | |
383 | ||
384 | def_val = x_get_resource_string ("selectionForeground", "SelectionForeground"); | |
385 | if ( | |
386 | def_val != NULL && | |
387 | DisplayCells(display, DefaultScreen(display)) > 2 && | |
388 | XAllocDisplayColor(display, | |
389 | DefaultColormap(display, DefaultScreen(display)), | |
390 | def_val, | |
391 | &s_frg_color, &color_def) | |
177c0ea7 | 392 | ); |
e745ede7 DL |
393 | else if (reverse && |
394 | XAllocDisplayColor(display, | |
395 | DefaultColormap(display, DefaultScreen(display)), | |
396 | "white", | |
397 | &s_frg_color, &color_def) | |
398 | ) ; | |
399 | else if (XAllocDisplayColor(display, | |
400 | DefaultColormap(display, DefaultScreen(display)), | |
401 | "black", | |
402 | &s_frg_color, &color_def) | |
403 | ) ; | |
404 | else ; | |
177c0ea7 | 405 | |
e745ede7 DL |
406 | |
407 | def_val = x_get_resource_string ("selectionBorder", "SelectionBorder"); | |
408 | if ( | |
409 | def_val != NULL && | |
410 | DisplayCells(display, DefaultScreen(display)) > 2 && | |
411 | XAllocDisplayColor(display, | |
412 | DefaultColormap(display, DefaultScreen(display)), | |
413 | def_val, | |
414 | &s_bdr_color, &color_def) | |
415 | ) ; | |
416 | else if (reverse && | |
177c0ea7 | 417 | XAllocDisplayColor(display, |
e745ede7 DL |
418 | DefaultColormap(display, DefaultScreen(display)), |
419 | "white", | |
420 | &s_bdr_color, &color_def) | |
421 | ) ; | |
422 | else if (XAllocDisplayColor(display, | |
423 | DefaultColormap(display, DefaultScreen(display)), | |
424 | "black", | |
425 | &s_bdr_color, &color_def) | |
426 | ) ; | |
427 | else ; | |
428 | ||
429 | def_val = x_get_resource_string ("selectionBorderWidth", "SelectionBorderWidth"); | |
430 | if (def_val != NULL) s_bdr_width = atoi(def_val); | |
177c0ea7 | 431 | |
e745ede7 DL |
432 | def_val = x_get_resource_string ("selectionSpread", "SelectionSpread"); |
433 | if (def_val != NULL) s_spread = atof(def_val); | |
434 | ||
435 | /* | |
436 | * Create and store the inactive pattern pixmap. | |
437 | */ | |
438 | { | |
439 | char *data = NULL; | |
440 | int width, height; | |
441 | ||
177c0ea7 | 442 | switch (inact_pnum) |
e745ede7 DL |
443 | { |
444 | case 0: | |
445 | data = (char *)dimple1_bits; | |
446 | width = dimple1_width; | |
447 | height = dimple1_height; | |
448 | break; | |
449 | ||
450 | case 1: | |
451 | data = (char *)dimple3_bits; | |
452 | width = dimple3_width; | |
453 | height = dimple3_height; | |
454 | break; | |
455 | ||
456 | case 2: | |
457 | data = (char *)gray1_bits; | |
458 | width = gray1_width; | |
459 | height = gray1_height; | |
460 | break; | |
461 | ||
462 | case 3: | |
463 | data = (char *)gray3_bits; | |
464 | width = gray3_width; | |
465 | height = gray3_height; | |
466 | break; | |
467 | ||
468 | case 4: | |
469 | data = (char *)cross_weave_bits; | |
470 | width = cross_weave_width; | |
471 | height = cross_weave_height; | |
472 | break; | |
473 | } | |
474 | ||
475 | if (! data) | |
476 | { | |
477 | _XMErrorCode = XME_STORE_BITMAP; | |
478 | return(NULL); | |
479 | } | |
480 | ||
481 | inact_bitmap = | |
482 | XCreatePixmapFromBitmapData | |
483 | (display, root, data, width, height, | |
484 | p_frg_color.pixel, bkgnd_color.pixel, | |
485 | DisplayPlanes (display, DefaultScreen (display))); | |
486 | } | |
487 | ||
488 | /* | |
489 | * Load the mouse cursor. | |
490 | */ | |
177c0ea7 | 491 | |
e745ede7 DL |
492 | switch (menu_style) { |
493 | case LEFT: | |
494 | cursor = XCreateBitmapFromData(display, | |
495 | root, | |
496 | left_ptr_bits, | |
497 | left_ptr_width, | |
498 | left_ptr_height); | |
499 | cursor_mask = XCreateBitmapFromData(display, | |
500 | root, | |
501 | left_ptrmsk_bits, | |
502 | left_ptrmsk_width, | |
503 | left_ptrmsk_height); | |
504 | mouse_cursor = XCreatePixmapCursor( | |
505 | display, | |
177c0ea7 | 506 | cursor, cursor_mask, |
e745ede7 DL |
507 | &mouse_color, &bkgnd_color, |
508 | left_ptr_x_hot, | |
509 | left_ptr_y_hot | |
510 | ); | |
511 | XFreePixmap(display, cursor); | |
177c0ea7 | 512 | XFreePixmap(display, cursor_mask); |
e745ede7 DL |
513 | break; |
514 | case RIGHT: | |
515 | cursor = XCreateBitmapFromData(display, | |
516 | root, | |
517 | right_ptr_bits, | |
518 | right_ptr_width, | |
519 | right_ptr_height); | |
520 | cursor_mask = XCreateBitmapFromData(display, | |
521 | root, | |
522 | right_ptrmsk_bits, | |
523 | right_ptrmsk_width, | |
524 | right_ptrmsk_height); | |
525 | mouse_cursor = XCreatePixmapCursor( | |
526 | display, | |
527 | cursor, cursor_mask, | |
528 | &mouse_color, &bkgnd_color, | |
529 | right_ptr_x_hot, | |
530 | right_ptr_y_hot | |
531 | ); | |
532 | XFreePixmap(display, cursor); | |
177c0ea7 | 533 | XFreePixmap(display, cursor_mask); |
e745ede7 DL |
534 | break; |
535 | case CENTER: | |
536 | cursor = XCreateBitmapFromData(display, | |
537 | root, | |
538 | cntr_ptr_bits, | |
539 | cntr_ptr_width, | |
540 | cntr_ptr_height); | |
541 | cursor_mask = XCreateBitmapFromData(display, | |
542 | root, | |
543 | cntr_ptrmsk_bits, | |
544 | cntr_ptrmsk_width, | |
545 | cntr_ptrmsk_height); | |
546 | mouse_cursor = XCreatePixmapCursor( | |
547 | display, | |
548 | cursor, cursor_mask, | |
549 | &mouse_color, &bkgnd_color, | |
550 | cntr_ptr_x_hot, | |
551 | cntr_ptr_y_hot | |
552 | ); | |
553 | XFreePixmap(display, cursor); | |
177c0ea7 | 554 | XFreePixmap(display, cursor_mask); |
e745ede7 DL |
555 | break; |
556 | default: | |
557 | /* Error! Invalid style parameter. */ | |
558 | _XMErrorCode = XME_STYLE_PARAM; | |
559 | return(NULL); | |
560 | } | |
561 | if (mouse_cursor == _X_FAILURE) { | |
562 | _XMErrorCode = XME_CREATE_CURSOR; | |
563 | return(NULL); | |
564 | } | |
565 | ||
566 | /* | |
567 | * Open the pane and selection fonts. | |
568 | */ | |
177c0ea7 | 569 | |
e745ede7 DL |
570 | p_fnt_info = XLoadQueryFont(display, p_fnt_name); |
571 | if (p_fnt_info == NULL) { | |
572 | _XMErrorCode = XME_OPEN_FONT; | |
573 | return(NULL); | |
177c0ea7 | 574 | |
e745ede7 DL |
575 | } |
576 | ||
577 | s_fnt_info = XLoadQueryFont(display, s_fnt_name); | |
578 | if (s_fnt_info == NULL) { | |
579 | _XMErrorCode = XME_OPEN_FONT; | |
580 | return(NULL); | |
581 | } | |
582 | /* | |
583 | * Calculate the fixed padding value in pixels for each font. | |
584 | */ | |
585 | p_fnt_height = p_fnt_info->max_bounds.ascent + p_fnt_info->max_bounds.descent; | |
586 | s_fnt_height = s_fnt_info->max_bounds.ascent + s_fnt_info->max_bounds.descent; | |
587 | p_fnt_pad = s_spread * p_fnt_height; | |
588 | s_fnt_pad = s_spread * s_fnt_height; | |
589 | ||
590 | /* | |
591 | * Calculate fixed height and offset requirements. | |
592 | */ | |
593 | flag_height = p_fnt_height + (p_fnt_pad << 1); | |
594 | ||
595 | p_height = 0; | |
596 | p_y_off = flag_height + p_bdr_width; | |
597 | p_x_off = p_y_off * p_spread; | |
598 | ||
599 | s_height = s_fnt_height + (s_fnt_pad << 1) + (s_bdr_width << 1); | |
600 | s_y_off = s_height; | |
601 | s_x_off = p_x_off; | |
602 | ||
603 | /* | |
604 | * Set up the pane list header. | |
605 | */ | |
606 | pane->next = pane; | |
607 | pane->prev = pane; | |
608 | pane->type = PL_HEADER; | |
609 | pane->serial = -1; | |
610 | ||
611 | /* | |
612 | * Initialize the internal pane and selection creation queues. | |
613 | */ | |
614 | _XMWinQueInit(); | |
177c0ea7 | 615 | |
e745ede7 DL |
616 | /* |
617 | * Create pane, active, and inactive GC's. | |
618 | */ | |
619 | values = (XGCValues *)malloc(sizeof(XGCValues)); | |
620 | valuemask = (GCForeground | GCBackground | GCFont | GCLineWidth); | |
621 | ||
622 | /* | |
623 | * First, pane. | |
624 | */ | |
625 | ||
626 | values->foreground = p_frg_color.pixel; | |
627 | values->background = bkgnd_color.pixel; | |
628 | values->font = p_fnt_info->fid; | |
629 | values->line_width = p_bdr_width; | |
177c0ea7 | 630 | |
e745ede7 | 631 | pane_GC = XCreateGC( |
177c0ea7 | 632 | display, |
e745ede7 DL |
633 | root, |
634 | valuemask, | |
635 | values); | |
636 | /* | |
637 | * Then normal video selection. | |
638 | */ | |
639 | ||
640 | values->foreground = s_frg_color.pixel; | |
641 | values->background = bkgnd_color.pixel; | |
642 | values->font = s_fnt_info->fid; | |
643 | values->line_width = s_bdr_width; | |
177c0ea7 | 644 | normal_select_GC = XCreateGC(display, |
e745ede7 DL |
645 | root, |
646 | valuemask, | |
647 | values); | |
648 | /* | |
649 | * Inverse video selection. | |
650 | */ | |
651 | ||
177c0ea7 | 652 | values->foreground = bkgnd_color.pixel; |
e745ede7 DL |
653 | values->background = s_frg_color.pixel; |
654 | values->font = s_fnt_info->fid; | |
655 | values->line_width = s_bdr_width; | |
177c0ea7 | 656 | inverse_select_GC = XCreateGC(display, |
e745ede7 DL |
657 | root, |
658 | valuemask, | |
659 | values); | |
660 | stipple_pixmap = XCreateBitmapFromData(display, | |
661 | root, | |
177c0ea7 JB |
662 | stipple_bits, |
663 | stipple_width, | |
664 | stipple_height); | |
665 | ||
e745ede7 DL |
666 | /* |
667 | * Finally, inactive pane header and selections | |
668 | */ | |
669 | valuemask |= (GCFillStyle | GCStipple); | |
670 | values->foreground = s_frg_color.pixel; | |
671 | values->background = bkgnd_color.pixel; | |
672 | values->font = s_fnt_info->fid; | |
673 | values->line_width = s_bdr_width; | |
674 | values->fill_style = FillStippled; | |
675 | values->stipple = stipple_pixmap; | |
177c0ea7 JB |
676 | |
677 | inact_GC = XCreateGC(display, | |
e745ede7 DL |
678 | root, |
679 | valuemask, | |
680 | values); | |
681 | ||
682 | valuemask |= (GCGraphicsExposures); | |
683 | values->graphics_exposures = False; | |
177c0ea7 | 684 | inact_GC_noexpose = XCreateGC (display, |
e745ede7 DL |
685 | root, |
686 | valuemask, values); | |
687 | ||
688 | ||
689 | /* | |
690 | * Construct the XMenu object. | |
691 | */ | |
692 | /* -------------------- Menu data -------------------- */ | |
693 | menu->menu_style = menu_style; | |
694 | menu->menu_mode = menu_mode; | |
695 | menu->freeze = freeze; | |
696 | menu->aeq = 0; | |
697 | menu->recompute = 1; | |
698 | menu->parent = parent; | |
699 | menu->height = 0; | |
700 | menu->width = 0; | |
701 | menu->mouse_cursor = mouse_cursor; | |
702 | menu->assoc_tab = assoc_tab; | |
703 | menu->p_list = pane; | |
704 | /* -------------------- Pane window data -------------------- */ | |
705 | menu->p_style = p_style; | |
706 | menu->p_events = DEF_P_EVENTS; | |
707 | menu->p_fnt_info = p_fnt_info; | |
708 | menu->p_fnt_pad = p_fnt_pad; | |
709 | menu->p_spread = p_spread; | |
710 | menu->p_bdr_width = p_bdr_width; | |
711 | menu->flag_height = flag_height; | |
712 | menu->p_width = 0; | |
713 | menu->p_height = p_height; | |
714 | menu->p_x_off = p_x_off; | |
715 | menu->p_y_off = p_y_off; | |
716 | menu->p_count = 0; | |
717 | menu->pane_GC = pane_GC; | |
718 | menu->x_pos = 0; | |
719 | menu->y_pos = 0; | |
720 | /* -------------------- Selection window data -------------------- */ | |
721 | menu->s_style = s_style; | |
722 | menu->s_events = DEF_S_EVENTS; | |
723 | menu->s_fnt_info = s_fnt_info; | |
724 | menu->s_fnt_pad = s_fnt_pad; | |
725 | menu->s_spread = s_spread; | |
726 | menu->s_bdr_width = s_bdr_width; /* unnecessary */ | |
727 | menu->s_width = 0; | |
728 | menu->s_height = s_height; | |
729 | menu->s_x_off = s_x_off; | |
730 | menu->s_y_off = s_y_off; | |
731 | menu->s_count = 0; | |
732 | menu->normal_select_GC = normal_select_GC; | |
733 | menu->inverse_select_GC = inverse_select_GC; | |
734 | menu->inact_GC = inact_GC; | |
735 | /* -------------------- Color data -------------------- */ | |
736 | menu->p_bdr_color = p_bdr_color.pixel; | |
737 | menu->s_bdr_color = s_bdr_color.pixel; | |
738 | menu->p_frg_color = p_frg_color.pixel; | |
739 | menu->s_frg_color = s_frg_color.pixel; | |
740 | menu->bkgnd_color = bkgnd_color.pixel; | |
741 | /* -------------------- Pixmap data -------------------- */ | |
742 | menu->p_bdr_pixmap = None; | |
743 | menu->s_bdr_pixmap = None; | |
744 | menu->p_frg_pixmap = None; | |
745 | menu->s_frg_pixmap = None; | |
746 | menu->bkgnd_pixmap = None; | |
747 | menu->inact_pixmap = inact_bitmap; | |
748 | ||
749 | /* | |
750 | * Return the completed XMenu. | |
751 | */ | |
752 | _XMErrorCode = XME_NO_ERROR; | |
753 | return(menu); | |
754 | } | |
ab5796a9 | 755 |