[18859] | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
---|
| 2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
| 3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
| 4 | * |
---|
| 5 | * The contents of this file are subject to the Netscape Public License |
---|
| 6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
| 7 | * compliance with the License. You may obtain a copy of the License at |
---|
| 8 | * http://www.mozilla.org/NPL/ |
---|
| 9 | * |
---|
| 10 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
| 11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
| 12 | * for the specific language governing rights and limitations under the |
---|
| 13 | * License. |
---|
| 14 | * |
---|
| 15 | * The Original Code is Mozilla Communicator client code. |
---|
| 16 | * |
---|
| 17 | * The Initial Developer of the Original Code is |
---|
| 18 | * Netscape Communications Corporation. |
---|
| 19 | * Portions created by the Initial Developer are Copyright (C) 1998 |
---|
| 20 | * the Initial Developer. All Rights Reserved. |
---|
| 21 | * |
---|
| 22 | * Contributor(s): |
---|
| 23 | * Takashi Toyoshima <toyoshim@be-in.org> |
---|
| 24 | * |
---|
| 25 | * Alternatively, the contents of this file may be used under the terms of |
---|
| 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
| 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
| 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
---|
| 29 | * of those above. If you wish to allow use of your version of this file only |
---|
| 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
---|
| 31 | * use your version of this file under the terms of the NPL, indicate your |
---|
| 32 | * decision by deleting the provisions above and replace them with the notice |
---|
| 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
---|
| 34 | * the provisions above, a recipient may use your version of this file under |
---|
| 35 | * the terms of any one of the NPL, the GPL or the LGPL. |
---|
| 36 | * |
---|
| 37 | * ***** END LICENSE BLOCK ***** */ |
---|
| 38 | #include "nsNativeAppSupportBase.h" |
---|
| 39 | #include "nsString.h" |
---|
| 40 | #include "nsIObserver.h" |
---|
| 41 | |
---|
| 42 | #include <Application.h> |
---|
| 43 | #include <Window.h> |
---|
| 44 | #include <View.h> |
---|
| 45 | #include <StringView.h> |
---|
| 46 | #include <Bitmap.h> |
---|
| 47 | #include <Screen.h> |
---|
| 48 | #include <Font.h> |
---|
| 49 | #include <Resources.h> |
---|
| 50 | |
---|
| 51 | #ifdef DEBUG |
---|
| 52 | #define DEBUG_SPLASH 1 |
---|
| 53 | #endif |
---|
| 54 | |
---|
| 55 | class nsSplashScreenBeOS : public nsISplashScreen, |
---|
| 56 | public nsIObserver { |
---|
| 57 | public: |
---|
| 58 | nsSplashScreenBeOS(); |
---|
| 59 | virtual ~nsSplashScreenBeOS(); |
---|
| 60 | |
---|
| 61 | NS_DECL_ISUPPORTS |
---|
| 62 | |
---|
| 63 | NS_IMETHOD Show(); |
---|
| 64 | NS_IMETHOD Hide(); |
---|
| 65 | |
---|
| 66 | NS_DECL_NSIOBSERVER |
---|
| 67 | |
---|
| 68 | private: |
---|
| 69 | nsresult LoadBitmap(); |
---|
| 70 | |
---|
| 71 | BWindow *window; |
---|
| 72 | BBitmap *bitmap; |
---|
| 73 | BStringView *textView; |
---|
| 74 | }; // class nsSplashScreenBeOS |
---|
| 75 | |
---|
| 76 | nsSplashScreenBeOS::nsSplashScreenBeOS() |
---|
| 77 | : window( NULL ) , bitmap( NULL ), textView(NULL) { |
---|
| 78 | #ifdef DEBUG_SPLASH |
---|
| 79 | puts("nsSplashScreenBeOS::nsSlpashScreenBeOS()"); |
---|
| 80 | #endif |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | nsSplashScreenBeOS::~nsSplashScreenBeOS() { |
---|
| 84 | #ifdef DEBUG_SPLASH |
---|
| 85 | puts("nsSplashScreenBeOS::~nsSlpashScreenBeOS()"); |
---|
| 86 | #endif |
---|
| 87 | Hide(); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | NS_IMPL_ISUPPORTS2(nsSplashScreenBeOS, nsISplashScreen, nsIObserver); |
---|
| 91 | |
---|
| 92 | NS_IMETHODIMP |
---|
| 93 | nsSplashScreenBeOS::Show() { |
---|
| 94 | #ifdef DEBUG_SPLASH |
---|
| 95 | puts("nsSplashScreenBeOS::Show()"); |
---|
| 96 | #endif |
---|
| 97 | if (NULL == bitmap && NS_OK != LoadBitmap()) |
---|
| 98 | return NS_ERROR_FAILURE; |
---|
| 99 | |
---|
| 100 | // Get the center position. |
---|
| 101 | BScreen scr; |
---|
| 102 | BRect scrRect = scr.Frame(); |
---|
| 103 | BRect bmpRect = bitmap->Bounds(); |
---|
| 104 | float winX = (scrRect.right - bmpRect.right) / 2; |
---|
| 105 | float winY = (scrRect.bottom - bmpRect.bottom) / 2; |
---|
| 106 | BRect winRect(winX, winY, winX + bmpRect.right, winY + bmpRect.bottom); |
---|
| 107 | #ifdef DEBUG_SPLASH |
---|
| 108 | printf("SplashRect (%f, %f) - (%f, %f)\n", winRect.left, winRect.top, |
---|
| 109 | winRect.right, winRect.bottom); |
---|
| 110 | #endif |
---|
| 111 | if (NULL == window) { |
---|
| 112 | window = new BWindow(winRect, |
---|
| 113 | "mozilla splash", |
---|
| 114 | B_NO_BORDER_WINDOW_LOOK, |
---|
| 115 | B_MODAL_APP_WINDOW_FEEL, |
---|
| 116 | 0); |
---|
| 117 | if (NULL == window) |
---|
| 118 | return NS_ERROR_FAILURE; |
---|
| 119 | BView *view = new BView(bmpRect, "splash view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW); |
---|
| 120 | if (NULL != view) { |
---|
| 121 | window->AddChild(view); |
---|
| 122 | view->SetViewBitmap(bitmap); |
---|
| 123 | } |
---|
| 124 | window->Show(); |
---|
| 125 | } |
---|
| 126 | return NS_OK; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | NS_IMETHODIMP |
---|
| 130 | nsSplashScreenBeOS::Hide() { |
---|
| 131 | #ifdef DEBUG_SPLASH |
---|
| 132 | puts("nsSplashScreenBeOS::Hide()"); |
---|
| 133 | #endif |
---|
| 134 | if (NULL != window) { |
---|
| 135 | if (window->Lock()) |
---|
| 136 | window->Quit(); |
---|
| 137 | window = NULL; |
---|
| 138 | } |
---|
| 139 | if (NULL != bitmap) { |
---|
| 140 | delete bitmap; |
---|
| 141 | bitmap = NULL; |
---|
| 142 | } |
---|
| 143 | return NS_OK; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | NS_IMETHODIMP |
---|
| 147 | nsSplashScreenBeOS::Observe(nsISupports *aSubject, |
---|
| 148 | const char *aTopic, |
---|
| 149 | const PRUnichar *someData) |
---|
| 150 | { |
---|
[19517] | 151 | if (!bitmap) return NS_OK; |
---|
[18859] | 152 | nsCAutoString statusString; |
---|
| 153 | statusString.AssignWithConversion(someData); |
---|
| 154 | if (textView == NULL) { |
---|
| 155 | BRect textRect = bitmap->Bounds(); |
---|
| 156 | // Reduce the view size, and take into account the image frame |
---|
| 157 | textRect.bottom -= 10; |
---|
| 158 | textRect.left += 10; |
---|
| 159 | textRect.right -= 10; |
---|
| 160 | textRect.top = textRect.bottom - 20; |
---|
| 161 | textView = new BStringView(textRect, |
---|
| 162 | "splash text", |
---|
| 163 | statusString.get(), |
---|
| 164 | B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); |
---|
| 165 | textView->SetViewColor(B_TRANSPARENT_COLOR); |
---|
| 166 | textView->SetHighColor(255,255,255,0); |
---|
| 167 | textView->SetLowColor(0,0,0,0); |
---|
| 168 | if (textView != NULL) { |
---|
| 169 | window->AddChild(textView); |
---|
| 170 | } |
---|
| 171 | } else { |
---|
| 172 | if (textView->LockLooper()) { |
---|
| 173 | textView->SetText(statusString.get()); |
---|
| 174 | textView->UnlockLooper(); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | return NS_OK; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | nsresult |
---|
| 181 | nsSplashScreenBeOS::LoadBitmap() { |
---|
| 182 | BResources *rsrc = be_app->AppResources(); |
---|
| 183 | if (NULL == rsrc) |
---|
| 184 | return NS_ERROR_FAILURE; |
---|
| 185 | size_t length; |
---|
| 186 | const void *data = rsrc->LoadResource('BBMP', "MOZILLA:SPLASH", &length); |
---|
| 187 | if (NULL == data) |
---|
| 188 | return NS_ERROR_FAILURE; |
---|
| 189 | BMessage msg; |
---|
| 190 | if (B_OK != msg.Unflatten((const char *)data)) |
---|
| 191 | return NS_ERROR_FAILURE; |
---|
| 192 | BBitmap *bmp = new BBitmap(&msg); |
---|
| 193 | if (NULL == bmp) |
---|
| 194 | return NS_ERROR_FAILURE; |
---|
| 195 | bitmap = new BBitmap(bmp, true); |
---|
| 196 | if (NULL == bitmap) { |
---|
| 197 | delete bmp; |
---|
| 198 | return NS_ERROR_FAILURE; |
---|
| 199 | } |
---|
| 200 | return NS_OK; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | // Create instance of BeOS splash screen object. |
---|
| 205 | nsresult |
---|
| 206 | NS_CreateSplashScreen( nsISplashScreen **aResult ) { |
---|
| 207 | if ( aResult ) { |
---|
| 208 | *aResult = new nsSplashScreenBeOS; |
---|
| 209 | if ( *aResult ) { |
---|
| 210 | NS_ADDREF( *aResult ); |
---|
| 211 | return NS_OK; |
---|
| 212 | } else { |
---|
| 213 | return NS_ERROR_OUT_OF_MEMORY; |
---|
| 214 | } |
---|
| 215 | } else { |
---|
| 216 | return NS_ERROR_NULL_POINTER; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | PRBool NS_CanRun() |
---|
| 222 | { |
---|
| 223 | return PR_TRUE; |
---|
| 224 | } |
---|
| 225 | |
---|