| 1 |
/*--------------------------------------------------------------------- |
| 2 |
* $Date: 2009-08-18 15:23:20 $ $Revision: 1.2 $ |
| 3 |
*--------------------------------------------------------------------- |
| 4 |
* |
| 5 |
* |
| 6 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 7 |
* |
| 8 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 9 |
* distribute this software and its documentation for any purpose |
| 10 |
* and without fee is hereby granted, provided that the above |
| 11 |
* copyright notice appear in all copies and that both that |
| 12 |
* copyright notice and this permission notice appear in supporting |
| 13 |
* documentation, and that the name of Visual Edge Software not be |
| 14 |
* used in advertising or publicity pertaining to distribution of |
| 15 |
* the software without specific, written prior permission. The year |
| 16 |
* included in the notice is the year of the creation of the work. |
| 17 |
*--------------------------------------------------------------------- |
| 18 |
* File_Description_Section |
| 19 |
*--------------------------------------------------------------------*/ |
| 20 |
|
| 21 |
/* |
| 22 |
.VERSION |
| 23 |
090818 last modif |
| 24 |
*/ |
| 25 |
|
| 26 |
|
| 27 |
/*--- include files ---*/ |
| 28 |
#include "uxproto.h" |
| 29 |
#include "UxLib.h" |
| 30 |
#include "vtypes.h" |
| 31 |
#include "utype.h" |
| 32 |
|
| 33 |
#include <Xm/RowColumn.h> |
| 34 |
#include <Xm/SelectioB.h> |
| 35 |
|
| 36 |
#ifdef RUNTIME |
| 37 |
#include "uxdd.h" |
| 38 |
#else |
| 39 |
#include "resource.h" |
| 40 |
#endif /* RUNTIME */ |
| 41 |
|
| 42 |
/*--- macro symbolic constants ---*/ |
| 43 |
|
| 44 |
/*--- macro functions ---*/ |
| 45 |
|
| 46 |
/*--- types ---*/ |
| 47 |
|
| 48 |
/*--- external functions ---*/ |
| 49 |
|
| 50 |
/*--- external variables ---*/ |
| 51 |
|
| 52 |
/*--- global variables ---*/ |
| 53 |
|
| 54 |
/*--- file global variables ---*/ |
| 55 |
|
| 56 |
/*--- forward declaration of static functions ---*/ |
| 57 |
|
| 58 |
/*---------------------------------------------------------------------- |
| 59 |
* NAME: <UxFreeXValue(sw, xt_name, xt_value)> |
| 60 |
* DESCRIPTION: <The 'xt_value' argument is assumed to be the result |
| 61 |
* of a conversion from a UIM/X value. |
| 62 |
* This function, which is intended for use after the value |
| 63 |
* has been passed into the widget, does any cleanup necessary. |
| 64 |
* Whether there is anything to do is dependent on the |
| 65 |
* implementation of the 'TO_X' side of the convertor function.> |
| 66 |
* PARAMETERS: |
| 67 |
* widget sw - swidget |
| 68 |
* char *xt_name - Xt name of resource |
| 69 |
* XtArgVal xt_value - Xt resource value |
| 70 |
* RETURN: void |
| 71 |
* EXT REFS: none |
| 72 |
* EXT EFFECTS: none |
| 73 |
* ASSUMPTIONS: |
| 74 |
* REVISIONS: 23/10/92 created |
| 75 |
* 01/12/92 fix3749 added case for selectionarray |
| 76 |
* 05/07/93 fix4234 _NO_PROTO |
| 77 |
* 31/08/93 fix4472 free XmStrings on dg88 |
| 78 |
*--------------------------------------------------------------------*/ |
| 79 |
#ifdef _NO_PROTO |
| 80 |
void UxFreeXValue(sw, xt_name, xt_value) |
| 81 |
swidget sw; |
| 82 |
char *xt_name; |
| 83 |
XtArgVal xt_value; |
| 84 |
#else |
| 85 |
void UxFreeXValue(swidget sw, char *xt_name, XtArgVal xt_value) |
| 86 |
#endif /* _NO_PROTO */ |
| 87 |
{ |
| 88 |
int xtype, utype; |
| 89 |
|
| 90 |
#ifdef RUNTIME |
| 91 |
CL_ENTRY *dd = UxDDEntry(xt_name, UxGetClass(sw)); |
| 92 |
|
| 93 |
if (dd == NULL) |
| 94 |
return; |
| 95 |
|
| 96 |
xtype = dd->xtype; |
| 97 |
utype = dd->utype; |
| 98 |
#else |
| 99 |
Resource_t *res = UxFindXtResource(sw, xt_name); |
| 100 |
|
| 101 |
if (res == NULL) |
| 102 |
return; |
| 103 |
|
| 104 |
xtype = UxGetXType(res); |
| 105 |
utype = UxGetUType(res); |
| 106 |
#endif /* RUNTIME */ |
| 107 |
|
| 108 |
|
| 109 |
if (xtype == UxXT_ValueWcs && utype == UxUT_string) { |
| 110 |
/* the convertor string_ValueWcs() allocated an array */ |
| 111 |
|
| 112 |
UxFree((char *)xt_value); |
| 113 |
} |
| 114 |
|
| 115 |
if (xtype == UxXT_XmString && utype == UxUT_string) { |
| 116 |
|
| 117 |
/*----------------------------------------------------- |
| 118 |
* The convertor string_XmString() allocated an XmString. |
| 119 |
* In general, when an XmString is set on a widget via |
| 120 |
* a call to XtSetValues, Motif makes a copy of the |
| 121 |
* XmString. However, some inconsistencies in Motif force |
| 122 |
* us to leave some memory unfreed because the widget does |
| 123 |
* not make a copy of the passed XmString but just a pointer |
| 124 |
* to it. |
| 125 |
* |
| 126 |
* Widget Resource Platform |
| 127 |
* -------------------------------------------------------- |
| 128 |
* XmRowColumn XmNlabelString All |
| 129 |
* |
| 130 |
* For these resources, we cannot reliably free the allocated |
| 131 |
* memory after a call to XtSetValues otherwise the widget |
| 132 |
* would still have a pointer to freed memory. |
| 133 |
* For all these resources, we should actually register |
| 134 |
* destroyCallbacks to free the allocated memory. |
| 135 |
*-----------------------------------------------------*/ |
| 136 |
|
| 137 |
Widget wid = UxGetWidget(sw); |
| 138 |
if (!XtIsSubclass (wid, xmRowColumnWidgetClass)) |
| 139 |
{ |
| 140 |
XmStringFree((XmString)xt_value); |
| 141 |
} |
| 142 |
} else if (xtype == UxXT_SelectionArray && utype == UxUT_string) { |
| 143 |
/* the convertor string_Selection_array() allocated an array */ |
| 144 |
|
| 145 |
XtFree((char *) xt_value); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
/*---------------------------------------------------------------------- |
| 150 |
* NAME: <UxClearText> |
| 151 |
* DESCRIPTION: <Clears the specified text swidget.> |
| 152 |
* PARAMETERS: |
| 153 |
* swidget textsw I text swidget to be cleared |
| 154 |
* RETURN: none |
| 155 |
* EXT REFS: |
| 156 |
* EXT EFFECTS: |
| 157 |
* ASSUMPTIONS: |
| 158 |
* REVISIONS: 10/03/89 Creation |
| 159 |
* dd/04/93 fix4162 Use more explicit Xm calls. |
| 160 |
* 05/05/93 fix4225 renamed function. |
| 161 |
* 05/07/93 fix4234 _NO_PROTO |
| 162 |
*--------------------------------------------------------------------*/ |
| 163 |
#ifdef _NO_PROTO |
| 164 |
void UxClearText(textsw) |
| 165 |
swidget textsw; |
| 166 |
#else |
| 167 |
void UxClearText(swidget textsw) |
| 168 |
#endif /* _NO_PROTO */ |
| 169 |
{ |
| 170 |
Widget w = UxGetWidget(textsw); |
| 171 |
|
| 172 |
/*--------------------------------------------------------------- |
| 173 |
* This function used to say simply XmTextSetString(w, "") |
| 174 |
* but that led to mysterious crashes after a lot of text |
| 175 |
* was shown in and then cleared from the projwin message window. |
| 176 |
* The following sequence is more stable; |
| 177 |
* the final XmTextShowPosition(w, 1) is essential to |
| 178 |
* avoiding those undiagnosable crashes. |
| 179 |
|
| 180 |
*---------------------------------------------------------------*/ |
| 181 |
|
| 182 |
if (w) { |
| 183 |
int last = XmTextGetLastPosition(w); |
| 184 |
XmTextReplace(w, 0, last, ""); |
| 185 |
XmTextShowPosition(w, 1); |
| 186 |
} |
| 187 |
} |
| 188 |
/*---------------------------------------------------------------------- |
| 189 |
* NAME: <UxFreeClientDataCB> |
| 190 |
* DESCRIPTION: <Callback function to free client data.> |
| 191 |
* PARAMETERS: |
| 192 |
* Widget wgt I widget |
| 193 |
* XtPointer client_data I pointer to be freed |
| 194 |
* XtPointer call_data I not used |
| 195 |
* RETURN: none |
| 196 |
* EXT REFS: |
| 197 |
* EXT EFFECTS: |
| 198 |
* ASSUMPTIONS: |
| 199 |
* REVISIONS: 05/07/93 fix4234 created (copied from UxXt.c) |
| 200 |
*--------------------------------------------------------------------*/ |
| 201 |
#ifdef _NO_PROTO |
| 202 |
void UxFreeClientDataCB( _wgt, client_data, _call_data ) |
| 203 |
Widget _wgt; |
| 204 |
XtPointer client_data, _call_data; |
| 205 |
#else |
| 206 |
void UxFreeClientDataCB( Widget _wgt, XtPointer client_data, |
| 207 |
XtPointer _call_data ) |
| 208 |
#endif /* _NO_PROTO */ |
| 209 |
{ |
| 210 |
/* Widget wgt = _wgt; |
| 211 |
XtPointer call_data = _call_data; */ |
| 212 |
|
| 213 |
if (client_data != NULL) |
| 214 |
XtFree((char *) client_data); |
| 215 |
} |
| 216 |
|
| 217 |
/*--- end of file ---*/ |