AeAssetUI.c++
3.34 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <string.h>
#include <assert.h>
#include <Xm/Xm.h>
#include "AeTypes.h"
#include "AeAssetUI.h"
#include "AeFieldUI.h"
const char kShiftString[] = " ";
AeAssetUI::AeAssetUI (AeAsset * asset)
{
fAsset = asset;
fRow = 0;
fLevel = 0;
fIsOpen = False;
}
AeAssetUI::~AeAssetUI (void)
{
}
void
AeAssetUI::SetRow (int row)
{
assert (row >= 0);
fRow = row;
}
void
AeAssetUI::SetLevel (int level)
{
assert (level >= 0);
fLevel = level;
}
void
AeAssetUI::SetOpen (Boolean isOpen)
{
if (fAsset->CanContain ())
fIsOpen = isOpen;
}
Boolean
AeAssetUI::IsEditable (AeFieldUI * fieldUI)
{
assert (fieldUI);
if (!isFieldInUI (fieldUI))
return False;
return fieldUI->IsEditable (fAsset);
}
TAssetType
AeAssetUI::GetType (void)
{
return fAsset->GetType ();
}
Pixmap
AeAssetUI::GetIcon (void)
{
return fAsset->GetIcon ();
}
void
AeAssetUI::GetFieldString (AeFieldUI * fieldUI, String string)
{
assert (fieldUI);
if (!isFieldInUI (fieldUI))
{
*string = '\0';
}
else
{
// otherwise, get the field's string and make it look nice
// if we have to.
fieldUI->GetValueString (fAsset, string);
// If the field is hierarchical and the asset is not at the top level
// shift the string over to indicate it's place in the hierarchy.
if (fLevel && fieldUI->IsHierarchical ())
shiftString (string);
}
}
Boolean
AeAssetUI::VerifyAndSetFieldString (AeFieldUI * fieldUI, String string, Boolean * pChanged)
{
Boolean okay = False;
assert (fieldUI);
assert (IsEditable (fieldUI));
// always strip leading spaces. spaces used for hierarchical display.
stripString (string);
if (fieldUI->VerifyValueString (string))
{
TString63 oldString;
// get the current "old" string
fieldUI->GetValueString (fAsset, oldString);
if (*pChanged = fieldUI->SetValueString (fAsset, string))
updateWidth (fieldUI, string, oldString);
okay = True;
}
return okay;
}
void
AeAssetUI::updateWidth (AeFieldUI * fieldUI, String string, String oldString)
{
TString63 newString;
// make a copy of the string
strcpy (newString, string);
// shift the strings if necessary
if (fLevel && fieldUI->IsHierarchical ())
{
shiftString (oldString);
shiftString (newString);
}
// ask the field to update its width variables
fieldUI->UpdateWidth (newString, oldString);
}
void
AeAssetUI::shiftString (String string)
{
char tempString[kNameMaxLen];
int i, level;
// copy the string so we can insert spaces in front of it
strcpy (tempString, string);
// make sure we don't exceed the allocated string length
level = (kNameMaxLen - strlen(string))/strlen(kShiftString);
if (level > fLevel)
level = fLevel;
// insert spaces for each level down in the hierarchy
*string = '\0';
for (i=0; i<level; i++)
strcat (string, kShiftString);
// append the string to the inserted spaces
strcat (string, tempString);
}
void
AeAssetUI::stripString (String string)
{
char * p = string;
while (*p == ' ')
p++;
if (p != string)
strcpy (string, p);
}
// if the assetUI is not at the top of the hierarchy,
// then see if its fields match the top field and if it doesn't
// the don't display anything.
Boolean
AeAssetUI::isFieldInUI (AeFieldUI * fieldUI)
{
return fLevel == 0 || fieldUI->IsCommon ();
}