]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dialog.cpp
replace wxPostEvent with wxQueueEvent and update the thread sample description (the...
[wxWidgets.git] / src / msw / dialog.cpp
index 8d30e360194f0bed928e400009fa3a5d705818eb..2190cbd8e8ae8db9e7032d8472f52302463810d9 100644 (file)
@@ -27,6 +27,7 @@
 #include "wx/dialog.h"
 
 #ifndef WX_PRECOMP
+    #include "wx/msw/wrapcdlg.h"
     #include "wx/utils.h"
     #include "wx/frame.h"
     #include "wx/app.h"
@@ -41,8 +42,6 @@
 #include "wx/evtloop.h"
 #include "wx/ptr_scpd.h"
 
-#include "wx/msw/wrapcdlg.h"
-
 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
     #include "wx/msw/wince/resources.h"
 #endif // __SMARTPHONE__ && __WXWINCE__
@@ -153,6 +152,7 @@ void wxDialog::Init()
 #if wxUSE_TOOLBAR && defined(__POCKETPC__)
     m_dialogToolBar = NULL;
 #endif
+    m_hGripper = 0;
 }
 
 bool wxDialog::Create(wxWindow *parent,
@@ -184,55 +184,31 @@ bool wxDialog::Create(wxWindow *parent,
     CreateToolBar();
 #endif
 
-    return true;
-}
-
-#if WXWIN_COMPATIBILITY_2_6
-
-// deprecated ctor
-wxDialog::wxDialog(wxWindow *parent,
-                   const wxString& title,
-                   bool WXUNUSED(modal),
-                   int x,
-                   int y,
-                   int w,
-                   int h,
-                   long style,
-                   const wxString& name)
-{
-    Init();
+    if ( HasFlag(wxRESIZE_BORDER) )
+    {
+        CreateGripper();
 
-    Create(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h), style, name);
-}
+        Connect(wxEVT_CREATE,
+                wxWindowCreateEventHandler(wxDialog::OnWindowCreate));
+    }
 
-void wxDialog::SetModal(bool WXUNUSED(flag))
-{
-    // nothing to do, obsolete method
+    return true;
 }
 
-#endif // WXWIN_COMPATIBILITY_2_6
-
 wxDialog::~wxDialog()
 {
     m_isBeingDeleted = true;
 
     // this will also reenable all the other windows for a modal dialog
     Show(false);
+
+    DestroyGripper();
 }
 
 // ----------------------------------------------------------------------------
 // showing the dialogs
 // ----------------------------------------------------------------------------
 
-#if WXWIN_COMPATIBILITY_2_6
-
-bool wxDialog::IsModalShowing() const
-{
-    return IsModal();
-}
-
-#endif // WXWIN_COMPATIBILITY_2_6
-
 wxWindow *wxDialog::FindSuitableParent() const
 {
     // first try to use the currently active window
@@ -272,6 +248,9 @@ bool wxDialog::Show(bool show)
 
     if ( show )
     {
+        if (CanDoLayoutAdaptation())
+            DoLayoutAdaptation();
+
         // this usually will result in TransferDataToWindow() being called
         // which will change the controls values so do it before showing as
         // otherwise we could have some flicker
@@ -282,13 +261,15 @@ bool wxDialog::Show(bool show)
 
     if ( show )
     {
-        // dialogs don't get WM_SIZE message after creation unlike most (all?)
-        // other windows and so could start their life non laid out correctly
-        // if we didn't call Layout() from here
+        // dialogs don't get WM_SIZE message from ::ShowWindow() for some
+        // reason so generate it ourselves for consistency with frames and
+        // dialogs in other ports
         //
         // NB: normally we should call it just the first time but doing it
         //     every time is simpler than keeping a flag
-        Layout();
+        const wxSize size = GetClientSize();
+        ::SendMessage(GetHwnd(), WM_SIZE,
+                      SIZE_RESTORED, MAKELPARAM(size.x, size.y));
     }
 
     return true;
@@ -302,7 +283,7 @@ void wxDialog::Raise()
 // show dialog modally
 int wxDialog::ShowModal()
 {
-    wxASSERT_MSG( !IsModal(), _T("wxDialog::ShowModal() reentered?") );
+    wxASSERT_MSG( !IsModal(), _T("ShowModal() can't be called twice") );
 
     m_endModalCalled = false;
 
@@ -367,6 +348,98 @@ void wxDialog::EndModal(int retCode)
     Hide();
 }
 
+// ----------------------------------------------------------------------------
+// wxDialog gripper handling
+// ----------------------------------------------------------------------------
+
+void wxDialog::SetWindowStyleFlag(long style)
+{
+    wxDialogBase::SetWindowStyleFlag(style);
+
+    if ( HasFlag(wxRESIZE_BORDER) )
+        CreateGripper();
+    else
+        DestroyGripper();
+}
+
+void wxDialog::CreateGripper()
+{
+    if ( !m_hGripper )
+    {
+        // just create it here, it will be positioned and shown later
+        m_hGripper = (WXHWND)::CreateWindow
+                               (
+                                    wxT("SCROLLBAR"),
+                                    wxT(""),
+                                    WS_CHILD |
+                                    WS_CLIPSIBLINGS |
+                                    SBS_SIZEGRIP |
+                                    SBS_SIZEBOX |
+                                    SBS_SIZEBOXBOTTOMRIGHTALIGN,
+                                    0, 0, 0, 0,
+                                    GetHwnd(),
+                                    0,
+                                    wxGetInstance(),
+                                    NULL
+                               );
+    }
+}
+
+void wxDialog::DestroyGripper()
+{
+    if ( m_hGripper )
+    {
+        // we used to have trouble with gripper appearing on top (and hence
+        // overdrawing) the other, real, dialog children -- check that this
+        // isn't the case automatically (but notice that this could be false if
+        // we're not shown at all as in this case ResizeGripper() might not
+        // have been called yet)
+        wxASSERT_MSG( !IsShown() ||
+                      ::GetWindow((HWND)m_hGripper, GW_HWNDNEXT) == 0,
+            _T("Bug in wxWidgets: gripper should be at the bottom of Z-order") );
+        ::DestroyWindow((HWND) m_hGripper);
+        m_hGripper = 0;
+    }
+}
+
+void wxDialog::ShowGripper(bool show)
+{
+    wxASSERT_MSG( m_hGripper, _T("shouldn't be called if we have no gripper") );
+
+    if ( show )
+        ResizeGripper();
+
+    ::ShowWindow((HWND)m_hGripper, show ? SW_SHOW : SW_HIDE);
+}
+
+void wxDialog::ResizeGripper()
+{
+    wxASSERT_MSG( m_hGripper, _T("shouldn't be called if we have no gripper") );
+
+    HWND hwndGripper = (HWND)m_hGripper;
+
+    const wxRect rectGripper = wxRectFromRECT(wxGetWindowRect(hwndGripper));
+    const wxSize size = GetClientSize() - rectGripper.GetSize();
+
+    ::SetWindowPos(hwndGripper, HWND_BOTTOM,
+                   size.x, size.y,
+                   rectGripper.width, rectGripper.height,
+                   SWP_NOACTIVATE);
+}
+
+void wxDialog::OnWindowCreate(wxWindowCreateEvent& event)
+{
+    if ( m_hGripper && IsShown() &&
+            event.GetWindow() && event.GetWindow()->GetParent() == this )
+    {
+        // Put gripper below the newly created child window
+        ::SetWindowPos((HWND)m_hGripper, HWND_BOTTOM, 0, 0, 0, 0,
+                       SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
+    }
+
+    event.Skip();
+}
+
 // ----------------------------------------------------------------------------
 // wxWin event handlers
 // ----------------------------------------------------------------------------
@@ -384,7 +457,7 @@ bool wxDialog::DoOK()
     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetAffirmativeId());
     event.SetEventObject(this);
 
-    return GetEventHandler()->ProcessEvent(event);
+    return HandleWindowEvent(event);
 }
 #endif // __POCKETPC__
 
@@ -448,6 +521,19 @@ WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPar
             break;
 
         case WM_SIZE:
+            if ( m_hGripper )
+            {
+                switch ( wParam )
+                {
+                    case SIZE_MAXIMIZED:
+                        ShowGripper(false);
+                        break;
+
+                    case SIZE_RESTORED:
+                        ShowGripper(true);
+                }
+            }
+
             // the Windows dialogs unfortunately are not meant to be resizeable
             // at all and their standard class doesn't include CS_[VH]REDRAW
             // styles which means that the window is not refreshed properly