Add a simple BWindowStack test app.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38172 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-08-17 06:50:35 +00:00
parent 5836cd75c2
commit e71b4c11de
3 changed files with 236 additions and 0 deletions
+6
View File
@@ -11,6 +11,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ;
SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ; SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
@@ -162,6 +163,11 @@ SimpleTest TextViewTest :
: be $(TARGET_LIBSUPC++) : be $(TARGET_LIBSUPC++)
; ;
SimpleTest WindowStackTest :
WindowStackTest.cpp
: be $(TARGET_LIBSUPC++)
;
SEARCH on [ FGristFiles SEARCH on [ FGristFiles
ScrollView.cpp CheckBox.cpp ChannelSlider.cpp ChannelControl.cpp Slider.cpp Control.cpp ScrollView.cpp CheckBox.cpp ChannelSlider.cpp ChannelControl.cpp Slider.cpp Control.cpp
] = [ FDirName $(HAIKU_TOP) src kits interface ] ; ] = [ FDirName $(HAIKU_TOP) src kits interface ] ;
@@ -0,0 +1,178 @@
/*
* Copyright 2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler <[email protected]>
*/
#include "WindowStackTest.h"
#include <Alert.h>
#include <Application.h>
#include <ControlLook.h>
#include <Roster.h>
#include <String.h>
#include <Window.h>
#include <WindowStack.h>
const int32 kGetWindows = '&GeW';
const int32 kAddWindow = '&AdW';
const int32 kRemoveWindow = '&ReW';
WindowListItem::WindowListItem(const char* text, BWindow* window)
:
BStringItem(text),
fWindow(window)
{
}
MainView::MainView()
:
BBox("MainView")
{
fStackedWindowsLabel = new BStringView("label", "Stacked windows:");
fStackedWindowsList = new BListView;
fGetWindowsButton = new BButton("Get Windows", new BMessage(kGetWindows));
fAddWindowButton = new BButton("Add Window", new BMessage(kAddWindow));
fRemoveWindowButton = new BButton("Remove Window",
new BMessage(kRemoveWindow));
float spacing = be_control_look->DefaultItemSpacing();
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
.AddGroup(B_HORIZONTAL, spacing)
.Add(fStackedWindowsLabel)
.AddGlue()
.End()
.Add(fStackedWindowsList)
.AddGroup(B_HORIZONTAL, spacing)
.AddGlue()
.Add(fGetWindowsButton)
.Add(fRemoveWindowButton)
.Add(fAddWindowButton)
.End()
//.SetInsets(spacing, spacing, spacing, spacing)
);
}
void
MainView::AttachedToWindow()
{
fGetWindowsButton->SetTarget(this);
fAddWindowButton->SetTarget(this);
fRemoveWindowButton->SetTarget(this);
}
void
MainView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kGetWindows:
{
BWindowStack windowStack(Window());
/*BString string;
string << windowStack.CountWindows();
BAlert* alert = new BAlert("title", "Count: ", string.String());
alert->Go();*/
int32 stackWindowCount = windowStack.CountWindows();
fStackedWindowsList->MakeEmpty();
for (int i = 0; i < stackWindowCount; i++) {
BString result;
BMessenger messenger;//(NULL, Window());
windowStack.WindowAt(i, messenger);
// don't deadlock
if (!messenger.IsTargetLocal()) {
BMessage message(B_GET_PROPERTY);
message.AddSpecifier("Title");
BMessage reply;
messenger.SendMessage(&message, &reply);
reply.FindString("result", &result);
}
else
result = Window()->Title();
fStackedWindowsList->AddItem(new BStringItem(
result.String()));
}
break;
}
case kAddWindow:
{
app_info appInfo;
if (be_app->GetAppInfo(&appInfo) != B_OK)
break;
team_id team;
BRoster roster;
//roster.Launch("application/x-vnd.windowstack_test", (BMessage*)NULL,
// &team);
roster.Launch(&appInfo.ref, (BMessage*)NULL,
&team);
BMessage message(B_GET_PROPERTY);
message.AddSpecifier("Window", int32(0));
BMessage reply;
BMessenger appMessenger(NULL, team);
appMessenger.SendMessage(&message, &reply);
BMessenger window;
reply.FindMessenger("result", &window);
int32 error = 0;
reply.FindInt32("error", &error);
BWindowStack windowStack(Window());
if (windowStack.HasWindow(window)) {
BAlert* alert = new BAlert("API Error",
"Window on stack but should not be there!", "Ok");
alert->Go();
}
windowStack.AddWindow(window);
if (!windowStack.HasWindow(window)) {
BAlert* alert = new BAlert("API Error",
"Window not on stack but should be there!", "Ok");
alert->Go();
}
break;
}
case kRemoveWindow:
{
BWindowStack windowStack(Window());
BMessenger messenger;
windowStack.WindowAt(0, messenger);
windowStack.RemoveWindow(messenger);
break;
}
}
BView::MessageReceived(message);
}
int main()
{
BApplication app("application/x-vnd.windowstack_test");
BWindow *window = new BWindow(BRect(100, 100, 500, 300),
"BWindowStackTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
window->SetLayout(new BGroupLayout(B_VERTICAL));
window->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(new MainView)
.SetInsets(10, 10, 10, 10)
);
window->Show();
app.Run();
}
@@ -0,0 +1,52 @@
/*
* Copyright 2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler <[email protected]>
*/
#ifndef WINDOW_STACK_TEST_H
#define WINDOW_STACK_TEST_H
#include <Box.h>
#include <Button.h>
#include <GroupLayoutBuilder.h>
#include <ListView.h>
#include <StringItem.h>
#include <StringView.h>
class BWindow;
class WindowListItem : public BStringItem
{
public:
WindowListItem(const char* text, BWindow* window);
BWindow* Window() { return fWindow; }
private:
BWindow* fWindow;
};
class MainView : public BBox
{
public:
MainView();
virtual ~MainView() {}
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
private:
BStringView* fStackedWindowsLabel;
BListView* fStackedWindowsList;
BButton* fGetWindowsButton;
BButton* fAddWindowButton;
BButton* fRemoveWindowButton;
};
#endif