merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / inc / saldisp.hxx
blob89fc11bae63d08cae16a7c9f7b171aa4cba83fb9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: saldisp.hxx,v $
10 * $Revision: 1.47.6.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SV_SALDISP_HXX
32 #define _SV_SALDISP_HXX
34 // -=-= exports =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
35 class SalDisplay;
36 class SalColormap;
37 class SalVisual;
38 class SalXLib;
40 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
41 #include <salunx.h>
42 #include <vcl/salgtype.hxx>
43 #ifndef _SV_PTRSTYLE_HXX
44 #include <vcl/ptrstyle.hxx>
45 #endif
46 #include <sal/types.h>
47 #ifndef _OSL_MUTEX_H
48 #include <osl/mutex.h>
49 #endif
50 #include <vector>
51 #include <list>
52 #include <hash_map>
53 #include <tools/gen.hxx>
54 #include <vcl/salwtype.hxx>
55 #include <vcl/dllapi.h>
57 // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
58 class BitmapPalette;
59 class SalFrame;
60 class ColorMask;
62 namespace vcl_sal { class WMAdaptor; }
63 class DtIntegrator;
65 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
66 #define PROPERTY_SUPPORT_WM_SetPos 0x00000001
67 #define PROPERTY_SUPPORT_WM_Screen 0x00000002
68 #define PROPERTY_SUPPORT_WM_Parent_Pixmap_None 0x00000004
69 #define PROPERTY_SUPPORT_WM_ClientPos 0x00000008
70 #define PROPERTY_SUPPORT_XSetClipMask 0x00000010 // for bitmap ops.
71 #define PROPERTY_SUPPORT_3ButtonMouse 0x00000020
73 #define PROPERTY_BUG_XA_FAMILY_NAME_nil 0x00001000
74 #define PROPERTY_BUG_XCopyArea_GXxor 0x00002000 // from window
75 #define PROPERTY_BUG_Stipple 0x00004000 // 0/1 inverted
76 #define PROPERTY_BUG_Tile 0x00008000 // Recreate the
77 // dither brush each time
78 #define PROPERTY_BUG_FillPolygon_Tile 0x00010000 // always Toggle Fillstyle
79 #define PROPERTY_BUG_DrawLine 0x00020000 // a DrawLine is one point to short
80 #define PROPERTY_BUG_CopyPlane_RevertBWPixel 0x00040000 // revert fg and bg for xcopyplane
81 #define PROPERTY_BUG_CopyArea_OnlySmallSlices 0x00080000
82 #define PROPERTY_BUG_Bitmap_Bit_Order 0x00100000
84 #define PROPERTY_FEATURE_Maximize 0x01000000
85 #define PROPERTY_FEATURE_SharedMemory 0x02000000
86 #define PROPERTY_FEATURE_TrustedSolaris 0x04000000
88 #define PROPERTY_DEFAULT 0x00000FCB
90 // ------------------------------------------------------------------------
91 // server vendor
93 typedef enum {
94 vendor_none = 0,
95 vendor_attachmate,
96 vendor_excursion,
97 vendor_hp,
98 vendor_hummingbird,
99 vendor_ibm,
100 vendor_sco,
101 vendor_sgi,
102 vendor_sun,
103 vendor_xfree,
104 vendor_xinside,
105 vendor_xprinter,
106 vendor_unknown
107 } srv_vendor_t;
109 extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display );
111 // -=-= SalWM =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
112 enum SalWM { olwm, // Open Look
113 mwm, // Motif
114 kwm, // KDE Desktop Environment
115 FourDwm, // SGI
116 vuewm, // HP
117 dtwm, // CDE
118 winmgr, // Oracle NC
119 twm,
120 fvwm, // ...
121 pmwm, // SCO
122 otherwm };
124 // -=-= SalRGB -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
125 // MSB/Bigendian Sicht (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
127 enum SalRGB { RGB, RBG,
128 GBR, GRB,
129 BGR, BRG,
130 RGBA, RBGA,
131 GBRA, GRBA,
132 BGRA, BRGA,
133 other };
135 // -=-= SalVisual =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
136 class SalVisual : public XVisualInfo
138 SalRGB eRGBMode_;
139 int nRedShift_;
140 int nGreenShift_;
141 int nBlueShift_;
142 int nRedBits_;
143 int nGreenBits_;
144 int nBlueBits_;
145 public:
146 SalVisual();
147 ~SalVisual();
148 SalVisual( const XVisualInfo* pXVI );
150 inline VisualID GetVisualId() const { return visualid; }
151 inline Visual *GetVisual() const { return visual; }
152 inline int GetClass() const { return c_class; }
153 inline int GetDepth() const { return depth; }
154 inline SalRGB GetMode() const { return eRGBMode_; }
156 Pixel GetTCPixel( SalColor nColor ) const;
157 SalColor GetTCColor( Pixel nPixel ) const;
158 BOOL Convert( int &n0, int &n1, int &n2, int &n3 ); // 32bit
159 BOOL Convert( int &n0, int &n1, int &n2 ); // 24bit
162 // -=-= SalColormap =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
163 class SalColormap
165 const SalDisplay* m_pDisplay;
166 Colormap m_hColormap;
167 std::vector<SalColor> m_aPalette; // Pseudocolor
168 SalVisual m_aVisual;
169 std::vector<USHORT> m_aLookupTable; // Pseudocolor: 12bit reduction
170 Pixel m_nWhitePixel;
171 Pixel m_nBlackPixel;
172 Pixel m_nUsed; // Pseudocolor
173 int m_nScreen;
175 void GetPalette();
176 void GetLookupTable();
177 public:
178 SalColormap( const SalDisplay* pSalDisplay,
179 Colormap hColormap,
180 int nScreen );
181 SalColormap( const BitmapPalette &rpPalette );
182 SalColormap( USHORT nDepth );
183 SalColormap();
184 ~SalColormap();
186 inline Colormap GetXColormap() const { return m_hColormap; }
187 inline const SalDisplay* GetDisplay() const { return m_pDisplay; }
188 inline Display* GetXDisplay() const;
189 inline const SalVisual& GetVisual() const { return m_aVisual; }
190 inline Visual* GetXVisual() const { return m_aVisual.GetVisual(); }
191 inline Pixel GetWhitePixel() const { return m_nWhitePixel; }
192 inline Pixel GetBlackPixel() const { return m_nBlackPixel; }
193 inline Pixel GetUsed() const { return m_nUsed; }
194 inline int GetClass() const { return m_aVisual.GetClass(); }
195 inline int GetScreenNumber() const { return m_nScreen; }
197 BOOL GetXPixels( XColor &rColor,
198 int r,
199 int g,
200 int b ) const;
201 inline BOOL GetXPixel( XColor &rColor,
202 int r,
203 int g,
204 int b ) const;
205 Pixel GetPixel( SalColor nColor ) const;
206 SalColor GetColor( Pixel nPixel ) const;
207 void SetPalette( const BitmapPalette &rPalette );
210 // -=-= SalXLib =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
211 typedef int(*YieldFunc)(int fd, void* data);
212 struct YieldEntry;
214 class VCL_DLLPUBLIC SalXLib
216 protected:
217 timeval m_aTimeout;
218 ULONG m_nTimeoutMS;
219 int m_pTimeoutFDS[2];
221 bool m_bHaveSystemChildFrames;
223 int nFDs_;
224 fd_set aReadFDS_;
225 fd_set aExceptionFDS_;
226 YieldEntry *pYieldEntries_;
229 struct XErrorStackEntry
231 bool m_bIgnore;
232 bool m_bWas;
233 unsigned int m_nLastErrorRequest;
234 XErrorHandler m_aHandler;
236 std::vector< XErrorStackEntry > m_aXErrorHandlerStack;
237 public:
238 SalXLib();
239 virtual ~SalXLib();
240 virtual void Init();
242 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents );
243 virtual void Wakeup();
244 virtual void PostUserEvent();
246 virtual void Insert( int fd, void* data,
247 YieldFunc pending,
248 YieldFunc queued,
249 YieldFunc handle );
250 virtual void Remove( int fd );
252 void XError( Display *pDisp, XErrorEvent *pEvent );
253 bool HasXErrorOccured() const { return m_aXErrorHandlerStack.back().m_bWas; }
254 unsigned int GetLastXErrorRequestCode() const { return m_aXErrorHandlerStack.back().m_nLastErrorRequest; }
255 void ResetXErrorOccured() { m_aXErrorHandlerStack.back().m_bWas = false; }
256 void PushXErrorLevel( bool bIgnore );
257 void PopXErrorLevel();
259 virtual void StartTimer( ULONG nMS );
260 virtual void StopTimer();
262 bool CheckTimeout( bool bExecuteTimers = true );
264 void setHaveSystemChildFrame()
265 { m_bHaveSystemChildFrames = true; }
266 bool getHaveSystemChildFrame() const
267 { return m_bHaveSystemChildFrames; }
270 // -=-= SalDisplay -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
272 class SalI18N_InputMethod;
273 class SalI18N_KeyboardExtension;
274 class XlfdStorage;
275 class ExtendedFontStruct;
276 class ExtendedXlfd;
277 class AttributeProvider;
278 class SalUnicodeConverter;
279 class SalConverterCache;
281 DECLARE_LIST( SalFontCache, ExtendedFontStruct* )
283 extern "C" {
284 struct SnDisplay;
285 struct SnLauncheeContext;
286 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
289 class VCL_DLLPUBLIC SalDisplay
291 public:
292 struct RenderEntry
294 Pixmap m_aPixmap;
295 Picture m_aPicture;
297 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
300 typedef std::hash_map<int,RenderEntry> RenderEntryMap;
302 struct ScreenData
304 bool m_bInit;
306 XLIB_Window m_aRoot;
307 XLIB_Window m_aRefWindow;
308 Size m_aSize;
309 SalVisual m_aVisual;
310 SalColormap m_aColormap;
311 GC m_aMonoGC;
312 GC m_aCopyGC;
313 GC m_aAndInvertedGC;
314 GC m_aAndGC;
315 GC m_aOrGC;
316 GC m_aStippleGC;
317 Pixmap m_hInvert50;
318 mutable RenderEntryMap m_aRenderData;
320 ScreenData() :
321 m_bInit( false ),
322 m_aRoot( None ),
323 m_aRefWindow( None ),
324 m_aMonoGC( None ),
325 m_aCopyGC( None ),
326 m_aAndInvertedGC( None ),
327 m_aAndGC( None ),
328 m_aOrGC( None ),
329 m_aStippleGC( None ),
330 m_hInvert50( None ),
331 m_aRenderData( 1 )
334 // -=-= UserEvent =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
335 struct SalUserEvent
337 SalFrame* m_pFrame;
338 void* m_pData;
339 USHORT m_nEvent;
341 SalUserEvent( SalFrame* pFrame, void* pData, USHORT nEvent = SALEVENT_USEREVENT )
342 : m_pFrame( pFrame ),
343 m_pData( pData ),
344 m_nEvent( nEvent )
348 protected:
349 SalXLib *pXLib_;
350 SalI18N_InputMethod *mpInputMethod;
351 SalI18N_KeyboardExtension *mpKbdExtension;
353 AttributeProvider *mpFactory;
354 XlfdStorage *mpFontList;
355 const ExtendedXlfd *mpFallbackFactory;
357 Display *pDisp_; // X Display
358 int m_nDefaultScreen; // XDefaultScreen
359 std::vector< ScreenData > m_aScreens;
360 ScreenData m_aInvalidScreenData;
361 Pair aResolution_; // [dpi]
362 bool mbExactResolution;
363 ULONG nMaxRequestSize_; // [byte]
365 srv_vendor_t meServerVendor;
366 SalWM eWindowManager_;
367 ULONG nProperties_; // PROPERTY_SUPPORT, BUG, FEATURE
368 BOOL bLocal_; // Server==Client? Init
369 // in SalDisplay::IsLocal()
370 BOOL mbLocalIsValid; // bLocal_ is valid ?
371 // until x bytes
373 oslMutex hEventGuard_;
374 std::list< SalUserEvent > m_aUserEvents;
376 XLIB_Cursor aPointerCache_[POINTER_COUNT];
377 SalFrame* m_pCapture;
379 mutable SalFontCache* m_pFontCache;
381 // Keyboard
382 BOOL bNumLockFromXS_; // Num Lock handled by X Server
383 int nNumLockIndex_; // modifier index in modmap
384 int nNumLockMask_; // keyevent state mask for
385 KeySym nShiftKeySym_; // first shift modifier
386 KeySym nCtrlKeySym_; // first control modifier
387 KeySym nMod1KeySym_; // first mod1 modifier
388 ByteString m_aKeyboardName;
390 vcl_sal::WMAdaptor* m_pWMAdaptor;
391 DtIntegrator* m_pDtIntegrator;
393 bool m_bXinerama;
394 std::vector< Rectangle > m_aXineramaScreens;
395 std::list<SalFrame*> m_aFrames;
396 std::list<SalObject*> m_aSalObjects;
398 bool m_bUseRandRWrapper; // don't use randr on gtk, use gdk signals there
400 mutable XLIB_Time m_nLastUserEventTime; // mutable because changed on first access
402 void DestroyFontCache();
403 virtual long Dispatch( XEvent *pEvent ) = 0;
404 void InitXinerama();
405 void InitRandR( XLIB_Window aRoot ) const;
406 void DeInitRandR();
407 int processRandREvent( XEvent* );
409 void doDestruct();
410 public:
411 static SalDisplay *GetSalDisplay( Display* display );
412 static BOOL BestVisual( Display *pDisp,
413 int nScreen,
414 XVisualInfo &rVI );
416 SalDisplay( Display* pDisp );
418 virtual ~SalDisplay();
421 virtual void registerFrame( SalFrame* pFrame );
422 virtual void deregisterFrame( SalFrame* pFrame );
423 void setHaveSystemChildFrame() const
424 { pXLib_->setHaveSystemChildFrame(); }
425 bool getHaveSystemChildFrame() const
426 { return pXLib_->getHaveSystemChildFrame(); }
428 void Init();
430 void SendInternalEvent( SalFrame* pFrame, void* pData, USHORT nEvent = SALEVENT_USEREVENT );
431 void CancelInternalEvent( SalFrame* pFrame, void* pData, USHORT nEvent );
432 bool DispatchInternalEvent();
433 void PrintInfo() const;
435 void PrintEvent( const ByteString &rComment,
436 XEvent *pEvent ) const;
438 XlfdStorage* GetXlfdList() const;
439 ExtendedFontStruct*
440 GetFont( const ExtendedXlfd *pFont,
441 const Size& rPixelSize, sal_Bool bVertical ) const;
442 const ExtendedXlfd*
443 GetFallbackFactory()
444 { return mpFallbackFactory; }
446 void Beep() const;
448 void ModifierMapping();
449 void SimulateKeyPress( USHORT nKeyCode );
450 USHORT GetIndicatorState() const;
451 String GetKeyNameFromKeySym( KeySym keysym ) const;
452 XubString GetKeyName( USHORT nKeyCode ) const;
453 USHORT GetKeyCode( KeySym keysym, char*pcPrintable ) const;
454 KeySym GetKeySym( XKeyEvent *pEvent,
455 unsigned char *pPrintable,
456 int *pLen,
457 KeySym *pUnmodifiedKeySym,
458 Status *pStatus,
459 XIC = NULL ) const;
461 XLIB_Cursor GetPointer( int ePointerStyle );
462 virtual int CaptureMouse( SalFrame *pCapture );
464 BOOL IsLocal();
466 void Remove( XEvent *pEvent );
468 virtual void initScreen( int nScreen ) const;
469 const ScreenData& getDataForScreen( int nScreen ) const
471 if( nScreen < 0 || nScreen >= static_cast<int>(m_aScreens.size()) )
472 return m_aInvalidScreenData;
473 if( ! m_aScreens[nScreen].m_bInit )
474 initScreen( nScreen );
475 return m_aScreens[nScreen];
478 XLIB_Window GetDrawable( int nScreen ) const { return getDataForScreen( nScreen ).m_aRefWindow; }
479 Display *GetDisplay() const { return pDisp_; }
480 int GetDefaultScreenNumber() const { return m_nDefaultScreen; }
481 const Size& GetScreenSize( int nScreen ) const { return getDataForScreen( nScreen ).m_aSize; }
482 srv_vendor_t GetServerVendor() const { return meServerVendor; }
483 void SetServerVendor() { meServerVendor = sal_GetServerVendor(pDisp_); }
484 BOOL IsDisplay() const { return !!pXLib_; }
485 GC GetMonoGC( int nScreen ) const { return getDataForScreen(nScreen).m_aMonoGC; }
486 GC GetCopyGC( int nScreen ) const { return getDataForScreen(nScreen).m_aCopyGC; }
487 GC GetAndInvertedGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndInvertedGC; }
488 GC GetAndGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndGC; }
489 GC GetOrGC( int nScreen ) const { return getDataForScreen(nScreen).m_aOrGC; }
490 GC GetStippleGC( int nScreen ) const { return getDataForScreen(nScreen).m_aStippleGC; }
491 GC GetGC( USHORT nDepth, int nScreen ) const;
492 Pixmap GetInvert50( int nScreen ) const { return getDataForScreen(nScreen).m_hInvert50; }
493 const SalColormap& GetColormap( int nScreen ) const { return getDataForScreen(nScreen).m_aColormap; }
494 const SalVisual& GetVisual( int nScreen ) const { return getDataForScreen(nScreen).m_aVisual; }
495 RenderEntryMap& GetRenderEntries( int nScreen ) const { return getDataForScreen(nScreen).m_aRenderData; }
496 const Pair &GetResolution() const { return aResolution_; }
497 bool GetExactResolution() const { return mbExactResolution; }
498 ULONG GetProperties() const { return nProperties_; }
499 ULONG GetMaxRequestSize() const { return nMaxRequestSize_; }
500 XLIB_Time GetLastUserEventTime( bool bAlwaysReget = false ) const;
502 bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const;
504 BOOL MouseCaptured( const SalFrame *pFrameData ) const
505 { return m_pCapture == pFrameData; }
506 SalFrame* GetCaptureFrame() const
507 { return m_pCapture; }
508 SalXLib* GetXLib() const { return pXLib_; }
510 SalI18N_InputMethod* GetInputMethod() const { return mpInputMethod; }
511 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; }
512 void SetInputMethod( SalI18N_InputMethod *pInputMethod )
513 { mpInputMethod = pInputMethod; }
514 void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension)
515 { mpKbdExtension = pKbdExtension; }
516 const char* GetKeyboardName( BOOL bRefresh = FALSE );
517 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor; }
518 DtIntegrator* getDtIntegrator() const { return m_pDtIntegrator; }
519 bool IsXinerama() const { return m_bXinerama; }
520 const std::vector< Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; }
521 XLIB_Window GetRootWindow( int nScreen ) const
522 { return getDataForScreen( nScreen ).m_aRoot; }
523 const std::vector< ScreenData >& GetScreenData()
524 { return m_aScreens; }
525 int GetScreenCount() const { return static_cast<int>(m_aScreens.size()); }
527 const std::list< SalFrame* >& getFrames() const
528 { return m_aFrames; }
530 BOOL IsNumLockFromXS() const { return bNumLockFromXS_; }
532 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
535 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
537 inline GC SalDisplay::GetGC( USHORT nDepth, int nScreen ) const
538 { return 1 == nDepth
539 ? GetMonoGC( nScreen )
540 : getDataForScreen(nScreen).m_aVisual.GetDepth() == nDepth
541 ? GetCopyGC( nScreen )
542 : None; }
544 inline Display *SalColormap::GetXDisplay() const
545 { return m_pDisplay->GetDisplay(); }
547 class VCL_DLLPUBLIC SalX11Display : public SalDisplay
549 public:
550 SalX11Display( Display* pDisp );
551 virtual ~SalX11Display();
553 virtual long Dispatch( XEvent *pEvent );
554 virtual void Yield();
556 BOOL IsEvent();
559 /*----------------------------------------------------------
560 keep track of correct size of the initial window
562 // get foreign key names
563 namespace vcl_sal {
564 String getKeysymReplacementName(
565 const char* pKeyboard,
566 KeySym nSymbol );
570 #endif // _SV_SALDISP_HXX