2 * Copyright 2010-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus, superstippi@gmx.de
7 * Adrien Destugues, pulkomandy@pulkomandy.ath.cx
8 * Axel Dörfler, axeld@pinc-software.de
9 * John Scipione, jscipione@gmail.com
10 * Oliver Tappe, zooey@hirschkaefer.de
14 #include "TimeZoneListItem.h"
20 #include <ControlLook.h>
26 static const BString skDefaultString
;
29 TimeZoneListItem::TimeZoneListItem(const char* text
, BCountry
* country
,
32 BStringItem(text
, 0, false),
40 TimeZoneListItem::~TimeZoneListItem()
49 TimeZoneListItem::DrawItem(BView
* owner
, BRect frame
, bool complete
)
51 if (fIcon
!= NULL
&& fIcon
->IsValid()) {
52 float iconSize
= fIcon
->Bounds().Width();
53 _DrawItemWithTextOffset(owner
, frame
, complete
,
54 iconSize
+ be_control_look
->DefaultLabelSpacing());
56 BRect
iconFrame(frame
.left
+ be_control_look
->DefaultLabelSpacing(),
58 frame
.left
+ iconSize
- 1 + be_control_look
->DefaultLabelSpacing(),
59 frame
.top
+ iconSize
- 1);
60 owner
->SetDrawingMode(B_OP_OVER
);
61 owner
->DrawBitmap(fIcon
, iconFrame
);
62 owner
->SetDrawingMode(B_OP_COPY
);
64 _DrawItemWithTextOffset(owner
, frame
, complete
, 0);
69 TimeZoneListItem::Update(BView
* owner
, const BFont
* font
)
71 float oldIconSize
= Height();
72 BStringItem::Update(owner
, font
);
76 float iconSize
= Height();
77 if (iconSize
== oldIconSize
&& fIcon
!= NULL
)
80 SetWidth(Width() + iconSize
+ be_control_look
->DefaultLabelSpacing());
83 fIcon
= new(std::nothrow
) BBitmap(BRect(0, 0, iconSize
- 1, iconSize
- 1),
85 if (fIcon
!= NULL
&& fCountry
->GetIcon(fIcon
) != B_OK
) {
93 TimeZoneListItem::SetCountry(BCountry
* country
)
101 TimeZoneListItem::SetTimeZone(BTimeZone
* timeZone
)
104 fTimeZone
= timeZone
;
109 TimeZoneListItem::ID() const
112 return skDefaultString
;
114 return fTimeZone
->ID();
119 TimeZoneListItem::Name() const
122 return skDefaultString
;
124 return fTimeZone
->Name();
129 TimeZoneListItem::OffsetFromGMT() const
134 return fTimeZone
->OffsetFromGMT();
139 TimeZoneListItem::_DrawItemWithTextOffset(BView
* owner
, BRect frame
,
140 bool complete
, float textOffset
)
142 rgb_color highColor
= owner
->HighColor();
143 rgb_color lowColor
= owner
->LowColor();
145 if (IsSelected() || complete
) {
148 color
= ui_color(B_LIST_SELECTED_BACKGROUND_COLOR
);
150 color
= owner
->ViewColor();
152 owner
->SetHighColor(color
);
153 owner
->SetLowColor(color
);
154 owner
->FillRect(frame
);
156 owner
->SetLowColor(owner
->ViewColor());
159 rgb_color textColor
= ui_color(B_LIST_ITEM_TEXT_COLOR
);
160 if (textColor
.red
+ textColor
.green
+ textColor
.blue
> 128 * 3)
161 owner
->SetHighColor(tint_color(textColor
, B_DARKEN_2_TINT
));
163 owner
->SetHighColor(tint_color(textColor
, B_LIGHTEN_2_TINT
));
166 owner
->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR
));
168 owner
->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR
));
172 frame
.left
+ be_control_look
->DefaultLabelSpacing() + textOffset
,
173 frame
.top
+ BaselineOffset());
174 owner
->DrawString(Text());
176 owner
->SetHighColor(highColor
);
177 owner
->SetLowColor(lowColor
);