xref: /haiku/src/tests/add-ons/print/pdf/linepathbuilder/LPBApp.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 #include "LPBApp.h"
2 
3 BMessage* NewMessage(uint32 what, uint32 data)
4 {
5 	BMessage* m = new BMessage(what);
6 	m->AddInt32("data", (int32)data);
7 	return m;
8 }
9 
10 
11 AppWindow::AppWindow(BRect aRect)
12 	: BWindow(aRect, APPLICATION, B_TITLED_WINDOW, 0) {
13 	// add menu bar
14 	BRect rect = BRect(0,0,aRect.Width(), aRect.Height());
15 	menubar = new BMenuBar(rect, "menu_bar");
16 	BMenu *menu;
17 
18 	menu = new BMenu("Test");
19 	menu->AddItem(new BMenuItem("About ...", new BMessage(B_ABOUT_REQUESTED)));
20 	menu->AddSeparatorItem();
21 	menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
22 	menubar->AddItem(menu);
23 
24 	menu = new BMenu("Line Cap");
25 	menu->AddItem(new BMenuItem("Round",  NewMessage(CAP_MSG, B_ROUND_CAP)));
26 	menu->AddItem(new BMenuItem("Butt",   NewMessage(CAP_MSG, B_BUTT_CAP)));
27 	menu->AddItem(new BMenuItem("Square", NewMessage(CAP_MSG, B_SQUARE_CAP)));
28 	menubar->AddItem(menu);
29 
30 	menu = new BMenu("Line Join");
31 	menu->AddItem(new BMenuItem("Round",  NewMessage(JOIN_MSG, B_ROUND_JOIN)));
32 	menu->AddItem(new BMenuItem("Miter",  NewMessage(JOIN_MSG, B_MITER_JOIN)));
33 	menu->AddItem(new BMenuItem("Bevel",  NewMessage(JOIN_MSG, B_BEVEL_JOIN)));
34 	menu->AddItem(new BMenuItem("Butt",   NewMessage(JOIN_MSG, B_BUTT_JOIN)));
35 	menu->AddItem(new BMenuItem("Square", NewMessage(JOIN_MSG, B_SQUARE_JOIN)));
36 	menubar->AddItem(menu);
37 
38 	menu = new BMenu("Path");
39 	menu->AddItem(new BMenuItem("Open", new BMessage(OPEN_MSG)));
40 	menu->AddItem(new BMenuItem("Close", new BMessage(CLOSE_MSG)));
41 	menubar->AddItem(menu);
42 
43 	AddChild(menubar);
44 	// add path view
45 	aRect.Set(0, menubar->Bounds().Height()+1, aRect.Width(), aRect.Height());
46 	view = NULL;
47 	AddChild(view = new PathView(aRect));
48 	// make window visible
49 	Show();
50 }
51 
52 void AppWindow::MessageReceived(BMessage *message) {
53 	int32 data;
54 	message->FindInt32("data", &data);
55 
56 	switch(message->what) {
57 	case MENU_APP_NEW:
58 		break;
59 	case B_ABOUT_REQUESTED:
60 		AboutRequested();
61 		break;
62 	case CAP_MSG:
63 		view->SetLineMode((cap_mode)data, view->LineJoinMode(), view->LineMiterLimit());
64 		view->Invalidate();
65 		break;
66 	case JOIN_MSG:
67 		view->SetLineMode(view->LineCapMode(), (join_mode)data, view->LineMiterLimit());
68 		view->Invalidate();
69 		break;
70 	case OPEN_MSG:
71 	case CLOSE_MSG:
72 		view->SetClose(message->what == CLOSE_MSG);
73 		view->Invalidate();
74 		break;
75 	default:
76 		BWindow::MessageReceived(message);
77 	}
78 }
79 
80 
81 bool AppWindow::QuitRequested() {
82 	be_app->PostMessage(B_QUIT_REQUESTED);
83 	return(true);
84 }
85 
86 void AppWindow::AboutRequested() {
87 	BAlert *about = new BAlert(APPLICATION,
88 		APPLICATION " " VERSION "\nThis program is freeware under BSD/MIT license.\n\n"
89 		"Written 2002.\n\n"
90 		"By Michael Pfeiffer.\n\n"
91 		"EMail: michael.pfeiffer@utanet.at.","Close");
92 		about->Go();
93 }
94 
95 App::App() : BApplication("application/x-vnd.obos.LinePathBuilder") {
96 	BRect aRect;
97 	// set up a rectangle and instantiate a new window
98 	aRect.Set(100, 80, 410, 380);
99 	window = NULL;
100 	window = new AppWindow(aRect);
101 }
102 
103 int main(int argc, char *argv[]) {
104 	be_app = NULL;
105 	App app;
106 	be_app->Run();
107 	return 0;
108 }
109