re-write branded image location code in new module, and share with splash

This commit is contained in:
Michael Meeks 2010-10-11 11:52:13 +01:00
parent ff953c36ac
commit a7cfd70670
4 changed files with 85 additions and 64 deletions

View file

@ -318,6 +318,8 @@ public:
SAL_DLLPRIVATE ResMgr* GetOffResManager_Impl();
//#endif
/* loads a branded bitmap - that can be overridden per locale */
static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
/** loads the application logo as used in the about dialog and impress slideshow pause screen */
static Image GetApplicationLogo();
};

View file

@ -0,0 +1,79 @@
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
* Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2010 the
* Initial Developer. All Rights Reserved.
*
* Contributor(s): Michael Meeks <michael.meeks@novell.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sfx2.hxx"
#include <rtl/ustring.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/locale.hxx>
#include <osl/process.h>
#include <tools/urlobj.hxx>
#include <tools/stream.hxx>
#include <vcl/pngread.hxx>
#include <sfx2/app.hxx>
namespace {
static bool loadPng(const char *pPath, const rtl::OUString &rName, BitmapEx &rBitmap)
{
rtl::OUString uri = rtl::OUString::createFromAscii( pPath ) + rName;
rtl::Bootstrap::expandMacros( uri );
INetURLObject aObj( uri );
SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
if ( !aStrm.GetError() ) {
vcl::PNGReader aReader( aStrm );
rBitmap = aReader.Read();
return !rBitmap.IsEmpty();
}
else
return false;
}
}
bool SfxApplication::LoadBrandBitmap (const char* pName, BitmapEx &rBitmap)
{
// TODO - if we want more flexibility we could add a branding path
// in an rc file perhaps fallback to "about.bmp"
rtl::OUString aBaseName = ( rtl::OUString::createFromAscii( "/" ) +
rtl::OUString::createFromAscii( pName ) );
rtl::OUString aPng( RTL_CONSTASCII_USTRINGPARAM(".png") );
rtl_Locale *pLoc = NULL;
osl_getProcessLocale (&pLoc);
rtl::OLocale aLoc( pLoc );
rtl::OUString aName = aBaseName + aPng;
rtl::OUString aLocaleName = ( aBaseName + rtl::OUString::createFromAscii ("-") +
aLoc.getLanguage() +
rtl::OUString::createFromAscii ("_") +
aLoc.getCountry() + aPng );
return ( loadPng ("$BRAND_BASE_DIR/program/edition", aLocaleName, rBitmap) ||
loadPng ("$BRAND_BASE_DIR/program", aLocaleName, rBitmap) ||
loadPng ("$BRAND_BASE_DIR/program/edition", aName, rBitmap) ||
loadPng ("$BRAND_BASE_DIR/program", aName, rBitmap) );
}

View file

@ -88,6 +88,7 @@ SFX_OBJECTS = \
$(SLO)$/appserv.obj \
$(SLO)$/appuno.obj \
$(SLO)$/appbaslib.obj \
$(SLO)$/brand.obj \
$(SLO)$/childwin.obj \
$(SLO)$/fileobj.obj \
$(SLO)$/helpdispatch.obj \

View file

@ -60,73 +60,12 @@
#define WELCOME_URL DEFINE_CONST_UNICODE( "http://www.openoffice.org/welcome/credits.html" )
// class AboutDialog -----------------------------------------------------
static bool impl_loadBitmap(
const rtl::OUString &rPath, const rtl::OUString &rBmpFileName,
Image &rLogo )
{
rtl::OUString uri( rPath );
rtl::Bootstrap::expandMacros( uri );
INetURLObject aObj( uri );
aObj.insertName( rBmpFileName );
SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
if ( !aStrm.GetError() )
{
// Use graphic class to also support more graphic formats (bmp,png,...)
Graphic aGraphic;
GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
pGF->ImportGraphic( aGraphic, String(), aStrm, GRFILTER_FORMAT_DONTKNOW );
// Default case, we load the intro bitmap from a seperate file
// (e.g. staroffice_intro.bmp or starsuite_intro.bmp)
BitmapEx aBmp = aGraphic.GetBitmapEx();
rLogo = Image( aBmp );
return true;
}
return false;
}
/** loads the application logo as used in the about dialog and impress slideshow pause screen */
Image SfxApplication::GetApplicationLogo()
{
Image aAppLogo;
rtl::OUString aAbouts( RTL_CONSTASCII_USTRINGPARAM( ABOUT_BITMAP_STRINGLIST ) );
bool bLoaded = false;
sal_Int32 nIndex = 0;
do
{
bLoaded = impl_loadBitmap(
rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
aAbouts.getToken( 0, ',', nIndex ), aAppLogo );
}
while ( !bLoaded && ( nIndex >= 0 ) );
// fallback to "about.bmp"
if ( !bLoaded )
{
bLoaded = impl_loadBitmap(
rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
if ( !bLoaded )
bLoaded = impl_loadBitmap(
rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
}
if ( !bLoaded )
{
bLoaded = impl_loadBitmap(
rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
if ( !bLoaded )
bLoaded = impl_loadBitmap(
rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
}
return aAppLogo;
BitmapEx aBitmap;
LoadBrandBitmap ("about", aBitmap);
return Image( aBitmap );
}
AboutDialog::AboutDialog( Window* pParent, const ResId& rId, const String& rVerStr ) :