1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/private.cpp
3 // Purpose: implementation of wxGTK private functions
4 // Author: Marcin Malich
7 // Copyright: (c) 2008 Marcin Malich <me@malcom.pl>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #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
*GetNotebookWidget()
69 static GtkWidget
*s_notebook
= NULL
;
73 s_notebook
= gtk_notebook_new();
74 gtk_container_add(GetContainer(), s_notebook
);
75 gtk_widget_realize(s_notebook
);
81 GtkWidget
*GetCheckButtonWidget()
83 static GtkWidget
*s_button
= NULL
;
87 s_button
= gtk_check_button_new();
88 gtk_container_add(GetContainer(), s_button
);
89 gtk_widget_realize(s_button
);
95 GtkWidget
* GetComboBoxWidget()
97 static GtkWidget
*s_button
= NULL
;
98 static GtkWidget
*s_window
= NULL
;
102 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
103 gtk_widget_realize( s_window
);
104 s_button
= gtk_combo_box_new();
105 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
106 gtk_widget_realize( s_button
);
113 GtkWidget
*GetEntryWidget()
115 static GtkWidget
*s_entry
= NULL
;
119 s_entry
= gtk_entry_new();
120 gtk_container_add(GetContainer(), s_entry
);
121 gtk_widget_realize(s_entry
);
127 // This one just gets the button used by the column header. Although it's
128 // still a gtk_button the themes will typically differentiate and draw them
129 // differently if the button is in a treeview.
130 static GtkWidget
*s_first_button
= NULL
;
131 static GtkWidget
*s_other_button
= NULL
;
132 static GtkWidget
*s_last_button
= NULL
;
134 static void CreateHeaderButtons()
136 // Get the dummy tree widget, give it a column, and then use the
137 // widget in the column header for the rendering code.
138 GtkWidget
* treewidget
= GetTreeWidget();
140 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
141 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
143 s_first_button
= gtk_tree_view_column_get_button(column
);
145 s_first_button
= column
->button
;
147 wxASSERT(s_first_button
);
149 column
= gtk_tree_view_column_new();
150 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
152 s_other_button
= gtk_tree_view_column_get_button(column
);
154 s_other_button
= column
->button
;
157 column
= gtk_tree_view_column_new();
158 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
160 s_last_button
= gtk_tree_view_column_get_button(column
);
162 s_last_button
= column
->button
;
166 GtkWidget
*GetHeaderButtonWidgetFirst()
169 CreateHeaderButtons();
171 return s_first_button
;
174 GtkWidget
*GetHeaderButtonWidgetLast()
177 CreateHeaderButtons();
179 return s_last_button
;
182 GtkWidget
*GetHeaderButtonWidget()
185 CreateHeaderButtons();
187 return s_other_button
;
190 GtkWidget
* GetRadioButtonWidget()
192 static GtkWidget
*s_button
= NULL
;
193 static GtkWidget
*s_window
= NULL
;
197 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
198 gtk_widget_realize( s_window
);
199 s_button
= gtk_radio_button_new(NULL
);
200 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
201 gtk_widget_realize( s_button
);
207 GtkWidget
* GetSplitterWidget(wxOrientation orient
)
209 static GtkWidget
* widgets
[2];
210 const GtkOrientation gtkOrient
=
211 orient
== wxHORIZONTAL
? GTK_ORIENTATION_HORIZONTAL
: GTK_ORIENTATION_VERTICAL
;
212 GtkWidget
*& widget
= widgets
[gtkOrient
];
216 widget
= gtk_paned_new(gtkOrient
);
218 if (orient
== wxHORIZONTAL
)
219 widget
= gtk_hpaned_new();
221 widget
= gtk_vpaned_new();
223 gtk_container_add(GetContainer(), widget
);
224 gtk_widget_realize(widget
);
230 GtkWidget
* GetTextEntryWidget()
232 static GtkWidget
*s_button
= NULL
;
233 static GtkWidget
*s_window
= NULL
;
237 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
238 gtk_widget_realize( s_window
);
239 s_button
= gtk_entry_new();
240 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
241 gtk_widget_realize( s_button
);
247 GtkWidget
*GetTreeWidget()
249 static GtkWidget
*s_tree
= NULL
;
253 s_tree
= gtk_tree_view_new();
254 gtk_container_add(GetContainer(), s_tree
);
255 gtk_widget_realize(s_tree
);
261 // Module for destroying created widgets
262 class WidgetsCleanupModule
: public wxModule
265 virtual bool OnInit()
270 virtual void OnExit()
274 GtkWidget
* parent
= gtk_widget_get_parent(gs_container
);
275 gtk_widget_destroy(parent
);
279 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule
)
282 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule
, wxModule
)
284 static WidgetsCleanupModule gs_widgetsCleanupModule
;
286 } // wxGTKPrivate namespace