]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/private.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / gtk / private.cpp
CommitLineData
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
e8759560 7// Copyright: (c) 2008 Marcin Malich <me@malcom.pl>
526954c5 8// Licence: wxWindows licence
e8759560
VZ
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
9dc44eff 30#include <gtk/gtk.h>
e8759560
VZ
31#include "wx/gtk/private.h"
32
33// ----------------------------------------------------------------------------
34// wxGTKPrivate functions implementation
35// ----------------------------------------------------------------------------
36
37namespace wxGTKPrivate
38{
39
40static GtkWidget *gs_container = NULL;
41
42static 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
53GtkWidget *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
740dd154
VZ
67GtkWidget *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
e8759560
VZ
81GtkWidget *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
e4131985
KO
95GtkWidget * 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
e8759560
VZ
113GtkWidget *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.
25272c0f
RR
130static GtkWidget *s_first_button = NULL;
131static GtkWidget *s_other_button = NULL;
73c42ee8 132static GtkWidget *s_last_button = NULL;
e8759560 133
ecdf2898 134static void CreateHeaderButtons()
b047e876 135{
e8759560
VZ
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();
03647350 139
e8759560
VZ
140 GtkTreeViewColumn *column = gtk_tree_view_column_new();
141 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
142#ifdef __WXGTK3__
143 s_first_button = gtk_tree_view_column_get_button(column);
144#else
25272c0f 145 s_first_button = column->button;
9dc44eff
PC
146#endif
147 wxASSERT(s_first_button);
03647350 148
25272c0f
RR
149 column = gtk_tree_view_column_new();
150 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
151#ifdef __WXGTK3__
152 s_other_button = gtk_tree_view_column_get_button(column);
153#else
25272c0f 154 s_other_button = column->button;
9dc44eff 155#endif
03647350 156
73c42ee8
RR
157 column = gtk_tree_view_column_new();
158 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
159#ifdef __WXGTK3__
160 s_last_button = gtk_tree_view_column_get_button(column);
161#else
73c42ee8 162 s_last_button = column->button;
9dc44eff 163#endif
b047e876 164}
03647350 165
b047e876
RR
166GtkWidget *GetHeaderButtonWidgetFirst()
167{
168 if (!s_first_button)
169 CreateHeaderButtons();
e8759560 170
25272c0f
RR
171 return s_first_button;
172}
173
b047e876
RR
174GtkWidget *GetHeaderButtonWidgetLast()
175{
176 if (!s_last_button)
177 CreateHeaderButtons();
178
179 return s_last_button;
180}
181
25272c0f
RR
182GtkWidget *GetHeaderButtonWidget()
183{
b047e876
RR
184 if (!s_other_button)
185 CreateHeaderButtons();
25272c0f
RR
186
187 return s_other_button;
e8759560
VZ
188}
189
e4131985
KO
190GtkWidget * 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
9dc44eff 207GtkWidget* GetSplitterWidget(wxOrientation orient)
e8759560 208{
9dc44eff
PC
209 static GtkWidget* widgets[2];
210 const GtkOrientation gtkOrient =
211 orient == wxHORIZONTAL ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
212 GtkWidget*& widget = widgets[gtkOrient];
e8759560
VZ
213 if (widget == NULL)
214 {
9dc44eff
PC
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
e8759560
VZ
223 gtk_container_add(GetContainer(), widget);
224 gtk_widget_realize(widget);
225 }
226
227 return widget;
228}
229
e4131985
KO
230GtkWidget * 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
e8759560
VZ
247GtkWidget *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
e8759560
VZ
261// Module for destroying created widgets
262class WidgetsCleanupModule : public wxModule
263{
264public:
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
282IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
283
284static WidgetsCleanupModule gs_widgetsCleanupModule;
285
286} // wxGTKPrivate namespace