// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
-// RCS-ID: $Id: msgdlg.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/app.h"
#endif
+#include "wx/control.h"
#include "wx/thread.h"
+#include "wx/evtloop.h"
+#include "wx/modalhook.h"
#include "wx/osx/private.h"
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
+namespace
+{
+ NSAlertStyle GetAlertStyleFromWXStyle( long style )
+ {
+ NSAlertStyle alertType = NSWarningAlertStyle;
+ if (style & wxICON_EXCLAMATION)
+ alertType = NSCriticalAlertStyle;
+ else if (style & wxICON_HAND)
+ alertType = NSWarningAlertStyle;
+ else if (style & wxICON_INFORMATION)
+ alertType = NSInformationalAlertStyle;
+ else if (style & wxICON_QUESTION)
+ alertType = NSInformationalAlertStyle;
+ return alertType;
+ }
+}
+
wxMessageDialog::wxMessageDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
- : wxMessageDialogWithCustomLabels(parent, message, caption, style)
+ : wxMessageDialogBase(parent, message, caption, style)
{
+ m_sheetDelegate = [[ModalDialogDelegate alloc] init];
+ [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this];
+}
+
+wxMessageDialog::~wxMessageDialog()
+{
+ [m_sheetDelegate release];
}
int wxMessageDialog::ShowModal()
{
+ WX_HOOK_MODAL_DIALOG();
+
+ wxCFEventLoopPauseIdleEvents pause;
+
int resultbutton = wxID_CANCEL;
const long style = GetMessageDialogStyle();
wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
- NSAlertStyle alertType = NSWarningAlertStyle;
- if (style & wxICON_EXCLAMATION)
- alertType = NSCriticalAlertStyle;
- else if (style & wxICON_HAND)
- alertType = NSWarningAlertStyle;
- else if (style & wxICON_INFORMATION)
- alertType = NSInformationalAlertStyle;
- else if (style & wxICON_QUESTION)
- alertType = NSInformationalAlertStyle;
-
-
// work out what to display
// if the extended text is empty then we use the caption as the title
// and the message as the text (for backwards compatibility)
wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
- wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
- wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
- wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding()) ;
- wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
+ wxCFStringRef cfNoString( wxControl::GetLabelText(GetNoLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfYesString( wxControl::GetLabelText(GetYesLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfOKString( wxControl::GetLabelText(GetOKLabel()), GetFont().GetEncoding()) ;
+ wxCFStringRef cfCancelString( wxControl::GetLabelText(GetCancelLabel()), GetFont().GetEncoding() );
+ NSAlertStyle alertType = GetAlertStyleFromWXStyle(style);
+
int m_buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
if (style & wxYES_NO)
}
}
+ wxASSERT_MSG( !(style & wxHELP), "wxHELP not supported in non-GUI thread" );
+
CFOptionFlags exitButton;
OSStatus err = CFUserNotificationDisplayAlert(
0, alertType, NULL, NULL, NULL, cfTitle, cfText,
if (parentWindow)
{
NSWindow* nativeParent = parentWindow->GetWXWindow();
- ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
- [sheetDelegate setImplementation: this];
- [alert beginSheetModalForWindow: nativeParent modalDelegate: sheetDelegate
+ [alert beginSheetModalForWindow: nativeParent modalDelegate: m_sheetDelegate
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
}
-void wxMessageDialog::ModalFinishedCallback(void* panel, int resultCode)
+void wxMessageDialog::ModalFinishedCallback(void* WXUNUSED(panel), int resultCode)
{
int resultbutton = wxID_CANCEL;
if ( resultCode < NSAlertFirstButtonReturn )
}
NSAlert* alert = [[NSAlert alloc] init];
+ NSAlertStyle alertType = GetAlertStyleFromWXStyle(style);
- wxCFStringRef cfNoString( GetNoLabel(), GetFont().GetEncoding() );
- wxCFStringRef cfYesString( GetYesLabel(), GetFont().GetEncoding() );
- wxCFStringRef cfOKString( GetOKLabel(), GetFont().GetEncoding() );
- wxCFStringRef cfCancelString( GetCancelLabel(), GetFont().GetEncoding() );
+ wxCFStringRef cfNoString( wxControl::GetLabelText(GetNoLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfYesString( wxControl::GetLabelText(GetYesLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfOKString( wxControl::GetLabelText(GetOKLabel()), GetFont().GetEncoding() );
+ wxCFStringRef cfCancelString( wxControl::GetLabelText(GetCancelLabel()), GetFont().GetEncoding() );
wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
[alert setMessageText:cfTitle.AsNSString()];
[alert setInformativeText:cfText.AsNSString()];
+ [alert setAlertStyle:alertType];
m_buttonCount = 0;
// the MSW implementation even shows an OK button if it is not specified, we'll do the same
else
{
- [alert addButtonWithTitle:cfOKString.AsNSString()];
- m_buttonId[ m_buttonCount++ ] = wxID_OK;
- if (style & wxCANCEL)
+ if ( style & wxCANCEL_DEFAULT )
{
[alert addButtonWithTitle:cfCancelString.AsNSString()];
m_buttonId[ m_buttonCount++ ] = wxID_CANCEL;
+
+ [alert addButtonWithTitle:cfOKString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_OK;
+ }
+ else
+ {
+ [alert addButtonWithTitle:cfOKString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_OK;
+ if (style & wxCANCEL)
+ {
+ [alert addButtonWithTitle:cfCancelString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_CANCEL;
+ }
}
+
+ }
+
+ if ( style & wxHELP )
+ {
+ wxCFStringRef cfHelpString( GetHelpLabel(), GetFont().GetEncoding() );
+ [alert addButtonWithTitle:cfHelpString.AsNSString()];
+ m_buttonId[ m_buttonCount++ ] = wxID_HELP;
}
+
+ wxASSERT_MSG( m_buttonCount <= WXSIZEOF(m_buttonId), "Too many buttons" );
+
return alert;
}