24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/drawing/XDrawView.hpp>
26#include <com/sun/star/frame/XController.hpp>
27#include <com/sun/star/lang/XSingleServiceFactory.hpp>
28#include <com/sun/star/util/XModifiable.hpp>
29#include <com/sun/star/view/XSelectionSupplier.hpp>
30#include <com/sun/star/style/XStyle.hpp>
31#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
49#include <svx/svxids.hrc>
62#include <stlsheet.hxx>
65#include <bitmaps.hlst>
94 u"UseBandingRowStyle",
95 u"UseFirstColumnStyle",
96 u"UseLastColumnStyle",
97 u"UseBandingColumnStyle"
104 , m_xMenu(rBuilder.weld_menu(
"menu"))
105 , m_xValueSet(new
TableValueSet(rBuilder.weld_scrolled_window(
"previewswin", true)))
106 , m_xValueSetWin(new
weld::CustomWeld(rBuilder,
"previews", *m_xValueSet))
128 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
xController->getModel(), UNO_QUERY_THROW );
129 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
130 mxTableFamily.set( xFamilies->getByName(
"table" ), UNO_QUERY_THROW );
131 mxCellFamily.set( xFamilies->getByName(
"cell" ), UNO_QUERY_THROW );
152 Reference<util::XModifiable> xModifiable(
xController->getModel(), UNO_QUERY_THROW);
153 xModifiable->setModified(
true);
163 auto nClickedItemId = pPoint ? m_xValueSet->GetItemId(*pPoint) : m_xValueSet->GetSelectedItemId();
167 if (nClickedItemId > mxTableFamily->getCount())
172 Reference<XStyle> xStyle(mxTableFamily->getByIndex(nClickedItemId - 1), UNO_QUERY_THROW);
174 m_xMenu->set_visible(
"clone",
true);
175 m_xMenu->set_visible(
"format",
true);
176 m_xMenu->set_visible(
"delete", xStyle->isUserDefined());
177 m_xMenu->set_visible(
"reset", !xStyle->isUserDefined());
178 m_xMenu->set_sensitive(
"reset", Reference<util::XModifiable>(xStyle, UNO_QUERY_THROW)->isModified());
182 m_xMenu->set_visible(
"clone",
false);
183 m_xMenu->set_visible(
"format",
false);
184 m_xMenu->set_visible(
"delete",
false);
185 m_xMenu->set_visible(
"reset",
false);
193 m_xValueSet->SelectItem(nClickedItemId);
195 Point aPosition = pPoint ? *pPoint : m_xValueSet->GetItemRect(nClickedItemId).Center();
212 OUString getNewStyleName(
const Reference<XNameContainer>& rFamily, std::u16string_view rBaseName)
214 OUString
aName(rBaseName);
216 while(rFamily->hasByName(aName))
218 aName = rBaseName + OUString::number(nIndex++);
230 Reference<XNameContainer> xTableFamily(
mxTableFamily, UNO_QUERY_THROW);
231 Reference<XNameReplace> xTableStyle(
xFactory->createInstance(), UNO_QUERY_THROW);
233 xTableFamily->insertByName(
aName,
Any(xTableStyle));
235 Reference<XStyle> xCellStyle(
mxCellFamily->getByName(
"default"), UNO_QUERY_THROW);
237 xTableStyle->replaceByName(
"body",
Any(xCellStyle));
238 xTableStyle->replaceByName(
"odd-rows" ,
Any(xCellStyle));
239 xTableStyle->replaceByName(
"odd-columns" ,
Any(xCellStyle));
240 xTableStyle->replaceByName(
"first-row" ,
Any(xCellStyle));
241 xTableStyle->replaceByName(
"first-column" ,
Any(xCellStyle));
242 xTableStyle->replaceByName(
"last-row" ,
Any(xCellStyle));
243 xTableStyle->replaceByName(
"last-column" ,
Any(xCellStyle));
259 Reference<XNameAccess> xSrcTableStyle(
mxTableFamily->getByIndex(
m_xValueSet->GetSelectedItemId() - 1), UNO_QUERY_THROW);
262 Reference<XNameContainer> xTableFamily(
mxTableFamily, UNO_QUERY_THROW);
263 Reference<XNameReplace> xDestTableStyle(
xFactory->createInstance(), UNO_QUERY_THROW);
265 xTableFamily->insertByName(
aName,
Any(xDestTableStyle));
267 auto aNames(xSrcTableStyle->getElementNames());
268 for (
const auto&
name : aNames)
270 Reference<XStyle> xSrcCellStyle(xSrcTableStyle->getByName(
name), UNO_QUERY);
271 if (xSrcCellStyle && xSrcCellStyle->isUserDefined())
273 Reference<XSingleServiceFactory> xCellFactory(
mxCellFamily, UNO_QUERY_THROW);
274 Reference<XStyle> xDestCellStyle(xCellFactory->createInstance(), UNO_QUERY_THROW);
275 xDestCellStyle->setParentStyle(xSrcCellStyle->getParentStyle());
282 xDestStyleSheet->GetItemSet().Put(xSrcStyleSheet->GetItemSet());
284 xDestTableStyle->replaceByName(
name,
Any(xDestCellStyle));
287 xDestTableStyle->replaceByName(
name,
Any(xSrcCellStyle));
304 Reference<XIndexReplace> xTableStyle(
mxTableFamily->getByIndex(
m_xValueSet->GetSelectedItemId() - 1), UNO_QUERY_THROW);
306 for (sal_Int32
i = 0;
i < xTableStyle->getCount(); ++
i)
308 Reference<XStyle> xCellStyle(xTableStyle->getByIndex(
i), UNO_QUERY);
309 while (xCellStyle && xCellStyle->isUserDefined() && !xCellStyle->getParentStyle().isEmpty())
310 xCellStyle.set(
mxCellFamily->getByName(xCellStyle->getParentStyle()), UNO_QUERY);
312 xTableStyle->replaceByIndex(
i,
Any(xCellStyle));
316 Reference<util::XModifiable>(xTableStyle, UNO_QUERY_THROW)->setModified(
false);
333 if (xTableStyle->isInUse())
336 m_xValueSet->GetDrawingArea(), VclMessageType::Question, VclButtonsType::YesNo,
SdResId(STR_REMOVE_TABLESTYLE)));
344 Reference<XNameContainer>(
mxTableFamily, UNO_QUERY_THROW)->removeByName(xTableStyle->getName());
359 Reference<XNameReplace> xTableStyle(
mxTableFamily->getByIndex(
m_xValueSet->GetSelectedItemId() - 1), UNO_QUERY_THROW);
360 Reference<XStyle> xCellStyle(xTableStyle->getByName(rCommand), UNO_QUERY_THROW);
363 bool bUserDefined = xStyleSheet->IsEditable();
367 xCellStyle.set(
xFactory->createInstance(), UNO_QUERY_THROW);
368 xCellStyle->setParentStyle(xStyleSheet->getName());
369 xStyleSheet =
static_cast<SdStyleSheet*
>(xCellStyle.get());
372 SfxItemSet aNewAttr(xStyleSheet->GetItemSet());
376 aNewAttr.
Put(aBoxItem);
381 aNewAttr.
Put(aBoxInfoItem);
386 if (pDlg && pDlg->Execute() ==
RET_OK)
392 Reference<XNamed> xNamed(xTableStyle, UNO_QUERY_THROW);
393 const OUString aStyleName(getNewStyleName(
mxCellFamily, Concat2View(xNamed->getName() +
"-" + rCommand)));
395 xTableStyle->replaceByName(rCommand,
Any(xCellStyle));
398 SfxItemSet aNewSet(*pDlg->GetOutputItemSet());
401 xStyleSheet->GetItemSet().Put(aNewSet);
402 xStyleSheet->Broadcast(
SfxHint(SfxHintId::DataChanged));
440 sal_Int32
nIndex =
static_cast< sal_Int32
>(
m_xValueSet->GetSelectedItemId() ) - 1;
444 Reference< XNameAccess > xNames(
mxTableFamily, UNO_QUERY_THROW );
445 sStyleName = xNames->getElementNames()[
nIndex];
453 if( sStyleName.isEmpty() )
484 pDispatcher->
ExecuteList(SID_INSERT_TABLE, SfxCallMode::ASYNCHRON,
497 FillDesignPreviewControl();
502 static const sal_uInt16 gParamIds[
CB_COUNT] =
504 ID_VAL_USEFIRSTROWSTYLE, ID_VAL_USELASTROWSTYLE, ID_VAL_USEBANDINGROWSTYLE,
505 ID_VAL_USEFIRSTCOLUMNSTYLE, ID_VAL_USELASTCOLUMNSTYLE, ID_VAL_USEBANDINGCOLUMNSTYLE
539 Reference< XPropertySet > xNewSelection;
543 Reference< XSelectionSupplier > xSel(
mxView, UNO_QUERY_THROW );
544 Any aSel( xSel->getSelection() );
545 Sequence< XShape > xShapeSeq;
546 if( aSel >>= xShapeSeq )
548 if( xShapeSeq.getLength() == 1 )
549 aSel <<= xShapeSeq[0];
553 Reference< XShapes > xShapes( aSel, UNO_QUERY );
554 if( xShapes.is() && (xShapes->getCount() == 1) )
555 aSel = xShapes->getByIndex(0);
558 Reference< XShapeDescriptor > xDesc( aSel, UNO_QUERY );
559 if( xDesc.is() && ( xDesc->getShapeType() ==
"com.sun.star.drawing.TableShape" || xDesc->getShapeType() ==
"com.sun.star.presentation.TableShape" ) )
561 xNewSelection.set( xDesc, UNO_QUERY );
578 if (rEvent.
GetCommand() != CommandEventId::ContextMenu)
579 return ValueSet::Command(rEvent);
592 Size aValueSetSize = GetOutputSizePixel();
599 if (nColumnCount < 1)
602 int nRowCount = (
GetItemCount() + nColumnCount - 1) / nColumnCount;
608 SetColCount (
static_cast<sal_uInt16
>(nColumnCount));
609 SetLineCount (
static_cast<sal_uInt16
>(nVisibleRowCount));
614 if( nRowCount > nVisibleRowCount )
645 static const bool gDefaults[
CB_COUNT] = {
true,
false,
true,
false,
false,
false };
651 bool bUse = gDefaults[
i];
670 Reference< XNamed > xNamed(
mxSelectedTable->getPropertyValue(
"TableTemplate" ), UNO_QUERY );
681 Sequence< OUString > aNames( xNames->getElementNames() );
693 Reference<XInterface> xTableStyle(
mxSelectedTable->getPropertyValue(
"TableTemplate"), UNO_QUERY);
694 if (xTableStyle != rStyle)
716 switch (rEvent.meEventId)
720 onSelectionChanged();
725 onSelectionChanged();
729 mxView.set( mrBase.GetController(), UNO_QUERY );
730 onSelectionChanged();
743 std::shared_ptr<SvxBoxItem> maBorder;
745 explicit CellInfo(
const Reference< XStyle >& xStyle );
750CellInfo::CellInfo(
const Reference< XStyle >& xStyle )
766 maTextColor = pTextColor->
GetValue();
773 maBorder.reset(pBoxItem->
Clone());
781struct TableStyleSettings
785 bool mbUseFirstColumn;
786 bool mbUseLastColumn;
787 bool mbUseRowBanding;
788 bool mbUseColumnBanding;
791 : mbUseFirstRow(
true)
792 , mbUseLastRow(
false)
793 , mbUseFirstColumn(
false)
794 , mbUseLastColumn(
false)
795 , mbUseRowBanding(
true)
796 , mbUseColumnBanding(
false) {}
804 if( !xTableStyle.is() )
813 Reference< XStyle > xStyle( xTableStyle->getByIndex( nStyle ), UNO_QUERY );
815 rVector[nStyle] = std::make_shared<CellInfo>( xStyle );
828 const bool bFirstRow = rSettings.mbUseFirstRow && (nRow == 0);
829 const bool bLastRow = rSettings.mbUseLastRow && (nRow ==
nPreviewColumns - 1);
833 std::shared_ptr< CellInfo > xCellInfo;
848 if( rSettings.mbUseFirstColumn && (nCol == 0) )
860 if( rSettings.mbUseRowBanding )
862 if( (nRow & 1) == 0 )
875 if( rSettings.mbUseColumnBanding )
877 if( (nCol & 1) == 0 )
917 pVirDev->SetOutputSizePixel(aBmpSize);
930 std::shared_ptr< CellInfo > xCellInfo(aMatrix[(nCol *
nPreviewColumns) + nRow]);
940 pVirDev->SetFillColor( xCellInfo->maCellColor );
941 pVirDev->DrawRect( aRect );
944 aTextColor = xCellInfo->maTextColor;
950 pVirDev->SetLineColor( aTextColor );
953 pVirDev->DrawLine( aPnt1, aPnt2 );
964 std::shared_ptr< CellInfo > xCellInfo(aMatrix[(nCol *
nPreviewColumns) + nRow]);
968 const Point aPntTL( nX, nY );
973 sal_Int32 border_diffs[8] = { 0,-1, 0,1, -1,0, 1,0 };
974 sal_Int32* pDiff = &border_diffs[0];
979 const ::editeng::SvxBorderLine* pBorderLine = xCellInfo->maBorder->GetLine(nLine);
980 if( !pBorderLine || ((pBorderLine->GetOutWidth() == 0) && (pBorderLine->GetInWidth()==0)) )
983 sal_Int32 nBorderCol = nCol + *pDiff++;
984 sal_Int32 nBorderRow = nRow + *pDiff++;
988 std::shared_ptr< CellInfo > xBorderInfo(aMatrix[(nBorderCol *
nPreviewColumns) + nBorderRow]);
991 const ::editeng::SvxBorderLine* pBorderLine2 = xBorderInfo->maBorder->GetLine(
static_cast<SvxBoxItemLine>(
static_cast<int>(nLine)^1));
992 if( pBorderLine2 && pBorderLine2->HasPriority(*pBorderLine) )
997 pVirDev->SetLineColor( pBorderLine->GetColor() );
1000 case SvxBoxItemLine::TOP: pVirDev->DrawLine( aPntTL, aPntTR );
break;
1001 case SvxBoxItemLine::BOTTOM: pVirDev->DrawLine( aPntBL, aPntBR );
break;
1002 case SvxBoxItemLine::LEFT: pVirDev->DrawLine( aPntTL, aPntBL );
break;
1003 case SvxBoxItemLine::RIGHT: pVirDev->DrawLine( aPntTR, aPntBR );
break;
1010 return pVirDev->GetBitmapEx(
Point(0,0), aBmpSize);
1013void TableDesignWidget::FillDesignPreviewControl()
1015 sal_uInt16 nSelectedItem = m_xValueSet->GetSelectedItemId();
1016 m_xValueSet->Clear();
1019 TableStyleSettings aSettings;
1020 if( mxSelectedTable.is() )
1022 aSettings.mbUseFirstRow = m_aCheckBoxes[
CB_HEADER_ROW]->get_active();
1023 aSettings.mbUseLastRow = m_aCheckBoxes[
CB_TOTAL_ROW]->get_active();
1024 aSettings.mbUseRowBanding = m_aCheckBoxes[
CB_BANDED_ROWS]->get_active();
1025 aSettings.mbUseFirstColumn = m_aCheckBoxes[
CB_FIRST_COLUMN]->get_active();
1026 aSettings.mbUseLastColumn = m_aCheckBoxes[
CB_LAST_COLUMN]->get_active();
1030 bool bIsPageDark =
false;
1033 Reference< XPropertySet > xPageSet(
mxView->getCurrentPage(), UNO_QUERY );
1036 xPageSet->getPropertyValue(
"IsBackgroundDark") >>= bIsPageDark;
1040 sal_Int32
nCount = mxTableFamily->getCount();
1043 Reference< XIndexAccess > xTableStyle( mxTableFamily->getByIndex(
nIndex ), UNO_QUERY );
1044 if( xTableStyle.is() )
1051 m_xValueSet->InsertItem(++
nCount,
Image(StockImage::Yes, BMP_INSERT_TABLESTYLE),
SdResId(STR_INSERT_TABLESTYLE));
1053 sal_Int32 nCols = 3;
1054 sal_Int32 nRows = std::min<sal_Int32>((
nCount+2)/3, TableValueSet::getMaxRowCount());
1055 m_xValueSet->SetColCount(nCols);
1056 m_xValueSet->SetLineCount(nRows);
1057 WinBits nStyle = m_xValueSet->GetStyle() & ~WB_VSCROLL;
1058 m_xValueSet->SetStyle(nStyle);
1060 m_xValueSet->SetOptimalSize();
1067 m_xValueSet->Resize();
1073 m_xValueSet->SelectItem(nSelectedItem);
@ EditViewSelection
The selection in the center pane has changed.
@ MainViewRemoved
The current MainViewShell (the ViewShell displayed in the center pane) has been removed.
@ MainViewAdded
A new ViewShell has been made the MainViewShell.
@ CurrentPageChanged
The current page has changed.
SfxApplication * SfxGetpApp()
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
Size GetSizePixel() const
constexpr tools::Long Y() const
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false)
const rtl::Reference< sdr::SelectionController > & getSelectionController() const
virtual bool IsTextEdit() const final override
SdrModel & GetModel() const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void AppendItem(const SfxPoolItem &)
virtual SfxItemSet & GetItemSet()
static SfxUnoStyleSheet * getUnoStyleSheet(const css::uno::Reference< css::style::XStyle > &xStyle)
weld::Window * GetFrameWeld() const
css::uno::Reference< css::frame::XController > GetController() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
const Color & GetWindowColor() const
virtual VclPtr< SfxAbstractTabDialog > CreateSvxFormatCellsDialog(weld::Window *pParent, const SfxItemSet &rAttr, const SdrModel &rModel, bool bStyle)=0
static SvxAbstractDialogFactory * Create()
virtual SvxBoxItem * Clone(SfxItemPool *pPool=nullptr) const override
const Color & GetValue() const
int GetScrollWidth() const
size_t GetItemCount() const
void SetStyle(WinBits nStyle)
void SetLineCount(sal_uInt16 nNewLines=0)
void SetColCount(sal_uInt16 nNewCols=1)
virtual void Resize() override
sal_uInt16 GetItemId(size_t nPos) const
Image GetItemImage(sal_uInt16 nItemId) const
void SetExtraSpacing(sal_uInt16 nNewSpacing)
virtual void StyleUpdated() override
Link< const Point *, void > maContextMenuHandler
virtual void Resize() override
TableValueSet(std::unique_ptr< weld::ScrolledWindow > pScrolledWindow)
virtual bool Command(const CommandEvent &rEvent) override
static constexpr int getMaxRowCount()
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
std::shared_ptr< tools::EventMultiplexer > const & GetEventMultiplexer() const
Return an event multiplexer.
virtual SdrView * GetDrawView() const override
static SvxBoxItem TextDistancesToSvxBoxItem(const SfxItemSet &rAttrSet)
static void SvxBoxItemToTextDistances(const SvxBoxItem &pOriginalItem, SfxItemSet &rAttrSet)
virtual std::unique_ptr< CheckButton > weld_check_button(const OUString &id)=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
#define LINK(Instance, Class, Member)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
std::shared_ptr< T > make_shared(Args &&... args)
static void FillCellInfoMatrix(const CellInfoVector &rStyle, const TableStyleSettings &rSettings, CellInfoMatrix &rMatrix)
static SfxBindings * getBindings(ViewShellBase const &rBase)
const std::u16string_view gPropNames[CB_COUNT]
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
const sal_Int32 nPreviewColumns
static SfxDispatcher * getDispatcher(ViewShellBase const &rBase)
const sal_Int32 nCellHeight
std::vector< std::shared_ptr< CellInfo > > CellInfoVector
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
const sal_Int32 nBitmapHeight
std::shared_ptr< CellInfo > CellInfoMatrix[nPreviewColumns *nPreviewRows]
static BitmapEx CreateDesignPreview(const Reference< XIndexAccess > &xTableStyle, const TableStyleSettings &rSettings, bool bIsPageDark)
constexpr std::u16string_view aTableStyleBaseName
const sal_Int32 nCellWidth
const sal_Int32 nBitmapWidth
const sal_Int32 nPreviewRows
static void FillCellInfoVector(const Reference< XIndexAccess > &xTableStyle, CellInfoVector &rVector)
void CleanupFillProperties(SfxItemSet &rItemSet)
const sal_Int32 style_count
const sal_Int32 last_column_style
const sal_Int32 first_column_style
const sal_Int32 odd_columns_style
const sal_Int32 body_style
const sal_Int32 even_rows_style
const sal_Int32 first_row_style
const sal_Int32 last_row_style
const sal_Int32 even_columns_style
const sal_Int32 odd_rows_style
OUString SdResId(TranslateId aId)
uno::Reference< presentation::XSlideShowView > mxView
Reference< XController > xController
constexpr TypedWhichId< SvxBoxInfoItem > SDRATTR_TABLE_BORDER_INNER(SDRATTR_TABLE_FIRST+1)
constexpr TypedWhichId< SvxBoxItem > SDRATTR_TABLE_BORDER(SDRATTR_TABLE_FIRST+0)
SVXCORE_DLLPUBLIC bool GetDraftFillColor(const SfxItemSet &rSet, Color &rCol)
#define WB_NO_DIRECTSELECT