1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #ifndef VIEW_STATE_H 10 #define VIEW_STATE_H 11 12 #include <View.h> 13 14 class BMessage; 15 class Command; 16 class StateView; 17 18 struct mouse_info { 19 mouse_info(); 20 21 uint32 buttons; 22 BPoint position; 23 uint32 transit; 24 uint32 modifiers; 25 }; 26 27 class ViewState { 28 public: 29 ViewState(StateView* view); 30 ViewState(const ViewState& other); 31 virtual ~ViewState(); 32 33 // ViewState interface 34 virtual void Init(); 35 virtual void Cleanup(); 36 37 virtual void Draw(BView* into, BRect updateRect); 38 virtual bool MessageReceived(BMessage* message, 39 Command** _command); 40 41 // mouse tracking 42 virtual void MouseDown(BPoint where, 43 uint32 buttons, 44 uint32 clicks); 45 46 virtual void MouseMoved(BPoint where, 47 uint32 transit, 48 const BMessage* dragMessage); 49 virtual Command* MouseUp(); 50 51 // modifiers 52 virtual void ModifiersChanged(uint32 modifiers); 53 54 55 // TODO: mouse wheel 56 virtual bool HandleKeyDown(uint32 key, uint32 modifiers, 57 Command** _command); 58 virtual bool HandleKeyUp(uint32 key, uint32 modifiers, 59 Command** _command); 60 61 62 inline uint32 PressedMouseButtons() const 63 { return fMouseInfo->buttons; } 64 65 inline bool IsFirstButtonDown() const 66 { return fMouseInfo->buttons & B_PRIMARY_MOUSE_BUTTON; } 67 inline bool IsSecondButtonDown() const 68 { return fMouseInfo->buttons & B_SECONDARY_MOUSE_BUTTON; } 69 inline bool IsThirdButtonDown() const 70 { return fMouseInfo->buttons & B_TERTIARY_MOUSE_BUTTON; } 71 72 inline BPoint MousePos() const 73 { return fMouseInfo->position; } 74 75 inline uint32 Modifiers() const 76 { return fMouseInfo->modifiers; } 77 78 protected: 79 StateView* fView; 80 81 // NOTE: the intention of using a pointer 82 // to a mouse_info struct is that all 83 // ViewStates belonging to the same StateView 84 // should have the same pointer, so that 85 // they will all be up to date with the same info 86 const mouse_info* fMouseInfo; 87 }; 88 89 #endif // VIEW_STATE_H 90