-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainFrm.cpp
600 lines (466 loc) · 15.8 KB
/
MainFrm.cpp
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
Pixcen - A windows platform low level pixel editor for C64
Copyright (C) 2013 John Hammarberg ([email protected])
This file is part of Pixcen.
Pixcen is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pixcen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pixcen. If not, see <http://www.gnu.org/licenses/>.
*/
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Pixcen.h"
#include "MainFrm.h"
#include <afxinet.h>
#include "res\version.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CFrameWndEx)
const int iMaxUserToolbars = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)
ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook)
ON_MESSAGE(UM_GRAPHIX, &CMainFrame::OnUmGraphix)
ON_WM_CLOSE()
ON_COMMAND(ID_VIEW_PREVIEW, &CMainFrame::OnViewPreview)
ON_COMMAND(ID_HELP_CHECKFORUPDATES, &CMainFrame::OnHelpCheckforupdates)
ON_UPDATE_COMMAND_UI(ID_HELP_CHECKFORUPDATES, &CMainFrame::OnUpdateHelpCheckforupdates)
ON_MESSAGE(UM_UPDATE_VERSION, &CMainFrame::OnUmUpdateVersion)
ON_COMMAND(ID_HELP_HELP, &CMainFrame::OnHelpHelp)
ON_COMMAND(ID_HELP_DOWNLOADSOURCECODE, &CMainFrame::OnHelpDownloadsourcecode)
ON_COMMAND(ID_HELP_FACEBOOK, &CMainFrame::OnHelpFacebook)
ON_COMMAND(ID_HELP_LEMON64SUPPORTFORUM, &CMainFrame::OnHelpLemon64supportforum)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008);
m_pC64Pal = NULL;
m_pCColCtrl = NULL;
m_pUpdateThread = NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
//BOOL bNameValid;
// set the visual manager and style based on persisted value
OnApplicationLook(theApp.m_nAppLook);
if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
// prevent the menu bar from taking the focus on activation
CMFCPopupMenu::SetForceMenuFocus(FALSE);
// create a view to occupy the client area of the frame
if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW/*|WS_HSCROLL|WS_VSCROLL*/, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
{
TRACE0("Failed to create view window\n");
return -1;
}
m_wndView.DragAcceptFiles();
/*
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
CString strToolBarName;
bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
ASSERT(bNameValid);
m_wndToolBar.SetWindowText(strToolBarName);
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
// Allow user-defined toolbars operations:
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
*/
if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
// TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable
//m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
//DockPane(&m_wndToolBar);
// enable Visual Studio 2005 style docking window behavior
CDockingManager::SetDockingMode(DT_SMART);
// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// Enable toolbar and docking window menu replacement
//EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
// enable quick (Alt+drag) toolbar customization
CMFCToolBar::EnableQuickCustomization();
if (CMFCToolBar::GetUserImages() == NULL)
{
// load user-defined toolbar images
if (m_UserImages.Load(_T(".\\UserImages.bmp")))
{
CMFCToolBar::SetUserImages(&m_UserImages);
}
}
// enable menu personalization (most-recently used commands)
// TODO: define your own basic commands, ensuring that each pulldown menu has at least one basic command.
/*
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail(ID_APP_EXIT);
lstBasicCommands.AddTail(ID_EDIT_CUT);
lstBasicCommands.AddTail(ID_EDIT_PASTE);
lstBasicCommands.AddTail(ID_EDIT_UNDO);
lstBasicCommands.AddTail(ID_EDIT_REDO);
lstBasicCommands.AddTail(ID_APP_ABOUT);
lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);
lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA);
lstBasicCommands.AddTail(ID_VIEW_APPLOOK_WINDOWS_7);
CMFCToolBar::SetBasicCommands(lstBasicCommands);
*/
m_pC64Pal = new C64Palette(&m_wndView);
m_pC64Pal->Create(IDD_C64PAL, &m_wndView);
m_pC64Pal->ShowWindow(SW_SHOW);
m_pCColCtrl = new CColorCtrl(&m_wndView);
m_pCColCtrl->Create(IDD_CONTROL, &m_wndView);
m_pCColCtrl->ShowWindow(SW_SHOW);
TCHAR *p=new TCHAR[16];
lstrcpy(p, _T("Untitled"));
Mail(MSG_FILE_TITLE, (UINT_PTR)p);
OnHelpCheckforupdates();
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWndEx::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWndEx::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWndEx::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
void CMainFrame::OnSetFocus(CWnd* /*pOldWnd*/)
{
// forward focus to the view window
m_wndView.SetFocus();
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// let the view have first crack at the command
if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// otherwise, do default handling
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CMainFrame::OnViewCustomize()
{
CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */);
pDlgCust->EnableUserDefinedToolbars();
pDlgCust->Create();
}
LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
{
LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp);
if (lres == 0)
{
return 0;
}
CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;
ASSERT_VALID(pUserToolbar);
BOOL bNameValid;
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
return lres;
}
void CMainFrame::OnApplicationLook(UINT id)
{
CWaitCursor wait;
theApp.m_nAppLook = id;
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_WIN_2000:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
break;
case ID_VIEW_APPLOOK_OFF_XP:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
break;
case ID_VIEW_APPLOOK_WIN_XP:
CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
break;
case ID_VIEW_APPLOOK_OFF_2003:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_VS_2005:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_VS_2008:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
CDockingManager::SetDockingMode(DT_SMART);
break;
case ID_VIEW_APPLOOK_WINDOWS_7:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
CDockingManager::SetDockingMode(DT_SMART);
break;
default:
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_OFF_2007_BLUE:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
break;
case ID_VIEW_APPLOOK_OFF_2007_BLACK:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
break;
case ID_VIEW_APPLOOK_OFF_2007_SILVER:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
break;
case ID_VIEW_APPLOOK_OFF_2007_AQUA:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
break;
}
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
CDockingManager::SetDockingMode(DT_SMART);
}
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}
void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// base class does the real work
if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
{
return FALSE;
}
// enable customization button for all user toolbars
BOOL bNameValid;
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
for (int i = 0; i < iMaxUserToolbars; i ++)
{
CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
if (pUserToolbar != NULL)
{
pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
}
}
return TRUE;
}
BOOL CMainFrame::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_pC64Pal->DestroyWindow();
delete m_pC64Pal;
m_pCColCtrl->DestroyWindow();
delete m_pCColCtrl;
for(int r=0;r<m_pPreview.count();r++)
{
m_pPreview[r]->DestroyWindow();
delete m_pPreview[r];
}
return CFrameWndEx::DestroyWindow();
}
afx_msg LRESULT CMainFrame::OnUmGraphix(WPARAM wParam, LPARAM lParam)
{
unsigned short message = lParam&0xffff, extra = unsigned short(lParam >> 16);
UINT_PTR data = UINT_PTR(wParam);
Receive(message,data,extra);
m_pC64Pal->Receive(message,data,extra);
m_pCColCtrl->Receive(message,data,extra);
m_wndView.Receive(message,data,extra);
for(int r=0;r<m_pPreview.count();r++)
{
m_pPreview[r]->Receive(message,data,extra);
}
return 0;
}
void CMainFrame::Receive(unsigned short message, UINT_PTR data, unsigned short extra)
{
switch(message)
{
case MSG_STATUS_TEXT:
{
TCHAR *p=(TCHAR *)data;
m_wndStatusBar.SetPaneText(0,p);
delete [] p;
}
break;
case MSG_PREV_CLOSE:
{
CPreview *p=(CPreview *)data;
p->DestroyWindow();
delete p;
int n=m_pPreview.find(p);
if(n!=-1)
{
m_pPreview.remove(n);
}
}
break;
case MSG_FILE_TITLE:
{
TCHAR *p =(TCHAR *)data;
nstr tmp = _T("Pixcen - ");
tmp += p;
delete [] p;
SetWindowText(tmp);
}
break;
default:
break;
}
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(this->m_wndView.FrameClose())
{
__super::OnClose();
}
}
void CMainFrame::OnViewPreview()
{
// TODO: Add your command handler code here
CPreview *p=new CPreview(1.0/m_wndView.m_pbm->GetPARValue());
LPCTSTR pClass=AfxRegisterWndClass(CS_DROPSHADOW|CS_HREDRAW,0,0,0);
p->CreateEx(0,pClass,_T("Preview"),WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,320,200,*this,(HMENU)0);
p->m_ppInterface = &m_wndView.m_pbm;
m_pPreview.add(p);
}
UINT CMainFrame::UpdateThread( LPVOID pParam )
{
try
{
CMainFrame *pWnd = (CMainFrame *)pParam;
CInternetSession session;
CHttpFile* file = NULL;
file = (CHttpFile *)session.OpenURL(_T("http://binarybone.com/pixcen/ver"), 1UL, INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD);
if (NULL != file)
{
char txt[17];
UINT n=file->Read(txt,16);
file->Close();
if(n>0)
{
txt[n]=0;
::PostMessage(*pWnd, UM_UPDATE_VERSION, WPARAM(atoi(txt)), NULL);
}
else
{
::PostMessage(*pWnd, UM_UPDATE_VERSION, WPARAM(0), NULL);
}
//Do something here with the web request
//Clean up the file here to avoid a memory leak!!!!!!!
delete file;
}
session.Close();
}
catch(CInternetException *ex)
{
ex->Delete();
}
return 0;
}
afx_msg LRESULT CMainFrame::OnUmUpdateVersion(WPARAM wParam, LPARAM lParam)
{
int ver = int(wParam);
if(ver > VERSION_NUM)
{
if(MessageBox(_T("There is an updated version of Pixcen.\nWould you like to download?"),_T("New version"),MB_YESNO|MB_ICONQUESTION) == IDYES)
{
#ifdef _M_X64
ShellExecute(NULL,L"open",L"http://binarybone.com/pixcen/pixcen64.zip",NULL,NULL,SW_SHOWNORMAL);
#else
ShellExecute(NULL,L"open",L"http://binarybone.com/pixcen/pixcen.zip",NULL,NULL,SW_SHOWNORMAL);
#endif
}
}
//m_pUpdateThread->Delete();
m_pUpdateThread = NULL;
return 0;
}
void CMainFrame::OnHelpCheckforupdates()
{
#ifdef RELEASEVERSION
if(m_pUpdateThread)return;
m_pUpdateThread = AfxBeginThread(UpdateThread, this);
#endif
}
void CMainFrame::OnUpdateHelpCheckforupdates(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_pUpdateThread ? 0 : 1);
}
void CMainFrame::OnHelpHelp()
{
ShellExecute(NULL,L"open",L"https://github.com/Hammarberg/pixcen/wiki",NULL,NULL,SW_SHOWNORMAL);
}
void CMainFrame::OnHelpDownloadsourcecode()
{
ShellExecute(NULL,L"open",L"https://github.com/Hammarberg/pixcen",NULL,NULL,SW_SHOWNORMAL);
}
void CMainFrame::OnHelpFacebook()
{
ShellExecute(NULL,L"open",L"https://www.facebook.com/groups/pixcen/",NULL,NULL,SW_SHOWNORMAL);
}
void CMainFrame::OnHelpLemon64supportforum()
{
ShellExecute(NULL,L"open",L"http://www.lemon64.com/forum/viewtopic.php?t=57459",NULL,NULL,SW_SHOWNORMAL);
}