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 // Licence: 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"
32 #include "wx/gtk/private.h"
34 // ----------------------------------------------------------------------------
35 // wxGTKPrivate functions implementation
36 // ----------------------------------------------------------------------------
38 namespace wxGTKPrivate
41 static GtkWidget
*gs_container
= NULL
;
43 static GtkContainer
* GetContainer()
45 if ( gs_container
== NULL
)
47 GtkWidget
* window
= gtk_window_new(GTK_WINDOW_POPUP
);
48 gs_container
= gtk_fixed_new();
49 gtk_container_add(GTK_CONTAINER(window
), gs_container
);
51 return GTK_CONTAINER(gs_container
);
54 GtkWidget
*GetButtonWidget()
56 static GtkWidget
*s_button
= NULL
;
60 s_button
= gtk_button_new();
61 gtk_container_add(GetContainer(), s_button
);
62 gtk_widget_realize(s_button
);
68 GtkWidget
*GetNotebookWidget()
70 static GtkWidget
*s_notebook
= NULL
;
74 s_notebook
= gtk_notebook_new();
75 gtk_container_add(GetContainer(), s_notebook
);
76 gtk_widget_realize(s_notebook
);
82 GtkWidget
*GetCheckButtonWidget()
84 static GtkWidget
*s_button
= NULL
;
88 s_button
= gtk_check_button_new();
89 gtk_container_add(GetContainer(), s_button
);
90 gtk_widget_realize(s_button
);
96 GtkWidget
* GetComboBoxWidget()
98 static GtkWidget
*s_button
= NULL
;
99 static GtkWidget
*s_window
= NULL
;
103 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
104 gtk_widget_realize( s_window
);
105 s_button
= gtk_combo_box_new();
106 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
107 gtk_widget_realize( s_button
);
114 GtkWidget
*GetEntryWidget()
116 static GtkWidget
*s_entry
= NULL
;
120 s_entry
= gtk_entry_new();
121 gtk_container_add(GetContainer(), s_entry
);
122 gtk_widget_realize(s_entry
);
128 // This one just gets the button used by the column header. Although it's
129 // still a gtk_button the themes will typically differentiate and draw them
130 // differently if the button is in a treeview.
131 static GtkWidget
*s_first_button
= NULL
;
132 static GtkWidget
*s_other_button
= NULL
;
133 static GtkWidget
*s_last_button
= NULL
;
135 static void CreateHeaderButtons()
137 // Get the dummy tree widget, give it a column, and then use the
138 // widget in the column header for the rendering code.
139 GtkWidget
* treewidget
= GetTreeWidget();
141 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
142 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
144 s_first_button
= gtk_tree_view_column_get_button(column
);
146 s_first_button
= column
->button
;
148 wxASSERT(s_first_button
);
150 column
= gtk_tree_view_column_new();
151 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
153 s_other_button
= gtk_tree_view_column_get_button(column
);
155 s_other_button
= column
->button
;
158 column
= gtk_tree_view_column_new();
159 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget
), column
);
161 s_last_button
= gtk_tree_view_column_get_button(column
);
163 s_last_button
= column
->button
;
167 GtkWidget
*GetHeaderButtonWidgetFirst()
170 CreateHeaderButtons();
172 return s_first_button
;
175 GtkWidget
*GetHeaderButtonWidgetLast()
178 CreateHeaderButtons();
180 return s_last_button
;
183 GtkWidget
*GetHeaderButtonWidget()
186 CreateHeaderButtons();
188 return s_other_button
;
191 GtkWidget
* GetRadioButtonWidget()
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_radio_button_new(NULL
);
201 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
202 gtk_widget_realize( s_button
);
208 GtkWidget
* GetSplitterWidget(wxOrientation orient
)
210 static GtkWidget
* widgets
[2];
211 const GtkOrientation gtkOrient
=
212 orient
== wxHORIZONTAL
? GTK_ORIENTATION_HORIZONTAL
: GTK_ORIENTATION_VERTICAL
;
213 GtkWidget
*& widget
= widgets
[gtkOrient
];
217 widget
= gtk_paned_new(gtkOrient
);
219 if (orient
== wxHORIZONTAL
)
220 widget
= gtk_hpaned_new();
222 widget
= gtk_vpaned_new();
224 gtk_container_add(GetContainer(), widget
);
225 gtk_widget_realize(widget
);
231 GtkWidget
* GetTextEntryWidget()
233 static GtkWidget
*s_button
= NULL
;
234 static GtkWidget
*s_window
= NULL
;
238 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
239 gtk_widget_realize( s_window
);
240 s_button
= gtk_entry_new();
241 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
242 gtk_widget_realize( s_button
);
248 GtkWidget
*GetTreeWidget()
250 static GtkWidget
*s_tree
= NULL
;
254 s_tree
= gtk_tree_view_new();
255 gtk_container_add(GetContainer(), s_tree
);
256 gtk_widget_realize(s_tree
);
262 // Module for destroying created widgets
263 class WidgetsCleanupModule
: public wxModule
266 virtual bool OnInit()
271 virtual void OnExit()
275 GtkWidget
* parent
= gtk_widget_get_parent(gs_container
);
276 gtk_widget_destroy(parent
);
280 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule
)
283 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule
, wxModule
)
285 static WidgetsCleanupModule gs_widgetsCleanupModule
;
287 } // wxGTKPrivate namespace