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