1 | #include <Application.h>
|
---|
2 | #include <Button.h>
|
---|
3 | #include <GroupLayout.h>
|
---|
4 | #include <InterfaceDefs.h>
|
---|
5 | #include <Menu.h>
|
---|
6 | #include <MenuBar.h>
|
---|
7 | #include <MenuItem.h>
|
---|
8 | #include <Message.h>
|
---|
9 | #include <Rect.h>
|
---|
10 | #include <Window.h>
|
---|
11 |
|
---|
12 |
|
---|
13 | class App : public BApplication {
|
---|
14 | public:
|
---|
15 | App();
|
---|
16 | ~App();
|
---|
17 |
|
---|
18 | protected:
|
---|
19 | void ReadyToRun();
|
---|
20 | bool QuitRequested();
|
---|
21 | };
|
---|
22 |
|
---|
23 |
|
---|
24 | App::App()
|
---|
25 | :
|
---|
26 | BApplication("application/x-vnd.Haiku-MenuTester")
|
---|
27 | {
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | App::~App(void)
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | void
|
---|
37 | App::ReadyToRun()
|
---|
38 | {
|
---|
39 | BWindow* window = new BWindow(BRect(100, 100, 400, 200), "menu tester window",
|
---|
40 | B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS);
|
---|
41 | window->SetLayout(new BGroupLayout(B_VERTICAL, B_USE_DEFAULT_SPACING));
|
---|
42 |
|
---|
43 | BMenuBar* menuBar = new BMenuBar("menu bar");
|
---|
44 | BMenu* fileMenu = new BMenu("File");
|
---|
45 | BMenuItem* closeItem = new BMenuItem("close", new BMessage(B_QUIT_REQUESTED));
|
---|
46 | fileMenu->AddItem(closeItem);
|
---|
47 | menuBar->AddItem(fileMenu);
|
---|
48 |
|
---|
49 | BMenu* editMenu = new BMenu("Edit");
|
---|
50 | BMenuItem* cutItem = new BMenuItem("cut", new BMessage(B_CUT));
|
---|
51 | editMenu->AddItem(cutItem);
|
---|
52 | BMenuItem* copyItem = new BMenuItem("copy", new BMessage(B_COPY));
|
---|
53 | editMenu->AddItem(copyItem);
|
---|
54 | BMenuItem* pasteItem = new BMenuItem("paste", new BMessage(B_PASTE));
|
---|
55 | editMenu->AddItem(pasteItem);
|
---|
56 | menuBar->AddItem(editMenu);
|
---|
57 |
|
---|
58 | window->GetLayout()->AddView(menuBar);
|
---|
59 |
|
---|
60 | BButton* closeWindowButton = new BButton("close", "Close Window",
|
---|
61 | new BMessage(B_QUIT_REQUESTED));
|
---|
62 | closeWindowButton->SetTarget(this);
|
---|
63 |
|
---|
64 | window->GetLayout()->AddView(closeWindowButton);
|
---|
65 |
|
---|
66 | window->Show();
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | bool
|
---|
71 | App::QuitRequested()
|
---|
72 | {
|
---|
73 | snooze(1000000);
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | int
|
---|
79 | main(void)
|
---|
80 | {
|
---|
81 | App app;
|
---|
82 | app.Run();
|
---|
83 |
|
---|
84 | return 0;
|
---|
85 | }
|
---|