1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2020 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Functions to obtain Windows 10 accent colors and colors used to paint window frames.
27 #include <windows.ui.viewmanagement.h>
35 Win10Colors(const Win10Colors
& t
) = delete;
36 Win10Colors
& operator=(const Win10Colors
& t
) = delete;
39 * RGBA color. Red is in the LSB, Alpha in the MSB.
40 * You can use GetRValue() et al to access individual components.
44 /// Accent color shades
47 /// foreground accent color
49 /// background accent color
67 static HRESULT
GetAccentColor(AccentColor
& color
);
69 /// Dynamically loaded WindowsCreateStringReference, if available
70 static HRESULT
WindowsCreateStringReference(PCWSTR sourceString
, UINT32 length
, HSTRING_HEADER
* hstringHeader
, HSTRING
* string
)
72 return instance
.WindowsCreateStringReferenceImpl(sourceString
, length
, hstringHeader
, string
);
75 /// Dynamically loaded RoActivateInstance, if available
76 static HRESULT
RoActivateInstance(HSTRING activatableClassId
, IInspectable
** newInstance
)
78 return instance
.RoActivateInstanceImpl(activatableClassId
, newInstance
);
82 /// Wrap WindowsCreateStringReference
83 inline HRESULT
WindowsCreateStringReferenceImpl(PCWSTR sourceString
, UINT32 length
, HSTRING_HEADER
* hstringHeader
, HSTRING
* string
)
85 if (!pWindowsCreateStringReference
)
87 return pWindowsCreateStringReference(sourceString
, length
, hstringHeader
, string
);
90 /// Wrap RoActivateInstance
91 inline HRESULT
RoActivateInstanceImpl(HSTRING activatableClassId
, IInspectable
** inst
)
93 if (!pRoActivateInstance
)
95 return pRoActivateInstance(activatableClassId
, inst
);
98 static inline RGBA
MakeRGBA(uint8_t R
, uint8_t G
, uint8_t B
, uint8_t A
)
100 return RGB(R
, G
, B
) | (A
<< 24);
103 static inline RGBA
ToRGBA(ABI::Windows::UI::Color color
)
105 return MakeRGBA(color
.R
, color
.G
, color
.B
, color
.A
);
109 static Win10Colors instance
;
110 bool modules_loaded
= false;
112 HMODULE winrt_string
= 0;
114 typedef HRESULT(STDAPICALLTYPE
* pfnWindowsCreateStringReference
)(
115 PCWSTR sourceString
, UINT32 length
, HSTRING_HEADER
* hstringHeader
, HSTRING
* string
);
116 pfnWindowsCreateStringReference pWindowsCreateStringReference
= nullptr;
117 typedef HRESULT(WINAPI
* pfnRoActivateInstance
)(HSTRING activatableClassId
, IInspectable
** instance
);
118 pfnRoActivateInstance pRoActivateInstance
= nullptr;