1 /* 2 * Copyright 2010-2015, Rene Gollent, rene@gollent.com 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "StringValueHandler.h" 8 9 #include <new> 10 11 #include "StringValue.h" 12 #include "StringValueFormatter.h" 13 #include "TableCellFormattedValueRenderer.h" 14 15 StringValueHandler()16StringValueHandler::StringValueHandler() 17 { 18 } 19 20 ~StringValueHandler()21StringValueHandler::~StringValueHandler() 22 { 23 } 24 25 26 status_t Init()27StringValueHandler::Init() 28 { 29 return B_OK; 30 } 31 32 33 float SupportsValue(Value * value)34StringValueHandler::SupportsValue(Value* value) 35 { 36 return dynamic_cast<StringValue*>(value) != NULL ? 0.8f : 0; 37 } 38 39 40 status_t GetValueFormatter(Value * value,ValueFormatter * & _formatter)41StringValueHandler::GetValueFormatter(Value* value, 42 ValueFormatter*& _formatter) 43 { 44 if (dynamic_cast<StringValue*>(value) == NULL) 45 return B_BAD_VALUE; 46 47 ValueFormatter* formatter = new(std::nothrow) StringValueFormatter; 48 if (formatter == NULL) 49 return B_NO_MEMORY; 50 51 _formatter = formatter; 52 return B_OK; 53 } 54 55 56 status_t GetTableCellValueRenderer(Value * value,TableCellValueRenderer * & _renderer)57StringValueHandler::GetTableCellValueRenderer(Value* value, 58 TableCellValueRenderer*& _renderer) 59 { 60 if (dynamic_cast<StringValue*>(value) == NULL) 61 return B_BAD_VALUE; 62 63 ValueFormatter* formatter = NULL; 64 status_t error = GetValueFormatter(value, formatter); 65 if (error != B_OK) 66 return error; 67 BReference<ValueFormatter> formatterReference(formatter, true); 68 69 // create the renderer 70 TableCellValueRenderer* renderer 71 = new(std::nothrow) TableCellFormattedValueRenderer(formatter); 72 if (renderer == NULL) 73 return B_NO_MEMORY; 74 75 _renderer = renderer; 76 return B_OK; 77 } 78