xref: /haiku/src/libs/print/libprint/AboutBox.cpp (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * AboutBox.cpp
3  * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4  */
5 
6 #include <cstdio>
7 #include <string>
8 
9 #include <Window.h>
10 #include <View.h>
11 #include <Button.h>
12 
13 #include "AboutBox.h"
14 
15 #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
16 using namespace std;
17 #else
18 #define std
19 #endif
20 
21 enum {
22 	kMsgOK = 'AbOK'
23 };
24 
25 
26 class AboutBoxView : public BView {
27 public:
28 	AboutBoxView(BRect frame, const char *driver_name, const char *version, const char *copyright);
29 	virtual void Draw(BRect);
30 	virtual void AttachedToWindow();
31 
32 private:
33 	string fDriverName;
34 	string fVersion;
35 	string fCopyright;
36 };
37 
38 AboutBoxView::AboutBoxView(BRect rect, const char *driver_name, const char *version, const char *copyright)
39 	: BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW)
40 {
41 	fDriverName = driver_name;
42 	fVersion     = version;
43 	fCopyright   = copyright;
44 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
45 	SetDrawingMode(B_OP_SELECT);
46 }
47 
48 void AboutBoxView::Draw(BRect)
49 {
50 	SetHighColor(0, 0, 0);
51 	DrawString(fDriverName.c_str(), BPoint(10.0f, 16.0f));
52 	DrawString(" Driver for ");
53 	SetHighColor(0, 0, 0xff);
54 	DrawString("B");
55 	SetHighColor(0xff, 0, 0);
56 	DrawString("e");
57 	SetHighColor(0, 0, 0);
58 	DrawString("OS  Version ");
59 	DrawString(fVersion.c_str());
60 	DrawString(fCopyright.c_str(), BPoint(10.0f, 30.0f));
61 }
62 
63 void AboutBoxView::AttachedToWindow()
64 {
65 	BRect rect;
66 	rect.Set(110, 50, 175, 55);
67 	BButton *button = new BButton(rect, "", "OK", new BMessage(kMsgOK));
68 	AddChild(button);
69 	button->MakeDefault(true);
70 }
71 
72 class AboutBoxWindow : public BWindow {
73 public:
74 	AboutBoxWindow(BRect frame, const char *driver_name, const char *version, const char *copyright);
75 	virtual void MessageReceived(BMessage *msg);
76 	virtual	bool QuitRequested();
77 };
78 
79 AboutBoxWindow::AboutBoxWindow(BRect frame, const char *driver_name, const char *version, const char *copyright)
80 	: BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE )
81 {
82 	char title[256];
83 	sprintf(title, "About %s Driver", driver_name);
84 	SetTitle(title);
85 	AddChild(new AboutBoxView(Bounds(), driver_name, version, copyright));
86 }
87 
88 void AboutBoxWindow::MessageReceived(BMessage *msg)
89 {
90 	switch (msg->what) {
91 	case kMsgOK:
92 		be_app->PostMessage(B_QUIT_REQUESTED);
93 		break;
94 	}
95 }
96 
97 bool AboutBoxWindow::QuitRequested()
98 {
99 	be_app->PostMessage(B_QUIT_REQUESTED);
100 	return true;
101 }
102 
103 AboutBox::AboutBox(const char *signature, const char *driver_name, const char *version, const char *copyright)
104 	: BApplication(signature)
105 {
106 	BRect rect;
107 	rect.Set(100, 80, 400, 170);
108 	AboutBoxWindow *window = new AboutBoxWindow(rect, driver_name, version, copyright);
109 	window->Show();
110 }
111