From ae556acad3c7afe9fe35ba94deb6e1d88c146ad4 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 3 Jan 2018 17:24:13 +1100 Subject: [PATCH] Dialog: wrap GTK widgets in data binding --- libs/uilib/uilib.cpp | 20 ++- libs/uilib/uilib.h | 3 +- radiant/dialog.cpp | 265 +++++++++++++++++----------------- radiant/dialog.h | 199 ++++++++++++++----------- radiant/findtexturedialog.cpp | 6 +- radiant/patchdialog.cpp | 16 +- radiant/surfacedialog.cpp | 4 +- 7 files changed, 280 insertions(+), 233 deletions(-) diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index 563a9793..e4fb3d32 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -46,13 +46,20 @@ namespace ui { template _IMPL(T,); -#define this (verify::test(*static_cast(this))) + template + using pointer_remove_const = std::add_pointer< + typename std::remove_const< + typename std::remove_pointer::type + >::type + >; + +#define this (verify::test(*static_cast(const_cast::type>(this)))) IMPL(Editable, GTK_EDITABLE); void IEditable::editable(bool value) { - gtk_editable_set_editable(GTK_EDITABLE(this), value); + gtk_editable_set_editable(this, value); } IMPL(TreeModel, GTK_TREE_MODEL); @@ -221,9 +228,14 @@ namespace ui { IMPL(ToggleButton, GTK_TOGGLE_BUTTON); - bool IToggleButton::active() + bool IToggleButton::active() const + { + return gtk_toggle_button_get_active(this) != 0; + } + + void IToggleButton::active(bool value) { - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this)) != 0; + gtk_toggle_button_set_active(this, value); } IMPL(CheckButton, GTK_CHECK_BUTTON); diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 1b082456..f873939f 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -338,7 +338,8 @@ namespace ui { WRAP(ToggleButton, Button, _GtkToggleButton, (), , - bool active(); + bool active() const; + void active(bool value); ); WRAP(CheckButton, ToggleButton, _GtkCheckButton, (), diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index ff215079..e32f81c8 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -108,141 +108,139 @@ DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lo struct BoolToggle { - static void Export(const GtkToggleButton &self, const Callback &returnz) { - returnz(gtk_toggle_button_get_active(const_cast(&self)) != FALSE); + static void Export(const ui::ToggleButton &self, const Callback &returnz) { + returnz(self.active()); } - static void Import(GtkToggleButton &self, bool value) { - gtk_toggle_button_set_active(&self, value); + static void Import(ui::ToggleButton &self, bool value) { + self.active(value); } }; -using BoolToggleImportExport = PropertyAdaptor; +using BoolToggleImportExport = PropertyAdaptor; struct IntEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz(atoi(gtk_entry_get_text(const_cast(&self)))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(atoi(gtk_entry_get_text(self))); } - static void Import(GtkEntry &self, int value) { - entry_set_int(ui::Entry(&self), value); + static void Import(ui::Entry &self, int value) { + entry_set_int(self, value); } }; -using IntEntryImportExport = PropertyAdaptor; +using IntEntryImportExport = PropertyAdaptor; struct IntRadio { - static void Export(const GtkRadioButton &self, const Callback &returnz) { - returnz(radio_button_get_active(ui::RadioButton(const_cast(&self)))); + static void Export(const ui::RadioButton &self, const Callback &returnz) { + returnz(radio_button_get_active(self)); } - static void Import(GtkRadioButton &self, int value) { - radio_button_set_active(ui::RadioButton(&self), value); + static void Import(ui::RadioButton &self, int value) { + radio_button_set_active(self, value); } }; -using IntRadioImportExport = PropertyAdaptor; +using IntRadioImportExport = PropertyAdaptor; struct IntCombo { - static void Export(const GtkComboBox &self, const Callback &returnz) { - returnz(gtk_combo_box_get_active(const_cast(&self))); + static void Export(const ui::ComboBox &self, const Callback &returnz) { + returnz(gtk_combo_box_get_active(self)); } - static void Import(GtkComboBox &self, int value) { - gtk_combo_box_set_active(&self, value); + static void Import(ui::ComboBox &self, int value) { + gtk_combo_box_set_active(self, value); } }; -using IntComboImportExport = PropertyAdaptor; +using IntComboImportExport = PropertyAdaptor; struct IntAdjustment { - static void Export(const GtkAdjustment &self, const Callback &returnz) { - returnz((int) gtk_adjustment_get_value(const_cast(&self))); + static void Export(const ui::Adjustment &self, const Callback &returnz) { + returnz(int(gtk_adjustment_get_value(self))); } - static void Import(GtkAdjustment &self, int value) { - gtk_adjustment_set_value(&self, value); + static void Import(ui::Adjustment &self, int value) { + gtk_adjustment_set_value(self, value); } }; -using IntAdjustmentImportExport = PropertyAdaptor; +using IntAdjustmentImportExport = PropertyAdaptor; struct IntSpinner { - static void Export(const GtkSpinButton &self, const Callback &returnz) { - returnz(gtk_spin_button_get_value_as_int(const_cast(&self))); + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(gtk_spin_button_get_value_as_int(self)); } - static void Import(GtkSpinButton &self, int value) { - gtk_spin_button_set_value(&self, value); + static void Import(ui::SpinButton &self, int value) { + gtk_spin_button_set_value(self, value); } }; -using IntSpinnerImportExport = PropertyAdaptor; - -using StringImportExport = PropertyAdaptor; +using IntSpinnerImportExport = PropertyAdaptor; struct TextEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz(gtk_entry_get_text(const_cast(&self))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(gtk_entry_get_text(self)); } - static void Import(GtkEntry &self, const char *value) { - ui::Entry(&self).text(value); + static void Import(ui::Entry &self, const char *value) { + self.text(value); } }; -using TextEntryImportExport = PropertyAdaptor; +using TextEntryImportExport = PropertyAdaptor; struct SizeEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - int value = atoi(gtk_entry_get_text(const_cast(&self))); + 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(GtkEntry &self, std::size_t value) { - entry_set_int(ui::Entry(&self), int(value)); + static void Import(ui::Entry &self, std::size_t value) { + entry_set_int(self, int(value)); } }; -using SizeEntryImportExport = PropertyAdaptor; +using SizeEntryImportExport = PropertyAdaptor; struct FloatEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz((float) atof(gtk_entry_get_text(const_cast(&self)))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(float(atof(gtk_entry_get_text(self)))); } - static void Import(GtkEntry &self, float value) { - entry_set_float(ui::Entry(&self), value); + static void Import(ui::Entry &self, float value) { + entry_set_float(self, value); } }; -using FloatEntryImportExport = PropertyAdaptor; +using FloatEntryImportExport = PropertyAdaptor; struct FloatSpinner { - static void Export(const GtkSpinButton &self, const Callback &returnz) { - returnz(float(gtk_spin_button_get_value(const_cast(&self)))); + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(float(gtk_spin_button_get_value(self))); } - static void Import(GtkSpinButton &self, float value) { - gtk_spin_button_set_value(&self, value); + static void Import(ui::SpinButton &self, float value) { + gtk_spin_button_set_value(self, value); } }; -using FloatSpinnerImportExport = PropertyAdaptor; +using FloatSpinnerImportExport = PropertyAdaptor; template class CallbackDialogData : public DLG_DATA { - Property m_cbWidget; - Property m_cbViewer; + Property m_pWidget; + Property m_pData; public: - CallbackDialogData(const Property &cbWidget, const Property &cbViewer) - : m_cbWidget(cbWidget), m_cbViewer(cbViewer) { + CallbackDialogData(const Property &pWidget, const Property &pData) + : m_pWidget(pWidget), m_pData(pData) { } void release() { @@ -250,36 +248,41 @@ public: } void importData() const { - m_cbViewer.get(m_cbWidget.set); + m_pData.get(m_pWidget.set); } void exportData() const { - m_cbWidget.get(m_cbViewer.set); + m_pWidget.get(m_pData.set); } }; -template -void AddData(DialogDataList &data, typename Widget::Type &widget, typename Viewer::Type &viewer) { - data.push_back( - new CallbackDialogData( - make_property(widget), - make_property(viewer) - ) - ); -} - -template -void AddCustomData( - DialogDataList &data, - typename Widget::Type &widget, - Property const &cbViewer -) { - data.push_back( - new CallbackDialogData( - make_property(widget), - cbViewer - ) - ); +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; + struct Wrapper { + static void Export(const native &self, const Callback &returnz) { + native *p = &const_cast(self); + auto widget = Self(p); + Widget::Get::thunk_(widget, returnz); + } + + static void Import(native &self, T value) { + native *p = &self; + auto widget = Self(p); + Widget::Set::thunk_(widget, value); + } + }; + 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)); } // ============================================================================= @@ -330,76 +333,76 @@ void Dialog::Destroy(){ } -void Dialog::AddBoolToggleData( GtkToggleButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddBoolToggleData( ui::ToggleButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntRadioData( GtkRadioButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntRadioData( ui::RadioButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddTextEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddTextEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddSizeEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddSizeEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddFloatEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddFloatSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntSpinnerData( GtkSpinButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntAdjustmentData( ui::Adjustment widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntComboData( GtkComboBox& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntComboData( ui::ComboBox widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){ - AddData>( m_data, 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, 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, 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, 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, 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, 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, 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, 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, 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, widget, data ); +void Dialog::AddDialogData( ui::ComboBox widget, int& data ){ + AddData( m_data, widget, data ); } void Dialog::exportData(){ @@ -443,7 +446,7 @@ EMessageBoxReturn Dialog::DoModal(){ 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 ), cb ); + AddBoolToggleData( check, cb ); DialogVBox_packRow( vbox, ui::Widget(DialogRow_new( name, check ) )); return check; @@ -464,7 +467,7 @@ void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), *i ); } - AddIntComboData( *GTK_COMBO_BOX( combo ), cb ); + AddIntComboData( combo, cb ); combo.show(); alignment.add(combo); @@ -499,7 +502,7 @@ void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean dra // adjustment auto adj = ui::Adjustment( value, lower, upper, step_increment, page_increment, 0 ); - AddIntAdjustmentData(*GTK_ADJUSTMENT(adj), make_property(data)); + AddIntAdjustmentData(adj, make_property(data)); // scale auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 ); @@ -523,7 +526,7 @@ void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, { RadioHBox radioBox = RadioHBox_new( names ); alignment.add(radioBox.m_hbox); - AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), cb ); + AddIntRadioData( radioBox.m_radio, cb ); } auto row = DialogRow_new( name, alignment ); @@ -557,7 +560,7 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange ic group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( radio ) ); } - AddIntRadioData( *GTK_RADIO_BUTTON( radio ), cb ); + AddIntRadioData( radio, cb ); DialogVBox_packRow( vbox, DialogRow_new( name, table ) ); } @@ -568,21 +571,21 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, int& data, StringAr ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddIntEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddIntEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddSizeEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddSizeEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddFloatEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddFloatEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } @@ -591,7 +594,7 @@ ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_di PathEntry pathEntry = PathEntry_new(); 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), cb ); + AddTextEntryData( pathEntry.m_entry, cb ); auto row = DialogRow_new( name, ui::Widget(pathEntry.m_frame ) ); DialogVBox_packRow( vbox, row ); @@ -605,7 +608,7 @@ ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, CopiedString& 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( *GTK_SPIN_BUTTON(row.m_spin), cb ); + AddIntSpinnerData( row.m_spin, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_spin; } @@ -616,7 +619,7 @@ ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, int& data, d 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( *GTK_SPIN_BUTTON(row.m_spin), cb ); + AddFloatSpinnerData( row.m_spin, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_spin; } diff --git a/radiant/dialog.h b/radiant/dialog.h index 0147eb2c..78efa830 100644 --- a/radiant/dialog.h +++ b/radiant/dialog.h @@ -45,110 +45,141 @@ class CallbackDialogData; typedef std::list DialogDataList; -class Dialog -{ -ui::Window m_window; -DialogDataList m_data; +class Dialog { + ui::Window m_window; + DialogDataList m_data; public: -ModalDialog m_modal; -ui::Window m_parent; + ModalDialog m_modal; + ui::Window m_parent; + + Dialog(); -Dialog(); -virtual ~Dialog(); + virtual ~Dialog(); /*! start modal dialog box you need to use AddModalButton to select eIDOK eIDCANCEL buttons */ -EMessageBoxReturn DoModal(); -void EndModal( EMessageBoxReturn code ); -virtual ui::Window BuildDialog() = 0; -virtual void exportData(); -virtual void importData(); -virtual void PreModal() { }; -virtual void PostModal( EMessageBoxReturn code ) { }; -virtual void ShowDlg(); -virtual void HideDlg(); -void Create(); -void Destroy(); -ui::Window GetWidget(){ - return m_window; -} -const ui::Window GetWidget() const { - return m_window; -} - - ui::CheckButton addCheckBox(ui::VBox vbox, const char *name, const char *flag, Property const &cb); -ui::CheckButton addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data ); - - void addCombo(ui::VBox vbox, const char *name, StringArrayRange values, Property const &cb); -void addCombo( ui::VBox vbox, const char* name, int& data, StringArrayRange values ); -void 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 ); - - void addRadio(ui::VBox vbox, const char *name, StringArrayRange names, Property const &cb); -void addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names ); - - void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, Property const &cb); -void addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ); - - ui::Widget addIntEntry(ui::VBox vbox, const char *name, Property const &cb); -ui::Widget addEntry( ui::VBox vbox, const char* name, int& data ){ - return addIntEntry(vbox, name, make_property(data)); -} - - ui::Widget addSizeEntry(ui::VBox vbox, const char *name, Property const &cb); -ui::Widget addEntry( ui::VBox vbox, const char* name, std::size_t& data ){ - return addSizeEntry(vbox, name, make_property(data)); -} - - ui::Widget addFloatEntry(ui::VBox vbox, const char *name, Property const &cb); -ui::Widget addEntry( ui::VBox vbox, const char* name, float& data ){ - return addFloatEntry(vbox, name, make_property(data)); -} - - ui::Widget - addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, Property const &cb); -ui::Widget addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool directory ); -ui::SpinButton addSpinner( ui::VBox vbox, const char* name, int& data, double value, double lower, double upper ); - - ui::SpinButton - addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, Property const &cb); - - ui::SpinButton addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, - Property const &cb); + EMessageBoxReturn DoModal(); + + void EndModal(EMessageBoxReturn code); + + virtual ui::Window BuildDialog() = 0; + + virtual void exportData(); + + virtual void importData(); + + virtual void PreModal() {}; + + virtual void PostModal(EMessageBoxReturn code) {}; + + virtual void ShowDlg(); + + virtual void HideDlg(); + + void Create(); + + void Destroy(); + + ui::Window GetWidget() { + return m_window; + } + + const ui::Window GetWidget() const { + return m_window; + } + + ui::CheckButton addCheckBox(ui::VBox vbox, const char *name, const char *flag, Property const &cb); + + ui::CheckButton addCheckBox(ui::VBox vbox, const char *name, const char *flag, bool &data); + + void addCombo(ui::VBox vbox, const char *name, StringArrayRange values, Property const &cb); + + void addCombo(ui::VBox vbox, const char *name, int &data, StringArrayRange values); + + void 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); + + void addRadio(ui::VBox vbox, const char *name, StringArrayRange names, Property const &cb); + + void addRadio(ui::VBox vbox, const char *name, int &data, StringArrayRange names); + + void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, Property const &cb); + + void addRadioIcons(ui::VBox vbox, const char *name, int &data, StringArrayRange icons); + + ui::Widget addIntEntry(ui::VBox vbox, const char *name, Property const &cb); + + ui::Widget addEntry(ui::VBox vbox, const char *name, int &data) { + return addIntEntry(vbox, name, make_property(data)); + } + + ui::Widget addSizeEntry(ui::VBox vbox, const char *name, Property const &cb); + + ui::Widget addEntry(ui::VBox vbox, const char *name, std::size_t &data) { + return addSizeEntry(vbox, name, make_property(data)); + } + + ui::Widget addFloatEntry(ui::VBox vbox, const char *name, Property const &cb); + + ui::Widget addEntry(ui::VBox vbox, const char *name, float &data) { + return addFloatEntry(vbox, name, make_property(data)); + } + + ui::Widget addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, Property const &cb); + + ui::Widget addPathEntry(ui::VBox vbox, const char *name, CopiedString &data, bool directory); + + ui::SpinButton addSpinner(ui::VBox vbox, const char *name, int &data, double value, double lower, double upper); + + ui::SpinButton + addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, Property const &cb); + + ui::SpinButton + addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, Property const &cb); protected: - void AddBoolToggleData(struct _GtkToggleButton &object, Property const &cb); + void AddBoolToggleData(ui::ToggleButton object, Property const &cb); + + void AddIntRadioData(ui::RadioButton object, Property const &cb); + + void AddTextEntryData(ui::Entry object, Property const &cb); + + void AddIntEntryData(ui::Entry object, Property const &cb); + + void AddSizeEntryData(ui::Entry object, Property const &cb); + + void AddFloatEntryData(ui::Entry object, Property const &cb); + + void AddFloatSpinnerData(ui::SpinButton object, Property const &cb); + + void AddIntSpinnerData(ui::SpinButton object, Property const &cb); + + void AddIntAdjustmentData(ui::Adjustment object, Property const &cb); + + void AddIntComboData(ui::ComboBox object, Property const &cb); - void AddIntRadioData(struct _GtkRadioButton &object, Property const &cb); + void AddDialogData(ui::ToggleButton object, bool &data); - void AddTextEntryData(struct _GtkEntry &object, Property const &cb); + void AddDialogData(ui::RadioButton object, int &data); - void AddIntEntryData(struct _GtkEntry &object, Property const &cb); + void AddDialogData(ui::Entry object, CopiedString &data); - void AddSizeEntryData(struct _GtkEntry &object, Property const &cb); + void AddDialogData(ui::Entry object, int &data); - void AddFloatEntryData(struct _GtkEntry &object, Property const &cb); + void AddDialogData(ui::Entry object, std::size_t &data); - void AddFloatSpinnerData(struct _GtkSpinButton &object, Property const &cb); + void AddDialogData(ui::Entry object, float &data); - void AddIntSpinnerData(struct _GtkSpinButton &object, Property const &cb); + void AddDialogData(ui::SpinButton object, float &data); - void AddIntAdjustmentData(struct _GtkAdjustment &object, Property const &cb); + void AddDialogData(ui::SpinButton object, int &data); - void AddIntComboData(struct _GtkComboBox &object, Property const &cb); + void AddDialogData(ui::Adjustment object, int &data); -void AddDialogData( struct _GtkToggleButton& object, bool& data ); -void AddDialogData( struct _GtkRadioButton& object, int& data ); -void AddDialogData( struct _GtkEntry& object, CopiedString& data ); -void AddDialogData( struct _GtkEntry& object, int& data ); -void AddDialogData( struct _GtkEntry& object, std::size_t& data ); -void AddDialogData( struct _GtkEntry& object, float& data ); -void AddDialogData( struct _GtkSpinButton& object, float& data ); -void AddDialogData( struct _GtkSpinButton& object, int& data ); -void AddDialogData( struct _GtkAdjustment& object, int& data ); -void AddDialogData( struct _GtkComboBox& object, int& data ); + void AddDialogData(ui::ComboBox object, int &data); }; #endif diff --git a/radiant/findtexturedialog.cpp b/radiant/findtexturedialog.cpp index a511cb1c..d74fc657 100644 --- a/radiant/findtexturedialog.cpp +++ b/radiant/findtexturedialog.cpp @@ -164,7 +164,7 @@ ui::Window FindTextureDialog::BuildDialog(){ table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0}); entry.connect( "focus_in_event", G_CALLBACK( find_focus_in ), 0 ); - AddDialogData( *GTK_ENTRY(entry), m_strFind ); + AddDialogData( entry, m_strFind ); GlobalTextureEntryCompletion::instance().connect( entry ); entry = ui::Entry(ui::New); @@ -172,13 +172,13 @@ ui::Window FindTextureDialog::BuildDialog(){ table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); entry.connect( "focus_in_event", G_CALLBACK( replace_focus_in ), 0 ); - AddDialogData( *GTK_ENTRY(entry), m_strReplace ); + AddDialogData( entry, m_strReplace ); GlobalTextureEntryCompletion::instance().connect( entry ); auto check = ui::CheckButton( "Within selected brushes only" ); check.show(); vbox.pack_start( check, TRUE, TRUE, 0 ); - AddDialogData( *GTK_TOGGLE_BUTTON(check), m_bSelectedOnly ); + AddDialogData( check, m_bSelectedOnly ); vbox = ui::VBox( FALSE, 5 ); vbox.show(); diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index 83037832..6fbbe3e7 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -561,7 +561,7 @@ ui::Window PatchInspector::BuildDialog(){ { auto combo = ui::ComboBoxText(ui::New); combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this ); - AddDialogData( *GTK_COMBO_BOX(combo), m_nRow ); + AddDialogData( combo, m_nRow ); combo.show(); table.attach(combo, {0, 1, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0}); @@ -572,7 +572,7 @@ ui::Window PatchInspector::BuildDialog(){ { auto combo = ui::ComboBoxText(ui::New); combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this ); - AddDialogData( *GTK_COMBO_BOX(combo), m_nCol ); + AddDialogData( combo, m_nCol ); combo.show(); table.attach(combo, {1, 2, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0}); @@ -614,7 +614,7 @@ ui::Window PatchInspector::BuildDialog(){ auto entry = ui::Entry(ui::New); entry.show(); table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0}); - AddDialogData( *GTK_ENTRY(entry), m_fX ); + AddDialogData( entry, m_fX ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } @@ -622,7 +622,7 @@ ui::Window PatchInspector::BuildDialog(){ auto entry = ui::Entry(ui::New); entry.show(); table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); - AddDialogData( *GTK_ENTRY(entry), m_fY ); + AddDialogData( entry, m_fY ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } @@ -630,7 +630,7 @@ ui::Window PatchInspector::BuildDialog(){ auto entry = ui::Entry(ui::New); entry.show(); table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0}); - AddDialogData( *GTK_ENTRY(entry), m_fZ ); + AddDialogData( entry, m_fZ ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } @@ -638,7 +638,7 @@ ui::Window PatchInspector::BuildDialog(){ auto entry = ui::Entry(ui::New); entry.show(); table.attach(entry, {1, 2, 3, 4}, {GTK_EXPAND | GTK_FILL, 0}); - AddDialogData( *GTK_ENTRY(entry), m_fS ); + AddDialogData( entry, m_fS ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } @@ -646,7 +646,7 @@ ui::Window PatchInspector::BuildDialog(){ auto entry = ui::Entry(ui::New); entry.show(); table.attach(entry, {1, 2, 4, 5}, {GTK_EXPAND | GTK_FILL, 0}); - AddDialogData( *GTK_ENTRY(entry), m_fT ); + AddDialogData( entry, m_fT ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } @@ -729,7 +729,7 @@ ui::Window PatchInspector::BuildDialog(){ // gtk_editable_set_editable (GTK_ENTRY (entry), false); entry.show(); vbox2.pack_start( entry, TRUE, TRUE, 0 ); - AddDialogData( *GTK_ENTRY(entry), m_strName ); + AddDialogData( entry, m_strName ); entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 ); } diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index 89df8a77..26389044 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -855,14 +855,14 @@ ui::Window SurfaceInspector::BuildDialog(){ spin.show(); table.attach(spin, {2, 3, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); spin.dimensions(60, -1); - AddDialogData( *GTK_SPIN_BUTTON( spin ), m_fitHorizontal ); + AddDialogData( spin, m_fitHorizontal ); } { auto spin = ui::SpinButton( ui::Adjustment( 1, 0, 1 << 16, 1, 10, 0 ), 0, 6 ); spin.show(); table.attach(spin, {3, 4, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); spin.dimensions(60, -1); - AddDialogData( *GTK_SPIN_BUTTON( spin ), m_fitVertical ); + AddDialogData( spin, m_fitVertical ); } } } -- 2.39.2