Tidy up whitespace and CMake definition master
authorPat Thoyts <patthoyts@users.sourceforge.net>
Fri, 4 Oct 2024 15:03:29 +0000 (16:03 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Fri, 4 Oct 2024 15:03:29 +0000 (16:03 +0100)
.editorconfig [new file with mode: 0644]
ButtonProvider.cpp
ButtonProvider.h
CMakeLists.txt
PolyButton.cpp
PolyButton.h
main.cpp
main.rc

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..05fb160
--- /dev/null
@@ -0,0 +1,19 @@
+# top-most EditorConfig file
+root = true
+
+# Don't use tabs for indentation.
+[*]
+indent_style = space
+trim_trailing_whitespace = true
+# (Please don't specify an indent_size here; that has too many unintended consequences.)
+
+[*.{c,h,cxx,cpp}]
+indent_size = 4
+
+# Powershell files
+[*.{ps1,psm1,psd1}]
+indent_size = 4
+
+# Xml based files
+[*.{proj,xml,nuspec}]
+indent_size = 2
index 615f0a2a9b21bef33b0c07ec1d8703308834b6ca..1e402e94c9f2ee50e2640dcce57a2ed423f2b4a5 100644 (file)
@@ -8,14 +8,14 @@
 HRESULT ButtonProvider::CreateInstance(HWND hwnd, IRawElementProviderSimple **ppProvider)
 {
     ButtonProvider *provider = new (std::nothrow) ButtonProvider(hwnd);
-       wchar_t wsz[128]; swprintf_s(wsz, L"Created %p\n", provider); OutputDebugStringW(wsz);
+    wchar_t wsz[128]; swprintf_s(wsz, L"Created %p\n", provider); OutputDebugStringW(wsz);
     return provider->QueryInterface(IID_IRawElementProviderSimple, reinterpret_cast<void**>(ppProvider));
 }
 
 DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::QueryInterface(REFIID riid, void **ppv)
 {
     HRESULT hr = S_OK;
-       *ppv = nullptr;
+    *ppv = nullptr;
     if (IsEqualIID(riid, IID_IUnknown)
         || IsEqualIID(riid, IID_IRawElementProviderSimple))
     {
@@ -27,11 +27,11 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::QueryInterface(REFIID riid, void *
         *ppv = static_cast<IInvokeProvider *>(this);
         this->AddRef();
     }
-       else if (IsEqualIID(riid, IID_IToggleProvider))
-       {
-               *ppv = static_cast<IToggleProvider *>(this);
-               this->AddRef();
-       }
+    else if (IsEqualIID(riid, IID_IToggleProvider))
+    {
+        *ppv = static_cast<IToggleProvider *>(this);
+        this->AddRef();
+    }
     else
         hr = E_NOINTERFACE;
     return hr;
@@ -39,19 +39,19 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::QueryInterface(REFIID riid, void *
 
 DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) ButtonProvider::AddRef()
 {
-       ULONG result = InterlockedIncrement(&_refcount);
-       //wchar_t wsz[128]; swprintf_s(wsz, L"AddRef %lu\n", result); OutputDebugStringW(wsz);
-       return result;
+    ULONG result = InterlockedIncrement(&_refcount);
+    //wchar_t wsz[128]; swprintf_s(wsz, L"AddRef %lu\n", result); OutputDebugStringW(wsz);
+    return result;
 }
 
 DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) ButtonProvider::Release()
 {
     unsigned long result = InterlockedDecrement(&_refcount);
-       //wchar_t wsz[128]; swprintf_s(wsz, L"Release %lu\n", result); OutputDebugStringW(wsz);
-       if (result == 0)
+    //wchar_t wsz[128]; swprintf_s(wsz, L"Release %lu\n", result); OutputDebugStringW(wsz);
+    if (result == 0)
     {
-               wchar_t wsz[128]; swprintf_s(wsz, L"Destroy %p\n", this); OutputDebugStringW(wsz);
-               delete this;
+        wchar_t wsz[128]; swprintf_s(wsz, L"Destroy %p\n", this); OutputDebugStringW(wsz);
+        delete this;
     }
     return result;
 }
@@ -61,15 +61,15 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::get_ProviderOptions(ProviderOption
     HRESULT hr = E_POINTER;
     if (pVal)
     {
-               if (!IsWindow(_hwnd))
-                       hr = UIA_E_ELEMENTNOTENABLED;
-               else
-               {
-                       *pVal = ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading;
-                       hr = S_OK;
-               }
+        if (!IsWindow(_hwnd))
+            hr = UIA_E_ELEMENTNOTENABLED;
+        else
+        {
+            *pVal = ProviderOptions_ServerSideProvider | ProviderOptions_UseComThreading;
+            hr = S_OK;
+        }
     }
-    return hr;    
+    return hr;
 }
 
 DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::GetPatternProvider(PATTERNID patternId, IUnknown **ppVal)
@@ -83,10 +83,10 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::GetPatternProvider(PATTERNID patte
         {
             hr = QueryInterface(IID_IUnknown, reinterpret_cast<void **>(ppVal));
         }
-               else if (patternId == UIA_TogglePatternId)
-               {
-                       hr = QueryInterface(IID_IUnknown, reinterpret_cast<void **>(ppVal));
-               }
+        else if (patternId == UIA_TogglePatternId)
+        {
+            hr = QueryInterface(IID_IUnknown, reinterpret_cast<void **>(ppVal));
+        }
     }
     return hr;
 }
@@ -98,20 +98,20 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::GetPropertyValue(PROPERTYID proper
         pVal->vt = VT_I4;
         pVal->lVal = UIA_ButtonControlTypeId;
     }
-       else if (propertyId == UIA_IsControlElementPropertyId)
-       {
-               pVal->vt = VT_BOOL;
-               pVal->boolVal = VARIANT_TRUE;
-       }
-       else if (propertyId == UIA_HasKeyboardFocusPropertyId)
-       {
-               pVal->vt = VT_BOOL;
-               pVal->boolVal = VARIANT_FALSE;
-       }
-       else if (propertyId == UIA_ClassNamePropertyId)
-    {
-               wchar_t name[32] = { 0 };
-               GetClassNameW(_hwnd, name, 32);
+    else if (propertyId == UIA_IsControlElementPropertyId)
+    {
+        pVal->vt = VT_BOOL;
+        pVal->boolVal = VARIANT_TRUE;
+    }
+    else if (propertyId == UIA_HasKeyboardFocusPropertyId)
+    {
+        pVal->vt = VT_BOOL;
+        pVal->boolVal = VARIANT_FALSE;
+    }
+    else if (propertyId == UIA_ClassNamePropertyId)
+    {
+        wchar_t name[32] = { 0 };
+        GetClassNameW(_hwnd, name, 32);
         pVal->vt = VT_BSTR;
         pVal->bstrVal = SysAllocString(name);
     }
@@ -143,39 +143,39 @@ DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::get_HostRawElementProvider(IRawEle
 
 DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::Invoke()
 {
-       HRESULT hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
-       if (IsWindow(_hwnd))
-       {
-               PostMessage(_hwnd, BM_CLICK, 0L, 0L);
-               hr = S_OK;
-       }
-       return hr;
+    HRESULT hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
+    if (IsWindow(_hwnd))
+    {
+        PostMessage(_hwnd, BM_CLICK, 0L, 0L);
+        hr = S_OK;
+    }
+    return hr;
 }
 
 DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::Toggle()
 {
-       HRESULT hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
-       if (IsWindow(_hwnd))
-       {
-               PostMessage(_hwnd, BM_CLICK, 0, 0);
-               hr = S_OK;
-       }
-       return hr;
+    HRESULT hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
+    if (IsWindow(_hwnd))
+    {
+        PostMessage(_hwnd, BM_CLICK, 0, 0);
+        hr = S_OK;
+    }
+    return hr;
 }
 
 DECLSPEC_NOTHROW STDMETHODIMP ButtonProvider::get_ToggleState(ToggleState *pVal)
 {
-       HRESULT hr = E_POINTER;
-       if (pVal)
-       {
-               if (!IsWindow(_hwnd))
-                       hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
-               else
-               {
-                       auto state = SendMessage(_hwnd, BM_GETCHECK, WPARAM(0), LPARAM(0));
-                       *pVal = (state == BST_CHECKED) ? ToggleState_On : ToggleState_Off;
-                       hr = S_OK;
-               }
-       }
-       return hr;
-}
\ No newline at end of file
+    HRESULT hr = E_POINTER;
+    if (pVal)
+    {
+        if (!IsWindow(_hwnd))
+            hr = static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE);
+        else
+        {
+            auto state = SendMessage(_hwnd, BM_GETCHECK, WPARAM(0), LPARAM(0));
+            *pVal = (state == BST_CHECKED) ? ToggleState_On : ToggleState_Off;
+            hr = S_OK;
+        }
+    }
+    return hr;
+}
index ae1d551d3f39cc5041a5381ead3df5dd246f7c8a..080b0258a4047b42d9b727d1267811cff0aa9b52 100644 (file)
@@ -6,7 +6,7 @@ class ButtonProvider : public IRawElementProviderSimple, public IInvokeProvider,
 {
 public:
     static HRESULT CreateInstance(HWND hwnd, IRawElementProviderSimple **ppProvider);
-    
+
     STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
     STDMETHOD_(ULONG, AddRef)();
     STDMETHOD_(ULONG, Release)();
@@ -18,13 +18,13 @@ public:
 
     STDMETHOD(Invoke)();
 
-       STDMETHOD(Toggle)();
-       STDMETHOD(get_ToggleState)(ToggleState *pVal);
+    STDMETHOD(Toggle)();
+    STDMETHOD(get_ToggleState)(ToggleState *pVal);
 
 private:
     ButtonProvider() : _refcount(0), _hwnd(HWND_DESKTOP) {}
     ButtonProvider(HWND hwnd) : _refcount(0), _hwnd(hwnd) {}
-       virtual ~ButtonProvider() {}
-       unsigned long _refcount;
+    virtual ~ButtonProvider() {}
+    unsigned long _refcount;
     HWND _hwnd;
 };
index a2db26642b5ac461f4e35d9e44bf1df954770c91..44721c9722b9fb3071f82275758b2b58d8611699 100644 (file)
@@ -1,19 +1,14 @@
-# CMAKE_BUILD_TYPE has no effect on the Visual Studio generator.
-#   cmake -G"Visual Studio 15 2017 Win64" ..
-#   cmake --build . --config Release
-#
-# For LLVM / CLang build:
-#   cmake -G"Visual Studio 15 2017 Win64" -T LLVM ..
-#   cmake --build . --config Release
+cmake_minimum_required(VERSION 3.26)
 
-cmake_minimum_required(VERSION 3.0)
+project(UIADemo VERSION 1.0 LANGUAGES CXX RC)
 
-ENABLE_LANGUAGE(RC)
-
-project(UIADemo VERSION 1.0)
+set(TARGET ${PROJECT_NAME})
 set(SOURCE main.cpp main.rc resource.h
            PolyButton.cpp PolyButton.h
            ButtonProvider.cpp ButtonProvider.h)
-set(CMAKE_CXX_STANDARD 14)
-add_definitions(-DUNICODE -D_UNICODE -DSTRICT -D_WIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN8)
-add_executable(${PROJECT_NAME} WIN32 ${SOURCE})
+
+add_executable(${TARGET} WIN32 ${SOURCE})
+target_compile_features(${TARGET} PRIVATE cxx_std_17)
+target_compile_definitions(${TARGET} PRIVATE
+    -DUNICODE -D_UNICODE -DSTRICT -D_WIN32_LEAN_AND_MEAN
+    -D_WIN32_WINNT=_WIN32_WINNT_WIN8)
index 122e972ed2f2a774d1f03fa87e7b2b0856164ff7..45ae6f4e6f59244a517b8ee376155aff01e7689f 100644 (file)
@@ -60,8 +60,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT messageId, WPARAM wparam, LPARAM lparam
         case WM_DESTROY:
             {
                 PolyButton *ctrl = reinterpret_cast<PolyButton *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
-                               UiaReturnRawElementProvider(hwnd, 0, 0, nullptr);
-                               UiaDisconnectProvider(ctrl->GetUIAutomationProvider(hwnd));
+                UiaReturnRawElementProvider(hwnd, 0, 0, nullptr);
+                UiaDisconnectProvider(ctrl->GetUIAutomationProvider(hwnd));
                 delete ctrl;
             }
             break;
@@ -98,17 +98,17 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT messageId, WPARAM wparam, LPARAM lparam
                 ctrl->InvokeButton();
             }
             break;
-               case BM_CLICK:
-                       {
-                               PolyButton *ctrl = reinterpret_cast<PolyButton *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
-                               ctrl->InvokeButton();
-                       }
-                       break;
-               case BM_GETCHECK:
-               {
-                       PolyButton *ctrl = reinterpret_cast<PolyButton *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
-                       return ctrl->IsChecked() ? BST_CHECKED : BST_UNCHECKED;
-               }
+        case BM_CLICK:
+            {
+                PolyButton *ctrl = reinterpret_cast<PolyButton *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+                ctrl->InvokeButton();
+            }
+            break;
+        case BM_GETCHECK:
+        {
+            PolyButton *ctrl = reinterpret_cast<PolyButton *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+            return ctrl->IsChecked() ? BST_CHECKED : BST_UNCHECKED;
+        }
     }
     return DefWindowProc(hwnd, messageId, wparam, lparam);
 }
@@ -190,17 +190,17 @@ void PolyButton::InvokeButton()
     {
         if ((_state & PolyButtonState::Focussed) != PolyButtonState::Focussed)
             SetFocus(_hwnd);
-               _state ^= PolyButtonState::Checked;
+        _state ^= PolyButtonState::Checked;
         if (UiaClientsAreListening())
         {
             // Raise an event.
-                       IRawElementProviderSimple *p = nullptr;
-                       if (_provider)
-                       {
-                               _provider->QueryInterface(&p);
-                               UiaRaiseAutomationEvent(p, UIA_Invoke_InvokedEventId);
-                               p->Release();
-                       }
+            IRawElementProviderSimple *p = nullptr;
+            if (_provider)
+            {
+                _provider->QueryInterface(&p);
+                UiaRaiseAutomationEvent(p, UIA_Invoke_InvokedEventId);
+                p->Release();
+            }
         }
         InvalidateRect(_hwnd, nullptr, TRUE);
     }
index b262484e9a7cf263e1b79ee5f61f9dc533f1a621..19d7e9a9ec805130077896b9eb85bde0f022ef9b 100644 (file)
@@ -6,12 +6,12 @@
 #include <uiautomation.h>
 
 enum class PolyButtonState {
-       Normal = 0,
-       Active = (1 << 0),
-       Pressed = (1 << 1),
-       Focussed = (1 << 2),
-       Checked = (1 << 3),
-       Disabled = (1 << 4)
+    Normal = 0,
+    Active = (1 << 0),
+    Pressed = (1 << 1),
+    Focussed = (1 << 2),
+    Checked = (1 << 3),
+    Disabled = (1 << 4)
 };
 DEFINE_ENUM_FLAG_OPERATORS(PolyButtonState);
 
@@ -23,7 +23,7 @@ public:
     IRawElementProviderSimple *GetUIAutomationProvider(HWND hwnd);
     void InvokeButton();
     static void RegisterControl(HINSTANCE instance);
-       bool IsChecked() const { return ((_state & PolyButtonState::Checked) == PolyButtonState::Checked); }
+    bool IsChecked() const { return ((_state & PolyButtonState::Checked) == PolyButtonState::Checked); }
     void OnPaint();
     void OnSetFocus();
     void OnKillFocus();
index 6f09f7615340dd76d438ad9889dd30f99d3436f1..ac9dd50ffa89c311501dd990d15b23702d744bb5 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -9,29 +9,29 @@
 
 static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
 {
-       switch (message)
-       {
-       case WM_COMMAND:
-               if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
-               {
-                       EndDialog(hDlg, LOWORD(wParam));
-                       return TRUE;
-               }
-               break;
-       }
-       return FALSE;
+    switch (message)
+    {
+    case WM_COMMAND:
+        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
+        {
+            EndDialog(hDlg, LOWORD(wParam));
+            return TRUE;
+        }
+        break;
+    }
+    return FALSE;
 }
 
 int PASCAL
 WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int)
 {
-       Gdiplus::GdiplusStartupInput gdiplusStartupInput;
-       ULONG_PTR gdiplusToken(0);
-       Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
-       CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
-       PolyButton::RegisterControl(hinst);
-       DialogBox(hinst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
-       CoUninitialize();
-       Gdiplus::GdiplusShutdown(gdiplusToken);
-       return 0;
+    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
+    ULONG_PTR gdiplusToken(0);
+    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+    CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+    PolyButton::RegisterControl(hinst);
+    DialogBox(hinst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
+    CoUninitialize();
+    Gdiplus::GdiplusShutdown(gdiplusToken);
+    return 0;
 }
diff --git a/main.rc b/main.rc
index 595a68a215eaa2051d4214f7021d8885601a4cb6..e12acb79708eb0c81fe0624b13a07e83748fb79a 100644 (file)
--- a/main.rc
+++ b/main.rc
@@ -41,13 +41,13 @@ BEGIN
     BEGIN
         BLOCK "040904b0"
         BEGIN
-            VALUE "Comments", "Direct2D sample application"
+            VALUE "Comments", "Custom control UI automation example"
             VALUE "CompanyName", "Renishaw plc."
-            VALUE "FileDescription", "Direct2D sample application"
+            VALUE "FileDescription", "Custom control UI automation example"
             VALUE "FileVersion", "1, 0, 0, 0"
-            VALUE "InternalName", "D2DDemo"
+            VALUE "InternalName", "UIADemo"
             VALUE "LegalCopyright", "Copyright (c) 2020 Renishaw plc."
-            VALUE "OriginalFilename", "D2DDemo.exe"
+            VALUE "OriginalFilename", "UIADemo.exe"
             VALUE "ProductVersion", "1, 0, 0, 0"
         END
     END
@@ -74,18 +74,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
 // TEXTINCLUDE
 //
 
-1 TEXTINCLUDE 
+1 TEXTINCLUDE
 BEGIN
     "resource.h\0"
 END
 
-2 TEXTINCLUDE 
+2 TEXTINCLUDE
 BEGIN
     "#include <winres.h>\r\n"
     "\0"
 END
 
-3 TEXTINCLUDE 
+3 TEXTINCLUDE
 BEGIN
     "\r\n"
     "\0"