]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented IsVisible and GetFirst/NextVisibleItem for generic tree control
authorJulian Smart <julian@anthemion.co.uk>
Fri, 18 Aug 2000 12:45:21 +0000 (12:45 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Fri, 18 Aug 2000 12:45:21 +0000 (12:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/include/wx/gizmos/splittree.h
contrib/samples/gizmos/splittree/tree.cpp
contrib/samples/gizmos/splittree/tree.h
contrib/src/gizmos/splittree.cpp
docs/latex/book/tex2rtf.ini
include/wx/generic/treectlg.h
src/generic/treectlg.cpp

index 118f0b450eb5352cad67a53140045a8a8e72a100..a6877851db4c07fb6a811b59924b194be1e9d5ff 100644 (file)
@@ -56,7 +56,6 @@ public:
 
 //// Events
        void OnSize(wxSizeEvent& event);
-       void OnPaint(wxPaintEvent& event);
        void OnExpand(wxTreeEvent& event);
     void OnScroll(wxScrollWinEvent& event);
 
index 14687eedf8ab98b58ff24ea513afc0249b63627d..9276e9b423587eb4c4e558509b3a80a8b7cacb05 100644 (file)
@@ -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
  */
index 95f9fbbff015aeb29730b7079b61ef1c71e7994c..07355ad0e90a0215e1b6ab21d9fc02673c9aa325 100644 (file)
@@ -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;
index 6d307776fc96b52857155133ab93f226a410dff6..3c27a32151e67e87ae85dca31d56b96697f4d70c 100644 (file)
@@ -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)))
+       {
+               // 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;
-
-       wxScrolledWindow* scrolledWindow = GetScrolledWindow();
-       if (scrolledWindow)
+       }
+       else
        {
-               wxRect itemRect;
-               if (GetBoundingRect(GetRootItem(), itemRect))
+               // 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();
index e9ad12b4ec7ddaa3bc3b9bc5ce2bf7a74947aafa..d35f4f1bbc05ff78253b6ea1dc5eb30db4930f73 100644 (file)
@@ -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
index 17e4e295ed360c731f209162c84a19f67ee0a0a1..650d518bc312a815fb6af45bf94878fd382248be 100644 (file)
@@ -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);
index 76bf9030ab17a773e8f93d39a57c6b91817ca2dc..4b45a0496c64a56cda4186d0f2dc9ed4fcf90c7a 100644 (file)
@@ -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,19 +946,70 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
                     : wxTreeItemId(siblings[(size_t)(index - 1)]);
 }
 
-wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
+// 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
+{
+  wxTreeItemId id = GetRootItem();
+  if (!id.IsOk())
+    return id;
+
+  do
+  {
+    if (IsVisible(id))
+        return id;
+    id = GetNext(id);
+  } while (id.IsOk());
+
+  return wxTreeItemId();
+}
+
 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;
 }
 
 /* **** */