1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/private.cpp
3 // Purpose: implementation of wxGTK private functions
4 // Author: Marcin Malich
8 // Copyright: (c) 2008 Marcin Malich <me@malcom.pl>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/module.h"
31 #include "wx/gtk/private.h"
33 // ----------------------------------------------------------------------------
34 // wxGTKPrivate functions implementation
35 // ----------------------------------------------------------------------------
37 namespace wxGTKPrivate
40 static GtkWidget
*gs_container
= NULL
;
42 static GtkContainer
* GetContainer()
44 if ( gs_container
== NULL
)
46 GtkWidget
* window
= gtk_window_new(GTK_WINDOW_POPUP
);
47 gs_container
= gtk_fixed_new();
48 gtk_container_add(GTK_CONTAINER(window
), gs_container
);
50 return GTK_CONTAINER(gs_container
);
53 GtkWidget
*GetButtonWidget()
55 static GtkWidget
*s_button
= NULL
;
59 s_button
= gtk_button_new();
60 gtk_container_add(GetContainer(), s_button
);
61 gtk_widget_realize(s_button
);
67 GtkWidget
*GetCheckButtonWidget()
69 static GtkWidget
*s_button
= NULL
;
73 s_button
= gtk_check_button_new();
74 gtk_container_add(GetContainer(), s_button
);
75 gtk_widget_realize(s_button
);
81 GtkWidget
* GetComboBoxWidget()
83 static GtkWidget
*s_button
= NULL
;
84 static GtkWidget
*s_window
= NULL
;
88 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
89 gtk_widget_realize( s_window
);
90 s_button
= gtk_combo_box_new();
91 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
92 gtk_widget_realize( s_button
);
99 GtkWidget
*GetEntryWidget()
101 static GtkWidget
*s_entry
= NULL
;
105 s_entry
= gtk_entry_new();
106 gtk_container_add(GetContainer(), s_entry
);
107 gtk_widget_realize(s_entry
);
113 // This one just gets the button used by the column header. Although it's
114 // still a gtk_button the themes will typically differentiate and draw them
115 // differently if the button is in a treeview.
116 static GtkWidget
*s_first_button
= NULL
;
117 static GtkWidget
*s_other_button
= NULL
;
119 GtkWidget
*GetHeaderButtonWidgetFirst()
122 if ( !s_first_button
)
124 // Get the dummy tree widget, give it a column, and then use the
125 // widget in the column header for the rendering code.
126 GtkWidget
* treewidget
= GetTreeWidget();
128 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
129 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
130 s_first_button
= column
->button
;
132 column
= gtk_tree_view_column_new();
133 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
134 s_other_button
= column
->button
;
137 return s_first_button
;
140 GtkWidget
*GetHeaderButtonWidget()
142 if ( !s_other_button
)
144 // Get the dummy tree widget, give it a column, and then use the
145 // widget in the column header for the rendering code.
146 GtkWidget
* treewidget
= GetTreeWidget();
148 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
149 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
150 s_first_button
= column
->button
;
152 column
= gtk_tree_view_column_new();
153 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
154 s_other_button
= column
->button
;
157 return s_other_button
;
160 GtkWidget
* GetRadioButtonWidget()
162 static GtkWidget
*s_button
= NULL
;
163 static GtkWidget
*s_window
= NULL
;
167 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
168 gtk_widget_realize( s_window
);
169 s_button
= gtk_radio_button_new(NULL
);
170 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
171 gtk_widget_realize( s_button
);
177 GtkWidget
* GetSplitterWidget()
179 static GtkWidget
* widget
;
183 widget
= gtk_vpaned_new();
184 gtk_container_add(GetContainer(), widget
);
185 gtk_widget_realize(widget
);
191 GtkWidget
* GetTextEntryWidget()
193 static GtkWidget
*s_button
= NULL
;
194 static GtkWidget
*s_window
= NULL
;
198 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
199 gtk_widget_realize( s_window
);
200 s_button
= gtk_entry_new();
201 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
202 gtk_widget_realize( s_button
);
208 GtkWidget
*GetTreeWidget()
210 static GtkWidget
*s_tree
= NULL
;
214 s_tree
= gtk_tree_view_new();
215 gtk_container_add(GetContainer(), s_tree
);
216 gtk_widget_realize(s_tree
);
223 // Module for destroying created widgets
224 class WidgetsCleanupModule
: public wxModule
227 virtual bool OnInit()
232 virtual void OnExit()
236 GtkWidget
* parent
= gtk_widget_get_parent(gs_container
);
237 gtk_widget_destroy(parent
);
241 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule
)
244 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule
, wxModule
)
246 static WidgetsCleanupModule gs_widgetsCleanupModule
;
248 } // wxGTKPrivate namespace