tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / vcl / inc / win / salgdi.h
blobf8107a4a2a0049ba0c54d36a7917ae29bb4087db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <sal/config.h>
24 #include <sallayout.hxx>
25 #include <salgeom.hxx>
26 #include <salgdi.hxx>
27 #include <font/LogicalFontInstance.hxx>
28 #include <fontattributes.hxx>
29 #include <font/PhysicalFontFace.hxx>
30 #include <impfont.hxx>
31 #include <vcl/fontcapabilities.hxx>
32 #include <vcl/fontcharmap.hxx>
33 #include <systools/win32/comtools.hxx>
35 #include <memory>
36 #include <unordered_set>
38 #ifndef INCLUDED_PRE_POST_WIN_H
39 #define INCLUDED_PRE_POST_WIN_H
40 # include <prewin.h>
41 # include <postwin.h>
42 #endif
44 #include <hb-ot.h>
45 #include <dwrite.h>
47 namespace vcl::font
49 class PhysicalFontCollection;
50 class FontSelectPattern;
52 class WinFontInstance;
53 class ImplFontAttrCache;
54 class SalGraphicsImpl;
55 class WinSalGraphicsImplBase;
56 class FontMetricData;
58 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
59 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
61 // win32 specific physically available font face
62 class WinFontFace final : public vcl::font::PhysicalFontFace
64 public:
65 explicit WinFontFace(const ENUMLOGFONTEXW&, const NEWTEXTMETRICW&);
66 ~WinFontFace() override;
68 rtl::Reference<LogicalFontInstance> CreateFontInstance( const vcl::font::FontSelectPattern& ) const override;
69 sal_IntPtr GetFontId() const override;
70 void SetFontId( sal_IntPtr nId ) { mnId = nId; }
72 BYTE GetCharSet() const { return meWinCharSet; }
73 BYTE GetPitchAndFamily() const { return mnPitchAndFamily; }
75 hb_blob_t* GetHbTable(hb_tag_t nTag) const override;
77 const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const override;
79 private:
80 sal_IntPtr mnId;
82 BYTE meWinCharSet;
83 BYTE mnPitchAndFamily;
84 LOGFONTW maLogFont;
85 mutable sal::systools::COMReference<IDWriteFontFace> mxDWFontFace;
88 /** Class that creates (and destroys) a compatible Device Context.
90 This is to be used for GDI drawing into a DIB that we later use for a different
91 drawing method, such as a texture for OpenGL drawing or surface for Skia drawing.
93 class CompatibleDC
95 protected:
96 /// The compatible DC that we create for our purposes.
97 HDC mhCompatibleDC;
99 /// DIBSection that we use for the GDI drawing, and later obtain.
100 HBITMAP mhBitmap;
102 /// Return the previous bitmap to undo the SelectObject.
103 HBITMAP mhOrigBitmap;
105 /// DIBSection data.
106 sal_uInt32 *mpData;
108 /// Mapping between the GDI position and OpenGL, to use for OpenGL drawing.
109 SalTwoRect maRects;
111 /// The SalGraphicsImpl where we will draw. If null, we ignore the drawing, it means it happened directly to the DC...
112 WinSalGraphicsImplBase *mpImpl;
114 // If 'disable' is true, this class is a simple wrapper for drawing directly. Subclasses should use true.
115 CompatibleDC(SalGraphics &rGraphics, int x, int y, int width, int height, bool disable=true);
117 public:
118 static std::unique_ptr< CompatibleDC > create(SalGraphics &rGraphics, int x, int y, int width, int height);
120 virtual ~CompatibleDC();
122 HDC getCompatibleHDC() { return mhCompatibleDC; }
124 SalTwoRect getTwoRect() const { return maRects; }
126 tools::Long getBitmapWidth() const { return maRects.mnSrcWidth; }
127 tools::Long getBitmapHeight() const { return maRects.mnSrcHeight; }
129 /// Reset the DC with the defined color.
130 void fill(sal_uInt32 color);
134 * WinSalGraphics never owns the HDC it uses to draw, because the HDC can have
135 * various origins with different ways to correctly free it. And WinSalGraphics
136 * stores all default values (mhDef*) of the HDC, which must be restored when
137 * the HDC changes (setHDC) or the SalGraphics is destructed. So think of the
138 * HDC in terms of Rust's Borrowing semantics.
140 class WinSalGraphics : public SalGraphics
142 friend class WinSalGraphicsImpl;
143 friend class ScopedFont;
145 protected:
146 std::unique_ptr<SalGraphicsImpl> mpImpl;
147 WinSalGraphicsImplBase * mWinSalGraphicsImplBase;
149 private:
150 HDC mhLocalDC; // HDC
151 bool mbPrinter : 1; // is Printer
152 bool mbVirDev : 1; // is VirDev
153 bool mbWindow : 1; // is Window
154 bool mbScreen : 1; // is Screen compatible
155 HWND mhWnd; // Window-Handle, when Window-Graphics
157 rtl::Reference<WinFontInstance>
158 mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
159 HRGN mhRegion; // vcl::Region Handle
160 HPEN mhDefPen; // DefaultPen
161 HBRUSH mhDefBrush; // DefaultBrush
162 HFONT mhDefFont; // DefaultFont
163 HPALETTE mhDefPal; // DefaultPalette
164 COLORREF mnTextColor; // TextColor
165 RGNDATA* mpClipRgnData; // ClipRegion-Data
166 RGNDATA* mpStdClipRgnData; // Cache Standard-ClipRegion-Data
167 int mnPenWidth; // line width
169 // just call both from setHDC!
170 void InitGraphics();
171 void DeInitGraphics();
173 public:
174 // Return HFONT, and whether the font is for vertical writing ( prefixed with '@' )
175 // and tmDescent value for adjusting offset in vertical writing mode.
176 std::tuple<HFONT,bool,sal_Int32> ImplDoSetFont(HDC hDC, vcl::font::FontSelectPattern const & i_rFont, const vcl::font::PhysicalFontFace * i_pFontFace, HFONT& o_rOldFont);
178 HDC getHDC() const { return mhLocalDC; }
179 // NOTE: this doesn't transfer ownership! See class comment.
180 void setHDC(HDC aNew);
182 HPALETTE getDefPal() const;
183 // returns the result from RealizePalette, otherwise 0 on success or GDI_ERROR
184 UINT setPalette(HPALETTE, BOOL bForceBkgd = TRUE);
186 HRGN getRegion() const;
189 enum Type
191 PRINTER,
192 VIRTUAL_DEVICE,
193 WINDOW,
194 SCREEN
197 static IDWriteFactory* getDWriteFactory();
198 static IDWriteGdiInterop* getDWriteGdiInterop();
200 public:
202 HWND gethWnd();
205 public:
206 explicit WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hWnd,
207 SalGeometryProvider *pProvider);
208 virtual ~WinSalGraphics() override;
210 SalGraphicsImpl* GetImpl() const override;
211 WinSalGraphicsImplBase * getWinSalGraphicsImplBase() const { return mWinSalGraphicsImplBase; }
212 bool isPrinter() const;
213 bool isVirtualDevice() const;
214 bool isWindow() const;
215 bool isScreen() const;
217 void setHWND(HWND hWnd);
218 void Flush();
220 protected:
221 virtual void setClipRegion( const vcl::Region& ) override;
222 // draw --> LineColor and FillColor and RasterOp and ClipRegion
223 virtual void drawPixel( tools::Long nX, tools::Long nY ) override;
224 virtual void drawPixel( tools::Long nX, tools::Long nY, Color nColor ) override;
225 virtual void drawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) override;
226 virtual void drawRect( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
227 virtual void drawPolyLine( sal_uInt32 nPoints, const Point* pPtAry ) override;
228 virtual void drawPolygon( sal_uInt32 nPoints, const Point* pPtAry ) override;
229 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point** pPtAry ) override;
230 virtual void drawPolyPolygon(
231 const basegfx::B2DHomMatrix& rObjectToDevice,
232 const basegfx::B2DPolyPolygon&,
233 double fTransparency) override;
234 virtual bool drawPolyLine(
235 const basegfx::B2DHomMatrix& rObjectToDevice,
236 const basegfx::B2DPolygon&,
237 double fTransparency,
238 double fLineWidth,
239 const std::vector< double >* pStroke, // MM01
240 basegfx::B2DLineJoin,
241 css::drawing::LineCap,
242 double fMiterMinimumAngle,
243 bool bPixelSnapHairline) override;
244 virtual bool drawPolyLineBezier( sal_uInt32 nPoints, const Point* pPtAry, const PolyFlags* pFlgAry ) override;
245 virtual bool drawPolygonBezier( sal_uInt32 nPoints, const Point* pPtAry, const PolyFlags* pFlgAry ) override;
246 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point* const* pPtAry, const PolyFlags* const* pFlgAry ) override;
247 virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) override;
248 virtual bool implDrawGradient(basegfx::B2DPolyPolygon const & rPolyPolygon, SalGradient const & rGradient) override;
250 // CopyArea --> No RasterOp, but ClipRegion
251 virtual void copyArea( tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY, tools::Long nSrcWidth,
252 tools::Long nSrcHeight, bool bWindowInvalidate ) override;
254 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
255 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
256 virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) override;
257 virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override;
258 virtual void drawBitmap( const SalTwoRect& rPosAry,
259 const SalBitmap& rSalBitmap,
260 const SalBitmap& rTransparentBitmap ) override;
261 virtual void drawMask( const SalTwoRect& rPosAry,
262 const SalBitmap& rSalBitmap,
263 Color nMaskColor ) override;
265 virtual std::shared_ptr<SalBitmap> getBitmap( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
266 virtual Color getPixel( tools::Long nX, tools::Long nY ) override;
268 // invert --> ClipRegion (only Windows or VirDevs)
269 virtual void invert( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags) override;
270 virtual void invert( sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags ) override;
272 virtual bool drawEPS( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, void* pPtr, sal_uInt32 nSize ) override;
274 // native widget rendering methods that require mirroring
275 protected:
276 virtual bool isNativeControlSupported( ControlType nType, ControlPart nPart ) override;
277 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
278 const Point& aPos, bool& rIsInside ) override;
279 virtual bool drawNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion,
280 ControlState nState, const ImplControlValue& aValue,
281 const OUString& aCaption, const Color& rBackgroundColor ) override;
282 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion, ControlState nState,
283 const ImplControlValue& aValue, const OUString& aCaption,
284 tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion ) override;
286 public:
287 virtual bool blendBitmap( const SalTwoRect&,
288 const SalBitmap& rBitmap ) override;
290 virtual bool blendAlphaBitmap( const SalTwoRect&,
291 const SalBitmap& rSrcBitmap,
292 const SalBitmap& rMaskBitmap,
293 const SalBitmap& rAlphaBitmap ) override;
295 virtual bool drawAlphaBitmap( const SalTwoRect&,
296 const SalBitmap& rSourceBitmap,
297 const SalBitmap& rAlphaBitmap ) override;
298 virtual bool drawTransformedBitmap(
299 const basegfx::B2DPoint& rNull,
300 const basegfx::B2DPoint& rX,
301 const basegfx::B2DPoint& rY,
302 const SalBitmap& rSourceBitmap,
303 const SalBitmap* pAlphaBitmap,
304 double fAlpha) override;
306 virtual bool hasFastDrawTransformedBitmap() const override;
308 virtual bool drawAlphaRect( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency ) override;
310 private:
311 // local helpers
313 void DrawTextLayout(const GenericSalLayout&, HDC, bool bUseDWrite, bool bRenderingModeNatural);
315 public:
316 // public SalGraphics methods, the interface to the independent vcl part
318 // get device resolution
319 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
320 // get the depth of the device
321 virtual sal_uInt16 GetBitCount() const override;
322 // get the width of the device
323 virtual tools::Long GetGraphicsWidth() const override;
325 // set the clip region to empty
326 virtual void ResetClipRegion() override;
328 // set the line color to transparent (= don't draw lines)
329 virtual void SetLineColor() override;
330 // set the line color to a specific color
331 virtual void SetLineColor( Color nColor ) override;
332 // set the fill color to transparent (= don't fill)
333 virtual void SetFillColor() override;
334 // set the fill color to a specific color, shapes will be
335 // filled accordingly
336 virtual void SetFillColor( Color nColor ) override;
337 // enable/disable XOR drawing
338 virtual void SetXORMode( bool bSet, bool ) override;
339 // set line color for raster operations
340 virtual void SetROPLineColor( SalROPColor nROPColor ) override;
341 // set fill color for raster operations
342 virtual void SetROPFillColor( SalROPColor nROPColor ) override;
343 // set the text color to a specific color
344 virtual void SetTextColor( Color nColor ) override;
345 // set the font
346 virtual void SetFont( LogicalFontInstance*, int nFallbackLevel ) override;
347 // get the current font's metrics
348 virtual void GetFontMetric( FontMetricDataRef&, int nFallbackLevel ) override;
349 // get the repertoire of the current font
350 virtual FontCharMapRef GetFontCharMap() const override;
351 // get the layout capabilities of the current font
352 virtual bool GetFontCapabilities(vcl::FontCapabilities &rGetFontCapabilities) const override;
353 // graphics must fill supplied font list
354 virtual void GetDevFontList( vcl::font::PhysicalFontCollection* ) override;
355 // graphics must drop any cached font info
356 virtual void ClearDevFontCache() override;
357 virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
359 virtual std::unique_ptr<GenericSalLayout>
360 GetTextLayout(int nFallbackLevel) override;
361 virtual void DrawTextLayout( const GenericSalLayout& ) override;
363 virtual bool supportsOperation( OutDevSupportType ) const override;
365 virtual SystemGraphicsData GetGraphicsData() const override;
367 /// Update settings based on the platform values
368 static void updateSettingsNative( AllSettings& rSettings );
371 // Init/Deinit Graphics
372 void ImplUpdateSysColorEntries();
373 int ImplIsSysColorEntry( Color nColor );
374 void ImplGetLogFontFromFontSelect( const vcl::font::FontSelectPattern&,
375 const vcl::font::PhysicalFontFace*, LOGFONTW&, bool bAntiAliased);
377 #define MAX_64KSALPOINTS ((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */