Fixes
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3536 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -46,27 +46,36 @@ class BTextControl;
|
|||||||
// _BTextInput_ class ----------------------------------------------------------
|
// _BTextInput_ class ----------------------------------------------------------
|
||||||
class _BTextInput_ : public BTextView {
|
class _BTextInput_ : public BTextView {
|
||||||
public:
|
public:
|
||||||
_BTextInput_(BTextControl* parent, BRect frame,
|
_BTextInput_(BRect frame, BRect textRect,
|
||||||
const char* name, BRect rect,
|
uint32 resizeMask,
|
||||||
uint32 mask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED);
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
_BTextInput_(BMessage *data);
|
||||||
~_BTextInput_();
|
~_BTextInput_();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
static BArchivable* Instantiate(BMessage *data);
|
||||||
virtual void MakeFocus(bool state = true);
|
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||||
virtual void SetViewColor(rgb_color);
|
|
||||||
rgb_color ViewColor();
|
virtual void FrameResized(float width, float height);
|
||||||
virtual bool CanEndLine(int32);
|
virtual void KeyDown(const char *bytes, int32 numBytes);
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
virtual void MakeFocus(bool focusState = true);
|
||||||
virtual void Draw(BRect);
|
|
||||||
virtual void SetEnabled(bool state);
|
void AlignTextRect();
|
||||||
virtual void MouseDown(BPoint where);
|
void SetInitialText();
|
||||||
|
|
||||||
|
virtual void Paste(BClipboard *clipboard);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void InsertText(const char *inText, int32 inLength,
|
||||||
|
int32 inOffset, const text_run_array *inRuns);
|
||||||
|
virtual void DeleteText(int32 fromOffset, int32 toOffset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rgb_color fViewColor;
|
|
||||||
bool fEnabled;
|
BTextControl *TextControl();
|
||||||
bool fChanged;
|
|
||||||
BTextControl* fParent;
|
char *fPreviousText;
|
||||||
|
bool fBool;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
+80
-54
@@ -44,76 +44,72 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
|
BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
|
||||||
border_style border)
|
border_style border)
|
||||||
: BView(frame, name, resizingMode, flags),
|
: BView(frame, name, resizingMode, flags)
|
||||||
fLabel(NULL),
|
|
||||||
fStyle(border),
|
|
||||||
fLabelView(NULL)
|
|
||||||
{
|
{
|
||||||
fBounds = Bounds();
|
|
||||||
|
|
||||||
SetFont(be_bold_font);
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
InitObject();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BBox::~BBox()
|
BBox::~BBox()
|
||||||
{
|
{
|
||||||
if (fLabel)
|
ClearAnyLabel();
|
||||||
delete fLabel;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BBox::BBox(BMessage *archive)
|
BBox::BBox(BMessage *archive)
|
||||||
: BView(archive)
|
: BView(archive)
|
||||||
{
|
{
|
||||||
fBounds = Bounds();
|
InitObject(archive);
|
||||||
fLabelView = NULL;
|
|
||||||
|
|
||||||
const char *string;
|
const char *string;
|
||||||
|
|
||||||
if (archive->FindString("_label", &string) != B_OK)
|
if (archive->FindString("_label", &string) == B_OK)
|
||||||
fLabel = NULL;
|
|
||||||
else
|
|
||||||
SetLabel(string);
|
SetLabel(string);
|
||||||
|
|
||||||
|
bool aBool;
|
||||||
int32 anInt32;
|
int32 anInt32;
|
||||||
|
|
||||||
if (archive->FindInt32("_style", &anInt32) != B_OK)
|
if (archive->FindBool("_style", &aBool) == B_OK)
|
||||||
fStyle = B_FANCY_BORDER;
|
fStyle = aBool ? B_FANCY_BORDER : B_PLAIN_BORDER;
|
||||||
else
|
else if (archive->FindInt32("_style", &anInt32) == B_OK)
|
||||||
fStyle = (border_style)anInt32;
|
fStyle = (border_style)anInt32;
|
||||||
|
|
||||||
|
if (archive->FindBool("_lblview", &aBool) == B_OK)
|
||||||
|
fLabelView = ChildAt(0);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable *BBox::Instantiate(BMessage *archive)
|
BArchivable *BBox::Instantiate(BMessage *archive)
|
||||||
{
|
{
|
||||||
if ( validate_instantiation ( archive, "BBox" ) )
|
if (validate_instantiation(archive, "BBox"))
|
||||||
return new BBox ( archive );
|
return new BBox(archive);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BBox::Archive(BMessage *archive, bool deep) const
|
status_t BBox::Archive(BMessage *archive, bool deep) const
|
||||||
{
|
{
|
||||||
status_t err = BView::Archive(archive, deep);
|
BView::Archive(archive, deep);
|
||||||
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
if (fLabel)
|
if (fLabel)
|
||||||
err = archive->AddString("_label",fLabel);
|
archive->AddString("_label", fLabel);
|
||||||
|
|
||||||
if (err != B_OK)
|
if (fLabelView)
|
||||||
return err;
|
archive->AddBool("_lblview", true);
|
||||||
|
|
||||||
if (fStyle != B_FANCY_BORDER)
|
if (fStyle != B_FANCY_BORDER)
|
||||||
err = archive->AddInt32("_style", fStyle);
|
archive->AddInt32("_style", fStyle);
|
||||||
|
|
||||||
return err;
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::SetBorder(border_style border)
|
void BBox::SetBorder(border_style border)
|
||||||
{
|
{
|
||||||
fStyle = border;
|
fStyle = border;
|
||||||
|
|
||||||
|
LockLooper();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
border_style BBox::Border() const
|
border_style BBox::Border() const
|
||||||
@@ -123,48 +119,43 @@ border_style BBox::Border() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::SetLabel(const char *string)
|
void BBox::SetLabel(const char *string)
|
||||||
{
|
{
|
||||||
if (fLabel)
|
ClearAnyLabel();
|
||||||
delete fLabel;
|
|
||||||
|
|
||||||
fLabel = strdup(string);
|
|
||||||
|
|
||||||
|
if (string)
|
||||||
|
{
|
||||||
// Update fBounds
|
// Update fBounds
|
||||||
fBounds = Bounds();
|
fBounds = Bounds();
|
||||||
|
|
||||||
if (fLabel)
|
|
||||||
{
|
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
|
|
||||||
fBounds.top = (float)ceil((fh.ascent + fh.descent) / 2.0f);
|
fBounds.top = (float)ceil((fh.ascent + fh.descent) / 2.0f);
|
||||||
|
|
||||||
|
fLabel = strdup(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Window())
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BBox::SetLabel(BView *viewLabel)
|
status_t BBox::SetLabel(BView *viewLabel)
|
||||||
{
|
{
|
||||||
|
ClearAnyLabel();
|
||||||
|
|
||||||
if (viewLabel)
|
if (viewLabel)
|
||||||
{
|
{
|
||||||
if (fLabelView)
|
|
||||||
RemoveChild(fLabelView);
|
|
||||||
|
|
||||||
fLabelView = viewLabel;
|
|
||||||
AddChild(fLabelView);
|
|
||||||
|
|
||||||
if(fLabel)
|
|
||||||
{
|
|
||||||
delete fLabel;
|
|
||||||
fLabel = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update fBounds
|
// Update fBounds
|
||||||
fBounds = Bounds();
|
fBounds = Bounds();
|
||||||
|
font_height fh;
|
||||||
|
GetFontHeight(&fh);
|
||||||
|
|
||||||
if (fLabelView)
|
fBounds.top = (float)ceil(viewLabel->Bounds().Height() / 2.0f);
|
||||||
fBounds.top = (float)ceil(fLabelView->Frame().Height() / 2.0f);
|
|
||||||
|
|
||||||
|
fLabelView = viewLabel;
|
||||||
|
fLabelView->MoveTo(10.0f, 0.0f);
|
||||||
|
AddChild(fLabelView, ChildAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Window())
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -207,7 +198,8 @@ void BBox::Draw(BRect updateRect)
|
|||||||
(float)ceil(fh.ascent + fh.descent))/*, B_SOLID_LOW*/);
|
(float)ceil(fh.ascent + fh.descent))/*, B_SOLID_LOW*/);
|
||||||
|
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
DrawString(fLabel, BPoint(10.0f, (float)ceil(fh.ascent - fh.descent) + 1.0f ));
|
DrawString(fLabel, BPoint(10.0f, (float)ceil(fh.ascent - fh.descent)
|
||||||
|
+ 1.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -237,8 +229,12 @@ void BBox::AllDetached()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::FrameResized(float width, float height)
|
void BBox::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
fBounds.right = Bounds().right;
|
fBounds.right = Bounds().right;
|
||||||
fBounds.bottom = Bounds().bottom;
|
fBounds.bottom = Bounds().bottom;
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::MessageReceived(BMessage *message)
|
void BBox::MessageReceived(BMessage *message)
|
||||||
@@ -285,7 +281,7 @@ void BBox::ResizeToPreferred()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::GetPreferredSize(float *width, float *height)
|
void BBox::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
BRect rect(0,0,99,99);
|
/* BRect rect(0,0,99,99);
|
||||||
|
|
||||||
if (Parent())
|
if (Parent())
|
||||||
{
|
{
|
||||||
@@ -294,7 +290,9 @@ void BBox::GetPreferredSize(float *width, float *height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*width = rect.Width();
|
*width = rect.Width();
|
||||||
*height = rect.Height();
|
*height = rect.Height();*/
|
||||||
|
|
||||||
|
BView::GetPreferredSize(width, height);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::MakeFocus(bool focused)
|
void BBox::MakeFocus(bool focused)
|
||||||
@@ -309,7 +307,7 @@ status_t BBox::GetSupportedSuites(BMessage *message)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BBox::Perform(perform_code d, void *arg)
|
status_t BBox::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BView::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::_ReservedBox1() {}
|
void BBox::_ReservedBox1() {}
|
||||||
@@ -322,6 +320,23 @@ BBox &BBox::operator=(const BBox &)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::InitObject(BMessage *data)
|
void BBox::InitObject(BMessage *data)
|
||||||
{
|
{
|
||||||
|
fLabel = NULL;
|
||||||
|
fBounds = Bounds();
|
||||||
|
fStyle = B_FANCY_BORDER;
|
||||||
|
fLabelView = NULL;
|
||||||
|
|
||||||
|
int32 flags = 0;
|
||||||
|
|
||||||
|
BFont font(be_bold_font);
|
||||||
|
|
||||||
|
if (!data || !data->HasString("_fname"))
|
||||||
|
flags = 1;
|
||||||
|
|
||||||
|
if (!data || !data->HasFloat("_fflt"))
|
||||||
|
flags |= 2;
|
||||||
|
|
||||||
|
if (flags != 0)
|
||||||
|
SetFont(&font, flags);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::DrawPlain()
|
void BBox::DrawPlain()
|
||||||
@@ -351,6 +366,17 @@ void BBox::DrawFancy()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BBox::ClearAnyLabel()
|
void BBox::ClearAnyLabel()
|
||||||
{
|
{
|
||||||
|
if (fLabel)
|
||||||
|
{
|
||||||
|
free(fLabel);
|
||||||
|
fLabel = NULL;
|
||||||
|
}
|
||||||
|
else if (fLabelView)
|
||||||
|
{
|
||||||
|
fLabelView->RemoveSelf();
|
||||||
|
delete fLabelView;
|
||||||
|
fLabelView = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
+183
-120
@@ -55,12 +55,13 @@ BTab::BTab(BView *tabView)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTab::~BTab()
|
BTab::~BTab()
|
||||||
{
|
{
|
||||||
if (fView->Window() != NULL)
|
if (!fView)
|
||||||
{
|
return;
|
||||||
|
|
||||||
|
if (fSelected)
|
||||||
fView->RemoveSelf();
|
fView->RemoveSelf();
|
||||||
|
|
||||||
delete fView;
|
delete fView;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTab::BTab(BMessage *archive)
|
BTab::BTab(BMessage *archive)
|
||||||
@@ -68,10 +69,12 @@ BTab::BTab(BMessage *archive)
|
|||||||
fFocus(false),
|
fFocus(false),
|
||||||
fView(NULL)
|
fView(NULL)
|
||||||
{
|
{
|
||||||
if (archive->FindBool("_disable", &fEnabled) != B_OK)
|
bool disable;
|
||||||
fEnabled = true;
|
|
||||||
|
if (archive->FindBool("_disable", &disable) != B_OK)
|
||||||
|
SetEnabled(true);
|
||||||
else
|
else
|
||||||
fEnabled = !fEnabled;
|
SetEnabled(!disable);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable *BTab::Instantiate(BMessage *archive)
|
BArchivable *BTab::Instantiate(BMessage *archive)
|
||||||
@@ -89,7 +92,7 @@ status_t BTab::Archive(BMessage *archive, bool deep) const
|
|||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if ( !fEnabled )
|
if (!fEnabled)
|
||||||
err = archive->AddBool("_disable", false);
|
err = archive->AddBool("_disable", false);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@@ -97,7 +100,7 @@ status_t BTab::Archive(BMessage *archive, bool deep) const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTab::Perform(uint32 d, void *arg)
|
status_t BTab::Perform(uint32 d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BArchivable::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
const char *BTab::Label() const
|
const char *BTab::Label() const
|
||||||
@@ -110,7 +113,12 @@ const char *BTab::Label() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTab::SetLabel(const char *label)
|
void BTab::SetLabel(const char *label)
|
||||||
{
|
{
|
||||||
if (fView)
|
if (!label)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!fView)
|
||||||
|
return;
|
||||||
|
|
||||||
fView->SetName(label);
|
fView->SetName(label);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -121,14 +129,25 @@ bool BTab::IsSelected() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTab::Select(BView *owner)
|
void BTab::Select(BView *owner)
|
||||||
{
|
{
|
||||||
dynamic_cast<BTabView*>(owner)->ContainerView()->AddChild(fView);
|
if (!owner)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!View())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!owner->Window())
|
||||||
|
return;
|
||||||
|
|
||||||
|
owner->AddChild(fView);
|
||||||
|
//fView->Show();
|
||||||
|
|
||||||
fSelected = true;
|
fSelected = true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTab::Deselect()
|
void BTab::Deselect()
|
||||||
{
|
{
|
||||||
fView->RemoveSelf();
|
if (View())
|
||||||
|
View()->RemoveSelf();
|
||||||
|
|
||||||
fSelected = false;
|
fSelected = false;
|
||||||
}
|
}
|
||||||
@@ -155,9 +174,20 @@ bool BTab::IsFocus() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTab::SetView(BView *view)
|
void BTab::SetView(BView *view)
|
||||||
{
|
{
|
||||||
// TODO: do we need to remove the previous view and add the new one if
|
if (!view)
|
||||||
// selected?
|
return;
|
||||||
|
|
||||||
|
if (fView == view)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fView == NULL)
|
||||||
fView = view;
|
fView = view;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fView->RemoveSelf();
|
||||||
|
delete fView;
|
||||||
|
fView = view;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BView *BTab::View() const
|
BView *BTab::View() const
|
||||||
@@ -257,78 +287,82 @@ BTab &BTab::operator=(const BTab &)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTabView::BTabView(BRect frame, const char *name, button_width width,
|
BTabView::BTabView(BRect frame, const char *name, button_width width,
|
||||||
uint32 resizingMode, uint32 flags)
|
uint32 resizingMode, uint32 flags)
|
||||||
: BView(frame, name, resizingMode, flags),
|
: BView(frame, name, resizingMode, flags)
|
||||||
fTabWidthSetting(width),
|
|
||||||
fTabWidth(0.0f),
|
|
||||||
fSelection(-1),
|
|
||||||
fInitialSelection(-1),
|
|
||||||
fFocus(-1)
|
|
||||||
{
|
{
|
||||||
fTabList = new BList;
|
_InitObject();
|
||||||
|
|
||||||
//font_height fh;
|
fTabWidthSetting = width;
|
||||||
//GetFontHeight(&fh);
|
|
||||||
//fTabHeight = fh.ascent + fh.descent + 8.0f;
|
|
||||||
fTabHeight = 20.0f;
|
|
||||||
|
|
||||||
BRect bounds = Bounds();
|
|
||||||
|
|
||||||
bounds.top += fTabHeight + 1.0f;
|
|
||||||
bounds.InsetBy ( 2.0f, 2.0f );
|
|
||||||
|
|
||||||
fContainerView = new BView(bounds, "_fContainerView", B_FOLLOW_ALL,
|
|
||||||
B_FRAME_EVENTS);
|
|
||||||
AddChild(fContainerView);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTabView::~BTabView()
|
BTabView::~BTabView()
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < CountTabs(); i++)
|
for (int32 i = 0; i < CountTabs(); i++)
|
||||||
|
{
|
||||||
|
if (TabAt(i))
|
||||||
delete TabAt(i);
|
delete TabAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
delete fTabList;
|
delete fTabList;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTabView::BTabView(BMessage *archive)
|
BTabView::BTabView(BMessage *archive)
|
||||||
: BView(archive),
|
: BView(archive),
|
||||||
fInitialSelection(-1),
|
|
||||||
fFocus(-1)
|
fFocus(-1)
|
||||||
{
|
{
|
||||||
|
fContainerView == NULL;
|
||||||
fTabList = new BList;
|
fTabList = new BList;
|
||||||
|
|
||||||
|
int16 width;
|
||||||
|
|
||||||
|
if (archive->FindInt16("_but_width", &width) == B_OK)
|
||||||
|
fTabWidthSetting = (button_width)width;
|
||||||
|
else
|
||||||
|
fTabWidthSetting = B_WIDTH_AS_USUAL;
|
||||||
|
|
||||||
if (archive->FindFloat("_high", &fTabHeight) != B_OK)
|
if (archive->FindFloat("_high", &fTabHeight) != B_OK)
|
||||||
{
|
{
|
||||||
//font_height fh;
|
font_height fh;
|
||||||
//GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
//fTabHeight = fh.ascent + fh.descent + 8.0f;
|
fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f;
|
||||||
fTabHeight = 20.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (archive->FindInt16("_but_width", (int16*)&fTabWidthSetting) != B_OK)
|
fFocus = -1;
|
||||||
fTabWidthSetting = B_WIDTH_AS_USUAL;
|
|
||||||
|
|
||||||
if (archive->FindInt32("_sel", &fSelection) != B_OK)
|
if (archive->FindInt32("_sel", &fSelection) != B_OK)
|
||||||
fSelection = -1;
|
fSelection = 0;
|
||||||
|
|
||||||
|
if (fContainerView == NULL)
|
||||||
|
fContainerView = ChildAt(0);
|
||||||
|
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
BMessage msg;
|
BMessage tabMsg;
|
||||||
|
|
||||||
while (archive->FindMessage("_l_items", i++, &msg) == B_OK)
|
while (archive->FindMessage("_l_items", i, &tabMsg) == B_OK)
|
||||||
{
|
{
|
||||||
BTab *tab = dynamic_cast<BTab*>(instantiate_object(&msg));
|
BArchivable *archivedTab = instantiate_object(&tabMsg);
|
||||||
|
|
||||||
if (tab)
|
if (archivedTab)
|
||||||
AddTab(NULL, tab);
|
{
|
||||||
|
BTab *tab = dynamic_cast<BTab*>(archivedTab);
|
||||||
|
|
||||||
|
BMessage viewMsg;
|
||||||
|
|
||||||
|
if (archive->FindMessage("_view_list", i, &viewMsg) == B_OK)
|
||||||
|
{
|
||||||
|
BArchivable *archivedView = instantiate_object(&viewMsg);
|
||||||
|
|
||||||
|
if (archivedView)
|
||||||
|
{
|
||||||
|
BView *view = dynamic_cast<BView*>(archivedView);
|
||||||
|
|
||||||
|
AddTab(view, tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect bounds = Bounds();
|
tabMsg.MakeEmpty();
|
||||||
|
i++;
|
||||||
bounds.top += fTabHeight + 1.0f;
|
}
|
||||||
bounds.InsetBy ( 2.0f, 2.0f );
|
|
||||||
|
|
||||||
fContainerView = new BView(bounds, "_fContainerView", B_FOLLOW_ALL,
|
|
||||||
B_FRAME_EVENTS);
|
|
||||||
AddChild(fContainerView);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable *BTabView::Instantiate(BMessage *archive)
|
BArchivable *BTabView::Instantiate(BMessage *archive)
|
||||||
@@ -341,41 +375,42 @@ BArchivable *BTabView::Instantiate(BMessage *archive)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTabView::Archive(BMessage *archive, bool deep) const
|
status_t BTabView::Archive(BMessage *archive, bool deep) const
|
||||||
{
|
{
|
||||||
status_t err = BView::Archive(archive, deep);
|
if(CountTabs() > 0)
|
||||||
|
TabAt(Selection())->View()->RemoveSelf();
|
||||||
|
|
||||||
if (err != B_OK)
|
BView::Archive(archive, deep);
|
||||||
return err;
|
|
||||||
|
|
||||||
err = archive->AddFloat("_high", fTabHeight);
|
archive->AddInt16("_but_width", fTabWidthSetting);
|
||||||
|
archive->AddFloat("_high", fTabHeight);
|
||||||
if (err != B_OK)
|
archive->AddInt32("_sel", fSelection);
|
||||||
return err;
|
|
||||||
|
|
||||||
if (fTabHeight != B_WIDTH_AS_USUAL)
|
|
||||||
{
|
|
||||||
err = archive->AddInt16("_but_width", fTabWidthSetting);
|
|
||||||
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fSelection != -1)
|
|
||||||
{
|
|
||||||
err = archive->AddInt32("_sel", fSelection);
|
|
||||||
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deep)
|
if (deep)
|
||||||
{
|
{
|
||||||
BMessage tabArchive;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < CountTabs(); i++)
|
for (int32 i = 0; i < CountTabs(); i++)
|
||||||
if ((err = TabAt(i)->Archive(&tabArchive, deep)) == B_OK)
|
{
|
||||||
|
BMessage tabArchive;
|
||||||
|
BTab *tab = TabAt(i);
|
||||||
|
|
||||||
|
if (!tab)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (tab->Archive(&tabArchive, true) == B_OK)
|
||||||
archive->AddMessage("_l_items", &tabArchive);
|
archive->AddMessage("_l_items", &tabArchive);
|
||||||
else
|
|
||||||
return err;
|
if (!tab->View())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BMessage viewArchive;
|
||||||
|
|
||||||
|
if (tab->View()->Archive(&viewArchive, true) == B_OK)
|
||||||
|
archive->AddMessage("_view_list", &viewArchive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CountTabs() > 0)
|
||||||
|
{
|
||||||
|
if (TabAt(Selection())->View() && ContainerView())
|
||||||
|
TabAt(Selection())->Select(ContainerView());
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -383,7 +418,7 @@ status_t BTabView::Archive(BMessage *archive, bool deep) const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTabView::Perform(perform_code d, void *arg)
|
status_t BTabView::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BTabView::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::WindowActivated(bool active)
|
void BTabView::WindowActivated(bool active)
|
||||||
@@ -397,12 +432,7 @@ void BTabView::AttachedToWindow()
|
|||||||
{
|
{
|
||||||
BView::AttachedToWindow();
|
BView::AttachedToWindow();
|
||||||
|
|
||||||
// TODO: check if this color is set in the BeOS implementation
|
Select(fSelection);
|
||||||
//if (Parent())
|
|
||||||
// SetViewColor(Parent()->ViewColor ());
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
|
|
||||||
Select(0);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::AllAttached()
|
void BTabView::AllAttached()
|
||||||
@@ -437,6 +467,9 @@ void BTabView::FrameResized(float width,float height)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::KeyDown(const char *bytes, int32 numBytes)
|
void BTabView::KeyDown(const char *bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
|
if (IsHidden())
|
||||||
|
return;
|
||||||
|
|
||||||
switch (bytes[0])
|
switch (bytes[0])
|
||||||
{
|
{
|
||||||
case B_DOWN_ARROW:
|
case B_DOWN_ARROW:
|
||||||
@@ -469,13 +502,16 @@ void BTabView::MouseDown(BPoint point)
|
|||||||
for (int32 i = 0; i < CountTabs(); i++)
|
for (int32 i = 0; i < CountTabs(); i++)
|
||||||
{
|
{
|
||||||
if (TabFrame(i).Contains(point))
|
if (TabFrame(i).Contains(point))
|
||||||
|
{
|
||||||
|
if (i != Selection())
|
||||||
{
|
{
|
||||||
Select(i);
|
Select(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
BView::MouseDown(point);
|
BView::MouseDown(point);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -494,22 +530,25 @@ void BTabView::Pulse()
|
|||||||
BView::Pulse();
|
BView::Pulse();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::Select(int32 tab)
|
void BTabView::Select(int32 index)
|
||||||
{
|
{
|
||||||
if (tab < 0 || tab >= CountTabs())
|
if (index < 0 || index >= CountTabs())
|
||||||
return;
|
index = Selection();
|
||||||
|
|
||||||
if (tab == fSelection)
|
BTab *tab = TabAt(Selection());
|
||||||
return;
|
|
||||||
|
|
||||||
if (fSelection != -1)
|
if (tab)
|
||||||
TabAt(fSelection)->Deselect();
|
tab->Deselect();
|
||||||
|
|
||||||
if (tab != -1)
|
tab = TabAt(index);
|
||||||
TabAt(tab)->Select(this);
|
|
||||||
|
|
||||||
fSelection = tab;
|
if (tab && ContainerView())
|
||||||
|
{
|
||||||
|
tab->Select(ContainerView());
|
||||||
|
fSelection = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw(Bounds());
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -527,7 +566,7 @@ void BTabView::MakeFocus(bool focused)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::SetFocusTab(int32 tab, bool focused)
|
void BTabView::SetFocusTab(int32 tab, bool focused)
|
||||||
{
|
{
|
||||||
if (tab < 0 || tab >= CountTabs())
|
if (tab >= CountTabs())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (focused)
|
if (focused)
|
||||||
@@ -570,7 +609,7 @@ BRect BTabView::DrawTabs()
|
|||||||
(i == fSelection) ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY,
|
(i == fSelection) ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY,
|
||||||
(i + 1 != fSelection));
|
(i + 1 != fSelection));
|
||||||
|
|
||||||
if (fSelection > -1)
|
if (fSelection < CountTabs())
|
||||||
return TabFrame(fSelection);
|
return TabFrame(fSelection);
|
||||||
else
|
else
|
||||||
return BRect();
|
return BRect();
|
||||||
@@ -613,6 +652,7 @@ BRect BTabView::TabFrame(int32 tab_index) const
|
|||||||
}
|
}
|
||||||
case B_WIDTH_FROM_WIDEST:
|
case B_WIDTH_FROM_WIDEST:
|
||||||
{
|
{
|
||||||
|
float x = 6.0f;
|
||||||
float width = 0.0f;
|
float width = 0.0f;
|
||||||
|
|
||||||
for (int32 i = 0; i < CountTabs(); i++)
|
for (int32 i = 0; i < CountTabs(); i++)
|
||||||
@@ -649,15 +689,12 @@ void BTabView::SetResizingMode(uint32 mode)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::GetPreferredSize(float *width, float *height)
|
void BTabView::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
*width = Bounds().Width();
|
BTabView::GetPreferredSize(width, height);
|
||||||
*height = Bounds().Height();
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::ResizeToPreferred()
|
void BTabView::ResizeToPreferred()
|
||||||
{
|
{
|
||||||
float width, height;
|
BView::ResizeToPreferred();
|
||||||
GetPreferredSize(&width, &height);
|
|
||||||
BView::ResizeTo(width, height);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BHandler *BTabView::ResolveSpecifier(BMessage *message, int32 index,
|
BHandler *BTabView::ResolveSpecifier(BMessage *message, int32 index,
|
||||||
@@ -679,29 +716,27 @@ void BTabView::AddTab(BView *target, BTab *tab)
|
|||||||
tab->SetView(target);
|
tab->SetView(target);
|
||||||
|
|
||||||
fTabList->AddItem(tab);
|
fTabList->AddItem(tab);
|
||||||
|
|
||||||
// TODO: check if we need to select the new tab
|
|
||||||
if (fSelection == -1)
|
|
||||||
Select(0);
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTab *BTabView::RemoveTab(int32 tab_index)
|
BTab *BTabView::RemoveTab(int32 tab_index)
|
||||||
{
|
{
|
||||||
// TODO: check if we need to change the selection and focus
|
if (tab_index < 0 || tab_index >= CountTabs())
|
||||||
if (fSelection == CountTabs() - 1)
|
return NULL;
|
||||||
Select(fSelection - 1);
|
|
||||||
|
BTab *tab = (BTab*)fTabList->RemoveItem(tab_index);
|
||||||
|
|
||||||
|
tab->Deselect();
|
||||||
|
|
||||||
|
if (tab_index <= fSelection && fSelection != 0)
|
||||||
|
fSelection--;
|
||||||
|
|
||||||
|
Select(fSelection);
|
||||||
|
|
||||||
if (fFocus == CountTabs() - 1)
|
if (fFocus == CountTabs() - 1)
|
||||||
SetFocusTab(fFocus, false);
|
SetFocusTab(fFocus, false);
|
||||||
else
|
else
|
||||||
SetFocusTab(fFocus, true);
|
SetFocusTab(fFocus, true);
|
||||||
|
|
||||||
BTab *tab = (BTab*)fTabList->RemoveItem(tab_index);
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
|
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -727,6 +762,7 @@ void BTabView::SetTabHeight(float height)
|
|||||||
if (fTabHeight == height)
|
if (fTabHeight == height)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fContainerView->MoveBy(0.0f, height - fTabHeight);
|
||||||
fContainerView->ResizeBy(0.0f, height - fTabHeight);
|
fContainerView->ResizeBy(0.0f, height - fTabHeight);
|
||||||
|
|
||||||
fTabHeight = height;
|
fTabHeight = height;
|
||||||
@@ -761,6 +797,33 @@ BView *BTabView::ViewForTab(int32 tabIndex) const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::_InitObject()
|
void BTabView::_InitObject()
|
||||||
{
|
{
|
||||||
|
fTabList = new BList;
|
||||||
|
|
||||||
|
fTabWidthSetting = B_WIDTH_AS_USUAL;
|
||||||
|
fSelection = 0;
|
||||||
|
fFocus = -1;
|
||||||
|
|
||||||
|
rgb_color color = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
|
||||||
|
SetViewColor(color);
|
||||||
|
SetLowColor(color);
|
||||||
|
|
||||||
|
font_height fh;
|
||||||
|
GetFontHeight(&fh);
|
||||||
|
fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f;
|
||||||
|
|
||||||
|
BRect bounds = Bounds();
|
||||||
|
|
||||||
|
bounds.top += 1.0f + TabHeight();
|
||||||
|
bounds.InsetBy(2.0f, 2.0f);
|
||||||
|
|
||||||
|
fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL,
|
||||||
|
B_WILL_DRAW);
|
||||||
|
|
||||||
|
fContainerView->SetViewColor(color);
|
||||||
|
fContainerView->SetLowColor(color);
|
||||||
|
|
||||||
|
AddChild(fContainerView);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTabView::_ReservedTabView1() {}
|
void BTabView::_ReservedTabView1() {}
|
||||||
|
|||||||
+331
-176
@@ -42,136 +42,126 @@
|
|||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTextControl::BTextControl(BRect frame, const char* name, const char* label,
|
BTextControl::BTextControl(BRect frame, const char *name, const char *label,
|
||||||
const char* text, BMessage* message, uint32 mask,
|
const char *text, BMessage *message, uint32 mask,
|
||||||
uint32 flags)
|
uint32 flags)
|
||||||
: BControl(frame, name, label, message, mask, flags)
|
: BControl(frame, name, label, message, mask, flags | B_FRAME_EVENTS)
|
||||||
{
|
{
|
||||||
if (label)
|
InitData(label, text);
|
||||||
{
|
|
||||||
fDivider = frame.Width() / 2.0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// no label
|
|
||||||
fDivider = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
fModificationMessage = NULL;
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
frame = Bounds();
|
font_height fh;
|
||||||
if (fDivider)
|
GetFontHeight(&fh);
|
||||||
{
|
|
||||||
frame.left = fDivider + 5.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
BRect rect(frame);
|
float height = (float)ceil(fh.ascent + fh.descent + fh.leading);
|
||||||
rect.OffsetTo(0,0);
|
float lineHeight = fText->LineHeight(0);
|
||||||
|
|
||||||
frame.OffsetBy(-2,1);
|
ResizeTo(bounds.Width(), height + 8);
|
||||||
|
|
||||||
rect.InsetBy(2,2);
|
BRect textBounds(fText->Bounds());
|
||||||
fText = new _BTextInput_(this, frame, "text", rect);
|
|
||||||
fText->SetText(text);
|
fText->ResizeTo(textBounds.Width(), lineHeight + 4);
|
||||||
AddChild(fText);
|
fText->MoveBy(0, (bounds.Height() - height) / 2.0f);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTextControl::~BTextControl()
|
BTextControl::~BTextControl()
|
||||||
{
|
{
|
||||||
if (fText)
|
SetModificationMessage(NULL);
|
||||||
{
|
|
||||||
fText->RemoveSelf();
|
|
||||||
delete fText;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTextControl::BTextControl(BMessage* data)
|
BTextControl::BTextControl(BMessage *data)
|
||||||
: BControl(data)
|
: BControl(data)
|
||||||
{
|
{
|
||||||
if (data->FindInt32("_a_label", (int32*)&fLabelAlign) != B_OK)
|
InitData(Label(), NULL, data);
|
||||||
{
|
|
||||||
fLabelAlign = B_ALIGN_LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
alignment textAlign;
|
int32 _a_label = B_ALIGN_LEFT;
|
||||||
if (data->FindInt32("_a_text", (int32*)&textAlign) != B_OK)
|
int32 _a_text = B_ALIGN_LEFT;
|
||||||
{
|
|
||||||
fText->SetAlignment(B_ALIGN_LEFT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fText->SetAlignment(textAlign);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->FindFloat("_divide", &fDivider) != B_OK)
|
if (data->HasInt32("_a_label"))
|
||||||
{
|
data->FindInt32("_a_label", &_a_label);
|
||||||
if (Label())
|
|
||||||
fDivider = Frame().Width()/2.0f;
|
|
||||||
else
|
|
||||||
fDivider = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->FindMessage("_mod_msg", fModificationMessage) != B_OK)
|
if (data->HasInt32("_a_text"))
|
||||||
{
|
data->FindInt32("_a_text", &_a_text);
|
||||||
fModificationMessage = NULL; // Is this really necessary?
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Recover additional info as per final implementation of Archive()
|
SetAlignment((alignment)_a_label, (alignment)_a_text);
|
||||||
|
|
||||||
|
if (data->HasFloat("_divide"))
|
||||||
|
data->FindFloat("_a_text", &fDivider);
|
||||||
|
|
||||||
|
if (data->HasMessage("_mod_msg"))
|
||||||
|
{
|
||||||
|
BMessage *_mod_msg = new BMessage;
|
||||||
|
data->FindMessage("_mod_msg", _mod_msg);
|
||||||
|
SetModificationMessage(_mod_msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable* BTextControl::Instantiate(BMessage* data)
|
BArchivable* BTextControl::Instantiate(BMessage *archive)
|
||||||
{
|
{
|
||||||
if (!validate_instantiation(data,"BTextControl"))
|
if (validate_instantiation(archive, "BTextControl"))
|
||||||
{
|
return new BTextControl(archive);
|
||||||
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return new BTextControl(data);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTextControl::Archive(BMessage* data, bool deep) const
|
status_t BTextControl::Archive(BMessage *data, bool deep) const
|
||||||
{
|
{
|
||||||
// TODO: compare against original version and finish
|
BView::Archive(data, deep);
|
||||||
status_t err = BView::Archive(data, deep);
|
|
||||||
|
|
||||||
if (!err)
|
alignment _a_label, _a_text;
|
||||||
err = data->AddInt32("_a_label", fLabelAlign);
|
|
||||||
if (!err)
|
|
||||||
err = data->AddInt32("_a_text", fText->Alignment());
|
|
||||||
if (!err)
|
|
||||||
err = data->AddFloat("_divide", fDivider);
|
|
||||||
if (!err && fModificationMessage)
|
|
||||||
err = data->AddMessage("_mod_msg", fModificationMessage);
|
|
||||||
|
|
||||||
return err;
|
GetAlignment(&_a_label, &_a_text);
|
||||||
|
|
||||||
|
data->AddInt32("_a_label", _a_label);
|
||||||
|
data->AddInt32("_a_text", _a_text);
|
||||||
|
|
||||||
|
data->AddFloat("_divide", Divider());
|
||||||
|
|
||||||
|
if (ModificationMessage())
|
||||||
|
data->AddMessage("_mod_msg", ModificationMessage());
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetText(const char* text)
|
void BTextControl::SetText(const char *text)
|
||||||
{
|
{
|
||||||
|
if (InvokeKind() != B_CONTROL_INVOKED)
|
||||||
|
return;
|
||||||
|
|
||||||
fText->SetText(text);
|
fText->SetText(text);
|
||||||
|
|
||||||
|
if (IsFocus())
|
||||||
|
fText->SetInitialText();
|
||||||
|
|
||||||
|
fText->Invalidate();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
const char* BTextControl::Text() const
|
const char *BTextControl::Text() const
|
||||||
{
|
{
|
||||||
return fText->Text();
|
return fText->Text();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetValue(int32 value)
|
void BTextControl::SetValue(int32 value)
|
||||||
{
|
{
|
||||||
|
BControl::SetValue(value);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTextControl::Invoke(BMessage* msg)
|
status_t BTextControl::Invoke(BMessage *msg)
|
||||||
{
|
{
|
||||||
return BControl::Invoke(msg);
|
return BControl::Invoke(msg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BTextView* BTextControl::TextView() const
|
BTextView* BTextControl::TextView() const
|
||||||
{
|
{
|
||||||
return (BTextView*)fText;
|
return fText;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetModificationMessage(BMessage* message)
|
void BTextControl::SetModificationMessage(BMessage *message)
|
||||||
{
|
{
|
||||||
|
if (fModificationMessage)
|
||||||
|
delete fModificationMessage;
|
||||||
|
|
||||||
fModificationMessage = message;
|
fModificationMessage = message;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -182,11 +172,17 @@ BMessage* BTextControl::ModificationMessage() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetAlignment(alignment label, alignment text)
|
void BTextControl::SetAlignment(alignment label, alignment text)
|
||||||
{
|
{
|
||||||
fLabelAlign = label;
|
|
||||||
fText->SetAlignment(text);
|
fText->SetAlignment(text);
|
||||||
|
fText->AlignTextRect();
|
||||||
|
|
||||||
|
if (fLabelAlign != label)
|
||||||
|
{
|
||||||
|
fLabelAlign = label;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::GetAlignment(alignment* label, alignment* text) const
|
void BTextControl::GetAlignment(alignment *label, alignment *text) const
|
||||||
{
|
{
|
||||||
*label = fLabelAlign;
|
*label = fLabelAlign;
|
||||||
*text = fText->Alignment();
|
*text = fText->Alignment();
|
||||||
@@ -194,30 +190,18 @@ void BTextControl::GetAlignment(alignment* label, alignment* text) const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetDivider(float dividing_line)
|
void BTextControl::SetDivider(float dividing_line)
|
||||||
{
|
{
|
||||||
|
float dx = fDivider - dividing_line;
|
||||||
|
|
||||||
fDivider = dividing_line;
|
fDivider = dividing_line;
|
||||||
// here I need some code to resize and invalidate the textView
|
|
||||||
|
|
||||||
BRect frame = fText->Frame();
|
fText->MoveBy(-dx, 0.0f);
|
||||||
if (fDivider)
|
fText->ResizeBy(dx, 0.0f);
|
||||||
{
|
|
||||||
frame.left = fDivider + 5.0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame.left = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!frame.IsValid())
|
if (Window())
|
||||||
{
|
{
|
||||||
frame.left = frame.right - 6.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
fText->ResizeTo( frame.Width(), frame.Height());
|
|
||||||
// fText->FrameResized( frame.Width(), frame.Height());
|
|
||||||
fText->MoveTo( frame.left, frame.top);
|
|
||||||
fText->Invalidate();
|
fText->Invalidate();
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
float BTextControl::Divider() const
|
float BTextControl::Divider() const
|
||||||
@@ -225,26 +209,82 @@ float BTextControl::Divider() const
|
|||||||
return fDivider;
|
return fDivider;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::Draw(BRect rect)
|
void BTextControl::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
SetLowColor(ViewColor());
|
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||||
BFont font;
|
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
||||||
GetFont(&font);
|
lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT),
|
||||||
font_height fh;
|
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
|
||||||
font.GetHeight(&fh);
|
darken1 = tint_color(no_tint, B_DARKEN_1_TINT),
|
||||||
|
darken2 = tint_color(no_tint, B_DARKEN_2_TINT),
|
||||||
|
darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
|
||||||
|
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT),
|
||||||
|
nav = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
|
||||||
|
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
bool enabled = IsEnabled();
|
||||||
|
bool active = false;
|
||||||
|
|
||||||
|
if (fText->IsFocus() && Window()->IsActive())
|
||||||
|
active = true;
|
||||||
|
|
||||||
|
BRect rect(fText->Frame());
|
||||||
|
rect.InsetBy(-1.0f, -1.0f);
|
||||||
|
|
||||||
|
if (active)
|
||||||
|
{
|
||||||
|
SetHighColor(nav);
|
||||||
|
StrokeRect(rect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
SetHighColor(darken4);
|
||||||
|
else
|
||||||
|
SetHighColor(darken2);
|
||||||
|
|
||||||
|
StrokeLine(rect.LeftTop(), rect.LeftBottom());
|
||||||
|
StrokeLine(rect.LeftTop(), rect.RightTop());
|
||||||
|
|
||||||
|
SetHighColor(no_tint);
|
||||||
|
StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom());
|
||||||
|
StrokeLine(BPoint(rect.right, rect.top + 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.InsetBy(-1.0f, -1.0f);
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
SetHighColor(darken1);
|
||||||
|
else
|
||||||
|
SetHighColor(no_tint);
|
||||||
|
|
||||||
|
StrokeLine(rect.LeftBottom(), rect.LeftTop());
|
||||||
|
StrokeLine(rect.RightTop());
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
SetHighColor(lighten2);
|
||||||
|
else
|
||||||
|
SetHighColor(lighten1);
|
||||||
|
|
||||||
|
StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom());
|
||||||
|
StrokeLine(BPoint(rect.right, rect.top + 1.0f), rect.RightBottom());
|
||||||
|
|
||||||
if (Label())
|
if (Label())
|
||||||
{
|
{
|
||||||
float y = ceil(fh.ascent + fh.descent + fh.leading) + 2.0f;
|
font_height fh;
|
||||||
|
GetFontHeight(&fh);
|
||||||
|
|
||||||
|
float y = (float)ceil(fh.ascent + fh.descent + fh.leading) + 2.0f;
|
||||||
float x;
|
float x;
|
||||||
|
|
||||||
switch (fLabelAlign)
|
switch (fLabelAlign)
|
||||||
{
|
{
|
||||||
case B_ALIGN_RIGHT:
|
case B_ALIGN_RIGHT:
|
||||||
x = fDivider - font.StringWidth(Label()) - 3.0f;
|
x = fDivider - StringWidth(Label()) - 3.0f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ALIGN_CENTER:
|
case B_ALIGN_CENTER:
|
||||||
x = fDivider - font.StringWidth(Label())/2.0f;
|
x = fDivider - StringWidth(Label()) / 2.0f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -256,73 +296,111 @@ void BTextControl::Draw(BRect rect)
|
|||||||
IsEnabled() ? B_DARKEN_MAX_TINT : B_DISABLED_LABEL_TINT));
|
IsEnabled() ? B_DARKEN_MAX_TINT : B_DISABLED_LABEL_TINT));
|
||||||
DrawString(Label(), BPoint(x, y));
|
DrawString(Label(), BPoint(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
rect = fText->Frame();
|
|
||||||
|
|
||||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
|
|
||||||
rect.InsetBy(-1,-1);
|
|
||||||
SetHighColor(tint_color(base, IsEnabled() ?
|
|
||||||
B_DARKEN_1_TINT : B_DARKEN_2_TINT));
|
|
||||||
StrokeLine(BPoint(rect.left,rect.bottom), BPoint(rect.left, rect.top));
|
|
||||||
StrokeLine(BPoint(rect.left+1.0f,rect.top), BPoint(rect.right, rect.top));
|
|
||||||
SetHighColor(tint_color(base, IsEnabled() ?
|
|
||||||
B_LIGHTEN_MAX_TINT : B_LIGHTEN_2_TINT));
|
|
||||||
StrokeLine(BPoint(rect.left+1.0f,rect.bottom),
|
|
||||||
BPoint(rect.right, rect.bottom));
|
|
||||||
StrokeLine(BPoint(rect.right,rect.bottom),
|
|
||||||
BPoint(rect.right, rect.top+1.0f));
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::MouseDown(BPoint where)
|
void BTextControl::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (IsEnabled())
|
if (!fText->IsFocus())
|
||||||
{
|
{
|
||||||
MakeFocus(true);
|
fText->MakeFocus(true);
|
||||||
|
fText->SelectAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::AttachedToWindow()
|
void BTextControl::AttachedToWindow()
|
||||||
{
|
{
|
||||||
BControl::AttachedToWindow();
|
BControl::AttachedToWindow();
|
||||||
if (Parent())
|
|
||||||
{
|
|
||||||
SetViewColor(Parent()->ViewColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
float w;
|
bool enabled = IsEnabled();
|
||||||
float h;
|
rgb_color textColor;
|
||||||
GetPreferredSize(&w, &h);
|
rgb_color color = HighColor();
|
||||||
ResizeTo(Bounds().Width(), h);
|
BFont font;
|
||||||
fText->ResizeTo(fText->Bounds().Width(), h);
|
|
||||||
|
fText->GetFontAndColor(0, &font, &color);
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
textColor = color;
|
||||||
|
else
|
||||||
|
textColor = tint_color(color, B_LIGHTEN_2_TINT);
|
||||||
|
|
||||||
|
fText->SetFontAndColor(&font, B_FONT_ALL, &textColor);
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
color.red = 255;
|
||||||
|
color.green = 255;
|
||||||
|
color.blue = 255;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
color = tint_color(color, B_LIGHTEN_2_TINT);
|
||||||
|
|
||||||
|
fText->SetViewColor(color);
|
||||||
|
fText->SetLowColor(color);
|
||||||
|
|
||||||
|
fText->MakeEditable(enabled);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::MakeFocus(bool state)
|
void BTextControl::MakeFocus(bool state)
|
||||||
{
|
{
|
||||||
if (IsEnabled())
|
|
||||||
{
|
|
||||||
fText->MakeFocus(state);
|
fText->MakeFocus(state);
|
||||||
Invalidate();
|
|
||||||
}
|
if (state)
|
||||||
|
fText->SelectAll();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetEnabled(bool state)
|
void BTextControl::SetEnabled(bool state)
|
||||||
{
|
{
|
||||||
fText->SetEnabled(state);
|
if (IsEnabled() == state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Window())
|
||||||
|
{
|
||||||
|
fText->MakeEditable(state);
|
||||||
|
|
||||||
|
rgb_color textColor;
|
||||||
|
rgb_color color = {0, 0, 0, 255};
|
||||||
|
BFont font;
|
||||||
|
|
||||||
|
fText->GetFontAndColor(0, &font, &color);
|
||||||
|
|
||||||
|
if (state)
|
||||||
|
textColor = color;
|
||||||
|
else
|
||||||
|
textColor = tint_color(color, B_DISABLED_LABEL_TINT);
|
||||||
|
|
||||||
|
fText->SetFontAndColor(&font, B_FONT_ALL, &textColor);
|
||||||
|
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
color.red = 255;
|
||||||
|
color.green = 255;
|
||||||
|
color.blue = 255;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||||
|
B_LIGHTEN_2_TINT);
|
||||||
|
|
||||||
|
fText->SetViewColor(color);
|
||||||
|
fText->SetLowColor(color);
|
||||||
|
|
||||||
|
fText->Invalidate();
|
||||||
|
Window()->UpdateIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
BControl::SetEnabled(state);
|
BControl::SetEnabled(state);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::GetPreferredSize(float* width, float* height)
|
void BTextControl::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
font_height fh;
|
font_height fh;
|
||||||
font.GetHeight(&fh);
|
font.GetHeight(&fh);
|
||||||
|
|
||||||
*height = ceil(fh.ascent + fh.descent + fh.leading) + 7.0f;
|
*height = (float)ceil(fh.ascent + fh.descent + fh.leading) + 7.0f;
|
||||||
|
|
||||||
// TODO: this one I need to find out
|
// TODO: this one I need to find out
|
||||||
*width = 4.0f + ceil(font.StringWidth(Label()))*2.0f;
|
*width = 4.0f + (float)ceil(font.StringWidth(Label()))*2.0f;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::ResizeToPreferred()
|
void BTextControl::ResizeToPreferred()
|
||||||
@@ -335,36 +413,62 @@ void BTextControl::ResizeToPreferred()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::SetFlags(uint32 flags)
|
void BTextControl::SetFlags(uint32 flags)
|
||||||
{
|
{
|
||||||
|
if (!fSkipSetFlags)
|
||||||
|
{
|
||||||
|
// If the textview is navigable, set it to not navigable if needed
|
||||||
|
// Else if it is not navigable, set it to navigable if needed
|
||||||
|
if (fText->Flags() & B_NAVIGABLE)
|
||||||
|
{
|
||||||
|
if (!(flags & B_NAVIGABLE))
|
||||||
|
fText->SetFlags(fText->Flags() & ~B_NAVIGABLE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (flags & B_NAVIGABLE)
|
||||||
|
fText->SetFlags(fText->Flags() | B_NAVIGABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't make this one navigable
|
||||||
|
flags &= ~B_NAVIGABLE;
|
||||||
|
}
|
||||||
|
|
||||||
BView::SetFlags(flags);
|
BView::SetFlags(flags);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::MessageReceived(BMessage* msg)
|
void BTextControl::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch(msg->what)
|
switch(msg->what)
|
||||||
{
|
{
|
||||||
case B_CONTROL_MODIFIED:
|
case B_SET_PROPERTY:
|
||||||
if (fModificationMessage)
|
case B_GET_PROPERTY:
|
||||||
{
|
// TODO
|
||||||
BControl::Invoke(fModificationMessage);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BControl::MessageReceived(msg);
|
BControl::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BHandler* BTextControl::ResolveSpecifier(BMessage* msg, int32 index,
|
BHandler *BTextControl::ResolveSpecifier(BMessage *msg, int32 index,
|
||||||
BMessage* specifier, int32 form,
|
BMessage *specifier, int32 form,
|
||||||
const char* property)
|
const char *property)
|
||||||
{
|
{
|
||||||
return NULL;
|
/*
|
||||||
|
BPropertyInfo propInfo(prop_list);
|
||||||
|
BHandler *target = NULL;
|
||||||
|
|
||||||
|
if (propInfo.FindMatch(message, 0, specifier, what, property) < B_OK)
|
||||||
|
return BControl::ResolveSpecifier(message, index, specifier, what,
|
||||||
|
property);
|
||||||
|
else
|
||||||
|
return this;
|
||||||
|
*/
|
||||||
|
return BControl::ResolveSpecifier(msg, index, specifier, form, property);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTextControl::GetSupportedSuites(BMessage* data)
|
status_t BTextControl::GetSupportedSuites(BMessage *data)
|
||||||
{
|
{
|
||||||
return B_OK;
|
return BControl::GetSupportedSuites(data);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::MouseUp(BPoint pt)
|
void BTextControl::MouseUp(BPoint pt)
|
||||||
@@ -372,7 +476,7 @@ void BTextControl::MouseUp(BPoint pt)
|
|||||||
BControl::MouseUp(pt);
|
BControl::MouseUp(pt);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::MouseMoved(BPoint pt, uint32 code, const BMessage* msg)
|
void BTextControl::MouseMoved(BPoint pt, uint32 code, const BMessage *msg)
|
||||||
{
|
{
|
||||||
BControl::MouseMoved(pt, code, msg);
|
BControl::MouseMoved(pt, code, msg);
|
||||||
}
|
}
|
||||||
@@ -404,36 +508,87 @@ void BTextControl::FrameResized(float newWidth, float newHeight)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::WindowActivated(bool active)
|
void BTextControl::WindowActivated(bool active)
|
||||||
{
|
{
|
||||||
BControl::WindowActivated(active);
|
if (fText->IsFocus())
|
||||||
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BTextControl::Perform(perform_code d, void* arg)
|
status_t BTextControl::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return BControl::Perform(d, arg);
|
return BControl::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::_ReservedTextControl1()
|
void BTextControl::_ReservedTextControl1() {}
|
||||||
{
|
void BTextControl::_ReservedTextControl2() {}
|
||||||
}
|
void BTextControl::_ReservedTextControl3() {}
|
||||||
|
void BTextControl::_ReservedTextControl4() {}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BTextControl::_ReservedTextControl2()
|
BTextControl &BTextControl::operator=(const BTextControl&)
|
||||||
{
|
{
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BTextControl::_ReservedTextControl3()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BTextControl::_ReservedTextControl4()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BTextControl& BTextControl::operator=(const BTextControl&)
|
|
||||||
{
|
|
||||||
// Assignment not allowed
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
void BTextControl::CommitValue()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void BTextControl::InitData(const char *label, const char *initial_text,
|
||||||
|
BMessage *data)
|
||||||
|
{
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
|
fText = NULL;
|
||||||
|
//fLabel = NULL;
|
||||||
|
fModificationMessage = NULL;
|
||||||
|
fLabelAlign = B_ALIGN_LEFT;
|
||||||
|
fDivider = 0.0f;
|
||||||
|
fPrevWidth = 0;
|
||||||
|
fPrevHeight = 0;
|
||||||
|
//fClean = true;
|
||||||
|
fSkipSetFlags = false;
|
||||||
|
|
||||||
|
int32 flags = 0;
|
||||||
|
|
||||||
|
BFont font(be_bold_font);
|
||||||
|
|
||||||
|
if (!data || !data->HasString("_fname"))
|
||||||
|
flags = 1;
|
||||||
|
|
||||||
|
if (!data || !data->HasFloat("_fflt"))
|
||||||
|
flags |= 2;
|
||||||
|
|
||||||
|
if (flags != 0)
|
||||||
|
SetFont(&font, flags);
|
||||||
|
|
||||||
|
if (label)
|
||||||
|
fDivider = bounds.Width() / 2.0f;
|
||||||
|
|
||||||
|
if (Flags() & B_NAVIGABLE)
|
||||||
|
{
|
||||||
|
fSkipSetFlags = true;
|
||||||
|
SetFlags(Flags() & ~B_NAVIGABLE);
|
||||||
|
fSkipSetFlags = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
fText = (_BTextInput_*)FindView("_input_");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BRect frame(fDivider, bounds.top + 2.0f, bounds.right - 2.0f,
|
||||||
|
bounds.bottom - 2.0f);
|
||||||
|
BRect textRect(frame.OffsetToCopy(0.0f, 0.0f));
|
||||||
|
|
||||||
|
fText = new _BTextInput_(frame, textRect,
|
||||||
|
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS |
|
||||||
|
B_NAVIGABLE);
|
||||||
|
|
||||||
|
AddChild(fText);
|
||||||
|
|
||||||
|
SetText(initial_text);
|
||||||
|
fText->SetAlignment(B_ALIGN_LEFT);
|
||||||
|
fText->AlignTextRect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
+139
-139
@@ -46,197 +46,197 @@
|
|||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BTextInput_::_BTextInput_(BTextControl* parent, BRect frame, const char* name,
|
_BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask,
|
||||||
BRect rect, uint32 mask, uint32 flags)
|
uint32 flags)
|
||||||
: BTextView(frame, name, rect, mask, flags),
|
: BTextView(frame, "_input_", textRect, resizeMask, flags),
|
||||||
fEnabled(true),
|
fPreviousText(NULL),
|
||||||
fChanged(false),
|
fBool(false)
|
||||||
fParent(parent)
|
|
||||||
{
|
{
|
||||||
SetMaxBytes(255);
|
MakeResizable(true);
|
||||||
SetWordWrap(false);
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
_BTextInput_::_BTextInput_(BMessage *archive)
|
||||||
|
: BTextView(archive),
|
||||||
|
fPreviousText(NULL),
|
||||||
|
fBool(false)
|
||||||
|
{
|
||||||
|
MakeResizable(true);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
_BTextInput_::~_BTextInput_()
|
_BTextInput_::~_BTextInput_()
|
||||||
{
|
{
|
||||||
|
if (fPreviousText)
|
||||||
|
free(fPreviousText);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextInput_::SetEnabled(bool state)
|
BArchivable *_BTextInput_::Instantiate(BMessage *archive)
|
||||||
{
|
{
|
||||||
fEnabled = state;
|
if (validate_instantiation(archive, "_BTextInput_"))
|
||||||
if (fEnabled)
|
return new _BTextInput_(archive);
|
||||||
{
|
|
||||||
BView::SetFlags(Flags() | B_NAVIGABLE);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return NULL;
|
||||||
BView::SetFlags(Flags() & (0xffffffff - B_NAVIGABLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextInput_::AttachedToWindow()
|
status_t _BTextInput_::Archive(BMessage *data, bool deep) const
|
||||||
{
|
{
|
||||||
BFont font;
|
return BTextView::Archive(data, true);
|
||||||
GetFont(&font);
|
|
||||||
float h = font.Size() + 6.0f;
|
|
||||||
ResizeTo(Bounds().Width(), h);
|
|
||||||
|
|
||||||
fViewColor = BTextView::ViewColor();
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
rgb_color _BTextInput_::ViewColor()
|
void _BTextInput_::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
return fViewColor;
|
BTextView::FrameResized(width, height);
|
||||||
}
|
AlignTextRect();
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BTextInput_::SetViewColor(rgb_color color)
|
|
||||||
{
|
|
||||||
fViewColor = color;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void _BTextInput_::MakeFocus(bool state)
|
|
||||||
{
|
|
||||||
BTextView::MakeFocus(state);
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
BTextView::SetViewColor(255, 255, 255, 255);
|
|
||||||
fChanged = false;
|
|
||||||
SelectAll();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BTextView::SetViewColor(fViewColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool _BTextInput_::CanEndLine(int32 end)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextInput_::KeyDown(const char* bytes, int32 numBytes)
|
void _BTextInput_::KeyDown(const char* bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
bool send = false;
|
switch (*bytes)
|
||||||
|
|
||||||
BMessage* msg = Window()->CurrentMessage();
|
|
||||||
if (numBytes == 1)
|
|
||||||
{
|
{
|
||||||
switch (bytes[0])
|
|
||||||
{
|
|
||||||
case B_UP_ARROW:
|
|
||||||
msg->ReplaceInt64("when", (int64)system_time());
|
|
||||||
msg->ReplaceInt32("key", 38);
|
|
||||||
msg->ReplaceInt32("raw_char", B_TAB);
|
|
||||||
msg->ReplaceInt32("modifiers", B_SCROLL_LOCK | B_SHIFT_KEY);
|
|
||||||
msg->ReplaceInt8("byte", B_TAB);
|
|
||||||
msg->ReplaceString("bytes", "");
|
|
||||||
fParent->BView::MakeFocus(true);
|
|
||||||
Looper()->PostMessage(msg);
|
|
||||||
send = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case B_ENTER:
|
case B_ENTER:
|
||||||
{
|
{
|
||||||
|
if (!TextControl()->IsEnabled())
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(strcmp(Text(), fPreviousText) != 0)
|
||||||
|
{
|
||||||
|
TextControl()->Invoke();
|
||||||
|
free(fPreviousText);
|
||||||
|
fPreviousText = strdup(Text());
|
||||||
|
}
|
||||||
|
|
||||||
SelectAll();
|
SelectAll();
|
||||||
send = true;
|
|
||||||
fChanged = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_DOWN_ARROW:
|
|
||||||
msg->ReplaceInt64("when", (int64)system_time());
|
|
||||||
msg->ReplaceInt32("key", 38);
|
|
||||||
msg->ReplaceInt32("raw_char", B_TAB);
|
|
||||||
msg->ReplaceInt8("byte", B_TAB);
|
|
||||||
msg->ReplaceString("bytes", "");
|
|
||||||
Looper()->PostMessage(msg);
|
|
||||||
send = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case B_TAB:
|
case B_TAB:
|
||||||
// This will make sure that it will skip to the next object
|
|
||||||
BView::KeyDown(bytes, numBytes);
|
BView::KeyDown(bytes, numBytes);
|
||||||
send = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BTextView::KeyDown(bytes, numBytes);
|
BTextView::KeyDown(bytes, numBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
//------------------------------------------------------------------------------
|
||||||
{
|
void _BTextInput_::MakeFocus(bool state)
|
||||||
BTextView::KeyDown(bytes, numBytes);
|
{
|
||||||
}
|
if (state == IsFocus())
|
||||||
|
return;
|
||||||
|
|
||||||
if (send)
|
BTextView::MakeFocus(state);
|
||||||
|
|
||||||
|
if (state)
|
||||||
{
|
{
|
||||||
if (fChanged)
|
SetInitialText();
|
||||||
|
|
||||||
|
fBool = true;
|
||||||
|
|
||||||
|
if (Window())
|
||||||
{
|
{
|
||||||
Window()->PostMessage(new BMessage(B_CONTROL_INVOKED), fParent);
|
BMessage *msg = Window()->CurrentMessage();
|
||||||
|
|
||||||
|
if (msg && msg->what == B_KEY_DOWN)
|
||||||
|
SelectAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Window()->PostMessage(new BMessage(B_CONTROL_MODIFIED), fParent);
|
if (strcmp(Text(), fPreviousText) != 0)
|
||||||
|
TextControl()->Invoke();
|
||||||
|
|
||||||
|
free(fPreviousText);
|
||||||
|
fPreviousText = NULL;
|
||||||
|
fBool = false;
|
||||||
|
|
||||||
|
if (Window())
|
||||||
|
{
|
||||||
|
BMessage *msg = Window()->CurrentMessage();
|
||||||
|
|
||||||
|
if (msg && msg->what == B_MOUSE_DOWN)
|
||||||
|
{
|
||||||
|
Select(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fChanged = true;
|
if (Window())
|
||||||
|
{
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextInput_::MouseDown(BPoint where)
|
void _BTextInput_::AlignTextRect()
|
||||||
{
|
{
|
||||||
if (fEnabled)
|
// TODO
|
||||||
{
|
|
||||||
BTextView::MouseDown(where);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void _BTextInput_::Draw(BRect rect)
|
void _BTextInput_::SetInitialText()
|
||||||
{
|
{
|
||||||
|
if (fPreviousText)
|
||||||
BTextView::Draw(rect);
|
|
||||||
|
|
||||||
rect = Bounds();
|
|
||||||
|
|
||||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
SetHighColor(tint_color(base, fEnabled ?
|
|
||||||
B_DARKEN_4_TINT : B_LIGHTEN_2_TINT));
|
|
||||||
StrokeLine(BPoint(rect.left,rect.bottom), BPoint(rect.left, rect.top));
|
|
||||||
StrokeLine(BPoint(rect.left+1.0f,rect.top), BPoint(rect.right, rect.top));
|
|
||||||
SetHighColor(tint_color(base, B_NO_TINT));
|
|
||||||
StrokeLine(BPoint(rect.left+1.0f,rect.bottom),
|
|
||||||
BPoint(rect.right, rect.bottom));
|
|
||||||
StrokeLine(BPoint(rect.right,rect.bottom),
|
|
||||||
BPoint(rect.right, rect.top+1.0f));
|
|
||||||
|
|
||||||
if (IsFocus())
|
|
||||||
{
|
{
|
||||||
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
free(fPreviousText);
|
||||||
StrokeRect(rect);
|
fPreviousText = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fEnabled)
|
if (Text())
|
||||||
{
|
fPreviousText = strdup(Text());
|
||||||
rect.InsetBy(1,1);
|
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
|
||||||
rgb_color color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
|
||||||
B_LIGHTEN_1_TINT);
|
|
||||||
color.alpha = 140;
|
|
||||||
SetHighColor(color);
|
|
||||||
FillRect(rect);
|
|
||||||
SetDrawingMode(B_OP_COPY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
void _BTextInput_::Paste(BClipboard *clipboard)
|
||||||
|
{
|
||||||
|
BTextView::Paste(clipboard);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void _BTextInput_::InsertText(const char *inText, int32 inLength,
|
||||||
|
int32 inOffset, const text_run_array *inRuns)
|
||||||
|
{
|
||||||
|
char *buffer = NULL;
|
||||||
|
|
||||||
/*
|
if (strpbrk(inText, "\r\n") && inLength <= 1024)
|
||||||
* $Log $
|
{
|
||||||
*
|
buffer = (char*)malloc(inLength);
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
if (buffer)
|
||||||
|
{
|
||||||
|
strcpy(buffer, inText);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < inLength; i++)
|
||||||
|
if (buffer[i] == '\r' || buffer[i] == '\n')
|
||||||
|
buffer[i] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BTextView::InsertText(buffer ? buffer : inText, inLength, inOffset,
|
||||||
|
inRuns);
|
||||||
|
|
||||||
|
TextControl()->InvokeNotify(TextControl()->ModificationMessage(),
|
||||||
|
B_CONTROL_MODIFIED);
|
||||||
|
|
||||||
|
if (buffer)
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void _BTextInput_::DeleteText(int32 fromOffset, int32 toOffset)
|
||||||
|
{
|
||||||
|
BTextView::DeleteText(fromOffset, toOffset);
|
||||||
|
|
||||||
|
TextControl()->InvokeNotify(TextControl()->ModificationMessage(),
|
||||||
|
B_CONTROL_MODIFIED);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
BTextControl *_BTextInput_::TextControl()
|
||||||
|
{
|
||||||
|
BTextControl *textControl;
|
||||||
|
|
||||||
|
if (Parent())
|
||||||
|
textControl = dynamic_cast<BTextControl*>(Parent());
|
||||||
|
else
|
||||||
|
textControl = NULL;
|
||||||
|
|
||||||
|
if (!textControl)
|
||||||
|
debugger("_BTextInput_ should have a BTextControl as parent");
|
||||||
|
|
||||||
|
return textControl;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user