/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
void Load(const OUString& rScheme); void CommitCurrentSchemeName(); //changes the name of the current scheme but doesn't load it! void SetCurrentSchemeName(const OUString& rSchemeName) {m_sLoadedScheme = rSchemeName;} virtualvoid Notify( const uno::Sequence<OUString>& aPropertyNames) override;
void AddScheme(const OUString& rNode); void RemoveScheme(const OUString& rNode); using ConfigItem::SetModified; using ConfigItem::ClearModified; void SettingsChanged(); void SetupTheme(); const OUString& GetCurrentSchemeName(); void LoadThemeColorsFromRegistry(); // get the configured value - if bSmart is set the default color setting is provided // instead of the automatic color
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart = true) const;
uno::Sequence< OUString> GetPropertyNames(std::u16string_view rScheme)
{
uno::Sequence<OUString> aNames(3 * ColorConfigEntryCount);
OUString* pNames = aNames.getArray(); int nIndex = 0;
OUString sBase = "ColorSchemes/"
+ utl::wrapConfigurationElementName(rScheme); for(sal_Int32 i = 0; i < ColorConfigEntryCount; ++i)
{ // every property has two entries, one for light color and one // for dark color. and an optional visibility entry based on // cNames[nIndex].bCanBeVisible
OUString sBaseName = sBase + "/" + cNames[i].cName;
pNames[nIndex++] = sBaseName + "/Color";
ColorConfig_Impl::ColorConfig_Impl() :
ConfigItem(u"Office.UI/ColorScheme"_ustr)
{ //try to register on the root node - if possible
uno::Sequence < OUString > aNames(1);
EnableNotification( aNames );
// use automatic theme as the fallback, in case the theme extension was removed if (ThemeColors::IsCustomTheme(sScheme))
{
uno::Sequence<OUString> aSchemes = GetSchemeNames(); bool bFound = std::any_of(aSchemes.begin(), aSchemes.end(),
[&sScheme](const OUString& rSchemeName) { return sScheme == rSchemeName; });
if (!pColors[nIndex].hasValue())
m_aConfigValues[i].nColor = COL_AUTO;
++nIndex;
if(nIndex >= aColors.getLength()) break;
// we check if the property ends with "/IsVisible" because not all entries are visible // see cNames[nIndex].bCanBeVisible if(pColorNames[nIndex].endsWith(g_sIsVisible))
m_aConfigValues[i].bIsVisible = Any2Bool(pColors[nIndex++]);
}
}
// If the name of the scheme hasn't changed, then there is no change to the // global color scheme name, but Kit deliberately only changed the then // current document when it last changed, so there are typically a mixture // of documents with the original 'light' color scheme and the last changed // color scheme 'dark'. Kit then tries to set the color scheme again to the // last changed color scheme 'dark' to try and update a 'light' document // that had opted out of the last change to 'dark'... constbool bEmptyColorSchemeNotify =
rProperties.getLength() == 1
&& rProperties[0] == "CurrentColorScheme"
&& bNoColorSchemeChange;
// ...We can get into a similar situation with inverted backgrounds, for // similar reasons, so even if we are only changing the current color scheme // we need to make sure that something actually changed... bool bNoConfigChange = true; for (int i = 0; i < ColorConfigEntryCount; ++i) { if (aOldConfigValues[i] != m_aConfigValues[i]) {
bNoConfigChange = false; break;
}
}
// ...and if something from a different color scheme changes, our config // values wouldn't change anyway, so we need to make sure that if something // changed it was this color scheme... const OUString sCurrentSchemePropertyPrefix = "ColorSchemes/org.openoffice.Office.UI:ColorScheme['" + m_sLoadedScheme + "']/"; bool bOnlyCurrentSchemeChanges = true; for (int i = 0; i < rProperties.getLength(); ++i) { if (!rProperties[i].startsWith(sCurrentSchemePropertyPrefix)) {
bOnlyCurrentSchemeChanges = false; break;
}
}
// ...We can tag apparent null change attempts with // 'OnlyCurrentDocumentColorScheme' to allow them to go through, but // identify what that change is for, so the other color config listeners for // whom it doesn't matter, can ignore it as an optimization. constbool bOnlyCurrentDocumentColorScheme = (bEmptyColorSchemeNotify || bEmptyCurrentSchemeNotify) && comphelper::LibreOfficeKit::isActive();
NotifyListeners(bOnlyCurrentDocumentColorScheme ? ConfigurationHints::OnlyCurrentDocumentColorScheme : ConfigurationHints::NONE);
}
// we check if the property ends with "/IsVisible" because not all entries are visible // see cNames[nIndex].bCanBeVisible if(pColorNames[nIndex].endsWith(g_sIsVisible))
{
pPropValues[nIndex].Name = pColorNames[nIndex];
pPropValues[nIndex].Value <<= m_aConfigValues[i].bIsVisible;
nIndex++;
}
}
SetSetProperties(u"ColorSchemes"_ustr, aPropValues);
// caches registry colors into the static ThemeColors::m_aThemeColors object. if the color // value is set to COL_AUTO, the ColorConfig::GetColorValue function calls ColorConfig::GetDefaultColor() // which returns some hard coded colors for the document, and StyleSettings colors for the UI (lcl_GetDefaultUIColor). void ColorConfig_Impl::LoadThemeColorsFromRegistry()
{
ThemeColors& rThemeColors = ThemeColors::GetThemeColors();
void ColorConfig_Impl::SetupTheme()
{ if (ThemeColors::IsThemeDisabled())
{
ThemeColors::SetThemeCached(false); return;
}
// When the theme is set to RESET, the IsThemeReset conditional doesn't let the theme to be loaded // as explained above, and returns if the StyleSettings doesn't have system colors loaded. IsThemeReset // is also used in VclPluginCanUseThemeColors where it prevents the VCL_PLUGINs from using theme colors. if (ThemeColors::IsThemeReset())
{ if (!Application::GetSettings().GetStyleSettings().GetSystemColorsLoaded()) return;
ThemeColors::SetThemeState(ThemeState::ENABLED);
}
// When the application is started for the first time, themes is set to ENABLED. // that would skip the first two checks for IsThemeDisabled and IsThemeReset in the // ColorConfig::SetupTheme function and call LoadThemeColorsFromRegistry(); if (!ThemeColors::IsThemeCached())
{ // registry to ColorConfig::m_pImpl
Load(GetCurrentSchemeName());
CommitCurrentSchemeName();
// ColorConfig::m_pImpl to static ThemeColors::m_aThemeColors
LoadThemeColorsFromRegistry();
}
}
ColorConfig::ColorConfig()
{ if (comphelper::IsFuzzing()) return;
std::unique_lock aGuard( ColorMutex_Impl() ); if ( !m_pImpl )
{
m_pImpl = new ColorConfig_Impl;
aGuard.unlock(); // because holdConfigItem will call this constructor
svtools::ItemHolder2::holdConfigItem(EItem::ColorConfig);
}
++nColorRefCount_Impl;
m_pImpl->AddListener(this);
}
static Color lcl_GetDefaultUIColor(ColorConfigEntry eEntry)
{ const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); switch (eEntry)
{ case WINDOWCOLOR: return rStyleSettings.GetWindowColor(); case WINDOWTEXTCOLOR: return rStyleSettings.GetWindowTextColor(); case BASECOLOR: return rStyleSettings.GetFieldColor(); case BUTTONCOLOR: return rStyleSettings.GetDialogColor(); case BUTTONTEXTCOLOR: return rStyleSettings.GetButtonTextColor(); case ACCENTCOLOR: return rStyleSettings.GetAccentColor(); case DISABLEDCOLOR: return rStyleSettings.GetDisableColor(); case DISABLEDTEXTCOLOR: case SHADECOLOR: return rStyleSettings.GetShadowColor(); case SEPARATORCOLOR: return rStyleSettings.GetSeparatorColor(); case FACECOLOR: return rStyleSettings.GetFaceColor(); case ACTIVECOLOR: return rStyleSettings.GetActiveColor(); case ACTIVETEXTCOLOR: return rStyleSettings.GetActiveTextColor(); case ACTIVEBORDERCOLOR: return rStyleSettings.GetActiveBorderColor(); case FIELDCOLOR: return rStyleSettings.GetFieldColor(); case MENUBARCOLOR: return rStyleSettings.GetMenuBarColor(); case MENUBARTEXTCOLOR: return rStyleSettings.GetMenuBarTextColor(); case MENUBARHIGHLIGHTCOLOR: return rStyleSettings.GetAccentColor(); case MENUBARHIGHLIGHTTEXTCOLOR: return rStyleSettings.GetMenuBarHighlightTextColor(); case MENUCOLOR: return rStyleSettings.GetMenuColor(); case MENUTEXTCOLOR: return rStyleSettings.GetMenuTextColor(); case MENUHIGHLIGHTCOLOR: return rStyleSettings.GetMenuHighlightColor(); case MENUHIGHLIGHTTEXTCOLOR: return rStyleSettings.GetMenuHighlightTextColor(); case MENUBORDERCOLOR: return rStyleSettings.GetMenuBorderColor(); case INACTIVECOLOR: case INACTIVETEXTCOLOR: case INACTIVEBORDERCOLOR: return rStyleSettings.GetShadowColor(); default: return COL_AUTO;
}
}
Color ColorConfig::GetDefaultColor(ColorConfigEntry eEntry, int nMod)
{ // the actual value of default color doesn't matter for colors in Group_Application // and this is just to prevent index out of bound error. if (eEntry >= WINDOWCOLOR) return lcl_GetDefaultUIColor(eEntry);
for (const OUString& rSchemeName : aNames) if (rSchemeName == aCurrentSchemeName) return GetLoadedScheme();
// Use "Automatic" as fallback auto pChange(comphelper::ConfigurationChanges::create());
officecfg::Office::UI::ColorScheme::CurrentColorScheme::set(AUTOMATIC_COLOR_SCHEME, pChange);
pChange->commit();
void EditableColorConfig::LoadScheme(const OUString& rScheme )
{ if(m_bModified)
m_pImpl->SetModified(); if(m_pImpl->IsModified())
m_pImpl->Commit();
m_bModified = false;
m_pImpl->Load(rScheme); //the name of the loaded scheme has to be committed separately
m_pImpl->CommitCurrentSchemeName();
}
// Changes the name of the current scheme but doesn't load it! void EditableColorConfig::SetCurrentSchemeName(const OUString& rScheme)
{
m_pImpl->SetCurrentSchemeName(rScheme);
m_pImpl->CommitCurrentSchemeName();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.