vfs: check userland buffers before reading them.
[haiku.git] / src / libs / print / libprint / AboutBox.cpp
blob8c5f895029302eacf34969f6440b4f22d25ac4d5
1 /*
2 * AboutBox.cpp
3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 */
6 #include <cstdio>
7 #include <string>
9 #include <Window.h>
10 #include <View.h>
11 #include <Button.h>
13 #include "AboutBox.h"
16 using namespace std;
19 enum {
20 kMsgOK = 'AbOK'
24 class AboutBoxView : public BView {
25 public:
26 AboutBoxView(BRect frame, const char *driver_name, const char *version, const char *copyright);
27 virtual void Draw(BRect);
28 virtual void AttachedToWindow();
30 private:
31 string fDriverName;
32 string fVersion;
33 string fCopyright;
36 AboutBoxView::AboutBoxView(BRect rect, const char *driver_name, const char *version, const char *copyright)
37 : BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW)
39 fDriverName = driver_name;
40 fVersion = version;
41 fCopyright = copyright;
42 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
43 SetDrawingMode(B_OP_SELECT);
46 void AboutBoxView::Draw(BRect)
48 SetHighColor(0, 0, 0);
49 DrawString(fDriverName.c_str(), BPoint(10.0f, 16.0f));
50 DrawString(" Driver for ");
51 SetHighColor(0, 0, 0xff);
52 DrawString("B");
53 SetHighColor(0xff, 0, 0);
54 DrawString("e");
55 SetHighColor(0, 0, 0);
56 DrawString("OS Version ");
57 DrawString(fVersion.c_str());
58 DrawString(fCopyright.c_str(), BPoint(10.0f, 30.0f));
61 void AboutBoxView::AttachedToWindow()
63 BRect rect;
64 rect.Set(110, 50, 175, 55);
65 BButton *button = new BButton(rect, "", "OK", new BMessage(kMsgOK));
66 AddChild(button);
67 button->MakeDefault(true);
70 class AboutBoxWindow : public BWindow {
71 public:
72 AboutBoxWindow(BRect frame, const char *driver_name, const char *version, const char *copyright);
73 virtual void MessageReceived(BMessage *msg);
74 virtual bool QuitRequested();
77 AboutBoxWindow::AboutBoxWindow(BRect frame, const char *driver_name, const char *version, const char *copyright)
78 : BWindow(frame, "", B_TITLED_WINDOW,
79 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE)
81 char title[256];
82 sprintf(title, "About %s Driver", driver_name);
83 SetTitle(title);
84 AddChild(new AboutBoxView(Bounds(), driver_name, version, copyright));
87 void AboutBoxWindow::MessageReceived(BMessage *msg)
89 switch (msg->what) {
90 case kMsgOK:
91 be_app->PostMessage(B_QUIT_REQUESTED);
92 break;
96 bool AboutBoxWindow::QuitRequested()
98 be_app->PostMessage(B_QUIT_REQUESTED);
99 return true;
102 AboutBox::AboutBox(const char *signature, const char *driver_name, const char *version, const char *copyright)
103 : BApplication(signature)
105 BRect rect;
106 rect.Set(100, 80, 400, 170);
107 AboutBoxWindow *window = new AboutBoxWindow(rect, driver_name, version, copyright);
108 window->Show();