Get ShowWindowModal behavior working under OS X Cocoa for file, dir and message dialogs.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2010-01-28 04:06:23 +00:00
parent 896576e31e
commit bfa92264c0
10 changed files with 312 additions and 182 deletions

View File

@@ -140,10 +140,63 @@ NSArray* GetTypesFromFilter( const wxString filter )
return types;
}
void wxFileDialog::ShowWindowModal()
{
wxCFStringRef cf( m_message );
wxCFStringRef dir( m_dir );
wxCFStringRef file( m_fileName );
wxNonOwnedWindow* parentWindow = NULL;
m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
if (GetParent())
parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
if (HasFlag(wxFD_SAVE))
{
NSSavePanel* sPanel = [NSSavePanel savePanel];
// makes things more convenient:
[sPanel setCanCreateDirectories:YES];
[sPanel setMessage:cf.AsNSString()];
// if we should be able to descend into pacakges we must somehow
// be able to pass this in
[sPanel setTreatsFilePackagesAsDirectories:NO];
[sPanel setCanSelectHiddenExtension:YES];
NSWindow* nativeParent = parentWindow->GetWXWindow();
ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
[sheetDelegate setImplementation: this];
[sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
modalForWindow: nativeParent modalDelegate: sheetDelegate
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
else
{
NSArray* types = GetTypesFromFilter( m_wildCard ) ;
NSOpenPanel* oPanel = [NSOpenPanel openPanel];
[oPanel setTreatsFilePackagesAsDirectories:NO];
[oPanel setCanChooseDirectories:NO];
[oPanel setResolvesAliases:YES];
[oPanel setCanChooseFiles:YES];
[oPanel setMessage:cf.AsNSString()];
NSWindow* nativeParent = parentWindow->GetWXWindow();
ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
[sheetDelegate setImplementation: this];
[oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
types: types modalForWindow: nativeParent
modalDelegate: sheetDelegate
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
}
int wxFileDialog::ShowModal()
{
int result = wxID_CANCEL;
NSSavePanel *panel = nil;
wxCFStringRef cf( m_message );
@@ -180,34 +233,8 @@ int wxFileDialog::ShowModal()
{
}
/*
if (parentWindow)
{
NSWindow* nativeParent = parentWindow->GetWXWindow();
ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
[sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
modalForWindow: nativeParent modalDelegate: sheetDelegate
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
[sheetDelegate waitForSheetToFinish];
returnCode = [sheetDelegate code];
[sheetDelegate release];
}
else
*/
{
returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ];
}
if (returnCode == NSOKButton )
{
panel = sPanel;
result = wxID_OK;
m_path = wxCFStringRef::AsString([sPanel filename]);
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly( m_path );
}
returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ];
ModalFinishedCallback(sPanel, returnCode);
}
else
{
@@ -219,26 +246,36 @@ int wxFileDialog::ShowModal()
[oPanel setCanChooseFiles:YES];
[oPanel setMessage:cf.AsNSString()];
/*
if (parentWindow)
{
NSWindow* nativeParent = parentWindow->GetWXWindow();
ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
[oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString()
types: types modalForWindow: nativeParent
modalDelegate: sheetDelegate
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
[sheetDelegate waitForSheetToFinish];
returnCode = [sheetDelegate code];
[sheetDelegate release];
}
else
*/
{
returnCode = [oPanel runModalForDirectory:dir.AsNSString()
returnCode = [oPanel runModalForDirectory:dir.AsNSString()
file:file.AsNSString() types:types];
ModalFinishedCallback(oPanel, returnCode);
if ( types != nil )
[types release];
}
return GetReturnCode();
}
void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
{
int result = wxID_CANCEL;
if (HasFlag(wxFD_SAVE))
{
if (returnCode == NSOKButton )
{
NSSavePanel* sPanel = (NSSavePanel*)panel;
result = wxID_OK;
m_path = wxCFStringRef::AsString([sPanel filename]);
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly( m_path );
}
}
else
{
NSOpenPanel* oPanel = (NSOpenPanel*)panel;
if (returnCode == NSOKButton )
{
panel = oPanel;
@@ -257,11 +294,11 @@ int wxFileDialog::ShowModal()
}
}
}
if ( types != nil )
[types release];
}
return result;
SetReturnCode(result);
if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
}
#endif // wxUSE_FILEDLG