~ubuntu-branches/ubuntu/quantal/openmotif/quantal

« back to all changes in this revision

Viewing changes to lib/Xm/LabelG.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bauer
  • Date: 2010-06-23 12:12:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100623121231-u89gxdp51sg9wjj2
Tags: 2.3.0-1
* New Maintainer (Closes: #379258) 
* Acknowledge NMU changes
* New upstream release (Closes: #494375)
* Get rid of security patches as they are already part of new upstream
  release (00-xpmvuln.openmotif.patch, 342092-CVE-2005-3964.patch)
* Bump Standards to 3.8.4
* Added {misc:Depends} to make the package lintian cleaner
* Fix weak-library-dev-dependency by adding ${binary:Version}) for the
  -dev Package of openmotif
* Let package depend on autotools-dev to use newer autotools-helper-files
* Work around an autoconf-bug (Gentoo-Bug #1475)
* Added Client-side anti-aliased fonts support via XFT
* Added UTF-8 and UTF8_STRING atom support
* Ability to show text and pixmaps in Label, LabelGadget and all
  derived widgets
* Support of PNG/JPEG image formats in the same way as XPM is supported
* Increase FILE_OFFSET_BITS to 64 to show files >2GB in file-selector
  Idea taken from Magne Oestlyngen (Closes: #288537)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 *  @OPENGROUP_COPYRIGHT@
 
3
 *  COPYRIGHT NOTICE
 
4
 *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
 
5
 *  Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
 
6
 *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
 
7
 *  the full copyright text.
 
8
 *
 
9
 *  This software is subject to an open license. It may only be
 
10
 *  used on, with or for operating systems which are themselves open
 
11
 *  source systems. You must contact The Open Group for a license
 
12
 *  allowing distribution and sublicensing of this software on, with,
 
13
 *  or for operating systems which are not Open Source programs.
 
14
 *
 
15
 *  See http://www.opengroup.org/openmotif/license for full
 
16
 *  details of the license agreement. Any use, reproduction, or
 
17
 *  distribution of the program constitutes recipient's acceptance of
 
18
 *  this agreement.
 
19
 *
 
20
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
 
21
 *  PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
22
 *  KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 
23
 *  WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
 
24
 *  OR FITNESS FOR A PARTICULAR PURPOSE
 
25
 *
 
26
 *  EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
 
27
 *  NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
 
28
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
29
 *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
 
30
 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
31
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
32
 *  ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
 
33
 *  EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
 
34
 *  POSSIBILITY OF SUCH DAMAGES.
 
35
 */
 
36
/* 
 
37
 * HISTORY
 
38
 */
 
39
#ifdef REV_INFO
 
40
#ifndef lint
 
41
static char rcsid[] = "$TOG: LabelG.c /main/24 1999/01/26 15:31:18 mgreess $"
 
42
#endif
 
43
#endif
 
44
/* (c) Copyright 1989, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
 
45
/* (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 HEWLETT-PACKARD COMPANY */
 
46
 
 
47
#ifdef HAVE_CONFIG_H
 
48
#include <config.h>
 
49
#endif
 
50
 
 
51
#include <string.h>
 
52
#include <stdio.h>
 
53
#include <ctype.h>
 
54
#include <X11/IntrinsicP.h>
 
55
#include <X11/ShellP.h>
 
56
#include <X11/Xatom.h>
 
57
#include <X11/keysymdef.h>
 
58
#include <Xm/AccColorT.h>
 
59
#include <Xm/AccTextT.h>
 
60
#include <Xm/AtomMgr.h>
 
61
#include <Xm/BaseClassP.h>
 
62
#include <Xm/CacheP.h>
 
63
#include <Xm/CareVisualT.h>
 
64
#include <Xm/CascadeBGP.h>
 
65
#include <Xm/DisplayP.h>
 
66
#include <Xm/DragC.h>
 
67
#include <Xm/DragIcon.h>
 
68
#include <Xm/DragIconP.h>
 
69
#include <Xm/DrawP.h>
 
70
#include <Xm/ManagerP.h>
 
71
#include <Xm/MenuT.h>
 
72
#include <Xm/RowColumnP.h>
 
73
#include <Xm/ScreenP.h>
 
74
#include <Xm/TraitP.h>
 
75
#include <Xm/TransferT.h>
 
76
#include <Xm/VaSimpleP.h>
 
77
#include "BaseClassI.h"
 
78
#include "CacheI.h"
 
79
#include "ColorI.h"
 
80
#include "ExtObjectI.h"
 
81
#include "GadgetUtiI.h"
 
82
#include "LabelGI.h"
 
83
#include "MessagesI.h"
 
84
#include "MenuProcI.h"
 
85
#include "PixConvI.h"
 
86
#include "RepTypeI.h"
 
87
#include "ScreenI.h"
 
88
#include "SyntheticI.h"
 
89
#include "TravActI.h"
 
90
#include "XmI.h"
 
91
#include "XmosI.h"
 
92
#include "XmStringI.h"
 
93
 
 
94
#define Pix(w)      LabG_Pixmap(w)
 
95
#define Pix_insen(w)    LabG_PixmapInsensitive(w)
 
96
 
 
97
/* Warning Messages */
 
98
 
 
99
#define CS_STRING_MESSAGE   _XmMMsgLabel_0003
 
100
#define ACC_MESSAGE     _XmMMsgLabel_0004
 
101
 
 
102
/********    Static Function Declarations    ********/
 
103
 
 
104
static Pixmap GetTopShadowPixmapDefault(Widget);
 
105
static Pixmap GetLabelHighlightPixmapDefault(Widget);
 
106
static void ClassInitialize(void);
 
107
static void ClassPartInitialize(WidgetClass cl);
 
108
static void SecondaryObjectCreate(Widget req, Widget new_w,
 
109
ArgList args, Cardinal *num_args);
 
110
static void InitializePosthook(Widget req, Widget new_w,
 
111
ArgList args, Cardinal *num_args);
 
112
static Boolean SetValuesPrehook(Widget oldParent,
 
113
Widget refParent,
 
114
Widget newParent,
 
115
ArgList args,
 
116
Cardinal *num_args);
 
117
static void GetValuesPrehook(Widget newParent,
 
118
ArgList args,
 
119
Cardinal *num_args);
 
120
static void GetValuesPosthook(Widget new_w,
 
121
ArgList args,
 
122
Cardinal *num_args);
 
123
static Boolean SetValuesPosthook(Widget current,
 
124
Widget req,
 
125
Widget new_w,
 
126
ArgList args,
 
127
Cardinal *num_args);
 
128
static void BorderHighlight(Widget w);
 
129
static void SetNormalGC(XmLabelGadget lw);
 
130
static void Resize(Widget wid);
 
131
static void Initialize(Widget req, Widget new_w,
 
132
ArgList args, Cardinal *num_args);
 
133
static XtGeometryResult QueryGeometry(Widget wid,
 
134
XtWidgetGeometry *intended,
 
135
XtWidgetGeometry *reply);
 
136
static void Destroy(Widget w);
 
137
static void Redisplay(Widget wid, XEvent *event, Region region);
 
138
static Boolean SetValues(Widget cw, Widget rw, Widget nw,
 
139
ArgList args, Cardinal *num_args);
 
140
static void InputDispatch(Widget wid, XEvent *event, Mask event_mask);
 
141
static void Help(Widget w, XEvent *event);
 
142
static void GetLabelString(Widget wid, int offset, XtArgVal *value);
 
143
static void GetAccelerator(Widget wid, int offset, XtArgVal *value);
 
144
static void GetAcceleratorText(Widget wid, int offset, XtArgVal *value);
 
145
static XmStringCharSet _XmStringCharsetCreate(XmStringCharSet stringcharset);
 
146
static void GetMnemonicCharset(Widget wid, int resource, XtArgVal *value);
 
147
static void QualifyLabelLocalCache(XmLabelGadget w);
 
148
static void SetOverrideCallback(Widget w);
 
149
static Cardinal GetLabelBGClassSecResData(WidgetClass w_class,
 
150
XmSecondaryResourceData **data_rtn);
 
151
static XtPointer GetLabelClassResBase(Widget widget, XtPointer client_data);
 
152
static void SetValuesAlmost(Widget cw, Widget nw,
 
153
XtWidgetGeometry *request, XtWidgetGeometry *reply);
 
154
static Boolean XmLabelGadgetGetBaselines(Widget wid,
 
155
Dimension **baselines,
 
156
int *line_count);
 
157
static Boolean XmLabelGadgetGetDisplayRect(Widget w,
 
158
XRectangle *displayrect);
 
159
static void XmLabelGadgetMarginsProc(Widget w,
 
160
XmBaselineMargins *margins_rec);
 
161
static Widget GetPixmapDragIcon(Widget w);
 
162
static void SetGadgetActivateCallbackState(Widget w, XmActivateState state);
 
163
static void CheckSetRenderTable(Widget wid, int offset, XrmValue *value);
 
164
static void FromPaddingPixels(Widget, int, XtArgVal *);
 
165
static XmImportOperator ToPaddingPixels(Widget, int, XtArgVal*);
 
166
static Boolean HandleRedraw(Widget kid,
 
167
Widget cur_parent,
 
168
Widget new_parent,
 
169
Mask visual_flag);
 
170
static void InitNewColorBehavior(XmLabelGadget lw);
 
171
static void DealWithColors(XmLabelGadget lw);
 
172
static void DealWithPixmaps(XmLabelGadget lw);
 
173
static void InitNewPixmapBehavior(XmLabelGadget lw);
 
174
static char* GetLabelGadgetAccelerator(Widget);
 
175
static KeySym GetLabelGadgetMnemonic(Widget);
 
176
static void GetColors(Widget widget, XmAccessColorData color_data);
 
177
 
 
178
/********    End Static Function Declarations    ********/
 
179
 
 
180
void _XmLabelConvert(Widget w, XtPointer ignore, XmConvertCallbackStruct*);
 
181
 
 
182
/* Transfer trait record */
 
183
static XmConst XmTransferTraitRec LabelGTransfer =
 
184
{
 
185
    0,                                            /* version              */
 
186
    (XmConvertCallbackProc) _XmLabelConvert,      /* convertProc                  */
 
187
    NULL,                                         /* destinationProc      */
 
188
    NULL                                          /* destinationPreHookProc */
 
189
};
 
190
 
 
191
/* Menu Savvy trait record */
 
192
static XmConst XmMenuSavvyTraitRec MenuSavvyGadgetRecord =
 
193
{
 
194
    0,                                            /* version           */
 
195
    SetGadgetActivateCallbackState,               /* disableCallback   */
 
196
    GetLabelGadgetAccelerator,                    /* getAccelerator    */
 
197
    GetLabelGadgetMnemonic,                       /* getMnemonic       */
 
198
    NULL                                          /* getActivateCBName */
 
199
};
 
200
 
 
201
/* Used to be:
 
202
      extern XmConst XmAccessTextualTraitRec _XmLabel_AccessTextualRecord;
 
203
   but that was giving a linkage undefined with g++.
 
204
   It looks like a G++ bug. */
 
205
extern XmAccessTextualTraitRec _XmLabel_AccessTextualRecord;
 
206
 
 
207
static XmConst XmCareVisualTraitRec LabelGCVT =
 
208
{
 
209
    0,                                            /* version */
 
210
    HandleRedraw                                  /* redraw */
 
211
};
 
212
 
 
213
/* Access Colors Trait record for label gadget */
 
214
static XmConst XmAccessColorsTraitRec labACT =
 
215
{
 
216
    0,                                            /* version */
 
217
    GetColors,                                    /* getColors */
 
218
    NULL                                          /* setColors */
 
219
};
 
220
 
 
221
/*
 
222
 * Uncached resources for Label Gadget
 
223
 */
 
224
 
 
225
static XtResource resources[] =
 
226
{
 
227
    /* The following hackery is a way in Xt to see if a widget has been
 
228
     * initialized.  We need to know whether or not the gadget cache is
 
229
     * valid.  We use "." in the name so that an end user cannot access
 
230
     * it from a resource file.  With that in place, we just need to
 
231
     * check label.cache != NULL to see if the gadget has been
 
232
     * initialized and that we can access the colors for instance. */
 
233
    {
 
234
        XmNdotCache, XmCDotCache, XmRPointer,
 
235
        sizeof(XtPointer), XtOffsetOf(XmLabelGadgetRec, label.cache),
 
236
        XtRImmediate, (XtPointer) NULL
 
237
    },
 
238
 
 
239
    {
 
240
        XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension,
 
241
        sizeof(Dimension), XtOffsetOf(XmLabelGadgetRec, gadget.shadow_thickness),
 
242
        XmRImmediate, (XtPointer) 0
 
243
    },
 
244
 
 
245
    {
 
246
        XmNlabelPixmap, XmCLabelPixmap, XmRDynamicPixmap,
 
247
        sizeof(Pixmap), XtOffsetOf(XmLabelGadgetRec, label.pixmap),
 
248
        XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
 
249
    },
 
250
 
 
251
    {
 
252
        XmNlabelInsensitivePixmap, XmCLabelInsensitivePixmap, XmRDynamicPixmap,
 
253
        sizeof(Pixmap), XtOffsetOf(XmLabelGadgetRec, label.pixmap_insen),
 
254
        XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
 
255
    },
 
256
 
 
257
    {
 
258
        XmNlabelString, XmCXmString, XmRXmString,
 
259
        sizeof(XmString), XtOffsetOf(XmLabelGadgetRec, label._label),
 
260
        XmRImmediate, (XtPointer) NULL
 
261
    },
 
262
 
 
263
    {
 
264
        "pri.vate","Pri.vate", XmRBoolean,
 
265
        sizeof(Boolean), XtOffsetOf(XmLabelGadgetRec,
 
266
        label.check_set_render_table),
 
267
        XmRImmediate, (XtPointer) False
 
268
    },
 
269
 
 
270
    {
 
271
        XmNfontList, XmCFontList, XmRFontList,
 
272
        sizeof(XmFontList), XtOffsetOf(XmLabelGadgetRec, label.font),
 
273
        XmRCallProc, (XtPointer)CheckSetRenderTable
 
274
    },
 
275
 
 
276
    {
 
277
        XmNrenderTable, XmCRenderTable, XmRRenderTable,
 
278
        sizeof(XmRenderTable), XtOffsetOf(XmLabelGadgetRec, label.font),
 
279
        XmRCallProc, (XtPointer)CheckSetRenderTable
 
280
    },
 
281
 
 
282
    {
 
283
        XmNmnemonic, XmCMnemonic, XmRKeySym,
 
284
        sizeof(KeySym), XtOffsetOf(XmLabelGadgetRec, label.mnemonic),
 
285
        XmRImmediate, (XtPointer) XK_VoidSymbol
 
286
    },
 
287
 
 
288
    {
 
289
        XmNmnemonicCharSet, XmCMnemonicCharSet, XmRString,
 
290
        sizeof(XmStringCharSet), XtOffsetOf(XmLabelGadgetRec,label.mnemonicCharset),
 
291
        XmRImmediate, (XtPointer)  XmFONTLIST_DEFAULT_TAG
 
292
    },
 
293
 
 
294
    {
 
295
        XmNaccelerator, XmCAccelerator, XmRString,
 
296
        sizeof(char *), XtOffsetOf(XmLabelGadgetRec, label.accelerator),
 
297
        XmRImmediate, (XtPointer) NULL
 
298
    },
 
299
 
 
300
    {
 
301
        XmNacceleratorText, XmCAcceleratorText, XmRXmString,
 
302
        sizeof(XmString), XtOffsetOf(XmLabelGadgetRec, label._acc_text),
 
303
        XmRImmediate, (XtPointer) NULL
 
304
    },
 
305
 
 
306
    {
 
307
        XmNtraversalOn, XmCTraversalOn, XmRBoolean,
 
308
        sizeof(Boolean), XtOffsetOf(XmGadgetRec, gadget.traversal_on),
 
309
        XmRImmediate, (XtPointer) False
 
310
    },
 
311
 
 
312
    {
 
313
        XmNhighlightThickness, XmCHighlightThickness, XmRHorizontalDimension,
 
314
        sizeof(Dimension), XtOffsetOf(XmGadgetRec, gadget.highlight_thickness),
 
315
        XmRImmediate, (XtPointer) 0
 
316
    },
 
317
    
 
318
    {
 
319
        XmNpixmapPlacement, XmCPixmapPlacement, XmRPixmapPlacement,
 
320
        sizeof(XmPixmapPlacement), XtOffsetOf(XmLabelGadgetRec, label.pixmap_placement),
 
321
        XmRImmediate, (XtPointer) XmPIXMAP_LEFT
 
322
    },
 
323
    
 
324
    {
 
325
        XmNpixmapTextPadding, XmCSpace, XmRVerticalDimension,
 
326
        sizeof(Dimension), XtOffsetOf(XmLabelGadgetRec, label.pixmap_text_padding),
 
327
        XmRImmediate, (XtPointer) 2
 
328
    }
 
329
};
 
330
 
 
331
/* These 2 slots are needed for the delayed conversion. */
 
332
static XtResource label_pixmap_resource[] =
 
333
{
 
334
    {
 
335
        XmNlabelPixmap, XmCLabelPixmap, XmRDynamicPixmap,
 
336
        sizeof(Pixmap), XtOffsetOf(XmLabelGadgetRec, label.pixmap),
 
337
        XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
 
338
    }
 
339
};
 
340
 
 
341
static XtResource label_pixmap_insen_resource[] =
 
342
{
 
343
    {
 
344
        XmNlabelInsensitivePixmap, XmCLabelInsensitivePixmap, XmRDynamicPixmap,
 
345
        sizeof(Pixmap), XtOffsetOf(XmLabelGadgetRec, label.pixmap_insen),
 
346
        XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
 
347
    }
 
348
};
 
349
 
 
350
/*
 
351
 * Cached resources for Label Gadget
 
352
 */
 
353
static XtResource cache_resources[] =
 
354
{
 
355
    {
 
356
        XmNlabelType, XmCLabelType, XmRLabelType,
 
357
        sizeof(unsigned char),
 
358
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.label_type),
 
359
        XmRImmediate, (XtPointer) XmSTRING
 
360
    },
 
361
 
 
362
    {
 
363
        XmNalignment, XmCAlignment, XmRAlignment,
 
364
        sizeof(unsigned char),
 
365
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.alignment),
 
366
        XmRImmediate, (XtPointer) XmALIGNMENT_CENTER
 
367
    },
 
368
 
 
369
    {
 
370
        XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension,
 
371
        sizeof(Dimension),
 
372
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_width),
 
373
        XmRImmediate, (XtPointer) 2
 
374
    },
 
375
 
 
376
    {
 
377
        XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension,
 
378
        sizeof(Dimension),
 
379
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_height),
 
380
        XmRImmediate, (XtPointer) 2
 
381
    },
 
382
 
 
383
    {
 
384
        XmNmarginLeft, XmCMarginLeft, XmRHorizontalDimension,
 
385
        sizeof(Dimension),
 
386
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_left),
 
387
        XmRImmediate, (XtPointer) 0
 
388
    },
 
389
 
 
390
    {
 
391
        XmNmarginRight, XmCMarginRight, XmRHorizontalDimension,
 
392
        sizeof(Dimension),
 
393
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_right),
 
394
        XmRImmediate, (XtPointer) 0
 
395
    },
 
396
 
 
397
    {
 
398
        XmNmarginTop, XmCMarginTop, XmRVerticalDimension,
 
399
        sizeof(Dimension),
 
400
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_top),
 
401
        XmRImmediate, (XtPointer) 0
 
402
    },
 
403
 
 
404
    {
 
405
        XmNmarginBottom, XmCMarginBottom, XmRVerticalDimension,
 
406
        sizeof(Dimension),
 
407
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_bottom),
 
408
        XmRImmediate, (XtPointer) 0
 
409
    },
 
410
 
 
411
    {
 
412
        XmNrecomputeSize, XmCRecomputeSize, XmRBoolean,
 
413
        sizeof(Boolean),
 
414
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.recompute_size),
 
415
        XmRImmediate, (XtPointer) True
 
416
    },
 
417
 
 
418
    {
 
419
        XmNstringDirection, XmCStringDirection, XmRStringDirection,
 
420
        sizeof(unsigned char),
 
421
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.string_direction),
 
422
        XmRImmediate, (XtPointer) XmDEFAULT_DIRECTION
 
423
    },
 
424
 
 
425
    {
 
426
        XmNlayoutDirection, XmCLayoutDirection, XmRDirection,
 
427
        sizeof(XmDirection),
 
428
        XtOffsetOf(XmGadgetRec, gadget.layout_direction),
 
429
        XmRImmediate, (XtPointer) XmDEFAULT_DIRECTION
 
430
    },
 
431
 
 
432
    {
 
433
        XmNbackground, XmCBackground, XmRPixel,
 
434
        sizeof(Pixel),
 
435
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.background),
 
436
        XmRImmediate, (XtPointer) INVALID_PIXEL
 
437
    },
 
438
 
 
439
    {
 
440
        XmNforeground, XmCForeground, XmRPixel,
 
441
        sizeof(Pixel),
 
442
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.foreground),
 
443
        XmRImmediate, (XtPointer) INVALID_PIXEL
 
444
    },
 
445
 
 
446
    {
 
447
        XmNtopShadowColor, XmCTopShadowColor, XmRPixel,
 
448
        sizeof(Pixel),
 
449
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.top_shadow_color),
 
450
        XmRImmediate, (XtPointer) INVALID_PIXEL
 
451
    },
 
452
 
 
453
    {
 
454
        XmNtopShadowPixmap, XmCTopShadowPixmap, XmRNoScalingDynamicPixmap,
 
455
        sizeof(Pixmap),
 
456
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.top_shadow_pixmap),
 
457
        XmRImmediate, (XtPointer) INVALID_PIXMAP
 
458
    },
 
459
 
 
460
    {
 
461
        XmNbottomShadowColor, XmCBottomShadowColor, XmRPixel,
 
462
        sizeof(Pixel),
 
463
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.bottom_shadow_color),
 
464
        XmRImmediate, (XtPointer) INVALID_PIXEL
 
465
    },
 
466
 
 
467
    {
 
468
        XmNbottomShadowPixmap, XmCBottomShadowPixmap, XmRNoScalingDynamicPixmap,
 
469
        sizeof(Pixmap),
 
470
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.bottom_shadow_pixmap),
 
471
        XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
 
472
    },
 
473
 
 
474
    {
 
475
        XmNhighlightColor, XmCHighlightColor, XmRPixel,
 
476
        sizeof(Pixel),
 
477
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.highlight_color),
 
478
        XmRImmediate, (XtPointer) INVALID_PIXEL
 
479
    },
 
480
 
 
481
    {
 
482
        XmNhighlightPixmap, XmCHighlightPixmap, XmRNoScalingDynamicPixmap,
 
483
        sizeof(Pixmap),
 
484
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.highlight_pixmap),
 
485
        XmRImmediate, (XtPointer) INVALID_PIXMAP
 
486
    }
 
487
};
 
488
 
 
489
/*  Definition for resources that need special processing in get values  */
 
490
 
 
491
static XmSyntheticResource syn_resources[] =
 
492
{
 
493
    {
 
494
        XmNlabelString,
 
495
        sizeof(XmString), XtOffsetOf(XmLabelGadgetRec, label._label),
 
496
        GetLabelString, NULL
 
497
    },
 
498
 
 
499
    {
 
500
        XmNaccelerator,
 
501
        sizeof(String), XtOffsetOf(XmLabelGadgetRec, label.accelerator),
 
502
        GetAccelerator, NULL
 
503
    },
 
504
 
 
505
    {
 
506
        XmNacceleratorText,
 
507
        sizeof(XmString), XtOffsetOf(XmLabelGadgetRec, label._acc_text),
 
508
        GetAcceleratorText, NULL
 
509
    },
 
510
 
 
511
    {
 
512
        XmNmnemonicCharSet,
 
513
        sizeof(XmStringCharSet), XtOffsetOf(XmLabelGadgetRec,label.mnemonicCharset),
 
514
        GetMnemonicCharset, NULL
 
515
    },
 
516
    
 
517
    {
 
518
        XmNpixmapTextPadding,
 
519
        sizeof(Dimension), XtOffsetOf(XmLabelGadgetRec, label.pixmap_text_padding),
 
520
        FromPaddingPixels, (XmImportProc) ToPaddingPixels
 
521
    }
 
522
};
 
523
 
 
524
static XmSyntheticResource cache_syn_resources[] =
 
525
{
 
526
    {
 
527
        XmNmarginWidth,
 
528
        sizeof(Dimension),
 
529
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_width),
 
530
        XmeFromHorizontalPixels, XmeToHorizontalPixels
 
531
    },
 
532
 
 
533
    {
 
534
        XmNmarginHeight,
 
535
        sizeof(Dimension),
 
536
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_height),
 
537
        XmeFromVerticalPixels, XmeToVerticalPixels
 
538
    },
 
539
 
 
540
    {
 
541
        XmNmarginLeft,
 
542
        sizeof(Dimension),
 
543
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_left),
 
544
        XmeFromHorizontalPixels, XmeToHorizontalPixels
 
545
    },
 
546
 
 
547
    {
 
548
        XmNmarginRight,
 
549
        sizeof(Dimension),
 
550
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_right),
 
551
        XmeFromHorizontalPixels, XmeToHorizontalPixels
 
552
    },
 
553
 
 
554
    {
 
555
        XmNmarginTop,
 
556
        sizeof(Dimension),
 
557
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_top),
 
558
        XmeFromVerticalPixels, XmeToVerticalPixels
 
559
    },
 
560
 
 
561
    {
 
562
        XmNmarginBottom,
 
563
        sizeof(Dimension),
 
564
        XtOffsetOf(XmLabelGCacheObjRec, label_cache.margin_bottom),
 
565
        XmeFromVerticalPixels, XmeToVerticalPixels
 
566
    }
 
567
};
 
568
 
 
569
static XmCacheClassPart LabelClassCachePart =
 
570
{
 
571
    {                                             /* head of class cache list */
 
572
        NULL, 0, 0
 
573
    },
 
574
    _XmCacheCopy,                                 /* Copy routine               */
 
575
    _XmCacheDelete,                               /* Delete routine     */
 
576
    _XmLabelCacheCompare                          /* Comparison routine         */
 
577
};
 
578
 
 
579
static XmBaseClassExtRec labelBaseClassExtRec =
 
580
{
 
581
    NULL,                                         /* Next extension         */
 
582
    NULLQUARK,                                    /* record type XmQmotif   */
 
583
    XmBaseClassExtVersion,                        /* version                */
 
584
    sizeof(XmBaseClassExtRec),                    /* size                   */
 
585
    XmInheritInitializePrehook,                   /* initialize prehook     */
 
586
    SetValuesPrehook,                             /* set_values prehook     */
 
587
    InitializePosthook,                           /* initialize posthook    */
 
588
    SetValuesPosthook,                            /* set_values posthook    */
 
589
    (WidgetClass)&xmLabelGCacheObjClassRec,       /* secondary class        */
 
590
    SecondaryObjectCreate,                        /* creation proc          */
 
591
    GetLabelBGClassSecResData,                    /* getSecResData          */
 
592
    {                                             /* fast subclass          */
 
593
        0
 
594
    },
 
595
    GetValuesPrehook,                             /* get_values prehook     */
 
596
    GetValuesPosthook,                            /* get_values posthook    */
 
597
    NULL,                                         /* classPartInitPrehook   */
 
598
    NULL,                                         /* classPartInitPosthook  */
 
599
    NULL,                                         /* ext_resources          */
 
600
    NULL,                                         /* compiled_ext_resources */
 
601
    0,                                            /* num_ext_resources      */
 
602
    FALSE,                                        /* use_sub_resources      */
 
603
    XmInheritWidgetNavigable,                     /* widgetNavigable        */
 
604
    XmInheritFocusChange                          /* focusChange            */
 
605
};
 
606
 
 
607
externaldef (xmlabelgcacheobjclassrec)
 
608
XmLabelGCacheObjClassRec xmLabelGCacheObjClassRec =
 
609
{
 
610
    {
 
611
        (WidgetClass) &xmExtClassRec,             /* superclass          */
 
612
        "XmLabelGadget",                          /* class_name          */
 
613
        sizeof(XmLabelGCacheObjRec),              /* widget_size         */
 
614
        NULL,                                     /* class_initialize    */
 
615
        NULL,                                     /* chained class init  */
 
616
        False,                                    /* class_inited        */
 
617
        NULL,                                     /* initialize          */
 
618
        NULL,                                     /* initialize hook     */
 
619
        NULL,                                     /* realize             */
 
620
        NULL,                                     /* actions             */
 
621
        0,                                        /* num_actions         */
 
622
        cache_resources,                          /* resources           */
 
623
        XtNumber(cache_resources),                /* num_resources       */
 
624
        NULLQUARK,                                /* xrm_class           */
 
625
        False,                                    /* compress_motion     */
 
626
        False,                                    /* compress_exposure   */
 
627
        False,                                    /* compress enter/exit */
 
628
        False,                                    /* visible_interest    */
 
629
        NULL,                                     /* destroy             */
 
630
        NULL,                                     /* resize              */
 
631
        NULL,                                     /* expose              */
 
632
        NULL,                                     /* set_values          */
 
633
        NULL,                                     /* set values hook     */
 
634
        NULL,                                     /* set values almost   */
 
635
        NULL,                                     /* get values hook     */
 
636
        NULL,                                     /* accept_focus        */
 
637
        XtVersion,                                /* version             */
 
638
        NULL,                                     /* callback offsetlst  */
 
639
        NULL,                                     /* default trans       */
 
640
        NULL,                                     /* query geo proc      */
 
641
        NULL,                                     /* display accelerator */
 
642
        NULL                                      /* extension record    */
 
643
    },
 
644
 
 
645
    {
 
646
        cache_syn_resources,                      /* synthetic resources */
 
647
        XtNumber(cache_syn_resources),            /* num_syn_resources   */
 
648
        NULL                                      /* extension           */
 
649
    }
 
650
};
 
651
 
 
652
/* This is the class record that gets set at compile/link time  */
 
653
/* this is what is passed to the widget create routine as the   */
 
654
/* the class.  All fields must be inited at compile time.       */
 
655
 
 
656
static XmGadgetClassExtRec _XmLabelGadClassExtRec =
 
657
{
 
658
    NULL,                                         /* next_extension     */
 
659
    NULLQUARK,                                    /* record_type                */
 
660
    XmGadgetClassExtVersion,                      /* version            */
 
661
    sizeof(XmGadgetClassExtRec),                  /* record_size                */
 
662
    XmLabelGadgetGetBaselines,                    /* widget_baseline    */
 
663
    XmLabelGadgetGetDisplayRect,                  /* widget_display_rect        */
 
664
    XmLabelGadgetMarginsProc,                     /* widget_margins */
 
665
};
 
666
 
 
667
externaldef (xmlabelgadgetclassrec)
 
668
XmLabelGadgetClassRec xmLabelGadgetClassRec =
 
669
{
 
670
    {
 
671
        (WidgetClass) &xmGadgetClassRec,          /* superclass      */
 
672
        "XmLabelGadget",                          /* class_name      */
 
673
        sizeof(XmLabelGadgetRec),                 /* widget_size             */
 
674
        ClassInitialize,                          /* class_initialize    */
 
675
        ClassPartInitialize,                      /* chained class init  */
 
676
        False,                                    /* class_inited            */
 
677
        Initialize,                               /* initialize      */
 
678
        NULL,                                     /* initialize hook     */
 
679
        NULL,                                     /* realize         */
 
680
        NULL,                                     /* actions         */
 
681
        0,                                        /* num_actions             */
 
682
        resources,                                /* resources       */
 
683
        XtNumber(resources),                      /* num_resources           */
 
684
        NULLQUARK,                                /* xrm_class       */
 
685
        True,                                     /* compress_motion     */
 
686
        XtExposeCompressMaximal,                  /* compress_exposure   */
 
687
        True,                                     /* compress enter/exit */
 
688
        False,                                    /* visible_interest    */
 
689
        Destroy,                                  /* destroy         */
 
690
        Resize,                                   /* resize                  */
 
691
        Redisplay,                                /* expose                  */
 
692
        SetValues,                                /* set_values      */
 
693
        NULL,                                     /* set values hook     */
 
694
        SetValuesAlmost,                          /* set values almost   */
 
695
        NULL,                                     /* get values hook     */
 
696
        NULL,                                     /* accept_focus            */
 
697
        XtVersion,                                /* version         */
 
698
        NULL,                                     /* callback offsetlst  */
 
699
        NULL,                                     /* default trans           */
 
700
        QueryGeometry,                            /* query geo proc          */
 
701
        NULL,                                     /* display accelerator */
 
702
        (XtPointer)&labelBaseClassExtRec          /* extension record    */
 
703
    },
 
704
 
 
705
    {                                             /* XmGadgetClassPart  */
 
706
        BorderHighlight,                          /* border_highlight   */
 
707
        XmInheritBorderUnhighlight,               /* border_unhighlight */
 
708
        NULL,                                     /* arm_and_activate   */
 
709
        InputDispatch,                            /* input dispatch     */
 
710
        XmInheritVisualChange,                    /* visual_change      */
 
711
        syn_resources,                            /* syn resources      */
 
712
        XtNumber(syn_resources),                  /* num syn_resources  */
 
713
        &LabelClassCachePart,                     /* class cache part   */
 
714
        (XtPointer)&_XmLabelGadClassExtRec        /* extension          */
 
715
    },
 
716
 
 
717
    {                                             /* XmLabelGadgetClassPart   */
 
718
        SetOverrideCallback,                      /* override_callback        */
 
719
        NULL,                                     /* menu procedure interface */
 
720
        NULL                                      /* extension record         */
 
721
    }
 
722
};
 
723
 
 
724
externaldef(xmlabelgadgetclass) WidgetClass xmLabelGadgetClass =
 
725
(WidgetClass) &xmLabelGadgetClassRec;
 
726
 
 
727
/*ARGSUSED*/
 
728
static Pixmap
 
729
GetTopShadowPixmapDefault(Widget widget)
 
730
{
 
731
    XmLabelGadget lg = (XmLabelGadget) widget;
 
732
    XmManagerWidget mw = (XmManagerWidget)XtParent(lg);
 
733
    Pixmap result = XmUNSPECIFIED_PIXMAP;
 
734
 
 
735
    if (LabG_TopShadowColor(lg) == LabG_Background(lg))
 
736
        result = XmGetPixmapByDepth (XtScreen (lg), XmS50_foreground,
 
737
            LabG_TopShadowColor(lg),
 
738
            LabG_Foreground(lg),
 
739
            mw->core.depth);
 
740
 
 
741
    else if (DefaultDepthOfScreen (XtScreen (widget)) == 1)
 
742
        result = XmGetPixmapByDepth (XtScreen (lg), XmS50_foreground,
 
743
                LabG_TopShadowColor(lg),
 
744
                LabG_Background(lg),
 
745
                mw->core.depth);
 
746
 
 
747
    return result;
 
748
}
 
749
 
 
750
 
 
751
/*ARGSUSED*/
 
752
static Pixmap
 
753
GetLabelHighlightPixmapDefault(Widget widget)
 
754
{
 
755
    XmLabelGadget lg = (XmLabelGadget) widget;
 
756
    XmManagerWidget mw = (XmManagerWidget)XtParent(lg);
 
757
    Pixmap result = XmUNSPECIFIED_PIXMAP;
 
758
 
 
759
    if (LabG_HighlightColor(lg) == LabG_Background(lg))
 
760
        result = XmGetPixmapByDepth (XtScreen (lg), XmS50_foreground,
 
761
            LabG_HighlightColor(lg),
 
762
            LabG_Foreground(lg),
 
763
            mw->core.depth);
 
764
 
 
765
    return result;
 
766
}
 
767
 
 
768
 
 
769
/*******************************************************************
 
770
 *
 
771
 *  _XmLabelCacheCompare
 
772
 *
 
773
 *******************************************************************/
 
774
 
 
775
int
 
776
_XmLabelCacheCompare(
 
777
XtPointer A,
 
778
XtPointer B)
 
779
{
 
780
    XmLabelGCacheObjPart *label_inst = (XmLabelGCacheObjPart *) A;
 
781
    XmLabelGCacheObjPart *label_cache_inst = (XmLabelGCacheObjPart *) B;
 
782
 
 
783
    if ((label_inst->label_type == label_cache_inst->label_type) &&
 
784
        (label_inst->alignment == label_cache_inst->alignment) &&
 
785
        (label_inst->string_direction == label_cache_inst->string_direction) &&
 
786
        (label_inst->margin_height == label_cache_inst->margin_height) &&
 
787
        (label_inst->margin_width == label_cache_inst->margin_width) &&
 
788
        (label_inst->margin_left == label_cache_inst->margin_left) &&
 
789
        (label_inst->margin_right == label_cache_inst->margin_right) &&
 
790
        (label_inst->margin_top == label_cache_inst->margin_top) &&
 
791
        (label_inst->margin_bottom == label_cache_inst->margin_bottom) &&
 
792
        (label_inst->recompute_size == label_cache_inst->recompute_size) &&
 
793
        (label_inst->skipCallback == label_cache_inst->skipCallback) &&
 
794
        (label_inst->menu_type == label_cache_inst->menu_type) &&
 
795
        (label_inst->background_GC == label_cache_inst->background_GC) &&
 
796
        (label_inst->top_shadow_GC == label_cache_inst->top_shadow_GC) &&
 
797
        (label_inst->bottom_shadow_GC == label_cache_inst->bottom_shadow_GC) &&
 
798
        (label_inst->highlight_GC == label_cache_inst->highlight_GC) &&
 
799
        (label_inst->foreground == label_cache_inst->foreground) &&
 
800
        (label_inst->background == label_cache_inst->background) &&
 
801
        (label_inst->top_shadow_color == label_cache_inst->top_shadow_color) &&
 
802
        (label_inst->top_shadow_pixmap == label_cache_inst->top_shadow_pixmap) &&
 
803
        (label_inst->bottom_shadow_color ==
 
804
        label_cache_inst->bottom_shadow_color) &&
 
805
        (label_inst->bottom_shadow_pixmap ==
 
806
        label_cache_inst->bottom_shadow_pixmap) &&
 
807
        (label_inst->highlight_color == label_cache_inst->highlight_color) &&
 
808
        (label_inst->highlight_pixmap == label_cache_inst->highlight_pixmap))
 
809
        return 1;
 
810
    else
 
811
        return 0;
 
812
}
 
813
 
 
814
 
 
815
/***********************************************************
 
816
 *
 
817
 *  ClassInitialize
 
818
 *
 
819
 ************************************************************/
 
820
 
 
821
static void
 
822
ClassInitialize(void)
 
823
{
 
824
    labelBaseClassExtRec.record_type = XmQmotif;
 
825
 
 
826
    /* Install menu savvy on just this class */
 
827
    XmeTraitSet((XtPointer) &xmLabelGadgetClassRec,
 
828
        XmQTmenuSavvy, (XtPointer) &MenuSavvyGadgetRecord);
 
829
 
 
830
}
 
831
 
 
832
 
 
833
void
 
834
_XmLabelGCloneMenuSavvy(WidgetClass wc,
 
835
XmMenuSavvyTrait mst)
 
836
{
 
837
    /* Modify and reinstall menu savvy trait */
 
838
    if (mst->version == -1)
 
839
    {
 
840
        mst->version = MenuSavvyGadgetRecord.version;
 
841
        mst->disableCallback = MenuSavvyGadgetRecord.disableCallback;
 
842
        mst->getAccelerator = MenuSavvyGadgetRecord.getAccelerator;
 
843
        mst->getMnemonic = MenuSavvyGadgetRecord.getMnemonic;
 
844
    }
 
845
 
 
846
    /* Install the new record */
 
847
    XmeTraitSet((XtPointer) wc, XmQTmenuSavvy, (XtPointer) mst);
 
848
}
 
849
 
 
850
 
 
851
/************************************************************************
 
852
 *
 
853
 *  ClassPartInitialize
 
854
 *      Processes the class fields which need to be inherited.
 
855
 *
 
856
 ************************************************************************/
 
857
 
 
858
static void
 
859
ClassPartInitialize(WidgetClass cl)
 
860
{
 
861
    register XmLabelGadgetClass wc = (XmLabelGadgetClass) cl;
 
862
    XmLabelGadgetClass super = (XmLabelGadgetClass)wc->rect_class.superclass;
 
863
    XmGadgetClassExt *wcePtr, *scePtr;
 
864
 
 
865
    if (wc->label_class.setOverrideCallback == XmInheritSetOverrideCallback)
 
866
        wc->label_class.setOverrideCallback =
 
867
            super->label_class.setOverrideCallback;
 
868
 
 
869
    if (wc->rect_class.resize == XmInheritResize)
 
870
        wc->rect_class.resize = super->rect_class.resize;
 
871
 
 
872
    wcePtr = _XmGetGadgetClassExtPtr(wc, NULLQUARK);
 
873
    scePtr = _XmGetGadgetClassExtPtr(super, NULLQUARK);
 
874
 
 
875
    if ((*wcePtr)->widget_baseline == XmInheritBaselineProc)
 
876
        (*wcePtr)->widget_baseline = (*scePtr)->widget_baseline;
 
877
 
 
878
    if ((*wcePtr)->widget_display_rect == XmInheritDisplayRectProc)
 
879
        (*wcePtr)->widget_display_rect  = (*scePtr)->widget_display_rect;
 
880
 
 
881
    _XmFastSubclassInit (((WidgetClass)wc), XmLABEL_GADGET_BIT);
 
882
 
 
883
    /* Install transfer trait */
 
884
    XmeTraitSet((XtPointer)cl, XmQTtransfer, (XtPointer) &LabelGTransfer);
 
885
    XmeTraitSet((XtPointer) cl, XmQTaccessTextual, (XtPointer)
 
886
        &_XmLabel_AccessTextualRecord);
 
887
 
 
888
    /* Install the careParentVisual trait for all subclasses as well. */
 
889
    XmeTraitSet((XtPointer)cl, XmQTcareParentVisual, (XtPointer)&LabelGCVT);
 
890
 
 
891
    /* Install the accessColors trait for all subclasses as well. */
 
892
    XmeTraitSet((XtPointer)cl, XmQTaccessColors, (XtPointer)&labACT);
 
893
}
 
894
 
 
895
 
 
896
/************************************************************************
 
897
 *
 
898
 *  SecondaryObjectCreate
 
899
 *
 
900
 ************************************************************************/
 
901
 
 
902
/*ARGSUSED*/
 
903
static void
 
904
SecondaryObjectCreate(Widget req,
 
905
Widget new_w,
 
906
ArgList args,
 
907
Cardinal *num_args)
 
908
{
 
909
    XmBaseClassExt *cePtr;
 
910
    XmWidgetExtData extData;
 
911
    WidgetClass   wc;
 
912
    Cardinal  size;
 
913
    XtPointer newSec, reqSec;
 
914
 
 
915
    _XmProcessLock();
 
916
    cePtr = _XmGetBaseClassExtPtr(XtClass(new_w), XmQmotif);
 
917
 
 
918
    wc = (*cePtr)->secondaryObjectClass;
 
919
    size = wc->core_class.widget_size;
 
920
 
 
921
    newSec = _XmExtObjAlloc(size);
 
922
    reqSec = _XmExtObjAlloc(size);
 
923
    _XmProcessUnlock();
 
924
 
 
925
    /*
 
926
     * Update pointers in instance records now so references to resources
 
927
     * in the cache record will be valid for use in CallProcs.
 
928
     * CallProcs are invoked by XtGetSubresources().
 
929
     */
 
930
    LabG_Cache(new_w) = &(((XmLabelGCacheObject)newSec)->label_cache);
 
931
    LabG_Cache(req) = &(((XmLabelGCacheObject)reqSec)->label_cache);
 
932
 
 
933
    /*
 
934
     * Fetch the resources in superclass to subclass order
 
935
     */
 
936
 
 
937
    XtGetSubresources(new_w, newSec, NULL, NULL,
 
938
        wc->core_class.resources,
 
939
        wc->core_class.num_resources,
 
940
        args, *num_args);
 
941
 
 
942
    extData = (XmWidgetExtData) XtCalloc(1, sizeof(XmWidgetExtDataRec));
 
943
    extData->widget = (Widget)newSec;
 
944
    extData->reqWidget = (Widget)reqSec;
 
945
 
 
946
    ((XmLabelGCacheObject)newSec)->ext.extensionType = XmCACHE_EXTENSION;
 
947
    ((XmLabelGCacheObject)newSec)->ext.logicalParent = new_w;
 
948
 
 
949
    _XmPushWidgetExtData((Widget) new_w, extData,
 
950
        ((XmLabelGCacheObject)newSec)->ext.extensionType);
 
951
    memcpy(reqSec, newSec, size);
 
952
}
 
953
 
 
954
 
 
955
/************************************************************************
 
956
 *
 
957
 *  InitializePosthook
 
958
 *
 
959
 ************************************************************************/
 
960
 
 
961
/*ARGSUSED*/
 
962
static void
 
963
InitializePosthook(Widget req,
 
964
Widget new_w,
 
965
ArgList args,
 
966
Cardinal *num_args)
 
967
{
 
968
    XmWidgetExtData     ext;
 
969
    XmLabelGadget lw = (XmLabelGadget)new_w;
 
970
 
 
971
    /*
 
972
     * - register parts in cache.
 
973
     * - update cache pointers
 
974
     * - and free req
 
975
     */
 
976
 
 
977
    _XmProcessLock();
 
978
    LabG_Cache(lw) = (XmLabelGCacheObjPart *)
 
979
        _XmCachePart(LabG_ClassCachePart(lw),
 
980
        (XtPointer) LabG_Cache(lw),
 
981
        sizeof(XmLabelGCacheObjPart));
 
982
 
 
983
    /*
 
984
     * Might want to break up into per-class work that gets explicitly
 
985
     * chained.  For right now, each class has to replicate all
 
986
     * superclass logic in hook routine.
 
987
     */
 
988
 
 
989
    /*
 
990
     * free the req subobject used for comparisons
 
991
     */
 
992
    _XmPopWidgetExtData((Widget) lw, &ext, XmCACHE_EXTENSION);
 
993
    _XmExtObjFree((XtPointer)ext->widget);
 
994
    _XmExtObjFree((XtPointer)ext->reqWidget);
 
995
    _XmProcessUnlock();
 
996
    XtFree((char *) ext);
 
997
}
 
998
 
 
999
 
 
1000
/************************************************************************
 
1001
 *
 
1002
 *  SetValuesPrehook
 
1003
 *
 
1004
 ************************************************************************/
 
1005
 
 
1006
/*ARGSUSED*/
 
1007
static Boolean
 
1008
SetValuesPrehook(Widget oldParent,
 
1009
Widget refParent,
 
1010
Widget newParent,
 
1011
ArgList args,
 
1012
Cardinal *num_args)
 
1013
{
 
1014
    XmWidgetExtData     extData;
 
1015
    XmBaseClassExt      *cePtr;
 
1016
    WidgetClass         ec;
 
1017
    XmLabelGCacheObject newSec, reqSec;
 
1018
    Cardinal        size;
 
1019
 
 
1020
    _XmProcessLock();
 
1021
    cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
 
1022
    ec = (*cePtr)->secondaryObjectClass;
 
1023
    size = ec->core_class.widget_size;
 
1024
 
 
1025
    newSec = (XmLabelGCacheObject)_XmExtObjAlloc(size);
 
1026
    reqSec = (XmLabelGCacheObject)_XmExtObjAlloc(size);
 
1027
    _XmProcessUnlock();
 
1028
 
 
1029
    newSec->object.self = (Widget)newSec;
 
1030
    newSec->object.widget_class = ec;
 
1031
    newSec->object.parent = XtParent(newParent);
 
1032
    newSec->object.xrm_name = newParent->core.xrm_name;
 
1033
    newSec->object.being_destroyed = False;
 
1034
    newSec->object.destroy_callbacks = NULL;
 
1035
    newSec->object.constraints = NULL;
 
1036
 
 
1037
    newSec->ext.logicalParent = newParent;
 
1038
    newSec->ext.extensionType = XmCACHE_EXTENSION;
 
1039
 
 
1040
    memcpy(&(newSec->label_cache),
 
1041
        LabG_Cache(newParent),
 
1042
        sizeof(XmLabelGCacheObjPart));
 
1043
 
 
1044
    extData = (XmWidgetExtData) XtCalloc(1, sizeof(XmWidgetExtDataRec));
 
1045
    extData->widget = (Widget)newSec;
 
1046
    extData->reqWidget = (Widget)reqSec;
 
1047
    _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
 
1048
 
 
1049
    XtSetSubvalues((XtPointer)newSec,
 
1050
        ec->core_class.resources,
 
1051
        ec->core_class.num_resources,
 
1052
        args, *num_args);
 
1053
 
 
1054
    _XmExtImportArgs((Widget)newSec, args, num_args);
 
1055
 
 
1056
    memcpy((XtPointer)reqSec, (XtPointer)newSec, size);
 
1057
 
 
1058
    LabG_Cache(newParent) = &((newSec)->label_cache);
 
1059
    LabG_Cache(refParent) = &((reqSec)->label_cache);
 
1060
 
 
1061
    return FALSE;
 
1062
}
 
1063
 
 
1064
 
 
1065
/************************************************************************
 
1066
 *
 
1067
 *  GetValuesPrehook
 
1068
 *
 
1069
 ************************************************************************/
 
1070
 
 
1071
/*ARGSUSED*/
 
1072
static void
 
1073
GetValuesPrehook(Widget newParent,
 
1074
ArgList args,
 
1075
Cardinal *num_args)
 
1076
{
 
1077
    XmWidgetExtData     extData;
 
1078
    XmBaseClassExt      *cePtr;
 
1079
    WidgetClass         ec;
 
1080
    XmLabelGCacheObject newSec;
 
1081
    Cardinal            size;
 
1082
 
 
1083
    _XmProcessLock();
 
1084
    cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
 
1085
    ec = (*cePtr)->secondaryObjectClass;
 
1086
    size = ec->core_class.widget_size;
 
1087
 
 
1088
    newSec = (XmLabelGCacheObject)_XmExtObjAlloc(size);
 
1089
    _XmProcessUnlock();
 
1090
 
 
1091
    newSec->object.self = (Widget)newSec;
 
1092
    newSec->object.widget_class = ec;
 
1093
    newSec->object.parent = XtParent(newParent);
 
1094
    newSec->object.xrm_name = newParent->core.xrm_name;
 
1095
    newSec->object.being_destroyed = False;
 
1096
    newSec->object.destroy_callbacks = NULL;
 
1097
    newSec->object.constraints = NULL;
 
1098
 
 
1099
    newSec->ext.logicalParent = newParent;
 
1100
    newSec->ext.extensionType = XmCACHE_EXTENSION;
 
1101
 
 
1102
    memcpy(&(newSec->label_cache),
 
1103
        LabG_Cache(newParent),
 
1104
        sizeof(XmLabelGCacheObjPart));
 
1105
 
 
1106
    extData = (XmWidgetExtData) XtCalloc(1, sizeof(XmWidgetExtDataRec));
 
1107
    extData->widget = (Widget)newSec;
 
1108
    _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
 
1109
 
 
1110
    XtGetSubvalues((XtPointer)newSec,
 
1111
        ec->core_class.resources,
 
1112
        ec->core_class.num_resources,
 
1113
        args, *num_args);
 
1114
 
 
1115
    _XmExtGetValuesHook((Widget)newSec, args, num_args);
 
1116
}
 
1117
 
 
1118
 
 
1119
/************************************************************************
 
1120
 *
 
1121
 *  GetValuesPosthook
 
1122
 *
 
1123
 ************************************************************************/
 
1124
 
 
1125
/*ARGSUSED*/
 
1126
static void
 
1127
GetValuesPosthook(Widget new_w,
 
1128
ArgList args,
 
1129
Cardinal *num_args)
 
1130
{
 
1131
    XmWidgetExtData ext;
 
1132
 
 
1133
    _XmPopWidgetExtData(new_w, &ext, XmCACHE_EXTENSION);
 
1134
 
 
1135
    _XmProcessLock();
 
1136
    _XmExtObjFree((XtPointer)ext->widget);
 
1137
    _XmProcessUnlock();
 
1138
 
 
1139
    XtFree((char *) ext);
 
1140
}
 
1141
 
 
1142
 
 
1143
/************************************************************************
 
1144
 *
 
1145
 *  SetValuesPosthook
 
1146
 *
 
1147
 ************************************************************************/
 
1148
 
 
1149
/*ARGSUSED*/
 
1150
static Boolean
 
1151
SetValuesPosthook(Widget current,
 
1152
Widget req,
 
1153
Widget new_w,
 
1154
ArgList args,
 
1155
Cardinal *num_args)
 
1156
{
 
1157
    XmWidgetExtData ext;
 
1158
 
 
1159
    /*
 
1160
     * - register parts in cache.
 
1161
     * - update cache pointers
 
1162
     * - and free req
 
1163
     */
 
1164
 
 
1165
    /* assign if changed! */
 
1166
    _XmProcessLock();
 
1167
    if (!_XmLabelCacheCompare((XtPointer)LabG_Cache(new_w),
 
1168
        (XtPointer)LabG_Cache(current)))
 
1169
 
 
1170
    {
 
1171
        /* delete the old one */
 
1172
        _XmCacheDelete((XtPointer) LabG_Cache(current));
 
1173
        LabG_Cache(new_w) = (XmLabelGCacheObjPart *)
 
1174
            _XmCachePart(LabG_ClassCachePart(new_w),
 
1175
            (XtPointer) LabG_Cache(new_w),
 
1176
            sizeof(XmLabelGCacheObjPart));
 
1177
    }
 
1178
    else
 
1179
        LabG_Cache(new_w) = LabG_Cache(current);
 
1180
 
 
1181
    _XmPopWidgetExtData(new_w, &ext, XmCACHE_EXTENSION);
 
1182
 
 
1183
    _XmExtObjFree((XtPointer)ext->widget);
 
1184
    _XmExtObjFree((XtPointer)ext->reqWidget);
 
1185
 
 
1186
    XtFree((char *) ext);
 
1187
    _XmProcessUnlock();
 
1188
 
 
1189
    return FALSE;
 
1190
}
 
1191
 
 
1192
 
 
1193
static void
 
1194
BorderHighlight(Widget w)
 
1195
{
 
1196
    XmLabelGadget lg = (XmLabelGadget) w;
 
1197
 
 
1198
    if (lg->rectangle.width == 0 ||
 
1199
        lg->rectangle.height == 0 ||
 
1200
        lg->gadget.highlight_thickness == 0)
 
1201
    {
 
1202
        return;
 
1203
    }
 
1204
 
 
1205
    lg->gadget.highlighted = True;
 
1206
    lg->gadget.highlight_drawn = True;
 
1207
 
 
1208
    /* CR 7330: Use XmeDrawHighlight, not _XmDrawHighlight. */
 
1209
    XmeDrawHighlight(XtDisplay((Widget) lg), XtWindow((Widget) lg),
 
1210
        LabG_HighlightGC(lg),
 
1211
        lg->rectangle.x, lg->rectangle.y,
 
1212
        lg->rectangle.width, lg->rectangle.height,
 
1213
        lg->gadget.highlight_thickness);
 
1214
}
 
1215
 
 
1216
 
 
1217
/************************************************************************
 
1218
 *
 
1219
 *  SetNormalGC
 
1220
 *      Create the normal and insensitive GC's for the gadget.
 
1221
 *
 
1222
 ************************************************************************/
 
1223
 
 
1224
static void
 
1225
SetNormalGC(XmLabelGadget lw)
 
1226
{
 
1227
    XGCValues       values;
 
1228
    XtGCMask        valueMask, dynamicMask;
 
1229
    XmManagerWidget mw;
 
1230
    XFontStruct     *fs = (XFontStruct *) NULL;
 
1231
 
 
1232
    mw = (XmManagerWidget) XtParent(lw);
 
1233
 
 
1234
    valueMask = GCForeground | GCBackground | GCGraphicsExposures;
 
1235
    dynamicMask = GCClipXOrigin | GCClipYOrigin | GCClipMask;
 
1236
 
 
1237
    values.foreground = LabG_Foreground(lw);
 
1238
    values.background = LabG_Background(lw);
 
1239
    values.graphics_exposures = FALSE;
 
1240
 
 
1241
    if (XmeRenderTableGetDefaultFont(LabG_Font(lw), &fs))
 
1242
    {
 
1243
        valueMask |= GCFont;
 
1244
        values.font = fs->fid;
 
1245
    }
 
1246
 
 
1247
    LabG_NormalGC(lw) = XtAllocateGC((Widget) mw, 0, valueMask, &values,
 
1248
        dynamicMask, 0);
 
1249
 
 
1250
    valueMask |= GCFillStyle | GCStipple;
 
1251
    values.foreground = LabG_Background(lw); 
 
1252
    values.background = LabG_Foreground(lw);
 
1253
    values.fill_style = FillOpaqueStippled;
 
1254
 
 
1255
    values.stipple = _XmGetInsensitiveStippleBitmap((Widget) lw);
 
1256
 
 
1257
    LabG_InsensitiveGC(lw) = XtAllocateGC((Widget) mw, 0, valueMask, &values,
 
1258
        dynamicMask, 0);
 
1259
}
 
1260
 
 
1261
 
 
1262
/************************************************************************
 
1263
 *
 
1264
 *  _XmLabelSetBackgroundGC
 
1265
 *     Get the graphics context used for drawing the shadows.
 
1266
 *
 
1267
 ************************************************************************/
 
1268
 
 
1269
void
 
1270
_XmLabelSetBackgroundGC(XmLabelGadget lw)
 
1271
{
 
1272
    XGCValues   values;
 
1273
    XtGCMask    valueMask;
 
1274
    XmManagerWidget mw;
 
1275
    XFontStruct     *fs = (XFontStruct *) NULL;
 
1276
 
 
1277
    mw = (XmManagerWidget) XtParent(lw);
 
1278
 
 
1279
    if (lw->label.fill_bg_box != _XmALWAYS_FILL_BG_BOX)
 
1280
    {
 
1281
        if ((mw->core.background_pixel != LabG_Background(lw)) &&
 
1282
            (mw->core.background_pixmap == XmUNSPECIFIED_PIXMAP))
 
1283
            lw->label.fill_bg_box = _XmFILL_BG_BOX;
 
1284
        else
 
1285
            lw->label.fill_bg_box = _XmPLAIN_BG_BOX;
 
1286
    }
 
1287
 
 
1288
    valueMask = GCForeground | GCBackground | GCGraphicsExposures | GCClipMask;
 
1289
    values.foreground = LabG_Background(lw);
 
1290
    values.background = LabG_Foreground(lw);
 
1291
    values.graphics_exposures = FALSE;
 
1292
    values.clip_mask = None;
 
1293
 
 
1294
    /* CR 8980: Use parent's background_pixmap if possible. */
 
1295
    if (mw->core.background_pixmap != XmUNSPECIFIED_PIXMAP)
 
1296
    {
 
1297
        int depth;
 
1298
 
 
1299
        XmeGetPixmapData(XtScreen((Widget)lw), mw->core.background_pixmap,
 
1300
            NULL, &depth, NULL, NULL, NULL, NULL, NULL, NULL);
 
1301
 
 
1302
        if (depth == 1)
 
1303
        {
 
1304
            valueMask |= GCFillStyle | GCStipple ;
 
1305
            values.fill_style = FillOpaqueStippled;
 
1306
            values.stipple = mw->core.background_pixmap;
 
1307
        }
 
1308
        else
 
1309
        {
 
1310
            valueMask |= GCFillStyle | GCTile ;
 
1311
            values.fill_style = FillTiled;
 
1312
            values.tile = mw->core.background_pixmap;
 
1313
        }
 
1314
    }
 
1315
 
 
1316
    if (XmeRenderTableGetDefaultFont(LabG_Font(lw), &fs))
 
1317
    {
 
1318
        valueMask |= GCFont;
 
1319
        values.font = fs->fid;
 
1320
    }
 
1321
 
 
1322
    LabG_BackgroundGC(lw) = XtGetGC ((Widget) mw, valueMask, &values);
 
1323
}
 
1324
 
 
1325
 
 
1326
/************************************************************************
 
1327
 *
 
1328
 * _XmCalcLabelGDimensions()
 
1329
 *   Calculates the dimensionsof the label text and pixmap, and updates
 
1330
 *   the TextRect fields appropriately. Called at Initialize and SetValues.
 
1331
 *   This is also called by the subclasses to recalculate label dimensions.
 
1332
 *
 
1333
 *************************************************************************/
 
1334
 
 
1335
void
 
1336
_XmCalcLabelGDimensions(Widget wid)
 
1337
{
 
1338
    XmLabelGadget newlw = (XmLabelGadget) wid;
 
1339
    unsigned int  w = 0 , h = 0;
 
1340
 
 
1341
    /* initialize TextRect width and height to 0, reset if needed */
 
1342
 
 
1343
    LabG_AccTextRect(newlw).width = 0;
 
1344
    LabG_AccTextRect(newlw).height = 0;
 
1345
    LabG_StringRect(newlw).x = 0;
 
1346
    LabG_StringRect(newlw).y = 0;
 
1347
    LabG_StringRect(newlw).width = 0;
 
1348
    LabG_StringRect(newlw).height = 0;
 
1349
    LabG_PixmapRect(newlw).x = 0;
 
1350
    LabG_PixmapRect(newlw).y = 0;
 
1351
    LabG_PixmapRect(newlw).width = 0;
 
1352
    LabG_PixmapRect(newlw).height = 0;
 
1353
 
 
1354
    if (LabG_IsPixmap(newlw) || LabG_IsPixmapAndText(newlw))
 
1355
    {
 
1356
        if (XtIsSensitive(wid))
 
1357
        {
 
1358
            if (Pix (newlw) != XmUNSPECIFIED_PIXMAP)
 
1359
            {
 
1360
                XmeGetPixmapData(XtScreen(newlw), Pix(newlw),
 
1361
                    NULL, NULL, NULL, NULL, NULL, NULL,
 
1362
                    &w, &h);
 
1363
 
 
1364
                LabG_PixmapRect(newlw).width = (unsigned short) w;
 
1365
                LabG_PixmapRect(newlw).height = (unsigned short) h;
 
1366
            }
 
1367
        }
 
1368
        else
 
1369
        {
 
1370
            Pixmap pix_use = Pix_insen (newlw) ;
 
1371
 
 
1372
            if (pix_use == XmUNSPECIFIED_PIXMAP)
 
1373
                pix_use = Pix(newlw);
 
1374
 
 
1375
            if (pix_use != XmUNSPECIFIED_PIXMAP)
 
1376
            {
 
1377
                XmeGetPixmapData(XtScreen(newlw), pix_use,
 
1378
                    NULL, NULL, NULL, NULL, NULL, NULL,
 
1379
                    &w, &h);
 
1380
 
 
1381
                LabG_PixmapRect(newlw).width = (unsigned short) w;
 
1382
                LabG_PixmapRect(newlw).height = (unsigned short) h;
 
1383
            }
 
1384
        }
 
1385
    }
 
1386
        
 
1387
    if (LabG_IsText (newlw) || LabG_IsPixmapAndText(newlw))
 
1388
    {
 
1389
        Dimension w, h;
 
1390
 
 
1391
        /* If we have a string then size it.  */
 
1392
        if (!XmStringEmpty (LabG__label(newlw)))
 
1393
        {
 
1394
            XmStringExtent (LabG_Font(newlw), LabG__label(newlw), &w, &h);
 
1395
            LabG_StringRect(newlw).width = (unsigned short)w;
 
1396
            LabG_StringRect(newlw).height = (unsigned short)h;
 
1397
        }
 
1398
    }
 
1399
    
 
1400
    _XmLabelGCalcTextRect(wid);
 
1401
    
 
1402
    if (LabG__acceleratorText(newlw) != NULL)
 
1403
    {
 
1404
        /* If we have a string then size it. */
 
1405
        Dimension w,h;
 
1406
 
 
1407
        if (!XmStringEmpty (LabG__acceleratorText(newlw)))
 
1408
        {
 
1409
            XmStringExtent(LabG_Font(newlw),
 
1410
                    LabG__acceleratorText(newlw), &w, &h);
 
1411
            LabG_AccTextRect(newlw).width = (unsigned short)w;
 
1412
            LabG_AccTextRect(newlw).height = (unsigned short)h;
 
1413
        }
 
1414
    }
 
1415
}
 
1416
 
 
1417
void 
 
1418
_XmLabelGCalcTextRect(Widget wid)
 
1419
{
 
1420
  LabG_TextRect(wid).width = 0;
 
1421
  LabG_TextRect(wid).height = 0;
 
1422
  
 
1423
  if (LabG_IsPixmap(wid))
 
1424
    {
 
1425
      LabG_TextRect(wid).width = LabG_PixmapRect(wid).width;
 
1426
      LabG_TextRect(wid).height = LabG_PixmapRect(wid).height;
 
1427
    }
 
1428
  else if (LabG_IsText(wid))
 
1429
    {
 
1430
      LabG_TextRect(wid).width = LabG_StringRect(wid).width;
 
1431
      LabG_TextRect(wid).height = LabG_StringRect(wid).height;
 
1432
    }
 
1433
  else if (LabG_IsPixmapAndText(wid))
 
1434
    {
 
1435
      if (LabG_PixmapPlacement(wid) == XmPIXMAP_TOP ||
 
1436
          LabG_PixmapPlacement(wid) == XmPIXMAP_BOTTOM)
 
1437
        {
 
1438
          LabG_TextRect(wid).height = LabG_PixmapRect(wid).height +
 
1439
                LabG_StringRect(wid).height + LabG_PixmapTextPadding(wid);
 
1440
          LabG_TextRect(wid).width =
 
1441
                MAX(LabG_StringRect(wid).width, LabG_PixmapRect(wid).width);
 
1442
        }
 
1443
      else if (LabG_PixmapPlacement(wid) == XmPIXMAP_LEFT ||
 
1444
               LabG_PixmapPlacement(wid) == XmPIXMAP_RIGHT)
 
1445
        {
 
1446
          LabG_TextRect(wid).width = LabG_PixmapRect(wid).width +
 
1447
                LabG_StringRect(wid).width + LabG_PixmapTextPadding(wid);
 
1448
          LabG_TextRect(wid).height =
 
1449
                MAX(LabG_StringRect(wid).height, LabG_PixmapRect(wid).height);
 
1450
        }
 
1451
          
 
1452
      if (LabG_PixmapPlacement(wid) == XmPIXMAP_TOP)
 
1453
        {
 
1454
          LabG_PixmapRect(wid).y = 0;
 
1455
          LabG_StringRect(wid).y =
 
1456
                LabG_PixmapRect(wid).height + LabG_PixmapTextPadding(wid);
 
1457
        }
 
1458
      else if (LabG_PixmapPlacement(wid) == XmPIXMAP_BOTTOM)
 
1459
        {
 
1460
          LabG_StringRect(wid).y = 0;
 
1461
          LabG_PixmapRect(wid).y =
 
1462
                LabG_StringRect(wid).height + LabG_PixmapTextPadding(wid);
 
1463
        }
 
1464
      else if ((LabG_PixmapPlacement(wid) == XmPIXMAP_RIGHT &&
 
1465
                LayoutIsRtoLG(wid)) ||
 
1466
               (LabG_PixmapPlacement(wid) == XmPIXMAP_LEFT &&
 
1467
                !LayoutIsRtoLG(wid)))
 
1468
        {
 
1469
          LabG_PixmapRect(wid).x = 0;
 
1470
          LabG_StringRect(wid).x =
 
1471
                LabG_PixmapRect(wid).width + LabG_PixmapTextPadding(wid);
 
1472
        }
 
1473
      else if ((LabG_PixmapPlacement(wid) == XmPIXMAP_LEFT &&
 
1474
                LayoutIsRtoLG(wid)) ||
 
1475
               (LabG_PixmapPlacement(wid) == XmPIXMAP_RIGHT &&
 
1476
                !LayoutIsRtoLG(wid)))
 
1477
        {
 
1478
           LabG_StringRect(wid).x = 0;
 
1479
           LabG_PixmapRect(wid).x =
 
1480
                LabG_StringRect(wid).width + LabG_PixmapTextPadding(wid);
 
1481
        }
 
1482
            
 
1483
      if (LabG_PixmapPlacement(wid) == XmPIXMAP_RIGHT ||
 
1484
          LabG_PixmapPlacement(wid) == XmPIXMAP_LEFT)
 
1485
        {
 
1486
          LabG_PixmapRect(wid).y =
 
1487
                (LabG_TextRect(wid).height - LabG_PixmapRect(wid).height) / 2;
 
1488
          LabG_StringRect(wid).y =
 
1489
                (LabG_TextRect(wid).height - LabG_StringRect(wid).height) / 2;
 
1490
        }
 
1491
      else
 
1492
        {
 
1493
          if (LabG_Alignment(wid) == XmALIGNMENT_CENTER)
 
1494
            {
 
1495
              LabG_PixmapRect(wid).x =
 
1496
                (LabG_TextRect(wid).width - LabG_PixmapRect(wid).width) / 2;
 
1497
              LabG_StringRect(wid).x =
 
1498
                (LabG_TextRect(wid).width - LabG_StringRect(wid).width) / 2;
 
1499
            }
 
1500
          else if ((LabG_Alignment(wid) == XmALIGNMENT_END &&
 
1501
                     !LayoutIsRtoLG(wid)) ||
 
1502
                    (LabG_Alignment(wid) == XmALIGNMENT_BEGINNING &&
 
1503
                     LayoutIsRtoLG(wid)))
 
1504
            {
 
1505
              LabG_PixmapRect(wid).x =
 
1506
                LabG_TextRect(wid).width - LabG_PixmapRect(wid).width;
 
1507
              LabG_StringRect(wid).x =
 
1508
                LabG_TextRect(wid).width - LabG_StringRect(wid).width;
 
1509
            }
 
1510
        }
 
1511
    }
 
1512
}
 
1513
 
 
1514
 
 
1515
/************************************************************************
 
1516
 *
 
1517
 *  Resize
 
1518
 *      Sets new width, new height, and new label.TextRect
 
1519
 *      appropriately. It is called by Initialize and SetValues.
 
1520
 *
 
1521
 ************************************************************************/
 
1522
 
 
1523
static void
 
1524
Resize(Widget wid)
 
1525
{
 
1526
    XmLabelGadget newlw = (XmLabelGadget) wid;
 
1527
    int leftx, rightx;
 
1528
 
 
1529
    /* increase margin width if necessary to accomodate accelerator text */
 
1530
    if (LabG__acceleratorText(newlw) != NULL)
 
1531
    {
 
1532
        if (LayoutIsRtoLG(newlw))
 
1533
        {
 
1534
            if (LabG_MarginLeft(newlw) <
 
1535
                LabG_AccTextRect(newlw).width + LABELG_ACC_PAD)
 
1536
            {
 
1537
                int delta = LabG_AccTextRect(newlw).width + LABELG_ACC_PAD -
 
1538
                    LabG_MarginLeft(newlw);
 
1539
                newlw->label.acc_left_delta += delta;
 
1540
                LabG_MarginLeft(newlw) += delta;
 
1541
            }
 
1542
        }
 
1543
        else
 
1544
        {
 
1545
            if (LabG_MarginRight(newlw) <
 
1546
                LabG_AccTextRect(newlw).width + LABELG_ACC_PAD)
 
1547
            {
 
1548
                int delta = LabG_AccTextRect(newlw).width + LABELG_ACC_PAD -
 
1549
                    LabG_MarginRight(newlw);
 
1550
                newlw->label.acc_right_delta += delta;
 
1551
                LabG_MarginRight(newlw) += delta;
 
1552
            }
 
1553
        }
 
1554
    }
 
1555
    /* Has a width been specified?  */
 
1556
    if (newlw->rectangle.width == 0)
 
1557
        newlw->rectangle.width =
 
1558
            LabG_TextRect(newlw).width +
 
1559
            LabG_MarginLeft(newlw) + LabG_MarginRight(newlw) +
 
1560
            (2 * (LabG_MarginWidth(newlw) +
 
1561
            newlw->gadget.highlight_thickness
 
1562
            + newlw->gadget.shadow_thickness));
 
1563
 
 
1564
    leftx = newlw->gadget.highlight_thickness +
 
1565
        newlw->gadget.shadow_thickness + LabG_MarginWidth(newlw) +
 
1566
        LabG_MarginLeft(newlw);
 
1567
 
 
1568
    rightx = newlw->rectangle.width - newlw->gadget.highlight_thickness -
 
1569
        newlw->gadget.shadow_thickness - LabG_MarginWidth(newlw) -
 
1570
        LabG_MarginRight(newlw);
 
1571
 
 
1572
    switch (LabG_Alignment(newlw))
 
1573
    {
 
1574
        case XmALIGNMENT_BEGINNING:
 
1575
            if (LayoutIsRtoLG(newlw))
 
1576
                LabG_TextRect(newlw).x = rightx - LabG_TextRect(newlw).width;
 
1577
            else
 
1578
                LabG_TextRect(newlw).x = leftx;
 
1579
            break;
 
1580
 
 
1581
        case XmALIGNMENT_END:
 
1582
            if (LayoutIsRtoLG(newlw))
 
1583
                LabG_TextRect(newlw).x = leftx;
 
1584
            else
 
1585
                LabG_TextRect(newlw).x = rightx - LabG_TextRect(newlw).width;
 
1586
            break;
 
1587
 
 
1588
        default:
 
1589
            /* XmALIGNMENT_CENTER */
 
1590
            LabG_TextRect(newlw).x = leftx +
 
1591
                (rightx - leftx - (int)LabG_TextRect(newlw).width) / 2;
 
1592
            break;
 
1593
    }
 
1594
 
 
1595
    /*  Has a height been specified?  */
 
1596
    if (newlw->rectangle.height == 0)
 
1597
        newlw->rectangle.height = MAX(LabG_TextRect(newlw).height,
 
1598
            LabG_AccTextRect(newlw).height)
 
1599
            + LabG_MarginTop(newlw)
 
1600
            + LabG_MarginBottom(newlw)
 
1601
            + (2 * (LabG_MarginHeight(newlw)
 
1602
            + newlw->gadget.highlight_thickness
 
1603
            + newlw->gadget.shadow_thickness));
 
1604
 
 
1605
    LabG_TextRect(newlw).y =
 
1606
        (short) (newlw->gadget.highlight_thickness
 
1607
        + newlw->gadget.shadow_thickness
 
1608
        + LabG_MarginHeight(newlw) + LabG_MarginTop(newlw) +
 
1609
        ((int) (newlw->rectangle.height - LabG_MarginTop(newlw)
 
1610
        - LabG_MarginBottom(newlw)
 
1611
        - (2 * (LabG_MarginHeight(newlw)
 
1612
        + newlw->gadget.highlight_thickness
 
1613
        + newlw->gadget.shadow_thickness))
 
1614
        - LabG_TextRect(newlw).height) / 2));
 
1615
 
 
1616
    if (LabG__acceleratorText(newlw) != NULL)
 
1617
    {
 
1618
        Dimension  base_label, base_accText, diff;
 
1619
 
 
1620
        if (LayoutIsRtoLG(newlw))
 
1621
            LabG_AccTextRect(newlw).x =  newlw->rectangle .x +
 
1622
                (newlw->gadget.highlight_thickness +
 
1623
                newlw->gadget.shadow_thickness +
 
1624
                LabG_MarginWidth(newlw));
 
1625
        else
 
1626
            LabG_AccTextRect(newlw).x = (newlw->rectangle.width -
 
1627
                newlw->gadget.highlight_thickness -
 
1628
                newlw->gadget.shadow_thickness -
 
1629
                LabG_MarginWidth(newlw) -
 
1630
                LabG_MarginRight(newlw) +
 
1631
                LABELG_ACC_PAD);
 
1632
 
 
1633
        LabG_AccTextRect(newlw).y = newlw->gadget.highlight_thickness
 
1634
            + newlw->gadget.shadow_thickness
 
1635
            + LabG_MarginHeight(newlw) + LabG_MarginTop(newlw) +
 
1636
            ((int) (newlw->rectangle.height - LabG_MarginTop(newlw)
 
1637
            - LabG_MarginBottom(newlw)
 
1638
            - (2 * (LabG_MarginHeight(newlw)
 
1639
            + newlw->gadget.highlight_thickness
 
1640
            + newlw->gadget.shadow_thickness))
 
1641
            - LabG_AccTextRect(newlw).height) / 2);
 
1642
 
 
1643
        /* make sure the label and accelerator text line up */
 
1644
        /* when the fonts are different */
 
1645
 
 
1646
        if (LabG_IsText (newlw))
 
1647
        {
 
1648
            base_label =
 
1649
                XmStringBaseline (LabG_Font(newlw), LabG__label(newlw));
 
1650
            base_accText =
 
1651
                XmStringBaseline (LabG_Font(newlw),
 
1652
                LabG__acceleratorText(newlw));
 
1653
 
 
1654
            if (base_label > base_accText)
 
1655
            {
 
1656
                diff = base_label - base_accText;
 
1657
                LabG_AccTextRect(newlw).y = LabG_TextRect(newlw).y + diff - 1;
 
1658
            }
 
1659
            else if (base_label < base_accText)
 
1660
            {
 
1661
                diff = base_accText - base_label;
 
1662
                LabG_TextRect(newlw).y = LabG_AccTextRect(newlw).y + diff - 1;
 
1663
            }
 
1664
        }
 
1665
    }
 
1666
 
 
1667
    /* Set core dimensions so we don't get a Toolkit error. */
 
1668
    if (newlw->rectangle.width == 0)
 
1669
        newlw->rectangle.width = 1;
 
1670
    if (newlw->rectangle.height == 0)
 
1671
        newlw->rectangle.height = 1;
 
1672
}
 
1673
 
 
1674
 
 
1675
/************************************************************************
 
1676
 *
 
1677
 *  Initialize
 
1678
 *      This is the widget's instance initialize routine.  It is
 
1679
 *      called once for each widget.
 
1680
 *  Changes: Treat label, pixmap, labeltype, mnemoniccharset as independently
 
1681
 *      setable resource.
 
1682
 ************************************************************************/
 
1683
 
 
1684
/*ARGSUSED*/
 
1685
static void
 
1686
Initialize(Widget req,
 
1687
Widget new_w,
 
1688
ArgList args,
 
1689
Cardinal *num_args)
 
1690
{
 
1691
    XmMenuSystemTrait menuSTrait;
 
1692
 
 
1693
    XmLabelGadget lw = (XmLabelGadget) new_w;
 
1694
    XmLabelGadget rw = (XmLabelGadget) req;
 
1695
 
 
1696
    lw->label.baselines = NULL;
 
1697
 
 
1698
    /* Before doing anything with the pixmap, check if we have to
 
1699
     * re-ask for a conversion */
 
1700
    if (Pix  (new_w) == XmDELAYED_PIXMAP)
 
1701
    {
 
1702
        /* This test means that a conversion was asked for
 
1703
         * but failed because the colors were not accessible
 
1704
         * prior to Initialize, because the cache wasn't there yet.
 
1705
         * We have to try again from here. */
 
1706
 
 
1707
        XtGetSubresources(new_w, new_w,
 
1708
            NULL, NULL,
 
1709
            label_pixmap_resource, 1,
 
1710
            args, *num_args);
 
1711
    }
 
1712
 
 
1713
    if (Pix_insen (new_w) == XmDELAYED_PIXMAP)
 
1714
    {
 
1715
        XtGetSubresources(new_w, new_w,
 
1716
            NULL, NULL,
 
1717
            label_pixmap_insen_resource, 1,
 
1718
            args, *num_args);
 
1719
    }
 
1720
 
 
1721
    /* If menuProcs is not set up yet, try again */
 
1722
    _XmProcessLock();
 
1723
    if (xmLabelGadgetClassRec.label_class.menuProcs == NULL)
 
1724
        xmLabelGadgetClassRec.label_class.menuProcs =
 
1725
            (XmMenuProc) _XmGetMenuProcContext();
 
1726
    _XmProcessUnlock();
 
1727
 
 
1728
    LabG_SkipCallback(new_w) = FALSE;
 
1729
 
 
1730
    /* Check for Invalid enumerated types */
 
1731
 
 
1732
    if (!XmRepTypeValidValue(XmRID_LABEL_TYPE, LabG_LabelType(new_w), new_w))
 
1733
        LabG_LabelType(new_w) = XmSTRING;
 
1734
 
 
1735
    if (!XmRepTypeValidValue(XmRID_ALIGNMENT, LabG_Alignment(new_w), new_w))
 
1736
        LabG_Alignment(new_w) = XmALIGNMENT_CENTER;
 
1737
 
 
1738
    if (!XmRepTypeValidValue(XmRID_PIXMAP_PLACEMENT, LabG_PixmapPlacement(new_w), new_w))
 
1739
        LabG_PixmapPlacement(new_w) = XmPIXMAP_LEFT;
 
1740
        
 
1741
    #ifndef NO_XM_1_2_BC
 
1742
    /*
 
1743
     * Some pre-Motif 2.0 XmManager subclasses may be bypassing the
 
1744
     * synthetic resouce GetValues hook and passing us the manager's raw
 
1745
     * string_direction field (which is now a layout_direction).  Fixup
 
1746
     * the common/simple cases.
 
1747
     */
 
1748
    switch (LabG_StringDirection(lw))
 
1749
    {
 
1750
        case XmLEFT_TO_RIGHT:
 
1751
        case XmRIGHT_TO_LEFT:
 
1752
            /* These string directions are erroneous uses of layout directions. */
 
1753
            LabG_StringDirection(lw) =
 
1754
                XmDirectionToStringDirection(LabG_StringDirection(lw));
 
1755
            break;
 
1756
        default:
 
1757
            /* Other unknown layout directions will still get a warning. */
 
1758
            break;
 
1759
    }
 
1760
    #endif
 
1761
 
 
1762
    /* If layout_direction is set, it overrides string_direction.
 
1763
     * If string_direction is set, but not layout_direction, use
 
1764
     *  string_direction value.
 
1765
     * If neither is set, get from parent.
 
1766
     */
 
1767
    if (lw->gadget.layout_direction != XmDEFAULT_DIRECTION)
 
1768
    {
 
1769
        if (LabG_StringDirection(lw) == XmDEFAULT_DIRECTION)
 
1770
            LabG_StringDirection(lw) =
 
1771
                XmDirectionToStringDirection(lw->gadget.layout_direction);
 
1772
    }
 
1773
    else if (LabG_StringDirection(lw) != XmDEFAULT_DIRECTION)
 
1774
    {
 
1775
        lw->gadget.layout_direction =
 
1776
            XmStringDirectionToDirection(LabG_StringDirection(lw));
 
1777
    }
 
1778
    else
 
1779
    {
 
1780
        lw->gadget.layout_direction = _XmGetLayoutDirection(XtParent(new_w));
 
1781
        LabG_StringDirection(lw) =
 
1782
            XmDirectionToStringDirection(lw->gadget.layout_direction);
 
1783
    }
 
1784
 
 
1785
    if (!XmRepTypeValidValue(XmRID_STRING_DIRECTION,
 
1786
        LabG_StringDirection(new_w), new_w))
 
1787
        LabG_StringDirection(new_w) = XmSTRING_DIRECTION_L_TO_R;
 
1788
 
 
1789
    /* Make a local copy of the font list */
 
1790
    if (LabG_Font(new_w) == NULL)
 
1791
    {
 
1792
        /* CR 2990:  Let subclasses choose their own default font. */
 
1793
        LabG_Font(new_w) = XmeGetDefaultRenderTable (new_w, XmLABEL_FONTLIST);
 
1794
    }
 
1795
    LabG_Font(new_w) = XmFontListCopy(LabG_Font(new_w));
 
1796
 
 
1797
    menuSTrait = (XmMenuSystemTrait)
 
1798
        XmeTraitGet((XtPointer) XtClass((Widget) XtParent(new_w)), XmQTmenuSystem);
 
1799
 
 
1800
    if (menuSTrait != (XmMenuSystemTrait) NULL)
 
1801
        LabG_MenuType(new_w) = menuSTrait->type(XtParent(new_w));
 
1802
    else
 
1803
        LabG_MenuType(new_w) = XmWORK_AREA;
 
1804
 
 
1805
    /*  Handle the label string :
 
1806
     *   If no label string is given accept widget's name as default.
 
1807
     *     convert the widgets name to an XmString before storing;
 
1808
     *   else
 
1809
     *     save a copy of the given string.
 
1810
     *     If the given string is not an XmString issue an warning.
 
1811
     */
 
1812
 
 
1813
    if (LabG__label(new_w) == NULL)
 
1814
    {
 
1815
                                                  /* reserved */
 
1816
        LabG__label(new_w) = XmeGetLocalizedString ((char *) NULL,
 
1817
            (Widget) lw,
 
1818
            XmNlabelString,
 
1819
            XrmQuarkToString(lw->object.xrm_name));
 
1820
    }
 
1821
    else if (XmeStringIsValid((XmString) LabG__label(new_w)))
 
1822
    {
 
1823
        LabG__label(new_w) = XmStringCopy((XmString) LabG__label(new_w));
 
1824
    }
 
1825
    else
 
1826
    {
 
1827
        XmeWarning((Widget) lw, CS_STRING_MESSAGE);
 
1828
        LabG__label(new_w) =
 
1829
            XmStringCreateLocalized(XrmQuarkToString(lw->object.xrm_name));
 
1830
    }
 
1831
 
 
1832
    /*
 
1833
     * Convert the given mnemonicCharset to the internal Xm-form.
 
1834
     */
 
1835
    if (LabG_MnemonicCharset(new_w) != NULL)
 
1836
    {
 
1837
        LabG_MnemonicCharset (new_w) =
 
1838
            _XmStringCharsetCreate (LabG_MnemonicCharset (new_w));
 
1839
    }
 
1840
    else
 
1841
        LabG_MnemonicCharset (new_w) =
 
1842
            _XmStringCharsetCreate (XmFONTLIST_DEFAULT_TAG);
 
1843
 
 
1844
    /* Accelerators are currently only supported in menus */
 
1845
    if ((LabG__acceleratorText(new_w) != NULL) && LabG_IsMenupane(new_w))
 
1846
    {
 
1847
        if (XmeStringIsValid((XmString) LabG__acceleratorText(new_w)))
 
1848
        {
 
1849
            /* Copy the input string into local space if not a Cascade Button. */
 
1850
            if (XmIsCascadeButtonGadget(new_w))
 
1851
                LabG__acceleratorText(new_w) = NULL;
 
1852
            else
 
1853
                LabG__acceleratorText(new_w)=
 
1854
                    XmStringCopy((XmString) LabG__acceleratorText(new_w));
 
1855
        }
 
1856
        else
 
1857
        {
 
1858
            XmeWarning((Widget) lw, ACC_MESSAGE);
 
1859
            LabG__acceleratorText(new_w) = NULL;
 
1860
        }
 
1861
    }
 
1862
    else
 
1863
        LabG__acceleratorText(new_w) = NULL;
 
1864
 
 
1865
    if ((LabG_Accelerator(new_w) != NULL) && LabG_IsMenupane(new_w))
 
1866
    {
 
1867
        /* Copy the accelerator into local space */
 
1868
        LabG_Accelerator(lw) = XtNewString(LabG_Accelerator(new_w));
 
1869
    }
 
1870
    else
 
1871
        LabG_Accelerator(lw) = NULL;
 
1872
 
 
1873
    LabG_SkipCallback(lw) = FALSE;
 
1874
 
 
1875
    lw->label.acc_left_delta = 0;
 
1876
    lw->label.acc_right_delta = 0;
 
1877
 
 
1878
    /*  If zero width and height was requested by the application,  */
 
1879
    /*  reset new's width and height to zero to allow Resize()     */
 
1880
    /*  to operate properly.                                        */
 
1881
 
 
1882
    if (rw->rectangle.width == 0)
 
1883
        lw->rectangle.width = 0;
 
1884
 
 
1885
    if (rw->rectangle.height == 0)
 
1886
        lw->rectangle.height = 0;
 
1887
 
 
1888
    /* CR 6267:  Suppress highlight thickness before sizing also. */
 
1889
    if ((LabG_MenuType(new_w) == XmMENU_POPUP) ||
 
1890
        (LabG_MenuType(new_w) == XmMENU_PULLDOWN) ||
 
1891
        (LabG_MenuType(new_w) == XmMENU_BAR))
 
1892
        lw->gadget.highlight_thickness = 0;
 
1893
 
 
1894
    _XmCalcLabelGDimensions(new_w);
 
1895
 
 
1896
    /* CR 7283: Can't use the resize method pointer here because */
 
1897
    /*  subclasses haven't been initialized.                   */
 
1898
    Resize((Widget) lw);
 
1899
 
 
1900
    DealWithColors(lw);
 
1901
    DealWithPixmaps(lw);
 
1902
 
 
1903
    /* Initialize only; set properly in _XmLabelSetBackgroundGC(). */
 
1904
    lw->label.fill_bg_box = _XmPLAIN_BG_BOX;
 
1905
 
 
1906
    SetNormalGC(lw);
 
1907
    _XmLabelSetBackgroundGC (lw);
 
1908
    LabG_HighlightGC(lw) =
 
1909
        _XmGetPixmapBasedGC (XtParent(new_w),
 
1910
        LabG_HighlightColor(lw),
 
1911
        LabG_Background(lw),
 
1912
        LabG_HighlightPixmap(lw));
 
1913
    LabG_TopShadowGC(lw) =
 
1914
        _XmGetPixmapBasedGC (XtParent(new_w),
 
1915
        LabG_TopShadowColor(lw),
 
1916
        LabG_Background(lw),
 
1917
        LabG_TopShadowPixmap(lw));
 
1918
    LabG_BottomShadowGC(lw) =
 
1919
        _XmGetPixmapBasedGC (XtParent(new_w),
 
1920
        LabG_BottomShadowColor(lw),
 
1921
        LabG_Background(lw),
 
1922
        LabG_BottomShadowPixmap(lw));
 
1923
 
 
1924
    /*  Force the label traversal flag when in a menu  */
 
1925
    if ((XtClass(lw) == xmLabelGadgetClass) &&
 
1926
        ((LabG_MenuType(new_w) == XmMENU_POPUP) ||
 
1927
        (LabG_MenuType(new_w) == XmMENU_PULLDOWN) ||
 
1928
        (LabG_MenuType(new_w) == XmMENU_OPTION)))
 
1929
    {
 
1930
        lw->gadget.traversal_on = False;
 
1931
        lw->gadget.highlight_on_enter = False;
 
1932
    }
 
1933
 
 
1934
    /*  Initialize the interesting input types.  */
 
1935
    lw->gadget.event_mask = XmHELP_EVENT | XmFOCUS_IN_EVENT | XmFOCUS_OUT_EVENT
 
1936
        | XmENTER_EVENT | XmLEAVE_EVENT | XmBDRAG_EVENT;
 
1937
}
 
1938
 
 
1939
 
 
1940
/*
 
1941
 * DealWithColors
 
1942
 *      Deal with compatibility.
 
1943
 */
 
1944
 
 
1945
static void
 
1946
DealWithColors(XmLabelGadget lw)
 
1947
{
 
1948
    XmManagerWidget mw = (XmManagerWidget) XtParent(lw);
 
1949
 
 
1950
    /*
 
1951
     * If the gadget color is set to the tag value or it is the
 
1952
     * same as the manager color; bc mode is enabled otherwise
 
1953
     * initialize like a widget.
 
1954
     */
 
1955
    if ((LabG_Background(lw) == INVALID_PIXEL ||
 
1956
        LabG_Background(lw) == mw->core.background_pixel) &&
 
1957
        (LabG_Foreground(lw) == INVALID_PIXEL ||
 
1958
        LabG_Foreground(lw) == mw->manager.foreground) &&
 
1959
        (LabG_TopShadowColor(lw) == INVALID_PIXEL ||
 
1960
        LabG_TopShadowColor(lw) == mw->manager.top_shadow_color) &&
 
1961
        (LabG_BottomShadowColor(lw) == INVALID_PIXEL ||
 
1962
        LabG_BottomShadowColor(lw) == mw->manager.bottom_shadow_color) &&
 
1963
        (LabG_HighlightColor(lw) == INVALID_PIXEL ||
 
1964
        LabG_HighlightColor(lw) == mw->manager.highlight_color))
 
1965
    {
 
1966
        LabG_Background(lw) = mw->core.background_pixel;
 
1967
        LabG_Foreground(lw) = mw->manager.foreground;
 
1968
        LabG_TopShadowColor(lw) = mw->manager.top_shadow_color;
 
1969
        LabG_BottomShadowColor(lw) = mw->manager.bottom_shadow_color;
 
1970
        LabG_HighlightColor(lw) = mw->manager.highlight_color;
 
1971
    }
 
1972
    else
 
1973
    {
 
1974
        InitNewColorBehavior(lw);
 
1975
    }
 
1976
}
 
1977
 
 
1978
 
 
1979
/*
 
1980
 * InitNewColorBehavior
 
1981
 *      Initialize colors like a widget.  These are CallProcs so
 
1982
 * they should be called with a correct offset. However offset
 
1983
 * isn't used by these functions.  Even so I supply offset.
 
1984
 * You make the call.
 
1985
 */
 
1986
 
 
1987
static void
 
1988
InitNewColorBehavior(XmLabelGadget lw)
 
1989
{
 
1990
    XrmValue value;
 
1991
 
 
1992
    value.size = sizeof(Pixel);
 
1993
 
 
1994
    if (LabG_Background(lw) == INVALID_PIXEL)
 
1995
    {
 
1996
        _XmBackgroundColorDefault
 
1997
            ((Widget) lw,
 
1998
            XtOffsetOf(struct _XmLabelGCacheObjRec, label_cache.background),
 
1999
            &value);
 
2000
        memcpy((char*) &LabG_Background(lw), value.addr, value.size);
 
2001
    }
 
2002
 
 
2003
    if (LabG_Foreground(lw) == INVALID_PIXEL)
 
2004
    {
 
2005
        _XmForegroundColorDefault
 
2006
            ((Widget) lw,
 
2007
            XtOffsetOf(struct _XmLabelGCacheObjRec, label_cache.foreground),
 
2008
            &value);
 
2009
        memcpy((char*) &LabG_Foreground(lw), value.addr, value.size);
 
2010
    }
 
2011
 
 
2012
    if (LabG_TopShadowColor(lw) == INVALID_PIXEL)
 
2013
    {
 
2014
        _XmTopShadowColorDefault
 
2015
            ((Widget) lw,
 
2016
            XtOffsetOf(struct _XmLabelGCacheObjRec, label_cache.top_shadow_color),
 
2017
            &value);
 
2018
        memcpy((char*) &LabG_TopShadowColor(lw), value.addr, value.size);
 
2019
    }
 
2020
 
 
2021
    if (LabG_BottomShadowColor(lw) == INVALID_PIXEL)
 
2022
    {
 
2023
        _XmBottomShadowColorDefault
 
2024
            ((Widget) lw,
 
2025
            XtOffsetOf(struct _XmLabelGCacheObjRec,
 
2026
            label_cache.bottom_shadow_color),
 
2027
            &value);
 
2028
        memcpy((char*) &LabG_BottomShadowColor(lw), value.addr, value.size);
 
2029
    }
 
2030
 
 
2031
    if (LabG_HighlightColor(lw) == INVALID_PIXEL)
 
2032
    {
 
2033
        _XmHighlightColorDefault
 
2034
            ((Widget) lw,
 
2035
            XtOffsetOf(struct _XmLabelGCacheObjRec, label_cache.highlight_color),
 
2036
            &value);
 
2037
        memcpy((char*) &LabG_HighlightColor(lw), value.addr, value.size);
 
2038
    }
 
2039
}
 
2040
 
 
2041
 
 
2042
/*
 
2043
 * DealWithPixmaps
 
2044
 *      Deal with compatibility.  If any resource is set initialize
 
2045
 * like a widget otherwise get everything from the parent.
 
2046
 */
 
2047
 
 
2048
static void
 
2049
DealWithPixmaps(XmLabelGadget lw)
 
2050
{
 
2051
    XmManagerWidget mw = (XmManagerWidget) XtParent(lw);
 
2052
 
 
2053
    if ((LabG_TopShadowPixmap(lw) == INVALID_PIXMAP ||
 
2054
        LabG_TopShadowPixmap(lw) == mw->manager.top_shadow_pixmap) &&
 
2055
        (LabG_HighlightPixmap(lw) == INVALID_PIXMAP ||
 
2056
        LabG_HighlightPixmap(lw) == mw->manager.highlight_pixmap))
 
2057
    {
 
2058
        LabG_TopShadowPixmap(lw) = mw->manager.top_shadow_pixmap;
 
2059
        LabG_HighlightPixmap(lw) = mw->manager.highlight_pixmap;
 
2060
    }
 
2061
    else
 
2062
    {
 
2063
        InitNewPixmapBehavior(lw);
 
2064
    }
 
2065
}
 
2066
 
 
2067
 
 
2068
/*
 
2069
 * InitNewPixmapBehavior
 
2070
 *      Initialize colors like a widget.
 
2071
 */
 
2072
 
 
2073
static void
 
2074
InitNewPixmapBehavior(XmLabelGadget lw)
 
2075
{
 
2076
    if (LabG_TopShadowPixmap(lw) == INVALID_PIXMAP)
 
2077
        LabG_TopShadowColor(lw) = GetTopShadowPixmapDefault((Widget)lw);
 
2078
 
 
2079
    if (LabG_HighlightPixmap(lw) == INVALID_PIXMAP)
 
2080
        LabG_HighlightPixmap(lw) = GetLabelHighlightPixmapDefault((Widget)lw);
 
2081
}
 
2082
 
 
2083
 
 
2084
/************************************************************************
 
2085
 *
 
2086
 *  QueryGeometry
 
2087
 *
 
2088
 ************************************************************************/
 
2089
 
 
2090
static XtGeometryResult
 
2091
QueryGeometry(Widget wid,
 
2092
XtWidgetGeometry *intended,
 
2093
XtWidgetGeometry *reply)
 
2094
{
 
2095
    XmLabelGadget lg = (XmLabelGadget) wid;
 
2096
    reply->request_mode = 0;
 
2097
 
 
2098
    /* Don't really know what to do with queries about x,y,border,stacking.
 
2099
     * Since we are interpreting unset bits as a request for information
 
2100
     * (asking about neither height or width does the old 0-0 request)
 
2101
     * a caller asking about x,y should not get back width and height,
 
2102
     * especially since it is an expensive operation.  So x, y, border, stack
 
2103
     * all return No, this indicates we'd prefer to remain as is.  Parent
 
2104
     * is free to change it anyway...
 
2105
     */
 
2106
 
 
2107
    if (GMode(intended) & ~(CWWidth | CWHeight))
 
2108
        return XtGeometryNo;
 
2109
 
 
2110
    if (LabG_RecomputeSize(lg) == FALSE)
 
2111
        return XtGeometryNo;
 
2112
 
 
2113
    /* pre-load the reply with input values */
 
2114
 
 
2115
    reply->request_mode = (CWWidth | CWHeight);
 
2116
 
 
2117
    reply->width = LabG_TextRect(lg).width +
 
2118
        (2 * (LabG_MarginWidth(lg) +
 
2119
        lg->gadget.highlight_thickness +
 
2120
        lg->gadget.shadow_thickness)) +
 
2121
        LabG_MarginLeft(lg) +
 
2122
        LabG_MarginRight(lg);
 
2123
 
 
2124
    if (reply->width == 0)
 
2125
        reply->width = 1;
 
2126
 
 
2127
    reply->height = MAX(LabG_TextRect(lg).height,
 
2128
        LabG_AccTextRect(lg).height) +
 
2129
        (2 * (LabG_MarginHeight(lg) +
 
2130
        lg->gadget.highlight_thickness +
 
2131
        lg->gadget.shadow_thickness)) +
 
2132
        LabG_MarginTop(lg) +
 
2133
        LabG_MarginBottom(lg);
 
2134
 
 
2135
    if (reply->height == 0)
 
2136
        reply->height = 1;
 
2137
 
 
2138
    if ((IsWidth(intended) && (reply->width != intended->width)) ||
 
2139
        (IsHeight(intended) && (reply->height != intended->height)) ||
 
2140
        (GMode(intended) != GMode(reply)))
 
2141
    {
 
2142
        return XtGeometryAlmost;
 
2143
    }
 
2144
    else
 
2145
    {
 
2146
        reply->request_mode = 0;
 
2147
        return XtGeometryYes;
 
2148
    }
 
2149
}
 
2150
 
 
2151
 
 
2152
/************************************************************************
 
2153
 *
 
2154
 *  Destroy
 
2155
 *      Free up the label gadget allocated space.  This includes
 
2156
 *      the label, and GC's.
 
2157
 *
 
2158
 ************************************************************************/
 
2159
 
 
2160
static void
 
2161
Destroy(Widget w)
 
2162
{
 
2163
    if (LabG__label(w) != NULL)
 
2164
        XmStringFree (LabG__label(w));
 
2165
    if (LabG__acceleratorText(w) != NULL)
 
2166
        XmStringFree (LabG__acceleratorText(w));
 
2167
    XtFree (LabG_Accelerator(w));
 
2168
    if (LabG_Font(w)  != NULL)
 
2169
        XmFontListFree (LabG_Font(w));
 
2170
    XtFree (LabG_MnemonicCharset (w));
 
2171
 
 
2172
    XtFree ((char*) ((XmLabelGadget)w)->label.baselines);
 
2173
 
 
2174
    XtReleaseGC (XtParent(w), LabG_NormalGC(w));
 
2175
    XtReleaseGC (XtParent(w), LabG_InsensitiveGC(w));
 
2176
 
 
2177
    XtReleaseGC (XtParent(w), LabG_BackgroundGC(w));
 
2178
    XtReleaseGC (XtParent(w), LabG_HighlightGC(w));
 
2179
    XtReleaseGC (XtParent(w), LabG_TopShadowGC(w));
 
2180
    XtReleaseGC (XtParent(w), LabG_BottomShadowGC(w));
 
2181
 
 
2182
    /* CR 6571: Free cache *after* making all references. */
 
2183
    _XmProcessLock();
 
2184
    _XmCacheDelete((XtPointer) LabG_Cache(w));
 
2185
    _XmProcessUnlock();
 
2186
}
 
2187
 
 
2188
 
 
2189
/*ARGSUSED*/
 
2190
static void
 
2191
LabelDrawBackground(Widget wid,
 
2192
XEvent *event,                                    /* unused */
 
2193
Region region,                                    /* unused */
 
2194
LRectangle *background_box)
 
2195
{
 
2196
    XmLabelGadget lw = (XmLabelGadget) wid;
 
2197
 
 
2198
    switch (lw->label.fill_bg_box)
 
2199
    {
 
2200
        case _XmPLAIN_BG_BOX:
 
2201
#ifndef USE_XFT
 
2202
            return;
 
2203
#endif
 
2204
 
 
2205
        case _XmFILL_BG_BOX:
 
2206
        case _XmALWAYS_FILL_BG_BOX:
 
2207
        default:
 
2208
            break;
 
2209
    }
 
2210
 
 
2211
    /*
 
2212
     * Background_box is a parameter because subclasses like
 
2213
     * PushBG and ToggleBG need to be able to adjust this rectangle.
 
2214
     */
 
2215
 
 
2216
    if (background_box->width < 0)
 
2217
        background_box->width = 0;
 
2218
 
 
2219
    if (background_box->height < 0)
 
2220
        background_box->height = 0;
 
2221
 
 
2222
    XFillRectangle(XtDisplay(lw),
 
2223
        XtWindow((Widget) lw),
 
2224
        LabG_BackgroundGC(lw),
 
2225
        background_box->x,
 
2226
        background_box->y,
 
2227
        background_box->width,
 
2228
        background_box->height);
 
2229
}
 
2230
 
 
2231
 
 
2232
/************************************************************************
 
2233
 *
 
2234
 *  Redisplay
 
2235
 *
 
2236
 ************************************************************************/
 
2237
 
 
2238
static void
 
2239
Redisplay(Widget wid,
 
2240
XEvent *event,
 
2241
Region region)
 
2242
{
 
2243
    XmLabelGadget lw = (XmLabelGadget) wid;
 
2244
    LRectangle background_box;
 
2245
 
 
2246
    background_box.x = lw->rectangle.x + LabG_Highlight(lw);
 
2247
    background_box.y = lw->rectangle.y + LabG_Highlight(lw);
 
2248
    background_box.width = lw->rectangle.width - (2 * LabG_Highlight(lw));
 
2249
    background_box.height = lw->rectangle.height - (2 * LabG_Highlight(lw));
 
2250
 
 
2251
    _XmRedisplayLabG(wid, event, region, &background_box);
 
2252
}
 
2253
 
 
2254
 
 
2255
void
 
2256
_XmRedisplayLabG(Widget wid,
 
2257
XEvent *event,
 
2258
Region region,
 
2259
LRectangle *background_box)
 
2260
{
 
2261
    XmLabelGadget lw = (XmLabelGadget) wid;
 
2262
    GC gc;
 
2263
    GC clipgc = NULL;
 
2264
    XRectangle clip_rect;
 
2265
    Dimension availW, availH, marginal_width, marginal_height, max_text_height;
 
2266
 
 
2267
    if (!XtIsRealized(wid)) return ;
 
2268
 
 
2269
    if (LabG_IsMenupane(lw))
 
2270
    {
 
2271
        ShellWidget mshell = (ShellWidget) XtParent(XtParent(lw));
 
2272
        if (! mshell->shell.popped_up)
 
2273
            return;
 
2274
    }
 
2275
 
 
2276
    availH = lw->rectangle.height;
 
2277
    availW = lw->rectangle.width;
 
2278
 
 
2279
    /*
 
2280
     * Don't count MarginWidth to be consistent with Label Widget.
 
2281
     *
 
2282
     * Adjust definitions of temporary variables
 
2283
     */
 
2284
    marginal_width = LabG_MarginLeft(lw) + LabG_MarginRight(lw) +
 
2285
        (2 * (lw->gadget.highlight_thickness + lw->gadget.shadow_thickness));
 
2286
 
 
2287
    marginal_height = LabG_MarginTop(lw) + LabG_MarginBottom(lw) +
 
2288
        (2 * (lw->gadget.highlight_thickness + lw->gadget.shadow_thickness));
 
2289
 
 
2290
    max_text_height = MAX(LabG_TextRect(lw).height, LabG_AccTextRect(lw).height);
 
2291
 
 
2292
    if (XtIsSensitive(wid))
 
2293
        clipgc = LabG_NormalGC(lw);
 
2294
    else
 
2295
        clipgc = LabG_InsensitiveGC(lw);
 
2296
 
 
2297
    /* Clip should include critical margins (see Label.c) */
 
2298
    if (availH < (marginal_height + max_text_height) ||
 
2299
        availW < (marginal_width + LabG_TextRect(lw).width))
 
2300
    {
 
2301
        clip_rect.x = lw->rectangle.x + lw->gadget.highlight_thickness +
 
2302
            lw->gadget.shadow_thickness + LabG_MarginLeft(lw);
 
2303
        clip_rect.y = lw->rectangle.y + lw->gadget.highlight_thickness +
 
2304
            lw->gadget.shadow_thickness + LabG_MarginTop(lw);
 
2305
 
 
2306
        /* Don't allow negative dimensions */
 
2307
        if (availW > marginal_width)
 
2308
            clip_rect.width = availW - marginal_width;
 
2309
        else
 
2310
            clip_rect.width = 0;
 
2311
 
 
2312
        if (availH > marginal_height)
 
2313
            clip_rect.height = availH - marginal_height;
 
2314
        else
 
2315
            clip_rect.height = 0;
 
2316
 
 
2317
        XSetClipRectangles(XtDisplay(lw), clipgc, 0,0, &clip_rect, 1, Unsorted);
 
2318
    } else
 
2319
    XSetClipMask (XtDisplay (lw), clipgc, None);
 
2320
 
 
2321
    /*  Draw the pixmap or text  */
 
2322
    LabelDrawBackground((Widget)lw, event, region, background_box);
 
2323
 
 
2324
    if (LabG_IsPixmap(lw) || LabG_IsPixmapAndText(lw))
 
2325
    {
 
2326
        int depth;
 
2327
 
 
2328
        /* moved before the condition: LabelDrawBackground((Widget)lw, event, region, background_box); */
 
2329
        if (XtIsSensitive(wid))
 
2330
        {
 
2331
            if (Pix (lw) != XmUNSPECIFIED_PIXMAP)
 
2332
            {
 
2333
                gc = LabG_NormalGC(lw);
 
2334
 
 
2335
                XmeGetPixmapData(XtScreen(lw), Pix(lw), NULL, &depth,
 
2336
                    NULL, NULL, NULL, NULL, NULL, NULL);
 
2337
 
 
2338
                if (depth == XtParent(lw)->core.depth)
 
2339
                    XCopyArea (XtDisplay(lw), Pix(lw), XtWindow(lw), gc, 0, 0,
 
2340
                        LabG_PixmapRect(lw).width, LabG_PixmapRect(lw).height,
 
2341
                        lw->rectangle.x + LabG_TextRect(lw).x +
 
2342
                                LabG_PixmapRect(lw).x,
 
2343
                        lw->rectangle.y + LabG_TextRect(lw).y +
 
2344
                                LabG_PixmapRect(lw).y);
 
2345
                else if (depth == 1)
 
2346
                    XCopyPlane (XtDisplay(lw), Pix(lw), XtWindow(lw), gc, 0, 0,
 
2347
                            LabG_PixmapRect(lw).width,
 
2348
                            LabG_PixmapRect(lw).height,
 
2349
                            lw->rectangle.x + LabG_TextRect(lw).x +
 
2350
                                LabG_PixmapRect(lw).x,
 
2351
                            lw->rectangle.y + LabG_TextRect(lw).y +
 
2352
                                LabG_PixmapRect(lw).y,
 
2353
                            1);
 
2354
            }
 
2355
        }
 
2356
        else
 
2357
        {
 
2358
            Pixmap pix_use = Pix_insen (lw) ;
 
2359
 
 
2360
            if (pix_use == XmUNSPECIFIED_PIXMAP)
 
2361
                pix_use = Pix(lw);
 
2362
 
 
2363
            if (pix_use != XmUNSPECIFIED_PIXMAP)
 
2364
            {
 
2365
                gc = LabG_InsensitiveGC(lw);
 
2366
 
 
2367
                XmeGetPixmapData(XtScreen(lw), pix_use, NULL, &depth,
 
2368
                    NULL, NULL, NULL, NULL, NULL, NULL);
 
2369
 
 
2370
                if (depth == XtParent(lw)->core.depth)
 
2371
                    XCopyArea (XtDisplay(lw), pix_use, XtWindow(lw), gc, 0, 0,
 
2372
                        LabG_PixmapRect(lw).width, LabG_PixmapRect(lw).height,
 
2373
                        lw->rectangle.x + LabG_TextRect(lw).x +
 
2374
                                LabG_PixmapRect(lw).x,
 
2375
                        lw->rectangle.y + LabG_TextRect(lw).y +
 
2376
                                LabG_PixmapRect(lw).y);
 
2377
                else if (depth == 1)
 
2378
                    XCopyPlane (XtDisplay(lw), pix_use, XtWindow(lw), gc, 0, 0,
 
2379
                            LabG_PixmapRect(lw).width,
 
2380
                            LabG_PixmapRect(lw).height,
 
2381
                            lw->rectangle.x + LabG_TextRect(lw).x + LabG_PixmapRect(lw).x,
 
2382
                            lw->rectangle.y + LabG_TextRect(lw).y + LabG_PixmapRect(lw).y,
 
2383
                            1);
 
2384
 
 
2385
                /* if no insensitive pixmap but a regular one, we need
 
2386
                to do the stipple manually, since copyarea doesn't */
 
2387
                if (pix_use == Pix(lw))
 
2388
                {
 
2389
                    /* need fill stipple, not opaque */
 
2390
                    XSetFillStyle(XtDisplay(lw), gc, FillStippled);
 
2391
                    XFillRectangle(XtDisplay(lw), XtWindow(lw),
 
2392
                        gc,
 
2393
                        lw->rectangle.x + LabG_TextRect(lw).x +
 
2394
                                LabG_PixmapRect(lw).x,
 
2395
                        lw->rectangle.y + LabG_TextRect(lw).y +
 
2396
                                LabG_PixmapRect(lw).y,
 
2397
                        LabG_PixmapRect(lw).width,
 
2398
                        LabG_PixmapRect(lw).height);
 
2399
                    XSetFillStyle(XtDisplay(lw), gc, FillOpaqueStippled);
 
2400
                }
 
2401
            }
 
2402
        }
 
2403
    }
 
2404
 
 
2405
    if ((LabG_IsText(lw) || LabG_IsPixmapAndText(lw)) && (LabG__label(lw) != NULL))
 
2406
    {
 
2407
        /* TODO this clears the pixmap, but this is needed to draw background */
 
2408
        /* LabelDrawBackground((Widget)lw, event, region, background_box); */
 
2409
        
 
2410
        if (LabG_Mnemonic(lw) != XK_VoidSymbol)
 
2411
        {
 
2412
            /* CR 5181: Convert the mnemonic keysym to a character string. */
 
2413
            char tmp[MB_LEN_MAX * 2];
 
2414
            XmString underline;
 
2415
 
 
2416
            tmp[_XmOSKeySymToCharacter(LabG_Mnemonic(lw), NULL, tmp)] = '\0';
 
2417
            underline = XmStringCreate(tmp, LabG_MnemonicCharset(lw));
 
2418
 
 
2419
            XmStringDrawUnderline(XtDisplay(lw), XtWindow(lw),
 
2420
                LabG_Font(lw), LabG__label(lw),
 
2421
                (XtIsSensitive(wid) ?
 
2422
                LabG_NormalGC(lw) : LabG_InsensitiveGC(lw)),
 
2423
                lw->rectangle.x + LabG_TextRect(lw).x + LabG_StringRect(lw).x,
 
2424
                lw->rectangle.y + LabG_TextRect(lw).y + LabG_StringRect(lw).y,
 
2425
                LabG_StringRect(lw).width, LabG_Alignment(lw),
 
2426
                LayoutG(lw), NULL, underline);
 
2427
            XmStringFree(underline);
 
2428
        }
 
2429
        else
 
2430
            XmStringDraw (XtDisplay(lw), XtWindow(lw),
 
2431
                LabG_Font(lw), LabG__label(lw),
 
2432
                (XtIsSensitive(wid) ?
 
2433
                LabG_NormalGC(lw) : LabG_InsensitiveGC(lw)),
 
2434
            lw->rectangle.x + LabG_TextRect(lw).x + LabG_StringRect(lw).x,
 
2435
            lw->rectangle.y + LabG_TextRect(lw).y + LabG_StringRect(lw).y,
 
2436
            LabG_StringRect(lw).width,
 
2437
            LabG_Alignment(lw), LayoutG(lw), NULL);
 
2438
#ifdef USE_XFT
 
2439
        if (!XtIsSensitive(wid)) {
 
2440
          XSetFillStyle(XtDisplay(lw), LabG_InsensitiveGC(lw), FillStippled);
 
2441
          XFillRectangle(XtDisplay(lw), XtWindow(lw), LabG_InsensitiveGC(lw),
 
2442
                        lw->rectangle.x + LabG_TextRect(lw).x +
 
2443
                                LabG_StringRect(lw).x,
 
2444
                        lw->rectangle.y + LabG_TextRect(lw).y +
 
2445
                                LabG_StringRect(lw).y,
 
2446
                        LabG_StringRect(lw).width,
 
2447
                        LabG_StringRect(lw).height);
 
2448
          XSetFillStyle(XtDisplay(lw), LabG_InsensitiveGC(lw), FillOpaqueStippled);
 
2449
        }
 
2450
#endif
 
2451
    }
 
2452
 
 
2453
    if (LabG__acceleratorText(lw) != NULL)
 
2454
    {
 
2455
        /* Since accelerator text is drawn by moving in from the right,
 
2456
         * it is possible to overwrite label text when there is clipping,
 
2457
         * Therefore draw accelerator text only if there is enough
 
2458
         * room for everything */
 
2459
 
 
2460
        if ((lw->rectangle.width) >=
 
2461
            (2 * (lw->gadget.highlight_thickness +
 
2462
            lw->gadget.shadow_thickness +
 
2463
            LabG_MarginWidth(lw)) +
 
2464
            LabG_MarginLeft(lw) + LabG_TextRect(lw).width +
 
2465
            LabG_MarginRight(lw)))
 
2466
        {
 
2467
            XmStringDraw (XtDisplay(lw), XtWindow(lw),
 
2468
                LabG_Font(lw), LabG__acceleratorText(lw),
 
2469
                (XtIsSensitive(wid) ?
 
2470
                LabG_NormalGC(lw) : LabG_InsensitiveGC(lw)),
 
2471
                lw->rectangle.x + LabG_AccTextRect(lw).x,
 
2472
                lw->rectangle.y + LabG_AccTextRect(lw).y,
 
2473
                LabG_AccTextRect(lw).width, XmALIGNMENT_END,
 
2474
                LayoutG(lw), NULL);
 
2475
        }
 
2476
    }
 
2477
 
 
2478
    /* Redraw the proper highlight  */
 
2479
    if (! LabG_IsMenupane(lw) && LabG_MenuType(lw) != XmMENU_BAR)
 
2480
    {
 
2481
        if (lw->gadget.highlighted)
 
2482
        {
 
2483
            (*((XmGadgetClass) XtClass(lw))->gadget_class.border_highlight)
 
2484
                ((Widget) lw);
 
2485
        }
 
2486
    }
 
2487
}
 
2488
 
 
2489
 
 
2490
/************************************************************************
 
2491
 *
 
2492
 *  SetValues
 
2493
 *      This routine will take care of any changes that have been made
 
2494
 *
 
2495
 ************************************************************************/
 
2496
 
 
2497
/*ARGSUSED*/
 
2498
static Boolean
 
2499
SetValues(Widget cw,
 
2500
Widget rw,
 
2501
Widget nw,
 
2502
ArgList args,                                     /* unused */
 
2503
Cardinal *num_args)                               /* unused */
 
2504
{
 
2505
    XmLabelGadget current = (XmLabelGadget) cw;
 
2506
    XmLabelGadget req = (XmLabelGadget) rw;
 
2507
    XmLabelGadget new_w = (XmLabelGadget) nw;
 
2508
    Boolean flag = False;
 
2509
    Boolean newstring = False;
 
2510
    Boolean ProcessFlag = FALSE;
 
2511
    Boolean CleanupFontFlag = FALSE;
 
2512
    Boolean Call_Resize = False;
 
2513
    XmMenuSystemTrait menuSTrait;
 
2514
 
 
2515
    /* Invalidate the basline cache if necessary. */
 
2516
    if ((LabG__label(new_w) != LabG__label(current)) ||
 
2517
        (LabG_Font(new_w) != LabG_Font(current)))
 
2518
    {
 
2519
        if (new_w->label.baselines)
 
2520
        {
 
2521
            XtFree ((char*) new_w->label.baselines);
 
2522
            new_w->label.baselines = NULL;
 
2523
        }
 
2524
    }
 
2525
 
 
2526
    /*  If the label has changed, make a copy of the new label,  */
 
2527
    /*  and free the old label.                                  */
 
2528
 
 
2529
    if (LabG__label(new_w)!= LabG__label(current))
 
2530
    {
 
2531
        newstring = True;
 
2532
        if (LabG__label(new_w) == NULL)
 
2533
        {
 
2534
            LabG__label(new_w) =
 
2535
                XmStringCreateLocalized(XrmQuarkToString (current->object.xrm_name));
 
2536
        }
 
2537
        else
 
2538
        {
 
2539
            if (XmeStringIsValid((XmString) LabG__label(new_w)))
 
2540
            {
 
2541
                LabG__label(new_w) = XmStringCopy((XmString) LabG__label(new_w));
 
2542
            }
 
2543
            else
 
2544
            {
 
2545
                XmeWarning((Widget) new_w, CS_STRING_MESSAGE);
 
2546
                LabG__label(new_w) =
 
2547
                    XmStringCreateLocalized(XrmQuarkToString(new_w->object.xrm_name));
 
2548
            }
 
2549
        }
 
2550
 
 
2551
        XmStringFree(LabG__label(current));
 
2552
        LabG__label(current)= NULL;
 
2553
        LabG__label(req)= NULL;
 
2554
    }
 
2555
 
 
2556
    if (LabG_MarginRight(new_w) != LabG_MarginRight(current))
 
2557
        new_w->label.acc_right_delta = 0;
 
2558
    if (LabG_MarginLeft(new_w) != LabG_MarginLeft(current))
 
2559
        new_w->label.acc_left_delta = 0;
 
2560
 
 
2561
    if ((LabG__acceleratorText(new_w) != LabG__acceleratorText(current)) &&
 
2562
        LabG_IsMenupane(new_w))
 
2563
    {
 
2564
        /* BEGIN OSF Fix pir 1098 */
 
2565
        newstring = TRUE;
 
2566
        /* END OSF Fix pir 1098 */
 
2567
        if (LabG__acceleratorText(new_w) != NULL)
 
2568
        {
 
2569
            if (XmeStringIsValid((XmString) LabG__acceleratorText(new_w)))
 
2570
            {
 
2571
                if ((XmIsCascadeButtonGadget(new_w)) &&
 
2572
                    (LabG__acceleratorText(new_w) != NULL))
 
2573
                    LabG__acceleratorText(new_w) = NULL;
 
2574
                else
 
2575
                    LabG__acceleratorText(new_w) =
 
2576
                        XmStringCopy(LabG__acceleratorText(new_w));
 
2577
                XmStringFree(LabG__acceleratorText(current));
 
2578
                LabG__acceleratorText(current)= NULL;
 
2579
                LabG__acceleratorText(req)= NULL;
 
2580
            }
 
2581
            else
 
2582
            {
 
2583
                XmeWarning((Widget) new_w, ACC_MESSAGE);
 
2584
                LabG__acceleratorText(new_w) = NULL;
 
2585
                XmStringFree(LabG__acceleratorText(current));
 
2586
                LabG__acceleratorText(current)= NULL;
 
2587
                LabG__acceleratorText(req)= NULL;
 
2588
            }
 
2589
        }
 
2590
        /* BEGIN OSF Fix pir 1098 */
 
2591
        else if (LabG__acceleratorText(current))
 
2592
        {
 
2593
            /* CR 3481:  Don't blindly force the margin back to 0; */
 
2594
            /*  try to preserve the user specified value. */
 
2595
            if (LayoutIsRtoLG(new_w))
 
2596
            {
 
2597
                LabG_MarginLeft(new_w) -= new_w->label.acc_left_delta;
 
2598
                new_w->label.acc_left_delta = 0;
 
2599
            }
 
2600
            else
 
2601
            {
 
2602
                LabG_MarginRight(new_w) -= new_w->label.acc_right_delta;
 
2603
                new_w->label.acc_right_delta = 0;
 
2604
            }
 
2605
        }
 
2606
        /* END OSF Fix pir 1098 */
 
2607
    }
 
2608
    else
 
2609
        LabG__acceleratorText(new_w) = LabG__acceleratorText(current);
 
2610
 
 
2611
    if (LabG_Font(new_w) != LabG_Font(current))
 
2612
    {
 
2613
        CleanupFontFlag = True;
 
2614
        if (LabG_Font(new_w) == NULL)
 
2615
        {
 
2616
            /* CR 2990: let subclasses pick their own default fonts. */
 
2617
            LabG_Font(new_w) =
 
2618
                XmeGetDefaultRenderTable((Widget) new_w, XmLABEL_FONTLIST);
 
2619
        }
 
2620
        LabG_Font(new_w) = XmFontListCopy (LabG_Font(new_w));
 
2621
    }
 
2622
 
 
2623
    /*  Reinitialize the interesting input types.  */
 
2624
 
 
2625
    new_w->gadget.event_mask = XmHELP_EVENT;
 
2626
 
 
2627
    new_w->gadget.event_mask |=
 
2628
        XmFOCUS_IN_EVENT | XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT |
 
2629
        XmBDRAG_EVENT;
 
2630
 
 
2631
    if ((LabG_MenuType(new_w) == XmMENU_POPUP) ||
 
2632
        (LabG_MenuType(new_w) == XmMENU_PULLDOWN) ||
 
2633
        (LabG_MenuType(new_w) == XmMENU_BAR))
 
2634
        new_w->gadget.highlight_thickness = 0;
 
2635
 
 
2636
    if (!XmRepTypeValidValue(XmRID_LABEL_TYPE, LabG_LabelType(new_w),
 
2637
        (Widget) new_w))
 
2638
    {
 
2639
        LabG_LabelType(new_w) = LabG_LabelType(current);
 
2640
    }
 
2641
 
 
2642
    if (!XmRepTypeValidValue(XmRID_PIXMAP_PLACEMENT, LabG_PixmapPlacement(new_w),
 
2643
        (Widget) new_w))
 
2644
    {
 
2645
        LabG_PixmapPlacement(new_w) = LabG_PixmapPlacement(current);
 
2646
    }
 
2647
 
 
2648
    if (LayoutG(new_w) != LayoutG(current))
 
2649
    {
 
2650
        /* If no new margins specified swap them */
 
2651
        if ((LayoutIsRtoLG(current) != LayoutIsRtoLG(new_w)) &&
 
2652
            (LabG_MarginLeft(current)  == LabG_MarginLeft(new_w)) &&
 
2653
            (LabG_MarginRight(current) == LabG_MarginRight(new_w)))
 
2654
        {
 
2655
            LabG_MarginLeft(new_w)  = LabG_MarginRight(current);
 
2656
            LabG_MarginRight(new_w) = LabG_MarginLeft(current);
 
2657
        }
 
2658
        flag = TRUE;
 
2659
    }
 
2660
 
 
2661
    /* ValidateInputs(new_w); */
 
2662
 
 
2663
    if (((LabG_IsText(new_w) || LabG_IsPixmapAndText(new_w)) &&
 
2664
        (newstring || (LabG_Font(new_w) != LabG_Font(current)))) ||
 
2665
        ((LabG_IsPixmap(new_w) || LabG_IsPixmapAndText(new_w)) &&
 
2666
        ((LabG_Pixmap(new_w) != LabG_Pixmap(current)) ||
 
2667
        (LabG_PixmapInsensitive(new_w) != LabG_PixmapInsensitive(current)) ||
 
2668
        /* When you have different sized pixmaps for sensitive and */
 
2669
        /* insensitive states and sensitivity changes, */
 
2670
        /* the right size is chosen. (osfP2560) */
 
2671
        (XtIsSensitive(nw) != XtIsSensitive(cw)))) ||
 
2672
        (LabG_IsPixmapAndText(new_w) &&
 
2673
        LabG_PixmapPlacement(new_w) != LabG_PixmapPlacement(current)) ||
 
2674
        (LabG_LabelType(new_w) != LabG_LabelType(current)))
 
2675
    {
 
2676
        /* CR 9179: back out CR 5419 changes. */
 
2677
        _XmCalcLabelGDimensions((Widget) new_w);
 
2678
 
 
2679
        if (LabG_RecomputeSize(new_w))
 
2680
        {
 
2681
            if (req->rectangle.width == current->rectangle.width)
 
2682
                new_w->rectangle.width = 0;
 
2683
            if (req->rectangle.height == current->rectangle.height)
 
2684
                new_w->rectangle.height = 0;
 
2685
        }
 
2686
 
 
2687
        Call_Resize = True;
 
2688
 
 
2689
        flag = True;
 
2690
    }
 
2691
 
 
2692
    if ((LabG_Alignment(new_w)!= LabG_Alignment(current)) ||
 
2693
        (LayoutG(new_w) != LayoutG(current)))
 
2694
    {
 
2695
        if (!XmRepTypeValidValue(XmRID_ALIGNMENT, LabG_Alignment(new_w),
 
2696
            (Widget) new_w))
 
2697
        {
 
2698
            LabG_Alignment(new_w) = LabG_Alignment(current);
 
2699
        }
 
2700
 
 
2701
        Call_Resize = True;
 
2702
 
 
2703
        flag = True;
 
2704
    }
 
2705
 
 
2706
    if ((LabG_MarginHeight(new_w) != LabG_MarginHeight(current)) ||
 
2707
        (LabG_MarginWidth(new_w) != LabG_MarginWidth(current)) ||
 
2708
        (LabG_MarginRight(new_w) != LabG_MarginRight(current)) ||
 
2709
        (LabG_MarginLeft(new_w)!= LabG_MarginLeft(current)) ||
 
2710
        (LabG_MarginTop(new_w)!= LabG_MarginTop(current)) ||
 
2711
        (LabG_MarginBottom(new_w)!= LabG_MarginBottom(current)) ||
 
2712
        (new_w->gadget.shadow_thickness != current->gadget.shadow_thickness) ||
 
2713
        (new_w->gadget.highlight_thickness !=
 
2714
        current->gadget.highlight_thickness) ||
 
2715
        ((new_w->rectangle.width <= 0) || (new_w->rectangle.height <= 0)) ||
 
2716
        (LabG_PixmapTextPadding(new_w) != LabG_PixmapTextPadding(current)))
 
2717
    {
 
2718
        if (LabG_RecomputeSize(new_w))
 
2719
        {
 
2720
            if (req->rectangle.width == current->rectangle.width)
 
2721
                new_w->rectangle.width = 0;
 
2722
            if (req->rectangle.height == current->rectangle.height)
 
2723
                new_w->rectangle.height = 0;
 
2724
        }
 
2725
 
 
2726
        Call_Resize = True;
 
2727
        flag = True;
 
2728
    }
 
2729
 
 
2730
    /* Resize is called only if we need to calculate the dimensions or */
 
2731
    /* coordinates  for the string.                                   */
 
2732
 
 
2733
    if (Call_Resize)
 
2734
    {
 
2735
 
 
2736
        XtWidgetProc resize;
 
2737
 
 
2738
        _XmProcessLock();
 
2739
        resize = (((XmLabelGadgetClassRec *)(new_w->object.widget_class))->
 
2740
            rect_class.resize);
 
2741
        _XmProcessUnlock();
 
2742
 
 
2743
        (* (resize)) ((Widget) new_w);
 
2744
    }
 
2745
 
 
2746
    /* If the sensitivity has changed then we must redisplay. */
 
2747
    if (XtIsSensitive(nw) != XtIsSensitive(cw))
 
2748
    {
 
2749
        flag = True;
 
2750
    }
 
2751
 
 
2752
    /*  Force the traversal flag when in a menu.  */
 
2753
    if ((XtClass(new_w) == xmLabelGadgetClass) &&
 
2754
        ((LabG_MenuType(new_w) == XmMENU_POPUP) ||
 
2755
        (LabG_MenuType(new_w) == XmMENU_PULLDOWN) ||
 
2756
        (LabG_MenuType(new_w) == XmMENU_OPTION)))
 
2757
    {
 
2758
        new_w->gadget.traversal_on = False;
 
2759
        new_w->gadget.highlight_on_enter = False;
 
2760
    }
 
2761
 
 
2762
    if (LabG_Font(new_w) != LabG_Font(current) ||
 
2763
        LabG_Foreground(new_w) != LabG_Foreground(current) ||
 
2764
        LabG_Background(new_w) != LabG_Background(current))
 
2765
    {
 
2766
        /* Recreate the GC's if the font has been changed */
 
2767
        XtReleaseGC (XtParent (current), LabG_NormalGC(current));
 
2768
        XtReleaseGC (XtParent (current), LabG_InsensitiveGC(current));
 
2769
        SetNormalGC(new_w);
 
2770
        flag = True;
 
2771
    }
 
2772
 
 
2773
    /*
 
2774
     * The test for foreground is done here to allow for subclasses
 
2775
     * to use this gc in a graphix op that may reference the background
 
2776
     * field of the GC (i.e. in this gc background is set to LabG_Foreground.
 
2777
     */
 
2778
 
 
2779
    if (LabG_Background(new_w) != LabG_Background(current) ||
 
2780
        LabG_Foreground(new_w) != LabG_Foreground(current))
 
2781
    {
 
2782
        XtReleaseGC (XtParent (current), LabG_BackgroundGC(current));
 
2783
        _XmLabelSetBackgroundGC(new_w);
 
2784
        flag = True;
 
2785
    }
 
2786
 
 
2787
    if (LabG_TopShadowColor(new_w) != LabG_TopShadowColor(current) ||
 
2788
        LabG_TopShadowPixmap(new_w) != LabG_TopShadowPixmap(current))
 
2789
    {
 
2790
        XtReleaseGC (XtParent (current), LabG_TopShadowGC(current));
 
2791
        LabG_TopShadowGC(new_w) =
 
2792
            _XmGetPixmapBasedGC (XtParent(nw),
 
2793
            LabG_TopShadowColor(new_w),
 
2794
            LabG_Background(new_w),
 
2795
            LabG_TopShadowPixmap(new_w));
 
2796
        flag = True;
 
2797
    }
 
2798
 
 
2799
    if (LabG_BottomShadowColor(new_w) != LabG_BottomShadowColor(current) ||
 
2800
        LabG_BottomShadowPixmap(new_w) != LabG_BottomShadowPixmap(current))
 
2801
    {
 
2802
        XtReleaseGC (XtParent (current), LabG_BottomShadowGC(current));
 
2803
        LabG_BottomShadowGC(new_w) =
 
2804
            _XmGetPixmapBasedGC (XtParent(nw),
 
2805
            LabG_BottomShadowColor(new_w),
 
2806
            LabG_Background(new_w),
 
2807
            LabG_BottomShadowPixmap(new_w));
 
2808
        flag = True;
 
2809
    }
 
2810
 
 
2811
    if (LabG_HighlightColor(new_w) != LabG_HighlightColor(current) ||
 
2812
        LabG_HighlightPixmap(new_w) != LabG_HighlightPixmap(current))
 
2813
    {
 
2814
        XtReleaseGC (XtParent (current), LabG_HighlightGC(current));
 
2815
        LabG_HighlightGC(new_w) =
 
2816
            _XmGetPixmapBasedGC (XtParent(nw),
 
2817
            LabG_HighlightColor(new_w),
 
2818
            LabG_Background(new_w),
 
2819
            LabG_HighlightPixmap(new_w));
 
2820
        flag = True;
 
2821
    }
 
2822
 
 
2823
    if ((LabG_MenuType(new_w) != XmWORK_AREA) &&
 
2824
        (LabG_Mnemonic(new_w) != LabG_Mnemonic(current)))
 
2825
    {
 
2826
        /* New grabs only required if mnemonic changes */
 
2827
        ProcessFlag = TRUE;
 
2828
        if (LabG_LabelType(new_w) == XmSTRING ||
 
2829
           LabG_LabelType(new_w) == XmPIXMAP_AND_STRING)
 
2830
            flag = TRUE;
 
2831
    }
 
2832
 
 
2833
    if (LabG_MnemonicCharset(new_w) != LabG_MnemonicCharset(current))
 
2834
    {
 
2835
        if (LabG_MnemonicCharset(new_w))
 
2836
            LabG_MnemonicCharset(new_w) =
 
2837
                _XmStringCharsetCreate(LabG_MnemonicCharset (new_w));
 
2838
        else
 
2839
            LabG_MnemonicCharset(new_w) =
 
2840
                _XmStringCharsetCreate(XmFONTLIST_DEFAULT_TAG);
 
2841
 
 
2842
        if (LabG_MnemonicCharset (current) != NULL)
 
2843
            XtFree(LabG_MnemonicCharset(current));
 
2844
 
 
2845
        if (LabG_LabelType(new_w) == XmSTRING ||
 
2846
           LabG_LabelType(new_w) == XmPIXMAP_AND_STRING)
 
2847
            flag = TRUE;
 
2848
    }
 
2849
 
 
2850
    if (LabG_IsMenupane(new_w) &&
 
2851
        (LabG_Accelerator(new_w) != LabG_Accelerator(current)))
 
2852
    {
 
2853
        if (LabG_Accelerator(new_w) != NULL)
 
2854
        {
 
2855
            /* Copy the accelerator into local space */
 
2856
            LabG_Accelerator(new_w) = XtNewString(LabG_Accelerator(new_w));
 
2857
        }
 
2858
 
 
2859
        if (LabG_Accelerator(current) != NULL)
 
2860
            XtFree(LabG_Accelerator(current));
 
2861
 
 
2862
        LabG_Accelerator(current) = NULL;
 
2863
        LabG_Accelerator(req) = NULL;
 
2864
        ProcessFlag = TRUE;
 
2865
    }
 
2866
    else
 
2867
        LabG_Accelerator(new_w) = LabG_Accelerator(current);
 
2868
 
 
2869
    menuSTrait = (XmMenuSystemTrait)
 
2870
        XmeTraitGet((XtPointer) XtClass(XtParent(new_w)), XmQTmenuSystem);
 
2871
 
 
2872
    if (ProcessFlag && menuSTrait != NULL)
 
2873
        menuSTrait->updateBindings((Widget)new_w, XmREPLACE);
 
2874
 
 
2875
    if (flag && (LabG_MenuType(new_w) == XmMENU_PULLDOWN) &&
 
2876
        menuSTrait != NULL)
 
2877
        menuSTrait->updateHistory(XtParent(new_w), (Widget) new_w, True);
 
2878
 
 
2879
    if (CleanupFontFlag)
 
2880
        if (LabG_Font(current)) XmFontListFree(LabG_Font(current));
 
2881
 
 
2882
    return flag;
 
2883
}
 
2884
 
 
2885
 
 
2886
/*
 
2887
 * So complications.  HandleRedraw is a wrapper that calls _XmLabelGCVTRedraw
 
2888
 * which does the work for the trait stuff.
 
2889
 *
 
2890
 * _XmLabelGCVTRedraw returns a boolean which determines if the child, not the
 
2891
 * parent should be redrawn.
 
2892
 *
 
2893
 * This is done to serve as a form of inheritance.  ToggleBG needs all the
 
2894
 * LabelG stuff changed plus some of its own state.  Therefore ToggleBG
 
2895
 * will call _XmLabelGCVTRedraw.
 
2896
 */
 
2897
 
 
2898
static Boolean
 
2899
HandleRedraw (Widget kid,
 
2900
Widget cur_parent,
 
2901
Widget new_parent,
 
2902
Mask visual_flag)
 
2903
{
 
2904
    Boolean redraw = False;
 
2905
    XtExposeProc  expose;
 
2906
 
 
2907
    /* Don't change with parent.  New Gadget behavior has been enabled. */
 
2908
    redraw = _XmLabelGCVTRedraw (kid,  cur_parent, new_parent, visual_flag);
 
2909
 
 
2910
    _XmProcessLock();
 
2911
    expose = ((XmLabelGadgetClassRec *)(XtClass(kid)))->rect_class.expose;
 
2912
    _XmProcessUnlock();
 
2913
 
 
2914
    if (redraw)
 
2915
    {
 
2916
        if (! XtIsRealized(kid))
 
2917
        {
 
2918
            return redraw;
 
2919
        }
 
2920
        else
 
2921
        {
 
2922
            (* (expose)) ((Widget)kid, NULL, (Region) NULL);
 
2923
        }
 
2924
    }
 
2925
    return False;
 
2926
}
 
2927
 
 
2928
 
 
2929
Boolean
 
2930
_XmLabelGCVTRedraw(Widget kid,
 
2931
Widget cur_parent,
 
2932
Widget new_parent,
 
2933
Mask visual_flag)
 
2934
{
 
2935
    XmLabelGadget lw = (XmLabelGadget) kid;
 
2936
    XmManagerWidget mw = (XmManagerWidget) new_parent;
 
2937
    XmManagerWidget curmw = (XmManagerWidget) cur_parent;
 
2938
    Boolean redraw = False, do_normal = False, do_background = False;
 
2939
    XmLabelGCacheObjPart oldCopy;
 
2940
 
 
2941
    /*
 
2942
     * Since we are here the instance record is going to be changed.
 
2943
     * So break this out out the cache, make the changes and reinsert
 
2944
     * below.
 
2945
     */
 
2946
 
 
2947
    _XmProcessLock();
 
2948
    _XmCacheCopy((XtPointer) LabG_Cache(lw), (XtPointer) &oldCopy,
 
2949
        sizeof(XmLabelGCacheObjPart));
 
2950
    _XmCacheDelete ((XtPointer) LabG_Cache(lw));
 
2951
    _XmProcessUnlock();
 
2952
    LabG_Cache(lw) = &oldCopy;
 
2953
 
 
2954
    if ((visual_flag & VisualBackgroundPixel) &&
 
2955
        (LabG_Background(lw) == curmw->core.background_pixel))
 
2956
    {
 
2957
        redraw = do_background = do_normal = True;
 
2958
        LabG_Background(lw) = mw->core.background_pixel;
 
2959
    }
 
2960
 
 
2961
    if (visual_flag & VisualBackgroundPixmap)
 
2962
    {
 
2963
        redraw = do_background = True;
 
2964
    }
 
2965
 
 
2966
    if ((visual_flag & VisualForeground) &&
 
2967
        (LabG_Foreground(lw) == curmw->manager.foreground))
 
2968
    {
 
2969
        redraw = do_normal = True;
 
2970
        LabG_Foreground(lw) = mw->manager.foreground;
 
2971
    }
 
2972
 
 
2973
    if (do_background)
 
2974
    {
 
2975
        XtReleaseGC (XtParent(lw), LabG_BackgroundGC(lw));
 
2976
        _XmLabelSetBackgroundGC((XmLabelGadget)lw);
 
2977
    }
 
2978
 
 
2979
    if (do_normal)
 
2980
    {
 
2981
        XtReleaseGC (XtParent(lw), LabG_NormalGC(lw));
 
2982
        XtReleaseGC (XtParent(lw), LabG_InsensitiveGC(lw));
 
2983
        SetNormalGC((XmLabelGadget)lw);
 
2984
    }
 
2985
 
 
2986
    if (visual_flag & (VisualTopShadowColor | VisualTopShadowPixmap))
 
2987
    {
 
2988
        XtReleaseGC (XtParent(lw), LabG_TopShadowGC(lw));
 
2989
 
 
2990
        if(LabG_TopShadowColor(lw) == curmw->manager.top_shadow_color)
 
2991
            LabG_TopShadowColor(lw) = mw->manager.top_shadow_color;
 
2992
 
 
2993
        if(LabG_TopShadowPixmap(lw) == curmw->manager.top_shadow_pixmap &&
 
2994
            (LabG_TopShadowPixmap(lw) != XmUNSPECIFIED_PIXMAP
 
2995
            || LabG_TopShadowColor(lw) == curmw->manager.top_shadow_color))
 
2996
            LabG_TopShadowPixmap(lw) = mw->manager.top_shadow_pixmap;
 
2997
 
 
2998
        LabG_TopShadowGC(lw) =
 
2999
            _XmGetPixmapBasedGC (XtParent(lw),
 
3000
            LabG_TopShadowColor(lw),
 
3001
            LabG_Background(lw),
 
3002
            LabG_TopShadowPixmap(lw));
 
3003
 
 
3004
        redraw = True;
 
3005
    }
 
3006
 
 
3007
    if (visual_flag & (VisualBottomShadowColor | VisualBottomShadowPixmap))
 
3008
    {
 
3009
        XtReleaseGC (XtParent(lw), LabG_BottomShadowGC(lw));
 
3010
 
 
3011
        if(LabG_BottomShadowColor(lw) == curmw->manager.bottom_shadow_color)
 
3012
            LabG_BottomShadowColor(lw) = mw->manager.bottom_shadow_color;
 
3013
 
 
3014
        if(LabG_BottomShadowPixmap(lw) == curmw->manager.bottom_shadow_pixmap &&
 
3015
            (LabG_BottomShadowPixmap(lw) != XmUNSPECIFIED_PIXMAP
 
3016
            || LabG_BottomShadowColor(lw) == curmw->manager.bottom_shadow_color))
 
3017
            LabG_BottomShadowPixmap(lw) = mw->manager.bottom_shadow_pixmap;
 
3018
 
 
3019
        LabG_BottomShadowGC(lw) =
 
3020
            _XmGetPixmapBasedGC (XtParent(lw),
 
3021
            LabG_BottomShadowColor(lw),
 
3022
            LabG_Background(lw),
 
3023
            LabG_BottomShadowPixmap(lw));
 
3024
 
 
3025
        redraw = True;
 
3026
    }
 
3027
 
 
3028
    if (visual_flag & (VisualHighlightColor | VisualHighlightPixmap))
 
3029
    {
 
3030
        XtReleaseGC (XtParent(lw), LabG_HighlightGC(lw));
 
3031
 
 
3032
        if(LabG_HighlightColor(lw) == curmw->manager.highlight_color)
 
3033
            LabG_HighlightColor(lw) = mw->manager.highlight_color;
 
3034
 
 
3035
        if(LabG_HighlightPixmap(lw) == curmw->manager.highlight_pixmap &&
 
3036
            (LabG_HighlightPixmap(lw) != XmUNSPECIFIED_PIXMAP
 
3037
            || LabG_HighlightColor(lw) == curmw->manager.highlight_color))
 
3038
            LabG_HighlightPixmap(lw) = mw->manager.highlight_pixmap;
 
3039
 
 
3040
        LabG_HighlightGC(lw) =
 
3041
            _XmGetPixmapBasedGC (XtParent(lw),
 
3042
            LabG_HighlightColor(lw),
 
3043
            LabG_Background(lw),
 
3044
            LabG_HighlightPixmap(lw));
 
3045
 
 
3046
        redraw = True;
 
3047
    }
 
3048
 
 
3049
    _XmProcessLock();
 
3050
    LabG_Cache(lw) = (XmLabelGCacheObjPart *)
 
3051
        _XmCachePart(LabG_ClassCachePart(lw), (XtPointer) LabG_Cache(lw),
 
3052
        sizeof(XmLabelGCacheObjPart));
 
3053
    _XmProcessUnlock();
 
3054
    return redraw;
 
3055
}
 
3056
 
 
3057
 
 
3058
/************************************************************************
 
3059
 *
 
3060
 *  InputDispatch
 
3061
 *     This function catches input sent by a manager and dispatches it
 
3062
 *     to the individual routines.
 
3063
 *
 
3064
 ************************************************************************/
 
3065
 
 
3066
static void
 
3067
InputDispatch(Widget wid,
 
3068
XEvent *event,
 
3069
Mask event_mask)
 
3070
{
 
3071
    XmLabelGadget lg = (XmLabelGadget) wid;
 
3072
 
 
3073
    if (event_mask & XmHELP_EVENT)
 
3074
        Help ((Widget) lg, event);
 
3075
    else if (event_mask & XmENTER_EVENT)
 
3076
        _XmEnterGadget ((Widget) lg, event, NULL, NULL);
 
3077
    else if (event_mask & XmLEAVE_EVENT)
 
3078
        _XmLeaveGadget ((Widget) lg, event, NULL, NULL);
 
3079
    else if (event_mask & XmFOCUS_IN_EVENT)
 
3080
        _XmFocusInGadget ((Widget) lg, event, NULL, NULL);
 
3081
    else if (event_mask & XmFOCUS_OUT_EVENT)
 
3082
        _XmFocusOutGadget ((Widget) lg, event, NULL, NULL);
 
3083
    else if (event_mask & XmBDRAG_EVENT)
 
3084
        _XmProcessDrag ((Widget) lg, event, NULL, NULL);
 
3085
}
 
3086
 
 
3087
 
 
3088
/************************************************************************
 
3089
 *
 
3090
 *  Help
 
3091
 *      This routine is called if the user made a help selection
 
3092
 *      on the widget.
 
3093
 *
 
3094
 ************************************************************************/
 
3095
 
 
3096
static void
 
3097
Help(Widget w,
 
3098
XEvent *event)
 
3099
{
 
3100
    XmLabelGadget lg = (XmLabelGadget) w;
 
3101
    XmMenuSystemTrait menuSTrait;
 
3102
 
 
3103
    menuSTrait = (XmMenuSystemTrait)
 
3104
        XmeTraitGet((XtPointer) XtClass(XtParent(lg)), XmQTmenuSystem);
 
3105
 
 
3106
    if (LabG_IsMenupane(lg) && (menuSTrait != NULL))
 
3107
        menuSTrait->popdown(XtParent(lg), event);
 
3108
 
 
3109
    _XmSocorro(w, event, NULL, NULL);
 
3110
}
 
3111
 
 
3112
 
 
3113
/************************************************************************
 
3114
 *
 
3115
 *  GetLabelString
 
3116
 *     This is a get values hook function that returns the external
 
3117
 *     form of the label string from the internal form.
 
3118
 *
 
3119
 ***********************************************************************/
 
3120
 
 
3121
/*ARGSUSED*/
 
3122
static void
 
3123
GetLabelString(Widget wid,
 
3124
int offset,
 
3125
XtArgVal *value)
 
3126
{
 
3127
    XmLabelGadget lw = (XmLabelGadget) wid;
 
3128
    XmString string;
 
3129
 
 
3130
    string = XmStringCopy(LabG__label(lw));
 
3131
 
 
3132
    *value = (XtArgVal) string;
 
3133
}
 
3134
 
 
3135
 
 
3136
/************************************************************************
 
3137
 *
 
3138
 *  GetAccelerator
 
3139
 *     This is a get values hook function that returns a copy
 
3140
 *     of the accelerator string.
 
3141
 *
 
3142
 ***********************************************************************/
 
3143
 
 
3144
/*ARGSUSED*/
 
3145
static void
 
3146
GetAccelerator(Widget wid,
 
3147
int offset,
 
3148
XtArgVal *value)
 
3149
{
 
3150
    XmLabelGadget lw = (XmLabelGadget) wid;
 
3151
    String string;
 
3152
 
 
3153
    string = XtNewString(LabG_Accelerator(lw));
 
3154
 
 
3155
    *value = (XtArgVal) string;
 
3156
}
 
3157
 
 
3158
 
 
3159
/************************************************************************
 
3160
 *
 
3161
 *  GetAcceleratorText
 
3162
 *     This is a get values hook function that returns the external
 
3163
 *     form of the accelerator text from the internal form.
 
3164
 *
 
3165
 ***********************************************************************/
 
3166
 
 
3167
/*ARGSUSED*/
 
3168
static void
 
3169
GetAcceleratorText(Widget wid,
 
3170
int offset,
 
3171
XtArgVal *value)
 
3172
{
 
3173
    XmLabelGadget lw = (XmLabelGadget) wid;
 
3174
    XmString string;
 
3175
 
 
3176
    string = XmStringCopy(LabG__acceleratorText(lw));
 
3177
 
 
3178
    *value = (XtArgVal) string;
 
3179
}
 
3180
 
 
3181
 
 
3182
/************************************************************************
 
3183
 *
 
3184
 *  _XmStringCharsetCreate
 
3185
 *
 
3186
 ************************************************************************/
 
3187
 
 
3188
static XmStringCharSet
 
3189
_XmStringCharsetCreate(XmStringCharSet stringcharset)
 
3190
{
 
3191
    return (XmStringCharSet) XtNewString((char*) stringcharset);
 
3192
}
 
3193
 
 
3194
 
 
3195
/************************************************************************
 
3196
 *
 
3197
 *  GetMnemonicCharset
 
3198
 *     This is a get values hook function that returns the external
 
3199
 *     form of the mnemonicCharset from the internal form.
 
3200
 *  : Returns a string containg the mnemonicCharset.
 
3201
 *    Caller must free the string .
 
3202
 *
 
3203
 ***********************************************************************/
 
3204
 
 
3205
/*ARGSUSED*/
 
3206
static void
 
3207
GetMnemonicCharset(Widget wid,
 
3208
int resource,                                     /* unused */
 
3209
XtArgVal *value)
 
3210
{
 
3211
    XmLabelGadget lw = (XmLabelGadget) wid;
 
3212
    char *cset;
 
3213
    int   size;
 
3214
 
 
3215
    cset = NULL;
 
3216
    if (LabG_MnemonicCharset (lw))
 
3217
    {
 
3218
        size = strlen (LabG_MnemonicCharset (lw));
 
3219
        if (size > 0)
 
3220
            cset = (char *) (_XmStringCharsetCreate(LabG_MnemonicCharset (lw)));
 
3221
    }
 
3222
 
 
3223
    *value = (XtArgVal) cset;
 
3224
}
 
3225
 
 
3226
 
 
3227
/************************************************************************
 
3228
 *
 
3229
 *  Caching Assignment help
 
3230
 *     These routines are for manager widgets that go into Label's
 
3231
 *     fields and set them, instead of doing a SetValues.
 
3232
 *
 
3233
 ************************************************************************/
 
3234
 
 
3235
static XmLabelGCacheObjPart local_cache;
 
3236
static Boolean local_cache_inited = FALSE;
 
3237
 
 
3238
/*
 
3239
 * QualifyLabelLocalCache
 
3240
 *  Checks to see if local cache is set up
 
3241
 */
 
3242
static void
 
3243
QualifyLabelLocalCache(XmLabelGadget w)
 
3244
{
 
3245
    if (!local_cache_inited)
 
3246
    {
 
3247
        local_cache_inited = TRUE;
 
3248
        ClassCacheCopy(LabG_ClassCachePart(w))
 
3249
            (LabG_Cache(w), &local_cache, sizeof(local_cache));
 
3250
    }
 
3251
}
 
3252
 
 
3253
 
 
3254
/************************************************************************
 
3255
 *
 
3256
 * _XmReCacheLabG()
 
3257
 * Check to see if ReCaching is necessary as a result of fields having
 
3258
 * been set by a mananger widget. This routine is called by the
 
3259
 * manager widget in their SetValues after a change is made to any
 
3260
 * of Label's cached fields.
 
3261
 *
 
3262
 ************************************************************************/
 
3263
 
 
3264
void
 
3265
_XmReCacheLabG(Widget wid)
 
3266
{
 
3267
    XmLabelGadget lw = (XmLabelGadget) wid;
 
3268
 
 
3269
    _XmProcessLock();
 
3270
    if (local_cache_inited &&
 
3271
        (!_XmLabelCacheCompare((XtPointer)&local_cache,
 
3272
        (XtPointer)LabG_Cache(lw))))
 
3273
    {
 
3274
        /* Delete the old one. */
 
3275
        _XmCacheDelete((XtPointer) LabG_Cache(lw));
 
3276
        LabG_Cache(lw) = (XmLabelGCacheObjPart *)
 
3277
            _XmCachePart(LabG_ClassCachePart(lw),
 
3278
            (XtPointer) &local_cache, sizeof(local_cache));
 
3279
    }
 
3280
    local_cache_inited = FALSE;
 
3281
    _XmProcessUnlock();
 
3282
}
 
3283
 
 
3284
 
 
3285
void
 
3286
_XmAssignLabG_MarginHeight(XmLabelGadget lw,
 
3287
#if NeedWidePrototypes
 
3288
int value)
 
3289
#else
 
3290
Dimension value)
 
3291
#endif                                            /* NeedWidePrototypes */
 
3292
{
 
3293
    _XmProcessLock();
 
3294
        QualifyLabelLocalCache(lw);
 
3295
        local_cache.margin_height = value;
 
3296
        _XmProcessUnlock();
 
3297
}
 
3298
 
 
3299
 
 
3300
void
 
3301
_XmAssignLabG_MarginWidth(XmLabelGadget lw,
 
3302
#if NeedWidePrototypes
 
3303
int value)
 
3304
#else
 
3305
Dimension value)
 
3306
#endif                                            /* NeedWidePrototypes */
 
3307
{
 
3308
    _XmProcessLock();
 
3309
        QualifyLabelLocalCache(lw);
 
3310
        local_cache.margin_width = value;
 
3311
        _XmProcessUnlock();
 
3312
}
 
3313
 
 
3314
 
 
3315
void
 
3316
_XmAssignLabG_MarginLeft(XmLabelGadget lw,
 
3317
#if NeedWidePrototypes
 
3318
int value)
 
3319
#else
 
3320
Dimension value)
 
3321
#endif                                            /* NeedWidePrototypes */
 
3322
{
 
3323
    _XmProcessLock();
 
3324
        QualifyLabelLocalCache(lw);
 
3325
        local_cache.margin_left = value;
 
3326
        _XmProcessUnlock();
 
3327
}
 
3328
 
 
3329
 
 
3330
void
 
3331
_XmAssignLabG_MarginRight(XmLabelGadget lw,
 
3332
#if NeedWidePrototypes
 
3333
int value)
 
3334
#else
 
3335
Dimension value)
 
3336
#endif                                            /* NeedWidePrototypes */
 
3337
{
 
3338
    _XmProcessLock();
 
3339
        QualifyLabelLocalCache(lw);
 
3340
        local_cache.margin_right = value;
 
3341
        _XmProcessUnlock();
 
3342
}
 
3343
 
 
3344
 
 
3345
void
 
3346
_XmAssignLabG_MarginTop(XmLabelGadget lw,
 
3347
#if NeedWidePrototypes
 
3348
int value)
 
3349
#else
 
3350
Dimension value)
 
3351
#endif                                            /* NeedWidePrototypes */
 
3352
{
 
3353
    _XmProcessLock();
 
3354
        QualifyLabelLocalCache(lw);
 
3355
        local_cache.margin_top = value;
 
3356
        _XmProcessUnlock();
 
3357
}
 
3358
 
 
3359
 
 
3360
void
 
3361
_XmAssignLabG_MarginBottom(XmLabelGadget lw,
 
3362
#if NeedWidePrototypes
 
3363
int value)
 
3364
#else
 
3365
Dimension value)
 
3366
#endif                                            /* NeedWidePrototypes */
 
3367
{
 
3368
    _XmProcessLock();
 
3369
        QualifyLabelLocalCache(lw);
 
3370
        local_cache.margin_bottom = value;
 
3371
        _XmProcessUnlock();
 
3372
}
 
3373
 
 
3374
 
 
3375
/************************************************************************
 
3376
 *
 
3377
 *  SetGadgetActivateCallbackState
 
3378
 *
 
3379
 * This function is used as the method of the menuSavvy trait. It is
 
3380
 * used by menu savvy parents to set whether or not the child will
 
3381
 * invoke its own activate callback or whether it will defer to the
 
3382
 * entryCallback of the parent.
 
3383
 *
 
3384
 ************************************************************************/
 
3385
 
 
3386
static void
 
3387
SetGadgetActivateCallbackState(Widget wid,
 
3388
XmActivateState state)
 
3389
{
 
3390
    XmLabelGCacheObjPart localCache;
 
3391
 
 
3392
        _XmQualifyLabelLocalCache(&localCache, (XmLabelGadget)wid);
 
3393
 
 
3394
        switch (state)
 
3395
    {
 
3396
        case XmDISABLE_ACTIVATE:
 
3397
            localCache.skipCallback = True;
 
3398
                break;
 
3399
 
 
3400
            case XmENABLE_ACTIVATE:
 
3401
            localCache.skipCallback = False;
 
3402
                break;
 
3403
    }
 
3404
 
 
3405
    _XmReCacheLabG_r(&localCache, (XmLabelGadget)wid);
 
3406
}
 
3407
 
 
3408
 
 
3409
/************************************************************************
 
3410
 *
 
3411
 *  SetOverrideCallback
 
3412
 *
 
3413
 * Used by subclasses.  If this is set true, then there is a RowColumn
 
3414
 * parent with the entryCallback resource set.  The subclasses do not
 
3415
 * do their activate callbacks, instead the RowColumn callbacks are called
 
3416
 * by RowColumn.
 
3417
 ************************************************************************/
 
3418
 
 
3419
/*ARGSUSED*/
 
3420
static void
 
3421
SetOverrideCallback(
 
3422
Widget w)
 
3423
{
 
3424
    XmLabelGCacheObjPart localCache;
 
3425
 
 
3426
        _XmQualifyLabelLocalCache(&localCache, (XmLabelGadget)w);
 
3427
        localCache.skipCallback= True;
 
3428
        _XmReCacheLabG_r(&localCache, (XmLabelGadget)w);
 
3429
}
 
3430
 
 
3431
 
 
3432
/************************************************************************
 
3433
 *
 
3434
 *  XmCreateLabelGadget()
 
3435
 *  XmVaCreateLabelGadget()
 
3436
 *  XmVaCreateManagedLabelGadget()
 
3437
 *
 
3438
 *      Externally accessable function for creating a label gadget.
 
3439
 *
 
3440
 ************************************************************************/
 
3441
 
 
3442
Widget
 
3443
XmCreateLabelGadget(Widget parent,
 
3444
char *name,
 
3445
Arg *arglist,
 
3446
Cardinal argCount)
 
3447
{
 
3448
    return XtCreateWidget(name, xmLabelGadgetClass, parent, arglist, argCount);
 
3449
}
 
3450
Widget 
 
3451
XmVaCreateLabelGadget(
 
3452
        Widget parent,
 
3453
        char *name,
 
3454
        ...)
 
3455
{
 
3456
    register Widget w;
 
3457
    va_list var;
 
3458
    int count;
 
3459
    
 
3460
    Va_start(var,name);
 
3461
    count = XmeCountVaListSimple(var);
 
3462
    va_end(var);
 
3463
 
 
3464
    
 
3465
    Va_start(var, name);
 
3466
    w = XmeVLCreateWidget(name, 
 
3467
                         xmLabelGadgetClass, 
 
3468
                         parent, False, 
 
3469
                         var, count);
 
3470
    va_end(var);   
 
3471
    return w;
 
3472
    
 
3473
}
 
3474
Widget 
 
3475
XmVaCreateManagedLabelGadget(
 
3476
        Widget parent,
 
3477
        char *name,
 
3478
        ...)
 
3479
{
 
3480
    Widget w = NULL;
 
3481
    va_list var;
 
3482
    int count;
 
3483
    
 
3484
    Va_start(var, name);
 
3485
    count = XmeCountVaListSimple(var);
 
3486
    va_end(var);
 
3487
    
 
3488
    Va_start(var, name);
 
3489
    w = XmeVLCreateWidget(name, 
 
3490
                         xmLabelGadgetClass, 
 
3491
                         parent, True, 
 
3492
                         var, count);
 
3493
    va_end(var);   
 
3494
    return w;
 
3495
    
 
3496
}
 
3497
 
 
3498
/*
 
3499
 *  GetLabelBGClassSecResData ()
 
3500
 *    Class function to be called to copy secondary resource for external
 
3501
 *  use.  i.e. copy the cached resources and send it back.
 
3502
 */
 
3503
 
 
3504
/*ARGSUSED*/
 
3505
static Cardinal
 
3506
GetLabelBGClassSecResData(WidgetClass w_class,
 
3507
XmSecondaryResourceData **data_rtn)
 
3508
{
 
3509
    int        arrayCount;
 
3510
        XmBaseClassExt bcePtr;
 
3511
        String     resource_class, resource_name;
 
3512
        XtPointer  client_data;
 
3513
 
 
3514
        _XmProcessLock();
 
3515
        bcePtr = &(labelBaseClassExtRec);
 
3516
        client_data = NULL;
 
3517
        resource_class = NULL;
 
3518
        resource_name = NULL;
 
3519
        arrayCount =
 
3520
        _XmSecondaryResourceData(bcePtr, data_rtn, client_data,
 
3521
        resource_name, resource_class,
 
3522
        GetLabelClassResBase);
 
3523
        _XmProcessUnlock();
 
3524
        return arrayCount;
 
3525
}
 
3526
 
 
3527
 
 
3528
/*
 
3529
 * GetLabelClassResBase ()
 
3530
 *   retrun the address of the base of resources.
 
3531
 *   - Not yet implemented.
 
3532
 */
 
3533
 
 
3534
/*ARGSUSED*/
 
3535
static XtPointer
 
3536
GetLabelClassResBase(Widget widget,
 
3537
XtPointer client_data)                            /* unused */
 
3538
{
 
3539
    XtPointer widgetSecdataPtr;
 
3540
        int       labg_cache_size = sizeof(XmLabelGCacheObjPart);
 
3541
        char     *cp;
 
3542
 
 
3543
        widgetSecdataPtr = (XtPointer) (XtMalloc (labg_cache_size +1));
 
3544
 
 
3545
        _XmProcessLock();
 
3546
        if (widgetSecdataPtr)
 
3547
    {
 
3548
        cp = (char *) widgetSecdataPtr;
 
3549
            memcpy(cp, LabG_Cache(widget), labg_cache_size);
 
3550
    }
 
3551
 
 
3552
    _XmProcessUnlock();
 
3553
        return widgetSecdataPtr;
 
3554
}
 
3555
 
 
3556
 
 
3557
/*ARGSUSED*/
 
3558
static void
 
3559
SetValuesAlmost(Widget cw,                        /* unused */
 
3560
Widget nw,
 
3561
XtWidgetGeometry *request,
 
3562
XtWidgetGeometry *reply)
 
3563
{
 
3564
    XmLabelGadget new_w = (XmLabelGadget) nw;
 
3565
        XtWidgetProc resize;
 
3566
 
 
3567
        _XmProcessLock();
 
3568
        resize = ((XmLabelGadgetClassRec *)(new_w->object.widget_class))->
 
3569
        rect_class.resize;
 
3570
        _XmProcessUnlock();
 
3571
 
 
3572
        (* (resize)) ((Widget) new_w);
 
3573
        *request = *reply;
 
3574
}
 
3575
 
 
3576
 
 
3577
static void
 
3578
GetColors(Widget w,
 
3579
XmAccessColorData color_data)
 
3580
{
 
3581
    if (LabG_Cache(w))
 
3582
    {
 
3583
        color_data->valueMask = AccessForeground | AccessBackgroundPixel |
 
3584
            AccessHighlightColor | AccessTopShadowColor | AccessBottomShadowColor;
 
3585
            color_data->background = LabG_Background(w);
 
3586
            color_data->foreground = LabG_Foreground(w);
 
3587
            color_data->highlight_color = LabG_HighlightColor(w);
 
3588
            color_data->top_shadow_color = LabG_TopShadowColor(w);
 
3589
            color_data->bottom_shadow_color = LabG_BottomShadowColor(w);
 
3590
    }
 
3591
    else
 
3592
    {
 
3593
        color_data->valueMask = AccessColorInvalid;
 
3594
    }
 
3595
}
 
3596
 
 
3597
 
 
3598
/************************************************************************
 
3599
 *
 
3600
 * XmLabelGadgetGetBaselines
 
3601
 *
 
3602
 * A Class function which when called returns True, if the widget has
 
3603
 * a baseline and also determines the number of pixels from the y
 
3604
 * origin to the first line of text and assigns it to the variable
 
3605
 * being passed in.
 
3606
 *
 
3607
 ************************************************************************/
 
3608
 
 
3609
static Boolean
 
3610
XmLabelGadgetGetBaselines(Widget wid,
 
3611
Dimension **baselines,
 
3612
int *line_count)
 
3613
{
 
3614
    XmLabelGadget lw = (XmLabelGadget)wid;
 
3615
        Cardinal count;
 
3616
        int delta;
 
3617
 
 
3618
        if (LabG_IsPixmap(wid))
 
3619
        return False;
 
3620
 
 
3621
    /* Compute raw baselines if unavailable. */
 
3622
        if (lw->label.baselines == NULL)
 
3623
    {
 
3624
        _XmStringGetBaselines(LabG_Font(lw), LabG__label(lw),
 
3625
            &(lw->label.baselines), &count);
 
3626
            assert(lw->label.baselines != NULL);
 
3627
 
 
3628
        /* Store the current offset in an extra location. */
 
3629
            lw->label.baselines = (Dimension*)
 
3630
            XtRealloc((char*) lw->label.baselines, (count+1) * sizeof(Dimension));
 
3631
            lw->label.baselines[count] = 0;
 
3632
    }
 
3633
    else
 
3634
    {
 
3635
        count = XmStringLineCount(LabG__label(lw));
 
3636
    }
 
3637
 
 
3638
    /* Readjust offsets if necessary. */
 
3639
    delta = LabG_TextRect_y(lw) - lw->label.baselines[count];
 
3640
        if (delta)
 
3641
    {
 
3642
        int tmp;
 
3643
            for (tmp = 0; tmp <= count; tmp++)
 
3644
            lw->label.baselines[tmp] += delta;
 
3645
    }
 
3646
 
 
3647
    /* Copy the cached data. */
 
3648
    *line_count = count;
 
3649
        *baselines = (Dimension*) XtMalloc(*line_count * sizeof(Dimension));
 
3650
        memcpy((char*) *baselines, (char*) lw->label.baselines,
 
3651
        *line_count * sizeof(Dimension));
 
3652
 
 
3653
        return True;
 
3654
}
 
3655
 
 
3656
 
 
3657
/************************************************************************
 
3658
 *
 
3659
 * XmLabelGadgetGetDisplayRect
 
3660
 *
 
3661
 * A Class function which returns true if the widget being passed in
 
3662
 * has a display rectangle associated with it. It also determines the
 
3663
 * x,y coordinates of the character cell or pixmap relative to the origin
 
3664
 * and the width and height in pixels of the smallest rectangle that encloses
 
3665
 * the text or pixmap. This is assigned to the variable being passed in
 
3666
 *
 
3667
 ***********************************************************************/
 
3668
 
 
3669
static Boolean
 
3670
XmLabelGadgetGetDisplayRect(Widget w,
 
3671
XRectangle *displayrect)
 
3672
{
 
3673
    XmLabelGadget wid = (XmLabelGadget) w;
 
3674
 
 
3675
        displayrect->x = wid->label.TextRect.x;
 
3676
        displayrect->y = wid->label.TextRect.y;
 
3677
        displayrect->width = wid->label.TextRect.width;
 
3678
        displayrect->height = wid->label.TextRect.height;
 
3679
 
 
3680
        return TRUE;
 
3681
}
 
3682
 
 
3683
 
 
3684
/************************************************************************
 
3685
 *
 
3686
 * XmLabelGadgetMarginsProc
 
3687
 *
 
3688
 ***********************************************************************/
 
3689
 
 
3690
/* ARGSUSED */
 
3691
static void
 
3692
XmLabelGadgetMarginsProc(Widget w,
 
3693
XmBaselineMargins *margins_rec)
 
3694
{
 
3695
    XmLabelGCacheObjPart localCache;
 
3696
 
 
3697
        if (margins_rec->get_or_set == XmBASELINE_SET)
 
3698
    {
 
3699
        _XmQualifyLabelLocalCache(&localCache, (XmLabelGadget)w);
 
3700
            _XmAssignLabG_MarginTop_r((&localCache), margins_rec->margin_top);
 
3701
            _XmAssignLabG_MarginBottom_r((&localCache), margins_rec->margin_bottom);
 
3702
            _XmReCacheLabG_r(&localCache, (XmLabelGadget)w);
 
3703
    }
 
3704
    else
 
3705
    {
 
3706
        margins_rec->margin_top = LabG_MarginTop(w);
 
3707
            margins_rec->margin_bottom = LabG_MarginBottom(w);
 
3708
            margins_rec->shadow = LabG_Shadow(w);
 
3709
            margins_rec->highlight = LabG_Highlight(w);
 
3710
            margins_rec->text_height = LabG_TextRect_height(w);
 
3711
            margins_rec->margin_height = LabG_MarginHeight(w);
 
3712
    }
 
3713
}
 
3714
 
 
3715
 
 
3716
static Widget
 
3717
GetPixmapDragIcon(Widget w)
 
3718
{
 
3719
    XmLabelGadget lw = (XmLabelGadget) w;
 
3720
        Arg args[10];
 
3721
        int n = 0;
 
3722
        Widget drag_icon;
 
3723
        Widget screen_object = XmGetXmScreen(XtScreen(w));
 
3724
        unsigned int wid, hei;
 
3725
        int d;
 
3726
 
 
3727
    /* it's a labelPixmap, use directly the pixmap */
 
3728
 
 
3729
        XmeGetPixmapData(XtScreen(lw), Pix(lw), NULL, &d,
 
3730
        NULL, NULL, NULL, NULL, &wid, &hei);
 
3731
 
 
3732
        n = 0;
 
3733
        XtSetArg(args[n], XmNhotX, 0),             n++;
 
3734
        XtSetArg(args[n], XmNhotY, 0),             n++;
 
3735
        XtSetArg(args[n], XmNwidth, wid),          n++;
 
3736
        XtSetArg(args[n], XmNheight, hei),             n++;
 
3737
        XtSetArg(args[n], XmNmaxWidth, wid),           n++;
 
3738
        XtSetArg(args[n], XmNmaxHeight, hei),          n++;
 
3739
        XtSetArg(args[n], XmNdepth, d),            n++;
 
3740
        XtSetArg(args[n], XmNpixmap, Pix(lw)),         n++;
 
3741
        XtSetArg(args[n], XmNforeground, LabG_Background(lw)), n++;
 
3742
        XtSetArg(args[n], XmNbackground, LabG_Foreground(lw)), n++;
 
3743
        assert(n <= XtNumber(args));
 
3744
        drag_icon = XtCreateWidget("drag_icon", xmDragIconObjectClass,
 
3745
        screen_object, args, n);
 
3746
        return drag_icon;
 
3747
}
 
3748
 
 
3749
 
 
3750
/*ARGSUSED*/
 
3751
void
 
3752
_XmProcessDrag(Widget w,
 
3753
XEvent *event,
 
3754
String *params,
 
3755
Cardinal *num_params)
 
3756
{
 
3757
    XmLabelGadget lw = (XmLabelGadget) w;
 
3758
        Widget drag_icon;
 
3759
        Arg args[10];
 
3760
        int n;
 
3761
        XmManagerWidget mw;
 
3762
        Time _time = _XmGetDefaultTime(w, event);
 
3763
        XmDisplay dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(w));
 
3764
 
 
3765
        mw = (XmManagerWidget) XtParent(lw);
 
3766
 
 
3767
        if (LabG_IsMenupane(w))
 
3768
        XAllowEvents(XtDisplay(mw), SyncPointer, _time);
 
3769
 
 
3770
    /* Disallow drag if this is a cascade button and armed - Hack alert */
 
3771
        if (XmIsCascadeButtonGadget(w) && CBG_IsArmed(w)) return;
 
3772
 
 
3773
    /* CDE - allow user to not drag labels and label subclasses
 
3774
       also,  disable drag if enable_btn1_transfer is set to
 
3775
       BUTTON2_ADJUST and the trigger was button2 */
 
3776
        if (! dpy -> display.enable_unselectable_drag ||
 
3777
        (dpy -> display.enable_btn1_transfer == XmBUTTON2_ADJUST &&
 
3778
        event && event -> xany.type == ButtonPress &&
 
3779
        event -> xbutton.button == 2)) return;
 
3780
 
 
3781
        n = 0;
 
3782
        XtSetArg(args[n], XmNcursorBackground, LabG_Background(lw)), n++;
 
3783
        XtSetArg(args[n], XmNcursorForeground, LabG_Foreground(lw)), n++;
 
3784
 
 
3785
    /* If it's a labelPixmap, only specify the pixmap icon */
 
3786
        if (LabG_IsPixmap(lw) && (Pix(lw) != XmUNSPECIFIED_PIXMAP))
 
3787
    {
 
3788
        drag_icon = GetPixmapDragIcon(w);
 
3789
            XtSetArg(args[n], XmNsourcePixmapIcon, drag_icon), n++;
 
3790
    }
 
3791
    else
 
3792
    {
 
3793
        drag_icon = XmeGetTextualDragIcon(w);
 
3794
            XtSetArg(args[n], XmNsourceCursorIcon, drag_icon), n++;
 
3795
    }
 
3796
 
 
3797
    XtSetArg(args[n], XmNdragOperations, XmDROP_COPY), n++;
 
3798
        (void) XmeDragSource(w, NULL, event, args, n);
 
3799
}
 
3800
 
 
3801
 
 
3802
/*
 
3803
 * XmRCallProc routine for checking label.font before setting it to NULL
 
3804
 * If "check_set_render_table" is True, then function has
 
3805
 * been called twice on same widget, thus resource needs to be set NULL,
 
3806
 * otherwise leave it alone.
 
3807
 */
 
3808
 
 
3809
/*ARGSUSED*/
 
3810
static void
 
3811
CheckSetRenderTable(Widget wid,
 
3812
int offset,
 
3813
XrmValue *value)
 
3814
{
 
3815
    XmLabelGadget lw = (XmLabelGadget)wid;
 
3816
 
 
3817
    /* Check if been here before */
 
3818
        if (lw->label.check_set_render_table)
 
3819
        value->addr = NULL;
 
3820
        else
 
3821
    {
 
3822
        lw->label.check_set_render_table = True;
 
3823
            value->addr = (char*)&(lw->label.font);
 
3824
    }
 
3825
}
 
3826
 
 
3827
/**************************************************************************
 
3828
 * FromPaddingPixels
 
3829
 *
 
3830
 * Converts from pixels to current unit type does either horiz or vert
 
3831
 * depending on icon placement.
 
3832
 *  widget - the icon button widget.
 
3833
 *  offset, value - passed to correct function based on orientation.
 
3834
 **************************************************************************/
 
3835
  
 
3836
static void
 
3837
FromPaddingPixels(Widget widget, int offset, XtArgVal *value)
 
3838
{
 
3839
    switch(LabG_PixmapPlacement(widget)) {
 
3840
    case XmPIXMAP_TOP:
 
3841
    case XmPIXMAP_BOTTOM:
 
3842
        XmeFromVerticalPixels(widget, offset, value);
 
3843
        break;
 
3844
    default:                    /* everything else is horiz. */
 
3845
        XmeFromHorizontalPixels(widget, offset, value);
 
3846
        break;
 
3847
    }
 
3848
}
 
3849
    
 
3850
/**************************************************************************
 
3851
 * ToPaddingPixels
 
3852
 *
 
3853
 * Converts from pixels to current unit type does either horiz or vert
 
3854
 * depending on icon placement.
 
3855
 *  widget - the icon button widget.
 
3856
 *  offset, value - passed to correct function based on orientation.
 
3857
 * Returns the import order from _XmTo{Horizontal, Vertical}Pixels.
 
3858
 **************************************************************************/
 
3859
 
 
3860
static XmImportOperator
 
3861
ToPaddingPixels(Widget widget, int offset, XtArgVal *value)
 
3862
{
 
3863
    switch(LabG_PixmapPlacement(widget)) {
 
3864
    case XmPIXMAP_TOP:
 
3865
    case XmPIXMAP_BOTTOM:
 
3866
        return(XmeToVerticalPixels(widget, offset, value));
 
3867
    default:
 
3868
        return(XmeToHorizontalPixels(widget, offset, value));
 
3869
    }
 
3870
}
 
3871
    
 
3872
 
 
3873
static char*
 
3874
GetLabelGadgetAccelerator(Widget w)
 
3875
{
 
3876
    if (XtClass(w) == xmLabelGadgetClass)
 
3877
        return NULL;
 
3878
        else
 
3879
        return LabG_Accelerator(w);
 
3880
}
 
3881
 
 
3882
 
 
3883
static KeySym
 
3884
GetLabelGadgetMnemonic(Widget w)
 
3885
{
 
3886
    if (XtClass(w) == xmLabelGadgetClass)
 
3887
        return XK_VoidSymbol;
 
3888
        else
 
3889
        return LabG_Mnemonic(w);
 
3890
}
 
3891
 
 
3892
 
 
3893
void
 
3894
_XmQualifyLabelLocalCache(
 
3895
XmLabelGCacheObjPart *local_cache,
 
3896
XmLabelGadget w)
 
3897
{
 
3898
    _XmProcessLock();
 
3899
        ClassCacheCopy(LabG_ClassCachePart(w))
 
3900
        (LabG_Cache(w),
 
3901
        local_cache,
 
3902
        sizeof(XmLabelGCacheObjPart)
 
3903
        );
 
3904
        _XmProcessUnlock();
 
3905
}
 
3906
 
 
3907
 
 
3908
void
 
3909
_XmReCacheLabG_r(XmLabelGCacheObjPart *local_cache, XmLabelGadget w)
 
3910
{
 
3911
    _XmProcessLock();
 
3912
        if (!_XmLabelCacheCompare(local_cache, (XtPointer)LabG_Cache(w)))
 
3913
    {
 
3914
        _XmCacheDelete((XtPointer)LabG_Cache(w));
 
3915
            LabG_Cache(w) = (XmLabelGCacheObjPart *)_XmCachePart(
 
3916
            LabG_ClassCachePart(w),
 
3917
            local_cache,
 
3918
            sizeof(XmLabelGCacheObjPart));
 
3919
    }
 
3920
    _XmProcessUnlock();
 
3921
}