* Added LabeledCheckBox class to make using check boxes simpler.
* Added a check box to toggle the button font to the button test. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21190 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <Font.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
#include "CheckBox.h"
|
#include "CheckBox.h"
|
||||||
@@ -16,7 +17,8 @@
|
|||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_CHANGE_BUTTON_TEXT = 'lgbt'
|
MSG_CHANGE_BUTTON_TEXT = 'chbt',
|
||||||
|
MSG_CHANGE_BUTTON_FONT = 'chbf'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +27,10 @@ ButtonTest::ButtonTest()
|
|||||||
: Test("Button", NULL),
|
: Test("Button", NULL),
|
||||||
fButton(new BButton(BRect(0, 0, 9, 9), "test button", "",
|
fButton(new BButton(BRect(0, 0, 9, 9), "test button", "",
|
||||||
(BMessage*)NULL, B_FOLLOW_NONE)),
|
(BMessage*)NULL, B_FOLLOW_NONE)),
|
||||||
fLongTextCheckBox(NULL)
|
fLongTextCheckBox(NULL),
|
||||||
|
fBigFontCheckBox(NULL),
|
||||||
|
fDefaultFont(NULL),
|
||||||
|
fBigFont(NULL)
|
||||||
|
|
||||||
{
|
{
|
||||||
_SetButtonText(false);
|
_SetButtonText(false);
|
||||||
@@ -36,6 +41,8 @@ ButtonTest::ButtonTest()
|
|||||||
// destructor
|
// destructor
|
||||||
ButtonTest::~ButtonTest()
|
ButtonTest::~ButtonTest()
|
||||||
{
|
{
|
||||||
|
delete fDefaultFont;
|
||||||
|
delete fBigFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,18 +52,23 @@ ButtonTest::ActivateTest(View* controls)
|
|||||||
{
|
{
|
||||||
GroupView* group = new GroupView(B_VERTICAL);
|
GroupView* group = new GroupView(B_VERTICAL);
|
||||||
group->SetFrame(controls->Bounds());
|
group->SetFrame(controls->Bounds());
|
||||||
|
group->SetSpacing(0, 8);
|
||||||
controls->AddChild(group);
|
controls->AddChild(group);
|
||||||
|
|
||||||
GroupView* longTextGroup = new GroupView(B_HORIZONTAL);
|
// long button text
|
||||||
group->AddChild(longTextGroup);
|
fLongTextCheckBox = new LabeledCheckBox("Long Button Text",
|
||||||
fLongTextCheckBox = new CheckBox(new BMessage(MSG_CHANGE_BUTTON_TEXT),
|
new BMessage(MSG_CHANGE_BUTTON_TEXT), this);
|
||||||
this);
|
group->AddChild(fLongTextCheckBox);
|
||||||
longTextGroup->AddChild(fLongTextCheckBox);
|
|
||||||
longTextGroup->AddChild(new StringView(" Long Button Text"));
|
// big font
|
||||||
|
fBigFontCheckBox = new LabeledCheckBox("Big Button Font",
|
||||||
|
new BMessage(MSG_CHANGE_BUTTON_FONT), this);
|
||||||
|
group->AddChild(fBigFontCheckBox);
|
||||||
|
|
||||||
group->AddChild(new Glue());
|
group->AddChild(new Glue());
|
||||||
|
|
||||||
_SetButtonText(false);
|
_SetButtonText(false);
|
||||||
|
_SetButtonFont(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,6 +87,9 @@ ButtonTest::MessageReceived(BMessage* message)
|
|||||||
case MSG_CHANGE_BUTTON_TEXT:
|
case MSG_CHANGE_BUTTON_TEXT:
|
||||||
_SetButtonText(fLongTextCheckBox->IsSelected());
|
_SetButtonText(fLongTextCheckBox->IsSelected());
|
||||||
break;
|
break;
|
||||||
|
case MSG_CHANGE_BUTTON_FONT:
|
||||||
|
_SetButtonFont(fBigFontCheckBox->IsSelected());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Test::MessageReceived(message);
|
Test::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -91,3 +106,25 @@ ButtonTest::_SetButtonText(bool longText)
|
|||||||
fButton->SetLabel(longText ? "very long text for a simple button"
|
fButton->SetLabel(longText ? "very long text for a simple button"
|
||||||
: "Ooh, press me!");
|
: "Ooh, press me!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _SetButtonFont
|
||||||
|
void
|
||||||
|
ButtonTest::_SetButtonFont(bool bigFont)
|
||||||
|
{
|
||||||
|
if (fBigFontCheckBox)
|
||||||
|
fBigFontCheckBox->SetSelected(bigFont);
|
||||||
|
if (fButton->Window()) {
|
||||||
|
// get default font lazily
|
||||||
|
if (!fDefaultFont) {
|
||||||
|
fDefaultFont = new BFont;
|
||||||
|
fButton->GetFont(fDefaultFont);
|
||||||
|
|
||||||
|
fBigFont = new BFont(fDefaultFont);
|
||||||
|
fBigFont->SetSize(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set font
|
||||||
|
fButton->SetFont(bigFont ? fBigFont : fDefaultFont);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
class CheckBox;
|
class BFont;
|
||||||
|
class LabeledCheckBox;
|
||||||
class View;
|
class View;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,10 +27,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _SetButtonText(bool longText);
|
void _SetButtonText(bool longText);
|
||||||
|
void _SetButtonFont(bool bigFont);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BButton* fButton;
|
BButton* fButton;
|
||||||
CheckBox* fLongTextCheckBox;
|
LabeledCheckBox* fLongTextCheckBox;
|
||||||
|
LabeledCheckBox* fBigFontCheckBox;
|
||||||
|
BFont* fDefaultFont;
|
||||||
|
BFont* fBigFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
#include "StringView.h"
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - CheckBox
|
||||||
|
|
||||||
|
|
||||||
CheckBox::CheckBox(BMessage* message, BMessenger target)
|
CheckBox::CheckBox(BMessage* message, BMessenger target)
|
||||||
: View(BRect(0, 0, 12, 12)),
|
: View(BRect(0, 0, 12, 12)),
|
||||||
@@ -120,3 +125,40 @@ CheckBox::_PressedUpdate(BPoint where)
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - LabeledCheckBox
|
||||||
|
|
||||||
|
|
||||||
|
LabeledCheckBox::LabeledCheckBox(const char* label, BMessage* message,
|
||||||
|
BMessenger target)
|
||||||
|
: GroupView(B_HORIZONTAL),
|
||||||
|
fCheckBox(new CheckBox(message, target))
|
||||||
|
{
|
||||||
|
SetSpacing(8, 0);
|
||||||
|
|
||||||
|
AddChild(fCheckBox);
|
||||||
|
if (label)
|
||||||
|
AddChild(new StringView(label));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LabeledCheckBox::SetTarget(BMessenger messenger)
|
||||||
|
{
|
||||||
|
fCheckBox->SetTarget(messenger);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LabeledCheckBox::SetSelected(bool selected)
|
||||||
|
{
|
||||||
|
fCheckBox->SetSelected(selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
LabeledCheckBox::IsSelected() const
|
||||||
|
{
|
||||||
|
return fCheckBox->IsSelected();
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
#include <Invoker.h>
|
#include <Invoker.h>
|
||||||
|
|
||||||
#include "View.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
|
|
||||||
|
// CheckBox
|
||||||
class CheckBox : public View, public BInvoker {
|
class CheckBox : public View, public BInvoker {
|
||||||
public:
|
public:
|
||||||
CheckBox(BMessage* message = NULL,
|
CheckBox(BMessage* message = NULL,
|
||||||
@@ -41,4 +42,21 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// LabeledCheckBox
|
||||||
|
class LabeledCheckBox : public GroupView {
|
||||||
|
public:
|
||||||
|
LabeledCheckBox(const char* label,
|
||||||
|
BMessage* message = NULL,
|
||||||
|
BMessenger target = BMessenger());
|
||||||
|
|
||||||
|
void SetTarget(BMessenger messenger);
|
||||||
|
|
||||||
|
void SetSelected(bool selected);
|
||||||
|
bool IsSelected() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CheckBox* fCheckBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // WIDGET_LAYOUT_TEST_CHECK_BOX_H
|
#endif // WIDGET_LAYOUT_TEST_CHECK_BOX_H
|
||||||
|
|||||||
@@ -82,14 +82,11 @@ public:
|
|||||||
fMinHeightView);
|
fMinHeightView);
|
||||||
|
|
||||||
// max (with checkbox)
|
// max (with checkbox)
|
||||||
GroupView* unlimitedMaxGroup = new GroupView(B_HORIZONTAL);
|
fUnlimitedMaxSizeCheckBox = new LabeledCheckBox("override",
|
||||||
fUnlimitedMaxSizeCheckBox = new CheckBox(
|
|
||||||
new BMessage(MSG_UNLIMITED_MAX_SIZE_CHANGED), this);
|
new BMessage(MSG_UNLIMITED_MAX_SIZE_CHANGED), this);
|
||||||
unlimitedMaxGroup->AddChild(fUnlimitedMaxSizeCheckBox);
|
|
||||||
unlimitedMaxGroup->AddChild(new StringView(" override"));
|
|
||||||
|
|
||||||
_CreateSizeViews(sizeViewsGroup, "max: ", fMaxWidthView,
|
_CreateSizeViews(sizeViewsGroup, "max: ", fMaxWidthView,
|
||||||
fMaxHeightView, unlimitedMaxGroup);
|
fMaxHeightView, fUnlimitedMaxSizeCheckBox);
|
||||||
|
|
||||||
// preferred
|
// preferred
|
||||||
_CreateSizeViews(sizeViewsGroup, "preferred: ", fPreferredWidthView,
|
_CreateSizeViews(sizeViewsGroup, "preferred: ", fPreferredWidthView,
|
||||||
@@ -253,7 +250,7 @@ private:
|
|||||||
StringView* fPreferredHeightView;
|
StringView* fPreferredHeightView;
|
||||||
StringView* fCurrentWidthView;
|
StringView* fCurrentWidthView;
|
||||||
StringView* fCurrentHeightView;
|
StringView* fCurrentHeightView;
|
||||||
CheckBox* fUnlimitedMaxSizeCheckBox;
|
LabeledCheckBox* fUnlimitedMaxSizeCheckBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user