Control.c 54 KB

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