1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
40 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
42 #include <vcl/salgtype.hxx>
43 #ifndef _SV_PTRSTYLE_HXX
44 #include <vcl/ptrstyle.hxx>
46 #include <sal/types.h>
48 #include <osl/mutex.h>
53 #include <tools/gen.hxx>
54 #include <vcl/salwtype.hxx>
55 #include <vcl/dllapi.h>
57 // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
62 namespace vcl_sal
{ class WMAdaptor
; }
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 // ------------------------------------------------------------------------
109 extern "C" srv_vendor_t
sal_GetServerVendor( Display
*p_display
);
111 // -=-= SalWM =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
112 enum SalWM
{ olwm
, // Open Look
114 kwm
, // KDE Desktop Environment
124 // -=-= SalRGB -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
125 // MSB/Bigendian Sicht (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF)
127 enum SalRGB
{ RGB
, RBG
,
135 // -=-= SalVisual =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
136 class SalVisual
: public XVisualInfo
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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
165 const SalDisplay
* m_pDisplay
;
166 Colormap m_hColormap
;
167 std::vector
<SalColor
> m_aPalette
; // Pseudocolor
169 std::vector
<USHORT
> m_aLookupTable
; // Pseudocolor: 12bit reduction
172 Pixel m_nUsed
; // Pseudocolor
176 void GetLookupTable();
178 SalColormap( const SalDisplay
* pSalDisplay
,
181 SalColormap( const BitmapPalette
&rpPalette
);
182 SalColormap( USHORT nDepth
);
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
,
201 inline BOOL
GetXPixel( XColor
&rColor
,
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
);
214 class VCL_DLLPUBLIC SalXLib
219 int m_pTimeoutFDS
[2];
221 bool m_bHaveSystemChildFrames
;
225 fd_set aExceptionFDS_
;
226 YieldEntry
*pYieldEntries_
;
229 struct XErrorStackEntry
233 unsigned int m_nLastErrorRequest
;
234 XErrorHandler m_aHandler
;
236 std::vector
< XErrorStackEntry
> m_aXErrorHandlerStack
;
242 virtual void Yield( bool bWait
, bool bHandleAllCurrentEvents
);
243 virtual void Wakeup();
244 virtual void PostUserEvent();
246 virtual void Insert( int fd
, void* data
,
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
;
275 class ExtendedFontStruct
;
277 class AttributeProvider
;
278 class SalUnicodeConverter
;
279 class SalConverterCache
;
281 DECLARE_LIST( SalFontCache
, ExtendedFontStruct
* )
285 struct SnLauncheeContext
;
286 typedef Bool(*X_if_predicate
)(Display
*,XEvent
*,XPointer
);
289 class VCL_DLLPUBLIC SalDisplay
297 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {}
300 typedef std::hash_map
<int,RenderEntry
> RenderEntryMap
;
307 XLIB_Window m_aRefWindow
;
310 SalColormap m_aColormap
;
318 mutable RenderEntryMap m_aRenderData
;
323 m_aRefWindow( None
),
326 m_aAndInvertedGC( None
),
329 m_aStippleGC( None
),
334 // -=-= UserEvent =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
341 SalUserEvent( SalFrame
* pFrame
, void* pData
, USHORT nEvent
= SALEVENT_USEREVENT
)
342 : m_pFrame( pFrame
),
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 ?
373 oslMutex hEventGuard_
;
374 std::list
< SalUserEvent
> m_aUserEvents
;
376 XLIB_Cursor aPointerCache_
[POINTER_COUNT
];
377 SalFrame
* m_pCapture
;
379 mutable SalFontCache
* m_pFontCache
;
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
;
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;
405 void InitRandR( XLIB_Window aRoot
) const;
407 int processRandREvent( XEvent
* );
411 static SalDisplay
*GetSalDisplay( Display
* display
);
412 static BOOL
BestVisual( Display
*pDisp
,
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(); }
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;
440 GetFont( const ExtendedXlfd
*pFont
,
441 const Size
& rPixelSize
, sal_Bool bVertical
) const;
444 { return mpFallbackFactory
; }
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
,
457 KeySym
*pUnmodifiedKeySym
,
461 XLIB_Cursor
GetPointer( int ePointerStyle
);
462 virtual int CaptureMouse( SalFrame
*pCapture
);
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
539 ? GetMonoGC( nScreen
)
540 : getDataForScreen(nScreen
).m_aVisual
.GetDepth() == nDepth
541 ? GetCopyGC( nScreen
)
544 inline Display
*SalColormap::GetXDisplay() const
545 { return m_pDisplay
->GetDisplay(); }
547 class VCL_DLLPUBLIC SalX11Display
: public SalDisplay
550 SalX11Display( Display
* pDisp
);
551 virtual ~SalX11Display();
553 virtual long Dispatch( XEvent
*pEvent
);
554 virtual void Yield();
559 /*----------------------------------------------------------
560 keep track of correct size of the initial window
562 // get foreign key names
564 String
getKeysymReplacementName(
565 const char* pKeyboard
,
570 #endif // _SV_SALDISP_HXX