#include "image.h"
#include "pointer.h"
-void clicked_closure_callback( GtkWidget* widget, gpointer data ){
+void clicked_closure_callback( ui::Widget widget, gpointer data ){
( *reinterpret_cast<Callback*>( data ) )( );
}
-void button_connect_callback( GtkButton* button, const Callback& callback ){
+void button_connect_callback( ui::Button button, const Callback& callback ){
#if 1
g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
#else
#endif
}
-void button_connect_callback( GtkToolButton* button, const Callback& callback ){
+void button_connect_callback( ui::ToolButton button, const Callback& callback ){
#if 1
g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
#else
#endif
}
-guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ){
+guint toggle_button_connect_callback( ui::ToggleButton button, const Callback& callback ){
#if 1
guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
#else
return handler;
}
-guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback ){
+guint toggle_button_connect_callback( ui::ToggleToolButton button, const Callback& callback ){
#if 1
guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() );
#else
return handler;
}
-void button_set_icon( GtkButton* button, const char* icon ){
- GtkImage* image = new_local_image( icon );
- gtk_widget_show( GTK_WIDGET( image ) );
+void button_set_icon( ui::Button button, const char* icon ){
+ ui::Image image = ui::Image(new_local_image( icon ));
+ image.show();
gtk_container_add( GTK_CONTAINER( button ), GTK_WIDGET( image ) );
}
-void toggle_button_set_active_no_signal( GtkToggleButton* button, gboolean active ){
+void toggle_button_set_active_no_signal( ui::ToggleButton button, gboolean active ){
//globalOutputStream() << "set active: " << active << "\n";
guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) );
//guint signal_id = g_signal_lookup("toggled", G_OBJECT_TYPE (button));
g_signal_handler_unblock( G_OBJECT( button ), handler_id );
}
-void toggle_button_set_active_no_signal( GtkToggleToolButton* button, gboolean active ){
+void toggle_button_set_active_no_signal( ui::ToggleToolButton 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 );
}
-void radio_button_print_state( GtkRadioButton* button ){
+void radio_button_print_state( ui::RadioButton button ){
globalOutputStream() << "toggle button: ";
for ( GSList* radio = gtk_radio_button_get_group( button ); radio != 0; radio = g_slist_next( radio ) )
{
globalOutputStream() << "\n";
}
-GtkToggleButton* radio_button_get_nth( GtkRadioButton* radio, int index ){
+GtkToggleButton* radio_button_get_nth( ui::RadioButton radio, int index ){
GSList *group = gtk_radio_button_get_group( radio );
return GTK_TOGGLE_BUTTON( g_slist_nth_data( group, g_slist_length( group ) - index - 1 ) );
}
-void radio_button_set_active( GtkRadioButton* radio, int index ){
+void radio_button_set_active( ui::RadioButton radio, int index ){
//radio_button_print_state(radio);
gtk_toggle_button_set_active( radio_button_get_nth( radio, index ), TRUE );
//radio_button_print_state(radio);
}
-void radio_button_set_active_no_signal( GtkRadioButton* radio, int index ){
+void radio_button_set_active_no_signal( ui::RadioButton radio, int index ){
{
for ( GSList* l = gtk_radio_button_get_group( radio ); l != 0; l = g_slist_next( l ) )
{
}
}
-int radio_button_get_active( GtkRadioButton* radio ){
+int radio_button_get_active( ui::RadioButton radio ){
//radio_button_print_state(radio);
GSList *group = gtk_radio_button_get_group( radio );
int index = g_slist_length( group ) - 1;
#if !defined( INCLUDED_GTKUTIL_BUTTON_H )
#define INCLUDED_GTKUTIL_BUTTON_H
-#include <gtk/gtk.h>
+#include <uilib/uilib.h>
#include "generic/callbackfwd.h"
-typedef struct _GtkButton GtkButton;
-typedef struct _GtkToggleButton GtkToggleButton;
-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_connect_callback( ui::Button button, const Callback& callback );
+void button_connect_callback( ui::ToolButton button, const Callback& callback );
+guint toggle_button_connect_callback( ui::ToggleButton button, const Callback& callback );
+guint toggle_button_connect_callback( ui::ToggleToolButton 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 button_set_icon( ui::Button button, const char* icon );
+void toggle_button_set_active_no_signal( ui::ToggleButton item, gboolean active );
+void toggle_button_set_active_no_signal( ui::ToggleToolButton item, gboolean active );
-void radio_button_set_active( GtkRadioButton* radio, int index );
-void radio_button_set_active_no_signal( GtkRadioButton* radio, int index );
-int radio_button_get_active( GtkRadioButton* radio );
+void radio_button_set_active( ui::RadioButton radio, int index );
+void radio_button_set_active_no_signal( ui::RadioButton radio, int index );
+int radio_button_get_active( ui::RadioButton radio );
#endif
gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
// browse button
- GtkButton* button = ui::Button();
+ auto button = ui::Button();
button_set_icon( button, "ellipsis.bmp" );
gtk_widget_show( GTK_WIDGET( button ) );
gtk_box_pack_end( GTK_BOX( hbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
{
public:
GtkHBox* m_hbox;
-GtkRadioButton* m_radio;
+ui::RadioButton m_radio;
RadioHBox( GtkHBox* hbox, GtkRadioButton* radio ) :
m_hbox( hbox ),
m_radio( radio ){
GSList* group = gtk_radio_button_get_group( radio );
for (; group != 0; group = g_slist_next( group ) )
{
- toggle_button_connect_callback( GTK_TOGGLE_BUTTON( group->data ), m_changed );
+ toggle_button_connect_callback( ui::ToggleButton(GTK_TOGGLE_BUTTON( group->data )), m_changed );
}
}
};
gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button));
}
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
- auto button = GTK_TOOL_BUTTON(gtk_tool_button_new(GTK_WIDGET(new_local_image(icon)), nullptr));
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
+ auto button = ui::ToolButton(GTK_TOOL_BUTTON(gtk_tool_button_new(GTK_WIDGET(new_local_image(icon)), nullptr)));
button_connect_callback(button, callback);
toolbar_append(toolbar, GTK_TOOL_ITEM(button), description);
return button;
}
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
- auto button = GTK_TOGGLE_TOOL_BUTTON(gtk_toggle_tool_button_new());
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){
+ auto button = ui::ToggleToolButton(GTK_TOGGLE_TOOL_BUTTON(gtk_toggle_tool_button_new()));
toggle_button_connect_callback(button, callback);
gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), GTK_WIDGET(new_local_image(icon)));
gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), description);
return button;
}
-GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){
+ui::ToolButton 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( GtkToggleToolButton& button, bool active ){
- toggle_button_set_active_no_signal( &button, active );
+ toggle_button_set_active_no_signal( ui::ToggleToolButton(&button), active );
}
using ToggleButtonSetActiveCaller = ReferenceCaller1<GtkToggleToolButton, bool, toggle_button_set_active_callback>;
-GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){
auto button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback );
- toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button ) );
+ GtkToggleToolButton *button_ = button;
+ toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button_ ) );
return button;
}
#define INCLUDED_GTKUTIL_TOOLBAR_H
#include <gtk/gtk.h>
+#include <uilib/uilib.h>
#include "generic/callbackfwd.h"
typedef struct _GtkButton GtkButton;
class Command;
class Toggle;
-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 );
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
+ui::ToolButton toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command );
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback );
+ui::ToggleToolButton toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle );
#endif
Widget root{nullptr};
-#define this (*static_cast<self>(this))
+#define IMPL(T, F) template<> _IMPL(T, F)
+#define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self(F(it)); } }
+
+ template<class T>
+ struct verify;
+
+ template<class T> _IMPL(T,);
+
+#define this verify<self>::test(*static_cast<self>(this))
+
+ IMPL(Editable, GTK_EDITABLE);
void IEditable::editable(bool value)
{
gtk_editable_set_editable(GTK_EDITABLE(this), value);
}
+ IMPL(Widget, GTK_WIDGET);
+
Widget::Widget() : Widget(nullptr)
{}
return ::file_dialog(this, open, title, path, pattern, want_load, want_import, want_save);
}
+ void IWidget::show()
+ {
+ gtk_widget_show(this);
+ }
+
+ IMPL(Window, GTK_WINDOW);
+
Window::Window() : Window(nullptr)
{}
gtk_window_add_accel_group(this, group);
}
+ IMPL(Alignment, GTK_ALIGNMENT);
+
Alignment::Alignment(float xalign, float yalign, float xscale, float yscale)
: Alignment(GTK_ALIGNMENT(gtk_alignment_new(xalign, yalign, xscale, yscale)))
{}
+ IMPL(Frame, GTK_FRAME);
+
Frame::Frame(const char *label) : Frame(GTK_FRAME(gtk_frame_new(label)))
{}
+ IMPL(Button, GTK_BUTTON);
+
Button::Button() : Button(GTK_BUTTON(gtk_button_new()))
{}
Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label)))
{}
+ IMPL(ToggleButton, GTK_TOGGLE_BUTTON);
+
bool IToggleButton::active()
{
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this)) != 0;
}
+ IMPL(CheckButton, GTK_CHECK_BUTTON);
+
CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label)))
{}
+ IMPL(MenuItem, GTK_MENU_ITEM);
+
MenuItem::MenuItem() : MenuItem(GTK_MENU_ITEM(gtk_menu_item_new()))
{}
GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label)))
{}
+ IMPL(TearoffMenuItem, GTK_TEAROFF_MENU_ITEM);
+
TearoffMenuItem::TearoffMenuItem() : TearoffMenuItem(GTK_TEAROFF_MENU_ITEM(gtk_tearoff_menu_item_new()))
{}
+ IMPL(ComboBoxText, GTK_COMBO_BOX_TEXT);
+
ComboBoxText::ComboBoxText() : ComboBoxText(GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new()))
{}
+ IMPL(ScrolledWindow, GTK_SCROLLED_WINDOW);
+
ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr)))
{}
+ IMPL(VBox, GTK_VBOX);
+
VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))
{}
+ IMPL(HBox, GTK_HBOX);
+
HBox::HBox(bool homogenous, int spacing) : HBox(GTK_HBOX(gtk_hbox_new(homogenous, spacing)))
{}
+ IMPL(HPaned, GTK_HPANED);
+
HPaned::HPaned() : HPaned(GTK_HPANED(gtk_hpaned_new()))
{}
+ IMPL(VPaned, GTK_VPANED);
+
VPaned::VPaned() : VPaned(GTK_VPANED(gtk_vpaned_new()))
{}
+ IMPL(Menu, GTK_MENU);
+
Menu::Menu() : Menu(GTK_MENU(gtk_menu_new()))
{}
+ IMPL(Table, GTK_TABLE);
+
Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table(
GTK_TABLE(gtk_table_new(rows, columns, homogenous))
)
{}
+ IMPL(TextView, GTK_TEXT_VIEW);
+
TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new()))
{}
TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model)))
{}
+ IMPL(Label, GTK_LABEL);
+
Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label)))
{}
+ IMPL(Image, GTK_IMAGE);
+
Image::Image() : Image(GTK_IMAGE(gtk_image_new()))
{}
+ IMPL(Entry, GTK_ENTRY);
+
Entry::Entry() : Entry(GTK_ENTRY(gtk_entry_new()))
{}
gtk_entry_set_max_length(this, static_cast<gint>(max_length));
}
+ IMPL(SpinButton, GTK_SPIN_BUTTON);
+
SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton(
GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits)))
{}
+ IMPL(HScale, GTK_HSCALE);
+
HScale::HScale(Adjustment adjustment) : HScale(GTK_HSCALE(gtk_hscale_new(adjustment)))
{}
HScale::HScale(double min, double max, double step) : HScale(GTK_HSCALE(gtk_hscale_new_with_range(min, max, step)))
{}
+ IMPL(Adjustment, GTK_ADJUSTMENT);
+
Adjustment::Adjustment(double value,
double lower, double upper,
double step_increment, double page_increment,
GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size)))
{}
+ IMPL(CellRendererText, GTK_CELL_RENDERER_TEXT);
+
CellRendererText::CellRendererText() : CellRendererText(GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()))
{}
+ IMPL(TreeViewColumn, GTK_TREE_VIEW_COLUMN);
+
TreeViewColumn::TreeViewColumn(const char *title, CellRenderer renderer,
std::initializer_list<TreeViewColumnAttribute> attributes)
: TreeViewColumn(gtk_tree_view_column_new_with_attributes(title, renderer, nullptr))
}
};
+ IMPL(AccelGroup, GTK_ACCEL_GROUP);
+
AccelGroup::AccelGroup() : AccelGroup(GTK_ACCEL_GROUP(gtk_accel_group_new()))
{}
- void IListStore::clear() {
+ IMPL(ListStore, GTK_LIST_STORE);
+
+ void IListStore::clear()
+ {
gtk_list_store_clear(this);
}
+ // IMPL(TreePath, GTK_TREE_PATH);
+
TreePath::TreePath() : TreePath(gtk_tree_path_new())
{}
struct _GtkLabel;
struct _GtkListStore;
struct _GtkMenu;
-struct _GtkMenuShell;
struct _GtkMenuItem;
+struct _GtkMenuShell;
struct _GtkMisc;
struct _GtkObject;
struct _GtkPaned;
+struct _GtkRadioButton;
+struct _GtkRadioToolButton;
struct _GtkRange;
struct _GtkScale;
struct _GtkScrolledWindow;
struct _GtkTearoffMenuItem;
struct _GtkTextView;
struct _GtkToggleButton;
+struct _GtkToggleToolButton;
+struct _GtkToolButton;
+struct _GtkToolItem;
struct _GtkTreeModel;
struct _GtkTreePath;
struct _GtkTreeView;
bool want_import = false,
bool want_save = false
);
+ void show();
);
WRAP(Container, Widget, _GtkContainer, (),
,
);
+ WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
+ ,
+ );
+
WRAP(Item, Bin, _GtkItem, (),
,
);
,
);
+ WRAP(ToolItem, Bin, _GtkToolItem, (),
+ ,
+ );
+
+ WRAP(ToolButton, ToolItem, _GtkToolButton, (),
+ ,
+ );
+
+ WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
+ ,
+ );
+
+ WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
+ ,
+ );
+
WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
ScrolledWindow();
,
void IntRadioImport( GtkRadioButton& widget, int index ){
- radio_button_set_active( &widget, index );
+ radio_button_set_active( ui::RadioButton(&widget), index );
}
void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCallback ){
- importCallback( radio_button_get_active( &widget ) );
+ importCallback( radio_button_get_active( ui::RadioButton(&widget) ) );
}
typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
void update(){
const char* value = SelectedEntity_getValueForKey( m_key.c_str() );
if ( !string_empty( value ) ) {
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), atoi( value ) != 0 );
+ toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), atoi( value ) != 0 );
}
else
{
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_check ), false );
+ toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), false );
}
}
typedef MemberCaller<BooleanAttribute, &BooleanAttribute::update> UpdateCaller;
{
int v = !!( f & ( 1 << spawn_table[i] ) );
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), v );
+ toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), v );
}
}
{
// take care of the remaining ones
for ( int i = g_spawnflag_count; i < MAX_FLAGS; ++i )
{
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] ), FALSE );
+ toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( g_entitySpawnflagsCheck[i] )), FALSE );
}
}
}
class Subdivisions
{
public:
-GtkCheckButton* m_enabled;
+ui::CheckButton m_enabled;
GtkEntry* m_horizontal;
GtkEntry* m_vertical;
-Subdivisions() : m_enabled( 0 ), m_horizontal( 0 ), m_vertical( 0 ){
+Subdivisions() : m_enabled( (GtkCheckButton *) 0 ), m_horizontal( 0 ), m_vertical( 0 ){
}
void update(){
PatchFixedSubdivisions subdivisions;
Scene_PatchGetFixedSubdivisions( subdivisions );
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_enabled ), subdivisions.m_enabled );
+ toggle_button_set_active_no_signal( m_enabled, subdivisions.m_enabled );
if ( subdivisions.m_enabled ) {
entry_set_int( m_horizontal, static_cast<int>( subdivisions.m_x ) );
(GtkAttachOptions)( 0 ), 0, 0 );
}
{
- GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
+ auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() ));
gtk_widget_show( GTK_WIDGET( check ) );
gtk_table_attach( table, GTK_WIDGET( check ), 1, 2, 0, 1,
(GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
for ( GtkCheckButton** p = m_surfaceFlags; p != m_surfaceFlags + 32; ++p )
{
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( *p ), flags.m_surfaceFlags & ( 1 << ( p - m_surfaceFlags ) ) );
+ toggle_button_set_active_no_signal( ui::CheckButton( *p ), flags.m_surfaceFlags & ( 1 << ( p - m_surfaceFlags ) ) );
}
for ( GtkCheckButton** p = m_contentFlags; p != m_contentFlags + 32; ++p )
{
- toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( *p ), flags.m_contentFlags & ( 1 << ( p - m_contentFlags ) ) );
+ toggle_button_set_active_no_signal( ui::CheckButton( *p ), flags.m_contentFlags & ( 1 << ( p - m_contentFlags ) ) );
}
}
}