~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/ege-output-action.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 */
 
4
/* ***** BEGIN LICENSE BLOCK *****
 
5
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
6
 *
 
7
 * The contents of this file are subject to the Mozilla Public License Version
 
8
 * 1.1 (the "License"); you may not use this file except in compliance with
 
9
 * the License. You may obtain a copy of the License at
 
10
 * http://www.mozilla.org/MPL/
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS" basis,
 
13
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
14
 * for the specific language governing rights and limitations under the
 
15
 * License.
 
16
 *
 
17
 * The Original Code is EGE Output Action.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Jon A. Cruz.
 
21
 * Portions created by the Initial Developer are Copyright (C) 2007
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the MPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the MPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
/* Note: this file should be kept compilable as both .cpp and .c */
 
41
 
 
42
#include <string.h>
 
43
 
 
44
#include <gtk/gtkhbox.h>
 
45
#include <gtk/gtklabel.h>
 
46
#include <gtk/gtktoolitem.h>
 
47
 
 
48
#include "ege-output-action.h"
 
49
 
 
50
 
 
51
static void ege_output_action_class_init( EgeOutputActionClass* klass );
 
52
static void ege_output_action_init( EgeOutputAction* action );
 
53
static void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec );
 
54
static void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec );
 
55
static void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data );
 
56
 
 
57
/* static GtkWidget* create_menu_item( GtkAction* action ); */
 
58
static GtkWidget* create_tool_item( GtkAction* action );
 
59
 
 
60
static GtkActionClass* gParentClass = 0;
 
61
 
 
62
 
 
63
struct _EgeOutputActionPrivate
 
64
{
 
65
    gboolean useMarkup;
 
66
};
 
67
 
 
68
#define EGE_OUTPUT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_OUTPUT_ACTION_TYPE, EgeOutputActionPrivate ) )
 
69
 
 
70
enum {
 
71
    PROP_USE_MARKUP = 1,
 
72
};
 
73
 
 
74
GType ege_output_action_get_type( void )
 
75
{
 
76
    static GType myType = 0;
 
77
    if ( !myType ) {
 
78
        static const GTypeInfo myInfo = {
 
79
            sizeof( EgeOutputActionClass ),
 
80
            NULL, /* base_init */
 
81
            NULL, /* base_finalize */
 
82
            (GClassInitFunc)ege_output_action_class_init,
 
83
            NULL, /* class_finalize */
 
84
            NULL, /* class_data */
 
85
            sizeof( EgeOutputAction ),
 
86
            0, /* n_preallocs */
 
87
            (GInstanceInitFunc)ege_output_action_init,
 
88
            NULL
 
89
        };
 
90
 
 
91
        myType = g_type_register_static( GTK_TYPE_ACTION, "EgeOutputAction", &myInfo, (GTypeFlags)0 );
 
92
    }
 
93
 
 
94
    return myType;
 
95
}
 
96
 
 
97
void ege_output_action_class_init( EgeOutputActionClass* klass )
 
98
{
 
99
    if ( klass ) {
 
100
        GObjectClass* objClass = G_OBJECT_CLASS( klass );
 
101
        gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) );
 
102
 
 
103
        objClass->get_property = ege_output_action_get_property;
 
104
        objClass->set_property = ege_output_action_set_property;
 
105
 
 
106
/*         klass->parent_class.create_menu_item = create_menu_item; */
 
107
        klass->parent_class.create_tool_item = create_tool_item;
 
108
 
 
109
        g_object_class_install_property( objClass,
 
110
                                         PROP_USE_MARKUP,
 
111
                                         g_param_spec_boolean( "use-markup",
 
112
                                                               "UseMarkup",
 
113
                                                               "If markup should be used",
 
114
                                                               FALSE,
 
115
                                                               (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
 
116
 
 
117
        g_type_class_add_private( klass, sizeof(EgeOutputActionClass) );
 
118
    }
 
119
}
 
120
 
 
121
 
 
122
void ege_output_action_init( EgeOutputAction* action )
 
123
{
 
124
    action->private_data = EGE_OUTPUT_ACTION_GET_PRIVATE( action );
 
125
    action->private_data->useMarkup = FALSE;
 
126
 
 
127
    g_signal_connect( action, "notify", G_CALLBACK( fixup_labels ), NULL );
 
128
}
 
129
 
 
130
EgeOutputAction* ege_output_action_new( const gchar *name,
 
131
                                        const gchar *label,
 
132
                                        const gchar *tooltip,
 
133
                                        const gchar *stock_id )
 
134
{
 
135
    GObject* obj = (GObject*)g_object_new( EGE_OUTPUT_ACTION_TYPE,
 
136
                                           "name", name,
 
137
                                           "label", label,
 
138
                                           "tooltip", tooltip,
 
139
                                           "stock_id", stock_id,
 
140
                                           "use-markup", FALSE,
 
141
                                           NULL );
 
142
 
 
143
    EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
 
144
 
 
145
    return action;
 
146
}
 
147
 
 
148
gboolean ege_output_action_get_use_markup( EgeOutputAction* action )
 
149
{
 
150
    g_return_val_if_fail( IS_EGE_OUTPUT_ACTION(action), FALSE );
 
151
 
 
152
    return action->private_data->useMarkup;
 
153
}
 
154
 
 
155
void ege_output_action_set_use_markup( EgeOutputAction* action, gboolean setting )
 
156
{
 
157
    g_object_set( G_OBJECT(action), "use-markup", setting, NULL );
 
158
}
 
159
 
 
160
void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec )
 
161
{
 
162
    EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
 
163
    switch ( propId ) {
 
164
        case PROP_USE_MARKUP:
 
165
            g_value_set_boolean( value, action->private_data->useMarkup );
 
166
            break;
 
167
 
 
168
        default:
 
169
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
 
170
    }
 
171
}
 
172
 
 
173
void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec )
 
174
{
 
175
    EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
 
176
    switch ( propId ) {
 
177
        case PROP_USE_MARKUP:
 
178
        {
 
179
            action->private_data->useMarkup = g_value_get_boolean( value );
 
180
        }
 
181
        break;
 
182
 
 
183
        default:
 
184
            G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
 
185
    }
 
186
}
 
187
 
 
188
 
 
189
/* static GtkWidget* create_menu_item( GtkAction* action ) */
 
190
 
 
191
GtkWidget* create_tool_item( GtkAction* action )
 
192
{
 
193
    GtkWidget* item = 0;
 
194
 
 
195
    if ( IS_EGE_OUTPUT_ACTION(action) )
 
196
    {
 
197
        GValue value;
 
198
        GtkWidget* hb = gtk_hbox_new( FALSE, 5 );
 
199
        GtkWidget* lbl = 0;
 
200
        memset( &value, 0, sizeof(value) );
 
201
 
 
202
        g_value_init( &value, G_TYPE_STRING );
 
203
        g_object_get_property( G_OBJECT(action), "short_label", &value );
 
204
        const gchar* sss = g_value_get_string( &value );
 
205
 
 
206
        item = GTK_WIDGET( gtk_tool_item_new() );
 
207
 
 
208
        lbl = gtk_label_new( " " );
 
209
        gtk_container_add( GTK_CONTAINER(hb), lbl );
 
210
 
 
211
        if ( EGE_OUTPUT_ACTION(action)->private_data->useMarkup ) {
 
212
            lbl = gtk_label_new(NULL);
 
213
            gtk_label_set_markup( GTK_LABEL(lbl), sss ? sss : " " );
 
214
        } else {
 
215
            lbl = gtk_label_new( sss ? sss : " " );
 
216
        }
 
217
        gtk_container_add( GTK_CONTAINER(hb), lbl );
 
218
 
 
219
        lbl = gtk_label_new( " " );
 
220
        gtk_container_add( GTK_CONTAINER(hb), lbl );
 
221
 
 
222
        gtk_container_add( GTK_CONTAINER(item), hb );
 
223
 
 
224
        gtk_widget_show_all( item );
 
225
    } else {
 
226
        item = gParentClass->create_tool_item( action );
 
227
    }
 
228
 
 
229
    return item;
 
230
}
 
231
 
 
232
void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data )
 
233
{
 
234
    /* TODO: handle 'use-markup' getting changed also */
 
235
 
 
236
    if ( arg1 && arg1->name && (strcmp("label", arg1->name) == 0) ) {
 
237
        GSList* proxies = gtk_action_get_proxies( GTK_ACTION(gobject) );
 
238
        gchar* str = 0;
 
239
        g_object_get( gobject, "label", &str, NULL );
 
240
        (void)user_data;
 
241
        while ( proxies ) {
 
242
            if ( GTK_IS_TOOL_ITEM(proxies->data) ) {
 
243
                /* Search for the things we built up in create_tool_item() */
 
244
                GList* children = gtk_container_get_children( GTK_CONTAINER(proxies->data) );
 
245
                if ( children && children->data ) {
 
246
                    if ( GTK_IS_HBOX(children->data) ) {
 
247
                        children = gtk_container_get_children( GTK_CONTAINER(children->data) );
 
248
                        if ( children && g_list_next(children) ) {
 
249
                            GtkWidget* child = GTK_WIDGET( g_list_next(children)->data );
 
250
                            if ( GTK_IS_LABEL(child) ) {
 
251
                                GtkLabel* lbl = GTK_LABEL(child);
 
252
                                if ( EGE_OUTPUT_ACTION(gobject)->private_data->useMarkup ) {
 
253
                                    gtk_label_set_markup( lbl, str );
 
254
                                } else {
 
255
                                    gtk_label_set_text( lbl, str );
 
256
                                }
 
257
                            }
 
258
                        }
 
259
                    }
 
260
                }
 
261
            }
 
262
            proxies = g_slist_next( proxies );
 
263
        }
 
264
        g_free( str );
 
265
    }
 
266
}
 
267