From cf724bceea97553bef690f52062ffbc336d0f7a9 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 3 May 1999 23:11:53 +0000 Subject: [PATCH] TreeCtrl indentation and spacing git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/treectrl.h | 5 +++++ include/wx/msw/treectrl.h | 5 +++++ samples/treectrl/treetest.cpp | 40 +++++++++++++++++++++++++++++++++++ samples/treectrl/treetest.h | 10 +++++++++ src/generic/treectrl.cpp | 28 ++++++++++++++++-------- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/include/wx/generic/treectrl.h b/include/wx/generic/treectrl.h index 8bbf086830..407e7c573c 100644 --- a/include/wx/generic/treectrl.h +++ b/include/wx/generic/treectrl.h @@ -234,6 +234,10 @@ public: unsigned int GetIndent() const { return m_indent; } void SetIndent(unsigned int indent); + // spacing is the number of pixels between the start and the Text + unsigned int GetSpacing() const { return m_spacing; } + void SetSpacing(unsigned int spacing); + // image list: these functions allow to associate an image list with // the control and retrieve it. Note that the control does _not_ delete // the associated image list when it's deleted in order to allow image @@ -453,6 +457,7 @@ protected: bool m_dirty; int m_xScroll,m_yScroll; unsigned int m_indent; + unsigned int m_spacing; int m_lineHeight; wxPen m_dottedPen; wxBrush *m_hilightBrush; diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index f20bb7501e..6f4050df46 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -199,6 +199,11 @@ public: unsigned int GetIndent() const; void SetIndent(unsigned int indent); + // spacing is the number of pixels between the start and the Text + // not implemented under wxMSW + unsigned int GetSpacing() const { return 18; } // return wxGTK default + void SetSpacing(unsigned int ) {} + // image list: these functions allow to associate an image list with // the control and retrieve it. Note that the control does _not_ delete // the associated image list when it's deleted in order to allow image diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 174b9bdc5f..2fe8fe49fd 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -37,6 +37,8 @@ #include "wx/imaglist.h" #include "wx/treectrl.h" +#include "math.h" + #include "treetest.h" // verify that the item is ok and insult the user if it is not @@ -64,6 +66,10 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TreeTest_CollapseAndReset, MyFrame::OnCollapseAndReset) EVT_MENU(TreeTest_EnsureVisible, MyFrame::OnEnsureVisible) EVT_MENU(TreeTest_AddItem, MyFrame::OnAddItem) + EVT_MENU(TreeTest_IncIndent, MyFrame::OnIncIndent) + EVT_MENU(TreeTest_DecIndent, MyFrame::OnDecIndent) + EVT_MENU(TreeTest_IncSpacing, MyFrame::OnIncSpacing) + EVT_MENU(TreeTest_DecSpacing, MyFrame::OnDecSpacing) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) @@ -133,6 +139,12 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) tree_menu->Append(TreeTest_SortRev, "Sort in reversed order"); tree_menu->AppendSeparator(); tree_menu->Append(TreeTest_EnsureVisible, "Make the last item &visible"); + tree_menu->AppendSeparator(); + tree_menu->Append(TreeTest_IncIndent, "Add 5 points to indentation\tAlt-I"); + tree_menu->Append(TreeTest_DecIndent, "Reduce indentation by 5 points\tAlt-R"); + tree_menu->AppendSeparator(); + tree_menu->Append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I"); + tree_menu->Append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R"); item_menu->Append(TreeTest_Dump, "&Dump item children"); item_menu->AppendSeparator(); @@ -296,6 +308,34 @@ void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event)) MyTreeCtrl::TreeCtrlIcon_File); } +void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event)) +{ + unsigned int indent = m_treeCtrl->GetIndent(); + if (indent < 100) + m_treeCtrl->SetIndent( indent+5 ); +} + +void MyFrame::OnDecIndent(wxCommandEvent& WXUNUSED(event)) +{ + unsigned int indent = m_treeCtrl->GetIndent(); + if (indent > 10) + m_treeCtrl->SetIndent( indent-5 ); +} + +void MyFrame::OnIncSpacing(wxCommandEvent& WXUNUSED(event)) +{ + unsigned int indent = m_treeCtrl->GetSpacing(); + if (indent < 100) + m_treeCtrl->SetSpacing( indent+5 ); +} + +void MyFrame::OnDecSpacing(wxCommandEvent& WXUNUSED(event)) +{ + unsigned int indent = m_treeCtrl->GetSpacing(); + if (indent > 10) + m_treeCtrl->SetSpacing( indent-5 ); +} + // MyTreeCtrl implementation IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxTreeCtrl) diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 0cd2f06ca8..c3ce883347 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -118,6 +118,12 @@ public: void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); } void OnAddItem(wxCommandEvent& event); + + void OnIncIndent(wxCommandEvent& event); + void OnDecIndent(wxCommandEvent& event); + + void OnIncSpacing(wxCommandEvent& event); + void OnDecSpacing(wxCommandEvent& event); private: void DoSort(bool reverse = FALSE); @@ -147,5 +153,9 @@ enum TreeTest_CollapseAndReset, TreeTest_EnsureVisible, TreeTest_AddItem, + TreeTest_IncIndent, + TreeTest_DecIndent, + TreeTest_IncSpacing, + TreeTest_DecSpacing, TreeTest_Ctrl = 100 }; diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 2494432374..698488be06 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -353,6 +353,7 @@ void wxTreeCtrl::Init() m_yScroll = 0; m_lineHeight = 10; m_indent = 15; + m_spacing = 18; m_hilightBrush = new wxBrush ( @@ -403,6 +404,14 @@ size_t wxTreeCtrl::GetCount() const void wxTreeCtrl::SetIndent(unsigned int indent) { m_indent = indent; + m_dirty = TRUE; + Refresh(); +} + +void wxTreeCtrl::SetSpacing(unsigned int spacing) +{ + m_spacing = spacing; + m_dirty = TRUE; Refresh(); } @@ -1152,11 +1161,11 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & { int horizX = level*m_indent; - item->SetX( horizX+33 ); + item->SetX( horizX+m_indent+m_spacing ); item->SetY( y-m_lineHeight/2 ); item->SetHeight( m_lineHeight ); - item->SetCross( horizX+15, y ); + item->SetCross( horizX+m_indent, y ); int oldY = y; @@ -1166,24 +1175,25 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & if (IsExposed( exposed_x, exposed_y, 10000, m_lineHeight+4 )) // 10000 = very much { int startX = horizX; - int endX = horizX + 10; + int endX = horizX + (m_indent-5); +// if (!item->HasChildren()) endX += (m_indent+5); if (!item->HasChildren()) endX += 20; dc.DrawLine( startX, y, endX, y ); if (item->HasPlus()) { - dc.DrawLine( horizX+20, y, horizX+30, y ); + dc.DrawLine( horizX+(m_indent+5), y, horizX+(m_indent+15), y ); dc.SetPen( *wxGREY_PEN ); dc.SetBrush( *wxWHITE_BRUSH ); - dc.DrawRectangle( horizX+10, y-4, 11, 9 ); + dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 ); dc.SetPen( *wxBLACK_PEN ); - dc.DrawLine( horizX+13, y, horizX+18, y ); + dc.DrawLine( horizX+(m_indent-2), y, horizX+(m_indent+3), y ); if (!item->IsExpanded()) { - dc.DrawLine( horizX+15, y-2, horizX+15, y+3 ); + dc.DrawLine( horizX+m_indent, y-2, horizX+m_indent, y+3 ); } } @@ -1232,7 +1242,7 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & // delete all its children for example) - don't draw the vertical line // in this case if (count > 0) - dc.DrawLine( horizX+15, oldY+5, horizX+15, semiOldY ); + dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY ); } } @@ -1534,7 +1544,7 @@ void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, i { int horizX = level*m_indent; - item->SetX( horizX+33 ); + item->SetX( horizX+m_indent+m_spacing ); item->SetY( y-m_lineHeight/2 ); item->SetHeight( m_lineHeight ); -- 2.45.2