git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10442
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// Name: treelay.h
// Purpose: wxTreeLayout class
// Author: Julian Smart
// Name: treelay.h
// Purpose: wxTreeLayout class
// Author: Julian Smart
// Created: 7/4/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart
// Created: 7/4/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart
#endif
// For compilers that support precompilation, includes "wx.h".
#endif
// For compilers that support precompilation, includes "wx.h".
#ifdef __BORLANDC__
#pragma hdrstop
#ifdef __BORLANDC__
#pragma hdrstop
{
if (topId != -1)
SetTopNode(topId);
{
if (topId != -1)
SetTopNode(topId);
long actualTopId = GetTopNode();
long id = actualTopId;
while (id != -1)
long actualTopId = GetTopNode();
long id = actualTopId;
while (id != -1)
}
void wxTreeLayout::DrawNodes(wxDC& dc)
}
void wxTreeLayout::DrawNodes(wxDC& dc)
long id = GetTopNode();
while (id != -1)
{
long id = GetTopNode();
while (id != -1)
{
}
void wxTreeLayout::DrawBranches(wxDC& dc)
}
void wxTreeLayout::DrawBranches(wxDC& dc)
long id = GetTopNode();
while (id != -1)
{
long id = GetTopNode();
while (id != -1)
{
wxSprintf(buf, wxT("%s"), (const wxChar*) name);
else
wxSprintf(buf, wxT("<unnamed>"));
wxSprintf(buf, wxT("%s"), (const wxChar*) name);
else
wxSprintf(buf, wxT("<unnamed>"));
long x = 80;
long y = 20;
dc.GetTextExtent(buf, &x, &y);
long x = 80;
long y = 20;
dc.GetTextExtent(buf, &x, &y);
wxList children;
GetChildren(nodeId, children);
int n = children.Number();
wxList children;
GetChildren(nodeId, children);
int n = children.Number();
if (m_orientation == FALSE)
{
// Left to right
if (m_orientation == FALSE)
{
// Left to right
GetNodeSize(parentId, &x, &y, dc);
SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x));
}
GetNodeSize(parentId, &x, &y, dc);
SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x));
}
wxNode *node = children.First();
while (node)
{
CalcLayout((long)node->Data(), level+1, dc);
node = node->Next();
}
wxNode *node = children.First();
while (node)
{
CalcLayout((long)node->Data(), level+1, dc);
node = node->Next();
}
// Y Calculations
long averageY;
ActivateNode(nodeId, TRUE);
// Y Calculations
long averageY;
ActivateNode(nodeId, TRUE);
if (n > 0)
{
averageY = 0;
if (n > 0)
{
averageY = 0;
SetNodeY(nodeId, m_lastY);
long x, y;
GetNodeSize(nodeId, &x, &y, dc);
SetNodeY(nodeId, m_lastY);
long x, y;
GetNodeSize(nodeId, &x, &y, dc);
m_lastY = m_lastY + y + m_ySpacing;
}
}
else
{
// Top to bottom
m_lastY = m_lastY + y + m_ySpacing;
}
}
else
{
// Top to bottom
// Y Calculations
if (level == 0)
SetNodeY(nodeId, m_topMargin);
// Y Calculations
if (level == 0)
SetNodeY(nodeId, m_topMargin);
GetNodeSize(parentId, &x, &y, dc);
SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y));
}
GetNodeSize(parentId, &x, &y, dc);
SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y));
}
wxNode *node = children.First();
while (node)
{
CalcLayout((long)node->Data(), level+1, dc);
node = node->Next();
}
wxNode *node = children.First();
while (node)
{
CalcLayout((long)node->Data(), level+1, dc);
node = node->Next();
}
// X Calculations
long averageX;
ActivateNode(nodeId, TRUE);
// X Calculations
long averageX;
ActivateNode(nodeId, TRUE);
if (n > 0)
{
averageX = 0;
if (n > 0)
{
averageX = 0;
SetNodeX(nodeId, m_lastX);
long x, y;
GetNodeSize(nodeId, &x, &y, dc);
SetNodeX(nodeId, m_lastX);
long x, y;
GetNodeSize(nodeId, &x, &y, dc);
m_lastX = m_lastX + x + m_xSpacing;
}
}
m_lastX = m_lastX + x + m_xSpacing;
}
}
if (parent != wxT(""))
i = NameToId(parent);
else m_parentNode = m_num;
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 ++;
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 (m_num - 1);
}
else
wxStoredNode* wxTreeLayoutStored::GetNode(long idx) const
{
wxASSERT(idx < m_num);
wxStoredNode* wxTreeLayoutStored::GetNode(long idx) const
{
wxASSERT(idx < m_num);
return &m_nodes[idx];
};
long wxTreeLayoutStored::GetNodeX(long id)
{
wxASSERT(id < 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_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);
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_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_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);
m_nodes[id].m_name = name;
}
wxString wxTreeLayoutStored::GetNodeName(long id)
{
wxASSERT(id < m_num);
return m_nodes[id].m_name;
}
return m_nodes[id].m_name;
}
if (id != -1)
{
wxASSERT(id < m_num);
if (id != -1)
{
wxASSERT(id < m_num);
return m_nodes[id].m_parentId;
}
else
return m_nodes[id].m_parentId;
}
else
long wxTreeLayoutStored::GetNextNode(long id)
{
wxASSERT(id < m_num);
long wxTreeLayoutStored::GetNextNode(long id)
{
wxASSERT(id < m_num);
if ((id != -1) && (id < (m_num - 1)))
return id + 1;
else
if ((id != -1) && (id < (m_num - 1)))
return id + 1;
else
void wxTreeLayoutStored::SetClientData(long id, long clientData)
{
wxASSERT(id < m_num);
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);
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);
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);
m_nodes[id].m_active = active;
}
bool wxTreeLayoutStored::NodeActive(long id)
{
wxASSERT(id < m_num);
return m_nodes[id].m_active;
}
return m_nodes[id].m_active;
}
wxPoint pt = event.GetPosition();
wxCoord x = pt.x;
wxCoord y = pt.y;
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);
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;
}
}
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;
}
}