xref: /aoo41x/main/cui/source/dialogs/about.cxx (revision 23c0a6f8)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include <vcl/svapp.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <tools/stream.hxx>
32 #include <tools/urlobj.hxx>
33 #include <rtl/bootstrap.hxx>
34 #include <unotools/configmgr.hxx>
35 #include <unotools/bootstrap.hxx>
36 #include <com/sun/star/uno/Any.h>
37 #include <vcl/graph.hxx>
38 #include <svtools/filter.hxx>
39 #include <sfx2/sfxuno.hxx>
40 #include "about.hxx"
41 #include <sfx2/sfxdefs.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/sfxcommands.h>
44 #include "about.hrc"
45 #include <dialmgr.hxx>
46 #include <svtools/svtools.hrc>
47 
48 #include <comphelper/processfactory.hxx>
49 #include <com/sun/star/system/XSystemShellExecute.hpp>
50 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
51 
52 // defines ---------------------------------------------------------------
53 
54 #define _STRINGIFY(x) #x
55 #define STRINGIFY(x) _STRINGIFY(x)
56 
57 // -----------------------------------------------------------------------
58 
59 static void layoutFixedText( FixedText &rControl, const Point& aPos, Size &aSize, const long nTextWidth )
60 {
61     aSize = rControl.GetSizePixel();
62     // change the width
63     aSize.Width() = nTextWidth;
64     // set Position and Size, to calculate the minimum size
65     // this will update the Height
66     rControl.SetPosSizePixel( aPos, aSize );
67     aSize = rControl.CalcMinimumSize();
68     // update the size with the right Height
69     rControl.SetSizePixel( aSize );
70 }
71 
72 static void layoutEdit( Edit &rControl, const Point& aPos, Size &aSize, const long nTextWidth )
73 {
74     aSize = rControl.GetSizePixel();
75     // change the width
76     aSize.Width() = nTextWidth;
77     // set Position and Size, to calculate the minimum size
78     // this will update the Height
79     rControl.SetPosSizePixel( aPos, aSize );
80     aSize = rControl.CalcMinimumSize();
81     // update the size with the right Height
82     rControl.SetSizePixel( aSize );
83 }
84 
85 // -----------------------------------------------------------------------
86 
87 AboutDialog::AboutDialog( Window* pParent, const ResId& rId ) :
88     SfxModalDialog( pParent, rId ),
89     maOKButton( this, ResId( RID_CUI_ABOUT_BTN_OK, *rId.GetResMgr() ) ),
90     maVersionText( this, ResId( RID_CUI_ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
91     maBuildInfoEdit( this, ResId( RID_CUI_ABOUT_FTXT_BUILDDATA, *rId.GetResMgr() ) ),
92     maCopyrightEdit( this, ResId( RID_CUI_ABOUT_FTXT_COPYRIGHT, *rId.GetResMgr() ) ),
93     maCreditsLink( this, ResId( RID_CUI_ABOUT_FTXT_WELCOME_LINK, *rId.GetResMgr() )  ),
94     maCopyrightTextStr( ResId( RID_CUI_ABOUT_STR_COPYRIGHT, *rId.GetResMgr() ) )
95 {
96     // load image from module path
97     maAppLogo = SfxApplication::GetApplicationLogo();
98 
99     InitControls();
100 
101     // set links
102     maCreditsLink.SetClickHdl( LINK( this, AboutDialog, OpenLinkHdl_Impl ) );
103 
104     FreeResource();
105 
106     SetHelpId( CMD_SID_ABOUT );
107 }
108 
109 // -----------------------------------------------------------------------
110 
111 AboutDialog::~AboutDialog()
112 {
113 }
114 
115 // -----------------------------------------------------------------------
116 
117 void AboutDialog::InitControls()
118 {
119     // apply font, background et al.
120     ApplyStyleSettings();
121 
122     // set strings
123     maCopyrightEdit.SetText( maCopyrightTextStr );
124     maBuildInfoEdit.SetText( GetBuildVersionString() );
125     maCreditsLink.SetURL( maCreditsLink.GetText() );
126 
127     // determine size and position of the dialog & elements
128     Size aDlgSize;
129     LayoutControls( aDlgSize );
130 
131     // Change the width of the dialog
132     SetOutputSizePixel( aDlgSize );
133 }
134 
135 // -----------------------------------------------------------------------
136 
137 void AboutDialog::ApplyStyleSettings()
138 {
139     // Transparenter Font
140     Font aFont = GetFont();
141     aFont.SetTransparent( sal_True );
142     SetFont( aFont );
143 
144     // set for background and text the correct system color
145     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
146     Color aWhiteCol( rSettings.GetWindowColor() );
147     Wallpaper aWall( aWhiteCol );
148     SetBackground( aWall );
149     Font aNewFont( maCopyrightEdit.GetFont() );
150     aNewFont.SetTransparent( sal_True );
151 
152     maVersionText.SetFont( aNewFont );
153     maCopyrightEdit.SetFont( aNewFont );
154 
155     maVersionText.SetBackground();
156     maCopyrightEdit.SetBackground();
157     maBuildInfoEdit.SetBackground();
158     maCreditsLink.SetBackground();
159 
160     Color aTextColor( rSettings.GetWindowTextColor() );
161     maVersionText.SetControlForeground( aTextColor );
162     maCopyrightEdit.SetControlForeground( aTextColor );
163     maBuildInfoEdit.SetControlForeground( aTextColor );
164     maCreditsLink.SetControlForeground();
165 
166     Size aSmaller = aNewFont.GetSize();
167     aSmaller.Width() = (long) (aSmaller.Width() * 0.75);
168     aSmaller.Height() = (long) (aSmaller.Height() * 0.75);
169     aNewFont.SetSize( aSmaller );
170 
171     maBuildInfoEdit.SetFont( aNewFont );
172 
173     // the following is a hack to force the MultiLineEdit update its settings
174     // in order to reflect the Font
175     // See
176     //      Window::SetControlFont
177     //      MultiLineEdit::StateChanged
178     //      MultiLineEdit::ImplInitSettings
179     // TODO Override SetFont in MultiLineEdit and do the following,
180     // otherwise SetFont has no effect at all!
181     aSmaller = PixelToLogic( aSmaller, MAP_POINT );
182     aNewFont.SetSize( aSmaller );
183     maBuildInfoEdit.SetControlFont( aNewFont );
184 }
185 
186 // -----------------------------------------------------------------------
187 
188 void AboutDialog::LayoutControls( Size& aDlgSize )
189 {
190     Size aAppLogoSiz = maAppLogo.GetSizePixel();
191 
192     aDlgSize = GetOutputSizePixel();
193     aDlgSize.Width() = aAppLogoSiz.Width();
194 
195     Size a6Size      = maVersionText.LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
196     long nY          = aAppLogoSiz.Height() + ( a6Size.Height() * 2 );
197     long nDlgMargin  = a6Size.Width() * 2;
198     long nCtrlMargin = a6Size.Height() * 2;
199     long nTextWidth  = aDlgSize.Width() - ( nDlgMargin * 2 );
200 
201     Point aPos( nDlgMargin, nY );
202     Size aSize;
203     // layout fixed text control
204     layoutFixedText( maVersionText, aPos, aSize, nTextWidth );
205     // set the next control closer
206     nY += aSize.Height() + (nCtrlMargin / 2);
207 
208     // Multiline edit with Build info
209     aPos.Y() = nY;
210     layoutEdit( maBuildInfoEdit, aPos, aSize, nTextWidth );
211     nY += aSize.Height() + nCtrlMargin;
212 
213     // Multiline edit with Copyright-Text
214     aPos.Y() = nY;
215     layoutEdit( maCopyrightEdit, aPos, aSize, nTextWidth );
216     // set the next control closer
217     nY += aSize.Height() + (nCtrlMargin/2);
218 
219     // Hyperlink
220     aPos.Y() = nY;
221     layoutFixedText( maCreditsLink, aPos, aSize, nTextWidth );
222     nY += aSize.Height() + nCtrlMargin;
223 
224     // OK-Button-Position (at the bottom and centered)
225     Size aOKSiz = maOKButton.GetSizePixel();
226     Point aOKPnt( ( aDlgSize.Width() - aOKSiz.Width() ) / 2, nY );
227     maOKButton.SetPosPixel( aOKPnt );
228 
229     aDlgSize.Height() = aOKPnt.Y() + aOKSiz.Height() + nCtrlMargin;
230 }
231 
232 // -----------------------------------------------------------------------
233 
234 const rtl::OUString AboutDialog::GetBuildId() const
235 {
236     rtl::OUString sDefault;
237 
238     // Get buildid from version[rc|.ini]
239     rtl::OUString sBuildId( utl::Bootstrap::getBuildIdData( sDefault ) );
240     OSL_ENSURE( sBuildId.getLength() > 0, "No BUILDID in bootstrap file" );
241     rtl::OUStringBuffer sBuildIdBuff( sBuildId );
242 
243     // Get ProductSource from version[rc|.ini]
244     rtl::OUString sProductSource( utl::Bootstrap::getProductSource( sDefault ) );
245     OSL_ENSURE( sProductSource.getLength() > 0, "No ProductSource in bootstrap file" );
246 
247     // the product source is something like "AOO340",
248     // while the build id is something like "340m1(Build:9590)"
249     // For better readability, strip the duplicate ProductMajor ("340").
250     if ( sProductSource.getLength() )
251     {
252         bool bMatchingUPD =
253                 ( sProductSource.getLength() >= 3 )
254             &&  ( sBuildId.getLength() >= 3 )
255             &&  ( sProductSource.copy( sProductSource.getLength() - 3 ) == sBuildId.copy( 0, 3 ) );
256         OSL_ENSURE( bMatchingUPD, "BUILDID and ProductSource do not match in their UPD" );
257         if ( bMatchingUPD )
258             sProductSource = sProductSource.copy( 0, sProductSource.getLength() - 3 );
259 
260         // prepend the product source
261         sBuildIdBuff.insert( 0, sProductSource );
262     }
263 
264     return sBuildIdBuff.makeStringAndClear();
265 }
266 
267 // -----------------------------------------------------------------------
268 
269 const rtl::OUString AboutDialog::GetBuildVersionString() const
270 {
271     rtl::OUStringBuffer aBuildString( GetBuildId() );
272     rtl::OUString sRevision( utl::Bootstrap::getRevisionInfo() );
273 
274     if ( sRevision.getLength() > 0 )
275     {
276         aBuildString.appendAscii( RTL_CONSTASCII_STRINGPARAM( "  -  Rev. " ) );
277         aBuildString.append( sRevision );
278     }
279 
280 #ifdef BUILD_VER_STRING
281     rtl::OUString sBuildVer( RTL_CONSTASCII_USTRINGPARAM( STRINGIFY( BUILD_VER_STRING ) ) );
282     if ( sBuildVer.getLength() > 0 )
283     {
284         aBuildString.append( sal_Unicode( '\n' ) );
285         aBuildString.append( sBuildVer );
286     }
287 #endif
288 
289     return aBuildString.makeStringAndClear();
290 }
291 
292 // -----------------------------------------------------------------------
293 
294 sal_Bool AboutDialog::Close()
295 {
296     EndDialog( RET_OK );
297     return( sal_False );
298 }
299 
300 // -----------------------------------------------------------------------
301 
302 void AboutDialog::Paint( const Rectangle& rRect )
303 {
304     SetClipRegion( rRect );
305     Point aPos( 0, 0 );
306     DrawImage( aPos, maAppLogo );
307 
308     return;
309 }
310 
311 // -----------------------------------------------------------------------
312 
313 IMPL_LINK ( AboutDialog, OpenLinkHdl_Impl, svt::FixedHyperlink*, EMPTYARG )
314 {
315     ::rtl::OUString sURL( maCreditsLink.GetURL() );
316     if ( sURL.getLength() > 0 )
317     {
318         try
319         {
320             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xSMGR =
321                 ::comphelper::getProcessServiceFactory();
322             com::sun::star::uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
323                 xSMGR->createInstance( ::rtl::OUString(
324                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
325                 com::sun::star::uno::UNO_QUERY_THROW );
326             if ( xSystemShell.is() )
327                 xSystemShell->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
328         }
329         catch( const com::sun::star::uno::Exception& e )
330         {
331              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
332                 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
333         }
334     }
335     return 0;
336 }
337