1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/views/win/skia_win.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,207 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#include <windows.h> 1.12 +#include <tchar.h> 1.13 + 1.14 +#include "SkApplication.h" 1.15 + 1.16 +#define MAX_LOADSTRING 100 1.17 + 1.18 +// Global Variables: 1.19 +HINSTANCE hInst; // current instance 1.20 +TCHAR szTitle[] = _T("SampleApp"); // The title bar text 1.21 +TCHAR szWindowClass[] = _T("SAMPLEAPP"); // the main window class name 1.22 + 1.23 +// Forward declarations of functions included in this code module: 1.24 +ATOM MyRegisterClass(HINSTANCE hInstance); 1.25 +BOOL InitInstance(HINSTANCE, int, LPTSTR); 1.26 +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 1.27 +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 1.28 + 1.29 +int APIENTRY _tWinMain(HINSTANCE hInstance, 1.30 + HINSTANCE hPrevInstance, 1.31 + LPTSTR lpCmdLine, 1.32 + int nCmdShow) 1.33 +{ 1.34 + UNREFERENCED_PARAMETER(hPrevInstance); 1.35 + 1.36 + MSG msg; 1.37 + 1.38 + // Initialize global strings 1.39 + MyRegisterClass(hInstance); 1.40 + 1.41 + // Perform application initialization: 1.42 + if (!InitInstance (hInstance, nCmdShow, lpCmdLine)) 1.43 + { 1.44 + return FALSE; 1.45 + } 1.46 + 1.47 + // Main message loop: 1.48 + while (GetMessage(&msg, NULL, 0, 0)) 1.49 + { 1.50 + if (true) 1.51 + { 1.52 + TranslateMessage(&msg); 1.53 + DispatchMessage(&msg); 1.54 + } 1.55 + } 1.56 + 1.57 + application_term(); 1.58 + 1.59 + return (int) msg.wParam; 1.60 +} 1.61 + 1.62 + 1.63 + 1.64 +// 1.65 +// FUNCTION: MyRegisterClass() 1.66 +// 1.67 +// PURPOSE: Registers the window class. 1.68 +// 1.69 +// COMMENTS: 1.70 +// 1.71 +// This function and its usage are only necessary if you want this code 1.72 +// to be compatible with Win32 systems prior to the 'RegisterClassEx' 1.73 +// function that was added to Windows 95. It is important to call this function 1.74 +// so that the application will get 'well formed' small icons associated 1.75 +// with it. 1.76 +// 1.77 +ATOM MyRegisterClass(HINSTANCE hInstance) 1.78 +{ 1.79 + WNDCLASSEX wcex; 1.80 + 1.81 + wcex.cbSize = sizeof(WNDCLASSEX); 1.82 + 1.83 + wcex.style = CS_HREDRAW | CS_VREDRAW; 1.84 + wcex.lpfnWndProc = WndProc; 1.85 + wcex.cbClsExtra = 0; 1.86 + wcex.cbWndExtra = 0; 1.87 + wcex.hInstance = hInstance; 1.88 + wcex.hIcon = NULL; 1.89 + wcex.hCursor = NULL; 1.90 + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 1.91 + wcex.lpszMenuName = NULL; 1.92 + wcex.lpszClassName = szWindowClass; 1.93 + wcex.hIconSm = NULL; 1.94 + 1.95 + return RegisterClassEx(&wcex); 1.96 +} 1.97 + 1.98 +#include "SkOSWindow_Win.h" 1.99 +extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); 1.100 + 1.101 +static SkOSWindow* gSkWind; 1.102 + 1.103 +char* tchar_to_utf8(const TCHAR* str) { 1.104 +#ifdef _UNICODE 1.105 + int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL); 1.106 + char* str8 = (char*) malloc(size+1); 1.107 + WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); 1.108 + str8[size] = '\0'; 1.109 + return str8; 1.110 +#else 1.111 + return _strdup(str); 1.112 +#endif 1.113 +} 1.114 + 1.115 +// 1.116 +// FUNCTION: InitInstance(HINSTANCE, int, LPTSTR) 1.117 +// 1.118 +// PURPOSE: Saves instance handle and creates main window 1.119 +// 1.120 +// COMMENTS: 1.121 +// 1.122 +// In this function, we save the instance handle in a global variable and 1.123 +// create and display the main program window. 1.124 +// 1.125 + 1.126 + 1.127 +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPTSTR lpCmdLine) 1.128 +{ 1.129 + application_init(); 1.130 + 1.131 + hInst = hInstance; // Store instance handle in our global variable 1.132 + 1.133 + HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 1.134 + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 1.135 + 1.136 + if (!hWnd) 1.137 + { 1.138 + return FALSE; 1.139 + } 1.140 + 1.141 + char* argv[4096]; 1.142 + int argc = 0; 1.143 + TCHAR exename[1024], *next; 1.144 + int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename)); 1.145 + // we're ignoring the possibility that the exe name exceeds the exename buffer 1.146 + (void) exenameLen; 1.147 + argv[argc++] = tchar_to_utf8(exename); 1.148 + TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next); 1.149 + while (arg != NULL) { 1.150 + argv[argc++] = tchar_to_utf8(arg); 1.151 + arg = _tcstok_s(NULL, _T(" "), &next); 1.152 + } 1.153 + 1.154 + gSkWind = create_sk_window(hWnd, argc, argv); 1.155 + for (int i = 0; i < argc; ++i) { 1.156 + free(argv[i]); 1.157 + } 1.158 + ShowWindow(hWnd, nCmdShow); 1.159 + UpdateWindow(hWnd); 1.160 + 1.161 + return TRUE; 1.162 +} 1.163 + 1.164 +// 1.165 +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 1.166 +// 1.167 +// PURPOSE: Processes messages for the main window. 1.168 +// 1.169 +// WM_COMMAND - process the application menu 1.170 +// WM_PAINT - Paint the main window 1.171 +// WM_DESTROY - post a quit message and return 1.172 +// 1.173 +// 1.174 +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 1.175 +{ 1.176 + switch (message) { 1.177 + case WM_COMMAND: 1.178 + return DefWindowProc(hWnd, message, wParam, lParam); 1.179 + case WM_DESTROY: 1.180 + PostQuitMessage(0); 1.181 + break; 1.182 + default: 1.183 + if (gSkWind->wndProc(hWnd, message, wParam, lParam)) { 1.184 + return 0; 1.185 + } else { 1.186 + return DefWindowProc(hWnd, message, wParam, lParam); 1.187 + } 1.188 + } 1.189 + return 0; 1.190 +} 1.191 + 1.192 +// Message handler for about box. 1.193 +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 1.194 +{ 1.195 + UNREFERENCED_PARAMETER(lParam); 1.196 + switch (message) 1.197 + { 1.198 + case WM_INITDIALOG: 1.199 + return (INT_PTR)TRUE; 1.200 + 1.201 + case WM_COMMAND: 1.202 + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 1.203 + { 1.204 + EndDialog(hDlg, LOWORD(wParam)); 1.205 + return (INT_PTR)TRUE; 1.206 + } 1.207 + break; 1.208 + } 1.209 + return (INT_PTR)FALSE; 1.210 +}