]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/frame.cpp
Now even Julian can use wxGTK :-)
[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
10#ifdef __GNUG__
11#pragma implementation "frame.h"
12#endif
13
14#include "wx/frame.h"
15#include "wx/dialog.h"
16#include "wx/control.h"
17#include "wx/app.h"
cf4219e7
RR
18#include "wx/menu.h"
19#include "wx/toolbar.h"
20#include "wx/statusbr.h"
362c6693 21#include "wx/dcclient.h"
c801d85f
KB
22#include "wx/gtk/win_gtk.h"
23
2f2aa628
RR
24//-----------------------------------------------------------------------------
25// constants
26//-----------------------------------------------------------------------------
27
907789a0 28const int wxMENU_HEIGHT = 27;
c67daf87 29const int wxSTATUS_HEIGHT = 25;
c801d85f 30
2f2aa628
RR
31//-----------------------------------------------------------------------------
32// data
33//-----------------------------------------------------------------------------
34
c801d85f
KB
35extern wxList wxTopLevelWindows;
36extern wxList wxPendingDelete;
37
38//-----------------------------------------------------------------------------
2f2aa628 39// "size_allocate"
c801d85f 40//-----------------------------------------------------------------------------
c801d85f 41
2f2aa628 42static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win )
ed7a557b 43{
fb1585ae 44 if (!win->HasVMT()) return;
8bbe427f 45
c801d85f 46/*
fb1585ae
RR
47 printf( "OnFrameResize from " );
48 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
49 printf( win->GetClassInfo()->GetClassName() );
50 printf( ".\n" );
c801d85f 51*/
8bbe427f 52
e52f60e6
RR
53 if ((win->m_width != alloc->width) || (win->m_height != alloc->height))
54 {
55 win->m_sizeSet = FALSE;
56 win->m_width = alloc->width;
57 win->m_height = alloc->height;
58 }
362c6693 59}
c801d85f
KB
60
61//-----------------------------------------------------------------------------
2f2aa628
RR
62// "delete_event"
63//-----------------------------------------------------------------------------
c801d85f 64
2f2aa628 65static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win )
ed7a557b 66{
c801d85f 67/*
fb1585ae
RR
68 printf( "OnDelete from " );
69 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
70 printf( win->GetClassInfo()->GetClassName() );
71 printf( ".\n" );
c801d85f 72*/
ed7a557b 73
fb1585ae 74 win->Close();
c801d85f 75
fb1585ae 76 return TRUE;
362c6693 77}
c801d85f 78
47908e25 79//-----------------------------------------------------------------------------
2f2aa628
RR
80// "configure_event"
81//-----------------------------------------------------------------------------
47908e25 82
2f2aa628 83static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win )
47908e25 84{
fb1585ae 85 if (!win->HasVMT()) return FALSE;
8bbe427f 86
fb1585ae
RR
87 win->m_x = event->x;
88 win->m_y = event->y;
8bbe427f 89
fb1585ae 90 return FALSE;
362c6693 91}
47908e25 92
2f2aa628
RR
93//-----------------------------------------------------------------------------
94// wxFrame
c801d85f
KB
95//-----------------------------------------------------------------------------
96
97BEGIN_EVENT_TABLE(wxFrame, wxWindow)
fb1585ae
RR
98 EVT_SIZE(wxFrame::OnSize)
99 EVT_CLOSE(wxFrame::OnCloseWindow)
100 EVT_IDLE(wxFrame::OnIdle)
c801d85f
KB
101END_EVENT_TABLE()
102
103IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
104
19717c50 105wxFrame::wxFrame()
c801d85f 106{
fb1585ae
RR
107 m_frameMenuBar = (wxMenuBar *) NULL;
108 m_frameStatusBar = (wxStatusBar *) NULL;
109 m_frameToolBar = (wxToolBar *) NULL;
110 m_sizeSet = FALSE;
b2b3ccc5
RR
111 m_miniEdge = 0;
112 m_miniTitle = 0;
362c6693 113}
c801d85f 114
ed7a557b 115wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title,
debe6624
JS
116 const wxPoint &pos, const wxSize &size,
117 long style, const wxString &name )
c801d85f 118{
fb1585ae
RR
119 m_frameMenuBar = (wxMenuBar *) NULL;
120 m_frameStatusBar = (wxStatusBar *) NULL;
121 m_frameToolBar = (wxToolBar *) NULL;
122 m_sizeSet = FALSE;
b2b3ccc5
RR
123 m_miniEdge = 0;
124 m_miniTitle = 0;
fb1585ae 125 Create( parent, id, title, pos, size, style, name );
362c6693 126}
c801d85f 127
debe6624 128bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
c801d85f 129 const wxPoint &pos, const wxSize &size,
debe6624 130 long style, const wxString &name )
c801d85f 131{
a802c3a1 132 wxTopLevelWindows.Append( this );
8bbe427f 133
fb1585ae 134 m_needParent = FALSE;
ed7a557b 135
fb1585ae 136 PreCreation( parent, id, pos, size, style, name );
c801d85f 137
fb1585ae 138 m_title = title;
ed7a557b 139
fb1585ae
RR
140 GtkWindowType win_type = GTK_WINDOW_TOPLEVEL;
141 if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP;
8bbe427f 142
fb1585ae 143 m_widget = gtk_window_new( win_type );
8bbe427f 144
b292e2f5
RR
145#ifdef __WXDEBUG__
146 debug_focus_in( m_widget, "wxFrame::m_widget", name );
147#endif
148
fb1585ae
RR
149 if ((size.x != -1) && (size.y != -1))
150 gtk_widget_set_usize( m_widget, m_width, m_height );
151 if ((pos.x != -1) && (pos.y != -1))
152 gtk_widget_set_uposition( m_widget, m_x, m_y );
ed7a557b 153
fb1585ae
RR
154 gtk_window_set_title( GTK_WINDOW(m_widget), title );
155 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
ed7a557b 156
fb1585ae 157 gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL );
ed7a557b 158
fb1585ae
RR
159 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
160 GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this );
ed7a557b 161
fb1585ae
RR
162 m_wxwindow = gtk_myfixed_new();
163 gtk_widget_show( m_wxwindow );
164 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
ed7a557b 165
b292e2f5
RR
166#ifdef __WXDEBUG__
167 debug_focus_in( m_wxwindow, "wxFrame::m_wxwindow", name );
168#endif
169
fb1585ae 170 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
ed7a557b 171
fb1585ae
RR
172 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
173 GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this );
ed7a557b 174
fb1585ae
RR
175 gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event",
176 GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this );
8bbe427f 177
fb1585ae 178 if (m_parent) m_parent->AddChild( this );
8bbe427f 179
fb1585ae 180 PostCreation();
8bbe427f 181
fb1585ae 182 return TRUE;
362c6693 183}
c801d85f 184
19717c50 185wxFrame::~wxFrame()
c801d85f 186{
fb1585ae
RR
187 if (m_frameMenuBar) delete m_frameMenuBar;
188 if (m_frameStatusBar) delete m_frameStatusBar;
189 if (m_frameToolBar) delete m_frameToolBar;
ed7a557b 190
fb1585ae
RR
191 wxTopLevelWindows.DeleteObject( this );
192 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
362c6693 193}
ed7a557b 194
debe6624 195bool wxFrame::Show( bool show )
c801d85f 196{
fb1585ae 197 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 198
35178437 199 if (show && !m_sizeSet)
fb1585ae 200 {
8bbe427f
VZ
201 // by calling GtkOnSize here, we don't have to call
202 // either after showing the frame, which would entail
203 // much ugly flicker nor from within the size_allocate
204 // handler, because GTK 1.1.X forbids that.
205
35178437 206 GtkOnSize( m_x, m_y, m_width, m_height );
fb1585ae 207 }
8bbe427f 208
fb1585ae 209 return wxWindow::Show( show );
362c6693 210}
c801d85f 211
716b7364 212void wxFrame::OnCloseWindow( wxCloseEvent &event )
c801d85f 213{
fb1585ae 214 if (GetEventHandler()->OnClose() || event.GetForce()) this->Destroy();
362c6693 215}
c801d85f 216
19717c50 217bool wxFrame::Destroy()
c801d85f 218{
fb1585ae 219 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 220
fb1585ae 221 if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this);
ed7a557b 222
fb1585ae 223 return TRUE;
c801d85f
KB
224}
225
6ca41e57
RR
226wxPoint wxFrame::GetClientAreaOrigin() const
227{
b2b3ccc5 228 wxPoint pt( m_miniEdge, m_miniEdge + m_miniTitle );
fb1585ae
RR
229 if (m_frameMenuBar)
230 {
231 int h = 0;
232 m_frameMenuBar->GetSize( (int*)NULL, &h );
907789a0 233 pt.y += h;
fb1585ae
RR
234 }
235 if (m_frameToolBar)
236 {
237 int h = 0;
238 m_frameToolBar->GetSize( (int*)NULL, &h );
239 pt.y += h;
240 }
241 return pt;
6ca41e57
RR
242}
243
fb1585ae 244void wxFrame::SetSize( int x, int y, int width, int height, int sizeFlags )
903f689b 245{
fb1585ae 246 wxASSERT_MSG( (m_widget != NULL), "invalid window" );
8bbe427f 247
fb1585ae
RR
248 // Don't do anything for children of wxMDIChildFrame
249 if (!m_wxwindow) return;
250
251 if (m_resizing) return; // I don't like recursions
252 m_resizing = TRUE;
253
254 int old_x = m_x;
255 int old_y = m_y;
256 int old_width = m_width;
257 int old_height = m_height;
8bbe427f 258
fb1585ae
RR
259 if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
260 {
261 if (x != -1) m_x = x;
262 if (y != -1) m_y = y;
263 if (width != -1) m_width = width;
264 if (height != -1) m_height = height;
265 }
266 else
267 {
268 m_x = x;
269 m_y = y;
270 m_width = width;
271 m_height = height;
272 }
273
274 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
275 {
276 if (width == -1) m_width = 80;
277 }
278
279 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
280 {
281 if (height == -1) m_height = 26;
282 }
8bbe427f 283
fb1585ae
RR
284 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
285 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
286 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth;
287 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight;
288
289 if ((m_x != -1) || (m_y != -1))
290 {
8bbe427f 291 if ((m_x != old_x) || (m_y != old_y))
fb1585ae
RR
292 gtk_widget_set_uposition( m_widget, m_x, m_y );
293 }
8bbe427f 294
fb1585ae
RR
295 if ((m_width != old_width) || (m_height != old_height))
296 {
297 gtk_widget_set_usize( m_widget, m_width, m_height );
298 }
8bbe427f 299
fb1585ae
RR
300 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
301 event.SetEventObject( this );
e52f60e6 302 GetEventHandler()->ProcessEvent( event );
fb1585ae
RR
303
304 m_resizing = FALSE;
903f689b
RR
305}
306
43a18898
RR
307void wxFrame::SetSize( int width, int height )
308{
309 SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING );
310}
311
903f689b
RR
312void wxFrame::Centre( int direction )
313{
fb1585ae 314 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 315
43a18898
RR
316 int x = 0;
317 int y = 0;
8bbe427f 318
fb1585ae
RR
319 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
320 if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
8bbe427f 321
fb1585ae 322 Move( x, y );
903f689b
RR
323}
324
c801d85f
KB
325void wxFrame::GetClientSize( int *width, int *height ) const
326{
fb1585ae 327 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 328
fb1585ae
RR
329 wxWindow::GetClientSize( width, height );
330 if (height)
46dc76ba 331 {
fb1585ae
RR
332 if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT;
333 if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT;
334 if (m_frameToolBar)
335 {
336 int y = 0;
337 m_frameToolBar->GetSize( (int *) NULL, &y );
338 (*height) -= y;
339 }
b2b3ccc5
RR
340 (*height) -= m_miniEdge*2 + m_miniTitle;
341 }
342 if (width)
343 {
344 (*width) -= m_miniEdge*2;
46dc76ba 345 }
362c6693 346}
c801d85f 347
b593568e
RR
348void wxFrame::SetClientSize( int const width, int const height )
349{
f5368809 350 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 351
f5368809
RR
352 int h = height;
353 if (m_frameMenuBar) h += wxMENU_HEIGHT;
354 if (m_frameStatusBar) h += wxSTATUS_HEIGHT;
355 if (m_frameToolBar)
356 {
357 int y = 0;
358 m_frameToolBar->GetSize( (int *) NULL, &y );
359 h += y;
360 }
b2b3ccc5 361 wxWindow::SetClientSize( width + m_miniEdge*2, h + m_miniEdge*2 + m_miniTitle );
362c6693 362}
b593568e 363
47908e25 364void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
c801d85f 365{
f5368809
RR
366 // due to a bug in gtk, x,y are always 0
367 // m_x = x;
368 // m_y = y;
369
e52f60e6
RR
370 if (m_resizing) return;
371 m_resizing = TRUE;
8bbe427f 372
f5368809 373 if (!m_wxwindow) return;
8bbe427f 374
f5368809
RR
375 m_width = width;
376 m_height = height;
8bbe427f 377
f5368809
RR
378 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
379 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
380 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth;
381 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight;
382
7f985bd3 383 gtk_widget_set_usize( m_widget, m_width, m_height );
8bbe427f 384
b2b3ccc5
RR
385 // this emulates the new wxMSW behaviour of placing all
386 // frame-subwindows (menu, toolbar..) on one native window
387 // OK, this hurts in the eye, but I don't want to call SetSize()
388 // because I don't want to call any non-native functions here.
8bbe427f 389
f5368809
RR
390 if (m_frameMenuBar)
391 {
907789a0 392 int xx = m_miniEdge;
8bbe427f
VZ
393 int yy = m_miniEdge + m_miniTitle;
394 int ww = m_width - 2*m_miniEdge;
395 int hh = wxMENU_HEIGHT;
b2b3ccc5
RR
396 m_frameMenuBar->m_x = xx;
397 m_frameMenuBar->m_y = yy;
398 m_frameMenuBar->m_width = ww;
399 m_frameMenuBar->m_height = hh;
8bbe427f 400
b2b3ccc5
RR
401 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, xx, yy );
402 gtk_widget_set_usize( m_frameMenuBar->m_widget, ww, hh );
f5368809
RR
403 }
404
405 if (m_frameToolBar)
406 {
907789a0 407 int xx = m_miniEdge;
8bbe427f 408 int yy = m_miniEdge + m_miniTitle;
b2b3ccc5 409 if (m_frameMenuBar) yy += wxMENU_HEIGHT;
8bbe427f 410 int ww = m_width - 2*m_miniEdge;
b2b3ccc5 411 int hh = m_frameToolBar->m_height;
8bbe427f
VZ
412
413 m_frameToolBar->m_x = xx;
b2b3ccc5
RR
414 m_frameToolBar->m_y = yy;
415 m_frameToolBar->m_height = hh;
416 m_frameToolBar->m_width = ww;
8bbe427f 417
b2b3ccc5
RR
418 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, xx, yy );
419 gtk_widget_set_usize( m_frameToolBar->m_widget, ww, hh );
f5368809 420 }
8bbe427f 421
f5368809
RR
422 if (m_frameStatusBar)
423 {
b2b3ccc5 424 int xx = 0 + m_miniEdge;
8bbe427f
VZ
425 int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge;
426 int ww = m_width - 2*m_miniEdge;
427 int hh = wxSTATUS_HEIGHT;
428
b2b3ccc5
RR
429 m_frameStatusBar->m_x = xx;
430 m_frameStatusBar->m_y = yy;
431 m_frameStatusBar->m_width = ww;
432 m_frameStatusBar->m_height = hh;
8bbe427f 433
b2b3ccc5
RR
434 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, xx, yy );
435 gtk_widget_set_usize( m_frameStatusBar->m_widget, ww, hh );
f5368809 436 }
8bbe427f 437
f5368809 438 m_sizeSet = TRUE;
8bbe427f 439
43a18898
RR
440 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
441 event.SetEventObject( this );
e52f60e6 442 GetEventHandler()->ProcessEvent( event );
8bbe427f 443
e52f60e6
RR
444 m_resizing = FALSE;
445}
446
447void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) )
448{
449 if (!m_sizeSet)
450 GtkOnSize( m_x, m_y, m_width, m_height );
8bbe427f 451
e52f60e6 452 DoMenuUpdates();
362c6693 453}
c801d85f
KB
454
455void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
456{
f5368809 457 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 458
f5368809
RR
459 if (GetAutoLayout())
460 {
461 Layout();
462 }
8bbe427f 463 else
c801d85f 464 {
f5368809 465 // no child: go out !
db1b4961 466 if (!GetChildren().First()) return;
8bbe427f 467
f5368809
RR
468 // do we have exactly one child?
469 wxWindow *child = (wxWindow *) NULL;
db1b4961 470 for(wxNode *node = GetChildren().First(); node; node = node->Next())
f5368809
RR
471 {
472 wxWindow *win = (wxWindow *)node->Data();
de135918 473 if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog)
6ca41e57 474#if 0 // not in m_children anyway ?
f5368809
RR
475 && (win != m_frameMenuBar) &&
476 (win != m_frameToolBar) &&
477 (win != m_frameStatusBar)
ed7a557b 478#endif
f5368809
RR
479 )
480 {
8bbe427f 481 // it's the second one: do nothing
f5368809
RR
482 if (child) return;
483 child = win;
484 }
485 }
ed7a557b 486
f5368809
RR
487 // yes: set it's size to fill all the frame
488 int client_x, client_y;
489 GetClientSize( &client_x, &client_y );
7be4c594 490 child->SetSize( 1, 1, client_x-2, client_y-2 );
362c6693 491 }
362c6693 492}
c801d85f 493
716b7364 494static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
c801d85f 495{
f5368809
RR
496 menu->SetInvokingWindow( win );
497 wxNode *node = menu->m_items.First();
498 while (node)
499 {
500 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
501 if (menuitem->IsSubMenu())
502 SetInvokingWindow( menuitem->GetSubMenu(), win );
503 node = node->Next();
504 }
362c6693 505}
c801d85f
KB
506
507void wxFrame::SetMenuBar( wxMenuBar *menuBar )
508{
f5368809
RR
509 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
510 wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" );
8bbe427f 511
f5368809 512 m_frameMenuBar = menuBar;
8bbe427f 513
f5368809 514 if (m_frameMenuBar)
30dea054 515 {
f5368809
RR
516 wxNode *node = m_frameMenuBar->m_menus.First();
517 while (node)
518 {
519 wxMenu *menu = (wxMenu*)node->Data();
520 SetInvokingWindow( menu, this );
521 node = node->Next();
522 }
8bbe427f 523
f5368809
RR
524 if (m_frameMenuBar->m_parent != this)
525 {
526 m_frameMenuBar->m_parent = this;
527 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow),
528 m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y );
529 }
716b7364 530 }
8bbe427f 531
7be4c594 532 if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height );
362c6693 533}
c801d85f 534
8bbe427f 535wxMenuBar *wxFrame::GetMenuBar() const
46dc76ba 536{
f5368809 537 return m_frameMenuBar;
362c6693 538}
46dc76ba 539
362c6693 540wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
46dc76ba 541{
f5368809 542 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 543
f5368809 544 wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" );
362c6693 545
f5368809 546 m_frameToolBar = OnCreateToolBar( style, id, name );
8bbe427f 547
db1b4961 548 GetChildren().DeleteObject( m_frameToolBar );
8bbe427f 549
7be4c594 550 if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height );
8bbe427f 551
f5368809 552 return m_frameToolBar;
362c6693 553}
46dc76ba 554
362c6693 555wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name )
46dc76ba 556{
f5368809 557 return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name );
362c6693
RR
558}
559
8bbe427f
VZ
560wxToolBar *wxFrame::GetToolBar() const
561{
562 return m_frameToolBar;
362c6693 563}
46dc76ba 564
e3e65dac 565wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
c801d85f 566{
f5368809 567 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 568
f5368809 569 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, "recreating status bar in wxFrame" );
c801d85f 570
f5368809 571 m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
8bbe427f 572
7be4c594 573 if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height );
8bbe427f 574
f5368809 575 return m_frameStatusBar;
362c6693
RR
576}
577
578wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
579{
f5368809 580 wxStatusBar *statusBar = (wxStatusBar *) NULL;
8bbe427f 581
f5368809 582 statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name);
8bbe427f 583
f5368809
RR
584 // Set the height according to the font and the border size
585 wxClientDC dc(statusBar);
8bbe427f 586 dc.SetFont( statusBar->GetFont() );
362c6693 587
f5368809
RR
588 long x, y;
589 dc.GetTextExtent( "X", &x, &y );
362c6693 590
f5368809 591 int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
362c6693 592
f5368809 593 statusBar->SetSize( -1, -1, 100, height );
362c6693 594
f5368809
RR
595 statusBar->SetFieldsCount( number );
596 return statusBar;
362c6693 597}
c801d85f 598
362c6693 599void wxFrame::SetStatusText(const wxString& text, int number)
c801d85f 600{
f5368809 601 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 602
f5368809 603 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
c801d85f 604
f5368809 605 m_frameStatusBar->SetStatusText(text, number);
362c6693
RR
606}
607
608void wxFrame::SetStatusWidths(int n, const int widths_field[] )
c801d85f 609{
f5368809 610 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 611
f5368809 612 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
362c6693 613
f5368809 614 m_frameStatusBar->SetStatusWidths(n, widths_field);
362c6693 615}
c801d85f 616
8bbe427f 617wxStatusBar *wxFrame::GetStatusBar() const
c801d85f 618{
f5368809 619 return m_frameStatusBar;
362c6693 620}
c801d85f 621
c801d85f
KB
622void wxFrame::SetTitle( const wxString &title )
623{
f5368809 624 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 625
f5368809
RR
626 m_title = title;
627 if (m_title.IsNull()) m_title = "";
628 gtk_window_set_title( GTK_WINDOW(m_widget), title );
362c6693 629}
c801d85f 630
d355d3fe
RR
631void wxFrame::SetIcon( const wxIcon &icon )
632{
f5368809 633 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 634
f5368809
RR
635 m_icon = icon;
636 if (!icon.Ok()) return;
8bbe427f 637
f5368809
RR
638 wxMask *mask = icon.GetMask();
639 GdkBitmap *bm = (GdkBitmap *) NULL;
640 if (mask) bm = mask->GetBitmap();
8bbe427f 641
f5368809 642 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
d355d3fe 643}
b2b3ccc5 644