Mercurial > hg > xemacs-beta
diff lwlib/lwlib-Xm.c @ 420:41dbb7a9d5f2 r21-2-18
Import from CVS: tag r21-2-18
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:24:09 +0200 |
parents | 697ef44129c6 |
children | 11054d720c21 |
line wrap: on
line diff
--- a/lwlib/lwlib-Xm.c Mon Aug 13 11:23:14 2007 +0200 +++ b/lwlib/lwlib-Xm.c Mon Aug 13 11:24:09 2007 +0200 @@ -4,13 +4,13 @@ This file is part of the Lucid Widget Library. -The Lucid Widget Library is free software; you can redistribute it and/or +The Lucid Widget Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Lucid Widget Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of +but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -60,15 +60,17 @@ #include <Xm/Separator.h> #include <Xm/DialogS.h> #include <Xm/Form.h> +#include <Xm/Scale.h> +#if XmVERSION > 1 +#include <Xm/ComboBox.h> +#endif #ifdef LWLIB_MENUBARS_MOTIF static void xm_pull_down_callback (Widget, XtPointer, XtPointer); -#if 0 -static void xm_pop_down_callback (Widget, XtPointer, XtPointer); -#endif /* 0 */ #endif static void xm_internal_update_other_instances (Widget, XtPointer, XtPointer); +static void xm_pop_down_callback (Widget, XtPointer, XtPointer); static void xm_generic_callback (Widget, XtPointer, XtPointer); #ifdef LWLIB_DIALOGS_MOTIF static void xm_nosel_callback (Widget, XtPointer, XtPointer); @@ -84,7 +86,7 @@ #endif /* Structures to keep destroyed instances */ -typedef struct _destroyed_instance +typedef struct _destroyed_instance { char* name; char* type; @@ -124,7 +126,7 @@ instance->next = NULL; return instance; } - + static void free_destroyed_instance (destroyed_instance* instance) { @@ -143,7 +145,7 @@ Boolean lw_motif_widget_p (Widget widget) { - return + return #ifdef LWLIB_DIALOGS_MOTIF XtClass (widget) == xmDialogShellWidgetClass || #endif @@ -155,7 +157,7 @@ { XtResource resource; char *result = NULL; - + resource.resource_name = "labelString"; resource.resource_class = "LabelString"; /* #### should be Xmsomething... */ resource.resource_type = XtRString; @@ -181,7 +183,7 @@ children = XtCompositeChildren (widget, &number); if (children) { - /* Unmanage all children and destroy them. They will only be + /* Unmanage all children and destroy them. They will only be * really destroyed when we get out of DispatchEvent. */ for (i = 0; i < number; i++) { @@ -283,7 +285,7 @@ XtSetArg (al [ac], XmNlabelString, built_string); ac++; XtSetArg (al [ac], XmNlabelType, XmSTRING); ac++; } - + if (val->key) { key_string = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET); @@ -363,7 +365,7 @@ XtRemoveAllCallbacks (widget, XmNcascadingCallback); XtAddCallback (widget, XmNcascadingCallback, xm_pull_down_callback, instance); - } + } } #endif /* LWLIB_MENUBARS_MOTIF */ @@ -459,7 +461,7 @@ num_children = 0; for (child_index = 0, cur = val; cur; child_index++, cur = cur->next) - { + { ac = 0; button = 0; XtSetArg (al [ac], XmNsensitive, cur->enabled); ac++; @@ -577,7 +579,7 @@ menu = NULL; XtSetArg (al [0], XmNsubMenuId, &menu); XtGetValues (widget, al, 1); - + contents = val->contents; if (!menu) @@ -658,8 +660,6 @@ #endif /* LWLIB_MENUBARS_MOTIF */ -#ifdef LWLIB_DIALOGS_MOTIF - /* update text widgets */ static void @@ -685,7 +685,6 @@ xm_internal_update_other_instances, instance); } -#endif /* LWLIB_DIALOGS_MOTIF */ #ifdef LWLIB_SCROLLBARS_MOTIF @@ -769,7 +768,7 @@ { WidgetClass class; Arg al [2]; - + /* Mark as not edited */ val->edited = False; @@ -782,8 +781,8 @@ /* Common to all label like widgets */ if (XtIsSubclass (widget, xmLabelWidgetClass)) xm_update_label (instance, widget, val); -#endif - +#endif /* defined (LWLIB_DIALOGS_MOTIF) || defined (LWLIB_MENUBARS_MOTIF) */ + class = XtClass (widget); /* Class specific things */ if (class == xmPushButtonWidgetClass || @@ -808,7 +807,7 @@ XtSetArg (al [0], XmNradioBehavior, &radiobox); XtGetValues (widget, al, 1); - + if (radiobox) xm_update_radiobox (instance, widget, val); #ifdef LWLIB_MENUBARS_MOTIF @@ -816,7 +815,6 @@ xm_update_menu (instance, widget, val, deep_p); #endif } -#ifdef LWLIB_DIALOGS_MOTIF else if (class == xmTextWidgetClass) { xm_update_text (instance, widget, val); @@ -825,7 +823,6 @@ { xm_update_text_field (instance, widget, val); } -#endif else if (class == xmListWidgetClass) { xm_update_list (instance, widget, val); @@ -853,7 +850,7 @@ val->call_data = old_wv->call_data; break; } - + if (class == xmToggleButtonWidgetClass || class == xmToggleButtonGadgetClass) { Arg al [1]; @@ -861,7 +858,6 @@ XtGetValues (widget, al, 1); val->edited = True; } -#ifdef LWLIB_DIALOGS_MOTIF else if (class == xmTextWidgetClass) { if (val->value) @@ -876,7 +872,6 @@ val->value = XmTextFieldGetString (widget); val->edited = True; } -#endif else if (class == xmRowColumnWidgetClass) { Boolean radiobox = 0; @@ -946,7 +941,7 @@ /* This function is for activating a button from a program. It's wrong because we pass a NULL argument in the call_data which is not Motif compatible. This is used from the XmNdefaultAction callback of the List widgets to - have a dble-click put down a dialog box like the button woudl do. + have a double-click put down a dialog box like the button would do. I could not find a way to do that with accelerators. */ static void @@ -996,7 +991,7 @@ /* This is a kludge to disable drag-and-drop in dialog boxes. The symptom was a segv down in libXm somewhere if you used the middle button on a dialog box to begin a drag; when you released the button to make a drop - things would lose if you were not over the button where you started the + things would lose if you were not over the button where you started the drag (canceling the operation). This was probably due to the fact that the dialog boxes were not set up to handle a drag but were trying to do so anyway for some reason. @@ -1029,7 +1024,7 @@ Arg al[64]; /* Arg List */ int ac; /* Arg Count */ int i; - + #ifdef DND_KLUDGE XtTranslations dnd_override = XtParseTranslationTable (disable_dnd_trans); # define DO_DND_KLUDGE(widget) XtOverrideTranslations ((widget), dnd_override) @@ -1077,7 +1072,7 @@ XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; XtSetArg(al[ac], XmNrightOffset, 13); ac++; row = XmCreateRowColumn (form, "row", al, ac); - + n_children = 0; for (i = 0; i < left_buttons; i++) { @@ -1119,7 +1114,7 @@ al, ac); DO_DND_KLUDGE (children [n_children]); n_children++; - + for (i = 0; i < right_buttons; i++) { char button_name [16]; @@ -1131,9 +1126,9 @@ if (! button) button = children [n_children]; n_children++; } - + XtManageChildren (children, n_children); - + ac = 0; XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE); ac++; XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++; @@ -1232,7 +1227,7 @@ list activate the default button */ XtAddCallback (value, XmNdefaultActionCallback, activate_button, button); } - + ac = 0; XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++; @@ -1248,7 +1243,7 @@ XtSetArg(al[ac], XmNrightOffset, 13); ac++; message = XmCreateLabel (form, "message", al, ac); DO_DND_KLUDGE (message); - + if (list) XtManageChild (value); @@ -1263,7 +1258,7 @@ children [i] = icon; i++; children [i] = icon_separator; i++; XtManageChildren (children, i); - + if (text_input_slot || list) { XtInstallAccelerators (value, button); @@ -1274,7 +1269,7 @@ XtInstallAccelerators (form, button); XmProcessTraversal(value, XmTRAVERSE_CURRENT); } - + #ifdef DND_KLUDGE XtFree ((char *) dnd_override); #endif @@ -1353,7 +1348,7 @@ x = (Position) ((parent_width - child_width) / 2); y = (Position) ((parent_height - child_height) / 2); - + XtTranslateCoords (parent, x, y, &x, &y); if ((Dimension) (x + child_width) > screen_width) @@ -1466,7 +1461,7 @@ shell_name = "Question"; break; } - + total_buttons = name [1] - '0'; if (name [3] == 'T' || name [3] == 't') @@ -1476,9 +1471,9 @@ } else if (name [3]) right_buttons = name [4] - '0'; - + left_buttons = total_buttons - right_buttons; - + widget = make_dialog (name, parent, pop_up_p, shell_name, icon_name, text_input_slot, radio_box, list, left_buttons, right_buttons); @@ -1537,7 +1532,7 @@ { {xm_scrollbar_callback, NULL}, {NULL, NULL} }; callbacks[0].closure = (XtPointer) instance; - + XtSetArg (al[ac], XmNminimum, 1); ac++; XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++; XtSetArg (al[ac], XmNincrement, 1); ac++; @@ -1571,10 +1566,154 @@ #endif /* LWLIB_SCROLLBARS_MOTIF */ -/* Table of functions to create widgets */ +/* glyph widgets */ +static Widget +make_button (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget button = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XmNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; + XtSetArg (al [ac], XmNuserData, val->call_data); ac++; + XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++; + /* The highlight doesn't appear to be dynamically set which makes it + look ugly. I think this may be a LessTif bug but for now we just + get rid of it. */ + XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + if (!val->call_data) + button = XmCreateLabel (instance->parent, val->name, al, ac); + + else if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE) + { + XtSetArg (al [ac], XmNset, val->selected); ac++; + XtSetArg (al [ac], XmNindicatorType, + (val->type == TOGGLE_TYPE ? + XmN_OF_MANY : XmONE_OF_MANY)); ac++; + XtSetArg (al [ac], XmNvisibleWhenOff, True); ac++; + button = XmCreateToggleButton (instance->parent, val->name, al, ac); + XtRemoveAllCallbacks (button, XmNvalueChangedCallback); + XtAddCallback (button, XmNvalueChangedCallback, xm_generic_callback, + (XtPointer)instance); + } + else + { + button = XmCreatePushButton (instance->parent, val->name, al, ac); + XtAddCallback (button, XmNactivateCallback, xm_generic_callback, + (XtPointer)instance); + } + + XtManageChild (button); + + return button; +} + +static Widget +make_progress (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget scale = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XmNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; + XtSetArg (al [ac], XmNuserData, val->call_data); ac++; + XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++; + XtSetArg (al [ac], XmNorientation, XmHORIZONTAL); ac++; + /* The highlight doesn't appear to be dynamically set which makes it + look ugly. I think this may be a LessTif bug but for now we just + get rid of it. */ + XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; + if (!val->call_data) + XtSetArg (al [ac], XmNsensitive, False); ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + scale = XmCreateScale (instance->parent, val->name, al, ac); + if (val->call_data) + XtAddCallback (scale, XmNvalueChangedCallback, xm_generic_callback, + (XtPointer)instance); + + XtManageChild (scale); + + return scale; +} + +static Widget +make_text_field (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget text = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XmNsensitive, val->enabled && val->call_data); ac++; + XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; + XtSetArg (al [ac], XmNuserData, val->call_data); ac++; + XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++; + /* The highlight doesn't appear to be dynamically set which makes it + look ugly. I think this may be a LessTif bug but for now we just + get rid of it. */ + XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + text = XmCreateTextField (instance->parent, val->name, al, ac); + if (val->call_data) + XtAddCallback (text, XmNvalueChangedCallback, xm_generic_callback, + (XtPointer)instance); + + XtManageChild (text); + + return text; +} + +#if XmVERSION > 1 +static Widget +make_combo_box (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget combo = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XmNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++; + XtSetArg (al [ac], XmNuserData, val->call_data); ac++; + XtSetArg (al [ac], XmNmappedWhenManaged, FALSE); ac++; + /* The highlight doesn't appear to be dynamically set which makes it + look ugly. I think this may be a LessTif bug but for now we just + get rid of it. */ + XtSetArg (al [ac], XmNhighlightThickness, (Dimension)0);ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + combo = XmCreateComboBox (instance->parent, val->name, al, ac); + if (val->call_data) + XtAddCallback (combo, XmNselectionCallback, xm_generic_callback, + (XtPointer)instance); + + XtManageChild (combo); + + return combo; +} +#endif + + +/* Table of functions to create widgets */ widget_creation_entry -xm_creation_table [] = +xm_creation_table [] = { #ifdef LWLIB_MENUBARS_MOTIF {"menubar", make_menubar}, @@ -1584,6 +1723,12 @@ {"vertical-scrollbar", make_vertical_scrollbar}, {"horizontal-scrollbar", make_horizontal_scrollbar}, #endif + {"button", make_button}, + {"progress", make_progress}, + {"text-field", make_text_field}, +#if XmVERSION > 1 + {"combo-box", make_combo_box}, +#endif {NULL, NULL} }; @@ -1700,12 +1845,12 @@ if (up) XtManageChild (widget); else - XtUnmanageChild (widget); + XtUnmanageChild (widget); } } -/* motif callback */ +/* motif callback */ enum do_call_type { pre_activate, selection, no_selection, post_activate }; @@ -1755,7 +1900,7 @@ } /* Like lw_internal_update_other_instances except that it does not do - anything if its shell parent is not managed. This is to protect + anything if its shell parent is not managed. This is to protect lw_internal_update_other_instances to dereference freed memory if the widget was ``destroyed'' by caching it in the all_destroyed_instances list */ @@ -1790,11 +1935,17 @@ XtSetArg (al [0], XmNset, !check); XtSetValues (widget, al, 1); } -#endif +#endif lw_internal_update_other_instances (widget, closure, call_data); do_call (widget, closure, selection); } +static void +xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data) +{ + do_call (widget, closure, post_activate); +} + #ifdef LWLIB_DIALOGS_MOTIF static void @@ -1823,21 +1974,13 @@ if (call_data) { /* new behavior for incremental menu construction */ - + } else -#endif +#endif do_call (widget, closure, pre_activate); } -#if 0 -static void -xm_pop_down_callback (Widget widget, XtPointer closure, XtPointer call_data) -{ - do_call (widget, closure, post_activate); -} -#endif /* 0 */ - #endif /* LWLIB_MENUBARS_MOTIF */ #ifdef LWLIB_SCROLLBARS_MOTIF