Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / unx / saldisp.hxx
bloba304a4b3718b2582700b0ff58da91d6a78fe3adf
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 #ifndef INCLUDED_VCL_INC_UNX_SALDISP_HXX
21 #define INCLUDED_VCL_INC_UNX_SALDISP_HXX
23 class SalDisplay;
24 class SalColormap;
25 class SalVisual;
26 class SalXLib;
28 #include <unx/salunx.h>
29 #include <unx/saltype.h>
30 #include <vcl/salgtype.hxx>
31 #include <vcl/ptrstyle.hxx>
32 #include <sal/types.h>
33 #include <osl/mutex.h>
34 #include <list>
35 #include <unordered_map>
36 #include <vector>
37 #include <tools/gen.hxx>
38 #include <salwtype.hxx>
39 #include <generic/gendata.hxx>
40 #include <generic/gendisp.hxx>
41 #include <o3tl/enumarray.hxx>
43 #include <vclpluginapi.h>
45 class BitmapPalette;
46 class SalFrame;
47 class ColorMask;
49 namespace vcl_sal { class WMAdaptor; }
51 // server vendor
53 typedef enum {
54 vendor_none = 0,
55 vendor_sun,
56 vendor_unknown
57 } srv_vendor_t;
59 extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
61 // MSB/Bigendian view (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
63 enum SalRGB { RGB, RBG,
64 GBR, GRB,
65 BGR, BRG,
66 RGBA, RBGA,
67 GBRA, GRBA,
68 BGRA, BRGA,
69 otherSalRGB };
71 class SalVisual : public XVisualInfo
73 SalRGB eRGBMode_;
74 int nRedShift_;
75 int nGreenShift_;
76 int nBlueShift_;
77 int nRedBits_;
78 int nGreenBits_;
79 int nBlueBits_;
80 public:
81 SalVisual();
82 ~SalVisual();
83 SalVisual( const XVisualInfo* pXVI );
85 inline VisualID GetVisualId() const { return visualid; }
86 inline Visual *GetVisual() const { return visual; }
87 inline int GetClass() const { return c_class; }
88 inline int GetDepth() const { return depth; }
89 inline SalRGB GetMode() const { return eRGBMode_; }
91 Pixel GetTCPixel( SalColor nColor ) const;
92 SalColor GetTCColor( Pixel nPixel ) const;
95 class SalColormap
97 const SalDisplay* m_pDisplay;
98 Colormap m_hColormap;
99 std::vector<SalColor> m_aPalette; // Pseudocolor
100 SalVisual m_aVisual;
101 std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction
102 Pixel m_nWhitePixel;
103 Pixel m_nBlackPixel;
104 Pixel m_nUsed; // Pseudocolor
105 SalX11Screen m_nXScreen;
107 void GetPalette();
108 void GetLookupTable();
109 public:
110 SalColormap( const SalDisplay* pSalDisplay,
111 Colormap hColormap,
112 SalX11Screen nXScreen );
113 SalColormap( sal_uInt16 nDepth );
114 SalColormap();
115 ~SalColormap();
117 inline Colormap GetXColormap() const { return m_hColormap; }
118 inline const SalDisplay* GetDisplay() const { return m_pDisplay; }
119 inline Display* GetXDisplay() const;
120 inline const SalVisual& GetVisual() const { return m_aVisual; }
121 inline Visual* GetXVisual() const { return m_aVisual.GetVisual(); }
122 inline Pixel GetWhitePixel() const { return m_nWhitePixel; }
123 inline Pixel GetBlackPixel() const { return m_nBlackPixel; }
124 inline Pixel GetUsed() const { return m_nUsed; }
125 inline int GetClass() const { return m_aVisual.GetClass(); }
127 bool GetXPixels( XColor &rColor,
128 int r,
129 int g,
130 int b ) const;
131 inline bool GetXPixel( XColor &rColor,
132 int r,
133 int g,
134 int b ) const;
135 Pixel GetPixel( SalColor nColor ) const;
136 SalColor GetColor( Pixel nPixel ) const;
139 typedef int(*YieldFunc)(int fd, void* data);
141 class VCLPLUG_GEN_PUBLIC SalXLib
143 protected:
144 timeval m_aTimeout;
145 sal_uLong m_nTimeoutMS;
146 int m_pTimeoutFDS[2];
147 bool blockIdleTimeout;
149 int nFDs_;
150 fd_set aReadFDS_;
151 fd_set aExceptionFDS_;
153 public:
154 SalXLib();
155 virtual ~SalXLib();
156 virtual void Init();
158 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents );
159 virtual void Wakeup();
160 virtual void PostUserEvent();
162 virtual void Insert( int fd, void* data,
163 YieldFunc pending,
164 YieldFunc queued,
165 YieldFunc handle );
166 virtual void Remove( int fd );
168 virtual void StartTimer( sal_uLong nMS );
169 virtual void StopTimer();
171 bool CheckTimeout( bool bExecuteTimers = true );
174 class SalI18N_InputMethod;
175 class SalI18N_KeyboardExtension;
176 class AttributeProvider;
178 extern "C" {
179 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
182 class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay
184 public:
185 struct RenderEntry
187 Pixmap m_aPixmap;
188 Picture m_aPicture;
190 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
193 typedef std::unordered_map<int,RenderEntry> RenderEntryMap;
195 struct ScreenData
197 bool m_bInit;
199 ::Window m_aRoot;
200 ::Window m_aRefWindow;
201 Size m_aSize;
202 SalVisual m_aVisual;
203 SalColormap m_aColormap;
204 GC m_aMonoGC;
205 GC m_aCopyGC;
206 GC m_aAndInvertedGC;
207 GC m_aAndGC;
208 GC m_aOrGC;
209 GC m_aStippleGC;
210 Pixmap m_hInvert50;
211 mutable RenderEntryMap m_aRenderData;
213 ScreenData() :
214 m_bInit( false ),
215 m_aRoot( None ),
216 m_aRefWindow( None ),
217 m_aMonoGC( None ),
218 m_aCopyGC( None ),
219 m_aAndInvertedGC( None ),
220 m_aAndGC( None ),
221 m_aOrGC( None ),
222 m_aStippleGC( None ),
223 m_hInvert50( None ),
224 m_aRenderData( 1 )
228 protected:
229 SalXLib *pXLib_;
230 SalI18N_InputMethod *mpInputMethod;
231 SalI18N_KeyboardExtension *mpKbdExtension;
233 AttributeProvider *mpFactory;
235 Display *pDisp_; // X Display
237 SalX11Screen m_nXDefaultScreen;
238 std::vector< ScreenData > m_aScreens;
239 ScreenData m_aInvalidScreenData;
240 Pair aResolution_; // [dpi]
241 sal_uLong nMaxRequestSize_; // [byte]
243 srv_vendor_t meServerVendor;
245 // until x bytes
247 o3tl::enumarray<PointerStyle, Cursor> aPointerCache_;
249 // Keyboard
250 bool bNumLockFromXS_; // Num Lock handled by X Server
251 int nNumLockIndex_; // modifier index in modmap
252 int nNumLockMask_; // keyevent state mask for
253 KeySym nShiftKeySym_; // first shift modifier
254 KeySym nCtrlKeySym_; // first control modifier
255 KeySym nMod1KeySym_; // first mod1 modifier
257 vcl_sal::WMAdaptor* m_pWMAdaptor;
259 bool m_bXinerama;
260 std::vector< Rectangle > m_aXineramaScreens;
261 std::vector< int > m_aXineramaScreenIndexMap;
262 std::list<SalObject*> m_aSalObjects;
264 bool m_bUseRandRWrapper; // don't use randr on gtk, use gdk signals there
266 mutable Time m_nLastUserEventTime; // mutable because changed on first access
268 virtual bool Dispatch( XEvent *pEvent ) = 0;
269 void InitXinerama();
270 void InitRandR( ::Window aRoot ) const;
271 void DeInitRandR();
272 int processRandREvent( XEvent* );
274 void doDestruct();
275 void addXineramaScreenUnique( int i, long i_nX, long i_nY, long i_nWidth, long i_nHeight );
276 public:
277 static bool BestVisual( Display *pDisp,
278 int nScreen,
279 XVisualInfo &rVI );
281 SalDisplay( Display* pDisp );
283 virtual ~SalDisplay();
285 void Init();
287 #ifdef DBG_UTIL
288 void PrintInfo() const;
289 void DbgPrintDisplayEvent(const char *pComment, XEvent *pEvent) const;
290 #endif
292 void Beep() const;
294 void ModifierMapping();
295 void SimulateKeyPress( sal_uInt16 nKeyCode );
296 KeyIndicatorState GetIndicatorState() const;
297 OUString GetKeyNameFromKeySym( KeySym keysym ) const;
298 OUString GetKeyName( sal_uInt16 nKeyCode ) const;
299 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const;
300 KeySym GetKeySym( XKeyEvent *pEvent,
301 unsigned char *pPrintable,
302 int *pLen,
303 KeySym *pUnmodifiedKeySym,
304 Status *pStatus,
305 XIC = NULL ) const;
307 Cursor GetPointer( PointerStyle ePointerStyle );
308 virtual int CaptureMouse( SalFrame *pCapture );
310 void Remove( XEvent *pEvent );
311 virtual ScreenData *initScreen( SalX11Screen nXScreen ) const;
312 const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const
314 if( nXScreen.getXScreen() >= m_aScreens.size() )
315 return m_aInvalidScreenData;
316 if( ! m_aScreens[nXScreen.getXScreen()].m_bInit )
317 initScreen( nXScreen );
318 return m_aScreens[nXScreen.getXScreen()];
321 ::Window GetDrawable( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aRefWindow; }
322 Display *GetDisplay() const { return pDisp_; }
323 SalX11Screen GetDefaultXScreen() const { return m_nXDefaultScreen; }
324 const Size& GetScreenSize( SalX11Screen nXScreen ) const { return getDataForScreen( nXScreen ).m_aSize; }
325 srv_vendor_t GetServerVendor() const { return meServerVendor; }
326 void SetServerVendor() { meServerVendor = sal_GetServerVendor(pDisp_); }
327 bool IsDisplay() const { return !!pXLib_; }
328 GC GetMonoGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aMonoGC; }
329 GC GetCopyGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aCopyGC; }
330 GC GetAndInvertedGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aAndInvertedGC; }
331 GC GetAndGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aAndGC; }
332 GC GetOrGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aOrGC; }
333 GC GetStippleGC( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aStippleGC; }
334 GC GetGC( sal_uInt16 nDepth, SalX11Screen nXScreen ) const;
335 Pixmap GetInvert50( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_hInvert50; }
336 const SalColormap& GetColormap( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aColormap; }
337 const SalVisual& GetVisual( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aVisual; }
338 RenderEntryMap& GetRenderEntries( SalX11Screen nXScreen ) const { return getDataForScreen(nXScreen).m_aRenderData; }
339 const Pair &GetResolution() const { return aResolution_; }
340 sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; }
341 Time GetLastUserEventTime( bool bAlwaysReget = false ) const;
343 bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const;
344 SalXLib* GetXLib() const { return pXLib_; }
346 SalI18N_InputMethod* GetInputMethod() const { return mpInputMethod; }
347 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
348 void SetInputMethod( SalI18N_InputMethod *pInputMethod )
349 { mpInputMethod = pInputMethod; }
350 void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
351 { mpKbdExtension = pKbdExtension; }
352 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor; }
353 bool IsXinerama() const { return m_bXinerama; }
354 const std::vector< Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
355 ::Window GetRootWindow( SalX11Screen nXScreen ) const
356 { return getDataForScreen( nXScreen ).m_aRoot; }
357 const std::vector< ScreenData >& GetScreenData() { return m_aScreens; }
358 unsigned int GetXScreenCount() const { return m_aScreens.size(); }
360 const std::list< SalFrame* >& getFrames() const { return m_aFrames; }
361 bool IsNumLockFromXS() const { return bNumLockFromXS_; }
363 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
365 virtual void PostUserEvent() SAL_OVERRIDE = 0;
368 inline GC SalDisplay::GetGC( sal_uInt16 nDepth, SalX11Screen nXScreen ) const
369 { return 1 == nDepth
370 ? GetMonoGC( nXScreen )
371 : getDataForScreen(nXScreen).m_aVisual.GetDepth() == nDepth
372 ? GetCopyGC( nXScreen )
373 : None; }
375 inline Display *SalColormap::GetXDisplay() const
376 { return m_pDisplay->GetDisplay(); }
378 class VCLPLUG_GEN_PUBLIC SalX11Display : public SalDisplay
380 public:
381 SalX11Display( Display* pDisp );
382 virtual ~SalX11Display();
384 virtual bool Dispatch( XEvent *pEvent ) SAL_OVERRIDE;
385 virtual void Yield();
386 virtual void PostUserEvent() SAL_OVERRIDE;
388 bool IsEvent();
389 void SetupInput( SalI18N_InputMethod *pInputMethod );
392 namespace vcl_sal {
393 // get foreign key names
394 OUString getKeysymReplacementName(
395 const OUString& pLang,
396 KeySym nSymbol );
398 inline SalDisplay *getSalDisplay(SalGenericData const * data)
400 assert(data != nullptr);
401 assert(data->GetType() != SAL_DATA_GTK3);
402 return static_cast<SalDisplay *>(data->GetDisplay());
406 #endif // INCLUDED_VCL_INC_UNX_SALDISP_HXX
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */