Control.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  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: Control.c /main/18 1997/04/22 11:40:14 mgreess $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1992,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: Control.c
  36. ***
  37. *** project: MotifPlus Widgets
  38. ***
  39. *** description: Source code for DtControl class.
  40. ***
  41. ***-------------------------------------------------------------------*/
  42. /*-------------------------------------------------------------
  43. ** Include Files
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <sys/stat.h>
  48. #define X_INCLUDE_STRING_H
  49. #define X_INCLUDE_TIME_H
  50. #define XOS_USE_XT_LOCKING
  51. #include <X11/Xos_r.h>
  52. #include <Xm/GadgetP.h>
  53. #include <Xm/DrawP.h>
  54. #include <Xm/XmP.h>
  55. #include <Dt/Control.h>
  56. #include <Dt/ControlP.h>
  57. #include <Xm/ManagerP.h>
  58. #include <Dt/MacrosP.h>
  59. #include <langinfo.h>
  60. #include "DtWidgetI.h"
  61. #include "DtSvcInternal.h"
  62. /******** Public Function Declarations ********/
  63. extern Widget _DtCreateControl(
  64. Widget parent,
  65. String name,
  66. ArgList arglist,
  67. int argcount) ;
  68. /******** End Public Function Declarations ********/
  69. /******** Static Function Declarations ********/
  70. static void ClickTimeout(
  71. XtPointer client_data,
  72. XtIntervalId *id) ;
  73. static void BusyTimeout(
  74. XtPointer client_data,
  75. XtIntervalId *id) ;
  76. static void DateTimeout(
  77. XtPointer client_data,
  78. XtIntervalId *id) ;
  79. static void PushAnimationTimeout(
  80. XtPointer client_data,
  81. XtIntervalId *id) ;
  82. static void DropAnimationTimeout(
  83. XtPointer client_data,
  84. XtIntervalId *id) ;
  85. static void FileCheckTimeout(
  86. XtPointer client_data,
  87. XtIntervalId *id) ;
  88. static void CheckFile(
  89. DtControlGadget g) ;
  90. static void ClassInitialize( void ) ;
  91. static void ClassPartInitialize(
  92. WidgetClass cl) ;
  93. static void Destroy (Widget);
  94. static void Initialize(
  95. Widget request_w,
  96. Widget new_w) ;
  97. static Boolean SetValues(
  98. Widget current_w,
  99. Widget request_w,
  100. Widget new_w) ;
  101. static void GetSize(
  102. DtControlGadget g,
  103. Dimension *w,
  104. Dimension *h) ;
  105. static void GetPositions(
  106. DtControlGadget g,
  107. Position w,
  108. Position h,
  109. Dimension h_t,
  110. Dimension s_t,
  111. Position *pix_x,
  112. Position *pix_y,
  113. Position *str_x,
  114. Position *str_y) ;
  115. static void Draw(
  116. DtControlGadget g,
  117. Drawable drawable,
  118. Position x,
  119. Position y,
  120. Dimension w,
  121. Dimension h,
  122. Dimension h_t,
  123. Dimension s_t,
  124. unsigned char s_type,
  125. unsigned char fill_mode) ;
  126. static void CallCallback(
  127. DtControlGadget g,
  128. XtCallbackList cb,
  129. int reason,
  130. XEvent *event) ;
  131. static void UpdateGCs(
  132. DtControlGadget g) ;
  133. static void ReplaceJPDate(
  134. char *date,
  135. char *jpstr,
  136. int wday) ;
  137. /******** End Static Function Declarations ********/
  138. /*-------------------------------------------------------------
  139. ** Public Interface
  140. **-------------------------------------------------------------
  141. */
  142. WidgetClass dtControlGadgetClass;
  143. #define UNSPECIFIED_DIMENSION 9999
  144. #define UNSPECIFIED_CHAR 255
  145. static const char _DtMsgIndicator_0000[] = "/var/mail/";
  146. #define MAIL_DIR _DtMsgIndicator_0000
  147. #define Min(x, y) (((x) < (y)) ? (x) : (y))
  148. #define Max(x, y) (((x) > (y)) ? (x) : (y))
  149. #define G_Width(r) (r -> rectangle.width)
  150. #define G_Height(r) (r -> rectangle.height)
  151. /*-------------------------------------------------------------
  152. ** Resource List
  153. */
  154. #define R_Offset(field) \
  155. XtOffset (DtControlGadget, control.field)
  156. static XtResource resources[] =
  157. {
  158. {
  159. "_do_update",
  160. XmCBoolean, XmRBoolean, sizeof (Boolean),
  161. R_Offset (_do_update), XmRImmediate, (XtPointer) FALSE
  162. },
  163. {
  164. XmNuseEmbossedText,
  165. XmCBoolean, XmRBoolean, sizeof (Boolean),
  166. R_Offset (use_embossed_text), XmRImmediate, (XtPointer) TRUE
  167. },
  168. {
  169. XmNpushFunction,
  170. XmCPushFunction, XmRFunction, sizeof (XtPointer),
  171. R_Offset (push_function),
  172. XmRImmediate, (XtPointer) NULL
  173. },
  174. {
  175. XmNpushArgument,
  176. XmCPushArgument, XmRPointer, sizeof (XtPointer),
  177. R_Offset (push_argument),
  178. XmRImmediate, (XtPointer) NULL
  179. },
  180. {
  181. XmNdropAction,
  182. XmCDropAction, XmRString, sizeof (String),
  183. R_Offset (drop_action),
  184. XmRImmediate, (XtPointer) NULL
  185. },
  186. {
  187. "pushAction",
  188. "PushAction", XmRString, sizeof (String),
  189. R_Offset (push_action),
  190. XmRImmediate, (XtPointer) NULL
  191. },
  192. {
  193. XmNformat,
  194. XmCFormat, XmRString, sizeof (String),
  195. R_Offset (format),
  196. XmRImmediate, (XtPointer) "%b%n%e"
  197. },
  198. {
  199. XmNformatJP,
  200. XmCFormatJP, XmRString, sizeof (String),
  201. R_Offset (format_jp),
  202. XmRImmediate, (XtPointer) NULL
  203. },
  204. {
  205. XmNsubpanel,
  206. XmCSubpanel, XmRWidget, sizeof (Widget),
  207. R_Offset (subpanel),
  208. XmRImmediate, (XtPointer) NULL
  209. },
  210. {
  211. XmNcontrolType,
  212. XmCControlType, XmRControlType, sizeof (unsigned char),
  213. R_Offset (control_type),
  214. XmRImmediate, (XtPointer) XmCONTROL_NONE
  215. },
  216. {
  217. XmNfileName,
  218. XmCString, XmRString, sizeof (XmString),
  219. R_Offset (file_name), XmRImmediate, (XtPointer) NULL
  220. },
  221. {
  222. XmNalternateImage,
  223. XmCAlternateImage, XmRString, sizeof (String),
  224. R_Offset (alt_image), XmRImmediate, (XtPointer) NULL
  225. },
  226. {
  227. XmNchime,
  228. XmCBoolean, XmRBoolean, sizeof (Boolean),
  229. R_Offset (chime), XmRImmediate, (XtPointer) FALSE
  230. },
  231. {
  232. XmNclientTimeoutInterval,
  233. XmCInterval, XmRInt, sizeof (int),
  234. R_Offset (max_blink_time), XmRImmediate, (XtPointer) 10000
  235. },
  236. {
  237. XmNwaitingBlinkRate,
  238. XmCInterval, XmRInt, sizeof (int),
  239. R_Offset (blink_time), XmRImmediate, (XtPointer) 500
  240. },
  241. {
  242. XmNmonitorTime,
  243. XmCInterval, XmRInt, sizeof (int),
  244. R_Offset (monitor_time), XmRImmediate, (XtPointer) 30000
  245. },
  246. {
  247. XmNpushButtonClickTime,
  248. XmCInterval, XmRInt, sizeof (int),
  249. R_Offset (click_time),
  250. XmRImmediate, (XtPointer) 1000
  251. },
  252. {
  253. XmNuseLabelAdjustment,
  254. XmCBoolean, XmRBoolean, sizeof (Boolean),
  255. R_Offset (use_label_adj), XmRImmediate, (XtPointer) TRUE
  256. }
  257. };
  258. #undef R_Offset
  259. static XmBaseClassExtRec controlBaseClassExtRec = {
  260. NULL, /* Next extension */
  261. NULLQUARK, /* record type XmQmotif */
  262. XmBaseClassExtVersion, /* version */
  263. sizeof(XmBaseClassExtRec), /* size */
  264. XmInheritInitializePrehook, /* initialize prehook */
  265. XmInheritSetValuesPrehook, /* set_values prehook */
  266. XmInheritInitializePosthook, /* initialize posthook */
  267. XmInheritSetValuesPosthook, /* set_values posthook */
  268. (WidgetClass)&dtControlCacheObjClassRec, /* secondary class */
  269. XmInheritSecObjectCreate, /* creation proc */
  270. XmInheritGetSecResData, /* getSecResData */
  271. {0}, /* fast subclass */
  272. XmInheritGetValuesPrehook, /* get_values prehook */
  273. XmInheritGetValuesPosthook, /* get_values posthook */
  274. NULL, /* classPartInitPrehook */
  275. NULL, /* classPartInitPosthook*/
  276. NULL, /* ext_resources */
  277. NULL, /* compiled_ext_resources*/
  278. 0, /* num_ext_resources */
  279. FALSE, /* use_sub_resources */
  280. XmInheritWidgetNavigable, /* widgetNavigable */
  281. XmInheritFocusChange, /* focusChange */
  282. };
  283. /* ext rec static initialization */
  284. externaldef (xmcontrolcacheobjclassrec)
  285. DtControlCacheObjClassRec dtControlCacheObjClassRec =
  286. {
  287. {
  288. /* superclass */ (WidgetClass) &xmExtClassRec,
  289. /* class_name */ "DtControl",
  290. /* widget_size */ sizeof(DtControlCacheObjRec),
  291. /* class_initialize */ NULL,
  292. /* chained class init */ NULL,
  293. /* class_inited */ False,
  294. /* initialize */ NULL,
  295. /* initialize hook */ NULL,
  296. /* realize */ NULL,
  297. /* actions */ NULL,
  298. /* num_actions */ 0,
  299. /* resources */ NULL,
  300. /* num_resources */ 0,
  301. /* xrm_class */ NULLQUARK,
  302. /* compress_motion */ False,
  303. /* compress_exposure */ False,
  304. /* compress enter/exit*/ False,
  305. /* visible_interest */ False,
  306. /* destroy */ NULL,
  307. /* resize */ NULL,
  308. /* expose */ NULL,
  309. /* set_values */ NULL,
  310. /* set values hook */ NULL,
  311. /* set values almost */ NULL,
  312. /* get values hook */ NULL,
  313. /* accept_focus */ NULL,
  314. /* version */ XtVersion,
  315. /* callback offsetlst */ NULL,
  316. /* default trans */ NULL,
  317. /* query geo proc */ NULL,
  318. /* display accelerator*/ NULL,
  319. /* extension record */ (XtPointer)NULL,
  320. },
  321. {
  322. /* synthetic resources */ NULL,
  323. /* num_syn_resources */ 0,
  324. /* extension */ NULL,
  325. }
  326. };
  327. /*-------------------------------------------------------------
  328. ** Class Record
  329. */
  330. DtControlClassRec dtControlClassRec =
  331. {
  332. /* Core Part
  333. */
  334. {
  335. (WidgetClass) &dtIconClassRec, /* superclass */
  336. "Control", /* class_name */
  337. sizeof (DtControlRec), /* widget_size */
  338. ClassInitialize, /* class_initialize */
  339. ClassPartInitialize, /* class_part_initialize*/
  340. False, /* class_inited */
  341. (XtInitProc) Initialize, /* initialize */
  342. NULL, /* initialize_hook */
  343. NULL, /* realize */
  344. NULL, /* actions */
  345. 0, /* num_actions */
  346. resources, /* resources */
  347. XtNumber (resources), /* num_resources */
  348. NULLQUARK, /* xrm_class */
  349. True, /* compress_motion */
  350. True, /* compress_exposure */
  351. True, /* compress_enterleave */
  352. False, /* visible_interest */
  353. Destroy, /* destroy */
  354. XtInheritResize, /* resize */
  355. XtInheritExpose, /* expose */
  356. (XtSetValuesFunc)SetValues, /* set_values */
  357. NULL, /* set_values_hook */
  358. XtInheritSetValuesAlmost, /* set_values_almost */
  359. NULL, /* get_values_hook */
  360. NULL, /* accept_focus */
  361. XtVersion, /* version */
  362. NULL, /* callback private */
  363. NULL, /* tm_table */
  364. NULL, /* query_geometry */
  365. NULL, /* display_accelerator */
  366. (XtPointer)&controlBaseClassExtRec, /* extension */
  367. },
  368. /* XmGadget Part
  369. */
  370. {
  371. (XtWidgetProc) XmInheritBorderHighlight, /* border_highlight */
  372. (XtWidgetProc) XmInheritBorderUnhighlight, /* border_unhighlight */
  373. (XtActionProc) XmInheritArmAndActivate, /* arm_and_activate */
  374. (XmWidgetDispatchProc) XmInheritInputDispatch, /* input_dispatch */
  375. (XmVisualChangeProc) XmInheritVisualChange, /* visual_change */
  376. NULL, /* get_resources */
  377. 0, /* num_get_resources */
  378. XmInheritCachePart, /* class_cache_part */
  379. NULL, /* extension */
  380. },
  381. /* DtIcon Part
  382. */
  383. {
  384. (GetSizeProc) GetSize, /* get_size */
  385. (GetPositionProc) GetPositions, /* get_positions */
  386. (DrawProc) Draw, /* draw */
  387. (CallCallbackProc) CallCallback, /* call_callback */
  388. (UpdateGCsProc) UpdateGCs, /* update_gcs */
  389. True, /* optimize_redraw */
  390. NULL, /* class_cache_part */
  391. NULL, /* extension */
  392. },
  393. /* DtControl Part
  394. */
  395. {
  396. NULL, /* class_cache_part */
  397. NULL, /* extension */
  398. }
  399. };
  400. WidgetClass dtControlGadgetClass = (WidgetClass) &dtControlClassRec;
  401. /*-------------------------------------------------------------
  402. ** Private Functions
  403. **-------------------------------------------------------------
  404. */
  405. /*-------------------------------------------------------------
  406. ** FileCheckTimeout
  407. ** Check for change in file, reset timeout.
  408. ** An XtTimerCallbackProc.
  409. */
  410. static void
  411. FileCheckTimeout(
  412. XtPointer client_data,
  413. XtIntervalId *id )
  414. {
  415. DtControlGadget g = (DtControlGadget) client_data;
  416. XtAppContext app_context =
  417. XtWidgetToApplicationContext ((Widget) g);
  418. CheckFile (g);
  419. G_MonitorTimer (g) =
  420. XtAppAddTimeOut (app_context, G_MonitorTime (g),
  421. FileCheckTimeout, (XtPointer) g);
  422. }
  423. /*-------------------------------------------------------------
  424. ** CheckFile
  425. ** Check for change in file size
  426. */
  427. static void
  428. CheckFile(
  429. DtControlGadget g )
  430. {
  431. Boolean file_changed;
  432. long file_size = 0;
  433. struct stat stat_buf;
  434. if (stat (G_FileName (g), &stat_buf) == 0)
  435. {
  436. file_size = stat_buf.st_size;
  437. }
  438. switch (G_ControlType (g))
  439. {
  440. case XmCONTROL_MONITOR:
  441. file_changed = (file_size == 0) ? False : True;
  442. break;
  443. case XmCONTROL_MAIL:
  444. if (file_size == 0)
  445. file_changed = False;
  446. else if (stat_buf.st_atime > stat_buf.st_mtime)
  447. file_changed = False;
  448. else if (file_size == G_FileSize (g))
  449. file_changed = G_FileChanged (g);
  450. else if (file_size > G_FileSize (g))
  451. file_changed = True;
  452. else
  453. file_changed = False;
  454. break;
  455. default:
  456. /* unsupported control type */
  457. return;
  458. }
  459. G_FileSize (g) = file_size;
  460. if (file_changed != G_FileChanged (g))
  461. {
  462. XtExposeProc expose;
  463. CallCallbackProc call_callback;
  464. _DtProcessLock();
  465. expose = XtCoreProc((Widget)g, expose);
  466. call_callback = C_CallCallback(XtClass(g));
  467. _DtProcessUnlock();
  468. G_FileChanged (g) = file_changed;
  469. (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_MONITOR, NULL);
  470. (*expose)((Widget)g, NULL, NULL);
  471. XmUpdateDisplay ((Widget) g);
  472. }
  473. }
  474. /*-------------------------------------------------------------
  475. ** ClickTimeout
  476. ** An XtTimerCallbackProc.
  477. **
  478. */
  479. static void
  480. ClickTimeout(
  481. XtPointer client_data,
  482. XtIntervalId *id )
  483. {
  484. DtControlGadget g = (DtControlGadget) client_data;
  485. G_ClickTimer (g) = 0;
  486. }
  487. /*-------------------------------------------------------------
  488. ** BusyTimeout
  489. ** Switch pixmap.
  490. ** An XtTimerCallbackProc.
  491. */
  492. static void
  493. BusyTimeout(
  494. XtPointer client_data,
  495. XtIntervalId *id )
  496. {
  497. DtControlGadget g = (DtControlGadget) client_data;
  498. XtAppContext app_context = XtWidgetToApplicationContext((Widget) g);
  499. XtExposeProc expose;
  500. CallCallbackProc call_callback;
  501. _DtProcessLock();
  502. expose = XtCoreProc((Widget)g, expose);
  503. call_callback = C_CallCallback(XtClass((Widget)g));
  504. _DtProcessUnlock();
  505. if ((G_Busy (g) > 0) && (G_BlinkElapsed (g) < G_MaxBlinkTime (g)))
  506. {
  507. G_Set (g) = ! G_Set (g);
  508. G_BlinkTimer (g) =
  509. XtAppAddTimeOut (app_context, G_BlinkTime (g),
  510. BusyTimeout, (XtPointer) g);
  511. G_BlinkElapsed (g) += G_BlinkTime (g);
  512. }
  513. else
  514. {
  515. G_Set (g) = False;
  516. G_BlinkTimer (g) = 0;
  517. G_BlinkElapsed (g) = 0;
  518. G_Busy (g) = 0;
  519. (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_BUSY_STOP, NULL);
  520. }
  521. (*expose) ((Widget) g, NULL, False);
  522. }
  523. /*-------------------------------------------------------------
  524. ** DateTimeout
  525. ** Update date strings.
  526. ** An XtTimerCallbackProc.
  527. */
  528. static void
  529. DateTimeout(
  530. XtPointer client_data,
  531. XtIntervalId *id )
  532. {
  533. DtControlGadget g = (DtControlGadget) client_data;
  534. XtAppContext app_context =
  535. XtWidgetToApplicationContext ((Widget) g);
  536. char sTime[128];
  537. struct tm *timeptr;
  538. time_t tse;
  539. String s1, s2, s3;
  540. unsigned long tilMidnight;
  541. XtExposeProc expose;
  542. /* Get time string.
  543. */
  544. tse = time (NULL);
  545. timeptr = _XLocaltime(&tse, localtime_buf);
  546. strftime ((char*) sTime, 128, G_Format (g), timeptr);
  547. if (g->control.format_jp != NULL && strlen(g->control.format_jp) != 0)
  548. ReplaceJPDate(sTime, g->control.format_jp, timeptr->tm_wday);
  549. /* Break time string between date and day of week.
  550. */
  551. s1 = sTime;
  552. s2 = strchr (sTime, '\n');
  553. if (s2 == NULL)
  554. s3 = NULL;
  555. else
  556. {
  557. s3 = strchr (s2+1, '\n');
  558. if (s3 != NULL)
  559. {
  560. s2[0] = ' ';
  561. s2 = s3;
  562. }
  563. s2[0] = '\0';
  564. s2++;
  565. }
  566. /* Create date string.
  567. */
  568. if (s1 != NULL)
  569. {
  570. if (s2 == NULL)
  571. {
  572. XmStringFree(G_String(g));
  573. G_String (g) = XmStringCreate (s1, XmFONTLIST_DEFAULT_TAG);
  574. XmStringExtent (G_FontList (g), G_String (g),
  575. &(G_StringWidth (g)), &(G_StringHeight (g)));
  576. if (G_AltString (g) != NULL)
  577. {
  578. XmStringFree (G_AltString (g));
  579. G_AltString (g) = NULL;
  580. G_AltStringHeight (g) = 0;
  581. G_AltStringWidth (g) = 0;
  582. }
  583. }
  584. else
  585. {
  586. if (!G_UseLabelAdjustment (g))
  587. {
  588. /* swap s1 and s2 */
  589. s3 = s1;
  590. s1 = s2;
  591. s2 = s3;
  592. }
  593. if (G_AltString (g) != NULL)
  594. XmStringFree (G_AltString (g));
  595. G_AltString (g) = XmStringCreate (s1, XmFONTLIST_DEFAULT_TAG);
  596. XmStringExtent (G_FontList (g), G_AltString (g),
  597. &(G_AltStringWidth (g)), &(G_AltStringHeight (g)));
  598. XmStringFree(G_String(g));
  599. G_String (g) = XmStringCreate (s2, XmFONTLIST_DEFAULT_TAG);
  600. XmStringExtent (G_FontList (g), G_String (g),
  601. &(G_StringWidth (g)), &(G_StringHeight (g)));
  602. }
  603. }
  604. /* Update display.
  605. */
  606. _DtProcessLock();
  607. expose = XtCoreProc((Widget)g, expose);
  608. _DtProcessUnlock();
  609. (*expose) ((Widget) g, NULL, False);
  610. XmUpdateDisplay ((Widget) g);
  611. /* Compute milliseconds until midnight:
  612. * a. compute current time in seconds
  613. * b. subtract that from number of seconds in a day.
  614. * c. multiply by 1000 to get milliseconds.
  615. * Add timeout.
  616. */
  617. tilMidnight = 1000 * (86400 - ((3600 * timeptr->tm_hour) +
  618. (60 * timeptr->tm_min) +
  619. (timeptr->tm_sec)));
  620. if (G_Format (g) != NULL)
  621. {
  622. G_DateTimer (g) =
  623. XtAppAddTimeOut (app_context, tilMidnight,
  624. DateTimeout, (XtPointer) g);
  625. }
  626. else
  627. {
  628. G_DateTimer (g) = 0;
  629. }
  630. }
  631. /*-------------------------------------------------------------
  632. ** Action Procs
  633. **-------------------------------------------------------------
  634. */
  635. /*-------------------------------------------------------------
  636. ** Core Procs
  637. **-------------------------------------------------------------
  638. */
  639. /*-------------------------------------------------------------
  640. ** ClassInitialize
  641. */
  642. static void
  643. ClassInitialize( void )
  644. {
  645. controlBaseClassExtRec.record_type = XmQmotif;
  646. }
  647. /*-------------------------------------------------------------
  648. ** ClassPartInitialize
  649. */
  650. static void
  651. ClassPartInitialize(
  652. WidgetClass cl )
  653. {
  654. dtControlCacheObjClassRec.object_class.resources =
  655. dtIconCacheObjClassRec.object_class.resources;
  656. dtControlCacheObjClassRec.object_class.num_resources =
  657. dtIconCacheObjClassRec.object_class.num_resources;
  658. }
  659. /*-------------------------------------------------------------
  660. ** Initialize
  661. ** Initialize a new gadget instance.
  662. */
  663. static void
  664. Initialize(
  665. Widget request_w,
  666. Widget new_w )
  667. {
  668. DtControlGadget request = (DtControlGadget) request_w,
  669. new = (DtControlGadget) new_w;
  670. XtAppContext app_context =
  671. XtWidgetToApplicationContext (new_w);
  672. String str;
  673. UpdateGCsProc update_gcs;
  674. G_MonitorTimer (new) = 0;
  675. G_ClickTimer (new) = 0;
  676. G_DateTimer (new) = 0;
  677. G_BlinkTimer (new) = 0;
  678. G_PushAnimationTimer (new) = 0;
  679. G_DropAnimationTimer (new) = 0;
  680. G_FileSize (new) = 0;
  681. G_FileChanged (new) = False;
  682. G_Busy (new) = 0;
  683. G_AltString (new) = NULL;
  684. G_AltStringWidth (new) = 0;
  685. G_AltStringHeight (new) = 0;
  686. /* Initialize animation data.
  687. */
  688. G_NumPushImages (new) = 0;
  689. G_MaxPushImages (new) = 0;
  690. G_PushImagePosition (new) = 0;
  691. G_PushDelays (new) = NULL;
  692. G_PushPixmaps (new) = NULL;
  693. G_PushMasks (new) = NULL;
  694. G_NumDropImages (new) = 0;
  695. G_MaxDropImages (new) = 0;
  696. G_DropImagePosition (new) = 0;
  697. G_DropDelays (new) = NULL;
  698. G_DropPixmaps (new) = NULL;
  699. G_DropMasks (new) = NULL;
  700. /* Copy drop argument.
  701. */
  702. if (G_DropAction (new) != NULL)
  703. {
  704. String str = G_DropAction (new);
  705. G_DropAction (new) = XtMalloc (strlen (str) + 1);
  706. strcpy (G_DropAction (new), str);
  707. }
  708. if (G_PushAction (new) != NULL)
  709. {
  710. String str = G_PushAction (new);
  711. G_PushAction (new) = XtMalloc (strlen (str) + 1);
  712. strcpy (G_PushAction (new), str);
  713. }
  714. /* Validate control type.
  715. */
  716. if (G_ControlType (new) != XmCONTROL_NONE &&
  717. G_ControlType (new) != XmCONTROL_SWITCH &&
  718. G_ControlType (new) != XmCONTROL_BUTTON &&
  719. G_ControlType (new) != XmCONTROL_BLANK &&
  720. G_ControlType (new) != XmCONTROL_DATE &&
  721. G_ControlType (new) != XmCONTROL_BUSY &&
  722. G_ControlType (new) != XmCONTROL_CLIENT &&
  723. G_ControlType (new) != XmCONTROL_MAIL &&
  724. G_ControlType (new) != XmCONTROL_MONITOR)
  725. {
  726. G_ControlType (new) = XmCONTROL_NONE;
  727. }
  728. if (G_ControlType (new) == XmCONTROL_SWITCH)
  729. G_ShadowType (new) = (G_Set (new)) ? XmSHADOW_IN : XmSHADOW_OUT;
  730. if ( ((G_ControlType (new) == XmCONTROL_MONITOR) ||
  731. (G_ControlType (new) == XmCONTROL_MAIL) ||
  732. (G_ControlType (new) == XmCONTROL_BUSY)) &&
  733. (G_AltImage (new) != NULL))
  734. {
  735. /* Copy string or default to user mail directory.
  736. */
  737. if ((G_ControlType (new) == XmCONTROL_MONITOR) ||
  738. (G_ControlType (new) == XmCONTROL_MAIL))
  739. {
  740. if (G_FileName (new) == NULL)
  741. {
  742. if (G_ControlType (new) == XmCONTROL_MAIL)
  743. {
  744. if ((str = getenv ("MAIL")) == NULL)
  745. {
  746. str = getenv ("LOGNAME");
  747. G_FileName (new) =
  748. XtMalloc (strlen (MAIL_DIR) + strlen (str) + 1);
  749. strcpy (G_FileName (new), MAIL_DIR);
  750. strcat (G_FileName (new), str);
  751. }
  752. else
  753. {
  754. G_FileName (new) = XtMalloc (strlen (str) + 1);
  755. strcpy (G_FileName (new), str);
  756. }
  757. }
  758. }
  759. else
  760. {
  761. str = G_FileName (new);
  762. G_FileName (new) = XtMalloc (strlen (str) + 1);
  763. strcpy (G_FileName (new), str);
  764. }
  765. G_FileChanged (new) = False;
  766. }
  767. /* Get alternate pixmap and mask.
  768. */
  769. G_AltPix (new) =
  770. XmGetPixmap (XtScreen (new), G_AltImage (new),
  771. G_PixmapForeground (new),
  772. G_PixmapBackground (new));
  773. G_AltMask (new) =
  774. _DtGetMask (XtScreen (new), G_AltImage (new));
  775. G_AltImage (new) = NULL;
  776. if ((G_AltPix (new) != XmUNSPECIFIED_PIXMAP) &&
  777. ((G_ControlType (new) == XmCONTROL_MONITOR) ||
  778. (G_ControlType (new) == XmCONTROL_MAIL)))
  779. {
  780. CheckFile (new);
  781. G_MonitorTimer (new) =
  782. XtAppAddTimeOut (app_context, G_MonitorTime (new),
  783. FileCheckTimeout, (XtPointer) new);
  784. }
  785. /* Check for Control state change.
  786. */
  787. }
  788. else
  789. {
  790. G_AltPix (new) = XmUNSPECIFIED_PIXMAP;
  791. G_AltMask (new) = XmUNSPECIFIED_PIXMAP;
  792. G_MonitorTimer (new) = 0;
  793. G_FileName (new) = NULL;
  794. }
  795. if (G_ControlType (new) == XmCONTROL_DATE)
  796. {
  797. Dimension w, h;
  798. DateTimeout ((XtPointer) new_w, NULL);
  799. if (G_Width (request) == 0 || G_Height (request) == 0)
  800. {
  801. GetSizeProc get_size;
  802. _DtProcessLock();
  803. get_size = C_GetSize(XtClass(new));
  804. _DtProcessUnlock();
  805. (*get_size) ((DtIconGadget) new, &w, &h);
  806. if (G_Width (request) == 0)
  807. G_Width (new) = w;
  808. if (G_Height (request) == 0)
  809. G_Height (new) = h;
  810. }
  811. }
  812. G_ArmedGC (new) = NULL;
  813. G_TopShadowGC (new) = NULL;
  814. G_BottomShadowGC (new) = NULL;
  815. G__DoUpdate (new) = True;
  816. _DtProcessLock();
  817. update_gcs = C_UpdateGCs(XtClass(new));
  818. _DtProcessUnlock();
  819. (*update_gcs) ((DtIconGadget) new);
  820. G__DoUpdate (new) = False;
  821. }
  822. /*-------------------------------------------------------------
  823. ** Destroy
  824. ** Release resources allocated for gadget.
  825. */
  826. static void
  827. Destroy(
  828. Widget w )
  829. {
  830. DtControlGadget g = (DtControlGadget) w;
  831. if (G_FileName (g) != NULL)
  832. XtFree (G_FileName (g));
  833. if (G_NumPushImages (g) > 0)
  834. {
  835. XtFree ((char*) G_PushDelays (g));
  836. XtFree ((char*) G_PushPixmaps (g));
  837. XtFree ((char*) G_PushMasks (g));
  838. }
  839. if (G_NumDropImages (g) > 0)
  840. {
  841. XtFree ((char*) G_DropDelays (g));
  842. XtFree ((char*) G_DropPixmaps (g));
  843. XtFree ((char*) G_DropMasks (g));
  844. }
  845. if (G_DropAction (g) != NULL)
  846. XtFree (G_DropAction (g));
  847. if (G_PushAction (g) != NULL)
  848. XtFree (G_PushAction (g));
  849. if (G_AltString (g) != NULL)
  850. XmStringFree (G_AltString (g));
  851. if (G_ClickTimer (g))
  852. XtRemoveTimeOut (G_ClickTimer (g));
  853. if (G_BlinkTimer (g))
  854. XtRemoveTimeOut (G_BlinkTimer (g));
  855. if (G_MonitorTimer (g))
  856. XtRemoveTimeOut (G_MonitorTimer (g));
  857. if (G_DateTimer (g))
  858. XtRemoveTimeOut (G_DateTimer (g));
  859. if (G_PushAnimationTimer (g))
  860. XtRemoveTimeOut (G_PushAnimationTimer (g));
  861. if (G_DropAnimationTimer (g))
  862. XtRemoveTimeOut (G_DropAnimationTimer (g));
  863. }
  864. /*-------------------------------------------------------------
  865. ** SetValues
  866. **
  867. */
  868. static Boolean
  869. SetValues(
  870. Widget current_w,
  871. Widget request_w,
  872. Widget new_w )
  873. {
  874. DtControlGadget current_c = (DtControlGadget) current_w,
  875. new_c = (DtControlGadget) new_w;
  876. #if 0
  877. String file_name = G_FileName (new);
  878. int file_name_size;
  879. Boolean redraw_flag = False;
  880. #endif /* 0 */
  881. if (strcmp(G_Format(new_c),G_Format(current_c)) &&
  882. G_ControlType (new_c) == XmCONTROL_DATE)
  883. {
  884. if (G_DateTimer (new_c))
  885. XtRemoveTimeOut (G_DateTimer (new_c));
  886. if (G_Format(new_c) != NULL)
  887. DateTimeout ((XtPointer) new_w, NULL);
  888. }
  889. if (G_ImageName (new_c) && (G_ImageName (current_c) != G_ImageName (new_c)))
  890. return True;
  891. return False;
  892. #if 0
  893. /* Copy drop argument.
  894. */
  895. if (G_DropAction (new) != G_DropAction (current))
  896. {
  897. String str = G_DropAction (new);
  898. if (G_DropAction (current) != NULL)
  899. XtFree (G_DropAction (current));
  900. G_DropAction (new) = XtMalloc (strlen (str) + 1);
  901. strcpy (G_DropAction (new), str);
  902. }
  903. if (G_PushAction (new) != G_PushAction (current))
  904. {
  905. String str = G_PushAction (new);
  906. if (G_PushAction (current) != NULL)
  907. XtFree (G_PushAction (current));
  908. G_PushAction (new) = XtMalloc (strlen (str) + 1);
  909. strcpy (G_PushAction (new), str);
  910. }
  911. /* Copy string or default to user mail directory.
  912. */
  913. if ((G_ControlType (new) == XmCONTROL_MONITOR) ||
  914. (G_ControlType (new) == XmCONTROL_MAIL))
  915. {
  916. if (G_FileName (new) != G_FileName (current))
  917. {
  918. if (G_FileName (current) != NULL)
  919. XtFree (G_FileName (current));
  920. if (G_FileName (new) != NULL)
  921. {
  922. file_name_size = strlen (G_FileName (new));
  923. G_FileName (new) = XtMalloc (file_name_size);
  924. strcpy (G_FileName (new), file_name);
  925. }
  926. }
  927. }
  928. return (redraw_flag);
  929. #endif /* 0 */
  930. }
  931. /*-------------------------------------------------------------
  932. ** Gadget Procs
  933. **-------------------------------------------------------------
  934. */
  935. /*-------------------------------------------------------------
  936. ** Icon Procs
  937. **-------------------------------------------------------------
  938. */
  939. /*-------------------------------------------------------------
  940. ** GetSize
  941. ** Compute size.
  942. */
  943. static void
  944. GetSize(
  945. DtControlGadget g,
  946. Dimension *w,
  947. Dimension *h )
  948. {
  949. Dimension s_t = G_ShadowThickness (g);
  950. Dimension h_t = G_HighlightThickness (g);
  951. Dimension p_w = G_PixmapWidth (g);
  952. Dimension p_h = G_PixmapHeight (g);
  953. Dimension m_w = G_MarginWidth (g);
  954. Dimension m_h = G_MarginHeight (g);
  955. Dimension s_w = G_StringWidth (g);
  956. Dimension s_h = G_StringHeight (g);
  957. Dimension v_pad = 2 * (s_t + h_t + m_h);
  958. Dimension h_pad = 2 * (s_t + h_t + m_w);
  959. Dimension spacing = G_Spacing (g);
  960. if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
  961. spacing = 0;
  962. if (G_ControlType (g) == XmCONTROL_DATE)
  963. {
  964. /* Adjust size based on second date string.
  965. */
  966. if ( (G_StringWidth (g) > 0) &&
  967. (G_AltStringWidth (g) > G_StringWidth (g)) )
  968. s_w = G_AltStringWidth (g);
  969. if ( (G_StringWidth (g) > 0) && (G_AltStringWidth (g) > 0) )
  970. s_h += spacing + G_AltStringHeight (g);
  971. }
  972. else
  973. {
  974. /* Add left and right spacing for string.
  975. */
  976. if (s_w > 0)
  977. s_w += 4;
  978. }
  979. /* Get width and height.
  980. */
  981. switch ((int) G_PixmapPosition (g))
  982. {
  983. case XmPIXMAP_TOP:
  984. case XmPIXMAP_BOTTOM:
  985. *w = Max (p_w, s_w) + h_pad;
  986. *h = p_h + s_h + v_pad + spacing;
  987. break;
  988. case XmPIXMAP_LEFT:
  989. case XmPIXMAP_RIGHT:
  990. *w = p_w + s_w + h_pad + spacing;
  991. *h = Max (p_h, s_h) + v_pad;
  992. break;
  993. case XmPIXMAP_MIDDLE:
  994. *w = Max (p_w, s_w) + h_pad;
  995. *h = Max (p_h, s_h) + v_pad;
  996. break;
  997. }
  998. }
  999. /*-------------------------------------------------------------
  1000. ** GetPositions
  1001. ** Get positions of string and pixmap.
  1002. */
  1003. static void
  1004. GetPositions(
  1005. DtControlGadget g,
  1006. Position w,
  1007. Position h,
  1008. Dimension h_t,
  1009. Dimension s_t,
  1010. Position *pix_x,
  1011. Position *pix_y,
  1012. Position *str_x,
  1013. Position *str_y )
  1014. {
  1015. Dimension p_w = G_PixmapWidth (g),
  1016. p_h = G_PixmapHeight (g),
  1017. s_w = G_StringWidth (g),
  1018. s_h = G_StringHeight (g),
  1019. m_w = G_MarginWidth (g),
  1020. m_h = G_MarginHeight (g),
  1021. spacing = G_Spacing (g),
  1022. h_pad = s_t + h_t + m_w,
  1023. v_pad = s_t + h_t + m_h,
  1024. width = w - 2 * h_pad,
  1025. height = h - 2 * v_pad;
  1026. Position p_x = h_pad,
  1027. p_y = v_pad,
  1028. s_x = h_pad,
  1029. s_y = v_pad;
  1030. unsigned char align = G_Alignment (g);
  1031. if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
  1032. spacing = 0;
  1033. /* Set positions
  1034. */
  1035. switch ((int) G_PixmapPosition (g))
  1036. {
  1037. case XmPIXMAP_TOP:
  1038. if (align == XmALIGNMENT_CENTER)
  1039. {
  1040. if (p_w && width > p_w)
  1041. p_x += (width - p_w)/2U;
  1042. if (s_w && width > s_w)
  1043. s_x += (width - s_w)/2U;
  1044. }
  1045. else if (align == XmALIGNMENT_END)
  1046. {
  1047. if (p_w && width > p_w)
  1048. p_x += width - p_w;
  1049. if (s_w && width > s_w)
  1050. s_x += width - s_w;
  1051. }
  1052. if (p_h && ((unsigned)height > (p_h + s_h + spacing)))
  1053. p_y += (height - p_h - s_h - spacing)/2U;
  1054. if (p_h)
  1055. s_y = p_y + p_h + spacing;
  1056. else
  1057. s_y += (height - s_h)/2U;
  1058. break;
  1059. case XmPIXMAP_BOTTOM:
  1060. if (align == XmALIGNMENT_CENTER)
  1061. {
  1062. if (p_w && width > p_w)
  1063. p_x += (width - p_w)/2U;
  1064. if (s_w && width > s_w)
  1065. s_x += (width - s_w)/2U;
  1066. }
  1067. else if (align == XmALIGNMENT_END)
  1068. {
  1069. if (p_w && width > p_w)
  1070. p_x += width - p_w;
  1071. if (s_w && width > s_w)
  1072. s_x += width - s_w;
  1073. }
  1074. if (s_h && ((unsigned)height > (p_h + s_h + spacing)))
  1075. s_y += (height - p_h - s_h - spacing)/2U;
  1076. if (s_h)
  1077. p_y = s_y + s_h + spacing;
  1078. else
  1079. p_y += (height - p_h)/2U;
  1080. break;
  1081. case XmPIXMAP_LEFT:
  1082. if (p_h && height > p_h)
  1083. p_y += (height - p_h)/2U;
  1084. s_x += p_w + spacing;
  1085. if (s_h && height > s_h)
  1086. s_y += (height - s_h)/2U;
  1087. /*
  1088. if (p_w && width > p_w + spacing + s_w)
  1089. p_x += (width - p_w - spacing - s_w)/2;
  1090. if (s_w && width > p_w + spacing + s_w)
  1091. s_x += (width - p_w - spacing - s_w)/2;
  1092. */
  1093. break;
  1094. case XmPIXMAP_RIGHT:
  1095. if (s_h && height > s_h)
  1096. s_y += (height - s_h)/2U;
  1097. p_x += s_w + spacing;
  1098. if (p_w && ((unsigned)width > (p_w + spacing + s_w)))
  1099. p_x += (width - p_w - spacing - s_w)/2U;
  1100. if (s_w && ((unsigned)width > (p_w + spacing + s_w)))
  1101. s_x += (width - p_w - spacing - s_w)/2U;
  1102. if (p_h && height > p_h)
  1103. p_y += (height - p_h)/2U;
  1104. break;
  1105. case XmPIXMAP_MIDDLE:
  1106. if (p_w && width > p_w)
  1107. p_x += (width - p_w)/2U;
  1108. if (s_w && width > s_w)
  1109. s_x += (width - s_w)/2U;
  1110. if (s_h && height > s_h)
  1111. s_y += (height - s_h)/2U;
  1112. if (p_h && height > p_h)
  1113. p_y += (height - p_h)/2U;
  1114. break;
  1115. }
  1116. *pix_x = p_x;
  1117. *pix_y = p_y;
  1118. *str_x = s_x;
  1119. *str_y = s_y;
  1120. }
  1121. /*-------------------------------------------------------------
  1122. ** Draw
  1123. ** Draw gadget to drawable.
  1124. */
  1125. static void
  1126. Draw(
  1127. DtControlGadget g,
  1128. Drawable drawable,
  1129. Position x,
  1130. Position y,
  1131. Dimension w,
  1132. Dimension h,
  1133. Dimension h_t,
  1134. Dimension s_t,
  1135. unsigned char s_type,
  1136. unsigned char fill_mode )
  1137. {
  1138. XmManagerWidget mgr = (XmManagerWidget) XtParent (g);
  1139. Display * d = XtDisplay (g);
  1140. GC gc, gcTS, gcBS;
  1141. XRectangle clip;
  1142. Position p_x, p_y, s_x, s_y;
  1143. Dimension width = 0, height = 0;
  1144. Pixmap pix = 0;
  1145. Pixmap mask = 0;
  1146. int index;
  1147. Dimension left = 0, right = 0, top = 0, bottom = 0;
  1148. Dimension v_pad;
  1149. Boolean bClearArea = False;
  1150. Boolean bClearShadow = False;
  1151. Boolean bMono;
  1152. GetPositionProc get_positions;
  1153. bMono = (((G_Foreground (g) == BlackPixelOfScreen (XtScreen (g))) ||
  1154. (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))) &&
  1155. ((G_Background (g) == BlackPixelOfScreen (XtScreen (g))) ||
  1156. (G_Background (g) == WhitePixelOfScreen (XtScreen (g)))) );
  1157. /* Select gc to fill background.
  1158. */
  1159. if (G_ControlType (g) == XmCONTROL_SWITCH)
  1160. gc = bMono ? M_BackgroundGC (mgr) : G_BackgroundGC (g);
  1161. else if ((G_Armed (g)) && (fill_mode != XmFILL_PARENT))
  1162. gc = G_ArmedBackgroundGC (g);
  1163. else
  1164. gc = M_BackgroundGC (mgr);
  1165. if ((fill_mode != XmFILL_NONE) && (fill_mode != XmFILL_TRANSPARENT))
  1166. bClearArea = True;
  1167. /* Select pixmap and mask.
  1168. */
  1169. if (G_Pixmap (g))
  1170. {
  1171. /* Terminate animation sequence.
  1172. */
  1173. if (G_PushImagePosition (g) > G_NumPushImages (g))
  1174. G_PushImagePosition (g) = 0;
  1175. if (G_DropImagePosition (g) > G_NumDropImages (g))
  1176. G_DropImagePosition (g) = 0;
  1177. /* Use animation image.
  1178. */
  1179. if (G_PushImagePosition (g) > 0)
  1180. {
  1181. index = (G_PushImagePosition (g)) - 1;
  1182. if ((index == 0) || (bMono))
  1183. bClearArea = True;
  1184. else
  1185. bClearArea = False;
  1186. pix = G_PushPixmaps (g)[index];
  1187. mask = G_PushMasks (g)[index];
  1188. ++G_PushImagePosition (g);
  1189. }
  1190. else if (G_DropImagePosition (g) > 0)
  1191. {
  1192. index = G_DropImagePosition (g) - 1;
  1193. if (bMono)
  1194. bClearArea = True;
  1195. else
  1196. bClearArea = False;
  1197. pix = G_DropPixmaps (g)[index];
  1198. mask = G_DropMasks (g)[index];
  1199. ++G_DropImagePosition (g);
  1200. }
  1201. /* Use alternate image.
  1202. */
  1203. else if ( ( ((G_ControlType (g) == XmCONTROL_MONITOR) ||
  1204. (G_ControlType (g) == XmCONTROL_MAIL)) &&
  1205. (G_AltPix (g) != XmUNSPECIFIED_PIXMAP) &&
  1206. G_FileChanged (g) ) ||
  1207. ( (G_ControlType (g) == XmCONTROL_BUSY) &&
  1208. (G_AltPix (g) != XmUNSPECIFIED_PIXMAP) &&
  1209. G_Busy (g) && G_Set (g)) )
  1210. {
  1211. pix = G_AltPix (g);
  1212. mask = G_AltMask (g);
  1213. }
  1214. /* Use normal image.
  1215. */
  1216. else
  1217. {
  1218. pix = G_Pixmap (g);
  1219. mask = G_Mask (g);
  1220. }
  1221. }
  1222. if (bClearShadow)
  1223. {
  1224. /* Erase shadow - top, left, right, bottom.
  1225. */
  1226. XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
  1227. w - 2 * h_t, s_t);
  1228. XFillRectangle (d, drawable, gc, x + h_t, y + h_t + s_t,
  1229. s_t, h - 2 * (h_t + s_t));
  1230. XFillRectangle (d, drawable, gc, x + w - h_t - s_t, y + h_t + s_t,
  1231. s_t, h - 2 * (h_t + s_t));
  1232. XFillRectangle (d, drawable, gc, x + h_t, y + h - h_t - s_t,
  1233. w - 2 * h_t, s_t);
  1234. }
  1235. else if (bClearArea)
  1236. /* Fill background.
  1237. */
  1238. XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
  1239. w - 2 * h_t, h - 2 * h_t);
  1240. /* Get pixmap and string positions.
  1241. */
  1242. _DtProcessLock();
  1243. get_positions = C_GetPositions(XtClass(g));
  1244. _DtProcessUnlock();
  1245. (*get_positions) ((DtIconGadget) g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
  1246. /* Select and display pixmap.
  1247. */
  1248. if (G_Pixmap (g))
  1249. {
  1250. /* Compute display region.
  1251. */
  1252. if ((width == 0) && (height == 0))
  1253. {
  1254. width = ((unsigned)(p_x + s_t + h_t) >= G_Width (g))
  1255. ? 0 : Min ((unsigned)G_PixmapWidth (g),
  1256. G_Width (g) - p_x - s_t - h_t);
  1257. height = ((unsigned)(p_y + s_t + h_t) >= G_Height (g))
  1258. ? 0 : Min ((unsigned)G_PixmapHeight (g),
  1259. G_Height (g) - p_y - s_t - h_t);
  1260. }
  1261. /* Update clip gc.
  1262. */
  1263. if (mask != XmUNSPECIFIED_PIXMAP)
  1264. {
  1265. gc = G_ClipGC (g);
  1266. XSetClipMask (XtDisplay(g), gc, mask);
  1267. XSetClipOrigin (XtDisplay(g), gc, x + p_x, y + p_y);
  1268. }
  1269. else
  1270. gc = G_NormalGC (g);
  1271. /* Paint pixmap.
  1272. */
  1273. if ((width > 0 && height > 0) &&
  1274. (gc != NULL) && (pix != XmUNSPECIFIED_PIXMAP))
  1275. XCopyArea (d, pix, drawable, gc, 0, 0,
  1276. width, height, x + p_x, y + p_y);
  1277. }
  1278. /* Draw string.
  1279. */
  1280. clip.x = x + h_t + s_t;
  1281. clip.y = y + h_t + s_t;
  1282. clip.width = G_Width (g) - (2 * (h_t + s_t));
  1283. clip.height = G_Height (g) - (2 * (h_t + s_t));
  1284. if ((G_String (g)) && (clip.width > 0 && clip.height > 0))
  1285. {
  1286. if (G_ControlType (g) == XmCONTROL_DATE)
  1287. {
  1288. if ( (G_StringHeight (g) > 0) && (G_AltStringHeight (g) > 0) )
  1289. {
  1290. unsigned pad_factor;
  1291. if (G_UseLabelAdjustment (g))
  1292. pad_factor = 3;
  1293. else
  1294. pad_factor = 4;
  1295. v_pad = ((unsigned)G_Height(g) >
  1296. (G_StringHeight(g) + G_AltStringHeight(g))) ?
  1297. (G_Height (g) - G_StringHeight (g) -
  1298. G_AltStringHeight (g)) / pad_factor : 0;
  1299. s_y = (2 * v_pad);
  1300. }
  1301. if (bMono)
  1302. {
  1303. XmStringDrawImage (d, drawable, G_FontList (g), G_String (g),
  1304. G_NormalGC (g), x + s_x, y + s_y,
  1305. clip.width, XmALIGNMENT_BEGINNING,
  1306. XmSTRING_DIRECTION_L_TO_R, &clip);
  1307. }
  1308. else
  1309. {
  1310. if (G_UseEmbossedText (g))
  1311. XmStringDraw (d, drawable, G_FontList (g), G_String (g),
  1312. G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
  1313. clip.width, XmALIGNMENT_BEGINNING,
  1314. XmSTRING_DIRECTION_L_TO_R, &clip);
  1315. XmStringDraw (d, drawable, G_FontList (g), G_String (g),
  1316. G_NormalGC (g), x + s_x, y + s_y,
  1317. clip.width, XmALIGNMENT_BEGINNING,
  1318. XmSTRING_DIRECTION_L_TO_R, &clip);
  1319. }
  1320. if (G_Width (g) > G_AltStringWidth (g))
  1321. s_x = (G_Width (g) - G_AltStringWidth (g)) / 2U;
  1322. if (G_UseLabelAdjustment (g))
  1323. s_y = ((G_Height (g) - G_AltStringWidth (g)) + 5);
  1324. else
  1325. s_y += G_StringHeight (g);
  1326. if (bMono)
  1327. {
  1328. XmStringDrawImage (d, drawable, G_FontList (g),
  1329. G_AltString (g),
  1330. G_NormalGC (g), x + s_x, y + s_y,
  1331. clip.width, XmALIGNMENT_BEGINNING,
  1332. XmSTRING_DIRECTION_L_TO_R, &clip);
  1333. }
  1334. else
  1335. {
  1336. if (G_UseEmbossedText (g))
  1337. XmStringDraw (d, drawable, G_FontList (g),
  1338. G_AltString (g),
  1339. G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
  1340. clip.width, XmALIGNMENT_BEGINNING,
  1341. XmSTRING_DIRECTION_L_TO_R, &clip);
  1342. XmStringDraw (d, drawable, G_FontList (g),
  1343. G_AltString (g),
  1344. G_NormalGC (g), x + s_x, y + s_y,
  1345. clip.width, XmALIGNMENT_BEGINNING,
  1346. XmSTRING_DIRECTION_L_TO_R, &clip);
  1347. }
  1348. }
  1349. else
  1350. {
  1351. if (bMono)
  1352. {
  1353. if ((s_x - 2U) >= (h_t + s_t))
  1354. XFillRectangle (d, drawable, G_ArmedBackgroundGC (g),
  1355. x + s_x - 2, y + s_y,
  1356. 2, G_StringHeight (g));
  1357. XmStringDrawImage (d, drawable, G_FontList (g), G_String (g),
  1358. G_NormalGC (g), x + s_x, y + s_y,
  1359. clip.width, XmALIGNMENT_BEGINNING,
  1360. XmSTRING_DIRECTION_L_TO_R, &clip);
  1361. if ((s_x + G_StringWidth (g) + 2U) <= (G_Width (g) - h_t - s_t))
  1362. XFillRectangle (d, drawable, G_ArmedBackgroundGC (g),
  1363. x + s_x + G_StringWidth (g), y + s_y,
  1364. 2, G_StringHeight (g));
  1365. }
  1366. else
  1367. {
  1368. if (G_UseEmbossedText (g))
  1369. XmStringDraw (d, drawable, G_FontList (g), G_String (g),
  1370. G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
  1371. clip.width, XmALIGNMENT_BEGINNING,
  1372. XmSTRING_DIRECTION_L_TO_R, &clip);
  1373. XmStringDraw (d, drawable, G_FontList (g), G_String (g),
  1374. G_NormalGC (g), x + s_x, y + s_y,
  1375. clip.width, XmALIGNMENT_BEGINNING,
  1376. XmSTRING_DIRECTION_L_TO_R, &clip);
  1377. }
  1378. }
  1379. }
  1380. /* Draw shadow.
  1381. */
  1382. switch (G_ControlType (g))
  1383. {
  1384. case XmCONTROL_BLANK:
  1385. case XmCONTROL_DATE:
  1386. break;
  1387. case XmCONTROL_CLIENT:
  1388. /* Get insets.
  1389. */
  1390. if (bMono)
  1391. /* Use black and white.
  1392. */
  1393. {
  1394. if (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))
  1395. {
  1396. gcTS = G_BackgroundGC (g);
  1397. gcBS = G_NormalGC (g);
  1398. }
  1399. else
  1400. {
  1401. gcBS = G_BackgroundGC (g);
  1402. gcTS = G_NormalGC (g);
  1403. }
  1404. }
  1405. else
  1406. {
  1407. gcTS = M_BottomShadowGC (mgr);
  1408. gcBS = M_TopShadowGC (mgr);
  1409. }
  1410. /* Drop inner shadow if secondary since no fill.
  1411. */
  1412. XmeDrawShadows (d, drawable, gcTS, gcBS,
  1413. x + left - s_t, y + top - s_t,
  1414. w - left - right + (2 * s_t),
  1415. h - top - bottom + (2 * s_t),
  1416. s_t, XmSHADOW_ETCHED_OUT);
  1417. break;
  1418. default:
  1419. case XmCONTROL_BUTTON:
  1420. case XmCONTROL_MONITOR:
  1421. case XmCONTROL_MAIL:
  1422. switch (G_Behavior (g))
  1423. {
  1424. case XmICON_BUTTON:
  1425. if (G_Armed (g))
  1426. XmeDrawShadows(d, drawable,
  1427. M_TopShadowGC(mgr), M_BottomShadowGC(mgr),
  1428. x + h_t, y + h_t,
  1429. w - 2*h_t, h - 2*h_t, s_t, XmSHADOW_IN);
  1430. break;
  1431. case XmICON_TOGGLE:
  1432. if ( (G_Armed (g) && !G_Set (g)) ||
  1433. (!G_Armed (g) && G_Set (g)) )
  1434. XmeDrawShadows(d, drawable,
  1435. M_TopShadowGC(mgr), M_BottomShadowGC(mgr),
  1436. x + h_t, y + h_t,
  1437. w - 2*h_t, h - 2*h_t, s_t, XmSHADOW_IN);
  1438. break;
  1439. }
  1440. break;
  1441. case XmCONTROL_SWITCH:
  1442. if (!G_FillOnArm (g))
  1443. {
  1444. gcTS = G_BottomShadowGC (g);
  1445. gcBS = G_TopShadowGC (g);
  1446. }
  1447. else
  1448. {
  1449. if (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))
  1450. {
  1451. gcTS = G_BackgroundGC (g);
  1452. gcBS = G_NormalGC (g);
  1453. }
  1454. else
  1455. {
  1456. gcTS = G_NormalGC (g);
  1457. gcBS = G_BackgroundGC (g);
  1458. }
  1459. }
  1460. XmeDrawShadows (d, drawable, gcTS, gcBS,
  1461. x + h_t, y + h_t, w - 2*h_t, h - 2*h_t, 1,
  1462. XmSHADOW_OUT);
  1463. ++x; ++y; w -= 2; h -= 2; --s_t;
  1464. if (s_t > 0)
  1465. {
  1466. if ( (G_Armed (g) && !G_Set (g)) ||
  1467. (!G_Armed (g) && G_Set (g)) )
  1468. {
  1469. gcTS = G_BottomShadowGC (g);
  1470. gcBS = G_TopShadowGC (g);
  1471. }
  1472. else
  1473. {
  1474. gcTS = G_TopShadowGC (g);
  1475. gcBS = G_BottomShadowGC (g);
  1476. }
  1477. XmeDrawShadows (d, drawable, gcTS, gcBS,
  1478. x + h_t, y + h_t, w - 2*h_t, h - 2*h_t, s_t,
  1479. XmSHADOW_OUT);
  1480. }
  1481. break;
  1482. }
  1483. }
  1484. /*-------------------------------------------------------------
  1485. ** CallCallback
  1486. ** Call callback, if any, with reason and event.
  1487. */
  1488. static void
  1489. CallCallback(
  1490. DtControlGadget g,
  1491. XtCallbackList cb,
  1492. int reason,
  1493. XEvent *event )
  1494. {
  1495. DtControlCallbackStruct cb_data;
  1496. XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
  1497. if ((reason == XmCR_ACTIVATE) && (G_Behavior (g) == XmICON_BUTTON))
  1498. {
  1499. if (G_ClickTimer (g) != 0)
  1500. return;
  1501. else
  1502. G_ClickTimer (g) =
  1503. XtAppAddTimeOut (app_context, G_ClickTime (g),
  1504. ClickTimeout, (XtPointer) g);
  1505. }
  1506. if (cb != NULL)
  1507. {
  1508. cb_data.reason = reason;
  1509. cb_data.event = event;
  1510. cb_data.control_type = G_ControlType (g);
  1511. cb_data.set = G_Set (g);
  1512. cb_data.push_function = G_PushFunction (g);
  1513. cb_data.push_argument = G_PushArgument (g);
  1514. cb_data.subpanel = G_Subpanel (g);
  1515. cb_data.file_size = G_FileSize (g);
  1516. XtCallCallbackList ((Widget) g, cb, &cb_data);
  1517. }
  1518. }
  1519. /*-------------------------------------------------------------
  1520. ** UpdateGCs
  1521. ** Get normal and background graphics contexts.
  1522. ** Use standard mask to maximize caching opportunities.
  1523. */
  1524. static void
  1525. UpdateGCs(
  1526. DtControlGadget g )
  1527. {
  1528. XGCValues values;
  1529. XtGCMask value_mask;
  1530. XmManagerWidget mw = (XmManagerWidget) XtParent(g);
  1531. XFontStruct * font;
  1532. if (!G__DoUpdate (g))
  1533. return;
  1534. if (G_NormalGC (g))
  1535. XtReleaseGC ((Widget)mw, G_NormalGC (g));
  1536. if (G_ClipGC (g))
  1537. XtReleaseGC ((Widget)mw, G_ClipGC (g));
  1538. if (G_BackgroundGC (g))
  1539. XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
  1540. if (G_ArmedBackgroundGC (g))
  1541. XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
  1542. if (G_TopShadowGC (g))
  1543. XtReleaseGC ((Widget)mw, G_TopShadowGC (g));
  1544. if (G_BottomShadowGC (g))
  1545. XtReleaseGC ((Widget)mw, G_BottomShadowGC (g));
  1546. /* Get normal GC.
  1547. */
  1548. value_mask = GCForeground | GCBackground | GCFillStyle;
  1549. if (XmeRenderTableGetDefaultFont (G_FontList (g), &font)) {
  1550. value_mask |= GCFont;
  1551. values.font = font->fid;
  1552. }
  1553. if (G_UseEmbossedText (g))
  1554. values.foreground = WhitePixelOfScreen (XtScreen (g));
  1555. else
  1556. values.foreground = G_Foreground (g);
  1557. values.background = G_Background (g);
  1558. values.fill_style = FillSolid;
  1559. G_NormalGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1560. /* Get top shadow GC.
  1561. */
  1562. if (G_ControlType (g) == XmCONTROL_SWITCH)
  1563. values.foreground = G_PixmapBackground (g);
  1564. else
  1565. values.foreground = mw -> manager.top_shadow_color;
  1566. values.background = G_Background (g);
  1567. G_TopShadowGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1568. /* Get bottom shadow GC.
  1569. */
  1570. if (G_ControlType (g) == XmCONTROL_SWITCH)
  1571. values.foreground = G_PixmapForeground (g);
  1572. else
  1573. values.foreground = mw -> manager.bottom_shadow_color;
  1574. values.background = G_Background (g);
  1575. G_BottomShadowGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1576. /* Get background GC.
  1577. */
  1578. values.foreground = G_Background (g);
  1579. values.background = G_Foreground (g);
  1580. G_BackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1581. /* Get armed background GC.
  1582. */
  1583. values.foreground = G_ArmColor (g);
  1584. values.background = G_Background (g);
  1585. G_ArmedBackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1586. /* Get Clip GC
  1587. */
  1588. if (G_Mask(g) != XmUNSPECIFIED_PIXMAP)
  1589. {
  1590. value_mask |= GCClipMask;
  1591. values.clip_mask = G_Mask(g);
  1592. }
  1593. values.foreground = G_Foreground (g);
  1594. values.background = G_Background (g);
  1595. G_ClipGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
  1596. }
  1597. /*-------------------------------------------------------------
  1598. ** Public Entry Points
  1599. **-------------------------------------------------------------
  1600. */
  1601. /*-------------------------------------------------------------
  1602. ** Push Animation Timeout
  1603. ** An XtTimerCallbackProc.
  1604. */
  1605. static void
  1606. PushAnimationTimeout(
  1607. XtPointer client_data,
  1608. XtIntervalId *id )
  1609. {
  1610. DtControlGadget g = (DtControlGadget) client_data;
  1611. XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
  1612. XtExposeProc expose;
  1613. if ((G_PushImagePosition (g) > 0) &&
  1614. (G_PushImagePosition (g) <= G_NumPushImages (g)))
  1615. {
  1616. G_PushAnimationTimer (g) =
  1617. XtAppAddTimeOut (app_context,
  1618. G_PushDelays (g)[G_PushImagePosition (g) - 1],
  1619. PushAnimationTimeout, (XtPointer) g);
  1620. }
  1621. if (G_PushImagePosition (g) > 1)
  1622. {
  1623. _DtProcessLock();
  1624. expose = XtCoreProc((Widget)g, expose);
  1625. _DtProcessUnlock();
  1626. (*expose) ((Widget) g, NULL, NULL);
  1627. }
  1628. }
  1629. /*-------------------------------------------------------------
  1630. ** _DtControlDoPushAnimation
  1631. ** Do Push animation.
  1632. **-------------------------------------------------------------
  1633. */
  1634. void
  1635. _DtControlDoPushAnimation(
  1636. Widget w )
  1637. {
  1638. DtControlGadget g = (DtControlGadget) w;
  1639. if ((G_NumPushImages (g) > 0) && (G_PushImagePosition (g) == 0))
  1640. {
  1641. G_PushImagePosition (g) = 1;
  1642. PushAnimationTimeout ((XtPointer) g, NULL);
  1643. }
  1644. }
  1645. /*-------------------------------------------------------------
  1646. ** _DtControlAddPushAnimationImage
  1647. ** Add Push animation image.
  1648. **-------------------------------------------------------------
  1649. */
  1650. void
  1651. _DtControlAddPushAnimationImage(
  1652. Widget w,
  1653. String image,
  1654. int delay )
  1655. {
  1656. DtControlGadget g = (DtControlGadget) w;
  1657. int i;
  1658. /* Allocate blocks of animation data.
  1659. */
  1660. if (G_NumPushImages (g) == G_MaxPushImages (g))
  1661. {
  1662. G_MaxPushImages (g) += NUM_LIST_ITEMS;
  1663. G_PushDelays (g) = (int*)
  1664. XtRealloc ((char*) G_PushDelays (g),
  1665. G_MaxPushImages (g) *sizeof (int));
  1666. G_PushPixmaps (g) = (Pixmap*)
  1667. XtRealloc ((char*) G_PushPixmaps (g),
  1668. G_MaxPushImages (g) *sizeof (Pixmap));
  1669. G_PushMasks (g) = (Pixmap*)
  1670. XtRealloc ((char*) G_PushMasks (g),
  1671. G_MaxPushImages (g) *sizeof (Pixmap));
  1672. }
  1673. /* Allocate animation image.
  1674. */
  1675. i = G_NumPushImages (g)++;
  1676. G_PushDelays (g)[i] = delay;
  1677. G_PushPixmaps (g)[i] = XmGetPixmap (XtScreen (g), image,
  1678. G_PixmapForeground (g),
  1679. G_PixmapBackground (g));
  1680. G_PushMasks (g)[i] = _DtGetMask (XtScreen (g), image);
  1681. }
  1682. /*-------------------------------------------------------------
  1683. ** Drop Animation Timeout
  1684. ** An XtTimerCallbackProc.
  1685. */
  1686. static void
  1687. DropAnimationTimeout(
  1688. XtPointer client_data,
  1689. XtIntervalId *id )
  1690. {
  1691. DtControlGadget g = (DtControlGadget) client_data;
  1692. XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
  1693. XtExposeProc expose;
  1694. if ((G_DropImagePosition (g) > 0) &&
  1695. (G_DropImagePosition (g) <= G_NumDropImages (g)))
  1696. {
  1697. G_DropAnimationTimer (g) =
  1698. XtAppAddTimeOut (app_context,
  1699. G_DropDelays (g)[G_DropImagePosition (g) - 1],
  1700. DropAnimationTimeout, (XtPointer) g);
  1701. }
  1702. _DtProcessLock();
  1703. expose = XtCoreProc((Widget)g, expose);
  1704. _DtProcessUnlock();
  1705. (*expose) ((Widget) g, NULL, NULL);
  1706. }
  1707. /*-------------------------------------------------------------
  1708. ** _DtControlDoDropAnimation
  1709. ** Do drop animation.
  1710. **-------------------------------------------------------------
  1711. */
  1712. void
  1713. _DtControlDoDropAnimation(
  1714. Widget w )
  1715. {
  1716. DtControlGadget g = (DtControlGadget) w;
  1717. if ((G_NumDropImages (g) > 0) && (G_DropImagePosition (g) == 0))
  1718. {
  1719. G_DropImagePosition (g) = 1;
  1720. DropAnimationTimeout ((XtPointer) g, NULL);
  1721. }
  1722. }
  1723. /*-------------------------------------------------------------
  1724. ** _DtControlAddDropAnimationImage
  1725. ** Add drop animation image.
  1726. **-------------------------------------------------------------
  1727. */
  1728. void
  1729. _DtControlAddDropAnimationImage(
  1730. Widget w,
  1731. String image,
  1732. int delay )
  1733. {
  1734. DtControlGadget g = (DtControlGadget) w;
  1735. int i;
  1736. /* Allocate blocks of animation data.
  1737. */
  1738. if (G_NumDropImages (g) == G_MaxDropImages (g))
  1739. {
  1740. G_MaxDropImages (g) += NUM_LIST_ITEMS;
  1741. G_DropDelays (g) = (int*)
  1742. XtRealloc ((char*) G_DropDelays (g),
  1743. G_MaxDropImages (g) *sizeof (int));
  1744. G_DropPixmaps (g) = (Pixmap*)
  1745. XtRealloc ((char*) G_DropPixmaps (g),
  1746. G_MaxDropImages (g) *sizeof (Pixmap));
  1747. G_DropMasks (g) = (Pixmap*)
  1748. XtRealloc ((char*) G_DropMasks (g),
  1749. G_MaxDropImages (g) *sizeof (Pixmap));
  1750. }
  1751. /* Allocate animation image.
  1752. */
  1753. i = G_NumDropImages (g)++;
  1754. G_DropDelays (g)[i] = delay;
  1755. G_DropPixmaps (g)[i] = XmGetPixmap (XtScreen (g), image,
  1756. G_PixmapForeground (g),
  1757. G_PixmapBackground (g));
  1758. G_DropMasks (g)[i] = _DtGetMask (XtScreen (g), image);
  1759. }
  1760. /*-------------------------------------------------------------
  1761. ** _DtControlSetFileChanged
  1762. ** Set file changed.
  1763. **-------------------------------------------------------------
  1764. */
  1765. void
  1766. _DtControlSetFileChanged(
  1767. Widget w,
  1768. Boolean b )
  1769. {
  1770. DtControlGadget g = (DtControlGadget) w;
  1771. XtExposeProc expose;
  1772. if ((G_ControlType (g) == XmCONTROL_MONITOR) ||
  1773. (G_ControlType (g) == XmCONTROL_MAIL))
  1774. {
  1775. G_FileChanged (g) = b;
  1776. _DtProcessLock();
  1777. expose = XtCoreProc((Widget)g, expose);
  1778. _DtProcessUnlock();
  1779. (*expose) ((Widget) g, NULL, False);
  1780. }
  1781. }
  1782. /*-------------------------------------------------------------
  1783. ** _DtControlSetBusy
  1784. ** Set busy.
  1785. **-------------------------------------------------------------
  1786. */
  1787. void
  1788. _DtControlSetBusy(
  1789. Widget w,
  1790. Boolean b )
  1791. {
  1792. DtControlGadget g = (DtControlGadget) w;
  1793. if (G_ControlType (g) != XmCONTROL_BUSY)
  1794. return;
  1795. if (b)
  1796. {
  1797. G_BlinkElapsed (g) = 0;
  1798. ++ G_Busy (g);
  1799. if (G_Busy (g) == 1)
  1800. {
  1801. CallCallbackProc call_callback;
  1802. _DtProcessLock();
  1803. call_callback = C_CallCallback(XtClass(g));
  1804. _DtProcessUnlock();
  1805. (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_BUSY_START,
  1806. NULL);
  1807. BusyTimeout ((XtPointer) w, NULL);
  1808. }
  1809. }
  1810. else
  1811. {
  1812. if (G_Busy (g) > 0)
  1813. --G_Busy (g);
  1814. }
  1815. }
  1816. /*-------------------------------------------------------------
  1817. ** _DtCreateControl
  1818. ** Create a new gadget instance.
  1819. **-------------------------------------------------------------
  1820. */
  1821. Widget
  1822. _DtCreateControl(
  1823. Widget parent,
  1824. String name,
  1825. ArgList arglist,
  1826. int argcount )
  1827. {
  1828. return (XtCreateWidget (name, dtControlGadgetClass,
  1829. parent, arglist, argcount));
  1830. }
  1831. static void
  1832. ReplaceJPDate(char *date, char *jpstr, int wday)
  1833. {
  1834. char *s, *rp, *sp;
  1835. char *p = NULL;
  1836. char abday[5];
  1837. char newdate[128];
  1838. int i, j;
  1839. size_t k;
  1840. _Xstrtokparams strtok_buf;
  1841. s = (char *)malloc((strlen(jpstr) + 1) * sizeof(char));
  1842. strcpy(s, jpstr);
  1843. for(p = _XStrtok(s, ",", strtok_buf), i = 0;
  1844. p != NULL && i < wday ;
  1845. p = _XStrtok(NULL, ",", strtok_buf), i++)
  1846. /* EMPTY */;
  1847. if(p == NULL) {
  1848. free(s);
  1849. return;
  1850. }
  1851. snprintf(abday, sizeof(abday), "%s", nl_langinfo(ABDAY_1 + wday));
  1852. if((rp = strstr(date, abday)) != NULL) {
  1853. for(i = 0, j = 0, sp = date; date[j] != '\0'; sp++) {
  1854. if(sp == rp) {
  1855. for(k = 0; k < strlen(p); k++)
  1856. newdate[i++] = p[k];
  1857. j += strlen(abday);
  1858. }
  1859. else
  1860. newdate[i++] = date[j++];
  1861. }
  1862. newdate[i] = '\0';
  1863. strcpy(date, newdate);
  1864. }
  1865. free(s);
  1866. return;
  1867. }
  1868. char
  1869. _DtControlGetMonitorState(Widget w)
  1870. {
  1871. DtControlGadget g = (DtControlGadget) w;
  1872. if (G_FileChanged (g))
  1873. return(DtMONITOR_ON);
  1874. else
  1875. return(DtMONITOR_OFF);
  1876. }