X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..578dc95029e761a59911b7c1bc09f59384d64ddf:/src/generic/treelay.cpp diff --git a/src/generic/treelay.cpp b/src/generic/treelay.cpp index 947d53e6ac..16f82ebd0f 100644 --- a/src/generic/treelay.cpp +++ b/src/generic/treelay.cpp @@ -2,7 +2,7 @@ // Name: treelay.h // Purpose: wxTreeLayout class // Author: Julian Smart -// Modified by: +// Modified by: // Created: 7/4/98 // RCS-ID: $Id$ // Copyright: (c) 1998 Julian Smart @@ -14,19 +14,20 @@ #endif // For compilers that support precompilation, includes "wx.h". -#include +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/wx.h" +#include "wx/dc.h" +#include "wx/event.h" #endif #if wxUSE_TREELAYOUT -#include +#include "wx/treelay.h" /* * Abstract tree @@ -49,7 +50,7 @@ void wxTreeLayout::DoLayout(wxDC& dc, long topId) { if (topId != -1) SetTopNode(topId); - + long actualTopId = GetTopNode(); long id = actualTopId; while (id != -1) @@ -72,7 +73,7 @@ void wxTreeLayout::Draw(wxDC& dc) } void wxTreeLayout::DrawNodes(wxDC& dc) -{ +{ long id = GetTopNode(); while (id != -1) { @@ -83,7 +84,7 @@ void wxTreeLayout::DrawNodes(wxDC& dc) } void wxTreeLayout::DrawBranches(wxDC& dc) -{ +{ long id = GetTopNode(); while (id != -1) { @@ -105,7 +106,7 @@ void wxTreeLayout::DrawNode(long id, wxDC& dc) wxSprintf(buf, wxT("%s"), (const wxChar*) name); else wxSprintf(buf, wxT("")); - + long x = 80; long y = 20; dc.GetTextExtent(buf, &x, &y); @@ -139,8 +140,8 @@ void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) { wxList children; GetChildren(nodeId, children); - int n = children.Number(); - + int n = children.GetCount(); + if (m_orientation == FALSE) { // Left to right @@ -156,26 +157,26 @@ void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) GetNodeSize(parentId, &x, &y, dc); SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x)); } - - wxNode *node = children.First(); + + wxNode *node = children.GetFirst(); while (node) { - CalcLayout((long)node->Data(), level+1, dc); - node = node->Next(); + CalcLayout((long)node->GetData(), level+1, dc); + node = node->GetNext(); } - + // Y Calculations long averageY; ActivateNode(nodeId, TRUE); - + if (n > 0) { averageY = 0; - node = children.First(); + node = children.GetFirst(); while (node) { - averageY += GetNodeY((long)node->Data()); - node = node->Next(); + averageY += GetNodeY((long)node->GetData()); + node = node->GetNext(); } averageY = averageY / n; SetNodeY(nodeId, averageY); @@ -185,14 +186,14 @@ void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) SetNodeY(nodeId, m_lastY); long x, y; GetNodeSize(nodeId, &x, &y, dc); - + m_lastY = m_lastY + y + m_ySpacing; } } else { // Top to bottom - + // Y Calculations if (level == 0) SetNodeY(nodeId, m_topMargin); @@ -205,26 +206,26 @@ void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) GetNodeSize(parentId, &x, &y, dc); SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y)); } - - wxNode *node = children.First(); + + wxNode *node = children.GetFirst(); while (node) { - CalcLayout((long)node->Data(), level+1, dc); - node = node->Next(); + CalcLayout((long)node->GetData(), level+1, dc); + node = node->GetNext(); } - + // X Calculations long averageX; ActivateNode(nodeId, TRUE); - + if (n > 0) { averageX = 0; - node = children.First(); + node = children.GetFirst(); while (node) { - averageX += GetNodeX((long)node->Data()); - node = node->Next(); + averageX += GetNodeX((long)node->GetData()); + node = node->GetNext(); } averageX = averageX / n; SetNodeX(nodeId, averageX); @@ -234,7 +235,7 @@ void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) SetNodeX(nodeId, m_lastX); long x, y; GetNodeSize(nodeId, &x, &y, dc); - + m_lastX = m_lastX + x + m_xSpacing; } } @@ -269,7 +270,7 @@ void wxTreeLayoutStored::Initialize(int n) int i; for (i = 0; i < n; i++) { - m_nodes[i].m_name = ""; + m_nodes[i].m_name = wxT(""); m_nodes[i].m_active = FALSE; m_nodes[i].m_parentId = -1; m_nodes[i].m_x = 0; @@ -286,6 +287,32 @@ long wxTreeLayoutStored::AddChild(const wxString& name, const wxString& parent) if (parent != wxT("")) i = NameToId(parent); else m_parentNode = m_num; + + m_nodes[m_num].m_parentId = i; + m_nodes[m_num].m_name = name; + m_nodes[m_num].m_x = m_nodes[m_num].m_y = 0; + m_nodes[m_num].m_clientData = 0; + m_num ++; + + return (m_num - 1); + } + else + return -1; +} + +long wxTreeLayoutStored::AddChild(const wxString& name, long parent) +{ + if (m_num < (m_maxNodes -1 ) && parent < m_num) + { + long i = -1; + if (parent != -1) + { + i = parent; + } + else + { + m_parentNode = m_num; + } m_nodes[m_num].m_parentId = i; m_nodes[m_num].m_name = name; @@ -322,49 +349,49 @@ void wxTreeLayoutStored::GetChildren(long id, wxList& list) wxStoredNode* wxTreeLayoutStored::GetNode(long idx) const { wxASSERT(idx < m_num); - + return &m_nodes[idx]; }; long wxTreeLayoutStored::GetNodeX(long id) { wxASSERT(id < m_num); - + return (long)m_nodes[id].m_x; } long wxTreeLayoutStored::GetNodeY(long id) { wxASSERT(id < m_num); - + return (long)m_nodes[id].m_y; } void wxTreeLayoutStored::SetNodeX(long id, long x) { wxASSERT(id < m_num); - + m_nodes[id].m_x = (int)x; } void wxTreeLayoutStored::SetNodeY(long id, long y) { wxASSERT(id < m_num); - + m_nodes[id].m_y = (int)y; } void wxTreeLayoutStored::SetNodeName(long id, const wxString& name) { wxASSERT(id < m_num); - + m_nodes[id].m_name = name; } wxString wxTreeLayoutStored::GetNodeName(long id) { wxASSERT(id < m_num); - + return m_nodes[id].m_name; } @@ -373,7 +400,7 @@ long wxTreeLayoutStored::GetNodeParent(long id) if (id != -1) { wxASSERT(id < m_num); - + return m_nodes[id].m_parentId; } else @@ -383,7 +410,7 @@ long wxTreeLayoutStored::GetNodeParent(long id) long wxTreeLayoutStored::GetNextNode(long id) { wxASSERT(id < m_num); - + if ((id != -1) && (id < (m_num - 1))) return id + 1; else @@ -393,28 +420,28 @@ long wxTreeLayoutStored::GetNextNode(long id) void wxTreeLayoutStored::SetClientData(long id, long clientData) { wxASSERT(id < m_num); - + m_nodes[id].m_clientData = clientData; } long wxTreeLayoutStored::GetClientData(long id) const { wxASSERT(id < m_num); - + return m_nodes[id].m_clientData; } void wxTreeLayoutStored::ActivateNode(long id, bool active) { wxASSERT(id < m_num); - + m_nodes[id].m_active = active; } bool wxTreeLayoutStored::NodeActive(long id) { wxASSERT(id < m_num); - + return m_nodes[id].m_active; } @@ -423,21 +450,21 @@ wxString wxTreeLayoutStored::HitTest(wxMouseEvent& event, wxDC& dc) wxPoint pt = event.GetPosition(); wxCoord x = pt.x; wxCoord y = pt.y; - + int i; for (i = 0; i < m_maxNodes; i++) { long width, height; dc.GetTextExtent(m_nodes[i].m_name, &width, &height); - + if ( (x >= (m_nodes[i].m_x-10)) && (x < (m_nodes[i].m_x + width+10)) && (y >= m_nodes[i].m_y-10) && (y < (m_nodes[i].m_y + height+10)) ) { return m_nodes[i].m_name; } } - - return wxString(""); + + return wxString( wxT("") ); } #endif