From: TimePath Date: Sun, 6 Aug 2017 05:33:28 +0000 (+1000) Subject: Wrap more GTK X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=66dab04732db09384c0031d3271a78533811a184;p=xonotic%2Fnetradiant.git Wrap more GTK --- diff --git a/contrib/bkgrnd2d/dialog.cpp b/contrib/bkgrnd2d/dialog.cpp index f66fb6fb..9db81330 100644 --- a/contrib/bkgrnd2d/dialog.cpp +++ b/contrib/bkgrnd2d/dialog.cpp @@ -43,7 +43,7 @@ class CBackgroundDialogPage private: GtkWidget *m_pWidget; GtkWidget *m_pTabLabel; -GtkWidget *m_pFileLabel; +ui::Label m_pFileLabel; GtkWidget *m_pPosLabel; VIEWTYPE m_vt; bool m_bValidFile; @@ -159,7 +159,7 @@ void CBackgroundDialogPage::Browse(){ if ( m_pImage->Load( newfile ) ) { m_bValidFile = true; - gtk_label_set_text( GTK_LABEL( m_pFileLabel ),newfile ); + m_pFileLabel.text(newfile); } } @@ -168,7 +168,7 @@ void CBackgroundDialogPage::SetPosLabel(){ // TODO no snprintf ? sprintf( s, "Size/Position (%d,%d) (%d,%d)",(int)( m_pImage->m_xmin ), (int)( m_pImage->m_ymin ),(int)( m_pImage->m_xmax ),(int)( m_pImage->m_ymax ) ); - gtk_label_set_text( GTK_LABEL( m_pPosLabel ),s ); + m_pPosLabel.text(s); } CBackgroundDialogPage::CBackgroundDialogPage( VIEWTYPE vt ){ diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index f2517224..72da1de0 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -92,11 +92,28 @@ namespace ui { return ::file_dialog(this, open, title, path, pattern, want_load, want_import, want_save); } + bool IWidget::visible() + { + return gtk_widget_get_visible(this) != 0; + } + void IWidget::show() { gtk_widget_show(this); } + Dimensions IWidget::dimensions() + { + GtkAllocation allocation; + gtk_widget_get_allocation(this, &allocation); + return Dimensions{allocation.width, allocation.height}; + } + + void IWidget::dimensions(int width, int height) + { + gtk_widget_set_size_request(this, width, height); + } + IMPL(Container, GTK_CONTAINER); void IContainer::add(Widget widget) @@ -185,6 +202,9 @@ namespace ui { IMPL(CheckButton, GTK_CHECK_BUTTON); + CheckButton::CheckButton() : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new())) + {} + CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label))) {} @@ -212,6 +232,11 @@ namespace ui { ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr))) {} + void IScrolledWindow::overflow(Policy x, Policy y) + { + gtk_scrolled_window_set_policy(this, static_cast(x), static_cast(y)); + } + IMPL(VBox, GTK_VBOX); VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing))) @@ -249,6 +274,12 @@ namespace ui { TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new())) {} + void ITextView::text(char const *str) + { + GtkTextBuffer *buffer = gtk_text_view_get_buffer(this); + gtk_text_buffer_set_text(buffer, str, -1); + } + TreeView::TreeView() : TreeView(GTK_TREE_VIEW(gtk_tree_view_new())) {} @@ -260,6 +291,11 @@ namespace ui { Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label))) {} + void ILabel::text(char const *str) + { + gtk_label_set_text(this, str); + } + IMPL(Image, GTK_IMAGE); Image::Image() : Image(GTK_IMAGE(gtk_image_new())) @@ -275,6 +311,16 @@ namespace ui { gtk_entry_set_max_length(this, static_cast(max_length)); } + char const *IEntry::text() + { + return gtk_entry_get_text(this); + } + + void IEntry::text(char const *str) + { + return gtk_entry_set_text(this, str); + } + IMPL(SpinButton, GTK_SPIN_BUTTON); SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton( diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index c6483515..53241ec2 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -175,7 +175,7 @@ namespace ui { using native = _GtkObject *; native _handle; - Object(native h) : _handle(h) + explicit Object(native h) : _handle(h) {} explicit operator bool() const @@ -223,7 +223,7 @@ namespace ui { ); WRAP(Editable, Object, _GtkEditable, (), - Editable(); + explicit Editable(); , void editable(bool value); ); @@ -234,8 +234,13 @@ namespace ui { // GObject + struct Dimensions { + int width; + int height; + }; + WRAP(Widget, Object, _GtkWidget, (), - Widget(); + explicit Widget(); , alert_response alert( std::string text, @@ -252,7 +257,10 @@ namespace ui { bool want_import = false, bool want_save = false ); + bool visible(); void show(); + Dimensions dimensions(); + void dimensions(int width, int height); ); WRAP(Container, Widget, _GtkContainer, (), @@ -271,7 +279,7 @@ namespace ui { class AccelGroup; WRAP(Window, Bin, _GtkWindow, (), - Window(window_type type); + explicit Window(window_type type); , Window create_dialog_window( const char *title, @@ -308,13 +316,13 @@ namespace ui { ); WRAP(Frame, Bin, _GtkFrame, (), - Frame(const char *label = nullptr); + explicit Frame(const char *label = nullptr); , ); WRAP(Button, Bin, _GtkButton, (), - Button(); - Button(const char *label); + explicit Button(); + explicit Button(const char *label); , ); @@ -324,7 +332,8 @@ namespace ui { ); WRAP(CheckButton, ToggleButton, _GtkCheckButton, (), - CheckButton(const char *label); + explicit CheckButton(); + explicit CheckButton(const char *label); , ); @@ -337,8 +346,8 @@ namespace ui { ); WRAP(MenuItem, Item, _GtkMenuItem, (), - MenuItem(); - MenuItem(const char *label, bool mnemonic = false); + explicit MenuItem(); + explicit MenuItem(const char *label, bool mnemonic = false); , ); @@ -351,7 +360,7 @@ namespace ui { ); WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (), - TearoffMenuItem(); + explicit TearoffMenuItem(); , ); @@ -360,7 +369,7 @@ namespace ui { ); WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (), - ComboBoxText(); + explicit ComboBoxText(); , ); @@ -381,8 +390,9 @@ namespace ui { ); WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (), - ScrolledWindow(); + explicit ScrolledWindow(); , + void overflow(Policy x, Policy y); ); WRAP(Box, Container, _GtkBox, (), @@ -404,12 +414,12 @@ namespace ui { ); WRAP(HPaned, Paned, _GtkHPaned, (), - HPaned(); + explicit HPaned(); , ); WRAP(VPaned, Paned, _GtkVPaned, (), - VPaned(); + explicit VPaned(); , ); @@ -422,7 +432,7 @@ namespace ui { ); WRAP(Menu, MenuShell, _GtkMenu, (), - Menu(); + explicit Menu(); , ); @@ -432,8 +442,9 @@ namespace ui { ); WRAP(TextView, Container, _GtkTextView, (), - TextView(); + explicit TextView(); , + void text(char const *str); ); WRAP(Toolbar, Container, _GtkToolbar, (), @@ -442,7 +453,7 @@ namespace ui { class TreeModel; WRAP(TreeView, Widget, _GtkTreeView, (), - TreeView(); + explicit TreeView(); TreeView(TreeModel model); , ); @@ -452,19 +463,22 @@ namespace ui { ); WRAP(Label, Widget, _GtkLabel, (), - Label(const char *label); + explicit Label(const char *label); , + void text(char const *str); ); WRAP(Image, Widget, _GtkImage, (), - Image(); + explicit Image(); , ); WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable), - Entry(); - Entry(std::size_t max_length); + explicit Entry(); + explicit Entry(std::size_t max_length); , + char const *text(); + void text(char const *str); ); class Adjustment; @@ -482,7 +496,7 @@ namespace ui { ); WRAP(HScale, Scale, _GtkHScale, (), - HScale(Adjustment adjustment); + explicit HScale(Adjustment adjustment); HScale(double min, double max, double step); , ); @@ -500,7 +514,7 @@ namespace ui { ); WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (), - CellRendererText(); + explicit CellRendererText(); , ); @@ -514,7 +528,7 @@ namespace ui { ); WRAP(AccelGroup, Object, _GtkAccelGroup, (), - AccelGroup(); + explicit AccelGroup(); , ); @@ -534,8 +548,8 @@ namespace ui { // GBoxed WRAP(TreePath, Object, _GtkTreePath, (), - TreePath(); - TreePath(const char *path); + explicit TreePath(); + explicit TreePath(const char *path); , ); diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 0f729b40..0a8c80fd 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -828,7 +828,7 @@ gboolean mousecontrol_button_press( ui::Widget widget, GdkEventButton* event, Ca #endif void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){ - if ( gtk_widget_get_visible( self.m_gl_widget ) ) { + if ( self.m_gl_widget.visible() ) { self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ) ); } } @@ -854,8 +854,7 @@ void selection_motion( gdouble x, gdouble y, guint state, void* data ){ } inline WindowVector windowvector_for_widget_centre( ui::Widget widget ){ - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); + auto allocation = widget.dimensions(); return WindowVector( static_cast( allocation.width / 2 ), static_cast(allocation.height / 2 ) ); } diff --git a/radiant/console.cpp b/radiant/console.cpp index 2f156dd2..68c22ea1 100644 --- a/radiant/console.cpp +++ b/radiant/console.cpp @@ -81,14 +81,13 @@ void Sys_LogFile( bool enable ){ } } -ui::Widget g_console; +ui::TextView g_console{ui::null}; void console_clear(){ - GtkTextBuffer* buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( g_console ) ); - gtk_text_buffer_set_text( buffer, "", -1 ); + g_console.text(""); } -void console_populate_popup( GtkTextView* textview, ui::Menu menu, gpointer user_data ){ +void console_populate_popup( ui::TextView textview, ui::Menu menu, gpointer user_data ){ menu_separator( menu ); ui::Widget item(ui::MenuItem( "Clear" )); @@ -106,12 +105,12 @@ WidgetFocusPrinter g_consoleWidgetFocusPrinter( "console" ); ui::Widget Console_constructWindow( ui::Window toplevel ){ auto scr = ui::ScrolledWindow(); - gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); + scr.overflow(ui::Policy::AUTOMATIC, ui::Policy::AUTOMATIC); gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN ); scr.show(); { - ui::Widget text = ui::TextView(); + auto text = ui::TextView(); gtk_widget_set_size_request( text, 0, -1 ); // allow shrinking gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( text ), GTK_WRAP_WORD ); gtk_text_view_set_editable( GTK_TEXT_VIEW( text ), FALSE ); @@ -163,7 +162,7 @@ std::size_t Sys_Print( int level, const char* buf, std::size_t length ){ } if ( level != SYS_NOCON ) { - if ( g_console != 0 ) { + if ( g_console ) { GtkTextBuffer* buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( g_console ) ); GtkTextIter iter; diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index 01e58f7c..6e558bb9 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -150,7 +150,7 @@ void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCall typedef ImportExport IntRadioImportExport; void TextEntryImport( GtkEntry& widget, const char* text ){ - gtk_entry_set_text( &widget, text ); + ui::Entry(&widget).text(text); } void TextEntryExport( GtkEntry& widget, const StringImportCallback& importCallback ){ importCallback( gtk_entry_get_text( &widget ) ); diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index 82c0bb5f..cffa9358 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -67,7 +67,7 @@ ui::Entry numeric_entry_new(){ auto entry = ui::Entry(); entry.show(); - gtk_widget_set_size_request( GTK_WIDGET( entry ), 64, -1 ); + entry.dimensions(64, -1); return entry; } @@ -112,7 +112,7 @@ virtual void release() = 0; class BooleanAttribute : public EntityAttribute { CopiedString m_key; -GtkCheckButton* m_check; +ui::CheckButton m_check; static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){ self->apply(); @@ -121,8 +121,8 @@ static gboolean toggled( ui::Widget widget, BooleanAttribute* self ){ public: BooleanAttribute( const char* key ) : m_key( key ), - m_check( 0 ){ - auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() )); + m_check( ui::null ){ + auto check = ui::CheckButton(); check.show(); m_check = check; @@ -133,24 +133,24 @@ BooleanAttribute( const char* key ) : update(); } ui::Widget getWidget() const { - return ui::Widget(GTK_WIDGET( m_check )); + return m_check; } void release(){ delete this; } void apply(){ - Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_check ) ) ? "1" : "0" ); + Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), m_check.active() ? "1" : "0" ); } typedef MemberCaller ApplyCaller; void update(){ const char* value = SelectedEntity_getValueForKey( m_key.c_str() ); if ( !string_empty( value ) ) { - toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), atoi( value ) != 0 ); + toggle_button_set_active_no_signal( m_check, atoi( value ) != 0 ); } else { - toggle_button_set_active_no_signal( ui::ToggleButton(GTK_TOGGLE_BUTTON( m_check )), false ); + toggle_button_set_active_no_signal( m_check, false ); } } typedef MemberCaller UpdateCaller; @@ -169,13 +169,13 @@ StringAttribute( const char* key ) : m_nonModal( ApplyCaller( *this ), UpdateCaller( *this ) ){ auto entry = ui::Entry(); entry.show(); - gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 ); + entry.dimensions(50, -1); m_entry = entry; m_nonModal.connect( m_entry ); } ui::Widget getWidget() const { - return ui::Widget(GTK_WIDGET( m_entry )); + return m_entry; } ui::Entry getEntry() const { return m_entry; @@ -186,7 +186,7 @@ void release(){ } void apply(){ StringOutputStream value( 64 ); - value << gtk_entry_get_text( m_entry ); + value << m_entry.text(); Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() ); } typedef MemberCaller ApplyCaller; @@ -194,7 +194,7 @@ typedef MemberCaller ApplyCaller; void update(){ StringOutputStream value( 64 ); value << SelectedEntity_getValueForKey( m_key.c_str() ); - gtk_entry_set_text( m_entry, value.c_str() ); + m_entry.text(value.c_str()); } typedef MemberCaller UpdateCaller; }; @@ -224,18 +224,18 @@ void release(){ delete this; } ui::Widget getWidget() const { - return ui::Widget(GTK_WIDGET( m_entry.m_entry.m_frame )); + return m_entry.m_entry.m_frame; } void apply(){ StringOutputStream value( 64 ); - value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) ); + value << m_entry.m_entry.m_entry.text(); Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() ); } typedef MemberCaller ApplyCaller; void update(){ StringOutputStream value( 64 ); value << SelectedEntity_getValueForKey( m_key.c_str() ); - gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() ); + m_entry.m_entry.m_entry.text(value.c_str()); } typedef MemberCaller UpdateCaller; void browse( const BrowsedPathEntry::SetPathCallback& setPath ){ @@ -291,14 +291,14 @@ ui::Widget getWidget() const { } void apply(){ StringOutputStream value( 64 ); - value << gtk_entry_get_text( GTK_ENTRY( m_entry.m_entry.m_entry ) ); + value << m_entry.m_entry.m_entry.text(); Scene_EntitySetKeyValue_Selected_Undoable( m_key.c_str(), value.c_str() ); } typedef MemberCaller ApplyCaller; void update(){ StringOutputStream value( 64 ); value << SelectedEntity_getValueForKey( m_key.c_str() ); - gtk_entry_set_text( GTK_ENTRY( m_entry.m_entry.m_entry ), value.c_str() ); + m_entry.m_entry.m_entry.text(value.c_str()); } typedef MemberCaller UpdateCaller; void browse( const BrowsedPathEntry::SetPathCallback& setPath ){ @@ -348,11 +348,11 @@ void update(){ if ( !string_empty( value ) ) { StringOutputStream angle( 32 ); angle << angle_normalised( atof( value ) ); - gtk_entry_set_text( m_entry, angle.c_str() ); + m_entry.text(angle.c_str()); } else { - gtk_entry_set_text( m_entry, "0" ); + m_entry.text("0"); } } typedef MemberCaller UpdateCaller; @@ -411,12 +411,12 @@ void update(){ if ( f == -1 ) { gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE ); radio_button_set_active_no_signal( m_radio.m_radio, 0 ); - gtk_entry_set_text( m_entry, "" ); + m_entry.text(""); } else if ( f == -2 ) { gtk_widget_set_sensitive( GTK_WIDGET( m_entry ), FALSE ); radio_button_set_active_no_signal( m_radio.m_radio, 1 ); - gtk_entry_set_text( m_entry, "" ); + m_entry.text(""); } else { @@ -424,12 +424,12 @@ void update(){ radio_button_set_active_no_signal( m_radio.m_radio, 2 ); StringOutputStream angle( 32 ); angle << angle_normalised( f ); - gtk_entry_set_text( m_entry, angle.c_str() ); + m_entry.text(angle.c_str()); } } else { - gtk_entry_set_text( m_entry, "0" ); + m_entry.text("0"); } } typedef MemberCaller UpdateCaller; @@ -519,22 +519,22 @@ void update(){ } angle << angle_normalised( pitch_yaw_roll.x() ); - gtk_entry_set_text( m_angles.m_pitch, angle.c_str() ); + m_angles.m_pitch.text(angle.c_str()); angle.clear(); angle << angle_normalised( pitch_yaw_roll.y() ); - gtk_entry_set_text( m_angles.m_yaw, angle.c_str() ); + m_angles.m_yaw.text(angle.c_str()); angle.clear(); angle << angle_normalised( pitch_yaw_roll.z() ); - gtk_entry_set_text( m_angles.m_roll, angle.c_str() ); + m_angles.m_roll.text(angle.c_str()); angle.clear(); } else { - gtk_entry_set_text( m_angles.m_pitch, "0" ); - gtk_entry_set_text( m_angles.m_yaw, "0" ); - gtk_entry_set_text( m_angles.m_roll, "0" ); + m_angles.m_pitch.text("0"); + m_angles.m_yaw.text("0"); + m_angles.m_roll.text("0"); } } typedef MemberCaller UpdateCaller; @@ -606,22 +606,22 @@ void update(){ } buffer << x_y_z.x(); - gtk_entry_set_text( m_vector3.m_x, buffer.c_str() ); + m_vector3.m_x.text(buffer.c_str()); buffer.clear(); buffer << x_y_z.y(); - gtk_entry_set_text( m_vector3.m_y, buffer.c_str() ); + m_vector3.m_y.text(buffer.c_str()); buffer.clear(); buffer << x_y_z.z(); - gtk_entry_set_text( m_vector3.m_z, buffer.c_str() ); + m_vector3.m_z.text(buffer.c_str()); buffer.clear(); } else { - gtk_entry_set_text( m_vector3.m_x, "0" ); - gtk_entry_set_text( m_vector3.m_y, "0" ); - gtk_entry_set_text( m_vector3.m_z, "0" ); + m_vector3.m_x.text("0"); + m_vector3.m_y.text("0"); + m_vector3.m_z.text("0"); } } typedef MemberCaller UpdateCaller; @@ -710,12 +710,12 @@ int g_entitysplit2_position; bool g_entityInspector_windowConstructed = false; GtkTreeView* g_entityClassList; -GtkTextView* g_entityClassComment; +ui::TextView g_entityClassComment; GtkCheckButton* g_entitySpawnflagsCheck[MAX_FLAGS]; -GtkEntry* g_entityKeyEntry; -GtkEntry* g_entityValueEntry; +ui::Entry g_entityKeyEntry; +ui::Entry g_entityValueEntry; ui::ListStore g_entlist_store{ui::null}; ui::ListStore g_entprops_store{ui::null}; @@ -831,8 +831,7 @@ void SetComment( EntityClass* eclass ){ g_current_comment = eclass; - GtkTextBuffer* buffer = gtk_text_view_get_buffer( g_entityClassComment ); - gtk_text_buffer_set_text( buffer, eclass->comments(), -1 ); + g_entityClassComment.text(eclass->comments()); } void SurfaceFlags_setEntityClass( EntityClass* eclass ){ @@ -860,8 +859,9 @@ void SurfaceFlags_setEntityClass( EntityClass* eclass ){ { for ( int i = 0; i < g_spawnflag_count; ++i ) { - ui::Widget widget = ui::Widget(GTK_WIDGET( g_entitySpawnflagsCheck[i] )); - gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), " " ); + auto widget = ui::Widget(GTK_WIDGET(g_entitySpawnflagsCheck[i])); + auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget)))); + label.text(" "); gtk_widget_hide( widget ); g_object_ref( widget ); gtk_container_remove( GTK_CONTAINER( g_spawnflagsTable ), widget ); @@ -884,7 +884,8 @@ void SurfaceFlags_setEntityClass( EntityClass* eclass ){ (GtkAttachOptions)( GTK_FILL ), 0, 0 ); widget.unref(); - gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN(widget)) ), str.c_str() ); + auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget)) )); + label.text(str.c_str()); } } } @@ -1038,8 +1039,8 @@ void EntityInspector_updateKeyValues(){ // save current key/val pair around filling epair box // row_select wipes it and sets to first in list - CopiedString strKey( gtk_entry_get_text( g_entityKeyEntry ) ); - CopiedString strVal( gtk_entry_get_text( g_entityValueEntry ) ); + CopiedString strKey( g_entityKeyEntry.text() ); + CopiedString strVal( g_entityValueEntry.text() ); gtk_list_store_clear( store ); // Walk through list and add pairs @@ -1054,8 +1055,8 @@ void EntityInspector_updateKeyValues(){ gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 ); } - gtk_entry_set_text( g_entityKeyEntry, strKey.c_str() ); - gtk_entry_set_text( g_entityValueEntry, strVal.c_str() ); + g_entityKeyEntry.text( strKey.c_str() ); + g_entityValueEntry.text( strVal.c_str() ); for ( EntityAttributes::const_iterator i = g_entityAttributes.begin(); i != g_entityAttributes.end(); ++i ) { @@ -1249,8 +1250,8 @@ static void EntityProperties_selection_changed( GtkTreeSelection* selection, gpo char* val; gtk_tree_model_get( model, &iter, 0, &key, 1, &val, -1 ); - gtk_entry_set_text( g_entityKeyEntry, key ); - gtk_entry_set_text( g_entityValueEntry, val ); + g_entityKeyEntry.text( key ); + g_entityValueEntry.text( val ); g_free( key ); g_free( val ); @@ -1263,7 +1264,7 @@ static void SpawnflagCheck_toggled( ui::Widget widget, gpointer data ){ static gint EntityEntry_keypress( GtkEntry* widget, GdkEventKey* event, gpointer data ){ if ( event->keyval == GDK_KEY_Return ) { if ( widget == g_entityKeyEntry ) { - gtk_entry_set_text( g_entityValueEntry, "" ); + g_entityValueEntry.text( "" ); gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityValueEntry ) ); } else diff --git a/radiant/entitylist.cpp b/radiant/entitylist.cpp index dad00e4e..239aef06 100644 --- a/radiant/entitylist.cpp +++ b/radiant/entitylist.cpp @@ -71,8 +71,8 @@ EntityList() : m_selection_disabled( false ){ } -bool visible() const { - return gtk_widget_get_visible( m_window ); +bool visible() { + return m_window.visible(); } }; diff --git a/radiant/findtexturedialog.cpp b/radiant/findtexturedialog.cpp index 9766843a..49efe49e 100644 --- a/radiant/findtexturedialog.cpp +++ b/radiant/findtexturedialog.cpp @@ -222,7 +222,7 @@ void FindTextureDialog::updateTextures( const char* name ){ } bool FindTextureDialog::isOpen(){ - return gtk_widget_get_visible( g_FindTextureDialog.GetWidget() ) == TRUE; + return g_FindTextureDialog.GetWidget().visible(); } void FindTextureDialog::setFindStr( const char* name ){ diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 79944252..f39487a5 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -155,7 +155,7 @@ inline void path_copy_clean( char* destination, const char* source ){ struct GameCombo { ui::ComboBoxText game_select; - GtkEntry* fsgame_entry; + ui::Entry fsgame_entry; }; gboolean OnSelchangeComboWhatgame( ui::Widget widget, GameCombo* combo ){ @@ -168,7 +168,7 @@ gboolean OnSelchangeComboWhatgame( ui::Widget widget, GameCombo* combo ){ gamecombo_t gamecombo = gamecombo_for_gamename( gamename ); - gtk_entry_set_text( combo->fsgame_entry, gamecombo.fs_game ); + combo->fsgame_entry.text( gamecombo.fs_game ); gtk_widget_set_sensitive( GTK_WIDGET( combo->fsgame_entry ), gamecombo.sensitive ); return FALSE; @@ -301,7 +301,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal gamecombo_t gamecombo = gamecombo_for_dir( dir ); gtk_combo_box_set_active( dialog.game_combo.game_select, gamecombo.game ); - gtk_entry_set_text( dialog.game_combo.fsgame_entry, gamecombo.fs_game ); + dialog.game_combo.fsgame_entry.text( gamecombo.fs_game ); gtk_widget_set_sensitive( GTK_WIDGET( dialog.game_combo.fsgame_entry ), gamecombo.sensitive ); if ( globalMappingMode().do_mapping_mode ) { @@ -569,8 +569,7 @@ void DoAbout(){ auto text_extensions = ui::TextView(); gtk_text_view_set_editable( GTK_TEXT_VIEW( text_extensions ), FALSE ); sc_extensions.add(text_extensions); - GtkTextBuffer* buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_extensions ) ); - gtk_text_buffer_set_text( buffer, reinterpret_cast( glGetString( GL_EXTENSIONS ) ), -1 ); + text_extensions.text(reinterpret_cast(glGetString(GL_EXTENSIONS))); gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( text_extensions ), GTK_WRAP_WORD ); text_extensions.show(); } @@ -595,8 +594,8 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){ ModalDialog dialog; ModalDialogButton ok_button( dialog, eIDOK ); ModalDialogButton cancel_button( dialog, eIDCANCEL ); - GtkEntry* x; - GtkEntry* y; + ui::Entry x; + ui::Entry y; auto window = MainFrame_getWindow().create_modal_dialog_window("Patch texture layout", dialog ); @@ -679,10 +678,10 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){ char buf[16]; sprintf( buf, "%f", last_used_texture_layout_scale_x ); - gtk_entry_set_text( x, buf ); + x.text( buf ); sprintf( buf, "%f", last_used_texture_layout_scale_y ); - gtk_entry_set_text( y, buf ); + y.text( buf ); // Set focus after intializing the values gtk_widget_grab_focus( GTK_WIDGET( x ) ); @@ -854,7 +853,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){ ModalDialog dialog; - GtkEntry* intensity_entry; + ui::Entry intensity_entry; ModalDialogButton ok_button( dialog, eIDOK ); ModalDialogButton cancel_button( dialog, eIDCANCEL ); @@ -904,7 +903,7 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){ char buf[16]; sprintf( buf, "%d", *intensity ); - gtk_entry_set_text( intensity_entry, buf ); + intensity_entry.text(buf); EMessageBoxReturn ret = modal_dialog_show( window, dialog ); if ( ret == eIDOK ) { diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index 693d569f..acb6da12 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -131,7 +131,7 @@ void button_clicked_entry_browse_file( ui::Widget widget, ui::Entry entry ){ const char *filename = ui::Widget(gtk_widget_get_toplevel( widget )).file_dialog( TRUE, "Choose File", gtk_entry_get_text( entry ) ); if ( filename != 0 ) { - gtk_entry_set_text( entry, filename ); + entry.text(filename); } } @@ -141,7 +141,7 @@ void button_clicked_entry_browse_directory( ui::Widget widget, ui::Entry entry ) if ( dir != 0 ) { gchar* converted = g_filename_to_utf8( dir, -1, 0, 0, 0 ); - gtk_entry_set_text( entry, converted ); + entry.text(converted); g_free( dir ); g_free( converted ); } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 92e1960a..2e01ca05 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -443,7 +443,7 @@ ui::Window BuildDialog(){ frame.add(vbox2); { - PreferencesPage preferencesPage( *this, ui::Widget(GTK_WIDGET( vbox2 )) ); + PreferencesPage preferencesPage( *this, vbox2 ); Paths_constructPreferences( preferencesPage ); } @@ -1676,7 +1676,7 @@ bool ScreenUpdates_Enabled(){ } void ScreenUpdates_process(){ - if ( redrawRequired() && gtk_widget_get_visible( g_wait.m_window ) ) { + if ( redrawRequired() && g_wait.m_window.visible() ) { ui::process(); } } @@ -1698,8 +1698,8 @@ void ScreenUpdates_Disable( const char* message, const char* title ){ ScreenUpdates_process(); } } - else if ( gtk_widget_get_visible( g_wait.m_window ) ) { - gtk_label_set_text( g_wait.m_label, message ); + else if ( g_wait.m_window.visible() ) { + g_wait.m_label.text(message); ScreenUpdates_process(); } g_wait_stack.push_back( message ); @@ -1718,8 +1718,8 @@ void ScreenUpdates_Enable(){ //gtk_window_present(MainFrame_getWindow()); } - else if ( gtk_widget_get_visible( g_wait.m_window ) ) { - gtk_label_set_text( g_wait.m_label, g_wait_stack.back().c_str() ); + else if ( g_wait.m_window.visible() ) { + g_wait.m_label.text(g_wait_stack.back().c_str()); ScreenUpdates_process(); } } @@ -2469,7 +2469,7 @@ WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" ); class MainWindowActive { static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){ - if ( g_wait.m_window && gtk_window_is_active( window ) && !gtk_widget_get_visible( g_wait.m_window ) ) { + if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) { g_wait.m_window.show(); } @@ -2521,7 +2521,7 @@ MainFrame::MainFrame() : m_window( 0 ), m_idleRedrawStatusText( RedrawStatusText for ( int n = 0; n < c_count_status; n++ ) { - m_pStatusLabel[n] = ui::root; + m_pStatusLabel[n] = ui::Label(ui::null); } m_bSleeping = false; @@ -3040,11 +3040,11 @@ void MainFrame::Shutdown(){ } void MainFrame::RedrawStatusText(){ - gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_command_status] ), m_command_status.c_str() ); - gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_position_status] ), m_position_status.c_str() ); - gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_brushcount_status] ), m_brushcount_status.c_str() ); - gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_texture_status] ), m_texture_status.c_str() ); - gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_grid_status] ), m_grid_status.c_str() ); + ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str()); + ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str()); + ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str()); + ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str()); + ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str()); } void MainFrame::UpdateStatusText(){ diff --git a/radiant/map.cpp b/radiant/map.cpp index 056f3ecf..42f8a706 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -763,8 +763,8 @@ WindowPosition g_posMapInfoWnd( c_default_window_pos ); void DoMapInfo(){ ModalDialog dialog; - GtkEntry* brushes_entry; - GtkEntry* entities_entry; + ui::Entry brushes_entry; + ui::Entry entities_entry; ui::ListStore EntityBreakdownWalker{ui::null}; ui::Window window = MainFrame_getWindow().create_dialog_window("Map Info", G_CALLBACK(dialog_delete_callback ), &dialog ); @@ -889,9 +889,9 @@ void DoMapInfo(){ char tmp[16]; sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) ); - gtk_entry_set_text( GTK_ENTRY( brushes_entry ), tmp ); + brushes_entry.text(tmp); sprintf( tmp, "%u", Unsigned( g_entityCount.get() ) ); - gtk_entry_set_text( GTK_ENTRY( entities_entry ), tmp ); + entities_entry.text(tmp); modal_dialog_show( window, dialog ); @@ -2036,8 +2036,8 @@ static void GetSelectionIndex( int *ent, int *brush ){ void DoFind(){ ModalDialog dialog; - GtkEntry* entity; - GtkEntry* brush; + ui::Entry entity; + ui::Entry brush; ui::Window window = MainFrame_getWindow().create_dialog_window("Find Brush", G_CALLBACK(dialog_delete_callback ), &dialog ); @@ -2106,9 +2106,9 @@ void DoFind(){ GetSelectionIndex( &ent, &br ); sprintf( buf, "%i", ent ); - gtk_entry_set_text( entity, buf ); + entity.text(buf); sprintf( buf, "%i", br ); - gtk_entry_set_text( brush, buf ); + brush.text(buf); if ( modal_dialog_show( window, dialog ) == eIDOK ) { const char *entstr = gtk_entry_get_text( entity ); diff --git a/radiant/mru.cpp b/radiant/mru.cpp index 50d89bf1..3a01d142 100644 --- a/radiant/mru.cpp +++ b/radiant/mru.cpp @@ -159,7 +159,8 @@ void MRU_Activate( std::size_t index ){ MRU_SetText( i, MRU_GetText( i + 1 ) ); if ( MRU_used == 0 ) { - gtk_label_set_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( MRU_items[0] )) ), "Recent Files" ); + auto label = ui::Label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(MRU_items[0] )) )); + label.text("Recent Files"); gtk_widget_set_sensitive( GTK_WIDGET( MRU_items[0] ), FALSE ); } else diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index 96e60eac..0d8b2276 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -176,8 +176,8 @@ void update(){ } else { - gtk_entry_set_text( m_horizontal, "" ); - gtk_entry_set_text( m_vertical, "" ); + m_horizontal.text(""); + m_vertical.text(""); gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), FALSE ); gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), FALSE ); } @@ -256,7 +256,7 @@ PatchInspector() : } bool visible(){ - return gtk_widget_get_visible( GetWidget() ); + return GetWidget().visible(); } // void UpdateInfo(); diff --git a/radiant/select.cpp b/radiant/select.cpp index eff55f51..5a36f5a4 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -1016,9 +1016,9 @@ void DoRotateDlg(){ struct ScaleDialog { - ui::Widget x; - ui::Widget y; - ui::Widget z; + ui::Entry x; + ui::Entry y; + ui::Entry z; ui::Window window{ui::null}; }; @@ -1041,9 +1041,9 @@ static gboolean scaledlg_apply( ui::Widget widget, ScaleDialog* scaleDialog ){ static gboolean scaledlg_cancel( ui::Widget widget, ScaleDialog* scaleDialog ){ gtk_widget_hide( GTK_WIDGET( scaleDialog->window ) ); - gtk_entry_set_text( GTK_ENTRY( scaleDialog->x ), "1.0" ); - gtk_entry_set_text( GTK_ENTRY( scaleDialog->y ), "1.0" ); - gtk_entry_set_text( GTK_ENTRY( scaleDialog->z ), "1.0" ); + scaleDialog->x.text("1.0"); + scaleDialog->y.text("1.0"); + scaleDialog->z.text("1.0"); return TRUE; } @@ -1096,8 +1096,8 @@ void DoScaleDlg(){ (GtkAttachOptions) ( 0 ), 0, 0 ); } { - ui::Widget entry = ui::Entry(); - gtk_entry_set_text( GTK_ENTRY( entry ), "1.0" ); + auto entry = ui::Entry(); + entry.text("1.0"); entry.show(); gtk_table_attach( table, entry, 1, 2, 0, 1, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -1106,8 +1106,8 @@ void DoScaleDlg(){ g_scale_dialog.x = entry; } { - ui::Widget entry = ui::Entry(); - gtk_entry_set_text( GTK_ENTRY( entry ), "1.0" ); + auto entry = ui::Entry(); + entry.text("1.0"); entry.show(); gtk_table_attach( table, entry, 1, 2, 1, 2, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), @@ -1116,8 +1116,8 @@ void DoScaleDlg(){ g_scale_dialog.y = entry; } { - ui::Widget entry = ui::Entry(); - gtk_entry_set_text( GTK_ENTRY( entry ), "1.0" ); + auto entry = ui::Entry(); + entry.text("1.0"); entry.show(); gtk_table_attach( table, entry, 1, 2, 2, 3, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index f9774559..24e35890 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -174,7 +174,7 @@ Increment m_vshiftIncrement; Increment m_hscaleIncrement; Increment m_vscaleIncrement; Increment m_rotateIncrement; -GtkEntry* m_texture; +ui::Entry m_texture; SurfaceInspector() : m_textureEntry( ApplyShaderCaller( *this ), UpdateCaller( *this ) ), @@ -210,8 +210,8 @@ void constructWindow( ui::Window main_window ){ void destroyWindow(){ Destroy(); } -bool visible() const { - return gtk_widget_get_visible( GetWidget() ); +bool visible() { + return GetWidget().visible(); } void queueDraw(){ if ( visible() ) { @@ -1112,11 +1112,11 @@ void SurfaceInspector::Update(){ const char * name = SurfaceInspector_GetSelectedShader(); if ( shader_is_texture( name ) ) { - gtk_entry_set_text( m_texture, shader_get_textureName( name ) ); + m_texture.text(shader_get_textureName(name)); } else { - gtk_entry_set_text( m_texture, "" ); + m_texture.text(""); } texdef_t shiftScaleRotate; diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index eb275baf..b265c25e 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -707,7 +707,7 @@ bool XYWnd::chaseMouseMotion( int pointx, int pointy ){ Shader* XYWnd::m_state_selected = 0; void xy_update_xor_rectangle( XYWnd& self, rect_t area ){ - if ( gtk_widget_get_visible( self.GetWidget() ) ) { + if ( self.GetWidget().visible() ) { self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.Width(), self.Height() ) ); } }