Added test for BMenuField.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21467 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b321303cf9
commit
de83ade240
@ -25,6 +25,7 @@ SimpleTest WidgetLayoutTest :
|
||||
ControlTest.cpp
|
||||
ListViewTest.cpp
|
||||
MenuBarTest.cpp
|
||||
MenuFieldTest.cpp
|
||||
MenuTest.cpp
|
||||
:
|
||||
be
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "GroupView.h"
|
||||
#include "ListViewTest.h"
|
||||
#include "MenuBarTest.h"
|
||||
#include "MenuFieldTest.h"
|
||||
#include "MenuTest.h"
|
||||
#include "StringView.h"
|
||||
#include "Test.h"
|
||||
@ -43,6 +44,7 @@ const test_info kTestInfos[] = {
|
||||
{ "BListView", ListViewTest::CreateTest },
|
||||
{ "BMenu", MenuTest::CreateTest },
|
||||
{ "BMenuBar", MenuBarTest::CreateTest },
|
||||
{ "BMenuField", MenuFieldTest::CreateTest },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "MenuFieldTest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Menu.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
#include "GroupView.h"
|
||||
|
||||
|
||||
enum {
|
||||
MSG_CHANGE_LABEL_TEXT = 'chlt',
|
||||
MSG_CHANGE_LABEL_FONT = 'chlf'
|
||||
};
|
||||
|
||||
|
||||
// constructor
|
||||
MenuFieldTest::MenuFieldTest()
|
||||
: ControlTest("MenuField"),
|
||||
fLongTextCheckBox(NULL),
|
||||
fBigFontCheckBox(NULL),
|
||||
fDefaultFont(NULL),
|
||||
fBigFont(NULL)
|
||||
{
|
||||
BMenu* menu = new BMenu("The Menu");
|
||||
|
||||
// add a few items
|
||||
for (int32 i = 0; i < 10; i++) {
|
||||
BString itemText("Menu item ");
|
||||
itemText << i;
|
||||
menu->AddItem(new BMenuItem(itemText.String(), NULL));
|
||||
}
|
||||
|
||||
fMenuField = new BMenuField("", menu);
|
||||
|
||||
SetView(fMenuField);
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
MenuFieldTest::~MenuFieldTest()
|
||||
{
|
||||
delete fDefaultFont;
|
||||
delete fBigFont;
|
||||
}
|
||||
|
||||
|
||||
// CreateTest
|
||||
Test*
|
||||
MenuFieldTest::CreateTest()
|
||||
{
|
||||
return new MenuFieldTest;
|
||||
}
|
||||
|
||||
|
||||
// ActivateTest
|
||||
void
|
||||
MenuFieldTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
group->SetSpacing(0, 8);
|
||||
controls->AddChild(group);
|
||||
|
||||
// BMenuField sets its background color to that of its parent in
|
||||
// AttachedToWindow(). Override.
|
||||
rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
fMenuField->SetViewColor(background);
|
||||
fMenuField->SetLowColor(background);
|
||||
|
||||
// long text
|
||||
fLongTextCheckBox = new LabeledCheckBox("Long label text",
|
||||
new BMessage(MSG_CHANGE_LABEL_TEXT), this);
|
||||
group->AddChild(fLongTextCheckBox);
|
||||
|
||||
// big font
|
||||
fBigFontCheckBox = new LabeledCheckBox("Big label font",
|
||||
new BMessage(MSG_CHANGE_LABEL_FONT), this);
|
||||
group->AddChild(fBigFontCheckBox);
|
||||
|
||||
UpdateLabelText();
|
||||
UpdateLabelFont();
|
||||
|
||||
group->AddChild(new Glue());
|
||||
}
|
||||
|
||||
|
||||
// DectivateTest
|
||||
void
|
||||
MenuFieldTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
MenuFieldTest::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_CHANGE_LABEL_TEXT:
|
||||
UpdateLabelText();
|
||||
break;
|
||||
case MSG_CHANGE_LABEL_FONT:
|
||||
UpdateLabelFont();
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// UpdateLabelText
|
||||
void
|
||||
MenuFieldTest::UpdateLabelText()
|
||||
{
|
||||
if (!fLongTextCheckBox || !fMenuField)
|
||||
return;
|
||||
|
||||
fMenuField->SetLabel(fLongTextCheckBox->IsSelected()
|
||||
? "Pretty long menu field label"
|
||||
: "Short label");
|
||||
}
|
||||
|
||||
|
||||
// UpdateLabelFont
|
||||
void
|
||||
MenuFieldTest::UpdateLabelFont()
|
||||
{
|
||||
if (!fBigFontCheckBox || !fMenuField || !fMenuField->Window())
|
||||
return;
|
||||
|
||||
// get default font lazily
|
||||
if (!fDefaultFont) {
|
||||
fDefaultFont = new BFont;
|
||||
fMenuField->GetFont(fDefaultFont);
|
||||
|
||||
fBigFont = new BFont(fDefaultFont);
|
||||
fBigFont->SetSize(20);
|
||||
}
|
||||
|
||||
// set font
|
||||
fMenuField->SetFont(fBigFontCheckBox->IsSelected()
|
||||
? fBigFont : fDefaultFont);
|
||||
fMenuField->InvalidateLayout();
|
||||
fMenuField->Invalidate();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_MENU_FIELD_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_MENU_FIELD_TEST_H
|
||||
|
||||
|
||||
#include "ControlTest.h"
|
||||
|
||||
|
||||
class BFont;
|
||||
class BMenuField;
|
||||
class LabeledCheckBox;
|
||||
|
||||
|
||||
class MenuFieldTest : public ControlTest {
|
||||
public:
|
||||
MenuFieldTest();
|
||||
virtual ~MenuFieldTest();
|
||||
|
||||
static Test* CreateTest();
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void UpdateLabelText();
|
||||
void UpdateLabelFont();
|
||||
|
||||
private:
|
||||
BMenuField* fMenuField;
|
||||
LabeledCheckBox* fLongTextCheckBox;
|
||||
LabeledCheckBox* fBigFontCheckBox;
|
||||
BFont* fDefaultFont;
|
||||
BFont* fBigFont;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_MENU_FIELD_TEST_H
|
Loading…
Reference in New Issue
Block a user