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 void FilterMouse(BPoint* where) const; 55 56 virtual ViewState* StateForDragMessage(const BMessage* message); 57 58 void SetLocker(RWLocker* locker); 59 RWLocker* Locker() const 60 { return fLocker; } 61 62 void SetCommandStack(::CommandStack* stack); 63 ::CommandStack* CommandStack() const 64 { return fCommandStack; } 65 66 void SetUpdateTarget(BHandler* target, 67 uint32 command); 68 69 void SetCatchAllEvents(bool catchAll); 70 71 status_t Perform(Command* command); 72 73 protected: 74 virtual bool _HandleKeyDown(uint32 key, uint32 modifiers); 75 virtual bool _HandleKeyUp(uint32 key, uint32 modifiers); 76 77 void _InstallEventFilter(); 78 void _RemoveEventFilter(); 79 80 void _TriggerUpdate(); 81 82 ViewState* fCurrentState; 83 ViewState* fDropAnticipatingState; 84 // the drop anticipation state is some 85 // kind of "temporary" state that is 86 // used on top of the current state (it 87 // doesn't replace it) 88 mouse_info fMouseInfo; 89 90 ::CommandStack* fCommandStack; 91 RWLocker* fLocker; 92 93 BMessageFilter* fEventFilter; 94 bool fCatchAllEvents; 95 96 BHandler* fUpdateTarget; 97 uint32 fUpdateCommand; 98 }; 99 100 #endif // STATE_VIEW_H 101