Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

gtkcomboperiodic.c

00001 /* 
00002  * Gnome Chemisty Utils
00003  * gtkcomboperiodic.c
00004  *
00005  * Copyright (C) 2006
00006  *
00007  * Developed by Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #include "config.h"
00026 #include "gtkperiodic.h"
00027 #include "gtkcomboperiodic.h"
00028 #include "chemistry.h"
00029 #include <goffice/gtk/go-combo-box.h>
00030 #include <gtk/gtklabel.h>
00031 #include <gsf/gsf-impl-utils.h>
00032 #include <glib/gi18n-lib.h>
00033 
00034 struct _GtkComboPeriodic {
00035         GOComboBox     base;
00036 
00037         GtkWidget    *periodic, *preview_button, *label;
00038         gulong handler_id;
00039 };
00040 
00041 typedef struct {
00042         GOComboBoxClass base;
00043         void (* changed) (GtkComboPeriodic *combo, int id);
00044 } GtkComboPeriodicClass;
00045 
00046 enum {
00047         CHANGED,
00048         LAST_SIGNAL
00049 };
00050 
00051 static guint go_combo_pixmaps_signals [LAST_SIGNAL] = { 0, };
00052 
00053 static void
00054 cb_screen_changed (GtkComboPeriodic *combo, GdkScreen *previous_screen)
00055 {
00056         GtkWidget *w = GTK_WIDGET (combo);
00057         GdkScreen *screen = gtk_widget_has_screen (w)
00058                 ? gtk_widget_get_screen (w)
00059                 : NULL;
00060 
00061         if (screen) {
00062                 GtkWidget *toplevel = gtk_widget_get_toplevel (combo->periodic);
00063                 gtk_window_set_screen (GTK_WINDOW (toplevel), screen);
00064         }
00065 }
00066 
00067 static void
00068 element_changed_cb (GtkComboPeriodic *combo)
00069 {
00070         int newZ = gtk_periodic_get_element (GTK_PERIODIC (combo->periodic));
00071         gtk_label_set_text (GTK_LABEL (combo->label), gcu_element_get_symbol (newZ));
00072         if (_go_combo_is_updating (GO_COMBO_BOX (combo)))
00073                 return;
00074         g_signal_emit (combo, go_combo_pixmaps_signals [CHANGED], 0, newZ);
00075         go_combo_box_popup_hide (GO_COMBO_BOX (combo));
00076 }
00077 
00078 static void
00079 gtk_combo_periodic_init (GtkComboPeriodic *combo)
00080 {
00081         combo->preview_button = gtk_toggle_button_new ();
00082         combo->label = gtk_label_new ("");
00083         gtk_widget_show (combo->label);
00084         gtk_container_add (GTK_CONTAINER (combo->preview_button),
00085                 GTK_WIDGET (combo->label));
00086 
00087         g_signal_connect (G_OBJECT (combo),
00088                 "screen-changed",
00089                 G_CALLBACK (cb_screen_changed), NULL);
00090 
00091         gtk_widget_show_all (combo->preview_button);
00092         combo->periodic = gtk_periodic_new ();
00093         combo->handler_id = g_signal_connect_swapped (combo->periodic,
00094                 "element_changed", G_CALLBACK (element_changed_cb), combo);
00095         gtk_widget_show_all (combo->periodic);
00096         go_combo_box_construct (GO_COMBO_BOX (combo),
00097                 combo->preview_button, combo->periodic, combo->periodic);
00098         go_combo_box_set_title(GO_COMBO_BOX (combo), _("Periodic table of the elements"));
00099         gtk_widget_show_all (GTK_WIDGET (combo));
00100 }
00101 
00102 static void
00103 gtk_combo_periodic_class_init (GObjectClass *gobject_class)
00104 {
00105         go_combo_pixmaps_signals [CHANGED] =
00106                 g_signal_new ("changed",
00107                               G_OBJECT_CLASS_TYPE (gobject_class),
00108                               G_SIGNAL_RUN_LAST,
00109                               G_STRUCT_OFFSET (GtkComboPeriodicClass, changed),
00110                               NULL, NULL,
00111                               g_cclosure_marshal_VOID__INT,
00112                               G_TYPE_NONE, 1, G_TYPE_INT);
00113 }
00114 
00115 GSF_CLASS (GtkComboPeriodic, gtk_combo_periodic,
00116            gtk_combo_periodic_class_init, gtk_combo_periodic_init,
00117            GO_COMBO_BOX_TYPE)
00118 
00119 GtkWidget *gtk_combo_periodic_new (void)
00120 {
00121         return GTK_WIDGET (g_object_new (GTK_COMBO_PERIODIC_TYPE, NULL));
00122 }
00123 
00124 guint   gtk_combo_periodic_get_element  (GtkComboPeriodic* combo)
00125 {
00126         return gtk_periodic_get_element (GTK_PERIODIC (combo->periodic));
00127 }
00128 
00129 void    gtk_combo_periodic_set_element  (GtkComboPeriodic* combo, guint element)
00130 {
00131         g_signal_handler_block (combo->periodic, combo->handler_id);
00132         gtk_periodic_set_element (GTK_PERIODIC (combo->periodic), element);
00133         g_signal_handler_unblock (combo->periodic, combo->handler_id);
00134         gtk_label_set_text (GTK_LABEL (combo->label), gcu_element_get_symbol (element));
00135 }

Generated on Sun Jan 1 14:15:49 2006 for The Gnome Chemistry Utils by  doxygen 1.4.1