Repository navigation
Expand file tree
/
Copy pathLayoutInput.cpp
More file actions
342 lines (327 loc) · 9.63 KB
/
Copy pathLayoutInput.cpp
File metadata and controls
342 lines (327 loc) · 9.63 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
// LayoutInput.cpp : clicking and double clicking the cells of the Layout tab's lists.
//
// A click selects the value in the hex view (and makes it the value "Change Value" writes). A double click opens
// what the value refers to (a string, a bitmap, a layout, a font, a command) or lets the value be changed (colors,
// the style and the position of text).
#include "stdafx.h"
#include "iPodWizard.h"
#include "LayoutDialog.h"
typedef PixoScript::Ref Ref;
// Where the value in a list column of a layout element is stored, relative to the start of the element
void CLayoutDialog::ViewCellRegion(const resource_type_view_elem *e, int col, DWORD *pOffset, DWORD *pSize)
{
const BYTE *b = (const BYTE *)e;
*pOffset = 0;
*pSize = 0;
CLayoutAttrs::Extra x;
CLayoutAttrs::ExtraOf(e, &x);
switch (col)
{
case 0: *pOffset = 0; *pSize = 4; break;
case 1: *pOffset = 4; *pSize = 4; break;
case 2: *pOffset = 8; *pSize = 4; break;
case 3: *pOffset = 12; *pSize = 2; break;
case 4: *pOffset = 14; *pSize = 2; break;
case 5: *pOffset = 16; *pSize = 4; break;
case 6: *pOffset = 20; *pSize = 4; break;
case 7: *pOffset = 24; *pSize = 2; break;
case 8: *pOffset = 26; *pSize = 2; break;
case 9: *pOffset = (DWORD)((const BYTE *)&e->left.val - b); *pSize = 4; break;
case 10: *pOffset = (DWORD)((const BYTE *)&e->top.val - b); *pSize = 4; break;
case 11: *pOffset = (DWORD)((const BYTE *)&e->right.val - b); *pSize = 4; break;
case 12: *pOffset = (DWORD)((const BYTE *)&e->bottom.val - b); *pSize = 4; break;
case 13: *pOffset = 76; *pSize = x.gradient ? 4 : 0; break;
case 14: *pOffset = 80; *pSize = x.gradient ? 4 : 0; break;
case 15: *pOffset = 76; *pSize = 0; break;
case 18: *pOffset = (DWORD)((const BYTE *)&e->left - b); *pSize = 8; break; // the descriptors: reference, mode and flag of each edge
case 19: *pOffset = (DWORD)((const BYTE *)&e->top - b); *pSize = 8; break;
case 20: *pOffset = (DWORD)((const BYTE *)&e->right - b); *pSize = 8; break;
case 21: *pOffset = (DWORD)((const BYTE *)&e->bottom - b); *pSize = 8; break;
case 16:
if (x.text >= 0)
{
*pOffset = 76 + 4 * x.text + 2; // the high half of the {string, font type} value
*pSize = 2;
}
else
*pOffset = 76;
break;
}
}
void CLayoutDialog::OnLvnItemClickedResourceList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMLV = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (m_ResourceList.GetFirstSelectedItemPosition()<=0)
return;
if (pNMLV->iItem==-1)
return;
int iItem=pNMLV->iItem;
int col=pNMLV->iSubItem;
m_ClickedCol=(m_ResourceType==1) ? MenuLogicalCol(col) : col; // for a menu: the field its column shows
m_bLinkClick=false;
// a marked part of a cell: the bytes it stands for are shown in the hex view
{
int hitItem, hitSub, hitLink;
if (m_ResourceList.HitLink(pNMLV->ptAction, &hitItem, &hitSub, &hitLink))
{
const std::vector<CCellLink> *pLinks=m_ResourceList.GetCellLinks(hitItem, hitSub);
if (pLinks!=NULL && hitLink<(int)pLinks->size())
{
ShowLink(pLinks->at(hitLink));
UpdateData(FALSE);
return;
}
}
}
int sel_id=_ttoi(m_ResourceTree.GetItemText(m_ResourceTree.GetSelectedItem()));
LPBYTE lpBuf=m_pFirmware->GetFirmwareBuffer();
DWORD j, rel=0, sz=0;
const BYTE *base=NULL;
switch(m_ResourceType)
{
case 0: //view
for (j = 0; j < ViewList->size(); j++)
if (ViewList->at(j)->id==sel_id)
{
if (iItem < ViewList->at(j)->num_elems)
{
const resource_type_view_elem *e=ViewList->at(j)->ViewElemList[iItem]->element;
ViewCellRegion(e, col, &rel, &sz);
base=(const BYTE *)e;
}
break;
}
break;
case 1: //menu
for (j = 0; j < MenuList->size(); j++)
if (MenuList->at(j)->id==sel_id)
{
if (iItem < MenuList->at(j)->num_elems)
{
const resource_type_menu_elem *e=MenuList->at(j)->MenuElemList[iItem]->element;
if (MenuLogicalCol(col)<=12)
m_Attrs.MenuField(MenuLogicalCol(col), &rel, &sz);
base=(const BYTE *)e;
}
break;
}
break;
case 2: //type
{
TypeRecord *pType=SelectedType();
if (pType!=NULL && iItem==0)
{
static const DWORD toff[7]={0,2,4,8,12,13,14};
static const DWORD tsz[7]={2,2,4,4,1,1,2};
if (col>=0 && col<7)
{
rel=toff[col];
sz=tsz[col];
}
base=(const BYTE *)pType->element;
}
}
break;
case 3: //commands
case 4:
CmdSelectRow(iItem);
break;
}
if (base!=NULL)
{
DWORD iOffset=(DWORD)(base-lpBuf)+rel;
m_ValSize=sz;
m_ValOffset=iOffset;
m_HexWnd.SetRange(iOffset, sz);
}
UpdateData(FALSE);
RefreshChangeCue();
}
void CLayoutDialog::OnLvnItemDblClickedResourceList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMLV = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (m_ResourceList.GetFirstSelectedItemPosition()<=0 && *pResult!=1)
return;
if (pNMLV->iItem==-1)
return;
int iItem=pNMLV->iItem;
int col=pNMLV->iSubItem;
int sel_id=_ttoi(m_ResourceTree.GetItemText(m_ResourceTree.GetSelectedItem()));
LPBYTE lpBuf=m_pFirmware->GetFirmwareBuffer();
CPoint pt(pNMLV->ptAction);
m_ResourceList.ClientToScreen(&pt);
HWND hEditor=::GetParent(::GetParent(m_hWnd));
DWORD j;
switch(m_ResourceType)
{
case 0: //view
for (j = 0; j < ViewList->size(); j++)
if (ViewList->at(j)->id==sel_id)
break;
if (j==ViewList->size() || iItem>=ViewList->at(j)->num_elems)
return;
{
const resource_type_view_elem *e=ViewList->at(j)->ViewElemList[iItem]->element;
CLayoutAttrs::Extra x;
CLayoutAttrs::ExtraOf(e, &x);
switch (col)
{
case 3: //what the element shows
if (CLayoutAttrs::IsKind(e, " rtS"))
{
int sid=e->id!=0 ? e->id : (x.text>=0 ? (short)(x.p[x.text] & 0xFFFF) : 0);
if (sid!=0)
::SendMessage(hEditor, WM_APP, (WPARAM)11, (LPARAM)sid);
}
else if (CLayoutAttrs::IsKind(e, "paMB"))
::SendMessage(hEditor, WM_APP, (WPARAM)12, (LPARAM)m_pFirmware->GetPictureIndexFromID((DWORD)e->id));
else if (CLayoutAttrs::IsKind(e, "enoN") && e->id!=0)
{
for (DWORD k = 0; k < ViewList->size(); k++)
if (ViewList->at(k)->id==e->id)
{
SelectResource(0, e->id);
break;
}
}
break;
case 5: //numbers that may be the ID of something
case 6:
{
Ref r;
r.type=PixoScript::REF_CONSTANT;
r.value=col==5 ? e->z1 : e->z2;
std::vector<PixoScript::Ref> refs;
refs.push_back(r);
GoToRef(refs, pt);
}
break;
case 13: //the two colors of a gradient
case 14:
{
DWORD o1, o2;
if (!m_Attrs.ViewColorOffsets(e, &o1, &o2))
{
MessageBox(_T("This element has no gradient colors."));
break;
}
DWORD off=col==13 ? o1 : o2;
PickColor((DWORD)((const BYTE *)e-lpBuf)+off, *(const DWORD *)((const BYTE *)e+off));
}
break;
case 16: //the font of a text
{
int ft=m_Attrs.ViewFontType(e);
if (ft!=0)
SelectResource(2, ft);
}
break;
}
}
break;
case 1: //menu
for (j = 0; j < MenuList->size(); j++)
if (MenuList->at(j)->id==sel_id)
break;
if (j==MenuList->size() || iItem>=MenuList->at(j)->num_elems)
return;
{
const resource_type_menu_elem *e=MenuList->at(j)->MenuElemList[iItem]->element;
switch (MenuLogicalCol(col))
{
case 2: //commands: opened from the ID columns only
case 3:
if (col!=2 && col!=4)
break;
{
int fn=CCommandTable::RefToFunction(MenuLogicalCol(col)==2 ? e->z2 : e->cmd);
if (fn>=0 && m_Commands.FindFunction(fn)!=NULL)
SelectResource(3, fn);
}
break;
case 4: //an ID
{
Ref r;
r.type=PixoScript::REF_CONSTANT;
r.value=e->submenuID;
std::vector<PixoScript::Ref> refs;
refs.push_back(r);
GoToRef(refs, pt);
}
break;
case 6: //the text
::SendMessage(hEditor, WM_APP, (WPARAM)11, (LPARAM)m_Attrs.MenuTextId(e));
break;
case 10:
::SendMessage(hEditor, WM_APP, (WPARAM)11, (LPARAM)e->textID2);
break;
case 8: //numbers that may be the ID of something
case 9:
{
DWORD off, size;
m_Attrs.MenuField(MenuLogicalCol(col), &off, &size);
DWORD v=*(const DWORD *)((const BYTE *)e+off);
std::vector<PixoScript::Ref> refs;
Ref r;
r.type=PixoScript::REF_CONSTANT;
r.value=(int)(v & 0xFFFF);
refs.push_back(r);
if (v>>16)
{
r.value=(int)(v>>16);
refs.push_back(r);
}
GoToRef(refs, pt);
}
break;
case 12: //the font
if (e->typeID!=0)
SelectResource(2, e->typeID);
else if (m_Attrs.MenuDefaultFont(MenuList->at(j)->id)!=0)
SelectResource(2, m_Attrs.MenuDefaultFont(MenuList->at(j)->id));
break;
}
}
break;
case 2: //type
if (SelectedType()==NULL)
return;
{
resource_type_type_elem *e=SelectedType()->element;
DWORD base=(DWORD)((const BYTE *)e-lpBuf);
switch (col)
{
case 0: //the name of the font
::SendMessage(hEditor, WM_APP, (WPARAM)11, (LPARAM)e->fontID);
break;
case 2: //the font itself
::SendMessage(hEditor, WM_APP, (WPARAM)13, (LPARAM)e);
break;
case 3: //the color
PickColor(base+8, e->color);
break;
case 4: //style: set in the hex value, no chooser
break;
case 7: //where the font is used: go there
if (iItem<(int)m_TypeUses.size())
{
CLayoutAttrs::TypeUse u=m_TypeUses[iItem];
SelectResource(u.kind==CLayoutAttrs::TU_MENU ? 1 : 0, u.id, u.row, u.offset, u.size, u.kind==CLayoutAttrs::TU_MENU ? 12 : (u.kind==CLayoutAttrs::TU_LIST ? 3 : 16));
}
break;
case 5: //position of the text
{
static const TCHAR *const aligns[3]={ _T("Left (0)"), _T("Center (1)"), _T("Right (2)") };
PickValue(aligns, 3, e->alignment, base+13, 1);
}
break;
}
}
break;
case 3: //commands
case 4:
CmdActivateRow(iItem, pt);
break;
}
UpdateData(FALSE);
}