Added tests for BMenu and BMenuBar. The former is pretty useless, though,
since the menu resizes the window to an unusable size. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21429 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -24,6 +24,8 @@ SimpleTest WidgetLayoutTest :
|
||||
CheckBoxTest.cpp
|
||||
ControlTest.cpp
|
||||
ListViewTest.cpp
|
||||
MenuBarTest.cpp
|
||||
MenuTest.cpp
|
||||
:
|
||||
be
|
||||
;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "CheckBoxTest.h"
|
||||
#include "GroupView.h"
|
||||
#include "ListViewTest.h"
|
||||
#include "MenuBarTest.h"
|
||||
#include "MenuTest.h"
|
||||
#include "StringView.h"
|
||||
#include "Test.h"
|
||||
#include "TwoDimensionalSliderView.h"
|
||||
@@ -39,6 +41,8 @@ const test_info kTestInfos[] = {
|
||||
{ "BButton", ButtonTest::CreateTest },
|
||||
{ "BCheckBox", CheckBoxTest::CreateTest },
|
||||
{ "BListView", ListViewTest::CreateTest },
|
||||
{ "BMenu", MenuTest::CreateTest },
|
||||
{ "BMenuBar", MenuBarTest::CreateTest },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "MenuBarTest.h"
|
||||
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
|
||||
|
||||
enum {
|
||||
MSG_THIRD_ITEM = '3rdi',
|
||||
MSG_CHANGE_ITEM_TEXT = 'chit'
|
||||
};
|
||||
|
||||
|
||||
MenuBarTest::MenuBarTest()
|
||||
: Test("MenuBar", NULL),
|
||||
fMenuBar(new BMenuBar("The Menu"))
|
||||
|
||||
{
|
||||
SetView(fMenuBar);
|
||||
|
||||
// add a few items
|
||||
fMenuBar->AddItem(fFirstItem = new BMenuItem("Menu item 1", NULL));
|
||||
fMenuBar->AddItem(new BMenuItem("Menu item 2", NULL));
|
||||
fThirdItem = new BMenuItem("Menu item 3", NULL);
|
||||
}
|
||||
|
||||
|
||||
Test*
|
||||
MenuBarTest::CreateTest()
|
||||
{
|
||||
return new MenuBarTest;
|
||||
}
|
||||
|
||||
|
||||
// ActivateTest
|
||||
void
|
||||
MenuBarTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
group->SetSpacing(0, 8);
|
||||
controls->AddChild(group);
|
||||
|
||||
// third item
|
||||
fThirdItemCheckBox = new LabeledCheckBox("Third item",
|
||||
new BMessage(MSG_THIRD_ITEM), this);
|
||||
group->AddChild(fThirdItemCheckBox);
|
||||
|
||||
// long text
|
||||
fLongTextCheckBox = new LabeledCheckBox("Long label text",
|
||||
new BMessage(MSG_CHANGE_ITEM_TEXT), this);
|
||||
group->AddChild(fLongTextCheckBox);
|
||||
|
||||
group->AddChild(new Glue());
|
||||
|
||||
UpdateThirdItem();
|
||||
UpdateLongText();
|
||||
}
|
||||
|
||||
|
||||
// DectivateTest
|
||||
void
|
||||
MenuBarTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
MenuBarTest::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_THIRD_ITEM:
|
||||
UpdateThirdItem();
|
||||
break;
|
||||
case MSG_CHANGE_ITEM_TEXT:
|
||||
UpdateLongText();
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// UpdateThirdItem
|
||||
void
|
||||
MenuBarTest::UpdateThirdItem()
|
||||
{
|
||||
if (!fThirdItemCheckBox || !fMenuBar)
|
||||
return;
|
||||
|
||||
if (fThirdItemCheckBox->IsSelected() == (fThirdItem->Menu() != NULL))
|
||||
return;
|
||||
|
||||
if (fThirdItemCheckBox->IsSelected())
|
||||
fMenuBar->AddItem(fThirdItem);
|
||||
else
|
||||
fMenuBar->RemoveItem(fThirdItem);
|
||||
}
|
||||
|
||||
|
||||
// UpdateLongText
|
||||
void
|
||||
MenuBarTest::UpdateLongText()
|
||||
{
|
||||
if (!fLongTextCheckBox || !fMenuBar)
|
||||
return;
|
||||
|
||||
fFirstItem->SetLabel(fLongTextCheckBox->IsSelected()
|
||||
? "Very long text for a menu item"
|
||||
: "Menu item 1");
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_MENU_BAR_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_MENU_BAR_TEST_H
|
||||
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
|
||||
class BMenuBar;
|
||||
class BMenuItem;
|
||||
class LabeledCheckBox;
|
||||
|
||||
|
||||
class MenuBarTest : public Test {
|
||||
public:
|
||||
MenuBarTest();
|
||||
|
||||
static Test* CreateTest();
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void UpdateThirdItem();
|
||||
void UpdateLongText();
|
||||
|
||||
private:
|
||||
BMenuBar* fMenuBar;
|
||||
BMenuItem* fFirstItem;
|
||||
BMenuItem* fThirdItem;
|
||||
LabeledCheckBox* fThirdItemCheckBox;
|
||||
LabeledCheckBox* fLongTextCheckBox;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_MENU_BAR_TEST_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "MenuTest.h"
|
||||
|
||||
#include <Menu.h>
|
||||
#include <MenuItem.h>
|
||||
|
||||
class TestMenu : public BMenu {
|
||||
public:
|
||||
TestMenu(const char* title)
|
||||
: BMenu(BRect(), title, B_FOLLOW_NONE,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT,
|
||||
B_ITEMS_IN_COLUMN, false)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
MenuTest::MenuTest()
|
||||
: Test("Menu", NULL),
|
||||
fMenu(new TestMenu("The Menu"))
|
||||
{
|
||||
SetView(fMenu);
|
||||
|
||||
// add a few items
|
||||
for (int32 i = 0; i < 15; i++) {
|
||||
BString itemText("menu item ");
|
||||
itemText << i;
|
||||
fMenu->AddItem(new BMenuItem(itemText.String(), NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Test*
|
||||
MenuTest::CreateTest()
|
||||
{
|
||||
return new MenuTest;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_MENU_TEST_H
|
||||
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
|
||||
class BMenu;
|
||||
|
||||
|
||||
class MenuTest : public Test {
|
||||
public:
|
||||
MenuTest();
|
||||
|
||||
static Test* CreateTest();
|
||||
|
||||
private:
|
||||
BMenu* fMenu;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_LIST_VIEW_TEST_H
|
||||
Reference in New Issue
Block a user