gtktreeview.c 499 KB
Newer Older
1 2 3
/* gtktreeview.c
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
 *
4
 * This library is free software; you can redistribute it and/or
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


21
#include "config.h"
22

Benjamin Otte's avatar
Benjamin Otte committed
23
#include <math.h>
Manish Singh's avatar
Manish Singh committed
24 25
#include <string.h>

26 27
#include "gtktreeview.h"
#include "gtkrbtree.h"
28
#include "gtktreednd.h"
29 30
#include "gtktreeprivate.h"
#include "gtkcellrenderer.h"
31
#include "gtkmainprivate.h"
32
#include "gtkmarshalers.h"
Johan Dahlin's avatar
Johan Dahlin committed
33
#include "gtkbuildable.h"
34 35 36
#include "gtkbutton.h"
#include "gtkalignment.h"
#include "gtklabel.h"
Havoc Pennington's avatar
Havoc Pennington committed
37
#include "gtkhbox.h"
Jonathan Blandford's avatar
Jonathan Blandford committed
38
#include "gtkvbox.h"
Havoc Pennington's avatar
Havoc Pennington committed
39
#include "gtkarrow.h"
40
#include "gtkintl.h"
41
#include "gtkbindings.h"
42 43
#include "gtkcontainer.h"
#include "gtkentry.h"
44
#include "gtkframe.h"
Jonathan Blandford's avatar
Jonathan Blandford committed
45
#include "gtktreemodelsort.h"
46
#include "gtktooltip.h"
47
#include "gtkscrollable.h"
48
#include "gtkcelllayout.h"
49
#include "gtkprivate.h"
Emmanuele Bassi's avatar
Emmanuele Bassi committed
50
#include "gtkwidgetprivate.h"
51
#include "gtkentryprivate.h"
52
#include "gtkstylecontextprivate.h"
53
#include "gtktypebuiltins.h"
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

/**
 * SECTION:gtktreeview
 * @Short_description: A widget for displaying both trees and lists
 * @Title: GtkTreeView
 * @See_also: #GtkTreeViewColumn, #GtkTreeSelection, #GtkTreeDnd, #GtkTreeMode,
 *   #GtkTreeSortable, #GtkTreeModelSort, #GtkListStore, #GtkTreeStore,
 *   #GtkCellRenderer, #GtkCellEditable, #GtkCellRendererPixbuf,
 *   #GtkCellRendererText, #GtkCellRendererToggle
 *
 * Widget that displays any object that implements the #GtkTreeModel interface.
 *
 * Please refer to the <link linkend="TreeWidget">tree widget conceptual
 * overview</link> for an overview of all the objects and data types related
 * to the tree widget and how they work together.
 *
 * Several different coordinate systems are exposed in the GtkTreeView API.
 * These are:
 *
 * <inlinegraphic fileref="tree-view-coordinates.png" format="PNG"></inlinegraphic>
 * <variablelist><title>Coordinate systems in GtkTreeView API</title>
 * <varlistentry><term>Widget coordinates</term>
 * <listitem>
 * <para>
 * Coordinates relative to the widget (usually <literal>widget->window</literal>).
 * </para>
 * </listitem>
 * </varlistentry>
 * <varlistentry><term>Bin window coordinates</term>
 * <listitem>
 * <para>
 * Coordinates relative to the window that GtkTreeView renders to.
 * </para>
 * </listitem>
 * </varlistentry>
 * <varlistentry><term>Tree coordinates</term>
 * <listitem>
 * <para>
 * Coordinates relative to the entire scrollable area of GtkTreeView. These
 * coordinates start at (0, 0) for row 0 of the tree.
 * </para>
 * </listitem>
 * </varlistentry>
 * </variablelist>
 *
 * Several functions are available for converting between the different
 * coordinate systems.  The most common translations are between widget and bin
 * window coordinates and between bin window and tree coordinates. For the
 * former you can use gtk_tree_view_convert_widget_to_bin_window_coords()
 * (and vice versa), for the latter gtk_tree_view_convert_bin_window_to_tree_coords()
 * (and vice versa).
Matthias Clasen's avatar
Matthias Clasen committed
106
 *
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
 * <refsect2 id="GtkTreeView-BUILDER-UI">
 * <title>GtkTreeView as GtkBuildable</title>
 * The GtkTreeView implementation of the GtkBuildable interface accepts
 * #GtkTreeViewColumn objects as &lt;child&gt; elements and exposes the
 * internal #GtkTreeSelection in UI definitions.
 * <example>
 * <title>A UI definition fragment with GtkTreeView</title>
 * <programlisting><![CDATA[
 * <object class="GtkTreeView" id="treeview">
 *   <property name="model">liststore1</property>
 *   <child>
 *     <object class="GtkTreeViewColumn" id="test-column">
 *       <property name="title">Test</property>
 *       <child>
 *         <object class="GtkCellRendererText" id="test-renderer"/>
 *         <attributes>
 *           <attribute name="text">1</attribute>
 *         </attributes>
 *       </child>
 *     </object>
 *   </child>
 *   <child internal-child="selection">
 *     <object class="GtkTreeSelection" id="selection">
 *       <signal name="changed" handler="on_treeview_selection_changed"/>
 *     </object>
 *   </child>
 * </object>
 * ]]></programlisting>
 * </example>
 * </refsect2>
 */

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
enum
{
  DRAG_COLUMN_WINDOW_STATE_UNSET = 0,
  DRAG_COLUMN_WINDOW_STATE_ORIGINAL = 1,
  DRAG_COLUMN_WINDOW_STATE_ARROW = 2,
  DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT = 3,
  DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT = 4
};

enum
{
  RUBBER_BAND_OFF = 0,
  RUBBER_BAND_MAYBE_START = 1,
  RUBBER_BAND_ACTIVE = 2
};

 /* This lovely little value is used to determine how far away from the title bar
  * you can move the mouse and still have a column drag work.
  */
158
#define TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER(tree_view) (10*gtk_tree_view_get_effective_header_height(tree_view))
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

#ifdef __GNUC__

#define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
     if (!(expr))                                                       \
       {                                                                \
         g_log (G_LOG_DOMAIN,                                           \
                G_LOG_LEVEL_CRITICAL,                                   \
		"%s (%s): assertion `%s' failed.\n"                     \
	        "There is a disparity between the internal view of the GtkTreeView,\n"    \
		"and the GtkTreeModel.  This generally means that the model has changed\n"\
		"without letting the view know.  Any display from now on is likely to\n"  \
		"be incorrect.\n",                                                        \
                G_STRLOC,                                               \
                G_STRFUNC,                                              \
                #expr);                                                 \
         return ret;                                                    \
       };                               }G_STMT_END

#define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{          \
     if (!(expr))                                                       \
       {                                                                \
         g_log (G_LOG_DOMAIN,                                           \
                G_LOG_LEVEL_CRITICAL,                                   \
		"%s (%s): assertion `%s' failed.\n"                     \
	        "There is a disparity between the internal view of the GtkTreeView,\n"    \
		"and the GtkTreeModel.  This generally means that the model has changed\n"\
		"without letting the view know.  Any display from now on is likely to\n"  \
		"be incorrect.\n",                                                        \
                G_STRLOC,                                               \
                G_STRFUNC,                                              \
                #expr);                                                 \
         return;                                                        \
       };                               }G_STMT_END

#else

#define TREE_VIEW_INTERNAL_ASSERT(expr, ret)     G_STMT_START{          \
     if (!(expr))                                                       \
       {                                                                \
         g_log (G_LOG_DOMAIN,                                           \
                G_LOG_LEVEL_CRITICAL,                                   \
		"file %s: line %d: assertion `%s' failed.\n"       \
	        "There is a disparity between the internal view of the GtkTreeView,\n"    \
		"and the GtkTreeModel.  This generally means that the model has changed\n"\
		"without letting the view know.  Any display from now on is likely to\n"  \
		"be incorrect.\n",                                                        \
                __FILE__,                                               \
                __LINE__,                                               \
                #expr);                                                 \
         return ret;                                                    \
       };                               }G_STMT_END

#define TREE_VIEW_INTERNAL_ASSERT_VOID(expr)     G_STMT_START{          \
     if (!(expr))                                                       \
       {                                                                \
         g_log (G_LOG_DOMAIN,                                           \
                G_LOG_LEVEL_CRITICAL,                                   \
		"file %s: line %d: assertion '%s' failed.\n"            \
	        "There is a disparity between the internal view of the GtkTreeView,\n"    \
		"and the GtkTreeModel.  This generally means that the model has changed\n"\
		"without letting the view know.  Any display from now on is likely to\n"  \
		"be incorrect.\n",                                                        \
                __FILE__,                                               \
                __LINE__,                                               \
                #expr);                                                 \
         return;                                                        \
       };                               }G_STMT_END
#endif

Jonathan Blandford's avatar
Jonathan Blandford committed
229
#define GTK_TREE_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
230
#define GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC (GTK_TREE_VIEW_PRIORITY_VALIDATE + 2)
231
#define GTK_TREE_VIEW_TIME_MS_PER_IDLE 30
232
#define SCROLL_EDGE_SIZE 15
233
#define EXPANDER_EXTRA_PADDING 4
Jonathan Blandford's avatar
Jonathan Blandford committed
234
#define GTK_TREE_VIEW_SEARCH_DIALOG_TIMEOUT 5000
235 236
#define AUTO_EXPAND_TIMEOUT 500

237 238 239
/* Translate from bin_window coordinates to rbtree (tree coordinates) and
 * vice versa.
 */
240 241
#define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
#define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
242

243 244 245 246 247 248 249 250
typedef struct _GtkTreeViewColumnReorder GtkTreeViewColumnReorder;
struct _GtkTreeViewColumnReorder
{
  gint left_align;
  gint right_align;
  GtkTreeViewColumn *left_column;
  GtkTreeViewColumn *right_column;
};
251

252
typedef struct _GtkTreeViewChild GtkTreeViewChild;
253 254 255 256 257
struct _GtkTreeViewChild
{
  GtkWidget *widget;
  gint x;
  gint y;
258 259
  gint width;
  gint height;
260 261
};

Jonathan Blandford's avatar
Jonathan Blandford committed
262

263 264 265 266
typedef struct _TreeViewDragInfo TreeViewDragInfo;
struct _TreeViewDragInfo
{
  GdkModifierType start_button_mask;
267
  GtkTargetList *_unused_source_target_list;
268 269
  GdkDragAction source_actions;

270
  GtkTargetList *_unused_dest_target_list;
271 272 273 274 275 276

  guint source_set : 1;
  guint dest_set : 1;
};


277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
struct _GtkTreeViewPrivate
{
  GtkTreeModel *model;

  /* tree information */
  GtkRBTree *tree;

  /* Container info */
  GList *children;
  gint width;
  gint height;

  /* Adjustments */
  GtkAdjustment *hadjustment;
  GtkAdjustment *vadjustment;
  gint           min_display_width;
  gint           min_display_height;

  /* Sub windows */
  GdkWindow *bin_window;
  GdkWindow *header_window;

  /* Scroll position state keeping */
  GtkTreeRowReference *top_row;
  gint top_row_dy;
  /* dy == y pos of top_row + top_row_dy */
  /* we cache it for simplicity of the code */
  gint dy;

  guint presize_handler_timer;
  guint validate_rows_timer;
  guint scroll_sync_timer;

  /* Indentation and expander layout */
  gint expander_size;
  GtkTreeViewColumn *expander_column;

  gint level_indentation;

  /* Key navigation (focus), selection */
  gint cursor_offset;

  GtkTreeRowReference *anchor;
  GtkTreeRowReference *cursor;

  GtkTreeViewColumn *focus_column;

  /* Current pressed node, previously pressed, prelight */
  GtkRBNode *button_pressed_node;
  GtkRBTree *button_pressed_tree;

  gint pressed_button;
  gint press_start_x;
  gint press_start_y;

  gint event_last_x;
  gint event_last_y;

  guint last_button_time;
  gint last_button_x;
  gint last_button_y;

  GtkRBNode *prelight_node;
  GtkRBTree *prelight_tree;

  /* Cell Editing */
  GtkTreeViewColumn *edited_column;

  /* The node that's currently being collapsed or expanded */
  GtkRBNode *expanded_collapsed_node;
  GtkRBTree *expanded_collapsed_tree;
  guint expand_collapse_timeout;

  /* Auto expand/collapse timeout in hover mode */
  guint auto_expand_timeout;

  /* Selection information */
  GtkTreeSelection *selection;

  /* Header information */
  gint n_columns;
  GList *columns;
  gint header_height;

  GtkTreeViewColumnDropFunc column_drop_func;
  gpointer column_drop_func_data;
  GDestroyNotify column_drop_func_data_destroy;
  GList *column_drag_info;
  GtkTreeViewColumnReorder *cur_reorder;

  gint prev_width_before_expander;

  /* Interactive Header reordering */
  GdkWindow *drag_window;
  GdkWindow *drag_highlight_window;
  GtkTreeViewColumn *drag_column;
  gint drag_column_x;

  /* Interactive Header Resizing */
  gint drag_pos;
  gint x_drag;

  /* Non-interactive Header Resizing, expand flag support */
  gint prev_width;

  gint last_extra_space;
  gint last_extra_space_per_column;
  gint last_number_of_expand_columns;

  /* ATK Hack */
  GtkTreeDestroyCountFunc destroy_count_func;
  gpointer destroy_count_data;
  GDestroyNotify destroy_count_destroy;

  /* Scroll timeout (e.g. during dnd, rubber banding) */
  guint scroll_timeout;

  /* Row drag-and-drop */
  GtkTreeRowReference *drag_dest_row;
  GtkTreeViewDropPosition drag_dest_pos;
  guint open_dest_timeout;

  /* Rubber banding */
  gint rubber_band_status;
  gint rubber_band_x;
  gint rubber_band_y;
  gint rubber_band_shift;
  gint rubber_band_ctrl;

  GtkRBNode *rubber_band_start_node;
  GtkRBTree *rubber_band_start_tree;

  GtkRBNode *rubber_band_end_node;
  GtkRBTree *rubber_band_end_tree;

  /* fixed height */
  gint fixed_height;

  /* Scroll-to functionality when unrealized */
  GtkTreeRowReference *scroll_to_path;
  GtkTreeViewColumn *scroll_to_column;
  gfloat scroll_to_row_align;
  gfloat scroll_to_col_align;

  /* Interactive search */
  gint selected_iter;
  gint search_column;
  GtkTreeViewSearchPositionFunc search_position_func;
  GtkTreeViewSearchEqualFunc search_equal_func;
  gpointer search_user_data;
  GDestroyNotify search_destroy;
  gpointer search_position_user_data;
  GDestroyNotify search_position_destroy;
  GtkWidget *search_window;
  GtkWidget *search_entry;
  gulong search_entry_changed_id;
  guint typeselect_flush_timeout;

  /* Grid and tree lines */
  GtkTreeViewGridLines grid_lines;
  double grid_line_dashes[2];
  int grid_line_width;

  gboolean tree_lines_enabled;
  double tree_line_dashes[2];
  int tree_line_width;

  /* Row separators */
  GtkTreeViewRowSeparatorFunc row_separator_func;
  gpointer row_separator_data;
  GDestroyNotify row_separator_destroy;

  /* Tooltip support */
  gint tooltip_column;

  /* Here comes the bitfield */
  guint scroll_to_use_align : 1;

  guint fixed_height_mode : 1;
  guint fixed_height_check : 1;

  guint reorderable : 1;
  guint header_has_focus : 1;
  guint drag_column_window_state : 3;
  /* hint to display rows in alternating colors */
  guint has_rules : 1;
  guint mark_rows_col_dirty : 1;

  /* for DnD */
  guint empty_view_drop : 1;

  guint ctrl_pressed : 1;
  guint shift_pressed : 1;

  guint init_hadjust_value : 1;

  guint in_top_row_to_dy : 1;

  /* interactive search */
  guint enable_search : 1;
  guint disable_popdown : 1;
  guint search_custom_entry_set : 1;
  
  guint hover_selection : 1;
  guint hover_expand : 1;
  guint imcontext_changed : 1;

  guint rubber_banding_enable : 1;

  guint in_grab : 1;

  guint post_validation_flag : 1;

  /* Whether our key press handler is to avoid sending an unhandled binding to the search entry */
  guint search_entry_avoid_unhandled_binding : 1;

  /* GtkScrollablePolicy needs to be checked when
   * driving the scrollable adjustment values */
  guint hscroll_policy : 1;
  guint vscroll_policy : 1;
497 498 499 500 501 502 503 504 505 506

  /* GtkTreeView flags */
  guint is_list : 1;
  guint show_expanders : 1;
  guint in_column_resize : 1;
  guint arrow_prelit : 1;
  guint headers_visible : 1;
  guint draw_keyfocus : 1;
  guint model_setup : 1;
  guint in_column_drag : 1;
507 508 509
};


510
/* Signals */
511 512 513
enum
{
  ROW_ACTIVATED,
514 515 516 517
  TEST_EXPAND_ROW,
  TEST_COLLAPSE_ROW,
  ROW_EXPANDED,
  ROW_COLLAPSED,
518
  COLUMNS_CHANGED,
519
  CURSOR_CHANGED,
520
  MOVE_CURSOR,
521
  SELECT_ALL,
522
  UNSELECT_ALL,
523
  SELECT_CURSOR_ROW,
524 525 526
  TOGGLE_CURSOR_ROW,
  EXPAND_COLLAPSE_CURSOR_ROW,
  SELECT_CURSOR_PARENT,
527
  START_INTERACTIVE_SEARCH,
528 529 530
  LAST_SIGNAL
};

531
/* Properties */
532 533 534 535 536
enum {
  PROP_0,
  PROP_MODEL,
  PROP_HADJUSTMENT,
  PROP_VADJUSTMENT,
537 538
  PROP_HSCROLL_POLICY,
  PROP_VSCROLL_POLICY,
539 540 541
  PROP_HEADERS_VISIBLE,
  PROP_HEADERS_CLICKABLE,
  PROP_EXPANDER_COLUMN,
542
  PROP_REORDERABLE,
543 544
  PROP_RULES_HINT,
  PROP_ENABLE_SEARCH,
545
  PROP_SEARCH_COLUMN,
546
  PROP_FIXED_HEIGHT_MODE,
547
  PROP_HOVER_SELECTION,
Kristian Rietveld's avatar
Kristian Rietveld committed
548 549
  PROP_HOVER_EXPAND,
  PROP_SHOW_EXPANDERS,
550
  PROP_LEVEL_INDENTATION,
551 552
  PROP_RUBBER_BANDING,
  PROP_ENABLE_GRID_LINES,
553
  PROP_ENABLE_TREE_LINES,
554
  PROP_TOOLTIP_COLUMN
555
};
556

557 558
/* object signals */
static void     gtk_tree_view_finalize             (GObject          *object);
559 560 561
static void     gtk_tree_view_set_property         (GObject         *object,
						    guint            prop_id,
						    const GValue    *value,
Jonathan Blandford's avatar
Jonathan Blandford committed
562
						    GParamSpec      *pspec);
563 564 565
static void     gtk_tree_view_get_property         (GObject         *object,
						    guint            prop_id,
						    GValue          *value,
Jonathan Blandford's avatar
Jonathan Blandford committed
566
						    GParamSpec      *pspec);
567

568
/* gtkwidget signals */
569
static void     gtk_tree_view_destroy              (GtkWidget        *widget);
570 571 572
static void     gtk_tree_view_realize              (GtkWidget        *widget);
static void     gtk_tree_view_unrealize            (GtkWidget        *widget);
static void     gtk_tree_view_map                  (GtkWidget        *widget);
573 574 575 576 577 578
static void     gtk_tree_view_get_preferred_width  (GtkWidget        *widget,
						    gint             *minimum,
						    gint             *natural);
static void     gtk_tree_view_get_preferred_height (GtkWidget        *widget,
						    gint             *minimum,
						    gint             *natural);
579
static void     gtk_tree_view_size_request         (GtkWidget        *widget,
580 581
						    GtkRequisition   *requisition,
                                                    gboolean          may_validate);
582 583
static void     gtk_tree_view_size_allocate        (GtkWidget        *widget,
						    GtkAllocation    *allocation);
Benjamin Otte's avatar
Benjamin Otte committed
584 585
static gboolean gtk_tree_view_draw                 (GtkWidget        *widget,
                                                    cairo_t          *cr);
586 587
static gboolean gtk_tree_view_key_press            (GtkWidget        *widget,
						    GdkEventKey      *event);
Jonathan Blandford's avatar
Jonathan Blandford committed
588 589
static gboolean gtk_tree_view_key_release          (GtkWidget        *widget,
						    GdkEventKey      *event);
590 591 592 593 594 595 596 597 598 599
static gboolean gtk_tree_view_motion               (GtkWidget        *widget,
						    GdkEventMotion   *event);
static gboolean gtk_tree_view_enter_notify         (GtkWidget        *widget,
						    GdkEventCrossing *event);
static gboolean gtk_tree_view_leave_notify         (GtkWidget        *widget,
						    GdkEventCrossing *event);
static gboolean gtk_tree_view_button_press         (GtkWidget        *widget,
						    GdkEventButton   *event);
static gboolean gtk_tree_view_button_release       (GtkWidget        *widget,
						    GdkEventButton   *event);
600 601
static gboolean gtk_tree_view_grab_broken          (GtkWidget          *widget,
						    GdkEventGrabBroken *event);
602 603 604 605 606
#if 0
static gboolean gtk_tree_view_configure            (GtkWidget         *widget,
						    GdkEventConfigure *event);
#endif

607 608 609
static GtkWidgetPath * gtk_tree_view_get_path_for_child (GtkContainer *container,
                                                         GtkWidget    *child);

610 611
static void     gtk_tree_view_set_focus_child      (GtkContainer     *container,
						    GtkWidget        *child);
612 613
static gint     gtk_tree_view_focus_out            (GtkWidget        *widget,
						    GdkEventFocus    *event);
614
static gint     gtk_tree_view_focus                (GtkWidget        *widget,
615
						    GtkDirectionType  direction);
616
static void     gtk_tree_view_grab_focus           (GtkWidget        *widget);
617
static void     gtk_tree_view_style_updated        (GtkWidget        *widget);
618 619
static void     gtk_tree_view_grab_notify          (GtkWidget        *widget,
						    gboolean          was_grabbed);
620 621
static void     gtk_tree_view_state_flags_changed  (GtkWidget        *widget,
						    GtkStateFlags     previous_state);
622 623 624 625 626 627 628 629 630

/* container signals */
static void     gtk_tree_view_remove               (GtkContainer     *container,
						    GtkWidget        *widget);
static void     gtk_tree_view_forall               (GtkContainer     *container,
						    gboolean          include_internals,
						    GtkCallback       callback,
						    gpointer          callback_data);

Havoc Pennington's avatar
Havoc Pennington committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
/* Source side drag signals */
static void gtk_tree_view_drag_begin       (GtkWidget        *widget,
                                            GdkDragContext   *context);
static void gtk_tree_view_drag_end         (GtkWidget        *widget,
                                            GdkDragContext   *context);
static void gtk_tree_view_drag_data_get    (GtkWidget        *widget,
                                            GdkDragContext   *context,
                                            GtkSelectionData *selection_data,
                                            guint             info,
                                            guint             time);
static void gtk_tree_view_drag_data_delete (GtkWidget        *widget,
                                            GdkDragContext   *context);

/* Target side drag signals */
static void     gtk_tree_view_drag_leave         (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  guint             time);
static gboolean gtk_tree_view_drag_motion        (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  guint             time);
static gboolean gtk_tree_view_drag_drop          (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  guint             time);
static void     gtk_tree_view_drag_data_received (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  GtkSelectionData *selection_data,
                                                  guint             info,
                                                  guint             time);

666
/* tree_model signals */
667 668 669 670
static void     gtk_tree_view_set_hadjustment             (GtkTreeView     *tree_view,
                                                           GtkAdjustment   *adjustment);
static void     gtk_tree_view_set_vadjustment             (GtkTreeView     *tree_view,
                                                           GtkAdjustment   *adjustment);
671
static gboolean gtk_tree_view_real_move_cursor            (GtkTreeView     *tree_view,
672
							   GtkMovementStep  step,
673
							   gint             count);
674 675 676
static gboolean gtk_tree_view_real_select_all             (GtkTreeView     *tree_view);
static gboolean gtk_tree_view_real_unselect_all           (GtkTreeView     *tree_view);
static gboolean gtk_tree_view_real_select_cursor_row      (GtkTreeView     *tree_view,
677
							   gboolean         start_editing);
678 679 680 681 682 683
static gboolean gtk_tree_view_real_toggle_cursor_row      (GtkTreeView     *tree_view);
static gboolean gtk_tree_view_real_expand_collapse_cursor_row (GtkTreeView     *tree_view,
							       gboolean         logical,
							       gboolean         expand,
							       gboolean         open_all);
static gboolean gtk_tree_view_real_select_cursor_parent   (GtkTreeView     *tree_view);
684
static void gtk_tree_view_row_changed                     (GtkTreeModel    *model,
685 686 687
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
688
static void gtk_tree_view_row_inserted                    (GtkTreeModel    *model,
689 690 691
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
692
static void gtk_tree_view_row_has_child_toggled           (GtkTreeModel    *model,
693 694 695
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
696
static void gtk_tree_view_row_deleted                     (GtkTreeModel    *model,
697 698
							   GtkTreePath     *path,
							   gpointer         data);
699
static void gtk_tree_view_rows_reordered                  (GtkTreeModel    *model,
700 701 702 703 704
							   GtkTreePath     *parent,
							   GtkTreeIter     *iter,
							   gint            *new_order,
							   gpointer         data);

Jonathan Blandford's avatar
Jonathan Blandford committed
705 706 707 708 709 710 711 712
/* Incremental reflow */
static gboolean validate_row             (GtkTreeView *tree_view,
					  GtkRBTree   *tree,
					  GtkRBNode   *node,
					  GtkTreeIter *iter,
					  GtkTreePath *path);
static void     validate_visible_area    (GtkTreeView *tree_view);
static gboolean validate_rows_handler    (GtkTreeView *tree_view);
713 714
static gboolean do_validate_rows         (GtkTreeView *tree_view,
					  gboolean     size_request);
715
static gboolean validate_rows            (GtkTreeView *tree_view);
Jonathan Blandford's avatar
Jonathan Blandford committed
716 717
static gboolean presize_handler_callback (gpointer     data);
static void     install_presize_handler  (GtkTreeView *tree_view);
718
static void     install_scroll_sync_handler (GtkTreeView *tree_view);
719 720 721
static void     gtk_tree_view_set_top_row   (GtkTreeView *tree_view,
					     GtkTreePath *path,
					     gint         offset);
722
static void	gtk_tree_view_dy_to_top_row (GtkTreeView *tree_view);
723
static void     gtk_tree_view_top_row_to_dy (GtkTreeView *tree_view);
724
static void     invalidate_empty_focus      (GtkTreeView *tree_view);
725

726
/* Internal functions */
727 728
static gboolean gtk_tree_view_is_expander_column             (GtkTreeView        *tree_view,
							      GtkTreeViewColumn  *column);
729
static inline gboolean gtk_tree_view_draw_expanders          (GtkTreeView        *tree_view);
730 731 732 733 734 735 736 737 738 739 740 741 742
static void     gtk_tree_view_add_move_binding               (GtkBindingSet      *binding_set,
							      guint               keyval,
							      guint               modmask,
							      gboolean            add_shifted_binding,
							      GtkMovementStep     step,
							      gint                count);
static gint     gtk_tree_view_unref_and_check_selection_tree (GtkTreeView        *tree_view,
							      GtkRBTree          *tree);
static void     gtk_tree_view_queue_draw_path                (GtkTreeView        *tree_view,
							      GtkTreePath        *path,
							      const GdkRectangle *clip_rect);
static void     gtk_tree_view_queue_draw_arrow               (GtkTreeView        *tree_view,
							      GtkRBTree          *tree,
743
							      GtkRBNode          *node);
744
static void     gtk_tree_view_draw_arrow                     (GtkTreeView        *tree_view,
745
                                                              cairo_t            *cr,
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
							      GtkRBTree          *tree,
							      GtkRBNode          *node,
							      gint                x,
							      gint                y);
static void     gtk_tree_view_get_arrow_xrange               (GtkTreeView        *tree_view,
							      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,
							      GtkRBTree          *tree,
							      GtkTreeIter        *iter,
							      gint                depth,
							      gboolean            recurse);
static void     gtk_tree_view_clamp_node_visible             (GtkTreeView        *tree_view,
							      GtkRBTree          *tree,
							      GtkRBNode          *node);
static void     gtk_tree_view_clamp_column_visible           (GtkTreeView        *tree_view,
							      GtkTreeViewColumn  *column,
							      gboolean            focus_to_cell);
static gboolean gtk_tree_view_maybe_begin_dragging_row       (GtkTreeView        *tree_view,
							      GdkEventMotion     *event);
static void     gtk_tree_view_focus_to_cursor                (GtkTreeView        *tree_view);
static void     gtk_tree_view_move_cursor_up_down            (GtkTreeView        *tree_view,
							      gint                count);
static void     gtk_tree_view_move_cursor_page_up_down       (GtkTreeView        *tree_view,
							      gint                count);
static void     gtk_tree_view_move_cursor_left_right         (GtkTreeView        *tree_view,
							      gint                count);
static void     gtk_tree_view_move_cursor_start_end          (GtkTreeView        *tree_view,
							      gint                count);
static gboolean gtk_tree_view_real_collapse_row              (GtkTreeView        *tree_view,
							      GtkTreePath        *path,
							      GtkRBTree          *tree,
							      GtkRBNode          *node,
							      gboolean            animate);
static gboolean gtk_tree_view_real_expand_row                (GtkTreeView        *tree_view,
							      GtkTreePath        *path,
							      GtkRBTree          *tree,
							      GtkRBNode          *node,
							      gboolean            open_all,
							      gboolean            animate);
static void     gtk_tree_view_real_set_cursor                (GtkTreeView        *tree_view,
							      GtkTreePath        *path,
							      gboolean            clear_and_select,
							      gboolean            clamp_node);
796
static gboolean gtk_tree_view_has_can_focus_cell             (GtkTreeView        *tree_view);
797 798 799 800
static void     column_sizing_notify                         (GObject            *object,
                                                              GParamSpec         *pspec,
                                                              gpointer            data);
static void     gtk_tree_view_stop_rubber_band               (GtkTreeView        *tree_view);
801 802 803
static void     update_prelight                              (GtkTreeView        *tree_view,
                                                              int                 x,
                                                              int                 y);
Kristian Rietveld's avatar
Kristian Rietveld committed
804

805 806
static inline gint gtk_tree_view_get_effective_header_height (GtkTreeView *tree_view);

807 808 809 810
static inline gint gtk_tree_view_get_cell_area_y_offset      (GtkTreeView *tree_view,
                                                              GtkRBTree   *tree,
                                                              GtkRBNode   *node,
                                                              gint         vertical_separator);
811 812 813
static inline gint gtk_tree_view_get_cell_area_height        (GtkTreeView *tree_view,
                                                              GtkRBNode   *node,
                                                              gint         vertical_separator);
814 815 816 817

static inline gint gtk_tree_view_get_row_y_offset            (GtkTreeView *tree_view,
                                                              GtkRBTree   *tree,
                                                              GtkRBNode   *node);
818 819 820
static inline gint gtk_tree_view_get_row_height              (GtkTreeView *tree_view,
                                                              GtkRBNode   *node);

821
/* interactive search */
Jonathan Blandford's avatar
Jonathan Blandford committed
822
static void     gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view);
823 824 825
static void     gtk_tree_view_search_dialog_hide        (GtkWidget        *search_dialog,
                                                         GtkTreeView      *tree_view,
                                                         GdkDevice        *device);
826
static void     gtk_tree_view_search_position_func      (GtkTreeView      *tree_view,
827 828
							 GtkWidget        *search_dialog,
							 gpointer          user_data);
829 830 831
static void     gtk_tree_view_search_disable_popdown    (GtkEntry         *entry,
							 GtkMenu          *menu,
							 gpointer          data);
Jonathan Blandford's avatar
Jonathan Blandford committed
832 833
static void     gtk_tree_view_search_preedit_changed    (GtkIMContext     *im_context,
							 GtkTreeView      *tree_view);
834 835
static void     gtk_tree_view_search_activate           (GtkEntry         *entry,
							 GtkTreeView      *tree_view);
836 837 838
static gboolean gtk_tree_view_real_search_enable_popdown(gpointer          data);
static void     gtk_tree_view_search_enable_popdown     (GtkWidget        *widget,
							 gpointer          data);
839 840 841 842 843 844
static gboolean gtk_tree_view_search_delete_event       (GtkWidget        *widget,
							 GdkEventAny      *event,
							 GtkTreeView      *tree_view);
static gboolean gtk_tree_view_search_button_press_event (GtkWidget        *widget,
							 GdkEventButton   *event,
							 GtkTreeView      *tree_view);
845 846 847
static gboolean gtk_tree_view_search_scroll_event       (GtkWidget        *entry,
							 GdkEventScroll   *event,
							 GtkTreeView      *tree_view);
848 849 850
static gboolean gtk_tree_view_search_key_press_event    (GtkWidget        *entry,
							 GdkEventKey      *event,
							 GtkTreeView      *tree_view);
851
static gboolean gtk_tree_view_search_move               (GtkWidget        *window,
852 853 854 855
							 GtkTreeView      *tree_view,
							 gboolean          up);
static gboolean gtk_tree_view_search_equal_func         (GtkTreeModel     *model,
							 gint              column,
856
							 const gchar      *key,
857 858
							 GtkTreeIter      *iter,
							 gpointer          search_data);
859 860 861
static gboolean gtk_tree_view_search_iter               (GtkTreeModel     *model,
							 GtkTreeSelection *selection,
							 GtkTreeIter      *iter,
862
							 const gchar      *text,
863 864 865 866
							 gint             *count,
							 gint              n);
static void     gtk_tree_view_search_init               (GtkWidget        *entry,
							 GtkTreeView      *tree_view);
867 868 869 870 871 872
static void     gtk_tree_view_put                       (GtkTreeView      *tree_view,
							 GtkWidget        *child_widget,
							 gint              x,
							 gint              y,
							 gint              width,
							 gint              height);
873
static gboolean gtk_tree_view_start_editing             (GtkTreeView      *tree_view,
874 875
							 GtkTreePath      *cursor_path,
							 gboolean          edit_only);
Jonathan Blandford's avatar
Jonathan Blandford committed
876 877
static void gtk_tree_view_stop_editing                  (GtkTreeView *tree_view,
							 gboolean     cancel_editing);
Jonathan Blandford's avatar
Jonathan Blandford committed
878
static gboolean gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view,
879
                                                             GdkDevice   *device,
Jonathan Blandford's avatar
Jonathan Blandford committed
880 881
							     gboolean     keybinding);
static gboolean gtk_tree_view_start_interactive_search      (GtkTreeView *tree_view);
882 883 884
static GtkTreeViewColumn *gtk_tree_view_get_drop_column (GtkTreeView       *tree_view,
							 GtkTreeViewColumn *column,
							 gint               drop_position);
885

Johan Dahlin's avatar
Johan Dahlin committed
886
/* GtkBuildable */
887 888 889 890 891 892 893 894
static void     gtk_tree_view_buildable_add_child          (GtkBuildable      *tree_view,
							    GtkBuilder        *builder,
							    GObject           *child,
							    const gchar       *type);
static GObject *gtk_tree_view_buildable_get_internal_child (GtkBuildable      *buildable,
							    GtkBuilder        *builder,
							    const gchar       *childname);
static void     gtk_tree_view_buildable_init               (GtkBuildableIface *iface);
Johan Dahlin's avatar
Johan Dahlin committed
895 896


897 898 899
static gboolean scroll_row_timeout                   (gpointer     data);
static void     add_scroll_timeout                   (GtkTreeView *tree_view);
static void     remove_scroll_timeout                (GtkTreeView *tree_view);
900

901
static guint tree_view_signals [LAST_SIGNAL] = { 0 };
902

903 904 905 906 907


/* GType Methods
 */

Johan Dahlin's avatar
Johan Dahlin committed
908 909
G_DEFINE_TYPE_WITH_CODE (GtkTreeView, gtk_tree_view, GTK_TYPE_CONTAINER,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
910 911
						gtk_tree_view_buildable_init)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
912 913 914 915

static void
gtk_tree_view_class_init (GtkTreeViewClass *class)
{
916
  GObjectClass *o_class;
917 918
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;
919
  GtkBindingSet *binding_set;
920

921
  binding_set = gtk_binding_set_by_class (class);
922

923 924 925 926
  o_class = (GObjectClass *) class;
  widget_class = (GtkWidgetClass *) class;
  container_class = (GtkContainerClass *) class;

927
  /* GObject signals */
928 929
  o_class->set_property = gtk_tree_view_set_property;
  o_class->get_property = gtk_tree_view_get_property;
930
  o_class->finalize = gtk_tree_view_finalize;
931

932
  /* GtkWidget signals */
933
  widget_class->destroy = gtk_tree_view_destroy;
934
  widget_class->map = gtk_tree_view_map;
935 936
  widget_class->realize = gtk_tree_view_realize;
  widget_class->unrealize = gtk_tree_view_unrealize;
937 938
  widget_class->get_preferred_width = gtk_tree_view_get_preferred_width;
  widget_class->get_preferred_height = gtk_tree_view_get_preferred_height;
939
  widget_class->size_allocate = gtk_tree_view_size_allocate;
940 941
  widget_class->button_press_event = gtk_tree_view_button_press;
  widget_class->button_release_event = gtk_tree_view_button_release;
942
  widget_class->grab_broken_event = gtk_tree_view_grab_broken;
943
  /*widget_class->configure_event = gtk_tree_view_configure;*/
944
  widget_class->motion_notify_event = gtk_tree_view_motion;
Benjamin Otte's avatar
Benjamin Otte committed
945
  widget_class->draw = gtk_tree_view_draw;
946
  widget_class->key_press_event = gtk_tree_view_key_press;
Jonathan Blandford's avatar
Jonathan Blandford committed
947
  widget_class->key_release_event = gtk_tree_view_key_release;
948 949 950
  widget_class->enter_notify_event = gtk_tree_view_enter_notify;
  widget_class->leave_notify_event = gtk_tree_view_leave_notify;
  widget_class->focus_out_event = gtk_tree_view_focus_out;
Havoc Pennington's avatar
Havoc Pennington committed
951 952 953 954 955 956 957 958
  widget_class->drag_begin = gtk_tree_view_drag_begin;
  widget_class->drag_end = gtk_tree_view_drag_end;
  widget_class->drag_data_get = gtk_tree_view_drag_data_get;
  widget_class->drag_data_delete = gtk_tree_view_drag_data_delete;
  widget_class->drag_leave = gtk_tree_view_drag_leave;
  widget_class->drag_motion = gtk_tree_view_drag_motion;
  widget_class->drag_drop = gtk_tree_view_drag_drop;
  widget_class->drag_data_received = gtk_tree_view_drag_data_received;
959
  widget_class->focus = gtk_tree_view_focus;
960
  widget_class->grab_focus = gtk_tree_view_grab_focus;
961
  widget_class->style_updated = gtk_tree_view_style_updated;
962
  widget_class->grab_notify = gtk_tree_view_grab_notify;
963
  widget_class->state_flags_changed = gtk_tree_view_state_flags_changed;
964

965
  /* GtkContainer signals */
966
  container_class->remove = gtk_tree_view_remove;
967 968
  container_class->forall = gtk_tree_view_forall;
  container_class->set_focus_child = gtk_tree_view_set_focus_child;
969
  container_class->get_path_for_child = gtk_tree_view_get_path_for_child;
970

971
  class->move_cursor = gtk_tree_view_real_move_cursor;
972
  class->select_all = gtk_tree_view_real_select_all;
973
  class->unselect_all = gtk_tree_view_real_unselect_all;
974
  class->select_cursor_row = gtk_tree_view_real_select_cursor_row;
975 976 977
  class->toggle_cursor_row = gtk_tree_view_real_toggle_cursor_row;
  class->expand_collapse_cursor_row = gtk_tree_view_real_expand_collapse_cursor_row;
  class->select_cursor_parent = gtk_tree_view_real_select_cursor_parent;
Jonathan Blandford's avatar
Jonathan Blandford committed
978
  class->start_interactive_search = gtk_tree_view_start_interactive_search;
979

980
  /* Properties */
981

982 983
  g_object_class_install_property (o_class,
                                   PROP_MODEL,
Tim Janik's avatar
Tim Janik committed
984
                                   g_param_spec_object ("model",
985 986
							P_("TreeView Model"),
							P_("The model for the tree view"),
Tim Janik's avatar
Tim Janik committed
987
							GTK_TYPE_TREE_MODEL,
988
							GTK_PARAM_READWRITE));
Jonathan Blandford's avatar
Jonathan Blandford committed
989

990 991 992 993
  g_object_class_override_property (o_class, PROP_HADJUSTMENT,    "hadjustment");
  g_object_class_override_property (o_class, PROP_VADJUSTMENT,    "vadjustment");
  g_object_class_override_property (o_class, PROP_HSCROLL_POLICY, "hscroll-policy");
  g_object_class_override_property (o_class, PROP_VSCROLL_POLICY, "vscroll-policy");
994 995 996

  g_object_class_install_property (o_class,
                                   PROP_HEADERS_VISIBLE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
997
                                   g_param_spec_boolean ("headers-visible",
998
							 P_("Headers Visible"),
999
							 P_("Show the column header buttons"),
1000
							 TRUE,
1001
							 GTK_PARAM_READWRITE));
1002 1003 1004

  g_object_class_install_property (o_class,
                                   PROP_HEADERS_CLICKABLE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1005
                                   g_param_spec_boolean ("headers-clickable",
1006 1007
							 P_("Headers Clickable"),
							 P_("Column headers respond to click events"),
1008
							 TRUE,
1009
							 GTK_PARAM_READWRITE));
1010 1011 1012

  g_object_class_install_property (o_class,
                                   PROP_EXPANDER_COLUMN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1013
                                   g_param_spec_object ("expander-column",
1014 1015
							P_("Expander Column"),
							P_("Set the column for the expander column"),
1016
							GTK_TYPE_TREE_VIEW_COLUMN,
1017
							GTK_PARAM_READWRITE));
1018

1019 1020 1021
  g_object_class_install_property (o_class,
                                   PROP_REORDERABLE,
                                   g_param_spec_boolean ("reorderable",
1022 1023
							 P_("Reorderable"),
							 P_("View is reorderable"),
1024
							 FALSE,
1025
							 GTK_PARAM_READWRITE));
1026

1027 1028
  g_object_class_install_property (o_class,
                                   PROP_RULES_HINT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1029
                                   g_param_spec_boolean ("rules-hint",
1030 1031
							 P_("Rules Hint"),
							 P_("Set a hint to the theme engine to draw rows in alternating colors"),
1032
							 FALSE,
1033
							 GTK_PARAM_READWRITE));
1034

1035 1036
    g_object_class_install_property (o_class,
				     PROP_ENABLE_SEARCH,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1037
				     g_param_spec_boolean ("enable-search",
1038 1039
							   P_("Enable Search"),
							   P_("View allows user to search through columns interactively"),
1040
							   TRUE,
1041
							   GTK_PARAM_READWRITE));
1042

1043 1044
    g_object_class_install_property (o_class,
				     PROP_SEARCH_COLUMN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1045
				     g_param_spec_int ("search-column",
1046
						       P_("Search Column"),
1047
						       P_("Model column to search through during interactive search"),
1048 1049
						       -1,
						       G_MAXINT,
1050
						       -1,
1051
						       GTK_PARAM_READWRITE));
1052

1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
    /**
     * GtkTreeView:fixed-height-mode:
     *
     * Setting the ::fixed-height-mode property to %TRUE speeds up 
     * #GtkTreeView by assuming that all rows have the same height. 
     * Only enable this option if all rows are the same height.  
     * Please see gtk_tree_view_set_fixed_height_mode() for more 
     * information on this option.
     *
     * Since: 2.4
     **/
1064 1065
    g_object_class_install_property (o_class,
                                     PROP_FIXED_HEIGHT_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1066
                                     g_param_spec_boolean ("fixed-height-mode",
1067 1068
                                                           P_("Fixed Height Mode"),
                                                           P_("Speeds up GtkTreeView by assuming that all rows have the same height"),
1069
                                                           FALSE,
1070
                                                           GTK_PARAM_READWRITE));
1071 1072 1073 1074
    
    /**
     * GtkTreeView:hover-selection:
     * 
Matthias Clasen's avatar
Matthias Clasen committed
1075
     * Enables or disables the hover selection mode of @tree_view.
1076
     * Hover selection makes the selected row follow the pointer.
Matthias Clasen's avatar
Matthias Clasen committed
1077 1078 1079
     * Currently, this works only for the selection modes 
     * %GTK_SELECTION_SINGLE and %GTK_SELECTION_BROWSE.
     *
Matthias Clasen's avatar
Matthias Clasen committed
1080
     * This mode is primarily intended for treeviews in popups, e.g.
1081 1082 1083 1084 1085 1086
     * in #GtkComboBox or #GtkEntryCompletion.
     *
     * Since: 2.6
     */
    g_object_class_install_property (o_class,
                                     PROP_HOVER_SELECTION,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1087
                                     g_param_spec_boolean ("hover-selection",
1088 1089 1090
                                                           P_("Hover Selection"),
                                                           P_("Whether the selection should follow the pointer"),
                                                           FALSE,
1091
                                                           GTK_PARAM_READWRITE));
1092

1093 1094 1095
    /**
     * GtkTreeView:hover-expand:
     * 
Matthias Clasen's avatar
Matthias Clasen committed
1096
     * Enables or disables the hover expansion mode of @tree_view.
Matthias Clasen's avatar
Matthias Clasen committed
1097
     * Hover expansion makes rows expand or collapse if the pointer moves 
1098 1099
     * over them.
     *
Matthias Clasen's avatar
Matthias Clasen committed
1100
     * This mode is primarily intended for treeviews in popups, e.g.
1101 1102 1103 1104 1105 1106
     * in #GtkComboBox or #GtkEntryCompletion.
     *
     * Since: 2.6
     */
    g_object_class_install_property (o_class,
                                     PROP_HOVER_EXPAND,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1107
                                     g_param_spec_boolean ("hover-expand",
1108
                                                           P_("Hover Expand"),
1109
                                                           P_("Whether rows should be expanded/collapsed when the pointer moves over them"),
1110
                                                           FALSE,
1111
                                                           GTK_PARAM_READWRITE));
1112

Matthias Clasen's avatar
Matthias Clasen committed
1113 1114 1115 1116 1117 1118 1119
    /**
     * GtkTreeView:show-expanders:
     *
     * %TRUE if the view has expanders.
     *
     * Since: 2.12
     */
Kristian Rietveld's avatar
Kristian Rietveld committed
1120 1121 1122 1123 1124 1125 1126 1127
    g_object_class_install_property (o_class,
				     PROP_SHOW_EXPANDERS,
				     g_param_spec_boolean ("show-expanders",
							   P_("Show Expanders"),
							   P_("View has expanders"),
							   TRUE,
							   GTK_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
1128 1129 1130 1131 1132 1133 1134
    /**
     * GtkTreeView:level-indentation:
     *
     * Extra indentation for each level.
     *
     * Since: 2.12
     */
Kristian Rietveld's avatar
Kristian Rietveld committed
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
    g_object_class_install_property (o_class,
				     PROP_LEVEL_INDENTATION,
				     g_param_spec_int ("level-indentation",
						       P_("Level Indentation"),
						       P_("Extra indentation for each level"),
						       0,
						       G_MAXINT,
						       0,
						       GTK_PARAM_READWRITE));

1145 1146 1147 1148 1149 1150 1151 1152
    g_object_class_install_property (o_class,
                                     PROP_RUBBER_BANDING,
                                     g_param_spec_boolean ("rubber-banding",
                                                           P_("Rubber Banding"),
                                                           P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
                                                           FALSE,
                                                           GTK_PARAM_READWRITE));

1153 1154
    g_object_class_install_property (o_class,
                                     PROP_ENABLE_GRID_LINES,
1155 1156 1157 1158 1159 1160
                                     g_param_spec_enum ("enable-grid-lines",
							P_("Enable Grid Lines"),
							P_("Whether grid lines should be drawn in the tree view"),
							GTK_TYPE_TREE_VIEW_GRID_LINES,
							GTK_TREE_VIEW_GRID_LINES_NONE,
							GTK_PARAM_READWRITE));
1161 1162 1163 1164 1165 1166 1167 1168 1169

    g_object_class_install_property (o_class,
                                     PROP_ENABLE_TREE_LINES,
                                     g_param_spec_boolean ("enable-tree-lines",
                                                           P_("Enable Tree Lines"),
                                                           P_("Whether tree lines should be drawn in the tree view"),
                                                           FALSE,
                                                           GTK_PARAM_READWRITE));

1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
    g_object_class_install_property (o_class,
				     PROP_TOOLTIP_COLUMN,
				     g_param_spec_int ("tooltip-column",
						       P_("Tooltip Column"),
						       P_("The column in the model containing the tooltip texts for the rows"),
						       -1,
						       G_MAXINT,
						       -1,
						       GTK_PARAM_READWRITE));

1180
  /* Style properties */
1181
#define _TREE_VIEW_EXPANDER_SIZE 12
1182
#define _TREE_VIEW_VERTICAL_SEPARATOR 2
1183
#define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
1184

1185
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1186
					   g_param_spec_int ("expander-size",
1187 1188
							     P_("Expander Size"),
							     P_("Size of the expander arrow"),
1189 1190
							     0,
							     G_MAXINT,
1191
							     _TREE_VIEW_EXPANDER_SIZE,
1192
							     GTK_PARAM_READABLE));
1193

1194
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1195
					   g_param_spec_int ("vertical-separator",
1196 1197
							     P_("Vertical Separator Width"),
							     P_("Vertical space between cells.  Must be an even number"),
1198 1199 1200
							     0,
							     G_MAXINT,
							     _TREE_VIEW_VERTICAL_SEPARATOR,
1201
							     GTK_PARAM_READABLE));
1202

1203
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1204
					   g_param_spec_int ("horizontal-separator",
1205 1206
							     P_("Horizontal Separator Width"),
							     P_("Horizontal space between cells.  Must be an even number"),
1207 1208 1209
							     0,
							     G_MAXINT,
							     _TREE_VIEW_HORIZONTAL_SEPARATOR,
1210
							     GTK_PARAM_READABLE));
1211

1212
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1213
					   g_param_spec_boolean ("allow-rules",
1214 1215
								 P_("Allow Rules"),
								 P_("Allow drawing of alternating color rows"),
1216
								 TRUE,
1217
								 GTK_PARAM_READABLE));
1218

1219
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1220
					   g_param_spec_boolean ("indent-expanders",
1221 1222
								 P_("Indent Expanders"),
								 P_("Make the expanders indented"),
1223
								 TRUE,
1224
								 GTK_PARAM_READABLE));
Manish Singh's avatar
Manish Singh committed
1225

1226
  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1227
                                           g_param_spec_boxed ("even-row-color",
1228 1229
                                                               P_("Even Row Color"),
                                                               P_("Color to use for even rows"),
1230
							       GDK_TYPE_COLOR,
1231
							       GTK_PARAM_READABLE));
1232 1233

  gtk_widget_class_install_style_property (widget_class,
Matthias Clasen's avatar
x  
Matthias Clasen committed
1234
                                           g_param_spec_boxed ("odd-row-color",
1235 1236
                                                               P_("Odd Row Color"),
                                                               P_("Color to use for odd rows"),
1237
							       GDK_TYPE_COLOR,
1238
							       GTK_PARAM_READABLE));
1239

1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("grid-line-width",
							     P_("Grid line width"),
							     P_("Width, in pixels, of the tree view grid lines"),
							     0, G_MAXINT, 1,
							     GTK_PARAM_READABLE));

  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("tree-line-width",
							     P_("Tree line width"),
							     P_("Width, in pixels, of the tree view lines"),
							     0, G_MAXINT, 1,
							     GTK_PARAM_READABLE));

  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_string ("grid-line-pattern",
								P_("Grid line pattern"),
								P_("Dash pattern used to draw the tree view grid lines"),
								"\1\1",
								GTK_PARAM_READABLE));

  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_string ("tree-line-pattern",
								P_("Tree line pattern"),
								P_("Dash pattern used to draw the tree view lines"),
								"\1\1",
								GTK_PARAM_READABLE));

1268
  /* Signals */
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
  /**
   * GtkTreeView::row-activated:
   * @tree_view: the object on which the signal is emitted
   * @path: the #GtkTreePath for the activated row
   * @column: the #GtkTreeViewColumn in which the activation occurred
   *
   * The "row-activated" signal is emitted when the method
   * gtk_tree_view_row_activated() is called or the user double clicks 
   * a treeview row. It is also emitted when a non-editable row is 
   * selected and one of the keys: Space, Shift+Space, Return or 
   * Enter is pressed.
   * 
   * For selection handling refer to the <link linkend="TreeWidget">tree 
   * widget conceptual overview</link> as well as #GtkTreeSelection.
   */
1284
  tree_view_signals[ROW_ACTIVATED] =
1285
    g_signal_new (I_("row-activated"),
Manish Singh's avatar
Manish Singh committed
1286 1287 1288 1289 1290 1291 1292 1293
		  G_TYPE_FROM_CLASS (o_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkTreeViewClass, row_activated),
		  NULL, NULL,
		  _gtk_marshal_VOID__BOXED_OBJECT,
		  G_TYPE_NONE, 2,
		  GTK_TYPE_TREE_PATH,
		  GTK_TYPE_TREE_VIEW_COLUMN);
1294

1295 1296 1297 1298 1299 1300 1301 1302 1303
  /**
   * GtkTreeView::test-expand-row:
   * @tree_view: the object on which the signal is emitted
   * @iter: the tree iter of the row to expand
   * @path: a tree path that points to the row 
   * 
   * The given row is about to be expanded (show its children nodes). Use this
   * signal if you need to control the expandability of individual rows.
   *
1304
   * Returns: %FALSE to allow expansion, %TRUE to reject
1305
   */
1306
  tree_view_signals[TEST_EXPAND_ROW] =
1307
    g_signal_new (I_("test-expand-row"),
Manish Singh's avatar
Manish Singh committed
1308 1309 1310 1311 1312 1313 1314 1315
		  G_TYPE_FROM_CLASS (o_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkTreeViewClass, test_expand_row),
		  _gtk_boolean_handled_accumulator, NULL,
		  _gtk_marshal_BOOLEAN__BOXED_BOXED,
		  G_TYPE_BOOLEAN, 2,
		  GTK_TYPE_TREE_ITER,
		  GTK_TYPE_TREE_PATH);
1316

1317 1318 1319 1320 1321 1322 1323 1324 1325
  /**
   * GtkTreeView::test-collapse-row:
   * @tree_view: the object on which the signal is emitted
   * @iter: the tree iter of the row to collapse
   * @path: a tree path that points to the row 
   * 
   * The given row is about to be collapsed (hide its children nodes). Use this
   * signal if you need to control the collapsibility of individual rows.
   *
1326
   * Returns: %FALSE to allow collapsing, %TRUE to reject
1327
   */
1328
  tree_view_signals[TEST_COLLAPSE_ROW] =
1329
    g_signal_new (I_("test-collapse-row"),
Manish Singh's avatar
Manish Singh committed
1330 1331 1332 1333 1334 1335 1336 1337
		  G_TYPE_FROM_CLASS (o_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkTreeViewClass, test_collapse_row),
		  _gtk_boolean_handled_accumulator, NULL,
		  _gtk_marshal_BOOLEAN__BOXED_BOXED,
		  G_TYPE_BOOLEAN, 2,
		  GTK_TYPE_TREE_ITER,
		  GTK_TYPE_TREE_PATH);
1338

1339 1340 1341 1342 1343 1344 1345 1346
  /**
   * GtkTreeView::row-expanded:
   * @tree_view: the object on which the signal is emitted
   * @iter: the tree iter of the expanded row
   * @path: a tree path that points to the row 
   * 
   * The given row has been expanded (child nodes are shown).
   */
1347
  tree_view_signals[ROW_EXPANDED] =
1348
    g_signal_new (I_("row-expanded"),
Manish Singh's avatar
Manish Singh committed
1349 1350 1351 1352 1353 1354 1355 1356
		  G_TYPE_FROM_CLASS (o_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkTreeViewClass, row_expanded),
		  NULL, NULL,
		  _gtk_marshal_VOID__BOXED_BOXED,
		  G_TYPE_NONE, 2,
		  GTK_TYPE_TREE_ITER,
		  GTK_TYPE_TREE_PATH);
1357

1358 1359 1360 1361 1362 1363 1364 1365
  /**
   * GtkTreeView::row-collapsed:
   * @tree_view: the object on which the signal is emitted
   * @iter: the tree iter of the collapsed row
   * @path: a tree path that points to the row 
   * 
   * The given row has been collapsed (child nodes are hidden).
   */
1366
  tree_view_signals[ROW_COLLAPSED] =
1367
    g_signal_new (I_("row-collapsed"),
Manish Singh's avatar
Manish Singh committed
1368 1369 1370 1371 1372 1373 1374 1375
		  G_TYPE_FROM_CLASS (o_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkTreeViewClass, row_collapsed),
		  NULL, NULL,
		  _gtk_marshal_VOID__BOXED_BOXED,
		  G_TYPE_NONE, 2,
		  GTK_TYPE_TREE_ITER,
		  GTK_TYPE_TREE_PATH);
1376

1377 1378 1379 1380 1381