-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCdCoverCreator2Doc.cpp
executable file
·883 lines (724 loc) · 21.4 KB
/
CdCoverCreator2Doc.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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
// CdCoverCreator2Doc.cpp : implementation of the CCdCoverCreator2Doc class
//
#include "stdafx.h"
#include "CdCoverCreator2.h"
#include "CdCoverCreator2Doc.h"
#include "MainFrm.h"
#include "ImagePreviewFileDialogEx.h"
#include "CdCoverCreator2Doc.h"
#include "CdCoverCreator2View.h"
#include "CreationWizard.h"
#include "StyleTemplateWizard.h"
#include "StyleTemplates.h"
#include "WebCdCoversBrowser1.h"
#include "M3UPlaylist.h"
#include "FloatingGraphicsObject.h"
#include "FloatingText.h"
#include "FloatingImage.h"
#include "FloatingBarcode.h"
#include "cccTwain.h"
#include "Lightscribe.h"
#include ".\cdcovercreator2doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define CURRENT_VERSION 9
// CCdCoverCreator2Doc
IMPLEMENT_DYNCREATE(CCdCoverCreator2Doc, CDocument)
BEGIN_MESSAGE_MAP(CCdCoverCreator2Doc, CDocument)
ON_COMMAND(ID_PROPERTIES, OnProperties)
ON_COMMAND(ID_BKIMG_IMAGE, OnBkimgImage)
ON_COMMAND(ID_BKIMG_SCAN, OnBkimgScan)
ON_COMMAND(ID_FILE_LIGHTSCRIBE, OnFileLightscribe)
END_MESSAGE_MAP()
// CCdCoverCreator2Doc construction/destruction
CCdCoverCreator2Doc::CCdCoverCreator2Doc()
{
m_pTracks = NULL;
m_pDataCDInfo = NULL;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
m_pBackground[i] = NULL;
m_pStyle = NULL;
}
CCdCoverCreator2Doc::~CCdCoverCreator2Doc()
{
if (m_pTracks != NULL)
delete m_pTracks;
m_pTracks = NULL;
if (m_pDataCDInfo != NULL)
delete m_pDataCDInfo;
m_pDataCDInfo = NULL;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
if (m_pBackground[i] != NULL)
delete m_pBackground[i];
m_pBackground[i] = NULL;
for (std::list<CFloatingGraphicsObject*>::iterator it = m_listFloatingObjects[i].begin (); it != m_listFloatingObjects[i].end (); it++)
delete *it;
m_listFloatingObjects[i].clear ();
}
if (m_pStyle != NULL)
delete m_pStyle;
m_pStyle = NULL;
}
BOOL CCdCoverCreator2Doc::OnNewDocument()
{
m_bCreating = true;
// do not make new doc on init of the app
if (((CCdCoverCreator2App*) AfxGetApp ())->m_bFirstDoc)
{
((CCdCoverCreator2App*) AfxGetApp ())->m_bFirstDoc = false;
return FALSE;
}
if (m_pTracks != NULL)
delete m_pTracks;
m_pTracks = NULL;
if (m_pDataCDInfo != NULL)
delete m_pDataCDInfo;
m_pDataCDInfo = NULL;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
if (m_pBackground[i] != NULL)
delete m_pBackground[i];
m_pBackground[i] = NULL;
}
if (m_pStyle != NULL)
delete m_pStyle;
m_pStyle = NULL;
switch (((CCdCoverCreator2App*) AfxGetApp ())->m_NewDocMode)
{
case Empty:
{
m_pTracks = new CTracksInfo ();
for (int i = 0; i < NUM_RENDER_TYPES; i++)
m_pBackground[i] = new CBackgroundInfo ((RenderType) i, "", NULL, BIAM_CENTERCENTER, -1);
m_pStyle = new CStyleTemplate ("Empty");
}
CheckPoint (false);
m_bCreating = false;
return TRUE;
case AudioCD:
case DataCD:
if (Properties (((CCdCoverCreator2App*) AfxGetApp ())->m_NewDocMode))
{
if (!CDocument::OnNewDocument())
{
m_bCreating = false;
return FALSE;
}
CheckPoint ();
m_bCreating = false;
ApplyStyleToRTFTitles (m_pStyle);
return TRUE;
}
break;
case Web:
{
m_pTracks = new CTracksInfo ();
m_pStyle = new CStyleTemplate ("Empty");
for (int i = 0; i < NUM_RENDER_TYPES - 1; i++)
m_pBackground[i] = new CBackgroundInfo ((RenderType) i);
// show the cover browser
((CMainFrame*) AfxGetMainWnd ())->m_wndLeftPanel.m_pLastDoc = this;
((CMainFrame*) AfxGetMainWnd ())->m_bmCoverBrowserMode = BrowserSearch;
((CMainFrame*) AfxGetMainWnd ())->OnViewCoverbrowser ();
}
CheckPoint ();
m_bCreating = false;
return TRUE;
case ImportM3U:
{
m_pTracks = new CTracksInfo ();
m_pStyle = new CStyleTemplate ("Azur");
for (int i = 0; i < NUM_RENDER_TYPES - 1; i++)
m_pBackground[i] = new CBackgroundInfo ((RenderType) i);
CString strFilename;
strFilename.LoadString (IDS_OPENM3U_FILENAME);
CString strFilter;
strFilter.LoadString (IDS_OPENM3U_FILTER);
CFileDialog dlg (TRUE, NULL, strFilename, 0, strFilter, AfxGetMainWnd ());
if (dlg.DoModal () == IDOK)
{
// read the playlist
AfxGetApp ()->BeginWaitCursor ();
CM3UPlaylist pl (dlg.GetPathName ());
// set titles
m_pTracks->SetTitle (pl.m_strName);
SetTitle (pl.m_strName);
int n = 0;
CString strRemark, strLength;
for (std::list<CPlaylistEntry*>::iterator it = pl.m_List.begin (); it != pl.m_List.end (); it++)
{
// create the remark consisting of artist and (album, year), if available
strRemark = (*it)->m_strArtist;
if (!(*it)->m_strAlbum.IsEmpty () || !(*it)->m_strYear.IsEmpty ())
{
strRemark += " (";
if (!(*it)->m_strAlbum.IsEmpty ())
strRemark += (*it)->m_strAlbum + ", ";
strRemark += (*it)->m_strYear + ")";
}
// format the length of the track
strLength.Format ("%02d:%02d", (*it)->m_nLengthSec / 60, (*it)->m_nLengthSec % 60);
// add to the track's list
m_pTracks->Add (new CTrack (++n, strLength, (*it)->m_strTitle, strRemark));
}
AfxGetApp ()->EndWaitCursor ();
CheckPoint ();
m_bCreating = false;
ApplyStyleToRTFTitles (m_pStyle);
return TRUE;
}
}
m_bCreating = false;
return FALSE;
}
m_bCreating = false;
return FALSE;
}
// CCdCoverCreator2Doc serialization
void CCdCoverCreator2Doc::Serialize(CArchive& ar)
{
ar.m_pDocument = this;
// instantiate objects
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
if (m_pBackground[i] == NULL)
m_pBackground[i] = new CBackgroundInfo ((RenderType) i);
}
if (m_pStyle == NULL)
m_pStyle = new CStyleTemplate ();
// version number
DWORD dwVer = CURRENT_VERSION;
if (ar.IsLoading ())
{
ar.GetFile ()->Read (&dwVer, sizeof (DWORD));
if (dwVer >= 16)
{
// version 1 had no version number, so
// - dwVer is >= 16
// - file must be reset to start position
ar.GetFile ()->SeekToBegin ();
//ar.SetObjectSchema (1);
m_nObjectSchema = 1;
}
else
m_nObjectSchema = dwVer;
}
else
{
ar << dwVer;
m_nObjectSchema = CURRENT_VERSION;
// save the contents via the view
POSITION pos = GetFirstViewPosition ();
if ((pos != NULL) && !m_bCreating)
{
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
if (pView != NULL)
pView->ShowRenderType (pView->GetRenderType ());
}
}
/////////////////////////////////////////////////////////////////
// Serialization
// serialize backgrounds
// version 1: only inlay background
// version 2: cover, label and inlay background
int nNumRenderTypes = m_nObjectSchema <= 3 ? 4 : NUM_RENDER_TYPES;
if (m_nObjectSchema == 1)
{
// serialize tracks
if (m_pTracks == NULL)
m_pTracks = new CTracksInfo ();
m_pTracks->Serialize (ar);
// serialize backgrounds
m_pBackground[Inlay]->Serialize (ar);
// copy inlay background to other backgrounds
*m_pBackground[Cover] = *m_pBackground[Inlay];
*m_pBackground[Back] = *m_pBackground[Inlay];
*m_pBackground[Label] = *m_pBackground[Inlay];
m_pBackground[Cover]->SetRenderType (Cover);
m_pBackground[Back]->SetRenderType (Back);
m_pBackground[Label]->SetRenderType (Label);
// serialize style
m_pStyle->Serialize (ar);
}
else
{
// serialize tracks
int nMode;
if (ar.IsLoading ())
{
if (m_nObjectSchema >= 6)
ar >> nMode;
else
nMode = (int) AudioCD;
}
else
{
nMode = m_pTracks == NULL ? DataCD : AudioCD;
ar << nMode;
}
switch (nMode)
{
case (int) AudioCD:
if (m_pTracks == NULL)
m_pTracks = new CTracksInfo ();
m_pTracks->Serialize (ar);
break;
case (int) DataCD:
if (m_pDataCDInfo == NULL)
m_pDataCDInfo = new CDataCDInfo ();
m_pDataCDInfo->Serialize (ar);
break;
}
// serialize backgrounds
for (int i = 0; i < nNumRenderTypes; i++)
m_pBackground[i]->Serialize (ar);
// serialize style
m_pStyle->Serialize (ar);
}
if (ar.IsStoring ())
{
ar << m_strBookletRTFText;
// serialize floating objects
int nType;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
ar << (int) m_listFloatingObjects[i].size ();
for (std::list<CFloatingGraphicsObject*>::iterator it = m_listFloatingObjects[i].begin (); it != m_listFloatingObjects[i].end (); it++)
{
if ((*it)->IsKindOf (RUNTIME_CLASS (CFloatingText)))
nType = 0;
else if ((*it)->IsKindOf (RUNTIME_CLASS (CFloatingImage)))
nType = 1;
else if ((*it)->IsKindOf (RUNTIME_CLASS (CFloatingBarCode)))
nType = 2;
else
nType = -1;
ar << nType;
(*it)->Serialize (ar);
}
}
// medium type
nType = (int) m_pStyle->GetMediumType ();
ar << nType;
}
else
{
if (m_nObjectSchema >= 4)
ar >> m_strBookletRTFText;
// serialize floating objects
if (m_nObjectSchema >= 6)
{
int nObjCount, nType;
CFloatingGraphicsObject* pObj;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
// clear the object list
for (std::list<CFloatingGraphicsObject*>::iterator it = m_listFloatingObjects[i].begin (); it != m_listFloatingObjects[i].end (); it++)
delete *it;
m_listFloatingObjects[i].clear ();
// load the objects
ar >> nObjCount;
for (int j = 0; j < nObjCount; j++)
{
ar >> nType;
switch (nType)
{
case 0:
pObj = new CFloatingText ();
break;
case 1:
pObj = new CFloatingImage ();
break;
case 2:
pObj = new CFloatingBarCode ();
break;
}
pObj->Serialize (ar);
m_listFloatingObjects[i].push_back (pObj);
}
}
// medium type
ar >> nType;
m_pStyle->SetMeasures ((MediumType) nType);
}
}
if (ar.IsLoading ())
{
DisplayStyle ();
DisplayMediumType ();
}
}
// CCdCoverCreator2Doc diagnostics
#ifdef _DEBUG
void CCdCoverCreator2Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CCdCoverCreator2Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CCdCoverCreator2Doc commands
bool CCdCoverCreator2Doc::Properties (NewDocMode mode)
{
#ifdef _DEBUG
CMemoryState oldMemState, newMemState, diffMemState;
oldMemState.Checkpoint ();
#endif
CCreationWizard wizard (mode);
bool bSetCheckPoint = false;
// set tracks
if (m_pTracks != NULL)
wizard.SetTracksInfo (*m_pTracks);
// set data CD info
if (m_pDataCDInfo != NULL)
wizard.SetDataCDInfo (*m_pDataCDInfo);
// set backgrounds
for (int i = 0; i < NUM_RENDER_TYPES; i++)
if (m_pBackground[i] != NULL)
wizard.SetBackgroundInfo (*m_pBackground[i], (RenderType) i);
// set style
if (m_pStyle != NULL)
wizard.SetStyleTemplate (*m_pStyle);
bool bRet = wizard.DoModal () == ID_WIZFINISH;
if (bRet)
{
CTracksInfo* pTiNew = mode == AudioCD ? new CTracksInfo (wizard.GetTracksInfo ()) : NULL;
CDataCDInfo* pDCdiNew = mode == DataCD ? new CDataCDInfo (wizard.GetDataCDInfo ()) : NULL;
CBackgroundInfo* pBiNew[NUM_RENDER_TYPES];
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
CBackgroundInfo* pBkInfo = wizard.GetBackgroundInfo ()[i];
if (pBkInfo != NULL)
pBiNew[i] = new CBackgroundInfo (*pBkInfo);
else
pBiNew[i] = new CBackgroundInfo ((RenderType) i);
}
CStyleTemplate* pStNew = new CStyleTemplate (wizard.GetStyleTemplate ());
// set new data and set modified flag, if data has changed
// tracks
if (m_pTracks == NULL)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
else
{
if (*pTiNew != *m_pTracks)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
delete m_pTracks;
}
m_pTracks = pTiNew;
// data CD info
if (m_pDataCDInfo == NULL)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
else
{
if (*pDCdiNew != *m_pDataCDInfo)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
delete m_pDataCDInfo;
}
m_pDataCDInfo = pDCdiNew;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
{
if (m_pBackground[i] == NULL)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
else
{
if (*pBiNew[i] != *m_pBackground[i])
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
delete m_pBackground[i];
}
m_pBackground[i] = pBiNew[i];
}
if (m_pStyle == NULL)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
else
{
if (*pStNew != *m_pStyle)
{
bSetCheckPoint = true;
SetModifiedFlag ();
}
delete m_pStyle;
}
m_pStyle = pStNew;
// refresh display
UpdateAllViews (NULL);
// set default doc title if document has not been safed yet
if (GetPathName ().IsEmpty ())
{
if (m_pTracks != NULL)
SetTitle (m_pTracks->GetTitle ().SpanExcluding (":"));
else if (m_pDataCDInfo != NULL)
SetTitle (m_pDataCDInfo->m_strCDTitle);
}
}
#ifdef _DEBUG
newMemState.Checkpoint ();
// if (diffMemState.Difference (oldMemState, newMemState))
// diffMemState.DumpAllObjectsSince ();
#endif
if (bSetCheckPoint)
CheckPoint ();
DisplayStyle ();
DisplayMediumType ();
return bRet;
}
void CCdCoverCreator2Doc::OnProperties()
{
Properties (m_pTracks == NULL ? DataCD : AudioCD);
}
void CCdCoverCreator2Doc::SetStyle(CString strStyle)
{
// save old style sheet for checking whether the style has changed
CStyleTemplate* pStNew = NULL;
bool bSetCheckPoint = false;
if (m_pStyle == NULL)
{
m_pStyle = new CStyleTemplate ();
bSetCheckPoint = true;
SetModifiedFlag ();
}
else
pStNew = new CStyleTemplate (*m_pStyle);
// load new template
((CCdCoverCreator2App*) AfxGetApp ())->GetTemplates ().LoadTemplate (strStyle, m_pStyle);
if (pStNew != NULL)
{
if (*pStNew != *m_pStyle)
{
bSetCheckPoint = true;
SetModifiedFlag ();
// RTF title must be re-formatted
// (if it is empty, it will be done in CTracksInfo::DrawTitle2)
// for (int i = 0; i < NUM_RENDER_TYPES; i++)
// m_pTracks->SetRTFTitle ("", (RenderType) i);
ApplyStyleToRTFTitles (m_pStyle);
}
delete pStNew;
}
UpdateAllViews (NULL);
// update the style palette window
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
RenderType rt = pView->GetRenderType ();
((CMainFrame*) AfxGetMainWnd ())->UpdateStyleDlgs (m_pStyle, m_pBackground[rt], rt);
if (bSetCheckPoint)
CheckPoint ();
}
void CCdCoverCreator2Doc::SetMediumType (MediumType type)
{
if (m_pStyle->GetMediumType () == type)
return;
m_pStyle->SetMeasures (type);
// switch to the next available render type
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
RenderType rt = pView->GetRenderType ();
int i = 1;
while (!m_pStyle->m_bHasRenderType[rt])
{
rt = (RenderType) (((int) rt + 1) % NUM_RENDER_TYPES);
i++;
if (i == NUM_RENDER_TYPES)
break;
}
// switch to the render type or update the views, if still the same render type
if (rt != pView->GetRenderType ())
pView->ShowRenderType (rt);
else
UpdateAllViews (NULL);
// update the left panel
((CMainFrame*) AfxGetMainWnd ())->m_wndLeftPanel.Update (true);
CheckPoint ();
}
void CCdCoverCreator2Doc::UpdateStyle()
{
if (m_pStyle != NULL)
SetStyle (m_pStyle->GetName ());
}
BOOL CCdCoverCreator2Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
// serialize...
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// template name may have been changed during loading:
// if new template is created under new name
if (m_pStyle != NULL)
if (m_pStyle->IsTemplateNameChanged ())
SetModifiedFlag ();
for (int i = 0; i < NUM_RENDER_TYPES; i++)
if (m_pBackground[i] != NULL)
if (m_pBackground[i]->IsImgFilenameChanged () || m_pBackground[i]->m_pAlphaTexture->IsImgFilenameChanged ())
{
SetModifiedFlag ();
break; // exit loop (it suffices to set the modified flag once...)
}
CheckPoint (false);
return TRUE;
}
void CCdCoverCreator2Doc::DisplayStyle()
{
// update the style display in the dlgbar combo
((CMainFrame*) AfxGetMainWnd ())->ListStyles (m_pStyle ? m_pStyle->GetName () : "");
// update the style palette window
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
RenderType rt = pView->GetRenderType ();
((CMainFrame*) AfxGetMainWnd ())->UpdateStyleDlgs (m_pStyle, m_pBackground[rt], rt);
}
void CCdCoverCreator2Doc::DisplayMediumType ()
{
if (m_pStyle != NULL)
((CMainFrame*) AfxGetMainWnd ())->m_wndDlgBarSelectMedium.SetMediumType (m_pStyle->GetMediumType ());
}
void CCdCoverCreator2Doc::OnBkimgImage()
{
CString strFilename;
strFilename.LoadString (IDS_OPENBKIMGFILE_FILENAME);
CString strFilter;
strFilter.LoadString (IDS_OPENBKIMGFILE_FILTER);
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
CImagePreviewFileDialogEx dlg (TRUE, NULL, strFilename, 0, strFilter, pView);
if (dlg.DoModal () == IDOK)
if (pView != NULL)
SetBkImageFilename (dlg.GetPathName ());
}
void CCdCoverCreator2Doc::OnBkimgScan()
{
CcccTwain* pTwain = &((CMainFrame*) AfxGetApp ()->GetMainWnd ())->m_twain;
pTwain->m_pBkImgPage = NULL;
pTwain->SelectSource ();
if (pTwain->SourceSelected ())
pTwain->Acquire ();
}
bool CCdCoverCreator2Doc::SetBkImageFilename(CString strFilename)
{
bool bResult = false;
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
if (pView != NULL)
{
RenderType rt = pView->GetRenderType ();
bResult = m_pBackground[rt]->SetImage (strFilename);
((CMainFrame*) AfxGetMainWnd ())->UpdateStyleDlgs (m_pStyle, m_pBackground[rt], rt);
UpdateAllViews (NULL);
OFSTRUCT of;
if ((::OpenFile (strFilename, &of, OF_EXIST) != HFILE_ERROR) || strFilename.IsEmpty ())
CheckPoint ();
SetModifiedFlag ();
}
return bResult;
}
void CCdCoverCreator2Doc::SetBkAlphaFilename(CString strFilename)
{
POSITION pos = GetFirstViewPosition ();
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
if (pView != NULL)
{
RenderType rt = pView->GetRenderType ();
CBackgroundAlphaTexture* pBkAlpha = m_pBackground[rt]->m_pAlphaTexture;
int nAlphaFormat = pBkAlpha->m_nAlphaFormat;
int nSCnstAlpha = pBkAlpha->m_nSourceConstantAlpha;
delete pBkAlpha;
m_pBackground[rt]->m_pAlphaTexture = new CBackgroundAlphaTexture (strFilename, nAlphaFormat, nSCnstAlpha);
((CMainFrame*) AfxGetMainWnd ())->UpdateStyleDlgs (m_pStyle, m_pBackground[rt], rt);
UpdateAllViews (NULL);
OFSTRUCT of;
if ((::OpenFile (strFilename, &of, OF_EXIST) != HFILE_ERROR) || strFilename.IsEmpty ())
CheckPoint ();
SetModifiedFlag ();
}
}
void CCdCoverCreator2Doc::OnCloseDocument()
{
// update style dlg, left panel
((CMainFrame*) AfxGetMainWnd ())->UpdateStyleDlgs (NULL, NULL, (RenderType) -1);
CDocument::OnCloseDocument();
}
bool CCdCoverCreator2Doc::SetRTFTitle (CString strRTFTitle, RenderType rt)
{
if (m_pTracks != NULL)
return m_pTracks->SetRTFTitle (strRTFTitle, rt);
if (m_pDataCDInfo != NULL)
return m_pDataCDInfo->SetRTFTitle (strRTFTitle, rt);
return false;
}
CString CCdCoverCreator2Doc::GetRTFTitle (RenderType rt)
{
if (m_pTracks != NULL)
return m_pTracks->GetRTFTitle (rt);
if (m_pDataCDInfo != NULL)
return m_pDataCDInfo->GetRTFTitle (rt);
return "";
}
void CCdCoverCreator2Doc::ApplyStyleToRTFTitles (CStyleTemplate* pStyle, RenderType rt)
{
if (m_pTracks != NULL)
m_pTracks->ApplyStyleToRTFTitles (pStyle, rt);
if (m_pDataCDInfo != NULL)
m_pDataCDInfo->ApplyStyleToRTFTitles (pStyle, rt);
}
void CCdCoverCreator2Doc::OnFileLightscribe()
{
CSize szUnit (236, 236); // 2834x2834 Pixel^2 bitmap equals a 12x12 cm^2 square
// save the contents via the view
POSITION pos = GetFirstViewPosition ();
if (pos != NULL)
{
CCdCoverCreator2View* pView = (CCdCoverCreator2View*) GetNextView (pos);
if (pView != NULL)
{
CDC* pDC = pView->GetDC ();
int nHeight = (int) ((m_pStyle->GetTotalCoverRect ()->Height () * szUnit.cy) / 1000);
BITMAPINFOHEADER* pBi = new BITMAPINFOHEADER;
BYTE* pBitmapBits;
pBi->biSize = sizeof (BITMAPINFOHEADER);
pBi->biBitCount = 24;
pBi->biPlanes = 1;
pBi->biCompression = BI_RGB;
pBi->biWidth = nHeight;
pBi->biHeight = nHeight;
pBi->biSizeImage = ((((pBi->biWidth * pBi->biBitCount) + 31) & ~31) >> 3) * pBi->biHeight;
pBi->biXPelsPerMeter = 24139;
pBi->biYPelsPerMeter = 24139;
pBi->biClrUsed = 0;
pBi->biClrImportant = 0;
HBITMAP hBmp = CreateDIBSection (pDC->GetSafeHdc (), (CONST BITMAPINFO*) pBi, DIB_RGB_COLORS, (void**) &pBitmapBits, NULL, 0);
CDC memDC;
memDC.CreateCompatibleDC (pDC);
HBITMAP hOldBmp = (HBITMAP) SelectObject (memDC.GetSafeHdc (), hBmp);
memDC.PatBlt (0, 0, nHeight, nHeight, WHITENESS);
CRenderDC rdc (&memDC, nHeight, m_pStyle);
CLabelRenderer renderer (m_pTracks, m_pDataCDInfo, m_pBackground, m_listFloatingObjects, *m_pStyle);
renderer.Render (rdc, Label, false, true, false, false);
SelectObject (memDC.GetSafeHdc (), hOldBmp);
memDC.DeleteDC ();
pView->ReleaseDC (pDC);
new CLightscribe (hBmp, pBi, pBitmapBits);
}
}
}