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