|
|
|
|
| 21 |
* |
21 |
* |
| 22 |
* Contributor(s): |
22 |
* Contributor(s): |
| 23 |
* Takashi Toyoshima <toyoshim@be-in.org> |
23 |
* Takashi Toyoshima <toyoshim@be-in.org> |
|
|
24 |
* Fredrik Holmqvist <thesuckiestemail@yahoo.se> |
| 24 |
* |
25 |
* |
| 25 |
* Alternatively, the contents of this file may be used under the terms of |
26 |
* Alternatively, the contents of this file may be used under the terms of |
| 26 |
* either of the GNU General Public License Version 2 or later (the "GPL"), |
27 |
* either of the GNU General Public License Version 2 or later (the "GPL"), |
|
|
| 42 |
#include "nsIObserver.h" |
43 |
#include "nsIObserver.h" |
| 43 |
|
44 |
|
| 44 |
#include <Application.h> |
45 |
#include <Application.h> |
|
|
46 |
#include <AppFileInfo.h> |
| 45 |
#include <Window.h> |
47 |
#include <Window.h> |
| 46 |
#include <View.h> |
48 |
#include <View.h> |
| 47 |
#include <StringView.h> |
49 |
#include <StringView.h> |
|
|
| 54 |
#define DEBUG_SPLASH 1 |
56 |
#define DEBUG_SPLASH 1 |
| 55 |
#endif |
57 |
#endif |
| 56 |
|
58 |
|
| 57 |
class nsSplashScreenBeOS : public nsISplashScreen, |
59 |
class nsNativeAppSupportBeOS : public nsNativeAppSupportBase, public nsIObserver |
| 58 |
public nsIObserver { |
60 |
{ |
| 59 |
public: |
61 |
public: |
| 60 |
nsSplashScreenBeOS(); |
62 |
nsNativeAppSupportBeOS(); |
| 61 |
virtual ~nsSplashScreenBeOS(); |
63 |
~nsNativeAppSupportBeOS(); |
|
|
64 |
NS_DECL_ISUPPORTS |
| 65 |
NS_DECL_NSINATIVEAPPSUPPORT |
| 66 |
NS_DECL_NSIOBSERVER |
| 67 |
|
| 68 |
private: |
| 69 |
nsresult LoadBitmap(); |
| 70 |
|
| 71 |
BWindow *window; |
| 72 |
BBitmap *bitmap; |
| 73 |
BStringView *textView; |
| 74 |
}; // nsNativeAppSupportBeOS |
| 62 |
|
75 |
|
| 63 |
NS_DECL_ISUPPORTS |
|
|
| 64 |
|
76 |
|
| 65 |
NS_IMETHOD Show(); |
77 |
class nsBeOSApp : public BApplication |
| 66 |
NS_IMETHOD Hide(); |
78 |
{ |
|
|
79 |
public: |
| 80 |
nsBeOSApp(sem_id sem) : BApplication( GetAppSig() ), init(sem) |
| 81 |
{} |
| 82 |
|
| 83 |
void ReadyToRun() |
| 84 |
{ |
| 85 |
release_sem(init); |
| 86 |
} |
| 67 |
|
87 |
|
| 68 |
NS_DECL_NSIOBSERVER |
88 |
static int32 Main( void *args ) |
|
|
89 |
{ |
| 90 |
nsBeOSApp *app = new nsBeOSApp( (sem_id)args ); |
| 91 |
if( app == NULL ) |
| 92 |
return B_ERROR; |
| 93 |
return app->Run(); |
| 94 |
} |
| 69 |
|
95 |
|
| 70 |
private: |
96 |
private: |
| 71 |
nsresult LoadBitmap(); |
|
|
| 72 |
|
97 |
|
| 73 |
BWindow *window; |
98 |
char *GetAppSig(void) |
| 74 |
BBitmap *bitmap; |
99 |
{ |
| 75 |
BStringView *textView; |
100 |
image_info info; |
| 76 |
}; // class nsSplashScreenBeOS |
101 |
int32 cookie = 0; |
|
|
102 |
BFile file; |
| 103 |
BAppFileInfo appFileInfo; |
| 104 |
static char sig[B_MIME_TYPE_LENGTH]; |
| 105 |
|
| 106 |
sig[0] = 0; |
| 107 |
if (get_next_image_info(0, &cookie, &info) == B_OK && |
| 108 |
file.SetTo(info.name, B_READ_ONLY) == B_OK && |
| 109 |
appFileInfo.SetTo(&file) == B_OK && |
| 110 |
appFileInfo.GetSignature(sig) == B_OK) { |
| 111 |
return sig; |
| 112 |
} |
| 113 |
return "application/x-vnd.Mozilla"; |
| 114 |
} |
| 77 |
|
115 |
|
| 78 |
nsSplashScreenBeOS::nsSplashScreenBeOS() |
116 |
sem_id init; |
| 79 |
: window( NULL ) , bitmap( NULL ), textView(NULL) { |
117 |
}; //class nsBeOSApp |
| 80 |
#ifdef DEBUG_SPLASH |
118 |
|
| 81 |
puts("nsSplashScreenBeOS::nsSlpashScreenBeOS()"); |
119 |
// Create and return an instance of class nsNativeAppSupportBeOS. |
| 82 |
#endif |
120 |
nsresult |
|
|
121 |
NS_CreateNativeAppSupport( nsINativeAppSupport **aResult ) |
| 122 |
{ |
| 123 |
if ( !aResult ) { |
| 124 |
return NS_ERROR_NULL_POINTER; |
| 125 |
} |
| 126 |
nsNativeAppSupportBeOS *pNative = new nsNativeAppSupportBeOS(); |
| 127 |
if ( !pNative ) { |
| 128 |
return NS_ERROR_OUT_OF_MEMORY; |
| 129 |
} |
| 130 |
*aResult = pNative; |
| 131 |
NS_ADDREF( *aResult ); |
| 132 |
return NS_OK; |
| 83 |
} |
133 |
} |
| 84 |
|
134 |
|
| 85 |
nsSplashScreenBeOS::~nsSplashScreenBeOS() { |
135 |
nsNativeAppSupportBeOS::nsNativeAppSupportBeOS() |
| 86 |
#ifdef DEBUG_SPLASH |
136 |
: window( NULL ) , bitmap( NULL ), textView(NULL) |
| 87 |
puts("nsSplashScreenBeOS::~nsSlpashScreenBeOS()"); |
137 |
{} |
| 88 |
#endif |
138 |
|
| 89 |
Hide(); |
139 |
nsNativeAppSupportBeOS::~nsNativeAppSupportBeOS() |
|
|
140 |
{ |
| 141 |
if(window != NULL) HideSplashScreen(); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
NS_IMPL_ISUPPORTS2(nsNativeAppSupportBeOS, nsINativeAppSupport, nsIObserver) |
| 146 |
|
| 147 |
NS_IMETHODIMP |
| 148 |
nsNativeAppSupportBeOS::Start( PRBool *aResult ) |
| 149 |
{ |
| 150 |
NS_ENSURE_ARG( aResult ); |
| 151 |
NS_ENSURE_TRUE( be_app == NULL, NS_ERROR_NOT_INITIALIZED ); |
| 152 |
|
| 153 |
sem_id initsem = create_sem(0, "Mozilla BApplication init"); |
| 154 |
if (initsem < B_OK) |
| 155 |
return NS_ERROR_FAILURE; |
| 156 |
thread_id tid = spawn_thread(nsBeOSApp::Main, "Mozilla BApplication", B_NORMAL_PRIORITY, (void *)initsem); |
| 157 |
* aResult = PR_TRUE; |
| 158 |
if (tid < B_OK || B_OK != resume_thread(tid)) |
| 159 |
* aResult = PR_FALSE; |
| 160 |
|
| 161 |
if (B_OK != acquire_sem(initsem)) |
| 162 |
* aResult = PR_FALSE; |
| 163 |
|
| 164 |
if (B_OK != delete_sem(initsem)) |
| 165 |
* aResult = PR_FALSE; |
| 166 |
return * aResult == PR_TRUE ? NS_OK : NS_ERROR_FAILURE; |
| 167 |
} |
| 168 |
|
| 169 |
NS_IMETHODIMP |
| 170 |
nsNativeAppSupportBeOS::Stop( PRBool *aResult ) |
| 171 |
{ |
| 172 |
NS_ENSURE_ARG( aResult ); |
| 173 |
NS_ENSURE_TRUE( be_app, NS_ERROR_NOT_INITIALIZED ); |
| 174 |
|
| 175 |
*aResult = PR_TRUE; |
| 176 |
return NS_OK; |
| 177 |
} |
| 178 |
|
| 179 |
NS_IMETHODIMP |
| 180 |
nsNativeAppSupportBeOS::Quit() |
| 181 |
{ |
| 182 |
return NS_OK; |
| 183 |
} |
| 184 |
|
| 185 |
NS_IMETHODIMP |
| 186 |
nsNativeAppSupportBeOS::EnsureProfile(nsICmdLineService* args) |
| 187 |
{ |
| 188 |
return NS_OK; |
| 90 |
} |
189 |
} |
| 91 |
|
190 |
|
| 92 |
NS_IMPL_ISUPPORTS2(nsSplashScreenBeOS, nsISplashScreen, nsIObserver) |
191 |
NS_IMETHODIMP |
|
|
192 |
nsNativeAppSupportBeOS::ReOpen() |
| 193 |
{ |
| 194 |
return NS_ERROR_NOT_IMPLEMENTED; |
| 195 |
} |
| 93 |
|
196 |
|
| 94 |
NS_IMETHODIMP |
197 |
NS_IMETHODIMP |
| 95 |
nsSplashScreenBeOS::Show() { |
198 |
nsNativeAppSupportBeOS::OnLastWindowClosing() |
|
|
199 |
{ |
| 200 |
return NS_OK; |
| 201 |
} |
| 202 |
|
| 203 |
NS_IMETHODIMP |
| 204 |
nsNativeAppSupportBeOS::GetIsServerMode(PRBool *aIsServerMode) { |
| 205 |
*aIsServerMode = PR_FALSE; |
| 206 |
return NS_OK; |
| 207 |
} |
| 208 |
|
| 209 |
NS_IMETHODIMP |
| 210 |
nsNativeAppSupportBeOS::SetIsServerMode(PRBool aIsServerMode) { |
| 211 |
mServerMode = aIsServerMode; |
| 212 |
return NS_ERROR_NOT_IMPLEMENTED; |
| 213 |
} |
| 214 |
|
| 215 |
NS_IMETHODIMP |
| 216 |
nsNativeAppSupportBeOS::StartServerMode() { |
| 217 |
return NS_ERROR_NOT_IMPLEMENTED; |
| 218 |
} |
| 219 |
|
| 220 |
NS_IMETHODIMP |
| 221 |
nsNativeAppSupportBeOS::SetShouldShowUI(PRBool aShouldShowUI) { |
| 222 |
return NS_ERROR_NOT_IMPLEMENTED; |
| 223 |
} |
| 224 |
|
| 225 |
NS_IMETHODIMP |
| 226 |
nsNativeAppSupportBeOS::GetShouldShowUI(PRBool *aShouldShowUI) { |
| 227 |
*aShouldShowUI = PR_TRUE; |
| 228 |
return NS_OK; |
| 229 |
} |
| 230 |
|
| 231 |
NS_IMETHODIMP |
| 232 |
nsNativeAppSupportBeOS::ShowSplashScreen() { |
| 96 |
#ifdef DEBUG_SPLASH |
233 |
#ifdef DEBUG_SPLASH |
| 97 |
puts("nsSplashScreenBeOS::Show()"); |
234 |
puts("nsNativeAppSupportBeOS::ShowSplashScreen()"); |
| 98 |
#endif |
235 |
#endif |
| 99 |
if (NULL == bitmap && NS_OK != LoadBitmap()) |
236 |
if (NULL == bitmap && NS_OK != LoadBitmap()) |
| 100 |
return NS_ERROR_FAILURE; |
237 |
return NS_ERROR_FAILURE; |
|
|
| 129 |
} |
266 |
} |
| 130 |
|
267 |
|
| 131 |
NS_IMETHODIMP |
268 |
NS_IMETHODIMP |
| 132 |
nsSplashScreenBeOS::Hide() { |
269 |
nsNativeAppSupportBeOS::HideSplashScreen() { |
| 133 |
#ifdef DEBUG_SPLASH |
270 |
#ifdef DEBUG_SPLASH |
| 134 |
puts("nsSplashScreenBeOS::Hide()"); |
271 |
puts("nsNativeAppSupportBeOS::HideSplashScreen()"); |
| 135 |
#endif |
272 |
#endif |
| 136 |
if (NULL != window) { |
273 |
if (NULL != window) { |
| 137 |
if (window->Lock()) |
274 |
if (window->Lock()) |
|
|
| 146 |
} |
283 |
} |
| 147 |
|
284 |
|
| 148 |
NS_IMETHODIMP |
285 |
NS_IMETHODIMP |
| 149 |
nsSplashScreenBeOS::Observe(nsISupports *aSubject, |
286 |
nsNativeAppSupportBeOS::Observe(nsISupports *aSubject, |
| 150 |
const char *aTopic, |
287 |
const char *aTopic, |
| 151 |
const PRUnichar *someData) |
288 |
const PRUnichar *someData) |
| 152 |
{ |
289 |
{ |
| 153 |
if (!bitmap) return NS_OK; |
290 |
if (!bitmap) return NS_OK; |
| 154 |
nsCAutoString statusString; |
291 |
nsCAutoString statusString; |
| 155 |
statusString.AssignWithConversion(someData); |
292 |
statusString.AssignWithConversion(someData); |
| 156 |
if (textView == NULL) { |
293 |
if (textView != NULL) { |
| 157 |
BRect textRect = bitmap->Bounds(); |
|
|
| 158 |
textView = new BStringView(textRect, |
| 159 |
"splash text", |
| 160 |
statusString.get(), |
| 161 |
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); |
| 162 |
if (textView) { |
| 163 |
// Reduce the view size, and take into account the image frame |
| 164 |
textRect.bottom -= 10; |
| 165 |
textRect.left += 10; |
| 166 |
textRect.right -= 10; |
| 167 |
textRect.top = textRect.bottom - 20; |
| 168 |
|
| 169 |
textView->SetViewColor(B_TRANSPARENT_COLOR); |
| 170 |
textView->SetHighColor(255,255,255,0); |
| 171 |
textView->SetLowColor(0,0,0,0); |
| 172 |
window->AddChild(textView); |
| 173 |
} |
| 174 |
} else { |
| 175 |
if (textView->LockLooper()) { |
294 |
if (textView->LockLooper()) { |
| 176 |
textView->SetText(statusString.get()); |
295 |
textView->SetText(statusString.get()); |
| 177 |
textView->UnlockLooper(); |
296 |
textView->UnlockLooper(); |
| 178 |
} |
297 |
} |
|
|
298 |
return NS_OK; |
| 179 |
} |
299 |
} |
|
|
300 |
BRect textRect = bitmap->Bounds(); |
| 301 |
textView = new BStringView(textRect, |
| 302 |
"splash text", |
| 303 |
statusString.get(), |
| 304 |
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); |
| 305 |
|
| 306 |
if (!textView) return NS_OK; |
| 307 |
|
| 308 |
// Reduce the view size, and take into account the image frame |
| 309 |
textRect.bottom -= 10; |
| 310 |
textRect.left += 10; |
| 311 |
textRect.right -= 10; |
| 312 |
textRect.top = textRect.bottom - 20; |
| 313 |
textView->SetViewColor(B_TRANSPARENT_COLOR); |
| 314 |
textView->SetHighColor(255,255,255,0); |
| 315 |
textView->SetLowColor(0,0,0,0); |
| 316 |
window->AddChild(textView); |
| 180 |
return NS_OK; |
317 |
return NS_OK; |
| 181 |
} |
318 |
} |
| 182 |
|
319 |
|
| 183 |
nsresult |
320 |
nsresult |
| 184 |
nsSplashScreenBeOS::LoadBitmap() { |
321 |
nsNativeAppSupportBeOS::LoadBitmap() { |
| 185 |
BResources *rsrc = be_app->AppResources(); |
322 |
BResources *rsrc = be_app->AppResources(); |
| 186 |
if (NULL == rsrc) |
323 |
if (NULL == rsrc) |
| 187 |
return NS_ERROR_FAILURE; |
324 |
return NS_ERROR_FAILURE; |
|
|
| 203 |
return NS_OK; |
340 |
return NS_OK; |
| 204 |
} |
341 |
} |
| 205 |
|
342 |
|
| 206 |
|
|
|
| 207 |
// Create instance of BeOS splash screen object. |
| 208 |
nsresult |
| 209 |
NS_CreateSplashScreen( nsISplashScreen **aResult ) { |
| 210 |
if ( aResult ) { |
| 211 |
*aResult = new nsSplashScreenBeOS; |
| 212 |
if ( *aResult ) { |
| 213 |
NS_ADDREF( *aResult ); |
| 214 |
return NS_OK; |
| 215 |
} else { |
| 216 |
return NS_ERROR_OUT_OF_MEMORY; |
| 217 |
} |
| 218 |
} else { |
| 219 |
return NS_ERROR_NULL_POINTER; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
PRBool NS_CanRun() |
| 225 |
{ |
| 226 |
return PR_TRUE; |
| 227 |
} |
| 228 |
|