wxRemotelyScrolledTreeCtrl draws its own lines if wxTR_ROW_LINES flag

is used, but prevents the base class from seeing the flag so they
won't be drawn twice with possibly different colours.

Also changed all tabs to spaces, so the diffs will show a lot of
whitespace-only changes.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12881 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2001-12-05 16:17:17 +00:00
parent 8f3fc6b415
commit 7f60145d85
2 changed files with 250 additions and 245 deletions

View File

@@ -15,7 +15,7 @@
#define _WX_SPLITTREE_H_ #define _WX_SPLITTREE_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "splittree.h" #pragma interface "splittree.h"
#endif #endif
#ifdef GIZMOISDLL #ifdef GIZMOISDLL
@@ -54,17 +54,17 @@ class wxSplitterScrolledWindow;
class GIZMODLLEXPORT wxRemotelyScrolledTreeCtrl: public wxTreeCtrl class GIZMODLLEXPORT wxRemotelyScrolledTreeCtrl: public wxTreeCtrl
{ {
DECLARE_CLASS(wxRemotelyScrolledTreeCtrl) DECLARE_CLASS(wxRemotelyScrolledTreeCtrl)
public: public:
wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition, wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition,
const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS); const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS);
~wxRemotelyScrolledTreeCtrl(); ~wxRemotelyScrolledTreeCtrl();
//// Events //// Events
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);
void OnExpand(wxTreeEvent& event); void OnExpand(wxTreeEvent& event);
void OnScroll(wxScrollWinEvent& event); void OnScroll(wxScrollWinEvent& event);
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
//// Overrides //// Overrides
// Override this in case we're using the generic tree control. // Override this in case we're using the generic tree control.
@@ -89,18 +89,18 @@ public:
virtual int GetScrollPos(int orient) const; virtual int GetScrollPos(int orient) const;
//// Helpers //// Helpers
void HideVScrollbar(); void HideVScrollbar();
// Calculate the tree overall size so we can set the scrollbar // Calculate the tree overall size so we can set the scrollbar
// correctly // correctly
void CalcTreeSize(wxRect& rect); void CalcTreeSize(wxRect& rect);
void CalcTreeSize(const wxTreeItemId& id, wxRect& rect); void CalcTreeSize(const wxTreeItemId& id, wxRect& rect);
// Adjust the containing wxScrolledWindow's scrollbars appropriately // Adjust the containing wxScrolledWindow's scrollbars appropriately
void AdjustRemoteScrollbars(); void AdjustRemoteScrollbars();
// Find the scrolled window that contains this control // Find the scrolled window that contains this control
wxScrolledWindow* GetScrolledWindow() const; wxScrolledWindow* GetScrolledWindow() const;
// Scroll to the given line (in scroll units where each unit is // Scroll to the given line (in scroll units where each unit is
// the height of an item) // the height of an item)
@@ -108,15 +108,16 @@ public:
//// Accessors //// Accessors
// The companion window is one which will get notified when certain // The companion window is one which will get notified when certain
// events happen such as node expansion // events happen such as node expansion
void SetCompanionWindow(wxWindow* companion) { m_companionWindow = companion; } void SetCompanionWindow(wxWindow* companion) { m_companionWindow = companion; }
wxWindow* GetCompanionWindow() const { return m_companionWindow; } wxWindow* GetCompanionWindow() const { return m_companionWindow; }
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
protected: protected:
wxWindow* m_companionWindow; wxWindow* m_companionWindow;
bool m_drawRowLines;
}; };
/* /*
@@ -136,22 +137,22 @@ public:
long style = 0); long style = 0);
//// Overrides //// Overrides
virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect); virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect);
//// Events //// Events
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnScroll(wxScrollWinEvent& event); void OnScroll(wxScrollWinEvent& event);
void OnExpand(wxTreeEvent& event); void OnExpand(wxTreeEvent& event);
//// Operations //// Operations
//// Accessors //// Accessors
wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }; wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; };
void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl) { m_treeCtrl = treeCtrl; } void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl) { m_treeCtrl = treeCtrl; }
//// Data members //// Data members
protected: protected:
wxRemotelyScrolledTreeCtrl* m_treeCtrl; wxRemotelyScrolledTreeCtrl* m_treeCtrl;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@@ -180,7 +181,7 @@ public:
// Tests for x, y over sash. Overriding this allows us to increase // Tests for x, y over sash. Overriding this allows us to increase
// the tolerance. // the tolerance.
bool SashHitTest(int x, int y, int tolerance = 2); bool SashHitTest(int x, int y, int tolerance = 2);
void DrawSash(wxDC& dc); void DrawSash(wxDC& dc);
//// Events //// Events

View File

@@ -58,18 +58,25 @@ BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl)
#else #else
BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxTreeCtrl) BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxTreeCtrl)
#endif #endif
EVT_SIZE(wxRemotelyScrolledTreeCtrl::OnSize) EVT_SIZE(wxRemotelyScrolledTreeCtrl::OnSize)
EVT_PAINT(wxRemotelyScrolledTreeCtrl::OnPaint) EVT_PAINT(wxRemotelyScrolledTreeCtrl::OnPaint)
EVT_TREE_ITEM_EXPANDED(-1, wxRemotelyScrolledTreeCtrl::OnExpand) EVT_TREE_ITEM_EXPANDED(-1, wxRemotelyScrolledTreeCtrl::OnExpand)
EVT_TREE_ITEM_COLLAPSED(-1, wxRemotelyScrolledTreeCtrl::OnExpand) EVT_TREE_ITEM_COLLAPSED(-1, wxRemotelyScrolledTreeCtrl::OnExpand)
EVT_SCROLLWIN(wxRemotelyScrolledTreeCtrl::OnScroll) EVT_SCROLLWIN(wxRemotelyScrolledTreeCtrl::OnScroll)
END_EVENT_TABLE() END_EVENT_TABLE()
wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt, wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl(
const wxSize& sz, long style): wxWindow* parent, wxWindowID id, const wxPoint& pt,
wxTreeCtrl(parent, id, pt, sz, style) const wxSize& sz, long style)
: wxTreeCtrl(parent, id, pt, sz, style & ~wxTR_ROW_LINES)
{ {
m_companionWindow = NULL; m_companionWindow = NULL;
// We draw the row lines ourself so they match what's done
// by the companion window. That is why the flag is turned
// off above, so wxGenericTreeCtrl doesn't draw them in a
// different colour.
m_drawRowLines = (style & wxTR_ROW_LINES) != 0;
} }
wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl() wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
@@ -108,9 +115,9 @@ void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPer
wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
win->wxGenericTreeCtrl::SetScrollbars(pixelsPerUnitX, 0, noUnitsX, 0, xPos, 0, noRefresh); win->wxGenericTreeCtrl::SetScrollbars(pixelsPerUnitX, 0, noUnitsX, 0, xPos, 0, noRefresh);
wxScrolledWindow* scrolledWindow = GetScrolledWindow(); wxScrolledWindow* scrolledWindow = GetScrolledWindow();
if (scrolledWindow) if (scrolledWindow)
{ {
scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh); scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh);
} }
} }
@@ -159,13 +166,13 @@ void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
scrolledWindow->GetViewStart(& x2, & y2); scrolledWindow->GetViewStart(& x2, & y2);
* y = y2; * y = y2;
} }
else else
#endif #endif
{ {
// x is wrong since the horizontal scrollbar is controlled by the // x is wrong since the horizontal scrollbar is controlled by the
// tree control, but we probably don't need it. // tree control, but we probably don't need it.
scrolledWindow->GetViewStart(x, y); scrolledWindow->GetViewStart(x, y);
} }
} }
// In case we're using the generic tree control. // In case we're using the generic tree control.
@@ -174,7 +181,7 @@ void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& dc)
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
{ {
wxScrolledWindow* scrolledWindow = GetScrolledWindow(); wxScrolledWindow* scrolledWindow = GetScrolledWindow();
wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
@@ -200,9 +207,9 @@ void wxRemotelyScrolledTreeCtrl::ScrollToLine(int posHoriz, int posVert)
if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl))) if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
#endif #endif
{ {
UINT sbCode = SB_THUMBPOSITION; UINT sbCode = SB_THUMBPOSITION;
HWND vertScrollBar = 0; HWND vertScrollBar = 0;
MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXHWND) vertScrollBar); MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXHWND) vertScrollBar);
} }
#if USE_GENERIC_TREECTRL #if USE_GENERIC_TREECTRL
else else
@@ -211,78 +218,75 @@ void wxRemotelyScrolledTreeCtrl::ScrollToLine(int posHoriz, int posVert)
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
{ {
wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
win->Refresh(); win->Refresh();
/* Doesn't work yet because scrolling is ignored by Scroll /* Doesn't work yet because scrolling is ignored by Scroll
int xppu, yppu; int xppu, yppu;
wxScrolledWindow* scrolledWindow = GetScrolledWindow(); wxScrolledWindow* scrolledWindow = GetScrolledWindow();
if (scrolledWindow) if (scrolledWindow)
{ {
scrolledWindow->GetScrollPixelsPerUnit(& xppu, & yppu); scrolledWindow->GetScrollPixelsPerUnit(& xppu, & yppu);
win->Scroll(-1, posVert*yppu); win->Scroll(-1, posVert*yppu);
} }
*/ */
} }
#endif #endif
} }
void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event) void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event)
{ {
HideVScrollbar(); HideVScrollbar();
AdjustRemoteScrollbars(); AdjustRemoteScrollbars();
event.Skip(); event.Skip();
} }
void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event) void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event)
{ {
AdjustRemoteScrollbars(); AdjustRemoteScrollbars();
event.Skip(); event.Skip();
// If we don't have this, we get some bits of lines still remaining // If we don't have this, we get some bits of lines still remaining
if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED) if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED)
Refresh(); Refresh();
// Pass on the event // Pass on the event
if (m_companionWindow) if (m_companionWindow)
m_companionWindow->GetEventHandler()->ProcessEvent(event); m_companionWindow->GetEventHandler()->ProcessEvent(event);
} }
void wxRemotelyScrolledTreeCtrl::OnPaint(wxPaintEvent& event) void wxRemotelyScrolledTreeCtrl::OnPaint(wxPaintEvent& event)
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
wxTreeCtrl::OnPaint(event); wxTreeCtrl::OnPaint(event);
// The generic tree already knows how to draw lines if (! m_drawRowLines)
#ifdef __WXMSW__ return;
if ((GetWindowStyle() & wxTR_ROW_LINES) == 0)
return FALSE;
// Reset the device origin since it may have been set // Reset the device origin since it may have been set
dc.SetDeviceOrigin(0, 0); dc.SetDeviceOrigin(0, 0);
wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
dc.SetPen(pen); dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH); dc.SetBrush(* wxTRANSPARENT_BRUSH);
wxSize clientSize = GetClientSize(); wxSize clientSize = GetClientSize();
wxRect itemRect; wxRect itemRect;
int cy=0; int cy=0;
wxTreeItemId h, lastH; wxTreeItemId h, lastH;
for(h=GetFirstVisibleItem();h;h=GetNextVisible(h)) for(h=GetFirstVisibleItem();h;h=GetNextVisible(h))
{ {
if (GetBoundingRect(h, itemRect)) if (GetBoundingRect(h, itemRect))
{ {
cy = itemRect.GetTop(); cy = itemRect.GetTop();
dc.DrawLine(0, cy, clientSize.x, cy); dc.DrawLine(0, cy, clientSize.x, cy);
lastH = h; lastH = h;
} }
} }
if (GetBoundingRect(lastH, itemRect)) if (GetBoundingRect(lastH, itemRect))
{ {
cy = itemRect.GetBottom(); cy = itemRect.GetBottom();
dc.DrawLine(0, cy, clientSize.x, cy); dc.DrawLine(0, cy, clientSize.x, cy);
} }
#endif
} }
@@ -291,50 +295,50 @@ void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
{ {
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__) #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
{ {
// This is for the generic tree control. // This is for the generic tree control.
// It calls SetScrollbars which has been overridden // It calls SetScrollbars which has been overridden
// to adjust the parent scrolled window vertical // to adjust the parent scrolled window vertical
// scrollbar. // scrollbar.
((wxGenericTreeCtrl*) this)->AdjustMyScrollbars(); ((wxGenericTreeCtrl*) this)->AdjustMyScrollbars();
return; return;
} }
else else
#endif #endif
{ {
// This is for the wxMSW tree control // This is for the wxMSW tree control
wxScrolledWindow* scrolledWindow = GetScrolledWindow(); wxScrolledWindow* scrolledWindow = GetScrolledWindow();
if (scrolledWindow) if (scrolledWindow)
{ {
wxRect itemRect; wxRect itemRect;
if (GetBoundingRect(GetRootItem(), itemRect)) if (GetBoundingRect(GetRootItem(), itemRect))
{ {
// Actually, the real height seems to be 1 less than reported // Actually, the real height seems to be 1 less than reported
// (e.g. 16 instead of 16) // (e.g. 16 instead of 16)
int itemHeight = itemRect.GetHeight() - 1; int itemHeight = itemRect.GetHeight() - 1;
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
wxRect rect(0, 0, 0, 0); wxRect rect(0, 0, 0, 0);
CalcTreeSize(rect); CalcTreeSize(rect);
double f = ((double) (rect.GetHeight()) / (double) itemHeight) ; double f = ((double) (rect.GetHeight()) / (double) itemHeight) ;
int treeViewHeight = (int) ceil(f); int treeViewHeight = (int) ceil(f);
int scrollPixelsPerLine = itemHeight; int scrollPixelsPerLine = itemHeight;
int scrollPos = - (itemRect.y / itemHeight); int scrollPos = - (itemRect.y / itemHeight);
scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos); scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos);
// Ensure that when a scrollbar becomes hidden or visible, // Ensure that when a scrollbar becomes hidden or visible,
// the contained window sizes are right. // the contained window sizes are right.
// Problem: this is called too early (?) // Problem: this is called too early (?)
wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId()); wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId());
scrolledWindow->GetEventHandler()->ProcessEvent(event); scrolledWindow->GetEventHandler()->ProcessEvent(event);
} }
} }
} }
} }
@@ -347,10 +351,10 @@ static wxRect CombineRectangles(const wxRect& rect1, const wxRect& rect2)
int bottom1 = rect1.GetBottom(); int bottom1 = rect1.GetBottom();
int right2 = rect2.GetRight(); int right2 = rect2.GetRight();
int bottom2 = rect2.GetBottom(); int bottom2 = rect2.GetBottom();
wxPoint topLeft = wxPoint(wxMin(rect1.x, rect2.x), wxMin(rect1.y, rect2.y)); wxPoint topLeft = wxPoint(wxMin(rect1.x, rect2.x), wxMin(rect1.y, rect2.y));
wxPoint bottomRight = wxPoint(wxMax(right1, right2), wxMax(bottom1, bottom2)); wxPoint bottomRight = wxPoint(wxMax(right1, right2), wxMax(bottom1, bottom2));
rect.x = topLeft.x; rect.y = topLeft.y; rect.x = topLeft.x; rect.y = topLeft.y;
rect.SetRight(bottomRight.x); rect.SetRight(bottomRight.x);
rect.SetBottom(bottomRight.y); rect.SetBottom(bottomRight.y);
@@ -363,40 +367,40 @@ static wxRect CombineRectangles(const wxRect& rect1, const wxRect& rect2)
// correctly // correctly
void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect) void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect)
{ {
CalcTreeSize(GetRootItem(), rect); CalcTreeSize(GetRootItem(), rect);
} }
void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect) void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect)
{ {
// More efficient implementation would be to find the last item (but how?) // More efficient implementation would be to find the last item (but how?)
// Q: is the bounding rect relative to the top of the virtual tree workspace // Q: is the bounding rect relative to the top of the virtual tree workspace
// or the top of the window? How would we convert? // or the top of the window? How would we convert?
wxRect itemSize; wxRect itemSize;
if (GetBoundingRect(id, itemSize)) if (GetBoundingRect(id, itemSize))
{ {
rect = CombineRectangles(rect, itemSize); rect = CombineRectangles(rect, itemSize);
} }
long cookie; long cookie;
wxTreeItemId childId = GetFirstChild(id, cookie); wxTreeItemId childId = GetFirstChild(id, cookie);
while (childId != 0) while (childId != 0)
{ {
CalcTreeSize(childId, rect); CalcTreeSize(childId, rect);
childId = GetNextChild(childId, cookie); childId = GetNextChild(childId, cookie);
} }
} }
// Find the scrolled window that contains this control // Find the scrolled window that contains this control
wxScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const wxScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const
{ {
wxWindow* parent = wxWindow::GetParent(); wxWindow* parent = wxWindow::GetParent();
while (parent) while (parent)
{ {
if (parent->IsKindOf(CLASSINFO(wxScrolledWindow))) if (parent->IsKindOf(CLASSINFO(wxScrolledWindow)))
return (wxScrolledWindow*) parent; return (wxScrolledWindow*) parent;
parent = parent->GetParent(); parent = parent->GetParent();
} }
return NULL; return NULL;
} }
void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event) void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
@@ -426,78 +430,78 @@ void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow) IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow)
BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow) BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow)
EVT_PAINT(wxTreeCompanionWindow::OnPaint) EVT_PAINT(wxTreeCompanionWindow::OnPaint)
EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll) EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll)
EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand) EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand)
EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand) EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand)
END_EVENT_TABLE() END_EVENT_TABLE()
wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id, wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& sz, const wxSize& sz,
long style): long style):
wxWindow(parent, id, pos, sz, style) wxWindow(parent, id, pos, sz, style)
{ {
m_treeCtrl = NULL; m_treeCtrl = NULL;
} }
void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect)
{ {
// TEST CODE // TEST CODE
#if 1 #if 1
if (m_treeCtrl) if (m_treeCtrl)
{ {
wxString text = m_treeCtrl->GetItemText(id); wxString text = m_treeCtrl->GetItemText(id);
dc.SetTextForeground(* wxBLACK); dc.SetTextForeground(* wxBLACK);
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
int textW, textH; int textW, textH;
dc.GetTextExtent(text, & textW, & textH); dc.GetTextExtent(text, & textW, & textH);
int x = 5; int x = 5;
int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2); int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);
dc.DrawText(text, x, y); dc.DrawText(text, x, y);
} }
#endif #endif
} }
void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event) void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event)
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
if (!m_treeCtrl) if (!m_treeCtrl)
return; return;
wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
dc.SetPen(pen); dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH); dc.SetBrush(* wxTRANSPARENT_BRUSH);
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
dc.SetFont(font); dc.SetFont(font);
wxSize clientSize = GetClientSize(); wxSize clientSize = GetClientSize();
wxRect itemRect; wxRect itemRect;
int cy=0; int cy=0;
wxTreeItemId h, lastH; wxTreeItemId h, lastH;
for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h)) for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h))
{ {
if (m_treeCtrl->GetBoundingRect(h, itemRect)) if (m_treeCtrl->GetBoundingRect(h, itemRect))
{ {
cy = itemRect.GetTop(); cy = itemRect.GetTop();
wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight()); wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
lastH = h; lastH = h;
// Draw the actual item // Draw the actual item
DrawItem(dc, h, drawItemRect); DrawItem(dc, h, drawItemRect);
dc.DrawLine(0, cy, clientSize.x, cy); dc.DrawLine(0, cy, clientSize.x, cy);
} }
} }
if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect)) if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect))
{ {
cy = itemRect.GetBottom(); cy = itemRect.GetBottom();
dc.DrawLine(0, cy, clientSize.x, cy); dc.DrawLine(0, cy, clientSize.x, cy);
} }
} }
void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event) void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event)
@@ -511,15 +515,15 @@ void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event)
if (!m_treeCtrl) if (!m_treeCtrl)
return; return;
// TODO: scroll the window physically instead of just refreshing. // TODO: scroll the window physically instead of just refreshing.
Refresh(TRUE); Refresh(TRUE);
} }
void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event) void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event)
{ {
// TODO: something more optimized than simply refresh the whole // TODO: something more optimized than simply refresh the whole
// window when the tree is expanded/collapsed. Tricky. // window when the tree is expanded/collapsed. Tricky.
Refresh(); Refresh();
} }
/* /*
@@ -529,7 +533,7 @@ void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event)
IMPLEMENT_CLASS(wxThinSplitterWindow, wxSplitterWindow) IMPLEMENT_CLASS(wxThinSplitterWindow, wxSplitterWindow)
BEGIN_EVENT_TABLE(wxThinSplitterWindow, wxSplitterWindow) BEGIN_EVENT_TABLE(wxThinSplitterWindow, wxSplitterWindow)
EVT_SIZE(wxThinSplitterWindow::OnSize) EVT_SIZE(wxThinSplitterWindow::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id, wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id,
@@ -542,9 +546,9 @@ wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id,
void wxThinSplitterWindow::SizeWindows() void wxThinSplitterWindow::SizeWindows()
{ {
// The client size may have changed inbetween // The client size may have changed inbetween
// the sizing of the first window and the sizing of // the sizing of the first window and the sizing of
// the second. So repeat SizeWindows. // the second. So repeat SizeWindows.
wxSplitterWindow::SizeWindows(); wxSplitterWindow::SizeWindows();
wxSplitterWindow::SizeWindows(); wxSplitterWindow::SizeWindows();
} }
@@ -552,7 +556,7 @@ void wxThinSplitterWindow::SizeWindows()
// Tests for x, y over sash // Tests for x, y over sash
bool wxThinSplitterWindow::SashHitTest(int x, int y, int tolerance) bool wxThinSplitterWindow::SashHitTest(int x, int y, int tolerance)
{ {
return wxSplitterWindow::SashHitTest(x, y, 4); return wxSplitterWindow::SashHitTest(x, y, 4);
} }
void wxThinSplitterWindow::DrawSash(wxDC& dc) void wxThinSplitterWindow::DrawSash(wxDC& dc)
@@ -565,42 +569,42 @@ void wxThinSplitterWindow::DrawSash(wxDC& dc)
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
if ( m_splitMode == wxSPLIT_VERTICAL ) if ( m_splitMode == wxSPLIT_VERTICAL )
{ {
dc.SetPen(* m_facePen); dc.SetPen(* m_facePen);
dc.SetBrush(* m_faceBrush); dc.SetBrush(* m_faceBrush);
int h1 = h-1; int h1 = h-1;
int y1 = 0; int y1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
h1 += 1; // Not sure why this is necessary... h1 += 1; // Not sure why this is necessary...
if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)
{ {
y1 = 2; h1 -= 3; y1 = 2; h1 -= 3;
} }
dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1); dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1);
} }
else else
{ {
dc.SetPen(* m_facePen); dc.SetPen(* m_facePen);
dc.SetBrush(* m_faceBrush); dc.SetBrush(* m_faceBrush);
int w1 = w-1; int w1 = w-1;
int x1 = 0; int x1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
w1 ++; w1 ++;
if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)
{ {
x1 = 2; w1 -= 3; x1 = 2; w1 -= 3;
} }
dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize); dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize);
} }
dc.SetPen(wxNullPen); dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush); dc.SetBrush(wxNullBrush);
} }
void wxThinSplitterWindow::OnSize(wxSizeEvent& event) void wxThinSplitterWindow::OnSize(wxSizeEvent& event)
{ {
wxSplitterWindow::OnSize(event); wxSplitterWindow::OnSize(event);
} }
/* /*
@@ -610,8 +614,8 @@ void wxThinSplitterWindow::OnSize(wxSizeEvent& event)
IMPLEMENT_CLASS(wxSplitterScrolledWindow, wxScrolledWindow) IMPLEMENT_CLASS(wxSplitterScrolledWindow, wxScrolledWindow)
BEGIN_EVENT_TABLE(wxSplitterScrolledWindow, wxScrolledWindow) BEGIN_EVENT_TABLE(wxSplitterScrolledWindow, wxScrolledWindow)
EVT_SCROLLWIN(wxSplitterScrolledWindow::OnScroll) EVT_SCROLLWIN(wxSplitterScrolledWindow::OnScroll)
EVT_SIZE(wxSplitterScrolledWindow::OnSize) EVT_SIZE(wxSplitterScrolledWindow::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id, wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id,
@@ -624,11 +628,11 @@ wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID
void wxSplitterScrolledWindow::OnSize(wxSizeEvent& event) void wxSplitterScrolledWindow::OnSize(wxSizeEvent& event)
{ {
wxSize sz = GetClientSize(); wxSize sz = GetClientSize();
if (GetChildren().First()) if (GetChildren().First())
{ {
((wxWindow*) GetChildren().First()->Data())->SetSize(0, 0, sz.x, sz.y); ((wxWindow*) GetChildren().First()->Data())->SetSize(0, 0, sz.x, sz.y);
} }
} }
void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event) void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
@@ -642,7 +646,7 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
return; return;
} }
inOnScroll = TRUE; inOnScroll = TRUE;
int orient = event.GetOrientation(); int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event); int nScrollInc = CalcScrollInc(event);