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 #include "NstObjectHeap.hpp"
26 #include "NstWindowParam.hpp"
27 #include "NstManager.hpp"
28 #include "NstDialogLauncher.hpp"
29 #include "NstManagerLauncher.hpp"
30 
31 namespace Nestopia
32 {
33 	namespace Managers
34 	{
Launcher(Emulator & e,const Configuration & cfg,Window::Menu & m,const Paths & paths,Window::Custom & w)35 		Launcher::Launcher(Emulator& e,const Configuration& cfg,Window::Menu& m,const Paths& paths,Window::Custom& w)
36 		:
37 		Manager    ( e, m, this, &Launcher::OnEmuEvent, IDM_FILE_LAUNCHER, &Launcher::OnCmdLauncher, &Launcher::OnAppEvent ),
38 		fullscreen ( false ),
39 		window     ( w ),
40 		dialog     ( new Window::Launcher(Nes::Cartridge(e).GetDatabase(),paths,cfg) )
41 		{
42 			state[FITS] = true;
43 			state[AVAILABLE] = true;
44 
45 			static const Window::MsgHandler::HookEntry<Launcher> hooks[] =
46 			{
47 				{ WM_ACTIVATE,      &Launcher::OnActivate      },
48 				{ WM_DISPLAYCHANGE, &Launcher::OnDisplayChange }
49 			};
50 
51 			window.Messages().Hooks().Add( this, hooks );
52 		}
53 
~Launcher()54 		Launcher::~Launcher()
55 		{
56 			window.Messages().Hooks().Remove( this );
57 		}
58 
Save(Configuration & cfg,bool saveSize,bool saveFiles) const59 		void Launcher::Save(Configuration& cfg,bool saveSize,bool saveFiles) const
60 		{
61 			dialog->Save( cfg, saveSize, saveFiles );
62 		}
63 
Update()64 		void Launcher::Update()
65 		{
66 			if (!state[FITS] || !state[AVAILABLE])
67 				dialog->Close();
68 
69 			menu[IDM_FILE_LAUNCHER].Enable( state[FITS] && state[AVAILABLE] );
70 		}
71 
OnCmdLauncher(uint)72 		void Launcher::OnCmdLauncher(uint)
73 		{
74 			dialog->Open( fullscreen );
75 		}
76 
OnActivate(Window::Param & param)77 		void Launcher::OnActivate(Window::Param& param)
78 		{
79 			if (param.Activator().Entering() && !param.Activator().Minimized())
80 				dialog->Synchronize( param.hWnd );
81 		}
82 
OnDisplayChange(Window::Param & param)83 		void Launcher::OnDisplayChange(Window::Param& param)
84 		{
85 			state[FITS] =
86 			(
87 				LOWORD(param.lParam) >= MIN_DIALOG_WIDTH &&
88 				HIWORD(param.lParam) >= MIN_DIALOG_HEIGHT
89 			);
90 
91 			Update();
92 		}
93 
OnEmuEvent(const Emulator::Event event,const Emulator::Data data)94 		void Launcher::OnEmuEvent(const Emulator::Event event,const Emulator::Data data)
95 		{
96 			switch (event)
97 			{
98 				case Emulator::EVENT_NETPLAY_MODE:
99 
100 					state[AVAILABLE] = !data;
101 					Update();
102 					break;
103 			}
104 		}
105 
OnAppEvent(Application::Instance::Event event,const void *)106 		void Launcher::OnAppEvent(Application::Instance::Event event,const void*)
107 		{
108 			switch (event)
109 			{
110 				case Application::Instance::EVENT_FULLSCREEN:
111 				case Application::Instance::EVENT_DESKTOP:
112 
113 					fullscreen = (event == Application::Instance::EVENT_FULLSCREEN);
114 					dialog->Close();
115 					break;
116 			}
117 		}
118 	}
119 }
120