]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/private.cpp
fix warnings about unreachable return statements
[wxWidgets.git] / src / gtk / private.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/private.cpp
3 // Purpose: implementation of wxGTK private functions
4 // Author: Marcin Malich
5 // Modified by:
6 // Created: 28.06.2008
7 // RCS-ID: $Id$
8 // Copyright: (c) 2008 Marcin Malich <me@malcom.pl>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/module.h"
29 #endif
30
31 #include "wx/gtk/private.h"
32
33 // ----------------------------------------------------------------------------
34 // wxGTKPrivate functions implementation
35 // ----------------------------------------------------------------------------
36
37 namespace wxGTKPrivate
38 {
39
40 static GtkWidget *gs_container = NULL;
41
42 static GtkContainer* GetContainer()
43 {
44 if ( gs_container == NULL )
45 {
46 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
47 gs_container = gtk_fixed_new();
48 gtk_container_add(GTK_CONTAINER(window), gs_container);
49 }
50 return GTK_CONTAINER(gs_container);
51 }
52
53 GtkWidget *GetButtonWidget()
54 {
55 static GtkWidget *s_button = NULL;
56
57 if ( !s_button )
58 {
59 s_button = gtk_button_new();
60 gtk_container_add(GetContainer(), s_button);
61 gtk_widget_realize(s_button);
62 }
63
64 return s_button;
65 }
66
67 GtkWidget *GetNotebookWidget()
68 {
69 static GtkWidget *s_notebook = NULL;
70
71 if ( !s_notebook )
72 {
73 s_notebook = gtk_notebook_new();
74 gtk_container_add(GetContainer(), s_notebook);
75 gtk_widget_realize(s_notebook);
76 }
77
78 return s_notebook;
79 }
80
81 GtkWidget *GetCheckButtonWidget()
82 {
83 static GtkWidget *s_button = NULL;
84
85 if ( !s_button )
86 {
87 s_button = gtk_check_button_new();
88 gtk_container_add(GetContainer(), s_button);
89 gtk_widget_realize(s_button);
90 }
91
92 return s_button;
93 }
94
95 GtkWidget * GetComboBoxWidget()
96 {
97 static GtkWidget *s_button = NULL;
98 static GtkWidget *s_window = NULL;
99
100 if ( !s_button )
101 {
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 );
107 }
108
109 return s_button;
110 }
111
112
113 GtkWidget *GetEntryWidget()
114 {
115 static GtkWidget *s_entry = NULL;
116
117 if ( !s_entry )
118 {
119 s_entry = gtk_entry_new();
120 gtk_container_add(GetContainer(), s_entry);
121 gtk_widget_realize(s_entry);
122 }
123
124 return s_entry;
125 }
126
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;
133
134 static void CreateHeaderButtons()
135 {
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();
139
140 GtkTreeViewColumn *column = gtk_tree_view_column_new();
141 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
142 s_first_button = column->button;
143
144 column = gtk_tree_view_column_new();
145 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
146 s_other_button = column->button;
147
148 column = gtk_tree_view_column_new();
149 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
150 s_last_button = column->button;
151 }
152
153 GtkWidget *GetHeaderButtonWidgetFirst()
154 {
155 if (!s_first_button)
156 CreateHeaderButtons();
157
158 return s_first_button;
159 }
160
161 GtkWidget *GetHeaderButtonWidgetLast()
162 {
163 if (!s_last_button)
164 CreateHeaderButtons();
165
166 return s_last_button;
167 }
168
169 GtkWidget *GetHeaderButtonWidget()
170 {
171 if (!s_other_button)
172 CreateHeaderButtons();
173
174 return s_other_button;
175 }
176
177 GtkWidget * GetRadioButtonWidget()
178 {
179 static GtkWidget *s_button = NULL;
180 static GtkWidget *s_window = NULL;
181
182 if ( !s_button )
183 {
184 s_window = gtk_window_new( GTK_WINDOW_POPUP );
185 gtk_widget_realize( s_window );
186 s_button = gtk_radio_button_new(NULL);
187 gtk_container_add( GTK_CONTAINER(s_window), s_button );
188 gtk_widget_realize( s_button );
189 }
190
191 return s_button;
192 }
193
194 GtkWidget* GetSplitterWidget()
195 {
196 static GtkWidget* widget;
197
198 if (widget == NULL)
199 {
200 widget = gtk_vpaned_new();
201 gtk_container_add(GetContainer(), widget);
202 gtk_widget_realize(widget);
203 }
204
205 return widget;
206 }
207
208 GtkWidget * GetTextEntryWidget()
209 {
210 static GtkWidget *s_button = NULL;
211 static GtkWidget *s_window = NULL;
212
213 if ( !s_button )
214 {
215 s_window = gtk_window_new( GTK_WINDOW_POPUP );
216 gtk_widget_realize( s_window );
217 s_button = gtk_entry_new();
218 gtk_container_add( GTK_CONTAINER(s_window), s_button );
219 gtk_widget_realize( s_button );
220 }
221
222 return s_button;
223 }
224
225 GtkWidget *GetTreeWidget()
226 {
227 static GtkWidget *s_tree = NULL;
228
229 if ( !s_tree )
230 {
231 s_tree = gtk_tree_view_new();
232 gtk_container_add(GetContainer(), s_tree);
233 gtk_widget_realize(s_tree);
234 }
235
236 return s_tree;
237 }
238
239
240 // Module for destroying created widgets
241 class WidgetsCleanupModule : public wxModule
242 {
243 public:
244 virtual bool OnInit()
245 {
246 return true;
247 }
248
249 virtual void OnExit()
250 {
251 if ( gs_container )
252 {
253 GtkWidget* parent = gtk_widget_get_parent(gs_container);
254 gtk_widget_destroy(parent);
255 }
256 }
257
258 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule)
259 };
260
261 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
262
263 static WidgetsCleanupModule gs_widgetsCleanupModule;
264
265 } // wxGTKPrivate namespace