[libslab/gnome-3] more, rather mixed success porting action ...
- From: Michael Meeks <michael src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libslab/gnome-3] more, rather mixed success porting action ...
- Date: Wed, 5 Oct 2011 10:07:05 +0000 (UTC)
commit 1e42e9e21d9804e9d38da0443f475e605222b78e
Author: Michael Meeks <michael meeks suse com>
Date: Mon Sep 26 16:43:02 2011 +0100
more, rather mixed success porting action ...
libslab/app-resizer.c | 110 ++++++++++++++++------------------
libslab/shell-window.c | 129 +++++++++++++++-------------------------
libslab/shell-window.h | 1 +
libslab/slab-section.c | 154 ++++++++++++++++++-----------------------------
4 files changed, 160 insertions(+), 234 deletions(-)
---
diff --git a/libslab/app-resizer.c b/libslab/app-resizer.c
index 9925d32..4451387 100644
--- a/libslab/app-resizer.c
+++ b/libslab/app-resizer.c
@@ -26,27 +26,8 @@
static void app_resizer_class_init (AppResizerClass *);
static void app_resizer_init (AppResizer *);
-static void app_resizer_size_allocate (GtkWidget * resizer, GtkAllocation * allocation);
-static gboolean app_resizer_paint_window (GtkWidget * widget, GdkEventExpose * event,
- AppShellData * app_data);
-
G_DEFINE_TYPE (AppResizer, app_resizer, GTK_TYPE_LAYOUT);
-
-static void
-app_resizer_class_init (AppResizerClass * klass)
-{
- GtkWidgetClass *widget_class;
-
- widget_class = GTK_WIDGET_CLASS (klass);
- widget_class->size_allocate = app_resizer_size_allocate;
-}
-
-static void
-app_resizer_init (AppResizer * window)
-{
-}
-
void
remove_container_entries (GtkContainer * widget)
{
@@ -257,6 +238,59 @@ app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
child_allocation.height);
}
+static gboolean
+app_resizer_draw (GtkWidget * widget, cairo_t *cr)
+{
+
+ AppShellData * app_data = APP_RESIZER (widget)->app_data;
+
+ /*
+ printf("ENTER - app_resizer_paint_window\n");
+ printf("Area: %d, %d, %d, %d\n", event->area.x, event->area.y, event->area.width, event->area.height);
+ printf("Allocation:%d, %d, %d, %d\n\n", widget->allocation.x, widget->allocation.y, widget->allocation.width, widget->allocation.height);
+ */
+
+ GTK_WIDGET_CLASS (app_resizer_parent_class)->draw (widget, cr);
+
+ g_warning ("TESTME: do I render the selected group nicely !?");
+
+ if (app_data->selected_group)
+ {
+ GdkRGBA rgba;
+ GtkWidget *selected_widget = GTK_WIDGET (app_data->selected_group);
+ GtkAllocation allocation, selected_allocation;
+ GtkStyleContext *context;
+
+ gtk_widget_get_allocation (widget, &allocation);
+ gtk_widget_get_allocation (selected_widget, &selected_allocation);
+
+ /* set the correct source color */
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context, GTK_STATE_SELECTED, &rgba);
+ gdk_cairo_set_source_rgba (cr, &rgba);
+
+ cairo_rectangle (cr, selected_allocation.x, selected_allocation.y,
+ allocation.width, selected_allocation.height);
+ }
+
+ return FALSE;
+}
+
+static void
+app_resizer_class_init (AppResizerClass * klass)
+{
+ GtkWidgetClass *widget_class;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->size_allocate = app_resizer_size_allocate;
+ widget_class->draw = app_resizer_draw;
+}
+
+static void
+app_resizer_init (AppResizer * window)
+{
+}
+
GtkWidget *
app_resizer_new (GtkBox * child, gint initial_num_columns,
gboolean homogeneous, AppShellData * app_data)
@@ -273,9 +307,6 @@ app_resizer_new (GtkBox * child, gint initial_num_columns,
widget->setting_style = FALSE;
widget->app_data = app_data;
- g_signal_connect (G_OBJECT (widget), "expose-event", G_CALLBACK (app_resizer_paint_window),
- app_data);
-
gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (child));
widget->child = child;
@@ -297,38 +328,3 @@ app_resizer_set_vadjustment_value (GtkWidget * widget, gdouble value)
}
gtk_adjustment_set_value (adjust, value);
}
-
-static gboolean
-app_resizer_paint_window (GtkWidget * widget, GdkEventExpose * event, AppShellData * app_data)
-{
- /*
- printf("ENTER - app_resizer_paint_window\n");
- printf("Area: %d, %d, %d, %d\n", event->area.x, event->area.y, event->area.width, event->area.height);
- printf("Allocation:%d, %d, %d, %d\n\n", widget->allocation.x, widget->allocation.y, widget->allocation.width, widget->allocation.height);
- */
-
- g_warning ("GTK3ME: No gdk to draw rectangles with");
-#ifdef DISABLED_FOR_NOW
- gdk_draw_rectangle (gtk_layout_get_bin_window (GTK_LAYOUT (widget)),
- gtk_widget_get_style (widget)->base_gc[GTK_STATE_NORMAL],
- TRUE, event->area.x, event->area.y,
- event->area.width, event->area.height);
-
- if (app_data->selected_group)
- {
- GtkWidget *selected_widget = GTK_WIDGET (app_data->selected_group);
- GtkAllocation allocation, selected_allocation;
-
- gtk_widget_get_allocation (widget, &allocation);
- gtk_widget_get_allocation (selected_widget, &selected_allocation);
-
- gdk_draw_rectangle (gtk_widget_get_window (selected_widget), /* drawing on child window and child coordinates */
- gtk_widget_get_style (selected_widget)->light_gc[GTK_STATE_SELECTED], TRUE,
- selected_allocation.x, selected_allocation.y,
- allocation.width, /* drawing with our coordinates here to draw all the way to the edge. */
- selected_allocation.height);
- }
-#endif
-
- return FALSE;
-}
diff --git a/libslab/shell-window.c b/libslab/shell-window.c
index d52e538..9d5c480 100644
--- a/libslab/shell-window.c
+++ b/libslab/shell-window.c
@@ -26,92 +26,63 @@
static void shell_window_class_init (ShellWindowClass *);
static void shell_window_init (ShellWindow *);
-static void shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
- AppShellData * data);
-
-gboolean shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data);
-
-#define SHELL_WINDOW_BORDER_WIDTH 6
G_DEFINE_TYPE (ShellWindow, shell_window, GTK_TYPE_FRAME);
-static void
-shell_window_class_init (ShellWindowClass * klass)
+static GtkSizeRequestMode
+shell_window_get_request_mode (GtkWidget *widget)
{
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}
static void
-shell_window_init (ShellWindow * window)
+shell_window_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
{
- window->_hbox = NULL;
- window->_left_pane = NULL;
- window->_right_pane = NULL;
+ AppShellData * app_data = SHELL_WINDOW (widget)->data;
+
+ GTK_WIDGET_CLASS (shell_window_parent_class)->get_preferred_height
+ (widget, minimum_height, natural_height);
+ *natural_height = (double)gdk_screen_height () * SIZING_HEIGHT_PERCENT;
+// fprintf (stderr, "heights: %d %d\n", *minimum_height, *natural_height);
}
-GtkWidget *
-shell_window_new (AppShellData * app_data)
+static void
+shell_window_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width)
{
- ShellWindow *window = g_object_new (SHELL_WINDOW_TYPE, NULL);
+ AppShellData * app_data = SHELL_WINDOW (widget)->data;
- gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
- gtk_frame_set_shadow_type(GTK_FRAME(window), GTK_SHADOW_NONE);
+ GTK_WIDGET_CLASS (shell_window_parent_class)->get_preferred_width
+ (widget, minimum_width, natural_width);
- window->_hbox = GTK_BOX (gtk_hbox_new (FALSE, 0));
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (window->_hbox));
+ *natural_width = MAX (((gfloat) gdk_screen_width () * SIZING_HEIGHT_PERCENT), *natural_width);
+// fprintf (stderr, "widths: %d %d\n", *minimum_width, *natural_width);
+}
- g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (shell_window_paint_window),
- NULL);
- window->resize_handler_id =
- g_signal_connect (G_OBJECT (window), "size-request",
- G_CALLBACK (shell_window_handle_size_request), app_data);
+static void
+shell_window_class_init (ShellWindowClass * klass)
+{
+ GtkWidgetClass *wklass = GTK_WIDGET_CLASS (klass);
- return GTK_WIDGET (window);
+ wklass->get_request_mode = shell_window_get_request_mode;
+ wklass->get_preferred_width = shell_window_get_preferred_width;
+ wklass->get_preferred_height = shell_window_get_preferred_height;
}
-void
-shell_window_clear_resize_handler (ShellWindow * win)
+static void
+shell_window_init (ShellWindow * window)
{
- if (win->resize_handler_id)
- {
- g_signal_handler_disconnect (win, win->resize_handler_id);
- win->resize_handler_id = 0;
- }
+ window->_hbox = NULL;
+ window->_left_pane = NULL;
+ window->_right_pane = NULL;
}
-/* We want the window to come up with proper runtime calculated width ( ie taking into account font size, locale, ...) so
- we can't hard code a size. But since ScrolledWindow returns basically zero for it's size request we need to
- grab the "real" desired width. Once it's shown though we want to allow the user to size down if they want too, so
- we unhook this function
-*/
-static void
-shell_window_handle_size_request (GtkWidget * widget, GtkRequisition * requisition,
- AppShellData * app_data)
+void
+shell_window_clear_resize_handler (ShellWindow * win)
{
- GtkRequisition child_requisition;
- gint height;
-
- /*
- Fixme - counting on this being called after the real size request is done.
- seems to be that way but I don't know why. I would think I would need to explictly call it here first
- printf("Enter - shell_window_handle_size_request\n");
- printf("passed in width:%d, height:%d\n", requisition->width, requisition->height);
- printf("left side width:%d\n", SHELL_WINDOW(widget)->_left_pane->requisition.width);
- printf("right side width:%d\n", GTK_WIDGET(APP_RESIZER(app_data->category_layout)->child)->requisition.width);
- */
-
- gtk_widget_get_requisition (GTK_WIDGET (APP_RESIZER (app_data->category_layout)->child),
- &child_requisition);
- requisition->width += child_requisition.width;
-
- /* use the left side as a minimum height, if the right side is taller,
- use it up to SIZING_HEIGHT_PERCENT of the screen height
- */
- height = child_requisition.height + 10;
- if (height > requisition->height)
- {
- requisition->height =
- MIN (((gfloat) gdk_screen_height () * SIZING_HEIGHT_PERCENT), height);
- }
}
void
@@ -130,26 +101,20 @@ shell_window_set_contents (ShellWindow * shell, GtkWidget * left_pane, GtkWidget
gtk_container_add (GTK_CONTAINER (shell->_right_pane), right_pane);
}
-gboolean
-shell_window_paint_window (GtkWidget * widget, GdkEventExpose * event, gpointer data)
+GtkWidget *
+shell_window_new (AppShellData * app_data)
{
- GtkWidget *left_pane, *right_pane;
- GtkAllocation allocation;
+ ShellWindow *window = g_object_new (SHELL_WINDOW_TYPE, NULL);
- left_pane = SHELL_WINDOW (widget)->_left_pane;
- right_pane = SHELL_WINDOW (widget)->_right_pane;
+ window->data = app_data;
- gtk_widget_get_allocation (left_pane, &allocation);
+ gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
+ gtk_frame_set_shadow_type(GTK_FRAME(window), GTK_SHADOW_NONE);
-#ifdef PORTING_MORE
- /* draw left pane background */
- gtk_paint_flat_box (gtk_widget_get_style (widget),
- gtk_widget_get_window (widget),
- gtk_widget_get_state (widget),
- GTK_SHADOW_NONE, NULL, widget, "",
- allocation.x, allocation.y,
- allocation.width, allocation.height);
-#endif
+ window->_hbox = GTK_BOX (gtk_box_new (FALSE, 0));
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (window->_hbox),
+ GTK_ORIENTATION_HORIZONTAL);
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (window->_hbox));
- return FALSE;
+ return GTK_WIDGET (window);
}
diff --git a/libslab/shell-window.h b/libslab/shell-window.h
index 8318094..3aed75f 100644
--- a/libslab/shell-window.h
+++ b/libslab/shell-window.h
@@ -45,6 +45,7 @@ struct _ShellWindow
GtkBox *_hbox;
GtkWidget *_left_pane;
GtkWidget *_right_pane;
+ AppShellData *data;
gulong resize_handler_id;
};
diff --git a/libslab/slab-section.c b/libslab/slab-section.c
index 2bf032c..a3b4e98 100644
--- a/libslab/slab-section.c
+++ b/libslab/slab-section.c
@@ -22,106 +22,17 @@
G_DEFINE_TYPE (SlabSection, slab_section, GTK_TYPE_BOX)
-static void slab_section_finalize (GObject *);
-
-static void slab_section_class_init (SlabSectionClass * slab_section_class)
-{
- GObjectClass *g_obj_class = G_OBJECT_CLASS (slab_section_class);
-
- g_obj_class->finalize = slab_section_finalize;
-}
-
-static void
-slab_section_init (SlabSection * section)
-{
- section->title = NULL;
- section->contents = NULL;
- gtk_orientable_set_orientation (GTK_ORIENTABLE (section),
- GTK_ORIENTATION_VERTICAL);
-}
-
-static void
-slab_section_finalize (GObject * obj)
-{
- g_assert (IS_SLAB_SECTION (obj));
- (*G_OBJECT_CLASS (slab_section_parent_class)->finalize) (obj);
-}
-
-static void
-slab_section_set_title_color (GtkWidget * widget)
-{
- GtkStyle *style;
-
- g_warning ("set_title_color");
-#ifdef PORTING_MORE
- style = gtk_widget_get_style (widget);
-
- switch (SLAB_SECTION (widget)->style)
- {
- case Style1:
- gtk_widget_modify_fg (SLAB_SECTION (widget)->title, GTK_STATE_NORMAL,
- &style->bg[GTK_STATE_SELECTED]);
- break;
- case Style2:
- if (SLAB_SECTION (widget)->selected)
- gtk_widget_modify_fg (SLAB_SECTION (widget)->title, GTK_STATE_NORMAL,
- &style->dark[GTK_STATE_SELECTED]);
- else
- gtk_widget_modify_fg (SLAB_SECTION (widget)->title, GTK_STATE_NORMAL,
- &style->text[GTK_STATE_INSENSITIVE]);
- break;
- default:
- g_assert_not_reached ();
- }
-#endif
-}
-
-static void
-slab_section_style_set (GtkWidget * widget, GtkStyle * prev_style, gpointer user_data)
-{
- static gboolean recursively_entered = FALSE;
- if (!recursively_entered)
- {
- recursively_entered = TRUE;
-
- slab_section_set_title_color (widget);
-
- recursively_entered = FALSE;
- }
-}
-
-/*
-gboolean
-slab_section_expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer data)
-{
- gdk_draw_rectangle (widget->window, widget->style->light_gc[GTK_STATE_SELECTED], TRUE,
- widget->allocation.x, widget->allocation.y,
- widget->allocation.width + 40, widget->allocation.height);
-
- return FALSE;
-}
-*/
-
void
slab_section_set_selected (SlabSection * section, gboolean selected)
{
if (selected == section->selected)
return;
section->selected = selected;
+ gtk_widget_queue_draw (GTK_WIDGET (section));
- /*
- if(selected)
- {
- section->expose_handler_id = g_signal_connect(G_OBJECT(section),
- "expose-event", G_CALLBACK(slab_section_expose_event), NULL);
- }
- else
- {
- g_signal_handler_disconnect(section, section->expose_handler_id);
- }
- */
-
- slab_section_set_title_color (GTK_WIDGET (section));
+ g_warning ("TESTME: side-bar / section title_color %d", selected);
+ gtk_widget_set_state (section->title,
+ selected ? GTK_STATE_SELECTED : GTK_STATE_NORMAL);
}
GtkWidget *
@@ -164,8 +75,6 @@ slab_section_new_with_markup (const gchar * title_markup, SlabStyle style)
gtk_misc_set_alignment (GTK_MISC (section->title), 0.0, 0.5);
gtk_widget_set_name (GTK_WIDGET (section), widget_theming_name);
- g_signal_connect (G_OBJECT (section), "style-set", G_CALLBACK (slab_section_style_set),
- NULL);
gtk_box_pack_start (section->childbox, section->title, FALSE, FALSE, 0);
@@ -203,3 +112,58 @@ slab_section_set_contents (SlabSection * section, GtkWidget * contents)
gtk_box_pack_start (section->childbox, contents, FALSE, FALSE, 0);
}
+
+static gboolean
+slab_section_draw (GtkWidget *widget, cairo_t *cr)
+{
+ SlabSection *section = SLAB_SECTION (widget);
+
+ GTK_WIDGET_CLASS (slab_section_parent_class)->draw (widget, cr);
+
+ g_warning ("TESTME: slab section draw - not so hot !");
+ if (section->selected)
+ {
+ GdkRGBA rgba;
+ GtkAllocation allocation;
+ GtkStyleContext *context;
+
+ g_warning ("TESTME: render slab section selected");
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ /* set the correct source color */
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context, GTK_STATE_SELECTED, &rgba);
+ gdk_cairo_set_source_rgba (cr, &rgba);
+
+ cairo_rectangle (cr, allocation.x, allocation.y,
+ allocation.width, allocation.height);
+ }
+
+ return FALSE;
+}
+
+static void
+slab_section_finalize (GObject * obj)
+{
+ g_assert (IS_SLAB_SECTION (obj));
+ (*G_OBJECT_CLASS (slab_section_parent_class)->finalize) (obj);
+}
+
+static void slab_section_class_init (SlabSectionClass * slab_section_class)
+{
+ GObjectClass *g_obj_class = G_OBJECT_CLASS (slab_section_class);
+
+ g_obj_class->finalize = slab_section_finalize;
+
+ GTK_WIDGET_CLASS (slab_section_class)->draw = slab_section_draw;
+}
+
+static void
+slab_section_init (SlabSection * section)
+{
+ section->title = NULL;
+ section->contents = NULL;
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (section),
+ GTK_ORIENTATION_VERTICAL);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]