comparison src/toolbar.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents cca96a509cfe
children 3d6bfa290dbd
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
58 static Lisp_Object 58 static Lisp_Object
59 mark_toolbar_data (Lisp_Object obj, void (*markobj) (Lisp_Object)) 59 mark_toolbar_data (Lisp_Object obj, void (*markobj) (Lisp_Object))
60 { 60 {
61 struct toolbar_data *data = (struct toolbar_data *) XPNTR (obj); 61 struct toolbar_data *data = (struct toolbar_data *) XPNTR (obj);
62 ((markobj) (data->last_toolbar_buffer)); 62 ((markobj) (data->last_toolbar_buffer));
63 return (data->toolbar_buttons); 63 return data->toolbar_buttons;
64 } 64 }
65 65
66 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-data", toolbar_data, 66 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-data", toolbar_data,
67 mark_toolbar_data, internal_object_printer, 67 mark_toolbar_data, internal_object_printer,
68 0, 0, 0, struct toolbar_data); 68 0, 0, 0, struct toolbar_data);
79 ((markobj) (data->cap_up_glyph)); 79 ((markobj) (data->cap_up_glyph));
80 ((markobj) (data->cap_down_glyph)); 80 ((markobj) (data->cap_down_glyph));
81 ((markobj) (data->cap_disabled_glyph)); 81 ((markobj) (data->cap_disabled_glyph));
82 ((markobj) (data->callback)); 82 ((markobj) (data->callback));
83 ((markobj) (data->enabled_p)); 83 ((markobj) (data->enabled_p));
84 return (data->help_string); 84 return data->help_string;
85 } 85 }
86 86
87 static void 87 static void
88 print_toolbar_button (Lisp_Object obj, Lisp_Object printcharfun, 88 print_toolbar_button (Lisp_Object obj, Lisp_Object printcharfun,
89 int escapeflag) 89 int escapeflag)
107 DEFUN ("toolbar-button-p", Ftoolbar_button_p, 1, 1, 0, /* 107 DEFUN ("toolbar-button-p", Ftoolbar_button_p, 1, 1, 0, /*
108 Return non-nil if OBJECT is a toolbar button. 108 Return non-nil if OBJECT is a toolbar button.
109 */ 109 */
110 (object)) 110 (object))
111 { 111 {
112 return (TOOLBAR_BUTTONP (object) ? Qt : Qnil); 112 return TOOLBAR_BUTTONP (object) ? Qt : Qnil;
113 } 113 }
114 114
115 /* Only query functions are provided for toolbar buttons. They are 115 /* Only query functions are provided for toolbar buttons. They are
116 generated and updated from a toolbar description list. Any 116 generated and updated from a toolbar description list. Any
117 directly made changes would be wiped out the first time the toolbar 117 directly made changes would be wiped out the first time the toolbar
127 */ 127 */
128 (button)) 128 (button))
129 { 129 {
130 CHECK_TOOLBAR_BUTTON (button); 130 CHECK_TOOLBAR_BUTTON (button);
131 131
132 return (XTOOLBAR_BUTTON (button)->callback); 132 return XTOOLBAR_BUTTON (button)->callback;
133 } 133 }
134 134
135 DEFUN ("toolbar-button-help-string", Ftoolbar_button_help_string, 1, 1, 0, /* 135 DEFUN ("toolbar-button-help-string", Ftoolbar_button_help_string, 1, 1, 0, /*
136 Return the help string function associated with the toolbar BUTTON. 136 Return the help string function associated with the toolbar BUTTON.
137 */ 137 */
138 (button)) 138 (button))
139 { 139 {
140 CHECK_TOOLBAR_BUTTON (button); 140 CHECK_TOOLBAR_BUTTON (button);
141 141
142 return (XTOOLBAR_BUTTON (button)->help_string); 142 return XTOOLBAR_BUTTON (button)->help_string;
143 } 143 }
144 144
145 DEFUN ("toolbar-button-enabled-p", Ftoolbar_button_enabled_p, 1, 1, 0, /* 145 DEFUN ("toolbar-button-enabled-p", Ftoolbar_button_enabled_p, 1, 1, 0, /*
146 Return t if BUTTON is active. 146 Return t if BUTTON is active.
147 */ 147 */
148 (button)) 148 (button))
149 { 149 {
150 CHECK_TOOLBAR_BUTTON (button); 150 CHECK_TOOLBAR_BUTTON (button);
151 151
152 return (XTOOLBAR_BUTTON (button)->enabled ? Qt : Qnil); 152 return XTOOLBAR_BUTTON (button)->enabled ? Qt : Qnil;
153 } 153 }
154 154
155 DEFUN ("set-toolbar-button-down-flag", Fset_toolbar_button_down_flag, 2, 2, 0, /* 155 DEFUN ("set-toolbar-button-down-flag", Fset_toolbar_button_down_flag, 2, 2, 0, /*
156 Don't touch. 156 Don't touch.
157 */ 157 */
193 } 193 }
194 } 194 }
195 } 195 }
196 196
197 return Qnil; 197 return Qnil;
198 } 198 }
199 199
200 Lisp_Object 200 Lisp_Object
201 get_toolbar_button_glyph (struct window *w, struct toolbar_button *tb) 201 get_toolbar_button_glyph (struct window *w, struct toolbar_button *tb)
202 { 202 {
203 Lisp_Object glyph = Qnil; 203 Lisp_Object glyph = Qnil;
216 { 216 {
217 if (tb->enabled && tb->down) 217 if (tb->enabled && tb->down)
218 glyph = tb->cap_down_glyph; 218 glyph = tb->cap_down_glyph;
219 else if (!tb->enabled) 219 else if (!tb->enabled)
220 glyph = tb->cap_disabled_glyph; 220 glyph = tb->cap_disabled_glyph;
221 221
222 if (NILP (glyph)) 222 if (NILP (glyph))
223 glyph = tb->cap_up_glyph; 223 glyph = tb->cap_up_glyph;
224 } 224 }
225 225
226 if (NILP (glyph)) 226 if (NILP (glyph))
246 if (EQ (position, Qtop)) return TOP_TOOLBAR; 246 if (EQ (position, Qtop)) return TOP_TOOLBAR;
247 if (EQ (position, Qbottom)) return BOTTOM_TOOLBAR; 247 if (EQ (position, Qbottom)) return BOTTOM_TOOLBAR;
248 if (EQ (position, Qleft)) return LEFT_TOOLBAR; 248 if (EQ (position, Qleft)) return LEFT_TOOLBAR;
249 if (EQ (position, Qright)) return RIGHT_TOOLBAR; 249 if (EQ (position, Qright)) return RIGHT_TOOLBAR;
250 signal_simple_error ("Invalid toolbar position", position); 250 signal_simple_error ("Invalid toolbar position", position);
251 251
252 return TOP_TOOLBAR; /* not reached */ 252 return TOP_TOOLBAR; /* not reached */
253 } 253 }
254 254
255 DEFUN ("set-default-toolbar-position", Fset_default_toolbar_position, 1, 1, 0, /* 255 DEFUN ("set-default-toolbar-position", Fset_default_toolbar_position, 1, 1, 0, /*
256 Set the position that the `default-toolbar' will be displayed at. 256 Set the position that the `default-toolbar' will be displayed at.
302 Lisp_Object desc, int pushright) 302 Lisp_Object desc, int pushright)
303 { 303 {
304 Lisp_Object *elt, glyphs, retval, buffer; 304 Lisp_Object *elt, glyphs, retval, buffer;
305 struct gcpro gcpro1, gcpro2; 305 struct gcpro gcpro1, gcpro2;
306 306
307 elt = vector_data (XVECTOR (desc)); 307 elt = XVECTOR_DATA (desc);
308 buffer = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer; 308 buffer = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
309 309
310 if (!tb) 310 if (!tb)
311 { 311 {
312 tb = alloc_lcrecord (sizeof (struct toolbar_button), 312 tb = alloc_lcrecord (sizeof (struct toolbar_button),
343 if (KEYWORDP (glyphs)) 343 if (KEYWORDP (glyphs))
344 { 344 {
345 int pos; 345 int pos;
346 int style_seen = 0; 346 int style_seen = 0;
347 int size_seen = 0; 347 int size_seen = 0;
348 int len = XVECTOR_LENGTH (desc);
348 349
349 if (!tb->blank) 350 if (!tb->blank)
350 { 351 {
351 tb->blank = 1; 352 tb->blank = 1;
352 tb->dirty = 1; 353 tb->dirty = 1;
353 } 354 }
354 355
355 for (pos = 0; pos < vector_length (XVECTOR (desc)); pos += 2) 356 for (pos = 0; pos < len; pos += 2)
356 { 357 {
357 Lisp_Object key = elt[pos]; 358 Lisp_Object key = elt[pos];
358 Lisp_Object val = elt[pos + 1]; 359 Lisp_Object val = elt[pos + 1];
359 360
360 if (EQ (key, Q_style)) 361 if (EQ (key, Q_style))
727 buttons = Qnil; 728 buttons = Qnil;
728 729
729 FRAME_TOOLBAR_DATA (f, pos)->last_toolbar_buffer = buffer; 730 FRAME_TOOLBAR_DATA (f, pos)->last_toolbar_buffer = buffer;
730 FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons = buttons; 731 FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons = buttons;
731 732
732 return (visible); 733 return visible;
733 } 734 }
734 735
735 #define COMPUTE_TOOLBAR_DATA(position) \ 736 #define COMPUTE_TOOLBAR_DATA(position) \
736 do \ 737 do \
737 { \ 738 { \
919 { \ 920 { \
920 get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 0); \ 921 get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 0); \
921 if ((x_coord >= x) && (x_coord < (x + width))) \ 922 if ((x_coord >= x) && (x_coord < (x + width))) \
922 { \ 923 { \
923 if ((y_coord >= y) && (y_coord < (y + height))) \ 924 if ((y_coord >= y) && (y_coord < (y + height))) \
924 { \ 925 return FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; \
925 return (FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons); \
926 } \
927 } \ 926 } \
928 } while (0) 927 } while (0)
929 928
930 static Lisp_Object 929 static Lisp_Object
931 toolbar_buttons_at_pixpos (struct frame *f, int x_coord, int y_coord) 930 toolbar_buttons_at_pixpos (struct frame *f, int x_coord, int y_coord)
1043 int len; 1042 int len;
1044 Error_behavior errb = decode_error_behavior_flag (no_error); 1043 Error_behavior errb = decode_error_behavior_flag (no_error);
1045 1044
1046 if (!VECTORP (button)) 1045 if (!VECTORP (button))
1047 CTB_ERROR ("toolbar button descriptors must be vectors"); 1046 CTB_ERROR ("toolbar button descriptors must be vectors");
1048 elt = vector_data (XVECTOR (button)); 1047 elt = XVECTOR_DATA (button);
1049 1048
1050 if (vector_length (XVECTOR (button)) == 2) 1049 if (XVECTOR_LENGTH (button) == 2)
1051 { 1050 {
1052 if (!EQ (Q_style, check_toolbar_button_keywords (button, elt[0], 1051 if (!EQ (Q_style, check_toolbar_button_keywords (button, elt[0],
1053 elt[1], errb))) 1052 elt[1], errb)))
1054 CTB_ERROR ("must specify toolbar blank style"); 1053 CTB_ERROR ("must specify toolbar blank style");
1055 1054
1056 return Qt; 1055 return Qt;
1057 } 1056 }
1058 1057
1059 if (vector_length (XVECTOR (button)) != 4) 1058 if (XVECTOR_LENGTH (button) != 4)
1060 CTB_ERROR ("toolbar button descriptors must be 2 or 4 long"); 1059 CTB_ERROR ("toolbar button descriptors must be 2 or 4 long");
1061 1060
1062 /* The first element must be a list of glyphs of length 1-6. The 1061 /* The first element must be a list of glyphs of length 1-6. The
1063 first entry is the pixmap for the up state, the second for the 1062 first entry is the pixmap for the up state, the second for the
1064 down state, the third for the disabled state, the fourth for the 1063 down state, the third for the disabled state, the fourth for the
1108 value = elt[0]; 1107 value = elt[0];
1109 1108
1110 len = XINT (Flength (value)); 1109 len = XINT (Flength (value));
1111 if (len < 1) 1110 if (len < 1)
1112 CTB_ERROR ("toolbar button glyph list must have at least 1 entry"); 1111 CTB_ERROR ("toolbar button glyph list must have at least 1 entry");
1113 1112
1114 if (len > 6) 1113 if (len > 6)
1115 CTB_ERROR ("toolbar button glyph list can have at most 6 entries"); 1114 CTB_ERROR ("toolbar button glyph list can have at most 6 entries");
1116 1115
1117 glyphs = value; 1116 glyphs = value;
1118 while (!NILP (glyphs)) 1117 while (!NILP (glyphs))
1200 and are lists of vectors. See `default-toolbar' for a description 1199 and are lists of vectors. See `default-toolbar' for a description
1201 of the exact format. 1200 of the exact format.
1202 */ 1201 */
1203 (object)) 1202 (object))
1204 { 1203 {
1205 return (TOOLBAR_SPECIFIERP (object) ? Qt : Qnil); 1204 return TOOLBAR_SPECIFIERP (object) ? Qt : Qnil;
1206 } 1205 }
1207 1206
1208 1207
1209 static void 1208 static void
1210 toolbar_specs_changed (Lisp_Object specifier, struct window *w, 1209 toolbar_specs_changed (Lisp_Object specifier, struct window *w,
1345 1344
1346 void 1345 void
1347 specifier_vars_of_toolbar (void) 1346 specifier_vars_of_toolbar (void)
1348 { 1347 {
1349 Lisp_Object elt; 1348 Lisp_Object elt;
1350 1349
1351 DEFVAR_SPECIFIER ("default-toolbar", &Vdefault_toolbar /* 1350 DEFVAR_SPECIFIER ("default-toolbar", &Vdefault_toolbar /*
1352 Specifier for a fallback toolbar. 1351 Specifier for a fallback toolbar.
1353 Use `set-specifier' to change this. 1352 Use `set-specifier' to change this.
1354 1353
1355 The position of this toolbar is specified in the function 1354 The position of this toolbar is specified in the function