Change wxMSW wxTreeCtrl::DoFreeze() to not hide the tree any more.

Hiding the tree when it's frozen, as done in r72665, results in its own
problems, e.g. loss of focus. So don't do this but resize the control to a
very small size when freezing it and restore it to its old size afterwards.

Closes #15166.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74072 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-05-31 23:21:36 +00:00
parent 926df8a162
commit 4e1e8dc51b
4 changed files with 50 additions and 8 deletions

View File

@@ -216,6 +216,10 @@ protected:
virtual void DoFreeze(); virtual void DoFreeze();
virtual void DoThaw(); virtual void DoThaw();
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
// SetImageList helper // SetImageList helper
void SetAnyImageList(wxImageList *imageList, int which); void SetAnyImageList(wxImageList *imageList, int which);
@@ -336,6 +340,9 @@ private:
// whether we need to deselect other items on mouse up // whether we need to deselect other items on mouse up
bool m_mouseUpDeselect; bool m_mouseUpDeselect;
// The size to restore the control to when it is thawed, see DoThaw().
wxSize m_thawnSize;
friend class wxTreeItemIndirectData; friend class wxTreeItemIndirectData;
friend class wxTreeSortHelper; friend class wxTreeSortHelper;

View File

@@ -30,6 +30,7 @@
#include "wx/treectrl.h" #include "wx/treectrl.h"
#include "wx/math.h" #include "wx/math.h"
#include "wx/renderer.h" #include "wx/renderer.h"
#include "wx/wupdlock.h"
#ifdef __WIN32__ #ifdef __WIN32__
// this is not supported by native control // this is not supported by native control
@@ -122,6 +123,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
MENU_LINK(EnsureVisible) MENU_LINK(EnsureVisible)
MENU_LINK(SetFocus) MENU_LINK(SetFocus)
MENU_LINK(AddItem) MENU_LINK(AddItem)
MENU_LINK(AddManyItems)
MENU_LINK(InsertItem) MENU_LINK(InsertItem)
MENU_LINK(IncIndent) MENU_LINK(IncIndent)
MENU_LINK(DecIndent) MENU_LINK(DecIndent)
@@ -264,6 +266,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
tree_menu->Append(TreeTest_CollapseAndReset, wxT("C&ollapse and reset")); tree_menu->Append(TreeTest_CollapseAndReset, wxT("C&ollapse and reset"));
tree_menu->AppendSeparator(); tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_AddItem, wxT("Append a &new item")); tree_menu->Append(TreeTest_AddItem, wxT("Append a &new item"));
tree_menu->Append(TreeTest_AddManyItems, wxT("Appends &many items"));
tree_menu->Append(TreeTest_InsertItem, wxT("&Insert a new item")); tree_menu->Append(TreeTest_InsertItem, wxT("&Insert a new item"));
tree_menu->Append(TreeTest_Delete, wxT("&Delete this item")); tree_menu->Append(TreeTest_Delete, wxT("&Delete this item"));
tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children")); tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
@@ -782,6 +785,17 @@ void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
MyTreeCtrl::TreeCtrlIcon_File */ ); MyTreeCtrl::TreeCtrlIcon_File */ );
} }
void MyFrame::OnAddManyItems(wxCommandEvent& WXUNUSED(event))
{
wxWindowUpdateLocker lockUpdates(this);
const wxTreeItemId root = m_treeCtrl->GetRootItem();
for ( int n = 0; n < 1000; n++ )
{
m_treeCtrl->AppendItem(root, wxString::Format("Item #%03d", n));
}
}
void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
{ {
unsigned int indent = m_treeCtrl->GetIndent(); unsigned int indent = m_treeCtrl->GetIndent();

View File

@@ -242,6 +242,7 @@ public:
void OnSortRev(wxCommandEvent& WXUNUSED(event)) { DoSort(true); } void OnSortRev(wxCommandEvent& WXUNUSED(event)) { DoSort(true); }
void OnAddItem(wxCommandEvent& event); void OnAddItem(wxCommandEvent& event);
void OnAddManyItems(wxCommandEvent& event);
void OnInsertItem(wxCommandEvent& event); void OnInsertItem(wxCommandEvent& event);
void OnIncIndent(wxCommandEvent& event); void OnIncIndent(wxCommandEvent& event);
@@ -350,6 +351,7 @@ enum
TreeTest_EnsureVisible, TreeTest_EnsureVisible,
TreeTest_SetFocus, TreeTest_SetFocus,
TreeTest_AddItem, TreeTest_AddItem,
TreeTest_AddManyItems,
TreeTest_InsertItem, TreeTest_InsertItem,
TreeTest_IncIndent, TreeTest_IncIndent,
TreeTest_DecIndent, TreeTest_DecIndent,

View File

@@ -3932,23 +3932,42 @@ void wxTreeCtrl::DoSetItemState(const wxTreeItemId& item, int state)
// doesn't seem to do anything in other ones (e.g. under Windows 7 the tree // doesn't seem to do anything in other ones (e.g. under Windows 7 the tree
// control keeps updating its scrollbars while the items are added to it, // control keeps updating its scrollbars while the items are added to it,
// resulting in horrible flicker when adding even a couple of dozen items). // resulting in horrible flicker when adding even a couple of dozen items).
// So we hide it instead of freezing -- this still flickers, but actually not // So we resize it to the smallest possible size instead of freezing -- this
// as badly as it would if we didn't do it. // still flickers, but actually not as badly as it would if we didn't do it.
void wxTreeCtrl::DoFreeze() void wxTreeCtrl::DoFreeze()
{ {
// Notice that we don't call wxWindow::Hide() here as we want the window to
// remain shown from wxWidgets point of view and also because
// wxWindowMSW::Show() calls Do{Freeze,Thaw}() itself, so we'd get into
// infinite recursion this way.
if ( IsShown() ) if ( IsShown() )
::ShowWindow(GetHwnd(), SW_HIDE); {
RECT rc;
::GetWindowRect(GetHwnd(), &rc);
m_thawnSize = wxRectFromRECT(rc).GetSize();
::SetWindowPos(GetHwnd(), 0, 0, 0, 1, 1,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
}
} }
void wxTreeCtrl::DoThaw() void wxTreeCtrl::DoThaw()
{ {
if ( IsShown() ) if ( IsShown() )
::ShowWindow(GetHwnd(), SW_SHOW); {
if ( m_thawnSize != wxDefaultSize )
{
::SetWindowPos(GetHwnd(), 0, 0, 0, m_thawnSize.x, m_thawnSize.y,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
}
}
// We also need to override DoSetSize() to ensure that m_thawnSize is reset if
// the window is resized while being frozen -- in this case, we need to avoid
// resizing it back to its original, pre-freeze, size when it's thawed.
void wxTreeCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
m_thawnSize = wxDefaultSize;
wxTreeCtrlBase::DoSetSize(x, y, width, height, sizeFlags);
} }
#endif // wxUSE_TREECTRL #endif // wxUSE_TREECTRL