1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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
15 * The Original Code is Mozilla code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2009
20 * the Initial Developer. All Rights Reserved.
23 * Vladimir Vukicevic <vladimir@pobox.com>
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 MPL, 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 MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSplashScreen.h"
43 static ATOM gSplashScreenClass
= 0;
45 class nsSplashScreenWin
;
47 static nsSplashScreenWin
*gSplashScreen
= NULL
;
49 class nsSplashScreenWin
:
57 virtual void Update(PRInt32 progress
);
61 HBITMAP mSplashBitmap
, mOldBitmap
;
65 static DWORD WINAPI
ThreadProc(LPVOID splashScreen
);
67 static LRESULT CALLBACK
DialogProc (HWND hWnd
,
72 void OnPaint(HDC dc
, const PAINTSTRUCT
*ps
);
78 nsSplashScreen::GetOrCreate()
81 gSplashScreen
= new nsSplashScreenWin();
92 nsSplashScreenWin::nsSplashScreenWin()
93 : mDialog(NULL
), mSplashBitmap(NULL
), mOldBitmap(NULL
),
94 mSplashBitmapDC(NULL
),
95 mWidth(200), mHeight(100),
101 nsSplashScreenWin::Open()
103 if (mIsOpen
|| mDialog
)
108 if (gSplashScreenClass
== 0) {
110 memset(&wc
, 0, sizeof(WNDCLASS
));
112 wc
.style
= CS_NOCLOSE
;
113 wc
.lpfnWndProc
= (WNDPROC
) DialogProc
;
114 wc
.hInstance
= GetModuleHandle(0);
117 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
118 wc
.lpszMenuName
= NULL
;
119 wc
.lpszClassName
= TEXT("MozillaSplashScreen");
121 gSplashScreenClass
= RegisterClass(&wc
);
124 if (mSplashBitmap
== NULL
) {
125 wchar_t path
[_MAX_PATH
];
126 if (::GetModuleFileNameW(0, path
, _MAX_PATH
)) {
127 wchar_t *slash
= wcsrchr(path
, '\\');
131 wcscat(path
, L
"splash.bmp");
134 mSplashBitmap
= ::SHLoadDIBitmap(path
);
136 #warning splashscreen needs some code to load bitmaps on non-WinCE
137 mSplashBitmap
= nsnull
;
142 if (GetObject(mSplashBitmap
, sizeof(BITMAP
), &bmo
) > 0) {
143 mWidth
= bmo
.bmWidth
;
144 mHeight
= bmo
.bmHeight
;
146 mSplashBitmapDC
= CreateCompatibleDC(NULL
);
147 mOldBitmap
= (HBITMAP
) SelectObject(mSplashBitmapDC
, mSplashBitmap
);
149 DeleteObject(mSplashBitmap
);
150 mSplashBitmap
= NULL
;
157 CreateThread(0, 0, (LPTHREAD_START_ROUTINE
)ThreadProc
, this, 0, &threadID
);
161 nsSplashScreenWin::ThreadProc(LPVOID splashScreen
)
163 nsSplashScreenWin
*sp
= (nsSplashScreenWin
*) splashScreen
;
165 int screenWidth
= GetSystemMetrics(SM_CXSCREEN
);
166 int screenHeight
= GetSystemMetrics(SM_CYSCREEN
);
168 LONG horizPad
= (screenWidth
- sp
->mWidth
) / 2;
169 LONG vertPad
= (screenHeight
- sp
->mHeight
) / 2;
172 horizPad
+ sp
->mWidth
,
173 vertPad
+ sp
->mHeight
};
175 DWORD winStyle
= (WS_POPUP
| WS_BORDER
);
176 DWORD winStyleEx
= WS_EX_NOACTIVATE
;
178 if(!::AdjustWindowRectEx(&r
, winStyle
, FALSE
, winStyleEx
))
181 HWND dlg
= CreateWindowEx(
183 TEXT("MozillaSplashScreen"),
184 TEXT("Starting up..."),
187 (r
.right
- r
.left
), (r
.bottom
- r
.top
),
195 ShowWindow(dlg
, SW_SHOW
);
196 SetForegroundWindow(dlg
);
199 while (::GetMessage(&msg
, NULL
, 0, 0)) {
200 DispatchMessage(&msg
);
203 // window was destroyed, nothing to do
208 nsSplashScreenWin::Close()
211 ShowWindow(mDialog
, SW_HIDE
);
212 PostMessage(mDialog
, WM_QUIT
, 0, 0);
217 SelectObject(mSplashBitmapDC
, mOldBitmap
);
218 DeleteObject(mSplashBitmapDC
);
219 DeleteObject(mSplashBitmap
);
221 mSplashBitmapDC
= NULL
;
222 mSplashBitmap
= NULL
;
229 nsSplashScreenWin::Update(PRInt32 progress
)
232 mProgress
= progress
> 100 ? 100 : progress
;
234 InvalidateRect(mDialog
, NULL
, FALSE
);
238 nsSplashScreenWin::OnPaint(HDC dc
, const PAINTSTRUCT
*ps
)
242 // Paint the splash screen
243 if (mSplashBitmapDC
) {
245 0, 0, gSplashScreen
->mWidth
, gSplashScreen
->mHeight
,
246 gSplashScreen
->mSplashBitmapDC
,
250 HBRUSH bkgr
= CreateSolidBrush(RGB(200,200,200));
251 RECT r
= { 0, 0, mWidth
, mHeight
};
252 FillRect(dc
, &r
, bkgr
);
256 // Size of progress bar area
257 if (mSplashBitmapDC
&&
258 gSplashScreen
->mWidth
== 440 &&
259 gSplashScreen
->mHeight
== 180) {
260 // For now we're tightly tied to a specific splash.bmp design,
261 // ideally we would determine the region automagically.
262 progressBar
.left
= 183;
263 progressBar
.right
= 410;
264 progressBar
.top
= 148;
265 progressBar
.bottom
= 153;
267 // The default progress bar will be 2/3 the width of the splash box,
268 // 9 pixels tall, 10 pixels from the bottom.
269 progressBar
.left
= (mWidth
/ 6);
270 progressBar
.right
= mWidth
- (mWidth
/ 6);
271 progressBar
.top
= mHeight
- 19;
272 progressBar
.bottom
= mHeight
- 10;
275 if (mProgress
!= -1) {
276 HBRUSH fill
= CreateSolidBrush(RGB(0x77,0xC7,0x1C));
278 int maxWidth
= progressBar
.right
- progressBar
.left
;
279 progressBar
.right
= progressBar
.left
+ maxWidth
* mProgress
/ 100;
280 FillRect(dc
, &progressBar
, fill
);
287 nsSplashScreenWin::DialogProc (HWND hWnd
,
295 HDC dc
= BeginPaint(hWnd
, &ps
);
298 gSplashScreen
->OnPaint(dc
, &ps
);
313 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);