/* -*- 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 .
*/
// the factory for the columns
Reference< XGridColumnFactory > xColumnFactory(rContext.xObjectModel, UNO_QUERY);
DBG_ASSERT(xColumnFactory.is(), "OGridWizard::implApplySettings: should never have made it 'til here!"); // (if we're here, what the hell happened in approveControl??)
// the container for the columns
Reference< XNameContainer > xColumnContainer(rContext.xObjectModel, UNO_QUERY);
DBG_ASSERT(xColumnContainer.is(), "OGridWizard::implApplySettings: no container!");
if (!xColumnFactory.is() || !xColumnContainer.is()) return;
// collect "descriptors" for the to-be-created (grid)columns
std::vector< OUString > aColumnServiceNames; // service names to be used with the XGridColumnFactory
std::vector< OUString > aColumnLabelPostfixes; // postfixes to append to the column labels
std::vector< OUString > aFormFieldNames; // data field names
// loop through the selected field names for (auto& selectedField : getSettings().aSelectedFields)
{ // get the information for the selected column
sal_Int32 nFieldType = DataType::OTHER;
OControlWizardContext::TNameTypeMap::const_iterator aFind = rContext.aTypes.find(selectedField); if ( aFind != rContext.aTypes.end() )
nFieldType = aFind->second;
aFormFieldNames.push_back(selectedField); switch (nFieldType)
{ case DataType::BIT: case DataType::BOOLEAN:
aColumnServiceNames.emplace_back("CheckBox");
aColumnLabelPostfixes.push_back(s_sEmptyString); break;
case DataType::TINYINT: case DataType::SMALLINT: case DataType::INTEGER:
aColumnServiceNames.emplace_back("NumericField");
aColumnLabelPostfixes.push_back(s_sEmptyString); break;
case DataType::FLOAT: case DataType::REAL: case DataType::DOUBLE: case DataType::NUMERIC: case DataType::DECIMAL:
aColumnServiceNames.emplace_back("FormattedField");
aColumnLabelPostfixes.push_back(s_sEmptyString); break;
case DataType::DATE:
aColumnServiceNames.emplace_back("DateField");
aColumnLabelPostfixes.push_back(s_sEmptyString); break;
case DataType::TIME:
aColumnServiceNames.emplace_back("TimeField");
aColumnLabelPostfixes.push_back(s_sEmptyString); break;
case DataType::TIMESTAMP:
aColumnServiceNames.emplace_back("DateField");
aColumnLabelPostfixes.push_back(compmodule::ModuleRes(RID_STR_DATEPOSTFIX));
// now loop through the descriptions and create the (grid)columns out of th descriptors
{
Reference< XNameAccess > xExistenceChecker(xColumnContainer);
// the data field the column should be bound to
xColumn->setPropertyValue(u"DataField"_ustr, Any(*pFormFieldName)); // the label
xColumn->setPropertyValue(u"Label"_ustr, Any(*pFormFieldName + *pColumnLabelPostfix)); // the width (<void/> => column will be auto-sized)
xColumn->setPropertyValue(u"Width"_ustr, Any());
// the index of the selected entry const sal_Int32 nSelected = bMoveRight ? m_xExistFields->get_selected_index() : m_xSelFields->get_selected_index(); // the (original) relative position of the entry int nRelativeIndex = bMoveRight ? m_xExistFields->get_id(nSelected).toInt32() : m_xSelFields->get_id(nSelected).toInt32();
sal_Int32 nInsertPos = -1; if (!bMoveRight)
{ // need to determine an insert pos which reflects the original
nInsertPos = 0; while (nInsertPos < rMoveTo.n_children())
{ if (rMoveTo.get_id(nInsertPos).toInt32() > nRelativeIndex) break;
++nInsertPos;
}
}
// the text of the entry to move
OUString sMovingEntry = bMoveRight ? m_xExistFields->get_text(nSelected) : m_xSelFields->get_text(nSelected);
// insert the entry preserving it's "relative position" entry data
OUString sId(OUString::number(nRelativeIndex));
rMoveTo.insert(nullptr, nInsertPos, &sMovingEntry, &sId, nullptr, nullptr, false, nullptr);
// remove the entry from its old list if (bMoveRight)
{
sal_Int32 nSelectPos = m_xExistFields->get_selected_index();
m_xExistFields->remove(nSelected); if ((nSelectPos != -1) && (nSelectPos < m_xExistFields->n_children()))
m_xExistFields->select(nSelectPos);
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.