/cde/lib/DtWidget/Icon.c
C | 1818 lines | 1319 code | 215 blank | 284 comment | 138 complexity | 726053066a2e2a8586dbff44b9d6b843 MD5 | raw file
Possible License(s): LGPL-2.1, IPL-1.0, 0BSD
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $TOG: Icon.c /main/20 1999/09/08 10:44:52 mgreess $
- *
- * (c) Copyright 1996 Digital Equipment Corporation.
- * (c) Copyright 1990,1996 Hewlett-Packard Company.
- * (c) Copyright 1996 International Business Machines Corp.
- * (c) Copyright 1996 Sun Microsystems, Inc.
- * (c) Copyright 1996 Novell, Inc.
- * (c) Copyright 1996 FUJITSU LIMITED.
- * (c) Copyright 1996 Hitachi.
- */
- /**---------------------------------------------------------------------
- ***
- *** file: Icon.c
- ***
- *** project: MotifPlus Widgets
- ***
- *** description: Source code for DtIconGadget class.
- ***
- ***-------------------------------------------------------------------*/
- /*-------------------------------------------------------------
- ** Include Files
- */
- #include <stdio.h>
- #ifdef __apollo
- #include <sys/types.h>
- #endif
- #include <sys/stat.h>
- #include <X11/Xatom.h>
- #include <Xm/XmP.h>
- #include <Xm/CacheP.h>
- #include <Xm/ManagerP.h>
- #include <Xm/PrimitiveP.h>
- #include <Xm/DrawP.h>
- #include <Dt/IconP.h>
- #include <Dt/MacrosP.h>
- #include <Dt/DtMsgsP.h>
- #include <Dt/Dnd.h>
- #include "DtWidgetI.h"
- /*-------------------------------------------------------------
- ** Public Interface
- **-------------------------------------------------------------
- */
- WidgetClass dtIconGadgetClass;
- #define Min(x, y) (((x) < (y)) ? (x) : (y))
- #define Max(x, y) (((x) > (y)) ? (x) : (y))
- #define Limit(x, lim) (((lim) == 0 || (x) <= (lim))? (x): (lim))
- /*-------------------------------------------------------------
- ** Forward Declarations
- */
- extern void _DtRegisterNewConverters ( void );
- extern char * _XmExtObjAlloc(int size);
- extern void _XmExtObjFree(XtPointer element);
- extern void _XmSelectColorDefault ( Widget, int, XrmValue * );
- #define SPACING_DEFAULT 2
- #define MARGIN_DEFAULT 2
- #define UNSPECIFIED_DIMENSION 9999
- #define UNSPECIFIED_CHAR 255
- #define WARN_ALIGNMENT _DtMsgIcon_0000
- #define WARN_BEHAVIOR _DtMsgIcon_0001
- #define WARN_FILL_MODE _DtMsgIcon_0002
- #define WARN_PIXMAP_POSITION _DtMsgIcon_0003
- #define WARN_MARGIN _DtMsgIcon_0004
- #define WARN_SHADOW_TYPE _DtMsgIcon_0005
- #define MgrParent(g) ((XmManagerWidget) (XmIsManager(XtParent(g)) ? (XtParent(g)) : (XtParent(XtParent(g)))))
- /******** Private Function Declarations ********/
- extern void _DtIconRegisterDropsite(
- Widget w) ;
- /******** End Private Function Declarations ********/
- /******** Static Function Declarations ********/
- static int IconCacheCompare(
- XtPointer A,
- XtPointer B) ;
- static void ReCacheIcon_r(
- DtIconCacheObjPart *cache,
- DtIconGadget g);
- static void GetDefaultBackground(
- Widget g,
- int offset,
- XrmValue *value) ;
- static void GetDefaultForeground(
- Widget g,
- int offset,
- XrmValue *value) ;
- static void GetDefaultFillMode(
- Widget w,
- int offset,
- XrmValue *value) ;
- static void GetSpacing(
- Widget w,
- int offset,
- XtArgVal *value) ;
- static void GetString(
- Widget w,
- int offset,
- XtArgVal *value) ;
- static void IconEventHandler(
- Widget w,
- XtPointer client_data,
- XButtonEvent *event) ;
- static void ClickTimeout(
- Widget w,
- XtIntervalId *id) ;
- static void IconArm(
- Widget w,
- XEvent *event) ;
- static void IconDisarm(
- Widget w,
- XEvent *event) ;
- static void IconActivate(
- Widget w,
- XEvent *event) ;
- static void IconDrag(
- Widget w,
- XEvent *event) ;
- static void IconPopup(
- Widget w,
- XEvent *event) ;
- static void IconEnter(
- Widget w,
- XEvent *event) ;
- static void IconLeave(
- Widget w,
- XEvent *event) ;
- static void ClassInitialize( void ) ;
- static void SecondaryObjectCreate(
- Widget req,
- Widget new_w,
- ArgList args,
- Cardinal *num_args) ;
- static void InitializePosthook(
- Widget req,
- Widget new,
- ArgList args,
- Cardinal *num_args) ;
- static Boolean SetValuesPrehook(
- Widget oldParent,
- Widget refParent,
- Widget newParent,
- ArgList args,
- Cardinal *num_args) ;
- static void GetValuesPrehook(
- Widget newParent,
- ArgList args,
- Cardinal *num_args) ;
- static void GetValuesPosthook(
- Widget new,
- ArgList args,
- Cardinal *num_args) ;
- static Boolean SetValuesPosthook(
- Widget current,
- Widget req,
- Widget new,
- ArgList args,
- Cardinal *num_args) ;
- static void QualifyIconLocalCache(
- DtIconGadget g,
- DtIconCacheObjPart *cache);
- static void Initialize(
- Widget request_w,
- Widget new_w) ;
- static void Destroy(
- Widget w) ;
- static void Resize(
- Widget w) ;
- static void Redisplay(
- Widget w,
- XEvent *event,
- Region region) ;
- static Boolean SetValues(
- Widget current_w,
- Widget request_w,
- Widget new_w) ;
- static void BorderHighlight(
- DtIconGadget g) ;
- static void BorderUnhighlight(
- DtIconGadget g) ;
- static void ArmAndActivate(
- Widget w,
- XEvent *event) ;
- static void InputDispatch(
- Widget w,
- XButtonEvent *event,
- Mask event_mask) ;
- static Boolean VisualChange(
- Widget w,
- Widget current_w,
- Widget new_w) ;
- static void GetSize(
- DtIconGadget g,
- Dimension *w,
- Dimension *h) ;
- static void GetPositions(
- DtIconGadget g,
- Position w,
- Position h,
- Dimension h_t,
- Dimension s_t,
- Position *pix_x,
- Position *pix_y,
- Position *str_x,
- Position *str_y) ;
- static void Draw(
- DtIconGadget g,
- Drawable drawable,
- Position x,
- Position y,
- Dimension w,
- Dimension h,
- Dimension h_t,
- Dimension s_t,
- unsigned char s_type,
- unsigned char fill_mode) ;
- static void CallCallback(
- DtIconGadget g,
- XtCallbackList cb,
- int reason,
- XEvent *event) ;
- static void UpdateGCs(
- DtIconGadget g) ;
- static Cardinal GetIconClassSecResData(
- WidgetClass class,
- XmSecondaryResourceData **data_rtn) ;
- static XtPointer GetIconClassResBase(
- Widget widget,
- XtPointer client_data) ;
- static Boolean LoadPixmap(
- DtIconGadget new,
- String pixmap) ;
- static void ClassPartInitialize ( WidgetClass wc);
- static void HighlightBorder( Widget w );
- static void UnhighlightBorder( Widget w );
- /******** End Static Function Declarations ********/
- /* External Cache Procs
- */
- extern void _XmCacheDelete( XtPointer data );
- extern void _XmCacheCopy( XtPointer src, XtPointer dest, size_t size );
- extern Cardinal _XmSecondaryResourceData( XmBaseClassExt, XmSecondaryResourceData **,
- XtPointer, String, String, XmResourceBaseProc);
- extern XtPointer _XmCachePart( XmCacheClassPartPtr cp, XtPointer cpart, size_t size );
- /*-------------------------------------------------------------
- ** Resource List
- */
- #define I_Offset(field) \
- XtOffset (DtIconGadget, icon.field)
- #define I_Cache_Offset(field) \
- XtOffset (DtIconCacheObject, icon_cache.field)
- static XtResource resources[] =
- {
- {
- XmNset,
- XmCSet, XmRBoolean, sizeof (Boolean),
- I_Offset (set), XmRImmediate, (XtPointer) False
- },
- {
- XmNshadowType,
- XmCShadowType, XmRShadowType, sizeof (unsigned char),
- I_Offset (shadow_type),
- XmRImmediate, (XtPointer) XmSHADOW_ETCHED_OUT
- },
- {
- XmNborderType,
- XmCBorderType, XmRBorderType, sizeof (unsigned char),
- I_Offset (border_type),
- XmRImmediate, (XtPointer) DtRECTANGLE
- },
- {
- XmNcallback,
- XmCCallback, XmRCallback, sizeof (XtCallbackList),
- I_Offset (callback), XmRImmediate, (XtPointer) NULL
- },
- {
- XmNfontList,
- XmCFontList, XmRFontList, sizeof (XmFontList),
- I_Offset (font_list), XmRString, "Fixed"
- },
- {
- XmNimageName,
- XmCString, XmRString, sizeof (XmString),
- I_Offset (image_name), XmRImmediate, (XtPointer) NULL
- },
- {
- XmNpixmap,
- XmCPixmap, XmRPixmap, sizeof (Pixmap),
- I_Offset (pixmap),
- XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
- },
- {
- XmNstring,
- XmCXmString, XmRXmString, sizeof (XmString),
- I_Offset (string),
- XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
- },
- {
- XmNpixmapForeground,
- XmCForeground, XmRPixel, sizeof (Pixel),
- I_Offset (pixmap_foreground),
- XmRCallProc, (XtPointer) GetDefaultForeground
- },
- {
- XmNpixmapBackground,
- XmCBackground, XmRPixel, sizeof (Pixel),
- I_Offset (pixmap_background),
- XmRCallProc, (XtPointer) GetDefaultBackground
- },
- {
- XmNmaxPixmapWidth,
- XmCMaxWidth, XmRHorizontalDimension, sizeof (Dimension),
- I_Offset (max_pixmap_width), XmRImmediate, (XtPointer) 0
- },
- {
- XmNmaxPixmapHeight,
- XmCMaxHeight, XmRVerticalDimension, sizeof (Dimension),
- I_Offset (max_pixmap_height), XmRImmediate, (XtPointer) 0
- },
- {
- XmNunderline,
- XmCUnderline, XmRBoolean, sizeof (Boolean),
- I_Offset (underline), XmRImmediate, (XtPointer) False
- },
- {
- XmNdropSiteOperations, XmCDropSiteOperations,
- XmRDropSiteOperations, sizeof(unsigned char),
- I_Offset(operations), XmRImmediate, (XtPointer) XmDROP_NOOP
- },
- {
- XmNdropCallback,
- XmCDropCallback, XmRCallback, sizeof (XtCallbackList),
- I_Offset (drop_callback), XmRImmediate, (XtPointer) NULL
- }
- };
- static XtResource cache_resources[] =
- {
- {
- XmNbehavior,
- XmCBehavior, XmRBehavior, sizeof (unsigned char),
- I_Cache_Offset (behavior),
- XmRImmediate, (XtPointer) XmICON_BUTTON
- },
- {
- XmNrecomputeSize,
- XmCRecomputeSize, XmRBoolean, sizeof (Boolean),
- I_Cache_Offset (recompute_size), XmRImmediate, (XtPointer) True
- },
- {
- "drawShadow",
- "DrawShadow", XmRBoolean, sizeof (Boolean),
- I_Cache_Offset (draw_shadow), XmRImmediate, (XtPointer) False
- },
- {
- XmNfillOnArm,
- XmCFillOnArm, XmRBoolean, sizeof (Boolean),
- I_Cache_Offset (fill_on_arm), XmRImmediate, (XtPointer) True
- },
- {
- XmNforeground,
- XmCForeground, XmRPixel, sizeof (Pixel),
- I_Cache_Offset (foreground),
- XmRCallProc, (XtPointer) GetDefaultForeground
- },
- {
- XmNbackground,
- XmCBackground, XmRPixel, sizeof (Pixel),
- I_Cache_Offset (background),
- XmRCallProc, (XtPointer) GetDefaultBackground
- },
- {
- XmNarmColor,
- XmCArmColor, XmRPixel, sizeof (Pixel),
- I_Cache_Offset (arm_color),
- XmRCallProc, (XtPointer) _XmSelectColorDefault
- },
- {
- XmNspacing,
- XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
- I_Cache_Offset (spacing),
- XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
- },
- {
- XmNmarginHeight,
- XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
- I_Cache_Offset (margin_height),
- XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
- },
- {
- XmNmarginWidth,
- XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
- I_Cache_Offset (margin_width),
- XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
- },
- {
- XmNpixmapPosition,
- XmCPixmapPosition, XmRPixmapPosition, sizeof (unsigned char),
- I_Cache_Offset (pixmap_position),
- XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
- },
- {
- XmNstringPosition,
- XmCStringPosition, XmRStringPosition, sizeof (unsigned char),
- I_Cache_Offset (string_position),
- XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
- },
- {
- XmNalignment,
- XmCAlignment, XmRAlignment, sizeof (unsigned char),
- I_Cache_Offset (alignment),
- XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
- },
- {
- XmNfillMode,
- XmCFillMode, XmRFillMode, sizeof (unsigned char),
- I_Cache_Offset (fill_mode),
- XmRCallProc, (XtPointer) GetDefaultFillMode
- }
- };
- static XmSyntheticResource syn_resources[] =
- {
- {
- XmNstring, sizeof (XmString),
- I_Offset (string), GetString,
- (XmImportProc) NULL
- },
- };
- static XmSyntheticResource cache_syn_resources[] =
- {
- {
- XmNspacing, sizeof (Dimension),
- I_Cache_Offset (spacing), GetSpacing,
- (XmImportProc) NULL
- },
- {
- XmNmarginWidth, sizeof (Dimension),
- I_Cache_Offset (margin_width),
- XmeFromHorizontalPixels,
- (XmImportProc)XmeToHorizontalPixels
- },
- {
- XmNmarginHeight, sizeof (Dimension),
- I_Cache_Offset (margin_height),
- XmeFromVerticalPixels,
- (XmImportProc)XmeToVerticalPixels,
- }
- };
- #undef I_Offset
- #undef I_Cache_Offset
-
- /*-------------------------------------------------------------
- ** Cache Class Record
- */
- static XmCacheClassPart IconClassCachePart = {
- {NULL, 0, 0}, /* head of class cache list */
- _XmCacheCopy, /* Copy routine */
- _XmCacheDelete, /* Delete routine */
- IconCacheCompare, /* Comparison routine */
- };
- /*-------------------------------------------------------------
- ** Base Class Extension Record
- */
- static XmBaseClassExtRec iconBaseClassExtRec = {
- NULL, /* Next extension */
- NULLQUARK, /* record type XmQmotif */
- XmBaseClassExtVersion, /* version */
- sizeof(XmBaseClassExtRec), /* size */
- XmInheritInitializePrehook, /* initialize prehook */
- SetValuesPrehook, /* set_values prehook */
- InitializePosthook, /* initialize posthook */
- SetValuesPosthook, /* set_values posthook */
- (WidgetClass)&dtIconCacheObjClassRec, /* secondary class */
- (XtInitProc)SecondaryObjectCreate, /* creation proc */
- (XmGetSecResDataFunc) GetIconClassSecResData, /* getSecResData */
- {NULL}, /* fast subclass */
- GetValuesPrehook, /* get_values prehook */
- GetValuesPosthook, /* get_values posthook */
- NULL, /* classPartInitPrehook */
- NULL, /* classPartInitPosthook*/
- NULL, /* ext_resources */
- NULL, /* compiled_ext_resources*/
- 0, /* num_ext_resources */
- FALSE, /* use_sub_resources */
- XmInheritWidgetNavigable, /* widgetNavigable */
- XmInheritFocusChange, /* focusChange */
- };
- /*-------------------------------------------------------------
- ** Icon Cache Object Class Record
- */
- externaldef (dticoncacheobjclassrec)
- DtIconCacheObjClassRec dtIconCacheObjClassRec =
- {
- {
- /* superclass */ (WidgetClass) &xmExtClassRec,
- /* class_name */ "DtIcon",
- /* widget_size */ sizeof(DtIconCacheObjRec),
- /* class_initialize */ NULL,
- /* chained class init */ NULL,
- /* class_inited */ False,
- /* initialize */ NULL,
- /* initialize hook */ NULL,
- /* realize */ NULL,
- /* actions */ NULL,
- /* num_actions */ 0,
- /* resources */ cache_resources,
- /* num_resources */ XtNumber(cache_resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ False,
- /* compress_exposure */ False,
- /* compress enter/exit*/ False,
- /* visible_interest */ False,
- /* destroy */ NULL,
- /* resize */ NULL,
- /* expose */ NULL,
- /* set_values */ NULL,
- /* set values hook */ NULL,
- /* set values almost */ NULL,
- /* get values hook */ NULL,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback offsetlst */ NULL,
- /* default trans */ NULL,
- /* query geo proc */ NULL,
- /* display accelerator*/ NULL,
- /* extension record */ NULL,
- },
- {
- /* synthetic resources */ cache_syn_resources,
- /* num_syn_resources */ XtNumber(cache_syn_resources),
- /* extension */ NULL,
- },
- };
- /*-------------------------------------------------------------
- ** Class Record
- */
- externaldef (dticonclassrec)
- DtIconClassRec dtIconClassRec =
- {
- /* Core Part
- */
- {
- (WidgetClass) &xmGadgetClassRec, /* superclass */
- "DtIcon", /* class_name */
- sizeof (DtIconRec), /* widget_size */
- ClassInitialize, /* class_initialize */
- ClassPartInitialize, /* class_part_initialize*/
- False, /* class_inited */
- (XtInitProc) Initialize, /* initialize */
- NULL, /* initialize_hook */
- NULL, /* realize */
- NULL, /* actions */
- 0, /* num_actions */
- resources, /* resources */
- XtNumber (resources), /* num_resources */
- NULLQUARK, /* xrm_class */
- True, /* compress_motion */
- True, /* compress_exposure */
- True, /* compress_enterleave */
- False, /* visible_interest */
- (XtWidgetProc) Destroy, /* destroy */
- (XtWidgetProc) Resize, /* resize */
- (XtExposeProc) Redisplay, /* expose */
- (XtSetValuesFunc) SetValues, /* set_values */
- NULL, /* set_values_hook */
- XtInheritSetValuesAlmost, /* set_values_almost */
- NULL, /* get_values_hook */
- NULL, /* accept_focus */
- XtVersion, /* version */
- NULL, /* callback private */
- NULL, /* tm_table */
- NULL, /* query_geometry */
- NULL, /* display_accelerator */
- (XtPointer)&iconBaseClassExtRec,/* extension */
- },
- /* XmGadget Part
- */
- {
- (XtWidgetProc) BorderHighlight, /* border_highlight */
- (XtWidgetProc) BorderUnhighlight, /* border_unhighlight */
- (XtActionProc) ArmAndActivate, /* arm_and_activate */
- (XmWidgetDispatchProc) InputDispatch, /* input_dispatch */
- (XmVisualChangeProc) VisualChange, /* visual_change */
- syn_resources, /* get_resources */
- XtNumber (syn_resources), /* num_get_resources */
- &IconClassCachePart, /* class_cache_part */
- NULL, /* extension */
- },
- /* DtIconGadget Part
- */
- {
- GetSize, /* get_size */
- GetPositions, /* get_positions */
- Draw, /* draw */
- CallCallback, /* call_callback */
- UpdateGCs, /* update_gcs */
- True, /* optimize_redraw */
- NULL, /* class_cache_part */
- NULL, /* extension */
- }
- };
- externaldef (dticongadgetclass) WidgetClass dtIconGadgetClass = (WidgetClass) &dtIconClassRec;
- /*-------------------------------------------------------------
- ** Private Functions
- **-------------------------------------------------------------
- */
- /************************************************************************
- *
- * The border highlighting and unhighlighting routines.
- *
- * These routines were originally in Obsolete.c but can not depend
- * on these routines to live forever. Therefore, copied into my
- * own space.
- *
- ************************************************************************/
- static void
- HighlightBorder(
- Widget w )
- {
- XtWidgetProc border_highlight;
- if (XmIsPrimitive(w)) {
- _DtProcessLock();
- border_highlight = xmPrimitiveClassRec.primitive_class.border_highlight;
- _DtProcessUnlock();
- (*border_highlight) (w);
- } else if (XmIsGadget(w)) {
- _DtProcessLock();
- border_highlight = xmGadgetClassRec.gadget_class.border_highlight;
- _DtProcessUnlock();
- (*border_highlight) (w);
- }
- }
- static void
- UnhighlightBorder(
- Widget w )
- {
- XtWidgetProc border_unhighlight;
- if (XmIsPrimitive(w)) {
- _DtProcessLock();
- border_unhighlight = xmPrimitiveClassRec.primitive_class.border_unhighlight;
- _DtProcessUnlock();
- (*border_unhighlight) (w);
- } else if (XmIsGadget(w)) {
- _DtProcessLock();
- border_unhighlight = xmGadgetClassRec.gadget_class.border_unhighlight;
- _DtProcessUnlock();
- (*border_unhighlight) (w);
- }
- }
- /*-------------------------------------------------------------
- ** GetMaskGC
- ** Get normal and background graphics contexts.
- */
- static GC
- GetMaskGC(
- DtIconGadget g,
- Position x,
- Position y)
- {
- if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
- XSetClipOrigin(XtDisplay(g),
- G_ClipGC(g),
- x, y);
- return G_ClipGC(g);
- }
- else {
- return G_NormalGC(g);
- }
- }
- /*-------------------------------------------------------------
- ** GetDefaultBackground
- ** Copy background pixel from Manager parent.
- */
- /* ARGSUSED */
- static void
- GetDefaultBackground(
- Widget g,
- int offset,
- XrmValue *value )
- {
- static Pixel pixel;
- XmManagerWidget parent = (XmManagerWidget) XtParent (g);
- value->addr = (XtPointer) &pixel;
- value->size = sizeof (Pixel);
- if (XmIsManager ((Widget) parent))
- pixel = M_Background (parent);
- else
- XmeGetDefaultPixel (g, XmBACKGROUND, offset, value);
- }
- /*-------------------------------------------------------------
- ** GetDefaultForeground
- ** Copy foreground pixel from Manager parent.
- */
- static void
- GetDefaultForeground(
- Widget g,
- int offset,
- XrmValue *value )
- {
- static Pixel pixel;
- XmManagerWidget parent = (XmManagerWidget) XtParent (g);
- value->addr = (XtPointer) &pixel;
- value->size = sizeof (Pixel);
- if (XmIsManager ((Widget) parent))
- pixel = M_Foreground (parent);
- else
- XmeGetDefaultPixel (g, XmFOREGROUND, offset, value);
- }
- /*-------------------------------------------------------------
- ** GetDefaultFillMode
- ** Get default fill mode.
- */
- /* ARGSUSED */
- static void
- GetDefaultFillMode(
- Widget w,
- int offset,
- XrmValue *value )
- {
- static unsigned char fill_mode;
- DtIconGadget g = (DtIconGadget) w;
- value->addr = (XtPointer) &fill_mode;
- value->size = sizeof (unsigned char);
- if (G_ShadowThickness (g) == 0)
- fill_mode = XmFILL_PARENT;
- else
- fill_mode = XmFILL_SELF;
- }
- /*-------------------------------------------------------------
- ** GetSpacing
- ** Convert from pixels to horizontal or vertical units.
- */
- static void
- GetSpacing(
- Widget w,
- int offset,
- XtArgVal *value )
- {
- DtIconCacheObject icon_co = (DtIconCacheObject) w;
- if (G_CachePixmapPosition (icon_co) == XmPIXMAP_TOP ||
- G_CachePixmapPosition (icon_co) == XmPIXMAP_BOTTOM ||
- G_CachePixmapPosition (icon_co) == XmPIXMAP_MIDDLE)
- XmeFromVerticalPixels ((Widget)icon_co, offset, value);
- else
- XmeFromHorizontalPixels ((Widget)icon_co, offset, value);
- }
- /*-------------------------------------------------------------
- ** GetString
- ** Convert string from internal to external form.
- */
- /* ARGSUSED */
- static void
- GetString(
- Widget w,
- int offset,
- XtArgVal *value )
- {
- DtIconGadget g = (DtIconGadget) w;
- XmString string;
- string = XmStringCopy (G_String (g));
- *value = (XtArgVal) string;
- }
- /*-------------------------------------------------------------
- ** IconEventHandler
- ** Event handler for middle button events.
- */
- /* ARGSUSED */
- static void
- IconEventHandler(
- Widget w,
- XtPointer client_data,
- XButtonEvent *event )
- {
- DtIconGadget g = NULL;
- g = (DtIconGadget) XmObjectAtPoint (w, event->x, event->y);
-
- if (!g || !DtIsIcon ((Widget)g))
- return;
- if (event->button == Button2 || event->button == Button3)
- {
- if (event->type == ButtonPress)
- InputDispatch ((Widget) g, event, XmARM_EVENT);
- else if (event->type == ButtonRelease)
- InputDispatch ((Widget) g, event, XmACTIVATE_EVENT);
- }
- }
- /*-------------------------------------------------------------
- ** ClickTimeout
- ** Clear Click flags.
- */
- /* ARGSUSED */
- static void
- ClickTimeout(
- Widget w,
- XtIntervalId *id )
- {
- DtIconGadget g = (DtIconGadget) w;
- Time last_time, end_time;
- if (! G_Armed (g))
- {
- G_ClickTimerID (g) = 0;
- XtFree ((char *)G_ClickEvent (g));
- G_ClickEvent (g) = NULL;
- return;
- }
- last_time = XtLastTimestampProcessed (XtDisplay (g));
- /*
- * fix for bug# 4504
- */
- if( G_ClickEvent (g) == NULL) return;
- end_time = G_ClickEvent (g) -> time + (Time)
- XtGetMultiClickTime (XtDisplay (g));
- /* Sync and reset timer if server interval may not have elapsed.
- */
- if ((last_time < end_time) && G_Sync (g))
- {
- G_Sync (g) = False;
- XSync (XtDisplay (g), False);
- G_ClickTimerID (g) =
- XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget)g),
- (unsigned long) 50,
- (XtTimerCallbackProc)ClickTimeout,
- (XtPointer) g);
- }
- /* Handle Select action.
- */
- else
- {
- CallCallbackProc call_callback;
- XtExposeProc expose;
- _DtProcessLock();
- expose = XtCoreProc(w, expose);
- call_callback = C_CallCallback(XtClass(w));
- _DtProcessUnlock();
- G_ClickTimerID (g) = 0;
- G_Armed (g) = False;
- (*call_callback) (g, G_Callback (g), XmCR_SELECT,
- (XEvent *)G_ClickEvent (g));
- if ((G_Behavior (g) == XmICON_DRAG) &&
- (G_ShadowThickness (g) == 0))
- {
- /* Do nothing */
- }
- else
- (*expose) ((Widget)g, (XEvent*)G_ClickEvent (g), NULL);
- XtFree ((char *)G_ClickEvent (g));
- G_ClickEvent (g) = NULL;
- }
- }
- /*-------------------------------------------------------------
- ** Action Procs
- **-------------------------------------------------------------
- */
- /*-------------------------------------------------------------
- ** IconArm
- ** Handle Arm action.
- */
- static void
- IconArm(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- if (G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
- return;
- G_Armed (g) = True;
- if (G_Behavior (g) == XmICON_DRAG)
- {
- CallCallbackProc call_callback;
- _DtProcessLock();
- call_callback = C_CallCallback(XtClass(g));
- _DtProcessUnlock();
- (*call_callback) (g, G_Callback (g), XmCR_ARM, event);
- }
- if ((G_Behavior (g) == XmICON_DRAG) &&
- (G_ShadowThickness (g) == 0))
- {
- /* Do nothing */
- }
- else
- {
- XtExposeProc expose;
- _DtProcessLock();
- expose = XtCoreProc(w, expose);
- _DtProcessUnlock();
- (*expose) ((Widget)g, event, NULL);
- }
- }
- /*-------------------------------------------------------------
- ** IconDisarm
- ** Handle Disarm action.
- */
- static void
- IconDisarm(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- if (! G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
- return;
- G_Armed (g) = False;
- if (G_Behavior (g) == XmICON_DRAG)
- {
- CallCallbackProc call_callback;
- XtExposeProc expose;
- _DtProcessLock();
- call_callback = C_CallCallback(XtClass(g));
- expose = XtCoreProc(w, expose);
- _DtProcessUnlock();
- (*call_callback) (g, G_Callback (g), XmCR_DISARM, event);
- (*expose) ((Widget)g, event, NULL);
- }
- }
- /*-------------------------------------------------------------
- ** IconActivate
- ** Handle Activate action.
- */
- static void
- IconActivate(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- unsigned long delay;
- XButtonEvent * b_event = (XButtonEvent *) event;
- CallCallbackProc call_callback;
- XtExposeProc expose;
- if (! G_Armed (g))
- return;
- _DtProcessLock();
- call_callback = C_CallCallback(XtClass(g));
- expose = XtCoreProc(w, expose);
- _DtProcessUnlock();
- if (G_Behavior (g) == XmICON_BUTTON)
- {
- G_Armed (g) = False;
- (*call_callback) (g, G_Callback (g), XmCR_ACTIVATE, event);
- (*expose) ((Widget)g, event, NULL);
- }
- else if (G_Behavior (g) == XmICON_TOGGLE)
- {
- G_Armed (g) = False;
- G_Set (g) = ! G_Set (g);
- (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, event);
- }
- else if (G_Behavior (g) == XmICON_DRAG)
- {
- if (G_ClickTimerID (g))
- {
- G_ClickTimerID (g) = 0;
- XtFree ((char *)G_ClickEvent (g));
- G_ClickEvent (g) = NULL;
- G_Armed (g) = False;
- (*call_callback) (g, G_Callback (g),
- XmCR_DEFAULT_ACTION, event);
- }
- else
- {
- delay = (unsigned long)
- XtGetMultiClickTime (XtDisplay (g));
- G_ClickEvent (g) = (XButtonEvent *)
- XtMalloc (sizeof (XButtonEvent));
- *(G_ClickEvent (g)) = *b_event;
- G_Sync (g) = True;
- G_ClickTimerID (g) =
- XtAppAddTimeOut (
- XtWidgetToApplicationContext ((Widget)g),
- delay, (XtTimerCallbackProc)ClickTimeout,
- (XtPointer) g);
- }
- if (G_ShadowThickness (g) > 0)
- (*expose) ((Widget)g, event, NULL);
- }
- }
- /*-------------------------------------------------------------
- ** IconDrag
- ** Handle Drag action.
- */
- static void
- IconDrag(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- if (G_Behavior (g) == XmICON_DRAG)
- {
- CallCallbackProc call_callback;
- _DtProcessLock();
- call_callback = C_CallCallback(XtClass(w));
- _DtProcessUnlock();
- (*call_callback) (g, G_Callback (g), XmCR_DRAG, event);
- }
- }
- /*-------------------------------------------------------------
- ** IconPopup
- ** Handle button 3 - popup's
- */
- static void
- IconPopup(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- CallCallbackProc call_callback;
- _DtProcessLock();
- call_callback = C_CallCallback(XtClass(w));
- _DtProcessUnlock();
- (*call_callback) (g, G_Callback (g), XmCR_POPUP, event);
- }
- /*-------------------------------------------------------------
- ** IconEnter
- ** Handle Enter action.
- */
- static void
- IconEnter(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- _XmEnterGadget (w, (XEvent *)event,
- (String *)NULL,(Cardinal *)0);
- if (G_Armed (g))
- {
- if ((G_Behavior (g) == XmICON_BUTTON) ||
- (G_Behavior (g) == XmICON_TOGGLE))
- {
- XtExposeProc expose;
- _DtProcessLock();
- expose = XtCoreProc(w, expose);
- _DtProcessUnlock();
- (*expose) ((Widget)g, event, NULL);
- }
- }
- }
- /*-------------------------------------------------------------
- ** IconLeave
- ** Handle Leave action.
- */
- static void
- IconLeave(
- Widget w,
- XEvent *event )
- {
- DtIconGadget g = (DtIconGadget) w;
- _XmLeaveGadget (w, (XEvent *)event,
- (String *)NULL, (Cardinal *)0);
- if (G_Armed (g))
- {
- if ((G_Behavior (g) == XmICON_BUTTON) ||
- (G_Behavior (g) == XmICON_TOGGLE))
- {
- XtExposeProc expose;
- _DtProcessLock();
- expose = XtCoreProc(w, expose);
- _DtProcessUnlock();
- G_Armed (g) = False;
- (*expose) ((Widget)g, event, NULL);
- G_Armed (g) = True;
- }
- }
- }
- /*-------------------------------------------------------------
- ** Core Procs
- **-------------------------------------------------------------
- */
- /*-------------------------------------------------------------
- ** ClassInitialize
- ** Initialize gadget class.
- */
- static void
- ClassInitialize( void )
- {
- _DtRegisterNewConverters ();
- iconBaseClassExtRec.record_type = XmQmotif;
- }
- /*-------------------------------------------------------------
- ** ClassPartInitialize
- ** Initialize gadget class part.
- */
- static void
- ClassPartInitialize (
- WidgetClass wc)
- {
- DtIconGadgetClass ic = (DtIconGadgetClass) wc;
- DtIconGadgetClass super = (DtIconGadgetClass) ic->rect_class.superclass;
- if (C_GetSize (ic) == DtInheritGetSize)
- C_GetSize (ic) = C_GetSize (super);
- if (C_GetPositions (ic) == DtInheritGetPositions)
- C_GetPositions (ic) = C_GetPositions (super);
- if (C_Draw (ic) == DtInheritDraw)
- C_Draw (ic) = C_Draw (super);
- if (C_CallCallback (ic) == DtInheritCallCallback)
- C_CallCallback (ic) = C_CallCallback (super);
- if (C_UpdateGCs (ic) == DtInheritUpdateGCs)
- C_UpdateGCs (ic) = C_UpdateGCs (super);
- }
- /*-------------------------------------------------------------
- ** Cache Procs
- **-------------------------------------------------------------
- */
- /*-------------------------------------------------------------
- ** IconCacheCompare
- **
- */
- static int
- IconCacheCompare(
- XtPointer A,
- XtPointer B )
- {
- DtIconCacheObjPart *icon_inst = (DtIconCacheObjPart *) A ;
- DtIconCacheObjPart *icon_cache_inst = (DtIconCacheObjPart *) B ;
- if ((icon_inst->fill_on_arm == icon_cache_inst->fill_on_arm) &&
- (icon_inst->recompute_size== icon_cache_inst->recompute_size) &&
- (icon_inst->pixmap_position== icon_cache_inst->pixmap_position) &&
- (icon_inst->string_position== icon_cache_inst->string_position) &&
- (icon_inst->alignment == icon_cache_inst->alignment) &&
- (icon_inst->behavior == icon_cache_inst->behavior) &&
- (icon_inst->draw_shadow == icon_cache_inst->draw_shadow) &&
- (icon_inst->fill_mode == icon_cache_inst->fill_mode) &&
- (icon_inst->margin_width== icon_cache_inst->margin_width) &&
- (icon_inst->margin_height== icon_cache_inst->margin_height) &&
- (icon_inst->string_height== icon_cache_inst->string_height) &&
- (icon_inst->spacing== icon_cache_inst->spacing) &&
- (icon_inst->foreground== icon_cache_inst->foreground) &&
- (icon_inst->background== icon_cache_inst->background) &&
- (icon_inst->arm_color== icon_cache_inst->arm_color))
- return 1;
- else
- return 0;
- }
- /*-------------------------------------------------------------
- ** SecondaryObjectCreate
- **
- */
- static void
- SecondaryObjectCreate(
- Widget req,
- Widget new_w,
- ArgList args,
- Cardinal *num_args )
- {
- XmBaseClassExt *cePtr;
- XmWidgetExtData extData;
- WidgetClass wc;
- Cardinal size;
- XtPointer newSec, reqSec;
- XtResourceList resources;
- Cardinal num_resources;
- _DtProcessLock();
- cePtr = _XmGetBaseClassExtPtr(XtClass(new_w), XmQmotif);
- wc = (*cePtr)->secondaryObjectClass;
- if (NULL == wc) return;
- size = wc->core_class.widget_size;
- resources = wc->core_class.resources;
- num_resources = wc->core_class.num_resources;
- newSec = _XmExtObjAlloc(size);
- reqSec = _XmExtObjAlloc(size);
- _DtProcessUnlock();
- /*
- * fetch the resources in superclass to subclass order
- */
- XtGetSubresources(new_w, newSec, NULL, NULL,
- resources, num_resources, args, *num_args );
- extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
- extData->widget = (Widget)newSec;
- extData->reqWidget = (Widget)reqSec;
- ((DtIconCacheObject)newSec)->ext.extensionType = XmCACHE_EXTENSION;
- ((DtIconCacheObject)newSec)->ext.logicalParent = new_w;
- _XmPushWidgetExtData(new_w, extData,
- ((DtIconCacheObject)newSec)->ext.extensionType);
- memcpy(reqSec, newSec, size);
- /*
- * fill out cache pointers
- */
- Icon_Cache(new_w) = &(((DtIconCacheObject)extData->widget)->icon_cache);
- Icon_Cache(req) = &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
- }
- /*-------------------------------------------------------------
- ** InitializePostHook
- **
- */
- /* ARGSUSED */
- static void
- InitializePosthook(
- Widget req,
- Widget new,
- ArgList args,
- Cardinal *num_args )
- {
- XmWidgetExtData ext;
- DtIconGadget lw = (DtIconGadget)new;
- /*
- * - register parts in cache.
- * - update cache pointers
- * - and free req
- */
- _DtProcessLock();
- Icon_Cache(lw) = (DtIconCacheObjPart *)
- _XmCachePart( Icon_ClassCachePart(lw),
- (XtPointer) Icon_Cache(lw),
- sizeof(DtIconCacheObjPart));
- /*
- * might want to break up into per-class work that gets explicitly
- * chained. For right now, each class has to replicate all
- * superclass logic in hook routine
- */
- /* * free the req subobject used for comparisons
- */
- _XmPopWidgetExtData((Widget) lw, &ext, XmCACHE_EXTENSION);
- _XmExtObjFree((XtPointer)ext->widget);
- _XmExtObjFree((XtPointer)ext->reqWidget);
- _DtProcessUnlock();
- XtFree( (char *) ext);
- }
- /*-------------------------------------------------------------
- ** SetValuesPrehook
- **
- */
- /* ARGSUSED */
- static Boolean
- SetValuesPrehook(
- Widget oldParent,
- Widget refParent,
- Widget newParent,
- ArgList args,
- Cardinal *num_args )
- {
- XmWidgetExtData extData;
- XmBaseClassExt *cePtr;
- WidgetClass ec;
- DtIconCacheObject newSec, reqSec;
- Cardinal size;
- XtResourceList resources;
- Cardinal num_resources;
- _DtProcessLock();
- cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
- ec = (*cePtr)->secondaryObjectClass;
- size = ec->core_class.widget_size;
- resources = ec->core_class.resources;
- num_resources = ec->core_class.num_resources;
- /* allocate copies and fill from cache */
- newSec = (DtIconCacheObject) _XmExtObjAlloc(size);
- reqSec = (DtIconCacheObject) _XmExtObjAlloc(size);
- _DtProcessUnlock();
- newSec->object.self = (Widget)newSec;
- newSec->object.widget_class = ec;
- newSec->object.parent = XtParent(newParent);
- newSec->object.xrm_name = newParent->core.xrm_name;
- newSec->object.being_destroyed = False;
- newSec->object.destroy_callbacks = NULL;
- newSec->object.constraints = NULL;
- newSec->ext.logicalParent = newParent;
- newSec->ext.extensionType = XmCACHE_EXTENSION;
- memcpy(&(newSec->icon_cache),
- Icon_Cache(newParent),
- sizeof(DtIconCacheObjPart));
- extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
- extData->widget = (Widget)newSec;
- extData->reqWidget = (Widget)reqSec;
- _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
- _XmGadgetImportSecondaryArgs(newParent, args, num_args);
- XtSetSubvalues((XtPointer)newSec, resources, num_resources,
- args, *num_args);
- _XmExtImportArgs((Widget)newSec, args, num_args);
- memcpy((XtPointer)reqSec, (XtPointer)newSec, size);
- Icon_Cache(newParent) = &(((DtIconCacheObject)newSec)->icon_cache);
- Icon_Cache(refParent) =
- &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
- return FALSE;
- }
- /*-------------------------------------------------------------
- ** GetValuesPrehook
- **
- */
- static void
- GetValuesPrehook(
- Widget newParent,
- ArgList args,
- Cardinal *num_args )
- {
- XmWidgetExtData extData;
- XmBaseClassExt *cePtr;
- WidgetClass ec;
- DtIconCacheObject newSec;
- Cardinal size;
- XtResourceList resources;
- Cardinal num_resources;
- _DtProcessLock();
- cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
- ec = (*cePtr)->secondaryObjectClass;
- size = ec->core_class.widget_size;
- resources = ec->core_class.resources;
- num_resources = ec->core_class.num_resources;
- newSec = (DtIconCacheObject)_XmExtObjAlloc(size);
- _DtProcessUnlock();
- newSec->object.self = (Widget)newSec;
- newSec->object.widget_class = ec;
- newSec->object.parent = XtParent(newParent);
- newSec->object.xrm_name = newParent->core.xrm_name;
- newSec->object.being_destroyed = False;
- newSec->object.destroy_callbacks = NULL;
- newSec->object.constraints = NULL;
- newSec->ext.logicalParent = newParent;
- newSec->ext.extensionType = XmCACHE_EXTENSION;
- memcpy( &(newSec->icon_cache),
- Icon_Cache(newParent),
- sizeof(DtIconCacheObjPart));
- extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
- extData->widget = (Widget)newSec;
- _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
- XtGetSubvalues((XtPointer)newSec, resources, num_resources,
- args, *num_args);
- _XmExtGetValuesHook((Widget)newSec, args, num_args);
- }
- /*-------------------------------------------------------------
- ** GetValuesPosthook
- **
- */
- /* ARGSUSED */
- static void
- GetValuesPosthook(
- Widget new,
- ArgList args,
- Cardinal *num_args )
- {
- XmWidgetExtData ext;
- _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
- _DtProcessLock();
- _XmExtObjFree((XtPointer)ext->widget);
- _DtProcessUnlock();
- XtFree((char *)ext);
- }
- /*-------------------------------------------------------------
- ** SetValuesPosthook
- **
- */
- /* ARGSUSED */
- static Boolean
- SetValuesPosthook(
- Widget current,
- Widget req,
- Widget new,
- ArgList args,
- Cardinal *num_args )
- {
- XmWidgetExtData ext;
- /*
- * - register parts in cache.
- * - update cache pointers
- * - and free req
- */
- /* assign if changed! */
- _DtProcessLock();
- if (!IconCacheCompare((XtPointer)Icon_Cache(new),
- (XtPointer)Icon_Cache(current)))
- {
- _XmCacheDelete((XtPointer) Icon_Cache(current)); /* delete the old one */
- Icon_Cache(new) = (DtIconCacheObjPart *)
- _XmCachePart(Icon_ClassCachePart(new),
- (XtPointer) Icon_Cache(new),
- sizeof(DtIconCacheObjPart));
- } else
- Icon_Cache(new) = Icon_Cache(current);
- _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
- _XmExtObjFree((XtPointer)ext->widget);
- _XmExtObjFree((XtPointer)ext->reqWidget);
- _DtProcessUnlock();
- XtFree((char *)ext);
- return FALSE;
- }
- /*--------------------------------------------------------------------------
- ** QualifyIconLocalCache
- ** Checks to see if local cache is set up
- */
- static void
- QualifyIconLocalCache(DtIconGadget g, DtIconCacheObjPart *local_cache)
- {
- _DtProcessLock();
- ClassCacheCopy(Icon_ClassCachePart(g))((XtPointer) Icon_Cache(g),
- (XtPointer) local_cache,
- sizeof(DtIconCacheObjPart));
- _DtProcessUnlock();
- }
- /************************************************************************
- *
- * ReCacheIcon_r()
- * Check to see if ReCaching is necessary as a result of fields having
- * been set by a mananger widget. This routine is called by the
- * manager widget in their SetValues after a change is made to any
- * of Icon's cached fields.
- *
- ************************************************************************/
- static void
- ReCacheIcon_r(DtIconCacheObjPart *local_cache, DtIconGadget g)
- {
- if (!IconCacheCompare( (XtPointer)local_cache, (XtPointer)Icon_Cache(g)))
- {
- _DtProcessLock();
- _XmCacheDelete( (XtPointer) Icon_Cache(g)); /* delete the old one */
- Icon_Cache(g) = (DtIconCacheObjPart *)
- _XmCachePart(Icon_ClassCachePart(g),
- (XtPointer) local_cache,
- sizeof(DtIconCacheObjPart));
- _DtProcessUnlock();
- }
- }
- /*********************************************************************
- *
- * GetParentBackgroundGC
- * Get the graphics context used for erasing their highlight border.
- *
- *********************************************************************/
- static void
- GetParentBackgroundGC(
- DtIconGadget g )
- {
- XGCValues values;
- XtGCMask valueMask;
- Widget parent = XtParent((Widget)g);
- valueMask = GCForeground | GCBackground;
- values.foreground = parent->core.background_pixel;
- if (XmIsManager(parent))
- values.background = ((XmManagerWidget) parent)->manager.foreground;
- else
- values.background = ((XmPrimitiveWidget) parent)->primitive.foreground;
- if ((parent->core.background_pixmap != None) &&
- (parent->core.background_pixmap != XmUNSPECIFIED_PIXMAP))
- {
- valueMask |= GCFillStyle | GCTile;
- values.fill_style = FillTiled;
- values.tile = parent->core.background_pixmap;
- }
- G_SavedParentBG(g) = parent->core.background_pixel;
- G_ParentBackgroundGC(g) = XtGetGC (parent, valueMask, &values);
- }
- /*-------------------------------------------------------------
- ** Initialize
- ** Initialize a new gadget instance.
- */
- static void
- Initialize(
- Widget request_w,
- Widget new_w )
- {
- DtIconGadget request = (DtIconGadget) request_w,
- new = (DtIconGadget) new_w;
- Window root;
- int int_x = 0, int_y = 0;
- unsigned int int_w = 0, int_h = 0,
- int_bw, depth;
- Dimension w, h;
- EventMask mask;
- String name = NULL;
- UpdateGCsProc update_gcs;
- G_Sync (new) = False;
- /* Validate behavior.
- */
- if (G_Behavior (new) != XmICON_LABEL &&
- G_Behavior (new) != XmICON_BUTTON &&
- G_Behavior (new) != XmICON_TOGGLE &&
- G_Behavior (new) != XmICON_DRAG)
- {
- XmeWarning ((Widget)new, WARN_BEHAVIOR);
- G_Behavior (new) = XmICON_BUTTON;
- }
- /* Set the input mask for events handled by Manager.
- */
- G_EventMask (new) = (XmARM_EVENT | XmACTIVATE_EVENT |
- XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
- XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
- XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
- /* Add event handler for icon events.
- */
- if (G_Behavior (new) == XmICON_DRAG)
- {
- mask = ButtonPressMask|ButtonReleaseMask;
- XtAddEventHandler (XtParent (new), mask, False,
- (XtEventHandler) IconEventHandler, 0);
- }
- G_ClickTimerID (new) = 0;
- G_ClickEvent (new) = NULL;
- G_Armed (new) = False;
- G_Mask (new) = NULL;
- if (G_Pixmap (new) == XmUNSPECIFIED_PIXMAP)
- G_Pixmap (new) = NULL;
- if (G_ImageName (new) || G_Pixmap (new))
- {
- if (G_ImageName (new))
- {
- /* Try to get pixmap from image name.
- */
- G_Pixmap (new) =
- XmGetPixmap (XtScreen (new), G_ImageName (new),
- G_PixmapForeground (new),
- G_PixmapBackground (new));
- if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
- {
- name = G_ImageName (new);
- G_Mask (new) =
- _DtGetMask(XtScreen (new), G_ImageName
- (new));
- }
- else
- {
- /* warning? */
- name = NULL;
- G_Pixmap (new) = NULL;
- }
- }
- /* Update width and height; copy image name.
- */
- if (G_Pixmap (new))
- {
- XGetGeometry (XtDisplay (new), G_Pixmap (new),
- &root, &int_x, &int_y, &int_w, &int_h,
- &int_bw, &depth);
- }
- if (name)
- {
- G_ImageName (new) = XtNewString(name);
- }
- else
- G_ImageName (new) = NULL;
- }
- G_PixmapWidth(new) = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
- G_PixmapHeight(new) = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
- /* Validate fill mode.
- */
- if (G_FillMode (new) != XmFILL_NONE &&
- G_FillMode (new) != XmFILL_PARENT &&
- G_FillMode (new) != XmFILL_TRANSPARENT &&
- G_FillMode (new) != XmFILL_SELF)
- {
- XmeWarning ((Widget)new, WARN_FILL_MODE);
- if (G_ShadowThickness (new) > 0)
- G_FillMode (new) = XmFILL_SELF;
- else
- G_FillMode (new) = XmFILL_PARENT;
- }
- /* Validate pixmap position.
- */
- if (G_StringPosition (new) != UNSPECIFIED_CHAR)
- G_PixmapPosition (new) = G_StringPosition (new);
- if (G_PixmapPosition (new) == UNSPECIFIED_CHAR)
- G_PixmapPosition (new) = XmPIXMAP_LEFT;
- else if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
- G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
- G_PixmapPosition (new) != XmPIXMAP_TOP &&
- G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
- G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
- {
- XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
- G_PixmapPosition (new) = XmPIXMAP_LEFT;
- }
- G_StringPosition (new) = G_PixmapPosition (new);
- /* Validate alignment.
- */
- if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
- G_Alignment (new) != XmALIGNMENT_CENTER &&
- G_Alignment (new) != XmALIGNMENT_END)
- {
- XmeWarning ((Widget)new, WARN_ALIGNMENT);
- G_Alignment (new) = XmALIGNMENT_BEGINNING;
- }
- /* Validate shadow type.
- */
- if (G_ShadowType (new) != XmSHADOW_IN &&
- G_ShadowType (new) != XmSHADOW_OUT &&
- G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
- G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
- {
- Xm