1 /* 2 * Copyright 2008, Haiku. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Michael Pfeiffer <laplace@users.sourceforge.net> 7 */ 8 9 #include "PPDConfigApplication.h" 10 #include "PrinterSelection.h" 11 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; 18 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); 24 25 AddChild(fMenuBar); 26 27 float x = aRect.Width() / 2 - 3; 28 float right = rect.right - 3; 29 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); 39 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)); 45 46 // make window visible 47 Show(); 48 } 49 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); 62 } 63 break; 64 default: 65 BWindow::MessageReceived(message); 66 } 67 } 68 69 70 bool AppWindow::QuitRequested() { 71 be_app->PostMessage(B_QUIT_REQUESTED); 72 return(true); 73 } 74 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(); 82 } 83 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); 90 } 91 92 int main(int argc, char *argv[]) { 93 PPDConfigApplication app; 94 app.Run(); 95 return 0; 96 } 97