r1553 - trunk/src/target/OM-2007/openmoko-libs/libmokoui
thomas at sita.openmoko.org
thomas at sita.openmoko.org
Thu Mar 29 19:16:51 CEST 2007
Author: thomas
Date: 2007-03-29 19:16:50 +0200 (Thu, 29 Mar 2007)
New Revision: 1553
Modified:
trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.c
trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.h
Log:
* openmoko-libs/libmokoui/moko-dialog.c:
* openmoko-libs/libmokoui/moko-dialog.h:
- Expose more API in the header
- Move button box to the top of the window
- Ensure correct styling is applied to dialog buttons
Modified: trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.c
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.c 2007-03-29 15:56:43 UTC (rev 1552)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.c 2007-03-29 17:16:50 UTC (rev 1553)
@@ -146,34 +146,15 @@
/* Most of this was borrowed from GTK */
+ /**
+ * Set up a "Title Bar" - this should really be done in the window manager
+ * theme...
+ */
+
/* The primary vbox holds the contents of the dialog and the action_area */
self->vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (self), self->vbox);
- /* Create the action_area and put it into the main vbox */
- self->action_area = gtk_hbutton_box_new ();
- gtk_button_box_set_layout (GTK_BUTTON_BOX (self->action_area),
- GTK_BUTTONBOX_END);
- gtk_box_pack_end (GTK_BOX (self->vbox), self->action_area,
- FALSE, TRUE, 0);
-
- /* Mark it as a dialog window */
- gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_DIALOG);
-
- /* Center on parent?, yessir */
- gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ON_PARENT);
-
-
- /* Setup the relationship between this window and its parent */
- parent = moko_application_get_main_window(moko_application_get_instance());
-
- if (parent)
- {
- gtk_window_set_transient_for(GTK_WINDOW(self), GTK_WINDOW (parent) );
- gtk_window_set_modal(GTK_WINDOW(self), TRUE );
- gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE );
- }
-
/* Create the hbox at the top */
priv->hbox = gtk_hbox_new(FALSE, 0);
@@ -199,6 +180,35 @@
/* Add this hbox to the start of vbox */
gtk_box_pack_start (GTK_BOX (self->vbox), priv->hbox, FALSE, FALSE, 0 );
+ /**
+ * Now get back to the proper parts of the dialog
+ */
+
+ /* Create the action_area and put it into the main vbox */
+ self->action_area = gtk_hbutton_box_new ();
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (self->action_area),
+ GTK_BUTTONBOX_END);
+ gtk_box_pack_start (GTK_BOX (self->vbox), self->action_area,
+ FALSE, TRUE, 0);
+
+ /* Mark it as a dialog window */
+ gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+ /* Center on parent?, yessir */
+ gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ON_PARENT);
+
+
+ /* Setup the relationship between this window and its parent */
+ parent = moko_application_get_main_window(moko_application_get_instance());
+
+ if (parent)
+ {
+ gtk_window_set_transient_for(GTK_WINDOW(self), GTK_WINDOW (parent) );
+ gtk_window_set_modal(GTK_WINDOW(self), TRUE );
+ gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE );
+ }
+
+
gtk_widget_show_all (GTK_WIDGET (self->vbox));
}
@@ -275,12 +285,13 @@
GtkWidget *button;
button = gtk_button_new_from_stock (text);
- moko_dialog_add_button_widget (self, button, response_id);
+ moko_dialog_add_button_widget (self, GTK_BUTTON (button), response_id);
gtk_widget_show (button);
return button;
}
+
void
moko_dialog_add_buttons (MokoDialog *self, gchar *first_button_text, ...)
{
@@ -324,6 +335,49 @@
return g_object_new (MOKO_TYPE_DIALOG, NULL);
}
+/* Check all buttons have the correct style */
+static void
+check_button_style_cb (GtkWidget *widget, GtkButtonBox *box)
+{
+ if (GTK_IS_BUTTON (widget)
+ && gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (box), widget))
+ gtk_widget_set_name (GTK_WIDGET (widget), "mokostylusbutton-white");
+ else
+ gtk_widget_set_name (GTK_WIDGET (widget), "mokostylusbutton-black");
+}
+
+static void
+check_button_styles (MokoDialog *self)
+{
+ gtk_container_forall (GTK_CONTAINER (self->action_area), (GtkCallback)
+ (check_button_style_cb), self->action_area);
+#if 0
+
+ GList *children, *l;
+ /*
+ * the button box doesn't seem to return secondary children from
+ * gtk_container_get_children
+ *
+ * maybe a gtk+ bug?
+ */
+
+ children = gtk_container_get_children (GTK_CONTAINER (self->action_area));
+
+ for (l = children; (l = g_list_next (l)); )
+ {
+
+ if (GTK_IS_BUTTON (l->data)
+ && gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (self->action_area), l->data))
+ gtk_widget_set_name (GTK_WIDGET (l->data), "mokostylusbutton-white");
+ else
+ gtk_widget_set_name (GTK_WIDGET (l->data), "mokostylusbutton-black");
+
+ if (GTK_IS_CONTAINER (l->data))
+ l = g_list_concat (l, gtk_container_get_children (GTK_CONTAINER (l->data)));
+ }
+#endif
+}
+
/* Code beyond this point directly derived from gtk+ (gtkdialog.c) */
static void
shutdown_loop (MokoDialog *self)
@@ -382,6 +436,9 @@
g_object_ref (self);
+ /* check we have the correct styles for OpenMoko */
+ check_button_styles (self);
+
was_modal = GTK_WINDOW (self)->modal;
if (!was_modal)
gtk_window_set_modal (GTK_WINDOW (self), TRUE);
Modified: trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.h
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.h 2007-03-29 15:56:43 UTC (rev 1552)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokoui/moko-dialog.h 2007-03-29 17:16:50 UTC (rev 1553)
@@ -60,8 +60,11 @@
GType moko_dialog_get_type (void);
-void moko_dialog_add_button_widget (MokoDialog *self, GtkButton *button, gint response_id);
gint moko_dialog_get_button_response_id (MokoDialog *self, GtkButton *button);
+
+
+void moko_dialog_add_buttons (MokoDialog *self, gchar *first_button_text, ...);
+GtkWidget* moko_dialog_add_button (MokoDialog *self, gchar *text, gint response_id);
void moko_dialog_add_button_widget (MokoDialog *self, GtkButton *button, gint response_id);
void moko_dialog_response (MokoDialog *self, gint response_id);
gint moko_dialog_run (MokoDialog *self);
More information about the commitlog
mailing list