From 17808a759627b03c2acbe7333dd2386557e1b804 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Jan 2008 00:21:31 +0000 Subject: [PATCH] move Freeze() and Thaw() to wxWindowBase to ensure that they behave consistently (i.e. recursively, as described in the docs) in all ports; removed different duplications of freeze count from derived classes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51018 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 6 ++- docs/latex/wx/window.tex | 3 +- include/wx/dfb/window.h | 8 +-- include/wx/generic/listctrl.h | 6 +-- include/wx/generic/treectlg.h | 6 +-- include/wx/gtk/textctrl.h | 13 ++--- include/wx/gtk1/textctrl.h | 9 ++-- include/wx/mac/carbon/window.h | 9 ++-- include/wx/mgl/window.h | 7 +-- include/wx/msw/toplevel.h | 8 +-- include/wx/msw/window.h | 12 ++--- include/wx/os2/window.h | 5 +- include/wx/palmos/window.h | 5 -- include/wx/richtext/richtextctrl.h | 15 +----- include/wx/window.h | 26 ++++++++-- include/wx/x11/textctrl.h | 3 -- src/common/wincmn.cpp | 2 + src/dfb/window.cpp | 19 ++----- src/generic/listctrl.cpp | 34 ++++--------- src/generic/treectlg.cpp | 35 +++++-------- src/gtk/textctrl.cpp | 79 +++++++++++++----------------- src/gtk1/textctrl.cpp | 4 +- src/mac/carbon/window.cpp | 28 +++-------- src/mgl/window.cpp | 11 ++--- src/msw/toplevel.cpp | 65 ++++++++++++------------ src/msw/window.cpp | 28 ++++------- src/os2/window.cpp | 4 +- src/palmos/window.cpp | 8 --- src/richtext/richtextctrl.cpp | 34 +++++-------- src/x11/textctrl.cpp | 12 ----- 30 files changed, 192 insertions(+), 312 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 107f4c271d..bd73790238 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -68,6 +68,10 @@ Changes in behaviour not resulting in compilation errors, please read this! sizes of the sizer items to be in the same proportion as the items proportions to return to the old behaviour. +- wxWindow::Freeze/Thaw() are not virtual any more, if you overrode them in + your code you need to override DoFreeze/Thaw() instead now. + + Changes in behaviour which may result in compilation errors ----------------------------------------------------------- @@ -128,7 +132,7 @@ Changes in behaviour which may result in compilation errors - Removed global GetLine() function from wx/protocol/protocol.h, use wxProtocol::ReadLine() instead. - + - wxVariant no longer derives from wxObject. wxVariantData also no longer derives from wxObject; instead of using wxDynamicCast with wxVariantData you can use the macro wxDynamicCastVariantData with the same arguments. diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 7bda507e7a..cf6e0c3eca 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -728,7 +728,8 @@ subwindows. Freezes the window or, in other words, prevents any updates from taking place on screen, the window is not redrawn at all. \helpref{Thaw}{wxwindowthaw} must be called to reenable window redrawing. Calls to these two functions may be -nested. +nested but to ensure that the window is properly repainted again, you must thaw +it exactly as many times as you froze it. This method is useful for visual appearance optimization (for example, it is a good idea to use it before doing many large text insertions in a row into diff --git a/include/wx/dfb/window.h b/include/wx/dfb/window.h index 684b282a4f..89ee39d46f 100644 --- a/include/wx/dfb/window.h +++ b/include/wx/dfb/window.h @@ -75,9 +75,6 @@ public: virtual void Refresh(bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL); virtual void Update(); - virtual void Freeze(); - virtual void Thaw(); - virtual bool IsFrozen() const { return m_frozenness > 0; } virtual bool SetCursor(const wxCursor &cursor); virtual bool SetFont(const wxFont &font) { m_font = font; return true; } @@ -128,6 +125,8 @@ protected: virtual void DoCaptureMouse(); virtual void DoReleaseMouse(); + virtual void DoThaw(); + // move the window to the specified location and resize it: this is called // from both DoSetSize() and DoSetClientSize() and would usually just call // ::MoveWindow() except for composite controls which will want to arrange @@ -183,9 +182,6 @@ private: // don't access it directly) wxRect m_rect; - // number of calls to Freeze() minus number of calls to Thaw() - unsigned m_frozenness; - // overlays for this window (or NULL if it doesn't have any) wxDfbOverlaysList *m_overlays; diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index 8db983e3c7..1dedb608c6 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -174,9 +174,6 @@ public: virtual void Refresh(bool eraseBackground = true, const wxRect *rect = NULL); - virtual void Freeze(); - virtual void Thaw(); - virtual bool SetBackgroundColour( const wxColour &colour ); virtual bool SetForegroundColour( const wxColour &colour ); virtual wxColour GetBackgroundColour() const; @@ -218,6 +215,9 @@ protected: virtual wxSize DoGetBestSize() const; + virtual void DoFreeze(); + virtual void DoThaw(); + // return the text for the given column of the given item virtual wxString OnGetItemText(long item, long column) const; diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index f57802cf70..c21b331fe6 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -197,8 +197,6 @@ public: virtual bool SetBackgroundColour(const wxColour& colour); virtual bool SetForegroundColour(const wxColour& colour); - virtual void Freeze(); - virtual void Thaw(); virtual void Refresh(bool eraseBackground = true, const wxRect *rect = NULL); virtual bool SetFont( const wxFont &font ); @@ -253,7 +251,6 @@ protected: bool m_lastOnSame; // last click on the same item as prev wxImageList *m_imageListButtons; - int m_freezeCount; int m_dragCount; wxPoint m_dragStart; wxGenericTreeItem *m_dropTarget; @@ -273,6 +270,9 @@ protected: // the common part of all ctors void Init(); + // overridden wxWindow methods + virtual void DoThaw(); + // misc helpers void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted); diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 28554b1f96..19d716fcab 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -121,11 +121,6 @@ public: void SetUpdateFont(bool WXUNUSED(update)) { } - // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to - // avoid horrible flicker/scrolling back and forth - virtual void Freeze(); - virtual void Thaw(); - // implementation only from now on // tell the control to ignore next text changed signal @@ -148,9 +143,6 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - // has the control been frozen by Freeze()? - bool IsFrozen() const { return m_freezeCount > 0; } - protected: // wxGTK-specific: called recursively by Enable, // to give widgets an oppprtunity to correct their colours after they @@ -162,6 +154,9 @@ protected: virtual void DoApplyWidgetStyle(GtkRcStyle *style); virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; + virtual void DoFreeze(); + virtual void DoThaw(); + // common part of all ctors void Init(); @@ -217,8 +212,6 @@ private: // a dummy one when frozen GtkTextBuffer *m_buffer; - // number of calls to Freeze() minus number of calls to Thaw() - unsigned m_freezeCount; GtkTextMark* m_showPositionOnThaw; // For wxTE_AUTO_URL diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index 5abad1b57b..5c7a3ca1bc 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -139,11 +139,6 @@ public: void SetModified() { m_modified = true; } - // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to - // avoid horrible flicker/scrolling back and forth - virtual void Freeze(); - virtual void Thaw(); - // textctrl specific scrolling virtual bool ScrollLines(int lines); virtual bool ScrollPages(int pages); @@ -170,6 +165,10 @@ protected: // common part of all ctors void Init(); + // overridden wxWindow methods + virtual void DoFreeze(); + virtual void DoThaw(); + // get the vertical adjustment, if any, NULL otherwise GtkAdjustment *GetVAdj() const; diff --git a/include/wx/mac/carbon/window.h b/include/wx/mac/carbon/window.h index dfb4e8d059..3410dcb801 100644 --- a/include/wx/mac/carbon/window.h +++ b/include/wx/mac/carbon/window.h @@ -62,9 +62,6 @@ public: virtual void Refresh( bool eraseBackground = true, const wxRect *rect = NULL ); - virtual void Freeze(); - virtual void Thaw(); - virtual bool IsFrozen() const; virtual void Update() ; virtual void ClearBackground(); @@ -86,6 +83,9 @@ protected: virtual void DoEnable( bool enable ); virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); + virtual void DoFreeze(); + virtual void DoThaw(); + public: virtual void SetScrollbar( int orient, int pos, int thumbVisible, int range, bool refresh = true ); @@ -262,9 +262,6 @@ protected: // For controls like radio buttons which are genuinely composite wxList m_subControls; - // number of calls to Freeze() minus number of calls to Thaw() - unsigned int m_frozenness; - // the peer object, allowing for cleaner API support wxMacControl * m_peer ; diff --git a/include/wx/mgl/window.h b/include/wx/mgl/window.h index 4c3091bd4f..738bc927fb 100644 --- a/include/wx/mgl/window.h +++ b/include/wx/mgl/window.h @@ -68,8 +68,6 @@ public: virtual void Refresh(bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL); virtual void Update(); - virtual void Freeze(); - virtual void Thaw(); virtual bool SetCursor(const wxCursor &cursor); virtual bool SetFont(const wxFont &font) { m_font = font; return true; } @@ -100,11 +98,14 @@ public: void OnInternalIdle(); protected: + virtual void DoFreeze(); + virtual void DoThaw(); + + // the window handle struct window_t *m_wnd; // whether there should be wxEraseEvent before wxPaintEvent or not // (see wxWindow::Refresh) - bool m_frozen:1; bool m_refreshAfterThaw:1; int m_eraseBackground; diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index b4f4e0ae03..d3422813f0 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -75,10 +75,6 @@ public: virtual bool SetTransparent(wxByte alpha); virtual bool CanSetTransparent(); - //Top level windows have different freeze semantics on Windows - virtual void Freeze(); - virtual void Thaw(); - virtual void AddChild( wxWindowBase *child ); @@ -142,6 +138,10 @@ protected: virtual void DoGetSize(int *width, int *height) const; #endif // __WXWINCE__ + // Top level windows have different freeze semantics on Windows + virtual void DoFreeze(); + virtual void DoThaw(); + // helper of SetIcons(): calls gets the icon with the size specified by the // given system metrics (SM_C{X|Y}[SM]ICON) from the bundle and sets it // using WM_SETICON with the specified wParam (ICOM_SMALL or ICON_BIG) diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index dd35d7fd88..4238868df3 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -83,9 +83,6 @@ public: virtual void Refresh( bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL ); virtual void Update(); - virtual void Freeze(); - virtual void Thaw(); - virtual bool IsFrozen() const { return m_frozenness > 0; } virtual void SetWindowStyleFlag(long style); virtual void SetExtraStyle(long exStyle); @@ -503,6 +500,9 @@ protected: virtual void DoEnable(bool enable); + virtual void DoFreeze(); + virtual void DoThaw(); + // this simply moves/resizes the given HWND which is supposed to be our // sibling (this is useful for controls which are composite at MSW level // and for which DoMoveWindow() is not enough) @@ -555,8 +555,6 @@ private: bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); - - // current defer window position operation handle (may be NULL) WXHANDLE m_hDWP; @@ -567,10 +565,6 @@ protected: wxPoint m_pendingPosition; wxSize m_pendingSize; - // number of calls to Freeze() minus number of calls to Thaw() - // protected so that wxTopLevelWindowMSW can access it - unsigned int m_frozenness; - private: #ifdef __POCKETPC__ bool m_contextMenuEnabled; diff --git a/include/wx/os2/window.h b/include/wx/os2/window.h index 9070497a44..9765a809fa 100644 --- a/include/wx/os2/window.h +++ b/include/wx/os2/window.h @@ -92,9 +92,7 @@ public: virtual void Refresh( bool bEraseBackground = true ,const wxRect* pRect = (const wxRect *)NULL ); - virtual void Freeze(void); virtual void Update(void); - virtual void Thaw(void); virtual void SetWindowStyleFlag(long lStyle); virtual bool SetCursor(const wxCursor& rCursor); virtual bool SetFont(const wxFont& rFont); @@ -416,6 +414,9 @@ public: PSWP GetSwp(void) {return &m_vWinSwp;} protected: + virtual void DoFreeze(void); + virtual void DoThaw(void); + // PM can't create some MSW styles natively but can perform these after // creation by sending messages typedef enum extra_flags { kFrameToolWindow = 0x0001 diff --git a/include/wx/palmos/window.h b/include/wx/palmos/window.h index aeb2a5f9a9..25965867b9 100644 --- a/include/wx/palmos/window.h +++ b/include/wx/palmos/window.h @@ -73,8 +73,6 @@ public: virtual void Refresh( bool eraseBackground = true, const wxRect *rect = NULL ); virtual void Update(); - virtual void Freeze(); - virtual void Thaw(); virtual bool SetCursor( const wxCursor &cursor ); virtual bool SetFont( const wxFont &font ); @@ -271,9 +269,6 @@ private: bool HandleMoving(wxRect& rect); bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); - // number of calls to Freeze() minus number of calls to Thaw() - unsigned int m_frozenness; - DECLARE_DYNAMIC_CLASS(wxWindowPalm) DECLARE_NO_COPY_CLASS(wxWindowPalm) DECLARE_EVENT_TABLE() diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index bd07bee8bf..416a53413e 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -263,15 +263,6 @@ public: virtual void SelectAll(); virtual void SetEditable(bool editable); - /// Call Freeze to prevent refresh - virtual void Freeze(); - - /// Call Thaw to refresh - virtual void Thaw(); - - /// Call Thaw to refresh - virtual bool IsFrozen() const { return m_freezeCount > 0; } - virtual bool HasSelection() const; ///// Functionality specific to wxRichTextCtrl @@ -772,13 +763,11 @@ protected: virtual void DoSetValue(const wxString& value, int flags = 0); + virtual void DoThaw(); + // Data members private: - - /// Allows nested Freeze/Thaw - int m_freezeCount; - #if wxRICHTEXT_BUFFERED_PAINTING /// Buffer bitmap wxBitmap m_bufferBitmap; diff --git a/include/wx/window.h b/include/wx/window.h index 6bc220b4d3..4f5388aaa9 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -858,13 +858,19 @@ public: virtual void ClearBackground(); // freeze the window: don't redraw it until it is thawed - virtual void Freeze() { } + void Freeze() { if ( !m_freezeCount++ ) DoFreeze(); } // thaw the window: redraw it after it had been frozen - virtual void Thaw() { } + void Thaw() + { + wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" ); + + if ( !--m_freezeCount ) + DoThaw(); + } // return true if window had been frozen and not unthawed yet - virtual bool IsFrozen() const { return false; } + bool IsFrozen() const { return m_freezeCount != 0; } // adjust DC for drawing on this window virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } @@ -1563,6 +1569,12 @@ protected: // implements the window variants virtual void DoSetWindowVariant( wxWindowVariant variant ) ; + + // really freeze/thaw the window (should have port-specific implementation) + virtual void DoFreeze() { } + virtual void DoThaw() { } + + // Must be called when mouse capture is lost to send // wxMouseCaptureLostEvent to windows on capture stack. static void NotifyCaptureLost(); @@ -1583,11 +1595,19 @@ private: // the stack of windows which have captured the mouse static struct WXDLLIMPEXP_FWD_CORE wxWindowNext *ms_winCaptureNext; + // the window that currently has mouse capture static wxWindow *ms_winCaptureCurrent; + // indicates if execution is inside CaptureMouse/ReleaseMouse static bool ms_winCaptureChanging; + + // number of Freeze() calls minus the number of Thaw() calls: we're frozen + // (i.e. not being updated) if it is positive + unsigned int m_freezeCount; + + DECLARE_ABSTRACT_CLASS(wxWindowBase) DECLARE_NO_COPY_CLASS(wxWindowBase) DECLARE_EVENT_TABLE() diff --git a/include/wx/x11/textctrl.h b/include/wx/x11/textctrl.h index c0c750baa1..920af63cec 100644 --- a/include/wx/x11/textctrl.h +++ b/include/wx/x11/textctrl.h @@ -205,9 +205,6 @@ public: void SetModified() { m_modified = true; } - virtual void Freeze(); - virtual void Thaw(); - // textctrl specific scrolling virtual bool ScrollLines(int lines); virtual bool ScrollPages(int pages); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index ffb3ad473e..393f781207 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -212,6 +212,8 @@ wxWindowBase::wxWindowBase() // VZ: this one shouldn't exist... m_isBeingDeleted = false; + + m_freezeCount = 0; } // common part of window creation process diff --git a/src/dfb/window.cpp b/src/dfb/window.cpp index d30298757a..a4ad6529e6 100644 --- a/src/dfb/window.cpp +++ b/src/dfb/window.cpp @@ -79,7 +79,6 @@ END_EVENT_TABLE() void wxWindowDFB::Init() { m_isShown = true; - m_frozenness = 0; m_tlw = NULL; m_overlays = NULL; } @@ -638,20 +637,10 @@ void wxWindowDFB::Update() GetParent()->Update(); } -void wxWindowDFB::Freeze() +void wxWindowDFB::DoThaw() { - m_frozenness++; -} - -void wxWindowDFB::Thaw() -{ - wxASSERT_MSG( IsFrozen(), "Thaw() without matching Freeze()" ); - - if ( --m_frozenness == 0 ) - { - if ( IsShown() ) - DoRefreshWindow(); - } + if ( IsShown() ) + DoRefreshWindow(); } void wxWindowDFB::PaintWindow(const wxRect& rect) @@ -1080,7 +1069,7 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt) return wxFindWindowAtPoint(pt = wxGetMousePosition()); } -wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +wxWindow* wxFindWindowAtPoint(const wxPoint& WXUNUSED(pt)) { wxFAIL_MSG( "wxFindWindowAtPoint not implemented" ); return NULL; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 3bb512deb5..3243cf941a 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -600,9 +600,9 @@ public: SetFocusIgnoringChildren(); } - // suspend/resume redrawing the control - void Freeze(); - void Thaw(); + // we don't draw anything while we're frozen so we must refresh ourselves + // when we're thawed to make sure the changes are displayed correctly + virtual void DoThaw() { Refresh(); } void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); @@ -850,9 +850,6 @@ private: wxBrush *m_highlightBrush, *m_highlightUnfocusedBrush; - // if this is > 0, the control is frozen and doesn't redraw itself - size_t m_freezeCount; - // wrapper around the text control currently used for in place editing or // NULL if no item is being edited wxListTextCtrlWrapper *m_textctrlWrapper; @@ -2283,8 +2280,6 @@ void wxListMainWindow::Init() m_lineLastClicked = m_lineSelectSingleOnUp = m_lineBeforeLastClicked = (size_t)-1; - - m_freezeCount = 0; } wxListMainWindow::wxListMainWindow() @@ -2703,32 +2698,23 @@ void wxListMainWindow::RefreshSelected() } } -void wxListMainWindow::Freeze() -{ - m_freezeCount++; -} - -void wxListMainWindow::Thaw() -{ - wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); - - if ( --m_freezeCount == 0 ) - Refresh(); -} - void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { // Note: a wxPaintDC must be constructed even if no drawing is // done (a Windows requirement). wxPaintDC dc( this ); - if ( IsEmpty() || m_freezeCount ) + if ( IsEmpty() || IsFrozen() ) + { // nothing to draw or not the moment to draw it return; + } if ( m_dirty ) + { // delay the repainting until we calculate all the items positions return; + } PrepareDC( dc ); @@ -5920,12 +5906,12 @@ void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect) } } -void wxGenericListCtrl::Freeze() +void wxGenericListCtrl::DoFreeze() { m_mainWin->Freeze(); } -void wxGenericListCtrl::Thaw() +void wxGenericListCtrl::DoThaw() { m_mainWin->Thaw(); } diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index f4f6800fa7..88c3f6c713 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -782,7 +782,6 @@ void wxGenericTreeCtrl::Init() m_textCtrl = NULL; m_renameTimer = NULL; - m_freezeCount = 0; m_findTimer = NULL; @@ -1646,7 +1645,7 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) } item->Expand(); - if ( !m_freezeCount ) + if ( !IsFrozen() ) { CalculatePositions(); @@ -3517,13 +3516,13 @@ void wxGenericTreeCtrl::CalculatePositions() void wxGenericTreeCtrl::Refresh(bool eraseBackground, const wxRect *rect) { - if ( !m_freezeCount ) + if ( !IsFrozen() ) wxTreeCtrlBase::Refresh(eraseBackground, rect); } void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem *item) { - if (m_dirty || m_freezeCount) + if (m_dirty || IsFrozen() ) return; wxSize client = GetClientSize(); @@ -3540,7 +3539,7 @@ void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem *item) void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item ) { - if (m_dirty || m_freezeCount) + if (m_dirty || IsFrozen() ) return; wxRect rect; @@ -3553,7 +3552,7 @@ void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item ) void wxGenericTreeCtrl::RefreshSelected() { - if (m_freezeCount) + if (IsFrozen()) return; // TODO: this is awfully inefficient, we should keep the list of all @@ -3564,7 +3563,7 @@ void wxGenericTreeCtrl::RefreshSelected() void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem *item) { - if (m_freezeCount) + if (IsFrozen()) return; if ( item->IsSelected() ) @@ -3578,22 +3577,12 @@ void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem *item) } } -void wxGenericTreeCtrl::Freeze() +void wxGenericTreeCtrl::DoThaw() { - m_freezeCount++; -} - -void wxGenericTreeCtrl::Thaw() -{ - wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen tree control?") ); - - if ( --m_freezeCount == 0 ) - { - if ( m_dirty ) - DoDirtyProcessing(); - else - Refresh(); - } + if ( m_dirty ) + DoDirtyProcessing(); + else + Refresh(); } // ---------------------------------------------------------------------------- @@ -3654,7 +3643,7 @@ wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) void wxGenericTreeCtrl::DoDirtyProcessing() { - if (m_freezeCount) + if (IsFrozen()) return; m_dirty = false; diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 8fc7205172..4d122f9757 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -614,7 +614,6 @@ void wxTextCtrl::Init() SetUpdateFont(false); m_text = NULL; - m_freezeCount = 0; m_showPositionOnThaw = NULL; m_gdkHandCursor = NULL; m_gdkXTermCursor = NULL; @@ -1719,58 +1718,50 @@ wxSize wxTextCtrl::DoGetBestSize() const // freeze/thaw // ---------------------------------------------------------------------------- -void wxTextCtrl::Freeze() +void wxTextCtrl::DoFreeze() { wxCHECK_RET(m_text != NULL, wxT("invalid text ctrl")); if ( HasFlag(wxTE_MULTILINE) ) { - if (m_freezeCount++ == 0) - { - // freeze textview updates and remove buffer - g_signal_connect (m_text, "expose_event", - G_CALLBACK (gtk_text_exposed_callback), this); - g_signal_connect (m_widget, "expose_event", - G_CALLBACK (gtk_text_exposed_callback), this); - gtk_widget_set_sensitive(m_widget, false); - g_object_ref(m_buffer); - GtkTextBuffer* buf_new = gtk_text_buffer_new(NULL); - GtkTextMark* mark = GTK_TEXT_VIEW(m_text)->first_para_mark; - gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), buf_new); - // gtk_text_view_set_buffer adds its own reference - g_object_unref(buf_new); - // This mark should be deleted when the buffer is changed, - // but it's not (in GTK+ up to at least 2.10.6). - // Otherwise these anonymous marks start to build up in the buffer, - // and Freeze takes longer and longer each time it is called. - if (GTK_IS_TEXT_MARK(mark) && !gtk_text_mark_get_deleted(mark)) - gtk_text_buffer_delete_mark(m_buffer, mark); - } - } -} - -void wxTextCtrl::Thaw() + // freeze textview updates and remove buffer + g_signal_connect (m_text, "expose_event", + G_CALLBACK (gtk_text_exposed_callback), this); + g_signal_connect (m_widget, "expose_event", + G_CALLBACK (gtk_text_exposed_callback), this); + gtk_widget_set_sensitive(m_widget, false); + g_object_ref(m_buffer); + GtkTextBuffer* buf_new = gtk_text_buffer_new(NULL); + GtkTextMark* mark = GTK_TEXT_VIEW(m_text)->first_para_mark; + gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), buf_new); + // gtk_text_view_set_buffer adds its own reference + g_object_unref(buf_new); + // This mark should be deleted when the buffer is changed, + // but it's not (in GTK+ up to at least 2.10.6). + // Otherwise these anonymous marks start to build up in the buffer, + // and Freeze takes longer and longer each time it is called. + if (GTK_IS_TEXT_MARK(mark) && !gtk_text_mark_get_deleted(mark)) + gtk_text_buffer_delete_mark(m_buffer, mark); + } +} + +void wxTextCtrl::DoThaw() { if ( HasFlag(wxTE_MULTILINE) ) { - wxCHECK_RET(m_freezeCount != 0, _T("Thaw() without matching Freeze()")); - - if (--m_freezeCount == 0) + // Reattach buffer and thaw textview updates + gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer); + g_object_unref(m_buffer); + gtk_widget_set_sensitive(m_widget, true); + g_signal_handlers_disconnect_by_func (m_widget, + (gpointer) gtk_text_exposed_callback, this); + g_signal_handlers_disconnect_by_func (m_text, + (gpointer) gtk_text_exposed_callback, this); + if (m_showPositionOnThaw != NULL) { - // Reattach buffer and thaw textview updates - gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer); - g_object_unref(m_buffer); - gtk_widget_set_sensitive(m_widget, true); - g_signal_handlers_disconnect_by_func (m_widget, - (gpointer) gtk_text_exposed_callback, this); - g_signal_handlers_disconnect_by_func (m_text, - (gpointer) gtk_text_exposed_callback, this); - if (m_showPositionOnThaw != NULL) - { - gtk_text_view_scroll_mark_onscreen( - GTK_TEXT_VIEW(m_text), m_showPositionOnThaw); - m_showPositionOnThaw = NULL; - } + gtk_text_view_scroll_mark_onscreen( + GTK_TEXT_VIEW(m_text), m_showPositionOnThaw); + m_showPositionOnThaw = NULL; } } } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 1df0a5b8b1..ea289a657e 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -1290,7 +1290,7 @@ wxSize wxTextCtrl::DoGetBestSize() const // freeze/thaw // ---------------------------------------------------------------------------- -void wxTextCtrl::Freeze() +void wxTextCtrl::DoFreeze() { if ( HasFlag(wxTE_MULTILINE) ) { @@ -1298,7 +1298,7 @@ void wxTextCtrl::Freeze() } } -void wxTextCtrl::Thaw() +void wxTextCtrl::DoThaw() { if ( HasFlag(wxTE_MULTILINE) ) { diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 565c2b38a7..abf913ca76 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -865,7 +865,6 @@ wxWindowMac::wxWindowMac(wxWindowMac *parent, void wxWindowMac::Init() { m_peer = NULL ; - m_frozenness = 0 ; m_macAlpha = 255 ; m_cgContextRef = NULL ; @@ -2091,38 +2090,25 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) } } -void wxWindowMac::Freeze() +void wxWindowMac::DoFreeze() { #if TARGET_API_MAC_OSX - if ( !m_frozenness++ ) - { - if ( m_peer && m_peer->Ok() ) - m_peer->SetDrawingEnabled( false ) ; - } + if ( m_peer && m_peer->Ok() ) + m_peer->SetDrawingEnabled( false ) ; #endif } -void wxWindowMac::Thaw() +void wxWindowMac::DoThaw() { #if TARGET_API_MAC_OSX - wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") ); - - if ( !--m_frozenness ) + if ( m_peer && m_peer->Ok() ) { - if ( m_peer && m_peer->Ok() ) - { - m_peer->SetDrawingEnabled( true ) ; - m_peer->InvalidateWithChildren() ; - } + m_peer->SetDrawingEnabled( true ) ; + m_peer->InvalidateWithChildren() ; } #endif } -bool wxWindowMac::IsFrozen() const -{ - return m_frozenness != 0; -} - wxWindowMac *wxGetActiveWindow() { // actually this is a windows-only concept diff --git a/src/mgl/window.cpp b/src/mgl/window.cpp index 587ed4cd58..5ad62e94e3 100644 --- a/src/mgl/window.cpp +++ b/src/mgl/window.cpp @@ -550,7 +550,6 @@ void wxWindowMGL::Init() // mgl specific: m_wnd = NULL; m_isShown = true; - m_frozen = false; m_paintMGLDC = NULL; m_eraseBackground = -1; } @@ -1119,26 +1118,24 @@ void wxWindowMGL::Refresh(bool eraseBack, const wxRect *rect) void wxWindowMGL::Update() { - if ( !m_frozen ) + if ( !IsFrozen() ) MGL_wmUpdateDC(g_winMng); } -void wxWindowMGL::Freeze() +void wxWindowMGL::DoFreeze() { - m_frozen = true; m_refreshAfterThaw = false; } -void wxWindowMGL::Thaw() +void wxWindowMGL::DoThaw() { - m_frozen = false; if ( m_refreshAfterThaw ) Refresh(); } void wxWindowMGL::HandlePaint(MGLDevCtx *dc) { - if ( m_frozen ) + if ( IsFrozen() ) { // Don't paint anything if the window is frozen. m_refreshAfterThaw = true; diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index a7217b5c91..8a22cb54a1 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -1172,55 +1172,50 @@ bool wxTopLevelWindowMSW::CanSetTransparent() } -void wxTopLevelWindowMSW::Freeze() +void wxTopLevelWindowMSW::DoFreeze() { - if ( !m_frozenness++) { - if (IsShown()) { - for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - node; - node = node->GetNext() ) - { - wxWindow *child = node->GetData(); - if ( child->IsTopLevel() ) - continue; - else - child->Freeze(); - } + if ( IsShown() ) + { + for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *child = node->GetData(); + if ( child->IsTopLevel() ) + continue; + + child->Freeze(); } } } -void wxTopLevelWindowMSW::Thaw() +void wxTopLevelWindowMSW::DoThaw() { - wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); - if ( --m_frozenness == 0 ) + if ( IsShown() ) { - if ( IsShown() ) { - for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - node; - node = node->GetNext() ) - { - wxWindow *child = node->GetData(); - if ( child->IsTopLevel() ) - continue; - else - child->Thaw(); - } + for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *child = node->GetData(); + if ( child->IsTopLevel() ) + continue; + + child->Thaw(); } } } -void wxTopLevelWindowMSW::AddChild(wxWindowBase *child ) +void wxTopLevelWindowMSW::AddChild(wxWindowBase *child) { - //adding a child while frozen will assert when thawn, - // so freeze it - if (child && !child->IsTopLevel() && IsFrozen()) { - //need to match our current freeze level - for (unsigned int ii=0;ii< m_frozenness;ii++) { - child->Freeze(); - } + // adding a child while frozen will assert when thawn, so freeze it as if + // it had been already present when we were frozen + if ( child && !child->IsTopLevel() && IsFrozen() ) + { + child->Freeze(); } + wxTopLevelWindowBase::AddChild(child); } diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 3c6e6acc6b..4e82274435 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -524,8 +524,6 @@ void wxWindowMSW::Init() m_mouseInWindow = false; m_lastKeydownProcessed = false; - m_frozenness = 0; - m_hWnd = 0; m_hDWP = 0; @@ -1606,29 +1604,21 @@ static inline void SendSetRedraw(HWND hwnd, bool on) #endif } -void wxWindowMSW::Freeze() +void wxWindowMSW::DoFreeze() { - if ( !m_frozenness++ ) - { - if ( IsShown() ) - SendSetRedraw(GetHwnd(), false); - } + if ( IsShown() ) + SendSetRedraw(GetHwnd(), false); } -void wxWindowMSW::Thaw() +void wxWindowMSW::DoThaw() { - wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); - - if ( --m_frozenness == 0 ) + if ( IsShown() ) { - if ( IsShown() ) - { - SendSetRedraw(GetHwnd(), true); + SendSetRedraw(GetHwnd(), true); - // we need to refresh everything or otherwise the invalidated area - // is not going to be repainted - Refresh(); - } + // we need to refresh everything or otherwise the invalidated area + // is not going to be repainted + Refresh(); } } diff --git a/src/os2/window.cpp b/src/os2/window.cpp index c1ec1c18f6..f5c84cb939 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -1109,12 +1109,12 @@ void wxWindowOS2::Update() ::WinUpdateWindow(GetHwnd()); } // end of wxWindowOS2::Update -void wxWindowOS2::Freeze() +void wxWindowOS2::DoFreeze() { ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0); } // end of wxWindowOS2::Freeze -void wxWindowOS2::Thaw() +void wxWindowOS2::DoThaw() { ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0); diff --git a/src/palmos/window.cpp b/src/palmos/window.cpp index 75ddf0bc24..9dd143a633 100644 --- a/src/palmos/window.cpp +++ b/src/palmos/window.cpp @@ -432,14 +432,6 @@ bool wxWindowPalm::Reparent(wxWindowBase *parent) return false; } -void wxWindowPalm::Freeze() -{ -} - -void wxWindowPalm::Thaw() -{ -} - void wxWindowPalm::Refresh(bool eraseBack, const wxRect *rect) { WinHandle handle = (WinHandle)GetHWND(); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 62acf0a2fa..6acea71f6c 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -201,7 +201,6 @@ wxRichTextCtrl::~wxRichTextCtrl() /// Member initialisation void wxRichTextCtrl::Init() { - m_freezeCount = 0; m_contextMenu = NULL; m_caret = NULL; m_caretPosition = -1; @@ -217,25 +216,13 @@ void wxRichTextCtrl::Init() m_caretPositionForDefaultStyle = -2; } -/// Call Freeze to prevent refresh -void wxRichTextCtrl::Freeze() +void wxRichTextCtrl::DoThaw() { - m_freezeCount ++; -} - -/// Call Thaw to refresh -void wxRichTextCtrl::Thaw() -{ - m_freezeCount --; - - if (m_freezeCount == 0) - { - if (GetBuffer().GetDirty()) - LayoutContent(); - else - SetupScrollbars(); - Refresh(false); - } + if (GetBuffer().GetDirty()) + LayoutContent(); + else + SetupScrollbars(); + Refresh(false); } /// Clear all text @@ -248,7 +235,7 @@ void wxRichTextCtrl::Clear() m_caretAtLineStart = false; m_selectionRange.SetRange(-2, -2); - if (m_freezeCount == 0) + if (!IsFrozen()) { LayoutContent(); Refresh(false); @@ -269,11 +256,12 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) #else wxPaintDC dc(this); #endif - PrepareDC(dc); - if (m_freezeCount > 0) + if (IsFrozen()) return; + PrepareDC(dc); + dc.SetFont(GetFont()); // Paint the background @@ -1789,7 +1777,7 @@ void wxRichTextCtrl::OnScroll(wxScrollWinEvent& event) /// Set up scrollbars, e.g. after a resize void wxRichTextCtrl::SetupScrollbars(bool atTop) { - if (m_freezeCount) + if (IsFrozen()) return; if (GetBuffer().IsEmpty()) diff --git a/src/x11/textctrl.cpp b/src/x11/textctrl.cpp index ffb7b41301..9cb8938945 100644 --- a/src/x11/textctrl.cpp +++ b/src/x11/textctrl.cpp @@ -2375,18 +2375,6 @@ wxSize wxTextCtrl::DoGetBestSize() const } } -// ---------------------------------------------------------------------------- -// freeze/thaw -// ---------------------------------------------------------------------------- - -void wxTextCtrl::Freeze() -{ -} - -void wxTextCtrl::Thaw() -{ -} - void wxTextCtrl::OnSetFocus( wxFocusEvent& event ) { // To hide or show caret, as appropriate -- 2.45.2