diff options
author | Jan Holesovsky <kendy@suse.cz> | 2013-01-01 22:30:18 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2013-01-04 22:02:51 +0100 |
commit | a2500801cf2d337f176b074f9159df4925420af4 (patch) | |
tree | c512cd0d273ef09f78946db7708353b485d4884e /vcl | |
parent | 0c22f3eadd3ffb461eada94f4b019fbb2161f197 (diff) |
Personas: Read the bitmaps in StyleSettings.
Change-Id: I52b67c82f69059a7d2babf1b49e59f27062cc02c
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/settings.hxx | 9 | ||||
-rw-r--r-- | vcl/source/app/settings.cxx | 110 |
2 files changed, 116 insertions, 3 deletions
diff --git a/vcl/inc/vcl/settings.hxx b/vcl/inc/vcl/settings.hxx index 3a18de34a705..d4d44388d4c4 100644 --- a/vcl/inc/vcl/settings.hxx +++ b/vcl/inc/vcl/settings.hxx @@ -29,6 +29,7 @@ #include <i18npool/languagetag.hxx> #include <unotools/syslocale.hxx> +class BitmapEx; class CollatorWrapper; class LocaleDataWrapper; @@ -347,6 +348,11 @@ private: DialogStyle maDialogStyle; FrameStyle maFrameStyle; const void* mpFontOptions; + + OUString maPersonaHeaderFooter; ///< Cache the settings to detect changes. + + BitmapEx* mpPersonaHeaderBitmap; ///< Cache the header bitmap. + BitmapEx* mpPersonaFooterBitmap; ///< Cache the footer bitmap. }; #define DEFAULT_WORKSPACE_GRADIENT_START_COLOR Color( 0xa3, 0xae, 0xb8 ) @@ -860,6 +866,9 @@ public: void SetFrameStyle( const FrameStyle& rStyle ) { CopyData(); mpData->maFrameStyle = rStyle; } + const BitmapEx* GetPersonaHeader() const; + const BitmapEx* GetPersonaFooter() const; + void SetStandardStyles(); const StyleSettings& operator =( const StyleSettings& rSet ); diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx index 5370f1cc647a..abaff95fb5b7 100644 --- a/vcl/source/app/settings.cxx +++ b/vcl/source/app/settings.cxx @@ -17,9 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <officecfg/Office/Common.hxx> + #include <svsys.h> #include "comphelper/processfactory.hxx" +#include <rtl/bootstrap.hxx> #include "tools/debug.hxx" +#include <vcl/graphicfilter.hxx> #include "i18npool/mslangid.hxx" #include "i18npool/languagetag.hxx" @@ -38,7 +42,7 @@ #include "unotools/confignode.hxx" #include "unotools/syslocaleoptions.hxx" -using ::rtl::OUString; +using namespace ::com::sun::star; #include "svdata.hxx" #include "impimagetree.hxx" @@ -198,7 +202,10 @@ sal_Bool MouseSettings::operator ==( const MouseSettings& rSet ) const // ======================================================================= -ImplStyleData::ImplStyleData() +ImplStyleData::ImplStyleData() : + maPersonaHeaderFooter(), + mpPersonaHeaderBitmap( NULL ), + mpPersonaFooterBitmap( NULL ) { mnRefCount = 1; mnScrollBarSize = 16; @@ -296,7 +303,10 @@ ImplStyleData::ImplStyleData( const ImplStyleData& rData ) : maGroupFont( rData.maGroupFont ), maWorkspaceGradient( rData.maWorkspaceGradient ), maDialogStyle( rData.maDialogStyle ), - maFrameStyle( rData.maFrameStyle ) + maFrameStyle( rData.maFrameStyle ), + maPersonaHeaderFooter( rData.maPersonaHeaderFooter ), + mpPersonaHeaderBitmap( NULL ), + mpPersonaFooterBitmap( NULL ) { mnRefCount = 1; mnBorderSize = rData.mnBorderSize; @@ -677,6 +687,100 @@ sal_Bool StyleSettings::GetUseImagesInMenus() const // ----------------------------------------------------------------------- +static BitmapEx* readBitmapEx( const OUString& rPath ) +{ + OUString aPath( rPath ); + rtl::Bootstrap::expandMacros( aPath ); + + // import the image + Graphic aGraphic; + if ( GraphicFilter::LoadGraphic( aPath, String(), aGraphic ) != GRFILTER_OK ) + return NULL; + + const BitmapEx& rBitmap( aGraphic.GetBitmapEx() ); + if ( rBitmap.IsEmpty() ) + return NULL; + + return new BitmapEx( rBitmap ); +} + +enum WhichPersona { PERSONA_HEADER, PERSONA_FOOTER }; + +/** Update the setting of the Persona header / footer in ImplStyleData */ +static void setupPersonaHeaderFooter( WhichPersona eWhich, OUString& rHeaderFooter, BitmapEx*& pHeaderFooterBitmap ) +{ + uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); + if ( !xContext.is() ) + return; + + // read from the configuration + OUString aPersona( officecfg::Office::Common::Misc::Persona::get( xContext ) ); + OUString aPersonaSettings( officecfg::Office::Common::Misc::PersonaSettings::get( xContext ) ); + + // have the settings changed? + OUString aOldValue( aPersona + ";" + aPersonaSettings ); + if ( rHeaderFooter == aOldValue ) + return; + + rHeaderFooter = aOldValue; + + // now read the new values and setup bitmaps + OUString aHeader, aFooter; + if ( aPersona == "own" ) + { + sal_Int32 nIndex = 0; + aHeader = aPersonaSettings.getToken( 0, ';', nIndex ); + if ( nIndex > 0 ) + aFooter = aPersonaSettings.getToken( 0, ';', nIndex ); + } + else if ( aPersona == "default" ) + { + aHeader = "header.jpg"; + aFooter = "footer.jpg"; + } + + OUString aName; + switch ( eWhich ) { + case PERSONA_HEADER: aName = aHeader; break; + case PERSONA_FOOTER: aName = aFooter; break; + } + + delete pHeaderFooterBitmap; + pHeaderFooterBitmap = NULL; + + if ( !aName.isEmpty() ) + { + // try the gallery first, then edition, and the program path if + // everything else fails + OUString gallery = "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}"; + rtl::Bootstrap::expandMacros( gallery ); + gallery += "/user/gallery/personas/"; + + if ( aPersona == "own" ) + pHeaderFooterBitmap = readBitmapEx( gallery + aName ); + + if ( !pHeaderFooterBitmap ) + pHeaderFooterBitmap = readBitmapEx( "$BRAND_BASE_DIR/program/edition/" + aName ); + + if ( !pHeaderFooterBitmap ) + pHeaderFooterBitmap = readBitmapEx( "$BRAND_BASE_DIR/program/" + aName ); + } +} + +const BitmapEx* StyleSettings::GetPersonaHeader() const +{ + setupPersonaHeaderFooter( PERSONA_HEADER, mpData->maPersonaHeaderFooter, mpData->mpPersonaHeaderBitmap ); + return mpData->mpPersonaHeaderBitmap; +} + +const BitmapEx* StyleSettings::GetPersonaFooter() const +{ + setupPersonaHeaderFooter( PERSONA_FOOTER, mpData->maPersonaHeaderFooter, mpData->mpPersonaFooterBitmap ); + return mpData->mpPersonaFooterBitmap; +} + +// ----------------------------------------------------------------------- + void StyleSettings::SetStandardStyles() { CopyData(); |