update dev300-m58
[ooovba.git] / sfx2 / source / dialog / about.cxx
blobf93178cc75daceda5aa2745e1a23ec686a48313d
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>
37 #ifndef _SV_APP_HXX
38 #include <vcl/svapp.hxx>
39 #endif
40 #ifndef _MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
42 #endif
43 #ifndef GCC
44 #endif
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>
55 #include "about.hxx"
56 #include "sfxresid.hxx"
57 #include <sfx2/sfxdefs.hxx>
58 #include <sfx2/app.hxx>
60 #include "dialog.hrc"
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;
75 aTextPos.Y() = nY;
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,
89 Image &rLogo )
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() )
98 Bitmap aBmp;
99 aStrm >> aBmp;
100 rLogo = Image( aBmp );
101 return true;
103 return false;
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() ) ),
113 aBuildData ( this ),
114 aDeveloperAry ( ResId( ABOUT_STR_DEVELOPER_ARY, *rId.GetResMgr() ) ),
115 aDevVersionStr ( rVerStr ),
116 aAccelStr ( ResId( ABOUT_STR_ACCEL, *rId.GetResMgr() ) ),
117 aTimer (),
118 nOff ( 0 ),
119 m_nDeltaWidth ( 0 ),
120 m_nPendingScrolls( 0 ),
121 bNormal ( TRUE )
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 );
137 // <--
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"
153 if ( !bLoaded )
155 bLoaded = impl_loadBitmap(
156 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
157 rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
160 if ( !bLoaded )
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 );
170 SetFont( aFont );
172 // if necessary more info
173 String sVersion = aVersionText.GetText();
174 sVersion.SearchAndReplaceAscii( "$(VER)", Application::GetDisplayName() );
175 sVersion += '\n';
176 sVersion += rVerStr;
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 )
187 pPrevAccel = pAccel;
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 ) );
192 if ( i > 0 )
193 pPrevAccel->SetAccel( 1, pAccel );
194 if ( i == 0 )
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 ) );
224 #else
225 String aBuildString;
226 #endif
227 aBuildData.SetText( aBuildString );
228 aBuildData.Show();
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;
268 aOKPnt.Y() = nY + 8;
269 aOKButton.SetPosPixel( aOKPnt );
270 nY = aOKPnt.Y() + aOKSiz.Height() + a6Size.Height();
271 aOutSiz.Height() = nY;
272 SetOutputSizePixel( aOutSiz );
274 FreeResource();
276 // explizite Help-Id
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();
306 while ( pAccel )
308 delete pAccel;
309 pAccel = aAccelList.Prev();
314 // -----------------------------------------------------------------------
316 IMPL_LINK( AboutDialog, TimerHdl, Timer *, pTimer )
318 (void)pTimer; //unused
319 ++m_nPendingScrolls;
320 Invalidate( INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN );
321 return 0;
324 // -----------------------------------------------------------------------
326 IMPL_LINK( AboutDialog, AccelSelectHdl, Accelerator *, pAccelerator )
328 #ifdef YURI_DARIO
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") );
331 #endif
333 (void)pAccelerator; //unused
334 // init Timer
335 aTimer.SetTimeoutHdl( LINK( this, AboutDialog, TimerHdl ) );
337 // init scroll mode
338 nOff = GetOutputSizePixel().Height();
339 MapMode aMapMode( MAP_PIXEL );
340 SetMapMode( aMapMode );
341 bNormal = FALSE;
343 // start scroll Timer
344 aTimer.SetTimeout( SCROLL_TIMER );
345 aTimer.Start();
346 return 0;
349 // -----------------------------------------------------------------------
351 BOOL AboutDialog::Close()
353 // stop Timer and finish the dialog
354 aTimer.Stop();
355 EndDialog( RET_OK );
356 return( FALSE );
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 );
369 return;
372 // scroll the content
373 const int nDeltaY = -SCROLL_OFFSET * m_nPendingScrolls;
374 if( !nDeltaY )
375 return;
376 nOff += nDeltaY;
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();
384 int nY = nOff;
385 const int nDevCnt = static_cast<int>( aDeveloperAry.Count() );
386 for( int i = 0; i < nDevCnt; ++i )
388 if( nY >= rRect.Bottom() )
389 break;
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);
397 if ( nVal )
399 // emphasize the headers
400 Font aFont = aOrigFont;
401 aFont.SetWeight( (FontWeight)nVal );
402 SetFont( aFont );
403 nPos2 = nY + GetTextHeight() + 3;
406 // clear text background
407 Rectangle aEraseRect( Point(0,nY), Size( nFullWidth, nPos2-nY));
408 Erase( aEraseRect );
410 // draw centered text
411 const long nTextWidth = GetTextWidth( aStr );
412 long nX = (nFullWidth - 5 - nTextWidth) / 2;
413 if( nX < 0 )
414 nX = SPACE_OFFSET;
415 const Point aPnt( nX, nY );
416 DrawText( aPnt, aStr );
418 // restore the font if needed
419 if( nVal )
420 SetFont( aOrigFont );
422 nY = nPos2;
425 // close dialog if the whole text has been scrolled
426 if ( nY <= 0 )
428 bNormal = TRUE;
429 Close();