2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "Spinneret.h"
30 #include "unicode/uclean.h"
34 #define MAX_LOADSTRING 100
35 #define URLBAR_HEIGHT 24
37 using namespace WebKit;
40 HINSTANCE hInst; // current instance
44 WebView* gWebView = 0;
45 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
46 TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
48 // Forward declarations of functions included in this code module:
49 ATOM MyRegisterClass(HINSTANCE hInstance);
50 BOOL InitInstance(HINSTANCE, int);
51 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
52 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
53 LRESULT CALLBACK MyEditProc(HWND, UINT, WPARAM, LPARAM);
55 void updateLocationBar(const char* URL)
57 SendMessageA(hURLBarWnd, (UINT)WM_SETTEXT, 0, (LPARAM)URL);
60 static void resizeSubViews()
63 GetClientRect(hMainWnd, &rcClient);
64 MoveWindow(hURLBarWnd, 0, 0, rcClient.right, URLBAR_HEIGHT, TRUE);
65 MoveWindow(gWebView->windowHandle(), 0, URLBAR_HEIGHT, rcClient.right, rcClient.bottom - URLBAR_HEIGHT, TRUE);
68 int APIENTRY _tWinMain(HINSTANCE hInstance,
69 HINSTANCE hPrevInstance,
73 #ifdef _CRTDBG_MAP_ALLOC
74 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
75 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
78 UNREFERENCED_PARAMETER(hPrevInstance);
79 UNREFERENCED_PARAMETER(lpCmdLine);
81 // TODO: Place code here.
85 INITCOMMONCONTROLSEX InitCtrlEx;
87 InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
88 InitCtrlEx.dwICC = ICC_STANDARD_CLASSES;
89 InitCommonControlsEx(&InitCtrlEx);
91 // Initialize global strings
92 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
93 LoadString(hInstance, IDC_SPINNERET, szWindowClass, MAX_LOADSTRING);
94 MyRegisterClass(hInstance);
96 // Perform application initialization:
97 if (!InitInstance (hInstance, nCmdShow))
100 hURLBarWnd = CreateWindow(L"EDIT", 0,
101 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL,
107 DefEditProc = GetWindowLong(hURLBarWnd, GWL_WNDPROC);
108 SetWindowLong(hURLBarWnd, GWL_WNDPROC,(long)MyEditProc);
109 SetFocus(hURLBarWnd);
111 gWebView = WebView::createWebView(hInstance, hMainWnd);
113 ShowWindow(gWebView->windowHandle(), nCmdShow);
114 UpdateWindow(gWebView->windowHandle());
116 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SPINNERET));
118 // Main message loop:
119 while (GetMessage(&msg, NULL, 0, 0))
121 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
123 TranslateMessage(&msg);
124 DispatchMessage(&msg);
129 #ifdef _CRTDBG_MAP_ALLOC
131 _CrtDumpMemoryLeaks();
134 return (int) msg.wParam;
137 ATOM MyRegisterClass(HINSTANCE hInstance)
141 wcex.cbSize = sizeof(WNDCLASSEX);
143 wcex.style = CS_HREDRAW | CS_VREDRAW;
144 wcex.lpfnWndProc = WndProc;
147 wcex.hInstance = hInstance;
148 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SPINNERET));
149 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
150 wcex.hbrBackground = 0;
151 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_SPINNERET);
152 wcex.lpszClassName = szWindowClass;
153 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
155 return RegisterClassEx(&wcex);
158 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
160 hInst = hInstance; // Store instance handle in our global variable
162 hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
163 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
168 ShowWindow(hMainWnd, nCmdShow);
169 UpdateWindow(hMainWnd);
174 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
183 wmId = LOWORD(wParam);
184 wmEvent = HIWORD(wParam);
185 // Parse the menu selections:
189 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
195 return DefWindowProc(hWnd, message, wParam, lParam);
207 return DefWindowProc(hWnd, message, wParam, lParam);
213 #define MAX_URL_LENGTH 1024
215 LRESULT CALLBACK MyEditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
219 if( wParam == 13 ) { // Enter Key
220 wchar_t strPtr[MAX_URL_LENGTH];
221 char cstrPtr[MAX_URL_LENGTH];
222 *((LPWORD)strPtr) = MAX_URL_LENGTH;
223 int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr);
226 for(x = 0; x < strLen; x++)
227 cstrPtr[x] = strPtr[x];
230 gWebView->mainFrame()->loadURL(cstrPtr);
231 SetFocus(gWebView->windowHandle());
235 return (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hDlg,message,wParam,lParam);
238 return (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hDlg,message,wParam,lParam);
245 // Message handler for about box.
246 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
248 UNREFERENCED_PARAMETER(lParam);
252 return (INT_PTR)TRUE;
255 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
257 EndDialog(hDlg, LOWORD(wParam));
258 return (INT_PTR)TRUE;
262 return (INT_PTR)FALSE;