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