1 /*
2 * Copyright 2007, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
8
9
10 #include <stdio.h>
11
12 #include <Application.h>
13 #include <Menu.h>
14 #include <MenuBar.h>
15 #include <MenuItem.h>
16 #include <View.h>
17 #include <Window.h>
18
19
20 class MenuItem : public BMenuItem {
21 public:
22 MenuItem(const char* name);
23 virtual ~MenuItem();
24
25 virtual void DrawContent();
26 };
27
28
MenuItem(const char * name)29 MenuItem::MenuItem(const char* name)
30 : BMenuItem(name, NULL)
31 {
32 }
33
34
~MenuItem()35 MenuItem::~MenuItem()
36 {
37 }
38
39
40 void
DrawContent()41 MenuItem::DrawContent()
42 {
43 *(uint32*)0 = 0;
44 }
45
46
47 // #pragma mark -
48
49
50 class Window : public BWindow {
51 public:
52 Window();
53 virtual ~Window();
54
55 virtual bool QuitRequested();
56 };
57
58
Window()59 Window::Window()
60 : BWindow(BRect(100, 100, 400, 400), "MenuCrash-Test",
61 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
62 {
63 BMenuBar* menuBar = new BMenuBar(Bounds(), "menu");
64 AddChild(menuBar);
65
66 // add menu
67
68 BMenu* menu = new BMenu("File");
69 BMenu* crashMenu = new BMenu("Crash");
70 crashMenu->AddItem(new MenuItem("Crash"));
71 menu->AddItem(crashMenu);
72
73 menu->AddSeparatorItem();
74
75 menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
76 'Q', B_COMMAND_KEY));
77 menu->SetTargetForItems(this);
78 menuBar->AddItem(menu);
79 }
80
~Window()81 Window::~Window()
82 {
83 }
84
85
86 bool
QuitRequested()87 Window::QuitRequested()
88 {
89 be_app->PostMessage(B_QUIT_REQUESTED);
90 return true;
91 }
92
93
94 // #pragma mark -
95
96
97 class Application : public BApplication {
98 public:
99 Application();
100
101 virtual void ReadyToRun(void);
102 };
103
104
Application()105 Application::Application()
106 : BApplication("application/x-vnd.haiku-menu_crash")
107 {
108 }
109
110
111 void
ReadyToRun(void)112 Application::ReadyToRun(void)
113 {
114 Window *window = new Window();
115 window->Show();
116 }
117
118
119 // #pragma mark -
120
121
122 int
main(int argc,char ** argv)123 main(int argc, char **argv)
124 {
125 Application app;
126
127 app.Run();
128 return 0;
129 }
130