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