/* -*- 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 .
*/
OUString OFieldDescControl::BoolStringPersistent(std::u16string_view rUIString) const
{ if (rUIString == aNo) return OUString('0'); if (rUIString == aYes) return OUString('1'); return OUString();
}
OUString OFieldDescControl::BoolStringUI(const OUString& rPersistentString) const
{ // Older versions may store a language dependent string as a default if (rPersistentString == aYes || rPersistentString == aNo) return rPersistentString;
if (rPersistentString == "0") return aNo; if (rPersistentString == "1") return aYes;
for (autoconst & aggregate: aggregates)
{ if (aggregate.text)
aggregate.text->set_sensitive(!bReadOnly); if (aggregate.aggregate)
aggregate.aggregate->set_sensitive(!bReadOnly);
}
if (m_xFormat)
{
assert(m_xFormatText);
m_xFormat->set_sensitive(!bReadOnly);
m_xFormatText->set_sensitive(!bReadOnly);
}
}
void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const OUString& rText )
{ // Set the Controls' texts switch( nControlId )
{ case FIELD_PROPERTY_BOOL_DEFAULT: if (m_xBoolDefault)
{
OUString sOld = m_xBoolDefault->get_active_text();
m_xBoolDefault->set_active_text(rText); if (sOld != rText)
ChangeHdl(m_xBoolDefault->GetComboBox());
} break; case FIELD_PROPERTY_DEFAULT: if (m_xDefault)
{
m_xDefault->set_text(rText);
UpdateFormatSample(pActFieldDescr);
} break;
case FIELD_PROPERTY_REQUIRED: if (m_xRequired)
m_xRequired->set_active_text(rText); break;
case FIELD_PROPERTY_TEXTLEN: if (m_xTextLen)
m_xTextLen->set_text(rText); break;
case FIELD_PROPERTY_NUMTYPE: if (m_xNumType)
m_xNumType->set_active_text(rText); break;
case FIELD_PROPERTY_AUTOINC: if (m_xAutoIncrement)
{
OUString sOld = m_xAutoIncrement->get_active_text();
m_xAutoIncrement->set_active_text(rText); if (sOld != rText)
ChangeHdl(m_xAutoIncrement->GetComboBox());
} break;
case FIELD_PROPERTY_LENGTH: if (m_xLength)
m_xLength->set_text(rText); break;
case FIELD_PROPERTY_SCALE: if (m_xScale)
m_xScale->set_text(rText); break;
case FIELD_PROPERTY_FORMAT: if (pActFieldDescr)
UpdateFormatSample(pActFieldDescr); break; case FIELD_PROPERTY_COLUMNNAME: if (m_xColumnName)
m_xColumnName->set_text(rText); break; case FIELD_PROPERTY_TYPE: if (m_xType)
m_xType->set_active_text(rText); break; case FIELD_PROPERTY_AUTOINCREMENT: if (m_xAutoIncrementValue)
m_xAutoIncrementValue->set_text(rText); break;
}
}
IMPL_LINK_NOARG(OFieldDescControl, FormatClickHdl, weld::Button&, void)
{ // Create temporary Column, which is used for data exchange with Dialog if( !pActFieldDescr ) return;
IMPL_LINK(OFieldDescControl, ChangeHdl, weld::ComboBox&, rListBox, void)
{ if (!pActFieldDescr) return;
if (rListBox.get_value_changed_from_saved())
SetModified(true);
// Special treatment for Bool fields if (m_xRequired && &rListBox == m_xRequired->GetWidget() && m_xBoolDefault)
{ // If m_xRequired = sal_True then the sal_Bool field must NOT contain <<none>>
OUString sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
if (m_xRequired->get_active() == 0) // Yes
{
m_xBoolDefault->remove_text(DBA_RES(STR_VALUE_NONE)); if (sDef != aYes && sDef != aNo)
m_xBoolDefault->set_active(1); // No as a default else
m_xBoolDefault->set_active_text(sDef);
} elseif (m_xBoolDefault->get_count() < 3)
{
m_xBoolDefault->append_text(DBA_RES(STR_VALUE_NONE));
m_xBoolDefault->set_active_text(sDef);
}
}
// A special treatment only for AutoIncrement if (m_xAutoIncrement && &rListBox == m_xAutoIncrement->GetWidget())
{ if (rListBox.get_active() == 1)
{ // no
DeactivateAggregate( tpAutoIncrementValue ); if(pActFieldDescr->IsPrimaryKey())
DeactivateAggregate( tpRequired ); elseif( pActFieldDescr->getTypeInfo()->bNullable )
{
ActivateAggregate( tpRequired ); if (m_xRequired)
{ if( pActFieldDescr->IsNullable() )
m_xRequired->set_active(1); // no else
m_xRequired->set_active(0); // yes
}
}
ActivateAggregate( tpDefault );
} else
{
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpDefault );
ActivateAggregate( tpAutoIncrementValue );
}
}
case tpAutoIncrementValue:
lcl_HideAndDeleteControl(m_nPos,m_xAutoIncrementValue,m_xAutoIncrementValueText); break;
case tpColumnName:
lcl_HideAndDeleteControl(m_nPos,m_xColumnName,m_xColumnNameText); break;
case tpType:
lcl_HideAndDeleteControl(m_nPos,m_xType,m_xTypeText); break;
case tpAutoIncrement:
lcl_HideAndDeleteControl(m_nPos,m_xAutoIncrement,m_xAutoIncrementText); break;
case tpRequired:
lcl_HideAndDeleteControl(m_nPos,m_xRequired,m_xRequiredText); break;
case tpTextLen:
lcl_HideAndDeleteControl(m_nPos,m_xTextLen,m_xTextLenText); break;
case tpNumType:
lcl_HideAndDeleteControl(m_nPos,m_xNumType,m_xNumTypeText); break;
case tpLength:
lcl_HideAndDeleteControl(m_nPos,m_xLength,m_xLengthText); break;
case tpScale:
lcl_HideAndDeleteControl(m_nPos,m_xScale,m_xScaleText); break;
case tpFormat: // TODO: we have to check if we have to increment m_nPos again
lcl_HideAndDeleteControl(m_nPos,m_xFormat,m_xFormatText); if (m_xFormatSample)
{
m_xFormatSample->hide();
m_xFormatSample.reset();
} break; case tpBoolDefault:
lcl_HideAndDeleteControl(m_nPos,m_xBoolDefault,m_xBoolDefaultText); break;
}
}
OSL_ENSURE(pFieldType,"We need a type information here!"); // If the type has changed, substitute Controls if( m_pPreviousType != pFieldType )
{ // Reset the saved focus' pointer
m_pLastFocusWindow = nullptr;
// Controls, which must NOT be displayed again
DeactivateAggregate( tpNumType );
// determine which controls we should show and which not
// 1. the required control if ( pFieldType->bNullable )
ActivateAggregate( tpRequired ); else
DeactivateAggregate( tpRequired );
// and now look for type specific things switch( pFieldType->nType )
{ case DataType::CHAR: case DataType::VARCHAR: case DataType::LONGVARCHAR:
DeactivateAggregate( tpLength );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpDefault );
ActivateAggregate( tpFormat ); if (pFieldType->nPrecision)
{
ActivateAggregate( tpTextLen );
m_xTextLen->set_max(std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
m_xTextLen->set_editable(!pFieldType->aCreateParams.isEmpty());
} else
DeactivateAggregate( tpTextLen ); break; case DataType::DATE: case DataType::TIME: case DataType::TIMESTAMP: case DataType::TIME_WITH_TIMEZONE: case DataType::TIMESTAMP_WITH_TIMEZONE:
DeactivateAggregate( tpLength ); // we don't need a length for date types
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpBoolDefault ); break; case DataType::DECIMAL: case DataType::NUMERIC: case DataType::BIGINT: case DataType::FLOAT: case DataType::DOUBLE: case DataType::TINYINT: case DataType::SMALLINT: case DataType::INTEGER: case DataType::REAL:
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpFormat ); break; case DataType::BINARY: case DataType::VARBINARY:
DeactivateAggregate( tpDefault );
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
ActivateAggregate( tpFormat ); break; case DataType::LONGVARBINARY: case DataType::SQLNULL: case DataType::OBJECT: case DataType::DISTINCT: case DataType::STRUCT: case DataType::ARRAY: case DataType::BLOB: case DataType::CLOB: case DataType::REF: case DataType::OTHER:
DeactivateAggregate( tpFormat );
DeactivateAggregate( tpTextLen );
DeactivateAggregate( tpBoolDefault );
if (pFieldDescr->IsPrimaryKey())
{
DeactivateAggregate(tpRequired);
} elseif (!m_xAutoIncrement && pFieldType)
{ if (pFieldType->bNullable)
ActivateAggregate(tpRequired); else
DeactivateAggregate(tpRequired);
} // Initialize Controls if (m_xAutoIncrement)
{ if ( pFieldDescr->IsAutoIncrement() )
{
m_xAutoIncrement->set_active(0); // yes
ActivateAggregate( tpAutoIncrementValue ); if (m_xAutoIncrementValue)
m_xAutoIncrementValue->set_text(pFieldDescr->GetAutoIncrementValue());
DeactivateAggregate( tpRequired );
DeactivateAggregate( tpDefault );
} else
{ // disable autoincrement value because it should only be visible when autoincrement is to true
DeactivateAggregate( tpAutoIncrementValue );
m_xAutoIncrement->set_active(1); // no
ActivateAggregate( tpDefault ); // Affects pRequired if(!pFieldDescr->IsPrimaryKey())
ActivateAggregate( tpRequired );
}
}
if (m_xDefault)
{
m_xDefault->set_text(getControlDefault(pFieldDescr));
m_xDefault->save_value();
}
if (m_xBoolDefault)
{ // If m_xRequired = sal_True then the sal_Bool field must NOT contain <<none>>
OUString sValue;
pFieldDescr->GetControlDefault() >>= sValue;
OUString sDef = BoolStringUI(sValue);
// Make sure that <<none>> is only present if the field can be NULL if ( ( pFieldType && !pFieldType->bNullable ) || !pFieldDescr->IsNullable() )
{
pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); // The type says so
m_xBoolDefault->remove_text(DBA_RES(STR_VALUE_NONE)); if ( sDef != aYes && sDef != aNo )
m_xBoolDefault->set_active(1); // No as a default else
m_xBoolDefault->set_active_text(sDef);
// Read out Controls
OUString sDefault; if (m_xDefault)
{ // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string // suitable as the database default, e.g. 12.34
sDefault = CanonicalizeToControlDefault(pFieldDescr, m_xDefault->get_text());
} elseif (m_xBoolDefault)
{
sDefault = BoolStringPersistent(m_xBoolDefault->get_active_text());
}
if ( !sDefault.isEmpty() )
pFieldDescr->SetControlDefault(Any(sDefault)); else
pFieldDescr->SetControlDefault(Any());
// Set the Focus to the Control that has been active last if (m_pLastFocusWindow)
{
m_pLastFocusWindow->grab_focus();
m_pLastFocusWindow = nullptr;
}
}
void OFieldDescControl::implFocusLost(weld::Widget* _pWhich)
{ // Remember the active Control if (!m_pLastFocusWindow)
m_pLastFocusWindow = _pWhich;
void OFieldDescControl::cut()
{ if (isCutAllowed()) dynamic_cast<weld::Entry&>(*m_pActFocusWindow).cut_clipboard();
}
void OFieldDescControl::copy()
{ if (isCopyAllowed()) // this only checks if the focus window is valid dynamic_cast<weld::Entry&>(*m_pActFocusWindow).copy_clipboard();
}
void OFieldDescControl::paste()
{ if (m_pActFocusWindow) // this only checks if the focus window is valid dynamic_cast<weld::Entry&>(*m_pActFocusWindow).paste_clipboard();
}
if ( !bTextFormat )
{
Locale aLocale;
::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,u"Locale"_ustr) >>= aLocale;
sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey); if( (nNumberFormat & css::util::NumberFormat::DATE) == css::util::NumberFormat::DATE
|| (nNumberFormat & css::util::NumberFormat::DATETIME) == css::util::NumberFormat::DATETIME )
{ bool bDoCorrect = true; if (!sDefault.isEmpty())
{ // nValue was converted from that string. If that string was a date, nValue // is already in the required epoch, and we should not try to correct it
sal_Int32 nFormatKeyOf_sDefault = xNumberFormatter->detectNumberFormat(nFormatKey, sDefault);
sal_Int16 nNumberFormatType = comphelper::getNumberFormatType(xNumberFormatter, nFormatKeyOf_sDefault);
bDoCorrect = (nNumberFormatType & css::util::NumberFormat::DATE) == 0;
} if (bDoCorrect)
nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
}
// tdf#138409 intended to be effectively the reverse of getControlDefault to // turn a user's possibly 12,34 format into 12.34 format for numerical types
OUString OFieldDescControl::CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rDefault) const
{ if (rDefault.isEmpty()) return rDefault;
bool bIsNumericalType = false; switch (pFieldDescr->GetType())
{ case DataType::TINYINT: case DataType::SMALLINT: case DataType::INTEGER: case DataType::BIGINT: case DataType::FLOAT: case DataType::REAL: case DataType::DOUBLE: case DataType::NUMERIC: case DataType::DECIMAL:
bIsNumericalType = true; break;
}
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.