TitleBox.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  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. /* $XConsortium: TitleBox.c /main/14 1996/10/14 10:48:11 pascale $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1990,1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. /**---------------------------------------------------------------------
  34. ***
  35. *** file: TitleBox.c
  36. ***
  37. *** project: MotifPlus Widgets
  38. ***
  39. *** description: Source code for DtTitleBox class.
  40. ***
  41. ***-------------------------------------------------------------------*/
  42. /*-------------------------------------------------------------
  43. ** Include Files
  44. */
  45. #include <Xm/LabelG.h>
  46. #if RiversVersion == _31
  47. #include <Xm/ManagerP.h>
  48. #include <Xm/GadgetP.h>
  49. #endif /* RiversVersion == _31 */
  50. #include <Xm/DrawP.h>
  51. #include <Xm/XmP.h>
  52. #include <Dt/TitleBoxP.h>
  53. #include <Dt/MacrosP.h>
  54. #include <Dt/DtMsgsP.h>
  55. #include "DtWidgetI.h"
  56. #include <Xm/XmPrivate.h> /* _XmClearShadowType */
  57. /******** Public Function Declarations ********/
  58. extern Widget _DtCreateTitleBox(
  59. Widget parent,
  60. char *name,
  61. ArgList arglist,
  62. Cardinal argcount) ;
  63. extern Widget _DtTitleBoxGetTitleArea(
  64. Widget w) ;
  65. extern Widget _DtTitleBoxGetWorkArea(
  66. Widget w) ;
  67. #define Max(x, y) (((x) > (y)) ? (x) : (y))
  68. /******** End Public Function Declarations ********/
  69. /******** Static Function Declarations ********/
  70. static void ConfigureChildren(
  71. DtTitleBoxWidget manager) ;
  72. static void GetSize(
  73. DtTitleBoxWidget manager,
  74. Dimension ta_w,
  75. Dimension ta_h,
  76. Dimension wa_w,
  77. Dimension wa_h,
  78. Dimension *w,
  79. Dimension *h) ;
  80. static void GetTitleString(
  81. DtTitleBoxWidget manager,
  82. XrmQuark resource,
  83. XtArgVal *value) ;
  84. static void ClassInitialize( void ) ;
  85. static void ClassPartInitialize(
  86. WidgetClass wc) ;
  87. static void Initialize(
  88. DtTitleBoxWidget request,
  89. DtTitleBoxWidget new) ;
  90. static void Destroy(
  91. DtTitleBoxWidget manager) ;
  92. static void Resize(
  93. DtTitleBoxWidget manager) ;
  94. static void Redisplay(
  95. DtTitleBoxWidget manager,
  96. XEvent *event,
  97. Region region) ;
  98. static Boolean SetValues(
  99. DtTitleBoxWidget current,
  100. DtTitleBoxWidget request,
  101. DtTitleBoxWidget new) ;
  102. static XtGeometryResult QueryGeometry(
  103. DtTitleBoxWidget manager,
  104. XtWidgetGeometry *request,
  105. XtWidgetGeometry *reply) ;
  106. static XtGeometryResult GeometryManager(
  107. Widget kid,
  108. XtWidgetGeometry *request,
  109. XtWidgetGeometry *reply) ;
  110. static void ChangeManaged(
  111. DtTitleBoxWidget manager) ;
  112. static void InsertChild(
  113. Widget child) ;
  114. static void ConstraintInitialize(
  115. Widget request,
  116. Widget new) ;
  117. /******** End Static Function Declarations ********/
  118. /*-------------------------------------------------------------
  119. ** Forward Declarations
  120. */
  121. #define UNSPECIFIED_CHAR 255
  122. #define UNSPECIFIED_DIMENSION 9999
  123. #define MARGIN_DEFAULT 10
  124. #define WARN_CHILD_TYPE _DtMsgDialogBox_0000
  125. #define WARN_SHADOW_TYPE _DtMsgIcon_0005
  126. #define WARN_TITLE_POSITION _DtMsgTitleBox_0000
  127. #define WARN_TITLE_ALIGNMENT _DtMsgTitleBox_0001
  128. #define MESSAGE2 _DtMsgTitleBox_0002
  129. #define MESSAGE3 _DtMsgTitleBox_0003
  130. #define MESSAGE4 _DtMsgTitleBox_0004
  131. extern void _DtRegisterNewConverters( void ) ;
  132. /*-------------------------------------------------------------
  133. ** Translations and Actions
  134. */
  135. /*-------------------------------------------------------------
  136. ** Resource List
  137. */
  138. /* Define offset macros.
  139. */
  140. #define TB_Offset(field) \
  141. XtOffset (DtTitleBoxWidget, title_box.field)
  142. #define TBC_Offset(field) \
  143. XtOffset (DtTitleBoxConstraintPtr, title_box_constraint.field)
  144. static XtResource resources[] =
  145. {
  146. {
  147. XmNshadowThickness,
  148. XmCShadowThickness, XmRShort, sizeof (short),
  149. XtOffset (DtTitleBoxWidget, manager.shadow_thickness),
  150. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  151. },
  152. {
  153. XmNmarginWidth,
  154. XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
  155. TB_Offset (margin_width),
  156. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  157. },
  158. {
  159. XmNmarginHeight,
  160. XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
  161. TB_Offset (margin_height),
  162. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  163. },
  164. {
  165. XmNshadowType,
  166. XmCShadowType, XmRShadowType, sizeof (unsigned char),
  167. TB_Offset (shadow_type),
  168. XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
  169. },
  170. {
  171. XmNtitleSpacing,
  172. XmCTitleSpacing, XmRHorizontalDimension, sizeof (Dimension),
  173. TB_Offset (title_spacing),
  174. XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
  175. },
  176. {
  177. XmNtitlePosition,
  178. XmCTitlePosition, XmRTitlePosition, sizeof (unsigned char),
  179. TB_Offset (title_position), XmRImmediate, (XtPointer) XmTITLE_TOP
  180. },
  181. {
  182. XmNtitleAlignment,
  183. XmCAlignment, XmRAlignment, sizeof (unsigned char),
  184. TB_Offset (title_alignment),
  185. XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
  186. },
  187. {
  188. XmNtitleString,
  189. XmCXmString, XmRXmString, sizeof (XmString),
  190. TB_Offset (title_string),
  191. XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
  192. },
  193. {
  194. XmNfontList,
  195. XmCFontList, XmRFontList, sizeof (XmFontList),
  196. TB_Offset (font_list), XmRImmediate, (XtPointer) NULL
  197. }
  198. };
  199. /* Synthetic Resources
  200. */
  201. static XmSyntheticResource syn_resources[] =
  202. {
  203. {
  204. XmNtitleString, sizeof (XmString),
  205. TB_Offset (title_string),
  206. (XmExportProc) GetTitleString,
  207. (XmImportProc) NULL
  208. },
  209. {
  210. XmNmarginWidth, sizeof (Dimension),
  211. TB_Offset (margin_width),
  212. (XmExportProc) XmeFromHorizontalPixels,
  213. (XmImportProc) XmeToHorizontalPixels
  214. },
  215. {
  216. XmNmarginHeight, sizeof (Dimension),
  217. TB_Offset (margin_height),
  218. (XmExportProc) XmeFromVerticalPixels,
  219. (XmImportProc) XmeToVerticalPixels,
  220. }
  221. };
  222. /* Constraint Resources
  223. */
  224. static XtResource constraints[] =
  225. {
  226. {
  227. XmNchildType,
  228. XmCChildType, XmRChildType, sizeof (unsigned char),
  229. TBC_Offset (child_type), XmRImmediate, (XtPointer) XmWORK_AREA
  230. }
  231. };
  232. /*-------------------------------------------------------------
  233. ** Class Record
  234. */
  235. DtTitleBoxClassRec dtTitleBoxClassRec =
  236. {
  237. /* Core Part
  238. */
  239. {
  240. (WidgetClass) &xmManagerClassRec, /* superclass */
  241. "DtTitleBox", /* class_name */
  242. sizeof (DtTitleBoxRec), /* widget_size */
  243. ClassInitialize, /* class_initialize */
  244. ClassPartInitialize, /* class_part_initialize*/
  245. False, /* class_inited */
  246. (XtInitProc) Initialize, /* initialize */
  247. NULL, /* initialize_hook */
  248. XtInheritRealize, /* realize */
  249. NULL, /* actions */
  250. 0, /* num_actions */
  251. resources, /* resources */
  252. XtNumber (resources), /* num_resources */
  253. NULLQUARK, /* xrm_class */
  254. True, /* compress_motion */
  255. True, /* compress_exposure */
  256. True, /* compress_enterleave */
  257. False, /* visible_interest */
  258. (XtWidgetProc) Destroy, /* destroy */
  259. (XtWidgetProc) Resize, /* resize */
  260. (XtExposeProc) Redisplay, /* expose */
  261. (XtSetValuesFunc) SetValues, /* set_values */
  262. NULL, /* set_values_hook */
  263. XtInheritSetValuesAlmost, /* set_values_almost */
  264. NULL, /* get_values_hook */
  265. NULL, /* accept_focus */
  266. XtVersion, /* version */
  267. NULL, /* callback private */
  268. XtInheritTranslations, /* tm_table */
  269. XtInheritQueryGeometry, /* query_geometry */
  270. NULL, /* display_accelerator */
  271. NULL, /* extension */
  272. },
  273. /* Composite Part
  274. */
  275. {
  276. (XtGeometryHandler) GeometryManager,/* geometry_manager */
  277. (XtWidgetProc) ChangeManaged, /* change_managed */
  278. (XtWidgetProc) InsertChild, /* insert_child */
  279. XtInheritDeleteChild, /* delete_child */
  280. NULL, /* extension */
  281. },
  282. /* Composite Part
  283. */
  284. {
  285. constraints, /* constraint_resources */
  286. XtNumber (constraints), /* num_constraint_resources */
  287. sizeof (DtTitleBoxConstraintRec), /* constraint_record */
  288. (XtInitProc) ConstraintInitialize, /* constraint_initialize */
  289. NULL, /* constraint_destroy */
  290. NULL, /* constraint_set_values */
  291. NULL, /* extension */
  292. },
  293. /* XmManager Part
  294. */
  295. {
  296. XtInheritTranslations, /* default_translations */
  297. syn_resources, /* syn_resources */
  298. XtNumber (syn_resources), /* num_syn_resources */
  299. NULL, /* syn_cont_resources */
  300. 0, /* num_syn_cont_resources */
  301. XmInheritParentProcess, /* parent_process */
  302. NULL, /* extension */
  303. },
  304. /* DtTitleBox Part
  305. */
  306. {
  307. NULL, /* extension */
  308. }
  309. };
  310. WidgetClass dtTitleBoxWidgetClass = (WidgetClass) &dtTitleBoxClassRec;
  311. /*-------------------------------------------------------------
  312. ** Private Procs
  313. **-------------------------------------------------------------
  314. */
  315. /*-------------------------------------------------------------------------
  316. ** ConfigureChildren
  317. ** Set positions and sizes of title and work area.
  318. */
  319. static void
  320. ConfigureChildren(
  321. DtTitleBoxWidget manager )
  322. {
  323. Widget title_area = M_TitleArea (manager),
  324. work_area = M_WorkArea (manager);
  325. Position ta_x = 0, ta_y = 0, wa_x = 0, wa_y = 0;
  326. Dimension ta_w = 0, ta_h = 0, ta_bw = 0,
  327. wa_w = 0, wa_h = 0, wa_bw = 0,
  328. w = M_Width (manager),
  329. h = M_Height (manager),
  330. s_t = M_ShadowThickness (manager),
  331. m_w = M_MarginWidth (manager),
  332. m_h = M_MarginHeight (manager),
  333. ta_sp = M_TitleSpacing (manager);
  334. Boolean title_top;
  335. unsigned char align = M_TitleAlignment (manager);
  336. XtWidgetGeometry ta_reply;
  337. title_top = (M_TitlePosition (manager) == XmTITLE_TOP) ? True : False;
  338. /* Set position and size of title area.
  339. */
  340. if (title_area)
  341. {
  342. XtQueryGeometry (title_area, NULL, &ta_reply);
  343. ta_w = ta_reply.width;
  344. ta_h = ta_reply.height;
  345. if (ta_w + 2U * ta_sp > (M_Width (manager) - 2U * ta_sp))
  346. ta_w = M_Width (manager) - 2 * ta_sp;
  347. if (ta_w == 0)
  348. ta_w = 10;
  349. if (ta_h == 0)
  350. ta_h = 10;
  351. if (align == XmALIGNMENT_BEGINNING)
  352. ta_x = ta_sp;
  353. else if (align == XmALIGNMENT_END)
  354. ta_x = w - ta_sp - ta_w;
  355. else
  356. ta_x = (w - ta_w) / 2U;
  357. ta_y = (title_top) ? 0 : h - ta_h;
  358. ta_bw = P_BorderWidth (title_area);
  359. XmeConfigureObject (title_area, ta_x, ta_y, ta_w, ta_h, ta_bw);
  360. }
  361. /* Set position and size of work area.
  362. */
  363. if (work_area)
  364. {
  365. wa_x = m_w + s_t;
  366. wa_y = (title_top) ? Max (s_t, ta_h) + m_h : s_t + m_h;
  367. wa_w = w - 2 * (m_w + s_t);
  368. if (wa_w == 0)
  369. wa_w = 10;
  370. wa_h = h - Max (s_t, ta_h) - s_t - 2 * m_h;
  371. if (wa_h == 0)
  372. wa_h = 10;
  373. wa_bw = P_BorderWidth (work_area);
  374. XmeConfigureObject (work_area,
  375. wa_x, wa_y, wa_w, wa_h, wa_bw);
  376. }
  377. }
  378. /*-------------------------------------------------------------------------
  379. ** GetSize
  380. ** Calculate desired size based on children.
  381. */
  382. static void
  383. GetSize(
  384. DtTitleBoxWidget manager,
  385. Dimension ta_w,
  386. Dimension ta_h,
  387. Dimension wa_w,
  388. Dimension wa_h,
  389. Dimension *w,
  390. Dimension *h )
  391. {
  392. Widget title_area = M_TitleArea (manager),
  393. work_area = M_WorkArea (manager);
  394. XtWidgetGeometry ta_reply, wa_reply;
  395. Dimension s_t = M_ShadowThickness (manager),
  396. m_w = M_MarginWidth (manager),
  397. m_h = M_MarginHeight (manager),
  398. ta_sp = M_TitleSpacing (manager);
  399. /* Optimize title area change if possible.
  400. */
  401. if (work_area && (wa_w == 0) && (wa_h == 0))
  402. {
  403. if ((ta_w != 0) && (ta_h == 0))
  404. {
  405. if ((M_Width (manager) >=
  406. M_Width (work_area) + (2U * ta_sp)) &&
  407. (M_Height (manager) >= Max (ta_h, s_t) +
  408. M_Height (work_area) + s_t + (2U * m_h)))
  409. {
  410. wa_w = M_Width (work_area);
  411. wa_h = M_Height (work_area);
  412. }
  413. }
  414. if ((wa_w == 0) && (wa_h == 0))
  415. {
  416. XtQueryGeometry (work_area, NULL, &wa_reply);
  417. wa_w = wa_reply.width;
  418. wa_h = wa_reply.height;
  419. }
  420. }
  421. if (title_area && (ta_w == 0) && (ta_h == 0))
  422. {
  423. XtQueryGeometry (title_area, NULL, &ta_reply);
  424. ta_w = ta_reply.width;
  425. ta_h = ta_reply.height;
  426. }
  427. *w = Max (wa_w + (2U * (m_w + s_t)), ta_w + (2U * ta_sp));
  428. if (*w == 0)
  429. *w = 10;
  430. *h = Max (s_t, ta_h) + wa_h + (2 * m_h) + s_t;
  431. if (*h == 0)
  432. *h = 10;
  433. }
  434. /*-------------------------------------------------------------
  435. ** GetTitleString
  436. ** Get string from title label.
  437. */
  438. static void
  439. GetTitleString(
  440. DtTitleBoxWidget manager,
  441. XrmQuark resource,
  442. XtArgVal *value )
  443. {
  444. Arg al[10]; /* arg list */
  445. int ac; /* arg count */
  446. Widget title_area = M_TitleArea (manager);
  447. XmString string = NULL;
  448. if (title_area)
  449. {
  450. ac = 0;
  451. XtSetArg (al[ac], XmNlabelString, &string); ac++;
  452. XtGetValues (title_area, al, ac);
  453. }
  454. *value = (XtArgVal) string;
  455. }
  456. /*-------------------------------------------------------------
  457. ** Action Procs
  458. **-------------------------------------------------------------
  459. */
  460. /*-------------------------------------------------------------
  461. ** Core Procs
  462. **-------------------------------------------------------------
  463. */
  464. /*-------------------------------------------------------------------------
  465. ** ClassInitialize
  466. ** Initialize widget class.
  467. */
  468. static void
  469. ClassInitialize( void )
  470. {
  471. _DtRegisterNewConverters ();
  472. }
  473. /*-------------------------------------------------------------------------
  474. ** ClassPartInitialize
  475. ** Initialize widget class data.
  476. */
  477. static void
  478. ClassPartInitialize(
  479. WidgetClass wc )
  480. {
  481. }
  482. /*-------------------------------------------------------------
  483. ** Initialize
  484. ** Initialize a new widget instance.
  485. */
  486. static void
  487. Initialize(
  488. DtTitleBoxWidget request,
  489. DtTitleBoxWidget new )
  490. {
  491. Arg al[10]; /* arg list */
  492. int ac; /* arg count */
  493. Widget title = NULL;
  494. XmString title_string = NULL;
  495. /* Check for unspecified dimensions.
  496. */
  497. if (M_MarginWidth (request) == UNSPECIFIED_DIMENSION)
  498. M_MarginWidth (new) = MARGIN_DEFAULT;
  499. if (M_MarginHeight (request) == UNSPECIFIED_DIMENSION)
  500. M_MarginHeight (new) = MARGIN_DEFAULT;
  501. if (M_TitleSpacing (request) == UNSPECIFIED_DIMENSION)
  502. M_TitleSpacing (new) = UNSPECIFIED_DIMENSION;
  503. if (M_ShadowThickness (new) == UNSPECIFIED_DIMENSION)
  504. {
  505. if (XtIsShell (XtParent (new)))
  506. M_ShadowThickness (new) = 1;
  507. else
  508. M_ShadowThickness (new) = 2;
  509. }
  510. /* Validate shadow type.
  511. */
  512. if (M_ShadowType (new) == UNSPECIFIED_CHAR)
  513. {
  514. if (XtIsShell (XtParent (new)))
  515. M_ShadowType (new) = XmSHADOW_OUT;
  516. else
  517. M_ShadowType (new) = XmSHADOW_ETCHED_IN;
  518. }
  519. else if (M_ShadowType (new) != XmSHADOW_IN &&
  520. M_ShadowType (new) != XmSHADOW_OUT &&
  521. M_ShadowType (new) != XmSHADOW_ETCHED_IN &&
  522. M_ShadowType (new) != XmSHADOW_ETCHED_OUT)
  523. {
  524. XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
  525. }
  526. /* Validate title position.
  527. */
  528. if (M_TitlePosition (new) != XmTITLE_TOP &&
  529. M_TitlePosition (new) != XmTITLE_BOTTOM)
  530. {
  531. XmeWarning ((Widget)new, WARN_TITLE_POSITION);
  532. }
  533. /* Validate title alignment.
  534. */
  535. if (M_TitleAlignment (new) != XmALIGNMENT_BEGINNING &&
  536. M_TitleAlignment (new) != XmALIGNMENT_CENTER &&
  537. M_TitleAlignment (new) != XmALIGNMENT_END)
  538. {
  539. XmeWarning ((Widget)new, WARN_TITLE_ALIGNMENT);
  540. }
  541. /* Check width and height.
  542. */
  543. if (M_Width (new) == 0)
  544. {
  545. M_Width (new) = 2 * (M_ShadowThickness (new) +
  546. M_MarginWidth (new));
  547. if (M_Width (new) == 0)
  548. M_Width (new) = 10;
  549. }
  550. if (M_Height (new) == 0)
  551. {
  552. M_Height (new) = 2 * (M_ShadowThickness (new) +
  553. M_MarginHeight (new));
  554. if (M_Height (new) == 0)
  555. M_Height (new) = 10;
  556. }
  557. M_OldWidth (new) = M_Width (new);
  558. M_OldHeight (new) = M_Height (new);
  559. M_OldShadowThickness (new) = M_ShadowThickness (new);
  560. M_WorkArea (new) = NULL;
  561. /* Create title_area unless title explicitly set to null;
  562. * use name if unspecified.
  563. */
  564. if (! M_TitleString (new))
  565. {
  566. M_TitleArea (new) = NULL;
  567. return;
  568. }
  569. if (M_TitleString (new) == XmUNSPECIFIED_STRING && M_Name (new))
  570. {
  571. M_TitleString (new) = XmStringCreateLocalized(M_Name (new));
  572. title_string = M_TitleString (new);
  573. }
  574. ac = 0;
  575. XtSetArg (al[ac], XmNchildType, XmTITLE_AREA); ac++;
  576. XtSetArg (al[ac], XmNmarginWidth, 2); ac++;
  577. XtSetArg (al[ac], XmNmarginHeight, 0); ac++;
  578. XtSetArg (al[ac], XmNshadowThickness, 0); ac++;
  579. XtSetArg (al[ac], XmNhighlightThickness, 0); ac++;
  580. XtSetArg (al[ac], XmNlabelString, M_TitleString (new)); ac++;
  581. if (M_FontList (new))
  582. {
  583. XtSetArg (al[ac], XmNfontList, M_FontList (new));
  584. ac++;
  585. }
  586. title = XmCreateLabelGadget ((Widget)new, "title", al, ac);
  587. M_TitleArea (new) = title;
  588. XtManageChild (title);
  589. if (M_TitleSpacing (new) == UNSPECIFIED_DIMENSION)
  590. M_TitleSpacing (new) =
  591. Max (P_Height (title)/2U, M_ShadowThickness (new));
  592. M_TitleString (new) = XmUNSPECIFIED_STRING;
  593. M_FontList (new) = NULL;
  594. if (title_string != NULL)
  595. XmStringFree (title_string);
  596. }
  597. /*-------------------------------------------------------------
  598. ** Destroy
  599. ** Release resources allocated for widget instance.
  600. */
  601. static void
  602. Destroy(
  603. DtTitleBoxWidget manager )
  604. {
  605. /* Superclass does all the work so far.
  606. */
  607. }
  608. /*-------------------------------------------------------------
  609. ** Resize
  610. ** Update size of children.
  611. */
  612. static void
  613. Resize(
  614. DtTitleBoxWidget manager )
  615. {
  616. Widget title_area = M_TitleArea (manager);
  617. Dimension s_t = M_OldShadowThickness (manager),
  618. w = M_OldWidth (manager),
  619. h = M_OldHeight (manager);
  620. Position y;
  621. /* Clear shadow and save shadow data.
  622. */
  623. if (XtIsRealized ((Widget)manager))
  624. {
  625. _XmClearShadowType ((Widget)manager, w, h, s_t, 0);
  626. if ((M_TitlePosition (manager) == XmTITLE_BOTTOM) &&
  627. (M_Height (manager) > h))
  628. {
  629. y = h - P_Height (title_area);
  630. XClearArea (XtDisplay (manager), XtWindow (manager),
  631. 0, y, M_Width (manager),
  632. M_Height (manager) - y, False);
  633. }
  634. }
  635. M_OldWidth (manager) = M_Width (manager);
  636. M_OldHeight (manager) = M_Height (manager);
  637. M_OldShadowThickness (manager) = M_ShadowThickness (manager);
  638. ConfigureChildren (manager);
  639. /* Draw shadow and title.
  640. */
  641. if (XtIsRealized ((Widget)manager))
  642. Redisplay (manager, NULL, NULL);
  643. }
  644. /*-------------------------------------------------------------
  645. ** Redisplay
  646. ** Redisplay widget.
  647. */
  648. static void
  649. Redisplay(
  650. DtTitleBoxWidget manager,
  651. XEvent *event,
  652. Region region )
  653. {
  654. Widget title_area = M_TitleArea (manager),
  655. work_area = M_WorkArea (manager);
  656. Position title_x = M_X (title_area),
  657. title_y = M_Y (title_area);
  658. Dimension title_width = M_Width (title_area),
  659. title_height = M_Height (title_area);
  660. Display * d = XtDisplay (manager);
  661. Dimension w = M_Width (manager),
  662. h = M_Height (manager),
  663. s_t = M_ShadowThickness (manager);
  664. Position x = 0,
  665. y = title_height / 2 - s_t / 2;
  666. /* Redisplay work area.
  667. */
  668. if (XmIsGadget (work_area) && XtIsManaged (work_area))
  669. {
  670. XtExposeProc expose;
  671. _DtProcessLock();
  672. expose = XtCoreProc(work_area, expose);
  673. _DtProcessUnlock();
  674. (*expose) (work_area, event, region);
  675. }
  676. /* Draw shadow.
  677. */
  678. if (M_ShadowThickness (manager) > 0)
  679. {
  680. h -= y;
  681. if (M_TitlePosition (manager) == XmTITLE_BOTTOM)
  682. y = 0;
  683. XmeDrawShadows(d, XtWindow(manager),
  684. M_TopShadowGC(manager),
  685. M_BottomShadowGC(manager),
  686. x, y, w, h, s_t, M_ShadowType(manager));
  687. }
  688. /* Redisplay title area.
  689. */
  690. if (title_area && XtIsManaged (title_area))
  691. {
  692. XClearArea (d, XtWindow (manager), title_x, title_y,
  693. title_width, title_height, False);
  694. if (XmIsGadget (title_area))
  695. {
  696. XtExposeProc expose;
  697. _DtProcessLock();
  698. expose = XtCoreProc(title_area, expose);
  699. _DtProcessUnlock();
  700. (*expose) (title_area, event, region);
  701. }
  702. }
  703. }
  704. /*-------------------------------------------------------------
  705. ** SetValues
  706. ** Handle changes in resource data.
  707. */
  708. static Boolean
  709. SetValues(
  710. DtTitleBoxWidget current,
  711. DtTitleBoxWidget request,
  712. DtTitleBoxWidget new )
  713. {
  714. Widget title = M_TitleArea (new);
  715. Boolean redisplay_flag = False,
  716. new_title = False,
  717. new_font = False;
  718. Arg al[10]; /* arg list */
  719. int ac; /* arg count */
  720. /* Validate title position.
  721. */
  722. if (M_TitlePosition (new) != M_TitlePosition (current) &&
  723. M_TitlePosition (new) != XmTITLE_TOP &&
  724. M_TitlePosition (new) != XmTITLE_BOTTOM)
  725. {
  726. XmeWarning ((Widget)new, WARN_TITLE_POSITION);
  727. M_TitlePosition (new) = M_TitlePosition (current);
  728. }
  729. /* Validate title alignment.
  730. */
  731. if (M_TitleAlignment (new) != M_TitleAlignment (current) &&
  732. M_TitleAlignment (new) != XmALIGNMENT_BEGINNING &&
  733. M_TitleAlignment (new) != XmALIGNMENT_CENTER &&
  734. M_TitleAlignment (new) != XmALIGNMENT_END)
  735. {
  736. XmeWarning ((Widget)new, WARN_TITLE_ALIGNMENT);
  737. M_TitleAlignment (new) = M_TitleAlignment (current);
  738. }
  739. /* Validate shadow type.
  740. */
  741. if (M_ShadowType (new) != M_ShadowThickness (current) &&
  742. M_ShadowType (new) != XmSHADOW_IN &&
  743. M_ShadowType (new) != XmSHADOW_OUT &&
  744. M_ShadowType (new) != XmSHADOW_ETCHED_IN &&
  745. M_ShadowType (new) != XmSHADOW_ETCHED_OUT)
  746. {
  747. XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
  748. M_ShadowType (new) = M_ShadowThickness (current);
  749. }
  750. /* Check for redisplay; query and update kids if no resize.
  751. */
  752. if (M_MarginWidth (new) != M_MarginWidth (current) ||
  753. M_MarginHeight (new) != M_MarginHeight (current) ||
  754. M_ShadowThickness (new) != M_ShadowThickness (current))
  755. {
  756. redisplay_flag = True;
  757. if (M_Width (new) == M_Width (current) &&
  758. M_Height (new) == M_Height (current))
  759. {
  760. GetSize (new, 0, 0, 0, 0,
  761. &(M_Width (new)), &(M_Height (new)));
  762. ConfigureChildren (new);
  763. }
  764. }
  765. else if (M_TitleSpacing (new) != M_TitleSpacing (current) ||
  766. M_TitlePosition (new) != M_TitlePosition (current) ||
  767. M_TitleAlignment (new) != M_TitleAlignment (current))
  768. {
  769. redisplay_flag = True;
  770. ConfigureChildren (new);
  771. }
  772. else if (M_ShadowType (new) != M_ShadowThickness (current))
  773. {
  774. redisplay_flag = True;
  775. }
  776. /* Update title if string or font changed.
  777. */
  778. ac = 0;
  779. if (M_TitleString (current) != M_TitleString (new))
  780. {
  781. new_title = True;
  782. XtSetArg (al[ac], XmNlabelString, M_TitleString (new)); ac++;
  783. }
  784. if (M_FontList (current) != M_FontList (new))
  785. {
  786. new_font = True;
  787. XtSetArg (al[ac], XmNfontList, M_FontList (new));
  788. ac++;
  789. }
  790. if (ac && title)
  791. {
  792. XtSetValues (title, al, ac);
  793. if (new_title)
  794. M_TitleString (new) = XmUNSPECIFIED_STRING;
  795. if (new_font)
  796. M_FontList (new) = NULL;
  797. redisplay_flag = True;
  798. }
  799. return (redisplay_flag);
  800. }
  801. /*-------------------------------------------------------------
  802. ** QueryGeometry
  803. ** Handle query geometry request.
  804. */
  805. static XtGeometryResult
  806. QueryGeometry(
  807. DtTitleBoxWidget manager,
  808. XtWidgetGeometry *request,
  809. XtWidgetGeometry *reply )
  810. {
  811. Dimension w = M_Width (manager),
  812. h = M_Height (manager),
  813. new_w = 0,
  814. new_h = 0;
  815. Boolean width_req = request->request_mode & CWWidth,
  816. height_req = request->request_mode & CWHeight;
  817. /* Compute preferred size if preferred width or height requested.
  818. */
  819. if (width_req || height_req)
  820. GetSize (manager, 0, 0, 0, 0, &new_w, &new_h);
  821. /* Load reply.
  822. */
  823. reply->request_mode = request->request_mode;
  824. reply->x = request->x;
  825. reply->y = request->y;
  826. reply->width = (width_req) ? new_w : request->width;
  827. reply->height = (height_req) ? new_h : request->height;
  828. reply->border_width = request->border_width;
  829. /* If no change return no; otherwise yes.
  830. */
  831. if ((!width_req || (width_req && w == new_w)) &&
  832. (!height_req || (height_req && h == new_h)))
  833. return (XtGeometryNo);
  834. else
  835. return (XtGeometryYes);
  836. }
  837. /*-------------------------------------------------------------
  838. ** Composite Procs
  839. **-------------------------------------------------------------
  840. */
  841. /*-------------------------------------------------------------
  842. ** GeometryManager
  843. ** Handle geometry request from title area or work area.
  844. */
  845. static XtGeometryResult
  846. GeometryManager(
  847. Widget kid,
  848. XtWidgetGeometry *request,
  849. XtWidgetGeometry *reply )
  850. {
  851. DtTitleBoxWidget manager = (DtTitleBoxWidget) XtParent (kid);
  852. Widget title_area = M_TitleArea (manager);
  853. Dimension ta_w = 0, ta_h = 0, ta_bw = 0,
  854. wa_w = 0, wa_h = 0,
  855. w = M_Width (manager),
  856. h = M_Height (manager);
  857. Boolean query_only = request->request_mode & XtCWQueryOnly,
  858. x_req = request->request_mode & CWX,
  859. y_req = request->request_mode & CWY,
  860. width_req = request->request_mode & CWWidth,
  861. height_req = request->request_mode & CWHeight,
  862. bw_req = request->request_mode & CWBorderWidth,
  863. almost = False;
  864. XtGeometryResult result = XtGeometryYes, parent_result;
  865. XtWidgetGeometry parent_req, parent_reply;
  866. /* Check for width, height, and borderwidth requests.
  867. */
  868. if (!width_req && !height_req)
  869. {
  870. if (x_req || y_req)
  871. return (XtGeometryNo);
  872. else
  873. return (XtGeometryYes);
  874. }
  875. else
  876. {
  877. if (x_req || y_req)
  878. almost = True;
  879. }
  880. /* Compute desired size.
  881. */
  882. if (kid == title_area)
  883. {
  884. ta_w = (width_req) ? request->width : P_Width (kid);
  885. ta_h = (height_req) ? request->height : P_Height (kid);
  886. ta_bw = (bw_req) ? request->border_width : P_BorderWidth (kid);
  887. }
  888. else
  889. {
  890. wa_w = (width_req) ? request->width : P_Width (kid);
  891. wa_h = (height_req) ? request->height : P_Height (kid);
  892. }
  893. GetSize (manager, ta_w, ta_h, wa_w, wa_h, &w, &h);
  894. /* Request change from parent if necessary.
  895. */
  896. if (w != M_Width (manager) || h != M_Height (manager))
  897. {
  898. parent_req.request_mode = CWWidth | CWHeight;
  899. parent_req.width = w;
  900. parent_req.height = h;
  901. if (almost || query_only)
  902. parent_req.request_mode |= XtCWQueryOnly;
  903. parent_result =
  904. XtMakeGeometryRequest ((Widget)manager, &parent_req,
  905. &parent_reply);
  906. if (kid == (Widget) title_area)
  907. parent_result = XtGeometryYes;
  908. }
  909. else
  910. parent_result = XtGeometryYes;
  911. /* Reply to kid based on reply from parent.
  912. */
  913. switch ((int) parent_result)
  914. {
  915. case XtGeometryYes:
  916. if (query_only)
  917. result = XtGeometryYes;
  918. else if (!almost)
  919. {
  920. XtWidgetProc resize;
  921. if (kid == title_area)
  922. XmeConfigureObject (title_area,
  923. title_area->core.x,
  924. title_area->core.y,
  925. ta_w, ta_h, ta_bw);
  926. _DtProcessLock();
  927. resize = XtCoreProc(XtParent(kid), resize);
  928. _DtProcessUnlock();
  929. (*resize) (XtParent (kid));
  930. result = XtGeometryDone;
  931. }
  932. else
  933. {
  934. result = XtGeometryNo;
  935. }
  936. break;
  937. case XtGeometryAlmost:
  938. case XtGeometryNo:
  939. result = XtGeometryNo;
  940. break;
  941. }
  942. return (result);
  943. }
  944. /*-------------------------------------------------------------
  945. ** ChangeManaged
  946. ** Handle change in set of managed children.
  947. */
  948. static void
  949. ChangeManaged(
  950. DtTitleBoxWidget manager )
  951. {
  952. Dimension w = M_Width (manager),
  953. h = M_Height (manager);
  954. /* Compute desired size.
  955. */
  956. GetSize (manager, 0, 0, 0, 0, &w, &h);
  957. /* Try to change size to fit children
  958. */
  959. if (w != M_Width (manager) || h != M_Height (manager))
  960. {
  961. switch (XtMakeResizeRequest ((Widget) manager, w, h, &w, &h))
  962. {
  963. case XtGeometryAlmost:
  964. XtMakeResizeRequest ((Widget) manager, w, h,
  965. NULL, NULL);
  966. case XtGeometryYes:
  967. case XtGeometryNo:
  968. default:
  969. break;
  970. }
  971. }
  972. /* Set positions and sizes of children.
  973. */
  974. ConfigureChildren (manager);
  975. XmeNavigChangeManaged ((Widget)manager);
  976. }
  977. /*-------------------------------------------------------------
  978. ** InsertChild
  979. ** Add a child.
  980. */
  981. static void
  982. InsertChild(
  983. Widget child )
  984. {
  985. DtTitleBoxConstraint constraint = (DtTitleBoxConstraint)
  986. M_TitleBoxConstraint (child);
  987. DtTitleBoxWidget w;
  988. XmManagerWidgetClass mc = (XmManagerWidgetClass)
  989. xmManagerWidgetClass;
  990. XtWidgetProc insert_child;
  991. _DtProcessLock();
  992. insert_child = mc->composite_class.insert_child;
  993. _DtProcessUnlock();
  994. (* insert_child) (child);
  995. w = (DtTitleBoxWidget) XtParent (child);
  996. if (constraint->child_type == XmWORK_AREA)
  997. {
  998. if (! M_WorkArea (w))
  999. {
  1000. M_WorkArea (w) = child;
  1001. }
  1002. }
  1003. else if (constraint->child_type == XmTITLE_AREA)
  1004. {
  1005. if (! M_TitleArea (w))
  1006. {
  1007. M_TitleArea (w) = child;
  1008. }
  1009. }
  1010. }
  1011. /*-------------------------------------------------------------
  1012. ** Constraint Procs
  1013. **-------------------------------------------------------------
  1014. */
  1015. /*-------------------------------------------------------------
  1016. ** ConstraintInitialize
  1017. ** Add a child.
  1018. */
  1019. static void
  1020. ConstraintInitialize(
  1021. Widget request,
  1022. Widget new )
  1023. {
  1024. DtTitleBoxWidget manager = (DtTitleBoxWidget) XtParent (new);
  1025. DtTitleBoxConstraint constraint = M_TitleBoxConstraint (new);
  1026. /* Validate child type.
  1027. */
  1028. if (constraint->child_type != XmWORK_AREA &&
  1029. constraint->child_type != XmTITLE_AREA)
  1030. {
  1031. XmeWarning (new, WARN_CHILD_TYPE);
  1032. if (! M_WorkArea (manager))
  1033. {
  1034. constraint->child_type = XmWORK_AREA;
  1035. }
  1036. else if (! M_TitleArea (manager))
  1037. {
  1038. constraint->child_type = XmTITLE_AREA;
  1039. }
  1040. }
  1041. }
  1042. /*-------------------------------------------------------------
  1043. ** Manager Procs
  1044. **-------------------------------------------------------------
  1045. */
  1046. /* All inherited from superclass.
  1047. */
  1048. /*-------------------------------------------------------------
  1049. ** Public Entry Points
  1050. **-------------------------------------------------------------
  1051. */
  1052. /*-------------------------------------------------------------
  1053. ** _DtCreateTitleBox
  1054. ** Create a new DtTitleBox instance.
  1055. **-------------------------------------------------------------
  1056. */
  1057. Widget
  1058. _DtCreateTitleBox(
  1059. Widget parent,
  1060. char *name,
  1061. ArgList arglist,
  1062. Cardinal argcount )
  1063. {
  1064. return (XtCreateWidget (name, dtTitleBoxWidgetClass,
  1065. parent, arglist, argcount));
  1066. }
  1067. /*-------------------------------------------------------------
  1068. ** _DtTitleBoxGetTitleArea
  1069. ** Return TitleBox title area;
  1070. **-------------------------------------------------------------
  1071. */
  1072. Widget
  1073. _DtTitleBoxGetTitleArea(
  1074. Widget w )
  1075. {
  1076. DtTitleBoxWidget mgr = (DtTitleBoxWidget) w;
  1077. Widget rtn_w = M_TitleArea (mgr);
  1078. return (rtn_w);
  1079. }
  1080. /*-------------------------------------------------------------
  1081. ** _DtTitleBoxGetWorkArea
  1082. ** Return TitleBox work area;
  1083. **-------------------------------------------------------------
  1084. */
  1085. Widget
  1086. _DtTitleBoxGetWorkArea(
  1087. Widget w )
  1088. {
  1089. DtTitleBoxWidget mgr = (DtTitleBoxWidget) w;
  1090. Widget rtn_w = M_WorkArea (mgr);
  1091. return (rtn_w);
  1092. }