xref: /haiku/src/kits/tracker/Pose.h (revision 70449c90d95aeea01b25f686d51da4217fe41317)
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 _POSE_H
35 #define _POSE_H
36 
37 
38 #include <Region.h>
39 
40 #include "TextWidget.h"
41 #include "Model.h"
42 #include "Utilities.h"
43 
44 
45 namespace BPrivate {
46 
47 class BPoseView;
48 class BTextWidget;
49 
50 enum {
51 	B_NAME_WIDGET,
52 	B_ALL_WIDGETS
53 };
54 
55 
56 class BPose {
57 	public:
58 		BPose(Model* adopt, BPoseView*, uint32 clipboardMode,
59 			bool selected = false);
60 		virtual ~BPose();
61 
62 		BTextWidget* AddWidget(BPoseView*, BColumn*);
63 		BTextWidget* AddWidget(BPoseView*, BColumn*,
64 			ModelNodeLazyOpener &opener);
65 		void RemoveWidget(BPoseView*, BColumn*);
66 		void SetLocation(BPoint, const BPoseView*);
67 		void MoveTo(BPoint, BPoseView*, bool inval = true);
68 
69 		void Draw(BRect poseRect, const BRect& updateRect, BPoseView*,
70 			bool fullDraw = true);
71 		void Draw(BRect poseRect, const BRect& updateRect, BPoseView*,
72 			BView* drawView, bool fullDraw, BPoint offset, bool selected);
73 		void DeselectWithoutErasingBackground(BRect rect,
74 			BPoseView* poseView);
75 			// special purpose draw call for deselecting over a textured
76 			// background
77 
78 		void DrawBar(BPoint where, BView* view, icon_size kind);
79 
80 		void DrawIcon(BPoint, BView*, icon_size, bool direct,
81 			bool drawUnselected = false);
82 		void DrawToggleSwitch(BRect, BPoseView*);
83 		void MouseUp(BPoint poseLoc, BPoseView*, BPoint where, int32 index);
84 		Model* TargetModel() const;
85 		Model* ResolvedModel() const;
86 		void Select(bool selected);
87 		bool IsSelected() const;
88 			// Rename to IsHighlighted
89 		bigtime_t SelectionTime() const;
90 
91 		BTextWidget* ActiveWidget() const;
92 		BTextWidget* WidgetFor(uint32 hashAttr, int32* index = 0) const;
93 		BTextWidget* WidgetFor(BColumn* column, BPoseView* poseView,
94 			ModelNodeLazyOpener &opener, int32* index = NULL);
95 			// adds the widget if needed
96 
97 		bool PointInPose(BPoint poseLoc, const BPoseView*, BPoint where,
98 				BTextWidget** = NULL) const;
99 		bool PointInPose(const BPoseView*, BPoint where) const;
100 		BRect CalcRect(BPoint loc, const BPoseView*,
101 			bool minimal_rect = false) const;
102 		BRect CalcRect(const BPoseView*) const;
103 		void UpdateAllWidgets(int32 poseIndex, BPoint poseLoc, BPoseView*);
104 		void UpdateWidgetAndModel(Model* resolvedModel, const char* attrName,
105 				uint32 attrType, int32 poseIndex, BPoint poseLoc,
106 				BPoseView* view, bool visible);
107 		bool UpdateVolumeSpaceBar(BVolume* volume);
108 		void UpdateIcon(BPoint poseLoc, BPoseView*);
109 
110 		//void UpdateFixedSymlink(BPoint poseLoc, BPoseView*);
111 		void UpdateBrokenSymLink(BPoint poseLoc, BPoseView*);
112 		void UpdateWasBrokenSymlink(BPoint poseLoc, BPoseView* poseView);
113 
114 		void Commit(bool saveChanges, BPoint loc, BPoseView*, int32 index);
115 		void EditFirstWidget(BPoint poseLoc, BPoseView*);
116 		void EditNextWidget(BPoseView*);
117 		void EditPreviousWidget(BPoseView*);
118 
119 		BPoint Location(const BPoseView* poseView) const;
120 		bool DelayedEdit() const;
121 		void SetDelayedEdit(bool delay);
122 		bool ListModeInited() const;
123 		bool HasLocation() const;
124 		bool NeedsSaveLocation() const;
125 		void SetSaveLocation();
126 		bool WasAutoPlaced() const;
127 		void SetAutoPlaced(bool);
128 
129 		uint32 ClipboardMode() const;
130 		void SetClipboardMode(uint32 clipboardMode);
131 
132 #if DEBUG
133 		void PrintToStream();
134 #endif
135 
136 	private:
137 		static bool _PeriodicUpdateCallback(BPose* pose, void* cookie);
138 		void EditPreviousNextWidgetCommon(BPoseView* poseView, bool next);
139 		void CreateWidgets(BPoseView*);
140 		bool TestLargeIconPixel(BPoint) const;
141 
142 		Model* fModel;
143 		BObjectList<BTextWidget> fWidgetList;
144 		BPoint fLocation;
145 
146 		uint32 fClipboardMode;
147 		int32 fPercent;
148 		bigtime_t fSelectionTime;
149 
150 		bool fIsSelected : 1;
151 		bool fHasLocation : 1;
152 		bool fNeedsSaveLocation : 1;
153 		bool fListModeInited : 1;
154 		bool fWasAutoPlaced : 1;
155 		bool fBrokenSymLink : 1;
156 		bool fBackgroundClean : 1;
157 };
158 
159 
160 inline Model*
161 BPose::TargetModel() const
162 {
163 	return fModel;
164 }
165 
166 
167 inline Model*
168 BPose::ResolvedModel() const
169 {
170 	return fModel->IsSymLink() ?
171 		(fModel->LinkTo() ? fModel->LinkTo() : fModel) : fModel;
172 }
173 
174 
175 inline bool
176 BPose::IsSelected()	const
177 {
178 	return fIsSelected;
179 }
180 
181 
182 inline void
183 BPose::Select(bool on)
184 {
185 	fIsSelected = on;
186 	if (on)
187 		fSelectionTime = system_time();
188 }
189 
190 
191 inline bigtime_t
192 BPose::SelectionTime()	const
193 {
194 	return fSelectionTime;
195 }
196 
197 
198 inline bool
199 BPose::NeedsSaveLocation() const
200 {
201 	return fNeedsSaveLocation;
202 }
203 
204 
205 inline void
206 BPose::SetSaveLocation()
207 {
208 	fNeedsSaveLocation = true;
209 }
210 
211 
212 inline bool
213 BPose::ListModeInited() const
214 {
215 	return fListModeInited;
216 }
217 
218 
219 inline bool
220 BPose::WasAutoPlaced() const
221 {
222 	return fWasAutoPlaced;
223 }
224 
225 
226 inline void
227 BPose::SetAutoPlaced(bool on)
228 {
229 	fWasAutoPlaced = on;
230 }
231 
232 
233 inline bool
234 BPose::HasLocation() const
235 {
236 	return fHasLocation;
237 }
238 
239 
240 inline void
241 BPose::Draw(BRect poseRect, const BRect& updateRect, BPoseView* view,
242 	bool fullDraw)
243 {
244 	Draw(poseRect, updateRect, view, (BView*)view, fullDraw, BPoint(0, 0),
245 		IsSelected());
246 }
247 
248 
249 inline uint32
250 BPose::ClipboardMode() const
251 {
252 	return fClipboardMode;
253 }
254 
255 
256 inline void
257 BPose::SetClipboardMode(uint32 clipboardMode)
258 {
259 	fClipboardMode = clipboardMode;
260 }
261 
262 } // namespace BPrivate
263 
264 using namespace BPrivate;
265 
266 #endif	// _POSE_H
267