1. Derive wxMessageDialogBase from wxDialog (why did we use multiple

inheritance here?), moved more wxMessageDialog fields into the base class
2. Added functions to set the text of message box buttons (patch 1700393,
   currently only implemented for wxMac)
3. Added wxMessageDialog::SetMessage() and SetExtendedMessage() and
   implemented them for wxMac (part of the patch), wxGTK 2.4+ and in
   a generic way for everybody else
4. Allow changing the dialog attributes between creating and showing it,
   for this the real dialog creation is now done on in ShowModal() in all
   ports


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-05-24 12:50:42 +00:00
parent f3d32879d6
commit 2afb9e1690
18 changed files with 429 additions and 262 deletions

View File

@@ -100,6 +100,7 @@ All (GUI):
- Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron) - Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron)
- Added support for drop down toolbar buttons (Tim Kosse) - Added support for drop down toolbar buttons (Tim Kosse)
- Added support for labels for toolbar controls (Vince Harron) - Added support for labels for toolbar controls (Vince Harron)
- Added wxMessageDialog::SetMessage() and SetExtendedMessage()
- Added wxEventBlocker class (Francesco Montorsi). - Added wxEventBlocker class (Francesco Montorsi).
- Added wxFile/DirPickerCtrl::Get/SetFile/DirName() (Francesco Montorsi). - Added wxFile/DirPickerCtrl::Get/SetFile/DirName() (Francesco Montorsi).
- Added wxSizerFlags::Top() and Bottom(). - Added wxSizerFlags::Top() and Bottom().
@@ -135,6 +136,7 @@ wxGTK:
wxMac: wxMac:
- Better IconRef support (Alan Shouls) - Better IconRef support (Alan Shouls)
- Added support for changing button labels in wxMessageDialog (Gareth Simpson)
- Fix duplicate (empty) help menu in non-English programs (Andreas Jacobs) - Fix duplicate (empty) help menu in non-English programs (Andreas Jacobs)
- Allow accelerators to be used with buttons too (Ryan Wilcox) - Allow accelerators to be used with buttons too (Ryan Wilcox)
- Support resource forks in wxCopyFile() (Hank Schultz) - Support resource forks in wxCopyFile() (Hank Schultz)

View File

@@ -20,6 +20,7 @@ with a choice of OK, Yes, No and Cancel buttons.
\latexignore{\rtfignore{\wxheading{Members}}} \latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxMessageDialog::wxMessageDialog}\label{wxmessagedialogctor} \membersection{wxMessageDialog::wxMessageDialog}\label{wxmessagedialogctor}
\func{}{wxMessageDialog}{\param{wxWindow* }{parent}, \param{const wxString\& }{message},\rtfsp \func{}{wxMessageDialog}{\param{wxWindow* }{parent}, \param{const wxString\& }{message},\rtfsp
@@ -56,15 +57,86 @@ Constructor. Use \helpref{wxMessageDialog::ShowModal}{wxmessagedialogshowmodal}
\docparam{pos}{Dialog position. Not Windows.} \docparam{pos}{Dialog position. Not Windows.}
\membersection{wxMessageDialog::\destruct{wxMessageDialog}}\label{wxmessagedialogdtor} \membersection{wxMessageDialog::\destruct{wxMessageDialog}}\label{wxmessagedialogdtor}
\func{}{\destruct{wxMessageDialog}}{\void} \func{}{\destruct{wxMessageDialog}}{\void}
Destructor. Destructor.
\membersection{wxMessageDialog::ShowModal}\label{wxmessagedialogshowmodal} \membersection{wxMessageDialog::ShowModal}\label{wxmessagedialogshowmodal}
\func{int}{ShowModal}{\void} \func{int}{ShowModal}{\void}
Shows the dialog, returning one of wxID\_OK, wxID\_CANCEL, wxID\_YES, wxID\_NO. Shows the dialog, returning one of wxID\_OK, wxID\_CANCEL, wxID\_YES, wxID\_NO.
\membersection{wxMessageDialog::SetYesNoLabels}\label{wxmessagedialogsetyesnolabels}
\func{bool}{SetYesNoLabels}{\param{const wxString&}{yes},\param{const wxString&}{no}}
Overrides the default labels of the Yes and No buttons.
Notice that this function is not currently available on all platforms, so it
may return \false to indicate that the labels couldn't be changed. If it
returns \true (currently only under wxMac), the labels were set successfully.
Typically, if the function was used successfully, the main dialog message may
need to be changed, e.g.:
\begin{verbatim}
wxMessageDialog dlg(...);
if ( dlg.SetYesNoLabels(_("&Quit"), _("&Don't quit")) )
dlg.SetMessage(_("What do you want to do?"));
else // buttons have standard "Yes"/"No" values, so rephrase the question
dlg.SetMessage(_("Do you really want to quit?"));
\end{verbatim}
\membersection{wxMessageDialog::SetYesNoCancelLabels}\label{wxmessagedialogsetyesnocancellabels}
\func{bool}{SetYesNoCancelLabels}{\param{const wxString&}{yes},\param{const wxString&}{no},\param{const wxString&}{cancel}}
Overrides the default labels of the Yes, No and Cancel buttons.
Please see the remarks in
\helpref{SetYesNoLabels}{wxmessagedialogsetyesnolabels} documentation.
\membersection{wxMessageDialog::SetOKLabel}\label{wxmessagedialogsetyesoklabel}
\func{bool}{SetOKLabel}{\param{const wxString&}{ok}}
Overrides the default label of the OK button.
Please see the remarks in
\helpref{SetYesNoLabels}{wxmessagedialogsetyesnolabels} documentation.
\membersection{wxMessageDialog::SetOKCancelLabels}\label{wxmessagedialogsetokcancellabels}
\func{bool}{SetOKCancelLabels}{\param{const wxString&}{ok},\param{const wxString&}{cancel}}
Overrides the default labels of the OK and Cancel buttons.
Please see the remarks in
\helpref{SetYesNoLabels}{wxmessagedialogsetyesnolabels} documentation.
\membersection{wxMessageDialog::SetMessage}\label{wxmessagedialogsetmessage}
\func{void}{SetMessage}{\param{const wxString&}{msg}}
Sets the message shown by the dialog.
\membersection{wxMessageDialog::SetExtendedMessage}\label{wxmessagedialogsetextendedmessage}
\func{void}{SetExtendedMessage}{\param{const wxString&}{exMsg}
Sets the extended message for the dialog: this message is usually an extension
of the short message specified in the constructor or set with
\helpref{SetMessage}{wxmessagedialogsetmessage}. If it is set, the main message
appears highlighted -- if supported -- and this message appears beneath it in
normal font. On the platforms which don't support extended messages, it is
simply appended to the normal message with a new line separating them.

View File

@@ -9,36 +9,33 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __MSGDLGH_G__ #ifndef _WX_GENERIC_MSGDLGG_H_
#define __MSGDLGH_G__ #define _WX_GENERIC_MSGDLGG_H_
#include "wx/defs.h" class WXDLLEXPORT wxGenericMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
// type is an 'or' (|) of wxOK, wxCANCEL, wxYES_NO
// Returns wxYES/NO/OK/CANCEL
extern WXDLLEXPORT_DATA(const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxGenericMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxGenericMessageDialog)
public: public:
wxGenericMessageDialog(wxWindow *parent, const wxString& message, wxGenericMessageDialog(wxWindow *parent,
const wxString& caption = wxMessageBoxCaptionStr, const wxString& message,
long style = wxOK|wxCENTRE, const wxPoint& pos = wxDefaultPosition); const wxString& caption = wxMessageBoxCaptionStr,
long style = wxOK|wxCENTRE,
const wxPoint& pos = wxDefaultPosition);
virtual int ShowModal();
protected:
void OnYes(wxCommandEvent& event); void OnYes(wxCommandEvent& event);
void OnNo(wxCommandEvent& event); void OnNo(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event); void OnCancel(wxCommandEvent& event);
private: private:
void DoCreateMsgdialog();
wxPoint m_pos;
bool m_created;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxGenericMessageDialog)
}; };
#if (!defined( __WXMSW__ ) && !defined( __WXMAC__) && !defined(__WXPM__)) || defined(__WXUNIVERSAL__) #endif // _WX_GENERIC_MSGDLGG_H_
#define wxMessageDialog wxGenericMessageDialog
#endif
#endif // __MSGDLGH_G__

View File

@@ -9,27 +9,18 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __MSGDLG_H__ #ifndef _WX_GTK_MSGDLG_H_
#define __MSGDLG_H__ #define _WX_GTK_MSGDLG_H_
#include "wx/defs.h" class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
// type is an 'or' (|) of wxOK, wxCANCEL, wxYES_NO
// Returns wxYES/NO/OK/CANCEL
WXDLLEXPORT_DATA(extern const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
public: public:
wxMessageDialog(wxWindow *parent, const wxString& message, wxMessageDialog(wxWindow *parent, const wxString& message,
const wxString& caption = wxMessageBoxCaptionStr, const wxString& caption = wxMessageBoxCaptionStr,
long style = wxOK|wxCENTRE, long style = wxOK|wxCENTRE,
const wxPoint& pos = wxDefaultPosition); const wxPoint& pos = wxDefaultPosition);
virtual ~wxMessageDialog();
int ShowModal(); virtual int ShowModal();
virtual bool Show( bool WXUNUSED(show) = true ) { return false; }; virtual bool Show( bool WXUNUSED(show) = true ) { return false; };
protected: protected:
@@ -42,10 +33,11 @@ protected:
int WXUNUSED(width), int WXUNUSED(height)) {} int WXUNUSED(width), int WXUNUSED(height)) {}
private: private:
wxString m_caption; // create the real GTK+ dialog: this is done from ShowModal() to allow
wxString m_message; // changing the message between constructing the dialog and showing it
void GTKCreateMsgDialog();
DECLARE_DYNAMIC_CLASS(wxMessageDialog) DECLARE_DYNAMIC_CLASS(wxMessageDialog)
}; };
#endif #endif // _WX_GTK_MSGDLG_H_

View File

@@ -13,23 +13,8 @@
#ifndef _WX_MSGBOXDLG_H_ #ifndef _WX_MSGBOXDLG_H_
#define _WX_MSGBOXDLG_H_ #define _WX_MSGBOXDLG_H_
#include "wx/defs.h" class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
/*
* Message box dialog
*/
WXDLLEXPORT_DATA(extern const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
protected:
wxString m_caption;
wxString m_message;
wxWindow * m_parent;
public: public:
wxMessageDialog(wxWindow *parent, wxMessageDialog(wxWindow *parent,
const wxString& message, const wxString& message,
@@ -37,15 +22,27 @@ public:
long style = wxOK|wxCENTRE, long style = wxOK|wxCENTRE,
const wxPoint& pos = wxDefaultPosition); const wxPoint& pos = wxDefaultPosition);
int ShowModal(); virtual int ShowModal();
// customization of the message box
virtual bool SetYesNoLabels(const wxString& yes,const wxString& no);
virtual bool SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel);
virtual bool SetOKLabel(const wxString& ok);
virtual bool SetOKCancelLabels(const wxString& ok, const wxString& cancel);
protected: protected:
// not supported for message dialog, RR // not supported for message dialog
virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y), virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
int WXUNUSED(width), int WXUNUSED(height), int WXUNUSED(width), int WXUNUSED(height),
int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {} int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
// labels for the buttons
wxString m_yes,
m_no,
m_ok,
m_cancel;
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
}; };
#endif #endif // _WX_MSGBOXDLG_H_
// _WX_MSGBOXDLG_H_

View File

@@ -13,38 +13,32 @@
#ifndef _WX_MSGBOXDLG_H_ #ifndef _WX_MSGBOXDLG_H_
#define _WX_MSGBOXDLG_H_ #define _WX_MSGBOXDLG_H_
#include "wx/defs.h"
#include "wx/dialog.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Message box dialog // Message box dialog
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
WXDLLEXPORT_DATA(extern const wxChar) wxMessageBoxCaptionStr[]; class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
class WXDLLEXPORT wxMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
public: public:
wxMessageDialog(wxWindow *parent, wxMessageDialog(wxWindow *parent,
const wxString& message, const wxString& message,
const wxString& caption = wxMessageBoxCaptionStr, const wxString& caption = wxMessageBoxCaptionStr,
long style = wxOK | wxCENTRE, long style = wxOK | wxCENTRE,
const wxPoint& pos = wxDefaultPosition); const wxPoint& WXUNUSED(pos) = wxDefaultPosition)
: wxMessageDialogBase(parent, message, caption, style)
{
}
int ShowModal(); virtual int ShowModal();
// implementation only from now on // implementation only from now on
// called by the Motif callback // called by the Motif callback
void SetResult(long result) { m_result = result; } void SetResult(long result) { m_result = result; }
protected: protected:
wxString m_caption;
wxString m_message;
wxWindow * m_parent;
long m_result; long m_result;
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
}; };
#endif #endif // _WX_MSGBOXDLG_H_
// _WX_MSGBOXDLG_H_

View File

@@ -16,8 +16,66 @@
#if wxUSE_MSGDLG #if wxUSE_MSGDLG
class WXDLLEXPORT wxMessageDialogBase #include "wx/dialog.h"
WXDLLEXPORT_DATA(extern const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxMessageDialogBase : public wxDialog
{ {
public:
// ctors
wxMessageDialogBase() { m_dialogStyle = 0; }
wxMessageDialogBase(wxWindow *parent,
const wxString& message,
const wxString& caption,
long style)
: m_message(message),
m_caption(caption)
{
m_parent = parent;
SetMessageDialogStyle(style);
}
// virtual dtor for the base class
virtual ~wxMessageDialogBase() { }
// methods for setting up more custom message dialogs -- all functions
// return false if they're not implemented
virtual bool SetYesNoLabels(const wxString& WXUNUSED(yes),
const wxString& WXUNUSED(no))
{
return false;
}
virtual bool SetYesNoCancelLabels(const wxString& WXUNUSED(yes),
const wxString& WXUNUSED(no),
const wxString& WXUNUSED(cancel))
{
return false;
}
virtual bool SetOKLabel(const wxString& WXUNUSED(ok))
{
return false;
}
virtual bool SetOKCancelLabels(const wxString& WXUNUSED(ok),
const wxString& WXUNUSED(cancel))
{
return false;
}
virtual void SetMessage(const wxString& message)
{
m_message = message;
}
virtual void SetExtendedMessage(const wxString& extendedMessage)
{
m_extendedMessage = extendedMessage;
}
protected: protected:
// common validation of wxMessageDialog style // common validation of wxMessageDialog style
void SetMessageDialogStyle(long style) void SetMessageDialogStyle(long style)
@@ -30,37 +88,46 @@ protected:
m_dialogStyle = style; m_dialogStyle = style;
} }
inline long GetMessageDialogStyle() const
long GetMessageDialogStyle() const { return m_dialogStyle; }
// for the platforms not supporting separate main and extended messages
// this function should be used to combine both of them in a single string
wxString GetFullMessage() const
{ {
return m_dialogStyle; wxString msg = m_message;
if ( !m_extendedMessage.empty() )
msg << "\n\n" << m_extendedMessage;
return msg;
} }
private: wxString m_message,
m_extendedMessage,
m_caption;
long m_dialogStyle; long m_dialogStyle;
}; };
#if defined(__WX_COMPILING_MSGDLGG_CPP__) #if defined(__WX_COMPILING_MSGDLGG_CPP__) || \
#include "wx/generic/msgdlgg.h" defined(__WXUNIVERSAL__) || defined(__WXGPE__) || \
#elif defined(__WXUNIVERSAL__) || defined(__WXGPE__) defined(__WXCOCOA__) || \
#include "wx/generic/msgdlgg.h" (defined(__WXGTK__) && !defined(__WXGTK20__))
#include "wx/generic/msgdlgg.h"
#define wxMessageDialog wxGenericMessageDialog
#elif defined(__WXPALMOS__) #elif defined(__WXPALMOS__)
#include "wx/palmos/msgdlg.h" #include "wx/palmos/msgdlg.h"
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
#include "wx/msw/msgdlg.h" #include "wx/msw/msgdlg.h"
#elif defined(__WXMOTIF__) #elif defined(__WXMOTIF__)
#include "wx/motif/msgdlg.h" #include "wx/motif/msgdlg.h"
#elif defined(__WXGTK20__) #elif defined(__WXGTK20__)
#include "wx/gtk/msgdlg.h" #include "wx/gtk/msgdlg.h"
#elif defined(__WXGTK__)
#include "wx/generic/msgdlgg.h"
#elif defined(__WXGTK__)
#include "wx/generic/msgdlgg.h"
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
#include "wx/mac/msgdlg.h" #include "wx/mac/msgdlg.h"
#elif defined(__WXCOCOA__)
#include "wx/generic/msgdlgg.h"
#elif defined(__WXPM__) #elif defined(__WXPM__)
#include "wx/os2/msgdlg.h" #include "wx/os2/msgdlg.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -75,5 +142,4 @@ int WXDLLEXPORT wxMessageBox(const wxString& message,
#endif // wxUSE_MSGDLG #endif // wxUSE_MSGDLG
#endif #endif // _WX_MSGDLG_H_BASE_
// _WX_MSGDLG_H_BASE_

View File

@@ -12,31 +12,25 @@
#ifndef _WX_MSGBOXDLG_H_ #ifndef _WX_MSGBOXDLG_H_
#define _WX_MSGBOXDLG_H_ #define _WX_MSGBOXDLG_H_
#include "wx/defs.h" class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
/*
* Message box dialog
*/
extern WXDLLEXPORT_DATA(const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
protected:
wxString m_caption;
wxString m_message;
wxWindow * m_parent;
public: public:
wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption = wxMessageBoxCaptionStr, wxMessageDialog(wxWindow *parent,
long style = wxOK|wxCENTRE, const wxPoint& pos = wxDefaultPosition); const wxString& message,
const wxString& caption = wxMessageBoxCaptionStr,
long style = wxOK|wxCENTRE,
const wxPoint& WXUNUSED(pos) = wxDefaultPosition)
: wxMessageDialogBase(parent, message, caption, style)
{
}
int ShowModal(void);
virtual int ShowModal();
protected:
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
DECLARE_NO_COPY_CLASS(wxMessageDialog) DECLARE_NO_COPY_CLASS(wxMessageDialog)
}; };
#endif #endif // _WX_MSGBOXDLG_H_
// _WX_MSGBOXDLG_H_

View File

@@ -13,31 +13,23 @@
#ifndef _WX_MSGBOXDLG_H_ #ifndef _WX_MSGBOXDLG_H_
#define _WX_MSGBOXDLG_H_ #define _WX_MSGBOXDLG_H_
#include "wx/defs.h" class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
/*
* Message box dialog
*/
class WXDLLEXPORT wxMessageDialog : public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
public: public:
wxMessageDialog( wxWindow* pParent wxMessageDialog( wxWindow* pParent
,const wxString& rsMessage ,const wxString& rsMessage
,const wxString& rsCaption = wxMessageBoxCaptionStr ,const wxString& rsCaption = wxMessageBoxCaptionStr
,long lStyle = wxOK|wxCENTRE ,long lStyle = wxOK|wxCENTRE
,const wxPoint& rPos = wxDefaultPosition ,const wxPoint& WXUNUSED(rPos) = wxDefaultPosition
); )
: wxMessageDialogBase(pParent, rsMessage, rsCaption, lStyle)
{
}
int ShowModal(void); int ShowModal(void);
protected: protected:
wxString m_sCaption; DECLARE_DYNAMIC_CLASS(wxMessageDialog)
wxString m_sMessage;
wxWindow* m_pParent;
}; // end of CLASS wxMessageDialog }; // end of CLASS wxMessageDialog
#endif #endif // _WX_MSGBOXDLG_H_
// _WX_MSGBOXDLG_H_

View File

@@ -12,28 +12,21 @@
#ifndef _WX_MSGBOXDLG_H_ #ifndef _WX_MSGBOXDLG_H_
#define _WX_MSGBOXDLG_H_ #define _WX_MSGBOXDLG_H_
#include "wx/defs.h" class WXDLLEXPORT wxMessageDialog : public wxMessageDialogBase
#include "wx/dialog.h"
/*
* Message box dialog
*/
WXDLLEXPORT_DATA(extern const wxChar) wxMessageBoxCaptionStr[];
class WXDLLEXPORT wxMessageDialog: public wxDialog, public wxMessageDialogBase
{ {
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
protected:
wxString m_caption;
wxString m_message;
wxWindow * m_parent;
public: public:
wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption = wxMessageBoxCaptionStr, wxMessageDialog(wxWindow *parent,
long style = wxOK|wxCENTRE, const wxPoint& pos = wxDefaultPosition); const wxString& message,
const wxString& caption = wxMessageBoxCaptionStr,
long style = wxOK|wxCENTRE,
const wxPoint& WXUNUSED(pos) = wxDefaultPosition)
: wxMessageDialogBase(parent, message, caption, style)
{
}
int ShowModal(void); virtual int ShowModal(void);
DECLARE_DYNAMIC_CLASS(wxMessageDialog)
DECLARE_NO_COPY_CLASS(wxMessageDialog) DECLARE_NO_COPY_CLASS(wxMessageDialog)
}; };

View File

@@ -593,8 +593,19 @@ void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
{ {
wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), wxMessageDialog dialog(NULL,
_T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); _T("This is a message box\nA long, long string to test out the message box properly"),
_T("Message box text"),
wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION);
if ( dialog.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
{
dialog.SetExtendedMessage(_T("This platform supports custom button labels"));
}
else
{
dialog.SetExtendedMessage(_T("Custom button labels are not supported."));
}
switch ( dialog.ShowModal() ) switch ( dialog.ShowModal() )
{ {

View File

@@ -60,11 +60,18 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
const wxString& caption, const wxString& caption,
long style, long style,
const wxPoint& pos) const wxPoint& pos)
: wxDialog( parent, wxID_ANY, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ) : wxMessageDialogBase(GetParentForModalDialog(parent),
message,
caption,
style),
m_pos(pos)
{ {
SetMessageDialogStyle(style); m_created = false;
}
parent = GetParentForModalDialog(parent); void wxGenericMessageDialog::DoCreateMsgdialog()
{
wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
@@ -74,10 +81,10 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
#if wxUSE_STATBMP #if wxUSE_STATBMP
// 1) icon // 1) icon
if (style & wxICON_MASK) if (m_dialogStyle & wxICON_MASK)
{ {
wxBitmap bitmap; wxBitmap bitmap;
switch ( style & wxICON_MASK ) switch ( m_dialogStyle & wxICON_MASK )
{ {
default: default:
wxFAIL_MSG(_T("incorrect log style")); wxFAIL_MSG(_T("incorrect log style"));
@@ -109,16 +116,16 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
#if wxUSE_STATTEXT #if wxUSE_STATTEXT
// 2) text // 2) text
icon_text->Add( CreateTextSizer( message ), 0, wxALIGN_CENTER | wxLEFT, 10 ); icon_text->Add( CreateTextSizer( GetFullMessage() ), 0, wxALIGN_CENTER | wxLEFT, 10 );
topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
#endif // wxUSE_STATTEXT #endif // wxUSE_STATTEXT
// 3) buttons // 3) buttons
int center_flag = wxEXPAND; int center_flag = wxEXPAND;
if (style & wxYES_NO) if (m_dialogStyle & wxYES_NO)
center_flag = wxALIGN_CENTRE; center_flag = wxALIGN_CENTRE;
wxSizer *sizerBtn = CreateSeparatedButtonSizer(style & ButtonSizerFlags); wxSizer *sizerBtn = CreateSeparatedButtonSizer(m_dialogStyle & ButtonSizerFlags);
if ( sizerBtn ) if ( sizerBtn )
topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10 ); topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10 );
@@ -158,4 +165,15 @@ void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
} }
} }
int wxGenericMessageDialog::ShowModal()
{
if ( !m_created )
{
m_created = true;
DoCreateMsgdialog();
}
return wxMessageDialogBase::ShowModal();
}
#endif // wxUSE_MSGDLG && !defined(__WXGTK20__) #endif // wxUSE_MSGDLG && !defined(__WXGTK20__)

View File

@@ -34,57 +34,88 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
const wxString& caption, const wxString& caption,
long style, long style,
const wxPoint& WXUNUSED(pos)) const wxPoint& WXUNUSED(pos))
: wxMessageDialogBase(GetParentForModalDialog(parent),
message,
caption,
style)
{ {
m_caption = caption; }
m_message = message;
SetMessageDialogStyle(style);
m_parent = GetParentForModalDialog(parent);
void wxMessageDialog::GTKCreateMsgDialog()
{
GtkMessageType type = GTK_MESSAGE_ERROR; GtkMessageType type = GTK_MESSAGE_ERROR;
GtkButtonsType buttons = GTK_BUTTONS_OK; GtkButtonsType buttons = GTK_BUTTONS_OK;
if (style & wxYES_NO) if (m_dialogStyle & wxYES_NO)
{ {
if (style & wxCANCEL) if (m_dialogStyle & wxCANCEL)
buttons = GTK_BUTTONS_NONE; buttons = GTK_BUTTONS_NONE;
else else
buttons = GTK_BUTTONS_YES_NO; buttons = GTK_BUTTONS_YES_NO;
} }
if (style & wxOK) if (m_dialogStyle & wxOK)
{ {
if (style & wxCANCEL) if (m_dialogStyle & wxCANCEL)
buttons = GTK_BUTTONS_OK_CANCEL; buttons = GTK_BUTTONS_OK_CANCEL;
else else
buttons = GTK_BUTTONS_OK; buttons = GTK_BUTTONS_OK;
} }
if (style & wxICON_EXCLAMATION) if (m_dialogStyle & wxICON_EXCLAMATION)
type = GTK_MESSAGE_WARNING; type = GTK_MESSAGE_WARNING;
else if (style & wxICON_ERROR) else if (m_dialogStyle & wxICON_ERROR)
type = GTK_MESSAGE_ERROR; type = GTK_MESSAGE_ERROR;
else if (style & wxICON_INFORMATION) else if (m_dialogStyle & wxICON_INFORMATION)
type = GTK_MESSAGE_INFO; type = GTK_MESSAGE_INFO;
else if (style & wxICON_QUESTION) else if (m_dialogStyle & wxICON_QUESTION)
type = GTK_MESSAGE_QUESTION; type = GTK_MESSAGE_QUESTION;
else else
{ {
// GTK+ doesn't have a "typeless" msg box, so try to auto detect... // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
} }
m_widget = gtk_message_dialog_new(m_parent ? wxString message;
GTK_WINDOW(m_parent->m_widget) : NULL, #if GTK_CHECK_VERSION(2, 4, 0)
bool needsExtMessage = false;
if ( gtk_check_version(2, 4, 0) == NULL && !m_extendedMessage.empty() )
{
message = m_message;
needsExtMessage = true;
}
else // extended message not needed or not supported
#endif // GTK+ 2.4+
{
message = GetFullMessage();
}
m_widget = gtk_message_dialog_new(m_parent ? GTK_WINDOW(m_parent->m_widget)
: NULL,
GTK_DIALOG_MODAL, GTK_DIALOG_MODAL,
type, buttons, type,
"%s", (const char*)wxGTK_CONV(m_message)); buttons,
"%s",
(const char*)wxGTK_CONV(message));
#if GTK_CHECK_VERSION(2, 4, 0)
if ( needsExtMessage )
{
gtk_message_dialog_format_secondary_text
(
(GtkMessageDialog *)m_widget,
"%s",
(const char *)wxGTK_CONV(m_extendedMessage)
);
}
#endif // GTK+ 2.4+
if (m_caption != wxMessageBoxCaptionStr) if (m_caption != wxMessageBoxCaptionStr)
gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
if (style & wxYES_NO) if (m_dialogStyle & wxYES_NO)
{ {
if (style & wxCANCEL) if (m_dialogStyle & wxCANCEL)
{ {
gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO, gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
GTK_RESPONSE_NO); GTK_RESPONSE_NO);
@@ -93,7 +124,7 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES, gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
GTK_RESPONSE_YES); GTK_RESPONSE_YES);
} }
if (style & wxNO_DEFAULT) if (m_dialogStyle & wxNO_DEFAULT)
gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
else else
gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
@@ -104,12 +135,15 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
GTK_WINDOW(m_parent->m_widget)); GTK_WINDOW(m_parent->m_widget));
} }
wxMessageDialog::~wxMessageDialog()
{
}
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
{ {
if ( !m_widget )
{
GTKCreateMsgDialog();
wxCHECK_MSG( m_widget, wxID_CANCEL,
_T("failed to create GtkMessageDialog") );
}
// This should be necessary, but otherwise the // This should be necessary, but otherwise the
// parent TLW will disappear.. // parent TLW will disappear..
if (m_parent) if (m_parent)

View File

@@ -24,14 +24,45 @@
IMPLEMENT_CLASS(wxMessageDialog, wxDialog) IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
wxMessageDialog::wxMessageDialog( wxMessageDialog::wxMessageDialog(wxWindow *parent,
wxWindow *parent, const wxString& message, const wxString& caption, const wxString& message,
long style, const wxPoint& pos ) const wxString& caption,
long style,
const wxPoint& pos)
: wxMessageDialogBase(parent, message, caption, style)
{ {
m_caption = caption; m_yes = _("Yes");
m_message = message; m_no = _("No");
m_parent = parent; m_ok = _("OK");
SetMessageDialogStyle(style); m_cancel = _("Cancel");
}
bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
{
m_yes = yes;
m_no = no;
return true;
}
bool wxMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel)
{
m_yes = yes;
m_no = no;
m_cancel = cancel;
return true;
}
bool wxMessageDialog::SetOKLabel(const wxString& ok)
{
m_ok = ok;
return true;
}
bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
{
m_ok = ok;
m_cancel = cancel;
return true;
} }
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
@@ -52,6 +83,26 @@ int wxMessageDialog::ShowModal()
else if (style & wxICON_QUESTION) else if (style & wxICON_QUESTION)
alertType = kAlertCautionAlert; alertType = kAlertCautionAlert;
// 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)
// but if the extended message is not empty then we use the message as the title
// and the extended message as the text because that makes more sense
wxString msgtitle,msgtext;
if(m_extendedMessage.IsEmpty())
{
msgtitle = m_caption;
msgtext = m_message;
}
else
{
msgtitle = m_message;
msgtext = m_extendedMessage;
}
#if TARGET_API_MAC_OSX #if TARGET_API_MAC_OSX
if ( !wxIsMainThread() ) if ( !wxIsMainThread() )
{ {
@@ -59,13 +110,13 @@ int wxMessageDialog::ShowModal()
CFStringRef alternateButtonTitle = NULL; CFStringRef alternateButtonTitle = NULL;
CFStringRef otherButtonTitle = NULL; CFStringRef otherButtonTitle = NULL;
wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ; wxMacCFStringHolder cfOKString( m_ok.c_str() , m_font.GetEncoding()) ;
wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() ); wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() );
int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
@@ -117,11 +168,13 @@ int wxMessageDialog::ShowModal()
short result; short result;
AlertStdCFStringAlertParamRec param; AlertStdCFStringAlertParamRec param;
wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfOKString( m_ok.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() );
wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
param.movable = true; param.movable = true;
param.flags = 0; param.flags = 0;
@@ -134,7 +187,7 @@ int wxMessageDialog::ShowModal()
if (style & wxCANCEL) if (style & wxCANCEL)
{ {
param.defaultText = cfYesString; param.defaultText = cfYesString;
param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.cancelText = cfCancelString;
param.otherText = cfNoString; param.otherText = cfNoString;
param.helpButton = false; param.helpButton = false;
param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
@@ -156,8 +209,8 @@ int wxMessageDialog::ShowModal()
if (style & wxCANCEL) if (style & wxCANCEL)
{ {
// that's a cancel missing // that's a cancel missing
param.defaultText = (CFStringRef) kAlertDefaultOKText; param.defaultText = cfOKString;
param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.cancelText = cfCancelString;
param.otherText = NULL; param.otherText = NULL;
param.helpButton = false; param.helpButton = false;
param.defaultButton = kAlertStdAlertOKButton; param.defaultButton = kAlertStdAlertOKButton;
@@ -165,7 +218,7 @@ int wxMessageDialog::ShowModal()
} }
else else
{ {
param.defaultText = (CFStringRef) kAlertDefaultOKText; param.defaultText = cfOKString;
param.cancelText = NULL; param.cancelText = NULL;
param.otherText = NULL; param.otherText = NULL;
param.helpButton = false; param.helpButton = false;

View File

@@ -99,18 +99,6 @@ static void msgboxCallBackClose(Widget w,
// wxMessageDialog // wxMessageDialog
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxMessageDialog::wxMessageDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
{
m_caption = caption;
m_message = message;
m_parent = parent;
SetMessageDialogStyle(style);
}
extern "C" extern "C"
{ {
typedef Widget (*DialogCreateFunction)(Widget, String, ArgList, Cardinal); typedef Widget (*DialogCreateFunction)(Widget, String, ArgList, Cardinal);
@@ -160,7 +148,7 @@ int wxMessageDialog::ShowModal()
Arg args[10]; Arg args[10];
int ac = 0; int ac = 0;
wxXmString text(m_message); wxXmString text(GetFullMessage());
wxXmString title(m_caption); wxXmString title(m_caption);
XtSetArg(args[ac], XmNmessageString, text()); ac++; XtSetArg(args[ac], XmNmessageString, text()); ac++;
XtSetArg(args[ac], XmNdialogTitle, title()); ac++; XtSetArg(args[ac], XmNdialogTitle, title()); ac++;

View File

@@ -33,18 +33,6 @@
IMPLEMENT_CLASS(wxMessageDialog, wxDialog) IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
wxMessageDialog::wxMessageDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
{
m_caption = caption;
m_message = message;
m_parent = parent;
SetMessageDialogStyle(style);
}
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
{ {
if ( !wxTheApp->GetTopWindow() ) if ( !wxTheApp->GetTopWindow() )
@@ -110,7 +98,7 @@ int wxMessageDialog::ShowModal()
// per MSDN documentation for MessageBox() we can prefix the message with 2 // per MSDN documentation for MessageBox() we can prefix the message with 2
// right-to-left mark characters to tell the function to use RTL layout // right-to-left mark characters to tell the function to use RTL layout
// (unfortunately this only works in Unicode builds) // (unfortunately this only works in Unicode builds)
wxString message = m_message; wxString message = GetFullMessage();
#if wxUSE_UNICODE #if wxUSE_UNICODE
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
{ {

View File

@@ -32,18 +32,6 @@
IMPLEMENT_CLASS(wxMessageDialog, wxDialog) IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
wxMessageDialog::wxMessageDialog( wxWindow* WXUNUSED(pParent),
const wxString& rsMessage,
const wxString& rsCaption,
long lStyle,
const wxPoint& WXUNUSED(pPos) )
{
m_sCaption = rsCaption;
m_sMessage = rsMessage;
m_pParent = NULL; // pParent;
SetMessageDialogStyle(lStyle);
} // end of wxMessageDialog::wxMessageDialog
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
{ {
HWND hWnd = 0; HWND hWnd = 0;
@@ -63,8 +51,8 @@ int wxMessageDialog::ShowModal()
wxTheApp->Dispatch(); wxTheApp->Dispatch();
} }
if (m_pParent) if (m_parent)
hWnd = (HWND) m_pParent->GetHWND(); hWnd = (HWND) m_parent->GetHWND();
else else
hWnd = HWND_DESKTOP; hWnd = HWND_DESKTOP;
if (lStyle & wxYES_NO) if (lStyle & wxYES_NO)
@@ -109,8 +97,8 @@ int wxMessageDialog::ShowModal()
ULONG ulAns = ::WinMessageBox( hWnd ULONG ulAns = ::WinMessageBox( hWnd
,hWnd ,hWnd
,m_sMessage.c_str() ,GetFullMessage().c_str()
,m_sCaption.c_str() ,m_caption.c_str()
,0L ,0L
,ulStyle); ,ulStyle);
switch (ulAns) switch (ulAns)

View File

@@ -28,18 +28,6 @@
IMPLEMENT_CLASS(wxMessageDialog, wxDialog) IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
wxMessageDialog::wxMessageDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
{
m_caption = caption;
m_message = message;
m_parent = parent;
SetMessageDialogStyle(style);
}
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
{ {
int AlertID=1000; int AlertID=1000;
@@ -111,7 +99,7 @@ int wxMessageDialog::ShowModal()
DmReleaseResource(AlertHandle); DmReleaseResource(AlertHandle);
// Display the dialog // Display the dialog
Result=FrmCustomAlert(AppDB,AlertID,m_message.c_str(),"",""); Result=FrmCustomAlert(AppDB,AlertID,GetFullMessage().c_str(),"","");
// Convert the Palm OS result to wxResult // Convert the Palm OS result to wxResult
if(AlertID<1100) if(AlertID<1100)