| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | #ifndef _ALLOCA_S_THRESHOLD
|
|---|
| 4 | # define _ALLOCA_S_THRESHOLD 1024
|
|---|
| 5 | #endif
|
|---|
| 6 |
|
|---|
| 7 | #ifdef _MSC_VER
|
|---|
| 8 | # define I3_WINDOWS_SEH_TRY __try
|
|---|
| 9 | # define I3_WINDOWS_SEH_EXCEPT(x) __except(x)
|
|---|
| 10 | #else
|
|---|
| 11 | # define I3_WINDOWS_SEH_TRY
|
|---|
| 12 | # define I3_WINDOWS_SEH_EXCEPT(x) if (false)
|
|---|
| 13 | #endif
|
|---|
| 14 |
|
|---|
| 15 | #ifndef MSFTEDIT_CLASS
|
|---|
| 16 | #define MSFTEDIT_CLASS TEXT("RichEdit50W")
|
|---|
| 17 | #endif
|
|---|
| 18 |
|
|---|
| 19 | #ifdef HAVE_UXTHEME_H
|
|---|
| 20 | # include <uxtheme.h>
|
|---|
| 21 | #else
|
|---|
| 22 | typedef struct _MARGINS {
|
|---|
| 23 | int cxLeftWidth; // width of left border that retains its size
|
|---|
| 24 | int cxRightWidth; // width of right border that retains its size
|
|---|
| 25 | int cyTopHeight; // height of top border that retains its size
|
|---|
| 26 | int cyBottomHeight; // height of bottom border that retains its size
|
|---|
| 27 | } MARGINS;
|
|---|
| 28 | typedef MARGINS* PMARGINS;
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | #if !defined(HAVE_UXTHEME_H) || defined(__CYGWIN__)
|
|---|
| 32 | typedef struct _BP_PAINTPARAMS {
|
|---|
| 33 | DWORD cbSize;
|
|---|
| 34 | DWORD dwFlags;
|
|---|
| 35 | const RECT *prcExclude;
|
|---|
| 36 | const BLENDFUNCTION *pBlendFunction;
|
|---|
| 37 | } BP_PAINTPARAMS, *PBP_PAINTPARAMS;
|
|---|
| 38 | typedef HANDLE HPAINTBUFFER;
|
|---|
| 39 | typedef enum _BP_BUFFERFORMAT {
|
|---|
| 40 | BPBF_COMPATIBLEBITMAP,
|
|---|
| 41 | BPBF_DIB,
|
|---|
| 42 | BPBF_TOPDOWNDIB,
|
|---|
| 43 | BPBF_TOPDOWNMONODIB
|
|---|
| 44 | } BP_BUFFERFORMAT;
|
|---|
| 45 | #define BPPF_ERASE 0x0001 // Empty the buffer during BeginBufferedPaint()
|
|---|
| 46 | #define BPPF_NOCLIP 0x0002 // Don't apply the target DC's clip region to the double buffer
|
|---|
| 47 | #define BPPF_NONCLIENT 0x0004 // Using a non-client DC
|
|---|
| 48 | #define ULW_EX_NORESIZE 0x00000008
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | #ifdef HAVE_DWMAPI_H
|
|---|
| 52 | # include <dwmapi.h>
|
|---|
| 53 | #else
|
|---|
| 54 | typedef enum _DWMWINDOWATTRIBUTE {
|
|---|
| 55 | DWMWA_NCRENDERING_ENABLED = 1,
|
|---|
| 56 | DWMWA_NCRENDERING_POLICY,
|
|---|
| 57 | DWMWA_TRANSITIONS_FORCEDISABLED,
|
|---|
| 58 | DWMWA_ALLOW_NCPAINT,
|
|---|
| 59 | DWMWA_CAPTION_BUTTON_BOUNDS,
|
|---|
| 60 | DWMWA_NONCLIENT_RTL_LAYOUT,
|
|---|
| 61 | DWMWA_FORCE_ICONIC_REPRESENTATION,
|
|---|
| 62 | DWMWA_FLIP3D_POLICY,
|
|---|
| 63 | DWMWA_EXTENDED_FRAME_BOUNDS,
|
|---|
| 64 | DWMWA_HAS_ICONIC_BITMAP,
|
|---|
| 65 | DWMWA_DISALLOW_PEEK,
|
|---|
| 66 | DWMWA_EXCLUDED_FROM_PEEK,
|
|---|
| 67 | DWMWA_LAST
|
|---|
| 68 | } DWMWINDOWATTRIBUTE;
|
|---|
| 69 | // Blur behind data structures
|
|---|
| 70 | #define DWM_BB_ENABLE 0x00000001 // fEnable has been specified
|
|---|
| 71 | #define DWM_BB_BLURREGION 0x00000002 // hRgnBlur has been specified
|
|---|
| 72 | #define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004 // fTransitionOnMaximized has been specified
|
|---|
| 73 | typedef struct _DWM_BLURBEHIND {
|
|---|
| 74 | DWORD dwFlags;
|
|---|
| 75 | BOOL fEnable;
|
|---|
| 76 | HRGN hRgnBlur;
|
|---|
| 77 | BOOL fTransitionOnMaximized;
|
|---|
| 78 | } DWM_BLURBEHIND, *PDWM_BLURBEHIND;
|
|---|
| 79 | #endif
|
|---|
| 80 |
|
|---|
| 81 | #ifdef _WIN32_WCE
|
|---|
| 82 | #ifndef SWP_NOREDRAW
|
|---|
| 83 | #define SWP_NOREDRAW 0
|
|---|
| 84 | #endif
|
|---|
| 85 | #endif
|
|---|
| 86 |
|
|---|
| 87 | namespace i3 {
|
|---|
| 88 | struct Dll {
|
|---|
| 89 | //BOOL (WINAPI *dll_SetLayeredWindowAttributes)(HWND, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
|
|---|
| 90 |
|
|---|
| 91 | bool have_dwmapi_dll;
|
|---|
| 92 | HRESULT (WINAPI *dll_DwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS *pMarInset);
|
|---|
| 93 | HRESULT (WINAPI *dll_DwmIsCompositionEnabled)(BOOL *pfEnabled);
|
|---|
| 94 | HRESULT (WINAPI *dll_DwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND *pBlurBehind);
|
|---|
| 95 | HRESULT (WINAPI *dll_DwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend);
|
|---|
| 96 | HRESULT (WINAPI *dll_DwmGetWindowAttribute)(HWND hWnd, DWORD dwAttribute, PVOID pvAttribute,DWORD cbAttribute);
|
|---|
| 97 | HPAINTBUFFER (WINAPI *dll_BeginBufferedPaint)(HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
|
|---|
| 98 | HRESULT (WINAPI *dll_BufferedPaintInit)(VOID);
|
|---|
| 99 | HRESULT (WINAPI *dll_BufferedPaintUnInit)(VOID);
|
|---|
| 100 | HRESULT (WINAPI *dll_EndBufferedPaint)(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget);
|
|---|
| 101 | HRESULT (WINAPI *dll_BufferedPaintSetAlpha)(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha);
|
|---|
| 102 | };
|
|---|
| 103 | extern Dll dll;
|
|---|
| 104 | extern HINSTANCE hInstance;
|
|---|
| 105 |
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | #define UTF8_TO_UTF16LE_ALLOCA(data8, data16) \
|
|---|
| 109 | wchar_t* data16 = NULL; \
|
|---|
| 110 | for (;;) { \
|
|---|
| 111 | const char* check = data8; check; \
|
|---|
| 112 | unsigned int num_elements = \
|
|---|
| 113 | MultiByteToWideChar(CP_UTF8, 0, data8, -1, NULL, 0); \
|
|---|
| 114 | if (num_elements == 0) { \
|
|---|
| 115 | break; \
|
|---|
| 116 | } \
|
|---|
| 117 | const size_t data16_bytes = num_elements*sizeof(wchar_t); \
|
|---|
| 118 | if (data16_bytes > _ALLOCA_S_THRESHOLD) { \
|
|---|
| 119 | data16 = NULL; \
|
|---|
| 120 | break; \
|
|---|
| 121 | } \
|
|---|
| 122 | I3_WINDOWS_SEH_TRY { \
|
|---|
| 123 | data16 = (wchar_t*)alloca(data16_bytes); \
|
|---|
| 124 | } I3_WINDOWS_SEH_EXCEPT \
|
|---|
| 125 | (GetExceptionCode() == STATUS_STACK_OVERFLOW ? \
|
|---|
| 126 | EXCEPTION_EXECUTE_HANDLER : \
|
|---|
| 127 | EXCEPTION_CONTINUE_SEARCH) { \
|
|---|
| 128 | data16 = NULL; \
|
|---|
| 129 | break; \
|
|---|
| 130 | } \
|
|---|
| 131 | if (0 == MultiByteToWideChar( \
|
|---|
| 132 | CP_UTF8, 0, data8, -1, data16, num_elements)) { \
|
|---|
| 133 | data16 = NULL; \
|
|---|
| 134 | break; \
|
|---|
| 135 | } \
|
|---|
| 136 | break; \
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | #define UTF16LE_TO_UTF8_ALLOCA(data16, data8) \
|
|---|
| 140 | char* data8 = NULL; \
|
|---|
| 141 | for (;;) { \
|
|---|
| 142 | const wchar_t* check = data16; check; \
|
|---|
| 143 | unsigned int num_elements = WideCharToMultiByte( \
|
|---|
| 144 | CP_UTF8, 0, data16, -1, NULL, 0, 0, 0); \
|
|---|
| 145 | if (num_elements == 0 || num_elements > _ALLOCA_S_THRESHOLD) { \
|
|---|
| 146 | break; \
|
|---|
| 147 | } \
|
|---|
| 148 | I3_WINDOWS_SEH_TRY { \
|
|---|
| 149 | data8 = (char*)alloca(num_elements*sizeof(char)); \
|
|---|
| 150 | } I3_WINDOWS_SEH_EXCEPT \
|
|---|
| 151 | (GetExceptionCode() == STATUS_STACK_OVERFLOW ? \
|
|---|
| 152 | EXCEPTION_EXECUTE_HANDLER : \
|
|---|
| 153 | EXCEPTION_CONTINUE_SEARCH) { \
|
|---|
| 154 | data8 = NULL; \
|
|---|
| 155 | break; \
|
|---|
| 156 | } \
|
|---|
| 157 | if (0 == WideCharToMultiByte( \
|
|---|
| 158 | CP_UTF8, 0, data16, -1, data8, num_elements, 0, 0)) { \
|
|---|
| 159 | data8 = NULL; \
|
|---|
| 160 | break; \
|
|---|
| 161 | } \
|
|---|
| 162 | break; \
|
|---|
| 163 | }
|
|---|