fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / desktop / win32 / source / guiloader / genericloader.cxx
blob4c3d94883e6d026defece87299a579bf7353c0c2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #define UNICODE
21 #define _UNICODE
23 #define WIN32_LEAN_AND_MEAN
24 #if defined _MSC_VER
25 #pragma warning(push, 1)
26 #endif
27 #include <windows.h>
28 #include <shellapi.h>
29 #if defined _MSC_VER
30 #pragma warning(pop)
31 #endif
33 #include <tchar.h>
35 #include <malloc.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <systools/win32/uwinapi.h>
40 #include <tools/pathutils.hxx>
41 #include "../loader.hxx"
45 static int GenericMain()
47 TCHAR szTargetFileName[MAX_PATH];
48 TCHAR szIniDirectory[MAX_PATH];
49 STARTUPINFO aStartupInfo;
51 desktop_win32::getPaths(szTargetFileName, szIniDirectory);
53 ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) );
54 aStartupInfo.cb = sizeof(aStartupInfo);
56 GetStartupInfo( &aStartupInfo );
58 DWORD dwExitCode = (DWORD)-1;
60 PROCESS_INFORMATION aProcessInfo;
62 size_t iniDirLen = wcslen(szIniDirectory);
63 WCHAR cwd[MAX_PATH];
64 DWORD cwdLen = GetCurrentDirectoryW(MAX_PATH, cwd);
65 if (cwdLen >= MAX_PATH) {
66 cwdLen = 0;
68 WCHAR redirect[MAX_PATH];
69 DWORD dummy;
70 bool hasRedirect =
71 tools::buildPath(
72 redirect, szIniDirectory, szIniDirectory + iniDirLen,
73 MY_STRING(L"redirect.ini")) != NULL &&
74 (GetBinaryType(redirect, &dummy) || // cheaper check for file existence?
75 GetLastError() != ERROR_FILE_NOT_FOUND);
76 LPTSTR cl1 = GetCommandLine();
77 WCHAR * cl2 = new WCHAR[
78 wcslen(cl1) +
79 (hasRedirect
80 ? (MY_LENGTH(L" \"-env:INIFILENAME=vnd.sun.star.pathname:") +
81 iniDirLen + MY_LENGTH(L"redirect.ini\""))
82 : 0) +
83 MY_LENGTH(L" \"-env:OOO_CWD=2") + 4 * cwdLen + MY_LENGTH(L"\"") + 1];
84 // 4 * cwdLen: each char preceded by backslash, each trailing backslash
85 // doubled
86 WCHAR * p = desktop_win32::commandLineAppend(cl2, cl1);
87 if (hasRedirect) {
88 p = desktop_win32::commandLineAppend(
89 p, MY_STRING(L" \"-env:INIFILENAME=vnd.sun.star.pathname:"));
90 p = desktop_win32::commandLineAppend(p, szIniDirectory);
91 p = desktop_win32::commandLineAppend(p, MY_STRING(L"redirect.ini\""));
93 p = desktop_win32::commandLineAppend(p, MY_STRING(L" \"-env:OOO_CWD="));
94 if (cwdLen == 0) {
95 p = desktop_win32::commandLineAppend(p, MY_STRING(L"0"));
96 } else {
97 p = desktop_win32::commandLineAppend(p, MY_STRING(L"2"));
98 p = desktop_win32::commandLineAppendEncoded(p, cwd);
100 desktop_win32::commandLineAppend(p, MY_STRING(L"\""));
102 BOOL fSuccess = CreateProcess(
103 szTargetFileName,
104 cl2,
105 NULL,
106 NULL,
107 TRUE,
109 NULL,
110 szIniDirectory,
111 &aStartupInfo,
112 &aProcessInfo );
114 delete[] cl2;
116 if ( fSuccess )
118 DWORD dwWaitResult;
122 // On Windows XP it seems as the desktop calls WaitForInputIdle after "OpenWidth" so we have to do so
123 // as if we where processing any messages
125 dwWaitResult = MsgWaitForMultipleObjects( 1, &aProcessInfo.hProcess, FALSE, INFINITE, QS_ALLEVENTS );
127 if ( WAIT_OBJECT_0 + 1 == dwWaitResult )
129 MSG msg;
131 PeekMessage( &msg, NULL, 0, 0, PM_REMOVE );
133 } while ( WAIT_OBJECT_0 + 1 == dwWaitResult );
135 dwExitCode = 0;
136 GetExitCodeProcess( aProcessInfo.hProcess, &dwExitCode );
138 CloseHandle( aProcessInfo.hProcess );
139 CloseHandle( aProcessInfo.hThread );
142 return dwExitCode;
147 #ifdef __MINGW32__
148 int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
149 #else
150 int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
151 #endif
153 return GenericMain();
158 #ifdef __MINGW32__
159 int __cdecl main()
160 #else
161 int __cdecl _tmain()
162 #endif
164 return GenericMain();
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */