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