X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..3a922bb4bd8dbcb04e31e324648c2912e167e0cd:/src/mac/frame.cpp?ds=sidebyside diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index 1e8c9e9ae5..8a589cbf54 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: frame.cpp -// Purpose: wxFrame +// Purpose: wxFrameMac // Author: AUTHOR // Modified by: // Created: ??/??/98 @@ -23,39 +23,81 @@ #include "wx/settings.h" #include "wx/app.h" +#include + extern wxList wxModelessWindows; extern wxList wxPendingDelete; #if !USE_SHARED_LIBRARY -BEGIN_EVENT_TABLE(wxFrame, wxWindow) - EVT_SIZE(wxFrame::OnSize) - EVT_ACTIVATE(wxFrame::OnActivate) - EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) - EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) - EVT_IDLE(wxFrame::OnIdle) - EVT_CLOSE(wxFrame::OnCloseWindow) +BEGIN_EVENT_TABLE(wxFrameMac, wxFrameBase) +// EVT_SIZE(wxFrameMac::OnSize) + EVT_ACTIVATE(wxFrameMac::OnActivate) + // EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight) + EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged) +// EVT_IDLE(wxFrameMac::OnIdle) +// EVT_CLOSE(wxFrameMac::OnCloseWindow) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) +IMPLEMENT_DYNAMIC_CLASS(wxFrameMac, wxWindow) +#endif +#ifndef __WXUNIVERSAL__ +IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxFrameMac) #endif #if wxUSE_NATIVE_STATUSBAR -bool wxFrame::m_useNativeStatusBar = TRUE; +bool wxFrameMac::m_useNativeStatusBar = TRUE; #else -bool wxFrame::m_useNativeStatusBar = FALSE; +bool wxFrameMac::m_useNativeStatusBar = FALSE; #endif -wxFrame::wxFrame() +#define WX_MAC_STATUSBAR_HEIGHT 15 +// ---------------------------------------------------------------------------- +// creation/destruction +// ---------------------------------------------------------------------------- + +void wxFrameMac::Init() { - m_frameToolBar = NULL ; m_frameMenuBar = NULL; + +#if wxUSE_TOOLBAR + m_frameToolBar = NULL ; +#endif m_frameStatusBar = NULL; + m_winLastFocused = NULL ; + + m_iconized = FALSE; - m_windowParent = NULL; - m_iconized = FALSE; +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; +#endif } -bool wxFrame::Create(wxWindow *parent, +wxPoint wxFrameMac::GetClientAreaOrigin() const +{ + // on mac we are at position -1,-1 with the control + wxPoint pt(0, 0); + +#if wxUSE_TOOLBAR + if ( GetToolBar() ) + { + int w, h; + GetToolBar()->GetSize(& w, & h); + + if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) + { + pt.x += w - 1; + } + else + { + pt.y += h - 1 ; + } + } +#endif // wxUSE_TOOLBAR + + return pt; +} + +bool wxFrameMac::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, @@ -63,15 +105,6 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if (!parent) - wxTopLevelWindows.Append(this); - - SetName(name); - m_windowStyle = style; - m_frameMenuBar = NULL; - m_frameToolBar = NULL ; - m_frameStatusBar = NULL; - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); if ( id > -1 ) @@ -81,21 +114,24 @@ bool wxFrame::Create(wxWindow *parent, if (parent) parent->AddChild(this); - wxModelessWindows.Append(this); + if (!parent) + wxTopLevelWindows.Append(this); + + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - // TODO: create frame. + wxModelessWindows.Append(this); - return FALSE; + return TRUE; } -wxFrame::~wxFrame() +wxFrameMac::~wxFrameMac() { + m_isBeingDeleted = TRUE; wxTopLevelWindows.DeleteObject(this); - if (m_frameStatusBar) - delete m_frameStatusBar; - if (m_frameMenuBar) - delete m_frameMenuBar; + DeleteAllBars(); /* Check if it's the last top-level window */ @@ -105,146 +141,79 @@ wxFrame::~wxFrame() if (wxTheApp->GetExitOnFrameDelete()) { - // TODO signal to the app that we're going to close + wxTheApp->ExitMainLoop() ; } } wxModelessWindows.DeleteObject(this); } -// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. -void wxFrame::GetClientSize(int *x, int *y) const -{ - // TODO -} -// Set the client size (i.e. leave the calculation of borders etc. -// to wxWindows) -void wxFrame::SetClientSize(int width, int height) +bool wxFrameMac::Enable(bool enable) { - // TODO -} + if ( !wxWindow::Enable(enable) ) + return FALSE; -void wxFrame::GetSize(int *width, int *height) const -{ - // TODO -} + if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) + { + for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) + { + m_frameMenuBar->EnableTop( i , enable ) ; + } + } -void wxFrame::GetPosition(int *x, int *y) const -{ - // TODO + return TRUE; } - -void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags) +// Equivalent to maximize/restore in Windows +void wxFrameMac::Maximize(bool maximize) { // TODO } -bool wxFrame::Show(bool show) +bool wxFrameMac::IsIconized() const { // TODO return FALSE; } -void wxFrame::Iconize(bool iconize) +void wxFrameMac::Iconize(bool iconize) { // TODO } -// Equivalent to maximize/restore in Windows -void wxFrame::Maximize(bool maximize) -{ - // TODO -} - -bool wxFrame::IsIconized() const -{ - // TODO - return FALSE; -} - // Is the frame maximized? -bool wxFrame::IsMaximized(void) const +bool wxFrameMac::IsMaximized(void) const { // TODO return FALSE; } -void wxFrame::SetTitle(const wxString& title) +void wxFrameMac::Restore() { // TODO } -wxString wxFrame::GetTitle() const +void wxFrameMac::SetIcon(const wxIcon& icon) { - // TODO - return wxString(""); + wxFrameBase::SetIcon(icon); } -void wxFrame::SetIcon(const wxIcon& icon) -{ - m_icon = icon; - // TODO -} - -wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, +wxStatusBar *wxFrameMac::OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name) { wxStatusBar *statusBar = NULL; - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), + statusBar = new wxStatusBar(this, id, style, name); - - // Set the height according to the font and the border size - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); - - long x, y; - dc.GetTextExtent("X", &x, &y); - - int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); - - statusBar->SetSize(-1, -1, 100, height); - + statusBar->SetSize( 100 , 15 ) ; statusBar->SetFieldsCount(number); return statusBar; } -wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) +void wxFrameMac::PositionStatusBar() { - // Calling CreateStatusBar twice is an error. - wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, - "recreating status bar in wxFrame" ); - - m_frameStatusBar = OnCreateStatusBar(number, style, id, - name); - if ( m_frameStatusBar ) + if (m_frameStatusBar ) { - PositionStatusBar(); - return m_frameStatusBar; - } - else - return NULL; -} - -void wxFrame::SetStatusText(const wxString& text, int number) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); - - m_frameStatusBar->SetStatusText(text, number); -} - -void wxFrame::SetStatusWidths(int n, const int widths_field[]) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); - - m_frameStatusBar->SetStatusWidths(n, widths_field); - PositionStatusBar(); -} - -void wxFrame::PositionStatusBar() -{ int w, h; GetClientSize(&w, &h); int sw, sh; @@ -253,52 +222,11 @@ void wxFrame::PositionStatusBar() // Since we wish the status bar to be directly under the client area, // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. m_frameStatusBar->SetSize(0, h, w, sh); -} - -void wxFrame::SetMenuBar(wxMenuBar *menuBar) -{ - if (!menuBar) - { - m_frameMenuBar = NULL; - return; - } - - m_frameMenuBar = menuBar; - - // TODO -} - -void wxFrame::Fit() -{ - // Work out max. size - wxNode *node = GetChildren().First(); - int max_width = 0; - int max_height = 0; - while (node) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *win = (wxWindow *)node->Data(); - - if (!win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog))) - { - int width, height; - int x, y; - win->GetSize(&width, &height); - win->GetPosition(&x, &y); - - if ((x + width) > max_width) - max_width = x + width; - if ((y + height) > max_height) - max_height = y + height; - } - node = node->Next(); - } - SetClientSize(max_width, max_height); + } } // Responds to colour changes, and passes event on to children. -void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) +void wxFrameMac::OnSysColourChanged(wxSysColourChangedEvent& event) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); Refresh(); @@ -314,233 +242,117 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxWindow::OnSysColourChanged(event); } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size -void wxFrame::OnSize(wxSizeEvent& event) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; - } - #endif - - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) && - (win != GetToolBar()) ) - { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; - } - } - - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); - - int x = 0; - int y = 0; - - child->SetSize(x, y, clientW, clientH); - } -} // Default activation behaviour - set the focus for the first child // subwindow found. -void wxFrame::OnActivate(wxActivateEvent& event) +void wxFrameMac::OnActivate(wxActivateEvent& event) { - for(wxNode *node = GetChildren().First(); node; node = node->Next()) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *child = (wxWindow *)node->Data(); - if (!child->IsKindOf(CLASSINFO(wxFrame)) && - !child->IsKindOf(CLASSINFO(wxDialog))) + if ( !event.GetActive() ) { - child->SetFocus(); - return; - } - } -} + // remember the last focused child + m_winLastFocused = FindFocus(); + while ( m_winLastFocused ) + { + if ( GetChildren().Find(m_winLastFocused) ) + break; -// The default implementation for the close window event - calls -// OnClose for backward compatibility. + m_winLastFocused = m_winLastFocused->GetParent(); + } -void wxFrame::OnCloseWindow(wxCloseEvent& event) -{ - // Compatibility - if ( GetEventHandler()->OnClose() || event.GetForce()) - { - this->Destroy(); + event.Skip(); } -} - -bool wxFrame::OnClose() -{ - return TRUE; -} - -// Destroy the window (delayed, if a managed window) -bool wxFrame::Destroy() -{ - if (!wxPendingDelete.Member(this)) - wxPendingDelete.Append(this); - return TRUE; -} - -// Default menu selection behaviour - display a help string -void wxFrame::OnMenuHighlight(wxMenuEvent& event) -{ - if (GetStatusBar()) - { - if (event.GetMenuId() == -1) - SetStatusText(""); - else + else + { +/* + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuBar *menuBar = GetMenuBar(); - if (menuBar) - { - wxString helpString(menuBar->GetHelpString(event.GetMenuId())); - if (helpString != "") - SetStatusText(helpString); - } + // FIXME all this is totally bogus - we need to do the same as wxPanel, + // but how to do it without duplicating the code? + + // restore focus + wxWindow *child = node->GetData(); + + if ( !child->IsTopLevel() && child->AcceptsFocus() +#if wxUSE_TOOLBAR + && !wxDynamicCast(child, wxToolBar) +#endif // wxUSE_TOOLBAR +#if wxUSE_STATUSBAR + && !wxDynamicCast(child, wxStatusBar) +#endif // wxUSE_STATUSBAR + ) + { + child->SetFocus(); + break; + } } - } -} - -wxMenuBar *wxFrame::GetMenuBar() const -{ - return m_frameMenuBar; -} - -void wxFrame::Centre(int direction) -{ - int display_width, display_height, width, height, x, y; - wxDisplaySize(&display_width, &display_height); + */ + wxSetFocusToChild(this, &m_winLastFocused); - GetSize(&width, &height); - GetPosition(&x, &y); - - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); - - SetSize(x, y, width, height); + if ( m_frameMenuBar != NULL ) + { + m_frameMenuBar->MacInstallMenuBar() ; + } + } } -// Call this to simulate a menu command -void wxFrame::Command(int id) +void wxFrameMac::DoGetClientSize(int *x, int *y) const { - ProcessCommand(id); -} + wxWindow::DoGetClientSize( x , y ) ; -void wxFrame::ProcessCommand(int id) -{ - wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id); - commandEvent.SetInt( id ); - commandEvent.SetEventObject( this ); - - wxMenuBar *bar = GetMenuBar() ; - if (!bar) - return; - -/* TODO: check the menu item if required - wxMenuItem *item = bar->FindItemForId(id) ; - if (item && item->IsCheckable()) +#if wxUSE_STATUSBAR + if ( GetStatusBar() && y ) { - bar->Check(id,!bar->Checked(id)) ; + int statusX, statusY; + GetStatusBar()->GetClientSize(&statusX, &statusY); + *y -= statusY; } -*/ +#endif // wxUSE_STATUSBAR - GetEventHandler()->ProcessEvent(commandEvent); + wxPoint pt(GetClientAreaOrigin()); + if ( y ) + *y -= pt.y; + if ( x ) + *x -= pt.x; } -// Checks if there is a toolbar, and returns the first free client position -wxPoint wxFrame::GetClientAreaOrigin() const +void wxFrameMac::DoSetClientSize(int clientwidth, int clientheight) { - wxPoint pt(0, 0); - if (GetToolBar()) - { - int w, h; - GetToolBar()->GetSize(& w, & h); + int currentclientwidth , currentclientheight ; + int currentwidth , currentheight ; + + GetClientSize( ¤tclientwidth , ¤tclientheight ) ; + GetSize( ¤twidth , ¤theight ) ; + + // find the current client size - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) - { - pt.x += w; - } - else - { - pt.y += h; - } - } - return pt; -} + // Find the difference between the entire window (title bar and all) + // and the client area; add this to the new client size to move the + // window -void wxFrame::ScreenToClient(int *x, int *y) const -{ - wxWindow::ScreenToClient(x, y); - - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - wxPoint pt(GetClientAreaOrigin()); - *x -= pt.x; - *y -= pt.y; + DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , + currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; } -void wxFrame::ClientToScreen(int *x, int *y) const -{ - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - wxPoint pt1(GetClientAreaOrigin()); - *x += pt1.x; - *y += pt1.y; - - wxWindow::ClientToScreen(x, y); -} -wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) +#if wxUSE_TOOLBAR +wxToolBar* wxFrameMac::CreateToolBar(long style, wxWindowID id, const wxString& name) { - wxCHECK_MSG( m_frameToolBar == NULL, FALSE, - "recreating toolbar in wxFrame" ); - - wxToolBar* toolBar = OnCreateToolBar(style, id, name); - if (toolBar) + if ( wxFrameBase::CreateToolBar(style, id, name) ) { - SetToolBar(toolBar); PositionToolBar(); - return toolBar; - } - else - { - return NULL; } -} -wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) -{ - return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return m_frameToolBar; } -void wxFrame::PositionToolBar() +void wxFrameMac::PositionToolBar() { int cw, ch; - // TODO: we actually need to use the low-level client size, before - // the toolbar/status bar were added. - // So DEFINITELY replace the line below with something appropriate. - - GetClientSize(& cw, &ch); + cw = m_width ; + ch = m_height ; if ( GetStatusBar() ) { @@ -559,13 +371,13 @@ void wxFrame::PositionToolBar() // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS // means, pretend we don't have toolbar/status bar, so we // have the original client size. - GetToolBar()->SetSize(0, 0, tw, ch, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } else { // Use the 'real' position - GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } } } - +#endif