TreeCtrl indentation and spacing

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-05-03 23:11:53 +00:00
parent e208b369f0
commit cf724bceea
5 changed files with 79 additions and 9 deletions

View File

@@ -234,6 +234,10 @@ public:
unsigned int GetIndent() const { return m_indent; } unsigned int GetIndent() const { return m_indent; }
void SetIndent(unsigned int 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 // image list: these functions allow to associate an image list with
// the control and retrieve it. Note that the control does _not_ delete // 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 // the associated image list when it's deleted in order to allow image
@@ -453,6 +457,7 @@ protected:
bool m_dirty; bool m_dirty;
int m_xScroll,m_yScroll; int m_xScroll,m_yScroll;
unsigned int m_indent; unsigned int m_indent;
unsigned int m_spacing;
int m_lineHeight; int m_lineHeight;
wxPen m_dottedPen; wxPen m_dottedPen;
wxBrush *m_hilightBrush; wxBrush *m_hilightBrush;

View File

@@ -199,6 +199,11 @@ public:
unsigned int GetIndent() const; unsigned int GetIndent() const;
void SetIndent(unsigned int indent); 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 // image list: these functions allow to associate an image list with
// the control and retrieve it. Note that the control does _not_ delete // 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 // the associated image list when it's deleted in order to allow image

View File

@@ -37,6 +37,8 @@
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/treectrl.h" #include "wx/treectrl.h"
#include "math.h"
#include "treetest.h" #include "treetest.h"
// verify that the item is ok and insult the user if it is not // 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_CollapseAndReset, MyFrame::OnCollapseAndReset)
EVT_MENU(TreeTest_EnsureVisible, MyFrame::OnEnsureVisible) EVT_MENU(TreeTest_EnsureVisible, MyFrame::OnEnsureVisible)
EVT_MENU(TreeTest_AddItem, MyFrame::OnAddItem) 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() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) 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->Append(TreeTest_SortRev, "Sort in reversed order");
tree_menu->AppendSeparator(); tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_EnsureVisible, "Make the last item &visible"); 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->Append(TreeTest_Dump, "&Dump item children");
item_menu->AppendSeparator(); item_menu->AppendSeparator();
@@ -296,6 +308,34 @@ void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
MyTreeCtrl::TreeCtrlIcon_File); 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 // MyTreeCtrl implementation
IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxTreeCtrl) IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxTreeCtrl)

View File

@@ -119,6 +119,12 @@ public:
void OnAddItem(wxCommandEvent& event); void OnAddItem(wxCommandEvent& event);
void OnIncIndent(wxCommandEvent& event);
void OnDecIndent(wxCommandEvent& event);
void OnIncSpacing(wxCommandEvent& event);
void OnDecSpacing(wxCommandEvent& event);
private: private:
void DoSort(bool reverse = FALSE); void DoSort(bool reverse = FALSE);
@@ -147,5 +153,9 @@ enum
TreeTest_CollapseAndReset, TreeTest_CollapseAndReset,
TreeTest_EnsureVisible, TreeTest_EnsureVisible,
TreeTest_AddItem, TreeTest_AddItem,
TreeTest_IncIndent,
TreeTest_DecIndent,
TreeTest_IncSpacing,
TreeTest_DecSpacing,
TreeTest_Ctrl = 100 TreeTest_Ctrl = 100
}; };

View File

@@ -353,6 +353,7 @@ void wxTreeCtrl::Init()
m_yScroll = 0; m_yScroll = 0;
m_lineHeight = 10; m_lineHeight = 10;
m_indent = 15; m_indent = 15;
m_spacing = 18;
m_hilightBrush = new wxBrush m_hilightBrush = new wxBrush
( (
@@ -403,6 +404,14 @@ size_t wxTreeCtrl::GetCount() const
void wxTreeCtrl::SetIndent(unsigned int indent) void wxTreeCtrl::SetIndent(unsigned int indent)
{ {
m_indent = indent; m_indent = indent;
m_dirty = TRUE;
Refresh();
}
void wxTreeCtrl::SetSpacing(unsigned int spacing)
{
m_spacing = spacing;
m_dirty = TRUE;
Refresh(); Refresh();
} }
@@ -1152,11 +1161,11 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &
{ {
int horizX = level*m_indent; int horizX = level*m_indent;
item->SetX( horizX+33 ); item->SetX( horizX+m_indent+m_spacing );
item->SetY( y-m_lineHeight/2 ); item->SetY( y-m_lineHeight/2 );
item->SetHeight( m_lineHeight ); item->SetHeight( m_lineHeight );
item->SetCross( horizX+15, y ); item->SetCross( horizX+m_indent, y );
int oldY = 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 if (IsExposed( exposed_x, exposed_y, 10000, m_lineHeight+4 )) // 10000 = very much
{ {
int startX = horizX; 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; if (!item->HasChildren()) endX += 20;
dc.DrawLine( startX, y, endX, y ); dc.DrawLine( startX, y, endX, y );
if (item->HasPlus()) 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.SetPen( *wxGREY_PEN );
dc.SetBrush( *wxWHITE_BRUSH ); 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.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()) 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 // delete all its children for example) - don't draw the vertical line
// in this case // in this case
if (count > 0) 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; int horizX = level*m_indent;
item->SetX( horizX+33 ); item->SetX( horizX+m_indent+m_spacing );
item->SetY( y-m_lineHeight/2 ); item->SetY( y-m_lineHeight/2 );
item->SetHeight( m_lineHeight ); item->SetHeight( m_lineHeight );