comparison src/menubar-x.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 2d532a89d707
children d44af0c54775
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
83 We do not have to worry about the pointers to Lisp_String data after 83 We do not have to worry about the pointers to Lisp_String data after
84 this function successfully finishes. lwlib copies all such data with 84 this function successfully finishes. lwlib copies all such data with
85 strdup(). */ 85 strdup(). */
86 86
87 static widget_value * 87 static widget_value *
88 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc, 88 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc,
89 int menu_type, int deep_p, 89 int menu_type, int deep_p,
90 int filter_p, 90 int filter_p,
91 int depth) 91 int depth)
92 { 92 {
93 /* This function cannot GC. 93 /* This function cannot GC.
116 string_chars = GETTEXT (string_chars); 116 string_chars = GETTEXT (string_chars);
117 #endif 117 #endif
118 if (wv->type == SEPARATOR_TYPE) 118 if (wv->type == SEPARATOR_TYPE)
119 { 119 {
120 wv->value = menu_separator_style (string_chars); 120 wv->value = menu_separator_style (string_chars);
121 } 121 }
122 else 122 else
123 { 123 {
124 wv->name = string_chars; 124 wv->name = string_chars;
125 wv->enabled = 1; 125 wv->enabled = 1;
126 } 126 }
160 { 160 {
161 Lisp_Object cascade = desc; 161 Lisp_Object cascade = desc;
162 desc = Fcdr (desc); 162 desc = Fcdr (desc);
163 if (NILP (desc)) 163 if (NILP (desc))
164 signal_simple_error ("keyword in menu lacks a value", 164 signal_simple_error ("keyword in menu lacks a value",
165 cascade); 165 cascade);
166 val = Fcar (desc); 166 val = Fcar (desc);
167 desc = Fcdr (desc); 167 desc = Fcdr (desc);
168 if (EQ (key, Q_included)) 168 if (EQ (key, Q_included))
169 include_p = val, included_spec = 1; 169 include_p = val, included_spec = 1;
170 else if (EQ (key, Q_config)) 170 else if (EQ (key, Q_config))
177 || CHARP (val)) 177 || CHARP (val))
178 wv->accel = LISP_TO_VOID (val); 178 wv->accel = LISP_TO_VOID (val);
179 else 179 else
180 signal_simple_error ("bad keyboard accelerator", val); 180 signal_simple_error ("bad keyboard accelerator", val);
181 } 181 }
182 else 182 else
183 signal_simple_error ("unknown menu cascade keyword", cascade); 183 signal_simple_error ("unknown menu cascade keyword", cascade);
184 } 184 }
185 185
186 if ((!NILP (config_tag) 186 if ((!NILP (config_tag)
187 && NILP (Fmemq (config_tag, Vmenubar_configuration))) 187 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
193 if (!NILP (hook_fn)) 193 if (!NILP (hook_fn))
194 { 194 {
195 #ifdef LWLIB_MENUBARS_LUCID 195 #ifdef LWLIB_MENUBARS_LUCID
196 if (filter_p || depth == 0) 196 if (filter_p || depth == 0)
197 { 197 {
198 #endif 198 #endif
199 desc = call1_trapping_errors ("Error in menubar filter", 199 desc = call1_trapping_errors ("Error in menubar filter",
200 hook_fn, desc); 200 hook_fn, desc);
201 if (UNBOUNDP (desc)) 201 if (UNBOUNDP (desc))
202 desc = Qnil; 202 desc = Qnil;
203 #ifdef LWLIB_MENUBARS_LUCID 203 #ifdef LWLIB_MENUBARS_LUCID
229 title_wv->enabled = 1; 229 title_wv->enabled = 1;
230 title_wv->next = sep_wv; 230 title_wv->next = sep_wv;
231 sep_wv->type = SEPARATOR_TYPE; 231 sep_wv->type = SEPARATOR_TYPE;
232 sep_wv->value = menu_separator_style ("=="); 232 sep_wv->value = menu_separator_style ("==");
233 sep_wv->next = 0; 233 sep_wv->next = 0;
234 234
235 wv->contents = title_wv; 235 wv->contents = title_wv;
236 prev = sep_wv; 236 prev = sep_wv;
237 } 237 }
238 } 238 }
239 else if (menubar_root_p) 239 else if (menubar_root_p)
299 unbind_to (count, Qnil); 299 unbind_to (count, Qnil);
300 return wv; 300 return wv;
301 } 301 }
302 302
303 static widget_value * 303 static widget_value *
304 menu_item_descriptor_to_widget_value (Lisp_Object desc, 304 menu_item_descriptor_to_widget_value (Lisp_Object desc,
305 int menu_type, /* if this is a menubar, 305 int menu_type, /* if this is a menubar,
306 popup or sub menu */ 306 popup or sub menu */
307 int deep_p, /* */ 307 int deep_p, /* */
308 int filter_p) /* if :filter forms 308 int filter_p) /* if :filter forms
309 should run now */ 309 should run now */
310 { 310 {
311 widget_value *wv; 311 widget_value *wv;
312 int count = specpdl_depth (); 312 int count = specpdl_depth ();
313 record_unwind_protect (restore_gc_inhibit, 313 record_unwind_protect (restore_gc_inhibit,
314 make_int (gc_currently_forbidden)); 314 make_int (gc_currently_forbidden));
343 The pre_activate_callback() *IS* intentionally called multiple times. 343 The pre_activate_callback() *IS* intentionally called multiple times.
344 If client_data == NULL, then it's being called before the menu is posted. 344 If client_data == NULL, then it's being called before the menu is posted.
345 If client_data != NULL, then client_data is a (widget_value *) and 345 If client_data != NULL, then client_data is a (widget_value *) and
346 client_data->data is a Lisp_Object pointing to a lisp submenu description 346 client_data->data is a Lisp_Object pointing to a lisp submenu description
347 that must be converted into widget_values. *client_data is destructively 347 that must be converted into widget_values. *client_data is destructively
348 modified. 348 modified.
349 349
350 #### Stig thinks that there may be a GC problem here due to the 350 #### Stig thinks that there may be a GC problem here due to the
351 fact that pre_activate_callback() is called multiple times, but I 351 fact that pre_activate_callback() is called multiple times, but I
352 think he's wrong. 352 think he's wrong.
353 353
427 function, just to simplify things. */ 427 function, just to simplify things. */
428 if (!NILP (Vactivate_menubar_hook) && 428 if (!NILP (Vactivate_menubar_hook) &&
429 (!CONSP (Vactivate_menubar_hook) || 429 (!CONSP (Vactivate_menubar_hook) ||
430 EQ (XCAR (Vactivate_menubar_hook), Qlambda))) 430 EQ (XCAR (Vactivate_menubar_hook), Qlambda)))
431 Vactivate_menubar_hook = Fcons (Vactivate_menubar_hook, Qnil); 431 Vactivate_menubar_hook = Fcons (Vactivate_menubar_hook, Qnil);
432 432
433 GCPRO1 (rest); 433 GCPRO1 (rest);
434 for (rest = Vactivate_menubar_hook; !NILP (rest); rest = Fcdr (rest)) 434 for (rest = Vactivate_menubar_hook; !NILP (rest); rest = Fcdr (rest))
435 if (!EQ (call0 (XCAR (rest)), Qt)) 435 if (!EQ (call0 (XCAR (rest)), Qt))
436 any_changes = 1; 436 any_changes = 1;
437 #if 0 437 #if 0
443 It is difficult to undo the destructive operation in lwlib because 443 It is difficult to undo the destructive operation in lwlib because
444 a pointer back to lisp data needs to be hidden away somewhere. So 444 a pointer back to lisp data needs to be hidden away somewhere. So
445 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */ 445 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
446 if (any_changes || 446 if (any_changes ||
447 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date) 447 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date)
448 #endif 448 #endif
449 set_frame_menubar (f, 1, 0); 449 set_frame_menubar (f, 1, 0);
450 DEVICE_X_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) = 450 DEVICE_X_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
451 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) = 451 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
452 x_focus_timestamp_really_sucks_fix_me_better; 452 x_focus_timestamp_really_sucks_fix_me_better;
453 UNGCPRO; 453 UNGCPRO;
540 menubar_visible = !NILP (w->menubar_visible_p); 540 menubar_visible = !NILP (w->menubar_visible_p);
541 541
542 data = compute_menubar_data (f, menubar, deep_p); 542 data = compute_menubar_data (f, menubar, deep_p);
543 if (!data || (!data->next && !data->contents)) 543 if (!data || (!data->next && !data->contents))
544 abort (); 544 abort ();
545 545
546 if (NILP (FRAME_MENUBAR_DATA (f))) 546 if (NILP (FRAME_MENUBAR_DATA (f)))
547 { 547 {
548 struct popup_data *mdata = 548 struct popup_data *mdata =
549 alloc_lcrecord (sizeof (struct popup_data), lrecord_popup_data); 549 alloc_lcrecord_type (struct popup_data, lrecord_popup_data);
550 550
551 mdata->id = new_lwlib_id (); 551 mdata->id = new_lwlib_id ();
552 mdata->last_menubar_buffer = Qnil; 552 mdata->last_menubar_buffer = Qnil;
553 mdata->menubar_contents_up_to_date = 0; 553 mdata->menubar_contents_up_to_date = 0;
554 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata); 554 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata);
582 else 582 else
583 { 583 {
584 lw_modify_all_widgets (id, data, deep_p ? True : False); 584 lw_modify_all_widgets (id, data, deep_p ? True : False);
585 } 585 }
586 free_popup_widget_value_tree (data); 586 free_popup_widget_value_tree (data);
587 587
588 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p; 588 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
589 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer = 589 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
590 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer; 590 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
591 return menubar_visible; 591 return menubar_visible;
592 } 592 }
630 } 630 }
631 631
632 632
633 static void 633 static void
634 make_dummy_xbutton_event (XEvent *dummy, 634 make_dummy_xbutton_event (XEvent *dummy,
635 Widget daddy, 635 Widget daddy,
636 struct Lisp_Event *eev) 636 struct Lisp_Event *eev)
637 /* NULL for eev means query pointer */ 637 /* NULL for eev means query pointer */
638 { 638 {
639 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy; 639 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
640 640
701 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f)); 701 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
702 Boolean menubar_will_be_visible = menubar_was_visible; 702 Boolean menubar_will_be_visible = menubar_was_visible;
703 Boolean menubar_visibility_changed; 703 Boolean menubar_visibility_changed;
704 Cardinal new_num_top_widgets = 1; /* for the menubar */ 704 Cardinal new_num_top_widgets = 1; /* for the menubar */
705 Widget container = FRAME_X_CONTAINER_WIDGET (f); 705 Widget container = FRAME_X_CONTAINER_WIDGET (f);
706 706
707 #ifdef ENERGIZE 707 #ifdef ENERGIZE
708 int *old_sheets = FRAME_X_CURRENT_PSHEETS (f); 708 int *old_sheets = FRAME_X_CURRENT_PSHEETS (f);
709 int *new_sheets = FRAME_X_DESIRED_PSHEETS (f); 709 int *new_sheets = FRAME_X_DESIRED_PSHEETS (f);
710 int old_count = FRAME_X_CURRENT_PSHEET_COUNT (f); 710 int old_count = FRAME_X_CURRENT_PSHEET_COUNT (f);
711 int new_count = FRAME_X_DESIRED_PSHEET_COUNT (f); 711 int new_count = FRAME_X_DESIRED_PSHEET_COUNT (f);
741 741
742 /* Set menubar visibility */ 742 /* Set menubar visibility */
743 if (menubar_visibility_changed) 743 if (menubar_visibility_changed)
744 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild) 744 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
745 (FRAME_X_MENUBAR_WIDGET (f)); 745 (FRAME_X_MENUBAR_WIDGET (f));
746 746
747 747
748 #ifdef ENERGIZE 748 #ifdef ENERGIZE
749 /* Set debugger panel visibility */ 749 /* Set debugger panel visibility */
750 if (debuggerpanel_changed) 750 if (debuggerpanel_changed)
751 { 751 {
857 x_free_frame_menubars (struct frame *f) 857 x_free_frame_menubars (struct frame *f)
858 { 858 {
859 Widget menubar_widget; 859 Widget menubar_widget;
860 860
861 assert (FRAME_X_P (f)); 861 assert (FRAME_X_P (f));
862 862
863 menubar_widget = FRAME_X_MENUBAR_WIDGET (f); 863 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
864 if (menubar_widget) 864 if (menubar_widget)
865 { 865 {
866 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id; 866 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
867 lw_destroy_all_widgets (id); 867 lw_destroy_all_widgets (id);
946 CHECK_CONS (menu_desc); 946 CHECK_CONS (menu_desc);
947 CHECK_STRING (XCAR (menu_desc)); 947 CHECK_STRING (XCAR (menu_desc));
948 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1); 948 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
949 949
950 if (! data) error ("no menu"); 950 if (! data) error ("no menu");
951 951
952 menu_id = new_lwlib_id (); 952 menu_id = new_lwlib_id ();
953 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data, 953 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
954 parent, 1, 0, 954 parent, 1, 0,
955 popup_menu_selection_callback, 955 popup_menu_selection_callback,
956 popup_menu_down_callback); 956 popup_menu_down_callback);
962 from a menu is really a two-command process: the first command (bound to 962 from a menu is really a two-command process: the first command (bound to
963 the button-click) simply pops up the menu, and returns. This causes a 963 the button-click) simply pops up the menu, and returns. This causes a
964 sequence of magic-events (destined for the popup-menu widget) to begin. 964 sequence of magic-events (destined for the popup-menu widget) to begin.
965 Eventually, a menu item is selected, and a menu-event blip is pushed onto 965 Eventually, a menu item is selected, and a menu-event blip is pushed onto
966 the end of the input stream, which is then executed by the event loop. 966 the end of the input stream, which is then executed by the event loop.
967 967
968 So there are two command-events, with a bunch of magic-events between 968 So there are two command-events, with a bunch of magic-events between
969 them. We don't want the *first* command event to alter the state of the 969 them. We don't want the *first* command event to alter the state of the
970 region, so that the region can be available as an argument for the second 970 region, so that the region can be available as an argument for the second
971 command. 971 command.
972 */ 972 */