~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/ink-action.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <gtk/gtktoolitem.h>
7
7
#include <gtk/gtktoggletoolbutton.h>
8
8
#include <gtk/gtkcheckmenuitem.h>
 
9
#include <gtk/gtkimagemenuitem.h>
9
10
 
10
11
#include "icon-size.h"
11
12
#include "ink-action.h"
17
18
 
18
19
static void ink_action_class_init( InkActionClass* klass );
19
20
static void ink_action_init( InkAction* action );
 
21
static void ink_action_finalize( GObject* obj );
20
22
static void ink_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec );
21
23
static void ink_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec );
22
24
 
25
27
 
26
28
static GtkActionClass* gInkActionParentClass = 0;
27
29
 
 
30
struct _InkActionPrivate
 
31
{
 
32
    gchar* iconId;
 
33
    Inkscape::IconSize iconSize;
 
34
};
 
35
 
 
36
#define INK_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_ACTION_TYPE, InkActionPrivate ) )
 
37
 
28
38
GType ink_action_get_type( void )
29
39
{
30
40
    static GType myType = 0;
59
69
        gInkActionParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) );
60
70
        GObjectClass * objClass = G_OBJECT_CLASS( klass );
61
71
 
 
72
        objClass->finalize = ink_action_finalize;
62
73
        objClass->get_property = ink_action_get_property;
63
74
        objClass->set_property = ink_action_set_property;
64
75
 
84
95
                                                           (int)Inkscape::ICON_SIZE_DECORATION,
85
96
                                                           (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR,
86
97
                                                           (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
 
98
 
 
99
        g_type_class_add_private( klass, sizeof(InkActionClass) );
87
100
    }
88
101
}
89
102
 
90
103
static void ink_action_init( InkAction* action )
91
104
{
 
105
    action->private_data = INK_ACTION_GET_PRIVATE( action );
 
106
    action->private_data->iconId = 0;
 
107
    action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR;
 
108
}
 
109
 
 
110
static void ink_action_finalize( GObject* obj )
 
111
{
 
112
    InkAction* action = INK_ACTION( obj );
 
113
 
 
114
    g_free( action->private_data->iconId );
 
115
    g_free( action->private_data );
 
116
 
92
117
}
93
118
 
94
119
InkAction* ink_action_new( const gchar *name,
117
142
    switch ( propId ) {
118
143
        case PROP_INK_ID:
119
144
        {
120
 
            //g_value_set_pointer( value, action->private_data->adj );
 
145
            g_value_set_string( value, action->private_data->iconId );
121
146
        }
122
147
        break;
123
148
 
124
149
        case PROP_INK_SIZE:
125
150
        {
126
 
            //g_value_set_pointer( value, action->private_data->adj );
 
151
            g_value_set_int( value, action->private_data->iconSize );
127
152
        }
128
153
        break;
129
154
 
139
164
    switch ( propId ) {
140
165
        case PROP_INK_ID:
141
166
        {
142
 
//          gchar* tmp = action->private_data->iconId;
143
 
//          action->private_data->iconId = g_value_dup_string( value );
144
 
//          g_free( tmp );
 
167
            gchar* tmp = action->private_data->iconId;
 
168
            action->private_data->iconId = g_value_dup_string( value );
 
169
            g_free( tmp );
145
170
        }
146
171
        break;
147
172
 
148
173
        case PROP_INK_SIZE:
149
174
        {
150
 
//          action->private_data->iconSize = g_value_get_( value );
 
175
            action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value );
151
176
        }
152
177
        break;
153
178
 
154
179
        default:
 
180
        {
155
181
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
 
182
        }
156
183
    }
157
184
}
158
185
 
 
186
#include <gtk/gtkstock.h>
 
187
 
159
188
static GtkWidget* ink_action_create_menu_item( GtkAction* action )
160
189
{
 
190
    InkAction* act = INK_ACTION( action );
161
191
    GtkWidget* item = 0;
162
 
    g_message("INK ACTION CREATE MENU ITEM");
163
 
    item = gInkActionParentClass->create_menu_item( action );
 
192
 
 
193
    if ( act->private_data->iconId ) {
 
194
        gchar* label = 0;
 
195
        g_object_get( G_OBJECT(act), "label", &label, NULL );
 
196
 
 
197
        item = gtk_image_menu_item_new_with_mnemonic( label );
 
198
        GtkWidget* child = sp_icon_new( Inkscape::ICON_SIZE_MENU, act->private_data->iconId );
 
199
        // TODO this work-around is until SPIcon will live properly inside of a popup menu
 
200
        if ( SP_IS_ICON(child) ) {
 
201
            SPIcon* icon = SP_ICON(child);
 
202
            sp_icon_fetch_pixbuf( icon );
 
203
            GdkPixbuf* target = gtk_action_is_sensitive(action) ? icon->pb : icon->pb_faded;
 
204
            if ( target ) {
 
205
                child = gtk_image_new_from_pixbuf( target );
 
206
                gtk_widget_destroy( GTK_WIDGET(icon) );
 
207
            }
 
208
        }
 
209
        gtk_widget_show_all( child );
 
210
        gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(item), child );
 
211
 
 
212
        g_free( label );
 
213
        label = 0;
 
214
    } else {
 
215
        item = gInkActionParentClass->create_menu_item( action );
 
216
    }
 
217
 
164
218
    return item;
165
219
}
166
220
 
167
221
static GtkWidget* ink_action_create_tool_item( GtkAction* action )
168
222
{
169
 
    GtkWidget* item = 0;
170
 
    g_message("INK ACTION CREATE TOOL ITEM");
171
 
 
172
 
 
173
 
    //item = gInkActionParentClass->create_tool_item( action );
174
 
    GtkTooltips *tt = gtk_tooltips_new();
175
 
    GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
176
 
                                                 SP_BUTTON_TYPE_NORMAL,
177
 
                                                 NULL,
178
 
                                                 "use_pressure",
179
 
                                                 _("Use the pressure of the input device to alter the width of the pen"),
180
 
                                                 tt);
181
 
    //g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (sp_ddc_pressure_state_changed), NULL);
182
 
    //gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("tools.calligraphic", "usepressure", 1));
183
 
    item = GTK_WIDGET(gtk_tool_item_new());
184
 
    gtk_container_add( GTK_CONTAINER(item), button );
185
 
 
 
223
    InkAction* act = INK_ACTION( action );
 
224
    GtkWidget* item = gInkActionParentClass->create_tool_item(action);
 
225
 
 
226
    if ( act->private_data->iconId ) {
 
227
        if ( GTK_IS_TOOL_BUTTON(item) ) {
 
228
            GtkToolButton* button = GTK_TOOL_BUTTON(item);
 
229
 
 
230
            GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId );
 
231
            gtk_tool_button_set_icon_widget( button, child );
 
232
        } else {
 
233
            // For now trigger a warning but don't do anything else
 
234
            GtkToolButton* button = GTK_TOOL_BUTTON(item);
 
235
            (void)button;
 
236
        }
 
237
    }
 
238
 
 
239
    // TODO investigate if needed
186
240
    gtk_widget_show_all( item );
187
241
 
188
242
    return item;
205
259
static GtkWidget* ink_toggle_action_create_menu_item( GtkAction* action );
206
260
static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action );
207
261
 
 
262
static void ink_toggle_action_update_icon( InkToggleAction* action );
 
263
 
208
264
static GtkToggleActionClass* gInkToggleActionParentClass = 0;
209
265
 
210
266
struct _InkToggleActionPrivate
245
301
        gInkToggleActionParentClass = GTK_TOGGLE_ACTION_CLASS( g_type_class_peek_parent( klass ) );
246
302
        GObjectClass * objClass = G_OBJECT_CLASS( klass );
247
303
 
248
 
        objClass->finalize = ink_toggle_action_finalize;
 
304
        objClass->finalize = ink_toggle_action_finalize;
249
305
        objClass->get_property = ink_toggle_action_get_property;
250
306
        objClass->set_property = ink_toggle_action_set_property;
251
307
 
340
396
    switch ( propId ) {
341
397
        case PROP_INK_ID:
342
398
        {
343
 
            gchar* tmp = action->private_data->iconId;
344
 
            action->private_data->iconId = g_value_dup_string( value );
345
 
            g_free( tmp );
 
399
            gchar* tmp = action->private_data->iconId;
 
400
            action->private_data->iconId = g_value_dup_string( value );
 
401
            g_free( tmp );
 
402
 
 
403
            ink_toggle_action_update_icon( action );
346
404
        }
347
405
        break;
348
406
 
353
411
        break;
354
412
 
355
413
        default:
356
 
        {
 
414
        {
357
415
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
358
 
        }
 
416
        }
359
417
    }
360
418
}
361
419
 
369
427
static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action )
370
428
{
371
429
    InkToggleAction* act = INK_TOGGLE_ACTION( action );
 
430
 
372
431
    GtkWidget* item = gInkToggleActionParentClass->parent_class.create_tool_item(action);
 
432
    if ( GTK_IS_TOOL_BUTTON(item) ) {
 
433
        GtkToolButton* button = GTK_TOOL_BUTTON(item);
 
434
        if ( act->private_data->iconId ) {
 
435
            GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId );
 
436
            gtk_tool_button_set_icon_widget( button, child );
 
437
        } else {
 
438
            gchar *label;
 
439
            g_object_get (G_OBJECT(action), "short_label", &label, NULL);
 
440
            gtk_tool_button_set_label( button, label );
 
441
        }
 
442
    } else {
 
443
        // For now trigger a warning but don't do anything else
 
444
        GtkToolButton* button = GTK_TOOL_BUTTON(item);
 
445
        (void)button;
 
446
    }
 
447
    gtk_widget_show_all( item );
 
448
 
 
449
    return item;
 
450
}
 
451
 
 
452
 
 
453
static void ink_toggle_action_update_icon( InkToggleAction* action )
 
454
{
 
455
    if ( action ) {
 
456
        GSList* proxies = gtk_action_get_proxies( GTK_ACTION(action) );
 
457
        while ( proxies ) {
 
458
            if ( GTK_IS_TOOL_ITEM(proxies->data) ) {
 
459
                if ( GTK_IS_TOOL_BUTTON(proxies->data) ) {
 
460
                    GtkToolButton* button = GTK_TOOL_BUTTON(proxies->data);
 
461
 
 
462
                    GtkWidget* child = sp_icon_new( action->private_data->iconSize, action->private_data->iconId );
 
463
                    gtk_widget_show_all( child );
 
464
                    gtk_tool_button_set_icon_widget( button, child );
 
465
                }
 
466
            }
 
467
 
 
468
            proxies = g_slist_next( proxies );
 
469
        }
 
470
    }
 
471
}
 
472
 
 
473
 
 
474
/* --------------------------------------------------------------- */
 
475
/* --------------------------------------------------------------- */
 
476
/* --------------------------------------------------------------- */
 
477
/* --------------------------------------------------------------- */
 
478
 
 
479
 
 
480
static void ink_radio_action_class_init( InkRadioActionClass* klass );
 
481
static void ink_radio_action_init( InkRadioAction* action );
 
482
static void ink_radio_action_finalize( GObject* obj );
 
483
static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec );
 
484
static void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec );
 
485
 
 
486
static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action );
 
487
static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action );
 
488
 
 
489
static GtkRadioActionClass* gInkRadioActionParentClass = 0;
 
490
 
 
491
struct _InkRadioActionPrivate
 
492
{
 
493
    gchar* iconId;
 
494
    Inkscape::IconSize iconSize;
 
495
};
 
496
 
 
497
#define INK_RADIO_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_RADIO_ACTION_TYPE, InkRadioActionPrivate ) )
 
498
 
 
499
GType ink_radio_action_get_type( void )
 
500
{
 
501
    static GType myType = 0;
 
502
    if ( !myType ) {
 
503
        static const GTypeInfo myInfo = {
 
504
            sizeof( InkRadioActionClass ),
 
505
            NULL, /* base_init */
 
506
            NULL, /* base_finalize */
 
507
            (GClassInitFunc)ink_radio_action_class_init,
 
508
            NULL, /* class_finalize */
 
509
            NULL, /* class_data */
 
510
            sizeof( InkRadioAction ),
 
511
            0, /* n_preallocs */
 
512
            (GInstanceInitFunc)ink_radio_action_init,
 
513
            NULL
 
514
        };
 
515
 
 
516
        myType = g_type_register_static( GTK_TYPE_RADIO_ACTION, "InkRadioAction", &myInfo, (GTypeFlags)0 );
 
517
    }
 
518
 
 
519
    return myType;
 
520
}
 
521
 
 
522
 
 
523
static void ink_radio_action_class_init( InkRadioActionClass* klass )
 
524
{
 
525
    if ( klass ) {
 
526
        gInkRadioActionParentClass = GTK_RADIO_ACTION_CLASS( g_type_class_peek_parent( klass ) );
 
527
        GObjectClass * objClass = G_OBJECT_CLASS( klass );
 
528
 
 
529
        objClass->finalize = ink_radio_action_finalize;
 
530
        objClass->get_property = ink_radio_action_get_property;
 
531
        objClass->set_property = ink_radio_action_set_property;
 
532
 
 
533
        klass->parent_class.parent_class.parent_class.create_menu_item = ink_radio_action_create_menu_item;
 
534
        klass->parent_class.parent_class.parent_class.create_tool_item = ink_radio_action_create_tool_item;
 
535
        /*klass->parent_class.connect_proxy = connect_proxy;*/
 
536
        /*klass->parent_class.disconnect_proxy = disconnect_proxy;*/
 
537
 
 
538
        g_object_class_install_property( objClass,
 
539
                                         PROP_INK_ID,
 
540
                                         g_param_spec_string( "iconId",
 
541
                                                              "Icon ID",
 
542
                                                              "The id for the icon",
 
543
                                                              "",
 
544
                                                              (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
 
545
 
 
546
        g_object_class_install_property( objClass,
 
547
                                         PROP_INK_SIZE,
 
548
                                         g_param_spec_int( "iconSize",
 
549
                                                           "Icon Size",
 
550
                                                           "The size the icon",
 
551
                                                           (int)Inkscape::ICON_SIZE_MENU,
 
552
                                                           (int)Inkscape::ICON_SIZE_DECORATION,
 
553
                                                           (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR,
 
554
                                                           (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
 
555
 
 
556
        g_type_class_add_private( klass, sizeof(InkRadioActionClass) );
 
557
    }
 
558
}
 
559
 
 
560
static void ink_radio_action_init( InkRadioAction* action )
 
561
{
 
562
    action->private_data = INK_RADIO_ACTION_GET_PRIVATE( action );
 
563
    action->private_data->iconId = 0;
 
564
    action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR;
 
565
}
 
566
 
 
567
static void ink_radio_action_finalize( GObject* obj )
 
568
{
 
569
    InkRadioAction* action = INK_RADIO_ACTION( obj );
 
570
 
 
571
    g_free( action->private_data->iconId );
 
572
    g_free( action->private_data );
 
573
 
 
574
}
 
575
 
 
576
InkRadioAction* ink_radio_action_new( const gchar *name,
 
577
                           const gchar *label,
 
578
                           const gchar *tooltip,
 
579
                           const gchar *inkId,
 
580
                           Inkscape::IconSize size )
 
581
{
 
582
    GObject* obj = (GObject*)g_object_new( INK_RADIO_ACTION_TYPE,
 
583
                                           "name", name,
 
584
                                           "label", label,
 
585
                                           "tooltip", tooltip,
 
586
                                           "iconId", inkId,
 
587
                                           "iconSize", size,
 
588
                                           NULL );
 
589
 
 
590
    InkRadioAction* action = INK_RADIO_ACTION( obj );
 
591
 
 
592
    return action;
 
593
}
 
594
 
 
595
static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec )
 
596
{
 
597
    InkRadioAction* action = INK_RADIO_ACTION( obj );
 
598
    (void)action;
 
599
    switch ( propId ) {
 
600
        case PROP_INK_ID:
 
601
        {
 
602
            g_value_set_string( value, action->private_data->iconId );
 
603
        }
 
604
        break;
 
605
 
 
606
        case PROP_INK_SIZE:
 
607
        {
 
608
            g_value_set_int( value, action->private_data->iconSize );
 
609
        }
 
610
        break;
 
611
 
 
612
        default:
 
613
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
 
614
    }
 
615
}
 
616
 
 
617
void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec )
 
618
{
 
619
    InkRadioAction* action = INK_RADIO_ACTION( obj );
 
620
    (void)action;
 
621
    switch ( propId ) {
 
622
        case PROP_INK_ID:
 
623
        {
 
624
            gchar* tmp = action->private_data->iconId;
 
625
            action->private_data->iconId = g_value_dup_string( value );
 
626
            g_free( tmp );
 
627
        }
 
628
        break;
 
629
 
 
630
        case PROP_INK_SIZE:
 
631
        {
 
632
            action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value );
 
633
        }
 
634
        break;
 
635
 
 
636
        default:
 
637
        {
 
638
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
 
639
        }
 
640
    }
 
641
}
 
642
 
 
643
static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action )
 
644
{
 
645
    GtkWidget* item = gInkRadioActionParentClass->parent_class.parent_class.create_menu_item(action);
 
646
 
 
647
    return item;
 
648
}
 
649
 
 
650
static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action )
 
651
{
 
652
    InkRadioAction* act = INK_RADIO_ACTION( action );
 
653
    GtkWidget* item = gInkRadioActionParentClass->parent_class.parent_class.create_tool_item(action);
373
654
 
374
655
    if ( act->private_data->iconId ) {
375
656
        if ( GTK_IS_TOOL_BUTTON(item) ) {
376
657
            GtkToolButton* button = GTK_TOOL_BUTTON(item);
377
658
 
378
 
            GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId );
379
 
            gtk_tool_button_set_icon_widget( button, child );
380
 
        } else {
 
659
            GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId );
 
660
            gtk_tool_button_set_icon_widget( button, child );
 
661
        } else {
381
662
            // For now trigger a warning but don't do anything else
382
 
            GtkToolButton* button = GTK_TOOL_BUTTON(item);
383
 
            (void)button;
384
 
        }
 
663
            GtkToolButton* button = GTK_TOOL_BUTTON(item);
 
664
            (void)button;
 
665
        }
385
666
    }
386
667
 
387
668
    // TODO investigate if needed