1/* 2 * Copyright 2015, Rene Gollent, rene@gollent.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include "TableCellOptionPopUpEditor.h" 7 8#include "Value.h" 9 10 11enum { 12 MSG_SELECTED_OPTION_CHANGED = 'msoc' 13}; 14 15 16TableCellOptionPopUpEditor::TableCellOptionPopUpEditor(::Value* initialValue, 17 ValueFormatter* formatter) 18 : 19 TableCellFormattedValueEditor(initialValue, formatter), 20 BOptionPopUp("optionEditor", NULL, NULL) 21{ 22} 23 24 25TableCellOptionPopUpEditor::~TableCellOptionPopUpEditor() 26{ 27} 28 29 30status_t 31TableCellOptionPopUpEditor::Init() 32{ 33 BMessage* message = new(std::nothrow) BMessage( 34 MSG_SELECTED_OPTION_CHANGED); 35 if (message == NULL) 36 return B_NO_MEMORY; 37 38 SetMessage(message); 39 40 return ConfigureOptions(); 41} 42 43 44BView* 45TableCellOptionPopUpEditor::GetView() 46{ 47 return this; 48} 49 50 51void 52TableCellOptionPopUpEditor::AttachedToWindow() 53{ 54 BOptionPopUp::AttachedToWindow(); 55 56 SetTarget(this); 57 58 NotifyEditBeginning(); 59} 60 61 62void 63TableCellOptionPopUpEditor::MessageReceived(BMessage* message) 64{ 65 switch (message->what) { 66 case MSG_SELECTED_OPTION_CHANGED: 67 { 68 ::Value* value = NULL; 69 if (GetSelectedValue(value) == B_OK) { 70 BReference< ::Value> valueReference(value, true); 71 NotifyEditCompleted(value); 72 } else 73 NotifyEditCancelled(); 74 75 break; 76 } 77 default: 78 BOptionPopUp::MessageReceived(message); 79 break; 80 } 81} 82