X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..79f585d90388128f9d245f7c92d3013b98b9ed14:/src/mac/frame.cpp?ds=inline diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index 1e8c9e9ae5..cded59c604 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -23,10 +23,11 @@ #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) @@ -37,7 +38,6 @@ BEGIN_EVENT_TABLE(wxFrame, wxWindow) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) -#endif #if wxUSE_NATIVE_STATUSBAR bool wxFrame::m_useNativeStatusBar = TRUE; @@ -47,12 +47,15 @@ bool wxFrame::m_useNativeStatusBar = FALSE; wxFrame::wxFrame() { +#if wxUSE_TOOLBAR m_frameToolBar = NULL ; +#endif + + // in order to be able to give size events on show m_frameMenuBar = NULL; m_frameStatusBar = NULL; - - m_windowParent = NULL; m_iconized = FALSE; + m_isShown = FALSE; } bool wxFrame::Create(wxWindow *parent, @@ -69,7 +72,11 @@ bool wxFrame::Create(wxWindow *parent, SetName(name); m_windowStyle = style; m_frameMenuBar = NULL; + m_isShown = FALSE; + +#if wxUSE_TOOLBAR m_frameToolBar = NULL ; +#endif m_frameStatusBar = NULL; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); @@ -83,9 +90,62 @@ bool wxFrame::Create(wxWindow *parent, wxModelessWindows.Append(this); - // TODO: create frame. - - return FALSE; + // create frame. + + Rect theBoundsRect; + + m_x = (int)pos.x; + m_y = (int)pos.y; + if ( m_y < 50 ) + m_y = 50 ; + if ( m_x < 20 ) + m_x = 20 ; + + m_width = size.x; + if (m_width == -1) + m_width = 20; + m_height = size.y; + if (m_height == -1) + m_height = 20; + + m_macWindowData = new MacWindowData() ; + + ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); + + WindowClass wclass = kDocumentWindowClass ; + WindowAttributes attr = kWindowNoAttributes ; + + if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) + { + attr |= kWindowFullZoomAttribute ; + attr |= kWindowResizableAttribute ; + } + if ( m_windowStyle & wxSTAY_ON_TOP ) + { + wclass = kFloatingWindowClass ; + +// if ( m_windowStyle & wxCAPTION ) +// attr |= kHasPaletteTitlebarMask ; + } + else + { + } + if ( m_windowStyle & wxSYSTEM_MENU ) + { + attr |= kWindowCloseBoxAttribute ; + } + UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; + wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; + wxString label ; + if( wxApp::s_macDefaultEncodingIsPC ) + label = wxMacMakeMacStringFromPC( title ) ; + else + label = title ; + UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; + UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; + m_macWindowData->m_macFocus = NULL ; + return TRUE; } wxFrame::~wxFrame() @@ -105,46 +165,13 @@ 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) -{ - // TODO -} - -void wxFrame::GetSize(int *width, int *height) const -{ - // TODO -} - -void wxFrame::GetPosition(int *x, int *y) const -{ - // TODO -} - -void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags) -{ - // TODO -} - -bool wxFrame::Show(bool show) -{ - // TODO - return FALSE; -} void wxFrame::Iconize(bool iconize) { @@ -170,17 +197,6 @@ bool wxFrame::IsMaximized(void) const return FALSE; } -void wxFrame::SetTitle(const wxString& title) -{ - // TODO -} - -wxString wxFrame::GetTitle() const -{ - // TODO - return wxString(""); -} - void wxFrame::SetIcon(const wxIcon& icon) { m_icon = icon; @@ -192,10 +208,12 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, { wxStatusBar *statusBar = NULL; - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), + statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 17), style, name); // Set the height according to the font and the border size + // we shouldn't do this on the mac, because we have to fit the grow box + /* wxClientDC dc(statusBar); dc.SetFont(statusBar->GetFont()); @@ -206,6 +224,8 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, statusBar->SetSize(-1, -1, 100, height); + */ + statusBar->SetFieldsCount(number); return statusBar; } @@ -245,6 +265,8 @@ void wxFrame::SetStatusWidths(int n, const int widths_field[]) void wxFrame::PositionStatusBar() { + if (m_frameStatusBar ) + { int w, h; GetClientSize(&w, &h); int sw, sh; @@ -253,6 +275,7 @@ 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) @@ -264,8 +287,8 @@ void wxFrame::SetMenuBar(wxMenuBar *menuBar) } m_frameMenuBar = menuBar; - - // TODO + // TODO : we move this into the app code + m_frameMenuBar->MacInstallMenuBar() ; } void wxFrame::Fit() @@ -316,6 +339,56 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) // Default resizing behaviour - if only ONE subwindow, // resize to client rectangle size +void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) ) +{ + DoMenuUpdates(); +} + + +// update all menus +void wxFrame::DoMenuUpdates() +{ + wxMenuBar* bar = GetMenuBar(); + + if ( bar != NULL ) + { + int nCount = bar->GetMenuCount(); + for (int n = 0; n < nCount; n++) + DoMenuUpdates(bar->GetMenu(n), (wxWindow*) NULL); + } +} + +// update a menu and all submenus recursively +void wxFrame::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin)) +{ + wxEvtHandler* evtHandler = GetEventHandler(); + wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst(); + while (node) + { + wxMenuItem* item = node->GetData(); + if ( !item->IsSeparator() ) + { + wxWindowID id = item->GetId(); + wxUpdateUIEvent event(id); + event.SetEventObject( this ); + + if (evtHandler->ProcessEvent(event)) + { + if (event.GetSetText()) + menu->SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + menu->Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + menu->Enable(id, event.GetEnabled()); + } + + if (item->GetSubMenu()) + DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL); + } + node = node->GetNext(); + } +} + void wxFrame::OnSize(wxSizeEvent& event) { // if we're using constraints - do use them @@ -333,8 +406,12 @@ void wxFrame::OnSize(wxSizeEvent& event) wxWindow *win = (wxWindow *)node->Data(); if ( !win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) && - (win != GetToolBar()) ) + (win != GetStatusBar()) +#if wxUSE_TOOLBAR + && + (win != GetToolBar()) +#endif + ) { if ( child ) return; // it's our second subwindow - nothing to do @@ -371,21 +448,10 @@ void wxFrame::OnActivate(wxActivateEvent& event) } } -// The default implementation for the close window event - calls -// OnClose for backward compatibility. - +// The default implementation for the close window event. void wxFrame::OnCloseWindow(wxCloseEvent& event) { - // Compatibility - if ( GetEventHandler()->OnClose() || event.GetForce()) - { - this->Destroy(); - } -} - -bool wxFrame::OnClose() -{ - return TRUE; + this->Destroy(); } // Destroy the window (delayed, if a managed window) @@ -421,21 +487,6 @@ 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); - - 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); -} // Call this to simulate a menu command void wxFrame::Command(int id) @@ -445,7 +496,7 @@ void wxFrame::Command(int id) void wxFrame::ProcessCommand(int id) { - wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id); + wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); commandEvent.SetInt( id ); commandEvent.SetEventObject( this ); @@ -468,6 +519,7 @@ void wxFrame::ProcessCommand(int id) wxPoint wxFrame::GetClientAreaOrigin() const { wxPoint pt(0, 0); +#if wxUSE_TOOLBAR if (GetToolBar()) { int w, h; @@ -482,33 +534,46 @@ wxPoint wxFrame::GetClientAreaOrigin() const pt.y += h; } } +#endif return pt; } -void wxFrame::ScreenToClient(int *x, int *y) const +void wxFrame::DoGetClientSize(int *x, int *y) const { - wxWindow::ScreenToClient(x, y); + wxWindow::DoGetClientSize( x , y ) ; + + if ( GetStatusBar() ) + { + int statusX, statusY; + GetStatusBar()->GetClientSize(&statusX, &statusY); + *y -= statusY; + } - // 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; + wxPoint pt(GetClientAreaOrigin()); + *y -= pt.y; + *x -= pt.x; } -void wxFrame::ClientToScreen(int *x, int *y) const +void wxFrame::DoSetClientSize(int clientwidth, int clientheight) { - // 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; + int currentclientwidth , currentclientheight ; + int currentwidth , currentheight ; + + GetClientSize( ¤tclientwidth , ¤tclientheight ) ; + GetSize( ¤twidth , ¤theight ) ; + + // find the current client size - wxWindow::ClientToScreen(x, y); + // 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 + + DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , + currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; } + +#if wxUSE_TOOLBAR wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { wxCHECK_MSG( m_frameToolBar == NULL, FALSE, @@ -540,7 +605,10 @@ void wxFrame::PositionToolBar() // the toolbar/status bar were added. // So DEFINITELY replace the line below with something appropriate. - GetClientSize(& cw, &ch); + // GetClientSize(& cw, &ch); + + cw = m_width ; + ch = m_height ; if ( GetStatusBar() ) { @@ -568,4 +636,4 @@ void wxFrame::PositionToolBar() } } } - +#endif