xref: /haiku/src/kits/tracker/TitleView.h (revision 8fdd2629ebdaba038f02d95bc4b0886fac4ccef4)
102be5353SAxel Dörfler /*
202be5353SAxel Dörfler Open Tracker License
302be5353SAxel Dörfler 
402be5353SAxel Dörfler Terms and Conditions
502be5353SAxel Dörfler 
602be5353SAxel Dörfler Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler 
802be5353SAxel Dörfler Permission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörfler this software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörfler the Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfler use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörfler of the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörfler so, subject to the following conditions:
1402be5353SAxel Dörfler 
1502be5353SAxel Dörfler The above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörfler and shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler 
1802be5353SAxel Dörfler THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1902be5353SAxel Dörfler IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2002be5353SAxel Dörfler FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2102be5353SAxel Dörfler BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2202be5353SAxel Dörfler AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2302be5353SAxel Dörfler WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2402be5353SAxel Dörfler 
2502be5353SAxel Dörfler Except as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörfler used in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörfler this Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler 
2902be5353SAxel Dörfler Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörfler of Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörfler names are registered trademarks or trademarks of their respective holders.
3202be5353SAxel Dörfler All rights reserved.
3302be5353SAxel Dörfler */
3402be5353SAxel Dörfler #ifndef _TITLE_VIEW_H
3502be5353SAxel Dörfler #define _TITLE_VIEW_H
3602be5353SAxel Dörfler 
37b05aa8b5SJohn Scipione 
3802be5353SAxel Dörfler #include <Cursor.h>
3902be5353SAxel Dörfler #include <DataIO.h>
406d4e243aSJohn Scipione #include <ObjectList.h>
4102be5353SAxel Dörfler #include <View.h>
4202be5353SAxel Dörfler 
43b05aa8b5SJohn Scipione 
4402be5353SAxel Dörfler namespace BPrivate {
4502be5353SAxel Dörfler 
46b05aa8b5SJohn Scipione 
4702be5353SAxel Dörfler class BPoseView;
4802be5353SAxel Dörfler class BColumn;
4902be5353SAxel Dörfler class BColumnTitle;
5027eab79bSAxel Dörfler class ColumnTrackState;
5102be5353SAxel Dörfler class OffscreenBitmap;
5202be5353SAxel Dörfler 
5302be5353SAxel Dörfler const int32 kEdgeSize = 6;
542f86ba45SStephan Aßmus const int32 kTitleColumnLeftExtraMargin = 11;
5502be5353SAxel Dörfler const int32 kTitleColumnRightExtraMargin = 5;
5602be5353SAxel Dörfler const int32 kTitleColumnExtraMargin = kTitleColumnLeftExtraMargin
5702be5353SAxel Dörfler 	+ kTitleColumnRightExtraMargin;
5802be5353SAxel Dörfler const int32 kMinColumnWidth = 20;
5902be5353SAxel Dörfler const int32 kRemoveTitleMargin = 10;
6002be5353SAxel Dörfler 
6127eab79bSAxel Dörfler 
6202be5353SAxel Dörfler class BTitleView : public BView {
6302be5353SAxel Dörfler public:
64e7803cf1SAugustin Cavalier 	BTitleView(BPoseView*);
6502be5353SAxel Dörfler 	virtual ~BTitleView();
6602be5353SAxel Dörfler 
6727eab79bSAxel Dörfler 	virtual	void MouseDown(BPoint where);
6827eab79bSAxel Dörfler 	virtual	void MouseUp(BPoint where);
6927eab79bSAxel Dörfler 	virtual	void Draw(BRect updateRect);
7002be5353SAxel Dörfler 
71*d8b517b5SAxel Dörfler 	virtual	BSize				MinSize();
72*d8b517b5SAxel Dörfler 	virtual	BSize				MaxSize();
73*d8b517b5SAxel Dörfler 
7402be5353SAxel Dörfler 	void Draw(BRect, bool useOffscreen = false,
7502be5353SAxel Dörfler 		bool updateOnly = true,
7602be5353SAxel Dörfler 		const BColumnTitle* pressedColumn = 0,
7702be5353SAxel Dörfler 		void (*trackRectBlitter)(BView*, BRect) = 0,
7802be5353SAxel Dörfler 		BRect passThru = BRect(0, 0, 0, 0));
7902be5353SAxel Dörfler 
8002be5353SAxel Dörfler 	void AddTitle(BColumn*, const BColumn* after = 0);
8102be5353SAxel Dörfler 	void RemoveTitle(BColumn*);
8202be5353SAxel Dörfler 	void Reset();
8302be5353SAxel Dörfler 
8402be5353SAxel Dörfler 	BPoseView* PoseView() const;
8502be5353SAxel Dörfler 
8602be5353SAxel Dörfler protected:
8702be5353SAxel Dörfler 	void MouseMoved(BPoint, uint32, const BMessage*);
8802be5353SAxel Dörfler 
8902be5353SAxel Dörfler private:
9002be5353SAxel Dörfler 	BColumnTitle* FindColumnTitle(BPoint) const;
9102be5353SAxel Dörfler 	BColumnTitle* InColumnResizeArea(BPoint) const;
9202be5353SAxel Dörfler 	BColumnTitle* FindColumnTitle(const BColumn*) const;
9302be5353SAxel Dörfler 
94*d8b517b5SAxel Dörfler private:
9502be5353SAxel Dörfler 	BPoseView* fPoseView;
9602be5353SAxel Dörfler 	BObjectList<BColumnTitle> fTitleList;
9702be5353SAxel Dörfler 	BCursor fHorizontalResizeCursor;
98*d8b517b5SAxel Dörfler 			float				fPreferredHeight;
9902be5353SAxel Dörfler 
10002be5353SAxel Dörfler 	BColumnTitle* fPreviouslyClickedColumnTitle;
10102be5353SAxel Dörfler 	bigtime_t fPreviousLeftClickTime;
10227eab79bSAxel Dörfler 	ColumnTrackState* fTrackingState;
10302be5353SAxel Dörfler 
10427eab79bSAxel Dörfler 	static OffscreenBitmap* sOffscreen;
10502be5353SAxel Dörfler 
10602be5353SAxel Dörfler 	typedef BView _inherited;
10702be5353SAxel Dörfler 
10802be5353SAxel Dörfler 	friend class ColumnTrackState;
10902be5353SAxel Dörfler 	friend class ColumnDragState;
11002be5353SAxel Dörfler };
11102be5353SAxel Dörfler 
112b05aa8b5SJohn Scipione 
11302be5353SAxel Dörfler class BColumnTitle {
11402be5353SAxel Dörfler public:
11502be5353SAxel Dörfler 	BColumnTitle(BTitleView*, BColumn*);
~BColumnTitle()11602be5353SAxel Dörfler 	virtual ~BColumnTitle() {}
11702be5353SAxel Dörfler 
11802be5353SAxel Dörfler 	virtual void Draw(BView*, bool pressed = false);
11902be5353SAxel Dörfler 
12002be5353SAxel Dörfler 	BColumn* Column() const;
12102be5353SAxel Dörfler 	BRect Bounds() const;
12202be5353SAxel Dörfler 
12302be5353SAxel Dörfler 	bool InColumnResizeArea(BPoint) const;
12402be5353SAxel Dörfler 
12502be5353SAxel Dörfler private:
12602be5353SAxel Dörfler 	BColumn* fColumn;
12702be5353SAxel Dörfler 	BTitleView* fParent;
12802be5353SAxel Dörfler 
12902be5353SAxel Dörfler 	friend class ColumnResizeState;
13002be5353SAxel Dörfler };
13102be5353SAxel Dörfler 
132b05aa8b5SJohn Scipione 
13302be5353SAxel Dörfler // Utility classes to handle dragging state
13402be5353SAxel Dörfler class ColumnTrackState {
13502be5353SAxel Dörfler public:
13627eab79bSAxel Dörfler 	ColumnTrackState(BTitleView* titleView, BColumnTitle* columnTitle,
13727eab79bSAxel Dörfler 		BPoint where, bigtime_t pastClickTime);
~ColumnTrackState()13802be5353SAxel Dörfler 	virtual ~ColumnTrackState() {}
13902be5353SAxel Dörfler 
14002be5353SAxel Dörfler 	void MouseMoved(BPoint where, uint32 buttons);
14127eab79bSAxel Dörfler 	void MouseUp(BPoint where);
14202be5353SAxel Dörfler 
14302be5353SAxel Dörfler protected:
14427eab79bSAxel Dörfler 	virtual void Moved(BPoint where, uint32 buttons) = 0;
14527eab79bSAxel Dörfler 	virtual void Clicked(BPoint where) = 0;
14627eab79bSAxel Dörfler 	virtual void Done(BPoint where) = 0;
14702be5353SAxel Dörfler 	virtual bool ValueChanged(BPoint where) = 0;
14802be5353SAxel Dörfler 
14902be5353SAxel Dörfler 	BTitleView*		fTitleView;
15002be5353SAxel Dörfler 	BColumnTitle*	fTitle;
15127eab79bSAxel Dörfler 	BPoint			fFirstClickPoint;
15227eab79bSAxel Dörfler 	bigtime_t		fPastClickTime;
15327eab79bSAxel Dörfler 	bool			fHasMoved;
15402be5353SAxel Dörfler };
15502be5353SAxel Dörfler 
156b05aa8b5SJohn Scipione 
15702be5353SAxel Dörfler class ColumnResizeState : public ColumnTrackState {
15802be5353SAxel Dörfler public:
15927eab79bSAxel Dörfler 	ColumnResizeState(BTitleView* titleView, BColumnTitle* columnTitle,
16027eab79bSAxel Dörfler 		BPoint where, bigtime_t pastClickTime);
16102be5353SAxel Dörfler 
16202be5353SAxel Dörfler protected:
16327eab79bSAxel Dörfler 	virtual void Moved(BPoint where, uint32 buttons);
16427eab79bSAxel Dörfler 	virtual void Done(BPoint where);
16527eab79bSAxel Dörfler 	virtual void Clicked(BPoint where);
16602be5353SAxel Dörfler 	virtual bool ValueChanged(BPoint);
16702be5353SAxel Dörfler 
16802be5353SAxel Dörfler 	void DrawLine();
16902be5353SAxel Dörfler 	void UndrawLine();
17002be5353SAxel Dörfler 
17102be5353SAxel Dörfler private:
17202be5353SAxel Dörfler 	float fLastLineDrawPos;
17302be5353SAxel Dörfler 	float fInitialTrackOffset;
17402be5353SAxel Dörfler 
17502be5353SAxel Dörfler 	typedef ColumnTrackState _inherited;
17602be5353SAxel Dörfler };
17702be5353SAxel Dörfler 
178b05aa8b5SJohn Scipione 
17902be5353SAxel Dörfler class ColumnDragState : public ColumnTrackState {
18002be5353SAxel Dörfler public:
18127eab79bSAxel Dörfler 	ColumnDragState(BTitleView* titleView, BColumnTitle* columnTitle,
18227eab79bSAxel Dörfler 		BPoint where, bigtime_t pastClickTime);
18302be5353SAxel Dörfler 
18402be5353SAxel Dörfler protected:
18527eab79bSAxel Dörfler 	virtual void Moved(BPoint where, uint32 buttons);
18627eab79bSAxel Dörfler 	virtual void Done(BPoint where);
18727eab79bSAxel Dörfler 	virtual void Clicked(BPoint where);
18802be5353SAxel Dörfler 	virtual bool ValueChanged(BPoint);
18902be5353SAxel Dörfler 
19002be5353SAxel Dörfler 	void DrawOutline(float);
19102be5353SAxel Dörfler 	void UndrawOutline();
19202be5353SAxel Dörfler 	void DrawPressNoOutline();
19302be5353SAxel Dörfler 
19402be5353SAxel Dörfler private:
19502be5353SAxel Dörfler 	float fInitialMouseTrackOffset;
19602be5353SAxel Dörfler 	bool fTrackingRemovedColumn;
19702be5353SAxel Dörfler 	BMallocIO fColumnArchive;
19802be5353SAxel Dörfler 
19902be5353SAxel Dörfler 	typedef ColumnTrackState _inherited;
20002be5353SAxel Dörfler };
20102be5353SAxel Dörfler 
202b05aa8b5SJohn Scipione 
20302be5353SAxel Dörfler inline BColumn*
Column()20402be5353SAxel Dörfler BColumnTitle::Column() const
20502be5353SAxel Dörfler {
20602be5353SAxel Dörfler 	return fColumn;
20702be5353SAxel Dörfler }
20802be5353SAxel Dörfler 
209b05aa8b5SJohn Scipione 
21002be5353SAxel Dörfler inline BPoseView*
PoseView()21102be5353SAxel Dörfler BTitleView::PoseView() const
21202be5353SAxel Dörfler {
21302be5353SAxel Dörfler 	return fPoseView;
21402be5353SAxel Dörfler }
21502be5353SAxel Dörfler 
216b05aa8b5SJohn Scipione 
21702be5353SAxel Dörfler } // namespace BPrivate
21802be5353SAxel Dörfler 
21902be5353SAxel Dörfler using namespace BPrivate;
22002be5353SAxel Dörfler 
2216d4e243aSJohn Scipione 
22227eab79bSAxel Dörfler #endif	// _TITLE_VIEW_H
223