#include "wx/msw/private.h"
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
#include "wx/msw/wince/resources.h"
void wxDialog::Init()
{
- m_oldFocus = (wxWindow *)NULL;
m_isShown = false;
m_modalData = NULL;
- m_endModalCalled = false;
#if wxUSE_TOOLBAR && defined(__POCKETPC__)
m_dialogToolBar = NULL;
#endif
+#if wxUSE_DIALOG_SIZEGRIP
m_hGripper = 0;
+#endif // wxUSE_DIALOG_SIZEGRIP
}
bool wxDialog::Create(wxWindow *parent,
{
SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
- // save focus before doing anything which can potentially change it
- m_oldFocus = FindFocus();
-
// All dialogs should really have this style
style |= wxTAB_TRAVERSAL;
CreateToolBar();
#endif
+#if wxUSE_DIALOG_SIZEGRIP
if ( HasFlag(wxRESIZE_BORDER) )
{
CreateGripper();
Connect(wxEVT_CREATE,
wxWindowCreateEventHandler(wxDialog::OnWindowCreate));
}
+#endif // wxUSE_DIALOG_SIZEGRIP
return true;
}
wxDialog::~wxDialog()
{
- m_isBeingDeleted = true;
-
// this will also reenable all the other windows for a modal dialog
Show(false);
+#if wxUSE_DIALOG_SIZEGRIP
DestroyGripper();
+#endif // wxUSE_DIALOG_SIZEGRIP
}
// ----------------------------------------------------------------------------
// showing the dialogs
// ----------------------------------------------------------------------------
-wxWindow *wxDialog::FindSuitableParent() const
-{
- // first try to use the currently active window
- HWND hwndFg = ::GetForegroundWindow();
- wxWindow *parent = hwndFg ? wxFindWinFromHandle((WXHWND)hwndFg)
- : NULL;
- if ( !parent )
- {
- // next try the main app window
- parent = wxTheApp->GetTopWindow();
- }
-
- // finally, check if the parent we found is really suitable
- if ( !parent || parent == (wxWindow *)this || !parent->IsShown() )
- {
- // don't use this one
- parent = NULL;
- }
-
- return parent;
-}
-
bool wxDialog::Show(bool show)
{
if ( show == IsShown() )
{
wxASSERT_MSG( !IsModal(), _T("ShowModal() can't be called twice") );
- m_endModalCalled = false;
-
Show();
// EndModal may have been called from InitDialog handler (called from
- // inside Show()), which would cause an infinite loop if we didn't take it
- // into account
- if ( !m_endModalCalled )
+ // inside Show()) and hidden the dialog back again
+ if ( IsShown() )
{
- // modal dialog needs a parent window, so try to find one
- wxWindow *parent = GetParent();
- if ( !parent )
- {
- parent = FindSuitableParent();
- }
-
- // remember where the focus was
- wxWindow *oldFocus = m_oldFocus;
- if ( !oldFocus )
- {
- // VZ: do we really want to do this?
- oldFocus = parent;
- }
-
- // We have to remember the HWND because we need to check
- // the HWND still exists (oldFocus can be garbage when the dialog
- // exits, if it has been destroyed)
- HWND hwndOldFocus = oldFocus ? GetHwndOf(oldFocus) : NULL;
-
-
// enter and run the modal loop
- {
- wxDialogModalDataTiedPtr modalData(&m_modalData,
- new wxDialogModalData(this));
- modalData->RunLoop();
- }
-
-
- // and restore focus
- // Note that this code MUST NOT access the dialog object's data
- // in case the object has been deleted (which will be the case
- // for a modal dialog that has been destroyed before calling EndModal).
- if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus))
- {
- // This is likely to prove that the object still exists
- if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
- oldFocus->SetFocus();
- }
+ wxDialogModalDataTiedPtr modalData(&m_modalData,
+ new wxDialogModalData(this));
+ modalData->RunLoop();
}
return GetReturnCode();
{
wxASSERT_MSG( IsModal(), _T("EndModal() called for non modal dialog") );
- m_endModalCalled = true;
SetReturnCode(retCode);
Hide();
// wxDialog gripper handling
// ----------------------------------------------------------------------------
+#if wxUSE_DIALOG_SIZEGRIP
+
void wxDialog::SetWindowStyleFlag(long style)
{
wxDialogBase::SetWindowStyleFlag(style);
event.Skip();
}
+#endif // wxUSE_DIALOG_SIZEGRIP
+
// ----------------------------------------------------------------------------
// wxWin event handlers
// ----------------------------------------------------------------------------
break;
case WM_SIZE:
+#if wxUSE_DIALOG_SIZEGRIP
if ( m_hGripper )
{
switch ( wParam )
ShowGripper(true);
}
}
+#endif // wxUSE_DIALOG_SIZEGRIP
// the Windows dialogs unfortunately are not meant to be resizeable
// at all and their standard class doesn't include CS_[VH]REDRAW