xref: /haiku/src/kits/tracker/TitleView.h (revision fef6144999c2fa611f59ee6ffe6dd7999501385c)
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 
35 #ifndef	_TITLE_VIEW_H
36 #define _TITLE_VIEW_H
37 
38 #include <Cursor.h>
39 #include <DataIO.h>
40 #include <View.h>
41 
42 #include "ObjectList.h"
43 
44 namespace BPrivate {
45 
46 class BPoseView;
47 class BColumn;
48 class BColumnTitle;
49 class OffscreenBitmap;
50 
51 const int32 kTitleViewHeight = 16;
52 const int32 kEdgeSize = 6;
53 const int32 kTitleColumnLeftExtraMargin = 10;
54 const int32 kTitleColumnRightExtraMargin = 5;
55 const int32 kTitleColumnExtraMargin = kTitleColumnLeftExtraMargin
56 	+ kTitleColumnRightExtraMargin;
57 const int32 kMinColumnWidth = 20;
58 const int32 kRemoveTitleMargin = 10;
59 const int32 kColumnStart = 40;
60 
61 class BTitleView : public BView {
62 public:
63 	BTitleView(BRect, BPoseView *);
64 	virtual ~BTitleView();
65 
66 	virtual	void MouseDown(BPoint);
67 	virtual	void Draw(BRect);
68 
69 	void Draw(BRect, bool useOffscreen = false,
70 		bool updateOnly = true,
71 		const BColumnTitle *pressedColumn = 0,
72 		void (*trackRectBlitter)(BView *, BRect) = 0,
73 		BRect passThru = BRect(0, 0, 0, 0));
74 
75 	void AddTitle(BColumn *, const BColumn *after = 0);
76 	void RemoveTitle(BColumn *);
77 	void Reset();
78 
79 	BPoseView *PoseView() const;
80 
81 protected:
82 	void MouseMoved(BPoint, uint32, const BMessage *);
83 
84 private:
85 	BColumnTitle *FindColumnTitle(BPoint) const;
86 	BColumnTitle *InColumnResizeArea(BPoint) const;
87 	BColumnTitle *FindColumnTitle(const BColumn *) const;
88 
89 	BPoseView *fPoseView;
90 	BObjectList<BColumnTitle> fTitleList;
91 	BCursor fHorizontalResizeCursor;
92 
93 	BColumnTitle *fPreviouslyClickedColumnTitle;
94 	bigtime_t fPreviousLeftClickTime;
95 
96 	static OffscreenBitmap *offscreen;
97 
98 	typedef BView _inherited;
99 
100 	friend class ColumnTrackState;
101 	friend class ColumnDragState;
102 };
103 
104 class BColumnTitle {
105 public:
106 	BColumnTitle(BTitleView *, BColumn *);
107 	virtual ~BColumnTitle() {}
108 
109 	virtual	void Draw(BView *, bool pressed = false);
110 
111 
112 	BColumn *Column() const;
113 	BRect Bounds() const;
114 
115 	bool InColumnResizeArea(BPoint) const;
116 
117 private:
118 	BColumn *fColumn;
119 	BTitleView *fParent;
120 
121 	friend class ColumnResizeState;
122 };
123 
124 // Utility classes to handle dragging state
125 class ColumnTrackState {
126 public:
127 	ColumnTrackState(BTitleView *, BColumnTitle *, BPoint where);
128 	virtual ~ColumnTrackState() {}
129 
130 	void MouseMoved(BPoint where, uint32 buttons);
131 
132 	virtual void Moved(BPoint where, uint32 buttons) = 0;
133 	virtual void Clicked(BPoint where, uint32 buttons) = 0;
134 	virtual void Pressing(BPoint where, uint32 buttons) = 0;
135 		// called if mouse held down too long for click but hasn't
136 		// been moved a bit
137 	virtual void Done(BPoint where) = 0;
138 
139 protected:
140 	virtual bool ValueChanged(BPoint where) = 0;
141 
142 	BTitleView *fTitleView;
143 	BColumnTitle *fTitle;
144 	BPoint fLastPos;
145 };
146 
147 class ColumnResizeState : public ColumnTrackState {
148 public:
149 	ColumnResizeState(BTitleView *, BColumnTitle *, BPoint);
150 
151 protected:
152 	virtual void Moved(BPoint, uint32 buttons);
153 	virtual void Done(BPoint);
154 	virtual void Clicked(BPoint, uint32 buttons);
155 	virtual void Pressing(BPoint, uint32) {}
156 	virtual bool ValueChanged(BPoint);
157 
158 	void DrawLine();
159 	void UndrawLine();
160 
161 private:
162 	float fLastLineDrawPos;
163 	float fInitialTrackOffset;
164 
165 	typedef ColumnTrackState _inherited;
166 };
167 
168 class ColumnDragState : public ColumnTrackState {
169 public:
170 	ColumnDragState(BTitleView *, BColumnTitle *, BPoint where);
171 
172 protected:
173 	virtual void Moved(BPoint, uint32 buttons);
174 	virtual void Done(BPoint);
175 	virtual void Clicked(BPoint, uint32 buttons);
176 	virtual void Pressing(BPoint, uint32 buttons);
177 	virtual bool ValueChanged(BPoint);
178 
179 	void DrawOutline(float);
180 	void UndrawOutline();
181 	void DrawPressNoOutline();
182 
183 private:
184 	float fInitialMouseTrackOffset;
185 	bool fTrackingRemovedColumn;
186 	BMallocIO fColumnArchive;
187 
188 	typedef ColumnTrackState _inherited;
189 };
190 
191 inline BColumn *
192 BColumnTitle::Column() const
193 {
194 	return fColumn;
195 }
196 
197 inline BPoseView *
198 BTitleView::PoseView() const
199 {
200 	return fPoseView;
201 }
202 
203 
204 } // namespace BPrivate
205 
206 using namespace BPrivate;
207 
208 #endif
209