[monkey-bubble: 41/753] Splited from gnome-app to avoid people believing that they need to use the



commit 91f06921a6d18c6d46234d21f4f170b39b1cba91
Author: Miguel de Icaza <miguel nuclecu unam mx>
Date:   Tue Jan 6 19:32:21 1998 +0000

    Splited from gnome-app to avoid people believing that they need to use the
    
    Tue Jan  6 13:43:45 1998  Miguel de Icaza  <miguel nuclecu unam mx>
    
    	* libgnome/gnome-app-helper.c: Splited from gnome-app to avoid
    	people believing that they need to use the wrappers for toolbar
    	and menubar creation.
    
    	* libgnome/gnome-app.c: Do not remove from the parent container if
    	we have not been added yet.

 libgnomeui/Makefile.am        |    2 +
 libgnomeui/gnome-app-helper.c |  118 +++++++++++++++++++++++++++++++++++++++++
 libgnomeui/gnome-app-helper.h |   58 ++++++++++++++++++++
 libgnomeui/gnome-app.c        |  118 +++--------------------------------------
 libgnomeui/gnome-app.h        |   61 ---------------------
 libgnomeui/libgnomeui.h       |    1 +
 6 files changed, 186 insertions(+), 172 deletions(-)
---
diff --git a/libgnomeui/Makefile.am b/libgnomeui/Makefile.am
index bc156c9..2df788a 100644
--- a/libgnomeui/Makefile.am
+++ b/libgnomeui/Makefile.am
@@ -9,6 +9,7 @@ lib_LTLIBRARIES = libgnomeui.la
 libgnomeui_la_SOURCES = \
 	gnome-actionarea.c		\
 	gnome-app.c			\
+	gnome-app-helper.c		\
 	gnome-color-selector.c 		\
 	gnome-colors.c			\
 	gnome-ice.c			\
@@ -22,6 +23,7 @@ libgnomeui_la_SOURCES = \
 libgnomeuiinclude_HEADERS = 		\
         gnome-actionarea.h     		\
 	gnome-app.h			\
+	gnome-app-helper.h		\
 	gnome-color-selector.h 		\
 	gnome-colors.h         		\
 	gnome-ice.h			\
diff --git a/libgnomeui/gnome-app-helper.c b/libgnomeui/gnome-app-helper.c
new file mode 100644
index 0000000..97365c9
--- /dev/null
+++ b/libgnomeui/gnome-app-helper.c
@@ -0,0 +1,118 @@
+/*
+ * GnomeApp widget by Elliot Lee
+ */
+#include "libgnome/gnome-defs.h"
+#include "libgnome/gnome-util.h"
+#include "libgnome/gnome-config.h"
+#include "gnome-app.h"
+#include "gnome-app-helper.h"
+#include "gnome-pixmap.h"
+#include <string.h>
+#include <gtk/gtk.h>
+
+static void gnome_app_do_menu_creation        (GtkWidget *parent_widget,
+					       GnomeMenuInfo *menuinfo);
+static void gnome_app_do_toolbar_creation     (GnomeApp *app,
+					       GtkWidget *parent_widget,
+					       GnomeToolbarInfo *tbinfo);
+
+static void
+gnome_app_do_menu_creation(GtkWidget *parent_widget,
+			   GnomeMenuInfo *menuinfo)
+{
+	int i;
+	for(i = 0; menuinfo[i].type != GNOME_APP_MENU_ENDOFINFO; i++)
+	{
+		menuinfo[i].widget = gtk_menu_item_new_with_label(menuinfo[i].label);
+		gtk_widget_show(menuinfo[i].widget);
+		gtk_menu_shell_append(GTK_MENU_SHELL(parent_widget),
+				      menuinfo[i].widget);
+		
+		if(menuinfo[i].type == GNOME_APP_MENU_ITEM)
+		{
+			gtk_signal_connect(GTK_OBJECT(menuinfo[i].widget), "activate",
+					   menuinfo[i].moreinfo, NULL);
+		}
+		else if(menuinfo[i].type == GNOME_APP_MENU_SUBMENU)
+		{
+			GtkWidget *submenu;
+			submenu = gtk_menu_new();
+			gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuinfo[i].widget),
+						  submenu);
+			gnome_app_do_menu_creation(submenu, menuinfo[i].moreinfo);
+		}
+	}
+}
+
+void
+gnome_app_create_menus(GnomeApp *app,
+		       GnomeMenuInfo *menuinfo)
+{
+	GtkWidget *hb, *menubar;
+	
+	g_return_if_fail(app != NULL);
+	g_return_if_fail(GNOME_IS_APP(app));
+	g_return_if_fail(app->menubar == NULL);
+
+	menubar = gtk_menu_bar_new ();
+	gnome_app_set_menus (app, GTK_MENU_BAR (menubar));
+	
+	if(menuinfo)
+		gnome_app_do_menu_creation(app->menubar, menuinfo);
+}
+
+static void
+gnome_app_do_toolbar_creation(GnomeApp *app,
+			      GtkWidget *parent_widget,
+			      GnomeToolbarInfo *tbinfo)
+{
+	int i;
+	GtkWidget *pmap;
+	
+	if(!GTK_WIDGET(app)->window)
+		gtk_widget_realize(GTK_WIDGET(app));
+	
+	for(i = 0; tbinfo[i].type != GNOME_APP_TOOLBAR_ENDOFINFO; i++)
+	{
+		if(tbinfo[i].type == GNOME_APP_TOOLBAR_ITEM)
+		{
+			if(tbinfo[i].pixmap_type == GNOME_APP_PIXMAP_DATA)
+				pmap = gnome_create_pixmap_widget_d(GTK_WIDGET(app),
+								    parent_widget,
+								    (char **)tbinfo[i].pixmap_info);
+			else if(tbinfo[i].pixmap_type == GNOME_APP_PIXMAP_FILENAME)
+				pmap = gnome_create_pixmap_widget(GTK_WIDGET(app),
+								  parent_widget,
+								  (char *)tbinfo[i].pixmap_info);
+			else
+				pmap = NULL;
+			gtk_toolbar_append_item(GTK_TOOLBAR(parent_widget),
+						tbinfo[i].text,
+						tbinfo[i].tooltip_text,
+						GTK_PIXMAP(pmap),
+						tbinfo[i].clicked_callback,
+						NULL);
+		}
+		else if(tbinfo[i].type == GNOME_APP_TOOLBAR_SPACE)
+		{
+			gtk_toolbar_append_space(GTK_TOOLBAR(parent_widget));
+		}
+	}
+}
+
+void gnome_app_create_toolbar(GnomeApp *app,
+			      GnomeToolbarInfo *toolbarinfo)
+{
+	GtkWidget *hb;
+	
+	g_return_if_fail(app != NULL);
+	g_return_if_fail(GNOME_IS_APP(app));
+	g_return_if_fail(app->toolbar == NULL);
+	
+	gnome_app_set_toolbar (app, GTK_TOOLBAR (
+		gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH)));
+	
+	if(toolbarinfo)
+		gnome_app_do_toolbar_creation(app, app->toolbar, toolbarinfo);
+}
+
diff --git a/libgnomeui/gnome-app-helper.h b/libgnomeui/gnome-app-helper.h
new file mode 100644
index 0000000..856e686
--- /dev/null
+++ b/libgnomeui/gnome-app-helper.h
@@ -0,0 +1,58 @@
+/*
+ * Helper routines,
+ */
+struct _GnomeMenuInfo {
+	enum {
+		GNOME_APP_MENU_ENDOFINFO,
+		GNOME_APP_MENU_ITEM,
+		GNOME_APP_MENU_SUBMENU
+	} type;
+	gchar *label;
+	gpointer moreinfo; /* For a menuitem, this should point to the
+			      procedure to be called when this menu item is
+			      activated.
+			      
+			      For a submenu, it should point to the
+			      GnomeMenuInfo array for that menu. */
+	GtkWidget *widget; /* This is filled in by gnome_app_create_menu() */
+};
+
+typedef struct _GnomeMenuInfo GnomeMenuInfo;
+
+struct _GnomeToolbarInfo {
+	enum {
+		GNOME_APP_TOOLBAR_ENDOFINFO,
+		GNOME_APP_TOOLBAR_ITEM,
+		GNOME_APP_TOOLBAR_SPACE
+	} type;
+	
+	/* You can leave the rest of these to NULL or whatever if this is an
+	 * GNOME_APP_TOOLBAR_SPACE
+	 */
+	
+	gchar *text;
+	gchar *tooltip_text;
+	enum {
+		GNOME_APP_PIXMAP_NONE,
+		GNOME_APP_PIXMAP_DATA,
+		GNOME_APP_PIXMAP_FILENAME
+	} pixmap_type;
+	
+	/* Either a pointer to the char 
+	 *  for the pixmap
+	 * (for PMAP_DATA) or a char * for the filename
+	 * (PMAP_FILENAME)
+	 */
+	gpointer pixmap_info;
+
+	/* Useful for TB_ITEMs only,
+	 *  it's the GtkSignalFunc
+	 */
+	gpointer clicked_callback; 
+};
+typedef struct _GnomeToolbarInfo GnomeToolbarInfo;
+
+void gnome_app_create_menus         (GnomeApp *app,
+			             GnomeMenuInfo *menuinfo);
+void gnome_app_create_toolbar       (GnomeApp *app,
+			             GnomeToolbarInfo *tbinfo);
diff --git a/libgnomeui/gnome-app.c b/libgnomeui/gnome-app.c
index 4f03fdc..531517b 100644
--- a/libgnomeui/gnome-app.c
+++ b/libgnomeui/gnome-app.c
@@ -5,18 +5,12 @@
 #include "libgnome/gnome-util.h"
 #include "libgnome/gnome-config.h"
 #include "gnome-app.h"
-#include "gnome-pixmap.h"
 #include <string.h>
 #include <gtk/gtk.h>
 
 static void gnome_app_class_init     	      (GnomeAppClass *appclass);
 static void gnome_app_destroy        	      (GnomeApp      *app);
 static void gnome_app_init           	      (GnomeApp      *app);
-static void gnome_app_do_menu_creation        (GtkWidget *parent_widget,
-					       GnomeMenuInfo *menuinfo);
-static void gnome_app_do_toolbar_creation     (GnomeApp *app,
-					       GtkWidget *parent_widget,
-					       GnomeToolbarInfo *tbinfo);
 static void gnome_app_rightclick_event        (GtkWidget *widget,
 					       GdkEventButton *event,
 					       GnomeApp *app);
@@ -116,113 +110,14 @@ gnome_app_destroy(GnomeApp *app)
 }
 
 static void
-gnome_app_do_menu_creation(GtkWidget *parent_widget,
-			   GnomeMenuInfo *menuinfo)
-{
-	int i;
-	for(i = 0; menuinfo[i].type != GNOME_APP_MENU_ENDOFINFO; i++)
-	{
-		menuinfo[i].widget = gtk_menu_item_new_with_label(menuinfo[i].label);
-		gtk_widget_show(menuinfo[i].widget);
-		gtk_menu_shell_append(GTK_MENU_SHELL(parent_widget),
-				      menuinfo[i].widget);
-		
-		if(menuinfo[i].type == GNOME_APP_MENU_ITEM)
-		{
-			gtk_signal_connect(GTK_OBJECT(menuinfo[i].widget), "activate",
-					   menuinfo[i].moreinfo, NULL);
-		}
-		else if(menuinfo[i].type == GNOME_APP_MENU_SUBMENU)
-		{
-			GtkWidget *submenu;
-			submenu = gtk_menu_new();
-			gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuinfo[i].widget),
-						  submenu);
-			gnome_app_do_menu_creation(submenu, menuinfo[i].moreinfo);
-		}
-	}
-}
-
-void
-gnome_app_create_menus(GnomeApp *app,
-		       GnomeMenuInfo *menuinfo)
-{
-	GtkWidget *hb, *menubar;
-	
-	g_return_if_fail(app != NULL);
-	g_return_if_fail(GNOME_IS_APP(app));
-	g_return_if_fail(app->menubar == NULL);
-
-	menubar = gtk_menu_bar_new ();
-	gnome_app_set_menus (app, GTK_MENU_BAR (menubar));
-	
-	if(menuinfo)
-		gnome_app_do_menu_creation(app->menubar, menuinfo);
-}
-
-static void
-gnome_app_do_toolbar_creation(GnomeApp *app,
-			      GtkWidget *parent_widget,
-			      GnomeToolbarInfo *tbinfo)
-{
-	int i;
-	GtkWidget *pmap;
-	
-	if(!GTK_WIDGET(app)->window)
-		gtk_widget_realize(GTK_WIDGET(app));
-	
-	for(i = 0; tbinfo[i].type != GNOME_APP_TOOLBAR_ENDOFINFO; i++)
-	{
-		if(tbinfo[i].type == GNOME_APP_TOOLBAR_ITEM)
-		{
-			if(tbinfo[i].pixmap_type == GNOME_APP_PIXMAP_DATA)
-				pmap = gnome_create_pixmap_widget_d(GTK_WIDGET(app),
-								    parent_widget,
-								    (char **)tbinfo[i].pixmap_info);
-			else if(tbinfo[i].pixmap_type == GNOME_APP_PIXMAP_FILENAME)
-				pmap = gnome_create_pixmap_widget(GTK_WIDGET(app),
-								  parent_widget,
-								  (char *)tbinfo[i].pixmap_info);
-			else
-				pmap = NULL;
-			gtk_toolbar_append_item(GTK_TOOLBAR(parent_widget),
-						tbinfo[i].text,
-						tbinfo[i].tooltip_text,
-						GTK_PIXMAP(pmap),
-						tbinfo[i].clicked_callback,
-						NULL);
-		}
-		else if(tbinfo[i].type == GNOME_APP_TOOLBAR_SPACE)
-		{
-			gtk_toolbar_append_space(GTK_TOOLBAR(parent_widget));
-		}
-	}
-}
-
-void gnome_app_create_toolbar(GnomeApp *app,
-			      GnomeToolbarInfo *toolbarinfo)
-{
-	GtkWidget *hb;
-	
-	g_return_if_fail(app != NULL);
-	g_return_if_fail(GNOME_IS_APP(app));
-	g_return_if_fail(app->toolbar == NULL);
-	
-	gnome_app_set_toolbar (app, GTK_TOOLBAR (
-		gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH)));
-	
-	if(toolbarinfo)
-		gnome_app_do_toolbar_creation(app, app->toolbar, toolbarinfo);
-}
-
-static void
 gnome_app_configure_positions (GnomeApp *app)
 {
 
 	/* 1.  The menubar: can go on top or bottom */
 	if (app->menubar){
-		gtk_container_remove (GTK_CONTAINER(app->menubar->parent->parent),
-				      app->menubar->parent);
+		if (app->menubar->parent->parent)
+			gtk_container_remove (GTK_CONTAINER(app->menubar->parent->parent),
+					      app->menubar->parent);
 		gtk_table_attach_defaults(GTK_TABLE(app->table),
 					  app->menubar->parent,
 					  0, 3,
@@ -233,9 +128,10 @@ gnome_app_configure_positions (GnomeApp *app)
 	/* 2. the toolbar */
 	if (app->toolbar){
 		int offset = 0;
-		
-		gtk_container_remove (GTK_CONTAINER(app->toolbar->parent->parent),
-				      app->toolbar->parent);
+
+		if (app->toolbar->parent->parent)
+			gtk_container_remove (GTK_CONTAINER(app->toolbar->parent->parent),
+					      app->toolbar->parent);
 
 		if(app->pos_menubar == GNOME_APP_POS_TOP)
 			offset = 1;
diff --git a/libgnomeui/gnome-app.h b/libgnomeui/gnome-app.h
index f6bd3da..c47bf3b 100644
--- a/libgnomeui/gnome-app.h
+++ b/libgnomeui/gnome-app.h
@@ -23,63 +23,6 @@ typedef enum
 	GNOME_APP_POS_FLOATING,
 } GnomeAppWidgetPositionType;
 
-typedef enum
-{
-	GNOME_APP_MENUBAR = 1,
-	GNOME_APP_TOOLBAR = 2,
-} GnomeAppWidgetType;
-
-struct _GnomeMenuInfo {
-	enum {
-		GNOME_APP_MENU_ENDOFINFO,
-		GNOME_APP_MENU_ITEM,
-		GNOME_APP_MENU_SUBMENU
-	} type;
-	gchar *label;
-	gpointer moreinfo; /* For a menuitem, this should point to the
-			      procedure to be called when this menu item is
-			      activated.
-			      
-			      For a submenu, it should point to the
-			      GnomeMenuInfo array for that menu. */
-	GtkWidget *widget; /* This is filled in by gnome_app_create_menu() */
-};
-
-typedef struct _GnomeMenuInfo GnomeMenuInfo;
-
-struct _GnomeToolbarInfo {
-	enum {
-		GNOME_APP_TOOLBAR_ENDOFINFO,
-		GNOME_APP_TOOLBAR_ITEM,
-		GNOME_APP_TOOLBAR_SPACE
-	} type;
-	
-	/* You can leave the rest of these to NULL or whatever if this is an
-	 * GNOME_APP_TOOLBAR_SPACE
-	 */
-	
-	gchar *text;
-	gchar *tooltip_text;
-	enum {
-		GNOME_APP_PIXMAP_NONE,
-		GNOME_APP_PIXMAP_DATA,
-		GNOME_APP_PIXMAP_FILENAME
-	} pixmap_type;
-	
-	/* Either a pointer to the char 
-	 *  for the pixmap
-	 * (for PMAP_DATA) or a char * for the filename
-	 * (PMAP_FILENAME)
-	 */
-	gpointer pixmap_info;
-
-	/* Useful for TB_ITEMs only,
-	 *  it's the GtkSignalFunc
-	 */
-	gpointer clicked_callback; 
-};
-typedef struct _GnomeToolbarInfo GnomeToolbarInfo;
-
 /* Everything gets put into a table that looks like:
  *
  * XXX
@@ -112,10 +55,6 @@ struct _GnomeAppClass {
 guint gnome_app_get_type      (void);
 GtkWidget *gnome_app_new      (gchar *appname, char *title);
 
-void gnome_app_create_menus         (GnomeApp *app,
-			             GnomeMenuInfo *menuinfo);
-void gnome_app_create_toolbar       (GnomeApp *app,
-			             GnomeToolbarInfo *tbinfo);
 void gnome_app_set_menus            (GnomeApp *app,
 			             GtkMenuBar *menubar);
 void gnome_app_set_toolbar          (GnomeApp *app,
diff --git a/libgnomeui/libgnomeui.h b/libgnomeui/libgnomeui.h
index 8b1a7b8..211178b 100644
--- a/libgnomeui/libgnomeui.h
+++ b/libgnomeui/libgnomeui.h
@@ -3,6 +3,7 @@
 
 #include "libgnome/gnome-defs.h"
 #include "libgnomeui/gnome-app.h"
+#include "libgnomeui/gnome-app-helper.h"
 #include "libgnomeui/gnome-actionarea.h"
 #include "libgnomeui/gnome-colors.h"
 #include "libgnomeui/gnome-color-selector.h"



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