[gtk+/resizegrips] GtkWindow: update resize grips properly
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/resizegrips] GtkWindow: update resize grips properly
- Date: Thu, 30 Sep 2010 18:06:58 +0000 (UTC)
commit f48f0995592e6d4e6ea4f43cf71d5e62ab75728a
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Sep 30 14:05:19 2010 -0400
GtkWindow: update resize grips properly
Copy some code from GtkStatusbar to handle direction and resizability
changes properly.
gtk/gtkwindow.c | 183 +++++++++++++++++++++++++++++++-----------------------
1 files changed, 105 insertions(+), 78 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 94a39a1..83b0fde 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -330,6 +330,10 @@ static gint gtk_window_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_window_real_set_focus (GtkWindow *window,
GtkWidget *focus);
+static void gtk_window_direction_changed (GtkWidget *widget,
+ GtkTextDirection prev_dir);
+static void gtk_window_state_changed (GtkWidget *widget,
+ GtkStateType previous_state);
static void gtk_window_real_activate_default (GtkWindow *window);
static void gtk_window_real_activate_focus (GtkWindow *window);
@@ -564,6 +568,8 @@ gtk_window_class_init (GtkWindowClass *klass)
widget_class->get_preferred_width = gtk_window_get_preferred_width;
widget_class->get_preferred_height = gtk_window_get_preferred_height;
widget_class->window_state_event = gtk_window_state_event;
+ widget_class->direction_changed = gtk_window_direction_changed;
+ widget_class->state_changed = gtk_window_state_changed;
container_class->check_resize = gtk_window_check_resize;
@@ -1094,8 +1100,7 @@ gtk_window_set_property (GObject *object,
gtk_window_set_startup_id (window, g_value_get_string (value));
break;
case PROP_RESIZABLE:
- priv->resizable = g_value_get_boolean (value);
- gtk_widget_queue_resize (GTK_WIDGET (window));
+ gtk_window_set_resizable (window, g_value_get_boolean (value));
break;
case PROP_MODAL:
gtk_window_set_modal (window, g_value_get_boolean (value));
@@ -4910,77 +4915,89 @@ get_grip_edge (GtkWidget *widget)
static void
set_grip_cursor (GtkWindow *window)
{
+ GtkWidget *widget = GTK_WIDGET (window);
GtkWindowPrivate *priv = window->priv;
+ GdkWindowEdge edge;
+ GdkDisplay *display;
+ GdkCursorType cursor_type;
+ GdkCursor *cursor;
- if (priv->has_resize_grip && priv->grip_window != NULL)
- {
- GtkWidget *widget = GTK_WIDGET (window);
- GdkDisplay *display;
- GdkWindowEdge edge;
- GdkCursorType cursor_type;
- GdkCursor *cursor;
-
- if (gtk_widget_is_sensitive (widget))
- {
- display = gtk_widget_get_display (widget);
- edge = get_grip_edge (widget);
+ if (priv->grip_window == NULL)
+ return;
- if (edge == GDK_WINDOW_EDGE_SOUTH_EAST)
- cursor_type = GDK_BOTTOM_RIGHT_CORNER;
- else
- cursor_type = GDK_BOTTOM_LEFT_CORNER;
+ if (gtk_widget_is_sensitive (widget))
+ {
+ edge = get_grip_edge (widget);
- cursor = gdk_cursor_new_for_display (display, cursor_type);
- gdk_window_set_cursor (priv->grip_window, cursor);
- gdk_cursor_unref (cursor);
- }
+ if (edge == GDK_WINDOW_EDGE_SOUTH_EAST)
+ cursor_type = GDK_BOTTOM_RIGHT_CORNER;
else
- gdk_window_set_cursor (priv->grip_window, NULL);
+ cursor_type = GDK_BOTTOM_LEFT_CORNER;
+
+ display = gtk_widget_get_display (widget);
+ cursor = gdk_cursor_new_for_display (display, cursor_type);
+ gdk_window_set_cursor (priv->grip_window, cursor);
+ gdk_cursor_unref (cursor);
}
+ else
+ gdk_window_set_cursor (priv->grip_window, NULL);
}
static void
set_grip_shape (GtkWindow *window)
{
GtkWindowPrivate *priv = window->priv;
+ cairo_region_t *region;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ double width, height;
+
+ if (priv->grip_window == NULL)
+ return;
- if (priv->has_resize_grip && priv->grip_window != NULL)
+ width = gdk_window_get_width (priv->grip_window);
+ height = gdk_window_get_height (priv->grip_window);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+
+ cr = cairo_create (surface);
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
+ cairo_paint (cr);
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+ if (get_grip_edge (GTK_WIDGET (window)) == GDK_WINDOW_EDGE_SOUTH_EAST)
+ {
+ cairo_move_to (cr, width, 0.0);
+ cairo_line_to (cr, width, height);
+ cairo_line_to (cr, 0.0, height);
+ }
+ else
{
- cairo_region_t *region;
- cairo_surface_t *surface;
- cairo_t *cr;
- double width, height;
+ cairo_move_to (cr, 0.0, 0.0);
+ cairo_line_to (cr, width, height);
+ cairo_line_to (cr, 0.0, height);
+ }
+ cairo_close_path (cr);
+ cairo_fill (cr);
+ cairo_destroy (cr);
+ region = gdk_cairo_region_create_from_surface (surface);
+ cairo_surface_destroy (surface);
+ gdk_window_shape_combine_region (priv->grip_window, region, 0, 0);
+}
- width = gdk_window_get_width (priv->grip_window);
- height = gdk_window_get_height (priv->grip_window);
- surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+static void
+set_grip_position (GtkWindow *window)
+{
+ GtkWindowPrivate *priv = window->priv;
+ GdkRectangle rect;
- cr = cairo_create (surface);
- cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
- cairo_paint (cr);
- cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
- if (get_grip_edge (GTK_WIDGET (window)) == GDK_WINDOW_EDGE_SOUTH_EAST)
- {
- cairo_move_to (cr, width, 0.0);
- cairo_line_to (cr, width, height);
- cairo_line_to (cr, 0.0, height);
- }
- else
- {
- cairo_move_to (cr, 0.0, 0.0);
- cairo_line_to (cr, width, height);
- cairo_line_to (cr, 0.0, height);
- }
- cairo_close_path (cr);
- cairo_fill (cr);
- cairo_destroy (cr);
- region = gdk_cairo_region_create_from_surface (surface);
- cairo_surface_destroy (surface);
+ if (priv->grip_window == NULL)
+ return;
- gdk_window_shape_combine_region (priv->grip_window,
- region, 0, 0);
- }
+ get_grip_rect (window, &rect);
+ gdk_window_raise (priv->grip_window);
+ gdk_window_move_resize (priv->grip_window,
+ rect.x, rect.y,
+ rect.width, rect.height);
}
static void
@@ -5018,14 +5035,7 @@ gtk_window_size_allocate (GtkWidget *widget,
if (priv->grip_window != NULL)
{
- GdkRectangle rect;
-
- get_grip_rect (window, &rect);
-
- gdk_window_move_resize (priv->grip_window,
- rect.x, rect.y,
- rect.width, rect.height);
-
+ set_grip_position (window);
set_grip_cursor (window);
set_grip_shape (window);
}
@@ -5193,12 +5203,14 @@ get_grip_rect (GtkWindow *window,
static void
set_grip_visibility (GtkWindow *window)
{
- GtkWindowPrivate *priv;
+ GtkWindowPrivate *priv = window->priv;
GdkWindowState state;
- priv = window->priv;
+ if (priv->grip_window == NULL)
+ return;
state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
+
if (priv->has_resize_grip && priv->resizable &&
(state & (GDK_WINDOW_STATE_MAXIMIZED|GDK_WINDOW_STATE_FULLSCREEN)) == 0)
gdk_window_show (priv->grip_window);
@@ -5210,13 +5222,30 @@ static gboolean
gtk_window_state_event (GtkWidget *widget,
GdkEventWindowState *event)
{
+ set_grip_visibility (GTK_WINDOW (widget));
+
+ return FALSE;
+}
+
+static void
+gtk_window_direction_changed (GtkWidget *widget,
+ GtkTextDirection prev_dir)
+{
GtkWindow *window = GTK_WINDOW (widget);
- GtkWindowPrivate *priv = window->priv;
- if (priv->grip_window)
- set_grip_visibility (window);
+ set_grip_cursor (window);
+ set_grip_position (window);
+ set_grip_shape (window);
+}
- return FALSE;
+static void
+gtk_window_state_changed (GtkWidget *widget,
+ GtkStateType previous_state)
+{
+ GtkWindow *window = GTK_WINDOW (widget);
+
+ set_grip_cursor (window);
+ set_grip_visibility (window);
}
static void
@@ -5442,14 +5471,12 @@ gtk_window_button_press_event (GtkWidget *widget,
GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
if (event->window == priv->grip_window)
- {
- gtk_window_begin_resize_drag (GTK_WINDOW (widget),
- get_grip_edge (widget),
- event->button,
- event->x_root,
- event->y_root,
- event->time);
- }
+ gtk_window_begin_resize_drag (GTK_WINDOW (widget),
+ get_grip_edge (widget),
+ event->button,
+ event->x_root,
+ event->y_root,
+ event->time);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]