From a96ab55820d22972d17766eb2f5a80bd14e2ca44 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 17 Feb 2016 17:07:24 +1100 Subject: [PATCH] Wrap GtkTreeViewColumn --- contrib/brushexport/interface.cpp | 2 +- libs/uilib/uilib.cpp | 25 +++++++++++++++++++------ libs/uilib/uilib.h | 14 ++++++++++---- radiant/build.cpp | 8 ++++---- radiant/commands.cpp | 8 ++++---- radiant/entityinspector.cpp | 14 +++++++------- radiant/entitylist.cpp | 2 +- radiant/feedback.cpp | 4 ++-- radiant/main.cpp | 2 +- radiant/map.cpp | 8 ++++---- radiant/preferences.cpp | 4 ++-- radiant/texwindow.cpp | 14 ++++++-------- 12 files changed, 61 insertions(+), 44 deletions(-) diff --git a/contrib/brushexport/interface.cpp b/contrib/brushexport/interface.cpp index 5d1f9982..2ac8f977 100644 --- a/contrib/brushexport/interface.cpp +++ b/contrib/brushexport/interface.cpp @@ -214,7 +214,7 @@ void CreateWindow( void ){ GtkTreeViewColumn* col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title( col, "materials" ); gtk_tree_view_append_column( GTK_TREE_VIEW( lookup_widget( wnd, "t_materialist" ) ), col ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( lookup_widget( wnd, "t_materialist" ) ), -1, "", renderer, "text", 0, NULL ); // list store diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index 763029b2..bfcca620 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -91,7 +91,8 @@ namespace ui { double lower, double upper, double step_increment, double page_increment, double page_size) - : Adjustment(GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size))) + : Adjustment( + GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size))) { } Alignment::Alignment(float xalign, float yalign, float xscale, float yscale) @@ -107,8 +108,8 @@ namespace ui { CellRendererText::CellRendererText() : CellRendererText(GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new())) { } - ComboBoxText::ComboBoxText() : ComboBoxText(GTK_COMBO_BOX(gtk_combo_box_new_text())) - { } + ComboBox ComboBoxText() + { return ComboBox(GTK_COMBO_BOX(gtk_combo_box_new_text())); } CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label))) { } @@ -131,16 +132,19 @@ namespace ui { Menu::Menu() : Menu(GTK_MENU(gtk_menu_new())) { } - MenuItem::MenuItem(const char *label, bool mnemonic) : MenuItem(GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label))) + MenuItem::MenuItem(const char *label, bool mnemonic) : MenuItem( + GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label))) { } ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr))) { } - SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton(GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits))) + SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton( + GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits))) { } - Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table(GTK_TABLE(gtk_table_new(rows, columns, homogenous))) + Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table( + GTK_TABLE(gtk_table_new(rows, columns, homogenous))) { } TreePath::TreePath() : TreePath(gtk_tree_path_new()) @@ -152,6 +156,15 @@ namespace ui { TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model))) { } + TreeViewColumn::TreeViewColumn(const char *title, CellRenderer renderer, + std::initializer_list attributes) + : TreeViewColumn(gtk_tree_view_column_new_with_attributes(title, renderer, nullptr)) + { + for (auto &it : attributes) { + gtk_tree_view_column_add_attribute(*this, renderer, it.attribute, it.column); + } + }; + VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing))) { } diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index f9b996c6..5a6e1a58 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -10,7 +10,6 @@ using ui_box = struct _GtkBox; using ui_button = struct _GtkButton; using ui_checkbutton = struct _GtkCheckButton; using ui_combobox = struct _GtkComboBox; -using ui_comboboxtext = ui_combobox; using ui_cellrenderer = struct _GtkCellRenderer; using ui_cellrenderertext = struct _GtkCellRendererText; using ui_entry = struct _GtkEntry; @@ -28,6 +27,7 @@ using ui_table = struct _GtkTable; using ui_treemodel = struct _GtkTreeModel; using ui_treepath = struct _GtkTreePath; using ui_treeview = struct _GtkTreeView; +using ui_treeviewcolumn = struct _GtkTreeViewColumn; using ui_typeinst = struct _GTypeInstance; using ui_vbox = struct _GtkVBox; using ui_widget = struct _GtkWidget; @@ -158,9 +158,7 @@ namespace ui { WRAP(ComboBox, Widget, ui_combobox,); - WRAP(ComboBoxText, ComboBox, ui_comboboxtext, - ComboBoxText(); - ); + ComboBox ComboBoxText(); WRAP(Entry, Widget, ui_entry, Entry(); @@ -210,6 +208,14 @@ namespace ui { TreeView(TreeModel model); ); + struct TreeViewColumnAttribute { + const char *attribute; + int column; + }; + WRAP(TreeViewColumn, Widget, ui_treeviewcolumn, + TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list attributes); + ); + WRAP(VBox, Box, ui_vbox, VBox(bool homogenous, int spacing); ); diff --git a/radiant/build.cpp b/radiant/build.cpp index 2bad89c1..03ebf652 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -882,11 +882,11 @@ ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectLi ui::Widget view = ui::TreeView( ui::TreeModel(GTK_TREE_MODEL( store ) )); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE ); g_signal_connect( renderer, "edited", G_CALLBACK( project_cell_edited ), &projectList ); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 ); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ); @@ -919,11 +919,11 @@ ui::Window BuildMenuDialog_construct( ModalDialog& modal, ProjectList& projectLi ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) )); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); object_set_boolean_property( G_OBJECT( renderer ), "editable", TRUE ); g_signal_connect( renderer, "edited", G_CALLBACK( commands_cell_edited ), store ); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 ); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ); diff --git a/radiant/commands.cpp b/radiant/commands.cpp index b220e3b5..a431257a 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -412,14 +412,14 @@ void DoCommandListDlg(){ gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), false ); // annoying { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Command", renderer, "text", 0, "weight-set", 2, "weight", 3, NULL ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Command", renderer, {{"text", 0}, {"weight-set", 2}, {"weight", 3}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Key", renderer, "text", 1, "weight-set", 2, "weight", 3, NULL ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 1}, {"weight-set", 2}, {"weight", 3}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index 8db78f1c..8b194497 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -679,7 +679,7 @@ ListAttribute( const char* key, const ListAttributeType& type ) : m_combo( 0 ), m_nonModal( ApplyCaller( *this ) ), m_type( type ){ - GtkComboBox* combo = ui::ComboBoxText(); + auto combo = ui::ComboBoxText(); for ( ListAttributeType::const_iterator i = type.begin(); i != type.end(); ++i ) { @@ -1344,8 +1344,8 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){ g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityClassList_keypress ), 0 ); { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Key", renderer, "text", 0, 0 ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Key", renderer, {{"text", 0}} ); gtk_tree_view_append_column( view, column ); } @@ -1426,14 +1426,14 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){ gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, 0 ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 1, 0 ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 1}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } diff --git a/radiant/entitylist.cpp b/radiant/entitylist.cpp index 96de418c..a93d9698 100644 --- a/radiant/entitylist.cpp +++ b/radiant/entitylist.cpp @@ -303,7 +303,7 @@ void EntityList_constructWindow( ui::Window main_window ){ ui::Widget view = ui::Widget(gtk_tree_view_new()); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); GtkTreeViewColumn* column = gtk_tree_view_column_new(); gtk_tree_view_column_pack_start( column, renderer, TRUE ); gtk_tree_view_column_set_cell_data_func( column, renderer, entitylist_treeviewcolumn_celldatafunc, 0, 0 ); diff --git a/radiant/feedback.cpp b/radiant/feedback.cpp index 45bcf9c6..54679a53 100644 --- a/radiant/feedback.cpp +++ b/radiant/feedback.cpp @@ -311,8 +311,8 @@ ui::Window CDbgDlg::BuildDialog(){ gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", 0, NULL ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } diff --git a/radiant/main.cpp b/radiant/main.cpp index 65a45497..d72aa6c8 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -310,7 +310,7 @@ bool handleMessage(){ ScopedLock lock( m_lock ); #if defined _DEBUG m_buffer << "Break into the debugger?\n"; - bool handled = ui::alert( 0, m_buffer.c_str(), "Radiant - Runtime Error", eMB_YESNO, eMB_ICONERROR ) == eIDNO; + bool handled = ui::root.alert( m_buffer.c_str(), "Radiant - Runtime Error", ui::alert_type::YESNO, ui::alert_icon::ERROR ) == ui::alert_response::NO; m_buffer.clear(); return handled; #else diff --git a/radiant/map.cpp b/radiant/map.cpp index 10b60754..0dcf9791 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -850,15 +850,15 @@ void DoMapInfo(){ gtk_tree_view_set_headers_clickable( GTK_TREE_VIEW( view ), TRUE ); { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Entity", renderer, "text", 0, 0 ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Entity", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); gtk_tree_view_column_set_sort_column_id( column, 0 ); } { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Count", renderer, "text", 1, 0 ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Count", renderer, {{"text", 1}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); gtk_tree_view_column_set_sort_column_id( column, 1 ); } diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 7b62beef..86454c66 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -755,8 +755,8 @@ ui::Window PrefsDlg::BuildDialog(){ gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE ); { - GtkCellRenderer* renderer = ui::CellRendererText(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Preferences", renderer, "text", 0, NULL ); + auto renderer = ui::CellRendererText(); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Preferences", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 9ddc26a8..2aad7a3c 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -1529,14 +1529,13 @@ void TreeView_onRowActivated( GtkTreeView* treeview, GtkTreePath* path, GtkTreeV } void TextureBrowser_createTreeViewTree(){ - GtkCellRenderer* renderer; g_TextureBrowser.m_treeViewTree = ui::Widget(GTK_WIDGET( gtk_tree_view_new() )); gtk_tree_view_set_enable_search( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), FALSE ); gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), FALSE ); g_signal_connect( g_TextureBrowser.m_treeViewTree, "row-activated", (GCallback) TreeView_onRowActivated, NULL ); - renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), -1, "", renderer, "text", 0, NULL ); TextureBrowser_constructTreeStore(); @@ -1586,7 +1585,6 @@ gboolean TreeViewTags_onButtonPressed( ui::Widget treeview, GdkEventButton *even } void TextureBrowser_createTreeViewTags(){ - GtkCellRenderer* renderer; g_TextureBrowser.m_treeViewTags = ui::Widget(GTK_WIDGET( gtk_tree_view_new() )); gtk_tree_view_set_enable_search( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), FALSE ); @@ -1594,7 +1592,7 @@ void TextureBrowser_createTreeViewTags(){ gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), FALSE ); - renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), -1, "", renderer, "text", 0, NULL ); TextureBrowser_constructTreeStoreTags(); @@ -2078,7 +2076,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ GtkTreeSortable* sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_assigned_store ); gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); g_TextureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_assigned_store ) )); g_object_unref( G_OBJECT( g_TextureBrowser.m_assigned_store ) ); @@ -2088,7 +2086,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ) ); gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", TAG_COLUMN, NULL ); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ), column ); gtk_widget_show( g_TextureBrowser.m_assigned_tree ); @@ -2106,7 +2104,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ GtkTreeSortable* sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_available_store ); gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING ); - GtkCellRenderer* renderer = ui::CellRendererText(); + auto renderer = ui::CellRendererText(); g_TextureBrowser.m_available_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_available_store ) )); g_object_unref( G_OBJECT( g_TextureBrowser.m_available_store ) ); @@ -2116,7 +2114,7 @@ ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){ GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ) ); gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE ); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "", renderer, "text", TAG_COLUMN, NULL ); + GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ), column ); gtk_widget_show( g_TextureBrowser.m_available_tree ); -- 2.39.2