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 struct YieldEntry; 207 208 class VCLPLUG_GEN_PUBLIC SalXLib 209 { 210 protected: 211 timeval m_aTimeout; 212 sal_uLong m_nTimeoutMS; 213 int m_pTimeoutFDS[2]; 214 215 bool m_bHaveSystemChildFrames; 216 217 int nFDs_; 218 fd_set aReadFDS_; 219 fd_set aExceptionFDS_; 220 YieldEntry *pYieldEntries_; 221 222 223 struct XErrorStackEntry 224 { 225 bool m_bIgnore; 226 bool m_bWas; 227 unsigned int m_nLastErrorRequest; 228 XErrorHandler m_aHandler; 229 }; 230 std::vector< XErrorStackEntry > m_aXErrorHandlerStack; 231 XIOErrorHandler m_aOrigXIOErrorHandler; 232 public: 233 SalXLib(); 234 virtual ~SalXLib(); 235 virtual void Init(); 236 237 virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ); 238 virtual void Wakeup(); 239 virtual void PostUserEvent(); 240 241 virtual void Insert( int fd, void* data, 242 YieldFunc pending, 243 YieldFunc queued, 244 YieldFunc handle ); 245 virtual void Remove( int fd ); 246 247 void XError( Display *pDisp, XErrorEvent *pEvent ); 248 bool HasXErrorOccured() const { return m_aXErrorHandlerStack.back().m_bWas; } 249 unsigned int GetLastXErrorRequestCode() const { return m_aXErrorHandlerStack.back().m_nLastErrorRequest; } 250 void ResetXErrorOccured() { m_aXErrorHandlerStack.back().m_bWas = false; } 251 void PushXErrorLevel( bool bIgnore ); 252 void PopXErrorLevel(); 253 254 virtual void StartTimer( sal_uLong nMS ); 255 virtual void StopTimer(); 256 257 bool CheckTimeout( bool bExecuteTimers = true ); 258 259 void setHaveSystemChildFrame() 260 { m_bHaveSystemChildFrames = true; } 261 bool getHaveSystemChildFrame() const 262 { return m_bHaveSystemChildFrames; } 263 }; 264 265 // -=-= SalDisplay -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 266 267 class SalI18N_InputMethod; 268 class SalI18N_KeyboardExtension; 269 class AttributeProvider; 270 class SalUnicodeConverter; 271 class SalConverterCache; 272 273 extern "C" { 274 struct SnDisplay; 275 struct SnLauncheeContext; 276 typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer); 277 } 278 279 class VCLPLUG_GEN_PUBLIC SalDisplay 280 { 281 public: 282 struct RenderEntry 283 { 284 Pixmap m_aPixmap; 285 Picture m_aPicture; 286 287 RenderEntry() : m_aPixmap( 0 ), m_aPicture( 0 ) {} 288 }; 289 290 typedef std::hash_map<int,RenderEntry> RenderEntryMap; 291 292 struct ScreenData 293 { 294 bool m_bInit; 295 296 XLIB_Window m_aRoot; 297 XLIB_Window m_aRefWindow; 298 Size m_aSize; 299 SalVisual m_aVisual; 300 SalColormap m_aColormap; 301 GC m_aMonoGC; 302 GC m_aCopyGC; 303 GC m_aAndInvertedGC; 304 GC m_aAndGC; 305 GC m_aOrGC; 306 GC m_aStippleGC; 307 Pixmap m_hInvert50; 308 mutable RenderEntryMap m_aRenderData; 309 310 ScreenData() : 311 m_bInit( false ), 312 m_aRoot( None ), 313 m_aRefWindow( None ), 314 m_aMonoGC( None ), 315 m_aCopyGC( None ), 316 m_aAndInvertedGC( None ), 317 m_aAndGC( None ), 318 m_aOrGC( None ), 319 m_aStippleGC( None ), 320 m_hInvert50( None ), 321 m_aRenderData( 1 ) 322 {} 323 }; 324 // -=-= UserEvent =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 325 struct SalUserEvent 326 { 327 SalFrame* m_pFrame; 328 void* m_pData; 329 sal_uInt16 m_nEvent; 330 331 SalUserEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT ) 332 : m_pFrame( pFrame ), 333 m_pData( pData ), 334 m_nEvent( nEvent ) 335 {} 336 }; 337 338 protected: 339 SalXLib *pXLib_; 340 SalI18N_InputMethod *mpInputMethod; 341 SalI18N_KeyboardExtension *mpKbdExtension; 342 343 AttributeProvider *mpFactory; 344 345 Display *pDisp_; // X Display 346 int m_nDefaultScreen; // XDefaultScreen 347 std::vector< ScreenData > m_aScreens; 348 ScreenData m_aInvalidScreenData; 349 Pair aResolution_; // [dpi] 350 bool mbExactResolution; 351 sal_uLong nMaxRequestSize_; // [byte] 352 353 srv_vendor_t meServerVendor; 354 SalWM eWindowManager_; 355 sal_uLong nProperties_; // PROPERTY_SUPPORT, BUG, FEATURE 356 sal_Bool bLocal_; // Server==Client? Init 357 // in SalDisplay::IsLocal() 358 sal_Bool mbLocalIsValid; // bLocal_ is valid ? 359 // until x bytes 360 361 oslMutex hEventGuard_; 362 std::list< SalUserEvent > m_aUserEvents; 363 364 XLIB_Cursor aPointerCache_[POINTER_COUNT]; 365 SalFrame* m_pCapture; 366 367 // Keyboard 368 sal_Bool bNumLockFromXS_; // Num Lock handled by X Server 369 int nNumLockIndex_; // modifier index in modmap 370 int nNumLockMask_; // keyevent state mask for 371 KeySym nShiftKeySym_; // first shift modifier 372 KeySym nCtrlKeySym_; // first control modifier 373 KeySym nMod1KeySym_; // first mod1 modifier 374 ByteString m_aKeyboardName; 375 376 vcl_sal::WMAdaptor* m_pWMAdaptor; 377 DtIntegrator* m_pDtIntegrator; 378 379 bool m_bXinerama; 380 std::vector< Rectangle > m_aXineramaScreens; 381 std::list<SalFrame*> m_aFrames; 382 std::list<SalObject*> m_aSalObjects; 383 384 bool m_bUseRandRWrapper; // don't use randr on gtk, use gdk signals there 385 386 mutable XLIB_Time m_nLastUserEventTime; // mutable because changed on first access 387 388 virtual long Dispatch( XEvent *pEvent ) = 0; 389 void InitXinerama(); 390 void InitRandR( XLIB_Window aRoot ) const; 391 void DeInitRandR(); 392 int processRandREvent( XEvent* ); 393 394 void doDestruct(); 395 int addXineramaScreenUnique( long i_nX, long i_nY, long i_nWidth, long i_nHeight ); 396 public: 397 static SalDisplay *GetSalDisplay( Display* display ); 398 static sal_Bool BestVisual( Display *pDisp, 399 int nScreen, 400 XVisualInfo &rVI ); 401 402 SalDisplay( Display* pDisp ); 403 404 virtual ~SalDisplay(); 405 406 407 virtual void registerFrame( SalFrame* pFrame ); 408 virtual void deregisterFrame( SalFrame* pFrame ); 409 void setHaveSystemChildFrame() const 410 { pXLib_->setHaveSystemChildFrame(); } 411 bool getHaveSystemChildFrame() const 412 { return pXLib_->getHaveSystemChildFrame(); } 413 414 void Init(); 415 416 void SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT ); 417 void CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent ); 418 bool DispatchInternalEvent(); 419 void PrintInfo() const; 420 421 void PrintEvent( const ByteString &rComment, 422 XEvent *pEvent ) const; 423 424 void Beep() const; 425 426 void ModifierMapping(); 427 String GetKeyNameFromKeySym( KeySym keysym ) const; 428 XubString GetKeyName( sal_uInt16 nKeyCode ) const; 429 sal_uInt16 GetKeyCode( KeySym keysym, char*pcPrintable ) const; 430 KeySym GetKeySym( XKeyEvent *pEvent, 431 unsigned char *pPrintable, 432 int *pLen, 433 KeySym *pUnmodifiedKeySym, 434 Status *pStatus, 435 XIC = NULL ) const; 436 437 XLIB_Cursor GetPointer( int ePointerStyle ); 438 virtual int CaptureMouse( SalFrame *pCapture ); 439 440 sal_Bool IsLocal(); 441 442 void Remove( XEvent *pEvent ); 443 444 virtual void initScreen( int nScreen ) const; 445 const ScreenData& getDataForScreen( int nScreen ) const 446 { 447 if( nScreen < 0 || nScreen >= static_cast<int>(m_aScreens.size()) ) 448 return m_aInvalidScreenData; 449 if( ! m_aScreens[nScreen].m_bInit ) 450 initScreen( nScreen ); 451 return m_aScreens[nScreen]; 452 } 453 454 XLIB_Window GetDrawable( int nScreen ) const { return getDataForScreen( nScreen ).m_aRefWindow; } 455 Display *GetDisplay() const { return pDisp_; } 456 int GetDefaultScreenNumber() const { return m_nDefaultScreen; } 457 virtual int GetDefaultMonitorNumber() const { return 0; } 458 const Size& GetScreenSize( int nScreen ) const { return getDataForScreen( nScreen ).m_aSize; } 459 srv_vendor_t GetServerVendor() const { return meServerVendor; } 460 void SetServerVendor() { meServerVendor = sal_GetServerVendor(pDisp_); } 461 sal_Bool IsDisplay() const { return !!pXLib_; } 462 GC GetMonoGC( int nScreen ) const { return getDataForScreen(nScreen).m_aMonoGC; } 463 GC GetCopyGC( int nScreen ) const { return getDataForScreen(nScreen).m_aCopyGC; } 464 GC GetAndInvertedGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndInvertedGC; } 465 GC GetAndGC( int nScreen ) const { return getDataForScreen(nScreen).m_aAndGC; } 466 GC GetOrGC( int nScreen ) const { return getDataForScreen(nScreen).m_aOrGC; } 467 GC GetStippleGC( int nScreen ) const { return getDataForScreen(nScreen).m_aStippleGC; } 468 GC GetGC( sal_uInt16 nDepth, int nScreen ) const; 469 Pixmap GetInvert50( int nScreen ) const { return getDataForScreen(nScreen).m_hInvert50; } 470 const SalColormap& GetColormap( int nScreen ) const { return getDataForScreen(nScreen).m_aColormap; } 471 const SalVisual& GetVisual( int nScreen ) const { return getDataForScreen(nScreen).m_aVisual; } 472 RenderEntryMap& GetRenderEntries( int nScreen ) const { return getDataForScreen(nScreen).m_aRenderData; } 473 const Pair &GetResolution() const { return aResolution_; } 474 bool GetExactResolution() const { return mbExactResolution; } 475 sal_uLong GetProperties() const { return nProperties_; } 476 sal_uLong GetMaxRequestSize() const { return nMaxRequestSize_; } 477 XLIB_Time GetLastUserEventTime( bool bAlwaysReget = false ) const; 478 479 bool XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const; 480 481 sal_Bool MouseCaptured( const SalFrame *pFrameData ) const 482 { return m_pCapture == pFrameData; } 483 SalFrame* GetCaptureFrame() const 484 { return m_pCapture; } 485 SalXLib* GetXLib() const { return pXLib_; } 486 487 SalI18N_InputMethod* GetInputMethod() const { return mpInputMethod; } 488 SalI18N_KeyboardExtension* GetKbdExtension() const { return mpKbdExtension; } 489 void SetInputMethod( SalI18N_InputMethod *pInputMethod ) 490 { mpInputMethod = pInputMethod; } 491 void SetKbdExtension(SalI18N_KeyboardExtension *pKbdExtension) 492 { mpKbdExtension = pKbdExtension; } 493 const char* GetKeyboardName( sal_Bool bRefresh = sal_False ); 494 ::vcl_sal::WMAdaptor* getWMAdaptor() const { return m_pWMAdaptor; } 495 DtIntegrator* getDtIntegrator() const { return m_pDtIntegrator; } 496 bool IsXinerama() const { return m_bXinerama; } 497 const std::vector< Rectangle >& GetXineramaScreens() const { return m_aXineramaScreens; } 498 XLIB_Window GetRootWindow( int nScreen ) const 499 { return getDataForScreen( nScreen ).m_aRoot; } 500 const std::vector< ScreenData >& GetScreenData() 501 { return m_aScreens; } 502 int GetScreenCount() const { return static_cast<int>(m_aScreens.size()); } 503 504 const std::list< SalFrame* >& getFrames() const 505 { return m_aFrames; } 506 507 sal_Bool IsNumLockFromXS() const { return bNumLockFromXS_; } 508 509 std::list< SalObject* >& getSalObjects() { return m_aSalObjects; } 510 }; 511 512 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 513 514 inline GC SalDisplay::GetGC( sal_uInt16 nDepth, int nScreen ) const 515 { return 1 == nDepth 516 ? GetMonoGC( nScreen ) 517 : getDataForScreen(nScreen).m_aVisual.GetDepth() == nDepth 518 ? GetCopyGC( nScreen ) 519 : None; } 520 521 inline Display *SalColormap::GetXDisplay() const 522 { return m_pDisplay->GetDisplay(); } 523 524 class VCLPLUG_GEN_PUBLIC SalX11Display : public SalDisplay 525 { 526 public: 527 SalX11Display( Display* pDisp ); 528 virtual ~SalX11Display(); 529 530 virtual long Dispatch( XEvent *pEvent ); 531 virtual void Yield(); 532 533 sal_Bool IsEvent(); 534 }; 535 536 /*---------------------------------------------------------- 537 keep track of correct size of the initial window 538 */ 539 // get foreign key names 540 namespace vcl_sal { 541 String getKeysymReplacementName( 542 const char* pKeyboard, 543 KeySym nSymbol ); 544 } 545 546 547 #endif // _SV_SALDISP_HXX 548