Repository navigation
Expand file tree
/
Copy pathEditorDialog.cpp
More file actions
349 lines (321 loc) · 10.8 KB
/
Copy pathEditorDialog.cpp
File metadata and controls
349 lines (321 loc) · 10.8 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
#include "stdafx.h"
#include "iPodWizard.h"
#include "EditorDialog.h"
IMPLEMENT_DYNAMIC(CEditorDialog, CDarkDialog)
CEditorDialog::CEditorDialog(CWnd* pParent /*=NULL*/)
: CDarkDialog(CEditorDialog::IDD, pParent)
, bFonts(FALSE)
, bOTFCreate(FALSE)
, m_pThemePreview(NULL)
{
}
CEditorDialog::~CEditorDialog()
{
}
void CEditorDialog::DoDataExchange(CDataExchange* pDX)
{
CDarkDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROP_TAB, m_PropsTab);
}
BEGIN_MESSAGE_MAP(CEditorDialog, CDarkDialog)
ON_NOTIFY(TCN_SELCHANGE, IDC_PROP_TAB, OnTcnSelchangePropTab)
ON_MESSAGE(WM_APP, OnSwitchFontSystem)
ON_WM_SIZE()
END_MESSAGE_MAP()
BOOL CEditorDialog::OnInitDialog()
{
CDarkDialog::OnInitDialog();
// initialize pages
CRect rect;
m_PropsTab.InsertItem(TAB_PICTURES, TEXT("Graphics"));
m_PropsTab.InsertItem(TAB_FONTS, TEXT("Fonts"));
m_PropsTab.InsertItem(TAB_STRINGS, TEXT("Strings"));
m_PropsTab.InsertItem(TAB_LAYOUT, TEXT("Layout"));
m_PropsTab.InsertItem(TAB_MENUS, TEXT("Menus"));
m_PropsTab.InsertItem(TAB_TYPES, TEXT("Font Types"));
m_PropsTab.InsertItem(TAB_COMMANDS, TEXT("Commands"));
m_PropsTab.InsertItem(TAB_TWEAKS, TEXT("Tweaks"));
m_PropsTab.UpdateGaps();
m_PicsDialog.Create(m_PicsDialog.IDD, &m_PropsTab);
m_FontsDialog.Create(m_FontsDialog.IDD, &m_PropsTab);
m_StringDialog.Create(m_StringDialog.IDD, &m_PropsTab);
m_OTFDialog.Create(m_OTFDialog.IDD, &m_PropsTab);
m_LayoutDialog.Create(m_LayoutDialog.IDD, &m_PropsTab);
m_TweaksDialog.Create(m_TweaksDialog.IDD, &m_PropsTab);
m_PropsTab.GetClientRect(&rect);
m_PropsTab.AdjustRect(FALSE, &rect);
m_PicsDialog.MoveWindow(rect);
m_FontsDialog.MoveWindow(rect);
m_StringDialog.MoveWindow(rect);
m_OTFDialog.MoveWindow(rect);
m_LayoutDialog.MoveWindow(rect);
m_TweaksDialog.MoveWindow(rect);
UpdatePages(FALSE);
return TRUE;
}
void CEditorDialog::OnOK()
{
// TODO: Add your specialized code here and/or call the base class
// CDarkDialog::OnOK();
}
void CEditorDialog::SetPreviewButton(CWnd *pWnd)
{
m_pThemePreview = pWnd;
}
//Switch page when user clicked OTF Fonts/Bitmap Fonts
LRESULT CEditorDialog::OnSwitchFontSystem(WPARAM wParam, LPARAM lParam)
{
if (wParam == NULL)
return 0;
if (m_pFirmware==NULL)
return 0;
int mg=(int)wParam;
CString temp;
CIpodFont fnt;
COTFFont ofnt;
bool found;
switch(mg)
{
case 10:
bFonts=(BOOL)lParam;
UpdatePages(bFonts);
break;
case 11:
m_StringDialog.m_Langidx.SetCurSel(m_StringDialog.m_Langidx.GetCount()-2);
m_StringDialog.OnCbnSelchangeLangidxCombo();
LRESULT Result;
NMLISTVIEW dNMHDR;
dNMHDR.uOldState = 0;
temp.Format(_T("%d"), (int)lParam);
int i;
for (i=0;i<m_StringDialog.m_LangStringList.GetItemCount();i++)
{
if (m_StringDialog.m_LangStringList.GetItemText(i, 0).Compare(temp)==0)
break;
}
if (i!=m_StringDialog.m_LangStringList.GetItemCount())
{
m_StringDialog.m_LangStringList.SetSelectionMark(i);
LVITEM lim;
lim.mask=LVIF_STATE;
lim.iItem=i;
lim.stateMask=LVIS_SELECTED;
lim.state=LVIS_SELECTED;
lim.iSubItem=0;
m_StringDialog.m_LangStringList.SetItem(&lim);
m_StringDialog.m_LangStringList.EnsureVisible(i, FALSE);
dNMHDR.iItem = i;
m_StringDialog.OnLvnItemchangedLangstringList((NMHDR *)&dNMHDR, &Result);
m_PropsTab.SetCurSel(TAB_STRINGS);
UpdatePages(bFonts);
}
else
MessageBox(_T("String not found in firmware, it may be generated on the fly by the iPod's program."));
break;
case 12:
//if (m_PicsDialog.m_PicIndexCombo.GetCurSel()!=(int)lParam)
if ((DWORD)lParam==0xFFFFFFFF)
MessageBox(_T("Picture not found in firmware, it may be generated on the fly by the iPod's program."));
else
{
m_PicsDialog.m_PicIndexCombo.SetCurSel((int)lParam);
m_PicsDialog.OnCbnSelchangePicidxCombo();
m_PropsTab.SetCurSel(TAB_PICTURES);
UpdatePages(bFonts);
}
break;
case 13:
resource_type_type_elem *type;
type=(resource_type_type_elem *)lParam;
DWORD j;
int k;
LPBYTE lpEnd;
lpEnd=m_pFirmware->GetFirmwareBuffer()+m_pFirmware->GetFirmwareSize();
found=false;
unsigned char fstyle;
fstyle=type->style;
for (j=0;j<m_pFirmware->GetNumLangStrings(m_pFirmware->GetNumLangs()-1);j++)
{
if (m_pFirmware->GetLangStringID(m_pFirmware->GetNumLangs()-1, j)==type->fontID)
{
unsigned char style=0;
wchar_t *sOut;
Utf8Decode((char *)m_pFirmware->GetLangString(m_pFirmware->GetNumLangs()-1, j), &sOut);
// The font menu (the Fonts page) is where a font is shown. The OpenType page only gets the click when the firmware
// has no font of this name, size and style for the Fonts page.
bool hasBitmap;
hasBitmap=false;
for (k=0;(DWORD)k<m_pFirmware->GetNumFonts();k++)
if (fnt.Read(m_pFirmware->GetFont(k), lpEnd)==TRUE && !wcscmp(fnt.GetFontName(), sOut) && fnt.GetFontSize()==type->size && fnt.GetFontStyleID()==fstyle)
{
hasBitmap=true;
break;
}
for (k=0;!hasBitmap && (DWORD)k<m_pFirmware->GetNumOTFFonts();k++)
{
if (ofnt.Read(m_pFirmware->GetOTFFont(k), TRUE))
{
if (!wcscmp(ofnt.GetFontStyle(), _T("Bold")))
style=0;
else if (!wcscmp(ofnt.GetFontStyle(), _T("Regular")))
style=1;
if (!wcscmp(ofnt.GetFontName(), sOut) && ofnt.GetFontSize()==type->size && fstyle==style)
{
m_OTFDialog.m_FontIndexCombo.SetCurSel(m_pFirmware->GetNumFonts() + k);
m_OTFDialog.OnCbnSelchangeFontidxCombo();
bFonts=TRUE;
m_PropsTab.SetCurSel(TAB_FONTS);
UpdatePages(bFonts);
found=true;
break;
}
}
}
for (k=0;(DWORD)k<m_pFirmware->GetNumFonts();k++)
{
if (fnt.Read(m_pFirmware->GetFont(k), lpEnd)==TRUE)
{
if (!wcscmp(fnt.GetFontStyle(), _T("Bold")))
style=1;
else if (!wcscmp(fnt.GetFontStyle(), _T("Regular")))
style=0;
if (!wcscmp(fnt.GetFontName(), sOut) && fnt.GetFontSize()==type->size && fnt.GetFontStyleID()==fstyle)
{
bFonts=FALSE;
m_FontsDialog.m_FontIndexCombo.SetCurSel(k);
m_FontsDialog.OnCbnSelchangeFontidxCombo();
m_PropsTab.SetCurSel(TAB_FONTS);
UpdatePages(bFonts);
found=true;
break;
}
}
}
delete sOut;
break;
}
}
if (found==false)
MessageBox(_T("Font not found in firmware, it may be generated on the fly by the iPod's program."));
break;
case 14:
// an entry of the list of fonts that the page that is shown does not edit (the list is the bitmap fonts, then the OpenType ones)
{
DWORD sel = (DWORD)lParam;
if (sel < m_pFirmware->GetNumFonts())
{
bFonts=FALSE;
m_FontsDialog.m_FontIndexCombo.SetCurSel((int)sel);
m_FontsDialog.OnCbnSelchangeFontidxCombo();
}
else
{
bFonts=TRUE;
m_OTFDialog.m_FontIndexCombo.SetCurSel((int)sel);
m_OTFDialog.OnCbnSelchangeFontidxCombo();
}
m_PropsTab.SetCurSel(TAB_FONTS);
UpdatePages(bFonts);
}
break;
case 21:
//show layouts dialog
m_PropsTab.SetCurSel(TAB_LAYOUT);
UpdatePages(bFonts);
break;
case 22:
//the layout editor changed its mode (0 layouts, 1 menus, 2 font types, 3 / 4 commands): the tab follows, but only
//when the layout editor is what is shown (loading a firmware must not take anyone away from the page they are on)
{
int cur = m_PropsTab.GetCurSel();
int want = (int)lParam == 4 ? TAB_COMMANDS : TAB_LAYOUT + (int)lParam; // both ways of showing the commands are one tab
if ((int)lParam >= 0 && (int)lParam <= 4 && cur >= TAB_LAYOUT && cur <= TAB_COMMANDS && cur != want)
{
m_PropsTab.SetCurSel(want);
UpdatePages(bFonts);
}
}
break;
default:
break;
}
return 0;
}
// The undo keys of the font editor also work when the focus is on the tabs (a click on a tab moves it there). They are only taken
// while the Fonts page is shown with its editor open: with the editor closed, or another tab shown, they are not.
BOOL CEditorDialog::PreTranslateMessage(MSG *pMsg)
{
if (m_FontsDialog.GetSafeHwnd() && m_FontsDialog.HandleUndoKey(pMsg))
return TRUE;
return CDarkDialog::PreTranslateMessage(pMsg);
}
void CEditorDialog::UpdatePages(BOOL bFonts)
{
int i = m_PropsTab.GetCurSel();
if (m_PropsTab.IsGap(i))
return;
// the tabs from "Layout" to "Commands" are the pages of one dialog, the layout editor
BOOL bLayout = i >= TAB_LAYOUT && i <= TAB_COMMANDS;
if (bLayout)
m_LayoutDialog.SetPage(i - TAB_LAYOUT);
// the font list has the focus (a font was picked, the arrow keys step through the fonts): it keeps it when the page of the other
// kind of font takes over, instead of the focus being lost with the page that goes
CWnd *pFocus = GetFocus();
bool bFontListFocus = pFocus != NULL && (pFocus->m_hWnd == m_FontsDialog.m_FontIndexCombo.m_hWnd || pFocus->m_hWnd == m_OTFDialog.m_FontIndexCombo.m_hWnd);
m_PicsDialog.ShowWindow(i == TAB_PICTURES ? SW_SHOW : SW_HIDE);
m_FontsDialog.ShowWindow(i == TAB_FONTS && !bFonts ? SW_SHOW : SW_HIDE);
m_OTFDialog.ShowWindow(i == TAB_FONTS && bFonts ? SW_SHOW : SW_HIDE);
if (bFontListFocus && i == TAB_FONTS)
(bFonts ? m_OTFDialog.m_FontIndexCombo : m_FontsDialog.m_FontIndexCombo).SetFocus();
m_StringDialog.ShowWindow(i == TAB_STRINGS ? SW_SHOW : SW_HIDE);
m_LayoutDialog.ShowWindow(bLayout ? SW_SHOW : SW_HIDE);
m_TweaksDialog.ShowWindow(i == TAB_TWEAKS ? SW_SHOW : SW_HIDE);
if (i == TAB_TWEAKS)
m_TweaksDialog.Refresh();
}
void CEditorDialog::SetFirmware(CFirmware *pFirmware)
{
//Initialize firmware on all sections
m_PicsDialog.SetFirmware(pFirmware, &m_LayoutDialog, m_pThemePreview);
m_FontsDialog.SetFirmware(pFirmware, &m_LayoutDialog);
m_OTFDialog.SetFirmware(pFirmware, &m_LayoutDialog);
m_StringDialog.SetFirmware(pFirmware);
m_LayoutDialog.SetFirmware(pFirmware);
m_TweaksDialog.SetFirmware(pFirmware);
m_TweaksDialog.Refresh();
m_pFirmware=pFirmware;
if (pFirmware->GetNumOTFFonts()==0) //if no OTF fonts then show only bitmap (even if before user was on OTF)
{
bFonts=FALSE;
UpdatePages(bFonts);
}
}
void CEditorDialog::OnSize(UINT nType, int cx, int cy)
{
CDarkDialog::OnSize(nType, cx, cy);
if (nType == SIZE_MINIMIZED || !IsWindow(m_PropsTab.GetSafeHwnd()))
return;
m_PropsTab.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
CRect clientRect;
m_PropsTab.GetClientRect(&clientRect);
m_PropsTab.AdjustRect(FALSE, &clientRect);
m_PicsDialog.MoveWindow(clientRect);
m_FontsDialog.MoveWindow(clientRect);
m_StringDialog.MoveWindow(clientRect);
m_OTFDialog.MoveWindow(clientRect);
m_LayoutDialog.MoveWindow(clientRect);
m_TweaksDialog.MoveWindow(clientRect);
}
void CEditorDialog::OnTcnSelchangePropTab(NMHDR *pNMHDR, LRESULT *pResult)
{
// changes of the font that are not written: ask before the page is left
if (m_PropsTab.GetCurSel() != TAB_FONTS && m_FontsDialog.IsWindowVisible() && !m_FontsDialog.ConfirmPending(this))
{
m_PropsTab.SetCurSel(TAB_FONTS);
*pResult = 0;
return;
}
//show page according to user selection
UpdatePages(bFonts);
*pResult = 0;
}