* Fixed BTextControl resizing (did not invalidate the border area before).

* Rewrote TextControl.h
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16331 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-02-10 14:22:33 +00:00
parent 039132ab1d
commit ffe72abd85
2 changed files with 140 additions and 150 deletions
+75 -123
View File
@@ -1,153 +1,105 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2006, Haiku, Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// 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: TextControl.cpp
// Author: Frans van Nispen ([email protected])
// Description: BTextControl displays text that can act like a control.
//------------------------------------------------------------------------------
#ifndef _TEXT_CONTROL_H #ifndef _TEXT_CONTROL_H
#define _TEXT_CONTROL_H #define _TEXT_CONTROL_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h>
#include <Control.h> #include <Control.h>
#include <TextView.h> /* For convenience */ #include <TextView.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class _BTextInput_; class _BTextInput_;
// BTextControl class ----------------------------------------------------------
class BTextControl : public BControl { 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);
virtual ~BTextControl();
public: BTextControl(BMessage* archive);
BTextControl(BRect frame, static BArchivable* Instantiate(BMessage* archive);
const char *name, virtual status_t Archive(BMessage* archive, bool deep = true) const;
const char *label,
const char *initial_text,
BMessage *message,
uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
virtual ~BTextControl();
BTextControl(BMessage *data); virtual void SetText(const char* text);
static BArchivable *Instantiate(BMessage *data); const char* Text() const;
virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual void SetText(const char *text); virtual void SetValue(int32 value);
const char *Text() const; virtual status_t Invoke(BMessage* message = NULL);
virtual void SetValue(int32 value); BTextView* TextView() const;
virtual status_t Invoke(BMessage *msg = NULL);
BTextView *TextView() const; virtual void SetModificationMessage(BMessage* message);
BMessage* ModificationMessage() const;
virtual void SetModificationMessage(BMessage *message); virtual void SetAlignment(alignment label, alignment text);
BMessage *ModificationMessage() const; void GetAlignment(alignment* _label, alignment* _text) const;
virtual void SetDivider(float position);
float Divider() const;
virtual void SetAlignment(alignment label, alignment text); virtual void Draw(BRect updateRect);
void GetAlignment(alignment *label, alignment *text) const; virtual void MouseDown(BPoint where);
virtual void SetDivider(float dividing_line); virtual void AttachedToWindow();
float Divider() const; 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 GetPreferredSize(float* _width, float* _height);
virtual void MouseDown(BPoint where); virtual void ResizeToPreferred();
virtual void AttachedToWindow();
virtual void MakeFocus(bool focusState = true);
virtual void SetEnabled(bool state);
virtual void FrameMoved(BPoint new_position);
virtual void FrameResized(float new_width, float new_height);
virtual void WindowActivated(bool active);
virtual void GetPreferredSize(float *width, float *height);
virtual void ResizeToPreferred();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage* message);
virtual BHandler *ResolveSpecifier(BMessage *msg, virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
int32 index, BMessage* specifier, int32 what,
BMessage *specifier, const char* property);
int32 form,
const char *property);
virtual void MouseUp(BPoint pt); virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); virtual void MouseMoved(BPoint point, uint32 transit,
virtual void DetachedFromWindow(); const BMessage* dragMessage);
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);
private:
friend class _BTextInput_;
/*----- Private or reserved -----------------------------------------*/ virtual status_t Perform(perform_code d, void* arg);
virtual status_t Perform(perform_code d, void *arg);
private: virtual void _ReservedTextControl1();
friend class _BTextInput_; virtual void _ReservedTextControl2();
virtual void _ReservedTextControl3();
virtual void _ReservedTextControl4();
virtual void _ReservedTextControl1(); BTextControl& operator=(const BTextControl& other);
virtual void _ReservedTextControl2();
virtual void _ReservedTextControl3();
virtual void _ReservedTextControl4();
BTextControl &operator=(const BTextControl &); void _CommitValue();
void _InitData(const char* label, const char* initialText,
BMessage* archive = NULL);
void CommitValue(); private:
void InitData(const char *label, _BTextInput_* fText;
const char *initial_text, char* fLabel;
BMessage *data = NULL); BMessage* fModificationMessage;
alignment fLabelAlign;
float fDivider;
float fPreviousWidth;
float fPreviousHeight;
_BTextInput_ *fText; uint32 _reserved[6];
char *fLabel;
BMessage *fModificationMessage;
alignment fLabelAlign;
float fDivider;
uint16 fPrevWidth;
uint16 fPrevHeight;
uint32 _reserved[3]; /* was 4 */
#if !_PR3_COMPATIBLE_
uint32 _more_reserved[4];
#endif
bool fClean; bool fClean;
bool fSkipSetFlags; bool fSkipSetFlags;
bool fUnusedBool1;
bool fUnusedBool2; bool _reserved1;
bool _reserved2;
}; };
//------------------------------------------------------------------------------
#endif // _TEXT_CONTROL_H #endif // _TEXT_CONTROL_H
/*
* $Log $
*
* $Id $
*
*/
+65 -27
View File
@@ -25,7 +25,7 @@ BTextControl::BTextControl(BRect frame, const char *name, const char *label,
uint32 flags) uint32 flags)
: BControl(frame, name, label, message, mask, flags | B_FRAME_EVENTS) : BControl(frame, name, label, message, mask, flags | B_FRAME_EVENTS)
{ {
InitData(label, text); _InitData(label, text);
float height; float height;
BTextControl::GetPreferredSize(NULL, &height); BTextControl::GetPreferredSize(NULL, &height);
@@ -35,6 +35,8 @@ BTextControl::BTextControl(BRect frame, const char *name, const char *label,
float lineHeight = ceil(fText->LineHeight(0)); float lineHeight = ceil(fText->LineHeight(0));
fText->ResizeTo(fText->Bounds().Width(), lineHeight); fText->ResizeTo(fText->Bounds().Width(), lineHeight);
fText->MoveTo(fText->Frame().left, (height - lineHeight) / 2); fText->MoveTo(fText->Frame().left, (height - lineHeight) / 2);
fPreviousHeight = Bounds().Height();
} }
@@ -44,29 +46,29 @@ BTextControl::~BTextControl()
} }
BTextControl::BTextControl(BMessage *data) BTextControl::BTextControl(BMessage* archive)
: BControl(data) : BControl(archive)
{ {
InitData(Label(), NULL, data); _InitData(Label(), NULL, archive);
int32 _a_label = B_ALIGN_LEFT; int32 labelAlignment = B_ALIGN_LEFT;
int32 _a_text = B_ALIGN_LEFT; int32 textAlignment = B_ALIGN_LEFT;
if (data->HasInt32("_a_label")) if (archive->HasInt32("_a_label"))
data->FindInt32("_a_label", &_a_label); archive->FindInt32("_a_label", &labelAlignment);
if (data->HasInt32("_a_text")) if (archive->HasInt32("_a_text"))
data->FindInt32("_a_text", &_a_text); archive->FindInt32("_a_text", &textAlignment);
SetAlignment((alignment)_a_label, (alignment)_a_text); SetAlignment((alignment)labelAlignment, (alignment)textAlignment);
if (data->HasFloat("_divide")) if (archive->HasFloat("_divide"))
data->FindFloat("_a_text", &fDivider); archive->FindFloat("_a_text", &fDivider);
if (data->HasMessage("_mod_msg")) { if (archive->HasMessage("_mod_msg")) {
BMessage *_mod_msg = new BMessage; BMessage* message = new BMessage;
data->FindMessage("_mod_msg", _mod_msg); archive->FindMessage("_mod_msg", message);
SetModificationMessage(_mod_msg); SetModificationMessage(message);
} }
} }
@@ -542,9 +544,45 @@ BTextControl::FrameMoved(BPoint newPosition)
void void
BTextControl::FrameResized(float newWidth, float newHeight) BTextControl::FrameResized(float width, float height)
{ {
BControl::FrameResized(newWidth, newHeight); BControl::FrameResized(width, height);
// changes in width
BRect bounds = Bounds();
const float border = 2.0f;
if (bounds.Width() > fPreviousWidth) {
// invalidate the region between the old and the new right border
BRect rect = bounds;
rect.left += fPreviousWidth - border;
rect.right--;
Invalidate(rect);
} else if (bounds.Width() < fPreviousWidth) {
// invalidate the region of the new right border
BRect rect = bounds;
rect.left = rect.right - border;
Invalidate(rect);
}
// changes in height
if (bounds.Height() > fPreviousHeight) {
// invalidate the region between the old and the new bottom border
BRect rect = bounds;
rect.top += fPreviousHeight - border;
rect.bottom--;
Invalidate(rect);
} else if (bounds.Height() < fPreviousHeight) {
// invalidate the region of the new bottom border
BRect rect = bounds;
rect.top = rect.bottom - border;
Invalidate(rect);
}
fPreviousWidth = uint16(bounds.Width());
fPreviousHeight = uint16(bounds.Height());
} }
@@ -585,14 +623,14 @@ BTextControl::operator=(const BTextControl&)
void void
BTextControl::CommitValue() BTextControl::_CommitValue()
{ {
} }
void void
BTextControl::InitData(const char *label, const char *initialText, BTextControl::_InitData(const char* label, const char* initialText,
BMessage *data) BMessage* archive)
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
@@ -600,18 +638,18 @@ BTextControl::InitData(const char *label, const char *initialText,
fModificationMessage = NULL; fModificationMessage = NULL;
fLabelAlign = B_ALIGN_LEFT; fLabelAlign = B_ALIGN_LEFT;
fDivider = 0.0f; fDivider = 0.0f;
fPrevWidth = 0; fPreviousWidth = bounds.Width();
fPrevHeight = 0; fPreviousHeight = bounds.Height();
fSkipSetFlags = false; fSkipSetFlags = false;
int32 flags = 0; int32 flags = 0;
BFont font(be_plain_font); BFont font(be_plain_font);
if (!data || !data->HasString("_fname")) if (!archive || !archive->HasString("_fname"))
flags |= B_FONT_FAMILY_AND_STYLE; flags |= B_FONT_FAMILY_AND_STYLE;
if (!data || !data->HasFloat("_fflt")) if (!archive || !archive->HasFloat("_fflt"))
flags |= B_FONT_SIZE; flags |= B_FONT_SIZE;
if (flags != 0) if (flags != 0)
@@ -627,7 +665,7 @@ BTextControl::InitData(const char *label, const char *initialText,
fSkipSetFlags = false; fSkipSetFlags = false;
} }
if (data) if (archive)
fText = static_cast<_BTextInput_ *>(FindView("_input_")); fText = static_cast<_BTextInput_ *>(FindView("_input_"));
else { else {
BRect frame(fDivider, bounds.top, BRect frame(fDivider, bounds.top,