PageRenderTime 110ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/cde/lib/DtWidget/Icon.c

https://bitbucket.org/tifan/cde
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
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $TOG: Icon.c /main/20 1999/09/08 10:44:52 mgreess $
  24. *
  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.
  32. */
  33. /**---------------------------------------------------------------------
  34. ***
  35. *** file: Icon.c
  36. ***
  37. *** project: MotifPlus Widgets
  38. ***
  39. *** description: Source code for DtIconGadget class.
  40. ***
  41. ***-------------------------------------------------------------------*/
  42. /*-------------------------------------------------------------
  43. ** Include Files
  44. */
  45. #include <stdio.h>
  46. #ifdef __apollo
  47. #include <sys/types.h>
  48. #endif
  49. #include <sys/stat.h>
  50. #include <X11/Xatom.h>
  51. #include <Xm/XmP.h>
  52. #include <Xm/CacheP.h>
  53. #include <Xm/ManagerP.h>
  54. #include <Xm/PrimitiveP.h>
  55. #include <Xm/DrawP.h>
  56. #include <Dt/IconP.h>
  57. #include <Dt/MacrosP.h>
  58. #include <Dt/DtMsgsP.h>
  59. #include <Dt/Dnd.h>
  60. #include "DtWidgetI.h"
  61. /*-------------------------------------------------------------
  62. ** Public Interface
  63. **-------------------------------------------------------------
  64. */
  65. WidgetClass dtIconGadgetClass;
  66. #define Min(x, y) (((x) < (y)) ? (x) : (y))
  67. #define Max(x, y) (((x) > (y)) ? (x) : (y))
  68. #define Limit(x, lim) (((lim) == 0 || (x) <= (lim))? (x): (lim))
  69. /*-------------------------------------------------------------
  70. ** Forward Declarations
  71. */
  72. extern void _DtRegisterNewConverters ( void );
  73. extern char * _XmExtObjAlloc(int size);
  74. extern void _XmExtObjFree(XtPointer element);
  75. extern void _XmSelectColorDefault ( Widget, int, XrmValue * );
  76. #define SPACING_DEFAULT 2
  77. #define MARGIN_DEFAULT 2
  78. #define UNSPECIFIED_DIMENSION 9999
  79. #define UNSPECIFIED_CHAR 255
  80. #define WARN_ALIGNMENT _DtMsgIcon_0000
  81. #define WARN_BEHAVIOR _DtMsgIcon_0001
  82. #define WARN_FILL_MODE _DtMsgIcon_0002
  83. #define WARN_PIXMAP_POSITION _DtMsgIcon_0003
  84. #define WARN_MARGIN _DtMsgIcon_0004
  85. #define WARN_SHADOW_TYPE _DtMsgIcon_0005
  86. #define MgrParent(g) ((XmManagerWidget) (XmIsManager(XtParent(g)) ? (XtParent(g)) : (XtParent(XtParent(g)))))
  87. /******** Private Function Declarations ********/
  88. extern void _DtIconRegisterDropsite(
  89. Widget w) ;
  90. /******** End Private Function Declarations ********/
  91. /******** Static Function Declarations ********/
  92. static int IconCacheCompare(
  93. XtPointer A,
  94. XtPointer B) ;
  95. static void ReCacheIcon_r(
  96. DtIconCacheObjPart *cache,
  97. DtIconGadget g);
  98. static void GetDefaultBackground(
  99. Widget g,
  100. int offset,
  101. XrmValue *value) ;
  102. static void GetDefaultForeground(
  103. Widget g,
  104. int offset,
  105. XrmValue *value) ;
  106. static void GetDefaultFillMode(
  107. Widget w,
  108. int offset,
  109. XrmValue *value) ;
  110. static void GetSpacing(
  111. Widget w,
  112. int offset,
  113. XtArgVal *value) ;
  114. static void GetString(
  115. Widget w,
  116. int offset,
  117. XtArgVal *value) ;
  118. static void IconEventHandler(
  119. Widget w,
  120. XtPointer client_data,
  121. XButtonEvent *event) ;
  122. static void ClickTimeout(
  123. Widget w,
  124. XtIntervalId *id) ;
  125. static void IconArm(
  126. Widget w,
  127. XEvent *event) ;
  128. static void IconDisarm(
  129. Widget w,
  130. XEvent *event) ;
  131. static void IconActivate(
  132. Widget w,
  133. XEvent *event) ;
  134. static void IconDrag(
  135. Widget w,
  136. XEvent *event) ;
  137. static void IconPopup(
  138. Widget w,
  139. XEvent *event) ;
  140. static void IconEnter(
  141. Widget w,
  142. XEvent *event) ;
  143. static void IconLeave(
  144. Widget w,
  145. XEvent *event) ;
  146. static void ClassInitialize( void ) ;
  147. static void SecondaryObjectCreate(
  148. Widget req,
  149. Widget new_w,
  150. ArgList args,
  151. Cardinal *num_args) ;
  152. static void InitializePosthook(
  153. Widget req,
  154. Widget new,
  155. ArgList args,
  156. Cardinal *num_args) ;
  157. static Boolean SetValuesPrehook(
  158. Widget oldParent,
  159. Widget refParent,
  160. Widget newParent,
  161. ArgList args,
  162. Cardinal *num_args) ;
  163. static void GetValuesPrehook(
  164. Widget newParent,
  165. ArgList args,
  166. Cardinal *num_args) ;
  167. static void GetValuesPosthook(
  168. Widget new,
  169. ArgList args,
  170. Cardinal *num_args) ;
  171. static Boolean SetValuesPosthook(
  172. Widget current,
  173. Widget req,
  174. Widget new,
  175. ArgList args,
  176. Cardinal *num_args) ;
  177. static void QualifyIconLocalCache(
  178. DtIconGadget g,
  179. DtIconCacheObjPart *cache);
  180. static void Initialize(
  181. Widget request_w,
  182. Widget new_w) ;
  183. static void Destroy(
  184. Widget w) ;
  185. static void Resize(
  186. Widget w) ;
  187. static void Redisplay(
  188. Widget w,
  189. XEvent *event,
  190. Region region) ;
  191. static Boolean SetValues(
  192. Widget current_w,
  193. Widget request_w,
  194. Widget new_w) ;
  195. static void BorderHighlight(
  196. DtIconGadget g) ;
  197. static void BorderUnhighlight(
  198. DtIconGadget g) ;
  199. static void ArmAndActivate(
  200. Widget w,
  201. XEvent *event) ;
  202. static void InputDispatch(
  203. Widget w,
  204. XButtonEvent *event,
  205. Mask event_mask) ;
  206. static Boolean VisualChange(
  207. Widget w,
  208. Widget current_w,
  209. Widget new_w) ;
  210. static void GetSize(
  211. DtIconGadget g,
  212. Dimension *w,
  213. Dimension *h) ;
  214. static void GetPositions(
  215. DtIconGadget g,
  216. Position w,
  217. Position h,
  218. Dimension h_t,
  219. Dimension s_t,
  220. Position *pix_x,
  221. Position *pix_y,
  222. Position *str_x,
  223. Position *str_y) ;
  224. static void Draw(
  225. DtIconGadget g,
  226. Drawable drawable,
  227. Position x,
  228. Position y,
  229. Dimension w,
  230. Dimension h,
  231. Dimension h_t,
  232. Dimension s_t,
  233. unsigned char s_type,
  234. unsigned char fill_mode) ;
  235. static void CallCallback(
  236. DtIconGadget g,
  237. XtCallbackList cb,
  238. int reason,
  239. XEvent *event) ;
  240. static void UpdateGCs(
  241. DtIconGadget g) ;
  242. static Cardinal GetIconClassSecResData(
  243. WidgetClass class,
  244. XmSecondaryResourceData **data_rtn) ;
  245. static XtPointer GetIconClassResBase(
  246. Widget widget,
  247. XtPointer client_data) ;
  248. static Boolean LoadPixmap(
  249. DtIconGadget new,
  250. String pixmap) ;
  251. static void ClassPartInitialize ( WidgetClass wc);
  252. static void HighlightBorder( Widget w );
  253. static void UnhighlightBorder( Widget w );
  254. /******** End Static Function Declarations ********/
  255. /* External Cache Procs
  256. */
  257. extern void _XmCacheDelete( XtPointer data );
  258. extern void _XmCacheCopy( XtPointer src, XtPointer dest, size_t size );
  259. extern Cardinal _XmSecondaryResourceData( XmBaseClassExt, XmSecondaryResourceData **,
  260. XtPointer, String, String, XmResourceBaseProc);
  261. extern XtPointer _XmCachePart( XmCacheClassPartPtr cp, XtPointer cpart, size_t size );
  262. /*-------------------------------------------------------------
  263. ** Resource List
  264. */
  265. #define I_Offset(field) \
  266. XtOffset (DtIconGadget, icon.field)
  267. #define I_Cache_Offset(field) \
  268. XtOffset (DtIconCacheObject, icon_cache.field)
  269. static XtResource resources[] =
  270. {
  271. {
  272. XmNset,
  273. XmCSet, XmRBoolean, sizeof (Boolean),
  274. I_Offset (set), XmRImmediate, (XtPointer) False
  275. },
  276. {
  277. XmNshadowType,
  278. XmCShadowType, XmRShadowType, sizeof (unsigned char),
  279. I_Offset (shadow_type),
  280. XmRImmediate, (XtPointer) XmSHADOW_ETCHED_OUT
  281. },
  282. {
  283. XmNborderType,
  284. XmCBorderType, XmRBorderType, sizeof (unsigned char),
  285. I_Offset (border_type),
  286. XmRImmediate, (XtPointer) DtRECTANGLE
  287. },
  288. {
  289. XmNcallback,
  290. XmCCallback, XmRCallback, sizeof (XtCallbackList),
  291. I_Offset (callback), XmRImmediate, (XtPointer) NULL
  292. },
  293. {
  294. XmNfontList,
  295. XmCFontList, XmRFontList, sizeof (XmFontList),
  296. I_Offset (font_list), XmRString, "Fixed"
  297. },
  298. {
  299. XmNimageName,
  300. XmCString, XmRString, sizeof (XmString),
  301. I_Offset (image_name), XmRImmediate, (XtPointer) NULL
  302. },
  303. {
  304. XmNpixmap,
  305. XmCPixmap, XmRPixmap, sizeof (Pixmap),
  306. I_Offset (pixmap),
  307. XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
  308. },
  309. {
  310. XmNstring,
  311. XmCXmString, XmRXmString, sizeof (XmString),
  312. I_Offset (string),
  313. XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
  314. },
  315. {
  316. XmNpixmapForeground,
  317. XmCForeground, XmRPixel, sizeof (Pixel),
  318. I_Offset (pixmap_foreground),
  319. XmRCallProc, (XtPointer) GetDefaultForeground
  320. },
  321. {
  322. XmNpixmapBackground,
  323. XmCBackground, XmRPixel, sizeof (Pixel),
  324. I_Offset (pixmap_background),
  325. XmRCallProc, (XtPointer) GetDefaultBackground
  326. },
  327. {
  328. XmNmaxPixmapWidth,
  329. XmCMaxWidth, XmRHorizontalDimension, sizeof (Dimension),
  330. I_Offset (max_pixmap_width), XmRImmediate, (XtPointer) 0
  331. },
  332. {
  333. XmNmaxPixmapHeight,
  334. XmCMaxHeight, XmRVerticalDimension, sizeof (Dimension),
  335. I_Offset (max_pixmap_height), XmRImmediate, (XtPointer) 0
  336. },
  337. {
  338. XmNunderline,
  339. XmCUnderline, XmRBoolean, sizeof (Boolean),
  340. I_Offset (underline), XmRImmediate, (XtPointer) False
  341. },
  342. {
  343. XmNdropSiteOperations, XmCDropSiteOperations,
  344. XmRDropSiteOperations, sizeof(unsigned char),
  345. I_Offset(operations), XmRImmediate, (XtPointer) XmDROP_NOOP
  346. },
  347. {
  348. XmNdropCallback,
  349. XmCDropCallback, XmRCallback, sizeof (XtCallbackList),
  350. I_Offset (drop_callback), XmRImmediate, (XtPointer) NULL
  351. }
  352. };
  353. static XtResource cache_resources[] =
  354. {
  355. {
  356. XmNbehavior,
  357. XmCBehavior, XmRBehavior, sizeof (unsigned char),
  358. I_Cache_Offset (behavior),
  359. XmRImmediate, (XtPointer) XmICON_BUTTON
  360. },
  361. {
  362. XmNrecomputeSize,
  363. XmCRecomputeSize, XmRBoolean, sizeof (Boolean),
  364. I_Cache_Offset (recompute_size), XmRImmediate, (XtPointer) True
  365. },
  366. {
  367. "drawShadow",
  368. "DrawShadow", XmRBoolean, sizeof (Boolean),
  369. I_Cache_Offset (draw_shadow), XmRImmediate, (XtPointer) False
  370. },
  371. {
  372. XmNfillOnArm,
  373. XmCFillOnArm, XmRBoolean, sizeof (Boolean),
  374. I_Cache_Offset (fill_on_arm), XmRImmediate, (XtPointer) True
  375. },
  376. {
  377. XmNforeground,
  378. XmCForeground, XmRPixel, sizeof (Pixel),
  379. I_Cache_Offset (foreground),
  380. XmRCallProc, (XtPointer) GetDefaultForeground
  381. },
  382. {
  383. XmNbackground,
  384. XmCBackground, XmRPixel, sizeof (Pixel),
  385. I_Cache_Offset (background),
  386. XmRCallProc, (XtPointer) GetDefaultBackground
  387. },
  388. {
  389. XmNarmColor,
  390. XmCArmColor, XmRPixel, sizeof (Pixel),
  391. I_Cache_Offset (arm_color),
  392. XmRCallProc, (XtPointer) _XmSelectColorDefault
  393. },
  394. {
  395. XmNspacing,
  396. XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
  397. I_Cache_Offset (spacing),
  398. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  399. },
  400. {
  401. XmNmarginHeight,
  402. XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
  403. I_Cache_Offset (margin_height),
  404. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  405. },
  406. {
  407. XmNmarginWidth,
  408. XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
  409. I_Cache_Offset (margin_width),
  410. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  411. },
  412. {
  413. XmNpixmapPosition,
  414. XmCPixmapPosition, XmRPixmapPosition, sizeof (unsigned char),
  415. I_Cache_Offset (pixmap_position),
  416. XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
  417. },
  418. {
  419. XmNstringPosition,
  420. XmCStringPosition, XmRStringPosition, sizeof (unsigned char),
  421. I_Cache_Offset (string_position),
  422. XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
  423. },
  424. {
  425. XmNalignment,
  426. XmCAlignment, XmRAlignment, sizeof (unsigned char),
  427. I_Cache_Offset (alignment),
  428. XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
  429. },
  430. {
  431. XmNfillMode,
  432. XmCFillMode, XmRFillMode, sizeof (unsigned char),
  433. I_Cache_Offset (fill_mode),
  434. XmRCallProc, (XtPointer) GetDefaultFillMode
  435. }
  436. };
  437. static XmSyntheticResource syn_resources[] =
  438. {
  439. {
  440. XmNstring, sizeof (XmString),
  441. I_Offset (string), GetString,
  442. (XmImportProc) NULL
  443. },
  444. };
  445. static XmSyntheticResource cache_syn_resources[] =
  446. {
  447. {
  448. XmNspacing, sizeof (Dimension),
  449. I_Cache_Offset (spacing), GetSpacing,
  450. (XmImportProc) NULL
  451. },
  452. {
  453. XmNmarginWidth, sizeof (Dimension),
  454. I_Cache_Offset (margin_width),
  455. XmeFromHorizontalPixels,
  456. (XmImportProc)XmeToHorizontalPixels
  457. },
  458. {
  459. XmNmarginHeight, sizeof (Dimension),
  460. I_Cache_Offset (margin_height),
  461. XmeFromVerticalPixels,
  462. (XmImportProc)XmeToVerticalPixels,
  463. }
  464. };
  465. #undef I_Offset
  466. #undef I_Cache_Offset
  467. /*-------------------------------------------------------------
  468. ** Cache Class Record
  469. */
  470. static XmCacheClassPart IconClassCachePart = {
  471. {NULL, 0, 0}, /* head of class cache list */
  472. _XmCacheCopy, /* Copy routine */
  473. _XmCacheDelete, /* Delete routine */
  474. IconCacheCompare, /* Comparison routine */
  475. };
  476. /*-------------------------------------------------------------
  477. ** Base Class Extension Record
  478. */
  479. static XmBaseClassExtRec iconBaseClassExtRec = {
  480. NULL, /* Next extension */
  481. NULLQUARK, /* record type XmQmotif */
  482. XmBaseClassExtVersion, /* version */
  483. sizeof(XmBaseClassExtRec), /* size */
  484. XmInheritInitializePrehook, /* initialize prehook */
  485. SetValuesPrehook, /* set_values prehook */
  486. InitializePosthook, /* initialize posthook */
  487. SetValuesPosthook, /* set_values posthook */
  488. (WidgetClass)&dtIconCacheObjClassRec, /* secondary class */
  489. (XtInitProc)SecondaryObjectCreate, /* creation proc */
  490. (XmGetSecResDataFunc) GetIconClassSecResData, /* getSecResData */
  491. {NULL}, /* fast subclass */
  492. GetValuesPrehook, /* get_values prehook */
  493. GetValuesPosthook, /* get_values posthook */
  494. NULL, /* classPartInitPrehook */
  495. NULL, /* classPartInitPosthook*/
  496. NULL, /* ext_resources */
  497. NULL, /* compiled_ext_resources*/
  498. 0, /* num_ext_resources */
  499. FALSE, /* use_sub_resources */
  500. XmInheritWidgetNavigable, /* widgetNavigable */
  501. XmInheritFocusChange, /* focusChange */
  502. };
  503. /*-------------------------------------------------------------
  504. ** Icon Cache Object Class Record
  505. */
  506. externaldef (dticoncacheobjclassrec)
  507. DtIconCacheObjClassRec dtIconCacheObjClassRec =
  508. {
  509. {
  510. /* superclass */ (WidgetClass) &xmExtClassRec,
  511. /* class_name */ "DtIcon",
  512. /* widget_size */ sizeof(DtIconCacheObjRec),
  513. /* class_initialize */ NULL,
  514. /* chained class init */ NULL,
  515. /* class_inited */ False,
  516. /* initialize */ NULL,
  517. /* initialize hook */ NULL,
  518. /* realize */ NULL,
  519. /* actions */ NULL,
  520. /* num_actions */ 0,
  521. /* resources */ cache_resources,
  522. /* num_resources */ XtNumber(cache_resources),
  523. /* xrm_class */ NULLQUARK,
  524. /* compress_motion */ False,
  525. /* compress_exposure */ False,
  526. /* compress enter/exit*/ False,
  527. /* visible_interest */ False,
  528. /* destroy */ NULL,
  529. /* resize */ NULL,
  530. /* expose */ NULL,
  531. /* set_values */ NULL,
  532. /* set values hook */ NULL,
  533. /* set values almost */ NULL,
  534. /* get values hook */ NULL,
  535. /* accept_focus */ NULL,
  536. /* version */ XtVersion,
  537. /* callback offsetlst */ NULL,
  538. /* default trans */ NULL,
  539. /* query geo proc */ NULL,
  540. /* display accelerator*/ NULL,
  541. /* extension record */ NULL,
  542. },
  543. {
  544. /* synthetic resources */ cache_syn_resources,
  545. /* num_syn_resources */ XtNumber(cache_syn_resources),
  546. /* extension */ NULL,
  547. },
  548. };
  549. /*-------------------------------------------------------------
  550. ** Class Record
  551. */
  552. externaldef (dticonclassrec)
  553. DtIconClassRec dtIconClassRec =
  554. {
  555. /* Core Part
  556. */
  557. {
  558. (WidgetClass) &xmGadgetClassRec, /* superclass */
  559. "DtIcon", /* class_name */
  560. sizeof (DtIconRec), /* widget_size */
  561. ClassInitialize, /* class_initialize */
  562. ClassPartInitialize, /* class_part_initialize*/
  563. False, /* class_inited */
  564. (XtInitProc) Initialize, /* initialize */
  565. NULL, /* initialize_hook */
  566. NULL, /* realize */
  567. NULL, /* actions */
  568. 0, /* num_actions */
  569. resources, /* resources */
  570. XtNumber (resources), /* num_resources */
  571. NULLQUARK, /* xrm_class */
  572. True, /* compress_motion */
  573. True, /* compress_exposure */
  574. True, /* compress_enterleave */
  575. False, /* visible_interest */
  576. (XtWidgetProc) Destroy, /* destroy */
  577. (XtWidgetProc) Resize, /* resize */
  578. (XtExposeProc) Redisplay, /* expose */
  579. (XtSetValuesFunc) SetValues, /* set_values */
  580. NULL, /* set_values_hook */
  581. XtInheritSetValuesAlmost, /* set_values_almost */
  582. NULL, /* get_values_hook */
  583. NULL, /* accept_focus */
  584. XtVersion, /* version */
  585. NULL, /* callback private */
  586. NULL, /* tm_table */
  587. NULL, /* query_geometry */
  588. NULL, /* display_accelerator */
  589. (XtPointer)&iconBaseClassExtRec,/* extension */
  590. },
  591. /* XmGadget Part
  592. */
  593. {
  594. (XtWidgetProc) BorderHighlight, /* border_highlight */
  595. (XtWidgetProc) BorderUnhighlight, /* border_unhighlight */
  596. (XtActionProc) ArmAndActivate, /* arm_and_activate */
  597. (XmWidgetDispatchProc) InputDispatch, /* input_dispatch */
  598. (XmVisualChangeProc) VisualChange, /* visual_change */
  599. syn_resources, /* get_resources */
  600. XtNumber (syn_resources), /* num_get_resources */
  601. &IconClassCachePart, /* class_cache_part */
  602. NULL, /* extension */
  603. },
  604. /* DtIconGadget Part
  605. */
  606. {
  607. GetSize, /* get_size */
  608. GetPositions, /* get_positions */
  609. Draw, /* draw */
  610. CallCallback, /* call_callback */
  611. UpdateGCs, /* update_gcs */
  612. True, /* optimize_redraw */
  613. NULL, /* class_cache_part */
  614. NULL, /* extension */
  615. }
  616. };
  617. externaldef (dticongadgetclass) WidgetClass dtIconGadgetClass = (WidgetClass) &dtIconClassRec;
  618. /*-------------------------------------------------------------
  619. ** Private Functions
  620. **-------------------------------------------------------------
  621. */
  622. /************************************************************************
  623. *
  624. * The border highlighting and unhighlighting routines.
  625. *
  626. * These routines were originally in Obsolete.c but can not depend
  627. * on these routines to live forever. Therefore, copied into my
  628. * own space.
  629. *
  630. ************************************************************************/
  631. static void
  632. HighlightBorder(
  633. Widget w )
  634. {
  635. XtWidgetProc border_highlight;
  636. if (XmIsPrimitive(w)) {
  637. _DtProcessLock();
  638. border_highlight = xmPrimitiveClassRec.primitive_class.border_highlight;
  639. _DtProcessUnlock();
  640. (*border_highlight) (w);
  641. } else if (XmIsGadget(w)) {
  642. _DtProcessLock();
  643. border_highlight = xmGadgetClassRec.gadget_class.border_highlight;
  644. _DtProcessUnlock();
  645. (*border_highlight) (w);
  646. }
  647. }
  648. static void
  649. UnhighlightBorder(
  650. Widget w )
  651. {
  652. XtWidgetProc border_unhighlight;
  653. if (XmIsPrimitive(w)) {
  654. _DtProcessLock();
  655. border_unhighlight = xmPrimitiveClassRec.primitive_class.border_unhighlight;
  656. _DtProcessUnlock();
  657. (*border_unhighlight) (w);
  658. } else if (XmIsGadget(w)) {
  659. _DtProcessLock();
  660. border_unhighlight = xmGadgetClassRec.gadget_class.border_unhighlight;
  661. _DtProcessUnlock();
  662. (*border_unhighlight) (w);
  663. }
  664. }
  665. /*-------------------------------------------------------------
  666. ** GetMaskGC
  667. ** Get normal and background graphics contexts.
  668. */
  669. static GC
  670. GetMaskGC(
  671. DtIconGadget g,
  672. Position x,
  673. Position y)
  674. {
  675. if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
  676. XSetClipOrigin(XtDisplay(g),
  677. G_ClipGC(g),
  678. x, y);
  679. return G_ClipGC(g);
  680. }
  681. else {
  682. return G_NormalGC(g);
  683. }
  684. }
  685. /*-------------------------------------------------------------
  686. ** GetDefaultBackground
  687. ** Copy background pixel from Manager parent.
  688. */
  689. /* ARGSUSED */
  690. static void
  691. GetDefaultBackground(
  692. Widget g,
  693. int offset,
  694. XrmValue *value )
  695. {
  696. static Pixel pixel;
  697. XmManagerWidget parent = (XmManagerWidget) XtParent (g);
  698. value->addr = (XtPointer) &pixel;
  699. value->size = sizeof (Pixel);
  700. if (XmIsManager ((Widget) parent))
  701. pixel = M_Background (parent);
  702. else
  703. XmeGetDefaultPixel (g, XmBACKGROUND, offset, value);
  704. }
  705. /*-------------------------------------------------------------
  706. ** GetDefaultForeground
  707. ** Copy foreground pixel from Manager parent.
  708. */
  709. static void
  710. GetDefaultForeground(
  711. Widget g,
  712. int offset,
  713. XrmValue *value )
  714. {
  715. static Pixel pixel;
  716. XmManagerWidget parent = (XmManagerWidget) XtParent (g);
  717. value->addr = (XtPointer) &pixel;
  718. value->size = sizeof (Pixel);
  719. if (XmIsManager ((Widget) parent))
  720. pixel = M_Foreground (parent);
  721. else
  722. XmeGetDefaultPixel (g, XmFOREGROUND, offset, value);
  723. }
  724. /*-------------------------------------------------------------
  725. ** GetDefaultFillMode
  726. ** Get default fill mode.
  727. */
  728. /* ARGSUSED */
  729. static void
  730. GetDefaultFillMode(
  731. Widget w,
  732. int offset,
  733. XrmValue *value )
  734. {
  735. static unsigned char fill_mode;
  736. DtIconGadget g = (DtIconGadget) w;
  737. value->addr = (XtPointer) &fill_mode;
  738. value->size = sizeof (unsigned char);
  739. if (G_ShadowThickness (g) == 0)
  740. fill_mode = XmFILL_PARENT;
  741. else
  742. fill_mode = XmFILL_SELF;
  743. }
  744. /*-------------------------------------------------------------
  745. ** GetSpacing
  746. ** Convert from pixels to horizontal or vertical units.
  747. */
  748. static void
  749. GetSpacing(
  750. Widget w,
  751. int offset,
  752. XtArgVal *value )
  753. {
  754. DtIconCacheObject icon_co = (DtIconCacheObject) w;
  755. if (G_CachePixmapPosition (icon_co) == XmPIXMAP_TOP ||
  756. G_CachePixmapPosition (icon_co) == XmPIXMAP_BOTTOM ||
  757. G_CachePixmapPosition (icon_co) == XmPIXMAP_MIDDLE)
  758. XmeFromVerticalPixels ((Widget)icon_co, offset, value);
  759. else
  760. XmeFromHorizontalPixels ((Widget)icon_co, offset, value);
  761. }
  762. /*-------------------------------------------------------------
  763. ** GetString
  764. ** Convert string from internal to external form.
  765. */
  766. /* ARGSUSED */
  767. static void
  768. GetString(
  769. Widget w,
  770. int offset,
  771. XtArgVal *value )
  772. {
  773. DtIconGadget g = (DtIconGadget) w;
  774. XmString string;
  775. string = XmStringCopy (G_String (g));
  776. *value = (XtArgVal) string;
  777. }
  778. /*-------------------------------------------------------------
  779. ** IconEventHandler
  780. ** Event handler for middle button events.
  781. */
  782. /* ARGSUSED */
  783. static void
  784. IconEventHandler(
  785. Widget w,
  786. XtPointer client_data,
  787. XButtonEvent *event )
  788. {
  789. DtIconGadget g = NULL;
  790. g = (DtIconGadget) XmObjectAtPoint (w, event->x, event->y);
  791. if (!g || !DtIsIcon ((Widget)g))
  792. return;
  793. if (event->button == Button2 || event->button == Button3)
  794. {
  795. if (event->type == ButtonPress)
  796. InputDispatch ((Widget) g, event, XmARM_EVENT);
  797. else if (event->type == ButtonRelease)
  798. InputDispatch ((Widget) g, event, XmACTIVATE_EVENT);
  799. }
  800. }
  801. /*-------------------------------------------------------------
  802. ** ClickTimeout
  803. ** Clear Click flags.
  804. */
  805. /* ARGSUSED */
  806. static void
  807. ClickTimeout(
  808. Widget w,
  809. XtIntervalId *id )
  810. {
  811. DtIconGadget g = (DtIconGadget) w;
  812. Time last_time, end_time;
  813. if (! G_Armed (g))
  814. {
  815. G_ClickTimerID (g) = 0;
  816. XtFree ((char *)G_ClickEvent (g));
  817. G_ClickEvent (g) = NULL;
  818. return;
  819. }
  820. last_time = XtLastTimestampProcessed (XtDisplay (g));
  821. /*
  822. * fix for bug# 4504
  823. */
  824. if( G_ClickEvent (g) == NULL) return;
  825. end_time = G_ClickEvent (g) -> time + (Time)
  826. XtGetMultiClickTime (XtDisplay (g));
  827. /* Sync and reset timer if server interval may not have elapsed.
  828. */
  829. if ((last_time < end_time) && G_Sync (g))
  830. {
  831. G_Sync (g) = False;
  832. XSync (XtDisplay (g), False);
  833. G_ClickTimerID (g) =
  834. XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget)g),
  835. (unsigned long) 50,
  836. (XtTimerCallbackProc)ClickTimeout,
  837. (XtPointer) g);
  838. }
  839. /* Handle Select action.
  840. */
  841. else
  842. {
  843. CallCallbackProc call_callback;
  844. XtExposeProc expose;
  845. _DtProcessLock();
  846. expose = XtCoreProc(w, expose);
  847. call_callback = C_CallCallback(XtClass(w));
  848. _DtProcessUnlock();
  849. G_ClickTimerID (g) = 0;
  850. G_Armed (g) = False;
  851. (*call_callback) (g, G_Callback (g), XmCR_SELECT,
  852. (XEvent *)G_ClickEvent (g));
  853. if ((G_Behavior (g) == XmICON_DRAG) &&
  854. (G_ShadowThickness (g) == 0))
  855. {
  856. /* Do nothing */
  857. }
  858. else
  859. (*expose) ((Widget)g, (XEvent*)G_ClickEvent (g), NULL);
  860. XtFree ((char *)G_ClickEvent (g));
  861. G_ClickEvent (g) = NULL;
  862. }
  863. }
  864. /*-------------------------------------------------------------
  865. ** Action Procs
  866. **-------------------------------------------------------------
  867. */
  868. /*-------------------------------------------------------------
  869. ** IconArm
  870. ** Handle Arm action.
  871. */
  872. static void
  873. IconArm(
  874. Widget w,
  875. XEvent *event )
  876. {
  877. DtIconGadget g = (DtIconGadget) w;
  878. if (G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
  879. return;
  880. G_Armed (g) = True;
  881. if (G_Behavior (g) == XmICON_DRAG)
  882. {
  883. CallCallbackProc call_callback;
  884. _DtProcessLock();
  885. call_callback = C_CallCallback(XtClass(g));
  886. _DtProcessUnlock();
  887. (*call_callback) (g, G_Callback (g), XmCR_ARM, event);
  888. }
  889. if ((G_Behavior (g) == XmICON_DRAG) &&
  890. (G_ShadowThickness (g) == 0))
  891. {
  892. /* Do nothing */
  893. }
  894. else
  895. {
  896. XtExposeProc expose;
  897. _DtProcessLock();
  898. expose = XtCoreProc(w, expose);
  899. _DtProcessUnlock();
  900. (*expose) ((Widget)g, event, NULL);
  901. }
  902. }
  903. /*-------------------------------------------------------------
  904. ** IconDisarm
  905. ** Handle Disarm action.
  906. */
  907. static void
  908. IconDisarm(
  909. Widget w,
  910. XEvent *event )
  911. {
  912. DtIconGadget g = (DtIconGadget) w;
  913. if (! G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
  914. return;
  915. G_Armed (g) = False;
  916. if (G_Behavior (g) == XmICON_DRAG)
  917. {
  918. CallCallbackProc call_callback;
  919. XtExposeProc expose;
  920. _DtProcessLock();
  921. call_callback = C_CallCallback(XtClass(g));
  922. expose = XtCoreProc(w, expose);
  923. _DtProcessUnlock();
  924. (*call_callback) (g, G_Callback (g), XmCR_DISARM, event);
  925. (*expose) ((Widget)g, event, NULL);
  926. }
  927. }
  928. /*-------------------------------------------------------------
  929. ** IconActivate
  930. ** Handle Activate action.
  931. */
  932. static void
  933. IconActivate(
  934. Widget w,
  935. XEvent *event )
  936. {
  937. DtIconGadget g = (DtIconGadget) w;
  938. unsigned long delay;
  939. XButtonEvent * b_event = (XButtonEvent *) event;
  940. CallCallbackProc call_callback;
  941. XtExposeProc expose;
  942. if (! G_Armed (g))
  943. return;
  944. _DtProcessLock();
  945. call_callback = C_CallCallback(XtClass(g));
  946. expose = XtCoreProc(w, expose);
  947. _DtProcessUnlock();
  948. if (G_Behavior (g) == XmICON_BUTTON)
  949. {
  950. G_Armed (g) = False;
  951. (*call_callback) (g, G_Callback (g), XmCR_ACTIVATE, event);
  952. (*expose) ((Widget)g, event, NULL);
  953. }
  954. else if (G_Behavior (g) == XmICON_TOGGLE)
  955. {
  956. G_Armed (g) = False;
  957. G_Set (g) = ! G_Set (g);
  958. (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, event);
  959. }
  960. else if (G_Behavior (g) == XmICON_DRAG)
  961. {
  962. if (G_ClickTimerID (g))
  963. {
  964. G_ClickTimerID (g) = 0;
  965. XtFree ((char *)G_ClickEvent (g));
  966. G_ClickEvent (g) = NULL;
  967. G_Armed (g) = False;
  968. (*call_callback) (g, G_Callback (g),
  969. XmCR_DEFAULT_ACTION, event);
  970. }
  971. else
  972. {
  973. delay = (unsigned long)
  974. XtGetMultiClickTime (XtDisplay (g));
  975. G_ClickEvent (g) = (XButtonEvent *)
  976. XtMalloc (sizeof (XButtonEvent));
  977. *(G_ClickEvent (g)) = *b_event;
  978. G_Sync (g) = True;
  979. G_ClickTimerID (g) =
  980. XtAppAddTimeOut (
  981. XtWidgetToApplicationContext ((Widget)g),
  982. delay, (XtTimerCallbackProc)ClickTimeout,
  983. (XtPointer) g);
  984. }
  985. if (G_ShadowThickness (g) > 0)
  986. (*expose) ((Widget)g, event, NULL);
  987. }
  988. }
  989. /*-------------------------------------------------------------
  990. ** IconDrag
  991. ** Handle Drag action.
  992. */
  993. static void
  994. IconDrag(
  995. Widget w,
  996. XEvent *event )
  997. {
  998. DtIconGadget g = (DtIconGadget) w;
  999. if (G_Behavior (g) == XmICON_DRAG)
  1000. {
  1001. CallCallbackProc call_callback;
  1002. _DtProcessLock();
  1003. call_callback = C_CallCallback(XtClass(w));
  1004. _DtProcessUnlock();
  1005. (*call_callback) (g, G_Callback (g), XmCR_DRAG, event);
  1006. }
  1007. }
  1008. /*-------------------------------------------------------------
  1009. ** IconPopup
  1010. ** Handle button 3 - popup's
  1011. */
  1012. static void
  1013. IconPopup(
  1014. Widget w,
  1015. XEvent *event )
  1016. {
  1017. DtIconGadget g = (DtIconGadget) w;
  1018. CallCallbackProc call_callback;
  1019. _DtProcessLock();
  1020. call_callback = C_CallCallback(XtClass(w));
  1021. _DtProcessUnlock();
  1022. (*call_callback) (g, G_Callback (g), XmCR_POPUP, event);
  1023. }
  1024. /*-------------------------------------------------------------
  1025. ** IconEnter
  1026. ** Handle Enter action.
  1027. */
  1028. static void
  1029. IconEnter(
  1030. Widget w,
  1031. XEvent *event )
  1032. {
  1033. DtIconGadget g = (DtIconGadget) w;
  1034. _XmEnterGadget (w, (XEvent *)event,
  1035. (String *)NULL,(Cardinal *)0);
  1036. if (G_Armed (g))
  1037. {
  1038. if ((G_Behavior (g) == XmICON_BUTTON) ||
  1039. (G_Behavior (g) == XmICON_TOGGLE))
  1040. {
  1041. XtExposeProc expose;
  1042. _DtProcessLock();
  1043. expose = XtCoreProc(w, expose);
  1044. _DtProcessUnlock();
  1045. (*expose) ((Widget)g, event, NULL);
  1046. }
  1047. }
  1048. }
  1049. /*-------------------------------------------------------------
  1050. ** IconLeave
  1051. ** Handle Leave action.
  1052. */
  1053. static void
  1054. IconLeave(
  1055. Widget w,
  1056. XEvent *event )
  1057. {
  1058. DtIconGadget g = (DtIconGadget) w;
  1059. _XmLeaveGadget (w, (XEvent *)event,
  1060. (String *)NULL, (Cardinal *)0);
  1061. if (G_Armed (g))
  1062. {
  1063. if ((G_Behavior (g) == XmICON_BUTTON) ||
  1064. (G_Behavior (g) == XmICON_TOGGLE))
  1065. {
  1066. XtExposeProc expose;
  1067. _DtProcessLock();
  1068. expose = XtCoreProc(w, expose);
  1069. _DtProcessUnlock();
  1070. G_Armed (g) = False;
  1071. (*expose) ((Widget)g, event, NULL);
  1072. G_Armed (g) = True;
  1073. }
  1074. }
  1075. }
  1076. /*-------------------------------------------------------------
  1077. ** Core Procs
  1078. **-------------------------------------------------------------
  1079. */
  1080. /*-------------------------------------------------------------
  1081. ** ClassInitialize
  1082. ** Initialize gadget class.
  1083. */
  1084. static void
  1085. ClassInitialize( void )
  1086. {
  1087. _DtRegisterNewConverters ();
  1088. iconBaseClassExtRec.record_type = XmQmotif;
  1089. }
  1090. /*-------------------------------------------------------------
  1091. ** ClassPartInitialize
  1092. ** Initialize gadget class part.
  1093. */
  1094. static void
  1095. ClassPartInitialize (
  1096. WidgetClass wc)
  1097. {
  1098. DtIconGadgetClass ic = (DtIconGadgetClass) wc;
  1099. DtIconGadgetClass super = (DtIconGadgetClass) ic->rect_class.superclass;
  1100. if (C_GetSize (ic) == DtInheritGetSize)
  1101. C_GetSize (ic) = C_GetSize (super);
  1102. if (C_GetPositions (ic) == DtInheritGetPositions)
  1103. C_GetPositions (ic) = C_GetPositions (super);
  1104. if (C_Draw (ic) == DtInheritDraw)
  1105. C_Draw (ic) = C_Draw (super);
  1106. if (C_CallCallback (ic) == DtInheritCallCallback)
  1107. C_CallCallback (ic) = C_CallCallback (super);
  1108. if (C_UpdateGCs (ic) == DtInheritUpdateGCs)
  1109. C_UpdateGCs (ic) = C_UpdateGCs (super);
  1110. }
  1111. /*-------------------------------------------------------------
  1112. ** Cache Procs
  1113. **-------------------------------------------------------------
  1114. */
  1115. /*-------------------------------------------------------------
  1116. ** IconCacheCompare
  1117. **
  1118. */
  1119. static int
  1120. IconCacheCompare(
  1121. XtPointer A,
  1122. XtPointer B )
  1123. {
  1124. DtIconCacheObjPart *icon_inst = (DtIconCacheObjPart *) A ;
  1125. DtIconCacheObjPart *icon_cache_inst = (DtIconCacheObjPart *) B ;
  1126. if ((icon_inst->fill_on_arm == icon_cache_inst->fill_on_arm) &&
  1127. (icon_inst->recompute_size== icon_cache_inst->recompute_size) &&
  1128. (icon_inst->pixmap_position== icon_cache_inst->pixmap_position) &&
  1129. (icon_inst->string_position== icon_cache_inst->string_position) &&
  1130. (icon_inst->alignment == icon_cache_inst->alignment) &&
  1131. (icon_inst->behavior == icon_cache_inst->behavior) &&
  1132. (icon_inst->draw_shadow == icon_cache_inst->draw_shadow) &&
  1133. (icon_inst->fill_mode == icon_cache_inst->fill_mode) &&
  1134. (icon_inst->margin_width== icon_cache_inst->margin_width) &&
  1135. (icon_inst->margin_height== icon_cache_inst->margin_height) &&
  1136. (icon_inst->string_height== icon_cache_inst->string_height) &&
  1137. (icon_inst->spacing== icon_cache_inst->spacing) &&
  1138. (icon_inst->foreground== icon_cache_inst->foreground) &&
  1139. (icon_inst->background== icon_cache_inst->background) &&
  1140. (icon_inst->arm_color== icon_cache_inst->arm_color))
  1141. return 1;
  1142. else
  1143. return 0;
  1144. }
  1145. /*-------------------------------------------------------------
  1146. ** SecondaryObjectCreate
  1147. **
  1148. */
  1149. static void
  1150. SecondaryObjectCreate(
  1151. Widget req,
  1152. Widget new_w,
  1153. ArgList args,
  1154. Cardinal *num_args )
  1155. {
  1156. XmBaseClassExt *cePtr;
  1157. XmWidgetExtData extData;
  1158. WidgetClass wc;
  1159. Cardinal size;
  1160. XtPointer newSec, reqSec;
  1161. XtResourceList resources;
  1162. Cardinal num_resources;
  1163. _DtProcessLock();
  1164. cePtr = _XmGetBaseClassExtPtr(XtClass(new_w), XmQmotif);
  1165. wc = (*cePtr)->secondaryObjectClass;
  1166. if (NULL == wc) return;
  1167. size = wc->core_class.widget_size;
  1168. resources = wc->core_class.resources;
  1169. num_resources = wc->core_class.num_resources;
  1170. newSec = _XmExtObjAlloc(size);
  1171. reqSec = _XmExtObjAlloc(size);
  1172. _DtProcessUnlock();
  1173. /*
  1174. * fetch the resources in superclass to subclass order
  1175. */
  1176. XtGetSubresources(new_w, newSec, NULL, NULL,
  1177. resources, num_resources, args, *num_args );
  1178. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1179. extData->widget = (Widget)newSec;
  1180. extData->reqWidget = (Widget)reqSec;
  1181. ((DtIconCacheObject)newSec)->ext.extensionType = XmCACHE_EXTENSION;
  1182. ((DtIconCacheObject)newSec)->ext.logicalParent = new_w;
  1183. _XmPushWidgetExtData(new_w, extData,
  1184. ((DtIconCacheObject)newSec)->ext.extensionType);
  1185. memcpy(reqSec, newSec, size);
  1186. /*
  1187. * fill out cache pointers
  1188. */
  1189. Icon_Cache(new_w) = &(((DtIconCacheObject)extData->widget)->icon_cache);
  1190. Icon_Cache(req) = &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
  1191. }
  1192. /*-------------------------------------------------------------
  1193. ** InitializePostHook
  1194. **
  1195. */
  1196. /* ARGSUSED */
  1197. static void
  1198. InitializePosthook(
  1199. Widget req,
  1200. Widget new,
  1201. ArgList args,
  1202. Cardinal *num_args )
  1203. {
  1204. XmWidgetExtData ext;
  1205. DtIconGadget lw = (DtIconGadget)new;
  1206. /*
  1207. * - register parts in cache.
  1208. * - update cache pointers
  1209. * - and free req
  1210. */
  1211. _DtProcessLock();
  1212. Icon_Cache(lw) = (DtIconCacheObjPart *)
  1213. _XmCachePart( Icon_ClassCachePart(lw),
  1214. (XtPointer) Icon_Cache(lw),
  1215. sizeof(DtIconCacheObjPart));
  1216. /*
  1217. * might want to break up into per-class work that gets explicitly
  1218. * chained. For right now, each class has to replicate all
  1219. * superclass logic in hook routine
  1220. */
  1221. /* * free the req subobject used for comparisons
  1222. */
  1223. _XmPopWidgetExtData((Widget) lw, &ext, XmCACHE_EXTENSION);
  1224. _XmExtObjFree((XtPointer)ext->widget);
  1225. _XmExtObjFree((XtPointer)ext->reqWidget);
  1226. _DtProcessUnlock();
  1227. XtFree( (char *) ext);
  1228. }
  1229. /*-------------------------------------------------------------
  1230. ** SetValuesPrehook
  1231. **
  1232. */
  1233. /* ARGSUSED */
  1234. static Boolean
  1235. SetValuesPrehook(
  1236. Widget oldParent,
  1237. Widget refParent,
  1238. Widget newParent,
  1239. ArgList args,
  1240. Cardinal *num_args )
  1241. {
  1242. XmWidgetExtData extData;
  1243. XmBaseClassExt *cePtr;
  1244. WidgetClass ec;
  1245. DtIconCacheObject newSec, reqSec;
  1246. Cardinal size;
  1247. XtResourceList resources;
  1248. Cardinal num_resources;
  1249. _DtProcessLock();
  1250. cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
  1251. ec = (*cePtr)->secondaryObjectClass;
  1252. size = ec->core_class.widget_size;
  1253. resources = ec->core_class.resources;
  1254. num_resources = ec->core_class.num_resources;
  1255. /* allocate copies and fill from cache */
  1256. newSec = (DtIconCacheObject) _XmExtObjAlloc(size);
  1257. reqSec = (DtIconCacheObject) _XmExtObjAlloc(size);
  1258. _DtProcessUnlock();
  1259. newSec->object.self = (Widget)newSec;
  1260. newSec->object.widget_class = ec;
  1261. newSec->object.parent = XtParent(newParent);
  1262. newSec->object.xrm_name = newParent->core.xrm_name;
  1263. newSec->object.being_destroyed = False;
  1264. newSec->object.destroy_callbacks = NULL;
  1265. newSec->object.constraints = NULL;
  1266. newSec->ext.logicalParent = newParent;
  1267. newSec->ext.extensionType = XmCACHE_EXTENSION;
  1268. memcpy(&(newSec->icon_cache),
  1269. Icon_Cache(newParent),
  1270. sizeof(DtIconCacheObjPart));
  1271. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1272. extData->widget = (Widget)newSec;
  1273. extData->reqWidget = (Widget)reqSec;
  1274. _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
  1275. _XmGadgetImportSecondaryArgs(newParent, args, num_args);
  1276. XtSetSubvalues((XtPointer)newSec, resources, num_resources,
  1277. args, *num_args);
  1278. _XmExtImportArgs((Widget)newSec, args, num_args);
  1279. memcpy((XtPointer)reqSec, (XtPointer)newSec, size);
  1280. Icon_Cache(newParent) = &(((DtIconCacheObject)newSec)->icon_cache);
  1281. Icon_Cache(refParent) =
  1282. &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
  1283. return FALSE;
  1284. }
  1285. /*-------------------------------------------------------------
  1286. ** GetValuesPrehook
  1287. **
  1288. */
  1289. static void
  1290. GetValuesPrehook(
  1291. Widget newParent,
  1292. ArgList args,
  1293. Cardinal *num_args )
  1294. {
  1295. XmWidgetExtData extData;
  1296. XmBaseClassExt *cePtr;
  1297. WidgetClass ec;
  1298. DtIconCacheObject newSec;
  1299. Cardinal size;
  1300. XtResourceList resources;
  1301. Cardinal num_resources;
  1302. _DtProcessLock();
  1303. cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
  1304. ec = (*cePtr)->secondaryObjectClass;
  1305. size = ec->core_class.widget_size;
  1306. resources = ec->core_class.resources;
  1307. num_resources = ec->core_class.num_resources;
  1308. newSec = (DtIconCacheObject)_XmExtObjAlloc(size);
  1309. _DtProcessUnlock();
  1310. newSec->object.self = (Widget)newSec;
  1311. newSec->object.widget_class = ec;
  1312. newSec->object.parent = XtParent(newParent);
  1313. newSec->object.xrm_name = newParent->core.xrm_name;
  1314. newSec->object.being_destroyed = False;
  1315. newSec->object.destroy_callbacks = NULL;
  1316. newSec->object.constraints = NULL;
  1317. newSec->ext.logicalParent = newParent;
  1318. newSec->ext.extensionType = XmCACHE_EXTENSION;
  1319. memcpy( &(newSec->icon_cache),
  1320. Icon_Cache(newParent),
  1321. sizeof(DtIconCacheObjPart));
  1322. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1323. extData->widget = (Widget)newSec;
  1324. _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
  1325. XtGetSubvalues((XtPointer)newSec, resources, num_resources,
  1326. args, *num_args);
  1327. _XmExtGetValuesHook((Widget)newSec, args, num_args);
  1328. }
  1329. /*-------------------------------------------------------------
  1330. ** GetValuesPosthook
  1331. **
  1332. */
  1333. /* ARGSUSED */
  1334. static void
  1335. GetValuesPosthook(
  1336. Widget new,
  1337. ArgList args,
  1338. Cardinal *num_args )
  1339. {
  1340. XmWidgetExtData ext;
  1341. _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
  1342. _DtProcessLock();
  1343. _XmExtObjFree((XtPointer)ext->widget);
  1344. _DtProcessUnlock();
  1345. XtFree((char *)ext);
  1346. }
  1347. /*-------------------------------------------------------------
  1348. ** SetValuesPosthook
  1349. **
  1350. */
  1351. /* ARGSUSED */
  1352. static Boolean
  1353. SetValuesPosthook(
  1354. Widget current,
  1355. Widget req,
  1356. Widget new,
  1357. ArgList args,
  1358. Cardinal *num_args )
  1359. {
  1360. XmWidgetExtData ext;
  1361. /*
  1362. * - register parts in cache.
  1363. * - update cache pointers
  1364. * - and free req
  1365. */
  1366. /* assign if changed! */
  1367. _DtProcessLock();
  1368. if (!IconCacheCompare((XtPointer)Icon_Cache(new),
  1369. (XtPointer)Icon_Cache(current)))
  1370. {
  1371. _XmCacheDelete((XtPointer) Icon_Cache(current)); /* delete the old one */
  1372. Icon_Cache(new) = (DtIconCacheObjPart *)
  1373. _XmCachePart(Icon_ClassCachePart(new),
  1374. (XtPointer) Icon_Cache(new),
  1375. sizeof(DtIconCacheObjPart));
  1376. } else
  1377. Icon_Cache(new) = Icon_Cache(current);
  1378. _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
  1379. _XmExtObjFree((XtPointer)ext->widget);
  1380. _XmExtObjFree((XtPointer)ext->reqWidget);
  1381. _DtProcessUnlock();
  1382. XtFree((char *)ext);
  1383. return FALSE;
  1384. }
  1385. /*--------------------------------------------------------------------------
  1386. ** QualifyIconLocalCache
  1387. ** Checks to see if local cache is set up
  1388. */
  1389. static void
  1390. QualifyIconLocalCache(DtIconGadget g, DtIconCacheObjPart *local_cache)
  1391. {
  1392. _DtProcessLock();
  1393. ClassCacheCopy(Icon_ClassCachePart(g))((XtPointer) Icon_Cache(g),
  1394. (XtPointer) local_cache,
  1395. sizeof(DtIconCacheObjPart));
  1396. _DtProcessUnlock();
  1397. }
  1398. /************************************************************************
  1399. *
  1400. * ReCacheIcon_r()
  1401. * Check to see if ReCaching is necessary as a result of fields having
  1402. * been set by a mananger widget. This routine is called by the
  1403. * manager widget in their SetValues after a change is made to any
  1404. * of Icon's cached fields.
  1405. *
  1406. ************************************************************************/
  1407. static void
  1408. ReCacheIcon_r(DtIconCacheObjPart *local_cache, DtIconGadget g)
  1409. {
  1410. if (!IconCacheCompare( (XtPointer)local_cache, (XtPointer)Icon_Cache(g)))
  1411. {
  1412. _DtProcessLock();
  1413. _XmCacheDelete( (XtPointer) Icon_Cache(g)); /* delete the old one */
  1414. Icon_Cache(g) = (DtIconCacheObjPart *)
  1415. _XmCachePart(Icon_ClassCachePart(g),
  1416. (XtPointer) local_cache,
  1417. sizeof(DtIconCacheObjPart));
  1418. _DtProcessUnlock();
  1419. }
  1420. }
  1421. /*********************************************************************
  1422. *
  1423. * GetParentBackgroundGC
  1424. * Get the graphics context used for erasing their highlight border.
  1425. *
  1426. *********************************************************************/
  1427. static void
  1428. GetParentBackgroundGC(
  1429. DtIconGadget g )
  1430. {
  1431. XGCValues values;
  1432. XtGCMask valueMask;
  1433. Widget parent = XtParent((Widget)g);
  1434. valueMask = GCForeground | GCBackground;
  1435. values.foreground = parent->core.background_pixel;
  1436. if (XmIsManager(parent))
  1437. values.background = ((XmManagerWidget) parent)->manager.foreground;
  1438. else
  1439. values.background = ((XmPrimitiveWidget) parent)->primitive.foreground;
  1440. if ((parent->core.background_pixmap != None) &&
  1441. (parent->core.background_pixmap != XmUNSPECIFIED_PIXMAP))
  1442. {
  1443. valueMask |= GCFillStyle | GCTile;
  1444. values.fill_style = FillTiled;
  1445. values.tile = parent->core.background_pixmap;
  1446. }
  1447. G_SavedParentBG(g) = parent->core.background_pixel;
  1448. G_ParentBackgroundGC(g) = XtGetGC (parent, valueMask, &values);
  1449. }
  1450. /*-------------------------------------------------------------
  1451. ** Initialize
  1452. ** Initialize a new gadget instance.
  1453. */
  1454. static void
  1455. Initialize(
  1456. Widget request_w,
  1457. Widget new_w )
  1458. {
  1459. DtIconGadget request = (DtIconGadget) request_w,
  1460. new = (DtIconGadget) new_w;
  1461. Window root;
  1462. int int_x = 0, int_y = 0;
  1463. unsigned int int_w = 0, int_h = 0,
  1464. int_bw, depth;
  1465. Dimension w, h;
  1466. EventMask mask;
  1467. String name = NULL;
  1468. UpdateGCsProc update_gcs;
  1469. G_Sync (new) = False;
  1470. /* Validate behavior.
  1471. */
  1472. if (G_Behavior (new) != XmICON_LABEL &&
  1473. G_Behavior (new) != XmICON_BUTTON &&
  1474. G_Behavior (new) != XmICON_TOGGLE &&
  1475. G_Behavior (new) != XmICON_DRAG)
  1476. {
  1477. XmeWarning ((Widget)new, WARN_BEHAVIOR);
  1478. G_Behavior (new) = XmICON_BUTTON;
  1479. }
  1480. /* Set the input mask for events handled by Manager.
  1481. */
  1482. G_EventMask (new) = (XmARM_EVENT | XmACTIVATE_EVENT |
  1483. XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
  1484. XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
  1485. XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
  1486. /* Add event handler for icon events.
  1487. */
  1488. if (G_Behavior (new) == XmICON_DRAG)
  1489. {
  1490. mask = ButtonPressMask|ButtonReleaseMask;
  1491. XtAddEventHandler (XtParent (new), mask, False,
  1492. (XtEventHandler) IconEventHandler, 0);
  1493. }
  1494. G_ClickTimerID (new) = 0;
  1495. G_ClickEvent (new) = NULL;
  1496. G_Armed (new) = False;
  1497. G_Mask (new) = NULL;
  1498. if (G_Pixmap (new) == XmUNSPECIFIED_PIXMAP)
  1499. G_Pixmap (new) = NULL;
  1500. if (G_ImageName (new) || G_Pixmap (new))
  1501. {
  1502. if (G_ImageName (new))
  1503. {
  1504. /* Try to get pixmap from image name.
  1505. */
  1506. G_Pixmap (new) =
  1507. XmGetPixmap (XtScreen (new), G_ImageName (new),
  1508. G_PixmapForeground (new),
  1509. G_PixmapBackground (new));
  1510. if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
  1511. {
  1512. name = G_ImageName (new);
  1513. G_Mask (new) =
  1514. _DtGetMask(XtScreen (new), G_ImageName
  1515. (new));
  1516. }
  1517. else
  1518. {
  1519. /* warning? */
  1520. name = NULL;
  1521. G_Pixmap (new) = NULL;
  1522. }
  1523. }
  1524. /* Update width and height; copy image name.
  1525. */
  1526. if (G_Pixmap (new))
  1527. {
  1528. XGetGeometry (XtDisplay (new), G_Pixmap (new),
  1529. &root, &int_x, &int_y, &int_w, &int_h,
  1530. &int_bw, &depth);
  1531. }
  1532. if (name)
  1533. {
  1534. G_ImageName (new) = XtNewString(name);
  1535. }
  1536. else
  1537. G_ImageName (new) = NULL;
  1538. }
  1539. G_PixmapWidth(new) = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
  1540. G_PixmapHeight(new) = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
  1541. /* Validate fill mode.
  1542. */
  1543. if (G_FillMode (new) != XmFILL_NONE &&
  1544. G_FillMode (new) != XmFILL_PARENT &&
  1545. G_FillMode (new) != XmFILL_TRANSPARENT &&
  1546. G_FillMode (new) != XmFILL_SELF)
  1547. {
  1548. XmeWarning ((Widget)new, WARN_FILL_MODE);
  1549. if (G_ShadowThickness (new) > 0)
  1550. G_FillMode (new) = XmFILL_SELF;
  1551. else
  1552. G_FillMode (new) = XmFILL_PARENT;
  1553. }
  1554. /* Validate pixmap position.
  1555. */
  1556. if (G_StringPosition (new) != UNSPECIFIED_CHAR)
  1557. G_PixmapPosition (new) = G_StringPosition (new);
  1558. if (G_PixmapPosition (new) == UNSPECIFIED_CHAR)
  1559. G_PixmapPosition (new) = XmPIXMAP_LEFT;
  1560. else if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
  1561. G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
  1562. G_PixmapPosition (new) != XmPIXMAP_TOP &&
  1563. G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
  1564. G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
  1565. {
  1566. XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
  1567. G_PixmapPosition (new) = XmPIXMAP_LEFT;
  1568. }
  1569. G_StringPosition (new) = G_PixmapPosition (new);
  1570. /* Validate alignment.
  1571. */
  1572. if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
  1573. G_Alignment (new) != XmALIGNMENT_CENTER &&
  1574. G_Alignment (new) != XmALIGNMENT_END)
  1575. {
  1576. XmeWarning ((Widget)new, WARN_ALIGNMENT);
  1577. G_Alignment (new) = XmALIGNMENT_BEGINNING;
  1578. }
  1579. /* Validate shadow type.
  1580. */
  1581. if (G_ShadowType (new) != XmSHADOW_IN &&
  1582. G_ShadowType (new) != XmSHADOW_OUT &&
  1583. G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
  1584. G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
  1585. {
  1586. Xm