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