Icon.c 108 KB

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