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 STATE_VIEW_H 10 #define STATE_VIEW_H 11 12 #include <View.h> 13 14 #include "ViewState.h" 15 16 class BMessageFilter; 17 class Command; 18 class CommandStack; 19 class RWLocker; 20 21 class StateView : public BView { 22 public: 23 StateView(BRect frame, const char* name, 24 uint32 resizingMode, uint32 flags); 25 virtual ~StateView(); 26 27 // BView interface 28 virtual void AttachedToWindow(); 29 virtual void DetachedFromWindow(); 30 virtual void Draw(BRect updateRect); 31 virtual void MessageReceived(BMessage* message); 32 33 virtual void MouseDown(BPoint where); 34 virtual void MouseMoved(BPoint where, uint32 transit, 35 const BMessage* dragMessage); 36 virtual void MouseUp(BPoint where); 37 38 virtual void KeyDown(const char* bytes, int32 numBytes); 39 virtual void KeyUp(const char* bytes, int32 numBytes); 40 41 // StateView interface 42 void SetState(ViewState* state); 43 44 void Draw(BView* into, BRect updateRect); 45 46 virtual bool MouseWheelChanged(float x, float y); 47 48 bool HandleKeyDown(uint32 key, uint32 modifiers); 49 bool HandleKeyUp(uint32 key, uint32 modifiers); 50 51 const mouse_info* MouseInfo() const 52 { return &fMouseInfo; } 53 54 virtual ViewState* StateForDragMessage(const BMessage* message); 55 56 void SetLocker(RWLocker* locker); 57 RWLocker* Locker() const 58 { return fLocker; } 59 60 void SetCommandStack(::CommandStack* stack); 61 ::CommandStack* CommandStack() const 62 { return fCommandStack; } 63 64 void SetUpdateTarget(BHandler* target, 65 uint32 command); 66 67 void SetCatchAllEvents(bool catchAll); 68 69 status_t Perform(Command* command); 70 71 protected: 72 virtual bool _HandleKeyDown(uint32 key, uint32 modifiers); 73 virtual bool _HandleKeyUp(uint32 key, uint32 modifiers); 74 75 void _InstallEventFilter(); 76 void _RemoveEventFilter(); 77 78 void _TriggerUpdate(); 79 80 ViewState* fCurrentState; 81 ViewState* fDropAnticipatingState; 82 // the drop anticipation state is some 83 // kind of "temporary" state that is 84 // used on top of the current state (it 85 // doesn't replace it) 86 mouse_info fMouseInfo; 87 88 ::CommandStack* fCommandStack; 89 RWLocker* fLocker; 90 91 BMessageFilter* fEventFilter; 92 bool fCatchAllEvents; 93 94 BHandler* fUpdateTarget; 95 uint32 fUpdateCommand; 96 }; 97 98 #endif // STATE_VIEW_H 99