vfs: check userland buffers before reading them.
[haiku.git] / src / tests / add-ons / print / ppd / test / PPDConfigApplication.cpp
blob10a45ebbdd7fde0f69845ddc356c22712fe8aa36
1 /*
2 * Copyright 2008, Haiku.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Michael Pfeiffer <laplace@users.sourceforge.net>
7 */
9 #include "PPDConfigApplication.h"
10 #include "PrinterSelection.h"
12 AppWindow::AppWindow(BRect aRect)
13 : BWindow(aRect, APPLICATION, B_TITLED_WINDOW, 0) {
14 // add menu bar
15 BRect rect = BRect(0, 0, aRect.Width(), aRect.Height());
16 fMenuBar = new BMenuBar(rect, "menu_bar");
17 BMenu *menu;
19 menu = new BMenu("File");
20 menu->AddItem(new BMenuItem("About ...", new BMessage(B_ABOUT_REQUESTED), 'A'));
21 menu->AddSeparatorItem();
22 menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
23 fMenuBar->AddItem(menu);
25 AddChild(fMenuBar);
27 float x = aRect.Width() / 2 - 3;
28 float right = rect.right - 3;
30 // add view
31 aRect.Set(0, fMenuBar->Bounds().Height()+1, x, aRect.Height());
32 PrinterSelectionView* printerSelection = new PrinterSelectionView(aRect,
33 "printer-selection",
34 B_FOLLOW_TOP_BOTTOM,
35 B_WILL_DRAW);
36 AddChild(printerSelection);
37 printerSelection->SetMessage(new BMessage('prnt'));
38 printerSelection->SetTarget(this);
40 aRect.left = x + 3;
41 aRect.right = right;
42 AddChild(fConfig = new PPDConfigView(aRect, "ppd-config",
43 B_FOLLOW_ALL_SIDES,
44 B_WILL_DRAW));
46 // make window visible
47 Show();
50 void AppWindow::MessageReceived(BMessage *message) {
51 const char* file;
52 switch(message->what) {
53 case MENU_APP_NEW:
54 break;
55 case B_ABOUT_REQUESTED:
56 AboutRequested();
57 break;
58 case 'prnt':
59 if (message->FindString("file", &file) == B_OK) {
60 BMessage settings;
61 fConfig->Set(file, settings);
63 break;
64 default:
65 BWindow::MessageReceived(message);
70 bool AppWindow::QuitRequested() {
71 be_app->PostMessage(B_QUIT_REQUESTED);
72 return(true);
75 void AppWindow::AboutRequested() {
76 BAlert *about = new BAlert(APPLICATION,
77 APPLICATION " " VERSION "\nPrototype for PPD printer selection and configuration.\n\n"
78 "Written 2008.\n\n"
79 "By Michael Pfeiffer.\n\n"
80 "EMail: laplace@users.sourceforge.net.","Close");
81 about->Go();
84 PPDConfigApplication::PPDConfigApplication() : BApplication(SIGNATURE) {
85 BRect aRect;
86 // set up a rectangle and instantiate a new window
87 aRect.Set(100, 80, 950, 580);
88 window = NULL;
89 window = new AppWindow(aRect);
92 int main(int argc, char *argv[]) {
93 PPDConfigApplication app;
94 app.Run();
95 return 0;