gtkiconview.c 256 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 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,
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
/* 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);
242 243 244 245
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
246 247 248 249 250 251 252 253 254 255 256 257
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);
258 259 260 261
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
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
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
291 292 293 294 295
									  GdkRectangle           *area,
									  GdkDrawable *drawable,
									  gint         x,
									  gint         y,
									  gboolean     draw_focus);
Matthias Clasen's avatar
Matthias Clasen committed
296 297 298
static void                 gtk_icon_view_paint_rubberband               (GtkIconView            *icon_view,
								          cairo_t *cr,
									  GdkRectangle           *area);
Matthias Clasen's avatar
Matthias Clasen committed
299 300
static void                 gtk_icon_view_queue_draw_path                (GtkIconView *icon_view,
									  GtkTreePath *path);
Matthias Clasen's avatar
Matthias Clasen committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
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
355
									  gboolean                only_in_cell,
Matthias Clasen's avatar
Matthias Clasen committed
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
									  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);
390 391
static GList *              gtk_icon_view_cell_layout_get_cells          (GtkCellLayout          *layout);

Matthias Clasen's avatar
Matthias Clasen committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
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);
408

Matthias Clasen's avatar
Matthias Clasen committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
/* 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);
447 448
static void     clear_dest_info                  (GtkIconView *icon_view);
static void     clear_source_info                (GtkIconView *icon_view);
Matthias Clasen's avatar
Matthias Clasen committed
449

450 451
static void     adjust_wrap_width                (GtkIconView     *icon_view,
						  GtkIconViewItem *item);
Matthias Clasen's avatar
Matthias Clasen committed
452

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
/* 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);

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

Matthias Clasen's avatar
Matthias Clasen committed
470 471
G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
472 473 474
						gtk_icon_view_cell_layout_init)
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
						gtk_icon_view_buildable_init))
Anders Carlsson's avatar
Anders Carlsson committed
475 476

static void
477
gtk_icon_view_class_init (GtkIconViewClass *klass)
Anders Carlsson's avatar
Anders Carlsson committed
478 479
{
  GObjectClass *gobject_class;
480
  GtkObjectClass *object_class;
Anders Carlsson's avatar
Anders Carlsson committed
481
  GtkWidgetClass *widget_class;
Matthias Clasen's avatar
Matthias Clasen committed
482
  GtkContainerClass *container_class;
Anders Carlsson's avatar
Anders Carlsson committed
483 484 485
  GtkBindingSet *binding_set;
  
  binding_set = gtk_binding_set_by_class (klass);
486

487
  g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
488

Anders Carlsson's avatar
Anders Carlsson committed
489
  gobject_class = (GObjectClass *) klass;
490
  object_class = (GtkObjectClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
491
  widget_class = (GtkWidgetClass *) klass;
Matthias Clasen's avatar
Matthias Clasen committed
492
  container_class = (GtkContainerClass *) klass;
Anders Carlsson's avatar
Anders Carlsson committed
493

494 495 496 497 498 499 500 501
  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;
502 503
  widget_class->style_set = gtk_icon_view_style_set;
  widget_class->get_accessible = gtk_icon_view_get_accessible;
504 505 506 507 508 509
  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;
510 511
  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
512 513 514 515 516 517 518 519
  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;
520
  widget_class->state_changed = gtk_icon_view_state_changed;
521

Matthias Clasen's avatar
Matthias Clasen committed
522 523 524
  container_class->remove = gtk_icon_view_remove;
  container_class->forall = gtk_icon_view_forall;

525 526 527 528 529
  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;
530
  klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;  
531
  klass->move_cursor = gtk_icon_view_real_move_cursor;
Anders Carlsson's avatar
Anders Carlsson committed
532 533
  
  /* Properties */
534 535 536 537 538 539 540 541 542
  /**
   * 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
543 544
  g_object_class_install_property (gobject_class,
				   PROP_SELECTION_MODE,
545
				   g_param_spec_enum ("selection-mode",
546 547
						      P_("Selection mode"),
						      P_("The selection mode"),
Anders Carlsson's avatar
Anders Carlsson committed
548 549
						      GTK_TYPE_SELECTION_MODE,
						      GTK_SELECTION_SINGLE,
550
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
551

552 553 554 555 556 557 558 559 560 561
  /**
   * 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
562
  g_object_class_install_property (gobject_class,
563
				   PROP_PIXBUF_COLUMN,
564
				   g_param_spec_int ("pixbuf-column",
565 566
						     P_("Pixbuf column"),
						     P_("Model column used to retrieve the icon pixbuf from"),
567
						     -1, G_MAXINT, -1,
568
						     GTK_PARAM_READWRITE));
569

570 571 572 573 574 575 576 577 578 579
  /**
   * 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
580
  g_object_class_install_property (gobject_class,
581
				   PROP_TEXT_COLUMN,
582
				   g_param_spec_int ("text-column",
583 584
						     P_("Text column"),
						     P_("Model column used to retrieve the text from"),
585
						     -1, G_MAXINT, -1,
586
						     GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
587

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

  /**
635
   * GtkIconView:item-width:
Matthias Clasen's avatar
Matthias Clasen committed
636 637 638 639 640 641 642 643 644
   *
   * 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,
645
				   g_param_spec_int ("item-width",
Matthias Clasen's avatar
Matthias Clasen committed
646 647 648
						     P_("Width for each item"),
						     P_("The width used for each item"),
						     -1, G_MAXINT, -1,
649
						     GTK_PARAM_READWRITE));  
Matthias Clasen's avatar
Matthias Clasen committed
650 651

  /**
652
   * GtkIconView:spacing:
Matthias Clasen's avatar
Matthias Clasen committed
653 654 655 656 657 658 659 660 661 662 663 664
   *
   * 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,
665
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
666 667

  /**
668
   * GtkIconView:row-spacing:
Matthias Clasen's avatar
Matthias Clasen committed
669 670 671 672 673 674 675 676
   *
   * 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,
677
                                   g_param_spec_int ("row-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
678 679 680
						     P_("Row Spacing"),
						     P_("Space which is inserted between grid rows"),
						     0, G_MAXINT, 6,
681
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
682 683

  /**
684
   * GtkIconView:column-spacing:
Matthias Clasen's avatar
Matthias Clasen committed
685 686 687 688 689 690 691 692
   *
   * 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,
693
                                   g_param_spec_int ("column-spacing",
Matthias Clasen's avatar
Matthias Clasen committed
694
						     P_("Column Spacing"),
695
						     P_("Space which is inserted between grid columns"),
Matthias Clasen's avatar
Matthias Clasen committed
696
						     0, G_MAXINT, 6,
697
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
698 699

  /**
700
   * GtkIconView:margin:
Matthias Clasen's avatar
Matthias Clasen committed
701 702 703 704 705 706 707 708 709 710 711 712
   *
   * 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,
713
						     GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
714 715 716


  /**
717
   * GtkIconView:orientation:
Matthias Clasen's avatar
Matthias Clasen committed
718 719 720 721 722 723
   *
   * 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
   */
724 725 726 727 728 729 730
  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,
731
						      GTK_PARAM_READWRITE));
Anders Carlsson's avatar
Anders Carlsson committed
732

Matthias Clasen's avatar
Matthias Clasen committed
733
  /**
734
   * GtkIconView:reorderable:
Matthias Clasen's avatar
Matthias Clasen committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748
   *
   * 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));

749
  /* Style properties */
750
  gtk_widget_class_install_style_property (widget_class,
751
                                           g_param_spec_boxed ("selection-box-color",
752 753
                                                               P_("Selection Box Color"),
                                                               P_("Color of the selection box"),
754
                                                               GDK_TYPE_COLOR,
755
                                                               GTK_PARAM_READABLE));
756 757

  gtk_widget_class_install_style_property (widget_class,
758
                                           g_param_spec_uchar ("selection-box-alpha",
759 760
                                                               P_("Selection Box Alpha"),
                                                               P_("Opacity of the selection box"),
761 762
                                                               0, 0xff,
                                                               0x40,
763
                                                               GTK_PARAM_READABLE));
764

Anders Carlsson's avatar
Anders Carlsson committed
765 766
  /* Signals */
  widget_class->set_scroll_adjustments_signal =
767
    g_signal_new (I_("set_scroll_adjustments"),
Anders Carlsson's avatar
Anders Carlsson committed
768 769
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
770
		  G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
Anders Carlsson's avatar
Anders Carlsson committed
771
		  NULL, NULL, 
772
		  _gtk_marshal_VOID__OBJECT_OBJECT,
Anders Carlsson's avatar
Anders Carlsson committed
773 774 775
		  G_TYPE_NONE, 2,
		  GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);

776
  icon_view_signals[ITEM_ACTIVATED] =
777
    g_signal_new (I_("item_activated"),
Anders Carlsson's avatar
Anders Carlsson committed
778 779
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
780
		  G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
Anders Carlsson's avatar
Anders Carlsson committed
781
		  NULL, NULL,
782
		  g_cclosure_marshal_VOID__BOXED,
Anders Carlsson's avatar
Anders Carlsson committed
783
		  G_TYPE_NONE, 1,
784
		  GTK_TYPE_TREE_PATH);
Anders Carlsson's avatar
Anders Carlsson committed
785

786
  icon_view_signals[SELECTION_CHANGED] =
787
    g_signal_new (I_("selection-changed"),
Anders Carlsson's avatar
Anders Carlsson committed
788 789
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_FIRST,
790
		  G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
Anders Carlsson's avatar
Anders Carlsson committed
791 792 793 794
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
795
  icon_view_signals[SELECT_ALL] =
796
    g_signal_new (I_("select_all"),
Anders Carlsson's avatar
Anders Carlsson committed
797 798
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
799
		  G_STRUCT_OFFSET (GtkIconViewClass, select_all),
Anders Carlsson's avatar
Anders Carlsson committed
800 801 802 803
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
  
804
  icon_view_signals[UNSELECT_ALL] =
805
    g_signal_new (I_("unselect_all"),
Anders Carlsson's avatar
Anders Carlsson committed
806 807
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
808
		  G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
Anders Carlsson's avatar
Anders Carlsson committed
809 810 811 812
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

813
  icon_view_signals[SELECT_CURSOR_ITEM] =
814
    g_signal_new (I_("select_cursor_item"),
Anders Carlsson's avatar
Anders Carlsson committed
815 816
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
817
		  G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
818 819 820 821
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

822
  icon_view_signals[TOGGLE_CURSOR_ITEM] =
823
    g_signal_new (I_("toggle_cursor_item"),
Anders Carlsson's avatar
Anders Carlsson committed
824 825
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
826
		  G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
Anders Carlsson's avatar
Anders Carlsson committed
827 828 829 830
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

831
  icon_view_signals[ACTIVATE_CURSOR_ITEM] =
832
    g_signal_new (I_("activate_cursor_item"),
833 834 835 836 837 838 839
		  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);
  
840
  icon_view_signals[MOVE_CURSOR] =
841
    g_signal_new (I_("move_cursor"),
Matthias Clasen's avatar
Matthias Clasen committed
842 843
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
844
		  G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
Matthias Clasen's avatar
Matthias Clasen committed
845
		  NULL, NULL,
846
		  _gtk_marshal_BOOLEAN__ENUM_INT,
Matthias Clasen's avatar
Matthias Clasen committed
847 848 849 850
		  G_TYPE_BOOLEAN, 2,
		  GTK_TYPE_MOVEMENT_STEP,
		  G_TYPE_INT);

Anders Carlsson's avatar
Anders Carlsson committed
851
  /* Key bindings */
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
  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);
867

868
  gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
869
				  GTK_MOVEMENT_DISPLAY_LINES, -1);
870
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
871 872
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

873
  gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
874
				  GTK_MOVEMENT_DISPLAY_LINES, 1);
875
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
876 877
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

878
  gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
879 880
				  GTK_MOVEMENT_DISPLAY_LINES, -1);

881
  gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
Matthias Clasen's avatar
Matthias Clasen committed
882 883
				  GTK_MOVEMENT_DISPLAY_LINES, 1);

884
  gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
885
				  GTK_MOVEMENT_BUFFER_ENDS, -1);
886
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
Matthias Clasen's avatar
Matthias Clasen committed
887 888
				  GTK_MOVEMENT_BUFFER_ENDS, -1);

889
  gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
890
				  GTK_MOVEMENT_BUFFER_ENDS, 1);
891
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
Matthias Clasen's avatar
Matthias Clasen committed
892 893
				  GTK_MOVEMENT_BUFFER_ENDS, 1);

894
  gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
895
				  GTK_MOVEMENT_PAGES, -1);
896
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
Matthias Clasen's avatar
Matthias Clasen committed
897 898
				  GTK_MOVEMENT_PAGES, -1);

899
  gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
900
				  GTK_MOVEMENT_PAGES, 1);
901
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
Matthias Clasen's avatar
Matthias Clasen committed
902 903
				  GTK_MOVEMENT_PAGES, 1);

904
  gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
905
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
906
  gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
907 908
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);

909
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
910
				  GTK_MOVEMENT_VISUAL_POSITIONS, 1);
911
  gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0, 
Matthias Clasen's avatar
Matthias Clasen committed
912 913
				  GTK_MOVEMENT_VISUAL_POSITIONS, -1);
}
Anders Carlsson's avatar
Anders Carlsson committed
914

915 916 917 918
static void
gtk_icon_view_buildable_init (GtkBuildableIface *iface)
{
  parent_buildable_iface = g_type_interface_peek_parent (iface);
919
  iface->add_child = _gtk_cell_layout_buildable_add_child;
920 921 922 923
  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
924 925 926 927 928 929 930 931 932 933
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;
934
  iface->get_cells = gtk_icon_view_cell_layout_get_cells;
Matthias Clasen's avatar
Matthias Clasen committed
935 936
}

Anders Carlsson's avatar
Anders Carlsson committed
937
static void
938
gtk_icon_view_init (GtkIconView *icon_view)
Anders Carlsson's avatar
Anders Carlsson committed
939
{
940
  icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
941
  
942 943 944 945 946 947 948 949 950
  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
951 952
  icon_view->priv->text_cell = -1;
  icon_view->priv->pixbuf_cell = -1;  
953

954
  GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
Anders Carlsson's avatar
Anders Carlsson committed
955
  
956
  gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
957

Matthias Clasen's avatar
Matthias Clasen committed
958 959 960 961
  icon_view->priv->cell_list = NULL;
  icon_view->priv->n_cells = 0;
  icon_view->priv->cursor_cell = -1;

962
  icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
Matthias Clasen's avatar
Matthias Clasen committed
963 964 965 966 967 968 969

  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
970 971 972
}

static void
973
gtk_icon_view_destroy (GtkObject *object)
Anders Carlsson's avatar
Anders Carlsson committed
974
{
975
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
976

977
  icon_view = GTK_ICON_VIEW (object);
978
  
Matthias Clasen's avatar
Matthias Clasen committed
979 980
  gtk_icon_view_stop_editing (icon_view, TRUE);

981
  gtk_icon_view_set_model (icon_view, NULL);
982
  
983
  if (icon_view->priv->layout_idle_id != 0)
984 985 986 987 988 989 990 991 992 993
    {
      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
994

Matthias Clasen's avatar
Matthias Clasen committed
995
  remove_scroll_timeout (icon_view);
Matthias Clasen's avatar
Matthias Clasen committed
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007

  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;
    }
1008
  
1009 1010 1011
  clear_dest_info (icon_view);
  clear_source_info (icon_view);

Matthias Clasen's avatar
Matthias Clasen committed
1012
  (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1013 1014 1015 1016
}

/* GObject methods */
static void
1017
gtk_icon_view_finalize (GObject *object)
1018
{
Matthias Clasen's avatar
Matthias Clasen committed
1019
  gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1020

Matthias Clasen's avatar
Matthias Clasen committed
1021
  (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
Anders Carlsson's avatar
Anders Carlsson committed
1022 1023 1024 1025
}


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

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

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
1038
      gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
Anders Carlsson's avatar
Anders Carlsson committed
1039
      break;
1040
    case PROP_PIXBUF_COLUMN:
1041
      gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1042 1043
      break;
    case PROP_TEXT_COLUMN:
1044
      gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
Anders Carlsson's avatar
Anders Carlsson committed
1045
      break;
1046
    case PROP_MARKUP_COLUMN:
1047
      gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1048
      break;
1049
    case PROP_MODEL:
1050
      gtk_icon_view_set_model (icon_view, g_value_get_object (value));
Anders Carlsson's avatar
Anders Carlsson committed
1051
      break;
1052 1053 1054
    case PROP_ORIENTATION:
      gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    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
1073 1074 1075
    case PROP_REORDERABLE:
      gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
      break;
1076
      
Anders Carlsson's avatar
Anders Carlsson committed
1077 1078 1079 1080 1081 1082 1083
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
1084
gtk_icon_view_get_property (GObject      *object,
Anders Carlsson's avatar
Anders Carlsson committed
1085 1086 1087 1088
			    guint         prop_id,
			    GValue       *value,
			    GParamSpec   *pspec)
{
1089
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1090

1091
  icon_view = GTK_ICON_VIEW (object);
Anders Carlsson's avatar
Anders Carlsson committed
1092 1093 1094 1095

  switch (prop_id)
    {
    case PROP_SELECTION_MODE:
1096
      g_value_set_enum (value, icon_view->priv->selection_mode);
Anders Carlsson's avatar
Anders Carlsson committed
1097
      break;
1098
    case PROP_PIXBUF_COLUMN:
1099
      g_value_set_int (value, icon_view->priv->pixbuf_column);
1100 1101
      break;
    case PROP_TEXT_COLUMN:
1102
      g_value_set_int (value, icon_view->priv->text_column);
Anders Carlsson's avatar
Anders Carlsson committed
1103
      break;
1104
    case PROP_MARKUP_COLUMN:
1105
      g_value_set_int (value, icon_view->priv->markup_column);
1106
      break;
1107
    case PROP_MODEL:
1108
      g_value_set_object (value, icon_view->priv->model);
Anders Carlsson's avatar
Anders Carlsson committed
1109
      break;
1110 1111 1112
    case PROP_ORIENTATION:
      g_value_set_enum (value, icon_view->priv->orientation);
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
    case PROP_COLUMNS:
      g_value_set_int (value, icon_view->priv->columns);
      break;
    case PROP_ITEM_WIDTH:
      g_value_set_int (value, icon_view->priv->item_width);
      break;
    case PROP_SPACING:
      g_value_set_int (value, icon_view->priv->spacing);
      break;
    case PROP_ROW_SPACING:
      g_value_set_int (value, icon_view->priv->row_spacing);
      break;
    case PROP_COLUMN_SPACING:
      g_value_set_int (value, icon_view->priv->column_spacing);
      break;
    case PROP_MARGIN:
      g_value_set_int (value, icon_view->priv->margin);
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1131 1132 1133
    case PROP_REORDERABLE:
      g_value_set_boolean (value, icon_view->priv->reorderable);
      break;
Matthias Clasen's avatar
Matthias Clasen committed
1134

Anders Carlsson's avatar
Anders Carlsson committed
1135 1136 1137 1138 1139 1140 1141 1142
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/* GtkWidget signals */
static void
1143
gtk_icon_view_realize (GtkWidget *widget)
Anders Carlsson's avatar
Anders Carlsson committed
1144
{
1145
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1146 1147 1148
  GdkWindowAttr attributes;
  gint attributes_mask;
  
1149
  icon_view = GTK_ICON_VIEW (widget);
Anders Carlsson's avatar
Anders Carlsson committed
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  /* Make the main, clipping window */
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
				   &attributes, attributes_mask);
1168
  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
Anders Carlsson's avatar
Anders Carlsson committed
1169 1170
  gdk_window_set_user_data (widget->window, widget);

1171
  /* Make the window for the icon view */
Anders Carlsson's avatar
Anders Carlsson committed
1172 1173
  attributes.x = 0;
  attributes.y = 0;
1174 1175
  attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
  attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
Anders Carlsson's avatar
Anders Carlsson committed
1176 1177 1178 1179 1180 1181 1182 1183 1184
  attributes.event_mask = (GDK_EXPOSURE_MASK |
			   GDK_SCROLL_MASK |
			   GDK_POINTER_MOTION_MASK |
			   GDK_BUTTON_PRESS_MASK |
			   GDK_BUTTON_RELEASE_MASK |
			   GDK_KEY_PRESS_MASK |
			   GDK_KEY_RELEASE_MASK) |
    gtk_widget_get_events (widget);
  
1185
  icon_view->priv->bin_window = gdk_window_new (widget->window,
1186
						&attributes, attributes_mask);
1187
  gdk_window_set_user_data (icon_view->priv->bin_window, widget);
Anders Carlsson's avatar
Anders Carlsson committed
1188 1189

  widget->style = gtk_style_attach (widget->style, widget->window);
1190
  gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1191 1192

  gdk_window_show (icon_view->priv->bin_window);
Anders Carlsson's avatar
Anders Carlsson committed
1193 1194 1195
}

static void
1196
gtk_icon_view_unrealize (GtkWidget *widget)
Anders Carlsson's avatar
Anders Carlsson committed
1197
{
1198
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1199

1200
  icon_view = GTK_ICON_VIEW (widget);
Anders Carlsson's avatar
Anders Carlsson committed
1201

1202 1203 1204
  gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
  gdk_window_destroy (icon_view->priv->bin_window);
  icon_view->priv->bin_window = NULL;
Anders Carlsson's avatar
Anders Carlsson committed
1205 1206

  /* GtkWidget::unrealize destroys children and widget->window */
Matthias Clasen's avatar
Matthias Clasen committed
1207 1208
  if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
Anders Carlsson's avatar
Anders Carlsson committed
1209 1210
}

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
static void
gtk_icon_view_state_changed (GtkWidget      *widget,
		 	     GtkStateType    previous_state)
{
  GtkIconView *icon_view = GTK_ICON_VIEW (widget);

  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
      gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
    }

  gtk_widget_queue_draw (widget);
}

static void
gtk_icon_view_style_set (GtkWidget *widget,
			 GtkStyle *previous_style)
{
  GtkIconView *icon_view;

  g_return_if_fail (GTK_IS_ICON_VIEW (widget));

  icon_view = GTK_ICON_VIEW (widget);

  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
      gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
    }

  gtk_widget_queue_resize (widget);
}

Anders Carlsson's avatar
Anders Carlsson committed
1245
static void
1246
gtk_icon_view_size_request (GtkWidget      *widget,
Anders Carlsson's avatar
Anders Carlsson committed
1247 1248
			    GtkRequisition *requisition)
{
1249
  GtkIconView *icon_view;
Matthias Clasen's avatar
Matthias Clasen committed
1250
  GList *tmp_list;
Anders Carlsson's avatar
Anders Carlsson committed
1251

1252
  icon_view = GTK_ICON_VIEW (widget);
Anders Carlsson's avatar
Anders Carlsson committed
1253

1254 1255
  requisition->width = icon_view->priv->width;
  requisition->height = icon_view->priv->height;
Matthias Clasen's avatar
Matthias Clasen committed
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300

  tmp_list = icon_view->priv->children;

  while (tmp_list)
    {
      GtkIconViewChild *child = tmp_list->data;
      GtkRequisition child_requisition;

      tmp_list = tmp_list->next;

      if (GTK_WIDGET_VISIBLE (child->widget))
        gtk_widget_size_request (child->widget, &child_requisition);
    }  
}

static void
gtk_icon_view_allocate_children (GtkIconView *icon_view)
{
  GList *list;

  for (list = icon_view->priv->children; list; list = list->next)
    {
      GtkIconViewChild *child = list->data;
      GtkAllocation allocation;

      /* totally ignore our child's requisition */
      if (child->cell < 0)
	{
	  allocation.x = child->item->x;
	  allocation.y = child->item->y;
	  allocation.width = child->item->width;
	  allocation.height = child->item->height;
	}
      else
	{
	  GdkRectangle *box = &child->item->box[child->cell];

	  allocation.x = box->x;
	  allocation.y = box->y;
	  allocation.width = box->width;
	  allocation.height = box->height;
	}

      gtk_widget_size_allocate (child->widget, &allocation);
    }
Anders Carlsson's avatar
Anders Carlsson committed
1301 1302 1303
}

static void
1304
gtk_icon_view_size_allocate (GtkWidget      *widget,
Anders Carlsson's avatar
Anders Carlsson committed
1305 1306
			     GtkAllocation  *allocation)
{
Matthias Clasen's avatar
Matthias Clasen committed
1307 1308
  GtkIconView *icon_view = GTK_ICON_VIEW (widget);

1309
  GtkAdjustment *hadjustment, *vadjustment;
Anders Carlsson's avatar
Anders Carlsson committed
1310 1311 1312 1313 1314 1315 1316 1317

  widget->allocation = *allocation;
  
  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_move_resize (widget->window,
			      allocation->x, allocation->y,
			      allocation->width, allocation->height);
1318 1319 1320
      gdk_window_resize (icon_view->priv->bin_window,
			 MAX (icon_view->priv->width, allocation->width),
			 MAX (icon_view->priv->height, allocation->height));
Anders Carlsson's avatar
Anders Carlsson committed
1321 1322
    }

Matthias Clasen's avatar
Matthias Clasen committed
1323 1324 1325 1326
  gtk_icon_view_layout (icon_view);
  
  gtk_icon_view_allocate_children (icon_view);

1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
  hadjustment = icon_view->priv->hadjustment;
  vadjustment = icon_view->priv->vadjustment;

  hadjustment->page_size = allocation->width;
  hadjustment->page_increment = allocation->width * 0.9;
  hadjustment->step_increment = allocation->width * 0.1;
  hadjustment->lower = 0;
  hadjustment->upper = MAX (allocation->width, icon_view->priv->width);

  if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
    gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));

  vadjustment->page_size = allocation->height;
  vadjustment->page_increment = allocation->height * 0.9;
  vadjustment->step_increment = allocation->height * 0.1;
  vadjustment->lower = 0;
  vadjustment->upper = MAX (allocation->height, icon_view->priv->height);

  if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
    gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));

1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
  if (GTK_WIDGET_REALIZED (widget) &&
      icon_view->priv->scroll_to_path)
    {
      GtkTreePath *path;
      path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
      gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
      icon_view->priv->scroll_to_path = NULL;

      gtk_icon_view_scroll_to_path (icon_view, path,
				    icon_view->priv->scroll_to_use_align,
				    icon_view->priv->scroll_to_row_align,
				    icon_view->priv->scroll_to_col_align);
      gtk_tree_path_free (path);
    }
  else
    {
      gtk_adjustment_changed (hadjustment);
      gtk_adjustment_changed (vadjustment);
    }
Anders Carlsson's avatar
Anders Carlsson committed
1367 1368 1369
}

static gboolean
1370
gtk_icon_view_expose (GtkWidget *widget,
Anders Carlsson's avatar
Anders Carlsson committed
1371 1372
		      GdkEventExpose *expose)
{
1373
  GtkIconView *icon_view;
Anders Carlsson's avatar
Anders Carlsson committed
1374
  GList *icons;
1375
  cairo_t *cr;
Matthias Clasen's avatar
Matthias Clasen committed
1376 1377 1378 1379
  GtkTreePath *path;
  gint dest_index;
  GtkIconViewDropPosition dest_pos;
  GtkIconViewItem *dest_item = NULL;
Anders Carlsson's avatar
Anders Carlsson committed
1380

1381
  icon_view = GTK_ICON_VIEW (widget);
Anders Carlsson's avatar
Anders Carlsson committed
1382

1383
  if (expose->window != icon_view->priv->bin_window)
Anders Carlsson's avatar
Anders Carlsson committed
1384 1385
    return FALSE;

1386
  cr = gdk_cairo_create (icon_view->priv->bin_window);
1387 1388
  cairo_set_line_width (cr, 1.);

Matthias Clasen's avatar
Matthias Clasen committed
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
  gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);

  if (path)
    {
      dest_index = gtk_tree_path_get_indices (path)[0];
      gtk_tree_path_free (path);
    }
  else
    dest_index = -1;

Matthias Clasen's avatar
Matthias Clasen committed
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
  for (icons = icon_view->priv->items; icons; icons = icons->next) 
    {
      GtkIconViewItem *item = icons->data;
      GdkRectangle area;
      
      area.x = item->x;
      area.y = item->y;
      area.width = item->width;
      area.height = item->height;
	
      if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
	continue;
      
Matthias Clasen's avatar
Matthias Clasen committed
1412 1413 1414 1415 1416 1417
      gtk_icon_view_paint_item (icon_view, cr, item, &expose->area, 
				icon_view->priv->bin_window,
				item->x, item->y, TRUE); 
 
      if (dest_index == item->index)
	dest_item = item;
Matthias Clasen's avatar
Matthias Clasen committed
1418
    }
Anders Carlsson's avatar
Anders Carlsson committed
1419

Matthias Clasen's avatar
Matthias Clasen committed
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
  if (dest_item)
    {
      switch (dest_pos)
	{
	case GTK_ICON_VIEW_DROP_INTO:
	  gtk_paint_focus (widget->style,
			   icon_view->priv->bin_window,
			   GTK_WIDGET_STATE (widget),
			   NULL,
			   widget,
			   "iconview-drop-indicator",
			   dest_item->x, dest_item->y,
			   dest_item->width, dest_item->height);
	  break;
	case GTK_ICON_VIEW_DROP_ABOVE:
	  gtk_paint_focus (widget->style,
			   icon_view->priv->bin_window,
			   GTK_WIDGET_STATE (widget),
			   NULL,
			   widget,
			   "iconview-drop-indicator",
			   dest_item->x, dest_item->y - 1,
			   dest_item->width, 2);
	  break;
	case GTK_ICON_VIEW_DROP_LEFT:
	  gtk_paint_focus (widget->style,
			   icon_view->priv->bin_window,
			   GTK_WIDGET_STATE (widget),
			   NULL,
			   widget,
			   "iconview-drop-indicator",
			   dest_item->x - 1, dest_item->y,
			   2, dest_item->height);
	  break;
	case GTK_ICON_VIEW_DROP_BELOW:
	  gtk_paint_focus (widget->style,
			   icon_view->priv->bin_window,
			   GTK_WIDGET_STATE (widget),
			   NULL,
			   widget,
			   "iconview-drop-indicator",
			   dest_item->x, dest_item->y + dest_item->height - 1,
			   dest_item->width, 2);
	  break;
	case GTK_ICON_VIEW_DROP_RIGHT:
	  gtk_paint_focus (widget->style,
			   icon_view->priv->bin_window,
			   GTK_WIDGET_STATE (widget),
			   NULL,
			   widget,
			   "iconview-drop-indicator",
			   dest_item->x + dest_item->width - 1, dest_item->y,
			   2, dest_item->height);
	case GTK_ICON_VIEW_NO_DROP: ;
	  break;
	}
    }
  
1478
  if (icon_view->priv->doing_rubberband)
Anders Carlsson's avatar
Anders Carlsson committed
1479 1480 1481 1482 1483 1484 1485 1486 1487
    {
      GdkRectangle *rectangles;
      gint n_rectangles;
      
      gdk_region_get_rectangles (expose->region,
				 &rectangles,
				 &n_rectangles);
      
      while (n_rectangles--)
1488
	gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
Anders Carlsson's avatar
Anders Carlsson committed
1489 1490 1491 1492

      g_free (rectangles);
    }

1493 1494
  cairo_destroy (cr);

Matthias Clasen's avatar
Matthias Clasen committed
1495 1496
  (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);

Anders Carlsson's avatar
Anders Carlsson committed
1497 1498 1499
  return TRUE;
}

1500
static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1501
rubberband_scroll_timeout (gpointer data)
1502
{
1503
  GtkIconView *icon_view;
1504
  gdouble value;
Matthias Clasen's avatar
Matthias Clasen committed
1505

1506
  icon_view = data;
1507

1508 1509 1510 1511
  value = MIN (icon_view->priv->vadjustment->value +
	       icon_view->priv->scroll_value_diff,
	       icon_view->priv->vadjustment->upper -
	       icon_view->priv->vadjustment->page_size);
1512