aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.h
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-03-20 16:46:11 +1100
committerNeil <nyamatongwe@gmail.com>2025-03-20 16:46:11 +1100
commit2f542786fd95e7bbce6c689934cb4988aa3fa1df (patch)
treed2d41c023eae2a6d3b13cf1450e9ba59e55920c5 /win32/PlatWin.h
parentcb342d444c6c13671a5c1832d1723c073eca0a37 (diff)
downloadscintilla-mirror-2f542786fd95e7bbce6c689934cb4988aa3fa1df.tar.gz
Move SurfaceGDI, SurfaceD2D, ListBox, and associated code out of PlatWin.cxx to
new files SurfaceGDI.cxx, SurfaceD2D.cxx, and ListBox.cxx + associated headers.
Diffstat (limited to 'win32/PlatWin.h')
-rw-r--r--win32/PlatWin.h102
1 files changed, 84 insertions, 18 deletions
diff --git a/win32/PlatWin.h b/win32/PlatWin.h
index dcda7c944..27f9b3e3d 100644
--- a/win32/PlatWin.h
+++ b/win32/PlatWin.h
@@ -49,6 +49,10 @@ inline HWND HwndFromWindow(const Window &w) noexcept {
return HwndFromWindowID(w.GetID());
}
+extern HINSTANCE hinstPlatformRes;
+
+UINT CodePageFromCharSet(CharacterSet characterSet, UINT documentCodePage) noexcept;
+
void *PointerFromWindow(HWND hWnd) noexcept;
void SetWindowPointer(HWND hWnd, void *ptr) noexcept;
@@ -59,6 +63,8 @@ float GetDeviceScaleFactorWhenGdiScalingActive(HWND hWnd) noexcept;
int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept;
+void AdjustWindowRectForDpi(LPRECT lpRect, DWORD dwStyle, UINT dpi) noexcept;
+
HCURSOR LoadReverseArrowCursor(UINT dpi) noexcept;
// Encapsulate WM_PAINT handling so that EndPaint is always called even with unexpected returns or exceptions.
@@ -87,29 +93,89 @@ public:
}
};
-#if defined(USE_D2D)
-extern bool LoadD2D() noexcept;
-extern ID2D1Factory1 *pD2DFactory;
-extern IDWriteFactory1 *pIDWriteFactory;
-
-using DCRenderTarget = ComPtr<ID2D1DCRenderTarget>;
-
-using D3D11Device = ComPtr<ID3D11Device1>;
-
-HRESULT CreateDCRenderTarget(const D2D1_RENDER_TARGET_PROPERTIES *renderTargetProperties, DCRenderTarget &dcRT) noexcept;
-extern HRESULT CreateD3D(D3D11Device &device) noexcept;
+// Both GDI and DirectWrite can produce a HFONT for use in list boxes
+struct FontWin : public Font {
+ [[nodiscard]] virtual HFONT HFont() const noexcept = 0;
+ [[nodiscard]] virtual std::unique_ptr<FontWin> Duplicate() const = 0;
+ [[nodiscard]] virtual CharacterSet GetCharacterSet() const noexcept = 0;
+};
-using WriteRenderingParams = ComPtr<IDWriteRenderingParams1>;
+// Buffer to hold strings and string position arrays without always allocating on heap.
+// May sometimes have string too long to allocate on stack. So use a fixed stack-allocated buffer
+// when less than safe size otherwise allocate on heap and free automatically.
+template<typename T, int lengthStandard>
+class VarBuffer {
+ T bufferStandard[lengthStandard];
+public:
+ T *buffer;
+ explicit VarBuffer(size_t length) : buffer(nullptr) {
+ if (length > lengthStandard) {
+ buffer = new T[length];
+ } else {
+ buffer = bufferStandard;
+ }
+ }
+ // Deleted so VarBuffer objects can not be copied.
+ VarBuffer(const VarBuffer &) = delete;
+ VarBuffer(VarBuffer &&) = delete;
+ VarBuffer &operator=(const VarBuffer &) = delete;
+ VarBuffer &operator=(VarBuffer &&) = delete;
+
+ ~VarBuffer() noexcept {
+ if (buffer != bufferStandard) {
+ delete[]buffer;
+ buffer = nullptr;
+ }
+ }
+};
-struct RenderingParams {
- WriteRenderingParams defaultRenderingParams;
- WriteRenderingParams customRenderingParams;
+constexpr int stackBufferLength = 400;
+class TextWide : public VarBuffer<wchar_t, stackBufferLength> {
+public:
+ int tlen; // Using int instead of size_t as most Win32 APIs take int.
+ TextWide(std::string_view text, int codePage) :
+ VarBuffer<wchar_t, stackBufferLength>(text.length()) {
+ if (codePage == CpUtf8) {
+ tlen = static_cast<int>(UTF16FromUTF8(text, buffer, text.length()));
+ } else {
+ // Support Asian string display in 9x English
+ tlen = ::MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.length()),
+ buffer, static_cast<int>(text.length()));
+ }
+ }
+ [[nodiscard]] std::wstring_view AsView() const noexcept {
+ return std::wstring_view(buffer, tlen);
+ }
};
+using TextPositions = VarBuffer<XYPOSITION, stackBufferLength>;
+
+// Manage the lifetime of a memory HBITMAP and its HDC so there are no leaks.
+class GDIBitMap {
+ HDC hdc{};
+ HBITMAP hbm{};
+ HBITMAP hbmOriginal{};
-struct ISetRenderingParams {
- virtual void SetRenderingParams(std::shared_ptr<RenderingParams> renderingParams_) = 0;
+public:
+ GDIBitMap() noexcept = default;
+ // Deleted so GDIBitMap objects can not be copied.
+ GDIBitMap(const GDIBitMap &) = delete;
+ GDIBitMap(GDIBitMap &&) = delete;
+ // Move would be OK but not needed yet
+ GDIBitMap &operator=(const GDIBitMap &) = delete;
+ GDIBitMap &operator=(GDIBitMap &&) = delete;
+ ~GDIBitMap() noexcept;
+
+ void Create(HDC hdcBase, int width, int height, DWORD **pixels) noexcept;
+ void Release() noexcept;
+ HBITMAP Extract() noexcept;
+
+ [[nodiscard]] HDC DC() const noexcept {
+ return hdc;
+ }
+ [[nodiscard]] explicit operator bool() const noexcept {
+ return hdc && hbm;
+ }
};
-#endif
}