xref: /haiku/src/kits/tracker/Pose.h (revision 9760dcae2038d47442f4658c2575844c6cf92c40)
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 *, uint32 clipboardMode, 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, const BPoseView *);
64 		void MoveTo(BPoint, BPoseView *, bool inval = true);
65 
66 		void Draw(BRect poseRect, const BRect& updateRect, BPoseView *,
67 			bool fullDraw = true);
68 		void Draw(BRect poseRect, const BRect& updateRect, BPoseView *,
69 			BView *drawView, bool fullDraw, BPoint offset, bool selected);
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 		bigtime_t SelectionTime() const;
85 
86 		BTextWidget *ActiveWidget() const;
87 		BTextWidget *WidgetFor(uint32 hashAttr, int32 *index = 0) const;
88 		BTextWidget *WidgetFor(BColumn *column, BPoseView *poseView, ModelNodeLazyOpener &opener,
89 				int32 *index = NULL);
90 			// adds the widget if needed
91 
92 		bool PointInPose(BPoint poseLoc, const BPoseView *, BPoint where,
93 				BTextWidget ** = NULL) const;
94 		bool PointInPose(const BPoseView *, BPoint where) const ;
95 		BRect CalcRect(BPoint loc, const BPoseView *,
96 			bool minimal_rect = false) const;
97 		BRect CalcRect(const BPoseView *) const;
98 		void UpdateAllWidgets(int32 poseIndex, BPoint poseLoc, BPoseView *);
99 		void UpdateWidgetAndModel(Model *resolvedModel, const char *attrName,
100 				uint32 attrType, int32 poseIndex, BPoint poseLoc, BPoseView *view);
101 		bool UpdateVolumeSpaceBar(BVolume *volume);
102 		void UpdateIcon(BPoint poseLoc, BPoseView *);
103 
104 		//void UpdateFixedSymlink(BPoint poseLoc, BPoseView *);
105 		void UpdateBrokenSymLink(BPoint poseLoc, BPoseView *);
106 		void UpdateWasBrokenSymlink(BPoint poseLoc, BPoseView *poseView);
107 
108 		void Commit(bool saveChanges, BPoint loc, BPoseView *, int32 index);
109 		void EditFirstWidget(BPoint poseLoc, BPoseView *);
110 		void EditNextWidget(BPoseView *);
111 		void EditPreviousWidget(BPoseView *);
112 
113 		BPoint Location(const BPoseView *poseView) const;
114 		bool DelayedEdit() const;
115 		void SetDelayedEdit(bool delay);
116 		bool ListModeInited() const;
117 		bool HasLocation() const;
118 		bool NeedsSaveLocation() const;
119 		void SetSaveLocation();
120 		bool WasAutoPlaced() const;
121 		void SetAutoPlaced(bool);
122 
123 		uint32 ClipboardMode() const;
124 		void SetClipboardMode(uint32 clipboardMode);
125 
126 #if DEBUG
127 		void PrintToStream();
128 #endif
129 
130 	private:
131 		static bool _PeriodicUpdateCallback(BPose *pose, void *cookie);
132 		void EditPreviousNextWidgetCommon(BPoseView *poseView, bool next);
133 		void CreateWidgets(BPoseView *);
134 		bool TestLargeIconPixel(BPoint) const;
135 
136 		Model *fModel;
137 		BObjectList<BTextWidget> fWidgetList;
138 		BPoint fLocation;
139 
140 		uint32 fClipboardMode;
141 		int32 fPercent;
142 		bigtime_t fSelectionTime;
143 
144 		bool fIsSelected : 1;
145 		bool fHasLocation : 1;
146 		bool fNeedsSaveLocation : 1;
147 		bool fListModeInited : 1;
148 		bool fWasAutoPlaced : 1;
149 		bool fBrokenSymLink : 1;
150 		bool fBackgroundClean : 1;
151 };
152 
153 
154 inline Model *
155 BPose::TargetModel() const
156 {
157 	return fModel;
158 }
159 
160 
161 inline Model *
162 BPose::ResolvedModel() const
163 {
164 	return fModel->IsSymLink() ?
165 		(fModel->LinkTo() ? fModel->LinkTo() : fModel) : fModel;
166 }
167 
168 
169 inline bool
170 BPose::IsSelected()	const
171 {
172 	return fIsSelected;
173 }
174 
175 
176 inline void
177 BPose::Select(bool on)
178 {
179 	fIsSelected = on;
180 	if (on)
181 		fSelectionTime = system_time();
182 }
183 
184 
185 inline bigtime_t
186 BPose::SelectionTime()	const
187 {
188 	return fSelectionTime;
189 }
190 
191 
192 inline bool
193 BPose::NeedsSaveLocation() const
194 {
195 	return fNeedsSaveLocation;
196 }
197 
198 
199 inline void
200 BPose::SetSaveLocation()
201 {
202 	fNeedsSaveLocation = true;
203 }
204 
205 
206 inline bool
207 BPose::ListModeInited() const
208 {
209 	return fListModeInited;
210 }
211 
212 
213 inline bool
214 BPose::WasAutoPlaced() const
215 {
216 	return fWasAutoPlaced;
217 }
218 
219 
220 inline void
221 BPose::SetAutoPlaced(bool on)
222 {
223 	fWasAutoPlaced = on;
224 }
225 
226 
227 inline bool
228 BPose::HasLocation() const
229 {
230 	return fHasLocation;
231 }
232 
233 
234 inline void
235 BPose::Draw(BRect poseRect, const BRect& updateRect, BPoseView *view,
236 	bool fullDraw)
237 {
238 	Draw(poseRect, updateRect, view, (BView *)view, fullDraw, BPoint(0, 0),
239 		IsSelected());
240 }
241 
242 
243 inline uint32
244 BPose::ClipboardMode()	const
245 {
246 	return fClipboardMode;
247 }
248 
249 
250 inline void
251 BPose::SetClipboardMode(uint32 clipboardMode)
252 {
253 	fClipboardMode = clipboardMode;
254 }
255 
256 } // namespace BPrivate
257 
258 using namespace BPrivate;
259 
260 #endif
261