/
gtkiconview.c
9365 lines (7816 loc) · 270 KB
/
gtkiconview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* gtkiconview.c
* Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
*
* 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.
*/
#include "config.h"
#include <string.h>
#include <atk/atk.h>
#include "gtkiconview.h"
#include "gtkcelllayout.h"
#include "gtkcellrenderer.h"
#include "gtkcellareabox.h"
#include "gtkcellareacontext.h"
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
#include "gtkorientable.h"
#include "gtkmarshalers.h"
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkmain.h"
#include "gtkintl.h"
#include "gtkaccessible.h"
#include "gtkwindow.h"
#include "gtkentry.h"
#include "gtkcombobox.h"
#include "gtktextbuffer.h"
#include "gtkscrollable.h"
#include "gtksizerequest.h"
#include "gtktreednd.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
/**
* SECTION:gtkiconview
* @title: GtkIconView
* @short_description: A widget which displays a list of icons in a grid
*
* #GtkIconView provides an alternative view on a #GtkTreeModel.
* 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.
*
* Note that if the tree model is backed by an actual tree store (as
* opposed to a flat list where the mapping to icons is obvious),
* #GtkIconView will only display the first level of the tree and
* ignore the tree's branches.
*/
#define SCROLL_EDGE_SIZE 15
#define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
typedef struct _GtkIconViewItem GtkIconViewItem;
struct _GtkIconViewItem
{
/* First member is always the rectangle so it
* can be cast to a rectangle. */
GdkRectangle cell_area;
GtkTreeIter iter;
gint index;
gint row, col;
guint selected : 1;
guint selected_before_rubberbanding : 1;
};
typedef struct _GtkIconViewChild GtkIconViewChild;
struct _GtkIconViewChild
{
GtkWidget *widget;
GdkRectangle area;
};
struct _GtkIconViewPrivate
{
GtkCellArea *cell_area;
GtkCellAreaContext *cell_area_context;
gulong add_editable_id;
gulong remove_editable_id;
gulong context_changed_id;
GPtrArray *row_contexts;
gint width, height;
GtkSelectionMode selection_mode;
GdkWindow *bin_window;
GList *children;
GtkTreeModel *model;
GList *items;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
guint layout_idle_id;
gint rubberband_x1, rubberband_y1;
gint rubberband_x2, rubberband_y2;
GdkDevice *rubberband_device;
guint scroll_timeout_id;
gint scroll_value_diff;
gint event_last_x, event_last_y;
GtkIconViewItem *anchor_item;
GtkIconViewItem *cursor_item;
GtkIconViewItem *last_single_clicked;
GtkOrientation item_orientation;
gint columns;
gint item_width;
gint spacing;
gint row_spacing;
gint column_spacing;
gint margin;
gint item_padding;
gint text_column;
gint markup_column;
gint pixbuf_column;
GtkCellRenderer *pixbuf_cell;
GtkCellRenderer *text_cell;
gint tooltip_column;
/* 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;
/* scroll to */
GtkTreeRowReference *scroll_to_path;
gfloat scroll_to_row_align;
gfloat scroll_to_col_align;
guint scroll_to_use_align : 1;
guint source_set : 1;
guint dest_set : 1;
guint reorderable : 1;
guint empty_view_drop :1;
guint ctrl_pressed : 1;
guint shift_pressed : 1;
guint draw_focus : 1;
/* GtkScrollablePolicy needs to be checked when
* driving the scrollable adjustment values */
guint hscroll_policy : 1;
guint vscroll_policy : 1;
guint doing_rubberband : 1;
};
/* Signals */
enum
{
ITEM_ACTIVATED,
SELECTION_CHANGED,
SELECT_ALL,
UNSELECT_ALL,
SELECT_CURSOR_ITEM,
TOGGLE_CURSOR_ITEM,
MOVE_CURSOR,
ACTIVATE_CURSOR_ITEM,
LAST_SIGNAL
};
/* Properties */
enum
{
PROP_0,
PROP_PIXBUF_COLUMN,
PROP_TEXT_COLUMN,
PROP_MARKUP_COLUMN,
PROP_SELECTION_MODE,
PROP_ITEM_ORIENTATION,
PROP_MODEL,
PROP_COLUMNS,
PROP_ITEM_WIDTH,
PROP_SPACING,
PROP_ROW_SPACING,
PROP_COLUMN_SPACING,
PROP_MARGIN,
PROP_REORDERABLE,
PROP_TOOLTIP_COLUMN,
PROP_ITEM_PADDING,
PROP_CELL_AREA,
/* For scrollable interface */
PROP_HADJUSTMENT,
PROP_VADJUSTMENT,
PROP_HSCROLL_POLICY,
PROP_VSCROLL_POLICY
};
/* GObject vfuncs */
static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
static void gtk_icon_view_dispose (GObject *object);
static GObject *gtk_icon_view_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties);
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);
/* GtkWidget vfuncs */
static void gtk_icon_view_destroy (GtkWidget *widget);
static void gtk_icon_view_realize (GtkWidget *widget);
static void gtk_icon_view_unrealize (GtkWidget *widget);
static void gtk_icon_view_style_updated (GtkWidget *widget);
static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural);
static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural);
static void gtk_icon_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gboolean gtk_icon_view_draw (GtkWidget *widget,
cairo_t *cr);
static gboolean gtk_icon_view_motion (GtkWidget *widget,
GdkEventMotion *event);
static gboolean gtk_icon_view_button_press (GtkWidget *widget,
GdkEventButton *event);
static gboolean gtk_icon_view_button_release (GtkWidget *widget,
GdkEventButton *event);
static gboolean gtk_icon_view_key_press (GtkWidget *widget,
GdkEventKey *event);
static gboolean gtk_icon_view_key_release (GtkWidget *widget,
GdkEventKey *event);
static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
/* GtkContainer vfuncs */
static void gtk_icon_view_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_icon_view_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
/* GtkIconView vfuncs */
static void gtk_icon_view_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_set_hadjustment_values (GtkIconView *icon_view);
static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
GtkAdjustment *adjustment);
static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
GtkAdjustment *adjustment);
static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
GtkOrientation orientation,
GtkAdjustment *adjustment);
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,
gint x,
gint y,
gboolean draw_focus);
static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
cairo_t *cr);
static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
GtkTreePath *path);
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,
GtkCellRenderer *cursor_cell);
static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
GdkDevice *device,
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_cache_widths (GtkIconView *icon_view);
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,
gboolean only_in_cell,
GtkCellRenderer **cell_at_pos);
static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
GtkIconViewItem *item);
static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
GtkCellArea *cell_area);
static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
GtkIconViewItem *item);
static void gtk_icon_view_add_editable (GtkCellArea *area,
GtkCellRenderer *renderer,
GtkCellEditable *editable,
GdkRectangle *cell_area,
const gchar *path,
GtkIconView *icon_view);
static void gtk_icon_view_remove_editable (GtkCellArea *area,
GtkCellRenderer *renderer,
GtkCellEditable *editable,
GtkIconView *icon_view);
static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
GParamSpec *pspec,
GtkIconView *icon_view);
/* 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);
/* 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);
static guint icon_view_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
gtk_icon_view_cell_layout_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_icon_view_buildable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static void
gtk_icon_view_class_init (GtkIconViewClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
binding_set = gtk_binding_set_by_class (klass);
g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
gobject_class = (GObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
container_class = (GtkContainerClass *) klass;
gobject_class->constructor = gtk_icon_view_constructor;
gobject_class->dispose = gtk_icon_view_dispose;
gobject_class->set_property = gtk_icon_view_set_property;
gobject_class->get_property = gtk_icon_view_get_property;
widget_class->destroy = gtk_icon_view_destroy;
widget_class->realize = gtk_icon_view_realize;
widget_class->unrealize = gtk_icon_view_unrealize;
widget_class->style_updated = gtk_icon_view_style_updated;
widget_class->get_accessible = gtk_icon_view_get_accessible;
widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
widget_class->size_allocate = gtk_icon_view_size_allocate;
widget_class->draw = gtk_icon_view_draw;
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;
widget_class->key_press_event = gtk_icon_view_key_press;
widget_class->key_release_event = gtk_icon_view_key_release;
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;
widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
container_class->remove = gtk_icon_view_remove;
container_class->forall = gtk_icon_view_forall;
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;
klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
klass->move_cursor = gtk_icon_view_real_move_cursor;
/* Properties */
/**
* 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
*/
g_object_class_install_property (gobject_class,
PROP_SELECTION_MODE,
g_param_spec_enum ("selection-mode",
P_("Selection mode"),
P_("The selection mode"),
GTK_TYPE_SELECTION_MODE,
GTK_SELECTION_SINGLE,
GTK_PARAM_READWRITE));
/**
* 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
*/
g_object_class_install_property (gobject_class,
PROP_PIXBUF_COLUMN,
g_param_spec_int ("pixbuf-column",
P_("Pixbuf column"),
P_("Model column used to retrieve the icon pixbuf from"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
/**
* 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
*/
g_object_class_install_property (gobject_class,
PROP_TEXT_COLUMN,
g_param_spec_int ("text-column",
P_("Text column"),
P_("Model column used to retrieve the text from"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
/**
* 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
*/
g_object_class_install_property (gobject_class,
PROP_MARKUP_COLUMN,
g_param_spec_int ("markup-column",
P_("Markup column"),
P_("Model column used to retrieve the text if using Pango markup"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_MODEL,
g_param_spec_object ("model",
P_("Icon View Model"),
P_("The model for the icon view"),
GTK_TYPE_TREE_MODEL,
GTK_PARAM_READWRITE));
/**
* 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,
GTK_PARAM_READWRITE));
/**
* GtkIconView:item-width:
*
* The item-width property specifies the width to use for each item.
* If it is set to -1, the icon view will automatically determine a
* suitable item size.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_ITEM_WIDTH,
g_param_spec_int ("item-width",
P_("Width for each item"),
P_("The width used for each item"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
/**
* GtkIconView:spacing:
*
* The spacing property specifies the space which is inserted between
* the cells (i.e. the icon and the text) of an item.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_SPACING,
g_param_spec_int ("spacing",
P_("Spacing"),
P_("Space which is inserted between cells of an item"),
0, G_MAXINT, 0,
GTK_PARAM_READWRITE));
/**
* GtkIconView:row-spacing:
*
* The row-spacing property specifies the space which is inserted between
* the rows of the icon view.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_ROW_SPACING,
g_param_spec_int ("row-spacing",
P_("Row Spacing"),
P_("Space which is inserted between grid rows"),
0, G_MAXINT, 6,
GTK_PARAM_READWRITE));
/**
* GtkIconView:column-spacing:
*
* The column-spacing property specifies the space which is inserted between
* the columns of the icon view.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_COLUMN_SPACING,
g_param_spec_int ("column-spacing",
P_("Column Spacing"),
P_("Space which is inserted between grid columns"),
0, G_MAXINT, 6,
GTK_PARAM_READWRITE));
/**
* GtkIconView:margin:
*
* The margin property specifies the space which is inserted
* at the edges of the icon view.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_MARGIN,
g_param_spec_int ("margin",
P_("Margin"),
P_("Space which is inserted at the edges of the icon view"),
0, G_MAXINT, 6,
GTK_PARAM_READWRITE));
/**
* GtkIconView:item-orientation:
*
* The item-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
*/
g_object_class_install_property (gobject_class,
PROP_ITEM_ORIENTATION,
g_param_spec_enum ("item-orientation",
P_("Item Orientation"),
P_("How the text and icon of each item are positioned relative to each other"),
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_VERTICAL,
GTK_PARAM_READWRITE));
/**
* GtkIconView:reorderable:
*
* 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));
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));
/**
* 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));
/**
* GtkIconView:cell-area:
*
* The #GtkCellArea used to layout cell renderers for this view.
*
* Since: 3.0
*/
g_object_class_install_property (gobject_class,
PROP_CELL_AREA,
g_param_spec_object ("cell-area",
P_("Cell Area"),
P_("The GtkCellArea used to layout cells"),
GTK_TYPE_CELL_AREA,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* Scrollable interface properties */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
/* Style properties */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("selection-box-color",
P_("Selection Box Color"),
P_("Color of the selection box"),
GDK_TYPE_COLOR,
GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_uchar ("selection-box-alpha",
P_("Selection Box Alpha"),
P_("Opacity of the selection box"),
0, 0xff,
0x40,
GTK_PARAM_READABLE));
/* Signals */
/**
* 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.
*/
icon_view_signals[ITEM_ACTIVATED] =
g_signal_new (I_("item-activated"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
GTK_TYPE_TREE_PATH);
/**
* 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.
*/
icon_view_signals[SELECTION_CHANGED] =
g_signal_new (I_("selection-changed"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* 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.
*/
icon_view_signals[SELECT_ALL] =
g_signal_new (I_("select-all"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, select_all),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* 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.
*/
icon_view_signals[UNSELECT_ALL] =
g_signal_new (I_("unselect-all"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* 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.
*/
icon_view_signals[SELECT_CURSOR_ITEM] =
g_signal_new (I_("select-cursor-item"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* 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.
*/
icon_view_signals[TOGGLE_CURSOR_ITEM] =
g_signal_new (I_("toggle-cursor-item"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* 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.
*/
icon_view_signals[ACTIVATE_CURSOR_ITEM] =
g_signal_new (I_("activate-cursor-item"),
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);
/**
* 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.
*/
icon_view_signals[MOVE_CURSOR] =
g_signal_new (I_("move-cursor"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
NULL, NULL,
_gtk_marshal_BOOLEAN__ENUM_INT,
G_TYPE_BOOLEAN, 2,
GTK_TYPE_MOVEMENT_STEP,
G_TYPE_INT);
/* Key bindings */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"select-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate-cursor-item", 0);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);