Mercurial > emacs
comparison src/xmenu.c @ 62661:0db5674a79de
(Fx_popup_dialog): Add a third boolean argument to
select frame title ("Question"/"Information").
(xdialog_show): Use it.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Tue, 24 May 2005 03:45:42 +0000 |
parents | 0c2ce5566afa |
children | b83593f0515d 63b7247f4be6 5b029ff3b08d |
comparison
equal
deleted
inserted
replaced
62660:a3b4d6c789db | 62661:0db5674a79de |
---|---|
114 | 114 |
115 #ifdef USE_X_TOOLKIT | 115 #ifdef USE_X_TOOLKIT |
116 extern void set_frame_menubar P_ ((FRAME_PTR, int, int)); | 116 extern void set_frame_menubar P_ ((FRAME_PTR, int, int)); |
117 extern XtAppContext Xt_app_con; | 117 extern XtAppContext Xt_app_con; |
118 | 118 |
119 static Lisp_Object xdialog_show P_ ((FRAME_PTR, int, Lisp_Object, char **)); | 119 static Lisp_Object xdialog_show P_ ((FRAME_PTR, int, Lisp_Object, Lisp_Object, |
120 char **)); | |
120 static void popup_get_selection P_ ((XEvent *, struct x_display_info *, | 121 static void popup_get_selection P_ ((XEvent *, struct x_display_info *, |
121 LWLIB_ID, int)); | 122 LWLIB_ID, int)); |
122 | 123 |
123 /* Define HAVE_BOXES if menus can handle radio and toggle buttons. */ | 124 /* Define HAVE_BOXES if menus can handle radio and toggle buttons. */ |
124 | 125 |
127 | 128 |
128 #ifdef USE_GTK | 129 #ifdef USE_GTK |
129 #include "gtkutil.h" | 130 #include "gtkutil.h" |
130 #define HAVE_BOXES 1 | 131 #define HAVE_BOXES 1 |
131 extern void set_frame_menubar P_ ((FRAME_PTR, int, int)); | 132 extern void set_frame_menubar P_ ((FRAME_PTR, int, int)); |
132 static Lisp_Object xdialog_show P_ ((FRAME_PTR, int, Lisp_Object, char **)); | 133 static Lisp_Object xdialog_show P_ ((FRAME_PTR, int, Lisp_Object, Lisp_Object, |
134 char **)); | |
133 #endif | 135 #endif |
134 | 136 |
135 /* This is how to deal with multibyte text if HAVE_MULTILINGUAL_MENU | 137 /* This is how to deal with multibyte text if HAVE_MULTILINGUAL_MENU |
136 isn't defined. The use of HAVE_MULTILINGUAL_MENU could probably be | 138 isn't defined. The use of HAVE_MULTILINGUAL_MENU could probably be |
137 confined to an extended version of this with sections of code below | 139 confined to an extended version of this with sections of code below |
997 return selection; | 999 return selection; |
998 } | 1000 } |
999 | 1001 |
1000 #ifdef HAVE_MENUS | 1002 #ifdef HAVE_MENUS |
1001 | 1003 |
1002 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0, | 1004 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 3, 0, |
1003 doc: /* Pop up a dialog box and return user's selection. | 1005 doc: /* Pop up a dialog box and return user's selection. |
1004 POSITION specifies which frame to use. | 1006 POSITION specifies which frame to use. |
1005 This is normally a mouse button event or a window or frame. | 1007 This is normally a mouse button event or a window or frame. |
1006 If POSITION is t, it means to use the frame the mouse is on. | 1008 If POSITION is t, it means to use the frame the mouse is on. |
1007 The dialog box appears in the middle of the specified frame. | 1009 The dialog box appears in the middle of the specified frame. |
1008 | 1010 |
1009 CONTENTS specifies the alternatives to display in the dialog box. | 1011 CONTENTS specifies the alternatives to display in the dialog box. |
1010 It is a list of the form (TITLE ITEM1 ITEM2...). | 1012 It is a list of the form (DIALOG ITEM1 ITEM2...). |
1011 Each ITEM is a cons cell (STRING . VALUE). | 1013 Each ITEM is a cons cell (STRING . VALUE). |
1012 The return value is VALUE from the chosen item. | 1014 The return value is VALUE from the chosen item. |
1013 | 1015 |
1014 An ITEM may also be just a string--that makes a nonselectable item. | 1016 An ITEM may also be just a string--that makes a nonselectable item. |
1015 An ITEM may also be nil--that means to put all preceding items | 1017 An ITEM may also be nil--that means to put all preceding items |
1016 on the left of the dialog box and all following items on the right. | 1018 on the left of the dialog box and all following items on the right. |
1017 \(By default, approximately half appear on each side.) | 1019 \(By default, approximately half appear on each side.) |
1018 | 1020 |
1021 If HEADER is non-nil, the frame title for the box is "Information", | |
1022 otherwise it is "Question". | |
1023 | |
1019 If the user gets rid of the dialog box without making a valid choice, | 1024 If the user gets rid of the dialog box without making a valid choice, |
1020 for instance using the window manager, then this produces a quit and | 1025 for instance using the window manager, then this produces a quit and |
1021 `x-popup-dialog' does not return. */) | 1026 `x-popup-dialog' does not return. */) |
1022 (position, contents) | 1027 (position, contents, header) |
1023 Lisp_Object position, contents; | 1028 Lisp_Object position, contents, header; |
1024 { | 1029 { |
1025 FRAME_PTR f = NULL; | 1030 FRAME_PTR f = NULL; |
1026 Lisp_Object window; | 1031 Lisp_Object window; |
1027 | 1032 |
1028 check_x (); | 1033 check_x (); |
1113 | 1118 |
1114 list_of_panes (Fcons (contents, Qnil)); | 1119 list_of_panes (Fcons (contents, Qnil)); |
1115 | 1120 |
1116 /* Display them in a dialog box. */ | 1121 /* Display them in a dialog box. */ |
1117 BLOCK_INPUT; | 1122 BLOCK_INPUT; |
1118 selection = xdialog_show (f, 0, title, &error_name); | 1123 selection = xdialog_show (f, 0, title, header, &error_name); |
1119 UNBLOCK_INPUT; | 1124 UNBLOCK_INPUT; |
1120 | 1125 |
1121 unbind_to (specpdl_count, Qnil); | 1126 unbind_to (specpdl_count, Qnil); |
1122 discard_menu_items (); | 1127 discard_menu_items (); |
1123 | 1128 |
3018 static char * button_names [] = { | 3023 static char * button_names [] = { |
3019 "button1", "button2", "button3", "button4", "button5", | 3024 "button1", "button2", "button3", "button4", "button5", |
3020 "button6", "button7", "button8", "button9", "button10" }; | 3025 "button6", "button7", "button8", "button9", "button10" }; |
3021 | 3026 |
3022 static Lisp_Object | 3027 static Lisp_Object |
3023 xdialog_show (f, keymaps, title, error) | 3028 xdialog_show (f, keymaps, title, header, error_name) |
3024 FRAME_PTR f; | 3029 FRAME_PTR f; |
3025 int keymaps; | 3030 int keymaps; |
3026 Lisp_Object title; | 3031 Lisp_Object title, header; |
3027 char **error; | 3032 char **error_name; |
3028 { | 3033 { |
3029 int i, nb_buttons=0; | 3034 int i, nb_buttons=0; |
3030 char dialog_name[6]; | 3035 char dialog_name[6]; |
3031 | 3036 |
3032 widget_value *wv, *first_wv = 0, *prev_wv = 0; | 3037 widget_value *wv, *first_wv = 0, *prev_wv = 0; |
3034 /* Number of elements seen so far, before boundary. */ | 3039 /* Number of elements seen so far, before boundary. */ |
3035 int left_count = 0; | 3040 int left_count = 0; |
3036 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ | 3041 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ |
3037 int boundary_seen = 0; | 3042 int boundary_seen = 0; |
3038 | 3043 |
3039 *error = NULL; | 3044 *error_name = NULL; |
3040 | 3045 |
3041 if (menu_items_n_panes > 1) | 3046 if (menu_items_n_panes > 1) |
3042 { | 3047 { |
3043 *error = "Multiple panes in dialog box"; | 3048 *error_name = "Multiple panes in dialog box"; |
3044 return Qnil; | 3049 return Qnil; |
3045 } | 3050 } |
3046 | 3051 |
3047 /* Create a tree of widget_value objects | 3052 /* Create a tree of widget_value objects |
3048 representing the text label and buttons. */ | 3053 representing the text label and buttons. */ |
3075 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; | 3080 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; |
3076 | 3081 |
3077 if (NILP (item_name)) | 3082 if (NILP (item_name)) |
3078 { | 3083 { |
3079 free_menubar_widget_value_tree (first_wv); | 3084 free_menubar_widget_value_tree (first_wv); |
3080 *error = "Submenu in dialog items"; | 3085 *error_name = "Submenu in dialog items"; |
3081 return Qnil; | 3086 return Qnil; |
3082 } | 3087 } |
3083 if (EQ (item_name, Qquote)) | 3088 if (EQ (item_name, Qquote)) |
3084 { | 3089 { |
3085 /* This is the boundary between left-side elts | 3090 /* This is the boundary between left-side elts |
3089 continue; | 3094 continue; |
3090 } | 3095 } |
3091 if (nb_buttons >= 9) | 3096 if (nb_buttons >= 9) |
3092 { | 3097 { |
3093 free_menubar_widget_value_tree (first_wv); | 3098 free_menubar_widget_value_tree (first_wv); |
3094 *error = "Too many dialog items"; | 3099 *error_name = "Too many dialog items"; |
3095 return Qnil; | 3100 return Qnil; |
3096 } | 3101 } |
3097 | 3102 |
3098 wv = xmalloc_widget_value (); | 3103 wv = xmalloc_widget_value (); |
3099 prev_wv->next = wv; | 3104 prev_wv->next = wv; |
3119 left_count = nb_buttons - nb_buttons / 2; | 3124 left_count = nb_buttons - nb_buttons / 2; |
3120 | 3125 |
3121 wv = xmalloc_widget_value (); | 3126 wv = xmalloc_widget_value (); |
3122 wv->name = dialog_name; | 3127 wv->name = dialog_name; |
3123 wv->help = Qnil; | 3128 wv->help = Qnil; |
3129 | |
3130 /* Frame title: 'Q' = Question, 'I' = Information. | |
3131 Can also have 'E' = Error if, one day, we want | |
3132 a popup for errors. */ | |
3133 if (NILP(header)) | |
3134 dialog_name[0] = 'Q'; | |
3135 else | |
3136 dialog_name[0] = 'I'; | |
3137 | |
3124 /* Dialog boxes use a really stupid name encoding | 3138 /* Dialog boxes use a really stupid name encoding |
3125 which specifies how many buttons to use | 3139 which specifies how many buttons to use |
3126 and how many buttons are on the right. | 3140 and how many buttons are on the right. */ |
3127 The Q means something also. */ | |
3128 dialog_name[0] = 'Q'; | |
3129 dialog_name[1] = '0' + nb_buttons; | 3141 dialog_name[1] = '0' + nb_buttons; |
3130 dialog_name[2] = 'B'; | 3142 dialog_name[2] = 'B'; |
3131 dialog_name[3] = 'R'; | 3143 dialog_name[3] = 'R'; |
3132 /* Number of buttons to put on the right. */ | 3144 /* Number of buttons to put on the right. */ |
3133 dialog_name[4] = '0' + nb_buttons - left_count; | 3145 dialog_name[4] = '0' + nb_buttons - left_count; |