btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / tracker / WidgetAttributeText.h
blobbdc5c96448607552f29d28f89075c8c1963089ac
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
34 #ifndef _TEXT_WIDGET_ATTRIBUTE_H
35 #define _TEXT_WIDGET_ATTRIBUTE_H
38 #include <DateFormat.h>
39 #include <String.h>
41 #include "TrackerSettings.h"
44 namespace BPrivate {
46 class Model;
47 class BPoseView;
48 class BColumn;
50 // Tracker-only type for truncating the size string
51 // (Used in InfoWindow.cpp)
52 const uint32 kSizeType = 'kszt';
54 class WidgetAttributeText {
55 // each of subclasses knows how to retrieve a specific attribute
56 // from a model that is passed in and knows how to display the
57 // corresponding text, fitted into a specified width using a given
58 // view
59 // It is being asked for the string value by the TextWidget object
60 public:
61 WidgetAttributeText(const Model*, const BColumn*);
62 virtual ~WidgetAttributeText();
64 virtual bool CheckAttributeChanged() = 0;
65 // returns true if attribute value changed
67 bool CheckViewChanged(const BPoseView*);
68 // returns true if fitted text changed, either because value
69 // changed or because width/view changed
71 virtual bool CheckSettingsChanged();
72 // override if the text rendering depends on a setting
74 const char* FittingText(const BPoseView*);
75 // returns text, recalculating if not yet calculated
77 virtual int Compare(WidgetAttributeText&, BPoseView* view) = 0;
78 // override to define a compare of two different attributes for
79 // sorting
81 static WidgetAttributeText* NewWidgetText(const Model*,
82 const BColumn*, const BPoseView*);
83 // WidgetAttributeText factory
84 // call this to make the right WidgetAttributeText type for a
85 // given column
87 float Width(const BPoseView*);
88 // respects the width of the corresponding column
89 float CurrentWidth() const;
90 // return the item width we got during our last fitting attempt
92 virtual void SetUpEditing(BTextView*);
93 // set up the passed textView for the specifics of a given
94 // attribute editing
95 virtual bool CommitEditedText(BTextView*) = 0;
96 // return true if attribute actually changed
98 virtual float PreferredWidth(const BPoseView*) const = 0;
100 static status_t AttrAsString(const Model* model, BString* result,
101 const char* attrName, int32 attrType, float width,
102 BView* view, int64* value = 0);
104 Model* TargetModel() const;
106 virtual bool IsEditable() const;
108 void SetDirty(bool);
110 protected:
111 // generic fitting routines used by the different attributes
112 static float TruncString(BString* result, const char* src,
113 int32 length, const BPoseView*, float width,
114 uint32 truncMode = B_TRUNCATE_MIDDLE);
116 static float TruncTime(BString* result, int64 src,
117 const BPoseView* view, float width);
119 static float TruncFileSize(BString* result, int64 src,
120 const BPoseView* view, float width);
122 virtual void FitValue(BString* result, const BPoseView*) = 0;
123 // override FitValue to do a specific text fitting for a given
124 // attribute
126 mutable Model* fModel;
127 const BColumn* fColumn;
128 // TODO: make these int32 only
129 float fOldWidth;
130 float fTruncatedWidth;
131 bool fDirty;
132 // if true, need to recalculate text next time we try to use it
133 bool fValueIsDefined;
134 BString fText;
135 // holds the truncated text, fit to the parameters passed in
136 // in the last FittingText call
139 inline Model*
140 WidgetAttributeText::TargetModel() const
142 return fModel;
146 class StringAttributeText : public WidgetAttributeText {
147 public:
148 StringAttributeText(const Model*, const BColumn*);
150 virtual const char* ValueAsText(const BPoseView* view);
151 // returns the untrucated text that corresponds to
152 // the attribute value
154 virtual bool CheckAttributeChanged();
156 virtual float PreferredWidth(const BPoseView*) const;
158 virtual bool CommitEditedText(BTextView*);
160 protected:
161 virtual bool CommitEditedTextFlavor(BTextView*) { return false; }
163 virtual void FitValue(BString* result, const BPoseView*);
164 virtual void ReadValue(BString* result) = 0;
166 virtual int Compare(WidgetAttributeText &, BPoseView* view);
168 BString fFullValueText;
169 bool fValueDirty;
170 // used for lazy read, managed by ReadValue
174 class ScalarAttributeText : public WidgetAttributeText {
175 public:
176 ScalarAttributeText(const Model*, const BColumn*);
178 int64 Value();
179 virtual bool CheckAttributeChanged();
181 virtual float PreferredWidth(const BPoseView*) const;
183 virtual bool CommitEditedText(BTextView*) { return false; }
184 // return true if attribute actually changed
185 protected:
186 virtual int64 ReadValue() = 0;
187 virtual int Compare(WidgetAttributeText&, BPoseView* view);
188 int64 fValue;
189 bool fValueDirty;
190 // used for lazy read, managed by ReadValue
194 union GenericValueStruct {
195 time_t time_tt;
196 off_t off_tt;
198 bool boolt;
199 int8 int8t;
200 uint8 uint8t;
201 int16 int16t;
202 int16 uint16t;
203 int32 int32t;
204 int32 uint32t;
205 int64 int64t;
206 int64 uint64t;
208 float floatt;
209 double doublet;
213 //! Used for displaying mime extra attributes. Supports different formats.
214 class GenericAttributeText : public StringAttributeText {
215 public:
216 GenericAttributeText(const Model* model, const BColumn* column);
218 virtual bool CheckAttributeChanged();
219 virtual float PreferredWidth(const BPoseView* view) const;
221 virtual int Compare(WidgetAttributeText& other, BPoseView* view);
223 virtual void SetUpEditing(BTextView* view);
224 virtual bool CommitEditedText(BTextView* view);
226 virtual const char* ValueAsText(const BPoseView* view);
228 protected:
229 virtual bool CommitEditedTextFlavor(BTextView* view);
231 virtual void FitValue(BString* result, const BPoseView* view);
232 virtual void ReadValue(BString* result);
234 protected:
235 // TODO: split this up into a scalar flavor and string flavor
236 // to save memory
237 GenericValueStruct fValue;
241 //! Used for the display-as type "duration"
242 class DurationAttributeText : public GenericAttributeText {
243 public:
244 DurationAttributeText(const Model* model, const BColumn* column);
246 private:
247 virtual void FitValue(BString* result, const BPoseView* view);
251 //! Used for the display-as type "checkbox"
252 class CheckboxAttributeText : public GenericAttributeText {
253 public:
254 CheckboxAttributeText(const Model* model, const BColumn* column);
256 virtual void SetUpEditing(BTextView* view);
258 private:
259 virtual void FitValue(BString* result, const BPoseView* view);
261 private:
262 BString fOnChar;
263 BString fOffChar;
267 //! Used for the display-as type "rating"
268 class RatingAttributeText : public GenericAttributeText {
269 public:
270 RatingAttributeText(const Model* model, const BColumn* column);
272 virtual void SetUpEditing(BTextView* view);
274 private:
275 virtual void FitValue(BString* result, const BPoseView* view);
277 private:
278 int32 fCount;
279 int32 fMax;
283 class TimeAttributeText : public ScalarAttributeText {
284 public:
285 TimeAttributeText(const Model*, const BColumn*);
287 protected:
288 virtual float PreferredWidth(const BPoseView*) const;
289 virtual void FitValue(BString* ratingString, const BPoseView* view);
290 virtual bool CheckSettingsChanged();
292 TrackerSettings fSettings;
293 bool fLastClockIs24;
294 DateOrder fLastDateOrder;
295 FormatSeparator fLastTimeFormatSeparator;
299 class PathAttributeText : public StringAttributeText {
300 public:
301 PathAttributeText(const Model*, const BColumn*);
303 protected:
304 virtual void ReadValue(BString* result);
308 class OriginalPathAttributeText : public StringAttributeText {
309 public:
310 OriginalPathAttributeText(const Model*, const BColumn*);
312 protected:
313 virtual void ReadValue(BString* result);
317 class KindAttributeText : public StringAttributeText {
318 public:
319 KindAttributeText(const Model*, const BColumn*);
321 protected:
322 virtual void ReadValue(BString* result);
326 class NameAttributeText : public StringAttributeText {
327 public:
328 NameAttributeText(const Model*, const BColumn*);
329 virtual void SetUpEditing(BTextView*);
330 virtual void FitValue(BString* result, const BPoseView*);
331 virtual bool IsEditable() const;
333 static void SetSortFolderNamesFirst(bool);
335 protected:
336 virtual bool CommitEditedTextFlavor(BTextView*);
337 virtual int Compare(WidgetAttributeText&, BPoseView* view);
338 virtual void ReadValue(BString* result);
340 static bool sSortFolderNamesFirst;
344 class RealNameAttributeText : public StringAttributeText {
345 public:
346 RealNameAttributeText(const Model*, const BColumn*);
348 virtual void SetUpEditing(BTextView*);
349 virtual void FitValue(BString* result, const BPoseView*);
351 static void SetSortFolderNamesFirst(bool);
353 protected:
354 virtual bool CommitEditedTextFlavor(BTextView*);
355 virtual int Compare(WidgetAttributeText&, BPoseView* view);
356 virtual void ReadValue(BString* result);
358 static bool sSortFolderNamesFirst;
362 #ifdef OWNER_GROUP_ATTRIBUTES
363 class OwnerAttributeText : public StringAttributeText {
364 public:
365 OwnerAttributeText(const Model*, const BColumn*);
367 protected:
368 virtual void ReadValue(BString* result);
372 class GroupAttributeText : public StringAttributeText {
373 public:
374 GroupAttributeText(const Model*, const BColumn*);
376 protected:
377 virtual void ReadValue(BString* result);
379 #endif // OWNER_GROUP_ATTRIBUTES
382 class ModeAttributeText : public StringAttributeText {
383 public:
384 ModeAttributeText(const Model*, const BColumn*);
386 protected:
387 virtual void ReadValue(BString* result);
391 const int64 kUnknownSize = -1;
394 class SizeAttributeText : public ScalarAttributeText {
395 public:
396 SizeAttributeText(const Model*, const BColumn*);
398 protected:
399 virtual void FitValue(BString* result, const BPoseView*);
400 virtual int64 ReadValue();
401 virtual float PreferredWidth(const BPoseView*) const;
405 class CreationTimeAttributeText : public TimeAttributeText {
406 public:
407 CreationTimeAttributeText(const Model*, const BColumn*);
409 protected:
410 virtual int64 ReadValue();
414 class ModificationTimeAttributeText : public TimeAttributeText {
415 public:
416 ModificationTimeAttributeText(const Model*, const BColumn*);
418 protected:
419 virtual int64 ReadValue();
423 class OpenWithRelationAttributeText : public ScalarAttributeText {
424 public:
425 OpenWithRelationAttributeText(const Model*, const BColumn*,
426 const BPoseView*);
428 protected:
429 virtual void FitValue(BString* result, const BPoseView*);
430 virtual int64 ReadValue();
431 virtual float PreferredWidth(const BPoseView*) const;
433 const BPoseView* fPoseView;
434 BString fRelationText;
438 class VersionAttributeText : public StringAttributeText {
439 public:
440 VersionAttributeText(const Model*, const BColumn*, bool appVersion);
442 protected:
443 virtual void ReadValue(BString* result);
445 private:
446 bool fAppVersion;
450 class AppShortVersionAttributeText : public VersionAttributeText {
451 public:
452 AppShortVersionAttributeText(const Model* model,
453 const BColumn* column)
455 VersionAttributeText(model, column, true)
461 class SystemShortVersionAttributeText : public VersionAttributeText {
462 public:
463 SystemShortVersionAttributeText(const Model* model,
464 const BColumn* column)
466 VersionAttributeText(model, column, false)
471 } // namespace BPrivate
474 extern status_t TimeFormat(BString &string, int32 index,
475 FormatSeparator format, DateOrder order, bool clockIs24Hour);
477 using namespace BPrivate;
480 #endif // _TEXT_WIDGET_ATTRIBUTE_H