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