gtktreeview.c 307 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
21
22
 * 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.
 */


#include "gtktreeview.h"
#include "gtkrbtree.h"
Havoc Pennington's avatar
Havoc Pennington committed
23
#include "gtktreednd.h"
24
25
26
27
#include "gtktreeprivate.h"
#include "gtkcellrenderer.h"
#include "gtksignal.h"
#include "gtkmain.h"
28
#include "gtkmarshalers.h"
29
30
31
#include "gtkbutton.h"
#include "gtkalignment.h"
#include "gtklabel.h"
Havoc Pennington's avatar
Havoc Pennington committed
32
33
#include "gtkhbox.h"
#include "gtkarrow.h"
34
#include "gtkintl.h"
35
#include "gtkbindings.h"
36
37
#include "gtkcontainer.h"
#include "gtkentry.h"
Jonathan Blandford's avatar
Jonathan Blandford committed
38
#include "gtktreemodelsort.h"
39

40
#include <string.h>
41
42
#include <gdk/gdkkeysyms.h>

43
#define GTK_TREE_VIEW_SEARCH_DIALOG_KEY "gtk-tree-view-search-dialog"
Jonathan Blandford's avatar
Jonathan Blandford committed
44
#define GTK_TREE_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
45
#define GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC (GTK_TREE_VIEW_PRIORITY_VALIDATE + 2)
Jonathan Blandford's avatar
Jonathan Blandford committed
46
#define GTK_TREE_VIEW_NUM_ROWS_PER_IDLE 500
47
#define SCROLL_EDGE_SIZE 15
48
#define EXPANDER_EXTRA_PADDING 4
49

Havoc Pennington's avatar
Havoc Pennington committed
50
51
52
53
54
55
56
/* The "background" areas of all rows/cells add up to cover the entire tree.
 * The background includes all inter-row and inter-cell spacing.
 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
 * i.e. just the cells, no spacing.
 */

#define BACKGROUND_HEIGHT(node) (GTK_RBNODE_GET_HEIGHT (node))
Kristian Rietveld's avatar
Kristian Rietveld committed
57
#define CELL_HEIGHT(node, separator) ((BACKGROUND_HEIGHT (node)) - (separator))
Havoc Pennington's avatar
Havoc Pennington committed
58

59
60
#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)
61
62
63
64

/* This is in Window coordinates */
#define BACKGROUND_FIRST_PIXEL(tree_view,tree,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, _gtk_rbtree_node_find_offset ((tree), (node))))
#define CELL_FIRST_PIXEL(tree_view,tree,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,tree,node) + separator/2)
65
66


67
typedef struct _GtkTreeViewChild GtkTreeViewChild;
68
69
70
71
72
struct _GtkTreeViewChild
{
  GtkWidget *widget;
  gint x;
  gint y;
73
74
  gint width;
  gint height;
75
76
};

Jonathan Blandford's avatar
Jonathan Blandford committed
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
typedef struct _TreeViewDragInfo TreeViewDragInfo;
struct _TreeViewDragInfo
{
  GdkModifierType start_button_mask;
  GtkTargetList *source_target_list;
  GdkDragAction source_actions;

  GtkTargetList *dest_target_list;

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


/* Signals */
93
94
95
enum
{
  ROW_ACTIVATED,
96
97
98
99
  TEST_EXPAND_ROW,
  TEST_COLLAPSE_ROW,
  ROW_EXPANDED,
  ROW_COLLAPSED,
100
  COLUMNS_CHANGED,
101
  CURSOR_CHANGED,
102
  MOVE_CURSOR,
103
  SELECT_ALL,
104
  UNSELECT_ALL,
105
  SELECT_CURSOR_ROW,
106
107
108
  TOGGLE_CURSOR_ROW,
  EXPAND_COLLAPSE_CURSOR_ROW,
  SELECT_CURSOR_PARENT,
109
  START_INTERACTIVE_SEARCH,
110
111
112
  LAST_SIGNAL
};

113
/* Properties */
114
115
116
117
118
119
120
121
enum {
  PROP_0,
  PROP_MODEL,
  PROP_HADJUSTMENT,
  PROP_VADJUSTMENT,
  PROP_HEADERS_VISIBLE,
  PROP_HEADERS_CLICKABLE,
  PROP_EXPANDER_COLUMN,
122
  PROP_REORDERABLE,
123
124
  PROP_RULES_HINT,
  PROP_ENABLE_SEARCH,
125
  PROP_SEARCH_COLUMN
126
};
127
128

static void     gtk_tree_view_class_init           (GtkTreeViewClass *klass);
129
130
131
132
static void     gtk_tree_view_init                 (GtkTreeView      *tree_view);

/* object signals */
static void     gtk_tree_view_finalize             (GObject          *object);
133
134
135
static void     gtk_tree_view_set_property         (GObject         *object,
						    guint            prop_id,
						    const GValue    *value,
Jonathan Blandford's avatar
Jonathan Blandford committed
136
						    GParamSpec      *pspec);
137
138
139
static void     gtk_tree_view_get_property         (GObject         *object,
						    guint            prop_id,
						    GValue          *value,
Jonathan Blandford's avatar
Jonathan Blandford committed
140
						    GParamSpec      *pspec);
141

142
/* gtkobject signals */
Jonathan Blandford's avatar
Jonathan Blandford committed
143
144
static void     gtk_tree_view_destroy              (GtkObject        *object);

145
/* gtkwidget signals */
146
147
148
149
150
151
152
153
154
static void     gtk_tree_view_realize              (GtkWidget        *widget);
static void     gtk_tree_view_unrealize            (GtkWidget        *widget);
static void     gtk_tree_view_map                  (GtkWidget        *widget);
static void     gtk_tree_view_size_request         (GtkWidget        *widget,
						    GtkRequisition   *requisition);
static void     gtk_tree_view_size_allocate        (GtkWidget        *widget,
						    GtkAllocation    *allocation);
static gboolean gtk_tree_view_expose               (GtkWidget        *widget,
						    GdkEventExpose   *event);
155
156
static gboolean gtk_tree_view_key_press            (GtkWidget        *widget,
						    GdkEventKey      *event);
157
158
159
160
161
162
163
164
165
166
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);
167
168
static void     gtk_tree_view_set_focus_child      (GtkContainer     *container,
						    GtkWidget        *child);
169
170
static gint     gtk_tree_view_focus_out            (GtkWidget        *widget,
						    GdkEventFocus    *event);
171
static gint     gtk_tree_view_focus                (GtkWidget        *widget,
172
						    GtkDirectionType  direction);
173
static void     gtk_tree_view_grab_focus           (GtkWidget        *widget);
Kristian Rietveld's avatar
Kristian Rietveld committed
174
175
static void     gtk_tree_view_style_set            (GtkWidget        *widget,
						    GtkStyle         *previous_style);
176
177
178
179
180
181
182
183
184

/* 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
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
/* 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);

220
/* tree_model signals */
221
222
223
static void gtk_tree_view_set_adjustments                 (GtkTreeView     *tree_view,
							   GtkAdjustment   *hadj,
							   GtkAdjustment   *vadj);
224
static gboolean gtk_tree_view_real_move_cursor            (GtkTreeView     *tree_view,
225
							   GtkMovementStep  step,
226
							   gint             count);
227
static void gtk_tree_view_real_select_all                 (GtkTreeView     *tree_view);
228
static void gtk_tree_view_real_unselect_all               (GtkTreeView     *tree_view);
229
230
static void gtk_tree_view_real_select_cursor_row          (GtkTreeView     *tree_view,
							   gboolean         start_editing);
231
232
233
234
235
236
static void gtk_tree_view_real_toggle_cursor_row          (GtkTreeView     *tree_view);
static void gtk_tree_view_real_expand_collapse_cursor_row (GtkTreeView     *tree_view,
							   gboolean         logical,
							   gboolean         expand,
							   gboolean         open_all);
static void gtk_tree_view_real_select_cursor_parent       (GtkTreeView     *tree_view);
237
static void gtk_tree_view_row_changed                     (GtkTreeModel    *model,
238
239
240
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
241
static void gtk_tree_view_row_inserted                    (GtkTreeModel    *model,
242
243
244
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
245
static void gtk_tree_view_row_has_child_toggled           (GtkTreeModel    *model,
246
247
248
							   GtkTreePath     *path,
							   GtkTreeIter     *iter,
							   gpointer         data);
249
static void gtk_tree_view_row_deleted                     (GtkTreeModel    *model,
250
251
							   GtkTreePath     *path,
							   gpointer         data);
252
static void gtk_tree_view_rows_reordered                  (GtkTreeModel    *model,
253
254
255
256
257
							   GtkTreePath     *parent,
							   GtkTreeIter     *iter,
							   gint            *new_order,
							   gpointer         data);

Jonathan Blandford's avatar
Jonathan Blandford committed
258
259
260
261
262
263
264
265
/* 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);
266
static gboolean do_validate_rows	 (GtkTreeView *tree_view);
Jonathan Blandford's avatar
Jonathan Blandford committed
267
268
static gboolean presize_handler_callback (gpointer     data);
static void     install_presize_handler  (GtkTreeView *tree_view);
269
static void     install_scroll_sync_handler (GtkTreeView *tree_view);
270
static void	gtk_tree_view_dy_to_top_row (GtkTreeView *tree_view);
271
static void     gtk_tree_view_top_row_to_dy (GtkTreeView *tree_view);
272
273


274
/* Internal functions */
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
static gboolean gtk_tree_view_is_expander_column             (GtkTreeView       *tree_view,
							      GtkTreeViewColumn *column);
static void     gtk_tree_view_add_move_binding               (GtkBindingSet     *binding_set,
							      guint              keyval,
							      guint              modmask,
							      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,
							      GdkRectangle      *clip_rect);
static void     gtk_tree_view_queue_draw_arrow               (GtkTreeView       *tree_view,
							      GtkRBTree         *tree,
							      GtkRBNode         *node,
							      GdkRectangle      *clip_rect);
static void     gtk_tree_view_draw_arrow                     (GtkTreeView       *tree_view,
							      GtkRBTree         *tree,
							      GtkRBNode         *node,
							      gint               x,
							      gint               y);
static void     gtk_tree_view_get_arrow_xrange               (GtkTreeView       *tree_view,
297
							      GtkRBTree         *tree,
298
299
300
301
302
303
304
305
306
307
308
							      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,
Jonathan Blandford's avatar
Jonathan Blandford committed
309
							      gboolean           recurse);
310
311
312
static gboolean gtk_tree_view_discover_dirty_iter            (GtkTreeView       *tree_view,
							      GtkTreeIter       *iter,
							      gint               depth,
313
314
							      gint              *height,
							      GtkRBNode         *node);
315
316
317
318
319
320
321
static void     gtk_tree_view_discover_dirty                 (GtkTreeView       *tree_view,
							      GtkRBTree         *tree,
							      GtkTreeIter       *iter,
							      gint               depth);
static void     gtk_tree_view_clamp_node_visible             (GtkTreeView       *tree_view,
							      GtkRBTree         *tree,
							      GtkRBNode         *node);
322
323
static void     gtk_tree_view_clamp_column_visible           (GtkTreeView       *tree_view,
							      GtkTreeViewColumn *column);
324
325
326
327
328
329
330
331
332
333
334
335
336
337
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,
338
339
							      GtkRBNode         *node,
							      gboolean           animate);
340
341
342
343
static gboolean gtk_tree_view_real_expand_row                (GtkTreeView       *tree_view,
							      GtkTreePath       *path,
							      GtkRBTree         *tree,
							      GtkRBNode         *node,
344
345
							      gboolean           open_all,
							      gboolean           animate);
346
347
static void     gtk_tree_view_real_set_cursor                (GtkTreeView       *tree_view,
							      GtkTreePath       *path,
348
349
							      gboolean           clear_and_select,
							      gboolean           clamp_node);
350
351
352
353
354
355

/* interactive search */
static void     gtk_tree_view_search_dialog_destroy     (GtkWidget        *search_dialog,
							 GtkTreeView      *tree_view);
static void     gtk_tree_view_search_position_func      (GtkTreeView      *tree_view,
							 GtkWidget        *search_dialog);
356
357
358
359
360
361
static void     gtk_tree_view_search_disable_popdown    (GtkEntry         *entry,
							 GtkMenu          *menu,
							 gpointer          data);
static gboolean gtk_tree_view_real_search_enable_popdown(gpointer          data);
static void     gtk_tree_view_search_enable_popdown     (GtkWidget        *widget,
							 gpointer          data);
362
363
364
365
366
367
368
369
370
371
372
373
374
375
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);
static gboolean gtk_tree_view_search_key_press_event    (GtkWidget        *entry,
							 GdkEventKey      *event,
							 GtkTreeView      *tree_view);
static void     gtk_tree_view_search_move               (GtkWidget        *window,
							 GtkTreeView      *tree_view,
							 gboolean          up);
static gboolean gtk_tree_view_search_equal_func         (GtkTreeModel     *model,
							 gint              column,
376
							 const gchar      *key,
377
378
							 GtkTreeIter      *iter,
							 gpointer          search_data);
379
380
381
static gboolean gtk_tree_view_search_iter               (GtkTreeModel     *model,
							 GtkTreeSelection *selection,
							 GtkTreeIter      *iter,
382
							 const gchar      *text,
383
384
385
386
							 gint             *count,
							 gint              n);
static void     gtk_tree_view_search_init               (GtkWidget        *entry,
							 GtkTreeView      *tree_view);
387
388
389
390
391
392
static void     gtk_tree_view_put                       (GtkTreeView      *tree_view,
							 GtkWidget        *child_widget,
							 gint              x,
							 gint              y,
							 gint              width,
							 gint              height);
393
394
395
396
397
398
399
400
401
static gboolean gtk_tree_view_start_editing             (GtkTreeView      *tree_view,
							 GtkTreePath      *cursor_path);
static void gtk_tree_view_real_start_editing (GtkTreeView       *tree_view,
					      GtkTreeViewColumn *column,
					      GtkTreePath       *path,
					      GtkCellEditable   *cell_editable,
					      GdkRectangle      *cell_area,
					      GdkEvent          *event,
					      guint              flags);
Jonathan Blandford's avatar
Jonathan Blandford committed
402
403
static void gtk_tree_view_stop_editing                  (GtkTreeView *tree_view,
							 gboolean     cancel_editing);
404
static void gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view);
405
406
407
static GtkTreeViewColumn *gtk_tree_view_get_drop_column (GtkTreeView       *tree_view,
							 GtkTreeViewColumn *column,
							 gint               drop_position);
408

409
410

static GtkContainerClass *parent_class = NULL;
411
static guint tree_view_signals [LAST_SIGNAL] = { 0 };
412

413
414
415
416
417


/* GType Methods
 */

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
GtkType
gtk_tree_view_get_type (void)
{
  static GtkType tree_view_type = 0;

  if (!tree_view_type)
    {
      static const GTypeInfo tree_view_info =
      {
        sizeof (GtkTreeViewClass),
	NULL,		/* base_init */
	NULL,		/* base_finalize */
        (GClassInitFunc) gtk_tree_view_class_init,
	NULL,		/* class_finalize */
	NULL,		/* class_data */
        sizeof (GtkTreeView),
	0,              /* n_preallocs */
        (GInstanceInitFunc) gtk_tree_view_init
      };

438
      tree_view_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTreeView", &tree_view_info, 0);
439
440
441
442
443
444
445
446
    }

  return tree_view_type;
}

static void
gtk_tree_view_class_init (GtkTreeViewClass *class)
{
447
  GObjectClass *o_class;
448
449
450
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;
451
  GtkBindingSet *binding_set;
452

453
  parent_class = g_type_class_peek_parent (class);
454
  binding_set = gtk_binding_set_by_class (class);
455

456
457
458
459
460
  o_class = (GObjectClass *) class;
  object_class = (GtkObjectClass *) class;
  widget_class = (GtkWidgetClass *) class;
  container_class = (GtkContainerClass *) class;

461
  /* GObject signals */
462
463
  o_class->set_property = gtk_tree_view_set_property;
  o_class->get_property = gtk_tree_view_get_property;
464
  o_class->finalize = gtk_tree_view_finalize;
465

466
  /* GtkObject signals */
Jonathan Blandford's avatar
Jonathan Blandford committed
467
  object_class->destroy = gtk_tree_view_destroy;
468

469
470
  /* GtkWidget signals */
  widget_class->map = gtk_tree_view_map;
471
472
473
474
  widget_class->realize = gtk_tree_view_realize;
  widget_class->unrealize = gtk_tree_view_unrealize;
  widget_class->size_request = gtk_tree_view_size_request;
  widget_class->size_allocate = gtk_tree_view_size_allocate;
475
476
  widget_class->button_press_event = gtk_tree_view_button_press;
  widget_class->button_release_event = gtk_tree_view_button_release;
477
  widget_class->motion_notify_event = gtk_tree_view_motion;
478
  widget_class->expose_event = gtk_tree_view_expose;
479
  widget_class->key_press_event = gtk_tree_view_key_press;
480
481
482
  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
483
484
485
486
487
488
489
490
  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;
491
  widget_class->focus = gtk_tree_view_focus;
492
  widget_class->grab_focus = gtk_tree_view_grab_focus;
Kristian Rietveld's avatar
Kristian Rietveld committed
493
  widget_class->style_set = gtk_tree_view_style_set;
494

495
  /* GtkContainer signals */
496
  container_class->remove = gtk_tree_view_remove;
497
498
  container_class->forall = gtk_tree_view_forall;
  container_class->set_focus_child = gtk_tree_view_set_focus_child;
499
500

  class->set_scroll_adjustments = gtk_tree_view_set_adjustments;
501
  class->move_cursor = gtk_tree_view_real_move_cursor;
502
  class->select_all = gtk_tree_view_real_select_all;
503
  class->unselect_all = gtk_tree_view_real_unselect_all;
504
  class->select_cursor_row = gtk_tree_view_real_select_cursor_row;
505
506
507
  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;
508
  class->start_interactive_search = gtk_tree_view_real_start_interactive_search;
509

510
  /* Properties */
511

512
513
  g_object_class_install_property (o_class,
                                   PROP_MODEL,
Tim Janik's avatar
Tim Janik committed
514
515
516
517
518
                                   g_param_spec_object ("model",
							_("TreeView Model"),
							_("The model for the tree view"),
							GTK_TYPE_TREE_MODEL,
							G_PARAM_READWRITE));
Jonathan Blandford's avatar
Jonathan Blandford committed
519

520
521
522
523
  g_object_class_install_property (o_class,
                                   PROP_HADJUSTMENT,
                                   g_param_spec_object ("hadjustment",
							_("Horizontal Adjustment"),
Jonathan Blandford's avatar
Jonathan Blandford committed
524
                                                        _("Horizontal Adjustment for the widget"),
525
526
527
528
529
530
531
                                                        GTK_TYPE_ADJUSTMENT,
                                                        G_PARAM_READWRITE));

  g_object_class_install_property (o_class,
                                   PROP_VADJUSTMENT,
                                   g_param_spec_object ("vadjustment",
							_("Vertical Adjustment"),
Jonathan Blandford's avatar
Jonathan Blandford committed
532
                                                        _("Vertical Adjustment for the widget"),
533
534
535
536
537
538
539
                                                        GTK_TYPE_ADJUSTMENT,
                                                        G_PARAM_READWRITE));

  g_object_class_install_property (o_class,
                                   PROP_HEADERS_VISIBLE,
                                   g_param_spec_boolean ("headers_visible",
							 _("Visible"),
Jonathan Blandford's avatar
Jonathan Blandford committed
540
							 _("Show the column header buttons"),
541
							 TRUE,
542
543
544
545
546
547
							 G_PARAM_READWRITE));

  g_object_class_install_property (o_class,
                                   PROP_HEADERS_CLICKABLE,
                                   g_param_spec_boolean ("headers_clickable",
							 _("Headers Clickable"),
Jonathan Blandford's avatar
Jonathan Blandford committed
548
							 _("Column headers respond to click events"),
549
							 FALSE,
550
							 G_PARAM_WRITABLE));
551
552
553

  g_object_class_install_property (o_class,
                                   PROP_EXPANDER_COLUMN,
554
555
556
557
558
                                   g_param_spec_object ("expander_column",
							_("Expander Column"),
							_("Set the column for the expander column"),
							GTK_TYPE_TREE_VIEW_COLUMN,
							G_PARAM_READWRITE));
559

560
561
562
563
564
565
566
567
  g_object_class_install_property (o_class,
                                   PROP_REORDERABLE,
                                   g_param_spec_boolean ("reorderable",
							 _("Reorderable"),
							 _("View is reorderable"),
							 FALSE,
							 G_PARAM_READWRITE));

568
569
570
571
  g_object_class_install_property (o_class,
                                   PROP_RULES_HINT,
                                   g_param_spec_boolean ("rules_hint",
							 _("Rules Hint"),
Jonathan Blandford's avatar
Jonathan Blandford committed
572
							 _("Set a hint to the theme engine to draw rows in alternating colors"),
573
574
575
							 FALSE,
							 G_PARAM_READWRITE));

576
577
578
579
580
581
582
    g_object_class_install_property (o_class,
				     PROP_ENABLE_SEARCH,
				     g_param_spec_boolean ("enable_search",
							   _("Enable Search"),
							   _("View allows user to search through columns interactively"),
							   TRUE,
							   G_PARAM_READWRITE));
583

584
585
586
587
588
589
590
591
592
    g_object_class_install_property (o_class,
				     PROP_SEARCH_COLUMN,
				     g_param_spec_int ("search_column",
						       _("Search Column"),
						       _("Model column to search through when searching through code"),
						       -1,
						       G_MAXINT,
						       0,
						       G_PARAM_READWRITE));
593

594
  /* Style properties */
595
#define _TREE_VIEW_EXPANDER_SIZE 10
596
#define _TREE_VIEW_VERTICAL_SEPARATOR 2
597
#define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
598
    
599
  gtk_widget_class_install_style_property (widget_class,
600
601
					   g_param_spec_int ("expander_size",
							     _("Expander Size"),
602
							     _("Size of the expander arrow."),
603
604
							     0,
							     G_MAXINT,
605
							     _TREE_VIEW_EXPANDER_SIZE,
606
							     G_PARAM_READABLE));
607

608
609
610
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("vertical_separator",
							     _("Vertical Separator Width"),
611
							     _("Vertical space between cells.  Must be an even number."),
612
613
614
615
							     0,
							     G_MAXINT,
							     _TREE_VIEW_VERTICAL_SEPARATOR,
							     G_PARAM_READABLE));
616

617
  gtk_widget_class_install_style_property (widget_class,
618
619
					   g_param_spec_int ("horizontal_separator",
							     _("Horizontal Separator Width"),
620
							     _("Horizontal space between cells.  Must be an even number."),
621
622
623
624
625
							     0,
							     G_MAXINT,
							     _TREE_VIEW_HORIZONTAL_SEPARATOR,
							     G_PARAM_READABLE));

626
627
628
629
630
631
632
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_boolean ("allow_rules",
								 _("Allow Rules"),
								 _("Allow drawing of alternating color rows."),
								 TRUE,
								 G_PARAM_READABLE));

633
634
635
636
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_boolean ("indent_expanders",
								 _("Indent Expanders"),
								 _("Make the expanders indented."),
637
								 TRUE,
638
								 G_PARAM_READABLE));
639
  /* Signals */
640
641
642
643
644
  widget_class->set_scroll_adjustments_signal =
    gtk_signal_new ("set_scroll_adjustments",
		    GTK_RUN_LAST,
		    GTK_CLASS_TYPE (object_class),
		    GTK_SIGNAL_OFFSET (GtkTreeViewClass, set_scroll_adjustments),
645
		    _gtk_marshal_VOID__OBJECT_OBJECT,
646
		    GTK_TYPE_NONE, 2,
647
		    GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
648

649
650
651
652
653
  tree_view_signals[ROW_ACTIVATED] =
    gtk_signal_new ("row_activated",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    GTK_CLASS_TYPE (object_class),
		    GTK_SIGNAL_OFFSET (GtkTreeViewClass, row_activated),
654
		    _gtk_marshal_VOID__BOXED_OBJECT,
655
656
657
		    GTK_TYPE_NONE, 2,
		    GTK_TYPE_TREE_PATH,
		    GTK_TYPE_TREE_VIEW_COLUMN);
658

659
  tree_view_signals[TEST_EXPAND_ROW] =
660
661
662
663
664
    g_signal_new ("test_expand_row",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, test_expand_row),
                  _gtk_boolean_handled_accumulator, NULL,
665
                  _gtk_marshal_BOOLEAN__BOXED_BOXED,
666
667
668
                  G_TYPE_BOOLEAN, 2,
                  GTK_TYPE_TREE_ITER,
                  GTK_TYPE_TREE_PATH);
669

670
  tree_view_signals[TEST_COLLAPSE_ROW] =
671
672
673
674
675
    g_signal_new ("test_collapse_row",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, test_collapse_row),
                  _gtk_boolean_handled_accumulator, NULL,
676
                  _gtk_marshal_BOOLEAN__BOXED_BOXED,
677
678
679
                  G_TYPE_BOOLEAN, 2,
                  GTK_TYPE_TREE_ITER,
                  GTK_TYPE_TREE_PATH);
680

681
  tree_view_signals[ROW_EXPANDED] =
682
683
684
685
686
    g_signal_new ("row_expanded",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, row_expanded),
                  NULL, NULL,
687
                  _gtk_marshal_VOID__BOXED_BOXED,
688
689
690
                  GTK_TYPE_NONE, 2,
                  GTK_TYPE_TREE_ITER,
                  GTK_TYPE_TREE_PATH);
691
692

  tree_view_signals[ROW_COLLAPSED] =
693
694
695
696
697
    g_signal_new ("row_collapsed",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, row_collapsed),
                  NULL, NULL,
698
                  _gtk_marshal_VOID__BOXED_BOXED,
699
700
701
                  GTK_TYPE_NONE, 2,
                  GTK_TYPE_TREE_ITER,
                  GTK_TYPE_TREE_PATH);
702

703
  tree_view_signals[COLUMNS_CHANGED] =
704
705
706
707
708
    g_signal_new ("columns_changed",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, columns_changed),
                  NULL, NULL,
709
                  _gtk_marshal_NONE__NONE,
710
                  G_TYPE_NONE, 0);
711

712
713
714
715
716
717
  tree_view_signals[CURSOR_CHANGED] =
    g_signal_new ("cursor_changed",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkTreeViewClass, cursor_changed),
                  NULL, NULL,
718
                  _gtk_marshal_NONE__NONE,
719
720
                  G_TYPE_NONE, 0);

721
  tree_view_signals[MOVE_CURSOR] =
722
723
724
725
726
    g_signal_new ("move_cursor",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, move_cursor),
                  NULL, NULL,
727
728
                  _gtk_marshal_BOOLEAN__ENUM_INT,
                  GTK_TYPE_BOOL, 2, GTK_TYPE_MOVEMENT_STEP, GTK_TYPE_INT);
729

730
731
732
733
734
735
  tree_view_signals[SELECT_ALL] =
    g_signal_new ("select_all",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, select_all),
                  NULL, NULL,
736
                  _gtk_marshal_NONE__NONE,
737
738
                  GTK_TYPE_NONE, 0);

739
740
741
742
743
744
745
746
747
  tree_view_signals[UNSELECT_ALL] =
    g_signal_new ("unselect_all",
		  G_TYPE_FROM_CLASS (object_class),
		  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
		  G_STRUCT_OFFSET (GtkTreeViewClass, unselect_all),
		  NULL, NULL,
		  _gtk_marshal_NONE__NONE,
		  GTK_TYPE_NONE, 0);

748
  tree_view_signals[SELECT_CURSOR_ROW] =
749
750
751
752
753
    g_signal_new ("select_cursor_row",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, select_cursor_row),
                  NULL, NULL,
754
                  _gtk_marshal_VOID__BOOLEAN,
755
756
                  GTK_TYPE_NONE, 1,
		  G_TYPE_BOOLEAN);
757

758
  tree_view_signals[TOGGLE_CURSOR_ROW] =
759
760
761
762
763
    g_signal_new ("toggle_cursor_row",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, toggle_cursor_row),
                  NULL, NULL,
764
                  _gtk_marshal_NONE__NONE,
765
                  GTK_TYPE_NONE, 0);
766

767
  tree_view_signals[EXPAND_COLLAPSE_CURSOR_ROW] =
768
769
770
771
772
    g_signal_new ("expand_collapse_cursor_row",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, expand_collapse_cursor_row),
                  NULL, NULL,
773
                  _gtk_marshal_VOID__BOOLEAN_BOOLEAN_BOOLEAN,
774
                  GTK_TYPE_NONE, 3, GTK_TYPE_BOOL, GTK_TYPE_BOOL, GTK_TYPE_BOOL);
775

776
  tree_view_signals[SELECT_CURSOR_PARENT] =
777
778
779
780
781
    g_signal_new ("select_cursor_parent",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, select_cursor_parent),
                  NULL, NULL,
782
                  _gtk_marshal_NONE__NONE,
783
                  GTK_TYPE_NONE, 0);
784

785
786
787
788
789
790
  tree_view_signals[START_INTERACTIVE_SEARCH] =
    g_signal_new ("start_interactive_search",
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
                  G_STRUCT_OFFSET (GtkTreeViewClass, start_interactive_search),
                  NULL, NULL,
791
                  _gtk_marshal_NONE__NONE,
792
793
                  GTK_TYPE_NONE, 0);

794
  /* Key bindings */
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
  gtk_tree_view_add_move_binding (binding_set, GDK_Up, 0,
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

  gtk_tree_view_add_move_binding (binding_set, GDK_Down, 0,
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

  gtk_tree_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

  gtk_tree_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

  gtk_tree_view_add_move_binding (binding_set, GDK_Home, 0,
				  GTK_MOVEMENT_BUFFER_ENDS, -1);

  gtk_tree_view_add_move_binding (binding_set, GDK_End, 0,
				  GTK_MOVEMENT_BUFFER_ENDS, 1);

  gtk_tree_view_add_move_binding (binding_set, GDK_Page_Up, 0,
				  GTK_MOVEMENT_PAGES, -1);

  gtk_tree_view_add_move_binding (binding_set, GDK_Page_Down, 0,
				  GTK_MOVEMENT_PAGES, 1);
818

819
820
821
  gtk_binding_entry_add_signal (binding_set, GDK_Right, 0, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, 1);
822

823
824
825
  gtk_binding_entry_add_signal (binding_set, GDK_Left, 0, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, -1);
826

827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
  gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_CONTROL_MASK, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_CONTROL_MASK, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, -1);

  gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_CONTROL_MASK|GDK_SHIFT_MASK, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, 1);

  gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_CONTROL_MASK|GDK_SHIFT_MASK, "move_cursor", 2,
				GTK_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
				GTK_TYPE_INT, -1);

843
844
  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle_cursor_row", 0);

845
  gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select_all", 0);
846
847
848
849
  gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, "select_all", 0);

  gtk_binding_entry_add_signal (binding_set, GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect_all", 0);
  gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK, "unselect_all", 0);
850

851
852
853
854
855
  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_SHIFT_MASK, "select_cursor_row", 1,
				GTK_TYPE_BOOL, TRUE);

  gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "select_cursor_row", 1,
				GTK_TYPE_BOOL, TRUE);
856

857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
  /* expand and collapse rows */
  gtk_binding_entry_add_signal (binding_set, GDK_plus, 0, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, FALSE);
  /* Not doable on US keyboards */
  gtk_binding_entry_add_signal (binding_set, GDK_plus, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Add, 0, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, FALSE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Add, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Add, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, TRUE,
				GTK_TYPE_BOOL, TRUE);

  gtk_binding_entry_add_signal (binding_set, GDK_minus, 0, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE);
  gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Subtract, 0, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Subtract, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_SHIFT_MASK, "expand_collapse_cursor_row", 3,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, FALSE,
				GTK_TYPE_BOOL, TRUE);

  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "select_cursor_parent", 0);

907
  gtk_binding_entry_add_signal (binding_set, GDK_f, GDK_CONTROL_MASK, "start_interactive_search", 0);
908

909
  gtk_binding_entry_add_signal (binding_set, GDK_F, GDK_CONTROL_MASK, "start_interactive_search", 0);
910
911
912
913
914
915
916
917
918
}

static void
gtk_tree_view_init (GtkTreeView *tree_view)
{
  tree_view->priv = g_new0 (GtkTreeViewPrivate, 1);
  GTK_WIDGET_SET_FLAGS (tree_view, GTK_CAN_FOCUS);

  tree_view->priv->flags = GTK_TREE_VIEW_IS_LIST | GTK_TREE_VIEW_SHOW_EXPANDERS | GTK_TREE_VIEW_DRAW_KEYFOCUS | GTK_TREE_VIEW_HEADERS_VISIBLE;
919
920

  /* We need some padding */
921
  tree_view->priv->dy = 0;
922
  tree_view->priv->n_columns = 0;
923
924
925
  tree_view->priv->header_height = 1;
  tree_view->priv->x_drag = 0;
  tree_view->priv->drag_pos = -1;
926
  tree_view->priv->header_has_focus = FALSE;
Havoc Pennington's avatar
Havoc Pennington committed
927
928
929
  tree_view->priv->pressed_button = -1;
  tree_view->priv->press_start_x = -1;
  tree_view->priv->press_start_y = -1;
930
  tree_view->priv->reorderable = FALSE;
Jonathan Blandford's avatar
Jonathan Blandford committed
931
  tree_view->priv->presize_handler_timer = 0;
932
933
  tree_view->priv->scroll_sync_timer = 0;
  tree_view->priv->fixed_height_check = 0;
934
  gtk_tree_view_set_adjustments (tree_view, NULL, NULL);
935
  tree_view->priv->selection = _gtk_tree_selection_new_with_tree_view (tree_view);
936
937
938
939
  tree_view->priv->enable_search = TRUE;
  tree_view->priv->search_column = -1;
  tree_view->priv->search_dialog_position_func = gtk_tree_view_search_position_func;
  tree_view->priv->search_equal_func = gtk_tree_view_search_equal_func;
940
941
}

942

943

944
/* GObject Methods
945
946
 */

947
948
949
950
951
952
953
954
955
956
957
958
959
static void
gtk_tree_view_set_property (GObject         *object,
			    guint            prop_id,
			    const GValue    *value,
			    GParamSpec      *pspec)
{
  GtkTreeView *tree_view;

  tree_view = GTK_TREE_VIEW (object);

  switch (prop_id)
    {
    case PROP_MODEL:
Tim Janik's avatar
Tim Janik committed
960
      gtk_tree_view_set_model (tree_view, g_value_get_object (value));
961
962
      break;
    case PROP_HADJUSTMENT:
Tim Janik's avatar
Tim Janik committed
963
      gtk_tree_view_set_hadjustment (tree_view, g_value_get_object (value));
964
965
      break;
    case PROP_VADJUSTMENT:
Tim Janik's avatar
Tim Janik committed
966
      gtk_tree_view_set_vadjustment (tree_view, g_value_get_object (value));
967
968
969
970
971
972
973
974
      break;
    case PROP_HEADERS_VISIBLE:
      gtk_tree_view_set_headers_visible (tree_view, g_value_get_boolean (value));
      break;
    case PROP_HEADERS_CLICKABLE:
      gtk_tree_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
      break;
    case PROP_EXPANDER_COLUMN:
Tim Janik's avatar
Tim Janik committed
975
      gtk_tree_view_set_expander_column (tree_view, g_value_get_object (value));
976
      break;
977
978
979
    case PROP_REORDERABLE:
      gtk_tree_view_set_reorderable (tree_view, g_value_get_boolean (value));
      break;
980
981
    case PROP_RULES_HINT:
      gtk_tree_view_set_rules_hint (tree_view, g_value_get_boolean (value));
982
      break;
983
984
985
986
987
    case PROP_ENABLE_SEARCH:
      gtk_tree_view_set_enable_search (tree_view, g_value_get_boolean (value));
      break;
    case PROP_SEARCH_COLUMN:
      gtk_tree_view_set_search_column (tree_view, g_value_get_int (value));
988
989
990
991
992
993
994
      break;
    default:
      break;
    }
}

static void
Jonathan Blandford's avatar
Jonathan Blandford committed
995
996
997
998
gtk_tree_view_get_property (GObject    *object,
			    guint       prop_id,
			    GValue     *value,
			    GParamSpec *pspec)
999
1000
1001
1002
1003
1004
1005
1006
{
  GtkTreeView *tree_view;

  tree_view = GTK_TREE_VIEW (object);

  switch (prop_id)
    {
    case PROP_MODEL:
1007
      g_value_set_object (value, tree_view->priv->model);
1008
1009
      break;
    case PROP_HADJUSTMENT:
1010
      g_value_set_object (value, tree_view->priv->hadjustment);
1011
1012
      break;
    case PROP_VADJUSTMENT:
1013
      g_value_set_object (value, tree_view->priv->vadjustment);
1014
1015
1016
1017
1018
      break;
    case PROP_HEADERS_VISIBLE:
      g_value_set_boolean (value, gtk_tree_view_get_headers_visible (tree_view));
      break;
    case PROP_EXPANDER_COLUMN:
1019
      g_value_set_object (value, tree_view->priv->expander_column);
1020
      break;
1021
1022
1023
    case PROP_REORDERABLE:
      g_value_set_boolean (value, tree_view->priv->reorderable);
      break;
1024
1025
1026
    case PROP_RULES_HINT:
      g_value_set_boolean (value, tree_view->priv->has_rules);
      break;
1027
1028
1029
1030
1031
1032
    case PROP_ENABLE_SEARCH:
      g_value_set_boolean (value, tree_view->priv->enable_search);
      break;
    case PROP_SEARCH_COLUMN:
      g_value_set_int (value, tree_view->priv->search_column);
      break;
1033
1034
1035
1036
1037
1038
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

1039
1040
1041
1042
1043
1044
static void
gtk_tree_view_finalize (GObject *object)
{
  GtkTreeView *tree_view = (GtkTreeView *) object;

  g_free (tree_view->priv);
1045

1046
1047
1048
1049
  if (G_OBJECT_CLASS (parent_class)->finalize)
    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
}

1050
1051
1052
1053
1054


/* GtkObject Methods
 */

Jonathan Blandford's avatar
Jonathan Blandford committed
1055
1056
1057
static void
gtk_tree_view_destroy (GtkObject *object)
{
Tim Janik's avatar
Tim Janik committed
1058
  GtkTreeView *tree_view = GTK_TREE_VIEW (object);
1059
  GtkWidget *search_dialog;
Jonathan Blandford's avatar
Jonathan Blandford committed
1060
1061
  GList *list;

Jonathan Blandford's avatar
Jonathan Blandford committed
1062
  gtk_tree_view_stop_editing (tree_view, TRUE);
1063
1064

  if (tree_view->priv->columns != NULL)
Jonathan Blandford's avatar
Jonathan Blandford committed
1065
    {
Jonathan Blandford's avatar
Jonathan Blandford committed
1066
1067
1068
1069
1070
1071
1072
1073
      list = tree_view->priv->columns;
      while (list)
	{
	  GtkTreeViewColumn *column;
	  column = GTK_TREE_VIEW_COLUMN (list->data);
	  list = list->next;
	  gtk_tree_view_remove_column (tree_view, column);
	}
Jonathan Blandford's avatar
Jonathan Blandford committed
1074
1075
1076
      tree_view->priv->columns = NULL;
    }

1077
1078
  if (tree_view->priv->tree != NULL)
    {
1079
      gtk_tree_view_unref_and_check_selection_tree (tree_view, tree_view->priv->tree);
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
      _gtk_rbtree_free (tree_view->priv->tree);
      tree_view->priv->tree = NULL;
    }

  if (tree_view->priv->selection != NULL)
    {
      _gtk_tree_selection_set_tree_view (tree_view->priv->selection, NULL);
      g_object_unref (tree_view->priv->selection);
      tree_view->priv->selection = NULL;
    }
Jonathan Blandford's avatar
Jonathan Blandford committed
1090

1091
1092
  if (tree_view->priv->scroll_to_path != NULL)
    {
1093
      gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1094
1095
1096
1097
1098
1099
1100
1101
1102
      tree_view->priv->scroll_to_path = NULL;
    }

  if (tree_view->priv->drag_dest_row != NULL)
    {
      gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
      tree_view->priv->drag_dest_row = NULL;
    }

1103
  if (tree_view->priv->last_button_press != NULL)
1104
    {
1105
1106
      gtk_tree_row_reference_free (tree_view->priv->last_button_press);
      tree_view->priv->last_button_press = NULL;
1107
1108
    }

1109
  if (tree_view->priv->last_button_press_2 != NULL)
1110
    {
1111
1112
      gtk_tree_row_reference_free (tree_view->priv->last_button_press_2);
      tree_view->priv->last_button_press_2 = NULL;
1113
1114
    }

1115
1116
1117
1118
1119
  if (tree_view->priv->top_row != NULL)
    {
      gtk_tree_row_reference_free (tree_view->priv->top_row);
      tree_view->priv->top_row = NULL;
    }
1120

1121
1122
1123
1124
1125
1126
1127
  if (tree_view->priv->column_drop_func_data &&
      tree_view->priv->column_drop_func_data_destroy)
    {
      (* tree_view->priv->column_drop_func_data_destroy) (tree_view->priv->column_drop_func_data);
      tree_view->priv->column_drop_func_data = NULL;
    }

1128
1129
1130
1131
1132
1133
1134
  if (tree_view->priv->destroy_count_destroy &&
      tree_view->priv->destroy_count_data)
    {
      (* tree_view->priv->destroy_count_destroy) (tree_view->priv->destroy_count_data);
      tree_view->priv->destroy_count_data = NULL;
    }

1135
1136
1137
1138
1139
1140
  gtk_tree_row_reference_free (tree_view->priv->cursor);
  tree_view->priv->cursor = NULL;

  gtk_tree_row_reference_free (tree_view->priv->anchor);
  tree_view->priv->anchor = NULL;

1141
  /* destroy interactive search dialog */
1142
1143
  search_dialog = gtk_object_get_data (GTK_OBJECT (tree_view),
				       GTK_TREE_VIEW_SEARCH_DIALOG_KEY);
1144
1145
  if (search_dialog)
    gtk_tree_view_search_dialog_destroy (search_dialog,
1146
					 tree_view);
1147

Jonathan Blandford's avatar
Jonathan Blandford committed
1148
1149
1150
1151
1152
  if (tree_view->priv->search_user_data)
    {
      (* tree_view->priv->search_destroy) (tree_view->priv->search_user_data);
      tree_view->priv->search_user_data = NULL;
    }
1153
1154
1155

  gtk_tree_view_set_model (tree_view, NULL);

1156
1157
  if (GTK_OBJECT_CLASS (parent_class)->destroy)
    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
Jonathan Blandford's avatar
Jonathan Blandford committed
1158
1159
}

1160
1161
1162


/* GtkWidget Methods
1163
1164
 */

1165
/* GtkWidget::map helper */
1166
static void
1167
gtk_tree_view_map_buttons (GtkTreeView *tree_view)
1168
{
1169
  GList *list;
1170

1171
  g_return_if_fail (GTK_WIDGET_MAPPED (tree_view));
1172

1173
  if (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE))
1174
    {
1175
1176
1177
1178
1179
1180
1181
1182