AeBinEditorEdit.c++
8.29 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//
// AeBinEditorEdit.c++
//
// Routines for handling UI edit events
//
#include <assert.h>
#include <Xm/Xm.h>
#include "Matrix.h"
#include "GList.h"
#include "AeBinEditor.h"
#include "AeAssetBase.h"
#include "AeAssetBin.h"
#include "AeAssetBinUI.h"
#include "AeAssetUI.h"
#include "AeFieldUI.h"
#include "AeBinView.h"
#include "AePlayer.h"
XrmQuark AeBinEditor::qLeft = 0;
XrmQuark AeBinEditor::qRight = 0;
XrmQuark AeBinEditor::qUp = 0;
XrmQuark AeBinEditor::qDown = 0;
AeBinEditor * AeBinEditor::fMenuEditor = NULL;
AeAssetUI * AeBinEditor::fMenuAssetUI = NULL;
AeFieldUI * AeBinEditor::fMenuFieldUI = NULL;
void
AeBinEditor::EnterCell (Widget list, XbaeMatrixEnterCellCallbackStruct * ecData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, ecData->row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, ecData->column);
if (fieldUI && assetUI)
{
assert (assetUI->GetRow () == ecData->row);
ecData->doit = assetUI->IsEditable (fieldUI);
ecData->select_text = True; // Always select text for editing
}
}
void
AeBinEditor::LeaveCell (Widget list, XbaeMatrixLeaveCellCallbackStruct * lcData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
Boolean changed;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, lcData->row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, lcData->column);
if (fieldUI && assetUI)
{
assert (assetUI->GetRow () == lcData->row);
if (lcData->doit = assetUI->VerifyAndSetFieldString (fieldUI, lcData->value, &changed))
{
if (changed)
fAssetBase->NotifyUpdate (assetUI->GetAsset ());
}
}
}
void
AeBinEditor::ModifyVerify (Widget list, XbaeMatrixModifyVerifyCallbackStruct * mvData)
{
AeFieldUI * fieldUI;
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, mvData->column);
if (fieldUI)
mvData->verify->doit = fieldUI->VerifyInput (mvData->verify, mvData->prev_text);
}
void
AeBinEditor::DrawCell (Widget list, XbaeMatrixDrawCellCallbackStruct * dcData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, dcData->row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, dcData->column);
if (fieldUI && assetUI)
{
assert (assetUI->GetRow () == dcData->row);
if (assetUI->GetAsset()->IsSelected())
{
dcData->foreground = fView->ListGetSelectForeground ();
dcData->background = fView->ListGetSelectBackground ();
}
if (fieldUI->IsIcon ())
{
dcData->type = XbaePixmap;
dcData->pixmap = assetUI->GetIcon ();
if ((assetUI->GetAsset())->IsOnline ())
dcData->foreground = fView->ListGetOnlineColor ();
}
else
{
dcData->type = XbaeString;
assetUI->GetFieldString (fieldUI, dcData->string);
}
}
}
void
AeBinEditor::SelectCell (Widget list, XbaeMatrixSelectCellCallbackStruct * scData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
TEditModifier modifier;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, scData->row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, scData->column);
if (fieldUI && assetUI)
{
assert (assetUI->GetRow () == scData->row);
modifier = params2modifier (scData->num_params, scData->params);
// if the alt key was clicked, then text edit the value
if (modifier == kModAlt && assetUI->IsEditable (fieldUI))
XbaeMatrixEditCell (list, scData->row, scData->column);
// else let the field handle it specially
else
{
if (!fieldUI->HandleButtonPress (this, assetUI, scData->event, modifier))
if (assetUI->IsEditable (fieldUI))
XbaeMatrixEditCell (list, scData->row, scData->column);
}
}
}
void
AeBinEditor::TraverseCell (Widget list, XbaeMatrixTraverseCellCallbackStruct * tcData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
tcData->next_row = tcData->row;
tcData->next_column = tcData->column;
do
{
if (tcData->qparam == qDown)
{
if (++tcData->next_row >= tcData->num_rows)
tcData->next_row = 0;
}
else if (tcData->qparam == qUp)
{
if (--tcData->next_row < 0)
tcData->next_row = tcData->num_rows - 1;
}
else if (tcData->qparam == qLeft)
{
if (--tcData->next_column < 0)
tcData->next_column = tcData->num_columns - 1;
}
else if (tcData->qparam == qRight)
{
if (++tcData->next_column >= tcData->num_columns)
tcData->next_column = 0;
}
else
return;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, tcData->next_row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, tcData->next_column);
} while (!assetUI->IsEditable (fieldUI));
}
void
AeBinEditor::DefaultAction (Widget list, XbaeMatrixDefaultActionCallbackStruct * daData)
{
AeAssetUI * assetUI;
AeFieldUI * fieldUI;
assetUI = (AeAssetUI *)XbaeMatrixGetRowUserData (list, daData->row);
fieldUI = (AeFieldUI *)XbaeMatrixGetColumnUserData (list, daData->column);
if (fieldUI && assetUI)
fieldUI->HandleDoubleClick (this, assetUI, daData->event, kModNone);
}
void
AeBinEditor::MenuCallback (Widget list, XtPointer value, XtPointer callData)
{
assert (AeBinEditor::fMenuEditor);
assert (AeBinEditor::fMenuFieldUI);
assert (AeBinEditor::fMenuAssetUI);
AeBinEditor::fMenuEditor->SetAssetFieldValue (AeBinEditor::fMenuAssetUI,
AeBinEditor::fMenuFieldUI,
value);
}
void
AeBinEditor::SetAssetFieldValue (AeAssetUI * assetUI, AeFieldUI * fieldUI, XtPointer value)
{
if (fieldUI->SetValue (assetUI->GetAsset (), value))
fAssetBase->NotifyUpdate (assetUI->GetAsset ());
}
void
AeBinEditor::SelectAssetUI (AeAssetUI * assetUI, TEditModifier modifier)
{
assert (assetUI);
assert (fAssetBase);
assert (fSelectionList);
static AeAssetUI * lastAssetUI = NULL;
static AeAssetUI * pivotAssetUI = NULL;
if (modifier == kModMotion && lastAssetUI == assetUI)
return;
// if we're dragging out a selection, then select or
// deselect all the assets in between the current assetUI
// and the last assetUI
if (modifier == kModMotion)
{
AeAssetUI * aUI;
int startRow, endRow, nRows, i;
int lastRow = lastAssetUI->GetRow ();
int curRow = assetUI->GetRow ();
int pivotRow = pivotAssetUI->GetRow ();
assert (lastAssetUI);
assert (pivotAssetUI);
// select or deselect items from the pivot point
// and downwards (larger row numbers)
if (lastRow > pivotRow || curRow > pivotRow)
{
if (lastRow < curRow)
{
startRow = lastRow;
endRow = curRow;
}
else
{
startRow = curRow;
endRow = lastRow;
}
// clip startRow to the pivotRow
if (startRow < pivotRow)
startRow = pivotRow;
nRows = endRow - startRow;
for (i=startRow+1; --nRows>=0; i++)
{
aUI = (AeAssetUI *)XbaeMatrixGetRowUserData (fView->ListGetWidget (), i);
aUI->GetAsset()->ToggleSelect ();
fAssetBase->NotifySelect (aUI->GetAsset ());
}
}
// select or deselect items from the pivot point
// and upwards (smaller row numbers)
if (lastRow < pivotRow || curRow < pivotRow)
{
if (lastRow > curRow)
{
startRow = lastRow;
endRow = curRow;
}
else
{
startRow = curRow;
endRow = lastRow;
}
// clip startRow to the pivotRow
if (startRow > pivotRow)
startRow = pivotRow;
nRows = startRow - endRow;
for (i=startRow-1; --nRows>=0; i--)
{
aUI = (AeAssetUI *)XbaeMatrixGetRowUserData (fView->ListGetWidget (), i);
aUI->GetAsset()->ToggleSelect ();
fAssetBase->NotifySelect (aUI->GetAsset ());
}
}
}
else if (modifier == kModDown || modifier == kModShift)
{
Boolean selected = assetUI->GetAsset()->IsSelected ();
// if selection was exclusive clear all other selections
if (modifier == kModDown)
DeselectAllAssets ();
// select if it wasn't originally selected
if (!selected)
{
assetUI->GetAsset()->SetSelect (True);
fAssetBase->NotifySelect (assetUI->GetAsset ());
}
pivotAssetUI = assetUI;
}
lastAssetUI = assetUI;
}
TEditModifier
AeBinEditor::params2modifier (int nParams, String * params)
{
if (nParams)
{
if (!strcmp (*params, "Shift"))
return kModShift;
if (!strcmp (*params, "Alt"))
return kModAlt;
if (!strcmp (*params, "Down"))
return kModDown;
if (!strcmp (*params, "Motion"))
return kModMotion;
if (!strcmp (*params, "Up"))
return kModUp;
}
return kModNone;
}