Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / toolkit / xre / nsNativeAppSupportWin.cpp
blob8c4b43b3f61f1c4189b090b209a50556b2bba7fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsNativeAppSupportBase.h"
7 #include "nsNativeAppSupportWin.h"
9 #include "mozilla/CmdLineAndEnvUtils.h"
10 #include "mozilla/WindowsConsole.h"
12 using namespace mozilla;
15 * This code attaches the process to the appropriate console.
18 class nsNativeAppSupportWin : public nsNativeAppSupportBase {
19 public:
20 // Utility function to handle a Win32-specific command line
21 // option: "--console", which dynamically creates a Windows
22 // console.
23 void CheckConsole();
25 private:
26 ~nsNativeAppSupportWin() {}
27 }; // nsNativeAppSupportWin
29 void nsNativeAppSupportWin::CheckConsole() {
30 if (CheckArg(gArgc, gArgv, "attach-console") == ARG_FOUND) {
31 UseParentConsole();
34 if (CheckArg(gArgc, gArgv, "console") == ARG_FOUND) {
35 if (AllocConsole()) {
36 // Redirect the standard streams to the new console, but
37 // only if they haven't been redirected to a valid file.
38 // Visual Studio's _fileno() returns -2 for the standard
39 // streams if they aren't associated with an output stream.
40 if (_fileno(stdout) == -2) {
41 freopen("CONOUT$", "w", stdout);
43 // There is no CONERR$, so use CONOUT$ for stderr as well.
44 if (_fileno(stderr) == -2) {
45 freopen("CONOUT$", "w", stderr);
47 if (_fileno(stdin) == -2) {
48 freopen("CONIN$", "r", stdin);
54 // Create and return an instance of class nsNativeAppSupportWin.
55 nsresult NS_CreateNativeAppSupport(nsINativeAppSupport** aResult) {
56 nsNativeAppSupportWin* pNative = new nsNativeAppSupportWin;
57 if (!pNative) return NS_ERROR_OUT_OF_MEMORY;
59 // Check for dynamic console creation request.
60 pNative->CheckConsole();
62 *aResult = pNative;
63 NS_ADDREF(*aResult);
65 return NS_OK;