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