Skip to content

Commit

Permalink
Merge 5aefab9 into f1c4e6f
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR authored Oct 7, 2023
2 parents f1c4e6f + 5aefab9 commit ac9dc06
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 19 deletions.
102 changes: 102 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# OSARA: Open Source Accessibility for the REAPER Application
# .clang-format
# Author: James Teh <[email protected]>
# Copyright 2023 Leonard de Ruijter
# License: GNU General Public License version 2.0

# Style based on Google's C++ style guide.
BasedOnStyle: Google
# Offset for access modifiers (public, protected, private).
AccessModifierOffset: 0
# Align code after an open bracket with block indentation.
AlignAfterOpenBracket: BlockIndent
# Do not align consecutive assignments.
AlignConsecutiveAssignments: None
# Do not align consecutive bit fields.
AlignConsecutiveBitFields: None
# Do not align consecutive declarations.
AlignConsecutiveDeclarations: None
# Do not align consecutive macros.
AlignConsecutiveMacros: None
# Do not align escaped newlines.
AlignEscapedNewlines: DontAlign
# Do not align operands in expressions.
AlignOperands: DontAlign
# Do not align trailing comments.
AlignTrailingComments: Never
# Do not allow short blocks (e.g., if statements without braces) on a single line.
AllowShortBlocksOnASingleLine: Never
# Do not allow short case labels in switch statements on a single line.
AllowShortCaseLabelsOnASingleLine: false
# Do not allow short enums on a single line.
AllowShortEnumsOnASingleLine: false
# Only allow empty functions on a single line.
AllowShortFunctionsOnASingleLine: Empty
# Do not allow short if statements on a single line.
AllowShortIfStatementsOnASingleLine: Never
# Do not allow short loops on a single line.
AllowShortLoopsOnASingleLine: false
# Do not pack function call arguments together.
# A function call’s arguments will either be all on the same line or will have one line each.
BinPackArguments: false
# Do not pack function parameters together.
# A function declaration’s or function definition’s parameters will either all be on the same line
# or will have one line each.
BinPackParameters: false
# Add a space after the colon in bit fields.
BitFieldColonSpacing: After
# Break before binary operators that are not assignments.
# E.g. break before "+", but not before "+=".
BreakBeforeBinaryOperators: NonAssignment
# Attach opening braces to the same line as the statement or declaration it belongs to.
BreakBeforeBraces: Attach
# Break string literals if they are too long.
BreakStringLiterals: true
# Maximum column width before code will be wrapped or formatted.
ColumnLimit: 110
# Indentation width for constructor initializers.
ConstructorInitializerIndentWidth: 4
# Indentation width for continuation lines.
ContinuationIndentWidth: 4
# Format braced lists as best suited for C++11 braced lists.
Cpp11BracedListStyle: true
# Use a fixed alignment for all pointers.
DerivePointerAlignment: false
# Indent case blocks in switch statements.
IndentCaseBlocks: true
# Indent case labels in switch statements.
IndentCaseLabels: true
# Standard indentation width.
IndentWidth: 4
# Do not indent if a function definition or declaration is wrapped after the type.
IndentWrappedFunctionNames: false
# Insert a newline at end of file if missing.
InsertNewlineAtEOF: true
# Maximum number of consecutive empty lines to keep.
MaxEmptyLinesToKeep: 2
# Do not indent namespaces.
NamespaceIndentation: None
# Penalty for indentation using spaces rather than tabs.
PenaltyIndentedWhitespace: 0
# Pointer alignment (Left or Right).
PointerAlignment: Left
# Separate definition blocks (Always, Never, or Leave).
SeparateDefinitionBlocks: Always
# Number of spaces before trailing comments.
SpacesBeforeTrailingComments: 1
# Do not add a space after a C-style cast.
SpaceAfterCStyleCast: false
# Do not add a space after the template keyword.
SpaceAfterTemplateKeyword: false
# Sort includes (CaseSensitive, CaseInsensitive, or None).
SortIncludes: CaseInsensitive
# C++ standard to be followed (e.g., c++98, c++11, c++14, c++17, c++20).
Standard: c++20
# Add a space before opening parentheses in control statements.
SpaceBeforeParens: ControlStatements
# Do not add a space before square brackets.
SpaceBeforeSquareBrackets: false
# Width of a tab character.
TabWidth: 4
# Always use tabs for indentation.
UseTab: Always
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gitattributes text
.gitignore text
.clang-format text
*.cpp text
*.h text
*.bat eol=crlf
Expand Down
42 changes: 23 additions & 19 deletions src/uia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* License: GNU General Public License version 2.0
*/

#include <uiautomation.h>
#include <atlcomcli.h>
#include <ole2.h>
#include <tlhelp32.h>
#include <atlcomcli.h>
#include <uiautomation.h>

#include <memory>
#include <utility>
#include "osara.h"

#include "config.h"
#include "osara.h"

using namespace std;

Expand All @@ -38,7 +40,7 @@ class UiaCore {

decltype(UiaRaiseNotificationEvent)* RaiseNotificationEvent =
getFunc<decltype(UiaRaiseNotificationEvent)>("UiaRaiseNotificationEvent");
decltype(UiaDisconnectProvider)* DisconnectProvider =
decltype(UiaDisconnectProvider)* DisconnectProvider =
getFunc<decltype(UiaDisconnectProvider)>("UiaDisconnectProvider");
decltype(UiaDisconnectAllProviders)* DisconnectAllProviders =
getFunc<decltype(UiaDisconnectAllProviders)>("UiaDisconnectAllProviders");
Expand All @@ -49,7 +51,7 @@ unique_ptr<UiaCore> uiaCore;
// Provider code based on Microsoft's uiautomationSimpleProvider example.
class UiaProvider : public IRawElementProviderSimple {
public:
UiaProvider(_In_ HWND hwnd): refCount(0), controlHWnd(hwnd) {}
UiaProvider(_In_ HWND hwnd) : refCount(0), controlHWnd(hwnd) {}

// IUnknown methods
ULONG STDMETHODCALLTYPE AddRef() {
Expand All @@ -69,9 +71,9 @@ class UiaProvider : public IRawElementProviderSimple {
return E_INVALIDARG;
}
if (riid == __uuidof(IUnknown)) {
*ppInterface =static_cast<IRawElementProviderSimple*>(this);
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
} else if (riid == __uuidof(IRawElementProviderSimple)) {
*ppInterface =static_cast<IRawElementProviderSimple*>(this);
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
} else {
*ppInterface = nullptr;
return E_NOINTERFACE;
Expand All @@ -86,7 +88,8 @@ class UiaProvider : public IRawElementProviderSimple {
return S_OK;
}

HRESULT STDMETHODCALLTYPE GetPatternProvider(PATTERNID patternId, _Outptr_result_maybenull_ IUnknown** pRetVal) {
HRESULT STDMETHODCALLTYPE
GetPatternProvider(PATTERNID patternId, _Outptr_result_maybenull_ IUnknown** pRetVal) {
// We do not support any pattern.
*pRetVal = NULL;
return S_OK;
Expand Down Expand Up @@ -120,8 +123,7 @@ class UiaProvider : public IRawElementProviderSimple {
}

private:
virtual ~UiaProvider() {
}
virtual ~UiaProvider() {}

ULONG refCount; // Ref Count for this COM object
HWND controlHWnd; // The HWND for the control.
Expand Down Expand Up @@ -226,8 +228,7 @@ bool shouldUseUiaNotifications() {
// Setting not present or '1' means auto.
// Several screen readers ignore or don't support UIA notification events.
// First check for screen readers with in-process dlls.
if (
GetModuleHandleA("jhook.dll") // JAWS
if (GetModuleHandleA("jhook.dll") // JAWS
|| GetModuleHandleA("dolwinhk.dll") // Dolphin
) {
return false;
Expand All @@ -241,13 +242,16 @@ bool sendUiaNotification(const string& message, bool interrupt) {
if (!UiaClientsAreListening() || message.empty()) {
return true;
}
return (uiaCore->RaiseNotificationEvent(
uiaProvider,
NotificationKind_Other,
interrupt ? NotificationProcessing_MostRecent : NotificationProcessing_All,
SysAllocString(widen(message).c_str()),
SysAllocString(L"REAPER_OSARA")
) == S_OK);
return (
uiaCore->RaiseNotificationEvent(
uiaProvider,
NotificationKind_Other,
interrupt ? NotificationProcessing_MostRecent : NotificationProcessing_All,
SysAllocString(widen(message).c_str()),
SysAllocString(L"REAPER_OSARA")
)
== S_OK
);
}

void resetUia() {
Expand Down

0 comments on commit ac9dc06

Please sign in to comment.