tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / time / TimeZoneListItem.cpp
blob4bcd7fdf28dad54dfa080be82f7aef2d3ba11e40
1 /*
2 * Copyright 2010-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
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"
16 #include <new>
18 #include <Bitmap.h>
19 #include <Country.h>
20 #include <ControlLook.h>
21 #include <String.h>
22 #include <TimeZone.h>
23 #include <Window.h>
26 static const BString skDefaultString;
29 TimeZoneListItem::TimeZoneListItem(const char* text, BCountry* country,
30 BTimeZone* timeZone)
32 BStringItem(text, 0, false),
33 fCountry(country),
34 fTimeZone(timeZone),
35 fIcon(NULL)
40 TimeZoneListItem::~TimeZoneListItem()
42 delete fCountry;
43 delete fTimeZone;
44 delete fIcon;
48 void
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(),
57 frame.top,
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);
63 } else
64 _DrawItemWithTextOffset(owner, frame, complete, 0);
68 void
69 TimeZoneListItem::Update(BView* owner, const BFont* font)
71 float oldIconSize = Height();
72 BStringItem::Update(owner, font);
73 if (!HasCountry())
74 return;
76 float iconSize = Height();
77 if (iconSize == oldIconSize && fIcon != NULL)
78 return;
80 SetWidth(Width() + iconSize + be_control_look->DefaultLabelSpacing());
82 delete fIcon;
83 fIcon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
84 B_RGBA32);
85 if (fIcon != NULL && fCountry->GetIcon(fIcon) != B_OK) {
86 delete fIcon;
87 fIcon = NULL;
92 void
93 TimeZoneListItem::SetCountry(BCountry* country)
95 delete fCountry;
96 fCountry = country;
100 void
101 TimeZoneListItem::SetTimeZone(BTimeZone* timeZone)
103 delete fTimeZone;
104 fTimeZone = timeZone;
108 const BString&
109 TimeZoneListItem::ID() const
111 if (!HasTimeZone())
112 return skDefaultString;
114 return fTimeZone->ID();
118 const BString&
119 TimeZoneListItem::Name() const
121 if (!HasTimeZone())
122 return skDefaultString;
124 return fTimeZone->Name();
129 TimeZoneListItem::OffsetFromGMT() const
131 if (!HasTimeZone())
132 return 0;
134 return fTimeZone->OffsetFromGMT();
138 void
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) {
146 rgb_color color;
147 if (IsSelected())
148 color = ui_color(B_LIST_SELECTED_BACKGROUND_COLOR);
149 else
150 color = owner->ViewColor();
152 owner->SetHighColor(color);
153 owner->SetLowColor(color);
154 owner->FillRect(frame);
155 } else
156 owner->SetLowColor(owner->ViewColor());
158 if (!IsEnabled()) {
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));
162 else
163 owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
164 } else {
165 if (IsSelected())
166 owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
167 else
168 owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR));
171 owner->MovePenTo(
172 frame.left + be_control_look->DefaultLabelSpacing() + textOffset,
173 frame.top + BaselineOffset());
174 owner->DrawString(Text());
176 owner->SetHighColor(highColor);
177 owner->SetLowColor(lowColor);