1 /******************************************************************************* 2 / 3 / File: ColumnTypes.h 4 / 5 / Description: Experimental classes that implement particular column/field 6 / data types for use in BColumnListView. 7 / 8 / Copyright 2000+, Be Incorporated, All Rights Reserved 9 / 10 *******************************************************************************/ 11 12 13 #ifndef _COLUMN_TYPES_H 14 #define _COLUMN_TYPES_H 15 16 17 #include "ColumnListView.h" 18 19 #include <Bitmap.h> 20 #include <DateFormat.h> 21 #include <DateTimeFormat.h> 22 #include <Font.h> 23 #include <NumberFormat.h> 24 #include <String.h> 25 26 27 //===================================================================== 28 // Common base-class: a column that draws a standard title at its top. 29 30 class BTitledColumn : public BColumn 31 { 32 public: 33 BTitledColumn(const char* title, float width, float minWidth, 34 float maxWidth, alignment align = B_ALIGN_LEFT); 35 virtual void DrawTitle(BRect rect, BView* parent); 36 virtual void GetColumnName(BString* into) const; 37 38 void DrawString(const char*, BView*, BRect); 39 void SetTitle(const char* title); 40 void Title(BString* forTitle) const; 41 // sets the BString arg to be the title 42 float FontHeight() const; 43 44 virtual float GetPreferredWidth(BField* field, BView* parent) const; 45 46 protected: 47 BNumberFormat fNumberFormat; 48 49 private: 50 float fFontHeight; 51 BString fTitle; 52 }; 53 54 55 //===================================================================== 56 // Field and column classes for strings. 57 58 class BStringField : public BField 59 { 60 public: 61 BStringField(const char* string); 62 63 void SetString(const char* string); 64 const char* String() const; 65 void SetClippedString(const char* string); 66 bool HasClippedString() const; 67 const char* ClippedString(); 68 void SetWidth(float); 69 float Width(); 70 71 private: 72 float fWidth; 73 BString fString; 74 BString fClippedString; 75 }; 76 77 78 //-------------------------------------------------------------------- 79 80 class BStringColumn : public BTitledColumn 81 { 82 public: 83 BStringColumn(const char* title, float width, 84 float minWidth, float maxWidth, uint32 truncate, 85 alignment align = B_ALIGN_LEFT); 86 virtual void DrawField(BField* field, BRect rect, BView* parent); 87 virtual int CompareFields(BField* field1, BField* field2); 88 virtual float GetPreferredWidth(BField* field, BView* parent) const; 89 virtual bool AcceptsField(const BField* field) const; 90 91 private: 92 uint32 fTruncate; 93 }; 94 95 96 //===================================================================== 97 // Field and column classes for dates. 98 99 class BDateField : public BField 100 { 101 public: 102 BDateField(time_t* t); 103 void SetWidth(float); 104 float Width(); 105 void SetClippedString(const char*); 106 const char* ClippedString(); 107 time_t Seconds(); 108 time_t UnixTime(); 109 110 private: 111 struct tm fTime; 112 time_t fUnixTime; 113 time_t fSeconds; 114 BString fClippedString; 115 float fWidth; 116 }; 117 118 119 //-------------------------------------------------------------------- 120 121 class BDateColumn : public BTitledColumn 122 { 123 public: 124 BDateColumn(const char* title, float width, 125 float minWidth, float maxWidth, 126 alignment align = B_ALIGN_LEFT); 127 virtual void DrawField(BField* field, BRect rect, BView* parent); 128 virtual int CompareFields(BField* field1, BField* field2); 129 130 private: 131 BDateTimeFormat fDateTimeFormat; 132 BDateFormat fDateFormat; 133 BString fTitle; 134 }; 135 136 137 //===================================================================== 138 // Field and column classes for numeric sizes. 139 140 class BSizeField : public BField 141 { 142 public: 143 BSizeField(off_t size); 144 void SetSize(off_t); 145 off_t Size(); 146 147 private: 148 off_t fSize; 149 }; 150 151 152 //-------------------------------------------------------------------- 153 154 class BSizeColumn : public BTitledColumn 155 { 156 public: 157 BSizeColumn(const char* title, float width, 158 float minWidth, float maxWidth, 159 alignment align = B_ALIGN_LEFT); 160 virtual void DrawField(BField* field, BRect rect, BView* parent); 161 virtual int CompareFields(BField* field1, BField* field2); 162 }; 163 164 165 //===================================================================== 166 // Field and column classes for integers. 167 168 class BIntegerField : public BField 169 { 170 public: 171 BIntegerField(int32 number); 172 void SetValue(int32); 173 int32 Value(); 174 175 private: 176 int32 fInteger; 177 }; 178 179 180 //-------------------------------------------------------------------- 181 182 class BIntegerColumn : public BTitledColumn 183 { 184 public: 185 BIntegerColumn(const char* title, float width, 186 float minWidth, float maxWidth, 187 alignment align = B_ALIGN_LEFT); 188 virtual void DrawField(BField* field, BRect rect, BView* parent); 189 virtual int CompareFields(BField* field1, BField* field2); 190 }; 191 192 193 //===================================================================== 194 // Field and column classes for bitmaps 195 196 class BBitmapField : public BField 197 { 198 public: 199 BBitmapField(BBitmap* bitmap); 200 const BBitmap* Bitmap(); 201 void SetBitmap(BBitmap* bitmap); 202 203 private: 204 BBitmap* fBitmap; 205 }; 206 207 208 //-------------------------------------------------------------------- 209 210 class BBitmapColumn : public BTitledColumn 211 { 212 public: 213 BBitmapColumn(const char* title, float width, 214 float minWidth, float maxWidth, 215 alignment align = B_ALIGN_LEFT); 216 virtual void DrawField(BField* field, BRect rect, BView* parent); 217 virtual int CompareFields(BField* field1, BField* field2); 218 virtual bool AcceptsField(const BField* field) const; 219 }; 220 221 222 //===================================================================== 223 // Column to display BIntegerField objects as a graph. 224 225 class GraphColumn : public BIntegerColumn 226 { 227 public: 228 GraphColumn(const char* name, float width, 229 float minWidth, float maxWidth, 230 alignment align = B_ALIGN_LEFT); 231 virtual void DrawField(BField* field, BRect rect, BView* parent); 232 }; 233 234 235 #endif // _COLUMN_TYPES_H 236