From 741ca84241cf2593f49b6def7bdd1b293307b182 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 29 Jun 2000 20:28:53 +0000 Subject: [PATCH] Fixed DoShowModal again, to check that the oldFocus object isn't dead. Added integer handling for wxTextCtrls in wxGenericValidator. Added virtual function to wxGenericDragImage so it can do _really_ smooth dragging under app control. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/timer.tex | 4 +--- include/wx/generic/dragimgg.h | 14 ++++++++++++++ src/common/valgen.cpp | 22 +++++++++++++++++----- src/generic/dragimgg.cpp | 26 ++++++++++++++++++++------ src/msw/dialog.cpp | 4 +++- 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/docs/latex/wx/timer.tex b/docs/latex/wx/timer.tex index 00eba9a6ca..62ddfb3f1a 100644 --- a/docs/latex/wx/timer.tex +++ b/docs/latex/wx/timer.tex @@ -34,7 +34,7 @@ be stopped later with \helpref{Stop}{wxtimerstop}. \latexignore{\rtfignore{\wxheading{Members}}} -\membersection{wxTimer::wxTimer}\label{wxtimerctordef} +\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer} \func{}{wxTimer}{\void} @@ -42,8 +42,6 @@ Default constructor. If you use it to construct the object and don't call \helpref{SetOwner}{wxtimersetowner} later, you must override \helpref{Notify}{wxtimernotify} method to process the notifications. -\membersection{wxTimer::wxTimer}\label{wxtimerwxtimer} - \func{}{wxTimer}{\param{wxEvtHandler *}{owner}, \param{int }{id = -1}} Creates a timer and associates it with {\it owner}. Please see diff --git a/include/wx/generic/dragimgg.h b/include/wx/generic/dragimgg.h index 20f11bb283..53830a504c 100644 --- a/include/wx/generic/dragimgg.h +++ b/include/wx/generic/dragimgg.h @@ -137,6 +137,10 @@ public: // Attributes //////////////////////////////////////////////////////////////////////////// + // For efficiency, tell wxGenericDragImage to use a bitmap that's already + // created (e.g. from last drag) + void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; } + // Operations //////////////////////////////////////////////////////////////////////////// @@ -191,6 +195,14 @@ public: // Override this if you are using a virtual image (drawing your own image) virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const; + // Override this if you wish to draw the window contents to the backing bitmap + // yourself. This can be desirable if you wish to avoid flicker by not having to + // redraw the window itself before dragging in order to be graphic-minus-dragged-objects. + // Instead, paint the drag image's backing bitmap to be correct, and leave the window + // to be updated only when dragging the objects away (thus giving a smoother appearance). + virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC, + const wxRect& sourceRect, const wxRect& destRect) const; + // Erase and redraw simultaneously if possible virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew); @@ -209,6 +221,8 @@ protected: // Stores the window contents while we're dragging the image around wxBitmap m_backingBitmap; + wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap + // (pass to wxGenericDragImage as an efficiency measure) // A temporary bitmap for repairing/redrawing wxBitmap m_repairBitmap; diff --git a/src/common/valgen.cpp b/src/common/valgen.cpp index 0cf2ce6f13..caadd90e80 100644 --- a/src/common/valgen.cpp +++ b/src/common/valgen.cpp @@ -258,11 +258,18 @@ bool wxGenericValidator::TransferToWindow(void) if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) { wxTextCtrl* pControl = (wxTextCtrl*) m_validatorWindow; - if (m_pString) - { - pControl->SetValue(*m_pString) ; - return TRUE; - } + if (m_pString) + { + pControl->SetValue(*m_pString) ; + return TRUE; + } + else if (m_pInt) + { + wxString str; + str.Printf("%d", *m_pInt); + pControl->SetValue(str); + return TRUE; + } } else #if wxUSE_CHECKLISTBOX #ifndef __WIN16__ @@ -474,6 +481,11 @@ bool wxGenericValidator::TransferFromWindow(void) *m_pString = pControl->GetValue() ; return TRUE; } + else if (m_pInt) + { + *m_pInt = atoi(pControl->GetValue()); + return TRUE; + } } else #if wxUSE_CHECKLISTBOX #ifndef __WIN16__ diff --git a/src/generic/dragimgg.cpp b/src/generic/dragimgg.cpp index a3708fa671..37071c5a03 100644 --- a/src/generic/dragimgg.cpp +++ b/src/generic/dragimgg.cpp @@ -83,6 +83,7 @@ void wxGenericDragImage::Init() m_windowDC = (wxDC*) NULL; m_window = (wxWindow*) NULL; m_fullScreen = FALSE; + m_pBackingBitmap = (wxBitmap*) NULL; } // Attributes @@ -244,8 +245,10 @@ bool wxGenericDragImage::BeginDrag(const wxPoint& hotspot, } } - if (!m_backingBitmap.Ok() || (m_backingBitmap.GetWidth() < clientSize.x || m_backingBitmap.GetHeight() < clientSize.y)) - m_backingBitmap = wxBitmap(clientSize.x, clientSize.y); + wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); + + if (!backing->Ok() || (backing->GetWidth() < clientSize.x || backing->GetHeight() < clientSize.y)) + (*backing) = wxBitmap(clientSize.x, clientSize.y); if (!m_fullScreen) m_windowDC = new wxClientDC(window); @@ -343,9 +346,13 @@ bool wxGenericDragImage::Show() // This is where we restore the backing bitmap, in case // something has changed on the window. + wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); wxMemoryDC memDC; - memDC.SelectObject(m_backingBitmap); - memDC.Blit(0, 0, m_boundingRect.width, m_boundingRect.height, m_windowDC, m_boundingRect.x, m_boundingRect.y); + memDC.SelectObject(* backing); + + UpdateBackingFromWindow(* m_windowDC, memDC, m_boundingRect, wxRect(0, 0, m_boundingRect.width, m_boundingRect.height)); + + //memDC.Blit(0, 0, m_boundingRect.width, m_boundingRect.height, m_windowDC, m_boundingRect.x, m_boundingRect.y); memDC.SelectObject(wxNullBitmap); RedrawImage(m_position - m_offset, m_position - m_offset, FALSE, TRUE); @@ -357,6 +364,12 @@ bool wxGenericDragImage::Show() return TRUE; } +bool wxGenericDragImage::UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC, + const wxRect& sourceRect, const wxRect& destRect) const +{ + return destDC.Blit(destRect.x, destRect.y, destRect.width, destRect.height, & windowDC, sourceRect.x, sourceRect.y); +} + bool wxGenericDragImage::Hide() { wxASSERT_MSG( (m_windowDC != (wxDC*) NULL), wxT("No window DC in wxGenericDragImage::Hide()") ); @@ -381,7 +394,8 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos, const wxPoint& newPo if (!m_windowDC) return FALSE; - if (!m_backingBitmap.Ok()) + wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); + if (!backing->Ok()) return FALSE; wxRect oldRect(GetImageRect(oldPos)); @@ -419,7 +433,7 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos, const wxPoint& newPo } wxMemoryDC memDC; - memDC.SelectObject(m_backingBitmap); + memDC.SelectObject(* backing); wxMemoryDC memDCTemp; memDCTemp.SelectObject(m_repairBitmap); diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index 9842ec4ab7..5556d4e24e 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -375,7 +375,9 @@ void wxDialog::DoShowModal() // for a modal dialog that has been destroyed before calling EndModal). if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus)) { - oldFocus->SetFocus(); + // This is likely to prove that the object still exists + if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus) + oldFocus->SetFocus(); } }