/src/libreoffice/sd/source/ui/table/tableobjectbar.cxx
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 | | #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> |
30 | | |
31 | | #include <createtableobjectbar.hxx> |
32 | | #include <registerinterfaces.hxx> |
33 | | |
34 | | #include <strings.hrc> |
35 | | #include <DrawDocShell.hxx> |
36 | | #include <ViewShell.hxx> |
37 | | #include <sdmod.hxx> |
38 | | #include <sdresid.hxx> |
39 | | #include <DrawViewShell.hxx> |
40 | | |
41 | | #include "tableobjectbar.hxx" |
42 | | |
43 | | using namespace sd; |
44 | | using namespace sd::ui::table; |
45 | | |
46 | | #define ShellClass_TableObjectBar |
47 | | #include <sdslots.hxx> |
48 | | |
49 | | namespace sd::ui::table { |
50 | | |
51 | | /** creates a table object bar for the given ViewShell */ |
52 | | SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView ) |
53 | 0 | { |
54 | 0 | return new TableObjectBar( rShell, pView ); |
55 | 0 | } |
56 | | |
57 | | /** registers the interfaces from the table ui */ |
58 | | void RegisterInterfaces(const SfxModule* pMod) |
59 | 5 | { |
60 | 5 | TableObjectBar::RegisterInterface(pMod); |
61 | 5 | } |
62 | | |
63 | | |
64 | | SFX_IMPL_INTERFACE(TableObjectBar, SfxShell) |
65 | | |
66 | | void TableObjectBar::InitInterface_Impl() |
67 | 5 | { |
68 | 5 | } |
69 | | |
70 | | TableObjectBar::TableObjectBar( ViewShell& rSdViewShell, ::sd::View* pSdView ) |
71 | 0 | : SfxShell( rSdViewShell.GetViewShell() ) |
72 | 0 | , mpView( pSdView ) |
73 | 0 | , mrViewSh( rSdViewShell ) |
74 | 0 | { |
75 | 0 | DrawDocShell* pDocShell = mrViewSh.GetDocSh(); |
76 | 0 | if( pDocShell ) |
77 | 0 | { |
78 | 0 | SetPool( &pDocShell->GetPool() ); |
79 | 0 | SetUndoManager( pDocShell->GetUndoManager() ); |
80 | 0 | } |
81 | 0 | SetRepeatTarget( mpView ); |
82 | 0 | SetName( SdResId( RID_DRAW_TABLE_TOOLBOX ) ); |
83 | 0 | SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Table)); |
84 | 0 | } |
85 | | |
86 | | TableObjectBar::~TableObjectBar() |
87 | 0 | { |
88 | 0 | SetRepeatTarget( nullptr ); |
89 | 0 | } |
90 | | |
91 | | void TableObjectBar::GetState( SfxItemSet& rSet ) |
92 | 0 | { |
93 | 0 | if( mpView ) |
94 | 0 | { |
95 | 0 | rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() ); |
96 | 0 | if( xController.is() ) |
97 | 0 | { |
98 | 0 | xController->GetState( rSet ); |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | | void TableObjectBar::GetAttrState( SfxItemSet& rSet ) |
104 | 0 | { |
105 | 0 | DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( &mrViewSh ); |
106 | 0 | if( pDrawViewShell ) |
107 | 0 | pDrawViewShell->GetAttrState( rSet ); |
108 | 0 | } |
109 | | |
110 | | void TableObjectBar::Execute( SfxRequest& rReq ) |
111 | 0 | { |
112 | 0 | if( !mpView ) |
113 | 0 | return; |
114 | | |
115 | 0 | SdrView* pView = mpView; |
116 | 0 | SfxBindings* pBindings = &mrViewSh.GetViewFrame()->GetBindings(); |
117 | |
|
118 | 0 | rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() ); |
119 | 0 | sal_uInt16 nSlotId = rReq.GetSlot(); |
120 | 0 | if( xController.is() ) |
121 | 0 | { |
122 | 0 | switch( nSlotId ) |
123 | 0 | { |
124 | 0 | case SID_TABLE_INSERT_ROW_DLG: |
125 | 0 | case SID_TABLE_INSERT_COL_DLG: |
126 | 0 | { |
127 | 0 | auto xRequest = std::make_shared<SfxRequest>(rReq); |
128 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
129 | 0 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); |
130 | 0 | vcl::Window* pWin = mpView->GetViewShell()->GetParentWindow(); |
131 | 0 | VclPtr<SvxAbstractInsRowColDlg> pDlg( pFact->CreateSvxInsRowColDlg(pWin ? pWin->GetFrameWeld() : nullptr, |
132 | 0 | nSlotId == SID_TABLE_INSERT_COL_DLG, |
133 | 0 | SdModule::get()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) ); |
134 | 0 | pDlg->StartExecuteAsync( |
135 | 0 | [pDlg, xRequest=std::move(xRequest), nSlotId, xController, pBindings] (sal_Int32 nResult) mutable ->void |
136 | 0 | { |
137 | 0 | if (nResult == RET_OK) |
138 | 0 | { |
139 | 0 | sal_uInt16 nCount = pDlg->getInsertCount(); |
140 | 0 | bool bInsertAfter = !pDlg->isInsertBefore(); |
141 | |
|
142 | 0 | if (nSlotId == SID_TABLE_INSERT_ROW_DLG) |
143 | 0 | nSlotId = SID_TABLE_INSERT_ROW; |
144 | 0 | else |
145 | 0 | nSlotId = SID_TABLE_INSERT_COL; |
146 | |
|
147 | 0 | xRequest->AppendItem(SfxInt16Item(nSlotId, nCount)); |
148 | 0 | xRequest->AppendItem(SfxBoolItem(SID_TABLE_PARAM_INSERT_AFTER, bInsertAfter)); |
149 | |
|
150 | 0 | xRequest->SetSlot( nSlotId ); |
151 | 0 | } |
152 | 0 | pDlg->disposeOnce(); |
153 | 0 | xController->Execute( *xRequest ); |
154 | 0 | pBindings->Invalidate( SID_UNDO ); |
155 | 0 | pBindings->Invalidate( SID_REDO ); |
156 | 0 | } |
157 | 0 | ); |
158 | 0 | return; |
159 | 0 | } |
160 | 0 | case SID_TABLE_INSERT_ROW_BEFORE: |
161 | 0 | case SID_TABLE_INSERT_ROW_AFTER: |
162 | 0 | case SID_TABLE_INSERT_COL_BEFORE: |
163 | 0 | case SID_TABLE_INSERT_COL_AFTER: |
164 | 0 | { |
165 | 0 | sal_uInt16 nCount = 1; |
166 | 0 | bool bInsertAfter = (nSlotId == SID_TABLE_INSERT_ROW_AFTER) || (nSlotId == SID_TABLE_INSERT_COL_AFTER); |
167 | |
|
168 | 0 | if ( nSlotId == SID_TABLE_INSERT_ROW_BEFORE || nSlotId == SID_TABLE_INSERT_ROW_AFTER) |
169 | 0 | nSlotId = SID_TABLE_INSERT_ROW; |
170 | 0 | else |
171 | 0 | nSlotId = SID_TABLE_INSERT_COL; |
172 | |
|
173 | 0 | rReq.AppendItem(SfxInt16Item(nSlotId, nCount)); |
174 | 0 | rReq.AppendItem(SfxBoolItem(SID_TABLE_PARAM_INSERT_AFTER, bInsertAfter)); |
175 | |
|
176 | 0 | rReq.SetSlot( nSlotId ); |
177 | 0 | } |
178 | 0 | } |
179 | | |
180 | 0 | xController->Execute( rReq ); |
181 | 0 | } |
182 | | |
183 | | // note: we may be deleted at this point, no more member access possible |
184 | | |
185 | 0 | switch( rReq.GetSlot() ) |
186 | 0 | { |
187 | 0 | case SID_ATTR_BORDER: |
188 | 0 | case SID_TABLE_MERGE_CELLS: |
189 | 0 | case SID_TABLE_SPLIT_CELLS: |
190 | 0 | case SID_OPTIMIZE_TABLE: |
191 | 0 | case SID_TABLE_DELETE_ROW: |
192 | 0 | case SID_TABLE_DELETE_COL: |
193 | 0 | case SID_TABLE_DELETE_TABLE: |
194 | 0 | case SID_FORMAT_TABLE_DLG: |
195 | 0 | case SID_TABLE_INSERT_ROW: |
196 | 0 | case SID_TABLE_INSERT_COL: |
197 | 0 | { |
198 | 0 | pView->AdjustMarkHdl(); |
199 | 0 | pBindings->Invalidate( SID_TABLE_DELETE_ROW ); |
200 | 0 | pBindings->Invalidate( SID_TABLE_DELETE_COL ); |
201 | 0 | pBindings->Invalidate( SID_TABLE_DELETE_TABLE ); |
202 | 0 | pBindings->Invalidate( SID_FRAME_LINESTYLE ); |
203 | 0 | pBindings->Invalidate( SID_FRAME_LINECOLOR ); |
204 | 0 | pBindings->Invalidate( SID_ATTR_BORDER ); |
205 | 0 | pBindings->Invalidate( SID_ATTR_FILL_STYLE ); |
206 | 0 | pBindings->Invalidate( SID_ATTR_FILL_USE_SLIDE_BACKGROUND ); |
207 | 0 | pBindings->Invalidate( SID_ATTR_FILL_TRANSPARENCE ); |
208 | 0 | pBindings->Invalidate( SID_ATTR_FILL_FLOATTRANSPARENCE ); |
209 | 0 | pBindings->Invalidate( SID_TABLE_MERGE_CELLS ); |
210 | 0 | pBindings->Invalidate( SID_TABLE_SPLIT_CELLS ); |
211 | 0 | pBindings->Invalidate( SID_OPTIMIZE_TABLE ); |
212 | 0 | pBindings->Invalidate( SID_TABLE_VERT_BOTTOM ); |
213 | 0 | pBindings->Invalidate( SID_TABLE_VERT_CENTER ); |
214 | 0 | pBindings->Invalidate( SID_TABLE_VERT_NONE ); |
215 | 0 | break; |
216 | 0 | } |
217 | 0 | case SID_TABLE_VERT_BOTTOM: |
218 | 0 | case SID_TABLE_VERT_CENTER: |
219 | 0 | case SID_TABLE_VERT_NONE: |
220 | 0 | { |
221 | 0 | pBindings->Invalidate( SID_TABLE_VERT_BOTTOM ); |
222 | 0 | pBindings->Invalidate( SID_TABLE_VERT_CENTER ); |
223 | 0 | pBindings->Invalidate( SID_TABLE_VERT_NONE ); |
224 | 0 | break; |
225 | 0 | } |
226 | 0 | } |
227 | | |
228 | 0 | pBindings->Invalidate( SID_UNDO ); |
229 | 0 | pBindings->Invalidate( SID_REDO ); |
230 | 0 | } |
231 | | |
232 | | } |
233 | | |
234 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |