chiark / gitweb /
Initial version.
authormdw <mdw>
Fri, 11 Dec 1998 09:44:21 +0000 (09:44 +0000)
committermdw <mdw>
Fri, 11 Dec 1998 09:44:21 +0000 (09:44 +0000)
.cvsignore [new file with mode: 0644]
.links [new file with mode: 0644]
.skelrc [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
cancel.c [new file with mode: 0644]
cancel.h [new file with mode: 0644]
configure.in [new file with mode: 0644]
mdwfocus.c [new file with mode: 0644]
mdwfocus.h [new file with mode: 0644]
msg.c [new file with mode: 0644]
msg.h [new file with mode: 0644]

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..3b08a19
--- /dev/null
@@ -0,0 +1,4 @@
+Makefile.in
+aclocal.m4
+build
+configure
diff --git a/.links b/.links
new file mode 100644 (file)
index 0000000..10f134c
--- /dev/null
+++ b/.links
@@ -0,0 +1,4 @@
+COPYING
+install-sh
+missing
+mkinstalldirs
diff --git a/.skelrc b/.skelrc
new file mode 100644 (file)
index 0000000..235e96e
--- /dev/null
+++ b/.skelrc
@@ -0,0 +1,8 @@
+;;; -*-emacs-lisp-*-
+
+(setq skel-alist
+      (append
+       '((author . "Straylight/Edgeware")
+        (full-title . "the mgLib GTK utilities library")
+        (program . "mgLib"))
+       skel-alist))
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..28a6626
--- /dev/null
@@ -0,0 +1,45 @@
+## -*-makefile-*-
+##
+## $Id: Makefile.am,v 1.1 1998/12/11 09:44:21 mdw Exp $
+##
+## Makefile for mgLib
+##
+## (c) 1998 Straylight/Edgeware
+##
+
+##----- Licensing notice ----------------------------------------------------
+##
+## This file is part of the mgLib GTK utilities library.
+##
+## mgLib 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 of the License, or
+## (at your option) any later version.
+## 
+## mgLib is distributed in the hope that it will be useful,
+## 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 mgLib; if not, write to the Free Software Foundation,
+## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+##----- Revision history ----------------------------------------------------
+##
+## $Log: Makefile.am,v $
+## Revision 1.1  1998/12/11 09:44:21  mdw
+## Initial version.
+##
+
+AUTOMAKE_OPTIONS = foreign
+
+lib_LIBRARIES = libmgLib.a
+
+INCLUDES = -I$(topsrcdir)/mLib -I$(srcdir)/../mLib
+
+libmgLib_a_SOURCES = \
+       msg.c mdwfocus.c cancel.c \
+       msg.h mdwfocus.h cancel.h
+
+##----- That's all, folks ---------------------------------------------------
diff --git a/cancel.c b/cancel.c
new file mode 100644 (file)
index 0000000..c7605dd
--- /dev/null
+++ b/cancel.c
@@ -0,0 +1,75 @@
+/* -*-c-*-
+ *
+ * $Id: cancel.c,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Handle Escape keypresses, directing them to cancel buttons
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: cancel.c,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "cancel.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @cancel@ --- *
+ *
+ * Arguments:  @GtkWindow *win@ = window in which this is happening
+ *             @GtkWidget *w@ = widget to activate, or null
+ *
+ * Returns:    ---
+ *
+ * Use:                Sets up @win@ so that a press of `escape' will activate
+ *             @w@ or destroy @win@.
+ */
+
+static gboolean cancel_press(GtkWidget *w, GdkEventKey *ev, gpointer *p)
+{
+  if (ev->keyval == GDK_Escape) {
+    if (p)
+      gtk_widget_activate(GTK_WIDGET(p));
+    else
+      gtk_object_destroy(GTK_OBJECT(w));
+    return (1);
+  }
+  return (0);
+}
+
+void cancel(GtkWindow *win, GtkWidget *w)
+{
+  gtk_signal_connect(GTK_OBJECT(win), "key_press_event",
+                    GTK_SIGNAL_FUNC(cancel_press), w);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/cancel.h b/cancel.h
new file mode 100644 (file)
index 0000000..aa78df6
--- /dev/null
+++ b/cancel.h
@@ -0,0 +1,69 @@
+/* -*-c-*-
+ *
+ * $Id: cancel.h,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Handle Escape keypresses, directing them to cancel buttons
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: cancel.h,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+#ifndef CANCEL_H
+#define CANCEL_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <gtk/gtk.h>
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @cancel@ --- *
+ *
+ * Arguments:  @GtkWindow *win@ = window in which this is happening
+ *             @GtkWidget *w@ = widget to activate, or null
+ *
+ * Returns:    ---
+ *
+ * Use:                Sets up @win@ so that a press of `escape' will activate
+ *             @w@ or destroy @win@.
+ */
+
+extern void cancel(GtkWindow */*win*/, GtkWidget */*w*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif
diff --git a/configure.in b/configure.in
new file mode 100644 (file)
index 0000000..517bef9
--- /dev/null
@@ -0,0 +1,53 @@
+dnl -*-fundamental-*-
+dnl
+dnl $Id: configure.in,v 1.1 1998/12/11 09:44:21 mdw Exp $
+dnl
+dnl Configuration script for mgLib
+dnl
+dnl (c) 1998 Straylight/Edgeware
+dnl
+
+dnl ----- Licensing notice --------------------------------------------------
+dnl
+dnl This file is part of the mgLib GTK utilities library.
+dnl
+dnl mgLib is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl 
+dnl mgLib is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl 
+dnl You should have received a copy of the GNU General Public License
+dnl along with mgLib; if not, write to the Free Software Foundation,
+dnl Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+dnl ----- Revision history --------------------------------------------------
+dnl
+dnl $Log: configure.in,v $
+dnl Revision 1.1  1998/12/11 09:44:21  mdw
+dnl Initial version.
+dnl
+
+AC_INIT(mdwfocus.c)
+AM_INIT_AUTOMAKE(mgLib, 1.0.0)
+
+AC_PROG_CC
+mdw_GCC_FLAGS
+AC_CHECK_PROG(AR, ar, ar)
+AC_PROG_RANLIB
+AC_PROG_INSTALL
+
+AM_PATH_GTK(1.0.0,
+            [LIBS="$LIBS $GTK_LIBS" CFLAGS="$CFLAGS $GTK_CFLAGS"],
+            [AC_MSG_ERROR([couldn't find GTK])])
+
+mdw_OPT_mLib_DEBUG(mgLib)
+AC_CHECK_FUNCS(vsnprintf)
+
+AC_OUTPUT(Makefile)
+
+dnl ----- That's all, folks -------------------------------------------------
diff --git a/mdwfocus.c b/mdwfocus.c
new file mode 100644 (file)
index 0000000..918d751
--- /dev/null
@@ -0,0 +1,69 @@
+/* -*-c-*-
+ *
+ * $Id: mdwfocus.c,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Tell my hacked `fvwm' to focus this window
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: mdwfocus.c,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @mdwfocus@ --- *
+ *
+ * Arguments:  @GtkWidget *w@ = widget to mark as must-be-focussed.
+ *
+ * Returns:    ---
+ *
+ * Use:                Marks a window as wanting to have focus `anyway', even if
+ *             normally disabled.  This only works with my hacked `fvwm'
+ *             version.
+ */
+
+void mdwfocus(GtkWidget *w)
+{
+  static GdkAtom a = 0;
+  unsigned char c = 1;
+
+  if (!a)
+    a = gdk_atom_intern("FVWM_GIVE_ME_FOCUS", 0);
+  gdk_property_change(w->window, a, XA_CARDINAL, 8,
+                     GDK_PROP_MODE_REPLACE, &c, 1);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/mdwfocus.h b/mdwfocus.h
new file mode 100644 (file)
index 0000000..06b7254
--- /dev/null
@@ -0,0 +1,69 @@
+/* -*-c-*-
+ *
+ * $Id: mdwfocus.h,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Tell my hacked `fvwm' to focus this window
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: mdwfocus.h,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+#ifndef MDWFOCUS_H
+#define MDWFOCUS_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <gtk/gtk.h>
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @mdwfocus@ --- *
+ *
+ * Arguments:  @GtkWidget *w@ = widget to mark as must-be-focussed.
+ *
+ * Returns:    ---
+ *
+ * Use:                Marks a window as wanting to have focus `anyway', even if
+ *             normally disabled.  This only works with my hacked `fvwm'
+ *             version.
+ */
+
+extern void mdwfocus(GtkWidget */*w*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif
diff --git a/msg.c b/msg.c
new file mode 100644 (file)
index 0000000..6c0ca9d
--- /dev/null
+++ b/msg.c
@@ -0,0 +1,172 @@
+/* -*-c-*-
+ *
+ * $Id: msg.c,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Display a message and get an answer
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: msg.c,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+#include <mLib/alloc.h>
+
+#include "cancel.h"
+#include "mdwfocus.h"
+#include "msg.h"
+
+/*----- Static variables --------------------------------------------------*/
+
+static int reply;
+static int creply;
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @msg@ --- *
+ *
+ * Arguments:  @char *buttons@ = the button strings to display
+ *             @char *msg@ = the message skeleton string
+ *
+ * Returns:    Index of the button selected.
+ *
+ * Use:                Displays a message to the user in a nice dialogue box and
+ *             returns the index of the button selected.
+ */
+
+static int close(GtkWidget *w, gpointer p)
+{
+  reply = creply;
+  gtk_main_quit();
+  return (1);
+}
+
+static void click(GtkWidget *w, gpointer p)
+{
+  reply = (int)p;
+  gtk_main_quit();
+}
+
+int msg(const char *buttons, const char *msg, ...)
+{
+  GtkWidget *dbox, *w;
+
+  /* --- Make most of the dialogue box --- */
+
+  dbox = gtk_dialog_new();
+  gtk_signal_connect(GTK_OBJECT(dbox), "delete_event",
+                    GTK_SIGNAL_FUNC(close), 0);
+  gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(dbox)->action_area), 0);  
+
+  /* --- Set up the message string --- */
+
+  {
+    char buf[1024];
+    va_list ap;
+
+    va_start(ap, msg);
+#ifdef HAVE_VSNPRINTF
+    vsnprintf(buf, sizeof(buf), msg, ap);
+#else
+    vsprintf(buf, sizeof(buf), msg, ap);
+#endif
+    va_end(ap);
+    w = gtk_label_new(buf);
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dbox)->vbox), w, 1, 1, 0);
+    gtk_window_position(GTK_WINDOW(dbox), GTK_WIN_POS_MOUSE);
+    gtk_widget_show(w);
+    gtk_misc_set_padding(GTK_MISC(w), 16, 16);
+  }
+
+  /* --- Set up the buttons --- */
+
+  {
+    char *p = xstrdup(buttons);
+    unsigned f = 0;
+    int i = 0;
+
+    enum {
+      f_ok = 1,
+      f_cancel = 2,
+      f_mdwfocus = 4
+    };
+
+    if (*p == '!') {
+      f |= f_mdwfocus;
+      p++;
+    }
+
+    creply = -1;
+
+    for (p = strtok(p, ","); p; p = strtok(0, ","), i++) {
+      unsigned ff = 0;
+      if (*p == ':') {
+       ff |= f_ok;
+       p++;
+      }
+      if (*p == '~') {
+       ff |= f_cancel;
+       creply = i;
+       p++;
+      }
+      w = gtk_button_new_with_label(p);
+      GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
+      gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dbox)->action_area), w, 0, 0, 0);
+      gtk_signal_connect(GTK_OBJECT(w), "clicked",
+                        GTK_SIGNAL_FUNC(click), (gpointer)i);
+      if (ff & f_ok)
+       gtk_widget_grab_default(w);
+      if (ff & f_cancel)
+       cancel(GTK_WINDOW(dbox), w);
+      gtk_widget_show(w);
+    }
+
+    gtk_widget_realize(dbox);
+    if (f & f_mdwfocus)
+      mdwfocus(dbox);
+  }
+
+  /* --- Ready --- */
+
+  gtk_grab_add(GTK_WIDGET(dbox));
+  gtk_widget_show(dbox);
+  gtk_main();
+  gtk_grab_remove(GTK_WIDGET(dbox));
+  gtk_widget_destroy(dbox);
+  return (reply);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/msg.h b/msg.h
new file mode 100644 (file)
index 0000000..f4f1214
--- /dev/null
+++ b/msg.h
@@ -0,0 +1,69 @@
+/* -*-c-*-
+ *
+ * $Id: msg.h,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ *
+ * Display a message and get an answer
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mgLib GTK utilities library.
+ *
+ * mgLib 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 of the License, or
+ * (at your option) any later version.
+ * 
+ * mgLib is distributed in the hope that it will be useful,
+ * 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 mgLib; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: msg.h,v $
+ * Revision 1.1  1998/12/11 09:44:21  mdw
+ * Initial version.
+ *
+ */
+
+#ifndef MSG_H
+#define MSG_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <gtk/gtk.h>
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @msg@ --- *
+ *
+ * Arguments:  @char *buttons@ = the button strings to display
+ *             @char *msg@ = the message skeleton string
+ *
+ * Returns:    Index of the button selected.
+ *
+ * Use:                Displays a message to the user in a nice dialogue box and
+ *             returns the index of the button selected.
+ */
+
+extern int msg(const char */*buttons*/, const char */*msg*/, ...);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif