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