File indexing completed on 2024-05-05 05:34:56
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 "oxygenframedemowidget.h" 0012 0013 #include <iostream> 0014 #include <string> 0015 0016 namespace Oxygen 0017 { 0018 0019 //____________________________________________________ 0020 FrameDemoWidget::FrameDemoWidget( void ) 0021 { 0022 0023 // main widget 0024 GtkWidget* mainWidget( gtk_vbox_new( false, 0 ) ); 0025 gtk_box_set_spacing( GTK_BOX( mainWidget ), 5 ); 0026 setWidget( mainWidget ); 0027 0028 // setup 0029 setName( "Frames" ); 0030 setComments( "Shows the appearance of various framed widgets" ); 0031 setIconName( "draw-rectangle" ); 0032 realize(); 0033 0034 // orientation 0035 { 0036 GtkWidget* hbox( gtk_hbox_new( false, 0 ) ); 0037 gtk_box_set_spacing( GTK_BOX( hbox ), 5 ); 0038 gtk_box_pack_start( GTK_BOX( mainWidget ), hbox, false, true, 0 ); 0039 gtk_widget_show( hbox ); 0040 0041 // label 0042 GtkWidget* label( gtk_label_new( "Layout orientation: " ) ); 0043 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 ); 0044 gtk_box_pack_start( GTK_BOX( hbox ), label, false, true, 0 ); 0045 gtk_widget_show( label ); 0046 0047 // combobox 0048 GtkListStore* model( gtk_list_store_new( 1, G_TYPE_STRING ) ); 0049 const char* columns[] = 0050 { 0051 "Horizontal", 0052 "Vertical" 0053 }; 0054 0055 for( unsigned int i=0; i<2; i++ ) 0056 { 0057 GtkTreeIter iter; 0058 gtk_list_store_append( model, &iter ); 0059 gtk_list_store_set( model, &iter, 0, columns[i], -1 ); 0060 } 0061 0062 GtkWidget* comboBox( gtk_combo_box_new() ); 0063 gtk_combo_box_set_model( GTK_COMBO_BOX( comboBox ), GTK_TREE_MODEL( model ) ); 0064 g_object_unref( model ); 0065 0066 // text renderer 0067 GtkCellRenderer* cell( gtk_cell_renderer_text_new() ); 0068 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBox ), cell, FALSE ); 0069 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( comboBox ), cell, "text", 0, NULL ); 0070 0071 gtk_combo_box_set_active( GTK_COMBO_BOX( comboBox ), 0 ); 0072 gtk_box_pack_start( GTK_BOX( hbox ), comboBox, false, true, 0 ); 0073 gtk_widget_show( comboBox ); 0074 0075 // connection 0076 connect( G_OBJECT( comboBox ), "changed", G_CALLBACK( orientationChanged ), this ); 0077 0078 } 0079 0080 { 0081 // box 0082 _box = gtk_hbox_new( true, 0 ); 0083 gtk_box_set_spacing( GTK_BOX( _box ), 5 ); 0084 gtk_box_pack_start( GTK_BOX( mainWidget ), _box, true, true, 0 ); 0085 gtk_widget_show( _box ); 0086 0087 // named frame 0088 { 0089 GtkWidget* frame( gtk_frame_new( "GroupBox" ) ); 0090 gtk_box_pack_start( GTK_BOX( _box ), frame, true, true, 0 ); 0091 gtk_widget_show( frame ); 0092 0093 } 0094 0095 // unnamed frame 0096 { 0097 _frame = gtk_frame_new( 0L ); 0098 gtk_frame_set_shadow_type( GTK_FRAME( _frame ), GTK_SHADOW_OUT ); 0099 gtk_box_pack_start( GTK_BOX( _box ), _frame, true, true, 0 ); 0100 gtk_widget_show( _frame ); 0101 0102 GtkWidget* vbox( gtk_vbox_new( false, 0 ) ); 0103 gtk_container_add( GTK_CONTAINER( _frame ), vbox ); 0104 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 ); 0105 gtk_widget_show( vbox ); 0106 0107 GtkWidget* label( gtk_label_new( "Frame" ) ); 0108 gtk_box_pack_start( GTK_BOX( vbox ), label, false, true, 0 ); 0109 gtk_widget_show( label ); 0110 0111 Signal signal; 0112 0113 // radio buttons 0114 GtkWidget* radiobutton; 0115 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label( 0L, "Raised" ), false, true, 0 ); 0116 gtk_widget_show( radiobutton ); 0117 _widgets.insert( std::make_pair( radiobutton, GTK_SHADOW_OUT ) ); 0118 connect( G_OBJECT( radiobutton ), "toggled", G_CALLBACK( shadowChanged ), this ); 0119 0120 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( radiobutton ), "Etched" ), false, true, 0 ); 0121 gtk_widget_show( radiobutton ); 0122 _widgets.insert( std::make_pair( radiobutton, GTK_SHADOW_ETCHED_IN ) ); 0123 connect( G_OBJECT( radiobutton ), "toggled", G_CALLBACK( shadowChanged ), this ); 0124 0125 gtk_box_pack_start( GTK_BOX( vbox ), radiobutton = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( radiobutton ), "Sunken" ), false, true, 0 ); 0126 gtk_widget_show( radiobutton ); 0127 _widgets.insert( std::make_pair( radiobutton, GTK_SHADOW_IN ) ); 0128 connect( G_OBJECT( radiobutton ), "toggled", G_CALLBACK( shadowChanged ), this ); 0129 0130 } 0131 0132 // notebook 0133 { 0134 GtkWidget* notebook( gtk_notebook_new() ); 0135 gtk_box_pack_start( GTK_BOX( _box ), notebook, true, true, 0 ); 0136 gtk_widget_show( notebook ); 0137 0138 // add empty page 0139 GtkWidget* label( gtk_label_new( "Tab Widget" ) ); 0140 GtkWidget* vbox( gtk_vbox_new( false, 0 ) ); 0141 gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), vbox, label ); 0142 gtk_widget_show( label ); 0143 gtk_widget_show( vbox ); 0144 } 0145 0146 } 0147 } 0148 0149 //____________________________________________________ 0150 FrameDemoWidget::~FrameDemoWidget( void ) 0151 {} 0152 0153 //____________________________________________________ 0154 void FrameDemoWidget::shadowChanged( GtkToggleButton* button, gpointer pointer ) 0155 { 0156 FrameDemoWidget& data( *static_cast<FrameDemoWidget*>( pointer ) ); 0157 if( !gtk_toggle_button_get_active( button ) ) return; 0158 0159 WidgetMap::const_iterator iter( data._widgets.find( GTK_WIDGET( button ) ) ); 0160 if( iter == data._widgets.end() ) return; 0161 gtk_frame_set_shadow_type( GTK_FRAME( data._frame ), iter->second ); 0162 0163 } 0164 0165 //____________________________________________________ 0166 void FrameDemoWidget::orientationChanged( GtkComboBox* comboBox, gpointer pointer ) 0167 { 0168 const gint id( gtk_combo_box_get_active( comboBox ) ); 0169 gtk_orientable_set_orientation( 0170 GTK_ORIENTABLE( static_cast<FrameDemoWidget*>( pointer )->_box ), 0171 id == 0 ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL ); 0172 } 0173 0174 }