1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include <Application.h>
7#include <OS.h>
8#include <Window.h>
9#include <WindowStack.h>
10
11
12static BRect* sFrames = NULL;
13static uint32 sNumFrames = 0;
14
15
16class TestApp : public BApplication {
17public:
18								TestApp(uint32 numWindows);
19	virtual						~TestApp();
20
21private:
22			void				_CreateFrames(uint32 numWindows);
23			int32				_WindowCreator();
24			static int32		_ThreadStarter(void* data);
25
26private:
27			uint32				fFrameNum;
28			uint32				fNumWindows;
29			uint32				fMaxWindows;
30};
31
32
33class TestWindow : public BWindow {
34public:
35						TestWindow(BRect frame);
36	virtual				~TestWindow();
37
38	virtual	void		DispatchMessage(BMessage* message, BHandler* handler);
39};
40
41
42TestApp::TestApp(uint32 numWindows)
43	:
44	BApplication("application/x.vnd-Haiku.stack-tile"),
45	fNumWindows(0),
46	fMaxWindows(numWindows)
47{
48	_CreateFrames(numWindows);
49}
50
51
52TestApp::~TestApp()
53{
54	delete[] sFrames;
55}
56
57
58void
59TestApp::_CreateFrames(uint32 numWindows)
60{
61	BWindowStack* stack = NULL;
62	while (fNumWindows < fMaxWindows) {
63		if (fFrameNum >= sNumFrames)
64			fFrameNum = 0;
65
66		BWindow* window = new TestWindow(BRect(20, 20, 300, 200));
67
68		if (!stack) stack = new BWindowStack(window);
69		else stack->AddWindow(window);
70
71		window->Show();
72		fNumWindows++;
73	}
74}
75
76
77TestWindow::TestWindow(BRect frame)
78	:
79	BWindow(frame, "Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
80{
81}
82
83
84TestWindow::~TestWindow()
85{
86}
87
88
89void
90TestWindow::DispatchMessage(BMessage* message, BHandler* handler)
91{
92	BWindow::DispatchMessage(message, handler);
93
94	int a = rand();
95	char buf[32];
96	sprintf(buf, "%d", a);
97	SetTitle(buf);
98}
99
100
101int
102main(int argc, char** argv)
103{
104	uint32 numWindows = 2;
105	if (argc > 1)
106		numWindows = atoi(argv[1]);
107
108	TestApp app(numWindows);
109	app.Run();
110
111	return 0;
112}
113