xref: /haiku/src/apps/debugger/user_interface/gui/value/value_handlers/FloatValueHandler.cpp (revision 20df96b029ae00b592e754ff66404b12e7e12414)
1*20df96b0SRene Gollent /*
2*20df96b0SRene Gollent  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3*20df96b0SRene Gollent  * Distributed under the terms of the MIT License.
4*20df96b0SRene Gollent  */
5*20df96b0SRene Gollent 
6*20df96b0SRene Gollent 
7*20df96b0SRene Gollent #include "FloatValueHandler.h"
8*20df96b0SRene Gollent 
9*20df96b0SRene Gollent #include <new>
10*20df96b0SRene Gollent 
11*20df96b0SRene Gollent #include "FloatValue.h"
12*20df96b0SRene Gollent #include "FloatValueFormatter.h"
13*20df96b0SRene Gollent #include "TableCellFloatEditor.h"
14*20df96b0SRene Gollent #include "TableCellFormattedValueRenderer.h"
15*20df96b0SRene Gollent 
16*20df96b0SRene Gollent 
FloatValueHandler()17*20df96b0SRene Gollent FloatValueHandler::FloatValueHandler()
18*20df96b0SRene Gollent {
19*20df96b0SRene Gollent }
20*20df96b0SRene Gollent 
21*20df96b0SRene Gollent 
~FloatValueHandler()22*20df96b0SRene Gollent FloatValueHandler::~FloatValueHandler()
23*20df96b0SRene Gollent {
24*20df96b0SRene Gollent }
25*20df96b0SRene Gollent 
26*20df96b0SRene Gollent 
27*20df96b0SRene Gollent status_t
Init()28*20df96b0SRene Gollent FloatValueHandler::Init()
29*20df96b0SRene Gollent {
30*20df96b0SRene Gollent 	return B_OK;
31*20df96b0SRene Gollent }
32*20df96b0SRene Gollent 
33*20df96b0SRene Gollent 
34*20df96b0SRene Gollent float
SupportsValue(Value * value)35*20df96b0SRene Gollent FloatValueHandler::SupportsValue(Value* value)
36*20df96b0SRene Gollent {
37*20df96b0SRene Gollent 	return dynamic_cast<FloatValue*>(value) != NULL ? 0.5f : 0;
38*20df96b0SRene Gollent }
39*20df96b0SRene Gollent 
40*20df96b0SRene Gollent 
41*20df96b0SRene Gollent status_t
GetValueFormatter(Value * value,ValueFormatter * & _formatter)42*20df96b0SRene Gollent FloatValueHandler::GetValueFormatter(Value* value,
43*20df96b0SRene Gollent 	ValueFormatter*& _formatter)
44*20df96b0SRene Gollent {
45*20df96b0SRene Gollent 	if (dynamic_cast<FloatValue*>(value) == NULL)
46*20df96b0SRene Gollent 		return B_BAD_VALUE;
47*20df96b0SRene Gollent 
48*20df96b0SRene Gollent 	FloatValueFormatter* formatter = new(std::nothrow) FloatValueFormatter;
49*20df96b0SRene Gollent 	if (formatter == NULL)
50*20df96b0SRene Gollent 		return B_NO_MEMORY;
51*20df96b0SRene Gollent 
52*20df96b0SRene Gollent 	_formatter = formatter;
53*20df96b0SRene Gollent 	return B_OK;
54*20df96b0SRene Gollent }
55*20df96b0SRene Gollent 
56*20df96b0SRene Gollent 
57*20df96b0SRene Gollent status_t
GetTableCellValueRenderer(Value * value,TableCellValueRenderer * & _renderer)58*20df96b0SRene Gollent FloatValueHandler::GetTableCellValueRenderer(Value* value,
59*20df96b0SRene Gollent 	TableCellValueRenderer*& _renderer)
60*20df96b0SRene Gollent {
61*20df96b0SRene Gollent 	if (dynamic_cast<FloatValue*>(value) == NULL)
62*20df96b0SRene Gollent 		return B_BAD_VALUE;
63*20df96b0SRene Gollent 
64*20df96b0SRene Gollent 	ValueFormatter* formatter = NULL;
65*20df96b0SRene Gollent 	status_t error = GetValueFormatter(value, formatter);
66*20df96b0SRene Gollent 	if (error != B_OK)
67*20df96b0SRene Gollent 		return error;
68*20df96b0SRene Gollent 	BReference<ValueFormatter> formatterReference(formatter, true);
69*20df96b0SRene Gollent 
70*20df96b0SRene Gollent 	// create the renderer
71*20df96b0SRene Gollent 	TableCellValueRenderer* renderer
72*20df96b0SRene Gollent 		= new(std::nothrow) TableCellFormattedValueRenderer(formatter);
73*20df96b0SRene Gollent 	if (renderer == NULL)
74*20df96b0SRene Gollent 		return B_NO_MEMORY;
75*20df96b0SRene Gollent 
76*20df96b0SRene Gollent 	_renderer = renderer;
77*20df96b0SRene Gollent 	return B_OK;
78*20df96b0SRene Gollent }
79*20df96b0SRene Gollent 
80*20df96b0SRene Gollent 
81*20df96b0SRene Gollent status_t
GetTableCellValueEditor(Value * _value,Settings * settings,TableCellValueEditor * & _editor)82*20df96b0SRene Gollent FloatValueHandler::GetTableCellValueEditor(Value* _value, Settings* settings,
83*20df96b0SRene Gollent 	TableCellValueEditor*& _editor)
84*20df96b0SRene Gollent {
85*20df96b0SRene Gollent 	FloatValue* value = dynamic_cast<FloatValue*>(_value);
86*20df96b0SRene Gollent 	if (value == NULL)
87*20df96b0SRene Gollent 		return B_BAD_VALUE;
88*20df96b0SRene Gollent 
89*20df96b0SRene Gollent 	ValueFormatter* formatter;
90*20df96b0SRene Gollent 	status_t error = GetValueFormatter(value, formatter);
91*20df96b0SRene Gollent 	if (error != B_OK)
92*20df96b0SRene Gollent 		return error;
93*20df96b0SRene Gollent 	BReference<ValueFormatter> formatterReference(formatter, true);
94*20df96b0SRene Gollent 
95*20df96b0SRene Gollent 	TableCellFloatEditor* editor = new(std::nothrow)
96*20df96b0SRene Gollent 		TableCellFloatEditor(value, formatter);
97*20df96b0SRene Gollent 	if (editor == NULL)
98*20df96b0SRene Gollent 		return B_NO_MEMORY;
99*20df96b0SRene Gollent 
100*20df96b0SRene Gollent 	BReference<TableCellFloatEditor> editorReference(editor, true);
101*20df96b0SRene Gollent 	error = editor->Init();
102*20df96b0SRene Gollent 	if (error != B_OK)
103*20df96b0SRene Gollent 		return error;
104*20df96b0SRene Gollent 
105*20df96b0SRene Gollent 	editorReference.Detach();
106*20df96b0SRene Gollent 	_editor = editor;
107*20df96b0SRene Gollent 	return B_OK;
108*20df96b0SRene Gollent }
109