Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_SALDISP_HXX
30 : : #define _SV_SALDISP_HXX
31 : :
32 : : // -=-= exports =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
33 : : class SalDisplay;
34 : : class SalColormap;
35 : : class SalVisual;
36 : : class SalXLib;
37 : :
38 : : #include <unx/salunx.h>
39 : : #include <unx/saltype.h>
40 : : #include <vcl/salgtype.hxx>
41 : : #include <vcl/ptrstyle.hxx>
42 : : #include <sal/types.h>
43 : : #include <osl/mutex.h>
44 : : #include <vector>
45 : : #include <list>
46 : : #include <boost/unordered_map.hpp>
47 : : #include <tools/gen.hxx>
48 : : #include <salwtype.hxx>
49 : : #include <generic/gendisp.hxx>
50 : :
51 : : #include <vclpluginapi.h>
52 : :
53 : : // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
54 : : class BitmapPalette;
55 : : class SalFrame;
56 : : class ColorMask;
57 : :
58 : : namespace vcl_sal { class WMAdaptor; }
59 : :
60 : : // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
61 : : #define PROPERTY_SUPPORT_WM_Parent_Pixmap_None 0x00000004
62 : : #define PROPERTY_SUPPORT_WM_ClientPos 0x00000008
63 : : #define PROPERTY_SUPPORT_3ButtonMouse 0x00000020
64 : :
65 : : #define PROPERTY_BUG_XCopyArea_GXxor 0x00002000 // from window
66 : : #define PROPERTY_BUG_Tile 0x00008000 // Recreate the
67 : : // dither brush each time
68 : : #define PROPERTY_BUG_FillPolygon_Tile 0x00010000 // always Toggle Fillstyle
69 : : #define PROPERTY_BUG_DrawLine 0x00020000 // a DrawLine is one point to short
70 : : #define PROPERTY_BUG_Bitmap_Bit_Order 0x00100000
71 : :
72 : : #define PROPERTY_FEATURE_SharedMemory 0x02000000
73 : : #define PROPERTY_FEATURE_TrustedSolaris 0x04000000
74 : :
75 : : #define PROPERTY_DEFAULT 0x00000FCB
76 : :
77 : : // ------------------------------------------------------------------------
78 : : // server vendor
79 : :
80 : : typedef enum {
81 : : vendor_none = 0,
82 : : vendor_sun,
83 : : vendor_unknown
84 : : } srv_vendor_t;
85 : :
86 : : extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
87 : :
88 : : // -=-= SalRGB -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
89 : : // MSB/Bigendian view (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
90 : :
91 : : enum SalRGB { RGB, RBG,
92 : : GBR, GRB,
93 : : BGR, BRG,
94 : : RGBA, RBGA,
95 : : GBRA, GRBA,
96 : : BGRA, BRGA,
97 : : otherSalRGB };
98 : :
99 : : // -=-= SalVisual =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
100 : : class SalVisual : public XVisualInfo
101 : : {
102 : : SalRGB eRGBMode_;
103 : : int nRedShift_;
104 : : int nGreenShift_;
105 : : int nBlueShift_;
106 : : int nRedBits_;
107 : : int nGreenBits_;
108 : : int nBlueBits_;
109 : : public:
110 : : SalVisual();
111 : : ~SalVisual();
112 : : SalVisual( const XVisualInfo* pXVI );
113 : :
114 : 0 : inline VisualID GetVisualId() const { return visualid; }
115 : 0 : inline Visual *GetVisual() const { return visual; }
116 : 0 : inline int GetClass() const { return c_class; }
117 : 0 : inline int GetDepth() const { return depth; }
118 : : inline SalRGB GetMode() const { return eRGBMode_; }
119 : :
120 : : Pixel GetTCPixel( SalColor nColor ) const;
121 : : SalColor GetTCColor( Pixel nPixel ) const;
122 : : };
123 : :
124 : : // -=-= SalColormap =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
125 : 0 : class SalColormap
126 : : {
127 : : const SalDisplay* m_pDisplay;
128 : : Colormap m_hColormap;
129 : : std::vector<SalColor> m_aPalette; // Pseudocolor
130 : : SalVisual m_aVisual;
131 : : std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction
132 : : Pixel m_nWhitePixel;
133 : : Pixel m_nBlackPixel;
134 : : Pixel m_nUsed; // Pseudocolor
135 : : SalX11Screen m_nXScreen;
136 : :
137 : : void GetPalette();
138 : : void GetLookupTable();
139 : : public:
140 : : SalColormap( const SalDisplay* pSalDisplay,
141 : : Colormap hColormap,
142 : : SalX11Screen nXScreen );
143 : : SalColormap( sal_uInt16 nDepth );
144 : : SalColormap();
145 : : ~SalColormap();
146 : :
147 : 0 : inline Colormap GetXColormap() const { return m_hColormap; }
148 : 0 : inline const SalDisplay* GetDisplay() const { return m_pDisplay; }
149 : : inline Display* GetXDisplay() const;
150 : 0 : inline const SalVisual& GetVisual() const { return m_aVisual; }
151 : 0 : inline Visual* GetXVisual() const { return m_aVisual.GetVisual(); }
152 : 0 : inline Pixel GetWhitePixel() const { return m_nWhitePixel; }
153 : 0 : inline Pixel GetBlackPixel() const { return m_nBlackPixel; }
154 : 0 : inline Pixel GetUsed() const { return m_nUsed; }
155 : : inline int GetClass() const { return m_aVisual.GetClass(); }
156 : :
157 : : sal_Bool GetXPixels( XColor &rColor,
158 : : int r,
159 : : int g,
160 : : int b ) const;
161 : : inline sal_Bool GetXPixel( XColor &rColor,
162 : : int r,
163 : : int g,
164 : : int b ) const;
165 : : Pixel GetPixel( SalColor nColor ) const;
166 : : SalColor GetColor( Pixel nPixel ) const;
167 : : };
168 : :
169 : : // -=-= SalXLib =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
170 : : typedef int(*YieldFunc)(int fd, void* data);
171 : : struct YieldEntry;
172 : :
173 : : class VCLPLUG_GEN_PUBLIC SalXLib
174 : : {
175 : : protected:
176 : : timeval m_aTimeout;
177 : : sal_uLong m_nTimeoutMS;
178 : : int m_pTimeoutFDS[2];
179 : :
180 : : int nFDs_;
181 : : fd_set aReadFDS_;
182 : : fd_set aExceptionFDS_;
183 : : YieldEntry *pYieldEntries_;
184 : :
185 : : public:
186 : : SalXLib();
187 : : virtual ~SalXLib();
188 : : virtual void Init();
189 : :
190 : : virtual void Yield( bool bWait, bool bHandleAllCurrentEvents );
191 : : virtual void Wakeup();
192 : : virtual void PostUserEvent();
193 : :
194 : : virtual void Insert( int fd, void* data,
195 : : YieldFunc pending,
196 : : YieldFunc queued,
197 : : YieldFunc handle );
198 : : virtual void Remove( int fd );
199 : :
200 : : virtual void StartTimer( sal_uLong nMS );
201 : : virtual void StopTimer();
202 : :
203 : : bool CheckTimeout( bool bExecuteTimers = true );
204 : : };
205 : :
206 : : // -=-= SalDisplay -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
207 : :
208 : : class SalI18N_InputMethod;
209 : : class SalI18N_KeyboardExtension;
210 : : class AttributeProvider;
211 : :
212 : : extern "C" {
213 : : typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
214 : : }
215 : :
216 : : class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay
217 : : {
218 : : public:
219 : : struct RenderEntry
220 : : {
221 : : Pixmap m_aPixmap;
222 : : Picture m_aPicture;
223 : :
224 : 0 : RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
225 : : };
226 : :
227 : : typedef boost::unordered_map<int,RenderEntry> RenderEntryMap;
228 : :
229 : 0 : struct ScreenData
230 : : {
231 : : bool m_bInit;
232 : :
233 : : XLIB_Window m_aRoot;
234 : : XLIB_Window m_aRefWindow;
235 : : Size m_aSize;
236 : : SalVisual m_aVisual;
237 : : SalColormap m_aColormap;
238 : : GC m_aMonoGC;
239 : : GC m_aCopyGC;
240 : : GC m_aAndInvertedGC;
241 : : GC m_aAndGC;
242 : : GC m_aOrGC;
243 : : GC m_aStippleGC;
244 : : Pixmap m_hInvert50;
245 : : mutable RenderEntryMap m_aRenderData;
246 : :
247 : 0 : ScreenData() :
248 : : m_bInit( false ),
249 : : m_aRoot( None ),
250 : : m_aRefWindow( None ),
251 : : m_aMonoGC( None ),
252 : : m_aCopyGC( None ),
253 : : m_aAndInvertedGC( None ),
254 : : m_aAndGC( None ),
255 : : m_aOrGC( None ),
256 : : m_aStippleGC( None ),
257 : : m_hInvert50( None ),
258 : 0 : m_aRenderData( 1 )
259 : 0 : {}
260 : : };
261 : :
262 : : protected:
263 : : SalXLib *pXLib_;
264 : : SalI18N_InputMethod *mpInputMethod;
265 : : SalI18N_KeyboardExtension *mpKbdExtension;
266 : :
267 : : AttributeProvider *mpFactory;
268 : :
269 : : Display *pDisp_; // X Display
270 : :
271 : : SalX11Screen m_nXDefaultScreen;
272 : : std::vector< ScreenData > m_aScreens;
273 : : ScreenData m_aInvalidScreenData;
274 : : Pair aResolution_; // [dpi]
275 : : bool mbExactResolution;
276 : : sal_uLong nMaxRequestSize_; // [byte]
277 : :
278 : : srv_vendor_t meServerVendor;
279 : :
280 : : // until x bytes
281 : :
282 : : XLIB_Cursor aPointerCache_[POINTER_COUNT];
283 : :
284 : : // Keyboard
285 : : sal_Bool bNumLockFromXS_; // Num Lock handled by X Server
286 : : int nNumLockIndex_; // modifier index in modmap
287 : : int nNumLockMask_; // keyevent state mask for
288 : : KeySym nShiftKeySym_; // first shift modifier
289 : : KeySym nCtrlKeySym_; // first control modifier
290 : : KeySym nMod1KeySym_; // first mod1 modifier
291 : :
292 : : vcl_sal::WMAdaptor* m_pWMAdaptor;
293 : :
294 : : bool m_bXinerama;
295 : : std::vector< Rectangle > m_aXineramaScreens;
296 : : std::vector< int > m_aXineramaScreenIndexMap;
297 : : std::list<SalObject*> m_aSalObjects;
298 : :
299 : : bool m_bUseRandRWrapper; // don't use randr on gtk, use gdk signals there
300 : :
301 : : mutable XLIB_Time m_nLastUserEventTime; // mutable because changed on first access
302 : :
303 : : virtual long Dispatch( XEvent *pEvent ) = 0;
304 : : void InitXinerama();
305 : : void InitRandR( XLIB_Window aRoot ) const;
306 : : void DeInitRandR();
307 : : int processRandREvent( XEvent* );
308 : :
309 : : void doDestruct();
310 : : void addXineramaScreenUnique( int i, long i_nX, long i_nY, long i_nWidth, long i_nHeight );
311 : : public:
312 : : static SalDisplay *GetSalDisplay( Display* display );
313 : : static sal_Bool BestVisual( Display *pDisp,
314 : : int nScreen,
315 : : XVisualInfo &rVI );
316 : :
317 : : SalDisplay( Display* pDisp );
318 : :
319 : : virtual ~SalDisplay();
320 : :
321 : : void Init();
322 : : void PrintInfo() const;
323 : :
324 : : #ifdef DBG_UTIL
325 : : void DbgPrintDisplayEvent(const char *pComment, XEvent *pEvent) const;
326 : : #endif
327 : :
328 : : void ModifierMapping();
329 : : void SimulateKeyPress( sal_uInt16 nKeyCode );
330 : : sal_uInt16 GetIndicatorState() const;
331 : : rtl::OUString GetKeyNameFromKeySym( KeySym keysym ) const;
332 : : rtl::OUString GetKeyName( sal_uInt16 nKeyCode ) const;
333 : : sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
334 : : KeySym GetKeySym( XKeyEvent *pEvent,
335 : : unsigned char *pPrintable,
336 : : int *pLen,
337 : : KeySym *pUnmodifiedKeySym,
338 : : Status *pStatus,
339 : : XIC = NULL ) const;
340 : :
341 : : XLIB_Cursor GetPointer( int ePointerStyle );
342 : : virtual int CaptureMouse( SalFrame *pCapture );
343 : :
344 : : void Remove( XEvent *pEvent );
345 : : virtual ScreenData *initScreen( SalX11Screen nXScreen ) const;
346 : 0 : const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
347 : : {
348 : 0 : if( nXScreen.getXScreen() >= m_aScreens.size() )
349 : 0 : return m_aInvalidScreenData;
350 : 0 : if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
351 : 0 : initScreen( nXScreen );
352 : 0 : return m_aScreens[nXScreen.getXScreen()];
353 : : }
354 : :
355 : 0 : XLIB_Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
356 : 0 : Display *GetDisplay() const { return pDisp_; }
357 : 0 : SalX11Screen GetDefaultXScreen() const { return m_nXDefaultScreen; }
358 : 0 : const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
359 : 0 : srv_vendor_t GetServerVendor() const { return meServerVendor; }
360 : 0 : void SetServerVendor() { meServerVendor = sal_GetServerVendor(pDisp_); }
361 : 0 : sal_Bool IsDisplay() const { return !!pXLib_; }
362 : : GC GetMonoGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aMonoGC; }
363 : 0 : GC GetCopyGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aCopyGC; }
364 : : GC GetAndInvertedGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aAndInvertedGC; }
365 : : GC GetAndGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aAndGC; }
366 : : GC GetOrGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aOrGC; }
367 : : GC GetStippleGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aStippleGC; }
368 : : GC GetGC( sal_uInt16 nDepth, SalX11Screen nXScreen ) const;
369 : 0 : Pixmap GetInvert50( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_hInvert50; }
370 : 0 : const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
371 : 0 : const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
372 : 0 : RenderEntryMap& GetRenderEntries( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aRenderData; }
373 : 0 : const Pair &GetResolution() const { return aResolution_; }
374 : 0 : bool GetExactResolution() const { return mbExactResolution; }
375 : 0 : sal_uLong GetProperties() const { return PROPERTY_DEFAULT; }
376 : 0 : sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; }
377 : : XLIB_Time GetLastUserEventTime( bool bAlwaysReget = false ) const;
378 : :
379 : : bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const;
380 : : SalXLib* GetXLib() const { return pXLib_; }
381 : :
382 : 0 : SalI18N_InputMethod* GetInputMethod() const { return mpInputMethod; }
383 : 0 : SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
384 : 0 : void SetInputMethod( SalI18N_InputMethod *pInputMethod )
385 : 0 : { mpInputMethod = pInputMethod; }
386 : 0 : void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
387 : 0 : { mpKbdExtension = pKbdExtension; }
388 : 0 : ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor; }
389 : 0 : bool IsXinerama() const { return m_bXinerama; }
390 : 0 : const std::vector< Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
391 : 0 : XLIB_Window GetRootWindow( SalX11Screen nXScreen ) const
392 : 0 : { return getDataForScreen( nXScreen ).m_aRoot; }
393 : : const std::vector< ScreenData >& GetScreenData() { return m_aScreens; }
394 : 0 : unsigned int GetXScreenCount() const { return m_aScreens.size(); }
395 : :
396 : 0 : const std::list< SalFrame* >& getFrames() const { return m_aFrames; }
397 : 0 : sal_Bool IsNumLockFromXS() const { return bNumLockFromXS_; }
398 : :
399 : 0 : std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
400 : :
401 : : virtual void PostUserEvent() = 0;
402 : : };
403 : :
404 : : // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
405 : :
406 : : inline GC SalDisplay::GetGC( sal_uInt16 nDepth, SalX11Screen nXScreen ) const
407 : : { return 1 == nDepth
408 : : ? GetMonoGC( nXScreen )
409 : : : getDataForScreen(nXScreen).m_aVisual.GetDepth() == nDepth
410 : : ? GetCopyGC( nXScreen )
411 : : : None; }
412 : :
413 : 0 : inline Display *SalColormap::GetXDisplay() const
414 : 0 : { return m_pDisplay->GetDisplay(); }
415 : :
416 : : class VCLPLUG_GEN_PUBLIC SalX11Display : public SalDisplay
417 : : {
418 : : public:
419 : : SalX11Display( Display* pDisp );
420 : : virtual ~SalX11Display();
421 : :
422 : : virtual long Dispatch( XEvent *pEvent );
423 : : virtual void Yield();
424 : : virtual void PostUserEvent();
425 : :
426 : : sal_Bool IsEvent();
427 : : void SetupInput( SalI18N_InputMethod *pInputMethod );
428 : : };
429 : :
430 : :
431 : : // get foreign key names
432 : : namespace vcl_sal {
433 : : rtl::OUString getKeysymReplacementName(
434 : : rtl::OUString pLang,
435 : : KeySym nSymbol );
436 : : }
437 : :
438 : :
439 : : #endif // _SV_SALDISP_HXX
440 : :
441 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|