Mercurial > hg > xemacs-beta
comparison lwlib/xlwmenu.c @ 78:c7528f8e288d r20-0b34
Import from CVS: tag r20-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:05:42 +0200 |
parents | 131b0175ea99 |
children | 1ce6082ce73f |
comparison
equal
deleted
inserted
replaced
77:6cb4f478e7bc | 78:c7528f8e288d |
---|---|
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 and 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 = | |
244 ((((color_def->red >> 8) - (cells[0].red >> 8)) | |
245 * ((color_def->red >> 8) - (cells[0].red >> 8))) | |
246 + | |
247 (((color_def->green >> 8) - (cells[0].green >> 8)) | |
248 * ((color_def->green >> 8) - (cells[0].green >> 8))) | |
249 + | |
250 (((color_def->blue >> 8) - (cells[0].blue >> 8)) | |
251 * ((color_def->blue >> 8) - (cells[0].blue >> 8)))); | |
252 for (x = 1; x < no_cells; x++) | |
253 { | 241 { |
254 trial_delta = | 242 long dred = (color_def->red >> 8) - (cells[x].red >> 8); |
255 ((((color_def->red >> 8) - (cells[x].red >> 8)) | 243 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); |
256 * ((color_def->red >> 8) - (cells[x].red >> 8))) | 244 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); |
257 + | 245 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; |
258 (((color_def->green >> 8) - (cells[x].green >> 8)) | 246 |
259 * ((color_def->green >> 8) - (cells[x].green >> 8))) | 247 if (delta < nearest_delta) |
260 + | |
261 (((color_def->blue >> 8) - (cells[x].blue >> 8)) | |
262 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); | |
263 if (trial_delta < nearest_delta) | |
264 { | 248 { |
265 nearest = x; | 249 nearest = x; |
266 nearest_delta = trial_delta; | 250 nearest_delta = delta; |
267 } | 251 } |
268 } | 252 } |
269 color_def->red = cells[nearest].red; | 253 color_def->red = cells[nearest].red; |
270 color_def->green = cells[nearest].green; | 254 color_def->green = cells[nearest].green; |
271 color_def->blue = cells[nearest].blue; | 255 color_def->blue = cells[nearest].blue; |
272 status = XAllocColor (display, screen_colormap, color_def); | |
273 | 256 |
274 free (cells); | 257 free (cells); |
275 } | 258 return XAllocColor (display, screen_colormap, color_def); |
276 | 259 } |
277 return status; | |
278 } | 260 } |
279 | 261 |
280 static void | 262 static void |
281 push_new_stack (XlwMenuWidget mw, widget_value *val) | 263 push_new_stack (XlwMenuWidget mw, widget_value *val) |
282 { | 264 { |
423 } | 405 } |
424 | 406 |
425 static XtResource | 407 static XtResource |
426 nameResource[] = | 408 nameResource[] = |
427 { | 409 { |
428 { (String) "labelString", (String) "LabelString", XtRString, sizeof(String), | 410 { "labelString", "LabelString", XtRString, sizeof(String), |
429 0, XtRImmediate, 0 } | 411 0, XtRImmediate, 0 } |
430 }; | 412 }; |
431 | 413 |
432 /* | 414 /* |
433 * This function looks through string searching for parameter | 415 * This function looks through string searching for parameter |