* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "StringTextView.h"
#include <stdio.h>
#include <stdlib.h>
StringTextView::StringTextView(BRect frame, const char* name,
BRect textRect,
uint32 resizingMode,
uint32 flags)
: InputTextView(frame, name, textRect, resizingMode, flags),
fStringCache("")
{
}
StringTextView::~StringTextView()
{
}
status_t
StringTextView::Invoke(BMessage* message)
{
if (!message)
message = Message();
if (message) {
BMessage copy(*message);
copy.AddString("value", Value());
return InputTextView::Invoke(©);
}
return B_BAD_VALUE;
}
void
StringTextView::RevertChanges()
{
SetValue(fStringCache.String());
}
void
StringTextView::ApplyChanges()
{
if (fStringCache != Text()) {
Invoke();
}
}
void
StringTextView::SetValue(const char* string)
{
SetText(string);
Value();
if (IsFocus())
SelectAll();
}
const char*
StringTextView::Value() const
{
fStringCache = Text();
return fStringCache.String();
}