1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * based on the Null Theme Engine for Gtk+. 6 * Copyright (c) 2008 Robert Staudinger <robert.staudinger@gmail.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or( at your option ) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free 20 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 * MA 02110-1301, USA. 22 */ 23 24 #include "oxygenbuttondemowidget.h" 25 26 #include <string> 27 28 namespace Oxygen 29 { 30 31 //____________________________________________________ ButtonDemoWidget(void)32 ButtonDemoWidget::ButtonDemoWidget( void ) 33 { 34 35 // main widget 36 GtkWidget* mainWidget( gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ) ); 37 gtk_box_set_spacing( GTK_BOX( mainWidget ), 4 ); 38 setWidget( mainWidget ); 39 40 // setup 41 setName( "Buttons" ); 42 setComments( "Shows the appearance of buttons" ); 43 setIconName( "go-jump-locationbar" ); 44 realize(); 45 46 // pushbuttons 47 { 48 GtkWidget* frame( gtk_frame_new( "Pushbutton" ) ); 49 gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 ); 50 gtk_widget_show( frame ); 51 52 // inner grid 53 GtkWidget* grid = gtk_grid_new(); 54 gtk_container_set_border_width( GTK_CONTAINER( grid ), 8 ); 55 gtk_grid_set_row_spacing( GTK_GRID( grid ), 4 ); 56 gtk_container_add( GTK_CONTAINER( frame ), grid ); 57 gtk_widget_show( grid ); 58 59 // spacing 60 GtkWidget* spacing( gtk_label_new( "" ) ); 61 gtk_grid_attach( GTK_GRID( grid ), spacing, 3, 0, 1, 1 ); 62 gtk_widget_show( spacing ); 63 64 // generic label 65 GtkWidget* label( 0L ); 66 67 { 68 // text only 69 gtk_grid_attach( GTK_GRID( grid ), label = gtk_label_new( "Text only: " ), 0, 0, 1, 1 ); 70 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 71 gtk_widget_show( label ); 72 73 // button 74 GtkWidget* button( gtk_button_new_with_label( "Normal" ) ); 75 gtk_grid_attach( GTK_GRID( grid ), button, 1, 0, 1, 1 ); 76 gtk_widget_show( button ); 77 gtk_widget_set_tooltip_text( button, "This is a normal, text only button" ); 78 79 // combobox model 80 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 81 const char* columns[] = 82 { 83 "Small", 84 "Normal", 85 "Large" 86 }; 87 88 for( unsigned int i=0; i<3; i++ ) 89 { 90 GtkTreeIter iter; 91 gtk_list_store_append( model, &iter ); 92 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 93 } 94 95 GtkWidget* comboBox( gtk_combo_box_new() ); 96 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 97 g_object_unref( model ); 98 99 // text renderer 100 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 101 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 102 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 103 104 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 105 106 gtk_grid_attach( GTK_GRID( grid ), comboBox, 2, 0, 1, 1 ); 107 gtk_widget_show( comboBox ); 108 gtk_widget_set_tooltip_text( comboBox, "This is a normal, text only combo box" ); 109 110 } 111 112 { 113 // text and icons 114 gtk_grid_attach( GTK_GRID( grid ), label = gtk_label_new( "Text and icon: " ), 0, 1, 1, 1 ); 115 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 116 gtk_widget_show( label ); 117 118 // button 119 GtkWidget* button( gtk_button_new_with_label( "Normal" ) ); 120 gtk_grid_attach( GTK_GRID( grid ), button, 1, 1, 1, 1 ); 121 122 GtkIconTheme* theme( gtk_icon_theme_get_default() ); 123 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, "oxygen", 16, (GtkIconLookupFlags) 0, 0L ); 124 if(icon) 125 { 126 GtkWidget* image( gtk_image_new_from_pixbuf( icon ) ); 127 g_object_unref( icon ); 128 129 gtk_button_set_image( GTK_BUTTON( button ), image ); 130 } 131 gtk_widget_show( button ); 132 gtk_widget_set_tooltip_text( button, "This is a normal, text and icon button" ); 133 134 // combobox model 135 GtkListStore* model( gtk_list_store_new( 2, GDK_TYPE_PIXBUF, G_TYPE_STRING ) ); 136 const char* columns[] = 137 { 138 "New", 139 "Open", 140 "Save" 141 }; 142 143 const char* icons[] = 144 { 145 "document-new", 146 "document-open", 147 "document-save" 148 }; 149 150 // store into model 151 for( unsigned int i=0; i<3; i++ ) 152 { 153 GtkTreeIter iter; 154 gtk_list_store_append( model, &iter ); 155 156 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, icons[i], 16, (GtkIconLookupFlags) 0, 0L ); 157 gtk_list_store_set( model, &iter, 0, icon, 1, columns[i], -1 ); 158 g_object_unref( icon ); 159 } 160 161 GtkWidget* comboBox( gtk_combo_box_new() ); 162 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 163 g_object_unref( model ); 164 165 { 166 // pixbuf renderer 167 GtkCellRenderer* cell = gtk_cell_renderer_pixbuf_new(); 168 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 169 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, 170 "pixbuf", 0, 171 NULL ); 172 } 173 174 { 175 // text renderer 176 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 177 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 178 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 1, NULL ); 179 } 180 181 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 182 183 gtk_grid_attach( GTK_GRID( grid ), comboBox, 2, 1, 1, 1 ); 184 gtk_widget_show( comboBox ); 185 gtk_widget_set_tooltip_text( comboBox, "This is a normal, text and icon combo box" ); 186 187 } 188 189 190 } 191 192 { 193 // toolbar 194 GtkWidget* frame( gtk_frame_new( "Toolbuttons" ) ); 195 gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 ); 196 gtk_widget_show( frame ); 197 198 // inner box 199 GtkWidget* vbox( gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ) ); 200 gtk_box_set_spacing( GTK_BOX( vbox ), 4 ); 201 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 202 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 203 gtk_widget_show( vbox ); 204 205 _toolbar = gtk_toolbar_new(); 206 gtk_box_pack_start( GTK_BOX( vbox ), _toolbar, false, true, 0 ); 207 gtk_widget_show( _toolbar ); 208 209 // toolbuttons 210 GtkToolItem* toolButton; 211 212 gtk_toolbar_insert( GTK_TOOLBAR(_toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 0 ); 213 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "document-new" ); 214 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "New" ); 215 gtk_widget_show( GTK_WIDGET( toolButton ) ); 216 217 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 1 ); 218 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "document-open" ); 219 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Open" ); 220 gtk_widget_show( GTK_WIDGET( toolButton ) ); 221 222 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 2 ); 223 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "document-save" ); 224 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Save" ); 225 gtk_widget_show( GTK_WIDGET( toolButton ) ); 226 227 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 3 ); 228 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "edit-cut" ); 229 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Cut selection" ); 230 gtk_widget_show( GTK_WIDGET( toolButton ) ); 231 232 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 4 ); 233 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "edit-copy" ); 234 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Copy selection" ); 235 gtk_widget_show( GTK_WIDGET( toolButton ) ); 236 237 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_tool_button_new( 0, 0 ), 5 ); 238 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "edit-paste" ); 239 gtk_widget_set_tooltip_markup( GTK_WIDGET( toolButton ), "Paste clipboard" ); 240 gtk_widget_show( GTK_WIDGET( toolButton ) ); 241 242 gtk_toolbar_insert( GTK_TOOLBAR( _toolbar ), toolButton = gtk_toggle_tool_button_new(), 6 ); 243 gtk_tool_button_set_icon_name( GTK_TOOL_BUTTON( toolButton ), "dialog-password" ); 244 gtk_toggle_tool_button_set_active( GTK_TOGGLE_TOOL_BUTTON( toolButton ), true ); 245 gtk_widget_show( GTK_WIDGET( toolButton ) ); 246 247 // grid for text position and icon size 248 GtkWidget* grid = gtk_grid_new(); 249 gtk_container_set_border_width( GTK_CONTAINER( grid ), 4 ); 250 gtk_grid_set_row_spacing( GTK_GRID( grid ), 4 ); 251 gtk_box_pack_start( GTK_BOX( vbox ), grid, false, true, 0 ); 252 gtk_widget_show( grid ); 253 254 { 255 256 // text position combobox 257 GtkWidget* label( 0L ); 258 259 gtk_grid_attach( GTK_GRID( grid ), label = gtk_label_new( "Text position: " ), 0, 0, 1, 1 ); 260 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 261 gtk_widget_show( label ); 262 263 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 264 const char* columns[] = 265 { 266 "Icons Only", 267 "Text Only", 268 "Text Alongside Icons", 269 "Text Under Icons" 270 }; 271 272 for( unsigned int i=0; i<4; i++ ) 273 { 274 GtkTreeIter iter; 275 gtk_list_store_append( model, &iter ); 276 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 277 } 278 279 GtkWidget* comboBox( gtk_combo_box_new() ); 280 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 281 g_object_unref( model ); 282 283 // text renderer 284 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 285 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 286 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 287 288 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 289 290 gtk_grid_attach( GTK_GRID( grid ), comboBox, 1, 0, 1, 1 ); 291 gtk_widget_show( comboBox ); 292 293 // connection 294 connect( G_OBJECT( comboBox ), "changed", G_CALLBACK( toolBarStyleChanged ), this ); 295 296 } 297 298 { 299 300 // icon size combobox 301 GtkWidget* label( 0L ); 302 303 gtk_grid_attach( GTK_GRID( grid ), label = gtk_label_new( "Icon size: " ), 0, 1, 1, 1 ); 304 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 305 gtk_widget_show( label ); 306 307 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 308 const char* columns[] = 309 { 310 "Small", 311 "Medium", 312 "Large", 313 "Huge" 314 }; 315 316 for( unsigned int i=0; i<4; i++ ) 317 { 318 GtkTreeIter iter; 319 gtk_list_store_append( model, &iter ); 320 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 321 } 322 323 GtkWidget* comboBox( gtk_combo_box_new() ); 324 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 325 g_object_unref( model ); 326 327 // text renderer 328 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 329 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 330 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 331 332 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 2 ); 333 334 gtk_grid_attach( GTK_GRID( grid ), comboBox, 1, 1, 1, 1 ); 335 gtk_widget_show( comboBox ); 336 337 // connection 338 connect( G_OBJECT( comboBox ), "changed", G_CALLBACK( iconSizeChanged ), this ); 339 340 } 341 342 343 } 344 345 // checkboxes and radiobuttons 346 GtkWidget* hbox( gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 ) ); 347 gtk_box_set_spacing( GTK_BOX( hbox ), 4 ); 348 gtk_box_pack_start( GTK_BOX( mainWidget ), hbox, false, true, 0 ); 349 gtk_widget_show( hbox ); 350 351 { 352 // checkboxes 353 GtkWidget* frame( gtk_frame_new( "Checkboxes" ) ); 354 gtk_box_pack_start( GTK_BOX( hbox ), frame, true, true, 0 ); 355 gtk_widget_show( frame ); 356 357 GtkWidget* vbox( gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ) ); 358 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 359 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 360 gtk_widget_show( vbox ); 361 362 GtkWidget* checkbutton; 363 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "Off" ), false, true, 0 ); 364 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkbutton ), false ); 365 gtk_widget_show( checkbutton ); 366 367 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "Partial" ), false, true, 0 ); 368 gtk_toggle_button_set_inconsistent( GTK_TOGGLE_BUTTON( checkbutton ), true ); 369 gtk_widget_show( checkbutton ); 370 371 gtk_box_pack_start( GTK_BOX( vbox ), checkbutton = gtk_check_button_new_with_label( "On" ), false, true, 0 ); 372 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkbutton ), true ); 373 gtk_widget_show( checkbutton ); 374 375 } 376 377 { 378 // radio buttons 379 GtkWidget* frame( gtk_frame_new( "Radiobuttons" ) ); 380 gtk_box_pack_start( GTK_BOX( hbox ), frame, true, true, 0 ); 381 gtk_widget_show( frame ); 382 383 GtkWidget* vbox( gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ) ); 384 gtk_container_add( GTK_CONTAINER( frame ), vbox ); 385 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 4 ); 386 gtk_widget_show( vbox ); 387 388 GtkWidget* radiobutton; 389 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label( 0L, "First Choice" ), false, true, 0 ); 390 gtk_widget_show( radiobutton ); 391 392 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 ); 393 gtk_widget_show( radiobutton ); 394 395 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 ); 396 gtk_widget_show( radiobutton ); 397 } 398 399 400 { 401 // other buttons 402 GtkWidget* frame( gtk_frame_new( "Other buttons" ) ); 403 gtk_box_pack_start( GTK_BOX( mainWidget ), frame, false, true, 0 ); 404 gtk_widget_show( frame ); 405 406 // switch 407 GtkWidget* hbox( gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 ) ); 408 gtk_box_set_spacing( GTK_BOX( hbox ), 4 ); 409 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 8 ); 410 gtk_container_add( GTK_CONTAINER( frame ), hbox ); 411 gtk_widget_show( hbox ); 412 413 GtkWidget* label; 414 gtk_box_pack_start( GTK_BOX( hbox ), label = gtk_label_new( "On/Off switch: " ), false, false, 0 ); 415 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 416 gtk_widget_show( label ); 417 418 GtkWidget* switchbutton; 419 gtk_box_pack_start( GTK_BOX( hbox ), switchbutton = gtk_switch_new(), false, false, 0 ); 420 gtk_widget_show( switchbutton ); 421 } 422 423 } 424 425 //____________________________________________________ ~ButtonDemoWidget(void)426 ButtonDemoWidget::~ButtonDemoWidget( void ) 427 {} 428 429 //____________________________________________________ toolBarStyleChanged(GtkComboBox * comboBox,gpointer data)430 void ButtonDemoWidget::toolBarStyleChanged( GtkComboBox* comboBox, gpointer data ) 431 { 432 433 GtkToolbar* toolbar( GTK_TOOLBAR( static_cast<ButtonDemoWidget*>( data )->_toolbar ) ); 434 switch( gtk_combo_box_get_active( comboBox ) ) 435 { 436 default: 437 case 0: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); break; 438 case 1: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_TEXT ); break; 439 case 2: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_BOTH_HORIZ ); break; 440 case 3: gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_BOTH ); break; 441 } 442 443 } 444 445 //____________________________________________________ iconSizeChanged(GtkComboBox * comboBox,gpointer data)446 void ButtonDemoWidget::iconSizeChanged( GtkComboBox* comboBox, gpointer data ) 447 { 448 449 GtkToolbar* toolbar( GTK_TOOLBAR( static_cast<ButtonDemoWidget*>( data )->_toolbar ) ); 450 switch( gtk_combo_box_get_active( comboBox ) ) 451 { 452 default: 453 case 0: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_MENU ); break; 454 case 1: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR ); break; 455 case 2: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_LARGE_TOOLBAR ); break; 456 case 3: gtk_toolbar_set_icon_size( toolbar, GTK_ICON_SIZE_DND ); break; 457 } 458 459 } 460 461 } 462