diff --git a/headers/os/interface/CheckBox.h b/headers/os/interface/CheckBox.h index c591313306..17c134d823 100644 --- a/headers/os/interface/CheckBox.h +++ b/headers/os/interface/CheckBox.h @@ -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]; }; //------------------------------------------------------------------------------ diff --git a/src/kits/interface/CheckBox.cpp b/src/kits/interface/CheckBox.cpp index d6e438271b..70e28e5176 100644 --- a/src/kits/interface/CheckBox.cpp +++ b/src/kits/interface/CheckBox.cpp @@ -10,13 +10,16 @@ #include + +#include #include 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; +}