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 "NstWindowParam.hpp" 26 #include "NstDialogLanguage.hpp" 27 28 namespace Nestopia 29 { 30 namespace Window 31 { 32 struct Language::Handlers 33 { 34 static const MsgHandler::Entry<Language> messages[]; 35 static const MsgHandler::Entry<Language> commands[]; 36 }; 37 38 const MsgHandler::Entry<Language> Language::Handlers::messages[] = 39 { 40 { WM_INITDIALOG, &Language::OnInitDialog } 41 }; 42 43 const MsgHandler::Entry<Language> Language::Handlers::commands[] = 44 { 45 { IDOK, &Language::OnCmdOk }, 46 { IDC_LANGUAGE_LIST, &Language::OnDblClk } 47 }; 48 Language()49 Language::Language() 50 : dialog(IDD_LANGUAGE,this,Handlers::messages,Handlers::commands) {} 51 ~Language()52 Language::~Language() 53 { 54 } 55 OnInitDialog(Param &)56 ibool Language::OnInitDialog(Param&) 57 { 58 paths.clear(); 59 Application::Instance::GetLanguage().EnumerateResources( paths ); 60 61 const Control::ListBox listBox( dialog.ListBox(IDC_LANGUAGE_LIST) ); 62 63 Path name; 64 65 for (Paths::const_iterator it(paths.begin()), end(paths.end()); it != end; ++it) 66 { 67 name = it->File(); 68 name.Extension().Clear(); 69 ::CharUpperBuff( name.Ptr(), 1 ); 70 71 const uint index = listBox.Add( name.Ptr() ).GetIndex(); 72 listBox[index].Data() = (it - paths.begin()); 73 74 if (*it == Application::Instance::GetLanguage().GetResourcePath()) 75 listBox[index].Select(); 76 } 77 78 return true; 79 } 80 CloseOk()81 void Language::CloseOk() 82 { 83 const Control::ListBox listBox( dialog.ListBox(IDC_LANGUAGE_LIST) ); 84 85 if (listBox.AnySelection()) 86 { 87 const uint index = listBox.Selection().Data(); 88 89 if (paths[index] != Application::Instance::GetLanguage().GetResourcePath()) 90 newPath = paths[index]; 91 } 92 93 dialog.Close(); 94 } 95 OnCmdOk(Param & param)96 ibool Language::OnCmdOk(Param& param) 97 { 98 if (param.Button().Clicked()) 99 CloseOk(); 100 101 return true; 102 } 103 OnDblClk(Param & param)104 ibool Language::OnDblClk(Param& param) 105 { 106 if (HIWORD(param.wParam) == LBN_DBLCLK) 107 { 108 CloseOk(); 109 return true; 110 } 111 112 return false; 113 } 114 } 115 } 116