gtkiconview.c 250 KB
Newer Older
Matthias Clasen's avatar
Matthias Clasen committed
1
/* gtkiconview.c
2
 * Copyright (C) 2002, 2004  Anders Carlsson <andersca@gnu.org>
Anders Carlsson's avatar
Anders Carlsson committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * 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.
 */

20
#include <config.h>
Anders Carlsson's avatar
Anders Carlsson committed
21 22
#include <string.h>

23 24
#include <atk/atk.h>

25
#include <gdk/gdkkeysyms.h>
26

27
#include "gtkiconview.h"
Matthias Clasen's avatar
Matthias Clasen committed
28 29 30 31
#include "gtkcelllayout.h"
#include "gtkcellrenderer.h"
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
32 33 34 35 36 37
#include "gtkmarshalers.h"
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkmain.h"
#include "gtksignal.h"
#include "gtkintl.h"
38 39
#include "gtkaccessible.h"
#include "gtkwindow.h"
Matthias Clasen's avatar
Matthias Clasen committed
40 41
#include "gtkentry.h"
#include "gtkcombobox.h"
42
#include "gtktextbuffer.h"
Matthias Clasen's avatar
Matthias Clasen committed
43
#include "gtktreednd.h"
44
#include "gtkprivate.h"
45
#include "gtkalias.h"
Anders Carlsson's avatar
Anders Carlsson committed
46

47
#undef DEBUG_ICON_VIEW
48

Matthias Clasen's avatar
Matthias Clasen committed
49 50
#define SCROLL_EDGE_SIZE 15

51
#define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
Anders Carlsson's avatar
Anders Carlsson committed
52

Matthias Clasen's avatar
Matthias Clasen committed
53 54
typedef struct _GtkIconViewItem GtkIconViewItem;
struct _GtkIconViewItem
Anders Carlsson's avatar
Anders Carlsson committed
55
{
56
  GtkTreeIter iter;
Matthias Clasen's avatar
Matthias Clasen committed
57
  gint index;
Anders Carlsson's avatar
Anders Carlsson committed
58
  
Matthias Clasen's avatar
Matthias Clasen committed
59 60
  gint row, col;

Matthias Clasen's avatar
Matthias Clasen committed
61 62
  /* Bounding box */
  gint x, y, width, height;
Anders Carlsson's avatar
Anders Carlsson committed
63

Matthias Clasen's avatar
Matthias Clasen committed
64 65 66 67 68 69 70 71 72 73
  /* Individual cells.
   * box[i] is the actual area occupied by cell i,
   * before, after are used to calculate the cell 
   * area relative to the box. 
   * See gtk_icon_view_get_cell_area().
   */
  gint n_cells;
  GdkRectangle *box;
  gint *before;
  gint *after;
Anders Carlsson's avatar
Anders Carlsson committed
74 75 76

  guint selected : 1;
  guint selected_before_rubberbanding : 1;
77

Matthias Clasen's avatar
Matthias Clasen committed
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
};

typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
struct _GtkIconViewCellInfo
{
  GtkCellRenderer *cell;

  guint expand : 1;
  guint pack : 1;
  guint editing : 1;

  gint position;

  GSList *attributes;

  GtkCellLayoutDataFunc func;
  gpointer func_data;
  GDestroyNotify destroy;
};

typedef struct _GtkIconViewChild GtkIconViewChild;
struct _GtkIconViewChild
{
  GtkWidget *widget;
  GtkIconViewItem *item;
  gint cell;
};
Anders Carlsson's avatar
Anders Carlsson committed
105

106
struct _GtkIconViewPrivate
Anders Carlsson's avatar
Anders Carlsson committed
107 108 109 110 111 112 113
{
  gint width, height;

  GtkSelectionMode selection_mode;

  GdkWindow *bin_window;

Matthias Clasen's avatar
Matthias Clasen committed
114 115
  GList *children;

116 117
  GtkTreeModel *model;
  
Anders Carlsson's avatar
Anders Carlsson committed
118 119 120 121 122 123 124
  GList *items;
  
  GtkAdjustment *hadjustment;
  GtkAdjustment *vadjustment;

  guint layout_idle_id;
  
125
  gboolean doing_rubberband;
Anders Carlsson's avatar
Anders Carlsson committed
126 127
  gint rubberband_x1, rubberband_y1;
  gint rubberband_x2, rubberband_y2;
128 129 130 131 132

  guint scroll_timeout_id;
  gint scroll_value_diff;
  gint event_last_x, event_last_y;

133 134
  GtkIconViewItem *anchor_item;
  GtkIconViewItem *cursor_item;
Matthias Clasen's avatar
Matthias Clasen committed
135 136
  GtkIconViewItem *edited_item;
  GtkCellEditable *editable;
Matthias Clasen's avatar
Matthias Clasen committed
137

138
  GtkIconViewItem *last_single_clicked;
Anders Carlsson's avatar
Anders Carlsson committed
139

Matthias Clasen's avatar
Matthias Clasen committed
140 141 142 143 144
  GList *cell_list;
  guint n_cells;

  gint cursor_cell;

145
  GtkOrientation orientation;
Matthias Clasen's avatar
Matthias Clasen committed
146 147 148 149 150 151 152

  gint columns;
  gint item_width;
  gint spacing;
  gint row_spacing;
  gint column_spacing;
  gint margin;
Matthias Clasen's avatar
Matthias Clasen committed
153 154 155 156 157 158 159

  gint text_column;
  gint markup_column;
  gint pixbuf_column;

  gint pixbuf_cell;
  gint text_cell;
Matthias Clasen's avatar
Matthias Clasen committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

  /* Drag-and-drop. */
  GdkModifierType start_button_mask;
  gint pressed_button;
  gint press_start_x;
  gint press_start_y;

  GtkTargetList *source_targets;
  GdkDragAction source_actions;

  GtkTargetList *dest_targets;
  GdkDragAction dest_actions;

  GtkTreeRowReference *dest_item;
  GtkIconViewDropPosition dest_pos;

176 177 178 179 180 181
  /* scroll to */
  GtkTreeRowReference *scroll_to_path;
  gfloat scroll_to_row_align;
  gfloat scroll_to_col_align;
  guint scroll_to_use_align : 1;

Matthias Clasen's avatar
Matthias Clasen committed
182 183 184 185 186 187 188
  guint source_set : 1;
  guint dest_set : 1;
  guint reorderable : 1;
  guint empty_view_drop :1;

  guint ctrl_pressed : 1;
  guint shift_pressed : 1;  
Anders Carlsson's avatar
Anders Carlsson committed
189 190 191 192 193 194 195 196 197 198 199 200
};

/* Signals */
enum
{
  ITEM_ACTIVATED,
  SELECTION_CHANGED,
  SELECT_ALL,
  UNSELECT_ALL,
  SELECT_CURSOR_ITEM,
  TOGGLE_CURSOR_ITEM,
  MOVE_CURSOR,
201
  ACTIVATE_CURSOR_ITEM,
Anders Carlsson's avatar
Anders Carlsson committed
202 203 204 205 206 207 208
  LAST_SIGNAL
};

/* Properties */
enum
{
  PROP_0,
209 210
  PROP_PIXBUF_COLUMN,
  PROP_TEXT_COLUMN,
Anders Carlsson's avatar
Anders Carlsson committed
211
  PROP_MARKUP_COLUMN,  
Anders Carlsson's avatar
Anders Carlsson committed
212
  PROP_SELECTION_MODE,
213
  PROP_ORIENTATION,
214
  PROP_MODEL,
Matthias Clasen's avatar
Matthias Clasen committed
215 216 217 218 219
  PROP_COLUMNS,
  PROP_ITEM_WIDTH,
  PROP_SPACING,
  PROP_ROW_SPACING,
  PROP_COLUMN_SPACING,
Matthias Clasen's avatar
Matthias Clasen committed
220 221
  PROP_MARGIN,
  PROP_REORDERABLE
Anders Carlsson's avatar
Anders Carlsson committed
222 223
};

Matthias Clasen's avatar
Matthias Clasen committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
/* GObject vfuncs */
static void             gtk_icon_view_cell_layout_init          (GtkCellLayoutIface *iface);
static void             gtk_icon_view_finalize                  (GObject            *object);
static void             gtk_icon_view_set_property              (GObject            *object,
								 guint               prop_id,
								 const GValue       *value,
								 GParamSpec         *pspec);
static void             gtk_icon_view_get_property              (GObject            *object,
								 guint               prop_id,
								 GValue             *value,
								 GParamSpec         *pspec);

/* GtkObject vfuncs */
static void             gtk_icon_view_destroy                   (GtkObject          *object);

/* GtkWidget vfuncs */
static void             gtk_icon_view_realize                   (GtkWidget          *widget);
static void             gtk_icon_view_unrealize                 (GtkWidget          *widget);
static void             gtk_icon_view_size_request              (GtkWidget          *widget,
								 GtkRequisition     *requisition);
static void             gtk_icon_view_size_allocate             (GtkWidget          *widget,
								 GtkAllocation      *allocation);
static gboolean         gtk_icon_view_expose                    (GtkWidget          *widget,
								 GdkEventExpose     *expose);
static gboolean         gtk_icon_view_motion                    (GtkWidget          *widget,
								 GdkEventMotion     *event);
static gboolean         gtk_icon_view_button_press              (GtkWidget          *widget,
								 GdkEventButton     *event);
static gboolean         gtk_icon_view_button_release            (GtkWidget          *widget,
								 GdkEventButton     *event);
static AtkObject       *gtk_icon_view_get_accessible            (GtkWidget          *widget);


/* GtkContainer vfuncs */
static void             gtk_icon_view_remove                    (GtkContainer       *container,
								 GtkWidget          *widget);
static void             gtk_icon_view_forall                    (GtkContainer       *container,
								 gboolean            include_internals,
								 GtkCallback         callback,
								 gpointer            callback_data);

/* GtkIconView vfuncs */
static void             gtk_icon_view_set_adjustments           (GtkIconView        *icon_view,
								 GtkAdjustment      *hadj,
								 GtkAdjustment      *vadj);
static void             gtk_icon_view_real_select_all           (GtkIconView        *icon_view);
static void             gtk_icon_view_real_unselect_all         (GtkIconView        *icon_view);
static void             gtk_icon_view_real_select_cursor_item   (GtkIconView        *icon_view);
static void             gtk_icon_view_real_toggle_cursor_item   (GtkIconView        *icon_view);
static gboolean         gtk_icon_view_real_activate_cursor_item (GtkIconView        *icon_view);

 /* Internal functions */
static void                 gtk_icon_view_adjustment_changed             (GtkAdjustment          *adjustment,
									  GtkIconView            *icon_view);
static void                 gtk_icon_view_layout                         (GtkIconView            *icon_view);
static void                 gtk_icon_view_paint_item                     (GtkIconView            *icon_view,
									  cairo_t *cr,

									  GtkIconViewItem        *item,
Matthias Clasen's avatar
Matthias Clasen committed
283 284 285 286 287
									  GdkRectangle           *area,
									  GdkDrawable *drawable,
									  gint         x,
									  gint         y,
									  gboolean     draw_focus);
Matthias Clasen's avatar
Matthias Clasen committed
288 289 290
static void                 gtk_icon_view_paint_rubberband               (GtkIconView            *icon_view,
								          cairo_t *cr,
									  GdkRectangle           *area);
Matthias Clasen's avatar
Matthias Clasen committed
291 292
static void                 gtk_icon_view_queue_draw_path                (GtkIconView *icon_view,
									  GtkTreePath *path);
Matthias Clasen's avatar
Matthias Clasen committed
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
static void                 gtk_icon_view_queue_draw_item                (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static void                 gtk_icon_view_queue_layout                   (GtkIconView            *icon_view);
static void                 gtk_icon_view_set_cursor_item                (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  gint                    cursor_cell);
static void                 gtk_icon_view_start_rubberbanding            (GtkIconView            *icon_view,
									  gint                    x,
									  gint                    y);
static void                 gtk_icon_view_stop_rubberbanding             (GtkIconView            *icon_view);
static void                 gtk_icon_view_update_rubberband_selection    (GtkIconView            *icon_view);
static gboolean             gtk_icon_view_item_hit_test                  (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  gint                    x,
									  gint                    y,
									  gint                    width,
									  gint                    height);
static gboolean             gtk_icon_view_unselect_all_internal          (GtkIconView            *icon_view);
static void                 gtk_icon_view_calculate_item_size            (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static void                 gtk_icon_view_calculate_item_size2           (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  gint                   *max_height);
static void                 gtk_icon_view_update_rubberband              (gpointer                data);
static void                 gtk_icon_view_item_invalidate_size           (GtkIconViewItem        *item);
static void                 gtk_icon_view_invalidate_sizes               (GtkIconView            *icon_view);
static void                 gtk_icon_view_add_move_binding               (GtkBindingSet          *binding_set,
									  guint                   keyval,
									  guint                   modmask,
									  GtkMovementStep         step,
									  gint                    count);
static gboolean             gtk_icon_view_real_move_cursor               (GtkIconView            *icon_view,
									  GtkMovementStep         step,
									  gint                    count);
static void                 gtk_icon_view_move_cursor_up_down            (GtkIconView            *icon_view,
									  gint                    count);
static void                 gtk_icon_view_move_cursor_page_up_down       (GtkIconView            *icon_view,
									  gint                    count);
static void                 gtk_icon_view_move_cursor_left_right         (GtkIconView            *icon_view,
									  gint                    count);
static void                 gtk_icon_view_move_cursor_start_end          (GtkIconView            *icon_view,
									  gint                    count);
static void                 gtk_icon_view_scroll_to_item                 (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static void                 gtk_icon_view_select_item                    (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static void                 gtk_icon_view_unselect_item                  (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static gboolean             gtk_icon_view_select_all_between             (GtkIconView            *icon_view,
									  GtkIconViewItem        *anchor,
									  GtkIconViewItem        *cursor);
static GtkIconViewItem *    gtk_icon_view_get_item_at_coords             (GtkIconView            *icon_view,
									  gint                    x,
									  gint                    y,
Matthias Clasen's avatar
Matthias Clasen committed
347
									  gboolean                only_in_cell,
Matthias Clasen's avatar
Matthias Clasen committed
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
									  GtkIconViewCellInfo   **cell_at_pos);
static void                 gtk_icon_view_get_cell_area                  (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  GtkIconViewCellInfo    *cell_info,
									  GdkRectangle           *cell_area);
static void                 gtk_icon_view_get_cell_box                   (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  GtkIconViewCellInfo    *info,
									  GdkRectangle           *box);
static GtkIconViewCellInfo *gtk_icon_view_get_cell_info                  (GtkIconView            *icon_view,
									  GtkCellRenderer        *renderer);
static void                 gtk_icon_view_set_cell_data                  (GtkIconView            *icon_view,
									  GtkIconViewItem        *item);
static void                 gtk_icon_view_cell_layout_pack_start         (GtkCellLayout          *layout,
									  GtkCellRenderer        *renderer,
									  gboolean                expand);
static void                 gtk_icon_view_cell_layout_pack_end           (GtkCellLayout          *layout,
									  GtkCellRenderer        *renderer,
									  gboolean                expand);
static void                 gtk_icon_view_cell_layout_add_attribute      (GtkCellLayout          *layout,
									  GtkCellRenderer        *renderer,
									  const gchar            *attribute,
									  gint                    column);
static void                 gtk_icon_view_cell_layout_clear              (GtkCellLayout          *layout);
static void                 gtk_icon_view_cell_layout_clear_attributes   (GtkCellLayout          *layout,
									  GtkCellRenderer        *renderer);
static void                 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout          *layout,
									  GtkCellRenderer        *cell,
									  GtkCellLayoutDataFunc   func,
									  gpointer                func_data,
									  GDestroyNotify          destroy);
static void                 gtk_icon_view_cell_layout_reorder            (GtkCellLayout          *layout,
									  GtkCellRenderer        *cell,
									  gint                    position);
static void                 gtk_icon_view_item_activate_cell             (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  GtkIconViewCellInfo    *cell_info,
									  GdkEvent               *event);
static void                 gtk_icon_view_put                            (GtkIconView            *icon_view,
									  GtkWidget              *widget,
									  GtkIconViewItem        *item,
									  gint                    cell);
static void                 gtk_icon_view_remove_widget                  (GtkCellEditable        *editable,
									  GtkIconView            *icon_view);
static void                 gtk_icon_view_start_editing                  (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  GtkIconViewCellInfo    *cell_info,
									  GdkEvent               *event);
static void                 gtk_icon_view_stop_editing                   (GtkIconView            *icon_view,
									  gboolean                cancel_editing);
398

Matthias Clasen's avatar
Matthias Clasen committed
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
/* Source side drag signals */
static void gtk_icon_view_drag_begin       (GtkWidget        *widget,
                                            GdkDragContext   *context);
static void gtk_icon_view_drag_end         (GtkWidget        *widget,
                                            GdkDragContext   *context);
static void gtk_icon_view_drag_data_get    (GtkWidget        *widget,
                                            GdkDragContext   *context,
                                            GtkSelectionData *selection_data,
                                            guint             info,
                                            guint             time);
static void gtk_icon_view_drag_data_delete (GtkWidget        *widget,
                                            GdkDragContext   *context);

/* Target side drag signals */
static void     gtk_icon_view_drag_leave         (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  guint             time);
static gboolean gtk_icon_view_drag_motion        (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  guint             time);
static gboolean gtk_icon_view_drag_drop          (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  guint             time);
static void     gtk_icon_view_drag_data_received (GtkWidget        *widget,
                                                  GdkDragContext   *context,
                                                  gint              x,
                                                  gint              y,
                                                  GtkSelectionData *selection_data,
                                                  guint             info,
                                                  guint             time);
static gboolean gtk_icon_view_maybe_begin_drag   (GtkIconView             *icon_view,
					   	  GdkEventMotion          *event);

static void     remove_scroll_timeout            (GtkIconView *icon_view);


439
static guint icon_view_signals[LAST_SIGNAL] = { 0 };
Anders Carlsson's avatar
Anders Carlsson committed
440

Matthias Clasen's avatar
Matthias Clasen committed
441 442
G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
Matthias Clasen's avatar
Matthias Clasen committed
443
						gtk_icon_view_cell_layout_init))
Anders Carlsson's avatar
Anders Carlsson committed
444 445

static void
446
gtk_icon_view_class_init (GtkIconViewClass *klass)
Anders Carlsson's avatar
Anders Carlsson committed
447 448
{
  GObjectClass *gobject_class;
449
  GtkObjectClass *object_class;
Anders Carlsson's avatar
Anders Carlsson committed
450
  GtkWidgetClass *widget_class;
Matthias Clasen's avatar
Matthias Clasen committed
451
  GtkContainerClass *container_class;
Anders Carlsson's avatar
Anders Carlsson committed
452 453 454
  GtkBindingSet *binding_set;
  
  binding_set = gtk_binding_set_by_class (klass);
455

456
  g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
457

Anders Carlsson's avatar
Anders Carlsson committed
458
  gobject_class = (GObjectClass *) klass;
459
  object_class = (GtkObjectClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
460
  widget_class = (GtkWidgetClass *) klass;
Matthias Clasen's avatar
Matthias Clasen committed
461
  container_class = (GtkContainerClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
462

463 464 465 466 467 468 469 470 471 472 473 474 475 476
  gobject_class->finalize = gtk_icon_view_finalize;
  gobject_class->set_property = gtk_icon_view_set_property;
  gobject_class->get_property = gtk_icon_view_get_property;

  object_class->destroy = gtk_icon_view_destroy;
  
  widget_class->realize = gtk_icon_view_realize;
  widget_class->unrealize = gtk_icon_view_unrealize;
  widget_class->size_request = gtk_icon_view_size_request;
  widget_class->size_allocate = gtk_icon_view_size_allocate;
  widget_class->expose_event = gtk_icon_view_expose;
  widget_class->motion_notify_event = gtk_icon_view_motion;
  widget_class->button_press_event = gtk_icon_view_button_press;
  widget_class->button_release_event = gtk_icon_view_button_release;
Matthias Clasen's avatar
Matthias Clasen committed
477 478 479 480 481 482 483 484
  widget_class->drag_begin = gtk_icon_view_drag_begin;
  widget_class->drag_end = gtk_icon_view_drag_end;
  widget_class->drag_data_get = gtk_icon_view_drag_data_get;
  widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
  widget_class->drag_leave = gtk_icon_view_drag_leave;
  widget_class->drag_motion = gtk_icon_view_drag_motion;
  widget_class->drag_drop = gtk_icon_view_drag_drop;
  widget_class->drag_data_received = gtk_icon_view_drag_data_received;
485
  widget_class->get_accessible = gtk_icon_view_get_accessible;
486

Matthias Clasen's avatar
Matthias Clasen committed
487 488 489
  container_class->remove = gtk_icon_view_remove;
  container_class->forall = gtk_icon_view_forall;

490 491 492 493 494
  klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
  klass->select_all = gtk_icon_view_real_select_all;
  klass->unselect_all = gtk_icon_view_real_unselect_all;
  klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
  klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
495
  klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;  
496
  klass->move_cursor = gtk_icon_view_real_move_cursor;
Anders Carlsson's avatar
Anders Carlsson committed
497 498
  
  /* Properties */
Matthias Clasen's avatar
Matthias Clasen committed
499 500 501 502 503 504 505 506 507
  /**
   * GtkIconView:selection-mode:
   * 
   * The ::selection-mode property specifies the selection mode of
   * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
   * is enabled, for the other modes, only keyboard selection is possible.
   *
   * Since: 2.6
   */
Anders Carlsson's avatar
Anders Carlsson committed
508 509
  g_object_class_install_property (gobject_class,
				   PROP_SELECTION_MODE,
510
				   g_param_spec_enum ("selection-mode",
511 512
						      P_("Selection mode"),
						      P_("The selection mode"),
Anders Carlsson's avatar
Anders Carlsson committed
513 514
						      GTK_TYPE_SELECTION_MODE,
						      GTK_SELECTION_SINGLE,
515
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
516

Matthias Clasen's avatar
Matthias Clasen committed
517 518 519 520 521 522 523 524 525 526
  /**
   * GtkIconView:pixbuf-column:
   *
   * The ::pixbuf-column property contains the number of the model column
   * containing the pixbufs which are displayed. The pixbuf column must be 
   * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
   * display of pixbufs.
   *
   * Since: 2.6
   */
Anders Carlsson's avatar
Anders Carlsson committed
527
  g_object_class_install_property (gobject_class,
528
				   PROP_PIXBUF_COLUMN,
529
				   g_param_spec_int ("pixbuf-column",
530 531
						     P_("Pixbuf column"),
						     P_("Model column used to retrieve the icon pixbuf from"),
532
						     -1, G_MAXINT, -1,
533
						     GTK_PARAM_READWRITE));
534

Matthias Clasen's avatar
Matthias Clasen committed
535 536 537 538 539 540 541 542 543 544
  /**
   * GtkIconView:text-column:
   *
   * The ::text-column property contains the number of the model column
   * containing the texts which are displayed. The text column must be 
   * of type #G_TYPE_STRING. If this property and the :markup-column 
   * property are both set to -1, no texts are displayed.   
   *
   * Since: 2.6
   */
Anders Carlsson's avatar
Anders Carlsson committed
545
  g_object_class_install_property (gobject_class,
546
				   PROP_TEXT_COLUMN,
547
				   g_param_spec_int ("text-column",
548 549
						     P_("Text column"),
						     P_("Model column used to retrieve the text from"),
550
						     -1, G_MAXINT, -1,
551
						     GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
552

Matthias Clasen's avatar
Matthias Clasen committed
553 554 555 556 557 558 559 560 561 562 563 564
  
  /**
   * GtkIconView:markup-column:
   *
   * The ::markup-column property contains the number of the model column
   * containing markup information to be displayed. The markup column must be 
   * of type #G_TYPE_STRING. If this property and the :text-column property 
   * are both set to column numbers, it overrides the text column.
   * If both are set to -1, no texts are displayed.   
   *
   * Since: 2.6
   */
Anders Carlsson's avatar
Anders Carlsson committed
565 566
  g_object_class_install_property (gobject_class,
				   PROP_MARKUP_COLUMN,
567
				   g_param_spec_int ("markup-column",
568
						     P_("Markup column"),
Matthias Clasen's avatar
Matthias Clasen committed
569
						     P_("Model column used to retrieve the text if using Pango markup"),
Anders Carlsson's avatar
Anders Carlsson committed
570
						     -1, G_MAXINT, -1,
571
						     GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
572
  
573 574 575
  g_object_class_install_property (gobject_class,
                                   PROP_MODEL,
                                   g_param_spec_object ("model",
Matthias Clasen's avatar
Matthias Clasen committed
576 577
							P_("Icon View Model"),
							P_("The model for the icon view"),
578
							GTK_TYPE_TREE_MODEL,
579
							GTK_PARAM_READWRITE));
580
  
Matthias Clasen's avatar
Matthias Clasen committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
  /**
   * GtkIconView:columns:
   *
   * The columns property contains the number of the columns in which the
   * items should be displayed. If it is -1, the number of columns will
   * be chosen automatically to fill the available area.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
				   PROP_COLUMNS,
				   g_param_spec_int ("columns",
						     P_("Number of columns"),
						     P_("Number of columns to display"),
						     -1, G_MAXINT, -1,
596
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
597 598 599 600 601 602 603 604 605 606 607 608 609
  

  /**
   * GtkIconView::item-width:
   *
   * The item-width property specifies the width to use for each item. 
   * If it is set to -1, the icon view will automatically determine a 
   * suitable item size.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
				   PROP_ITEM_WIDTH,
610
				   g_param_spec_int ("item-width",
Matthias Clasen's avatar
Matthias Clasen committed
611 612 613
						     P_("Width for each item"),
						     P_("The width used for each item"),
						     -1, G_MAXINT, -1,
614
						     GTK_PARAM_READWRITE));  
Matthias Clasen's avatar
Matthias Clasen committed
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

  /**
   * GtkIconView::spacing:
   *
   * The spacing property specifies the space which is inserted between
   * the cells (i.e. the icon and the text) of an item.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
                                   PROP_SPACING,
                                   g_param_spec_int ("spacing",
						     P_("Spacing"),
						     P_("Space which is inserted between cells of an item"),
						     0, G_MAXINT, 0,
630
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
631 632 633 634 635 636 637 638 639 640 641

  /**
   * GtkIconView::row-spacing:
   *
   * The row-spacing property specifies the space which is inserted between
   * the rows of the icon view.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ROW_SPACING,
642
                                   g_param_spec_int ("row-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
643 644 645
						     P_("Row Spacing"),
						     P_("Space which is inserted between grid rows"),
						     0, G_MAXINT, 6,
646
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
647 648 649 650 651 652 653 654 655 656 657

  /**
   * GtkIconView::column-spacing:
   *
   * The column-spacing property specifies the space which is inserted between
   * the columns of the icon view.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
                                   PROP_COLUMN_SPACING,
658
                                   g_param_spec_int ("column-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
659
						     P_("Column Spacing"),
660
						     P_("Space which is inserted between grid columns"),
Matthias Clasen's avatar
Matthias Clasen committed
661
						     0, G_MAXINT, 6,
662
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677

  /**
   * GtkIconView::margin:
   *
   * The margin property specifies the space which is inserted 
   * at the edges of the icon view.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
                                   PROP_MARGIN,
                                   g_param_spec_int ("margin",
						     P_("Margin"),
						     P_("Space which is inserted at the edges of the icon view"),
						     0, G_MAXINT, 6,
678
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
679 680 681 682 683 684 685 686 687 688


  /**
   * GtkIconView::orientation:
   *
   * The orientation property specifies how the cells (i.e. the icon and 
   * the text) of the item are positioned relative to each other.
   *
   * Since: 2.6
   */
689 690 691 692 693 694 695
  g_object_class_install_property (gobject_class,
				   PROP_ORIENTATION,
				   g_param_spec_enum ("orientation",
						      P_("Orientation"),
						      P_("How the text and icon of each item are positioned relative to each other"),
						      GTK_TYPE_ORIENTATION,
						      GTK_ORIENTATION_VERTICAL,
696
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
697

Matthias Clasen's avatar
Matthias Clasen committed
698
  /**
699
   * GtkIconView:reorderable:
Matthias Clasen's avatar
Matthias Clasen committed
700 701 702 703 704 705 706 707 708 709 710 711 712 713
   *
   * The reorderable property specifies if the items can be reordered
   * by DND.
   *
   * Since: 2.8
   */
  g_object_class_install_property (gobject_class,
                                   PROP_REORDERABLE,
                                   g_param_spec_boolean ("reorderable",
							 P_("Reorderable"),
							 P_("View is reorderable"),
							 FALSE,
							 G_PARAM_READWRITE));

714
  /* Style properties */
715
  gtk_widget_class_install_style_property (widget_class,
716
                                           g_param_spec_boxed ("selection-box-color",
717 718
                                                               P_("Selection Box Color"),
                                                               P_("Color of the selection box"),
719
                                                               GDK_TYPE_COLOR,
720
                                                               GTK_PARAM_READABLE));
721 722

  gtk_widget_class_install_style_property (widget_class,
723
                                           g_param_spec_uchar ("selection-box-alpha",
724 725
                                                               P_("Selection Box Alpha"),
                                                               P_("Opacity of the selection box"),
726 727
                                                               0, 0xff,
                                                               0x40,
728
                                                               GTK_PARAM_READABLE));
729

Anders Carlsson's avatar
Anders Carlsson committed
730 731
  /* Signals */
  widget_class->set_scroll_adjustments_signal =
Matthias Clasen's avatar
Matthias Clasen committed
732
    g_signal_new (I_("set_scroll_adjustments"),
Anders Carlsson's avatar
Anders Carlsson committed
733 734
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
735
		  G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
Anders Carlsson's avatar
Anders Carlsson committed
736
		  NULL, NULL, 
737
		  _gtk_marshal_VOID__OBJECT_OBJECT,
Anders Carlsson's avatar
Anders Carlsson committed
738 739 740
		  G_TYPE_NONE, 2,
		  GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);

741
  icon_view_signals[ITEM_ACTIVATED] =
Matthias Clasen's avatar
Matthias Clasen committed
742
    g_signal_new (I_("item_activated"),
Anders Carlsson's avatar
Anders Carlsson committed
743 744
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
745
		  G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
Anders Carlsson's avatar
Anders Carlsson committed
746
		  NULL, NULL,
Anders Carlsson's avatar
Anders Carlsson committed
747
		  g_cclosure_marshal_VOID__BOXED,
Anders Carlsson's avatar
Anders Carlsson committed
748
		  G_TYPE_NONE, 1,
749
		  GTK_TYPE_TREE_PATH);
Anders Carlsson's avatar
Anders Carlsson committed
750

751
  icon_view_signals[SELECTION_CHANGED] =
Matthias Clasen's avatar
Matthias Clasen committed
752
    g_signal_new (I_("selection_changed"),
Anders Carlsson's avatar
Anders Carlsson committed
753 754
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_FIRST,
755
		  G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
Anders Carlsson's avatar
Anders Carlsson committed
756 757 758 759
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
760
  icon_view_signals[SELECT_ALL] =
Matthias Clasen's avatar
Matthias Clasen committed
761
    g_signal_new (I_("select_all"),
Anders Carlsson's avatar
Anders Carlsson committed
762 763
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
764
		  G_STRUCT_OFFSET (GtkIconViewClass, select_all),
Anders Carlsson's avatar
Anders Carlsson committed
765 766 767 768
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
769
  icon_view_signals[UNSELECT_ALL] =
Matthias Clasen's avatar
Matthias Clasen committed
770
    g_signal_new (I_("unselect_all"),
Anders Carlsson's avatar
Anders Carlsson committed
771 772
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
773
		  G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
Anders Carlsson's avatar
Anders Carlsson committed
774 775 776 777
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

778
  icon_view_signals[SELECT_CURSOR_ITEM] =
Matthias Clasen's avatar
Matthias Clasen committed
779
    g_signal_new (I_("select_cursor_item"),
Anders Carlsson's avatar
Anders Carlsson committed
780 781
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782
		  G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
783 784 785 786
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

787
  icon_view_signals[TOGGLE_CURSOR_ITEM] =
Matthias Clasen's avatar
Matthias Clasen committed
788
    g_signal_new (I_("toggle_cursor_item"),
Anders Carlsson's avatar
Anders Carlsson committed
789 790
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
791
		  G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
792 793 794 795
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

796
  icon_view_signals[ACTIVATE_CURSOR_ITEM] =
Matthias Clasen's avatar
Matthias Clasen committed
797
    g_signal_new (I_("activate_cursor_item"),
798 799 800 801 802 803 804
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
		  NULL, NULL,
		  _gtk_marshal_BOOLEAN__VOID,
		  G_TYPE_BOOLEAN, 0);
  
805
  icon_view_signals[MOVE_CURSOR] =
Matthias Clasen's avatar
Matthias Clasen committed
806
    g_signal_new (I_("move_cursor"),
Matthias Clasen's avatar
Matthias Clasen committed
807 808
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
809
		  G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
Matthias Clasen's avatar
Matthias Clasen committed
810
		  NULL, NULL,
811
		  _gtk_marshal_BOOLEAN__ENUM_INT,
Matthias Clasen's avatar
Matthias Clasen committed
812 813 814 815
		  G_TYPE_BOOLEAN, 2,
		  GTK_TYPE_MOVEMENT_STEP,
		  G_TYPE_INT);

Anders Carlsson's avatar
Anders Carlsson committed
816
  /* Key bindings */
Matthias Clasen's avatar
Matthias Clasen committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
  gtk_binding_entry_add_signal (binding_set, GDK_a, 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_space, GDK_CONTROL_MASK, 
				"toggle_cursor_item", 0);

  gtk_binding_entry_add_signal (binding_set, GDK_space, 0, 
				"activate_cursor_item", 0);
  gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, 
				"activate_cursor_item", 0);
  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, 
				"activate_cursor_item", 0);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, 
				"activate_cursor_item", 0);
832

833
  gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
834
				  GTK_MOVEMENT_DISPLAY_LINES, -1);
835
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
836 837
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

838
  gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
839
				  GTK_MOVEMENT_DISPLAY_LINES, 1);
840
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
841 842
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

843
  gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
844 845
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

846
  gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
847 848
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

849
  gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
850
				  GTK_MOVEMENT_BUFFER_ENDS, -1);
851
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
852 853
				  GTK_MOVEMENT_BUFFER_ENDS, -1);

854
  gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
855
				  GTK_MOVEMENT_BUFFER_ENDS, 1);
856
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
857 858
				  GTK_MOVEMENT_BUFFER_ENDS, 1);

859
  gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
860
				  GTK_MOVEMENT_PAGES, -1);
861
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
862 863
				  GTK_MOVEMENT_PAGES, -1);

864
  gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
865
				  GTK_MOVEMENT_PAGES, 1);
866
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
867 868
				  GTK_MOVEMENT_PAGES, 1);

869
  gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
870
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
871
  gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
872 873
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);

874
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
875
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
876
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
877 878
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);
}
Anders Carlsson's avatar
Anders Carlsson committed
879

Matthias Clasen's avatar
Matthias Clasen committed
880 881 882 883 884 885 886 887 888 889 890 891
static void
gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
{
  iface->pack_start = gtk_icon_view_cell_layout_pack_start;
  iface->pack_end = gtk_icon_view_cell_layout_pack_end;
  iface->clear = gtk_icon_view_cell_layout_clear;
  iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
  iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
  iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
  iface->reorder = gtk_icon_view_cell_layout_reorder;
}

Anders Carlsson's avatar
Anders Carlsson committed
892
static void
893
gtk_icon_view_init (GtkIconView *icon_view)
Anders Carlsson's avatar
Anders Carlsson committed
894
{
895
  icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
896
  
897 898 899 900 901 902 903 904 905
  icon_view->priv->width = 0;
  icon_view->priv->height = 0;
  icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
  icon_view->priv->pressed_button = -1;
  icon_view->priv->press_start_x = -1;
  icon_view->priv->press_start_y = -1;
  icon_view->priv->text_column = -1;
  icon_view->priv->markup_column = -1;  
  icon_view->priv->pixbuf_column = -1;
Matthias Clasen's avatar
Matthias Clasen committed
906 907
  icon_view->priv->text_cell = -1;
  icon_view->priv->pixbuf_cell = -1;  
908

909
  GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
Anders Carlsson's avatar
Anders Carlsson committed
910
  
911
  gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
912

Matthias Clasen's avatar
Matthias Clasen committed
913 914 915 916
  icon_view->priv->cell_list = NULL;
  icon_view->priv->n_cells = 0;
  icon_view->priv->cursor_cell = -1;

917
  icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
Matthias Clasen's avatar
Matthias Clasen committed
918 919 920 921 922 923 924

  icon_view->priv->columns = -1;
  icon_view->priv->item_width = -1;
  icon_view->priv->spacing = 0;
  icon_view->priv->row_spacing = 6;
  icon_view->priv->column_spacing = 6;
  icon_view->priv->margin = 6;
Anders Carlsson's avatar
Anders Carlsson committed
925 926 927
}

static void
928
gtk_icon_view_destroy (GtkObject *object)
Anders Carlsson's avatar
Anders Carlsson committed
929
{
930
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
931

932
  icon_view = GTK_ICON_VIEW (object);
933
  
Matthias Clasen's avatar
Matthias Clasen committed
934 935
  gtk_icon_view_stop_editing (icon_view, TRUE);

936
  gtk_icon_view_set_model (icon_view, NULL);
937
  
938
  if (icon_view->priv->layout_idle_id != 0)
939 940 941 942 943 944 945 946 947 948
    {
      g_source_remove (icon_view->priv->layout_idle_id);
      icon_view->priv->layout_idle_id = 0;
    }

  if (icon_view->priv->scroll_to_path != NULL)
    {
      gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
      icon_view->priv->scroll_to_path = NULL;
    }
Anders Carlsson's avatar
Anders Carlsson committed
949

Matthias Clasen's avatar
Matthias Clasen committed
950
  remove_scroll_timeout (icon_view);
951
  
Matthias Clasen's avatar
Matthias Clasen committed
952
  (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
953 954 955 956
}

/* GObject methods */
static void
957
gtk_icon_view_finalize (GObject *object)
958
{
Matthias Clasen's avatar
Matthias Clasen committed
959
  gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
960

Matthias Clasen's avatar
Matthias Clasen committed
961
  (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
Anders Carlsson's avatar
Anders Carlsson committed
962 963 964 965
}


static void
966
gtk_icon_view_set_property (GObject      *object,
Anders Carlsson's avatar
Anders Carlsson committed
967 968 969 970
			    guint         prop_id,
			    const GValue *value,
			    GParamSpec   *pspec)
{
971
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
972

973
  icon_view = GTK_ICON_VIEW (object);
Anders Carlsson's avatar
Anders Carlsson committed
974 975 976 977

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
978
      gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
Anders Carlsson's avatar
Anders Carlsson committed
979
      break;
980
    case PROP_PIXBUF_COLUMN:
981
      gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
982 983
      break;
    case PROP_TEXT_COLUMN:
984
      gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
Anders Carlsson's avatar
Anders Carlsson committed
985
      break;
Anders Carlsson's avatar
Anders Carlsson committed
986
    case PROP_MARKUP_COLUMN:
987
      gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
Anders Carlsson's avatar
Anders Carlsson committed
988
      break;
989
    case PROP_MODEL:
990
      gtk_icon_view_set_model (icon_view, g_value_get_object (value));
Anders Carlsson's avatar
Anders Carlsson committed
991
      break;
992 993 994
    case PROP_ORIENTATION:
      gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
      break;
Matthias Clasen's avatar
Matthias Clasen committed
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
    case PROP_COLUMNS:
      gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
      break;
    case PROP_ITEM_WIDTH:
      gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
      break;
    case PROP_SPACING:
      gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
      break;
    case PROP_ROW_SPACING:
      gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
      break;
    case PROP_COLUMN_SPACING:
      gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
      break;
    case PROP_MARGIN:
      gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1013 1014 1015
    case PROP_REORDERABLE:
      gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
      break;
1016
      
Anders Carlsson's avatar
Anders Carlsson committed
1017 1018 1019 1020 1021 1022 1023
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
1024
gtk_icon_view_get_property (GObject      *object,
Anders Carlsson's avatar
Anders Carlsson committed
1025 1026 1027 1028
			    guint         prop_id,
			    GValue       *value,
			    GParamSpec   *pspec)
{
1029
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1030

1031
  icon_view = GTK_ICON_VIEW (object);
Anders Carlsson's avatar
Anders Carlsson committed
1032 1033 1034 1035

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
1036
      g_value_set_enum (value, icon_view->priv->selection_mode);
Anders Carlsson's avatar
Anders Carlsson committed
1037
      break;
1038
    case PROP_PIXBUF_COLUMN:
1039
      g_value_set_int (value, icon_view->priv->pixbuf_column);
1040