* 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:
parent
8d619bc9d2
commit
93ba577c3e
@ -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.
|
||||
*/
|
||||
#ifndef _TEXT_CONTROL_H
|
||||
@ -15,114 +15,111 @@ class _BTextInput_;
|
||||
}
|
||||
|
||||
class BTextControl : public BControl {
|
||||
public:
|
||||
BTextControl(BRect frame, const char* name,
|
||||
const char* label, const char* initialText,
|
||||
BMessage* message,
|
||||
uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BTextControl(const char* name,
|
||||
const char* label, const char* initialText,
|
||||
BMessage* message,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BTextControl(const char* label,
|
||||
const char* initialText,
|
||||
BMessage* message);
|
||||
virtual ~BTextControl();
|
||||
public:
|
||||
BTextControl(BRect frame, const char* name,
|
||||
const char* label, const char* initialText,
|
||||
BMessage* message,
|
||||
uint32 resizeMode
|
||||
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BTextControl(const char* name,
|
||||
const char* label, const char* initialText,
|
||||
BMessage* message,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BTextControl(const char* label,
|
||||
const char* initialText,
|
||||
BMessage* message);
|
||||
virtual ~BTextControl();
|
||||
|
||||
BTextControl(BMessage* archive);
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
BTextControl(BMessage* archive);
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* archive,
|
||||
bool deep = true) const;
|
||||
|
||||
virtual void SetText(const char* text);
|
||||
const char* Text() const;
|
||||
virtual void SetText(const char* text);
|
||||
const char* Text() const;
|
||||
|
||||
virtual void SetValue(int32 value);
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
virtual void SetValue(int32 value);
|
||||
virtual status_t Invoke(BMessage* message = NULL);
|
||||
|
||||
BTextView* TextView() const;
|
||||
BTextView* TextView() const;
|
||||
|
||||
virtual void SetModificationMessage(BMessage* message);
|
||||
BMessage* ModificationMessage() const;
|
||||
virtual void SetModificationMessage(BMessage* message);
|
||||
BMessage* ModificationMessage() const;
|
||||
|
||||
virtual void SetAlignment(alignment label, alignment text);
|
||||
void GetAlignment(alignment* _label, alignment* _text) const;
|
||||
virtual void SetDivider(float position);
|
||||
float Divider() const;
|
||||
virtual void SetAlignment(alignment label, alignment text);
|
||||
void GetAlignment(alignment* _label,
|
||||
alignment* _text) const;
|
||||
virtual void SetDivider(float position);
|
||||
float Divider() const;
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void SetEnabled(bool enabled);
|
||||
virtual void FrameMoved(BPoint newPosition);
|
||||
virtual void FrameResized(float newWidth, float newHeight);
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void SetEnabled(bool enabled);
|
||||
virtual void FrameMoved(BPoint newPosition);
|
||||
virtual void FrameResized(float newWidth, float newHeight);
|
||||
virtual void WindowActivated(bool active);
|
||||
|
||||
virtual void GetPreferredSize(float* _width, float* _height);
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void GetPreferredSize(float* _width, float* _height);
|
||||
virtual void ResizeToPreferred();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||
BMessage* specifier, int32 what,
|
||||
const char* property);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||
BMessage* specifier, int32 what,
|
||||
const char* property);
|
||||
|
||||
virtual void MouseUp(BPoint point);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void MouseUp(BPoint point);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
virtual void DetachedFromWindow();
|
||||
|
||||
virtual void AllAttached();
|
||||
virtual void AllDetached();
|
||||
virtual status_t GetSupportedSuites(BMessage* data);
|
||||
virtual void SetFlags(uint32 flags);
|
||||
virtual void AllAttached();
|
||||
virtual void AllDetached();
|
||||
virtual status_t GetSupportedSuites(BMessage* data);
|
||||
virtual void SetFlags(uint32 flags);
|
||||
|
||||
BLayoutItem* CreateLabelLayoutItem();
|
||||
BLayoutItem* CreateTextViewLayoutItem();
|
||||
BLayoutItem* CreateLabelLayoutItem();
|
||||
BLayoutItem* CreateTextViewLayoutItem();
|
||||
|
||||
private:
|
||||
class LabelLayoutItem;
|
||||
class TextViewLayoutItem;
|
||||
private:
|
||||
class LabelLayoutItem;
|
||||
class TextViewLayoutItem;
|
||||
|
||||
friend class _BTextInput_;
|
||||
friend class LabelLayoutItem;
|
||||
friend class TextViewLayoutItem;
|
||||
friend class _BTextInput_;
|
||||
friend class LabelLayoutItem;
|
||||
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 _ReservedTextControl2();
|
||||
virtual void _ReservedTextControl3();
|
||||
virtual void _ReservedTextControl4();
|
||||
virtual void _ReservedTextControl1();
|
||||
virtual void _ReservedTextControl2();
|
||||
virtual void _ReservedTextControl3();
|
||||
virtual void _ReservedTextControl4();
|
||||
|
||||
BTextControl& operator=(const BTextControl& other);
|
||||
BTextControl& operator=(const BTextControl& other);
|
||||
|
||||
void _CommitValue();
|
||||
void _UpdateTextViewColors(bool enabled);
|
||||
void _InitData(const char* label, const char* initialText,
|
||||
BMessage* archive = NULL);
|
||||
void _ValidateLayout();
|
||||
void _LayoutTextView();
|
||||
void _UpdateFrame();
|
||||
void _CommitValue();
|
||||
void _UpdateTextViewColors(bool enabled);
|
||||
void _InitData(const char* label, const char* initialText,
|
||||
BMessage* archive = NULL);
|
||||
void _ValidateLayout();
|
||||
void _LayoutTextView();
|
||||
void _UpdateFrame();
|
||||
|
||||
private:
|
||||
BPrivate::_BTextInput_* fText;
|
||||
char* fLabel;
|
||||
BMessage* fModificationMessage;
|
||||
alignment fLabelAlign;
|
||||
float fDivider;
|
||||
float fPreviousWidth;
|
||||
float fPreviousHeight;
|
||||
BLayoutItem* fLabelLayoutItem;
|
||||
BLayoutItem* fTextViewLayoutItem;
|
||||
private:
|
||||
BPrivate::_BTextInput_* fText;
|
||||
char* fLabel;
|
||||
BMessage* fModificationMessage;
|
||||
alignment fLabelAlign;
|
||||
float fDivider;
|
||||
float fPreviousWidth;
|
||||
float fPreviousHeight;
|
||||
BLayoutItem* fLabelLayoutItem;
|
||||
BLayoutItem* fTextViewLayoutItem;
|
||||
|
||||
uint32 _reserved[4];
|
||||
|
||||
bool fClean;
|
||||
bool fSkipSetFlags;
|
||||
|
||||
bool _reserved1;
|
||||
bool _reserved2;
|
||||
uint32 _reserved[5];
|
||||
};
|
||||
|
||||
#endif // _TEXT_CONTROL_H
|
||||
|
@ -23,6 +23,21 @@
|
||||
#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 {
|
||||
public:
|
||||
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,
|
||||
const char* text, BMessage* message, uint32 flags)
|
||||
: BControl(BRect(0, 0, -1, -1), name, label, message, B_FOLLOW_NONE,
|
||||
flags | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT)
|
||||
: BControl(name, label, message, flags | B_FRAME_EVENTS)
|
||||
{
|
||||
_InitData(label, text);
|
||||
_ValidateLayout();
|
||||
@ -93,8 +107,8 @@ BTextControl::BTextControl(const char* name, const char* label,
|
||||
|
||||
BTextControl::BTextControl(const char* label, const char* text,
|
||||
BMessage* message)
|
||||
: BControl(BRect(0, 0, -1, -1), NULL, label, message, B_FOLLOW_NONE,
|
||||
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT)
|
||||
: BControl(NULL, label, message,
|
||||
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS)
|
||||
{
|
||||
_InitData(label, text);
|
||||
_ValidateLayout();
|
||||
@ -172,6 +186,8 @@ BTextControl::SetText(const char *text)
|
||||
if (InvokeKind() != B_CONTROL_INVOKED)
|
||||
return;
|
||||
|
||||
CALLED();
|
||||
|
||||
fText->SetText(text);
|
||||
|
||||
if (IsFocus())
|
||||
@ -459,22 +475,20 @@ 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);
|
||||
// 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;
|
||||
} else {
|
||||
if (flags & B_NAVIGABLE)
|
||||
fText->SetFlags(fText->Flags() | B_NAVIGABLE);
|
||||
}
|
||||
|
||||
// Don't make this one navigable
|
||||
flags &= ~B_NAVIGABLE;
|
||||
|
||||
BView::SetFlags(flags);
|
||||
}
|
||||
|
||||
@ -565,6 +579,8 @@ BTextControl::FrameMoved(BPoint newPosition)
|
||||
void
|
||||
BTextControl::FrameResized(float width, float height)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
BControl::FrameResized(width, height);
|
||||
|
||||
// changes in width
|
||||
@ -602,6 +618,8 @@ BTextControl::FrameResized(float width, float height)
|
||||
|
||||
fPreviousWidth = uint16(bounds.Width());
|
||||
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();
|
||||
fLabelLayoutItem = NULL;
|
||||
fTextViewLayoutItem = NULL;
|
||||
fSkipSetFlags = false;
|
||||
|
||||
int32 flags = 0;
|
||||
|
||||
@ -728,11 +745,8 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
||||
fDivider = floorf(bounds.Width() / 2.0f);
|
||||
|
||||
uint32 navigableFlags = Flags() & B_NAVIGABLE;
|
||||
if (navigableFlags != 0) {
|
||||
fSkipSetFlags = true;
|
||||
SetFlags(Flags() & ~B_NAVIGABLE);
|
||||
fSkipSetFlags = false;
|
||||
}
|
||||
if (navigableFlags != 0)
|
||||
BView::SetFlags(Flags() & ~B_NAVIGABLE);
|
||||
|
||||
if (archive)
|
||||
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));
|
||||
|
||||
fText = new BPrivate::_BTextInput_(frame, textRect,
|
||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | navigableFlags);
|
||||
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | navigableFlags);
|
||||
AddChild(fText);
|
||||
|
||||
SetText(initialText);
|
||||
@ -759,6 +772,8 @@ BTextControl::_InitData(const char* label, const char* initialText,
|
||||
void
|
||||
BTextControl::_ValidateLayout()
|
||||
{
|
||||
CALLED();
|
||||
|
||||
float height;
|
||||
BTextControl::GetPreferredSize(NULL, &height);
|
||||
|
||||
@ -773,6 +788,8 @@ BTextControl::_ValidateLayout()
|
||||
void
|
||||
BTextControl::_LayoutTextView()
|
||||
{
|
||||
CALLED();
|
||||
|
||||
BRect frame = Bounds();
|
||||
frame.left = fDivider;
|
||||
// we are stroking the frame around the text view, which
|
||||
@ -781,6 +798,11 @@ BTextControl::_LayoutTextView()
|
||||
fText->MoveTo(frame.left, frame.top);
|
||||
fText->ResizeTo(frame.Width(), frame.Height());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user