Here are recommended the changes.

Ed

From 2bed699bb8b90435e9e59019419344ae8c71eb7a Mon Sep 17 00:00:00 2001
From: Edward Hennessy <[EMAIL PROTECTED]>
Date: Tue, 29 Jul 2008 07:11:00 -0700
Subject: [PATCH] Misc cleanup on previous submitted patch.

---
 gschem/include/Makefile.am |    2 +-
 gschem/include/prototype.h |    6 ++--
 gschem/src/gschem.c        |    5 ++-
 gschem/src/x_icons.c       |   83 ++++++++++++++++++++++++++++++++-----------
 gschem/src/x_window.c      |   65 +++++-----------------------------
 5 files changed, 79 insertions(+), 82 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 5e19e1f..de73716 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -807,8 +807,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);
@@ -866,4 +867,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..b955a3a 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 and load gschem 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/x_icons.c b/gschem/src/x_icons.c
index a476096..6b609ef 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
- *  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.
+ *
+ *  Since the application can operate with missing icons, this function treats
+ *  a the failure to load an icon as a warning.
+ *
+ *  \param [in] bitmap_directory The bitmap directory containing the toolbar
+ *  icons.  This parameter 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) {
-      g_warning("Loading icons: %s\n",error->message);
+    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 56e5e1f..361583b 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);
 
@@ -314,21 +309,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_toolbar_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_toolbar_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_toolbar_file_save, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -336,14 +331,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_toolbar_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_toolbar_edit_redo, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -352,7 +347,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_toolbar_add_component, 
                              w_current);
     w_current->toolbar_net = 
@@ -362,7 +357,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_toolbar_add_net,
                                  w_current);
     w_current->toolbar_bus = 
@@ -372,7 +367,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_toolbar_add_bus,
                                  w_current);
     /* not part of any radio button group */
@@ -380,7 +375,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_toolbar_add_text, 
                              w_current);
     gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
@@ -391,7 +386,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_toolbar_edit_select, 
                                  w_current);
 
@@ -946,43 +941,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