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_WINDOW_DIALOG_H 26 #define NST_WINDOW_DIALOG_H 27 28 #pragma once 29 30 #include "language/resource.h" 31 #include "NstWindowCustom.hpp" 32 #include "NstCtrlCheckBox.hpp" 33 #include "NstCtrlRadioButton.hpp" 34 #include "NstCtrlListBox.hpp" 35 #include "NstCtrlListView.hpp" 36 #include "NstCtrlTreeView.hpp" 37 #include "NstCtrlComboBox.hpp" 38 #include "NstCtrlSlider.hpp" 39 #include "NstCtrlEdit.hpp" 40 41 namespace Nestopia 42 { 43 namespace Window 44 { 45 class Dialog : public Custom 46 { 47 public: 48 49 explicit Dialog(uint); 50 51 template<typename Owner,typename MsgArray> 52 Dialog(uint,Owner*,MsgArray&); 53 54 template<typename Owner,typename MsgArray,typename CmdArray> 55 Dialog(uint,Owner*,MsgArray&,CmdArray&); 56 57 template<typename Owner,typename Msg> 58 Dialog(uint,uint,Owner*,Msg); 59 60 ~Dialog(); 61 62 enum Type 63 { 64 MODAL, 65 MODELESS_CHILD, 66 MODELESS_FREE 67 }; 68 69 INT_PTR Open(Type=MODAL); 70 void Close(int=0); 71 void SetItemIcon(uint,uint) const; 72 73 private: 74 75 class NoTaskbarWindow; 76 77 typedef Collection::Vector<Dialog*> Instances; 78 79 void Init(); 80 81 ibool OnCommand (Param&); 82 ibool OnClose (Param&); 83 84 void OnIdle (Param&); 85 void OnSysCommand (Param&); 86 void OnNclButton (Param&); 87 void OnNcrButton (Param&); 88 89 NST_NO_INLINE void Fetch(HWND); 90 NST_NO_INLINE void Ditch(Instances::Iterator); 91 92 static BOOL CALLBACK DlgProc(HWND,uint,WPARAM,LPARAM); 93 94 MsgHandler cmdHandler; 95 const uint id; 96 const NoTaskbarWindow* noTaskbarWindow; 97 98 class ModelessDialogs 99 { 100 public: 101 102 static void Add(HWND); 103 static bool Remove(HWND); 104 105 private: 106 107 typedef bool (*Processor)(MSG&); 108 typedef Collection::Vector<HWND> Instances; 109 110 static void Update(); 111 static bool ProcessNone (MSG&); 112 static bool ProcessSingle (MSG&); 113 static bool ProcessMultiple (MSG&); 114 115 static Processor processor; 116 static Instances instances; 117 118 public: 119 ProcessMessage(MSG & msg)120 static bool ProcessMessage(MSG& msg) 121 { 122 return processor( msg ); 123 } 124 }; 125 126 static Instances instances; 127 128 public: 129 Control(uint id) const130 Control::Generic Control (uint id) const { return Control::Generic ( hWnd, id ); } CheckBox(uint id) const131 Control::CheckBox CheckBox (uint id) const { return Control::CheckBox ( hWnd, id ); } ComboBox(uint id) const132 Control::ComboBox ComboBox (uint id) const { return Control::ComboBox ( hWnd, id ); } RadioButton(uint id) const133 Control::RadioButton RadioButton (uint id) const { return Control::RadioButton ( hWnd, id ); } Edit(uint id) const134 Control::Edit Edit (uint id) const { return Control::Edit ( hWnd, id ); } ListBox(uint id) const135 Control::ListBox ListBox (uint id) const { return Control::ListBox ( hWnd, id ); } ListView(uint id) const136 Control::ListView ListView (uint id) const { return Control::ListView ( hWnd, id ); } TreeView(uint id) const137 Control::TreeView TreeView (uint id) const { return Control::TreeView ( hWnd, id ); } Slider(uint id) const138 Control::Slider Slider (uint id) const { return Control::Slider ( hWnd, id ); } 139 GetId() const140 uint GetId() const 141 { 142 return id; 143 } 144 IsOpen() const145 bool IsOpen() const 146 { 147 return hWnd; 148 } 149 Commands()150 MsgHandler& Commands() 151 { 152 return cmdHandler; 153 } 154 ProcessMessage(MSG & msg)155 static bool ProcessMessage(MSG& msg) 156 { 157 return ModelessDialogs::ProcessMessage( msg ); 158 } 159 RegisterModeless(HWND hWnd)160 static void RegisterModeless(HWND hWnd) 161 { 162 NST_ASSERT( hWnd ); 163 ModelessDialogs::Add( hWnd ); 164 } 165 UnregisterModeless(HWND hWnd)166 static bool UnregisterModeless(HWND hWnd) 167 { 168 NST_ASSERT( hWnd ); 169 return ModelessDialogs::Remove( hWnd ); 170 } 171 }; 172 } 173 } 174 175 #include "NstWindowDialog.inl" 176 177 #endif 178