xref: /haiku/src/kits/tracker/Pose.h (revision 8446d3b9b52156fd5d196b202090bda1a2cfa7b0)
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 _POSE_H
3502be5353SAxel Dörfler #define _POSE_H
3602be5353SAxel Dörfler 
37b05aa8b5SJohn Scipione 
3802be5353SAxel Dörfler #include <Region.h>
3902be5353SAxel Dörfler 
4002be5353SAxel Dörfler #include "TextWidget.h"
4102be5353SAxel Dörfler #include "Model.h"
4202be5353SAxel Dörfler #include "Utilities.h"
4302be5353SAxel Dörfler 
44b05aa8b5SJohn Scipione 
4502be5353SAxel Dörfler namespace BPrivate {
4602be5353SAxel Dörfler 
4702be5353SAxel Dörfler class BPoseView;
4802be5353SAxel Dörfler class BTextWidget;
4902be5353SAxel Dörfler 
5002be5353SAxel Dörfler enum {
5102be5353SAxel Dörfler 	B_NAME_WIDGET,
5202be5353SAxel Dörfler 	B_ALL_WIDGETS
5302be5353SAxel Dörfler };
5402be5353SAxel Dörfler 
5502be5353SAxel Dörfler 
5602be5353SAxel Dörfler class BPose {
5702be5353SAxel Dörfler public:
58a51764c5SJohn Scipione 	BPose(Model* adopt, BPoseView*, uint32 clipboardMode,
59a51764c5SJohn Scipione 		bool selected = false);
6002be5353SAxel Dörfler 	virtual ~BPose();
6102be5353SAxel Dörfler 
6202be5353SAxel Dörfler 	BTextWidget* AddWidget(BPoseView*, BColumn*);
63a51764c5SJohn Scipione 	BTextWidget* AddWidget(BPoseView*, BColumn*,
64a51764c5SJohn Scipione 		ModelNodeLazyOpener &opener);
6502be5353SAxel Dörfler 	void RemoveWidget(BPoseView*, BColumn*);
667cdbeb0eSStephan Aßmus 	void SetLocation(BPoint, const BPoseView*);
676b1b5709SJohn Scipione 	void MoveTo(BPoint, BPoseView*, bool invalidate = true);
6802be5353SAxel Dörfler 
696a71afb0SStephan Aßmus 	void Draw(BRect poseRect, const BRect& updateRect, BPoseView*,
706a71afb0SStephan Aßmus 		bool fullDraw = true);
716a71afb0SStephan Aßmus 	void Draw(BRect poseRect, const BRect& updateRect, BPoseView*,
726a71afb0SStephan Aßmus 		BView* drawView, bool fullDraw, BPoint offset, bool selected);
73a51764c5SJohn Scipione 	void DeselectWithoutErasingBackground(BRect rect,
74a51764c5SJohn Scipione 		BPoseView* poseView);
7502be5353SAxel Dörfler 		// special purpose draw call for deselecting over a textured
7602be5353SAxel Dörfler 		// background
7702be5353SAxel Dörfler 
780c973c94SAugustin Cavalier 	void DrawBar(BPoint where, BView* view, BSize iconSize);
7902be5353SAxel Dörfler 
800c973c94SAugustin Cavalier 	void DrawIcon(BPoint where, BView* view, BSize size, bool direct,
81a51764c5SJohn Scipione 		bool drawUnselected = false);
8202be5353SAxel Dörfler 	void DrawToggleSwitch(BRect, BPoseView*);
8302be5353SAxel Dörfler 	void MouseUp(BPoint poseLoc, BPoseView*, BPoint where, int32 index);
8402be5353SAxel Dörfler 	Model* TargetModel() const;
8502be5353SAxel Dörfler 	Model* ResolvedModel() const;
8602be5353SAxel Dörfler 	void Select(bool selected);
8702be5353SAxel Dörfler 	bool IsSelected() const;
8802be5353SAxel Dörfler 		// Rename to IsHighlighted
8950f1b82dSAlexandre Deckner 	bigtime_t SelectionTime() const;
9002be5353SAxel Dörfler 
9102be5353SAxel Dörfler 	BTextWidget* ActiveWidget() const;
9202be5353SAxel Dörfler 	BTextWidget* WidgetFor(uint32 hashAttr, int32* index = 0) const;
93b05aa8b5SJohn Scipione 	BTextWidget* WidgetFor(BColumn* column, BPoseView* poseView,
94b05aa8b5SJohn Scipione 		ModelNodeLazyOpener &opener, int32* index = NULL);
9502be5353SAxel Dörfler 		// adds the widget if needed
9602be5353SAxel Dörfler 
9702be5353SAxel Dörfler 	bool PointInPose(BPoint poseLoc, const BPoseView*, BPoint where,
9802be5353SAxel Dörfler 			BTextWidget** = NULL) const;
9902be5353SAxel Dörfler 	bool PointInPose(const BPoseView*, BPoint where) const;
10096da4b41SStephan Aßmus 	BRect CalcRect(BPoint loc, const BPoseView*,
10196da4b41SStephan Aßmus 		bool minimal_rect = false) const;
10296da4b41SStephan Aßmus 	BRect CalcRect(const BPoseView*) const;
10302be5353SAxel Dörfler 	void UpdateAllWidgets(int32 poseIndex, BPoint poseLoc, BPoseView*);
10402be5353SAxel Dörfler 	void UpdateWidgetAndModel(Model* resolvedModel, const char* attrName,
105545ebde0SMichael Lotz 			uint32 attrType, int32 poseIndex, BPoint poseLoc,
106545ebde0SMichael Lotz 			BPoseView* view, bool visible);
107687e327bSMichael Lotz 	bool UpdateVolumeSpaceBar(BVolume* volume);
10802be5353SAxel Dörfler 	void UpdateIcon(BPoint poseLoc, BPoseView*);
10902be5353SAxel Dörfler 
11002be5353SAxel Dörfler 	//void UpdateFixedSymlink(BPoint poseLoc, BPoseView*);
11102be5353SAxel Dörfler 	void UpdateBrokenSymLink(BPoint poseLoc, BPoseView*);
11202be5353SAxel Dörfler 	void UpdateWasBrokenSymlink(BPoint poseLoc, BPoseView* poseView);
11302be5353SAxel Dörfler 
11402be5353SAxel Dörfler 	void Commit(bool saveChanges, BPoint loc, BPoseView*, int32 index);
11502be5353SAxel Dörfler 	void EditFirstWidget(BPoint poseLoc, BPoseView*);
11602be5353SAxel Dörfler 	void EditNextWidget(BPoseView*);
11702be5353SAxel Dörfler 	void EditPreviousWidget(BPoseView*);
11802be5353SAxel Dörfler 
1197cdbeb0eSStephan Aßmus 	BPoint Location(const BPoseView* poseView) const;
12002be5353SAxel Dörfler 	bool DelayedEdit() const;
12102be5353SAxel Dörfler 	void SetDelayedEdit(bool delay);
12202be5353SAxel Dörfler 	bool ListModeInited() const;
12302be5353SAxel Dörfler 	bool HasLocation() const;
12402be5353SAxel Dörfler 	bool NeedsSaveLocation() const;
12502be5353SAxel Dörfler 	void SetSaveLocation();
12602be5353SAxel Dörfler 	bool WasAutoPlaced() const;
12702be5353SAxel Dörfler 	void SetAutoPlaced(bool);
12802be5353SAxel Dörfler 
12902be5353SAxel Dörfler 	uint32 ClipboardMode() const;
13002be5353SAxel Dörfler 	void SetClipboardMode(uint32 clipboardMode);
13102be5353SAxel Dörfler #if DEBUG
13202be5353SAxel Dörfler 	void PrintToStream();
13302be5353SAxel Dörfler #endif
13402be5353SAxel Dörfler 
13502be5353SAxel Dörfler private:
136687e327bSMichael Lotz 	static bool _PeriodicUpdateCallback(BPose* pose, void* cookie);
13702be5353SAxel Dörfler 	void EditPreviousNextWidgetCommon(BPoseView* poseView, bool next);
13802be5353SAxel Dörfler 	void CreateWidgets(BPoseView*);
1390c973c94SAugustin Cavalier 
14046dd7d50SAxel Dörfler 			BRect				_IconRect(const BPoseView* poseView,
14146dd7d50SAxel Dörfler 									BPoint location) const;
14202be5353SAxel Dörfler 
14302be5353SAxel Dörfler 	Model* fModel;
14402be5353SAxel Dörfler 	BObjectList<BTextWidget> fWidgetList;
14502be5353SAxel Dörfler 	BPoint fLocation;
14602be5353SAxel Dörfler 
14702be5353SAxel Dörfler 	uint32 fClipboardMode;
14802be5353SAxel Dörfler 	int32 fPercent;
14950f1b82dSAlexandre Deckner 	bigtime_t fSelectionTime;
15002be5353SAxel Dörfler 
15102be5353SAxel Dörfler 	bool fIsSelected : 1;
15202be5353SAxel Dörfler 	bool fHasLocation : 1;
15302be5353SAxel Dörfler 	bool fNeedsSaveLocation : 1;
15402be5353SAxel Dörfler 	bool fListModeInited : 1;
15502be5353SAxel Dörfler 	bool fWasAutoPlaced : 1;
15602be5353SAxel Dörfler 	bool fBrokenSymLink : 1;
15702be5353SAxel Dörfler 	bool fBackgroundClean : 1;
15802be5353SAxel Dörfler };
15902be5353SAxel Dörfler 
16002be5353SAxel Dörfler 
16102be5353SAxel Dörfler inline Model*
TargetModel()16202be5353SAxel Dörfler BPose::TargetModel() const
16302be5353SAxel Dörfler {
16402be5353SAxel Dörfler 	return fModel;
16502be5353SAxel Dörfler }
16602be5353SAxel Dörfler 
16702be5353SAxel Dörfler 
16802be5353SAxel Dörfler inline Model*
ResolvedModel()16902be5353SAxel Dörfler BPose::ResolvedModel() const
17002be5353SAxel Dörfler {
171d7e68211SJohn Scipione 	if (fModel->IsSymLink())
172d7e68211SJohn Scipione 		return fModel->LinkTo() != NULL ? fModel->LinkTo() : fModel;
173d7e68211SJohn Scipione 	else
174d7e68211SJohn Scipione 		return fModel;
17502be5353SAxel Dörfler }
17602be5353SAxel Dörfler 
17702be5353SAxel Dörfler 
17802be5353SAxel Dörfler inline bool
IsSelected()17902be5353SAxel Dörfler BPose::IsSelected() const
18002be5353SAxel Dörfler {
18102be5353SAxel Dörfler 	return fIsSelected;
18202be5353SAxel Dörfler }
18302be5353SAxel Dörfler 
18402be5353SAxel Dörfler 
18502be5353SAxel Dörfler inline void
Select(bool on)18602be5353SAxel Dörfler BPose::Select(bool on)
18702be5353SAxel Dörfler {
18802be5353SAxel Dörfler 	fIsSelected = on;
18950f1b82dSAlexandre Deckner 	if (on)
19050f1b82dSAlexandre Deckner 		fSelectionTime = system_time();
19102be5353SAxel Dörfler }
19202be5353SAxel Dörfler 
19302be5353SAxel Dörfler 
19450f1b82dSAlexandre Deckner inline bigtime_t
SelectionTime()19550f1b82dSAlexandre Deckner BPose::SelectionTime() const
19602be5353SAxel Dörfler {
19750f1b82dSAlexandre Deckner 	return fSelectionTime;
19802be5353SAxel Dörfler }
19902be5353SAxel Dörfler 
20002be5353SAxel Dörfler 
20102be5353SAxel Dörfler inline bool
NeedsSaveLocation()20202be5353SAxel Dörfler BPose::NeedsSaveLocation() const
20302be5353SAxel Dörfler {
20402be5353SAxel Dörfler 	return fNeedsSaveLocation;
20502be5353SAxel Dörfler }
20602be5353SAxel Dörfler 
20702be5353SAxel Dörfler 
20802be5353SAxel Dörfler inline void
SetSaveLocation()20902be5353SAxel Dörfler BPose::SetSaveLocation()
21002be5353SAxel Dörfler {
21102be5353SAxel Dörfler 	fNeedsSaveLocation = true;
21202be5353SAxel Dörfler }
21302be5353SAxel Dörfler 
21402be5353SAxel Dörfler 
21502be5353SAxel Dörfler inline bool
ListModeInited()21602be5353SAxel Dörfler BPose::ListModeInited() const
21702be5353SAxel Dörfler {
21802be5353SAxel Dörfler 	return fListModeInited;
21902be5353SAxel Dörfler }
22002be5353SAxel Dörfler 
22102be5353SAxel Dörfler 
22202be5353SAxel Dörfler inline bool
WasAutoPlaced()22302be5353SAxel Dörfler BPose::WasAutoPlaced() const
22402be5353SAxel Dörfler {
22502be5353SAxel Dörfler 	return fWasAutoPlaced;
22602be5353SAxel Dörfler }
22702be5353SAxel Dörfler 
22802be5353SAxel Dörfler 
22902be5353SAxel Dörfler inline void
SetAutoPlaced(bool on)23002be5353SAxel Dörfler BPose::SetAutoPlaced(bool on)
23102be5353SAxel Dörfler {
23202be5353SAxel Dörfler 	fWasAutoPlaced = on;
23302be5353SAxel Dörfler }
23402be5353SAxel Dörfler 
23502be5353SAxel Dörfler 
23602be5353SAxel Dörfler inline bool
HasLocation()23702be5353SAxel Dörfler BPose::HasLocation() const
23802be5353SAxel Dörfler {
23902be5353SAxel Dörfler 	return fHasLocation;
24002be5353SAxel Dörfler }
24102be5353SAxel Dörfler 
24202be5353SAxel Dörfler 
24302be5353SAxel Dörfler inline void
Draw(BRect poseRect,const BRect & updateRect,BPoseView * view,bool fullDraw)2446a71afb0SStephan Aßmus BPose::Draw(BRect poseRect, const BRect& updateRect, BPoseView* view,
2456a71afb0SStephan Aßmus 	bool fullDraw)
24602be5353SAxel Dörfler {
247*8446d3b9SJohn Scipione 	Draw(poseRect, updateRect, view, (BView*)view, fullDraw, B_ORIGIN,
248e9842421SAlexandre Deckner 		IsSelected());
24902be5353SAxel Dörfler }
25002be5353SAxel Dörfler 
25102be5353SAxel Dörfler 
25202be5353SAxel Dörfler inline uint32
ClipboardMode()25302be5353SAxel Dörfler BPose::ClipboardMode() const
25402be5353SAxel Dörfler {
25502be5353SAxel Dörfler 	return fClipboardMode;
25602be5353SAxel Dörfler }
25702be5353SAxel Dörfler 
25802be5353SAxel Dörfler 
25902be5353SAxel Dörfler inline void
SetClipboardMode(uint32 clipboardMode)26002be5353SAxel Dörfler BPose::SetClipboardMode(uint32 clipboardMode)
26102be5353SAxel Dörfler {
26202be5353SAxel Dörfler 	fClipboardMode = clipboardMode;
26302be5353SAxel Dörfler }
26402be5353SAxel Dörfler 
26502be5353SAxel Dörfler } // namespace BPrivate
26602be5353SAxel Dörfler 
26702be5353SAxel Dörfler using namespace BPrivate;
26802be5353SAxel Dörfler 
2696b1b5709SJohn Scipione 
270b05aa8b5SJohn Scipione #endif	// _POSE_H
271