+/*
+ * 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& WXUNUSED(event))
+{
+ wxPaintDC dc(this);
+
+ if (!m_treeCtrl)
+ return;
+
+ wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
+ dc.SetPen(pen);
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+ wxFont font(wxSystemSettings::GetFont(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& WXUNUSED(event))
+{
+ // TODO: something more optimized than simply refresh the whole
+ // window when the tree is expanded/collapsed. Tricky.
+ Refresh();
+}
+