Icon.c 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027
  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. #include "DtSvcInternal.h"
  62. #include <Xm/XmPrivate.h> /* Motif _XmEnterGadget and friends */
  63. /*-------------------------------------------------------------
  64. ** Public Interface
  65. **-------------------------------------------------------------
  66. */
  67. WidgetClass dtIconGadgetClass;
  68. #define Min(x, y) (((x) < (y)) ? (x) : (y))
  69. #define Max(x, y) (((x) > (y)) ? (x) : (y))
  70. #define Limit(x, lim) (((lim) == 0 || (x) <= (lim))? (x): (lim))
  71. /*-------------------------------------------------------------
  72. ** Forward Declarations
  73. */
  74. extern void _DtRegisterNewConverters ( void );
  75. extern char * _XmExtObjAlloc(int size);
  76. extern void _XmExtObjFree(XtPointer element);
  77. extern void _XmSelectColorDefault ( Widget, int, XrmValue * );
  78. #define SPACING_DEFAULT 2
  79. #define MARGIN_DEFAULT 2
  80. #define UNSPECIFIED_DIMENSION 9999
  81. #define UNSPECIFIED_CHAR 255
  82. #define WARN_ALIGNMENT _DtMsgIcon_0000
  83. #define WARN_BEHAVIOR _DtMsgIcon_0001
  84. #define WARN_FILL_MODE _DtMsgIcon_0002
  85. #define WARN_PIXMAP_POSITION _DtMsgIcon_0003
  86. #define WARN_MARGIN _DtMsgIcon_0004
  87. #define WARN_SHADOW_TYPE _DtMsgIcon_0005
  88. #define MgrParent(g) ((XmManagerWidget) (XmIsManager(XtParent(g)) ? (XtParent(g)) : (XtParent(XtParent(g)))))
  89. /******** Private Function Declarations ********/
  90. extern void _DtIconRegisterDropsite(
  91. Widget w) ;
  92. /******** End Private Function Declarations ********/
  93. /******** Static Function Declarations ********/
  94. static int IconCacheCompare(
  95. XtPointer A,
  96. XtPointer B) ;
  97. static void ReCacheIcon_r(
  98. DtIconCacheObjPart *cache,
  99. DtIconGadget g);
  100. static void GetDefaultBackground(
  101. Widget g,
  102. int offset,
  103. XrmValue *value) ;
  104. static void GetDefaultForeground(
  105. Widget g,
  106. int offset,
  107. XrmValue *value) ;
  108. static void GetDefaultFillMode(
  109. Widget w,
  110. int offset,
  111. XrmValue *value) ;
  112. static void GetSpacing(
  113. Widget w,
  114. int offset,
  115. XtArgVal *value) ;
  116. static void GetString(
  117. Widget w,
  118. int offset,
  119. XtArgVal *value) ;
  120. static void IconEventHandler(
  121. Widget w,
  122. XtPointer client_data,
  123. XButtonEvent *event) ;
  124. static void ClickTimeout(
  125. Widget w,
  126. XtIntervalId *id) ;
  127. static void IconArm(
  128. Widget w,
  129. XEvent *event) ;
  130. static void IconDisarm(
  131. Widget w,
  132. XEvent *event) ;
  133. static void IconActivate(
  134. Widget w,
  135. XEvent *event) ;
  136. static void IconDrag(
  137. Widget w,
  138. XEvent *event) ;
  139. static void IconPopup(
  140. Widget w,
  141. XEvent *event) ;
  142. static void IconEnter(
  143. Widget w,
  144. XEvent *event) ;
  145. static void IconLeave(
  146. Widget w,
  147. XEvent *event) ;
  148. static void ClassInitialize( void ) ;
  149. static void SecondaryObjectCreate(
  150. Widget req,
  151. Widget new_w,
  152. ArgList args,
  153. Cardinal *num_args) ;
  154. static void InitializePosthook(
  155. Widget req,
  156. Widget new,
  157. ArgList args,
  158. Cardinal *num_args) ;
  159. static Boolean SetValuesPrehook(
  160. Widget oldParent,
  161. Widget refParent,
  162. Widget newParent,
  163. ArgList args,
  164. Cardinal *num_args) ;
  165. static void GetValuesPrehook(
  166. Widget newParent,
  167. ArgList args,
  168. Cardinal *num_args) ;
  169. static void GetValuesPosthook(
  170. Widget new,
  171. ArgList args,
  172. Cardinal *num_args) ;
  173. static Boolean SetValuesPosthook(
  174. Widget current,
  175. Widget req,
  176. Widget new,
  177. ArgList args,
  178. Cardinal *num_args) ;
  179. static void QualifyIconLocalCache(
  180. DtIconGadget g,
  181. DtIconCacheObjPart *cache);
  182. static void Initialize(
  183. Widget request_w,
  184. Widget new_w) ;
  185. static void Destroy(
  186. Widget w) ;
  187. static void Resize(
  188. Widget w) ;
  189. static void Redisplay(
  190. Widget w,
  191. XEvent *event,
  192. Region region) ;
  193. static Boolean SetValues(
  194. Widget current_w,
  195. Widget request_w,
  196. Widget new_w) ;
  197. static void BorderHighlight(
  198. DtIconGadget g) ;
  199. static void BorderUnhighlight(
  200. DtIconGadget g) ;
  201. static void ArmAndActivate(
  202. Widget w,
  203. XEvent *event) ;
  204. static void InputDispatch(
  205. Widget w,
  206. XButtonEvent *event,
  207. Mask event_mask) ;
  208. static Boolean VisualChange(
  209. Widget w,
  210. Widget current_w,
  211. Widget new_w) ;
  212. static void GetSize(
  213. DtIconGadget g,
  214. Dimension *w,
  215. Dimension *h) ;
  216. static void GetPositions(
  217. DtIconGadget g,
  218. Position w,
  219. Position h,
  220. Dimension h_t,
  221. Dimension s_t,
  222. Position *pix_x,
  223. Position *pix_y,
  224. Position *str_x,
  225. Position *str_y) ;
  226. static void Draw(
  227. DtIconGadget g,
  228. Drawable drawable,
  229. Position x,
  230. Position y,
  231. Dimension w,
  232. Dimension h,
  233. Dimension h_t,
  234. Dimension s_t,
  235. unsigned char s_type,
  236. unsigned char fill_mode) ;
  237. static void CallCallback(
  238. DtIconGadget g,
  239. XtCallbackList cb,
  240. int reason,
  241. XEvent *event) ;
  242. static void UpdateGCs(
  243. DtIconGadget g) ;
  244. static Cardinal GetIconClassSecResData(
  245. WidgetClass class,
  246. XmSecondaryResourceData **data_rtn) ;
  247. static XtPointer GetIconClassResBase(
  248. Widget widget,
  249. XtPointer client_data) ;
  250. static Boolean LoadPixmap(
  251. DtIconGadget new,
  252. String pixmap) ;
  253. static void ClassPartInitialize ( WidgetClass wc);
  254. static void HighlightBorder( Widget w );
  255. static void UnhighlightBorder( Widget w );
  256. /******** End Static Function Declarations ********/
  257. /* External Cache Procs
  258. */
  259. extern void _XmCacheDelete( XtPointer data );
  260. extern void _XmCacheCopy( XtPointer src, XtPointer dest, size_t size );
  261. extern Cardinal _XmSecondaryResourceData( XmBaseClassExt, XmSecondaryResourceData **,
  262. XtPointer, String, String, XmResourceBaseProc);
  263. extern XtPointer _XmCachePart( XmCacheClassPartPtr cp, XtPointer cpart, size_t size );
  264. /*-------------------------------------------------------------
  265. ** Resource List
  266. */
  267. #define I_Offset(field) \
  268. XtOffset (DtIconGadget, icon.field)
  269. #define I_Cache_Offset(field) \
  270. XtOffset (DtIconCacheObject, icon_cache.field)
  271. static XtResource resources[] =
  272. {
  273. {
  274. XmNset,
  275. XmCSet, XmRBoolean, sizeof (Boolean),
  276. I_Offset (set), XmRImmediate, (XtPointer) False
  277. },
  278. {
  279. XmNshadowType,
  280. XmCShadowType, XmRShadowType, sizeof (unsigned char),
  281. I_Offset (shadow_type),
  282. XmRImmediate, (XtPointer) XmSHADOW_ETCHED_OUT
  283. },
  284. {
  285. XmNborderType,
  286. XmCBorderType, XmRBorderType, sizeof (unsigned char),
  287. I_Offset (border_type),
  288. XmRImmediate, (XtPointer) DtRECTANGLE
  289. },
  290. {
  291. XmNcallback,
  292. XmCCallback, XmRCallback, sizeof (XtCallbackList),
  293. I_Offset (callback), XmRImmediate, (XtPointer) NULL
  294. },
  295. {
  296. XmNfontList,
  297. XmCFontList, XmRFontList, sizeof (XmFontList),
  298. I_Offset (font_list), XmRString, "Fixed"
  299. },
  300. {
  301. XmNimageName,
  302. XmCString, XmRString, sizeof (XmString),
  303. I_Offset (image_name), XmRImmediate, (XtPointer) NULL
  304. },
  305. {
  306. XmNpixmap,
  307. XmCPixmap, XmRPixmap, sizeof (Pixmap),
  308. I_Offset (pixmap),
  309. XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
  310. },
  311. {
  312. XmNstring,
  313. XmCXmString, XmRXmString, sizeof (XmString),
  314. I_Offset (string),
  315. XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
  316. },
  317. {
  318. XmNpixmapForeground,
  319. XmCForeground, XmRPixel, sizeof (Pixel),
  320. I_Offset (pixmap_foreground),
  321. XmRCallProc, (XtPointer) GetDefaultForeground
  322. },
  323. {
  324. XmNpixmapBackground,
  325. XmCBackground, XmRPixel, sizeof (Pixel),
  326. I_Offset (pixmap_background),
  327. XmRCallProc, (XtPointer) GetDefaultBackground
  328. },
  329. {
  330. XmNmaxPixmapWidth,
  331. XmCMaxWidth, XmRHorizontalDimension, sizeof (Dimension),
  332. I_Offset (max_pixmap_width), XmRImmediate, (XtPointer) 0
  333. },
  334. {
  335. XmNmaxPixmapHeight,
  336. XmCMaxHeight, XmRVerticalDimension, sizeof (Dimension),
  337. I_Offset (max_pixmap_height), XmRImmediate, (XtPointer) 0
  338. },
  339. {
  340. XmNunderline,
  341. XmCUnderline, XmRBoolean, sizeof (Boolean),
  342. I_Offset (underline), XmRImmediate, (XtPointer) False
  343. },
  344. {
  345. XmNdropSiteOperations, XmCDropSiteOperations,
  346. XmRDropSiteOperations, sizeof(unsigned char),
  347. I_Offset(operations), XmRImmediate, (XtPointer) XmDROP_NOOP
  348. },
  349. {
  350. XmNdropCallback,
  351. XmCDropCallback, XmRCallback, sizeof (XtCallbackList),
  352. I_Offset (drop_callback), XmRImmediate, (XtPointer) NULL
  353. }
  354. };
  355. static XtResource cache_resources[] =
  356. {
  357. {
  358. XmNbehavior,
  359. XmCBehavior, XmRBehavior, sizeof (unsigned char),
  360. I_Cache_Offset (behavior),
  361. XmRImmediate, (XtPointer) XmICON_BUTTON
  362. },
  363. {
  364. XmNrecomputeSize,
  365. XmCRecomputeSize, XmRBoolean, sizeof (Boolean),
  366. I_Cache_Offset (recompute_size), XmRImmediate, (XtPointer) True
  367. },
  368. {
  369. "drawShadow",
  370. "DrawShadow", XmRBoolean, sizeof (Boolean),
  371. I_Cache_Offset (draw_shadow), XmRImmediate, (XtPointer) False
  372. },
  373. {
  374. XmNfillOnArm,
  375. XmCFillOnArm, XmRBoolean, sizeof (Boolean),
  376. I_Cache_Offset (fill_on_arm), XmRImmediate, (XtPointer) True
  377. },
  378. {
  379. XmNforeground,
  380. XmCForeground, XmRPixel, sizeof (Pixel),
  381. I_Cache_Offset (foreground),
  382. XmRCallProc, (XtPointer) GetDefaultForeground
  383. },
  384. {
  385. XmNbackground,
  386. XmCBackground, XmRPixel, sizeof (Pixel),
  387. I_Cache_Offset (background),
  388. XmRCallProc, (XtPointer) GetDefaultBackground
  389. },
  390. {
  391. XmNarmColor,
  392. XmCArmColor, XmRPixel, sizeof (Pixel),
  393. I_Cache_Offset (arm_color),
  394. XmRCallProc, (XtPointer) _XmSelectColorDefault
  395. },
  396. {
  397. XmNspacing,
  398. XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
  399. I_Cache_Offset (spacing),
  400. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  401. },
  402. {
  403. XmNmarginHeight,
  404. XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
  405. I_Cache_Offset (margin_height),
  406. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  407. },
  408. {
  409. XmNmarginWidth,
  410. XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
  411. I_Cache_Offset (margin_width),
  412. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  413. },
  414. {
  415. XmNpixmapPosition,
  416. XmCPixmapPosition, XmRPixmapPosition, sizeof (unsigned char),
  417. I_Cache_Offset (pixmap_position),
  418. XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
  419. },
  420. {
  421. XmNstringPosition,
  422. XmCStringPosition, XmRStringPosition, sizeof (unsigned char),
  423. I_Cache_Offset (string_position),
  424. XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
  425. },
  426. {
  427. XmNalignment,
  428. XmCAlignment, XmRAlignment, sizeof (unsigned char),
  429. I_Cache_Offset (alignment),
  430. XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
  431. },
  432. {
  433. XmNfillMode,
  434. XmCFillMode, XmRFillMode, sizeof (unsigned char),
  435. I_Cache_Offset (fill_mode),
  436. XmRCallProc, (XtPointer) GetDefaultFillMode
  437. }
  438. };
  439. static XmSyntheticResource syn_resources[] =
  440. {
  441. {
  442. XmNstring, sizeof (XmString),
  443. I_Offset (string), GetString,
  444. (XmImportProc) NULL
  445. },
  446. };
  447. static XmSyntheticResource cache_syn_resources[] =
  448. {
  449. {
  450. XmNspacing, sizeof (Dimension),
  451. I_Cache_Offset (spacing), GetSpacing,
  452. (XmImportProc) NULL
  453. },
  454. {
  455. XmNmarginWidth, sizeof (Dimension),
  456. I_Cache_Offset (margin_width),
  457. XmeFromHorizontalPixels,
  458. (XmImportProc)XmeToHorizontalPixels
  459. },
  460. {
  461. XmNmarginHeight, sizeof (Dimension),
  462. I_Cache_Offset (margin_height),
  463. XmeFromVerticalPixels,
  464. (XmImportProc)XmeToVerticalPixels,
  465. }
  466. };
  467. #undef I_Offset
  468. #undef I_Cache_Offset
  469. /*-------------------------------------------------------------
  470. ** Cache Class Record
  471. */
  472. static XmCacheClassPart IconClassCachePart = {
  473. {NULL, 0, 0}, /* head of class cache list */
  474. _XmCacheCopy, /* Copy routine */
  475. _XmCacheDelete, /* Delete routine */
  476. IconCacheCompare, /* Comparison routine */
  477. };
  478. /*-------------------------------------------------------------
  479. ** Base Class Extension Record
  480. */
  481. static XmBaseClassExtRec iconBaseClassExtRec = {
  482. NULL, /* Next extension */
  483. NULLQUARK, /* record type XmQmotif */
  484. XmBaseClassExtVersion, /* version */
  485. sizeof(XmBaseClassExtRec), /* size */
  486. XmInheritInitializePrehook, /* initialize prehook */
  487. SetValuesPrehook, /* set_values prehook */
  488. InitializePosthook, /* initialize posthook */
  489. SetValuesPosthook, /* set_values posthook */
  490. (WidgetClass)&dtIconCacheObjClassRec, /* secondary class */
  491. (XtInitProc)SecondaryObjectCreate, /* creation proc */
  492. (XmGetSecResDataFunc) GetIconClassSecResData, /* getSecResData */
  493. {0}, /* fast subclass */
  494. GetValuesPrehook, /* get_values prehook */
  495. GetValuesPosthook, /* get_values posthook */
  496. NULL, /* classPartInitPrehook */
  497. NULL, /* classPartInitPosthook*/
  498. NULL, /* ext_resources */
  499. NULL, /* compiled_ext_resources*/
  500. 0, /* num_ext_resources */
  501. FALSE, /* use_sub_resources */
  502. XmInheritWidgetNavigable, /* widgetNavigable */
  503. XmInheritFocusChange, /* focusChange */
  504. };
  505. /*-------------------------------------------------------------
  506. ** Icon Cache Object Class Record
  507. */
  508. externaldef (dticoncacheobjclassrec)
  509. DtIconCacheObjClassRec dtIconCacheObjClassRec =
  510. {
  511. {
  512. /* superclass */ (WidgetClass) &xmExtClassRec,
  513. /* class_name */ "DtIcon",
  514. /* widget_size */ sizeof(DtIconCacheObjRec),
  515. /* class_initialize */ NULL,
  516. /* chained class init */ NULL,
  517. /* class_inited */ False,
  518. /* initialize */ NULL,
  519. /* initialize hook */ NULL,
  520. /* realize */ NULL,
  521. /* actions */ NULL,
  522. /* num_actions */ 0,
  523. /* resources */ cache_resources,
  524. /* num_resources */ XtNumber(cache_resources),
  525. /* xrm_class */ NULLQUARK,
  526. /* compress_motion */ False,
  527. /* compress_exposure */ False,
  528. /* compress enter/exit*/ False,
  529. /* visible_interest */ False,
  530. /* destroy */ NULL,
  531. /* resize */ NULL,
  532. /* expose */ NULL,
  533. /* set_values */ NULL,
  534. /* set values hook */ NULL,
  535. /* set values almost */ NULL,
  536. /* get values hook */ NULL,
  537. /* accept_focus */ NULL,
  538. /* version */ XtVersion,
  539. /* callback offsetlst */ NULL,
  540. /* default trans */ NULL,
  541. /* query geo proc */ NULL,
  542. /* display accelerator*/ NULL,
  543. /* extension record */ NULL,
  544. },
  545. {
  546. /* synthetic resources */ cache_syn_resources,
  547. /* num_syn_resources */ XtNumber(cache_syn_resources),
  548. /* extension */ NULL,
  549. },
  550. };
  551. /*-------------------------------------------------------------
  552. ** Class Record
  553. */
  554. externaldef (dticonclassrec)
  555. DtIconClassRec dtIconClassRec =
  556. {
  557. /* Core Part
  558. */
  559. {
  560. (WidgetClass) &xmGadgetClassRec, /* superclass */
  561. "DtIcon", /* class_name */
  562. sizeof (DtIconRec), /* widget_size */
  563. ClassInitialize, /* class_initialize */
  564. ClassPartInitialize, /* class_part_initialize*/
  565. False, /* class_inited */
  566. (XtInitProc) Initialize, /* initialize */
  567. NULL, /* initialize_hook */
  568. NULL, /* realize */
  569. NULL, /* actions */
  570. 0, /* num_actions */
  571. resources, /* resources */
  572. XtNumber (resources), /* num_resources */
  573. NULLQUARK, /* xrm_class */
  574. True, /* compress_motion */
  575. True, /* compress_exposure */
  576. True, /* compress_enterleave */
  577. False, /* visible_interest */
  578. (XtWidgetProc) Destroy, /* destroy */
  579. (XtWidgetProc) Resize, /* resize */
  580. (XtExposeProc) Redisplay, /* expose */
  581. (XtSetValuesFunc) SetValues, /* set_values */
  582. NULL, /* set_values_hook */
  583. XtInheritSetValuesAlmost, /* set_values_almost */
  584. NULL, /* get_values_hook */
  585. NULL, /* accept_focus */
  586. XtVersion, /* version */
  587. NULL, /* callback private */
  588. NULL, /* tm_table */
  589. NULL, /* query_geometry */
  590. NULL, /* display_accelerator */
  591. (XtPointer)&iconBaseClassExtRec,/* extension */
  592. },
  593. /* XmGadget Part
  594. */
  595. {
  596. (XtWidgetProc) BorderHighlight, /* border_highlight */
  597. (XtWidgetProc) BorderUnhighlight, /* border_unhighlight */
  598. (XtActionProc) ArmAndActivate, /* arm_and_activate */
  599. (XmWidgetDispatchProc) InputDispatch, /* input_dispatch */
  600. (XmVisualChangeProc) VisualChange, /* visual_change */
  601. syn_resources, /* get_resources */
  602. XtNumber (syn_resources), /* num_get_resources */
  603. &IconClassCachePart, /* class_cache_part */
  604. NULL, /* extension */
  605. },
  606. /* DtIconGadget Part
  607. */
  608. {
  609. GetSize, /* get_size */
  610. GetPositions, /* get_positions */
  611. Draw, /* draw */
  612. CallCallback, /* call_callback */
  613. UpdateGCs, /* update_gcs */
  614. True, /* optimize_redraw */
  615. NULL, /* class_cache_part */
  616. NULL, /* extension */
  617. }
  618. };
  619. externaldef (dticongadgetclass) WidgetClass dtIconGadgetClass = (WidgetClass) &dtIconClassRec;
  620. /*-------------------------------------------------------------
  621. ** Private Functions
  622. **-------------------------------------------------------------
  623. */
  624. /************************************************************************
  625. *
  626. * The border highlighting and unhighlighting routines.
  627. *
  628. * These routines were originally in Obsolete.c but can not depend
  629. * on these routines to live forever. Therefore, copied into my
  630. * own space.
  631. *
  632. ************************************************************************/
  633. static void
  634. HighlightBorder(
  635. Widget w )
  636. {
  637. XtWidgetProc border_highlight;
  638. if (XmIsPrimitive(w)) {
  639. _DtProcessLock();
  640. border_highlight = xmPrimitiveClassRec.primitive_class.border_highlight;
  641. _DtProcessUnlock();
  642. (*border_highlight) (w);
  643. } else if (XmIsGadget(w)) {
  644. _DtProcessLock();
  645. border_highlight = xmGadgetClassRec.gadget_class.border_highlight;
  646. _DtProcessUnlock();
  647. (*border_highlight) (w);
  648. }
  649. }
  650. static void
  651. UnhighlightBorder(
  652. Widget w )
  653. {
  654. XtWidgetProc border_unhighlight;
  655. if (XmIsPrimitive(w)) {
  656. _DtProcessLock();
  657. border_unhighlight = xmPrimitiveClassRec.primitive_class.border_unhighlight;
  658. _DtProcessUnlock();
  659. (*border_unhighlight) (w);
  660. } else if (XmIsGadget(w)) {
  661. _DtProcessLock();
  662. border_unhighlight = xmGadgetClassRec.gadget_class.border_unhighlight;
  663. _DtProcessUnlock();
  664. (*border_unhighlight) (w);
  665. }
  666. }
  667. /*-------------------------------------------------------------
  668. ** GetMaskGC
  669. ** Get normal and background graphics contexts.
  670. */
  671. static GC
  672. GetMaskGC(
  673. DtIconGadget g,
  674. Position x,
  675. Position y)
  676. {
  677. if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
  678. XSetClipOrigin(XtDisplay(g),
  679. G_ClipGC(g),
  680. x, y);
  681. return G_ClipGC(g);
  682. }
  683. else {
  684. return G_NormalGC(g);
  685. }
  686. }
  687. /*-------------------------------------------------------------
  688. ** GetDefaultBackground
  689. ** Copy background pixel from Manager parent.
  690. */
  691. /* ARGSUSED */
  692. static void
  693. GetDefaultBackground(
  694. Widget g,
  695. int offset,
  696. XrmValue *value )
  697. {
  698. static Pixel pixel;
  699. XmManagerWidget parent = (XmManagerWidget) XtParent (g);
  700. value->addr = (XtPointer) &pixel;
  701. value->size = sizeof (Pixel);
  702. if (XmIsManager ((Widget) parent))
  703. pixel = M_Background (parent);
  704. else
  705. XmeGetDefaultPixel (g, XmBACKGROUND, offset, value);
  706. }
  707. /*-------------------------------------------------------------
  708. ** GetDefaultForeground
  709. ** Copy foreground pixel from Manager parent.
  710. */
  711. static void
  712. GetDefaultForeground(
  713. Widget g,
  714. int offset,
  715. XrmValue *value )
  716. {
  717. static Pixel pixel;
  718. XmManagerWidget parent = (XmManagerWidget) XtParent (g);
  719. value->addr = (XtPointer) &pixel;
  720. value->size = sizeof (Pixel);
  721. if (XmIsManager ((Widget) parent))
  722. pixel = M_Foreground (parent);
  723. else
  724. XmeGetDefaultPixel (g, XmFOREGROUND, offset, value);
  725. }
  726. /*-------------------------------------------------------------
  727. ** GetDefaultFillMode
  728. ** Get default fill mode.
  729. */
  730. /* ARGSUSED */
  731. static void
  732. GetDefaultFillMode(
  733. Widget w,
  734. int offset,
  735. XrmValue *value )
  736. {
  737. static unsigned char fill_mode;
  738. DtIconGadget g = (DtIconGadget) w;
  739. value->addr = (XtPointer) &fill_mode;
  740. value->size = sizeof (unsigned char);
  741. if (G_ShadowThickness (g) == 0)
  742. fill_mode = XmFILL_PARENT;
  743. else
  744. fill_mode = XmFILL_SELF;
  745. }
  746. /*-------------------------------------------------------------
  747. ** GetSpacing
  748. ** Convert from pixels to horizontal or vertical units.
  749. */
  750. static void
  751. GetSpacing(
  752. Widget w,
  753. int offset,
  754. XtArgVal *value )
  755. {
  756. DtIconCacheObject icon_co = (DtIconCacheObject) w;
  757. if (G_CachePixmapPosition (icon_co) == XmPIXMAP_TOP ||
  758. G_CachePixmapPosition (icon_co) == XmPIXMAP_BOTTOM ||
  759. G_CachePixmapPosition (icon_co) == XmPIXMAP_MIDDLE)
  760. XmeFromVerticalPixels ((Widget)icon_co, offset, value);
  761. else
  762. XmeFromHorizontalPixels ((Widget)icon_co, offset, value);
  763. }
  764. /*-------------------------------------------------------------
  765. ** GetString
  766. ** Convert string from internal to external form.
  767. */
  768. /* ARGSUSED */
  769. static void
  770. GetString(
  771. Widget w,
  772. int offset,
  773. XtArgVal *value )
  774. {
  775. DtIconGadget g = (DtIconGadget) w;
  776. XmString string;
  777. string = XmStringCopy (G_String (g));
  778. *value = (XtArgVal) string;
  779. }
  780. /*-------------------------------------------------------------
  781. ** IconEventHandler
  782. ** Event handler for middle button events.
  783. */
  784. /* ARGSUSED */
  785. static void
  786. IconEventHandler(
  787. Widget w,
  788. XtPointer client_data,
  789. XButtonEvent *event )
  790. {
  791. DtIconGadget g = NULL;
  792. g = (DtIconGadget) XmObjectAtPoint (w, event->x, event->y);
  793. if (!g || !DtIsIcon ((Widget)g))
  794. return;
  795. if (event->button == Button2 || event->button == Button3)
  796. {
  797. if (event->type == ButtonPress)
  798. InputDispatch ((Widget) g, event, XmARM_EVENT);
  799. else if (event->type == ButtonRelease)
  800. InputDispatch ((Widget) g, event, XmACTIVATE_EVENT);
  801. }
  802. }
  803. /*-------------------------------------------------------------
  804. ** ClickTimeout
  805. ** Clear Click flags.
  806. */
  807. /* ARGSUSED */
  808. static void
  809. ClickTimeout(
  810. Widget w,
  811. XtIntervalId *id )
  812. {
  813. DtIconGadget g = (DtIconGadget) w;
  814. Time last_time, end_time;
  815. if (! G_Armed (g))
  816. {
  817. G_ClickTimerID (g) = 0;
  818. XtFree ((char *)G_ClickEvent (g));
  819. G_ClickEvent (g) = NULL;
  820. return;
  821. }
  822. last_time = XtLastTimestampProcessed (XtDisplay (g));
  823. /*
  824. * fix for bug# 4504
  825. */
  826. if( G_ClickEvent (g) == NULL) return;
  827. end_time = G_ClickEvent (g) -> time + (Time)
  828. XtGetMultiClickTime (XtDisplay (g));
  829. /* Sync and reset timer if server interval may not have elapsed.
  830. */
  831. if ((last_time < end_time) && G_Sync (g))
  832. {
  833. G_Sync (g) = False;
  834. XSync (XtDisplay (g), False);
  835. G_ClickTimerID (g) =
  836. XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget)g),
  837. (unsigned long) 50,
  838. (XtTimerCallbackProc)ClickTimeout,
  839. (XtPointer) g);
  840. }
  841. /* Handle Select action.
  842. */
  843. else
  844. {
  845. CallCallbackProc call_callback;
  846. XtExposeProc expose;
  847. _DtProcessLock();
  848. expose = XtCoreProc(w, expose);
  849. call_callback = C_CallCallback(XtClass(w));
  850. _DtProcessUnlock();
  851. G_ClickTimerID (g) = 0;
  852. G_Armed (g) = False;
  853. (*call_callback) (g, G_Callback (g), XmCR_SELECT,
  854. (XEvent *)G_ClickEvent (g));
  855. if ((G_Behavior (g) == XmICON_DRAG) &&
  856. (G_ShadowThickness (g) == 0))
  857. {
  858. /* Do nothing */
  859. }
  860. else
  861. (*expose) ((Widget)g, (XEvent*)G_ClickEvent (g), NULL);
  862. XtFree ((char *)G_ClickEvent (g));
  863. G_ClickEvent (g) = NULL;
  864. }
  865. }
  866. /*-------------------------------------------------------------
  867. ** Action Procs
  868. **-------------------------------------------------------------
  869. */
  870. /*-------------------------------------------------------------
  871. ** IconArm
  872. ** Handle Arm action.
  873. */
  874. static void
  875. IconArm(
  876. Widget w,
  877. XEvent *event )
  878. {
  879. DtIconGadget g = (DtIconGadget) w;
  880. if (G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
  881. return;
  882. G_Armed (g) = True;
  883. if (G_Behavior (g) == XmICON_DRAG)
  884. {
  885. CallCallbackProc call_callback;
  886. _DtProcessLock();
  887. call_callback = C_CallCallback(XtClass(g));
  888. _DtProcessUnlock();
  889. (*call_callback) (g, G_Callback (g), XmCR_ARM, event);
  890. }
  891. if ((G_Behavior (g) == XmICON_DRAG) &&
  892. (G_ShadowThickness (g) == 0))
  893. {
  894. /* Do nothing */
  895. }
  896. else
  897. {
  898. XtExposeProc expose;
  899. _DtProcessLock();
  900. expose = XtCoreProc(w, expose);
  901. _DtProcessUnlock();
  902. (*expose) ((Widget)g, event, NULL);
  903. }
  904. }
  905. /*-------------------------------------------------------------
  906. ** IconDisarm
  907. ** Handle Disarm action.
  908. */
  909. static void
  910. IconDisarm(
  911. Widget w,
  912. XEvent *event )
  913. {
  914. DtIconGadget g = (DtIconGadget) w;
  915. if (! G_Armed (g) || G_Behavior (g) == XmICON_LABEL)
  916. return;
  917. G_Armed (g) = False;
  918. if (G_Behavior (g) == XmICON_DRAG)
  919. {
  920. CallCallbackProc call_callback;
  921. XtExposeProc expose;
  922. _DtProcessLock();
  923. call_callback = C_CallCallback(XtClass(g));
  924. expose = XtCoreProc(w, expose);
  925. _DtProcessUnlock();
  926. (*call_callback) (g, G_Callback (g), XmCR_DISARM, event);
  927. (*expose) ((Widget)g, event, NULL);
  928. }
  929. }
  930. /*-------------------------------------------------------------
  931. ** IconActivate
  932. ** Handle Activate action.
  933. */
  934. static void
  935. IconActivate(
  936. Widget w,
  937. XEvent *event )
  938. {
  939. DtIconGadget g = (DtIconGadget) w;
  940. unsigned long delay;
  941. XButtonEvent * b_event = (XButtonEvent *) event;
  942. CallCallbackProc call_callback;
  943. XtExposeProc expose;
  944. if (! G_Armed (g))
  945. return;
  946. _DtProcessLock();
  947. call_callback = C_CallCallback(XtClass(g));
  948. expose = XtCoreProc(w, expose);
  949. _DtProcessUnlock();
  950. if (G_Behavior (g) == XmICON_BUTTON)
  951. {
  952. G_Armed (g) = False;
  953. (*call_callback) (g, G_Callback (g), XmCR_ACTIVATE, event);
  954. (*expose) ((Widget)g, event, NULL);
  955. }
  956. else if (G_Behavior (g) == XmICON_TOGGLE)
  957. {
  958. G_Armed (g) = False;
  959. G_Set (g) = ! G_Set (g);
  960. (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, event);
  961. }
  962. else if (G_Behavior (g) == XmICON_DRAG)
  963. {
  964. if (G_ClickTimerID (g))
  965. {
  966. G_ClickTimerID (g) = 0;
  967. XtFree ((char *)G_ClickEvent (g));
  968. G_ClickEvent (g) = NULL;
  969. G_Armed (g) = False;
  970. (*call_callback) (g, G_Callback (g),
  971. XmCR_DEFAULT_ACTION, event);
  972. }
  973. else
  974. {
  975. delay = (unsigned long)
  976. XtGetMultiClickTime (XtDisplay (g));
  977. G_ClickEvent (g) = (XButtonEvent *)
  978. XtMalloc (sizeof (XButtonEvent));
  979. *(G_ClickEvent (g)) = *b_event;
  980. G_Sync (g) = True;
  981. G_ClickTimerID (g) =
  982. XtAppAddTimeOut (
  983. XtWidgetToApplicationContext ((Widget)g),
  984. delay, (XtTimerCallbackProc)ClickTimeout,
  985. (XtPointer) g);
  986. }
  987. if (G_ShadowThickness (g) > 0)
  988. (*expose) ((Widget)g, event, NULL);
  989. }
  990. }
  991. /*-------------------------------------------------------------
  992. ** IconDrag
  993. ** Handle Drag action.
  994. */
  995. static void
  996. IconDrag(
  997. Widget w,
  998. XEvent *event )
  999. {
  1000. DtIconGadget g = (DtIconGadget) w;
  1001. if (G_Behavior (g) == XmICON_DRAG)
  1002. {
  1003. CallCallbackProc call_callback;
  1004. _DtProcessLock();
  1005. call_callback = C_CallCallback(XtClass(w));
  1006. _DtProcessUnlock();
  1007. (*call_callback) (g, G_Callback (g), XmCR_DRAG, event);
  1008. }
  1009. }
  1010. /*-------------------------------------------------------------
  1011. ** IconPopup
  1012. ** Handle button 3 - popup's
  1013. */
  1014. static void
  1015. IconPopup(
  1016. Widget w,
  1017. XEvent *event )
  1018. {
  1019. DtIconGadget g = (DtIconGadget) w;
  1020. CallCallbackProc call_callback;
  1021. _DtProcessLock();
  1022. call_callback = C_CallCallback(XtClass(w));
  1023. _DtProcessUnlock();
  1024. (*call_callback) (g, G_Callback (g), XmCR_POPUP, event);
  1025. }
  1026. /*-------------------------------------------------------------
  1027. ** IconEnter
  1028. ** Handle Enter action.
  1029. */
  1030. static void
  1031. IconEnter(
  1032. Widget w,
  1033. XEvent *event )
  1034. {
  1035. DtIconGadget g = (DtIconGadget) w;
  1036. _XmEnterGadget (w, (XEvent *)event,
  1037. (String *)NULL,(Cardinal *)0);
  1038. if (G_Armed (g))
  1039. {
  1040. if ((G_Behavior (g) == XmICON_BUTTON) ||
  1041. (G_Behavior (g) == XmICON_TOGGLE))
  1042. {
  1043. XtExposeProc expose;
  1044. _DtProcessLock();
  1045. expose = XtCoreProc(w, expose);
  1046. _DtProcessUnlock();
  1047. (*expose) ((Widget)g, event, NULL);
  1048. }
  1049. }
  1050. }
  1051. /*-------------------------------------------------------------
  1052. ** IconLeave
  1053. ** Handle Leave action.
  1054. */
  1055. static void
  1056. IconLeave(
  1057. Widget w,
  1058. XEvent *event )
  1059. {
  1060. DtIconGadget g = (DtIconGadget) w;
  1061. _XmLeaveGadget (w, (XEvent *)event,
  1062. (String *)NULL, (Cardinal *)0);
  1063. if (G_Armed (g))
  1064. {
  1065. if ((G_Behavior (g) == XmICON_BUTTON) ||
  1066. (G_Behavior (g) == XmICON_TOGGLE))
  1067. {
  1068. XtExposeProc expose;
  1069. _DtProcessLock();
  1070. expose = XtCoreProc(w, expose);
  1071. _DtProcessUnlock();
  1072. G_Armed (g) = False;
  1073. (*expose) ((Widget)g, event, NULL);
  1074. G_Armed (g) = True;
  1075. }
  1076. }
  1077. }
  1078. /*-------------------------------------------------------------
  1079. ** Core Procs
  1080. **-------------------------------------------------------------
  1081. */
  1082. /*-------------------------------------------------------------
  1083. ** ClassInitialize
  1084. ** Initialize gadget class.
  1085. */
  1086. static void
  1087. ClassInitialize( void )
  1088. {
  1089. _DtRegisterNewConverters ();
  1090. iconBaseClassExtRec.record_type = XmQmotif;
  1091. }
  1092. /*-------------------------------------------------------------
  1093. ** ClassPartInitialize
  1094. ** Initialize gadget class part.
  1095. */
  1096. static void
  1097. ClassPartInitialize (
  1098. WidgetClass wc)
  1099. {
  1100. DtIconGadgetClass ic = (DtIconGadgetClass) wc;
  1101. DtIconGadgetClass super = (DtIconGadgetClass) ic->rect_class.superclass;
  1102. if (C_GetSize (ic) == DtInheritGetSize)
  1103. C_GetSize (ic) = C_GetSize (super);
  1104. if (C_GetPositions (ic) == DtInheritGetPositions)
  1105. C_GetPositions (ic) = C_GetPositions (super);
  1106. if (C_Draw (ic) == DtInheritDraw)
  1107. C_Draw (ic) = C_Draw (super);
  1108. if (C_CallCallback (ic) == DtInheritCallCallback)
  1109. C_CallCallback (ic) = C_CallCallback (super);
  1110. if (C_UpdateGCs (ic) == DtInheritUpdateGCs)
  1111. C_UpdateGCs (ic) = C_UpdateGCs (super);
  1112. }
  1113. /*-------------------------------------------------------------
  1114. ** Cache Procs
  1115. **-------------------------------------------------------------
  1116. */
  1117. /*-------------------------------------------------------------
  1118. ** IconCacheCompare
  1119. **
  1120. */
  1121. static int
  1122. IconCacheCompare(
  1123. XtPointer A,
  1124. XtPointer B )
  1125. {
  1126. DtIconCacheObjPart *icon_inst = (DtIconCacheObjPart *) A ;
  1127. DtIconCacheObjPart *icon_cache_inst = (DtIconCacheObjPart *) B ;
  1128. if ((icon_inst->fill_on_arm == icon_cache_inst->fill_on_arm) &&
  1129. (icon_inst->recompute_size== icon_cache_inst->recompute_size) &&
  1130. (icon_inst->pixmap_position== icon_cache_inst->pixmap_position) &&
  1131. (icon_inst->string_position== icon_cache_inst->string_position) &&
  1132. (icon_inst->alignment == icon_cache_inst->alignment) &&
  1133. (icon_inst->behavior == icon_cache_inst->behavior) &&
  1134. (icon_inst->draw_shadow == icon_cache_inst->draw_shadow) &&
  1135. (icon_inst->fill_mode == icon_cache_inst->fill_mode) &&
  1136. (icon_inst->margin_width== icon_cache_inst->margin_width) &&
  1137. (icon_inst->margin_height== icon_cache_inst->margin_height) &&
  1138. (icon_inst->string_height== icon_cache_inst->string_height) &&
  1139. (icon_inst->spacing== icon_cache_inst->spacing) &&
  1140. (icon_inst->foreground== icon_cache_inst->foreground) &&
  1141. (icon_inst->background== icon_cache_inst->background) &&
  1142. (icon_inst->arm_color== icon_cache_inst->arm_color))
  1143. return 1;
  1144. else
  1145. return 0;
  1146. }
  1147. /*-------------------------------------------------------------
  1148. ** SecondaryObjectCreate
  1149. **
  1150. */
  1151. static void
  1152. SecondaryObjectCreate(
  1153. Widget req,
  1154. Widget new_w,
  1155. ArgList args,
  1156. Cardinal *num_args )
  1157. {
  1158. XmBaseClassExt *cePtr;
  1159. XmWidgetExtData extData;
  1160. WidgetClass wc;
  1161. Cardinal size;
  1162. XtPointer newSec, reqSec;
  1163. XtResourceList resources;
  1164. Cardinal num_resources;
  1165. _DtProcessLock();
  1166. cePtr = _XmGetBaseClassExtPtr(XtClass(new_w), XmQmotif);
  1167. wc = (*cePtr)->secondaryObjectClass;
  1168. if (NULL == wc) return;
  1169. size = wc->core_class.widget_size;
  1170. resources = wc->core_class.resources;
  1171. num_resources = wc->core_class.num_resources;
  1172. newSec = _XmExtObjAlloc(size);
  1173. reqSec = _XmExtObjAlloc(size);
  1174. _DtProcessUnlock();
  1175. /*
  1176. * fetch the resources in superclass to subclass order
  1177. */
  1178. XtGetSubresources(new_w, newSec, NULL, NULL,
  1179. resources, num_resources, args, *num_args );
  1180. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1181. extData->widget = (Widget)newSec;
  1182. extData->reqWidget = (Widget)reqSec;
  1183. ((DtIconCacheObject)newSec)->ext.extensionType = XmCACHE_EXTENSION;
  1184. ((DtIconCacheObject)newSec)->ext.logicalParent = new_w;
  1185. _XmPushWidgetExtData(new_w, extData,
  1186. ((DtIconCacheObject)newSec)->ext.extensionType);
  1187. memcpy(reqSec, newSec, size);
  1188. /*
  1189. * fill out cache pointers
  1190. */
  1191. Icon_Cache(new_w) = &(((DtIconCacheObject)extData->widget)->icon_cache);
  1192. Icon_Cache(req) = &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
  1193. }
  1194. /*-------------------------------------------------------------
  1195. ** InitializePostHook
  1196. **
  1197. */
  1198. /* ARGSUSED */
  1199. static void
  1200. InitializePosthook(
  1201. Widget req,
  1202. Widget new,
  1203. ArgList args,
  1204. Cardinal *num_args )
  1205. {
  1206. XmWidgetExtData ext;
  1207. DtIconGadget lw = (DtIconGadget)new;
  1208. /*
  1209. * - register parts in cache.
  1210. * - update cache pointers
  1211. * - and free req
  1212. */
  1213. _DtProcessLock();
  1214. Icon_Cache(lw) = (DtIconCacheObjPart *)
  1215. _XmCachePart( Icon_ClassCachePart(lw),
  1216. (XtPointer) Icon_Cache(lw),
  1217. sizeof(DtIconCacheObjPart));
  1218. /*
  1219. * might want to break up into per-class work that gets explicitly
  1220. * chained. For right now, each class has to replicate all
  1221. * superclass logic in hook routine
  1222. */
  1223. /* * free the req subobject used for comparisons
  1224. */
  1225. _XmPopWidgetExtData((Widget) lw, &ext, XmCACHE_EXTENSION);
  1226. _XmExtObjFree((XtPointer)ext->widget);
  1227. _XmExtObjFree((XtPointer)ext->reqWidget);
  1228. _DtProcessUnlock();
  1229. XtFree( (char *) ext);
  1230. }
  1231. /*-------------------------------------------------------------
  1232. ** SetValuesPrehook
  1233. **
  1234. */
  1235. /* ARGSUSED */
  1236. static Boolean
  1237. SetValuesPrehook(
  1238. Widget oldParent,
  1239. Widget refParent,
  1240. Widget newParent,
  1241. ArgList args,
  1242. Cardinal *num_args )
  1243. {
  1244. XmWidgetExtData extData;
  1245. XmBaseClassExt *cePtr;
  1246. WidgetClass ec;
  1247. DtIconCacheObject newSec, reqSec;
  1248. Cardinal size;
  1249. XtResourceList resources;
  1250. Cardinal num_resources;
  1251. _DtProcessLock();
  1252. cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
  1253. ec = (*cePtr)->secondaryObjectClass;
  1254. size = ec->core_class.widget_size;
  1255. resources = ec->core_class.resources;
  1256. num_resources = ec->core_class.num_resources;
  1257. /* allocate copies and fill from cache */
  1258. newSec = (DtIconCacheObject) _XmExtObjAlloc(size);
  1259. reqSec = (DtIconCacheObject) _XmExtObjAlloc(size);
  1260. _DtProcessUnlock();
  1261. newSec->object.self = (Widget)newSec;
  1262. newSec->object.widget_class = ec;
  1263. newSec->object.parent = XtParent(newParent);
  1264. newSec->object.xrm_name = newParent->core.xrm_name;
  1265. newSec->object.being_destroyed = False;
  1266. newSec->object.destroy_callbacks = NULL;
  1267. newSec->object.constraints = NULL;
  1268. newSec->ext.logicalParent = newParent;
  1269. newSec->ext.extensionType = XmCACHE_EXTENSION;
  1270. memcpy(&(newSec->icon_cache),
  1271. Icon_Cache(newParent),
  1272. sizeof(DtIconCacheObjPart));
  1273. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1274. extData->widget = (Widget)newSec;
  1275. extData->reqWidget = (Widget)reqSec;
  1276. _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
  1277. _XmGadgetImportSecondaryArgs(newParent, args, num_args);
  1278. XtSetSubvalues((XtPointer)newSec, resources, num_resources,
  1279. args, *num_args);
  1280. _XmExtImportArgs((Widget)newSec, args, num_args);
  1281. memcpy((XtPointer)reqSec, (XtPointer)newSec, size);
  1282. Icon_Cache(newParent) = &(((DtIconCacheObject)newSec)->icon_cache);
  1283. Icon_Cache(refParent) =
  1284. &(((DtIconCacheObject)extData->reqWidget)->icon_cache);
  1285. return FALSE;
  1286. }
  1287. /*-------------------------------------------------------------
  1288. ** GetValuesPrehook
  1289. **
  1290. */
  1291. static void
  1292. GetValuesPrehook(
  1293. Widget newParent,
  1294. ArgList args,
  1295. Cardinal *num_args )
  1296. {
  1297. XmWidgetExtData extData;
  1298. XmBaseClassExt *cePtr;
  1299. WidgetClass ec;
  1300. DtIconCacheObject newSec;
  1301. Cardinal size;
  1302. XtResourceList resources;
  1303. Cardinal num_resources;
  1304. _DtProcessLock();
  1305. cePtr = _XmGetBaseClassExtPtr(XtClass(newParent), XmQmotif);
  1306. ec = (*cePtr)->secondaryObjectClass;
  1307. size = ec->core_class.widget_size;
  1308. resources = ec->core_class.resources;
  1309. num_resources = ec->core_class.num_resources;
  1310. newSec = (DtIconCacheObject)_XmExtObjAlloc(size);
  1311. _DtProcessUnlock();
  1312. newSec->object.self = (Widget)newSec;
  1313. newSec->object.widget_class = ec;
  1314. newSec->object.parent = XtParent(newParent);
  1315. newSec->object.xrm_name = newParent->core.xrm_name;
  1316. newSec->object.being_destroyed = False;
  1317. newSec->object.destroy_callbacks = NULL;
  1318. newSec->object.constraints = NULL;
  1319. newSec->ext.logicalParent = newParent;
  1320. newSec->ext.extensionType = XmCACHE_EXTENSION;
  1321. memcpy( &(newSec->icon_cache),
  1322. Icon_Cache(newParent),
  1323. sizeof(DtIconCacheObjPart));
  1324. extData = (XmWidgetExtData) XtCalloc(sizeof(XmWidgetExtDataRec), 1);
  1325. extData->widget = (Widget)newSec;
  1326. _XmPushWidgetExtData(newParent, extData, XmCACHE_EXTENSION);
  1327. XtGetSubvalues((XtPointer)newSec, resources, num_resources,
  1328. args, *num_args);
  1329. _XmExtGetValuesHook((Widget)newSec, args, num_args);
  1330. }
  1331. /*-------------------------------------------------------------
  1332. ** GetValuesPosthook
  1333. **
  1334. */
  1335. /* ARGSUSED */
  1336. static void
  1337. GetValuesPosthook(
  1338. Widget new,
  1339. ArgList args,
  1340. Cardinal *num_args )
  1341. {
  1342. XmWidgetExtData ext;
  1343. _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
  1344. _DtProcessLock();
  1345. _XmExtObjFree((XtPointer)ext->widget);
  1346. _DtProcessUnlock();
  1347. XtFree((char *)ext);
  1348. }
  1349. /*-------------------------------------------------------------
  1350. ** SetValuesPosthook
  1351. **
  1352. */
  1353. /* ARGSUSED */
  1354. static Boolean
  1355. SetValuesPosthook(
  1356. Widget current,
  1357. Widget req,
  1358. Widget new,
  1359. ArgList args,
  1360. Cardinal *num_args )
  1361. {
  1362. XmWidgetExtData ext;
  1363. /*
  1364. * - register parts in cache.
  1365. * - update cache pointers
  1366. * - and free req
  1367. */
  1368. /* assign if changed! */
  1369. _DtProcessLock();
  1370. if (!IconCacheCompare((XtPointer)Icon_Cache(new),
  1371. (XtPointer)Icon_Cache(current)))
  1372. {
  1373. _XmCacheDelete((XtPointer) Icon_Cache(current)); /* delete the old one */
  1374. Icon_Cache(new) = (DtIconCacheObjPart *)
  1375. _XmCachePart(Icon_ClassCachePart(new),
  1376. (XtPointer) Icon_Cache(new),
  1377. sizeof(DtIconCacheObjPart));
  1378. } else
  1379. Icon_Cache(new) = Icon_Cache(current);
  1380. _XmPopWidgetExtData(new, &ext, XmCACHE_EXTENSION);
  1381. _XmExtObjFree((XtPointer)ext->widget);
  1382. _XmExtObjFree((XtPointer)ext->reqWidget);
  1383. _DtProcessUnlock();
  1384. XtFree((char *)ext);
  1385. return FALSE;
  1386. }
  1387. /*--------------------------------------------------------------------------
  1388. ** QualifyIconLocalCache
  1389. ** Checks to see if local cache is set up
  1390. */
  1391. static void
  1392. QualifyIconLocalCache(DtIconGadget g, DtIconCacheObjPart *local_cache)
  1393. {
  1394. _DtProcessLock();
  1395. ClassCacheCopy(Icon_ClassCachePart(g))((XtPointer) Icon_Cache(g),
  1396. (XtPointer) local_cache,
  1397. sizeof(DtIconCacheObjPart));
  1398. _DtProcessUnlock();
  1399. }
  1400. /************************************************************************
  1401. *
  1402. * ReCacheIcon_r()
  1403. * Check to see if ReCaching is necessary as a result of fields having
  1404. * been set by a mananger widget. This routine is called by the
  1405. * manager widget in their SetValues after a change is made to any
  1406. * of Icon's cached fields.
  1407. *
  1408. ************************************************************************/
  1409. static void
  1410. ReCacheIcon_r(DtIconCacheObjPart *local_cache, DtIconGadget g)
  1411. {
  1412. if (!IconCacheCompare( (XtPointer)local_cache, (XtPointer)Icon_Cache(g)))
  1413. {
  1414. _DtProcessLock();
  1415. _XmCacheDelete( (XtPointer) Icon_Cache(g)); /* delete the old one */
  1416. Icon_Cache(g) = (DtIconCacheObjPart *)
  1417. _XmCachePart(Icon_ClassCachePart(g),
  1418. (XtPointer) local_cache,
  1419. sizeof(DtIconCacheObjPart));
  1420. _DtProcessUnlock();
  1421. }
  1422. }
  1423. /*********************************************************************
  1424. *
  1425. * GetParentBackgroundGC
  1426. * Get the graphics context used for erasing their highlight border.
  1427. *
  1428. *********************************************************************/
  1429. static void
  1430. GetParentBackgroundGC(
  1431. DtIconGadget g )
  1432. {
  1433. XGCValues values;
  1434. XtGCMask valueMask;
  1435. Widget parent = XtParent((Widget)g);
  1436. valueMask = GCForeground | GCBackground;
  1437. values.foreground = parent->core.background_pixel;
  1438. if (XmIsManager(parent))
  1439. values.background = ((XmManagerWidget) parent)->manager.foreground;
  1440. else
  1441. values.background = ((XmPrimitiveWidget) parent)->primitive.foreground;
  1442. if ((parent->core.background_pixmap != None) &&
  1443. (parent->core.background_pixmap != XmUNSPECIFIED_PIXMAP))
  1444. {
  1445. valueMask |= GCFillStyle | GCTile;
  1446. values.fill_style = FillTiled;
  1447. values.tile = parent->core.background_pixmap;
  1448. }
  1449. G_SavedParentBG(g) = parent->core.background_pixel;
  1450. G_ParentBackgroundGC(g) = XtGetGC (parent, valueMask, &values);
  1451. }
  1452. /*-------------------------------------------------------------
  1453. ** Initialize
  1454. ** Initialize a new gadget instance.
  1455. */
  1456. static void
  1457. Initialize(
  1458. Widget request_w,
  1459. Widget new_w )
  1460. {
  1461. DtIconGadget request = (DtIconGadget) request_w,
  1462. new = (DtIconGadget) new_w;
  1463. Window root;
  1464. int int_x = 0, int_y = 0;
  1465. unsigned int int_w = 0, int_h = 0,
  1466. int_bw, depth;
  1467. Dimension w, h;
  1468. EventMask mask;
  1469. String name = NULL;
  1470. UpdateGCsProc update_gcs;
  1471. G_Sync (new) = False;
  1472. /* Validate behavior.
  1473. */
  1474. if (G_Behavior (new) != XmICON_LABEL &&
  1475. G_Behavior (new) != XmICON_BUTTON &&
  1476. G_Behavior (new) != XmICON_TOGGLE &&
  1477. G_Behavior (new) != XmICON_DRAG)
  1478. {
  1479. XmeWarning ((Widget)new, WARN_BEHAVIOR);
  1480. G_Behavior (new) = XmICON_BUTTON;
  1481. }
  1482. /* Set the input mask for events handled by Manager.
  1483. */
  1484. G_EventMask (new) = (XmARM_EVENT | XmACTIVATE_EVENT |
  1485. XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
  1486. XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
  1487. XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
  1488. /* Add event handler for icon events.
  1489. */
  1490. if (G_Behavior (new) == XmICON_DRAG)
  1491. {
  1492. mask = ButtonPressMask|ButtonReleaseMask;
  1493. XtAddEventHandler (XtParent (new), mask, False,
  1494. (XtEventHandler) IconEventHandler, 0);
  1495. }
  1496. G_ClickTimerID (new) = 0;
  1497. G_ClickEvent (new) = NULL;
  1498. G_Armed (new) = False;
  1499. G_Mask (new) = None;
  1500. if (G_Pixmap (new) == XmUNSPECIFIED_PIXMAP)
  1501. G_Pixmap (new) = None;
  1502. if (G_ImageName (new) || G_Pixmap (new))
  1503. {
  1504. if (G_ImageName (new))
  1505. {
  1506. /* Try to get pixmap from image name.
  1507. */
  1508. G_Pixmap (new) =
  1509. XmGetPixmap (XtScreen (new), G_ImageName (new),
  1510. G_PixmapForeground (new),
  1511. G_PixmapBackground (new));
  1512. if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
  1513. {
  1514. name = G_ImageName (new);
  1515. G_Mask (new) =
  1516. _DtGetMask(XtScreen (new), G_ImageName
  1517. (new));
  1518. }
  1519. else
  1520. {
  1521. /* warning? */
  1522. name = NULL;
  1523. G_Pixmap (new) = None;
  1524. }
  1525. }
  1526. /* Update width and height; copy image name.
  1527. */
  1528. if (G_Pixmap (new))
  1529. {
  1530. XGetGeometry (XtDisplay (new), G_Pixmap (new),
  1531. &root, &int_x, &int_y, &int_w, &int_h,
  1532. &int_bw, &depth);
  1533. }
  1534. if (name)
  1535. {
  1536. G_ImageName (new) = XtNewString(name);
  1537. }
  1538. else
  1539. G_ImageName (new) = NULL;
  1540. }
  1541. G_PixmapWidth(new) = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
  1542. G_PixmapHeight(new) = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
  1543. /* Validate fill mode.
  1544. */
  1545. if (G_FillMode (new) != XmFILL_NONE &&
  1546. G_FillMode (new) != XmFILL_PARENT &&
  1547. G_FillMode (new) != XmFILL_TRANSPARENT &&
  1548. G_FillMode (new) != XmFILL_SELF)
  1549. {
  1550. XmeWarning ((Widget)new, WARN_FILL_MODE);
  1551. if (G_ShadowThickness (new) > 0)
  1552. G_FillMode (new) = XmFILL_SELF;
  1553. else
  1554. G_FillMode (new) = XmFILL_PARENT;
  1555. }
  1556. /* Validate pixmap position.
  1557. */
  1558. if (G_StringPosition (new) != UNSPECIFIED_CHAR)
  1559. G_PixmapPosition (new) = G_StringPosition (new);
  1560. if (G_PixmapPosition (new) == UNSPECIFIED_CHAR)
  1561. G_PixmapPosition (new) = XmPIXMAP_LEFT;
  1562. else if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
  1563. G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
  1564. G_PixmapPosition (new) != XmPIXMAP_TOP &&
  1565. G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
  1566. G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
  1567. {
  1568. XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
  1569. G_PixmapPosition (new) = XmPIXMAP_LEFT;
  1570. }
  1571. G_StringPosition (new) = G_PixmapPosition (new);
  1572. /* Validate alignment.
  1573. */
  1574. if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
  1575. G_Alignment (new) != XmALIGNMENT_CENTER &&
  1576. G_Alignment (new) != XmALIGNMENT_END)
  1577. {
  1578. XmeWarning ((Widget)new, WARN_ALIGNMENT);
  1579. G_Alignment (new) = XmALIGNMENT_BEGINNING;
  1580. }
  1581. /* Validate shadow type.
  1582. */
  1583. if (G_ShadowType (new) != XmSHADOW_IN &&
  1584. G_ShadowType (new) != XmSHADOW_OUT &&
  1585. G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
  1586. G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
  1587. {
  1588. XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
  1589. if (G_Behavior (new) == XmICON_BUTTON)
  1590. G_ShadowType (new) = XmSHADOW_OUT;
  1591. else if (G_Behavior (new) == XmICON_TOGGLE)
  1592. G_ShadowType (new) = (G_Set (new))
  1593. ? XmSHADOW_ETCHED_IN : XmSHADOW_ETCHED_OUT;
  1594. }
  1595. /* Copy fontlist.
  1596. */
  1597. if (G_FontList (new) == NULL)
  1598. G_FontList (new) =
  1599. XmeGetDefaultRenderTable ((Widget)new, XmBUTTON_FONTLIST);
  1600. G_FontList (new) = XmFontListCopy (G_FontList (new));
  1601. if (G_String (new) == XmUNSPECIFIED_STRING)
  1602. G_String (new) = (_XmString) NULL;
  1603. if (G_String (new))
  1604. {
  1605. G_String (new) = XmStringCopy (G_String (new));
  1606. XmStringExtent (G_FontList (new), G_String (new),
  1607. &w, &h);
  1608. if (G_Underline(new))
  1609. h++;
  1610. }
  1611. else
  1612. w = h = 0;
  1613. G_StringWidth (new) = w;
  1614. G_StringHeight (new) = h;
  1615. /* Convert margins to pixel units.
  1616. */
  1617. if (G_UnitType (new) != XmPIXELS)
  1618. {
  1619. G_MarginWidth (new) =
  1620. XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
  1621. (XtArgVal *)G_MarginWidth (new));
  1622. G_MarginHeight (new) =
  1623. XmeToVerticalPixels ((Widget)new, G_UnitType (new),
  1624. (XtArgVal *)G_MarginHeight (new));
  1625. }
  1626. /* Check for unspecified margins.
  1627. */
  1628. if (G_MarginWidth (request) == UNSPECIFIED_DIMENSION)
  1629. G_MarginWidth (new) = MARGIN_DEFAULT;
  1630. if (G_MarginHeight (request) == UNSPECIFIED_DIMENSION)
  1631. G_MarginHeight (new) = MARGIN_DEFAULT;
  1632. /* Convert spacing.
  1633. */
  1634. if (G_Spacing (new) == UNSPECIFIED_DIMENSION)
  1635. {
  1636. G_Spacing (new) = G_StringHeight (new) / 5;
  1637. if (G_Spacing (new) < SPACING_DEFAULT)
  1638. G_Spacing (new) = SPACING_DEFAULT;
  1639. }
  1640. else if (G_Spacing (new) && G_UnitType (new) != XmPIXELS)
  1641. {
  1642. G_Spacing (new) =
  1643. (G_PixmapPosition (new) == XmPIXMAP_LEFT ||
  1644. G_PixmapPosition (new) == XmPIXMAP_RIGHT)
  1645. ? XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
  1646. (XtArgVal *)G_Spacing (new))
  1647. : XmeToVerticalPixels ((Widget)new, G_UnitType (new),
  1648. (XtArgVal *)G_Spacing (new));
  1649. }
  1650. /* Set width and height.
  1651. */
  1652. if (G_Width (request) == 0 || G_Height (request) == 0)
  1653. {
  1654. GetSizeProc get_size;
  1655. _DtProcessLock();
  1656. get_size = C_GetSize(XtClass(new));
  1657. _DtProcessUnlock();
  1658. (*get_size) (new, &w, &h);
  1659. if (G_Width (request) == 0)
  1660. G_Width (new) = w;
  1661. if (G_Height (request) == 0)
  1662. G_Height (new) = h;
  1663. }
  1664. /* Get graphics contexts.
  1665. */
  1666. G_NormalGC (new) = NULL;
  1667. G_ClipGC (new) = NULL;
  1668. G_BackgroundGC (new) = NULL;
  1669. G_ArmedGC (new) = NULL;
  1670. G_ArmedBackgroundGC (new) = NULL;
  1671. _DtProcessLock();
  1672. update_gcs = C_UpdateGCs(XtClass(new));
  1673. _DtProcessUnlock();
  1674. (*update_gcs) (new);
  1675. GetParentBackgroundGC(new);
  1676. if (G_Operations(new) != XmDROP_NOOP) {
  1677. _DtIconRegisterDropsite(new_w);
  1678. }
  1679. }
  1680. /*-------------------------------------------------------------
  1681. ** Destroy
  1682. ** Release resources allocated for gadget.
  1683. */
  1684. static void
  1685. Destroy(
  1686. Widget w )
  1687. {
  1688. DtIconGadget g = (DtIconGadget) w;
  1689. XmManagerWidget mw = (XmManagerWidget) XtParent(g);
  1690. if (G_ClickTimerID (g))
  1691. XtRemoveTimeOut (G_ClickTimerID (g));
  1692. XtFree ((char *)G_ClickEvent (g));
  1693. if (G_String (g) != NULL)
  1694. XmStringFree (G_String (g));
  1695. if (G_ImageName (g) != NULL)
  1696. {
  1697. XtFree (G_ImageName (g));
  1698. if (G_Mask (g) != XmUNSPECIFIED_PIXMAP)
  1699. XmDestroyPixmap (XtScreen(w),G_Mask (g));
  1700. XmDestroyPixmap (XtScreen(w),G_Pixmap (g));
  1701. }
  1702. XmFontListFree (G_FontList (g));
  1703. _DtProcessLock();
  1704. _XmCacheDelete((XtPointer) Icon_Cache(w));
  1705. _DtProcessUnlock();
  1706. XtReleaseGC ((Widget)mw, G_NormalGC (g));
  1707. XtReleaseGC ((Widget)mw, G_ClipGC (g));
  1708. XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
  1709. XtReleaseGC ((Widget)mw, G_ArmedGC (g));
  1710. XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
  1711. /* remove event handler if last Icon in parent? */
  1712. }
  1713. /*-------------------------------------------------------------
  1714. ** Resize
  1715. ** Set clip rect?
  1716. */
  1717. /* ARGSUSED */
  1718. static void
  1719. Resize(
  1720. Widget w )
  1721. {
  1722. }
  1723. /*-------------------------------------------------------------
  1724. ** Redisplay
  1725. ** Redisplay gadget.
  1726. */
  1727. /* ARGSUSED */
  1728. static void
  1729. Redisplay(
  1730. Widget w,
  1731. XEvent *event,
  1732. Region region )
  1733. {
  1734. DtIconGadget g = (DtIconGadget) w;
  1735. Dimension s_t = G_ShadowThickness (g);
  1736. unsigned char fill_mode = G_FillMode (g);
  1737. DrawProc draw;
  1738. if (! XtIsManaged (w))
  1739. return;
  1740. /* Draw gadget to window.
  1741. */
  1742. _DtProcessLock();
  1743. draw = C_Draw(XtClass(g));
  1744. _DtProcessUnlock();
  1745. (*draw) (g, XtWindow (g), G_X (g), G_Y (g), G_Width (g), G_Height (g),
  1746. G_HighlightThickness (g), s_t, G_ShadowType (g), fill_mode);
  1747. /* Draw highlight if highlighted.
  1748. */
  1749. if (G_Highlighted (g))
  1750. BorderHighlight( (DtIconGadget)g );
  1751. }
  1752. /*-------------------------------------------------------------
  1753. ** SetValues
  1754. **
  1755. */
  1756. /* ARGSUSED */
  1757. static Boolean
  1758. SetValues(
  1759. Widget current_w,
  1760. Widget request_w,
  1761. Widget new_w )
  1762. {
  1763. DtIconGadget current = (DtIconGadget) current_w,
  1764. new = (DtIconGadget) new_w;
  1765. Window root;
  1766. int int_x = 0, int_y = 0;
  1767. unsigned int int_w = 0, int_h = 0,
  1768. int_bw, depth;
  1769. Dimension w, h;
  1770. Boolean new_image_name = False,
  1771. redraw_flag = False,
  1772. draw_pixmap = False,
  1773. draw_string = False,
  1774. draw_shadow = False;
  1775. Dimension h_t = G_HighlightThickness (new),
  1776. s_t = G_ShadowThickness (new),
  1777. p_x, p_y, s_x, s_y;
  1778. String name = NULL;
  1779. Boolean optimize_redraw = False;
  1780. /* If unchanged, reuse old image name
  1781. */
  1782. if (G_ImageName (current) != G_ImageName (new) &&
  1783. G_ImageName (new) &&
  1784. G_ImageName (current) &&
  1785. strcmp(G_ImageName (current), G_ImageName (new)) == 0)
  1786. {
  1787. G_ImageName (new) = G_ImageName (current);
  1788. }
  1789. /* Validate behavior
  1790. */
  1791. if (G_Behavior (new) != G_Behavior (current))
  1792. {
  1793. if (G_Behavior (new) != XmICON_LABEL &&
  1794. G_Behavior (new) != XmICON_BUTTON &&
  1795. G_Behavior (new) != XmICON_TOGGLE &&
  1796. G_Behavior (new) != XmICON_DRAG)
  1797. {
  1798. XmeWarning ((Widget)new, WARN_BEHAVIOR);
  1799. G_Behavior (new) = G_Behavior (current);
  1800. }
  1801. if (G_Behavior (new) == XmICON_DRAG)
  1802. {
  1803. EventMask mask;
  1804. mask = ButtonPressMask|ButtonReleaseMask;
  1805. XtAddEventHandler (XtParent (new), mask, False,
  1806. (XtEventHandler) IconEventHandler, 0);
  1807. }
  1808. }
  1809. /* Reset the interesting input types.
  1810. */
  1811. G_EventMask (new) |= (XmARM_EVENT | XmACTIVATE_EVENT |
  1812. XmMULTI_ARM_EVENT | XmMULTI_ACTIVATE_EVENT |
  1813. XmHELP_EVENT | XmFOCUS_IN_EVENT | XmKEY_EVENT |
  1814. XmFOCUS_OUT_EVENT | XmENTER_EVENT | XmLEAVE_EVENT);
  1815. /* Check for new image name.
  1816. */
  1817. if (G_ImageName (new) && (G_ImageName (current) != G_ImageName (new)))
  1818. new_image_name = True;
  1819. /* Validate shadow type.
  1820. */
  1821. if ((G_ShadowType (new) != G_ShadowType (current)) ||
  1822. (G_Behavior (new) == XmICON_TOGGLE &&
  1823. G_Set (new) != G_Set (current)))
  1824. {
  1825. if (G_ShadowType (new) != XmSHADOW_IN &&
  1826. G_ShadowType (new) != XmSHADOW_OUT &&
  1827. G_ShadowType (new) != XmSHADOW_ETCHED_IN &&
  1828. G_ShadowType (new) != XmSHADOW_ETCHED_OUT)
  1829. {
  1830. XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
  1831. G_ShadowType (new) = G_ShadowType (current);
  1832. }
  1833. /* Disallow change if conflict with set or armed state.
  1834. */
  1835. else if (((G_Behavior (new) == XmICON_TOGGLE) &&
  1836. ((G_Set (new) && ! G_Armed (new)) ||
  1837. (! G_Set (new) && G_Armed (new)))) ||
  1838. ((G_Behavior (new) == XmICON_BUTTON) &&
  1839. (G_Armed (new))))
  1840. {
  1841. if (G_ShadowType (new) == XmSHADOW_OUT)
  1842. G_ShadowType (new) = XmSHADOW_IN;
  1843. else if (G_ShadowType (new) == XmSHADOW_ETCHED_OUT)
  1844. G_ShadowType (new) = XmSHADOW_ETCHED_IN;
  1845. }
  1846. else if (((G_Behavior (new) == XmICON_TOGGLE) &&
  1847. ((G_Set (new) && G_Armed (new)) ||
  1848. (! G_Set (new) && ! G_Armed (new)))) ||
  1849. ((G_Behavior (new) == XmICON_BUTTON) &&
  1850. (! G_Armed (new))))
  1851. {
  1852. if (G_ShadowType (new) == XmSHADOW_IN)
  1853. G_ShadowType (new) = XmSHADOW_OUT;
  1854. else if (G_ShadowType (new) == XmSHADOW_ETCHED_IN)
  1855. G_ShadowType (new) = XmSHADOW_ETCHED_OUT;
  1856. }
  1857. if (G_ShadowType (new) != G_ShadowType (current))
  1858. draw_shadow = True;
  1859. }
  1860. /* Validate alignment.
  1861. */
  1862. if (G_Alignment (new) != G_Alignment (current))
  1863. {
  1864. if (G_Alignment (new) != XmALIGNMENT_BEGINNING &&
  1865. G_Alignment (new) != XmALIGNMENT_CENTER &&
  1866. G_Alignment (new) != XmALIGNMENT_END)
  1867. {
  1868. XmeWarning ((Widget)new, WARN_ALIGNMENT);
  1869. G_Alignment (new) = G_Alignment (current);
  1870. }
  1871. else
  1872. redraw_flag = True;
  1873. }
  1874. /* Validate fill mode.
  1875. */
  1876. if (G_FillMode (new) != G_FillMode (current))
  1877. {
  1878. if (G_FillMode (new) != XmFILL_NONE &&
  1879. G_FillMode (new) != XmFILL_PARENT &&
  1880. G_FillMode (new) != XmFILL_TRANSPARENT &&
  1881. G_FillMode (new) != XmFILL_SELF)
  1882. {
  1883. XmeWarning ((Widget)new, WARN_FILL_MODE);
  1884. G_FillMode (new) = G_FillMode (current);
  1885. }
  1886. }
  1887. /* Validate pixmap position.
  1888. */
  1889. if (G_StringPosition (new) != G_StringPosition (current))
  1890. G_PixmapPosition (new) = G_StringPosition (new);
  1891. if (G_PixmapPosition (new) != G_PixmapPosition (current))
  1892. {
  1893. if (G_PixmapPosition (new) != XmPIXMAP_LEFT &&
  1894. G_PixmapPosition (new) != XmPIXMAP_RIGHT &&
  1895. G_PixmapPosition (new) != XmPIXMAP_TOP &&
  1896. G_PixmapPosition (new) != XmPIXMAP_BOTTOM &&
  1897. G_PixmapPosition (new) != XmPIXMAP_MIDDLE)
  1898. {
  1899. XmeWarning ((Widget)new, WARN_PIXMAP_POSITION);
  1900. G_PixmapPosition (new) = G_PixmapPosition (current);
  1901. }
  1902. else
  1903. redraw_flag = True;
  1904. G_StringPosition (new) = G_PixmapPosition (new);
  1905. }
  1906. /* Update pixmap if pixmap foreground or background changed.
  1907. */
  1908. if (G_PixmapForeground (current) != G_PixmapForeground (new) ||
  1909. G_PixmapBackground (current) != G_PixmapBackground (new))
  1910. {
  1911. if (G_Pixmap (current) == G_Pixmap (new) &&
  1912. (G_ImageName (new) != NULL) &&
  1913. (! new_image_name))
  1914. {
  1915. draw_pixmap = True;
  1916. if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
  1917. XmDestroyPixmap( XtScreen(new), G_Mask(current));
  1918. XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
  1919. G_Pixmap (new) =
  1920. XmGetPixmap (XtScreen (new), G_ImageName (new),
  1921. G_PixmapForeground (new),
  1922. G_PixmapBackground (new));
  1923. if (G_Pixmap(new) != XmUNSPECIFIED_PIXMAP)
  1924. G_Mask (new) =
  1925. _DtGetMask(XtScreen (new), G_ImageName (new));
  1926. }
  1927. }
  1928. /* Check for change in image name.
  1929. */
  1930. if (new_image_name)
  1931. {
  1932. /* Try to get pixmap from image name.
  1933. */
  1934. if (G_ImageName (current) != NULL)
  1935. {
  1936. if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
  1937. XmDestroyPixmap (XtScreen(new),G_Mask(current));
  1938. XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
  1939. }
  1940. G_Pixmap (new) =
  1941. XmGetPixmap (XtScreen (new), G_ImageName (new),
  1942. G_PixmapForeground (new),
  1943. G_PixmapBackground (new));
  1944. if (G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
  1945. {
  1946. G_Mask(new) = (Pixmap)_DtGetMask(XtScreen(new), G_ImageName(new));
  1947. XGetGeometry (XtDisplay (new), G_Pixmap (new),
  1948. &root, &int_x, &int_y, &int_w, &int_h,
  1949. &int_bw, &depth);
  1950. name = G_ImageName (new);
  1951. w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
  1952. h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
  1953. }
  1954. else
  1955. {
  1956. name = NULL;
  1957. G_Pixmap (new) = None;
  1958. w = 0;
  1959. h = 0;
  1960. }
  1961. /* If resetting to current image name, then reuse old copy.
  1962. */
  1963. if (name && G_ImageName (current)
  1964. && (! strcmp (G_ImageName (new), G_ImageName (current))))
  1965. {
  1966. G_ImageName (new) = G_ImageName (current);
  1967. name = G_ImageName (current);
  1968. }
  1969. else
  1970. {
  1971. if (name)
  1972. G_ImageName (new) = XtNewString(name);
  1973. else
  1974. G_ImageName (new) = NULL;
  1975. if (G_ImageName (current))
  1976. XtFree (G_ImageName (current));
  1977. }
  1978. if (G_Pixmap (new) != G_Pixmap (current))
  1979. {
  1980. if ((G_Pixmap (new) != None) &&
  1981. (G_PixmapWidth (new) == w) &&
  1982. (G_PixmapHeight (new) == h))
  1983. {
  1984. draw_pixmap = True;
  1985. }
  1986. else
  1987. {
  1988. redraw_flag = True;
  1989. G_PixmapWidth (new) = w;
  1990. G_PixmapHeight (new) = h;
  1991. }
  1992. }
  1993. }
  1994. /* Release image name and pixmap if name set to null.
  1995. */
  1996. else if (G_Pixmap (new) == G_Pixmap (current))
  1997. {
  1998. if ((G_ImageName (current) != NULL) &&
  1999. (G_ImageName (new) == NULL))
  2000. {
  2001. redraw_flag = True;
  2002. XtFree (G_ImageName (current));
  2003. if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
  2004. XmDestroyPixmap (XtScreen(new),G_Mask (current));
  2005. XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
  2006. G_Pixmap (new) = None;
  2007. G_PixmapWidth (new) = 0;
  2008. G_PixmapHeight (new) = 0;
  2009. }
  2010. }
  2011. /* Process change in pixmap.
  2012. */
  2013. else if (G_Pixmap (new) != G_Pixmap (current))
  2014. {
  2015. if (G_Pixmap (new))
  2016. {
  2017. XGetGeometry (XtDisplay (new), G_Pixmap (new), &root,
  2018. &int_x, &int_y, &int_w, &int_h,
  2019. &int_bw, &depth);
  2020. w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
  2021. h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
  2022. }
  2023. else
  2024. {
  2025. if (G_ImageName (current) != NULL)
  2026. {
  2027. XtFree (G_ImageName (current));
  2028. if (G_Mask(new) != XmUNSPECIFIED_PIXMAP)
  2029. XmDestroyPixmap (XtScreen(new),G_Mask (current));
  2030. XmDestroyPixmap (XtScreen(new),G_Pixmap (current));
  2031. G_ImageName (new) = NULL;
  2032. }
  2033. w = h = 0;
  2034. }
  2035. if (G_Pixmap (new) &&
  2036. (G_PixmapWidth (new) == w) &&
  2037. (G_PixmapHeight (new) == h))
  2038. {
  2039. draw_pixmap = True;
  2040. }
  2041. else
  2042. {
  2043. redraw_flag = True;
  2044. G_PixmapWidth (new) = w;
  2045. G_PixmapHeight (new) = h;
  2046. }
  2047. }
  2048. if( ( G_MaxPixmapWidth(new) != G_MaxPixmapWidth(current)) ||
  2049. (G_MaxPixmapHeight(new) != G_MaxPixmapHeight(current)) )
  2050. {
  2051. if (G_Pixmap (new))
  2052. {
  2053. XGetGeometry (XtDisplay (new), G_Pixmap (new), &root,
  2054. &int_x, &int_y, &int_w, &int_h,
  2055. &int_bw, &depth);
  2056. w = Limit((Dimension) int_w, G_MaxPixmapWidth(new));
  2057. h = Limit((Dimension) int_h, G_MaxPixmapHeight(new));
  2058. }
  2059. else
  2060. {
  2061. w = h = 0;
  2062. }
  2063. if (G_Pixmap (new) &&
  2064. (G_PixmapWidth (new) == w) &&
  2065. (G_PixmapHeight (new) == h))
  2066. {
  2067. draw_pixmap = True;
  2068. }
  2069. else
  2070. {
  2071. redraw_flag = True;
  2072. G_PixmapWidth (new) = w;
  2073. G_PixmapHeight (new) = h;
  2074. }
  2075. }
  2076. /* Update GCs if foreground, background or mask changed.
  2077. */
  2078. if (G_Foreground (current) != G_Foreground (new) ||
  2079. G_Background (current) != G_Background (new) ||
  2080. ((G_Mask (current) != G_Mask(new)) &&
  2081. (G_Pixmap (current) != G_Pixmap (new))) ||
  2082. G_ArmColor (current) != G_ArmColor (new))
  2083. {
  2084. UpdateGCsProc update_gcs;
  2085. if (G_ShadowThickness (new) > 0 &&
  2086. G_Behavior(new) != XmICON_DRAG &&
  2087. G_Background (current) != G_Background (new))
  2088. redraw_flag = True;
  2089. else
  2090. draw_string = True;
  2091. _DtProcessLock();
  2092. update_gcs = C_UpdateGCs(XtClass(new));
  2093. _DtProcessUnlock();
  2094. (*update_gcs) (new);
  2095. }
  2096. /* Convert dimensions to pixel units.
  2097. */
  2098. if (G_UnitType (new) != XmPIXELS)
  2099. {
  2100. G_MarginWidth (new) =
  2101. XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
  2102. (XtArgVal *)G_MarginWidth (new));
  2103. G_MarginHeight (new) =
  2104. XmeToVerticalPixels ((Widget)new, G_UnitType (new),
  2105. (XtArgVal *)G_MarginHeight (new));
  2106. }
  2107. /* Convert spacing.
  2108. */
  2109. if (G_UnitType (new) != G_UnitType (current) &&
  2110. G_UnitType (new) != XmPIXELS)
  2111. {
  2112. G_Spacing (new) =
  2113. (G_PixmapPosition (new) == XmPIXMAP_LEFT ||
  2114. G_PixmapPosition (new) == XmPIXMAP_RIGHT)
  2115. ? XmeToHorizontalPixels ((Widget)new, G_UnitType (new),
  2116. (XtArgVal *)G_Spacing (new))
  2117. : XmeToVerticalPixels ((Widget)new, G_UnitType (new),
  2118. (XtArgVal *)G_Spacing (new));
  2119. }
  2120. /* Process change in string or font list.
  2121. */
  2122. if (G_String (new) != G_String (current) ||
  2123. G_FontList (new) != G_FontList (current) ||
  2124. G_Underline (new) != G_Underline (current))
  2125. {
  2126. if (G_FontList (new) != G_FontList (current))
  2127. {
  2128. if (G_FontList (new) == NULL)
  2129. G_FontList (new) = G_FontList (current);
  2130. else
  2131. {
  2132. XmFontListFree (G_FontList (current));
  2133. G_FontList (new) =
  2134. XmFontListCopy (G_FontList (new));
  2135. }
  2136. }
  2137. if (G_String (new))
  2138. {
  2139. if (G_String (new) != G_String (current))
  2140. {
  2141. if (G_String (current))
  2142. XmStringFree (G_String (current));
  2143. G_String (new) =
  2144. XmStringCopy (G_String (new));
  2145. }
  2146. XmStringExtent (G_FontList (new), G_String (new),
  2147. &w, &h);
  2148. if (G_Underline(new))
  2149. h++;
  2150. }
  2151. else
  2152. w = h = 0;
  2153. G_StringWidth (new) = w;
  2154. G_StringHeight (new) = h;
  2155. G_Spacing (new) = (Dimension) G_StringHeight (new) / 5;
  2156. if (G_Spacing (new) < SPACING_DEFAULT)
  2157. G_Spacing (new) = SPACING_DEFAULT;
  2158. if ((G_String (new) != NULL) &&
  2159. (G_StringWidth (new) == G_StringWidth (current)) &&
  2160. (G_StringHeight (new) == G_StringHeight (current)))
  2161. draw_string = True;
  2162. else
  2163. redraw_flag = True;
  2164. }
  2165. /* Check for other changes requiring redraw.
  2166. */
  2167. if (G_HighlightThickness (new) != G_HighlightThickness (current) ||
  2168. G_ShadowThickness (new) != G_ShadowThickness (current) ||
  2169. G_MarginWidth (new) != G_MarginWidth (current) ||
  2170. G_MarginHeight (new) != G_MarginHeight (current) ||
  2171. G_Spacing (new) != G_Spacing (current))
  2172. {
  2173. redraw_flag = True;
  2174. }
  2175. /* Update size.
  2176. */
  2177. if (!(redraw_flag ||
  2178. (G_RecomputeSize (new) && ! G_RecomputeSize (current))))
  2179. {
  2180. _DtProcessLock();
  2181. optimize_redraw = C_OptimizeRedraw(XtClass(new));
  2182. _DtProcessUnlock();
  2183. }
  2184. if (redraw_flag ||
  2185. (G_RecomputeSize (new) && ! G_RecomputeSize (current)))
  2186. {
  2187. if (G_RecomputeSize (new) &&
  2188. (G_Width (current) == G_Width (new) ||
  2189. G_Height (current) == G_Height (new)))
  2190. {
  2191. GetSizeProc get_size;
  2192. _DtProcessLock();
  2193. get_size = C_GetSize(XtClass(new));
  2194. _DtProcessUnlock();
  2195. (*get_size) (new, &w, &h);
  2196. if (G_Width (current) == G_Width (new))
  2197. G_Width (new) = w;
  2198. if (G_Height (current) == G_Height (new))
  2199. G_Height (new) = h;
  2200. }
  2201. }
  2202. /* Set redraw flag if this class doesn't optimize redraw.
  2203. */
  2204. else if (! optimize_redraw)
  2205. {
  2206. if (draw_shadow || draw_pixmap || draw_string)
  2207. redraw_flag = True;
  2208. }
  2209. /* Optimize redraw if managed.
  2210. */
  2211. else if (XtIsManaged (new_w) && XtIsRealized(new_w))
  2212. {
  2213. /* Get string and pixmap positions if necessary.
  2214. */
  2215. if ((draw_pixmap && G_Pixmap (new)) ||
  2216. (draw_string && G_String (new)))
  2217. {
  2218. GetPositionProc get_positions;
  2219. _DtProcessLock();
  2220. get_positions = C_GetPositions(XtClass(new));
  2221. _DtProcessUnlock();
  2222. (*get_positions) (new, G_Width (new), G_Height (new),
  2223. h_t, G_ShadowThickness (new),
  2224. (Position *)&p_x, (Position *)&p_y,
  2225. (Position *)&s_x, (Position *)&s_y);
  2226. }
  2227. /* Copy pixmap, clip if necessary.
  2228. */
  2229. if (draw_pixmap && G_Pixmap (new) &&
  2230. G_Pixmap (new) != XmUNSPECIFIED_PIXMAP)
  2231. {
  2232. w = ((unsigned) (p_x + s_t + h_t) >= G_Width (new))
  2233. ? 0 : Min ((unsigned)G_PixmapWidth (new),
  2234. G_Width (new) - p_x - s_t - h_t);
  2235. h = ((unsigned) (p_y + s_t + h_t) >= G_Height (new))
  2236. ? 0 : Min ((unsigned)G_PixmapHeight (new),
  2237. G_Height (new) - p_y - s_t - h_t);
  2238. if (w > 0 && h > 0) {
  2239. XCopyArea
  2240. (XtDisplay (new), G_Pixmap (new), XtWindow (new),
  2241. GetMaskGC(new, G_X(new) + p_x, G_Y(new) + p_y),
  2242. 0, 0,
  2243. w, h, G_X (new) + p_x, G_Y (new) + p_y);
  2244. }
  2245. }
  2246. /* Draw string with normal or armed background; clip if necessary.
  2247. */
  2248. if (draw_string && G_String (new))
  2249. {
  2250. GC gc;
  2251. XRectangle clip;
  2252. unsigned char behavior = G_Behavior (new);
  2253. if ((behavior == XmICON_BUTTON ||
  2254. behavior == XmICON_DRAG) &&
  2255. G_FillOnArm (new) && G_Armed (new))
  2256. gc = G_ArmedGC (new);
  2257. else if (behavior == XmICON_TOGGLE &&
  2258. G_FillOnArm (new) &&
  2259. ((G_Armed (new) && !G_Set (new)) ||
  2260. (!G_Armed (new) && G_Set (new))))
  2261. gc = G_ArmedGC (new);
  2262. else
  2263. gc = G_NormalGC (new);
  2264. clip.x = G_X (new) + s_x;
  2265. clip.y = G_Y (new) + s_y;
  2266. clip.width = (s_x + s_t + h_t >=
  2267. (unsigned)G_Width (new))
  2268. ? 0 : Min ((unsigned)G_StringWidth (new),
  2269. G_Width (new) - s_x - s_t - h_t);
  2270. clip.height = (s_y + s_t + h_t >=
  2271. (unsigned)G_Height (new))
  2272. ? 0 : Min ((unsigned)G_StringHeight (new),
  2273. G_Height (new) - s_y - s_t - h_t);
  2274. if (clip.width > 0 && clip.height > 0)
  2275. {
  2276. XmStringDrawImage (XtDisplay (new),
  2277. XtWindow (new), G_FontList (new),
  2278. G_String (new), gc,
  2279. G_X (new) + s_x, G_Y (new) + s_y,
  2280. clip.width, XmALIGNMENT_CENTER,
  2281. XmSTRING_DIRECTION_L_TO_R, &clip);
  2282. if (G_Underline(new))
  2283. {
  2284. XmStringDrawUnderline (XtDisplay (new),
  2285. XtWindow (new), G_FontList (new),
  2286. G_String (new), gc,
  2287. G_X (new) + s_x, G_Y (new) + s_y,
  2288. clip.width, XmALIGNMENT_CENTER,
  2289. XmSTRING_DIRECTION_L_TO_R, &clip,
  2290. G_String(new));
  2291. }
  2292. }
  2293. }
  2294. /* Draw shadow.
  2295. */
  2296. if (draw_shadow && G_DrawShadow(new))
  2297. {
  2298. if(G_BorderType(new) == DtRECTANGLE || !G_Pixmap(new))
  2299. XmeDrawShadows(XtDisplay(new), XtWindow(new),
  2300. M_TopShadowGC(MgrParent(new)),
  2301. M_BottomShadowGC(MgrParent(new)),
  2302. G_X(new) + h_t, G_Y(new) + h_t,
  2303. G_Width(new) - 2*h_t, G_Height(new) - 2*h_t,
  2304. G_ShadowThickness(new), G_ShadowType(new));
  2305. else
  2306. {
  2307. CallCallbackProc call_callback;
  2308. _DtProcessLock();
  2309. call_callback = C_CallCallback(XtClass(new));
  2310. _DtProcessUnlock();
  2311. (*call_callback) (new, G_Callback (new),
  2312. XmCR_SHADOW, NULL);
  2313. }
  2314. }
  2315. }
  2316. if (G_Operations(current) != G_Operations(new)) {
  2317. if (G_Operations(current) == XmDROP_NOOP){
  2318. _DtIconRegisterDropsite(new_w);
  2319. } else {
  2320. if (G_Operations(new) == XmDROP_NOOP)
  2321. DtDndDropUnregister(new_w);
  2322. else {
  2323. Arg args[1];
  2324. XtSetArg(args[0], XmNdropSiteOperations, G_Operations(new));
  2325. XmDropSiteUpdate(new_w, args, 1);
  2326. }
  2327. }
  2328. }
  2329. return (redraw_flag);
  2330. }
  2331. /*-------------------------------------------------------------
  2332. ** Gadget Procs
  2333. **-------------------------------------------------------------
  2334. */
  2335. /*-------------------------------------------------------------
  2336. ** BorderHighlight
  2337. **
  2338. */
  2339. static void
  2340. BorderHighlight( DtIconGadget g)
  2341. {
  2342. register int width;
  2343. register int height;
  2344. CallCallbackProc call_callback;
  2345. width = g->rectangle.width;
  2346. height = g->rectangle.height;
  2347. if (width == 0 || height == 0) return;
  2348. if (g->gadget.highlight_thickness == 0) return;
  2349. g->gadget.highlighted = True;
  2350. g->gadget.highlight_drawn = True;
  2351. if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
  2352. HighlightBorder ((Widget)g);
  2353. _DtProcessLock();
  2354. call_callback = C_CallCallback(XtClass(g));
  2355. _DtProcessUnlock();
  2356. (*call_callback) (g, G_Callback (g), XmCR_HIGHLIGHT, NULL);
  2357. }
  2358. /*-------------------------------------------------------------
  2359. ** BorderUnhighlight
  2360. **
  2361. */
  2362. static void
  2363. BorderUnhighlight( DtIconGadget g)
  2364. {
  2365. register int window_width;
  2366. register int window_height;
  2367. register int highlight_width;
  2368. CallCallbackProc call_callback;
  2369. window_width = g->rectangle.width;
  2370. window_height = g->rectangle.height;
  2371. if (window_width == 0 || window_height == 0) return;
  2372. highlight_width = g->gadget.highlight_thickness;
  2373. if (highlight_width == 0) return;
  2374. g->gadget.highlighted = False;
  2375. g->gadget.highlight_drawn = False;
  2376. if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
  2377. UnhighlightBorder ((Widget)g);
  2378. _DtProcessLock();
  2379. call_callback = C_CallCallback(XtClass(g));
  2380. _DtProcessUnlock();
  2381. (*call_callback) (g, G_Callback (g), XmCR_UNHIGHLIGHT, NULL);
  2382. }
  2383. /*-------------------------------------------------------------
  2384. ** ArmAndActivate
  2385. ** Invoke Activate.
  2386. */
  2387. static void
  2388. ArmAndActivate(
  2389. Widget w,
  2390. XEvent *event )
  2391. {
  2392. IconArm (w, event);
  2393. IconActivate (w, event);
  2394. }
  2395. /*-------------------------------------------------------------
  2396. ** InputDispatch
  2397. ** Process event dispatched from parent or event handler.
  2398. */
  2399. static void
  2400. InputDispatch(
  2401. Widget w,
  2402. XButtonEvent *event,
  2403. Mask event_mask )
  2404. {
  2405. DtIconGadget g = (DtIconGadget) w;
  2406. if (event_mask & XmARM_EVENT || event_mask & XmMULTI_ARM_EVENT)
  2407. if (event->button == Button2)
  2408. IconDrag (w, (XEvent*) event);
  2409. else if (event->button == Button3)
  2410. IconPopup (w, (XEvent*) event);
  2411. else
  2412. IconArm (w, (XEvent*) event);
  2413. else if (event_mask & XmACTIVATE_EVENT ||
  2414. event_mask & XmMULTI_ACTIVATE_EVENT)
  2415. {
  2416. if (event->button == Button3)
  2417. ;
  2418. else if (event->x >= G_X (g) &&
  2419. event->x <= G_X (g) + (int)G_Width (g) &&
  2420. event->y >= G_Y (g) &&
  2421. event->y <= G_Y (g) + (int)G_Height (g))
  2422. IconActivate (w, (XEvent*) event);
  2423. else
  2424. IconDisarm (w, (XEvent*) event);
  2425. }
  2426. else if (event_mask & XmHELP_EVENT)
  2427. _XmSocorro (w, (XEvent *)event,
  2428. (String *)NULL,(Cardinal)0);
  2429. else if (event_mask & XmENTER_EVENT)
  2430. IconEnter (w, (XEvent *)event);
  2431. else if (event_mask & XmLEAVE_EVENT)
  2432. IconLeave (w, (XEvent *)event);
  2433. else if (event_mask & XmFOCUS_IN_EVENT)
  2434. _XmFocusInGadget (w, (XEvent *)event,
  2435. (String *)NULL,(Cardinal)0);
  2436. else if (event_mask & XmFOCUS_OUT_EVENT)
  2437. _XmFocusOutGadget (w, (XEvent *)event,
  2438. (String *)NULL,(Cardinal)0);
  2439. }
  2440. /*-------------------------------------------------------------
  2441. ** VisualChange
  2442. ** Update GCs when parent visuals change.
  2443. */
  2444. static Boolean
  2445. VisualChange(
  2446. Widget w,
  2447. Widget current_w,
  2448. Widget new_w )
  2449. {
  2450. XmManagerWidget current = (XmManagerWidget) current_w;
  2451. XmManagerWidget new = (XmManagerWidget) new_w;
  2452. DtIconGadget g = (DtIconGadget) w;
  2453. Boolean update = False;
  2454. DtIconCacheObjPart local_cache;
  2455. UpdateGCsProc update_gcs;
  2456. QualifyIconLocalCache(g, &local_cache);
  2457. /* If foreground or background was the same as the parent, and parent
  2458. ** foreground or background has changed, then update gcs and pixmap.
  2459. */
  2460. /* (can't really tell if explicitly set to be same as parent!
  2461. ** -- could add flags set in dynamic default procs for fg and bg)
  2462. */
  2463. if (G_Foreground (g) == M_Foreground (current) &&
  2464. M_Foreground (current) != M_Foreground (new))
  2465. {
  2466. local_cache.foreground = M_Foreground (new);
  2467. update = True;
  2468. }
  2469. if (G_Background (g) == M_Background (current) &&
  2470. M_Background (current) != M_Background (new))
  2471. {
  2472. local_cache.background = M_Background (new);
  2473. update = True;
  2474. }
  2475. if (G_PixmapForeground (g) == M_Foreground (current) &&
  2476. M_Foreground (current) != M_Foreground (new))
  2477. {
  2478. G_PixmapForeground(g) = M_Foreground (new);
  2479. update = True;
  2480. }
  2481. if (G_PixmapBackground (g) == M_Background (current) &&
  2482. M_Background (current) != M_Background (new))
  2483. {
  2484. G_PixmapBackground(g) = M_Background (new);
  2485. update = True;
  2486. }
  2487. if (update)
  2488. {
  2489. ReCacheIcon_r(&local_cache, g);
  2490. _DtProcessLock();
  2491. update_gcs = C_UpdateGCs(XtClass(g));
  2492. _DtProcessUnlock();
  2493. (*update_gcs) (g);
  2494. if (G_ImageName (g) != NULL)
  2495. {
  2496. if (G_Mask(g) != XmUNSPECIFIED_PIXMAP)
  2497. XmDestroyPixmap (XtScreen(g),G_Mask(g));
  2498. XmDestroyPixmap (XtScreen(w),G_Pixmap (g));
  2499. G_Pixmap (g) =
  2500. XmGetPixmap (XtScreen (g), G_ImageName (g),
  2501. G_PixmapForeground (g),
  2502. G_PixmapBackground (g));
  2503. if (G_Pixmap (g) != XmUNSPECIFIED_PIXMAP)
  2504. G_Mask(g) = (Pixmap)_DtGetMask(XtScreen(g), G_ImageName(g));
  2505. return (True);
  2506. }
  2507. else
  2508. return (False);
  2509. }
  2510. return (False);
  2511. }
  2512. /*-------------------------------------------------------------
  2513. ** Icon Procs
  2514. **-------------------------------------------------------------
  2515. */
  2516. /*-------------------------------------------------------------
  2517. ** GetSize
  2518. ** Compute size.
  2519. */
  2520. static void
  2521. GetSize(
  2522. DtIconGadget g,
  2523. Dimension *w,
  2524. Dimension *h )
  2525. {
  2526. Dimension s_t = G_ShadowThickness (g),
  2527. h_t = G_HighlightThickness (g),
  2528. p_w = G_PixmapWidth (g),
  2529. p_h = G_PixmapHeight (g),
  2530. m_w = G_MarginWidth (g),
  2531. m_h = G_MarginHeight (g),
  2532. s_w = G_StringWidth (g),
  2533. s_h = G_StringHeight (g),
  2534. v_pad = 2 * (s_t + h_t + m_h),
  2535. h_pad = 2 * (s_t + h_t + m_w),
  2536. spacing = G_Spacing (g);
  2537. if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
  2538. spacing = 0;
  2539. /* Get width and height.
  2540. */
  2541. switch ((int) G_PixmapPosition (g))
  2542. {
  2543. case XmPIXMAP_TOP:
  2544. case XmPIXMAP_BOTTOM:
  2545. *w = Max (p_w, s_w) + h_pad;
  2546. *h = p_h + s_h + v_pad + spacing;
  2547. break;
  2548. case XmPIXMAP_LEFT:
  2549. case XmPIXMAP_RIGHT:
  2550. *w = p_w + s_w + h_pad + spacing;
  2551. *h = Max (p_h, s_h) + v_pad;
  2552. break;
  2553. case XmPIXMAP_MIDDLE:
  2554. *w = Max (p_w, s_w) + h_pad;
  2555. *h = Max (p_h, s_h) + v_pad;
  2556. break;
  2557. default:
  2558. break;
  2559. }
  2560. }
  2561. /*-------------------------------------------------------------
  2562. ** GetPositions
  2563. ** Get positions of string and pixmap.
  2564. */
  2565. static void
  2566. GetPositions(
  2567. DtIconGadget g,
  2568. Position w,
  2569. Position h,
  2570. Dimension h_t,
  2571. Dimension s_t,
  2572. Position *pix_x,
  2573. Position *pix_y,
  2574. Position *str_x,
  2575. Position *str_y )
  2576. {
  2577. Dimension p_w = G_PixmapWidth (g),
  2578. p_h = G_PixmapHeight (g),
  2579. s_w = G_StringWidth (g),
  2580. s_h = G_StringHeight (g),
  2581. m_w = G_MarginWidth (g),
  2582. m_h = G_MarginHeight (g),
  2583. spacing = G_Spacing (g),
  2584. h_pad = s_t + h_t + m_w,
  2585. v_pad = s_t + h_t + m_h,
  2586. width = w - 2 * h_pad,
  2587. height = h - 2 * v_pad;
  2588. Position p_x = h_pad,
  2589. p_y = v_pad,
  2590. s_x = h_pad,
  2591. s_y = v_pad;
  2592. unsigned char align = G_Alignment (g);
  2593. if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
  2594. spacing = 0;
  2595. /* Set positions
  2596. */
  2597. switch ((int) G_PixmapPosition (g))
  2598. {
  2599. case XmPIXMAP_TOP:
  2600. if (align == XmALIGNMENT_CENTER)
  2601. {
  2602. if (p_w && width > p_w)
  2603. p_x += (width - p_w)/2U;
  2604. if (s_w && width > s_w)
  2605. s_x += (width - s_w)/2U;
  2606. }
  2607. else if (align == XmALIGNMENT_END)
  2608. {
  2609. if (p_w && width > p_w)
  2610. p_x += width - p_w;
  2611. if (s_w && width > s_w)
  2612. s_x += width - s_w;
  2613. }
  2614. if (p_h && ((unsigned)height > p_h + s_h + spacing))
  2615. p_y += (height - p_h - s_h - spacing)/2U;
  2616. if (p_h)
  2617. s_y = p_y + p_h + spacing;
  2618. else
  2619. s_y += (height - s_h)/2U;
  2620. break;
  2621. case XmPIXMAP_BOTTOM:
  2622. if (align == XmALIGNMENT_CENTER)
  2623. {
  2624. if (p_w && width > p_w)
  2625. p_x += (width - p_w)/2U;
  2626. if (s_w && width > s_w)
  2627. s_x += (width - s_w)/2U;
  2628. }
  2629. else if (align == XmALIGNMENT_END)
  2630. {
  2631. if (p_w && width > p_w)
  2632. p_x += width - p_w;
  2633. if (s_w && width > s_w)
  2634. s_x += width - s_w;
  2635. }
  2636. if (s_h && ((unsigned)height > p_h + s_h + spacing))
  2637. s_y += (height - p_h - s_h - spacing)/2U;
  2638. if (s_h)
  2639. p_y = s_y + s_h + spacing;
  2640. else
  2641. p_y += (height - s_h)/2U;
  2642. break;
  2643. case XmPIXMAP_LEFT:
  2644. if (p_h && height > p_h)
  2645. p_y += (height - p_h)/2U;
  2646. s_x += p_w + spacing;
  2647. if (s_h && height > s_h)
  2648. s_y += (height - s_h)/2U;
  2649. break;
  2650. case XmPIXMAP_RIGHT:
  2651. if (s_h && height > s_h)
  2652. s_y += (height - s_h)/2U;
  2653. p_x += s_w + spacing;
  2654. if (p_h && height > p_h)
  2655. p_y += (height - p_h)/2U;
  2656. break;
  2657. case XmPIXMAP_MIDDLE:
  2658. if (p_w && width > p_w)
  2659. p_x += (width - p_w)/2U;
  2660. if (s_w && width > s_w)
  2661. s_x += (width - s_w)/2U;
  2662. if (s_h && height > s_h)
  2663. s_y += (height - s_h)/2U;
  2664. if (p_h && height > p_h)
  2665. p_y += (height - p_h)/2U;
  2666. break;
  2667. default:
  2668. break;
  2669. }
  2670. *pix_x = p_x;
  2671. *pix_y = p_y;
  2672. *str_x = s_x;
  2673. *str_y = s_y;
  2674. }
  2675. /*-------------------------------------------------------------
  2676. ** Draw
  2677. ** Draw gadget to drawable.
  2678. */
  2679. /* ARGSUSED */
  2680. static void
  2681. Draw(
  2682. DtIconGadget g,
  2683. Drawable drawable,
  2684. Position x,
  2685. Position y,
  2686. Dimension w,
  2687. Dimension h,
  2688. Dimension h_t,
  2689. Dimension s_t,
  2690. unsigned char s_type,
  2691. unsigned char fill_mode )
  2692. {
  2693. XmManagerWidget mgr = (XmManagerWidget) XtParent (g);
  2694. Display * d = XtDisplay (g);
  2695. GC gc;
  2696. XRectangle clip;
  2697. Position p_x, p_y, s_x, s_y;
  2698. Dimension width, height;
  2699. unsigned char behavior = G_Behavior (g);
  2700. Position adj_x, adj_y;
  2701. int rec_width=0,begin=0,diff=0;
  2702. GetPositionProc get_positions;
  2703. /* Fill with icon or manager background or arm color.
  2704. */
  2705. if (G_SavedParentBG(g) != XtParent(g)->core.background_pixel) {
  2706. XtReleaseGC((Widget)mgr, G_ParentBackgroundGC(g));
  2707. GetParentBackgroundGC(g);
  2708. }
  2709. if (fill_mode == XmFILL_SELF)
  2710. {
  2711. if ((behavior == XmICON_BUTTON || behavior == XmICON_DRAG) &&
  2712. G_FillOnArm (g) && G_Armed (g))
  2713. gc = G_ArmedBackgroundGC (g);
  2714. else if (behavior == XmICON_TOGGLE && G_FillOnArm (g) &&
  2715. ((G_Armed (g) && !G_Set (g)) ||
  2716. (!G_Armed (g) && G_Set (g))))
  2717. gc = G_ArmedBackgroundGC (g);
  2718. else
  2719. gc = G_BackgroundGC (g);
  2720. }
  2721. else if (fill_mode == XmFILL_PARENT)
  2722. gc = G_ParentBackgroundGC (g);
  2723. if ((fill_mode != XmFILL_NONE) && (fill_mode != XmFILL_TRANSPARENT))
  2724. XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
  2725. w - 2 * h_t, h - 2 * h_t);
  2726. /* Get pixmap and string positions.
  2727. */
  2728. _DtProcessLock();
  2729. get_positions = C_GetPositions(XtClass(g));
  2730. _DtProcessUnlock();
  2731. (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
  2732. /* Copy pixmap.
  2733. */
  2734. if (G_Pixmap (g))
  2735. {
  2736. width = (p_x + s_t + h_t >= (unsigned)G_Width (g))
  2737. ? 0 : Min ((unsigned)G_PixmapWidth (g),
  2738. G_Width (g) - p_x - s_t - h_t);
  2739. height = (p_y + s_t + h_t >= (unsigned)G_Height (g))
  2740. ? 0 : Min ((unsigned)G_PixmapHeight (g),
  2741. G_Height (g) - p_y - s_t - h_t);
  2742. if (width > 0 && height > 0)
  2743. {
  2744. if (fill_mode == XmFILL_TRANSPARENT)
  2745. {
  2746. adj_x = s_t + h_t + G_MarginWidth(g);
  2747. adj_y = s_t + h_t + G_MarginHeight(g);
  2748. switch (G_PixmapPosition(g))
  2749. {
  2750. case XmPIXMAP_TOP:
  2751. case XmPIXMAP_BOTTOM:
  2752. XFillRectangle(d, drawable,
  2753. G_ParentBackgroundGC(g),
  2754. x + p_x - adj_x,
  2755. y + p_y - adj_y,
  2756. width + (2 * adj_y),
  2757. height + (2 * adj_x) -
  2758. (s_t + h_t));
  2759. break;
  2760. case XmPIXMAP_LEFT:
  2761. case XmPIXMAP_RIGHT:
  2762. XFillRectangle(d, drawable,
  2763. G_ParentBackgroundGC(g),
  2764. x + p_x - adj_x,
  2765. y + p_y - adj_y,
  2766. width + (2 * adj_y) -
  2767. (s_t + h_t),
  2768. height + (2 * adj_x));
  2769. break;
  2770. case XmPIXMAP_MIDDLE:
  2771. XFillRectangle(d, drawable,
  2772. G_ParentBackgroundGC(g),
  2773. x + p_x - adj_x,
  2774. y + p_y - adj_y,
  2775. width + (2 * adj_y),
  2776. height + (2 * adj_x));
  2777. break;
  2778. }
  2779. }
  2780. XCopyArea (d, G_Pixmap (g), drawable,
  2781. GetMaskGC(g, x + p_x, y + p_y),
  2782. 0, 0, width, height, x + p_x, y + p_y);
  2783. }
  2784. }
  2785. /* Draw string.
  2786. */
  2787. if ((behavior == XmICON_BUTTON || behavior == XmICON_DRAG) &&
  2788. G_FillOnArm (g) && G_Armed (g))
  2789. gc = G_ArmedGC (g);
  2790. else if (behavior == XmICON_TOGGLE && G_FillOnArm (g) &&
  2791. ((G_Armed (g) && !G_Set (g)) ||
  2792. (!G_Armed (g) && G_Set (g))))
  2793. gc = G_ArmedGC (g);
  2794. else
  2795. gc = G_NormalGC (g);
  2796. if (G_String (g))
  2797. {
  2798. clip.x = x + s_x;
  2799. clip.y = y + s_y;
  2800. switch (G_PixmapPosition(g))
  2801. {
  2802. case XmPIXMAP_TOP:
  2803. case XmPIXMAP_BOTTOM:
  2804. clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
  2805. ? 0 : Min ((unsigned)G_StringWidth (g),
  2806. G_Width (g) - s_x);
  2807. clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
  2808. ? 0 : Min ((unsigned)G_StringHeight (g),
  2809. G_Height (g) - s_y - s_t - h_t);
  2810. break;
  2811. case XmPIXMAP_LEFT:
  2812. case XmPIXMAP_RIGHT:
  2813. clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
  2814. ? 0 : Min ((unsigned)G_StringWidth (g),
  2815. G_Width (g) - s_x - s_t - h_t);
  2816. clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
  2817. ? 0 : Min ((unsigned)G_StringHeight (g),
  2818. G_Height (g) - s_y);
  2819. break;
  2820. case XmPIXMAP_MIDDLE:
  2821. clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
  2822. ? 0 : Min ((unsigned)G_StringWidth (g),
  2823. G_Width (g) - s_x);
  2824. clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
  2825. ? 0 : Min ((unsigned)G_StringHeight (g),
  2826. G_Height (g) - s_y);
  2827. break;
  2828. }
  2829. if (clip.width > 0 && clip.height > 0)
  2830. {
  2831. if (fill_mode == XmFILL_TRANSPARENT)
  2832. {
  2833. adj_x = s_t + h_t + G_MarginWidth(g);
  2834. adj_y = s_t + h_t + G_MarginHeight(g);
  2835. switch (G_PixmapPosition(g))
  2836. {
  2837. case XmPIXMAP_TOP:
  2838. case XmPIXMAP_BOTTOM:
  2839. XFillRectangle(d, drawable,
  2840. G_ParentBackgroundGC(g),
  2841. clip.x - adj_x,
  2842. clip.y - adj_y + s_t + h_t,
  2843. clip.width + (2 * adj_y),
  2844. clip.height + (2 * adj_x) -
  2845. (s_t + h_t));
  2846. break;
  2847. case XmPIXMAP_RIGHT:
  2848. case XmPIXMAP_LEFT:
  2849. begin = clip.x - adj_x + s_t + h_t;
  2850. rec_width = clip.width + (2 * adj_y)
  2851. -(s_t + h_t);
  2852. if (G_PixmapPosition(g) == XmPIXMAP_LEFT &&
  2853. begin > (int) (x + p_x) &&
  2854. begin < (int) (x + p_x + width))
  2855. {
  2856. /*
  2857. * XmPIXMAP_LEFT -- the rectangle starts
  2858. * inside the pixmap
  2859. */
  2860. diff = x+p_x+width - begin;
  2861. begin+=diff;
  2862. rec_width-=diff;
  2863. }
  2864. else if(G_PixmapPosition(g) == XmPIXMAP_RIGHT &&
  2865. (rec_width+begin) > (x+p_x))
  2866. {
  2867. /*
  2868. * PIXMAP_RIGHT -- rectangle drawn into
  2869. * the pixmap
  2870. */
  2871. diff = ( rec_width + begin) - (x+p_x);
  2872. rec_width-=diff;
  2873. }
  2874. XFillRectangle(d, drawable,
  2875. G_ParentBackgroundGC(g),
  2876. begin,
  2877. clip.y - adj_y,
  2878. rec_width,
  2879. clip.height + (2 * adj_x));
  2880. break;
  2881. case XmPIXMAP_MIDDLE:
  2882. XFillRectangle(d, drawable,
  2883. G_ParentBackgroundGC(g),
  2884. clip.x - adj_x,
  2885. clip.y - adj_y,
  2886. clip.width + (2 * adj_y),
  2887. clip.height + (2 * adj_x));
  2888. break;
  2889. }
  2890. }
  2891. XmStringDrawImage (d, drawable, G_FontList (g),
  2892. G_String (g), gc, x + s_x, y + s_y,
  2893. clip.width, XmALIGNMENT_BEGINNING,
  2894. XmSTRING_DIRECTION_L_TO_R, &clip);
  2895. if (G_Underline(g))
  2896. {
  2897. XmStringDrawUnderline (d, drawable, G_FontList (g),
  2898. G_String (g), gc, x + s_x, y + s_y,
  2899. clip.width, XmALIGNMENT_BEGINNING,
  2900. XmSTRING_DIRECTION_L_TO_R, &clip,
  2901. G_String(g));
  2902. }
  2903. }
  2904. }
  2905. /* Potentially fill the area between the label and the pixmap */
  2906. if ((fill_mode == XmFILL_TRANSPARENT) && G_Pixmap(g) && G_String(g) &&
  2907. (height > 0) && (width > 0) && (clip.width > 0) && (clip.height > 0))
  2908. {
  2909. switch (G_PixmapPosition(g))
  2910. {
  2911. case XmPIXMAP_TOP:
  2912. XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
  2913. x + Max(s_x, p_x), y + p_y + height,
  2914. Min(clip.width, width),
  2915. s_y - (p_y + height));
  2916. break;
  2917. case XmPIXMAP_BOTTOM:
  2918. XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
  2919. x + Max(s_x, p_x), y + s_y + clip.height,
  2920. Min(clip.width, width),
  2921. p_y - (s_y + clip.height));
  2922. break;
  2923. case XmPIXMAP_RIGHT:
  2924. XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
  2925. x + s_x + clip.width, y + Max(s_y, p_y),
  2926. p_x - (s_x + clip.width),
  2927. Min(clip.height, height));
  2928. break;
  2929. case XmPIXMAP_LEFT:
  2930. XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
  2931. x + p_x + width, y + Max(s_y, p_y),
  2932. s_x - (p_x + width),
  2933. Min(clip.height, height));
  2934. break;
  2935. case XmPIXMAP_MIDDLE:
  2936. XFillRectangle(d, drawable, G_ParentBackgroundGC(g),
  2937. x + Max(s_x, p_x), y + Max(s_y, p_y),
  2938. Min(clip.width, width),
  2939. Min(clip.height, height));
  2940. break;
  2941. }
  2942. }
  2943. /* Draw shadow.
  2944. */
  2945. if (G_ShadowThickness (g) > 0 && G_DrawShadow(g))
  2946. if(G_BorderType(g) == DtRECTANGLE || !G_Pixmap(g))
  2947. {
  2948. unsigned char shadow_type;
  2949. if (((G_Behavior (g) == XmICON_BUTTON) && G_Armed (g)) ||
  2950. ((G_Behavior (g) == XmICON_TOGGLE) &&
  2951. ((!G_Set (g) && G_Armed (g)) ||
  2952. (G_Set (g) && !G_Armed (g)))))
  2953. shadow_type = XmSHADOW_IN;
  2954. else
  2955. shadow_type = XmSHADOW_OUT;
  2956. XmeDrawShadows(d, drawable,
  2957. M_TopShadowGC(MgrParent(g)),
  2958. M_BottomShadowGC(MgrParent(g)),
  2959. x + h_t, y + h_t, w - 2*h_t, h - 2*h_t,
  2960. s_t, shadow_type);
  2961. }
  2962. else
  2963. {
  2964. CallCallbackProc call_callback;
  2965. _DtProcessLock();
  2966. call_callback = C_CallCallback(XtClass(g));
  2967. _DtProcessUnlock();
  2968. (*call_callback) (g, G_Callback (g), XmCR_SHADOW, NULL);
  2969. }
  2970. }
  2971. /*-------------------------------------------------------------
  2972. ** CallCallback
  2973. ** Call callback, if any, with reason and event.
  2974. */
  2975. static void
  2976. CallCallback(
  2977. DtIconGadget g,
  2978. XtCallbackList cb,
  2979. int reason,
  2980. XEvent *event )
  2981. {
  2982. DtIconCallbackStruct cb_data;
  2983. if (cb != NULL)
  2984. {
  2985. cb_data.reason = reason;
  2986. cb_data.event = event;
  2987. cb_data.set = G_Set (g);
  2988. XtCallCallbackList ((Widget) g, cb, &cb_data);
  2989. }
  2990. }
  2991. /*-------------------------------------------------------------
  2992. ** UpdateGCs
  2993. ** Get normal and background graphics contexts.
  2994. ** Use standard mask to maximize caching opportunities.
  2995. */
  2996. static void
  2997. UpdateGCs(
  2998. DtIconGadget g )
  2999. {
  3000. XGCValues values;
  3001. XtGCMask value_mask;
  3002. XmManagerWidget mw = (XmManagerWidget) XtParent(g);
  3003. XFontStruct * font;
  3004. if (G_NormalGC (g))
  3005. XtReleaseGC ((Widget)mw, G_NormalGC (g));
  3006. if (G_ClipGC (g))
  3007. XtReleaseGC ((Widget)mw, G_ClipGC (g));
  3008. if (G_BackgroundGC (g))
  3009. XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
  3010. if (G_ArmedGC (g))
  3011. XtReleaseGC ((Widget)mw, G_ArmedGC (g));
  3012. if (G_ArmedBackgroundGC (g))
  3013. XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
  3014. /* Get normal GC.
  3015. */
  3016. value_mask = GCForeground | GCBackground | GCFillStyle;
  3017. values.foreground = G_Foreground (g);
  3018. values.background = G_Background (g);
  3019. values.fill_style = FillSolid;
  3020. if (XmeRenderTableGetDefaultFont(G_FontList (g), &font)) {
  3021. value_mask |= GCFont;
  3022. values.font = font->fid;
  3023. }
  3024. G_NormalGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  3025. /* Get background GC.
  3026. */
  3027. values.foreground = G_Background (g);
  3028. values.background = G_Foreground (g);
  3029. G_BackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  3030. /* Get armed GC.
  3031. */
  3032. values.foreground = G_Foreground (g);
  3033. values.background = G_ArmColor (g);
  3034. G_ArmedGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  3035. /* Get armed background GC.
  3036. */
  3037. values.foreground = G_ArmColor (g);
  3038. values.background = G_Background (g);
  3039. G_ArmedBackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  3040. if (G_Mask(g) != XmUNSPECIFIED_PIXMAP) {
  3041. value_mask |= GCClipMask;
  3042. values.clip_mask = G_Mask(g);
  3043. values.foreground = G_Foreground (g);
  3044. values.background = G_Background (g);
  3045. G_ClipGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  3046. }
  3047. else
  3048. G_ClipGC (g) = NULL;
  3049. }
  3050. /*-------------------------------------------------------------
  3051. ** GetIconClassSecResData ( )
  3052. ** Class function to be called to copy secondary resource
  3053. ** for external use. i.e. copy the cached resources and
  3054. ** send it back.
  3055. **-------------------------------------------------------------
  3056. */
  3057. /* ARGSUSED */
  3058. static Cardinal
  3059. GetIconClassSecResData(
  3060. WidgetClass class,
  3061. XmSecondaryResourceData **data_rtn )
  3062. { int arrayCount = 0;
  3063. XmBaseClassExt bcePtr;
  3064. String resource_class, resource_name;
  3065. XtPointer client_data;
  3066. _DtProcessLock();
  3067. bcePtr = &( iconBaseClassExtRec);
  3068. client_data = NULL;
  3069. resource_class = NULL;
  3070. resource_name = NULL;
  3071. arrayCount =
  3072. _XmSecondaryResourceData ( bcePtr, data_rtn, client_data,
  3073. resource_name, resource_class,
  3074. (XmResourceBaseProc) (GetIconClassResBase));
  3075. _DtProcessUnlock();
  3076. return (arrayCount);
  3077. }
  3078. /*-------------------------------------------------------------
  3079. ** GetIconClassResBase ()
  3080. ** return the address of the base of resources.
  3081. ** - Not yet implemented.
  3082. **-------------------------------------------------------------
  3083. */
  3084. /* ARGSUSED */
  3085. static XtPointer
  3086. GetIconClassResBase(
  3087. Widget widget,
  3088. XtPointer client_data )
  3089. { XtPointer widgetSecdataPtr;
  3090. int icon_cache_size = sizeof (DtIconCacheObjPart);
  3091. char *cp;
  3092. widgetSecdataPtr = (XtPointer) (XtMalloc ( icon_cache_size +1));
  3093. if (widgetSecdataPtr)
  3094. {
  3095. cp = (char *) widgetSecdataPtr;
  3096. #ifndef SVR4
  3097. bcopy ( (char *) ( Icon_Cache(widget)), (char *) cp, icon_cache_size);
  3098. #else
  3099. memmove ( (char *)cp , (char *) ( Icon_Cache(widget)), icon_cache_size);
  3100. #endif
  3101. }
  3102. return (widgetSecdataPtr);
  3103. }
  3104. /*-------------------------------------------------------------
  3105. ** Public Entry Points
  3106. **-------------------------------------------------------------
  3107. */
  3108. /*-------------------------------------------------------------
  3109. ** _DtCreateIcon
  3110. ** Create a new gadget instance.
  3111. **-------------------------------------------------------------
  3112. */
  3113. Widget
  3114. _DtCreateIcon(
  3115. Widget parent,
  3116. String name,
  3117. ArgList arglist,
  3118. Cardinal argcount )
  3119. {
  3120. return (XtCreateWidget (name, dtIconGadgetClass,
  3121. parent, arglist, argcount));
  3122. }
  3123. /*-------------------------------------------------------------
  3124. ** _DtIconGetState
  3125. ** Return state of Icon.
  3126. **-------------------------------------------------------------
  3127. */
  3128. Boolean
  3129. _DtIconGetState(
  3130. Widget w )
  3131. {
  3132. DtIconGadget g = (DtIconGadget) w;
  3133. return (G_Set (g));
  3134. }
  3135. /*-------------------------------------------------------------
  3136. ** _DtIconSetState
  3137. ** Set state of Icon.
  3138. **-------------------------------------------------------------
  3139. */
  3140. void
  3141. _DtIconSetState(
  3142. Widget w,
  3143. Boolean state,
  3144. Boolean notify )
  3145. {
  3146. DtIconGadget g = (DtIconGadget) w;
  3147. CallCallbackProc call_callback;
  3148. XtExposeProc expose;
  3149. if (G_Behavior (g) != XmICON_TOGGLE || state == G_Set (g))
  3150. return;
  3151. _DtProcessLock();
  3152. call_callback = C_CallCallback(XtClass(g));
  3153. expose = XtCoreProc(w, expose);
  3154. _DtProcessUnlock();
  3155. G_Set (g) = state;
  3156. (*expose) ((Widget)g, NULL, NULL);
  3157. if (notify)
  3158. {
  3159. (*call_callback) (g, G_Callback (g), XmCR_VALUE_CHANGED, NULL);
  3160. }
  3161. }
  3162. /*-------------------------------------------------------------
  3163. ** _DtIconDraw
  3164. ** Render gadget to drawable without highlight.
  3165. **-------------------------------------------------------------
  3166. */
  3167. Drawable
  3168. _DtIconDraw(
  3169. Widget widget,
  3170. Drawable drawable,
  3171. Position x,
  3172. Position y,
  3173. Boolean fill )
  3174. {
  3175. DtIconGadget g = (DtIconGadget) widget;
  3176. Dimension h_t = G_HighlightThickness (g),
  3177. w = G_Width (g) - 2 * h_t,
  3178. h = G_Height (g) - 2 * h_t;
  3179. unsigned char fill_mode;
  3180. DrawProc draw;
  3181. if (!drawable || drawable == XmUNSPECIFIED_PIXMAP)
  3182. drawable = (Drawable)
  3183. XCreatePixmap (XtDisplay (g),
  3184. RootWindowOfScreen (XtScreen (g)),
  3185. w, h, DefaultDepthOfScreen (XtScreen (g)));
  3186. fill_mode = (fill) ? XmFILL_SELF : XmFILL_PARENT;
  3187. _DtProcessLock();
  3188. draw = C_Draw(XtClass(g));
  3189. _DtProcessUnlock();
  3190. (*draw) (g, drawable, x, y, w, h,
  3191. 0, G_ShadowThickness (g), G_ShadowType (g), fill_mode);
  3192. return (drawable);
  3193. }
  3194. /***************************************************************************/
  3195. /*
  3196. * Load the specified pixmap.
  3197. */
  3198. static Boolean
  3199. LoadPixmap(
  3200. DtIconGadget new,
  3201. String pixmap )
  3202. {
  3203. unsigned int int_h, int_w;
  3204. Screen *s = XtScreen(new);
  3205. Pixmap pm = XmGetPixmap(s, pixmap, G_PixmapForeground(new),
  3206. G_PixmapBackground(new));
  3207. Pixmap mask;
  3208. if (pm == XmUNSPECIFIED_PIXMAP)
  3209. return(True);
  3210. mask = XmeGetMask(s, pixmap);
  3211. G_Pixmap(new) = pm;
  3212. G_Mask(new) = mask;
  3213. G_ImageName(new) = XtNewString(pixmap);
  3214. XmeGetPixmapData(s, pm, NULL, NULL, NULL, NULL, NULL, NULL, &int_w, &int_h);
  3215. G_PixmapWidth(new) = Limit((Dimension)int_w, G_MaxPixmapWidth(new));
  3216. G_PixmapHeight(new) = Limit((Dimension)int_h, G_MaxPixmapWidth(new));
  3217. return(False);
  3218. }
  3219. Widget
  3220. _DtDuplicateIcon(
  3221. Widget parent,
  3222. Widget widget,
  3223. XmString string,
  3224. String pixmap,
  3225. XtPointer user_data,
  3226. Boolean underline )
  3227. {
  3228. DtIconGadget gadget;
  3229. int size;
  3230. DtIconGadget new;
  3231. Dimension h, w;
  3232. DtIconCacheObjPart local_cache;
  3233. XtWidgetProc insert_child;
  3234. GetSizeProc get_size;
  3235. /* Create the new instance structure */
  3236. gadget = (DtIconGadget) widget;
  3237. _DtProcessLock();
  3238. size = XtClass(gadget)->core_class.widget_size;
  3239. _DtProcessUnlock();
  3240. new = (DtIconGadget)XtMalloc(size);
  3241. /* Copy the master into the duplicate */
  3242. #ifndef SVR4
  3243. bcopy((char *)gadget, (char *)new, (int)size);
  3244. #else
  3245. memmove((char *)new, (char *)gadget, (int)size);
  3246. #endif
  3247. _DtProcessLock();
  3248. insert_child =
  3249. ((CompositeWidgetClass)XtClass(parent))->composite_class.insert_child;
  3250. get_size = C_GetSize(XtClass(new));
  3251. Icon_Cache(new) = (DtIconCacheObjPart *)
  3252. _XmCachePart(Icon_ClassCachePart(new),
  3253. (XtPointer) Icon_Cache(new),
  3254. sizeof(DtIconCacheObjPart));
  3255. _DtProcessUnlock();
  3256. /* Certain fields need to be updated */
  3257. new->object.parent = parent;
  3258. new->object.self = (Widget)new;
  3259. G_FontList(new) = XmFontListCopy(G_FontList(gadget));
  3260. /* Certain fields should not be inherited by the clone */
  3261. new->object.destroy_callbacks = NULL;
  3262. new->object.constraints = NULL;
  3263. new->gadget.help_callback = NULL;
  3264. new->icon.drop_callback = NULL;
  3265. new->rectangle.managed = False;
  3266. G_Callback(new) = NULL;
  3267. /* Set the user_data field */
  3268. new->gadget.user_data = user_data;
  3269. /* Process the optional pixmap name */
  3270. if ((pixmap == NULL) || LoadPixmap(new, pixmap))
  3271. {
  3272. /* No pixmap to load */
  3273. G_ImageName(new) = NULL;
  3274. G_Pixmap(new) = None;
  3275. G_PixmapWidth(new) = 0;
  3276. G_PixmapHeight(new) = 0;
  3277. }
  3278. /* Process the required label string */
  3279. G_String(new) = XmStringCopy(string);
  3280. XmStringExtent(G_FontList(new), G_String(new), &w, &h);
  3281. G_Underline(new) = underline;
  3282. if (G_Underline(new))
  3283. h++;
  3284. G_StringWidth(new) = w;
  3285. QualifyIconLocalCache(new, &local_cache);
  3286. local_cache.string_height = h;
  3287. ReCacheIcon_r(&local_cache, new);
  3288. /* Get copies of the GC's */
  3289. G_NormalGC(new) = NULL;
  3290. G_BackgroundGC(new) = NULL;
  3291. G_ArmedGC(new) = NULL;
  3292. G_ArmedBackgroundGC(new) = NULL;
  3293. G_ClipGC(new) = NULL;
  3294. UpdateGCs(new);
  3295. /* Size the gadget */
  3296. (*get_size) (new, &w, &h);
  3297. G_Width(new) = w;
  3298. G_Height(new) = h;
  3299. /* Insert the duplicate into the parent's child list */
  3300. (*insert_child) ((Widget)new);
  3301. return ((Widget) new);
  3302. }
  3303. Boolean
  3304. _DtIconSelectInTitle(
  3305. Widget widget,
  3306. Position pt_x,
  3307. Position pt_y )
  3308. {
  3309. DtIconGadget g = (DtIconGadget) widget;
  3310. Position x, y;
  3311. Dimension w, h, h_t, s_t;
  3312. XRectangle clip;
  3313. Position p_x, p_y, s_x, s_y;
  3314. GetPositionProc get_positions;
  3315. h_t = 0;
  3316. s_t = G_ShadowThickness(g);
  3317. x = G_X(g);
  3318. y = G_Y(g);
  3319. w = G_Width (g);
  3320. h = G_Height (g);
  3321. _DtProcessLock();
  3322. get_positions = C_GetPositions(XtClass(g));
  3323. _DtProcessUnlock();
  3324. (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
  3325. if (G_String (g))
  3326. {
  3327. clip.x = x + s_x;
  3328. clip.y = y + s_y;
  3329. clip.width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
  3330. ? 0 : Min ((unsigned)G_StringWidth (g),
  3331. G_Width (g) - s_x - s_t - h_t);
  3332. clip.height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
  3333. ? 0 : Min ((unsigned)G_StringHeight (g),
  3334. G_Height (g) - s_y - s_t - h_t);
  3335. if (clip.width <= 0 || clip.height <= 0)
  3336. return(False);
  3337. else
  3338. {
  3339. if ((pt_x >= clip.x) &&
  3340. (pt_y >= clip.y) &&
  3341. ((unsigned)pt_x <= clip.x + clip.width) &&
  3342. ((unsigned)pt_y <= clip.y + clip.height))
  3343. return(True);
  3344. else
  3345. return(False);
  3346. }
  3347. }
  3348. else
  3349. return(False);
  3350. }
  3351. /*
  3352. * Thread-safe variant of _DtIconGetTextExtent.
  3353. */
  3354. void
  3355. _DtIconGetTextExtent_r(Widget widget,
  3356. XRectangle *clip)
  3357. {
  3358. DtIconGadget g = (DtIconGadget) widget;
  3359. Position x, y;
  3360. Dimension w, h, h_t, s_t;
  3361. Position p_x, p_y, s_x, s_y;
  3362. GetPositionProc get_positions;
  3363. h_t = 0;
  3364. s_t = G_ShadowThickness(g);
  3365. x = G_X(g);
  3366. y = G_Y(g);
  3367. w = G_Width (g);
  3368. h = G_Height (g);
  3369. _DtProcessLock();
  3370. get_positions = C_GetPositions(XtClass(g));
  3371. _DtProcessUnlock();
  3372. (*get_positions) (g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
  3373. if (G_String (g))
  3374. {
  3375. clip->x = x + s_x;
  3376. clip->y = y + s_y;
  3377. clip->width = (s_x + s_t + h_t >= (unsigned)G_Width (g))
  3378. ? 0 : Min ((unsigned)G_StringWidth (g),
  3379. G_Width (g) - s_x - s_t - h_t);
  3380. clip->height = (s_y + s_t + h_t >= (unsigned)G_Height (g))
  3381. ? 0 : Min ((unsigned)G_StringHeight (g),
  3382. G_Height (g) - s_y - s_t - h_t);
  3383. if (clip->width <= 0)
  3384. clip->width = 0;
  3385. if (clip->height <= 0)
  3386. clip->height = 0;
  3387. }
  3388. else
  3389. {
  3390. clip->x = 0;
  3391. clip->y = 0;
  3392. clip->height = 0;
  3393. clip->width = 0;
  3394. }
  3395. }
  3396. /*
  3397. * Returns a pointer to a static storage area; must not be freed.
  3398. * This interface is deprecated in favor of _DtIconGetTextExtent_r.
  3399. */
  3400. XRectangle *
  3401. _DtIconGetTextExtent(
  3402. Widget widget )
  3403. {
  3404. static XRectangle clip;
  3405. _DtIconGetTextExtent_r(widget, &clip);
  3406. return(&clip);
  3407. }
  3408. /*-------------------------------------------------------------
  3409. ** _DtIconGetIconRects
  3410. ** Returns rects occupied by label and pixmap
  3411. */
  3412. void
  3413. _DtIconGetIconRects(
  3414. DtIconGadget g,
  3415. unsigned char *flags,
  3416. XRectangle *rect1,
  3417. XRectangle *rect2 )
  3418. {
  3419. Position p_x, p_y, s_x, s_y;
  3420. Dimension width, height;
  3421. Position adj_x, adj_y;
  3422. Dimension h_t, s_t;
  3423. GetPositionProc get_positions;
  3424. h_t = G_HighlightThickness(g);
  3425. s_t = G_ShadowThickness(g);
  3426. adj_x = G_MarginWidth(g);
  3427. adj_y = G_MarginHeight(g);
  3428. _DtProcessLock();
  3429. get_positions = C_GetPositions(XtClass(g));
  3430. _DtProcessUnlock();
  3431. (*get_positions) (g, G_Width(g), G_Height(g), h_t, s_t, &p_x, &p_y, &s_x, &s_y);
  3432. *flags = 0;
  3433. if (G_Pixmap (g))
  3434. {
  3435. width = (p_x + s_t + h_t >= (unsigned)G_Width (g)) ? 0 :
  3436. Min ((unsigned)G_PixmapWidth (g),
  3437. G_Width (g) - p_x - s_t - h_t);
  3438. height = (p_y + s_t + h_t >= (unsigned)G_Height (g)) ? 0 :
  3439. Min ((unsigned)G_PixmapHeight (g),
  3440. G_Height (g) - p_y - s_t - h_t);
  3441. if (width > 0 && height > 0)
  3442. {
  3443. rect1->x = G_X(g) + p_x - adj_x;
  3444. rect1->y = G_Y(g) + p_y - adj_y;
  3445. rect1->width = width + (2 * adj_y);
  3446. rect1->height = height + (2 * adj_x);
  3447. *flags |= XmPIXMAP_RECT;
  3448. }
  3449. }
  3450. if (G_String(g))
  3451. {
  3452. width = (s_x + s_t + h_t >= (unsigned)G_Width (g)) ? 0 :
  3453. Min ((unsigned)G_StringWidth (g), G_Width (g) - s_x - s_t - h_t);
  3454. height = (s_y + s_t + h_t >= (unsigned)G_Height (g)) ? 0 :
  3455. Min ((unsigned)G_StringHeight (g), G_Height (g) - s_y - s_t - h_t);
  3456. if (width > 0 && height > 0)
  3457. {
  3458. rect2->x = G_X(g) + s_x - adj_x;
  3459. rect2->y = G_Y(g) + s_y - adj_y;
  3460. rect2->width = width + (2 * adj_y);
  3461. rect2->height = height + (2 * adj_x);
  3462. *flags |= XmLABEL_RECT;
  3463. }
  3464. }
  3465. }
  3466. /* ARGSUSED */
  3467. /* Do animation when everything is completed.
  3468. * Note: DropDestroy callback is the only notification after the melt has
  3469. * been completed.
  3470. */
  3471. static void
  3472. AnimateCallback(
  3473. Widget w,
  3474. XtPointer clientData,
  3475. XtPointer callData )
  3476. {
  3477. DtIconGadget g = (DtIconGadget) w;
  3478. if (G_DropCallback(g)) {
  3479. XtCallCallbackList(w, G_DropCallback(g), callData);
  3480. }
  3481. }
  3482. /* ARGSUSED */
  3483. static void
  3484. TransferCallback(
  3485. Widget w,
  3486. XtPointer clientData,
  3487. XtPointer callData )
  3488. {
  3489. DtDndTransferCallback call_data = (DtDndTransferCallback) callData;
  3490. DtIconGadget g = (DtIconGadget) w;
  3491. call_data->x += G_X(g);
  3492. call_data->y += G_Y(g);
  3493. if (G_DropCallback(g)) {
  3494. XtCallCallbackList(w, G_DropCallback(g), callData);
  3495. }
  3496. }
  3497. /*-------------------------------------------------------------
  3498. ** _DtIconRegisterDropsite
  3499. ** Registers the Icon as a dropsite.
  3500. */
  3501. void
  3502. _DtIconRegisterDropsite(
  3503. Widget w)
  3504. {
  3505. XtCallbackRec transferCB[] = { {TransferCallback, NULL}, {NULL, NULL} };
  3506. XtCallbackRec animateCB[] = { {AnimateCallback, NULL}, {NULL, NULL} };
  3507. DtIconGadget g = (DtIconGadget) w;
  3508. XRectangle rects[2];
  3509. unsigned char flags;
  3510. int numRects = 0;
  3511. Arg args[5];
  3512. Cardinal n;
  3513. _DtIconGetIconRects(g, &flags, &rects[0], &rects[1]);
  3514. if (flags & XmPIXMAP_RECT) {
  3515. rects[0].x -= G_X(g);
  3516. rects[0].y -= G_Y(g);
  3517. numRects++;
  3518. }
  3519. if (flags & XmLABEL_RECT) {
  3520. rects[1].x -= G_X(g);
  3521. rects[1].y -= G_Y(g);
  3522. if (!numRects) rects[0] = rects[1];
  3523. numRects++;
  3524. }
  3525. n = 0;
  3526. if (numRects) {
  3527. XtSetArg(args[n], XmNdropRectangles, rects); n++;
  3528. XtSetArg(args[n], XmNnumDropRectangles, numRects); n++;
  3529. }
  3530. XtSetArg(args[n], XmNanimationStyle, XmDRAG_UNDER_SHADOW_IN); n++;
  3531. XtSetArg(args[n], DtNtextIsBuffer, True); n++;
  3532. XtSetArg(args[n], DtNdropAnimateCallback, animateCB); n++;
  3533. DtDndDropRegister(w, DtDND_FILENAME_TRANSFER|DtDND_BUFFER_TRANSFER,
  3534. G_Operations(g), transferCB,
  3535. args, n);
  3536. }