2008-07-01 22:57:50 +00:00
/* GTK - The GIMP Toolkit
2008-02-27 10:31:24 +00:00
* Copyright ( C ) 1995 - 1997 Peter Mattis , Spencer Kimball and Josh MacDonald
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
2012-02-27 13:01:10 +00:00
* License along with this library . If not , see < http : //www.gnu.org/licenses/>.
2008-02-27 10:31:24 +00:00
*/
2001-08-04 23:30:11 +00:00
2008-02-27 10:31:24 +00:00
/*
* Modified by the GTK + Team and others 1997 - 2000. See the AUTHORS
* file for a list of people on the GTK + Team . See the ChangeLog
* files for a list of changes . These files are distributed with
* GTK + at ftp : //ftp.gtk.org/pub/gtk/.
*/
2008-06-22 14:28:52 +00:00
# include "config.h"
2008-02-27 10:31:24 +00:00
# undef G_LOG_DOMAIN
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/stat.h>
# include <math.h>
# include <time.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
2017-03-12 18:36:21 +00:00
# include <glib/gstdio.h>
2008-02-27 10:31:24 +00:00
# include "gtk/gtk.h"
# include "gdk/gdk.h"
# include "gdk/gdkkeysyms.h"
# ifdef G_OS_WIN32
# define sleep(n) _sleep(n)
# endif
# include "test.xpm"
gboolean
file_exists ( const char * filename )
{
struct stat statbuf ;
return stat ( filename , & statbuf ) = = 0 ;
}
static GtkWidget *
build_option_menu ( gchar * items [ ] ,
gint num_items ,
gint history ,
void ( * func ) ( GtkWidget * widget , gpointer data ) ,
gpointer data ) ;
/* macro, structure and variables used by tree window demos */
# define DEFAULT_NUMBER_OF_ITEM 3
# define DEFAULT_RECURSION_LEVEL 3
struct {
GSList * selection_mode_group ;
GtkWidget * single_button ;
GtkWidget * browse_button ;
GtkWidget * multiple_button ;
GtkWidget * draw_line_button ;
GtkWidget * view_line_button ;
GtkWidget * no_root_item_button ;
GtkWidget * nb_item_spinner ;
GtkWidget * recursion_spinner ;
} sTreeSampleSelection ;
typedef struct sTreeButtons {
guint nb_item_add ;
GtkWidget * add_button ;
GtkWidget * remove_button ;
GtkWidget * subtree_button ;
} sTreeButtons ;
/* end of tree section */
static GtkWidget *
build_option_menu ( gchar * items [ ] ,
gint num_items ,
gint history ,
void ( * func ) ( GtkWidget * widget , gpointer data ) ,
gpointer data )
{
GtkWidget * omenu ;
gint i ;
2010-10-02 16:19:46 +00:00
omenu = gtk_combo_box_text_new ( ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( omenu , " changed " ,
G_CALLBACK ( func ) , data ) ;
for ( i = 0 ; i < num_items ; i + + )
2010-10-02 16:19:46 +00:00
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( omenu ) , items [ i ] ) ;
2008-02-27 10:31:24 +00:00
2010-03-26 16:55:07 +00:00
gtk_combo_box_set_active ( GTK_COMBO_BOX ( omenu ) , history ) ;
2008-02-27 10:31:24 +00:00
return omenu ;
}
/*
* Windows with an alpha channel
*/
static GtkWidget *
build_alpha_widgets ( void )
{
2011-09-28 00:25:07 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * radio_button ;
2011-09-28 00:25:07 +00:00
GtkWidget * check_button ;
2008-02-27 10:31:24 +00:00
GtkWidget * hbox ;
GtkWidget * label ;
GtkWidget * entry ;
2011-09-28 00:25:07 +00:00
grid = gtk_grid_new ( ) ;
2008-02-27 10:31:24 +00:00
radio_button = gtk_radio_button_new_with_label ( NULL , " Red " ) ;
2011-09-28 00:25:07 +00:00
gtk_widget_set_hexpand ( radio_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , radio_button , 0 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
radio_button = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radio_button ) , " Green " ) ;
2011-09-28 00:25:07 +00:00
gtk_widget_set_hexpand ( radio_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , radio_button , 0 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
radio_button = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radio_button ) , " Blue " ) ,
2011-09-28 00:25:07 +00:00
gtk_widget_set_hexpand ( radio_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , radio_button , 0 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2011-09-28 00:25:07 +00:00
check_button = gtk_check_button_new_with_label ( " Sedentary " ) ,
gtk_widget_set_hexpand ( check_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 1 , 0 , 1 , 1 ) ;
check_button = gtk_check_button_new_with_label ( " Nocturnal " ) ,
gtk_widget_set_hexpand ( check_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 1 , 1 , 1 , 1 ) ;
check_button = gtk_check_button_new_with_label ( " Compulsive " ) ,
gtk_widget_set_hexpand ( check_button , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 1 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( NULL ) ;
gtk_label_set_markup ( GTK_LABEL ( label ) , " <i>Entry: </i> " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2008-02-27 10:31:24 +00:00
entry = gtk_entry_new ( ) ;
2017-04-21 16:59:59 +00:00
gtk_widget_set_hexpand ( entry , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , entry ) ;
2011-09-28 00:25:07 +00:00
gtk_widget_set_hexpand ( hbox , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , hbox , 0 , 3 , 2 , 1 ) ;
2016-10-02 15:37:22 +00:00
2011-09-28 00:25:07 +00:00
return grid ;
2008-02-27 10:31:24 +00:00
}
static void
2016-10-29 02:37:20 +00:00
on_composited_changed ( GdkDisplay * display ,
GParamSpec * pspec ,
GtkLabel * label )
2008-02-27 10:31:24 +00:00
{
2016-10-29 02:37:20 +00:00
gboolean is_composited = gdk_display_is_composited ( display ) ;
2008-02-27 10:31:24 +00:00
if ( is_composited )
gtk_label_set_text ( label , " Composited " ) ;
else
gtk_label_set_text ( label , " Not composited " ) ;
2016-10-29 02:37:20 +00:00
2018-03-20 10:40:08 +00:00
/* We draw a different background on the GdkSurface */
2016-10-29 02:37:20 +00:00
gtk_widget_queue_draw ( gtk_widget_get_toplevel ( GTK_WIDGET ( label ) ) ) ;
2008-02-27 10:31:24 +00:00
}
void
create_alpha_window ( GtkWidget * widget )
{
static GtkWidget * window ;
if ( ! window )
{
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * vbox ;
GtkWidget * label ;
2016-10-29 02:37:20 +00:00
GdkDisplay * display ;
2018-04-02 07:18:48 +00:00
GtkCssProvider * provider ;
2008-02-27 10:31:24 +00:00
window = gtk_dialog_new_with_buttons ( " Alpha Window " ,
GTK_WINDOW ( gtk_widget_get_toplevel ( widget ) ) , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " , 0 ,
2008-02-27 10:31:24 +00:00
NULL ) ;
2018-04-02 07:18:48 +00:00
provider = gtk_css_provider_new ( ) ;
gtk_css_provider_load_from_data ( provider ,
" dialog { \n "
" background: radial-gradient(ellipse at center, #FFBF00, #FFBF0000); \n "
" } \n " ,
- 1 ) ;
gtk_style_context_add_provider ( gtk_widget_get_style_context ( window ) ,
GTK_STYLE_PROVIDER ( provider ) ,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION ) ;
g_object_unref ( provider ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 8 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , vbox ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , label ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , label ) ;
2016-10-29 02:37:20 +00:00
display = gtk_widget_get_display ( window ) ;
on_composited_changed ( display , NULL , GTK_LABEL ( label ) ) ;
g_signal_connect ( display , " notify::composited " , G_CALLBACK ( on_composited_changed ) , label ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , build_alpha_widgets ( ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
2016-10-02 15:37:22 +00:00
NULL ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkButton
*/
static void
button_window ( GtkWidget * widget ,
GtkWidget * button )
{
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( button ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( button ) ;
else
gtk_widget_hide ( button ) ;
}
static void
create_buttons ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
2011-09-28 00:52:07 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * separator ;
2011-09-28 00:45:43 +00:00
GtkWidget * button [ 10 ] ;
int button_x [ 9 ] = { 0 , 1 , 2 , 0 , 2 , 1 , 1 , 2 , 0 } ;
int button_y [ 9 ] = { 0 , 1 , 2 , 2 , 0 , 2 , 0 , 1 , 1 } ;
guint i ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkButton " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2011-09-28 00:52:07 +00:00
grid = gtk_grid_new ( ) ;
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 5 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , grid ) ;
2008-02-27 10:31:24 +00:00
button [ 0 ] = gtk_button_new_with_label ( " button1 " ) ;
button [ 1 ] = gtk_button_new_with_mnemonic ( " _button2 " ) ;
button [ 2 ] = gtk_button_new_with_mnemonic ( " _button3 " ) ;
2016-10-02 17:03:29 +00:00
button [ 3 ] = gtk_button_new_with_mnemonic ( " _button4 " ) ;
2008-02-27 10:31:24 +00:00
button [ 4 ] = gtk_button_new_with_label ( " button5 " ) ;
button [ 5 ] = gtk_button_new_with_label ( " button6 " ) ;
button [ 6 ] = gtk_button_new_with_label ( " button7 " ) ;
2016-10-02 17:03:29 +00:00
button [ 7 ] = gtk_button_new_with_label ( " button8 " ) ;
2008-02-27 10:31:24 +00:00
button [ 8 ] = gtk_button_new_with_label ( " button9 " ) ;
2016-10-02 17:03:29 +00:00
2011-09-28 00:45:43 +00:00
for ( i = 0 ; i < 9 ; i + + )
{
g_signal_connect ( button [ i ] , " clicked " ,
G_CALLBACK ( button_window ) ,
button [ ( i + 1 ) % 9 ] ) ;
2011-09-28 00:52:07 +00:00
gtk_widget_set_hexpand ( button [ i ] , TRUE ) ;
gtk_widget_set_vexpand ( button [ i ] , TRUE ) ;
2011-09-28 00:45:43 +00:00
2011-09-28 00:52:07 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , button [ i ] ,
button_x [ i ] , button_y [ i ] + 1 , 1 , 1 ) ;
2011-09-28 00:45:43 +00:00
}
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button [ 9 ] = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button [ 9 ] , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button [ 9 ] ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button [ 9 ] , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button [ 9 ] ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkToggleButton
*/
static void
create_toggle_buttons ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * separator ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkToggleButton " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_toggle_button_new_with_label ( " button1 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_toggle_button_new_with_label ( " button2 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_toggle_button_new_with_label ( " button3 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
static GtkWidget *
create_widget_grid ( GType widget_type )
{
2011-09-28 01:25:47 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * group_widget = NULL ;
gint i , j ;
2011-09-28 01:25:47 +00:00
grid = gtk_grid_new ( ) ;
2008-02-27 10:31:24 +00:00
for ( i = 0 ; i < 5 ; i + + )
{
for ( j = 0 ; j < 5 ; j + + )
{
GtkWidget * widget ;
char * tmp ;
if ( i = = 0 & & j = = 0 )
{
widget = NULL ;
}
else if ( i = = 0 )
{
tmp = g_strdup_printf ( " %d " , j ) ;
widget = gtk_label_new ( tmp ) ;
g_free ( tmp ) ;
}
else if ( j = = 0 )
{
tmp = g_strdup_printf ( " %c " , ' A ' + i - 1 ) ;
widget = gtk_label_new ( tmp ) ;
g_free ( tmp ) ;
}
else
{
widget = g_object_new ( widget_type , NULL ) ;
if ( g_type_is_a ( widget_type , GTK_TYPE_RADIO_BUTTON ) )
{
if ( ! group_widget )
group_widget = widget ;
else
g_object_set ( widget , " group " , group_widget , NULL ) ;
}
}
if ( widget )
2011-09-28 01:25:47 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , widget , i , j , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
}
}
2011-09-28 01:25:47 +00:00
return grid ;
2008-02-27 10:31:24 +00:00
}
/*
* GtkCheckButton
*/
static void
create_check_buttons ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * separator ;
GtkWidget * table ;
if ( ! window )
{
window = gtk_dialog_new_with_buttons ( " Check Buttons " ,
NULL , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " ,
2008-02-27 10:31:24 +00:00
GTK_RESPONSE_NONE ,
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
g_signal_connect ( window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2010-06-03 07:36:39 +00:00
box1 = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_mnemonic ( " _button1 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " button2 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " button3 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " inconsistent " ) ;
2017-01-28 07:11:14 +00:00
gtk_check_button_set_inconsistent ( GTK_CHECK_BUTTON ( button ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
table = create_widget_grid ( GTK_TYPE_CHECK_BUTTON ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , table ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkRadioButton
*/
static void
create_radio_buttons ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * separator ;
GtkWidget * table ;
if ( ! window )
{
window = gtk_dialog_new_with_buttons ( " Radio Buttons " ,
NULL , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " ,
2008-02-27 10:31:24 +00:00
GTK_RESPONSE_NONE ,
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
g_signal_connect ( window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2010-06-03 07:36:39 +00:00
box1 = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label ( NULL , " button1 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group ( GTK_RADIO_BUTTON ( button ) ) ,
" button2 " ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group ( GTK_RADIO_BUTTON ( button ) ) ,
" button3 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group ( GTK_RADIO_BUTTON ( button ) ) ,
" inconsistent " ) ;
2017-01-28 07:11:14 +00:00
gtk_check_button_set_inconsistent ( GTK_CHECK_BUTTON ( button ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2016-10-02 15:37:22 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label ( NULL , " button4 " ) ;
2017-01-27 11:02:47 +00:00
gtk_check_button_set_draw_indicator ( GTK_CHECK_BUTTON ( button ) , FALSE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group ( GTK_RADIO_BUTTON ( button ) ) ,
" button5 " ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
2017-01-27 11:02:47 +00:00
gtk_check_button_set_draw_indicator ( GTK_CHECK_BUTTON ( button ) , FALSE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group ( GTK_RADIO_BUTTON ( button ) ) ,
" button6 " ) ;
2017-01-27 11:02:47 +00:00
gtk_check_button_set_draw_indicator ( GTK_CHECK_BUTTON ( button ) , FALSE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
table = create_widget_grid ( GTK_TYPE_RADIO_BUTTON ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , table ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkButtonBox
*/
static GtkWidget *
create_bbox ( gint horizontal ,
char * title ,
gint spacing ,
gint child_w ,
gint child_h ,
gint layout )
{
GtkWidget * frame ;
GtkWidget * bbox ;
GtkWidget * button ;
frame = gtk_frame_new ( title ) ;
if ( horizontal )
2010-10-29 23:21:15 +00:00
bbox = gtk_button_box_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
else
2010-10-29 23:21:15 +00:00
bbox = gtk_button_box_new ( GTK_ORIENTATION_VERTICAL ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , bbox ) ;
gtk_button_box_set_layout ( GTK_BUTTON_BOX ( bbox ) , layout ) ;
gtk_box_set_spacing ( GTK_BOX ( bbox ) , spacing ) ;
button = gtk_button_new_with_label ( " OK " ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , button ) ;
button = gtk_button_new_with_label ( " Cancel " ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , button ) ;
button = gtk_button_new_with_label ( " Help " ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , button ) ;
return frame ;
}
static void
create_button_box ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * main_vbox ;
GtkWidget * vbox ;
GtkWidget * hbox ;
GtkWidget * frame_horz ;
GtkWidget * frame_vert ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) , gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Button Boxes " ) ;
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2010-10-31 17:07:20 +00:00
main_vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , main_vbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
frame_horz = gtk_frame_new ( " Horizontal Button Boxes " ) ;
2016-10-02 15:37:22 +00:00
gtk_widget_set_margin_top ( frame_horz , 10 ) ;
gtk_widget_set_margin_bottom ( frame_horz , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , frame_horz ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame_horz ) , vbox ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( TRUE , " Spread " , 40 , 85 , 20 , GTK_BUTTONBOX_SPREAD ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( TRUE , " Edge " , 40 , 85 , 20 , GTK_BUTTONBOX_EDGE ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( TRUE , " Start " , 40 , 85 , 20 , GTK_BUTTONBOX_START ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( TRUE , " End " , 40 , 85 , 20 , GTK_BUTTONBOX_END ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( TRUE , " Center " , 40 , 85 , 20 , GTK_BUTTONBOX_CENTER ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
frame_vert = gtk_frame_new ( " Vertical Button Boxes " ) ;
2016-10-02 15:37:22 +00:00
gtk_widget_set_margin_top ( frame_vert , 10 ) ;
gtk_widget_set_margin_bottom ( frame_vert , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , frame_vert ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame_vert ) , hbox ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( FALSE , " Spread " , 30 , 85 , 20 , GTK_BUTTONBOX_SPREAD ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( FALSE , " Edge " , 30 , 85 , 20 , GTK_BUTTONBOX_EDGE ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( FALSE , " Start " , 30 , 85 , 20 , GTK_BUTTONBOX_START ) ) ;
2016-10-02 15:37:22 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( FALSE , " End " , 30 , 85 , 20 , GTK_BUTTONBOX_END ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) ,
2017-04-21 20:34:36 +00:00
create_bbox ( FALSE , " Center " , 30 , 85 , 20 , GTK_BUTTONBOX_CENTER ) ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkToolBar
*/
static GtkWidget *
2010-08-06 20:09:08 +00:00
new_pixbuf ( char * filename ,
2018-03-20 10:40:08 +00:00
GdkSurface * window )
2008-02-27 10:31:24 +00:00
{
2010-08-06 20:09:08 +00:00
GtkWidget * widget ;
GdkPixbuf * pixbuf ;
2008-02-27 10:31:24 +00:00
2010-08-06 20:09:08 +00:00
if ( strcmp ( filename , " test.xpm " ) = = 0 )
pixbuf = NULL ;
2008-02-27 10:31:24 +00:00
else
2010-08-06 20:09:08 +00:00
pixbuf = gdk_pixbuf_new_from_file ( filename , NULL ) ;
if ( pixbuf = = NULL )
pixbuf = gdk_pixbuf_new_from_xpm_data ( ( const char * * ) openfile ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 20:09:08 +00:00
widget = gtk_image_new_from_pixbuf ( pixbuf ) ;
g_object_unref ( pixbuf ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 20:09:08 +00:00
return widget ;
2008-02-27 10:31:24 +00:00
}
/*
* GtkStatusBar
*/
static guint statusbar_counter = 1 ;
static void
statusbar_push ( GtkWidget * button ,
GtkStatusbar * statusbar )
{
gchar text [ 1024 ] ;
sprintf ( text , " something %d " , statusbar_counter + + ) ;
gtk_statusbar_push ( statusbar , 1 , text ) ;
}
static void
statusbar_push_long ( GtkWidget * button ,
GtkStatusbar * statusbar )
{
gchar text [ 1024 ] ;
sprintf ( text , " Just because a system has menu choices written with English words, phrases or sentences, that is no guarantee, that it is comprehensible. Individual words may not be familiar to some users (for example, \" repaginate \" ), and two menu items may appear to satisfy the users's needs, whereas only one does (for example, \" put away \" or \" eject \" ). " ) ;
gtk_statusbar_push ( statusbar , 1 , text ) ;
}
static void
statusbar_pop ( GtkWidget * button ,
GtkStatusbar * statusbar )
{
gtk_statusbar_pop ( statusbar , 1 ) ;
}
static void
statusbar_steal ( GtkWidget * button ,
GtkStatusbar * statusbar )
{
gtk_statusbar_remove ( statusbar , 1 , 4 ) ;
}
static void
statusbar_popped ( GtkStatusbar * statusbar ,
guint context_id ,
const gchar * text )
{
2010-07-13 01:05:58 +00:00
if ( ! text )
2008-02-27 10:31:24 +00:00
statusbar_counter = 1 ;
}
static void
statusbar_contexts ( GtkStatusbar * statusbar )
{
gchar * string ;
string = " any context " ;
g_print ( " GtkStatusBar: context= \" %s \" , context_id=%d \n " ,
string ,
gtk_statusbar_get_context_id ( statusbar , string ) ) ;
string = " idle messages " ;
g_print ( " GtkStatusBar: context= \" %s \" , context_id=%d \n " ,
string ,
gtk_statusbar_get_context_id ( statusbar , string ) ) ;
string = " some text " ;
g_print ( " GtkStatusBar: context= \" %s \" , context_id=%d \n " ,
string ,
gtk_statusbar_get_context_id ( statusbar , string ) ) ;
string = " hit the mouse " ;
g_print ( " GtkStatusBar: context= \" %s \" , context_id=%d \n " ,
string ,
gtk_statusbar_get_context_id ( statusbar , string ) ) ;
string = " hit the mouse2 " ;
g_print ( " GtkStatusBar: context= \" %s \" , context_id=%d \n " ,
string ,
gtk_statusbar_get_context_id ( statusbar , string ) ) ;
}
static void
create_statusbar ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * separator ;
GtkWidget * statusbar ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " statusbar " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
statusbar = gtk_statusbar_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( box1 ) , statusbar ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( statusbar ,
" text_popped " ,
G_CALLBACK ( statusbar_popped ) ,
NULL ) ;
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
button = g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " push something " ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
g_object_connect ( button ,
" signal::clicked " , statusbar_push , statusbar ,
NULL ) ;
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
button = g_object_connect ( g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " pop " ,
NULL ) ,
" signal_after::clicked " , statusbar_pop , statusbar ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
button = g_object_connect ( g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " steal #4 " ,
NULL ) ,
" signal_after::clicked " , statusbar_steal , statusbar ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
button = g_object_connect ( g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " test contexts " ,
NULL ) ,
" swapped_signal_after::clicked " , statusbar_contexts , statusbar ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
button = g_object_connect ( g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " push something long " ,
NULL ) ,
" signal_after::clicked " , statusbar_push_long , statusbar ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , button ) ;
2016-10-02 15:37:22 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* Label Demo
*/
static void
sensitivity_toggled ( GtkWidget * toggle ,
GtkWidget * widget )
{
2010-10-19 16:46:40 +00:00
gtk_widget_set_sensitive ( widget ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( toggle ) ) ) ;
2008-02-27 10:31:24 +00:00
}
static GtkWidget *
create_sensitivity_control ( GtkWidget * widget )
{
GtkWidget * button ;
button = gtk_toggle_button_new_with_label ( " Sensitive " ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) ,
2010-02-27 04:24:24 +00:00
gtk_widget_is_sensitive ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( button ,
" toggled " ,
G_CALLBACK ( sensitivity_toggled ) ,
widget ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( button ) ;
2008-02-27 10:31:24 +00:00
return button ;
}
static void
set_selectable_recursive ( GtkWidget * widget ,
gboolean setting )
{
if ( GTK_IS_CONTAINER ( widget ) )
{
GList * children ;
GList * tmp ;
children = gtk_container_get_children ( GTK_CONTAINER ( widget ) ) ;
tmp = children ;
while ( tmp )
{
set_selectable_recursive ( tmp - > data , setting ) ;
tmp = tmp - > next ;
}
g_list_free ( children ) ;
}
else if ( GTK_IS_LABEL ( widget ) )
{
gtk_label_set_selectable ( GTK_LABEL ( widget ) , setting ) ;
}
}
static void
selectable_toggled ( GtkWidget * toggle ,
GtkWidget * widget )
{
set_selectable_recursive ( widget ,
2010-10-19 16:46:40 +00:00
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( toggle ) ) ) ;
2008-02-27 10:31:24 +00:00
}
static GtkWidget *
create_selectable_control ( GtkWidget * widget )
{
GtkWidget * button ;
button = gtk_toggle_button_new_with_label ( " Selectable " ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) ,
FALSE ) ;
g_signal_connect ( button ,
" toggled " ,
G_CALLBACK ( selectable_toggled ) ,
widget ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( button ) ;
2008-02-27 10:31:24 +00:00
return button ;
}
2009-05-11 05:23:13 +00:00
static void
dialog_response ( GtkWidget * dialog , gint response_id , GtkLabel * label )
{
const gchar * text ;
gtk_widget_destroy ( dialog ) ;
text = " Some <a href= \" http://en.wikipedia.org/wiki/Text \" title= \" plain text \" >text</a> may be marked up \n "
" as hyperlinks, which can be clicked \n "
" or activated via <a href= \" keynav \" >keynav</a>. \n "
" The links remain the same. " ;
gtk_label_set_markup ( label , text ) ;
}
static gboolean
2009-05-11 06:44:12 +00:00
activate_link ( GtkWidget * label , const gchar * uri , gpointer data )
2009-05-11 05:23:13 +00:00
{
if ( g_strcmp0 ( uri , " keynav " ) = = 0 )
{
GtkWidget * dialog ;
dialog = gtk_message_dialog_new_with_markup ( GTK_WINDOW ( gtk_widget_get_toplevel ( label ) ) ,
GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_MESSAGE_INFO ,
GTK_BUTTONS_OK ,
" The term <i>keynav</i> is a shorthand for "
" keyboard navigation and refers to the process of using a program "
" (exclusively) via keyboard input. " ) ;
gtk_window_present ( GTK_WINDOW ( dialog ) ) ;
g_signal_connect ( dialog , " response " , G_CALLBACK ( dialog_response ) , label ) ;
return TRUE ;
}
return FALSE ;
}
2008-02-27 10:31:24 +00:00
void create_labels ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * hbox ;
GtkWidget * vbox ;
GtkWidget * frame ;
GtkWidget * label ;
GtkWidget * button ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Label " ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , vbox ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = create_sensitivity_control ( hbox ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = create_selectable_control ( hbox ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Normal Label " ) ;
label = gtk_label_new ( " This is a Normal label " ) ;
gtk_label_set_ellipsize ( GTK_LABEL ( label ) , PANGO_ELLIPSIZE_START ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Multi-line Label " ) ;
label = gtk_label_new ( " This is a Multi-line label. \n Second line \n Third line " ) ;
gtk_label_set_ellipsize ( GTK_LABEL ( label ) , PANGO_ELLIPSIZE_END ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Left Justified Label " ) ;
label = gtk_label_new ( " This is a Left-Justified \n Multi-line label. \n Third line " ) ;
gtk_label_set_ellipsize ( GTK_LABEL ( label ) , PANGO_ELLIPSIZE_MIDDLE ) ;
gtk_label_set_justify ( GTK_LABEL ( label ) , GTK_JUSTIFY_LEFT ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Right Justified Label " ) ;
gtk_label_set_ellipsize ( GTK_LABEL ( label ) , PANGO_ELLIPSIZE_START ) ;
label = gtk_label_new ( " This is a Right-Justified \n Multi-line label. \n Fourth line, (j/k) " ) ;
gtk_label_set_justify ( GTK_LABEL ( label ) , GTK_JUSTIFY_RIGHT ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Internationalized Label " ) ;
label = gtk_label_new ( NULL ) ;
gtk_label_set_markup ( GTK_LABEL ( label ) ,
" French (Fran \303 \247 ais) Bonjour, Salut \n "
" Korean ( \355 \225 \234 \352 \270 \200 ) \354 \225 \210 \353 \205 \225 \355 \225 \230 \354 \204 \270 \354 \232 \224 , \354 \225 \210 \353 \205 \225 \355 \225 \230 \354 \213 \255 \353 \213 \210 \352 \271 \214 \n "
" Russian ( \320 \240 \321 \203 \321 \201 \321 \201 \320 \272 \320 \270 \320 \271 ) \320 \227 \320 \264 \321 \200 \320 \260 \320 \262 \321 \201 \321 \202 \320 \262 \321 \203 \320 \271 \321 \202 \320 \265 ! \n "
" Chinese (Simplified) <span lang= \" zh-cn \" > \345 \205 \203 \346 \260 \224 \345 \274 \200 \345 \217 \221 </span> \n "
" Chinese (Traditional) <span lang= \" zh-tw \" > \345 \205 \203 \346 \260 \243 \351 \226 \213 \347 \231 \274 </span> \n "
" Japanese <span lang= \" ja \" > \345 \205 \203 \346 \260 \227 \351 \226 \213 \347 \231 \272 </span> " ) ;
gtk_label_set_justify ( GTK_LABEL ( label ) , GTK_JUSTIFY_LEFT ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Bidirection Label " ) ;
label = gtk_label_new ( " \342 \200 \217 Arabic \330 \247 \331 \204 \330 \263 \331 \204 \330 \247 \331 \205 \330 \271 \331 \204 \331 \212 \331 \203 \331 \205 \n "
" \342 \200 \217 Hebrew \327 \251 \327 \234 \327 \225 \327 \235 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
2009-05-11 05:23:13 +00:00
frame = gtk_frame_new ( " Links in a label " ) ;
label = gtk_label_new ( " Some <a href= \" http://en.wikipedia.org/wiki/Text \" title= \" plain text \" >text</a> may be marked up \n "
" as hyperlinks, which can be clicked \n "
" or activated via <a href= \" keynav \" >keynav</a> " ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2009-05-11 05:23:13 +00:00
g_signal_connect ( label , " activate-link " , G_CALLBACK ( activate_link ) , NULL ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Line wrapped label " ) ;
label = gtk_label_new ( " This is an example of a line-wrapped label. It should not be taking " \
" up the entire " /* big space to test spacing */ \
" width allocated to it, but automatically wraps the words to fit. " \
" The time has come, for all good men, to come to the aid of their party. " \
" The sixth sheik's six sheep's sick. \n " \
" It supports multiple paragraphs correctly, and correctly adds " \
" many extra spaces. " ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Filled, wrapped label " ) ;
label = gtk_label_new ( " This is an example of a line-wrapped, filled label. It should be taking " \
" up the entire width allocated to it. Here is a seneance to prove " \
" my point. Here is another sentence. " \
" Here comes the sun, do de do de do. \n " \
" This is a new paragraph. \n " \
" This is another newer, longer, better paragraph. It is coming to an end, " \
" unfortunately. " ) ;
gtk_label_set_justify ( GTK_LABEL ( label ) , GTK_JUSTIFY_FILL ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Underlined label " ) ;
label = gtk_label_new ( " This label is underlined! \n "
" This one is underlined ( \343 \201 \223 \343 \202 \223 \343 \201 \253 \343 \201 \241 \343 \201 \257 ) in quite a funky fashion " ) ;
gtk_label_set_justify ( GTK_LABEL ( label ) , GTK_JUSTIFY_LEFT ) ;
gtk_label_set_pattern ( GTK_LABEL ( label ) , " _________________________ _ _________ _ _____ _ __ __ ___ ____ _____ " ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Markup label " ) ;
label = gtk_label_new ( NULL ) ;
/* There's also a gtk_label_set_markup() without accel if you
* don ' t have an accelerator key
*/
gtk_label_set_markup_with_mnemonic ( GTK_LABEL ( label ) ,
" This <span foreground= \" blue \" background= \" orange \" >label</span> has "
" <b>markup</b> _such as "
" <big><i>Big Italics</i></big> \n "
" <tt>Monospace font</tt> \n "
" <u>Underline!</u> \n "
" foo \n "
" <span foreground= \" green \" background= \" red \" >Ugly colors</span> \n "
" and nothing on this line, \n "
" or this. \n "
" or this either \n "
" or even on this one \n "
" la <big>la <big>la <big>la <big>la</big></big></big></big> \n "
" but this _word is <span foreground= \" purple \" ><big>purple</big></span> \n "
" <span underline= \" double \" >We like <sup>superscript</sup> and <sub>subscript</sub> too</span> " ) ;
2010-09-08 17:35:51 +00:00
g_assert ( gtk_label_get_mnemonic_keyval ( GTK_LABEL ( label ) ) = = GDK_KEY_s ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
}
2016-10-02 15:37:22 +00:00
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
# define DEFAULT_TEXT_RADIUS 200
static void
on_rotated_text_unrealize ( GtkWidget * widget )
{
g_object_set_data ( G_OBJECT ( widget ) , " text-gc " , NULL ) ;
}
2017-11-08 14:27:21 +00:00
static void
on_rotated_text_draw ( GtkDrawingArea * drawing_area ,
cairo_t * cr ,
int width ,
int height ,
gpointer tile_pixbuf )
2008-02-27 10:31:24 +00:00
{
static const gchar * words [ ] = { " The " , " grand " , " old " , " Duke " , " of " , " York " ,
" had " , " 10,000 " , " men " } ;
int n_words ;
int i ;
double radius ;
PangoLayout * layout ;
PangoContext * context ;
PangoFontDescription * desc ;
2014-10-12 02:54:40 +00:00
cairo_set_source_rgb ( cr , 1 , 1 , 1 ) ;
cairo_paint ( cr ) ;
2010-07-21 23:51:59 +00:00
if ( tile_pixbuf )
{
gdk_cairo_set_source_pixbuf ( cr , tile_pixbuf , 0 , 0 ) ;
cairo_pattern_set_extend ( cairo_get_source ( cr ) , CAIRO_EXTEND_REPEAT ) ;
2008-02-27 10:31:24 +00:00
}
2010-07-21 23:51:59 +00:00
else
cairo_set_source_rgb ( cr , 0 , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
2010-09-08 20:34:28 +00:00
radius = MIN ( width , height ) / 2. ;
2008-02-27 10:31:24 +00:00
2010-07-21 23:51:59 +00:00
cairo_translate ( cr ,
2010-09-08 20:34:28 +00:00
radius + ( width - 2 * radius ) / 2 ,
radius + ( height - 2 * radius ) / 2 ) ;
2010-07-21 23:51:59 +00:00
cairo_scale ( cr , radius / DEFAULT_TEXT_RADIUS , radius / DEFAULT_TEXT_RADIUS ) ;
2008-02-27 10:31:24 +00:00
2017-11-08 14:27:21 +00:00
context = gtk_widget_get_pango_context ( GTK_WIDGET ( drawing_area ) ) ;
2008-02-27 10:31:24 +00:00
layout = pango_layout_new ( context ) ;
desc = pango_font_description_from_string ( " Sans Bold 30 " ) ;
pango_layout_set_font_description ( layout , desc ) ;
pango_font_description_free ( desc ) ;
n_words = G_N_ELEMENTS ( words ) ;
for ( i = 0 ; i < n_words ; i + + )
{
int width , height ;
2010-07-21 23:51:59 +00:00
cairo_save ( cr ) ;
cairo_rotate ( cr , 2 * G_PI * i / n_words ) ;
pango_cairo_update_layout ( cr , layout ) ;
2008-02-27 10:31:24 +00:00
pango_layout_set_text ( layout , words [ i ] , - 1 ) ;
pango_layout_get_size ( layout , & width , & height ) ;
2010-07-21 23:51:59 +00:00
cairo_move_to ( cr , - width / 2 / PANGO_SCALE , - DEFAULT_TEXT_RADIUS ) ;
pango_cairo_show_layout ( cr , layout ) ;
2008-02-27 10:31:24 +00:00
2010-07-21 23:51:59 +00:00
cairo_restore ( cr ) ;
}
2008-02-27 10:31:24 +00:00
g_object_unref ( layout ) ;
}
static void
create_rotated_text ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * drawing_area ;
GdkPixbuf * tile_pixbuf ;
window = gtk_dialog_new_with_buttons ( " Rotated Text " ,
GTK_WINDOW ( gtk_widget_get_toplevel ( widget ) ) , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " , GTK_RESPONSE_CLOSE ,
2008-02-27 10:31:24 +00:00
NULL ) ;
gtk_window_set_resizable ( GTK_WINDOW ( window ) , TRUE ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " response " ,
2010-09-18 23:57:32 +00:00
G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) , & window ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
drawing_area = gtk_drawing_area_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , drawing_area ) ;
2008-02-27 10:31:24 +00:00
tile_pixbuf = gdk_pixbuf_new_from_file ( " marble.xpm " , NULL ) ;
2016-10-02 15:37:22 +00:00
2017-11-08 14:27:21 +00:00
gtk_drawing_area_set_draw_func ( GTK_DRAWING_AREA ( drawing_area ) ,
on_rotated_text_draw ,
tile_pixbuf ,
g_object_unref ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( drawing_area , " unrealize " ,
G_CALLBACK ( on_rotated_text_unrealize ) , NULL ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( gtk_bin_get_child ( GTK_BIN ( window ) ) ) ;
2016-10-02 15:37:22 +00:00
2017-11-08 14:27:21 +00:00
gtk_drawing_area_set_content_width ( GTK_DRAWING_AREA ( drawing_area ) , DEFAULT_TEXT_RADIUS * 2 ) ;
gtk_drawing_area_set_content_height ( GTK_DRAWING_AREA ( drawing_area ) , DEFAULT_TEXT_RADIUS * 2 ) ;
2008-02-27 10:31:24 +00:00
}
2016-10-02 15:37:22 +00:00
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* Saved Position
*/
gint upositionx = 0 ;
gint upositiony = 0 ;
2018-01-01 23:18:11 +00:00
static gboolean
configure_event ( GtkWidget * window )
2008-02-27 10:31:24 +00:00
{
GtkLabel * lx ;
GtkLabel * ly ;
gchar buffer [ 64 ] ;
lx = g_object_get_data ( G_OBJECT ( window ) , " x " ) ;
ly = g_object_get_data ( G_OBJECT ( window ) , " y " ) ;
2018-03-20 14:21:12 +00:00
gdk_surface_get_root_origin ( gtk_widget_get_surface ( window ) ,
2010-08-15 22:33:57 +00:00
& upositionx , & upositiony ) ;
2008-02-27 10:31:24 +00:00
sprintf ( buffer , " %d " , upositionx ) ;
gtk_label_set_text ( lx , buffer ) ;
sprintf ( buffer , " %d " , upositiony ) ;
gtk_label_set_text ( ly , buffer ) ;
return FALSE ;
}
static void
uposition_stop_configure ( GtkToggleButton * toggle ,
2010-09-27 06:10:23 +00:00
GObject * window )
2008-02-27 10:31:24 +00:00
{
2010-10-19 16:46:40 +00:00
if ( gtk_toggle_button_get_active ( toggle ) )
2018-01-01 23:18:11 +00:00
g_signal_handlers_block_by_func ( window , G_CALLBACK ( configure_event ) , NULL ) ;
2008-02-27 10:31:24 +00:00
else
2018-01-01 23:18:11 +00:00
g_signal_handlers_unblock_by_func ( window , G_CALLBACK ( configure_event ) , NULL ) ;
2008-02-27 10:31:24 +00:00
}
static void
create_saved_position ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
GtkWidget * hbox ;
GtkWidget * main_vbox ;
GtkWidget * vbox ;
GtkWidget * x_label ;
GtkWidget * y_label ;
GtkWidget * button ;
GtkWidget * label ;
GtkWidget * any ;
2018-01-01 23:18:11 +00:00
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Saved Position " ) ;
g_signal_connect ( window , " event " , G_CALLBACK ( configure_event ) , NULL ) ;
2008-02-27 10:31:24 +00:00
gtk_window_move ( GTK_WINDOW ( window ) , upositionx , upositiony ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2010-10-31 17:07:20 +00:00
main_vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , main_vbox ) ;
2016-10-09 01:22:56 +00:00
button = g_object_new ( GTK_TYPE_TOGGLE_BUTTON ,
" label " , " Stop Events " ,
" active " , FALSE ,
" visible " , TRUE ,
NULL ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( uposition_stop_configure ) , window ) ;
2008-02-27 10:31:24 +00:00
vbox =
2011-04-22 13:38:40 +00:00
g_object_new ( GTK_TYPE_BOX ,
2011-05-02 17:19:09 +00:00
" orientation " , GTK_ORIENTATION_VERTICAL ,
2017-11-08 15:05:33 +00:00
" homogeneous " , FALSE ,
" spacing " , 5 ,
NULL ) ;
gtk_container_add ( GTK_CONTAINER ( main_vbox ) , vbox ) ;
2016-10-09 01:22:56 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " X Origin : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2008-02-27 10:31:24 +00:00
x_label = gtk_label_new ( " " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , x_label ) ;
2008-02-27 10:31:24 +00:00
g_object_set_data ( G_OBJECT ( window ) , " x " , x_label ) ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Y Origin : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2008-02-27 10:31:24 +00:00
y_label = gtk_label_new ( " " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , y_label ) ;
2008-02-27 10:31:24 +00:00
g_object_set_data ( G_OBJECT ( window ) , " y " , y_label ) ;
any =
2011-06-08 01:29:01 +00:00
g_object_new ( gtk_separator_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" GtkWidget::visible " , TRUE ,
NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , any ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
2016-10-02 15:37:22 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
}
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkPixmap
*/
static void
2010-08-06 20:12:24 +00:00
create_pixbuf ( GtkWidget * widget )
2008-02-27 10:31:24 +00:00
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * box3 ;
GtkWidget * button ;
GtkWidget * label ;
GtkWidget * separator ;
2010-08-06 20:12:24 +00:00
GtkWidget * pixbufwid ;
2018-03-20 10:40:08 +00:00
GdkSurface * gdk_surface ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkPixmap " ) ;
gtk_widget_realize ( window ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2018-03-20 14:21:12 +00:00
gdk_surface = gtk_widget_get_surface ( window ) ;
2010-08-15 22:33:57 +00:00
2018-03-20 10:40:08 +00:00
pixbufwid = new_pixbuf ( " test.xpm " , gdk_surface ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 20:12:24 +00:00
label = gtk_label_new ( " Pixbuf \n test " ) ;
2010-10-31 17:07:20 +00:00
box3 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2010-08-06 20:12:24 +00:00
gtk_container_add ( GTK_CONTAINER ( box3 ) , pixbufwid ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( box3 ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( button ) , box3 ) ;
button = gtk_button_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-08-15 22:33:57 +00:00
2018-03-20 10:40:08 +00:00
pixbufwid = new_pixbuf ( " test.xpm " , gdk_surface ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 20:12:24 +00:00
label = gtk_label_new ( " Pixbuf \n test " ) ;
2010-10-31 17:07:20 +00:00
box3 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2010-08-06 20:12:24 +00:00
gtk_container_add ( GTK_CONTAINER ( box3 ) , pixbufwid ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( box3 ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( button ) , box3 ) ;
gtk_widget_set_sensitive ( button , FALSE ) ;
2016-10-02 15:37:22 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
static void
create_tooltips ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * box3 ;
GtkWidget * button ;
GtkWidget * toggle ;
GtkWidget * frame ;
GtkWidget * separator ;
if ( ! window )
{
window =
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
g_object_new ( gtk_window_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" GtkWindow::type " , GTK_WINDOW_TOPLEVEL ,
" GtkWindow::title " , " Tooltips " ,
2010-08-07 15:07:17 +00:00
" GtkWindow::resizable " , FALSE ,
2008-02-27 10:31:24 +00:00
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_toggle_button_new_with_label ( " button1 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2009-12-10 11:28:38 +00:00
gtk_widget_set_tooltip_text ( button , " This is button 1 " ) ;
2008-02-27 10:31:24 +00:00
button = gtk_toggle_button_new_with_label ( " button2 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2009-12-10 11:28:38 +00:00
gtk_widget_set_tooltip_text ( button ,
" This is button 2. This is also a really long tooltip which probably "
" won't fit on a single line and will therefore need to be wrapped. "
" Hopefully the wrapping will work correctly. " ) ;
2008-02-27 10:31:24 +00:00
toggle = gtk_toggle_button_new_with_label ( " Override TipsQuery Label " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , toggle ) ;
2008-02-27 10:31:24 +00:00
2009-12-10 11:28:38 +00:00
gtk_widget_set_tooltip_text ( toggle , " Toggle TipsQuery view. " ) ;
2008-02-27 10:31:24 +00:00
box3 =
2011-04-22 13:38:40 +00:00
g_object_new ( GTK_TYPE_BOX ,
2011-05-02 17:19:09 +00:00
" orientation " , GTK_ORIENTATION_VERTICAL ,
2008-02-27 10:31:24 +00:00
" homogeneous " , FALSE ,
" spacing " , 5 ,
NULL ) ;
button =
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
g_object_new ( gtk_button_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " [?] " ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box3 ) , button ) ;
2017-04-21 20:34:36 +00:00
gtk_box_set_child_packing ( GTK_BOX ( box3 ) , button , GTK_PACK_START ) ;
2010-04-13 16:43:16 +00:00
gtk_widget_set_tooltip_text ( button , " Start the Tooltips Inspector " ) ;
2016-10-02 15:37:22 +00:00
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
frame = g_object_new ( gtk_frame_get_type ( ) ,
2008-02-27 10:31:24 +00:00
" label " , " ToolTips Inspector " ,
" label_xalign " , ( double ) 0.5 ,
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( box2 ) , frame ) ;
2016-10-09 01:22:56 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , box3 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_set_child_packing ( GTK_BOX ( box2 ) , frame , GTK_PACK_START ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
2009-12-10 11:28:38 +00:00
gtk_widget_set_tooltip_text ( button , " Push this button to close window " ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkImage
*/
static void
pack_image ( GtkWidget * box ,
const gchar * text ,
GtkWidget * image )
{
gtk_box_pack_start ( GTK_BOX ( box ) ,
2017-04-21 20:34:36 +00:00
gtk_label_new ( text ) ) ;
2008-02-27 10:31:24 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) ,
2017-04-21 20:34:36 +00:00
image ) ;
2008-02-27 10:31:24 +00:00
}
static void
create_image ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( window = = NULL )
{
GtkWidget * vbox ;
2010-08-06 19:54:16 +00:00
GdkPixbuf * pixbuf ;
2008-02-27 10:31:24 +00:00
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
/* this is bogus for testing drawing when allocation < request,
* don ' t copy into real code
*/
2010-08-07 15:07:17 +00:00
gtk_window_set_resizable ( GTK_WINDOW ( window ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , vbox ) ;
2017-11-15 00:43:13 +00:00
pack_image ( vbox , " Stock Warning Dialog " , gtk_image_new_from_icon_name ( " dialog-warning " ) ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 19:54:16 +00:00
pixbuf = gdk_pixbuf_new_from_xpm_data ( ( const char * * ) openfile ) ;
2008-02-27 10:31:24 +00:00
2010-08-06 19:54:16 +00:00
pack_image ( vbox , " Pixbuf " ,
gtk_image_new_from_pixbuf ( pixbuf ) ) ;
g_object_unref ( pixbuf ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
2013-06-10 12:15:56 +00:00
/*
* ListBox demo
*/
static int
list_sort_cb ( GtkListBoxRow * a , GtkListBoxRow * b , gpointer data )
{
gint aa = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( a ) , " value " ) ) ;
gint bb = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( b ) , " value " ) ) ;
return aa - bb ;
}
static gboolean
2013-06-11 14:53:46 +00:00
list_filter_all_cb ( GtkListBoxRow * row , gpointer data )
{
return FALSE ;
}
static gboolean
list_filter_odd_cb ( GtkListBoxRow * row , gpointer data )
2013-06-10 12:15:56 +00:00
{
gint value = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( row ) , " value " ) ) ;
return value % 2 = = 0 ;
}
static void
list_sort_clicked_cb ( GtkButton * button ,
gpointer data )
{
GtkListBox * list = data ;
gtk_list_box_set_sort_func ( list , list_sort_cb , NULL , NULL ) ;
}
static void
2013-06-11 14:53:46 +00:00
list_filter_odd_clicked_cb ( GtkButton * button ,
gpointer data )
2013-06-10 12:15:56 +00:00
{
GtkListBox * list = data ;
2013-06-11 14:53:46 +00:00
gtk_list_box_set_filter_func ( list , list_filter_odd_cb , NULL , NULL ) ;
}
static void
list_filter_all_clicked_cb ( GtkButton * button ,
gpointer data )
{
GtkListBox * list = data ;
gtk_list_box_set_filter_func ( list , list_filter_all_cb , NULL , NULL ) ;
2013-06-10 12:15:56 +00:00
}
static void
list_unfilter_clicked_cb ( GtkButton * button ,
gpointer data )
{
GtkListBox * list = data ;
gtk_list_box_set_filter_func ( list , NULL , NULL , NULL ) ;
}
2013-06-11 14:53:46 +00:00
static void
add_placeholder_clicked_cb ( GtkButton * button ,
gpointer data )
{
GtkListBox * list = data ;
GtkWidget * label ;
label = gtk_label_new ( " You filtered everything!!! " ) ;
gtk_widget_show ( label ) ;
gtk_list_box_set_placeholder ( GTK_LIST_BOX ( list ) , label ) ;
}
static void
remove_placeholder_clicked_cb ( GtkButton * button ,
gpointer data )
{
GtkListBox * list = data ;
gtk_list_box_set_placeholder ( GTK_LIST_BOX ( list ) , NULL ) ;
}
2013-06-10 12:15:56 +00:00
static void
create_listbox ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
GtkWidget * hbox , * vbox , * scrolled , * scrolled_box , * list , * label , * button ;
2017-10-31 06:41:15 +00:00
GdkDisplay * display = gtk_widget_get_display ( widget ) ;
2013-06-10 12:15:56 +00:00
int i ;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-12-31 17:52:54 +00:00
gtk_window_set_hide_on_close ( GTK_WINDOW ( window ) , TRUE ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) , display ) ;
2013-06-10 12:15:56 +00:00
2017-12-31 17:52:54 +00:00
g_signal_connect ( window , " destroy " , G_CALLBACK ( gtk_widget_destroyed ) , & window ) ;
2013-06-10 12:15:56 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " listbox " ) ;
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( window ) , hbox ) ;
scrolled = gtk_scrolled_window_new ( NULL , NULL ) ;
gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled ) , GTK_POLICY_NEVER , GTK_POLICY_AUTOMATIC ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , scrolled ) ;
scrolled_box = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( scrolled ) , scrolled_box ) ;
label = gtk_label_new ( " This is \n a LABEL \n with rows " ) ;
gtk_container_add ( GTK_CONTAINER ( scrolled_box ) , label ) ;
list = gtk_list_box_new ( ) ;
gtk_list_box_set_adjustment ( GTK_LIST_BOX ( list ) , gtk_scrolled_window_get_vadjustment ( GTK_SCROLLED_WINDOW ( scrolled ) ) ) ;
gtk_container_add ( GTK_CONTAINER ( scrolled_box ) , list ) ;
for ( i = 0 ; i < 1000 ; i + + )
{
gint value = g_random_int_range ( 0 , 10000 ) ;
label = gtk_label_new ( g_strdup_printf ( " Value %u " , value ) ) ;
gtk_widget_show ( label ) ;
gtk_container_add ( GTK_CONTAINER ( list ) , label ) ;
g_object_set_data ( G_OBJECT ( gtk_widget_get_parent ( label ) ) , " value " , GINT_TO_POINTER ( value ) ) ;
}
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , vbox ) ;
button = gtk_button_new_with_label ( " sort " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( list_sort_clicked_cb ) , list ) ;
button = gtk_button_new_with_label ( " filter odd " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
2013-06-11 14:53:46 +00:00
g_signal_connect ( button , " clicked " , G_CALLBACK ( list_filter_odd_clicked_cb ) , list ) ;
button = gtk_button_new_with_label ( " filter all " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( list_filter_all_clicked_cb ) , list ) ;
2013-06-10 12:15:56 +00:00
button = gtk_button_new_with_label ( " unfilter " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( list_unfilter_clicked_cb ) , list ) ;
2013-06-11 14:53:46 +00:00
button = gtk_button_new_with_label ( " add placeholder " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( add_placeholder_clicked_cb ) , list ) ;
button = gtk_button_new_with_label ( " remove placeholder " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , button ) ;
g_signal_connect ( button , " clicked " , G_CALLBACK ( remove_placeholder_clicked_cb ) , list ) ;
2013-06-10 12:15:56 +00:00
}
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2013-06-10 12:15:56 +00:00
else
gtk_widget_destroy ( window ) ;
}
2008-02-27 10:31:24 +00:00
/*
* Menu demo
*/
static GtkWidget *
2017-10-31 06:41:15 +00:00
create_menu ( GdkDisplay * display , gint depth , gint length )
2008-02-27 10:31:24 +00:00
{
GtkWidget * menu ;
GtkWidget * menuitem ;
GtkWidget * image ;
2016-10-03 07:33:32 +00:00
GtkWidget * box ;
GtkWidget * label ;
2008-02-27 10:31:24 +00:00
GSList * group ;
char buf [ 32 ] ;
int i , j ;
if ( depth < 1 )
return NULL ;
menu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( menu ) , display ) ;
2008-02-27 10:31:24 +00:00
group = NULL ;
2017-11-15 00:43:13 +00:00
image = gtk_image_new_from_icon_name ( " document-open " ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( image ) ;
2016-10-03 07:33:32 +00:00
menuitem = gtk_menu_item_new ( ) ;
label = gtk_label_new ( " Image Item " ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , image ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem ) , box ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
2016-10-03 07:33:32 +00:00
2008-02-27 10:31:24 +00:00
for ( i = 0 , j = 1 ; i < length ; i + + , j + + )
{
sprintf ( buf , " item %2d - %d " , depth , j ) ;
menuitem = gtk_radio_menu_item_new_with_label ( group , buf ) ;
group = gtk_radio_menu_item_get_group ( GTK_RADIO_MENU_ITEM ( menuitem ) ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
if ( i = = 3 )
gtk_widget_set_sensitive ( menuitem , FALSE ) ;
if ( i = = 5 )
gtk_check_menu_item_set_inconsistent ( GTK_CHECK_MENU_ITEM ( menuitem ) ,
TRUE ) ;
if ( i < 5 )
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) ,
2017-10-31 06:41:15 +00:00
create_menu ( display , depth - 1 , 5 ) ) ;
2008-02-27 10:31:24 +00:00
}
return menu ;
}
static GtkWidget *
2017-10-31 06:41:15 +00:00
create_table_menu ( GdkDisplay * display , gint cols , gint rows )
2008-02-27 10:31:24 +00:00
{
GtkWidget * menu ;
GtkWidget * menuitem ;
GtkWidget * submenu ;
GtkWidget * image ;
2016-10-03 07:33:32 +00:00
GtkWidget * label ;
GtkWidget * box ;
2008-02-27 10:31:24 +00:00
char buf [ 32 ] ;
int i , j ;
menu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( menu ) , display ) ;
2008-02-27 10:31:24 +00:00
j = 0 ;
menuitem = gtk_menu_item_new_with_label ( " items " ) ;
gtk_menu_attach ( GTK_MENU ( menu ) , menuitem , 0 , cols , j , j + 1 ) ;
submenu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( submenu ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , submenu ) ;
gtk_widget_show ( menuitem ) ;
j + + ;
/* now fill the items submenu */
2017-11-15 00:43:13 +00:00
image = gtk_image_new_from_icon_name ( " help-broswer " ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( image ) ;
2013-06-27 22:48:46 +00:00
G_GNUC_BEGIN_IGNORE_DEPRECATIONS ;
2016-10-03 07:33:32 +00:00
menuitem = gtk_menu_item_new ( ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 12 ) ;
label = gtk_label_new ( " Image " ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , image ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem ) , box ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 0 , 1 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 0 , 1 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 1 , 2 ) ;
gtk_widget_show ( menuitem ) ;
2016-10-03 07:33:32 +00:00
2017-11-15 00:43:13 +00:00
image = gtk_image_new_from_icon_name ( " help-browser " ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( image ) ;
2016-10-03 07:33:32 +00:00
menuitem = gtk_menu_item_new ( ) ;
label = gtk_label_new ( " Image " ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , image ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem ) , box ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 1 , 2 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_radio_menu_item_new_with_label ( NULL , " Radio " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 2 , 3 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 2 , 3 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 3 , 4 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_radio_menu_item_new_with_label ( NULL , " Radio " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 3 , 4 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_check_menu_item_new_with_label ( " Check " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 4 , 5 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 4 , 5 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " x " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 5 , 6 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_check_menu_item_new_with_label ( " Check " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 5 , 6 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " 1. Inserted normally (8) " ) ;
gtk_widget_show ( menuitem ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( submenu ) , menuitem , 8 ) ;
menuitem = gtk_menu_item_new_with_label ( " 2. Inserted normally (2) " ) ;
gtk_widget_show ( menuitem ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( submenu ) , menuitem , 2 ) ;
menuitem = gtk_menu_item_new_with_label ( " 3. Inserted normally (0) " ) ;
gtk_widget_show ( menuitem ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( submenu ) , menuitem , 0 ) ;
menuitem = gtk_menu_item_new_with_label ( " 4. Inserted normally (-1) " ) ;
gtk_widget_show ( menuitem ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( submenu ) , menuitem , - 1 ) ;
/* end of items submenu */
menuitem = gtk_menu_item_new_with_label ( " spanning " ) ;
gtk_menu_attach ( GTK_MENU ( menu ) , menuitem , 0 , cols , j , j + 1 ) ;
submenu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( submenu ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , submenu ) ;
gtk_widget_show ( menuitem ) ;
j + + ;
/* now fill the spanning submenu */
menuitem = gtk_menu_item_new_with_label ( " a " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 2 , 0 , 1 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " b " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 2 , 3 , 0 , 2 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " c " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 1 , 3 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " d " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 2 , 1 , 2 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " e " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 1 , 3 , 2 , 3 ) ;
gtk_widget_show ( menuitem ) ;
/* end of spanning submenu */
menuitem = gtk_menu_item_new_with_label ( " left " ) ;
gtk_menu_attach ( GTK_MENU ( menu ) , menuitem , 0 , 1 , j , j + 1 ) ;
submenu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( submenu ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , submenu ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " Empty " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 0 , 1 ) ;
submenu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( submenu ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , submenu ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " right " ) ;
gtk_menu_attach ( GTK_MENU ( menu ) , menuitem , 1 , 2 , j , j + 1 ) ;
submenu = gtk_menu_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_set_display ( GTK_MENU ( submenu ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , submenu ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " Empty " ) ;
gtk_menu_attach ( GTK_MENU ( submenu ) , menuitem , 0 , 1 , 0 , 1 ) ;
gtk_widget_show ( menuitem ) ;
j + + ;
for ( ; j < rows ; j + + )
for ( i = 0 ; i < cols ; i + + )
{
sprintf ( buf , " (%d %d) " , i , j ) ;
menuitem = gtk_menu_item_new_with_label ( buf ) ;
gtk_menu_attach ( GTK_MENU ( menu ) , menuitem , i , i + 1 , j , j + 1 ) ;
gtk_widget_show ( menuitem ) ;
}
menuitem = gtk_menu_item_new_with_label ( " 1. Inserted normally (8) " ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( menu ) , menuitem , 8 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " 2. Inserted normally (2) " ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( menu ) , menuitem , 2 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " 3. Inserted normally (0) " ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( menu ) , menuitem , 0 ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " 4. Inserted normally (-1) " ) ;
gtk_menu_shell_insert ( GTK_MENU_SHELL ( menu ) , menuitem , - 1 ) ;
gtk_widget_show ( menuitem ) ;
return menu ;
}
static void
create_menus ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * optionmenu ;
GtkWidget * separator ;
2016-10-03 07:33:32 +00:00
GtkWidget * box ;
GtkWidget * label ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
GtkWidget * menubar ;
GtkWidget * menu ;
GtkWidget * menuitem ;
GtkAccelGroup * accel_group ;
GtkWidget * image ;
2017-10-31 06:41:15 +00:00
GdkDisplay * display = gtk_widget_get_display ( widget ) ;
2008-02-27 10:31:24 +00:00
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-12-31 17:52:54 +00:00
gtk_window_set_hide_on_close ( GTK_WINDOW ( window ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) , display ) ;
2008-02-27 10:31:24 +00:00
2017-12-31 17:52:54 +00:00
g_signal_connect ( window , " destroy " , G_CALLBACK ( gtk_widget_destroyed ) , & window ) ;
2008-02-27 10:31:24 +00:00
accel_group = gtk_accel_group_new ( ) ;
gtk_window_add_accel_group ( GTK_WINDOW ( window ) , accel_group ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " menus " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
gtk_widget_show ( box1 ) ;
menubar = gtk_menu_bar_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , menubar ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( menubar ) ;
2017-10-31 06:41:15 +00:00
menu = create_menu ( display , 2 , 50 ) ;
2008-02-27 10:31:24 +00:00
menuitem = gtk_menu_item_new_with_label ( " test \n line2 " ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , menu ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menubar ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
2017-10-31 06:41:15 +00:00
menu = create_table_menu ( display , 2 , 50 ) ;
2008-02-27 10:31:24 +00:00
menuitem = gtk_menu_item_new_with_label ( " table " ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , menu ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menubar ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
menuitem = gtk_menu_item_new_with_label ( " foo " ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , create_menu ( display , 3 , 5 ) ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_shell_append ( GTK_MENU_SHELL ( menubar ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
2017-11-15 00:43:13 +00:00
image = gtk_image_new_from_icon_name ( " help-browser " ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( image ) ;
2016-10-03 07:33:32 +00:00
menuitem = gtk_menu_item_new ( ) ;
label = gtk_label_new ( " Help " ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , image ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem ) , box ) ;
2017-10-31 06:41:15 +00:00
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , create_menu ( display , 4 , 5 ) ) ;
2011-05-02 14:47:06 +00:00
gtk_widget_set_hexpand ( menuitem , TRUE ) ;
gtk_widget_set_halign ( menuitem , GTK_ALIGN_END ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_shell_append ( GTK_MENU_SHELL ( menubar ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
menubar = gtk_menu_bar_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , menubar ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( menubar ) ;
2016-10-02 15:37:22 +00:00
2017-10-31 06:41:15 +00:00
menu = create_menu ( display , 2 , 10 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
menuitem = gtk_menu_item_new_with_label ( " Second menu bar " ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem ) , menu ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menubar ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
2016-10-02 15:37:22 +00:00
2017-10-31 06:41:15 +00:00
menu = create_menu ( display , 1 , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_menu_set_accel_group ( GTK_MENU ( menu ) , accel_group ) ;
menuitem = gtk_check_menu_item_new_with_label ( " Accelerate Me " ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
gtk_widget_add_accelerator ( menuitem ,
" activate " ,
accel_group ,
2010-09-08 17:35:51 +00:00
GDK_KEY_F1 ,
2008-02-27 10:31:24 +00:00
0 ,
GTK_ACCEL_VISIBLE ) ;
menuitem = gtk_check_menu_item_new_with_label ( " Accelerator Locked " ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
gtk_widget_add_accelerator ( menuitem ,
" activate " ,
accel_group ,
2010-09-08 17:35:51 +00:00
GDK_KEY_F2 ,
2008-02-27 10:31:24 +00:00
0 ,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED ) ;
menuitem = gtk_check_menu_item_new_with_label ( " Accelerators Frozen " ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menuitem ) ;
gtk_widget_show ( menuitem ) ;
gtk_widget_add_accelerator ( menuitem ,
" activate " ,
accel_group ,
2010-09-08 17:35:51 +00:00
GDK_KEY_F2 ,
2008-02-27 10:31:24 +00:00
0 ,
GTK_ACCEL_VISIBLE ) ;
gtk_widget_add_accelerator ( menuitem ,
" activate " ,
accel_group ,
2010-09-08 17:35:51 +00:00
GDK_KEY_F3 ,
2008-02-27 10:31:24 +00:00
0 ,
GTK_ACCEL_VISIBLE ) ;
2010-10-02 16:19:46 +00:00
optionmenu = gtk_combo_box_text_new ( ) ;
2010-03-26 16:55:07 +00:00
gtk_combo_box_set_active ( GTK_COMBO_BOX ( optionmenu ) , 3 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , optionmenu ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( optionmenu ) ;
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( separator ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
gtk_widget_show ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
static GtkWidget *
accel_button_new ( GtkAccelGroup * accel_group ,
const gchar * text ,
const gchar * accel )
{
guint keyval ;
GdkModifierType modifiers ;
GtkWidget * button ;
GtkWidget * label ;
gtk_accelerator_parse ( accel , & keyval , & modifiers ) ;
g_assert ( keyval ) ;
button = gtk_button_new ( ) ;
gtk_widget_add_accelerator ( button , " activate " , accel_group ,
keyval , modifiers , GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED ) ;
label = gtk_accel_label_new ( text ) ;
gtk_accel_label_set_accel_widget ( GTK_ACCEL_LABEL ( label ) , button ) ;
gtk_widget_show ( label ) ;
gtk_container_add ( GTK_CONTAINER ( button ) , label ) ;
return button ;
}
static void
create_key_lookup ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
2008-07-18 18:27:30 +00:00
gpointer window_ptr ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
GtkAccelGroup * accel_group = gtk_accel_group_new ( ) ;
GtkWidget * button ;
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
window = gtk_dialog_new_with_buttons ( " Key Lookup " , NULL , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " , GTK_RESPONSE_CLOSE ,
2008-02-27 10:31:24 +00:00
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
/* We have to expand it so the accel labels will draw their labels
*/
gtk_window_set_default_size ( GTK_WINDOW ( window ) , 300 , - 1 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_add_accel_group ( GTK_WINDOW ( window ) , accel_group ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 1 (_a) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 2 (_A) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 3 (_ \321 \204 ) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 4 (_ \320 \244 ) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 6 (_b) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 7 " , " <Alt><Shift>b " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 8 " , " <Alt>d " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 9 " , " <Alt>Cyrillic_ve " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 10 (_1) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " Button 11 (_!) " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 12 " , " <Super>a " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 13 " , " <Hyper>a " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 14 " , " <Meta>a " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-02-27 10:31:24 +00:00
button = accel_button_new ( accel_group , " Button 15 " , " <Shift><Mod4>b " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , button ) ;
2008-07-18 18:27:30 +00:00
window_ptr = & window ;
g_object_add_weak_pointer ( G_OBJECT ( window ) , window_ptr ) ;
2010-09-18 23:57:32 +00:00
g_signal_connect ( window , " response " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2008-02-27 10:31:24 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
}
else
gtk_widget_destroy ( window ) ;
}
/*
create_modal_window
*/
static gboolean
cmw_destroy_cb ( GtkWidget * widget )
{
/* This is needed to get out of gtk_main */
gtk_main_quit ( ) ;
return FALSE ;
}
static void
cmw_color ( GtkWidget * widget , GtkWidget * parent )
{
GtkWidget * csd ;
2012-02-09 21:23:30 +00:00
csd = gtk_color_chooser_dialog_new ( " This is a modal color selection dialog " , GTK_WINDOW ( parent ) ) ;
2008-02-27 10:31:24 +00:00
/* Set as modal */
gtk_window_set_modal ( GTK_WINDOW ( csd ) , TRUE ) ;
g_signal_connect ( csd , " destroy " ,
G_CALLBACK ( cmw_destroy_cb ) , NULL ) ;
2012-02-09 21:23:30 +00:00
g_signal_connect ( csd , " response " ,
G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2008-02-27 10:31:24 +00:00
/* wait until destroy calls gtk_main_quit */
gtk_widget_show ( csd ) ;
gtk_main ( ) ;
}
static void
cmw_file ( GtkWidget * widget , GtkWidget * parent )
{
GtkWidget * fs ;
2010-04-06 15:22:18 +00:00
fs = gtk_file_chooser_dialog_new ( " This is a modal file selection dialog " ,
2013-06-24 21:31:22 +00:00
GTK_WINDOW ( parent ) ,
GTK_FILE_CHOOSER_ACTION_OPEN ,
" _Open " , GTK_RESPONSE_ACCEPT ,
" _Cancel " , GTK_RESPONSE_CANCEL ,
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( fs ) , gtk_widget_get_display ( parent ) ) ;
2010-04-06 15:22:18 +00:00
gtk_window_set_modal ( GTK_WINDOW ( fs ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( fs , " destroy " ,
G_CALLBACK ( cmw_destroy_cb ) , NULL ) ;
2010-04-06 15:22:18 +00:00
g_signal_connect_swapped ( fs , " response " ,
G_CALLBACK ( gtk_widget_destroy ) , fs ) ;
2008-02-27 10:31:24 +00:00
/* wait until destroy calls gtk_main_quit */
gtk_widget_show ( fs ) ;
gtk_main ( ) ;
}
static void
create_modal_window ( GtkWidget * widget )
{
GtkWidget * window = NULL ;
GtkWidget * box1 , * box2 ;
GtkWidget * frame1 ;
GtkWidget * btnColor , * btnFile , * btnClose ;
/* Create modal window (Here you can use any window descendent )*/
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " This window is modal " ) ;
/* Set window as modal */
gtk_window_set_modal ( GTK_WINDOW ( window ) , TRUE ) ;
/* Create widgets */
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
frame1 = gtk_frame_new ( " Standard dialogs in modal form " ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
gtk_box_set_homogeneous ( GTK_BOX ( box2 ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
btnColor = gtk_button_new_with_label ( " Color " ) ;
btnFile = gtk_button_new_with_label ( " File Selection " ) ;
btnClose = gtk_button_new_with_label ( " Close " ) ;
/* Pack widgets */
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , frame1 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame1 ) , box2 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , btnColor ) ;
gtk_box_pack_start ( GTK_BOX ( box2 ) , btnFile ) ;
gtk_box_pack_start ( GTK_BOX ( box1 ) , gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ) ;
gtk_box_pack_start ( GTK_BOX ( box1 ) , btnClose ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
/* connect signals */
g_signal_connect_swapped ( btnClose , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) , window ) ;
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( cmw_destroy_cb ) , NULL ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( btnColor , " clicked " ,
G_CALLBACK ( cmw_color ) , window ) ;
g_signal_connect ( btnFile , " clicked " ,
G_CALLBACK ( cmw_file ) , window ) ;
/* Show widgets */
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
/* wait until dialog get destroyed */
gtk_main ( ) ;
}
/*
* GtkMessageDialog
*/
static void
2017-10-31 06:41:15 +00:00
make_message_dialog ( GdkDisplay * display ,
GtkWidget * * dialog ,
2008-02-27 10:31:24 +00:00
GtkMessageType type ,
GtkButtonsType buttons ,
guint default_response )
{
if ( * dialog )
{
gtk_widget_destroy ( * dialog ) ;
return ;
}
* dialog = gtk_message_dialog_new ( NULL , 0 , type , buttons ,
" This is a message dialog; it can wrap long lines. This is a long line. La la la. Look this line is wrapped. Blah blah blah blah blah blah. (Note: testgtk has a nonstandard gtkrc that changes some of the message dialog icons.) " ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( * dialog ) , display ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect_swapped ( * dialog ,
" response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
* dialog ) ;
g_signal_connect ( * dialog ,
" destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
dialog ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( * dialog ) , default_response ) ;
gtk_widget_show ( * dialog ) ;
}
static void
create_message_dialog ( GtkWidget * widget )
{
static GtkWidget * info = NULL ;
static GtkWidget * warning = NULL ;
static GtkWidget * error = NULL ;
static GtkWidget * question = NULL ;
2017-10-31 06:41:15 +00:00
GdkDisplay * display = gtk_widget_get_display ( widget ) ;
2008-02-27 10:31:24 +00:00
2017-10-31 06:41:15 +00:00
make_message_dialog ( display , & info , GTK_MESSAGE_INFO , GTK_BUTTONS_OK , GTK_RESPONSE_OK ) ;
make_message_dialog ( display , & warning , GTK_MESSAGE_WARNING , GTK_BUTTONS_CLOSE , GTK_RESPONSE_CLOSE ) ;
make_message_dialog ( display , & error , GTK_MESSAGE_ERROR , GTK_BUTTONS_OK_CANCEL , GTK_RESPONSE_OK ) ;
make_message_dialog ( display , & question , GTK_MESSAGE_QUESTION , GTK_BUTTONS_YES_NO , GTK_RESPONSE_NO ) ;
2008-02-27 10:31:24 +00:00
}
/*
* GtkScrolledWindow
*/
static GtkWidget * sw_parent = NULL ;
static GtkWidget * sw_float_parent ;
2010-10-08 00:37:23 +00:00
static gulong sw_destroyed_handler = 0 ;
2008-02-27 10:31:24 +00:00
static gboolean
2018-01-01 20:27:16 +00:00
scrolled_windows_delete_cb ( GtkWidget * widget ,
GtkWidget * scrollwin )
2008-02-27 10:31:24 +00:00
{
2016-10-12 17:46:23 +00:00
g_object_ref ( scrollwin ) ;
gtk_container_remove ( GTK_CONTAINER ( gtk_widget_get_parent ( scrollwin ) ) , scrollwin ) ;
gtk_container_add ( GTK_CONTAINER ( sw_parent ) , scrollwin ) ;
g_object_unref ( scrollwin ) ;
2008-02-27 10:31:24 +00:00
g_signal_handler_disconnect ( sw_parent , sw_destroyed_handler ) ;
sw_float_parent = NULL ;
sw_parent = NULL ;
sw_destroyed_handler = 0 ;
return FALSE ;
}
static void
scrolled_windows_destroy_cb ( GtkWidget * widget , GtkWidget * scrollwin )
{
gtk_widget_destroy ( sw_float_parent ) ;
sw_float_parent = NULL ;
sw_parent = NULL ;
sw_destroyed_handler = 0 ;
}
static void
2014-04-10 14:42:59 +00:00
scrolled_windows_remove ( GtkWidget * dialog , gint response , GtkWidget * scrollwin )
2008-02-27 10:31:24 +00:00
{
2014-04-10 14:42:59 +00:00
if ( response ! = GTK_RESPONSE_APPLY )
{
gtk_widget_destroy ( dialog ) ;
return ;
}
2008-02-27 10:31:24 +00:00
if ( sw_parent )
{
2016-10-12 17:46:23 +00:00
g_object_ref ( scrollwin ) ;
gtk_container_remove ( GTK_CONTAINER ( gtk_widget_get_parent ( scrollwin ) ) , scrollwin ) ;
gtk_container_add ( GTK_CONTAINER ( sw_parent ) , scrollwin ) ;
g_object_unref ( scrollwin ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( sw_float_parent ) ;
g_signal_handler_disconnect ( sw_parent , sw_destroyed_handler ) ;
sw_float_parent = NULL ;
sw_parent = NULL ;
sw_destroyed_handler = 0 ;
}
else
{
2010-08-15 22:33:57 +00:00
sw_parent = gtk_widget_get_parent ( scrollwin ) ;
2008-02-27 10:31:24 +00:00
sw_float_parent = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( sw_float_parent ) ,
gtk_widget_get_display ( dialog ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_default_size ( GTK_WINDOW ( sw_float_parent ) , 200 , 200 ) ;
2016-10-12 17:46:23 +00:00
g_object_ref ( scrollwin ) ;
gtk_container_remove ( GTK_CONTAINER ( gtk_widget_get_parent ( scrollwin ) ) , scrollwin ) ;
gtk_container_add ( GTK_CONTAINER ( sw_float_parent ) , scrollwin ) ;
g_object_unref ( scrollwin ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( sw_float_parent ) ;
sw_destroyed_handler =
g_signal_connect ( sw_parent , " destroy " ,
G_CALLBACK ( scrolled_windows_destroy_cb ) , scrollwin ) ;
2018-01-01 20:27:16 +00:00
g_signal_connect ( sw_float_parent , " close-request " ,
2008-02-27 10:31:24 +00:00
G_CALLBACK ( scrolled_windows_delete_cb ) , scrollwin ) ;
}
}
static void
create_scrolled_windows ( GtkWidget * widget )
{
static GtkWidget * window ;
2014-04-10 14:42:59 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * scrolled_window ;
GtkWidget * button ;
2014-04-10 14:42:59 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
char buffer [ 32 ] ;
int i , j ;
if ( ! window )
{
window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " dialog " ) ;
scrolled_window = gtk_scrolled_window_new ( NULL , NULL ) ;
2018-01-01 15:24:12 +00:00
gtk_widget_set_hexpand ( scrolled_window , TRUE ) ;
gtk_widget_set_vexpand ( scrolled_window , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_window ) ,
GTK_POLICY_AUTOMATIC ,
GTK_POLICY_AUTOMATIC ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , scrolled_window ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scrolled_window ) ;
2011-09-28 01:33:47 +00:00
grid = gtk_grid_new ( ) ;
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 10 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 10 ) ;
2013-02-01 16:22:13 +00:00
gtk_container_add ( GTK_CONTAINER ( scrolled_window ) , grid ) ;
2011-09-28 01:33:47 +00:00
gtk_container_set_focus_hadjustment ( GTK_CONTAINER ( grid ) ,
2008-02-27 10:31:24 +00:00
gtk_scrolled_window_get_hadjustment ( GTK_SCROLLED_WINDOW ( scrolled_window ) ) ) ;
2011-09-28 01:33:47 +00:00
gtk_container_set_focus_vadjustment ( GTK_CONTAINER ( grid ) ,
2008-02-27 10:31:24 +00:00
gtk_scrolled_window_get_vadjustment ( GTK_SCROLLED_WINDOW ( scrolled_window ) ) ) ;
2011-09-28 01:33:47 +00:00
gtk_widget_show ( grid ) ;
2008-02-27 10:31:24 +00:00
for ( i = 0 ; i < 20 ; i + + )
for ( j = 0 ; j < 20 ; j + + )
{
sprintf ( buffer , " button (%d,%d) \n " , i , j ) ;
button = gtk_toggle_button_new_with_label ( buffer ) ;
2011-09-28 01:33:47 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , button , i , j , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( button ) ;
}
2014-04-10 14:42:59 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( window ) ,
" Close " ,
GTK_RESPONSE_CLOSE ) ;
2008-02-27 10:31:24 +00:00
2014-04-10 14:42:59 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( window ) ,
" Reparent Out " ,
GTK_RESPONSE_APPLY ) ;
2008-02-27 10:31:24 +00:00
2014-04-10 14:42:59 +00:00
g_signal_connect ( window , " response " ,
2008-02-27 10:31:24 +00:00
G_CALLBACK ( scrolled_windows_remove ) ,
scrolled_window ) ;
gtk_window_set_default_size ( GTK_WINDOW ( window ) , 300 , 300 ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkEntry
*/
static void
entry_toggle_frame ( GtkWidget * checkbutton ,
GtkWidget * entry )
{
gtk_entry_set_has_frame ( GTK_ENTRY ( entry ) ,
2010-10-19 16:46:40 +00:00
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ;
2008-02-27 10:31:24 +00:00
}
static void
entry_toggle_sensitive ( GtkWidget * checkbutton ,
GtkWidget * entry )
{
2010-10-19 16:46:40 +00:00
gtk_widget_set_sensitive ( entry ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ;
2008-02-27 10:31:24 +00:00
}
2008-12-05 11:31:30 +00:00
static gboolean
entry_progress_timeout ( gpointer data )
{
if ( GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( data ) , " progress-pulse " ) ) )
{
gtk_entry_progress_pulse ( GTK_ENTRY ( data ) ) ;
}
else
{
gdouble fraction ;
fraction = gtk_entry_get_progress_fraction ( GTK_ENTRY ( data ) ) ;
fraction + = 0.05 ;
if ( fraction > 1.0001 )
fraction = 0.0 ;
gtk_entry_set_progress_fraction ( GTK_ENTRY ( data ) , fraction ) ;
}
2012-01-31 00:12:27 +00:00
return G_SOURCE_CONTINUE ;
2008-12-05 11:31:30 +00:00
}
static void
entry_remove_timeout ( gpointer data )
{
g_source_remove ( GPOINTER_TO_UINT ( data ) ) ;
}
static void
entry_toggle_progress ( GtkWidget * checkbutton ,
GtkWidget * entry )
{
2010-10-19 16:46:40 +00:00
if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) )
2008-12-05 11:31:30 +00:00
{
2018-02-02 14:51:47 +00:00
guint timeout = g_timeout_add ( 100 , entry_progress_timeout , entry ) ;
2008-12-05 11:31:30 +00:00
g_object_set_data_full ( G_OBJECT ( entry ) , " timeout-id " ,
GUINT_TO_POINTER ( timeout ) ,
entry_remove_timeout ) ;
}
else
{
g_object_set_data ( G_OBJECT ( entry ) , " timeout-id " ,
GUINT_TO_POINTER ( 0 ) ) ;
gtk_entry_set_progress_fraction ( GTK_ENTRY ( entry ) , 0.0 ) ;
}
}
static void
entry_toggle_pulse ( GtkWidget * checkbutton ,
GtkWidget * entry )
{
g_object_set_data ( G_OBJECT ( entry ) , " progress-pulse " ,
2010-10-19 16:46:40 +00:00
GUINT_TO_POINTER ( ( guint ) gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ) ;
2008-12-05 11:31:30 +00:00
}
2008-02-27 10:31:24 +00:00
static void
create_entry ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * hbox ;
GtkWidget * has_frame_check ;
GtkWidget * sensitive_check ;
2008-12-05 11:31:30 +00:00
GtkWidget * progress_check ;
2010-04-06 14:36:05 +00:00
GtkWidget * entry ;
2010-10-18 07:10:27 +00:00
GtkComboBoxText * cb ;
2010-04-06 14:36:05 +00:00
GtkWidget * cb_entry ;
2008-02-27 10:31:24 +00:00
GtkWidget * button ;
GtkWidget * separator ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " entry " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
entry = gtk_entry_new ( ) ;
gtk_entry_set_text ( GTK_ENTRY ( entry ) , " hello world \330 \247 \331 \204 \330 \263 \331 \204 \330 \247 \331 \205 \330 \271 \331 \204 \331 \212 \331 \203 \331 \205 " ) ;
gtk_editable_select_region ( GTK_EDITABLE ( entry ) , 0 , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , entry ) ;
2008-02-27 10:31:24 +00:00
2010-10-18 07:10:27 +00:00
cb = GTK_COMBO_BOX_TEXT ( gtk_combo_box_text_new_with_entry ( ) ) ;
gtk_combo_box_text_append_text ( cb , " item0 " ) ;
gtk_combo_box_text_append_text ( cb , " item0 " ) ;
gtk_combo_box_text_append_text ( cb , " item1 item1 " ) ;
gtk_combo_box_text_append_text ( cb , " item2 item2 item2 " ) ;
gtk_combo_box_text_append_text ( cb , " item3 item3 item3 item3 " ) ;
gtk_combo_box_text_append_text ( cb , " item4 item4 item4 item4 item4 " ) ;
gtk_combo_box_text_append_text ( cb , " item5 item5 item5 item5 item5 item5 " ) ;
gtk_combo_box_text_append_text ( cb , " item6 item6 item6 item6 item6 " ) ;
gtk_combo_box_text_append_text ( cb , " item7 item7 item7 item7 " ) ;
gtk_combo_box_text_append_text ( cb , " item8 item8 item8 " ) ;
gtk_combo_box_text_append_text ( cb , " item9 item9 " ) ;
2010-04-06 14:36:05 +00:00
cb_entry = gtk_bin_get_child ( GTK_BIN ( cb ) ) ;
gtk_entry_set_text ( GTK_ENTRY ( cb_entry ) , " hello world \n \n \n foo " ) ;
gtk_editable_select_region ( GTK_EDITABLE ( cb_entry ) , 0 , - 1 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , GTK_WIDGET ( cb ) ) ;
2008-02-27 10:31:24 +00:00
sensitive_check = gtk_check_button_new_with_label ( " Sensitive " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , sensitive_check ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( sensitive_check , " toggled " ,
G_CALLBACK ( entry_toggle_sensitive ) , entry ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( sensitive_check ) , TRUE ) ;
has_frame_check = gtk_check_button_new_with_label ( " Has Frame " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , has_frame_check ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( has_frame_check , " toggled " ,
G_CALLBACK ( entry_toggle_frame ) , entry ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( has_frame_check ) , TRUE ) ;
2008-12-05 11:31:30 +00:00
progress_check = gtk_check_button_new_with_label ( " Show Progress " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , progress_check ) ;
2008-12-05 11:31:30 +00:00
g_signal_connect ( progress_check , " toggled " ,
G_CALLBACK ( entry_toggle_progress ) , entry ) ;
progress_check = gtk_check_button_new_with_label ( " Pulse Progress " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , progress_check ) ;
2008-12-05 11:31:30 +00:00
g_signal_connect ( progress_check , " toggled " ,
G_CALLBACK ( entry_toggle_pulse ) , entry ) ;
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
static void
create_expander ( GtkWidget * widget )
{
GtkWidget * box1 ;
GtkWidget * expander ;
GtkWidget * hidden ;
static GtkWidget * window = NULL ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " expander " ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
expander = gtk_expander_new ( " The Hidden " ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , expander ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
hidden = gtk_label_new ( " Revealed! " ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( expander ) , hidden ) ;
}
2016-10-02 15:37:22 +00:00
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkSizeGroup
*/
# define SIZE_GROUP_INITIAL_SIZE 50
static void
size_group_hsize_changed ( GtkSpinButton * spin_button ,
GtkWidget * button )
{
2010-05-24 20:31:36 +00:00
gtk_widget_set_size_request ( gtk_bin_get_child ( GTK_BIN ( button ) ) ,
2008-02-27 10:31:24 +00:00
gtk_spin_button_get_value_as_int ( spin_button ) ,
- 1 ) ;
}
static void
size_group_vsize_changed ( GtkSpinButton * spin_button ,
GtkWidget * button )
{
2010-05-24 20:31:36 +00:00
gtk_widget_set_size_request ( gtk_bin_get_child ( GTK_BIN ( button ) ) ,
2008-02-27 10:31:24 +00:00
- 1 ,
gtk_spin_button_get_value_as_int ( spin_button ) ) ;
}
static GtkWidget *
2017-10-31 06:41:15 +00:00
create_size_group_window ( GdkDisplay * display ,
2008-02-27 10:31:24 +00:00
GtkSizeGroup * master_size_group )
{
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * window ;
2011-09-28 22:35:35 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * main_button ;
GtkWidget * button ;
GtkWidget * spin_button ;
GtkWidget * hbox ;
GtkSizeGroup * hgroup1 ;
GtkSizeGroup * hgroup2 ;
GtkSizeGroup * vgroup1 ;
GtkSizeGroup * vgroup2 ;
window = gtk_dialog_new_with_buttons ( " GtkSizeGroup " ,
NULL , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " ,
2008-02-27 10:31:24 +00:00
GTK_RESPONSE_NONE ,
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) , display ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_resizable ( GTK_WINDOW ( window ) , TRUE ) ;
g_signal_connect ( window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2011-09-28 22:35:35 +00:00
grid = gtk_grid_new ( ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , grid ) ;
2008-02-27 10:31:24 +00:00
2011-09-28 22:35:35 +00:00
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 5 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 5 ) ;
gtk_widget_set_size_request ( grid , 250 , 250 ) ;
2008-02-27 10:31:24 +00:00
hgroup1 = gtk_size_group_new ( GTK_SIZE_GROUP_HORIZONTAL ) ;
hgroup2 = gtk_size_group_new ( GTK_SIZE_GROUP_HORIZONTAL ) ;
vgroup1 = gtk_size_group_new ( GTK_SIZE_GROUP_VERTICAL ) ;
vgroup2 = gtk_size_group_new ( GTK_SIZE_GROUP_VERTICAL ) ;
main_button = gtk_button_new_with_label ( " X " ) ;
2011-09-28 22:35:35 +00:00
gtk_widget_set_hexpand ( main_button , TRUE ) ;
gtk_widget_set_vexpand ( main_button , TRUE ) ;
gtk_widget_set_halign ( main_button , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( main_button , GTK_ALIGN_CENTER ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , main_button , 0 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_size_group_add_widget ( master_size_group , main_button ) ;
gtk_size_group_add_widget ( hgroup1 , main_button ) ;
gtk_size_group_add_widget ( vgroup1 , main_button ) ;
2010-05-24 20:31:36 +00:00
gtk_widget_set_size_request ( gtk_bin_get_child ( GTK_BIN ( main_button ) ) ,
2008-02-27 10:31:24 +00:00
SIZE_GROUP_INITIAL_SIZE ,
SIZE_GROUP_INITIAL_SIZE ) ;
button = gtk_button_new ( ) ;
2011-09-28 22:35:35 +00:00
gtk_widget_set_hexpand ( button , TRUE ) ;
gtk_widget_set_vexpand ( button , TRUE ) ;
gtk_widget_set_halign ( button , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( button , GTK_ALIGN_CENTER ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , button , 1 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_size_group_add_widget ( vgroup1 , button ) ;
gtk_size_group_add_widget ( vgroup2 , button ) ;
button = gtk_button_new ( ) ;
2011-09-28 22:35:35 +00:00
gtk_widget_set_hexpand ( button , TRUE ) ;
gtk_widget_set_vexpand ( button , TRUE ) ;
gtk_widget_set_halign ( button , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( button , GTK_ALIGN_CENTER ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , button , 0 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_size_group_add_widget ( hgroup1 , button ) ;
gtk_size_group_add_widget ( hgroup2 , button ) ;
button = gtk_button_new ( ) ;
2011-09-28 22:35:35 +00:00
gtk_widget_set_hexpand ( button , TRUE ) ;
gtk_widget_set_vexpand ( button , TRUE ) ;
gtk_widget_set_halign ( button , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( button , GTK_ALIGN_CENTER ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , button , 1 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_size_group_add_widget ( hgroup2 , button ) ;
gtk_size_group_add_widget ( vgroup2 , button ) ;
g_object_unref ( hgroup1 ) ;
g_object_unref ( hgroup2 ) ;
g_object_unref ( vgroup1 ) ;
g_object_unref ( vgroup2 ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
spin_button = gtk_spin_button_new_with_range ( 1 , 100 , 1 ) ;
gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spin_button ) , SIZE_GROUP_INITIAL_SIZE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , spin_button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( spin_button , " value_changed " ,
G_CALLBACK ( size_group_hsize_changed ) , main_button ) ;
spin_button = gtk_spin_button_new_with_range ( 1 , 100 , 1 ) ;
gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spin_button ) , SIZE_GROUP_INITIAL_SIZE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , spin_button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( spin_button , " value_changed " ,
G_CALLBACK ( size_group_vsize_changed ) , main_button ) ;
return window ;
}
static void
create_size_groups ( GtkWidget * widget )
{
static GtkWidget * window1 = NULL ;
static GtkWidget * window2 = NULL ;
static GtkSizeGroup * master_size_group ;
if ( ! master_size_group )
master_size_group = gtk_size_group_new ( GTK_SIZE_GROUP_BOTH ) ;
if ( ! window1 )
{
2017-10-31 06:41:15 +00:00
window1 = create_size_group_window ( gtk_widget_get_display ( widget ) ,
2008-02-27 10:31:24 +00:00
master_size_group ) ;
g_signal_connect ( window1 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window1 ) ;
}
if ( ! window2 )
{
2017-10-31 06:41:15 +00:00
window2 = create_size_group_window ( gtk_widget_get_display ( widget ) ,
2008-02-27 10:31:24 +00:00
master_size_group ) ;
g_signal_connect ( window2 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window2 ) ;
}
2010-03-01 06:47:38 +00:00
if ( gtk_widget_get_visible ( window1 ) & & gtk_widget_get_visible ( window2 ) )
2008-02-27 10:31:24 +00:00
{
gtk_widget_destroy ( window1 ) ;
gtk_widget_destroy ( window2 ) ;
}
else
{
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window1 ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window1 ) ;
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window2 ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window2 ) ;
2008-02-27 10:31:24 +00:00
}
}
/*
* GtkSpinButton
*/
static GtkWidget * spinner1 ;
static void
toggle_snap ( GtkWidget * widget , GtkSpinButton * spin )
{
2010-10-19 16:46:40 +00:00
gtk_spin_button_set_snap_to_ticks ( spin ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ) ;
2008-02-27 10:31:24 +00:00
}
static void
toggle_numeric ( GtkWidget * widget , GtkSpinButton * spin )
{
2010-10-19 16:46:40 +00:00
gtk_spin_button_set_numeric ( spin ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ) ;
2008-02-27 10:31:24 +00:00
}
static void
change_digits ( GtkWidget * widget , GtkSpinButton * spin )
{
gtk_spin_button_set_digits ( GTK_SPIN_BUTTON ( spinner1 ) ,
gtk_spin_button_get_value_as_int ( spin ) ) ;
}
static void
get_value ( GtkWidget * widget , gpointer data )
{
gchar buf [ 32 ] ;
GtkLabel * label ;
GtkSpinButton * spin ;
spin = GTK_SPIN_BUTTON ( spinner1 ) ;
label = GTK_LABEL ( g_object_get_data ( G_OBJECT ( widget ) , " user_data " ) ) ;
if ( GPOINTER_TO_INT ( data ) = = 1 )
sprintf ( buf , " %d " , gtk_spin_button_get_value_as_int ( spin ) ) ;
else
2010-07-12 22:48:49 +00:00
sprintf ( buf , " %0.*f " ,
gtk_spin_button_get_digits ( spin ) ,
gtk_spin_button_get_value ( spin ) ) ;
2008-02-27 10:31:24 +00:00
gtk_label_set_text ( label , buf ) ;
}
static void
get_spin_value ( GtkWidget * widget , gpointer data )
{
gchar * buffer ;
GtkLabel * label ;
GtkSpinButton * spin ;
spin = GTK_SPIN_BUTTON ( widget ) ;
label = GTK_LABEL ( data ) ;
2010-07-12 22:48:49 +00:00
buffer = g_strdup_printf ( " %0.*f " ,
gtk_spin_button_get_digits ( spin ) ,
2008-02-27 10:31:24 +00:00
gtk_spin_button_get_value ( spin ) ) ;
gtk_label_set_text ( label , buffer ) ;
g_free ( buffer ) ;
}
static gint
spin_button_time_output_func ( GtkSpinButton * spin_button )
{
2010-07-12 22:48:49 +00:00
GtkAdjustment * adjustment ;
2008-02-27 10:31:24 +00:00
static gchar buf [ 6 ] ;
gdouble hours ;
gdouble minutes ;
2010-07-12 22:48:49 +00:00
adjustment = gtk_spin_button_get_adjustment ( spin_button ) ;
hours = gtk_adjustment_get_value ( adjustment ) / 60.0 ;
2008-02-27 10:31:24 +00:00
minutes = ( fabs ( floor ( hours ) - hours ) < 1e-5 ) ? 0.0 : 30 ;
sprintf ( buf , " %02.0f:%02.0f " , floor ( hours ) , minutes ) ;
2018-03-17 10:20:49 +00:00
if ( strcmp ( buf , gtk_spin_button_get_text ( spin_button ) ) )
gtk_spin_button_set_text ( spin_button , buf ) ;
2008-02-27 10:31:24 +00:00
return TRUE ;
}
static gint
spin_button_month_input_func ( GtkSpinButton * spin_button ,
gdouble * new_val )
{
gint i ;
static gchar * month [ 12 ] = { " January " , " February " , " March " , " April " ,
" May " , " June " , " July " , " August " ,
" September " , " October " , " November " , " December " } ;
gchar * tmp1 , * tmp2 ;
gboolean found = FALSE ;
for ( i = 1 ; i < = 12 ; i + + )
{
tmp1 = g_ascii_strup ( month [ i - 1 ] , - 1 ) ;
2018-03-17 10:20:49 +00:00
tmp2 = g_ascii_strup ( gtk_spin_button_get_text ( spin_button ) , - 1 ) ;
2008-02-27 10:31:24 +00:00
if ( strstr ( tmp1 , tmp2 ) = = tmp1 )
found = TRUE ;
g_free ( tmp1 ) ;
g_free ( tmp2 ) ;
if ( found )
break ;
}
if ( ! found )
{
* new_val = 0.0 ;
return GTK_INPUT_ERROR ;
}
* new_val = ( gdouble ) i ;
return TRUE ;
}
static gint
spin_button_month_output_func ( GtkSpinButton * spin_button )
{
2010-07-12 22:48:49 +00:00
GtkAdjustment * adjustment ;
gdouble value ;
2008-02-27 10:31:24 +00:00
gint i ;
static gchar * month [ 12 ] = { " January " , " February " , " March " , " April " ,
" May " , " June " , " July " , " August " , " September " ,
" October " , " November " , " December " } ;
2010-07-12 22:48:49 +00:00
adjustment = gtk_spin_button_get_adjustment ( spin_button ) ;
value = gtk_adjustment_get_value ( adjustment ) ;
2008-02-27 10:31:24 +00:00
for ( i = 1 ; i < = 12 ; i + + )
2010-07-12 22:48:49 +00:00
if ( fabs ( value - ( double ) i ) < 1e-5 )
2008-02-27 10:31:24 +00:00
{
2018-03-17 10:20:49 +00:00
if ( strcmp ( month [ i - 1 ] , gtk_spin_button_get_text ( spin_button ) ) )
gtk_spin_button_set_text ( spin_button , month [ i - 1 ] ) ;
2008-02-27 10:31:24 +00:00
}
return TRUE ;
}
static gint
spin_button_hex_input_func ( GtkSpinButton * spin_button ,
gdouble * new_val )
{
const gchar * buf ;
gchar * err ;
gdouble res ;
2018-03-17 10:20:49 +00:00
buf = gtk_spin_button_get_text ( GTK_SPIN_BUTTON ( spin_button ) ) ;
2008-02-27 10:31:24 +00:00
res = strtol ( buf , & err , 16 ) ;
* new_val = res ;
if ( * err )
return GTK_INPUT_ERROR ;
else
return TRUE ;
}
static gint
spin_button_hex_output_func ( GtkSpinButton * spin_button )
{
2010-07-12 22:48:49 +00:00
GtkAdjustment * adjustment ;
2008-02-27 10:31:24 +00:00
static gchar buf [ 7 ] ;
gint val ;
2010-07-12 22:48:49 +00:00
adjustment = gtk_spin_button_get_adjustment ( spin_button ) ;
val = ( gint ) gtk_adjustment_get_value ( adjustment ) ;
2008-02-27 10:31:24 +00:00
if ( fabs ( val ) < 1e-5 )
sprintf ( buf , " 0x00 " ) ;
else
sprintf ( buf , " 0x%.2X " , val ) ;
2018-03-17 10:20:49 +00:00
if ( strcmp ( buf , gtk_spin_button_get_text ( spin_button ) ) )
gtk_spin_button_set_text ( spin_button , buf ) ;
2008-02-27 10:31:24 +00:00
return TRUE ;
}
static void
create_spins ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * frame ;
GtkWidget * hbox ;
GtkWidget * main_vbox ;
GtkWidget * vbox ;
GtkWidget * vbox2 ;
GtkWidget * spinner2 ;
GtkWidget * spinner ;
GtkWidget * button ;
GtkWidget * label ;
GtkWidget * val_label ;
2011-01-05 22:28:55 +00:00
GtkAdjustment * adjustment ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkSpinButton " ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
main_vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , main_vbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Not accelerated " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , frame ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , vbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
/* Time, month, hex spinners */
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox2 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Time : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label ) ;
2010-09-27 13:10:12 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 0 , 0 , 1410 , 30 , 60 , 0 ) ;
spinner = gtk_spin_button_new ( adjustment , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_editable_set_editable ( GTK_EDITABLE ( spinner ) , FALSE ) ;
g_signal_connect ( spinner ,
" output " ,
G_CALLBACK ( spin_button_time_output_func ) ,
NULL ) ;
gtk_spin_button_set_wrap ( GTK_SPIN_BUTTON ( spinner ) , TRUE ) ;
2018-03-17 10:20:49 +00:00
gtk_spin_button_set_width_chars ( GTK_SPIN_BUTTON ( spinner ) , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , spinner ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox2 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Month : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label ) ;
2010-09-27 13:10:12 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 1.0 , 1.0 , 12.0 , 1.0 ,
2008-02-27 10:31:24 +00:00
5.0 , 0.0 ) ;
2011-01-05 22:28:55 +00:00
spinner = gtk_spin_button_new ( adjustment , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_spin_button_set_update_policy ( GTK_SPIN_BUTTON ( spinner ) ,
GTK_UPDATE_IF_VALID ) ;
g_signal_connect ( spinner ,
" input " ,
G_CALLBACK ( spin_button_month_input_func ) ,
NULL ) ;
g_signal_connect ( spinner ,
" output " ,
G_CALLBACK ( spin_button_month_output_func ) ,
NULL ) ;
gtk_spin_button_set_wrap ( GTK_SPIN_BUTTON ( spinner ) , TRUE ) ;
2018-03-17 10:20:49 +00:00
gtk_spin_button_set_width_chars ( GTK_SPIN_BUTTON ( spinner ) , 9 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , spinner ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox2 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Hex : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label ) ;
2008-02-27 10:31:24 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 0 , 0 , 255 , 1 , 16 , 0 ) ;
spinner = gtk_spin_button_new ( adjustment , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_editable_set_editable ( GTK_EDITABLE ( spinner ) , TRUE ) ;
g_signal_connect ( spinner ,
" input " ,
G_CALLBACK ( spin_button_hex_input_func ) ,
NULL ) ;
g_signal_connect ( spinner ,
" output " ,
G_CALLBACK ( spin_button_hex_output_func ) ,
NULL ) ;
gtk_spin_button_set_wrap ( GTK_SPIN_BUTTON ( spinner ) , TRUE ) ;
2018-03-17 10:20:49 +00:00
gtk_spin_button_set_width_chars ( GTK_SPIN_BUTTON ( spinner ) , 4 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , spinner ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Accelerated " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , frame ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , vbox ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox2 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Value : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label ) ;
2008-02-27 10:31:24 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 0.0 , - 10000.0 , 10000.0 ,
2008-02-27 10:31:24 +00:00
0.5 , 100.0 , 0.0 ) ;
2011-01-05 22:28:55 +00:00
spinner1 = gtk_spin_button_new ( adjustment , 1.0 , 2 ) ;
2008-02-27 10:31:24 +00:00
gtk_spin_button_set_wrap ( GTK_SPIN_BUTTON ( spinner1 ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , spinner1 ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , vbox2 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Digits : " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label ) ;
2008-02-27 10:31:24 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 2 , 1 , 15 , 1 , 1 , 0 ) ;
spinner2 = gtk_spin_button_new ( adjustment , 0.0 , 0 ) ;
g_signal_connect ( adjustment , " value_changed " ,
2008-02-27 10:31:24 +00:00
G_CALLBACK ( change_digits ) ,
spinner2 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , spinner2 ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " Snap to 0.5-ticks " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( toggle_snap ) ,
spinner1 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
button = gtk_check_button_new_with_label ( " Numeric only input mode " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( toggle_numeric ) ,
spinner1 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
val_label = gtk_label_new ( " " ) ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Value as Int " ) ;
g_object_set_data ( G_OBJECT ( button ) , " user_data " , val_label ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( get_value ) ,
GINT_TO_POINTER ( 1 ) ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Value as Float " ) ;
g_object_set_data ( G_OBJECT ( button ) , " user_data " , val_label ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( get_value ) ,
GINT_TO_POINTER ( 2 ) ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , val_label ) ;
2008-02-27 10:31:24 +00:00
gtk_label_set_text ( GTK_LABEL ( val_label ) , " 0 " ) ;
frame = gtk_frame_new ( " Using Convenience Constructor " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , frame ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
val_label = gtk_label_new ( " 0.0 " ) ;
spinner = gtk_spin_button_new_with_range ( 0.0 , 10.0 , 0.009 ) ;
gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spinner ) , 0.0 ) ;
g_signal_connect ( spinner , " value_changed " ,
G_CALLBACK ( get_spin_value ) , val_label ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , spinner ) ;
gtk_box_pack_start ( GTK_BOX ( hbox ) , val_label ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , hbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* Cursors
*/
2017-11-08 15:05:33 +00:00
static void
cursor_draw ( GtkDrawingArea * darea ,
cairo_t * cr ,
int width ,
int height ,
gpointer user_data )
2008-02-27 10:31:24 +00:00
{
2014-10-12 02:54:40 +00:00
cairo_set_fill_rule ( cr , CAIRO_FILL_RULE_EVEN_ODD ) ;
cairo_rectangle ( cr , 0 , 0 , width , height ) ;
cairo_rectangle ( cr , width / 3 , height / 3 , width / 3 , height / 3 ) ;
cairo_clip ( cr ) ;
2010-07-15 17:05:46 +00:00
cairo_set_source_rgb ( cr , 1 , 1 , 1 ) ;
2010-09-09 01:12:51 +00:00
cairo_rectangle ( cr , 0 , 0 , width , height / 2 ) ;
2010-07-15 17:05:46 +00:00
cairo_fill ( cr ) ;
cairo_set_source_rgb ( cr , 0 , 0 , 0 ) ;
2010-09-09 01:12:51 +00:00
cairo_rectangle ( cr , 0 , height / 2 , width , height / 2 ) ;
2010-07-15 17:05:46 +00:00
cairo_fill ( cr ) ;
2008-02-27 10:31:24 +00:00
}
2015-04-05 23:00:44 +00:00
static const gchar * cursor_names [ ] = {
2015-05-07 22:29:04 +00:00
" all-scroll " ,
2015-04-05 23:00:44 +00:00
" arrow " ,
" bd_double_arrow " ,
" boat " ,
" bottom_left_corner " ,
" bottom_right_corner " ,
" bottom_side " ,
" bottom_tee " ,
" box_spiral " ,
" center_ptr " ,
" circle " ,
" clock " ,
" coffee_mug " ,
" copy " ,
" cross " ,
" crossed_circle " ,
" cross_reverse " ,
" crosshair " ,
" diamond_cross " ,
" dnd-ask " ,
" dnd-copy " ,
" dnd-link " ,
" dnd-move " ,
" dnd-none " ,
" dot " ,
" dotbox " ,
" double_arrow " ,
" draft_large " ,
" draft_small " ,
" draped_box " ,
" exchange " ,
" fd_double_arrow " ,
" fleur " ,
" gobbler " ,
" gumby " ,
2015-05-07 22:29:04 +00:00
" grab " ,
2015-04-05 23:00:44 +00:00
" grabbing " ,
" hand " ,
" hand1 " ,
" hand2 " ,
" heart " ,
" h_double_arrow " ,
" help " ,
" icon " ,
" iron_cross " ,
" left_ptr " ,
" left_ptr_help " ,
" left_ptr_watch " ,
" left_side " ,
" left_tee " ,
" leftbutton " ,
" link " ,
" ll_angle " ,
" lr_angle " ,
" man " ,
" middlebutton " ,
" mouse " ,
" move " ,
" pencil " ,
" pirate " ,
" plus " ,
" question_arrow " ,
" right_ptr " ,
" right_side " ,
" right_tee " ,
" rightbutton " ,
" rtl_logo " ,
" sailboat " ,
" sb_down_arrow " ,
" sb_h_double_arrow " ,
" sb_left_arrow " ,
" sb_right_arrow " ,
" sb_up_arrow " ,
" sb_v_double_arrow " ,
" shuttle " ,
" sizing " ,
" spider " ,
" spraycan " ,
" star " ,
" target " ,
" tcross " ,
" top_left_arrow " ,
" top_left_corner " ,
" top_right_corner " ,
" top_side " ,
" top_tee " ,
" trek " ,
" ul_angle " ,
" umbrella " ,
" ur_angle " ,
" v_double_arrow " ,
2015-05-07 22:29:04 +00:00
" vertical-text " ,
2015-04-05 23:00:44 +00:00
" watch " ,
" X_cursor " ,
2015-05-07 22:29:04 +00:00
" xterm " ,
" zoom-in " ,
" zoom-out "
2015-04-05 23:00:44 +00:00
} ;
2008-02-27 10:31:24 +00:00
2015-04-05 23:00:44 +00:00
static GtkTreeModel *
cursor_model ( void )
{
GtkListStore * store ;
gint i ;
store = gtk_list_store_new ( 1 , G_TYPE_STRING ) ;
2008-02-27 10:31:24 +00:00
2015-04-05 23:00:44 +00:00
for ( i = 0 ; i < G_N_ELEMENTS ( cursor_names ) ; i + + )
gtk_list_store_insert_with_values ( store , NULL , - 1 , 0 , cursor_names [ i ] , - 1 ) ;
2008-06-18 07:00:46 +00:00
2015-04-05 23:00:44 +00:00
return ( GtkTreeModel * ) store ;
2008-02-27 10:31:24 +00:00
}
2018-01-10 23:30:13 +00:00
static void
cursor_pressed_cb ( GtkGesture * gesture ,
int n_pressed ,
double x ,
double y ,
GtkWidget * entry )
2008-02-27 10:31:24 +00:00
{
2018-01-10 23:30:13 +00:00
GtkWidget * widget ;
2015-04-05 23:00:44 +00:00
const gchar * name ;
gint i ;
const gint n = G_N_ELEMENTS ( cursor_names ) ;
2018-01-10 23:30:13 +00:00
int button ;
widget = gtk_event_controller_get_widget ( GTK_EVENT_CONTROLLER ( gesture ) ) ;
2015-04-05 23:00:44 +00:00
name = ( const gchar * ) g_object_get_data ( G_OBJECT ( widget ) , " name " ) ;
if ( name ! = NULL )
{
for ( i = 0 ; i < n ; i + + )
if ( strcmp ( name , cursor_names [ i ] ) = = 0 )
break ;
}
else
i = 0 ;
2018-01-10 23:30:13 +00:00
button = gtk_gesture_single_get_current_button ( GTK_GESTURE_SINGLE ( gesture ) ) ;
if ( button = = GDK_BUTTON_PRIMARY )
i = ( i + 1 ) % n ;
else
i = ( i + n - 1 ) % n ;
2008-02-27 10:31:24 +00:00
2018-01-10 23:30:13 +00:00
gtk_entry_set_text ( GTK_ENTRY ( entry ) , cursor_names [ i ] ) ;
2008-02-27 10:31:24 +00:00
}
2015-04-05 23:00:44 +00:00
static void
set_cursor_from_name ( GtkWidget * entry ,
GtkWidget * widget )
{
const gchar * name ;
name = gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ;
2017-11-04 00:37:03 +00:00
gtk_widget_set_cursor_from_name ( widget , name ) ;
2015-04-05 23:00:44 +00:00
g_object_set_data_full ( G_OBJECT ( widget ) , " name " , g_strdup ( name ) , g_free ) ;
}
2008-02-27 10:31:24 +00:00
# ifdef GDK_WINDOWING_X11
# include "x11/gdkx.h"
2014-09-02 13:53:15 +00:00
# endif
# ifdef GDK_WINDOWING_WAYLAND
# include "wayland/gdkwayland.h"
# endif
2008-02-27 10:31:24 +00:00
static void
change_cursor_theme ( GtkWidget * widget ,
gpointer data )
{
2016-02-07 18:18:18 +00:00
# if defined(GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WAYLAND)
2008-02-27 10:31:24 +00:00
const gchar * theme ;
gint size ;
GList * children ;
2014-09-02 13:53:15 +00:00
GdkDisplay * display ;
2008-02-27 10:31:24 +00:00
children = gtk_container_get_children ( GTK_CONTAINER ( data ) ) ;
theme = gtk_entry_get_text ( GTK_ENTRY ( children - > next - > data ) ) ;
size = ( gint ) gtk_spin_button_get_value ( GTK_SPIN_BUTTON ( children - > next - > next - > data ) ) ;
g_list_free ( children ) ;
2014-09-02 13:53:15 +00:00
display = gtk_widget_get_display ( widget ) ;
# ifdef GDK_WINDOWING_X11
if ( GDK_IS_X11_DISPLAY ( display ) )
gdk_x11_display_set_cursor_theme ( display , theme , size ) ;
2008-02-27 10:31:24 +00:00
# endif
2014-09-02 13:53:15 +00:00
# ifdef GDK_WINDOWING_WAYLAND
if ( GDK_IS_WAYLAND_DISPLAY ( display ) )
gdk_wayland_display_set_cursor_theme ( display , theme , size ) ;
# endif
2016-02-07 18:18:18 +00:00
# endif
2014-09-02 13:53:15 +00:00
}
2008-02-27 10:31:24 +00:00
static void
create_cursors ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * frame ;
GtkWidget * hbox ;
GtkWidget * main_vbox ;
GtkWidget * vbox ;
GtkWidget * darea ;
GtkWidget * button ;
GtkWidget * label ;
GtkWidget * any ;
GtkWidget * entry ;
2015-04-05 23:00:44 +00:00
GtkWidget * size ;
GtkEntryCompletion * completion ;
GtkTreeModel * model ;
2014-09-02 18:24:34 +00:00
gboolean cursor_demo = FALSE ;
2018-01-10 23:30:13 +00:00
GtkGesture * gesture ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2015-04-05 23:00:44 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2015-04-05 23:00:44 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Cursors " ) ;
2015-04-05 23:00:44 +00:00
2010-10-31 17:07:20 +00:00
main_vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , main_vbox ) ;
2017-11-08 15:05:33 +00:00
vbox = g_object_new ( GTK_TYPE_BOX ,
" orientation " , GTK_ORIENTATION_VERTICAL ,
" homogeneous " , FALSE ,
" spacing " , 5 ,
NULL ) ;
gtk_container_add ( GTK_CONTAINER ( main_vbox ) , vbox ) ;
2008-02-27 10:31:24 +00:00
2014-09-25 08:11:38 +00:00
# ifdef GDK_WINDOWING_X11
2014-09-02 18:24:34 +00:00
if ( GDK_IS_X11_DISPLAY ( gtk_widget_get_display ( vbox ) ) )
cursor_demo = TRUE ;
# endif
# ifdef GDK_WINDOWING_WAYLAND
if ( GDK_IS_WAYLAND_DISPLAY ( gtk_widget_get_display ( vbox ) ) )
cursor_demo = TRUE ;
# endif
if ( cursor_demo )
2013-03-13 10:01:57 +00:00
{
2015-04-05 23:00:44 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 6 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2013-03-13 10:01:57 +00:00
2015-04-05 23:00:44 +00:00
label = gtk_label_new ( " Cursor Theme: " ) ;
2013-03-13 10:01:57 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2013-03-13 10:01:57 +00:00
entry = gtk_entry_new ( ) ;
gtk_entry_set_text ( GTK_ENTRY ( entry ) , " default " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , entry ) ;
2013-03-13 10:01:57 +00:00
2018-01-17 04:25:12 +00:00
size = gtk_spin_button_new_with_range ( 1.0 , 128.0 , 1.0 ) ;
2013-03-13 10:01:57 +00:00
gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( size ) , 24.0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , size ) ;
2013-03-13 10:01:57 +00:00
2015-04-05 23:00:44 +00:00
g_signal_connect ( entry , " changed " ,
2013-03-13 10:01:57 +00:00
G_CALLBACK ( change_cursor_theme ) , hbox ) ;
2015-04-05 17:28:26 +00:00
g_signal_connect ( size , " value-changed " ,
2013-03-13 10:01:57 +00:00
G_CALLBACK ( change_cursor_theme ) , hbox ) ;
}
2008-02-27 10:31:24 +00:00
2015-04-05 23:00:44 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 6 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
2015-04-05 23:00:44 +00:00
label = gtk_label_new ( " Cursor Name: " ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2010-09-27 13:10:12 +00:00
2015-04-05 23:00:44 +00:00
entry = gtk_entry_new ( ) ;
completion = gtk_entry_completion_new ( ) ;
model = cursor_model ( ) ;
gtk_entry_completion_set_model ( completion , model ) ;
gtk_entry_completion_set_text_column ( completion , 0 ) ;
gtk_entry_set_completion ( GTK_ENTRY ( entry ) , completion ) ;
g_object_unref ( model ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , entry ) ;
2008-02-27 10:31:24 +00:00
frame =
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
g_object_new ( gtk_frame_get_type ( ) ,
2017-11-08 15:05:33 +00:00
" label_xalign " , 0.5 ,
" label " , " Cursor Area " ,
2008-02-27 10:31:24 +00:00
NULL ) ;
2017-11-08 15:05:33 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
darea = gtk_drawing_area_new ( ) ;
2017-11-08 15:05:33 +00:00
gtk_drawing_area_set_content_width ( GTK_DRAWING_AREA ( darea ) , 80 ) ;
gtk_drawing_area_set_content_height ( GTK_DRAWING_AREA ( darea ) , 80 ) ;
gtk_drawing_area_set_draw_func ( GTK_DRAWING_AREA ( darea ) , cursor_draw , NULL , NULL ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , darea ) ;
2018-01-10 23:30:13 +00:00
gesture = gtk_gesture_multi_press_new ( darea ) ;
gtk_gesture_single_set_button ( GTK_GESTURE_SINGLE ( gesture ) , 0 ) ;
g_signal_connect ( gesture , " pressed " , G_CALLBACK ( cursor_pressed_cb ) , entry ) ;
g_object_set_data_full ( G_OBJECT ( darea ) , " gesture " , gesture , g_object_unref ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( darea ) ;
2015-04-05 23:00:44 +00:00
g_signal_connect ( entry , " changed " ,
G_CALLBACK ( set_cursor_from_name ) , darea ) ;
2008-02-27 10:31:24 +00:00
2011-06-09 04:20:42 +00:00
any = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , any ) ;
2015-04-05 23:00:44 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( main_vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
2015-04-05 23:10:39 +00:00
gtk_entry_set_text ( GTK_ENTRY ( entry ) , " arrow " ) ;
2008-02-27 10:31:24 +00:00
}
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkColorSelection
*/
void
create_color_selection ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
GtkWidget * picker ;
GtkWidget * hbox ;
GtkWidget * label ;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkColorButton " ) ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 8 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , hbox ) ;
label = gtk_label_new ( " Pick a color " ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , label ) ;
picker = gtk_color_button_new ( ) ;
2012-02-09 21:23:30 +00:00
gtk_color_chooser_set_use_alpha ( GTK_COLOR_CHOOSER ( picker ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( hbox ) , picker ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
void
flipping_toggled_cb ( GtkWidget * widget , gpointer data )
{
int state = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ;
int new_direction = state ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR ;
gtk_widget_set_default_direction ( new_direction ) ;
}
2009-02-19 15:12:35 +00:00
static void
orientable_toggle_orientation ( GtkOrientable * orientable )
{
GtkOrientation orientation ;
orientation = gtk_orientable_get_orientation ( orientable ) ;
gtk_orientable_set_orientation ( orientable ,
orientation = = GTK_ORIENTATION_HORIZONTAL ?
GTK_ORIENTATION_VERTICAL :
GTK_ORIENTATION_HORIZONTAL ) ;
if ( GTK_IS_CONTAINER ( orientable ) )
{
GList * children ;
GList * child ;
children = gtk_container_get_children ( GTK_CONTAINER ( orientable ) ) ;
for ( child = children ; child ; child = child - > next )
{
if ( GTK_IS_ORIENTABLE ( child - > data ) )
orientable_toggle_orientation ( child - > data ) ;
}
g_list_free ( children ) ;
}
}
void
flipping_orientation_toggled_cb ( GtkWidget * widget , gpointer data )
{
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
GtkWidget * toplevel ;
toplevel = gtk_widget_get_toplevel ( widget ) ;
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( toplevel ) ) ;
orientable_toggle_orientation ( GTK_ORIENTABLE ( content_area ) ) ;
2009-02-19 15:12:35 +00:00
}
2008-02-27 10:31:24 +00:00
static void
set_direction_recurse ( GtkWidget * widget ,
gpointer data )
{
GtkTextDirection * dir = data ;
gtk_widget_set_direction ( widget , * dir ) ;
if ( GTK_IS_CONTAINER ( widget ) )
gtk_container_foreach ( GTK_CONTAINER ( widget ) ,
set_direction_recurse ,
data ) ;
}
static GtkWidget *
create_forward_back ( const char * title ,
GtkTextDirection text_dir )
{
GtkWidget * frame = gtk_frame_new ( title ) ;
2010-10-29 23:21:15 +00:00
GtkWidget * bbox = gtk_button_box_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2013-06-24 21:31:22 +00:00
GtkWidget * back_button = gtk_button_new_with_label ( " Back " ) ;
GtkWidget * forward_button = gtk_button_new_with_label ( " Forward " ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , bbox ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , back_button ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , forward_button ) ;
set_direction_recurse ( frame , & text_dir ) ;
return frame ;
}
void
create_flipping ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
2014-04-10 12:28:44 +00:00
GtkWidget * check_button ;
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Bidirectional Flipping " ) ;
check_button = gtk_check_button_new_with_label ( " Right-to-left global direction " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , check_button ) ;
2009-02-19 15:12:35 +00:00
if ( gtk_widget_get_default_direction ( ) = = GTK_TEXT_DIR_RTL )
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ) , TRUE ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( flipping_toggled_cb ) , NULL ) ;
check_button = gtk_check_button_new_with_label ( " Toggle orientation of all boxes " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , check_button ) ;
2008-02-27 10:31:24 +00:00
2009-02-19 15:12:35 +00:00
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( flipping_orientation_toggled_cb ) , NULL ) ;
2010-06-03 07:36:39 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) ,
2017-04-21 20:34:36 +00:00
create_forward_back ( " Default " , GTK_TEXT_DIR_NONE ) ) ;
2008-02-27 10:31:24 +00:00
2010-06-03 07:36:39 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) ,
2017-04-21 20:34:36 +00:00
create_forward_back ( " Left-to-Right " , GTK_TEXT_DIR_LTR ) ) ;
2008-02-27 10:31:24 +00:00
2010-06-03 07:36:39 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) ,
2017-04-21 20:34:36 +00:00
create_forward_back ( " Right-to-Left " , GTK_TEXT_DIR_RTL ) ) ;
2008-02-27 10:31:24 +00:00
2014-04-10 12:28:44 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( window ) , " Close " , GTK_RESPONSE_CLOSE ) ;
g_signal_connect ( window , " response " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2008-02-27 10:31:24 +00:00
}
2016-10-02 15:37:22 +00:00
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* Focus test
*/
static GtkWidget *
make_focus_table ( GList * * list )
{
2011-09-28 03:03:20 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
gint i , j ;
2011-09-28 03:03:20 +00:00
grid = gtk_grid_new ( ) ;
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 10 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 10 ) ;
2008-02-27 10:31:24 +00:00
2011-09-28 02:42:54 +00:00
for ( i = 0 ; i < 5 ; i + + )
2008-02-27 10:31:24 +00:00
{
2011-09-28 02:42:54 +00:00
for ( j = 0 ; j < 5 ; j + + )
2008-02-27 10:31:24 +00:00
{
GtkWidget * widget ;
if ( ( i + j ) % 2 )
widget = gtk_entry_new ( ) ;
else
widget = gtk_button_new_with_label ( " Foo " ) ;
* list = g_list_prepend ( * list , widget ) ;
2011-09-28 03:03:20 +00:00
gtk_widget_set_hexpand ( widget , TRUE ) ;
gtk_widget_set_vexpand ( widget , TRUE ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , widget , i , j , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
}
}
* list = g_list_reverse ( * list ) ;
2011-09-28 03:03:20 +00:00
return grid ;
2008-02-27 10:31:24 +00:00
}
static void
create_focus ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
2010-06-03 07:36:39 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * table ;
GtkWidget * frame ;
GList * list = NULL ;
window = gtk_dialog_new_with_buttons ( " Keyboard focus navigation " ,
NULL , 0 ,
2013-06-24 21:31:22 +00:00
" _Close " ,
2008-02-27 10:31:24 +00:00
GTK_RESPONSE_NONE ,
NULL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
g_signal_connect ( window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Keyboard Focus Navigation " ) ;
frame = gtk_frame_new ( " Weird tab focus chain " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , frame ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
table = make_focus_table ( & list ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , table ) ;
gtk_container_set_focus_chain ( GTK_CONTAINER ( table ) ,
list ) ;
g_list_free ( list ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Default tab focus chain " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , frame ) ;
2008-02-27 10:31:24 +00:00
list = NULL ;
table = make_focus_table ( & list ) ;
g_list_free ( list ) ;
2016-10-02 15:37:22 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , table ) ;
2008-02-27 10:31:24 +00:00
}
2016-10-02 15:37:22 +00:00
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkFontSelection
*/
void
create_font_selection ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
if ( ! window )
{
GtkWidget * picker ;
GtkWidget * hbox ;
GtkWidget * label ;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " GtkFontButton " ) ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 8 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , hbox ) ;
label = gtk_label_new ( " Pick a font " ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , label ) ;
picker = gtk_font_button_new ( ) ;
gtk_font_button_set_use_font ( GTK_FONT_BUTTON ( picker ) , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , picker ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkDialog
*/
static GtkWidget * dialog_window = NULL ;
static void
2014-04-10 14:35:51 +00:00
dialog_response_cb ( GtkWidget * widget , gint response , gpointer unused )
2008-02-27 10:31:24 +00:00
{
2014-04-10 14:16:41 +00:00
GtkWidget * content_area ;
GList * l , * children ;
2014-04-10 14:35:51 +00:00
if ( response = = GTK_RESPONSE_APPLY )
2014-04-10 14:16:41 +00:00
{
2014-04-10 14:35:51 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( dialog_window ) ) ;
children = gtk_container_get_children ( GTK_CONTAINER ( content_area ) ) ;
for ( l = children ; l ; l = l - > next )
2014-04-10 14:16:41 +00:00
{
2014-04-10 14:35:51 +00:00
if ( GTK_IS_LABEL ( l - > data ) )
{
gtk_container_remove ( GTK_CONTAINER ( content_area ) , l - > data ) ;
break ;
}
2014-04-10 14:16:41 +00:00
}
2014-04-10 14:07:05 +00:00
2014-04-10 14:35:51 +00:00
/* no label removed, so add one */
if ( l = = NULL )
{
GtkWidget * label ;
2016-10-02 15:37:22 +00:00
2014-04-10 14:35:51 +00:00
label = gtk_label_new ( " Dialog Test " ) ;
g_object_set ( label , " margin " , 10 , NULL ) ;
gtk_box_pack_start ( GTK_BOX ( content_area ) ,
2017-04-21 20:34:36 +00:00
label ) ;
2014-04-10 14:35:51 +00:00
gtk_widget_show ( label ) ;
}
2016-10-02 15:37:22 +00:00
2014-04-10 14:35:51 +00:00
g_list_free ( children ) ;
2008-02-27 10:31:24 +00:00
}
}
static void
create_dialog ( GtkWidget * widget )
{
if ( ! dialog_window )
{
/* This is a terrible example; it's much simpler to create
* dialogs than this . Don ' t use testgtk for example code ,
* use gtk - demo ; - )
*/
dialog_window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( dialog_window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( dialog_window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& dialog_window ) ;
2010-06-03 07:36:39 +00:00
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( dialog_window ) , " GtkDialog " ) ;
2014-04-10 14:35:51 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog_window ) ,
" OK " ,
GTK_RESPONSE_OK ) ;
2008-02-27 10:31:24 +00:00
2014-04-10 14:35:51 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog_window ) ,
" Toggle " ,
GTK_RESPONSE_APPLY ) ;
g_signal_connect ( dialog_window , " response " ,
G_CALLBACK ( dialog_response_cb ) ,
2014-04-10 14:07:05 +00:00
NULL ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( dialog_window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( dialog_window ) ;
else
gtk_widget_destroy ( dialog_window ) ;
}
/* Display & Screen test
*/
2010-04-06 14:57:19 +00:00
typedef struct
{
GtkWidget * combo ;
GtkWidget * entry ;
GtkWidget * toplevel ;
2008-02-27 10:31:24 +00:00
GtkWidget * dialog_window ;
} ScreenDisplaySelection ;
static void
screen_display_check ( GtkWidget * widget , ScreenDisplaySelection * data )
{
2010-04-06 14:57:19 +00:00
const gchar * display_name ;
2015-07-17 23:54:09 +00:00
GdkDisplay * display ;
2008-02-27 10:31:24 +00:00
GtkWidget * dialog ;
2017-10-31 06:41:15 +00:00
GdkDisplay * new_display = NULL ;
GdkDisplay * current_display = gtk_widget_get_display ( widget ) ;
2008-02-27 10:31:24 +00:00
2013-04-04 14:36:09 +00:00
display_name = gtk_entry_get_text ( GTK_ENTRY ( data - > entry ) ) ;
display = gdk_display_open ( display_name ) ;
2008-02-27 10:31:24 +00:00
2013-04-04 14:36:09 +00:00
if ( ! display )
2008-02-27 10:31:24 +00:00
{
2013-04-04 14:36:09 +00:00
dialog = gtk_message_dialog_new ( GTK_WINDOW ( gtk_widget_get_toplevel ( widget ) ) ,
GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
" The display : \n %s \n cannot be opened " ,
display_name ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( dialog ) , current_display ) ;
2013-04-04 14:36:09 +00:00
gtk_widget_show ( dialog ) ;
g_signal_connect ( dialog , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2008-02-27 10:31:24 +00:00
}
2013-04-04 14:36:09 +00:00
else
2008-02-27 10:31:24 +00:00
{
2013-04-04 14:36:09 +00:00
GtkTreeModel * model = gtk_combo_box_get_model ( GTK_COMBO_BOX ( data - > combo ) ) ;
gint i = 0 ;
GtkTreeIter iter ;
gboolean found = FALSE ;
while ( gtk_tree_model_iter_nth_child ( model , & iter , NULL , i + + ) )
{
gchar * name ;
gtk_tree_model_get ( model , & iter , 0 , & name , - 1 ) ;
found = ! g_ascii_strcasecmp ( display_name , name ) ;
g_free ( name ) ;
if ( found )
break ;
}
if ( ! found )
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( data - > combo ) , display_name ) ;
2017-10-31 06:41:15 +00:00
new_display = display ;
2013-04-04 14:36:09 +00:00
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( data - > toplevel ) , new_display ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( data - > dialog_window ) ;
}
}
void
screen_display_destroy_diag ( GtkWidget * widget , GtkWidget * data )
{
gtk_widget_destroy ( data ) ;
}
void
create_display_screen ( GtkWidget * widget )
{
2011-09-28 03:13:00 +00:00
GtkWidget * grid , * frame , * window , * combo_dpy , * vbox ;
2013-04-04 14:36:09 +00:00
GtkWidget * label_dpy , * applyb , * cancelb ;
2008-02-27 10:31:24 +00:00
GtkWidget * bbox ;
ScreenDisplaySelection * scr_dpy_data ;
2017-10-31 06:41:15 +00:00
GdkDisplay * display = gtk_widget_get_display ( widget ) ;
2008-02-27 10:31:24 +00:00
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
window = g_object_new ( gtk_window_get_type ( ) ,
2017-10-31 06:41:15 +00:00
" display " , display ,
2011-09-28 03:08:19 +00:00
" type " , GTK_WINDOW_TOPLEVEL ,
" title " , " Screen or Display selection " ,
10 , NULL ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 3 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , vbox ) ;
2013-04-04 14:36:09 +00:00
frame = gtk_frame_new ( " Select display " ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , frame ) ;
2011-09-28 03:13:00 +00:00
grid = gtk_grid_new ( ) ;
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 3 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 3 ) ;
2008-02-27 10:31:24 +00:00
2011-09-28 03:13:00 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , grid ) ;
2008-02-27 10:31:24 +00:00
2013-04-04 14:36:09 +00:00
label_dpy = gtk_label_new ( " move to another X display " ) ;
2010-10-18 07:10:27 +00:00
combo_dpy = gtk_combo_box_text_new_with_entry ( ) ;
2011-09-28 03:13:00 +00:00
gtk_widget_set_hexpand ( combo_dpy , TRUE ) ;
2010-10-02 16:19:46 +00:00
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo_dpy ) , " diabolo:0.0 " ) ;
2010-04-06 14:57:19 +00:00
gtk_entry_set_text ( GTK_ENTRY ( gtk_bin_get_child ( GTK_BIN ( combo_dpy ) ) ) ,
" <hostname>:<X Server Num>.<Screen Num> " ) ;
2008-02-27 10:31:24 +00:00
2013-04-04 14:36:09 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , label_dpy , 0 , 0 , 1 , 1 ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , combo_dpy , 0 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:21:15 +00:00
bbox = gtk_button_box_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2013-06-24 21:31:22 +00:00
applyb = gtk_button_new_with_label ( " _Apply " ) ;
cancelb = gtk_button_new_with_label ( " _Cancel " ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , bbox ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , applyb ) ;
gtk_container_add ( GTK_CONTAINER ( bbox ) , cancelb ) ;
scr_dpy_data = g_new0 ( ScreenDisplaySelection , 1 ) ;
2010-04-06 14:57:19 +00:00
scr_dpy_data - > entry = gtk_bin_get_child ( GTK_BIN ( combo_dpy ) ) ;
2008-02-27 10:31:24 +00:00
scr_dpy_data - > toplevel = gtk_widget_get_toplevel ( widget ) ;
scr_dpy_data - > dialog_window = window ;
g_signal_connect ( cancelb , " clicked " ,
G_CALLBACK ( screen_display_destroy_diag ) , window ) ;
g_signal_connect ( applyb , " clicked " ,
G_CALLBACK ( screen_display_check ) , scr_dpy_data ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
}
/*
* GtkRange
*/
static gchar *
reformat_value ( GtkScale * scale ,
gdouble value )
{
return g_strdup_printf ( " -->%0.*g<-- " ,
gtk_scale_get_digits ( scale ) , value ) ;
}
static void
create_range_controls ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * scrollbar ;
GtkWidget * scale ;
GtkWidget * separator ;
2010-09-27 12:48:26 +00:00
GtkAdjustment * adjustment ;
2008-02-27 10:31:24 +00:00
GtkWidget * hbox ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " range controls " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
gtk_widget_show ( box1 ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
adjustment = gtk_adjustment_new ( 0.0 , 0.0 , 101.0 , 0.1 , 1.0 , 1.0 ) ;
2010-10-30 00:07:28 +00:00
scale = gtk_scale_new ( GTK_ORIENTATION_HORIZONTAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_set_size_request ( GTK_WIDGET ( scale ) , 150 , - 1 ) ;
gtk_scale_set_digits ( GTK_SCALE ( scale ) , 1 ) ;
gtk_scale_set_draw_value ( GTK_SCALE ( scale ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , scale ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scale ) ;
2010-10-30 00:11:05 +00:00
scrollbar = gtk_scrollbar_new ( GTK_ORIENTATION_HORIZONTAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , scrollbar ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scrollbar ) ;
2010-10-30 00:07:28 +00:00
scale = gtk_scale_new ( GTK_ORIENTATION_HORIZONTAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2008-02-27 10:31:24 +00:00
gtk_scale_set_draw_value ( GTK_SCALE ( scale ) , TRUE ) ;
g_signal_connect ( scale ,
" format_value " ,
G_CALLBACK ( reformat_value ) ,
NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , scale ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scale ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
2010-10-30 00:07:28 +00:00
scale = gtk_scale_new ( GTK_ORIENTATION_VERTICAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_set_size_request ( scale , - 1 , 200 ) ;
gtk_scale_set_digits ( GTK_SCALE ( scale ) , 2 ) ;
gtk_scale_set_draw_value ( GTK_SCALE ( scale ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , scale ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scale ) ;
2010-10-30 00:07:28 +00:00
scale = gtk_scale_new ( GTK_ORIENTATION_VERTICAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_set_size_request ( scale , - 1 , 200 ) ;
gtk_scale_set_digits ( GTK_SCALE ( scale ) , 2 ) ;
gtk_scale_set_draw_value ( GTK_SCALE ( scale ) , TRUE ) ;
gtk_range_set_inverted ( GTK_RANGE ( scale ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , scale ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scale ) ;
2010-10-30 00:07:28 +00:00
scale = gtk_scale_new ( GTK_ORIENTATION_VERTICAL , GTK_ADJUSTMENT ( adjustment ) ) ;
2008-02-27 10:31:24 +00:00
gtk_scale_set_draw_value ( GTK_SCALE ( scale ) , TRUE ) ;
g_signal_connect ( scale ,
" format_value " ,
G_CALLBACK ( reformat_value ) ,
NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , scale ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( scale ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , hbox ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( hbox ) ;
2016-10-02 15:37:22 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( separator ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
gtk_widget_show ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkNotebook
*/
2010-08-06 18:37:48 +00:00
static const char * book_open_xpm [ ] = {
2010-04-13 16:55:50 +00:00
" 16 16 4 1 " ,
" c None s None " ,
" . c black " ,
" X c #808080 " ,
" o c white " ,
" " ,
" .. " ,
" .Xo. ... " ,
" .Xoo. ..oo. " ,
" .Xooo.Xooo... " ,
" .Xooo.oooo.X. " ,
" .Xooo.Xooo.X. " ,
" .Xooo.oooo.X. " ,
" .Xooo.Xooo.X. " ,
" .Xooo.oooo.X. " ,
" .Xoo.Xoo..X. " ,
" .Xo.o..ooX. " ,
" .X..XXXXX. " ,
" ..X....... " ,
" .. " ,
" " } ;
2010-08-06 18:37:48 +00:00
static const char * book_closed_xpm [ ] = {
2010-04-13 16:55:50 +00:00
" 16 16 6 1 " ,
" c None s None " ,
" . c black " ,
" X c red " ,
" o c yellow " ,
" O c #808080 " ,
" # c white " ,
" " ,
" .. " ,
" ..XX. " ,
" ..XXXXX. " ,
" ..XXXXXXXX. " ,
" .ooXXXXXXXXX. " ,
" ..ooXXXXXXXXX. " ,
" .X.ooXXXXXXXXX. " ,
" .XX.ooXXXXXX.. " ,
" .XX.ooXXX..#O " ,
" .XX.oo..##OO. " ,
" .XX..##OO.. " ,
" .X.#OO.. " ,
" ..O.. " ,
" .. " ,
" " } ;
2008-02-27 10:31:24 +00:00
GdkPixbuf * book_open ;
GdkPixbuf * book_closed ;
GtkWidget * sample_notebook ;
static void
set_page_image ( GtkNotebook * notebook , gint page_num , GdkPixbuf * pixbuf )
{
GtkWidget * page_widget ;
GtkWidget * pixwid ;
page_widget = gtk_notebook_get_nth_page ( notebook , page_num ) ;
pixwid = g_object_get_data ( G_OBJECT ( page_widget ) , " tab_pixmap " ) ;
gtk_image_set_from_pixbuf ( GTK_IMAGE ( pixwid ) , pixbuf ) ;
pixwid = g_object_get_data ( G_OBJECT ( page_widget ) , " menu_pixmap " ) ;
gtk_image_set_from_pixbuf ( GTK_IMAGE ( pixwid ) , pixbuf ) ;
}
static void
2010-07-13 14:49:53 +00:00
page_switch ( GtkWidget * widget , gpointer * page , gint page_num )
2008-02-27 10:31:24 +00:00
{
GtkNotebook * notebook = GTK_NOTEBOOK ( widget ) ;
gint old_page_num = gtk_notebook_get_current_page ( notebook ) ;
if ( page_num = = old_page_num )
return ;
set_page_image ( notebook , page_num , book_open ) ;
if ( old_page_num ! = - 1 )
set_page_image ( notebook , old_page_num , book_closed ) ;
}
static void
tab_fill ( GtkToggleButton * button , GtkWidget * child )
{
2010-04-26 03:26:42 +00:00
gtk_container_child_set ( GTK_CONTAINER ( sample_notebook ) , child ,
" tab-fill " , gtk_toggle_button_get_active ( button ) ,
NULL ) ;
2008-02-27 10:31:24 +00:00
}
static void
tab_expand ( GtkToggleButton * button , GtkWidget * child )
{
2010-04-26 03:26:42 +00:00
gtk_container_child_set ( GTK_CONTAINER ( sample_notebook ) , child ,
" tab-expand " , gtk_toggle_button_get_active ( button ) ,
NULL ) ;
2008-02-27 10:31:24 +00:00
}
static void
create_pages ( GtkNotebook * notebook , gint start , gint end )
{
GtkWidget * child = NULL ;
GtkWidget * button ;
GtkWidget * label ;
GtkWidget * hbox ;
GtkWidget * vbox ;
GtkWidget * label_box ;
GtkWidget * menu_box ;
GtkWidget * pixwid ;
gint i ;
char buffer [ 32 ] ;
char accel_buffer [ 32 ] ;
for ( i = start ; i < = end ; i + + )
{
sprintf ( buffer , " Page %d " , i ) ;
sprintf ( accel_buffer , " Page _%d " , i ) ;
child = gtk_frame_new ( buffer ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
gtk_box_set_homogeneous ( GTK_BOX ( vbox ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( child ) , vbox ) ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
gtk_box_set_homogeneous ( GTK_BOX ( hbox ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , hbox ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " Fill Tab " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
g_signal_connect ( button , " toggled " ,
G_CALLBACK ( tab_fill ) , child ) ;
button = gtk_check_button_new_with_label ( " Expand Tab " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( button , " toggled " ,
G_CALLBACK ( tab_expand ) , child ) ;
button = gtk_button_new_with_label ( " Hide Page " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_hide ) ,
child ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( child ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
label_box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
pixwid = gtk_image_new_from_pixbuf ( book_closed ) ;
g_object_set_data ( G_OBJECT ( child ) , " tab_pixmap " , pixwid ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( label_box ) , pixwid ) ;
2013-11-14 22:31:17 +00:00
gtk_widget_set_margin_start ( pixwid , 3 ) ;
gtk_widget_set_margin_end ( pixwid , 3 ) ;
2011-06-02 11:37:43 +00:00
gtk_widget_set_margin_bottom ( pixwid , 1 ) ;
gtk_widget_set_margin_top ( pixwid , 1 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new_with_mnemonic ( accel_buffer ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( label_box ) , label ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( label_box ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
menu_box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
pixwid = gtk_image_new_from_pixbuf ( book_closed ) ;
g_object_set_data ( G_OBJECT ( child ) , " menu_pixmap " , pixwid ) ;
2016-10-02 15:37:22 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( menu_box ) , pixwid ) ;
2013-11-14 22:31:17 +00:00
gtk_widget_set_margin_start ( pixwid , 3 ) ;
gtk_widget_set_margin_end ( pixwid , 3 ) ;
2011-06-02 11:37:43 +00:00
gtk_widget_set_margin_bottom ( pixwid , 1 ) ;
gtk_widget_set_margin_top ( pixwid , 1 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( buffer ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( menu_box ) , label ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( menu_box ) ;
2008-02-27 10:31:24 +00:00
gtk_notebook_append_page_menu ( notebook , child , label_box , menu_box ) ;
}
}
static void
rotate_notebook ( GtkButton * button ,
GtkNotebook * notebook )
{
2010-07-02 20:39:02 +00:00
gtk_notebook_set_tab_pos ( notebook , ( gtk_notebook_get_tab_pos ( notebook ) + 1 ) % 4 ) ;
2008-02-27 10:31:24 +00:00
}
static void
show_all_pages ( GtkButton * button ,
GtkNotebook * notebook )
{
gtk_container_foreach ( GTK_CONTAINER ( notebook ) ,
( GtkCallback ) gtk_widget_show , NULL ) ;
}
static void
notebook_type_changed ( GtkWidget * optionmenu ,
gpointer data )
{
GtkNotebook * notebook ;
gint i , c ;
enum {
STANDARD ,
NOTABS ,
BORDERLESS ,
SCROLLABLE
} ;
notebook = GTK_NOTEBOOK ( data ) ;
2010-03-26 16:55:07 +00:00
c = gtk_combo_box_get_active ( GTK_COMBO_BOX ( optionmenu ) ) ;
2008-02-27 10:31:24 +00:00
switch ( c )
{
case STANDARD :
/* standard notebook */
gtk_notebook_set_show_tabs ( notebook , TRUE ) ;
gtk_notebook_set_show_border ( notebook , TRUE ) ;
gtk_notebook_set_scrollable ( notebook , FALSE ) ;
break ;
case NOTABS :
/* notabs notebook */
gtk_notebook_set_show_tabs ( notebook , FALSE ) ;
gtk_notebook_set_show_border ( notebook , TRUE ) ;
break ;
case BORDERLESS :
/* borderless */
gtk_notebook_set_show_tabs ( notebook , FALSE ) ;
gtk_notebook_set_show_border ( notebook , FALSE ) ;
break ;
case SCROLLABLE :
/* scrollable */
gtk_notebook_set_show_tabs ( notebook , TRUE ) ;
gtk_notebook_set_show_border ( notebook , TRUE ) ;
gtk_notebook_set_scrollable ( notebook , TRUE ) ;
2010-07-02 20:39:02 +00:00
if ( gtk_notebook_get_n_pages ( notebook ) = = 5 )
2008-02-27 10:31:24 +00:00
create_pages ( notebook , 6 , 15 ) ;
2010-07-02 20:39:02 +00:00
2008-02-27 10:31:24 +00:00
return ;
break ;
}
2010-07-02 20:39:02 +00:00
if ( gtk_notebook_get_n_pages ( notebook ) = = 15 )
2008-02-27 10:31:24 +00:00
for ( i = 0 ; i < 10 ; i + + )
gtk_notebook_remove_page ( notebook , 5 ) ;
}
static void
notebook_popup ( GtkToggleButton * button ,
GtkNotebook * notebook )
{
2010-10-19 16:46:40 +00:00
if ( gtk_toggle_button_get_active ( button ) )
2008-02-27 10:31:24 +00:00
gtk_notebook_popup_enable ( notebook ) ;
else
gtk_notebook_popup_disable ( notebook ) ;
}
static void
create_notebook ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * button ;
GtkWidget * separator ;
GtkWidget * omenu ;
GtkWidget * label ;
static gchar * items [ ] =
{
" Standard " ,
" No tabs " ,
" Borderless " ,
" Scrollable "
} ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " notebook " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
sample_notebook = gtk_notebook_new ( ) ;
g_signal_connect ( sample_notebook , " switch_page " ,
G_CALLBACK ( page_switch ) , NULL ) ;
gtk_notebook_set_tab_pos ( GTK_NOTEBOOK ( sample_notebook ) , GTK_POS_TOP ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , sample_notebook ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_realize ( sample_notebook ) ;
if ( ! book_open )
2010-08-06 18:37:48 +00:00
book_open = gdk_pixbuf_new_from_xpm_data ( book_open_xpm ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
if ( ! book_closed )
2010-08-06 18:37:48 +00:00
book_closed = gdk_pixbuf_new_from_xpm_data ( book_closed_xpm ) ;
2008-02-27 10:31:24 +00:00
create_pages ( GTK_NOTEBOOK ( sample_notebook ) , 1 , 5 ) ;
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_check_button_new_with_label ( " popup menu " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( notebook_popup ) ,
sample_notebook ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Notebook Style : " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , label ) ;
2008-02-27 10:31:24 +00:00
omenu = build_option_menu ( items , G_N_ELEMENTS ( items ) , 0 ,
notebook_type_changed ,
sample_notebook ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , omenu ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Show all Pages " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( show_all_pages ) , sample_notebook ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 10 ) ;
gtk_box_set_homogeneous ( GTK_BOX ( box2 ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " prev " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_notebook_prev_page ) ,
sample_notebook ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " next " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_notebook_next_page ) ,
sample_notebook ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " rotate " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( rotate_notebook ) , sample_notebook ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkPanes
*/
void
toggle_resize ( GtkWidget * widget , GtkWidget * child )
{
GtkContainer * container = GTK_CONTAINER ( gtk_widget_get_parent ( child ) ) ;
2011-09-30 15:31:04 +00:00
GValue value = G_VALUE_INIT ;
2008-02-27 10:31:24 +00:00
g_value_init ( & value , G_TYPE_BOOLEAN ) ;
gtk_container_child_get_property ( container , child , " resize " , & value ) ;
g_value_set_boolean ( & value , ! g_value_get_boolean ( & value ) ) ;
gtk_container_child_set_property ( container , child , " resize " , & value ) ;
}
void
toggle_shrink ( GtkWidget * widget , GtkWidget * child )
{
GtkContainer * container = GTK_CONTAINER ( gtk_widget_get_parent ( child ) ) ;
2011-09-30 15:31:04 +00:00
GValue value = G_VALUE_INIT ;
2008-02-27 10:31:24 +00:00
g_value_init ( & value , G_TYPE_BOOLEAN ) ;
gtk_container_child_get_property ( container , child , " shrink " , & value ) ;
g_value_set_boolean ( & value , ! g_value_get_boolean ( & value ) ) ;
gtk_container_child_set_property ( container , child , " shrink " , & value ) ;
}
GtkWidget *
create_pane_options ( GtkPaned * paned ,
const gchar * frame_label ,
const gchar * label1 ,
const gchar * label2 )
{
2010-07-06 04:32:48 +00:00
GtkWidget * child1 , * child2 ;
2008-02-27 10:31:24 +00:00
GtkWidget * frame ;
2011-09-28 22:41:35 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * label ;
GtkWidget * check_button ;
2010-07-06 04:32:48 +00:00
child1 = gtk_paned_get_child1 ( paned ) ;
child2 = gtk_paned_get_child2 ( paned ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( frame_label ) ;
2011-09-28 22:41:35 +00:00
grid = gtk_grid_new ( ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , grid ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( label1 ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , label , 0 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
check_button = gtk_check_button_new_with_label ( " Resize " ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 0 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( toggle_resize ) ,
2010-07-06 04:32:48 +00:00
child1 ) ;
2008-02-27 10:31:24 +00:00
check_button = gtk_check_button_new_with_label ( " Shrink " ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 0 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ) ,
TRUE ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( toggle_shrink ) ,
2010-07-06 04:32:48 +00:00
child1 ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( label2 ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , label , 1 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
check_button = gtk_check_button_new_with_label ( " Resize " ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 1 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ) ,
TRUE ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( toggle_resize ) ,
2010-07-06 04:32:48 +00:00
child2 ) ;
2008-02-27 10:31:24 +00:00
check_button = gtk_check_button_new_with_label ( " Shrink " ) ;
2011-09-28 22:41:35 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check_button , 1 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ) ,
TRUE ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( toggle_shrink ) ,
2010-07-06 04:32:48 +00:00
child2 ) ;
2008-02-27 10:31:24 +00:00
return frame ;
}
void
create_panes ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * frame ;
GtkWidget * hpaned ;
GtkWidget * vpaned ;
GtkWidget * button ;
GtkWidget * vbox ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Panes " ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , vbox ) ;
2016-10-02 15:37:22 +00:00
2010-10-29 23:47:13 +00:00
vpaned = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , vpaned ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
hpaned = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_add1 ( GTK_PANED ( vpaned ) , hpaned ) ;
frame = gtk_frame_new ( NULL ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame ) , GTK_SHADOW_IN ) ;
gtk_widget_set_size_request ( frame , 60 , 60 ) ;
gtk_paned_add1 ( GTK_PANED ( hpaned ) , frame ) ;
button = gtk_button_new_with_label ( " Hi there " ) ;
gtk_container_add ( GTK_CONTAINER ( frame ) , button ) ;
frame = gtk_frame_new ( NULL ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame ) , GTK_SHADOW_IN ) ;
gtk_widget_set_size_request ( frame , 80 , 60 ) ;
gtk_paned_add2 ( GTK_PANED ( hpaned ) , frame ) ;
frame = gtk_frame_new ( NULL ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame ) , GTK_SHADOW_IN ) ;
gtk_widget_set_size_request ( frame , 60 , 80 ) ;
gtk_paned_add2 ( GTK_PANED ( vpaned ) , frame ) ;
/* Now create toggle buttons to control sizing */
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
create_pane_options ( GTK_PANED ( hpaned ) ,
" Horizontal " ,
" Left " ,
2017-04-21 20:34:36 +00:00
" Right " ) ) ;
2008-02-27 10:31:24 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) ,
create_pane_options ( GTK_PANED ( vpaned ) ,
" Vertical " ,
" Top " ,
2017-04-21 20:34:36 +00:00
" Bottom " ) ) ;
2008-02-27 10:31:24 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( vbox ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* Paned keyboard navigation
*/
static GtkWidget *
paned_keyboard_window1 ( GtkWidget * widget )
{
GtkWidget * window1 ;
GtkWidget * hpaned1 ;
GtkWidget * frame1 ;
GtkWidget * vbox1 ;
GtkWidget * button7 ;
GtkWidget * button8 ;
GtkWidget * button9 ;
GtkWidget * vpaned1 ;
GtkWidget * frame2 ;
GtkWidget * frame5 ;
GtkWidget * hbox1 ;
GtkWidget * button5 ;
GtkWidget * button6 ;
GtkWidget * frame3 ;
GtkWidget * frame4 ;
2011-09-28 03:21:29 +00:00
GtkWidget * grid1 ;
2008-02-27 10:31:24 +00:00
GtkWidget * button1 ;
GtkWidget * button2 ;
GtkWidget * button3 ;
GtkWidget * button4 ;
window1 = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title ( GTK_WINDOW ( window1 ) , " Basic paned navigation " ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window1 ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
hpaned1 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window1 ) , hpaned1 ) ;
frame1 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( hpaned1 ) , frame1 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame1 ) , GTK_SHADOW_IN ) ;
2010-10-31 17:07:20 +00:00
vbox1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame1 ) , vbox1 ) ;
button7 = gtk_button_new_with_label ( " button7 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox1 ) , button7 ) ;
2008-02-27 10:31:24 +00:00
button8 = gtk_button_new_with_label ( " button8 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox1 ) , button8 ) ;
2008-02-27 10:31:24 +00:00
button9 = gtk_button_new_with_label ( " button9 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox1 ) , button9 ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
vpaned1 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack2 ( GTK_PANED ( hpaned1 ) , vpaned1 , TRUE , TRUE ) ;
frame2 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned1 ) , frame2 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame2 ) , GTK_SHADOW_IN ) ;
frame5 = gtk_frame_new ( NULL ) ;
gtk_container_add ( GTK_CONTAINER ( frame2 ) , frame5 ) ;
2010-10-31 17:07:20 +00:00
hbox1 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame5 ) , hbox1 ) ;
button5 = gtk_button_new_with_label ( " button5 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox1 ) , button5 ) ;
2008-02-27 10:31:24 +00:00
button6 = gtk_button_new_with_label ( " button6 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox1 ) , button6 ) ;
2008-02-27 10:31:24 +00:00
frame3 = gtk_frame_new ( NULL ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned1 ) , frame3 , TRUE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame3 ) , GTK_SHADOW_IN ) ;
frame4 = gtk_frame_new ( " Buttons " ) ;
gtk_container_add ( GTK_CONTAINER ( frame3 ) , frame4 ) ;
2011-09-28 03:21:29 +00:00
grid1 = gtk_grid_new ( ) ;
gtk_container_add ( GTK_CONTAINER ( frame4 ) , grid1 ) ;
2008-02-27 10:31:24 +00:00
button1 = gtk_button_new_with_label ( " button1 " ) ;
2011-09-28 03:21:29 +00:00
gtk_grid_attach ( GTK_GRID ( grid1 ) , button1 , 0 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
button2 = gtk_button_new_with_label ( " button2 " ) ;
2011-09-28 03:21:29 +00:00
gtk_grid_attach ( GTK_GRID ( grid1 ) , button2 , 1 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
button3 = gtk_button_new_with_label ( " button3 " ) ;
2011-09-28 03:21:29 +00:00
gtk_grid_attach ( GTK_GRID ( grid1 ) , button3 , 0 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
button4 = gtk_button_new_with_label ( " button4 " ) ;
2011-09-28 03:21:29 +00:00
gtk_grid_attach ( GTK_GRID ( grid1 ) , button4 , 1 , 1 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
return window1 ;
}
static GtkWidget *
paned_keyboard_window2 ( GtkWidget * widget )
{
GtkWidget * window2 ;
GtkWidget * hpaned2 ;
GtkWidget * frame6 ;
GtkWidget * button13 ;
GtkWidget * hbox2 ;
GtkWidget * vpaned2 ;
GtkWidget * frame7 ;
GtkWidget * button12 ;
GtkWidget * frame8 ;
GtkWidget * button11 ;
GtkWidget * button10 ;
window2 = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title ( GTK_WINDOW ( window2 ) , " \" button 10 \" is not inside the horisontal pane " ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window2 ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
hpaned2 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window2 ) , hpaned2 ) ;
frame6 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( hpaned2 ) , frame6 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame6 ) , GTK_SHADOW_IN ) ;
button13 = gtk_button_new_with_label ( " button13 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame6 ) , button13 ) ;
2010-10-31 17:07:20 +00:00
hbox2 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack2 ( GTK_PANED ( hpaned2 ) , hbox2 , TRUE , TRUE ) ;
2010-10-29 23:47:13 +00:00
vpaned2 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox2 ) , vpaned2 ) ;
2008-02-27 10:31:24 +00:00
frame7 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned2 ) , frame7 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame7 ) , GTK_SHADOW_IN ) ;
button12 = gtk_button_new_with_label ( " button12 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame7 ) , button12 ) ;
frame8 = gtk_frame_new ( NULL ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned2 ) , frame8 , TRUE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame8 ) , GTK_SHADOW_IN ) ;
button11 = gtk_button_new_with_label ( " button11 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame8 ) , button11 ) ;
button10 = gtk_button_new_with_label ( " button10 " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox2 ) , button10 ) ;
2008-02-27 10:31:24 +00:00
return window2 ;
}
static GtkWidget *
paned_keyboard_window3 ( GtkWidget * widget )
{
GtkWidget * window3 ;
GtkWidget * vbox2 ;
GtkWidget * label1 ;
GtkWidget * hpaned3 ;
GtkWidget * frame9 ;
GtkWidget * button14 ;
GtkWidget * hpaned4 ;
GtkWidget * frame10 ;
GtkWidget * button15 ;
GtkWidget * hpaned5 ;
GtkWidget * frame11 ;
GtkWidget * button16 ;
GtkWidget * frame12 ;
GtkWidget * button17 ;
window3 = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
g_object_set_data ( G_OBJECT ( window3 ) , " window3 " , window3 ) ;
gtk_window_set_title ( GTK_WINDOW ( window3 ) , " Nested panes " ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window3 ) ,
gtk_widget_get_display ( widget ) ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window3 ) , vbox2 ) ;
label1 = gtk_label_new ( " Three panes nested inside each other " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , label1 ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
hpaned3 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , hpaned3 ) ;
2008-02-27 10:31:24 +00:00
frame9 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( hpaned3 ) , frame9 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame9 ) , GTK_SHADOW_IN ) ;
button14 = gtk_button_new_with_label ( " button14 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame9 ) , button14 ) ;
2010-10-29 23:47:13 +00:00
hpaned4 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack2 ( GTK_PANED ( hpaned3 ) , hpaned4 , TRUE , TRUE ) ;
frame10 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( hpaned4 ) , frame10 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame10 ) , GTK_SHADOW_IN ) ;
button15 = gtk_button_new_with_label ( " button15 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame10 ) , button15 ) ;
2010-10-29 23:47:13 +00:00
hpaned5 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack2 ( GTK_PANED ( hpaned4 ) , hpaned5 , TRUE , TRUE ) ;
frame11 = gtk_frame_new ( NULL ) ;
gtk_paned_pack1 ( GTK_PANED ( hpaned5 ) , frame11 , FALSE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame11 ) , GTK_SHADOW_IN ) ;
button16 = gtk_button_new_with_label ( " button16 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame11 ) , button16 ) ;
frame12 = gtk_frame_new ( NULL ) ;
gtk_paned_pack2 ( GTK_PANED ( hpaned5 ) , frame12 , TRUE , TRUE ) ;
gtk_frame_set_shadow_type ( GTK_FRAME ( frame12 ) , GTK_SHADOW_IN ) ;
button17 = gtk_button_new_with_label ( " button17 " ) ;
gtk_container_add ( GTK_CONTAINER ( frame12 ) , button17 ) ;
return window3 ;
}
static GtkWidget *
paned_keyboard_window4 ( GtkWidget * widget )
{
GtkWidget * window4 ;
GtkWidget * vbox3 ;
GtkWidget * label2 ;
GtkWidget * hpaned6 ;
GtkWidget * vpaned3 ;
GtkWidget * button19 ;
GtkWidget * button18 ;
GtkWidget * hbox3 ;
GtkWidget * vpaned4 ;
GtkWidget * button21 ;
GtkWidget * button20 ;
GtkWidget * vpaned5 ;
GtkWidget * button23 ;
GtkWidget * button22 ;
GtkWidget * vpaned6 ;
GtkWidget * button25 ;
GtkWidget * button24 ;
window4 = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
g_object_set_data ( G_OBJECT ( window4 ) , " window4 " , window4 ) ;
gtk_window_set_title ( GTK_WINDOW ( window4 ) , " window4 " ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window4 ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox3 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window4 ) , vbox3 ) ;
label2 = gtk_label_new ( " Widget tree: \n \n hpaned \n - vpaned \n - hbox \n - vpaned \n - vpaned \n - vpaned \n " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox3 ) , label2 ) ;
2008-02-27 10:31:24 +00:00
gtk_label_set_justify ( GTK_LABEL ( label2 ) , GTK_JUSTIFY_LEFT ) ;
2010-10-29 23:47:13 +00:00
hpaned6 = gtk_paned_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox3 ) , hpaned6 ) ;
2008-02-27 10:31:24 +00:00
2010-10-29 23:47:13 +00:00
vpaned3 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack1 ( GTK_PANED ( hpaned6 ) , vpaned3 , FALSE , TRUE ) ;
button19 = gtk_button_new_with_label ( " button19 " ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned3 ) , button19 , FALSE , TRUE ) ;
button18 = gtk_button_new_with_label ( " button18 " ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned3 ) , button18 , TRUE , TRUE ) ;
2010-10-31 17:07:20 +00:00
hbox3 = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_paned_pack2 ( GTK_PANED ( hpaned6 ) , hbox3 , TRUE , TRUE ) ;
2010-10-29 23:47:13 +00:00
vpaned4 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox3 ) , vpaned4 ) ;
2008-02-27 10:31:24 +00:00
button21 = gtk_button_new_with_label ( " button21 " ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned4 ) , button21 , FALSE , TRUE ) ;
button20 = gtk_button_new_with_label ( " button20 " ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned4 ) , button20 , TRUE , TRUE ) ;
2010-10-29 23:47:13 +00:00
vpaned5 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox3 ) , vpaned5 ) ;
2008-02-27 10:31:24 +00:00
button23 = gtk_button_new_with_label ( " button23 " ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned5 ) , button23 , FALSE , TRUE ) ;
button22 = gtk_button_new_with_label ( " button22 " ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned5 ) , button22 , TRUE , TRUE ) ;
2010-10-29 23:47:13 +00:00
vpaned6 = gtk_paned_new ( GTK_ORIENTATION_VERTICAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox3 ) , vpaned6 ) ;
2008-02-27 10:31:24 +00:00
button25 = gtk_button_new_with_label ( " button25 " ) ;
gtk_paned_pack1 ( GTK_PANED ( vpaned6 ) , button25 , FALSE , TRUE ) ;
button24 = gtk_button_new_with_label ( " button24 " ) ;
gtk_paned_pack2 ( GTK_PANED ( vpaned6 ) , button24 , TRUE , TRUE ) ;
return window4 ;
}
static void
create_paned_keyboard_navigation ( GtkWidget * widget )
{
static GtkWidget * window1 = NULL ;
static GtkWidget * window2 = NULL ;
static GtkWidget * window3 = NULL ;
static GtkWidget * window4 = NULL ;
if ( window1 & &
2017-10-31 06:41:15 +00:00
( gtk_widget_get_display ( window1 ) ! = gtk_widget_get_display ( widget ) ) )
2008-02-27 10:31:24 +00:00
{
gtk_widget_destroy ( window1 ) ;
gtk_widget_destroy ( window2 ) ;
gtk_widget_destroy ( window3 ) ;
gtk_widget_destroy ( window4 ) ;
}
if ( ! window1 )
{
window1 = paned_keyboard_window1 ( widget ) ;
g_signal_connect ( window1 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window1 ) ;
}
if ( ! window2 )
{
window2 = paned_keyboard_window2 ( widget ) ;
g_signal_connect ( window2 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window2 ) ;
}
if ( ! window3 )
{
window3 = paned_keyboard_window3 ( widget ) ;
g_signal_connect ( window3 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window3 ) ;
}
if ( ! window4 )
{
window4 = paned_keyboard_window4 ( widget ) ;
g_signal_connect ( window4 , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window4 ) ;
}
2010-03-01 06:47:38 +00:00
if ( gtk_widget_get_visible ( window1 ) )
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( GTK_WIDGET ( window1 ) ) ;
else
2017-01-19 09:02:04 +00:00
gtk_widget_show ( GTK_WIDGET ( window1 ) ) ;
2008-02-27 10:31:24 +00:00
2010-03-01 06:47:38 +00:00
if ( gtk_widget_get_visible ( window2 ) )
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( GTK_WIDGET ( window2 ) ) ;
else
2017-01-19 09:02:04 +00:00
gtk_widget_show ( GTK_WIDGET ( window2 ) ) ;
2008-02-27 10:31:24 +00:00
2010-03-01 06:47:38 +00:00
if ( gtk_widget_get_visible ( window3 ) )
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( GTK_WIDGET ( window3 ) ) ;
else
2017-01-19 09:02:04 +00:00
gtk_widget_show ( GTK_WIDGET ( window3 ) ) ;
2008-02-27 10:31:24 +00:00
2010-03-01 06:47:38 +00:00
if ( gtk_widget_get_visible ( window4 ) )
2008-02-27 10:31:24 +00:00
gtk_widget_destroy ( GTK_WIDGET ( window4 ) ) ;
else
2017-01-19 09:02:04 +00:00
gtk_widget_show ( GTK_WIDGET ( window4 ) ) ;
2008-02-27 10:31:24 +00:00
}
/*
* WM Hints demo
*/
void
create_wmhints ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * label ;
GtkWidget * separator ;
GtkWidget * button ;
GtkWidget * box1 ;
GtkWidget * box2 ;
2018-03-20 10:40:08 +00:00
GdkSurface * gdk_surface ;
2010-08-12 02:39:28 +00:00
GdkPixbuf * pixbuf ;
2017-10-23 11:43:50 +00:00
cairo_surface_t * surface ;
2010-08-12 02:39:28 +00:00
GList * list ;
2008-02-27 10:31:24 +00:00
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " WM Hints " ) ;
gtk_widget_realize ( window ) ;
2010-08-15 22:33:57 +00:00
2018-03-20 14:21:12 +00:00
gdk_surface = gtk_widget_get_surface ( window ) ;
2010-08-06 20:37:34 +00:00
2010-08-12 02:39:28 +00:00
pixbuf = gdk_pixbuf_new_from_xpm_data ( ( const char * * ) openfile ) ;
2017-10-23 11:43:50 +00:00
surface = gdk_cairo_surface_create_from_pixbuf ( pixbuf , 1 , NULL ) ;
2010-08-15 22:33:57 +00:00
2017-10-23 11:43:50 +00:00
list = g_list_prepend ( NULL , surface ) ;
gtk_window_set_icon_list ( GTK_WINDOW ( window ) , list ) ;
2016-10-02 15:37:22 +00:00
2010-08-12 02:39:28 +00:00
g_list_free ( list ) ;
2017-10-23 11:43:50 +00:00
cairo_surface_destroy ( surface ) ;
2010-08-12 02:39:28 +00:00
g_object_unref ( pixbuf ) ;
2010-08-15 22:33:57 +00:00
2018-03-20 10:40:08 +00:00
gdk_surface_set_icon_name ( gdk_surface , " WMHints Test Icon " ) ;
2016-10-02 15:37:22 +00:00
2018-03-20 10:40:08 +00:00
gdk_surface_set_decorations ( gdk_surface , GDK_DECOR_ALL | GDK_DECOR_MENU ) ;
gdk_surface_set_functions ( gdk_surface , GDK_FUNC_ALL | GDK_FUNC_RESIZE ) ;
2016-10-02 15:37:22 +00:00
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
gtk_widget_show ( box1 ) ;
label = gtk_label_new ( " Try iconizing me! " ) ;
gtk_widget_set_size_request ( label , 150 , 50 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , label ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( label ) ;
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( separator ) ;
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
gtk_widget_show ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* Window state tracking
*/
2017-12-15 03:09:13 +00:00
static void
2018-03-20 11:05:26 +00:00
surface_state_callback ( GdkSurface * window ,
2017-12-15 03:09:13 +00:00
GParamSpec * pspec ,
GtkWidget * label )
2008-02-27 10:31:24 +00:00
{
gchar * msg ;
2018-03-20 10:40:08 +00:00
GdkSurfaceState new_state ;
2008-02-27 10:31:24 +00:00
2018-03-20 10:40:08 +00:00
new_state = gdk_surface_get_state ( window ) ;
2017-12-15 03:09:13 +00:00
msg = g_strconcat ( ( const char * ) g_object_get_data ( G_OBJECT ( label ) , " title " ) , " : " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_WITHDRAWN ) ?
2008-02-27 10:31:24 +00:00
" withdrawn " : " not withdrawn " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_ICONIFIED ) ?
2008-02-27 10:31:24 +00:00
" iconified " : " not iconified " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_STICKY ) ?
2008-02-27 10:31:24 +00:00
" sticky " : " not sticky " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_MAXIMIZED ) ?
2008-02-27 10:31:24 +00:00
" maximized " : " not maximized " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_FULLSCREEN ) ?
2017-12-15 03:09:13 +00:00
" fullscreen " : " not fullscreen " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_ABOVE ) ?
2008-02-27 10:31:24 +00:00
" above " : " not above " , " , " ,
2018-03-20 10:40:08 +00:00
( new_state & GDK_SURFACE_STATE_BELOW ) ?
2008-02-27 10:31:24 +00:00
" below " : " not below " , " , " ,
NULL ) ;
2017-12-15 03:09:13 +00:00
2008-02-27 10:31:24 +00:00
gtk_label_set_text ( GTK_LABEL ( label ) , msg ) ;
g_free ( msg ) ;
}
static GtkWidget *
tracking_label ( GtkWidget * window )
{
GtkWidget * label ;
GtkWidget * hbox ;
GtkWidget * button ;
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect_object ( hbox ,
" destroy " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ,
G_CONNECT_SWAPPED ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " <no window state events received> " ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2016-10-02 15:37:22 +00:00
2017-12-15 03:09:13 +00:00
g_object_set_data ( G_OBJECT ( label ) , " title " , ( gpointer ) gtk_window_get_title ( GTK_WINDOW ( window ) ) ) ;
2018-03-20 14:21:12 +00:00
g_signal_connect ( gtk_widget_get_surface ( window ) , " notify::state " ,
2018-03-20 11:05:26 +00:00
G_CALLBACK ( surface_state_callback ) ,
2017-12-15 03:09:13 +00:00
label ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Deiconify " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_deiconify ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Iconify " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_iconify ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Fullscreen " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_fullscreen ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unfullscreen " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_unfullscreen ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Present " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_present ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Show " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_widget_show ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( hbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( hbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
return hbox ;
}
void
keep_window_above ( GtkToggleButton * togglebutton , gpointer data )
{
GtkWidget * button = g_object_get_data ( G_OBJECT ( togglebutton ) , " radio " ) ;
gtk_window_set_keep_above ( GTK_WINDOW ( data ) ,
gtk_toggle_button_get_active ( togglebutton ) ) ;
if ( gtk_toggle_button_get_active ( togglebutton ) )
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , FALSE ) ;
}
void
keep_window_below ( GtkToggleButton * togglebutton , gpointer data )
{
GtkWidget * button = g_object_get_data ( G_OBJECT ( togglebutton ) , " radio " ) ;
gtk_window_set_keep_below ( GTK_WINDOW ( data ) ,
gtk_toggle_button_get_active ( togglebutton ) ) ;
if ( gtk_toggle_button_get_active ( togglebutton ) )
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , FALSE ) ;
}
static GtkWidget *
get_state_controls ( GtkWidget * window )
{
GtkWidget * vbox ;
GtkWidget * button ;
GtkWidget * button_above ;
GtkWidget * button_below ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Stick " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_stick ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unstick " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_unstick ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Maximize " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_maximize ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unmaximize " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_unmaximize ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Iconify " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_iconify ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Fullscreen " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_fullscreen ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unfullscreen " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_window_unfullscreen ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button_above = gtk_toggle_button_new_with_label ( " Keep above " ) ;
g_signal_connect ( button_above ,
" toggled " ,
G_CALLBACK ( keep_window_above ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button_above ) ;
2008-02-27 10:31:24 +00:00
button_below = gtk_toggle_button_new_with_label ( " Keep below " ) ;
g_signal_connect ( button_below ,
" toggled " ,
G_CALLBACK ( keep_window_below ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button_below ) ;
2008-02-27 10:31:24 +00:00
g_object_set_data ( G_OBJECT ( button_above ) , " radio " , button_below ) ;
g_object_set_data ( G_OBJECT ( button_below ) , " radio " , button_above ) ;
button = gtk_button_new_with_label ( " Hide (withdraw) " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_widget_hide ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( vbox ) ;
2008-02-27 10:31:24 +00:00
return vbox ;
}
void
2018-03-20 11:05:26 +00:00
create_surface_states ( GtkWidget * widget )
2008-02-27 10:31:24 +00:00
{
static GtkWidget * window = NULL ;
GtkWidget * label ;
GtkWidget * box1 ;
GtkWidget * iconified ;
GtkWidget * normal ;
GtkWidget * controls ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Window states " ) ;
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
iconified = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( iconified ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect_object ( iconified , " destroy " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ,
G_CONNECT_SWAPPED ) ;
gtk_window_iconify ( GTK_WINDOW ( iconified ) ) ;
gtk_window_set_title ( GTK_WINDOW ( iconified ) , " Iconified initially " ) ;
controls = get_state_controls ( iconified ) ;
gtk_container_add ( GTK_CONTAINER ( iconified ) , controls ) ;
normal = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( normal ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect_object ( normal , " destroy " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ,
G_CONNECT_SWAPPED ) ;
gtk_window_set_title ( GTK_WINDOW ( normal ) , " Deiconified initially " ) ;
controls = get_state_controls ( normal ) ;
gtk_container_add ( GTK_CONTAINER ( normal ) , controls ) ;
2017-12-15 03:09:13 +00:00
gtk_widget_realize ( iconified ) ;
gtk_widget_realize ( normal ) ;
2008-02-27 10:31:24 +00:00
label = tracking_label ( iconified ) ;
gtk_container_add ( GTK_CONTAINER ( box1 ) , label ) ;
label = tracking_label ( normal ) ;
gtk_container_add ( GTK_CONTAINER ( box1 ) , label ) ;
2017-01-19 09:02:04 +00:00
gtk_widget_show ( iconified ) ;
gtk_widget_show ( normal ) ;
gtk_widget_show ( box1 ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* Window sizing
*/
static gint
configure_event_callback ( GtkWidget * widget ,
2018-01-01 23:18:11 +00:00
GdkEvent * event ,
2008-02-27 10:31:24 +00:00
gpointer data )
{
GtkWidget * label = data ;
gchar * msg ;
gint x , y ;
gtk_window_get_position ( GTK_WINDOW ( widget ) , & x , & y ) ;
msg = g_strdup_printf ( " event: %d,%d %d x %d \n "
" position: %d, %d " ,
2017-08-28 23:11:14 +00:00
0 , 0 , 0 , 0 , // FIXME
2008-02-27 10:31:24 +00:00
x , y ) ;
gtk_label_set_text ( GTK_LABEL ( label ) , msg ) ;
g_free ( msg ) ;
return FALSE ;
}
static void
get_ints ( GtkWidget * window ,
gint * a ,
gint * b )
{
GtkWidget * spin1 ;
GtkWidget * spin2 ;
spin1 = g_object_get_data ( G_OBJECT ( window ) , " spin1 " ) ;
spin2 = g_object_get_data ( G_OBJECT ( window ) , " spin2 " ) ;
* a = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON ( spin1 ) ) ;
* b = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON ( spin2 ) ) ;
}
static void
set_size_callback ( GtkWidget * widget ,
gpointer data )
{
gint w , h ;
get_ints ( data , & w , & h ) ;
gtk_window_resize ( GTK_WINDOW ( g_object_get_data ( data , " target " ) ) , w , h ) ;
}
static void
unset_default_size_callback ( GtkWidget * widget ,
gpointer data )
{
gtk_window_set_default_size ( g_object_get_data ( data , " target " ) ,
- 1 , - 1 ) ;
}
static void
set_default_size_callback ( GtkWidget * widget ,
gpointer data )
{
gint w , h ;
get_ints ( data , & w , & h ) ;
gtk_window_set_default_size ( g_object_get_data ( data , " target " ) ,
w , h ) ;
}
static void
unset_size_request_callback ( GtkWidget * widget ,
gpointer data )
{
gtk_widget_set_size_request ( g_object_get_data ( data , " target " ) ,
- 1 , - 1 ) ;
}
static void
set_size_request_callback ( GtkWidget * widget ,
gpointer data )
{
gint w , h ;
get_ints ( data , & w , & h ) ;
gtk_widget_set_size_request ( g_object_get_data ( data , " target " ) ,
w , h ) ;
}
static void
set_location_callback ( GtkWidget * widget ,
gpointer data )
{
gint x , y ;
get_ints ( data , & x , & y ) ;
gtk_window_move ( g_object_get_data ( data , " target " ) , x , y ) ;
}
static void
move_to_position_callback ( GtkWidget * widget ,
gpointer data )
{
gint x , y ;
GtkWindow * window ;
window = g_object_get_data ( data , " target " ) ;
gtk_window_get_position ( window , & x , & y ) ;
gtk_window_move ( window , x , y ) ;
}
static void
2010-08-07 15:07:17 +00:00
resizable_callback ( GtkWidget * widget ,
2008-02-27 10:31:24 +00:00
gpointer data )
{
g_object_set ( g_object_get_data ( data , " target " ) ,
2010-10-19 16:46:40 +00:00
" resizable " , gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ,
2008-02-27 10:31:24 +00:00
NULL ) ;
}
static void
gravity_selected ( GtkWidget * widget ,
gpointer data )
{
gtk_window_set_gravity ( GTK_WINDOW ( g_object_get_data ( data , " target " ) ) ,
2010-03-26 16:55:07 +00:00
gtk_combo_box_get_active ( GTK_COMBO_BOX ( widget ) ) + GDK_GRAVITY_NORTH_WEST ) ;
2008-02-27 10:31:24 +00:00
}
static void
pos_selected ( GtkWidget * widget ,
gpointer data )
{
gtk_window_set_position ( GTK_WINDOW ( g_object_get_data ( data , " target " ) ) ,
2010-03-26 16:55:07 +00:00
gtk_combo_box_get_active ( GTK_COMBO_BOX ( widget ) ) + GTK_WIN_POS_NONE ) ;
2008-02-27 10:31:24 +00:00
}
static GtkWidget *
window_controls ( GtkWidget * window )
{
GtkWidget * control_window ;
GtkWidget * label ;
GtkWidget * vbox ;
GtkWidget * button ;
GtkWidget * spin ;
2011-01-05 22:28:55 +00:00
GtkAdjustment * adjustment ;
2008-02-27 10:31:24 +00:00
GtkWidget * om ;
gint i ;
control_window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( control_window ) ,
gtk_widget_get_display ( window ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( control_window ) , " Size controls " ) ;
g_object_set_data ( G_OBJECT ( control_window ) ,
" target " ,
window ) ;
g_signal_connect_object ( control_window ,
" destroy " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ,
G_CONNECT_SWAPPED ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( control_window ) , vbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " <no configure events> " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , label ) ;
2016-10-02 15:37:22 +00:00
2018-01-01 23:18:11 +00:00
g_signal_connect ( window , " event " , G_CALLBACK ( configure_event_callback ) , label ) ;
2008-02-27 10:31:24 +00:00
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 10.0 , - 2000.0 , 2000.0 , 1.0 , 5.0 , 0.0 ) ;
spin = gtk_spin_button_new ( adjustment , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , spin ) ;
2008-02-27 10:31:24 +00:00
g_object_set_data ( G_OBJECT ( control_window ) , " spin1 " , spin ) ;
2011-01-05 22:28:55 +00:00
adjustment = gtk_adjustment_new ( 10.0 , - 2000.0 , 2000.0 , 1.0 , 5.0 , 0.0 ) ;
spin = gtk_spin_button_new ( adjustment , 0 , 0 ) ;
2008-02-27 10:31:24 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , spin ) ;
2008-02-27 10:31:24 +00:00
g_object_set_data ( G_OBJECT ( control_window ) , " spin2 " , spin ) ;
button = gtk_button_new_with_label ( " Queue resize " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_widget_queue_resize ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Resize " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( set_size_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Set default size " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( set_default_size_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unset default size " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( unset_default_size_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Set size request " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( set_size_request_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Unset size request " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( unset_size_request_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Move " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( set_location_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_label ( " Move to current position " ) ;
g_signal_connect ( button ,
" clicked " ,
G_CALLBACK ( move_to_position_callback ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
2010-08-07 15:07:17 +00:00
button = gtk_check_button_new_with_label ( " Allow resize " ) ;
2008-02-27 10:31:24 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ) , TRUE ) ;
g_signal_connect ( button ,
" toggled " ,
2010-08-07 15:07:17 +00:00
G_CALLBACK ( resizable_callback ) ,
2008-02-27 10:31:24 +00:00
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " _Show " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_widget_show ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " _Hide " ) ;
g_signal_connect_object ( button ,
" clicked " ,
G_CALLBACK ( gtk_widget_hide ) ,
window ,
G_CONNECT_SWAPPED ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , button ) ;
2010-10-02 16:19:46 +00:00
om = gtk_combo_box_text_new ( ) ;
2008-02-27 10:31:24 +00:00
i = 0 ;
while ( i < 10 )
{
static gchar * names [ ] = {
" GDK_GRAVITY_NORTH_WEST " ,
" GDK_GRAVITY_NORTH " ,
" GDK_GRAVITY_NORTH_EAST " ,
" GDK_GRAVITY_WEST " ,
" GDK_GRAVITY_CENTER " ,
" GDK_GRAVITY_EAST " ,
" GDK_GRAVITY_SOUTH_WEST " ,
" GDK_GRAVITY_SOUTH " ,
" GDK_GRAVITY_SOUTH_EAST " ,
" GDK_GRAVITY_STATIC " ,
NULL
} ;
g_assert ( names [ i ] ) ;
2010-10-02 16:19:46 +00:00
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( om ) , names [ i ] ) ;
2008-02-27 10:31:24 +00:00
+ + i ;
}
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
g_signal_connect ( om ,
" changed " ,
G_CALLBACK ( gravity_selected ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , om ) ;
2008-02-27 10:31:24 +00:00
2010-10-02 16:19:46 +00:00
om = gtk_combo_box_text_new ( ) ;
2008-02-27 10:31:24 +00:00
i = 0 ;
while ( i < 5 )
{
static gchar * names [ ] = {
" GTK_WIN_POS_NONE " ,
" GTK_WIN_POS_CENTER " ,
" GTK_WIN_POS_MOUSE " ,
" GTK_WIN_POS_CENTER_ALWAYS " ,
" GTK_WIN_POS_CENTER_ON_PARENT " ,
NULL
} ;
g_assert ( names [ i ] ) ;
2010-10-02 16:19:46 +00:00
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( om ) , names [ i ] ) ;
2008-02-27 10:31:24 +00:00
+ + i ;
}
g_signal_connect ( om ,
" changed " ,
G_CALLBACK ( pos_selected ) ,
control_window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_end ( GTK_BOX ( vbox ) , om ) ;
2016-10-02 15:37:22 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( vbox ) ;
2016-10-02 15:37:22 +00:00
2008-02-27 10:31:24 +00:00
return control_window ;
}
void
create_window_sizing ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
static GtkWidget * target_window = NULL ;
if ( ! target_window )
{
GtkWidget * label ;
target_window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( target_window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( NULL ) ;
gtk_label_set_markup ( GTK_LABEL ( label ) , " <span foreground= \" purple \" ><big>Window being resized</big></span> \n Blah blah blah blah \n blah blah blah \n blah blah blah blah blah " ) ;
gtk_container_add ( GTK_CONTAINER ( target_window ) , label ) ;
gtk_widget_show ( label ) ;
g_signal_connect ( target_window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& target_window ) ;
window = window_controls ( target_window ) ;
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( target_window ) , " Window to size " ) ;
}
/* don't show target window by default, we want to allow testing
* of behavior on first show .
*/
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* GtkProgressBar
*/
typedef struct _ProgressData {
GtkWidget * window ;
GtkWidget * pbar ;
GtkWidget * block_spin ;
GtkWidget * x_align_spin ;
GtkWidget * y_align_spin ;
GtkWidget * step_spin ;
GtkWidget * act_blocks_spin ;
GtkWidget * label ;
GtkWidget * omenu1 ;
GtkWidget * elmenu ;
GtkWidget * omenu2 ;
GtkWidget * entry ;
int timer ;
2010-03-26 16:27:09 +00:00
gboolean activity ;
2008-02-27 10:31:24 +00:00
} ProgressData ;
2010-03-26 16:27:09 +00:00
gboolean
2008-02-27 10:31:24 +00:00
progress_timeout ( gpointer data )
{
2010-03-26 16:27:09 +00:00
ProgressData * pdata = data ;
2008-02-27 10:31:24 +00:00
gdouble new_val ;
2010-04-26 00:08:04 +00:00
gchar * text ;
2008-02-27 10:31:24 +00:00
2010-03-26 16:27:09 +00:00
if ( pdata - > activity )
{
gtk_progress_bar_pulse ( GTK_PROGRESS_BAR ( pdata - > pbar ) ) ;
2010-04-26 00:08:04 +00:00
text = g_strdup_printf ( " %s " , " ??? " ) ;
2010-03-26 16:27:09 +00:00
}
2010-04-26 00:08:04 +00:00
else
{
new_val = gtk_progress_bar_get_fraction ( GTK_PROGRESS_BAR ( pdata - > pbar ) ) + 0.01 ;
if ( new_val > 1.00 )
new_val = 0.00 ;
gtk_progress_bar_set_fraction ( GTK_PROGRESS_BAR ( pdata - > pbar ) , new_val ) ;
2008-02-27 10:31:24 +00:00
2010-04-26 00:08:04 +00:00
text = g_strdup_printf ( " %.0f%% " , 100 * new_val ) ;
}
2008-02-27 10:31:24 +00:00
2010-04-26 00:08:04 +00:00
gtk_label_set_text ( GTK_LABEL ( pdata - > label ) , text ) ;
g_free ( text ) ;
2008-02-27 10:31:24 +00:00
return TRUE ;
}
static void
destroy_progress ( GtkWidget * widget ,
ProgressData * * pdata )
{
2011-03-31 13:09:07 +00:00
if ( ( * pdata ) - > timer )
{
g_source_remove ( ( * pdata ) - > timer ) ;
( * pdata ) - > timer = 0 ;
}
2008-02-27 10:31:24 +00:00
( * pdata ) - > window = NULL ;
g_free ( * pdata ) ;
* pdata = NULL ;
}
static void
progressbar_toggle_orientation ( GtkWidget * widget , gpointer data )
{
ProgressData * pdata ;
gint i ;
pdata = ( ProgressData * ) data ;
2010-03-02 04:19:28 +00:00
if ( ! gtk_widget_get_mapped ( widget ) )
2008-02-27 10:31:24 +00:00
return ;
2010-03-26 16:55:07 +00:00
i = gtk_combo_box_get_active ( GTK_COMBO_BOX ( widget ) ) ;
2008-02-27 10:31:24 +00:00
2010-09-02 03:29:53 +00:00
if ( i = = 0 | | i = = 1 )
2010-09-02 03:26:19 +00:00
gtk_orientable_set_orientation ( GTK_ORIENTABLE ( pdata - > pbar ) , GTK_ORIENTATION_HORIZONTAL ) ;
else
gtk_orientable_set_orientation ( GTK_ORIENTABLE ( pdata - > pbar ) , GTK_ORIENTATION_VERTICAL ) ;
2010-09-02 03:29:53 +00:00
if ( i = = 1 | | i = = 2 )
2010-09-02 03:26:19 +00:00
gtk_progress_bar_set_inverted ( GTK_PROGRESS_BAR ( pdata - > pbar ) , TRUE ) ;
else
gtk_progress_bar_set_inverted ( GTK_PROGRESS_BAR ( pdata - > pbar ) , FALSE ) ;
2008-02-27 10:31:24 +00:00
}
static void
toggle_show_text ( GtkWidget * widget , ProgressData * pdata )
{
2010-04-26 00:08:04 +00:00
gboolean active ;
active = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ;
2010-06-09 04:29:55 +00:00
gtk_progress_bar_set_show_text ( GTK_PROGRESS_BAR ( pdata - > pbar ) , active ) ;
2008-02-27 10:31:24 +00:00
}
static void
progressbar_toggle_ellipsize ( GtkWidget * widget ,
gpointer data )
{
ProgressData * pdata = data ;
2010-01-07 15:47:35 +00:00
if ( gtk_widget_is_drawable ( widget ) )
2008-02-27 10:31:24 +00:00
{
2010-03-26 16:55:07 +00:00
gint i = gtk_combo_box_get_active ( GTK_COMBO_BOX ( widget ) ) ;
2008-02-27 10:31:24 +00:00
gtk_progress_bar_set_ellipsize ( GTK_PROGRESS_BAR ( pdata - > pbar ) , i ) ;
}
}
static void
toggle_activity_mode ( GtkWidget * widget , ProgressData * pdata )
{
2010-03-26 16:27:09 +00:00
pdata - > activity = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) ;
2008-02-27 10:31:24 +00:00
}
2011-03-31 13:09:07 +00:00
static void
toggle_running ( GtkWidget * widget , ProgressData * pdata )
{
if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( widget ) ) )
{
if ( pdata - > timer = = 0 )
pdata - > timer = g_timeout_add ( 100 , ( GSourceFunc ) progress_timeout , pdata ) ;
}
else
{
if ( pdata - > timer ! = 0 )
{
g_source_remove ( pdata - > timer ) ;
pdata - > timer = 0 ;
}
}
}
2008-02-27 10:31:24 +00:00
static void
entry_changed ( GtkWidget * widget , ProgressData * pdata )
{
2010-03-26 16:27:09 +00:00
gtk_progress_bar_set_text ( GTK_PROGRESS_BAR ( pdata - > pbar ) ,
2008-02-27 10:31:24 +00:00
gtk_entry_get_text ( GTK_ENTRY ( pdata - > entry ) ) ) ;
}
void
create_progress_bar ( GtkWidget * widget )
{
2014-04-10 14:48:13 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * vbox ;
GtkWidget * vbox2 ;
GtkWidget * hbox ;
GtkWidget * check ;
GtkWidget * frame ;
2011-09-28 17:40:11 +00:00
GtkWidget * grid ;
2008-02-27 10:31:24 +00:00
GtkWidget * label ;
static ProgressData * pdata = NULL ;
static gchar * items1 [ ] =
{
" Left-Right " ,
" Right-Left " ,
" Bottom-Top " ,
" Top-Bottom "
} ;
2010-03-26 16:27:09 +00:00
static char * ellipsize_items [ ] = {
2008-02-27 10:31:24 +00:00
" None " , // PANGO_ELLIPSIZE_NONE,
" Start " , // PANGO_ELLIPSIZE_START,
" Middle " , // PANGO_ELLIPSIZE_MIDDLE,
" End " , // PANGO_ELLIPSIZE_END
} ;
if ( ! pdata )
pdata = g_new0 ( ProgressData , 1 ) ;
if ( ! pdata - > window )
{
pdata - > window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( pdata - > window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_resizable ( GTK_WINDOW ( pdata - > window ) , TRUE ) ;
g_signal_connect ( pdata - > window , " destroy " ,
G_CALLBACK ( destroy_progress ) ,
& pdata ) ;
pdata - > timer = 0 ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( pdata - > window ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( pdata - > window ) , " GtkProgressBar " ) ;
2010-10-31 17:07:20 +00:00
vbox = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , vbox ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Progress " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , vbox2 ) ;
2010-04-26 00:08:04 +00:00
pdata - > pbar = gtk_progress_bar_new ( ) ;
gtk_progress_bar_set_ellipsize ( GTK_PROGRESS_BAR ( pdata - > pbar ) ,
PANGO_ELLIPSIZE_MIDDLE ) ;
2012-12-20 18:53:04 +00:00
gtk_widget_set_halign ( pdata - > pbar , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( pdata - > pbar , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , pdata - > pbar ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
2012-12-20 18:53:04 +00:00
gtk_widget_set_halign ( hbox , GTK_ALIGN_CENTER ) ;
gtk_widget_set_valign ( hbox , GTK_ALIGN_CENTER ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , hbox ) ;
2016-10-02 15:37:22 +00:00
label = gtk_label_new ( " Label updated by user : " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2008-02-27 10:31:24 +00:00
pdata - > label = gtk_label_new ( " " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , pdata - > label ) ;
2008-02-27 10:31:24 +00:00
frame = gtk_frame_new ( " Options " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , frame ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
vbox2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( frame ) , vbox2 ) ;
2011-09-28 17:40:11 +00:00
grid = gtk_grid_new ( ) ;
gtk_grid_set_row_spacing ( GTK_GRID ( grid ) , 10 ) ;
gtk_grid_set_column_spacing ( GTK_GRID ( grid ) , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox2 ) , grid ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " Orientation : " ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , label , 0 , 0 , 1 , 1 ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2008-02-27 10:31:24 +00:00
pdata - > omenu1 = build_option_menu ( items1 , 4 , 0 ,
progressbar_toggle_orientation ,
pdata ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , pdata - > omenu1 , 1 , 0 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2011-03-31 13:09:07 +00:00
check = gtk_check_button_new_with_label ( " Running " ) ;
g_signal_connect ( check , " toggled " ,
G_CALLBACK ( toggle_running ) ,
pdata ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check , 0 , 1 , 2 , 1 ) ;
2011-03-31 13:09:07 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , TRUE ) ;
2008-02-27 10:31:24 +00:00
check = gtk_check_button_new_with_label ( " Show text " ) ;
g_signal_connect ( check , " clicked " ,
G_CALLBACK ( toggle_show_text ) ,
pdata ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check , 0 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
hbox = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , hbox , 1 , 2 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2010-04-26 00:08:04 +00:00
label = gtk_label_new ( " Text: " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , label ) ;
2008-02-27 10:31:24 +00:00
pdata - > entry = gtk_entry_new ( ) ;
2011-09-28 17:40:11 +00:00
gtk_widget_set_hexpand ( pdata - > entry , TRUE ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( pdata - > entry , " changed " ,
G_CALLBACK ( entry_changed ) ,
pdata ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( hbox ) , pdata - > entry ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_set_size_request ( pdata - > entry , 100 , - 1 ) ;
label = gtk_label_new ( " Ellipsize text : " ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , label , 0 , 10 , 1 , 1 ) ;
2011-06-13 00:00:35 +00:00
gtk_widget_set_halign ( label , GTK_ALIGN_START ) ;
gtk_widget_set_valign ( label , GTK_ALIGN_CENTER ) ;
2008-02-27 10:31:24 +00:00
pdata - > elmenu = build_option_menu ( ellipsize_items ,
sizeof ( ellipsize_items ) / sizeof ( ellipsize_items [ 0 ] ) ,
2 , // PANGO_ELLIPSIZE_MIDDLE
progressbar_toggle_ellipsize ,
pdata ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , pdata - > elmenu , 1 , 10 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
check = gtk_check_button_new_with_label ( " Activity mode " ) ;
g_signal_connect ( check , " clicked " ,
G_CALLBACK ( toggle_activity_mode ) , pdata ) ;
2011-09-28 17:40:11 +00:00
gtk_grid_attach ( GTK_GRID ( grid ) , check , 0 , 15 , 1 , 1 ) ;
2008-02-27 10:31:24 +00:00
2014-04-10 14:48:13 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( pdata - > window ) , " Close " , GTK_RESPONSE_CLOSE ) ;
g_signal_connect ( pdata - > window , " response " ,
G_CALLBACK ( gtk_widget_destroy ) ,
NULL ) ;
2008-02-27 10:31:24 +00:00
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( pdata - > window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( pdata - > window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( pdata - > window ) ;
}
/*
* Timeout Test
*/
static int timer = 0 ;
gint
timeout_test ( GtkWidget * label )
{
static int count = 0 ;
static char buffer [ 32 ] ;
sprintf ( buffer , " count: %d " , + + count ) ;
gtk_label_set_text ( GTK_LABEL ( label ) , buffer ) ;
return TRUE ;
}
void
start_timeout_test ( GtkWidget * widget ,
GtkWidget * label )
{
if ( ! timer )
{
2009-10-22 03:17:29 +00:00
timer = g_timeout_add ( 100 , ( GSourceFunc ) timeout_test , label ) ;
2008-02-27 10:31:24 +00:00
}
}
void
stop_timeout_test ( GtkWidget * widget ,
gpointer data )
{
if ( timer )
{
2009-10-22 03:17:29 +00:00
g_source_remove ( timer ) ;
2008-02-27 10:31:24 +00:00
timer = 0 ;
}
}
void
destroy_timeout_test ( GtkWidget * widget ,
GtkWidget * * window )
{
stop_timeout_test ( NULL , NULL ) ;
* window = NULL ;
}
void
create_timeout_test ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
2010-06-03 07:36:39 +00:00
GtkWidget * action_area , * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * button ;
GtkWidget * label ;
if ( ! window )
{
window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( destroy_timeout_test ) ,
& window ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
action_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Timeout Test " ) ;
label = gtk_label_new ( " count: 0 " ) ;
2011-06-02 11:37:43 +00:00
g_object_set ( label , " margin " , 10 , NULL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , label ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( label ) ;
button = gtk_button_new_with_label ( " close " ) ;
g_signal_connect_swapped ( button , " clicked " ,
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( action_area ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
gtk_widget_show ( button ) ;
button = gtk_button_new_with_label ( " start " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( start_timeout_test ) ,
label ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( action_area ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( button ) ;
button = gtk_button_new_with_label ( " stop " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( stop_timeout_test ) ,
NULL ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( action_area ) , button ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( button ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
gtk_widget_show ( window ) ;
else
gtk_widget_destroy ( window ) ;
}
/*
* Test of recursive mainloop
*/
2001-08-04 23:30:11 +00:00
2008-02-27 10:31:24 +00:00
void
mainloop_destroyed ( GtkWidget * w , GtkWidget * * window )
{
* window = NULL ;
gtk_main_quit ( ) ;
}
void
create_mainloop ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
2014-04-10 00:36:38 +00:00
GtkWidget * content_area ;
2008-02-27 10:31:24 +00:00
GtkWidget * label ;
if ( ! window )
{
window = gtk_dialog_new ( ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_title ( GTK_WINDOW ( window ) , " Test Main Loop " ) ;
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( mainloop_destroyed ) ,
& window ) ;
2010-06-03 07:36:39 +00:00
content_area = gtk_dialog_get_content_area ( GTK_DIALOG ( window ) ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( " In recursive main loop... " ) ;
2011-06-02 11:37:43 +00:00
g_object_set ( label , " margin " , 20 , NULL ) ;
2008-02-27 10:31:24 +00:00
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( content_area ) , label ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( label ) ;
2014-04-10 00:36:38 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( window ) ,
" Leave " ,
GTK_RESPONSE_OK ) ;
g_signal_connect_swapped ( window , " response " ,
2008-02-27 10:31:24 +00:00
G_CALLBACK ( gtk_widget_destroy ) ,
window ) ;
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2008-02-27 10:31:24 +00:00
{
gtk_widget_show ( window ) ;
g_print ( " create_mainloop: start \n " ) ;
gtk_main ( ) ;
g_print ( " create_mainloop: done \n " ) ;
}
else
gtk_widget_destroy ( window ) ;
}
void create_layout ( GtkWidget * widget )
{
2010-06-28 02:51:34 +00:00
GtkAdjustment * hadjustment , * vadjustment ;
GtkLayout * layout ;
2008-02-27 10:31:24 +00:00
static GtkWidget * window = NULL ;
2010-06-28 02:51:34 +00:00
GtkWidget * layout_widget ;
2008-02-27 10:31:24 +00:00
GtkWidget * scrolledwindow ;
GtkWidget * button ;
if ( ! window )
{
gchar buf [ 16 ] ;
gint i , j ;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2008-02-27 10:31:24 +00:00
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Layout " ) ;
gtk_widget_set_size_request ( window , 200 , 200 ) ;
scrolledwindow = gtk_scrolled_window_new ( NULL , NULL ) ;
gtk_scrolled_window_set_shadow_type ( GTK_SCROLLED_WINDOW ( scrolledwindow ) ,
GTK_SHADOW_IN ) ;
gtk_scrolled_window_set_placement ( GTK_SCROLLED_WINDOW ( scrolledwindow ) ,
GTK_CORNER_TOP_RIGHT ) ;
gtk_container_add ( GTK_CONTAINER ( window ) , scrolledwindow ) ;
2010-06-28 02:51:34 +00:00
layout_widget = gtk_layout_new ( NULL , NULL ) ;
layout = GTK_LAYOUT ( layout_widget ) ;
gtk_container_add ( GTK_CONTAINER ( scrolledwindow ) , layout_widget ) ;
2008-02-27 10:31:24 +00:00
/* We set step sizes here since GtkLayout does not set
* them itself .
*/
2010-10-28 16:16:55 +00:00
hadjustment = gtk_scrollable_get_hadjustment ( GTK_SCROLLABLE ( layout ) ) ;
vadjustment = gtk_scrollable_get_vadjustment ( GTK_SCROLLABLE ( layout ) ) ;
2010-06-28 02:51:34 +00:00
gtk_adjustment_set_step_increment ( hadjustment , 10.0 ) ;
gtk_adjustment_set_step_increment ( vadjustment , 10.0 ) ;
2010-10-28 16:16:55 +00:00
gtk_scrollable_set_hadjustment ( GTK_SCROLLABLE ( layout ) , hadjustment ) ;
gtk_scrollable_set_vadjustment ( GTK_SCROLLABLE ( layout ) , vadjustment ) ;
2010-06-28 02:51:34 +00:00
gtk_layout_set_size ( layout , 1600 , 128000 ) ;
2008-02-27 10:31:24 +00:00
for ( i = 0 ; i < 16 ; i + + )
for ( j = 0 ; j < 16 ; j + + )
{
sprintf ( buf , " Button %d, %d " , i , j ) ;
if ( ( i + j ) % 2 )
button = gtk_button_new_with_label ( buf ) ;
else
button = gtk_label_new ( buf ) ;
2010-06-28 02:51:34 +00:00
gtk_layout_put ( layout , button , j * 100 , i * 100 ) ;
2008-02-27 10:31:24 +00:00
}
for ( i = 16 ; i < 1280 ; i + + )
{
sprintf ( buf , " Button %d, %d " , i , 0 ) ;
if ( i % 2 )
button = gtk_button_new_with_label ( buf ) ;
else
button = gtk_label_new ( buf ) ;
2010-06-28 02:51:34 +00:00
gtk_layout_put ( layout , button , 0 , i * 100 ) ;
2008-02-27 10:31:24 +00:00
}
}
2010-03-01 06:47:38 +00:00
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
else
gtk_widget_destroy ( window ) ;
}
2015-11-02 15:19:02 +00:00
static void
show_native ( GtkWidget * button ,
GtkFileChooserNative * native )
{
gtk_native_dialog_show ( GTK_NATIVE_DIALOG ( native ) ) ;
}
static void
hide_native ( GtkWidget * button ,
GtkFileChooserNative * native )
{
gtk_native_dialog_hide ( GTK_NATIVE_DIALOG ( native ) ) ;
}
static void
native_response ( GtkNativeDialog * self ,
gint response_id ,
GtkWidget * label )
{
static int count = 0 ;
char * res ;
GSList * uris , * l ;
GString * s ;
char * response ;
2017-07-13 19:03:55 +00:00
GtkFileFilter * filter ;
2015-11-02 15:19:02 +00:00
uris = gtk_file_chooser_get_uris ( GTK_FILE_CHOOSER ( self ) ) ;
2017-07-13 19:03:55 +00:00
filter = gtk_file_chooser_get_filter ( GTK_FILE_CHOOSER ( self ) ) ;
2015-11-02 15:19:02 +00:00
s = g_string_new ( " " ) ;
for ( l = uris ; l ! = NULL ; l = l - > next )
{
g_string_prepend ( s , l - > data ) ;
g_string_prepend ( s , " \n " ) ;
}
switch ( response_id )
{
case GTK_RESPONSE_NONE :
response = g_strdup ( " GTK_RESPONSE_NONE " ) ;
break ;
case GTK_RESPONSE_ACCEPT :
response = g_strdup ( " GTK_RESPONSE_ACCEPT " ) ;
break ;
case GTK_RESPONSE_CANCEL :
response = g_strdup ( " GTK_RESPONSE_CANCEL " ) ;
break ;
case GTK_RESPONSE_DELETE_EVENT :
response = g_strdup ( " GTK_RESPONSE_DELETE_EVENT " ) ;
break ;
default :
response = g_strdup_printf ( " %d " , response_id ) ;
break ;
}
2017-07-13 19:03:55 +00:00
if ( filter )
res = g_strdup_printf ( " Response #%d: %s \n "
" Filter: %s \n "
" Files: \n "
" %s " ,
+ + count ,
response ,
gtk_file_filter_get_name ( filter ) ,
s - > str ) ;
else
res = g_strdup_printf ( " Response #%d: %s \n "
" NO Filter \n "
" Files: \n "
" %s " ,
+ + count ,
response ,
s - > str ) ;
2015-11-02 15:19:02 +00:00
gtk_label_set_text ( GTK_LABEL ( label ) , res ) ;
g_free ( response ) ;
g_string_free ( s , TRUE ) ;
}
static void
native_modal_toggle ( GtkWidget * checkbutton ,
GtkFileChooserNative * native )
{
gtk_native_dialog_set_modal ( GTK_NATIVE_DIALOG ( native ) ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ;
}
static void
native_multi_select_toggle ( GtkWidget * checkbutton ,
GtkFileChooserNative * native )
{
gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( native ) ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ;
}
static void
native_overwrite_confirmation_toggle ( GtkWidget * checkbutton ,
GtkFileChooserNative * native )
{
gtk_file_chooser_set_do_overwrite_confirmation ( GTK_FILE_CHOOSER ( native ) ,
gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ) ;
}
static void
native_extra_widget_toggle ( GtkWidget * checkbutton ,
GtkFileChooserNative * native )
{
gboolean extra_widget = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbutton ) ) ;
if ( extra_widget )
{
GtkWidget * extra = gtk_check_button_new_with_label ( " Extra toggle " ) ;
gtk_widget_show ( extra ) ;
gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( native ) , extra ) ;
}
else
{
gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( native ) , NULL ) ;
}
}
static void
native_visible_notify_show ( GObject * object ,
GParamSpec * pspec ,
GtkWidget * show_button )
{
GtkFileChooserNative * native = GTK_FILE_CHOOSER_NATIVE ( object ) ;
gboolean visible ;
visible = gtk_native_dialog_get_visible ( GTK_NATIVE_DIALOG ( native ) ) ;
gtk_widget_set_sensitive ( show_button , ! visible ) ;
}
static void
native_visible_notify_hide ( GObject * object ,
GParamSpec * pspec ,
GtkWidget * hide_button )
{
GtkFileChooserNative * native = GTK_FILE_CHOOSER_NATIVE ( object ) ;
gboolean visible ;
visible = gtk_native_dialog_get_visible ( GTK_NATIVE_DIALOG ( native ) ) ;
gtk_widget_set_sensitive ( hide_button , visible ) ;
}
static char *
get_some_file ( void )
{
GFile * dir = g_file_new_for_path ( g_get_current_dir ( ) ) ;
GFileEnumerator * e ;
char * res = NULL ;
e = g_file_enumerate_children ( dir , " * " , 0 , NULL , NULL ) ;
if ( e )
{
GFileInfo * info ;
while ( res = = NULL )
{
info = g_file_enumerator_next_file ( e , NULL , NULL ) ;
if ( info )
{
if ( g_file_info_get_file_type ( info ) = = G_FILE_TYPE_REGULAR )
{
GFile * child = g_file_enumerator_get_child ( e , info ) ;
res = g_file_get_path ( child ) ;
g_object_unref ( child ) ;
}
g_object_unref ( info ) ;
}
else
break ;
}
}
return res ;
}
static void
native_action_changed ( GtkWidget * combo ,
GtkFileChooserNative * native )
{
int i ;
gboolean save_as = FALSE ;
i = gtk_combo_box_get_active ( GTK_COMBO_BOX ( combo ) ) ;
if ( i = = 4 ) /* Save as */
{
save_as = TRUE ;
i = GTK_FILE_CHOOSER_ACTION_SAVE ;
}
gtk_file_chooser_set_action ( GTK_FILE_CHOOSER ( native ) ,
( GtkFileChooserAction ) i ) ;
if ( i = = GTK_FILE_CHOOSER_ACTION_SAVE | |
i = = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER )
{
if ( save_as )
{
char * file = get_some_file ( ) ;
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( native ) , file ) ;
g_free ( file ) ;
}
else
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( native ) , " newname.txt " ) ;
}
}
static void
native_filter_changed ( GtkWidget * combo ,
GtkFileChooserNative * native )
{
int i ;
GSList * filters , * l ;
GtkFileFilter * filter ;
i = gtk_combo_box_get_active ( GTK_COMBO_BOX ( combo ) ) ;
filters = gtk_file_chooser_list_filters ( GTK_FILE_CHOOSER ( native ) ) ;
for ( l = filters ; l ! = NULL ; l = l - > next )
gtk_file_chooser_remove_filter ( GTK_FILE_CHOOSER ( native ) , l - > data ) ;
g_slist_free ( filters ) ;
switch ( i )
{
case 0 :
break ;
case 1 : /* pattern */
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , " Text " ) ;
gtk_file_filter_add_pattern ( filter , " *.doc " ) ;
gtk_file_filter_add_pattern ( filter , " *.txt " ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , " Images " ) ;
gtk_file_filter_add_pixbuf_formats ( filter ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
2017-07-13 19:03:55 +00:00
gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
2015-11-02 15:19:02 +00:00
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , " All " ) ;
gtk_file_filter_add_pattern ( filter , " * " ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
break ;
case 2 : /* mimetype */
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , " Text " ) ;
gtk_file_filter_add_mime_type ( filter , " text/plain " ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
filter = gtk_file_filter_new ( ) ;
gtk_file_filter_set_name ( filter , " All " ) ;
gtk_file_filter_add_pattern ( filter , " * " ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
2017-07-13 19:03:55 +00:00
gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( native ) , filter ) ;
2015-11-02 15:19:02 +00:00
break ;
}
}
2015-11-11 15:06:44 +00:00
static void
destroy_native ( GtkFileChooserNative * native )
{
gtk_native_dialog_destroy ( GTK_NATIVE_DIALOG ( native ) ) ;
g_object_unref ( native ) ;
}
2015-11-02 15:19:02 +00:00
void
create_native_dialogs ( GtkWidget * widget )
{
static GtkWidget * window = NULL ;
GtkWidget * box , * label ;
GtkWidget * show_button , * hide_button , * check_button ;
GtkFileChooserNative * native ;
GtkWidget * combo ;
if ( ! window )
{
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2017-10-31 06:41:15 +00:00
gtk_window_set_display ( GTK_WINDOW ( window ) ,
gtk_widget_get_display ( widget ) ) ;
2015-11-02 15:19:02 +00:00
native = gtk_file_chooser_native_new ( " Native title " ,
GTK_WINDOW ( window ) ,
GTK_FILE_CHOOSER_ACTION_OPEN ,
" _accept&native " ,
" _cancel__native " ) ;
2015-11-11 15:06:44 +00:00
g_signal_connect_swapped ( G_OBJECT ( window ) , " destroy " , G_CALLBACK ( destroy_native ) , native ) ;
2015-11-02 15:19:02 +00:00
gtk_file_chooser_add_shortcut_folder ( GTK_FILE_CHOOSER ( native ) ,
g_get_current_dir ( ) ,
NULL ) ;
gtk_window_set_title ( GTK_WINDOW ( window ) , " Native dialog parent " ) ;
box = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 ) ;
gtk_container_add ( GTK_CONTAINER ( window ) , box ) ;
label = gtk_label_new ( " " ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , label ) ;
2015-11-02 15:19:02 +00:00
combo = gtk_combo_box_text_new ( ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Open " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Save " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Select Folder " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Create Folder " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Save as " ) ;
g_signal_connect ( combo , " changed " ,
G_CALLBACK ( native_action_changed ) , native ) ;
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo ) , GTK_FILE_CHOOSER_ACTION_OPEN ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , combo ) ;
2015-11-02 15:19:02 +00:00
combo = gtk_combo_box_text_new ( ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " No filters " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Pattern filter " ) ;
gtk_combo_box_text_append_text ( GTK_COMBO_BOX_TEXT ( combo ) , " Mimetype filter " ) ;
g_signal_connect ( combo , " changed " ,
G_CALLBACK ( native_filter_changed ) , native ) ;
gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo ) , 0 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , combo ) ;
2015-11-02 15:19:02 +00:00
check_button = gtk_check_button_new_with_label ( " Modal " ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( native_modal_toggle ) , native ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , check_button ) ;
2015-11-02 15:19:02 +00:00
check_button = gtk_check_button_new_with_label ( " Multiple select " ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( native_multi_select_toggle ) , native ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , check_button ) ;
2015-11-02 15:19:02 +00:00
check_button = gtk_check_button_new_with_label ( " Confirm overwrite " ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( native_overwrite_confirmation_toggle ) , native ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , check_button ) ;
2015-11-02 15:19:02 +00:00
check_button = gtk_check_button_new_with_label ( " Extra widget " ) ;
g_signal_connect ( check_button , " toggled " ,
G_CALLBACK ( native_extra_widget_toggle ) , native ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , check_button ) ;
2015-11-02 15:19:02 +00:00
show_button = gtk_button_new_with_label ( " Show " ) ;
hide_button = gtk_button_new_with_label ( " Hide " ) ;
gtk_widget_set_sensitive ( hide_button , FALSE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box ) , show_button ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , hide_button ) ;
2015-11-02 15:19:02 +00:00
/* connect signals */
g_signal_connect ( native , " response " ,
G_CALLBACK ( native_response ) , label ) ;
g_signal_connect ( show_button , " clicked " ,
G_CALLBACK ( show_native ) , native ) ;
g_signal_connect ( hide_button , " clicked " ,
G_CALLBACK ( hide_native ) , native ) ;
g_signal_connect ( native , " notify::visible " ,
G_CALLBACK ( native_visible_notify_show ) , show_button ) ;
g_signal_connect ( native , " notify::visible " ,
G_CALLBACK ( native_visible_notify_hide ) , hide_button ) ;
g_signal_connect ( window , " destroy " ,
G_CALLBACK ( gtk_widget_destroyed ) ,
& window ) ;
}
if ( ! gtk_widget_get_visible ( window ) )
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2015-11-02 15:19:02 +00:00
else
gtk_widget_destroy ( window ) ;
}
2008-02-27 10:31:24 +00:00
/*
* Main Window and Exit
*/
2001-08-04 23:30:11 +00:00
2008-02-27 10:31:24 +00:00
void
do_exit ( GtkWidget * widget , GtkWidget * window )
{
gtk_widget_destroy ( window ) ;
gtk_main_quit ( ) ;
}
struct {
char * label ;
void ( * func ) ( GtkWidget * widget ) ;
gboolean do_not_benchmark ;
} buttons [ ] =
{
{ " alpha window " , create_alpha_window } ,
{ " button box " , create_button_box } ,
{ " buttons " , create_buttons } ,
{ " check buttons " , create_check_buttons } ,
{ " color selection " , create_color_selection } ,
{ " cursors " , create_cursors } ,
2009-07-26 17:05:45 +00:00
{ " dialog " , create_dialog } ,
2013-04-04 14:36:09 +00:00
{ " display " , create_display_screen , TRUE } ,
2008-02-27 10:31:24 +00:00
{ " entry " , create_entry } ,
{ " expander " , create_expander } ,
{ " flipping " , create_flipping } ,
{ " focus " , create_focus } ,
{ " font selection " , create_font_selection } ,
{ " image " , create_image } ,
{ " key lookup " , create_key_lookup } ,
{ " labels " , create_labels } ,
{ " layout " , create_layout } ,
2013-06-10 12:15:56 +00:00
{ " listbox " , create_listbox } ,
2008-02-27 10:31:24 +00:00
{ " menus " , create_menus } ,
{ " message dialog " , create_message_dialog } ,
{ " modal window " , create_modal_window , TRUE } ,
2015-11-02 15:19:02 +00:00
{ " native dialogs " , create_native_dialogs } ,
2008-02-27 10:31:24 +00:00
{ " notebook " , create_notebook } ,
{ " panes " , create_panes } ,
{ " paned keyboard " , create_paned_keyboard_navigation } ,
2010-08-06 20:12:24 +00:00
{ " pixbuf " , create_pixbuf } ,
2008-02-27 10:31:24 +00:00
{ " progress bar " , create_progress_bar } ,
{ " radio buttons " , create_radio_buttons } ,
{ " range controls " , create_range_controls } ,
{ " rotated text " , create_rotated_text } ,
{ " saved position " , create_saved_position } ,
{ " scrolled windows " , create_scrolled_windows } ,
{ " size groups " , create_size_groups } ,
{ " spinbutton " , create_spins } ,
{ " statusbar " , create_statusbar } ,
{ " test mainloop " , create_mainloop , TRUE } ,
{ " test timeout " , create_timeout_test } ,
{ " toggle buttons " , create_toggle_buttons } ,
{ " tooltips " , create_tooltips } ,
{ " WM hints " , create_wmhints } ,
{ " window sizing " , create_window_sizing } ,
2018-03-20 11:05:26 +00:00
{ " window states " , create_surface_states }
2008-02-27 10:31:24 +00:00
} ;
int nbuttons = sizeof ( buttons ) / sizeof ( buttons [ 0 ] ) ;
void
create_main_window ( void )
{
GtkWidget * window ;
GtkWidget * box1 ;
GtkWidget * box2 ;
GtkWidget * scrolled_window ;
GtkWidget * button ;
GtkWidget * label ;
gchar buffer [ 64 ] ;
GtkWidget * separator ;
int i ;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
2010-11-13 20:19:41 +00:00
gtk_widget_set_name ( window , " main_window " ) ;
2010-04-13 16:32:10 +00:00
gtk_window_move ( GTK_WINDOW ( window ) , 50 , 20 ) ;
2008-02-27 10:31:24 +00:00
gtk_window_set_default_size ( GTK_WINDOW ( window ) , - 1 , 400 ) ;
2017-12-31 17:52:54 +00:00
g_signal_connect ( window , " destroy " , G_CALLBACK ( gtk_main_quit ) , NULL ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box1 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2008-02-27 10:31:24 +00:00
gtk_container_add ( GTK_CONTAINER ( window ) , box1 ) ;
2016-11-19 17:27:02 +00:00
if ( gtk_get_micro_version ( ) > 0 )
2008-02-27 10:31:24 +00:00
sprintf ( buffer ,
" Gtk+ v%d.%d.%d " ,
2010-09-09 08:03:22 +00:00
gtk_get_major_version ( ) ,
gtk_get_minor_version ( ) ,
gtk_get_micro_version ( ) ) ;
2008-02-27 10:31:24 +00:00
else
sprintf ( buffer ,
" Gtk+ v%d.%d " ,
2010-09-09 08:03:22 +00:00
gtk_get_major_version ( ) ,
gtk_get_minor_version ( ) ) ;
2008-02-27 10:31:24 +00:00
label = gtk_label_new ( buffer ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , label ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_set_name ( label , " testgtk-version-label " ) ;
scrolled_window = gtk_scrolled_window_new ( NULL , NULL ) ;
2017-08-01 23:23:43 +00:00
gtk_widget_set_vexpand ( scrolled_window , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_window ) ,
GTK_POLICY_NEVER ,
GTK_POLICY_AUTOMATIC ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , scrolled_window ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 0 ) ;
2013-02-01 16:22:13 +00:00
gtk_container_add ( GTK_CONTAINER ( scrolled_window ) , box2 ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_show ( box2 ) ;
for ( i = 0 ; i < nbuttons ; i + + )
{
button = gtk_button_new_with_label ( buttons [ i ] . label ) ;
if ( buttons [ i ] . func )
2016-10-02 15:37:22 +00:00
g_signal_connect ( button ,
" clicked " ,
2008-02-27 10:31:24 +00:00
G_CALLBACK ( buttons [ i ] . func ) ,
NULL ) ;
else
gtk_widget_set_sensitive ( button , FALSE ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2008-02-27 10:31:24 +00:00
}
2010-10-29 23:32:34 +00:00
separator = gtk_separator_new ( GTK_ORIENTATION_HORIZONTAL ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , separator ) ;
2008-02-27 10:31:24 +00:00
2010-10-31 17:07:20 +00:00
box2 = gtk_box_new ( GTK_ORIENTATION_VERTICAL , 10 ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box1 ) , box2 ) ;
2008-02-27 10:31:24 +00:00
button = gtk_button_new_with_mnemonic ( " _Close " ) ;
g_signal_connect ( button , " clicked " ,
G_CALLBACK ( do_exit ) ,
window ) ;
2017-04-21 20:34:36 +00:00
gtk_box_pack_start ( GTK_BOX ( box2 ) , button ) ;
2010-03-02 06:58:05 +00:00
gtk_widget_set_can_default ( button , TRUE ) ;
2008-02-27 10:31:24 +00:00
gtk_widget_grab_default ( button ) ;
2000-06-21 16:19:59 +00:00
2017-01-19 09:02:04 +00:00
gtk_widget_show ( window ) ;
2008-02-27 10:31:24 +00:00
}
2000-06-21 16:19:59 +00:00
2008-02-27 10:31:24 +00:00
static void
test_init ( void )
{
2011-03-29 13:26:03 +00:00
if ( g_file_test ( " ../modules/input/immodules.cache " , G_FILE_TEST_EXISTS ) )
g_setenv ( " GTK_IM_MODULE_FILE " , " ../modules/input/immodules.cache " , TRUE ) ;
2008-02-27 10:31:24 +00:00
}
2001-02-04 07:05:29 +00:00
2008-02-27 10:31:24 +00:00
static char *
pad ( const char * str , int to )
{
static char buf [ 256 ] ;
int len = strlen ( str ) ;
int i ;
for ( i = 0 ; i < to ; i + + )
buf [ i ] = ' ' ;
buf [ to ] = ' \0 ' ;
memcpy ( buf , str , len ) ;
return buf ;
}
static void
bench_iteration ( GtkWidget * widget , void ( * fn ) ( GtkWidget * widget ) )
{
fn ( widget ) ; /* on */
while ( g_main_context_iteration ( NULL , FALSE ) ) ;
fn ( widget ) ; /* off */
while ( g_main_context_iteration ( NULL , FALSE ) ) ;
}
void
do_real_bench ( GtkWidget * widget , void ( * fn ) ( GtkWidget * widget ) , char * name , int num )
{
GTimeVal tv0 , tv1 ;
double dt_first ;
double dt ;
int n ;
static gboolean printed_headers = FALSE ;
if ( ! printed_headers ) {
g_print ( " Test Iters First Other \n " ) ;
g_print ( " -------------------- ----- ---------- ---------- \n " ) ;
printed_headers = TRUE ;
}
g_get_current_time ( & tv0 ) ;
bench_iteration ( widget , fn ) ;
g_get_current_time ( & tv1 ) ;
dt_first = ( ( double ) tv1 . tv_sec - tv0 . tv_sec ) * 1000.0
+ ( tv1 . tv_usec - tv0 . tv_usec ) / 1000.0 ;
g_get_current_time ( & tv0 ) ;
for ( n = 0 ; n < num - 1 ; n + + )
bench_iteration ( widget , fn ) ;
g_get_current_time ( & tv1 ) ;
dt = ( ( double ) tv1 . tv_sec - tv0 . tv_sec ) * 1000.0
+ ( tv1 . tv_usec - tv0 . tv_usec ) / 1000.0 ;
g_print ( " %s %5d " , pad ( name , 20 ) , num ) ;
if ( num > 1 )
g_print ( " %10.1f %10.1f \n " , dt_first , dt / ( num - 1 ) ) ;
else
g_print ( " %10.1f \n " , dt_first ) ;
}
void
do_bench ( char * what , int num )
{
int i ;
GtkWidget * widget ;
void ( * fn ) ( GtkWidget * widget ) ;
fn = NULL ;
widget = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
if ( g_ascii_strcasecmp ( what , " ALL " ) = = 0 )
{
for ( i = 0 ; i < nbuttons ; i + + )
{
if ( ! buttons [ i ] . do_not_benchmark )
do_real_bench ( widget , buttons [ i ] . func , buttons [ i ] . label , num ) ;
}
return ;
}
else
{
for ( i = 0 ; i < nbuttons ; i + + )
{
if ( strcmp ( buttons [ i ] . label , what ) = = 0 )
{
fn = buttons [ i ] . func ;
break ;
}
}
if ( ! fn )
g_print ( " Can't bench: \" %s \" not found. \n " , what ) ;
else
do_real_bench ( widget , fn , buttons [ i ] . label , num ) ;
}
1997-11-24 22:37:52 +00:00
}
2008-02-21 18:03:04 +00:00
2008-02-27 10:31:24 +00:00
void
usage ( void )
{
fprintf ( stderr , " Usage: testgtk [--bench ALL|<bench>[:<count>]] \n " ) ;
exit ( 1 ) ;
}
int
main ( int argc , char * argv [ ] )
{
2010-11-13 20:19:41 +00:00
GtkCssProvider * provider , * memory_provider ;
GdkDisplay * display ;
2008-02-27 10:31:24 +00:00
GtkBindingSet * binding_set ;
int i ;
gboolean done_benchmarks = FALSE ;
srand ( time ( NULL ) ) ;
test_init ( ) ;
2010-11-13 20:19:41 +00:00
g_set_application_name ( " GTK+ Test Program " ) ;
2017-03-12 18:36:21 +00:00
# ifdef GTK_SRCDIR
g_chdir ( GTK_SRCDIR ) ;
# endif
2016-12-28 13:53:22 +00:00
gtk_init ( ) ;
2010-11-13 20:19:41 +00:00
provider = gtk_css_provider_new ( ) ;
2008-02-27 10:31:24 +00:00
/* Check to see if we are being run from the correct
* directory .
*/
2010-11-13 20:19:41 +00:00
if ( file_exists ( " testgtk.css " ) )
2016-10-17 14:09:12 +00:00
gtk_css_provider_load_from_path ( provider , " testgtk.css " ) ;
2010-11-13 22:18:44 +00:00
else if ( file_exists ( " tests/testgtk.css " ) )
2016-10-17 14:09:12 +00:00
gtk_css_provider_load_from_path ( provider , " tests/testgtk.css " ) ;
2008-11-26 08:36:10 +00:00
else
2010-11-13 20:19:41 +00:00
g_warning ( " Couldn't find file \" testgtk.css \" . " ) ;
2008-02-27 10:31:24 +00:00
2010-11-13 20:19:41 +00:00
display = gdk_display_get_default ( ) ;
2008-02-27 10:31:24 +00:00
2017-10-31 01:35:21 +00:00
gtk_style_context_add_provider_for_display ( display , GTK_STYLE_PROVIDER ( provider ) ,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION ) ;
2010-11-13 20:19:41 +00:00
g_object_unref ( provider ) ;
2008-02-27 10:31:24 +00:00
gtk_accelerator_set_default_mod_mask ( GDK_SHIFT_MASK |
GDK_CONTROL_MASK |
GDK_MOD1_MASK |
GDK_META_MASK |
GDK_SUPER_MASK |
GDK_HYPER_MASK |
GDK_MOD4_MASK ) ;
/* benchmarking
*/
for ( i = 1 ; i < argc ; i + + )
{
if ( strncmp ( argv [ i ] , " --bench " , strlen ( " --bench " ) ) = = 0 )
{
int num = 1 ;
char * nextarg ;
char * what ;
char * count ;
nextarg = strchr ( argv [ i ] , ' = ' ) ;
if ( nextarg )
nextarg + + ;
else
{
i + + ;
if ( i = = argc )
usage ( ) ;
nextarg = argv [ i ] ;
}
count = strchr ( nextarg , ' : ' ) ;
if ( count )
{
what = g_strndup ( nextarg , count - nextarg ) ;
count + + ;
num = atoi ( count ) ;
if ( num < = 0 )
usage ( ) ;
}
else
what = g_strdup ( nextarg ) ;
do_bench ( what , num ? num : 1 ) ;
done_benchmarks = TRUE ;
}
else
usage ( ) ;
}
if ( done_benchmarks )
return 0 ;
/* bindings test
*/
2008-06-18 07:00:46 +00:00
binding_set = gtk_binding_set_by_class ( g_type_class_ref ( GTK_TYPE_WIDGET ) ) ;
2008-02-27 10:31:24 +00:00
gtk_binding_entry_add_signal ( binding_set ,
' 9 ' , GDK_CONTROL_MASK | GDK_RELEASE_MASK ,
" debug_msg " ,
1 ,
G_TYPE_STRING , " GtkWidgetClass <ctrl><release>9 test " ) ;
2008-02-21 18:03:04 +00:00
2010-11-13 20:19:41 +00:00
memory_provider = gtk_css_provider_new ( ) ;
gtk_css_provider_load_from_data ( memory_provider ,
" #testgtk-version-label { \n "
" color: #f00; \n "
2016-10-03 07:31:44 +00:00
" font-family: Sans; \n "
" font-size: 18px; \n "
2010-11-13 20:19:41 +00:00
" } " ,
2016-10-17 14:09:12 +00:00
- 1 ) ;
2017-10-31 01:35:21 +00:00
gtk_style_context_add_provider_for_display ( display , GTK_STYLE_PROVIDER ( memory_provider ) ,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1 ) ;
2010-11-13 20:19:41 +00:00
2008-02-27 10:31:24 +00:00
create_main_window ( ) ;
2008-02-21 18:03:04 +00:00
2008-02-27 10:31:24 +00:00
gtk_main ( ) ;
if ( 1 )
{
while ( g_main_context_pending ( NULL ) )
g_main_context_iteration ( NULL , FALSE ) ;
#if 0
sleep ( 1 ) ;
while ( g_main_context_pending ( NULL ) )
g_main_context_iteration ( NULL , FALSE ) ;
# endif
}
return 0 ;
}