1 /* $XConsortium: Destroy.c /main/12 1996/03/18 14:08:16 cde-hal $ */
2 /************************************<+>*************************************
3 ****************************************************************************
7 ** Project: Cde Help System
9 ** Description: This code frees the information associated with
12 ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
14 ** (c) Copyright 1993, 1994 Hewlett-Packard Company
15 ** (c) Copyright 1993, 1994 International Business Machines Corp.
16 ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
17 ** (c) Copyright 1993, 1994 Novell, Inc.
18 ****************************************************************************
19 ************************************<+>*************************************/
25 #include <X11/Xatom.h>
35 #include "DisplayAreaP.h"
36 #include "CallbacksI.h"
39 #include "GraphicsI.h"
40 #include "HyperTextI.h"
41 #include "StringFuncsI.h"
46 /******** Private Function Declarations ********/
47 /******** End Public Function Declarations ********/
49 /******************************************************************************
51 * These are the public routines available.
53 *****************************************************************************/
54 /*********************************************************************
55 * Function: _DtHelpDisplayAreaClean
57 * _DtHelpDisplayAreaClean deallocates all paragraph, font, and
58 * graphic information associated with it.
60 *********************************************************************/
62 _DtHelpDisplayAreaClean (XtPointer client_data)
66 Atom xa_primary = XA_PRIMARY;
67 DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
70 * remove the selection if necessary
72 _DtHelpLoseSelectionCB (pDAS->dispWid, &xa_primary);
77 if (NULL != pDAS->canvas)
78 _DtCanvasClean (pDAS->canvas);
83 if (XtIsRealized (pDAS->dispWid))
84 XClearArea(XtDisplay(pDAS->dispWid), XtWindow(pDAS->dispWid),
85 pDAS->decorThickness, pDAS->decorThickness,
86 pDAS->dispUseWidth, pDAS->dispUseHeight, False);
88 pDAS->toc_flag &= ~(_DT_HELP_TOC_ON);
91 * reset any scrollbars that are managed.
94 XtSetArg (args[n], XmNvalue , 0); ++n;
95 XtSetArg (args[n], XmNsliderSize , 1); ++n;
96 XtSetArg (args[n], XmNmaximum , 1); ++n;
97 XtSetArg (args[n], XmNpageIncrement, 1); ++n;
99 if (pDAS->vertScrollWid && XtIsManaged (pDAS->vertScrollWid))
100 XtSetValues (pDAS->vertScrollWid, args, n);
102 if (pDAS->horzScrollWid && XtIsManaged (pDAS->horzScrollWid))
103 XtSetValues (pDAS->horzScrollWid, args, n);
105 } /* End _DtHelpDisplayAreaClean */
107 /*********************************************************************
108 * Function: _DtHelpDisplayAreaDestroyCB
110 * _DtHelpDisplayAreaDestroyCB deallocates all information
111 * associated with it.
113 *********************************************************************/
115 _DtHelpDisplayAreaDestroyCB (
117 XtPointer client_data,
122 XrmName xrmList[_DtHelpFontQuarkNumber];
124 DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
125 Boolean usedDef = False;
128 * do the gross cleaning
130 _DtHelpDisplayAreaClean(client_data);
132 if (NULL != pDAS->canvas)
133 _DtCanvasDestroy (pDAS->canvas);
135 dpy = XtDisplay(pDAS->dispWid);
139 XFreeGC (dpy, pDAS->normalGC);
140 XFreeGC (dpy, pDAS->pixmapGC);
141 XFreeGC (dpy, pDAS->invertGC);
142 if (pDAS->def_pix != NULL &&
143 XmDestroyPixmap(XDefaultScreenOfDisplay(dpy), pDAS->def_pix) == False)
144 XFreePixmap(dpy, pDAS->def_pix);
145 if (pDAS->context != NULL)
147 _DtGrDestroyContext(pDAS->context);
148 XtFree((char *) pDAS->context);
152 * destroy the widgets.
154 XtDestroyWidget(pDAS->dispWid);
156 if (pDAS->horzScrollWid != NULL)
157 XtDestroyWidget(pDAS->horzScrollWid);
158 if (pDAS->vertScrollWid != NULL)
159 XtDestroyWidget(pDAS->vertScrollWid);
162 * free the special characters
164 if (pDAS->spc_chars != NULL)
165 free ((char *) pDAS->spc_chars);
168 * free the font info.
170 _DtHelpGetStringQuarks(xrmList);
171 if (__DtHelpFontIndexGet(pDAS, xrmList, &strIdx) != 0)
174 if (pDAS->font_info.def_font_db != NULL)
175 XrmDestroyDatabase(pDAS->font_info.def_font_db);
176 if (pDAS->font_info.font_idx_db != NULL)
177 XrmDestroyDatabase(pDAS->font_info.font_idx_db);
178 if (pDAS->font_info.exact_fonts != NULL)
180 _DtHelpCeFreeStringArray(pDAS->font_info.exact_fonts);
181 free(pDAS->font_info.exact_idx);
183 if (pDAS->font_info.font_structs != NULL)
186 * if the string index is a positive number, this
187 * indicates that the string font is a font not
188 * a font set and it wouldn't be freed in this
191 for (i = 0; i < pDAS->font_info.struct_cnt; i++)
193 if (usedDef == True || i != strIdx)
194 XFreeFont(dpy, pDAS->font_info.font_structs[i]);
196 free(pDAS->font_info.font_structs);
198 if (pDAS->font_info.font_sets != NULL)
201 * if the string index is a negative number, this turns
202 * it to positive and the tests will succeed.
204 * if the string index was a font not a fontset, then
205 * this will turn the value negative and the test
206 * will never succeed.
208 strIdx = (-strIdx) - 1;
209 for (i = 0; i < pDAS->font_info.set_cnt; i++)
211 if (usedDef == True || i != strIdx)
212 XFreeFontSet(dpy, pDAS->font_info.font_sets[i]);
214 free(pDAS->font_info.font_sets);
215 free(pDAS->font_info.fs_metrics);
219 * free the locale dependant information
221 if (NULL != pDAS->cant_begin_chars)
222 free (pDAS->cant_begin_chars);
223 if (NULL != pDAS->cant_end_chars)
224 free (pDAS->cant_end_chars);
227 * destroy the display area pointer
229 XtFree ((char *) pDAS);
231 } /* End DtHelpDisplayAreaDestroy */