LibreOffice Module vcl (master)  1
win/saldata.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_INC_WIN_SALDATA_HXX
21 #define INCLUDED_VCL_INC_WIN_SALDATA_HXX
22 
23 #include <config_features.h>
24 
25 #include <memory>
26 #include <osl/module.h>
27 
28 #include <svdata.hxx>
29 #include <salwtype.hxx>
30 
31 #include <systools/win32/comtools.hxx>
32 #include <tools/long.hxx>
33 
34 #include <win/wincomp.hxx>
35 
36 #include <set>
37 #include <map>
38 
39 class AutoTimer;
40 class WinSalInstance;
41 class WinSalObject;
42 class WinSalFrame;
44 class WinSalPrinter;
45 namespace vcl { class Font; }
46 struct HDCCache;
47 struct TempFontItem;
48 class TextOutRenderer;
49 #if HAVE_FEATURE_SKIA
50 class SkiaControlsCache;
51 #endif
52 
53 #define MAX_STOCKPEN 4
54 #define MAX_STOCKBRUSH 4
55 #define SAL_CLIPRECT_COUNT 16
56 
57 struct SalIcon
58 {
59  int nId;
60  HICON hIcon;
61  HICON hSmallIcon;
63 };
64 
65 class SalData : public sal::systools::CoInitializeGuard
66 {
67 public:
68  SalData();
69  ~SalData();
70 
71  // native widget framework
72  static void initNWF();
73  static void deInitNWF();
74 
75  // fill maVKMap;
76  void initKeyCodeMap();
77 
78  // checks if the menuhandle was created by VCL
79  bool IsKnownMenuHandle( HMENU hMenu );
80 
82 
83 public:
84  HINSTANCE mhInst; // default instance handle
85  int mnCmdShow; // default frame show style
86  HPALETTE mhDitherPal; // dither palette
87  HGLOBAL mhDitherDIB; // dither memory handle
88  BYTE* mpDitherDIB; // dither memory
89  BYTE* mpDitherDIBData; // beginning of DIB data
90  tools::Long* mpDitherDiff; // Dither mapping table
91  BYTE* mpDitherLow; // Dither mapping table
92  BYTE* mpDitherHigh; // Dither mapping table
93  HHOOK mhSalObjMsgHook; // hook to get interesting msg for SalObject
94  HWND mhWantLeaveMsg; // window handle, that want a MOUSELEAVE message
95  AutoTimer* mpMouseLeaveTimer; // Timer for MouseLeave Test
97  WinSalFrame* mpFirstFrame; // pointer of first frame
98  WinSalObject* mpFirstObject; // pointer of first object window
99  WinSalVirtualDevice* mpFirstVD; // first VirDev
100  WinSalPrinter* mpFirstPrinter; // first printing printer
101  HDCCache* mpHDCCache; // Cache for three DC's
102  HBITMAP mh50Bmp; // 50% Bitmap
103  HBRUSH mh50Brush; // 50% Brush
108  sal_uInt16 mnStockPenCount; // count of static pens
109  sal_uInt16 mnStockBrushCount; // count of static brushes
110  WPARAM mnSalObjWantKeyEvt; // KeyEvent that should be processed by SalObj-Hook
111  BYTE mnCacheDCInUse; // count of CacheDC in use
112  bool mbObjClassInit; // is SALOBJECTCLASS initialised
113  bool mbInPalChange; // is in WM_QUERYNEWPALETTE
114  DWORD mnAppThreadId; // Id from Application-Thread
115  BOOL mbScrSvrEnabled; // ScreenSaver enabled
116  SalIcon* mpFirstIcon; // icon cache, points to first icon, NULL if none
117  TempFontItem* mpSharedTempFontItem; // LibreOffice shared fonts
118  TempFontItem* mpOtherTempFontItem; // other temporary fonts (embedded?)
119  bool mbThemeChanged; // true if visual theme was changed: throw away theme handles
121 
122  // for GdiPlus GdiplusStartup/GdiplusShutdown
123  ULONG_PTR gdiplusToken;
124 
125  std::set< HMENU > mhMenuSet; // keeps track of menu handles created by VCL, used by IsKnownMenuHandle()
126  std::map< UINT,sal_uInt16 > maVKMap; // map some dynamic VK_* entries
127 
128  std::unique_ptr<TextOutRenderer> m_pD2DWriteTextOutRenderer;
129  // tdf#107205 need 2 instances because D2DWrite can't rotate text
130  std::unique_ptr<TextOutRenderer> m_pExTextOutRenderer;
131 #if HAVE_FEATURE_SKIA
132  std::unique_ptr<SkiaControlsCache> m_pSkiaControlsCache;
133 #endif
134 };
135 
137 {
138  HINSTANCE mhInst; // Instance of SAL-DLL
139  UINT mnWheelScrollLines; // WheelScrollLines
140  UINT mnWheelScrollChars; // WheelScrollChars
141 };
142 
143 extern SalShlData aSalShlData;
144 
145 #define CACHESIZE_HDC 3
146 #define CACHED_HDC_1 0
147 #define CACHED_HDC_2 1
148 #define CACHED_HDC_DRAW 2
149 #define CACHED_HDC_DEFEXT 64
150 
151 struct HDCCache
152 {
153  HDC mhDC;
154  HPALETTE mhDefPal;
155  HBITMAP mhDefBmp;
156  HBITMAP mhSelBmp;
157  HBITMAP mhActBmp;
158 };
159 
160 void ImplClearHDCCache( SalData* pData );
161 HDC ImplGetCachedDC( sal_uLong nID, HBITMAP hBmp = nullptr );
162 void ImplReleaseCachedDC( sal_uLong nID );
163 
164 void ImplReleaseTempFonts(SalData&, bool bAll);
165 
166 HCURSOR ImplLoadSalCursor( int nId );
167 HBITMAP ImplLoadSalBitmap( int nId );
168 bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon );
169 
170 void ImplInitSalGDI();
171 void ImplFreeSalGDI();
172 
173 void ImplSalYieldMutexAcquireWithWait( sal_uInt32 nCount = 1 );
176 
177 LRESULT CALLBACK SalFrameWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
178 
179 void SalTestMouseLeave();
180 
181 bool ImplHandleSalObjKeyMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
182 bool ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam );
183 bool ImplHandleGlobalMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& rlResult );
184 
185 WinSalObject* ImplFindSalObject( HWND hWndChild );
186 bool ImplSalPreDispatchMsg( const MSG* pMsg );
187 void ImplSalPostDispatchMsg( const MSG* pMsg );
188 
189 void ImplSalLogFontToFontW( HDC hDC, const LOGFONTW& rLogFont, vcl::Font& rFont );
190 
191 rtl_TextEncoding ImplSalGetSystemEncoding();
192 OUString ImplSalGetUniString(const char* pStr, sal_Int32 nLen = -1);
193 int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 );
194 
195 #define SAL_FRAME_WNDEXTRA sizeof( DWORD )
196 #define SAL_FRAME_THIS GWLP_USERDATA
197 #define SAL_FRAME_CLASSNAMEW L"SALFRAME"
198 #define SAL_SUBFRAME_CLASSNAMEW L"SALSUBFRAME"
199 #define SAL_TMPSUBFRAME_CLASSNAMEW L"SALTMPSUBFRAME"
200 #define SAL_OBJECT_WNDEXTRA sizeof( DWORD )
201 #define SAL_OBJECT_THIS GWLP_USERDATA
202 #define SAL_OBJECT_CLASSNAMEW L"SALOBJECT"
203 #define SAL_OBJECT_CHILDCLASSNAMEW L"SALOBJECTCHILD"
204 #define SAL_COM_CLASSNAMEW L"SALCOMWND"
205 
206 #define SAL_MOUSELEAVE_TIMEOUT 300
207 
208 // wParam == bWait; lParam == 0
209 #define SAL_MSG_THREADYIELD (WM_USER+111)
210 // wParam == 0; lParam == nMS
211 #define SAL_MSG_STARTTIMER (WM_USER+113)
212 // wParam == nFrameStyle; lParam == pParent; lResult == pFrame
213 #define SAL_MSG_CREATEFRAME (WM_USER+114)
214 // wParam == 0; lParam == 0
215 #define SAL_MSG_DESTROYFRAME (WM_USER+115)
216 // wParam == 0; lParam == pParent; lResult == pObject
217 #define SAL_MSG_CREATEOBJECT (WM_USER+116)
218 // wParam == 0; lParam == pObject;
219 #define SAL_MSG_DESTROYOBJECT (WM_USER+117)
220 // wParam == hWnd; lParam == 0; lResult == hDC
221 #define SAL_MSG_GETCACHEDDC (WM_USER+120)
222 // wParam == hWnd; lParam == 0
223 #define SAL_MSG_RELEASEDC (WM_USER+121)
224 // wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
225 #define SAL_MSG_RECREATEHWND (WM_USER+122)
226 // wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
227 #define SAL_MSG_RECREATECHILDHWND (WM_USER+123)
228 // wParam == 0; lParam == HWND;
229 #define SAL_MSG_DESTROYHWND (WM_USER+124)
230 
231 // wParam == 0; lParam == pData
232 #define SAL_MSG_USEREVENT (WM_USER+130)
233 // wParam == 0; lParam == MousePosition relative to upper left of screen
234 #define SAL_MSG_MOUSELEAVE (WM_USER+131)
235 // NULL-Message, should not be processed
236 #define SAL_MSG_DUMMY (WM_USER+132)
237 // Used for SETFOCUS and KILLFOCUS
238 // wParam == 0; lParam == 0
239 #define SAL_MSG_POSTFOCUS (WM_USER+133)
240 // wParam == wParam; lParam == lParam
241 #define SAL_MSG_POSTQUERYNEWPAL (WM_USER+134)
242 // wParam == wParam; lParam == lParam
243 #define SAL_MSG_POSTPALCHANGED (WM_USER+135)
244 // wParam == wParam; lParam == lParam
245 #define SAL_MSG_POSTMOVE (WM_USER+136)
246 // wParam == wParam; lParam == lParam
247 #define SAL_MSG_POSTCALLSIZE (WM_USER+137)
248 // wParam == pRECT; lParam == 0
249 #define SAL_MSG_POSTPAINT (WM_USER+138)
250 // wParam == 0; lParam == pFrame; lResult 0
251 #define SAL_MSG_FORCEPALETTE (WM_USER+139)
252 // wParam == 0; lParam == 0
253 #define SAL_MSG_CAPTUREMOUSE (WM_USER+140)
254 // wParam == 0; lParam == 0
255 #define SAL_MSG_RELEASEMOUSE (WM_USER+141)
256 // wParam == nFlags; lParam == 0
257 #define SAL_MSG_TOTOP (WM_USER+142)
258 // wParam == bVisible; lParam == 0
259 #define SAL_MSG_SHOW (WM_USER+143)
260 // wParam == 0; lParam == SalInputContext
261 #define SAL_MSG_SETINPUTCONTEXT (WM_USER+144)
262 // wParam == nFlags; lParam == 0
263 #define SAL_MSG_ENDEXTTEXTINPUT (WM_USER+145)
264 
265 // SysChild-ToTop; wParam = 0; lParam = 0
266 #define SALOBJ_MSG_TOTOP (WM_USER+160)
267 // Used for SETFOCUS and KILLFOCUS
268 // POSTFOCUS-Message; wParam == bFocus; lParam == 0
269 #define SALOBJ_MSG_POSTFOCUS (WM_USER+161)
270 
271 // Call the Timer's callback from the main thread
272 // wParam = 1 == run when yield is idle instead of direct
273 #define SAL_MSG_TIMER_CALLBACK (WM_USER+162)
274 // Stop the timer from the main thread; wParam = 0, lParam = 0
275 #define SAL_MSG_STOPTIMER (WM_USER+163)
276 // Start a real timer while GUI is blocked by native dialog
277 #define SAL_MSG_FORCE_REAL_TIMER (WM_USER+164)
278 
279 inline void SetWindowPtr( HWND hWnd, WinSalFrame* pThis )
280 {
281  SetWindowLongPtrW( hWnd, SAL_FRAME_THIS, reinterpret_cast<LONG_PTR>(pThis) );
282 }
283 
284 inline WinSalFrame* GetWindowPtr( HWND hWnd )
285 {
286  return reinterpret_cast<WinSalFrame*>(GetWindowLongPtrW( hWnd, SAL_FRAME_THIS ));
287 }
288 
289 inline void SetSalObjWindowPtr( HWND hWnd, WinSalObject* pThis )
290 {
291  SetWindowLongPtrW( hWnd, SAL_OBJECT_THIS, reinterpret_cast<LONG_PTR>(pThis) );
292 }
293 
294 inline WinSalObject* GetSalObjWindowPtr( HWND hWnd )
295 {
296  return reinterpret_cast<WinSalObject*>(GetWindowLongPtrW( hWnd, SAL_OBJECT_THIS ));
297 }
298 
299 #endif // INCLUDED_VCL_INC_WIN_SALDATA_HXX
300 
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbThemeMenuSupport
std::map< UINT, sal_uInt16 > maVKMap
HBITMAP mh50Bmp
bool ImplHandleGlobalMsg(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT &rlResult)
HBITMAP mhActBmp
unsigned char BYTE
std::unique_ptr< TextOutRenderer > m_pExTextOutRenderer
void SalTestMouseLeave()
TempFontItem * mpSharedTempFontItem
sal_uIntPtr sal_uLong
long Long
HBRUSH mh50Brush
bool IsKnownMenuHandle(HMENU hMenu)
BYTE * mpDitherDIB
Definition: win/saldata.hxx:88
WinSalPrinter * mpFirstPrinter
void ImplSalLogFontToFontW(HDC hDC, const LOGFONTW &rLogFont, vcl::Font &rFont)
DWORD mnAppThreadId
void ImplSalYieldMutexAcquireWithWait(sal_uInt32 nCount=1)
bool ImplHandleSalObjSysCharMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)
HICON hIcon
Definition: win/saldata.hxx:60
COLORREF maStockBrushColorAry[MAX_STOCKBRUSH]
bool ImplLoadSalIcon(int nId, HICON &rIcon, HICON &rSmallIcon)
const wchar_t *typedef BOOL
void ImplSalPostDispatchMsg(const MSG *pMsg)
#define MAX_STOCKPEN
Definition: win/saldata.hxx:53
void ImplSalYieldMutexRelease()
HHOOK mhSalObjMsgHook
Definition: win/saldata.hxx:93
An auto-timer is a multi-shot timer re-emitting itself at interval until destroyed or stopped...
Definition: timer.hxx:66
static void initNWF()
UINT mnWheelScrollChars
HWND mhWantLeaveMsg
Definition: win/saldata.hxx:94
BYTE * mpDitherHigh
Definition: win/saldata.hxx:92
void SetWindowPtr(HWND hWnd, WinSalFrame *pThis)
bool ImplSalPreDispatchMsg(const MSG *pMsg)
WinSalFrame * mpFirstFrame
Definition: win/saldata.hxx:97
tools::Long * mpDitherDiff
Definition: win/saldata.hxx:90
bool mbThemeChanged
HBITMAP mhDefBmp
#define MAX_STOCKBRUSH
Definition: win/saldata.hxx:54
void ImplFreeSalGDI()
std::set< HMENU > mhMenuSet
void ImplReleaseCachedDC(sal_uLong nID)
HBITMAP ImplLoadSalBitmap(int nId)
#define SAL_OBJECT_THIS
bool mbObjClassInit
bool mbInPalChange
ULONG_PTR gdiplusToken
HPALETTE mhDefPal
HBITMAP mhSelBmp
BYTE * mpDitherDIBData
Definition: win/saldata.hxx:89
HBRUSH mhStockBrushAry[MAX_STOCKBRUSH]
sal_uInt16 mnStockPenCount
static void deInitNWF()
WinSalVirtualDevice * mpFirstVD
Definition: win/saldata.hxx:99
void ImplReleaseTempFonts(SalData &, bool bAll)
HCURSOR ImplLoadSalCursor(int nId)
BOOL mbScrSvrEnabled
WinSalFrame * GetWindowPtr(HWND hWnd)
HINSTANCE mhInst
Definition: win/saldata.hxx:84
HINSTANCE mhInst
HPEN mhStockPenAry[MAX_STOCKPEN]
TempFontItem * mpOtherTempFontItem
#define SAL_FRAME_THIS
int ImplSalWICompareAscii(const wchar_t *pStr1, const char *pStr2)
BYTE mnCacheDCInUse
LRESULT CALLBACK SalFrameWndProcW(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
void ImplClearHDCCache(SalData *pData)
SalIcon * pNext
Definition: win/saldata.hxx:62
HGLOBAL mhDitherDIB
Definition: win/saldata.hxx:87
sal_uInt16 mnStockBrushCount
bool ImplSalYieldMutexTryToAcquire()
void ImplInitSalGDI()
WinSalObject * ImplFindSalObject(HWND hWndChild)
WinSalInstance * mpInstance
Definition: win/saldata.hxx:96
SalShlData aSalShlData
rtl_TextEncoding ImplSalGetSystemEncoding()
COLORREF maStockPenColorAry[MAX_STOCKPEN]
HDCCache * mpHDCCache
WinSalObject * GetSalObjWindowPtr(HWND hWnd)
#define CALLBACK
HDC ImplGetCachedDC(sal_uLong nID, HBITMAP hBmp=nullptr)
AutoTimer * mpMouseLeaveTimer
Definition: win/saldata.hxx:95
bool mbResourcesAlreadyFreed
Definition: win/saldata.hxx:81
SalIcon * mpFirstIcon
std::unique_ptr< TextOutRenderer > m_pD2DWriteTextOutRenderer
bool ImplHandleSalObjKeyMsg(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
int mnCmdShow
Definition: win/saldata.hxx:85
BYTE * mpDitherLow
Definition: win/saldata.hxx:91
OUString ImplSalGetUniString(const char *pStr, sal_Int32 nLen=-1)
HPALETTE mhDitherPal
Definition: win/saldata.hxx:86
UINT mnWheelScrollLines
WPARAM mnSalObjWantKeyEvt
void SetSalObjWindowPtr(HWND hWnd, WinSalObject *pThis)
WinSalObject * mpFirstObject
Definition: win/saldata.hxx:98
HICON hSmallIcon
Definition: win/saldata.hxx:61
void initKeyCodeMap()