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