* 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:
Stephan Aßmus
2008-09-15 19:43:18 +00:00
parent 8d619bc9d2
commit 93ba577c3e
2 changed files with 133 additions and 114 deletions
+11 -14
View File
@@ -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,11 +15,12 @@ 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
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BTextControl(const char* name, BTextControl(const char* name,
const char* label, const char* initialText, const char* label, const char* initialText,
@@ -32,7 +33,8 @@ class BTextControl : public BControl {
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;
@@ -46,7 +48,8 @@ class BTextControl : public BControl {
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,
alignment* _text) const;
virtual void SetDivider(float position); virtual void SetDivider(float position);
float Divider() const; float Divider() const;
@@ -80,7 +83,7 @@ class BTextControl : public BControl {
BLayoutItem* CreateLabelLayoutItem(); BLayoutItem* CreateLabelLayoutItem();
BLayoutItem* CreateTextViewLayoutItem(); BLayoutItem* CreateTextViewLayoutItem();
private: private:
class LabelLayoutItem; class LabelLayoutItem;
class TextViewLayoutItem; class TextViewLayoutItem;
@@ -105,7 +108,7 @@ class BTextControl : public BControl {
void _LayoutTextView(); void _LayoutTextView();
void _UpdateFrame(); void _UpdateFrame();
private: private:
BPrivate::_BTextInput_* fText; BPrivate::_BTextInput_* fText;
char* fLabel; char* fLabel;
BMessage* fModificationMessage; BMessage* fModificationMessage;
@@ -116,13 +119,7 @@ class BTextControl : public BControl {
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
+36 -14
View File
@@ -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,7 +475,6 @@ 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) {
@@ -473,7 +488,6 @@ BTextControl::SetFlags(uint32 flags)
// Don't make this one navigable // Don't make this one navigable
flags &= ~B_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);
} }