1 /* 2 * Copyright 2015, Rene Gollent, rene@gollent.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "TableCellEnumerationEditor.h" 7 8 #include "EnumerationValue.h" 9 #include "Type.h" 10 11 12 TableCellEnumerationEditor::TableCellEnumerationEditor(::Value* initialValue, 13 ValueFormatter* formatter) 14 : 15 TableCellOptionPopUpEditor(initialValue, formatter) 16 { 17 } 18 19 20 TableCellEnumerationEditor::~TableCellEnumerationEditor() 21 { 22 } 23 24 25 status_t 26 TableCellEnumerationEditor::ConfigureOptions() 27 { 28 EnumerationValue* initialValue = dynamic_cast<EnumerationValue*>( 29 InitialValue()); 30 if (initialValue == NULL) 31 return B_BAD_VALUE; 32 33 EnumerationType* type = initialValue->GetType(); 34 for (int32 i = 0; i < type->CountValues(); i++) { 35 EnumeratorValue* value = type->ValueAt(i); 36 BString output; 37 38 status_t error = AddOption(value->Name(), value->Value().ToInt32()); 39 if (error != B_OK) 40 return error; 41 } 42 43 BVariant integerValue; 44 if (!initialValue->ToVariant(integerValue)) 45 return B_NO_MEMORY; 46 47 SelectOptionFor(integerValue.ToInt32()); 48 49 return B_OK; 50 } 51 52 53 status_t 54 TableCellEnumerationEditor::GetSelectedValue(::Value*& _value) const 55 { 56 EnumerationValue* initialValue = dynamic_cast<EnumerationValue*>( 57 InitialValue()); 58 EnumerationType* type = initialValue->GetType(); 59 const char* name = NULL; 60 int32 selectedValue = 0; 61 SelectedOption(&name, &selectedValue); 62 63 EnumerationValue* value = new(std::nothrow) EnumerationValue(type, 64 BVariant(selectedValue)); 65 if (value == NULL) 66 return B_NO_MEMORY; 67 68 _value = value; 69 return B_OK; 70 } 71