From 233715861c7ca405b08c73e37f6c97d21437a13b Mon Sep 17 00:00:00 2001
From: Edward Hennessy <[EMAIL PROTECTED]>
Date: Sun, 27 Jul 2008 22:25:11 -0700
Subject: [PATCH] Created template function for GtkAction activate signal 
handlers.

---
 gschem/include/prototype.h |   20 +++---
 gschem/src/i_callbacks.c   |  152 ++++++++------------------------------------
 gschem/src/x_window.c      |   20 +++---
 3 files changed, 46 insertions(+), 146 deletions(-)

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index f0086e2..11f1478 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -305,13 +305,13 @@ void i_set_filename(GSCHEM_TOPLEVEL *w_current, const 
gchar *string);
 void i_set_grid(GSCHEM_TOPLEVEL *w_current, int visible_grid);
 /* i_callbacks.c */
 void i_callback_file_new(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_file_new(GtkWidget *widget, gpointer data);
+void i_callback_action_file_new(GtkWidget *widget, gpointer data);
 void i_callback_file_new_window(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_file_open(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_file_open(GtkWidget *widget, gpointer data);
+void i_callback_action_file_open(GtkWidget *widget, gpointer data);
 void i_callback_file_script(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_file_save(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_file_save(GtkWidget *widget, gpointer data);
+void i_callback_action_file_save(GtkWidget *widget, gpointer data);
 void i_callback_file_save_all(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_file_save_as(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_file_print(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
@@ -320,11 +320,11 @@ void i_callback_file_close(SCM rest, gpointer data, guint 
callback_action, GtkWi
 int i_callback_close(gpointer data, guint callback_action, GtkWidget *widget);
 void i_callback_file_quit(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_edit_undo(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_edit_undo(GtkWidget *widget, gpointer data);
+void i_callback_action_edit_undo(GtkWidget *widget, gpointer data);
 void i_callback_edit_redo(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_edit_redo(GtkWidget *widget, gpointer data);
+void i_callback_action_edit_redo(GtkWidget *widget, gpointer data);
 void i_callback_edit_select(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_edit_select(GtkWidget *widget, gpointer data);
+void i_callback_action_edit_select(GtkWidget *widget, gpointer data);
 void i_callback_edit_copy(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_edit_copy_hotkey(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_edit_mcopy(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
@@ -400,17 +400,17 @@ void i_callback_buffer_paste3_hotkey(SCM rest, gpointer 
data, guint callback_act
 void i_callback_buffer_paste4_hotkey(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_buffer_paste5_hotkey(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_add_component(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_add_component(GtkWidget *widget, gpointer data);
+void i_callback_action_add_component(GtkWidget *widget, gpointer data);
 void i_callback_add_attribute(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_add_attribute_hotkey(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_add_net(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_add_net_hotkey(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_add_net(GtkWidget *widget, gpointer data);
+void i_callback_action_add_net(GtkWidget *widget, gpointer data);
 void i_callback_add_bus(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_add_bus_hotkey(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_add_bus(GtkWidget *widget, gpointer data);
+void i_callback_action_add_bus(GtkWidget *widget, gpointer data);
 void i_callback_add_text(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
-void i_callback_toolbar_add_text(GtkWidget *widget, gpointer data);
+void i_callback_action_add_text(GtkWidget *widget, gpointer data);
 void i_callback_add_line(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
 void i_callback_add_line_hotkey(SCM rest, gpointer data, guint 
callback_action, GtkWidget *widget);
 void i_callback_add_box(SCM rest, gpointer data, guint callback_action, 
GtkWidget *widget);
diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c
index 7bd559d..7bd9496 100644
--- a/gschem/src/i_callbacks.c
+++ b/gschem/src/i_callbacks.c
@@ -146,6 +146,29 @@ static void initiate_gschemdoc(const char* 
documentation,const char *device,
 #endif
 }
 
+/* \par Create adapters for GtkAction "activate" signal handlers.  These
+ * functions adapt the GtkAction "activate" function signature to the classic
+ * i_callback function signature.
+ */
+#define ACTION_ADAPTER(name) \
+void i_callback_action_ ## name (GtkWidget *widget, gpointer data) \
+{                                                                  \
+  GSCHEM_TOPLEVEL *w_current;                                      \
+  g_assert(data != NULL);                                          \
+  w_current = (GSCHEM_TOPLEVEL*) data;                             \
+  if (w_current->window != NULL) {                                 \
+    i_callback_ ## name (SCM_EOL, data, 0, NULL);                  \
+  }                                                                \
+}
+
+ACTION_ADAPTER(add_component)
+ACTION_ADAPTER(add_text)
+ACTION_ADAPTER(edit_redo)
+ACTION_ADAPTER(edit_undo)
+ACTION_ADAPTER(file_new)
+ACTION_ADAPTER(file_open)
+ACTION_ADAPTER(file_save)
+
 /*! \todo Finish function documentation!!!
  *  \brief
  *  \par Function Description
@@ -191,23 +214,6 @@ DEFINE_I_CALLBACK(file_new)
  *  \brief
  *  \par Function Description
  *
- *  \note
- *  don't use the widget parameter on this function, or do some checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
- */
-void i_callback_toolbar_file_new(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-    
-  i_callback_file_new(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
  */
 DEFINE_I_CALLBACK(file_new_window)
 {
@@ -246,25 +252,6 @@ DEFINE_I_CALLBACK(file_open)
  *  \brief
  *  \par Function Description
  *
- *  \note
- *  don't use the widget parameter on this function, or do some
- *  checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current)
- *  \todo This should be renamed to page_open perhaps...
- */
-void i_callback_toolbar_file_open(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_file_open(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
  */
 DEFINE_I_CALLBACK(file_script)
 {
@@ -309,25 +296,6 @@ DEFINE_I_CALLBACK(file_save)
  *  \par Function Description
  *
  *  \note
- *  don't use the widget parameter on this function, or do some
- *  checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current)
- *  \todo This should be renamed to page_open perhaps...
- */
-void i_callback_toolbar_file_save(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_file_save(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- *  \note
  *  don't use the widget parameter on this function, or do some checking...
  *  since there is a call: widget = NULL, data = 0 (will be w_current)
  */
@@ -484,23 +452,6 @@ DEFINE_I_CALLBACK(edit_undo)
  *  \brief
  *  \par Function Description
  *
- *  \note
- *  don't use the widget parameter on this function, or do some checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
- */
-void i_callback_toolbar_edit_undo(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_edit_undo(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
  */
 DEFINE_I_CALLBACK(edit_redo)
 {
@@ -515,23 +466,6 @@ DEFINE_I_CALLBACK(edit_redo)
  *  \par Function Description
  *
  *  \note
- *  don't use the widget parameter on this function, or do some checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
- */
-void i_callback_toolbar_edit_redo(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_edit_redo(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- *  \note
  *  Select also does not update the middle button shortcut.
  */
 DEFINE_I_CALLBACK(edit_select)
@@ -553,7 +487,7 @@ DEFINE_I_CALLBACK(edit_select)
  *  don't use the widget parameter on this function, or do some checking...
  * since there is a call: widget = NULL, data = 0 (will be w_current hack)
  */
-void i_callback_toolbar_edit_select(GtkWidget* widget, gpointer data)
+void i_callback_action_edit_select(GtkWidget* widget, gpointer data)
 {
   GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
   exit_if_null(w_current);
@@ -2285,23 +2219,6 @@ DEFINE_I_CALLBACK(add_component)
  *  \brief
  *  \par Function Description
  *
- *  \note
- *  don't use the widget parameter on this function, or do some checking... 
- *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
- */
-void i_callback_toolbar_add_component(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_add_component(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
  */
 DEFINE_I_CALLBACK(add_attribute)
 {
@@ -2397,7 +2314,7 @@ DEFINE_I_CALLBACK(add_net_hotkey)
  *  don't use the widget parameter on this function, or do some checking...
  *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
  */
-void i_callback_toolbar_add_net(GtkWidget* widget, gpointer data)
+void i_callback_action_add_net(GtkWidget* widget, gpointer data)
 {
   GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
   exit_if_null(w_current);
@@ -2468,7 +2385,7 @@ DEFINE_I_CALLBACK(add_bus_hotkey)
  *  don't use the widget parameter on this function, or do some checking...
  *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
  */
-void i_callback_toolbar_add_bus(GtkWidget* widget, gpointer data)
+void i_callback_action_add_bus(GtkWidget* widget, gpointer data)
 {
   GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
   exit_if_null(w_current);
@@ -2504,23 +2421,6 @@ DEFINE_I_CALLBACK(add_text)
  *  \brief
  *  \par Function Description
  *
- *  \note
- *  don't use the widget parameter on this function, or do some checking...
- *  since there is a call: widget = NULL, data = 0 (will be w_current hack)
- */
-void i_callback_toolbar_add_text(GtkWidget* widget, gpointer data)
-{
-  GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data;
-  exit_if_null(w_current);
-  if (!w_current->window) return;
-
-  i_callback_add_text(SCM_EOL, data, 0, NULL);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
  */
 DEFINE_I_CALLBACK(add_line)
 {
diff --git a/gschem/src/x_window.c b/gschem/src/x_window.c
index bed6b6d..e3d9d56 100644
--- a/gschem/src/x_window.c
+++ b/gschem/src/x_window.c
@@ -324,21 +324,21 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("New file"), 
                              "toolbar/new", 
                              x_icons_stock_pixmap(GTK_STOCK_NEW),
-                             (GtkSignalFunc) i_callback_toolbar_file_new, 
+                             (GtkSignalFunc) i_callback_action_file_new, 
                              w_current);
     gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                              _("Open"), 
                              _("Open file..."), 
                              "toolbar/open",
                              x_icons_stock_pixmap(GTK_STOCK_OPEN),
-                             (GtkSignalFunc) i_callback_toolbar_file_open, 
+                             (GtkSignalFunc) i_callback_action_file_open, 
                              w_current);
     gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                              _("Save"), 
                              _("Save file"), 
                              "toolbar/save", 
                              x_icons_stock_pixmap(GTK_STOCK_SAVE),
-                             (GtkSignalFunc) i_callback_toolbar_file_save, 
+                             (GtkSignalFunc) i_callback_action_file_save, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
     gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
@@ -346,14 +346,14 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Undo last operation"), 
                              "toolbar/undo", 
                              x_icons_stock_pixmap(GTK_STOCK_UNDO),
-                             (GtkSignalFunc) i_callback_toolbar_edit_undo, 
+                             (GtkSignalFunc) i_callback_action_edit_undo, 
                              w_current);
     gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
                              _("Redo"), 
                              _("Redo last undo"), 
                              "toolbar/redo", 
                              x_icons_stock_pixmap(GTK_STOCK_REDO),
-                             (GtkSignalFunc) i_callback_toolbar_edit_redo, 
+                             (GtkSignalFunc) i_callback_action_edit_redo, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
     /* not part of any radio button group */
@@ -362,7 +362,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Add component...\nSelect library and component 
from list, move the mouse into main window, click to place\nRight mouse button 
to cancel"), 
                              "toolbar/component", 
                              x_icons_stock_pixmap(GSCHEM_STOCK_COMPONENT),
-                             (GtkSignalFunc) i_callback_toolbar_add_component, 
+                             (GtkSignalFunc) i_callback_action_add_component, 
                              w_current);
     w_current->toolbar_net = 
       gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
@@ -372,7 +372,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Add nets mode\nRight mouse button to 
cancel"),
                                  "toolbar/nets",
                                  x_icons_stock_pixmap(GSCHEM_STOCK_NET),
-                                 (GtkSignalFunc) i_callback_toolbar_add_net,
+                                 (GtkSignalFunc) i_callback_action_add_net,
                                  w_current);
     w_current->toolbar_bus = 
       gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
@@ -382,7 +382,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Add buses mode\nRight mouse button to 
cancel"),
                                  "toolbar/bus",
                                  x_icons_stock_pixmap(GSCHEM_STOCK_BUS),
-                                 (GtkSignalFunc) i_callback_toolbar_add_bus,
+                                 (GtkSignalFunc) i_callback_action_add_bus,
                                  w_current);
     /* not part of any radio button group */
     gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
@@ -390,7 +390,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Add Text..."), 
                              "toolbar/text", 
                              x_icons_stock_pixmap(GSCHEM_STOCK_TEXT),
-                             (GtkSignalFunc) i_callback_toolbar_add_text, 
+                             (GtkSignalFunc) i_callback_action_add_text, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
     w_current->toolbar_select = 
@@ -401,7 +401,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Select mode"),
                                  "toolbar/select",
                                  x_icons_stock_pixmap(GSCHEM_STOCK_SELECT),
-                                 (GtkSignalFunc) 
i_callback_toolbar_edit_select, 
+                                 (GtkSignalFunc) 
i_callback_action_edit_select, 
                                  w_current);
 
 
-- 
1.5.6


_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to