From 1bf79957787d6db2b5996d9ecd40c4e05f4570f8 Mon Sep 17 00:00:00 2001
From: Edward Hennessy <[EMAIL PROTECTED]>
Date: Wed, 30 Jul 2008 20:21:22 -0700
Subject: [PATCH] Various cleanup and fixes

- Added missing file x_icons.h to include/Makefile.am.
- Changed comments and whitespace to match gEDA style.
- Optimized loop in x_icons_init() (x_icons.c).
- Changed g_strconcat() to g_build_filename() (x_icons.c).
- Renamed function x_icons_stock_pixmap() to x_icons_new_toolbar_icon()
  in file x_icons.c.
- Moved x_icons_init() function call from x_window_setup() to main_prog().
  Moving this function only creates one GtkIconFactory per application instead
  of one GtkIconFactory per window.
- Changed x_icons_init(GSCHEM_TOPLEVEL *w_current) to
  x_icons_init(const gchar *bitmap_directory), since only the bitmap
  directory is required by the function.
- Moved x_window_set_default_icon() from x_window.c to x_icons.c (as
  x_icons_set_default_icon()).
---
 gschem/include/Makefile.am |    2 +-
 gschem/include/prototype.h |    6 ++--
 gschem/src/gschem.c        |    5 ++-
 gschem/src/i_callbacks.c   |    6 ++--
 gschem/src/x_icons.c       |   77 +++++++++++++++++++++++++++++++++----------
 gschem/src/x_window.c      |   64 ++++++------------------------------
 6 files changed, 79 insertions(+), 81 deletions(-)

diff --git a/gschem/include/Makefile.am b/gschem/include/Makefile.am
index c893c6b..1392507 100644
--- a/gschem/include/Makefile.am
+++ b/gschem/include/Makefile.am
@@ -5,7 +5,7 @@
 noinst_HEADERS = \
        globals.h i_vars.h prototype.h x_dialog.h x_states.h \
        gettext.h \
-       x_compselect.h \
+       x_compselect.h x_icons.h \
        x_log.h x_multiattrib.h x_pagesel.h x_print.h x_preview.h \
        gschem_dialog.h \
        gschem_struct.h
diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index 11f1478..043c2e4 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -806,8 +806,9 @@ int x_fileselect_load_backup(TOPLEVEL *toplevel, GString 
*message);
 void x_grid_draw(GSCHEM_TOPLEVEL *w_current);
 void x_draw_tiles(GSCHEM_TOPLEVEL *w_current);
 /* x_icons.c */
-void x_icons_init(GSCHEM_TOPLEVEL *w_current);
-GtkWidget *x_icons_stock_pixmap(const gchar *stock_id);
+void x_icons_init(const gchar *bitmap_directory);
+GtkWidget *x_icons_new_toolbar_pixmap(const gchar *stock_id);
+void x_icons_set_default_icon(void);
 /* x_image.c */
 void x_image_lowlevel(GSCHEM_TOPLEVEL *w_current, const char* filename,
                      int desired_width, int desired_height, char *filetype);
@@ -865,4 +866,3 @@ PAGE *x_window_open_page (GSCHEM_TOPLEVEL *w_current, const 
gchar *filename);
 void x_window_set_current_page (GSCHEM_TOPLEVEL *w_current, PAGE *page);
 gint x_window_save_page (GSCHEM_TOPLEVEL *w_current, PAGE *page, const gchar 
*filename);
 void x_window_close_page (GSCHEM_TOPLEVEL *w_current, PAGE *page);
-void x_window_set_default_icon (void);
diff --git a/gschem/src/gschem.c b/gschem/src/gschem.c
index 2ae8d51..63790f0 100644
--- a/gschem/src/gschem.c
+++ b/gschem/src/gschem.c
@@ -243,8 +243,9 @@ void main_prog(void *closure, int argc, char *argv[])
   recent_files_load();
   gschem_atexit(recent_files_save, NULL);
 
-  /* Set default icon */
-  x_window_set_default_icon();
+  /* Set default icon; load gschem's ui icons */
+  x_icons_set_default_icon();
+  x_icons_init(default_bitmap_directory);
 
   /* At end, complete set up of window. */
   colormap = gdk_colormap_get_system ();
diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c
index 7bd9496..6c2141d 100644
--- a/gschem/src/i_callbacks.c
+++ b/gschem/src/i_callbacks.c
@@ -146,9 +146,9 @@ 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.
+/* 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) \
diff --git a/gschem/src/x_icons.c b/gschem/src/x_icons.c
index a476096..3425fa3 100644
--- a/gschem/src/x_icons.c
+++ b/gschem/src/x_icons.c
@@ -32,6 +32,9 @@
 #include <dmalloc.h>
 #endif
 
+#define GSCHEM_THEME_ICON_NAME "geda-gschem"
+#define GSCHEM_ICON_SIZES 16, 22, 48
+
 typedef struct _icon_entry icon_entry;
 
 struct _icon_entry
@@ -54,38 +57,37 @@ static const icon_entry icon_table[] =
 #define ICONS_SIZE (sizeof(icon_table)/sizeof(icon_entry))
 
 /*! \brief Create and register gschem's icon factory.
- *  \par Since the application can operate with missing icons, this function
+ *
+ *  Since the application can operate with missing icons, this function
  *  treats a the failure to load an icon as a warning.
- *  \param w_current A pointer to GSCHEM_TOPLEVEL used to obtain the bitmap
- *   directory.  The w_current->toplevel->bitmap_directory must not be NULL.
+ *  
+ *  \param [in] bitmap_directory The directory containing the toolbar icons.
+ *  The bitmap_directory must not be NULL.
  */
-void x_icons_init(GSCHEM_TOPLEVEL *w_current)
+void x_icons_init(const gchar *bitmap_directory)
 {
   GError *error=NULL;
   GtkIconFactory *factory;
-  gchar *filename=NULL;
+  gchar *filename;
   int i;
   GtkIconSet *icons;
   GdkPixbuf *pixbuf;
 
-  g_assert(w_current!=NULL);
-  g_assert(w_current->toplevel!=NULL);
-  g_assert(w_current->toplevel->bitmap_directory!=NULL);
+  g_assert(bitmap_directory != NULL);
 
   factory = gtk_icon_factory_new();
  
   for (i=0; i<ICONS_SIZE; i++) {
-    g_clear_error(&error);
-    g_free(filename);
 
-    filename=g_strconcat(w_current->toplevel->bitmap_directory,
-                         G_DIR_SEPARATOR_S, 
-                         icon_table[i].filename, NULL);
+    filename=g_build_filename(bitmap_directory,
+                              icon_table[i].filename, NULL);
 
     pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+    g_free(filename);
 
-    if (pixbuf==NULL) {
+    if (pixbuf == NULL) {
       g_warning("Loading icons: %s\n",error->message);
+      g_clear_error(&error);
       continue;
     }
     
@@ -95,8 +97,6 @@ void x_icons_init(GSCHEM_TOPLEVEL *w_current)
     gtk_icon_factory_add(factory, icon_table[i].stock_id, icons);
     gtk_icon_set_unref(icons);
   }
-  g_clear_error(&error);
-  g_free(filename);
 
   gtk_icon_factory_add_default(factory);
 
@@ -108,10 +108,51 @@ void x_icons_init(GSCHEM_TOPLEVEL *w_current)
  * If a stock GTK icon with the requested name was not found, this function
  * falls back to the bitmap icons provided in the distribution.
  *
- * \param stock Name of the stock icon ("new", "open", etc.)
+ * \param [in] stock_id Name of the stock icon ("new", "open", etc.)
  * \return Pointer to the new GtkImage object.
  */
-GtkWidget *x_icons_stock_pixmap(const gchar *stock_id)
+GtkWidget *x_icons_new_toolbar_pixmap(const gchar *stock_id)
 {
   return gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_LARGE_TOOLBAR);
 }
+
+/*! \brief Setup default icon for GTK windows
+ *
+ *  \par Function Description
+ *  Sets the default window icon by name, to be found in the current icon
+ *  theme. The name used is #defined above as GSCHEM_THEME_ICON_NAME.
+ *
+ *  For GTK versions < 2.6, we have to load the icons explicitly, and pass
+ *  them to GTK. As we don't know what size is appropriate, a #define above,
+ *  GSCHEM_ICON_SIZES is used to list (comma separated) the sizes we have
+ *  icons for. Icons loaded at all of these sizes are passed to GTK.
+ */
+void x_icons_set_default_icon( void )
+{
+#if GTK_CHECK_VERSION (2,6,0)
+  gtk_window_set_default_icon_name( GSCHEM_THEME_ICON_NAME );
+#else
+  GtkIconTheme *icon_theme;
+  GdkPixbuf *icon;
+  GList *icon_list = NULL;
+  int icon_size[] = { GSCHEM_ICON_SIZES };
+  int i;
+
+  for ( i = 0; i < sizeof( icon_size ) / sizeof( *icon_size ); i++ ) {
+    icon_theme = gtk_icon_theme_get_default();
+    icon = gtk_icon_theme_load_icon( icon_theme,
+                                     GSCHEM_THEME_ICON_NAME,
+                                     icon_size[i],
+                                     0,   /* flags */
+                                     NULL /* **error */ );
+    if (icon != NULL)
+      icon_list = g_list_append( icon_list, icon );
+  }
+
+  gtk_window_set_default_icon_list( icon_list );
+
+  g_list_foreach( icon_list, (GFunc) g_object_unref, NULL );
+  g_list_free( icon_list );
+#endif
+}
+
diff --git a/gschem/src/x_window.c b/gschem/src/x_window.c
index e3d9d56..f267c2e 100644
--- a/gschem/src/x_window.c
+++ b/gschem/src/x_window.c
@@ -33,9 +33,6 @@
 #include <dmalloc.h>
 #endif
 
-#define GSCHEM_THEME_ICON_NAME "geda-gschem"
-#define GSCHEM_ICON_SIZES 16, 22, 48
-
 /*! \todo Finish function documentation!!!
  *  \brief
  *  \par Function Description
@@ -48,8 +45,6 @@ void x_window_setup (GSCHEM_TOPLEVEL *w_current)
   /* immediately setup user params */
   i_vars_set(w_current);
 
-  x_icons_init(w_current);
-
   /* Initialize the autosave callback */
   s_page_autosave_init(toplevel);
 
@@ -323,21 +318,21 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("New"), 
                              _("New file"), 
                              "toolbar/new", 
-                             x_icons_stock_pixmap(GTK_STOCK_NEW),
+                             x_icons_new_toolbar_pixmap(GTK_STOCK_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),
+                             x_icons_new_toolbar_pixmap(GTK_STOCK_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),
+                             x_icons_new_toolbar_pixmap(GTK_STOCK_SAVE),
                              (GtkSignalFunc) i_callback_action_file_save, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -345,14 +340,14 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Undo"), 
                              _("Undo last operation"), 
                              "toolbar/undo", 
-                             x_icons_stock_pixmap(GTK_STOCK_UNDO),
+                             x_icons_new_toolbar_pixmap(GTK_STOCK_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),
+                             x_icons_new_toolbar_pixmap(GTK_STOCK_REDO),
                              (GtkSignalFunc) i_callback_action_edit_redo, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -361,7 +356,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Component"), 
                              _("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),
+                             
x_icons_new_toolbar_pixmap(GSCHEM_STOCK_COMPONENT),
                              (GtkSignalFunc) i_callback_action_add_component, 
                              w_current);
     w_current->toolbar_net = 
@@ -371,7 +366,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Nets"),
                                  _("Add nets mode\nRight mouse button to 
cancel"),
                                  "toolbar/nets",
-                                 x_icons_stock_pixmap(GSCHEM_STOCK_NET),
+                                 x_icons_new_toolbar_pixmap(GSCHEM_STOCK_NET),
                                  (GtkSignalFunc) i_callback_action_add_net,
                                  w_current);
     w_current->toolbar_bus = 
@@ -381,7 +376,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Bus"),
                                  _("Add buses mode\nRight mouse button to 
cancel"),
                                  "toolbar/bus",
-                                 x_icons_stock_pixmap(GSCHEM_STOCK_BUS),
+                                 x_icons_new_toolbar_pixmap(GSCHEM_STOCK_BUS),
                                  (GtkSignalFunc) i_callback_action_add_bus,
                                  w_current);
     /* not part of any radio button group */
@@ -389,7 +384,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                              _("Text"), 
                              _("Add Text..."), 
                              "toolbar/text", 
-                             x_icons_stock_pixmap(GSCHEM_STOCK_TEXT),
+                             x_icons_new_toolbar_pixmap(GSCHEM_STOCK_TEXT),
                              (GtkSignalFunc) i_callback_action_add_text, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -400,7 +395,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current)
                                  _("Select"),
                                  _("Select mode"),
                                  "toolbar/select",
-                                 x_icons_stock_pixmap(GSCHEM_STOCK_SELECT),
+                                 
x_icons_new_toolbar_pixmap(GSCHEM_STOCK_SELECT),
                                  (GtkSignalFunc) 
i_callback_action_edit_select, 
                                  w_current);
 
@@ -966,42 +961,3 @@ x_window_close_page (GSCHEM_TOPLEVEL *w_current, PAGE 
*page)
 }
 
 
-/*! \brief Setup default icon for GTK windows
- *
- *  \par Function Description
- *  Sets the default window icon by name, to be found in the current icon
- *  theme. The name used is #defined above as GSCHEM_THEME_ICON_NAME.
- *
- *  For GTK versions < 2.6, we have to load the icons explicitly, and pass
- *  them to GTK. As we don't know what size is appropriate, a #define above,
- *  GSCHEM_ICON_SIZES is used to list (comma separated) the sizes we have
- *  icons for. Icons loaded at all of these sizes are passed to GTK.
- */
-void x_window_set_default_icon( void )
-{
-#if GTK_CHECK_VERSION (2,6,0)
-  gtk_window_set_default_icon_name( GSCHEM_THEME_ICON_NAME );
-#else
-  GtkIconTheme *icon_theme;
-  GdkPixbuf *icon;
-  GList *icon_list = NULL;
-  int icon_size[] = { GSCHEM_ICON_SIZES };
-  int i;
-
-  for ( i = 0; i < sizeof( icon_size ) / sizeof( *icon_size ); i++ ) {
-    icon_theme = gtk_icon_theme_get_default();
-    icon = gtk_icon_theme_load_icon( icon_theme,
-                                     GSCHEM_THEME_ICON_NAME,
-                                     icon_size[i],
-                                     0,   /* flags */
-                                     NULL /* **error */ );
-    if (icon != NULL)
-      icon_list = g_list_append( icon_list, icon );
-  }
-
-  gtk_window_set_default_icon_list( icon_list );
-
-  g_list_foreach( icon_list, (GFunc) g_object_unref, NULL );
-  g_list_free( icon_list );
-#endif
-}
-- 
1.5.6



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

Reply via email to