[gtk+/wip/baedert/drawing] treeviewcolumn: Remove input window
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing] treeviewcolumn: Remove input window
- Date: Sat, 15 Jul 2017 18:43:53 +0000 (UTC)
commit 6e3b361761742ff677a126cbfdd16ba62d3d1462
Author: Timm Bäder <mail baedert org>
Date: Sat Jul 15 20:43:52 2017 +0200
treeviewcolumn: Remove input window
gtk/gtktreeprivate.h | 7 ++-
gtk/gtktreeview.c | 71 +++++++++++-------------------
gtk/gtktreeviewcolumn.c | 110 +++++++++++++++--------------------------------
3 files changed, 64 insertions(+), 124 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 820187e..bac7d80 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -93,8 +93,7 @@ gboolean _gtk_tree_selection_row_is_selectable (GtkTreeSelection *sele
void _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column);
-void _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column);
-
+
void _gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
GtkTreeView *tree_view);
gint _gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column);
@@ -133,13 +132,15 @@ void gtk_tree_view_column_cell_snapshot (GtkTreeViewColumn
*tree_column,
void _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
gboolean install_handler);
gboolean _gtk_tree_view_column_cell_get_dirty (GtkTreeViewColumn *tree_column);
-GdkWindow *_gtk_tree_view_column_get_window (GtkTreeViewColumn *column);
void _gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
gint padding);
gint _gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column);
gint _gtk_tree_view_column_get_drag_x (GtkTreeViewColumn *column);
GtkCellAreaContext *_gtk_tree_view_column_get_context (GtkTreeViewColumn *column);
+gboolean _gtk_tree_view_column_coords_in_resize_rect (GtkTreeViewColumn *column,
+ double x,
+ double y);
G_END_DECLS
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 1c1ede9..5ea1618 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -2165,7 +2165,6 @@ gtk_tree_view_map_buttons (GtkTreeView *tree_view)
{
GtkTreeViewColumn *column;
GtkWidget *button;
- GdkWindow *window;
for (list = tree_view->priv->columns; list; list = list->next)
{
@@ -2179,21 +2178,6 @@ gtk_tree_view_map_buttons (GtkTreeView *tree_view)
!gtk_widget_get_mapped (button))
gtk_widget_map (button);
}
- for (list = tree_view->priv->columns; list; list = list->next)
- {
- column = list->data;
- if (gtk_tree_view_column_get_visible (column) == FALSE)
- continue;
-
- window = _gtk_tree_view_column_get_window (column);
- if (gtk_tree_view_column_get_resizable (column))
- {
- gdk_window_raise (window);
- gdk_window_show (window);
- }
- else
- gdk_window_hide (window);
- }
}
}
@@ -2245,7 +2229,6 @@ gtk_tree_view_unrealize (GtkWidget *widget)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
GtkTreeViewPrivate *priv = tree_view->priv;
- GList *list;
if (priv->scroll_timeout != 0)
{
@@ -2288,9 +2271,6 @@ gtk_tree_view_unrealize (GtkWidget *widget)
g_source_remove (priv->typeselect_flush_timeout);
priv->typeselect_flush_timeout = 0;
}
-
- for (list = priv->columns; list; list = list->next)
- _gtk_tree_view_column_unrealize_button (GTK_TREE_VIEW_COLUMN (list->data));
if (priv->drag_window)
{
@@ -3126,24 +3106,18 @@ gtk_tree_view_column_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
gdouble y,
GtkTreeView *tree_view)
{
- GdkEventSequence *sequence;
GtkTreeViewColumn *column;
- const GdkEvent *event;
GList *list;
- gint i;
if (n_press != 2)
return;
- sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
- event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
-
- for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
+ for (list = tree_view->priv->columns; list; list = list->next)
{
column = list->data;
- if (event->any.window != _gtk_tree_view_column_get_window (column) ||
- !gtk_tree_view_column_get_resizable (column))
+ if (!_gtk_tree_view_column_coords_in_resize_rect (column, x, y) ||
+ !gtk_tree_view_column_get_resizable (column))
continue;
if (gtk_tree_view_column_get_sizing (column) != GTK_TREE_VIEW_COLUMN_AUTOSIZE)
@@ -3164,18 +3138,12 @@ gtk_tree_view_column_drag_gesture_begin (GtkGestureDrag *gesture,
gdouble start_y,
GtkTreeView *tree_view)
{
- GdkEventSequence *sequence;
GtkTreeViewColumn *column;
- const GdkEvent *event;
- GdkWindow *window;
gboolean rtl;
GList *list;
gint i;
rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
- sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
- event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
- window = event->any.window;
for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
{
@@ -3184,7 +3152,7 @@ gtk_tree_view_column_drag_gesture_begin (GtkGestureDrag *gesture,
column = list->data;
- if (window != _gtk_tree_view_column_get_window (column))
+ if (!_gtk_tree_view_column_coords_in_resize_rect (column, start_x, start_y))
continue;
if (!gtk_tree_view_column_get_resizable (column))
@@ -3254,13 +3222,6 @@ gtk_tree_view_button_release_drag_column (GtkTreeView *tree_view)
gtk_widget_set_parent (button, GTK_WIDGET (tree_view));
g_object_unref (button);
gtk_widget_queue_resize (widget);
- if (gtk_tree_view_column_get_resizable (tree_view->priv->drag_column))
- {
- gdk_window_raise (_gtk_tree_view_column_get_window (tree_view->priv->drag_column));
- gdk_window_show (_gtk_tree_view_column_get_window (tree_view->priv->drag_column));
- }
- else
- gdk_window_hide (_gtk_tree_view_column_get_window (tree_view->priv->drag_column));
gtk_widget_grab_focus (button);
@@ -4505,6 +4466,8 @@ gtk_tree_view_motion (GtkWidget *widget,
GtkRBTree *tree;
GtkRBNode *node;
gint new_y;
+ GList *list;
+ gboolean cursor_set = FALSE;
tree_view = (GtkTreeView *) widget;
@@ -4524,6 +4487,25 @@ gtk_tree_view_motion (GtkWidget *widget,
prelight_or_select (tree_view, tree, node, event->x, event->y);
}
+ for (list = tree_view->priv->columns; list; list = list->next)
+ {
+ GtkTreeViewColumn *column = list->data;
+
+ if (_gtk_tree_view_column_coords_in_resize_rect (column, event->x, event->y))
+ {
+ GdkDisplay *display = gtk_widget_get_display (widget);
+ GdkCursor *cursor = gdk_cursor_new_from_name (display, "col-resize");
+
+ gtk_widget_set_cursor (widget, cursor);
+ g_object_unref (cursor);
+ cursor_set = TRUE;
+ break;
+ }
+ }
+
+ if (!cursor_set)
+ gtk_widget_set_cursor (widget, NULL);
+
return GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->motion_notify_event (widget, event);
}
@@ -11499,9 +11481,6 @@ gtk_tree_view_remove_column (GtkTreeView *tree_view,
position = g_list_index (tree_view->priv->columns, column);
- if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
- _gtk_tree_view_column_unrealize_button (column);
-
_gtk_tree_view_column_unset_tree_view (column);
tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index d989e4d..02d4436 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -35,6 +35,7 @@
#include "gtkintl.h"
#include "gtktypebuiltins.h"
#include "a11y/gtktreeviewaccessibleprivate.h"
+#include "gtkwidgetprivate.h"
/**
@@ -130,7 +131,6 @@ struct _GtkTreeViewColumnPrivate
GtkWidget *child;
GtkWidget *arrow;
GtkWidget *frame;
- GdkWindow *window;
gulong property_changed_signal;
gfloat xalign;
@@ -829,6 +829,7 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
priv->frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
+ gtk_widget_set_hexpand (priv->frame, TRUE);
gtk_widget_set_halign (priv->frame, GTK_ALIGN_START);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
@@ -976,25 +977,10 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (priv->tree_view)))
{
gtk_widget_show (priv->button);
-
- if (priv->window)
- {
- if (priv->resizable)
- {
- gdk_window_show (priv->window);
- gdk_window_raise (priv->window);
- }
- else
- {
- gdk_window_hide (priv->window);
- }
- }
}
else
{
gtk_widget_hide (priv->button);
- if (priv->window)
- gdk_window_hide (priv->window);
}
}
@@ -1297,53 +1283,15 @@ void
_gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
{
GtkTreeViewColumnPrivate *priv = column->priv;
- GtkAllocation allocation;
- GtkTreeView *tree_view;
- gboolean rtl;
- GdkDisplay *display;
- GdkCursor *cursor;
- tree_view = (GtkTreeView *)priv->tree_view;
- rtl = (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_RTL);
-
- g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
+ g_return_if_fail (GTK_IS_TREE_VIEW (priv->tree_view));
g_return_if_fail (gtk_widget_get_realized (priv->tree_view));
g_return_if_fail (priv->button != NULL);
- gtk_widget_set_parent_window (priv->button, gtk_widget_get_window (priv->tree_view));
-
- display = gtk_widget_get_display (priv->tree_view);
- gtk_widget_get_allocation (priv->button, &allocation);
-
- priv->window = gdk_window_new_input (gtk_widget_get_window (priv->tree_view),
- GDK_ALL_EVENTS_MASK,
- &(GdkRectangle) {(allocation.x + (rtl ? 0 : allocation.width)) -
TREE_VIEW_DRAG_WIDTH / 2, 0,
- TREE_VIEW_DRAG_WIDTH,
_gtk_tree_view_get_header_height (tree_view)});
- cursor = gdk_cursor_new_from_name (display, "col-resize");
- gdk_window_set_cursor (priv->window, cursor);
- g_object_unref (cursor);
-
- gtk_widget_register_window (GTK_WIDGET (tree_view), priv->window);
-
gtk_tree_view_column_update_button (column);
}
void
-_gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column)
-{
- GtkTreeViewColumnPrivate *priv;
-
- g_return_if_fail (column != NULL);
-
- priv = column->priv;
- g_return_if_fail (priv->window != NULL);
-
- gtk_widget_unregister_window (GTK_WIDGET (priv->tree_view), priv->window);
- gdk_window_destroy (priv->window);
- priv->window = NULL;
-}
-
-void
_gtk_tree_view_column_unset_model (GtkTreeViewColumn *column,
GtkTreeModel *old_model)
{
@@ -2069,9 +2017,7 @@ _gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
int width)
{
GtkTreeViewColumnPrivate *priv;
- gboolean rtl;
GtkAllocation allocation = { 0, 0, 0, 0 };
- GtkAllocation widget_allocation;
GtkAllocation clip;
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
@@ -2085,27 +2031,20 @@ _gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
priv->width = width;
gtk_cell_area_context_allocate (priv->cell_area_context, priv->width - priv->padding, -1);
- gtk_widget_get_allocation (priv->tree_view, &widget_allocation);
if (gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (priv->tree_view)))
{
- allocation.x = widget_allocation.x + x_offset;
- allocation.y = widget_allocation.y;
+ /* TODO: Underallocates the button horizontally, but
+ * https://bugzilla.gnome.org/show_bug.cgi?id=770388
+ */
+ allocation.x = x_offset;
+ allocation.y = 0;
allocation.width = width;
allocation.height = _gtk_tree_view_get_header_height (GTK_TREE_VIEW (priv->tree_view));
gtk_widget_size_allocate (priv->button, &allocation, -1, &clip);
}
- if (priv->window)
- {
- rtl = (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_RTL);
- gdk_window_move_resize (priv->window,
- allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
- allocation.y,
- TREE_VIEW_DRAG_WIDTH, allocation.height);
- }
-
g_object_notify_by_pspec (G_OBJECT (tree_column), tree_column_props[PROP_X_OFFSET]);
g_object_notify_by_pspec (G_OBJECT (tree_column), tree_column_props[PROP_WIDTH]);
}
@@ -3104,12 +3043,6 @@ gtk_tree_view_column_get_button (GtkTreeViewColumn *tree_column)
return tree_column->priv->button;
}
-GdkWindow *
-_gtk_tree_view_column_get_window (GtkTreeViewColumn *column)
-{
- return column->priv->window;
-}
-
void
_gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
gint padding)
@@ -3138,3 +3071,30 @@ _gtk_tree_view_column_get_context (GtkTreeViewColumn *column)
{
return column->priv->cell_area_context;
}
+
+gboolean
+_gtk_tree_view_column_coords_in_resize_rect (GtkTreeViewColumn *column,
+ double x,
+ double y)
+{
+ GtkTreeViewColumnPrivate *priv = column->priv;
+ GtkAllocation button_allocation;
+
+ /* x and y are in treeview coordinates. */
+
+ if (!gtk_widget_get_realized (priv->button) ||
+ !priv->resizable ||
+ !priv->visible)
+ return FALSE;
+
+ gtk_widget_get_outer_allocation (priv->button, &button_allocation);
+
+ /* No translation needed */
+ g_assert (gtk_widget_get_parent (priv->button) == priv->tree_view);
+
+ if (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_LTR)
+ button_allocation.x += button_allocation.width - TREE_VIEW_DRAG_WIDTH;
+
+ button_allocation.width = TREE_VIEW_DRAG_WIDTH;
+ return gdk_rectangle_contains_point (&button_allocation, (int)x, (int)y);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]