File indexing completed on 2024-05-05 05:34:55
0001 /* 0002 this file is part of the oxygen gtk engine 0003 SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0004 0005 based on the Null Theme Engine for Gtk+. 0006 SPDX-FileCopyrightText: 2008 Robert Staudinger <robert.staudinger@gmail.com> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #include "oxygenbuttondemowidget.h" 0012 0013 #include <string> 0014 0015 namespace Oxygen 0016 { 0017 0018 //____________________________________________________ 0019 ButtonDemoWidget::ButtonDemoWidget( void ) 0020 { 0021 0022 // main widget 0023 GtkWidget* mainWidget( gtk_vbox_new( false, 0 ) ); 0024 gtk_box_set_spacing( GTK_BOX( mainWidget ), 4 ); 0025 setWidget( mainWidget ); 0026 0027 // setup 0028 setName( "Buttons" ); 0029 setComments( "Shows the appearance of buttons" ); 0030 setIconName( "go-jump-locationbar" ); 0031 realize(); 0032 0033 // pushbuttons 0034 { 0035 GtkWidget* frame( gtk_frame_new( "Pushbutton" ) ); 0036 gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 ); 0037 gtk_widget_show( frame ); 0038 0039 // inner table 0040 GtkWidget* table = gtk_table_new( 2, 4, false ); 0041 gtk_container_set_border_width( GTK_CONTAINER( table ), 4 ); 0042 gtk_table_set_row_spacings( GTK_TABLE( table ), 4 ); 0043 gtk_container_add( GTK_CONTAINER( frame ), table ); 0044 gtk_widget_show( table ); 0045 0046 // spacing 0047 GtkWidget* spacing( gtk_label_new( "" ) ); 0048 gtk_table_attach( GTK_TABLE( table ), spacing, 3, 4, 0, 1, GTK_EXPAND, GTK_FILL, 2, 0 ); 0049 gtk_widget_show( spacing ); 0050 0051 // generic label 0052 GtkWidget* label( 0L ); 0053 0054 { 0055 // text only 0056 gtk_table_attach( GTK_TABLE( table ), label = gtk_label_new( "Text only: " ), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 2, 0 ); 0057 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 0058 gtk_widget_show( label ); 0059 0060 // button 0061 GtkWidget* button( gtk_button_new_with_label( "Normal" ) ); 0062 gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 2, 0 ); 0063 gtk_widget_show( button ); 0064 gtk_widget_set_tooltip_text( button, "This is a normal, text only button" ); 0065 0066 // combobox model 0067 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 0068 const char* columns[] = 0069 { 0070 "Small", 0071 "Normal", 0072 "Large" 0073 }; 0074 0075 for( unsigned int i=0; i<3; i++ ) 0076 { 0077 GtkTreeIter iter; 0078 gtk_list_store_append( model, &iter ); 0079 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 0080 } 0081 0082 GtkWidget* comboBox( gtk_combo_box_new() ); 0083 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 0084 g_object_unref( model ); 0085 0086 // text renderer 0087 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 0088 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0089 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 0090 0091 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 0092 0093 gtk_table_attach( GTK_TABLE( table ), comboBox, 2, 3, 0, 1, GTK_FILL, GTK_FILL, 2, 0 ); 0094 gtk_widget_show( comboBox ); 0095 gtk_widget_set_tooltip_text( comboBox, "This is a normal, text only combo box" ); 0096 0097 } 0098 0099 { 0100 // text and icons 0101 gtk_table_attach( GTK_TABLE( table ), label = gtk_label_new( "Text and icon: " ), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 2, 0 ); 0102 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 0103 gtk_widget_show( label ); 0104 0105 // button 0106 GtkWidget* button( gtk_button_new_with_label( "Normal" ) ); 0107 gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 2, 0 ); 0108 0109 GtkIconTheme* theme( gtk_icon_theme_get_default() ); 0110 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, "oxygen", 16, (GtkIconLookupFlags) 0, 0L ); 0111 if(icon) 0112 { 0113 GtkWidget* image( gtk_image_new_from_pixbuf( icon ) ); 0114 g_object_unref( icon ); 0115 0116 gtk_button_set_image( GTK_BUTTON( button ), image ); 0117 } 0118 gtk_widget_show( button ); 0119 gtk_widget_set_tooltip_text( button, "This is a normal, text and icon button" ); 0120 0121 // combobox model 0122 GtkListStore* model( gtk_list_store_new( 2, GDK_TYPE_PIXBUF, G_TYPE_STRING ) ); 0123 const char* columns[] = 0124 { 0125 "New", 0126 "Open", 0127 "Save" 0128 }; 0129 0130 const char* icons[] = 0131 { 0132 "document-new", 0133 "document-open", 0134 "document-save" 0135 }; 0136 0137 // store into model 0138 for( unsigned int i=0; i<3; i++ ) 0139 { 0140 GtkTreeIter iter; 0141 gtk_list_store_append( model, &iter ); 0142 0143 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, icons[i], 16, (GtkIconLookupFlags) 0, 0L ); 0144 gtk_list_store_set( model, &iter, 0, icon, 1, columns[i], -1 ); 0145 g_object_unref( icon ); 0146 } 0147 0148 GtkWidget* comboBox( gtk_combo_box_new() ); 0149 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 0150 g_object_unref( model ); 0151 0152 { 0153 // pixbuf renderer 0154 GtkCellRenderer* cell = gtk_cell_renderer_pixbuf_new(); 0155 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0156 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, 0157 "pixbuf", 0, 0158 NULL ); 0159 } 0160 0161 { 0162 // text renderer 0163 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 0164 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0165 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 1, NULL ); 0166 } 0167 0168 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 0169 0170 gtk_table_attach( GTK_TABLE( table ), comboBox, 2, 3, 1, 2, GTK_FILL, GTK_FILL, 2, 0 ); 0171 gtk_widget_show( comboBox ); 0172 gtk_widget_set_tooltip_text( comboBox, "This is a normal, text and icon combo box" ); 0173 0174 } 0175 0176 0177 } 0178 0179 { 0180 // toolbar 0181 GtkWidget* frame( gtk_frame_new( "Toolbuttons" ) ); 0182 gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 ); 0183 gtk_widget_show( frame ); 0184 0185 // inner box 0186 GtkWidget* vbox( gtk_vbox_new( false, 0 ) ); 0187 gtk_box_set_spacing( GTK_BOX( vbox ), 4 ); 0188 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 0189 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 0190 gtk_widget_show( vbox ); 0191 0192 _toolbar = gtk_toolbar_new(); 0193 gtk_box_pack_start( GTK_BOX( vbox ), _toolbar, false, true, 0 ); 0194 gtk_widget_show( _toolbar ); 0195 0196 // toolbuttons 0197 GtkToolItem* toolButton; 0198 0199 gtk_toolbar_insert( GTK_TOOLBAR(_toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_NEW ), 0 ); 0200 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "New" ); 0201 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0202 0203 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_OPEN ), 1 ); 0204 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Open" ); 0205 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0206 0207 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_SAVE ), 2 ); 0208 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Save" ); 0209 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0210 0211 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_CUT ), 2 ); 0212 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Cut selection" ); 0213 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0214 0215 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_COPY ), 2 ); 0216 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Copy selection" ); 0217 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0218 0219 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new_from_stock( GTK_STOCK_PASTE ), 2 ); 0220 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Paste clipboard" ); 0221 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0222 0223 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_toggle_tool_button_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION ), 2 ); 0224 gtk_toggle_tool_button_set_active( GTK_TOGGLE_TOOL_BUTTON( toolButton ), true ); 0225 gtk_widget_show( GTK_WIDGET( toolButton ) ); 0226 0227 // table for text position and icon size 0228 GtkWidget* table = gtk_table_new( 2, 3, false ); 0229 gtk_container_set_border_width( GTK_CONTAINER( table ), 4 ); 0230 gtk_table_set_row_spacings( GTK_TABLE( table ), 4 ); 0231 gtk_box_pack_start( GTK_BOX( vbox ), table, false, true, 0 ); 0232 gtk_widget_show( table ); 0233 0234 { 0235 0236 // text position combobox 0237 GtkWidget* label( 0L ); 0238 0239 gtk_table_attach( GTK_TABLE( table ), label = gtk_label_new( "Text position: " ), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 2, 0 ); 0240 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 0241 gtk_widget_show( label ); 0242 0243 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 0244 const char* columns[] = 0245 { 0246 "Icons Only", 0247 "Text Only", 0248 "Text Alongside Icons", 0249 "Text Under Icons" 0250 }; 0251 0252 for( unsigned int i=0; i<4; i++ ) 0253 { 0254 GtkTreeIter iter; 0255 gtk_list_store_append( model, &iter ); 0256 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 0257 } 0258 0259 GtkWidget* comboBox( gtk_combo_box_new() ); 0260 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 0261 g_object_unref( model ); 0262 0263 // text renderer 0264 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 0265 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0266 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 0267 0268 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 0269 0270 gtk_table_attach( GTK_TABLE( table ), comboBox, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 2, 0 ); 0271 gtk_widget_show( comboBox ); 0272 0273 // connection 0274 connect( G_OBJECT( comboBox ), "changed", G_CALLBACK( toolBarStyleChanged ), this ); 0275 0276 } 0277 0278 { 0279 0280 // icon size combobox 0281 GtkWidget* label( 0L ); 0282 0283 gtk_table_attach( GTK_TABLE( table ), label = gtk_label_new( "Icon size: " ), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 2, 0 ); 0284 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 0285 gtk_widget_show( label ); 0286 0287 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 0288 const char* columns[] = 0289 { 0290 "Small", 0291 "Medium", 0292 "Large", 0293 "Huge" 0294 }; 0295 0296 for( unsigned int i=0; i<4; i++ ) 0297 { 0298 GtkTreeIter iter; 0299 gtk_list_store_append( model, &iter ); 0300 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 0301 } 0302 0303 GtkWidget* comboBox( gtk_combo_box_new() ); 0304 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 0305 g_object_unref( model ); 0306 0307 // text renderer 0308 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 0309 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0310 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 0311 0312 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 2 ); 0313 0314 gtk_table_attach( GTK_TABLE( table ), comboBox, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 2, 0 ); 0315 gtk_widget_show( comboBox ); 0316 0317 // connection 0318 connect( G_OBJECT( comboBox ), "changed", G_CALLBACK( iconSizeChanged ), this ); 0319 0320 } 0321 0322 0323 } 0324 0325 0326 // checkboxes and radiobuttons 0327 GtkWidget* hbox( gtk_hbox_new( false, 0 ) ); 0328 gtk_box_set_spacing( GTK_BOX( hbox ), 4 ); 0329 gtk_box_pack_start( GTK_BOX( mainWidget ), hbox, false, true, 0 ); 0330 gtk_widget_show( hbox ); 0331 0332 { 0333 // checkboxes 0334 GtkWidget* frame( gtk_frame_new( "Checkboxes" ) ); 0335 gtk_box_pack_start( GTK_BOX( hbox ), frame, true, true, 0 ); 0336 gtk_widget_show( frame ); 0337 0338 GtkWidget* vbox( gtk_vbox_new( false, 0 ) ); 0339 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 0340 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 0341 gtk_widget_show( vbox ); 0342 0343 GtkWidget* checkbutton; 0344 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "Off" ), false, true, 0 ); 0345 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkbutton ), false ); 0346 gtk_widget_show( checkbutton ); 0347 0348 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "Partial" ), false, true, 0 ); 0349 gtk_toggle_button_set_inconsistent( GTK_TOGGLE_BUTTON( checkbutton ), true ); 0350 gtk_widget_show( checkbutton ); 0351 0352 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "On" ), false, true, 0 ); 0353 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkbutton ), true ); 0354 gtk_widget_show( checkbutton ); 0355 0356 } 0357 0358 { 0359 // radio buttons 0360 GtkWidget* frame( gtk_frame_new( "Radiobuttons" ) ); 0361 gtk_box_pack_start( GTK_BOX( hbox ), frame, true, true, 0 ); 0362 gtk_widget_show( frame ); 0363 0364 GtkWidget* vbox( gtk_vbox_new( false, 0 ) ); 0365 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 0366 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 0367 gtk_widget_show( vbox ); 0368 0369 GtkWidget* radiobutton; 0370 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label( 0L, "First Choice" ), false, true, 0 ); 0371 gtk_widget_show( radiobutton ); 0372 0373 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( radiobutton ), "Second Choice" ), false, true, 0 ); 0374 gtk_widget_show( radiobutton ); 0375 0376 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( radiobutton ), "Third Choice" ), false, true, 0 ); 0377 gtk_widget_show( radiobutton ); 0378 } 0379 0380 } 0381 0382 //____________________________________________________ 0383 ButtonDemoWidget::~ButtonDemoWidget( void ) 0384 {} 0385 0386 //____________________________________________________ 0387 void ButtonDemoWidget::toolBarStyleChanged( GtkComboBox* comboBox, gpointer data ) 0388 { 0389 0390 GtkToolbar* toolbar( GTK_TOOLBAR( static_cast<ButtonDemoWidget*>( data )->_toolbar ) ); 0391 switch( gtk_combo_box_get_active( comboBox ) ) 0392 { 0393 default: 0394 case 0: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); break; 0395 case 1: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_TEXT ); break; 0396 case 2: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_BOTH_HORIZ ); break; 0397 case 3: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_BOTH ); break; 0398 } 0399 0400 } 0401 0402 //____________________________________________________ 0403 void ButtonDemoWidget::iconSizeChanged( GtkComboBox* comboBox, gpointer data ) 0404 { 0405 0406 GtkToolbar* toolbar( GTK_TOOLBAR( static_cast<ButtonDemoWidget*>( data )->_toolbar ) ); 0407 switch( gtk_combo_box_get_active( comboBox ) ) 0408 { 0409 default: 0410 case 0: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_MENU ); break; 0411 case 1: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR ); break; 0412 case 2: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_LARGE_TOOLBAR ); break; 0413 case 3: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_DND ); break; 0414 } 0415 0416 } 0417 0418 }