1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
21 #define INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
23 #include <com/sun/star/util/XModifyListener.hpp>
24 #include <rtl/ref.hxx>
26 #include <svx/sdr/overlay/overlayobjectlist.hxx>
27 #include <svx/selectioncontroller.hxx>
28 #include <svx/svdotable.hxx>
29 #include <svx/svdview.hxx>
38 namespace sdr::table
{
42 class SVXCORE_DLLPUBLIC SvxTableController final
: public sdr::SelectionController
45 SVX_DLLPRIVATE
SvxTableController(
47 const SdrTableObj
& rObj
);
48 SVX_DLLPRIVATE
virtual ~SvxTableController() override
;
50 // from sdr::SelectionController
51 SVX_DLLPRIVATE
virtual bool onKeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
) override
;
52 SVX_DLLPRIVATE
virtual bool onMouseButtonDown(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) override
;
53 SVX_DLLPRIVATE
virtual bool onMouseButtonUp(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) override
;
54 SVX_DLLPRIVATE
virtual bool onMouseMove(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) override
;
56 SVX_DLLPRIVATE
bool HasMarked() const;
57 SVX_DLLPRIVATE
virtual bool DeleteMarked() override
;
59 SVX_DLLPRIVATE
virtual void onSelectionHasChanged() override
;
61 SVX_DLLPRIVATE
virtual void GetState( SfxItemSet
& rSet
) override
;
62 virtual void Execute( SfxRequest
& rReq
) override
;
64 SVX_DLLPRIVATE
virtual bool GetStyleSheet( SfxStyleSheet
* &rpStyleSheet
) const override
;
65 SVX_DLLPRIVATE
virtual bool SetStyleSheet( SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
) override
;
67 SVX_DLLPRIVATE
virtual bool ApplyFormatPaintBrush( SfxItemSet
& rFormatSet
, bool bNoCharacterFormats
, bool bNoParagraphFormats
) override
;
70 SVX_DLLPRIVATE
void onInsert( sal_uInt16 nSId
, const SfxItemSet
* pArgs
= nullptr );
71 SVX_DLLPRIVATE
void onDelete( sal_uInt16 nSId
);
72 SVX_DLLPRIVATE
void onSelect( sal_uInt16 nSId
);
73 SVX_DLLPRIVATE
void onFormatTable(const SfxRequest
& rReq
);
74 SVX_DLLPRIVATE
void MergeMarkedCells();
75 SVX_DLLPRIVATE
void SplitMarkedCells(const SfxRequest
& rReq
);
76 SVX_DLLPRIVATE
void DistributeColumns( const bool bOptimize
, const bool bMinimize
);
77 SVX_DLLPRIVATE
void DistributeRows( const bool bOptimize
, const bool bMinimize
);
78 SVX_DLLPRIVATE
void SetVertical( sal_uInt16 nSId
);
79 SVX_DLLPRIVATE
void changeTableEdge(const SfxRequest
& rReq
);
81 SVX_DLLPRIVATE
static rtl::Reference
< sdr::SelectionController
> create(
83 const SdrTableObj
& rObj
,
84 const rtl::Reference
< sdr::SelectionController
>& xRefController
);
86 SVX_DLLPRIVATE
void MergeAttrFromSelectedCells(SfxItemSet
& rAttr
, bool bOnlyHardAttr
) const;
87 SVX_DLLPRIVATE
void SetAttrToSelectedCells(const SfxItemSet
& rAttr
, bool bReplaceAll
);
88 void SetAttrToSelectedShape(const SfxItemSet
& rAttr
);
89 /** Fill the values that are common for all selected cells.
91 * This lets the Borders dialog to display the line arrangement
94 SVX_DLLPRIVATE
void FillCommonBorderAttrFromSelectedCells(SvxBoxItem
& rBox
, SvxBoxInfoItem
& rBoxInfo
) const;
96 SVX_DLLPRIVATE
virtual bool GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const override
;
97 SVX_DLLPRIVATE
virtual bool SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
) override
;
99 SVX_DLLPRIVATE
virtual SdrObject
* GetMarkedSdrObjClone( SdrModel
& rTargetModel
) override
;
100 SVX_DLLPRIVATE
virtual bool PasteObjModel( const SdrModel
& rModel
) override
;
102 SVX_DLLPRIVATE
virtual bool hasSelectedCells() const override
{ return mbCellSelectionMode
|| mrView
.IsTextEdit(); }
103 /// @see sdr::SelectionController::setCursorLogicPosition().
104 SVX_DLLPRIVATE
virtual bool setCursorLogicPosition(const Point
& rPosition
, bool bPoint
) override
;
106 /// @see sdr::SelectionController::getSelectedCells().
107 void getSelectedCells( CellPos
& rFirstPos
, CellPos
& rLastPos
) override
;
108 void setSelectedCells( const CellPos
& rFirstPos
, const CellPos
& rLastPos
);
110 virtual bool ChangeFontSize(bool bGrow
, const FontList
* pFontList
) override
;
112 void clearSelection();
115 SVX_DLLPRIVATE
void onTableModified();
117 bool selectRow( sal_Int32 row
);
118 bool selectColumn( sal_Int32 column
);
119 bool deselectRow( sal_Int32 row
);
120 bool deselectColumn( sal_Int32 column
);
121 bool isRowSelected( sal_Int32 nRow
);
122 bool isColumnSelected( sal_Int32 nColumn
);
124 bool isColumnHeader();
125 sdr::table::SdrTableObj
* GetTableObj() { return mxTableObj
.get(); }
127 SvxTableController(SvxTableController
const &) = delete;
128 SvxTableController
& operator =(SvxTableController
const &) = delete;
134 GotoFirstCell
, GotoFirstColumn
, GotoFirstRow
,
135 GotoLeftCell
, GotoUpCell
, GotoRightCell
, GotoDownCell
,
136 GotoLastCell
, GotoLastColumn
, GotoLastRow
,
137 EditCell
, StopTextEdit
,
141 SVX_DLLPRIVATE
void ApplyBorderAttr( const SfxItemSet
& rAttr
);
142 SVX_DLLPRIVATE
void UpdateTableShape();
144 SVX_DLLPRIVATE
void SetTableStyle( const SfxItemSet
* pArgs
);
145 SVX_DLLPRIVATE
void SetTableStyleSettings( const SfxItemSet
* pArgs
);
147 SVX_DLLPRIVATE
bool PasteObject( SdrTableObj
const * pPasteTableObj
);
149 SVX_DLLPRIVATE
bool checkTableObject();
150 SVX_DLLPRIVATE
const CellPos
& getSelectionStart();
151 SVX_DLLPRIVATE
void setSelectionStart( const CellPos
& rPos
);
152 SVX_DLLPRIVATE
const CellPos
& getSelectionEnd();
153 SVX_DLLPRIVATE
void checkCell( CellPos
& rPos
);
155 SVX_DLLPRIVATE
void MergeRange( sal_Int32 nFirstCol
, sal_Int32 nFirstRow
, sal_Int32 nLastCol
, sal_Int32 nLastRow
);
157 SVX_DLLPRIVATE
void EditCell(const CellPos
& rPos
, vcl::Window
* pWindow
, TblAction nAction
);
158 SVX_DLLPRIVATE
void StopTextEdit();
160 SVX_DLLPRIVATE TblAction
getKeyboardAction(const KeyEvent
& rKEvt
);
161 SVX_DLLPRIVATE
bool executeAction(TblAction nAction
, bool bSelect
, vcl::Window
* pWindow
);
162 SVX_DLLPRIVATE
void gotoCell(const CellPos
& rCell
, bool bSelect
, vcl::Window
* pWindow
, TblAction nAction
= TblAction::NONE
);
164 SVX_DLLPRIVATE
void StartSelection( const CellPos
& rPos
);
165 SVX_DLLPRIVATE
void UpdateSelection( const CellPos
& rPos
);
166 SVX_DLLPRIVATE
void RemoveSelection();
167 SVX_DLLPRIVATE
void updateSelectionOverlay();
168 SVX_DLLPRIVATE
void destroySelectionOverlay();
170 SVX_DLLPRIVATE
void findMergeOrigin( CellPos
& rPos
);
172 DECL_LINK( UpdateHdl
, void *, void );
174 //TableModelRef mxTable;
175 rtl::Reference
< TableModel
> mxTable
;
177 CellPos maCursorFirstPos
;
178 CellPos maCursorLastPos
;
179 bool mbCellSelectionMode
;
180 bool mbHasJustMerged
;
181 CellPos maMouseDownPos
;
182 bool mbLeftButtonDown
;
183 std::unique_ptr
<sdr::overlay::OverlayObjectList
> mpSelectionOverlay
;
185 tools::WeakReference
<SdrTableObj
> mxTableObj
;
186 css::uno::Reference
< css::util::XModifyListener
> mxModifyListener
;
187 ImplSVEvent
* mnUpdateEvent
;
190 rtl::Reference
< sdr::SelectionController
> CreateTableController(
192 const SdrTableObj
& rObj
,
193 const rtl::Reference
< sdr::SelectionController
>& xRefController
);
197 #endif // INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */