Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/svx/sdr/table/tablecontroller.hxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#ifndef INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
21
#define INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
22
23
#include <com/sun/star/util/XModifyListener.hpp>
24
#include <rtl/ref.hxx>
25
26
#include <svx/sdr/overlay/overlayobjectlist.hxx>
27
#include <svx/selectioncontroller.hxx>
28
#include <svx/svdotable.hxx>
29
#include <svx/svdview.hxx>
30
#include <optional>
31
#include <unotools/weakref.hxx>
32
33
struct ImplSVEvent;
34
class SfxItemSet;
35
class SvxBoxInfoItem;
36
class SvxBoxItem;
37
38
namespace sdr::table {
39
40
class SvxTableControllerModifyListener;
41
class TableModel;
42
43
class SVXCORE_DLLPUBLIC SvxTableController final : public sdr::SelectionController
44
{
45
public:
46
    SVX_DLLPRIVATE SvxTableController(
47
        SdrView& rView,
48
        const SdrTableObj& rObj);
49
    SVX_DLLPRIVATE virtual ~SvxTableController() override;
50
51
    // from sdr::SelectionController
52
    SVX_DLLPRIVATE virtual bool onKeyInput(const KeyEvent& rKEvt, vcl::Window* pWin) override;
53
    SVX_DLLPRIVATE virtual bool onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* pWin) override;
54
    SVX_DLLPRIVATE virtual bool onMouseButtonUp(const MouseEvent& rMEvt, vcl::Window* pWin) override;
55
    SVX_DLLPRIVATE virtual bool onMouseMove(const MouseEvent& rMEvt, vcl::Window* pWin) override;
56
57
    SVX_DLLPRIVATE bool HasMarked() const;
58
    SVX_DLLPRIVATE virtual bool DeleteMarked() override;
59
60
    SVX_DLLPRIVATE virtual void onSelectionHasChanged() override;
61
    SVX_DLLPRIVATE virtual void onSelectAll() override;
62
63
    SVX_DLLPRIVATE virtual void GetState( SfxItemSet& rSet ) override;
64
    virtual void Execute( SfxRequest& rReq ) override;
65
66
    SVX_DLLPRIVATE virtual bool GetStyleSheet( SfxStyleSheet* &rpStyleSheet ) const override;
67
    SVX_DLLPRIVATE virtual bool SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr ) override;
68
69
    SVX_DLLPRIVATE virtual bool ApplyFormatPaintBrush( SfxItemSet& rFormatSet, sal_Int16 nDepth, bool bNoCharacterFormats, bool bNoParagraphFormats ) override;
70
71
    // slots
72
    SVX_DLLPRIVATE void onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs = nullptr );
73
    SVX_DLLPRIVATE void onDelete( sal_uInt16 nSId );
74
    SVX_DLLPRIVATE void onSelect( sal_uInt16 nSId );
75
    SVX_DLLPRIVATE void onFormatTable(const SfxRequest& rReq);
76
    SVX_DLLPRIVATE void MergeMarkedCells();
77
    SVX_DLLPRIVATE void SplitMarkedCells(const SfxRequest& rReq);
78
    SVX_DLLPRIVATE void DistributeColumns( const bool bOptimize, const bool bMinimize );
79
    SVX_DLLPRIVATE void DistributeRows( const bool bOptimize, const bool bMinimize );
80
    SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );
81
    SVX_DLLPRIVATE void changeTableEdge(const SfxRequest& rReq);
82
83
    SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create(
84
        SdrView& rView,
85
        const SdrTableObj& rObj,
86
        const rtl::Reference< sdr::SelectionController >& xRefController);
87
88
    static SvxBoxItem TextDistancesToSvxBoxItem(const SfxItemSet& rAttrSet);
89
    static void SvxBoxItemToTextDistances(const SvxBoxItem& pOriginalItem, SfxItemSet& rAttrSet);
90
91
    SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
92
    SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
93
    void SetAttrToSelectedShape(const SfxItemSet& rAttr);
94
    /** Fill the values that are common for all selected cells.
95
      *
96
      * This lets the Borders dialog to display the line arrangement
97
      * properly.
98
      */
99
    SVX_DLLPRIVATE void FillCommonBorderAttrFromSelectedCells(SvxBoxItem& rBox, SvxBoxInfoItem& rBoxInfo) const;
100
101
    SVX_DLLPRIVATE virtual bool GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const override;
102
    SVX_DLLPRIVATE virtual bool SetAttributes(const SfxItemSet& rSet, bool bReplaceAll) override;
103
104
    SVX_DLLPRIVATE virtual rtl::Reference<SdrObject> GetMarkedSdrObjClone( SdrModel& rTargetModel ) override;
105
    SVX_DLLPRIVATE virtual bool PasteObjModel( const SdrModel& rModel ) override;
106
107
0
    SVX_DLLPRIVATE virtual bool hasSelectedCells() const override { return mbCellSelectionMode || mrView.IsTextEdit(); }
108
    /// @see sdr::SelectionController::setCursorLogicPosition().
109
    SVX_DLLPRIVATE virtual bool setCursorLogicPosition(const Point& rPosition, bool bPoint) override;
110
111
    /// @see sdr::SelectionController::getSelectedCells().
112
    void getSelectedCells( CellPos& rFirstPos, CellPos& rLastPos ) override;
113
    void setSelectedCells( const CellPos& rFirstPos, const CellPos& rLastPos );
114
115
    virtual bool ChangeFontSize(bool bGrow, const FontList* pFontList) override;
116
117
    void clearSelection();
118
    void selectAll();
119
120
    SVX_DLLPRIVATE void onTableModified();
121
122
    bool selectRow( sal_Int32 row );
123
    bool selectColumn( sal_Int32 column );
124
    bool deselectRow( sal_Int32 row );
125
    bool deselectColumn( sal_Int32 column );
126
    bool isRowSelected( sal_Int32 nRow );
127
    bool isColumnSelected( sal_Int32 nColumn );
128
    bool isRowHeader();
129
    bool isColumnHeader();
130
0
    sdr::table::SdrTableObj* GetTableObj() { return mxTableObj.get().get(); }
131
private:
132
    SvxTableController(SvxTableController const &) = delete;
133
    SvxTableController& operator =(SvxTableController const &) = delete;
134
135
    // internals
136
    enum class TblAction
137
    {
138
        NONE,
139
        GotoFirstCell, GotoFirstColumn, GotoFirstRow,
140
        GotoLeftCell, GotoUpCell, GotoRightCell, GotoDownCell,
141
        GotoLastCell, GotoLastColumn, GotoLastRow,
142
        EditCell, StopTextEdit,
143
        RemoveSelection,
144
        HandledByView, Tab
145
    };
146
    SVX_DLLPRIVATE void ApplyBorderAttr( const SfxItemSet& rAttr );
147
    SVX_DLLPRIVATE void UpdateTableShape();
148
149
    SVX_DLLPRIVATE void SetTableStyle( const SfxItemSet* pArgs );
150
    SVX_DLLPRIVATE void SetTableStyleSettings( const SfxItemSet* pArgs );
151
152
    SVX_DLLPRIVATE bool PasteObject( SdrTableObj const * pPasteTableObj );
153
154
    SVX_DLLPRIVATE bool checkTableObject();
155
    SVX_DLLPRIVATE const CellPos& getSelectionStart();
156
    SVX_DLLPRIVATE void setSelectionStart( const CellPos& rPos );
157
    SVX_DLLPRIVATE const CellPos& getSelectionEnd();
158
    SVX_DLLPRIVATE void checkCell( CellPos& rPos ) const;
159
160
    SVX_DLLPRIVATE void MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow );
161
162
    SVX_DLLPRIVATE void EditCell(const CellPos& rPos, vcl::Window* pWindow, TblAction nAction);
163
    SVX_DLLPRIVATE void StopTextEdit();
164
165
    SVX_DLLPRIVATE TblAction getKeyboardAction(const KeyEvent& rKEvt);
166
    SVX_DLLPRIVATE bool executeAction(TblAction nAction, bool bSelect, vcl::Window* pWindow);
167
    SVX_DLLPRIVATE void gotoCell(const CellPos& rCell, bool bSelect, vcl::Window* pWindow, TblAction nAction = TblAction::NONE);
168
169
    SVX_DLLPRIVATE void StartSelection( const CellPos& rPos );
170
    SVX_DLLPRIVATE void UpdateSelection( const CellPos& rPos );
171
    SVX_DLLPRIVATE void RemoveSelection();
172
    SVX_DLLPRIVATE void updateSelectionOverlay();
173
    SVX_DLLPRIVATE void destroySelectionOverlay();
174
175
    SVX_DLLPRIVATE void findMergeOrigin( CellPos& rPos );
176
177
    DECL_DLLPRIVATE_LINK( UpdateHdl, void *, void );
178
179
    //TableModelRef mxTable;
180
    rtl::Reference< TableModel > mxTable;
181
182
    CellPos maCursorFirstPos;
183
    CellPos maCursorLastPos;
184
    bool mbCellSelectionMode;
185
    bool mbHasJustMerged;
186
    CellPos maMouseDownPos;
187
    bool mbLeftButtonDown;
188
    std::optional<sdr::overlay::OverlayObjectList>  mpSelectionOverlay;
189
    SdrView& mrView;
190
    unotools::WeakReference<SdrTableObj> mxTableObj;
191
    rtl::Reference< SvxTableControllerModifyListener > mxModifyListener;
192
    ImplSVEvent * mnUpdateEvent;
193
};
194
195
rtl::Reference< sdr::SelectionController > CreateTableController(
196
     SdrView& rView,
197
     const SdrTableObj& rObj,
198
     const rtl::Reference< sdr::SelectionController >& xRefController );
199
200
}
201
202
#endif // INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
203
204
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */