tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / time / TZDisplay.cpp
blob1981ac27ef947f7ad988cd9685144b8420cec336
1 /*
2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Andrew McCall <mccall@@digitalparadise.co.uk>
7 * Mike Berg <mike@berg-net.us>
8 * Julun <host.haiku@gmx.de>
9 * Hamish Morrison <hamish@lavabit.com>
12 #include "TZDisplay.h"
14 #include <stdio.h>
16 #include <LayoutUtils.h>
20 TTZDisplay::TTZDisplay(const char* name, const char* label)
22 BView(name, B_WILL_DRAW),
23 fLabel(label),
24 fText(""),
25 fTime("")
30 TTZDisplay::~TTZDisplay()
35 void
36 TTZDisplay::AttachedToWindow()
38 if (Parent())
39 SetViewColor(Parent()->ViewColor());
43 void
44 TTZDisplay::ResizeToPreferred()
46 BSize size = _CalcPrefSize();
47 ResizeTo(size.width, size.height);
51 void
52 TTZDisplay::Draw(BRect)
54 SetLowColor(ViewColor());
56 BRect bounds = Bounds();
57 FillRect(Bounds(), B_SOLID_LOW);
59 font_height height;
60 GetFontHeight(&height);
61 float fontHeight = ceilf(height.descent + height.ascent +
62 height.leading);
64 BPoint pt(bounds.left, ceilf(bounds.top + height.ascent));
65 DrawString(fLabel.String(), pt);
67 pt.y += fontHeight;
68 DrawString(fText.String(), pt);
70 pt.y -= fontHeight;
71 pt.x = bounds.right - StringWidth(fTime.String());
72 DrawString(fTime.String(), pt);
76 const char*
77 TTZDisplay::Label() const
79 return fLabel.String();
83 void
84 TTZDisplay::SetLabel(const char* label)
86 fLabel.SetTo(label);
87 Invalidate();
88 InvalidateLayout();
92 const char*
93 TTZDisplay::Text() const
95 return fText.String();
99 void
100 TTZDisplay::SetText(const char* text)
102 fText.SetTo(text);
103 Invalidate();
104 InvalidateLayout();
108 const char*
109 TTZDisplay::Time() const
111 return fTime.String();
115 void
116 TTZDisplay::SetTime(const char* time)
118 fTime.SetTo(time);
119 Invalidate();
120 InvalidateLayout();
124 BSize
125 TTZDisplay::MaxSize()
127 BSize size = _CalcPrefSize();
128 size.width = B_SIZE_UNLIMITED;
130 return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
131 size);
135 BSize
136 TTZDisplay::MinSize()
138 return BLayoutUtils::ComposeSize(ExplicitMinSize(),
139 _CalcPrefSize());
143 BSize
144 TTZDisplay::PreferredSize()
146 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
147 _CalcPrefSize());
151 BSize
152 TTZDisplay::_CalcPrefSize()
154 font_height fontHeight;
155 GetFontHeight(&fontHeight);
157 BSize size;
158 size.height = 2 * ceilf(fontHeight.ascent + fontHeight.descent +
159 fontHeight.leading);
161 // Add a little padding
162 float padding = 10.0;
163 float firstLine = ceilf(StringWidth(fLabel.String()) +
164 StringWidth(" ") + StringWidth(fTime.String()) + padding);
165 float secondLine = ceilf(StringWidth(fText.String()) + padding);
166 size.width = firstLine > secondLine ? firstLine : secondLine;
168 return size;