Mercurial > hg > xemacs-beta
comparison lwlib/xlwmenu.c @ 12:bcdc7deadc19 r19-15b7
Import from CVS: tag r19-15b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:48:16 +0200 |
parents | ac2d302a0011 |
children | 9ee227acff29 |
comparison
equal
deleted
inserted
replaced
11:91ffe8bd52e4 | 12:bcdc7deadc19 |
---|---|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with GNU Emacs; see the file COPYING. If not, write to | 18 along with XEmacs; see the file COPYING. If not, write to |
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 Boston, MA 02111-1307, USA. */ | |
20 | 21 |
21 /* Created by devin@lucid.com */ | 22 /* Created by devin@lucid.com */ |
22 | 23 |
23 #include <stdlib.h> | 24 #include <stdlib.h> |
24 #include <unistd.h> | 25 #include <unistd.h> |
25 #include <string.h> | 26 #include <string.h> |
26 #include <ctype.h> | 27 #include <ctype.h> |
27 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <limits.h> | |
28 | 30 |
29 #include <sys/types.h> | 31 #include <sys/types.h> |
30 #include <X11/Xos.h> | 32 #include <X11/Xos.h> |
31 #include <X11/IntrinsicP.h> | 33 #include <X11/IntrinsicP.h> |
32 #include <X11/StringDefs.h> | 34 #include <X11/StringDefs.h> |
51 { | 53 { |
52 #ifdef NEED_MOTIF | 54 #ifdef NEED_MOTIF |
53 /* There are three font list resources, so that we can accept either of | 55 /* There are three font list resources, so that we can accept either of |
54 the resources *fontList: or *font:, and so that we can tell the | 56 the resources *fontList: or *font:, and so that we can tell the |
55 difference between them being specified, and being defaulted to a | 57 difference between them being specified, and being defaulted to a |
56 font from the XtRString specified here. | 58 font from the XtRString specified here. */ |
57 */ | |
58 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), | 59 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), |
59 offset(menu.font_list), XtRImmediate, (XtPointer)0}, | 60 offset(menu.font_list), XtRImmediate, (XtPointer)0}, |
60 {XtNfont, XtCFont, XmRFontList, sizeof(XmFontList), | 61 {XtNfont, XtCFont, XmRFontList, sizeof(XmFontList), |
61 offset(menu.font_list_2),XtRImmediate, (XtPointer)0}, | 62 offset(menu.font_list_2),XtRImmediate, (XtPointer)0}, |
62 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), | 63 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), |
63 offset(menu.fallback_font_list), | 64 offset(menu.fallback_font_list), |
64 /* We must use an iso8859-1 font here, or people without $LANG set lose. | 65 /* We must use an iso8859-1 font here, or people without $LANG set lose. |
65 It's fair to assume that those who do have $LANG set also have the | 66 It's fair to assume that those who do have $LANG set also have the |
66 *fontList resource set, or at least know how to deal with this. | 67 *fontList resource set, or at least know how to deal with this. */ |
67 */ | 68 XtRString, "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, |
68 XtRString, (String) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, | |
69 #else | 69 #else |
70 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | 70 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), |
71 offset(menu.font), XtRString, "XtDefaultFont"}, | 71 offset(menu.font), XtRString, "XtDefaultFont"}, |
72 #endif | 72 #endif |
73 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), | 73 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), |
74 offset(menu.foreground), XtRString, (String) "XtDefaultForeground"}, | 74 offset(menu.foreground), XtRString, "XtDefaultForeground"}, |
75 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), | 75 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), |
76 offset(menu.button_foreground), XtRString, (String)"XtDefaultForeground"}, | 76 offset(menu.button_foreground), XtRString, "XtDefaultForeground"}, |
77 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension), | 77 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension), |
78 offset(menu.margin), XtRImmediate, (XtPointer)2}, | 78 offset(menu.margin), XtRImmediate, (XtPointer)2}, |
79 {XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension, sizeof(Dimension), | 79 {XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension, sizeof(Dimension), |
80 offset(menu.horizontal_margin), XtRImmediate, (XtPointer)2}, | 80 offset(menu.horizontal_margin), XtRImmediate, (XtPointer)2}, |
81 {XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension, sizeof(Dimension), | 81 {XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension, sizeof(Dimension), |
137 #endif | 137 #endif |
138 | 138 |
139 static XtActionsRec | 139 static XtActionsRec |
140 xlwMenuActionsList [] = | 140 xlwMenuActionsList [] = |
141 { | 141 { |
142 {(String) "start", Start}, | 142 {"start", Start}, |
143 {(String) "drag", Drag}, | 143 {"drag", Drag}, |
144 {(String) "select", Select}, | 144 {"select", Select}, |
145 }; | 145 }; |
146 | 146 |
147 #define SuperClass ((CoreWidgetClass)&coreClassRec) | 147 #define SuperClass ((CoreWidgetClass)&coreClassRec) |
148 | 148 |
149 XlwMenuClassRec xlwMenuClassRec = | 149 XlwMenuClassRec xlwMenuClassRec = |
150 { | 150 { |
151 { /* CoreClass fields initialization */ | 151 { /* CoreClass fields initialization */ |
152 (WidgetClass) SuperClass, /* superclass */ | 152 (WidgetClass) SuperClass, /* superclass */ |
153 (String) "XlwMenu", /* class_name */ | 153 "XlwMenu", /* class_name */ |
154 sizeof(XlwMenuRec), /* size */ | 154 sizeof(XlwMenuRec), /* size */ |
155 XlwMenuClassInitialize, /* class_initialize */ | 155 XlwMenuClassInitialize, /* class_initialize */ |
156 NULL, /* class_part_initialize */ | 156 NULL, /* class_part_initialize */ |
157 FALSE, /* class_inited */ | 157 FALSE, /* class_inited */ |
158 XlwMenuInitialize, /* initialize */ | 158 XlwMenuInitialize, /* initialize */ |
172 XlwMenuRedisplay, /* expose */ | 172 XlwMenuRedisplay, /* expose */ |
173 XlwMenuSetValues, /* set_values */ | 173 XlwMenuSetValues, /* set_values */ |
174 NULL, /* set_values_hook */ | 174 NULL, /* set_values_hook */ |
175 XtInheritSetValuesAlmost, /* set_values_almost */ | 175 XtInheritSetValuesAlmost, /* set_values_almost */ |
176 NULL, /* get_values_hook */ | 176 NULL, /* get_values_hook */ |
177 NULL, /* #### - should this be set for grabs? accept_focus */ | 177 NULL, /* #### - should this be set for */ |
178 /* grabs? accept_focus */ | |
178 XtVersion, /* version */ | 179 XtVersion, /* version */ |
179 NULL, /* callback_private */ | 180 NULL, /* callback_private */ |
180 xlwMenuTranslations, /* tm_table */ | 181 xlwMenuTranslations, /* tm_table */ |
181 XtInheritQueryGeometry, /* query_geometry */ | 182 XtInheritQueryGeometry, /* query_geometry */ |
182 XtInheritDisplayAccelerator, /* display_accelerator */ | 183 XtInheritDisplayAccelerator, /* display_accelerator */ |
211 | 212 |
212 static int | 213 static int |
213 allocate_nearest_color (Display *display, Colormap screen_colormap, | 214 allocate_nearest_color (Display *display, Colormap screen_colormap, |
214 XColor *color_def) | 215 XColor *color_def) |
215 { | 216 { |
216 int status; | 217 int status = XAllocColor (display, screen_colormap, color_def); |
217 | 218 if (status) |
218 status = XAllocColor (display, screen_colormap, color_def); | 219 return status; |
219 if (!status) | 220 |
220 { | 221 { |
221 /* If we got to this point, the colormap is full, so we're | 222 /* If we got to this point, the colormap is full, so we're |
222 going to try and get the next closest color. | 223 going to try to get the next closest color. |
223 The algorithm used is a least-squares matching, which is | 224 The algorithm used is a least-squares matching, which is |
224 what X uses for closest color matching with StaticColor visuals. */ | 225 what X uses for closest color matching with StaticColor visuals. */ |
225 | 226 |
226 XColor *cells; | 227 int nearest, x; |
227 int no_cells; | 228 unsigned long nearest_delta = ULONG_MAX; |
228 int nearest; | 229 |
229 long nearest_delta, trial_delta; | 230 int no_cells = XDisplayCells (display, XDefaultScreen (display)); |
230 int x; | |
231 | |
232 no_cells = XDisplayCells (display, XDefaultScreen (display)); | |
233 /* Don't use alloca here because lwlib doesn't have the | 231 /* Don't use alloca here because lwlib doesn't have the |
234 necessary configuration information that src does. */ | 232 necessary configuration information that src does. */ |
235 cells = (XColor *) malloc (sizeof (XColor) * no_cells); | 233 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); |
236 | 234 |
237 for (x = 0; x < no_cells; x++) | 235 for (x = 0; x < no_cells; x++) |
238 cells[x].pixel = x; | 236 cells[x].pixel = x; |
239 | 237 |
240 XQueryColors (display, screen_colormap, cells, no_cells); | 238 XQueryColors (display, screen_colormap, cells, no_cells); |
241 nearest = 0; | 239 |
242 /* I'm assuming CSE so I'm not going to condense this. */ | 240 for (nearest = 0, x = 0; x < no_cells; x++) |
243 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8)) | |
244 * ((color_def->red >> 8) - (cells[0].red >> 8))) | |
245 + | |
246 (((color_def->green >> 8) - (cells[0].green >> 8)) | |
247 * ((color_def->green >> 8) - (cells[0].green >> 8))) | |
248 + | |
249 (((color_def->blue >> 8) - (cells[0].blue >> 8)) | |
250 * ((color_def->blue >> 8) - (cells[0].blue >> 8)))); | |
251 for (x = 1; x < no_cells; x++) | |
252 { | 241 { |
253 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8)) | 242 long dred = (color_def->red >> 8) - (cells[x].red >> 8); |
254 * ((color_def->red >> 8) - (cells[x].red >> 8))) | 243 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); |
255 + | 244 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); |
256 (((color_def->green >> 8) - (cells[x].green >> 8)) | 245 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; |
257 * ((color_def->green >> 8) - (cells[x].green >> 8))) | 246 |
258 + | 247 if (delta < nearest_delta) |
259 (((color_def->blue >> 8) - (cells[x].blue >> 8)) | |
260 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); | |
261 if (trial_delta < nearest_delta) | |
262 { | 248 { |
263 nearest = x; | 249 nearest = x; |
264 nearest_delta = trial_delta; | 250 nearest_delta = delta; |
265 } | 251 } |
266 } | 252 } |
267 color_def->red = cells[nearest].red; | 253 color_def->red = cells[nearest].red; |
268 color_def->green = cells[nearest].green; | 254 color_def->green = cells[nearest].green; |
269 color_def->blue = cells[nearest].blue; | 255 color_def->blue = cells[nearest].blue; |
270 status = XAllocColor (display, screen_colormap, color_def); | |
271 | 256 |
272 free (cells); | 257 free (cells); |
273 } | 258 return XAllocColor (display, screen_colormap, color_def); |
274 | 259 } |
275 return status; | |
276 } | 260 } |
277 | 261 |
278 static void | 262 static void |
279 push_new_stack (XlwMenuWidget mw, widget_value *val) | 263 push_new_stack (XlwMenuWidget mw, widget_value *val) |
280 { | 264 { |
297 } | 281 } |
298 | 282 |
299 static void | 283 static void |
300 pop_new_stack_if_no_contents (XlwMenuWidget mw) | 284 pop_new_stack_if_no_contents (XlwMenuWidget mw) |
301 { | 285 { |
302 if (mw->menu.new_depth) | 286 if (mw->menu.new_depth && |
303 { | 287 !mw->menu.new_stack [mw->menu.new_depth - 1]->contents) |
304 if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents) | 288 mw->menu.new_depth -= 1; |
305 { | |
306 mw->menu.new_depth -= 1; | |
307 } | |
308 } | |
309 } | 289 } |
310 | 290 |
311 static void | 291 static void |
312 make_old_stack_space (XlwMenuWidget mw, int n) | 292 make_old_stack_space (XlwMenuWidget mw, int n) |
313 { | 293 { |
418 } | 398 } |
419 | 399 |
420 static XtResource | 400 static XtResource |
421 nameResource[] = | 401 nameResource[] = |
422 { | 402 { |
423 { (String) "labelString", (String) "LabelString", XtRString, sizeof(String), | 403 { "labelString", "LabelString", XtRString, sizeof(String), |
424 0, XtRImmediate, 0 } | 404 0, XtRImmediate, 0 } |
425 }; | 405 }; |
426 | 406 |
427 /* | 407 /* |
428 * This function looks through string searching for parameter | 408 * This function looks through string searching for parameter |