]> code.delx.au - gnu-emacs/blobdiff - lwlib/lwlib-Xaw.c
(custom-reset-menu, custom-buffer-create-internal)
[gnu-emacs] / lwlib / lwlib-Xaw.c
index 3f11567916915081161ace65161b4869a987527e..1369ed26f72e8f67095f702ceb81ff5f75bfbe14 100644 (file)
@@ -3,22 +3,29 @@
 
 This file is part of the Lucid Widget Library.
 
 
 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 1, or (at your option)
 any later version.
 
 The Lucid Widget Library is distributed in the hope that it will be useful,
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 1, 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.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
+#include "../src/lisp.h"
+
 #include "lwlib-Xaw.h"
 
 #include <X11/StringDefs.h>
 #include "lwlib-Xaw.h"
 
 #include <X11/StringDefs.h>
@@ -35,21 +42,24 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <X11/Xatom.h>
 
 
 #include <X11/Xatom.h>
 
-static void xaw_generic_callback (Widget, XtPointer, XtPointer);
+static void xaw_generic_callback (/*Widget, XtPointer, XtPointer*/);
 
 
 Boolean
 
 
 Boolean
-lw_xaw_widget_p (Widget widget)
+lw_xaw_widget_p (widget)
+     Widget widget;
 {
   return (XtIsSubclass (widget, scrollbarWidgetClass) ||
          XtIsSubclass (widget, dialogWidgetClass));
 }
 
 {
   return (XtIsSubclass (widget, scrollbarWidgetClass) ||
          XtIsSubclass (widget, dialogWidgetClass));
 }
 
+#if 0
 static void
 static void
-xaw_update_scrollbar (widget_instance *instance, Widget widget,
-                     widget_value *val)
+xaw_update_scrollbar (instance, widget, val)
+     widget_instance *instance;
+     Widget widget;
+     widget_value *val;
 {
 {
-#if 0
   if (val->scrollbar_data)
     {
       scrollbar_values *data = val->scrollbar_data;
   if (val->scrollbar_data)
     {
       scrollbar_values *data = val->scrollbar_data;
@@ -65,7 +75,7 @@ xaw_update_scrollbar (widget_instance *instance, Widget widget,
                     XtNy, &pos_y,
                     XtNtopOfThumb, &widget_topOfThumb,
                     XtNshown, &widget_shown,
                     XtNy, &pos_y,
                     XtNtopOfThumb, &widget_topOfThumb,
                     XtNshown, &widget_shown,
-                    0);
+                    NULL);
 
       /*
        * First size and position the scrollbar widget.
 
       /*
        * First size and position the scrollbar widget.
@@ -80,7 +90,7 @@ xaw_update_scrollbar (widget_instance *instance, Widget widget,
          XtVaSetValues (widget,
                         XtNlength, data->scrollbar_height,
                         XtNthickness, width,
          XtVaSetValues (widget,
                         XtNlength, data->scrollbar_height,
                         XtNthickness, width,
-                        0);
+                        NULL);
        }
 
       /*
        }
 
       /*
@@ -105,25 +115,40 @@ xaw_update_scrollbar (widget_instance *instance, Widget widget,
       if (new_shown != widget_shown || new_topOfThumb != widget_topOfThumb)
        XawScrollbarSetThumb (widget, new_topOfThumb, new_shown);
     }
       if (new_shown != widget_shown || new_topOfThumb != widget_topOfThumb)
        XawScrollbarSetThumb (widget, new_topOfThumb, new_shown);
     }
-#endif
 }
 }
+#endif
 
 void
 
 void
+#ifdef PROTOTYPES
 xaw_update_one_widget (widget_instance *instance, Widget widget,
                       widget_value *val, Boolean deep_p)
 xaw_update_one_widget (widget_instance *instance, Widget widget,
                       widget_value *val, Boolean deep_p)
+#else
+xaw_update_one_widget (instance, widget, val, deep_p)
+     widget_instance *instance;
+     Widget widget;
+     widget_value *val;
+     Boolean deep_p;
+#endif
 {
 {
+#if 0
   if (XtIsSubclass (widget, scrollbarWidgetClass))
     {
       xaw_update_scrollbar (instance, widget, val);
     }
   if (XtIsSubclass (widget, scrollbarWidgetClass))
     {
       xaw_update_scrollbar (instance, widget, val);
     }
-  else if (XtIsSubclass (widget, dialogWidgetClass))
+#endif
+  if (XtIsSubclass (widget, dialogWidgetClass))
     {
     {
-      XtVaSetValues (widget, XtNlabel, val->contents->value, 0);
+      Arg al[1];
+      int ac = 0;
+      XtSetArg (al[ac], XtNlabel, val->contents->value); ac++;
+      XtSetValues (widget,  al, ac);
     }
   else if (XtIsSubclass (widget, commandWidgetClass))
     {
       Dimension bw = 0;
     }
   else if (XtIsSubclass (widget, commandWidgetClass))
     {
       Dimension bw = 0;
-      XtVaGetValues (widget, XtNborderWidth, &bw, 0);
+      Arg al[3];
+
+      XtVaGetValues (widget, XtNborderWidth, &bw, NULL);
       if (bw == 0)
        /* Don't let buttons end up with 0 borderwidth, that's ugly...
           Yeah, all this should really be done through app-defaults files
       if (bw == 0)
        /* Don't let buttons end up with 0 borderwidth, that's ugly...
           Yeah, all this should really be done through app-defaults files
@@ -131,23 +156,26 @@ xaw_update_one_widget (widget_instance *instance, Widget widget,
           that I don't feel like opening right now.  Making Athena widgets
           not look like shit is just entirely too much work.
         */
           that I don't feel like opening right now.  Making Athena widgets
           not look like shit is just entirely too much work.
         */
-       XtVaSetValues (widget, XtNborderWidth, 1, 0);
-
-      XtVaSetValues (widget,
-                    XtNlabel, val->value,
-                    XtNsensitive, val->enabled,
-                    /* Force centered button text.  Se above. */
-                    XtNjustify, XtJustifyCenter,
-                    0);
+       {
+         XtSetArg (al[0], XtNborderWidth, 1);
+         XtSetValues (widget, al, 1);
+       }
 
 
+      XtSetSensitive (widget, val->enabled);
+      XtSetArg (al[0], XtNlabel, val->value);
+      /* Force centered button text.  Se above. */
+      XtSetArg (al[1], XtNjustify, XtJustifyCenter);
+      XtSetValues (widget, al, 2);
       XtRemoveAllCallbacks (widget, XtNcallback);
       XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
     }
 }
 
 void
       XtRemoveAllCallbacks (widget, XtNcallback);
       XtAddCallback (widget, XtNcallback, xaw_generic_callback, instance);
     }
 }
 
 void
-xaw_update_one_value (widget_instance *instance, Widget widget,
-                     widget_value *val)
+xaw_update_one_value (instance, widget, val)
+     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. */
 {
   /* This function is not used by the scrollbars and those are the only
      Athena widget implemented at the moment so do nothing. */
@@ -155,7 +183,8 @@ xaw_update_one_value (widget_instance *instance, Widget widget,
 }
 
 void
 }
 
 void
-xaw_destroy_instance (widget_instance *instance)
+xaw_destroy_instance (instance)
+     widget_instance *instance;
 {
   if (XtIsSubclass (instance->widget, dialogWidgetClass))
     /* Need to destroy the Shell too. */
 {
   if (XtIsSubclass (instance->widget, dialogWidgetClass))
     /* Need to destroy the Shell too. */
@@ -165,14 +194,22 @@ xaw_destroy_instance (widget_instance *instance)
 }
 
 void
 }
 
 void
-xaw_popup_menu (Widget widget)
+xaw_popup_menu (widget, event)
+     Widget widget;
+     XEvent *event;
 {
   /* An Athena menubar has not been implemented. */
   return;
 }
 
 void
 {
   /* An Athena menubar has not been implemented. */
   return;
 }
 
 void
+#ifdef PROTOTYPES
 xaw_pop_instance (widget_instance *instance, Boolean up)
 xaw_pop_instance (widget_instance *instance, Boolean up)
+#else
+xaw_pop_instance (instance, up)
+     widget_instance *instance;
+     Boolean up;
+#endif
 {
   Widget widget = instance->widget;
 
 {
   Widget widget = instance->widget;
 
@@ -200,8 +237,10 @@ xaw_pop_instance (widget_instance *instance, Boolean up)
             life easier?
           */
          {
             life easier?
           */
          {
-           int x, y, w, h;
+           unsigned int x, y, w, h;
            Widget topmost = instance->parent;
            Widget topmost = instance->parent;
+           Arg args[2];
+
            w = shell->core.width;
            h = shell->core.height;
            while (topmost->core.parent && XtIsRealized (topmost->core.parent))
            w = shell->core.width;
            h = shell->core.height;
            while (topmost->core.parent && XtIsRealized (topmost->core.parent))
@@ -210,7 +249,12 @@ xaw_pop_instance (widget_instance *instance, Boolean up)
            else x = topmost->core.x + ((topmost->core.width - w) / 2);
            if (topmost->core.height < h) y = topmost->core.y;
            else y = topmost->core.y + ((topmost->core.height - h) / 2);
            else x = topmost->core.x + ((topmost->core.width - w) / 2);
            if (topmost->core.height < h) y = topmost->core.y;
            else y = topmost->core.y + ((topmost->core.height - h) / 2);
-           XtMoveWidget (shell, x, y);
+           /* Using XtMoveWidget caused the widget to come
+              out in the wrong place with vtwm.
+              Question of virtual vs real coords, perhaps.  */
+           XtSetArg (args[0], XtNx, x);
+           XtSetArg (args[1], XtNy, y);
+           XtSetValues (shell, args, 2);
          }
 
          /* Finally, pop it up. */
          }
 
          /* Finally, pop it up. */
@@ -233,6 +277,9 @@ xaw_pop_instance (widget_instance *instance, Boolean up)
 
 static char overrideTrans[] =
        "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
 
 static char overrideTrans[] =
        "<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
+/* Dialogs pop down on any key press */
+static char dialogOverride[] =
+       "<KeyPress>Escape:      lwlib_delete_dialog()";
 static void wm_delete_window();
 static XtActionsRec xaw_actions [] = {
   {"lwlib_delete_dialog", wm_delete_window}
 static void wm_delete_window();
 static XtActionsRec xaw_actions [] = {
   {"lwlib_delete_dialog", wm_delete_window}
@@ -240,10 +287,17 @@ static XtActionsRec xaw_actions [] = {
 static Boolean actions_initted = False;
 
 static Widget
 static Boolean actions_initted = False;
 
 static Widget
-make_dialog (char* name, Widget parent, Boolean pop_up_p,
-            char* shell_title, char* icon_name, Boolean text_input_slot,
-            Boolean radio_box, Boolean list,
-            int left_buttons, int right_buttons)
+make_dialog (name, parent, pop_up_p, shell_title, icon_name, text_input_slot, radio_box, list, left_buttons, right_buttons)
+     char* name;
+     Widget parent;
+     Boolean pop_up_p;
+     char* shell_title;
+     char* icon_name;
+     Boolean text_input_slot;
+     Boolean radio_box;
+     Boolean list;
+     int left_buttons;
+     int right_buttons;
 {
   Arg av [20];
   int ac = 0;
 {
   Arg av [20];
   int ac = 0;
@@ -272,12 +326,18 @@ make_dialog (char* name, Widget parent, Boolean pop_up_p,
   ac = 0;
   XtSetArg (av[ac], XtNtitle, shell_title); ac++;
   XtSetArg (av[ac], XtNallowShellResize, True); ac++;
   ac = 0;
   XtSetArg (av[ac], XtNtitle, shell_title); ac++;
   XtSetArg (av[ac], XtNallowShellResize, True); ac++;
+
+  /* Don't allow any geometry request from the user.  */
+  XtSetArg (av[ac], XtNgeometry, 0); ac++;
+
   shell = XtCreatePopupShell ("dialog", transientShellWidgetClass,
                              parent, av, ac);
   XtOverrideTranslations (shell, override);
 
   ac = 0;
   dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
   shell = XtCreatePopupShell ("dialog", transientShellWidgetClass,
                              parent, av, ac);
   XtOverrideTranslations (shell, override);
 
   ac = 0;
   dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
+  override = XtParseTranslationTable (dialogOverride);
+  XtOverrideTranslations (dialog, override);
 
   bc = 0;
   button = 0;
 
   bc = 0;
   button = 0;
@@ -301,7 +361,7 @@ make_dialog (char* name, Widget parent, Boolean pop_up_p,
         I want the separator to take up the slack between the buttons on
         the right and the buttons on the left (that is I want the buttons
         after the separator to be packed against the right edge of the
         I want the separator to take up the slack between the buttons on
         the right and the buttons on the left (that is I want the buttons
         after the separator to be packed against the right edge of the
-        window) but I can't seem to make it do it.  
+        window) but I can't seem to make it do it.
        */
       ac = 0;
       XtSetArg (av [ac], XtNfromHoriz, button); ac++;
        */
       ac = 0;
       XtSetArg (av [ac], XtNfromHoriz, button); ac++;
@@ -341,14 +401,15 @@ make_dialog (char* name, Widget parent, Boolean pop_up_p,
 }
 
 Widget
 }
 
 Widget
-xaw_create_dialog (widget_instance* instance)
+xaw_create_dialog (instance)
+     widget_instance* instance;
 {
   char *name = instance->info->type;
   Widget parent = instance->parent;
   Widget widget;
   Boolean pop_up_p = instance->pop_up_p;
   char *shell_name = 0;
 {
   char *name = instance->info->type;
   Widget parent = instance->parent;
   Widget widget;
   Boolean pop_up_p = instance->pop_up_p;
   char *shell_name = 0;
-  char *icon_name;
+  char *icon_name = 0;
   Boolean text_input_slot = False;
   Boolean radio_box = False;
   Boolean list = False;
   Boolean text_input_slot = False;
   Boolean radio_box = False;
   Boolean list = False;
@@ -384,7 +445,7 @@ xaw_create_dialog (widget_instance* instance)
     shell_name = "Question";
     break;
   }
     shell_name = "Question";
     break;
   }
-  
+
   total_buttons = name [1] - '0';
 
   if (name [3] == 'T' || name [3] == 't')
   total_buttons = name [1] - '0';
 
   if (name [3] == 'T' || name [3] == 't')
@@ -394,9 +455,9 @@ xaw_create_dialog (widget_instance* instance)
     }
   else if (name [3])
     right_buttons = name [4] - '0';
     }
   else if (name [3])
     right_buttons = name [4] - '0';
-  
+
   left_buttons = total_buttons - right_buttons;
   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);
   widget = make_dialog (name, parent, pop_up_p,
                        shell_name, icon_name, text_input_slot, radio_box,
                        list, left_buttons, right_buttons);
@@ -406,7 +467,10 @@ xaw_create_dialog (widget_instance* instance)
 
 
 static void
 
 
 static void
-xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
+xaw_generic_callback (widget, closure, call_data)
+     Widget widget;
+     XtPointer closure;
+     XtPointer call_data;
 {
   widget_instance *instance = (widget_instance *) closure;
   Widget instance_widget;
 {
   widget_instance *instance = (widget_instance *) closure;
   Widget instance_widget;
@@ -428,7 +492,7 @@ xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
 
 #if 0
   user_data = NULL;
 
 #if 0
   user_data = NULL;
-  XtVaGetValues (widget, XtNuserData, &user_data, 0);
+  XtVaGetValues (widget, XtNuserData, &user_data, NULL);
 #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
 #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
@@ -452,19 +516,34 @@ xaw_generic_callback (Widget widget, XtPointer closure, XtPointer call_data)
 }
 
 static void
 }
 
 static void
-wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data)
+wm_delete_window (w, closure, call_data)
+     Widget w;
+     XtPointer closure;
+     XtPointer call_data;
 {
   LWLIB_ID id;
 {
   LWLIB_ID id;
+  Cardinal nkids;
+  int i;
   Widget *kids = 0;
   Widget *kids = 0;
-  Widget widget;
+  Widget widget, shell;
+
+  if (XtIsSubclass (w, dialogWidgetClass))
+    shell = XtParent (w);
+  else
+    shell = w;
+
   if (! XtIsSubclass (shell, shellWidgetClass))
     abort ();
   if (! XtIsSubclass (shell, shellWidgetClass))
     abort ();
-  XtVaGetValues (shell, XtNchildren, &kids, 0);
+  XtVaGetValues (shell, XtNnumChildren, &nkids, NULL);
+  XtVaGetValues (shell, XtNchildren, &kids, NULL);
   if (!kids || !*kids)
     abort ();
   if (!kids || !*kids)
     abort ();
-  widget = kids [0];
-  if (! XtIsSubclass (widget, dialogWidgetClass))
-    abort ();
+  for (i = 0; i < nkids; i++)
+    {
+      widget = kids[i];
+      if (XtIsSubclass (widget, dialogWidgetClass))
+       break;
+    }
   id = lw_get_widget_id (widget);
   if (! id) abort ();
 
   id = lw_get_widget_id (widget);
   if (! id) abort ();
 
@@ -481,10 +560,13 @@ wm_delete_window (Widget shell, XtPointer closure, XtPointer call_data)
 \f
 /* Scrollbars */
 
 \f
 /* Scrollbars */
 
+#if 0
 static void
 static void
-xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data)
+xaw_scrollbar_scroll (widget, closure, call_data)
+     Widget widget;
+     XtPointer closure;
+     XtPointer call_data;
 {
 {
-#if 0
   widget_instance *instance = (widget_instance *) closure;
   LWLIB_ID id;
   scroll_event event_data;
   widget_instance *instance = (widget_instance *) closure;
   LWLIB_ID id;
   scroll_event event_data;
@@ -503,13 +585,16 @@ xaw_scrollbar_scroll (Widget widget, XtPointer closure, XtPointer call_data)
 
   if (instance->info->pre_activate_cb)
     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
 
   if (instance->info->pre_activate_cb)
     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
-#endif
 }
 }
+#endif
 
 
+#if 0
 static void
 static void
-xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data)
+xaw_scrollbar_jump (widget, closure, call_data)
+     Widget widget;
+     XtPointer closure;
+     XtPointer call_data;
 {
 {
-#if 0
   widget_instance *instance = (widget_instance *) closure;
   LWLIB_ID id;
   scroll_event event_data;
   widget_instance *instance = (widget_instance *) closure;
   LWLIB_ID id;
   scroll_event event_data;
@@ -531,11 +616,12 @@ xaw_scrollbar_jump (Widget widget, XtPointer closure, XtPointer call_data)
 
   if (instance->info->pre_activate_cb)
     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
 
   if (instance->info->pre_activate_cb)
     instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data);
-#endif
 }
 }
+#endif
 
 static Widget
 
 static Widget
-xaw_create_scrollbar (widget_instance *instance)
+xaw_create_scrollbar (instance)
+     widget_instance *instance;
 {
 #if 0
   Arg av[20];
 {
 #if 0
   Arg av[20];
@@ -543,8 +629,8 @@ xaw_create_scrollbar (widget_instance *instance)
   Dimension width;
   Widget scrollbar;
 
   Dimension width;
   Widget scrollbar;
 
-  XtVaGetValues (instance->parent, XtNwidth, &width, 0);
-  
+  XtVaGetValues (instance->parent, XtNwidth, &width, NULL);
+
   XtSetArg (av[ac], XtNshowGrip, 0); ac++;
   XtSetArg (av[ac], XtNresizeToPreferred, 1); ac++;
   XtSetArg (av[ac], XtNallowResize, True); ac++;
   XtSetArg (av[ac], XtNshowGrip, 0); ac++;
   XtSetArg (av[ac], XtNresizeToPreferred, 1); ac++;
   XtSetArg (av[ac], XtNallowResize, True); ac++;
@@ -558,7 +644,7 @@ xaw_create_scrollbar (widget_instance *instance)
 
   /* We have to force the border width to be 0 otherwise the
      geometry manager likes to start looping for awhile... */
 
   /* We have to force the border width to be 0 otherwise the
      geometry manager likes to start looping for awhile... */
-  XtVaSetValues (scrollbar, XtNborderWidth, 0, 0);
+  XtVaSetValues (scrollbar, XtNborderWidth, 0, NULL);
 
   XtRemoveAllCallbacks (scrollbar, "jumpProc");
   XtRemoveAllCallbacks (scrollbar, "scrollProc");
 
   XtRemoveAllCallbacks (scrollbar, "jumpProc");
   XtRemoveAllCallbacks (scrollbar, "scrollProc");
@@ -569,12 +655,32 @@ xaw_create_scrollbar (widget_instance *instance)
                 (XtPointer) instance);
 
   return scrollbar;
                 (XtPointer) instance);
 
   return scrollbar;
+#else
+  return NULL;
 #endif
 }
 
 #endif
 }
 
+static Widget
+xaw_create_main (instance)
+     widget_instance *instance;
+{
+  Arg al[1];
+  int ac;
+
+  /* Create a vertical Paned to hold menubar */
+  ac = 0;
+  XtSetArg (al[ac], XtNborderWidth, 0); ac++;
+  return XtCreateWidget (instance->info->name, panedWidgetClass,
+                        instance->parent, al, ac);
+}
+
 widget_creation_entry
 xaw_creation_table [] =
 {
   {"scrollbar",                        xaw_create_scrollbar},
 widget_creation_entry
 xaw_creation_table [] =
 {
   {"scrollbar",                        xaw_create_scrollbar},
+  {"main",                     xaw_create_main},
   {NULL, NULL}
 };
   {NULL, NULL}
 };
+
+/* arch-tag: fbbd3589-ae1c-41a0-9142-f628cfee6564
+   (do not change this comment) */