From d959c37eaa66298579ca55440aff5fdb8b3126b2 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Fri, 13 Sep 2013 12:22:45 +0300 Subject: WinRT: Basic global support Various global changes, primarily preprocessor flow, to support the WinRT platform. Change-Id: I3fa9cf91d5fb24019362e88fcf205e31b4f810b5 Reviewed-by: Andrew Knight --- src/corelib/codecs/qwindowscodec.cpp | 2 +- src/corelib/global/qglobal.cpp | 21 ++++++++++++++++++++- src/corelib/global/qglobal.h | 2 +- src/corelib/global/qlogging.cpp | 12 ++++++------ src/corelib/global/qprocessordetection.h | 2 +- src/corelib/global/qsystemdetection.h | 14 ++++++++++++-- src/corelib/kernel/qcoreapplication.cpp | 4 ++-- src/corelib/kernel/qcoreapplication_win.cpp | 16 ++++++++++++++++ src/corelib/kernel/qcorecmdlineargs_p.h | 6 +++--- 9 files changed, 62 insertions(+), 17 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/codecs/qwindowscodec.cpp b/src/corelib/codecs/qwindowscodec.cpp index 54d20ec4f4..cd3f403475 100644 --- a/src/corelib/codecs/qwindowscodec.cpp +++ b/src/corelib/codecs/qwindowscodec.cpp @@ -159,7 +159,7 @@ QString QWindowsLocalCodec::convertToUnicodeCharByChar(const char *chars, int le state->remainingChars = 0; } const char *mb = mbcs; -#ifndef Q_OS_WINCE +#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) const char *next = 0; QString s; while ((next = CharNextExA(CP_ACP, mb, 0)) != mb) { diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 9ce820afff..ce87e4bfd9 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1132,6 +1132,21 @@ bool qSharedBuild() Q_DECL_NOTHROW Defined on Windows CE. */ +/*! + \macro Q_OS_WINRT + \relates + + Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT, + and Windows Phone 8. +*/ + +/*! + \macro Q_OS_WINPHONE + \relates + + Defined on Windows Phone 8. +*/ + /*! \macro Q_OS_CYGWIN \relates @@ -1715,7 +1730,7 @@ QSysInfo::MacVersion QSysInfo::macVersion() } const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion(); -#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE) +#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) QT_BEGIN_INCLUDE_NAMESPACE #include "qt_windows.h" @@ -1739,6 +1754,9 @@ QSysInfo::WinVersion QSysInfo::windowsVersion() static QSysInfo::WinVersion winver; if (winver) return winver; +#ifdef Q_OS_WINRT + winver = QSysInfo::WV_WINDOWS8; +#else winver = QSysInfo::WV_NT; OSVERSIONINFO osver; osver.dwOSVersionInfoSize = sizeof(osver); @@ -1823,6 +1841,7 @@ QSysInfo::WinVersion QSysInfo::windowsVersion() winver = QSysInfo::WV_WINDOWS8; } #endif +#endif // !Q_OS_WINRT return winver; } diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index d3db3b9dde..62ec25f003 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -194,7 +194,7 @@ typedef quint64 qulonglong; #ifndef QT_POINTER_SIZE # if defined(Q_OS_WIN64) # define QT_POINTER_SIZE 8 -# elif defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +# elif defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) # define QT_POINTER_SIZE 4 # elif defined(Q_OS_ANDROID) # define QT_POINTER_SIZE 4 // ### Add auto-detection to Windows configure diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 117ce240d8..5aaa0716f1 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -88,7 +88,7 @@ static bool isFatal(QtMsgType msgType) // Do we have stderr for QDebug? - Either there is a console or we are running // with redirected stderr. -# ifndef Q_OS_WINCE +# if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) static inline bool hasStdErr() { if (GetConsoleWindow()) @@ -98,11 +98,11 @@ static inline bool hasStdErr() return (info.dwFlags & STARTF_USESTDHANDLES) && info.hStdError && info.hStdError != INVALID_HANDLE_VALUE; } -# endif // !Q_OS_WINCE +# endif // !Q_OS_WINCE && !Q_OS_WINRT bool qWinLogToStderr() { -# ifndef Q_OS_WINCE +# if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) static const bool result = hasStdErr(); return result; # else @@ -168,7 +168,7 @@ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) Q_DECL { char emergency_buf[256] = { '\0' }; emergency_buf[sizeof emergency_buf - 1] = '\0'; -#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) && defined(Q_OS_WINCE) \ +#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) && (defined(Q_OS_WINCE) || defined(Q_OS_WINRT)) \ || defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) wchar_t emergency_bufL[sizeof emergency_buf]; #endif @@ -177,7 +177,7 @@ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) Q_DECL qvsnprintf(emergency_buf, sizeof emergency_buf - 1, msg, ap); #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) -# ifdef Q_OS_WINCE +# if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) convert_to_wchar_t_elided(emergency_bufL, sizeof emergency_buf, emergency_buf); OutputDebugStringW(emergency_bufL); # else @@ -701,7 +701,7 @@ void QMessagePattern::setPattern(const QString &pattern) else if (inIf) error += QStringLiteral("QT_MESSAGE_PATTERN: missing %{endif}\n"); if (!error.isEmpty()) { -#if defined(Q_OS_WINCE) +#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) OutputDebugString(reinterpret_cast(error.utf16())); if (0) #elif defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index fb664cbc82..623e30aa06 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -317,7 +317,7 @@ # elif defined(__BIG_ENDIAN__) || defined(_big_endian__) || defined(_BIG_ENDIAN) # define Q_BYTE_ORDER Q_BIG_ENDIAN # elif defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN) \ - || defined(_WIN32_WCE) // Windows CE is always little-endian according to MSDN. + || defined(_WIN32_WCE) || defined(WINAPI_FAMILY) // Windows CE is always little-endian according to MSDN. # define Q_BYTE_ORDER Q_LITTLE_ENDIAN # else # error "Unable to determine byte order!" diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h index dc9fa7383a..7b1c32663b 100644 --- a/src/corelib/global/qsystemdetection.h +++ b/src/corelib/global/qsystemdetection.h @@ -58,6 +58,7 @@ OS2EMX - XFree86 on OS/2 (not PM) WIN32 - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008) WINCE - WinCE (Windows CE 5.0) + WINRT - WinRT (Windows 8 Runtime) CYGWIN - Cygwin SOLARIS - Sun Solaris HPUX - HP-UX @@ -105,12 +106,21 @@ # define Q_OS_LINUX #elif defined(__CYGWIN__) # define Q_OS_CYGWIN -#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) +#elif !defined(SAG_COM) && (!defined(WINAPI_FAMILY) || WINAPI_FAMILY==WINAPI_FAMILY_DESKTOP_APP) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) # define Q_OS_WIN32 # define Q_OS_WIN64 #elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) # if defined(WINCE) || defined(_WIN32_WCE) # define Q_OS_WINCE +# elif defined(WINAPI_FAMILY) +# if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP +# define Q_OS_WINPHONE +# define Q_OS_WINRT +# elif WINAPI_FAMILY==WINAPI_FAMILY_APP +# define Q_OS_WINRT +# else +# define Q_OS_WIN32 +# endif # else # define Q_OS_WIN32 # endif @@ -172,7 +182,7 @@ # error "Qt has not been ported to this OS - see http://www.qt-project.org/" #endif -#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) || defined(Q_OS_WINCE) +#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) # define Q_OS_WIN #endif diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 290248aa6d..bdb7dc17f6 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2028,7 +2028,7 @@ QString QCoreApplication::applicationFilePath() */ qint64 QCoreApplication::applicationPid() { -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) return GetCurrentProcessId(); #elif defined(Q_OS_VXWORKS) return (pid_t) taskIdCurrent; @@ -2079,7 +2079,7 @@ QStringList QCoreApplication::arguments() char ** const av = self->d_func()->argv; list.reserve(ac); -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // On Windows, it is possible to pass Unicode arguments on // the command line. To restore those, we split the command line // and filter out arguments that were deleted by derived application diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 3e2fd6a689..dd1b84aa58 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -56,6 +56,20 @@ QT_BEGIN_NAMESPACE int appCmdShow = 0; +#if defined(Q_OS_WINRT) + +Q_CORE_EXPORT QString qAppFileName() +{ + return QFileInfo(QCoreApplication::arguments().first()).filePath(); +} + +QString QCoreApplicationPrivate::appName() const +{ + return QFileInfo(QCoreApplication::arguments().first()).baseName(); +} + +#else + Q_CORE_EXPORT HINSTANCE qWinAppInst() // get Windows app handle { return GetModuleHandle(0); @@ -1000,4 +1014,6 @@ QDebug operator<<(QDebug dbg, const MSG &msg) #endif // QT_NO_QOBJECT +#endif // !defined(Q_OS_WINRT) + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcorecmdlineargs_p.h b/src/corelib/kernel/qcorecmdlineargs_p.h index f2b109facd..d1cfa2dfa9 100644 --- a/src/corelib/kernel/qcorecmdlineargs_p.h +++ b/src/corelib/kernel/qcorecmdlineargs_p.h @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QT_BEGIN_INCLUDE_NAMESPACE # include "QtCore/qvector.h" @@ -149,7 +149,7 @@ static inline QStringList qCmdLineArgs(int argc, char *argv[]) return qWinCmdArgs(cmdLine); } -#else // !Q_OS_WIN +#else // Q_OS_WIN && !Q_OS_WINRT static inline QStringList qCmdLineArgs(int argc, char *argv[]) { @@ -159,7 +159,7 @@ static inline QStringList qCmdLineArgs(int argc, char *argv[]) return args; } -#endif // Q_OS_WIN +#endif // !Q_OS_WIN || Q_OS_WINRT QT_END_NAMESPACE -- cgit v1.2.3