~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gtk/gtkiconfactory.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-09-23 09:50:04 UTC
  • mfrom: (1.5.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: james.westby@ubuntu.com-20090923095004-e9xauadn4bjs5n7m
Tags: upstream-2.18.0
ImportĀ upstreamĀ versionĀ 2.18.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22
22
 * file for a list of people on the GTK+ Team.  See the ChangeLog
23
23
 * files for a list of changes.  These files are distributed with
24
 
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 
24
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25
25
 */
26
26
 
27
27
#include "config.h"
54
54
struct _GtkIconSource
55
55
{
56
56
  GtkIconSourceType type;
57
 
  
 
57
 
58
58
  union {
59
59
    gchar *icon_name;
60
60
    gchar *filename;
126
126
gtk_icon_factory_class_init (GtkIconFactoryClass *klass)
127
127
{
128
128
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
129
 
  
 
129
 
130
130
  object_class->finalize = gtk_icon_factory_finalize;
131
131
}
132
132
 
150
150
  GtkIconFactory *factory = GTK_ICON_FACTORY (object);
151
151
 
152
152
  all_icon_factories = g_slist_remove (all_icon_factories, factory);
153
 
  
 
153
 
154
154
  g_hash_table_foreach (factory->icons, free_icon_set, NULL);
155
 
  
 
155
 
156
156
  g_hash_table_destroy (factory->icons);
157
 
  
 
157
 
158
158
  G_OBJECT_CLASS (gtk_icon_factory_parent_class)->finalize (object);
159
159
}
160
160
 
174
174
 * gtk_icon_factory_remove_default(). Applications with icons should
175
175
 * add a default icon factory with their icons, which will allow
176
176
 * themes to override the icons for the application.
177
 
 * 
 
177
 *
178
178
 * Return value: a new #GtkIconFactory
179
 
 **/
 
179
 */
180
180
GtkIconFactory*
181
181
gtk_icon_factory_new (void)
182
182
{
199
199
 * override your application's default icons. If an icon already
200
200
 * existed in @factory for @stock_id, it is unreferenced and replaced
201
201
 * with the new @icon_set.
202
 
 * 
203
 
 **/
 
202
 */
204
203
void
205
204
gtk_icon_factory_add (GtkIconFactory *factory,
206
205
                      const gchar    *stock_id,
211
210
 
212
211
  g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
213
212
  g_return_if_fail (stock_id != NULL);
214
 
  g_return_if_fail (icon_set != NULL);  
 
213
  g_return_if_fail (icon_set != NULL);
215
214
 
216
215
  g_hash_table_lookup_extended (factory->icons, stock_id,
217
216
                                &old_key, &old_value);
218
217
 
219
218
  if (old_value == icon_set)
220
219
    return;
221
 
  
 
220
 
222
221
  gtk_icon_set_ref (icon_set);
223
222
 
224
223
  /* GHashTable key memory management is so fantastically broken. */
235
234
 * gtk_icon_factory_lookup:
236
235
 * @factory: a #GtkIconFactory
237
236
 * @stock_id: an icon name
238
 
 * 
 
237
 *
239
238
 * Looks up @stock_id in the icon factory, returning an icon set
240
239
 * if found, otherwise %NULL. For display to the user, you should
241
240
 * use gtk_style_lookup_icon_set() on the #GtkStyle for the
242
241
 * widget that will display the icon, instead of using this
243
242
 * function directly, so that themes are taken into account.
244
 
 * 
 
243
 *
245
244
 * Return value: icon set of @stock_id.
246
 
 **/
 
245
 */
247
246
GtkIconSet *
248
247
gtk_icon_factory_lookup (GtkIconFactory *factory,
249
248
                         const gchar    *stock_id)
250
249
{
251
250
  g_return_val_if_fail (GTK_IS_ICON_FACTORY (factory), NULL);
252
251
  g_return_val_if_fail (stock_id != NULL, NULL);
253
 
  
 
252
 
254
253
  return g_hash_table_lookup (factory->icons, stock_id);
255
254
}
256
255
 
260
259
/**
261
260
 * gtk_icon_factory_add_default:
262
261
 * @factory: a #GtkIconFactory
263
 
 * 
 
262
 *
264
263
 * Adds an icon factory to the list of icon factories searched by
265
264
 * gtk_style_lookup_icon_set(). This means that, for example,
266
265
 * gtk_image_new_from_stock() will be able to find icons in @factory.
267
266
 * There will normally be an icon factory added for each library or
268
267
 * application that comes with icons. The default icon factories
269
268
 * can be overridden by themes.
270
 
 * 
271
 
 **/
 
269
 */
272
270
void
273
271
gtk_icon_factory_add_default (GtkIconFactory *factory)
274
272
{
275
273
  g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
276
274
 
277
275
  g_object_ref (factory);
278
 
  
 
276
 
279
277
  default_factories = g_slist_prepend (default_factories, factory);
280
278
}
281
279
 
286
284
 * Removes an icon factory from the list of default icon
287
285
 * factories. Not normally used; you might use it for a library that
288
286
 * can be unloaded or shut down.
289
 
 * 
290
 
 **/
 
287
 */
291
288
void
292
289
gtk_icon_factory_remove_default (GtkIconFactory  *factory)
293
290
{
318
315
 * the #GtkStyle for the widget that will display the icon, instead of
319
316
 * using this function directly, so that themes are taken into
320
317
 * account.
321
 
 * 
322
 
 * 
 
318
 *
323
319
 * Return value: a #GtkIconSet, or %NULL
324
 
 **/
 
320
 */
325
321
GtkIconSet *
326
322
gtk_icon_factory_lookup_default (const gchar *stock_id)
327
323
{
328
324
  GSList *tmp_list;
329
325
 
330
326
  g_return_val_if_fail (stock_id != NULL, NULL);
331
 
  
 
327
 
332
328
  tmp_list = default_factories;
333
329
  while (tmp_list != NULL)
334
330
    {
338
334
 
339
335
      if (icon_set)
340
336
        return icon_set;
341
 
      
 
337
 
342
338
      tmp_list = g_slist_next (tmp_list);
343
339
    }
344
340
 
345
341
  _gtk_icon_factory_ensure_default_icons ();
346
 
  
 
342
 
347
343
  return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
348
344
}
349
345
 
357
353
  source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
358
354
  source.source.icon_name = (gchar *)stock_id;
359
355
  gtk_icon_set_add_source (set, &source);
360
 
  
 
356
 
361
357
  gtk_icon_factory_add (factory, stock_id, set);
362
358
  gtk_icon_set_unref (set);
363
359
}
375
371
  source.source.icon_name = (gchar *)stock_id_ltr;
376
372
  source.direction = GTK_TEXT_DIR_LTR;
377
373
  gtk_icon_set_add_source (set, &source);
378
 
  
 
374
 
379
375
  source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
380
376
  source.source.icon_name = (gchar *)stock_id_rtl;
381
377
  source.direction = GTK_TEXT_DIR_RTL;
382
378
  gtk_icon_set_add_source (set, &source);
383
 
  
 
379
 
384
380
  gtk_icon_factory_add (factory, stock_id, set);
385
381
  gtk_icon_set_unref (set);
386
382
}
416
412
  register_stock_icon (factory, GTK_STOCK_GO_DOWN);
417
413
  register_stock_icon (factory, GTK_STOCK_EXECUTE);
418
414
  register_stock_icon (factory, GTK_STOCK_QUIT);
419
 
  register_bidi_stock_icon (factory,  
420
 
                            GTK_STOCK_GOTO_FIRST, 
421
 
                            GTK_STOCK_GOTO_FIRST "-ltr", 
 
415
  register_bidi_stock_icon (factory,
 
416
                            GTK_STOCK_GOTO_FIRST,
 
417
                            GTK_STOCK_GOTO_FIRST "-ltr",
422
418
                            GTK_STOCK_GOTO_FIRST "-rtl");
423
419
  register_stock_icon (factory, GTK_STOCK_SELECT_FONT);
424
420
  register_stock_icon (factory, GTK_STOCK_FULLSCREEN);
427
423
  register_stock_icon (factory, GTK_STOCK_HELP);
428
424
  register_stock_icon (factory, GTK_STOCK_HOME);
429
425
  register_stock_icon (factory, GTK_STOCK_INFO);
430
 
  register_bidi_stock_icon (factory, 
 
426
  register_bidi_stock_icon (factory,
431
427
                            GTK_STOCK_JUMP_TO,
432
428
                            GTK_STOCK_JUMP_TO "-ltr",
433
429
                            GTK_STOCK_JUMP_TO "-rtl");
434
 
  register_bidi_stock_icon (factory, 
 
430
  register_bidi_stock_icon (factory,
435
431
                            GTK_STOCK_GOTO_LAST,
436
432
                            GTK_STOCK_GOTO_LAST "-ltr",
437
433
                            GTK_STOCK_GOTO_LAST "-rtl");
438
 
  register_bidi_stock_icon (factory, 
 
434
  register_bidi_stock_icon (factory,
439
435
                            GTK_STOCK_GO_BACK,
440
436
                            GTK_STOCK_GO_BACK "-ltr",
441
437
                            GTK_STOCK_GO_BACK "-rtl");
457
453
  register_stock_icon (factory, GTK_STOCK_PRINT_REPORT);
458
454
  register_stock_icon (factory, GTK_STOCK_PRINT_WARNING);
459
455
  register_stock_icon (factory, GTK_STOCK_PROPERTIES);
460
 
  register_bidi_stock_icon (factory, 
 
456
  register_bidi_stock_icon (factory,
461
457
                            GTK_STOCK_REDO,
462
458
                            GTK_STOCK_REDO "-ltr",
463
459
                            GTK_STOCK_REDO "-rtl");
464
460
  register_stock_icon (factory, GTK_STOCK_REMOVE);
465
461
  register_stock_icon (factory, GTK_STOCK_REFRESH);
466
 
  register_bidi_stock_icon (factory, 
 
462
  register_bidi_stock_icon (factory,
467
463
                            GTK_STOCK_REVERT_TO_SAVED,
468
464
                            GTK_STOCK_REVERT_TO_SAVED "-ltr",
469
465
                            GTK_STOCK_REVERT_TO_SAVED "-rtl");
470
 
  register_bidi_stock_icon (factory, 
 
466
  register_bidi_stock_icon (factory,
471
467
                            GTK_STOCK_GO_FORWARD,
472
468
                            GTK_STOCK_GO_FORWARD "-ltr",
473
469
                            GTK_STOCK_GO_FORWARD "-rtl");
484
480
  register_stock_icon (factory, GTK_STOCK_ITALIC);
485
481
  register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH);
486
482
  register_stock_icon (factory, GTK_STOCK_UNDERLINE);
487
 
  register_bidi_stock_icon (factory, 
 
483
  register_bidi_stock_icon (factory,
488
484
                            GTK_STOCK_INDENT,
489
485
                            GTK_STOCK_INDENT "-ltr",
490
486
                            GTK_STOCK_INDENT "-rtl");
491
 
  register_bidi_stock_icon (factory, 
 
487
  register_bidi_stock_icon (factory,
492
488
                            GTK_STOCK_UNINDENT,
493
489
                            GTK_STOCK_UNINDENT "-ltr",
494
490
                            GTK_STOCK_UNINDENT "-rtl");
495
491
  register_stock_icon (factory, GTK_STOCK_GOTO_TOP);
496
492
  register_stock_icon (factory, GTK_STOCK_DELETE);
497
 
  register_bidi_stock_icon (factory, 
 
493
  register_bidi_stock_icon (factory,
498
494
                            GTK_STOCK_UNDELETE,
499
495
                            GTK_STOCK_UNDELETE "-ltr",
500
496
                            GTK_STOCK_UNDELETE "-rtl");
501
 
  register_bidi_stock_icon (factory, 
 
497
  register_bidi_stock_icon (factory,
502
498
                            GTK_STOCK_UNDO,
503
499
                            GTK_STOCK_UNDO "-ltr",
504
500
                            GTK_STOCK_UNDO "-rtl");
510
506
  register_stock_icon (factory, GTK_STOCK_DISCONNECT);
511
507
  register_stock_icon (factory, GTK_STOCK_EDIT);
512
508
  register_stock_icon (factory, GTK_STOCK_CAPS_LOCK_WARNING);
513
 
  register_bidi_stock_icon (factory, 
 
509
  register_bidi_stock_icon (factory,
514
510
                            GTK_STOCK_MEDIA_FORWARD,
515
511
                            GTK_STOCK_MEDIA_FORWARD "-ltr",
516
512
                            GTK_STOCK_MEDIA_FORWARD "-rtl");
517
 
  register_bidi_stock_icon (factory, 
 
513
  register_bidi_stock_icon (factory,
518
514
                            GTK_STOCK_MEDIA_NEXT,
519
515
                            GTK_STOCK_MEDIA_NEXT "-ltr",
520
516
                            GTK_STOCK_MEDIA_NEXT "-rtl");
521
517
  register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE);
522
 
  register_bidi_stock_icon (factory, 
 
518
  register_bidi_stock_icon (factory,
523
519
                            GTK_STOCK_MEDIA_PLAY,
524
520
                            GTK_STOCK_MEDIA_PLAY "-ltr",
525
521
                            GTK_STOCK_MEDIA_PLAY "-rtl");
526
 
  register_bidi_stock_icon (factory, 
 
522
  register_bidi_stock_icon (factory,
527
523
                            GTK_STOCK_MEDIA_PREVIOUS,
528
524
                            GTK_STOCK_MEDIA_PREVIOUS "-ltr",
529
525
                            GTK_STOCK_MEDIA_PREVIOUS "-rtl");
530
526
  register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD);
531
 
  register_bidi_stock_icon (factory, 
 
527
  register_bidi_stock_icon (factory,
532
528
                            GTK_STOCK_MEDIA_REWIND,
533
529
                            GTK_STOCK_MEDIA_REWIND "-ltr",
534
530
                            GTK_STOCK_MEDIA_REWIND "-rtl");
554
550
{
555
551
  gint size;
556
552
  gchar *name;
557
 
  
 
553
 
558
554
  gint width;
559
555
  gint height;
560
556
};
589
585
      gint i;
590
586
 
591
587
      icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
592
 
      
 
588
 
593
589
      icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
594
590
      icon_sizes_allocated = NUM_BUILTIN_SIZES;
595
591
      icon_sizes_used = NUM_BUILTIN_SIZES;
604
600
       * Even if we did I suppose removing the builtin sizes would be
605
601
       * disallowed.
606
602
       */
607
 
      
 
603
 
608
604
      icon_sizes[GTK_ICON_SIZE_MENU].size = GTK_ICON_SIZE_MENU;
609
605
      icon_sizes[GTK_ICON_SIZE_MENU].name = "gtk-menu";
610
606
      icon_sizes[GTK_ICON_SIZE_MENU].width = 16;
619
615
      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
620
616
      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].width = 18;
621
617
      icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].height = 18;
622
 
      
 
618
 
623
619
      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].size = GTK_ICON_SIZE_LARGE_TOOLBAR;
624
620
      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
625
621
      icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
642
638
      while (i < NUM_BUILTIN_SIZES)
643
639
        {
644
640
          gtk_icon_size_register_alias (icon_sizes[i].name, icon_sizes[i].size);
645
 
          
 
641
 
646
642
          ++i;
647
643
        }
648
 
      
 
644
 
649
645
#undef NUM_BUILTIN_SIZES
650
646
    }
651
647
}
695
691
  if (size == GTK_ICON_SIZE_INVALID)
696
692
    /* Reserve a place */
697
693
    size = icon_size_register_intern (size_name, -1, -1);
698
 
  
 
694
 
699
695
  settings_sizes = get_settings_sizes (settings, NULL);
700
696
  if (size >= settings_sizes->len)
701
697
    {
707
703
    }
708
704
 
709
705
  settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
710
 
  
 
706
 
711
707
  settings_size->width = width;
712
708
  settings_size->height = height;
713
709
}
721
717
 
722
718
  while (g_ascii_isspace (*p))
723
719
    p++;
724
 
  
 
720
 
725
721
  if (!((*p >= 'A' && *p <= 'Z') ||
726
722
        (*p >= 'a' && *p <= 'z') ||
727
723
        *p == '_' || *p == '-'))
755
751
  while (pango_skip_space (&p))
756
752
    {
757
753
      gint width, height;
758
 
      
 
754
 
759
755
      if (!scan_icon_size_name (&p, name_buf))
760
756
        goto err;
761
757
 
845
841
                    "notify::gtk-icon-sizes",
846
842
                    G_CALLBACK (icon_size_settings_changed),
847
843
                    NULL);
848
 
  
 
844
 
849
845
  icon_size_set_all_from_settings (settings);
850
846
}
851
 
     
 
847
 
852
848
static gboolean
853
849
icon_size_lookup_intern (GtkSettings *settings,
854
850
                         GtkIconSize  size,
858
854
  GArray *settings_sizes;
859
855
  gint width_for_settings = -1;
860
856
  gint height_for_settings = -1;
861
 
  
 
857
 
862
858
  init_icon_sizes ();
863
859
 
864
860
  if (size == (GtkIconSize)-1)
873
869
  if (settings)
874
870
    {
875
871
      gboolean initial = FALSE;
876
 
      
 
872
 
877
873
      settings_sizes = get_settings_sizes (settings, &initial);
 
874
 
878
875
      if (initial)
879
876
        icon_sizes_init_for_settings (settings);
880
 
  
 
877
 
881
878
      if (size < settings_sizes->len)
882
879
        {
883
880
          SettingsIconSize *settings_size;
884
 
          
 
881
 
885
882
          settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
886
 
          
 
883
 
887
884
          width_for_settings = settings_size->width;
888
885
          height_for_settings = settings_size->height;
889
886
        }
907
904
 * @height: location to store icon height
908
905
 *
909
906
 * Obtains the pixel size of a semantic icon size, possibly
910
 
 * modified by user preferences for a particular 
 
907
 * modified by user preferences for a particular
911
908
 * #GtkSettings. Normally @size would be
912
909
 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc.  This function
913
910
 * isn't normally needed, gtk_widget_render_icon() is the usual
916
913
 * the width/height returned by gtk_icon_size_lookup(), because themes
917
914
 * are free to render the pixbuf however they like, including changing
918
915
 * the usual size.
919
 
 * 
 
916
 *
920
917
 * Return value: %TRUE if @size was a valid size
921
918
 *
922
919
 * Since: 2.2
923
 
 **/
 
920
 */
924
921
gboolean
925
922
gtk_icon_size_lookup_for_settings (GtkSettings *settings,
926
923
                                   GtkIconSize  size,
949
946
 * the width/height returned by gtk_icon_size_lookup(), because themes
950
947
 * are free to render the pixbuf however they like, including changing
951
948
 * the usual size.
952
 
 * 
 
949
 *
953
950
 * Return value: %TRUE if @size was a valid size
954
 
 **/
 
951
 */
955
952
gboolean
956
953
gtk_icon_size_lookup (GtkIconSize  size,
957
954
                      gint        *widthp,
971
968
{
972
969
  IconAlias *old_alias;
973
970
  GtkIconSize size;
974
 
  
 
971
 
975
972
  init_icon_sizes ();
976
973
 
977
974
  old_alias = g_hash_table_lookup (icon_aliases, name);
1018
1015
 * etc. Returns the integer value for the size.
1019
1016
 *
1020
1017
 * Returns: integer value representing the size
1021
 
 * 
1022
 
 **/
 
1018
 */
1023
1019
GtkIconSize
1024
1020
gtk_icon_size_register (const gchar *name,
1025
1021
                        gint         width,
1028
1024
  g_return_val_if_fail (name != NULL, 0);
1029
1025
  g_return_val_if_fail (width > 0, 0);
1030
1026
  g_return_val_if_fail (height > 0, 0);
1031
 
  
 
1027
 
1032
1028
  return icon_size_register_intern (name, width, height);
1033
1029
}
1034
1030
 
1040
1036
 * Registers @alias as another name for @target.
1041
1037
 * So calling gtk_icon_size_from_name() with @alias as argument
1042
1038
 * will return @target.
1043
 
 *
1044
 
 **/
 
1039
 */
1045
1040
void
1046
1041
gtk_icon_size_register_alias (const gchar *alias,
1047
1042
                              GtkIconSize  target)
1048
1043
{
1049
1044
  IconAlias *ia;
1050
 
  
 
1045
 
1051
1046
  g_return_if_fail (alias != NULL);
1052
1047
 
1053
1048
  init_icon_sizes ();
1077
1072
    }
1078
1073
}
1079
1074
 
1080
 
/** 
 
1075
/**
1081
1076
 * gtk_icon_size_from_name:
1082
1077
 * @name: the name to look up.
1083
1078
 * @returns: the icon size with the given name.
1084
 
 * 
 
1079
 *
1085
1080
 * Looks up the icon size associated with @name.
1086
 
 **/
 
1081
 */
1087
1082
GtkIconSize
1088
1083
gtk_icon_size_from_name (const gchar *name)
1089
1084
{
1090
1085
  IconAlias *ia;
1091
1086
 
1092
1087
  init_icon_sizes ();
1093
 
  
 
1088
 
1094
1089
  ia = g_hash_table_lookup (icon_aliases, name);
1095
1090
 
1096
1091
  if (ia && icon_sizes[ia->target].width > 0)
1103
1098
 * gtk_icon_size_get_name:
1104
1099
 * @size: a #GtkIconSize.
1105
1100
 * @returns: the name of the given icon size.
1106
 
 * 
1107
 
 * Gets the canonical name of the given icon size. The returned string 
 
1101
 *
 
1102
 * Gets the canonical name of the given icon size. The returned string
1108
1103
 * is statically allocated and should not be freed.
1109
 
 **/
 
1104
 */
1110
1105
G_CONST_RETURN gchar*
1111
1106
gtk_icon_size_get_name (GtkIconSize  size)
1112
1107
{
1164
1159
 
1165
1160
/**
1166
1161
 * gtk_icon_set_new:
1167
 
 * 
 
1162
 *
1168
1163
 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
1169
1164
 * in various sizes and widget states. It can provide a #GdkPixbuf
1170
1165
 * for a given size and state on request, and automatically caches
1174
1169
 * using #GtkIconSet directly. The one case where you'd use
1175
1170
 * #GtkIconSet is to create application-specific icon sets to place in
1176
1171
 * a #GtkIconFactory.
1177
 
 * 
 
1172
 *
1178
1173
 * Return value: a new #GtkIconSet
1179
 
 **/
 
1174
 */
1180
1175
GtkIconSet*
1181
1176
gtk_icon_set_new (void)
1182
1177
{
1189
1184
  icon_set->cache = NULL;
1190
1185
  icon_set->cache_size = 0;
1191
1186
  icon_set->cache_serial = cache_serial;
1192
 
  
 
1187
 
1193
1188
  return icon_set;
1194
1189
}
1195
1190
 
1196
1191
/**
1197
1192
 * gtk_icon_set_new_from_pixbuf:
1198
1193
 * @pixbuf: a #GdkPixbuf
1199
 
 * 
 
1194
 *
1200
1195
 * Creates a new #GtkIconSet with @pixbuf as the default/fallback
1201
1196
 * source image. If you don't add any additional #GtkIconSource to the
1202
1197
 * icon set, all variants of the icon will be created from @pixbuf,
1203
1198
 * using scaling, pixelation, etc. as required to adjust the icon size
1204
1199
 * or make the icon look insensitive/prelighted.
1205
 
 * 
 
1200
 *
1206
1201
 * Return value: a new #GtkIconSet
1207
 
 **/
 
1202
 */
1208
1203
GtkIconSet *
1209
1204
gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
1210
1205
{
1219
1214
  gtk_icon_source_set_pixbuf (&source, pixbuf);
1220
1215
  gtk_icon_set_add_source (set, &source);
1221
1216
  gtk_icon_source_set_pixbuf (&source, NULL);
1222
 
  
 
1217
 
1223
1218
  return set;
1224
1219
}
1225
1220
 
1227
1222
/**
1228
1223
 * gtk_icon_set_ref:
1229
1224
 * @icon_set: a #GtkIconSet.
1230
 
 * 
 
1225
 *
1231
1226
 * Increments the reference count on @icon_set.
1232
 
 * 
 
1227
 *
1233
1228
 * Return value: @icon_set.
1234
 
 **/
 
1229
 */
1235
1230
GtkIconSet*
1236
1231
gtk_icon_set_ref (GtkIconSet *icon_set)
1237
1232
{
1246
1241
/**
1247
1242
 * gtk_icon_set_unref:
1248
1243
 * @icon_set: a #GtkIconSet
1249
 
 * 
 
1244
 *
1250
1245
 * Decrements the reference count on @icon_set, and frees memory
1251
1246
 * if the reference count reaches 0.
1252
 
 **/
 
1247
 */
1253
1248
void
1254
1249
gtk_icon_set_unref (GtkIconSet *icon_set)
1255
1250
{
1279
1274
gtk_icon_set_get_type (void)
1280
1275
{
1281
1276
  static GType our_type = 0;
1282
 
  
 
1277
 
1283
1278
  if (our_type == 0)
1284
1279
    our_type = g_boxed_type_register_static (I_("GtkIconSet"),
1285
1280
                                             (GBoxedCopyFunc) gtk_icon_set_ref,
1291
1286
/**
1292
1287
 * gtk_icon_set_copy:
1293
1288
 * @icon_set: a #GtkIconSet
1294
 
 * 
1295
 
 * Copies @icon_set by value. 
1296
 
 * 
 
1289
 *
 
1290
 * Copies @icon_set by value.
 
1291
 *
1297
1292
 * Return value: a new #GtkIconSet identical to the first.
1298
1293
 **/
1299
1294
GtkIconSet*
1301
1296
{
1302
1297
  GtkIconSet *copy;
1303
1298
  GSList *tmp_list;
1304
 
  
 
1299
 
1305
1300
  copy = gtk_icon_set_new ();
1306
1301
 
1307
1302
  tmp_list = icon_set->sources;
1318
1313
  copy->cache = copy_cache (icon_set, copy);
1319
1314
  copy->cache_size = icon_set->cache_size;
1320
1315
  copy->cache_serial = icon_set->cache_serial;
1321
 
  
 
1316
 
1322
1317
  return copy;
1323
1318
}
1324
1319
 
1334
1329
   */
1335
1330
#if 1
1336
1331
  return lhs == rhs;
1337
 
#else  
1338
 
  
 
1332
#else
 
1333
 
1339
1334
  gint r_w, r_h, l_w, l_h;
1340
1335
 
1341
1336
  icon_size_lookup_intern (NULL, rhs, &r_w, &r_h);
1354
1349
{
1355
1350
  GtkIconSource *source;
1356
1351
  GSList *tmp_list;
1357
 
  
 
1352
 
1358
1353
  /* We need to find the best icon source.  Direction matters more
1359
1354
   * than state, state matters more than size. icon_set->sources
1360
1355
   * is sorted according to wildness, so if we take the first
1362
1357
   * multiple matches for a given "wildness" then the RC file contained
1363
1358
   * dumb stuff, and we end up with an arbitrary matching source)
1364
1359
   */
1365
 
  
 
1360
 
1366
1361
  source = NULL;
1367
1362
  tmp_list = icon_set->sources;
1368
1363
  while (tmp_list != NULL)
1369
1364
    {
1370
1365
      GtkIconSource *s = tmp_list->data;
1371
 
      
 
1366
 
1372
1367
      if ((s->any_direction || (s->direction == direction)) &&
1373
1368
          (s->any_state || (s->state == state)) &&
1374
1369
          (s->any_size || size == (GtkIconSize)-1 || (sizes_equivalent (size, s->size))))
1379
1374
              break;
1380
1375
            }
1381
1376
        }
1382
 
          
 
1377
 
1383
1378
      tmp_list = g_slist_next (tmp_list);
1384
1379
    }
1385
1380
 
1386
1381
  return source;
1387
1382
}
1388
 
  
 
1383
 
1389
1384
static gboolean
1390
1385
ensure_filename_pixbuf (GtkIconSet    *icon_set,
1391
1386
                        GtkIconSource *source)
1393
1388
  if (source->filename_pixbuf == NULL)
1394
1389
    {
1395
1390
      GError *error = NULL;
1396
 
      
 
1391
 
1397
1392
      source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
1398
 
      
 
1393
 
1399
1394
      if (source->filename_pixbuf == NULL)
1400
1395
        {
1401
1396
          /* Remove this icon source so we don't keep trying to
1403
1398
           */
1404
1399
          g_warning (_("Error loading icon: %s"), error->message);
1405
1400
          g_error_free (error);
1406
 
          
 
1401
 
1407
1402
          icon_set->sources = g_slist_remove (icon_set->sources, source);
1408
 
          
 
1403
 
1409
1404
          gtk_icon_source_free (source);
1410
1405
 
1411
1406
          return FALSE;
1412
1407
        }
1413
1408
    }
1414
 
  
 
1409
 
1415
1410
  return TRUE;
1416
1411
}
1417
 
 
 
1412
 
1418
1413
static GdkPixbuf *
1419
1414
render_icon_name_pixbuf (GtkIconSource    *icon_source,
1420
1415
                         GtkStyle         *style,
1433
1428
  gint width, height, pixel_size;
1434
1429
  gint *sizes, *s, dist;
1435
1430
  GError *error = NULL;
1436
 
  
 
1431
 
1437
1432
  if (widget && gtk_widget_has_screen (widget))
1438
1433
    screen = gtk_widget_get_screen (widget);
1439
1434
  else if (style && style->colormap)
1452
1447
    {
1453
1448
      if (size == (GtkIconSize)-1)
1454
1449
        {
1455
 
          /* Find an available size close to 48 
1456
 
           */
 
1450
          /* Find an available size close to 48 */
1457
1451
          sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
1458
1452
          dist = 1000;
1459
1453
          width = height = 48;
1472
1466
                      dist = 48 - *s;
1473
1467
                    }
1474
1468
                }
1475
 
              else 
 
1469
              else
1476
1470
                {
1477
1471
                  if (*s - 48 < dist)
1478
1472
                    {
1481
1475
                    }
1482
1476
                }
1483
1477
            }
1484
 
          
 
1478
 
1485
1479
          g_free (sizes);
1486
1480
        }
1487
1481
      else
1500
1494
 
1501
1495
  if (!tmp_pixbuf)
1502
1496
    {
1503
 
      g_warning ("Error loading theme icon '%s' for stock: %s", 
1504
 
                 icon_source->source.icon_name, error->message);
1505
 
      g_error_free (error);
 
1497
      g_warning ("Error loading theme icon '%s' for stock: %s",
 
1498
                 icon_source->source.icon_name, error ? error->message : "");
 
1499
      if (error)
 
1500
        g_error_free (error);
1506
1501
      return NULL;
1507
1502
    }
1508
 
  
 
1503
 
1509
1504
  tmp_source = *icon_source;
1510
1505
  tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
1511
1506
  tmp_source.source.pixbuf = tmp_pixbuf;
1547
1542
  while (pixbuf == NULL)
1548
1543
    {
1549
1544
      GtkIconSource *source = find_best_matching_source (icon_set, direction, state, size, failed);
1550
 
      
 
1545
 
1551
1546
      if (source == NULL)
1552
1547
        break;
1553
1548
 
1612
1607
      gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
1613
1608
      g_object_unref (pixbuf);
1614
1609
    }
1615
 
  
 
1610
 
1616
1611
  return gtk_style_render_icon (style,
1617
1612
                                &fallback_source,
1618
1613
                                direction,
1636
1631
 * @detail: detail to pass to the theme engine, or %NULL.
1637
1632
 *          Note that passing a detail of anything but %NULL
1638
1633
 *          will disable caching.
1639
 
 * 
 
1634
 *
1640
1635
 * Renders an icon using gtk_style_render_icon(). In most cases,
1641
1636
 * gtk_widget_render_icon() is better, since it automatically provides
1642
1637
 * most of the arguments from the current widget settings.  This
1643
1638
 * function never returns %NULL; if the icon can't be rendered
1644
1639
 * (perhaps because an image file fails to load), a default "missing
1645
1640
 * image" icon will be returned instead.
1646
 
 * 
 
1641
 *
1647
1642
 * Return value: a #GdkPixbuf to be displayed
1648
 
 **/
 
1643
 */
1649
1644
GdkPixbuf*
1650
1645
gtk_icon_set_render_icon (GtkIconSet        *icon_set,
1651
1646
                          GtkStyle          *style,
1656
1651
                          const char        *detail)
1657
1652
{
1658
1653
  GdkPixbuf *icon;
1659
 
  
 
1654
 
1660
1655
  g_return_val_if_fail (icon_set != NULL, NULL);
1661
1656
  g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
1662
1657
 
1667
1662
    {
1668
1663
      icon = find_in_cache (icon_set, style, direction,
1669
1664
                        state, size);
1670
 
      
 
1665
 
1671
1666
      if (icon)
1672
1667
        {
1673
1668
          g_object_ref (icon);
1684
1679
 
1685
1680
  if (detail == NULL)
1686
1681
    add_to_cache (icon_set, style, direction, state, size, icon);
1687
 
  
 
1682
 
1688
1683
  return icon;
1689
1684
}
1690
1685
 
1726
1721
 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
1727
1722
 * work with. The base images and when to use them are described by
1728
1723
 * a #GtkIconSource.
1729
 
 * 
 
1724
 *
1730
1725
 * This function copies @source, so you can reuse the same source immediately
1731
1726
 * without affecting the icon set.
1732
1727
 *
1745
1740
 *
1746
1741
 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
1747
1742
 * default icon source based on the given pixbuf.
1748
 
 * 
1749
 
 **/
 
1743
 */
1750
1744
void
1751
 
gtk_icon_set_add_source (GtkIconSet *icon_set,
 
1745
gtk_icon_set_add_source (GtkIconSet          *icon_set,
1752
1746
                         const GtkIconSource *source)
1753
1747
{
1754
1748
  g_return_if_fail (icon_set != NULL);
1759
1753
      g_warning ("Useless empty GtkIconSource");
1760
1754
      return;
1761
1755
    }
1762
 
  
 
1756
 
1763
1757
  icon_set->sources = g_slist_insert_sorted (icon_set->sources,
1764
1758
                                             gtk_icon_source_copy (source),
1765
1759
                                             icon_source_compare);
1773
1767
 *
1774
1768
 * Obtains a list of icon sizes this icon set can render. The returned
1775
1769
 * array must be freed with g_free().
1776
 
 * 
1777
 
 **/
 
1770
 */
1778
1771
void
1779
1772
gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
1780
1773
                        GtkIconSize **sizes,
1783
1776
  GSList *tmp_list;
1784
1777
  gboolean all_sizes = FALSE;
1785
1778
  GSList *specifics = NULL;
1786
 
  
 
1779
 
1787
1780
  g_return_if_fail (icon_set != NULL);
1788
1781
  g_return_if_fail (sizes != NULL);
1789
1782
  g_return_if_fail (n_sizes != NULL);
1790
 
  
 
1783
 
1791
1784
  tmp_list = icon_set->sources;
1792
1785
  while (tmp_list != NULL)
1793
1786
    {
1802
1795
        }
1803
1796
      else
1804
1797
        specifics = g_slist_prepend (specifics, GINT_TO_POINTER (source->size));
1805
 
      
 
1798
 
1806
1799
      tmp_list = g_slist_next (tmp_list);
1807
1800
    }
1808
1801
 
1812
1805
      gint i;
1813
1806
 
1814
1807
      init_icon_sizes ();
1815
 
      
 
1808
 
1816
1809
      *sizes = g_new (GtkIconSize, icon_sizes_used);
1817
1810
      *n_sizes = icon_sizes_used - 1;
1818
 
      
1819
 
      i = 1;      
 
1811
 
 
1812
      i = 1;
1820
1813
      while (i < icon_sizes_used)
1821
1814
        {
1822
1815
          (*sizes)[i - 1] = icon_sizes[i].size;
1826
1819
  else
1827
1820
    {
1828
1821
      gint i;
1829
 
      
 
1822
 
1830
1823
      *n_sizes = g_slist_length (specifics);
1831
1824
      *sizes = g_new (GtkIconSize, *n_sizes);
1832
1825
 
1847
1840
 
1848
1841
/**
1849
1842
 * gtk_icon_source_new:
1850
 
 * 
 
1843
 *
1851
1844
 * Creates a new #GtkIconSource. A #GtkIconSource contains a #GdkPixbuf (or
1852
1845
 * image filename) that serves as the base image for one or more of the
1853
1846
 * icons in a #GtkIconSet, along with a specification for which icons in the
1854
1847
 * icon set will be based on that pixbuf or image file. An icon set contains
1855
1848
 * a set of icons that represent "the same" logical concept in different states,
1856
1849
 * different global text directions, and different sizes.
1857
 
 * 
 
1850
 *
1858
1851
 * So for example a web browser's "Back to Previous Page" icon might
1859
1852
 * point in a different direction in Hebrew and in English; it might
1860
1853
 * look different when insensitive; and it might change size depending
1861
1854
 * on toolbar mode (small/large icons). So a single icon set would
1862
1855
 * contain all those variants of the icon. #GtkIconSet contains a list
1863
1856
 * of #GtkIconSource from which it can derive specific icon variants in
1864
 
 * the set. 
 
1857
 * the set.
1865
1858
 *
1866
1859
 * In the simplest case, #GtkIconSet contains one source pixbuf from
1867
1860
 * which it derives all variants. The convenience function
1876
1869
 * By default, the icon source has all parameters wildcarded. That is,
1877
1870
 * the icon source will be used as the base icon for any desired text
1878
1871
 * direction, widget state, or icon size.
1879
 
 * 
 
1872
 *
1880
1873
 * Return value: a new #GtkIconSource
1881
 
 **/
 
1874
 */
1882
1875
GtkIconSource*
1883
1876
gtk_icon_source_new (void)
1884
1877
{
1885
1878
  GtkIconSource *src;
1886
 
  
 
1879
 
1887
1880
  src = g_new0 (GtkIconSource, 1);
1888
1881
 
1889
1882
  src->direction = GTK_TEXT_DIR_NONE;
1890
1883
  src->size = GTK_ICON_SIZE_INVALID;
1891
1884
  src->state = GTK_STATE_NORMAL;
1892
 
  
 
1885
 
1893
1886
  src->any_direction = TRUE;
1894
1887
  src->any_state = TRUE;
1895
1888
  src->any_size = TRUE;
1896
 
  
 
1889
 
1897
1890
  return src;
1898
1891
}
1899
1892
 
1900
1893
/**
1901
1894
 * gtk_icon_source_copy:
1902
1895
 * @source: a #GtkIconSource
1903
 
 * 
 
1896
 *
1904
1897
 * Creates a copy of @source; mostly useful for language bindings.
1905
 
 * 
 
1898
 *
1906
1899
 * Return value: a new #GtkIconSource
1907
 
 **/
 
1900
 */
1908
1901
GtkIconSource*
1909
1902
gtk_icon_source_copy (const GtkIconSource *source)
1910
1903
{
1911
1904
  GtkIconSource *copy;
1912
 
  
 
1905
 
1913
1906
  g_return_val_if_fail (source != NULL, NULL);
1914
1907
 
1915
1908
  copy = g_new (GtkIconSource, 1);
1916
1909
 
1917
1910
  *copy = *source;
1918
 
  
 
1911
 
1919
1912
  switch (copy->type)
1920
1913
    {
1921
1914
    case GTK_ICON_SOURCE_EMPTY:
1945
1938
/**
1946
1939
 * gtk_icon_source_free:
1947
1940
 * @source: a #GtkIconSource
1948
 
 * 
 
1941
 *
1949
1942
 * Frees a dynamically-allocated icon source, along with its
1950
1943
 * filename, size, and pixbuf fields if those are not %NULL.
1951
 
 **/
 
1944
 */
1952
1945
void
1953
1946
gtk_icon_source_free (GtkIconSource *source)
1954
1947
{
1962
1955
gtk_icon_source_get_type (void)
1963
1956
{
1964
1957
  static GType our_type = 0;
1965
 
  
 
1958
 
1966
1959
  if (our_type == 0)
1967
1960
    our_type = g_boxed_type_register_static (I_("GtkIconSource"),
1968
1961
                                             (GBoxedCopyFunc) gtk_icon_source_copy,
2012
2005
 * @filename: image file to use
2013
2006
 *
2014
2007
 * Sets the name of an image file to use as a base image when creating
2015
 
 * icon variants for #GtkIconSet. The filename must be absolute. 
2016
 
 **/
 
2008
 * icon variants for #GtkIconSet. The filename must be absolute.
 
2009
 */
2017
2010
void
2018
2011
gtk_icon_source_set_filename (GtkIconSource *source,
2019
2012
                              const gchar   *filename)
2024
2017
  if (source->type == GTK_ICON_SOURCE_FILENAME &&
2025
2018
      source->source.filename == filename)
2026
2019
    return;
2027
 
  
 
2020
 
2028
2021
  icon_source_clear (source);
2029
 
  
 
2022
 
2030
2023
  if (filename != NULL)
2031
2024
    {
2032
2025
      source->type = GTK_ICON_SOURCE_FILENAME;
2044
2037
 *
2045
2038
 * Sets the name of an icon to look up in the current icon theme
2046
2039
 * to use as a base image when creating icon variants for #GtkIconSet.
2047
 
 **/
 
2040
 */
2048
2041
void
2049
2042
gtk_icon_source_set_icon_name (GtkIconSource *source,
2050
2043
                               const gchar   *icon_name)
2056
2049
    return;
2057
2050
 
2058
2051
  icon_source_clear (source);
2059
 
  
 
2052
 
2060
2053
  if (icon_name != NULL)
2061
2054
    {
2062
2055
      source->type = GTK_ICON_SOURCE_ICON_NAME;
2071
2064
 *
2072
2065
 * Sets a pixbuf to use as a base image when creating icon variants
2073
2066
 * for #GtkIconSet.
2074
 
 **/
 
2067
 */
2075
2068
void
2076
2069
gtk_icon_source_set_pixbuf (GtkIconSource *source,
2077
2070
                            GdkPixbuf     *pixbuf)
2078
2071
{
2079
2072
  g_return_if_fail (source != NULL);
2080
2073
  g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2081
 
  
 
2074
 
2082
2075
  if (source->type == GTK_ICON_SOURCE_PIXBUF &&
2083
2076
      source->source.pixbuf == pixbuf)
2084
2077
    return;
2085
2078
 
2086
2079
  icon_source_clear (source);
2087
 
  
 
2080
 
2088
2081
  if (pixbuf != NULL)
2089
2082
    {
2090
2083
      source->type = GTK_ICON_SOURCE_PIXBUF;
2095
2088
/**
2096
2089
 * gtk_icon_source_get_filename:
2097
2090
 * @source: a #GtkIconSource
2098
 
 * 
 
2091
 *
2099
2092
 * Retrieves the source filename, or %NULL if none is set. The
2100
2093
 * filename is not a copy, and should not be modified or expected to
2101
2094
 * persist beyond the lifetime of the icon source.
2102
 
 * 
 
2095
 *
2103
2096
 * Return value: image filename. This string must not be modified
2104
2097
 * or freed.
2105
 
 **/
 
2098
 */
2106
2099
G_CONST_RETURN gchar*
2107
2100
gtk_icon_source_get_filename (const GtkIconSource *source)
2108
2101
{
2117
2110
/**
2118
2111
 * gtk_icon_source_get_icon_name:
2119
2112
 * @source: a #GtkIconSource
2120
 
 * 
 
2113
 *
2121
2114
 * Retrieves the source icon name, or %NULL if none is set. The
2122
2115
 * icon_name is not a copy, and should not be modified or expected to
2123
2116
 * persist beyond the lifetime of the icon source.
2124
 
 * 
 
2117
 *
2125
2118
 * Return value: icon name. This string must not be modified or freed.
2126
 
 **/
 
2119
 */
2127
2120
G_CONST_RETURN gchar*
2128
2121
gtk_icon_source_get_icon_name (const GtkIconSource *source)
2129
2122
{
2139
2132
/**
2140
2133
 * gtk_icon_source_get_pixbuf:
2141
2134
 * @source: a #GtkIconSource
2142
 
 * 
 
2135
 *
2143
2136
 * Retrieves the source pixbuf, or %NULL if none is set.
2144
2137
 * In addition, if a filename source is in use, this
2145
2138
 * function in some cases will return the pixbuf from
2147
2140
 * for the GtkIconSource passed to the GtkStyle::render_icon()
2148
2141
 * virtual function. The reference count on the pixbuf is
2149
2142
 * not incremented.
2150
 
 * 
 
2143
 *
2151
2144
 * Return value: source pixbuf
2152
 
 **/
 
2145
 */
2153
2146
GdkPixbuf*
2154
2147
gtk_icon_source_get_pixbuf (const GtkIconSource *source)
2155
2148
{
2156
2149
  g_return_val_if_fail (source != NULL, NULL);
2157
 
  
 
2150
 
2158
2151
  if (source->type == GTK_ICON_SOURCE_PIXBUF)
2159
2152
    return source->source.pixbuf;
2160
2153
  else if (source->type == GTK_ICON_SOURCE_FILENAME)
2177
2170
 *
2178
2171
 * #GtkIconSet prefers non-wildcarded sources (exact matches) over
2179
2172
 * wildcarded sources, and will use an exact match when possible.
2180
 
 * 
2181
 
 **/
 
2173
 */
2182
2174
void
2183
2175
gtk_icon_source_set_direction_wildcarded (GtkIconSource *source,
2184
2176
                                          gboolean       setting)
2206
2198
 * produce an appropriate icon for a given state, for example
2207
2199
 * lightening an image on prelight, but will not modify source images
2208
2200
 * that match exactly.
2209
 
 **/
 
2201
 */
2210
2202
void
2211
2203
gtk_icon_source_set_state_wildcarded (GtkIconSource *source,
2212
2204
                                      gboolean       setting)
2234
2226
 * #GtkIconSet will normally scale wildcarded source images to produce
2235
2227
 * an appropriate icon at a given size, but will not change the size
2236
2228
 * of source images that match exactly.
2237
 
 **/
 
2229
 */
2238
2230
void
2239
2231
gtk_icon_source_set_size_wildcarded (GtkIconSource *source,
2240
2232
                                     gboolean       setting)
2241
2233
{
2242
2234
  g_return_if_fail (source != NULL);
2243
2235
 
2244
 
  source->any_size = setting != FALSE;  
 
2236
  source->any_size = setting != FALSE;
2245
2237
}
2246
2238
 
2247
2239
/**
2248
2240
 * gtk_icon_source_get_size_wildcarded:
2249
2241
 * @source: a #GtkIconSource
2250
 
 * 
 
2242
 *
2251
2243
 * Gets the value set by gtk_icon_source_set_size_wildcarded().
2252
 
 * 
 
2244
 *
2253
2245
 * Return value: %TRUE if this icon source is a base for any icon size variant
2254
 
 **/
 
2246
 */
2255
2247
gboolean
2256
2248
gtk_icon_source_get_size_wildcarded (const GtkIconSource *source)
2257
2249
{
2258
2250
  g_return_val_if_fail (source != NULL, TRUE);
2259
 
  
 
2251
 
2260
2252
  return source->any_size;
2261
2253
}
2262
2254
 
2263
2255
/**
2264
2256
 * gtk_icon_source_get_state_wildcarded:
2265
2257
 * @source: a #GtkIconSource
2266
 
 * 
 
2258
 *
2267
2259
 * Gets the value set by gtk_icon_source_set_state_wildcarded().
2268
 
 * 
 
2260
 *
2269
2261
 * Return value: %TRUE if this icon source is a base for any widget state variant
2270
 
 **/
 
2262
 */
2271
2263
gboolean
2272
2264
gtk_icon_source_get_state_wildcarded (const GtkIconSource *source)
2273
2265
{
2279
2271
/**
2280
2272
 * gtk_icon_source_get_direction_wildcarded:
2281
2273
 * @source: a #GtkIconSource
2282
 
 * 
 
2274
 *
2283
2275
 * Gets the value set by gtk_icon_source_set_direction_wildcarded().
2284
 
 * 
 
2276
 *
2285
2277
 * Return value: %TRUE if this icon source is a base for any text direction variant
2286
 
 **/
 
2278
 */
2287
2279
gboolean
2288
2280
gtk_icon_source_get_direction_wildcarded (const GtkIconSource *source)
2289
2281
{
2299
2291
 *
2300
2292
 * Sets the text direction this icon source is intended to be used
2301
2293
 * with.
2302
 
 * 
 
2294
 *
2303
2295
 * Setting the text direction on an icon source makes no difference
2304
2296
 * if the text direction is wildcarded. Therefore, you should usually
2305
2297
 * call gtk_icon_source_set_direction_wildcarded() to un-wildcard it
2306
2298
 * in addition to calling this function.
2307
 
 * 
2308
 
 **/
 
2299
 */
2309
2300
void
2310
2301
gtk_icon_source_set_direction (GtkIconSource   *source,
2311
2302
                               GtkTextDirection direction)
2322
2313
 *
2323
2314
 * Sets the widget state this icon source is intended to be used
2324
2315
 * with.
2325
 
 * 
 
2316
 *
2326
2317
 * Setting the widget state on an icon source makes no difference
2327
2318
 * if the state is wildcarded. Therefore, you should usually
2328
2319
 * call gtk_icon_source_set_state_wildcarded() to un-wildcard it
2329
2320
 * in addition to calling this function.
2330
 
 * 
2331
 
 **/
 
2321
 */
2332
2322
void
2333
2323
gtk_icon_source_set_state (GtkIconSource *source,
2334
2324
                           GtkStateType   state)
2345
2335
 *
2346
2336
 * Sets the icon size this icon source is intended to be used
2347
2337
 * with.
2348
 
 * 
 
2338
 *
2349
2339
 * Setting the icon size on an icon source makes no difference
2350
2340
 * if the size is wildcarded. Therefore, you should usually
2351
2341
 * call gtk_icon_source_set_size_wildcarded() to un-wildcard it
2352
2342
 * in addition to calling this function.
2353
 
 * 
2354
 
 **/
 
2343
 */
2355
2344
void
2356
2345
gtk_icon_source_set_size (GtkIconSource *source,
2357
2346
                          GtkIconSize    size)
2364
2353
/**
2365
2354
 * gtk_icon_source_get_direction:
2366
2355
 * @source: a #GtkIconSource
2367
 
 * 
 
2356
 *
2368
2357
 * Obtains the text direction this icon source applies to. The return
2369
 
 * value is only useful/meaningful if the text direction is <emphasis>not</emphasis> 
 
2358
 * value is only useful/meaningful if the text direction is <emphasis>not</emphasis>
2370
2359
 * wildcarded.
2371
 
 * 
 
2360
 *
2372
2361
 * Return value: text direction this source matches
2373
 
 **/
 
2362
 */
2374
2363
GtkTextDirection
2375
2364
gtk_icon_source_get_direction (const GtkIconSource *source)
2376
2365
{
2382
2371
/**
2383
2372
 * gtk_icon_source_get_state:
2384
2373
 * @source: a #GtkIconSource
2385
 
 * 
 
2374
 *
2386
2375
 * Obtains the widget state this icon source applies to. The return
2387
2376
 * value is only useful/meaningful if the widget state is <emphasis>not</emphasis>
2388
2377
 * wildcarded.
2389
 
 * 
 
2378
 *
2390
2379
 * Return value: widget state this source matches
2391
 
 **/
 
2380
 */
2392
2381
GtkStateType
2393
2382
gtk_icon_source_get_state (const GtkIconSource *source)
2394
2383
{
2400
2389
/**
2401
2390
 * gtk_icon_source_get_size:
2402
2391
 * @source: a #GtkIconSource
2403
 
 * 
 
2392
 *
2404
2393
 * Obtains the icon size this source applies to. The return value
2405
2394
 * is only useful/meaningful if the icon size is <emphasis>not</emphasis> wildcarded.
2406
 
 * 
 
2395
 *
2407
2396
 * Return value: icon size this source matches.
2408
 
 **/
 
2397
 */
2409
2398
GtkIconSize
2410
2399
gtk_icon_source_get_size (const GtkIconSource *source)
2411
2400
{
2463
2452
  GSList *prev;
2464
2453
 
2465
2454
  ensure_cache_up_to_date (icon_set);
2466
 
  
 
2455
 
2467
2456
  prev = NULL;
2468
2457
  tmp_list = icon_set->cache;
2469
2458
  while (tmp_list != NULL)
2482
2471
              tmp_list->next = icon_set->cache;
2483
2472
              icon_set->cache = tmp_list;
2484
2473
            }
2485
 
          
 
2474
 
2486
2475
          return icon->pixbuf;
2487
2476
        }
2488
 
          
 
2477
 
2489
2478
      prev = tmp_list;
2490
2479
      tmp_list = g_slist_next (tmp_list);
2491
2480
    }
2511
2500
   * its address could be reused by another style, creating a
2512
2501
   * really weird bug
2513
2502
   */
2514
 
  
 
2503
 
2515
2504
  if (style)
2516
2505
    g_object_ref (style);
2517
2506
 
2527
2516
 
2528
2517
  if (icon->style)
2529
2518
    attach_to_style (icon_set, icon->style);
2530
 
  
 
2519
 
2531
2520
  if (icon_set->cache_size >= NUM_CACHED_ICONS)
2532
2521
    {
2533
2522
      /* Remove oldest item in the cache */
2534
2523
      GSList *tmp_list;
2535
 
      
 
2524
 
2536
2525
      tmp_list = icon_set->cache;
2537
2526
 
2538
2527
      /* Find next-to-last link */
2582
2571
              last_style = icon->style;
2583
2572
            }
2584
2573
        }
2585
 
      
2586
 
      cached_icon_free (icon);      
2587
 
      
 
2574
 
 
2575
      cached_icon_free (icon);
 
2576
 
2588
2577
      tmp_list = g_slist_next (tmp_list);
2589
2578
    }
2590
2579
 
2599
2588
  GSList *copy = NULL;
2600
2589
 
2601
2590
  ensure_cache_up_to_date (icon_set);
2602
 
  
 
2591
 
2603
2592
  tmp_list = icon_set->cache;
2604
2593
  while (tmp_list != NULL)
2605
2594
    {
2613
2602
          attach_to_style (copy_recipient, icon_copy->style);
2614
2603
          g_object_ref (icon_copy->style);
2615
2604
        }
2616
 
        
 
2605
 
2617
2606
      g_object_ref (icon_copy->pixbuf);
2618
2607
 
2619
2608
      icon_copy->size = icon->size;
2620
 
      
2621
 
      copy = g_slist_prepend (copy, icon_copy);      
2622
 
      
 
2609
 
 
2610
      copy = g_slist_prepend (copy, icon_copy);
 
2611
 
2623
2612
      tmp_list = g_slist_next (tmp_list);
2624
2613
    }
2625
2614
 
2673
2662
   * time all cache entries will have the same style,
2674
2663
   * so this is faster anyway.
2675
2664
   */
2676
 
  
 
2665
 
2677
2666
  clear_cache (icon_set, FALSE);
2678
2667
}
2679
2668
 
2681
2670
style_dnotify (gpointer data)
2682
2671
{
2683
2672
  GHashTable *table = data;
2684
 
  
 
2673
 
2685
2674
  g_hash_table_foreach (table, iconsets_foreach, NULL);
2686
2675
 
2687
2676
  g_hash_table_destroy (table);
2696
2685
 
2697
2686
/**
2698
2687
 * _gtk_icon_factory_list_ids:
2699
 
 * 
 
2688
 *
2700
2689
 * Gets all known IDs stored in an existing icon factory.
2701
2690
 * The strings in the returned list aren't copied.
2702
2691
 * The list itself should be freed.
2703
 
 * 
 
2692
 *
2704
2693
 * Return value: List of ids in icon factories
2705
 
 **/
 
2694
 */
2706
2695
GList*
2707
2696
_gtk_icon_factory_list_ids (void)
2708
2697
{
2712
2701
  ids = NULL;
2713
2702
 
2714
2703
  _gtk_icon_factory_ensure_default_icons ();
2715
 
  
 
2704
 
2716
2705
  tmp_list = all_icon_factories;
2717
2706
  while (tmp_list != NULL)
2718
2707
    {
2719
2708
      GList *these_ids;
2720
 
      
 
2709
 
2721
2710
      GtkIconFactory *factory = GTK_ICON_FACTORY (tmp_list->data);
2722
2711
 
2723
2712
      these_ids = g_hash_table_get_keys (factory->icons);
2724
 
      
 
2713
 
2725
2714
      ids = g_list_concat (ids, these_ids);
2726
 
      
 
2715
 
2727
2716
      tmp_list = g_slist_next (tmp_list);
2728
2717
    }
2729
2718
 
2733
2722
typedef struct {
2734
2723
  GSList *sources;
2735
2724
  gboolean in_source;
2736
 
  
 
2725
 
2737
2726
} IconFactoryParserData;
2738
2727
 
2739
2728
typedef struct {
2764
2753
  IconSourceParserData *source_data;
2765
2754
  gchar *error_msg;
2766
2755
  GQuark error_domain;
2767
 
  
 
2756
 
2768
2757
  parser_data = (IconFactoryParserData*)user_data;
2769
2758
 
2770
2759
  if (!parser_data->in_source)
2787
2776
          goto error;
2788
2777
        }
2789
2778
    }
2790
 
  
 
2779
 
2791
2780
  for (i = 0; names[i]; i++)
2792
2781
    {
2793
2782
      if (strcmp (names[i], "stock-id") == 0)
2851
2840
  {
2852
2841
    gchar *tmp;
2853
2842
    gint line_number, char_number;
2854
 
    
 
2843
 
2855
2844
    g_markup_parse_context_get_position (context,
2856
2845
                                         &line_number,
2857
2846
                                         &char_number);
2865
2854
                 tmp);
2866
2855
#else
2867
2856
    g_warning ("%s", tmp);
2868
 
#endif    
 
2857
#endif
2869
2858
    g_free (tmp);
2870
2859
    g_free (stock_id);
2871
2860
    g_free (filename);
2909
2898
                                           gpointer     *user_data)
2910
2899
{
2911
2900
  GtkIconFactory *icon_factory;
2912
 
  
 
2901
 
2913
2902
  icon_factory = GTK_ICON_FACTORY (buildable);
2914
2903
 
2915
2904
  if (strcmp (tagname, "sources") == 0)