use GtkToolItem in toolbars

This commit is contained in:
Garux
2020-05-22 00:23:41 +03:00
parent 495e90e6a9
commit 95809d79f5
11 changed files with 102 additions and 81 deletions

View File

@@ -41,6 +41,9 @@ void button_connect_callback( GtkButton* button, const Callback& callback ){
g_signal_connect_closure( G_OBJECT( button ), "clicked", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), FALSE );
#endif
}
void button_connect_callback( GtkToolButton* button, const Callback& callback ){
g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
}
guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ){
#if 1
@@ -51,6 +54,11 @@ guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& c
g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) );
return handler;
}
guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback ){
guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) );
return handler;
}
void button_set_icon( GtkButton* button, const char* icon ){
GtkImage* image = new_local_image( icon );
@@ -69,6 +77,12 @@ void toggle_button_set_active_no_signal( GtkToggleButton* button, gboolean activ
gtk_toggle_button_set_active( button, active );
g_signal_handler_unblock( G_OBJECT( button ), handler_id );
}
void toggle_button_set_active_no_signal( GtkToggleToolButton* button, gboolean active ){
guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
g_signal_handler_block( G_OBJECT( button ), handler_id );
gtk_toggle_tool_button_set_active( button, active );
g_signal_handler_unblock( G_OBJECT( button ), handler_id );
}
void radio_button_print_state( GtkRadioButton* button ){

View File

@@ -25,17 +25,22 @@
#include "generic/callbackfwd.h"
typedef struct _GtkButton GtkButton;
typedef struct _GtkToolButton GtkToolButton;
typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkToggleToolButton GtkToggleToolButton;
typedef struct _GtkRadioButton GtkRadioButton;
typedef int gint;
typedef gint gboolean;
typedef unsigned int guint;
void button_connect_callback( GtkButton* button, const Callback& callback );
void button_connect_callback( GtkToolButton* button, const Callback& callback );
guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback );
guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback );
void button_set_icon( GtkButton* button, const char* icon );
void toggle_button_set_active_no_signal( GtkToggleButton* item, gboolean active );
void toggle_button_set_active_no_signal( GtkToggleToolButton* item, gboolean active );
void radio_button_set_active( GtkRadioButton* radio, int index );
void radio_button_set_active_no_signal( GtkRadioButton* radio, int index );

View File

@@ -27,51 +27,61 @@
#include "accelerator.h"
#include "button.h"
#include "image.h"
#include "closure.h"
#include "pointer.h"
GtkToolbar* toolbar_new(){
GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
gtk_orientable_set_orientation( GTK_ORIENTABLE( toolbar ), GTK_ORIENTATION_HORIZONTAL );
gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
gtk_toolbar_set_show_arrow( toolbar, FALSE );
gtk_widget_show( GTK_WIDGET( toolbar ) );
return toolbar;
}
void toolbar_append_space( GtkToolbar* toolbar ){
GtkToolItem* space = gtk_separator_tool_item_new();
gtk_widget_show( GTK_WIDGET( space ) );
gtk_toolbar_insert( toolbar, space, -1 );
}
void toolbar_append( GtkToolbar* toolbar, GtkButton* button, const char* description ){
gtk_widget_show( GTK_WIDGET( button ) );
gtk_button_set_relief( button, GTK_RELIEF_NONE );
gtk_widget_set_can_focus( GTK_WIDGET( button ), FALSE );
gtk_widget_set_can_default( GTK_WIDGET( button ), FALSE );
gtk_toolbar_append_element( toolbar, GTK_TOOLBAR_CHILD_WIDGET, GTK_WIDGET( button ), "", description, "", 0, 0, 0 );
void toolbar_append( GtkToolbar* toolbar, GtkToolItem* button, const char* description ){
gtk_widget_show_all( GTK_WIDGET( button ) );
gtk_tool_item_set_tooltip_text( button, description );
// gtk_button_set_relief( button, GTK_RELIEF_NONE );
// gtk_widget_set_can_focus( GTK_WIDGET( button ), FALSE );
// gtk_widget_set_can_default( GTK_WIDGET( button ), FALSE );
gtk_toolbar_insert( toolbar, button, -1 );
}
GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
GtkButton* button = GTK_BUTTON( gtk_button_new() );
button_set_icon( button, icon );
GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
GtkToolButton* button = GTK_TOOL_BUTTON( gtk_tool_button_new( GTK_WIDGET( new_local_image( icon ) ), nullptr ) );
button_connect_callback( button, callback );
toolbar_append( toolbar, button, description );
toolbar_append( toolbar, GTK_TOOL_ITEM( button ), description );
return button;
}
GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
GtkToggleButton* button = GTK_TOGGLE_BUTTON( gtk_toggle_button_new() );
button_set_icon( GTK_BUTTON( button ), icon );
GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
GtkToggleToolButton* button = GTK_TOGGLE_TOOL_BUTTON( gtk_toggle_tool_button_new() );
gtk_tool_button_set_icon_widget( GTK_TOOL_BUTTON( button ), GTK_WIDGET( new_local_image( icon ) ) );
toggle_button_connect_callback( button, callback );
toolbar_append( toolbar, GTK_BUTTON( button ), description );
toolbar_append( toolbar, GTK_TOOL_ITEM( button ), description );
return button;
}
GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){
GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){
return toolbar_append_button( toolbar, description, icon, command.m_callback );
}
void toggle_button_set_active_callback( GtkToggleButton& button, bool active ){
void toggle_button_set_active_callback( GtkToggleToolButton& button, bool active ){
toggle_button_set_active_no_signal( &button, active );
}
typedef ReferenceCaller1<GtkToggleButton, bool, toggle_button_set_active_callback> ToggleButtonSetActiveCaller;
typedef ReferenceCaller1<GtkToggleToolButton, bool, toggle_button_set_active_callback> ToggleButtonSetActiveCaller;
GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
GtkToggleButton* button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback );
GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
GtkToggleToolButton* button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback );
toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button ) );
return button;
}

View File

@@ -24,16 +24,19 @@
#include "generic/callbackfwd.h"
typedef struct _GtkButton GtkButton;
typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkToolItem GtkToolItem;
typedef struct _GtkToolButton GtkToolButton;
typedef struct _GtkToggleToolButton GtkToggleToolButton;
typedef struct _GtkToolbar GtkToolbar;
class Command;
class Toggle;
GtkToolbar* toolbar_new();
void toolbar_append_space( GtkToolbar* toolbar );
GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command );
GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle );
void toolbar_append( GtkToolbar* toolbar, GtkToolItem* button, const char* description );
GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command );
GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle );
#endif