gtkiconview.c 282 KB
Newer Older
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
#include "gtkmarshalers.h"
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkmain.h"
#include "gtkintl.h"
37 38
#include "gtkaccessible.h"
#include "gtkwindow.h"
Matthias Clasen's avatar
Matthias Clasen committed
39 40
#include "gtkentry.h"
#include "gtkcombobox.h"
41
#include "gtktextbuffer.h"
42
#include "gtksizerequest.h"
Matthias Clasen's avatar
Matthias Clasen committed
43
#include "gtktreednd.h"
44
#include "gtkprivate.h"
Anders Carlsson's avatar
Anders Carlsson committed
45

46 47 48 49 50 51 52 53 54 55 56 57 58
/**
 * SECTION:gtkiconview
 * @title: GtkIconView
 * @short_description: A widget which displays a list of icons in a grid
 *
 * #GtkIconView provides an alternative view on a list model.
 * It displays the model as a grid of icons with labels. Like
 * #GtkTreeView, it allows to select one or multiple items
 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
 * In addition to selection with the arrow keys, #GtkIconView supports
 * rubberband selection, which is controlled by dragging the pointer.
 */

Matthias Clasen's avatar
Matthias Clasen committed
59 60
#define SCROLL_EDGE_SIZE 15

Matthias Clasen's avatar
Matthias Clasen committed
61 62
typedef struct _GtkIconViewItem GtkIconViewItem;
struct _GtkIconViewItem
Anders Carlsson's avatar
Anders Carlsson committed
63
{
64
  GtkTreeIter iter;
Matthias Clasen's avatar
Matthias Clasen committed
65
  gint index;
Anders Carlsson's avatar
Anders Carlsson committed
66
  
Matthias Clasen's avatar
Matthias Clasen committed
67 68
  gint row, col;

Matthias Clasen's avatar
Matthias Clasen committed
69 70
  /* Bounding box */
  gint x, y, width, height;
Anders Carlsson's avatar
Anders Carlsson committed
71

Matthias Clasen's avatar
Matthias Clasen committed
72 73 74 75 76 77 78 79 80 81
  /* 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
82 83 84

  guint selected : 1;
  guint selected_before_rubberbanding : 1;
85

Matthias Clasen's avatar
Matthias Clasen committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
};

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
113

114
struct _GtkIconViewPrivate
Anders Carlsson's avatar
Anders Carlsson committed
115 116 117 118 119 120 121
{
  gint width, height;

  GtkSelectionMode selection_mode;

  GdkWindow *bin_window;

Matthias Clasen's avatar
Matthias Clasen committed
122 123
  GList *children;

124 125
  GtkTreeModel *model;
  
Anders Carlsson's avatar
Anders Carlsson committed
126 127 128 129 130 131 132
  GList *items;
  
  GtkAdjustment *hadjustment;
  GtkAdjustment *vadjustment;

  guint layout_idle_id;
  
133
  gboolean doing_rubberband;
Anders Carlsson's avatar
Anders Carlsson committed
134 135
  gint rubberband_x1, rubberband_y1;
  gint rubberband_x2, rubberband_y2;
136
  GdkDevice *rubberband_device;
137 138 139 140 141

  guint scroll_timeout_id;
  gint scroll_value_diff;
  gint event_last_x, event_last_y;

142 143
  GtkIconViewItem *anchor_item;
  GtkIconViewItem *cursor_item;
Matthias Clasen's avatar
Matthias Clasen committed
144 145
  GtkIconViewItem *edited_item;
  GtkCellEditable *editable;
Matthias Clasen's avatar
Matthias Clasen committed
146

147
  GtkIconViewItem *last_single_clicked;
Anders Carlsson's avatar
Anders Carlsson committed
148

Matthias Clasen's avatar
Matthias Clasen committed
149 150 151 152 153
  GList *cell_list;
  guint n_cells;

  gint cursor_cell;

154
  GtkOrientation item_orientation;
Matthias Clasen's avatar
Matthias Clasen committed
155 156 157 158 159 160 161

  gint columns;
  gint item_width;
  gint spacing;
  gint row_spacing;
  gint column_spacing;
  gint margin;
162
  gint item_padding;
Matthias Clasen's avatar
Matthias Clasen committed
163 164 165 166 167 168 169

  gint text_column;
  gint markup_column;
  gint pixbuf_column;

  gint pixbuf_cell;
  gint text_cell;
Matthias Clasen's avatar
Matthias Clasen committed
170

171 172
  gint tooltip_column;

Matthias Clasen's avatar
Matthias Clasen committed
173 174 175 176 177 178 179 180 181 182 183 184
  /* Drag-and-drop. */
  GdkModifierType start_button_mask;
  gint pressed_button;
  gint press_start_x;
  gint press_start_y;

  GdkDragAction source_actions;
  GdkDragAction dest_actions;

  GtkTreeRowReference *dest_item;
  GtkIconViewDropPosition dest_pos;

185 186 187 188 189 190
  /* 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
191 192 193 194 195 196
  guint source_set : 1;
  guint dest_set : 1;
  guint reorderable : 1;
  guint empty_view_drop :1;

  guint ctrl_pressed : 1;
197 198 199
  guint shift_pressed : 1;

  guint draw_focus : 1;
Anders Carlsson's avatar
Anders Carlsson committed
200 201 202 203 204 205 206 207 208 209 210 211
};

/* Signals */
enum
{
  ITEM_ACTIVATED,
  SELECTION_CHANGED,
  SELECT_ALL,
  UNSELECT_ALL,
  SELECT_CURSOR_ITEM,
  TOGGLE_CURSOR_ITEM,
  MOVE_CURSOR,
212
  ACTIVATE_CURSOR_ITEM,
Anders Carlsson's avatar
Anders Carlsson committed
213 214 215 216 217 218 219
  LAST_SIGNAL
};

/* Properties */
enum
{
  PROP_0,
220 221
  PROP_PIXBUF_COLUMN,
  PROP_TEXT_COLUMN,
222
  PROP_MARKUP_COLUMN,
Anders Carlsson's avatar
Anders Carlsson committed
223
  PROP_SELECTION_MODE,
224
  PROP_ITEM_ORIENTATION,
225
  PROP_MODEL,
Matthias Clasen's avatar
Matthias Clasen committed
226 227 228 229 230
  PROP_COLUMNS,
  PROP_ITEM_WIDTH,
  PROP_SPACING,
  PROP_ROW_SPACING,
  PROP_COLUMN_SPACING,
Matthias Clasen's avatar
Matthias Clasen committed
231
  PROP_MARGIN,
232
  PROP_REORDERABLE,
233 234
  PROP_TOOLTIP_COLUMN,
  PROP_ITEM_PADDING
Anders Carlsson's avatar
Anders Carlsson committed
235 236
};

Matthias Clasen's avatar
Matthias Clasen committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
/* 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);
255 256 257 258
static void             gtk_icon_view_style_set                 (GtkWidget        *widget,
						                 GtkStyle         *previous_style);
static void             gtk_icon_view_state_changed             (GtkWidget        *widget,
			                                         GtkStateType      previous_state);
Matthias Clasen's avatar
Matthias Clasen committed
259 260 261 262
static void             gtk_icon_view_size_request              (GtkWidget          *widget,
								 GtkRequisition     *requisition);
static void             gtk_icon_view_size_allocate             (GtkWidget          *widget,
								 GtkAllocation      *allocation);
Benjamin Otte's avatar
Benjamin Otte committed
263 264
static gboolean         gtk_icon_view_draw                      (GtkWidget          *widget,
                                                                 cairo_t            *cr);
Matthias Clasen's avatar
Matthias Clasen committed
265 266 267 268 269 270
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);
271 272 273 274
static gboolean         gtk_icon_view_key_press                 (GtkWidget          *widget,
								 GdkEventKey        *event);
static gboolean         gtk_icon_view_key_release               (GtkWidget          *widget,
								 GdkEventKey        *event);
Matthias Clasen's avatar
Matthias Clasen committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
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,
301
									  cairo_t                *cr,
Matthias Clasen's avatar
Matthias Clasen committed
302
									  GtkIconViewItem        *item,
303 304 305
									  gint                    x,
									  gint                    y,
									  gboolean                draw_focus);
Matthias Clasen's avatar
Matthias Clasen committed
306
static void                 gtk_icon_view_paint_rubberband               (GtkIconView            *icon_view,
307
								          cairo_t                *cr);
Matthias Clasen's avatar
Matthias Clasen committed
308 309
static void                 gtk_icon_view_queue_draw_path                (GtkIconView *icon_view,
									  GtkTreePath *path);
Matthias Clasen's avatar
Matthias Clasen committed
310 311 312 313 314 315 316
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,
317
                                                                          GdkDevice              *device,
Matthias Clasen's avatar
Matthias Clasen committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
									  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
365
									  gboolean                only_in_cell,
Matthias Clasen's avatar
Matthias Clasen committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
									  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);
400 401
static GList *              gtk_icon_view_cell_layout_get_cells          (GtkCellLayout          *layout);

Matthias Clasen's avatar
Matthias Clasen committed
402 403 404 405
static void                 gtk_icon_view_item_activate_cell             (GtkIconView            *icon_view,
									  GtkIconViewItem        *item,
									  GtkIconViewCellInfo    *cell_info,
									  GdkEvent               *event);
406 407
static void                 gtk_icon_view_item_selected_changed          (GtkIconView            *icon_view,
		                                                          GtkIconViewItem        *item);
Matthias Clasen's avatar
Matthias Clasen committed
408 409 410 411 412 413 414 415 416 417 418 419
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);
420

Matthias Clasen's avatar
Matthias Clasen committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
/* 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);

460 461
static void     adjust_wrap_width                (GtkIconView     *icon_view,
						  GtkIconViewItem *item);
Matthias Clasen's avatar
Matthias Clasen committed
462

Johan Dahlin's avatar
Johan Dahlin committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
/* GtkBuildable */
static GtkBuildableIface *parent_buildable_iface;
static void     gtk_icon_view_buildable_init             (GtkBuildableIface *iface);
static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable  *buildable,
							  GtkBuilder    *builder,
							  GObject       *child,
							  const gchar   *tagname,
							  GMarkupParser *parser,
							  gpointer      *data);
static void     gtk_icon_view_buildable_custom_tag_end   (GtkBuildable  *buildable,
							  GtkBuilder    *builder,
							  GObject       *child,
							  const gchar   *tagname,
							  gpointer      *data);

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

Matthias Clasen's avatar
Matthias Clasen committed
480 481
G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
Johan Dahlin's avatar
Johan Dahlin committed
482 483 484
						gtk_icon_view_cell_layout_init)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
						gtk_icon_view_buildable_init))
Anders Carlsson's avatar
Anders Carlsson committed
485 486

static void
487
gtk_icon_view_class_init (GtkIconViewClass *klass)
Anders Carlsson's avatar
Anders Carlsson committed
488 489
{
  GObjectClass *gobject_class;
490
  GtkObjectClass *object_class;
Anders Carlsson's avatar
Anders Carlsson committed
491
  GtkWidgetClass *widget_class;
Matthias Clasen's avatar
Matthias Clasen committed
492
  GtkContainerClass *container_class;
Anders Carlsson's avatar
Anders Carlsson committed
493 494 495
  GtkBindingSet *binding_set;
  
  binding_set = gtk_binding_set_by_class (klass);
496

497
  g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
498

Anders Carlsson's avatar
Anders Carlsson committed
499
  gobject_class = (GObjectClass *) klass;
500
  object_class = (GtkObjectClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
501
  widget_class = (GtkWidgetClass *) klass;
Matthias Clasen's avatar
Matthias Clasen committed
502
  container_class = (GtkContainerClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
503

504 505 506 507 508 509 510 511
  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;
512 513
  widget_class->style_set = gtk_icon_view_style_set;
  widget_class->get_accessible = gtk_icon_view_get_accessible;
514 515
  widget_class->size_request = gtk_icon_view_size_request;
  widget_class->size_allocate = gtk_icon_view_size_allocate;
Benjamin Otte's avatar
Benjamin Otte committed
516
  widget_class->draw = gtk_icon_view_draw;
517 518 519
  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;
520 521
  widget_class->key_press_event = gtk_icon_view_key_press;
  widget_class->key_release_event = gtk_icon_view_key_release;
Matthias Clasen's avatar
Matthias Clasen committed
522 523 524 525 526 527 528 529
  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;
530
  widget_class->state_changed = gtk_icon_view_state_changed;
531

Matthias Clasen's avatar
Matthias Clasen committed
532 533 534
  container_class->remove = gtk_icon_view_remove;
  container_class->forall = gtk_icon_view_forall;

535 536 537 538 539
  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;
540
  klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;  
541
  klass->move_cursor = gtk_icon_view_real_move_cursor;
Anders Carlsson's avatar
Anders Carlsson committed
542 543
  
  /* Properties */
544 545 546 547 548 549 550 551 552
  /**
   * 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
553 554
  g_object_class_install_property (gobject_class,
				   PROP_SELECTION_MODE,
555
				   g_param_spec_enum ("selection-mode",
556 557
						      P_("Selection mode"),
						      P_("The selection mode"),
Anders Carlsson's avatar
Anders Carlsson committed
558 559
						      GTK_TYPE_SELECTION_MODE,
						      GTK_SELECTION_SINGLE,
560
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
561

562 563 564 565 566 567 568 569 570 571
  /**
   * 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
572
  g_object_class_install_property (gobject_class,
573
				   PROP_PIXBUF_COLUMN,
574
				   g_param_spec_int ("pixbuf-column",
575 576
						     P_("Pixbuf column"),
						     P_("Model column used to retrieve the icon pixbuf from"),
577
						     -1, G_MAXINT, -1,
578
						     GTK_PARAM_READWRITE));
579

580 581 582 583 584 585 586 587 588 589
  /**
   * 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
590
  g_object_class_install_property (gobject_class,
591
				   PROP_TEXT_COLUMN,
592
				   g_param_spec_int ("text-column",
593 594
						     P_("Text column"),
						     P_("Model column used to retrieve the text from"),
595
						     -1, G_MAXINT, -1,
596
						     GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
597

598 599 600 601 602 603 604 605 606 607 608 609
  
  /**
   * 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
610 611
  g_object_class_install_property (gobject_class,
				   PROP_MARKUP_COLUMN,
612
				   g_param_spec_int ("markup-column",
613
						     P_("Markup column"),
614
						     P_("Model column used to retrieve the text if using Pango markup"),
Anders Carlsson's avatar
Anders Carlsson committed
615
						     -1, G_MAXINT, -1,
616
						     GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
617
  
618 619 620
  g_object_class_install_property (gobject_class,
                                   PROP_MODEL,
                                   g_param_spec_object ("model",
621 622
							P_("Icon View Model"),
							P_("The model for the icon view"),
623
							GTK_TYPE_TREE_MODEL,
624
							GTK_PARAM_READWRITE));
625
  
Matthias Clasen's avatar
Matthias Clasen committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
  /**
   * 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,
641
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
642 643 644
  

  /**
645
   * GtkIconView:item-width:
Matthias Clasen's avatar
Matthias Clasen committed
646 647 648 649 650 651 652 653 654
   *
   * 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,
655
				   g_param_spec_int ("item-width",
Matthias Clasen's avatar
Matthias Clasen committed
656 657 658
						     P_("Width for each item"),
						     P_("The width used for each item"),
						     -1, G_MAXINT, -1,
659
						     GTK_PARAM_READWRITE));  
Matthias Clasen's avatar
Matthias Clasen committed
660 661

  /**
662
   * GtkIconView:spacing:
Matthias Clasen's avatar
Matthias Clasen committed
663 664 665 666 667 668 669 670 671 672 673 674
   *
   * 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,
675
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
676 677

  /**
678
   * GtkIconView:row-spacing:
Matthias Clasen's avatar
Matthias Clasen committed
679 680 681 682 683 684 685 686
   *
   * 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,
687
                                   g_param_spec_int ("row-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
688 689 690
						     P_("Row Spacing"),
						     P_("Space which is inserted between grid rows"),
						     0, G_MAXINT, 6,
691
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
692 693

  /**
694
   * GtkIconView:column-spacing:
Matthias Clasen's avatar
Matthias Clasen committed
695 696 697 698 699 700 701 702
   *
   * 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,
703
                                   g_param_spec_int ("column-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
704
						     P_("Column Spacing"),
705
						     P_("Space which is inserted between grid columns"),
Matthias Clasen's avatar
Matthias Clasen committed
706
						     0, G_MAXINT, 6,
707
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
708 709

  /**
710
   * GtkIconView:margin:
Matthias Clasen's avatar
Matthias Clasen committed
711 712 713 714 715 716 717 718 719 720 721 722
   *
   * 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,
723
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
724 725

  /**
726
   * GtkIconView:item-orientation:
Matthias Clasen's avatar
Matthias Clasen committed
727
   *
728
   * The item-orientation property specifies how the cells (i.e. the icon and
Matthias Clasen's avatar
Matthias Clasen committed
729 730 731 732
   * the text) of the item are positioned relative to each other.
   *
   * Since: 2.6
   */
733
  g_object_class_install_property (gobject_class,
734 735 736
				   PROP_ITEM_ORIENTATION,
				   g_param_spec_enum ("item-orientation",
						      P_("Item Orientation"),
737 738 739
						      P_("How the text and icon of each item are positioned relative to each other"),
						      GTK_TYPE_ORIENTATION,
						      GTK_ORIENTATION_VERTICAL,
740
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
741

Matthias Clasen's avatar
Matthias Clasen committed
742
  /**
743
   * GtkIconView:reorderable:
Matthias Clasen's avatar
Matthias Clasen committed
744 745 746 747 748 749 750 751 752 753 754 755 756 757
   *
   * 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));

758 759 760 761 762 763 764 765 766 767
    g_object_class_install_property (gobject_class,
                                     PROP_TOOLTIP_COLUMN,
                                     g_param_spec_int ("tooltip-column",
                                                       P_("Tooltip Column"),
                                                       P_("The column in the model containing the tooltip texts for the items"),
                                                       -1,
                                                       G_MAXINT,
                                                       -1,
                                                       GTK_PARAM_READWRITE));

768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
  /**
   * GtkIconView:item-padding:
   *
   * The item-padding property specifies the padding around each
   * of the icon view's item.
   *
   * Since: 2.18
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ITEM_PADDING,
                                   g_param_spec_int ("item-padding",
						     P_("Item Padding"),
						     P_("Padding around icon view items"),
						     0, G_MAXINT, 6,
						     GTK_PARAM_READWRITE));

784 785


786
  /* Style properties */
787
  gtk_widget_class_install_style_property (widget_class,
788
                                           g_param_spec_boxed ("selection-box-color",
789 790
                                                               P_("Selection Box Color"),
                                                               P_("Color of the selection box"),
791
                                                               GDK_TYPE_COLOR,
792
                                                               GTK_PARAM_READABLE));
793 794

  gtk_widget_class_install_style_property (widget_class,
795
                                           g_param_spec_uchar ("selection-box-alpha",
796 797
                                                               P_("Selection Box Alpha"),
                                                               P_("Opacity of the selection box"),
798 799
                                                               0, 0xff,
                                                               0x40,
800
                                                               GTK_PARAM_READABLE));
801

Anders Carlsson's avatar
Anders Carlsson committed
802
  /* Signals */
803 804 805 806 807 808 809 810 811
  /**
   * GtkIconView::set-scroll-adjustments
   * @horizontal: the horizontal #GtkAdjustment
   * @vertical: the vertical #GtkAdjustment
   *
   * Set the scroll adjustments for the icon view. Usually scrolled containers
   * like #GtkScrolledWindow will emit this signal to connect two instances
   * of #GtkScrollbar to the scroll directions of the #GtkIconView.
   */
Anders Carlsson's avatar
Anders Carlsson committed
812
  widget_class->set_scroll_adjustments_signal =
813
    g_signal_new (I_("set-scroll-adjustments"),
Anders Carlsson's avatar
Anders Carlsson committed
814 815
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
816
		  G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
Anders Carlsson's avatar
Anders Carlsson committed
817
		  NULL, NULL, 
818
		  _gtk_marshal_VOID__OBJECT_OBJECT,
Anders Carlsson's avatar
Anders Carlsson committed
819 820 821
		  G_TYPE_NONE, 2,
		  GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);

Matthias Clasen's avatar
Matthias Clasen committed
822 823 824 825 826 827 828 829 830 831 832
  /**
   * GtkIconView::item-activated:
   * @iconview: the object on which the signal is emitted
   * @path: the #GtkTreePath for the activated item
   *
   * The ::item-activated signal is emitted when the method
   * gtk_icon_view_item_activated() is called or the user double 
   * clicks an item. It is also emitted when a non-editable item
   * is selected and one of the keys: Space, Return or Enter is
   * pressed.
   */
833
  icon_view_signals[ITEM_ACTIVATED] =
834
    g_signal_new (I_("item-activated"),
Anders Carlsson's avatar
Anders Carlsson committed
835 836
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
837
		  G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
Anders Carlsson's avatar
Anders Carlsson committed
838
		  NULL, NULL,
Anders Carlsson's avatar
Anders Carlsson committed
839
		  g_cclosure_marshal_VOID__BOXED,
Anders Carlsson's avatar
Anders Carlsson committed
840
		  G_TYPE_NONE, 1,
841
		  GTK_TYPE_TREE_PATH);
Anders Carlsson's avatar
Anders Carlsson committed
842

Matthias Clasen's avatar
Matthias Clasen committed
843 844 845 846 847 848 849
  /**
   * GtkIconView::selection-changed:
   * @iconview: the object on which the signal is emitted
   *
   * The ::selection-changed signal is emitted when the selection
   * (i.e. the set of selected items) changes.
   */
850
  icon_view_signals[SELECTION_CHANGED] =
851
    g_signal_new (I_("selection-changed"),
Anders Carlsson's avatar
Anders Carlsson committed
852 853
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_FIRST,
854
		  G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
Anders Carlsson's avatar
Anders Carlsson committed
855 856 857 858
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
Matthias Clasen's avatar
Matthias Clasen committed
859 860 861 862 863 864 865 866 867 868 869 870 871
  /**
   * GtkIconView::select-all:
   * @iconview: the object on which the signal is emitted
   *
   * A <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user selects all items.
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control selection
   * programmatically.
   * 
   * The default binding for this signal is Ctrl-a.
   */
872
  icon_view_signals[SELECT_ALL] =
873
    g_signal_new (I_("select-all"),
Anders Carlsson's avatar
Anders Carlsson committed
874 875
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
876
		  G_STRUCT_OFFSET (GtkIconViewClass, select_all),
Anders Carlsson's avatar
Anders Carlsson committed
877 878 879 880
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
Matthias Clasen's avatar
Matthias Clasen committed
881 882 883 884 885 886 887 888 889 890 891 892 893
  /**
   * GtkIconView::unselect-all:
   * @iconview: the object on which the signal is emitted
   *
   * A <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user unselects all items.
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control selection
   * programmatically.
   * 
   * The default binding for this signal is Ctrl-Shift-a. 
   */
894
  icon_view_signals[UNSELECT_ALL] =
895
    g_signal_new (I_("unselect-all"),
Anders Carlsson's avatar
Anders Carlsson committed
896 897
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
898
		  G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
Anders Carlsson's avatar
Anders Carlsson committed
899 900 901 902
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

Matthias Clasen's avatar
Matthias Clasen committed
903 904 905 906 907 908 909 910 911 912 913 914 915 916
  /**
   * GtkIconView::select-cursor-item:
   * @iconview: the object on which the signal is emitted
   *
   * A <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user selects the item that is currently
   * focused.
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control selection
   * programmatically.
   * 
   * There is no default binding for this signal.
   */
917
  icon_view_signals[SELECT_CURSOR_ITEM] =
918
    g_signal_new (I_("select-cursor-item"),
Anders Carlsson's avatar
Anders Carlsson committed
919 920
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
921
		  G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
922 923 924 925
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

Matthias Clasen's avatar
Matthias Clasen committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
  /**
   * GtkIconView::toggle-cursor-item:
   * @iconview: the object on which the signal is emitted
   *
   * A <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user toggles whether the currently
   * focused item is selected or not. The exact effect of this 
   * depend on the selection mode.
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control selection
   * programmatically.
   * 
   * There is no default binding for this signal is Ctrl-Space.
   */
941
  icon_view_signals[TOGGLE_CURSOR_ITEM] =
942
    g_signal_new (I_("toggle-cursor-item"),
Anders Carlsson's avatar
Anders Carlsson committed
943 944
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
945
		  G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
946 947 948 949
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

Matthias Clasen's avatar
Matthias Clasen committed
950 951 952 953 954 955 956 957 958 959 960 961 962 963
  /**
   * GtkIconView::activate-cursor-item:
   * @iconview: the object on which the signal is emitted
   *
   * A <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user activates the currently 
   * focused item. 
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control activation
   * programmatically.
   * 
   * The default bindings for this signal are Space, Return and Enter.
   */
964
  icon_view_signals[ACTIVATE_CURSOR_ITEM] =
965
    g_signal_new (I_("activate-cursor-item"),
966 967 968 969 970 971 972
		  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);
  
Matthias Clasen's avatar
Matthias Clasen committed
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
  /**
   * GtkIconView::move-cursor:
   * @iconview: the object which received the signal
   * @step: the granularity of the move, as a #GtkMovementStep
   * @count: the number of @step units to move
   *
   * The ::move-cursor signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user initiates a cursor movement.
   *
   * Applications should not connect to it, but may emit it with
   * g_signal_emit_by_name() if they need to control the cursor
   * programmatically.
   *
   * The default bindings for this signal include
   * <itemizedlist>
   * <listitem>Arrow keys which move by individual steps</listitem>
   * <listitem>Home/End keys which move to the first/last item</listitem>
   * <listitem>PageUp/PageDown which move by "pages"</listitem>
   * </itemizedlist>
   *
   * All of these will extend the selection when combined with
   * the Shift modifier.
   */
997
  icon_view_signals[MOVE_CURSOR] =
998
    g_signal_new (I_("move-cursor"),
Matthias Clasen's avatar
Matthias Clasen committed
999 1000
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1001
		  G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
Matthias Clasen's avatar
Matthias Clasen committed
1002
		  NULL, NULL,
1003
		  _gtk_marshal_BOOLEAN__ENUM_INT,
Matthias Clasen's avatar
Matthias Clasen committed
1004 1005 1006 1007
		  G_TYPE_BOOLEAN, 2,
		  GTK_TYPE_MOVEMENT_STEP,
		  G_TYPE_INT);

Anders Carlsson's avatar
Anders Carlsson committed
1008
  /* Key bindings */
1009
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, 
1010
				"select-all", 0);
1011
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK, 
1012
				"unselect-all", 0);
1013
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK, 
1014
				"toggle-cursor-item", 0);
1015
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
1016
				"toggle-cursor-item", 0);
Matthias Clasen's avatar
Matthias Clasen committed
1017

1018
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0, 
1019
				"activate-cursor-item", 0);
1020
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
1021
				"activate-cursor-item", 0);
1022
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, 
1023
				"activate-cursor-item", 0);
1024
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, 
1025
				"activate-cursor-item", 0);
1026
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, 
1027
				"activate-cursor-item", 0);
1028

1029
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1030
				  GTK_MOVEMENT_DISPLAY_LINES, -1);
1031
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1032 1033
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

1034
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1035
				  GTK_MOVEMENT_DISPLAY_LINES, 1);
1036
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1037 1038
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

1039
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
1040 1041
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

1042
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
1043 1044
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

1045
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1046
				  GTK_MOVEMENT_BUFFER_ENDS, -1);
1047
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1048 1049
				  GTK_MOVEMENT_BUFFER_ENDS, -1);

1050
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1051
				  GTK_MOVEMENT_BUFFER_ENDS, 1);
1052
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1053 1054
				  GTK_MOVEMENT_BUFFER_ENDS, 1);

1055
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1056
				  GTK_MOVEMENT_PAGES, -1);
1057
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1058 1059
				  GTK_MOVEMENT_PAGES, -1);

1060
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1061
				  GTK_MOVEMENT_PAGES, 1);
1062
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
1063 1064
				  GTK_MOVEMENT_PAGES, 1);

1065
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
1066
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1067
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
1068 1069
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);

1070
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
1071
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1072
  gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
1073 1074
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);
}
Anders Carlsson's avatar
Anders Carlsson committed
1075

Johan Dahlin's avatar
Johan Dahlin committed
1076 1077 1078 1079
static void
gtk_icon_view_buildable_init (GtkBuildableIface *iface)
{
  parent_buildable_iface = g_type_interface_peek_parent (iface);
1080
  iface->add_child = _gtk_cell_layout_buildable_add_child;
Johan Dahlin's avatar
Johan Dahlin committed
1081 1082 1083 1084
  iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
  iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
}

Matthias Clasen's avatar
Matthias Clasen committed
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
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;
1095
  iface->get_cells = gtk_icon_view_cell_layout_get_cells;
Matthias Clasen's avatar
Matthias Clasen committed
1096 1097
}

Anders Carlsson's avatar
Anders Carlsson committed
1098
static void
1099
gtk_icon_view_init (GtkIconView *icon_view)
Anders Carlsson's avatar
Anders Carlsson committed
1100
{
1101 1102 1103 1104
  icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
                                                 GTK_TYPE_ICON_VIEW,
                                                 GtkIconViewPrivate);

1105 1106 1107 1108 1109 1110 1111 1112 1113
  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
1114 1115
  icon_view->priv->text_cell = -1;
  icon_view->priv->pixbuf_cell = -1;  
1116
  icon_view->priv->tooltip_column = -1;  
1117

1118
  gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
Anders Carlsson's avatar
Anders Carlsson committed
1119
  
1120
  gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1121

Matthias Clasen's avatar
Matthias Clasen committed
1122 1123 1124 1125
  icon_view->priv->cell_list = NULL;
  icon_view->priv->n_cells = 0;
  icon_view->priv->cursor_cell = -1;

1126
  icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
Matthias Clasen's avatar
Matthias Clasen committed
1127 1128 1129 1130 1131 1132 1133

  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;
1134
  icon_view->priv->item_padding = 6;
1135 1136

  icon_view->priv->draw_focus = TRUE;
Anders Carlsson's avatar
Anders Carlsson committed
1137 1138 1139
}

static void
1140
gtk_icon_view_destroy (GtkObject *object)
Anders Carlsson's avatar
Anders Carlsson committed
1141
{
1142
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1143

1144
  icon_view = GTK_ICON_VIEW (object);
1145
  
Matthias Clasen's avatar
Matthias Clasen committed
1146 1147
  gtk_icon_view_stop_editing (icon_view, TRUE);

1148
  gtk_icon_view_set_model (icon_view, NULL);
1149
  
1150
  if (icon_view->priv->layout_idle_id != 0)
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
    {
      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
1161

Matthias Clasen's avatar
Matthias Clasen committed
1162
  remove_scroll_timeout (icon_view);
Matthias Clasen's avatar
Matthias Clasen committed
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174

  if (icon_view->priv->hadjustment != NULL)
    {
      g_object_unref (icon_view->priv->hadjustment);
      icon_view->priv->hadjustment = NULL;
    }

  if (icon_view->priv->vadjustment != NULL)
    {
      g_object_unref (icon_view->priv->vadjustment);
      icon_view->priv->vadjustment = NULL;
    }
1175
  
1176
  GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1177 1178 1179 1180
}

/* GObject methods */
static void
1181
gtk_icon_view_finalize (GObject *object)
1182
{
Matthias Clasen's avatar
Matthias Clasen committed
1183
  gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1184

1185
  G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
Anders Carlsson's avatar
Anders Carlsson committed
1186 1187 1188 1189
}


static void
1190
gtk_icon_view_set_property (GObject      *object,
Anders Carlsson's avatar
Anders Carlsson committed
1191 1192 1193 1194
			    guint         prop_id,
			    const GValue *value,
			    GParamSpec   *pspec)
{
1195
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1196

1197
  icon_view = GTK_ICON_VIEW (object);
Anders Carlsson's avatar
Anders Carlsson committed
1198 1199 1200 1201

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
1202
      gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
Anders Carlsson's avatar
Anders Carlsson committed
1203
      break;
1204
    case PROP_PIXBUF_COLUMN:
1205
      gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1206 1207
      break;
    case PROP_TEXT_COLUMN:
1208
      gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
Anders Carlsson's avatar
Anders Carlsson committed
1209
      break;
Anders Carlsson's avatar
Anders Carlsson committed
1210
    case PROP_MARKUP_COLUMN:
1211
      gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
Anders Carlsson's avatar
Anders Carlsson committed
1212
      break;
1213
    case PROP_MODEL:
1214
      gtk_icon_view_set_model (icon_view, g_value_get_object (value));
Anders Carlsson's avatar
Anders Carlsson committed
1215
      break;
1216 1217
    case PROP_ITEM_ORIENTATION:
      gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1218
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
    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
1237 1238 1239
    case PROP_REORDERABLE:
      gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
      break;
1240
      
1241 1242 1243 1244
    case PROP_TOOLTIP_COLUMN:
      gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
      break;

Matthias Clasen's avatar
Matthias Clasen committed
1245 1246 1247 1248
    case PROP_ITEM_PADDING:
      gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
      break;

Anders Carlsson's avatar
Anders Carlsson committed
1249 1250 1251 1252 1253 1254 1255
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
1256
gtk_icon_view_get_property (GObject      *object,
Anders Carlsson's avatar
Anders Carlsson committed
1257 1258 1259 1260
			    guint         prop_id,
			    GValue       *value,
			    GParamSpec   *pspec)
{
1261
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1262

1263
  icon_view = GTK_ICON_VIEW (object);
Anders Carlsson's avatar
Anders Carlsson committed
1264 1265 1266 1267

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
1268
      g_value_set_enum (value, icon_view->priv->selection_mode);
Anders Carlsson's avatar
Anders Carlsson committed
1269
      break;
1270
    case PROP_PIXBUF_COLUMN:
1271
      g_value_set_int (value, icon_view->priv->pixbuf_column);
1272 1273
      break;
    case PROP_TEXT_COLUMN:
1274
      g_value_set_int (value, icon_view->priv->text_column);