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