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_SALDISP_HXX 29 #define _SV_SALDISP_HXX 30 31 // -=-= exports =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 32 class SalDisplay; 33 class SalColormap; 34 class SalVisual; 35 class SalXLib; 36 37 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 38 #include <unx/salunx.h> 39 #include <vcl/salgtype.hxx> 40 #ifndef _SV_PTRSTYLE_HXX 41 #include <vcl/ptrstyle.hxx> 42 #endif 43 #include <sal/types.h> 44 #ifndef _OSL_MUTEX_H 45 #include <osl/mutex.h> 46 #endif 47 #include <vector> 48 #include <list> 49 #include <hash_map> 50 #include <tools/gen.hxx> 51 #include <salwtype.hxx> 52 53 #include <vclpluginapi.h> 54 55 // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 56 class BitmapPalette; 57 class SalFrame; 58 class ColorMask; 59 60 namespace vcl_sal { class WMAdaptor; } 61 class DtIntegrator; 62 63 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 64 #define PROPERTY_SUPPORT_WM_SetPos 0x00000001 65 #define PROPERTY_SUPPORT_WM_Screen 0x00000002 66 #define PROPERTY_SUPPORT_WM_Parent_Pixmap_None 0x00000004 67 #define PROPERTY_SUPPORT_WM_ClientPos 0x00000008 68 #define PROPERTY_SUPPORT_XSetClipMask 0x00000010 // for bitmap ops. 69 #define PROPERTY_SUPPORT_3ButtonMouse 0x00000020 70 71 #define PROPERTY_BUG_XA_FAMILY_NAME_nil 0x00001000 72 #define PROPERTY_BUG_XCopyArea_GXxor 0x00002000 // from window 73 #define PROPERTY_BUG_Stipple 0x00004000 // 0/1 inverted 74 #define PROPERTY_BUG_Tile 0x00008000 // Recreate the 75 // dither brush each time 76 #define PROPERTY_BUG_FillPolygon_Tile 0x00010000 // always Toggle Fillstyle 77 #define PROPERTY_BUG_DrawLine 0x00020000 // a DrawLine is one point to short 78 #define PROPERTY_BUG_CopyPlane_RevertBWPixel 0x00040000 // revert fg and bg for xcopyplane 79 #define PROPERTY_BUG_CopyArea_OnlySmallSlices 0x00080000 80 #define PROPERTY_BUG_Bitmap_Bit_Order 0x00100000 81 82 #define PROPERTY_FEATURE_Maximize 0x01000000 83 #define PROPERTY_FEATURE_SharedMemory 0x02000000 84 #define PROPERTY_FEATURE_TrustedSolaris 0x04000000 85 86 #define PROPERTY_DEFAULT 0x00000FCB 87 88 // ------------------------------------------------------------------------ 89 // server vendor 90 91 typedef enum { 92 vendor_none = 0, 93 vendor_attachmate, 94 vendor_excursion, 95 vendor_hp, 96 vendor_hummingbird, 97 vendor_ibm, 98 vendor_sco, 99 vendor_sgi, 100 vendor_sun, 101 vendor_xfree, 102 vendor_xinside, 103 vendor_xprinter, 104 vendor_unknown 105 } srv_vendor_t; 106 107 extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display ); 108 109 // -=-= SalWM =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 110 enum SalWM { olwm, // Open Look 111 mwm, // Motif 112 kwm, // KDE Desktop Environment 113 FourDwm, // SGI 114 vuewm, // HP 115 dtwm, // CDE 116 winmgr, // Oracle NC 117 twm, 118 fvwm, // ... 119 pmwm, // SCO 120 otherwm }; 121 122 // -=-= SalRGB -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 123 // MSB/Bigendian Sicht (SalColor == RGB, r=0xFF0000, g=0xFF00, b=0xFF) 124 125 enum SalRGB { RGB, RBG, 126 GBR, GRB, 127 BGR, BRG, 128 RGBA, RBGA, 129 GBRA, GRBA, 130 BGRA, BRGA, 131 otherSalRGB }; 132 133 // -=-= SalVisual =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 134 class SalVisual : public XVisualInfo 135 { 136 SalRGB eRGBMode_; 137 int nRedShift_; 138 int nGreenShift_; 139 int nBlueShift_; 140 int nRedBits_; 141 int nGreenBits_; 142 int nBlueBits_; 143 public: 144 SalVisual(); 145 ~SalVisual(); 146 SalVisual( const XVisualInfo* pXVI ); 147 148 inline VisualID GetVisualId() const { return visualid; } 149 inline Visual *GetVisual() const { return visual; } 150 inline int GetClass() const { return c_class; } 151 inline int GetDepth() const { return depth; } 152 inline SalRGB GetMode() const { return eRGBMode_; } 153 154 Pixel GetTCPixel( SalColor nColor ) const; 155 SalColor GetTCColor( Pixel nPixel ) const; 156 sal_Bool Convert( int &n0, int &n1, int &n2, int &n3 ); // 32bit 157 sal_Bool Convert( int &n0, int &n1, int &n2 ); // 24bit 158 }; 159 160 // -=-= SalColormap =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 161 class SalColormap 162 { 163 const SalDisplay* m_pDisplay; 164 Colormap m_hColormap; 165 std::vector<SalColor> m_aPalette; // Pseudocolor 166 SalVisual m_aVisual; 167 std::vector<sal_uInt16> m_aLookupTable; // Pseudocolor: 12bit reduction 168 Pixel m_nWhitePixel; 169 Pixel m_nBlackPixel; 170 Pixel m_nUsed; // Pseudocolor 171 int m_nScreen; 172 173 void GetPalette(); 174 void GetLookupTable(); 175 public: 176 SalColormap( const SalDisplay* pSalDisplay, 177 Colormap hColormap, 178 int nScreen ); 179 SalColormap( const BitmapPalette &rpPalette ); 180 SalColormap( sal_uInt16 nDepth ); 181 SalColormap(); 182 ~SalColormap(); 183 184 inline Colormap GetXColormap() const { return m_hColormap; } 185 inline const SalDisplay* GetDisplay() const { return m_pDisplay; } 186 inline Display* GetXDisplay() const; 187 inline const SalVisual& GetVisual() const { return m_aVisual; } 188 inline Visual* GetXVisual() const { return m_aVisual.GetVisual(); } 189 inline Pixel GetWhitePixel() const { return m_nWhitePixel; } 190 inline Pixel GetBlackPixel() const { return m_nBlackPixel; } 191 inline Pixel GetUsed() const { return m_nUsed; } 192 inline int GetClass() const { return m_aVisual.GetClass(); } 193 inline int GetScreenNumber() const { return m_nScreen; } 194 195 sal_Bool GetXPixels( XColor &rColor, 196 int r, 197 int g, 198 int b ) const; 199 inline sal_Bool GetXPixel( XColor &rColor, 200 int r, 201 int g, 202 int b ) const; 203 Pixel GetPixel( SalColor nColor ) const; 204 SalColor GetColor( Pixel nPixel ) const; 205 void SetPalette( const BitmapPalette &rPalette ); 206 }; 207 208 // -=-= SalXLib =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 209 typedef int(*YieldFunc)(int fd, void* data); 210 struct YieldEntry; 211 212 class VCLPLUG_GEN_PUBLIC SalXLib 213 { 214 protected: 215 timeval m_aTimeout; 216 sal_uLong m_nTimeoutMS; 217 int m_pTimeoutFDS[2]; 218 219 bool m_bHaveSystemChildFrames; 220 221 int nFDs_; 222 fd_set aReadFDS_; 223 fd_set aExceptionFDS_; 224 YieldEntry *pYieldEntries_; 225 226 227 struct XErrorStackEntry 228 { 229 bool m_bIgnore; 230 bool m_bWas; 231 unsigned int m_nLastErrorRequest; 232 XErrorHandler m_aHandler; 233 }; 234 std::vector< XErrorStackEntry > m_aXErrorHandlerStack; 235 XIOErrorHandler m_aOrigXIOErrorHandler; 236 public: 237 SalXLib(); 238 virtual ~SalXLib(); 239 virtual void Init(); 240 241 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ); 242 virtual void Wakeup(); 243 virtual void PostUserEvent(); 244 245 virtual void Insert( int fd, void* data, 246 YieldFunc pending, 247 YieldFunc queued, 248 YieldFunc handle ); 249 virtual void Remove( int fd ); 250 251 void XError( Display *pDisp, XErrorEvent *pEvent ); 252 bool HasXErrorOccured() const { return m_aXErrorHandlerStack.back().m_bWas; } 253 unsigned int GetLastXErrorRequestCode() const { return m_aXErrorHandlerStack.back().m_nLastErrorRequest; } 254 void ResetXErrorOccured() { m_aXErrorHandlerStack.back().m_bWas = false; } 255 void PushXErrorLevel( bool bIgnore ); 256 void PopXErrorLevel(); 257 258 virtual void StartTimer( sal_uLong nMS ); 259 virtual void StopTimer(); 260 261 bool CheckTimeout( bool bExecuteTimers = true ); 262 263 void setHaveSystemChildFrame() 264 { m_bHaveSystemChildFrames = true; } 265 bool getHaveSystemChildFrame() const 266 { return m_bHaveSystemChildFrames; } 267 }; 268 269 // -=-= SalDisplay -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 270 271 class SalI18N_InputMethod; 272 class SalI18N_KeyboardExtension; 273 class AttributeProvider; 274 class SalUnicodeConverter; 275 class SalConverterCache; 276 277 extern "C" { 278 struct SnDisplay; 279 struct SnLauncheeContext; 280 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer); 281 } 282 283 class VCLPLUG_GEN_PUBLIC SalDisplay 284 { 285 public: 286 struct RenderEntry 287 { 288 Pixmap m_aPixmap; 289 Picture m_aPicture; 290 291 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {} 292 }; 293 294 typedef std::hash_map<int,RenderEntry> RenderEntryMap; 295 296 struct ScreenData 297 { 298 bool m_bInit; 299 300 XLIB_Window m_aRoot; 301 XLIB_Window m_aRefWindow; 302 Size m_aSize; 303 SalVisual m_aVisual; 304 SalColormap m_aColormap; 305 GC m_aMonoGC; 306 GC m_aCopyGC; 307 GC m_aAndInvertedGC; 308 GC m_aAndGC; 309 GC m_aOrGC; 310 GC m_aStippleGC; 311 Pixmap m_hInvert50; 312 mutable RenderEntryMap m_aRenderData; 313 314 ScreenData() : 315 m_bInit( false ), 316 m_aRoot( None ), 317 m_aRefWindow( None ), 318 m_aMonoGC( None ), 319 m_aCopyGC( None ), 320 m_aAndInvertedGC( None ), 321 m_aAndGC( None ), 322 m_aOrGC( None ), 323 m_aStippleGC( None ), 324 m_hInvert50( None ), 325 m_aRenderData( 1 ) 326 {} 327 }; 328 // -=-= UserEvent =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 329 struct SalUserEvent 330 { 331 SalFrame* m_pFrame; 332 void* m_pData; 333 sal_uInt16 m_nEvent; 334 335 SalUserEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT ) 336 : m_pFrame( pFrame ), 337 m_pData( pData ), 338 m_nEvent( nEvent ) 339 {} 340 }; 341 342 protected: 343 SalXLib *pXLib_; 344 SalI18N_InputMethod *mpInputMethod; 345 SalI18N_KeyboardExtension *mpKbdExtension; 346 347 AttributeProvider *mpFactory; 348 349 Display *pDisp_; // X Display 350 int m_nDefaultScreen; // XDefaultScreen 351 std::vector< ScreenData > m_aScreens; 352 ScreenData m_aInvalidScreenData; 353 Pair aResolution_; // [dpi] 354 bool mbExactResolution; 355 sal_uLong nMaxRequestSize_; // [byte] 356 357 srv_vendor_t meServerVendor; 358 SalWM eWindowManager_; 359 sal_uLong nProperties_; // PROPERTY_SUPPORT, BUG, FEATURE 360 sal_Bool bLocal_; // Server==Client? Init 361 // in SalDisplay::IsLocal() 362 sal_Bool mbLocalIsValid; // bLocal_ is valid ? 363 // until x bytes 364 365 oslMutex hEventGuard_; 366 std::list< SalUserEvent > m_aUserEvents; 367 368 XLIB_Cursor aPointerCache_[POINTER_COUNT]; 369 SalFrame* m_pCapture; 370 371 // Keyboard 372 sal_Bool bNumLockFromXS_; // Num Lock handled by X Server 373 int nNumLockIndex_; // modifier index in modmap 374 int nNumLockMask_; // keyevent state mask for 375 KeySym nShiftKeySym_; // first shift modifier 376 KeySym nCtrlKeySym_; // first control modifier 377 KeySym nMod1KeySym_; // first mod1 modifier 378 ByteString m_aKeyboardName; 379 380 vcl_sal::WMAdaptor* m_pWMAdaptor; 381 DtIntegrator* m_pDtIntegrator; 382 383 bool m_bXinerama; 384 std::vector< Rectangle > m_aXineramaScreens; 385 std::list<SalFrame*> m_aFrames; 386 std::list<SalObject*> m_aSalObjects; 387 388 bool m_bUseRandRWrapper; // don't use randr on gtk, use gdk signals there 389 390 mutable XLIB_Time m_nLastUserEventTime; // mutable because changed on first access 391 392 virtual long Dispatch( XEvent *pEvent ) = 0; 393 void InitXinerama(); 394 void InitRandR( XLIB_Window aRoot ) const; 395 void DeInitRandR(); 396 int processRandREvent( XEvent* ); 397 398 void doDestruct(); 399 int addXineramaScreenUnique( long i_nX, long i_nY, long i_nWidth, long i_nHeight ); 400 public: 401 static SalDisplay *GetSalDisplay( Display* display ); 402 static sal_Bool BestVisual( Display *pDisp, 403 int nScreen, 404 XVisualInfo &rVI ); 405 406 SalDisplay( Display* pDisp ); 407 408 virtual ~SalDisplay(); 409 410 411 virtual void registerFrame( SalFrame* pFrame ); 412 virtual void deregisterFrame( SalFrame* pFrame ); 413 void setHaveSystemChildFrame() const 414 { pXLib_->setHaveSystemChildFrame(); } 415 bool getHaveSystemChildFrame() const 416 { return pXLib_->getHaveSystemChildFrame(); } 417 418 void Init(); 419 420 void SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT ); 421 void CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent ); 422 bool DispatchInternalEvent(); 423 void PrintInfo() const; 424 425 void PrintEvent( const ByteString &rComment, 426 XEvent *pEvent ) const; 427 428 void Beep() const; 429 430 void ModifierMapping(); 431 String GetKeyNameFromKeySym( KeySym keysym ) const; 432 XubString GetKeyName( sal_uInt16 nKeyCode ) const; 433 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const; 434 KeySym GetKeySym( XKeyEvent *pEvent, 435 unsigned char *pPrintable, 436 int *pLen, 437 KeySym *pUnmodifiedKeySym, 438 Status *pStatus, 439 XIC = NULL ) const; 440 441 XLIB_Cursor GetPointer( int ePointerStyle ); 442 virtual int CaptureMouse( SalFrame *pCapture ); 443 444 sal_Bool IsLocal(); 445 446 void Remove( XEvent *pEvent ); 447 448 virtual void initScreen( int nScreen ) const; 449 const ScreenData& getDataForScreen( int nScreen ) const 450 { 451 if( nScreen < 0 || nScreen >= static_cast<int>(m_aScreens.size()) ) 452 return m_aInvalidScreenData; 453 if( ! m_aScreens[nScreen].m_bInit ) 454 initScreen( nScreen ); 455 return m_aScreens[nScreen]; 456 } 457 458 XLIB_Window GetDrawable( int nScreen ) const { return getDataForScreen( nScreen ).m_aRefWindow; } 459 Display *GetDisplay() const { return pDisp_; } 460 int GetDefaultScreenNumber() const { return m_nDefaultScreen; } 461 virtual int GetDefaultMonitorNumber() const { return 0; } 462 const Size& GetScreenSize( int nScreen ) const { return getDataForScreen( nScreen ).m_aSize; } 463 srv_vendor_t GetServerVendor() const { return meServerVendor; } 464 void SetServerVendor() { meServerVendor = sal_GetServerVendor(pDisp_); } 465 sal_Bool IsDisplay() const { return !!pXLib_; } 466 GC GetMonoGC( int nScreen ) const { return getDataForScreen(nScreen).m_aMonoGC; } 467 GC GetCopyGC( int nScreen ) const { return getDataForScreen(nScreen).m_aCopyGC; } 468 GC GetAndInvertedGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndInvertedGC; } 469 GC GetAndGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndGC; } 470 GC GetOrGC( int nScreen ) const { return getDataForScreen(nScreen).m_aOrGC; } 471 GC GetStippleGC( int nScreen ) const { return getDataForScreen(nScreen).m_aStippleGC; } 472 GC GetGC( sal_uInt16 nDepth, int nScreen ) const; 473 Pixmap GetInvert50( int nScreen ) const { return getDataForScreen(nScreen).m_hInvert50; } 474 const SalColormap& GetColormap( int nScreen ) const { return getDataForScreen(nScreen).m_aColormap; } 475 const SalVisual& GetVisual( int nScreen ) const { return getDataForScreen(nScreen).m_aVisual; } 476 RenderEntryMap& GetRenderEntries( int nScreen ) const { return getDataForScreen(nScreen).m_aRenderData; } 477 const Pair &GetResolution() const { return aResolution_; } 478 bool GetExactResolution() const { return mbExactResolution; } 479 sal_uLong GetProperties() const { return nProperties_; } 480 sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; } 481 XLIB_Time GetLastUserEventTime( bool bAlwaysReget = false ) const; 482 483 bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const; 484 485 sal_Bool MouseCaptured( const SalFrame *pFrameData ) const 486 { return m_pCapture == pFrameData; } 487 SalFrame* GetCaptureFrame() const 488 { return m_pCapture; } 489 SalXLib* GetXLib() const { return pXLib_; } 490 491 SalI18N_InputMethod* GetInputMethod() const { return mpInputMethod; } 492 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; } 493 void SetInputMethod( SalI18N_InputMethod *pInputMethod ) 494 { mpInputMethod = pInputMethod; } 495 void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension) 496 { mpKbdExtension = pKbdExtension; } 497 const char* GetKeyboardName( sal_Bool bRefresh = sal_False ); 498 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor; } 499 DtIntegrator* getDtIntegrator() const { return m_pDtIntegrator; } 500 bool IsXinerama() const { return m_bXinerama; } 501 const std::vector< Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; } 502 XLIB_Window GetRootWindow( int nScreen ) const 503 { return getDataForScreen( nScreen ).m_aRoot; } 504 const std::vector< ScreenData >& GetScreenData() 505 { return m_aScreens; } 506 int GetScreenCount() const { return static_cast<int>(m_aScreens.size()); } 507 508 const std::list< SalFrame* >& getFrames() const 509 { return m_aFrames; } 510 511 sal_Bool IsNumLockFromXS() const { return bNumLockFromXS_; } 512 513 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; } 514 }; 515 516 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 517 518 inline GC SalDisplay::GetGC( sal_uInt16 nDepth, int nScreen ) const 519 { return 1 == nDepth 520 ? GetMonoGC( nScreen ) 521 : getDataForScreen(nScreen).m_aVisual.GetDepth() == nDepth 522 ? GetCopyGC( nScreen ) 523 : None; } 524 525 inline Display *SalColormap::GetXDisplay() const 526 { return m_pDisplay->GetDisplay(); } 527 528 class VCLPLUG_GEN_PUBLIC SalX11Display : public SalDisplay 529 { 530 public: 531 SalX11Display( Display* pDisp ); 532 virtual ~SalX11Display(); 533 534 virtual long Dispatch( XEvent *pEvent ); 535 virtual void Yield(); 536 537 sal_Bool IsEvent(); 538 }; 539 540 /*---------------------------------------------------------- 541 keep track of correct size of the initial window 542 */ 543 // get foreign key names 544 namespace vcl_sal { 545 String getKeysymReplacementName( 546 const char* pKeyboard, 547 KeySym nSymbol ); 548 } 549 550 551 #endif // _SV_SALDISP_HXX 552