Resize.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. /* $XConsortium: Resize.c /main/5 1995/10/26 12:31:25 rswiston $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Resize.c
  28. **
  29. ** Project: Display Area Library
  30. **
  31. ** Description: This body of code handles direct resize requests from
  32. ** the GUI.
  33. **
  34. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  35. **
  36. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  37. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  38. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  39. ** (c) Copyright 1993, 1994 Novell, Inc.
  40. **
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. /*
  45. * system includes
  46. */
  47. /*
  48. * private includes
  49. */
  50. #include "Access.h"
  51. #include "DisplayAreaP.h"
  52. #include "CallbacksI.h"
  53. #include "ResizeI.h"
  54. #include "SetListI.h"
  55. #include "XUICreateI.h"
  56. #ifdef NLS16
  57. #endif
  58. /******** Private Function Declarations ********/
  59. /******** End Private Function Declarations ********/
  60. /******** Private Variables ********/
  61. /******** End Private Variables ********/
  62. /*********************************************************************
  63. * Private Functions
  64. *********************************************************************/
  65. /*********************************************************************
  66. * Public Functions
  67. *********************************************************************/
  68. /*********************************************************************
  69. * Function: ResizeDisplayArea
  70. *
  71. * ResizeDisplayArea resizes the Display Area and re-formats the
  72. * text based on a row and column values given.
  73. *
  74. *********************************************************************/
  75. void
  76. _DtHelpResizeDisplayArea (
  77. Widget parent,
  78. XtPointer client_data,
  79. int rows,
  80. int columns )
  81. {
  82. int count = 0;
  83. register int n;
  84. unsigned long char_width;
  85. Arg args[5];
  86. Dimension newWidth;
  87. Dimension newHeight;
  88. Dimension vertWidth = 0;
  89. Dimension horzHeight = 0;
  90. Dimension tstWidth;
  91. Dimension tstHeight;
  92. Dimension oldWidth;
  93. Dimension oldHeight;
  94. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  95. /*
  96. * check the values.
  97. */
  98. if (rows <= 0)
  99. rows = 1;
  100. if (columns <= 0)
  101. columns = 1;
  102. /* Set the size of the text view area to the requested number of columns */
  103. /* and lines. */
  104. char_width = pDAS->charWidth * columns;
  105. newWidth = char_width / 10 + (char_width % 10 ? 1 : 0) +
  106. 2 * (pDAS->decorThickness + pDAS->marginWidth);
  107. newHeight = pDAS->lineHeight * rows + 2 * pDAS->decorThickness;
  108. /*
  109. * get the width and height of the scroll bars.
  110. */
  111. if (pDAS->vertScrollWid)
  112. {
  113. XtSetArg (args[0], XmNwidth , &vertWidth);
  114. XtGetValues (pDAS->vertScrollWid, args, 1);
  115. }
  116. if (pDAS->horzScrollWid)
  117. {
  118. XtSetArg (args[0], XmNheight , &horzHeight);
  119. XtGetValues (pDAS->horzScrollWid, args, 1);
  120. }
  121. /*
  122. * loop a couple of times at most to get the sizing correct.
  123. * This is caused by the fact we can't do a set values on
  124. * the drawn button itself, someone above it is rejecting
  125. * the resize request. So, resize the great-grandparent
  126. * (a couple of times if necessary).
  127. */
  128. do {
  129. /*
  130. * take into consideration the scrollbars.
  131. */
  132. tstWidth = newWidth;
  133. tstHeight = newHeight;
  134. if (pDAS->vertScrollWid &&
  135. _DtHelpIS_AS_NEEDED(pDAS->neededFlags, _DtHelpVERTICAL_SCROLLBAR)
  136. && pDAS->vertIsMapped)
  137. {
  138. if (tstWidth > vertWidth)
  139. tstWidth -= vertWidth;
  140. else
  141. tstWidth = 0;
  142. }
  143. if (pDAS->horzScrollWid &&
  144. _DtHelpIS_AS_NEEDED(pDAS->neededFlags, _DtHelpHORIZONTAL_SCROLLBAR)
  145. && pDAS->horzIsMapped)
  146. {
  147. if (tstHeight > horzHeight)
  148. tstHeight -= horzHeight;
  149. else
  150. tstHeight = 0;
  151. }
  152. if (tstWidth == pDAS->dispWidth && tstHeight == pDAS->dispHeight)
  153. return;
  154. /*
  155. * kludge around the fact that some parent is not letting
  156. * me resize the drawn button. Get the parent's size and
  157. * resize that!
  158. */
  159. n = 0;
  160. XtSetArg(args[n], XmNwidth, &oldWidth); ++n;
  161. XtSetArg(args[n], XmNheight, &oldHeight); ++n;
  162. XtGetValues(parent, args, n);
  163. /*
  164. * calculate its new size
  165. */
  166. oldWidth = oldWidth - pDAS->dispWidth + tstWidth;
  167. oldHeight = oldHeight - pDAS->dispHeight + tstHeight;
  168. /*
  169. * set my parent's size to affect me.
  170. */
  171. n = 0;
  172. XtSetArg(args[n], XmNwidth, oldWidth); ++n;
  173. XtSetArg(args[n], XmNheight, oldHeight); ++n;
  174. XtSetValues(parent, args, n);
  175. } while (count++ < 2);
  176. /*
  177. * check to see if the Set Values on my parent took care of everything.
  178. */
  179. if (pDAS->vertScrollWid &&
  180. _DtHelpIS_AS_NEEDED(pDAS->neededFlags, _DtHelpVERTICAL_SCROLLBAR)
  181. && pDAS->vertIsMapped)
  182. {
  183. if (newWidth > vertWidth)
  184. newWidth -= vertWidth;
  185. else
  186. newWidth = 0;
  187. }
  188. if (pDAS->horzScrollWid &&
  189. _DtHelpIS_AS_NEEDED(pDAS->neededFlags, _DtHelpHORIZONTAL_SCROLLBAR)
  190. && pDAS->horzIsMapped)
  191. {
  192. if (newHeight > horzHeight)
  193. newHeight -= horzHeight;
  194. else
  195. newHeight = 0;
  196. }
  197. if (newWidth == pDAS->dispWidth && newHeight == pDAS->dispHeight)
  198. return;
  199. /*
  200. * clean up
  201. _DtHelpClearSelection (pDAS);
  202. */
  203. /*
  204. * reset the scroll bars and possibly reformat the text.
  205. */
  206. _DtHelpSetScrollBars (client_data, newWidth, newHeight);
  207. if (XtIsRealized (pDAS->dispWid))
  208. _DtHelpCleanAndDrawWholeCanvas(client_data);
  209. } /* End _DtHelpResizeDisplayArea */