tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / table / tableobjectbar.cxx
blob9f460238b0424acf8661670d16881d02a69d3190
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <sfx2/bindings.hxx>
21 #include <sfx2/msg.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/objface.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <sfx2/msgpool.hxx>
26 #include <vcl/EnumContext.hxx>
27 #include <svl/intitem.hxx>
28 #include <svx/svxdlg.hxx>
29 #include <svx/svxids.hrc>
31 #include <createtableobjectbar.hxx>
32 #include <registerinterfaces.hxx>
34 #include <strings.hrc>
35 #include <DrawDocShell.hxx>
36 #include <ViewShell.hxx>
37 #include <sdmod.hxx>
38 #include <sdresid.hxx>
39 #include <DrawViewShell.hxx>
41 #include "tableobjectbar.hxx"
43 using namespace sd;
44 using namespace sd::ui::table;
46 #define ShellClass_TableObjectBar
47 #include <sdslots.hxx>
49 namespace sd::ui::table {
51 /** creates a table object bar for the given ViewShell */
52 SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView )
54 return new TableObjectBar( &rShell, pView );
57 /** registers the interfaces from the table ui */
58 void RegisterInterfaces(const SfxModule* pMod)
60 TableObjectBar::RegisterInterface(pMod);
64 SFX_IMPL_INTERFACE(TableObjectBar, SfxShell)
66 void TableObjectBar::InitInterface_Impl()
70 TableObjectBar::TableObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView )
71 : SfxShell( pSdViewShell->GetViewShell() )
72 , mpView( pSdView )
73 , mpViewSh( pSdViewShell )
75 DrawDocShell* pDocShell = mpViewSh->GetDocSh();
76 if( pDocShell )
78 SetPool( &pDocShell->GetPool() );
79 SetUndoManager( pDocShell->GetUndoManager() );
81 SetRepeatTarget( mpView );
82 SetName( SdResId( RID_DRAW_TABLE_TOOLBOX ) );
83 SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Table));
86 TableObjectBar::~TableObjectBar()
88 SetRepeatTarget( nullptr );
91 void TableObjectBar::GetState( SfxItemSet& rSet )
93 if( mpView )
95 rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
96 if( xController.is() )
98 xController->GetState( rSet );
103 void TableObjectBar::GetAttrState( SfxItemSet& rSet )
105 DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpViewSh );
106 if( pDrawViewShell )
107 pDrawViewShell->GetAttrState( rSet );
110 void TableObjectBar::Execute( SfxRequest& rReq )
112 if( !mpView )
113 return;
115 SdrView* pView = mpView;
116 SfxBindings* pBindings = &mpViewSh->GetViewFrame()->GetBindings();
118 rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
119 sal_uInt16 nSlotId = rReq.GetSlot();
120 if( xController.is() )
122 switch( nSlotId )
124 case SID_TABLE_INSERT_ROW_DLG:
125 case SID_TABLE_INSERT_COL_DLG:
127 auto xRequest = std::make_shared<SfxRequest>(rReq);
128 rReq.Ignore(); // the 'old' request is not relevant any more
129 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
130 vcl::Window* pWin = mpView->GetViewShell()->GetParentWindow();
131 VclPtr<SvxAbstractInsRowColDlg> pDlg( pFact->CreateSvxInsRowColDlg(pWin ? pWin->GetFrameWeld() : nullptr,
132 nSlotId == SID_TABLE_INSERT_COL_DLG,
133 SdModule::get()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) );
134 pDlg->StartExecuteAsync(
135 [pDlg, xRequest=std::move(xRequest), nSlotId, xController, pBindings] (sal_Int32 nResult) mutable ->void
137 if (nResult == RET_OK)
139 sal_uInt16 nCount = pDlg->getInsertCount();
140 bool bInsertAfter = !pDlg->isInsertBefore();
142 if (nSlotId == SID_TABLE_INSERT_ROW_DLG)
143 nSlotId = SID_TABLE_INSERT_ROW;
144 else
145 nSlotId = SID_TABLE_INSERT_COL;
147 xRequest->AppendItem(SfxInt16Item(nSlotId, nCount));
148 xRequest->AppendItem(SfxBoolItem(SID_TABLE_PARAM_INSERT_AFTER, bInsertAfter));
150 xRequest->SetSlot( nSlotId );
152 pDlg->disposeOnce();
153 xController->Execute( *xRequest );
154 pBindings->Invalidate( SID_UNDO );
155 pBindings->Invalidate( SID_REDO );
158 return;
160 case SID_TABLE_INSERT_ROW_BEFORE:
161 case SID_TABLE_INSERT_ROW_AFTER:
162 case SID_TABLE_INSERT_COL_BEFORE:
163 case SID_TABLE_INSERT_COL_AFTER:
165 sal_uInt16 nCount = 1;
166 bool bInsertAfter = (nSlotId == SID_TABLE_INSERT_ROW_AFTER) || (nSlotId == SID_TABLE_INSERT_COL_AFTER);
168 if ( nSlotId == SID_TABLE_INSERT_ROW_BEFORE || nSlotId == SID_TABLE_INSERT_ROW_AFTER)
169 nSlotId = SID_TABLE_INSERT_ROW;
170 else
171 nSlotId = SID_TABLE_INSERT_COL;
173 rReq.AppendItem(SfxInt16Item(nSlotId, nCount));
174 rReq.AppendItem(SfxBoolItem(SID_TABLE_PARAM_INSERT_AFTER, bInsertAfter));
176 rReq.SetSlot( nSlotId );
180 xController->Execute( rReq );
183 // note: we may be deleted at this point, no more member access possible
185 switch( rReq.GetSlot() )
187 case SID_ATTR_BORDER:
188 case SID_TABLE_MERGE_CELLS:
189 case SID_TABLE_SPLIT_CELLS:
190 case SID_OPTIMIZE_TABLE:
191 case SID_TABLE_DELETE_ROW:
192 case SID_TABLE_DELETE_COL:
193 case SID_TABLE_DELETE_TABLE:
194 case SID_FORMAT_TABLE_DLG:
195 case SID_TABLE_INSERT_ROW:
196 case SID_TABLE_INSERT_COL:
198 pView->AdjustMarkHdl();
199 pBindings->Invalidate( SID_TABLE_DELETE_ROW );
200 pBindings->Invalidate( SID_TABLE_DELETE_COL );
201 pBindings->Invalidate( SID_TABLE_DELETE_TABLE );
202 pBindings->Invalidate( SID_FRAME_LINESTYLE );
203 pBindings->Invalidate( SID_FRAME_LINECOLOR );
204 pBindings->Invalidate( SID_ATTR_BORDER );
205 pBindings->Invalidate( SID_ATTR_FILL_STYLE );
206 pBindings->Invalidate( SID_ATTR_FILL_USE_SLIDE_BACKGROUND );
207 pBindings->Invalidate( SID_ATTR_FILL_TRANSPARENCE );
208 pBindings->Invalidate( SID_ATTR_FILL_FLOATTRANSPARENCE );
209 pBindings->Invalidate( SID_TABLE_MERGE_CELLS );
210 pBindings->Invalidate( SID_TABLE_SPLIT_CELLS );
211 pBindings->Invalidate( SID_OPTIMIZE_TABLE );
212 pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
213 pBindings->Invalidate( SID_TABLE_VERT_CENTER );
214 pBindings->Invalidate( SID_TABLE_VERT_NONE );
215 break;
217 case SID_TABLE_VERT_BOTTOM:
218 case SID_TABLE_VERT_CENTER:
219 case SID_TABLE_VERT_NONE:
221 pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
222 pBindings->Invalidate( SID_TABLE_VERT_CENTER );
223 pBindings->Invalidate( SID_TABLE_VERT_NONE );
224 break;
228 pBindings->Invalidate( SID_UNDO );
229 pBindings->Invalidate( SID_REDO );
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */