X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fdialog.cpp;h=66f2d998a31cc2993816d6402d77f5d9c37d9719;hb=b2827b118808cd6929d39ca7c628b8429542984f;hp=a77ddedde753c99b322958ba545262dce3c71a53;hpb=225950494a606af9aac2bc2f06ece70cb2146481;p=xonotic%2Fnetradiant.git diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index a77ddedd..66f2d998 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -28,6 +28,8 @@ #include "dialog.h" +#include + #include "debugging/debugging.h" @@ -46,19 +48,19 @@ ui::Entry DialogEntry_new(){ - auto entry = ui::Entry(); + auto entry = ui::Entry(ui::New); entry.show(); - gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 ); + entry.dimensions(64, -1); return entry; } class DialogEntryRow { public: -DialogEntryRow( ui::Widget row, GtkEntry* entry ) : m_row( row ), m_entry( entry ){ +DialogEntryRow( ui::Widget row, ui::Entry entry ) : m_row( row ), m_entry( entry ){ } ui::Widget m_row; -GtkEntry* m_entry; +ui::Entry m_entry; }; DialogEntryRow DialogEntryRow_new( const char* name ){ @@ -68,7 +70,7 @@ DialogEntryRow DialogEntryRow_new( const char* name ){ auto entry = DialogEntry_new(); alignment.add(entry); - return DialogEntryRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), entry ); + return DialogEntryRow( ui::Widget(DialogRow_new( name, alignment )), entry ); } @@ -81,17 +83,17 @@ ui::SpinButton DialogSpinner_new( double value, double lower, double upper, int } auto spin = ui::SpinButton( ui::Adjustment( value, lower, upper, step, 10, 0 ), step, digits ); spin.show(); - gtk_widget_set_size_request( GTK_WIDGET( spin ), 64, -1 ); + spin.dimensions(64, -1); return spin; } class DialogSpinnerRow { public: -DialogSpinnerRow( ui::Widget row, GtkSpinButton* spin ) : m_row( row ), m_spin( spin ){ +DialogSpinnerRow( ui::Widget row, ui::SpinButton spin ) : m_row( row ), m_spin( spin ){ } ui::Widget m_row; -GtkSpinButton* m_spin; +ui::SpinButton m_spin; }; DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lower, double upper, int fraction ){ @@ -101,202 +103,196 @@ DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lo auto spin = DialogSpinner_new( value, lower, upper, fraction ); alignment.add(spin); - return DialogSpinnerRow( ui::Widget(GTK_WIDGET( DialogRow_new( name, alignment ) )), spin ); + return DialogSpinnerRow( ui::Widget(DialogRow_new( name, alignment )), spin ); } +struct BoolToggle { + static void Export(const ui::ToggleButton &self, const Callback &returnz) { + returnz(self.active()); + } -template< - typename Type_, - typename Other_, - void( *Import ) ( Type_&, Other_ ), - void( *Export ) ( Type_&, const Callback1& ) - > -class ImportExport -{ -public: -typedef Type_ Type; -typedef Other_ Other; + static void Import(ui::ToggleButton &self, bool value) { + self.active(value); + } +}; + +using BoolToggleImportExport = PropertyAdaptor; -typedef ReferenceCaller1 ImportCaller; -typedef ReferenceCaller1&, Export> ExportCaller; +struct IntEntry { + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(atoi(gtk_entry_get_text(self))); + } + + static void Import(ui::Entry &self, int value) { + entry_set_int(self, value); + } }; -typedef ImportExport BoolImportExport; -typedef ImportExport IntImportExport; -typedef ImportExport SizeImportExport; -typedef ImportExport FloatImportExport; -typedef ImportExport StringImportExport; +using IntEntryImportExport = PropertyAdaptor; +struct IntRadio { + static void Export(const ui::RadioButton &self, const Callback &returnz) { + returnz(radio_button_get_active(self)); + } + static void Import(ui::RadioButton &self, int value) { + radio_button_set_active(self, value); + } +}; -void BoolToggleImport( GtkToggleButton& widget, bool value ){ - gtk_toggle_button_set_active( &widget, value ); -} -void BoolToggleExport( GtkToggleButton& widget, const BoolImportCallback& importCallback ){ - importCallback( gtk_toggle_button_get_active( &widget ) != FALSE ); -} -typedef ImportExport BoolToggleImportExport; +using IntRadioImportExport = PropertyAdaptor; +struct IntCombo { + static void Export(const ui::ComboBox &self, const Callback &returnz) { + returnz(gtk_combo_box_get_active(self)); + } -void IntRadioImport( GtkRadioButton& widget, int index ){ - radio_button_set_active( ui::RadioButton(&widget), index ); -} -void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCallback ){ - importCallback( radio_button_get_active( ui::RadioButton(&widget) ) ); -} -typedef ImportExport IntRadioImportExport; + static void Import(ui::ComboBox &self, int value) { + gtk_combo_box_set_active(self, value); + } +}; -void TextEntryImport( GtkEntry& widget, const char* text ){ - gtk_entry_set_text( &widget, text ); -} -void TextEntryExport( GtkEntry& widget, const StringImportCallback& importCallback ){ - importCallback( gtk_entry_get_text( &widget ) ); -} -typedef ImportExport TextEntryImportExport; +using IntComboImportExport = PropertyAdaptor; +struct IntAdjustment { + static void Export(const ui::Adjustment &self, const Callback &returnz) { + returnz(int(gtk_adjustment_get_value(self))); + } -void IntEntryImport( GtkEntry& widget, int value ){ - entry_set_int( ui::Entry(&widget), value ); -} -void IntEntryExport( GtkEntry& widget, const IntImportCallback& importCallback ){ - importCallback( atoi( gtk_entry_get_text( &widget ) ) ); -} -typedef ImportExport IntEntryImportExport; + static void Import(ui::Adjustment &self, int value) { + gtk_adjustment_set_value(self, value); + } +}; +using IntAdjustmentImportExport = PropertyAdaptor; -void SizeEntryImport( GtkEntry& widget, std::size_t value ){ - entry_set_int( ui::Entry(&widget), int(value) ); -} -void SizeEntryExport( GtkEntry& widget, const SizeImportCallback& importCallback ){ - int value = atoi( gtk_entry_get_text( &widget ) ); - if ( value < 0 ) { - value = 0; +struct IntSpinner { + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(gtk_spin_button_get_value_as_int(self)); } - importCallback( value ); -} -typedef ImportExport SizeEntryImportExport; + static void Import(ui::SpinButton &self, int value) { + gtk_spin_button_set_value(self, value); + } +}; -void FloatEntryImport( GtkEntry& widget, float value ){ - entry_set_float( ui::Entry(&widget), value ); -} -void FloatEntryExport( GtkEntry& widget, const FloatImportCallback& importCallback ){ - importCallback( (float)atof( gtk_entry_get_text( &widget ) ) ); -} -typedef ImportExport FloatEntryImportExport; +using IntSpinnerImportExport = PropertyAdaptor; +struct TextEntry { + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(gtk_entry_get_text(self)); + } -void FloatSpinnerImport( GtkSpinButton& widget, float value ){ - gtk_spin_button_set_value( &widget, value ); -} -void FloatSpinnerExport( GtkSpinButton& widget, const FloatImportCallback& importCallback ){ - importCallback( float(gtk_spin_button_get_value( &widget ) ) ); -} -typedef ImportExport FloatSpinnerImportExport; + static void Import(ui::Entry &self, const char *value) { + self.text(value); + } +}; +using TextEntryImportExport = PropertyAdaptor; -void IntSpinnerImport( GtkSpinButton& widget, int value ){ - gtk_spin_button_set_value( &widget, value ); -} -void IntSpinnerExport( GtkSpinButton& widget, const IntImportCallback& importCallback ){ - importCallback( gtk_spin_button_get_value_as_int( &widget ) ); -} -typedef ImportExport IntSpinnerImportExport; +struct SizeEntry { + static void Export(const ui::Entry &self, const Callback &returnz) { + int value = atoi(gtk_entry_get_text(self)); + if (value < 0) { + value = 0; + } + returnz(value); + } + static void Import(ui::Entry &self, std::size_t value) { + entry_set_int(self, int(value)); + } +}; -void IntAdjustmentImport( GtkAdjustment& widget, int value ){ - gtk_adjustment_set_value( &widget, value ); -} -void IntAdjustmentExport( GtkAdjustment& widget, const IntImportCallback& importCallback ){ - importCallback( (int)gtk_adjustment_get_value( &widget ) ); -} -typedef ImportExport IntAdjustmentImportExport; +using SizeEntryImportExport = PropertyAdaptor; +struct FloatEntry { + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(float(atof(gtk_entry_get_text(self)))); + } -void IntComboImport( GtkComboBox& widget, int value ){ - gtk_combo_box_set_active( &widget, value ); -} -void IntComboExport( GtkComboBox& widget, const IntImportCallback& importCallback ){ - importCallback( gtk_combo_box_get_active( &widget ) ); -} -typedef ImportExport IntComboImportExport; + static void Import(ui::Entry &self, float value) { + entry_set_float(self, value); + } +}; + +using FloatEntryImportExport = PropertyAdaptor; + +struct FloatSpinner { + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(float(gtk_spin_button_get_value(self))); + } + + static void Import(ui::SpinButton &self, float value) { + gtk_spin_button_set_value(self, value); + } +}; + +using FloatSpinnerImportExport = PropertyAdaptor; -template -class CallbackDialogData : public DLG_DATA -{ -public: -typedef Callback1 ImportCallback; -typedef Callback1 ExportCallback; -private: -ImportCallback m_importWidget; -ExportCallback m_exportWidget; -ImportCallback m_importViewer; -ExportCallback m_exportViewer; +template +class CallbackDialogData : public DLG_DATA { + Property m_pWidget; + Property m_pData; public: -CallbackDialogData( const ImportCallback& importWidget, const ExportCallback& exportWidget, const ImportCallback& importViewer, const ExportCallback& exportViewer ) - : m_importWidget( importWidget ), m_exportWidget( exportWidget ), m_importViewer( importViewer ), m_exportViewer( exportViewer ){ -} -void release(){ - delete this; -} -void importData() const { - m_exportViewer( m_importWidget ); -} -void exportData() const { - m_exportWidget( m_importViewer ); -} + CallbackDialogData(const Property &pWidget, const Property &pData) + : m_pWidget(pWidget), m_pData(pData) { + } + + void release() { + delete this; + } + + void importData() const { + m_pData.get(m_pWidget.set); + } + + void exportData() const { + m_pWidget.get(m_pData.set); + } }; -template -class AddData -{ -DialogDataList& m_data; -public: -AddData( DialogDataList& data ) : m_data( data ){ -} -void apply( typename Widget::Type& widget, typename Viewer::Type& viewer ) const { - m_data.push_back( - new CallbackDialogData( - typename Widget::ImportCaller( widget ), - typename Widget::ExportCaller( widget ), - typename Viewer::ImportCaller( viewer ), - typename Viewer::ExportCaller( viewer ) - ) - ); -} +template +struct AddDataCustom_Wrapper { + static void Export(const native &self, const Callback &returnz) { + native *p = &const_cast(self); + auto widget = Self::from(p); + Widget::Get::thunk_(widget, returnz); + } + + static void Import(native &self, T value) { + native *p = &self; + auto widget = Self::from(p); + Widget::Set::thunk_(widget, value); + } }; -template -class AddCustomData -{ -DialogDataList& m_data; -public: -AddCustomData( DialogDataList& data ) : m_data( data ){ -} -void apply( - typename Widget::Type& widget, - const Callback1& importViewer, - const Callback1&>& exportViewer - ) const { - m_data.push_back( - new CallbackDialogData( - typename Widget::ImportCaller( widget ), - typename Widget::ExportCaller( widget ), - importViewer, - exportViewer - ) - ); +template +void AddDataCustom(DialogDataList &self, typename Widget::Type widget, Property const &property) { + using Self = typename Widget::Type; + using T = typename Widget::Other; + using native = typename std::remove_pointer::type; + using Wrapper = AddDataCustom_Wrapper; + + self.push_back(new CallbackDialogData( + make_property>(*static_cast(widget)), + property + )); +} + +template +void AddData(DialogDataList &self, typename Widget::Type widget, D &data) { + AddDataCustom(self, widget, make_property>(data)); } -}; // ============================================================================= // Dialog class -Dialog::Dialog() : m_window( 0 ), m_parent( 0 ){ +Dialog::Dialog() : m_window( ui::null ), m_parent( ui::null ){ } Dialog::~Dialog(){ @@ -317,7 +313,7 @@ void Dialog::ShowDlg(){ void Dialog::HideDlg(){ ASSERT_MESSAGE( m_window, "dialog was not constructed" ); exportData(); - gtk_widget_hide( GTK_WIDGET( m_window ) ); + m_window.hide(); } static gint delete_event_callback( ui::Widget widget, GdkEvent* event, gpointer data ){ @@ -330,87 +326,87 @@ void Dialog::Create(){ ASSERT_MESSAGE( !m_window, "dialog cannot be constructed" ); m_window = BuildDialog(); - g_signal_connect( G_OBJECT( m_window ), "delete_event", G_CALLBACK( delete_event_callback ), this ); + m_window.connect( "delete_event", G_CALLBACK( delete_event_callback ), this ); } void Dialog::Destroy(){ ASSERT_MESSAGE( m_window, "dialog cannot be destroyed" ); - gtk_widget_destroy( GTK_WIDGET( m_window ) ); - m_window = ui::Window(); + m_window.destroy(); + m_window = ui::Window{ui::null}; } -void Dialog::AddBoolToggleData( GtkToggleButton& widget, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddBoolToggleData( ui::ToggleButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntRadioData( GtkRadioButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntRadioData( ui::RadioButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddTextEntryData( GtkEntry& widget, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddTextEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntEntryData( GtkEntry& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddSizeEntryData( GtkEntry& widget, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddSizeEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatEntryData( GtkEntry& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddFloatEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddFloatSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntSpinnerData( GtkSpinButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntAdjustmentData( ui::Adjustment widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntComboData( GtkComboBox& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntComboData( ui::ComboBox widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::ToggleButton widget, bool& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkRadioButton& widget, int& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::RadioButton widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, CopiedString& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::Entry widget, CopiedString& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, int& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::Entry widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, std::size_t& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::Entry widget, std::size_t& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, float& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::Entry widget, float& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkSpinButton& widget, float& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::SpinButton widget, float& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkSpinButton& widget, int& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::SpinButton widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkAdjustment& widget, int& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::Adjustment widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkComboBox& widget, int& data ){ - AddData( m_data ).apply( widget, data ); +void Dialog::AddDialogData( ui::ComboBox widget, int& data ){ + AddData( m_data, widget, data ); } void Dialog::exportData(){ @@ -443,7 +439,7 @@ EMessageBoxReturn Dialog::DoModal(){ exportData(); } - gtk_widget_hide( GTK_WIDGET( m_window ) ); + m_window.hide(); PostModal( m_modal.ret ); @@ -451,66 +447,66 @@ EMessageBoxReturn Dialog::DoModal(){ } -ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const char* flag, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){ +ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, Property const &cb ){ auto check = ui::CheckButton( flag ); check.show(); - AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), importViewer, exportViewer ); + AddBoolToggleData( check, cb ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), ui::Widget(GTK_WIDGET( DialogRow_new( name, check ) ) )); + DialogVBox_packRow( vbox, ui::Widget(DialogRow_new( name, check ) )); return check; } -ui::CheckButton Dialog::addCheckBox( ui::Widget vbox, const char* name, const char* flag, bool& data ){ - return addCheckBox( vbox, name, flag, BoolImportCaller( data ), BoolExportCaller( data ) ); +ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data ){ + return addCheckBox(vbox, name, flag, make_property(data)); } -void Dialog::addCombo( ui::Widget vbox, const char* name, StringArrayRange values, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, Property const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show(); { - ui::Widget combo = ui::ComboBoxText(); + auto combo = ui::ComboBoxText(ui::New); for ( StringArrayRange::Iterator i = values.first; i != values.last; ++i ) { gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), *i ); } - AddIntComboData( *GTK_COMBO_BOX( combo ), importViewer, exportViewer ); + AddIntComboData( combo, cb ); combo.show(); alignment.add(combo); } auto row = DialogRow_new( name, alignment ); - DialogVBox_packRow( ui::VBox(GTK_VBOX(vbox)), row ); + DialogVBox_packRow( vbox, row ); } -void Dialog::addCombo( ui::Widget vbox, const char* name, int& data, StringArrayRange values ){ - addCombo( vbox, name, values, IntImportCaller( data ), IntExportCaller( data ) ); +void Dialog::addCombo( ui::VBox vbox, const char* name, int& data, StringArrayRange values ){ + addCombo(vbox, name, values, make_property(data)); } -void Dialog::addSlider( ui::Widget vbox, const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment ){ +void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment ){ #if 0 if ( draw_value == FALSE ) { - ui::Widget hbox2 = ui::HBox( FALSE, 0 ); + auto hbox2 = ui::HBox( FALSE, 0 ); hbox2.show(); - gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox2 ), FALSE, FALSE, 0 ); + vbox.pack_start( hbox2 , FALSE, FALSE, 0 ); { ui::Widget label = ui::Label( low ); label.show(); - gtk_box_pack_start( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 ); + hbox2.pack_start( label, FALSE, FALSE, 0 ); } { ui::Widget label = ui::Label( high ); label.show(); - gtk_box_pack_end( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 ); + hbox2.pack_end(label, FALSE, FALSE, 0); } } #endif // adjustment auto adj = ui::Adjustment( value, lower, upper, step_increment, page_increment, 0 ); - AddIntAdjustmentData( *GTK_ADJUSTMENT(adj), IntImportCaller( data ), IntExportCaller( data ) ); + AddIntAdjustmentData(adj, make_property(data)); // scale auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 ); @@ -525,113 +521,109 @@ void Dialog::addSlider( ui::Widget vbox, const char* name, int& data, gboolean d gtk_scale_set_digits( GTK_SCALE( scale ), 0 ); auto row = DialogRow_new( name, alignment ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row ); + DialogVBox_packRow( vbox, row ); } -void Dialog::addRadio( ui::Widget vbox, const char* name, StringArrayRange names, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, Property const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show();; { RadioHBox radioBox = RadioHBox_new( names ); alignment.add(radioBox.m_hbox); - AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), importViewer, exportViewer ); + AddIntRadioData( radioBox.m_radio, cb ); } auto row = DialogRow_new( name, alignment ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row ); + DialogVBox_packRow( vbox, row ); } -void Dialog::addRadio( ui::Widget vbox, const char* name, int& data, StringArrayRange names ){ - addRadio( vbox, name, names, IntImportCaller( data ), IntExportCaller( data ) ); +void Dialog::addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names ){ + addRadio(vbox, name, names, make_property(data)); } -void Dialog::addRadioIcons( ui::Widget vbox, const char* name, StringArrayRange icons, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - ui::Widget table = ui::Table( 2, icons.last - icons.first, FALSE ); - table.show();; +void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, Property const &cb ){ + auto table = ui::Table(2, icons.last - icons.first, FALSE); + table.show(); - gtk_table_set_row_spacings( GTK_TABLE( table ), 5 ); - gtk_table_set_col_spacings( GTK_TABLE( table ), 5 ); + gtk_table_set_row_spacings(table, 5); + gtk_table_set_col_spacings(table, 5); GSList* group = 0; - ui::Widget radio; + ui::RadioButton radio{ui::null}; for ( StringArrayRange::Iterator icon = icons.first; icon != icons.last; ++icon ) { guint pos = static_cast( icon - icons.first ); auto image = new_local_image( *icon ); image.show(); - gtk_table_attach( GTK_TABLE( table ), GTK_WIDGET( image ), pos, pos + 1, 0, 1, - (GtkAttachOptions) ( 0 ), - (GtkAttachOptions) ( 0 ), 0, 0 ); + table.attach(image, {pos, pos + 1, 0, 1}, {0, 0}); - radio = ui::Widget(gtk_radio_button_new( group )); + radio = ui::RadioButton::from(gtk_radio_button_new( group )); radio.show(); - gtk_table_attach( GTK_TABLE( table ), radio, pos, pos + 1, 1, 2, - (GtkAttachOptions) ( 0 ), - (GtkAttachOptions) ( 0 ), 0, 0 ); + table.attach(radio, {pos, pos + 1, 1, 2}, {0, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( radio ) ); } - AddIntRadioData( *GTK_RADIO_BUTTON( radio ), importViewer, exportViewer ); + AddIntRadioData( radio, cb ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), DialogRow_new( name, table ) ); + DialogVBox_packRow( vbox, DialogRow_new( name, table ) ); } -void Dialog::addRadioIcons( ui::Widget vbox, const char* name, int& data, StringArrayRange icons ){ - addRadioIcons( vbox, name, icons, IntImportCaller( data ), IntExportCaller( data ) ); +void Dialog::addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ){ + addRadioIcons(vbox, name, icons, make_property(data)); } -ui::Widget Dialog::addIntEntry( ui::Widget vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddIntEntryData( *row.m_entry, importViewer, exportViewer ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row ); + AddIntEntryData( row.m_entry, cb ); + DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addSizeEntry( ui::Widget vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){ +ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddSizeEntryData( *row.m_entry, importViewer, exportViewer ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row ); + AddSizeEntryData( row.m_entry, cb ); + DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addFloatEntry( ui::Widget vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ +ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddFloatEntryData( *row.m_entry, importViewer, exportViewer ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row ); + AddFloatEntryData( row.m_entry, cb ); + DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, bool browse_directory, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){ +ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_directory, Property const &cb ){ PathEntry pathEntry = PathEntry_new(); - g_signal_connect( G_OBJECT( pathEntry.m_button ), "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry ); + pathEntry.m_button.connect( "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry ); - AddTextEntryData( *GTK_ENTRY( pathEntry.m_entry ), importViewer, exportViewer ); + AddTextEntryData( pathEntry.m_entry, cb ); - auto row = DialogRow_new( name, ui::Widget(GTK_WIDGET( pathEntry.m_frame )) ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row ); + auto row = DialogRow_new( name, ui::Widget(pathEntry.m_frame ) ); + DialogVBox_packRow( vbox, row ); - return ui::Widget(GTK_WIDGET( row )); + return row; } -ui::Widget Dialog::addPathEntry( ui::Widget vbox, const char* name, CopiedString& data, bool browse_directory ){ - return addPathEntry( vbox, name, browse_directory, StringImportCallback( StringImportCaller( data ) ), StringExportCallback( StringExportCaller( data ) ) ); +ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool browse_directory ){ + return addPathEntry(vbox, name, browse_directory, make_property(data)); } -ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) ); - AddIntSpinnerData( *row.m_spin, importViewer, exportViewer ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row ); - return ui::SpinButton(row.m_spin); + AddIntSpinnerData( row.m_spin, cb ); + DialogVBox_packRow( vbox, row.m_row ); + return row.m_spin; } -ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, int& data, double value, double lower, double upper ){ - return addSpinner( vbox, name, value, lower, upper, IntImportCallback( IntImportCaller( data ) ), IntExportCallback( IntExportCaller( data ) ) ); +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, int& data, double value, double lower, double upper ){ + return addSpinner(vbox, name, value, lower, upper, make_property(data)); } -ui::SpinButton Dialog::addSpinner( ui::Widget vbox, const char* name, double value, double lower, double upper, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) ); - AddFloatSpinnerData( *row.m_spin, importViewer, exportViewer ); - DialogVBox_packRow( ui::VBox(GTK_VBOX( vbox )), row.m_row ); - return ui::SpinButton(row.m_spin); + AddFloatSpinnerData( row.m_spin, cb ); + DialogVBox_packRow( vbox, row.m_row ); + return row.m_spin; }