]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/gizmos/splittree.cpp
added timestamping to wxLogStream
[wxWidgets.git] / contrib / src / gizmos / splittree.cpp
index 3c27a32151e67e87ae85dca31d56b96697f4d70c..a99b6733c8198c6c625c0bd191b4a07cb1c3e1d9 100644 (file)
@@ -19,7 +19,7 @@
 // headers
 // ----------------------------------------------------------------------------
 #ifdef __GNUG__
 // headers
 // ----------------------------------------------------------------------------
 #ifdef __GNUG__
-    #pragma interface "splittree.cpp"
+    #pragma implementation "splittree.h"
 #endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
@@ -64,6 +64,7 @@ wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindo
         const wxSize& sz, long style):
         wxTreeCtrl(parent, id, pt, sz, style)
 {
         const wxSize& sz, long style):
         wxTreeCtrl(parent, id, pt, sz, style)
 {
+       m_companionWindow = NULL;
 }
 
 wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
 }
 
 wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
@@ -105,13 +106,34 @@ void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPer
     }
 }
 
     }
 }
 
+// In case we're using the generic tree control.
+int wxRemotelyScrolledTreeCtrl::GetScrollPos(int orient) const
+{
+    wxScrolledWindow* scrolledWindow = GetScrolledWindow();
+
+    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
+    {
+        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
+
+        if (orient == wxHORIZONTAL)
+            return win->wxGenericTreeCtrl::GetScrollPos(orient);
+        else
+        {
+            return scrolledWindow->GetScrollPos(orient);
+        }
+    }
+    return 0;
+}
+
+
 // In case we're using the generic tree control.
 // Get the view start
 void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
 {
 // In case we're using the generic tree control.
 // Get the view start
 void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
 {
+    wxScrolledWindow* scrolledWindow = GetScrolledWindow();
+
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
     if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
     {
-           wxScrolledWindow* scrolledWindow = GetScrolledWindow();
 
         wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
         int x1, y1, x2, y2;
 
         wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
         int x1, y1, x2, y2;
@@ -123,6 +145,12 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
         scrolledWindow->GetViewStart(& x2, & y2);
         * y = y2;
     }
         scrolledWindow->GetViewStart(& x2, & y2);
         * y = y2;
     }
+       else
+       {
+               // x is wrong since the horizontal scrollbar is controlled by the
+               // tree control, but we probably don't need it.
+        scrolledWindow->GetViewStart(x, y);
+       }
 }
 
 // In case we're using the generic tree control.
 }
 
 // In case we're using the generic tree control.
@@ -189,6 +217,10 @@ void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event)
     // If we don't have this, we get some bits of lines still remaining
     if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED)
         Refresh();
     // If we don't have this, we get some bits of lines still remaining
     if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED)
         Refresh();
+
+       // Pass on the event
+       if (m_companionWindow)
+               m_companionWindow->GetEventHandler()->ProcessEvent(event);
 }
 
 // Adjust the containing wxScrolledWindow's scrollbars appropriately
 }
 
 // Adjust the containing wxScrolledWindow's scrollbars appropriately
@@ -265,7 +297,7 @@ void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect)
        CalcTreeSize(GetRootItem(), rect);
 }
 
        CalcTreeSize(GetRootItem(), rect);
 }
 
-void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxTreeItemId& id, wxRect& rect)
+void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect)
 {
        // TODO: implement GetFirst/NextVisibleItem
        // for wxGenericTreeCtrl, plus GetBoundingRect.
 {
        // TODO: implement GetFirst/NextVisibleItem
        // for wxGenericTreeCtrl, plus GetBoundingRect.
@@ -306,7 +338,7 @@ void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
     int orient = event.GetOrientation();
     if (orient == wxHORIZONTAL)
     {
     int orient = event.GetOrientation();
     if (orient == wxHORIZONTAL)
     {
-        // Don't 'skip' or we'd get into infinite recursion
+        event.Skip();
         return;
     }
     wxScrolledWindow* scrollWin = GetScrolledWindow();
         return;
     }
     wxScrolledWindow* scrollWin = GetScrolledWindow();
@@ -319,6 +351,111 @@ void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
     ScrollToLine(-1, y);
 }
 
     ScrollToLine(-1, y);
 }
 
+/*
+ * wxTreeCompanionWindow
+ *
+ * A window displaying values associated with tree control items.
+ */
+
+IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow)
+
+BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow)
+       EVT_PAINT(wxTreeCompanionWindow::OnPaint)
+       EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll)
+       EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand)
+       EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand)
+END_EVENT_TABLE()
+
+wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id,
+      const wxPoint& pos,
+      const wxSize& sz,
+      long style):
+       wxWindow(parent, id, pos, sz, style)
+{
+       m_treeCtrl = NULL;
+}
+
+void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect)
+{
+       // TEST CODE
+#if 1
+       if (m_treeCtrl)
+       {
+               wxString text = m_treeCtrl->GetItemText(id);
+               dc.SetTextForeground(* wxBLACK);
+               dc.SetBackgroundMode(wxTRANSPARENT);
+
+               int textW, textH;
+               dc.GetTextExtent(text, & textW, & textH);
+
+               int x = 5;
+               int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);
+
+               dc.DrawText(text, x, y);
+       }
+#endif
+}
+
+void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event)
+{
+       wxPaintDC dc(this);
+
+    if (!m_treeCtrl)
+        return;
+
+        wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
+       dc.SetPen(pen);
+       dc.SetBrush(* wxTRANSPARENT_BRUSH);
+       wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+       dc.SetFont(font);
+
+    wxSize clientSize = GetClientSize();
+       wxRect itemRect;
+       int cy=0;
+       wxTreeItemId h, lastH;
+       for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h))
+       {
+               if (m_treeCtrl->GetBoundingRect(h, itemRect))
+               {
+                       cy = itemRect.GetTop();
+                       wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
+
+                       lastH = h;
+
+                       // Draw the actual item
+                       DrawItem(dc, h, drawItemRect);
+                       dc.DrawLine(0, cy, clientSize.x, cy);
+               }
+       }
+       if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect))
+       {
+               cy = itemRect.GetBottom();
+               dc.DrawLine(0, cy, clientSize.x, cy);
+       }
+}
+
+void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event)
+{
+    int orient = event.GetOrientation();
+    if (orient == wxHORIZONTAL)
+    {
+        event.Skip();
+        return;
+    }
+    if (!m_treeCtrl)
+        return;
+
+       // TODO: scroll the window physically instead of just refreshing.
+       Refresh(TRUE);
+}
+
+void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event)
+{
+       // TODO: something more optimized than simply refresh the whole
+       // window when the tree is expanded/collapsed. Tricky.
+       Refresh();
+}
+
 /*
  * wxThinSplitterWindow
  */
 /*
  * wxThinSplitterWindow
  */
@@ -448,8 +585,13 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
 
     if (orient == wxHORIZONTAL)
     {
 
     if (orient == wxHORIZONTAL)
     {
+        inOnScroll = FALSE;
+        event.Skip();
+        return;
+#if 0
         int newPos = m_xScrollPosition + nScrollInc;
         SetScrollPos(wxHORIZONTAL, newPos, TRUE );
         int newPos = m_xScrollPosition + nScrollInc;
         SetScrollPos(wxHORIZONTAL, newPos, TRUE );
+#endif
     }
     else
     {
     }
     else
     {