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