1 /* 2 * Copyright 2006-2007, 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 virtual status_t Perform(perform_code code, void* data); 42 // Avoids warning about hiding BView::Perform(). 43 44 // StateView interface 45 void SetState(ViewState* state); 46 void UpdateStateCursor(); 47 48 void Draw(BView* into, BRect updateRect); 49 50 virtual bool MouseWheelChanged(BPoint where, 51 float x, float y); 52 53 bool HandleKeyDown(uint32 key, uint32 modifiers); 54 bool HandleKeyUp(uint32 key, uint32 modifiers); 55 56 const mouse_info* MouseInfo() const 57 { return &fMouseInfo; } 58 59 virtual void FilterMouse(BPoint* where) const; 60 61 virtual ViewState* StateForDragMessage(const BMessage* message); 62 63 void SetLocker(RWLocker* locker); 64 RWLocker* Locker() const 65 { return fLocker; } 66 67 void SetCommandStack(::CommandStack* stack); 68 ::CommandStack* CommandStack() const 69 { return fCommandStack; } 70 71 void SetUpdateTarget(BHandler* target, 72 uint32 command); 73 74 void SetCatchAllEvents(bool catchAll); 75 76 status_t Perform(Command* command); 77 78 protected: 79 virtual bool _HandleKeyDown(uint32 key, uint32 modifiers); 80 virtual bool _HandleKeyUp(uint32 key, uint32 modifiers); 81 82 void _InstallEventFilter(); 83 void _RemoveEventFilter(); 84 85 void _TriggerUpdate(); 86 87 ViewState* fCurrentState; 88 ViewState* fDropAnticipatingState; 89 // the drop anticipation state is some 90 // kind of "temporary" state that is 91 // used on top of the current state (it 92 // doesn't replace it) 93 mouse_info fMouseInfo; 94 95 ::CommandStack* fCommandStack; 96 RWLocker* fLocker; 97 98 BMessageFilter* fEventFilter; 99 bool fCatchAllEvents; 100 101 BHandler* fUpdateTarget; 102 uint32 fUpdateCommand; 103 }; 104 105 #endif // STATE_VIEW_H 106