xref: /aoo42x/main/vcl/inc/win/saldata.hxx (revision 67e470da)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_SALDATA_HXX
25 #define _SV_SALDATA_HXX
26 
27 #include "osl/module.h"
28 
29 #include <svdata.hxx>
30 #include <salwtype.hxx>
31 
32 #include <win/wincomp.hxx>
33 
34 #include <set>  // for hMenu validation
35 #include <map>
36 
37 class AutoTimer;
38 class WinSalInstance;
39 class WinSalObject;
40 class WinSalFrame;
41 class WinSalVirtualDevice;
42 class WinSalPrinter;
43 class Font;
44 struct HDCCache;
45 struct TempFontItem;
46 
47 typedef HRESULT (WINAPI  *DwmIsCompositionEnabled_ptr)(BOOL*);
48 
49 // --------------------
50 // - Standard-Defines -
51 // --------------------
52 
53 #define MAX_STOCKPEN            4
54 #define MAX_STOCKBRUSH          4
55 #define SAL_CLIPRECT_COUNT      16
56 
57 // --------------------
58 // - Icon cache       -
59 // --------------------
60 
61 struct SalIcon
62 {
63     int     nId;
64     HICON   hIcon;
65     HICON   hSmallIcon;
66     SalIcon *pNext;
67 };
68 
69 // -----------
70 // - SalData -
71 // -----------
72 
73 class SalData
74 {
75 public:
76     SalData();
77     ~SalData();
78 
79     // native widget framework
80     void    initNWF();
81     void    deInitNWF();
82 
83     // fill maVKMap;
84     void initKeyCodeMap();
85 
86     // checks if the menuhandle was created by VCL
87     sal_Bool    IsKnownMenuHandle( HMENU hMenu );
88 
89 public:
90     HINSTANCE               mhInst;                 // default instance handle
91     HINSTANCE               mhPrevInst;             // previous instance handle
92     int                     mnCmdShow;              // default frame show style
93     HPALETTE                mhDitherPal;            // dither palette
94     HGLOBAL                 mhDitherDIB;            // dither memory handle
95     BYTE*                   mpDitherDIB;            // dither memory
96     BYTE*                   mpDitherDIBData;        // beginning of DIB data
97     long*                   mpDitherDiff;           // Dither mapping table
98     BYTE*                   mpDitherLow;            // Dither mapping table
99     BYTE*                   mpDitherHigh;           // Dither mapping table
100     sal_uLong                   mnTimerMS;              // Current Time (in MS) of the Timer
101     sal_uLong                   mnTimerOrgMS;           // Current Original Time (in MS)
102 	DWORD					mnNextTimerTime;
103 	DWORD					mnLastEventTime;
104     UINT                    mnTimerId;              // windows timer id
105     sal_Bool                    mbInTimerProc;          // timer event is currently being dispatched
106     HHOOK                   mhSalObjMsgHook;        // hook to get interesting msg for SalObject
107     HWND                    mhWantLeaveMsg;         // window handle, that want a MOUSELEAVE message
108     AutoTimer*              mpMouseLeaveTimer;      // Timer for MouseLeave Test
109     WinSalInstance*         mpFirstInstance;        // pointer of first instance
110     WinSalFrame*            mpFirstFrame;           // pointer of first frame
111     WinSalObject*           mpFirstObject;          // pointer of first object window
112     WinSalVirtualDevice*    mpFirstVD;              // first VirDev
113     WinSalPrinter*          mpFirstPrinter;         // first printing printer
114     HDCCache*               mpHDCCache;             // Cache for three DC's
115     HBITMAP                 mh50Bmp;                // 50% Bitmap
116     HBRUSH                  mh50Brush;              // 50% Brush
117     COLORREF                maStockPenColorAry[MAX_STOCKPEN];
118     COLORREF                maStockBrushColorAry[MAX_STOCKBRUSH];
119     HPEN                    mhStockPenAry[MAX_STOCKPEN];
120     HBRUSH                  mhStockBrushAry[MAX_STOCKBRUSH];
121     sal_uInt16                  mnStockPenCount;        // count of static pens
122     sal_uInt16                  mnStockBrushCount;      // count of static brushes
123     WPARAM                  mnSalObjWantKeyEvt;     // KeyEvent, welcher vom SalObj-Hook verarbeitet werden soll
124     BYTE                    mnCacheDCInUse;         // count of CacheDC in use
125     sal_Bool                    mbObjClassInit;         // is SALOBJECTCLASS initialised
126     sal_Bool                    mbInPalChange;          // is in WM_QUERYNEWPALETTE
127     DWORD                   mnAppThreadId;          // Id from Applikation-Thread
128     BOOL                mbScrSvrEnabled;        // ScreenSaver enabled
129     int                     mnSageStatus;           // status of Sage-DLL (DISABLE_AGENT == nicht vorhanden)
130     SysAgt_Enable_PROC      mpSageEnableProc;       // funktion to deactivate the system agent
131     SalIcon*                mpFirstIcon;            // icon cache, points to first icon, NULL if none
132     TempFontItem*           mpTempFontItem;
133     sal_Bool                mbThemeChanged;         // true if visual theme was changed: throw away theme handles
134     sal_Bool                mbThemeMenuSupport;
135 
136     // for GdiPlus GdiplusStartup/GdiplusShutdown
137     ULONG_PTR               gdiplusToken;
138 
139     std::set< HMENU >       mhMenuSet;              // keeps track of menu handles created by VCL, used by IsKnownMenuHandle()
140     std::map< UINT,USHORT > maVKMap;      // map some dynamic VK_* entries
141     oslModule               maDwmLib;
142     DwmIsCompositionEnabled_ptr mpDwmIsCompositionEnabled;
143 };
144 
SetSalData(SalData * pData)145 inline void SetSalData( SalData* pData ) { ImplGetSVData()->mpSalData = (void*)pData; }
GetSalData()146 inline SalData* GetSalData() { return (SalData*)ImplGetSVData()->mpSalData; }
GetAppSalData()147 inline SalData* GetAppSalData() { return (SalData*)ImplGetAppSVData()->mpSalData; }
148 
149 // --------------
150 // - SalShlData -
151 // --------------
152 
153 struct SalShlData
154 {
155     HINSTANCE               mhInst;                 // Instance of SAL-DLL
156     UINT                    mnWheelScrollLines;     // WheelScrollLines
157     UINT                    mnWheelScrollChars;     // WheelScrollChars
158     UINT                    mnWheelMsgId;           // Wheel-Message-Id fuer W95
159     WORD                    mnVersion;              // System-Version (311 == 3.11)
160     BOOL                    mbW40;                  // Is System-Version >= 4.0
161     BOOL                    mbWXP;                  // Windows XP
162     BOOL                    mbWPrinter;             // true: use unicode printer functions
163                                                     // false: use anis compat printer functions
164     OSVERSIONINFO           maVersionInfo;
165 };
166 
167 extern SalShlData aSalShlData;
168 
169 // ------------
170 // - GDICache -
171 // ------------
172 
173 #define CACHESIZE_HDC       3
174 #define CACHED_HDC_1        0
175 #define CACHED_HDC_2        1
176 #define CACHED_HDC_DRAW     2
177 #define CACHED_HDC_DEFEXT   64
178 
179 struct HDCCache
180 {
181     HDC         mhDC;
182     HPALETTE    mhDefPal;
183     HBITMAP     mhDefBmp;
184     HBITMAP     mhSelBmp;
185     HBITMAP     mhActBmp;
186 };
187 
188 void ImplClearHDCCache( SalData* pData );
189 HDC ImplGetCachedDC( sal_uLong nID, HBITMAP hBmp = 0 );
190 void ImplReleaseCachedDC( sal_uLong nID );
191 
192 bool ImplAddTempFont( SalData&, const String& rFontFileURL );
193 void ImplReleaseTempFonts( SalData& );
194 
195 // --------------------------------------------
196 // - SALSHL.CXX - for accessing DLL resources -
197 // --------------------------------------------
198 
199 HCURSOR ImplLoadSalCursor( int nId );
200 HBITMAP ImplLoadSalBitmap( int nId );
201 sal_Bool ImplLoadSalIcon( int nId, HICON& rIcon, HICON& rSmallIcon );
202 
203 // SALGDI.CXX
204 void ImplInitSalGDI();
205 void ImplFreeSalGDI();
206 
207 // --------------
208 // - Prototypes -
209 // --------------
210 
211 // \\WIN\SOURCE\APP\SALINST.CXX
212 void ImplSalYieldMutexAcquireWithWait();
213 sal_Bool ImplSalYieldMutexTryToAcquire();
214 void ImplSalYieldMutexAcquire();
215 void ImplSalYieldMutexRelease();
216 sal_uLong ImplSalReleaseYieldMutex();
217 void ImplSalAcquireYieldMutex( sal_uLong nCount );
218 sal_Bool ImplInterceptChildWindowKeyDown( MSG& rMsg );
219 
220 // \\WIN\SOURCE\WINDOW\SALFRAME.CXX
221 LRESULT CALLBACK SalFrameWndProcA( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
222 LRESULT CALLBACK SalFrameWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
223 // \SV\WIN\SOURCE\APP\SALTIMER.CXX
224 #define SALTIMERPROC_RECURSIVE 0xffffffff
225 void    CALLBACK SalTimerProc( HWND hWnd, UINT nMsg, UINT_PTR nId, DWORD nTime );
226 
227 // \WIN\SOURCE\WINDOW\SALFRAME.CXX
228 void SalTestMouseLeave();
229 sal_Bool ImplWriteLastError( DWORD lastError, const char *szApiCall );
230 
231 // \WIN\SOURCE\WINDOW\SALFRAME.CXX
232 long ImplHandleSalObjKeyMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam );
233 long ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam );
234 sal_Bool ImplHandleGlobalMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& rlResult );
235 
236 // \WIN\SOURCE\WINDOW\SALOBJ.CXX
237 WinSalObject* ImplFindSalObject( HWND hWndChild );
238 sal_Bool ImplSalPreDispatchMsg( MSG* pMsg );
239 void ImplSalPostDispatchMsg( MSG* pMsg, LRESULT nDispatchResult );
240 
241 // \WIN\SOURCE\GDI\SALGDI3.CXX
242 void ImplSalLogFontToFontA( HDC hDC, const LOGFONTA& rLogFont, Font& rFont );
243 void ImplSalLogFontToFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont );
244 bool ImplIsFontAvailable( HDC hDC, const UniString& rName );
245 
246 // \WIN\SOURCE\APP\SALDATA.CXX
247 rtl_TextEncoding ImplSalGetSystemEncoding();
248 ByteString ImplSalGetWinAnsiString( const UniString& rStr, sal_Bool bFileName = FALSE );
249 UniString ImplSalGetUniString( const sal_Char* pStr, xub_StrLen nLen = STRING_LEN );
250 int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 );
251 
252 // -----------
253 // - Defines -
254 // -----------
255 
256 #define SAL_FRAME_WNDEXTRA          sizeof( DWORD )
257 #define SAL_FRAME_THIS              0
258 #define SAL_FRAME_CLASSNAMEA        "SALFRAME"
259 #define SAL_FRAME_CLASSNAMEW        L"SALFRAME"
260 #define SAL_SUBFRAME_CLASSNAMEA     "SALSUBFRAME"
261 #define SAL_SUBFRAME_CLASSNAMEW     L"SALSUBFRAME"
262 #define SAL_TMPSUBFRAME_CLASSNAMEW  L"SALTMPSUBFRAME"
263 #define SAL_OBJECT_WNDEXTRA         sizeof( DWORD )
264 #define SAL_OBJECT_THIS             0
265 #define SAL_OBJECT_CLASSNAMEA       "SALOBJECT"
266 #define SAL_OBJECT_CLASSNAMEW       L"SALOBJECT"
267 #define SAL_OBJECT_CHILDCLASSNAMEA  "SALOBJECTCHILD"
268 #define SAL_OBJECT_CHILDCLASSNAMEW  L"SALOBJECTCHILD"
269 #define SAL_COM_CLASSNAMEA          "SALCOMWND"
270 #define SAL_COM_CLASSNAMEW          L"SALCOMWND"
271 
272 #define SAL_MOUSELEAVE_TIMEOUT      300
273 
274 // wParam == hDC; lParam == 0
275 #define SAL_MSG_PRINTABORTJOB       (WM_USER+110)
276 // wParam == bWait; lParam == 0
277 #define SAL_MSG_THREADYIELD         (WM_USER+111)
278 // wParam == 0; lParam == 0
279 #define SAL_MSG_RELEASEWAITYIELD    (WM_USER+112)
280 // wParam == 0; lParam == nMS
281 #define SAL_MSG_STARTTIMER          (WM_USER+113)
282 // wParam == nFrameStyle; lParam == pParent; lResult == pFrame
283 #define SAL_MSG_CREATEFRAME         (WM_USER+114)
284 // wParam == 0; lParam == 0
285 #define SAL_MSG_DESTROYFRAME        (WM_USER+115)
286 // wParam == 0; lParam == pParent; lResult == pObject
287 #define SAL_MSG_CREATEOBJECT        (WM_USER+116)
288 // wParam == 0; lParam == pObject;
289 #define SAL_MSG_DESTROYOBJECT       (WM_USER+117)
290 // wParam == hWnd; lParam == 0; lResult == hDC
291 #define SAL_MSG_GETDC               (WM_USER+120)
292 // wParam == hWnd; lParam == 0
293 #define SAL_MSG_RELEASEDC           (WM_USER+121)
294 // wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
295 #define SAL_MSG_RECREATEHWND         (WM_USER+122)
296 // wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
297 #define SAL_MSG_RECREATECHILDHWND    (WM_USER+123)
298 // wParam == 0; lParam == HWND;
299 #define SAL_MSG_DESTROYHWND         (WM_USER+124)
300 
301 // wParam == 0; lParam == pData
302 #define SAL_MSG_USEREVENT           (WM_USER+130)
303 // wParam == 0; lParam == MousePosition relativ to upper left of screen
304 #define SAL_MSG_MOUSELEAVE          (WM_USER+131)
305 // NULL-Message, soll nicht verarbeitet werden
306 #define SAL_MSG_DUMMY               (WM_USER+132)
307 // wParam == 0; lParam == 0
308 #define SAL_MSG_POSTFOCUS           (WM_USER+133)
309 // wParam == wParam; lParam == lParam
310 #define SAL_MSG_POSTQUERYNEWPAL     (WM_USER+134)
311 // wParam == wParam; lParam == lParam
312 #define SAL_MSG_POSTPALCHANGED      (WM_USER+135)
313 // wParam == wParam; lParam == lParam
314 #define SAL_MSG_POSTMOVE            (WM_USER+136)
315 // wParam == wParam; lParam == lParam
316 #define SAL_MSG_POSTCALLSIZE        (WM_USER+137)
317 // wParam == pRECT; lParam == 0
318 #define SAL_MSG_POSTPAINT           (WM_USER+138)
319 // wParam == 0; lParam == pFrame; lResult 0
320 #define SAL_MSG_FORCEPALETTE        (WM_USER+139)
321 // wParam == 0; lParam == 0
322 #define SAL_MSG_CAPTUREMOUSE        (WM_USER+140)
323 // wParam == 0; lParam == 0
324 #define SAL_MSG_RELEASEMOUSE        (WM_USER+141)
325 // wParam == nFlags; lParam == 0
326 #define SAL_MSG_TOTOP               (WM_USER+142)
327 // wParam == bVisible; lParam == 0
328 #define SAL_MSG_SHOW                (WM_USER+143)
329 // wParam == 0; lParam == SalInputContext
330 #define SAL_MSG_SETINPUTCONTEXT     (WM_USER+144)
331 // wParam == nFlags; lParam == 0
332 #define SAL_MSG_ENDEXTTEXTINPUT     (WM_USER+145)
333 // POSTTIMER-Message; wparam = 0, lParam == time
334 #define SAL_MSG_POSTTIMER        (WM_USER+161)
335 
336 // SysChild-ToTop; wParam = 0; lParam = 0
337 #define SALOBJ_MSG_TOTOP            (WM_USER+160)
338 // POSTFOCUS-Message; wParam == bFocus; lParam == 0
339 #define SALOBJ_MSG_POSTFOCUS        (WM_USER+161)
340 
341 
342 // -----------------
343 // - Helpfunctions -
344 // -----------------
345 
346 // A/W-Wrapper
347 LONG        ImplSetWindowLong( HWND hWnd, int nIndex, DWORD dwNewLong );
348 LONG        ImplGetWindowLong( HWND hWnd, int nIndex );
349 BOOL    ImplPostMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
350 BOOL    ImplSendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
351 BOOL    ImplGetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax );
352 BOOL    ImplPeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg );
353 LONG        ImplDispatchMessage( CONST MSG *lpMsg );
354 
SetWindowPtr(HWND hWnd,WinSalFrame * pThis)355 inline void SetWindowPtr( HWND hWnd, WinSalFrame* pThis )
356 {
357     ImplSetWindowLong( hWnd, SAL_FRAME_THIS, (LONG)pThis );
358 }
359 
GetWindowPtr(HWND hWnd)360 inline WinSalFrame* GetWindowPtr( HWND hWnd )
361 {
362     return (WinSalFrame*)ImplGetWindowLong( hWnd, SAL_FRAME_THIS );
363 }
364 
SetSalObjWindowPtr(HWND hWnd,WinSalObject * pThis)365 inline void SetSalObjWindowPtr( HWND hWnd, WinSalObject* pThis )
366 {
367     ImplSetWindowLong( hWnd, SAL_OBJECT_THIS, (LONG)pThis );
368 }
369 
GetSalObjWindowPtr(HWND hWnd)370 inline WinSalObject* GetSalObjWindowPtr( HWND hWnd )
371 {
372     return (WinSalObject*)ImplGetWindowLong( hWnd, SAL_OBJECT_THIS );
373 }
374 
375 #endif  // _SV_SALDATA_HXX
376