vfs: check userland buffers before reading them.
[haiku.git] / src / apps / debugger / user_interface / gui / value / TableCellTextControlEditor.cpp
blob79a310693c2efc81dff254a79a135cb0e33df8fb
1 /*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "TableCellTextControlEditor.h"
8 #include "Value.h"
9 #include "ValueFormatter.h"
12 enum {
13 MSG_INPUT_VALIDATION_NEEDED = 'ivne',
14 MSG_TEXT_VALUE_CHANGED = 'tevc'
18 TableCellTextControlEditor::TableCellTextControlEditor(::Value* initialValue,
19 ValueFormatter* formatter)
21 TableCellFormattedValueEditor(initialValue, formatter),
22 BTextControl("", "", NULL)
27 TableCellTextControlEditor::~TableCellTextControlEditor()
32 status_t
33 TableCellTextControlEditor::Init()
35 BMessage* message = new(std::nothrow) BMessage(
36 MSG_INPUT_VALIDATION_NEEDED);
37 if (message == NULL)
38 return B_NO_MEMORY;
40 SetMessage(message);
42 message = new(std::nothrow) BMessage(MSG_TEXT_VALUE_CHANGED);
43 if (message == NULL)
44 return B_NO_MEMORY;
46 SetModificationMessage(message);
48 return B_OK;
52 BView*
53 TableCellTextControlEditor::GetView()
55 return this;
59 void
60 TableCellTextControlEditor::AttachedToWindow()
62 BTextControl::AttachedToWindow();
64 SetTarget(this);
66 BString output;
68 if (GetValueFormatter()->FormatValue(InitialValue(), output) == B_OK)
69 SetText(output);
71 NotifyEditBeginning();
75 void
76 TableCellTextControlEditor::MessageReceived(BMessage* message)
78 switch (message->what) {
79 case MSG_TEXT_VALUE_CHANGED:
81 // TODO: highlight the input view in some way to show
82 // invalid inputs
84 // fall through
86 case MSG_INPUT_VALIDATION_NEEDED:
88 if (ValidateInput()) {
89 ::Value* value = NULL;
90 status_t error = GetValueForInput(value);
91 if (error != B_OK)
92 break;
94 BReference< ::Value> valueReference(value, true);
95 NotifyEditCompleted(value);
97 break;
99 default:
100 BTextControl::MessageReceived(message);
101 break;