]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/private.cpp
use wxWindow::GetClientSize() instead of ::GetClientRect() in wxActiveXContainer...
[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 GtkWidget *GetHeaderButtonWidget()
117 {
118 static GtkWidget *s_button = NULL;
119
120 if ( !s_button )
121 {
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();
125 GtkTreeViewColumn *column = gtk_tree_view_column_new();
126 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
127 s_button = column->button;
128 }
129
130 return s_button;
131 }
132
133 GtkWidget * GetRadioButtonWidget()
134 {
135 static GtkWidget *s_button = NULL;
136 static GtkWidget *s_window = NULL;
137
138 if ( !s_button )
139 {
140 s_window = gtk_window_new( GTK_WINDOW_POPUP );
141 gtk_widget_realize( s_window );
142 s_button = gtk_radio_button_new(NULL);
143 gtk_container_add( GTK_CONTAINER(s_window), s_button );
144 gtk_widget_realize( s_button );
145 }
146
147 return s_button;
148 }
149
150 GtkWidget* GetSplitterWidget()
151 {
152 static GtkWidget* widget;
153
154 if (widget == NULL)
155 {
156 widget = gtk_vpaned_new();
157 gtk_container_add(GetContainer(), widget);
158 gtk_widget_realize(widget);
159 }
160
161 return widget;
162 }
163
164 GtkWidget * GetTextEntryWidget()
165 {
166 static GtkWidget *s_button = NULL;
167 static GtkWidget *s_window = NULL;
168
169 if ( !s_button )
170 {
171 s_window = gtk_window_new( GTK_WINDOW_POPUP );
172 gtk_widget_realize( s_window );
173 s_button = gtk_entry_new();
174 gtk_container_add( GTK_CONTAINER(s_window), s_button );
175 gtk_widget_realize( s_button );
176 }
177
178 return s_button;
179 }
180
181 GtkWidget *GetTreeWidget()
182 {
183 static GtkWidget *s_tree = NULL;
184
185 if ( !s_tree )
186 {
187 s_tree = gtk_tree_view_new();
188 gtk_container_add(GetContainer(), s_tree);
189 gtk_widget_realize(s_tree);
190 }
191
192 return s_tree;
193 }
194
195
196 // Module for destroying created widgets
197 class WidgetsCleanupModule : public wxModule
198 {
199 public:
200 virtual bool OnInit()
201 {
202 return true;
203 }
204
205 virtual void OnExit()
206 {
207 if ( gs_container )
208 {
209 GtkWidget* parent = gtk_widget_get_parent(gs_container);
210 gtk_widget_destroy(parent);
211 }
212 }
213
214 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule)
215 };
216
217 IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
218
219 static WidgetsCleanupModule gs_widgetsCleanupModule;
220
221 } // wxGTKPrivate namespace