vfs: check userland buffers before reading them.
[haiku.git] / src / apps / cortex / ValControl / ValControlSegment.h
blob8dae0d3b38227164699cb976e7df3f3864718f93
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // ValControlSegment.h
33 // +++++ cortex integration 23aug99:
34 // - allow adjustment of dragScaleFactor
35 //
36 // e.moon 17jan99
38 // ABSTRACT CLASS: ValControlSegment
39 // Represents a single manipulable (manipulatable?) segment of
40 // a ValControl interface element.
42 // CLASS: ValControlDigitSegment
43 // Extends ValControlSegment to provide a single or multi-digit
44 // numeric segment.
46 // CLASS: ValControlStringSegment
47 // Extends ValControlSegment to provide a string-selection
48 // segment. [+++++ driven by BMenu?]
49 #ifndef VAL_CONTROL_SEGMENT_H
50 #define VAL_CONTROL_SEGMENT_H
53 #include <View.h>
55 // possibly 'fed' by a BMenu?
56 class BMenu;
58 #include "cortex_defs.h"
59 __BEGIN_CORTEX_NAMESPACE
61 // forward declarations
62 class ValControl;
63 class ValCtrlLayoutEntry;
65 // ---------------------------------------------------------------- //
66 // +++++ base 'manipulatable segment' class
68 // Might have some functionality:
69 // - underline (overridable)
70 // - chaining: segments need to inform segments to their left
71 // when they 'roll around', using the M_INCREMENT and
72 // M_DECREMENT messages.
74 class ValControlSegment : public BView {
75 public:
76 typedef BView _Inherited;
78 friend class ValControl;
80 public:
82 enum underline_style {
83 NO_UNDERLINE,
84 DOTTED_UNDERLINE,
85 SOLID_UNDERLINE
88 // mouse-tracking
89 enum track_flags {
90 TRACK_HORIZONTAL = 1,
91 TRACK_VERTICAL = 2
94 protected: // pure virtuals
95 // fetch layout entry (called by ValControl)
96 virtual ValCtrlLayoutEntry makeLayoutEntry() = 0;
98 public: // hooks
100 // * mouse-tracking callbacks
102 // do any font-related layout work
103 virtual void fontChanged(const BFont* font) {}
105 // return 'unused pixels' (if value updates are triggered
106 // at less than one per pixel)
107 virtual float handleDragUpdate(float distance) { return 0; }
109 virtual void mouseReleased() {}
111 // underline size (tweak if you must)
112 // +++++ 18sep99: 'ewww.'
113 virtual void sizeUnderline(float* outLeft, float* outRight);
115 public:
116 virtual ~ValControlSegment();
118 protected: // ctor/internal operations
119 ValControlSegment(underline_style underlineStyle);
121 // get parent
122 ValControl* parent() const;
124 // init mouse tracking: must be called from MouseDown()
125 void trackMouse(BPoint point, track_flags flags);
127 void setTracking(bool tracking);
128 bool isTracking() const;
130 // fetch pixel:unit ratio for dragging
131 double dragScaleFactor() const;
133 public:// BView impl.
134 // calls sizeUnderline()
135 virtual void AttachedToWindow();
137 virtual void Draw(BRect updateRect);
139 // calls sizeUnderline() after bounds changed
140 virtual void FrameResized(float width, float height);
142 // calls trackMouse(TRACK_VERTICAL) if left button down
143 virtual void MouseDown(BPoint point);
145 // feeds trackUpdate()
146 virtual void MouseMoved(BPoint point, uint32 transit,
147 const BMessage* dragMessage);
149 // triggers mouseReleased()
150 virtual void MouseUp(BPoint point);
152 public:
153 virtual void MessageReceived(BMessage* message); //nyi
155 public:
156 ValControlSegment(BMessage* archive);
157 virtual status_t Archive(BMessage* archive, bool deep = true) const;
159 private:
160 void _Init();
162 // left segment (ValControl)
163 // ValControlSegment* m_pLeft;
165 // mouse-tracking machinery
166 track_flags fTrackFlags;
167 bool fTracking;
168 BPoint fPrevPoint;
169 double fDragScaleFactor;
171 bigtime_t fLastClickTime;
173 // look'n'feel parameters
174 underline_style fUnderlineStyle;
175 float fXUnderlineLeft;
176 float fXUnderlineRight;
178 // constants
179 static const double fDefDragScaleFactor;
182 __END_CORTEX_NAMESPACE
183 #endif // VAL_CONTROL_SEGMENT_H