]> git.saurik.com Git - wxWidgets.git/commitdiff
No changes, just avoid code duplication in wxOSX wxDirDialog.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 29 Oct 2012 01:20:26 +0000 (01:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 29 Oct 2012 01:20:26 +0000 (01:20 +0000)
Factor our common parts of wxDirDialog::ShowModal() and ShowWindowModal() in
OSXCreatePanel() helper.

Also some minor cosmetic changes.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72814 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/dirdlg.h
src/osx/cocoa/dirdlg.mm

index 882b9beaab849079e1be9809fd94eb58af905c7f..a33a20b6be7adb37a48e51af17f6dc55db63d21a 100644 (file)
 #ifndef _WX_DIRDLG_H_
 #define _WX_DIRDLG_H_
 
 #ifndef _WX_DIRDLG_H_
 #define _WX_DIRDLG_H_
 
+#if wxOSX_USE_COCOA
+    DECLARE_WXCOCOA_OBJC_CLASS(NSOpenPanel);
+#endif
+
 class WXDLLIMPEXP_CORE wxDirDialog : public wxDirDialogBase
 {
 public:
 class WXDLLIMPEXP_CORE wxDirDialog : public wxDirDialogBase
 {
 public:
@@ -34,14 +38,16 @@ public:
     virtual void ModalFinishedCallback(void* panel, int returnCode);
 #endif
 
     virtual void ModalFinishedCallback(void* panel, int returnCode);
 #endif
 
-protected:
-
-    DECLARE_DYNAMIC_CLASS(wxDirDialog)
-
+private:
 #if wxOSX_USE_COCOA
 #if wxOSX_USE_COCOA
+    // Create and initialize NSOpenPanel that we use in both ShowModal() and
+    // ShowWindowModal().
+    WX_NSOpenPanel OSXCreatePanel() const;
+
     WX_NSObject m_sheetDelegate;
 #endif
     WX_NSObject m_sheetDelegate;
 #endif
+
+    DECLARE_DYNAMIC_CLASS(wxDirDialog)
 };
 
 };
 
-#endif
-    // _WX_DIRDLG_H_
+#endif // _WX_DIRDLG_H_
index 7d7dc66a2193e93de42814c758c0419d49d2823a..78b32419d3475de33b3dfa48d78bb54c30e9f1f0 100644 (file)
@@ -55,12 +55,8 @@ wxDirDialog::~wxDirDialog()
     [m_sheetDelegate release];
 }
 
     [m_sheetDelegate release];
 }
 
-void wxDirDialog::ShowWindowModal()
+WX_NSOpenPanel wxDirDialog::OSXCreatePanel() const
 {
 {
-    wxCFStringRef dir( m_path );
-    
-    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
-    
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
@@ -71,38 +67,36 @@ void wxDirDialog::ShowWindowModal()
 
     if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
         [oPanel setCanCreateDirectories:YES];
 
     if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
         [oPanel setCanCreateDirectories:YES];
-    
+
+    return oPanel;
+}
+
+void wxDirDialog::ShowWindowModal()
+{
     wxNonOwnedWindow* parentWindow = NULL;
     wxNonOwnedWindow* parentWindow = NULL;
-    
+
     if (GetParent())
         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
     if (GetParent())
         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
-    
-    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
-    
-    if (parentWindow)
-    {
-        NSWindow* nativeParent = parentWindow->GetWXWindow();
-        [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
-            modalForWindow: nativeParent modalDelegate: m_sheetDelegate
-            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
-            contextInfo: nil];
-    }
+
+    wxCHECK_RET(parentWindow, "Window modal display requires parent.");
+
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+
+    NSOpenPanel *oPanel = OSXCreatePanel();
+
+    NSWindow* nativeParent = parentWindow->GetWXWindow();
+    wxCFStringRef dir( m_path );
+    [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
+        modalForWindow: nativeParent modalDelegate: m_sheetDelegate
+        didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+        contextInfo: nil];
 }
 
 int wxDirDialog::ShowModal()
 {
     wxCFEventLoopPauseIdleEvents pause;
 
 }
 
 int wxDirDialog::ShowModal()
 {
     wxCFEventLoopPauseIdleEvents pause;
 
-    NSOpenPanel *oPanel = [NSOpenPanel openPanel];
-    [oPanel setCanChooseDirectories:YES];
-    [oPanel setResolvesAliases:YES];
-    [oPanel setCanChooseFiles:NO];
-
-    wxCFStringRef cf( m_message );
-    [oPanel setMessage:cf.AsNSString()];
-
-    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
-        [oPanel setCanCreateDirectories:YES];
+    NSOpenPanel *oPanel = OSXCreatePanel();
 
     wxCFStringRef dir( m_path );
 
 
     wxCFStringRef dir( m_path );
 
@@ -127,7 +121,7 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
         result = wxID_OK;
     }
     SetReturnCode(result);
         result = wxID_OK;
     }
     SetReturnCode(result);
-    
+
     if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
         SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
     if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
         SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }