/* -*- 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 .
*/
/************************************************************************* #* Method: NotifyChange #*------------------------------------------------------------------------ #* #* Class: SvxNumberPreview #* Function: Function for changing the preview string #* Input: String, color #* Output: --- #*
#************************************************************************/
void SvxNumberPreview::NotifyChange( const OUString& rPrevStr, const Color* pColor )
{ // detect and strip out '*' related placeholders
aPrevStr = rPrevStr;
mnPos = aPrevStr.indexOf( 0x1B ); if ( mnPos != -1 )
{ // Right during user input the star symbol is the very // last character before the user enters another one. if (mnPos < aPrevStr.getLength() - 1)
{
mnChar = aPrevStr[ mnPos + 1 ]; // delete placeholder and char to repeat
aPrevStr = aPrevStr.replaceAt( mnPos, 2, u"" );
} else
{ // delete placeholder
aPrevStr = aPrevStr.replaceAt( mnPos, 1, u"" ); // do not attempt to draw a 0 fill character
mnPos = -1;
}
} if (pColor)
aPrevCol = *pColor; else
{
svtools::ColorConfig aColorConfig;
Color aFgColor = aColorConfig.GetColorValue(svtools::FONTCOLOR, false).nColor; if (aFgColor == COL_AUTO)
{
Color aBgColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
aFgColor = aBgColor.IsDark() ? COL_WHITE : COL_BLACK;
}
aPrevCol = aFgColor;
}
Invalidate();
}
/************************************************************************* #* Method: Paint #*------------------------------------------------------------------------ #* #* Class: SvxNumberPreview #* Function: Function for repainting the window. #* Input: --- #* Output: --- #*
#************************************************************************/
auto nWidth = m_xLbCategory->get_approximate_digit_width() * 22;
m_xLbCategory->set_size_request(nWidth, m_xLbCategory->get_height_rows(7));
m_xLbFormat->set_size_request(nWidth, m_xLbFormat->get_height_rows(5));
m_xLbCurrency->set_size_request(nWidth, -1); // force using (narrower) width of its LbFormat sibling
// Initially remove the "Automatically" entry.
m_xLbCurrency->set_active(-1); // First ensure that nothing is selected.
sAutomaticCurrencyEntry = m_xLbCurrency->get_text(0);
m_xLbCurrency->remove(0);
Init_Impl();
SetExchangeSupport(); // this page needs ExchangeSupport
nFixedCategory=-1;
}
/************************************************************************* #* Method: Reset #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: The dialog's attributes are reset #* using the Itemset. #* Input: SfxItemSet #* Output: --- #*
#************************************************************************/
void SvxNumberFormatTabPage::set_active_currency(sal_Int32 nPos)
{
static_assert(SELPOS_NONE == -1, "SELPOS_NONE was -1 at time of writing"); if (nPos == 0 && !bLegacyAutomaticCurrency)
{ // Insert "Automatically" if currently used so it is selectable.
m_xLbCurrency->insert_text(0, sAutomaticCurrencyEntry);
bLegacyAutomaticCurrency = true;
} if (nPos != -1 && !bLegacyAutomaticCurrency)
--nPos;
m_xLbCurrency->set_active(nPos);
}
sal_uInt32 SvxNumberFormatTabPage::get_active_currency() const
{
static_assert(SELPOS_NONE == -1, "SELPOS_NONE was -1 at time of writing");
sal_Int32 nCurrencyPos = m_xLbCurrency->get_active(); if (nCurrencyPos != -1 && !bLegacyAutomaticCurrency)
++nCurrencyPos; return nCurrencyPos;
}
switch ( eValType )
{ case SvxNumberValueType::String:
aValString = pNumItem->GetValueString(); break; case SvxNumberValueType::Number: // #50441# string may be set in addition to the value
aValString = pNumItem->GetValueString();
nValDouble = pNumItem->GetValueDouble(); break; case SvxNumberValueType::Undefined: default: break;
}
pNumFmtShell.reset(); // delete old shell if applicable (== reset)
if (nCatLbSelPos==CAT_CURRENCY)
set_active_currency(pNumFmtShell->GetCurrencySymbol());
nFixedCategory=nCatLbSelPos; if(bOneAreaFlag)
{
OUString sFixedCategory = m_xLbCategory->get_text(nFixedCategory);
m_xLbCategory->clear();
m_xLbCategory->append_text(sFixedCategory);
SetCategory(0);
} else
{
SetCategory(nCatLbSelPos );
}
pAutoEntryAttr = rSet->GetItemIfSet( SID_ATTR_NUMBERFORMAT_ADD_AUTO ); // no_NO is an alias for nb_NO and normally isn't listed, we need it for // backwards compatibility, but only if the format passed is of // LanguageType no_NO. if ( eLangType == LANGUAGE_NORWEGIAN )
{
m_xLbLanguage->remove_id(eLangType); // in case we're already called
m_xLbLanguage->InsertLanguage( eLangType );
}
m_xLbLanguage->set_active_id(eLangType); if(pAutoEntryAttr)
AddAutomaticLanguage_Impl(eLangType, pAutoEntryAttr->GetValue());
UpdateFormatListBox_Impl(false,true);
//! This spoils everything because it rematches currency formats based on //! the selected m_xLbCurrency entry instead of the current format. //! Besides that everything seems to be initialized by now, so why call it? // SelFormatHdl_Impl(m_xLbCategory.get());
if ( pValFmtAttr )
{
EditHdl_Impl(m_xEdFormat.get()); // UpdateOptions_Impl() as a side effect
} else// DONT_KNOW
{ // everything disabled except direct input or changing the category
Obstructing();
}
m_xLbCategory->select(0);
m_xEdFormat->set_text( OUString() );
m_xFtComment->set_label( OUString() );
m_xEdComment->set_text(m_xLbCategory->get_text(1)); // string for user defined
/************************************************************************* #* Method: FillItemSet #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Adjusts the attributes in the ItemSet, #* and - if bNumItemFlag is not set - the #* numItem in the DocShell. #* Input: SfxItemSet #* Output: --- #*
#************************************************************************/
// OK chosen - Is format code input entered already taken over? // If not, simulate Add. Upon syntax error ignore input and prevent Put.
OUString aFormat = m_xEdFormat->get_text();
sal_uInt32 nCurKey = pNumFmtShell->GetCurNumFmtKey();
if ( m_xIbAdd->get_sensitive() || pNumFmtShell->IsTmpCurrencyFormat(aFormat) )
{ // #79599# It is not sufficient to just add the format code (or // delete it in case of bOneAreaFlag and resulting category change). // Upon switching tab pages we need all settings to be consistent // in case this page will be redisplayed later.
bDataChanged = Click_Impl(*m_xIbAdd);
nCurKey = pNumFmtShell->GetCurNumFmtKey();
} elseif(nCurKey == NUMKEY_UNDEFINED)
{ // something went wrong, e.g. in Writer #70281#
pNumFmtShell->FindEntry(aFormat, &nCurKey);
}
// FillItemSet is only called on OK, here we can notify the // NumberFormatShell that all new user defined formats are valid.
pNumFmtShell->ValidateNewEntries(); if(m_xLbLanguage->get_visible() &&
m_xLbLanguage->find_text(sAutomaticLangEntry) != -1)
rCoreAttrs->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO,
m_xLbLanguage->get_active_text() == sAutomaticLangEntry));
}
case CAT_ALL: case CAT_USERDEFINED: case CAT_TEXT: case CAT_DATE: case CAT_BOOLEAN: default:
m_xFtOptions->set_sensitive(false);
m_xFtDecimals->set_sensitive(false);
m_xEdDecimals->set_sensitive(false);
m_xFtDenominator->set_sensitive(false);
m_xEdDenominator->set_sensitive(false);
m_xFtLeadZeroes->set_sensitive(false);
m_xEdLeadZeroes->set_sensitive(false);
m_xBtnNegRed->set_sensitive(false);
m_xBtnThousand->set_sensitive(false);
m_xBtnEngineering->set_sensitive(false);
m_xEdDecimals->set_text( OUString() );
m_xEdLeadZeroes->set_text( OUString() );
m_xBtnNegRed->set_active( false );
m_xBtnThousand->set_active( false );
m_xBtnEngineering->set_active( false );
}
}
/************************************************************************* #* Method: UpdateFormatListBox_Impl #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Updates the format listbox and additionally the #* string in the editbox is changed depending on #* the bUpdateEdit flag. #* Input: Flags for category and editbox. #* Output: --- #*
#************************************************************************/
void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
( bool bCat, // Category or country/language ListBox? bool bUpdateEdit
)
{
std::vector<OUString> aEntryList; short nFmtLbSelPos = 0; short nTmpCatPos;
/************************************************************************* #* Handle: DoubleClickHdl_Impl #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: On a double click in the format listbox the #* value is adopted and the OK button pushed. #* Input: Pointer on the Listbox #* Output: --- #*
#************************************************************************/
IMPL_LINK(SvxNumberFormatTabPage, DoubleClickHdl_Impl, weld::TreeView&, rLb, bool)
{
SelFormatHdl_Impl(&rLb);
/************************************************************************* #* Method: SelFormatHdl_Impl #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Is called when the language, the category or the format #* is changed. Accordingly the settings are adjusted. #* Input: Pointer on the Listbox #* Output: --- #*
#************************************************************************/
void SvxNumberFormatTabPage::SelFormatHdl_Impl(weld::Widget* pLb)
{ if (m_nLbFormatSelPosEdComment != SELPOS_NONE)
{ // Click handler is called before focus change handler, so finish // comment editing of previous format, otherwise a new format will have // the old comment displayed after LostFocusHdl_Impl() is called // later. Also, clicking into another category invalidates the format // list and SvxNumberFormatShell::SetComment4Entry() could either // access a wrong format from aCurEntryList[nEntry] or crash there if // the new vector has less elements.
LostFocusHdl_Impl(*pLb);
}
if (pLb == m_xCbSourceFormat.get())
{
EnableBySourceFormat_Impl(); // enable/disable everything else if ( m_xCbSourceFormat->get_active() ) return; // just disabled everything else
// Reinit options enable/disable for current selection.
// Current category may be UserDefined with no format entries defined. if (m_xLbFormat->get_selected_index() == -1)
pLb = m_xLbCategory.get(); // continue with the current category selected else
pLb = m_xLbFormat.get(); // continue with the current format selected
}
/************************************************************************* #* Method: ClickHdl_Impl, weld::Button& rIB #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Called when the add or delete button is pushed, #* adjusts the number format list. #* Input: Toolbox- Button #* Output: --- #*
#************************************************************************/
bool SvxNumberFormatTabPage::Click_Impl(const weld::Button& rIB)
{
sal_uInt8 nReturn = 0;
constexpr sal_uInt8 nReturnChanged = 0x1; // THE boolean return value
constexpr sal_uInt8 nReturnAdded = 0x2; // temp: format added
constexpr sal_uInt8 nReturnOneArea = 0x4; // temp: one area but category changed => ignored
if (&rIB == m_xIbAdd.get())
{ // Also called from FillItemSet() if a temporary currency format has // to be added, not only if the Add button is enabled.
OUString aFormat = m_xEdFormat->get_text();
std::vector<OUString> aEntryList;
std::vector<OUString> a2EntryList;
sal_uInt16 nCatLbSelPos = 0; short nFmtLbSelPos = SELPOS_NONE;
sal_Int32 nErrPos=0;
if (m_xEdComment->get_visible())
{
m_xEdFormat->grab_focus();
m_xEdComment->hide();
m_xFtComment->show();
m_xFtComment->set_label(m_xEdComment->get_text());
}
if ( !nErrPos ) // Syntax ok?
{ // May be sorted under a different locale if LCID was parsed. if (bAdded)
m_xLbLanguage->set_active_id(pNumFmtShell->GetCurLanguage());
if (nCatLbSelPos==CAT_CURRENCY)
set_active_currency(pNumFmtShell->GetCurrencySymbol());
/************************************************************************* #* Method: EditHdl_Impl #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: When the entry in the edit field is changed #* the preview is updated and #* Input: Pointer on Editbox #* Output: --- #*
#************************************************************************/
/************************************************************************* #* Method: LostFocusHdl_Impl #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Does changes in the number attributes. #* Input: Options- Controls #* Output: --- #*
#************************************************************************/
IMPL_LINK_NOARG(SvxNumberFormatTabPage, LostFocusHdl_Impl, weld::Widget&, void)
{ if (!pNumFmtShell) return;
constbool bAddSensitive = m_xIbAdd->get_sensitive(); if (bAddSensitive || m_nLbFormatSelPosEdComment != SELPOS_NONE) // Comment editing was possible.
m_xFtComment->set_label(m_xEdComment->get_text());
m_xEdComment->hide();
m_xFtComment->show(); if (m_nLbFormatSelPosEdComment != SELPOS_NONE)
{ // Save edited comment of existing format.
pNumFmtShell->SetComment4Entry( m_nLbFormatSelPosEdComment, m_xEdComment->get_text());
m_nLbFormatSelPosEdComment = SELPOS_NONE;
} if (!bAddSensitive)
{ // String for user defined, if present
OUString sEntry = m_xLbCategory->n_children() > 1 ? m_xLbCategory->get_text(1) : OUString();
m_xEdComment->set_text(sEntry);
}
}
/************************************************************************* #* Method: NotifyChange #*------------------------------------------------------------------------ #* #* Class: SvxNumberFormatTabPage #* Function: Does changes in the number attributes. #* Input: Options- Controls #* Output: --- #*
#************************************************************************/
OUString SvxNumberFormatTabPage::GetExpColorString( const Color*& rpPreviewColor, const OUString& rFormatStr, short nTmpCatPos)
{
SvxNumValCategory i; switch (nTmpCatPos)
{ case CAT_ALL: i=SvxNumValCategory::Standard; break;
case CAT_NUMBER: i=SvxNumValCategory::Standard; break;
case CAT_PERCENT: i=SvxNumValCategory::Percent; break;
case CAT_CURRENCY: i=SvxNumValCategory::Currency; break;
case CAT_DATE: i=SvxNumValCategory::Date; break;
case CAT_TIME: i=SvxNumValCategory::Time; break;
case CAT_SCIENTIFIC: i=SvxNumValCategory::Scientific; break;
case CAT_FRACTION: i=SvxNumValCategory::Fraction; break;
case CAT_BOOLEAN: i=SvxNumValCategory::Boolean; break;
case CAT_USERDEFINED: i=SvxNumValCategory::Standard; break;
case CAT_TEXT: default: i=SvxNumValCategory::NoValue;break;
} double fVal = fSvxNumValConst[i];
// use lower number for long NatNum12 transliteration if ( ( CAT_CURRENCY == nTmpCatPos || CAT_NUMBER == nTmpCatPos ) &&
rFormatStr.indexOf("NatNum12") >= 0 )
{ if ( CAT_CURRENCY == nTmpCatPos )
fVal = 1.2; else
fVal = 100; // show also title case for English: One Hundred
}
/* to support Writer text field language handling an additional entry needs to be inserted into the ListBox which marks a certain language as automatically detected Additionally the "Default" language is removed
*/ void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang, boolbSelect)
{
m_xLbLanguage->remove_id(LANGUAGE_SYSTEM);
m_xLbLanguage->append(eAutoLang, sAutomaticLangEntry); if (bSelect)
m_xLbLanguage->set_active_id(eAutoLang);
}
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.