From 9cb2dbe29dbcf58bce0bd925316c77faafce43e0 Mon Sep 17 00:00:00 2001 From: Marc Flerackers Date: Mon, 16 Jun 2003 07:27:24 +0000 Subject: [PATCH] Fixes git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3536 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/TextInput.h | 45 +- src/kits/interface/Box.cpp | 750 +++++------ src/kits/interface/TabView.cpp | 1653 +++++++++++++------------ src/kits/interface/TextControl.cpp | 521 +++++--- src/kits/interface/TextInput.cpp | 326 ++--- 5 files changed, 1774 insertions(+), 1521 deletions(-) diff --git a/headers/private/interface/TextInput.h b/headers/private/interface/TextInput.h index f838aea59b..a2bec282ff 100644 --- a/headers/private/interface/TextInput.h +++ b/headers/private/interface/TextInput.h @@ -46,27 +46,36 @@ class BTextControl; // _BTextInput_ class ---------------------------------------------------------- class _BTextInput_ : public BTextView { public: - _BTextInput_(BTextControl* parent, BRect frame, - const char* name, BRect rect, - uint32 mask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - ~_BTextInput_(); + _BTextInput_(BRect frame, BRect textRect, + uint32 resizeMask, + uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED); + _BTextInput_(BMessage *data); + ~_BTextInput_(); - virtual void AttachedToWindow(); - virtual void MakeFocus(bool state = true); - virtual void SetViewColor(rgb_color); - rgb_color ViewColor(); - virtual bool CanEndLine(int32); - virtual void KeyDown(const char* bytes, int32 numBytes); - virtual void Draw(BRect); - virtual void SetEnabled(bool state); - virtual void MouseDown(BPoint where); +static BArchivable* Instantiate(BMessage *data); +virtual status_t Archive(BMessage *data, bool deep = true) const; + +virtual void FrameResized(float width, float height); +virtual void KeyDown(const char *bytes, int32 numBytes); +virtual void MakeFocus(bool focusState = true); + + void AlignTextRect(); + 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: - rgb_color fViewColor; - bool fEnabled; - bool fChanged; - BTextControl* fParent; + + BTextControl *TextControl(); + + char *fPreviousText; + bool fBool; }; //------------------------------------------------------------------------------ diff --git a/src/kits/interface/Box.cpp b/src/kits/interface/Box.cpp index 5b0188569b..41159fc7a3 100644 --- a/src/kits/interface/Box.cpp +++ b/src/kits/interface/Box.cpp @@ -1,362 +1,388 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Box.cpp -// Author: Marc Flerackers (mflerackers@androme.be) -// Description: BBox objects group views together and draw a border -// around them. -//------------------------------------------------------------------------------ - -// Standard Includes ----------------------------------------------------------- -#include - -// System Includes ------------------------------------------------------------- -#include -#include -#include - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -//------------------------------------------------------------------------------ -BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags, - border_style border) - : BView(frame, name, resizingMode, flags), - fLabel(NULL), - fStyle(border), - fLabelView(NULL) -{ - fBounds = Bounds(); - - SetFont(be_bold_font); - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); -} -//------------------------------------------------------------------------------ -BBox::~BBox() -{ - if (fLabel) - delete fLabel; -} -//------------------------------------------------------------------------------ -BBox::BBox(BMessage *archive) - : BView(archive) -{ - fBounds = Bounds(); - fLabelView = NULL; - - const char *string; - - if (archive->FindString("_label", &string) != B_OK) - fLabel = NULL; - else - SetLabel(string); - - int32 anInt32; - - if (archive->FindInt32("_style", &anInt32) != B_OK) - fStyle = B_FANCY_BORDER; - else - fStyle = (border_style)anInt32; -} -//------------------------------------------------------------------------------ -BArchivable *BBox::Instantiate(BMessage *archive) -{ - if ( validate_instantiation ( archive, "BBox" ) ) - return new BBox ( archive ); - else - return NULL; -} -//------------------------------------------------------------------------------ -status_t BBox::Archive(BMessage *archive, bool deep) const -{ - status_t err = BView::Archive(archive, deep); - - if (err != B_OK) - return err; - - if (fLabel) - err = archive->AddString("_label",fLabel); - - if (err != B_OK) - return err; - - if (fStyle != B_FANCY_BORDER) - err = archive->AddInt32("_style", fStyle); - - return err; -} -//------------------------------------------------------------------------------ -void BBox::SetBorder(border_style border) -{ - fStyle = border; - - Invalidate(); -} -//------------------------------------------------------------------------------ -border_style BBox::Border() const -{ - return fStyle; -} -//------------------------------------------------------------------------------ -void BBox::SetLabel(const char *string) -{ - if (fLabel) - delete fLabel; - - fLabel = strdup(string); - - // Update fBounds - fBounds = Bounds(); - - if (fLabel) - { - font_height fh; - GetFontHeight(&fh); - - fBounds.top = (float)ceil((fh.ascent + fh.descent) / 2.0f); - } - - Invalidate(); -} -//------------------------------------------------------------------------------ -status_t BBox::SetLabel(BView *viewLabel) -{ - if (viewLabel) - { - if (fLabelView) - RemoveChild(fLabelView); - - fLabelView = viewLabel; - AddChild(fLabelView); - - if(fLabel) - { - delete fLabel; - fLabel = NULL; - } - } - - // Update fBounds - fBounds = Bounds(); - - if (fLabelView) - fBounds.top = (float)ceil(fLabelView->Frame().Height() / 2.0f); - - Invalidate(); - - return B_OK; -} -//------------------------------------------------------------------------------ -const char *BBox::Label() const -{ - return fLabel; -} -//------------------------------------------------------------------------------ -BView *BBox::LabelView() const -{ - return fLabelView; -} -//------------------------------------------------------------------------------ -void BBox::Draw(BRect updateRect) -{ - switch (fStyle) - { - case B_FANCY_BORDER: - DrawFancy(); - break; - - case B_PLAIN_BORDER: - DrawPlain(); - break; - - default: - break; - } - - if (fLabel) - { - font_height fh; - GetFontHeight(&fh); - - SetHighColor(ViewColor()); - - FillRect(BRect(6.0f, 1.0f, 12.0f + StringWidth(fLabel), - (float)ceil(fh.ascent + fh.descent))/*, B_SOLID_LOW*/); - - SetHighColor(0, 0, 0); - DrawString(fLabel, BPoint(10.0f, (float)ceil(fh.ascent - fh.descent) + 1.0f )); - } -} -//------------------------------------------------------------------------------ -void BBox::AttachedToWindow() -{ - if (Parent()) - { - SetViewColor(Parent()->ViewColor()); - SetLowColor(Parent()->ViewColor()); - } -} -//------------------------------------------------------------------------------ -void BBox::DetachedFromWindow() -{ - BView::DetachedFromWindow(); -} -//------------------------------------------------------------------------------ -void BBox::AllAttached() -{ - BView::AllAttached(); -} -//------------------------------------------------------------------------------ -void BBox::AllDetached() -{ - BView::AllDetached(); -} -//------------------------------------------------------------------------------ -void BBox::FrameResized(float width, float height) -{ - fBounds.right = Bounds().right; - fBounds.bottom = Bounds().bottom; -} -//------------------------------------------------------------------------------ -void BBox::MessageReceived(BMessage *message) -{ - BView::MessageReceived(message); -} -//------------------------------------------------------------------------------ -void BBox::MouseDown(BPoint point) -{ - BView::MouseDown(point); -} -//------------------------------------------------------------------------------ -void BBox::MouseUp(BPoint point) -{ - BView::MouseUp(point); -} -//------------------------------------------------------------------------------ -void BBox::WindowActivated(bool active) -{ - BView::WindowActivated(active); -} -//------------------------------------------------------------------------------ -void BBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message) -{ - BView::MouseMoved(point, transit, message); -} -//------------------------------------------------------------------------------ -void BBox::FrameMoved(BPoint newLocation) -{ - BView::FrameMoved(newLocation); -} -//------------------------------------------------------------------------------ -BHandler *BBox::ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, int32 what, - const char *property) -{ - return BView::ResolveSpecifier(message, index, specifier, what, property); -} -//------------------------------------------------------------------------------ -void BBox::ResizeToPreferred() -{ - BView::ResizeToPreferred(); -} -//------------------------------------------------------------------------------ -void BBox::GetPreferredSize(float *width, float *height) -{ - BRect rect(0,0,99,99); - - if (Parent()) - { - rect = Parent()->Bounds(); - rect.InsetBy(10,10); - } - - *width = rect.Width(); - *height = rect.Height(); -} -//------------------------------------------------------------------------------ -void BBox::MakeFocus(bool focused) -{ - BView::MakeFocus(focused); -} -//------------------------------------------------------------------------------ -status_t BBox::GetSupportedSuites(BMessage *message) -{ - return BView::GetSupportedSuites(message); -} -//------------------------------------------------------------------------------ -status_t BBox::Perform(perform_code d, void *arg) -{ - return B_ERROR; -} -//------------------------------------------------------------------------------ -void BBox::_ReservedBox1() {} -void BBox::_ReservedBox2() {} -//------------------------------------------------------------------------------ -BBox &BBox::operator=(const BBox &) -{ - return *this; -} -//------------------------------------------------------------------------------ -void BBox::InitObject(BMessage *data) -{ -} -//------------------------------------------------------------------------------ -void BBox::DrawPlain() -{ - BRect rect = fBounds; - - SetHighColor(tint_color(ViewColor(), B_LIGHTEN_MAX_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(ViewColor(), B_DARKEN_3_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 BBox::DrawFancy() -{ - BRect rect = fBounds; - - SetHighColor(tint_color(ViewColor(), B_LIGHTEN_MAX_TINT)); - rect.left++; - rect.top++; - StrokeRect(rect); - SetHighColor(tint_color(ViewColor(), B_DARKEN_3_TINT)); - rect.OffsetBy(-1,-1); - StrokeRect(rect); -} -//------------------------------------------------------------------------------ -void BBox::ClearAnyLabel() -{ -} -//------------------------------------------------------------------------------ - -/* - * $Log $ - * - * $Id $ - * - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: Box.cpp +// Author: Marc Flerackers (mflerackers@androme.be) +// Description: BBox objects group views together and draw a border +// around them. +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include + +// System Includes ------------------------------------------------------------- +#include +#include +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags, + border_style border) + : BView(frame, name, resizingMode, flags) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + InitObject(); +} +//------------------------------------------------------------------------------ +BBox::~BBox() +{ + ClearAnyLabel(); +} +//------------------------------------------------------------------------------ +BBox::BBox(BMessage *archive) + : BView(archive) +{ + InitObject(archive); + + const char *string; + + if (archive->FindString("_label", &string) == B_OK) + SetLabel(string); + + bool aBool; + int32 anInt32; + + if (archive->FindBool("_style", &aBool) == B_OK) + fStyle = aBool ? B_FANCY_BORDER : B_PLAIN_BORDER; + else if (archive->FindInt32("_style", &anInt32) == B_OK) + fStyle = (border_style)anInt32; + + if (archive->FindBool("_lblview", &aBool) == B_OK) + fLabelView = ChildAt(0); +} +//------------------------------------------------------------------------------ +BArchivable *BBox::Instantiate(BMessage *archive) +{ + if (validate_instantiation(archive, "BBox")) + return new BBox(archive); + else + return NULL; +} +//------------------------------------------------------------------------------ +status_t BBox::Archive(BMessage *archive, bool deep) const +{ + BView::Archive(archive, deep); + + if (fLabel) + archive->AddString("_label", fLabel); + + if (fLabelView) + archive->AddBool("_lblview", true); + + if (fStyle != B_FANCY_BORDER) + archive->AddInt32("_style", fStyle); + + return B_OK; +} +//------------------------------------------------------------------------------ +void BBox::SetBorder(border_style border) +{ + fStyle = border; + + LockLooper(); + Invalidate(); + UnlockLooper(); +} +//------------------------------------------------------------------------------ +border_style BBox::Border() const +{ + return fStyle; +} +//------------------------------------------------------------------------------ +void BBox::SetLabel(const char *string) +{ + ClearAnyLabel(); + + if (string) + { + // Update fBounds + fBounds = Bounds(); + font_height fh; + GetFontHeight(&fh); + + fBounds.top = (float)ceil((fh.ascent + fh.descent) / 2.0f); + + fLabel = strdup(string); + } + + if (Window()) + Invalidate(); +} +//------------------------------------------------------------------------------ +status_t BBox::SetLabel(BView *viewLabel) +{ + ClearAnyLabel(); + + if (viewLabel) + { + // Update fBounds + fBounds = Bounds(); + font_height fh; + GetFontHeight(&fh); + + fBounds.top = (float)ceil(viewLabel->Bounds().Height() / 2.0f); + + fLabelView = viewLabel; + fLabelView->MoveTo(10.0f, 0.0f); + AddChild(fLabelView, ChildAt(0)); + } + + if (Window()) + Invalidate(); + + return B_OK; +} +//------------------------------------------------------------------------------ +const char *BBox::Label() const +{ + return fLabel; +} +//------------------------------------------------------------------------------ +BView *BBox::LabelView() const +{ + return fLabelView; +} +//------------------------------------------------------------------------------ +void BBox::Draw(BRect updateRect) +{ + switch (fStyle) + { + case B_FANCY_BORDER: + DrawFancy(); + break; + + case B_PLAIN_BORDER: + DrawPlain(); + break; + + default: + break; + } + + if (fLabel) + { + font_height fh; + GetFontHeight(&fh); + + SetHighColor(ViewColor()); + + FillRect(BRect(6.0f, 1.0f, 12.0f + StringWidth(fLabel), + (float)ceil(fh.ascent + fh.descent))/*, B_SOLID_LOW*/); + + SetHighColor(0, 0, 0); + DrawString(fLabel, BPoint(10.0f, (float)ceil(fh.ascent - fh.descent) + + 1.0f)); + } +} +//------------------------------------------------------------------------------ +void BBox::AttachedToWindow() +{ + if (Parent()) + { + SetViewColor(Parent()->ViewColor()); + SetLowColor(Parent()->ViewColor()); + } +} +//------------------------------------------------------------------------------ +void BBox::DetachedFromWindow() +{ + BView::DetachedFromWindow(); +} +//------------------------------------------------------------------------------ +void BBox::AllAttached() +{ + BView::AllAttached(); +} +//------------------------------------------------------------------------------ +void BBox::AllDetached() +{ + BView::AllDetached(); +} +//------------------------------------------------------------------------------ +void BBox::FrameResized(float width, float height) +{ + BRect bounds(Bounds()); + + fBounds.right = Bounds().right; + fBounds.bottom = Bounds().bottom; + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BBox::MessageReceived(BMessage *message) +{ + BView::MessageReceived(message); +} +//------------------------------------------------------------------------------ +void BBox::MouseDown(BPoint point) +{ + BView::MouseDown(point); +} +//------------------------------------------------------------------------------ +void BBox::MouseUp(BPoint point) +{ + BView::MouseUp(point); +} +//------------------------------------------------------------------------------ +void BBox::WindowActivated(bool active) +{ + BView::WindowActivated(active); +} +//------------------------------------------------------------------------------ +void BBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message) +{ + BView::MouseMoved(point, transit, message); +} +//------------------------------------------------------------------------------ +void BBox::FrameMoved(BPoint newLocation) +{ + BView::FrameMoved(newLocation); +} +//------------------------------------------------------------------------------ +BHandler *BBox::ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, int32 what, + const char *property) +{ + return BView::ResolveSpecifier(message, index, specifier, what, property); +} +//------------------------------------------------------------------------------ +void BBox::ResizeToPreferred() +{ + BView::ResizeToPreferred(); +} +//------------------------------------------------------------------------------ +void BBox::GetPreferredSize(float *width, float *height) +{ +/* BRect rect(0,0,99,99); + + if (Parent()) + { + rect = Parent()->Bounds(); + rect.InsetBy(10,10); + } + + *width = rect.Width(); + *height = rect.Height();*/ + + BView::GetPreferredSize(width, height); +} +//------------------------------------------------------------------------------ +void BBox::MakeFocus(bool focused) +{ + BView::MakeFocus(focused); +} +//------------------------------------------------------------------------------ +status_t BBox::GetSupportedSuites(BMessage *message) +{ + return BView::GetSupportedSuites(message); +} +//------------------------------------------------------------------------------ +status_t BBox::Perform(perform_code d, void *arg) +{ + return BView::Perform(d, arg); +} +//------------------------------------------------------------------------------ +void BBox::_ReservedBox1() {} +void BBox::_ReservedBox2() {} +//------------------------------------------------------------------------------ +BBox &BBox::operator=(const BBox &) +{ + return *this; +} +//------------------------------------------------------------------------------ +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() +{ + BRect rect = fBounds; + + SetHighColor(tint_color(ViewColor(), B_LIGHTEN_MAX_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(ViewColor(), B_DARKEN_3_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 BBox::DrawFancy() +{ + BRect rect = fBounds; + + SetHighColor(tint_color(ViewColor(), B_LIGHTEN_MAX_TINT)); + rect.left++; + rect.top++; + StrokeRect(rect); + SetHighColor(tint_color(ViewColor(), B_DARKEN_3_TINT)); + rect.OffsetBy(-1,-1); + StrokeRect(rect); +} +//------------------------------------------------------------------------------ +void BBox::ClearAnyLabel() +{ + if (fLabel) + { + free(fLabel); + fLabel = NULL; + } + else if (fLabelView) + { + fLabelView->RemoveSelf(); + delete fLabelView; + fLabelView = NULL; + } +} +//------------------------------------------------------------------------------ + +/* + * $Log $ + * + * $Id $ + * + */ diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp index 01e5d31858..904e57d96f 100644 --- a/src/kits/interface/TabView.cpp +++ b/src/kits/interface/TabView.cpp @@ -1,795 +1,858 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: TabView.cpp -// Author: Marc Flerackers (mflerackers@androme.be) -// Description: BTab creates individual "tabs" that can be assigned -// to specific views. -// BTabView provides the framework for containing and -// managing groups of BTab objects. -//------------------------------------------------------------------------------ - -// Standard Includes ----------------------------------------------------------- - -// System Includes ------------------------------------------------------------- -#include -#include -#include -#include -#include - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -//------------------------------------------------------------------------------ -BTab::BTab(BView *tabView) - : fEnabled(true), - fSelected(false), - fFocus(false), - fView(tabView) -{ -} -//------------------------------------------------------------------------------ -BTab::~BTab() -{ - if (fView->Window() != NULL) - { - fView->RemoveSelf(); - - delete fView; - } -} -//------------------------------------------------------------------------------ -BTab::BTab(BMessage *archive) - : fSelected(false), - fFocus(false), - fView(NULL) -{ - if (archive->FindBool("_disable", &fEnabled) != B_OK) - fEnabled = true; - else - fEnabled = !fEnabled; -} -//------------------------------------------------------------------------------ -BArchivable *BTab::Instantiate(BMessage *archive) -{ - if (validate_instantiation(archive, "BTab")) - return new BTab(archive); - else - return NULL; -} -//------------------------------------------------------------------------------ -status_t BTab::Archive(BMessage *archive, bool deep) const -{ - status_t err = BArchivable::Archive(archive, deep); - - if (err != B_OK) - return err; - - if ( !fEnabled ) - err = archive->AddBool("_disable", false); - - return err; -} -//------------------------------------------------------------------------------ -status_t BTab::Perform(uint32 d, void *arg) -{ - return B_ERROR; -} -//------------------------------------------------------------------------------ -const char *BTab::Label() const -{ - if (fView) - return fView->Name(); - else - return NULL; -} -//------------------------------------------------------------------------------ -void BTab::SetLabel(const char *label) -{ - if (fView) - fView->SetName(label); -} -//------------------------------------------------------------------------------ -bool BTab::IsSelected() const -{ - return fSelected; -} -//------------------------------------------------------------------------------ -void BTab::Select(BView *owner) -{ - dynamic_cast(owner)->ContainerView()->AddChild(fView); - - fSelected = true; -} -//------------------------------------------------------------------------------ -void BTab::Deselect() -{ - fView->RemoveSelf(); - - fSelected = false; -} -//------------------------------------------------------------------------------ -void BTab::SetEnabled(bool enabled) -{ - fEnabled = enabled; -} -//------------------------------------------------------------------------------ -bool BTab::IsEnabled() const -{ - return fEnabled; -} -//------------------------------------------------------------------------------ -void BTab::MakeFocus(bool inFocus) -{ - fFocus = inFocus; -} -//------------------------------------------------------------------------------ -bool BTab::IsFocus() const -{ - return fFocus; -} -//------------------------------------------------------------------------------ -void BTab::SetView(BView *view) -{ - // TODO: do we need to remove the previous view and add the new one if - // selected? - fView = view; -} -//------------------------------------------------------------------------------ -BView *BTab::View() const -{ - return fView; -} -//------------------------------------------------------------------------------ -void BTab::DrawFocusMark(BView *owner, BRect frame) -{ - float width = owner->StringWidth(Label()); - - owner->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); - owner->StrokeLine(BPoint(frame.left + frame.Width() * 0.5f - width * 0.5f, frame.bottom), - BPoint(frame.left + frame.Width() * 0.5f + width * 0.5f, frame.bottom)); -} -//------------------------------------------------------------------------------ -void BTab::DrawLabel(BView *owner, BRect frame) -{ - const char *label = Label(); - - if (label) - { - owner->SetHighColor(0, 0, 0); - owner->DrawString(label, BPoint(frame.left + frame.Width() * 0.5f - - owner->StringWidth(label) * 0.5f, frame.bottom - 4.0f - 2.0f)); - } -} -//------------------------------------------------------------------------------ -void BTab::DrawTab(BView *owner, BRect frame, tab_position position, bool full) -{ - rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), - lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), - darken4 = tint_color(no_tint, B_DARKEN_4_TINT), - darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); - - owner->SetHighColor(darkenmax); - owner->SetLowColor(no_tint); - DrawLabel(owner, frame); - - owner->BeginLineArray(12); - - if (position != B_TAB_ANY) - { - owner->AddLine(BPoint(frame.left - 2.0f, frame.bottom), - BPoint(frame.left - 1.0f, frame.bottom - 1.0f), lightenmax); - owner->AddLine(BPoint(frame.left, frame.bottom - 2.0f), - BPoint(frame.left, frame.bottom - 3.0f), lightenmax); - } - - owner->AddLine(BPoint(frame.left + 1.0f, frame.bottom - 4.0f), - BPoint(frame.left + 1.0f, frame.top + 5.0f), lightenmax); - owner->AddLine(BPoint(frame.left + 1.0f, frame.top + 4.0f), - BPoint(frame.left + 2.0f, frame.top + 2.0f), lightenmax); - owner->AddLine(BPoint(frame.left + 3.0f, frame.top + 1.0f), - BPoint(frame.left + 4.0f, frame.top + 1.0f), lightenmax); - owner->AddLine(BPoint(frame.left + 5.0f, frame.top), - BPoint(frame.right - 5.0f, frame.top), lightenmax); - - owner->AddLine(BPoint(frame.right - 4.0f, frame.top + 1.0f), - BPoint(frame.right - 3.0f, frame.top + 1.0f), lightenmax); - - owner->AddLine(BPoint(frame.right - 2.0f, frame.top + 2.0f), - BPoint(frame.right - 2.0f, frame.top + 3.0f), darken4); - owner->AddLine(BPoint(frame.right - 1.0f, frame.top + 4.0f), - BPoint(frame.right - 1.0f, frame.bottom - 4.0f), darken4); - - if (full) - { - owner->AddLine(BPoint(frame.right, frame.bottom - 3.0f), - BPoint(frame.right, frame.bottom - 2.0f), darken4); - owner->AddLine(BPoint(frame.right + 1.0f, frame.bottom - 1.0f), - BPoint(frame.right + 2.0f, frame.bottom), darken4); - } - - owner->EndLineArray(); -} -//------------------------------------------------------------------------------ -void BTab::_ReservedTab1() {} -void BTab::_ReservedTab2() {} -void BTab::_ReservedTab3() {} -void BTab::_ReservedTab4() {} -void BTab::_ReservedTab5() {} -void BTab::_ReservedTab6() {} -void BTab::_ReservedTab7() {} -void BTab::_ReservedTab8() {} -void BTab::_ReservedTab9() {} -void BTab::_ReservedTab10() {} -void BTab::_ReservedTab11() {} -void BTab::_ReservedTab12() {} -//------------------------------------------------------------------------------ -BTab &BTab::operator=(const BTab &) -{ - return *this; -} -//------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -BTabView::BTabView(BRect frame, const char *name, button_width width, - uint32 resizingMode, uint32 flags) - : BView(frame, name, resizingMode, flags), - fTabWidthSetting(width), - fTabWidth(0.0f), - fSelection(-1), - fInitialSelection(-1), - fFocus(-1) -{ - fTabList = new BList; - - //font_height fh; - //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() -{ - for (int32 i = 0; i < CountTabs(); i++) - delete TabAt(i); - - delete fTabList; -} -//------------------------------------------------------------------------------ -BTabView::BTabView(BMessage *archive) - : BView(archive), - fInitialSelection(-1), - fFocus(-1) -{ - fTabList = new BList; - - if (archive->FindFloat("_high", &fTabHeight) != B_OK) - { - //font_height fh; - //GetFontHeight(&fh); - //fTabHeight = fh.ascent + fh.descent + 8.0f; - fTabHeight = 20.0f; - } - - if (archive->FindInt16("_but_width", (int16*)&fTabWidthSetting) != B_OK) - fTabWidthSetting = B_WIDTH_AS_USUAL; - - if (archive->FindInt32("_sel", &fSelection) != B_OK) - fSelection = -1; - - int32 i = 0; - BMessage msg; - - while (archive->FindMessage("_l_items", i++, &msg) == B_OK) - { - BTab *tab = dynamic_cast(instantiate_object(&msg)); - - if (tab) - AddTab(NULL, tab); - } - - 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); -} -//------------------------------------------------------------------------------ -BArchivable *BTabView::Instantiate(BMessage *archive) -{ - if ( validate_instantiation(archive, "BTabView")) - return new BTabView(archive); - else - return NULL; -} -//------------------------------------------------------------------------------ -status_t BTabView::Archive(BMessage *archive, bool deep) const -{ - status_t err = BView::Archive(archive, deep); - - if (err != B_OK) - return err; - - err = archive->AddFloat("_high", fTabHeight); - - if (err != B_OK) - 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) - { - BMessage tabArchive; - - for (int32 i = 0; i < CountTabs(); i++) - if ((err = TabAt(i)->Archive(&tabArchive, deep)) == B_OK) - archive->AddMessage("_l_items", &tabArchive); - else - return err; - } - - return B_OK; -} -//------------------------------------------------------------------------------ -status_t BTabView::Perform(perform_code d, void *arg) -{ - return B_ERROR; -} -//------------------------------------------------------------------------------ -void BTabView::WindowActivated(bool active) -{ - BView::WindowActivated(active); - - DrawTabs(); -} -//------------------------------------------------------------------------------ -void BTabView::AttachedToWindow() -{ - BView::AttachedToWindow(); - - // TODO: check if this color is set in the BeOS implementation - //if (Parent()) - // SetViewColor(Parent()->ViewColor ()); - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - Select(0); -} -//------------------------------------------------------------------------------ -void BTabView::AllAttached() -{ - BView::AllAttached(); -} -//------------------------------------------------------------------------------ -void BTabView::AllDetached() -{ - BView::AllDetached(); -} -//------------------------------------------------------------------------------ -void BTabView::DetachedFromWindow() -{ - BView::DetachedFromWindow(); -} -//------------------------------------------------------------------------------ -void BTabView::MessageReceived(BMessage *message) -{ - BView::MessageReceived(message); -} -//------------------------------------------------------------------------------ -void BTabView::FrameMoved(BPoint newLocation) -{ - BView::FrameMoved(newLocation); -} -//------------------------------------------------------------------------------ -void BTabView::FrameResized(float width,float height) -{ - BView::FrameResized(width, height); -} -//------------------------------------------------------------------------------ -void BTabView::KeyDown(const char *bytes, int32 numBytes) -{ - switch (bytes[0]) - { - case B_DOWN_ARROW: - case B_LEFT_ARROW: - { - SetFocusTab((fFocus - 1) % CountTabs(), true); - break; - } - case B_UP_ARROW: - case B_RIGHT_ARROW: - { - SetFocusTab((fFocus + 1) % CountTabs(), true); - break; - } - case B_RETURN: - case B_SPACE: - { - Select(FocusTab()); - break; - } - default: - BView::KeyDown(bytes, numBytes); - } -} -//------------------------------------------------------------------------------ -void BTabView::MouseDown(BPoint point) -{ - if (point.y <= fTabHeight) - { - for (int32 i = 0; i < CountTabs(); i++) - { - if (TabFrame(i).Contains(point)) - { - Select(i); - return; - } - } - } - else - BView::MouseDown(point); -} -//------------------------------------------------------------------------------ -void BTabView::MouseUp(BPoint point) -{ - BView::MouseUp(point); -} -//------------------------------------------------------------------------------ -void BTabView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) -{ - BView::MouseMoved(point, transit, message); -} -//------------------------------------------------------------------------------ -void BTabView::Pulse() -{ - BView::Pulse(); -} -//------------------------------------------------------------------------------ -void BTabView::Select(int32 tab) -{ - if (tab < 0 || tab >= CountTabs()) - return; - - if (tab == fSelection) - return; - - if (fSelection != -1) - TabAt(fSelection)->Deselect(); - - if (tab != -1) - TabAt(tab)->Select(this); - - fSelection = tab; - - Invalidate(); -} -//------------------------------------------------------------------------------ -int32 BTabView::Selection() const -{ - return fSelection; -} -//------------------------------------------------------------------------------ -void BTabView::MakeFocus(bool focused) -{ - BView::MakeFocus(focused); - - SetFocusTab(Selection(), focused); -} -//------------------------------------------------------------------------------ -void BTabView::SetFocusTab(int32 tab, bool focused) -{ - if (tab < 0 || tab >= CountTabs()) - return; - - if (focused) - { - if (tab == fFocus) - return; - - if (fFocus != -1) - TabAt (fFocus)->MakeFocus(false); - - TabAt(tab)->MakeFocus(true); - fFocus = tab; - } - else if (fFocus != -1) - { - TabAt (fFocus)->MakeFocus(false); - fFocus = -1; - } - - Invalidate(); -} -//------------------------------------------------------------------------------ -int32 BTabView::FocusTab() const -{ - return fFocus; -} -//------------------------------------------------------------------------------ -void BTabView::Draw(BRect updateRect) -{ - DrawBox(DrawTabs()); - - if (IsFocus() && fFocus != -1) - TabAt(fFocus)->DrawFocusMark(this, TabFrame(fFocus)); -} -//------------------------------------------------------------------------------ -BRect BTabView::DrawTabs() -{ - for(int32 i = 0; i < CountTabs(); i++) - TabAt(i)->DrawTab(this, TabFrame(i), - (i == fSelection) ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY, - (i + 1 != fSelection)); - - if (fSelection > -1) - return TabFrame(fSelection); - else - return BRect(); -} -//------------------------------------------------------------------------------ -void BTabView::DrawBox(BRect selTabRect) -{ - BRect rect = Bounds(); - - SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_LIGHTEN_MAX_TINT)); - - StrokeLine(BPoint(0.0f, rect.bottom), BPoint(0.0f, selTabRect.bottom)); - StrokeLine(BPoint(selTabRect.left - 3.0f, selTabRect.bottom)); - StrokeLine(BPoint(selTabRect.right + 3.0f, selTabRect.bottom), - BPoint(rect.right - 1.0f, selTabRect.bottom)); - - SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - - StrokeLine(BPoint(rect.right, selTabRect.bottom + 1.0f), - BPoint(rect.right, rect.bottom)); - StrokeLine(BPoint(rect.left + 1.0f, rect.bottom)); -} -//------------------------------------------------------------------------------ -BRect BTabView::TabFrame(int32 tab_index) const -{ - switch (fTabWidthSetting) - { - case B_WIDTH_FROM_LABEL: - { - float x = 6.0f; - - for (int32 i = 0; i < tab_index; i++) - x += StringWidth(TabAt(i)->Label()) + 20.0f; - - return BRect(x, 0.0f, - x + StringWidth(TabAt(tab_index)->Label()) + 20.0f, fTabHeight); - break; - } - case B_WIDTH_FROM_WIDEST: - { - float width = 0.0f; - - for (int32 i = 0; i < CountTabs(); i++) - { - float tabWidth = StringWidth(TabAt(i)->Label()) + 20.0f; - - if (tabWidth > width) - width = tabWidth; - } - - return BRect((6.0f + tab_index * width), 0.0f, - (6.0f + tab_index * width + width), fTabHeight); - break; - } - case B_WIDTH_AS_USUAL: - default: - { - return BRect((6.0f + tab_index * 100.0f), 0.0f, - (6.0f + tab_index * 100.0f + 100.0f), fTabHeight); - break; - } - } -} -//------------------------------------------------------------------------------ -void BTabView::SetFlags(uint32 flags) -{ - BView::SetFlags(flags); -} -//------------------------------------------------------------------------------ -void BTabView::SetResizingMode(uint32 mode) -{ - BView::SetResizingMode(mode); -} -//------------------------------------------------------------------------------ -void BTabView::GetPreferredSize(float *width, float *height) -{ - *width = Bounds().Width(); - *height = Bounds().Height(); -} -//------------------------------------------------------------------------------ -void BTabView::ResizeToPreferred() -{ - float width, height; - GetPreferredSize(&width, &height); - BView::ResizeTo(width, height); -} -//------------------------------------------------------------------------------ -BHandler *BTabView::ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, int32 what, const char *property) -{ - return BView::ResolveSpecifier(message, index, specifier, what, property); -} -//------------------------------------------------------------------------------ -status_t BTabView::GetSupportedSuites(BMessage *message) -{ - return BView::GetSupportedSuites(message); -} -//------------------------------------------------------------------------------ -void BTabView::AddTab(BView *target, BTab *tab) -{ - if (tab == NULL) - tab = new BTab(target); - else - tab->SetView(target); - - 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) -{ - // TODO: check if we need to change the selection and focus - if (fSelection == CountTabs() - 1) - Select(fSelection - 1); - - if (fFocus == CountTabs() - 1) - SetFocusTab(fFocus, false); - else - SetFocusTab(fFocus, true); - - BTab *tab = (BTab*)fTabList->RemoveItem(tab_index); - - Invalidate(); - - return tab; -} -//------------------------------------------------------------------------------ -BTab *BTabView::TabAt(int32 tab_index) const -{ - return (BTab*)fTabList->ItemAt(tab_index); -} -//------------------------------------------------------------------------------ -void BTabView::SetTabWidth(button_width width) -{ - fTabWidthSetting = width; - - Invalidate(); -} -//------------------------------------------------------------------------------ -button_width BTabView::TabWidth() const -{ - return fTabWidthSetting; -} -//------------------------------------------------------------------------------ -void BTabView::SetTabHeight(float height) -{ - if (fTabHeight == height) - return; - - fContainerView->ResizeBy(0.0f, height - fTabHeight); - - fTabHeight = height; - - Invalidate(); -} -//------------------------------------------------------------------------------ -float BTabView::TabHeight() const -{ - return fTabHeight; -} -//------------------------------------------------------------------------------ -BView *BTabView::ContainerView() const -{ - return fContainerView; -} -//------------------------------------------------------------------------------ -int32 BTabView::CountTabs() const -{ - return fTabList->CountItems(); -} -//------------------------------------------------------------------------------ -BView *BTabView::ViewForTab(int32 tabIndex) const -{ - BTab *tab = TabAt(tabIndex); - - if (tab) - return tab->View(); - else - return NULL; -} -//------------------------------------------------------------------------------ -void BTabView::_InitObject() -{ -} -//------------------------------------------------------------------------------ -void BTabView::_ReservedTabView1() {} -void BTabView::_ReservedTabView2() {} -void BTabView::_ReservedTabView3() {} -void BTabView::_ReservedTabView4() {} -void BTabView::_ReservedTabView5() {} -void BTabView::_ReservedTabView6() {} -void BTabView::_ReservedTabView7() {} -void BTabView::_ReservedTabView8() {} -void BTabView::_ReservedTabView9() {} -void BTabView::_ReservedTabView10() {} -void BTabView::_ReservedTabView11() {} -void BTabView::_ReservedTabView12() {} -//------------------------------------------------------------------------------ -BTabView::BTabView(const BTabView &tabView) - : BView(tabView) -{ -} -//------------------------------------------------------------------------------ -BTabView &BTabView::operator=(const BTabView &) -{ - return *this; -} -//------------------------------------------------------------------------------ - -/* - * $Log $ - * - * $Id $ - * - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: TabView.cpp +// Author: Marc Flerackers (mflerackers@androme.be) +// Description: BTab creates individual "tabs" that can be assigned +// to specific views. +// BTabView provides the framework for containing and +// managing groups of BTab objects. +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- +#include +#include +#include +#include +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +BTab::BTab(BView *tabView) + : fEnabled(true), + fSelected(false), + fFocus(false), + fView(tabView) +{ +} +//------------------------------------------------------------------------------ +BTab::~BTab() +{ + if (!fView) + return; + + if (fSelected) + fView->RemoveSelf(); + + delete fView; +} +//------------------------------------------------------------------------------ +BTab::BTab(BMessage *archive) + : fSelected(false), + fFocus(false), + fView(NULL) +{ + bool disable; + + if (archive->FindBool("_disable", &disable) != B_OK) + SetEnabled(true); + else + SetEnabled(!disable); +} +//------------------------------------------------------------------------------ +BArchivable *BTab::Instantiate(BMessage *archive) +{ + if (validate_instantiation(archive, "BTab")) + return new BTab(archive); + else + return NULL; +} +//------------------------------------------------------------------------------ +status_t BTab::Archive(BMessage *archive, bool deep) const +{ + status_t err = BArchivable::Archive(archive, deep); + + if (err != B_OK) + return err; + + if (!fEnabled) + err = archive->AddBool("_disable", false); + + return err; +} +//------------------------------------------------------------------------------ +status_t BTab::Perform(uint32 d, void *arg) +{ + return BArchivable::Perform(d, arg); +} +//------------------------------------------------------------------------------ +const char *BTab::Label() const +{ + if (fView) + return fView->Name(); + else + return NULL; +} +//------------------------------------------------------------------------------ +void BTab::SetLabel(const char *label) +{ + if (!label) + return; + + if (!fView) + return; + + fView->SetName(label); +} +//------------------------------------------------------------------------------ +bool BTab::IsSelected() const +{ + return fSelected; +} +//------------------------------------------------------------------------------ +void BTab::Select(BView *owner) +{ + if (!owner) + return; + + if (!View()) + return; + + if (!owner->Window()) + return; + + owner->AddChild(fView); + //fView->Show(); + + fSelected = true; +} +//------------------------------------------------------------------------------ +void BTab::Deselect() +{ + if (View()) + View()->RemoveSelf(); + + fSelected = false; +} +//------------------------------------------------------------------------------ +void BTab::SetEnabled(bool enabled) +{ + fEnabled = enabled; +} +//------------------------------------------------------------------------------ +bool BTab::IsEnabled() const +{ + return fEnabled; +} +//------------------------------------------------------------------------------ +void BTab::MakeFocus(bool inFocus) +{ + fFocus = inFocus; +} +//------------------------------------------------------------------------------ +bool BTab::IsFocus() const +{ + return fFocus; +} +//------------------------------------------------------------------------------ +void BTab::SetView(BView *view) +{ + if (!view) + return; + + if (fView == view) + return; + + if (fView == NULL) + fView = view; + else + { + fView->RemoveSelf(); + delete fView; + fView = view; + } +} +//------------------------------------------------------------------------------ +BView *BTab::View() const +{ + return fView; +} +//------------------------------------------------------------------------------ +void BTab::DrawFocusMark(BView *owner, BRect frame) +{ + float width = owner->StringWidth(Label()); + + owner->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); + owner->StrokeLine(BPoint(frame.left + frame.Width() * 0.5f - width * 0.5f, frame.bottom), + BPoint(frame.left + frame.Width() * 0.5f + width * 0.5f, frame.bottom)); +} +//------------------------------------------------------------------------------ +void BTab::DrawLabel(BView *owner, BRect frame) +{ + const char *label = Label(); + + if (label) + { + owner->SetHighColor(0, 0, 0); + owner->DrawString(label, BPoint(frame.left + frame.Width() * 0.5f - + owner->StringWidth(label) * 0.5f, frame.bottom - 4.0f - 2.0f)); + } +} +//------------------------------------------------------------------------------ +void BTab::DrawTab(BView *owner, BRect frame, tab_position position, bool full) +{ + rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), + darken4 = tint_color(no_tint, B_DARKEN_4_TINT), + darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); + + owner->SetHighColor(darkenmax); + owner->SetLowColor(no_tint); + DrawLabel(owner, frame); + + owner->BeginLineArray(12); + + if (position != B_TAB_ANY) + { + owner->AddLine(BPoint(frame.left - 2.0f, frame.bottom), + BPoint(frame.left - 1.0f, frame.bottom - 1.0f), lightenmax); + owner->AddLine(BPoint(frame.left, frame.bottom - 2.0f), + BPoint(frame.left, frame.bottom - 3.0f), lightenmax); + } + + owner->AddLine(BPoint(frame.left + 1.0f, frame.bottom - 4.0f), + BPoint(frame.left + 1.0f, frame.top + 5.0f), lightenmax); + owner->AddLine(BPoint(frame.left + 1.0f, frame.top + 4.0f), + BPoint(frame.left + 2.0f, frame.top + 2.0f), lightenmax); + owner->AddLine(BPoint(frame.left + 3.0f, frame.top + 1.0f), + BPoint(frame.left + 4.0f, frame.top + 1.0f), lightenmax); + owner->AddLine(BPoint(frame.left + 5.0f, frame.top), + BPoint(frame.right - 5.0f, frame.top), lightenmax); + + owner->AddLine(BPoint(frame.right - 4.0f, frame.top + 1.0f), + BPoint(frame.right - 3.0f, frame.top + 1.0f), lightenmax); + + owner->AddLine(BPoint(frame.right - 2.0f, frame.top + 2.0f), + BPoint(frame.right - 2.0f, frame.top + 3.0f), darken4); + owner->AddLine(BPoint(frame.right - 1.0f, frame.top + 4.0f), + BPoint(frame.right - 1.0f, frame.bottom - 4.0f), darken4); + + if (full) + { + owner->AddLine(BPoint(frame.right, frame.bottom - 3.0f), + BPoint(frame.right, frame.bottom - 2.0f), darken4); + owner->AddLine(BPoint(frame.right + 1.0f, frame.bottom - 1.0f), + BPoint(frame.right + 2.0f, frame.bottom), darken4); + } + + owner->EndLineArray(); +} +//------------------------------------------------------------------------------ +void BTab::_ReservedTab1() {} +void BTab::_ReservedTab2() {} +void BTab::_ReservedTab3() {} +void BTab::_ReservedTab4() {} +void BTab::_ReservedTab5() {} +void BTab::_ReservedTab6() {} +void BTab::_ReservedTab7() {} +void BTab::_ReservedTab8() {} +void BTab::_ReservedTab9() {} +void BTab::_ReservedTab10() {} +void BTab::_ReservedTab11() {} +void BTab::_ReservedTab12() {} +//------------------------------------------------------------------------------ +BTab &BTab::operator=(const BTab &) +{ + return *this; +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +BTabView::BTabView(BRect frame, const char *name, button_width width, + uint32 resizingMode, uint32 flags) + : BView(frame, name, resizingMode, flags) +{ + _InitObject(); + + fTabWidthSetting = width; +} +//------------------------------------------------------------------------------ +BTabView::~BTabView() +{ + for (int32 i = 0; i < CountTabs(); i++) + { + if (TabAt(i)) + delete TabAt(i); + } + + delete fTabList; +} +//------------------------------------------------------------------------------ +BTabView::BTabView(BMessage *archive) + : BView(archive), + fFocus(-1) +{ + fContainerView == NULL; + 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) + { + font_height fh; + GetFontHeight(&fh); + fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f; + } + + fFocus = -1; + + if (archive->FindInt32("_sel", &fSelection) != B_OK) + fSelection = 0; + + if (fContainerView == NULL) + fContainerView = ChildAt(0); + + int32 i = 0; + BMessage tabMsg; + + while (archive->FindMessage("_l_items", i, &tabMsg) == B_OK) + { + BArchivable *archivedTab = instantiate_object(&tabMsg); + + if (archivedTab) + { + BTab *tab = dynamic_cast(archivedTab); + + BMessage viewMsg; + + if (archive->FindMessage("_view_list", i, &viewMsg) == B_OK) + { + BArchivable *archivedView = instantiate_object(&viewMsg); + + if (archivedView) + { + BView *view = dynamic_cast(archivedView); + + AddTab(view, tab); + } + } + } + + tabMsg.MakeEmpty(); + i++; + } +} +//------------------------------------------------------------------------------ +BArchivable *BTabView::Instantiate(BMessage *archive) +{ + if ( validate_instantiation(archive, "BTabView")) + return new BTabView(archive); + else + return NULL; +} +//------------------------------------------------------------------------------ +status_t BTabView::Archive(BMessage *archive, bool deep) const +{ + if(CountTabs() > 0) + TabAt(Selection())->View()->RemoveSelf(); + + BView::Archive(archive, deep); + + archive->AddInt16("_but_width", fTabWidthSetting); + archive->AddFloat("_high", fTabHeight); + archive->AddInt32("_sel", fSelection); + + if (deep) + { + for (int32 i = 0; i < CountTabs(); i++) + { + BMessage tabArchive; + BTab *tab = TabAt(i); + + if (!tab) + continue; + + if (tab->Archive(&tabArchive, true) == B_OK) + archive->AddMessage("_l_items", &tabArchive); + + 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; +} +//------------------------------------------------------------------------------ +status_t BTabView::Perform(perform_code d, void *arg) +{ + return BTabView::Perform(d, arg); +} +//------------------------------------------------------------------------------ +void BTabView::WindowActivated(bool active) +{ + BView::WindowActivated(active); + + DrawTabs(); +} +//------------------------------------------------------------------------------ +void BTabView::AttachedToWindow() +{ + BView::AttachedToWindow(); + + Select(fSelection); +} +//------------------------------------------------------------------------------ +void BTabView::AllAttached() +{ + BView::AllAttached(); +} +//------------------------------------------------------------------------------ +void BTabView::AllDetached() +{ + BView::AllDetached(); +} +//------------------------------------------------------------------------------ +void BTabView::DetachedFromWindow() +{ + BView::DetachedFromWindow(); +} +//------------------------------------------------------------------------------ +void BTabView::MessageReceived(BMessage *message) +{ + BView::MessageReceived(message); +} +//------------------------------------------------------------------------------ +void BTabView::FrameMoved(BPoint newLocation) +{ + BView::FrameMoved(newLocation); +} +//------------------------------------------------------------------------------ +void BTabView::FrameResized(float width,float height) +{ + BView::FrameResized(width, height); +} +//------------------------------------------------------------------------------ +void BTabView::KeyDown(const char *bytes, int32 numBytes) +{ + if (IsHidden()) + return; + + switch (bytes[0]) + { + case B_DOWN_ARROW: + case B_LEFT_ARROW: + { + SetFocusTab((fFocus - 1) % CountTabs(), true); + break; + } + case B_UP_ARROW: + case B_RIGHT_ARROW: + { + SetFocusTab((fFocus + 1) % CountTabs(), true); + break; + } + case B_RETURN: + case B_SPACE: + { + Select(FocusTab()); + break; + } + default: + BView::KeyDown(bytes, numBytes); + } +} +//------------------------------------------------------------------------------ +void BTabView::MouseDown(BPoint point) +{ + if (point.y <= fTabHeight) + { + for (int32 i = 0; i < CountTabs(); i++) + { + if (TabFrame(i).Contains(point)) + { + if (i != Selection()) + { + Select(i); + return; + } + } + } + } + + BView::MouseDown(point); +} +//------------------------------------------------------------------------------ +void BTabView::MouseUp(BPoint point) +{ + BView::MouseUp(point); +} +//------------------------------------------------------------------------------ +void BTabView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) +{ + BView::MouseMoved(point, transit, message); +} +//------------------------------------------------------------------------------ +void BTabView::Pulse() +{ + BView::Pulse(); +} +//------------------------------------------------------------------------------ +void BTabView::Select(int32 index) +{ + if (index < 0 || index >= CountTabs()) + index = Selection(); + + BTab *tab = TabAt(Selection()); + + if (tab) + tab->Deselect(); + + tab = TabAt(index); + + if (tab && ContainerView()) + { + tab->Select(ContainerView()); + fSelection = index; + } + + //Draw(Bounds()); + Invalidate(); +} +//------------------------------------------------------------------------------ +int32 BTabView::Selection() const +{ + return fSelection; +} +//------------------------------------------------------------------------------ +void BTabView::MakeFocus(bool focused) +{ + BView::MakeFocus(focused); + + SetFocusTab(Selection(), focused); +} +//------------------------------------------------------------------------------ +void BTabView::SetFocusTab(int32 tab, bool focused) +{ + if (tab >= CountTabs()) + return; + + if (focused) + { + if (tab == fFocus) + return; + + if (fFocus != -1) + TabAt (fFocus)->MakeFocus(false); + + TabAt(tab)->MakeFocus(true); + fFocus = tab; + } + else if (fFocus != -1) + { + TabAt (fFocus)->MakeFocus(false); + fFocus = -1; + } + + Invalidate(); +} +//------------------------------------------------------------------------------ +int32 BTabView::FocusTab() const +{ + return fFocus; +} +//------------------------------------------------------------------------------ +void BTabView::Draw(BRect updateRect) +{ + DrawBox(DrawTabs()); + + if (IsFocus() && fFocus != -1) + TabAt(fFocus)->DrawFocusMark(this, TabFrame(fFocus)); +} +//------------------------------------------------------------------------------ +BRect BTabView::DrawTabs() +{ + for(int32 i = 0; i < CountTabs(); i++) + TabAt(i)->DrawTab(this, TabFrame(i), + (i == fSelection) ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY, + (i + 1 != fSelection)); + + if (fSelection < CountTabs()) + return TabFrame(fSelection); + else + return BRect(); +} +//------------------------------------------------------------------------------ +void BTabView::DrawBox(BRect selTabRect) +{ + BRect rect = Bounds(); + + SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_LIGHTEN_MAX_TINT)); + + StrokeLine(BPoint(0.0f, rect.bottom), BPoint(0.0f, selTabRect.bottom)); + StrokeLine(BPoint(selTabRect.left - 3.0f, selTabRect.bottom)); + StrokeLine(BPoint(selTabRect.right + 3.0f, selTabRect.bottom), + BPoint(rect.right - 1.0f, selTabRect.bottom)); + + SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_DARKEN_4_TINT)); + + StrokeLine(BPoint(rect.right, selTabRect.bottom + 1.0f), + BPoint(rect.right, rect.bottom)); + StrokeLine(BPoint(rect.left + 1.0f, rect.bottom)); +} +//------------------------------------------------------------------------------ +BRect BTabView::TabFrame(int32 tab_index) const +{ + switch (fTabWidthSetting) + { + case B_WIDTH_FROM_LABEL: + { + float x = 6.0f; + + for (int32 i = 0; i < tab_index; i++) + x += StringWidth(TabAt(i)->Label()) + 20.0f; + + return BRect(x, 0.0f, + x + StringWidth(TabAt(tab_index)->Label()) + 20.0f, fTabHeight); + break; + } + case B_WIDTH_FROM_WIDEST: + { + float x = 6.0f; + float width = 0.0f; + + for (int32 i = 0; i < CountTabs(); i++) + { + float tabWidth = StringWidth(TabAt(i)->Label()) + 20.0f; + + if (tabWidth > width) + width = tabWidth; + } + + return BRect((6.0f + tab_index * width), 0.0f, + (6.0f + tab_index * width + width), fTabHeight); + break; + } + case B_WIDTH_AS_USUAL: + default: + { + return BRect((6.0f + tab_index * 100.0f), 0.0f, + (6.0f + tab_index * 100.0f + 100.0f), fTabHeight); + break; + } + } +} +//------------------------------------------------------------------------------ +void BTabView::SetFlags(uint32 flags) +{ + BView::SetFlags(flags); +} +//------------------------------------------------------------------------------ +void BTabView::SetResizingMode(uint32 mode) +{ + BView::SetResizingMode(mode); +} +//------------------------------------------------------------------------------ +void BTabView::GetPreferredSize(float *width, float *height) +{ + BTabView::GetPreferredSize(width, height); +} +//------------------------------------------------------------------------------ +void BTabView::ResizeToPreferred() +{ + BView::ResizeToPreferred(); +} +//------------------------------------------------------------------------------ +BHandler *BTabView::ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, int32 what, const char *property) +{ + return BView::ResolveSpecifier(message, index, specifier, what, property); +} +//------------------------------------------------------------------------------ +status_t BTabView::GetSupportedSuites(BMessage *message) +{ + return BView::GetSupportedSuites(message); +} +//------------------------------------------------------------------------------ +void BTabView::AddTab(BView *target, BTab *tab) +{ + if (tab == NULL) + tab = new BTab(target); + else + tab->SetView(target); + + fTabList->AddItem(tab); +} +//------------------------------------------------------------------------------ +BTab *BTabView::RemoveTab(int32 tab_index) +{ + if (tab_index < 0 || tab_index >= CountTabs()) + return NULL; + + BTab *tab = (BTab*)fTabList->RemoveItem(tab_index); + + tab->Deselect(); + + if (tab_index <= fSelection && fSelection != 0) + fSelection--; + + Select(fSelection); + + if (fFocus == CountTabs() - 1) + SetFocusTab(fFocus, false); + else + SetFocusTab(fFocus, true); + + return tab; +} +//------------------------------------------------------------------------------ +BTab *BTabView::TabAt(int32 tab_index) const +{ + return (BTab*)fTabList->ItemAt(tab_index); +} +//------------------------------------------------------------------------------ +void BTabView::SetTabWidth(button_width width) +{ + fTabWidthSetting = width; + + Invalidate(); +} +//------------------------------------------------------------------------------ +button_width BTabView::TabWidth() const +{ + return fTabWidthSetting; +} +//------------------------------------------------------------------------------ +void BTabView::SetTabHeight(float height) +{ + if (fTabHeight == height) + return; + + fContainerView->MoveBy(0.0f, height - fTabHeight); + fContainerView->ResizeBy(0.0f, height - fTabHeight); + + fTabHeight = height; + + Invalidate(); +} +//------------------------------------------------------------------------------ +float BTabView::TabHeight() const +{ + return fTabHeight; +} +//------------------------------------------------------------------------------ +BView *BTabView::ContainerView() const +{ + return fContainerView; +} +//------------------------------------------------------------------------------ +int32 BTabView::CountTabs() const +{ + return fTabList->CountItems(); +} +//------------------------------------------------------------------------------ +BView *BTabView::ViewForTab(int32 tabIndex) const +{ + BTab *tab = TabAt(tabIndex); + + if (tab) + return tab->View(); + else + return NULL; +} +//------------------------------------------------------------------------------ +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::_ReservedTabView2() {} +void BTabView::_ReservedTabView3() {} +void BTabView::_ReservedTabView4() {} +void BTabView::_ReservedTabView5() {} +void BTabView::_ReservedTabView6() {} +void BTabView::_ReservedTabView7() {} +void BTabView::_ReservedTabView8() {} +void BTabView::_ReservedTabView9() {} +void BTabView::_ReservedTabView10() {} +void BTabView::_ReservedTabView11() {} +void BTabView::_ReservedTabView12() {} +//------------------------------------------------------------------------------ +BTabView::BTabView(const BTabView &tabView) + : BView(tabView) +{ +} +//------------------------------------------------------------------------------ +BTabView &BTabView::operator=(const BTabView &) +{ + return *this; +} +//------------------------------------------------------------------------------ + +/* + * $Log $ + * + * $Id $ + * + */ diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index d82277c204..54032dd5e1 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -42,136 +42,126 @@ // Globals --------------------------------------------------------------------- //------------------------------------------------------------------------------ -BTextControl::BTextControl(BRect frame, const char* name, const char* label, - const char* text, BMessage* message, uint32 mask, +BTextControl::BTextControl(BRect frame, const char *name, const char *label, + const char *text, BMessage *message, uint32 mask, uint32 flags) - : BControl(frame, name, label, message, mask, flags) + : BControl(frame, name, label, message, mask, flags | B_FRAME_EVENTS) { - if (label) - { - fDivider = frame.Width() / 2.0f; - } - else - { - // no label - fDivider = 0.0f; - } + InitData(label, text); - fModificationMessage = NULL; + BRect bounds(Bounds()); + + font_height fh; + GetFontHeight(&fh); - frame = Bounds(); - if (fDivider) - { - frame.left = fDivider + 5.0f; - } + float height = (float)ceil(fh.ascent + fh.descent + fh.leading); + float lineHeight = fText->LineHeight(0); - BRect rect(frame); - rect.OffsetTo(0,0); + ResizeTo(bounds.Width(), height + 8); - frame.OffsetBy(-2,1); + BRect textBounds(fText->Bounds()); - rect.InsetBy(2,2); - fText = new _BTextInput_(this, frame, "text", rect); - fText->SetText(text); - AddChild(fText); + fText->ResizeTo(textBounds.Width(), lineHeight + 4); + fText->MoveBy(0, (bounds.Height() - height) / 2.0f); } //------------------------------------------------------------------------------ BTextControl::~BTextControl() { - if (fText) - { - fText->RemoveSelf(); - delete fText; - } + SetModificationMessage(NULL); } //------------------------------------------------------------------------------ -BTextControl::BTextControl(BMessage* data) +BTextControl::BTextControl(BMessage *data) : BControl(data) { - if (data->FindInt32("_a_label", (int32*)&fLabelAlign) != B_OK) - { - fLabelAlign = B_ALIGN_LEFT; - } + InitData(Label(), NULL, data); - alignment textAlign; - if (data->FindInt32("_a_text", (int32*)&textAlign) != B_OK) + int32 _a_label = B_ALIGN_LEFT; + int32 _a_text = B_ALIGN_LEFT; + + if (data->HasInt32("_a_label")) + data->FindInt32("_a_label", &_a_label); + + if (data->HasInt32("_a_text")) + data->FindInt32("_a_text", &_a_text); + + SetAlignment((alignment)_a_label, (alignment)_a_text); + + if (data->HasFloat("_divide")) + data->FindFloat("_a_text", &fDivider); + + if (data->HasMessage("_mod_msg")) { - fText->SetAlignment(B_ALIGN_LEFT); + BMessage *_mod_msg = new BMessage; + data->FindMessage("_mod_msg", _mod_msg); + SetModificationMessage(_mod_msg); } +} +//------------------------------------------------------------------------------ +BArchivable* BTextControl::Instantiate(BMessage *archive) +{ + if (validate_instantiation(archive, "BTextControl")) + return new BTextControl(archive); else - { - fText->SetAlignment(textAlign); - } - - if (data->FindFloat("_divide", &fDivider) != B_OK) - { - if (Label()) - fDivider = Frame().Width()/2.0f; - else - fDivider = 0.0f; - } - - if (data->FindMessage("_mod_msg", fModificationMessage) != B_OK) - { - fModificationMessage = NULL; // Is this really necessary? - } - - // TODO: Recover additional info as per final implementation of Archive() -} -//------------------------------------------------------------------------------ -BArchivable* BTextControl::Instantiate(BMessage* data) -{ - if (!validate_instantiation(data,"BTextControl")) - { 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 - status_t err = BView::Archive(data, deep); + BView::Archive(data, deep); - if (!err) - 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); + alignment _a_label, _a_text; - 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); + + if (IsFocus()) + fText->SetInitialText(); + + fText->Invalidate(); } //------------------------------------------------------------------------------ -const char* BTextControl::Text() const +const char *BTextControl::Text() const { return fText->Text(); } //------------------------------------------------------------------------------ void BTextControl::SetValue(int32 value) { + BControl::SetValue(value); } //------------------------------------------------------------------------------ -status_t BTextControl::Invoke(BMessage* msg) +status_t BTextControl::Invoke(BMessage *msg) { return BControl::Invoke(msg); } //------------------------------------------------------------------------------ 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; } //------------------------------------------------------------------------------ @@ -182,11 +172,17 @@ BMessage* BTextControl::ModificationMessage() const //------------------------------------------------------------------------------ void BTextControl::SetAlignment(alignment label, alignment text) { - fLabelAlign = label; 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; *text = fText->Alignment(); @@ -194,30 +190,18 @@ void BTextControl::GetAlignment(alignment* label, alignment* text) const //------------------------------------------------------------------------------ void BTextControl::SetDivider(float dividing_line) { + float dx = fDivider - dividing_line; + fDivider = dividing_line; -// here I need some code to resize and invalidate the textView - BRect frame = fText->Frame(); - if (fDivider) - { - frame.left = fDivider + 5.0f; - } - else - { - frame.left = 0.0f; - } - - if (!frame.IsValid()) - { - frame.left = frame.right - 6.0f; - } + fText->MoveBy(-dx, 0.0f); + fText->ResizeBy(dx, 0.0f); - fText->ResizeTo( frame.Width(), frame.Height()); -// fText->FrameResized( frame.Width(), frame.Height()); - fText->MoveTo( frame.left, frame.top); - fText->Invalidate(); - - Invalidate(); + if (Window()) + { + fText->Invalidate(); + Invalidate(); + } } //------------------------------------------------------------------------------ float BTextControl::Divider() const @@ -225,26 +209,82 @@ float BTextControl::Divider() const return fDivider; } //------------------------------------------------------------------------------ -void BTextControl::Draw(BRect rect) +void BTextControl::Draw(BRect updateRect) { - SetLowColor(ViewColor()); - BFont font; - GetFont(&font); - font_height fh; - font.GetHeight(&fh); + rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), + lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), + lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT), + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), + 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()) { - 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; + switch (fLabelAlign) { case B_ALIGN_RIGHT: - x = fDivider - font.StringWidth(Label()) - 3.0f; + x = fDivider - StringWidth(Label()) - 3.0f; break; case B_ALIGN_CENTER: - x = fDivider - font.StringWidth(Label())/2.0f; + x = fDivider - StringWidth(Label()) / 2.0f; break; default: @@ -256,73 +296,111 @@ void BTextControl::Draw(BRect rect) IsEnabled() ? B_DARKEN_MAX_TINT : B_DISABLED_LABEL_TINT)); 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) { - if (IsEnabled()) + if (!fText->IsFocus()) { - MakeFocus(true); + fText->MakeFocus(true); + fText->SelectAll(); } } //------------------------------------------------------------------------------ void BTextControl::AttachedToWindow() { BControl::AttachedToWindow(); - if (Parent()) - { - SetViewColor(Parent()->ViewColor()); - } - float w; - float h; - GetPreferredSize(&w, &h); - ResizeTo(Bounds().Width(), h); - fText->ResizeTo(fText->Bounds().Width(), h); + bool enabled = IsEnabled(); + rgb_color textColor; + rgb_color color = HighColor(); + BFont font; + + 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) { - if (IsEnabled()) - { - fText->MakeFocus(state); - Invalidate(); - } + fText->MakeFocus(state); + + if (state) + fText->SelectAll(); } //------------------------------------------------------------------------------ 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); } //------------------------------------------------------------------------------ -void BTextControl::GetPreferredSize(float* width, float* height) +void BTextControl::GetPreferredSize(float *width, float *height) { BFont font; GetFont(&font); font_height 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 - *width = 4.0f + ceil(font.StringWidth(Label()))*2.0f; + *width = 4.0f + (float)ceil(font.StringWidth(Label()))*2.0f; } //------------------------------------------------------------------------------ void BTextControl::ResizeToPreferred() @@ -335,36 +413,62 @@ void BTextControl::ResizeToPreferred() //------------------------------------------------------------------------------ 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); } //------------------------------------------------------------------------------ -void BTextControl::MessageReceived(BMessage* msg) +void BTextControl::MessageReceived(BMessage *msg) { switch(msg->what) { - case B_CONTROL_MODIFIED: - if (fModificationMessage) - { - BControl::Invoke(fModificationMessage); - } + case B_SET_PROPERTY: + case B_GET_PROPERTY: + // TODO break; - default: BControl::MessageReceived(msg); break; } } //------------------------------------------------------------------------------ -BHandler* BTextControl::ResolveSpecifier(BMessage* msg, int32 index, - BMessage* specifier, int32 form, - const char* property) +BHandler *BTextControl::ResolveSpecifier(BMessage *msg, int32 index, + BMessage *specifier, int32 form, + 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) @@ -372,7 +476,7 @@ void BTextControl::MouseUp(BPoint 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); } @@ -404,36 +508,87 @@ void BTextControl::FrameResized(float newWidth, float newHeight) //------------------------------------------------------------------------------ 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); } //------------------------------------------------------------------------------ -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; } //------------------------------------------------------------------------------ +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 $ diff --git a/src/kits/interface/TextInput.cpp b/src/kits/interface/TextInput.cpp index 4eabacaa59..32837234c9 100644 --- a/src/kits/interface/TextInput.cpp +++ b/src/kits/interface/TextInput.cpp @@ -46,197 +46,197 @@ //------------------------------------------------------------------------------ -_BTextInput_::_BTextInput_(BTextControl* parent, BRect frame, const char* name, - BRect rect, uint32 mask, uint32 flags) - : BTextView(frame, name, rect, mask, flags), - fEnabled(true), - fChanged(false), - fParent(parent) +_BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask, + uint32 flags) + : BTextView(frame, "_input_", textRect, resizeMask, flags), + fPreviousText(NULL), + fBool(false) { - SetMaxBytes(255); - SetWordWrap(false); + MakeResizable(true); +} +//------------------------------------------------------------------------------ +_BTextInput_::_BTextInput_(BMessage *archive) + : BTextView(archive), + fPreviousText(NULL), + fBool(false) +{ + MakeResizable(true); } //------------------------------------------------------------------------------ _BTextInput_::~_BTextInput_() { + if (fPreviousText) + free(fPreviousText); } //------------------------------------------------------------------------------ -void _BTextInput_::SetEnabled(bool state) +BArchivable *_BTextInput_::Instantiate(BMessage *archive) { - fEnabled = state; - if (fEnabled) - { - BView::SetFlags(Flags() | B_NAVIGABLE); - } + if (validate_instantiation(archive, "_BTextInput_")) + return new _BTextInput_(archive); else - { - BView::SetFlags(Flags() & (0xffffffff - B_NAVIGABLE)); - } - - Invalidate(); + return NULL; } //------------------------------------------------------------------------------ -void _BTextInput_::AttachedToWindow() +status_t _BTextInput_::Archive(BMessage *data, bool deep) const { - BFont font; - GetFont(&font); - float h = font.Size() + 6.0f; - ResizeTo(Bounds().Width(), h); - - fViewColor = BTextView::ViewColor(); + return BTextView::Archive(data, true); } //------------------------------------------------------------------------------ -rgb_color _BTextInput_::ViewColor() +void _BTextInput_::FrameResized(float width, float height) { - return fViewColor; -} -//------------------------------------------------------------------------------ -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; + BTextView::FrameResized(width, height); + AlignTextRect(); } //------------------------------------------------------------------------------ void _BTextInput_::KeyDown(const char* bytes, int32 numBytes) { - bool send = false; - - BMessage* msg = Window()->CurrentMessage(); - if (numBytes == 1) + switch (*bytes) { - switch (bytes[0]) + case B_ENTER: { - 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; + if (!TextControl()->IsEnabled()) break; - - case B_ENTER: + + if(strcmp(Text(), fPreviousText) != 0) { - SelectAll(); - send = true; - fChanged = true; - break; - } + TextControl()->Invoke(); + free(fPreviousText); + fPreviousText = strdup(Text()); + } - 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; + SelectAll(); + break; + } - case B_TAB: - // This will make sure that it will skip to the next object - BView::KeyDown(bytes, numBytes); - send = true; - break; - - default: - BTextView::KeyDown(bytes, numBytes); - } - } - else - { - BTextView::KeyDown(bytes, numBytes); - } - - if (send) - { - if (fChanged) - { - Window()->PostMessage(new BMessage(B_CONTROL_INVOKED), fParent); - } - } - else - { - Window()->PostMessage(new BMessage(B_CONTROL_MODIFIED), fParent); - } - - fChanged = true; -} -//------------------------------------------------------------------------------ -void _BTextInput_::MouseDown(BPoint where) -{ - if (fEnabled) - { - BTextView::MouseDown(where); - } -} -//------------------------------------------------------------------------------ -void _BTextInput_::Draw(BRect rect) -{ - - BTextView::Draw(rect); + case B_TAB: + BView::KeyDown(bytes, numBytes); + break; - 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)); - StrokeRect(rect); - } - - if (!fEnabled) - { - 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); + default: + BTextView::KeyDown(bytes, numBytes); } } //------------------------------------------------------------------------------ +void _BTextInput_::MakeFocus(bool state) +{ + if (state == IsFocus()) + return; -/* - * $Log $ - * - * $Id $ - * - */ + BTextView::MakeFocus(state); + if (state) + { + SetInitialText(); + + fBool = true; + + if (Window()) + { + BMessage *msg = Window()->CurrentMessage(); + + if (msg && msg->what == B_KEY_DOWN) + SelectAll(); + } + } + else + { + 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); + } + } + } + + if (Window()) + { + Draw(Bounds()); + Flush(); + } +} +//------------------------------------------------------------------------------ +void _BTextInput_::AlignTextRect() +{ + // TODO +} +//------------------------------------------------------------------------------ +void _BTextInput_::SetInitialText() +{ + if (fPreviousText) + { + free(fPreviousText); + fPreviousText = NULL; + } + + if (Text()) + fPreviousText = strdup(Text()); +} +//------------------------------------------------------------------------------ +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) + { + buffer = (char*)malloc(inLength); + + 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(Parent()); + else + textControl = NULL; + + if (!textControl) + debugger("_BTextInput_ should have a BTextControl as parent"); + + return textControl; +} +//------------------------------------------------------------------------------