From 1ed01484e7bcce3d1668b5b76c8bb1beb32e9559 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 18 Aug 2000 12:45:21 +0000 Subject: [PATCH] Implemented IsVisible and GetFirst/NextVisibleItem for generic tree control git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/gizmos/splittree.h | 1 - contrib/samples/gizmos/splittree/tree.cpp | 42 +++++++++ contrib/samples/gizmos/splittree/tree.h | 2 + contrib/src/gizmos/splittree.cpp | 107 +++++++--------------- docs/latex/book/tex2rtf.ini | 2 +- include/wx/generic/treectlg.h | 6 ++ src/generic/treectlg.cpp | 94 +++++++++++++++++-- 7 files changed, 171 insertions(+), 83 deletions(-) diff --git a/contrib/include/wx/gizmos/splittree.h b/contrib/include/wx/gizmos/splittree.h index 118f0b450e..a6877851db 100644 --- a/contrib/include/wx/gizmos/splittree.h +++ b/contrib/include/wx/gizmos/splittree.h @@ -56,7 +56,6 @@ public: //// Events void OnSize(wxSizeEvent& event); - void OnPaint(wxPaintEvent& event); void OnExpand(wxTreeEvent& event); void OnScroll(wxScrollWinEvent& event); diff --git a/contrib/samples/gizmos/splittree/tree.cpp b/contrib/samples/gizmos/splittree/tree.cpp index 14687eedf8..9276e9b423 100644 --- a/contrib/samples/gizmos/splittree/tree.cpp +++ b/contrib/samples/gizmos/splittree/tree.cpp @@ -169,6 +169,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) IMPLEMENT_CLASS(TestTree, wxRemotelyScrolledTreeCtrl) BEGIN_EVENT_TABLE(TestTree, wxRemotelyScrolledTreeCtrl) + EVT_PAINT(TestTree::OnPaint) END_EVENT_TABLE() TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt, @@ -223,6 +224,47 @@ TestTree::~TestTree() delete m_imageList; } +void TestTree::OnPaint(wxPaintEvent& event) +{ + wxPaintDC dc(this); + + wxTreeCtrl::OnPaint(event); + + // Reset the device origin since it may have been set + dc.SetDeviceOrigin(0, 0); + + wxSize sz = GetClientSize(); + + wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + + wxRect itemRect; + if (GetBoundingRect(GetRootItem(), itemRect)) + { + int itemHeight = itemRect.GetHeight(); + wxRect rcClient = GetRect(); + wxRect itemRect; + int cy=0; + wxTreeItemId h, lastH; + for(h=GetFirstVisibleItem();h;h=GetNextVisible(h)) + { + if (GetBoundingRect(h, itemRect)) + { + cy = itemRect.GetTop(); + dc.DrawLine(rcClient.x, cy, rcClient.x + rcClient.width, cy); + lastH = h; + //cy += itemHeight; + } + } + if (GetBoundingRect(lastH, itemRect)) + { + cy = itemRect.GetBottom(); + dc.DrawLine(rcClient.x, cy, rcClient.x + rcClient.width, cy); + } + } +} + /* * TestValueWindow */ diff --git a/contrib/samples/gizmos/splittree/tree.h b/contrib/samples/gizmos/splittree/tree.h index 95f9fbbff0..07355ad0e9 100644 --- a/contrib/samples/gizmos/splittree/tree.h +++ b/contrib/samples/gizmos/splittree/tree.h @@ -77,6 +77,8 @@ public: TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS); ~TestTree(); + + void OnPaint(wxPaintEvent& event); DECLARE_EVENT_TABLE() protected: wxImageList* m_imageList; diff --git a/contrib/src/gizmos/splittree.cpp b/contrib/src/gizmos/splittree.cpp index 6d307776fc..3c27a32151 100644 --- a/contrib/src/gizmos/splittree.cpp +++ b/contrib/src/gizmos/splittree.cpp @@ -55,7 +55,6 @@ BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl) BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxTreeCtrl) #endif EVT_SIZE(wxRemotelyScrolledTreeCtrl::OnSize) - EVT_PAINT(wxRemotelyScrolledTreeCtrl::OnPaint) EVT_TREE_ITEM_EXPANDED(-1, wxRemotelyScrolledTreeCtrl::OnExpand) EVT_TREE_ITEM_COLLAPSED(-1, wxRemotelyScrolledTreeCtrl::OnExpand) EVT_SCROLLWIN(wxRemotelyScrolledTreeCtrl::OnScroll) @@ -195,49 +194,44 @@ void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event) // Adjust the containing wxScrolledWindow's scrollbars appropriately void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars() { - // WILL THIS BE DONE AUTOMATICALLY BY THE GENERIC TREE CONTROL? -/* - -Problem with remote-scrolling the generic tree control. It relies -on PrepareDC for adjusting the device origin, which in turn takes -values from wxScrolledWindow: which we've turned off in order to use -a different scrollbar :-( So we could override PrepareDC and use -the _other_ scrolled window's position instead. -Note also ViewStart would need to be overridden. -Plus, wxGenericTreeCtrl::OnPaint will reset the device origin. - -*/ - - // Assumption: wxGenericTreeCtrl will adjust the scrollbars automatically, - // since it'll call SetScrollbars and we've defined this to Do The Right Thing. if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) - return; - - wxScrolledWindow* scrolledWindow = GetScrolledWindow(); - if (scrolledWindow) { - wxRect itemRect; - if (GetBoundingRect(GetRootItem(), itemRect)) + // This is for the generic tree control. + // It calls SetScrollbars which has been overridden + // to adjust the parent scrolled window vertical + // scrollbar. + ((wxGenericTreeCtrl*) this)->AdjustMyScrollbars(); + return; + } + else + { + // This is for the wxMSW tree control + wxScrolledWindow* scrolledWindow = GetScrolledWindow(); + if (scrolledWindow) { - int itemHeight = itemRect.GetHeight(); - - int w, h; - GetClientSize(&w, &h); - - wxRect rect(0, 0, 0, 0); - CalcTreeSize(rect); - int treeViewHeight = rect.GetHeight()/itemHeight; - - int scrollPixelsPerLine = itemHeight; - int scrollPos = - (itemRect.y / itemHeight); - - scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos); - - // Ensure that when a scrollbar becomes hidden or visible, - // the contained window sizes are right. - // Problem: this is called too early (?) - wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId()); - scrolledWindow->GetEventHandler()->ProcessEvent(event); + wxRect itemRect; + if (GetBoundingRect(GetRootItem(), itemRect)) + { + int itemHeight = itemRect.GetHeight(); + + int w, h; + GetClientSize(&w, &h); + + wxRect rect(0, 0, 0, 0); + CalcTreeSize(rect); + int treeViewHeight = rect.GetHeight()/itemHeight; + + int scrollPixelsPerLine = itemHeight; + int scrollPos = - (itemRect.y / itemHeight); + + scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos); + + // Ensure that when a scrollbar becomes hidden or visible, + // the contained window sizes are right. + // Problem: this is called too early (?) + wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId()); + scrolledWindow->GetEventHandler()->ProcessEvent(event); + } } } } @@ -307,37 +301,6 @@ wxScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const return NULL; } -void wxRemotelyScrolledTreeCtrl::OnPaint(wxPaintEvent& event) -{ - wxPaintDC dc(this); - - wxTreeCtrl::OnPaint(event); - - // Reset the device origin since it may have been set - dc.SetDeviceOrigin(0, 0); - - wxSize sz = GetClientSize(); - - wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); - dc.SetPen(pen); - dc.SetBrush(* wxTRANSPARENT_BRUSH); - - wxRect itemRect; - if (GetBoundingRect(GetRootItem(), itemRect)) - { - int itemHeight = itemRect.GetHeight(); - wxRect rcClient = GetRect(); - int cy=0; - wxTreeItemId h; - for(h=GetFirstVisibleItem();h;h=GetNextVisible(h)) - { - dc.DrawLine(rcClient.x, cy, rcClient.x + rcClient.width, cy); - cy += itemHeight; - } - dc.DrawLine(rcClient.x, cy, rcClient.x + rcClient.width, cy); - } -} - void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event) { int orient = event.GetOrientation(); diff --git a/docs/latex/book/tex2rtf.ini b/docs/latex/book/tex2rtf.ini index e9ad12b4ec..d35f4f1bbc 100644 --- a/docs/latex/book/tex2rtf.ini +++ b/docs/latex/book/tex2rtf.ini @@ -1,8 +1,8 @@ +; Last change: JAC 18 Aug 100 12:58 pm ;;; Tex2RTF initialisation file runTwice = yes titleFontSize = 12 authorFontSize = 10 -authorFontSize = 10 chapterFontSize = 12 sectionFontSize = 12 subsectionFontSize = 12 diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index 17e4e295ed..650d518bc3 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -210,6 +210,10 @@ public: // get the previous visible item: item must be visible itself! wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; + // Only for internal use right now, but should probably be public + wxTreeItemId GetNext(const wxTreeItemId& item) const; + wxTreeItemId GetPrev(const wxTreeItemId& item) const; + // operations // ---------- @@ -371,7 +375,9 @@ protected: int image, int selectedImage, wxTreeItemData *data); +public: void AdjustMyScrollbars(); +protected: int GetLineHeight(wxGenericTreeItem *item) const; void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y ); void PaintItem( wxGenericTreeItem *item, wxDC& dc); diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 76bf9030ab..4b45a0496c 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -803,9 +803,34 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font // item status inquiries // ----------------------------------------------------------------------------- -bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& WXUNUSED(item)) const +bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& item) const { - wxFAIL_MSG(wxT("not implemented")); + wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); + + // An item is only visible if it's not a descendant of a collapsed item + wxGenericTreeItem *pItem = (wxGenericTreeItem*) item.m_pItem; + wxGenericTreeItem* parent = pItem->GetParent(); + while (parent) + { + if (!parent->IsExpanded()) + return FALSE; + parent = parent->GetParent(); + } + + int startX, startY; + GetViewStart(& startX, & startY); + + wxSize clientSize = GetClientSize(); + + wxRect rect; + if (!GetBoundingRect(item, rect)) + return FALSE; + if (rect.GetWidth() == 0 || rect.GetHeight() == 0) + return FALSE; + if (rect.GetBottom() < 0 || rect.GetTop() > clientSize.y) + return FALSE; + if (rect.GetRight() < 0 || rect.GetLeft() > clientSize.x) + return FALSE; return TRUE; } @@ -921,9 +946,54 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const : wxTreeItemId(siblings[(size_t)(index - 1)]); } +// Only for internal use right now, but should probably be public +wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const +{ + wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); + + wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem; + + // First see if there are any children. + wxArrayGenericTreeItems& children = i->GetChildren(); + if (children.GetCount() > 0) + { + return children.Item(0); + } + else + { + // Try a sibling of this or ancestor instead + wxTreeItemId p = item; + wxTreeItemId toFind; + do + { + toFind = GetNextSibling(p); + p = GetParent(p); + } while (p.IsOk() && !toFind.IsOk()); + return toFind; + } +} + +wxTreeItemId wxGenericTreeCtrl::GetPrev(const wxTreeItemId& item) const +{ + wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); + + wxFAIL_MSG(wxT("not implemented")); + + return wxTreeItemId(); +} + wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const { - wxFAIL_MSG(wxT("not implemented")); + wxTreeItemId id = GetRootItem(); + if (!id.IsOk()) + return id; + + do + { + if (IsVisible(id)) + return id; + id = GetNext(id); + } while (id.IsOk()); return wxTreeItemId(); } @@ -932,8 +1002,14 @@ wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const { wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); - wxFAIL_MSG(wxT("not implemented")); + wxTreeItemId id = item; + while (id.IsOk()) + { + id = GetNext(id); + if (id.IsOk() && IsVisible(id)) + return id; + } return wxTreeItemId(); } @@ -2121,13 +2197,13 @@ bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item, int startX, startY; GetViewStart(& startX, & startY); - rect.x = i->GetX() - startX*PIXELS_PER_UNIT; rect.y = i->GetY()*PIXELS_PER_UNIT; - rect.width = i->GetWidth(); rect.height = i->GetHeight(); + rect.x = i->GetX() - startX*PIXELS_PER_UNIT; + rect.y = i->GetY() - startY*PIXELS_PER_UNIT; + rect.width = i->GetWidth(); + //rect.height = i->GetHeight(); + rect.height = GetLineHeight(i); return TRUE; - - // wxFAIL_MSG(wxT("GetBoundingRect unimplemented")); - // return FALSE; } /* **** */