From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sd/source/ui/table/TableDesignPane.cxx | 763 +++++++++++++++++++++++++++++++++ sd/source/ui/table/tablefunction.cxx | 292 +++++++++++++ sd/source/ui/table/tableobjectbar.cxx | 224 ++++++++++ sd/source/ui/table/tableobjectbar.hxx | 56 +++ 4 files changed, 1335 insertions(+) create mode 100644 sd/source/ui/table/TableDesignPane.cxx create mode 100644 sd/source/ui/table/tablefunction.cxx create mode 100644 sd/source/ui/table/tableobjectbar.cxx create mode 100644 sd/source/ui/table/tableobjectbar.hxx (limited to 'sd/source/ui/table') diff --git a/sd/source/ui/table/TableDesignPane.cxx b/sd/source/ui/table/TableDesignPane.cxx new file mode 100644 index 000000000..82d4485fb --- /dev/null +++ b/sd/source/ui/table/TableDesignPane.cxx @@ -0,0 +1,763 @@ +/* -*- 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 . + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::view; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::ui; + +namespace sd { + +const sal_Int32 nPreviewColumns = 5; +const sal_Int32 nPreviewRows = 5; +const sal_Int32 nCellWidth = 12; // one pixel is shared with the next cell! +const sal_Int32 nCellHeight = 7; // one pixel is shared with the next cell! +const sal_Int32 nBitmapWidth = (nCellWidth * nPreviewColumns) - (nPreviewColumns - 1); +const sal_Int32 nBitmapHeight = (nCellHeight * nPreviewRows) - (nPreviewRows - 1); + +const std::string_view gPropNames[CB_COUNT] = +{ + "UseFirstRowStyle", + "UseLastRowStyle", + "UseBandingRowStyle", + "UseFirstColumnStyle", + "UseLastColumnStyle", + "UseBandingColumnStyle" +}; + +TableDesignWidget::TableDesignWidget(weld::Builder& rBuilder, ViewShellBase& rBase) + : mrBase(rBase) + , m_xValueSet(new TableValueSet(rBuilder.weld_scrolled_window("previewswin", true))) + , m_xValueSetWin(new weld::CustomWeld(rBuilder, "previews", *m_xValueSet)) +{ + m_xValueSet->SetStyle(m_xValueSet->GetStyle() | WB_NO_DIRECTSELECT | WB_FLATVALUESET | WB_ITEMBORDER); + m_xValueSet->SetExtraSpacing(8); + m_xValueSet->setModal(false); + m_xValueSet->SetColor(); + m_xValueSet->SetSelectHdl(LINK(this, TableDesignWidget, implValueSetHdl)); + + for (sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i) + { + m_aCheckBoxes[i] = rBuilder.weld_check_button(OString(gPropNames[i].data(), gPropNames[i].size())); + m_aCheckBoxes[i]->connect_toggled(LINK(this, TableDesignWidget, implCheckBoxHdl)); + } + + // get current controller and initialize listeners + try + { + mxView.set(mrBase.GetController(), UNO_QUERY); + addListener(); + + Reference< XController > xController( mrBase.GetController(), UNO_SET_THROW ); + Reference< XStyleFamiliesSupplier > xFamiliesSupp( xController->getModel(), UNO_QUERY_THROW ); + Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); + mxTableFamily.set( xFamilies->getByName( "table" ), UNO_QUERY_THROW ); + } + catch (const Exception&) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::CustomAnimationPane::CustomAnimationPane()" ); + } + + onSelectionChanged(); + updateControls(); +} + +TableDesignWidget::~TableDesignWidget() +{ + removeListener(); +} + +static SfxBindings* getBindings( ViewShellBase const & rBase ) +{ + if( rBase.GetMainViewShell() && rBase.GetMainViewShell()->GetViewFrame() ) + return &rBase.GetMainViewShell()->GetViewFrame()->GetBindings(); + else + return nullptr; +} + +static SfxDispatcher* getDispatcher( ViewShellBase const & rBase ) +{ + if( rBase.GetMainViewShell() && rBase.GetMainViewShell()->GetViewFrame() ) + return rBase.GetMainViewShell()->GetViewFrame()->GetDispatcher(); + else + return nullptr; +} + +IMPL_LINK_NOARG(TableDesignWidget, implValueSetHdl, ValueSet*, void) +{ + ApplyStyle(); +} + +void TableDesignWidget::ApplyStyle() +{ + try + { + OUString sStyleName; + sal_Int32 nIndex = static_cast< sal_Int32 >( m_xValueSet->GetSelectedItemId() ) - 1; + + if( (nIndex >= 0) && (nIndex < mxTableFamily->getCount()) ) + { + Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY_THROW ); + sStyleName = xNames->getElementNames()[nIndex]; + } + + if( sStyleName.isEmpty() ) + return; + + SdrView* pView = mrBase.GetDrawView(); + if( mxSelectedTable.is() ) + { + if( pView ) + { + SfxRequest aReq( SID_TABLE_STYLE, SfxCallMode::SYNCHRON, SfxGetpApp()->GetPool() ); + aReq.AppendItem( SfxStringItem( SID_TABLE_STYLE, sStyleName ) ); + + const rtl::Reference< sdr::SelectionController >& xController( pView->getSelectionController() ); + if( xController.is() ) + xController->Execute( aReq ); + + SfxBindings* pBindings = getBindings( mrBase ); + if( pBindings ) + { + pBindings->Invalidate( SID_UNDO ); + pBindings->Invalidate( SID_REDO ); + } + } + } + else + { + SfxDispatcher* pDispatcher = getDispatcher( mrBase ); + SfxStringItem aArg( SID_TABLE_STYLE, sStyleName ); + pDispatcher->ExecuteList(SID_INSERT_TABLE, SfxCallMode::ASYNCHRON, + { &aArg }); + } + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "TableDesignWidget::implValueSetHdl()"); + } +} + +IMPL_LINK_NOARG(TableDesignWidget, implCheckBoxHdl, weld::Toggleable&, void) +{ + ApplyOptions(); + FillDesignPreviewControl(); +} + +void TableDesignWidget::ApplyOptions() +{ + static const sal_uInt16 gParamIds[CB_COUNT] = + { + ID_VAL_USEFIRSTROWSTYLE, ID_VAL_USELASTROWSTYLE, ID_VAL_USEBANDINGROWSTYLE, + ID_VAL_USEFIRSTCOLUMNSTYLE, ID_VAL_USELASTCOLUMNSTYLE, ID_VAL_USEBANDINGCOLUMNSTYLE + }; + + if( !mxSelectedTable.is() ) + return; + + SfxRequest aReq( SID_TABLE_STYLE_SETTINGS, SfxCallMode::SYNCHRON, SfxGetpApp()->GetPool() ); + + for( sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i ) + { + aReq.AppendItem( SfxBoolItem( gParamIds[i], m_aCheckBoxes[i]->get_active() ) ); + } + + SdrView* pView = mrBase.GetDrawView(); + if( !pView ) + return; + + const rtl::Reference< sdr::SelectionController >& xController( pView->getSelectionController() ); + if( xController.is() ) + { + xController->Execute( aReq ); + + SfxBindings* pBindings = getBindings( mrBase ); + if( pBindings ) + { + pBindings->Invalidate( SID_UNDO ); + pBindings->Invalidate( SID_REDO ); + } + } +} + +void TableDesignWidget::onSelectionChanged() +{ + Reference< XPropertySet > xNewSelection; + + if( mxView.is() ) try + { + Reference< XSelectionSupplier > xSel( mxView, UNO_QUERY_THROW ); + Any aSel( xSel->getSelection() ); + Sequence< XShape > xShapeSeq; + if( aSel >>= xShapeSeq ) + { + if( xShapeSeq.getLength() == 1 ) + aSel <<= xShapeSeq[0]; + } + else + { + Reference< XShapes > xShapes( aSel, UNO_QUERY ); + if( xShapes.is() && (xShapes->getCount() == 1) ) + aSel = xShapes->getByIndex(0); + } + + Reference< XShapeDescriptor > xDesc( aSel, UNO_QUERY ); + if( xDesc.is() && ( xDesc->getShapeType() == "com.sun.star.drawing.TableShape" || xDesc->getShapeType() == "com.sun.star.presentation.TableShape" ) ) + { + xNewSelection.set( xDesc, UNO_QUERY ); + } + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::TableDesignWidget::onSelectionChanged()" ); + } + + if( mxSelectedTable != xNewSelection ) + { + mxSelectedTable = xNewSelection; + updateControls(); + } +} + +void TableValueSet::Resize() +{ + ValueSet::Resize(); + // Calculate the number of rows and columns. + if( GetItemCount() <= 0 ) + return; + + Size aValueSetSize = GetOutputSizePixel(); + + Image aImage = GetItemImage(GetItemId(0)); + Size aItemSize = aImage.GetSizePixel(); + + aItemSize.AdjustHeight(10 ); + int nColumnCount = (aValueSetSize.Width() - GetScrollWidth()) / aItemSize.Width(); + if (nColumnCount < 1) + nColumnCount = 1; + + int nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount; + if (nRowCount < 1) + nRowCount = 1; + + int nVisibleRowCount = (aValueSetSize.Height()+2) / aItemSize.Height(); + + SetColCount (static_cast(nColumnCount)); + SetLineCount (static_cast(nRowCount)); + + if( !m_bModal ) + { + WinBits nStyle = GetStyle() & ~WB_VSCROLL; + if( nRowCount > nVisibleRowCount ) + { + nStyle |= WB_VSCROLL; + } + SetStyle( nStyle ); + } +} + +TableValueSet::TableValueSet(std::unique_ptr pScrolledWindow) + : ValueSet(std::move(pScrolledWindow)) + , m_bModal(false) +{ +} + +void TableValueSet::StyleUpdated() +{ + updateSettings(); +} + +void TableValueSet::updateSettings() +{ + if( !m_bModal ) + { + Color aColor = Application::GetSettings().GetStyleSettings().GetWindowColor(); + SetColor(aColor); + SetExtraSpacing(8); + } +} + +void TableDesignWidget::updateControls() +{ + static const bool gDefaults[CB_COUNT] = { true, false, true, false, false, false }; + + const bool bHasTable = mxSelectedTable.is(); + + for (sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i) + { + bool bUse = gDefaults[i]; + if( bHasTable ) try + { + mxSelectedTable->getPropertyValue( OUString::createFromAscii(gPropNames[i]) ) >>= bUse; + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::TableDesignWidget::updateControls()"); + } + m_aCheckBoxes[i]->set_active(bUse); + m_aCheckBoxes[i]->set_sensitive(bHasTable); + } + + FillDesignPreviewControl(); + m_xValueSet->updateSettings(); + m_xValueSet->Resize(); + + sal_uInt16 nSelection = 0; + if( mxSelectedTable.is() ) + { + Reference< XNamed > xNamed( mxSelectedTable->getPropertyValue( "TableTemplate" ), UNO_QUERY ); + if( xNamed.is() ) + { + const OUString sStyleName( xNamed->getName() ); + + Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY ); + if( xNames.is() ) + { + Sequence< OUString > aNames( xNames->getElementNames() ); + sal_Int32 nIndex = comphelper::findValue(aNames, sStyleName); + if (nIndex != -1) + nSelection = static_cast(nIndex) + 1; + } + } + } + m_xValueSet->SelectItem( nSelection ); +} + +void TableDesignWidget::addListener() +{ + Link aLink( LINK(this,TableDesignWidget,EventMultiplexerListener) ); + mrBase.GetEventMultiplexer()->AddEventListener( aLink ); +} + +void TableDesignWidget::removeListener() +{ + Link aLink( LINK(this,TableDesignWidget,EventMultiplexerListener) ); + mrBase.GetEventMultiplexer()->RemoveEventListener( aLink ); +} + +IMPL_LINK(TableDesignWidget,EventMultiplexerListener, + tools::EventMultiplexerEvent&, rEvent, void) +{ + switch (rEvent.meEventId) + { + case EventMultiplexerEventId::CurrentPageChanged: + case EventMultiplexerEventId::EditViewSelection: + onSelectionChanged(); + break; + + case EventMultiplexerEventId::MainViewRemoved: + mxView.clear(); + onSelectionChanged(); + break; + + case EventMultiplexerEventId::MainViewAdded: + mxView.set( mrBase.GetController(), UNO_QUERY ); + onSelectionChanged(); + break; + + default: break; + } +} + +namespace { + +struct CellInfo +{ + Color maCellColor; + Color maTextColor; + std::shared_ptr maBorder; + + explicit CellInfo( const Reference< XStyle >& xStyle ); +}; + +} + +CellInfo::CellInfo( const Reference< XStyle >& xStyle ) +: maBorder(std::make_shared(SDRATTR_TABLE_BORDER)) +{ + SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle ); + if( !pStyleSheet ) + return; + + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + + // get style fill color + if( !GetDraftFillColor(rSet, maCellColor) ) + maCellColor = COL_TRANSPARENT; + + // get style text color + const SvxColorItem* pTextColor = rSet.GetItem(EE_CHAR_COLOR); + if( pTextColor ) + maTextColor = pTextColor->GetValue(); + else + maTextColor = COL_TRANSPARENT; + + // get border + const SvxBoxItem* pBoxItem = rSet.GetItem( SDRATTR_TABLE_BORDER ); + if( pBoxItem ) + maBorder.reset(pBoxItem->Clone()); +} + +typedef std::vector< std::shared_ptr< CellInfo > > CellInfoVector; +typedef std::shared_ptr< CellInfo > CellInfoMatrix[nPreviewColumns * nPreviewRows]; + +namespace { + +struct TableStyleSettings +{ + bool mbUseFirstRow; + bool mbUseLastRow; + bool mbUseFirstColumn; + bool mbUseLastColumn; + bool mbUseRowBanding; + bool mbUseColumnBanding; + + TableStyleSettings() + : mbUseFirstRow(true) + , mbUseLastRow(false) + , mbUseFirstColumn(false) + , mbUseLastColumn(false) + , mbUseRowBanding(true) + , mbUseColumnBanding(false) {} +}; + +} + +static void FillCellInfoVector( const Reference< XIndexAccess >& xTableStyle, CellInfoVector& rVector ) +{ + DBG_ASSERT( xTableStyle.is() && (xTableStyle->getCount() == sdr::table::style_count ), "sd::FillCellInfoVector(), invalid table style!" ); + if( !xTableStyle.is() ) + return; + + try + { + rVector.resize( sdr::table::style_count ); + + for( sal_Int32 nStyle = 0; nStyle < sdr::table::style_count; ++nStyle ) + { + Reference< XStyle > xStyle( xTableStyle->getByIndex( nStyle ), UNO_QUERY ); + if( xStyle.is() ) + rVector[nStyle] = std::make_shared( xStyle ); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::FillCellInfoVector()"); + } +} + +static void FillCellInfoMatrix( const CellInfoVector& rStyle, const TableStyleSettings& rSettings, CellInfoMatrix& rMatrix ) +{ + for( sal_Int32 nRow = 0; nRow < nPreviewColumns; ++nRow ) + { + const bool bFirstRow = rSettings.mbUseFirstRow && (nRow == 0); + const bool bLastRow = rSettings.mbUseLastRow && (nRow == nPreviewColumns - 1); + + for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol ) + { + std::shared_ptr< CellInfo > xCellInfo; + + // first and last row win first, if used and available + if( bFirstRow ) + { + xCellInfo = rStyle[sdr::table::first_row_style]; + } + else if( bLastRow ) + { + xCellInfo = rStyle[sdr::table::last_row_style]; + } + + if( !xCellInfo ) + { + // next come first and last column, if used and available + if( rSettings.mbUseFirstColumn && (nCol == 0) ) + { + xCellInfo = rStyle[sdr::table::first_column_style]; + } + else if( rSettings.mbUseLastColumn && (nCol == nPreviewColumns-1) ) + { + xCellInfo = rStyle[sdr::table::last_column_style]; + } + } + + if( !xCellInfo ) + { + if( rSettings.mbUseRowBanding ) + { + if( (nRow & 1) == 0 ) + { + xCellInfo = rStyle[sdr::table::even_rows_style]; + } + else + { + xCellInfo = rStyle[sdr::table::odd_rows_style]; + } + } + } + + if( !xCellInfo ) + { + if( rSettings.mbUseColumnBanding ) + { + if( (nCol & 1) == 0 ) + { + xCellInfo = rStyle[sdr::table::even_columns_style]; + } + else + { + xCellInfo = rStyle[sdr::table::odd_columns_style]; + } + } + } + + if( !xCellInfo ) + { + // use default cell style if non found yet + xCellInfo = rStyle[sdr::table::body_style]; + } + + rMatrix[(nCol * nPreviewColumns) + nRow] = xCellInfo; + } + } +} + +static BitmapEx CreateDesignPreview( const Reference< XIndexAccess >& xTableStyle, const TableStyleSettings& rSettings, bool bIsPageDark ) +{ + CellInfoVector aCellInfoVector(sdr::table::style_count); + FillCellInfoVector( xTableStyle, aCellInfoVector ); + + CellInfoMatrix aMatrix; + FillCellInfoMatrix( aCellInfoVector, rSettings, aMatrix ); + + // bbbbbbbbbbbb w = 12 pixel + // bccccccccccb h = 7 pixel + // bccccccccccb b = border color + // bcttttttttcb c = cell color + // bccccccccccb t = text color + // bccccccccccb + // bbbbbbbbbbbb + + ScopedVclPtr pVirDev(VclPtr::Create()); + Size aBmpSize(nBitmapWidth, nBitmapHeight); + pVirDev->SetOutputSizePixel(aBmpSize); + + pVirDev->SetBackground( bIsPageDark ? COL_BLACK : COL_WHITE ); + pVirDev->Erase(); + + // first draw cell background and text line previews + sal_Int32 nY = 0; + sal_Int32 nRow; + for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 ) + { + sal_Int32 nX = 0; + for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 ) + { + std::shared_ptr< CellInfo > xCellInfo(aMatrix[(nCol * nPreviewColumns) + nRow]); + + Color aTextColor( COL_AUTO ); + if( xCellInfo ) + { + // fill cell background + const ::tools::Rectangle aRect( nX, nY, nX + nCellWidth - 1, nY + nCellHeight - 1 ); + + if( xCellInfo->maCellColor != COL_TRANSPARENT ) + { + pVirDev->SetFillColor( xCellInfo->maCellColor ); + pVirDev->DrawRect( aRect ); + } + + aTextColor = xCellInfo->maTextColor; + } + + // draw text preview line + if( aTextColor == COL_AUTO ) + aTextColor = bIsPageDark ? COL_WHITE : COL_BLACK; + pVirDev->SetLineColor( aTextColor ); + const Point aPnt1( nX + 2, nY + ((nCellHeight - 1 ) >> 1) ); + const Point aPnt2( nX + nCellWidth - 3, aPnt1.Y() ); + pVirDev->DrawLine( aPnt1, aPnt2 ); + } + } + + // second draw border lines + nY = 0; + for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 ) + { + sal_Int32 nX = 0; + for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 ) + { + std::shared_ptr< CellInfo > xCellInfo(aMatrix[(nCol * nPreviewColumns) + nRow]); + + if( xCellInfo ) + { + const Point aPntTL( nX, nY ); + const Point aPntTR( nX + nCellWidth - 1, nY ); + const Point aPntBL( nX, nY + nCellHeight - 1 ); + const Point aPntBR( nX + nCellWidth - 1, nY + nCellHeight - 1 ); + + sal_Int32 border_diffs[8] = { 0,-1, 0,1, -1,0, 1,0 }; + sal_Int32* pDiff = &border_diffs[0]; + + // draw top border + for( SvxBoxItemLine nLine : o3tl::enumrange() ) + { + const ::editeng::SvxBorderLine* pBorderLine = xCellInfo->maBorder->GetLine(nLine); + if( !pBorderLine || ((pBorderLine->GetOutWidth() == 0) && (pBorderLine->GetInWidth()==0)) ) + continue; + + sal_Int32 nBorderCol = nCol + *pDiff++; + sal_Int32 nBorderRow = nRow + *pDiff++; + if( (nBorderCol >= 0) && (nBorderCol < nPreviewColumns) && (nBorderRow >= 0) && (nBorderRow < nPreviewRows) ) + { + // check border + std::shared_ptr< CellInfo > xBorderInfo(aMatrix[(nBorderCol * nPreviewColumns) + nBorderRow]); + if( xBorderInfo ) + { + const ::editeng::SvxBorderLine* pBorderLine2 = xBorderInfo->maBorder->GetLine(static_cast(static_cast(nLine)^1)); + if( pBorderLine2 && pBorderLine2->HasPriority(*pBorderLine) ) + continue; // other border line wins + } + } + + pVirDev->SetLineColor( pBorderLine->GetColor() ); + switch( nLine ) + { + case SvxBoxItemLine::TOP: pVirDev->DrawLine( aPntTL, aPntTR ); break; + case SvxBoxItemLine::BOTTOM: pVirDev->DrawLine( aPntBL, aPntBR ); break; + case SvxBoxItemLine::LEFT: pVirDev->DrawLine( aPntTL, aPntBL ); break; + case SvxBoxItemLine::RIGHT: pVirDev->DrawLine( aPntTR, aPntBR ); break; + } + } + } + } + } + + return pVirDev->GetBitmapEx(Point(0,0), aBmpSize); +} + +void TableDesignWidget::FillDesignPreviewControl() +{ + sal_uInt16 nSelectedItem = m_xValueSet->GetSelectedItemId(); + m_xValueSet->Clear(); + try + { + TableStyleSettings aSettings; + if( mxSelectedTable.is() ) + { + aSettings.mbUseFirstRow = m_aCheckBoxes[CB_HEADER_ROW]->get_active(); + aSettings.mbUseLastRow = m_aCheckBoxes[CB_TOTAL_ROW]->get_active(); + aSettings.mbUseRowBanding = m_aCheckBoxes[CB_BANDED_ROWS]->get_active(); + aSettings.mbUseFirstColumn = m_aCheckBoxes[CB_FIRST_COLUMN]->get_active(); + aSettings.mbUseLastColumn = m_aCheckBoxes[CB_LAST_COLUMN]->get_active(); + aSettings.mbUseColumnBanding = m_aCheckBoxes[CB_BANDED_COLUMNS]->get_active(); + } + + bool bIsPageDark = false; + if( mxView.is() ) + { + Reference< XPropertySet > xPageSet( mxView->getCurrentPage(), UNO_QUERY ); + if( xPageSet.is() ) + { + xPageSet->getPropertyValue("IsBackgroundDark") >>= bIsPageDark; + } + } + + sal_Int32 nCount = mxTableFamily->getCount(); + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) try + { + Reference< XIndexAccess > xTableStyle( mxTableFamily->getByIndex( nIndex ), UNO_QUERY ); + if( xTableStyle.is() ) + m_xValueSet->InsertItem( sal::static_int_cast( nIndex + 1 ), Image( CreateDesignPreview( xTableStyle, aSettings, bIsPageDark ) ) ); + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::TableDesignWidget::FillDesignPreviewControl()"); + } + sal_Int32 nCols = 3; + sal_Int32 nRows = (nCount+2)/3; + m_xValueSet->SetColCount(nCols); + m_xValueSet->SetLineCount(nRows); + WinBits nStyle = m_xValueSet->GetStyle() & ~WB_VSCROLL; + m_xValueSet->SetStyle(nStyle); + + m_xValueSet->SetOptimalSize(); + weld::DrawingArea* pDrawingArea = m_xValueSet->GetDrawingArea(); + Size aSize = pDrawingArea->get_preferred_size(); + aSize.AdjustWidth(10 * nCols); + aSize.AdjustHeight(10 * nRows); + pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); + + m_xValueSet->Resize(); + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::TableDesignWidget::FillDesignPreviewControl()"); + } + m_xValueSet->SelectItem(nSelectedItem); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/table/tablefunction.cxx b/sd/source/ui/table/tablefunction.cxx new file mode 100644 index 000000000..c19445429 --- /dev/null +++ b/sd/source/ui/table/tablefunction.cxx @@ -0,0 +1,292 @@ +/* -*- 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 . + */ + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace ::sd; +using namespace sdr::table; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::linguistic2; + +namespace sd +{ + +static void apply_table_style( SdrTableObj* pObj, SdrModel const * pModel, const OUString& sTableStyle ) +{ + if( !(pModel && pObj) ) + return; + + Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) ); + if( !xPool.is() ) + return; + + try + { + Reference< XNameContainer > xTableFamily( xPool->getByName( "table" ), UNO_QUERY_THROW ); + OUString aStdName( "default" ); + if( !sTableStyle.isEmpty() ) + aStdName = sTableStyle; + Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW ); + pObj->setTableStyle( xStyle ); + } + catch( Exception& ) + { + TOOLS_WARN_EXCEPTION( "sd", "sd::apply_default_table_style()"); + } +} + +static void InsertTableImpl(const DrawViewShell* pShell, + ::sd::View* pView, + sal_Int32 nColumns, + sal_Int32 nRows, + const OUString& sTableStyle) +{ + ::tools::Rectangle aRect; + + SdrObject* pPickObj = pView->GetEmptyPresentationObject( PresObjKind::Table ); + if( pPickObj ) + { + aRect = pPickObj->GetLogicRect(); + aRect.setHeight( 200 ); + } + else + { + Size aSize( 14100, 2000 ); + + Point aPos; + ::tools::Rectangle aWinRect(aPos, pShell->GetActiveWindow()->GetOutputSizePixel()); + aWinRect = pShell->GetActiveWindow()->PixelToLogic(aWinRect); + + // make sure that the default size of the table fits on the paper and is inside the viewing area. + // if zoomed in close, don't make the table bigger than the viewing window. + Size aMaxSize = pShell->getCurrentPage()->GetSize(); + + if (comphelper::LibreOfficeKit::isActive()) + { + // aWinRect is nonsensical in the LOK case + aWinRect = ::tools::Rectangle(aPos, aMaxSize); + } + else + { + if( aMaxSize.Height() > aWinRect.getHeight() ) + aMaxSize.setHeight( aWinRect.getHeight() ); + if( aMaxSize.Width() > aWinRect.getWidth() ) + aMaxSize.setWidth( aWinRect.getWidth() ); + } + + if( aSize.Width() > aMaxSize.getWidth() ) + aSize.setWidth( aMaxSize.getWidth() ); + + // adjust height based on # of rows. + if( nRows > 0 ) + { + aSize.setHeight( aSize.Height() * nRows ); + if( aSize.Height() > aMaxSize.getHeight() ) + aSize.setHeight( aMaxSize.getHeight() ); + } + + aPos = aWinRect.Center(); + aPos.AdjustX( -(aSize.Width() / 2) ); + aPos.AdjustY( -(aSize.Height() / 2) ); + aRect = ::tools::Rectangle(aPos, aSize); + } + + sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( + *pShell->GetDoc(), // TTTT should be reference + aRect, + nColumns, + nRows); + pObj->NbcSetStyleSheet( pShell->GetDoc()->GetDefaultStyleSheet(), true ); + apply_table_style( pObj, pShell->GetDoc(), sTableStyle ); + SdrPageView* pPV = pView->GetSdrPageView(); + + // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode, + // so to be on the safe side call SdrEndTextEdit here + SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj); + + if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode()) + { + pView->SdrEndTextEdit(); + } + + // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj + if( pPickObj ) + { + SdPage* pPage = static_cast< SdPage* >(pPickObj->getSdrPageFromSdrObject()); + if(pPage && pPage->IsPresObj(pPickObj)) + { + pObj->SetUserCall( pPickObj->GetUserCall() ); + pPage->InsertPresObj( pObj, PresObjKind::Table ); + } + } + + pShell->GetParentWindow()->GrabFocus(); + if( pPickObj ) + pView->ReplaceObjectAtView(pPickObj, *pPV, pObj ); + else + pView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER); +} + +void DrawViewShell::FuTable(SfxRequest& rReq) +{ + switch( rReq.GetSlot() ) + { + case SID_INSERT_TABLE: + { + sal_Int32 nColumns = 0; + sal_Int32 nRows = 0; + OUString sTableStyle; + DrawViewShell* pShell = this; + ::sd::View* pView = mpView; + + const SfxUInt16Item* pCols = rReq.GetArg(SID_ATTR_TABLE_COLUMN); + const SfxUInt16Item* pRows = rReq.GetArg(SID_ATTR_TABLE_ROW); + const SfxStringItem* pStyle = rReq.GetArg(SID_TABLE_STYLE); + + if( pCols ) + nColumns = pCols->GetValue(); + + if( pRows ) + nRows = pRows->GetValue(); + + if( pStyle ) + sTableStyle = pStyle->GetValue(); + + if( (nColumns == 0) || (nRows == 0) ) + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + std::shared_ptr pDlg( pFact->CreateSvxNewTableDialog(rReq.GetFrameWeld()) ); + + weld::DialogController::runAsync(pDlg->getDialogController(), + [pDlg, pShell, pView, sTableStyle] (sal_Int32 nResult) { + if (nResult == RET_OK) + { + sal_Int32 nColumnsIn = pDlg->getColumns(); + sal_Int32 nRowsIn = pDlg->getRows(); + + InsertTableImpl(pShell, pView, nColumnsIn, nRowsIn, sTableStyle); + } + }); + } + else + { + InsertTableImpl(pShell, pView, nColumns, nRows, sTableStyle); + } + + rReq.Ignore(); + SfxViewShell* pViewShell = GetViewShell(); + OSL_ASSERT (pViewShell!=nullptr); + SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings(); + rBindings.Invalidate( SID_INSERT_TABLE, true ); + break; + } + case SID_TABLEDESIGN: + { + // First make sure that the sidebar is visible + GetViewFrame()->ShowChildWindow(SID_SIDEBAR); + ::sfx2::sidebar::Sidebar::ShowPanel( + u"SdTableDesignPanel", + GetViewFrame()->GetFrame().GetFrameInterface()); + + Cancel(); + rReq.Done (); + break; + } + default: + break; + } +} + +void DrawViewShell::GetTableMenuState( SfxItemSet &rSet ) +{ + OUString aActiveLayer = mpDrawView->GetActiveLayer(); + SdrPageView* pPV = mpDrawView->GetSdrPageView(); + + if( + ( !aActiveLayer.isEmpty() && pPV && ( pPV->IsLayerLocked(aActiveLayer) || + !pPV->IsLayerVisible(aActiveLayer) ) ) || + SD_MOD()->GetWaterCan() ) + { + rSet.DisableItem( SID_INSERT_TABLE ); + } +} + +void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel ) +{ + rStream.Seek( 0 ); + + if( !pModel ) + return; + + SdrPage* pPage = pModel->GetPage(0); + if( !pPage ) + return; + + Size aSize( 200, 200 ); + ::tools::Rectangle aRect (Point(), aSize); + sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( + *pModel, + aRect, + 1, + 1); + pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true ); + apply_table_style( pObj, pModel, OUString() ); + + pPage->NbcInsertObject( pObj ); + + sdr::table::ImportAsRTF( rStream, *pObj ); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/table/tableobjectbar.cxx b/sd/source/ui/table/tableobjectbar.cxx new file mode 100644 index 000000000..62d81d980 --- /dev/null +++ b/sd/source/ui/table/tableobjectbar.cxx @@ -0,0 +1,224 @@ +/* -*- 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "tableobjectbar.hxx" + +using namespace sd; +using namespace sd::ui::table; + +#define ShellClass_TableObjectBar +#include + +namespace sd::ui::table { + +/** creates a table object bar for the given ViewShell */ +SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView ) +{ + return new TableObjectBar( &rShell, pView ); +} + +/** registers the interfaces from the table ui */ +void RegisterInterfaces(const SfxModule* pMod) +{ + TableObjectBar::RegisterInterface(pMod); +} + + +SFX_IMPL_INTERFACE(TableObjectBar, SfxShell) + +void TableObjectBar::InitInterface_Impl() +{ +} + +TableObjectBar::TableObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView ) +: SfxShell( pSdViewShell->GetViewShell() ) +, mpView( pSdView ) +, mpViewSh( pSdViewShell ) +{ + DrawDocShell* pDocShell = mpViewSh->GetDocSh(); + if( pDocShell ) + { + SetPool( &pDocShell->GetPool() ); + SetUndoManager( pDocShell->GetUndoManager() ); + } + SetRepeatTarget( mpView ); + SetName( SdResId( RID_DRAW_TABLE_TOOLBOX ) ); + SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Table)); +} + +TableObjectBar::~TableObjectBar() +{ + SetRepeatTarget( nullptr ); +} + +void TableObjectBar::GetState( SfxItemSet& rSet ) +{ + if( mpView ) + { + rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() ); + if( xController.is() ) + { + xController->GetState( rSet ); + } + } +} + +void TableObjectBar::GetAttrState( SfxItemSet& rSet ) +{ + DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpViewSh ); + if( pDrawViewShell ) + pDrawViewShell->GetAttrState( rSet ); +} + +void TableObjectBar::Execute( SfxRequest& rReq ) +{ + if( !mpView ) + return; + + SdrView* pView = mpView; + SfxBindings* pBindings = &mpViewSh->GetViewFrame()->GetBindings(); + + rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() ); + sal_uLong nSlotId = rReq.GetSlot(); + if( xController.is() ) + { + switch( nSlotId ) + { + case SID_TABLE_INSERT_ROW_DLG: + case SID_TABLE_INSERT_ROW_BEFORE: + case SID_TABLE_INSERT_ROW_AFTER: + case SID_TABLE_INSERT_COL_DLG: + case SID_TABLE_INSERT_COL_BEFORE: + case SID_TABLE_INSERT_COL_AFTER: + { + ScopedVclPtr pDlg; + if (nSlotId == SID_TABLE_INSERT_ROW_DLG || nSlotId == SID_TABLE_INSERT_COL_DLG) + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + vcl::Window* pWin = mpView->GetViewShell()->GetParentWindow(); + pDlg.disposeAndReset( pFact->CreateSvxInsRowColDlg(pWin ? pWin->GetFrameWeld() : nullptr, + nSlotId == SID_TABLE_INSERT_COL_DLG, + SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) ); + + if (pDlg->Execute() != 1) + break; + } + + sal_uInt16 nCount = 1; + bool bInsertAfter = (nSlotId == SID_TABLE_INSERT_ROW_AFTER) || (nSlotId == SID_TABLE_INSERT_COL_AFTER); + + if (nSlotId == SID_TABLE_INSERT_ROW_DLG) + { + nCount = pDlg->getInsertCount(); + bInsertAfter = !pDlg->isInsertBefore(); + } + else if (nSlotId == SID_TABLE_INSERT_COL_DLG) + { + nCount = pDlg->getInsertCount(); + bInsertAfter = !pDlg->isInsertBefore(); + } + + if (nSlotId == SID_TABLE_INSERT_ROW_DLG || nSlotId == SID_TABLE_INSERT_ROW_BEFORE || nSlotId == SID_TABLE_INSERT_ROW_AFTER) + nSlotId = SID_TABLE_INSERT_ROW; + else + nSlotId = SID_TABLE_INSERT_COL; + + rReq.AppendItem(SfxInt16Item(static_cast(nSlotId), nCount)); + rReq.AppendItem(SfxBoolItem(SID_TABLE_PARAM_INSERT_AFTER, bInsertAfter)); + + rReq.SetSlot( static_cast(nSlotId) ); + } + } + + xController->Execute( rReq ); + } + + // note: we may be deleted at this point, no more member access possible + + switch( rReq.GetSlot() ) + { + case SID_ATTR_BORDER: + case SID_TABLE_MERGE_CELLS: + case SID_TABLE_SPLIT_CELLS: + case SID_OPTIMIZE_TABLE: + case SID_TABLE_DELETE_ROW: + case SID_TABLE_DELETE_COL: + case SID_TABLE_DELETE_TABLE: + case SID_FORMAT_TABLE_DLG: + case SID_TABLE_INSERT_ROW: + case SID_TABLE_INSERT_COL: + { + pView->AdjustMarkHdl(); + pBindings->Invalidate( SID_TABLE_DELETE_ROW ); + pBindings->Invalidate( SID_TABLE_DELETE_COL ); + pBindings->Invalidate( SID_TABLE_DELETE_TABLE ); + pBindings->Invalidate( SID_FRAME_LINESTYLE ); + pBindings->Invalidate( SID_FRAME_LINECOLOR ); + pBindings->Invalidate( SID_ATTR_BORDER ); + pBindings->Invalidate( SID_ATTR_FILL_STYLE ); + pBindings->Invalidate( SID_ATTR_FILL_USE_SLIDE_BACKGROUND ); + pBindings->Invalidate( SID_ATTR_FILL_TRANSPARENCE ); + pBindings->Invalidate( SID_ATTR_FILL_FLOATTRANSPARENCE ); + pBindings->Invalidate( SID_TABLE_MERGE_CELLS ); + pBindings->Invalidate( SID_TABLE_SPLIT_CELLS ); + pBindings->Invalidate( SID_OPTIMIZE_TABLE ); + pBindings->Invalidate( SID_TABLE_VERT_BOTTOM ); + pBindings->Invalidate( SID_TABLE_VERT_CENTER ); + pBindings->Invalidate( SID_TABLE_VERT_NONE ); + break; + } + case SID_TABLE_VERT_BOTTOM: + case SID_TABLE_VERT_CENTER: + case SID_TABLE_VERT_NONE: + { + pBindings->Invalidate( SID_TABLE_VERT_BOTTOM ); + pBindings->Invalidate( SID_TABLE_VERT_CENTER ); + pBindings->Invalidate( SID_TABLE_VERT_NONE ); + break; + } + } + + pBindings->Invalidate( SID_UNDO ); + pBindings->Invalidate( SID_REDO ); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/table/tableobjectbar.hxx b/sd/source/ui/table/tableobjectbar.hxx new file mode 100644 index 000000000..c5d513bff --- /dev/null +++ b/sd/source/ui/table/tableobjectbar.hxx @@ -0,0 +1,56 @@ +/* -*- 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 . + */ + +#pragma once + +#include +#include + +namespace sd { + +class View; +class ViewShell; + +} + +namespace sd::ui::table { + +class TableObjectBar final : public SfxShell +{ +public: + SFX_DECL_INTERFACE( SD_IF_SDDRAWTABLEOBJECTBAR ) + + TableObjectBar( ::sd::ViewShell* pSdViewShell, ::sd::View* pSdView); + virtual ~TableObjectBar() override; + + void GetState( SfxItemSet& rSet ); + void GetAttrState( SfxItemSet& rSet ); + void Execute( SfxRequest& rReq ); + +private: + /// SfxInterface initializer. + static void InitInterface_Impl(); + + ::sd::View* mpView; + ::sd::ViewShell* mpViewSh; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3