diff options
author | Jonathan Blandford <jrb@redhat.com> | 2001-05-22 19:18:47 +0000 |
---|---|---|
committer | Jonathan Blandford <jrb@src.gnome.org> | 2001-05-22 19:18:47 +0000 |
commit | 66152ab6d01e53530dbd248f0b4bd6a0683e4b97 (patch) | |
tree | 61388fadcd0d804f359f39b5d7d753a0ed10b08d /gtk | |
parent | e8d54ce0c516f65b4d1d244517b3335f087eedba (diff) | |
download | gtk+-66152ab6d01e53530dbd248f0b4bd6a0683e4b97.tar.gz |
Evil function to deal with very large (TM) amounts of text. May be moved
Tue May 22 15:13:52 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkcellrenderertext.c
(gtk_cell_renderer_text_set_fixed_size): Evil function to deal
with very large (TM) amounts of text. May be moved to
GtkCellRenderer in the future, though I'm not sure it wants to be
this accessible.
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_update_button):
More sanity brought to this class. I like it.
* tests/testtreecolumns.c (ViewColumnModel): Amazingly scary test
case. Kids, don't try this at home.
* gtk/gtktreemodel.c (gtk_tree_model_get_iter_root): new
convenience function.
* gtk/gtkwindow.c (gtk_window_set_geometry_hints): Fix typo in docs.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkcellrenderertext.c | 38 | ||||
-rw-r--r-- | gtk/gtkcellrenderertext.h | 15 | ||||
-rw-r--r-- | gtk/gtkliststore.c | 10 | ||||
-rw-r--r-- | gtk/gtktreemodel.c | 30 | ||||
-rw-r--r-- | gtk/gtktreemodel.h | 2 | ||||
-rw-r--r-- | gtk/gtktreeviewcolumn.c | 175 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 2 |
7 files changed, 144 insertions, 128 deletions
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c index 706fffd2c3..937835f615 100644 --- a/gtk/gtkcellrenderertext.c +++ b/gtk/gtkcellrenderertext.c @@ -1087,6 +1087,16 @@ gtk_cell_renderer_text_get_size (GtkCellRenderer *cell, PangoRectangle rect; PangoLayout *layout; + if (celltext->fixed_size) + { + if (width) + *width = celltext->width; + if (height) + *height = celltext->height; + + return; + } + layout = get_layout (celltext, widget, FALSE, 0); pango_layout_get_pixel_extents (layout, NULL, &rect); @@ -1175,3 +1185,31 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell, g_object_unref (G_OBJECT (layout)); } + +/** + * gtk_cell_renderer_text_set_fixed_size: + * @renderer: A #GtkCellRendererText + * @fixed_size: TRUE if the renderer should be a fixed height. + * @width: The width of the cell + * @height: The height it of the cell, or -1 + * + * Sets the height of a renderer to explicitly be a certain size. This + * function is unflexible, and should really only be used if calculating the + * size of a cell is too slow. + **/ +void +gtk_cell_renderer_text_set_fixed_size (GtkCellRendererText *renderer, + gboolean fixed_size, + gint width, + gint height) +{ + g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer)); + + if (renderer->fixed_size == (fixed_size)?TRUE:FALSE) + return; + + renderer->fixed_size = (fixed_size)?TRUE:FALSE; + renderer->height = height; + renderer->width = width; + +} diff --git a/gtk/gtkcellrenderertext.h b/gtk/gtkcellrenderertext.h index 3ec1852288..4ac2bd232a 100644 --- a/gtk/gtkcellrenderertext.h +++ b/gtk/gtkcellrenderertext.h @@ -53,7 +53,10 @@ struct _GtkCellRendererText PangoUnderline underline_style; gint rise; - + gint width; + gint height; + + guint fixed_size : 1; guint strikethrough : 1; /* editable feature doesn't work */ @@ -86,8 +89,14 @@ struct _GtkCellRendererTextClass GtkCellRendererClass parent_class; }; -GtkType gtk_cell_renderer_text_get_type (void); -GtkCellRenderer *gtk_cell_renderer_text_new (void); +GtkType gtk_cell_renderer_text_get_type (void); +GtkCellRenderer *gtk_cell_renderer_text_new (void); + +void gtk_cell_renderer_text_set_fixed_size (GtkCellRendererText *renderer, + gboolean fixed_size, + gint width, + gint height); + #ifdef __cplusplus } diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 5737a306eb..92490eccf4 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -480,13 +480,9 @@ gtk_list_store_iter_next (GtkTreeModel *tree_model, g_return_val_if_fail (GTK_IS_LIST_STORE (tree_model), FALSE); g_return_val_if_fail (GTK_LIST_STORE (tree_model)->stamp == iter->stamp, FALSE); - if (G_SLIST (iter->user_data)->next) - { - iter->user_data = G_SLIST (iter->user_data)->next; - return TRUE; - } - else - return FALSE; + iter->user_data = G_SLIST (iter->user_data)->next; + + return (iter->user_data != NULL); } static gboolean diff --git a/gtk/gtktreemodel.c b/gtk/gtktreemodel.c index db062631ac..f4a08ec416 100644 --- a/gtk/gtktreemodel.c +++ b/gtk/gtktreemodel.c @@ -653,10 +653,9 @@ gtk_tree_model_get_iter (GtkTreeModel *tree_model, gint *indices; gint depth, i; - g_return_val_if_fail (tree_model != NULL, FALSE); + g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (path != NULL, FALSE); - g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); if (GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter != NULL) return (* GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter) (tree_model, iter, path); @@ -679,6 +678,33 @@ gtk_tree_model_get_iter (GtkTreeModel *tree_model, return TRUE; } + +/** + * gtk_tree_model_get_iter_root: + * @tree_model: A #GtkTreeModel. + * @iter: The uninitialized #GtkTreeIter. + * + * Gets the root iter, if it exists. + * + * Return value: TRUE, if @iter was set. + **/ +gboolean +gtk_tree_model_get_iter_root (GtkTreeModel *tree_model, + GtkTreeIter *iter) +{ + GtkTreePath *path; + gboolean retval; + + g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); + + path = gtk_tree_path_new_root (); + retval = gtk_tree_model_get_iter (tree_model, iter, path); + gtk_tree_path_free (path); + + return retval; +} + /** * gtk_tree_model_get_first: * @tree_model: a #GtkTreeModel diff --git a/gtk/gtktreemodel.h b/gtk/gtktreemodel.h index fc2b0bfd7a..78670243e7 100644 --- a/gtk/gtktreemodel.h +++ b/gtk/gtktreemodel.h @@ -176,6 +176,8 @@ GType gtk_tree_model_get_column_type (GtkTreeModel *tree_model, gboolean gtk_tree_model_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path); +gboolean gtk_tree_model_get_iter_root (GtkTreeModel *tree_model, + GtkTreeIter *iter); gboolean gtk_tree_model_get_first (GtkTreeModel *tree_model, GtkTreeIter *iter); GtkTreePath * gtk_tree_model_get_path (GtkTreeModel *tree_model, diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index 28d7d6452b..cbfac183b5 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -75,20 +75,13 @@ static void gtk_tree_view_column_create_button (GtkTreeViewColum static void gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column); /* Button signal handlers */ -static gint gtk_tree_view_column_button_passive_func (GtkWidget *widget, +static gint gtk_tree_view_column_button_event (GtkWidget *widget, GdkEvent *event, gpointer data); static void gtk_tree_view_column_button_realize (GtkWidget *widget, gpointer data); -static void gtk_tree_view_column_button_pressed (GtkWidget *widget, - gpointer data); -static void gtk_tree_view_column_button_released (GtkWidget *widget, - gpointer data); static void gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data); -static gint gtk_tree_view_column_button_motion_event (GtkWidget *widget, - GdkEventMotion *event, - gpointer data); /* Property handlers */ static void gtk_tree_view_model_property_changed (GtkTreeView *view, @@ -102,7 +95,6 @@ static void gtk_tree_view_model_sort_column_changed (GtkTreeSortable static void gtk_tree_view_column_sort (GtkTreeViewColumn *tree_column, gpointer data); static void gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn *tree_column); -static void gtk_tree_view_column_set_clickable_real (GtkTreeViewColumn *tree_column); static void gtk_tree_view_column_set_attributesv (GtkTreeViewColumn *tree_column, va_list args); @@ -507,18 +499,14 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column) gtk_signal_connect (GTK_OBJECT (tree_column->button), "realize", (GtkSignalFunc) gtk_tree_view_column_button_realize, NULL); + + gtk_signal_connect (GTK_OBJECT (tree_column->button), "event", + (GtkSignalFunc) gtk_tree_view_column_button_event, + (gpointer) tree_column); + gtk_signal_connect (GTK_OBJECT (tree_column->button), "clicked", (GtkSignalFunc) gtk_tree_view_column_button_clicked, (gpointer) tree_column); - gtk_signal_connect (GTK_OBJECT (tree_column->button), "pressed", - (GtkSignalFunc) gtk_tree_view_column_button_pressed, - (gpointer) tree_column); - gtk_signal_connect (GTK_OBJECT (tree_column->button), "motion_notify_event", - (GtkSignalFunc) gtk_tree_view_column_button_motion_event, - (gpointer) tree_column); - gtk_signal_connect (GTK_OBJECT (tree_column->button), "released", - (GtkSignalFunc) gtk_tree_view_column_button_released, - (gpointer) tree_column); tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0); @@ -546,8 +534,6 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column) gtk_widget_show (hbox); gtk_widget_show (tree_column->alignment); gtk_tree_view_column_update_button (tree_column); - - gtk_tree_view_column_set_clickable_real (tree_column); } static void @@ -558,7 +544,6 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) GtkWidget *arrow; GtkWidget *current_child; - /* Create a button if necessary */ if (tree_column->visible && tree_column->button == NULL && @@ -680,6 +665,11 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) gdk_window_hide (tree_column->window); } } + + if (tree_column->reorderable || tree_column->clickable) + GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS); + else + GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS); tree_column->dirty = TRUE; gtk_widget_queue_resize (tree_column->tree_view); @@ -689,24 +679,56 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column) */ static gint -gtk_tree_view_column_button_passive_func (GtkWidget *widget, - GdkEvent *event, - gpointer data) +gtk_tree_view_column_button_event (GtkWidget *widget, + GdkEvent *event, + gpointer data) { + GtkTreeViewColumn *column = (GtkTreeViewColumn *) data; + g_return_val_if_fail (event != NULL, FALSE); - switch (event->type) + if (event->type == GDK_BUTTON_PRESS && + column->reorderable) + { + column->maybe_reordered = TRUE; + gdk_window_get_pointer (widget->window, + &column->drag_x, + &column->drag_y, + NULL); + gtk_widget_grab_focus (widget); + } + + if (event->type == GDK_BUTTON_RELEASE && + column->maybe_reordered) + column->maybe_reordered = FALSE; + + if (event->type == GDK_MOTION_NOTIFY && + (column->maybe_reordered) && + (gtk_drag_check_threshold (widget, + column->drag_x, + column->drag_y, + (gint) ((GdkEventMotion *)event)->x, + (gint) ((GdkEventMotion *)event)->y))) { - case GDK_MOTION_NOTIFY: - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: + column->maybe_reordered = FALSE; + _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (column->tree_view), column); return TRUE; - default: - break; + } + if (column->clickable == FALSE) + { + switch (event->type) + { + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + case GDK_MOTION_NOTIFY: + case GDK_BUTTON_RELEASE: + case GDK_ENTER_NOTIFY: + case GDK_LEAVE_NOTIFY: + return TRUE; + default: + return FALSE; + } } return FALSE; } @@ -718,56 +740,11 @@ gtk_tree_view_column_button_realize (GtkWidget *widget, gpointer data) } static void -gtk_tree_view_column_button_pressed (GtkWidget *widget, gpointer data) -{ - GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) data; - - if (! tree_column->reorderable) - return; - - tree_column->maybe_reordered = TRUE; - gdk_window_get_pointer (widget->window, - &tree_column->drag_x, - &tree_column->drag_y, - NULL); -} - - -static void -gtk_tree_view_column_button_released (GtkWidget *widget, gpointer data) -{ - GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) data; - - tree_column->maybe_reordered = FALSE; -} - -static void gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data) { g_signal_emit_by_name (G_OBJECT (data), "clicked"); } -static gint -gtk_tree_view_column_button_motion_event (GtkWidget *widget, - GdkEventMotion *event, - gpointer data) -{ - GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) data; - - if ((tree_column->maybe_reordered) && - (gtk_drag_check_threshold (widget, - tree_column->drag_x, - tree_column->drag_y, - (gint) event->x, - (gint) event->y))) - { - tree_column->maybe_reordered = FALSE; - _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (tree_column->tree_view), tree_column); - } - - return TRUE; -} - static void gtk_tree_view_model_property_changed (GtkTreeView *view, guint n_pspecs, @@ -1636,7 +1613,6 @@ gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column, tree_column->title = NULL; gtk_tree_view_column_update_button (tree_column); - g_object_notify (G_OBJECT (tree_column), "title"); } @@ -1657,40 +1633,6 @@ gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column) return tree_column->title; } - -static void -gtk_tree_view_column_set_clickable_real (GtkTreeViewColumn *tree_column) -{ - if (!tree_column->button) - return; - - if (tree_column->clickable) - { - if (tree_column->clickable_signal) - { - g_signal_handler_disconnect (G_OBJECT (tree_column->button), tree_column->clickable_signal); - tree_column->clickable_signal = 0; - } - - GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS); - if (GTK_WIDGET_VISIBLE (tree_column->tree_view)) - gtk_widget_queue_draw (tree_column->button); - } - else - { - tree_column->clickable_signal = - gtk_signal_connect (GTK_OBJECT (tree_column->button), - "event", - (GtkSignalFunc) gtk_tree_view_column_button_passive_func, - NULL); - - GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS); - if (GTK_WIDGET_VISIBLE (tree_column->tree_view)) - gtk_widget_queue_draw (tree_column->button); - } - -} - /** * gtk_tree_view_column_set_clickable: * @tree_column: A #GtkTreeViewColumn. @@ -1709,7 +1651,7 @@ gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column, return; tree_column->clickable = (clickable?TRUE:FALSE); - gtk_tree_view_column_set_clickable_real (tree_column); + gtk_tree_view_column_update_button (tree_column); g_object_notify (G_OBJECT (tree_column), "clickable"); } @@ -1813,6 +1755,9 @@ gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column, { g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); + /* if (reorderable) + gtk_tree_view_column_set_clickable (tree_column, TRUE);*/ + if (tree_column->reorderable == (reorderable?TRUE:FALSE)) return; diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 6ae3b859ce..99c7e2f091 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1451,7 +1451,7 @@ gtk_window_get_geometry_info (GtkWindow *window, /** * gtk_window_set_geometry_hints: - * @window: a #GdkWindow + * @window: a #GtkWindow * @geometry_widget: widget the geometry hints will be applied to * @geometry: struct containing geometry information * @geom_mask: mask indicating which struct fields should be paid attention to |