]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dialog.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/dialog.cpp 
   3 // Purpose:     wxDialog class 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  14 #include "wx/dialog.h" 
  20     #include "wx/settings.h" 
  23 #include "wx/mac/uma.h" 
  26 // Lists to keep track of windows, so we can disable/enable them 
  28 wxList wxModalDialogs
; 
  30 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
) 
  34     m_isModalStyle 
= false; 
  37 bool wxDialog::Create( wxWindow 
*parent
, 
  39     const wxString
& title
, 
  43     const wxString
& name 
) 
  45     SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG 
); 
  47     // All dialogs should really have this style... 
  48     style 
|= wxTAB_TRAVERSAL
; 
  50     // ...but not these styles 
  51     style 
&= ~(wxYES 
| wxOK 
| wxNO
); // | wxCANCEL 
  53     if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name 
) ) 
  56 #if TARGET_API_MAC_OSX 
  57     HIViewRef growBoxRef 
= 0 ; 
  58     OSStatus err 
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow 
), kHIViewWindowGrowBoxID
, &growBoxRef  
); 
  59     if ( err 
== noErr 
&& growBoxRef 
!= 0 ) 
  60         HIGrowBoxViewSetTransparent( growBoxRef
, true ) ; 
  66 void wxDialog::SetModal( bool flag 
) 
  70         m_isModalStyle 
= true; 
  72         wxModelessWindows
.DeleteObject( this ); 
  75         SetWindowModality( (WindowRef
)MacGetWindowRef(), kWindowModalityAppModal
, NULL 
) ; 
  80         m_isModalStyle 
= false; 
  82         wxModelessWindows
.Append( this ); 
  88     m_isBeingDeleted 
= true; 
  92 // On mac command-stop does the same thing as Esc, let the base class know 
  94 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
) 
  96     if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD 
) 
  99     return wxDialogBase::IsEscapeKey(event
); 
 102 bool wxDialog::IsModal() const 
 104     return wxModalDialogs
.Find((wxDialog 
*)this) != NULL
; // const_cast 
 105     //    return m_isModalStyle; 
 109 bool wxDialog::IsModalShowing() const 
 111     return wxModalDialogs
.Find((wxDialog 
*)this) != NULL
; // const_cast 
 114 bool wxDialog::Show(bool show
) 
 116     if ( !wxDialogBase::Show(show
) ) 
 121         // usually will result in TransferDataToWindow() being called 
 124     if ( m_isModalStyle 
) 
 130         else // end of modal dialog 
 132             // this will cause IsModalShowing() return false and our local 
 133             // message loop will terminate 
 134             wxModalDialogs
.DeleteObject(this); 
 142 extern bool s_macIsInModalLoop 
; 
 145 void wxDialog::DoShowModal() 
 147     wxCHECK_RET( !IsModalShowing(), wxT("DoShowModal() called twice") ); 
 149     wxModalDialogs
.Append(this); 
 154     BeginAppModalStateForWindow(  (WindowRef
) MacGetWindowRef()) ; 
 156     // TODO : test whether parent gets disabled 
 157     bool formerModal 
= s_macIsInModalLoop 
; 
 158     s_macIsInModalLoop 
= true ; 
 161     while ( IsModalShowing() ) 
 163         wxTheApp
->MacDoOneEvent() ; 
 164         // calls process idle itself 
 168     EndAppModalStateForWindow( (WindowRef
) MacGetWindowRef() ) ; 
 170     // TODO probably reenable the parent window if any 
 171     s_macIsInModalLoop 
= formerModal 
; 
 176 // Replacement for Show(true) for modal dialogs - returns return code 
 177 int wxDialog::ShowModal() 
 179     if ( !m_isModalStyle 
) 
 184     return GetReturnCode(); 
 187 // NB: this function (surprizingly) may be called for both modal and modeless 
 188 //     dialogs and should work for both of them 
 189 void wxDialog::EndModal(int retCode
) 
 191     SetReturnCode(retCode
);