]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/private.cpp
Correctly align background brush when erasing owner drawn bitmaps in wxMSW.
[wxWidgets.git] / src / gtk / private.cpp
... / ...
CommitLineData
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// Licence: 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
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
67GtkWidget *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
81GtkWidget * 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
99GtkWidget *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.
116static GtkWidget *s_first_button = NULL;
117static GtkWidget *s_other_button = NULL;
118static GtkWidget *s_last_button = NULL;
119
120static void CreateHeaderButtons()
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
126 GtkTreeViewColumn *column = gtk_tree_view_column_new();
127 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
128 s_first_button = column->button;
129
130 column = gtk_tree_view_column_new();
131 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
132 s_other_button = column->button;
133
134 column = gtk_tree_view_column_new();
135 gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column);
136 s_last_button = column->button;
137}
138
139GtkWidget *GetHeaderButtonWidgetFirst()
140{
141 if (!s_first_button)
142 CreateHeaderButtons();
143
144 return s_first_button;
145}
146
147GtkWidget *GetHeaderButtonWidgetLast()
148{
149 if (!s_last_button)
150 CreateHeaderButtons();
151
152 return s_last_button;
153}
154
155GtkWidget *GetHeaderButtonWidget()
156{
157 if (!s_other_button)
158 CreateHeaderButtons();
159
160 return s_other_button;
161}
162
163GtkWidget * GetRadioButtonWidget()
164{
165 static GtkWidget *s_button = NULL;
166 static GtkWidget *s_window = NULL;
167
168 if ( !s_button )
169 {
170 s_window = gtk_window_new( GTK_WINDOW_POPUP );
171 gtk_widget_realize( s_window );
172 s_button = gtk_radio_button_new(NULL);
173 gtk_container_add( GTK_CONTAINER(s_window), s_button );
174 gtk_widget_realize( s_button );
175 }
176
177 return s_button;
178}
179
180GtkWidget* GetSplitterWidget()
181{
182 static GtkWidget* widget;
183
184 if (widget == NULL)
185 {
186 widget = gtk_vpaned_new();
187 gtk_container_add(GetContainer(), widget);
188 gtk_widget_realize(widget);
189 }
190
191 return widget;
192}
193
194GtkWidget * GetTextEntryWidget()
195{
196 static GtkWidget *s_button = NULL;
197 static GtkWidget *s_window = NULL;
198
199 if ( !s_button )
200 {
201 s_window = gtk_window_new( GTK_WINDOW_POPUP );
202 gtk_widget_realize( s_window );
203 s_button = gtk_entry_new();
204 gtk_container_add( GTK_CONTAINER(s_window), s_button );
205 gtk_widget_realize( s_button );
206 }
207
208 return s_button;
209}
210
211GtkWidget *GetTreeWidget()
212{
213 static GtkWidget *s_tree = NULL;
214
215 if ( !s_tree )
216 {
217 s_tree = gtk_tree_view_new();
218 gtk_container_add(GetContainer(), s_tree);
219 gtk_widget_realize(s_tree);
220 }
221
222 return s_tree;
223}
224
225
226// Module for destroying created widgets
227class WidgetsCleanupModule : public wxModule
228{
229public:
230 virtual bool OnInit()
231 {
232 return true;
233 }
234
235 virtual void OnExit()
236 {
237 if ( gs_container )
238 {
239 GtkWidget* parent = gtk_widget_get_parent(gs_container);
240 gtk_widget_destroy(parent);
241 }
242 }
243
244 DECLARE_DYNAMIC_CLASS(WidgetsCleanupModule)
245};
246
247IMPLEMENT_DYNAMIC_CLASS(WidgetsCleanupModule, wxModule)
248
249static WidgetsCleanupModule gs_widgetsCleanupModule;
250
251} // wxGTKPrivate namespace