Files
haiku-beta6/src/apps/people/TTextControl.cpp
T

81 lines
1.4 KiB
C++
Raw Normal View History

2002-10-26 03:33:06 +00:00
//--------------------------------------------------------------------
//
// TTextControl.cpp
//
// Written by: Robert Polic
//
//--------------------------------------------------------------------
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include <string.h>
#include <malloc.h>
#include <Font.h>
#include "TTextControl.h"
2005-06-15 03:18:00 +00:00
TTextControl::TTextControl(BRect r, const char *label, int32 offset,
const char *text, int32 modificationMessage, int32 msg)
: BTextControl(r, "", "", text, new BMessage(msg))
2002-10-26 03:33:06 +00:00
{
2005-06-15 03:18:00 +00:00
SetModificationMessage(new BMessage(modificationMessage));
if (label[0]) {
char newLabel[B_FILE_NAME_LENGTH];
int32 length = strlen(label);
memcpy(newLabel, label, length);
newLabel[length] = ':';
newLabel[length + 1] = '\0';
SetLabel(newLabel);
}
SetDivider(offset);
SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
if (text == NULL)
text = "";
fOriginal = strdup(text);
2002-10-26 03:33:06 +00:00
}
TTextControl::~TTextControl(void)
{
free(fOriginal);
}
2005-06-15 03:18:00 +00:00
void
TTextControl::AttachedToWindow(void)
2002-10-26 03:33:06 +00:00
{
BTextControl::AttachedToWindow();
2005-06-15 03:18:00 +00:00
BTextView* text = (BTextView *)ChildAt(0);
text->SetMaxBytes(255);
2002-10-26 03:33:06 +00:00
}
2005-06-15 03:18:00 +00:00
bool
TTextControl::Changed(void)
2002-10-26 03:33:06 +00:00
{
return strcmp(fOriginal, Text());
}
2005-06-15 03:18:00 +00:00
void
TTextControl::Revert(void)
2002-10-26 03:33:06 +00:00
{
if (Changed())
SetText(fOriginal);
}
2005-06-15 03:18:00 +00:00
void
TTextControl::Update(void)
2002-10-26 03:33:06 +00:00
{
fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
strcpy(fOriginal, Text());
}