* 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:
parent
4b5501d29d
commit
8dbedf907b
@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <Font.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
@ -16,7 +17,8 @@
|
||||
|
||||
|
||||
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),
|
||||
fButton(new BButton(BRect(0, 0, 9, 9), "test button", "",
|
||||
(BMessage*)NULL, B_FOLLOW_NONE)),
|
||||
fLongTextCheckBox(NULL)
|
||||
fLongTextCheckBox(NULL),
|
||||
fBigFontCheckBox(NULL),
|
||||
fDefaultFont(NULL),
|
||||
fBigFont(NULL)
|
||||
|
||||
{
|
||||
_SetButtonText(false);
|
||||
@ -36,6 +41,8 @@ ButtonTest::ButtonTest()
|
||||
// destructor
|
||||
ButtonTest::~ButtonTest()
|
||||
{
|
||||
delete fDefaultFont;
|
||||
delete fBigFont;
|
||||
}
|
||||
|
||||
|
||||
@ -45,18 +52,23 @@ ButtonTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
group->SetSpacing(0, 8);
|
||||
controls->AddChild(group);
|
||||
|
||||
GroupView* longTextGroup = new GroupView(B_HORIZONTAL);
|
||||
group->AddChild(longTextGroup);
|
||||
fLongTextCheckBox = new CheckBox(new BMessage(MSG_CHANGE_BUTTON_TEXT),
|
||||
this);
|
||||
longTextGroup->AddChild(fLongTextCheckBox);
|
||||
longTextGroup->AddChild(new StringView(" Long Button Text"));
|
||||
// long button text
|
||||
fLongTextCheckBox = new LabeledCheckBox("Long Button Text",
|
||||
new BMessage(MSG_CHANGE_BUTTON_TEXT), this);
|
||||
group->AddChild(fLongTextCheckBox);
|
||||
|
||||
// big font
|
||||
fBigFontCheckBox = new LabeledCheckBox("Big Button Font",
|
||||
new BMessage(MSG_CHANGE_BUTTON_FONT), this);
|
||||
group->AddChild(fBigFontCheckBox);
|
||||
|
||||
group->AddChild(new Glue());
|
||||
|
||||
_SetButtonText(false);
|
||||
_SetButtonFont(false);
|
||||
}
|
||||
|
||||
|
||||
@ -75,6 +87,9 @@ ButtonTest::MessageReceived(BMessage* message)
|
||||
case MSG_CHANGE_BUTTON_TEXT:
|
||||
_SetButtonText(fLongTextCheckBox->IsSelected());
|
||||
break;
|
||||
case MSG_CHANGE_BUTTON_FONT:
|
||||
_SetButtonFont(fBigFontCheckBox->IsSelected());
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
@ -91,3 +106,25 @@ ButtonTest::_SetButtonText(bool longText)
|
||||
fButton->SetLabel(longText ? "very long text for a simple button"
|
||||
: "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 CheckBox;
|
||||
class BFont;
|
||||
class LabeledCheckBox;
|
||||
class View;
|
||||
|
||||
|
||||
@ -26,10 +27,14 @@ public:
|
||||
|
||||
private:
|
||||
void _SetButtonText(bool longText);
|
||||
void _SetButtonFont(bool bigFont);
|
||||
|
||||
private:
|
||||
BButton* fButton;
|
||||
CheckBox* fLongTextCheckBox;
|
||||
LabeledCheckBox* fLongTextCheckBox;
|
||||
LabeledCheckBox* fBigFontCheckBox;
|
||||
BFont* fDefaultFont;
|
||||
BFont* fBigFont;
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
#include <View.h>
|
||||
|
||||
#include "StringView.h"
|
||||
|
||||
|
||||
// #pragma mark - CheckBox
|
||||
|
||||
|
||||
CheckBox::CheckBox(BMessage* message, BMessenger target)
|
||||
: View(BRect(0, 0, 12, 12)),
|
||||
@ -120,3 +125,40 @@ CheckBox::_PressedUpdate(BPoint where)
|
||||
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 "View.h"
|
||||
#include "GroupView.h"
|
||||
|
||||
|
||||
// CheckBox
|
||||
class CheckBox : public View, public BInvoker {
|
||||
public:
|
||||
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
|
||||
|
@ -82,14 +82,11 @@ public:
|
||||
fMinHeightView);
|
||||
|
||||
// max (with checkbox)
|
||||
GroupView* unlimitedMaxGroup = new GroupView(B_HORIZONTAL);
|
||||
fUnlimitedMaxSizeCheckBox = new CheckBox(
|
||||
fUnlimitedMaxSizeCheckBox = new LabeledCheckBox("override",
|
||||
new BMessage(MSG_UNLIMITED_MAX_SIZE_CHANGED), this);
|
||||
unlimitedMaxGroup->AddChild(fUnlimitedMaxSizeCheckBox);
|
||||
unlimitedMaxGroup->AddChild(new StringView(" override"));
|
||||
|
||||
_CreateSizeViews(sizeViewsGroup, "max: ", fMaxWidthView,
|
||||
fMaxHeightView, unlimitedMaxGroup);
|
||||
fMaxHeightView, fUnlimitedMaxSizeCheckBox);
|
||||
|
||||
// preferred
|
||||
_CreateSizeViews(sizeViewsGroup, "preferred: ", fPreferredWidthView,
|
||||
@ -253,7 +250,7 @@ private:
|
||||
StringView* fPreferredHeightView;
|
||||
StringView* fCurrentWidthView;
|
||||
StringView* fCurrentHeightView;
|
||||
CheckBox* fUnlimitedMaxSizeCheckBox;
|
||||
LabeledCheckBox* fUnlimitedMaxSizeCheckBox;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user