Added layout-friendly constructors and implemented Min/Max/PreferredSize().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21365 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6bef4a07d6
commit
c594b2f5f2
@ -51,6 +51,12 @@ public:
|
||||
BMessage *message,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BCheckBox(const char *name,
|
||||
const char *label,
|
||||
BMessage *message,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BCheckBox(const char *label,
|
||||
BMessage *message = NULL);
|
||||
virtual ~BCheckBox();
|
||||
|
||||
/* Archiving */
|
||||
@ -88,6 +94,12 @@ virtual void AllDetached();
|
||||
|
||||
virtual status_t Perform(perform_code d, void *arg);
|
||||
|
||||
virtual void InvalidateLayout(bool descendants = false);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
|
||||
private:
|
||||
|
||||
virtual void _ReservedCheckBox1();
|
||||
@ -95,11 +107,12 @@ virtual void _ReservedCheckBox2();
|
||||
virtual void _ReservedCheckBox3();
|
||||
|
||||
BRect _CheckBoxFrame() const;
|
||||
BSize _ValidatePreferredSize();
|
||||
|
||||
BCheckBox &operator=(const BCheckBox &);
|
||||
|
||||
BSize fPreferredSize;
|
||||
bool fOutlined;
|
||||
uint32 _reserved[2];
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -10,13 +10,16 @@
|
||||
|
||||
|
||||
#include <CheckBox.h>
|
||||
|
||||
#include <LayoutUtils.h>
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
|
||||
BMessage *message, uint32 resizingMode, uint32 flags)
|
||||
: BControl(frame, name, label, message, resizingMode, flags),
|
||||
fOutlined(false)
|
||||
fPreferredSize(-1, -1),
|
||||
fOutlined(false)
|
||||
{
|
||||
// Resize to minimum height if needed
|
||||
font_height fontHeight;
|
||||
@ -28,6 +31,23 @@ BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
|
||||
}
|
||||
|
||||
|
||||
BCheckBox::BCheckBox(const char *name, const char *label, BMessage *message,
|
||||
uint32 flags)
|
||||
: BControl(name, label, message, flags | B_WILL_DRAW | B_NAVIGABLE),
|
||||
fPreferredSize(-1, -1),
|
||||
fOutlined(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BCheckBox::BCheckBox(const char *label, BMessage *message)
|
||||
: BControl(NULL, label, message, B_WILL_DRAW | B_NAVIGABLE),
|
||||
fPreferredSize(-1, -1),
|
||||
fOutlined(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BCheckBox::~BCheckBox()
|
||||
{
|
||||
}
|
||||
@ -434,6 +454,40 @@ BCheckBox::Perform(perform_code d, void *arg)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCheckBox::InvalidateLayout(bool descendants)
|
||||
{
|
||||
// invalidate cached preferred size
|
||||
fPreferredSize.Set(-1, -1);
|
||||
|
||||
BControl::InvalidateLayout(descendants);
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BCheckBox::MinSize()
|
||||
{
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(),
|
||||
_ValidatePreferredSize());
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BCheckBox::MaxSize()
|
||||
{
|
||||
return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
|
||||
BSize(B_SIZE_UNLIMITED, _ValidatePreferredSize().height));
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BCheckBox::PreferredSize()
|
||||
{
|
||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
|
||||
_ValidatePreferredSize());
|
||||
}
|
||||
|
||||
|
||||
void BCheckBox::_ReservedCheckBox1() {}
|
||||
void BCheckBox::_ReservedCheckBox2() {}
|
||||
void BCheckBox::_ReservedCheckBox3() {}
|
||||
@ -455,3 +509,25 @@ BCheckBox::_CheckBoxFrame() const
|
||||
return BRect(1.0f, 3.0f, ceilf(3.0f + fontHeight.ascent),
|
||||
ceilf(5.0f + fontHeight.ascent));
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BCheckBox::_ValidatePreferredSize()
|
||||
{
|
||||
if (fPreferredSize.width < 0) {
|
||||
font_height fontHeight;
|
||||
GetFontHeight(&fontHeight);
|
||||
|
||||
float width = 12.0f + fontHeight.ascent;
|
||||
|
||||
if (Label())
|
||||
width += StringWidth(Label());
|
||||
|
||||
fPreferredSize.width = (float)ceil(width);
|
||||
|
||||
fPreferredSize.height = (float)ceil(6.0f + fontHeight.ascent
|
||||
+ fontHeight.descent);
|
||||
}
|
||||
|
||||
return fPreferredSize;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user