-
Notifications
You must be signed in to change notification settings - Fork 0
/
VirtualTreeNode.cpp
142 lines (127 loc) · 3.58 KB
/
VirtualTreeNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "StdH.h"
#include "WorldEditor.h"
#include "VirtualTreeNode.h"
CVirtualTreeNode::CVirtualTreeNode()
{
vtn_pTextureData = NULL;
vtn_bmBrowsingMode = BM_ICONS_MEDIUM;
vtn_bSelected = FALSE;
}
CVirtualTreeNode::~CVirtualTreeNode()
{
FORDELETELIST( CVirtualTreeNode, vtn_lnInDirectory, vtn_lhChildren, litDel)
{
delete &litDel.Current();
}
}
INDEX _iTabs=0;
void CVirtualTreeNode::Dump(CTStream *pFile)
{
for( INDEX iTab=0; iTab<_iTabs; iTab++)
{
pFile->PutString_t(" ");
}
if( vtn_bIsDirectory)
{
CTString strDirectory;
strDirectory.PrintF("Directory: %s", vtn_strName);
pFile->PutLine_t(strDirectory);
_iTabs++;
FOREACHINLIST(CVirtualTreeNode, vtn_lnInDirectory, vtn_lhChildren, it)
{
it->Dump(pFile);
}
_iTabs--;
}
else
{
CTString strItem;
strItem.PrintF("Item: %s", vtn_fnItem);
pFile->PutLine_t(strItem);
}
}
void CVirtualTreeNode::Read_t( CTStream *pFile, CVirtualTreeNode* pParent)
{
if( pParent != NULL)
{
pParent->vtn_lhChildren.AddTail( vtn_lnInDirectory);
}
vnt_pvtnParent = pParent;
pFile->Read_t( &vtn_bIsDirectory, sizeof(BOOL));
if( vtn_bIsDirectory)
{
pFile->Read_t( &vtn_itIconType, sizeof(INDEX)); // Symbolic icons for directories
pFile->Read_t( &vtn_bmBrowsingMode, sizeof(INDEX)); // Icons (and size) or descriptions
*pFile >> vtn_strName;
INDEX iDirEntries;
pFile->Read_t( &iDirEntries, sizeof(INDEX));
for( INDEX i=0; i<iDirEntries; i++)
{
CVirtualTreeNode *pVTN = new CVirtualTreeNode;
pVTN->Read_t( pFile, this);
}
}
else
{
pFile->Read_t( &vtn_bSelected, sizeof(BOOL)); // Item's selection bit
*pFile >> vtn_strName;
*pFile >> vtn_fnItem;
}
}
void CVirtualTreeNode::Write_t( CTStream *pFile)
{
*pFile << (INDEX) vtn_bIsDirectory;
if( vtn_bIsDirectory)
{
pFile->Write_t( &vtn_itIconType, sizeof(INDEX));
pFile->Write_t( &vtn_bmBrowsingMode, sizeof(INDEX));
*pFile << vtn_strName;
INDEX iDirEntries = vtn_lhChildren.Count();
pFile->Write_t( &iDirEntries, sizeof(INDEX));
FOREACHINLIST(CVirtualTreeNode, vtn_lnInDirectory, vtn_lhChildren, it)
{
it->Write_t( pFile);
}
}
else
{
pFile->Write_t( &vtn_bSelected, sizeof(BOOL));
*pFile << vtn_strName;
*pFile << vtn_fnItem;
}
}
void CVirtualTreeNode::MakeRoot(void)
{
FORDELETELIST( CVirtualTreeNode, vtn_lnInDirectory, vtn_lhChildren, litDel)
{
delete &litDel.Current();
}
vtn_bIsDirectory=TRUE;
vnt_pvtnParent=NULL;
vtn_Handle=NULL;
vtn_itIconType=0;
vtn_bmBrowsingMode=BM_ICONS_MEDIUM;
vtn_bSelected=FALSE;
vtn_pTextureData=NULL;
vtn_strName="VRT not loaded";
vtn_fnItem=CTString("");
}
void CVirtualTreeNode::MoveToDirectory(CVirtualTreeNode *pVTNDst)
{
ASSERT( vnt_pvtnParent!=NULL);
if( vnt_pvtnParent==NULL) return;
vnt_pvtnParent=pVTNDst;
vtn_lnInDirectory.Remove();
pVTNDst->vtn_lhChildren.AddTail( vtn_lnInDirectory);
}