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.
This commit is contained in:
Rene Gollent 2015-06-03 19:10:56 -04:00
parent 5f5499b40b
commit a82499551d
7 changed files with 305 additions and 0 deletions

View File

@ -300,7 +300,11 @@ Application Debugger :
WatchPromptWindow.cpp
# user_interface/gui/value
TableCellFormattedValueEditor.cpp
TableCellFormattedValueRenderer.cpp
TableCellOptionPopUpEditor.cpp
TableCellTextControlEditor.cpp
TableCellValueEditor.cpp
TableCellValueRenderer.cpp
TableCellValueRendererUtils.cpp

View File

@ -0,0 +1,25 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TableCellFormattedValueEditor.h"
#include "ValueFormatter.h"
TableCellFormattedValueEditor::TableCellFormattedValueEditor(
Value* initialValue, ValueFormatter* formatter)
:
TableCellValueEditor(),
fValueFormatter(formatter)
{
SetInitialValue(initialValue);
fValueFormatter->AcquireReference();
}
TableCellFormattedValueEditor::~TableCellFormattedValueEditor()
{
fValueFormatter->ReleaseReference();
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TABLE_CELL_FORMATTED_VALUE_EDITOR_H
#define TABLE_CELL_FORMATTED_VALUE_EDITOR_H
#include "TableCellValueEditor.h"
class ValueFormatter;
class TableCellFormattedValueEditor : public TableCellValueEditor {
public:
TableCellFormattedValueEditor(
Value* initialValue,
ValueFormatter* formatter);
virtual ~TableCellFormattedValueEditor();
protected:
ValueFormatter* GetValueFormatter() const
{ return fValueFormatter; }
private:
ValueFormatter* fValueFormatter;
};
#endif // TABLE_CELL_FORMATTED_VALUE_EDITOR_H

View File

@ -0,0 +1,75 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TableCellOptionPopUpEditor.h"
#include "Value.h"
enum {
MSG_SELECTED_OPTION_CHANGED = 'msoc'
};
TableCellOptionPopUpEditor::TableCellOptionPopUpEditor(::Value* initialValue,
ValueFormatter* formatter)
:
TableCellFormattedValueEditor(initialValue, formatter),
BOptionPopUp("optionEditor", NULL, NULL)
{
}
TableCellOptionPopUpEditor::~TableCellOptionPopUpEditor()
{
}
status_t
TableCellOptionPopUpEditor::Init()
{
BMessage* message = new(std::nothrow) BMessage(
MSG_SELECTED_OPTION_CHANGED);
if (message == NULL)
return B_NO_MEMORY;
SetMessage(message);
return ConfigureOptions();
}
BView*
TableCellOptionPopUpEditor::GetView()
{
return this;
}
void
TableCellOptionPopUpEditor::AttachedToWindow()
{
BOptionPopUp::AttachedToWindow();
SetTarget(this);
NotifyEditBeginning();
}
void
TableCellOptionPopUpEditor::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_SELECTED_OPTION_CHANGED:
{
// TODO: implement
break;
}
default:
BOptionPopUp::MessageReceived(message);
break;
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TABLE_CELL_OPTION_POPUP_EDITOR_H
#define TABLE_CELL_OPTION_POPUP_EDITOR_H
#include <OptionPopUp.h>
#include "TableCellFormattedValueEditor.h"
// common base class for editors that have a fixed set of chooseable
// values known up front
class TableCellOptionPopUpEditor : public TableCellFormattedValueEditor,
protected BOptionPopUp {
public:
TableCellOptionPopUpEditor(
::Value* initialValue,
ValueFormatter* formatter);
virtual ~TableCellOptionPopUpEditor();
status_t Init();
virtual BView* GetView();
virtual status_t ConfigureOptions() = 0;
protected:
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
};
#endif // TABLE_CELL_TEXT_CONTROL_EDITOR_H

View File

@ -0,0 +1,102 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* 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;
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TABLE_CELL_TEXT_CONTROL_EDITOR_H
#define TABLE_CELL_TEXT_CONTROL_EDITOR_H
#include <TextControl.h>
#include "TableCellFormattedValueEditor.h"
// common base class for editors that input a value via a text field
class TableCellTextControlEditor : public TableCellFormattedValueEditor,
protected BTextControl {
public:
TableCellTextControlEditor(
::Value* initialValue,
ValueFormatter* formatter);
virtual ~TableCellTextControlEditor();
status_t Init();
virtual BView* GetView();
virtual bool ValidateInput() const = 0;
virtual status_t GetValueForInput(::Value*& _output) const = 0;
// returns reference
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
};
#endif // TABLE_CELL_TEXT_CONTROL_EDITOR_H