root/branches/2.1/oldXMenu/Create.c

Revision 3207, 21.0 kB (checked in by miyoshi, 5 years ago)

Sync up with Emacs-21.2.

  • Property svn:eol-style set to native
Line 
1 /* $Header: /cvsroot/emacs/emacs/oldXMenu/Create.c,v 1.1 1999/10/03 19:34:56 fx Exp $ */
2 /* Copyright    Massachusetts Institute of Technology    1985   */
3
4 #include "copyright.h"
5
6 /*
7  * XMenu:       MIT Project Athena, X Window system menu package
8  *
9  *      XMenuCreate -   Creates an X window system menu object.
10  *
11  *      Author:         Tony Della Fera, DEC
12  *                      January 23, 1986
13  *
14  */
15
16 #include <config.h>
17 #include "XMenuInt.h"
18
19
20 #ifdef EMACS_BITMAP_FILES
21 #include "../src/bitmaps/dimple1.xbm"
22 #include "../src/bitmaps/dimple3.xbm"
23 #include "../src/bitmaps/gray1.xbm"
24 #include "../src/bitmaps/gray3.xbm"
25 #include "../src/bitmaps/crosswv.xbm"
26
27 #include "../src/bitmaps/leftptr.xbm"
28 #include "../src/bitmaps/leftpmsk.xbm"
29 #include "../src/bitmaps/rtptr.xbm"
30 #include "../src/bitmaps/rtpmsk.xbm"
31 #include "../src/bitmaps/cntrptr.xbm"
32 #include "../src/bitmaps/cntrpmsk.xbm"
33 #include "../src/bitmaps/stipple.xbm"
34
35 #else
36 #ifndef VMS
37
38 #include <X11/bitmaps/dimple1>
39 #include <X11/bitmaps/dimple3>
40 #include <X11/bitmaps/gray1>
41 #include <X11/bitmaps/gray3>
42 #include <X11/bitmaps/cross_weave>
43
44 #include <X11/bitmaps/left_ptr>
45 #include <X11/bitmaps/left_ptrmsk>
46 #include <X11/bitmaps/right_ptr>
47 #include <X11/bitmaps/right_ptrmsk>
48 #include <X11/bitmaps/cntr_ptr>
49 #include <X11/bitmaps/cntr_ptrmsk>
50 #include <X11/bitmaps/stipple>
51
52 #else
53
54 #include "[-.src.bitmaps]dimple1.xbm"
55 #include "[-.src.bitmaps]dimple3.xbm"
56 #include "[-.src.bitmaps]gray1.xbm"
57 #include "[-.src.bitmaps]gray3.xbm"
58 #include "[-.src.bitmaps]crosswv.xbm"
59
60 #include "[-.src.bitmaps]leftptr.xbm"
61 #include "[-.src.bitmaps]leftpmsk.xbm"
62 #include "[-.src.bitmaps]rtptr.xbm"
63 #include "[-.src.bitmaps]rtpmsk.xbm"
64 #include "[-.src.bitmaps]cntrptr.xbm"
65 #include "[-.src.bitmaps]cntrpmsk.xbm"
66 #include "[-.src.bitmaps]stipple.xbm"
67
68 #endif /* VMS */
69 #endif /* not EMACS_BITMAP_FILES */
70
71 #define DEF_FREEZE              0
72 #define DEF_REVERSE             0
73 #define DEF_MENU_STYLE          LEFT
74 #define DEF_MENU_MODE           BOX
75 #define DEF_INACT_PNUM          3
76 #define MAX_INACT_PNUM          4
77
78 #define DEF_P_STYLE             CENTER
79
80 #define DEF_P_EVENTS            (EnterWindowMask | ExposureMask)
81 #define DEF_P_FNT_NAME          "fixed"
82 #define DEF_P_SPREAD            0.5
83 #define DEF_P_BDR_WIDTH         2
84
85 #define DEF_S_STYLE             LEFT
86 #define DEF_S_EVENTS            (EnterWindowMask | LeaveWindowMask)
87 #define DEF_S_FNT_NAME          "fixed"
88 #define DEF_S_SPREAD            0.10
89 #define DEF_S_BDR_WIDTH         1
90
91 #define XASSOC_TABLE_SIZE       64
92
93 #define TILE_BUF_SIZE           5
94
95 int atoi();
96 double atof();
97 char *x_get_resource_string ();
98
99
100
101 static Status
102 XAllocDisplayColor(display, map, colorName, color, junk)
103     Display *display;
104     Colormap map;
105     char *colorName;
106     XColor *color;
107     XColor *junk;
108 {
109   return (colorName!=0 &&
110           XParseColor(display, map, colorName, color) &&
111           XAllocColor(display, map, color));
112 }
113
114
115 XMenu *
116 XMenuCreate(display, parent, def_env)
117     Display *display;           /* ID of previously opened display */
118     Window parent;              /* Window ID of the menu's parent window. */
119     register char *def_env;     /* X Defaults program environment name. */
120 {
121   register int i;               /* Loop counter. */
122   register int j;               /* Loop counter. */
123   register char *def_val;       /* X Default value temp variable. */
124
125   register XMenu *menu;         /* Pointer to the new menu. */
126   XMStyle menu_style;           /* Menu display style. */
127   XMMode menu_mode;             /* Menu display mode. */
128   XMPane *pane;                 /* Pane list header. */
129   XAssocTable *assoc_tab;       /* XAssocTable pointer. */
130
131   int freeze;                   /* Freeze server mode. */
132   int reverse;                  /* Reverse video mode. */
133
134   XMStyle p_style;              /* Pane display style. */
135   char *p_fnt_name;             /* Flag font name. */
136   XFontStruct *p_fnt_info;      /* Flag font structure */
137   int p_fnt_pad;                /* Flag font padding in pixels. */
138   double p_spread;              /* Pane spread in flag height fractions. */
139   int p_fnt_height;             /* Pane character height. */
140   int p_bdr_width;              /* Pane border width. */
141   int flag_height;              /* Flag window height. */
142   int p_height;                 /* Pane window height. */
143   int p_x_off;                  /* Pane X offset. */
144   int p_y_off;                  /* Pane Y offset. */
145   GC pane_GC;                   /* Pane graphics context. */
146
147   XMStyle s_style;              /* Selection display style. */
148   char *s_fnt_name;             /* Selection font name. */
149   XFontStruct *s_fnt_info;      /* Selection font structure. */
150   int s_fnt_pad;                /* Selection font padding in pixels. */
151   int s_fnt_height;             /* Selection font character height */
152   double s_spread;              /* Select spread in line height fractions. */
153   int s_bdr_width;              /* Highlight border width. */
154   int s_height;                 /* Selection window height. */
155   int s_x_off;                  /* Selection window X offset. */
156   int s_y_off;                  /* Selection window Y offset. */
157   GC normal_select_GC;          /* GC used for normal video selection. */
158   GC inverse_select_GC;         /* GC used for inverse video selection. */
159   GC inact_GC;                  /* GC for inactive pane header and */
160   /* selections. */
161   GC inact_GC_noexpose;
162
163   XColor color_def;             /* Temp color definition holder. */
164   XColor screen_def;            /* Temp screen color definition holder */
165   XColor p_bdr_color;           /* Color of border. */
166   XColor s_bdr_color;           /* Color of highlight. */
167   XColor p_frg_color;           /* Color of pane foreground color. */
168   XColor s_frg_color;           /* Color of selection foreground. */
169   XColor bkgnd_color;           /* Color of background.. */
170   XColor mouse_color;           /* Color of mouse cursor. */
171   Cursor mouse_cursor;          /* Mouse cursor. */
172   Pixmap inact_bitmap;          /* Menu inactive pixmap. */
173
174   int inact_pnum;               /* Inactive background pattern number. */
175
176   Pixel p_bdr_pixel;            /* Pane border pixel. */
177   Pixel s_bdr_pixel;            /* Selection border pixel. */
178   Pixel p_frg_pixel;            /* Pane foreground pixel. */
179   Pixel s_frg_pixel;            /* Selection foreground pixel. */
180   Pixel bkgnd_pixel;            /* Menu background pixel. */
181
182   int *width, *height;
183   Pixmap *bitmap;
184   int *x_hot, *y_hot;
185   int status;                   /* Return code from XReadBitmapFile. */
186
187   Pixmap cursor;                /* Cursor pixmap holder. */
188   Pixmap cursor_mask;           /* Cursor mask pixmap holder. */
189   Pixmap stipple_pixmap;        /* Stipple mask for half-tone text. */
190   unsigned long valuemask;
191   XGCValues *values;
192    
193   Window root = RootWindow (display, DefaultScreen (display));
194
195   /*
196    * Calloc the XMenu structure and the initial pane.
197    */
198   menu = (XMenu *)calloc(1, sizeof(XMenu));
199   if (menu == NULL) {
200     _XMErrorCode = XME_CALLOC;
201     return(NULL);
202   }
203   pane = (XMPane *)calloc(1, sizeof(XMPane));
204   if (pane == NULL) {
205     _XMErrorCode = XME_CALLOC;
206     return(NULL);
207   }
208    
209   /*
210    * Create the XAssocTable
211    */
212   assoc_tab = (XAssocTable *)XCreateAssocTable(XASSOC_TABLE_SIZE);
213   if(assoc_tab == NULL) {
214     _XMErrorCode= XME_CREATE_ASSOC;
215     return(NULL);
216   }
217
218   /*
219    * Set up the default environment name.
220    */
221   if (def_env == NULL || *def_env == '\0') def_env = "XMenu";
222
223   /*
224    * Set up internal fail-safe defaults.
225    */
226   freeze = DEF_FREEZE;
227   reverse = DEF_REVERSE;
228   menu_style = DEF_MENU_STYLE;
229   menu_mode = DEF_MENU_MODE;
230   inact_pnum = DEF_INACT_PNUM;
231
232   p_style = DEF_P_STYLE;
233   p_spread = DEF_P_SPREAD;
234   p_fnt_name = DEF_P_FNT_NAME;
235   p_bdr_width = DEF_P_BDR_WIDTH;
236
237   s_style = DEF_S_STYLE;
238   s_spread = DEF_S_SPREAD;
239   s_fnt_name = DEF_S_FNT_NAME;
240   s_bdr_width = DEF_S_BDR_WIDTH;
241
242   /*
243    * Get default values from X.
244    */
245   def_val = x_get_resource_string ("menuFreeze", "MenuFreeze");
246   if (def_val != NULL) {
247     if (strcmp(def_val, "on") == 0) freeze = 1;
248     else if (strcmp(def_val, "off") == 0) freeze = 0;
249   }
250
251   def_val = x_get_resource_string ("menuReverseVideo", "MenuReverseVideo");
252   if (def_val != NULL) {
253     if (strcmp(def_val, "on") == 0) reverse = 1;
254     else if (strcmp(def_val, "off") == 0) reverse = 0;
255   }
256
257   def_val = x_get_resource_string ("menuStyle", "MenuStyle");
258   if (def_val != NULL) {
259     if (strcmp(def_val, "right_hand") == 0) menu_style = RIGHT;
260     else if (strcmp(def_val, "left_hand") == 0) menu_style = LEFT;
261     else if (strcmp(def_val, "center") == 0) menu_style = CENTER;
262   }
263
264   def_val = x_get_resource_string ("menuMode", "MenuMode");
265   if (def_val != NULL) {
266     if (strcmp(def_val, "box") == 0) menu_mode = BOX;
267     else if (strcmp(def_val, "invert") == 0) menu_mode = INVERT;
268   }
269    
270   def_val = x_get_resource_string ("menuMouse", "MenuMouse");
271   if (
272       def_val != NULL &&
273       DisplayCells(display, DefaultScreen(display)) > 2 &&
274       XAllocDisplayColor(display,
275                          DefaultColormap(display, DefaultScreen(display)),
276                          def_val,
277                          &mouse_color, &color_def)
278       );
279   else if (reverse &&
280            XAllocDisplayColor(display,
281                               DefaultColormap(display, DefaultScreen(display)),
282                               "white",
283                               &mouse_color, &color_def)
284            );
285    
286   else if (XAllocDisplayColor(display,
287                               DefaultColormap(display, DefaultScreen(display)),
288                               "black",
289                               &mouse_color, &color_def)
290            );
291    
292   else ;
293
294   def_val = x_get_resource_string ("menuBackground", "MenuBackground");
295   if (
296       def_val != NULL &&
297       DisplayCells(display, DefaultScreen(display)) > 2 &&
298       XAllocDisplayColor(display,
299                          DefaultColormap(display, DefaultScreen(display)),
300                          def_val,
301                          &bkgnd_color, &color_def)
302       );
303   else if (reverse &&
304            XAllocDisplayColor(display,
305                               DefaultColormap(display, DefaultScreen(display)),
306                               "black",
307                               &bkgnd_color, &color_def)
308            );
309   else if (XAllocDisplayColor(display,
310                               DefaultColormap(display, DefaultScreen(display)),
311                               "white",
312                               &bkgnd_color, &color_def)
313            );
314   else;
315
316   def_val = x_get_resource_string ("menuInactivePattern", "MenuInactivePattern");
317   if (def_val != NULL) {
318     if (strcmp(def_val, "dimple1") == 0) inact_pnum = 0;
319     else if (strcmp(def_val, "dimple3") == 0) inact_pnum = 1;
320     else if (strcmp(def_val, "gray1") == 0) inact_pnum = 2;
321     else if (strcmp(def_val, "gray3") == 0) inact_pnum = 3;
322     else if (strcmp(def_val, "cross_weave") == 0) inact_pnum = 4;
323   }
324
325   def_val = x_get_resource_string ("paneStyle", "PaneStyle");
326   if (def_val != NULL) {
327     if (strcmp(def_val, "flush_left") == 0) p_style = LEFT;
328     else if (strcmp(def_val, "flush_right") == 0) p_style = RIGHT;
329     else if (strcmp(def_val, "center") == 0) p_style = CENTER;
330   }
331
332   def_val = x_get_resource_string ("paneFont", "PaneFont");
333   if (def_val != NULL) p_fnt_name = def_val;
334
335   def_val = x_get_resource_string ("paneForeground", "PaneForeground");
336   if (
337       def_val != NULL &&
338       DisplayCells(display, DefaultScreen(display)) > 2
339       )
340     XAllocDisplayColor(display, DefaultColormap(display,
341                                                 DefaultScreen(display)),
342                        def_val,
343                        &p_frg_color, &color_def);
344          
345   else if (reverse) XAllocDisplayColor(display,
346                                        DefaultColormap(display,
347                                                        DefaultScreen(display)),
348                                        "white",
349                                        &p_frg_color, &color_def);
350   else XAllocDisplayColor(display,
351                           DefaultColormap(display, DefaultScreen(display)),
352                           "black",
353                           &p_frg_color, &color_def);
354
355   def_val = x_get_resource_string ("paneBorder", "PaneBorder");
356   if (
357       def_val != NULL &&
358       DisplayCells(display, DefaultScreen(display)) > 2 &&
359       XAllocDisplayColor(display,
360                          DefaultColormap(display, DefaultScreen(display)),
361                          def_val,
362                          &p_bdr_color, &color_def)
363       );
364   else if (reverse &&
365            XAllocDisplayColor(display,
366                               DefaultColormap(display, DefaultScreen(display)),
367                               "white",
368                               &p_bdr_color, &color_def)
369            );
370   else XAllocDisplayColor(display,
371                           DefaultColormap(display, DefaultScreen(display)),
372                           "black",
373                           &p_bdr_color, &color_def);
374    
375   def_val = x_get_resource_string ("paneBorderWidth", "PaneBorderWidth");
376   if (def_val != NULL) p_bdr_width = atoi(def_val);
377    
378   def_val = x_get_resource_string ("paneSpread", "PaneSpread");
379   if (def_val != NULL) p_spread = atof(def_val);
380
381   def_val = x_get_resource_string ("selectionStyle", "SelectionStyle");
382   if (def_val != NULL) {
383     if (strcmp(def_val, "flush_left") == 0) s_style = LEFT;
384     else if (strcmp(def_val, "flush_right") == 0) s_style = RIGHT;
385     else if (strcmp(def_val, "center") == 0) s_style = CENTER;
386   }
387
388   def_val = x_get_resource_string ("selectionFont", "SelectionFont");
389   if (def_val != NULL) s_fnt_name = def_val;
390
391   def_val = x_get_resource_string ("selectionForeground", "SelectionForeground");
392   if (
393       def_val != NULL &&
394       DisplayCells(display, DefaultScreen(display)) > 2 &&
395       XAllocDisplayColor(display,
396                          DefaultColormap(display, DefaultScreen(display)),
397                          def_val,
398                          &s_frg_color, &color_def)
399       );
400   else if (reverse &&
401            XAllocDisplayColor(display,
402                               DefaultColormap(display, DefaultScreen(display)),
403                               "white",
404                               &s_frg_color, &color_def)
405            ) ;
406   else if (XAllocDisplayColor(display,
407                               DefaultColormap(display, DefaultScreen(display)),
408                               "black",
409                               &s_frg_color, &color_def)
410            ) ;
411   else ;
412    
413
414   def_val = x_get_resource_string ("selectionBorder", "SelectionBorder");
415   if (
416       def_val != NULL &&
417       DisplayCells(display, DefaultScreen(display)) > 2 &&
418       XAllocDisplayColor(display,
419                          DefaultColormap(display, DefaultScreen(display)),
420                          def_val,
421                          &s_bdr_color, &color_def)
422       ) ;
423   else if (reverse &&
424            XAllocDisplayColor(display,
425                               DefaultColormap(display, DefaultScreen(display)),
426                               "white",
427                               &s_bdr_color, &color_def)
428            ) ;
429   else if (XAllocDisplayColor(display,
430                               DefaultColormap(display, DefaultScreen(display)),
431                               "black",
432                               &s_bdr_color, &color_def)
433            ) ;
434   else ;
435
436   def_val = x_get_resource_string ("selectionBorderWidth", "SelectionBorderWidth");
437   if (def_val != NULL) s_bdr_width = atoi(def_val);
438    
439   def_val = x_get_resource_string ("selectionSpread", "SelectionSpread");
440   if (def_val != NULL) s_spread = atof(def_val);
441
442   /*
443    * Create and store the inactive pattern pixmap.
444    */
445   {
446     char *data = NULL;
447     int width, height;
448
449     switch (inact_pnum)
450       {
451       case 0:
452         data = (char *)dimple1_bits;
453         width = dimple1_width;
454         height = dimple1_height;
455         break;
456
457       case 1:
458         data = (char *)dimple3_bits;
459         width = dimple3_width;
460         height = dimple3_height;
461         break;
462
463       case 2:
464         data = (char *)gray1_bits;
465         width = gray1_width;
466         height = gray1_height;
467         break;
468
469       case 3:
470         data = (char *)gray3_bits;
471         width = gray3_width;
472         height = gray3_height;
473         break;
474
475       case 4:
476         data = (char *)cross_weave_bits;
477         width = cross_weave_width;
478         height = cross_weave_height;
479         break;
480       }
481
482     if (! data)
483       {
484         _XMErrorCode = XME_STORE_BITMAP;
485         return(NULL);
486       }
487
488     inact_bitmap =
489       XCreatePixmapFromBitmapData
490         (display, root, data, width, height,
491          p_frg_color.pixel, bkgnd_color.pixel,
492          DisplayPlanes (display, DefaultScreen (display)));
493   }
494
495   /*
496    * Load the mouse cursor.
497    */
498          
499   switch (menu_style) {
500   case LEFT:
501     cursor = XCreateBitmapFromData(display,
502                                    root,
503                                    left_ptr_bits,
504                                    left_ptr_width,
505                                    left_ptr_height);
506     cursor_mask = XCreateBitmapFromData(display,
507                                         root,
508                                         left_ptrmsk_bits,
509                                         left_ptrmsk_width,
510                                         left_ptrmsk_height);
511     mouse_cursor = XCreatePixmapCursor(
512                                        display,
513                                        cursor, cursor_mask,
514                                        &mouse_color, &bkgnd_color,
515                                        left_ptr_x_hot,
516                                        left_ptr_y_hot
517                                        );
518     XFreePixmap(display, cursor);
519     XFreePixmap