2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "stream/textstream.h"
27 #include "stream/stringstream.h"
28 #include "generic/callback.h"
33 void clicked_closure_callback( ui::Widget widget, gpointer data ){
34 ( *reinterpret_cast<Callback*>( data ) )( );
37 void button_connect_callback( ui::Button button, const Callback& callback ){
39 g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
41 g_signal_connect_closure( G_OBJECT( button ), "clicked", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), FALSE );
45 void button_connect_callback( ui::ToolButton button, const Callback& callback ){
47 g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
49 g_signal_connect_closure( G_OBJECT( button ), "clicked", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), FALSE );
53 guint toggle_button_connect_callback( ui::ToggleButton button, const Callback& callback ){
55 guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
57 guint handler = g_signal_connect_closure( G_OBJECT( button ), "toggled", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), TRUE );
59 g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) );
63 guint toggle_button_connect_callback( ui::ToggleToolButton button, const Callback& callback ){
65 guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
67 guint handler = g_signal_connect_closure( G_OBJECT( button ), "toggled", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), TRUE );
69 g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) );
73 void button_set_icon( ui::Button button, const char* icon ){
74 ui::Image image = ui::Image(new_local_image( icon ));
79 void toggle_button_set_active_no_signal( ui::ToggleButton button, gboolean active ){
80 //globalOutputStream() << "set active: " << active << "\n";
81 guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
82 //guint signal_id = g_signal_lookup("toggled", G_OBJECT_TYPE (button));
83 //globalOutputStream() << "signal_id: " << signal_id << "\n";
84 //guint found = g_signal_handler_find(G_OBJECT(button), G_SIGNAL_MATCH_ID, signal_id, 0, 0, 0, 0);
85 //globalOutputStream() << " handler found: " << found << "\n";
86 g_signal_handler_block( G_OBJECT( button ), handler_id );
87 gtk_toggle_button_set_active( button, active );
88 g_signal_handler_unblock( G_OBJECT( button ), handler_id );
91 void toggle_button_set_active_no_signal( ui::ToggleToolButton button, gboolean active ){
92 guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
93 g_signal_handler_block( G_OBJECT( button ), handler_id );
94 gtk_toggle_tool_button_set_active( button, active );
95 g_signal_handler_unblock( G_OBJECT( button ), handler_id );
99 void radio_button_print_state( ui::RadioButton button ){
100 globalOutputStream() << "toggle button: ";
101 for ( GSList* radio = gtk_radio_button_get_group( button ); radio != 0; radio = g_slist_next( radio ) )
103 globalOutputStream() << gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( radio->data ) );
105 globalOutputStream() << "\n";
108 GtkToggleButton* radio_button_get_nth( ui::RadioButton radio, int index ){
109 GSList *group = gtk_radio_button_get_group( radio );
110 return GTK_TOGGLE_BUTTON( g_slist_nth_data( group, g_slist_length( group ) - index - 1 ) );
113 void radio_button_set_active( ui::RadioButton radio, int index ){
114 //radio_button_print_state(radio);
115 gtk_toggle_button_set_active( radio_button_get_nth( radio, index ), TRUE );
116 //radio_button_print_state(radio);
119 void radio_button_set_active_no_signal( ui::RadioButton radio, int index ){
121 for ( GSList* l = gtk_radio_button_get_group( radio ); l != 0; l = g_slist_next( l ) )
123 g_signal_handler_block( G_OBJECT( l->data ), gpointer_to_int( g_object_get_data( G_OBJECT( l->data ), "handler" ) ) );
126 radio_button_set_active( radio, index );
128 for ( GSList* l = gtk_radio_button_get_group( radio ); l != 0; l = g_slist_next( l ) )
130 g_signal_handler_unblock( G_OBJECT( l->data ), gpointer_to_int( g_object_get_data( G_OBJECT( l->data ), "handler" ) ) );
135 int radio_button_get_active( ui::RadioButton radio ){
136 //radio_button_print_state(radio);
137 GSList *group = gtk_radio_button_get_group( radio );
138 int index = g_slist_length( group ) - 1;
139 for (; group != 0; group = g_slist_next( group ) )
141 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( group->data ) ) ) {