* Pulled most of the implementation of ButtonTest into a new super class
ControlTest. * Added a test for BCheckBox. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21366 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,30 +8,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <Font.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
#include "GroupView.h"
|
||||
#include "StringView.h"
|
||||
|
||||
|
||||
enum {
|
||||
MSG_CHANGE_BUTTON_TEXT = 'chbt',
|
||||
MSG_CHANGE_BUTTON_FONT = 'chbf'
|
||||
};
|
||||
|
||||
|
||||
// constructor
|
||||
ButtonTest::ButtonTest()
|
||||
: Test("Button", NULL),
|
||||
fButton(new BButton("test button", "", (BMessage*)NULL)),
|
||||
fLongTextCheckBox(NULL),
|
||||
fBigFontCheckBox(NULL),
|
||||
fDefaultFont(NULL),
|
||||
fBigFont(NULL)
|
||||
: ControlTest("Button"),
|
||||
fButton(new BButton(""))
|
||||
{
|
||||
_SetButtonText(false);
|
||||
SetView(fButton);
|
||||
}
|
||||
|
||||
@@ -39,8 +24,6 @@ ButtonTest::ButtonTest()
|
||||
// destructor
|
||||
ButtonTest::~ButtonTest()
|
||||
{
|
||||
delete fDefaultFont;
|
||||
delete fBigFont;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,23 +33,11 @@ ButtonTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
group->SetSpacing(0, 8);
|
||||
controls->AddChild(group);
|
||||
|
||||
// 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);
|
||||
ControlTest::ActivateTest(group);
|
||||
|
||||
group->AddChild(new Glue());
|
||||
|
||||
_SetButtonText(false);
|
||||
_SetButtonFont(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,56 +46,3 @@ void
|
||||
ButtonTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
ButtonTest::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_CHANGE_BUTTON_TEXT:
|
||||
_SetButtonText(fLongTextCheckBox->IsSelected());
|
||||
break;
|
||||
case MSG_CHANGE_BUTTON_FONT:
|
||||
_SetButtonFont(fBigFontCheckBox->IsSelected());
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// _SetButtonText
|
||||
void
|
||||
ButtonTest::_SetButtonText(bool longText)
|
||||
{
|
||||
if (fLongTextCheckBox)
|
||||
fLongTextCheckBox->SetSelected(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);
|
||||
fButton->InvalidateLayout();
|
||||
fButton->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,13 @@
|
||||
#define WIDGET_LAYOUT_TEST_BUTTON_TEST_H
|
||||
|
||||
|
||||
#include "Test.h"
|
||||
#include "ControlTest.h"
|
||||
|
||||
|
||||
class BButton;
|
||||
class BFont;
|
||||
class LabeledCheckBox;
|
||||
class View;
|
||||
|
||||
|
||||
class ButtonTest : public Test {
|
||||
class ButtonTest : public ControlTest {
|
||||
public:
|
||||
ButtonTest();
|
||||
virtual ~ButtonTest();
|
||||
@@ -23,18 +20,8 @@ public:
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void _SetButtonText(bool longText);
|
||||
void _SetButtonFont(bool bigFont);
|
||||
|
||||
private:
|
||||
BButton* fButton;
|
||||
LabeledCheckBox* fLongTextCheckBox;
|
||||
LabeledCheckBox* fBigFontCheckBox;
|
||||
BFont* fDefaultFont;
|
||||
BFont* fBigFont;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "CheckBoxTest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
|
||||
#include "GroupView.h"
|
||||
|
||||
|
||||
// constructor
|
||||
CheckBoxTest::CheckBoxTest()
|
||||
: ControlTest("CheckBox"),
|
||||
fCheckBox(new BCheckBox(""))
|
||||
{
|
||||
SetView(fCheckBox);
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
CheckBoxTest::~CheckBoxTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ActivateTest
|
||||
void
|
||||
CheckBoxTest::ActivateTest(View* controls)
|
||||
{
|
||||
// BControl sets its background color to that of its parent in
|
||||
// AttachedToWindow(). Override.
|
||||
rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
fControl->SetViewColor(background);
|
||||
fControl->SetLowColor(background);
|
||||
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
controls->AddChild(group);
|
||||
|
||||
ControlTest::ActivateTest(group);
|
||||
|
||||
group->AddChild(new Glue());
|
||||
}
|
||||
|
||||
|
||||
// DectivateTest
|
||||
void
|
||||
CheckBoxTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_CHECK_BOX_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_CHECK_BOX_TEST_H
|
||||
|
||||
|
||||
#include "ControlTest.h"
|
||||
|
||||
|
||||
class BCheckBox;
|
||||
|
||||
|
||||
class CheckBoxTest : public ControlTest {
|
||||
public:
|
||||
CheckBoxTest();
|
||||
virtual ~CheckBoxTest();
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
private:
|
||||
BCheckBox* fCheckBox;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_CHECK_BOX_TEST_H
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "ControlTest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Control.h>
|
||||
#include <Font.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
#include "GroupView.h"
|
||||
#include "StringView.h"
|
||||
|
||||
|
||||
|
||||
// constructor
|
||||
ControlTest::ControlTest(const char* name)
|
||||
: Test(name, NULL),
|
||||
fControl(NULL),
|
||||
fLongTextCheckBox(NULL),
|
||||
fBigFontCheckBox(NULL),
|
||||
fDefaultFont(NULL),
|
||||
fBigFont(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
ControlTest::~ControlTest()
|
||||
{
|
||||
delete fDefaultFont;
|
||||
delete fBigFont;
|
||||
}
|
||||
|
||||
|
||||
// SetView
|
||||
void
|
||||
ControlTest::SetView(BView* view)
|
||||
{
|
||||
Test::SetView(view);
|
||||
fControl = dynamic_cast<BControl*>(view);
|
||||
}
|
||||
|
||||
|
||||
// ActivateTest
|
||||
void
|
||||
ControlTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
group->SetSpacing(0, 8);
|
||||
controls->AddChild(group);
|
||||
|
||||
// long text
|
||||
fLongTextCheckBox = new LabeledCheckBox("Long label text",
|
||||
new BMessage(MSG_CHANGE_CONTROL_TEXT), this);
|
||||
group->AddChild(fLongTextCheckBox);
|
||||
|
||||
// big font
|
||||
fBigFontCheckBox = new LabeledCheckBox("Big label font",
|
||||
new BMessage(MSG_CHANGE_CONTROL_FONT), this);
|
||||
group->AddChild(fBigFontCheckBox);
|
||||
|
||||
UpdateControlText();
|
||||
UpdateControlFont();
|
||||
}
|
||||
|
||||
|
||||
// DectivateTest
|
||||
void
|
||||
ControlTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
ControlTest::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_CHANGE_CONTROL_TEXT:
|
||||
UpdateControlText();
|
||||
break;
|
||||
case MSG_CHANGE_CONTROL_FONT:
|
||||
UpdateControlFont();
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// UpdateControlText
|
||||
void
|
||||
ControlTest::UpdateControlText()
|
||||
{
|
||||
if (!fLongTextCheckBox || !fControl)
|
||||
return;
|
||||
|
||||
fControl->SetLabel(fLongTextCheckBox->IsSelected()
|
||||
? "Very long label for a simple control"
|
||||
: "Short label");
|
||||
}
|
||||
|
||||
|
||||
// UpdateControlFont
|
||||
void
|
||||
ControlTest::UpdateControlFont()
|
||||
{
|
||||
if (!fBigFontCheckBox || !fControl || !fControl->Window())
|
||||
return;
|
||||
|
||||
// get default font lazily
|
||||
if (!fDefaultFont) {
|
||||
fDefaultFont = new BFont;
|
||||
fControl->GetFont(fDefaultFont);
|
||||
|
||||
fBigFont = new BFont(fDefaultFont);
|
||||
fBigFont->SetSize(20);
|
||||
}
|
||||
|
||||
// set font
|
||||
fControl->SetFont(fBigFontCheckBox->IsSelected()
|
||||
? fBigFont : fDefaultFont);
|
||||
fControl->InvalidateLayout();
|
||||
fControl->Invalidate();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_CONTROL_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_CONTROL_TEST_H
|
||||
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
|
||||
class BButton;
|
||||
class BFont;
|
||||
class LabeledCheckBox;
|
||||
class View;
|
||||
|
||||
|
||||
class ControlTest : public Test {
|
||||
public:
|
||||
ControlTest(const char* name);
|
||||
virtual ~ControlTest();
|
||||
|
||||
virtual void SetView(BView* view);
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
MSG_CHANGE_CONTROL_TEXT = 'chct',
|
||||
MSG_CHANGE_CONTROL_FONT = 'chcf'
|
||||
};
|
||||
|
||||
protected:
|
||||
void UpdateControlText();
|
||||
void UpdateControlFont();
|
||||
|
||||
protected:
|
||||
BControl* fControl;
|
||||
LabeledCheckBox* fLongTextCheckBox;
|
||||
LabeledCheckBox* fBigFontCheckBox;
|
||||
BFont* fDefaultFont;
|
||||
BFont* fBigFont;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_CONTROL_TEST_H
|
||||
@@ -9,6 +9,8 @@ SimpleTest WidgetLayoutTest :
|
||||
BoxTest.cpp
|
||||
ButtonTest.cpp
|
||||
CheckBox.cpp
|
||||
CheckBoxTest.cpp
|
||||
ControlTest.cpp
|
||||
GroupView.cpp
|
||||
RadioButton.cpp
|
||||
StringView.cpp
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
const char* Description() const;
|
||||
|
||||
virtual BView* GetView() const;
|
||||
void SetView(BView* view);
|
||||
virtual void SetView(BView* view);
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "BoxTest.h"
|
||||
#include "ButtonTest.h"
|
||||
#include "CheckBox.h"
|
||||
#include "CheckBoxTest.h"
|
||||
#include "GroupView.h"
|
||||
#include "StringView.h"
|
||||
#include "Test.h"
|
||||
@@ -273,6 +274,8 @@ main(int argc, const char* const* argv)
|
||||
test = new BoxTest;
|
||||
} else if (strcmp(testName, "button") == 0) {
|
||||
test = new ButtonTest;
|
||||
} else if (strcmp(testName, "checkbox") == 0) {
|
||||
test = new CheckBoxTest;
|
||||
} else {
|
||||
fprintf(stderr, "Error: Invalid test name: \"%s\"\n", testName);
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user