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