1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "frame.h"
16 #include "wx/wxprec.h"
19 #include "wx/statusbr.h"
20 #include "wx/toolbar.h"
21 #include "wx/menuitem.h"
23 #include "wx/dcclient.h"
24 #include "wx/dialog.h"
25 #include "wx/settings.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
31 extern wxList wxPendingDelete
;
33 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
34 EVT_ACTIVATE(wxFrame::OnActivate
)
35 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
36 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
37 // EVT_IDLE(wxFrame::OnIdle)
38 // EVT_CLOSE(wxFrame::OnCloseWindow)
41 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
43 #define WX_MAC_STATUSBAR_HEIGHT 18
44 // ----------------------------------------------------------------------------
45 // creation/destruction
46 // ----------------------------------------------------------------------------
50 m_frameMenuBar
= NULL
;
53 m_frameToolBar
= NULL
;
55 m_frameStatusBar
= NULL
;
56 m_winLastFocused
= NULL
;
65 bool wxFrame::Create(wxWindow
*parent
,
67 const wxString
& title
,
74 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
77 wxModelessWindows
.Append(this);
84 m_isBeingDeleted
= true;
89 bool wxFrame::Enable(bool enable
)
91 if ( !wxWindow::Enable(enable
) )
94 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
96 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
97 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
99 m_frameMenuBar
->EnableTop( i
, enable
) ;
106 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
107 const wxString
& name
)
109 wxStatusBar
*statusBar
= NULL
;
111 statusBar
= new wxStatusBar(this, id
,
113 statusBar
->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT
) ;
114 statusBar
->SetFieldsCount(number
);
118 void wxFrame::PositionStatusBar()
120 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
123 GetClientSize(&w
, &h
);
125 // Since we wish the status bar to be directly under the client area,
126 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
127 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
131 // Responds to colour changes, and passes event on to children.
132 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
134 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
137 if ( m_frameStatusBar
)
139 wxSysColourChangedEvent event2
;
140 event2
.SetEventObject( m_frameStatusBar
);
141 m_frameStatusBar
->ProcessEvent(event2
);
144 // Propagate the event to the non-top-level children
145 wxWindow::OnSysColourChanged(event
);
149 // Default activation behaviour - set the focus for the first child
151 void wxFrame::OnActivate(wxActivateEvent
& event
)
153 if ( !event
.GetActive() )
155 // remember the last focused child if it is our child
156 m_winLastFocused
= FindFocus();
158 // so we NULL it out if it's a child from some other frame
159 wxWindow
*win
= m_winLastFocused
;
162 if ( win
->IsTopLevel() )
166 m_winLastFocused
= NULL
;
172 win
= win
->GetParent();
179 // restore focus to the child which was last focused
180 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
187 wxSetFocusToChild(parent
, &m_winLastFocused
);
189 if ( m_frameMenuBar
!= NULL
)
191 m_frameMenuBar
->MacInstallMenuBar() ;
193 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
195 // Trying toplevel frame menbar
196 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
197 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
202 void wxFrame::DetachMenuBar()
204 if ( m_frameMenuBar
)
206 m_frameMenuBar
->UnsetInvokingWindow();
209 wxFrameBase::DetachMenuBar();
212 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
214 wxFrameBase::AttachMenuBar(menuBar
);
218 m_frameMenuBar
->SetInvokingWindow( this );
222 void wxFrame::DoGetClientSize(int *x
, int *y
) const
224 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
227 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
229 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
231 #endif // wxUSE_STATUSBAR
234 wxToolBar
*toolbar
= GetToolBar();
235 if ( toolbar
&& toolbar
->IsShown() )
238 toolbar
->GetSize(&w
, &h
);
240 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
249 #endif // wxUSE_TOOLBAR
252 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
255 if ( child
== GetStatusBar() )
257 #endif // wxUSE_STATUSBAR
260 if ( child
== GetToolBar() )
262 #endif // wxUSE_TOOLBAR
264 return wxFrameBase::MacIsChildOfClientArea( child
) ;
267 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
269 int currentclientwidth
, currentclientheight
;
270 int currentwidth
, currentheight
;
272 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
273 if ( clientwidth
== -1 )
274 clientwidth
= currentclientwidth
;
275 if ( clientheight
== -1 )
276 clientheight
= currentclientheight
;
277 GetSize( ¤twidth
, ¤theight
) ;
279 // find the current client size
281 // Find the difference between the entire window (title bar and all)
282 // and the client area; add this to the new client size to move the
285 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
286 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
291 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
293 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
298 return m_frameToolBar
;
301 void wxFrame::PositionToolBar()
305 GetSize( &cw
, &ch
) ;
307 if ( GetStatusBar() && GetStatusBar()->IsShown())
309 int statusX
, statusY
;
310 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
319 GetToolBar()->GetSize(& tw
, & th
);
320 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
322 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
323 // means, pretend we don't have toolbar/status bar, so we
324 // have the original client size.
325 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
329 // Use the 'real' position
330 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);