-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTranquility.cpp
156 lines (128 loc) · 3.2 KB
/
Tranquility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright 2009, Ryan Leavengood, [email protected]
// All rights reserved.
//
// Distributed under the terms of the MIT License.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "Tranquility.h"
#include "AppSignatures.h"
#include "BrowserWindow.h"
#include "Constants.h"
#include <Alert.h>
#include <Bitmap.h>
#include <OS.h>
#include <Roster.h>
#include <String.h>
#include <syslog.h>
#ifdef DEBUG
#include "LeakTracker.h"
#endif
Tranquility::Tranquility()
: BApplication(kBrowserAppSignature),
fMessenger(NULL)
{
}
Tranquility::~Tranquility()
{
delete fMessenger;
}
void
Tranquility::AboutRequested()
{
BAlert* alert = new BAlert("About Tranquility",
"Tranquility Web Browser\n\nby Ryan Leavengood", "Sweet!");
alert->Go();
}
void
Tranquility::ReadyToRun()
{
fBrowserWindow = new BrowserWindow();
be_roster->StartWatching(be_app_messenger, B_REQUEST_QUIT);
BMessage startMsg(kMsgStartRenderApp);
startMsg.AddRect("renderFrame", fBrowserWindow->Bounds());
startMsg.AddInt32("teamID", be_app->Team());
team_id renderTeam;
if (be_roster->Launch(kRenderAppSignature, &startMsg, &renderTeam) != B_OK) {
BAlert* alert = new BAlert("Error!",
"There was an error trying to launch the render process!", "Damn!");
alert->Go();
} else {
fMessenger = new BMessenger(kRenderAppSignature, renderTeam);
}
fBrowserWindow->Show();
}
void
Tranquility::MessageReceived(BMessage *message)
{
switch (message->what) {
case kMsgForward:
case kMsgUpdate:
{
if (fMessenger)
fMessenger->SendMessage(message);
break;
}
case kMsgBitmapData:
{
syslog(LOG_DEBUG, "Tranquility: received kMsgBitmapData message");
BBitmap *bitmap = dynamic_cast<BBitmap*>(BBitmap::Instantiate(message));
if (bitmap != NULL) {
fBrowserWindow->SetViewBitmap(bitmap);
delete bitmap;
} else {
syslog(LOG_DEBUG, "Tranquility: bitmap from message is not valid!");
}
// Code to create the bitmap from raw data and a bytes per row (bpr) value
/*int32 length = 0;
const void *data;
if (message->FindData("data", B_RAW_TYPE, &data, &length) == B_OK) {
int32 bpr;
if (message->FindInt32("bpr", &bpr) == B_OK) {
syslog(LOG_DEBUG, "Tranquility: got bpr from kMsgBitmapData message");
BBitmap bitmap(fBrowserWindow->Bounds(), B_RGB32);
bitmap.ImportBits(data, length, bpr, 0, B_RGB32);
fBrowserWindow->SetViewBitmap(&bitmap);
}
}*/
break;
}
case B_SOME_APP_QUIT:
{
BString sig;
if (message->FindString("be:signature", &sig) == B_OK) {
if (sig.Compare(kRenderAppSignature) == 0) {
BAlert* alert = new BAlert("Error!",
"The render process has quit!", "Damn!");
alert->Go();
fMessenger = NULL;
}
}
break;
}
default:
BApplication::MessageReceived(message);
break;
}
}
bool
Tranquility::QuitRequested()
{
be_roster->StopWatching(be_app_messenger);
if (fMessenger)
fMessenger->SendMessage(B_QUIT_REQUESTED);
return true;
}
// #pragma mark -
int
main(int, char **)
{
Tranquility *browser = new Tranquility();
browser->Run();
delete browser;
#ifdef DEBUG
DumpUnfreed();
#endif
return 0;
}