Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | /* |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 21 | * Enhanced Motif PushButton widget with move over behavior. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 24 | #include "vim.h" |
| 25 | |
| 26 | #ifdef FEAT_TOOLBAR |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 27 | |
| 28 | #include <Xm/XmP.h> |
| 29 | #include <Xm/DrawP.h> |
Bram Moolenaar | b23c338 | 2005-01-31 19:09:12 +0000 | [diff] [blame] | 30 | #if defined(HAVE_XM_TRAITP_H) && defined(HAVE_XM_MANAGER_H) \ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 31 | && defined(HAVE_XM_UNHIGHLIGHTT_H) && defined(HAVE_XM_XPMP_H) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 32 | # include <Xm/TraitP.h> |
| 33 | # include <Xm/Manager.h> |
| 34 | # include <Xm/UnhighlightT.h> |
| 35 | # include <Xm/XpmP.h> |
Bram Moolenaar | b23c338 | 2005-01-31 19:09:12 +0000 | [diff] [blame] | 36 | # define UNHIGHLIGHTT |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 37 | #else |
Bram Moolenaar | 88c86eb | 2019-01-17 17:13:30 +0100 | [diff] [blame] | 38 | # ifdef HAVE_X11_XPM_H |
| 39 | # ifdef VMS |
| 40 | # include <xpm.h> |
| 41 | # else |
| 42 | # include <X11/xpm.h> |
| 43 | # endif |
| 44 | # endif |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 55 | // Provide some missing wrappers, which are missed from the LessTif |
| 56 | // implementation. Also missing in Motif 1.2 and earlier. |
| 57 | // |
| 58 | // We neither use XmeGetPixmapData or _XmGetPixmapData, since with LessTif the |
| 59 | // pixmap will not appear in its caches properly. We cache the interesting |
| 60 | // values in XmEnhancedButtonPart instead ourself. |
Bram Moolenaar | 5fffc13 | 2006-05-13 15:22:39 +0000 | [diff] [blame] | 61 | #if defined(LESSTIF_VERSION) || (XmVersion <= 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 76 | // Hopefully this will never change... |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 146 | // This is needed to work around a bug in Lesstif 2, leaving the extension |
| 147 | // NULL somehow results in getting it set to an invalid pointer. |
Bram Moolenaar | 8b610cf | 2006-10-24 20:29:10 +0000 | [diff] [blame] | 148 | XmPrimitiveClassExtRec xmEnhancedButtonPrimClassExtRec = |
| 149 | { |
| 150 | /* next_extension */ NULL, |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 151 | /* record_type */ NULLQUARK, |
| 152 | /* version */ XmPrimitiveClassExtVersion, |
| 153 | /* record_size */ sizeof(XmPrimitiveClassExtRec), |
| 154 | /* widget_baseline */ XmInheritBaselineProc, |
Bram Moolenaar | 8b610cf | 2006-10-24 20:29:10 +0000 | [diff] [blame] | 155 | /* widget_display_rect */ XmInheritDisplayRectProc, |
| 156 | /* widget_margins */ NULL |
| 157 | }; |
| 158 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 159 | XmEnhancedButtonClassRec xmEnhancedButtonClassRec = |
| 160 | { |
| 161 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 162 | // core_class fields |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 163 | /* superclass */ (WidgetClass) & xmPushButtonClassRec, |
| 164 | /* class_name */ "XmEnhancedButton", |
| 165 | /* widget_size */ sizeof(XmEnhancedButtonRec), |
| 166 | /* class_initialize */ NULL, |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 167 | /* class_part_initialize */ NULL, |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 195 | }, |
| 196 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 197 | // primitive_class fields |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 198 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 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, |
Bram Moolenaar | 8b610cf | 2006-10-24 20:29:10 +0000 | [diff] [blame] | 205 | /* extension */ (XtPointer)&xmEnhancedButtonPrimClassExtRec, |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 206 | }, |
| 207 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 208 | // label_class fields |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 209 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 210 | /* setOverrideCallback */ XmInheritSetOverrideCallback, |
| 211 | /* menuProcs */ XmInheritMenuProc, |
| 212 | /* translations */ XtInheritTranslations, |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 213 | /* extension */ NULL, |
| 214 | }, |
| 215 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 216 | // pushbutton_class record |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 217 | { |
| 218 | /* extension */ (XtPointer) NULL, |
| 219 | }, |
| 220 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 221 | // enhancedbutton_class fields |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 243 | static int |
| 244 | alloc_color(Display *display, |
| 245 | Colormap colormap, |
| 246 | char *colorname, |
| 247 | XColor *xcolor, |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 248 | void *closure UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 264 | // XPM |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 265 | static char * blank_xpm[] = |
| 266 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 267 | // width height ncolors cpp [x_hot y_hot] |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 268 | "12 12 4 1 0 0", |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 269 | // colors |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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", |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 274 | // pixels |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 294 | // Configure defines XPMATTRIBUTES_TYPE as XpmAttributes or as |
| 295 | // XpmAttributes_21, depending on what is in Xm/XpmP.h. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 296 | XPMATTRIBUTES_TYPE attr; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 314 | int status = 0; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 321 | char *fname = (char *) eb->enhancedbutton.pixmap_file; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 322 | int shift; |
| 323 | GC gc; |
| 324 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 325 | // Make sure there is a default value for the pixmap. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 335 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 344 | // We use dynamic colors, get them now. |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 352 | // Setup color substitution table. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 362 | // Create the "sensitive" pixmap. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 363 | attr.valuemask = XpmColorSymbols | XpmCloseness; |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 364 | attr.closeness = 65535; // accuracy isn't crucial |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 365 | attr.colorsymbols = color; |
| 366 | attr.numsymbols = XtNumber(color); |
| 367 | |
Bram Moolenaar | 7c62692 | 2005-02-07 22:01:03 +0000 | [diff] [blame] | 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); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 372 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 373 | // If something failed, we will fill in the default pixmap. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 382 | // TODO: does the shift depend on label_location somehow? |
Bram Moolenaar | a53c60d | 2012-06-29 13:19:27 +0200 | [diff] [blame] | 383 | shift = eb->primitive.shadow_thickness / 2; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 396 | // Create the "highlight" pixmap. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 397 | color[4].pixel = eb->primitive.bottom_shadow_color; |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 398 | #ifdef XpmAllocColor // SGI doesn't have it |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 399 | attr.valuemask = XpmColorSymbols | XpmCloseness | XpmAllocColor; |
Bram Moolenaar | 6f19245 | 2007-11-08 19:49:02 +0000 | [diff] [blame] | 400 | attr.alloc_color = alloc_color; |
| 401 | #else |
| 402 | attr.valuemask = XpmColorSymbols | XpmCloseness; |
| 403 | #endif |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 404 | attr.closeness = 65535; // accuracy isn't crucial |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 405 | attr.colorsymbols = color; |
| 406 | attr.numsymbols = XtNumber(color); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 440 | // Create the "insensitive" pixmap. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 441 | attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey; |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 442 | attr.closeness = 65535; // accuracy isn't crucial |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 448 | // Need to create new Pixmaps with the mask applied. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 500 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | b23c338 | 2005-01-31 19:09:12 +0000 | [diff] [blame] | 560 | #ifdef UNHIGHLIGHTT |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 561 | XmSpecifyUnhighlightTrait UnhighlightT; |
| 562 | |
| 563 | if (((UnhighlightT = (XmSpecifyUnhighlightTrait) XmeTraitGet((XtPointer) |
| 564 | XtClass(eb->core.parent), XmQTspecifyUnhighlight)) |
| 565 | != NULL) && (UnhighlightT->getUnhighlightGC != NULL)) |
| 566 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 567 | // if unhighlight trait in parent use specified GC... |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 568 | manager_background_GC = |
| 569 | UnhighlightT->getUnhighlightGC(eb->core.parent, (Widget) eb); |
| 570 | } |
| 571 | else |
| 572 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 573 | // ...otherwise, use parent's background GC |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 598 | static void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 599 | draw_pixmap(XmEnhancedButtonWidget eb, |
| 600 | XEvent *event UNUSED, |
| 601 | Region region UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 645 | if (depth == (int)eb->core.depth) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 662 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 697 | // pushbutton is not armed |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 735 | static void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 736 | Enter(Widget wid, |
| 737 | XEvent *event, |
| 738 | String *params UNUSED, |
| 739 | Cardinal *num_params UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 749 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 759 | // ...so KHelp event is delivered correctly. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 768 | // etched in menu button |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 824 | static void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 825 | Leave(Widget wid, |
| 826 | XEvent *event, |
| 827 | String *params UNUSED, |
| 828 | Cardinal *num_params UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 829 | { |
| 830 | XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)wid; |
| 831 | XmPushButtonCallbackStruct call_value; |
| 832 | |
| 833 | if (Lab_IsMenupane(eb)) |
| 834 | { |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 835 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 844 | && ( // !ActiveTearOff || |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 916 | // Find out how big the pixmap is |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | /* |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 926 | * Please note that we manipulate the width only in case of push buttons |
| 927 | * not used in the context of a menu pane. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 959 | // FIXME: We should calculate an drawing offset for the pixmap here to |
| 960 | // adjust it. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 973 | // Invoke Label's Resize procedure. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 974 | { |
| 975 | XtWidgetProc resize; |
| 976 | XtProcessLock(); |
| 977 | resize = xmLabelClassRec.core_class.resize; |
| 978 | XtProcessUnlock(); |
| 979 | |
| 980 | (* resize) ((Widget) newtb); |
| 981 | } |
| 982 | } |
| 983 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 984 | static void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 985 | Initialize(Widget rq, Widget ebw, ArgList args UNUSED, Cardinal *n UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 995 | // Create a bitmap for stippling (Drawable resources are cheap). |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1006 | // First see what type of extended label this is. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1007 | if (eb->enhancedbutton.pixmap_data) |
| 1008 | { |
| 1009 | XmString str; |
| 1010 | set_pixmap(eb); |
| 1011 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1012 | // FIXME: this is not the perfect way to deal with menus, which do not |
| 1013 | // have any string set right now. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1062 | static Boolean |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1063 | SetValues(Widget current, |
| 1064 | Widget request UNUSED, |
| 1065 | Widget new, |
| 1066 | ArgList args UNUSED, |
| 1067 | Cardinal *n UNUSED) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | /* |
Bram Moolenaar | a38edcd | 2007-05-10 17:46:55 +0000 | [diff] [blame] | 1104 | * Artificially let the highlight appear if the mouse is over us. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1105 | */ |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1106 | // Best way to get the root window of object: |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1117 | if ((win_x > (int)r_width) || (win_y > (int)r_height)) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1133 | // Don't change the pixmaps |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 1176 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 1188 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1230 | // Don't shade if the button contains a label with a pixmap, since |
| 1231 | // there is no variant of the label available with the needed |
| 1232 | // background. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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; |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1247 | // really need to fill with background if not armed ? |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 1264 | adjust = 0; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1265 | |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 1266 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 - |
Bram Moolenaar | fe86f2d | 2008-11-28 20:29:07 +0000 | [diff] [blame] | 1276 | (eb->pushbutton.default_button_shadow_thickness |
| 1277 | ? Xm3D_ENHANCE_PIXEL : 0)); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1278 | break; |
| 1279 | |
| 1280 | case XmINTERNAL_HIGHLIGHT: |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 1313 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1314 | switch (default_button_emphasis) |
| 1315 | { |
| 1316 | case XmINTERNAL_HIGHLIGHT: |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1317 | // The call above erases the border highlighting. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1367 | // Use the parent's GC so monochrome works. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1368 | bottom_gc = XmParentTopShadowGC(eb); |
| 1369 | top_gc = XmParentBottomShadowGC(eb); |
| 1370 | } |
| 1371 | else |
| 1372 | { |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1373 | // Use your own pixel for drawing. |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 6a1a370 | 2006-05-13 13:41:03 +0000 | [diff] [blame] | 1389 | #if !defined(LESSTIF_VERSION) && (XmVersion > 1002) |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 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 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 1445 | |
Bram Moolenaar | 734a867 | 2019-12-02 22:49:38 +0100 | [diff] [blame] | 1446 | #endif // FEAT_TOOLBAR |