Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

mytoolbar.c

Go to the documentation of this file.
00001 
00005 /* GtkSQL -- an interactive graphical query tool for PostgreSQL
00006  * Copyright (C) 1998-2003  Lionel ULMER, Darryl luff
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #include <assert.h>
00024 #include <string.h>
00025 
00026 #include "gui_common.h"
00027 #include "mytoolbar.h"
00028 
00030 #define NORM_KEY "norm"
00031 
00032 #define GREY_KEY "grey"
00033 
00034 #define MASK_KEY "mask"
00035 
00037 static GtkWidget *toolbar;
00038 
00040 void set_my_toolbar_config(int config)
00041 {
00042     /* Nothing yet.. */
00043 }
00044 
00046 static void pixmap_state_changed(GtkWidget * widget,
00047                                  GtkStateType previous_state,
00048                                  gpointer user_data)
00049 {
00050     GtkPixmap *pixmap;
00051     GdkPixmap *mask, *normal_pixmap, *insensitive_pixmap;
00052 
00053     pixmap = GTK_PIXMAP(widget);
00054     mask = (GdkPixmap *) gtk_object_get_data(GTK_OBJECT(pixmap), MASK_KEY);
00055     normal_pixmap =
00056         (GdkPixmap *) gtk_object_get_data(GTK_OBJECT(pixmap), NORM_KEY);
00057     insensitive_pixmap =
00058         (GdkPixmap *) gtk_object_get_data(GTK_OBJECT(pixmap), GREY_KEY);
00059 
00060     switch (GTK_WIDGET_STATE(pixmap)) {
00061     case GTK_STATE_NORMAL:
00062         gtk_pixmap_set(pixmap, normal_pixmap, mask);
00063         break;
00064     case GTK_STATE_INSENSITIVE:
00065         gtk_pixmap_set(pixmap, insensitive_pixmap, mask);
00066         break;
00067     case GTK_STATE_ACTIVE:
00068     case GTK_STATE_PRELIGHT:
00069     case GTK_STATE_SELECTED:
00070         /* we want to ignore these? */
00071         break;
00072     }
00073 }
00074 
00076 static GtkWidget *create_pixmap(GtkWidget * ref, char **pixmap, char **grey_pixmap)
00077 {
00078     GdkBitmap *mask;
00079     GdkPixmap *gdkpix, *gdkpix_grey;
00080     GtkStyle *style;
00081     GtkWidget *gtkpix;
00082     
00083     style = gtk_widget_get_style(ref);
00084     gdkpix =
00085         gdk_pixmap_create_from_xpm_d(ref->window, &mask,
00086                                      &(style->bg[GTK_STATE_NORMAL]), pixmap);
00087     gdkpix_grey =
00088         gdk_pixmap_create_from_xpm_d(ref->window, &mask,
00089                                      &style->bg[GTK_STATE_NORMAL],
00090                                      grey_pixmap);
00091     gtkpix = gtk_pixmap_new(gdkpix, mask);
00092     gtk_widget_show(gtkpix);
00093 
00094     gtk_object_set_data(GTK_OBJECT(gtkpix), NORM_KEY, gdkpix);
00095     gtk_object_set_data(GTK_OBJECT(gtkpix), GREY_KEY, gdkpix_grey);
00096     gtk_object_set_data(GTK_OBJECT(gtkpix), MASK_KEY, mask);
00097 
00098     gtk_signal_connect(GTK_OBJECT(gtkpix), "state_changed",
00099                        GTK_SIGNAL_FUNC(pixmap_state_changed), NULL);
00100     return gtkpix;
00101 }
00102 
00104 GtkWidget *create_my_toolbar(GtkWidget * ref, ToolBar * toolbardef)
00105 {
00106     int i;
00107     assert(ref != NULL);
00108 
00109     /* Create the toolbar */
00110     toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
00111     gtk_toolbar_set_tooltips(GTK_TOOLBAR(toolbar), TRUE);
00112 
00113     /* Builds the toolbar */
00114     i = 0;
00115     gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
00116     while (toolbardef[i].label != NULL) {
00117         if (strlen(toolbardef[i].label) == 0) {
00118             gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
00119         }
00120         else {
00121             GtkWidget *gtkpix =
00122                 create_pixmap(ref, toolbardef[i].pixmap,
00123                               toolbardef[i].grey_pixmap);
00124             GtkWidget *but_vbox;
00125 
00126             but_vbox =
00127                 gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
00128                                         toolbardef[i].label,
00129                                         toolbardef[i].tooltip, "Private",
00130                                         gtkpix, toolbardef[i].callback,
00131                                         toolbardef[i].data);
00132             *toolbardef[i].store_to = but_vbox;
00133         }
00134         i++;
00135     }
00136     return toolbar;
00137 }

Generated on Sun May 9 19:19:17 2004 for GtkSQL by doxygen1.2.18