File: NstDialogLauncher.hpp

package info (click to toggle)
nestopia 1.52.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,140 kB
  • sloc: cpp: 127,444; xml: 27,234; ansic: 3,635; makefile: 949; sh: 19
file content (811 lines) | stat: -rw-r--r-- 15,833 bytes parent folder | download | duplicates (3)
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
////////////////////////////////////////////////////////////////////////////////////////
//
// Nestopia - NES/Famicom emulator written in C++
//
// Copyright (C) 2003-2008 Martin Freij
//
// This file is part of Nestopia.
//
// Nestopia 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 2 of the License, or
// (at your option) any later version.
//
// Nestopia 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 Nestopia; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
////////////////////////////////////////////////////////////////////////////////////////

#ifndef NST_DIALOG_LAUNCHER_H
#define NST_DIALOG_LAUNCHER_H

#pragma once

#include <vector>
#include <map>
#include "NstCollectionBitSet.hpp"
#include "NstWindowMenu.hpp"
#include "NstWindowStatusBar.hpp"
#include "NstWindowDialog.hpp"
#include "NstDialogFind.hpp"
#include "../core/api/NstApiCartridge.hpp"
#include <CommCtrl.h>

namespace Nes
{
	using namespace Api;
}

namespace Nestopia
{
	namespace Io
	{
		class File;
	}

	namespace Managers
	{
		class Paths;
	}

	namespace Window
	{
		class Launcher
		{
		public:

			Launcher(const Nes::Cartridge::Database&,const Managers::Paths&,const Configuration&);
			~Launcher();

			void Save(Configuration&,bool,bool);
			void Open(bool);
			void Synchronize(HWND) const;
			void Close();

		private:

			struct Handlers;

			enum
			{
				STATUSBAR_SECOND_FIELD_WIDTH = 14,
				CMD_ENTER = 1
			};

			void UpdateItemCount(uint) const;
			void OnNoSelection() const;

			ibool OnInitDialog (Param&);
			ibool OnDropFiles  (Param&);
			ibool OnSize       (Param&);
			ibool OnCmdEnter   (Param&);
			ibool OnClose      (Param&);
			ibool OnDestroy    (Param&);

			void OnCmdFileRun                   (uint=0);
			void OnCmdFileRefresh               (uint);
			void OnCmdEditHeader                (uint);
			void OnCmdViewShowGrids             (uint);
			void OnCmdViewShowDatabaseCorrected (uint);
			void OnCmdViewShowOnTop             (uint);
			void OnCmdOptionsPaths              (uint);
			void OnCmdOptionsColors             (uint);

			void OnListGetDisplayInfo    (const NMHDR&);
			void OnListKeyDown           (const NMHDR&);
			void OnListColumnClick       (const NMHDR&);
			void OnListItemActivate      (const NMHDR&);
			void OnListItemChanged       (const NMHDR&);
			void OnListInsertItem        (const NMHDR&);
			void OnListDeleteItem        (const NMHDR&);
			void OnListDeleteAllItems    (const NMHDR&);
			void OnTreeSelectionChanging (const NMHDR&);

			class List
			{
			public:

				List
				(
					Dialog&,
					Menu::CmdHandler&,
					const Managers::Paths&,
					const Configuration&,
					const Nes::Cartridge::Database&
				);

				~List();

				void operator = (const Control::ListView&);

				enum Updater
				{
					DONT_REPAINT,
					REPAINT
				};

				void Add(wcstring);
				void Close();
				void Save(Configuration&,bool);
				void Sort(uint=0);
				bool CanRefresh() const;
				void Refresh();
				void Insert(const Param&);
				void SetColors(uint,uint,Updater=DONT_REPAINT) const;
				void OnGetDisplayInfo(LPARAM);

				class Paths
				{
				public:

					explicit Paths(const Configuration&);

					void Save(Configuration&) const;

					struct Settings
					{
						struct Folder
						{
							Path path;
							bool incSubDir;
						};

						typedef std::vector<Folder> Folders;

						struct Include : Collection::BitSet
						{
							enum
							{
								NES,UNF,XML,FDS,NSF,PATCH,ARCHIVE,ANY,UNIQUE
							};

							enum
							{
								TYPES = NES|UNF|XML|FDS|NSF|PATCH,
								FILES = TYPES|ARCHIVE
							};

							explicit Include(bool a=false)
							: Collection::BitSet( (0xFF^0x40) | uint(a) << 6 ) {}
						};

						Include include;
						Folders folders;
					};

				private:

					struct Handlers;

					enum
					{
						LIMIT = 999
					};

					ibool OnInitDialog (Param&);
					ibool OnCmdAdd     (Param&);
					ibool OnCmdRemove  (Param&);
					ibool OnCmdClear   (Param&);
					ibool OnCmdOk      (Param&);

					void OnKeyDown     (const NMHDR&);
					void OnItemChanged (const NMHDR&);
					void OnInsertItem  (const NMHDR&);
					void OnDeleteItem  (const NMHDR&);

					Settings settings;
					Dialog dialog;
					const Control::NotificationHandler notifications;

				public:

					void Open()
					{
						dialog.Open();
					}

					const Settings& GetSettings() const
					{
						return settings;
					}
				};

				class Files
				{
					class Inserter;
					class Searcher;

				public:

					class Strings
					{
						HeapString container;

					public:

						explicit Strings(uint=0);

						typedef uint Index;

						enum
						{
							NONE = -1
						};

						int  Find(GenericString) const;
						void Clear();

						template<typename T>
						Index operator << (const T& t)
						{
							uint pos = container.Length();
							container << t << '\0';
							return pos;
						}

						Index Import(cstring t)
						{
							uint pos = container.Length();
							container.Import( t );
							container << '\0';
							return pos;
						}

						wcstring operator [] (uint i) const
						{
							return container.Ptr() + i;
						}

						uint Size() const
						{
							return container.Length() * (container.Wide() ? 2 : 1);
						}
					};

					Files();

					void Load();
					void Save();
					void Refresh(const Paths::Settings&,const Nes::Cartridge::Database&);
					bool Insert(const Nes::Cartridge::Database&,GenericString);
					void Clear();
					bool ShouldDefrag() const;
					void Defrag();

					class Entry
					{
						friend class Files;
						friend class Inserter;
						friend class Searcher;

					public:

						typedef Nes::Cartridge::Database Db;

						enum Type
						{
							NES     = 0x01,
							UNF     = 0x02,
							XML     = 0x04,
							FDS     = 0x08,
							NSF     = 0x10,
							PATCH   = 0x20,
							ARCHIVE = 0x80,
							ALL     = NES|UNF|XML|FDS|NSF|PATCH
						};

						enum
						{
							SYSTEM_UNKNOWN,
							SYSTEM_PC10,
							SYSTEM_VS,
							SYSTEM_PAL,
							SYSTEM_NTSC,
							SYSTEM_NTSC_PAL
						};

						uint GetSystem(const Db*) const;

					private:

						explicit Entry(uint=0);

						Db::Entry SearchDb(const Db*) const;

						enum
						{
							ATR_BATTERY     = 0x08,
							ATR_PC10        = 0x10,
							ATR_VS          = 0x20,
							ATR_PAL         = 0x40,
							ATR_NTSC        = 0x80,
							ATR_NTSC_PAL    = ATR_PAL|ATR_NTSC,
							ATR_DEFAULT_FDS = ATR_NTSC
						};

						Strings::Index file;
						Strings::Index path;
						Strings::Index name;

						typedef Nes::Cartridge::Profile::Hash Hash;

						Hash hash;

						ushort pRom;
						ushort cRom;
						ushort wRam;
						ushort vRam;
						ushort mapper;
						uchar type;
						uchar attributes;

					public:

						uint GetType() const
						{
							return type;
						}

						wcstring GetPath(const Strings& strings) const
						{
							return strings[path];
						}

						wcstring GetFile(const Strings& strings) const
						{
							return strings[file];
						}

						wcstring GetName(const Strings& strings,const Db* db) const
						{
							if (const Db::Entry entry = SearchDb( db ))
							{
								wcstring title = entry.GetTitle();

								if (*title)
									return title;
							}

							return name ? strings[name] : L"-";
						}

						uint GetPRom(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetPrgRom() / Nes::Core::SIZE_1K;
							else
								return pRom;
						}

						uint GetCRom(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetChrRom() / Nes::Core::SIZE_1K;
							else
								return cRom;
						}

						uint GetWRam(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetWram() / Nes::Core::SIZE_1K;
							else
								return wRam;
						}

						uint GetVRam(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetVram() / Nes::Core::SIZE_1K;
							else
								return vRam;
						}

						bool GetBattery(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.HasBattery();
							else
								return (attributes & ATR_BATTERY);
						}

						uint GetMapper(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetMapper();
							else
								return mapper;
						}

						Nes::Cartridge::Profile::Dump::State GetDump(const Db* db=NULL) const
						{
							if (const Db::Entry entry = SearchDb( db ))
								return entry.GetDumpState();
							else
								return Nes::Cartridge::Profile::Dump::UNKNOWN;
						}
					};

					typedef Collection::Vector<Entry> Entries;

				private:

					enum Exception
					{
						ERR_CORRUPT_DATA
					};

					enum
					{
						MAX_ENTRIES = 0xFFFFF,
						GARBAGE_THRESHOLD = 127
					};

					ushort dirty;
					ushort loaded;
					Strings strings;
					Entries entries;

				public:

					uint Count() const
					{
						return entries.Size();
					}

					const Entry& operator [] (uint i) const
					{
						return entries[i];
					}

					void Disable(Entry* entry)
					{
						if (entry->type)
						{
							entry->type = 0;
							dirty = true;
						}
					}

					const Strings& GetStrings() const
					{
						return strings;
					}
				};

				class Columns
				{
				public:

					explicit Columns(const Configuration&);

					void Update(const uchar*);
					void Save(Configuration&) const;

					enum Type
					{
						TYPE_FILE,
						TYPE_SYSTEM,
						TYPE_MAPPER,
						TYPE_PROM,
						TYPE_CROM,
						TYPE_WRAM,
						TYPE_VRAM,
						TYPE_BATTERY,
						TYPE_DUMP,
						TYPE_NAME,
						TYPE_FOLDER,
						NUM_TYPES,
						NUM_DEFAULT_SELECTED_TYPES = 9,
						NUM_DEFAULT_AVAILABLE_TYPES = NUM_TYPES - NUM_DEFAULT_SELECTED_TYPES
					};

				private:

					struct Handlers;

					void Reset();
					void Add(uint,uint);
					void UpdateButtonRemove();
					void UpdateButtonAdd();

					ibool OnInitDialog   (Param&);
					ibool OnCmdSelected  (Param&);
					ibool OnCmdAvailable (Param&);
					ibool OnCmdAdd       (Param&);
					ibool OnCmdRemove    (Param&);
					ibool OnCmdDefault   (Param&);
					ibool OnCmdOk        (Param&);

					typedef Collection::Vector<uchar> Types;

					Types available;
					Types selected;
					Dialog dialog;

					static wcstring const cfgStrings[NUM_TYPES];

				public:

					uint Count() const
					{
						return selected.Size();
					}

					Type GetType(uint i) const
					{
						return Type(selected[i]);
					}

					uint GetStringId(uint i) const
					{
						return IDS_LAUNCHER_COLUMN_FILE + selected[i];
					}

					void Open()
					{
						dialog.Open();
					}
				};

			private:

				class Strings
				{
				public:

					wcstring GetMapper(uint);
					wcstring GetSize(uint);
					void Flush();

				private:

					struct ValueString
					{
						wchar_t string[5];
					};

					typedef String::Stack<10+1> SizeString;
					typedef std::map<uint,SizeString> Sizes;
					typedef Collection::Vector<ValueString> Mappers;

					Sizes sizes;
					Mappers mappers;
				};

				enum
				{
					STYLE =
					(
						LVS_EX_FULLROWSELECT |
						LVS_EX_TWOCLICKACTIVATE |
						LVS_EX_HEADERDRAGDROP
					)
				};

				void ReloadListColumns() const;
				void UpdateColumnOrder();
				void UpdateSortColumnOrder(uint);
				void Redraw();
				int  Sorter(const void*,const void*);
				void OnFind(GenericString,uint);
				bool Optimize();

				void OnCmdEditFind         (uint);
				void OnCmdEditInsert       (uint);
				void OnCmdEditDelete       (uint);
				void OnCmdEditClear        (uint);
				void OnCmdViewAlignColumns (uint);
				void OnCmdOptionsColumns   (uint);

				Control::ListView ctrl;

				const Nes::Cartridge::Database imageDatabase;
				const Nes::Cartridge::Database* useImageDatabase;

				uchar order[Columns::NUM_TYPES];

				uint typeFilter;
				uint style;

				Finder finder;
				Paths paths;
				Files files;
				Columns columns;
				Strings strings;
				const Managers::Paths& pathManager;

			public:

				Generic GetWindow() const
				{
					return ctrl.GetWindow();
				}

				void OpenPathDialog()
				{
					paths.Open();
				}

				void Draw(uint type)
				{
					typeFilter = type;
					Redraw();
				}

				bool DatabaseCorrectionEnabled() const
				{
					return useImageDatabase;
				}

				bool ToggleDatabase()
				{
					useImageDatabase = (useImageDatabase ? NULL : &imageDatabase);
					ctrl.Redraw();
					return useImageDatabase;
				}

				bool ToggleGrids()
				{
					style ^= LVS_EX_GRIDLINES;
					ctrl.StyleEx() = style;
					return style & LVS_EX_GRIDLINES;
				}

				bool HitTest(const Point& point) const
				{
					return ctrl.HitTest( point.x, point.y );
				}

				uint GetStyle() const
				{
					return ctrl.StyleEx();
				}

				HWND GetHandle() const
				{
					return ctrl.GetHandle();
				}

				uint NumPaths() const
				{
					return paths.GetSettings().folders.size();
				}

				uint Size() const
				{
					return ctrl.Size();
				}

				const Files::Entry* operator [] (uint i) const
				{
					return static_cast<const Files::Entry*>(static_cast<const void*>( ctrl[i].Data() ));
				}

				const Files::Entry* GetSelection() const
				{
					int index = ctrl.Selection().GetIndex();
					return index >= 0 ? (*this)[index] : NULL;
				}

				const Files::Strings& GetStrings() const
				{
					return files.GetStrings();
				}

				const Managers::Paths& GetPaths() const
				{
					return pathManager;
				}
			};

			class Tree
			{
			public:

				Tree();

				void operator = (const Control::TreeView&);

				enum Updater {DONT_REPAINT,REPAINT};

				void SetColors(uint,uint,Updater=DONT_REPAINT) const;
				uint GetType(HTREEITEM) const;
				void Close();

			private:

				Control::TreeView ctrl;
				uint selection;
				const Control::TreeView::ImageList imageList;

			public:

				Generic GetWindow() const
				{
					return ctrl.GetWindow();
				}
			};

			class Colors
			{
			public:

				explicit Colors(const Configuration&);

				void Save(Configuration&) const;

			private:

				struct Handlers;

				enum
				{
					DEF_BACKGROUND_COLOR = RGB(0xFF,0xFF,0xFF),
					DEF_FOREGROUND_COLOR = RGB(0x00,0x00,0x00)
				};

				struct Type
				{
					inline Type(int,int,int,int);

					COLORREF color;
					const Rect rect;
				};

				void UpdateColor(const Type&) const;
				void UpdateColors() const;
				void ChangeColor(COLORREF&);

				ibool OnInitDialog          (Param&);
				ibool OnPaint               (Param&);
				ibool OnCmdChangeBackground (Param&);
				ibool OnCmdChangeForeground (Param&);
				ibool OnCmdDefault          (Param&);

				Type background;
				Type foreground;

				COLORREF customColors[16];

				Dialog dialog;

			public:

				COLORREF GetBackgroundColor() const
				{
					return background.color;
				}

				COLORREF GetForegroundColor() const
				{
					return foreground.color;
				}

				void Open()
				{
					dialog.Open();
				}
			};

			Dialog dialog;
			Menu menu;
			Control::NotificationHandler listNotifications;
			Control::NotificationHandler treeNotifications;
			StatusBar statusBar;
			Tree tree;
			List list;
			Point margin;
			Colors colors;
			Point initialSize;
		};
	}
}

#endif