1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/frame.cpp 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  18     #include "wx/dcclient.h" 
  20     #include "wx/dialog.h" 
  21     #include "wx/settings.h" 
  22     #include "wx/toolbar.h" 
  23     #include "wx/statusbr.h" 
  24     #include "wx/menuitem.h" 
  27 #include "wx/mac/uma.h" 
  29 extern wxWindowList wxModelessWindows
; 
  31 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
) 
  32   EVT_ACTIVATE(wxFrame::OnActivate
) 
  33  // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) 
  34   EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
) 
  35 //  EVT_IDLE(wxFrame::OnIdle) 
  36 //  EVT_CLOSE(wxFrame::OnCloseWindow) 
  39 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
) 
  41 #define WX_MAC_STATUSBAR_HEIGHT 18 
  43 // ---------------------------------------------------------------------------- 
  44 // creation/destruction 
  45 // ---------------------------------------------------------------------------- 
  49     m_winLastFocused 
= NULL
; 
  52 bool wxFrame::Create(wxWindow 
*parent
, 
  54            const wxString
& title
, 
  61     if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) ) 
  64     wxModelessWindows
.Append(this); 
  71     m_isBeingDeleted 
= true; 
  75 // get the origin of the client area in the client coordinates 
  76 wxPoint 
wxFrame::GetClientAreaOrigin() const 
  78     wxPoint pt 
= wxTopLevelWindow::GetClientAreaOrigin(); 
  80 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) 
  81     wxToolBar 
*toolbar 
= GetToolBar(); 
  82     if ( toolbar 
&& toolbar
->IsShown() ) 
  85         toolbar
->GetSize(&w
, &h
); 
  87         if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL 
) 
  93 #if !wxMAC_USE_NATIVE_TOOLBAR 
 103 bool wxFrame::Enable(bool enable
) 
 105     if ( !wxWindow::Enable(enable
) ) 
 108     if ( m_frameMenuBar 
&& m_frameMenuBar 
== wxMenuBar::MacGetInstalledMenuBar() ) 
 110         int iMaxMenu 
= m_frameMenuBar
->GetMenuCount(); 
 111         for ( int i 
= 0 ; i 
< iMaxMenu 
; ++ i 
) 
 113             m_frameMenuBar
->EnableTop( i 
, enable 
) ; 
 121 wxStatusBar 
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
, 
 122     const wxString
& name
) 
 124     wxStatusBar 
*statusBar
; 
 126     statusBar 
= new wxStatusBar(this, id
, style
, name
); 
 127     statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
); 
 128     statusBar
->SetFieldsCount(number
); 
 133 void wxFrame::PositionStatusBar() 
 135     if (m_frameStatusBar 
&& m_frameStatusBar
->IsShown() ) 
 138         GetClientSize(&w
, &h
); 
 140         // Since we wish the status bar to be directly under the client area, 
 141         // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. 
 142         m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
); 
 145 #endif // wxUSE_STATUSBAR 
 147 // Responds to colour changes, and passes event on to children. 
 148 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
 150     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
)); 
 154     if ( m_frameStatusBar 
) 
 156         wxSysColourChangedEvent event2
; 
 158         event2
.SetEventObject( m_frameStatusBar 
); 
 159         m_frameStatusBar
->ProcessEvent(event2
); 
 161 #endif // wxUSE_STATUSBAR 
 163     // Propagate the event to the non-top-level children 
 164     wxWindow::OnSysColourChanged(event
); 
 167 // Default activation behaviour - set the focus for the first child 
 169 void wxFrame::OnActivate(wxActivateEvent
& event
) 
 171     if ( !event
.GetActive() ) 
 173        // remember the last focused child if it is our child 
 174         m_winLastFocused 
= FindFocus(); 
 176         // so we NULL it out if it's a child from some other frame 
 177         wxWindow 
*win 
= m_winLastFocused
; 
 180             if ( win
->IsTopLevel() ) 
 183                     m_winLastFocused 
= NULL
; 
 188             win 
= win
->GetParent(); 
 195         // restore focus to the child which was last focused 
 196         wxWindow 
*parent 
= m_winLastFocused
 
 197             ? m_winLastFocused
->GetParent() 
 203         wxSetFocusToChild(parent
, &m_winLastFocused
); 
 205         if (m_frameMenuBar 
!= NULL
) 
 207             m_frameMenuBar
->MacInstallMenuBar(); 
 211             wxFrame 
*tlf 
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame 
); 
 214                 // Trying top-level frame membar 
 215                 if (tlf
->GetMenuBar()) 
 216                     tlf
->GetMenuBar()->MacInstallMenuBar(); 
 222 void wxFrame::DetachMenuBar() 
 224     if ( m_frameMenuBar 
) 
 225         m_frameMenuBar
->UnsetInvokingWindow(); 
 227     wxFrameBase::DetachMenuBar(); 
 230 void wxFrame::AttachMenuBar( wxMenuBar 
*menuBar 
) 
 232     wxFrame
* tlf 
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame 
); 
 233     bool makeCurrent 
= false; 
 235     // if this is already the current menubar or we are the frontmost window 
 236     if ( (tlf 
== this) || (m_frameMenuBar 
== wxMenuBar::MacGetInstalledMenuBar()) ) 
 238     // or there is an app-level menubar like MDI 
 239     else if ( tlf 
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) ) 
 242     wxFrameBase::AttachMenuBar( menuBar 
); 
 246         m_frameMenuBar
->SetInvokingWindow( this ); 
 248             m_frameMenuBar
->MacInstallMenuBar(); 
 252 void wxFrame::DoGetClientSize(int *x
, int *y
) const 
 254     wxTopLevelWindow::DoGetClientSize( x 
, y 
); 
 257     if ( GetStatusBar() && GetStatusBar()->IsShown() && y 
) 
 258         *y 
-= WX_MAC_STATUSBAR_HEIGHT
; 
 262     wxToolBar 
*toolbar 
= GetToolBar(); 
 263     if ( toolbar 
&& toolbar
->IsShown() ) 
 266         toolbar
->GetSize(&w
, &h
); 
 268         if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL 
) 
 275 #if !wxMAC_USE_NATIVE_TOOLBAR 
 284 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child 
) const 
 287     if ( child 
== GetStatusBar() ) 
 292     if ( child 
== GetToolBar() ) 
 296     return wxFrameBase::MacIsChildOfClientArea( child 
) ; 
 299 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
) 
 301     int currentclientwidth 
, currentclientheight 
; 
 302     int currentwidth 
, currentheight 
; 
 304     GetClientSize( ¤tclientwidth 
, ¤tclientheight 
) ; 
 305     if ( clientwidth 
== -1 ) 
 306         clientwidth 
= currentclientwidth 
; 
 307     if ( clientheight 
== -1 ) 
 308         clientheight 
= currentclientheight 
; 
 309     GetSize( ¤twidth 
, ¤theight 
) ; 
 311     // find the current client size 
 313     // Find the difference between the entire window (title bar and all) and 
 314     // the client area; add this to the new client size to move the window 
 315     DoSetSize( -1 , -1 , currentwidth 
+ clientwidth 
- currentclientwidth 
, 
 316         currentheight 
+ clientheight 
- currentclientheight 
, wxSIZE_USE_EXISTING 
) ; 
 320 void wxFrame::SetToolBar(wxToolBar 
*toolbar
) 
 322     if ( m_frameToolBar 
== toolbar 
) 
 325 #if wxMAC_USE_NATIVE_TOOLBAR 
 326     if ( m_frameToolBar 
) 
 327         m_frameToolBar
->MacInstallNativeToolbar( false ) ; 
 330     m_frameToolBar 
= toolbar 
; 
 332 #if wxMAC_USE_NATIVE_TOOLBAR 
 334         toolbar
->MacInstallNativeToolbar( true ) ; 
 338 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
) 
 340     if ( wxFrameBase::CreateToolBar(style
, id
, name
) ) 
 343     return m_frameToolBar
; 
 346 void wxFrame::PositionToolBar() 
 350     GetSize( &cw 
, &ch 
) ; 
 356     if (GetStatusBar() && GetStatusBar()->IsShown()) 
 358         GetStatusBar()->GetClientSize(&statusX
, &statusY
); 
 368         GetToolBar()->GetSize(&tw
, &th
); 
 369         if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
) 
 371             // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS 
 372             // means, pretend we don't have toolbar/status bar, so we 
 373             // have the original client size. 
 374             GetToolBar()->SetSize(tx 
, ty 
, tw
, ch 
, wxSIZE_NO_ADJUSTMENTS 
); 
 376         else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM
) 
 378             //FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet, 
 379             //as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar 
 380             //doesn't extend it's width to the width of the frame. 
 382             ty 
= ch 
- (th 
+ statusY
); 
 383             GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS 
); 
 387 #if !wxMAC_USE_NATIVE_TOOLBAR 
 388             // Use the 'real' position 
 389             GetToolBar()->SetSize(tx 
, ty 
, cw 
, th
, wxSIZE_NO_ADJUSTMENTS 
); 
 394 #endif // wxUSE_TOOLBAR 
 396 void wxFrame::PositionBars()