1/*
2 * Copyright 2009-2018, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
4 *
5 * Authors:
6 *		Rene Gollent
7 *		Philippe Houdoin
8 */
9#ifndef TEAMS_LIST_ITEM_H
10#define TEAMS_LIST_ITEM_H
11
12#include <ColumnListView.h>
13#include <ColumnTypes.h>
14#include <OS.h>
15
16#include "TargetHost.h"
17#include "TeamInfo.h"
18#include "TeamsWindow.h"
19
20
21class BBitmap;
22class TargetHostInterface;
23
24
25// A field type displaying both a bitmap and a string so that the
26// tree display looks nicer (both text and bitmap are indented)
27class BBitmapStringField : public BStringField {
28	typedef BStringField Inherited;
29public:
30								BBitmapStringField(BBitmap* bitmap,
31									const char* string);
32	virtual						~BBitmapStringField();
33
34			void				SetBitmap(BBitmap* bitmap);
35			const BBitmap*		Bitmap() const
36									{ return fBitmap; }
37
38private:
39			BBitmap*			fBitmap;
40};
41
42
43// BColumn for TeamsListView which knows how to render
44// a BBitmapStringField
45class TeamsColumn : public BTitledColumn {
46	typedef BTitledColumn Inherited;
47public:
48								TeamsColumn(const char* title,
49									float width, float minWidth,
50									float maxWidth, uint32 truncateMode,
51									alignment align = B_ALIGN_LEFT);
52
53	virtual	void				DrawField(BField* field, BRect rect,
54									BView* parent);
55	virtual float				GetPreferredWidth(BField* field, BView* parent) const;
56
57	virtual	bool				AcceptsField(const BField* field) const;
58
59	static	void				InitTextMargin(BView* parent);
60
61private:
62			uint32				fTruncateMode;
63	static	float				sTextMargin;
64};
65
66
67
68class TeamRow : public BRow {
69	typedef BRow Inherited;
70public:
71								TeamRow(TeamInfo* teamInfo);
72
73public:
74			team_id				TeamID() const
75									{ return fTeamInfo.TeamID(); }
76
77			bool				NeedsUpdate(TeamInfo* info);
78
79	virtual	void				SetEnabled(bool enabled)
80									{ fEnabled = enabled; }
81			bool				IsEnabled() const
82									{ return fEnabled; }
83
84private:
85			status_t			_SetTo(TeamInfo* info);
86
87private:
88			bool				fEnabled;
89			TeamInfo			fTeamInfo;
90};
91
92
93class TeamsListView : public BColumnListView, public TargetHost::Listener,
94	public TeamsWindow::Listener {
95	typedef BColumnListView Inherited;
96public:
97								TeamsListView(const char* name);
98	virtual 					~TeamsListView();
99
100			TeamRow* 			FindTeamRow(team_id teamId);
101
102			// TargetHost::Listener
103	virtual	void				TeamAdded(TeamInfo* info);
104	virtual	void				TeamRemoved(team_id team);
105	virtual	void				TeamRenamed(TeamInfo* info);
106
107			// TeamsWindow::Listener
108	virtual	void				SelectedInterfaceChanged(
109									TargetHostInterface* interface);
110
111protected:
112	virtual void 				AttachedToWindow();
113	virtual void 				DetachedFromWindow();
114
115	virtual void 				MessageReceived(BMessage* message);
116
117private:
118			void 				_InitList();
119			void				_SetInterface(TargetHostInterface* interface);
120
121private:
122			TargetHostInterface* fInterface;
123			TargetHost*			fHost;
124};
125
126
127#endif	// TEAMS_LIST_VIEW_H
128