Files
haiku-beta6/src/apps/debugger/user_interface/gui/value/TableCellTextControlEditor.cpp
T
Rene Gollent a82499551d Debugger: Add interface subclasses for table cell editors.
TableCellTextControlEditor:
- Serves as a base for editors that expose their functionality via a
  text control. Handles common functionality of watching for changes,
  validating input, and notifying listeners appropriately.
TableCellOptionPopUpEditor:
- Serves as a base class for editors where the set of possible values
  is fixed and known up front. Handles reacting to selection changes
  and notifying listeners.
2015-06-13 16:57:13 -04:00

103 lines
1.7 KiB
C++

/*
* Copyright 2015, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "TableCellTextControlEditor.h"
#include "Value.h"
#include "ValueFormatter.h"
enum {
MSG_INPUT_VALIDATION_NEEDED = 'ivne',
MSG_TEXT_VALUE_CHANGED = 'tevc'
};
TableCellTextControlEditor::TableCellTextControlEditor(::Value* initialValue,
ValueFormatter* formatter)
:
TableCellFormattedValueEditor(initialValue, formatter),
BTextControl("", "", NULL)
{
}
TableCellTextControlEditor::~TableCellTextControlEditor()
{
}
status_t
TableCellTextControlEditor::Init()
{
BMessage* message = new(std::nothrow) BMessage(
MSG_INPUT_VALIDATION_NEEDED);
if (message == NULL)
return B_NO_MEMORY;
SetMessage(message);
message = new(std::nothrow) BMessage(MSG_TEXT_VALUE_CHANGED);
if (message == NULL)
return B_NO_MEMORY;
SetModificationMessage(message);
return B_OK;
}
BView*
TableCellTextControlEditor::GetView()
{
return this;
}
void
TableCellTextControlEditor::AttachedToWindow()
{
BTextControl::AttachedToWindow();
SetTarget(this);
BString output;
if (GetValueFormatter()->FormatValue(InitialValue(), output) == B_OK)
SetText(output);
NotifyEditBeginning();
}
void
TableCellTextControlEditor::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_TEXT_VALUE_CHANGED:
{
// TODO: highlight the input view in some way to show
// invalid inputs
break;
}
case MSG_INPUT_VALIDATION_NEEDED:
{
if (ValidateInput()) {
::Value* value = NULL;
status_t error = GetValueForInput(value);
if (error != B_OK)
break;
BReference< ::Value> valueReference(value, true);
NotifyEditCompleted(value);
}
break;
}
default:
BTextControl::MessageReceived(message);
break;
}
}