/* -*- 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 .
*/
// allow for a disabled control ... bool bEnabled = IsEnabled();
Color aOriginalColor = _rDev.GetTextColor(); if (!bEnabled)
_rDev.SetTextColor(GetSettings().GetStyleSettings().GetDisableColor());
// draw the text
_rDev.DrawText(aPos, aText);
// reset the color (if necessary) if (!bEnabled)
_rDev.SetTextColor(aOriginalColor);
if (_rDev.IsClipRegion())
_rDev.SetClipRegion();
}
void IndexFieldsControl::initializeFrom(IndexFields&& _rFields)
{ // copy the field descriptions
m_aFields = std::move(_rFields);
m_aSeekRow = m_aFields.end();
SetUpdateMode(false); // remove all rows
RowRemoved(1, GetRowCount()); // insert rows for the fields
RowInserted(GetRowCount(), m_aFields.size(), false); // insert an additional row for a new field for that index
RowInserted(GetRowCount(), 1, false);
SetUpdateMode(true);
GoToRowColumnId(0, COLUMN_ID_FIELDNAME);
}
void IndexFieldsControl::commitTo(IndexFields& _rFields)
{ // do not just copy the array, we may have empty field names (which should not be copied)
_rFields.resize(m_aFields.size());
IndexFields::iterator aDest = std::copy_if(m_aFields.begin(), m_aFields.end(), _rFields.begin(),
[](const OIndexField& source) { return !source.sFieldName.isEmpty(); });
_rFields.resize(aDest - _rFields.begin());
}
sal_uInt32 IndexFieldsControl::GetTotalCellWidth(sal_Int32 _nRow, sal_uInt16 _nColId)
{ if (COLUMN_ID_ORDER == _nColId)
{
sal_Int32 nWidthAsc = GetTextWidth(m_sAscendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
sal_Int32 nWidthDesc = GetTextWidth(m_sDescendingText) + GetSettings().GetStyleSettings().GetScrollBarSize(); // maximum plus some additional space return std::max(nWidthAsc, nWidthDesc) + GetTextWidth(OUString('0')) * 2;
} return EditBrowseBox::GetTotalCellWidth(_nRow, _nColId);
}
// for the width: both columns together should be somewhat smaller than the whole window (without the scrollbar)
sal_Int32 nFieldNameWidth = GetSizePixel().Width();
// the "sort order" column
OUString sColumnName = DBA_RES(STR_TAB_INDEX_SORTORDER); // the width of the order column is the maximum widths of the texts used // (the title of the column)
sal_Int32 nSortOrderColumnWidth = GetTextWidth(sColumnName); // ("ascending" + scrollbar width)
sal_Int32 nOther = GetTextWidth(m_sAscendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
nSortOrderColumnWidth = std::max(nSortOrderColumnWidth, nOther); // ("descending" + scrollbar width)
nOther = GetTextWidth(m_sDescendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
nSortOrderColumnWidth = std::max(nSortOrderColumnWidth, nOther); // (plus some additional space)
nSortOrderColumnWidth += GetTextWidth(OUString('0')) * 2;
InsertDataColumn(COLUMN_ID_ORDER, sColumnName, nSortOrderColumnWidth, HeaderBarItemBits::STDSTYLE, 1);
// create the cell controllers // for the field name cell
m_pFieldNameCell = VclPtr<ListBoxControl>::Create(&GetDataWindow());
weld::ComboBox& rNameListBox = m_pFieldNameCell->get_widget();
rNameListBox.append_text(OUString());
rNameListBox.set_help_id(HID_DLGINDEX_INDEXDETAILS_FIELD); for (auto& text : _rAvailableFields)
rNameListBox.append_text(text);
}
CellController* IndexFieldsControl::GetController(sal_Int32 _nRow, sal_uInt16 _nColumnId)
{ if (!IsEnabled()) return nullptr;
bool IndexFieldsControl::SaveModified()
{ if (!IsModified()) returntrue;
switch (GetCurColumnId())
{ case COLUMN_ID_FIELDNAME:
{
weld::ComboBox& rNameListBox = m_pFieldNameCell->get_widget();
OUString sFieldSelected = rNameListBox.get_active_text(); bool bEmptySelected = sFieldSelected.isEmpty(); if (isNewField())
{ if (!bEmptySelected)
{ // add a new field to the collection
OIndexField aNewField;
aNewField.sFieldName = sFieldSelected;
m_aFields.push_back(aNewField);
RowInserted(GetRowCount());
}
} else
{
sal_Int32 nRow = GetCurRow();
OSL_ENSURE(nRow < static_cast<sal_Int32>(m_aFields.size()), "IndexFieldsControl::SaveModified: invalid current row!"); if (nRow >= 0) // may be -1 in case the control was empty
{ // remove the field from the selection
IndexFields::iterator aPos = m_aFields.begin() + nRow;
if (bEmptySelected)
{
aPos->sFieldName.clear();
// invalidate the row to force repaint
Invalidate(GetRowRectPixel(nRow)); returntrue;
}
if (sFieldSelected == aPos->sFieldName) // nothing changed returntrue;
aPos->sFieldName = sFieldSelected;
}
}
Invalidate(GetRowRectPixel(GetCurRow()));
} break; case COLUMN_ID_ORDER:
{
OSL_ENSURE(!isNewField(), "IndexFieldsControl::SaveModified: why the hell ...!!!"); // selected entry
weld::ComboBox& rSortingListBox = m_pSortingCell->get_widget();
sal_Int32 nPos = rSortingListBox.get_active();
OSL_ENSURE(nPos != -1, "IndexFieldsControl::SaveModified: how did you get this selection??"); // adjust the sort flag in the index field description
OIndexField& rCurrentField = m_aFields[GetCurRow()];
rCurrentField.bSortAscending = (0 == nPos);
if (&rListBox != &m_pFieldNameCell->get_widget()) return;
// a field has been selected if (GetCurRow() >= GetRowCount() - 2)
{ // and we're in one of the last two rows
OUString sSelectedEntry = rListBox.get_active_text();
sal_Int32 nCurrentRow = GetCurRow();
sal_Int32 rowCount = GetRowCount();
if (!sSelectedEntry.isEmpty() && (nCurrentRow == rowCount - 1) /*&& (!m_nMaxColumnsInIndex || rowCount < m_nMaxColumnsInIndex )*/ )
{ // in the last row, a non-empty string has been selected // -> insert a new row
m_aFields.emplace_back();
RowInserted(GetRowCount());
Invalidate(GetRowRectPixel(nCurrentRow));
} elseif (sSelectedEntry.isEmpty() && (nCurrentRow == rowCount - 2))
{ // in the (last-1)th row, an empty entry has been selected // -> remove the last row
m_aFields.pop_back();
RowRemoved(GetRowCount() - 1);
Invalidate(GetRowRectPixel(nCurrentRow));
}
}
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.