]>
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 | // Copyright: (c) 2008 Marcin Malich <me@malcom.pl> | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | // for compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/module.h" | |
28 | #endif | |
29 | ||
30 | #include <gtk/gtk.h> | |
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 | #ifdef __WXGTK3__ | |
143 | s_first_button = gtk_tree_view_column_get_button(column); | |
144 | #else | |
145 | s_first_button = column->button; | |
146 | #endif | |
147 | wxASSERT(s_first_button); | |
148 | ||
149 | column = gtk_tree_view_column_new(); | |
150 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
151 | #ifdef __WXGTK3__ | |
152 | s_other_button = gtk_tree_view_column_get_button(column); | |
153 | #else | |
154 | s_other_button = column->button; | |
155 | #endif | |
156 | ||
157 | column = gtk_tree_view_column_new(); | |
158 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
159 | #ifdef __WXGTK3__ | |
160 | s_last_button = gtk_tree_view_column_get_button(column); | |
161 | #else | |
162 | s_last_button = column->button; | |
163 | #endif | |
164 | } | |
165 | ||
166 | GtkWidget *GetHeaderButtonWidgetFirst() | |
167 | { | |
168 | if (!s_first_button) | |
169 | CreateHeaderButtons(); | |
170 | ||
171 | return s_first_button; | |
172 | } | |
173 | ||
174 | GtkWidget *GetHeaderButtonWidgetLast() | |
175 | { | |
176 | if (!s_last_button) | |
177 | CreateHeaderButtons(); | |
178 | ||
179 | return s_last_button; | |
180 | } | |
181 | ||
182 | GtkWidget *GetHeaderButtonWidget() | |
183 | { | |
184 | if (!s_other_button) | |
185 | CreateHeaderButtons(); | |
186 | ||
187 | return s_other_button; | |
188 | } | |
189 | ||
190 | GtkWidget * GetRadioButtonWidget() | |
191 | { | |
192 | static GtkWidget *s_button = NULL; | |
193 | static GtkWidget *s_window = NULL; | |
194 | ||
195 | if ( !s_button ) | |
196 | { | |
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 ); | |
202 | } | |
203 | ||
204 | return s_button; | |
205 | } | |
206 | ||
207 | GtkWidget* GetSplitterWidget(wxOrientation orient) | |
208 | { | |
209 | static GtkWidget* widgets[2]; | |
210 | const GtkOrientation gtkOrient = | |
211 | orient == wxHORIZONTAL ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; | |
212 | GtkWidget*& widget = widgets[gtkOrient]; | |
213 | if (widget == NULL) | |
214 | { | |
215 | #ifdef __WXGTK3__ | |
216 | widget = gtk_paned_new(gtkOrient); | |
217 | #else | |
218 | if (orient == wxHORIZONTAL) | |
219 | widget = gtk_hpaned_new(); | |
220 | else | |
221 | widget = gtk_vpaned_new(); | |
222 | #endif | |
223 | gtk_container_add(GetContainer(), widget); | |
224 | gtk_widget_realize(widget); | |
225 | } | |
226 | ||
227 | return widget; | |
228 | } | |
229 | ||
230 | GtkWidget * GetTextEntryWidget() | |
231 | { | |
232 | static GtkWidget *s_button = NULL; | |
233 | static GtkWidget *s_window = NULL; | |
234 | ||
235 | if ( !s_button ) | |
236 | { | |
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 ); | |
242 | } | |
243 | ||
244 | return s_button; | |
245 | } | |
246 | ||
247 | GtkWidget *GetTreeWidget() | |
248 | { | |
249 | static GtkWidget *s_tree = NULL; | |
250 | ||
251 | if ( !s_tree ) | |
252 | { | |
253 | s_tree = gtk_tree_view_new(); | |
254 | gtk_container_add(GetContainer(), s_tree); | |
255 | gtk_widget_realize(s_tree); | |
256 | } | |
257 | ||
258 | return s_tree; | |
259 | } | |
260 | ||
261 | // Module for destroying created widgets | |
262 | class WidgetsCleanupModule : public wxModule | |
263 | { | |
264 | public: | |
265 | virtual bool OnInit() | |
266 | { | |
267 | return true; | |
268 | } | |
269 | ||
270 | virtual void OnExit() | |
271 | { | |
272 | if ( gs_container ) | |
273 | { | |
274 | GtkWidget* parent = gtk_widget_get_parent(gs_container); | |
275 | gtk_widget_destroy(parent); | |
276 | } | |
277 | } | |
278 | ||
279 | DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule) | |
280 | }; | |
281 | ||
282 | IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule) | |
283 | ||
284 | static WidgetsCleanupModule gs_widgetsCleanupModule; | |
285 | ||
286 | } // wxGTKPrivate namespace |