2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Icon.c /main/20 1999/09/08 10:44:52 mgreess $
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1990,1996 Hewlett-Packard Company.
27 * (c) Copyright 1996 International Business Machines Corp.
28 * (c) Copyright 1996 Sun Microsystems, Inc.
29 * (c) Copyright 1996 Novell, Inc.
30 * (c) Copyright 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
34 /**---------------------------------------------------------------------
38 *** project: MotifPlus Widgets
40 *** description: Source code for DtIconGadget class.
42 ***-------------------------------------------------------------------*/
45 /*-------------------------------------------------------------
51 #include <sys/types.h>
54 #include <X11/Xatom.h>
56 #include <Xm/CacheP.h>
57 #include <Xm/ManagerP.h>
58 #include <Xm/PrimitiveP.h>
61 #include <Dt/MacrosP.h>
62 #include <Dt/DtMsgsP.h>
64 #include "DtWidgetI.h"
65 #include "DtSvcInternal.h"
67 #include <Xm/XmPrivate.h> /* Motif _XmEnterGadget and friends */
69 /*-------------------------------------------------------------
71 **-------------------------------------------------------------
74 WidgetClass dtIconGadgetClass;
76 #define Min(x, y) (((x) < (y)) ? (x) : (y))
77 #define Max(x, y) (((x) > (y)) ? (x) : (y))
78 #define Limit(x, lim) (((lim) == 0 || (x) <= (lim))? (x): (lim))
80 /*-------------------------------------------------------------
81 ** Forward Declarations
84 extern void _DtRegisterNewConverters ( void );
85 extern char * _XmExtObjAlloc(int size);
86 extern void _XmExtObjFree(XtPointer element);
87 extern void _XmSelectColorDefault ( Widget, int, XrmValue * );
89 extern void _XmExtImportArgs( Widget w, ArgList args, Cardinal *num_args);
91 extern void _XmEnterGadget( Widget wid, XEvent *event, String*,Cardinal*);
93 #define SPACING_DEFAULT 2
94 #define MARGIN_DEFAULT 2
95 #define UNSPECIFIED_DIMENSION 9999
96 #define UNSPECIFIED_CHAR 255
98 #define WARN_ALIGNMENT _DtMsgIcon_0000
99 #define WARN_BEHAVIOR _DtMsgIcon_0001
100 #define WARN_FILL_MODE _DtMsgIcon_0002
101 #define WARN_PIXMAP_POSITION _DtMsgIcon_0003
102 #define WARN_MARGIN _DtMsgIcon_0004
103 #define WARN_SHADOW_TYPE _DtMsgIcon_0005
106 #define MgrParent(g) ((XmManagerWidget) (XmIsManager(XtParent(g)) ? (XtParent(g)) : (XtParent(XtParent(g)))))
108 /******** Private Function Declarations ********/
110 extern void _DtIconRegisterDropsite(
113 /******** End Private Function Declarations ********/
116 /******** Static Function Declarations ********/
118 static int IconCacheCompare(
122 static void ReCacheIcon_r(
123 DtIconCacheObjPart *cache,
126 static void GetDefaultBackground(
130 static void GetDefaultForeground(
134 static void GetDefaultFillMode(
138 static void GetSpacing(
142 static void GetString(
146 static void IconEventHandler(
148 XtPointer client_data,
149 XButtonEvent *event) ;
150 static void ClickTimeout(
156 static void IconDisarm(
159 static void IconActivate(
162 static void IconDrag(
165 static void IconPopup(
168 static void IconEnter(
171 static void IconLeave(
174 static void ClassInitialize( void ) ;
175 static void SecondaryObjectCreate(
179 Cardinal *num_args) ;
180 static void InitializePosthook(
184 Cardinal *num_args) ;
185 static Boolean SetValuesPrehook(
190 Cardinal *num_args) ;
191 static void GetValuesPrehook(
194 Cardinal *num_args) ;
195 static void GetValuesPosthook(
198 Cardinal *num_args) ;
199 static Boolean SetValuesPosthook(
204 Cardinal *num_args) ;
205 static void QualifyIconLocalCache(
207 DtIconCacheObjPart *cache);
208 static void Initialize(
215 static void Redisplay(
219 static Boolean SetValues(
223 static void BorderHighlight(
225 static void BorderUnhighlight(
227 static void ArmAndActivate(
230 static void InputDispatch(
234 static Boolean VisualChange(
242 static void GetPositions(
261 unsigned char s_type,
262 unsigned char fill_mode) ;
263 static void CallCallback(
268 static void UpdateGCs(
270 static Cardinal GetIconClassSecResData(
272 XmSecondaryResourceData **data_rtn) ;
273 static XtPointer GetIconClassResBase(
275 XtPointer client_data) ;
276 static Boolean LoadPixmap(
279 static void ClassPartInitialize ( WidgetClass wc);
280 static void HighlightBorder( Widget w );
281 static void UnhighlightBorder( Widget w );
283 /******** End Static Function Declarations ********/
285 /* External Cache Procs
287 extern void _XmCacheDelete( XtPointer data );
288 extern void _XmCacheCopy( XtPointer src, XtPointer dest, size_t size );
289 extern Cardinal _XmSecondaryResourceData( XmBaseClassExt, XmSecondaryResourceData **,
290 XtPointer, String, String, XmResourceBaseProc);
291 extern XtPointer _XmCachePart( XmCacheClassPartPtr cp, XtPointer cpart, size_t size );
294 /*-------------------------------------------------------------
297 #define I_Offset(field) \
298 XtOffset (DtIconGadget, icon.field)
300 #define I_Cache_Offset(field) \
301 XtOffset (DtIconCacheObject, icon_cache.field)
303 static XtResource resources[] =
307 XmCSet, XmRBoolean, sizeof (Boolean),
308 I_Offset (set), XmRImmediate, (XtPointer) False
312 XmCShadowType, XmRShadowType, sizeof (unsigned char),
313 I_Offset (shadow_type),
314 XmRImmediate, (XtPointer) XmSHADOW_ETCHED_OUT
318 XmCBorderType, XmRBorderType, sizeof (unsigned char),
319 I_Offset (border_type),
320 XmRImmediate, (XtPointer) DtRECTANGLE
324 XmCCallback, XmRCallback, sizeof (XtCallbackList),
325 I_Offset (callback), XmRImmediate, (XtPointer) NULL
329 XmCFontList, XmRFontList, sizeof (XmFontList),
330 I_Offset (font_list), XmRString, "Fixed"
334 XmCString, XmRString, sizeof (XmString),
335 I_Offset (image_name), XmRImmediate, (XtPointer) NULL
339 XmCPixmap, XmRPixmap, sizeof (Pixmap),
341 XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
345 XmCXmString, XmRXmString, sizeof (XmString),
347 XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
351 XmCForeground, XmRPixel, sizeof (Pixel),
352 I_Offset (pixmap_foreground),
353 XmRCallProc, (XtPointer) GetDefaultForeground
357 XmCBackground, XmRPixel, sizeof (Pixel),
358 I_Offset (pixmap_background),
359 XmRCallProc, (XtPointer) GetDefaultBackground
363 XmCMaxWidth, XmRHorizontalDimension, sizeof (Dimension),
364 I_Offset (max_pixmap_width), XmRImmediate, (XtPointer) 0
368 XmCMaxHeight, XmRVerticalDimension, sizeof (Dimension),
369 I_Offset (max_pixmap_height), XmRImmediate, (XtPointer) 0
373 XmCUnderline, XmRBoolean, sizeof (Boolean),
374 I_Offset (underline), XmRImmediate, (XtPointer) False
377 XmNdropSiteOperations, XmCDropSiteOperations,
378 XmRDropSiteOperations, sizeof(unsigned char),
379 I_Offset(operations), XmRImmediate, (XtPointer) XmDROP_NOOP
383 XmCDropCallback, XmRCallback, sizeof (XtCallbackList),
384 I_Offset (drop_callback), XmRImmediate, (XtPointer) NULL
389 static XtResource cache_resources[] =
393 XmCBehavior, XmRBehavior, sizeof (unsigned char),
394 I_Cache_Offset (behavior),
395 XmRImmediate, (XtPointer) XmICON_BUTTON
399 XmCRecomputeSize, XmRBoolean, sizeof (Boolean),
400 I_Cache_Offset (recompute_size), XmRImmediate, (XtPointer) True
404 "DrawShadow", XmRBoolean, sizeof (Boolean),
405 I_Cache_Offset (draw_shadow), XmRImmediate, (XtPointer) False
409 XmCFillOnArm, XmRBoolean, sizeof (Boolean),
410 I_Cache_Offset (fill_on_arm), XmRImmediate, (XtPointer) True
414 XmCForeground, XmRPixel, sizeof (Pixel),
415 I_Cache_Offset (foreground),
416 XmRCallProc, (XtPointer) GetDefaultForeground
420 XmCBackground, XmRPixel, sizeof (Pixel),
421 I_Cache_Offset (background),
422 XmRCallProc, (XtPointer) GetDefaultBackground
426 XmCArmColor, XmRPixel, sizeof (Pixel),
427 I_Cache_Offset (arm_color),
428 XmRCallProc, (XtPointer) _XmSelectColorDefault
432 XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
433 I_Cache_Offset (spacing),
434 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
438 XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
439 I_Cache_Offset (margin_height),
440 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
444 XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
445 I_Cache_Offset (margin_width),
446 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
450 XmCPixmapPosition, XmRPixmapPosition, sizeof (unsigned char),
451 I_Cache_Offset (pixmap_position),
452 XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
456 XmCStringPosition, XmRStringPosition, sizeof (unsigned char),
457 I_Cache_Offset (string_position),
458 XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
462 XmCAlignment, XmRAlignment, sizeof (unsigned char),
463 I_Cache_Offset (alignment),
464 XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
468 XmCFillMode, XmRFillMode, sizeof (unsigned char),
469 I_Cache_Offset (fill_mode),
470 XmRCallProc, (XtPointer) GetDefaultFillMode
475 static XmSyntheticResource syn_resources[] =
478 XmNstring, sizeof (XmString),
479 I_Offset (string), GetString,
485 static XmSyntheticResource cache_syn_resources[] =
488 XmNspacing, sizeof (Dimension),
489 I_Cache_Offset (spacing), GetSpacing,
493 XmNmarginWidth, sizeof (Dimension),
494 I_Cache_Offset (margin_width),
495 XmeFromHorizontalPixels,
496 (XmImportProc)XmeToHorizontalPixels
499 XmNmarginHeight, sizeof (Dimension),
500 I_Cache_Offset (margin_height),
501 XmeFromVerticalPixels,
502 (XmImportProc)XmeToVerticalPixels,
507 #undef I_Cache_Offset
510 /*-------------------------------------------------------------
511 ** Cache Class Record
514 static XmCacheClassPart IconClassCachePart = {
515 {NULL, 0, 0}, /* head of class cache list */
516 _XmCacheCopy, /* Copy routine */
517 _XmCacheDelete, /* Delete routine */
518 IconCacheCompare, /* Comparison routine */
521 /*-------------------------------------------------------------
522 ** Base Class Extension Record
524 static XmBaseClassExtRec iconBaseClassExtRec = {
525 NULL, /* Next extension */
526 NULLQUARK, /* record type XmQmotif */
527 XmBaseClassExtVersion, /* version */
528 sizeof(XmBaseClassExtRec), /* size */
529 XmInheritInitializePrehook, /* initialize prehook */
530 SetValuesPrehook, /* set_values prehook */
531 InitializePosthook, /* initialize posthook */
532 SetValuesPosthook, /* set_values posthook */
533 (WidgetClass)&dtIconCacheObjClassRec, /* secondary class */
534 (XtInitProc)SecondaryObjectCreate, /* creation proc */
535 (XmGetSecResDataFunc) GetIconClassSecResData, /* getSecResData */
536 {0}, /* fast subclass */
537 GetValuesPrehook, /* get_values prehook */
538 GetValuesPosthook, /* get_values posthook */
539 NULL, /* classPartInitPrehook */
540 NULL, /* classPartInitPosthook*/
541 NULL, /* ext_resources */
542 NULL, /* compiled_ext_resources*/
543 0, /* num_ext_resources */
544 FALSE, /* use_sub_resources */
545 XmInheritWidgetNavigable, /* widgetNavigable */
546 XmInheritFocusChange, /* focusChange */
549 /*-------------------------------------------------------------
550 ** Icon Cache Object Class Record
552 externaldef (dticoncacheobjclassrec)
553 DtIconCacheObjClassRec dtIconCacheObjClassRec =
556 /* superclass */ (WidgetClass) &xmExtClassRec,
557 /* class_name */ "DtIcon",
558 /* widget_size */ sizeof(DtIconCacheObjRec),
559 /* class_initialize */ NULL,
560 /* chained class init */ NULL,
561 /* class_inited */ False,
562 /* initialize */ NULL,
563 /* initialize hook */ NULL,
567 /* resources */ cache_resources,
568 /* num_resources */ XtNumber(cache_resources),
569 /* xrm_class */ NULLQUARK,
570 /* compress_motion */ False,
571 /* compress_exposure */ False,
572 /* compress enter/exit*/ False,
573 /* visible_interest */ False,
577 /* set_values */ NULL,
578 /* set values hook */ NULL,
579 /* set values almost */ NULL,
580 /* get values hook */ NULL,
581 /* accept_focus */ NULL,
582 /* version */ XtVersion,
583 /* callback offsetlst */ NULL,
584 /* default trans */ NULL,
585 /* query geo proc */ NULL,
586 /* display accelerator*/ NULL,
587 /* extension record */ NULL,
591 /* synthetic resources */ cache_syn_resources,
592 /* num_syn_resources */ XtNumber(cache_syn_resources),
593 /* extension */ NULL,
597 /*-------------------------------------------------------------
600 externaldef (dticonclassrec)
601 DtIconClassRec dtIconClassRec =
606 (WidgetClass) &xmGadgetClassRec, /* superclass */
607 "DtIcon", /* class_name */
608 sizeof (DtIconRec), /* widget_size */
609 ClassInitialize, /* class_initialize */
610 ClassPartInitialize, /* class_part_initialize*/
611 False, /* class_inited */
612 (XtInitProc) Initialize, /* initialize */
613 NULL, /* initialize_hook */
617 resources, /* resources */
618 XtNumber (resources), /* num_resources */
619 NULLQUARK, /* xrm_class */
620 True, /* compress_motion */
621 True, /* compress_exposure */
622 True, /* compress_enterleave */
623 False, /* visible_interest */
624 (XtWidgetProc) Destroy, /* destroy */
625 (XtWidgetProc) Resize, /* resize */
626 (XtExposeProc) Redisplay, /* expose */
627 (XtSetValuesFunc) SetValues, /* set_values */
628 NULL, /* set_values_hook */
629 XtInheritSetValuesAlmost, /* set_values_almost */
630 NULL, /* get_values_hook */
631 NULL, /* accept_focus */
632 XtVersion, /* version */
633 NULL, /* callback private */
635 NULL, /* query_geometry */
636 NULL, /* display_accelerator */
637 (XtPointer)&iconBaseClassExtRec,/* extension */
643 (XtWidgetProc) BorderHighlight, /* border_highlight */
644 (XtWidgetProc) BorderUnhighlight, /* border_unhighlight */
645 (XtActionProc) ArmAndActivate, /* arm_and_activate */
646 (XmWidgetDispatchProc) InputDispatch, /* input_dispatch */
647 (XmVisualChangeProc) VisualChange, /* visual_change */
648 syn_resources, /* get_resources */
649 XtNumber (syn_resources), /* num_get_resources */
650 &IconClassCachePart, /* class_cache_part */
651 NULL, /* extension */
657 GetSize, /* get_size */
658 GetPositions, /* get_positions */
660 CallCallback, /* call_callback */
661 UpdateGCs, /* update_gcs */
662 True, /* optimize_redraw */
663 NULL, /* class_cache_part */
664 NULL, /* extension */
669 externaldef (dticongadgetclass) WidgetClass dtIconGadgetClass = (WidgetClass) &dtIconClassRec;
672 /*-------------------------------------------------------------
674 **-------------------------------------------------------------
677 /************************************************************************
679 * The border highlighting and unhighlighting routines.
681 * These routines were originally in Obsolete.c but can not depend
682 * on these routines to live forever. Therefore, copied into my
685 ************************************************************************/
691 XtWidgetProc border_highlight;
693 if (XmIsPrimitive(w)) {
695 border_highlight = xmPrimitiveClassRec.primitive_class.border_highlight;
697 (*border_highlight) (w);
698 } else if (XmIsGadget(w)) {
700 border_highlight = xmGadgetClassRec.gadget_class.border_highlight;
702 (*border_highlight) (w);
710 XtWidgetProc border_unhighlight;
712 if (XmIsPrimitive(w)) {
714 border_unhighlight = xmPrimitiveClassRec.primitive_class.border_unhighlight;
716 (*border_unhighlight) (w);
717 } else if (XmIsGadget(w)) {
719 border_unhighlight = xmGadgetClassRec.gadget_class.border_unhighlight;
721 (*border_unhighlight) (w);
727 /*-------------------------------------------------------------
729 ** Get normal and background graphics contexts.
737 if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
739 XSetClipOrigin(XtDisplay(g),
745 return G_NormalGC(g);
749 /*-------------------------------------------------------------
750 ** GetDefaultBackground
751 ** Copy background pixel from Manager parent.
755 GetDefaultBackground(
761 XmManagerWidget parent = (XmManagerWidget) XtParent (g);
763 value->addr = (XtPointer) &pixel;
764 value->size = sizeof (Pixel);
766 if (XmIsManager ((Widget) parent))
767 pixel = M_Background (parent);
769 XmeGetDefaultPixel (g, XmBACKGROUND, offset, value);
773 /*-------------------------------------------------------------
774 ** GetDefaultForeground
775 ** Copy foreground pixel from Manager parent.
778 GetDefaultForeground(
784 XmManagerWidget parent = (XmManagerWidget) XtParent (g);
786 value->addr = (XtPointer) &pixel;
787 value->size = sizeof (Pixel);
789 if (XmIsManager ((Widget) parent))
790 pixel = M_Foreground (parent);
792 XmeGetDefaultPixel (g, XmFOREGROUND, offset, value);
797 /*-------------------------------------------------------------
798 ** GetDefaultFillMode
799 ** Get default fill mode.
808 static unsigned char fill_mode;
809 DtIconGadget g = (DtIconGadget) w;
811 value->addr = (XtPointer) &fill_mode;
812 value->size = sizeof (unsigned char);
814 if (G_ShadowThickness (g) == 0)
815 fill_mode = XmFILL_PARENT;
817 fill_mode = XmFILL_SELF;
821 /*-------------------------------------------------------------
823 ** Convert from pixels to horizontal or vertical units.
831 DtIconCacheObject icon_co = (DtIconCacheObject) w;
833 if (G_CachePixmapPosition (icon_co) == XmPIXMAP_TOP ||
834 G_CachePixmapPosition (icon_co) == XmPIXMAP_BOTTOM ||
835 G_CachePixmapPosition (icon_co) == XmPIXMAP_MIDDLE)
836 XmeFromVerticalPixels ((Widget)icon_co, offset, value);
838 XmeFromHorizontalPixels ((Widget)icon_co, offset, value);
843 /*-------------------------------------------------------------
845 ** Convert string from internal to external form.
854 DtIconGadget g = (DtIconGadget) w;
857 string = XmStringCopy (G_String (g));
859 *value = (XtArgVal) string;
863 /*-------------------------------------------------------------
865 ** Event handler for middle button events.
871 XtPointer client_data,
872 XButtonEvent *event )
874 DtIconGadget g = NULL;
876 g = (DtIconGadget) XmObjectAtPoint (w, event->x, event->y);
878 if (!g || !DtIsIcon ((Widget)g))
881 if (event->button == Button2 || event->button == Button3)
883 if (event->type == ButtonPress)
884 InputDispatch ((Widget) g, event, XmARM_EVENT);
885 else if (event->type == ButtonRelease)
886 InputDispatch ((Widget) g, event, XmACTIVATE_EVENT);
892 /*-------------------------------------------------------------
894 ** Clear Click flags.
902 DtIconGadget g = (DtIconGadget) w;
903 Time last_time, end_time;
907 G_ClickTimerID (g) = 0;
908 XtFree ((char *)G_ClickEvent (g));
909 G_ClickEvent (g) = NULL;
913 last_time = XtLastTimestampProcessed (XtDisplay (g));
917 if( G_ClickEvent (g) == NULL) return;
919 end_time = G_ClickEvent (g) -> time + (Time)
920 XtGetMultiClickTime (XtDisplay (g));
922 /* Sync and reset timer if server interval may not have elapsed.
924 if ((last_time < end_time) && G_Sync (g))
927 XSync (XtDisplay (g), False);
929 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget)g),
931 (XtTimerCallbackProc)ClickTimeout,
934 /* Handle Select action.
938 CallCallbackProc call_callback;
942 expose = XtCoreProc(w, expose);
943 call_callback = C_CallCallback(XtClass(w));
946 G_ClickTimerID (g) = 0;
948 (*call_callback) (g, G_Callback (g), XmCR_SELECT,
949 (XEvent *)G_ClickEvent (g));
951 if ((G_Behavior (g) == XmICON_DRAG) &&
952 (G_ShadowThickness (g) == 0))
957 (*expose) ((Widget)g, (XEvent*)G_ClickEvent (g), NULL);
958 XtFree ((char *)G_ClickEvent (g));
959 G_ClickEvent (g) = NULL;
965 /*-------------------------------------------------------------
967 **-------------------------------------------------------------
970 /*-------------------------------------------------------------
972 ** Handle Arm action.
979 DtIconGadget g = (DtIconGadget) w;
981 if (G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
986 if (G_Behavior (g) == XmICON_DRAG)
988 CallCallbackProc call_callback;
991 call_callback = C_CallCallback(XtClass(g));
993 (*call_callback) (g, G_Callback (g), XmCR_ARM, event);
996 if ((G_Behavior (g) == XmICON_DRAG) &&
997 (G_ShadowThickness (g) == 0))
1003 XtExposeProc expose;
1006 expose = XtCoreProc(w, expose);
1008 (*expose) ((Widget)g, event, NULL);
1014 /*-------------------------------------------------------------
1016 ** Handle Disarm action.
1023 DtIconGadget g = (DtIconGadget) w;
1025 if (! G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
1028 G_Armed (g) = False;
1030 if (G_Behavior (g) == XmICON_DRAG)
1032 CallCallbackProc call_callback;
1033 XtExposeProc expose;
1036 call_callback = C_CallCallback(XtClass(g));
1037 expose = XtCoreProc(w, expose);
1039 (*call_callback) (g, G_Callback (g), XmCR_DISARM, event);
1040 (*expose) ((Widget)g, event, NULL);
1046 /*-------------------------------------------------------------
1048 ** Handle Activate action.
1055 DtIconGadget g = (DtIconGadget) w;
1056 unsigned long delay;
1057 XButtonEvent * b_event = (XButtonEvent *) event;
1058 CallCallbackProc call_callback;
1059 XtExposeProc expose;
1065 call_callback = C_CallCallback(XtClass(g));
1066 expose = XtCoreProc(w, expose);
1068 if (G_Behavior (g) == XmICON_BUTTON)
1070 G_Armed (g) = False;
1071 (*call_callback) (g, G_Callback (g), XmCR_ACTIVATE, event);
1072 (*expose) ((Widget)g, event, NULL);
1075 else if (G_Behavior (g) == XmICON_TOGGLE)
1077 G_Armed (g) = False;
1078 G_Set (g) = ! G_Set (g);
1079 (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, event);
1082 else if (G_Behavior (g) == XmICON_DRAG)
1084 if (G_ClickTimerID (g))
1086 G_ClickTimerID (g) = 0;
1087 XtFree ((char *)G_ClickEvent (g));
1088 G_ClickEvent (g) = NULL;
1089 G_Armed (g) = False;
1090 (*call_callback) (g, G_Callback (g),
1091 XmCR_DEFAULT_ACTION, event);
1095 if(event->type==KeyPress){
1097 (*call_callback)(g,G_Callback(g),XmCR_SELECT,event);
1099 delay = (unsigned long)
1100 XtGetMultiClickTime (XtDisplay (g));
1101 G_ClickEvent (g) = (XButtonEvent *)
1102 XtMalloc (sizeof (XButtonEvent));
1103 *(G_ClickEvent (g)) = *b_event;
1105 G_ClickTimerID (g) =
1107 XtWidgetToApplicationContext ((Widget)g),
1108 delay, (XtTimerCallbackProc)ClickTimeout,
1113 if (G_ShadowThickness (g) > 0)
1114 (*expose) ((Widget)g, event, NULL);
1120 /*-------------------------------------------------------------
1122 ** Handle Drag action.
1129 DtIconGadget g = (DtIconGadget) w;
1131 if (G_Behavior (g) == XmICON_DRAG)
1133 CallCallbackProc call_callback;
1136 call_callback = C_CallCallback(XtClass(w));
1138 (*call_callback) (g, G_Callback (g), XmCR_DRAG, event);
1143 /*-------------------------------------------------------------
1145 ** Handle button 3 - popup's
1152 DtIconGadget g = (DtIconGadget) w;
1153 CallCallbackProc call_callback;
1156 call_callback = C_CallCallback(XtClass(w));
1158 (*call_callback) (g, G_Callback (g), XmCR_POPUP, event);
1163 /*-------------------------------------------------------------
1165 ** Handle Enter action.
1172 DtIconGadget g = (DtIconGadget) w;
1174 _XmEnterGadget (w, (XEvent *)event,
1175 (String *)NULL,(Cardinal *)0);
1179 if ((G_Behavior (g) == XmICON_BUTTON) ||
1180 (G_Behavior (g) == XmICON_TOGGLE))
1182 XtExposeProc expose;
1184 expose = XtCoreProc(w, expose);
1186 (*expose) ((Widget)g, event, NULL);
1192 /*-------------------------------------------------------------
1194 ** Handle Leave action.
1201 DtIconGadget g = (DtIconGadget) w;
1203 _XmLeaveGadget (w, (XEvent *)event,
1204 (String *)NULL, (Cardinal *)0);
1207 if ((G_Behavior (g) == XmICON_BUTTON) ||
1208 (G_Behavior (g) == XmICON_TOGGLE))
1210 XtExposeProc expose;
1213 expose = XtCoreProc(w, expose);
1216 G_Armed (g) = False;
1217 (*expose) ((Widget)g, event, NULL);
1225 /*-------------------------------------------------------------
1227 **-------------------------------------------------------------
1230 /*-------------------------------------------------------------
1232 ** Initialize gadget class.
1235 ClassInitialize( void )
1237 _DtRegisterNewConverters ();
1239 iconBaseClassExtRec.record_type = XmQmotif;
1242 /*-------------------------------------------------------------
1243 ** ClassPartInitialize
1244 ** Initialize gadget class part.
1247 ClassPartInitialize (
1250 DtIconGadgetClass ic = (DtIconGadgetClass) wc;
1251 DtIconGadgetClass super = (DtIconGadgetClass) ic->rect_class.superclass;
1253 if (C_GetSize (ic) == DtInheritGetSize)
1254 C_GetSize (ic) = C_GetSize (super);
1255 if (C_GetPositions (ic) == DtInheritGetPositions)
1256 C_GetPositions (ic) = C_GetPositions (super);
1257 if (C_Draw (ic) == DtInheritDraw)
1258 C_Draw (ic) = C_Draw (super);
1259 if (C_CallCallback (ic) == DtInheritCallCallback)
1260 C_CallCallback (ic) = C_CallCallback (super);
1261 if (C_UpdateGCs (ic) == DtInheritUpdateGCs)
1262 C_UpdateGCs (ic) = C_UpdateGCs (super);
1265 /*-------------------------------------------------------------
1267 **-------------------------------------------------------------
1270 /*-------------------------------------------------------------
1279 DtIconCacheObjPart *icon_inst = (DtIconCacheObjPart *) A ;
1280 DtIconCacheObjPart *icon_cache_inst = (DtIconCacheObjPart *) B ;
1282 if ((icon_inst->fill_on_arm == icon_cache_inst->fill_on_arm) &&
1283 (icon_inst->recompute_size== icon_cache_inst->recompute_size) &&
1284 (icon_inst->pixmap_position== icon_cache_inst->pixmap_position) &&
1285 (icon_inst->string_position== icon_cache_inst->string_position) &&
1286 (icon_inst->alignment == icon_cache_inst->alignment) &&
1287 (icon_inst->behavior == icon_cache_inst->behavior) &&
1288 (icon_inst->draw_shadow == icon_cache_inst->draw_shadow) &&
1289 (icon_inst->fill_mode == icon_cache_inst->fill_mode) &&
1290 (icon_inst->margin_width== icon_cache_inst->margin_width) &&
1291 (icon_inst->margin_height== icon_cache_inst->margin_height) &&
1292 (icon_inst->string_height== icon_cache_inst->string_height) &&
1293 (icon_inst->spacing== icon_cache_inst->spacing) &&
1294 (icon_inst->foreground== icon_cache_inst->foreground) &&
1295 (icon_inst->background== icon_cache_inst->background) &&
1296 (icon_inst->arm_color== icon_cache_inst->arm_color))
1304 /*-------------------------------------------------------------
1305 ** SecondaryObjectCreate
1309 SecondaryObjectCreate(
1313 Cardinal *num_args )
1315 XmBaseClassExt *cePtr;
1316 XmWidgetExtData extData;
1319 XtPointer newSec, reqSec;
1320 XtResourceList resources;
1321 Cardinal num_resources;
1324 cePtr = _XmGetBaseClassExtPtr(XtClass(new_w), XmQmotif);
1325 wc = (*cePtr)->secondaryObjectClass;
1326 if (NULL == wc) return;
1327 size = wc->core_class.widget_size;
1328 resources = wc->core_class.resources;
1329 num_resources = wc->core_class.num_resources;
1331 newSec = _XmExtObjAlloc(size);
1332 reqSec = _XmExtObjAlloc(size);
1336 * fetch the resources in superclass to subclass order
1339 XtGetSubresources(new_w, newSec, NULL, NULL,
1340 resources, num_resources, args, *num_args );
1342 extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
1343 extData->widget = (Widget)newSec;
1344 extData->reqWidget = (Widget)reqSec;
1346 ((DtIconCacheObject)newSec)->ext.extensionType = XmCACHE_EXTENSION;
1347 ((DtIconCacheObject)newSec)->ext.logicalParent = new_w;
1349 _XmPushWidgetExtData(new_w, extData,
1350 ((DtIconCacheObject)newSec)->ext.extensionType);
1351 memcpy(reqSec, newSec, size);
1354 * fill out cache pointers
1356 Icon_Cache(new_w) = &(((DtIconCacheObject)extData->widget)->icon_cache);
1357 Icon_Cache(req) = &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
1362 /*-------------------------------------------------------------
1363 ** InitializePostHook
1372 Cardinal *num_args )
1374 XmWidgetExtData ext;
1375 DtIconGadget lw = (DtIconGadget)new;
1378 * - register parts in cache.
1379 * - update cache pointers
1384 Icon_Cache(lw) = (DtIconCacheObjPart *)
1385 _XmCachePart( Icon_ClassCachePart(lw),
1386 (XtPointer) Icon_Cache(lw),
1387 sizeof(DtIconCacheObjPart));
1390 * might want to break up into per-class work that gets explicitly
1391 * chained. For right now, each class has to replicate all
1392 * superclass logic in hook routine
1395 /* * free the req subobject used for comparisons
1397 _XmPopWidgetExtData((Widget) lw, &ext, XmCACHE_EXTENSION);
1398 _XmExtObjFree((XtPointer)ext->widget);
1399 _XmExtObjFree((XtPointer)ext->reqWidget);
1401 XtFree( (char *) ext);
1404 /*-------------------------------------------------------------
1415 Cardinal *num_args )
1417 XmWidgetExtData extData;
1418 XmBaseClassExt *cePtr;
1420 DtIconCacheObject newSec, reqSec;
1422 XtResourceList resources;
1423 Cardinal num_resources;
1426 cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
1427 ec = (*cePtr)->secondaryObjectClass;
1428 size = ec->core_class.widget_size;
1429 resources = ec->core_class.resources;
1430 num_resources = ec->core_class.num_resources;
1432 /* allocate copies and fill from cache */
1433 newSec = (DtIconCacheObject) _XmExtObjAlloc(size);
1434 reqSec = (DtIconCacheObject) _XmExtObjAlloc(size);
1437 newSec->object.self = (Widget)newSec;
1438 newSec->object.widget_class = ec;
1439 newSec->object.parent = XtParent(newParent);
1440 newSec->object.xrm_name = newParent->core.xrm_name;
1441 newSec->object.being_destroyed = False;
1442 newSec->object.destroy_callbacks = NULL;
1443 newSec->object.constraints = NULL;
1445 newSec->ext.logicalParent = newParent;
1446 newSec->ext.extensionType = XmCACHE_EXTENSION;
1448 memcpy(&(newSec->icon_cache),
1449 Icon_Cache(newParent),
1450 sizeof(DtIconCacheObjPart));
1452 extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
1453 extData->widget = (Widget)newSec;
1454 extData->reqWidget = (Widget)reqSec;
1455 _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
1457 _XmGadgetImportSecondaryArgs(newParent, args, num_args);
1458 XtSetSubvalues((XtPointer)newSec, resources, num_resources,
1461 _XmExtImportArgs((Widget)newSec, args, num_args);
1463 memcpy((XtPointer)reqSec, (XtPointer)newSec, size);
1465 Icon_Cache(newParent) = &(((DtIconCacheObject)newSec)->icon_cache);
1466 Icon_Cache(refParent) =
1467 &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
1473 /*-------------------------------------------------------------
1481 Cardinal *num_args )
1483 XmWidgetExtData extData;
1484 XmBaseClassExt *cePtr;
1486 DtIconCacheObject newSec;
1488 XtResourceList resources;
1489 Cardinal num_resources;
1492 cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
1493 ec = (*cePtr)->secondaryObjectClass;
1494 size = ec->core_class.widget_size;
1495 resources = ec->core_class.resources;
1496 num_resources = ec->core_class.num_resources;
1498 newSec = (DtIconCacheObject)_XmExtObjAlloc(size);
1501 newSec->object.self = (Widget)newSec;
1502 newSec->object.widget_class = ec;
1503 newSec->object.parent = XtParent(newParent);
1504 newSec->object.xrm_name = newParent->core.xrm_name;
1505 newSec->object.being_destroyed = False;
1506 newSec->object.destroy_callbacks = NULL;
1507 newSec->object.constraints = NULL;
1509 newSec->ext.logicalParent = newParent;
1510 newSec->ext.extensionType = XmCACHE_EXTENSION;
1512 memcpy( &(newSec->icon_cache),
1513 Icon_Cache(newParent),
1514 sizeof(DtIconCacheObjPart));
1516 extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
1517 extData->widget = (Widget)newSec;
1518 _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
1520 XtGetSubvalues((XtPointer)newSec, resources, num_resources,
1523 _XmExtGetValuesHook((Widget)newSec, args, num_args);
1528 /*-------------------------------------------------------------
1529 ** GetValuesPosthook
1537 Cardinal *num_args )
1539 XmWidgetExtData ext;
1541 _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
1544 _XmExtObjFree((XtPointer)ext->widget);
1547 XtFree((char *)ext);
1552 /*-------------------------------------------------------------
1553 ** SetValuesPosthook
1563 Cardinal *num_args )
1565 XmWidgetExtData ext;
1568 * - register parts in cache.
1569 * - update cache pointers
1574 /* assign if changed! */
1576 if (!IconCacheCompare((XtPointer)Icon_Cache(new),
1577 (XtPointer)Icon_Cache(current)))
1580 _XmCacheDelete((XtPointer) Icon_Cache(current)); /* delete the old one */
1581 Icon_Cache(new) = (DtIconCacheObjPart *)
1582 _XmCachePart(Icon_ClassCachePart(new),
1583 (XtPointer) Icon_Cache(new),
1584 sizeof(DtIconCacheObjPart));
1586 Icon_Cache(new) = Icon_Cache(current);
1588 _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
1590 _XmExtObjFree((XtPointer)ext->widget);
1591 _XmExtObjFree((XtPointer)ext->reqWidget);
1594 XtFree((char *)ext);
1600 /*--------------------------------------------------------------------------
1601 ** QualifyIconLocalCache
1602 ** Checks to see if local cache is set up
1605 QualifyIconLocalCache(DtIconGadget g, DtIconCacheObjPart *local_cache)
1608 ClassCacheCopy(Icon_ClassCachePart(g))((XtPointer) Icon_Cache(g),
1609 (XtPointer) local_cache,
1610 sizeof(DtIconCacheObjPart));
1614 /************************************************************************
1617 * Check to see if ReCaching is necessary as a result of fields having
1618 * been set by a mananger widget. This routine is called by the
1619 * manager widget in their SetValues after a change is made to any
1620 * of Icon's cached fields.
1622 ************************************************************************/
1625 ReCacheIcon_r(DtIconCacheObjPart *local_cache, DtIconGadget g)
1627 if (!IconCacheCompare( (XtPointer)local_cache, (XtPointer)Icon_Cache(g)))
1630 _XmCacheDelete( (XtPointer) Icon_Cache(g)); /* delete the old one */
1631 Icon_Cache(g) = (DtIconCacheObjPart *)
1632 _XmCachePart(Icon_ClassCachePart(g),
1633 (XtPointer) local_cache,
1634 sizeof(DtIconCacheObjPart));
1640 /*********************************************************************
1642 * GetParentBackgroundGC
1643 * Get the graphics context used for erasing their highlight border.
1645 *********************************************************************/
1647 GetParentBackgroundGC(
1652 Widget parent = XtParent((Widget)g);
1654 valueMask = GCForeground | GCBackground;
1655 values.foreground = parent->core.background_pixel;
1657 if (XmIsManager(parent))
1659 values.background = ((XmManagerWidget) parent)->manager.foreground;
1661 values.background = ((XmPrimitiveWidget) parent)->primitive.foreground;
1663 if ((parent->core.background_pixmap != None) &&
1664 (parent->core.background_pixmap != XmUNSPECIFIED_PIXMAP))
1666 valueMask |= GCFillStyle | GCTile;
1667 values.fill_style = FillTiled;
1668 values.tile = parent->core.background_pixmap;
1671 G_SavedParentBG(g) = parent->core.background_pixel;
1673 G_ParentBackgroundGC(g) = XtGetGC (parent, valueMask, &values);
1677 /*-------------------------------------------------------------
1679 ** Initialize a new gadget instance.
1686 DtIconGadget request = (DtIconGadget) request_w,
1687 new = (DtIconGadget) new_w;
1689 int int_x = 0, int_y = 0;
1690 unsigned int int_w = 0, int_h = 0,
1695 UpdateGCsProc update_gcs;
1697 G_Sync (new) = False;
1699 /* Validate behavior.
1701 if (G_Behavior (new) != XmICON_LABEL &&
1702 G_Behavior (new) != XmICON_BUTTON &&
1703 G_Behavior (new) != XmICON_TOGGLE &&
1704 G_Behavior (new) != XmICON_DRAG)
1706 XmeWarning ((Widget)new, WARN_BEHAVIOR);
1707 G_Behavior (new) = XmICON_BUTTON;
1710 /* Set the input mask for events handled by Manager.
1712 G_EventMask (new) = (XmARM_EVENT | XmACTIVATE_EVENT |
1713 XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
1714 XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
1715 XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
1717 /* Add event handler for icon events.
1719 if (G_Behavior (new) == XmICON_DRAG)
1721 mask = ButtonPressMask|ButtonReleaseMask;
1722 XtAddEventHandler (XtParent (new), mask, False,
1723 (XtEventHandler) IconEventHandler, 0);
1726 G_ClickTimerID (new) = 0;
1727 G_ClickEvent (new) = NULL;
1729 G_Armed (new) = False;
1731 G_Mask (new) = None;
1733 if (G_Pixmap (new) == XmUNSPECIFIED_PIXMAP)
1734 G_Pixmap (new) = None;
1736 if (G_ImageName (new) || G_Pixmap (new))
1738 if (G_ImageName (new))
1741 /* Try to get pixmap from image name.
1744 XmGetPixmap (XtScreen (new), G_ImageName (new),
1745 G_PixmapForeground (new),
1746 G_PixmapBackground (new));
1747 if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
1749 name = G_ImageName (new);
1751 _DtGetMask(XtScreen (new), G_ImageName
1758 G_Pixmap (new) = None;
1762 /* Update width and height; copy image name.
1766 XGetGeometry (XtDisplay (new), G_Pixmap (new),
1767 &root, &int_x, &int_y, &int_w, &int_h,
1772 G_ImageName (new) = XtNewString(name);
1775 G_ImageName (new) = NULL;
1777 G_PixmapWidth(new) = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
1778 G_PixmapHeight(new) = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
1780 /* Validate fill mode.
1782 if (G_FillMode (new) != XmFILL_NONE &&
1783 G_FillMode (new) != XmFILL_PARENT &&
1784 G_FillMode (new) != XmFILL_TRANSPARENT &&
1785 G_FillMode (new) != XmFILL_SELF)
1787 XmeWarning ((Widget)new, WARN_FILL_MODE);
1788 if (G_ShadowThickness (new) > 0)
1789 G_FillMode (new) = XmFILL_SELF;
1791 G_FillMode (new) = XmFILL_PARENT;
1794 /* Validate pixmap position.
1796 if (G_StringPosition (new) != UNSPECIFIED_CHAR)
1797 G_PixmapPosition (new) = G_StringPosition (new);
1799 if (G_PixmapPosition (new) == UNSPECIFIED_CHAR)
1800 G_PixmapPosition (new) = XmPIXMAP_LEFT;
1801 else if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
1802 G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
1803 G_PixmapPosition (new) != XmPIXMAP_TOP &&
1804 G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
1805 G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
1807 XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
1808 G_PixmapPosition (new) = XmPIXMAP_LEFT;
1810 G_StringPosition (new) = G_PixmapPosition (new);
1812 /* Validate alignment.
1814 if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
1815 G_Alignment (new) != XmALIGNMENT_CENTER &&
1816 G_Alignment (new) != XmALIGNMENT_END)
1818 XmeWarning ((Widget)new, WARN_ALIGNMENT);
1819 G_Alignment (new) = XmALIGNMENT_BEGINNING;
1822 /* Validate shadow type.
1824 if (G_ShadowType (new) != XmSHADOW_IN &&
1825 G_ShadowType (new) != XmSHADOW_OUT &&
1826 G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
1827 G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
1829 XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
1830 if (G_Behavior (new) == XmICON_BUTTON)
1831 G_ShadowType (new) = XmSHADOW_OUT;
1832 else if (G_Behavior (new) == XmICON_TOGGLE)
1833 G_ShadowType (new) = (G_Set (new))
1834 ? XmSHADOW_ETCHED_IN : XmSHADOW_ETCHED_OUT;
1839 if (G_FontList (new) == NULL)
1841 XmeGetDefaultRenderTable ((Widget)new, XmBUTTON_FONTLIST);
1842 G_FontList (new) = XmFontListCopy (G_FontList (new));
1844 if (G_String (new) == XmUNSPECIFIED_STRING)
1845 G_String (new) = (_XmString) NULL;
1849 G_String (new) = XmStringCopy (G_String (new));
1850 XmStringExtent (G_FontList (new), G_String (new),
1852 if (G_Underline(new))
1858 G_StringWidth (new) = w;
1859 G_StringHeight (new) = h;
1861 /* Convert margins to pixel units.
1863 if (G_UnitType (new) != XmPIXELS)
1865 G_MarginWidth (new) =
1866 XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
1867 (XtArgVal *)((long)G_MarginWidth (new)));
1868 G_MarginHeight (new) =
1869 XmeToVerticalPixels ((Widget)new, G_UnitType (new),
1870 (XtArgVal *)((long)G_MarginHeight (new)));
1873 /* Check for unspecified margins.
1875 if (G_MarginWidth (request) == UNSPECIFIED_DIMENSION)
1876 G_MarginWidth (new) = MARGIN_DEFAULT;
1877 if (G_MarginHeight (request) == UNSPECIFIED_DIMENSION)
1878 G_MarginHeight (new) = MARGIN_DEFAULT;
1882 if (G_Spacing (new) == UNSPECIFIED_DIMENSION)
1884 G_Spacing (new) = G_StringHeight (new) / 5;
1885 if (G_Spacing (new) < SPACING_DEFAULT)
1886 G_Spacing (new) = SPACING_DEFAULT;
1888 else if (G_Spacing (new) && G_UnitType (new) != XmPIXELS)
1891 (G_PixmapPosition (new) == XmPIXMAP_LEFT ||
1892 G_PixmapPosition (new) == XmPIXMAP_RIGHT)
1893 ? XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
1894 (XtArgVal *)((long)G_Spacing (new)))
1895 : XmeToVerticalPixels ((Widget)new, G_UnitType (new),
1896 (XtArgVal *)((long)G_Spacing (new)));
1899 /* Set width and height.
1901 if (G_Width (request) == 0 || G_Height (request) == 0)
1903 GetSizeProc get_size;
1906 get_size = C_GetSize(XtClass(new));
1908 (*get_size) (new, &w, &h);
1910 if (G_Width (request) == 0)
1912 if (G_Height (request) == 0)
1916 /* Get graphics contexts.
1918 G_NormalGC (new) = NULL;
1919 G_ClipGC (new) = NULL;
1920 G_BackgroundGC (new) = NULL;
1921 G_ArmedGC (new) = NULL;
1922 G_ArmedBackgroundGC (new) = NULL;
1924 update_gcs = C_UpdateGCs(XtClass(new));
1926 (*update_gcs) (new);
1928 GetParentBackgroundGC(new);
1930 if (G_Operations(new) != XmDROP_NOOP) {
1931 _DtIconRegisterDropsite(new_w);
1937 /*-------------------------------------------------------------
1939 ** Release resources allocated for gadget.
1945 DtIconGadget g = (DtIconGadget) w;
1946 XmManagerWidget mw = (XmManagerWidget) XtParent(g);
1948 if (G_ClickTimerID (g))
1949 XtRemoveTimeOut (G_ClickTimerID (g));
1951 XtFree ((char *)G_ClickEvent (g));
1953 if (G_String (g) != NULL)
1954 XmStringFree (G_String (g));
1956 if (G_ImageName (g) != NULL)
1958 XtFree (G_ImageName (g));
1959 if (G_Mask (g) != XmUNSPECIFIED_PIXMAP)
1960 XmDestroyPixmap (XtScreen(w),G_Mask (g));
1961 XmDestroyPixmap (XtScreen(w),G_Pixmap (g));
1964 XmFontListFree (G_FontList (g));
1967 _XmCacheDelete((XtPointer) Icon_Cache(w));
1970 XtReleaseGC ((Widget)mw, G_NormalGC (g));
1971 XtReleaseGC ((Widget)mw, G_ClipGC (g));
1972 XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
1973 XtReleaseGC ((Widget)mw, G_ArmedGC (g));
1974 XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
1976 /* remove event handler if last Icon in parent? */
1981 /*-------------------------------------------------------------
1993 /*-------------------------------------------------------------
1995 ** Redisplay gadget.
2004 DtIconGadget g = (DtIconGadget) w;
2005 Dimension s_t = G_ShadowThickness (g);
2006 unsigned char fill_mode = G_FillMode (g);
2009 if (! XtIsManaged (w))
2012 /* Draw gadget to window.
2015 draw = C_Draw(XtClass(g));
2017 (*draw) (g, XtWindow (g), G_X (g), G_Y (g), G_Width (g), G_Height (g),
2018 G_HighlightThickness (g), s_t, G_ShadowType (g), fill_mode);
2020 /* Draw highlight if highlighted.
2022 if (G_Highlighted (g))
2023 BorderHighlight( (DtIconGadget)g );
2028 /*-------------------------------------------------------------
2039 DtIconGadget current = (DtIconGadget) current_w,
2040 new = (DtIconGadget) new_w;
2043 int int_x = 0, int_y = 0;
2044 unsigned int int_w = 0, int_h = 0,
2047 Boolean new_image_name = False,
2048 redraw_flag = False,
2049 draw_pixmap = False,
2050 draw_string = False,
2051 draw_shadow = False;
2052 Dimension h_t = G_HighlightThickness (new),
2053 s_t = G_ShadowThickness (new),
2056 Boolean optimize_redraw = False;
2058 /* If unchanged, reuse old image name
2060 if (G_ImageName (current) != G_ImageName (new) &&
2061 G_ImageName (new) &&
2062 G_ImageName (current) &&
2063 strcmp(G_ImageName (current), G_ImageName (new)) == 0)
2065 G_ImageName (new) = G_ImageName (current);
2068 /* Validate behavior
2070 if (G_Behavior (new) != G_Behavior (current))
2072 if (G_Behavior (new) != XmICON_LABEL &&
2073 G_Behavior (new) != XmICON_BUTTON &&
2074 G_Behavior (new) != XmICON_TOGGLE &&
2075 G_Behavior (new) != XmICON_DRAG)
2077 XmeWarning ((Widget)new, WARN_BEHAVIOR);
2078 G_Behavior (new) = G_Behavior (current);
2081 if (G_Behavior (new) == XmICON_DRAG)
2085 mask = ButtonPressMask|ButtonReleaseMask;
2086 XtAddEventHandler (XtParent (new), mask, False,
2087 (XtEventHandler) IconEventHandler, 0);
2091 /* Reset the interesting input types.
2093 G_EventMask (new) |= (XmARM_EVENT | XmACTIVATE_EVENT |
2094 XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
2095 XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
2096 XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
2098 /* Check for new image name.
2100 if (G_ImageName (new) && (G_ImageName (current) != G_ImageName (new)))
2101 new_image_name = True;
2103 /* Validate shadow type.
2105 if ((G_ShadowType (new) != G_ShadowType (current)) ||
2106 (G_Behavior (new) == XmICON_TOGGLE &&
2107 G_Set (new) != G_Set (current)))
2109 if (G_ShadowType (new) != XmSHADOW_IN &&
2110 G_ShadowType (new) != XmSHADOW_OUT &&
2111 G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
2112 G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
2114 XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
2115 G_ShadowType (new) = G_ShadowType (current);
2118 /* Disallow change if conflict with set or armed state.
2120 else if (((G_Behavior (new) == XmICON_TOGGLE) &&
2121 ((G_Set (new) && ! G_Armed (new)) ||
2122 (! G_Set (new) && G_Armed (new)))) ||
2123 ((G_Behavior (new) == XmICON_BUTTON) &&
2126 if (G_ShadowType (new) == XmSHADOW_OUT)
2127 G_ShadowType (new) = XmSHADOW_IN;
2128 else if (G_ShadowType (new) == XmSHADOW_ETCHED_OUT)
2129 G_ShadowType (new) = XmSHADOW_ETCHED_IN;
2131 else if (((G_Behavior (new) == XmICON_TOGGLE) &&
2132 ((G_Set (new) && G_Armed (new)) ||
2133 (! G_Set (new) && ! G_Armed (new)))) ||
2134 ((G_Behavior (new) == XmICON_BUTTON) &&
2137 if (G_ShadowType (new) == XmSHADOW_IN)
2138 G_ShadowType (new) = XmSHADOW_OUT;
2139 else if (G_ShadowType (new) == XmSHADOW_ETCHED_IN)
2140 G_ShadowType (new) = XmSHADOW_ETCHED_OUT;
2143 if (G_ShadowType (new) != G_ShadowType (current))
2147 /* Validate alignment.
2149 if (G_Alignment (new) != G_Alignment (current))
2151 if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
2152 G_Alignment (new) != XmALIGNMENT_CENTER &&
2153 G_Alignment (new) != XmALIGNMENT_END)
2155 XmeWarning ((Widget)new, WARN_ALIGNMENT);
2156 G_Alignment (new) = G_Alignment (current);
2163 /* Validate fill mode.
2165 if (G_FillMode (new) != G_FillMode (current))
2167 if (G_FillMode (new) != XmFILL_NONE &&
2168 G_FillMode (new) != XmFILL_PARENT &&
2169 G_FillMode (new) != XmFILL_TRANSPARENT &&
2170 G_FillMode (new) != XmFILL_SELF)
2172 XmeWarning ((Widget)new, WARN_FILL_MODE);
2173 G_FillMode (new) = G_FillMode (current);
2177 /* Validate pixmap position.
2179 if (G_StringPosition (new) != G_StringPosition (current))
2180 G_PixmapPosition (new) = G_StringPosition (new);
2182 if (G_PixmapPosition (new) != G_PixmapPosition (current))
2184 if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
2185 G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
2186 G_PixmapPosition (new) != XmPIXMAP_TOP &&
2187 G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
2188 G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
2190 XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
2191 G_PixmapPosition (new) = G_PixmapPosition (current);
2196 G_StringPosition (new) = G_PixmapPosition (new);
2199 /* Update pixmap if pixmap foreground or background changed.
2201 if (G_PixmapForeground (current) != G_PixmapForeground (new) ||
2202 G_PixmapBackground (current) != G_PixmapBackground (new))
2204 if (G_Pixmap (current) == G_Pixmap (new) &&
2205 (G_ImageName (new) != NULL) &&
2209 if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
2210 XmDestroyPixmap( XtScreen(new), G_Mask(current));
2211 XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
2213 XmGetPixmap (XtScreen (new), G_ImageName (new),
2214 G_PixmapForeground (new),
2215 G_PixmapBackground (new));
2216 if (G_Pixmap(new) != XmUNSPECIFIED_PIXMAP)
2218 _DtGetMask(XtScreen (new), G_ImageName (new));
2223 /* Check for change in image name.
2228 /* Try to get pixmap from image name.
2230 if (G_ImageName (current) != NULL)
2232 if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
2233 XmDestroyPixmap (XtScreen(new),G_Mask(current));
2234 XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
2237 XmGetPixmap (XtScreen (new), G_ImageName (new),
2238 G_PixmapForeground (new),
2239 G_PixmapBackground (new));
2241 if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
2243 G_Mask(new) = (Pixmap)_DtGetMask(XtScreen(new), G_ImageName(new));
2244 XGetGeometry (XtDisplay (new), G_Pixmap (new),
2245 &root, &int_x, &int_y, &int_w, &int_h,
2247 name = G_ImageName (new);
2248 w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
2249 h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
2254 G_Pixmap (new) = None;
2259 /* If resetting to current image name, then reuse old copy.
2261 if (name && G_ImageName (current)
2262 && (! strcmp (G_ImageName (new), G_ImageName (current))))
2264 G_ImageName (new) = G_ImageName (current);
2265 name = G_ImageName (current);
2270 G_ImageName (new) = XtNewString(name);
2272 G_ImageName (new) = NULL;
2273 if (G_ImageName (current))
2274 XtFree (G_ImageName (current));
2277 if (G_Pixmap (new) != G_Pixmap (current))
2279 if ((G_Pixmap (new) != None) &&
2280 (G_PixmapWidth (new) == w) &&
2281 (G_PixmapHeight (new) == h))
2288 G_PixmapWidth (new) = w;
2289 G_PixmapHeight (new) = h;
2294 /* Release image name and pixmap if name set to null.
2296 else if (G_Pixmap (new) == G_Pixmap (current))
2298 if ((G_ImageName (current) != NULL) &&
2299 (G_ImageName (new) == NULL))
2302 XtFree (G_ImageName (current));
2303 if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
2304 XmDestroyPixmap (XtScreen(new),G_Mask (current));
2305 XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
2306 G_Pixmap (new) = None;
2307 G_PixmapWidth (new) = 0;
2308 G_PixmapHeight (new) = 0;
2312 /* Process change in pixmap.
2314 else if (G_Pixmap (new) != G_Pixmap (current))
2318 XGetGeometry (XtDisplay (new), G_Pixmap (new), &root,
2319 &int_x, &int_y, &int_w, &int_h,
2321 w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
2322 h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
2326 if (G_ImageName (current) != NULL)
2328 XtFree (G_ImageName (current));
2329 if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
2330 XmDestroyPixmap (XtScreen(new),G_Mask (current));
2331 XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
2332 G_ImageName (new) = NULL;
2337 if (G_Pixmap (new) &&
2338 (G_PixmapWidth (new) == w) &&
2339 (G_PixmapHeight (new) == h))
2346 G_PixmapWidth (new) = w;
2347 G_PixmapHeight (new) = h;
2351 if( ( G_MaxPixmapWidth(new) != G_MaxPixmapWidth(current)) ||
2352 (G_MaxPixmapHeight(new) != G_MaxPixmapHeight(current)) )
2356 XGetGeometry (XtDisplay (new), G_Pixmap (new), &root,
2357 &int_x, &int_y, &int_w, &int_h,
2359 w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
2360 h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
2367 if (G_Pixmap (new) &&
2368 (G_PixmapWidth (new) == w) &&
2369 (G_PixmapHeight (new) == h))
2376 G_PixmapWidth (new) = w;
2377 G_PixmapHeight (new) = h;
2382 /* Update GCs if foreground, background or mask changed.
2384 if (G_Foreground (current) != G_Foreground (new) ||
2385 G_Background (current) != G_Background (new) ||
2386 ((G_Mask (current) != G_Mask(new)) &&
2387 (G_Pixmap (current) != G_Pixmap (new))) ||
2388 G_ArmColor (current) != G_ArmColor (new))
2390 UpdateGCsProc update_gcs;
2391 if (G_ShadowThickness (new) > 0 &&
2392 G_Behavior(new) != XmICON_DRAG &&
2393 G_Background (current) != G_Background (new))
2398 update_gcs = C_UpdateGCs(XtClass(new));
2400 (*update_gcs) (new);
2403 /* Convert dimensions to pixel units.
2405 if (G_UnitType (new) != XmPIXELS)
2407 G_MarginWidth (new) =
2408 XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
2409 (XtArgVal *)((long)G_MarginWidth (new)));
2410 G_MarginHeight (new) =
2411 XmeToVerticalPixels ((Widget)new, G_UnitType (new),
2412 (XtArgVal *)((long)G_MarginHeight (new)));
2417 if (G_UnitType (new) != G_UnitType (current) &&
2418 G_UnitType (new) != XmPIXELS)
2421 (G_PixmapPosition (new) == XmPIXMAP_LEFT ||
2422 G_PixmapPosition (new) == XmPIXMAP_RIGHT)
2423 ? XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
2424 (XtArgVal *)((long)G_Spacing (new)))
2425 : XmeToVerticalPixels ((Widget)new, G_UnitType (new),
2426 (XtArgVal *)((long)G_Spacing (new)));
2429 /* Process change in string or font list.
2432 if (G_String (new) != G_String (current) ||
2433 G_FontList (new) != G_FontList (current) ||
2434 G_Underline (new) != G_Underline (current))
2436 if (G_FontList (new) != G_FontList (current))
2438 if (G_FontList (new) == NULL)
2439 G_FontList (new) = G_FontList (current);
2442 XmFontListFree (G_FontList (current));
2444 XmFontListCopy (G_FontList (new));
2449 if (G_String (new) != G_String (current))
2451 if (G_String (current))
2452 XmStringFree (G_String (current));
2454 XmStringCopy (G_String (new));
2457 XmStringExtent (G_FontList (new), G_String (new),
2459 if (G_Underline(new))
2465 G_StringWidth (new) = w;
2466 G_StringHeight (new) = h;
2468 G_Spacing (new) = (Dimension) G_StringHeight (new) / 5;
2469 if (G_Spacing (new) < SPACING_DEFAULT)
2470 G_Spacing (new) = SPACING_DEFAULT;
2472 if ((G_String (new) != NULL) &&
2473 (G_StringWidth (new) == G_StringWidth (current)) &&
2474 (G_StringHeight (new) == G_StringHeight (current)))
2480 /* Check for other changes requiring redraw.
2482 if (G_HighlightThickness (new) != G_HighlightThickness (current) ||
2483 G_ShadowThickness (new) != G_ShadowThickness (current) ||
2484 G_MarginWidth (new) != G_MarginWidth (current) ||
2485 G_MarginHeight (new) != G_MarginHeight (current) ||
2486 G_Spacing (new) != G_Spacing (current))
2493 if (!(redraw_flag ||
2494 (G_RecomputeSize (new) && ! G_RecomputeSize (current))))
2497 optimize_redraw = C_OptimizeRedraw(XtClass(new));
2502 (G_RecomputeSize (new) && ! G_RecomputeSize (current)))
2504 if (G_RecomputeSize (new) &&
2505 (G_Width (current) == G_Width (new) ||
2506 G_Height (current) == G_Height (new)))
2508 GetSizeProc get_size;
2511 get_size = C_GetSize(XtClass(new));
2513 (*get_size) (new, &w, &h);
2515 if (G_Width (current) == G_Width (new))
2517 if (G_Height (current) == G_Height (new))
2522 /* Set redraw flag if this class doesn't optimize redraw.
2524 else if (! optimize_redraw)
2526 if (draw_shadow || draw_pixmap || draw_string)
2530 /* Optimize redraw if managed.
2532 else if (XtIsManaged (new_w) && XtIsRealized(new_w))
2534 /* Get string and pixmap positions if necessary.
2536 if ((draw_pixmap && G_Pixmap (new)) ||
2537 (draw_string && G_String (new)))
2539 GetPositionProc get_positions;
2542 get_positions = C_GetPositions(XtClass(new));
2544 (*get_positions) (new, G_Width (new), G_Height (new),
2545 h_t, G_ShadowThickness (new),
2546 (Position *)&p_x, (Position *)&p_y,
2547 (Position *)&s_x, (Position *)&s_y);
2549 /* Copy pixmap, clip if necessary.
2551 if (draw_pixmap && G_Pixmap (new) &&
2552 G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
2554 w = ((unsigned) (p_x + s_t + h_t) >= G_Width (new))
2555 ? 0 : Min ((unsigned)G_PixmapWidth (new),
2556 G_Width (new) - p_x - s_t - h_t);
2557 h = ((unsigned) (p_y + s_t + h_t) >= G_Height (new))
2558 ? 0 : Min ((unsigned)G_PixmapHeight (new),
2559 G_Height (new) - p_y - s_t - h_t);
2560 if (w > 0 && h > 0) {
2562 (XtDisplay (new), G_Pixmap (new), XtWindow (new),
2563 GetMaskGC(new, G_X(new) + p_x, G_Y(new) + p_y),
2565 w, h, G_X (new) + p_x, G_Y (new) + p_y);
2568 /* Draw string with normal or armed background; clip if necessary.
2570 if (draw_string && G_String (new))
2574 unsigned char behavior = G_Behavior (new);
2576 if ((behavior == XmICON_BUTTON ||
2577 behavior == XmICON_DRAG) &&
2578 G_FillOnArm (new) && G_Armed (new))
2579 gc = G_ArmedGC (new);
2580 else if (behavior == XmICON_TOGGLE &&
2581 G_FillOnArm (new) &&
2582 ((G_Armed (new) && !G_Set (new)) ||
2583 (!G_Armed (new) && G_Set (new))))
2584 gc = G_ArmedGC (new);
2586 gc = G_NormalGC (new);
2588 clip.x = G_X (new) + s_x;
2589 clip.y = G_Y (new) + s_y;
2590 clip.width = (s_x + s_t + h_t >=
2591 (unsigned)G_Width (new))
2592 ? 0 : Min ((unsigned)G_StringWidth (new),
2593 G_Width (new) - s_x - s_t - h_t);
2594 clip.height = (s_y + s_t + h_t >=
2595 (unsigned)G_Height (new))
2596 ? 0 : Min ((unsigned)G_StringHeight (new),
2597 G_Height (new) - s_y - s_t - h_t);
2598 if (clip.width > 0 && clip.height > 0)
2600 XmStringDrawImage (XtDisplay (new),
2601 XtWindow (new), G_FontList (new),
2603 G_X (new) + s_x, G_Y (new) + s_y,
2604 clip.width, XmALIGNMENT_CENTER,
2605 XmSTRING_DIRECTION_L_TO_R, &clip);
2607 if (G_Underline(new))
2609 XmStringDrawUnderline (XtDisplay (new),
2610 XtWindow (new), G_FontList (new),
2612 G_X (new) + s_x, G_Y (new) + s_y,
2613 clip.width, XmALIGNMENT_CENTER,
2614 XmSTRING_DIRECTION_L_TO_R, &clip,
2621 if (draw_shadow && G_DrawShadow(new))
2623 if(G_BorderType(new) == DtRECTANGLE || !G_Pixmap(new))
2624 XmeDrawShadows(XtDisplay(new), XtWindow(new),
2625 M_TopShadowGC(MgrParent(new)),
2626 M_BottomShadowGC(MgrParent(new)),
2627 G_X(new) + h_t, G_Y(new) + h_t,
2628 G_Width(new) - 2*h_t, G_Height(new) - 2*h_t,
2629 G_ShadowThickness(new), G_ShadowType(new));
2632 CallCallbackProc call_callback;
2634 call_callback = C_CallCallback(XtClass(new));
2636 (*call_callback) (new, G_Callback (new),
2642 if (G_Operations(current) != G_Operations(new)) {
2643 if (G_Operations(current) == XmDROP_NOOP){
2644 _DtIconRegisterDropsite(new_w);
2646 if (G_Operations(new) == XmDROP_NOOP)
2647 DtDndDropUnregister(new_w);
2651 XtSetArg(args[0], XmNdropSiteOperations, G_Operations(new));
2652 XmDropSiteUpdate(new_w, args, 1);
2657 return (redraw_flag);
2662 /*-------------------------------------------------------------
2664 **-------------------------------------------------------------
2667 /*-------------------------------------------------------------
2672 BorderHighlight( DtIconGadget g)
2675 register int height;
2676 CallCallbackProc call_callback;
2678 width = g->rectangle.width;
2679 height = g->rectangle.height;
2681 if (width == 0 || height == 0) return;
2683 if (g->gadget.highlight_thickness == 0) return;
2685 g->gadget.highlighted = True;
2686 g->gadget.highlight_drawn = True;
2688 if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
2689 HighlightBorder ((Widget)g);
2692 call_callback = C_CallCallback(XtClass(g));
2694 (*call_callback) (g, G_Callback (g), XmCR_HIGHLIGHT, NULL);
2697 /*-------------------------------------------------------------
2698 ** BorderUnhighlight
2702 BorderUnhighlight( DtIconGadget g)
2705 register int window_width;
2706 register int window_height;
2707 register int highlight_width;
2708 CallCallbackProc call_callback;
2710 window_width = g->rectangle.width;
2711 window_height = g->rectangle.height;
2713 if (window_width == 0 || window_height == 0) return;
2715 highlight_width = g->gadget.highlight_thickness;
2716 if (highlight_width == 0) return;
2718 g->gadget.highlighted = False;
2719 g->gadget.highlight_drawn = False;
2721 if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
2722 UnhighlightBorder ((Widget)g);
2725 call_callback = C_CallCallback(XtClass(g));
2727 (*call_callback) (g, G_Callback (g), XmCR_UNHIGHLIGHT, NULL);
2730 /*-------------------------------------------------------------
2740 IconActivate (w, event);
2745 /*-------------------------------------------------------------
2747 ** Process event dispatched from parent or event handler.
2752 XButtonEvent *event,
2755 DtIconGadget g = (DtIconGadget) w;
2757 if (event_mask & XmARM_EVENT || event_mask & XmMULTI_ARM_EVENT)
2758 if (event->button == Button2)
2759 IconDrag (w, (XEvent*) event);
2760 else if (event->button == Button3)
2761 IconPopup (w, (XEvent*) event);
2763 IconArm (w, (XEvent*) event);
2764 else if (event_mask & XmACTIVATE_EVENT ||
2765 event_mask & XmMULTI_ACTIVATE_EVENT)
2767 if (event->button == Button3)
2769 else if (event->x >= G_X (g) &&
2770 event->x <= G_X (g) + (int)G_Width (g) &&
2771 event->y >= G_Y (g) &&
2772 event->y <= G_Y (g) + (int)G_Height (g))
2773 IconActivate (w, (XEvent*) event);
2775 IconDisarm (w, (XEvent*) event);
2777 else if (event_mask & XmHELP_EVENT)
2778 _XmSocorro (w, (XEvent *)event,NULL,NULL);
2779 else if (event_mask & XmENTER_EVENT)
2780 IconEnter (w, (XEvent *)event);
2781 else if (event_mask & XmLEAVE_EVENT)
2782 IconLeave (w, (XEvent *)event);
2783 else if (event_mask & XmFOCUS_IN_EVENT)
2784 _XmFocusInGadget (w, (XEvent *)event,NULL,NULL);
2785 else if (event_mask & XmFOCUS_OUT_EVENT)
2786 _XmFocusOutGadget (w, (XEvent *)event,NULL,NULL);
2791 /*-------------------------------------------------------------
2793 ** Update GCs when parent visuals change.
2801 XmManagerWidget current = (XmManagerWidget) current_w;
2802 XmManagerWidget new = (XmManagerWidget) new_w;
2803 DtIconGadget g = (DtIconGadget) w;
2804 Boolean update = False;
2805 DtIconCacheObjPart local_cache;
2806 UpdateGCsProc update_gcs;
2808 QualifyIconLocalCache(g, &local_cache);
2809 /* If foreground or background was the same as the parent, and parent
2810 ** foreground or background has changed, then update gcs and pixmap.
2812 /* (can't really tell if explicitly set to be same as parent!
2813 ** -- could add flags set in dynamic default procs for fg and bg)
2815 if (G_Foreground (g) == M_Foreground (current) &&
2816 M_Foreground (current) != M_Foreground (new))
2818 local_cache.foreground = M_Foreground (new);
2822 if (G_Background (g) == M_Background (current) &&
2823 M_Background (current) != M_Background (new))
2825 local_cache.background = M_Background (new);
2829 if (G_PixmapForeground (g) == M_Foreground (current) &&
2830 M_Foreground (current) != M_Foreground (new))
2832 G_PixmapForeground(g) = M_Foreground (new);
2836 if (G_PixmapBackground (g) == M_Background (current) &&
2837 M_Background (current) != M_Background (new))
2839 G_PixmapBackground(g) = M_Background (new);
2845 ReCacheIcon_r(&local_cache, g);
2847 update_gcs = C_UpdateGCs(XtClass(g));
2851 if (G_ImageName (g) != NULL)
2853 if (G_Mask(g) != XmUNSPECIFIED_PIXMAP)
2854 XmDestroyPixmap (XtScreen(g),G_Mask(g));
2855 XmDestroyPixmap (XtScreen(w),G_Pixmap (g));
2857 XmGetPixmap (XtScreen (g), G_ImageName (g),
2858 G_PixmapForeground (g),
2859 G_PixmapBackground (g));
2860 if (G_Pixmap (g) != XmUNSPECIFIED_PIXMAP)
2861 G_Mask(g) = (Pixmap)_DtGetMask(XtScreen(g), G_ImageName(g));
2871 /*-------------------------------------------------------------
2873 **-------------------------------------------------------------
2876 /*-------------------------------------------------------------
2886 Dimension s_t = G_ShadowThickness (g),
2887 h_t = G_HighlightThickness (g),
2888 p_w = G_PixmapWidth (g),
2889 p_h = G_PixmapHeight (g),
2890 m_w = G_MarginWidth (g),
2891 m_h = G_MarginHeight (g),
2892 s_w = G_StringWidth (g),
2893 s_h = G_StringHeight (g),
2894 v_pad = 2 * (s_t + h_t + m_h),
2895 h_pad = 2 * (s_t + h_t + m_w),
2896 spacing = G_Spacing (g);
2898 if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
2901 /* Get width and height.
2903 switch ((int) G_PixmapPosition (g))
2906 case XmPIXMAP_BOTTOM:
2907 *w = Max (p_w, s_w) + h_pad;
2908 *h = p_h + s_h + v_pad + spacing;
2911 case XmPIXMAP_RIGHT:
2912 *w = p_w + s_w + h_pad + spacing;
2913 *h = Max (p_h, s_h) + v_pad;
2915 case XmPIXMAP_MIDDLE:
2916 *w = Max (p_w, s_w) + h_pad;
2917 *h = Max (p_h, s_h) + v_pad;
2926 /*-------------------------------------------------------------
2928 ** Get positions of string and pixmap.
2942 Dimension p_w = G_PixmapWidth (g),
2943 p_h = G_PixmapHeight (g),
2944 s_w = G_StringWidth (g),
2945 s_h = G_StringHeight (g),
2946 m_w = G_MarginWidth (g),
2947 m_h = G_MarginHeight (g),
2948 spacing = G_Spacing (g),
2949 h_pad = s_t + h_t + m_w,
2950 v_pad = s_t + h_t + m_h,
2951 width = w - 2 * h_pad,
2952 height = h - 2 * v_pad;
2953 Position p_x = h_pad,
2957 unsigned char align = G_Alignment (g);
2959 if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
2964 switch ((int) G_PixmapPosition (g))
2967 if (align == XmALIGNMENT_CENTER)
2969 if (p_w && width > p_w)
2970 p_x += (width - p_w)/2U;
2971 if (s_w && width > s_w)
2972 s_x += (width - s_w)/2U;
2974 else if (align == XmALIGNMENT_END)
2976 if (p_w && width > p_w)
2978 if (s_w && width > s_w)
2981 if (p_h && ((unsigned)height > p_h + s_h + spacing))
2982 p_y += (height - p_h - s_h - spacing)/2U;
2984 s_y = p_y + p_h + spacing;
2986 s_y += (height - s_h)/2U;
2988 case XmPIXMAP_BOTTOM:
2989 if (align == XmALIGNMENT_CENTER)
2991 if (p_w && width > p_w)
2992 p_x += (width - p_w)/2U;
2993 if (s_w && width > s_w)
2994 s_x += (width - s_w)/2U;
2996 else if (align == XmALIGNMENT_END)
2998 if (p_w && width > p_w)
3000 if (s_w && width > s_w)
3003 if (s_h && ((unsigned)height > p_h + s_h + spacing))
3004 s_y += (height - p_h - s_h - spacing)/2U;
3006 p_y = s_y + s_h + spacing;
3008 p_y += (height - s_h)/2U;
3011 if (p_h && height > p_h)
3012 p_y += (height - p_h)/2U;
3013 s_x += p_w + spacing;
3014 if (s_h && height > s_h)
3015 s_y += (height - s_h)/2U;
3017 case XmPIXMAP_RIGHT:
3018 if (s_h && height > s_h)
3019 s_y += (height - s_h)/2U;
3020 p_x += s_w + spacing;
3021 if (p_h && height > p_h)
3022 p_y += (height - p_h)/2U;
3024 case XmPIXMAP_MIDDLE:
3025 if (p_w && width > p_w)
3026 p_x += (width - p_w)/2U;
3027 if (s_w && width > s_w)
3028 s_x += (width - s_w)/2U;
3029 if (s_h && height > s_h)
3030 s_y += (height - s_h)/2U;
3031 if (p_h && height > p_h)
3032 p_y += (height - p_h)/2U;
3046 /*-------------------------------------------------------------
3048 ** Draw gadget to drawable.
3061 unsigned char s_type,
3062 unsigned char fill_mode )
3064 XmManagerWidget mgr = (XmManagerWidget) XtParent (g);
3065 Display * d = XtDisplay (g);
3068 Position p_x, p_y, s_x, s_y;
3069 Dimension width, height;
3070 unsigned char behavior = G_Behavior (g);
3071 Position adj_x, adj_y;
3072 int rec_width=0,begin=0,diff=0;
3073 GetPositionProc get_positions;
3075 /* Fill with icon or manager background or arm color.
3077 if (G_SavedParentBG(g) != XtParent(g)->core.background_pixel) {
3078 XtReleaseGC((Widget)mgr, G_ParentBackgroundGC(g));
3079 GetParentBackgroundGC(g);
3082 if (fill_mode == XmFILL_SELF)
3084 if ((behavior == XmICON_BUTTON || behavior == XmICON_DRAG) &&
3085 G_FillOnArm (g) && G_Armed (g))
3086 gc = G_ArmedBackgroundGC (g);
3087 else if (behavior == XmICON_TOGGLE && G_FillOnArm (g) &&
3088 ((G_Armed (g) && !G_Set (g)) ||
3089 (!G_Armed (g) && G_Set (g))))
3090 gc = G_ArmedBackgroundGC (g);
3092 gc = G_BackgroundGC (g);
3094 else if (fill_mode == XmFILL_PARENT)
3095 gc = G_ParentBackgroundGC (g);
3097 if ((fill_mode == XmFILL_SELF) || (fill_mode == XmFILL_PARENT))
3098 XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
3099 w - 2 * h_t, h - 2 * h_t);
3101 /* Get pixmap and string positions.
3104 get_positions = C_GetPositions(XtClass(g));
3106 (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
3112 width = (p_x + s_t + h_t >= (unsigned)G_Width (g))
3113 ? 0 : Min ((unsigned)G_PixmapWidth (g),
3114 G_Width (g) - p_x - s_t - h_t);
3115 height = (p_y + s_t + h_t >= (unsigned)G_Height (g))
3116 ? 0 : Min ((unsigned)G_PixmapHeight (g),
3117 G_Height (g) - p_y - s_t - h_t);
3118 if (width > 0 && height > 0)
3120 if (fill_mode == XmFILL_TRANSPARENT)
3122 adj_x = s_t + h_t + G_MarginWidth(g);
3123 adj_y = s_t + h_t + G_MarginHeight(g);
3124 switch (G_PixmapPosition(g))
3127 case XmPIXMAP_BOTTOM:
3128 XFillRectangle(d, drawable,
3129 G_ParentBackgroundGC(g),
3132 width + (2 * adj_y),
3133 height + (2 * adj_x) -
3137 case XmPIXMAP_RIGHT:
3138 XFillRectangle(d, drawable,
3139 G_ParentBackgroundGC(g),
3142 width + (2 * adj_y) -
3144 height + (2 * adj_x));
3146 case XmPIXMAP_MIDDLE:
3147 XFillRectangle(d, drawable,
3148 G_ParentBackgroundGC(g),
3151 width + (2 * adj_y),
3152 height + (2 * adj_x));
3156 XCopyArea (d, G_Pixmap (g), drawable,
3157 GetMaskGC(g, x + p_x, y + p_y),
3158 0, 0, width, height, x + p_x, y + p_y);
3164 if ((behavior == XmICON_BUTTON || behavior == XmICON_DRAG) &&
3165 G_FillOnArm (g) && G_Armed (g))
3167 else if (behavior == XmICON_TOGGLE && G_FillOnArm (g) &&
3168 ((G_Armed (g) && !G_Set (g)) ||
3169 (!G_Armed (g) && G_Set (g))))
3172 gc = G_NormalGC (g);
3178 switch (G_PixmapPosition(g))
3181 case XmPIXMAP_BOTTOM:
3182 clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
3183 ? 0 : Min ((unsigned)G_StringWidth (g),
3185 clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
3186 ? 0 : Min ((unsigned)G_StringHeight (g),
3187 G_Height (g) - s_y - s_t - h_t);
3190 case XmPIXMAP_RIGHT:
3191 clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
3192 ? 0 : Min ((unsigned)G_StringWidth (g),
3193 G_Width (g) - s_x - s_t - h_t);
3194 clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
3195 ? 0 : Min ((unsigned)G_StringHeight (g),
3196 G_Height (g) - s_y);
3198 case XmPIXMAP_MIDDLE:
3199 clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
3200 ? 0 : Min ((unsigned)G_StringWidth (g),
3202 clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
3203 ? 0 : Min ((unsigned)G_StringHeight (g),
3204 G_Height (g) - s_y);
3207 /* Unknown alignment */
3211 if (clip.width > 0 && clip.height > 0)
3213 if (fill_mode == XmFILL_TRANSPARENT)
3215 adj_x = s_t + h_t + G_MarginWidth(g);
3216 adj_y = s_t + h_t + G_MarginHeight(g);
3217 switch (G_PixmapPosition(g))
3220 case XmPIXMAP_BOTTOM:
3221 XFillRectangle(d, drawable,
3222 G_ParentBackgroundGC(g),
3224 clip.y - adj_y + s_t + h_t,
3225 clip.width + (2 * adj_y),
3226 clip.height + (2 * adj_x) -
3229 case XmPIXMAP_RIGHT:
3231 begin = clip.x - adj_x + s_t + h_t;
3232 rec_width = clip.width + (2 * adj_y)
3234 if (G_PixmapPosition(g) == XmPIXMAP_LEFT &&
3235 begin > (int) (x + p_x) &&
3236 begin < (int) (x + p_x + width))
3239 * XmPIXMAP_LEFT -- the rectangle starts
3242 diff = x+p_x+width - begin;
3246 else if(G_PixmapPosition(g) == XmPIXMAP_RIGHT &&
3247 (rec_width+begin) > (x+p_x))
3250 * PIXMAP_RIGHT -- rectangle drawn into
3253 diff = ( rec_width + begin) - (x+p_x);
3257 XFillRectangle(d, drawable,
3258 G_ParentBackgroundGC(g),
3262 clip.height + (2 * adj_x));
3264 case XmPIXMAP_MIDDLE:
3265 XFillRectangle(d, drawable,
3266 G_ParentBackgroundGC(g),
3269 clip.width + (2 * adj_y),
3270 clip.height + (2 * adj_x));
3275 XmStringDrawImage (d, drawable, G_FontList (g),
3276 G_String (g), gc, x + s_x, y + s_y,
3277 clip.width, XmALIGNMENT_BEGINNING,
3278 XmSTRING_DIRECTION_L_TO_R, &clip);
3282 XmStringDrawUnderline (d, drawable, G_FontList (g),
3283 G_String (g), gc, x + s_x, y + s_y,
3284 clip.width, XmALIGNMENT_BEGINNING,
3285 XmSTRING_DIRECTION_L_TO_R, &clip,
3291 /* Potentially fill the area between the label and the pixmap */
3292 if ((fill_mode == XmFILL_TRANSPARENT) && G_Pixmap(g) && G_String(g) &&
3293 (height > 0) && (width > 0) && (clip.width > 0) && (clip.height > 0))
3295 switch (G_PixmapPosition(g))
3298 XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
3299 x + Max(s_x, p_x), y + p_y + height,
3300 Min(clip.width, width),
3301 s_y - (p_y + height));
3304 case XmPIXMAP_BOTTOM:
3305 XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
3306 x + Max(s_x, p_x), y + s_y + clip.height,
3307 Min(clip.width, width),
3308 p_y - (s_y + clip.height));
3311 case XmPIXMAP_RIGHT:
3312 XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
3313 x + s_x + clip.width, y + Max(s_y, p_y),
3314 p_x - (s_x + clip.width),
3315 Min(clip.height, height));
3318 XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
3319 x + p_x + width, y + Max(s_y, p_y),
3320 s_x - (p_x + width),
3321 Min(clip.height, height));
3323 case XmPIXMAP_MIDDLE:
3324 XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
3325 x + Max(s_x, p_x), y + Max(s_y, p_y),
3326 Min(clip.width, width),
3327 Min(clip.height, height));
3335 if (G_ShadowThickness (g) > 0 && G_DrawShadow(g)){
3336 if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
3338 unsigned char shadow_type;
3340 if (((G_Behavior (g) == XmICON_BUTTON) && G_Armed (g)) ||
3341 ((G_Behavior (g) == XmICON_TOGGLE) &&
3342 ((!G_Set (g) && G_Armed (g)) ||
3343 (G_Set (g) && !G_Armed (g)))))
3344 shadow_type = XmSHADOW_IN;
3346 shadow_type = XmSHADOW_OUT;
3348 XmeDrawShadows(d, drawable,
3349 M_TopShadowGC(MgrParent(g)),
3350 M_BottomShadowGC(MgrParent(g)),
3351 x + h_t, y + h_t, w - 2*h_t, h - 2*h_t,
3356 CallCallbackProc call_callback;
3358 call_callback = C_CallCallback(XtClass(g));
3360 (*call_callback) (g, G_Callback (g), XmCR_SHADOW, NULL);
3367 /*-------------------------------------------------------------
3369 ** Call callback, if any, with reason and event.
3378 DtIconCallbackStruct cb_data;
3382 cb_data.reason = reason;
3383 cb_data.event = event;
3384 cb_data.set = G_Set (g);
3385 XtCallCallbackList ((Widget) g, cb, &cb_data);
3393 /*-------------------------------------------------------------
3395 ** Get normal and background graphics contexts.
3396 ** Use standard mask to maximize caching opportunities.
3403 XtGCMask value_mask;
3404 XmManagerWidget mw = (XmManagerWidget) XtParent(g);
3408 XtReleaseGC ((Widget)mw, G_NormalGC (g));
3410 XtReleaseGC ((Widget)mw, G_ClipGC (g));
3411 if (G_BackgroundGC (g))
3412 XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
3414 XtReleaseGC ((Widget)mw, G_ArmedGC (g));
3415 if (G_ArmedBackgroundGC (g))
3416 XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
3420 value_mask = GCForeground | GCBackground | GCFillStyle;
3421 values.foreground = G_Foreground (g);
3422 values.background = G_Background (g);
3423 values.fill_style = FillSolid;
3424 if (XmeRenderTableGetDefaultFont(G_FontList (g), &font)) {
3425 value_mask |= GCFont;
3426 values.font = font->fid;
3428 G_NormalGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
3430 /* Get background GC.
3432 values.foreground = G_Background (g);
3433 values.background = G_Foreground (g);
3434 G_BackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
3438 values.foreground = G_Foreground (g);
3439 values.background = G_ArmColor (g);
3440 G_ArmedGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
3442 /* Get armed background GC.
3444 values.foreground = G_ArmColor (g);
3445 values.background = G_Background (g);
3446 G_ArmedBackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
3448 if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
3449 value_mask |= GCClipMask;
3450 values.clip_mask = G_Mask(g);
3451 values.foreground = G_Foreground (g);
3452 values.background = G_Background (g);
3453 G_ClipGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
3456 G_ClipGC (g) = NULL;
3460 /*-------------------------------------------------------------
3461 ** GetIconClassSecResData ( )
3462 ** Class function to be called to copy secondary resource
3463 ** for external use. i.e. copy the cached resources and
3465 **-------------------------------------------------------------
3469 GetIconClassSecResData(
3471 XmSecondaryResourceData **data_rtn )
3472 { int arrayCount = 0;
3473 XmBaseClassExt bcePtr;
3474 String resource_class, resource_name;
3475 XtPointer client_data;
3478 bcePtr = &( iconBaseClassExtRec);
3480 resource_class = NULL;
3481 resource_name = NULL;
3483 _XmSecondaryResourceData ( bcePtr, data_rtn, client_data,
3484 resource_name, resource_class,
3485 (XmResourceBaseProc) (GetIconClassResBase));
3488 return (arrayCount);
3492 /*-------------------------------------------------------------
3493 ** GetIconClassResBase ()
3494 ** return the address of the base of resources.
3495 ** - Not yet implemented.
3496 **-------------------------------------------------------------
3500 GetIconClassResBase(
3502 XtPointer client_data )
3503 { XtPointer widgetSecdataPtr;
3504 int icon_cache_size = sizeof (DtIconCacheObjPart);
3507 widgetSecdataPtr = (XtPointer) (XtMalloc ( icon_cache_size +1));
3509 if (widgetSecdataPtr)
3511 cp = (char *) widgetSecdataPtr;
3514 bcopy ( (char *) ( Icon_Cache(widget)), (char *) cp, icon_cache_size);
3516 memmove ( (char *)cp , (char *) ( Icon_Cache(widget)), icon_cache_size);
3520 return (widgetSecdataPtr);
3525 /*-------------------------------------------------------------
3526 ** Public Entry Points
3527 **-------------------------------------------------------------
3530 /*-------------------------------------------------------------
3532 ** Create a new gadget instance.
3533 **-------------------------------------------------------------
3542 return (XtCreateWidget (name, dtIconGadgetClass,
3543 parent, arglist, argcount));
3548 /*-------------------------------------------------------------
3550 ** Return state of Icon.
3551 **-------------------------------------------------------------
3557 DtIconGadget g = (DtIconGadget) w;
3563 /*-------------------------------------------------------------
3565 ** Set state of Icon.
3566 **-------------------------------------------------------------
3574 DtIconGadget g = (DtIconGadget) w;
3575 CallCallbackProc call_callback;
3576 XtExposeProc expose;
3578 if (G_Behavior (g) != XmICON_TOGGLE || state == G_Set (g))
3582 call_callback = C_CallCallback(XtClass(g));
3583 expose = XtCoreProc(w, expose);
3587 (*expose) ((Widget)g, NULL, NULL);
3591 (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, NULL);
3597 /*-------------------------------------------------------------
3599 ** Render gadget to drawable without highlight.
3600 **-------------------------------------------------------------
3610 DtIconGadget g = (DtIconGadget) widget;
3611 Dimension h_t = G_HighlightThickness (g),
3612 w = G_Width (g) - 2 * h_t,
3613 h = G_Height (g) - 2 * h_t;
3614 unsigned char fill_mode;
3617 if (!drawable || drawable == XmUNSPECIFIED_PIXMAP)
3618 drawable = (Drawable)
3619 XCreatePixmap (XtDisplay (g),
3620 RootWindowOfScreen (XtScreen (g)),
3621 w, h, DefaultDepthOfScreen (XtScreen (g)));
3623 fill_mode = (fill) ? XmFILL_SELF : XmFILL_PARENT;
3626 draw = C_Draw(XtClass(g));
3628 (*draw) (g, drawable, x, y, w, h,
3629 0, G_ShadowThickness (g), G_ShadowType (g), fill_mode);
3636 /***************************************************************************/
3640 * Load the specified pixmap.
3649 unsigned int int_h, int_w;
3650 Screen *s = XtScreen(new);
3651 Pixmap pm = XmGetPixmap(s, pixmap, G_PixmapForeground(new),
3652 G_PixmapBackground(new));
3655 if (pm == XmUNSPECIFIED_PIXMAP)
3658 mask = XmeGetMask(s, pixmap);
3662 G_ImageName(new) = XtNewString(pixmap);
3664 XmeGetPixmapData(s, pm, NULL, NULL, NULL, NULL, NULL, NULL, &int_w, &int_h);
3665 G_PixmapWidth(new) = Limit((Dimension)int_w, G_MaxPixmapWidth(new));
3666 G_PixmapHeight(new) = Limit((Dimension)int_h, G_MaxPixmapWidth(new));
3678 XtPointer user_data,
3681 DtIconGadget gadget;
3685 DtIconCacheObjPart local_cache;
3686 XtWidgetProc insert_child;
3687 GetSizeProc get_size;
3689 /* Create the new instance structure */
3690 gadget = (DtIconGadget) widget;
3692 size = XtClass(gadget)->core_class.widget_size;
3694 new = (DtIconGadget)XtMalloc(size);
3696 /* Copy the master into the duplicate */
3699 bcopy((char *)gadget, (char *)new, (int)size);
3701 memmove((char *)new, (char *)gadget, (int)size);
3706 ((CompositeWidgetClass)XtClass(parent))->composite_class.insert_child;
3707 get_size = C_GetSize(XtClass(new));
3708 Icon_Cache(new) = (DtIconCacheObjPart *)
3709 _XmCachePart(Icon_ClassCachePart(new),
3710 (XtPointer) Icon_Cache(new),
3711 sizeof(DtIconCacheObjPart));
3714 /* Certain fields need to be updated */
3715 new->object.parent = parent;
3716 new->object.self = (Widget)new;
3717 G_FontList(new) = XmFontListCopy(G_FontList(gadget));
3719 /* Certain fields should not be inherited by the clone */
3720 new->object.destroy_callbacks = NULL;
3721 new->object.constraints = NULL;
3722 new->gadget.help_callback = NULL;
3723 new->icon.drop_callback = NULL;
3724 new->rectangle.managed = False;
3725 G_Callback(new) = NULL;
3727 /* Set the user_data field */
3728 new->gadget.user_data = user_data;
3730 /* Process the optional pixmap name */
3731 if ((pixmap == NULL) || LoadPixmap(new, pixmap))
3733 /* No pixmap to load */
3734 G_ImageName(new) = NULL;
3735 G_Pixmap(new) = None;
3736 G_PixmapWidth(new) = 0;
3737 G_PixmapHeight(new) = 0;
3740 /* Process the required label string */
3741 G_String(new) = XmStringCopy(string);
3742 XmStringExtent(G_FontList(new), G_String(new), &w, &h);
3743 G_Underline(new) = underline;
3744 if (G_Underline(new))
3746 G_StringWidth(new) = w;
3747 QualifyIconLocalCache(new, &local_cache);
3748 local_cache.string_height = h;
3750 ReCacheIcon_r(&local_cache, new);
3752 /* Get copies of the GC's */
3753 G_NormalGC(new) = NULL;
3754 G_BackgroundGC(new) = NULL;
3755 G_ArmedGC(new) = NULL;
3756 G_ArmedBackgroundGC(new) = NULL;
3757 G_ClipGC(new) = NULL;
3760 /* Size the gadget */
3761 (*get_size) (new, &w, &h);
3765 /* Insert the duplicate into the parent's child list */
3766 (*insert_child) ((Widget)new);
3768 return ((Widget) new);
3773 _DtIconSelectInTitle(
3779 DtIconGadget g = (DtIconGadget) widget;
3781 Dimension w, h, h_t, s_t;
3783 Position p_x, p_y, s_x, s_y;
3784 GetPositionProc get_positions;
3787 s_t = G_ShadowThickness(g);
3793 get_positions = C_GetPositions(XtClass(g));
3795 (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
3801 clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
3802 ? 0 : Min ((unsigned)G_StringWidth (g),
3803 G_Width (g) - s_x - s_t - h_t);
3804 clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
3805 ? 0 : Min ((unsigned)G_StringHeight (g),
3806 G_Height (g) - s_y - s_t - h_t);
3807 if (clip.width <= 0 || clip.height <= 0)
3811 if ((pt_x >= clip.x) &&
3813 ((unsigned)pt_x <= clip.x + clip.width) &&
3814 ((unsigned)pt_y <= clip.y + clip.height))
3826 * Thread-safe variant of _DtIconGetTextExtent.
3829 _DtIconGetTextExtent_r(Widget widget,
3832 DtIconGadget g = (DtIconGadget) widget;
3834 Dimension w, h, h_t, s_t;
3835 Position p_x, p_y, s_x, s_y;
3836 GetPositionProc get_positions;
3839 s_t = G_ShadowThickness(g);
3845 get_positions = C_GetPositions(XtClass(g));
3847 (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
3853 clip->width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
3854 ? 0 : Min ((unsigned)G_StringWidth (g),
3855 G_Width (g) - s_x - s_t - h_t);
3856 clip->height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
3857 ? 0 : Min ((unsigned)G_StringHeight (g),
3858 G_Height (g) - s_y - s_t - h_t);
3860 if (clip->width <= 0)
3863 if (clip->height <= 0)
3877 * Returns a pointer to a static storage area; must not be freed.
3878 * This interface is deprecated in favor of _DtIconGetTextExtent_r.
3882 _DtIconGetTextExtent(
3886 static XRectangle clip;
3888 _DtIconGetTextExtent_r(widget, &clip);
3893 /*-------------------------------------------------------------
3894 ** _DtIconGetIconRects
3895 ** Returns rects occupied by label and pixmap
3898 _DtIconGetIconRects(
3900 unsigned char *flags,
3905 Position p_x, p_y, s_x, s_y;
3906 Dimension width, height;
3907 Position adj_x, adj_y;
3909 GetPositionProc get_positions;
3911 h_t = G_HighlightThickness(g);
3912 s_t = G_ShadowThickness(g);
3914 adj_x = G_MarginWidth(g);
3915 adj_y = G_MarginHeight(g);
3917 get_positions = C_GetPositions(XtClass(g));
3919 (*get_positions) (g, G_Width(g), G_Height(g), h_t, s_t, &p_x, &p_y, &s_x, &s_y);
3924 width = (p_x + s_t + h_t >= (unsigned)G_Width (g)) ? 0 :
3925 Min ((unsigned)G_PixmapWidth (g),
3926 G_Width (g) - p_x - s_t - h_t);
3927 height = (p_y + s_t + h_t >= (unsigned)G_Height (g)) ? 0 :
3928 Min ((unsigned)G_PixmapHeight (g),
3929 G_Height (g) - p_y - s_t - h_t);
3930 if (width > 0 && height > 0)
3932 rect1->x = G_X(g) + p_x - adj_x;
3933 rect1->y = G_Y(g) + p_y - adj_y;
3934 rect1->width = width + (2 * adj_y);
3935 rect1->height = height + (2 * adj_x);
3936 *flags |= XmPIXMAP_RECT;
3942 width = (s_x + s_t + h_t >= (unsigned)G_Width (g)) ? 0 :
3943 Min ((unsigned)G_StringWidth (g), G_Width (g) - s_x - s_t - h_t);
3944 height = (s_y + s_t + h_t >= (unsigned)G_Height (g)) ? 0 :
3945 Min ((unsigned)G_StringHeight (g), G_Height (g) - s_y - s_t - h_t);
3946 if (width > 0 && height > 0)
3948 rect2->x = G_X(g) + s_x - adj_x;
3949 rect2->y = G_Y(g) + s_y - adj_y;
3950 rect2->width = width + (2 * adj_y);
3951 rect2->height = height + (2 * adj_x);
3952 *flags |= XmLABEL_RECT;
3958 /* Do animation when everything is completed.
3959 * Note: DropDestroy callback is the only notification after the melt has
3965 XtPointer clientData,
3966 XtPointer callData )
3968 DtIconGadget g = (DtIconGadget) w;
3970 if (G_DropCallback(g)) {
3971 XtCallCallbackList(w, G_DropCallback(g), callData);
3979 XtPointer clientData,
3980 XtPointer callData )
3982 DtDndTransferCallback call_data = (DtDndTransferCallback) callData;
3983 DtIconGadget g = (DtIconGadget) w;
3985 call_data->x += G_X(g);
3986 call_data->y += G_Y(g);
3988 if (G_DropCallback(g)) {
3989 XtCallCallbackList(w, G_DropCallback(g), callData);
3993 /*-------------------------------------------------------------
3994 ** _DtIconRegisterDropsite
3995 ** Registers the Icon as a dropsite.
3998 _DtIconRegisterDropsite(
4002 XtCallbackRec transferCB[] = { {TransferCallback, NULL}, {NULL, NULL} };
4003 XtCallbackRec animateCB[] = { {AnimateCallback, NULL}, {NULL, NULL} };
4004 DtIconGadget g = (DtIconGadget) w;
4005 XRectangle rects[2];
4006 unsigned char flags;
4011 _DtIconGetIconRects(g, &flags, &rects[0], &rects[1]);
4013 if (flags & XmPIXMAP_RECT) {
4014 rects[0].x -= G_X(g);
4015 rects[0].y -= G_Y(g);
4019 if (flags & XmLABEL_RECT) {
4020 rects[1].x -= G_X(g);
4021 rects[1].y -= G_Y(g);
4022 if (!numRects) rects[0] = rects[1];
4028 XtSetArg(args[n], XmNdropRectangles, rects); n++;
4029 XtSetArg(args[n], XmNnumDropRectangles, numRects); n++;
4031 XtSetArg(args[n], XmNanimationStyle, XmDRAG_UNDER_SHADOW_IN); n++;
4032 XtSetArg(args[n], DtNtextIsBuffer, True); n++;
4033 XtSetArg(args[n], DtNdropAnimateCallback, animateCB); n++;
4035 DtDndDropRegister(w, DtDND_FILENAME_TRANSFER|DtDND_BUFFER_TRANSFER,
4036 G_Operations(g), transferCB,