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 11 enum { 12 MSG_SELECTED_OPTION_CHANGED = 'msoc' 13 }; 14 15 16 TableCellOptionPopUpEditor::TableCellOptionPopUpEditor(::Value* initialValue, 17 ValueFormatter* formatter) 18 : 19 TableCellFormattedValueEditor(initialValue, formatter), 20 BOptionPopUp("optionEditor", NULL, NULL) 21 { 22 } 23 24 25 TableCellOptionPopUpEditor::~TableCellOptionPopUpEditor() 26 { 27 } 28 29 30 status_t 31 TableCellOptionPopUpEditor::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 44 BView* 45 TableCellOptionPopUpEditor::GetView() 46 { 47 return this; 48 } 49 50 51 void 52 TableCellOptionPopUpEditor::AttachedToWindow() 53 { 54 BOptionPopUp::AttachedToWindow(); 55 56 SetTarget(this); 57 58 NotifyEditBeginning(); 59 } 60 61 62 void 63 TableCellOptionPopUpEditor::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