[haiku-commits] r38172 - in haiku/trunk/src/tests/kits/interface: . bwindowstack

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 17 Aug 2010 08:50:36 +0200 (CEST)

Author: czeidler
Date: 2010-08-17 08:50:35 +0200 (Tue, 17 Aug 2010)
New Revision: 38172
Changeset: http://dev.haiku-os.org/changeset/38172

Added:
   haiku/trunk/src/tests/kits/interface/bwindowstack/
   haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.cpp
   haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.h
Modified:
   haiku/trunk/src/tests/kits/interface/Jamfile
Log:
Add a simple BWindowStack test app.



Modified: haiku/trunk/src/tests/kits/interface/Jamfile
===================================================================
--- haiku/trunk/src/tests/kits/interface/Jamfile        2010-08-17 06:47:26 UTC 
(rev 38171)
+++ haiku/trunk/src/tests/kits/interface/Jamfile        2010-08-17 06:50:35 UTC 
(rev 38172)
@@ -11,6 +11,7 @@
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
 SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
+SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ;
 
 SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
 
@@ -162,6 +163,11 @@
        : be $(TARGET_LIBSUPC++)
        ;
 
+SimpleTest WindowStackTest :
+       WindowStackTest.cpp
+       : be $(TARGET_LIBSUPC++)
+       ;
+
 SEARCH on [ FGristFiles
                ScrollView.cpp CheckBox.cpp ChannelSlider.cpp 
ChannelControl.cpp Slider.cpp Control.cpp
        ] = [ FDirName $(HAIKU_TOP) src kits interface ] ;

Added: haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.cpp
===================================================================
--- haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.cpp       
                        (rev 0)
+++ haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.cpp       
2010-08-17 06:50:35 UTC (rev 38172)
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2010, Haiku.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx>
+ */
+
+#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();
+}

Added: haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.h
===================================================================
--- haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.h         
                (rev 0)
+++ haiku/trunk/src/tests/kits/interface/bwindowstack/WindowStackTest.h 
2010-08-17 06:50:35 UTC (rev 38172)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010, Haiku.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx>
+ */
+#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


Other related posts:

  • » [haiku-commits] r38172 - in haiku/trunk/src/tests/kits/interface: . bwindowstack - clemens . zeidler