1 /* 2 * Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef WIDGET_LAYOUT_TEST_ABSTRACT_BUTTON_H 6 #define WIDGET_LAYOUT_TEST_ABSTRACT_BUTTON_H 7 8 9 #include <Invoker.h> 10 #include <List.h> 11 12 #include "View.h" 13 14 15 // button behavior policy 16 enum button_policy { 17 BUTTON_POLICY_TOGGLE_ON_RELEASE, // check box 18 BUTTON_POLICY_SELECT_ON_RELEASE, // radio button 19 BUTTON_POLICY_INVOKE_ON_RELEASE // button 20 }; 21 22 23 // AbstractButton 24 class AbstractButton : public View, public BInvoker { 25 public: 26 AbstractButton(button_policy policy, 27 BMessage* message = NULL, 28 BMessenger target = BMessenger()); 29 30 void SetPolicy(button_policy policy); 31 button_policy Policy() const; 32 33 void SetSelected(bool selected); 34 bool IsSelected() const; 35 36 virtual void MouseDown(BPoint where, uint32 buttons, 37 int32 modifiers); 38 virtual void MouseUp(BPoint where, uint32 buttons, 39 int32 modifiers); 40 virtual void MouseMoved(BPoint where, uint32 buttons, 41 int32 modifiers); 42 43 public: 44 class Listener; 45 46 void AddListener(Listener* listener); 47 void RemoveListener(Listener* listener); 48 49 protected: 50 bool IsPressed() const; 51 52 private: 53 void _PressedUpdate(BPoint where); 54 void _NotifyListeners(); 55 56 private: 57 button_policy fPolicy; 58 bool fSelected; 59 bool fPressed; 60 bool fPressedInBounds; 61 BList fListeners; 62 }; 63 64 65 // synchronous listener interface 66 class AbstractButton::Listener { 67 public: 68 virtual ~Listener(); 69 70 virtual void SelectionChanged(AbstractButton* button) = 0; 71 }; 72 73 74 #endif // WIDGET_LAYOUT_TEST_ABSTRACT_BUTTON_H 75