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
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;
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
#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
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)
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();
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)
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);
TreeTest_CollapseAndReset,
TreeTest_EnsureVisible,
TreeTest_AddItem,
+ TreeTest_IncIndent,
+ TreeTest_DecIndent,
+ TreeTest_IncSpacing,
+ TreeTest_DecSpacing,
TreeTest_Ctrl = 100
};
m_yScroll = 0;
m_lineHeight = 10;
m_indent = 15;
+ m_spacing = 18;
m_hilightBrush = new wxBrush
(
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();
}
{
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;
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 );
}
}
// 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 );
}
}
{
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 );