1 /*
2 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "config.h"
26 #include "WebView.h"
27 #include <windows.h>
28 #include <wtf/PassOwnPtr.h>
29
30 static const LPCWSTR kMainWindowTitle = L"WebKit for WinCE";
31 static const LPCWSTR kMainWindowClassName = L"MainWindowClass";
32
33
WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)34 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
35 {
36 switch (message) {
37 case WM_DESTROY:
38 PostQuitMessage(0);
39 break;
40
41 default:
42 return DefWindowProc(hWnd, message, wParam, lParam);
43 }
44
45 return 0;
46 }
47
_tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)48 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
49 {
50 UNREFERENCED_PARAMETER(hPrevInstance);
51
52 CoInitializeEx(0, COINIT_MULTITHREADED);
53 WebView::initialize(hInstance);
54
55 LPCWSTR homeUrl = lpCmdLine;
56 bool enableDoubleBuffer = true;
57 bool fullscreen = false;
58
59 if (homeUrl[0] == '-') {
60 for (; *homeUrl && *homeUrl != ' '; ++homeUrl) {
61 switch (*homeUrl) {
62 case 'd':
63 enableDoubleBuffer = false;
64 break;
65 case 'f':
66 fullscreen = true;
67 break;
68 default:
69 break;
70 }
71 }
72 if (*homeUrl)
73 ++homeUrl;
74 }
75
76 DWORD styles = WS_VISIBLE;
77
78 if (!fullscreen) {
79 styles |= WS_CAPTION
80 | WS_MAXIMIZEBOX
81 | WS_MINIMIZEBOX
82 | WS_OVERLAPPED
83 | WS_SYSMENU
84 | WS_THICKFRAME;
85 }
86
87 WNDCLASSW wc;
88 wc.style = CS_HREDRAW | CS_VREDRAW;
89 wc.lpfnWndProc = WndProc;
90 wc.cbClsExtra = 0;
91 wc.cbWndExtra = 0;
92 wc.hInstance = hInstance;
93 wc.hIcon = 0;
94 wc.hCursor = 0;
95 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
96 wc.lpszMenuName = 0;
97 wc.lpszClassName = kMainWindowClassName;
98 RegisterClass(&wc);
99
100 HWND hMainWindow = CreateWindowW(kMainWindowClassName, kMainWindowTitle, styles,
101 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
102
103 if (fullscreen) {
104 SetWindowPos(hMainWindow, HWND_TOPMOST, 0, 0, GetSystemMetrics(SM_CXSCREEN),
105 GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
106 }
107
108 ShowWindow(hMainWindow, nCmdShow);
109 UpdateWindow(hMainWindow);
110
111 WTF::OwnPtr<WebView> webView = WTF::adoptPtr(new WebView(hMainWindow, enableDoubleBuffer ? WebView::EnableDoubleBuffering : WebView::NoFeature));
112 webView->load(homeUrl);
113
114 // Main message loop:
115 MSG msg;
116 BOOL bRet;
117 while (bRet = GetMessage(&msg, 0, 0, 0)) {
118 if (bRet == -1) {
119 // FIXME: Handle the error and possibly exit.
120 } else {
121 TranslateMessage(&msg);
122 DispatchMessage(&msg);
123 }
124 }
125
126 webView.clear();
127 DestroyWindow(hMainWindow);
128
129 WebView::cleanup();
130 CoUninitialize();
131
132 return msg.wParam;
133 }
134