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: about.cxx,v $
10 * $Revision: 1.41.4.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // include ---------------------------------------------------------------
35 #include <aboutbmpnames.hxx>
38 #include <vcl/svapp.hxx>
40 #ifndef _MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
46 #include <tools/stream.hxx>
47 #include <tools/urlobj.hxx>
48 #include <rtl/bootstrap.hxx>
49 #include <unotools/configmgr.hxx>
50 #include <unotools/bootstrap.hxx>
51 #include <com/sun/star/uno/Any.h>
52 #include <unotools/configmgr.hxx>
54 #include <sfx2/sfxuno.hxx>
56 #include "sfxresid.hxx"
57 #include <sfx2/sfxdefs.hxx>
58 #include <sfx2/app.hxx>
62 // defines ---------------------------------------------------------------
64 #define SCROLL_OFFSET 1
65 #define SPACE_OFFSET 5
66 #define SCROLL_TIMER 30
68 #define WELCOME_URL DEFINE_CONST_UNICODE( "http://www.openoffice.org/welcome/credits.html" )
70 // class AboutDialog -----------------------------------------------------
71 static void layoutText( FixedInfo
&rText
, long &nY
, long nTextWidth
, Size a6Size
)
73 Point aTextPos
= rText
.GetPosPixel();
74 aTextPos
.X() = a6Size
.Width() * 2;
76 rText
.SetPosPixel( aTextPos
);
78 Size aTxtSiz
= rText
.GetSizePixel();
79 aTxtSiz
.Width() = nTextWidth
;
80 Size aCalcSize
= rText
.CalcMinimumSize( nTextWidth
);
81 aTxtSiz
.Height() = aCalcSize
.Height();
82 rText
.SetSizePixel( aTxtSiz
);
84 nY
+= aTxtSiz
.Height();
87 static bool impl_loadBitmap(
88 const rtl::OUString
&rPath
, const rtl::OUString
&rBmpFileName
,
91 rtl::OUString
uri( rPath
);
92 rtl::Bootstrap::expandMacros( uri
);
93 INetURLObject
aObj( uri
);
94 aObj
.insertName( rBmpFileName
);
95 SvFileStream
aStrm( aObj
.PathToFileName(), STREAM_STD_READ
);
96 if ( !aStrm
.GetError() )
100 rLogo
= Image( aBmp
);
106 AboutDialog::AboutDialog( Window
* pParent
, const ResId
& rId
, const String
& rVerStr
) :
108 SfxModalDialog ( pParent
, rId
),
110 aOKButton ( this, ResId( ABOUT_BTN_OK
, *rId
.GetResMgr() ) ),
111 aVersionText ( this, ResId( ABOUT_FTXT_VERSION
, *rId
.GetResMgr() ) ),
112 aCopyrightText ( this, ResId( ABOUT_FTXT_COPYRIGHT
, *rId
.GetResMgr() ) ),
114 aDeveloperAry ( ResId( ABOUT_STR_DEVELOPER_ARY
, *rId
.GetResMgr() ) ),
115 aDevVersionStr ( rVerStr
),
116 aAccelStr ( ResId( ABOUT_STR_ACCEL
, *rId
.GetResMgr() ) ),
120 m_nPendingScrolls( 0 ),
123 rtl::OUString sProduct
;
124 utl::ConfigManager::GetDirectConfigProperty(utl::ConfigManager::PRODUCTNAME
) >>= sProduct
;
126 if ( sProduct
.equals( rtl::OUString::createFromAscii("StarOffice") ) ||
127 sProduct
.equals( rtl::OUString::createFromAscii("StarSuite") ) )
129 // --> PB 2004-11-18 #118455# new copyright text (only in french version show a french text)
130 ::com::sun::star::lang::Locale aLocale
= Application::GetSettings().GetUILocale();
131 ::rtl::OUString
sFrenchLang( DEFINE_CONST_OUSTRING( "fr" ) );
132 if ( aLocale
.Language
.equals( sFrenchLang
) )
134 String
sNewCopyrightText( ResId( ABOUT_STR_FRENCH_COPYRIGHT
, *rId
.GetResMgr() ) );
135 aCopyrightText
.SetText( sNewCopyrightText
);
140 // load image from module path
141 rtl::OUString
aAbouts( RTL_CONSTASCII_USTRINGPARAM( ABOUT_BITMAP_STRINGLIST
) );
142 bool bLoaded
= false;
143 sal_Int32 nIndex
= 0;
146 bLoaded
= impl_loadBitmap(
147 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
148 aAbouts
.getToken( 0, ',', nIndex
), aAppLogo
);
150 while ( !bLoaded
&& ( nIndex
>= 0 ) );
152 // fallback to "about.bmp"
155 bLoaded
= impl_loadBitmap(
156 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
157 rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo
);
162 bLoaded
= impl_loadBitmap(
163 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
164 rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo
);
167 // Transparenter Font
168 Font aFont
= GetFont();
169 aFont
.SetTransparent( TRUE
);
172 // if necessary more info
173 String sVersion
= aVersionText
.GetText();
174 sVersion
.SearchAndReplaceAscii( "$(VER)", Application::GetDisplayName() );
177 aVersionText
.SetText( sVersion
);
179 // Initialisierung fuer Aufruf Entwickler
180 if ( aAccelStr
.Len() && ByteString(U2S(aAccelStr
)).IsAlphaAscii() )
182 Accelerator
*pAccel
= 0, *pPrevAccel
= 0, *pFirstAccel
= 0;
183 aAccelStr
.ToUpperAscii();
185 for ( USHORT i
= 0; i
< aAccelStr
.Len(); ++i
)
188 pAccel
= new Accelerator
;
189 aAccelList
.Insert( pAccel
, LIST_APPEND
);
190 USHORT nKey
= aAccelStr
.GetChar(i
) - 'A' + KEY_A
;
191 pAccel
->InsertItem( 1, KeyCode( nKey
, KEY_MOD1
) );
193 pPrevAccel
->SetAccel( 1, pAccel
);
195 pFirstAccel
= pAccel
;
197 pAccel
->SetSelectHdl( LINK( this, AboutDialog
, AccelSelectHdl
) );
198 GetpApp()->InsertAccel( pFirstAccel
);
201 // set for background and text the correct system color
202 const StyleSettings
& rSettings
= GetSettings().GetStyleSettings();
203 Color
aWhiteCol( rSettings
.GetWindowColor() );
204 Wallpaper
aWall( aWhiteCol
);
205 SetBackground( aWall
);
206 Font
aNewFont( aCopyrightText
.GetFont() );
207 aNewFont
.SetTransparent( TRUE
);
209 aVersionText
.SetFont( aNewFont
);
210 aCopyrightText
.SetFont( aNewFont
);
212 aVersionText
.SetBackground();
213 aCopyrightText
.SetBackground();
215 Color
aTextColor( rSettings
.GetWindowTextColor() );
216 aVersionText
.SetControlForeground( aTextColor
);
217 aCopyrightText
.SetControlForeground( aTextColor
);
218 aBuildData
.SetBackground( aWall
);
220 aBuildData
.SetFont( aNewFont
);
221 aBuildData
.SetBackground( aWall
);
222 #ifdef BUILD_VER_STRING
223 String
aBuildString( DEFINE_CONST_UNICODE( BUILD_VER_STRING
) );
227 aBuildData
.SetText( aBuildString
);
230 // determine size and position of the dialog & elements
231 Size aAppLogoSiz
= aAppLogo
.GetSizePixel();
232 Size aOutSiz
= GetOutputSizePixel();
233 aOutSiz
.Width() = aAppLogoSiz
.Width();
234 // spacing to the margin
235 Size a6Size
= aVersionText
.LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
236 long nDlgMargin
= a6Size
.Width() * 4 ;
237 // The URL (if found in copyright text) should not be line-wrapped
238 if ( aCopyrightText
.GetText().Search( WELCOME_URL
) != STRING_NOTFOUND
)
240 long nURLWidth
= GetTextWidth( WELCOME_URL
) + nDlgMargin
+ (2*SPACE_OFFSET
);
241 if ( nURLWidth
> aAppLogoSiz
.Width() )
243 // pb: can be used to align the position of the logo
244 // m_nDeltaWidth = nURLWidth - aOutSiz.Width();
246 aOutSiz
.Width() = nURLWidth
;
250 // layout the text-elements
251 long nTextWidth
= aOutSiz
.Width() - nDlgMargin
;
252 long nY
= aAppLogoSiz
.Height() + ( a6Size
.Height() * 2 );
254 layoutText( aVersionText
, nY
, nTextWidth
, a6Size
);
255 nY
+= ( a6Size
.Height() / 3 );
256 layoutText( aCopyrightText
, nY
, nTextWidth
, a6Size
);
257 nY
+= ( a6Size
.Height() / 3 );
258 if( aBuildString
.Len() > 0 )
260 layoutText( aBuildData
, nY
, nTextWidth
, a6Size
);
261 nY
+= ( a6Size
.Height() / 2 );
264 // OK-Button-Position (at the bottom and centered)
265 Size aOKSiz
= aOKButton
.GetSizePixel();
266 Point aOKPnt
= aOKButton
.GetPosPixel();
267 aOKPnt
.X() = ( aOutSiz
.Width() - aOKSiz
.Width() ) / 2;
269 aOKButton
.SetPosPixel( aOKPnt
);
270 nY
= aOKPnt
.Y() + aOKSiz
.Height() + a6Size
.Height();
271 aOutSiz
.Height() = nY
;
272 SetOutputSizePixel( aOutSiz
);
277 SetHelpId( SID_ABOUT
);
279 //#112429# replace occurences of "StarOffice" in the "StarSuite" version
280 String
sCopyright( aCopyrightText
.GetText() );
281 if(sProduct
.equals(rtl::OUString::createFromAscii("StarSuite")))
283 String
sSO(String::CreateFromAscii("StarOffice"));
284 sCopyright
.SearchAndReplaceAll(sSO
, sProduct
);
287 String
sNewYear( DEFINE_CONST_UNICODE("2005") );
288 xub_StrLen nIdx
= sCopyright
.SearchAndReplace( DEFINE_CONST_UNICODE("2002"), sNewYear
);
289 if ( STRING_NOTFOUND
== nIdx
)
290 nIdx
= sCopyright
.SearchAndReplace( DEFINE_CONST_UNICODE("2003"), sNewYear
);
291 if ( STRING_NOTFOUND
== nIdx
)
292 nIdx
= sCopyright
.SearchAndReplace( DEFINE_CONST_UNICODE("2004"), sNewYear
);
293 aCopyrightText
.SetText( sCopyright
);
296 // -----------------------------------------------------------------------
298 AboutDialog::~AboutDialog()
300 // L"oschen des Entwickleraufrufs
301 if ( aAccelList
.Count() )
303 GetpApp()->RemoveAccel( aAccelList
.First() );
304 Accelerator
* pAccel
= aAccelList
.Last();
309 pAccel
= aAccelList
.Prev();
314 // -----------------------------------------------------------------------
316 IMPL_LINK( AboutDialog
, TimerHdl
, Timer
*, pTimer
)
318 (void)pTimer
; //unused
320 Invalidate( INVALIDATE_NOERASE
| INVALIDATE_NOCHILDREN
);
324 // -----------------------------------------------------------------------
326 IMPL_LINK( AboutDialog
, AccelSelectHdl
, Accelerator
*, pAccelerator
)
329 aCopyrightText
.SetHelpText( DEFINE_CONST_UNICODE("Conoscere qualcuno ovunque egli sia, con cui comprendersi nonostante le distanze\n"
330 "e le differenze, puo' trasformare la terra in un giardino. baci Valeria") );
333 (void)pAccelerator
; //unused
335 aTimer
.SetTimeoutHdl( LINK( this, AboutDialog
, TimerHdl
) );
338 nOff
= GetOutputSizePixel().Height();
339 MapMode
aMapMode( MAP_PIXEL
);
340 SetMapMode( aMapMode
);
343 // start scroll Timer
344 aTimer
.SetTimeout( SCROLL_TIMER
);
349 // -----------------------------------------------------------------------
351 BOOL
AboutDialog::Close()
353 // stop Timer and finish the dialog
359 // -----------------------------------------------------------------------
361 void AboutDialog::Paint( const Rectangle
& rRect
)
363 SetClipRegion( rRect
);
365 if ( bNormal
) // not in scroll mode
367 Point
aPos( m_nDeltaWidth
/ 2, 0 );
368 DrawImage( aPos
, aAppLogo
);
372 // scroll the content
373 const int nDeltaY
= -SCROLL_OFFSET
* m_nPendingScrolls
;
377 Scroll( 0, nDeltaY
, SCROLL_NOERASE
);
378 m_nPendingScrolls
= 0;
380 // draw the credits text
381 const Font aOrigFont
= GetFont();
382 const int nFullWidth
= GetOutputSizePixel().Width();
385 const int nDevCnt
= static_cast<int>( aDeveloperAry
.Count() );
386 for( int i
= 0; i
< nDevCnt
; ++i
)
388 if( nY
>= rRect
.Bottom() )
391 int nPos2
= nY
+ GetTextHeight() + 3;
392 if( nPos2
>= rRect
.Top() + nDeltaY
)
394 const String aStr
= aDeveloperAry
.GetString(i
);
395 const long nVal
= aDeveloperAry
.GetValue(i
);
399 // emphasize the headers
400 Font aFont
= aOrigFont
;
401 aFont
.SetWeight( (FontWeight
)nVal
);
403 nPos2
= nY
+ GetTextHeight() + 3;
406 // clear text background
407 Rectangle
aEraseRect( Point(0,nY
), Size( nFullWidth
, nPos2
-nY
));
410 // draw centered text
411 const long nTextWidth
= GetTextWidth( aStr
);
412 long nX
= (nFullWidth
- 5 - nTextWidth
) / 2;
415 const Point
aPnt( nX
, nY
);
416 DrawText( aPnt
, aStr
);
418 // restore the font if needed
420 SetFont( aOrigFont
);
425 // close dialog if the whole text has been scrolled