]>
Commit | Line | Data |
---|---|---|
e8759560 VZ |
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> | |
526954c5 | 9 | // Licence: wxWindows licence |
e8759560 VZ |
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 *GetCheckButtonWidget() | |
68 | { | |
69 | static GtkWidget *s_button = NULL; | |
70 | ||
71 | if ( !s_button ) | |
72 | { | |
73 | s_button = gtk_check_button_new(); | |
74 | gtk_container_add(GetContainer(), s_button); | |
75 | gtk_widget_realize(s_button); | |
76 | } | |
77 | ||
78 | return s_button; | |
79 | } | |
80 | ||
e4131985 KO |
81 | GtkWidget * GetComboBoxWidget() |
82 | { | |
83 | static GtkWidget *s_button = NULL; | |
84 | static GtkWidget *s_window = NULL; | |
85 | ||
86 | if ( !s_button ) | |
87 | { | |
88 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
89 | gtk_widget_realize( s_window ); | |
90 | s_button = gtk_combo_box_new(); | |
91 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
92 | gtk_widget_realize( s_button ); | |
93 | } | |
94 | ||
95 | return s_button; | |
96 | } | |
97 | ||
98 | ||
e8759560 VZ |
99 | GtkWidget *GetEntryWidget() |
100 | { | |
101 | static GtkWidget *s_entry = NULL; | |
102 | ||
103 | if ( !s_entry ) | |
104 | { | |
105 | s_entry = gtk_entry_new(); | |
106 | gtk_container_add(GetContainer(), s_entry); | |
107 | gtk_widget_realize(s_entry); | |
108 | } | |
109 | ||
110 | return s_entry; | |
111 | } | |
112 | ||
113 | // This one just gets the button used by the column header. Although it's | |
114 | // still a gtk_button the themes will typically differentiate and draw them | |
115 | // differently if the button is in a treeview. | |
25272c0f RR |
116 | static GtkWidget *s_first_button = NULL; |
117 | static GtkWidget *s_other_button = NULL; | |
73c42ee8 | 118 | static GtkWidget *s_last_button = NULL; |
e8759560 | 119 | |
ecdf2898 | 120 | static void CreateHeaderButtons() |
b047e876 | 121 | { |
e8759560 VZ |
122 | // Get the dummy tree widget, give it a column, and then use the |
123 | // widget in the column header for the rendering code. | |
124 | GtkWidget* treewidget = GetTreeWidget(); | |
03647350 | 125 | |
e8759560 VZ |
126 | GtkTreeViewColumn *column = gtk_tree_view_column_new(); |
127 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
25272c0f | 128 | s_first_button = column->button; |
03647350 | 129 | |
25272c0f RR |
130 | column = gtk_tree_view_column_new(); |
131 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
132 | s_other_button = column->button; | |
03647350 | 133 | |
73c42ee8 RR |
134 | column = gtk_tree_view_column_new(); |
135 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
136 | s_last_button = column->button; | |
b047e876 | 137 | } |
03647350 | 138 | |
b047e876 RR |
139 | GtkWidget *GetHeaderButtonWidgetFirst() |
140 | { | |
141 | if (!s_first_button) | |
142 | CreateHeaderButtons(); | |
e8759560 | 143 | |
25272c0f RR |
144 | return s_first_button; |
145 | } | |
146 | ||
b047e876 RR |
147 | GtkWidget *GetHeaderButtonWidgetLast() |
148 | { | |
149 | if (!s_last_button) | |
150 | CreateHeaderButtons(); | |
151 | ||
152 | return s_last_button; | |
153 | } | |
154 | ||
25272c0f RR |
155 | GtkWidget *GetHeaderButtonWidget() |
156 | { | |
b047e876 RR |
157 | if (!s_other_button) |
158 | CreateHeaderButtons(); | |
25272c0f RR |
159 | |
160 | return s_other_button; | |
e8759560 VZ |
161 | } |
162 | ||
e4131985 KO |
163 | GtkWidget * GetRadioButtonWidget() |
164 | { | |
165 | static GtkWidget *s_button = NULL; | |
166 | static GtkWidget *s_window = NULL; | |
167 | ||
168 | if ( !s_button ) | |
169 | { | |
170 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
171 | gtk_widget_realize( s_window ); | |
172 | s_button = gtk_radio_button_new(NULL); | |
173 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
174 | gtk_widget_realize( s_button ); | |
175 | } | |
176 | ||
177 | return s_button; | |
178 | } | |
179 | ||
e8759560 VZ |
180 | GtkWidget* GetSplitterWidget() |
181 | { | |
182 | static GtkWidget* widget; | |
183 | ||
184 | if (widget == NULL) | |
185 | { | |
186 | widget = gtk_vpaned_new(); | |
187 | gtk_container_add(GetContainer(), widget); | |
188 | gtk_widget_realize(widget); | |
189 | } | |
190 | ||
191 | return widget; | |
192 | } | |
193 | ||
e4131985 KO |
194 | GtkWidget * GetTextEntryWidget() |
195 | { | |
196 | static GtkWidget *s_button = NULL; | |
197 | static GtkWidget *s_window = NULL; | |
198 | ||
199 | if ( !s_button ) | |
200 | { | |
201 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
202 | gtk_widget_realize( s_window ); | |
203 | s_button = gtk_entry_new(); | |
204 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
205 | gtk_widget_realize( s_button ); | |
206 | } | |
207 | ||
208 | return s_button; | |
209 | } | |
210 | ||
e8759560 VZ |
211 | GtkWidget *GetTreeWidget() |
212 | { | |
213 | static GtkWidget *s_tree = NULL; | |
214 | ||
215 | if ( !s_tree ) | |
216 | { | |
217 | s_tree = gtk_tree_view_new(); | |
218 | gtk_container_add(GetContainer(), s_tree); | |
219 | gtk_widget_realize(s_tree); | |
220 | } | |
221 | ||
222 | return s_tree; | |
223 | } | |
224 | ||
225 | ||
226 | // Module for destroying created widgets | |
227 | class WidgetsCleanupModule : public wxModule | |
228 | { | |
229 | public: | |
230 | virtual bool OnInit() | |
231 | { | |
232 | return true; | |
233 | } | |
234 | ||
235 | virtual void OnExit() | |
236 | { | |
237 | if ( gs_container ) | |
238 | { | |
239 | GtkWidget* parent = gtk_widget_get_parent(gs_container); | |
240 | gtk_widget_destroy(parent); | |
241 | } | |
242 | } | |
243 | ||
244 | DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule) | |
245 | }; | |
246 | ||
247 | IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule) | |
248 | ||
249 | static WidgetsCleanupModule gs_widgetsCleanupModule; | |
250 | ||
251 | } // wxGTKPrivate namespace |