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