Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / DtHelp / Destroy.c
1 /* $XConsortium: Destroy.c /main/12 1996/03/18 14:08:16 cde-hal $ */
2 /************************************<+>*************************************
3  ****************************************************************************
4  **
5  **   File:        Destroy.c
6  **
7  **   Project:     Cde Help System
8  **
9  **   Description: This code frees the information associated with
10  **                a Display Area.
11  **
12  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
13  **
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  ************************************<+>*************************************/
20
21 /*
22  * system includes
23  */
24 #include <stdlib.h>
25 #include <X11/Xatom.h>
26
27 /*
28  * Canvas Engine
29  */
30 #include "CanvasP.h"
31
32 /*
33  * private includes
34  */
35 #include "DisplayAreaP.h"
36 #include "CallbacksI.h"
37 #include "DestroyI.h"
38 #include "FontI.h"
39 #include "GraphicsI.h"
40 #include "HyperTextI.h"
41 #include "StringFuncsI.h"
42
43 #ifdef NLS16
44 #endif
45
46 /********    Private Function Declarations    ********/
47 /********    End Public Function Declarations    ********/
48
49 /******************************************************************************
50  *
51  * These are the public routines available.
52  *
53  *****************************************************************************/
54 /*********************************************************************
55  * Function: _DtHelpDisplayAreaClean
56  *
57  *    _DtHelpDisplayAreaClean deallocates all paragraph, font, and
58  *    graphic information associated with it.
59  *
60  *********************************************************************/
61 void
62 _DtHelpDisplayAreaClean (XtPointer  client_data)
63 {
64     int   n;
65     Arg   args[5];
66     Atom  xa_primary = XA_PRIMARY;
67     DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
68
69     /*
70      * remove the selection if necessary
71      */
72     _DtHelpLoseSelectionCB (pDAS->dispWid, &xa_primary);
73
74     /*
75      * clean the canvas
76      */
77     if (NULL != pDAS->canvas)
78         _DtCanvasClean (pDAS->canvas);
79
80     /*
81      * clean the slate
82      */
83     if (XtIsRealized (pDAS->dispWid))
84         XClearArea(XtDisplay(pDAS->dispWid), XtWindow(pDAS->dispWid),
85                         pDAS->decorThickness, pDAS->decorThickness,
86                         pDAS->dispUseWidth, pDAS->dispUseHeight, False);
87
88     pDAS->toc_flag &= ~(_DT_HELP_TOC_ON);
89
90     /*
91      * reset any scrollbars that are managed.
92      */
93     n = 0;
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;
98
99     if (pDAS->vertScrollWid && XtIsManaged (pDAS->vertScrollWid))
100         XtSetValues (pDAS->vertScrollWid, args, n);
101
102     if (pDAS->horzScrollWid && XtIsManaged (pDAS->horzScrollWid))
103         XtSetValues (pDAS->horzScrollWid, args, n);
104
105 }  /* End _DtHelpDisplayAreaClean */
106
107 /*********************************************************************
108  * Function: _DtHelpDisplayAreaDestroyCB
109  *
110  *    _DtHelpDisplayAreaDestroyCB deallocates all information
111  *    associated with it.
112  *
113  *********************************************************************/
114 void
115 _DtHelpDisplayAreaDestroyCB (
116     Widget w,
117     XtPointer client_data,
118     XtPointer call_data)
119 {
120     int      i;
121     int      strIdx;
122     XrmName               xrmList[_DtHelpFontQuarkNumber];
123     Display              *dpy;
124     DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data;
125     Boolean  usedDef = False;
126
127     /*
128      * do the gross cleaning
129      */
130     _DtHelpDisplayAreaClean(client_data);
131
132     if (NULL != pDAS->canvas)
133         _DtCanvasDestroy (pDAS->canvas);
134
135     dpy = XtDisplay(pDAS->dispWid);
136     /*
137      * Free the gc's
138      */
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)
146     {
147         _DtGrDestroyContext(pDAS->context);
148         XtFree((char *) pDAS->context);
149     }
150
151     /*
152      * destroy the widgets.
153      */
154     XtDestroyWidget(pDAS->dispWid);
155
156     if (pDAS->horzScrollWid != NULL)
157         XtDestroyWidget(pDAS->horzScrollWid);
158     if (pDAS->vertScrollWid != NULL)
159         XtDestroyWidget(pDAS->vertScrollWid);
160
161     /*
162      * free the special characters
163      */
164     if (pDAS->spc_chars != NULL)
165         free ((char *) pDAS->spc_chars);
166
167     /*
168      * free the font info.
169      */
170     _DtHelpGetStringQuarks(xrmList);
171     if (__DtHelpFontIndexGet(pDAS, xrmList, &strIdx) != 0)
172         usedDef = True;
173
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)
179       {
180         _DtHelpCeFreeStringArray(pDAS->font_info.exact_fonts);
181         free(pDAS->font_info.exact_idx);
182       }
183     if (pDAS->font_info.font_structs != NULL)
184       {
185         /*
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
189          * routine.
190          */
191         for (i = 0; i < pDAS->font_info.struct_cnt; i++)
192           {
193             if (usedDef == True || i != strIdx)
194                 XFreeFont(dpy, pDAS->font_info.font_structs[i]);
195           }
196         free(pDAS->font_info.font_structs);
197       }
198     if (pDAS->font_info.font_sets != NULL)
199       {
200         /*
201          * if the string index is a negative number, this turns
202          * it to positive and the tests will succeed.
203          *
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.
207          */
208         strIdx = (-strIdx) - 1;
209         for (i = 0; i < pDAS->font_info.set_cnt; i++)
210           {
211             if (usedDef == True || i != strIdx)
212                 XFreeFontSet(dpy, pDAS->font_info.font_sets[i]);
213           }
214         free(pDAS->font_info.font_sets);
215         free(pDAS->font_info.fs_metrics);
216       }
217
218     /*
219      * free the locale dependant information
220      */
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);
225
226     /*
227      * destroy the display area pointer
228      */
229     XtFree ((char *) pDAS);
230
231 }  /* End DtHelpDisplayAreaDestroy */