vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / newClipping / main.cpp
blob52048b397dbf219c378a0bf94367df67c498894a
1 #include <OS.h>
2 #include <Application.h>
3 #include <Window.h>
4 #include <View.h>
5 #include <Region.h>
6 #include <Rect.h>
7 #include <String.h>
9 #include <stdio.h>
10 #include <stdlib.h>
12 #include "MyView.h"
13 #include "Layer.h"
14 #include "WinBorder.h"
16 #define ApplicationSignature "application/x-vnd.generic-SkeletonApplication"
18 BWindow *wind = NULL;
20 class clsApp
22 public BApplication
24 public:
25 clsApp();
26 ~clsApp();
27 virtual void ReadyToRun();
30 class clsMainWindow
32 public BWindow
34 public:
35 clsMainWindow(const char *uWindowTitle);
36 ~clsMainWindow();
38 virtual bool QuitRequested();
39 void AddWindow(BRect frame, const char* name);
40 void test2();
41 void test1();
42 private:
43 MyView *fView;
46 clsApp::clsApp() : BApplication(ApplicationSignature)
48 srand(real_time_clock_usecs());
51 clsApp::~clsApp()
55 void clsApp::ReadyToRun()
60 clsMainWindow::clsMainWindow(const char *uWindowTitle)
62 BWindow(
63 BRect(50, 50, 800, 650),
64 uWindowTitle,
65 B_TITLED_WINDOW_LOOK,
66 B_NORMAL_WINDOW_FEEL,
67 0 )
69 wind = this;
70 fView = new MyView(Bounds(), "emu", B_FOLLOW_ALL, B_WILL_DRAW);
71 AddChild(fView);
72 fView->MakeFocus(true);
75 clsMainWindow::~clsMainWindow()
79 bool clsMainWindow::QuitRequested()
81 be_app->PostMessage(B_QUIT_REQUESTED);
82 return BWindow::QuitRequested();
86 // AddWindow
87 void
88 clsMainWindow::AddWindow(BRect frame, const char* name)
90 Layer* topLayer = fView->topLayer;
92 WinBorder* window = new WinBorder(frame, name, B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE,
93 (rgb_color){ 255, 203, 0, 255 });
94 topLayer->AddLayer(window);
96 // add a coupld children
97 frame.OffsetTo(B_ORIGIN);
98 frame.InsetBy(5.0, 5.0);
99 if (frame.IsValid()) {
100 Layer* layer1 = new Layer(frame, "View 1", B_FOLLOW_ALL,
101 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 180, 180, 180, 255 });
103 frame.OffsetTo(B_ORIGIN);
104 frame.InsetBy(15.0, 15.0);
105 if (frame.IsValid()) {
107 BRect f = frame;
108 f.bottom = f.top + f.Height() / 3 - 3;
109 f.right = f.left + f.Width() / 3 - 3;
111 // top row of views
112 Layer* layer;
113 layer = new Layer(f, "View", B_FOLLOW_LEFT | B_FOLLOW_TOP,
114 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
115 layer1->AddLayer(layer);
117 f.OffsetBy(f.Width() + 6, 0);
119 layer = new Layer(f, "View", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
120 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
121 layer1->AddLayer(layer);
123 f.OffsetBy(f.Width() + 6, 0);
125 layer = new Layer(f, "View", B_FOLLOW_RIGHT | B_FOLLOW_TOP,
126 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
127 layer1->AddLayer(layer);
129 // middle row of views
130 f = frame;
131 f.bottom = f.top + f.Height() / 3 - 3;
132 f.right = f.left + f.Width() / 3 - 3;
133 f.OffsetBy(0, f.Height() + 6);
135 layer = new Layer(f, "View", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
136 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
137 layer1->AddLayer(layer);
139 f.OffsetBy(f.Width() + 6, 0);
141 layer = new Layer(f, "View", B_FOLLOW_ALL,
142 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
143 layer1->AddLayer(layer);
145 f.OffsetBy(f.Width() + 6, 0);
147 layer = new Layer(f, "View", B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM,
148 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
149 layer1->AddLayer(layer);
151 // bottom row of views
152 f = frame;
153 f.bottom = f.top + f.Height() / 3 - 3;
154 f.right = f.left + f.Width() / 3 - 3;
155 f.OffsetBy(0, 2 * f.Height() + 12);
157 layer = new Layer(f, "View", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
158 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
159 layer1->AddLayer(layer);
161 f.OffsetBy(f.Width() + 6, 0);
163 layer = new Layer(f, "View", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM,
164 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
165 layer1->AddLayer(layer);
167 f.OffsetBy(f.Width() + 6, 0);
169 layer = new Layer(f, "View", B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM,
170 B_FULL_UPDATE_ON_RESIZE, (rgb_color){ 120, 120, 120, 255 });
171 layer1->AddLayer(layer);
174 window->AddLayer(layer1);
177 BRegion temp;
178 window->GetWantedRegion(temp);
179 topLayer->RebuildVisibleRegions(temp, window);
182 // test2
183 void
184 clsMainWindow::test2()
186 BRect frame(20, 20, 330, 230);
187 for (int32 i = 0; i < 20; i++) {
188 BString name("Window ");
189 frame.OffsetBy(20, 15);
190 name << i + 1;
191 AddWindow(frame, name.String());
194 frame.Set(10, 80, 320, 290);
195 for (int32 i = 20; i < 40; i++) {
196 BString name("Window ");
197 frame.OffsetBy(20, 15);
198 name << i + 1;
199 AddWindow(frame, name.String());
202 frame.Set(20, 140, 330, 230);
203 for (int32 i = 40; i < 60; i++) {
204 BString name("Window ");
205 frame.OffsetBy(20, 15);
206 name << i + 1;
207 AddWindow(frame, name.String());
210 frame.Set(20, 200, 330, 230);
211 for (int32 i = 60; i < 80; i++) {
212 BString name("Window ");
213 frame.OffsetBy(20, 15);
214 name << i + 1;
215 AddWindow(frame, name.String());
218 frame.Set(20, 260, 330, 230);
219 // 99 windows are ok, the 100th looper does not run anymore,
220 // I guess I'm hitting a BeOS limit (max loopers per app?)
221 for (int32 i = 80; i < 99; i++) {
222 BString name("Window ");
223 frame.OffsetBy(20, 15);
224 name << i + 1;
225 AddWindow(frame, name.String());
228 fView->RequestRedraw();
231 void clsMainWindow::test1()
233 Layer *topLayer = fView->topLayer;
235 rgb_color c;
237 c.red = rand()/256;
238 c.green = rand()/256;
239 c.blue = rand()/256;
240 // Layer *lay1
241 // = new Layer(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c);
242 // = new WinBorder(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c);
243 // topLayer->AddLayer(lay1);
244 // ------
245 WinBorder *wb1 = new WinBorder(BRect(20,20,300,220), "wb1", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
246 topLayer->AddLayer(wb1);
247 // same size as wb1
248 Layer *lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
249 wb1->AddLayer(lay1);
250 // ------
251 c.red = rand()/256;
252 c.green = rand()/256;
253 c.blue = rand()/256;
254 Layer *lay2 = new Layer(BRect(20,20,150,150), "lay2",
255 B_FOLLOW_NONE,
256 B_FULL_UPDATE_ON_RESIZE, c);
257 lay1->AddLayer(lay2);
259 c.red = rand()/256;
260 c.green = rand()/256;
261 c.blue = rand()/256;
262 Layer *lay3 = new Layer(BRect(20,20,100,100), "lay3",
263 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
264 0, c);
265 lay2->AddLayer(lay3);
267 c.red = rand()/256;
268 c.green = rand()/256;
269 c.blue = rand()/256;
270 Layer *lay12 = new Layer(BRect(170,20,290,150), "lay12",
271 B_FOLLOW_LEFT | B_FOLLOW_TOP,
272 // B_FOLLOW_NONE,
273 0, c);
274 lay1->AddLayer(lay12);
276 c.red = rand()/256;
277 c.green = rand()/256;
278 c.blue = rand()/256;
279 Layer *lay13 = new Layer(BRect(20,20,100,100), "lay13",
280 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
281 B_FOLLOW_RIGHT | B_FOLLOW_TOP,
282 // B_FOLLOW_LEFT | B_FOLLOW_V_CENTER,
283 // B_FOLLOW_H_CENTER | B_FOLLOW_TOP,
284 0, c);
285 lay12->AddLayer(lay13);
287 c.red = rand()/256;
288 c.green = rand()/256;
289 c.blue = rand()/256;
290 Layer *lay102 = new Layer(BRect(200,20,420,250), "lay102",
291 // B_FOLLOW_NONE,
292 B_FOLLOW_TOP_BOTTOM,
293 // B_FULL_UPDATE_ON_RESIZE, c);
294 0, c);
295 lay1->AddLayer(lay102);
297 c.red = rand()/256;
298 c.green = rand()/256;
299 c.blue = rand()/256;
300 Layer *lay103 = new Layer(BRect(0,0,100,50), "lay103",
301 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
302 // B_FOLLOW_LEFT | B_FOLLOW_TOP,
303 0, c);
304 lay102->AddLayer(lay103);
306 c.red = rand()/256;
307 c.green = rand()/256;
308 c.blue = rand()/256;
309 Layer *lay104 = new Layer(BRect(0,51,100,130), "lay104",
310 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
311 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM,
312 0, c);
313 lay102->AddLayer(lay104);
315 c.red = rand()/256;
316 c.green = rand()/256;
317 c.blue = rand()/256;
318 Layer *lay106 = new Layer(BRect(0,140,100, 200), "lay104",
319 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
320 B_FOLLOW_RIGHT | B_FOLLOW_TOP,
321 0, c);
322 lay102->AddLayer(lay106);
324 c.red = rand()/256;
325 c.green = rand()/256;
326 c.blue = rand()/256;
327 Layer *lay105 = new Layer(BRect(105,51,150,130), "lay104",
328 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
329 B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM,
330 0, c);
331 lay102->AddLayer(lay105);
333 //---------
334 c.red = rand()/256;
335 c.green = rand()/256;
336 c.blue = rand()/256;
337 WinBorder *wb2 = new WinBorder(BRect(280,120,600,420), "wb2", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
338 topLayer->AddLayer(wb2);
339 Layer *lay21 = new Layer(wb2->Bounds().OffsetToCopy(0,0), "lay21", B_FOLLOW_NONE, 0, c);
340 wb2->AddLayer(lay21);
342 c.red = rand()/256;
343 c.green = rand()/256;
344 c.blue = rand()/256;
345 Layer *lay22 = new Layer(BRect(20,20,150,150), "lay22",
346 B_FOLLOW_NONE,
347 0, c);
348 lay21->AddLayer(lay22);
351 WinBorder *wb3 = new WinBorder(BRect(20,20,300,220), "wb3", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
352 topLayer->AddLayer(wb3);
353 // same size as wb1
354 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
355 wb3->AddLayer(lay1);
357 WinBorder *wb4 = new WinBorder(BRect(20,20,300,220), "wb4", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
358 topLayer->AddLayer(wb4);
359 // same size as wb1
360 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
361 wb4->AddLayer(lay1);
363 WinBorder *wb5 = new WinBorder(BRect(20,20,300,220), "wb5", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
364 topLayer->AddLayer(wb5);
365 // same size as wb1
366 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
367 wb5->AddLayer(lay1);
369 WinBorder *wb6 = new WinBorder(BRect(20,20,300,220), "wb6", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
370 topLayer->AddLayer(wb6);
371 // same size as wb1
372 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
373 wb6->AddLayer(lay1);
375 WinBorder *wb7 = new WinBorder(BRect(20,20,300,220), "wb7", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
376 topLayer->AddLayer(wb7);
377 // same size as wb1
378 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
379 wb7->AddLayer(lay1);
381 WinBorder *wb8 = new WinBorder(BRect(20,20,300,220), "wb8", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
382 topLayer->AddLayer(wb8);
383 // same size as wb1
384 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
385 wb8->AddLayer(lay1);
387 WinBorder *wb9 = new WinBorder(BRect(20,20,300,220), "wb9", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
388 topLayer->AddLayer(wb9);
389 // same size as wb1
390 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
391 wb9->AddLayer(lay1);
393 WinBorder *wb10 = new WinBorder(BRect(20,20,300,220), "wb10", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c);
394 topLayer->AddLayer(wb10);
395 // same size as wb1
396 lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c);
397 wb10->AddLayer(lay1);
399 //---------
401 BRegion temp;
402 wb1->GetWantedRegion(temp);
403 topLayer->RebuildVisibleRegions(temp, wb1);
405 wb2->GetWantedRegion(temp);
406 topLayer->RebuildVisibleRegions(temp, wb2);
408 wb3->GetWantedRegion(temp);
409 topLayer->RebuildVisibleRegions(temp, wb3);
411 wb4->GetWantedRegion(temp);
412 topLayer->RebuildVisibleRegions(temp, wb4);
414 wb5->GetWantedRegion(temp);
415 topLayer->RebuildVisibleRegions(temp, wb5);
417 wb6->GetWantedRegion(temp);
418 topLayer->RebuildVisibleRegions(temp, wb6);
420 wb7->GetWantedRegion(temp);
421 topLayer->RebuildVisibleRegions(temp, wb7);
423 wb8->GetWantedRegion(temp);
424 topLayer->RebuildVisibleRegions(temp, wb8);
426 wb9->GetWantedRegion(temp);
427 topLayer->RebuildVisibleRegions(temp, wb9);
429 wb10->GetWantedRegion(temp);
430 topLayer->RebuildVisibleRegions(temp, wb10);
433 fView->RequestRedraw();
435 snooze(1000000);
437 wb1->Hide();
439 snooze(1000000);
441 wb1->Show();
445 snooze(2000000);
447 lay2->MoveBy(25,35);
449 snooze(2000000);
451 lay2->ResizeBy(45,55);
453 snooze(2000000);
455 lay2->ResizeBy(-45, -55);
458 snooze(2000000);
460 lay1->ScrollBy(0,50);
462 snooze(2000000);
464 lay2->Hide();
466 snooze(2000000);
468 lay2->Show();
470 snooze(2000000);
472 lay1->Invalidate(BRect(0,0,500,500));
476 int main()
478 new clsApp();
479 clsMainWindow *win = new clsMainWindow("clipping");
480 win->Show();
482 win->test2();
484 be_app->Run();
485 delete be_app;
486 return 0;