1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4
/* ***** BEGIN LICENSE BLOCK *****
5
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
17
* The Original Code is EGE Output Action.
19
* The Initial Developer of the Original Code is
21
* Portions created by the Initial Developer are Copyright (C) 2007
22
* the Initial Developer. All Rights Reserved.
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.
38
* ***** END LICENSE BLOCK ***** */
40
/* Note: this file should be kept compilable as both .cpp and .c */
44
#include <gtk/gtkhbox.h>
45
#include <gtk/gtklabel.h>
46
#include <gtk/gtktoolitem.h>
48
#include "ege-output-action.h"
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 );
57
/* static GtkWidget* create_menu_item( GtkAction* action ); */
58
static GtkWidget* create_tool_item( GtkAction* action );
60
static GtkActionClass* gParentClass = 0;
63
struct _EgeOutputActionPrivate
68
#define EGE_OUTPUT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_OUTPUT_ACTION_TYPE, EgeOutputActionPrivate ) )
74
GType ege_output_action_get_type( void )
76
static GType myType = 0;
78
static const GTypeInfo myInfo = {
79
sizeof( EgeOutputActionClass ),
81
NULL, /* base_finalize */
82
(GClassInitFunc)ege_output_action_class_init,
83
NULL, /* class_finalize */
84
NULL, /* class_data */
85
sizeof( EgeOutputAction ),
87
(GInstanceInitFunc)ege_output_action_init,
91
myType = g_type_register_static( GTK_TYPE_ACTION, "EgeOutputAction", &myInfo, (GTypeFlags)0 );
97
void ege_output_action_class_init( EgeOutputActionClass* klass )
100
GObjectClass* objClass = G_OBJECT_CLASS( klass );
101
gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) );
103
objClass->get_property = ege_output_action_get_property;
104
objClass->set_property = ege_output_action_set_property;
106
/* klass->parent_class.create_menu_item = create_menu_item; */
107
klass->parent_class.create_tool_item = create_tool_item;
109
g_object_class_install_property( objClass,
111
g_param_spec_boolean( "use-markup",
113
"If markup should be used",
115
(GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
117
g_type_class_add_private( klass, sizeof(EgeOutputActionClass) );
122
void ege_output_action_init( EgeOutputAction* action )
124
action->private_data = EGE_OUTPUT_ACTION_GET_PRIVATE( action );
125
action->private_data->useMarkup = FALSE;
127
g_signal_connect( action, "notify", G_CALLBACK( fixup_labels ), NULL );
130
EgeOutputAction* ege_output_action_new( const gchar *name,
132
const gchar *tooltip,
133
const gchar *stock_id )
135
GObject* obj = (GObject*)g_object_new( EGE_OUTPUT_ACTION_TYPE,
139
"stock_id", stock_id,
143
EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
148
gboolean ege_output_action_get_use_markup( EgeOutputAction* action )
150
g_return_val_if_fail( IS_EGE_OUTPUT_ACTION(action), FALSE );
152
return action->private_data->useMarkup;
155
void ege_output_action_set_use_markup( EgeOutputAction* action, gboolean setting )
157
g_object_set( G_OBJECT(action), "use-markup", setting, NULL );
160
void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec )
162
EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
164
case PROP_USE_MARKUP:
165
g_value_set_boolean( value, action->private_data->useMarkup );
169
G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
173
void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec )
175
EgeOutputAction* action = EGE_OUTPUT_ACTION( obj );
177
case PROP_USE_MARKUP:
179
action->private_data->useMarkup = g_value_get_boolean( value );
184
G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
189
/* static GtkWidget* create_menu_item( GtkAction* action ) */
191
GtkWidget* create_tool_item( GtkAction* action )
195
if ( IS_EGE_OUTPUT_ACTION(action) )
198
GtkWidget* hb = gtk_hbox_new( FALSE, 5 );
200
memset( &value, 0, sizeof(value) );
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 );
206
item = GTK_WIDGET( gtk_tool_item_new() );
208
lbl = gtk_label_new( " " );
209
gtk_container_add( GTK_CONTAINER(hb), lbl );
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 : " " );
215
lbl = gtk_label_new( sss ? sss : " " );
217
gtk_container_add( GTK_CONTAINER(hb), lbl );
219
lbl = gtk_label_new( " " );
220
gtk_container_add( GTK_CONTAINER(hb), lbl );
222
gtk_container_add( GTK_CONTAINER(item), hb );
224
gtk_widget_show_all( item );
226
item = gParentClass->create_tool_item( action );
232
void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data )
234
/* TODO: handle 'use-markup' getting changed also */
236
if ( arg1 && arg1->name && (strcmp("label", arg1->name) == 0) ) {
237
GSList* proxies = gtk_action_get_proxies( GTK_ACTION(gobject) );
239
g_object_get( gobject, "label", &str, NULL );
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 );
255
gtk_label_set_text( lbl, str );
262
proxies = g_slist_next( proxies );