xref: /haiku/src/kits/tracker/TitleView.h (revision ab4411e89a079bc0a40d901995f3418d998c51b3)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 #ifndef _TITLE_VIEW_H
35 #define _TITLE_VIEW_H
36 
37 
38 #include <Cursor.h>
39 #include <DataIO.h>
40 #include <ObjectList.h>
41 #include <View.h>
42 
43 
44 namespace BPrivate {
45 
46 
47 class BPoseView;
48 class BColumn;
49 class BColumnTitle;
50 class ColumnTrackState;
51 class OffscreenBitmap;
52 
53 const int32 kTitleViewHeight = 16;
54 const int32 kEdgeSize = 6;
55 const int32 kTitleColumnLeftExtraMargin = 11;
56 const int32 kTitleColumnRightExtraMargin = 5;
57 const int32 kTitleColumnExtraMargin = kTitleColumnLeftExtraMargin
58 	+ kTitleColumnRightExtraMargin;
59 const int32 kMinColumnWidth = 20;
60 const int32 kRemoveTitleMargin = 10;
61 const int32 kColumnStart = 40;
62 
63 
64 class BTitleView : public BView {
65 public:
66 	BTitleView(BRect, BPoseView*);
67 	virtual ~BTitleView();
68 
69 	virtual	void MouseDown(BPoint where);
70 	virtual	void MouseUp(BPoint where);
71 	virtual	void Draw(BRect updateRect);
72 
73 	void Draw(BRect, bool useOffscreen = false,
74 		bool updateOnly = true,
75 		const BColumnTitle* pressedColumn = 0,
76 		void (*trackRectBlitter)(BView*, BRect) = 0,
77 		BRect passThru = BRect(0, 0, 0, 0));
78 
79 	void AddTitle(BColumn*, const BColumn* after = 0);
80 	void RemoveTitle(BColumn*);
81 	void Reset();
82 
83 	BPoseView* PoseView() const;
84 
85 protected:
86 	void MouseMoved(BPoint, uint32, const BMessage*);
87 
88 private:
89 	BColumnTitle* FindColumnTitle(BPoint) const;
90 	BColumnTitle* InColumnResizeArea(BPoint) const;
91 	BColumnTitle* FindColumnTitle(const BColumn*) const;
92 
93 	BPoseView* fPoseView;
94 	BObjectList<BColumnTitle> fTitleList;
95 	BCursor fHorizontalResizeCursor;
96 
97 	BColumnTitle* fPreviouslyClickedColumnTitle;
98 	bigtime_t fPreviousLeftClickTime;
99 	ColumnTrackState* fTrackingState;
100 
101 	static OffscreenBitmap* sOffscreen;
102 
103 	typedef BView _inherited;
104 
105 	friend class ColumnTrackState;
106 	friend class ColumnDragState;
107 };
108 
109 
110 class BColumnTitle {
111 public:
112 	BColumnTitle(BTitleView*, BColumn*);
113 	virtual ~BColumnTitle() {}
114 
115 	virtual void Draw(BView*, bool pressed = false);
116 
117 	BColumn* Column() const;
118 	BRect Bounds() const;
119 
120 	bool InColumnResizeArea(BPoint) const;
121 
122 private:
123 	BColumn* fColumn;
124 	BTitleView* fParent;
125 
126 	friend class ColumnResizeState;
127 };
128 
129 
130 // Utility classes to handle dragging state
131 class ColumnTrackState {
132 public:
133 	ColumnTrackState(BTitleView* titleView, BColumnTitle* columnTitle,
134 		BPoint where, bigtime_t pastClickTime);
135 	virtual ~ColumnTrackState() {}
136 
137 	void MouseMoved(BPoint where, uint32 buttons);
138 	void MouseUp(BPoint where);
139 
140 protected:
141 	virtual void Moved(BPoint where, uint32 buttons) = 0;
142 	virtual void Clicked(BPoint where) = 0;
143 	virtual void Done(BPoint where) = 0;
144 	virtual bool ValueChanged(BPoint where) = 0;
145 
146 	BTitleView*		fTitleView;
147 	BColumnTitle*	fTitle;
148 	BPoint			fFirstClickPoint;
149 	bigtime_t		fPastClickTime;
150 	bool			fHasMoved;
151 };
152 
153 
154 class ColumnResizeState : public ColumnTrackState {
155 public:
156 	ColumnResizeState(BTitleView* titleView, BColumnTitle* columnTitle,
157 		BPoint where, bigtime_t pastClickTime);
158 
159 protected:
160 	virtual void Moved(BPoint where, uint32 buttons);
161 	virtual void Done(BPoint where);
162 	virtual void Clicked(BPoint where);
163 	virtual bool ValueChanged(BPoint);
164 
165 	void DrawLine();
166 	void UndrawLine();
167 
168 private:
169 	float fLastLineDrawPos;
170 	float fInitialTrackOffset;
171 
172 	typedef ColumnTrackState _inherited;
173 };
174 
175 
176 class ColumnDragState : public ColumnTrackState {
177 public:
178 	ColumnDragState(BTitleView* titleView, BColumnTitle* columnTitle,
179 		BPoint where, bigtime_t pastClickTime);
180 
181 protected:
182 	virtual void Moved(BPoint where, uint32 buttons);
183 	virtual void Done(BPoint where);
184 	virtual void Clicked(BPoint where);
185 	virtual bool ValueChanged(BPoint);
186 
187 	void DrawOutline(float);
188 	void UndrawOutline();
189 	void DrawPressNoOutline();
190 
191 private:
192 	float fInitialMouseTrackOffset;
193 	bool fTrackingRemovedColumn;
194 	BMallocIO fColumnArchive;
195 
196 	typedef ColumnTrackState _inherited;
197 };
198 
199 
200 inline BColumn*
201 BColumnTitle::Column() const
202 {
203 	return fColumn;
204 }
205 
206 
207 inline BPoseView*
208 BTitleView::PoseView() const
209 {
210 	return fPoseView;
211 }
212 
213 
214 } // namespace BPrivate
215 
216 using namespace BPrivate;
217 
218 
219 #endif	// _TITLE_VIEW_H
220