//// Events
void OnSize(wxSizeEvent& event);
- void OnPaint(wxPaintEvent& event);
void OnExpand(wxTreeEvent& event);
void OnScroll(wxScrollWinEvent& 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,
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
*/
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;
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)
// 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);
+ }
}
}
}
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();
+; 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
// 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
// ----------
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);
// 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;
}
: 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();
}
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;
}
/* **** */