vcl/inc/unx/saldisp.hxx | 12 +++ vcl/unx/generic/app/saldisp.cxx | 127 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+)
New commits: commit 6cef39508e8a834f694cbfb750e982c623c9bd49 Author: Thomas Arnhold <tho...@arnhold.org> Date: Mon Jan 16 12:54:27 2012 +0100 Add SOLARIS checks for SalDisplay::IsLocal() This method is (only) used at SalDisplay::GetKeyboardName() for SOLARIS diff --git a/unusedcode.easy b/unusedcode.easy index c4784db..26f593d 100644 --- a/unusedcode.easy +++ b/unusedcode.easy @@ -194,7 +194,6 @@ SVGExport::GetGlyphPlacement() const SVGExport::IsUseGradient() const SVGExport::popClip() SVGExport::pushClip(basegfx::B2DPolyPolygon const&) -SalDisplay::IsLocal() SalGraphics::DrawBitmap(SalTwoRect const*, SalBitmap const&, unsigned int, OutputDevice const*) SalGraphics::DrawNativeControlText(unsigned int, unsigned int, Rectangle const&, unsigned int, ImplControlValue const&, rtl::OUString const&, OutputDevice const*) SalGraphics::drawAlphaBitmap(SalTwoRect const&, SalBitmap const&, SalBitmap const&) diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx index d8ee2ec..94b66dc 100644 --- a/vcl/inc/unx/saldisp.hxx +++ b/vcl/inc/unx/saldisp.hxx @@ -305,9 +305,13 @@ protected: srv_vendor_t meServerVendor; SalWM eWindowManager_; + +#if defined(SOLARIS) sal_Bool bLocal_; // Server==Client? Init // in SalDisplay::IsLocal() sal_Bool mbLocalIsValid; // bLocal_ is valid ? +#endif + // until x bytes XLIB_Cursor aPointerCache_[POINTER_COUNT]; @@ -375,7 +379,9 @@ public: XLIB_Cursor GetPointer( int ePointerStyle ); virtual int CaptureMouse( SalFrame *pCapture ); +#if defined(SOLARIS) sal_Bool IsLocal(); +#endif void Remove( XEvent *pEvent ); virtual ScreenData *initScreen( SalX11Screen nXScreen ) const; diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index 23ff906..71bc7db 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -228,6 +228,9 @@ static sal_Bool sal_GetVisualInfo( Display *pDisplay, XID nVID, XVisualInfo &rVI // --------------------------------------------------------------------------- +/* this stuff is used in SalDisplay::GetKeyboardName for SOLARIS */ +#if defined(SOLARIS) + // check wether displaystring is in format N.M or N. or just N // with N and M beeing natural numbers static sal_Bool @@ -342,6 +345,8 @@ sal_Bool SalDisplay::IsLocal() return (sal_Bool)bLocal_; } +#endif //SOLARIS + // --------------------------------------------------------------------------- extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display ) @@ -817,9 +822,11 @@ void SalDisplay::Init() SetServerVendor(); X11SalBitmap::ImplCreateCache(); +#if defined(SOLARIS) bLocal_ = sal_False; /* dont care, initialize later by calling SalDisplay::IsLocal() */ mbLocalIsValid = sal_False; /* bLocal_ is not yet initialized */ +#endif // - - - - - - - - - - Synchronize - - - - - - - - - - - - - if( getenv( "SAL_SYNCHRONIZE" ) ) commit d799ac1320fb11439566a8a6c8215cfb3db10a00 Author: Thomas Arnhold <tho...@arnhold.org> Date: Mon Jan 16 12:47:36 2012 +0100 Revert "Remove unused SalDisplay::IsLocal" This reverts commit e9202ffeccdf6f669184f3f869d2e5b121bea9f3. Conflicts: vcl/inc/unx/saldisp.hxx diff --git a/unusedcode.easy b/unusedcode.easy index 26f593d..c4784db 100644 --- a/unusedcode.easy +++ b/unusedcode.easy @@ -194,6 +194,7 @@ SVGExport::GetGlyphPlacement() const SVGExport::IsUseGradient() const SVGExport::popClip() SVGExport::pushClip(basegfx::B2DPolyPolygon const&) +SalDisplay::IsLocal() SalGraphics::DrawBitmap(SalTwoRect const*, SalBitmap const&, unsigned int, OutputDevice const*) SalGraphics::DrawNativeControlText(unsigned int, unsigned int, Rectangle const&, unsigned int, ImplControlValue const&, rtl::OUString const&, OutputDevice const*) SalGraphics::drawAlphaBitmap(SalTwoRect const&, SalBitmap const&, SalBitmap const&) diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx index 23d54bd..d8ee2ec 100644 --- a/vcl/inc/unx/saldisp.hxx +++ b/vcl/inc/unx/saldisp.hxx @@ -305,6 +305,10 @@ protected: srv_vendor_t meServerVendor; SalWM eWindowManager_; + sal_Bool bLocal_; // Server==Client? Init + // in SalDisplay::IsLocal() + sal_Bool mbLocalIsValid; // bLocal_ is valid ? + // until x bytes XLIB_Cursor aPointerCache_[POINTER_COUNT]; @@ -371,6 +375,8 @@ public: XLIB_Cursor GetPointer( int ePointerStyle ); virtual int CaptureMouse( SalFrame *pCapture ); + sal_Bool IsLocal(); + void Remove( XEvent *pEvent ); virtual ScreenData *initScreen( SalX11Screen nXScreen ) const; const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index a8eac64..23ff906 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -227,6 +227,122 @@ static sal_Bool sal_GetVisualInfo( Display *pDisplay, XID nVID, XVisualInfo &rVI } // --------------------------------------------------------------------------- + +// check wether displaystring is in format N.M or N. or just N +// with N and M beeing natural numbers +static sal_Bool +sal_IsDisplayNumber( const char *pDisplayString ) +{ + if ( ! isdigit(*pDisplayString) ) + return sal_False; + while ( isdigit(*(++pDisplayString)) ) + ; /* do nothing */ + + if ( *pDisplayString == '.' ) + { + while ( isdigit(*(++pDisplayString)) ) + ; /* do nothing */ + } + + return (*pDisplayString == '\0'); +} + +// check whether host1 and host2 point to the same ip address +static sal_Bool +sal_EqualHosts( const OUString& Host1, const OUString& Host2) +{ + oslSocketAddr pHostAddr1; + oslSocketAddr pHostAddr2; + sal_Bool bEqualAddress = sal_False; + + if ( Host1.toChar() >= '0' && Host1.toChar() <= '9' ) + pHostAddr1 = osl_createInetSocketAddr( Host1.pData, 0 ); + else + pHostAddr1 = osl_resolveHostname( Host1.pData ); + + if ( Host2.toChar() >= '0' && Host2.toChar() <= '9' ) + pHostAddr2 = osl_createInetSocketAddr( Host2.pData, 0 ); + else + pHostAddr2 = osl_resolveHostname( Host2.pData ); + + if( pHostAddr1 && pHostAddr2 ) + bEqualAddress = osl_isEqualSocketAddr( pHostAddr1, pHostAddr2 ) ? sal_True : sal_False; + + if( pHostAddr1 ) + osl_destroySocketAddr( pHostAddr1 ); + if( pHostAddr2 ) + osl_destroySocketAddr( pHostAddr2 ); + + return bEqualAddress; +} + +static sal_Bool +sal_IsLocalDisplay( Display *pDisplay ) +{ + const char *pDisplayString = DisplayString( pDisplay ); + + // no string, no idea + if ( pDisplayString == NULL || pDisplayString[ 0 ] == '\0') + return sal_False; + + // check for ":x.y" + if ( pDisplayString[ 0 ] == ':' ) + return sal_IsDisplayNumber( pDisplayString + 1 ); + + // check for fixed token which all mean localhost:x.y + const char pLocal[] = "localhost:"; + const int nLocalLen = sizeof(pLocal) - 1; + if ( strncmp(pDisplayString, pLocal, nLocalLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nLocalLen ); + + const char pUnix[] = "unix:"; + const int nUnixLen = sizeof(pUnix) - 1; + if ( strncmp(pDisplayString, pUnix, nUnixLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nUnixLen ); + + const char pLoopback[] = "127.0.0.1:"; + const int nLoopbackLen= sizeof(pLoopback) - 1; + if ( strncmp(pDisplayString, pLoopback, nLoopbackLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nLoopbackLen ); + + // compare local hostname to displaystring, both may be ip address or + // hostname + sal_Bool bEqual = sal_False; + char *pDisplayHost = strdup( pDisplayString ); + char *pPtr = strrchr( pDisplayHost, ':' ); + + if( pPtr != NULL ) + { + const OUString& rLocalHostname( GetGenericData()->GetHostname() ); + if( rLocalHostname.getLength() ) + { + *pPtr = '\0'; + OUString aDisplayHostname( pDisplayHost, strlen( pDisplayHost ), osl_getThreadTextEncoding() ); + bEqual = sal_EqualHosts( rLocalHostname, aDisplayHostname ); + bEqual = bEqual && sal_IsDisplayNumber( pPtr + 1 ); + } + } + free( pDisplayHost ); + + return bEqual; +} + +// --------------------------------------------------------------------------- +// IsLocal means soffice is running on the same host as the xserver +// since it is not called very often and sal_IsLocalDisplay() is relative +// expensive bLocal_ is initialized on first call + +sal_Bool SalDisplay::IsLocal() +{ + if ( ! mbLocalIsValid ) + { + bLocal_ = sal_IsLocalDisplay( pDisp_ ); + mbLocalIsValid = sal_True; + } + return (sal_Bool)bLocal_; +} + +// --------------------------------------------------------------------------- extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display ) { @@ -701,6 +817,10 @@ void SalDisplay::Init() SetServerVendor(); X11SalBitmap::ImplCreateCache(); + bLocal_ = sal_False; /* dont care, initialize later by + calling SalDisplay::IsLocal() */ + mbLocalIsValid = sal_False; /* bLocal_ is not yet initialized */ + // - - - - - - - - - - Synchronize - - - - - - - - - - - - - if( getenv( "SAL_SYNCHRONIZE" ) ) XSynchronize( pDisp_, True ); _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits