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_PARAM_H 26 #define NST_WINDOW_PARAM_H 27 28 #pragma once 29 30 #include <cstdlib> 31 #include "NstMain.hpp" 32 #include <windows.h> 33 34 namespace Nestopia 35 { 36 namespace Window 37 { 38 struct Param 39 { 40 WPARAM wParam; 41 LPARAM lParam; 42 LRESULT lResult; 43 HWND hWnd; 44 45 class ButtonParam 46 { 47 const uint wParam; 48 49 public: 50 ButtonParam(uint w)51 explicit ButtonParam(uint w) 52 : wParam(w) {} 53 Clicked() const54 bool Clicked() const 55 { 56 return HIWORD(wParam) == BN_CLICKED; 57 } 58 GetId() const59 uint GetId() const 60 { 61 return LOWORD(wParam); 62 } 63 }; 64 65 class ListBoxParam 66 { 67 const uint wParam; 68 69 public: 70 ListBoxParam(uint w)71 explicit ListBoxParam(uint w) 72 : wParam(w) {} 73 SelectionChanged() const74 bool SelectionChanged() const 75 { 76 return HIWORD(wParam) == LBN_SELCHANGE; 77 } 78 GetId() const79 uint GetId() const 80 { 81 return LOWORD(wParam); 82 } 83 }; 84 85 class ComboBoxParam 86 { 87 const uint wParam; 88 89 public: 90 ComboBoxParam(uint w)91 explicit ComboBoxParam(uint w) 92 : wParam(w) {} 93 SelectionChanged() const94 bool SelectionChanged() const 95 { 96 return HIWORD(wParam) == CBN_SELCHANGE; 97 } 98 DropingDown() const99 bool DropingDown() const 100 { 101 return HIWORD(wParam) == CBN_DROPDOWN; 102 } 103 GetId() const104 uint GetId() const 105 { 106 return LOWORD(wParam); 107 } 108 }; 109 110 class EditParam 111 { 112 const uint wParam; 113 114 public: 115 EditParam(uint w)116 explicit EditParam(uint w) 117 : wParam(w) {} 118 SetFocus() const119 bool SetFocus() const 120 { 121 return HIWORD(wParam) == EN_SETFOCUS; 122 } 123 KillFocus() const124 bool KillFocus() const 125 { 126 return HIWORD(wParam) == EN_KILLFOCUS; 127 } 128 Changed() const129 bool Changed() const 130 { 131 return HIWORD(wParam) == EN_CHANGE; 132 } 133 GetId() const134 uint GetId() const 135 { 136 return LOWORD(wParam); 137 } 138 }; 139 140 class SliderParam 141 { 142 const Param& param; 143 144 public: 145 SliderParam(const Param & p)146 explicit SliderParam(const Param& p) 147 : param(p) {} 148 149 uint Scroll() const; 150 GetId() const151 uint GetId() const 152 { 153 return ::GetDlgCtrlID( reinterpret_cast<HWND>(param.lParam) ); 154 } 155 Released() const156 bool Released() const 157 { 158 return LOWORD(param.wParam) == SB_ENDSCROLL; 159 } 160 }; 161 162 class CursorParam 163 { 164 const Param& param; 165 166 public: 167 CursorParam(const Param & p)168 explicit CursorParam(const Param& p) 169 : param(p) {} 170 Inside(uint id) const171 bool Inside(uint id) const 172 { 173 return reinterpret_cast<HWND>(param.wParam) == ::GetDlgItem( param.hWnd, id ); 174 } 175 }; 176 177 class ActivatorParam 178 { 179 const Param& param; 180 181 public: 182 ActivatorParam(const Param & p)183 explicit ActivatorParam(const Param& p) 184 : param(p) {} 185 Leaving() const186 bool Leaving() const 187 { 188 return LOWORD(param.wParam) == WA_INACTIVE; 189 } 190 Entering() const191 bool Entering() const 192 { 193 return !Leaving(); 194 } 195 InsideApplication() const196 bool InsideApplication() const 197 { 198 return param.lParam && ::IsChild( param.hWnd, reinterpret_cast<HWND>(param.lParam) ); 199 } 200 OutsideApplication() const201 bool OutsideApplication() const 202 { 203 return !InsideApplication(); 204 } 205 Minimized() const206 bool Minimized() const 207 { 208 return HIWORD(param.wParam); 209 } 210 }; 211 ButtonNestopia::Window::Param212 ButtonParam Button() const { return ButtonParam ( wParam ); } ListBoxNestopia::Window::Param213 ListBoxParam ListBox() const { return ListBoxParam ( wParam ); } ComboBoxNestopia::Window::Param214 ComboBoxParam ComboBox() const { return ComboBoxParam ( wParam ); } EditNestopia::Window::Param215 EditParam Edit() const { return EditParam ( wParam ); } SliderNestopia::Window::Param216 SliderParam Slider() const { return SliderParam ( *this ); } CursorNestopia::Window::Param217 CursorParam Cursor() const { return CursorParam ( *this ); } ActivatorNestopia::Window::Param218 ActivatorParam Activator() const { return ActivatorParam ( *this ); } 219 }; 220 } 221 } 222 223 #endif 224