Bump version number of lxappearance to 0.2.
[lxde/lxappearance.git] / src / demo.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <gtk/gtk.h>
6
7 #include "demo.h"
8 #include "demo-ui.h"
9 #include "glade-support.h"
10
11 extern gboolean under_lxde; /* wether lxde-xsettings daemon is active */
12
13 static GtkIconView* icon_view = NULL;
14
15 static void load_demo_icons()
16 {
17 static const char** icon_names[]={
18 "gnome-fs-home",
19 "gnome-fs-desktop",
20 "gnome-fs-directory",
21 "gnome-fs-trash-empty",
22 "gnome-fs-regular",
23 "gnome-fs-executable",
24 "gnome-mime-image",
25 "gnome-mime-text"
26 };
27
28 int i;
29 GtkIconTheme* theme = gtk_icon_theme_get_default();
30 GtkListStore* demo_icon_list;
31
32 demo_icon_list = gtk_list_store_new( 2, GDK_TYPE_PIXBUF, G_TYPE_STRING );
33
34 for( i = 0; i < G_N_ELEMENTS(icon_names); ++i )
35 {
36 GtkTreeIter it;
37 GdkPixbuf* icon = gtk_icon_theme_load_icon( theme, icon_names[i], 32, 0, NULL );
38 gtk_list_store_append( demo_icon_list, &it );
39 gtk_list_store_set( demo_icon_list, &it, 0, icon, 1, icon_names[i], -1 );
40 if( icon )
41 g_object_unref( icon );
42 }
43 gtk_icon_view_set_model( icon_view, demo_icon_list );
44 g_object_unref( demo_icon_list );
45 }
46
47 static void load_demo_tree_view( GtkTreeView* view )
48 {
49 GtkListStore* list;
50 int i;
51 char str[256];
52
53 for( i = 0; i < 3; ++i )
54 {
55 GtkTreeViewColumn* col;
56 g_snprintf( str, 256, "%s %d", _("Column"), i + 1 );
57 col = gtk_tree_view_column_new_with_attributes( "Column 1", gtk_cell_renderer_text_new(), "text", i, NULL );
58 gtk_tree_view_append_column( view, col );
59 }
60
61 list = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
62 for( i = 0; i < 3; ++i )
63 {
64 GtkTreeIter it;
65 g_snprintf( str, 256, "%s %d", _("Item"), i + 1 );
66 gtk_list_store_append( list, &it );
67 gtk_list_store_set( list, &it, 0, str, 1, str, 2, str, -1 );
68 }
69 gtk_tree_view_set_model( view, (GtkTreeModel*)list );
70 g_object_unref( list );
71 }
72
73 void show_demo( GdkNativeWindow wid )
74 {
75 GtkWidget* demo = create_demo_window();
76 GtkWidget* plug;
77 GtkWidget* top_vbox;
78 GtkToolbarStyle tb_style;
79 GtkWidget* tree_view;
80
81 g_object_get( gtk_settings_get_default(), "gtk-toolbar-style", &tb_style, NULL );
82 gtk_toolbar_set_style (GTK_TOOLBAR (lookup_widget(demo, "toolbar")), tb_style );
83
84 icon_view = lookup_widget( demo, "icon_view" );
85 tree_view = lookup_widget( demo, "demo_treeview" );
86
87 gtk_icon_view_set_pixbuf_column( icon_view, 0 );
88 gtk_icon_view_set_text_column( icon_view, 1 );
89 gtk_icon_view_set_item_width( icon_view, 64 );
90 gtk_icon_view_set_column_spacing( icon_view, 8 );
91 gtk_icon_view_set_row_spacing( icon_view, 8 );
92
93 load_demo_icons();
94 load_demo_tree_view( (GtkTreeView*)tree_view );
95
96 gtk_widget_show_all( demo );
97
98 /* LXDE settings daemon is active and we don't use gtkrc files. */
99 if( under_lxde )
100 {
101 /* The demo window and the main dialog are in the same process */
102 GtkWidget* demo_box = (GtkWidget*)wid;
103 gtk_container_add( demo_box, demo );
104 g_signal_connect( gtk_icon_theme_get_default(), "changed", G_CALLBACK( load_demo_icons ), NULL );
105 }
106 else
107 {
108 /* we are in another process with a different gtkrc file. */
109 plug = gtk_plug_new( wid ); /* plug our demo window into the main process */
110 gtk_container_add( (GtkContainer*)plug, demo );
111 gtk_widget_show( plug );
112 }
113 }