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