xref: /AOO41X/main/cui/source/dialogs/about.cxx (revision 9807c9deeb0645cc3b46a352435b1c57e12b1bca)
12ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52ee96f1cSAndrew Rist  * distributed with this work for additional information
62ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
92ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
152ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
172ee96f1cSAndrew Rist  * specific language governing permissions and limitations
182ee96f1cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202ee96f1cSAndrew Rist  *************************************************************/
212ee96f1cSAndrew Rist 
222ee96f1cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir 
27ca04f111SAriel Constenla-Haile #include <comphelper/processfactory.hxx>
28ca04f111SAriel Constenla-Haile #include <dialmgr.hxx>
29ca04f111SAriel Constenla-Haile #include <osl/file.hxx>
30ca04f111SAriel Constenla-Haile #include <rtl/bootstrap.hxx>
31cdf0e10cSrcweir #include <sfx2/sfxcommands.h>
32ca04f111SAriel Constenla-Haile #include <sfx2/sfxdefs.hxx>
33ca04f111SAriel Constenla-Haile #include <sfx2/sfxuno.hxx>
34ca04f111SAriel Constenla-Haile #include <svtools/filter.hxx>
35cdf0e10cSrcweir #include <svtools/svtools.hrc>
36ca04f111SAriel Constenla-Haile #include <tools/stream.hxx>
37ca04f111SAriel Constenla-Haile #include <tools/urlobj.hxx>
38ca04f111SAriel Constenla-Haile #include <unotools/bootstrap.hxx>
39ca04f111SAriel Constenla-Haile #include <unotools/configmgr.hxx>
40ca04f111SAriel Constenla-Haile #include <vcl/graph.hxx>
417168672cSAriel Constenla-Haile #include <vcl/imagerepository.hxx>
42ca04f111SAriel Constenla-Haile #include <vcl/msgbox.hxx>
43ca04f111SAriel Constenla-Haile #include <vcl/svapp.hxx>
44ca04f111SAriel Constenla-Haile #include <vcl/tabctrl.hxx>
45ca04f111SAriel Constenla-Haile #include <vcl/tabdlg.hxx>
46ca04f111SAriel Constenla-Haile #include <vcl/tabpage.hxx>
47cdf0e10cSrcweir 
4823c0a6f8SAriel Constenla-Haile #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
49*9807c9deSAriel Constenla-Haile #include <com/sun/star/system/SystemShellExecute.hpp>
507168672cSAriel Constenla-Haile #include <com/sun/star/uno/Any.h>
5123c0a6f8SAriel Constenla-Haile 
52ca04f111SAriel Constenla-Haile #include "about.hxx"
53ca04f111SAriel Constenla-Haile #include "about.hrc"
54cdf0e10cSrcweir 
55a392ac37SAriel Constenla-Haile #define _STRINGIFY(x) #x
56a392ac37SAriel Constenla-Haile #define STRINGIFY(x) _STRINGIFY(x)
57cdf0e10cSrcweir 
587168672cSAriel Constenla-Haile /* On Windows/OS2, all the three files have .txt extension
597168672cSAriel Constenla-Haile    and the README file name is in lowercase
607168672cSAriel Constenla-Haile    Readme files are localized and have the locale in their file name:
617168672cSAriel Constenla-Haile    README_de README_en-US
627168672cSAriel Constenla-Haile */
637168672cSAriel Constenla-Haile #if defined(WNT) || defined(OS2)
647168672cSAriel Constenla-Haile #define FILE_EXTENSION  ".txt"
657168672cSAriel Constenla-Haile #define README_FILE     "readme"
667168672cSAriel Constenla-Haile #else
677168672cSAriel Constenla-Haile #define FILE_EXTENSION
687168672cSAriel Constenla-Haile #define README_FILE     "README"
697168672cSAriel Constenla-Haile #endif
707168672cSAriel Constenla-Haile #define LICENSE_FILE    "LICENSE" FILE_EXTENSION
717168672cSAriel Constenla-Haile #define NOTICE_FILE     "NOTICE"  FILE_EXTENSION
727168672cSAriel Constenla-Haile 
737168672cSAriel Constenla-Haile // Dir where the files are located
747168672cSAriel Constenla-Haile #define BRAND_DIR_SHARE_README  "${BRAND_BASE_DIR}/share/readme/"
757168672cSAriel Constenla-Haile 
767168672cSAriel Constenla-Haile using namespace com::sun::star;
777168672cSAriel Constenla-Haile 
78ca04f111SAriel Constenla-Haile namespace
79ca04f111SAriel Constenla-Haile {
80cdf0e10cSrcweir 
81ca04f111SAriel Constenla-Haile     static void lcl_layoutFixedText( FixedText &rControl,
82ca04f111SAriel Constenla-Haile                                      const Point& aPos,
83ca04f111SAriel Constenla-Haile                                      Size &aSize,
84ca04f111SAriel Constenla-Haile                                      const long nTextWidth )
85a392ac37SAriel Constenla-Haile     {
8623c0a6f8SAriel Constenla-Haile         aSize = rControl.GetSizePixel();
8723c0a6f8SAriel Constenla-Haile         // change the width
8823c0a6f8SAriel Constenla-Haile         aSize.Width() = nTextWidth;
8923c0a6f8SAriel Constenla-Haile         // set Position and Size, to calculate the minimum size
9023c0a6f8SAriel Constenla-Haile         // this will update the Height
9123c0a6f8SAriel Constenla-Haile         rControl.SetPosSizePixel( aPos, aSize );
9223c0a6f8SAriel Constenla-Haile         aSize = rControl.CalcMinimumSize();
9323c0a6f8SAriel Constenla-Haile         // update the size with the right Height
9423c0a6f8SAriel Constenla-Haile         rControl.SetSizePixel( aSize );
95a392ac37SAriel Constenla-Haile     }
96cdf0e10cSrcweir 
97ca04f111SAriel Constenla-Haile     static void lcl_layoutEdit( Edit &rControl,
98ca04f111SAriel Constenla-Haile                                 const Point& aPos,
99ca04f111SAriel Constenla-Haile                                 Size &aSize,
100ca04f111SAriel Constenla-Haile                                 const long nTextWidth )
10123c0a6f8SAriel Constenla-Haile     {
10223c0a6f8SAriel Constenla-Haile         aSize = rControl.GetSizePixel();
10323c0a6f8SAriel Constenla-Haile         // change the width
10423c0a6f8SAriel Constenla-Haile         aSize.Width() = nTextWidth;
10523c0a6f8SAriel Constenla-Haile         // set Position and Size, to calculate the minimum size
10623c0a6f8SAriel Constenla-Haile         // this will update the Height
10723c0a6f8SAriel Constenla-Haile         rControl.SetPosSizePixel( aPos, aSize );
10823c0a6f8SAriel Constenla-Haile         aSize = rControl.CalcMinimumSize();
10923c0a6f8SAriel Constenla-Haile         // update the size with the right Height
11023c0a6f8SAriel Constenla-Haile         rControl.SetSizePixel( aSize );
11123c0a6f8SAriel Constenla-Haile     }
112cdf0e10cSrcweir 
113ca04f111SAriel Constenla-Haile     static  void lcl_readTxtFile( const rtl::OUString &rFile, rtl::OUString &sText )
114ca04f111SAriel Constenla-Haile     {
115ca04f111SAriel Constenla-Haile         rtl::OUString sFile( rFile );
116ca04f111SAriel Constenla-Haile         rtl::Bootstrap::expandMacros( sFile );
117ca04f111SAriel Constenla-Haile         osl::File aFile(sFile);
118ca04f111SAriel Constenla-Haile         if ( aFile.open(OpenFlag_Read) == osl::FileBase::E_None )
119ca04f111SAriel Constenla-Haile         {
120ca04f111SAriel Constenla-Haile             osl::DirectoryItem aItem;
121ca04f111SAriel Constenla-Haile             osl::DirectoryItem::get(sFile, aItem);
122ca04f111SAriel Constenla-Haile 
123ca04f111SAriel Constenla-Haile             osl::FileStatus aStatus(FileStatusMask_FileSize);
124ca04f111SAriel Constenla-Haile             aItem.getFileStatus(aStatus);
125ca04f111SAriel Constenla-Haile 
126ca04f111SAriel Constenla-Haile             sal_uInt64 nBytesRead = 0;
127ca04f111SAriel Constenla-Haile             sal_uInt64 nPosition = 0;
128ca04f111SAriel Constenla-Haile             sal_uInt32 nBytes = (sal_uInt32)aStatus.getFileSize();
129ca04f111SAriel Constenla-Haile 
130ca04f111SAriel Constenla-Haile             sal_Char *pBuffer = new sal_Char[nBytes];
131ca04f111SAriel Constenla-Haile 
132ca04f111SAriel Constenla-Haile             while ( aFile.read( pBuffer + nPosition,
133ca04f111SAriel Constenla-Haile                                 nBytes-nPosition,
134ca04f111SAriel Constenla-Haile                                 nBytesRead ) == osl::FileBase::E_None
135ca04f111SAriel Constenla-Haile                     && nPosition + nBytesRead < nBytes)
136ca04f111SAriel Constenla-Haile             {
137ca04f111SAriel Constenla-Haile                 nPosition += nBytesRead;
138ca04f111SAriel Constenla-Haile             }
139ca04f111SAriel Constenla-Haile 
140ca04f111SAriel Constenla-Haile             OSL_ENSURE( nBytes < STRING_MAXLEN, "Text file has too much bytes!" );
141ca04f111SAriel Constenla-Haile             if ( nBytes > STRING_MAXLEN )
142ca04f111SAriel Constenla-Haile                 nBytes = STRING_MAXLEN - 1;
143ca04f111SAriel Constenla-Haile 
144ca04f111SAriel Constenla-Haile             sText = rtl::OUString( pBuffer,
145ca04f111SAriel Constenla-Haile                                 nBytes,
146ca04f111SAriel Constenla-Haile                                 RTL_TEXTENCODING_UTF8,
147ca04f111SAriel Constenla-Haile                                 OSTRING_TO_OUSTRING_CVTFLAGS
148ca04f111SAriel Constenla-Haile                                 | RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE);
149ca04f111SAriel Constenla-Haile             delete[] pBuffer;
150ca04f111SAriel Constenla-Haile         }
151ca04f111SAriel Constenla-Haile     }
152ca04f111SAriel Constenla-Haile 
153ca04f111SAriel Constenla-Haile     class ReadmeDialog;
154ca04f111SAriel Constenla-Haile 
155ca04f111SAriel Constenla-Haile     class ReadmeTabPage : public TabPage
156ca04f111SAriel Constenla-Haile     {
157ca04f111SAriel Constenla-Haile     private:
158ca04f111SAriel Constenla-Haile         MultiLineEdit maText;
159ca04f111SAriel Constenla-Haile         String        msText;
160ca04f111SAriel Constenla-Haile 
161ca04f111SAriel Constenla-Haile     public:
162ca04f111SAriel Constenla-Haile         ReadmeTabPage(Window *pParent, const String &sText);
163ca04f111SAriel Constenla-Haile         ~ReadmeTabPage();
164ca04f111SAriel Constenla-Haile 
165ca04f111SAriel Constenla-Haile         void Adjust(const Size &aSz, const Size &a6Size);
166ca04f111SAriel Constenla-Haile     };
167ca04f111SAriel Constenla-Haile 
168ca04f111SAriel Constenla-Haile     ReadmeTabPage::ReadmeTabPage(Window *pParent, const String &sText)
169ca04f111SAriel Constenla-Haile         : TabPage(pParent, CUI_RES( RID_CUI_README_TBPAGE))
170ca04f111SAriel Constenla-Haile         ,maText( this, CUI_RES( RID_CUI_README_TBPAGE_EDIT ))
171ca04f111SAriel Constenla-Haile         ,msText( sText )
172ca04f111SAriel Constenla-Haile     {
173ca04f111SAriel Constenla-Haile         FreeResource();
174ca04f111SAriel Constenla-Haile 
175ca04f111SAriel Constenla-Haile         maText.SetText(msText);
176ca04f111SAriel Constenla-Haile         maText.Show();
177ca04f111SAriel Constenla-Haile     }
178ca04f111SAriel Constenla-Haile 
179ca04f111SAriel Constenla-Haile     ReadmeTabPage::~ReadmeTabPage()
180ca04f111SAriel Constenla-Haile     {
181ca04f111SAriel Constenla-Haile     }
182ca04f111SAriel Constenla-Haile 
183ca04f111SAriel Constenla-Haile     void ReadmeTabPage::Adjust(const Size &aSz, const Size &a6Size)
184ca04f111SAriel Constenla-Haile     {
185ca04f111SAriel Constenla-Haile         long nDlgMargin  = a6Size.Width() * 2;
186ca04f111SAriel Constenla-Haile         long nCtrlMargin = a6Size.Height() * 2;
187ca04f111SAriel Constenla-Haile         maText.SetPosPixel( Point(a6Size.Width(), a6Size.Height()) );
188ca04f111SAriel Constenla-Haile         maText.SetSizePixel( Size(aSz.Width() - nDlgMargin, aSz.Height() - nCtrlMargin) );
189ca04f111SAriel Constenla-Haile     }
190ca04f111SAriel Constenla-Haile 
191ca04f111SAriel Constenla-Haile     class ReadmeDialog : public ModalDialog
192ca04f111SAriel Constenla-Haile     {
193ca04f111SAriel Constenla-Haile     private:
194ca04f111SAriel Constenla-Haile         TabControl      maTabCtrl;
195ca04f111SAriel Constenla-Haile         OKButton        maBtnOK;
196ca04f111SAriel Constenla-Haile 
197ca04f111SAriel Constenla-Haile         ReadmeTabPage  *maReadmeTabPage;
198ca04f111SAriel Constenla-Haile         ReadmeTabPage  *maLicenseTabPage;
199ca04f111SAriel Constenla-Haile         ReadmeTabPage  *maNoticeTabPage;
200ca04f111SAriel Constenla-Haile 
201ca04f111SAriel Constenla-Haile         DECL_LINK( ActivatePageHdl, TabControl * );
202ca04f111SAriel Constenla-Haile         DECL_LINK( DeactivatePageHdl, TabControl * );
203ca04f111SAriel Constenla-Haile 
204ca04f111SAriel Constenla-Haile     public:
205ca04f111SAriel Constenla-Haile         ReadmeDialog( Window* );
206ca04f111SAriel Constenla-Haile         ~ReadmeDialog();
207ca04f111SAriel Constenla-Haile     };
208ca04f111SAriel Constenla-Haile 
209ca04f111SAriel Constenla-Haile     ReadmeDialog::ReadmeDialog( Window * pParent )
210ca04f111SAriel Constenla-Haile         : ModalDialog( pParent, CUI_RES( RID_CUI_README_DLG ) )
211ca04f111SAriel Constenla-Haile         , maTabCtrl( this, CUI_RES(RID_CUI_README_TBCTL) )
212ca04f111SAriel Constenla-Haile         , maBtnOK( this, CUI_RES(RID_CUI_README_OKBTN) )
213ca04f111SAriel Constenla-Haile         , maReadmeTabPage(0)
214ca04f111SAriel Constenla-Haile         , maLicenseTabPage(0)
215ca04f111SAriel Constenla-Haile         , maNoticeTabPage(0)
216ca04f111SAriel Constenla-Haile     {
217ca04f111SAriel Constenla-Haile         FreeResource();
218ca04f111SAriel Constenla-Haile 
219ca04f111SAriel Constenla-Haile         maTabCtrl.Show();
220ca04f111SAriel Constenla-Haile 
2217168672cSAriel Constenla-Haile         // Notice and License are not localized
2227168672cSAriel Constenla-Haile         const rtl::OUString sLicense( RTL_CONSTASCII_USTRINGPARAM( BRAND_DIR_SHARE_README LICENSE_FILE ) );
2237168672cSAriel Constenla-Haile         const rtl::OUString sNotice( RTL_CONSTASCII_USTRINGPARAM(  BRAND_DIR_SHARE_README NOTICE_FILE ) );
2247168672cSAriel Constenla-Haile 
2257168672cSAriel Constenla-Haile         // get localized README
2267168672cSAriel Constenla-Haile         rtl::OUStringBuffer aBuff;
2277168672cSAriel Constenla-Haile         lang::Locale aLocale = Application::GetSettings().GetUILocale();
2287168672cSAriel Constenla-Haile         aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( BRAND_DIR_SHARE_README README_FILE "_" ) );
2297168672cSAriel Constenla-Haile         aBuff.append( aLocale.Language );
2307168672cSAriel Constenla-Haile         if ( aLocale.Country.getLength() )
2317168672cSAriel Constenla-Haile         {
2327168672cSAriel Constenla-Haile             aBuff.append( sal_Unicode( '-') );
2337168672cSAriel Constenla-Haile             aBuff.append( aLocale.Country );
2347168672cSAriel Constenla-Haile             if ( aLocale.Variant.getLength() )
2357168672cSAriel Constenla-Haile             {
2367168672cSAriel Constenla-Haile                 aBuff.append( sal_Unicode( '-' ) );
2377168672cSAriel Constenla-Haile                 aBuff.append( aLocale.Variant );
2387168672cSAriel Constenla-Haile             }
2397168672cSAriel Constenla-Haile         }
2407168672cSAriel Constenla-Haile #if defined(WNT) || defined(OS2)
2417168672cSAriel Constenla-Haile         aBuff.appendAscii( RTL_CONSTASCII_STRINGPARAM( FILE_EXTENSION ) );
2427168672cSAriel Constenla-Haile #endif
243ca04f111SAriel Constenla-Haile 
244ca04f111SAriel Constenla-Haile         rtl::OUString sReadmeTxt, sLicenseTxt, sNoticeTxt;
2457168672cSAriel Constenla-Haile         lcl_readTxtFile( aBuff.makeStringAndClear(), sReadmeTxt );
246ca04f111SAriel Constenla-Haile         lcl_readTxtFile( sLicense, sLicenseTxt );
247ca04f111SAriel Constenla-Haile         lcl_readTxtFile( sNotice, sNoticeTxt );
248ca04f111SAriel Constenla-Haile 
249ca04f111SAriel Constenla-Haile         maReadmeTabPage = new ReadmeTabPage( &maTabCtrl, sReadmeTxt );
250ca04f111SAriel Constenla-Haile         maLicenseTabPage = new ReadmeTabPage( &maTabCtrl, sLicenseTxt );
251ca04f111SAriel Constenla-Haile         maNoticeTabPage = new ReadmeTabPage( &maTabCtrl, sNoticeTxt );
252ca04f111SAriel Constenla-Haile 
253ca04f111SAriel Constenla-Haile         maTabCtrl.SetTabPage( RID_CUI_READMEPAGE, maReadmeTabPage );
254ca04f111SAriel Constenla-Haile         maTabCtrl.SetTabPage( RID_CUI_LICENSEPAGE, maLicenseTabPage );
255ca04f111SAriel Constenla-Haile         maTabCtrl.SetTabPage( RID_CUI_NOTICEPAGE, maNoticeTabPage );
256ca04f111SAriel Constenla-Haile 
257ca04f111SAriel Constenla-Haile         maTabCtrl.SelectTabPage( RID_CUI_READMEPAGE );
258ca04f111SAriel Constenla-Haile 
259ca04f111SAriel Constenla-Haile         Size aTpSz  = maReadmeTabPage->GetOutputSizePixel();
260ca04f111SAriel Constenla-Haile         Size a6Size = maReadmeTabPage->LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
261ca04f111SAriel Constenla-Haile 
262ca04f111SAriel Constenla-Haile         maReadmeTabPage->Adjust( aTpSz, a6Size );
263ca04f111SAriel Constenla-Haile         maLicenseTabPage->Adjust( aTpSz, a6Size );
264ca04f111SAriel Constenla-Haile         maNoticeTabPage->Adjust( aTpSz, a6Size );
265ca04f111SAriel Constenla-Haile 
266ca04f111SAriel Constenla-Haile         Size aDlgSize = GetOutputSizePixel();
267ca04f111SAriel Constenla-Haile         Size aOkBtnSz = maBtnOK.GetSizePixel();
268ca04f111SAriel Constenla-Haile         Point aOKPnt( aDlgSize.Width() / 2 - aOkBtnSz.Width() / 2 , maBtnOK.GetPosPixel().Y() );
269ca04f111SAriel Constenla-Haile         maBtnOK.SetPosPixel( aOKPnt );
270ca04f111SAriel Constenla-Haile     }
271ca04f111SAriel Constenla-Haile 
272ca04f111SAriel Constenla-Haile     ReadmeDialog::~ReadmeDialog()
273ca04f111SAriel Constenla-Haile     {
274ca04f111SAriel Constenla-Haile         delete maReadmeTabPage;
275ca04f111SAriel Constenla-Haile         delete maLicenseTabPage;
276ca04f111SAriel Constenla-Haile         delete maNoticeTabPage;
277ca04f111SAriel Constenla-Haile     }
278ca04f111SAriel Constenla-Haile }
279ca04f111SAriel Constenla-Haile 
28023c0a6f8SAriel Constenla-Haile // -----------------------------------------------------------------------
281cdf0e10cSrcweir 
28223c0a6f8SAriel Constenla-Haile AboutDialog::AboutDialog( Window* pParent, const ResId& rId ) :
28323c0a6f8SAriel Constenla-Haile     SfxModalDialog( pParent, rId ),
28423c0a6f8SAriel Constenla-Haile     maOKButton( this, ResId( RID_CUI_ABOUT_BTN_OK, *rId.GetResMgr() ) ),
285ca04f111SAriel Constenla-Haile     maReadmeButton( this, ResId( RID_CUI_ABOUT_BTN_README, *rId.GetResMgr() ) ),
28623c0a6f8SAriel Constenla-Haile     maVersionText( this, ResId( RID_CUI_ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
28723c0a6f8SAriel Constenla-Haile     maBuildInfoEdit( this, ResId( RID_CUI_ABOUT_FTXT_BUILDDATA, *rId.GetResMgr() ) ),
28823c0a6f8SAriel Constenla-Haile     maCopyrightEdit( this, ResId( RID_CUI_ABOUT_FTXT_COPYRIGHT, *rId.GetResMgr() ) ),
28923c0a6f8SAriel Constenla-Haile     maCreditsLink( this, ResId( RID_CUI_ABOUT_FTXT_WELCOME_LINK, *rId.GetResMgr() )  ),
29023c0a6f8SAriel Constenla-Haile     maCopyrightTextStr( ResId( RID_CUI_ABOUT_STR_COPYRIGHT, *rId.GetResMgr() ) )
29123c0a6f8SAriel Constenla-Haile {
2927168672cSAriel Constenla-Haile     bool bLoad = vcl::ImageRepository::loadBrandingImage(
2937168672cSAriel Constenla-Haile             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("about")),
2947168672cSAriel Constenla-Haile             maAppLogo );
2957168672cSAriel Constenla-Haile     OSL_ENSURE( bLoad, "Can't load about image");
2967168672cSAriel Constenla-Haile 
2977168672cSAriel Constenla-Haile     bLoad = vcl::ImageRepository::loadBrandingImage(
2987168672cSAriel Constenla-Haile             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("logo")),
2997168672cSAriel Constenla-Haile             maMainLogo );
3007168672cSAriel Constenla-Haile     OSL_ENSURE( bLoad, "Can't load logo image");
301cdf0e10cSrcweir 
30223c0a6f8SAriel Constenla-Haile     InitControls();
303cdf0e10cSrcweir 
30423c0a6f8SAriel Constenla-Haile     // set links
305ca04f111SAriel Constenla-Haile     maReadmeButton.SetClickHdl( LINK( this, AboutDialog, ShowReadme_Impl ) );
30623c0a6f8SAriel Constenla-Haile     maCreditsLink.SetClickHdl( LINK( this, AboutDialog, OpenLinkHdl_Impl ) );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     FreeResource();
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     SetHelpId( CMD_SID_ABOUT );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir // -----------------------------------------------------------------------
314cdf0e10cSrcweir 
315cdf0e10cSrcweir AboutDialog::~AboutDialog()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // -----------------------------------------------------------------------
320cdf0e10cSrcweir 
32123c0a6f8SAriel Constenla-Haile void AboutDialog::InitControls()
322cdf0e10cSrcweir {
32323c0a6f8SAriel Constenla-Haile     // apply font, background et al.
32423c0a6f8SAriel Constenla-Haile     ApplyStyleSettings();
32523c0a6f8SAriel Constenla-Haile 
32623c0a6f8SAriel Constenla-Haile     // set strings
32723c0a6f8SAriel Constenla-Haile     maCopyrightEdit.SetText( maCopyrightTextStr );
32823c0a6f8SAriel Constenla-Haile     maBuildInfoEdit.SetText( GetBuildVersionString() );
32923c0a6f8SAriel Constenla-Haile     maCreditsLink.SetURL( maCreditsLink.GetText() );
33023c0a6f8SAriel Constenla-Haile 
33123c0a6f8SAriel Constenla-Haile     // determine size and position of the dialog & elements
33223c0a6f8SAriel Constenla-Haile     Size aDlgSize;
33323c0a6f8SAriel Constenla-Haile     LayoutControls( aDlgSize );
33423c0a6f8SAriel Constenla-Haile 
33523c0a6f8SAriel Constenla-Haile     // Change the width of the dialog
33623c0a6f8SAriel Constenla-Haile     SetOutputSizePixel( aDlgSize );
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir // -----------------------------------------------------------------------
340cdf0e10cSrcweir 
34123c0a6f8SAriel Constenla-Haile void AboutDialog::ApplyStyleSettings()
342cdf0e10cSrcweir {
34323c0a6f8SAriel Constenla-Haile     // Transparenter Font
34423c0a6f8SAriel Constenla-Haile     Font aFont = GetFont();
34523c0a6f8SAriel Constenla-Haile     aFont.SetTransparent( sal_True );
34623c0a6f8SAriel Constenla-Haile     SetFont( aFont );
34723c0a6f8SAriel Constenla-Haile 
34823c0a6f8SAriel Constenla-Haile     // set for background and text the correct system color
34923c0a6f8SAriel Constenla-Haile     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
3507168672cSAriel Constenla-Haile     Color aWindowColor( rSettings.GetWindowColor() );
3517168672cSAriel Constenla-Haile     Wallpaper aWall( aWindowColor );
35223c0a6f8SAriel Constenla-Haile     SetBackground( aWall );
35323c0a6f8SAriel Constenla-Haile     Font aNewFont( maCopyrightEdit.GetFont() );
35423c0a6f8SAriel Constenla-Haile     aNewFont.SetTransparent( sal_True );
35523c0a6f8SAriel Constenla-Haile 
35623c0a6f8SAriel Constenla-Haile     maVersionText.SetFont( aNewFont );
35723c0a6f8SAriel Constenla-Haile     maCopyrightEdit.SetFont( aNewFont );
35823c0a6f8SAriel Constenla-Haile 
3597168672cSAriel Constenla-Haile     maVersionText.SetBackground(aWall);
3607168672cSAriel Constenla-Haile     maCopyrightEdit.SetBackground(aWall);
3617168672cSAriel Constenla-Haile     maBuildInfoEdit.SetBackground(aWall);
3627168672cSAriel Constenla-Haile     maCreditsLink.SetBackground(aWall);
36323c0a6f8SAriel Constenla-Haile 
36423c0a6f8SAriel Constenla-Haile     Color aTextColor( rSettings.GetWindowTextColor() );
36523c0a6f8SAriel Constenla-Haile     maVersionText.SetControlForeground( aTextColor );
36623c0a6f8SAriel Constenla-Haile     maCopyrightEdit.SetControlForeground( aTextColor );
36723c0a6f8SAriel Constenla-Haile     maBuildInfoEdit.SetControlForeground( aTextColor );
36823c0a6f8SAriel Constenla-Haile     maCreditsLink.SetControlForeground();
36923c0a6f8SAriel Constenla-Haile 
37023c0a6f8SAriel Constenla-Haile     Size aSmaller = aNewFont.GetSize();
37123c0a6f8SAriel Constenla-Haile     aSmaller.Width() = (long) (aSmaller.Width() * 0.75);
37223c0a6f8SAriel Constenla-Haile     aSmaller.Height() = (long) (aSmaller.Height() * 0.75);
37323c0a6f8SAriel Constenla-Haile     aNewFont.SetSize( aSmaller );
37423c0a6f8SAriel Constenla-Haile 
37523c0a6f8SAriel Constenla-Haile     maBuildInfoEdit.SetFont( aNewFont );
37623c0a6f8SAriel Constenla-Haile 
37723c0a6f8SAriel Constenla-Haile     // the following is a hack to force the MultiLineEdit update its settings
37823c0a6f8SAriel Constenla-Haile     // in order to reflect the Font
37923c0a6f8SAriel Constenla-Haile     // See
38023c0a6f8SAriel Constenla-Haile     //      Window::SetControlFont
38123c0a6f8SAriel Constenla-Haile     //      MultiLineEdit::StateChanged
38223c0a6f8SAriel Constenla-Haile     //      MultiLineEdit::ImplInitSettings
38323c0a6f8SAriel Constenla-Haile     // TODO Override SetFont in MultiLineEdit and do the following,
38423c0a6f8SAriel Constenla-Haile     // otherwise SetFont has no effect at all!
38523c0a6f8SAriel Constenla-Haile     aSmaller = PixelToLogic( aSmaller, MAP_POINT );
38623c0a6f8SAriel Constenla-Haile     aNewFont.SetSize( aSmaller );
38723c0a6f8SAriel Constenla-Haile     maBuildInfoEdit.SetControlFont( aNewFont );
38823c0a6f8SAriel Constenla-Haile }
38923c0a6f8SAriel Constenla-Haile 
39023c0a6f8SAriel Constenla-Haile // -----------------------------------------------------------------------
39123c0a6f8SAriel Constenla-Haile 
39223c0a6f8SAriel Constenla-Haile void AboutDialog::LayoutControls( Size& aDlgSize )
39323c0a6f8SAriel Constenla-Haile {
394ca04f111SAriel Constenla-Haile     Size aMainLogoSz = maMainLogo.GetSizePixel();
39523c0a6f8SAriel Constenla-Haile     Size aAppLogoSiz = maAppLogo.GetSizePixel();
39623c0a6f8SAriel Constenla-Haile 
39723c0a6f8SAriel Constenla-Haile     aDlgSize = GetOutputSizePixel();
398325547baSAriel Constenla-Haile     long nCol1 = aMainLogoSz.Width();
399325547baSAriel Constenla-Haile     long nCol2 = aAppLogoSiz.Width() ? aAppLogoSiz.Width() : aDlgSize.Width();
40023c0a6f8SAriel Constenla-Haile 
40123c0a6f8SAriel Constenla-Haile     Size a6Size      = maVersionText.LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
40223c0a6f8SAriel Constenla-Haile     long nDlgMargin  = a6Size.Width() * 2;
40323c0a6f8SAriel Constenla-Haile     long nCtrlMargin = a6Size.Height() * 2;
404325547baSAriel Constenla-Haile     long nTextWidth  = nCol2 - nDlgMargin;
405ca04f111SAriel Constenla-Haile     long nY          = aAppLogoSiz.Height() + a6Size.Height();
40623c0a6f8SAriel Constenla-Haile 
407325547baSAriel Constenla-Haile     aDlgSize.Width() = nCol1 + a6Size.Width() + nCol2;
408ca04f111SAriel Constenla-Haile 
409325547baSAriel Constenla-Haile     Point aPos( nCol1 + a6Size.Width(), nY );
41023c0a6f8SAriel Constenla-Haile     Size aSize;
41123c0a6f8SAriel Constenla-Haile     // layout fixed text control
412ca04f111SAriel Constenla-Haile     lcl_layoutFixedText( maVersionText, aPos, aSize, nTextWidth );
413ca04f111SAriel Constenla-Haile     nY += aSize.Height() + a6Size.Height();
41423c0a6f8SAriel Constenla-Haile 
41523c0a6f8SAriel Constenla-Haile     // Multiline edit with Build info
41623c0a6f8SAriel Constenla-Haile     aPos.Y() = nY;
417ca04f111SAriel Constenla-Haile     lcl_layoutEdit( maBuildInfoEdit, aPos, aSize, nTextWidth );
418ca04f111SAriel Constenla-Haile     nY += aSize.Height() + a6Size.Height();
41923c0a6f8SAriel Constenla-Haile 
42023c0a6f8SAriel Constenla-Haile     // Multiline edit with Copyright-Text
42123c0a6f8SAriel Constenla-Haile     aPos.Y() = nY;
422ca04f111SAriel Constenla-Haile     lcl_layoutEdit( maCopyrightEdit, aPos, aSize, nTextWidth );
423ca04f111SAriel Constenla-Haile     nY += aSize.Height() + a6Size.Height();
42423c0a6f8SAriel Constenla-Haile 
42523c0a6f8SAriel Constenla-Haile     // Hyperlink
42623c0a6f8SAriel Constenla-Haile     aPos.Y() = nY;
427ca04f111SAriel Constenla-Haile     lcl_layoutFixedText( maCreditsLink, aPos, aSize, nTextWidth );
428ca04f111SAriel Constenla-Haile     nY += aSize.Height();
429ca04f111SAriel Constenla-Haile 
430ca04f111SAriel Constenla-Haile     nY = std::max( nY, aMainLogoSz.Height() );
431ca04f111SAriel Constenla-Haile     nY += nCtrlMargin;
432ca04f111SAriel Constenla-Haile 
433ca04f111SAriel Constenla-Haile     // logos position
434ca04f111SAriel Constenla-Haile     maMainLogoPos = Point( 0, nY / 2 - aMainLogoSz.Height() / 2 );
435325547baSAriel Constenla-Haile     maAppLogoPos = Point( nCol1 + a6Size.Width(), 0 );
43623c0a6f8SAriel Constenla-Haile 
43723c0a6f8SAriel Constenla-Haile     // OK-Button-Position (at the bottom and centered)
43823c0a6f8SAriel Constenla-Haile     Size aOKSiz = maOKButton.GetSizePixel();
439ca04f111SAriel Constenla-Haile     Point aOKPnt( ( aDlgSize.Width() - aOKSiz.Width() ) - a6Size.Width(), nY );
44023c0a6f8SAriel Constenla-Haile     maOKButton.SetPosPixel( aOKPnt );
44123c0a6f8SAriel Constenla-Haile 
442ca04f111SAriel Constenla-Haile     maReadmeButton.SetPosPixel( Point(a6Size.Width(), nY) );
443ca04f111SAriel Constenla-Haile 
444ca04f111SAriel Constenla-Haile     aDlgSize.Height() = aOKPnt.Y() + aOKSiz.Height() + a6Size.Width();
44523c0a6f8SAriel Constenla-Haile }
44623c0a6f8SAriel Constenla-Haile 
44723c0a6f8SAriel Constenla-Haile // -----------------------------------------------------------------------
44823c0a6f8SAriel Constenla-Haile 
44923c0a6f8SAriel Constenla-Haile const rtl::OUString AboutDialog::GetBuildId() const
45023c0a6f8SAriel Constenla-Haile {
45123c0a6f8SAriel Constenla-Haile     rtl::OUString sDefault;
45223c0a6f8SAriel Constenla-Haile 
45323c0a6f8SAriel Constenla-Haile     // Get buildid from version[rc|.ini]
45423c0a6f8SAriel Constenla-Haile     rtl::OUString sBuildId( utl::Bootstrap::getBuildIdData( sDefault ) );
45523c0a6f8SAriel Constenla-Haile     OSL_ENSURE( sBuildId.getLength() > 0, "No BUILDID in bootstrap file" );
45623c0a6f8SAriel Constenla-Haile     rtl::OUStringBuffer sBuildIdBuff( sBuildId );
45723c0a6f8SAriel Constenla-Haile 
45823c0a6f8SAriel Constenla-Haile     // Get ProductSource from version[rc|.ini]
45923c0a6f8SAriel Constenla-Haile     rtl::OUString sProductSource( utl::Bootstrap::getProductSource( sDefault ) );
46023c0a6f8SAriel Constenla-Haile     OSL_ENSURE( sProductSource.getLength() > 0, "No ProductSource in bootstrap file" );
46123c0a6f8SAriel Constenla-Haile 
46223c0a6f8SAriel Constenla-Haile     // the product source is something like "AOO340",
46323c0a6f8SAriel Constenla-Haile     // while the build id is something like "340m1(Build:9590)"
46423c0a6f8SAriel Constenla-Haile     // For better readability, strip the duplicate ProductMajor ("340").
46523c0a6f8SAriel Constenla-Haile     if ( sProductSource.getLength() )
46623c0a6f8SAriel Constenla-Haile     {
46723c0a6f8SAriel Constenla-Haile         bool bMatchingUPD =
46823c0a6f8SAriel Constenla-Haile                 ( sProductSource.getLength() >= 3 )
46923c0a6f8SAriel Constenla-Haile             &&  ( sBuildId.getLength() >= 3 )
47023c0a6f8SAriel Constenla-Haile             &&  ( sProductSource.copy( sProductSource.getLength() - 3 ) == sBuildId.copy( 0, 3 ) );
47123c0a6f8SAriel Constenla-Haile         OSL_ENSURE( bMatchingUPD, "BUILDID and ProductSource do not match in their UPD" );
47223c0a6f8SAriel Constenla-Haile         if ( bMatchingUPD )
47323c0a6f8SAriel Constenla-Haile             sProductSource = sProductSource.copy( 0, sProductSource.getLength() - 3 );
47423c0a6f8SAriel Constenla-Haile 
47523c0a6f8SAriel Constenla-Haile         // prepend the product source
47623c0a6f8SAriel Constenla-Haile         sBuildIdBuff.insert( 0, sProductSource );
47723c0a6f8SAriel Constenla-Haile     }
47823c0a6f8SAriel Constenla-Haile 
47923c0a6f8SAriel Constenla-Haile     return sBuildIdBuff.makeStringAndClear();
48023c0a6f8SAriel Constenla-Haile }
48123c0a6f8SAriel Constenla-Haile 
48223c0a6f8SAriel Constenla-Haile // -----------------------------------------------------------------------
48323c0a6f8SAriel Constenla-Haile 
48423c0a6f8SAriel Constenla-Haile const rtl::OUString AboutDialog::GetBuildVersionString() const
48523c0a6f8SAriel Constenla-Haile {
48623c0a6f8SAriel Constenla-Haile     rtl::OUStringBuffer aBuildString( GetBuildId() );
48723c0a6f8SAriel Constenla-Haile     rtl::OUString sRevision( utl::Bootstrap::getRevisionInfo() );
48823c0a6f8SAriel Constenla-Haile 
48923c0a6f8SAriel Constenla-Haile     if ( sRevision.getLength() > 0 )
49023c0a6f8SAriel Constenla-Haile     {
49123c0a6f8SAriel Constenla-Haile         aBuildString.appendAscii( RTL_CONSTASCII_STRINGPARAM( "  -  Rev. " ) );
49223c0a6f8SAriel Constenla-Haile         aBuildString.append( sRevision );
49323c0a6f8SAriel Constenla-Haile     }
49423c0a6f8SAriel Constenla-Haile 
49523c0a6f8SAriel Constenla-Haile #ifdef BUILD_VER_STRING
49623c0a6f8SAriel Constenla-Haile     rtl::OUString sBuildVer( RTL_CONSTASCII_USTRINGPARAM( STRINGIFY( BUILD_VER_STRING ) ) );
49723c0a6f8SAriel Constenla-Haile     if ( sBuildVer.getLength() > 0 )
49823c0a6f8SAriel Constenla-Haile     {
49923c0a6f8SAriel Constenla-Haile         aBuildString.append( sal_Unicode( '\n' ) );
50023c0a6f8SAriel Constenla-Haile         aBuildString.append( sBuildVer );
50123c0a6f8SAriel Constenla-Haile     }
502cdf0e10cSrcweir #endif
503cdf0e10cSrcweir 
50423c0a6f8SAriel Constenla-Haile     return aBuildString.makeStringAndClear();
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir // -----------------------------------------------------------------------
508cdf0e10cSrcweir 
509cdf0e10cSrcweir sal_Bool AboutDialog::Close()
510cdf0e10cSrcweir {
511cdf0e10cSrcweir     EndDialog( RET_OK );
512cdf0e10cSrcweir     return( sal_False );
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir // -----------------------------------------------------------------------
516cdf0e10cSrcweir 
517cdf0e10cSrcweir void AboutDialog::Paint( const Rectangle& rRect )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir     SetClipRegion( rRect );
520ca04f111SAriel Constenla-Haile     DrawImage( maMainLogoPos, maMainLogo );
521ca04f111SAriel Constenla-Haile     DrawImage( maAppLogoPos, maAppLogo );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     return;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
52623c0a6f8SAriel Constenla-Haile // -----------------------------------------------------------------------
527cdf0e10cSrcweir 
52823c0a6f8SAriel Constenla-Haile IMPL_LINK ( AboutDialog, OpenLinkHdl_Impl, svt::FixedHyperlink*, EMPTYARG )
529cdf0e10cSrcweir {
53023c0a6f8SAriel Constenla-Haile     ::rtl::OUString sURL( maCreditsLink.GetURL() );
53123c0a6f8SAriel Constenla-Haile     if ( sURL.getLength() > 0 )
532cdf0e10cSrcweir     {
53323c0a6f8SAriel Constenla-Haile         try
534cdf0e10cSrcweir         {
5354ad1da77SJian Fang Zhang             uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
536*9807c9deSAriel Constenla-Haile                 com::sun::star::system::SystemShellExecute::create(
537*9807c9deSAriel Constenla-Haile                     ::comphelper::getProcessComponentContext() ) );
53823c0a6f8SAriel Constenla-Haile             if ( xSystemShell.is() )
5394ad1da77SJian Fang Zhang                 xSystemShell->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
540cdf0e10cSrcweir         }
5417168672cSAriel Constenla-Haile         catch( const uno::Exception& e )
542cdf0e10cSrcweir         {
54323c0a6f8SAriel Constenla-Haile              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
54423c0a6f8SAriel Constenla-Haile                 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
545cdf0e10cSrcweir         }
546cdf0e10cSrcweir     }
5477168672cSAriel Constenla-Haile 
54823c0a6f8SAriel Constenla-Haile     return 0;
54923c0a6f8SAriel Constenla-Haile }
550ca04f111SAriel Constenla-Haile 
551ca04f111SAriel Constenla-Haile IMPL_LINK ( AboutDialog, ShowReadme_Impl, PushButton*, EMPTYARG )
552ca04f111SAriel Constenla-Haile {
553ca04f111SAriel Constenla-Haile     ReadmeDialog aDlg( this );
554ca04f111SAriel Constenla-Haile     aDlg.Execute();
555ca04f111SAriel Constenla-Haile 
556ca04f111SAriel Constenla-Haile     return 0;
557ca04f111SAriel Constenla-Haile }
558