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 const char* ClippedString (); 64 void SetWidth (float); 65 float Width (); 66 67 private: 68 float fWidth; 69 BString fString; 70 BString fClippedString; 71 }; 72 73 74 //-------------------------------------------------------------------- 75 76 class BStringColumn : public BTitledColumn 77 { 78 public: 79 BStringColumn (const char *title, 80 float width, 81 float minWidth, 82 float maxWidth, 83 uint32 truncate, 84 alignment align = B_ALIGN_LEFT); 85 virtual void DrawField (BField* field, 86 BRect rect, 87 BView* parent); 88 virtual int CompareFields (BField* field1, 89 BField* field2); 90 virtual float GetPreferredWidth(BField* field, BView* parent) const; 91 virtual bool AcceptsField (const BField* field) const; 92 93 private: 94 uint32 fTruncate; 95 }; 96 97 98 //===================================================================== 99 // Field and column classes for dates. 100 101 class BDateField : public BField 102 { 103 public: 104 BDateField (time_t* t); 105 void SetWidth (float); 106 float Width (); 107 void SetClippedString (const char*); 108 const char* ClippedString (); 109 time_t Seconds (); 110 time_t UnixTime (); 111 112 private: 113 struct tm fTime; 114 time_t fUnixTime; 115 time_t fSeconds; 116 BString fClippedString; 117 float fWidth; 118 }; 119 120 121 //-------------------------------------------------------------------- 122 123 class BDateColumn : public BTitledColumn 124 { 125 public: 126 BDateColumn (const char* title, 127 float width, 128 float minWidth, 129 float maxWidth, 130 alignment align = B_ALIGN_LEFT); 131 virtual void DrawField (BField* field, 132 BRect rect, 133 BView* parent); 134 virtual int CompareFields (BField* field1, 135 BField* field2); 136 private: 137 BString fTitle; 138 }; 139 140 141 //===================================================================== 142 // Field and column classes for numeric sizes. 143 144 class BSizeField : public BField 145 { 146 public: 147 BSizeField (off_t size); 148 void SetSize (off_t); 149 off_t Size (); 150 151 private: 152 off_t fSize; 153 }; 154 155 156 //-------------------------------------------------------------------- 157 158 class BSizeColumn : public BTitledColumn 159 { 160 public: 161 BSizeColumn (const char* title, 162 float width, 163 float minWidth, 164 float maxWidth, 165 alignment align = B_ALIGN_LEFT); 166 virtual void DrawField (BField* field, 167 BRect rect, 168 BView* parent); 169 virtual int CompareFields (BField* field1, 170 BField* field2); 171 }; 172 173 174 //===================================================================== 175 // Field and column classes for integers. 176 177 class BIntegerField : public BField 178 { 179 public: 180 BIntegerField (int32 number); 181 void SetValue (int32); 182 int32 Value (); 183 184 private: 185 int32 fInteger; 186 }; 187 188 189 //-------------------------------------------------------------------- 190 191 class BIntegerColumn : public BTitledColumn 192 { 193 public: 194 BIntegerColumn (const char* title, 195 float width, 196 float minWidth, 197 float maxWidth, 198 alignment align = B_ALIGN_LEFT); 199 virtual void DrawField (BField* field, 200 BRect rect, 201 BView* parent); 202 virtual int CompareFields (BField* field1, 203 BField* field2); 204 }; 205 206 207 //===================================================================== 208 // Field and column classes for bitmaps 209 210 class BBitmapField : public BField 211 { 212 public: 213 BBitmapField (BBitmap* bitmap); 214 const BBitmap* Bitmap (); 215 void SetBitmap (BBitmap* bitmap); 216 217 private: 218 BBitmap* fBitmap; 219 }; 220 221 222 //-------------------------------------------------------------------- 223 224 class BBitmapColumn : public BTitledColumn 225 { 226 public: 227 BBitmapColumn (const char* title, 228 float width, 229 float minWidth, 230 float maxWidth, 231 alignment align = B_ALIGN_LEFT); 232 virtual void DrawField (BField*field, 233 BRect rect, 234 BView* parent); 235 virtual int CompareFields (BField* field1, BField* field2); 236 virtual bool AcceptsField (const BField* field) const; 237 }; 238 239 240 //===================================================================== 241 // Column to display BIntegerField objects as a graph. 242 243 class GraphColumn : public BIntegerColumn 244 { 245 public: 246 GraphColumn (const char* name, 247 float width, 248 float minWidth, 249 float maxWidth, 250 alignment align = B_ALIGN_LEFT); 251 virtual void DrawField (BField*field, 252 BRect rect, 253 BView* parent); 254 }; 255 256 #endif 257 258