forked from tcobbs/ldview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LDViewWindow.cpp
4417 lines (4083 loc) · 102 KB
/
LDViewWindow.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
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "LDViewWindow.h"
#include <shlwapi.h>
#include "LDVExtensionsSetup.h"
#include "LDViewPreferences.h"
#include "SSModelWindow.h"
#include "ModelTreeDialog.h"
#include "BoundingBoxDialog.h"
#include "MpdDialog.h"
#include "Resource.h"
#include "ToolbarStrip.h"
#include <LDLib/LDUserDefaultsKeys.h>
#include <LDLoader/LDLModel.h>
#include <TCFoundation/TCUserDefaults.h>
#include <TCFoundation/mystring.h>
#include <TCFoundation/TCAutoreleasePool.h>
#include <TCFoundation/TCStringArray.h>
#include <TCFoundation/TCSortedStringArray.h>
#include <TCFoundation/TCTypedObjectArray.h>
#include <TCFoundation/TCAlertManager.h>
#include <TCFoundation/TCProgressAlert.h>
#include <TCFoundation/TCLocalStrings.h>
#include <TCFoundation/TCWebClient.h>
#include <CUI/CUIWindowResizer.h>
#include <CUI/CUIScaler.h>
#include <LDLib/LDLibraryUpdater.h>
#include <LDLib/LDPartsList.h>
#include <LDLoader/LDLPalette.h>
#include <LDLoader/LDLMainModel.h>
#include <TRE/TREMainModel.h>
#include "ModelWindow.h"
#include <TCFoundation/TCMacros.h>
#include <LDLib/LDHtmlInventory.h>
#include "PartsListDialog.h"
#include "LatLonDialog.h"
#include "CameraLocationDialog.h"
#include "RotationCenterDialog.h"
#include "StatisticsDialog.h"
#include "StepDialog.h"
#if defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_DEBUG)
#define new DEBUG_CLIENTBLOCK
#endif // _DEBUG
#define DOWNLOAD_TIMER 12
#define DEFAULT_WIN_WIDTH 640
#define DEFAULT_WIN_HEIGHT 480
static char monthShortNames[12][4] =
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
TCStringArray* LDViewWindow::recentFiles = NULL;
TCStringArray* LDViewWindow::extraSearchDirs = NULL;
UCCHAR* LDViewWindow::productVersion = NULL;
UCCHAR* LDViewWindow::legalCopyright = NULL;
LDViewWindow::LDViewWindowCleanup LDViewWindow::ldViewWindowCleanup;
void debugOut(char *fmt, ...);
LDViewWindow::LDViewWindowCleanup::~LDViewWindowCleanup(void)
{
TCObject::release(LDViewWindow::recentFiles);
LDViewWindow::recentFiles = NULL;
TCObject::release(LDViewWindow::extraSearchDirs);
LDViewWindow::extraSearchDirs = NULL;
delete[] LDViewWindow::legalCopyright;
LDViewWindow::legalCopyright = NULL;
delete[] LDViewWindow::productVersion;
LDViewWindow::productVersion = NULL;
}
LDViewWindow::LDViewWindow(CUCSTR windowTitle, HINSTANCE hInstance, int x,
int y, int width, int height):
CUIWindow(windowTitle, hInstance, x, y, width, height),
modelWindow(NULL),
toolbarStrip(NULL),
hAboutWindow(NULL),
hOpenGLInfoWindow(NULL),
hStatusBar(NULL),
fullScreen(false),
fullScreenActive(false),
switchingModes(false),
searchDirsInitialized(false),
videoModes(NULL),
numVideoModes(0),
currentVideoModeIndex(-1),
showStatusBarOverride(false),
skipMinimize(false),
screenSaver(false),
originalMouseX(-999999),
originalMouseY(-999999),
hFileMenu(NULL),
hViewMenu(NULL),
hToolsMenu(NULL),
loading(FALSE),
openGLInfoWindoResizer(NULL),
hOpenGLStatusBar(NULL),
hExamineIcon(NULL),
hFlythroughIcon(NULL),
hWalkIcon(NULL),
#ifndef TC_NO_UNICODE
hMonitor(NULL),
#endif // TC_NO_UNICODE
#if defined(USE_CPP11) || !defined(_NO_BOOST)
hLibraryUpdateWindow(NULL),
libraryUpdater(NULL),
#endif // !_NO_BOOST
prefs(NULL),
drawWireframe(false),
examineLatLong(TCUserDefaults::longForKey(EXAMINE_MODE_KEY,
LDrawModelViewer::EMFree, false) == LDrawModelViewer::EMLatLong),
initialShown(false),
modelTreeDialog(NULL),
boundingBoxDialog(NULL),
mpdDialog(NULL)
{
CUIThemes::init();
if (CUIThemes::isThemeLibLoaded())
{
if (TCUserDefaults::boolForKey(VISUAL_STYLE_ENABLED_KEY, true, false))
{
CUIThemes::setThemeAppProperties(STAP_ALLOW_NONCLIENT |
STAP_ALLOW_CONTROLS);
}
else
{
CUIThemes::setThemeAppProperties(STAP_ALLOW_NONCLIENT);
}
}
loadSettings();
standardWindowStyle = windowStyle;
if (!recentFiles)
{
recentFiles = new TCStringArray(10, FALSE);
populateRecentFiles();
}
if (!extraSearchDirs)
{
extraSearchDirs = new TCStringArray;
populateExtraSearchDirs();
}
loadStatusBarIcons();
TCAlertManager::registerHandler(TCProgressAlert::alertClass(), this,
(TCAlertCallback)&LDViewWindow::progressAlertCallback);
UCCHAR ucUserAgent[256];
sucprintf(ucUserAgent, COUNT_OF(ucUserAgent),
_UC("LDView/%s (Windows; [email protected]; ")
_UC("https://github.com/tcobbs/ldview)"), getProductVersion());
std::string userAgent;
ucstringtoutf8(userAgent, ucUserAgent);
TCWebClient::setUserAgent(userAgent.c_str());
maxStandardSize.cx = 0;
maxStandardSize.cy = 0;
}
LDViewWindow::~LDViewWindow(void)
{
}
void LDViewWindow::dealloc(void)
{
destroyStatusBarIcons();
TCAlertManager::unregisterHandler(this);
TCObject::release(modelTreeDialog);
TCObject::release(boundingBoxDialog);
TCObject::release(mpdDialog);
TCObject::release(toolbarStrip);
delete videoModes;
videoModes = NULL;
if (hOpenGLInfoWindow)
{
DestroyWindow(hOpenGLInfoWindow);
}
if (openGLInfoWindoResizer)
{
openGLInfoWindoResizer->release();
}
#if defined(USE_CPP11) || !defined(_NO_BOOST)
if (hLibraryUpdateWindow)
{
DestroyWindow(hLibraryUpdateWindow);
}
#endif // !_NO_BOOST
TCObject::release(prefs);
CUIWindow::dealloc();
}
void LDViewWindow::destroyStatusBarIcons(void)
{
if (hExamineIcon)
{
DestroyIcon(hExamineIcon);
hExamineIcon = NULL;
}
if (hFlythroughIcon)
{
DestroyIcon(hFlythroughIcon);
hFlythroughIcon = NULL;
}
if (hWalkIcon)
{
DestroyIcon(hWalkIcon);
hWalkIcon = NULL;
}
}
void LDViewWindow::loadStatusBarIcons(void)
{
double scaleFactor = getScaleFactor();
hExamineIcon = TCImage::loadIconFromPngResource(hInstance,
IDR_TB_EXAMINE, scaleFactor, CUIScaler::use32bit());
hFlythroughIcon = TCImage::loadIconFromPngResource(hInstance,
IDR_TB_FLYTHROUGH, scaleFactor, CUIScaler::use32bit());
hWalkIcon = TCImage::loadIconFromPngResource(hInstance,
IDR_TB_WALK, scaleFactor, CUIScaler::use32bit());
}
void LDViewWindow::loadSettings(void)
{
fsWidth = TCUserDefaults::longForKey(FULLSCREEN_WIDTH_KEY, 640);
fsHeight = TCUserDefaults::longForKey(FULLSCREEN_HEIGHT_KEY, 480);
fsDepth = TCUserDefaults::longForKey(FULLSCREEN_DEPTH_KEY, 32);
showStatusBar = TCUserDefaults::boolForKey(STATUS_BAR_KEY, true, false);
showToolbar = TCUserDefaults::boolForKey(TOOLBAR_KEY, true, false);
topmost = TCUserDefaults::boolForKey(TOPMOST_KEY, false, false);
visualStyleEnabled = TCUserDefaults::boolForKey(VISUAL_STYLE_ENABLED_KEY,
true, false);
keepRightSideUp = TCUserDefaults::boolForKey(KEEP_RIGHT_SIDE_UP_KEY, false,
false);
}
HBRUSH LDViewWindow::getBackgroundBrush(void)
{
// return CUIWindow::getBackgroundBrush();
return NULL;
}
void LDViewWindow::showWindow(int nCmdShow)
{
LDrawModelViewer *modelViewer;
if (screenSaver)
{
x = 0;
y = 0;
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
CUIWindow::showWindow(SW_SHOW);
}
else
{
CUIWindow::showWindow(nCmdShow);
}
modelViewer = modelWindow->getModelViewer();
if (modelViewer && !searchDirsInitialized)
{
modelViewer->setExtraSearchDirs(extraSearchDirs);
searchDirsInitialized = true;
}
modelWindow->finalSetup();
}
void LDViewWindow::setScreenSaver(bool flag)
{
screenSaver = flag;
if (screenSaver)
{
windowStyle |= WS_CLIPCHILDREN;
}
else
{
windowStyle &= ~WS_CLIPCHILDREN;
}
}
const UCCHAR* LDViewWindow::windowClassName(void)
{
if (fullScreen || screenSaver)
{
return _UC("LDViewFullScreenWindow");
}
else
{
return _UC("LDViewWindow");
}
}
LRESULT LDViewWindow::doEraseBackground(RECT* updateRect)
{
BOOL noRect = FALSE;
if (updateRect == NULL)
{
if (paintStruct)
{
return 0;
}
updateRect = new RECT;
GetUpdateRect(hWindow, updateRect, FALSE);
noRect = TRUE;
}
DWORD backgroundColor = LDViewPreferences::getColor(BACKGROUND_COLOR_KEY);
HBRUSH hBrush = CreateSolidBrush(RGB(backgroundColor & 0xFF,
(backgroundColor >> 8) & 0xFF, (backgroundColor >> 16) & 0xFF));
debugPrintf(2, "updateRect size1: %d, %d\n",
updateRect->right - updateRect->left,
updateRect->bottom - updateRect->top);
if (!fullScreen && !screenSaver && !hParentWindow)
{
LONG margin = 0;
LONG bottomMargin = margin;
LONG topMargin = margin;
updateRect->left = std::max(updateRect->left, margin);
updateRect->right = std::min(updateRect->right, width - margin);
if (showStatusBar || showStatusBarOverride)
{
bottomMargin += getStatusBarHeight();
}
updateRect->bottom = std::min(updateRect->bottom,
height - bottomMargin);
if (showToolbar)
{
topMargin += getToolbarHeight();
}
updateRect->top = std::max(updateRect->top, topMargin);
}
debugPrintf(2, "updateRect size2: %d, %d\n",
updateRect->right - updateRect->left,
updateRect->bottom - updateRect->top);
FillRect(hdc, updateRect, hBrush);
DeleteObject(hBrush);
CUIWindow::doEraseBackground(updateRect);
if (toolbarStrip)
{
HRGN region = CreateRectRgn(updateRect->left, updateRect->top,
updateRect->right, updateRect->bottom);
RECT rect;
POINT points[2];
static int num = 0;
HWND hToolbar = toolbarStrip->getHWindow();
GetClientRect(hToolbar, &rect);
points[0].x = rect.left;
points[0].y = rect.top;
points[1].x = rect.right;
points[1].y = rect.bottom;
MapWindowPoints(hWindow, hWindow, points, 2);
rect.left = points[0].x;
rect.top = points[0].y;
rect.right = points[1].x;
rect.bottom = points[1].y;
if (RectInRegion(region, &rect) || updateRect->top ==
getToolbarHeight() + 2)
{
// For some reason, the toolbar won't redraw itself until there's an
// idle moment. So it won't redraw while the model is spinning, for
// example. The folowing forces it to redraw itself right now.
RedrawWindow(hToolbar, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
}
DeleteObject(region);
}
if (noRect)
{
delete updateRect;
updateRect = NULL;
}
return 0;
}
void LDViewWindow::forceShowStatusBar(bool value)
{
if (value != showStatusBarOverride)
{
showStatusBarOverride = value;
if (fullScreenActive)
{
if (!hStatusBar && showStatusBarOverride)
{
addStatusBar();
}
else if (hStatusBar && !showStatusBarOverride)
{
removeStatusBar();
}
}
else if (!showStatusBar)
{
if (showStatusBarOverride)
{
addStatusBar();
}
else
{
removeStatusBar();
}
}
}
}
void LDViewWindow::showStatusIcon(
LDrawModelViewer::ViewMode viewMode,
bool redraw /*= true*/)
{
if ((showStatusBar || showStatusBarOverride) && hStatusBar)
{
HICON hModeIcon = hExamineIcon;
CUCSTR tipText = ls(_UC("ExamineMode"));
int iconPart = 2;
if (inLatLonMode())
{
iconPart = 3;
statusBarSetIcon(hStatusBar, 2, NULL);
statusBarSetTipText(hStatusBar, 2, _UC(""));
}
if (viewMode == LDrawModelViewer::VMFlyThrough)
{
hModeIcon = hFlythroughIcon;
tipText = ls(_UC("FlyThroughMode"));
}
else if (viewMode == LDrawModelViewer::VMWalk)
{
hModeIcon = hWalkIcon;
tipText = ls(_UC("WalkMode"));
}
statusBarSetIcon(hStatusBar, iconPart, hModeIcon);
statusBarSetTipText(hStatusBar, iconPart, tipText);
if (redraw)
{
redrawStatusBar();
}
}
}
void LDViewWindow::setHParentWindow(HWND hWnd)
{
hParentWindow = hWnd;
}
bool LDViewWindow::handleDpiChange(void)
{
if (toolbarStrip)
{
removeToolbar();
}
if (!showToolbar && !initialShown)
{
// Icons from the toolbar get applied to the main menu. So we
// need to create it here if it's not visible, then immediately
// delete it.
createToolbar();
toolbarStrip->release();
toolbarStrip = NULL;
}
removeStatusBar();
destroyStatusBarIcons();
loadStatusBarIcons();
reflectToolbar();
reflectStatusBar();
if (prefs != NULL)
{
prefs->checkForDpiChange();
}
if (modelWindow != NULL)
{
modelWindow->updateModelViewerSize();
}
return true;
}
void LDViewWindow::createToolbar(void)
{
toolbarStrip = new ToolbarStrip(getLanguageModule());
toolbarStrip->create(this);
if (showToolbar)
{
toolbarStrip->show();
}
}
LDrawModelViewer::ViewMode LDViewWindow::getViewMode(void)
{
LDrawModelViewer *modelViewer = modelWindow->getModelViewer();
if (modelViewer != NULL)
{
return modelViewer->getViewMode();
}
return LDrawModelViewer::VMExamine;
}
bool LDViewWindow::inExamineMode(void)
{
return getViewMode() == LDrawModelViewer::VMExamine;
}
bool LDViewWindow::inLatLonMode(void)
{
LDrawModelViewer *modelViewer = modelWindow->getModelViewer();
if (inExamineMode() && modelViewer &&
modelViewer->getExamineMode() == LDrawModelViewer::EMLatLong)
{
return true;
}
return false;
}
// Note: static method
int LDViewWindow::intRound(TCFloat value)
{
if (value >= 0)
{
return (int)(value + 0.5f);
}
else
{
return (int)(value - 0.5f);
}
}
void LDViewWindow::showStatusLatLon(void)
{
if (hStatusBar)
{
if (inLatLonMode())
{
LDrawModelViewer *modelViewer = modelWindow->getModelViewer();
int lat = intRound(modelViewer->getExamineLatitude());
int lon = intRound(modelViewer->getExamineLongitude());
UCCHAR buf[1024];
// Rounding can give us -180, even though LDrawModelViewer won't
// allow that as an actual value.
if (lon == -180)
{
lon = 180;
}
sucprintf(buf, COUNT_OF(buf), ls(_UC("LatLonFormat")), lat, lon);
setStatusText(hStatusBar, 2, buf);
}
else
{
setStatusText(hStatusBar, 2, _UC(""));
}
}
}
void LDViewWindow::setStatusText(
HWND hStatus,
TCByte part,
CUCSTR text,
bool redraw /*= false*/)
{
ucstring oldText;
statusBarGetText(hStatus, part, oldText);
if (oldText != text)
{
statusBarSetText(hStatus, part, text);
if (redraw)
{
redrawStatusBar();
}
}
}
void LDViewWindow::updateStatusParts(void)
{
if (hStatusBar)
{
int parts[] = {100, 100, -1, -1};
RECT rect;
int numParts = 3;
bool latLon = inLatLonMode();
int rightMargin = scalePoints(20);
int latLonWidth = scalePoints(100);
if (latLon)
{
numParts = 4;
parts[2] = 100;
rightMargin += latLonWidth;
}
statusBarSetParts(hStatusBar, numParts, parts);
SendMessage(hStatusBar, SB_GETRECT, (WPARAM)numParts - 1, (LPARAM)&rect);
parts[1] += rect.right - rect.left - rightMargin;
if (latLon)
{
parts[2] = parts[1] + latLonWidth;
}
statusBarSetParts(hStatusBar, numParts, parts, false);
showStatusIcon(getViewMode(), false);
showStatusLatLon();
}
}
void LDViewWindow::createStatusBar(void)
{
if (showStatusBar || showStatusBarOverride)
{
HWND hProgressBar;
RECT rect;
ModelWindow::initCommonControls(ICC_TREEVIEW_CLASSES | ICC_BAR_CLASSES);
hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE |
SBARS_SIZEGRIP | SBT_TOOLTIPS, _UC(""), hWindow, ID_STATUS_BAR);
SetWindowLongW(hStatusBar, GWL_EXSTYLE, WS_EX_TRANSPARENT);
updateStatusParts();
statusBarSetText(hStatusBar, 0, _UC(""), SBT_NOBORDERS);
SendMessage(hStatusBar, SB_GETRECT, 0, (LPARAM)&rect);
InflateRect(&rect, scalePoints(-4), scalePoints(-3));
hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, _UC(""),
WS_CHILD | WS_VISIBLE | PBS_SMOOTH, rect.left,
rect.top, rect.right - rect.left, rect.bottom - rect.top,
hStatusBar, NULL, hInstance, NULL);
showStatusIcon(getViewMode());
if (modelWindow)
{
modelWindow->setStatusBar(hStatusBar);
modelWindow->setProgressBar(hProgressBar);
}
redrawStatusBar();
}
}
void LDViewWindow::redrawStatusBar(void)
{
RedrawWindow(hStatusBar, NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
}
void LDViewWindow::reflectPovCameraAspect(bool saveSetting)
{
LDrawModelViewer *modelViewer = modelWindow->getModelViewer();
if (modelViewer->getPovCameraAspect() !=
getMenuCheck(hToolsMenu, ID_TOOLS_POV_CAMERA_ASPECT))
{
switchPovCameraAspect(saveSetting);
}
}
void LDViewWindow::reflectViewMode(bool saveSetting)
{
LDrawModelViewer::ViewMode viewMode =
(LDrawModelViewer::ViewMode)TCUserDefaults::longForKey(VIEW_MODE_KEY, 0,
false);
switchToViewMode(viewMode, saveSetting);
}
BOOL LDViewWindow::initWindow(void)
{
if (!modelWindow)
{
createModelWindow();
}
if (fullScreen || screenSaver)
{
if (hWindowMenu)
{
DestroyMenu(hWindowMenu);
hWindowMenu = NULL;
}
windowStyle = WS_POPUP | WS_MAXIMIZE;
if (screenSaver)
{
windowStyle |= WS_CLIPCHILDREN;
}
#ifndef _DEBUG
exWindowStyle |= WS_EX_TOPMOST;
#endif
}
else if (hParentWindow)
{
windowStyle = WS_CHILD;
}
else
{
hWindowMenu = LoadMenu(getLanguageModule(),
MAKEINTRESOURCE(IDR_MAIN_MENU));
windowStyle = standardWindowStyle;
if (topmost)
{
exWindowStyle |= WS_EX_TOPMOST;
}
else
{
exWindowStyle &= ~WS_EX_TOPMOST;
}
}
DWORD origThemeAppProps = CUIThemes::getThemeAppProperties();
if (TCUserDefaults::boolForKey(FORCE_THEMED_MENUS_KEY, false, false))
{
CUIThemes::setThemeAppProperties(STAP_ALLOW_NONCLIENT |
STAP_ALLOW_CONTROLS);
}
if (CUIWindow::initWindow())
{
CUIThemes::setThemeAppProperties(origThemeAppProps);
hFileMenu = GetSubMenu(GetMenu(hWindow), 0);
hViewMenu = GetSubMenu(GetMenu(hWindow), 2);
hStepMenu = GetSubMenu(GetMenu(hWindow), 3);
hToolsMenu = GetSubMenu(GetMenu(hWindow), 4);
hViewAngleMenu = findSubMenu(hViewMenu, 0);
hStandardSizesMenu = findSubMenu(hViewMenu, 1);
if (!CUIThemes::isThemeLibLoaded())
{
RemoveMenu(hViewMenu, ID_VIEW_VISUALSTYLE, MF_BYCOMMAND);
}
else
{
reflectVisualStyle();
}
reflectViewMode(false);
reflectPovCameraAspect(false);
populateRecentFileMenuItems();
updateModelMenuItems();
if (!fullScreen && !screenSaver)
{
setMenuCheck(hViewMenu, ID_VIEW_ALWAYSONTOP, topmost);
}
return modelWindow->initWindow();
}
return FALSE;
}
std::string LDViewWindow::getFloatUdKey(const char* udKey)
{
std::string floatUdKey = udKey;
floatUdKey += "Float";
return floatUdKey;
}
void LDViewWindow::savePixelSize(const char* udKey, int size)
{
float scaleFactor = (float)getScaleFactor();
float fsize = size / scaleFactor;
TCUserDefaults::setFloatForKey(fsize, getFloatUdKey(udKey).c_str(), false);
TCUserDefaults::setLongForKey((long)fsize, udKey, false);
}
int LDViewWindow::getSavedPixelSize(const char* udKey, int defaultSize)
{
std::string floatUdKey = getFloatUdKey(udKey);
double size = TCUserDefaults::floatForKey(floatUdKey.c_str(), -1.0, false);
if (size == -1.0)
{
size = TCUserDefaults::longForKey(udKey, defaultSize, true);
}
return (int)(size * getScaleFactor());
}
int LDViewWindow::getSavedWindowWidth(int defaultValue /*= -1*/)
{
return getSavedPixelSize(WINDOW_WIDTH_KEY,
defaultValue == -1 ? DEFAULT_WIN_WIDTH : defaultValue);
}
int LDViewWindow::getSavedWindowHeight(int defaultValue /*= -1*/)
{
return getSavedPixelSize(WINDOW_HEIGHT_KEY,
defaultValue == -1 ? DEFAULT_WIN_HEIGHT : defaultValue);
}
void LDViewWindow::createModelWindow(void)
{
int lwidth;
int lheight;
bool maximized;
TCObject::release(modelWindow);
lwidth = getSavedWindowWidth();
lheight = getSavedWindowHeight();
maximized = TCUserDefaults::longForKey(WINDOW_MAXIMIZED_KEY, 0, false) != 0;
if (screenSaver)
{
modelWindow = new SSModelWindow(this, 0, 0, lwidth, lheight);
}
else
{
// Note that while the toolbar and status bar might be turned on, they
// haven't been shown yet. They'll resize the model window when they
// get shown.
modelWindow = new ModelWindow(this, 0, 0, lwidth, lheight);
}
prefs = modelWindow->getPrefs();
prefs->retain();
}
BOOL LDViewWindow::showAboutBox(void)
{
if (!hAboutWindow)
{
createAboutBox();
}
if (hAboutWindow)
{
runDialogModal(hAboutWindow);
return TRUE;
}
return FALSE;
}
const std::string LDViewWindow::getAppVersion(void)
{
std::string utf8ProductVersion;
ucstringtoutf8(utf8ProductVersion, getProductVersion());
return utf8ProductVersion;
}
const std::string LDViewWindow::getAppAsciiCopyright(void)
{
std::string copyright;
ucstringtoutf8(copyright, getLegalCopyright());
std::string copyrightSym = "\xC2\xA9"; // UTF-8 character sequence
size_t index = copyright.find(copyrightSym);
if (index < copyright.size())
{
copyright.replace(index, copyrightSym.size(), "(C)");
}
return copyright;
}
const UCCHAR *LDViewWindow::getProductVersion(void)
{
if (!productVersion)
{
readVersionInfo();
}
return productVersion;
}
const UCCHAR *LDViewWindow::getLegalCopyright(void)
{
if (!legalCopyright)
{
readVersionInfo();
}
return legalCopyright;
}
void LDViewWindow::readVersionInfo(void)
{
UCCHAR moduleFilename[1024];
if (productVersion != NULL)
{
return;
}
if (GetModuleFileName(NULL, moduleFilename, COUNT_OF(moduleFilename)) > 0)
{
DWORD zero;
DWORD versionInfoSize = GetFileVersionInfoSize(moduleFilename, &zero);
if (versionInfoSize > 0)
{
BYTE *versionInfo = new BYTE[versionInfoSize];
if (GetFileVersionInfo(moduleFilename, NULL, versionInfoSize,
versionInfo))
{
UCCHAR *value;
UINT versionLength;
if (VerQueryValue(versionInfo,
_UC("\\StringFileInfo\\040904B0\\ProductVersion"),
(void**)&value, &versionLength))
{
productVersion = copyString(value);
}
if (VerQueryValue(versionInfo,
_UC("\\StringFileInfo\\040904B0\\LegalCopyright"),
(void**)&value, &versionLength))
{
legalCopyright = copyString(value);
}
}
delete[] versionInfo;
}
}
}
#include <time.h>
void LDViewWindow::createAboutBox(void)
{
ucstring fullVersionFormat;
UCCHAR fullVersionString[1024];
UCCHAR versionString[128];
UCCHAR copyrightString[128];
UCCHAR buildDateString[128];
char *tmpString = stringByReplacingSubstring(__DATE__, " ", " ");
// Note: __DATE__ is ALWAYS in English, and thus will never contain
// non-ASCII characters.
UCCHAR *tmpUCString = mbstoucstring(tmpString);
size_t dateCount;
UCCHAR **dateComponents = componentsSeparatedByString(tmpUCString, _UC(" "),
dateCount);
delete[] tmpString;
delete[] tmpUCString;
ucstrcpy(buildDateString, _UC("!UnknownDate!"));
if (dateCount == 3)
{
const UCCHAR *buildMonth = ls(dateComponents[0]);
if (buildMonth)
{
sucprintf(buildDateString, COUNT_OF(buildDateString),
_UC("%s %s, %s"), dateComponents[1], buildMonth,
dateComponents[2]);
}
}
deleteStringArray(dateComponents, dateCount);
ucstrcpy(versionString, ls(_UC("!UnknownVersion!")));
ucstrcpy(copyrightString, ls(_UC("Copyright")));
hAboutWindow = createDialog(IDD_ABOUT_BOX);
CUIDialog::windowGetText(hAboutWindow, IDC_VERSION_LABEL, fullVersionFormat);
readVersionInfo();
if (productVersion != NULL)
{
ucstrcpy(versionString, productVersion);
}
if (legalCopyright != NULL)
{
ucstrcpy(copyrightString, legalCopyright);
}
#ifdef _WIN64
const UCCHAR *platform = _UC("x64");
#else // _WIN64
const UCCHAR *platform = _UC("x86");
#endif // _WIN64
sucprintf(fullVersionString, COUNT_OF(fullVersionString),
fullVersionFormat.c_str(), versionString, platform, buildDateString,
copyrightString);
CUIDialog::windowSetText(hAboutWindow, IDC_VERSION_LABEL, fullVersionString);
}
BOOL LDViewWindow::doLDrawDirOK(HWND hDlg)
{
ucstring ldrawDir;
CUIDialog::windowGetText(hDlg, IDC_LDRAWDIR, ldrawDir);
if (!ldrawDir.empty())
{
doDialogClose(hDlg);
}
else
{
MessageBeep(MB_ICONEXCLAMATION);
}
return TRUE;
}
LRESULT LDViewWindow::doMouseWheel(short keyFlags, short zDelta, int /*xPos*/,
int /*yPos*/)
{
if (modelWindow)
{
modelWindow->mouseWheel(keyFlags, zDelta);
return 0;
}
return 1;
}
UINT CALLBACK lDrawDirBrowseHook(HWND /*hDlg*/, UINT message, WPARAM /*wParam*/,
LPARAM lParam)
{
#ifdef _DEBUG
_CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "hook message: 0x%X\n", message);
#endif // _DEBUG
if (message == WM_NOTIFY)
{
LPOFNOTIFY notification = (LPOFNOTIFY)lParam;
switch (notification->hdr.code)
{
case CDN_FILEOK:
#ifdef _DEBUG
_CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "OK Pressed\n");
#endif // _DEBUG
break;
case CDN_FOLDERCHANGE:
#ifdef _DEBUG