Mercurial > vim
annotate src/gui_xmebw.c @ 20170:0612c64a2b87 v8.2.0640
patch 8.2.0640: Vim9: expanding does not work
Commit: https://github.com/vim/vim/commit/cfe435d7feacf123ac060747b885f7c4328062ea
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 25 20:02:55 2020 +0200
patch 8.2.0640: Vim9: expanding does not work
Problem: Vim9: expanding does not work.
Solution: Find wildcards in not compiled commands. Reorganize test files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 25 Apr 2020 20:15:03 +0200 |
parents | e1f4e9d78a6a |
children | 49d866e9b439 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
48 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * | |
11 * (C) 2002,2005 by Marcin Dalecki <martin@dalecki.de> | |
12 * | |
13 * MARCIN DALECKI ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE ANY | |
14 * OF THIS SOFTWARE . THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | |
15 * KIND, AND MARCIN DALECKI EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, | |
16 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
17 * FITNESS FOR A PARTICULAR PURPOSE. | |
18 */ | |
19 | |
20 /* | |
158 | 21 * Enhanced Motif PushButton widget with move over behavior. |
48 | 22 */ |
23 | |
158 | 24 #include "vim.h" |
25 | |
26 #ifdef FEAT_TOOLBAR | |
48 | 27 |
28 #include <Xm/XmP.h> | |
29 #include <Xm/DrawP.h> | |
147 | 30 #if defined(HAVE_XM_TRAITP_H) && defined(HAVE_XM_MANAGER_H) \ |
819 | 31 && defined(HAVE_XM_UNHIGHLIGHTT_H) && defined(HAVE_XM_XPMP_H) |
48 | 32 # include <Xm/TraitP.h> |
33 # include <Xm/Manager.h> | |
34 # include <Xm/UnhighlightT.h> | |
35 # include <Xm/XpmP.h> | |
147 | 36 # define UNHIGHLIGHTT |
48 | 37 #else |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
38 # ifdef HAVE_X11_XPM_H |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
39 # ifdef VMS |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
40 # include <xpm.h> |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
41 # else |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
42 # include <X11/xpm.h> |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
43 # endif |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
44 # endif |
48 | 45 #endif |
46 #include <Xm/ManagerP.h> | |
47 #include <Xm/Display.h> | |
48 #include <Xm/DisplayP.h> | |
49 | |
50 #include <X11/Shell.h> | |
51 #include <X11/ShellP.h> | |
52 | |
53 #include "gui_xmebwp.h" | |
54 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
55 // Provide some missing wrappers, which are missed from the LessTif |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
56 // implementation. Also missing in Motif 1.2 and earlier. |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
57 // |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
58 // We neither use XmeGetPixmapData or _XmGetPixmapData, since with LessTif the |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
59 // pixmap will not appear in its caches properly. We cache the interesting |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
60 // values in XmEnhancedButtonPart instead ourself. |
891 | 61 #if defined(LESSTIF_VERSION) || (XmVersion <= 1002) |
48 | 62 # ifndef Lab_IsMenupane |
63 # define Lab_IsMenupane(w) (Lab_MenuType(w) == (int)XmMENU_POPUP || \ | |
64 Lab_MenuType(w) == (int)XmMENU_PULLDOWN) | |
65 # endif | |
66 # define XmeClearBorder _XmClearBorder | |
67 # define XmeDrawShadows _XmDrawShadows | |
68 # define XmeDrawHighlight(a, b, c, d, e, f, g, h) \ | |
69 _XmDrawHighlight(a, b, c, d, e, f, g, h, LineSolid) | |
70 #endif | |
71 | |
72 /* | |
73 * Motif internals we have to cheat around with. | |
74 */ | |
75 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
76 // Hopefully this will never change... |
48 | 77 #ifndef XmFOCUS_IGNORE |
78 # define XmFOCUS_IGNORE 1<<1 | |
79 #endif | |
80 | |
81 extern Boolean _XmGetInDragMode(Widget widget); | |
82 extern void _XmPrimitiveEnter(Widget wid, | |
83 XEvent * event, | |
84 String * params, Cardinal * num_params); | |
85 extern void _XmPrimitiveLeave(Widget wid, | |
86 XEvent * event, | |
87 String * params, Cardinal * num_params); | |
88 extern void _XmSetFocusFlag(Widget w, unsigned int mask, Boolean value); | |
89 extern void _XmCalcLabelDimensions(Widget wid); | |
90 | |
91 /* | |
92 * Declaration of class methods. | |
93 */ | |
94 static void Destroy(Widget w); | |
95 static void Initialize(Widget rq, Widget eb, ArgList args, Cardinal *n); | |
96 static Boolean SetValues(Widget current, Widget request, Widget new, ArgList args, Cardinal *n); | |
97 static void Redisplay(Widget, XEvent *, Region); | |
98 | |
99 /* | |
100 * Declaration of action methods. | |
101 */ | |
102 static void Enter(Widget, XEvent *, String *, Cardinal *); | |
103 static void Leave(Widget, XEvent *, String *, Cardinal *); | |
104 static void BorderHighlight(Widget); | |
105 static void BorderUnhighlight(Widget); | |
106 | |
107 /* | |
108 * 4 x 4 stipple for desensitized widgets | |
109 */ | |
110 #define stipple_width 4 | |
111 #define stipple_height 4 | |
112 static char stipple_bits[] = { 0x0a, 0x05, 0x0a, 0x05 }; | |
113 #define STIPPLE_BITMAP xmEnhancedButtonClassRec.enhancedbutton_class.stipple_bitmap | |
114 | |
115 /* | |
116 * Override actions. | |
117 */ | |
118 static XtActionsRec actionsList[] = | |
119 { | |
120 {"Enter", Enter}, | |
121 {"Leave", Leave}, | |
122 }; | |
123 | |
124 static XtResource resources[] = | |
125 { | |
126 { | |
127 XmNpixmapData, XmCPixmap, XmRString, sizeof(String), | |
128 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.pixmap_data), | |
129 XmRImmediate, (XtPointer) NULL | |
130 }, { | |
131 XmNpixmapFile, XmCPixmap, XmRString, sizeof(String), | |
132 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.pixmap_file), | |
133 XmRImmediate, (XtPointer) NULL | |
134 }, { | |
135 XmNspacing, XmCSpacing, XmRHorizontalDimension, sizeof(Dimension), | |
136 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.spacing), | |
137 XmRImmediate, (XtPointer) 2 | |
138 }, | |
139 { | |
140 XmNlabelLocation, XmCLocation, XmRInt, sizeof(int), | |
141 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.label_location), | |
142 XtRImmediate, (XtPointer) XmRIGHT | |
143 } | |
144 }; | |
145 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
146 // This is needed to work around a bug in Lesstif 2, leaving the extension |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
147 // NULL somehow results in getting it set to an invalid pointer. |
1026 | 148 XmPrimitiveClassExtRec xmEnhancedButtonPrimClassExtRec = |
149 { | |
150 /* next_extension */ NULL, | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
151 /* record_type */ NULLQUARK, |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
152 /* version */ XmPrimitiveClassExtVersion, |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
153 /* record_size */ sizeof(XmPrimitiveClassExtRec), |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
154 /* widget_baseline */ XmInheritBaselineProc, |
1026 | 155 /* widget_display_rect */ XmInheritDisplayRectProc, |
156 /* widget_margins */ NULL | |
157 }; | |
158 | |
48 | 159 XmEnhancedButtonClassRec xmEnhancedButtonClassRec = |
160 { | |
161 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
162 // core_class fields |
856 | 163 /* superclass */ (WidgetClass) & xmPushButtonClassRec, |
164 /* class_name */ "XmEnhancedButton", | |
165 /* widget_size */ sizeof(XmEnhancedButtonRec), | |
166 /* class_initialize */ NULL, | |
48 | 167 /* class_part_initialize */ NULL, |
856 | 168 /* class_inited */ False, |
169 /* initialize */ Initialize, | |
170 /* initialize_hook */ NULL, | |
171 /* realize */ XtInheritRealize, | |
172 /* actions */ actionsList, | |
173 /* num_actions */ XtNumber(actionsList), | |
174 /* resources */ resources, | |
175 /* num_resources */ XtNumber(resources), | |
176 /* xrm_class */ NULLQUARK, | |
177 /* compress_motion */ True, | |
178 /* compress_exposure */ XtExposeCompressMaximal, | |
179 /* compress_enterleave */ True, | |
180 /* visible_interest */ False, | |
181 /* destroy */ Destroy, | |
182 /* resize */ XtInheritResize, | |
183 /* expose */ Redisplay, | |
184 /* set_values */ SetValues, | |
185 /* set_values_hook */ NULL, | |
186 /* set_values_almost */ XtInheritSetValuesAlmost, | |
187 /* get_values_hook */ NULL, | |
188 /* accept_focus */ XtInheritAcceptFocus, | |
189 /* version */ XtVersion, | |
190 /* callback_private */ NULL, | |
191 /* tm_table */ NULL, | |
192 /* query_geometry */ NULL, | |
193 /* display_accelerator */ XtInheritDisplayAccelerator, | |
194 /* extension */ NULL | |
48 | 195 }, |
196 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
197 // primitive_class fields |
48 | 198 { |
856 | 199 /* border highlight */ BorderHighlight, |
200 /* border_unhighlight */ BorderUnhighlight, | |
201 /* translations */ XtInheritTranslations, | |
202 /* arm and activate */ XmInheritArmAndActivate, | |
203 /* synthetic resources */ NULL, | |
204 /* number of syn res */ 0, | |
1026 | 205 /* extension */ (XtPointer)&xmEnhancedButtonPrimClassExtRec, |
48 | 206 }, |
207 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
208 // label_class fields |
48 | 209 { |
856 | 210 /* setOverrideCallback */ XmInheritSetOverrideCallback, |
211 /* menuProcs */ XmInheritMenuProc, | |
212 /* translations */ XtInheritTranslations, | |
48 | 213 /* extension */ NULL, |
214 }, | |
215 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
216 // pushbutton_class record |
48 | 217 { |
218 /* extension */ (XtPointer) NULL, | |
219 }, | |
220 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
221 // enhancedbutton_class fields |
48 | 222 { |
223 /* stipple_bitmap */ None | |
224 } | |
225 }; | |
226 | |
227 | |
228 WidgetClass xmEnhancedButtonWidgetClass = | |
229 (WidgetClass)&xmEnhancedButtonClassRec; | |
230 | |
231 | |
232 /* | |
233 * Create a slightly fainter pixmap to be shown on button entry. | |
234 */ | |
235 static unsigned short | |
236 bump_color(unsigned short value) | |
237 { | |
238 int tmp = 2 * (((int) value - 65535) / 3) + 65535; | |
239 | |
240 return tmp; | |
241 } | |
242 | |
243 static int | |
244 alloc_color(Display *display, | |
245 Colormap colormap, | |
246 char *colorname, | |
247 XColor *xcolor, | |
1887 | 248 void *closure UNUSED) |
48 | 249 { |
250 int status; | |
251 | |
252 if (colorname) | |
253 if (!XParseColor(display, colormap, colorname, xcolor)) | |
254 return -1; | |
255 | |
256 xcolor->red = bump_color(xcolor->red); | |
257 xcolor->green = bump_color(xcolor->green); | |
258 xcolor->blue = bump_color(xcolor->blue); | |
259 | |
260 status = XAllocColor(display, colormap, xcolor); | |
261 return status != 0 ? 1 : 0; | |
262 } | |
263 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
264 // XPM |
48 | 265 static char * blank_xpm[] = |
266 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
267 // width height ncolors cpp [x_hot y_hot] |
48 | 268 "12 12 4 1 0 0", |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
269 // colors |
48 | 270 " s iconColor1 m black c #000000", |
271 ". s none m none c none", | |
272 "X s topShadowColor m none c #DCDEE5", | |
273 "o s bottomShadowColor m black c #5D6069", | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
274 // pixels |
48 | 275 " ..", |
276 " XXXXXXXX ..", | |
277 " X....... o.", | |
278 " X....... o.", | |
279 " X....... o.", | |
280 " X....... o.", | |
281 " X....... o.", | |
282 " X....... o.", | |
283 " X....... o.", | |
284 " o.", | |
285 "..ooooooooo.", | |
286 "............"}; | |
287 | |
288 /* | |
289 * Set the pixmap. | |
290 */ | |
291 static void | |
292 set_pixmap(XmEnhancedButtonWidget eb) | |
293 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
294 // Configure defines XPMATTRIBUTES_TYPE as XpmAttributes or as |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
295 // XpmAttributes_21, depending on what is in Xm/XpmP.h. |
819 | 296 XPMATTRIBUTES_TYPE attr; |
48 | 297 Pixmap sen_pix; |
298 Window root; | |
299 static XpmColorSymbol color[8] = { | |
300 {"none", "none", 0}, | |
301 {"None", "none", 0}, | |
302 {"background", NULL, 0}, | |
303 {"foreground", NULL, 0}, | |
304 {"bottomShadowColor", NULL, 0}, | |
305 {"topShadowColor", NULL, 0}, | |
306 {"highlightColor", NULL, 0}, | |
307 {"armColor", NULL, 0} | |
308 }; | |
309 int scr; | |
310 Display *dpy = XtDisplay(eb); | |
311 int x; | |
312 int y; | |
313 unsigned int height, width, border, depth; | |
161 | 314 int status = 0; |
48 | 315 Pixmap mask; |
316 Pixmap pix = None; | |
317 Pixmap arm_pix = None; | |
318 Pixmap ins_pix = None; | |
319 Pixmap high_pix = None; | |
320 char **data = (char **) eb->enhancedbutton.pixmap_data; | |
161 | 321 char *fname = (char *) eb->enhancedbutton.pixmap_file; |
48 | 322 int shift; |
323 GC gc; | |
324 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
325 // Make sure there is a default value for the pixmap. |
48 | 326 if (!data) |
327 return; | |
328 | |
329 gc = XtGetGC((Widget)eb, (XtGCMask)0, NULL); | |
330 | |
331 scr = DefaultScreen(dpy); | |
332 root = RootWindow(dpy, scr); | |
333 | |
334 eb->label.pixmap = None; | |
161 | 335 |
48 | 336 eb->enhancedbutton.pixmap_depth = 0; |
337 eb->enhancedbutton.pixmap_width = 0; | |
338 eb->enhancedbutton.pixmap_height = 0; | |
339 eb->enhancedbutton.normal_pixmap = None; | |
340 eb->enhancedbutton.armed_pixmap = None; | |
341 eb->enhancedbutton.highlight_pixmap = None; | |
342 eb->enhancedbutton.insensitive_pixmap = None; | |
343 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
344 // We use dynamic colors, get them now. |
161 | 345 motif_get_toolbar_colors( |
346 &eb->core.background_pixel, | |
347 &eb->primitive.foreground, | |
348 &eb->primitive.bottom_shadow_color, | |
349 &eb->primitive.top_shadow_color, | |
350 &eb->primitive.highlight_color); | |
351 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
352 // Setup color substitution table. |
48 | 353 color[0].pixel = eb->core.background_pixel; |
354 color[1].pixel = eb->core.background_pixel; | |
355 color[2].pixel = eb->core.background_pixel; | |
356 color[3].pixel = eb->primitive.foreground; | |
357 color[4].pixel = eb->core.background_pixel; | |
358 color[5].pixel = eb->primitive.top_shadow_color; | |
359 color[6].pixel = eb->primitive.highlight_color; | |
360 color[7].pixel = eb->pushbutton.arm_color; | |
361 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
362 // Create the "sensitive" pixmap. |
48 | 363 attr.valuemask = XpmColorSymbols | XpmCloseness; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
364 attr.closeness = 65535; // accuracy isn't crucial |
48 | 365 attr.colorsymbols = color; |
366 attr.numsymbols = XtNumber(color); | |
367 | |
161 | 368 if (fname) |
369 status = XpmReadFileToPixmap(dpy, root, fname, &pix, &mask, &attr); | |
370 if (!fname || status != XpmSuccess) | |
371 status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); | |
48 | 372 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
373 // If something failed, we will fill in the default pixmap. |
48 | 374 if (status != XpmSuccess) |
375 status = XpmCreatePixmapFromData(dpy, root, blank_xpm, &pix, | |
376 &mask, &attr); | |
377 | |
378 XpmFreeAttributes(&attr); | |
379 | |
380 XGetGeometry(dpy, pix, &root, &x, &y, &width, &height, &border, &depth); | |
381 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
382 // TODO: does the shift depend on label_location somehow? |
3624 | 383 shift = eb->primitive.shadow_thickness / 2; |
48 | 384 |
385 if (shift < 1) | |
386 shift = 1; | |
387 | |
388 sen_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
389 | |
390 XSetForeground(dpy, gc, eb->core.background_pixel); | |
391 XFillRectangle(dpy, sen_pix, gc, 0, 0, width + shift, height + shift); | |
392 XSetClipMask(dpy, gc, mask); | |
393 XSetClipOrigin(dpy, gc, shift, shift); | |
394 XCopyArea(dpy, pix, sen_pix, gc, 0, 0, width, height, shift, shift); | |
395 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
396 // Create the "highlight" pixmap. |
48 | 397 color[4].pixel = eb->primitive.bottom_shadow_color; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
398 #ifdef XpmAllocColor // SGI doesn't have it |
48 | 399 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmAllocColor; |
1438 | 400 attr.alloc_color = alloc_color; |
401 #else | |
402 attr.valuemask = XpmColorSymbols | XpmCloseness; | |
403 #endif | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
404 attr.closeness = 65535; // accuracy isn't crucial |
48 | 405 attr.colorsymbols = color; |
406 attr.numsymbols = XtNumber(color); | |
407 | |
408 status = XpmCreatePixmapFromData(dpy, root, data, &pix, NULL, &attr); | |
409 XpmFreeAttributes(&attr); | |
410 | |
411 high_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
412 | |
413 #if 1 | |
414 XSetForeground(dpy, gc, eb->core.background_pixel); | |
415 #else | |
416 XSetForeground(dpy, gc, eb->primitive.top_shadow_color); | |
417 #endif | |
418 XSetClipMask(dpy, gc, None); | |
419 XFillRectangle(dpy, high_pix, gc, 0, 0, width + shift, height + shift); | |
420 XSetClipMask(dpy, gc, mask); | |
421 XSetClipOrigin(dpy, gc, 0, 0); | |
422 XCopyArea(dpy, pix, high_pix, gc, 0, 0, width, height, 0, 0); | |
423 | |
424 arm_pix = XCreatePixmap(dpy, pix, width + shift, height + shift, depth); | |
425 | |
426 if (eb->pushbutton.fill_on_arm) | |
427 XSetForeground(dpy, gc, eb->pushbutton.arm_color); | |
428 else | |
429 XSetForeground(dpy, gc, eb->core.background_pixel); | |
430 XSetClipOrigin(dpy, gc, shift, shift); | |
431 XSetClipMask(dpy, gc, None); | |
432 XFillRectangle(dpy, arm_pix, gc, 0, 0, width + shift, height + shift); | |
433 XSetClipMask(dpy, gc, mask); | |
434 XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); | |
435 XCopyArea(dpy, pix, arm_pix, gc, 0, 0, width, height, 2 * shift, 2 * shift); | |
436 | |
437 XFreePixmap(dpy, pix); | |
438 XFreePixmap(dpy, mask); | |
439 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
440 // Create the "insensitive" pixmap. |
48 | 441 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey; |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
442 attr.closeness = 65535; // accuracy isn't crucial |
48 | 443 attr.colorsymbols = color; |
444 attr.numsymbols = sizeof(color) / sizeof(color[0]); | |
445 attr.color_key = XPM_MONO; | |
446 status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); | |
447 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
448 // Need to create new Pixmaps with the mask applied. |
48 | 449 |
450 ins_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
451 | |
452 XSetForeground(dpy, gc, eb->core.background_pixel); | |
453 XSetClipOrigin(dpy, gc, 0, 0); | |
454 XSetClipMask(dpy, gc, None); | |
455 XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); | |
456 XSetClipMask(dpy, gc, mask); | |
457 XSetForeground(dpy, gc, eb->primitive.top_shadow_color); | |
458 XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); | |
459 XFillRectangle(dpy, ins_pix, gc, 2 * shift, 2 * shift, width, height); | |
460 XSetForeground(dpy, gc, eb->primitive.bottom_shadow_color); | |
461 XSetClipOrigin(dpy, gc, shift, shift); | |
462 XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); | |
463 XtReleaseGC((Widget) eb, gc); | |
464 | |
465 XpmFreeAttributes(&attr); | |
466 | |
467 eb->enhancedbutton.pixmap_depth = depth; | |
468 eb->enhancedbutton.pixmap_width = width; | |
469 eb->enhancedbutton.pixmap_height = height; | |
470 eb->enhancedbutton.normal_pixmap = sen_pix; | |
471 eb->enhancedbutton.highlight_pixmap = high_pix; | |
472 eb->enhancedbutton.insensitive_pixmap = ins_pix; | |
473 eb->enhancedbutton.armed_pixmap = arm_pix; | |
474 | |
475 eb->enhancedbutton.doing_setvalues = True; | |
476 eb->enhancedbutton.doing_setvalues = False; | |
477 | |
478 XFreePixmap(dpy, pix); | |
479 XFreePixmap(dpy, mask); | |
480 } | |
481 | |
482 #define BUTTON_MASK ( \ | |
483 Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask \ | |
484 ) | |
485 | |
486 static void | |
487 draw_shadows(XmEnhancedButtonWidget eb) | |
488 { | |
489 GC top_gc; | |
490 GC bottom_gc; | |
491 Boolean etched_in; | |
492 | |
493 if (!eb->primitive.shadow_thickness) | |
494 return; | |
495 | |
496 if ((eb->core.width <= 2 * eb->primitive.highlight_thickness) | |
497 || (eb->core.height <= 2 * eb->primitive.highlight_thickness)) | |
498 return; | |
499 | |
888 | 500 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 501 { |
502 XmDisplay dpy; | |
503 | |
504 dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(eb)); | |
505 etched_in = dpy->display.enable_etched_in_menu; | |
506 } | |
507 #else | |
508 etched_in = False; | |
509 #endif | |
510 if (!etched_in ^ eb->pushbutton.armed) | |
511 { | |
512 top_gc = eb->primitive.top_shadow_GC; | |
513 bottom_gc = eb->primitive.bottom_shadow_GC; | |
514 } | |
515 else | |
516 { | |
517 top_gc = eb->primitive.bottom_shadow_GC; | |
518 bottom_gc = eb->primitive.top_shadow_GC; | |
519 } | |
520 | |
521 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
522 top_gc, | |
523 bottom_gc, | |
524 eb->primitive.highlight_thickness, | |
525 eb->primitive.highlight_thickness, | |
526 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
527 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
528 eb->primitive.shadow_thickness, | |
529 (unsigned)(etched_in ? XmSHADOW_IN : XmSHADOW_OUT)); | |
530 } | |
531 | |
532 static void | |
533 draw_highlight(XmEnhancedButtonWidget eb) | |
534 { | |
535 eb->primitive.highlighted = True; | |
536 eb->primitive.highlight_drawn = True; | |
537 | |
538 if (!XtWidth(eb) || !XtHeight(eb) || !eb->primitive.highlight_thickness) | |
539 return; | |
540 | |
541 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
542 eb->primitive.highlight_GC, 0, 0, | |
543 XtWidth(eb), XtHeight(eb), | |
544 eb->primitive.highlight_thickness); | |
545 } | |
546 | |
547 static void | |
548 draw_unhighlight(XmEnhancedButtonWidget eb) | |
549 { | |
550 GC manager_background_GC; | |
551 | |
552 eb->primitive.highlighted = False; | |
553 eb->primitive.highlight_drawn = False; | |
554 | |
555 if (!XtWidth(eb) || !XtHeight(eb) || !eb->primitive.highlight_thickness) | |
556 return; | |
557 | |
558 if (XmIsManager(eb->core.parent)) | |
559 { | |
147 | 560 #ifdef UNHIGHLIGHTT |
48 | 561 XmSpecifyUnhighlightTrait UnhighlightT; |
562 | |
563 if (((UnhighlightT = (XmSpecifyUnhighlightTrait) XmeTraitGet((XtPointer) | |
564 XtClass(eb->core.parent), XmQTspecifyUnhighlight)) | |
565 != NULL) && (UnhighlightT->getUnhighlightGC != NULL)) | |
566 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
567 // if unhighlight trait in parent use specified GC... |
48 | 568 manager_background_GC = |
569 UnhighlightT->getUnhighlightGC(eb->core.parent, (Widget) eb); | |
570 } | |
571 else | |
572 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
573 // ...otherwise, use parent's background GC |
48 | 574 manager_background_GC = ((XmManagerWidget) |
575 (eb->core.parent))->manager.background_GC; | |
576 } | |
577 #else | |
578 manager_background_GC = ((XmManagerWidget) | |
579 (eb->core.parent))->manager.background_GC; | |
580 #endif | |
581 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
582 manager_background_GC, | |
583 0, 0, XtWidth(eb), XtHeight(eb), | |
584 eb->primitive.highlight_thickness); | |
585 if (!eb->pushbutton.armed && eb->primitive.shadow_thickness) | |
586 XmeClearBorder(XtDisplay(eb), XtWindow(eb), | |
587 eb->primitive.highlight_thickness, | |
588 eb->primitive.highlight_thickness, | |
589 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
590 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
591 eb->primitive.shadow_thickness); | |
592 } | |
593 else | |
594 XmeClearBorder(XtDisplay(eb), XtWindow(eb), 0, 0, XtWidth(eb), | |
595 XtHeight(eb), eb->primitive.highlight_thickness); | |
596 } | |
597 | |
598 static void | |
1887 | 599 draw_pixmap(XmEnhancedButtonWidget eb, |
600 XEvent *event UNUSED, | |
601 Region region UNUSED) | |
48 | 602 { |
603 Pixmap pix; | |
604 GC gc = eb->label.normal_GC; | |
605 int depth; | |
606 Cardinal width; | |
607 Cardinal height; | |
608 Cardinal w; | |
609 Cardinal h; | |
610 int x; | |
611 int y; | |
612 | |
613 if (!XtIsSensitive((Widget) eb)) | |
614 pix = eb->enhancedbutton.insensitive_pixmap; | |
615 else | |
616 { | |
617 if (eb->primitive.highlighted && !eb->pushbutton.armed) | |
618 pix = eb->enhancedbutton.highlight_pixmap; | |
619 else if (eb->pushbutton.armed) | |
620 pix = eb->enhancedbutton.armed_pixmap; | |
621 else | |
622 pix = eb->enhancedbutton.normal_pixmap; | |
623 } | |
624 | |
625 if (pix == None || !eb->enhancedbutton.pixmap_data) | |
626 return; | |
627 | |
628 depth = eb->enhancedbutton.pixmap_depth; | |
629 w = eb->enhancedbutton.pixmap_width; | |
630 h = eb->enhancedbutton.pixmap_height; | |
631 | |
632 gc = eb->label.normal_GC; | |
633 x = eb->primitive.highlight_thickness | |
634 + eb->primitive.shadow_thickness | |
635 + eb->label.margin_width; | |
636 y = eb->primitive.highlight_thickness | |
637 + eb->primitive.shadow_thickness | |
638 + eb->label.margin_height; | |
639 width = eb->core.width - 2 * x; | |
640 if (w < width) | |
641 width = w; | |
642 height = eb->core.height - 2 * y; | |
643 if (h < height) | |
644 height = h; | |
1887 | 645 if (depth == (int)eb->core.depth) |
48 | 646 XCopyArea(XtDisplay(eb), pix, XtWindow(eb), gc, 0, 0, |
647 width, height, x, y); | |
648 else if (depth == 1) | |
649 XCopyPlane(XtDisplay(eb), pix, XtWindow(eb), gc, 0, 0, | |
650 width, height, x, y, (unsigned long)1); | |
651 } | |
652 | |
653 /* | |
654 * Draw the label contained in the pushbutton. | |
655 */ | |
656 static void | |
657 draw_label(XmEnhancedButtonWidget eb, XEvent *event, Region region) | |
658 { | |
659 GC tmp_gc = NULL; | |
660 Boolean replaceGC = False; | |
661 Boolean deadjusted = False; | |
888 | 662 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 663 XmDisplay dpy = (XmDisplay)XmGetXmDisplay(XtDisplay(eb)); |
664 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
665 #else | |
666 Boolean etched_in = False; | |
667 #endif | |
668 | |
669 if (eb->pushbutton.armed | |
670 && ((!Lab_IsMenupane(eb) && eb->pushbutton.fill_on_arm) | |
671 || (Lab_IsMenupane(eb) && etched_in))) | |
672 { | |
673 if (eb->label.label_type == (int)XmSTRING | |
674 && eb->pushbutton.arm_color == eb->primitive.foreground) | |
675 { | |
676 tmp_gc = eb->label.normal_GC; | |
677 eb->label.normal_GC = eb->pushbutton.background_gc; | |
678 replaceGC = True; | |
679 } | |
680 } | |
681 | |
682 /* | |
683 * If the button contains a labeled pixmap, we will take it instead of our | |
684 * own pixmap. | |
685 */ | |
686 | |
687 if (eb->label.label_type == (int)XmPIXMAP) | |
688 { | |
689 if (eb->pushbutton.armed) | |
690 { | |
691 if (eb->pushbutton.arm_pixmap != XmUNSPECIFIED_PIXMAP) | |
692 eb->label.pixmap = eb->pushbutton.arm_pixmap; | |
693 else | |
694 eb->label.pixmap = eb->pushbutton.unarm_pixmap; | |
695 } | |
696 else | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
697 // pushbutton is not armed |
48 | 698 eb->label.pixmap = eb->pushbutton.unarm_pixmap; |
699 } | |
700 | |
701 /* | |
702 * Temporarily remove the Xm3D_ENHANCE_PIXEL hack ("adjustment") from the | |
703 * margin values, so we don't confuse Label. | |
704 */ | |
705 if (eb->pushbutton.default_button_shadow_thickness > 0) | |
706 { | |
707 deadjusted = True; | |
708 Lab_MarginLeft(eb) -= Xm3D_ENHANCE_PIXEL; | |
709 Lab_MarginRight(eb) -= Xm3D_ENHANCE_PIXEL; | |
710 Lab_MarginTop(eb) -= Xm3D_ENHANCE_PIXEL; | |
711 Lab_MarginBottom(eb) -= Xm3D_ENHANCE_PIXEL; | |
712 } | |
713 | |
714 { | |
715 XtExposeProc expose; | |
716 | |
717 XtProcessLock(); | |
718 expose = xmLabelClassRec.core_class.expose; | |
719 XtProcessUnlock(); | |
720 (*expose)((Widget) eb, event, region); | |
721 } | |
722 | |
723 if (deadjusted) | |
724 { | |
725 Lab_MarginLeft(eb) += Xm3D_ENHANCE_PIXEL; | |
726 Lab_MarginRight(eb) += Xm3D_ENHANCE_PIXEL; | |
727 Lab_MarginTop(eb) += Xm3D_ENHANCE_PIXEL; | |
728 Lab_MarginBottom(eb) += Xm3D_ENHANCE_PIXEL; | |
729 } | |
730 | |
731 if (replaceGC) | |
732 eb->label.normal_GC = tmp_gc; | |
733 } | |
734 | |
735 static void | |
1887 | 736 Enter(Widget wid, |
737 XEvent *event, | |
738 String *params UNUSED, | |
739 Cardinal *num_params UNUSED) | |
48 | 740 { |
741 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) wid; | |
742 XmPushButtonCallbackStruct call_value; | |
743 | |
744 if (Lab_IsMenupane(eb)) | |
745 { | |
746 if ((((ShellWidget) XtParent(XtParent(eb)))->shell.popped_up) | |
747 && _XmGetInDragMode((Widget) eb)) | |
748 { | |
888 | 749 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 750 XmDisplay dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(wid)); |
751 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
752 #else | |
753 Boolean etched_in = False; | |
754 #endif | |
755 | |
756 if (eb->pushbutton.armed) | |
757 return; | |
758 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
759 // ...so KHelp event is delivered correctly. |
48 | 760 _XmSetFocusFlag(XtParent(XtParent(eb)), XmFOCUS_IGNORE, TRUE); |
761 XtSetKeyboardFocus(XtParent(XtParent(eb)), (Widget) eb); | |
762 _XmSetFocusFlag(XtParent(XtParent(eb)), XmFOCUS_IGNORE, FALSE); | |
763 | |
764 eb->pushbutton.armed = TRUE; | |
765 | |
766 ((XmManagerWidget) XtParent(wid))->manager.active_child = wid; | |
767 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
768 // etched in menu button |
48 | 769 if (etched_in && !XmIsTearOffButton(eb)) |
770 { | |
771 XFillRectangle(XtDisplay(eb), XtWindow(eb), | |
772 eb->pushbutton.fill_gc, | |
773 0, 0, eb->core.width, eb->core.height); | |
774 draw_label(eb, event, NULL); | |
775 draw_pixmap(eb, event, NULL); | |
776 } | |
777 | |
778 if ((eb->core.width > 2 * eb->primitive.highlight_thickness) | |
779 && (eb->core.height > | |
780 2 * eb->primitive.highlight_thickness)) | |
781 { | |
782 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
783 eb->primitive.top_shadow_GC, | |
784 eb->primitive.bottom_shadow_GC, | |
785 eb->primitive.highlight_thickness, | |
786 eb->primitive.highlight_thickness, | |
787 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
788 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
789 eb->primitive.shadow_thickness, | |
790 (unsigned)(etched_in ? XmSHADOW_IN : XmSHADOW_OUT)); | |
791 } | |
792 | |
793 if (eb->pushbutton.arm_callback) | |
794 { | |
795 XFlush(XtDisplay(eb)); | |
796 | |
797 call_value.reason = (int)XmCR_ARM; | |
798 call_value.event = event; | |
799 XtCallCallbackList((Widget) eb, | |
800 eb->pushbutton.arm_callback, | |
801 &call_value); | |
802 } | |
803 } | |
804 } | |
805 else | |
806 { | |
807 XtExposeProc expose; | |
808 | |
809 _XmPrimitiveEnter((Widget) eb, event, NULL, NULL); | |
810 if (eb->pushbutton.armed == TRUE) | |
811 { | |
812 XtProcessLock(); | |
813 expose = XtClass(eb)->core_class.expose; | |
814 XtProcessUnlock(); | |
815 (*expose) (wid, event, (Region) NULL); | |
816 } | |
817 | |
818 draw_highlight(eb); | |
819 draw_shadows(eb); | |
820 draw_pixmap(eb, event, NULL); | |
821 } | |
822 } | |
823 | |
824 static void | |
1887 | 825 Leave(Widget wid, |
826 XEvent *event, | |
827 String *params UNUSED, | |
828 Cardinal *num_params UNUSED) | |
48 | 829 { |
830 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)wid; | |
831 XmPushButtonCallbackStruct call_value; | |
832 | |
833 if (Lab_IsMenupane(eb)) | |
834 { | |
888 | 835 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 836 XmDisplay dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(wid)); |
837 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
838 #else | |
839 Boolean etched_in = False; | |
840 #endif | |
841 | |
842 if (_XmGetInDragMode((Widget)eb) | |
843 && eb->pushbutton.armed | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
844 && ( // !ActiveTearOff || |
48 | 845 event->xcrossing.mode == NotifyNormal)) |
846 { | |
847 eb->pushbutton.armed = FALSE; | |
848 | |
849 ((XmManagerWidget) XtParent(wid))->manager.active_child = NULL; | |
850 | |
851 if (etched_in && !XmIsTearOffButton(eb)) | |
852 { | |
853 XFillRectangle(XtDisplay(eb), XtWindow(eb), | |
854 eb->pushbutton.background_gc, | |
855 0, 0, eb->core.width, eb->core.height); | |
856 draw_label(eb, event, NULL); | |
857 draw_pixmap(eb, event, NULL); | |
858 } | |
859 else | |
860 XmeClearBorder | |
861 (XtDisplay(eb), XtWindow(eb), | |
862 eb->primitive.highlight_thickness, | |
863 eb->primitive.highlight_thickness, | |
864 eb->core.width - | |
865 2 * eb->primitive.highlight_thickness, | |
866 eb->core.height - | |
867 2 * eb->primitive.highlight_thickness, | |
868 eb->primitive.shadow_thickness); | |
869 | |
870 if (eb->pushbutton.disarm_callback) | |
871 { | |
872 XFlush(XtDisplay(eb)); | |
873 | |
874 call_value.reason = (int)XmCR_DISARM; | |
875 call_value.event = event; | |
876 XtCallCallbackList((Widget) eb, | |
877 eb->pushbutton.disarm_callback, | |
878 &call_value); | |
879 } | |
880 } | |
881 } | |
882 else | |
883 { | |
884 _XmPrimitiveLeave((Widget) eb, event, NULL, NULL); | |
885 | |
886 if (eb->pushbutton.armed == TRUE) | |
887 { | |
888 XtExposeProc expose; | |
889 eb->pushbutton.armed = FALSE; | |
890 XtProcessLock(); | |
891 expose = XtClass(eb)->core_class.expose; | |
892 XtProcessUnlock(); | |
893 (*expose) (wid, event, (Region)NULL); | |
894 draw_unhighlight(eb); | |
895 draw_pixmap(eb, event, NULL); | |
896 eb->pushbutton.armed = TRUE; | |
897 } | |
898 else | |
899 { | |
900 draw_unhighlight(eb); | |
901 draw_pixmap(eb, event, NULL); | |
902 } | |
903 } | |
904 } | |
905 | |
906 #define IsNull(p) ((p) == XmUNSPECIFIED_PIXMAP) | |
907 | |
908 static void | |
909 set_size(XmEnhancedButtonWidget newtb) | |
910 { | |
911 unsigned int w = 0; | |
912 unsigned int h = 0; | |
913 | |
914 _XmCalcLabelDimensions((Widget) newtb); | |
915 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
916 // Find out how big the pixmap is |
48 | 917 if (newtb->enhancedbutton.pixmap_data |
918 && !IsNull(newtb->label.pixmap) | |
919 && !IsNull(newtb->enhancedbutton.normal_pixmap)) | |
920 { | |
921 w = newtb->enhancedbutton.pixmap_width; | |
922 h = newtb->enhancedbutton.pixmap_height; | |
923 } | |
924 | |
925 /* | |
4352 | 926 * Please note that we manipulate the width only in case of push buttons |
927 * not used in the context of a menu pane. | |
48 | 928 */ |
929 if (Lab_IsMenupane(newtb)) | |
930 { | |
931 newtb->label.margin_left = w + 2 * (newtb->primitive.shadow_thickness | |
932 + newtb->primitive.highlight_thickness) | |
933 + newtb->label.margin_width; | |
934 } | |
935 else | |
936 { | |
937 newtb->label.margin_left = w; | |
938 newtb->core.width = w + 2 * (newtb->primitive.shadow_thickness | |
939 + newtb->primitive.highlight_thickness | |
940 + newtb->label.margin_width) | |
941 + newtb->label.TextRect.width; | |
942 | |
943 if (newtb->label.TextRect.width > 0) | |
944 { | |
945 newtb->label.margin_left += newtb->label.margin_width | |
946 + newtb->primitive.shadow_thickness; | |
947 newtb->core.width += newtb->label.margin_width | |
948 + newtb->primitive.shadow_thickness; | |
949 } | |
950 } | |
951 if (newtb->label.TextRect.height < h) | |
952 { | |
953 newtb->core.height = h + 2 * (newtb->primitive.shadow_thickness | |
954 + newtb->primitive.highlight_thickness | |
955 + newtb->label.margin_height); | |
956 } | |
957 else | |
958 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
959 // FIXME: We should calculate an drawing offset for the pixmap here to |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
960 // adjust it. |
48 | 961 } |
962 | |
963 #if 0 | |
964 printf("%d %d %d %d %d %d - %d %d\n", newtb->enhancedbutton.normal_pixmap, | |
965 h, newtb->core.height, | |
966 newtb->primitive.shadow_thickness, | |
967 newtb->primitive.highlight_thickness, | |
968 newtb->label.margin_height, | |
969 newtb->core.width, | |
970 newtb->core.height); | |
971 #endif | |
972 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
973 // Invoke Label's Resize procedure. |
48 | 974 { |
975 XtWidgetProc resize; | |
976 XtProcessLock(); | |
977 resize = xmLabelClassRec.core_class.resize; | |
978 XtProcessUnlock(); | |
979 | |
980 (* resize) ((Widget) newtb); | |
981 } | |
982 } | |
983 | |
984 static void | |
1887 | 985 Initialize(Widget rq, Widget ebw, ArgList args UNUSED, Cardinal *n UNUSED) |
48 | 986 { |
987 XmEnhancedButtonWidget request = (XmEnhancedButtonWidget)rq; | |
988 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)ebw; | |
989 XtWidgetProc resize; | |
990 | |
991 XtProcessLock(); | |
992 resize = xmLabelClassRec.core_class.resize; | |
993 XtProcessUnlock(); | |
994 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
995 // Create a bitmap for stippling (Drawable resources are cheap). |
48 | 996 if (STIPPLE_BITMAP == None) |
997 { | |
998 Display *dpy = XtDisplay((Widget) request); | |
999 Window rootW = DefaultRootWindow(dpy); | |
1000 | |
1001 STIPPLE_BITMAP = XCreateBitmapFromData(dpy, rootW, stipple_bits, | |
1002 stipple_width, stipple_height); | |
1003 } | |
1004 eb->enhancedbutton.doing_setvalues = False; | |
1005 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1006 // First see what type of extended label this is. |
48 | 1007 if (eb->enhancedbutton.pixmap_data) |
1008 { | |
1009 XmString str; | |
1010 set_pixmap(eb); | |
1011 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1012 // FIXME: this is not the perfect way to deal with menus, which do not |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1013 // have any string set right now. |
48 | 1014 str = XmStringCreateLocalized(""); |
1015 XtVaSetValues((Widget) eb, XmNlabelString, str, NULL); | |
1016 XmStringFree(str); | |
1017 } | |
1018 eb->label.pixmap = eb->enhancedbutton.normal_pixmap; | |
1019 | |
1020 if (request->core.width == 0) | |
1021 eb->core.width = 0; | |
1022 if (request->core.height == 0) | |
1023 eb->core.height = 0; | |
1024 set_size(eb); | |
1025 | |
1026 (* resize)((Widget)eb); | |
1027 } | |
1028 | |
1029 static void | |
1030 free_pixmaps(XmEnhancedButtonWidget eb) | |
1031 { | |
1032 /* | |
1033 * Clear the old pixmaps. | |
1034 */ | |
1035 Pixmap norm_pix = eb->enhancedbutton.normal_pixmap; | |
1036 Pixmap arm_pix = eb->enhancedbutton.armed_pixmap; | |
1037 Pixmap insen_pix = eb->enhancedbutton.insensitive_pixmap; | |
1038 Pixmap high_pix = eb->enhancedbutton.highlight_pixmap; | |
1039 | |
1040 if (norm_pix != None && norm_pix != XmUNSPECIFIED_PIXMAP) | |
1041 XFreePixmap(XtDisplay(eb), norm_pix); | |
1042 | |
1043 if (arm_pix != None && arm_pix != XmUNSPECIFIED_PIXMAP) | |
1044 XFreePixmap(XtDisplay(eb), arm_pix); | |
1045 | |
1046 if (insen_pix != None && insen_pix != XmUNSPECIFIED_PIXMAP) | |
1047 XFreePixmap(XtDisplay(eb), insen_pix); | |
1048 | |
1049 if (high_pix != None && high_pix != XmUNSPECIFIED_PIXMAP) | |
1050 XFreePixmap(XtDisplay(eb), high_pix); | |
1051 } | |
1052 | |
1053 static void | |
1054 Destroy(Widget w) | |
1055 { | |
1056 if (!XmIsEnhancedButton(w)) | |
1057 return; | |
1058 | |
1059 free_pixmaps((XmEnhancedButtonWidget)w); | |
1060 } | |
1061 | |
1062 static Boolean | |
1887 | 1063 SetValues(Widget current, |
1064 Widget request UNUSED, | |
1065 Widget new, | |
1066 ArgList args UNUSED, | |
1067 Cardinal *n UNUSED) | |
48 | 1068 { |
1069 XmEnhancedButtonWidget cur = (XmEnhancedButtonWidget) current; | |
1070 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) new; | |
1071 Boolean redraw = False; | |
1072 Boolean change = True; | |
1073 Display *dpy = XtDisplay(current); | |
1074 | |
1075 #define NOT_EQUAL(field) (cur->field != eb->field) | |
1076 | |
1077 /* | |
1078 * Make sure that lost sensitivity is causing the border to vanish as well. | |
1079 */ | |
1080 if (NOT_EQUAL(core.sensitive) && !Lab_IsMenupane(current)) | |
1081 { | |
1082 if (cur->core.sensitive == True) | |
1083 { | |
1084 draw_unhighlight(eb); | |
1085 } | |
1086 else | |
1087 { | |
1088 int r_x; | |
1089 int r_y; | |
1090 unsigned int r_height; | |
1091 unsigned int r_width; | |
1092 unsigned int r_border; | |
1093 unsigned int r_depth; | |
1094 int root_x; | |
1095 int root_y; | |
1096 int win_x; | |
1097 int win_y; | |
1098 Window root; | |
1099 Window root_q; | |
1100 Window child; | |
1101 unsigned int mask; | |
1102 | |
1103 /* | |
1206 | 1104 * Artificially let the highlight appear if the mouse is over us. |
48 | 1105 */ |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1106 // Best way to get the root window of object: |
48 | 1107 XGetGeometry(dpy, XtWindow(cur), &root, &r_x, &r_y, &r_width, |
1108 &r_height, &r_border, &r_depth); | |
1109 XQueryPointer(XtDisplay(cur), XtWindow(cur), &root_q, &child, | |
1110 &root_x, &root_y, &win_x, &win_y, &mask); | |
1111 | |
1112 if (root == root_q) | |
1113 { | |
1114 if ((win_x < 0) || (win_y < 0)) | |
1115 return False; | |
1116 | |
1887 | 1117 if ((win_x > (int)r_width) || (win_y > (int)r_height)) |
48 | 1118 return False; |
1119 draw_highlight(eb); | |
1120 draw_shadows(eb); | |
1121 } | |
1122 } | |
1123 | |
1124 return True; | |
1125 } | |
1126 | |
1127 /* | |
1128 * Check for changed ExtLabelString. | |
1129 */ | |
1130 if (NOT_EQUAL(primitive.shadow_thickness)) | |
1131 { | |
1132 redraw = True; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1133 // Don't change the pixmaps |
48 | 1134 change = False; |
1135 } | |
1136 | |
1137 if (NOT_EQUAL(primitive.foreground)) | |
1138 redraw = True; | |
1139 if (NOT_EQUAL(core.background_pixel)) | |
1140 redraw = True; | |
1141 if (NOT_EQUAL(pushbutton.fill_on_arm)) | |
1142 redraw = True; | |
1143 if (NOT_EQUAL(enhancedbutton.spacing)) | |
1144 redraw = True; | |
1145 if (NOT_EQUAL(enhancedbutton.label_location)) | |
1146 { | |
1147 redraw = True; | |
1148 change = False; | |
1149 } | |
1150 if (NOT_EQUAL(label._label)) | |
1151 { | |
1152 redraw = True; | |
1153 set_size(eb); | |
1154 } | |
1155 | |
1156 if (redraw == True) | |
1157 { | |
1158 if (change) | |
1159 set_pixmap(eb); | |
1160 if (eb->primitive.highlighted) | |
1161 eb->label.pixmap = eb->enhancedbutton.highlight_pixmap; | |
1162 else | |
1163 eb->label.pixmap = eb->enhancedbutton.normal_pixmap; | |
1164 if (change) | |
1165 set_size(eb); | |
1166 redraw = False; | |
1167 } | |
1168 | |
1169 return redraw; | |
1170 } | |
1171 | |
1172 static void | |
1173 Redisplay(Widget w, XEvent *event, Region region) | |
1174 { | |
1175 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) w; | |
888 | 1176 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 1177 XmDisplay dpy; |
1178 XtEnum default_button_emphasis; | |
1179 #endif | |
1180 XRectangle box; | |
1181 int dx; | |
1182 int adjust; | |
1183 short fill = 0; | |
1184 | |
1185 if (!XtIsRealized((Widget)eb)) | |
1186 return; | |
1187 | |
888 | 1188 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 1189 dpy = (XmDisplay)XmGetXmDisplay(XtDisplay(eb)); |
1190 default_button_emphasis = dpy->display.default_button_emphasis; | |
1191 #endif | |
1192 | |
1193 /* | |
1194 * Compute the area allocated to the label of the pushbutton; fill in the | |
1195 * dimensions in the box. | |
1196 */ | |
1197 | |
1198 if ((eb->pushbutton.arm_color == eb->primitive.top_shadow_color) | |
1199 || (eb->pushbutton.arm_color == eb->primitive.bottom_shadow_color)) | |
1200 fill = 1; | |
1201 | |
1202 if (eb->pushbutton.compatible) | |
1203 adjust = eb->pushbutton.show_as_default; | |
1204 else | |
1205 adjust = eb->pushbutton.default_button_shadow_thickness; | |
1206 | |
1207 if (adjust > 0) | |
1208 { | |
1209 adjust = adjust + eb->primitive.shadow_thickness; | |
1210 adjust = (adjust << 1); | |
1211 dx = eb->primitive.highlight_thickness + adjust + fill; | |
1212 } | |
1213 else | |
1214 dx = (eb->primitive.highlight_thickness | |
1215 + eb->primitive.shadow_thickness + fill); | |
1216 | |
1217 box.x = dx; | |
1218 box.y = dx; | |
1219 adjust = (dx << 1); | |
1220 box.width = eb->core.width - adjust; | |
1221 box.height = eb->core.height - adjust; | |
1222 | |
1223 /* | |
1224 * Redraw the background. | |
1225 */ | |
1226 if (!Lab_IsMenupane(eb)) | |
1227 { | |
1228 GC gc; | |
1229 | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1230 // Don't shade if the button contains a label with a pixmap, since |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1231 // there is no variant of the label available with the needed |
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1232 // background. |
48 | 1233 if (eb->pushbutton.armed && eb->pushbutton.fill_on_arm) |
1234 { | |
1235 if (eb->label.label_type == (int)XmPIXMAP) | |
1236 { | |
1237 if (eb->pushbutton.arm_pixmap != XmUNSPECIFIED_PIXMAP) | |
1238 gc = eb->pushbutton.fill_gc; | |
1239 else | |
1240 gc = eb->pushbutton.background_gc; | |
1241 } | |
1242 else | |
1243 gc = eb->pushbutton.fill_gc; | |
1244 } | |
1245 else | |
1246 gc = eb->pushbutton.background_gc; | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1247 // really need to fill with background if not armed ? |
48 | 1248 if (gc) |
1249 XFillRectangle(XtDisplay(eb), XtWindow(eb), gc, | |
1250 box.x, box.y, box.width, box.height); | |
1251 } | |
1252 | |
1253 draw_label(eb, event, region); | |
1254 | |
1255 if (Lab_IsMenupane(eb)) | |
1256 { | |
1257 if (eb->pushbutton.armed) | |
1258 (*(((XmPushButtonWidgetClass)XtClass(eb)) | |
1259 ->primitive_class.border_highlight))(w); | |
1260 draw_pixmap(eb, event, region); | |
1261 } | |
1262 else | |
1263 { | |
1757 | 1264 adjust = 0; |
48 | 1265 |
888 | 1266 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 1267 /* |
1268 * NOTE: PushButton has two types of shadows: primitive-shadow and | |
1269 * default-button-shadow. If pushbutton is in a menu only primitive | |
1270 * shadows are drawn. | |
1271 */ | |
1272 switch (default_button_emphasis) | |
1273 { | |
1274 case XmEXTERNAL_HIGHLIGHT: | |
1275 adjust = (eb->primitive.highlight_thickness - | |
1757 | 1276 (eb->pushbutton.default_button_shadow_thickness |
1277 ? Xm3D_ENHANCE_PIXEL : 0)); | |
48 | 1278 break; |
1279 | |
1280 case XmINTERNAL_HIGHLIGHT: | |
1281 break; | |
1282 | |
1283 default: | |
1284 assert(FALSE); | |
1285 return; | |
1286 } | |
1287 #endif | |
1288 | |
1289 /* | |
1290 * Clear the area not occupied by label with parents background color. | |
1291 * Label will invoke BorderUnhighlight() on the highlight_thickness | |
1292 * area, which is redundant when XmEXTERNAL_HIGHLIGHT default button | |
1293 * shadow emphasis is used. | |
1294 */ | |
1295 if (box.x > adjust) | |
1296 { | |
1297 int borderwidth =box.x - adjust; | |
1298 int rectwidth = eb->core.width - 2 * adjust; | |
1299 int rectheight = eb->core.height - 2 * adjust; | |
1300 | |
1301 if (XmIsManager(XtParent(eb))) | |
1302 { | |
1303 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
1304 XmParentBackgroundGC(eb), | |
1305 adjust, adjust, rectwidth, rectheight, borderwidth); | |
1306 } | |
1307 else | |
1308 { | |
1309 XmeClearBorder(XtDisplay(eb), XtWindow(eb), | |
1310 adjust, adjust, rectwidth, rectheight, borderwidth); | |
1311 } | |
1312 | |
888 | 1313 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 1314 switch (default_button_emphasis) |
1315 { | |
1316 case XmINTERNAL_HIGHLIGHT: | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1317 // The call above erases the border highlighting. |
48 | 1318 if (eb->primitive.highlight_drawn) |
1319 (*(((XmPushButtonWidgetClass) XtClass (eb)) | |
1320 ->primitive_class.border_highlight)) ((Widget) eb) ; | |
1321 break; | |
1322 | |
1323 default: | |
1324 break; | |
1325 } | |
1326 #endif | |
1327 } | |
1328 | |
1329 if (eb->pushbutton.default_button_shadow_thickness) | |
1330 { | |
1331 if (eb->pushbutton.show_as_default) | |
1332 { | |
1333 /* | |
1334 * - get the topShadowColor and bottomShadowColor from the | |
1335 * parent; use those colors to construct top and bottom gc; | |
1336 * use these GCs to draw the shadows of the button. | |
1337 * | |
1338 * - Should not be called if pushbutton is in a row column or | |
1339 * in a menu. | |
1340 * | |
1341 * - Should be called only if a defaultbuttonshadow is to be | |
1342 * drawn. | |
1343 */ | |
1344 GC top_gc; | |
1345 GC bottom_gc; | |
1346 int default_button_shadow_thickness; | |
1347 int x, y, width, height, delta; | |
1348 Widget parent; | |
1349 | |
1350 if (eb->pushbutton.compatible | |
1351 && (eb->pushbutton.show_as_default == 0)) | |
1352 return; | |
1353 | |
1354 if (!eb->pushbutton.compatible | |
1355 && (eb->pushbutton.default_button_shadow_thickness | |
1356 == 0)) | |
1357 return; | |
1358 | |
1359 delta = eb->primitive.highlight_thickness; | |
1360 | |
1361 /* | |
1362 * May need more complex computation for getting the GCs. | |
1363 */ | |
1364 parent = XtParent(eb); | |
1365 if (XmIsManager(parent)) | |
1366 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1367 // Use the parent's GC so monochrome works. |
48 | 1368 bottom_gc = XmParentTopShadowGC(eb); |
1369 top_gc = XmParentBottomShadowGC(eb); | |
1370 } | |
1371 else | |
1372 { | |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1373 // Use your own pixel for drawing. |
48 | 1374 bottom_gc = eb->primitive.top_shadow_GC; |
1375 top_gc = eb->primitive.bottom_shadow_GC; | |
1376 } | |
1377 | |
1378 if ((bottom_gc == None) || (top_gc == None)) | |
1379 return; | |
1380 | |
1381 | |
1382 if (eb->pushbutton.compatible) | |
1383 default_button_shadow_thickness = | |
1384 eb->pushbutton.show_as_default; | |
1385 else | |
1386 default_button_shadow_thickness = | |
1387 eb->pushbutton.default_button_shadow_thickness; | |
1388 | |
888 | 1389 #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
48 | 1390 /* |
1391 * Compute location of bounding box to contain the | |
1392 * defaultButtonShadow. | |
1393 */ | |
1394 switch (default_button_emphasis) | |
1395 { | |
1396 case XmEXTERNAL_HIGHLIGHT: | |
1397 delta = eb->primitive.highlight_thickness; | |
1398 break; | |
1399 | |
1400 case XmINTERNAL_HIGHLIGHT: | |
1401 delta = Xm3D_ENHANCE_PIXEL; | |
1402 break; | |
1403 | |
1404 default: | |
1405 assert(FALSE); | |
1406 return; | |
1407 } | |
1408 #endif | |
1409 | |
1410 x = y = delta; | |
1411 width = eb->core.width - 2 * delta; | |
1412 height = eb->core.height - 2 * delta; | |
1413 | |
1414 if ((width > 0) && (height > 0)) | |
1415 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
1416 top_gc, bottom_gc, x, y, width, height, | |
1417 default_button_shadow_thickness, | |
1418 (unsigned)XmSHADOW_OUT); | |
1419 } | |
1420 } | |
1421 | |
1422 if (eb->primitive.highlight_drawn) | |
1423 draw_shadows(eb); | |
1424 draw_pixmap(eb, event, region); | |
1425 } | |
1426 } | |
1427 | |
1428 static void | |
1429 BorderHighlight(Widget w) | |
1430 { | |
1431 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)w; | |
1432 | |
1433 (*(xmPushButtonClassRec.primitive_class.border_highlight))(w); | |
1434 draw_pixmap(eb, NULL, NULL); | |
1435 } | |
1436 | |
1437 static void | |
1438 BorderUnhighlight(Widget w) | |
1439 { | |
1440 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)w; | |
1441 | |
1442 (*(xmPushButtonClassRec.primitive_class.border_unhighlight))(w); | |
1443 draw_pixmap(eb, NULL, NULL); | |
1444 } | |
158 | 1445 |
18788
e1f4e9d78a6a
patch 8.1.2383: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1446 #endif // FEAT_TOOLBAR |