| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/osx/dialog_osx.cpp |
| 3 | // Purpose: wxDialog class |
| 4 | // Author: Stefan Csomor |
| 5 | // Modified by: |
| 6 | // Created: 1998-01-01 |
| 7 | // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $ |
| 8 | // Copyright: (c) Stefan Csomor |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #include "wx/wxprec.h" |
| 13 | |
| 14 | #include "wx/dialog.h" |
| 15 | |
| 16 | #ifndef WX_PRECOMP |
| 17 | #include "wx/app.h" |
| 18 | #include "wx/utils.h" |
| 19 | #include "wx/frame.h" |
| 20 | #include "wx/settings.h" |
| 21 | #endif // WX_PRECOMP |
| 22 | |
| 23 | #include "wx/osx/private.h" |
| 24 | |
| 25 | |
| 26 | // Lists to keep track of windows, so we can disable/enable them |
| 27 | // for modal dialogs |
| 28 | |
| 29 | wxList wxModalDialogs; |
| 30 | |
| 31 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) |
| 32 | |
| 33 | void wxDialog::Init() |
| 34 | { |
| 35 | m_isModalStyle = false; |
| 36 | } |
| 37 | |
| 38 | bool wxDialog::Create( wxWindow *parent, |
| 39 | wxWindowID id, |
| 40 | const wxString& title, |
| 41 | const wxPoint& pos, |
| 42 | const wxSize& size, |
| 43 | long style, |
| 44 | const wxString& name ) |
| 45 | { |
| 46 | SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); |
| 47 | |
| 48 | // All dialogs should really have this style... |
| 49 | style |= wxTAB_TRAVERSAL; |
| 50 | |
| 51 | // ...but not these styles |
| 52 | style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL |
| 53 | |
| 54 | if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) |
| 55 | return false; |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | void wxDialog::SetModal( bool flag ) |
| 61 | { |
| 62 | if ( flag ) |
| 63 | { |
| 64 | m_isModalStyle = true; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | m_isModalStyle = false; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | wxDialog::~wxDialog() |
| 73 | { |
| 74 | m_isBeingDeleted = true; |
| 75 | |
| 76 | // if the dialog is modal, this will end its event loop |
| 77 | Show(false); |
| 78 | } |
| 79 | |
| 80 | // On mac command-stop does the same thing as Esc, let the base class know |
| 81 | // about it |
| 82 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) |
| 83 | { |
| 84 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) |
| 85 | return true; |
| 86 | |
| 87 | return wxDialogBase::IsEscapeKey(event); |
| 88 | } |
| 89 | |
| 90 | bool wxDialog::IsModal() const |
| 91 | { |
| 92 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
| 93 | // return m_isModalStyle; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | bool wxDialog::Show(bool show) |
| 98 | { |
| 99 | if ( !wxDialogBase::Show(show) ) |
| 100 | // nothing to do |
| 101 | return false; |
| 102 | |
| 103 | if (show && CanDoLayoutAdaptation()) |
| 104 | DoLayoutAdaptation(); |
| 105 | |
| 106 | if ( show ) |
| 107 | // usually will result in TransferDataToWindow() being called |
| 108 | InitDialog(); |
| 109 | |
| 110 | if ( m_isModalStyle ) |
| 111 | { |
| 112 | if ( show ) |
| 113 | { |
| 114 | DoShowModal(); |
| 115 | } |
| 116 | else // end of modal dialog |
| 117 | { |
| 118 | // this will cause IsModalShowing() return false and our local |
| 119 | // message loop will terminate |
| 120 | wxModalDialogs.DeleteObject(this); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | // Replacement for Show(true) for modal dialogs - returns return code |
| 128 | int wxDialog::ShowModal() |
| 129 | { |
| 130 | if ( !m_isModalStyle ) |
| 131 | SetModal(true); |
| 132 | |
| 133 | if ( IsShown() ) |
| 134 | DoShowModal(); |
| 135 | else |
| 136 | Show(true); |
| 137 | |
| 138 | return GetReturnCode(); |
| 139 | } |
| 140 | |
| 141 | // NB: this function (surprizingly) may be called for both modal and modeless |
| 142 | // dialogs and should work for both of them |
| 143 | void wxDialog::EndModal(int retCode) |
| 144 | { |
| 145 | SetReturnCode(retCode); |
| 146 | Show(false); |
| 147 | SetModal(false); |
| 148 | } |
| 149 | |