Destroy.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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: Destroy.c /main/12 1996/03/18 14:08:16 cde-hal $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Destroy.c
  28. **
  29. ** Project: Cde Help System
  30. **
  31. ** Description: This code frees the information associated with
  32. ** a Display Area.
  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. * system includes
  44. */
  45. #include <stdlib.h>
  46. #include <X11/Xatom.h>
  47. /*
  48. * Canvas Engine
  49. */
  50. #include "CanvasP.h"
  51. /*
  52. * private includes
  53. */
  54. #include "DisplayAreaP.h"
  55. #include "CallbacksI.h"
  56. #include "DestroyI.h"
  57. #include "FontI.h"
  58. #include "GraphicsI.h"
  59. #include "HyperTextI.h"
  60. #include "StringFuncsI.h"
  61. #ifdef NLS16
  62. #endif
  63. /******** Private Function Declarations ********/
  64. /******** End Public Function Declarations ********/
  65. /******************************************************************************
  66. *
  67. * These are the public routines available.
  68. *
  69. *****************************************************************************/
  70. /*********************************************************************
  71. * Function: _DtHelpDisplayAreaClean
  72. *
  73. * _DtHelpDisplayAreaClean deallocates all paragraph, font, and
  74. * graphic information associated with it.
  75. *
  76. *********************************************************************/
  77. void
  78. _DtHelpDisplayAreaClean (XtPointer client_data)
  79. {
  80. int n;
  81. Arg args[5];
  82. Atom xa_primary = XA_PRIMARY;
  83. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  84. /*
  85. * remove the selection if necessary
  86. */
  87. _DtHelpLoseSelectionCB (pDAS->dispWid, &xa_primary);
  88. /*
  89. * clean the canvas
  90. */
  91. if (NULL != pDAS->canvas)
  92. _DtCanvasClean (pDAS->canvas);
  93. /*
  94. * clean the slate
  95. */
  96. if (XtIsRealized (pDAS->dispWid))
  97. XClearArea(XtDisplay(pDAS->dispWid), XtWindow(pDAS->dispWid),
  98. pDAS->decorThickness, pDAS->decorThickness,
  99. pDAS->dispUseWidth, pDAS->dispUseHeight, False);
  100. pDAS->toc_flag &= ~(_DT_HELP_TOC_ON);
  101. /*
  102. * reset any scrollbars that are managed.
  103. */
  104. n = 0;
  105. XtSetArg (args[n], XmNvalue , 0); ++n;
  106. XtSetArg (args[n], XmNsliderSize , 1); ++n;
  107. XtSetArg (args[n], XmNmaximum , 1); ++n;
  108. XtSetArg (args[n], XmNpageIncrement, 1); ++n;
  109. if (pDAS->vertScrollWid && XtIsManaged (pDAS->vertScrollWid))
  110. XtSetValues (pDAS->vertScrollWid, args, n);
  111. if (pDAS->horzScrollWid && XtIsManaged (pDAS->horzScrollWid))
  112. XtSetValues (pDAS->horzScrollWid, args, n);
  113. } /* End _DtHelpDisplayAreaClean */
  114. /*********************************************************************
  115. * Function: _DtHelpDisplayAreaDestroyCB
  116. *
  117. * _DtHelpDisplayAreaDestroyCB deallocates all information
  118. * associated with it.
  119. *
  120. *********************************************************************/
  121. void
  122. _DtHelpDisplayAreaDestroyCB (
  123. Widget w,
  124. XtPointer client_data,
  125. XtPointer call_data)
  126. {
  127. int i;
  128. long strIdx;
  129. XrmName xrmList[_DtHelpFontQuarkNumber];
  130. Display *dpy;
  131. DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
  132. Boolean usedDef = False;
  133. /*
  134. * do the gross cleaning
  135. */
  136. _DtHelpDisplayAreaClean(client_data);
  137. if (NULL != pDAS->canvas)
  138. _DtCanvasDestroy (pDAS->canvas);
  139. dpy = XtDisplay(pDAS->dispWid);
  140. /*
  141. * Free the gc's
  142. */
  143. XFreeGC (dpy, pDAS->normalGC);
  144. XFreeGC (dpy, pDAS->pixmapGC);
  145. XFreeGC (dpy, pDAS->invertGC);
  146. if (pDAS->def_pix != 0 &&
  147. XmDestroyPixmap(XDefaultScreenOfDisplay(dpy), pDAS->def_pix) == False)
  148. XFreePixmap(dpy, pDAS->def_pix);
  149. if (pDAS->context != NULL)
  150. {
  151. _DtGrDestroyContext(pDAS->context);
  152. XtFree((char *) pDAS->context);
  153. }
  154. /*
  155. * destroy the widgets.
  156. */
  157. XtDestroyWidget(pDAS->dispWid);
  158. if (pDAS->horzScrollWid != NULL)
  159. XtDestroyWidget(pDAS->horzScrollWid);
  160. if (pDAS->vertScrollWid != NULL)
  161. XtDestroyWidget(pDAS->vertScrollWid);
  162. /*
  163. * free the special characters
  164. */
  165. if (pDAS->spc_chars != NULL)
  166. free ((char *) pDAS->spc_chars);
  167. /*
  168. * free the font info.
  169. */
  170. _DtHelpGetStringQuarks(xrmList);
  171. if (__DtHelpFontIndexGet(pDAS, xrmList, &strIdx) != 0)
  172. usedDef = True;
  173. if (pDAS->font_info.def_font_db != NULL)
  174. XrmDestroyDatabase(pDAS->font_info.def_font_db);
  175. if (pDAS->font_info.font_idx_db != NULL)
  176. XrmDestroyDatabase(pDAS->font_info.font_idx_db);
  177. if (pDAS->font_info.exact_fonts != NULL)
  178. {
  179. _DtHelpCeFreeStringArray(pDAS->font_info.exact_fonts);
  180. free(pDAS->font_info.exact_idx);
  181. }
  182. if (pDAS->font_info.font_structs != NULL)
  183. {
  184. /*
  185. * if the string index is a positive number, this
  186. * indicates that the string font is a font not
  187. * a font set and it wouldn't be freed in this
  188. * routine.
  189. */
  190. for (i = 0; i < pDAS->font_info.struct_cnt; i++)
  191. {
  192. if (usedDef == True || i != strIdx)
  193. XFreeFont(dpy, pDAS->font_info.font_structs[i]);
  194. }
  195. free(pDAS->font_info.font_structs);
  196. }
  197. if (pDAS->font_info.font_sets != NULL)
  198. {
  199. /*
  200. * if the string index is a negative number, this turns
  201. * it to positive and the tests will succeed.
  202. *
  203. * if the string index was a font not a fontset, then
  204. * this will turn the value negative and the test
  205. * will never succeed.
  206. */
  207. strIdx = (-strIdx) - 1;
  208. for (i = 0; i < pDAS->font_info.set_cnt; i++)
  209. {
  210. if (usedDef == True || i != strIdx)
  211. XFreeFontSet(dpy, pDAS->font_info.font_sets[i]);
  212. }
  213. free(pDAS->font_info.font_sets);
  214. free(pDAS->font_info.fs_metrics);
  215. }
  216. /*
  217. * free the locale dependant information
  218. */
  219. if (NULL != pDAS->cant_begin_chars)
  220. free (pDAS->cant_begin_chars);
  221. if (NULL != pDAS->cant_end_chars)
  222. free (pDAS->cant_end_chars);
  223. /*
  224. * destroy the display area pointer
  225. */
  226. XtFree ((char *) pDAS);
  227. } /* End DtHelpDisplayAreaDestroy */