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
This commit is contained in:
Julian Smart 2000-08-18 12:45:21 +00:00
parent f409b413be
commit 1ed01484e7
7 changed files with 171 additions and 83 deletions

View File

@ -56,7 +56,6 @@ public:
//// Events
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnExpand(wxTreeEvent& event);
void OnScroll(wxScrollWinEvent& event);

View 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
*/

View 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;

View 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)))
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();

View 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

View 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);

View 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,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;
}
/* **** */