1 /*
2 * Copyright 2014-2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
6
7
8 #include "TableCellFormattedValueRenderer.h"
9
10 #include <String.h>
11
12 #include "TableCellValueRendererUtils.h"
13 #include "ValueFormatter.h"
14
15
TableCellFormattedValueRenderer(ValueFormatter * formatter)16 TableCellFormattedValueRenderer::TableCellFormattedValueRenderer(
17 ValueFormatter* formatter)
18 :
19 fValueFormatter(formatter)
20 {
21 fValueFormatter->AcquireReference();
22 }
23
24
~TableCellFormattedValueRenderer()25 TableCellFormattedValueRenderer::~TableCellFormattedValueRenderer()
26 {
27 fValueFormatter->ReleaseReference();
28 }
29
30
31 Settings*
GetSettings() const32 TableCellFormattedValueRenderer::GetSettings() const
33 {
34 return fValueFormatter->GetSettings();
35 }
36
37
38 void
RenderValue(Value * value,bool valueChanged,BRect rect,BView * targetView)39 TableCellFormattedValueRenderer::RenderValue(Value* value, bool valueChanged,
40 BRect rect, BView* targetView)
41 {
42 BString output;
43
44 if (fValueFormatter->FormatValue(value, output) != B_OK)
45 return;
46
47 // render
48 TableCellValueRendererUtils::DrawString(targetView, rect, output,
49 valueChanged, B_ALIGN_RIGHT, true);
50 }
51
52
53 float
PreferredValueWidth(Value * value,BView * targetView)54 TableCellFormattedValueRenderer::PreferredValueWidth(Value* value, BView* targetView)
55 {
56 BString output;
57
58 if (fValueFormatter->FormatValue(value, output) != B_OK)
59 return 0;
60
61 // render
62 return TableCellValueRendererUtils::PreferredStringWidth(targetView,
63 output);
64 }
65