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
16using namespace std;
17
18
19enum {
20	kMsgOK = 'AbOK'
21};
22
23
24class AboutBoxView : public BView {
25public:
26	AboutBoxView(BRect frame, const char *driver_name, const char *version, const char *copyright);
27	virtual void Draw(BRect);
28	virtual void AttachedToWindow();
29
30private:
31	string fDriverName;
32	string fVersion;
33	string fCopyright;
34};
35
36AboutBoxView::AboutBoxView(BRect rect, const char *driver_name, const char *version, const char *copyright)
37	: BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW)
38{
39	fDriverName = driver_name;
40	fVersion     = version;
41	fCopyright   = copyright;
42	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
43	SetDrawingMode(B_OP_SELECT);
44}
45
46void AboutBoxView::Draw(BRect)
47{
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));
59}
60
61void AboutBoxView::AttachedToWindow()
62{
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);
68}
69
70class AboutBoxWindow : public BWindow {
71public:
72	AboutBoxWindow(BRect frame, const char *driver_name, const char *version, const char *copyright);
73	virtual void MessageReceived(BMessage *msg);
74	virtual	bool QuitRequested();
75};
76
77AboutBoxWindow::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)
80{
81	char title[256];
82	sprintf(title, "About %s Driver", driver_name);
83	SetTitle(title);
84	AddChild(new AboutBoxView(Bounds(), driver_name, version, copyright));
85}
86
87void AboutBoxWindow::MessageReceived(BMessage *msg)
88{
89	switch (msg->what) {
90	case kMsgOK:
91		be_app->PostMessage(B_QUIT_REQUESTED);
92		break;
93	}
94}
95
96bool AboutBoxWindow::QuitRequested()
97{
98	be_app->PostMessage(B_QUIT_REQUESTED);
99	return true;
100}
101
102AboutBox::AboutBox(const char *signature, const char *driver_name, const char *version, const char *copyright)
103	: BApplication(signature)
104{
105	BRect rect;
106	rect.Set(100, 80, 400, 170);
107	AboutBoxWindow *window = new AboutBoxWindow(rect, driver_name, version, copyright);
108	window->Show();
109}
110