From 59f428d25efb118003f83ef239846e5de49ab78e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 21 Nov 2017 16:06:29 +0100 Subject: [PATCH] Slightly simplify GestureFuncs code Document that the users of this class always must call IsOk() first, as they already do, and remove the checks for ms_gestureSymbolsLoaded and calls to LoadGestureSymbols() from all the other methods, which are unnecessary in this case. --- src/msw/window.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index a2bb278d59..7d86f026e7 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -205,29 +205,34 @@ bool gs_insideCaptureChanged = false; } // anonymous namespace +#ifdef WM_GESTURE + namespace { // Class used to dynamically load gestures related API functions. -#ifdef WM_GESTURE class GestureFuncs { public: + // Must be called before using any other methods of this class (and they + // can't be used if this one returns false). static bool IsOk() { if ( !ms_gestureSymbolsLoaded ) + { + ms_gestureSymbolsLoaded = true; LoadGestureSymbols(); + } - return ms_pfnGetGestureInfo && ms_pfnCloseGestureInfoHandle && ms_pfnSetGestureConfig; + return ms_pfnGetGestureInfo && + ms_pfnCloseGestureInfoHandle && + ms_pfnSetGestureConfig; } typedef BOOL (WINAPI *GetGestureInfo_t)(HGESTUREINFO, PGESTUREINFO); static GetGestureInfo_t GetGestureInfo() { - if ( !ms_gestureSymbolsLoaded ) - LoadGestureSymbols(); - return ms_pfnGetGestureInfo; } @@ -235,19 +240,14 @@ public: static CloseGestureInfoHandle_t CloseGestureInfoHandle() { - if ( !ms_gestureSymbolsLoaded ) - LoadGestureSymbols(); - return ms_pfnCloseGestureInfoHandle; } - typedef BOOL (WINAPI *SetGestureConfig_t)(HWND, DWORD, UINT, PGESTURECONFIG, UINT); + typedef BOOL + (WINAPI *SetGestureConfig_t)(HWND, DWORD, UINT, PGESTURECONFIG, UINT); static SetGestureConfig_t SetGestureConfig() { - if ( !ms_gestureSymbolsLoaded ) - LoadGestureSymbols(); - return ms_pfnSetGestureConfig; } @@ -259,8 +259,6 @@ private: wxDL_INIT_FUNC(ms_pfn, GetGestureInfo, dll); wxDL_INIT_FUNC(ms_pfn, CloseGestureInfoHandle, dll); wxDL_INIT_FUNC(ms_pfn, SetGestureConfig, dll); - - ms_gestureSymbolsLoaded = true; } static GetGestureInfo_t ms_pfnGetGestureInfo; @@ -268,7 +266,6 @@ private: static SetGestureConfig_t ms_pfnSetGestureConfig; static bool ms_gestureSymbolsLoaded; - }; GestureFuncs::GetGestureInfo_t @@ -280,10 +277,10 @@ GestureFuncs::SetGestureConfig_t bool GestureFuncs::ms_gestureSymbolsLoaded = false; -#endif // WM_GESTURE - } // anonymous namespace +#endif // WM_GESTURE + // --------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------