comparison lwlib/lwlib.c @ 434:9d177e8d4150 r21-2-25

Import from CVS: tag r21-2-25
author cvs
date Mon, 13 Aug 2007 11:30:53 +0200
parents 3ecd8885ac67
children 84b14dcb0985
comparison
equal deleted inserted replaced
433:892ca416f0fb 434:9d177e8d4150
38 #ifdef NEED_LUCID 38 #ifdef NEED_LUCID
39 #include "lwlib-Xlw.h" 39 #include "lwlib-Xlw.h"
40 #endif 40 #endif
41 #ifdef NEED_MOTIF 41 #ifdef NEED_MOTIF
42 #include "lwlib-Xm.h" 42 #include "lwlib-Xm.h"
43 #ifdef LWLIB_WIDGETS_MOTIF
44 #include <Xm/Xm.h>
45 #endif
43 #endif 46 #endif
44 #ifdef NEED_ATHENA 47 #ifdef NEED_ATHENA
45 #include "lwlib-Xaw.h" 48 #include "lwlib-Xaw.h"
46 #endif 49 #endif
47 50
65 /* whether the last menu operation was a keyboard accelerator */ 68 /* whether the last menu operation was a keyboard accelerator */
66 int lw_menu_accelerate = False; 69 int lw_menu_accelerate = False;
67 70
68 71
69 /* Forward declarations */ 72 /* Forward declarations */
70 static void 73 static void instantiate_widget_instance (widget_instance *instance);
71 instantiate_widget_instance (widget_instance *instance); 74 static void free_widget_value_args (widget_value* wv);
72 75
73 76
74 /* utility functions for widget_instance and widget_info */ 77 /* utility functions for widget_instance and widget_info */
75 static char * 78 static char *
76 safe_strdup (CONST char *s) 79 safe_strdup (CONST char *s)
151 if (wv->contents && (wv->contents != (widget_value*)1)) 154 if (wv->contents && (wv->contents != (widget_value*)1))
152 { 155 {
153 free_widget_value_tree (wv->contents); 156 free_widget_value_tree (wv->contents);
154 wv->contents = (widget_value *) 0xDEADBEEF; 157 wv->contents = (widget_value *) 0xDEADBEEF;
155 } 158 }
156 if (wv->args && wv->nargs) 159
157 { 160 free_widget_value_args (wv);
158 if (wv->free_args) 161
159 free (wv->args);
160 wv->args = (ArgList) 0xDEADBEEF;
161 wv->nargs = 0;
162 wv->free_args = 0;
163 }
164 if (wv->next) 162 if (wv->next)
165 { 163 {
166 free_widget_value_tree (wv->next); 164 free_widget_value_tree (wv->next);
167 wv->next = (widget_value *) 0xDEADBEEF; 165 wv->next = (widget_value *) 0xDEADBEEF;
168 } 166 }
234 232
235 return changed; 233 return changed;
236 } 234 }
237 235
238 #endif /* NEED_SCROLLBARS */ 236 #endif /* NEED_SCROLLBARS */
237
238 #ifdef HAVE_WIDGETS
239 /*
240 * Return true if old->args was not equivalent
241 * to new->args.
242 */
243 static Boolean
244 merge_widget_value_args (widget_value *old, widget_value *new)
245 {
246 Boolean changed = False;
247
248 if (new->args && !old->args)
249 {
250 lw_copy_widget_value_args (new, old);
251 changed = True;
252 }
253 /* Generally we don't want to lose values that are already in the
254 widget. */
255 else if (!new->args && old->args)
256 {
257 lw_copy_widget_value_args (old, new);
258 changed = True;
259 }
260 else if (new->args && old->args)
261 {
262 /* #### Do something more sensible here than just copying the
263 new values (like actually merging the values). */
264 free_widget_value_args (old);
265 lw_copy_widget_value_args (new, old);
266 changed = True;
267 }
268
269 return changed;
270 }
271 #endif /* HAVE_WIDGETS */
239 272
240 /* Make a complete copy of a widget_value tree. Store CHANGE into 273 /* Make a complete copy of a widget_value tree. Store CHANGE into
241 the widget_value tree's `change' field. */ 274 the widget_value tree's `change' field. */
242 275
243 static widget_value * 276 static widget_value *
267 copy->contents = copy_widget_value_tree (val->contents, change); 300 copy->contents = copy_widget_value_tree (val->contents, change);
268 copy->call_data = val->call_data; 301 copy->call_data = val->call_data;
269 copy->next = copy_widget_value_tree (val->next, change); 302 copy->next = copy_widget_value_tree (val->next, change);
270 copy->toolkit_data = NULL; 303 copy->toolkit_data = NULL;
271 copy->free_toolkit_data = False; 304 copy->free_toolkit_data = False;
272 if (val->nargs) 305
273 { 306 lw_copy_widget_value_args (val, copy);
274 copy->args = (ArgList)malloc (sizeof (Arg) * val->nargs);
275 memcpy (copy->args, val->args, sizeof(Arg) * val->nargs);
276 copy->nargs = val->nargs;
277 copy->free_args = True;
278 }
279 #ifdef NEED_SCROLLBARS 307 #ifdef NEED_SCROLLBARS
280 copy_scrollbar_values (val, copy); 308 copy_scrollbar_values (val, copy);
281 #endif 309 #endif
282 } 310 }
283 return copy; 311 return copy;
588 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "call-data change", 616 EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "call-data change",
589 val1->call_data, val2->call_data); 617 val1->call_data, val2->call_data);
590 change = max (change, INVISIBLE_CHANGE); 618 change = max (change, INVISIBLE_CHANGE);
591 val1->call_data = val2->call_data; 619 val1->call_data = val2->call_data;
592 } 620 }
621 #ifdef HAVE_WIDGETS
622 if (merge_widget_value_args (val1, val2))
623 {
624 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "widget change", 0, 0);
625 change = max (change, VISIBLE_CHANGE);
626 }
627 #endif
628
593 #ifdef NEED_SCROLLBARS 629 #ifdef NEED_SCROLLBARS
594 if (merge_scrollbar_values (val1, val2)) 630 if (merge_scrollbar_values (val1, val2))
595 { 631 {
596 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "scrollbar change", 0, 0); 632 EXPLAIN (val1->name, change, VISIBLE_CHANGE, "scrollbar change", 0, 0);
597 change = max (change, VISIBLE_CHANGE); 633 change = max (change, VISIBLE_CHANGE);
1315 } 1351 }
1316 1352
1317 void lw_add_value_args_to_args (widget_value* wv, ArgList addto, int* offset) 1353 void lw_add_value_args_to_args (widget_value* wv, ArgList addto, int* offset)
1318 { 1354 {
1319 int i; 1355 int i;
1320 if (wv->nargs && wv->args) 1356 if (wv->args && wv->args->nargs)
1321 { 1357 {
1322 for (i = 0; i<wv->nargs; i++) 1358 for (i = 0; i<wv->args->nargs; i++)
1323 { 1359 {
1324 addto[i + *offset] = wv->args[i]; 1360 addto[i + *offset] = wv->args->args[i];
1325 } 1361 }
1326 *offset += wv->nargs; 1362 *offset += wv->args->nargs;
1327 } 1363 }
1328 } 1364 }
1329 1365
1366 void lw_add_widget_value_arg (widget_value* wv, String name, XtArgVal value)
1367 {
1368 if (!wv->args)
1369 {
1370 wv->args = (widget_args *) malloc (sizeof (widget_args));
1371 memset (wv->args, 0, sizeof (widget_args));
1372 wv->args->ref_count = 1;
1373 wv->args->nargs = 0;
1374 wv->args->args = (ArgList) malloc (sizeof (Arg) * 10);
1375 memset (wv->args->args, 0, sizeof (Arg) * 10);
1376 }
1377
1378 if (wv->args->nargs > 10)
1379 return;
1380
1381 XtSetArg (wv->args->args [wv->args->nargs], name, value); wv->args->nargs++;
1382 }
1383
1384 static void free_widget_value_args (widget_value* wv)
1385 {
1386 if (wv->args)
1387 {
1388 if (--wv->args->ref_count <= 0)
1389 {
1390 #ifdef LWLIB_WIDGETS_MOTIF
1391 int i;
1392 for (i = 0; i < wv->args->nargs; i++)
1393 {
1394 if (!strcmp (wv->args->args[i].name, XmNfontList))
1395 XmFontListFree ((XmFontList)wv->args->args[i].value);
1396 }
1397 #endif
1398 free (wv->args->args);
1399 free (wv->args);
1400 wv->args = (widget_args*)0xDEADBEEF;
1401 }
1402 }
1403 }
1404
1405 void lw_copy_widget_value_args (widget_value* val, widget_value* copy)
1406 {
1407 if (!val->args)
1408 {
1409 if (copy->args)
1410 free_widget_value_args (copy);
1411 copy->args = 0;
1412 }
1413 else
1414 {
1415 copy->args = val->args;
1416 copy->args->ref_count++;
1417 }
1418 }
1419