1 // Test works like this:
2 // Start the app from the terminal
3 // 1. Click on "menu ONE"
4 // 2. Click on "menu TWO".
5 // Examine the output.
6
7 #include <Application.h>
8 #include <Menu.h>
9 #include <MenuBar.h>
10 #include <MenuItem.h>
11 #include <Window.h>
12
13 #include <cstdio>
14
15
16 class TestWindow : public BWindow {
17 public:
18 TestWindow();
19 virtual void MenusBeginning();
20 virtual void MenusEnded();
21 };
22
23
24 void
show_window(BWindow * window)25 show_window(BWindow *window)
26 {
27 BMenuBar *bar = new BMenuBar(BRect(0, 0, 10, 10), "menuBar");
28
29 BMenu *menu = new BMenu("menu ONE");
30
31 menu->AddItem(new BMenuItem("ONE", new BMessage('1ONE')));
32 menu->AddItem(new BMenuItem("TWO", new BMessage('2TWO')));
33 bar->AddItem(menu);
34
35 menu = new BMenu("menu TWO");
36 menu->AddItem(new BMenuItem("ONE", new BMessage('1ONE')));
37 menu->AddItem(new BMenuItem("TWO", new BMessage('2TWO')));
38 bar->AddItem(menu);
39
40 window->AddChild(bar);
41 window->Show();
42 }
43
44
main()45 int main()
46 {
47 BApplication app("application/x-vnd.menu-test");
48 BWindow *window = new TestWindow();
49 show_window(window);
50 app.Run();
51 }
52
53
TestWindow()54 TestWindow::TestWindow()
55 :BWindow(BRect(100, 100, 400, 300), "menu test", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
56 {
57
58 }
59
60
61 void
MenusBeginning()62 TestWindow::MenusBeginning()
63 {
64 printf("MenusBeginning()\n");
65 }
66
67
68 void
MenusEnded()69 TestWindow::MenusEnded()
70 {
71 printf("MenusEnded()\n");
72 }
73