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