X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lwlib%2Flwlib-Xaw.c;h=2fe4dc9cefbcbcb9fc966de98ed57240c275b5de;hb=140eac3b7653c4a9032eedead878981a0c782a65;hp=a0198bc28e71a58e2f64704af7ef5628b76b09f4;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910;p=chise%2Fxemacs-chise.git.1 diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c index a0198bc..2fe4dc9 100644 --- a/lwlib/lwlib-Xaw.c +++ b/lwlib/lwlib-Xaw.c @@ -33,15 +33,21 @@ Boston, MA 02111-1307, USA. */ #include #ifdef LWLIB_SCROLLBARS_ATHENA -#include +#include ATHENA_Scrollbar_h_ #endif #ifdef LWLIB_DIALOGS_ATHENA -#include -#include -#include -#include +#include ATHENA_Dialog_h_ +#include ATHENA_Form_h_ +#include ATHENA_Command_h_ +#include ATHENA_Label_h_ +#endif +#ifdef LWLIB_WIDGETS_ATHENA +#include ATHENA_Toggle_h_ +#include "xlwradio.h" +#include "xlwcheckbox.h" +#include "xlwgauge.h" +#include ATHENA_AsciiText_h_ #endif - #include static void xaw_generic_callback (Widget, XtPointer, XtPointer); @@ -57,6 +63,14 @@ lw_xaw_widget_p (Widget widget) #ifdef LWLIB_DIALOGS_ATHENA || XtIsSubclass (widget, dialogWidgetClass) #endif +#ifdef LWLIB_WIDGETS_ATHENA + || XtIsSubclass (widget, labelWidgetClass) + || XtIsSubclass (widget, toggleWidgetClass) + || XtIsSubclass (widget, gaugeWidgetClass) +#ifndef NEED_MOTIF + || XtIsSubclass (widget, asciiTextWidgetClass) +#endif +#endif ); } @@ -118,6 +132,13 @@ xaw_update_one_widget (widget_instance *instance, Widget widget, xaw_update_scrollbar (instance, widget, val); } #endif +#ifdef LWLIB_WIDGETS_ATHENA +#ifndef NEED_MOTIF + else if (XtIsSubclass (widget, asciiTextWidgetClass)) + { + } +#endif +#endif #ifdef LWLIB_DIALOGS_ATHENA else if (XtIsSubclass (widget, dialogWidgetClass)) { @@ -125,6 +146,16 @@ xaw_update_one_widget (widget_instance *instance, Widget widget, XtSetArg (al [0], XtNlabel, val->contents->value); XtSetValues (widget, al, 1); } +#endif /* LWLIB_DIALOGS_ATHENA */ +#ifdef LWLIB_WIDGETS_ATHENA + else if (XtClass (widget) == labelWidgetClass) + { + Arg al [1]; + XtSetArg (al [0], XtNlabel, val->value); + XtSetValues (widget, al, 1); + } +#endif /* LWLIB_WIDGETS_ATHENA */ +#if defined (LWLIB_DIALOGS_ATHENA) || defined (LWLIB_WIDGETS_ATHENA) else if (XtIsSubclass (widget, commandWidgetClass)) { Dimension bw = 0; @@ -146,6 +177,7 @@ xaw_update_one_widget (widget_instance *instance, Widget widget, } #endif /* ! LWLIB_DIALOGS_ATHENA3D */ + lw_remove_accelerator_spec (val->value); XtSetArg (al [0], XtNlabel, val->value); XtSetArg (al [1], XtNsensitive, val->enabled); /* Force centered button text. See above. */ @@ -154,17 +186,63 @@ xaw_update_one_widget (widget_instance *instance, Widget widget, XtRemoveAllCallbacks (widget, XtNcallback); XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance); +#ifdef LWLIB_WIDGETS_ATHENA + /* set the selected state */ + if (XtIsSubclass (widget, toggleWidgetClass)) + { + XtSetArg (al [0], XtNstate, val->selected); + XtSetValues (widget, al, 1); + } +#endif /* LWLIB_WIDGETS_ATHENA */ } #endif /* LWLIB_DIALOGS_ATHENA */ + /* Lastly update our global arg values. */ + if (val->args && val->args->nargs) + XtSetValues (widget, val->args->args, val->args->nargs); } void xaw_update_one_value (widget_instance *instance, Widget widget, widget_value *val) { - /* This function is not used by the scrollbars and those are the only - Athena widget implemented at the moment so do nothing. */ - return; +#ifdef LWLIB_WIDGETS_ATHENA + widget_value *old_wv; + + /* copy the call_data slot into the "return" widget_value */ + for (old_wv = instance->info->val->contents; old_wv; old_wv = old_wv->next) + if (!strcmp (val->name, old_wv->name)) + { + val->call_data = old_wv->call_data; + break; + } + + if (XtIsSubclass (widget, toggleWidgetClass)) + { + Arg al [1]; + XtSetArg (al [0], XtNstate, &val->selected); + XtGetValues (widget, al, 1); + val->edited = True; + } +#ifndef NEED_MOTIF + else if (XtIsSubclass (widget, asciiTextWidgetClass)) + { + Arg al [2]; + String buf = 0; + XtSetArg (al [0], XtNstring, &buf); + XtGetValues (widget, al, 1); + + if (val->value) + { + free (val->value); + val->value = 0; + } + /* I don't think this causes a leak. */ + if (buf) + val->value = strdup (buf); + val->edited = True; + } +#endif +#endif /* LWLIB_WIDGETS_ATHENA */ } void @@ -265,8 +343,8 @@ static XtActionsRec xaw_actions [] = { static Boolean actions_initted = False; static Widget -make_dialog (CONST char* name, Widget parent, Boolean pop_up_p, - CONST char* shell_title, CONST char* icon_name, +make_dialog (const char* name, Widget parent, Boolean pop_up_p, + const char* shell_title, const char* icon_name, Boolean text_input_slot, Boolean radio_box, Boolean list, int left_buttons, int right_buttons) @@ -374,8 +452,8 @@ xaw_create_dialog (widget_instance* instance) Widget parent = instance->parent; Widget widget; Boolean pop_up_p = instance->pop_up_p; - CONST char *shell_name = 0; - CONST char *icon_name = 0; + const char *shell_name = 0; + const char *icon_name = 0; Boolean text_input_slot = False; Boolean radio_box = False; Boolean list = False; @@ -440,7 +518,21 @@ xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data) Widget instance_widget; LWLIB_ID id; XtPointer user_data; +#ifdef LWLIB_WIDGETS_ATHENA + /* We want the selected status to change only when we decide it + should change. Yuck but correct. */ + if (XtIsSubclass (widget, toggleWidgetClass)) + { + Boolean check; + Arg al [1]; + XtSetArg (al [0], XtNstate, &check); + XtGetValues (widget, al, 1); + + XtSetArg (al [0], XtNstate, !check); + XtSetValues (widget, al, 1); + } +#endif /* LWLIB_WIDGETS_ATHENA */ lw_internal_update_other_instances (widget, closure, call_data); if (! instance) @@ -464,17 +556,26 @@ xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data) #else /* Damn! Athena doesn't give us a way to hang our own data on the buttons, so we have to go find it... I guess this assumes that - all instances of a button have the same call data. */ + all instances of a button have the same call data. + + ... Which is a totally bogus assumption --andyp */ { - widget_value *val = instance->info->val->contents; - char *name = XtName (widget); - while (val) + widget_value *val = instance->info->val; + /* If the widget is a buffer/gutter widget then we already have + the one we are looking for, so don't try and descend the widget + tree. */ + if (val->contents) { - if (val->name && !strcmp (val->name, name)) - break; - val = val->next; + char *name = XtName (widget); + val = val->contents; + while (val) + { + if (val->name && !strcmp (val->name, name)) + break; + val = val->next; + } + if (! val) abort (); } - if (! val) abort (); user_data = val->call_data; } #endif @@ -496,11 +597,14 @@ wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data) abort (); XtSetArg (al [0], XtNchildren, &kids); XtGetValues (shell, al, 1); - if (!kids || !*kids) - abort (); - widget = kids [0]; - if (! XtIsSubclass (widget, dialogWidgetClass)) - abort (); + if (!kids || !*kids) abort (); + + for (widget = *kids; + widget && ! XtIsSubclass (widget, dialogWidgetClass); + widget = *++kids) + ; + if (!widget) abort (); + id = lw_get_widget_id (widget); if (! id) abort (); @@ -614,12 +718,182 @@ xaw_create_horizontal_scrollbar (widget_instance *instance) } #endif /* LWLIB_SCROLLBARS_ATHENA */ -widget_creation_entry +#ifdef LWLIB_WIDGETS_ATHENA +/* glyph widgets */ +static Widget +xaw_create_button (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget button = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; + XtSetArg (al [ac], XtNjustify, XtJustifyCenter); 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], XtNhighlightThickness, (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 = XtCreateManagedWidget (val->name, labelWidgetClass, + instance->parent, al, ac); + + else + { + if (val->type == TOGGLE_TYPE || val->type == RADIO_TYPE) + { + XtSetArg (al [ac], XtNstate, val->selected); ac++; + button = XtCreateManagedWidget + (val->name, + val->type == TOGGLE_TYPE ? checkboxWidgetClass : radioWidgetClass, + instance->parent, al, ac); + } + else + { + button = XtCreateManagedWidget (val->name, commandWidgetClass, + instance->parent, al, ac); + } + XtRemoveAllCallbacks (button, XtNcallback); + XtAddCallback (button, XtNcallback, xaw_generic_callback, (XtPointer)instance); + } + + XtManageChild (button); + + return button; +} + +static Widget +xaw_create_label_field (widget_instance *instance) +{ + return xaw_create_label (instance->parent, instance->info->val); +} + +Widget +xaw_create_label (Widget parent, widget_value* val) +{ + Arg al[20]; + int ac = 0; + Widget label = 0; + + XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; + XtSetArg (al [ac], XtNjustify, XtJustifyCenter); ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + label = XtCreateManagedWidget (val->name, labelWidgetClass, + parent, al, ac); + + /* Do it again for arguments that have no effect until the widget is realized. */ + ac = 0; + lw_add_value_args_to_args (val, al, &ac); + if (ac > 20) + abort (); /* #### need assert macro in lwlib */ + XtSetValues (label, al, ac); + + return label; +} + +static Widget +xaw_create_progress (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget scale = 0; + widget_value* val = instance->info->val; +#if 0 /* This looks too awful, although more correct. */ + if (!val->call_data) + { + XtSetArg (al [ac], XtNsensitive, False); ac++; + } + else + { + XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; + } +#else + XtSetArg (al [ac], XtNsensitive, True); ac++; +#endif + + XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; + XtSetArg (al [ac], XtNorientation, XtorientHorizontal); ac++; + XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0);ac++; + XtSetArg (al [ac], XtNntics, (Cardinal)10);ac++; + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + scale = XtCreateManagedWidget (val->name, gaugeWidgetClass, + instance->parent, al, ac); + /* add the callback */ + if (val->call_data) + XtAddCallback (scale, XtNgetValue, xaw_generic_callback, (XtPointer)instance); + + XtManageChild (scale); + + return scale; +} + +#if defined(LWLIB_WIDGETS_ATHENA) +#define TEXT_BUFFER_SIZE 128 +static Widget +xaw_create_text_field (widget_instance *instance) +{ + Arg al[20]; + int ac = 0; + Widget text = 0; + widget_value* val = instance->info->val; + + XtSetArg (al [ac], XtNsensitive, val->enabled); ac++; + XtSetArg (al [ac], XtNmappedWhenManaged, FALSE); ac++; + XtSetArg (al [ac], XtNhighlightThickness, (Dimension)0); ac++; + XtSetArg (al [ac], XtNtype, XawAsciiString); ac++; + XtSetArg (al [ac], XtNeditType, XawtextEdit); ac++; + XtSetArg (al [ac], XtNuseStringInPlace, False); ac++; +#if 0 + XtSetArg (al [ac], XtNlength, TEXT_BUFFER_SIZE); ac++; +#endif + if (val->value) + { + XtSetArg (al [ac], XtNstring, val->value); ac++; + } + + /* add any args the user supplied for creation time */ + lw_add_value_args_to_args (val, al, &ac); + + text = XtCreateManagedWidget (val->name, asciiTextWidgetClass, + instance->parent, al, ac); + + /* add the callback */ + if (val->call_data) + XtAddCallback (text, XtNgetValue, xaw_generic_callback, (XtPointer)instance); + + XtManageChild (text); + + return text; +} +#endif + +#endif /* LWLIB_WIDGETS_ATHENA */ + +const widget_creation_entry xaw_creation_table [] = { #ifdef LWLIB_SCROLLBARS_ATHENA - {"vertical-scrollbar", xaw_create_vertical_scrollbar}, - {"horizontal-scrollbar", xaw_create_horizontal_scrollbar}, + {"vertical-scrollbar", xaw_create_vertical_scrollbar }, + {"horizontal-scrollbar", xaw_create_horizontal_scrollbar }, +#endif +#ifdef LWLIB_WIDGETS_ATHENA + {"button", xaw_create_button }, + { "label", xaw_create_label_field }, + {"text-field", xaw_create_text_field }, + {"progress", xaw_create_progress }, #endif {NULL, NULL} }; +