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.
34 #ifndef _TEXT_WIDGET_ATTRIBUTE_H
35 #define _TEXT_WIDGET_ATTRIBUTE_H
38 #include <DateFormat.h>
41 #include "TrackerSettings.h"
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
59 // It is being asked for the string value by the TextWidget object
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
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
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
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;
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
126 mutable Model
* fModel
;
127 const BColumn
* fColumn
;
128 // TODO: make these int32 only
130 float fTruncatedWidth
;
132 // if true, need to recalculate text next time we try to use it
133 bool fValueIsDefined
;
135 // holds the truncated text, fit to the parameters passed in
136 // in the last FittingText call
140 WidgetAttributeText::TargetModel() const
146 class StringAttributeText
: public WidgetAttributeText
{
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
*);
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
;
170 // used for lazy read, managed by ReadValue
174 class ScalarAttributeText
: public WidgetAttributeText
{
176 ScalarAttributeText(const Model
*, const BColumn
*);
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
186 virtual int64
ReadValue() = 0;
187 virtual int Compare(WidgetAttributeText
&, BPoseView
* view
);
190 // used for lazy read, managed by ReadValue
194 union GenericValueStruct
{
213 //! Used for displaying mime extra attributes. Supports different formats.
214 class GenericAttributeText
: public StringAttributeText
{
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
);
229 virtual bool CommitEditedTextFlavor(BTextView
* view
);
231 virtual void FitValue(BString
* result
, const BPoseView
* view
);
232 virtual void ReadValue(BString
* result
);
235 // TODO: split this up into a scalar flavor and string flavor
237 GenericValueStruct fValue
;
241 //! Used for the display-as type "duration"
242 class DurationAttributeText
: public GenericAttributeText
{
244 DurationAttributeText(const Model
* model
, const BColumn
* column
);
247 virtual void FitValue(BString
* result
, const BPoseView
* view
);
251 //! Used for the display-as type "checkbox"
252 class CheckboxAttributeText
: public GenericAttributeText
{
254 CheckboxAttributeText(const Model
* model
, const BColumn
* column
);
256 virtual void SetUpEditing(BTextView
* view
);
259 virtual void FitValue(BString
* result
, const BPoseView
* view
);
267 //! Used for the display-as type "rating"
268 class RatingAttributeText
: public GenericAttributeText
{
270 RatingAttributeText(const Model
* model
, const BColumn
* column
);
272 virtual void SetUpEditing(BTextView
* view
);
275 virtual void FitValue(BString
* result
, const BPoseView
* view
);
283 class TimeAttributeText
: public ScalarAttributeText
{
285 TimeAttributeText(const Model
*, const BColumn
*);
288 virtual float PreferredWidth(const BPoseView
*) const;
289 virtual void FitValue(BString
* ratingString
, const BPoseView
* view
);
290 virtual bool CheckSettingsChanged();
292 TrackerSettings fSettings
;
294 DateOrder fLastDateOrder
;
295 FormatSeparator fLastTimeFormatSeparator
;
299 class PathAttributeText
: public StringAttributeText
{
301 PathAttributeText(const Model
*, const BColumn
*);
304 virtual void ReadValue(BString
* result
);
308 class OriginalPathAttributeText
: public StringAttributeText
{
310 OriginalPathAttributeText(const Model
*, const BColumn
*);
313 virtual void ReadValue(BString
* result
);
317 class KindAttributeText
: public StringAttributeText
{
319 KindAttributeText(const Model
*, const BColumn
*);
322 virtual void ReadValue(BString
* result
);
326 class NameAttributeText
: public StringAttributeText
{
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);
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
{
346 RealNameAttributeText(const Model
*, const BColumn
*);
348 virtual void SetUpEditing(BTextView
*);
349 virtual void FitValue(BString
* result
, const BPoseView
*);
351 static void SetSortFolderNamesFirst(bool);
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
{
365 OwnerAttributeText(const Model
*, const BColumn
*);
368 virtual void ReadValue(BString
* result
);
372 class GroupAttributeText
: public StringAttributeText
{
374 GroupAttributeText(const Model
*, const BColumn
*);
377 virtual void ReadValue(BString
* result
);
379 #endif // OWNER_GROUP_ATTRIBUTES
382 class ModeAttributeText
: public StringAttributeText
{
384 ModeAttributeText(const Model
*, const BColumn
*);
387 virtual void ReadValue(BString
* result
);
391 const int64 kUnknownSize
= -1;
394 class SizeAttributeText
: public ScalarAttributeText
{
396 SizeAttributeText(const Model
*, const BColumn
*);
399 virtual void FitValue(BString
* result
, const BPoseView
*);
400 virtual int64
ReadValue();
401 virtual float PreferredWidth(const BPoseView
*) const;
405 class CreationTimeAttributeText
: public TimeAttributeText
{
407 CreationTimeAttributeText(const Model
*, const BColumn
*);
410 virtual int64
ReadValue();
414 class ModificationTimeAttributeText
: public TimeAttributeText
{
416 ModificationTimeAttributeText(const Model
*, const BColumn
*);
419 virtual int64
ReadValue();
423 class OpenWithRelationAttributeText
: public ScalarAttributeText
{
425 OpenWithRelationAttributeText(const Model
*, const BColumn
*,
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
{
440 VersionAttributeText(const Model
*, const BColumn
*, bool appVersion
);
443 virtual void ReadValue(BString
* result
);
450 class AppShortVersionAttributeText
: public VersionAttributeText
{
452 AppShortVersionAttributeText(const Model
* model
,
453 const BColumn
* column
)
455 VersionAttributeText(model
, column
, true)
461 class SystemShortVersionAttributeText
: public VersionAttributeText
{
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