]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
19717c50 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
fe4e9e6c | 11 | #pragma implementation "frame.h" |
c801d85f KB |
12 | #endif |
13 | ||
14 | #include "wx/frame.h" | |
15 | #include "wx/dialog.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/app.h" | |
cf4219e7 | 18 | #include "wx/menu.h" |
dcf924a3 | 19 | #if wxUSE_TOOLBAR |
cf4219e7 | 20 | #include "wx/toolbar.h" |
dcf924a3 RR |
21 | #endif |
22 | #if wxUSE_STATUSBAR | |
cf4219e7 | 23 | #include "wx/statusbr.h" |
dcf924a3 | 24 | #endif |
362c6693 | 25 | #include "wx/dcclient.h" |
83624f79 RR |
26 | |
27 | #include "glib.h" | |
28 | #include "gdk/gdk.h" | |
29 | #include "gtk/gtk.h" | |
c801d85f | 30 | #include "wx/gtk/win_gtk.h" |
801aa178 | 31 | #include "gdk/gdkkeysyms.h" |
cd25b18c | 32 | #include "gdk/gdkx.h" |
c801d85f | 33 | |
2f2aa628 RR |
34 | //----------------------------------------------------------------------------- |
35 | // constants | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
907789a0 | 38 | const int wxMENU_HEIGHT = 27; |
c67daf87 | 39 | const int wxSTATUS_HEIGHT = 25; |
41ca191f | 40 | const int wxPLACE_HOLDER = 0; |
c801d85f | 41 | |
acfd422a RR |
42 | //----------------------------------------------------------------------------- |
43 | // idle system | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | extern void wxapp_install_idle_handler(); | |
47 | extern bool g_isIdle; | |
2d68e1b4 | 48 | extern int g_openDialogs; |
acfd422a | 49 | |
2f2aa628 RR |
50 | //----------------------------------------------------------------------------- |
51 | // data | |
52 | //----------------------------------------------------------------------------- | |
53 | ||
c801d85f KB |
54 | extern wxList wxPendingDelete; |
55 | ||
2e563988 RR |
56 | //----------------------------------------------------------------------------- |
57 | // debug | |
58 | //----------------------------------------------------------------------------- | |
59 | ||
60 | #ifdef __WXDEBUG__ | |
61 | ||
62 | extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ); | |
63 | ||
64 | #endif | |
65 | ||
69ffe1d2 RR |
66 | //----------------------------------------------------------------------------- |
67 | // "focus" from m_window | |
68 | //----------------------------------------------------------------------------- | |
69 | ||
70 | static gint gtk_frame_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) ) | |
71 | { | |
72 | if (g_isIdle) | |
73 | wxapp_install_idle_handler(); | |
74 | ||
75 | // This disables GTK's tab traversal | |
76 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" ); | |
77 | return TRUE; | |
78 | } | |
79 | ||
c801d85f | 80 | //----------------------------------------------------------------------------- |
2f2aa628 | 81 | // "size_allocate" |
c801d85f | 82 | //----------------------------------------------------------------------------- |
c801d85f | 83 | |
2f2aa628 | 84 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) |
ed7a557b | 85 | { |
88ac883a | 86 | if (g_isIdle) |
121a3581 | 87 | wxapp_install_idle_handler(); |
acfd422a | 88 | |
54517652 RR |
89 | if (!win->m_hasVMT) |
90 | return; | |
8bbe427f | 91 | |
121a3581 RR |
92 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
93 | { | |
54517652 RR |
94 | /* |
95 | wxPrintf( "OnSize from " ); | |
96 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
97 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
98 | wxPrintf( " %d %d %d %d\n", (int)alloc->x, | |
99 | (int)alloc->y, | |
100 | (int)alloc->width, | |
101 | (int)alloc->height ); | |
102 | */ | |
7beba2fc | 103 | |
121a3581 RR |
104 | win->m_width = alloc->width; |
105 | win->m_height = alloc->height; | |
106 | win->UpdateSize(); | |
107 | } | |
362c6693 | 108 | } |
c801d85f KB |
109 | |
110 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
111 | // "delete_event" |
112 | //----------------------------------------------------------------------------- | |
c801d85f | 113 | |
2f2aa628 | 114 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) |
ed7a557b | 115 | { |
88ac883a | 116 | if (g_isIdle) |
121a3581 | 117 | wxapp_install_idle_handler(); |
ed7a557b | 118 | |
2d68e1b4 RR |
119 | if (g_openDialogs == 0) |
120 | win->Close(); | |
c801d85f | 121 | |
fb1585ae | 122 | return TRUE; |
362c6693 | 123 | } |
c801d85f | 124 | |
16bcc879 RR |
125 | //----------------------------------------------------------------------------- |
126 | // "child_attached" of menu bar | |
127 | //----------------------------------------------------------------------------- | |
128 | ||
129 | static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
130 | { | |
a2053b27 | 131 | if (!win->m_hasVMT) return; |
88ac883a | 132 | |
16bcc879 | 133 | win->m_menuBarDetached = FALSE; |
f03fc89f | 134 | win->UpdateSize(); |
16bcc879 RR |
135 | } |
136 | ||
137 | //----------------------------------------------------------------------------- | |
138 | // "child_detached" of menu bar | |
139 | //----------------------------------------------------------------------------- | |
140 | ||
141 | static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
142 | { | |
a2053b27 | 143 | if (!win->m_hasVMT) return; |
88ac883a | 144 | |
16bcc879 | 145 | win->m_menuBarDetached = TRUE; |
f03fc89f | 146 | win->UpdateSize(); |
16bcc879 RR |
147 | } |
148 | ||
88ac883a | 149 | #if wxUSE_TOOLBAR |
16bcc879 RR |
150 | //----------------------------------------------------------------------------- |
151 | // "child_attached" of tool bar | |
152 | //----------------------------------------------------------------------------- | |
153 | ||
154 | static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
155 | { | |
a2053b27 | 156 | if (!win->m_hasVMT) return; |
88ac883a | 157 | |
16bcc879 | 158 | win->m_toolBarDetached = FALSE; |
88ac883a | 159 | |
f03fc89f | 160 | win->UpdateSize(); |
16bcc879 RR |
161 | } |
162 | ||
163 | //----------------------------------------------------------------------------- | |
164 | // "child_detached" of tool bar | |
165 | //----------------------------------------------------------------------------- | |
166 | ||
5e0201ea | 167 | static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
16bcc879 | 168 | { |
88ac883a | 169 | if (g_isIdle) |
801aa178 | 170 | wxapp_install_idle_handler(); |
acfd422a | 171 | |
a2053b27 | 172 | if (!win->m_hasVMT) return; |
88ac883a | 173 | |
16bcc879 | 174 | win->m_toolBarDetached = TRUE; |
f03fc89f | 175 | win->UpdateSize(); |
16bcc879 | 176 | } |
88ac883a | 177 | #endif // wxUSE_TOOLBAR |
16bcc879 | 178 | |
47908e25 | 179 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
180 | // "configure_event" |
181 | //----------------------------------------------------------------------------- | |
47908e25 | 182 | |
7beba2fc | 183 | static gint |
2d68e1b4 | 184 | #if (GTK_MINOR_VERSION > 0) |
c693edf3 RR |
185 | gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxFrame *win ) |
186 | #else | |
187 | gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) | |
188 | #endif | |
47908e25 | 189 | { |
7beba2fc | 190 | if (g_isIdle) |
121a3581 | 191 | wxapp_install_idle_handler(); |
acfd422a | 192 | |
2d68e1b4 RR |
193 | if (!win->m_hasVMT) |
194 | return FALSE; | |
195 | ||
196 | #if (GTK_MINOR_VERSION > 0) | |
dfc3d7e0 RR |
197 | int x = 0; |
198 | int y = 0; | |
199 | gdk_window_get_root_origin( win->m_widget->window, &x, &y ); | |
dfc3d7e0 RR |
200 | win->m_x = x; |
201 | win->m_y = y; | |
c693edf3 RR |
202 | #else |
203 | win->m_x = event->x; | |
204 | win->m_y = event->y; | |
205 | #endif | |
8bbe427f | 206 | |
a2053b27 | 207 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); |
36b3b54a RR |
208 | mevent.SetEventObject( win ); |
209 | win->GetEventHandler()->ProcessEvent( mevent ); | |
210 | ||
fb1585ae | 211 | return FALSE; |
362c6693 | 212 | } |
47908e25 | 213 | |
2b07d713 RR |
214 | //----------------------------------------------------------------------------- |
215 | // "realize" from m_widget | |
216 | //----------------------------------------------------------------------------- | |
217 | ||
88ac883a | 218 | /* we cannot MWM hints and icons before the widget has been realized, |
2b07d713 RR |
219 | so we do this directly after realization */ |
220 | ||
88ac883a | 221 | static gint |
2e5c594e | 222 | gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win ) |
2b07d713 | 223 | { |
88ac883a | 224 | if (g_isIdle) |
121a3581 | 225 | wxapp_install_idle_handler(); |
acfd422a | 226 | |
2e5c594e RR |
227 | /* I haven't been able to set the position of |
228 | the dialog before it is shown, so I set the | |
229 | position in "realize" */ | |
8487f887 | 230 | gtk_widget_set_uposition( widget, win->m_x, win->m_y ); |
2e5c594e | 231 | |
2b07d713 RR |
232 | /* all this is for Motif Window Manager "hints" and is supposed to be |
233 | recognized by other WM as well. not tested. */ | |
051b55ad KB |
234 | long decor = (long) GDK_DECOR_BORDER; |
235 | long func = (long) GDK_FUNC_MOVE; | |
88ac883a | 236 | |
f03fc89f VZ |
237 | if ((win->GetWindowStyle() & wxCAPTION) != 0) |
238 | decor |= GDK_DECOR_TITLE; | |
239 | if ((win->GetWindowStyle() & wxSYSTEM_MENU) != 0) | |
aa64626e KB |
240 | { |
241 | decor |= GDK_DECOR_MENU; | |
242 | func |= GDK_FUNC_CLOSE; | |
243 | } | |
f03fc89f | 244 | if ((win->GetWindowStyle() & wxMINIMIZE_BOX) != 0) |
15b24b14 | 245 | { |
f03fc89f VZ |
246 | func |= GDK_FUNC_MINIMIZE; |
247 | decor |= GDK_DECOR_MINIMIZE; | |
15b24b14 | 248 | } |
f03fc89f | 249 | if ((win->GetWindowStyle() & wxMAXIMIZE_BOX) != 0) |
15b24b14 | 250 | { |
f03fc89f VZ |
251 | func |= GDK_FUNC_MAXIMIZE; |
252 | decor |= GDK_DECOR_MAXIMIZE; | |
15b24b14 | 253 | } |
f03fc89f | 254 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) != 0) |
aa64626e KB |
255 | { |
256 | func |= GDK_FUNC_RESIZE; | |
257 | decor |= GDK_DECOR_RESIZEH; | |
aa64626e KB |
258 | } |
259 | ||
a2053b27 RR |
260 | gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); |
261 | gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); | |
88ac883a | 262 | |
2b07d713 | 263 | /* GTK's shrinking/growing policy */ |
f03fc89f | 264 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) == 0) |
a2053b27 | 265 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); |
2b07d713 | 266 | else |
a2053b27 | 267 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); |
88ac883a | 268 | |
738f9e5a | 269 | /* set size hints */ |
8487f887 | 270 | gint flag = 0; // GDK_HINT_POS; |
738f9e5a RR |
271 | if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE; |
272 | if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE; | |
273 | if (flag) | |
274 | { | |
7beba2fc VZ |
275 | gdk_window_set_hints( win->m_widget->window, |
276 | win->m_x, win->m_y, | |
277 | win->GetMinWidth(), win->GetMinHeight(), | |
278 | win->GetMaxWidth(), win->GetMaxHeight(), | |
279 | flag ); | |
738f9e5a | 280 | } |
7beba2fc | 281 | |
58dea4b0 RR |
282 | /* reset the icon */ |
283 | if (win->m_icon != wxNullIcon) | |
284 | { | |
285 | wxIcon icon( win->m_icon ); | |
286 | win->m_icon = wxNullIcon; | |
f03fc89f | 287 | win->SetIcon( icon ); |
58dea4b0 | 288 | } |
88ac883a | 289 | |
2e563988 RR |
290 | /* we set the focus to the child that accepts the focus. this |
291 | doesn't really have to be done in "realize" but why not? */ | |
f03fc89f | 292 | wxWindowList::Node *node = win->GetChildren().GetFirst(); |
2e563988 RR |
293 | while (node) |
294 | { | |
f03fc89f VZ |
295 | wxWindow *child = node->GetData(); |
296 | if (child->AcceptsFocus()) | |
297 | { | |
298 | child->SetFocus(); | |
299 | break; | |
300 | } | |
88ac883a | 301 | |
f03fc89f | 302 | node = node->GetNext(); |
2e563988 | 303 | } |
88ac883a | 304 | |
227e5e99 RR |
305 | return FALSE; |
306 | } | |
88ac883a | 307 | |
f362b96d RR |
308 | //----------------------------------------------------------------------------- |
309 | // InsertChild for wxFrame | |
310 | //----------------------------------------------------------------------------- | |
311 | ||
312 | /* Callback for wxFrame. This very strange beast has to be used because | |
313 | * C++ has no virtual methods in a constructor. We have to emulate a | |
314 | * virtual function here as wxWindows requires different ways to insert | |
315 | * a child in container classes. */ | |
316 | ||
6bc8a1c8 | 317 | static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) |
f362b96d | 318 | { |
5fd11f09 | 319 | wxASSERT( GTK_IS_WIDGET(child->m_widget) ); |
7beba2fc | 320 | |
6bc8a1c8 | 321 | if (!parent->m_insertInClientArea) |
f362b96d RR |
322 | { |
323 | /* these are outside the client area */ | |
f03fc89f | 324 | wxFrame* frame = (wxFrame*) parent; |
da048e3d | 325 | gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget), |
a2053b27 RR |
326 | GTK_WIDGET(child->m_widget), |
327 | child->m_x, | |
328 | child->m_y, | |
329 | child->m_width, | |
330 | child->m_height ); | |
88ac883a VZ |
331 | |
332 | #if wxUSE_TOOLBAR | |
f03fc89f VZ |
333 | /* we connect to these events for recalculating the client area |
334 | space when the toolbar is floating */ | |
335 | if (wxIS_KIND_OF(child,wxToolBar)) | |
336 | { | |
337 | wxToolBar *toolBar = (wxToolBar*) child; | |
338 | if (toolBar->GetWindowStyle() & wxTB_DOCKABLE) | |
339 | { | |
a2053b27 | 340 | gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_attached", |
41ca191f | 341 | GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback), (gpointer)parent ); |
88ac883a | 342 | |
a2053b27 | 343 | gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_detached", |
41ca191f | 344 | GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback), (gpointer)parent ); |
f03fc89f VZ |
345 | } |
346 | } | |
88ac883a | 347 | #endif // wxUSE_TOOLBAR |
f362b96d RR |
348 | } |
349 | else | |
350 | { | |
351 | /* these are inside the client area */ | |
da048e3d | 352 | gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), |
a2053b27 RR |
353 | GTK_WIDGET(child->m_widget), |
354 | child->m_x, | |
355 | child->m_y, | |
356 | child->m_width, | |
357 | child->m_height ); | |
f362b96d RR |
358 | } |
359 | ||
f362b96d | 360 | /* resize on OnInternalIdle */ |
f03fc89f | 361 | parent->UpdateSize(); |
f362b96d RR |
362 | } |
363 | ||
2f2aa628 RR |
364 | //----------------------------------------------------------------------------- |
365 | // wxFrame | |
c801d85f KB |
366 | //----------------------------------------------------------------------------- |
367 | ||
368 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
fb1585ae | 369 | EVT_SIZE(wxFrame::OnSize) |
54517652 | 370 | EVT_IDLE(wxFrame::OnIdle) |
fe4e9e6c | 371 | EVT_CLOSE(wxFrame::OnCloseWindow) |
342b6a2f | 372 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) |
c801d85f KB |
373 | END_EVENT_TABLE() |
374 | ||
375 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
376 | ||
ddb6bc71 | 377 | void wxFrame::Init() |
c801d85f | 378 | { |
fb1585ae | 379 | m_frameMenuBar = (wxMenuBar *) NULL; |
88ac883a | 380 | #if wxUSE_STATUSBAR |
fb1585ae | 381 | m_frameStatusBar = (wxStatusBar *) NULL; |
88ac883a VZ |
382 | #endif // wxUSE_STATUSBAR |
383 | #if wxUSE_TOOLBAR | |
fb1585ae | 384 | m_frameToolBar = (wxToolBar *) NULL; |
88ac883a | 385 | #endif // wxUSE_TOOLBAR |
fb1585ae | 386 | m_sizeSet = FALSE; |
b2b3ccc5 RR |
387 | m_miniEdge = 0; |
388 | m_miniTitle = 0; | |
ab2b3dd4 | 389 | m_mainWidget = (GtkWidget*) NULL; |
16bcc879 RR |
390 | m_menuBarDetached = FALSE; |
391 | m_toolBarDetached = FALSE; | |
6bc8a1c8 | 392 | m_insertInClientArea = TRUE; |
54517652 | 393 | m_isFrame = TRUE; |
362c6693 | 394 | } |
c801d85f | 395 | |
ed7a557b | 396 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
397 | const wxPoint &pos, const wxSize &size, |
398 | long style, const wxString &name ) | |
c801d85f | 399 | { |
ddb6bc71 | 400 | Init(); |
88ac883a | 401 | |
fb1585ae | 402 | Create( parent, id, title, pos, size, style, name ); |
362c6693 | 403 | } |
c801d85f | 404 | |
debe6624 | 405 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 406 | const wxPoint &pos, const wxSize &size, |
debe6624 | 407 | long style, const wxString &name ) |
c801d85f | 408 | { |
a802c3a1 | 409 | wxTopLevelWindows.Append( this ); |
8bbe427f | 410 | |
fb1585ae | 411 | m_needParent = FALSE; |
ed7a557b | 412 | |
4dcaf11a RR |
413 | if (!PreCreation( parent, pos, size ) || |
414 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
415 | { | |
223d09f6 | 416 | wxFAIL_MSG( wxT("wxFrame creation failed") ); |
7beba2fc | 417 | return FALSE; |
4dcaf11a | 418 | } |
c801d85f | 419 | |
fb1585ae | 420 | m_title = title; |
88ac883a | 421 | |
6bc8a1c8 | 422 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame; |
ed7a557b | 423 | |
faecf4cb | 424 | GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; |
fb1585ae | 425 | if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; |
8bbe427f | 426 | |
fb1585ae | 427 | m_widget = gtk_window_new( win_type ); |
88ac883a | 428 | |
de1c750f RR |
429 | if (!name.IsEmpty()) |
430 | gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() ); | |
8bbe427f | 431 | |
2e563988 | 432 | #ifdef __WXDEBUG__ |
223d09f6 | 433 | debug_focus_in( m_widget, wxT("wxFrame::m_widget"), name ); |
2e563988 RR |
434 | #endif |
435 | ||
ed9b9841 | 436 | gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() ); |
fb1585ae | 437 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
ed7a557b | 438 | |
fb1585ae RR |
439 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
440 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
ed7a557b | 441 | |
f362b96d | 442 | /* m_mainWidget holds the toolbar, the menubar and the client area */ |
da048e3d | 443 | m_mainWidget = gtk_pizza_new(); |
f362b96d RR |
444 | gtk_widget_show( m_mainWidget ); |
445 | GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); | |
446 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); | |
88ac883a | 447 | |
2e563988 | 448 | #ifdef __WXDEBUG__ |
223d09f6 | 449 | debug_focus_in( m_mainWidget, wxT("wxFrame::m_mainWidget"), name ); |
2e563988 RR |
450 | #endif |
451 | ||
f362b96d | 452 | /* m_wxwindow only represents the client area without toolbar and menubar */ |
da048e3d | 453 | m_wxwindow = gtk_pizza_new(); |
fb1585ae | 454 | gtk_widget_show( m_wxwindow ); |
f362b96d | 455 | gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); |
88ac883a | 456 | |
2e563988 | 457 | #ifdef __WXDEBUG__ |
223d09f6 | 458 | debug_focus_in( m_wxwindow, wxT("wxFrame::m_wxwindow"), name ); |
2e563988 RR |
459 | #endif |
460 | ||
461 | /* we donm't allow the frame to get the focus as otherwise | |
462 | the frame will grabit at arbitrary fcous changes. */ | |
463 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 464 | |
de8113d9 RR |
465 | if (m_parent) m_parent->AddChild( this ); |
466 | ||
54517652 RR |
467 | /* the user resized the frame by dragging etc. */ |
468 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", | |
469 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
470 | ||
de8113d9 RR |
471 | PostCreation(); |
472 | ||
58dea4b0 | 473 | /* we cannot set MWM hints and icons before the widget has |
2b07d713 RR |
474 | been realized, so we do this directly after realization */ |
475 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", | |
f03fc89f | 476 | GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); |
88ac883a | 477 | |
ab2b3dd4 | 478 | /* the only way to get the window size is to connect to this event */ |
fb1585ae RR |
479 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
480 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
8bbe427f | 481 | |
69ffe1d2 RR |
482 | /* disable native tab traversal */ |
483 | gtk_signal_connect( GTK_OBJECT(m_widget), "focus", | |
484 | GTK_SIGNAL_FUNC(gtk_frame_focus_callback), (gpointer)this ); | |
485 | ||
fb1585ae | 486 | return TRUE; |
362c6693 | 487 | } |
c801d85f | 488 | |
19717c50 | 489 | wxFrame::~wxFrame() |
c801d85f | 490 | { |
31c6b4fc | 491 | m_isBeingDeleted = TRUE; |
88ac883a | 492 | |
fb1585ae | 493 | if (m_frameMenuBar) delete m_frameMenuBar; |
e27ce4e9 | 494 | m_frameMenuBar = (wxMenuBar *) NULL; |
88ac883a VZ |
495 | |
496 | #if wxUSE_STATUSBAR | |
fb1585ae | 497 | if (m_frameStatusBar) delete m_frameStatusBar; |
e27ce4e9 | 498 | m_frameStatusBar = (wxStatusBar *) NULL; |
88ac883a VZ |
499 | #endif // wxUSE_STATUSBAR |
500 | ||
501 | #if wxUSE_TOOLBAR | |
fb1585ae | 502 | if (m_frameToolBar) delete m_frameToolBar; |
e27ce4e9 | 503 | m_frameToolBar = (wxToolBar *) NULL; |
88ac883a | 504 | #endif // wxUSE_TOOLBAR |
ed7a557b | 505 | |
fb1585ae | 506 | wxTopLevelWindows.DeleteObject( this ); |
2b854a32 | 507 | |
0d2a2b60 | 508 | if (wxTheApp->GetTopWindow() == this) |
0d2a2b60 | 509 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); |
2b854a32 | 510 | |
0d2a2b60 | 511 | if (wxTopLevelWindows.Number() == 0) |
0d2a2b60 | 512 | wxTheApp->ExitMainLoop(); |
362c6693 | 513 | } |
ed7a557b | 514 | |
debe6624 | 515 | bool wxFrame::Show( bool show ) |
c801d85f | 516 | { |
223d09f6 | 517 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 518 | |
35178437 | 519 | if (show && !m_sizeSet) |
fb1585ae | 520 | { |
e27ce4e9 RR |
521 | /* by calling GtkOnSize here, we don't have to call |
522 | either after showing the frame, which would entail | |
f362b96d | 523 | much ugly flicker or from within the size_allocate |
e27ce4e9 | 524 | handler, because GTK 1.1.X forbids that. */ |
8bbe427f | 525 | |
35178437 | 526 | GtkOnSize( m_x, m_y, m_width, m_height ); |
fb1585ae | 527 | } |
8bbe427f | 528 | |
fb1585ae | 529 | return wxWindow::Show( show ); |
362c6693 | 530 | } |
c801d85f | 531 | |
19717c50 | 532 | bool wxFrame::Destroy() |
c801d85f | 533 | { |
223d09f6 | 534 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 535 | |
fb1585ae | 536 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
ed7a557b | 537 | |
fb1585ae | 538 | return TRUE; |
c801d85f KB |
539 | } |
540 | ||
bfc6fde4 | 541 | void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 542 | { |
223d09f6 | 543 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 544 | |
ab2b3dd4 | 545 | /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */ |
223d09f6 | 546 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
88ac883a | 547 | |
ab2b3dd4 | 548 | /* avoid recursions */ |
88ac883a | 549 | if (m_resizing) return; |
fb1585ae RR |
550 | m_resizing = TRUE; |
551 | ||
552 | int old_x = m_x; | |
553 | int old_y = m_y; | |
7beba2fc | 554 | |
fb1585ae RR |
555 | int old_width = m_width; |
556 | int old_height = m_height; | |
8bbe427f | 557 | |
85ad5eb5 | 558 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
fb1585ae RR |
559 | { |
560 | if (x != -1) m_x = x; | |
561 | if (y != -1) m_y = y; | |
562 | if (width != -1) m_width = width; | |
563 | if (height != -1) m_height = height; | |
564 | } | |
565 | else | |
566 | { | |
567 | m_x = x; | |
568 | m_y = y; | |
569 | m_width = width; | |
570 | m_height = height; | |
571 | } | |
572 | ||
11e1c70d | 573 | /* |
fb1585ae RR |
574 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) |
575 | { | |
576 | if (width == -1) m_width = 80; | |
577 | } | |
578 | ||
579 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
580 | { | |
581 | if (height == -1) m_height = 26; | |
582 | } | |
11e1c70d | 583 | */ |
8bbe427f | 584 | |
fb1585ae RR |
585 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
586 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
587 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
588 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
fb1585ae RR |
589 | |
590 | if ((m_x != -1) || (m_y != -1)) | |
591 | { | |
8bbe427f | 592 | if ((m_x != old_x) || (m_y != old_y)) |
0138c2de | 593 | { |
8487f887 | 594 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
0138c2de | 595 | } |
fb1585ae | 596 | } |
8bbe427f | 597 | |
fb1585ae RR |
598 | if ((m_width != old_width) || (m_height != old_height)) |
599 | { | |
ab2b3dd4 | 600 | /* we set the size in GtkOnSize, i.e. mostly the actual resizing is |
f03fc89f VZ |
601 | done either directly before the frame is shown or in idle time |
602 | so that different calls to SetSize() don't lead to flicker. */ | |
de8113d9 | 603 | m_sizeSet = FALSE; |
fb1585ae | 604 | } |
8bbe427f | 605 | |
fb1585ae | 606 | m_resizing = FALSE; |
903f689b RR |
607 | } |
608 | ||
609 | void wxFrame::Centre( int direction ) | |
610 | { | |
223d09f6 | 611 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 612 | |
43a18898 RR |
613 | int x = 0; |
614 | int y = 0; | |
8bbe427f | 615 | |
f5eafd0e RR |
616 | if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; |
617 | if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
8bbe427f | 618 | |
fb1585ae | 619 | Move( x, y ); |
903f689b RR |
620 | } |
621 | ||
f9241296 | 622 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
c801d85f | 623 | { |
223d09f6 | 624 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 625 | |
f9241296 | 626 | wxWindow::DoGetClientSize( width, height ); |
fb1585ae | 627 | if (height) |
46dc76ba | 628 | { |
41ca191f RR |
629 | /* menu bar */ |
630 | if (m_frameMenuBar) | |
f03fc89f | 631 | { |
88ac883a | 632 | if (!m_menuBarDetached) |
f03fc89f VZ |
633 | (*height) -= wxMENU_HEIGHT; |
634 | else | |
635 | (*height) -= wxPLACE_HOLDER; | |
636 | } | |
88ac883a | 637 | |
dcf924a3 | 638 | #if wxUSE_STATUSBAR |
f03fc89f | 639 | /* status bar */ |
fb1585ae | 640 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; |
dcf924a3 | 641 | #endif |
88ac883a | 642 | |
dcf924a3 | 643 | #if wxUSE_TOOLBAR |
f03fc89f | 644 | /* tool bar */ |
fb1585ae RR |
645 | if (m_frameToolBar) |
646 | { | |
f03fc89f VZ |
647 | if (!m_toolBarDetached) |
648 | { | |
41ca191f RR |
649 | int y = 0; |
650 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
651 | (*height) -= y; | |
f03fc89f VZ |
652 | } |
653 | else | |
41ca191f | 654 | (*height) -= wxPLACE_HOLDER; |
fb1585ae | 655 | } |
dcf924a3 | 656 | #endif |
88ac883a | 657 | |
f03fc89f | 658 | /* mini edge */ |
b2b3ccc5 RR |
659 | (*height) -= m_miniEdge*2 + m_miniTitle; |
660 | } | |
661 | if (width) | |
662 | { | |
663 | (*width) -= m_miniEdge*2; | |
46dc76ba | 664 | } |
362c6693 | 665 | } |
c801d85f | 666 | |
bfc6fde4 | 667 | void wxFrame::DoSetClientSize( int width, int height ) |
b593568e | 668 | { |
223d09f6 | 669 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 670 | |
41ca191f RR |
671 | /* menu bar */ |
672 | if (m_frameMenuBar) | |
f03fc89f | 673 | { |
88ac883a | 674 | if (!m_menuBarDetached) |
f03fc89f VZ |
675 | height += wxMENU_HEIGHT; |
676 | else | |
677 | height += wxPLACE_HOLDER; | |
678 | } | |
88ac883a | 679 | |
dcf924a3 | 680 | #if wxUSE_STATUSBAR |
f03fc89f | 681 | /* status bar */ |
41ca191f | 682 | if (m_frameStatusBar) height += wxSTATUS_HEIGHT; |
dcf924a3 | 683 | #endif |
88ac883a | 684 | |
dcf924a3 | 685 | #if wxUSE_TOOLBAR |
f03fc89f | 686 | /* tool bar */ |
41ca191f RR |
687 | if (m_frameToolBar) |
688 | { | |
f03fc89f VZ |
689 | if (!m_toolBarDetached) |
690 | { | |
41ca191f RR |
691 | int y = 0; |
692 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
693 | height += y; | |
f03fc89f VZ |
694 | } |
695 | else | |
41ca191f RR |
696 | height += wxPLACE_HOLDER; |
697 | } | |
dcf924a3 | 698 | #endif |
88ac883a | 699 | |
3017f78d | 700 | DoSetSize( -1, -1, width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0 ); |
362c6693 | 701 | } |
b593568e | 702 | |
47908e25 | 703 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
c801d85f | 704 | { |
f5368809 RR |
705 | // due to a bug in gtk, x,y are always 0 |
706 | // m_x = x; | |
707 | // m_y = y; | |
708 | ||
ab2b3dd4 | 709 | /* avoid recursions */ |
e52f60e6 RR |
710 | if (m_resizing) return; |
711 | m_resizing = TRUE; | |
8bbe427f | 712 | |
ab2b3dd4 | 713 | /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */ |
223d09f6 | 714 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
88ac883a | 715 | |
f5368809 RR |
716 | m_width = width; |
717 | m_height = height; | |
7beba2fc | 718 | |
ab2b3dd4 | 719 | /* space occupied by m_frameToolBar and m_frameMenuBar */ |
88ac883a | 720 | int client_area_y_offset = 0; |
8bbe427f | 721 | |
ab2b3dd4 RR |
722 | /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses |
723 | wxWindow::Create to create it's GTK equivalent. m_mainWidget is only | |
724 | set in wxFrame::Create so it is used to check what kind of frame we | |
725 | have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we | |
726 | skip the part which handles m_frameMenuBar, m_frameToolBar and (most | |
727 | importantly) m_mainWidget */ | |
88ac883a | 728 | |
ab2b3dd4 | 729 | if (m_mainWidget) |
f5368809 | 730 | { |
ab2b3dd4 RR |
731 | /* check if size is in legal range */ |
732 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
733 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
734 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
735 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
736 | ||
737 | /* I revert back to wxGTK's original behaviour. m_mainWidget holds the | |
738 | * menubar, the toolbar and the client area, which is represented by | |
739 | * m_wxwindow. | |
740 | * this hurts in the eye, but I don't want to call SetSize() | |
741 | * because I don't want to call any non-native functions here. */ | |
88ac883a | 742 | |
ab2b3dd4 RR |
743 | if (m_frameMenuBar) |
744 | { | |
745 | int xx = m_miniEdge; | |
746 | int yy = m_miniEdge + m_miniTitle; | |
747 | int ww = m_width - 2*m_miniEdge; | |
41ca191f | 748 | int hh = wxMENU_HEIGHT; |
f03fc89f | 749 | if (m_menuBarDetached) hh = wxPLACE_HOLDER; |
121a3581 RR |
750 | m_frameMenuBar->m_x = xx; |
751 | m_frameMenuBar->m_y = yy; | |
752 | m_frameMenuBar->m_width = ww; | |
753 | m_frameMenuBar->m_height = hh; | |
da048e3d | 754 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
88ac883a | 755 | m_frameMenuBar->m_widget, |
f03fc89f VZ |
756 | xx, yy, ww, hh ); |
757 | client_area_y_offset += hh; | |
ab2b3dd4 | 758 | } |
88ac883a | 759 | |
dcf924a3 | 760 | #if wxUSE_TOOLBAR |
11e1c70d | 761 | if ((m_frameToolBar) && |
7beba2fc | 762 | (m_frameToolBar->m_widget->parent == m_mainWidget)) |
ab2b3dd4 RR |
763 | { |
764 | int xx = m_miniEdge; | |
765 | int yy = m_miniEdge + m_miniTitle; | |
41ca191f | 766 | if (m_frameMenuBar) |
f03fc89f | 767 | { |
88ac883a VZ |
768 | if (!m_menuBarDetached) |
769 | yy += wxMENU_HEIGHT; | |
770 | else | |
f03fc89f VZ |
771 | yy += wxPLACE_HOLDER; |
772 | } | |
ab2b3dd4 | 773 | int ww = m_width - 2*m_miniEdge; |
a2053b27 | 774 | int hh = m_frameToolBar->m_height; |
7beba2fc | 775 | if (m_toolBarDetached) hh = wxPLACE_HOLDER; |
121a3581 RR |
776 | m_frameToolBar->m_x = xx; |
777 | m_frameToolBar->m_y = yy; | |
11e1c70d RR |
778 | /* m_frameToolBar->m_height = hh; don't change the toolbar's reported size |
779 | m_frameToolBar->m_width = ww; */ | |
da048e3d | 780 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
88ac883a | 781 | m_frameToolBar->m_widget, |
f03fc89f VZ |
782 | xx, yy, ww, hh ); |
783 | client_area_y_offset += hh; | |
ab2b3dd4 | 784 | } |
dcf924a3 | 785 | #endif |
88ac883a | 786 | |
32a95f9f | 787 | int client_x = m_miniEdge; |
f03fc89f | 788 | int client_y = client_area_y_offset + m_miniEdge + m_miniTitle; |
32a95f9f | 789 | int client_w = m_width - 2*m_miniEdge; |
f03fc89f | 790 | int client_h = m_height - client_area_y_offset- 2*m_miniEdge - m_miniTitle; |
da048e3d | 791 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
88ac883a | 792 | m_wxwindow, |
f03fc89f | 793 | client_x, client_y, client_w, client_h ); |
32a95f9f RR |
794 | } |
795 | else | |
796 | { | |
797 | /* if there is no m_mainWidget between m_widget and m_wxwindow there | |
f03fc89f | 798 | is no need to set the size or position of m_wxwindow. */ |
f5368809 | 799 | } |
88ac883a | 800 | |
dcf924a3 | 801 | #if wxUSE_STATUSBAR |
f5368809 RR |
802 | if (m_frameStatusBar) |
803 | { | |
b2b3ccc5 | 804 | int xx = 0 + m_miniEdge; |
f362b96d | 805 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset; |
ac57418f RR |
806 | int ww = m_width - 2*m_miniEdge; |
807 | int hh = wxSTATUS_HEIGHT; | |
121a3581 RR |
808 | m_frameStatusBar->m_x = xx; |
809 | m_frameStatusBar->m_y = yy; | |
810 | m_frameStatusBar->m_width = ww; | |
811 | m_frameStatusBar->m_height = hh; | |
da048e3d | 812 | gtk_pizza_set_size( GTK_PIZZA(m_wxwindow), |
88ac883a | 813 | m_frameStatusBar->m_widget, |
f03fc89f | 814 | xx, yy, ww, hh ); |
f5368809 | 815 | } |
dcf924a3 | 816 | #endif |
8bbe427f | 817 | |
de8113d9 RR |
818 | /* we actually set the size of a frame here and no-where else */ |
819 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
88ac883a | 820 | |
8bbe427f | 821 | |
54517652 | 822 | m_sizeSet = TRUE; |
7beba2fc | 823 | |
54517652 | 824 | // send size event to frame |
43a18898 RR |
825 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
826 | event.SetEventObject( this ); | |
e52f60e6 | 827 | GetEventHandler()->ProcessEvent( event ); |
8bbe427f | 828 | |
54517652 | 829 | // send size event to status bar |
5aa5e35a RR |
830 | if (m_frameStatusBar) |
831 | { | |
a2053b27 | 832 | wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); |
5aa5e35a RR |
833 | event2.SetEventObject( m_frameStatusBar ); |
834 | m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); | |
835 | } | |
884470b1 | 836 | |
e52f60e6 RR |
837 | m_resizing = FALSE; |
838 | } | |
839 | ||
ca26177c RR |
840 | void wxFrame::MakeModal( bool modal ) |
841 | { | |
842 | if (modal) | |
ca26177c | 843 | gtk_grab_add( m_widget ); |
ca26177c | 844 | else |
c25ccf85 | 845 | gtk_grab_remove( m_widget ); |
ca26177c RR |
846 | } |
847 | ||
9390a202 | 848 | void wxFrame::OnInternalIdle() |
e52f60e6 | 849 | { |
1b3667ab | 850 | if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) |
54517652 | 851 | { |
e52f60e6 | 852 | GtkOnSize( m_x, m_y, m_width, m_height ); |
7beba2fc VZ |
853 | |
854 | // we'll come back later | |
54517652 RR |
855 | if (g_isIdle) |
856 | wxapp_install_idle_handler(); | |
7beba2fc | 857 | return; |
54517652 | 858 | } |
88ac883a | 859 | |
082b2798 | 860 | if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); |
dcf924a3 | 861 | #if wxUSE_TOOLBAR |
082b2798 | 862 | if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); |
dcf924a3 RR |
863 | #endif |
864 | #if wxUSE_STATUSBAR | |
082b2798 | 865 | if (m_frameStatusBar) m_frameStatusBar->OnInternalIdle(); |
dcf924a3 | 866 | #endif |
5e014a0c RR |
867 | |
868 | wxWindow::OnInternalIdle(); | |
362c6693 | 869 | } |
c801d85f | 870 | |
6bc8a1c8 | 871 | void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) ) |
fe4e9e6c | 872 | { |
e3065973 | 873 | Destroy(); |
fe4e9e6c VZ |
874 | } |
875 | ||
c801d85f KB |
876 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) |
877 | { | |
223d09f6 | 878 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 879 | |
88ac883a | 880 | #if wxUSE_CONSTRAINTS |
f5368809 RR |
881 | if (GetAutoLayout()) |
882 | { | |
883 | Layout(); | |
884 | } | |
8bbe427f | 885 | else |
88ac883a | 886 | #endif // wxUSE_CONSTRAINTS |
c801d85f | 887 | { |
ab46dc18 | 888 | /* do we have exactly one child? */ |
0138c2de VZ |
889 | wxWindow *child = (wxWindow *)NULL; |
890 | for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) | |
f5368809 RR |
891 | { |
892 | wxWindow *win = (wxWindow *)node->Data(); | |
0138c2de | 893 | if ( !wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) ) |
f5368809 | 894 | { |
ab46dc18 | 895 | if (child) |
0138c2de | 896 | { |
ab46dc18 | 897 | /* it's the second one: do nothing */ |
0138c2de VZ |
898 | return; |
899 | } | |
900 | ||
f5368809 RR |
901 | child = win; |
902 | } | |
903 | } | |
ed7a557b | 904 | |
ab46dc18 RR |
905 | /* no children at all? */ |
906 | if (child) | |
0138c2de | 907 | { |
ab46dc18 | 908 | /* yes: set it's size to fill all the frame */ |
0138c2de | 909 | int client_x, client_y; |
326f9654 | 910 | DoGetClientSize( &client_x, &client_y ); |
0138c2de VZ |
911 | child->SetSize( 1, 1, client_x-2, client_y-2 ); |
912 | } | |
362c6693 | 913 | } |
362c6693 | 914 | } |
c801d85f | 915 | |
c801d85f KB |
916 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) |
917 | { | |
223d09f6 KB |
918 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
919 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); | |
8bbe427f | 920 | |
f5368809 | 921 | m_frameMenuBar = menuBar; |
8bbe427f | 922 | |
f5368809 | 923 | if (m_frameMenuBar) |
30dea054 | 924 | { |
5bd9e519 | 925 | m_frameMenuBar->SetInvokingWindow( this ); |
8bbe427f | 926 | |
f03fc89f | 927 | if (m_frameMenuBar->GetParent() != this) |
f5368809 | 928 | { |
f03fc89f | 929 | m_frameMenuBar->SetParent(this); |
da048e3d | 930 | gtk_pizza_put( GTK_PIZZA(m_mainWidget), |
88ac883a VZ |
931 | m_frameMenuBar->m_widget, |
932 | m_frameMenuBar->m_x, | |
a2053b27 RR |
933 | m_frameMenuBar->m_y, |
934 | m_frameMenuBar->m_width, | |
935 | m_frameMenuBar->m_height ); | |
88ac883a | 936 | |
f03fc89f VZ |
937 | if (menuBar->GetWindowStyle() & wxMB_DOCKABLE) |
938 | { | |
a2053b27 | 939 | gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_attached", |
16bcc879 | 940 | GTK_SIGNAL_FUNC(gtk_menu_attached_callback), (gpointer)this ); |
88ac883a | 941 | |
a2053b27 | 942 | gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_detached", |
16bcc879 | 943 | GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this ); |
f03fc89f | 944 | } |
7beba2fc VZ |
945 | |
946 | m_frameMenuBar->Show( TRUE ); | |
f5368809 | 947 | } |
716b7364 | 948 | } |
8bbe427f | 949 | |
1e133b7d | 950 | /* resize window in OnInternalIdle */ |
5b077d48 | 951 | m_sizeSet = FALSE; |
362c6693 | 952 | } |
c801d85f | 953 | |
8bbe427f | 954 | wxMenuBar *wxFrame::GetMenuBar() const |
46dc76ba | 955 | { |
f5368809 | 956 | return m_frameMenuBar; |
362c6693 | 957 | } |
46dc76ba | 958 | |
342b6a2f RR |
959 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) |
960 | { | |
88ac883a | 961 | #if wxUSE_STATUSBAR |
342b6a2f RR |
962 | if (GetStatusBar()) |
963 | { | |
0138c2de VZ |
964 | // if no help string found, we will clear the status bar text |
965 | wxString helpString; | |
966 | ||
967 | int menuId = event.GetMenuId(); | |
10c1d217 | 968 | if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ ) |
342b6a2f RR |
969 | { |
970 | wxMenuBar *menuBar = GetMenuBar(); | |
10c1d217 | 971 | if ( menuBar ) |
342b6a2f | 972 | { |
10c1d217 VZ |
973 | // it's ok if we don't find the item because it might belong to |
974 | // the popup menu | |
975 | wxMenuItem *item = menuBar->FindItem(menuId); | |
976 | if ( item ) | |
977 | helpString = item->GetHelp(); | |
342b6a2f RR |
978 | } |
979 | } | |
0138c2de VZ |
980 | |
981 | SetStatusText(helpString); | |
342b6a2f | 982 | } |
88ac883a | 983 | #endif // wxUSE_STATUSBAR |
342b6a2f RR |
984 | } |
985 | ||
88ac883a | 986 | #if wxUSE_TOOLBAR |
6bc8a1c8 | 987 | wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 988 | { |
223d09f6 | 989 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 990 | |
223d09f6 | 991 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, wxT("recreating toolbar in wxFrame") ); |
362c6693 | 992 | |
6bc8a1c8 | 993 | m_insertInClientArea = FALSE; |
88ac883a | 994 | |
f5368809 | 995 | m_frameToolBar = OnCreateToolBar( style, id, name ); |
8bbe427f | 996 | |
6bc8a1c8 | 997 | if (m_frameToolBar) GetChildren().DeleteObject( m_frameToolBar ); |
88ac883a | 998 | |
6bc8a1c8 | 999 | m_insertInClientArea = TRUE; |
8bbe427f | 1000 | |
5b077d48 | 1001 | m_sizeSet = FALSE; |
8bbe427f | 1002 | |
f5368809 | 1003 | return m_frameToolBar; |
362c6693 | 1004 | } |
46dc76ba | 1005 | |
362c6693 | 1006 | wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 1007 | { |
f5368809 | 1008 | return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); |
362c6693 RR |
1009 | } |
1010 | ||
7beba2fc VZ |
1011 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
1012 | { | |
1013 | m_frameToolBar = toolbar; | |
307f16e8 RR |
1014 | if (m_frameToolBar) |
1015 | { | |
1016 | /* insert into toolbar area if not already there */ | |
3017f78d RR |
1017 | if ((m_frameToolBar->m_widget->parent) && |
1018 | (m_frameToolBar->m_widget->parent != m_mainWidget)) | |
307f16e8 | 1019 | { |
3017f78d | 1020 | GetChildren().DeleteObject( m_frameToolBar ); |
7beba2fc VZ |
1021 | |
1022 | gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget ); | |
1023 | UpdateSize(); | |
1024 | } | |
307f16e8 RR |
1025 | } |
1026 | } | |
1027 | ||
8bbe427f VZ |
1028 | wxToolBar *wxFrame::GetToolBar() const |
1029 | { | |
1030 | return m_frameToolBar; | |
362c6693 | 1031 | } |
88ac883a | 1032 | #endif // wxUSE_TOOLBAR |
46dc76ba | 1033 | |
88ac883a | 1034 | #if wxUSE_STATUSBAR |
e3e65dac | 1035 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) |
c801d85f | 1036 | { |
223d09f6 | 1037 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1038 | |
223d09f6 | 1039 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, wxT("recreating status bar in wxFrame") ); |
c801d85f | 1040 | |
f5368809 | 1041 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); |
8bbe427f | 1042 | |
5b077d48 | 1043 | m_sizeSet = FALSE; |
8bbe427f | 1044 | |
f5368809 | 1045 | return m_frameStatusBar; |
362c6693 RR |
1046 | } |
1047 | ||
1048 | wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
1049 | { | |
f5368809 | 1050 | wxStatusBar *statusBar = (wxStatusBar *) NULL; |
8bbe427f | 1051 | |
f5368809 | 1052 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name); |
8bbe427f | 1053 | |
f5368809 RR |
1054 | // Set the height according to the font and the border size |
1055 | wxClientDC dc(statusBar); | |
8bbe427f | 1056 | dc.SetFont( statusBar->GetFont() ); |
362c6693 | 1057 | |
f5368809 RR |
1058 | long x, y; |
1059 | dc.GetTextExtent( "X", &x, &y ); | |
362c6693 | 1060 | |
f5368809 | 1061 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); |
362c6693 | 1062 | |
f5368809 | 1063 | statusBar->SetSize( -1, -1, 100, height ); |
362c6693 | 1064 | |
f5368809 RR |
1065 | statusBar->SetFieldsCount( number ); |
1066 | return statusBar; | |
362c6693 | 1067 | } |
c801d85f | 1068 | |
88ac883a | 1069 | wxStatusBar *wxFrame::GetStatusBar() const |
30f1b5f3 | 1070 | { |
88ac883a | 1071 | return m_frameStatusBar; |
30f1b5f3 RR |
1072 | } |
1073 | ||
362c6693 | 1074 | void wxFrame::SetStatusText(const wxString& text, int number) |
c801d85f | 1075 | { |
223d09f6 | 1076 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1077 | |
223d09f6 | 1078 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
c801d85f | 1079 | |
f5368809 | 1080 | m_frameStatusBar->SetStatusText(text, number); |
362c6693 RR |
1081 | } |
1082 | ||
1083 | void wxFrame::SetStatusWidths(int n, const int widths_field[] ) | |
c801d85f | 1084 | { |
223d09f6 | 1085 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1086 | |
223d09f6 | 1087 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") ); |
362c6693 | 1088 | |
f5368809 | 1089 | m_frameStatusBar->SetStatusWidths(n, widths_field); |
362c6693 | 1090 | } |
88ac883a | 1091 | #endif // wxUSE_STATUSBAR |
c801d85f | 1092 | |
88ac883a | 1093 | void wxFrame::Command( int id ) |
c801d85f | 1094 | { |
88ac883a VZ |
1095 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); |
1096 | commandEvent.SetInt( id ); | |
1097 | commandEvent.SetEventObject( this ); | |
1098 | ||
1099 | wxMenuBar *bar = GetMenuBar(); | |
1100 | if (!bar) return; | |
1101 | ||
1987af7e | 1102 | wxMenuItem *item = bar->FindItem(id) ; |
88ac883a VZ |
1103 | if (item && item->IsCheckable()) |
1104 | { | |
1987af7e | 1105 | bar->Check(id, !bar->IsChecked(id)) ; |
88ac883a VZ |
1106 | } |
1107 | ||
1108 | wxEvtHandler* evtHandler = GetEventHandler(); | |
1109 | ||
1110 | evtHandler->ProcessEvent(commandEvent); | |
362c6693 | 1111 | } |
c801d85f | 1112 | |
c801d85f KB |
1113 | void wxFrame::SetTitle( const wxString &title ) |
1114 | { | |
223d09f6 | 1115 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1116 | |
f5368809 | 1117 | m_title = title; |
223d09f6 | 1118 | if (m_title.IsNull()) m_title = wxT(""); |
ed9b9841 | 1119 | gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() ); |
362c6693 | 1120 | } |
c801d85f | 1121 | |
d355d3fe RR |
1122 | void wxFrame::SetIcon( const wxIcon &icon ) |
1123 | { | |
223d09f6 | 1124 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1125 | |
f5368809 RR |
1126 | m_icon = icon; |
1127 | if (!icon.Ok()) return; | |
8bbe427f | 1128 | |
58dea4b0 RR |
1129 | if (!m_widget->window) return; |
1130 | ||
f5368809 RR |
1131 | wxMask *mask = icon.GetMask(); |
1132 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
1133 | if (mask) bm = mask->GetBitmap(); | |
8bbe427f | 1134 | |
f5368809 | 1135 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
d355d3fe | 1136 | } |
b2b3ccc5 | 1137 | |
7beba2fc | 1138 | void wxFrame::Maximize(bool WXUNUSED(maximize)) |
cd25b18c RR |
1139 | { |
1140 | } | |
1141 | ||
7beba2fc | 1142 | void wxFrame::Restore() |
cd25b18c RR |
1143 | { |
1144 | } | |
1145 | ||
7beba2fc VZ |
1146 | void wxFrame::Iconize( bool iconize ) |
1147 | { | |
cd25b18c RR |
1148 | if (iconize) |
1149 | { | |
1150 | XIconifyWindow( GDK_WINDOW_XDISPLAY( m_widget->window ), | |
7beba2fc VZ |
1151 | GDK_WINDOW_XWINDOW( m_widget->window ), |
1152 | DefaultScreen( GDK_DISPLAY() ) ); | |
cd25b18c RR |
1153 | } |
1154 | } | |
1155 | ||
7beba2fc VZ |
1156 | bool wxFrame::IsIconized() const |
1157 | { | |
1158 | return FALSE; | |
cd25b18c | 1159 | } |