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
;
118 static GtkWidget
*s_last_button
= NULL
;
120 static void CreateHeaderButtons()
122 // Get the dummy tree widget, give it a column, and then use the
123 // widget in the column header for the rendering code.
124 GtkWidget
* treewidget
= GetTreeWidget();
126 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
127 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
128 s_first_button
= column
->button
;
130 column
= gtk_tree_view_column_new();
131 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
132 s_other_button
= column
->button
;
134 column
= gtk_tree_view_column_new();
135 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
136 s_last_button
= column
->button
;
139 GtkWidget
*GetHeaderButtonWidgetFirst()
142 CreateHeaderButtons();
144 return s_first_button
;
147 GtkWidget
*GetHeaderButtonWidgetLast()
150 CreateHeaderButtons();
152 return s_last_button
;
155 GtkWidget
*GetHeaderButtonWidget()
158 CreateHeaderButtons();
160 return s_other_button
;
163 GtkWidget
* GetRadioButtonWidget()
165 static GtkWidget
*s_button
= NULL
;
166 static GtkWidget
*s_window
= NULL
;
170 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
171 gtk_widget_realize( s_window
);
172 s_button
= gtk_radio_button_new(NULL
);
173 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
174 gtk_widget_realize( s_button
);
180 GtkWidget
* GetSplitterWidget()
182 static GtkWidget
* widget
;
186 widget
= gtk_vpaned_new();
187 gtk_container_add(GetContainer(), widget
);
188 gtk_widget_realize(widget
);
194 GtkWidget
* GetTextEntryWidget()
196 static GtkWidget
*s_button
= NULL
;
197 static GtkWidget
*s_window
= NULL
;
201 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
202 gtk_widget_realize( s_window
);
203 s_button
= gtk_entry_new();
204 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
205 gtk_widget_realize( s_button
);
211 GtkWidget
*GetTreeWidget()
213 static GtkWidget
*s_tree
= NULL
;
217 s_tree
= gtk_tree_view_new();
218 gtk_container_add(GetContainer(), s_tree
);
219 gtk_widget_realize(s_tree
);
226 // Module for destroying created widgets
227 class WidgetsCleanupModule
: public wxModule
230 virtual bool OnInit()
235 virtual void OnExit()
239 GtkWidget
* parent
= gtk_widget_get_parent(gs_container
);
240 gtk_widget_destroy(parent
);
244 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule
)
247 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule
, wxModule
)
249 static WidgetsCleanupModule gs_widgetsCleanupModule
;
251 } // wxGTKPrivate namespace