]>
Commit | Line | Data |
---|---|---|
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 <gtk/gtk.h> | |
32 | #include "wx/gtk/private.h" | |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // wxGTKPrivate functions implementation | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | namespace wxGTKPrivate | |
39 | { | |
40 | ||
41 | static GtkWidget *gs_container = NULL; | |
42 | ||
43 | static GtkContainer* GetContainer() | |
44 | { | |
45 | if ( gs_container == NULL ) | |
46 | { | |
47 | GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); | |
48 | gs_container = gtk_fixed_new(); | |
49 | gtk_container_add(GTK_CONTAINER(window), gs_container); | |
50 | } | |
51 | return GTK_CONTAINER(gs_container); | |
52 | } | |
53 | ||
54 | GtkWidget *GetButtonWidget() | |
55 | { | |
56 | static GtkWidget *s_button = NULL; | |
57 | ||
58 | if ( !s_button ) | |
59 | { | |
60 | s_button = gtk_button_new(); | |
61 | gtk_container_add(GetContainer(), s_button); | |
62 | gtk_widget_realize(s_button); | |
63 | } | |
64 | ||
65 | return s_button; | |
66 | } | |
67 | ||
68 | GtkWidget *GetNotebookWidget() | |
69 | { | |
70 | static GtkWidget *s_notebook = NULL; | |
71 | ||
72 | if ( !s_notebook ) | |
73 | { | |
74 | s_notebook = gtk_notebook_new(); | |
75 | gtk_container_add(GetContainer(), s_notebook); | |
76 | gtk_widget_realize(s_notebook); | |
77 | } | |
78 | ||
79 | return s_notebook; | |
80 | } | |
81 | ||
82 | GtkWidget *GetCheckButtonWidget() | |
83 | { | |
84 | static GtkWidget *s_button = NULL; | |
85 | ||
86 | if ( !s_button ) | |
87 | { | |
88 | s_button = gtk_check_button_new(); | |
89 | gtk_container_add(GetContainer(), s_button); | |
90 | gtk_widget_realize(s_button); | |
91 | } | |
92 | ||
93 | return s_button; | |
94 | } | |
95 | ||
96 | GtkWidget * GetComboBoxWidget() | |
97 | { | |
98 | static GtkWidget *s_button = NULL; | |
99 | static GtkWidget *s_window = NULL; | |
100 | ||
101 | if ( !s_button ) | |
102 | { | |
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 ); | |
108 | } | |
109 | ||
110 | return s_button; | |
111 | } | |
112 | ||
113 | ||
114 | GtkWidget *GetEntryWidget() | |
115 | { | |
116 | static GtkWidget *s_entry = NULL; | |
117 | ||
118 | if ( !s_entry ) | |
119 | { | |
120 | s_entry = gtk_entry_new(); | |
121 | gtk_container_add(GetContainer(), s_entry); | |
122 | gtk_widget_realize(s_entry); | |
123 | } | |
124 | ||
125 | return s_entry; | |
126 | } | |
127 | ||
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; | |
134 | ||
135 | static void CreateHeaderButtons() | |
136 | { | |
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(); | |
140 | ||
141 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); | |
142 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
143 | #ifdef __WXGTK3__ | |
144 | s_first_button = gtk_tree_view_column_get_button(column); | |
145 | #else | |
146 | s_first_button = column->button; | |
147 | #endif | |
148 | wxASSERT(s_first_button); | |
149 | ||
150 | column = gtk_tree_view_column_new(); | |
151 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
152 | #ifdef __WXGTK3__ | |
153 | s_other_button = gtk_tree_view_column_get_button(column); | |
154 | #else | |
155 | s_other_button = column->button; | |
156 | #endif | |
157 | ||
158 | column = gtk_tree_view_column_new(); | |
159 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
160 | #ifdef __WXGTK3__ | |
161 | s_last_button = gtk_tree_view_column_get_button(column); | |
162 | #else | |
163 | s_last_button = column->button; | |
164 | #endif | |
165 | } | |
166 | ||
167 | GtkWidget *GetHeaderButtonWidgetFirst() | |
168 | { | |
169 | if (!s_first_button) | |
170 | CreateHeaderButtons(); | |
171 | ||
172 | return s_first_button; | |
173 | } | |
174 | ||
175 | GtkWidget *GetHeaderButtonWidgetLast() | |
176 | { | |
177 | if (!s_last_button) | |
178 | CreateHeaderButtons(); | |
179 | ||
180 | return s_last_button; | |
181 | } | |
182 | ||
183 | GtkWidget *GetHeaderButtonWidget() | |
184 | { | |
185 | if (!s_other_button) | |
186 | CreateHeaderButtons(); | |
187 | ||
188 | return s_other_button; | |
189 | } | |
190 | ||
191 | GtkWidget * GetRadioButtonWidget() | |
192 | { | |
193 | static GtkWidget *s_button = NULL; | |
194 | static GtkWidget *s_window = NULL; | |
195 | ||
196 | if ( !s_button ) | |
197 | { | |
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 ); | |
203 | } | |
204 | ||
205 | return s_button; | |
206 | } | |
207 | ||
208 | GtkWidget* GetSplitterWidget(wxOrientation orient) | |
209 | { | |
210 | static GtkWidget* widgets[2]; | |
211 | const GtkOrientation gtkOrient = | |
212 | orient == wxHORIZONTAL ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; | |
213 | GtkWidget*& widget = widgets[gtkOrient]; | |
214 | if (widget == NULL) | |
215 | { | |
216 | #ifdef __WXGTK3__ | |
217 | widget = gtk_paned_new(gtkOrient); | |
218 | #else | |
219 | if (orient == wxHORIZONTAL) | |
220 | widget = gtk_hpaned_new(); | |
221 | else | |
222 | widget = gtk_vpaned_new(); | |
223 | #endif | |
224 | gtk_container_add(GetContainer(), widget); | |
225 | gtk_widget_realize(widget); | |
226 | } | |
227 | ||
228 | return widget; | |
229 | } | |
230 | ||
231 | GtkWidget * GetTextEntryWidget() | |
232 | { | |
233 | static GtkWidget *s_button = NULL; | |
234 | static GtkWidget *s_window = NULL; | |
235 | ||
236 | if ( !s_button ) | |
237 | { | |
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 ); | |
243 | } | |
244 | ||
245 | return s_button; | |
246 | } | |
247 | ||
248 | GtkWidget *GetTreeWidget() | |
249 | { | |
250 | static GtkWidget *s_tree = NULL; | |
251 | ||
252 | if ( !s_tree ) | |
253 | { | |
254 | s_tree = gtk_tree_view_new(); | |
255 | gtk_container_add(GetContainer(), s_tree); | |
256 | gtk_widget_realize(s_tree); | |
257 | } | |
258 | ||
259 | return s_tree; | |
260 | } | |
261 | ||
262 | // Module for destroying created widgets | |
263 | class WidgetsCleanupModule : public wxModule | |
264 | { | |
265 | public: | |
266 | virtual bool OnInit() | |
267 | { | |
268 | return true; | |
269 | } | |
270 | ||
271 | virtual void OnExit() | |
272 | { | |
273 | if ( gs_container ) | |
274 | { | |
275 | GtkWidget* parent = gtk_widget_get_parent(gs_container); | |
276 | gtk_widget_destroy(parent); | |
277 | } | |
278 | } | |
279 | ||
280 | DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule) | |
281 | }; | |
282 | ||
283 | IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule) | |
284 | ||
285 | static WidgetsCleanupModule gs_widgetsCleanupModule; | |
286 | ||
287 | } // wxGTKPrivate namespace |