SetList.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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: SetList.c /main/16 1996/11/18 16:35:22 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: SetList.c
  28. **
  29. ** Project: Text Graphic Display Library
  30. **
  31. ** Description: This body of code creates the Line and Graphic Tables for
  32. ** a Display Area.
  33. **
  34. **
  35. ****************************************************************************
  36. ************************************<+>*************************************/
  37. /*
  38. * (c) Copyright 1996 Digital Equipment Corporation.
  39. * (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992,
  40. 1993, 1994, 1996 Hewlett-Packard Company.
  41. * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
  42. * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
  43. * (c) Copyright 1993, 1994, 1996 Novell, Inc.
  44. * (c) Copyright 1996 FUJITSU LIMITED.
  45. * (c) Copyright 1996 Hitachi.
  46. */
  47. /*
  48. * system includes
  49. */
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <X11/Xlib.h>
  53. /*
  54. * Canvas Engine
  55. */
  56. #include "CanvasP.h"
  57. #include "CanvasSegP.h"
  58. /*
  59. * private includes
  60. */
  61. #include "Access.h"
  62. #include "CleanUpI.h"
  63. #include "DisplayAreaP.h"
  64. #include "CallbacksI.h"
  65. #include "FontAttrI.h"
  66. #include "FormatI.h"
  67. #include "SetListI.h"
  68. #include "XInterfaceI.h"
  69. #include "XUICreateI.h"
  70. /******** Private Function Declarations ********/
  71. /******** End Public Function Declarations ********/
  72. /******************************************************************************
  73. *
  74. * Private defines and variables
  75. *
  76. *****************************************************************************/
  77. #define GROW_SIZE 10
  78. #define ALL_LINES -1
  79. /******************************************************************************
  80. *
  81. * Private Macros
  82. *
  83. *****************************************************************************/
  84. #define NeedVertScrollbar(x) \
  85. _DtHelpIS_AS_NEEDED((x)->neededFlags,_DtHelpVERTICAL_SCROLLBAR)
  86. #define NeedHorzScrollbar(x) \
  87. _DtHelpIS_AS_NEEDED((x)->neededFlags,_DtHelpHORIZONTAL_SCROLLBAR)
  88. /******************************************************************************
  89. *
  90. * Private Functions
  91. *
  92. *****************************************************************************/
  93. static void
  94. SetMaxPositions (
  95. DtHelpDispAreaStruct *pDAS,
  96. _DtCvUnit max_x,
  97. _DtCvUnit max_y)
  98. {
  99. pDAS->maxX = max_x;
  100. pDAS->maxYpos = max_y + pDAS->marginHeight;
  101. }
  102. /******************************************************************************
  103. *
  104. * Semi Public Functions - these routines called by other modules within
  105. * the library.
  106. *
  107. *****************************************************************************/
  108. /******************************************************************************
  109. * Function: _DtHelpSetScrollBars
  110. *
  111. * Sets/Resets the vertical scroll bar values.
  112. *****************************************************************************/
  113. enum DoSomething { DoNothing, DoManage, DoUnmanage };
  114. Boolean
  115. _DtHelpSetScrollBars (
  116. XtPointer client_data,
  117. Dimension new_width,
  118. Dimension new_height)
  119. {
  120. int n = 0;
  121. int dispN = 0;
  122. int changeWidth = 0;
  123. int changeHeight = 0;
  124. int oldMaxYpos;
  125. int slideSize;
  126. int maximum;
  127. int pageInc;
  128. int oldScrollPercent = 10000;
  129. _DtCvUnit ret_width;
  130. _DtCvUnit ret_height;
  131. Arg dispArgs[10];
  132. Arg args[10];
  133. Dimension marginWidth;
  134. Dimension marginHeight;
  135. Dimension horzHeight;
  136. Dimension vertWidth;
  137. Dimension oldHeight;
  138. Dimension oldWidth;
  139. XRectangle rectangle[1];
  140. enum DoSomething doVert = DoNothing;
  141. enum DoSomething doHorz = DoNothing;
  142. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  143. /*
  144. * remember the old first line.
  145. */
  146. oldMaxYpos = pDAS->maxYpos;
  147. if (pDAS->firstVisible && pDAS->maxYpos)
  148. oldScrollPercent = pDAS->firstVisible * 10000 / pDAS->maxYpos;
  149. /*
  150. * get the width and height of the scroll bars.
  151. */
  152. if (pDAS->vertScrollWid)
  153. {
  154. XtSetArg (args[0], XmNwidth , &vertWidth);
  155. XtGetValues (pDAS->vertScrollWid, args, 1);
  156. }
  157. if (pDAS->horzScrollWid)
  158. {
  159. XtSetArg (args[0], XmNheight , &horzHeight);
  160. XtGetValues (pDAS->horzScrollWid, args, 1);
  161. }
  162. /*
  163. * remember our old width and height
  164. */
  165. oldWidth = pDAS->dispWidth;
  166. oldHeight = pDAS->dispHeight;
  167. /*
  168. * Settle the sizing issue before we remap the scroll bars.
  169. */
  170. do
  171. {
  172. /*
  173. * set the height.
  174. */
  175. if (new_height != pDAS->dispHeight)
  176. {
  177. pDAS->dispHeight = new_height;
  178. pDAS->dispUseHeight = new_height - 2 * pDAS->decorThickness;
  179. if (((int) new_height) < 2 * ((int) pDAS->decorThickness))
  180. pDAS->dispUseHeight = 0;
  181. pDAS->visibleCount = ((int) pDAS->dispUseHeight) /
  182. pDAS->lineHeight;
  183. if (pDAS->visibleCount < 0)
  184. pDAS->visibleCount = 0;
  185. }
  186. /*
  187. * check to see if we've changed width
  188. */
  189. if (new_width != pDAS->dispWidth)
  190. {
  191. /*
  192. * set the new width
  193. */
  194. pDAS->dispWidth = new_width;
  195. pDAS->dispUseWidth = new_width - 2 * pDAS->decorThickness;
  196. if (((int)new_width) < 2 * ((int) pDAS->decorThickness))
  197. pDAS->dispUseWidth = 0;
  198. /*
  199. * re-layout the information.
  200. */
  201. if (_DtCvSTATUS_OK ==
  202. _DtCanvasResize(pDAS->canvas, _DtCvFALSE,
  203. &ret_width, &ret_height))
  204. SetMaxPositions (pDAS, ret_width, ret_height);
  205. }
  206. /*
  207. * Check to see if we have a vertical scrollbar and whether it
  208. * is as_needed. If static, it is always mapped.
  209. */
  210. if (NULL != pDAS->vertScrollWid && NeedVertScrollbar(pDAS))
  211. {
  212. /*
  213. * will the information fit on one page?
  214. */
  215. if (pDAS->maxYpos <= ((int) pDAS->dispUseHeight))
  216. {
  217. /*
  218. * If the window has not already been 'stretched' by
  219. * the width of the scrollbar and if the scrollbar is
  220. * mapped, grow the window width.
  221. */
  222. if (0 == changeWidth && pDAS->vertIsMapped)
  223. {
  224. /*
  225. * set the flag to indicate that the window width
  226. * has grown. This can occur only if the window
  227. * has its vertical scrollbar already mapped.
  228. */
  229. changeWidth = 1;
  230. new_width += vertWidth;
  231. }
  232. /*
  233. * Else check to see if the window has been shrunk.
  234. * If so, then stretch it back out to its original
  235. * width.
  236. *
  237. * This can occur only if
  238. * a) The vertical scrollbar is not mapped.
  239. * b) The previous pass through this code indicates
  240. * that the window could not hold the length of
  241. * the information, and therefore calculations and
  242. * flags were set to map the vertical scrollbar.
  243. * But a _DtCanvasResize() now indicates that a
  244. * vertical scrollbar is not needed. So we don't
  245. * need the vertical scrollbar and have to nuliify
  246. * the calculation to include it.
  247. */
  248. else if (-1 == changeWidth)
  249. {
  250. changeWidth = 0;
  251. new_width += vertWidth;
  252. }
  253. }
  254. /*
  255. * The information will not fit on one page.
  256. */
  257. else
  258. {
  259. /*
  260. * If the window has not already been shrunk to
  261. * accomidate the vertical scrollbar (and the scrollbar
  262. * is not already mapped) then set the flags and
  263. * shrink the width.
  264. */
  265. if (False == pDAS->vertIsMapped && 0 == changeWidth)
  266. {
  267. /*
  268. * set the flag to indicate that the window width
  269. * has shrunk (and that consequently, the vertical
  270. * scrollbar is not mapped).
  271. */
  272. changeWidth = -1;
  273. if (new_width > vertWidth)
  274. new_width -= vertWidth;
  275. else
  276. new_width = 0;
  277. }
  278. /*
  279. * Else check to see if the window has been streched.
  280. * If so, then shrink it back out to its original
  281. * width.
  282. *
  283. * This can occur only if
  284. * a) The vertical scrollbar is mapped.
  285. * b) The previous pass through this code indicates
  286. * that the window could hold the length of
  287. * the information, and therefore calculations and
  288. * flags were set to unmap the vertical scrollbar.
  289. * But a _DtCanvasResize() now indicates that a
  290. * vertical scrollbar is needed. So we need
  291. * the vertical scrollbar and have to nuliify
  292. * the calculation to eliminate it.
  293. */
  294. else if (1 == changeWidth)
  295. {
  296. changeWidth = 0;
  297. new_width -= vertWidth;
  298. }
  299. }
  300. }
  301. /*
  302. * Check to see if we have a horizontal scrollbar and whether it
  303. * is as_needed. If static, it is always mapped.
  304. */
  305. if (NULL != pDAS->horzScrollWid && NeedHorzScrollbar(pDAS))
  306. {
  307. /*
  308. * will the information fit within the right border?
  309. */
  310. if (pDAS->maxX <= ((int) pDAS->dispUseWidth))
  311. {
  312. /*
  313. * If the window has not already been 'stretched' by
  314. * the height of the scrollbar and if the scrollbar is
  315. * mapped, grow the window.
  316. */
  317. if (0 == changeHeight && pDAS->horzIsMapped)
  318. {
  319. /*
  320. * set the flag to indicate that the window has
  321. * grown. This can occur only if the window has
  322. * its horizontal scrollbar already mapped.
  323. */
  324. changeHeight = 1;
  325. new_height += horzHeight;
  326. }
  327. /*
  328. * Else check to see if the window has been shrunk.
  329. * If so, stretch it back to its original height.
  330. *
  331. * This can occur only if
  332. * a) The horizontal scrollbar is not mapped.
  333. * b) The previous pass through the code indicated
  334. * that the information exceeded the right border
  335. * and therefore calculations and flags were set
  336. * to map the horizontal scrollbar. But a
  337. * _DtCanvasResize() now indicates that the
  338. * horizontal scrollbar is not needed. So we
  339. * have to nullify the calculations and flags
  340. * set to include it.
  341. */
  342. else if (-1 == changeHeight)
  343. {
  344. changeHeight = 0;
  345. new_height += horzHeight;
  346. }
  347. }
  348. /*
  349. * The information exceeds the right border of the window.
  350. */
  351. else
  352. {
  353. /*
  354. * If the window has no already been shrunk to
  355. * accomidate the horizontal scrollbar (and the
  356. * scrollbar is not already mapped), then set the
  357. * flags and shrink the height.
  358. */
  359. if (False == pDAS->horzIsMapped && 0 == changeHeight)
  360. {
  361. /*
  362. * set the flag to indicate that the window height
  363. * has shrunk (and that the scrollbar needs mapping).
  364. */
  365. changeHeight = -1;
  366. if (new_height > horzHeight)
  367. new_height -= horzHeight;
  368. else
  369. new_height = 0;
  370. }
  371. /*
  372. * Else check to see if the window has been streched.
  373. * If so, then shrink it back out to its original
  374. * height.
  375. *
  376. * This can occur only if
  377. * a) The horizontal scrollbar is mapped.
  378. * b) The previous pass through the code indicated
  379. * that the information did not exceeded the right
  380. * border and therefore calculations and flags were
  381. * set to unmap the horizontal scrollbar. But a
  382. * _DtCanvasResize() now indicates that the
  383. * horizontal scrollbar is needed. So we
  384. * have to nullify the calculations and flags
  385. * set to exclude it.
  386. */
  387. else if (1 == changeHeight)
  388. {
  389. changeHeight = 0;
  390. new_height -= horzHeight;
  391. }
  392. }
  393. }
  394. } while (new_height != pDAS->dispHeight || new_width != pDAS->dispWidth);
  395. /*
  396. * reset the first visible line, if needed.
  397. */
  398. if (oldScrollPercent != 10000 && pDAS->maxYpos != oldMaxYpos)
  399. pDAS->firstVisible = pDAS->maxYpos * oldScrollPercent / 10000;
  400. if (pDAS->firstVisible + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  401. pDAS->firstVisible = pDAS->maxYpos - pDAS->dispUseHeight;
  402. if (pDAS->firstVisible < 0)
  403. pDAS->firstVisible = 0;
  404. /*
  405. * Reset the virtual X value, if needed
  406. */
  407. if (pDAS->virtualX &&
  408. (pDAS->maxX - pDAS->virtualX < ((int) pDAS->dispUseWidth)))
  409. {
  410. pDAS->virtualX = pDAS->maxX - pDAS->dispUseWidth;
  411. if (pDAS->virtualX < 0)
  412. pDAS->virtualX = 0;
  413. }
  414. /*
  415. * If I've changed my size, I've got to change my clip masks.
  416. */
  417. if (oldWidth != pDAS->dispWidth || oldHeight != pDAS->dispHeight)
  418. {
  419. /*
  420. * If the display area hasn't been realized, the resetting of
  421. * the bottom right corner offsets will not cause a resize
  422. * event to occur. Rather the overall window will grow by
  423. * the width or height of the scroll bar and not cause the
  424. * display area to shrink. Therefore when the exposure event
  425. * is called the width or height will be not be equal to what
  426. * I think it should be causing the code to believe a resize
  427. * is in process. The short of the matter is that the exposure
  428. * will not happen and we end up with a blank window.
  429. *
  430. * So for this case, resize the display area to what we think it
  431. * should be and the exposure event will then happen.
  432. if (!XtIsRealized (pDAS->dispWid))
  433. */
  434. {
  435. XtSetArg(dispArgs[dispN], XmNwidth, pDAS->dispWidth); ++dispN;
  436. XtSetArg(dispArgs[dispN], XmNheight, pDAS->dispHeight); ++dispN;
  437. }
  438. rectangle[0].x = pDAS->decorThickness;
  439. rectangle[0].y = pDAS->decorThickness;
  440. rectangle[0].width = pDAS->dispUseWidth;
  441. rectangle[0].height = pDAS->dispUseHeight;
  442. XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->normalGC, 0, 0,
  443. rectangle, 1, Unsorted);
  444. XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->invertGC, 0, 0,
  445. rectangle, 1, Unsorted);
  446. if (pDAS->resizeCall)
  447. (*(pDAS->resizeCall)) (pDAS->clientData);
  448. }
  449. /*
  450. * Has the width changed? If so, then we are mapping or unmapping
  451. * the vertical scrollbar.
  452. */
  453. if (-1 == changeWidth)
  454. {
  455. /*
  456. * manage the scrollbar, the window has shrunk.
  457. */
  458. doVert = DoManage;
  459. XtSetArg(dispArgs[dispN], XmNrightAttachment, XmATTACH_WIDGET);
  460. ++dispN;
  461. XtSetArg(dispArgs[dispN], XmNrightWidget, pDAS->vertScrollWid);
  462. ++dispN;
  463. }
  464. else if (1 == changeWidth)
  465. {
  466. /*
  467. * unmanage the scrollbar, the window has grown.
  468. */
  469. doVert = DoUnmanage;
  470. XtSetArg(dispArgs[dispN], XmNrightAttachment, XmATTACH_FORM);
  471. ++dispN;
  472. }
  473. /*
  474. * Has the height changed? If so, then we are mapping or unmapping
  475. * the horizontal scrollbar.
  476. */
  477. if (-1 == changeHeight)
  478. {
  479. /*
  480. * manage the scrollbar, the window has shrunk.
  481. */
  482. doHorz = DoManage;
  483. XtSetArg(dispArgs[dispN], XmNbottomAttachment,XmATTACH_WIDGET);
  484. ++dispN;
  485. XtSetArg(dispArgs[dispN], XmNbottomWidget,pDAS->horzScrollWid);
  486. ++dispN;
  487. }
  488. else if (1 == changeHeight)
  489. {
  490. /*
  491. * unmanage the scrollbar, the window has grown.
  492. */
  493. doHorz = DoUnmanage;
  494. XtSetArg(dispArgs[dispN], XmNbottomAttachment, XmATTACH_FORM);
  495. ++dispN;
  496. }
  497. /*
  498. * get the margins, widths and height.
  499. */
  500. XtSetArg (args[0], XmNmarginWidth , &marginWidth);
  501. XtSetArg (args[1], XmNmarginHeight, &marginHeight);
  502. XtGetValues (XtParent (pDAS->dispWid), args, 2);
  503. /*
  504. * have to map the scroll bars before the drawn button can be
  505. * attached to them and can't unmap the scroll bars until
  506. * the drawn button has been unattached from them. But we
  507. * want to do the re-attachments all at once to minimize the
  508. * resizing.
  509. */
  510. if (doHorz == DoManage)
  511. {
  512. if (!XtIsRealized(pDAS->horzScrollWid))
  513. XtSetMappedWhenManaged (pDAS->horzScrollWid, True);
  514. else
  515. XtMapWidget (pDAS->horzScrollWid);
  516. pDAS->horzIsMapped = True;
  517. }
  518. if (doVert == DoManage)
  519. {
  520. if (!XtIsRealized(pDAS->vertScrollWid))
  521. XtSetMappedWhenManaged (pDAS->vertScrollWid, True);
  522. else
  523. XtMapWidget (pDAS->vertScrollWid);
  524. pDAS->vertIsMapped = True;
  525. }
  526. if (pDAS->vertScrollWid && pDAS->vertIsMapped && doVert != DoUnmanage)
  527. {
  528. if (pDAS->horzScrollWid && pDAS->horzIsMapped && doHorz != DoUnmanage)
  529. XtSetArg(args[0], XmNbottomOffset, (marginHeight + horzHeight));
  530. else
  531. XtSetArg(args[0], XmNbottomOffset, marginHeight);
  532. n = 1;
  533. /*
  534. * set the slider size.
  535. */
  536. slideSize = pDAS->dispUseHeight;
  537. if (slideSize < 1)
  538. slideSize = 1;
  539. /*
  540. * determine the maximum size
  541. */
  542. maximum = pDAS->maxYpos;
  543. if (maximum < slideSize)
  544. maximum = slideSize;
  545. if (maximum < 1)
  546. maximum = 1;
  547. /*
  548. * determine the page increment.
  549. */
  550. pageInc = 1;
  551. if (((int)pDAS->dispUseHeight) - pDAS->lineHeight > 2)
  552. pageInc = pDAS->dispUseHeight - pDAS->lineHeight;
  553. XtSetArg (args[n], XmNvalue , pDAS->firstVisible); ++n;
  554. XtSetArg (args[n], XmNsliderSize , slideSize); ++n;
  555. XtSetArg (args[n], XmNmaximum , maximum); ++n;
  556. XtSetArg (args[n], XmNpageIncrement, pageInc); ++n;
  557. XtSetValues (pDAS->vertScrollWid, args, n);
  558. }
  559. if (pDAS->horzScrollWid && pDAS->horzIsMapped && doHorz != DoUnmanage)
  560. {
  561. if (pDAS->vertScrollWid && pDAS->vertIsMapped && doVert != DoUnmanage)
  562. XtSetArg(args[0], XmNrightOffset, (marginWidth + vertWidth));
  563. else
  564. XtSetArg(args[0], XmNrightOffset, marginWidth);
  565. n = 1;
  566. /*
  567. * determine the slider size.
  568. */
  569. slideSize = pDAS->dispUseWidth - 1;
  570. if (slideSize < 1)
  571. slideSize = 1;
  572. /*
  573. * determine the maximum size
  574. */
  575. maximum = slideSize;
  576. if (maximum < pDAS->maxX)
  577. maximum = pDAS->maxX - 1;
  578. if (maximum < 1)
  579. maximum = 1;
  580. /*
  581. * determine the page increment.
  582. */
  583. pageInc = 1;
  584. if (((int) pDAS->dispUseWidth) > 2)
  585. pageInc = pDAS->dispUseWidth - 1;
  586. XtSetArg (args[n], XmNvalue , pDAS->virtualX); n++;
  587. XtSetArg (args[n], XmNsliderSize , slideSize); n++;
  588. XtSetArg (args[n], XmNmaximum , maximum); n++;
  589. XtSetArg (args[n], XmNpageIncrement, pageInc); ++n;
  590. XtSetValues (pDAS->horzScrollWid, args, n);
  591. }
  592. /*
  593. * set the display area args
  594. */
  595. if (dispN)
  596. XtSetValues (pDAS->dispWid, dispArgs, dispN);
  597. /*
  598. * unmap those we don't want.
  599. */
  600. if (doHorz == DoUnmanage)
  601. {
  602. if (!XtIsRealized(pDAS->horzScrollWid))
  603. XtSetMappedWhenManaged (pDAS->horzScrollWid, False);
  604. else
  605. XtUnmapWidget (pDAS->horzScrollWid);
  606. pDAS->horzIsMapped = False;
  607. }
  608. if (doVert == DoUnmanage)
  609. {
  610. if (!XtIsRealized(pDAS->vertScrollWid))
  611. XtSetMappedWhenManaged (pDAS->vertScrollWid, False);
  612. else
  613. XtUnmapWidget (pDAS->vertScrollWid);
  614. pDAS->vertIsMapped = False;
  615. }
  616. /*
  617. * return whether or not we generated a resize (and hence an expose
  618. * event) by resizing the display area.
  619. */
  620. return (dispN ? True : False);
  621. } /* End _DtHelpSetScrollBars */
  622. /******************************************************************************
  623. *
  624. * Public Functions - those an application developer can call.
  625. *
  626. *****************************************************************************/
  627. /*********************************************************************
  628. * Function: SetList
  629. *
  630. * SetList creates a Text Graphic area with the appropriate scroll bars.
  631. *
  632. *********************************************************************/
  633. void
  634. _DtHelpDisplayAreaSetList (
  635. XtPointer client_data,
  636. XtPointer topic_handle,
  637. Boolean append_flag,
  638. int scroll_percent)
  639. {
  640. _DtCvUnit width;
  641. _DtCvUnit height;
  642. _DtCvUnit scrollY;
  643. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  644. /*
  645. * clear the selection
  646. */
  647. _DtHelpClearSelection (client_data);
  648. /*
  649. * If there is anything to do
  650. */
  651. _DtCanvasSetTopic (pDAS->canvas, (_DtCvTopicPtr) topic_handle,
  652. pDAS->honor_size,
  653. &width, &height, &scrollY);
  654. /*
  655. * free the old topic and remember the new
  656. */
  657. _DtHelpDestroyTopicData(pDAS->lst_topic, _DtHelpDADestroyRegion,
  658. (_DtCvPointer) pDAS);
  659. pDAS->lst_topic = (_DtCvTopicPtr) topic_handle;
  660. /*
  661. * do we want to scroll?
  662. */
  663. if (scroll_percent != -1)
  664. scrollY = scroll_percent * height / 1000;
  665. /*
  666. * Reset the scroll bars and perhaps do an expose.
  667. */
  668. SetMaxPositions (pDAS, width, height);
  669. pDAS->firstVisible = scrollY;
  670. if (pDAS->firstVisible + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  671. pDAS->firstVisible = pDAS->maxYpos - pDAS->dispUseHeight;
  672. if (pDAS->firstVisible < 0)
  673. pDAS->firstVisible = 0;
  674. (void) _DtHelpSetScrollBars (client_data, pDAS->dispWidth, pDAS->dispHeight);
  675. if (XtIsRealized (pDAS->dispWid))
  676. _DtHelpCleanAndDrawWholeCanvas(client_data);
  677. } /* End _DtHelpDisplayAreaSetList */
  678. /*****************************************************************************
  679. * Function: void _DtHelpDisplayAreaDimensionsReturn (DtHelpDispAreaStruct *pDAS,
  680. * int *ret_width, int *ret_height)
  681. *
  682. * Parameters pDAS Specifies the Display Area.
  683. * ret_rows Returns the number of rows in
  684. * the Display Area.
  685. * ret_columns Returns the number of columns in
  686. * the Display Area.
  687. *
  688. * Returns: nothing
  689. *
  690. * Purpose: Allows access to the height and width of a Display Area.
  691. *
  692. *****************************************************************************/
  693. void
  694. _DtHelpDisplayAreaDimensionsReturn (
  695. XtPointer client_data,
  696. short *ret_rows,
  697. short *ret_columns )
  698. {
  699. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  700. *ret_rows = ((int)pDAS->dispUseHeight) / pDAS->lineHeight;
  701. *ret_columns = ((int) pDAS->dispUseWidth) / (pDAS->charWidth / 10);
  702. } /* End _DtHelpDisplayAreaDimensionsReturn */
  703. /*****************************************************************************
  704. * Function: int _DtHelpGetScrollbarValue (DtHelpDispAreaStruct *pDAS)
  705. *
  706. * Parameters pDAS Specifies the Display Area.
  707. *
  708. * Returns: a value from -1 to 100.
  709. * -1 means the vertical scrollbar was not created when
  710. * the display area was created.
  711. * 0 to 100 is the percentage the vertical scroll bar is
  712. * scrolled displaying the current topic.
  713. *
  714. * Purpose: Allows the system to query the location of the scrollbar
  715. * and remember for smart-backtracking.
  716. *
  717. *****************************************************************************/
  718. int
  719. _DtHelpGetScrollbarValue (XtPointer client_data)
  720. {
  721. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  722. int percent = -1;
  723. if (pDAS->vertScrollWid != NULL)
  724. {
  725. percent = 0;
  726. if (pDAS->firstVisible && pDAS->maxYpos)
  727. percent = (pDAS->firstVisible * 1000) / pDAS->maxYpos;
  728. }
  729. return percent;
  730. } /* End _DtHelpGetScrollbarValue */
  731. /*****************************************************************************
  732. * Function: int _DtHelpUpdatePath (DtHelpDispAreaStruct *pDAS,
  733. *
  734. * Parameters pDAS Specifies the Display Area.
  735. *
  736. * Returns: a value from -1 to 100.
  737. * -1 means the vertical scrollbar was not created when
  738. * the display area was created.
  739. * 0 to 100 is the percentage the vertical scroll bar is
  740. * scrolled displaying the current topic.
  741. *
  742. * Purpose: Allows the system to query the location of the scrollbar
  743. * and remember for smart-backtracking.
  744. *
  745. *****************************************************************************/
  746. int
  747. _DtHelpUpdatePath (
  748. DtHelpDispAreaStruct *pDAS,
  749. _DtHelpVolumeHdl volume_handle,
  750. char *loc_id)
  751. {
  752. int result;
  753. char *realId;
  754. _DtCvUnit width;
  755. _DtCvUnit height;
  756. _DtCvUnit tocY;
  757. _DtCvUnit tocHeight;
  758. XtPointer topic_handle;
  759. /*
  760. * turn off the toc marker
  761. */
  762. _DtHelpDATocMarker(pDAS, False);
  763. (void) _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_OFF, False,
  764. ((_DtCvValue) XtIsRealized(pDAS->dispWid)),
  765. NULL, NULL, NULL, NULL, NULL);
  766. /*
  767. * now create and set the topic
  768. */
  769. result = _DtHelpFormatToc(pDAS,volume_handle,loc_id,&realId,&topic_handle);
  770. if (-1 == result)
  771. return -1;
  772. _DtCanvasSetTopic (pDAS->canvas, (_DtCvTopicPtr) topic_handle,
  773. pDAS->honor_size,
  774. &width, &height, NULL);
  775. /*
  776. * free the old topic and remember the new
  777. */
  778. _DtHelpDestroyTopicData(pDAS->lst_topic, _DtHelpDADestroyRegion,
  779. (_DtCvPointer) pDAS);
  780. pDAS->lst_topic = (_DtCvTopicPtr) topic_handle;
  781. /*
  782. * Reset the scroll bars and perhaps do an expose.
  783. */
  784. SetMaxPositions (pDAS, width, height);
  785. /*
  786. * now turn the traversal on - but only if there is a path in
  787. * the TOC.
  788. */
  789. if (1 != result)
  790. {
  791. (void) _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ID, False,
  792. ((_DtCvStatus) XtIsRealized(pDAS->dispWid)), realId,
  793. NULL, &(pDAS->toc_y), &(pDAS->toc_base), &(pDAS->toc_height));
  794. /*
  795. * figure out where the first line should be...
  796. */
  797. tocY = pDAS->toc_y - pDAS->lineThickness;
  798. tocHeight = pDAS->toc_height + (2 * pDAS->lineThickness);
  799. if (tocY < pDAS->firstVisible ||
  800. tocY + tocHeight > pDAS->firstVisible + ((int)pDAS->dispUseHeight))
  801. {
  802. pDAS->firstVisible = tocY;
  803. if (pDAS->firstVisible + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
  804. pDAS->firstVisible = pDAS->maxYpos - pDAS->dispUseHeight;
  805. if (pDAS->firstVisible < 0)
  806. pDAS->firstVisible = 0;
  807. }
  808. }
  809. /*
  810. * Reset the scroll bars and perhaps do an expose.
  811. */
  812. (void) _DtHelpSetScrollBars((XtPointer) pDAS, pDAS->dispWidth, pDAS->dispHeight);
  813. if (XtIsRealized (pDAS->dispWid))
  814. _DtHelpCleanAndDrawWholeCanvas((XtPointer) pDAS);
  815. if (1 != result)
  816. _DtHelpDATocMarker((XtPointer) pDAS, True);
  817. return 0;
  818. } /* End _DtHelpUpdatePath */
  819. /*****************************************************************************
  820. * Function: Widget _DtHelpDisplayAreaWidget ();
  821. *
  822. * Parameters:
  823. * client_data Specifies the display area pointer.
  824. *
  825. * Returns: the widget associated with the display area.
  826. *
  827. * Purpose:
  828. *
  829. *****************************************************************************/
  830. Widget
  831. _DtHelpDisplayAreaWidget (
  832. XtPointer client_data)
  833. {
  834. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  835. return (pDAS->dispWid);
  836. }
  837. /*****************************************************************************
  838. * Function: XtPointer _DtHelpDisplayAreaData ();
  839. *
  840. * Parameters:
  841. * client_data Specifies the display area pointer.
  842. *
  843. * Returns: the client data associated with the display area.
  844. *
  845. * Purpose:
  846. *
  847. *****************************************************************************/
  848. XtPointer
  849. _DtHelpDisplayAreaData (
  850. XtPointer client_data)
  851. {
  852. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  853. return (pDAS->clientData);
  854. }