AeFieldUI.c++
3.94 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
#include <assert.h>
#include <string.h>
#include <math.h>
#include <Vk/VkApp.h>
#include "AeTypes.h"
#include "AeFieldUI.h"
#include "AeAsset.h"
#include "AeAssetUI.h"
#include "AeBinView.h"
double AeFieldUI::fLabel2CellFontRatio = 1.0;
AeFieldUI::AeFieldUI (const char * name,
Boolean isEditable,
Boolean isSelectable,
Boolean isHierarchical,
Boolean isCommon,
TJustify justify,
int maxLen)
{
strcpy (fName, name);
fJustify = justify;
fIsEditable = isEditable;
fIsSelectable = isSelectable;
fIsHierarchical = isHierarchical;
fIsCommon = isCommon;
fMaxLen = maxLen;
fMaxWidth = kMaxWidth;
fWidth = 0;
fNeedsWidthUpdate = False; // Will be set to True only by UpdateWidth
fNeedsWidthRecalc = True; // Force calculation of field width
// Since text widths are calculated using the text font, adjust the
// label width by the width ratio between cell font and label font.
// Otherwise, labels may get clipped in the UI.
fLabelWidth = (int)ceil(((double)strlen (name) * fLabel2CellFontRatio)) + 1;
}
AeFieldUI::~AeFieldUI (void)
{
}
void
AeFieldUI::GetValueString (AeAsset * asset, String string)
{
assert (1); // pure virtual called
}
Boolean
AeFieldUI::SetValueString (AeAsset * asset, String string)
{
assert (1); // pure virtual called
return False;
}
Boolean
AeFieldUI::VerifyValueString (String string)
{
assert (1); // pure virtual called
return True;
}
Boolean
AeFieldUI::VerifyInput (XmTextVerifyCallbackStruct * verify, const char * prevStr)
{
return True; // default to a valid string
}
void
AeFieldUI::SetWidth (int width)
{
if (width < kMinWidth)
width = kMinWidth;
else if (width > kMaxWidth)
width = kMaxWidth;
fWidth = width;
fNeedsWidthRecalc = False;
}
Boolean
AeFieldUI::HandleButtonPress (AeBinEditor * editor,
AeAssetUI * assetUI,
XEvent * event,
TEditModifier modifier)
{
return False; // default action is to do nothing
}
void
AeFieldUI::HandleDoubleClick (AeBinEditor * editor,
AeAssetUI * assetUI,
XEvent * event,
TEditModifier modifier)
{
}
//
// This routine helps keep field widths up to date.
// Whenever a new value is inserted into a field, call
// this routine with the string form of the new value
// to update fWidth. If fWidth must be recalculated
// a flag is set to indicate that the field needs
// updating.
//
void
AeFieldUI::UpdateWidth (String newString, String oldString)
{
int width;
fNeedsWidthUpdate = False;
width = strlen(newString);
if (width < kMinWidth)
width = kMinWidth;
else if (width > kMaxWidth)
width = kMaxWidth;
// if the width is greater than the current width, update the width
if (width > fWidth)
{
fWidth = width;
fNeedsWidthUpdate = True;
}
// else if the width is less than the current width and the string
// being replaced is equal to the current width, then
// we need to recalculate fWidth to find the new max.
else if (width < fWidth)
{
width = strlen(oldString);
if (width == fWidth)
fNeedsWidthRecalc = fNeedsWidthUpdate = True;
}
}
void
AeFieldUI::CalcListFontRatio (void)
{
XrmDatabase appDB;
char resFileName[256];
char * resType[20];
XrmValue resValue;
XFontStruct * labelStruct;
XFontStruct * cellStruct;
XrmInitialize ();
(void) strcpy (resFileName, "ae-defaults");
if (appDB = XrmGetFileDatabase (resFileName))
{
if (XrmGetResource(appDB, "labelFont", "", resType, &resValue) == True)
labelStruct = XLoadQueryFont (theApplication->display (), (char *)resValue.addr);
if (XrmGetResource(appDB, "cellFont", "", resType, &resValue) == True)
cellStruct = XLoadQueryFont (theApplication->display (), (char *)resValue.addr);
if (labelStruct && cellStruct)
AeFieldUI::fLabel2CellFontRatio = (double)labelStruct->max_bounds.width / (double)cellStruct->max_bounds.width;
}
}