]> git.saurik.com Git - wxWidgets.git/commitdiff
Start on ShowWindowModal for OS X Cocoa. Not working properly as children do not...
authorKevin Ollivier <kevino@theolliviers.com>
Sat, 23 Jan 2010 20:06:48 +0000 (20:06 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Sat, 23 Jan 2010 20:06:48 +0000 (20:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63232 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dialog.h
include/wx/osx/dialog.h
src/osx/carbon/dialog.cpp
src/osx/cocoa/dialog.mm
src/osx/dialog_osx.cpp

index 51852d49539ca34b05b8c47295fe723f239dddb1..4cc11bab8a4d884a7b0a466a61115c249f9b16b1 100644 (file)
@@ -74,7 +74,7 @@ public:
     virtual bool IsModal() const = 0;
     // show the dialog frame-modally (needs a parent), using app-modal
     // dialogs on platforms that don't support it
-    virtual bool ShowWindowModal () ;
+    virtual void ShowWindowModal () ;
     virtual void SendWindowModalDialogEvent ( wxEventType type );
 
     // Modal dialogs have a return code - usually the id of the last
index 351f6b8aee924f5d78b2bf96e317cae69ea3959e..2544d290bb156471b2301ecb857c5bf4dd6094ab 100644 (file)
@@ -55,6 +55,8 @@ public:
 
     // For now, same as Show(TRUE) but returns return code
     virtual int ShowModal();
+    
+    virtual void ShowWindowModal();
 
     // may be called to terminate the dialog with the given return code
     virtual void EndModal(int retCode);
@@ -69,6 +71,9 @@ protected:
     // mac also takes command-period as cancel
     virtual bool IsEscapeKey(const wxKeyEvent& event);
 
+    // needed for cleanup on the Cocoa side.
+    void EndWindowModal();
+
 private:
     void Init();
 
index 9924b54b06028dce197d051d1bf270542c30ac55..a17700638088d822b1ea985ad9dcb46c61cab217 100644 (file)
 
 extern wxList wxModalDialogs;
 
+void wxDialog::EndWindowModal()
+{
+    // Nothing to do for now.
+}
+
+void wxDialog::ShowWindowModal()
+{
+    // If someone wants to add support for this to wxOSX Carbon, here would 
+    // be the place to start: http://trac.wxwidgets.org/ticket/9459
+    // Unfortunately, supporting sheets in Carbon isn't as straightforward
+    // as with Cocoa, so it will probably take some tweaking.
+    wxDialogBase::ShowWindowModal();
+}
+
 void wxDialog::DoShowModal()
 {
     wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
index ab4ed1e5c32410fe9c1cc8a7a611eb851ef31e87..8976d677f5a15d68a66aee90aa4f25425f341eb5 100644 (file)
 
 extern wxList wxModalDialogs;
 
+void wxDialog::ShowWindowModal()
+{   
+    wxTopLevelWindow* parent = static_cast<wxTopLevelWindow*>(wxGetTopLevelParent(GetParent()));
+    
+    wxASSERT_MSG(parent, "ShowWindowModal requires the dialog to have a parent.");
+    
+    NSWindow* parentWindow = parent->GetWXWindow();
+    NSWindow* theWindow = GetWXWindow();
+    
+    wxASSERT_MSG([theWindow styleMask] & NSDocModalWindowMask, "Window must have DocModal mask set.");
+
+    [NSApp beginSheet: theWindow
+            modalForWindow: parentWindow
+            modalDelegate: theWindow
+            didEndSelector: nil
+            contextInfo: nil];
+}
+
+void wxDialog::EndWindowModal()
+{
+    [NSApp endSheet: GetWXWindow()];
+}
+
 void wxDialog::DoShowModal()
 {
     wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
index c51035b9690bbc4dfc5e87752c75faee18233d12..df4e2a4cc7ca15ad67954a9fbd52db1477aad661 100644 (file)
@@ -145,5 +145,10 @@ void wxDialog::EndModal(int retCode)
     SetReturnCode(retCode);
     Show(false);
     SetModal(false);
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+    {
+        EndWindowModal(); // OS X implementation method for cleanup
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
+    }
 }