X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de6185e212ebc37ff11ff70278e3c4f68419b097..6cef0db28018fd2644ee4e38af715872e5242459:/src/mac/carbon/dialog.cpp?ds=inline diff --git a/src/mac/carbon/dialog.cpp b/src/mac/carbon/dialog.cpp index 69f568b9a5..bb90e3812b 100644 --- a/src/mac/carbon/dialog.cpp +++ b/src/mac/carbon/dialog.cpp @@ -16,11 +16,10 @@ #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/utils.h" + #include "wx/frame.h" + #include "wx/settings.h" #endif // WX_PRECOMP -#include "wx/frame.h" -#include "wx/settings.h" - #include "wx/mac/uma.h" @@ -28,23 +27,8 @@ // for modal dialogs wxList wxModalDialogs; -extern wxList wxPendingDelete; - IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) -BEGIN_EVENT_TABLE(wxDialog, wxDialogBase) - EVT_BUTTON(wxID_OK, wxDialog::OnOK) - EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) - EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) - - EVT_CHAR_HOOK(wxDialog::OnCharHook) - - EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) - - EVT_CLOSE(wxDialog::OnCloseWindow) -END_EVENT_TABLE() - - void wxDialog::Init() { m_isModalStyle = false; @@ -69,13 +53,6 @@ bool wxDialog::Create( wxWindow *parent, if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) return false; -#if TARGET_API_MAC_OSX - HIViewRef growBoxRef = 0 ; - OSStatus err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); - if ( err == noErr && growBoxRef != 0 ) - HIGrowBoxViewSetTransparent( growBoxRef, true ) ; -#endif - return true; } @@ -87,9 +64,7 @@ void wxDialog::SetModal( bool flag ) wxModelessWindows.DeleteObject( this ); -#if TARGET_CARBON SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ; -#endif } else { @@ -102,27 +77,19 @@ void wxDialog::SetModal( bool flag ) wxDialog::~wxDialog() { m_isBeingDeleted = true; + + // if the dialog is modal, this will end its event loop Show(false); } -// By default, pressing escape cancels the dialog; on mac command-stop does the same thing -void wxDialog::OnCharHook(wxKeyEvent& event) +// On mac command-stop does the same thing as Esc, let the base class know +// about it +bool wxDialog::IsEscapeKey(const wxKeyEvent& event) { - if (( event.m_keyCode == WXK_ESCAPE || - ( event.m_keyCode == '.' && event.MetaDown() ) ) - && FindWindow(wxID_CANCEL) ) - { - // Behaviour changed in 2.0: we'll send a Cancel message - // to the dialog instead of Close. - wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); - cancelEvent.SetEventObject( this ); - GetEventHandler()->ProcessEvent(cancelEvent); - - return; - } + if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) + return true; - // We didn't process this event. - event.Skip(); + return wxDialogBase::IsEscapeKey(event); } bool wxDialog::IsModal() const @@ -132,21 +99,21 @@ bool wxDialog::IsModal() const } -bool wxDialog::IsModalShowing() const -{ - return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast -} - bool wxDialog::Show(bool show) { if ( !wxDialogBase::Show(show) ) // nothing to do return false; + if (show && CanDoLayoutAdaptation()) + DoLayoutAdaptation(); + if ( show ) // usually will result in TransferDataToWindow() being called InitDialog(); + HiliteMenu(0); + if ( m_isModalStyle ) { if ( show ) @@ -164,38 +131,39 @@ bool wxDialog::Show(bool show) return true; } -#if !TARGET_CARBON -extern bool s_macIsInModalLoop ; -#endif - void wxDialog::DoShowModal() { - wxCHECK_RET( !IsModalShowing(), wxT("DoShowModal() called twice") ); + wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") ); wxModalDialogs.Append(this); SetFocus() ; -#if TARGET_CARBON - BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ; -#else - // TODO : test whether parent gets disabled - bool formerModal = s_macIsInModalLoop ; - s_macIsInModalLoop = true ; -#endif + WindowRef windowRef = (WindowRef) MacGetWindowRef(); + WindowGroupRef windowGroup; + WindowGroupRef formerParentGroup; + bool resetGroupParent = false; - while ( IsModalShowing() ) + if ( GetParent() == NULL ) + { + windowGroup = GetWindowGroup(windowRef) ; + formerParentGroup = GetWindowGroupParent( windowGroup ); + SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); + resetGroupParent = true; + } + BeginAppModalStateForWindow(windowRef) ; + + while ( IsModal() ) { wxTheApp->MacDoOneEvent() ; // calls process idle itself } -#if TARGET_CARBON - EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ; -#else - // TODO probably reenable the parent window if any - s_macIsInModalLoop = formerModal ; -#endif + EndAppModalStateForWindow(windowRef) ; + if ( resetGroupParent ) + { + SetWindowGroupParent( windowGroup , formerParentGroup ); + } } @@ -219,58 +187,3 @@ void wxDialog::EndModal(int retCode) SetModal(false); } -// Standard buttons -void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event)) -{ - if ( Validate() && TransferDataFromWindow() ) - EndModal(wxID_OK); -} - -void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) -{ - if (Validate()) - TransferDataFromWindow(); - - // TODO probably need to disable the Apply button until things change again -} - -void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) -{ - EndModal(wxID_CANCEL); -} - -void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) -{ - // We'll send a Cancel message by default, - // which may close the dialog. - // Check for looping if the Cancel event handler calls Close(). - - // Note that if a cancel button and handler aren't present in the dialog, - // nothing will happen when you close the dialog via the window manager, or - // via Close(). - // We wouldn't want to destroy the dialog by default, since the dialog may have been - // created on the stack. - // However, this does mean that calling dialog->Close() won't delete the dialog - // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be - // sure to destroy the dialog. - // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. - - static wxList closing; - - if ( closing.Member(this) ) - return; - - closing.Append(this); - - wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); - cancelEvent.SetEventObject( this ); - GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog - - closing.DeleteObject(this); -} - -void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) -{ - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); - Refresh(); -}