The last button also looks different in the header control
[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 // License: 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 *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
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
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.
116 static GtkWidget *s_first_button = NULL;
117 static GtkWidget *s_other_button = NULL;
118 static GtkWidget *s_last_button = NULL;
119
120 GtkWidget *GetHeaderButtonWidgetFirst()
121 {
122
123 if ( !s_first_button )
124 {
125 // Get the dummy tree widget, give it a column, and then use the
126 // widget in the column header for the rendering code.
127 GtkWidget* treewidget = GetTreeWidget();
128
129 GtkTreeViewColumn *column = gtk_tree_view_column_new();
130 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
131 s_first_button = column->button;
132
133 column = gtk_tree_view_column_new();
134 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
135 s_other_button = column->button;
136
137 column = gtk_tree_view_column_new();
138 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
139 s_last_button = column->button;
140 }
141
142 return s_first_button;
143 }
144
145 GtkWidget *GetHeaderButtonWidget()
146 {
147 if ( !s_other_button )
148 {
149 // Get the dummy tree widget, give it a column, and then use the
150 // widget in the column header for the rendering code.
151 GtkWidget* treewidget = GetTreeWidget();
152
153 GtkTreeViewColumn *column = gtk_tree_view_column_new();
154 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
155 s_first_button = column->button;
156
157 column = gtk_tree_view_column_new();
158 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
159 s_other_button = column->button;
160
161 column = gtk_tree_view_column_new();
162 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
163 s_last_button = column->button;
164 }
165
166 return s_other_button;
167 }
168
169 GtkWidget * GetRadioButtonWidget()
170 {
171 static GtkWidget *s_button = NULL;
172 static GtkWidget *s_window = NULL;
173
174 if ( !s_button )
175 {
176 s_window = gtk_window_new( GTK_WINDOW_POPUP );
177 gtk_widget_realize( s_window );
178 s_button = gtk_radio_button_new(NULL);
179 gtk_container_add( GTK_CONTAINER(s_window), s_button );
180 gtk_widget_realize( s_button );
181 }
182
183 return s_button;
184 }
185
186 GtkWidget* GetSplitterWidget()
187 {
188 static GtkWidget* widget;
189
190 if (widget == NULL)
191 {
192 widget = gtk_vpaned_new();
193 gtk_container_add(GetContainer(), widget);
194 gtk_widget_realize(widget);
195 }
196
197 return widget;
198 }
199
200 GtkWidget * GetTextEntryWidget()
201 {
202 static GtkWidget *s_button = NULL;
203 static GtkWidget *s_window = NULL;
204
205 if ( !s_button )
206 {
207 s_window = gtk_window_new( GTK_WINDOW_POPUP );
208 gtk_widget_realize( s_window );
209 s_button = gtk_entry_new();
210 gtk_container_add( GTK_CONTAINER(s_window), s_button );
211 gtk_widget_realize( s_button );
212 }
213
214 return s_button;
215 }
216
217 GtkWidget *GetTreeWidget()
218 {
219 static GtkWidget *s_tree = NULL;
220
221 if ( !s_tree )
222 {
223 s_tree = gtk_tree_view_new();
224 gtk_container_add(GetContainer(), s_tree);
225 gtk_widget_realize(s_tree);
226 }
227
228 return s_tree;
229 }
230
231
232 // Module for destroying created widgets
233 class WidgetsCleanupModule : public wxModule
234 {
235 public:
236 virtual bool OnInit()
237 {
238 return true;
239 }
240
241 virtual void OnExit()
242 {
243 if ( gs_container )
244 {
245 GtkWidget* parent = gtk_widget_get_parent(gs_container);
246 gtk_widget_destroy(parent);
247 }
248 }
249
250 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule)
251 };
252
253 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
254
255 static WidgetsCleanupModule gs_widgetsCleanupModule;
256
257 } // wxGTKPrivate namespace