Added companion window. Now it's working pretty much as expected except

for the usual flickering...


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8130 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2000-08-18 16:28:38 +00:00
parent f1f2204967
commit 1a584f14bf
4 changed files with 185 additions and 29 deletions

View File

@ -96,10 +96,57 @@ public:
// the height of an item)
void ScrollToLine(int posHoriz, int posVert);
//// Accessors
// The companion window is one which will get notified when certain
// events happen such as node expansion
void SetCompanionWindow(wxWindow* companion) { m_companionWindow = companion; }
wxWindow* GetCompanionWindow() const { return m_companionWindow; }
DECLARE_EVENT_TABLE()
protected:
wxWindow* m_companionWindow;
};
/*
* wxTreeCompanionWindow
*
* A window displaying values associated with tree control items.
*/
class wxTreeCompanionWindow: public wxWindow
{
public:
DECLARE_CLASS(wxTreeCompanionWindow)
wxTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize,
long style = 0);
//// Overrides
virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect);
//// Events
void OnPaint(wxPaintEvent& event);
void OnScroll(wxScrollWinEvent& event);
void OnExpand(wxTreeEvent& event);
//// Operations
//// Accessors
wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; };
void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl) { m_treeCtrl = treeCtrl; }
//// Data members
protected:
wxRemotelyScrolledTreeCtrl* m_treeCtrl;
DECLARE_EVENT_TABLE()
};
/*
* wxThinSplitterWindow
*

View File

@ -123,6 +123,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
m_scrolledWindow->EnableScrolling(FALSE, FALSE);
// Let the two controls know about each other
m_valueWindow->SetTreeCtrl(m_tree);
m_tree->SetCompanionWindow(m_valueWindow);
// set the frame icon
SetIcon(wxICON(mondrian));
@ -239,30 +243,24 @@ void TestTree::OnPaint(wxPaintEvent& event)
dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH);
wxSize clientSize = GetClientSize();
wxRect itemRect;
if (GetBoundingRect(GetRootItem(), itemRect))
int cy=0;
wxTreeItemId h, lastH;
for(h=GetFirstVisibleItem();h;h=GetNextVisible(h))
{
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))
{
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);
cy = itemRect.GetTop();
dc.DrawLine(0, cy, clientSize.x, cy);
lastH = h;
}
}
if (GetBoundingRect(lastH, itemRect))
{
cy = itemRect.GetBottom();
dc.DrawLine(0, cy, clientSize.x, cy);
}
}
/*
@ -271,19 +269,14 @@ void TestTree::OnPaint(wxPaintEvent& event)
//IMPLEMENT_CLASS(TestValueWindow, wxWindow)
BEGIN_EVENT_TABLE(TestValueWindow, wxWindow)
EVT_SIZE(TestValueWindow::OnSize)
BEGIN_EVENT_TABLE(TestValueWindow, wxTreeCompanionWindow)
END_EVENT_TABLE()
TestValueWindow::TestValueWindow(wxWindow* parent, wxWindowID id,
const wxPoint& pos,
const wxSize& sz,
long style):
wxWindow(parent, id, pos, sz, style)
wxTreeCompanionWindow(parent, id, pos, sz, style)
{
SetBackgroundColour(* wxWHITE);
}
void TestValueWindow::OnSize(wxSizeEvent& event)
{
}

View File

@ -84,7 +84,7 @@ protected:
wxImageList* m_imageList;
};
class TestValueWindow: public wxWindow
class TestValueWindow: public wxTreeCompanionWindow
{
public:
TestValueWindow(wxWindow* parent, wxWindowID id = -1,
@ -95,7 +95,6 @@ public:
//// Overrides
//// Events
void OnSize(wxSizeEvent& event);
//// Data members
protected:

View File

@ -64,6 +64,7 @@ wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindo
const wxSize& sz, long style):
wxTreeCtrl(parent, id, pt, sz, style)
{
m_companionWindow = NULL;
}
wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
@ -109,9 +110,10 @@ void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPer
// Get the view start
void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
{
wxScrolledWindow* scrolledWindow = GetScrolledWindow();
if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
{
wxScrolledWindow* scrolledWindow = GetScrolledWindow();
wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
int x1, y1, x2, y2;
@ -123,6 +125,12 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
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.
@ -189,6 +197,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();
// Pass on the event
if (m_companionWindow)
m_companionWindow->GetEventHandler()->ProcessEvent(event);
}
// Adjust the containing wxScrolledWindow's scrollbars appropriately
@ -319,6 +331,111 @@ void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
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());
dc.DrawLine(0, cy, clientSize.x, cy);
lastH = h;
// Draw the actual item
DrawItem(dc, h, drawItemRect);
}
}
if (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)
{
// Don't 'skip' or we'd get into infinite recursion
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
*/