// Author: Vadim Zeitlin
// Modified by:
// Created: 29.06.99
-// RCS-ID: $Id$
// Copyright: (c) Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DIALOG_H_BASE_
#define _WX_DIALOG_H_BASE_
-#include "wx/defs.h"
#include "wx/toplevel.h"
+#include "wx/containr.h"
class WXDLLIMPEXP_FWD_CORE wxSizer;
class WXDLLIMPEXP_FWD_CORE wxStdDialogButtonSizer;
class WXDLLIMPEXP_FWD_CORE wxDialog;
class WXDLLIMPEXP_FWD_CORE wxButton;
class WXDLLIMPEXP_FWD_CORE wxScrolledWindow;
+class wxTextSizerWrapper;
-#define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
+// Also see the bit summary table in wx/toplevel.h.
+
+#define wxDIALOG_NO_PARENT 0x00000020 // Don't make owned by apps top window
#ifdef __WXWINCE__
#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
wxDIALOG_ADAPTATION_MODE_DISABLED = 2 // disable this dialog overriding global status
};
+enum wxDialogModality
+{
+ wxDIALOG_MODALITY_NONE = 0,
+ wxDIALOG_MODALITY_WINDOW_MODAL = 1,
+ wxDIALOG_MODALITY_APP_MODAL = 2
+};
+
extern WXDLLIMPEXP_DATA_CORE(const char) wxDialogNameStr[];
-class WXDLLIMPEXP_CORE wxDialogBase : public wxTopLevelWindow
+class WXDLLIMPEXP_CORE wxDialogBase : public wxNavigationEnabled<wxTopLevelWindow>
{
public:
- enum
- {
- // all flags allowed in wxDialogBase::CreateButtonSizer()
- ButtonSizerFlags = wxOK|wxCANCEL|wxYES|wxNO|wxHELP|wxNO_DEFAULT
- };
-
- wxDialogBase() { Init(); }
+ wxDialogBase();
virtual ~wxDialogBase() { }
// define public wxDialog methods to be implemented by the derived classes
virtual int ShowModal() = 0;
virtual void EndModal(int retCode) = 0;
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 void ShowWindowModal () ;
+ virtual void SendWindowModalDialogEvent ( wxEventType type );
+#ifdef wxHAS_EVENT_BIND
+ template<typename Functor>
+ void ShowWindowModalThenDo(const Functor& onEndModal);
+#endif // wxHAS_EVENT_BIND
// Modal dialogs have a return code - usually the id of the last
// pressed button
void SetEscapeId(int escapeId);
int GetEscapeId() const { return m_escapeId; }
- // Returns the parent to use for modal dialogs if the user did not specify it
- // explicitly
- wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const;
+ // Find the parent to use for modal dialog: try to use the specified parent
+ // but fall back to the current active window or main application window as
+ // last resort if it is unsuitable.
+ //
+ // As this function is often called from the ctor, the window style may be
+ // not set yet and hence must be passed explicitly to it so that we could
+ // check whether it contains wxDIALOG_NO_PARENT bit.
+ //
+ // This function always returns a valid top level window or NULL.
+ wxWindow *GetParentForModalDialog(wxWindow *parent, long style) const;
+
+ // This overload can only be used for already initialized windows, i.e. not
+ // from the ctor. It uses the current window parent and style.
+ wxWindow *GetParentForModalDialog() const
+ {
+ return GetParentForModalDialog(GetParent(), GetWindowStyle());
+ }
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
- // splits text up at newlines and places the
- // lines into a vertical wxBoxSizer
- wxSizer *CreateTextSizer( const wxString &message );
+ // splits text up at newlines and places the lines into a vertical
+ // wxBoxSizer
+ wxSizer *CreateTextSizer( const wxString& message );
+
+ // same as above but uses a customized wxTextSizerWrapper to create
+ // non-standard controls for the lines
+ wxSizer *CreateTextSizer( const wxString& message,
+ wxTextSizerWrapper& wrapper );
#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
// returns a horizontal wxBoxSizer containing the given buttons
// platforms which have hardware buttons replacing OK/Cancel and such)
wxSizer *CreateButtonSizer(long flags);
+ // returns a sizer containing the given one and a static line separating it
+ // from the preceding elements if it's appropriate for the current platform
+ wxSizer *CreateSeparatedSizer(wxSizer *sizer);
+
// returns the sizer containing CreateButtonSizer() below a separating
// static line for the platforms which use static lines for items
// separation (i.e. not Mac)
+ //
+ // this is just a combination of CreateButtonSizer() and
+ // CreateSeparatedSizer()
wxSizer *CreateSeparatedButtonSizer(long flags);
#if wxUSE_BUTTON
static bool IsLayoutAdaptationEnabled() { return sm_layoutAdaptation; }
static void EnableLayoutAdaptation(bool enable) { sm_layoutAdaptation = enable; }
+ // modality kind
+ virtual wxDialogModality GetModality() const;
protected:
// emulate click of a button with the given id if it's present in the dialog
//
// wxID_OK return code
void AcceptAndClose();
-
// The return code from modal dialog
int m_returnCode;
static bool sm_layoutAdaptation;
private:
- // common part of all ctors
- void Init();
+ // helper of GetParentForModalDialog(): returns the passed in window if it
+ // can be used as our parent or NULL if it can't
+ wxWindow *CheckIfCanBeUsedAsParent(wxWindow *parent) const;
+
+ // Helper of OnCharHook() and OnCloseWindow(): find the appropriate button
+ // for closing the dialog and send a click event for it.
+ //
+ // Return true if we found a button to close the dialog and "clicked" it or
+ // false otherwise.
+ bool SendCloseButtonClickEvent();
// handle Esc key presses
void OnCharHook(wxKeyEvent& event);
void OnSysColourChanged(wxSysColourChangedEvent& event);
- DECLARE_NO_COPY_CLASS(wxDialogBase)
+ wxDECLARE_NO_COPY_CLASS(wxDialogBase);
DECLARE_EVENT_TABLE()
};
// Create the scrolled window
virtual wxScrolledWindow* CreateScrolledWindow(wxWindow* parent);
+#if wxUSE_BUTTON
// Find a standard or horizontal box sizer
virtual wxSizer* FindButtonSizer(bool stdButtonSizer, wxDialog* dialog, wxSizer* sizer, int& retBorder, int accumlatedBorder = 0);
// Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
virtual bool FindLooseButtons(wxDialog* dialog, wxStdDialogButtonSizer* buttonSizer, wxSizer* sizer, int& count);
+#endif // wxUSE_BUTTON
// Reparent the controls to the scrolled window, except those in buttonSizer
virtual void ReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL);
#if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
#include "wx/univ/dialog.h"
#else
- #if defined(__WXPALMOS__)
- #include "wx/palmos/dialog.h"
- #elif defined(__WXMSW__)
+ #if defined(__WXMSW__)
#include "wx/msw/dialog.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/dialog.h"
#elif defined(__WXGTK__)
#include "wx/gtk1/dialog.h"
#elif defined(__WXMAC__)
- #include "wx/mac/dialog.h"
+ #include "wx/osx/dialog.h"
#elif defined(__WXCOCOA__)
#include "wx/cocoa/dialog.h"
#elif defined(__WXPM__)
#endif
#endif
+class WXDLLIMPEXP_CORE wxWindowModalDialogEvent : public wxCommandEvent
+{
+public:
+ wxWindowModalDialogEvent (wxEventType commandType = wxEVT_NULL, int id = 0)
+ : wxCommandEvent(commandType, id) { }
+
+ wxDialog *GetDialog() const
+ { return wxStaticCast(GetEventObject(), wxDialog); }
+
+ int GetReturnCode() const
+ { return GetDialog()->GetReturnCode(); }
+
+ virtual wxEvent *Clone() const { return new wxWindowModalDialogEvent (*this); }
+
+private:
+ DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowModalDialogEvent )
+};
+
+wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_WINDOW_MODAL_DIALOG_CLOSED , wxWindowModalDialogEvent );
+
+typedef void (wxEvtHandler::*wxWindowModalDialogEventFunction)(wxWindowModalDialogEvent &);
+
+#define wxWindowModalDialogEventHandler(func) \
+ wxEVENT_HANDLER_CAST(wxWindowModalDialogEventFunction, func)
+
+#define EVT_WINDOW_MODAL_DIALOG_CLOSED(winid, func) \
+ wx__DECLARE_EVT1(wxEVT_WINDOW_MODAL_DIALOG_CLOSED, winid, wxWindowModalDialogEventHandler(func))
+
+#ifdef wxHAS_EVENT_BIND
+template<typename Functor>
+class wxWindowModalDialogEventFunctor
+{
+public:
+ wxWindowModalDialogEventFunctor(const Functor& f)
+ : m_f(f), m_wasCalled(false)
+ {}
+
+ void operator()(wxWindowModalDialogEvent& event)
+ {
+ if ( m_wasCalled )
+ {
+ event.Skip();
+ return;
+ }
+
+ m_wasCalled = true;
+ m_f(event.GetReturnCode());
+ }
+
+private:
+ Functor m_f;
+ bool m_wasCalled;
+};
+
+template<typename Functor>
+void wxDialogBase::ShowWindowModalThenDo(const Functor& onEndModal)
+{
+ Bind(wxEVT_WINDOW_MODAL_DIALOG_CLOSED,
+ wxWindowModalDialogEventFunctor<Functor>(onEndModal));
+ ShowWindowModal();
+};
+#endif // wxHAS_EVENT_BIND
+
#endif
// _WX_DIALOG_H_BASE_