* Updated header indentation
* Removed unused fClean member * Got rid of fSkipSetFlags member by simply calling the BView::SetFlags() directly where fSkipSetFlags was supposed to prevent the custom implementation. * Added some debugging facilities. * Used the layout friendly constructors of BControl where appropriate. * Used B_FOLLOW_ALL for the child text input, it should be more correct. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27576 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _TEXT_CONTROL_H
|
#ifndef _TEXT_CONTROL_H
|
||||||
@@ -15,114 +15,111 @@ class _BTextInput_;
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BTextControl : public BControl {
|
class BTextControl : public BControl {
|
||||||
public:
|
public:
|
||||||
BTextControl(BRect frame, const char* name,
|
BTextControl(BRect frame, const char* name,
|
||||||
const char* label, const char* initialText,
|
const char* label, const char* initialText,
|
||||||
BMessage* message,
|
BMessage* message,
|
||||||
uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
uint32 resizeMode
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
BTextControl(const char* name,
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
const char* label, const char* initialText,
|
BTextControl(const char* name,
|
||||||
BMessage* message,
|
const char* label, const char* initialText,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
BMessage* message,
|
||||||
BTextControl(const char* label,
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
const char* initialText,
|
BTextControl(const char* label,
|
||||||
BMessage* message);
|
const char* initialText,
|
||||||
virtual ~BTextControl();
|
BMessage* message);
|
||||||
|
virtual ~BTextControl();
|
||||||
|
|
||||||
BTextControl(BMessage* archive);
|
BTextControl(BMessage* archive);
|
||||||
static BArchivable* Instantiate(BMessage* archive);
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
virtual status_t Archive(BMessage* archive,
|
||||||
|
bool deep = true) const;
|
||||||
|
|
||||||
virtual void SetText(const char* text);
|
virtual void SetText(const char* text);
|
||||||
const char* Text() const;
|
const char* Text() const;
|
||||||
|
|
||||||
virtual void SetValue(int32 value);
|
virtual void SetValue(int32 value);
|
||||||
virtual status_t Invoke(BMessage* message = NULL);
|
virtual status_t Invoke(BMessage* message = NULL);
|
||||||
|
|
||||||
BTextView* TextView() const;
|
BTextView* TextView() const;
|
||||||
|
|
||||||
virtual void SetModificationMessage(BMessage* message);
|
virtual void SetModificationMessage(BMessage* message);
|
||||||
BMessage* ModificationMessage() const;
|
BMessage* ModificationMessage() const;
|
||||||
|
|
||||||
virtual void SetAlignment(alignment label, alignment text);
|
virtual void SetAlignment(alignment label, alignment text);
|
||||||
void GetAlignment(alignment* _label, alignment* _text) const;
|
void GetAlignment(alignment* _label,
|
||||||
virtual void SetDivider(float position);
|
alignment* _text) const;
|
||||||
float Divider() const;
|
virtual void SetDivider(float position);
|
||||||
|
float Divider() const;
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MakeFocus(bool focus = true);
|
virtual void MakeFocus(bool focus = true);
|
||||||
virtual void SetEnabled(bool enabled);
|
virtual void SetEnabled(bool enabled);
|
||||||
virtual void FrameMoved(BPoint newPosition);
|
virtual void FrameMoved(BPoint newPosition);
|
||||||
virtual void FrameResized(float newWidth, float newHeight);
|
virtual void FrameResized(float newWidth, float newHeight);
|
||||||
virtual void WindowActivated(bool active);
|
virtual void WindowActivated(bool active);
|
||||||
|
|
||||||
virtual void GetPreferredSize(float* _width, float* _height);
|
virtual void GetPreferredSize(float* _width, float* _height);
|
||||||
virtual void ResizeToPreferred();
|
virtual void ResizeToPreferred();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||||
BMessage* specifier, int32 what,
|
BMessage* specifier, int32 what,
|
||||||
const char* property);
|
const char* property);
|
||||||
|
|
||||||
virtual void MouseUp(BPoint point);
|
virtual void MouseUp(BPoint point);
|
||||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||||
const BMessage* dragMessage);
|
const BMessage* dragMessage);
|
||||||
virtual void DetachedFromWindow();
|
virtual void DetachedFromWindow();
|
||||||
|
|
||||||
virtual void AllAttached();
|
virtual void AllAttached();
|
||||||
virtual void AllDetached();
|
virtual void AllDetached();
|
||||||
virtual status_t GetSupportedSuites(BMessage* data);
|
virtual status_t GetSupportedSuites(BMessage* data);
|
||||||
virtual void SetFlags(uint32 flags);
|
virtual void SetFlags(uint32 flags);
|
||||||
|
|
||||||
BLayoutItem* CreateLabelLayoutItem();
|
BLayoutItem* CreateLabelLayoutItem();
|
||||||
BLayoutItem* CreateTextViewLayoutItem();
|
BLayoutItem* CreateTextViewLayoutItem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class LabelLayoutItem;
|
class LabelLayoutItem;
|
||||||
class TextViewLayoutItem;
|
class TextViewLayoutItem;
|
||||||
|
|
||||||
friend class _BTextInput_;
|
friend class _BTextInput_;
|
||||||
friend class LabelLayoutItem;
|
friend class LabelLayoutItem;
|
||||||
friend class TextViewLayoutItem;
|
friend class TextViewLayoutItem;
|
||||||
|
|
||||||
virtual status_t Perform(perform_code d, void* arg);
|
virtual status_t Perform(perform_code d, void* arg);
|
||||||
|
|
||||||
virtual void _ReservedTextControl1();
|
virtual void _ReservedTextControl1();
|
||||||
virtual void _ReservedTextControl2();
|
virtual void _ReservedTextControl2();
|
||||||
virtual void _ReservedTextControl3();
|
virtual void _ReservedTextControl3();
|
||||||
virtual void _ReservedTextControl4();
|
virtual void _ReservedTextControl4();
|
||||||
|
|
||||||
BTextControl& operator=(const BTextControl& other);
|
BTextControl& operator=(const BTextControl& other);
|
||||||
|
|
||||||
void _CommitValue();
|
void _CommitValue();
|
||||||
void _UpdateTextViewColors(bool enabled);
|
void _UpdateTextViewColors(bool enabled);
|
||||||
void _InitData(const char* label, const char* initialText,
|
void _InitData(const char* label, const char* initialText,
|
||||||
BMessage* archive = NULL);
|
BMessage* archive = NULL);
|
||||||
void _ValidateLayout();
|
void _ValidateLayout();
|
||||||
void _LayoutTextView();
|
void _LayoutTextView();
|
||||||
void _UpdateFrame();
|
void _UpdateFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPrivate::_BTextInput_* fText;
|
BPrivate::_BTextInput_* fText;
|
||||||
char* fLabel;
|
char* fLabel;
|
||||||
BMessage* fModificationMessage;
|
BMessage* fModificationMessage;
|
||||||
alignment fLabelAlign;
|
alignment fLabelAlign;
|
||||||
float fDivider;
|
float fDivider;
|
||||||
float fPreviousWidth;
|
float fPreviousWidth;
|
||||||
float fPreviousHeight;
|
float fPreviousHeight;
|
||||||
BLayoutItem* fLabelLayoutItem;
|
BLayoutItem* fLabelLayoutItem;
|
||||||
BLayoutItem* fTextViewLayoutItem;
|
BLayoutItem* fTextViewLayoutItem;
|
||||||
|
|
||||||
uint32 _reserved[4];
|
uint32 _reserved[5];
|
||||||
|
|
||||||
bool fClean;
|
|
||||||
bool fSkipSetFlags;
|
|
||||||
|
|
||||||
bool _reserved1;
|
|
||||||
bool _reserved2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _TEXT_CONTROL_H
|
#endif // _TEXT_CONTROL_H
|
||||||
|
|||||||
@@ -23,6 +23,21 @@
|
|||||||
#include "TextInput.h"
|
#include "TextInput.h"
|
||||||
|
|
||||||
|
|
||||||
|
//#define TRACE_TEXT_CONTROL
|
||||||
|
#ifdef TRACE_TEXT_CONTROL
|
||||||
|
# include <FunctionTracer.h>
|
||||||
|
static int32 sFunctionDepth = -1;
|
||||||
|
# define CALLED(x...) FunctionTracer _ft("BMenuField", __FUNCTION__, \
|
||||||
|
sFunctionDepth)
|
||||||
|
# define TRACE(x...) { BString _to; \
|
||||||
|
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
||||||
|
printf("%s", _to.String()); printf(x); }
|
||||||
|
#else
|
||||||
|
# define CALLED(x...)
|
||||||
|
# define TRACE(x...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class BTextControl::LabelLayoutItem : public BAbstractLayoutItem {
|
class BTextControl::LabelLayoutItem : public BAbstractLayoutItem {
|
||||||
public:
|
public:
|
||||||
LabelLayoutItem(BTextControl* parent);
|
LabelLayoutItem(BTextControl* parent);
|
||||||
@@ -83,8 +98,7 @@ BTextControl::BTextControl(BRect frame, const char* name, const char* label,
|
|||||||
|
|
||||||
BTextControl::BTextControl(const char* name, const char* label,
|
BTextControl::BTextControl(const char* name, const char* label,
|
||||||
const char* text, BMessage* message, uint32 flags)
|
const char* text, BMessage* message, uint32 flags)
|
||||||
: BControl(BRect(0, 0, -1, -1), name, label, message, B_FOLLOW_NONE,
|
: BControl(name, label, message, flags | B_FRAME_EVENTS)
|
||||||
flags | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT)
|
|
||||||
{
|
{
|
||||||
_InitData(label, text);
|
_InitData(label, text);
|
||||||
_ValidateLayout();
|
_ValidateLayout();
|
||||||
@@ -93,8 +107,8 @@ BTextControl::BTextControl(const char* name, const char* label,
|
|||||||
|
|
||||||
BTextControl::BTextControl(const char* label, const char* text,
|
BTextControl::BTextControl(const char* label, const char* text,
|
||||||
BMessage* message)
|
BMessage* message)
|
||||||
: BControl(BRect(0, 0, -1, -1), NULL, label, message, B_FOLLOW_NONE,
|
: BControl(NULL, label, message,
|
||||||
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT)
|
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS)
|
||||||
{
|
{
|
||||||
_InitData(label, text);
|
_InitData(label, text);
|
||||||
_ValidateLayout();
|
_ValidateLayout();
|
||||||
@@ -172,6 +186,8 @@ BTextControl::SetText(const char *text)
|
|||||||
if (InvokeKind() != B_CONTROL_INVOKED)
|
if (InvokeKind() != B_CONTROL_INVOKED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CALLED();
|
||||||
|
|
||||||
fText->SetText(text);
|
fText->SetText(text);
|
||||||
|
|
||||||
if (IsFocus())
|
if (IsFocus())
|
||||||
@@ -459,22 +475,20 @@ BTextControl::ResizeToPreferred()
|
|||||||
void
|
void
|
||||||
BTextControl::SetFlags(uint32 flags)
|
BTextControl::SetFlags(uint32 flags)
|
||||||
{
|
{
|
||||||
if (!fSkipSetFlags) {
|
// If the textview is navigable, set it to not navigable if needed
|
||||||
// If the textview is navigable, set it to not navigable if needed
|
// Else if it is not navigable, set it to navigable if needed
|
||||||
// Else if it is not navigable, set it to navigable if needed
|
if (fText->Flags() & B_NAVIGABLE) {
|
||||||
if (fText->Flags() & B_NAVIGABLE) {
|
if (!(flags & B_NAVIGABLE))
|
||||||
if (!(flags & B_NAVIGABLE))
|
fText->SetFlags(fText->Flags() & ~B_NAVIGABLE);
|
||||||
fText->SetFlags(fText->Flags() & ~B_NAVIGABLE);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (flags & B_NAVIGABLE)
|
if (flags & B_NAVIGABLE)
|
||||||
fText->SetFlags(fText->Flags() | B_NAVIGABLE);
|
fText->SetFlags(fText->Flags() | B_NAVIGABLE);
|
||||||
}
|
|
||||||
|
|
||||||
// Don't make this one navigable
|
|
||||||
flags &= ~B_NAVIGABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't make this one navigable
|
||||||
|
flags &= ~B_NAVIGABLE;
|
||||||
|
|
||||||
BView::SetFlags(flags);
|
BView::SetFlags(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,6 +579,8 @@ BTextControl::FrameMoved(BPoint newPosition)
|
|||||||
void
|
void
|
||||||
BTextControl::FrameResized(float width, float height)
|
BTextControl::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
BControl::FrameResized(width, height);
|
BControl::FrameResized(width, height);
|
||||||
|
|
||||||
// changes in width
|
// changes in width
|
||||||
@@ -602,6 +618,8 @@ BTextControl::FrameResized(float width, float height)
|
|||||||
|
|
||||||
fPreviousWidth = uint16(bounds.Width());
|
fPreviousWidth = uint16(bounds.Width());
|
||||||
fPreviousHeight = uint16(bounds.Height());
|
fPreviousHeight = uint16(bounds.Height());
|
||||||
|
|
||||||
|
TRACE("width: %.2f, height: %.2f\n", bounds.Width(), bounds.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -709,7 +727,6 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
|||||||
fPreviousHeight = bounds.Height();
|
fPreviousHeight = bounds.Height();
|
||||||
fLabelLayoutItem = NULL;
|
fLabelLayoutItem = NULL;
|
||||||
fTextViewLayoutItem = NULL;
|
fTextViewLayoutItem = NULL;
|
||||||
fSkipSetFlags = false;
|
|
||||||
|
|
||||||
int32 flags = 0;
|
int32 flags = 0;
|
||||||
|
|
||||||
@@ -728,11 +745,8 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
|||||||
fDivider = floorf(bounds.Width() / 2.0f);
|
fDivider = floorf(bounds.Width() / 2.0f);
|
||||||
|
|
||||||
uint32 navigableFlags = Flags() & B_NAVIGABLE;
|
uint32 navigableFlags = Flags() & B_NAVIGABLE;
|
||||||
if (navigableFlags != 0) {
|
if (navigableFlags != 0)
|
||||||
fSkipSetFlags = true;
|
BView::SetFlags(Flags() & ~B_NAVIGABLE);
|
||||||
SetFlags(Flags() & ~B_NAVIGABLE);
|
|
||||||
fSkipSetFlags = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (archive)
|
if (archive)
|
||||||
fText = static_cast<BPrivate::_BTextInput_*>(FindView("_input_"));
|
fText = static_cast<BPrivate::_BTextInput_*>(FindView("_input_"));
|
||||||
@@ -745,8 +759,7 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
|||||||
BRect textRect(frame.OffsetToCopy(B_ORIGIN));
|
BRect textRect(frame.OffsetToCopy(B_ORIGIN));
|
||||||
|
|
||||||
fText = new BPrivate::_BTextInput_(frame, textRect,
|
fText = new BPrivate::_BTextInput_(frame, textRect,
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
|
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | navigableFlags);
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | navigableFlags);
|
|
||||||
AddChild(fText);
|
AddChild(fText);
|
||||||
|
|
||||||
SetText(initialText);
|
SetText(initialText);
|
||||||
@@ -759,6 +772,8 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
|||||||
void
|
void
|
||||||
BTextControl::_ValidateLayout()
|
BTextControl::_ValidateLayout()
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
float height;
|
float height;
|
||||||
BTextControl::GetPreferredSize(NULL, &height);
|
BTextControl::GetPreferredSize(NULL, &height);
|
||||||
|
|
||||||
@@ -773,6 +788,8 @@ BTextControl::_ValidateLayout()
|
|||||||
void
|
void
|
||||||
BTextControl::_LayoutTextView()
|
BTextControl::_LayoutTextView()
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
BRect frame = Bounds();
|
BRect frame = Bounds();
|
||||||
frame.left = fDivider;
|
frame.left = fDivider;
|
||||||
// we are stroking the frame around the text view, which
|
// we are stroking the frame around the text view, which
|
||||||
@@ -781,6 +798,11 @@ BTextControl::_LayoutTextView()
|
|||||||
fText->MoveTo(frame.left, frame.top);
|
fText->MoveTo(frame.left, frame.top);
|
||||||
fText->ResizeTo(frame.Width(), frame.Height());
|
fText->ResizeTo(frame.Width(), frame.Height());
|
||||||
fText->AlignTextRect();
|
fText->AlignTextRect();
|
||||||
|
|
||||||
|
TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height());
|
||||||
|
TRACE("fDivider: %.2f\n", fDivider);
|
||||||
|
TRACE("fText frame: (%.2f, %.2f, %.2f, %.2f)\n",
|
||||||
|
frame.left, frame.top, frame.right, frame.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user