1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 //
7 // This file is part of Nestopia.
8 //
9 // Nestopia is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Nestopia is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Nestopia; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////
24 
25 #ifndef NST_APPLICATION_INSTANCE_H
26 #define NST_APPLICATION_INSTANCE_H
27 
28 #pragma once
29 
30 #include "NstObjectDelegate.hpp"
31 #include "NstCollectionVector.hpp"
32 #include "NstApplicationConfiguration.hpp"
33 #include "NstWindowGeneric.hpp"
34 
35 namespace Nestopia
36 {
37 	namespace Application
38 	{
39 		class Instance
40 		{
41 		public:
42 
43 			Instance();
44 			~Instance();
45 
46 			void Save();
47 
48 			static const Path& GetExePath();
49 			static const Path GetExePath(const GenericString);
50 			static const Path GetConfigPath(const GenericString);//bg
51 			static const Path GetLongPath(wcstring);
52 			static const Path GetTmpPath(GenericString=GenericString());
53 			static const Path GetFullPath(const GenericString);
54 			static const String::Heap<char>& GetVersion();
55 
56 			static uint NumChildWindows();
57 			static void ShowChildWindows(bool=true);
58 			static Window::Generic GetChildWindow(uint=0);
59 			static Window::Generic GetMainWindow();
60 			static Window::Generic GetActiveWindow();
61 
62 			class Language;
63 
64 			static Language& GetLanguage();
65 
66 			enum IconStyle
67 			{
68 				ICONSTYLE_NES,
69 				ICONSTYLE_FAMICOM
70 			};
71 
72 			static IconStyle GetIconStyle();
73 			static void SetIconStyle(IconStyle);
74 
75 			enum
76 			{
77 				WM_NST_COMMAND_RESUME = WM_APP + 55,
78 				WM_NST_LAUNCH = WM_APP + 56,
79 				COPYDATA_OPENFILE_ID = 0xDEAF
80 			};
81 
82 			enum Event
83 			{
84 				EVENT_WINDOW_CREATE = 1,
85 				EVENT_WINDOW_DESTROY,
86 				EVENT_SYSTEM_BUSY,
87 				EVENT_FULLSCREEN,
88 				EVENT_DESKTOP
89 			};
90 
91 			class Events
92 			{
93 			public:
94 
95 				struct WindowCreateParam
96 				{
97 					HWND hWnd;
98 					uint x;
99 					uint y;
100 				};
101 
102 				struct WindowDestroyParam
103 				{
104 					HWND hWnd;
105 				};
106 
107 			private:
108 
109 				typedef Object::Delegate<void,Event,const void*> Callback;
110 
111 				struct Callbacks : Collection::Vector<Callback>
112 				{
113 					~Callbacks();
114 				};
115 
116 				static void Add(const Callback&);
117 
118 				static Callbacks callbacks;
119 
120 			public:
121 
122 				static void Remove(const void*);
123 				static void Signal(Event,const void* = NULL);
124 
125 				template<typename Data,typename Code>
Add(Data * data,Code code)126 				static void Add(Data* data,Code code)
127 				{
128 					Add( Callback(data,code) );
129 				}
130 			};
131 
132 		private:
133 
134 			Configuration cfg;
135 
136 			struct Global;
137 			static Global global;
138 
139 			static const wchar_t appClassName[];
140 
141 		public:
142 
GetConfiguration2()143 			Configuration& GetConfiguration2()
144 			{
145 				return cfg;
146 			}
147 
GetClassName()148 			static wcstring GetClassName()
149 			{
150 				return appClassName;
151 			}
152 
153 			class Waiter
154 			{
155 				HCURSOR const hCursor;
156 
157 			public:
158 
159 				Waiter();
160 
~Waiter()161 				~Waiter()
162 				{
163 					::SetCursor( hCursor );
164 				}
165 			};
166 
167 			class Locker
168 			{
169 				HWND const hWnd;
170 				const bool enabled;
171 
172 			public:
173 
174 				Locker();
175 				~Locker();
176 
177 				bool CheckInput(int) const;
178 			};
179 		};
180 	}
181 }
182 
183 #endif
184