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 <config_features.h>
21
22 #include <sfx2/msg.hxx>
23 #include <svl/srchitem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/infobar.hxx>
26 #include <sfx2/templdlg.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <svx/srchdlg.hxx>
29 #include <basic/sbxobj.hxx>
30 #include <uivwimp.hxx>
31 #include <svx/fmshell.hxx>
32 #include <svx/fmview.hxx>
33 #include <svx/extrusionbar.hxx>
34 #include <svx/fontworkbar.hxx>
35 #include <svx/svxids.hrc>
36 #include <vcl/inputctx.hxx>
37
38 #include <sfx2/objface.hxx>
39 #include <swmodule.hxx>
40 #include <unotxvw.hxx>
41 #include <swtypes.hxx>
42 #include <cmdid.h>
43 #include <globals.hrc>
44 #include <wrtsh.hxx>
45 #include <edtwin.hxx>
46 #include <wgrfsh.hxx>
47 #include <wfrmsh.hxx>
48 #include <wolesh.hxx>
49 #include <wtabsh.hxx>
50 #include <wlistsh.hxx>
51 #include <wformsh.hxx>
52 #include <wtextsh.hxx>
53 #include <barcfg.hxx>
54 #include <doc.hxx>
55
56 // TECHNICALLY not possible !!
57 #include <beziersh.hxx>
58 #include <drawsh.hxx>
59 #include <drwtxtsh.hxx>
60 #include <annotsh.hxx>
61
62 #include <wview.hxx>
63 #include <wdocsh.hxx>
64
65 #include <sfx2/request.hxx>
66 // needed for -fsanitize=function visibility of typeinfo for functions of
67 // type void(SfxShell*,SfxRequest&) defined in swslots.hxx
68 #include <sfx2/viewfac.hxx>
69 #define ShellClass_SwWebView
70 #define ShellClass_Text
71 #include <swslots.hxx>
72
73 SFX_IMPL_NAMED_VIEWFACTORY(SwWebView, "Default")
74 {
75 SFX_VIEW_REGISTRATION(SwWebDocShell);
76 }
77
SFX_IMPL_INTERFACE(SwWebView,SwView)78 SFX_IMPL_INTERFACE(SwWebView, SwView)
79
80 void SwWebView::InitInterface_Impl()
81 {
82 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
83 GetStaticInterface()->RegisterChildWindow(SfxInfoBarContainerChild::GetChildWindowId());
84
85 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_TOOLS, SfxVisibilityFlags::Standard|SfxVisibilityFlags::Server,
86 ToolbarId::Webtools_Toolbox);
87 }
88
89
SwWebView(SfxViewFrame * _pFrame,SfxViewShell * _pShell)90 SwWebView::SwWebView(SfxViewFrame* _pFrame, SfxViewShell* _pShell) :
91 SwView(_pFrame, _pShell)
92 {
93 }
94
~SwWebView()95 SwWebView::~SwWebView()
96 {
97 }
98
SelectShell()99 void SwWebView::SelectShell()
100 {
101 #if HAVE_FEATURE_DESKTOP
102 // Decision whether UpdateTable must be called
103 bool bUpdateTable = false;
104 const SwFrameFormat* pCurTableFormat = GetWrtShell().GetTableFormat();
105 if(pCurTableFormat && pCurTableFormat != GetLastTableFrameFormat())
106 {
107 bUpdateTable = true; // can only be executed later
108 }
109 SetLastTableFrameFormat(pCurTableFormat);
110 //SEL_TBL and SEL_TBL_CELLS can be ored!
111 SelectionType nNewSelectionType = GetWrtShell().GetSelectionType()
112 & ~SelectionType::TableCell;
113
114 SelectionType _nSelectionType = GetSelectionType();
115 if ( nNewSelectionType == _nSelectionType )
116 {
117 GetViewFrame()->GetBindings().InvalidateAll( false );
118 if ( _nSelectionType & SelectionType::Ole ||
119 _nSelectionType & SelectionType::Graphic )
120 //The verb may of course change for graphics and OLE!
121 ImpSetVerb( nNewSelectionType );
122 }
123 else
124 {
125 SfxDispatcher &rDispatcher = *GetViewFrame()->GetDispatcher();
126 SwToolbarConfigItem *pBarCfg = SW_MOD()->GetWebToolbarConfig();
127
128 if( GetCurShell() )
129 {
130 rDispatcher.Flush(); // really delete all cached shells
131
132 //Additional to the old selection remember which toolbar was visible.
133 ToolbarId eId = rDispatcher.GetObjectBarId(SFX_OBJECTBAR_OBJECT);
134 if (eId != ToolbarId::None)
135 pBarCfg->SetTopToolbar( _nSelectionType, eId );
136
137 SfxShell *pSfxShell;
138 sal_uInt16 i;
139 for ( i = 0; true; ++i )
140 {
141 pSfxShell = rDispatcher.GetShell( i );
142 if ( !( dynamic_cast< const SwBaseShell *>( pSfxShell ) != nullptr ||
143 dynamic_cast< const SwDrawTextShell *>( pSfxShell ) || dynamic_cast< const SwAnnotationShell *>( pSfxShell ) != nullptr ) )
144 break;
145 }
146 if (i)
147 {
148 pSfxShell = rDispatcher.GetShell( --i );
149 OSL_ENSURE( pSfxShell, "My Shell is lost in space" );
150 rDispatcher.Pop( *pSfxShell, SfxDispatcherPopFlags::POP_UNTIL | SfxDispatcherPopFlags::POP_DELETE);
151 }
152 }
153
154 bool bInitFormShell = false;
155 if( !GetFormShell() )
156 {
157 bInitFormShell = true;
158 SetFormShell( new FmFormShell( this ) );
159 rDispatcher.Push( *GetFormShell() );
160 }
161
162 bool bSetExtInpCntxt = false;
163 _nSelectionType = nNewSelectionType;
164 SetSelectionType( _nSelectionType );
165 ShellMode eShellMode;
166
167 if ( _nSelectionType & SelectionType::Ole )
168 {
169 eShellMode = ShellMode::Object;
170 SetShell( new SwWebOleShell( *this ));
171 rDispatcher.Push( *GetCurShell() );
172 }
173 else if ( _nSelectionType & SelectionType::Frame
174 || _nSelectionType & SelectionType::Graphic)
175 {
176 eShellMode = ShellMode::Frame;
177 SetShell( new SwWebFrameShell( *this ));
178 rDispatcher.Push( *GetCurShell() );
179 if(_nSelectionType & SelectionType::Graphic )
180 {
181 eShellMode = ShellMode::Graphic;
182 SetShell( new SwWebGrfShell( *this ));
183 rDispatcher.Push( *GetCurShell() );
184 }
185 }
186 else if ( _nSelectionType & SelectionType::Frame )
187 {
188 eShellMode = ShellMode::Frame;
189 SetShell( new SwWebFrameShell( *this ));
190 rDispatcher.Push( *GetCurShell() );
191 }
192 else if ( _nSelectionType & SelectionType::DrawObject )
193 {
194 eShellMode = ShellMode::Draw;
195 SetShell( new svx::ExtrusionBar( this ) );
196 rDispatcher.Push( *GetCurShell() );
197
198 SetShell( new svx::FontworkBar( this ) );
199 rDispatcher.Push( *GetCurShell() );
200
201 SetShell( new SwDrawShell( *this ));
202 rDispatcher.Push( *GetCurShell() );
203 if ( _nSelectionType & SelectionType::Ornament )
204 {
205 eShellMode = ShellMode::Bezier;
206 SetShell( new SwBezierShell( *this ));
207 rDispatcher.Push( *GetCurShell() );
208 }
209
210 }
211 else if ( _nSelectionType & SelectionType::DbForm )
212 {
213 eShellMode = ShellMode::DrawForm;
214 SetShell( new SwWebDrawFormShell( *this ));
215
216 rDispatcher.Push( *GetCurShell() );
217 }
218 else if ( _nSelectionType & SelectionType::DrawObjectEditMode )
219 {
220 eShellMode = ShellMode::DrawText;
221 rDispatcher.Push( *(new SwBaseShell( *this )) );
222 SetShell( new SwDrawTextShell( *this ));
223 rDispatcher.Push( *GetCurShell() );
224 }
225 else if ( _nSelectionType & SelectionType::PostIt )
226 {
227 eShellMode = ShellMode::PostIt;
228 SetShell( new SwAnnotationShell( *this ) );
229 rDispatcher.Push( *GetCurShell() );
230 }
231 else
232 {
233 bSetExtInpCntxt = true;
234 eShellMode = ShellMode::Text;
235 if ( _nSelectionType & SelectionType::NumberList )
236 {
237 eShellMode = ShellMode::ListText;
238 SetShell( new SwWebListShell( *this ));
239 rDispatcher.Push( *GetCurShell() );
240 }
241 SetShell( new SwWebTextShell(*this));
242 rDispatcher.Push( *GetCurShell() );
243 if ( _nSelectionType & SelectionType::Table )
244 {
245 eShellMode = eShellMode == ShellMode::ListText ? ShellMode::TableListText
246 : ShellMode::TableText;
247 SetShell( new SwWebTableShell( *this ));
248 rDispatcher.Push( *GetCurShell() );
249 }
250 }
251 ImpSetVerb( _nSelectionType );
252 GetViewImpl()->SetShellMode(eShellMode);
253
254 if( !GetDocShell()->IsReadOnly() )
255 {
256 if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
257 bSetExtInpCntxt = false;
258
259 InputContext aCntxt( GetEditWin().GetInputContext() );
260 aCntxt.SetOptions( bSetExtInpCntxt
261 ? (aCntxt.GetOptions() |
262 ( InputContextFlags::Text |
263 InputContextFlags::ExtText ))
264 : (aCntxt.GetOptions() & ~
265 InputContextFlags( InputContextFlags::Text |
266 InputContextFlags::ExtText )) );
267 GetEditWin().SetInputContext( aCntxt );
268 }
269
270 //Additional to the selection enable the toolbar, which was
271 //activated last time
272 //Before must be a Flush(), but concerns according to MBA not the
273 //user interface and is not a performance issue.
274 // TODO/LATER: maybe now the Flush() command is superfluous?!
275 rDispatcher.Flush();
276
277 Point aPnt = GetEditWin().GetPointerPosPixel();
278 aPnt = GetEditWin().PixelToLogic(aPnt);
279 GetEditWin().UpdatePointer(aPnt);
280
281 if ( bInitFormShell && GetWrtShell().GetDrawView() )
282 GetFormShell()->SetView( dynamic_cast< FmFormView* >(
283 GetWrtShell().GetDrawView()));
284
285 }
286 GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
287
288 //Opportune time for the communication with OLE objects?
289 if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
290 GetDocShell()->GetDoc()->PrtOLENotify( false );
291
292 //now the table update
293 if(bUpdateTable)
294 GetWrtShell().UpdateTable();
295 #endif
296 }
297
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
299