1 | #include <AppKit.h>
|
---|
2 | #include <InterfaceKit.h>
|
---|
3 |
|
---|
4 |
|
---|
5 | #define GO_MESSAGE 'MiGo'
|
---|
6 |
|
---|
7 |
|
---|
8 | class MyWin : public BWindow {
|
---|
9 | public:
|
---|
10 | MyWin(BRect rect) : BWindow(rect, "MenuFieldTest", B_TITLED_WINDOW
|
---|
11 | , B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS) {
|
---|
12 |
|
---|
13 | _CreateView(Bounds());
|
---|
14 |
|
---|
15 | }
|
---|
16 |
|
---|
17 |
|
---|
18 | virtual void MessageReceived(BMessage* message) {
|
---|
19 | switch (message->what) {
|
---|
20 | case GO_MESSAGE:
|
---|
21 | {
|
---|
22 | BView* containerView = ChildAt(0);
|
---|
23 |
|
---|
24 | if (containerView) {
|
---|
25 |
|
---|
26 | containerView->LockLooper();
|
---|
27 |
|
---|
28 | containerView->RemoveSelf();
|
---|
29 |
|
---|
30 | //This delete hangs approximately 1 out of every 6-8 tries
|
---|
31 | //The menufield is stalled at wait_for_thread() in it's destructor
|
---|
32 | //because _m_task_ won't exit properly
|
---|
33 | delete containerView;
|
---|
34 |
|
---|
35 | //Uncomment the following _CreateView() to hang immediately
|
---|
36 | //This one does weird things as well, I assume it's related
|
---|
37 | //_CreateView(Bounds());
|
---|
38 | }
|
---|
39 | }
|
---|
40 | break;
|
---|
41 | default:
|
---|
42 | BWindow::MessageReceived(message);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | void _CreateView(BRect rect) {
|
---|
48 | BView* containerView = new BView(Bounds(), NULL, B_FOLLOW_ALL_SIDES, 0);
|
---|
49 |
|
---|
50 | AddChild(containerView);
|
---|
51 |
|
---|
52 | BMenu* menu = new BMenu("Menu");
|
---|
53 |
|
---|
54 | menu->AddItem(new BMenuItem("Go", new BMessage(GO_MESSAGE)));
|
---|
55 |
|
---|
56 | containerView->AddChild(new BMenuField(BRect(0, 0, 200, 200)
|
---|
57 | , "MenuField", "TestMenuField", menu));
|
---|
58 | }
|
---|
59 | };
|
---|
60 |
|
---|
61 |
|
---|
62 | class MyApp : public BApplication {
|
---|
63 | public:
|
---|
64 | MyApp() : BApplication("application/x-vnd.cpr-mftest") {
|
---|
65 | MyWin* win = new MyWin(BRect(200, 200, 400, 400));
|
---|
66 |
|
---|
67 | win->Show();
|
---|
68 | }
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | int main(int argc, char** argv) {
|
---|
73 | MyApp app;
|
---|
74 |
|
---|
75 | app.Run();
|
---|
76 |
|
---|
77 | return 0;
|
---|
78 | }
|
---|