20#include <core_resource.hxx>
29#include <com/sun/star/sdbc/ColumnValue.hpp>
30#include <com/sun/star/util/NumberFormat.hpp>
31#include <com/sun/star/util/XNumberFormatPreviewer.hpp>
32#include <com/sun/star/util/XNumberFormatTypes.hpp>
33#include <com/sun/star/beans/XPropertySet.hpp>
42#include <osl/diagnose.h>
54 template<
typename T1,
typename T2>
void lcl_HideAndDeleteControl(
short& _nPos,std::unique_ptr<T1>& _pControl, std::unique_ptr<T2>& _pControlText)
60 _pControlText->hide();
62 _pControlText.reset();
68 : m_xBuilder(
Application::CreateBuilder(pPage,
"dbaccess/ui/fielddescpage.ui"))
69 ,
m_xContainer(m_xBuilder->weld_container(
"FieldDescPage"))
71 , m_pLastFocusWindow(nullptr)
72 , m_pActFocusWindow(nullptr)
77 , pActFieldDescr(nullptr)
137 if (rUIString ==
aNo)
138 return OUString(
'0');
139 if (rUIString ==
aYes)
140 return OUString(
'1');
147 if (rPersistentString ==
aYes || rPersistentString ==
aNo)
148 return rPersistentString;
150 if (rPersistentString ==
"0")
152 if (rPersistentString ==
"1")
155 return DBA_RES(STR_VALUE_NONE);
171 }
const aggregates[] = {
183 for (
auto const & aggregate: aggregates)
186 aggregate.text->set_sensitive(!
bReadOnly);
187 if (aggregate.aggregate)
188 aggregate.aggregate->set_sensitive(!
bReadOnly);
266 m_xType->set_active_text(rText);
278 if( !pActFieldDescr )
281 sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
292 bool bModified =
false;
293 if(nOldFormatKey != pActFieldDescr->GetFormatKey())
295 pActFieldDescr->SetFormatKey( nOldFormatKey );
298 if(rOldJustify != pActFieldDescr->GetHorJustify())
300 pActFieldDescr->SetHorJustify( rOldJustify );
307 UpdateFormatSample(pActFieldDescr);
320 if (rListBox.get_value_changed_from_saved())
324 if (m_xRequired && &rListBox == m_xRequired->GetWidget() && m_xBoolDefault)
327 OUString sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
329 if (m_xRequired->get_active() == 0)
331 m_xBoolDefault->remove_text(
DBA_RES(STR_VALUE_NONE));
332 if (sDef != aYes && sDef != aNo)
333 m_xBoolDefault->set_active(1);
335 m_xBoolDefault->set_active_text(sDef);
337 else if (m_xBoolDefault->get_count() < 3)
339 m_xBoolDefault->append_text(
DBA_RES(STR_VALUE_NONE));
340 m_xBoolDefault->set_active_text(sDef);
345 if (m_xAutoIncrement && &rListBox == m_xAutoIncrement->GetWidget())
347 if (rListBox.get_active() == 1)
350 if(pActFieldDescr->IsPrimaryKey())
352 else if( pActFieldDescr->getTypeInfo()->bNullable )
357 if( pActFieldDescr->IsNullable() )
358 m_xRequired->set_active(1);
360 m_xRequired->set_active(0);
373 if (m_xType && &rListBox == m_xType->GetWidget())
375 TOTypeInfoSP pTypeInfo = getTypeInfo(m_xType->get_active());
376 pActFieldDescr->FillFromTypeInfo(pTypeInfo,
true,
false);
378 DisplayData(pActFieldDescr);
379 CellModified(-1, m_xType->GetPos());
406 m_xBuilder->weld_spin_button(
"AutoIncrementValue"), STR_HELP_AUTOINCREMENT_VALUE,
419 if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
425 m_xBuilder->weld_combo_box(
"Required"), STR_HELP_AUTOINCREMENT_VALUE,
444 m_xBuilder->weld_combo_box(
"AutoIncrement"), STR_HELP_AUTOINCREMENT,
468 m_xType = std::make_unique<OPropListBoxCtrl>(
472 for (
auto const& elem : *pTypeInfo)
473 m_xType->append_text(elem.second->aUIName);
489 if ( xMetaData.is() )
491 nMax = xMetaData->getMaxColumnNameLength();
492 aTmpString = xMetaData->getExtraNameCharacters();
502 m_xBuilder->weld_entry(
"ColumnName"), aTmpString,
517 m_xNumType = std::make_unique<OPropListBoxCtrl>(
555 m_xBuilder->weld_entry(
"FormatText"), STR_HELP_FORMAT_CODE, -1);
577 m_xBuilder->weld_combo_box(
"BoolDefault"), STR_HELP_BOOL_DEFAULT,
590 if ( _bAddChangeHandler )
611 auto xControl = std::make_unique<OPropNumericEditCtrl>(
612 m_xBuilder->weld_spin_button(rId), pHelpId, _nProperty);
613 xControl->set_digits(0);
614 xControl->set_range(0, 0x7FFFFFFF);
713 OSL_ENSURE(pFieldType,
"We need a type information here!");
726 if ( pFieldType->bNullable )
732 if ( pFieldType->bAutoIncrement )
743 if(pFieldType->bNullable)
750 if (pFieldType->nPrecision)
754 m_xLength->set_editable(!pFieldType->aCreateParams.isEmpty());
759 if (pFieldType->nMaximumScale)
762 m_xScale->set_range(pFieldType->nMinimumScale,
763 std::max<sal_Int32>(pFieldType->nMaximumScale,pFieldDescr->
GetScale()));
764 m_xScale->set_editable(!pFieldType->aCreateParams.isEmpty() && pFieldType->aCreateParams !=
"PRECISION");
770 switch( pFieldType->nType )
773 case DataType::VARCHAR:
774 case DataType::LONGVARCHAR:
780 if (pFieldType->nPrecision)
784 m_xTextLen->set_editable(!pFieldType->aCreateParams.isEmpty());
791 case DataType::TIMESTAMP:
800 if ( !pFieldType->aCreateParams.isEmpty() )
808 case DataType::BOOLEAN:
815 case DataType::DECIMAL:
816 case DataType::NUMERIC:
817 case DataType::BIGINT:
818 case DataType::FLOAT:
819 case DataType::DOUBLE:
820 case DataType::TINYINT:
821 case DataType::SMALLINT:
822 case DataType::INTEGER:
829 case DataType::BINARY:
830 case DataType::VARBINARY:
838 case DataType::LONGVARBINARY:
839 case DataType::SQLNULL:
840 case DataType::OBJECT:
841 case DataType::DISTINCT:
842 case DataType::STRUCT:
843 case DataType::ARRAY:
847 case DataType::OTHER:
854 OSL_FAIL(
"Unknown type");
865 if (pFieldType->bNullable)
908 if ( ( pFieldType && !pFieldType->bNullable ) || !pFieldDescr->
IsNullable() )
913 if ( sDef !=
aYes && sDef !=
aNo )
945 OSL_FAIL(
"OFieldDescControl::DisplayData: invalid num type!");
966 OTypeInfoMap::const_iterator aIter = pMap->find(pFieldType ? pFieldDescr->
getTypeInfo()->nType : pFieldDescr->
GetType());
967 if(aIter == pMap->end() && !pMap->empty())
969 aIter = pMap->begin();
970 if(pFieldDescr->
GetPrecision() > aIter->second->nPrecision)
972 if(pFieldDescr->
GetScale() > aIter->second->nMaximumScale)
974 if(!aIter->second->bNullable && pFieldDescr->
IsNullable())
979 if ( aIter != pMap->end() )
981 pFieldDescr->
SetType(aIter->second);
995 OUString strHelpText;
997 if (m_xTextLen && &rControl == m_xTextLen->GetWidget())
999 m_xTextLen->save_value();
1000 strHelpText = m_xTextLen->GetHelp();
1002 else if (m_xLength && &rControl == m_xLength->GetWidget())
1004 m_xLength->save_value();
1005 strHelpText = m_xLength->GetHelp();
1007 else if (m_xScale && &rControl == m_xScale->GetWidget())
1009 m_xScale->save_value();
1010 strHelpText = m_xScale->GetHelp();
1012 else if (m_xColumnName && &rControl == m_xColumnName->GetWidget())
1014 m_xColumnName->save_value();
1015 strHelpText = m_xColumnName->GetHelp();
1017 else if (m_xDefault && &rControl == m_xDefault->GetWidget())
1019 m_xDefault->save_value();
1020 strHelpText = m_xDefault->GetHelp();
1022 else if (m_xFormatSample && &rControl == m_xFormatSample->GetWidget())
1024 m_xFormatSample->save_value();
1025 strHelpText = m_xFormatSample->GetHelp();
1027 else if (m_xAutoIncrementValue && &rControl == m_xAutoIncrementValue->GetWidget())
1029 m_xAutoIncrementValue->save_value();
1030 strHelpText = m_xAutoIncrementValue->GetHelp();
1032 else if (m_xRequired && &rControl == m_xRequired->GetWidget())
1034 m_xRequired->save_value();
1035 strHelpText = m_xRequired->GetHelp();
1037 else if (m_xNumType && &rControl == m_xNumType->GetWidget())
1039 m_xNumType->save_value();
1040 strHelpText = m_xNumType->GetHelp();
1042 else if (m_xAutoIncrement && &rControl == m_xAutoIncrement->GetWidget())
1044 m_xAutoIncrement->save_value();
1045 strHelpText = m_xAutoIncrement->GetHelp();
1047 else if (m_xBoolDefault && &rControl == m_xBoolDefault->GetWidget())
1049 m_xBoolDefault->save_value();
1050 strHelpText = m_xBoolDefault->GetHelp();
1052 else if (m_xType && &rControl == m_xType->GetWidget())
1054 m_xType->save_value();
1055 strHelpText = m_xType->GetHelp();
1057 else if (m_xFormat && &rControl == m_xFormat.get())
1058 strHelpText =
DBA_RES(STR_HELP_FORMAT_BUTTON);
1060 if (!strHelpText.isEmpty() && m_pHelp)
1061 m_pHelp->SetHelpText(strHelpText);
1063 m_pActFocusWindow = &rControl;
1065 m_aControlFocusIn.Call(rControl);
1070 if (m_xLength && &rControl == m_xLength->GetWidget() && m_xLength->get_value_changed_from_saved())
1071 CellModified(-1, m_xLength->GetPos());
1072 else if (m_xTextLen && &rControl == m_xTextLen->GetWidget() && m_xTextLen->get_value_changed_from_saved())
1073 CellModified(-1, m_xTextLen->GetPos());
1074 else if (m_xScale && &rControl == m_xScale->GetWidget() && m_xScale->get_value_changed_from_saved())
1075 CellModified(-1, m_xScale->GetPos());
1076 else if (m_xColumnName && &rControl == m_xColumnName->GetWidget() && m_xColumnName->get_value_changed_from_saved())
1077 CellModified(-1, m_xColumnName->GetPos());
1078 else if (m_xDefault && &rControl == m_xDefault->GetWidget() && m_xDefault->get_value_changed_from_saved())
1079 CellModified(-1, m_xDefault->GetPos());
1080 else if (m_xFormatSample && &rControl == m_xFormatSample->GetWidget() && m_xFormatSample->get_value_changed_from_saved())
1081 CellModified(-1, m_xFormatSample->GetPos());
1082 else if (m_xAutoIncrementValue && &rControl == m_xAutoIncrementValue->GetWidget() && m_xAutoIncrementValue->get_value_changed_from_saved())
1083 CellModified(-1, m_xAutoIncrementValue->GetPos());
1084 else if (m_xRequired && &rControl == m_xRequired->GetWidget() && m_xRequired->get_value_changed_from_saved())
1085 CellModified(-1, m_xRequired->GetPos());
1086 else if (m_xNumType && &rControl == m_xNumType->GetWidget() && m_xNumType->get_value_changed_from_saved())
1087 CellModified(-1, m_xNumType->GetPos());
1088 else if (m_xAutoIncrement && &rControl == m_xAutoIncrement->GetWidget() && m_xAutoIncrement->get_value_changed_from_saved())
1089 CellModified(-1, m_xAutoIncrement->GetPos());
1090 else if (m_xBoolDefault && &rControl == m_xBoolDefault->GetWidget() && m_xBoolDefault->get_value_changed_from_saved())
1091 CellModified(-1, m_xBoolDefault->GetPos());
1092 else if (m_xType && &rControl == m_xType->GetWidget() && m_xType->get_value_changed_from_saved())
1093 CellModified(-1, m_xType->GetPos());
1094 else if (m_xDefault && &rControl == m_xDefault->GetWidget())
1095 UpdateFormatSample(pActFieldDescr);
1097 implFocusLost(&rControl);
1118 if ( !sDefault.isEmpty() )
1176 m_pHelp->SetHelpText(OUString());
1205 int nStartPos, nEndPos;
1213 int nStartPos, nEndPos;
1225 bAllowed = aTransferData.
HasFormat(SotClipboardFormatId::STRING);
1251 bool bTextFormat =
true;
1258 OSL_ENSURE(xNumberTypes.is(),
"XNumberFormatTypes is null!");
1260 _nFormatKey = ::dbtools::getDefaultNumberFormat( _pFieldDescr->
GetType(),
1266 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(
GetFormatter(),_nFormatKey);
1267 bTextFormat = (nNumberFormat == css::util::NumberFormat::TEXT);
1286 sal_uInt32 nFormatKey;
1287 bool bTextFormat =
isTextFormat(_pFieldDescr,nFormatKey);
1292 if ( !sDefault.isEmpty() )
1309 Reference<XPropertySet> xFormSet = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey);
1310 OSL_ENSURE(xFormSet.is(),
"XPropertySet is null!");
1312 xFormSet->getPropertyValue(
"FormatString") >>= sFormat;
1317 ::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,
"Locale") >>= aLocale;
1319 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
1320 if( (nNumberFormat & css::util::NumberFormat::DATE) == css::util::NumberFormat::DATE
1321 || (nNumberFormat & css::util::NumberFormat::DATETIME) == css::util::NumberFormat::DATETIME )
1323 nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),
nValue);
1327 OSL_ENSURE(xPreviewer.is(),
"XNumberFormatPreviewer is null!");
1328 sDefault = xPreviewer->convertNumberToPreviewString(sFormat,
nValue,aLocale,
true);
1330 else if ( !(_bCheck && sDefault.isEmpty()) )
1331 sDefault = xNumberFormatter->formatString(nFormatKey, sDefault.isEmpty() ? sFormat : sDefault);
1346 if (rDefault.isEmpty())
1349 bool bIsNumericalType =
false;
1350 switch (pFieldDescr->
GetType())
1352 case DataType::TINYINT:
1353 case DataType::SMALLINT:
1354 case DataType::INTEGER:
1355 case DataType::BIGINT:
1356 case DataType::FLOAT:
1357 case DataType::REAL:
1358 case DataType::DOUBLE:
1359 case DataType::NUMERIC:
1360 case DataType::DECIMAL:
1361 bIsNumericalType =
true;
1365 if (!bIsNumericalType)
1370 sal_uInt32 nFormatKey;
1371 bool bTextFormat =
isTextFormat(pFieldDescr, nFormatKey);
1375 return OUString::number(
nValue);
#define FIELD_PROPERTY_LENGTH
#define FIELD_PROPERTY_SCALE
#define FIELD_PROPERTY_NUMTYPE
#define FIELD_PROPERTY_TEXTLEN
#define FIELD_PROPERTY_REQUIRED
#define FIELD_PROPERTY_FORMAT
#define FIELD_PROPERTY_BOOL_DEFAULT
#define FIELD_PROPERTY_COLUMNNAME
#define FIELD_PROPERTY_AUTOINCREMENT
#define FIELD_PROPERTY_DEFAULT
#define FIELD_PROPERTY_TYPE
#define FIELD_PROPERTY_AUTOINC
static OutputDevice * GetDefaultDevice()
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
static TransferableDataHelper CreateFromClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard)
bool HasFormat(SotClipboardFormatId nFormat) const
virtual bool isCopyAllowed() override
virtual void ActivateAggregate(EControlType eType)
weld::Widget * m_pActFocusWindow
bool HasChildPathFocus() const
virtual ~OFieldDescControl()
void SaveData(OFieldDescription *pFieldDescr)
std::unique_ptr< weld::Builder > m_xBuilder
std::unique_ptr< weld::Label > m_xDefaultText
weld::Widget * m_pLastFocusWindow
std::unique_ptr< OPropListBoxCtrl > m_xType
std::unique_ptr< OPropNumericEditCtrl > m_xLength
bool IsFocusInEditableWidget() const
std::unique_ptr< OPropNumericEditCtrl > CreateNumericControl(const OUString &rId, TranslateId pHelpId, short _nProperty, const OUString &_sHelpId)
OUString BoolStringPersistent(std::u16string_view rUIString) const
virtual void SetModified(bool bModified)
virtual void copy() override
OUString getControlDefault(const OFieldDescription *pFieldDescr, bool _bCheck=true) const
std::unique_ptr< OPropNumericEditCtrl > m_xScale
void SetReadOnly(bool bReadOnly)
virtual void paste() override
virtual bool isAutoIncrementValueEnabled() const =0
std::unique_ptr< weld::Label > m_xTypeText
virtual css::uno::Reference< css::sdbc::XConnection > getConnection()=0
OFieldDescription * pActFieldDescr
virtual void cut() override
std::unique_ptr< OPropListBoxCtrl > m_xRequired
std::unique_ptr< weld::Label > m_xTextLenText
std::unique_ptr< weld::Label > m_xScaleText
std::unique_ptr< weld::Container > m_xContainer
std::unique_ptr< weld::Label > m_xColumnNameText
virtual bool IsReadOnly()
virtual bool isPasteAllowed() override
virtual OUString getAutoIncrementValue() const =0
std::unique_ptr< weld::Label > m_xNumTypeText
std::unique_ptr< weld::Label > m_xAutoIncrementText
void DisplayData(OFieldDescription *pFieldDescr)
std::unique_ptr< OPropListBoxCtrl > m_xNumType
void UpdateFormatSample(OFieldDescription const *pFieldDescr)
std::unique_ptr< OPropNumericEditCtrl > m_xTextLen
std::unique_ptr< weld::Label > m_xAutoIncrementValueText
TOTypeInfoSP m_pPreviousType
OUString BoolStringUI(const OUString &rPersistentString) const
std::unique_ptr< weld::Button > m_xFormat
void SetControlText(sal_uInt16 nControlId, const OUString &rText)
std::unique_ptr< weld::Label > m_xFormatText
virtual bool isCutAllowed() override
bool isTextFormat(const OFieldDescription *_pFieldDescr, sal_uInt32 &_nFormatKey) const
std::unique_ptr< OPropListBoxCtrl > m_xBoolDefault
void implFocusLost(weld::Widget *_pWhich)
virtual const OTypeInfoMap * getTypeInfo() const =0
std::unique_ptr< weld::Label > m_xBoolDefaultText
std::unique_ptr< OPropColumnEditCtrl > m_xColumnName
void InitializeControl(weld::Widget *_pControl, const OUString &_sHelpId)
std::unique_ptr< OPropEditCtrl > m_xFormatSample
std::unique_ptr< weld::Label > m_xRequiredText
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > getMetaData()=0
std::unique_ptr< OPropEditCtrl > m_xDefault
std::unique_ptr< OPropEditCtrl > m_xAutoIncrementValue
std::unique_ptr< weld::Label > m_xLengthText
std::unique_ptr< OPropListBoxCtrl > m_xAutoIncrement
OUString CanonicalizeToControlDefault(const OFieldDescription *pFieldDescr, const OUString &rUserText) const
virtual void DeactivateAggregate(EControlType eType)
virtual css::lang::Locale GetLocale() const =0
virtual css::uno::Reference< css::util::XNumberFormatter > GetFormatter() const =0
OTableDesignHelpBar * m_pHelp
void SetControlDefault(const css::uno::Any &_rControlDefault)
void SetPrecision(sal_Int32 _rPrecision)
void SetIsNullable(sal_Int32 _rIsNullable)
const TOTypeInfoSP & getTypeInfo() const
void SetType(const TOTypeInfoSP &_pType)
sal_Int32 GetScale() const
void SetAutoIncrementValue(const OUString &_sAutoIncValue)
bool IsAutoIncrement() const
void SetAutoIncrement(bool _bAuto)
void SetName(const OUString &_rName)
sal_Int32 GetFormatKey() const
OUString GetAutoIncrementValue() const
bool IsPrimaryKey() const
sal_Int32 GetType() const
css::uno::Any GetControlDefault() const
sal_Int32 GetPrecision() const
void SetScale(sal_Int32 _rScale)
weld::ComboBox & GetComboBox()
void SetHelpText(const OUString &rText)
void connect_focus_out(const Link< weld::Widget &, void > &rLink)
void connect_changed(const Link< ComboBox &, void > &rLink)
virtual void cut_clipboard()=0
virtual bool get_selection_bounds(int &rStartPos, int &rEndPos)=0
virtual void copy_clipboard()=0
virtual void paste_clipboard()=0
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral HID_TAB_ENT_FORMAT_SAMPLE
constexpr OUStringLiteral HID_TAB_ENT_TEXT_LEN
constexpr OUStringLiteral HID_TAB_ENT_NUMTYP
constexpr OUStringLiteral HID_TAB_ENT_SCALE
constexpr OUStringLiteral HID_TAB_ENT_COLUMNNAME
constexpr OUStringLiteral HID_TAB_ENT_LEN
constexpr OUStringLiteral HID_TAB_ENT_TYPE
constexpr OUStringLiteral HID_TAB_ENT_BOOL_DEFAULT
constexpr OUStringLiteral HID_TAB_AUTOINCREMENTVALUE
constexpr OUStringLiteral HID_TAB_ENT_AUTOINCREMENT
constexpr OUStringLiteral HID_TAB_ENT_REQUIRED
constexpr OUStringLiteral HID_TAB_ENT_FORMAT
constexpr OUStringLiteral HID_TAB_ENT_DEFAULT
#define LINK(Instance, Class, Member)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
void callColumnFormatDialog(const css::uno::Reference< css::beans::XPropertySet > &_xAffectedCol, const css::uno::Reference< css::beans::XPropertySet > &_xField, SvNumberFormatter *_pFormatter, weld::Widget *_pParent)
call the format dialog and set the selected format at the column
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
std::multimap< sal_Int32, TOTypeInfoSP > OTypeInfoMap
void setEvalDateFormatForFormatter(css::uno::Reference< css::util::XNumberFormatter > const &_rxFormatter)
set the evaluation flag at the number formatter
std::shared_ptr< OTypeInfo > TOTypeInfoSP
bool isSQL92CheckEnabled(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
check if SQL92 name checking is enabled
Reference< XNameAccess > m_xContainer