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