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 <com/sun/star/table/XTable.hpp>
25 #include <rtl/ref.hxx>
27 #include <svx/sdr/overlay/overlayobjectlist.hxx>
28 #include <svx/selectioncontroller.hxx>
29 #include <svx/svdotable.hxx>
30 #include <svx/svdview.hxx>
38 namespace sdr
{ namespace table
{
42 class SVX_DLLPUBLIC SvxTableController
: public sdr::SelectionController
45 SVX_DLLPRIVATE
SvxTableController( SdrObjEditView
* pView
, const SdrObject
* pObj
);
46 SVX_DLLPRIVATE
virtual ~SvxTableController();
48 // from sdr::SelectionController
49 SVX_DLLPRIVATE
virtual bool onKeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
) SAL_OVERRIDE
;
50 SVX_DLLPRIVATE
virtual bool onMouseButtonDown(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) SAL_OVERRIDE
;
51 SVX_DLLPRIVATE
virtual bool onMouseButtonUp(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) SAL_OVERRIDE
;
52 SVX_DLLPRIVATE
virtual bool onMouseMove(const MouseEvent
& rMEvt
, vcl::Window
* pWin
) SAL_OVERRIDE
;
54 SVX_DLLPRIVATE
virtual bool DeleteMarked() SAL_OVERRIDE
;
56 SVX_DLLPRIVATE
virtual void onSelectionHasChanged() SAL_OVERRIDE
;
58 SVX_DLLPRIVATE
virtual void GetState( SfxItemSet
& rSet
) SAL_OVERRIDE
;
59 SVX_DLLPRIVATE
virtual void Execute( SfxRequest
& rReq
) SAL_OVERRIDE
;
61 SVX_DLLPRIVATE
virtual bool GetStyleSheet( SfxStyleSheet
* &rpStyleSheet
) const SAL_OVERRIDE
;
62 SVX_DLLPRIVATE
virtual bool SetStyleSheet( SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
) SAL_OVERRIDE
;
64 SVX_DLLPRIVATE
virtual bool TakeFormatPaintBrush( std::shared_ptr
< SfxItemSet
>& rFormatSet
) SAL_OVERRIDE
;
65 SVX_DLLPRIVATE
virtual bool ApplyFormatPaintBrush( SfxItemSet
& rFormatSet
, bool bNoCharacterFormats
, bool bNoParagraphFormats
) SAL_OVERRIDE
;
68 SVX_DLLPRIVATE
void onInsert( sal_uInt16 nSId
, const SfxItemSet
* pArgs
= 0 );
69 SVX_DLLPRIVATE
void onDelete( sal_uInt16 nSId
);
70 SVX_DLLPRIVATE
void onSelect( sal_uInt16 nSId
);
71 SVX_DLLPRIVATE
void onFormatTable( SfxRequest
& rReq
);
72 SVX_DLLPRIVATE
void MergeMarkedCells();
73 SVX_DLLPRIVATE
void SplitMarkedCells();
74 SVX_DLLPRIVATE
void DistributeColumns();
75 SVX_DLLPRIVATE
void DistributeRows();
76 SVX_DLLPRIVATE
void SetVertical( sal_uInt16 nSId
);
78 SVX_DLLPRIVATE
static rtl::Reference
< sdr::SelectionController
> create( SdrObjEditView
* pView
, const SdrObject
* pObj
, const rtl::Reference
< sdr::SelectionController
>& xRefController
);
80 SVX_DLLPRIVATE
void MergeAttrFromSelectedCells(SfxItemSet
& rAttr
, bool bOnlyHardAttr
) const;
81 SVX_DLLPRIVATE
void SetAttrToSelectedCells(const SfxItemSet
& rAttr
, bool bReplaceAll
);
82 /** Fill the values that are common for all selected cells.
84 * This lets the Borders dialog to display the line arrangement
87 SVX_DLLPRIVATE
void FillCommonBorderAttrFromSelectedCells(SvxBoxItem
& rBox
, SvxBoxInfoItem
& rBoxInfo
) const;
89 SVX_DLLPRIVATE
virtual bool GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const SAL_OVERRIDE
;
90 SVX_DLLPRIVATE
virtual bool SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
) SAL_OVERRIDE
;
92 SVX_DLLPRIVATE
virtual bool GetMarkedObjModel( SdrPage
* pNewPage
) SAL_OVERRIDE
;
93 SVX_DLLPRIVATE
virtual bool PasteObjModel( const SdrModel
& rModel
) SAL_OVERRIDE
;
95 SVX_DLLPRIVATE
virtual bool hasSelectedCells() const SAL_OVERRIDE
{ return mbCellSelectionMode
|| mpView
->IsTextEdit(); }
96 /// @see sdr::SelectionController::setCursorLogicPosition().
97 SVX_DLLPRIVATE
virtual bool setCursorLogicPosition(const Point
& rPosition
, bool bPoint
) SAL_OVERRIDE
;
99 void getSelectedCells( CellPos
& rFirstPos
, CellPos
& rLastPos
);
100 void setSelectedCells( const CellPos
& rFirstPos
, const CellPos
& rLastPos
);
101 void clearSelection();
104 SVX_DLLPRIVATE
void onTableModified();
106 bool selectRow( sal_Int32 row
);
107 bool selectColumn( sal_Int32 column
);
108 bool deselectRow( sal_Int32 row
);
109 bool deselectColumn( sal_Int32 column
);
110 bool isRowSelected( sal_Int32 nRow
);
111 bool isColumnSelected( sal_Int32 nColumn
);
113 bool isColumnHeader();
114 sdr::table::SdrTableObj
* GetTableObj() { return dynamic_cast< sdr::table::SdrTableObj
* >( mxTableObj
.get() ); }
115 //declare event notification method
116 void NotifySelection( const CellPos
& firstPos
, const CellPos
& lastPos
, const CellPos
& newPos
);
118 SvxTableController(SvxTableController
&) SAL_DELETED_FUNCTION
;
119 void operator =(SvxTableController
&) SAL_DELETED_FUNCTION
;
122 SVX_DLLPRIVATE
void ApplyBorderAttr( const SfxItemSet
& rAttr
);
123 SVX_DLLPRIVATE
void UpdateTableShape();
125 SVX_DLLPRIVATE
void SetTableStyle( const SfxItemSet
* pArgs
);
126 SVX_DLLPRIVATE
void SetTableStyleSettings( const SfxItemSet
* pArgs
);
128 SVX_DLLPRIVATE
bool PasteObject( SdrTableObj
* pPasteTableObj
);
130 SVX_DLLPRIVATE
bool checkTableObject();
131 SVX_DLLPRIVATE
bool updateTableObject();
132 SVX_DLLPRIVATE
const CellPos
& getSelectionStart();
133 SVX_DLLPRIVATE
void setSelectionStart( const CellPos
& rPos
);
134 SVX_DLLPRIVATE
const CellPos
& getSelectionEnd();
135 SVX_DLLPRIVATE
void checkCell( CellPos
& rPos
);
137 SVX_DLLPRIVATE
void MergeRange( sal_Int32 nFirstCol
, sal_Int32 nFirstRow
, sal_Int32 nLastCol
, sal_Int32 nLastRow
);
139 SVX_DLLPRIVATE
void EditCell( const CellPos
& rPos
, vcl::Window
* pWindow
, const ::com::sun::star::awt::MouseEvent
* pMouseEvent
= 0, sal_uInt16 nAction
= 0 );
140 SVX_DLLPRIVATE
bool StopTextEdit();
142 SVX_DLLPRIVATE sal_uInt16
getKeyboardAction( const KeyEvent
& rKEvt
, vcl::Window
* pWindow
);
143 SVX_DLLPRIVATE
bool executeAction( sal_uInt16 nAction
, bool bSelect
, vcl::Window
* pWindow
);
144 SVX_DLLPRIVATE
void gotoCell( const CellPos
& rCell
, bool bSelect
, vcl::Window
* pWindow
, sal_uInt16 nAction
= 0 );
146 SVX_DLLPRIVATE
void StartSelection( const CellPos
& rPos
);
147 SVX_DLLPRIVATE
void UpdateSelection( const CellPos
& rPos
);
148 SVX_DLLPRIVATE
void RemoveSelection();
149 SVX_DLLPRIVATE
void updateSelectionOverlay();
150 SVX_DLLPRIVATE
void destroySelectionOverlay();
152 SVX_DLLPRIVATE
void findMergeOrigin( CellPos
& rPos
);
154 DECL_LINK( UpdateHdl
, void * );
156 //TableModelRef mxTable;
157 rtl::Reference
< TableModel
> mxTable
;
159 CellPos maCursorFirstPos
;
160 CellPos maCursorLastPos
;
161 bool mbCellSelectionMode
;
162 CellPos maMouseDownPos
;
163 bool mbLeftButtonDown
;
164 sdr::overlay::OverlayObjectList
* mpSelectionOverlay
;
167 SdrObjectWeakRef mxTableObj
;
170 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
> mxModifyListener
;
172 ImplSVEvent
* mnUpdateEvent
;
175 rtl::Reference
< sdr::SelectionController
> CreateTableController( SdrObjEditView
* pView
, const SdrObject
* pObj
, const rtl::Reference
< sdr::SelectionController
>& xRefController
);
179 #endif // INCLUDED_SVX_SDR_TABLE_TABLECONTROLLER_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */