forked from AuroraMiddleware/gtk
Use fixed width for resizing
Removes the hidden “resized-width” and “use-resized-width” properties from GtkTreeViewColumn and instead uses the “fixed-width” property to serve the same purpose. “fixed-width”, if set, will now override the auto-sized width (-1 is now a legal value meaning “not set”). Additional “cleanups” in this commit: 1. When the user resizes the column the “expand” property is now also set to FALSE, in order to prevent the column from suddenly jumping to a different width when the window is resized. 2. The code that translated mouse movement to column sizes has been simplified: the change in column width is now calculated directly from the distance the mouse cursor has traveled. Weird behavior that might have happened previously if the position of the column changed during resizing, is now prevented. 3. There was some lengthy logic handling the keyboard shortcuts used to resize treeview columns, which would call gtk_widget_error_bell() once the minimum or maximum width was reached. Instead of rewriting these checks I simply set the “fixed-width” property to what was requested, relying on the fact that it is already clamped between the minimum and maximum width during size allocation. I will greatly surprised if anyone notices the missing error bell. https://bugzilla.gnome.org/show_bug.cgi?id=691751
This commit is contained in:
parent
d0e0e48942
commit
16195adc92
@ -147,12 +147,6 @@ GdkWindow *_gtk_tree_view_column_get_window (GtkTreeViewColumn *co
|
||||
void _gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
|
||||
gint padding);
|
||||
gint _gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column);
|
||||
void _gtk_tree_view_column_set_resized_width (GtkTreeViewColumn *column,
|
||||
gint width);
|
||||
gint _gtk_tree_view_column_get_resized_width (GtkTreeViewColumn *column);
|
||||
void _gtk_tree_view_column_set_use_resized_width (GtkTreeViewColumn *column,
|
||||
gboolean use_resized_width);
|
||||
gboolean _gtk_tree_view_column_get_use_resized_width (GtkTreeViewColumn *column);
|
||||
gint _gtk_tree_view_column_get_drag_x (GtkTreeViewColumn *column);
|
||||
GtkCellAreaContext *_gtk_tree_view_column_get_context (GtkTreeViewColumn *column);
|
||||
void _gtk_tree_view_reset_header_styles (GtkTreeView *tree_view);
|
||||
|
@ -749,9 +749,6 @@ static void gtk_tree_view_get_arrow_xrange (GtkTreeView
|
||||
GtkRBTree *tree,
|
||||
gint *x1,
|
||||
gint *x2);
|
||||
static gint gtk_tree_view_new_column_width (GtkTreeView *tree_view,
|
||||
gint i,
|
||||
gint *x);
|
||||
static void gtk_tree_view_adjustment_changed (GtkAdjustment *adjustment,
|
||||
GtkTreeView *tree_view);
|
||||
static void gtk_tree_view_build_tree (GtkTreeView *tree_view,
|
||||
@ -3172,11 +3169,13 @@ gtk_tree_view_button_press (GtkWidget *widget,
|
||||
_gtk_tree_view_column_get_window (column))
|
||||
{
|
||||
gpointer drag_data;
|
||||
gint column_width, x;
|
||||
|
||||
if (event->type == GDK_2BUTTON_PRESS &&
|
||||
gtk_tree_view_column_get_sizing (column) != GTK_TREE_VIEW_COLUMN_AUTOSIZE)
|
||||
{
|
||||
_gtk_tree_view_column_set_use_resized_width (column, FALSE);
|
||||
gtk_tree_view_column_set_fixed_width (column, -1);
|
||||
gtk_tree_view_column_set_expand (column, FALSE);
|
||||
_gtk_tree_view_column_autosize (tree_view, column);
|
||||
return TRUE;
|
||||
}
|
||||
@ -3195,9 +3194,6 @@ gtk_tree_view_button_press (GtkWidget *widget,
|
||||
gtk_grab_add (widget);
|
||||
tree_view->priv->in_column_resize = TRUE;
|
||||
|
||||
_gtk_tree_view_column_set_resized_width (column, gtk_tree_view_column_get_width (column) -
|
||||
tree_view->priv->last_extra_space_per_column);
|
||||
|
||||
/* block attached dnd signal handler */
|
||||
drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
if (drag_data)
|
||||
@ -3206,8 +3202,16 @@ gtk_tree_view_button_press (GtkWidget *widget,
|
||||
0, 0, NULL, NULL,
|
||||
drag_data);
|
||||
|
||||
column_width = gtk_tree_view_column_get_width (column);
|
||||
gtk_tree_view_column_set_fixed_width (column, column_width);
|
||||
gtk_tree_view_column_set_expand (column, FALSE);
|
||||
|
||||
gdk_window_get_device_position (tree_view->priv->bin_window,
|
||||
gdk_event_get_device ((GdkEvent *) event),
|
||||
&x, NULL, NULL);
|
||||
|
||||
tree_view->priv->drag_pos = i;
|
||||
tree_view->priv->x_drag = gtk_tree_view_column_get_x_offset (column) + (rtl ? 0 : gtk_tree_view_column_get_width (column));
|
||||
tree_view->priv->x_drag = x + (rtl ? column_width : -column_width);
|
||||
|
||||
if (!gtk_widget_has_focus (widget))
|
||||
gtk_widget_grab_focus (widget);
|
||||
@ -3936,31 +3940,17 @@ gtk_tree_view_motion_resize_column (GtkWidget *widget,
|
||||
|
||||
column = gtk_tree_view_get_column (tree_view, tree_view->priv->drag_pos);
|
||||
|
||||
if (event->is_hint || event->window != gtk_widget_get_window (widget))
|
||||
gdk_window_get_device_position (gtk_widget_get_window (widget),
|
||||
gdk_window_get_device_position (tree_view->priv->bin_window,
|
||||
gdk_event_get_device ((GdkEvent *) event),
|
||||
&x, NULL, NULL);
|
||||
|
||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
new_width = MAX (tree_view->priv->x_drag - x, 0);
|
||||
else
|
||||
x = event->x;
|
||||
new_width = MAX (x - tree_view->priv->x_drag, 0);
|
||||
|
||||
if (tree_view->priv->hadjustment)
|
||||
x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
|
||||
|
||||
new_width = gtk_tree_view_new_column_width (tree_view,
|
||||
tree_view->priv->drag_pos, &x);
|
||||
if (x != tree_view->priv->x_drag &&
|
||||
(new_width != gtk_tree_view_column_get_fixed_width (column)))
|
||||
{
|
||||
_gtk_tree_view_column_set_use_resized_width (column, TRUE);
|
||||
|
||||
if (gtk_tree_view_column_get_expand (column))
|
||||
new_width -= tree_view->priv->last_extra_space_per_column;
|
||||
|
||||
_gtk_tree_view_column_set_resized_width (column, new_width);
|
||||
|
||||
|
||||
gtk_widget_queue_resize (widget);
|
||||
}
|
||||
if (new_width != gtk_tree_view_column_get_fixed_width (column))
|
||||
gtk_tree_view_column_set_fixed_width (column, new_width);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -5634,7 +5624,7 @@ gtk_tree_view_key_press (GtkWidget *widget,
|
||||
|| event->keyval == GDK_KEY_Right || event->keyval == GDK_KEY_KP_Right))
|
||||
{
|
||||
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (focus_column->data);
|
||||
gint max_width, min_width;
|
||||
gint column_width;
|
||||
|
||||
if (!gtk_tree_view_column_get_resizable (column))
|
||||
{
|
||||
@ -5642,70 +5632,21 @@ gtk_tree_view_key_press (GtkWidget *widget,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
column_width = gtk_tree_view_column_get_width (column);
|
||||
|
||||
if (event->keyval == (rtl ? GDK_KEY_Right : GDK_KEY_Left)
|
||||
|| event->keyval == (rtl ? GDK_KEY_KP_Right : GDK_KEY_KP_Left))
|
||||
{
|
||||
GtkRequisition button_req;
|
||||
gint old_width = _gtk_tree_view_column_get_resized_width (column);
|
||||
gint new_width;
|
||||
|
||||
button = gtk_tree_view_column_get_button (column);
|
||||
|
||||
gtk_widget_get_preferred_size (button, &button_req, NULL);
|
||||
|
||||
new_width = MAX (old_width, gtk_tree_view_column_get_width (column));
|
||||
new_width -= 2;
|
||||
if (new_width < 0)
|
||||
new_width = 0;
|
||||
|
||||
_gtk_tree_view_column_set_resized_width (column, new_width);
|
||||
|
||||
min_width = gtk_tree_view_column_get_min_width (column);
|
||||
if (min_width == -1)
|
||||
new_width = MAX (button_req.width, new_width);
|
||||
else
|
||||
{
|
||||
new_width = MAX (min_width, new_width);
|
||||
}
|
||||
|
||||
max_width = gtk_tree_view_column_get_max_width (column);
|
||||
if (max_width != -1)
|
||||
new_width = MIN (new_width, max_width);
|
||||
|
||||
_gtk_tree_view_column_set_use_resized_width (column, TRUE);
|
||||
|
||||
if (new_width != old_width)
|
||||
{
|
||||
_gtk_tree_view_column_set_resized_width (column, new_width);
|
||||
gtk_widget_queue_resize (widget);
|
||||
}
|
||||
else
|
||||
gtk_widget_error_bell (widget);
|
||||
column_width = MAX (column_width - 2, 0);
|
||||
}
|
||||
else if (event->keyval == (rtl ? GDK_KEY_Left : GDK_KEY_Right)
|
||||
|| event->keyval == (rtl ? GDK_KEY_KP_Left : GDK_KEY_KP_Right))
|
||||
{
|
||||
gint old_width = _gtk_tree_view_column_get_resized_width (column);
|
||||
gint new_width;
|
||||
|
||||
new_width = MAX (old_width, gtk_tree_view_column_get_width (column));
|
||||
new_width += 2;
|
||||
|
||||
max_width = gtk_tree_view_column_get_max_width (column);
|
||||
if (max_width != -1)
|
||||
new_width = MIN (new_width, max_width);
|
||||
|
||||
_gtk_tree_view_column_set_use_resized_width (column, TRUE);
|
||||
|
||||
if (new_width != old_width)
|
||||
{
|
||||
_gtk_tree_view_column_set_resized_width (column, new_width);
|
||||
gtk_widget_queue_resize (widget);
|
||||
}
|
||||
else
|
||||
gtk_widget_error_bell (widget);
|
||||
column_width = column_width + 2;
|
||||
}
|
||||
|
||||
gtk_tree_view_column_set_fixed_width (column, column_width);
|
||||
gtk_tree_view_column_set_expand (column, FALSE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -11059,50 +11000,6 @@ gtk_tree_view_start_interactive_search (GtkTreeView *tree_view)
|
||||
TRUE);
|
||||
}
|
||||
|
||||
/* this function returns the new width of the column being resized given
|
||||
* the column and x position of the cursor; the x cursor position is passed
|
||||
* in as a pointer and automagicly corrected if it's beyond min/max limits
|
||||
*/
|
||||
static gint
|
||||
gtk_tree_view_new_column_width (GtkTreeView *tree_view,
|
||||
gint i,
|
||||
gint *x)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkRequisition button_req;
|
||||
gint max_width, min_width;
|
||||
gint width;
|
||||
gboolean rtl;
|
||||
|
||||
/* first translate the x position from widget->window
|
||||
* to clist->clist_window
|
||||
*/
|
||||
rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
|
||||
column = g_list_nth (tree_view->priv->columns, i)->data;
|
||||
gtk_widget_get_allocation (gtk_tree_view_column_get_button (column), &allocation);
|
||||
width = rtl ? (allocation.x + allocation.width - *x) : (*x - allocation.x);
|
||||
|
||||
/* Clamp down the value */
|
||||
min_width = gtk_tree_view_column_get_min_width (column);
|
||||
if (min_width == -1)
|
||||
{
|
||||
gtk_widget_get_preferred_size (gtk_tree_view_column_get_button (column), &button_req, NULL);
|
||||
width = MAX (button_req.width, width);
|
||||
}
|
||||
else
|
||||
width = MAX (min_width, width);
|
||||
|
||||
max_width = gtk_tree_view_column_get_max_width (column);
|
||||
if (max_width != -1)
|
||||
width = MIN (width, max_width);
|
||||
|
||||
*x = rtl ? (allocation.x + allocation.width - width) : (allocation.x + width);
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
/* FIXME this adjust_allocation is a big cut-and-paste from
|
||||
* GtkCList, needs to be some "official" way to do this
|
||||
* factored out.
|
||||
|
@ -140,7 +140,6 @@ struct _GtkTreeViewColumnPrivate
|
||||
/* see gtk+/doc/tree-column-sizing.txt for more information on them */
|
||||
GtkTreeViewColumnSizing column_type;
|
||||
gint padding;
|
||||
gint resized_width;
|
||||
gint x_offset;
|
||||
gint width;
|
||||
gint fixed_width;
|
||||
@ -174,7 +173,6 @@ struct _GtkTreeViewColumnPrivate
|
||||
guint show_sort_indicator : 1;
|
||||
guint maybe_reordered : 1;
|
||||
guint reorderable : 1;
|
||||
guint use_resized_width : 1;
|
||||
guint expand : 1;
|
||||
};
|
||||
|
||||
@ -299,9 +297,9 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
|
||||
g_param_spec_int ("fixed-width",
|
||||
P_("Fixed Width"),
|
||||
P_("Current fixed width of the column"),
|
||||
1,
|
||||
-1,
|
||||
G_MAXINT,
|
||||
1, /* not useful */
|
||||
-1,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
@ -472,7 +470,6 @@ gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
|
||||
priv->padding = -1;
|
||||
priv->min_width = -1;
|
||||
priv->max_width = -1;
|
||||
priv->resized_width = 0;
|
||||
priv->column_type = GTK_TREE_VIEW_COLUMN_GROW_ONLY;
|
||||
priv->visible = TRUE;
|
||||
priv->resizable = FALSE;
|
||||
@ -487,8 +484,7 @@ gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
|
||||
priv->sort_column_id = -1;
|
||||
priv->reorderable = FALSE;
|
||||
priv->maybe_reordered = FALSE;
|
||||
priv->fixed_width = 1;
|
||||
priv->use_resized_width = FALSE;
|
||||
priv->fixed_width = -1;
|
||||
priv->title = g_strdup ("");
|
||||
}
|
||||
|
||||
@ -2104,11 +2100,7 @@ _gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column)
|
||||
|
||||
priv = tree_column->priv;
|
||||
|
||||
if (priv->use_resized_width)
|
||||
{
|
||||
real_requested_width = priv->resized_width;
|
||||
}
|
||||
else if (priv->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
|
||||
if (priv->fixed_width != -1)
|
||||
{
|
||||
real_requested_width = priv->fixed_width;
|
||||
}
|
||||
@ -2206,16 +2198,15 @@ gtk_tree_view_column_set_fixed_width (GtkTreeViewColumn *tree_column,
|
||||
GtkTreeViewColumnPrivate *priv;
|
||||
|
||||
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
|
||||
g_return_if_fail (fixed_width > 0);
|
||||
g_return_if_fail (fixed_width >= -1);
|
||||
|
||||
priv = tree_column->priv;
|
||||
|
||||
priv->fixed_width = fixed_width;
|
||||
priv->use_resized_width = FALSE;
|
||||
|
||||
if (priv->tree_view &&
|
||||
gtk_widget_get_realized (priv->tree_view) &&
|
||||
priv->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
|
||||
if (priv->visible &&
|
||||
priv->tree_view != NULL &&
|
||||
gtk_widget_get_realized (priv->tree_view))
|
||||
{
|
||||
gtk_widget_queue_resize (priv->tree_view);
|
||||
}
|
||||
@ -2463,13 +2454,6 @@ gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column,
|
||||
priv->tree_view != NULL &&
|
||||
gtk_widget_get_realized (priv->tree_view))
|
||||
{
|
||||
/* We want to continue using the original width of the
|
||||
* column that includes additional space added by the user
|
||||
* resizing the columns and possibly extra (expanded) space, which
|
||||
* are not included in the resized width.
|
||||
*/
|
||||
priv->use_resized_width = FALSE;
|
||||
|
||||
gtk_widget_queue_resize (priv->tree_view);
|
||||
}
|
||||
|
||||
@ -3209,33 +3193,6 @@ _gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column)
|
||||
return requested_width + column->priv->padding;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_gtk_tree_view_column_set_resized_width (GtkTreeViewColumn *column,
|
||||
gint width)
|
||||
{
|
||||
column->priv->resized_width = width;
|
||||
}
|
||||
|
||||
gint
|
||||
_gtk_tree_view_column_get_resized_width (GtkTreeViewColumn *column)
|
||||
{
|
||||
return column->priv->resized_width;
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_tree_view_column_set_use_resized_width (GtkTreeViewColumn *column,
|
||||
gboolean use_resized_width)
|
||||
{
|
||||
column->priv->use_resized_width = use_resized_width;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gtk_tree_view_column_get_use_resized_width (GtkTreeViewColumn *column)
|
||||
{
|
||||
return column->priv->use_resized_width;
|
||||
}
|
||||
|
||||
gint
|
||||
_gtk_tree_view_column_get_drag_x (GtkTreeViewColumn *column)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user