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