xref: /haiku/src/apps/drivesetup/PartitionList.h (revision a4ef4a49150f118d47324242917a596a3f8f8bd5)
1 /*
2  * Copyright 2006-2008 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Ithamar R. Adema <ithamar@unet.nl>
7  *		James Urquhart
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 #ifndef PARTITIONLIST_H
11 #define PARTITIONLIST_H
12 
13 
14 #include <ColumnListView.h>
15 #include <ColumnTypes.h>
16 #include <Partition.h>
17 
18 
19 class BPartition;
20 
21 
22 // A field type displaying both a bitmap and a string so that the
23 // tree display looks nicer (both text and bitmap are indented)
24 class BBitmapStringField : public BStringField {
25 	typedef BStringField Inherited;
26 public:
27 								BBitmapStringField(BBitmap* bitmap,
28 									const char* string);
29 	virtual						~BBitmapStringField();
30 
31 			void				SetBitmap(BBitmap* bitmap);
32 			const BBitmap*		Bitmap() const
33 									{ return fBitmap; }
34 
35 private:
36 			BBitmap*			fBitmap;
37 };
38 
39 
40 // BColumn for PartitionListView which knows how to render
41 // a BBitmapStringField
42 class PartitionColumn : public BTitledColumn {
43 	typedef BTitledColumn Inherited;
44 public:
45 								PartitionColumn(const char* title,
46 									float width, float minWidth,
47 									float maxWidth, uint32 truncateMode,
48 									alignment align = B_ALIGN_LEFT);
49 
50 	virtual	void				DrawField(BField* field, BRect rect,
51 									BView* parent);
52 	virtual float				GetPreferredWidth(BField* field, BView* parent) const;
53 
54 	virtual	bool				AcceptsField(const BField* field) const;
55 
56 private:
57 			uint32				fTruncateMode;
58 	static	float				fTextMargin;
59 };
60 
61 
62 // BRow for the PartitionListView
63 class PartitionListRow : public BRow {
64 	typedef BRow Inherited;
65 public:
66 								PartitionListRow(BPartition* partition);
67 								PartitionListRow(partition_id parentID,
68 									partition_id id, off_t offset, off_t size);
69 
70 			partition_id		ID() const
71 									{ return fPartitionID; }
72 			partition_id		ParentID() const
73 									{ return fParentID; }
74 			off_t				Offset() const
75 									{ return fOffset; }
76 			off_t				Size() const
77 									{ return fSize; }
78 private:
79 			partition_id		fPartitionID;
80 			partition_id		fParentID;
81 			off_t				fOffset;
82 			off_t				fSize;
83 };
84 
85 
86 class PartitionListView : public BColumnListView {
87 	typedef BColumnListView Inherited;
88 public:
89 								PartitionListView(const BRect& frame,
90 									uint32 resizeMode);
91 
92 			PartitionListRow*	FindRow(partition_id id,
93 									PartitionListRow* parent = NULL);
94 			PartitionListRow*	AddPartition(BPartition* partition);
95 			PartitionListRow*	AddSpace(partition_id parent,
96 									partition_id id, off_t offset, off_t size);
97 
98 private:
99 			int32				_InsertIndexForOffset(PartitionListRow* parent,
100 									off_t offset) const;
101 };
102 
103 
104 #endif // PARTITIONLIST_H
105