]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/private.cpp
Use wxCONTROL_PRESSED instead of wxCONTROL_SELECTED in wxOSX renderer 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
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
9dc44eff 31#include <gtk/gtk.h>
e8759560
VZ
32#include "wx/gtk/private.h"
33
34// ----------------------------------------------------------------------------
35// wxGTKPrivate functions implementation
36// ----------------------------------------------------------------------------
37
38namespace wxGTKPrivate
39{
40
41static GtkWidget *gs_container = NULL;
42
43static GtkContainer* GetContainer()
44{
45 if ( gs_container == NULL )
46 {
47 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
48 gs_container = gtk_fixed_new();
49 gtk_container_add(GTK_CONTAINER(window), gs_container);
50 }
51 return GTK_CONTAINER(gs_container);
52}
53
54GtkWidget *GetButtonWidget()
55{
56 static GtkWidget *s_button = NULL;
57
58 if ( !s_button )
59 {
60 s_button = gtk_button_new();
61 gtk_container_add(GetContainer(), s_button);
62 gtk_widget_realize(s_button);
63 }
64
65 return s_button;
66}
67
740dd154
VZ
68GtkWidget *GetNotebookWidget()
69{
70 static GtkWidget *s_notebook = NULL;
71
72 if ( !s_notebook )
73 {
74 s_notebook = gtk_notebook_new();
75 gtk_container_add(GetContainer(), s_notebook);
76 gtk_widget_realize(s_notebook);
77 }
78
79 return s_notebook;
80}
81
e8759560
VZ
82GtkWidget *GetCheckButtonWidget()
83{
84 static GtkWidget *s_button = NULL;
85
86 if ( !s_button )
87 {
88 s_button = gtk_check_button_new();
89 gtk_container_add(GetContainer(), s_button);
90 gtk_widget_realize(s_button);
91 }
92
93 return s_button;
94}
95
e4131985
KO
96GtkWidget * GetComboBoxWidget()
97{
98 static GtkWidget *s_button = NULL;
99 static GtkWidget *s_window = NULL;
100
101 if ( !s_button )
102 {
103 s_window = gtk_window_new( GTK_WINDOW_POPUP );
104 gtk_widget_realize( s_window );
105 s_button = gtk_combo_box_new();
106 gtk_container_add( GTK_CONTAINER(s_window), s_button );
107 gtk_widget_realize( s_button );
108 }
109
110 return s_button;
111}
112
113
e8759560
VZ
114GtkWidget *GetEntryWidget()
115{
116 static GtkWidget *s_entry = NULL;
117
118 if ( !s_entry )
119 {
120 s_entry = gtk_entry_new();
121 gtk_container_add(GetContainer(), s_entry);
122 gtk_widget_realize(s_entry);
123 }
124
125 return s_entry;
126}
127
128// This one just gets the button used by the column header. Although it's
129// still a gtk_button the themes will typically differentiate and draw them
130// differently if the button is in a treeview.
25272c0f
RR
131static GtkWidget *s_first_button = NULL;
132static GtkWidget *s_other_button = NULL;
73c42ee8 133static GtkWidget *s_last_button = NULL;
e8759560 134
ecdf2898 135static void CreateHeaderButtons()
b047e876 136{
e8759560
VZ
137 // Get the dummy tree widget, give it a column, and then use the
138 // widget in the column header for the rendering code.
139 GtkWidget* treewidget = GetTreeWidget();
03647350 140
e8759560
VZ
141 GtkTreeViewColumn *column = gtk_tree_view_column_new();
142 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
143#ifdef __WXGTK3__
144 s_first_button = gtk_tree_view_column_get_button(column);
145#else
25272c0f 146 s_first_button = column->button;
9dc44eff
PC
147#endif
148 wxASSERT(s_first_button);
03647350 149
25272c0f
RR
150 column = gtk_tree_view_column_new();
151 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
152#ifdef __WXGTK3__
153 s_other_button = gtk_tree_view_column_get_button(column);
154#else
25272c0f 155 s_other_button = column->button;
9dc44eff 156#endif
03647350 157
73c42ee8
RR
158 column = gtk_tree_view_column_new();
159 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
9dc44eff
PC
160#ifdef __WXGTK3__
161 s_last_button = gtk_tree_view_column_get_button(column);
162#else
73c42ee8 163 s_last_button = column->button;
9dc44eff 164#endif
b047e876 165}
03647350 166
b047e876
RR
167GtkWidget *GetHeaderButtonWidgetFirst()
168{
169 if (!s_first_button)
170 CreateHeaderButtons();
e8759560 171
25272c0f
RR
172 return s_first_button;
173}
174
b047e876
RR
175GtkWidget *GetHeaderButtonWidgetLast()
176{
177 if (!s_last_button)
178 CreateHeaderButtons();
179
180 return s_last_button;
181}
182
25272c0f
RR
183GtkWidget *GetHeaderButtonWidget()
184{
b047e876
RR
185 if (!s_other_button)
186 CreateHeaderButtons();
25272c0f
RR
187
188 return s_other_button;
e8759560
VZ
189}
190
e4131985
KO
191GtkWidget * GetRadioButtonWidget()
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_radio_button_new(NULL);
201 gtk_container_add( GTK_CONTAINER(s_window), s_button );
202 gtk_widget_realize( s_button );
203 }
204
205 return s_button;
206}
207
9dc44eff 208GtkWidget* GetSplitterWidget(wxOrientation orient)
e8759560 209{
9dc44eff
PC
210 static GtkWidget* widgets[2];
211 const GtkOrientation gtkOrient =
212 orient == wxHORIZONTAL ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
213 GtkWidget*& widget = widgets[gtkOrient];
e8759560
VZ
214 if (widget == NULL)
215 {
9dc44eff
PC
216#ifdef __WXGTK3__
217 widget = gtk_paned_new(gtkOrient);
218#else
219 if (orient == wxHORIZONTAL)
220 widget = gtk_hpaned_new();
221 else
222 widget = gtk_vpaned_new();
223#endif
e8759560
VZ
224 gtk_container_add(GetContainer(), widget);
225 gtk_widget_realize(widget);
226 }
227
228 return widget;
229}
230
e4131985
KO
231GtkWidget * GetTextEntryWidget()
232{
233 static GtkWidget *s_button = NULL;
234 static GtkWidget *s_window = NULL;
235
236 if ( !s_button )
237 {
238 s_window = gtk_window_new( GTK_WINDOW_POPUP );
239 gtk_widget_realize( s_window );
240 s_button = gtk_entry_new();
241 gtk_container_add( GTK_CONTAINER(s_window), s_button );
242 gtk_widget_realize( s_button );
243 }
244
245 return s_button;
246}
247
e8759560
VZ
248GtkWidget *GetTreeWidget()
249{
250 static GtkWidget *s_tree = NULL;
251
252 if ( !s_tree )
253 {
254 s_tree = gtk_tree_view_new();
255 gtk_container_add(GetContainer(), s_tree);
256 gtk_widget_realize(s_tree);
257 }
258
259 return s_tree;
260}
261
e8759560
VZ
262// Module for destroying created widgets
263class WidgetsCleanupModule : public wxModule
264{
265public:
266 virtual bool OnInit()
267 {
268 return true;
269 }
270
271 virtual void OnExit()
272 {
273 if ( gs_container )
274 {
275 GtkWidget* parent = gtk_widget_get_parent(gs_container);
276 gtk_widget_destroy(parent);
277 }
278 }
279
280 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule)
281};
282
283IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
284
285static WidgetsCleanupModule gs_widgetsCleanupModule;
286
287} // wxGTKPrivate namespace