1 // ValControlSegment.h 2 // +++++ cortex integration 23aug99: 3 // - allow adjustment of dragScaleFactor 4 // 5 // e.moon 17jan99 6 // 7 // ABSTRACT CLASS: ValControlSegment 8 // Represents a single manipulable (manipulatable?) segment of 9 // a ValControl interface element. 10 // 11 // CLASS: ValControlDigitSegment 12 // Extends ValControlSegment to provide a single or multi-digit 13 // numeric segment. 14 // 15 // CLASS: ValControlStringSegment 16 // Extends ValControlSegment to provide a string-selection 17 // segment. [+++++ driven by BMenu?] 18 #ifndef VAL_CONTROL_SEGMENT_H 19 #define VAL_CONTROL_SEGMENT_H 20 21 22 #include <View.h> 23 24 // possibly 'fed' by a BMenu? 25 class BMenu; 26 27 #include "cortex_defs.h" 28 __BEGIN_CORTEX_NAMESPACE 29 30 // forward declarations 31 class ValControl; 32 class ValCtrlLayoutEntry; 33 34 // ---------------------------------------------------------------- // 35 // +++++ base 'manipulatable segment' class 36 37 // Might have some functionality: 38 // - underline (overridable) 39 // - chaining: segments need to inform segments to their left 40 // when they 'roll around', using the M_INCREMENT and 41 // M_DECREMENT messages. 42 43 class ValControlSegment : public BView { 44 public: 45 typedef BView _Inherited; 46 47 friend class ValControl; 48 49 public: 50 51 enum underline_style { 52 NO_UNDERLINE, 53 DOTTED_UNDERLINE, 54 SOLID_UNDERLINE 55 }; 56 57 // mouse-tracking 58 enum track_flags { 59 TRACK_HORIZONTAL = 1, 60 TRACK_VERTICAL = 2 61 }; 62 63 protected: // pure virtuals 64 // fetch layout entry (called by ValControl) 65 virtual ValCtrlLayoutEntry makeLayoutEntry() = 0; 66 67 public: // hooks 68 69 // * mouse-tracking callbacks 70 71 // do any font-related layout work 72 virtual void fontChanged(const BFont* font) {} 73 74 // return 'unused pixels' (if value updates are triggered 75 // at less than one per pixel) 76 virtual float handleDragUpdate(float distance) { return 0; } 77 78 virtual void mouseReleased() {} 79 80 // underline size (tweak if you must) 81 // +++++ 18sep99: 'ewww.' 82 virtual void sizeUnderline(float* outLeft, float* outRight); 83 84 public: 85 virtual ~ValControlSegment(); 86 87 protected: // ctor/internal operations 88 ValControlSegment(underline_style underlineStyle); 89 90 // get parent 91 ValControl* parent() const; 92 93 // init mouse tracking: must be called from MouseDown() 94 void trackMouse(BPoint point, track_flags flags); 95 96 void setTracking(bool tracking); 97 bool isTracking() const; 98 99 // fetch pixel:unit ratio for dragging 100 double dragScaleFactor() const; 101 102 public:// BView impl. 103 // calls sizeUnderline() 104 virtual void AttachedToWindow(); 105 106 virtual void Draw(BRect updateRect); 107 108 // calls sizeUnderline() after bounds changed 109 virtual void FrameResized(float width, float height); 110 111 // calls trackMouse(TRACK_VERTICAL) if left button down 112 virtual void MouseDown(BPoint point); 113 114 // feeds trackUpdate() 115 virtual void MouseMoved(BPoint point, uint32 transit, 116 const BMessage* dragMessage); 117 118 // triggers mouseReleased() 119 virtual void MouseUp(BPoint point); 120 121 public: 122 virtual void MessageReceived(BMessage* message); //nyi 123 124 public: 125 ValControlSegment(BMessage* archive); 126 virtual status_t Archive(BMessage* archive, bool deep = true) const; 127 128 private: 129 void _Init(); 130 131 // left segment (ValControl) 132 // ValControlSegment* m_pLeft; 133 134 // mouse-tracking machinery 135 track_flags fTrackFlags; 136 bool fTracking; 137 BPoint fPrevPoint; 138 double fDragScaleFactor; 139 140 bigtime_t fLastClickTime; 141 142 // look'n'feel parameters 143 underline_style fUnderlineStyle; 144 float fXUnderlineLeft; 145 float fXUnderlineRight; 146 147 // constants 148 static const double fDefDragScaleFactor; 149 }; 150 151 __END_CORTEX_NAMESPACE 152 #endif // VAL_CONTROL_SEGMENT_H 153