Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include <windows.h> |
michael@0 | 9 | #include <tchar.h> |
michael@0 | 10 | |
michael@0 | 11 | #include "SkApplication.h" |
michael@0 | 12 | |
michael@0 | 13 | #define MAX_LOADSTRING 100 |
michael@0 | 14 | |
michael@0 | 15 | // Global Variables: |
michael@0 | 16 | HINSTANCE hInst; // current instance |
michael@0 | 17 | TCHAR szTitle[] = _T("SampleApp"); // The title bar text |
michael@0 | 18 | TCHAR szWindowClass[] = _T("SAMPLEAPP"); // the main window class name |
michael@0 | 19 | |
michael@0 | 20 | // Forward declarations of functions included in this code module: |
michael@0 | 21 | ATOM MyRegisterClass(HINSTANCE hInstance); |
michael@0 | 22 | BOOL InitInstance(HINSTANCE, int, LPTSTR); |
michael@0 | 23 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); |
michael@0 | 24 | INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); |
michael@0 | 25 | |
michael@0 | 26 | int APIENTRY _tWinMain(HINSTANCE hInstance, |
michael@0 | 27 | HINSTANCE hPrevInstance, |
michael@0 | 28 | LPTSTR lpCmdLine, |
michael@0 | 29 | int nCmdShow) |
michael@0 | 30 | { |
michael@0 | 31 | UNREFERENCED_PARAMETER(hPrevInstance); |
michael@0 | 32 | |
michael@0 | 33 | MSG msg; |
michael@0 | 34 | |
michael@0 | 35 | // Initialize global strings |
michael@0 | 36 | MyRegisterClass(hInstance); |
michael@0 | 37 | |
michael@0 | 38 | // Perform application initialization: |
michael@0 | 39 | if (!InitInstance (hInstance, nCmdShow, lpCmdLine)) |
michael@0 | 40 | { |
michael@0 | 41 | return FALSE; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | // Main message loop: |
michael@0 | 45 | while (GetMessage(&msg, NULL, 0, 0)) |
michael@0 | 46 | { |
michael@0 | 47 | if (true) |
michael@0 | 48 | { |
michael@0 | 49 | TranslateMessage(&msg); |
michael@0 | 50 | DispatchMessage(&msg); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | application_term(); |
michael@0 | 55 | |
michael@0 | 56 | return (int) msg.wParam; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | |
michael@0 | 60 | |
michael@0 | 61 | // |
michael@0 | 62 | // FUNCTION: MyRegisterClass() |
michael@0 | 63 | // |
michael@0 | 64 | // PURPOSE: Registers the window class. |
michael@0 | 65 | // |
michael@0 | 66 | // COMMENTS: |
michael@0 | 67 | // |
michael@0 | 68 | // This function and its usage are only necessary if you want this code |
michael@0 | 69 | // to be compatible with Win32 systems prior to the 'RegisterClassEx' |
michael@0 | 70 | // function that was added to Windows 95. It is important to call this function |
michael@0 | 71 | // so that the application will get 'well formed' small icons associated |
michael@0 | 72 | // with it. |
michael@0 | 73 | // |
michael@0 | 74 | ATOM MyRegisterClass(HINSTANCE hInstance) |
michael@0 | 75 | { |
michael@0 | 76 | WNDCLASSEX wcex; |
michael@0 | 77 | |
michael@0 | 78 | wcex.cbSize = sizeof(WNDCLASSEX); |
michael@0 | 79 | |
michael@0 | 80 | wcex.style = CS_HREDRAW | CS_VREDRAW; |
michael@0 | 81 | wcex.lpfnWndProc = WndProc; |
michael@0 | 82 | wcex.cbClsExtra = 0; |
michael@0 | 83 | wcex.cbWndExtra = 0; |
michael@0 | 84 | wcex.hInstance = hInstance; |
michael@0 | 85 | wcex.hIcon = NULL; |
michael@0 | 86 | wcex.hCursor = NULL; |
michael@0 | 87 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
michael@0 | 88 | wcex.lpszMenuName = NULL; |
michael@0 | 89 | wcex.lpszClassName = szWindowClass; |
michael@0 | 90 | wcex.hIconSm = NULL; |
michael@0 | 91 | |
michael@0 | 92 | return RegisterClassEx(&wcex); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | #include "SkOSWindow_Win.h" |
michael@0 | 96 | extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); |
michael@0 | 97 | |
michael@0 | 98 | static SkOSWindow* gSkWind; |
michael@0 | 99 | |
michael@0 | 100 | char* tchar_to_utf8(const TCHAR* str) { |
michael@0 | 101 | #ifdef _UNICODE |
michael@0 | 102 | int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL); |
michael@0 | 103 | char* str8 = (char*) malloc(size+1); |
michael@0 | 104 | WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); |
michael@0 | 105 | str8[size] = '\0'; |
michael@0 | 106 | return str8; |
michael@0 | 107 | #else |
michael@0 | 108 | return _strdup(str); |
michael@0 | 109 | #endif |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | // |
michael@0 | 113 | // FUNCTION: InitInstance(HINSTANCE, int, LPTSTR) |
michael@0 | 114 | // |
michael@0 | 115 | // PURPOSE: Saves instance handle and creates main window |
michael@0 | 116 | // |
michael@0 | 117 | // COMMENTS: |
michael@0 | 118 | // |
michael@0 | 119 | // In this function, we save the instance handle in a global variable and |
michael@0 | 120 | // create and display the main program window. |
michael@0 | 121 | // |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPTSTR lpCmdLine) |
michael@0 | 125 | { |
michael@0 | 126 | application_init(); |
michael@0 | 127 | |
michael@0 | 128 | hInst = hInstance; // Store instance handle in our global variable |
michael@0 | 129 | |
michael@0 | 130 | HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, |
michael@0 | 131 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); |
michael@0 | 132 | |
michael@0 | 133 | if (!hWnd) |
michael@0 | 134 | { |
michael@0 | 135 | return FALSE; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | char* argv[4096]; |
michael@0 | 139 | int argc = 0; |
michael@0 | 140 | TCHAR exename[1024], *next; |
michael@0 | 141 | int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename)); |
michael@0 | 142 | // we're ignoring the possibility that the exe name exceeds the exename buffer |
michael@0 | 143 | (void) exenameLen; |
michael@0 | 144 | argv[argc++] = tchar_to_utf8(exename); |
michael@0 | 145 | TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next); |
michael@0 | 146 | while (arg != NULL) { |
michael@0 | 147 | argv[argc++] = tchar_to_utf8(arg); |
michael@0 | 148 | arg = _tcstok_s(NULL, _T(" "), &next); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | gSkWind = create_sk_window(hWnd, argc, argv); |
michael@0 | 152 | for (int i = 0; i < argc; ++i) { |
michael@0 | 153 | free(argv[i]); |
michael@0 | 154 | } |
michael@0 | 155 | ShowWindow(hWnd, nCmdShow); |
michael@0 | 156 | UpdateWindow(hWnd); |
michael@0 | 157 | |
michael@0 | 158 | return TRUE; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | // |
michael@0 | 162 | // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) |
michael@0 | 163 | // |
michael@0 | 164 | // PURPOSE: Processes messages for the main window. |
michael@0 | 165 | // |
michael@0 | 166 | // WM_COMMAND - process the application menu |
michael@0 | 167 | // WM_PAINT - Paint the main window |
michael@0 | 168 | // WM_DESTROY - post a quit message and return |
michael@0 | 169 | // |
michael@0 | 170 | // |
michael@0 | 171 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
michael@0 | 172 | { |
michael@0 | 173 | switch (message) { |
michael@0 | 174 | case WM_COMMAND: |
michael@0 | 175 | return DefWindowProc(hWnd, message, wParam, lParam); |
michael@0 | 176 | case WM_DESTROY: |
michael@0 | 177 | PostQuitMessage(0); |
michael@0 | 178 | break; |
michael@0 | 179 | default: |
michael@0 | 180 | if (gSkWind->wndProc(hWnd, message, wParam, lParam)) { |
michael@0 | 181 | return 0; |
michael@0 | 182 | } else { |
michael@0 | 183 | return DefWindowProc(hWnd, message, wParam, lParam); |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | return 0; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | // Message handler for about box. |
michael@0 | 190 | INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) |
michael@0 | 191 | { |
michael@0 | 192 | UNREFERENCED_PARAMETER(lParam); |
michael@0 | 193 | switch (message) |
michael@0 | 194 | { |
michael@0 | 195 | case WM_INITDIALOG: |
michael@0 | 196 | return (INT_PTR)TRUE; |
michael@0 | 197 | |
michael@0 | 198 | case WM_COMMAND: |
michael@0 | 199 | if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) |
michael@0 | 200 | { |
michael@0 | 201 | EndDialog(hDlg, LOWORD(wParam)); |
michael@0 | 202 | return (INT_PTR)TRUE; |
michael@0 | 203 | } |
michael@0 | 204 | break; |
michael@0 | 205 | } |
michael@0 | 206 | return (INT_PTR)FALSE; |
michael@0 | 207 | } |