From: Pat Thoyts Date: Fri, 4 Oct 2024 15:03:29 +0000 (+0100) Subject: Tidy up whitespace and CMake definition X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=accessibility%2Fuiademo.git Tidy up whitespace and CMake definition --- diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..05fb160 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/ButtonProvider.cpp b/ButtonProvider.cpp index 615f0a2..1e402e9 100644 --- a/ButtonProvider.cpp +++ b/ButtonProvider.cpp @@ -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(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(this); this->AddRef(); } - else if (IsEqualIID(riid, IID_IToggleProvider)) - { - *ppv = static_cast(this); - this->AddRef(); - } + else if (IsEqualIID(riid, IID_IToggleProvider)) + { + *ppv = static_cast(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(ppVal)); } - else if (patternId == UIA_TogglePatternId) - { - hr = QueryInterface(IID_IUnknown, reinterpret_cast(ppVal)); - } + else if (patternId == UIA_TogglePatternId) + { + hr = QueryInterface(IID_IUnknown, reinterpret_cast(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(UIA_E_ELEMENTNOTAVAILABLE); - if (IsWindow(_hwnd)) - { - PostMessage(_hwnd, BM_CLICK, 0L, 0L); - hr = S_OK; - } - return hr; + HRESULT hr = static_cast(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(UIA_E_ELEMENTNOTAVAILABLE); - if (IsWindow(_hwnd)) - { - PostMessage(_hwnd, BM_CLICK, 0, 0); - hr = S_OK; - } - return hr; + HRESULT hr = static_cast(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(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(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; +} diff --git a/ButtonProvider.h b/ButtonProvider.h index ae1d551..080b025 100644 --- a/ButtonProvider.h +++ b/ButtonProvider.h @@ -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; }; diff --git a/CMakeLists.txt b/CMakeLists.txt index a2db266..44721c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/PolyButton.cpp b/PolyButton.cpp index 122e972..45ae6f4 100644 --- a/PolyButton.cpp +++ b/PolyButton.cpp @@ -60,8 +60,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT messageId, WPARAM wparam, LPARAM lparam case WM_DESTROY: { PolyButton *ctrl = reinterpret_cast(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(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - ctrl->InvokeButton(); - } - break; - case BM_GETCHECK: - { - PolyButton *ctrl = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - return ctrl->IsChecked() ? BST_CHECKED : BST_UNCHECKED; - } + case BM_CLICK: + { + PolyButton *ctrl = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + ctrl->InvokeButton(); + } + break; + case BM_GETCHECK: + { + PolyButton *ctrl = reinterpret_cast(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); } diff --git a/PolyButton.h b/PolyButton.h index b262484..19d7e9a 100644 --- a/PolyButton.h +++ b/PolyButton.h @@ -6,12 +6,12 @@ #include 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(); diff --git a/main.cpp b/main.cpp index 6f09f76..ac9dd50 100644 --- 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 595a68a..e12acb7 100644 --- 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 \r\n" "\0" END -3 TEXTINCLUDE +3 TEXTINCLUDE BEGIN "\r\n" "\0"