[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gEDA-dev: [patch] Stock GTK icons in Gschem



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

This is a simple patch (for CVS head) that replaces old xpm icons on the
toolbar with stock GTK icons. This way Gschem looks a bit more
integrated with a Gnome desktop.

If stock icons aren't available it still falls back to the old xpm
icons. It shouldn't break building on GTK 1.x, but I haven't tested that.

Best regards
Tomaz Solc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEyIOhsAlAlRhL9q8RAtmHAKCiDBXucRggh6A1qvsPkhP0m/aMFQCgiA7P
cbTnRaMxmrXeCf/58HImWiA=
=yHh/
-----END PGP SIGNATURE-----
Index: src/x_window.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_window.c,v
retrieving revision 1.31
diff -u -3 -r1.31 x_window.c
--- src/x_window.c	25 Jul 2006 00:54:34 -0000	1.31
+++ src/x_window.c	26 Jul 2006 18:06:06 -0000
@@ -394,6 +394,7 @@
  *  \par Function Description
  *
  */
+/*
 static GtkWidget *x_window_new_pixmap(const char *filename,
 				      GdkWindow *window, GdkColor *background)
 {
@@ -412,6 +413,55 @@
 
   return wpixmap;
 }
+*/
+
+/*! \brief Creates a new GtkImage displaying a GTK stock icon if available.
+ *
+ * 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.)
+ * \return Pointer to the new GtkImage object.
+ */
+static GtkWidget *x_window_stock_pixmap(const char *stock, TOPLEVEL *w_current)
+{
+	GtkWidget *wpixmap;
+	GdkPixmap *pixmap;
+  	GdkBitmap *mask;
+	GtkStockItem item;
+
+  	GdkWindow *window=w_current->main_window->window;
+  	GdkColor *background=&w_current->main_window->style->bg[GTK_STATE_NORMAL];
+
+	gchar *filename=g_strconcat(w_current->bitmap_directory, 
+					G_DIR_SEPARATOR_S, 
+					"gschem-", stock, ".xpm", NULL);
+
+	gchar *stockid=g_strconcat("gtk-", stock, NULL);
+
+#ifdef HAS_GTK22 
+	/* First check if GTK knows this stock icon */
+	if(gtk_stock_lookup(stockid, &item)) {
+		wpixmap = gtk_image_new_from_stock(stockid, 
+						GTK_ICON_SIZE_SMALL_TOOLBAR);
+	} else {
+		/* Fallback to the original custom icon */
+  		pixmap = gdk_pixmap_create_from_xpm (window, &mask, 
+							background, filename);
+		wpixmap = gtk_image_new_from_pixmap (pixmap, mask);
+	}
+#else
+	/* Older versions of GTK do not support stock icons. */
+  	pixmap = gdk_pixmap_create_from_xpm (window, &mask, 
+							background, filename);
+	wpixmap = gtk_pixmap_new (pixmap, mask);
+#endif
+
+	g_free(filename);
+	g_free(stockid);
+
+	return wpixmap;
+}
 
 /*! \todo Finish function documentation!!!
  *  \brief
@@ -427,7 +477,6 @@
   GtkWidget *bottom_box=NULL;
   GtkWidget *toolbar=NULL;
   GtkWidget *handlebox=NULL;
-  char *filename = NULL;
 
   /* used to signify that the window isn't mapped yet */
   w_current->window = NULL; 
@@ -512,149 +561,87 @@
   		gtk_box_pack_start(GTK_BOX(main_box), toolbar, FALSE, FALSE, 0);
 	}
 
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-new.xpm", NULL);
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
-		  	   _("New"), 
-			   _("New file"), 
-			   "toolbar/new", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
-	      		   (GtkSignalFunc) i_callback_toolbar_file_new, 
-			   w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-open.xpm", NULL);
+ 				_("New"), 
+			   	_("New file"), 
+			   	"toolbar/new", 
+				x_window_stock_pixmap("new", w_current),
+	      		   	(GtkSignalFunc) i_callback_toolbar_file_new, 
+			   	w_current);
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("Open"), 
 			   _("Open file..."), 
-			   "toolbar/open", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+			   "toolbar/open",
+			   x_window_stock_pixmap("open", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_file_open, 
 			   w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-save.xpm", NULL);
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("Save"), 
 			   _("Save file"), 
 			   "toolbar/save", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+			   x_window_stock_pixmap("save", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_file_save, 
 			   w_current);
   	gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-undo.xpm", NULL);
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("Undo"), 
 			   _("Undo last operation"), 
 			   "toolbar/undo", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+			   x_window_stock_pixmap("undo", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_edit_undo, 
 			   w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-redo.xpm", NULL);
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("Redo"), 
 			   _("Redo last undo"), 
 			   "toolbar/redo", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+  			   x_window_stock_pixmap("redo", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_edit_redo, 
 			   w_current);
   	gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-comp.xpm", NULL);
   	/* not part of any radio button group */
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("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_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+  			   x_window_stock_pixmap("comp", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_add_component, 
 			   w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-net.xpm", NULL);
   	w_current->toolbar_net = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
-                                     GTK_TOOLBAR_CHILD_RADIOBUTTON,
-                                     NULL,
-                                     _("Nets"),
-                                     _("Add nets mode\nRight mouse button to cancel"),
-                                     "toolbar/nets",
-	                             x_window_new_pixmap (filename,
-                                     w_current->main_window->window,
-                                     &w_current->main_window->style->
-                                     bg[GTK_STATE_NORMAL]),
-	      		             (GtkSignalFunc) i_callback_toolbar_add_net,
-			             w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-bus.xpm", NULL);
+                           GTK_TOOLBAR_CHILD_RADIOBUTTON,
+                           NULL,
+                           _("Nets"),
+                           _("Add nets mode\nRight mouse button to cancel"),
+                           "toolbar/nets",
+			   x_window_stock_pixmap("net", w_current),
+	      		  (GtkSignalFunc) i_callback_toolbar_add_net,
+			  w_current);
   	w_current->toolbar_bus = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
-                                     GTK_TOOLBAR_CHILD_RADIOBUTTON,
-                                     w_current->toolbar_net,
-                                     _("Bus"),
-                                     _("Add buses mode\nRight mouse button to cancel"),
-                                     "toolbar/bus",
-	                             x_window_new_pixmap (filename,
-                                     w_current->main_window->window,
-                                     &w_current->main_window->style->
-                                     bg[GTK_STATE_NORMAL]),
-	      		             (GtkSignalFunc) i_callback_toolbar_add_bus,
-			             w_current);
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-text.xpm", NULL);
+                          GTK_TOOLBAR_CHILD_RADIOBUTTON,
+                          w_current->toolbar_net,
+                          _("Bus"),
+                          _("Add buses mode\nRight mouse button to cancel"),
+                          "toolbar/bus",
+                          x_window_stock_pixmap("bus", w_current),
+			  (GtkSignalFunc) i_callback_toolbar_add_bus,
+			  w_current);
   	/* not part of any radio button group */
   	gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), 
 		  	   _("Text"), 
 			   _("Add Text..."), 
 			   "toolbar/text", 
-  			   x_window_new_pixmap (filename,
-				       w_current->main_window->window, 
-	      			       &w_current->main_window->style->
-					bg[GTK_STATE_NORMAL]), 
+                           x_window_stock_pixmap("text", w_current),
 	      		   (GtkSignalFunc) i_callback_toolbar_add_text, 
 			   w_current);
-
   	gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); 
-
-  	g_free(filename);
-  	filename = g_strconcat(w_current->bitmap_directory, 
-			       G_DIR_SEPARATOR_S, "gschem-select.xpm", NULL);
   	w_current->toolbar_select = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
-                                     GTK_TOOLBAR_CHILD_RADIOBUTTON,
-                                     w_current->toolbar_bus,
-                                     _("Select"),
-                                     _("Select mode"),
-                                     "toolbar/select",
-	                             x_window_new_pixmap (filename,
-                                     w_current->main_window->window,
-                                     &w_current->main_window->style->
-                                     bg[GTK_STATE_NORMAL]),
-	      		   	     (GtkSignalFunc) i_callback_toolbar_edit_select, 
-			             w_current);
-  	g_free(filename);
+                           GTK_TOOLBAR_CHILD_RADIOBUTTON,
+                           w_current->toolbar_bus,
+                           _("Select"),
+                           _("Select mode"),
+                           "toolbar/select",
+                           x_window_stock_pixmap("select", w_current),
+			   (GtkSignalFunc) i_callback_toolbar_edit_select, 
+			   w_current);
 
 #if 0 /* out until they work */
   	filename = g_strconcat(w_current->bitmap_directory, 


_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev