Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / view.cxx
blob5e59d75ba043f76ecac8700283080b99896470b0
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 <sal/config.h>
22 #include <string_view>
24 #include <config_features.h>
25 #include <config_wasm_strip.h>
27 #include <stdlib.h>
28 #include <hintids.hxx>
29 #include <comphelper/string.hxx>
30 #include <comphelper/lok.hxx>
31 #include <o3tl/any.hxx>
32 #include <o3tl/string_view.hxx>
33 #include <officecfg/Office/Common.hxx>
34 #include <vcl/graph.hxx>
35 #include <vcl/inputctx.hxx>
36 #include <svl/eitem.hxx>
37 #include <unotools/configmgr.hxx>
38 #include <unotools/lingucfg.hxx>
39 #include <unotools/useroptions.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/objface.hxx>
43 #include <sfx2/request.hxx>
44 #include <svx/ruler.hxx>
45 #include <svx/srchdlg.hxx>
46 #include <svx/fmshell.hxx>
47 #include <svx/extrusionbar.hxx>
48 #include <svx/fontworkbar.hxx>
49 #include <svx/fmview.hxx>
50 #include <unotxvw.hxx>
51 #include <cmdid.h>
52 #include <svl/hint.hxx>
53 #include <swmodule.hxx>
54 #include <inputwin.hxx>
55 #include <uivwimp.hxx>
56 #include <edtwin.hxx>
57 #include <textsh.hxx>
58 #include <listsh.hxx>
59 #include <tabsh.hxx>
60 #include <grfsh.hxx>
61 #include <mediash.hxx>
62 #include <docsh.hxx>
63 #include <frmsh.hxx>
64 #include <olesh.hxx>
65 #include <drawsh.hxx>
66 #include <drawbase.hxx>
67 #include <drformsh.hxx>
68 #include <drwtxtsh.hxx>
69 #include <beziersh.hxx>
70 #include <navsh.hxx>
71 #include <globdoc.hxx>
72 #include <scroll.hxx>
73 #include <gloshdl.hxx>
74 #include <usrpref.hxx>
75 #include <srcview.hxx>
76 #include <doc.hxx>
77 #include <IDocumentUndoRedo.hxx>
78 #include <IDocumentSettingAccess.hxx>
79 #include <IDocumentDrawModelAccess.hxx>
80 #include <DocumentFieldsManager.hxx>
81 #include <IDocumentState.hxx>
82 #include <IDocumentLayoutAccess.hxx>
83 #include <drawdoc.hxx>
84 #include <wdocsh.hxx>
85 #include <wrtsh.hxx>
86 #include <barcfg.hxx>
87 #include <pview.hxx>
88 #include <swdtflvr.hxx>
89 #include <prtopt.hxx>
90 #include <com/sun/star/frame/FrameSearchFlag.hpp>
91 #include <com/sun/star/frame/XLayoutManager.hpp>
92 #include <com/sun/star/scanner/ScannerContext.hpp>
93 #include <com/sun/star/scanner/XScannerManager2.hpp>
94 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
95 #include <com/sun/star/sdb/XDatabaseContext.hpp>
96 #include <com/sun/star/sdb/DatabaseContext.hpp>
97 #include <toolkit/helper/vclunohelper.hxx>
98 #include <sal/log.hxx>
100 #include <formatclipboard.hxx>
101 #include <PostItMgr.hxx>
102 #include <annotsh.hxx>
103 #include <swruler.hxx>
104 #include <svx/theme/ThemeColorPaletteManager.hxx>
105 #include <com/sun/star/document/XDocumentProperties.hpp>
106 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
108 #include <comphelper/propertyvalue.hxx>
109 #include <sfx2/lokhelper.hxx>
110 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
111 #include <svtools/embedhlp.hxx>
112 #include <tools/UnitConversion.hxx>
114 using namespace ::com::sun::star;
115 using namespace ::com::sun::star::uno;
116 using namespace ::com::sun::star::lang;
117 using namespace ::com::sun::star::scanner;
118 using namespace ::com::sun::star::sdb;
119 using namespace ::com::sun::star::sdbc;
121 #define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS
123 // Statics. OMG.
125 bool bDocSzUpdated = true;
127 SvxSearchItem* SwView::s_pSrchItem = nullptr;
129 bool SwView::s_bExtra = false;
130 bool SwView::s_bFound = false;
131 bool SwView::s_bJustOpened = false;
133 std::unique_ptr<SearchAttrItemList> SwView::s_xSearchList;
134 std::unique_ptr<SearchAttrItemList> SwView::s_xReplaceList;
136 SfxDispatcher &SwView::GetDispatcher()
138 return *GetViewFrame().GetDispatcher();
141 void SwView::ImpSetVerb( SelectionType nSelType )
143 bool bResetVerbs = m_bVerbsActive;
144 if ( !GetViewFrame().GetFrame().IsInPlace() &&
145 (SelectionType::Ole|SelectionType::Graphic) & nSelType )
147 FlyProtectFlags eProtectFlags = m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content);
148 if (eProtectFlags == FlyProtectFlags::NONE || nSelType & SelectionType::Ole)
150 if ( nSelType & SelectionType::Ole )
152 SetVerbs( GetWrtShell().GetOLEObject()->getSupportedVerbs() );
153 m_bVerbsActive = true;
154 bResetVerbs = false;
158 if ( bResetVerbs )
160 SetVerbs( Sequence< embed::VerbDescriptor >() );
161 m_bVerbsActive = false;
165 // Called by the SwEditWin when it gets the focus.
167 void SwView::GotFocus() const
169 // if we got the focus, and the form shell *is* on the top of the dispatcher
170 // stack, then we need to rebuild the stack (the form shell doesn't belong to
171 // the top then)
172 const SfxDispatcher& rDispatcher = const_cast< SwView* >( this )->GetDispatcher();
173 SfxShell* pTopShell = rDispatcher.GetShell( 0 );
174 FmFormShell* pAsFormShell = dynamic_cast<FmFormShell*>( pTopShell );
175 if ( pAsFormShell )
177 pAsFormShell->ForgetActiveControl();
178 const_cast< SwView* >( this )->AttrChangedNotify(nullptr);
180 else if ( m_pPostItMgr )
182 SwAnnotationShell* pAsAnnotationShell = dynamic_cast<SwAnnotationShell*>( pTopShell );
183 if ( pAsAnnotationShell )
185 m_pPostItMgr->SetActiveSidebarWin(nullptr);
186 const_cast< SwView* >( this )->AttrChangedNotify(nullptr);
189 if (SwWrtShell* pWrtShell = GetWrtShellPtr())
191 SwWrtShell& rWrtShell = GetWrtShell();
192 rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( pWrtShell );
193 rWrtShell.GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::BROWSE_MODE,
194 rWrtShell.GetViewOptions()->getBrowseMode() );
198 // called by the FormShell when a form control is focused. This is
199 // a request to put the form shell on the top of the dispatcher stack
201 IMPL_LINK_NOARG(SwView, FormControlActivated, LinkParamNone*, void)
203 // if a form control has been activated, and the form shell is not on the top
204 // of the dispatcher stack, then we need to activate it
205 const SfxDispatcher& rDispatcher = GetDispatcher();
206 const SfxShell* pTopShell = rDispatcher.GetShell( 0 );
207 const FmFormShell* pAsFormShell = dynamic_cast<const FmFormShell*>( pTopShell );
208 if ( !pAsFormShell )
210 // if we're editing text currently, cancel this
211 SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : nullptr;
212 if ( pSdrView && pSdrView->IsTextEdit() )
213 pSdrView->SdrEndTextEdit( true );
215 AttrChangedNotify(nullptr);
219 namespace
221 uno::Reference<frame::XLayoutManager> getLayoutManager(const SfxViewFrame& rViewFrame)
223 uno::Reference<frame::XLayoutManager> xLayoutManager;
224 uno::Reference<beans::XPropertySet> xPropSet(rViewFrame.GetFrame().GetFrameInterface(),
225 uno::UNO_QUERY);
226 if (xPropSet.is())
230 xLayoutManager.set(xPropSet->getPropertyValue("LayoutManager"), uno::UNO_QUERY);
232 catch (const Exception& e)
234 SAL_WARN("sw.ui", "Failure getting layout manager: " + e.Message);
237 return xLayoutManager;
241 void SwView::ShowUIElement(const OUString& sElementURL) const
243 if (auto xLayoutManager = getLayoutManager(GetViewFrame()))
245 if (!xLayoutManager->getElement(sElementURL).is())
247 xLayoutManager->createElement(sElementURL);
248 xLayoutManager->showElement(sElementURL);
253 void SwView::SelectShell()
255 // Attention: Maintain the SelectShell for the WebView additionally
257 if(m_bInDtor)
258 return;
260 // Decision if the UpdateTable has to be called
261 bool bUpdateTable = false;
262 const SwFrameFormat* pCurTableFormat = m_pWrtShell->GetTableFormat();
263 if(pCurTableFormat && pCurTableFormat != m_pLastTableFormat)
265 bUpdateTable = true; // can only be executed later
267 m_pLastTableFormat = pCurTableFormat;
269 //SEL_TBL and SEL_TBL_CELLS can be ORed!
270 SelectionType nNewSelectionType = m_pWrtShell->GetSelectionType()
271 & ~SelectionType::TableCell;
273 // Determine if a different fly frame was selected.
274 bool bUpdateFly = false;
275 const SwFrameFormat* pCurFlyFormat = nullptr;
276 if (m_nSelectionType & SelectionType::Ole || m_nSelectionType & SelectionType::Graphic)
278 pCurFlyFormat = m_pWrtShell->GetFlyFrameFormat();
280 if (pCurFlyFormat && pCurFlyFormat != m_pLastFlyFormat)
282 bUpdateFly = true;
284 m_pLastFlyFormat = pCurFlyFormat;
286 if ( m_pFormShell && m_pFormShell->IsActiveControl() )
287 nNewSelectionType |= SelectionType::FormControl;
289 if ( nNewSelectionType == m_nSelectionType )
291 GetViewFrame().GetBindings().InvalidateAll( false );
292 if ( m_nSelectionType & SelectionType::Ole ||
293 m_nSelectionType & SelectionType::Graphic )
294 // For graphs and OLE the verb can be modified of course!
295 ImpSetVerb( nNewSelectionType );
297 if (bUpdateFly)
299 SfxViewFrame& rViewFrame = GetViewFrame();
300 uno::Reference<frame::XFrame> xFrame = rViewFrame.GetFrame().GetFrameInterface();
301 if (xFrame.is())
303 // Invalidate cached dispatch objects.
304 xFrame->contextChanged();
308 else
311 SfxDispatcher &rDispatcher = GetDispatcher();
312 SwToolbarConfigItem *pBarCfg = SW_MOD()->GetToolbarConfig();
314 if ( m_pShell )
316 rDispatcher.Flush(); // Really erase all cached shells
317 //Remember to the old selection which toolbar was visible
318 ToolbarId eId = rDispatcher.GetObjectBarId(SFX_OBJECTBAR_OBJECT);
319 if (eId != ToolbarId::None)
320 pBarCfg->SetTopToolbar(m_nSelectionType, eId);
322 for ( sal_uInt16 i = 0; true; ++i )
324 SfxShell *pSfxShell = rDispatcher.GetShell( i );
325 if ( dynamic_cast< const SwBaseShell *>( pSfxShell ) != nullptr
326 || dynamic_cast< const SwDrawTextShell *>( pSfxShell ) != nullptr
327 || dynamic_cast< const svx::ExtrusionBar*>( pSfxShell ) != nullptr
328 || dynamic_cast< const svx::FontworkBar*>( pSfxShell ) != nullptr
329 || dynamic_cast< const SwAnnotationShell *>( pSfxShell ) != nullptr
332 rDispatcher.Pop( *pSfxShell, SfxDispatcherPopFlags::POP_DELETE );
334 else if ( dynamic_cast< const FmFormShell *>( pSfxShell ) != nullptr )
336 rDispatcher.Pop( *pSfxShell );
338 else
339 break;
343 bool bInitFormShell = false;
344 if (!m_pFormShell)
346 bInitFormShell = true;
347 m_pFormShell = new FmFormShell( this );
348 m_pFormShell->SetControlActivationHandler( LINK( this, SwView, FormControlActivated ) );
349 StartListening(*m_pFormShell);
352 bool bSetExtInpCntxt = false;
353 m_nSelectionType = nNewSelectionType;
354 ShellMode eShellMode;
356 if ( !( m_nSelectionType & SelectionType::FormControl ) )
357 rDispatcher.Push( *m_pFormShell );
359 m_pShell = new SwNavigationShell( *this );
360 rDispatcher.Push( *m_pShell );
362 if ( m_nSelectionType & SelectionType::Ole )
364 eShellMode = ShellMode::Object;
365 m_pShell = new SwOleShell( *this );
366 rDispatcher.Push( *m_pShell );
368 else if ( m_nSelectionType & SelectionType::Frame
369 || m_nSelectionType & SelectionType::Graphic)
371 eShellMode = ShellMode::Frame;
372 m_pShell = new SwFrameShell( *this );
373 rDispatcher.Push( *m_pShell );
374 if(m_nSelectionType & SelectionType::Graphic )
376 eShellMode = ShellMode::Graphic;
377 m_pShell = new SwGrfShell( *this );
378 rDispatcher.Push( *m_pShell );
381 else if ( m_nSelectionType & SelectionType::DrawObject )
383 eShellMode = ShellMode::Draw;
384 m_pShell = new SwDrawShell( *this );
385 rDispatcher.Push( *m_pShell );
387 if ( m_nSelectionType & SelectionType::Ornament )
389 eShellMode = ShellMode::Bezier;
390 m_pShell = new SwBezierShell( *this );
391 rDispatcher.Push( *m_pShell );
393 #if HAVE_FEATURE_AVMEDIA
394 else if( m_nSelectionType & SelectionType::Media )
396 eShellMode = ShellMode::Media;
397 m_pShell = new SwMediaShell( *this );
398 rDispatcher.Push( *m_pShell );
400 #endif
401 if (m_nSelectionType & SelectionType::ExtrudedCustomShape)
403 eShellMode = ShellMode::ExtrudedCustomShape;
404 m_pShell = new svx::ExtrusionBar(this);
405 rDispatcher.Push( *m_pShell );
407 if (m_nSelectionType & SelectionType::FontWork)
409 eShellMode = ShellMode::FontWork;
410 m_pShell = new svx::FontworkBar(this);
411 rDispatcher.Push( *m_pShell );
414 else if ( m_nSelectionType & SelectionType::DbForm )
416 eShellMode = ShellMode::DrawForm;
417 m_pShell = new SwDrawFormShell( *this );
419 rDispatcher.Push( *m_pShell );
421 else if ( m_nSelectionType & SelectionType::DrawObjectEditMode )
423 bSetExtInpCntxt = true;
424 eShellMode = ShellMode::DrawText;
425 rDispatcher.Push( *(new SwBaseShell( *this )) );
426 m_pShell = new SwDrawTextShell( *this );
427 rDispatcher.Push( *m_pShell );
429 else if ( m_nSelectionType & SelectionType::PostIt )
431 eShellMode = ShellMode::PostIt;
432 m_pShell = new SwAnnotationShell( *this );
433 rDispatcher.Push( *m_pShell );
435 else
437 bSetExtInpCntxt = true;
438 eShellMode = ShellMode::Text;
439 if ( m_nSelectionType & SelectionType::NumberList )
441 eShellMode = ShellMode::ListText;
442 m_pShell = new SwListShell( *this );
443 rDispatcher.Push( *m_pShell );
445 m_pShell = new SwTextShell(*this);
446 rDispatcher.Push( *m_pShell );
447 if ( m_nSelectionType & SelectionType::Table )
449 eShellMode = eShellMode == ShellMode::ListText ? ShellMode::TableListText
450 : ShellMode::TableText;
451 m_pShell = new SwTableShell( *this );
452 rDispatcher.Push( *m_pShell );
456 if ( m_nSelectionType & SelectionType::FormControl )
457 rDispatcher.Push( *m_pFormShell );
459 m_pViewImpl->SetShellMode(eShellMode);
460 ImpSetVerb( m_nSelectionType );
462 if( !GetDocShell()->IsReadOnly() )
464 if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
465 bSetExtInpCntxt = false;
467 InputContext aCntxt( GetEditWin().GetInputContext() );
468 aCntxt.SetOptions( bSetExtInpCntxt
469 ? (aCntxt.GetOptions() |
470 ( InputContextFlags::Text |
471 InputContextFlags::ExtText ))
472 : (aCntxt.GetOptions() & ~
473 InputContextFlags( InputContextFlags::Text |
474 InputContextFlags::ExtText )) );
475 GetEditWin().SetInputContext( aCntxt );
478 // Show Mail Merge toolbar initially for documents with Database fields
479 if (!m_bInitOnceCompleted && GetWrtShell().IsAnyDatabaseFieldInDoc())
480 ShowUIElement("private:resource/toolbar/mailmerge");
482 // Activate the toolbar to the new selection which also was active last time.
483 // Before a flush () must be, but does not affect the UI according to MBA and
484 // is not a performance problem.
485 // TODO/LATER: maybe now the Flush() command is superfluous?!
486 rDispatcher.Flush();
488 Point aPnt = GetEditWin().OutputToScreenPixel(GetEditWin().GetPointerPosPixel());
489 aPnt = GetEditWin().PixelToLogic(aPnt);
490 GetEditWin().UpdatePointer(aPnt);
492 SdrView* pDView = GetWrtShell().GetDrawView();
493 if ( bInitFormShell && pDView )
494 m_pFormShell->SetView(dynamic_cast<FmFormView*>( pDView) );
497 // Opportune time for the communication with OLE objects?
498 if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
499 GetDocShell()->GetDoc()->PrtOLENotify( false );
501 // now the table-update
502 if(bUpdateTable)
503 m_pWrtShell->UpdateTable();
505 GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
507 m_bInitOnceCompleted = true;
510 // Interaction: AttrChangedNotify() and TimeoutHdl.
511 // No Update if actions are still open, since the cursor on the core side
512 // can be somewhere in no man's land.
513 // But since we can no longer supply status and we want instead lock
514 // the dispatcher.
516 extern "C"
518 static int lcl_CmpIds( const void *pFirst, const void *pSecond)
520 return *static_cast<sal_uInt16 const *>(pFirst) - *static_cast<sal_uInt16 const *>(pSecond);
524 IMPL_LINK_NOARG(SwView, AttrChangedNotify, LinkParamNone*, void)
526 if ( GetEditWin().IsChainMode() )
527 GetEditWin().SetChainMode( false );
529 if (!m_pWrtShell || !GetDocShell())
531 return;
534 //Opt: Not if PaintLocked. During unlock a notify will be once more triggered.
535 if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt &&
536 GetDocShell()->IsReadOnly() )
537 CheckReadonlyState();
539 if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt )
540 CheckReadonlySelection();
542 if( !m_bAttrChgNotified )
544 if (m_pWrtShell->ActionPend() || g_bNoInterrupt ||
545 GetDispatcher().IsLocked() || //do not confuse the SFX
546 GetViewFrame().GetBindings().IsInUpdate() )//do not confuse the SFX
548 m_bAttrChgNotified = true;
549 m_aTimer.Start();
551 const SfxBoolItem *pItem =
552 GetObjectShell()->GetMedium()->GetItemSet()->
553 GetItemIfSet( SID_HIDDEN, false );
554 if ( !pItem || !pItem->GetValue() )
556 GetViewFrame().GetBindings().ENTERREGISTRATIONS();
557 m_bAttrChgNotifiedWithRegistrations = true;
561 else
562 SelectShell();
566 // change ui if cursor is at a SwPostItField
567 if (m_pPostItMgr)
569 // only perform the code that is needed to determine, if at the
570 // actual cursor position is a post-it field
571 m_pPostItMgr->SetShadowState( m_pWrtShell->GetPostItFieldAtCursor() );
575 IMPL_LINK_NOARG(SwView, TimeoutHdl, Timer *, void)
577 if (m_pWrtShell->ActionPend() || g_bNoInterrupt)
579 m_aTimer.Start();
580 return;
583 if ( m_bAttrChgNotifiedWithRegistrations )
585 GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
586 m_bAttrChgNotifiedWithRegistrations = false;
589 CheckReadonlyState();
590 CheckReadonlySelection();
592 bool bOldUndo = m_pWrtShell->DoesUndo();
593 m_pWrtShell->DoUndo( false );
594 SelectShell();
595 m_pWrtShell->DoUndo( bOldUndo );
596 m_bAttrChgNotified = false;
597 GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
600 void SwView::CheckReadonlyState()
602 SfxDispatcher &rDis = GetDispatcher();
603 // To be able to recognize if it is already disabled!
604 SfxItemState eStateRO, eStateProtAll;
605 const SfxPoolItem *pItem;
606 // Query the status from a slot which is only known to us.
607 // Otherwise the slot is known from other; like the BasicIde
608 eStateRO = rDis.QueryState( FN_INSERT_BOOKMARK, pItem );
609 eStateProtAll = rDis.QueryState( FN_EDIT_REGION, pItem );
610 bool bChgd = false;
612 if ( !m_pWrtShell->IsCursorReadonly() )
614 static sal_uInt16 aROIds[] =
616 SID_DELETE, FN_BACKSPACE, FN_SHIFT_BACKSPACE,
617 SID_UNDO,
618 SID_REDO, SID_REPEAT, SID_PASTE,
619 SID_PASTE_UNFORMATTED, FN_PASTE_NESTED_TABLE, FN_TABLE_PASTE_ROW_BEFORE,
620 FN_TABLE_PASTE_COL_BEFORE, SID_PASTE_SPECIAL, SID_SBA_BRW_INSERT,
621 SID_BACKGROUND_COLOR, FN_INSERT_BOOKMARK, SID_CHARMAP_CONTROL,
622 SID_CHARMAP, FN_INSERT_SOFT_HYPHEN,
623 FN_INSERT_HARDHYPHEN, FN_INSERT_HARD_SPACE, FN_INSERT_NNBSP,
624 FN_INSERT_BREAK, FN_INSERT_LINEBREAK, FN_INSERT_COLUMN_BREAK,
625 FN_INSERT_BREAK_DLG, FN_INSERT_CONTENT_CONTROL, FN_INSERT_CHECKBOX_CONTENT_CONTROL,
626 FN_INSERT_DROPDOWN_CONTENT_CONTROL, FN_INSERT_PICTURE_CONTENT_CONTROL,
627 FN_INSERT_DATE_CONTENT_CONTROL, FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL,
628 FN_INSERT_COMBO_BOX_CONTENT_CONTROL,
629 FN_DELETE_SENT, FN_DELETE_BACK_SENT, FN_DELETE_WORD,
630 FN_DELETE_BACK_WORD, FN_DELETE_LINE, FN_DELETE_BACK_LINE,
631 FN_DELETE_PARA, FN_DELETE_BACK_PARA, FN_DELETE_WHOLE_LINE,
632 FN_CALCULATE, FN_FORMAT_RESET,
633 FN_POSTIT, FN_JAVAEDIT, SID_ATTR_PARA_ADJUST_LEFT,
634 SID_ATTR_PARA_ADJUST_RIGHT, SID_ATTR_PARA_ADJUST_CENTER,SID_ATTR_PARA_ADJUST_BLOCK,
635 SID_ATTR_PARA_LINESPACE_10, SID_ATTR_PARA_LINESPACE_15, SID_ATTR_PARA_LINESPACE_20,
636 SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONTHEIGHT, SID_ATTR_CHAR_COLOR_BACKGROUND,
637 SID_ATTR_CHAR_BACK_COLOR,
638 SID_ATTR_CHAR_COLOR_BACKGROUND_EXT, SID_ATTR_CHAR_COLOR_EXT,
639 SID_ATTR_CHAR_COLOR, SID_ATTR_CHAR_WEIGHT, SID_ATTR_CHAR_POSTURE,
640 SID_ATTR_CHAR_OVERLINE,
641 SID_ATTR_CHAR_UNDERLINE, SID_ATTR_FLASH, SID_ATTR_CHAR_STRIKEOUT,
642 SID_ULINE_VAL_SINGLE, SID_ULINE_VAL_DOUBLE, SID_ULINE_VAL_DOTTED,
643 SID_ATTR_CHAR_CONTOUR, SID_ATTR_CHAR_SHADOWED,
644 SID_ATTR_CHAR_AUTOKERN, SID_ATTR_CHAR_ESCAPEMENT, FN_SET_SUPER_SCRIPT,
645 FN_SET_SUB_SCRIPT, SID_ATTR_CHAR_CASEMAP, SID_ATTR_CHAR_LANGUAGE,
646 SID_ATTR_CHAR_KERNING, SID_CHAR_DLG, SID_ATTR_CHAR_WORDLINEMODE,
647 FN_GROW_FONT_SIZE, FN_SHRINK_FONT_SIZE, FN_TXTATR_INET,
648 FN_FORMAT_DROPCAPS, SID_ATTR_PARA_ADJUST, SID_ATTR_PARA_LINESPACE,
649 SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_KEEP, SID_ATTR_PARA_WIDOWS,
650 SID_ATTR_PARA_ORPHANS,
651 SID_ATTR_PARA_MODEL, SID_PARA_DLG,
652 FN_SELECT_PARA, SID_DEC_INDENT,
653 SID_INC_INDENT
655 static bool bFirst = true;
656 if ( bFirst )
658 qsort( static_cast<void*>(aROIds), SAL_N_ELEMENTS(aROIds), sizeof(sal_uInt16), lcl_CmpIds );
659 bFirst = false;
661 if ( SfxItemState::DISABLED == eStateRO )
663 rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aROIds );
664 bChgd = true;
667 else if( m_pWrtShell->IsAllProtect() )
669 if ( SfxItemState::DISABLED == eStateProtAll )
671 static sal_uInt16 aAllProtIds[] = { SID_SAVEDOC, FN_EDIT_REGION };
672 static bool bAllProtFirst = true;
673 if ( bAllProtFirst )
675 qsort( static_cast<void*>(aAllProtIds), SAL_N_ELEMENTS(aAllProtIds), sizeof(sal_uInt16), lcl_CmpIds );
676 bAllProtFirst = false;
678 rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aAllProtIds );
679 bChgd = true;
682 else if ( SfxItemState::DISABLED != eStateRO ||
683 SfxItemState::DISABLED != eStateProtAll )
685 bChgd = true;
686 rDis.SetSlotFilter();
688 if ( bChgd )
689 GetViewFrame().GetBindings().InvalidateAll(true);
692 void SwView::CheckReadonlySelection()
694 SfxDisableFlags nDisableFlags = SfxDisableFlags::NONE;
695 SfxDispatcher &rDis = GetDispatcher();
697 if( m_pWrtShell->HasReadonlySel() &&
698 ( !m_pWrtShell->GetDrawView() ||
699 !m_pWrtShell->GetDrawView()->GetMarkedObjectList().GetMarkCount() ))
700 nDisableFlags |= SfxDisableFlags::SwOnProtectedCursor;
702 if( (SfxDisableFlags::SwOnProtectedCursor & nDisableFlags ) !=
703 (SfxDisableFlags::SwOnProtectedCursor & rDis.GetDisableFlags() ) )
705 // Additionally move at the Window the InputContext, so that
706 // in japanese / chinese versions the external input will be
707 // turned on or off. This but only if the correct shell is on
708 // the stack.
709 switch( m_pViewImpl->GetShellMode() )
711 case ShellMode::Text:
712 case ShellMode::ListText:
713 case ShellMode::TableText:
714 case ShellMode::TableListText:
716 // Temporary solution!!! Should set the font of the current insertion point
717 // at each cursor movement, so outside of this "if". But TH does not
718 // evaluates the font at this time and the "purchase" appears to me
719 // as too expensive.
720 // Moreover, we don't have a font, but only attributes from which the
721 // text formatting and the correct font will be build together.
723 InputContext aCntxt( GetEditWin().GetInputContext() );
724 aCntxt.SetOptions( SfxDisableFlags::SwOnProtectedCursor & nDisableFlags
725 ? (aCntxt.GetOptions() & ~
726 InputContextFlags( InputContextFlags::Text |
727 InputContextFlags::ExtText ))
728 : (aCntxt.GetOptions() |
729 ( InputContextFlags::Text |
730 InputContextFlags::ExtText )) );
731 GetEditWin().SetInputContext( aCntxt );
733 break;
734 default:
740 if( nDisableFlags != rDis.GetDisableFlags() )
742 rDis.SetDisableFlags( nDisableFlags );
743 GetViewFrame().GetBindings().InvalidateAll( true );
747 SwView::SwView(SfxViewFrame& _rFrame, SfxViewShell* pOldSh)
748 : SfxViewShell(_rFrame, SWVIEWFLAGS),
749 m_aTimer( "sw::SwView m_aTimer" ),
750 m_nNewPage(USHRT_MAX),
751 m_nOldPageNum(0),
752 m_pNumRuleNodeFromDoc(nullptr),
753 m_pEditWin( VclPtr<SwEditWin>::Create( &_rFrame.GetWindow(), *this ) ),
754 m_pShell(nullptr),
755 m_pFormShell(nullptr),
756 m_pHScrollbar(nullptr),
757 m_pVScrollbar(nullptr),
758 m_pVRuler(VclPtr<SvxRuler>::Create(&GetViewFrame().GetWindow(), m_pEditWin,
759 SvxRulerSupportFlags::TABS | SvxRulerSupportFlags::PARAGRAPH_MARGINS_VERTICAL|
760 SvxRulerSupportFlags::BORDERS | SvxRulerSupportFlags::REDUCED_METRIC,
761 GetViewFrame().GetBindings(),
762 WB_VSCROLL | WB_EXTRAFIELD | WB_BORDER )),
763 m_pLastTableFormat(nullptr),
764 m_pLastFlyFormat(nullptr),
765 m_pFormatClipboard(new SwFormatClipboard()),
766 m_nSelectionType( SelectionType::All ),
767 m_nPageCnt(0),
768 m_nDrawSfxId( USHRT_MAX ),
769 m_nFormSfxId( USHRT_MAX ),
770 m_eFormObjKind(SdrObjKind::NONE),
771 m_nLastPasteDestination( static_cast<SotExchangeDest>(0xFFFF) ),
772 m_nLeftBorderDistance( 0 ),
773 m_nRightBorderDistance( 0 ),
774 m_eLastSearchCommand( static_cast<SvxSearchCmd>(0xFFFF) ),
775 m_bWheelScrollInProgress(false),
776 m_bCenterCursor(false),
777 m_bTopCursor(false),
778 m_bTabColFromDoc(false),
779 m_bTabRowFromDoc(false),
780 m_bSetTabColFromDoc(false),
781 m_bSetTabRowFromDoc(false),
782 m_bAttrChgNotified(false),
783 m_bAttrChgNotifiedWithRegistrations(false),
784 m_bVerbsActive(false),
785 m_bDrawRotate(false),
786 m_bDrawSelMode(true),
787 m_bShowAtResize(true),
788 m_bInOuterResizePixel(false),
789 m_bInInnerResizePixel(false),
790 m_bPasteState(false),
791 m_bPasteSpecialState(false),
792 m_bInMailMerge(false),
793 m_bInDtor(false),
794 m_bOldShellWasPagePreview(false),
795 m_bIsPreviewDoubleClick(false),
796 m_bMakeSelectionVisible(false),
797 m_bForceChangesToolbar(true),
798 m_nLOKPageUpDownOffset(0)
800 static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE");
801 if (bRequestDoubleBuffering)
802 m_pEditWin->RequestDoubleBuffering(true);
804 // According to discussion with MBA and further
805 // investigations, no old SfxViewShell will be set as parameter <pOldSh>,
806 // if function "New Window" is performed to open an additional view beside
807 // an already existing one.
808 // If the view is switch from one to another, the 'old' view is given by
809 // parameter <pOldSh>.
811 bDocSzUpdated = true;
813 static bool bFuzzing = utl::ConfigManager::IsFuzzing();
815 if (!bFuzzing)
817 CreateScrollbar( true );
818 CreateScrollbar( false );
821 m_pViewImpl.reset(new SwView_Impl(this));
822 SetName("View");
823 SetWindow( m_pEditWin );
825 m_aTimer.SetTimeout( 120 );
827 SwDocShell& rDocSh = dynamic_cast<SwDocShell&>(*_rFrame.GetObjectShell());
828 bool bOldModifyFlag = rDocSh.IsEnableSetModified();
829 if (bOldModifyFlag)
830 rDocSh.EnableSetModified( false );
831 // HACK: SwDocShell has some cached font info, VCL informs about font updates,
832 // but loading of docs with embedded fonts happens after SwDocShell is created
833 // but before SwEditWin (which handles the VCL event) is created. So update
834 // manually.
835 if (rDocSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
836 rDocSh.UpdateFontList();
837 bool bWebDShell = dynamic_cast<const SwWebDocShell*>(&rDocSh) != nullptr;
839 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(bWebDShell);
840 SwViewOption aUsrPref( *pUsrPref);
842 //! get lingu options without loading lingu DLL
843 SvtLinguOptions aLinguOpt;
844 SvtLinguConfig().GetOptions( aLinguOpt );
845 aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto );
847 bool bOldShellWasSrcView = false;
849 // determine if there is an existing view for
850 // document
851 SfxViewShell* pExistingSh = nullptr;
852 if ( pOldSh )
854 pExistingSh = pOldSh;
855 // determine type of existing view
856 if (SwPagePreview* pPagePreview = dynamic_cast<SwPagePreview *>(pExistingSh))
858 m_sSwViewData = pPagePreview->GetPrevSwViewData();
859 m_sNewCursorPos = pPagePreview->GetNewCursorPos();
860 m_nNewPage = pPagePreview->GetNewPage();
861 m_bOldShellWasPagePreview = true;
862 m_bIsPreviewDoubleClick = !m_sNewCursorPos.isEmpty() || m_nNewPage != USHRT_MAX;
864 else if (dynamic_cast<const SwSrcView *>(pExistingSh) != nullptr)
865 bOldShellWasSrcView = true;
868 SAL_INFO( "sw.ui", "before create WrtShell" );
869 if (SwView *pView = dynamic_cast<SwView*>(pExistingSh))
871 m_pWrtShell.reset(new SwWrtShell(*pView->m_pWrtShell, m_pEditWin, *this));
873 else if (SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(rDocSh.GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()))
875 m_pWrtShell.reset(new SwWrtShell(*pWrtShell, m_pEditWin, *this));
877 else
879 SwDoc& rDoc = *rDocSh.GetDoc();
881 if( !bOldShellWasSrcView && bWebDShell && !m_bOldShellWasPagePreview )
882 aUsrPref.setBrowseMode( true );
883 else
884 aUsrPref.setBrowseMode( rDoc.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) );
886 //For the BrowseMode we do not assume a factor.
887 if( aUsrPref.getBrowseMode() && aUsrPref.GetZoomType() != SvxZoomType::PERCENT )
889 aUsrPref.SetZoomType( SvxZoomType::PERCENT );
890 aUsrPref.SetZoom( 100 );
892 if (rDocSh.IsPreview())
894 aUsrPref.SetZoomType( SvxZoomType::WHOLEPAGE );
895 aUsrPref.SetViewLayoutBookMode( false );
896 aUsrPref.SetViewLayoutColumns( 1 );
898 m_pWrtShell.reset(new SwWrtShell(rDoc, m_pEditWin, *this, &aUsrPref));
899 // creating an SwView from a SwPagePreview needs to
900 // add the SwViewShell to the ring of the other SwViewShell(s)
901 if(m_bOldShellWasPagePreview)
903 SwViewShell& rPreviewViewShell = *static_cast<SwPagePreview*>(pExistingSh)->GetViewShell();
904 m_pWrtShell->MoveTo(&rPreviewViewShell);
905 // to update the field command et.al. if necessary
906 const SwViewOption* pPreviewOpt = rPreviewViewShell.GetViewOptions();
907 if( pPreviewOpt->IsFieldName() != aUsrPref.IsFieldName() ||
908 pPreviewOpt->IsShowHiddenField() != aUsrPref.IsShowHiddenField() ||
909 pPreviewOpt->IsShowHiddenPara() != aUsrPref.IsShowHiddenPara() ||
910 pPreviewOpt->IsShowHiddenChar() != aUsrPref.IsShowHiddenChar() )
911 rPreviewViewShell.ApplyViewOptions(aUsrPref);
912 // reset design mode at draw view for form
913 // shell, if needed.
914 if ( static_cast<SwPagePreview*>(pExistingSh)->ResetFormDesignMode() &&
915 m_pWrtShell->HasDrawView() )
917 SdrView* pDrawView = m_pWrtShell->GetDrawView();
918 pDrawView->SetDesignMode( static_cast<SwPagePreview*>(pExistingSh)->FormDesignModeToReset() );
922 SAL_INFO( "sw.ui", "after create WrtShell" );
923 m_pHRuler = VclPtr<SwCommentRuler>::Create(m_pWrtShell.get(), &GetViewFrame().GetWindow(), m_pEditWin,
924 SvxRulerSupportFlags::TABS |
925 SvxRulerSupportFlags::PARAGRAPH_MARGINS |
926 SvxRulerSupportFlags::BORDERS |
927 SvxRulerSupportFlags::NEGATIVE_MARGINS|
928 SvxRulerSupportFlags::REDUCED_METRIC,
929 GetViewFrame().GetBindings(),
930 WB_STDRULER | WB_EXTRAFIELD | WB_BORDER);
932 // assure that modified state of document
933 // isn't reset, if document is already modified.
934 const bool bIsDocModified = m_pWrtShell->GetDoc()->getIDocumentState().IsModified();
936 // Thus among other things, the HRuler is not displayed in the read-only case.
937 aUsrPref.SetReadonly( m_pWrtShell->GetViewOptions()->IsReadonly() );
939 // no margin for OLE!
940 Size aBrwsBorder;
941 if( SfxObjectCreateMode::EMBEDDED != rDocSh.GetCreateMode() )
942 aBrwsBorder = GetMargin();
944 m_pWrtShell->SetBrowseBorder( aBrwsBorder );
946 // In CTOR no shell changes may take place, which must be temporarily stored
947 // with the timer. Otherwise, the SFX removes them from the stack!
948 bool bOld = g_bNoInterrupt;
949 g_bNoInterrupt = true;
951 m_pHRuler->SetActive();
952 m_pVRuler->SetActive();
954 SfxViewFrame& rViewFrame = GetViewFrame();
956 StartListening(rViewFrame, DuplicateHandling::Prevent);
957 StartListening(rDocSh, DuplicateHandling::Prevent);
959 // Set Zoom-factor from HRuler
960 Fraction aZoomFract( aUsrPref.GetZoom(), 100 );
961 m_pHRuler->SetZoom( aZoomFract );
962 m_pVRuler->SetZoom( aZoomFract );
963 m_pHRuler->SetDoubleClickHdl(LINK( this, SwView, ExecRulerClick ));
964 FieldUnit eMetric = pUsrPref->GetHScrollMetric();
965 m_pHRuler->SetUnit( eMetric );
967 eMetric = pUsrPref->GetVScrollMetric();
968 m_pVRuler->SetUnit( eMetric );
970 m_pHRuler->SetCharWidth( 371 ); // default character width
971 m_pVRuler->SetLineHeight( 551 ); // default line height
973 // Set DocShell
974 m_xGlueDocShell.reset(new SwViewGlueDocShell(*this, rDocSh));
975 m_pPostItMgr.reset(new SwPostItMgr(this));
977 // Check and process the DocSize. Via the handler, the shell could not
978 // be found, because the shell is not known in the SFX management
979 // within the CTOR phase.
980 DocSzChgd( m_pWrtShell->GetDocSize() );
982 // Set AttrChangedNotify link
983 m_pWrtShell->SetChgLnk(LINK(this, SwView, AttrChangedNotify));
985 if (rDocSh.GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
986 !rDocSh.GetVisArea(ASPECT_CONTENT).IsEmpty())
987 SetVisArea(rDocSh.GetVisArea(ASPECT_CONTENT),false);
989 SAL_WARN_IF(
990 officecfg::Office::Common::Undo::Steps::get() <= 0,
991 "sw.ui", "/org.openoffice.Office.Common/Undo/Steps <= 0");
992 if (!bFuzzing && 0 < officecfg::Office::Common::Undo::Steps::get())
994 m_pWrtShell->DoUndo();
997 const bool bBrowse = m_pWrtShell->GetViewOptions()->getBrowseMode();
998 // Disable "multiple window"
999 SetNewWindowAllowed(!bBrowse);
1000 // End of disabled multiple window
1002 m_bVScrollbarEnabled = aUsrPref.IsViewVScrollBar();
1003 m_bHScrollbarEnabled = aUsrPref.IsViewHScrollBar();
1004 if (m_pHScrollbar)
1005 m_pHScrollbar->SetAuto(bBrowse);
1006 if( aUsrPref.IsViewHRuler() )
1007 CreateTab();
1008 if( aUsrPref.IsViewVRuler() )
1009 CreateVRuler();
1011 m_pWrtShell->SetUIOptions( aUsrPref );
1012 m_pWrtShell->SetReadOnlyAvailable( aUsrPref.IsCursorInProtectedArea() );
1013 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1014 m_pWrtShell->ApplyAccessibilityOptions();
1015 #endif
1017 if( m_pWrtShell->GetDoc()->getIDocumentState().IsUpdateExpField() )
1019 if (m_pWrtShell->GetDoc()->GetDocumentFieldsManager().containsUpdatableFields())
1021 CurrShell aCurr(m_pWrtShell.get());
1022 m_pWrtShell->StartAction();
1023 m_pWrtShell->CalcLayout();
1024 m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().UpdateFields(false);
1025 m_pWrtShell->EndAction();
1027 m_pWrtShell->GetDoc()->getIDocumentState().SetUpdateExpFieldStat( false );
1030 // Update all tables if necessary:
1031 if( m_pWrtShell->GetDoc()->IsUpdateTOX() )
1033 SfxRequest aSfxRequest( FN_UPDATE_TOX, SfxCallMode::SLOT, GetPool() );
1034 Execute( aSfxRequest );
1035 m_pWrtShell->GetDoc()->SetUpdateTOX( false ); // reset again
1036 m_pWrtShell->SttEndDoc(true);
1039 // No ResetModified, if there is already a view to this doc.
1040 SfxViewFrame& rVFrame = GetViewFrame();
1041 SfxViewFrame* pFirst = SfxViewFrame::GetFirst(&rDocSh);
1042 // Currently(360) the view is registered firstly after the CTOR,
1043 // the following expression is also working if this changes.
1044 // If the modification cannot be canceled by undo, then do NOT set
1045 // the modify back.
1046 // no reset of modified state, if document
1047 // was already modified.
1048 if (!m_pWrtShell->GetDoc()->GetIDocumentUndoRedo().IsUndoNoResetModified() &&
1049 ( !pFirst || pFirst == &rVFrame ) &&
1050 !bIsDocModified )
1052 m_pWrtShell->ResetModified();
1055 g_bNoInterrupt = bOld;
1057 // If a new GlobalDoc will be created, the navigator will also be generated.
1058 if( dynamic_cast<const SwGlobalDocShell*>(&rDocSh) != nullptr &&
1059 !rVFrame.GetChildWindow( SID_NAVIGATOR ))
1061 SfxBoolItem aNavi(SID_NAVIGATOR, true);
1062 GetDispatcher().ExecuteList(SID_NAVIGATOR, SfxCallMode::ASYNCHRON, { &aNavi });
1065 uno::Reference< frame::XFrame > xFrame = rVFrame.GetFrame().GetFrameInterface();
1067 uno::Reference< frame::XFrame > xBeamerFrame = xFrame->findFrame(
1068 "_beamer", frame::FrameSearchFlag::CHILDREN);
1069 if(xBeamerFrame.is())
1071 SwDBData aData = m_pWrtShell->GetDBData();
1072 SwModule::ShowDBObj( *this, aData );
1075 // has anybody calls the attrchanged handler in the constructor?
1076 if( m_bAttrChgNotifiedWithRegistrations )
1078 GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1079 if( m_aTimer.IsActive() )
1080 m_aTimer.Stop();
1083 m_aTimer.SetInvokeHandler(LINK(this, SwView, TimeoutHdl));
1084 m_bAttrChgNotified = m_bAttrChgNotifiedWithRegistrations = false;
1085 if (bOldModifyFlag)
1086 rDocSh.EnableSetModified();
1087 InvalidateBorder();
1089 if (!bFuzzing)
1091 if (!m_pHScrollbar->IsScrollbarVisible(true))
1092 ShowHScrollbar( false );
1093 if (!m_pVScrollbar->IsScrollbarVisible(true))
1094 ShowVScrollbar( false );
1097 if (m_pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton())
1098 m_pWrtShell->InvalidateOutlineContentVisibility();
1100 if (!bFuzzing)
1101 GetViewFrame().GetWindow().AddChildEventListener(LINK(this, SwView, WindowChildEventListener));
1104 SwViewGlueDocShell::SwViewGlueDocShell(SwView& rView, SwDocShell& rDocSh)
1105 : m_rView(rView)
1107 // Set DocShell
1108 rDocSh.SetView(&m_rView);
1109 SW_MOD()->SetView(&m_rView);
1112 SwViewGlueDocShell::~SwViewGlueDocShell()
1114 SwDocShell* pDocSh = m_rView.GetDocShell();
1115 if (pDocSh && pDocSh->GetView() == &m_rView)
1116 pDocSh->SetView(nullptr);
1117 if (SW_MOD()->GetView() == &m_rView)
1118 SW_MOD()->SetView(nullptr);
1121 SwView::~SwView()
1123 // Notify other LOK views that we are going away.
1124 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false");
1125 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", "");
1126 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY");
1128 // Need to remove activated field's button before disposing EditWin.
1129 GetWrtShell().getIDocumentMarkAccess()->ClearFieldActivation();
1131 GetViewFrame().GetWindow().RemoveChildEventListener( LINK( this, SwView, WindowChildEventListener ) );
1132 m_pPostItMgr.reset();
1134 m_bInDtor = true;
1135 m_pEditWin->Hide(); // prevent problems with painting
1137 // Set pointer in SwDocShell to the view again
1138 m_xGlueDocShell.reset();
1140 if( m_aTimer.IsActive() && m_bAttrChgNotifiedWithRegistrations )
1141 GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1143 // the last view must end the text edit
1144 SdrView *pSdrView = m_pWrtShell->GetDrawView();
1145 if( pSdrView && pSdrView->IsTextEdit() )
1146 pSdrView->SdrEndTextEdit( true );
1147 else if (pSdrView)
1149 pSdrView->DisposeUndoManager();
1152 SetWindow( nullptr );
1154 m_pViewImpl->Invalidate();
1155 EndListening(GetViewFrame());
1156 EndListening(*GetDocShell());
1158 // tdf#155410 speedup shutdown, prevent unnecessary broadcasting during teardown of draw model
1159 auto pDrawModel = GetWrtShell().getIDocumentDrawModelAccess().GetDrawModel();
1160 const bool bWasLocked = pDrawModel->isLocked();
1161 pDrawModel->setLock(true);
1162 m_pWrtShell.reset(); // reset here so that it is not accessible by the following dtors.
1163 pDrawModel->setLock(bWasLocked);
1165 m_pHScrollbar.disposeAndClear();
1166 m_pVScrollbar.disposeAndClear();
1167 m_pHRuler.disposeAndClear();
1168 m_pVRuler.disposeAndClear();
1169 m_pGlosHdl.reset();
1170 m_pViewImpl.reset();
1172 // If this was enabled in the ctor for the frame, then disable it here.
1173 static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE");
1174 if (bRequestDoubleBuffering)
1175 m_pEditWin->RequestDoubleBuffering(false);
1176 m_pEditWin.disposeAndClear();
1178 m_pFormatClipboard.reset();
1181 void SwView::afterCallbackRegistered()
1183 if (!comphelper::LibreOfficeKit::isActive())
1184 return;
1185 auto* pDocShell = GetDocShell();
1186 if (pDocShell)
1188 svx::ThemeColorPaletteManager aManager(pDocShell->GetThemeColors());
1189 libreOfficeKitViewCallback(LOK_CALLBACK_COLOR_PALETTES, aManager.generateJSON());
1193 SwDocShell* SwView::GetDocShell()
1195 SfxObjectShell* pDocShell = GetViewFrame().GetObjectShell();
1196 return dynamic_cast<SwDocShell*>( pDocShell );
1199 // Remember CursorPos
1201 void SwView::WriteUserData( OUString &rUserData, bool bBrowse )
1203 // The browse flag will be passed from Sfx when documents are browsed
1204 // (not to be confused with the BrowseMode).
1205 // Then that stored data are not persistent!
1207 const SwRect& rRect = m_pWrtShell->GetCharRect();
1208 const tools::Rectangle& rVis = GetVisArea();
1210 rUserData = OUString::number( rRect.Left() );
1211 rUserData += ";";
1212 rUserData += OUString::number( rRect.Top() );
1213 rUserData += ";";
1214 rUserData += OUString::number( m_pWrtShell->GetViewOptions()->GetZoom() );
1215 rUserData += ";";
1216 rUserData += OUString::number( rVis.Left() );
1217 rUserData += ";";
1218 rUserData += OUString::number( rVis.Top() );
1219 rUserData += ";";
1220 rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Right());
1221 rUserData += ";";
1222 rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Bottom());
1223 rUserData += ";";
1224 rUserData += OUString::number(
1225 static_cast<sal_uInt16>(m_pWrtShell->GetViewOptions()->GetZoomType()));//eZoom;
1226 rUserData += ";";
1227 rUserData += FrameTypeFlags::NONE == m_pWrtShell->GetSelFrameType() ? std::u16string_view(u"0") : std::u16string_view(u"1");
1230 // Set CursorPos
1232 static bool lcl_IsOwnDocument( SwView& rView )
1234 if (::officecfg::Office::Common::Load::ViewPositionForAnyUser::get())
1236 return true;
1238 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1239 rView.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
1240 uno::Reference<document::XDocumentProperties> xDocProps
1241 = xDPS->getDocumentProperties();
1242 OUString Created = xDocProps->getAuthor();
1243 OUString Changed = xDocProps->getModifiedBy();
1244 OUString FullName = SW_MOD()->GetUserOptions().GetFullName();
1245 return !FullName.isEmpty()
1246 && (Changed == FullName || (Changed.isEmpty() && Created == FullName));
1249 void SwView::ReadUserData( const OUString &rUserData, bool bBrowse )
1251 if ( !(rUserData.indexOf(';')>=0 && // more than one token
1252 // For document without layout only in the onlinelayout or
1253 // while forward/backward
1254 (!m_pWrtShell->IsNewLayout() || m_pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse)) )
1255 return;
1257 bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1259 CurrShell aCurr(m_pWrtShell.get());
1261 sal_Int32 nPos = 0;
1263 // No it is *not* a good idea to call GetToken within Point constr. immediately,
1264 // because which parameter is evaluated first?
1265 tools::Long nX = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1266 nY = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos ));
1267 Point aCursorPos( nX, nY );
1269 sal_uInt16 nZoomFactor =
1270 static_cast< sal_uInt16 >( o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )) );
1272 tools::Long nLeft = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1273 nTop = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1274 nRight = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1275 nBottom= o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos ));
1277 const tools::Long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1278 if ( nBottom > (m_pWrtShell->GetDocSize().Height()+nAdd) )
1279 return;
1281 m_pWrtShell->EnableSmooth( false );
1283 const tools::Rectangle aVis( nLeft, nTop, nRight, nBottom );
1285 sal_Int32 nOff = 0;
1286 SvxZoomType eZoom;
1287 if( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1288 eZoom = static_cast<SvxZoomType>(o3tl::narrowing<sal_uInt16>(o3tl::toInt32(o3tl::getToken(rUserData, nOff, ';', nPos ))));
1289 else
1291 eZoom = SvxZoomType::PERCENT;
1292 ++nOff;
1295 bool bSelectObj = (0 != o3tl::toInt32(o3tl::getToken(rUserData, nOff, ';', nPos )))
1296 && m_pWrtShell->IsObjSelectable( aCursorPos );
1298 // restore editing position
1299 m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj);
1300 // set flag value to avoid macro execution.
1301 bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1302 m_pWrtShell->SetMacroExecAllowed( false );
1303 // os: changed: The user data has to be read if the view is switched back from page preview
1304 // go to the last editing position when opening own files
1305 if(m_bOldShellWasPagePreview || bIsOwnDocument)
1307 m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj );
1308 if( bSelectObj )
1310 m_pWrtShell->SelectObj( aCursorPos );
1311 m_pWrtShell->EnterSelFrameMode( &aCursorPos );
1315 // reset flag value
1316 m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1318 // set visible area before applying
1319 // information from print preview. Otherwise, the applied information
1320 // is lost.
1321 // os: changed: The user data has to be read if the view is switched back from page preview
1322 // go to the last editing position when opening own files
1323 if(m_bOldShellWasPagePreview || bIsOwnDocument )
1325 if ( bBrowse )
1326 SetVisArea( aVis.TopLeft() );
1327 else
1328 SetVisArea( aVis );
1331 //apply information from print preview - if available
1332 if( !m_sNewCursorPos.isEmpty() )
1334 sal_Int32 nIdx{ 0 };
1335 const tools::Long nXTmp = o3tl::toInt32(o3tl::getToken(m_sNewCursorPos, 0, ';', nIdx ));
1336 const tools::Long nYTmp = o3tl::toInt32(o3tl::getToken(m_sNewCursorPos, 0, ';', nIdx ));
1337 Point aCursorPos2( nXTmp, nYTmp );
1338 bSelectObj = m_pWrtShell->IsObjSelectable( aCursorPos2 );
1340 m_pWrtShell->SwCursorShell::SetCursor( aCursorPos2 );
1341 if( bSelectObj )
1343 m_pWrtShell->SelectObj( aCursorPos2 );
1344 m_pWrtShell->EnterSelFrameMode( &aCursorPos2 );
1346 m_pWrtShell->MakeSelVisible();
1347 m_sNewCursorPos.clear();
1349 else if(USHRT_MAX != m_nNewPage)
1351 m_pWrtShell->GotoPage(m_nNewPage, true);
1352 m_nNewPage = USHRT_MAX;
1355 SelectShell();
1357 m_pWrtShell->StartAction();
1358 const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1359 if( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom )
1360 SetZoom( eZoom, nZoomFactor);
1362 m_pWrtShell->LockView( true );
1363 m_pWrtShell->EndAction();
1364 m_pWrtShell->LockView( false );
1365 m_pWrtShell->EnableSmooth( true );
1368 void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence )
1370 if(GetDocShell()->IsPreview()||m_bIsPreviewDoubleClick)
1371 return;
1372 bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1374 CurrShell aCurr(m_pWrtShell.get());
1375 const SwRect& rRect = m_pWrtShell->GetCharRect();
1376 const tools::Rectangle &rVis = GetVisArea();
1377 const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1379 sal_Int64 nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top();
1380 sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType());
1381 sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom());
1382 bool bViewLayoutBookMode = pVOpt->IsViewLayoutBookMode();
1383 sal_Int16 nViewLayoutColumns = pVOpt->GetViewLayoutColumns();
1385 bool bSelectedFrame = ( m_pWrtShell->GetSelFrameType() != FrameTypeFlags::NONE ),
1386 bGotVisibleLeft = false,
1387 bGotVisibleTop = false,
1388 bGotZoomType = false,
1389 bGotZoomFactor = false, bGotIsSelectedFrame = false,
1390 bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false,
1391 bBrowseMode = false, bGotBrowseMode = false;
1392 bool bKeepRatio = pVOpt->IsKeepRatio();
1393 bool bGotKeepRatio = false;
1395 for (const beans::PropertyValue& rValue : rSequence)
1397 if ( rValue.Name == "ViewLeft" )
1399 rValue.Value >>= nX;
1400 nX = o3tl::toTwips(nX, o3tl::Length::mm100);
1402 else if ( rValue.Name == "ViewTop" )
1404 rValue.Value >>= nY;
1405 nY = o3tl::toTwips(nY, o3tl::Length::mm100);
1407 else if ( rValue.Name == "VisibleLeft" )
1409 rValue.Value >>= nLeft;
1410 nLeft = o3tl::toTwips(nLeft, o3tl::Length::mm100);
1411 bGotVisibleLeft = true;
1413 else if ( rValue.Name == "VisibleTop" )
1415 rValue.Value >>= nTop;
1416 nTop = o3tl::toTwips(nTop, o3tl::Length::mm100);
1417 bGotVisibleTop = true;
1419 else if ( rValue.Name == "ZoomType" )
1421 rValue.Value >>= nZoomType;
1422 bGotZoomType = true;
1424 else if ( rValue.Name == "ZoomFactor" )
1426 rValue.Value >>= nZoomFactor;
1427 bGotZoomFactor = true;
1429 else if ( rValue.Name == "ViewLayoutColumns" )
1431 rValue.Value >>= nViewLayoutColumns;
1432 bGotViewLayoutColumns = true;
1434 else if ( rValue.Name == "ViewLayoutBookMode" )
1436 bViewLayoutBookMode = *o3tl::doAccess<bool>(rValue.Value);
1437 bGotViewLayoutBookMode = true;
1439 else if ( rValue.Name == "IsSelectedFrame" )
1441 rValue.Value >>= bSelectedFrame;
1442 bGotIsSelectedFrame = true;
1444 else if (rValue.Name == "ShowOnlineLayout")
1446 rValue.Value >>= bBrowseMode;
1447 bGotBrowseMode = true;
1449 else if (rValue.Name == "KeepRatio")
1451 rValue.Value >>= bKeepRatio;
1452 bGotKeepRatio = true;
1454 // Fallback to common SdrModel processing
1455 else
1456 GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->ReadUserDataSequenceValue(&rValue);
1458 if (bGotBrowseMode)
1460 // delegate further
1461 GetViewImpl()->GetUNOObject_Impl()->getViewSettings()->setPropertyValue("ShowOnlineLayout", uno::Any(bBrowseMode));
1464 SelectShell();
1466 Point aCursorPos( nX, nY );
1468 m_pWrtShell->EnableSmooth( false );
1470 SvxZoomType eZoom;
1471 if ( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1472 eZoom = static_cast < SvxZoomType > ( nZoomType );
1473 else
1475 eZoom = SvxZoomType::PERCENT;
1477 if (bGotIsSelectedFrame)
1479 bool bSelectObj = bSelectedFrame && m_pWrtShell->IsObjSelectable( aCursorPos );
1481 // set flag value to avoid macro execution.
1482 bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1483 m_pWrtShell->SetMacroExecAllowed( false );
1484 // os: changed: The user data has to be read if the view is switched back from page preview
1485 // go to the last editing position when opening own files
1486 m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj);
1487 if(m_bOldShellWasPagePreview|| bIsOwnDocument)
1489 m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj );
1491 // Update the shell to toggle Header/Footer edit if needed
1492 bool bInHeader = true;
1493 if ( m_pWrtShell->IsInHeaderFooter( &bInHeader ) )
1495 if ( !bInHeader )
1497 m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, true );
1498 m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, false );
1500 else
1502 m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, true );
1503 m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, false );
1506 // Force repaint
1507 m_pWrtShell->GetWin()->Invalidate();
1509 if ( m_pWrtShell->IsInHeaderFooter() != m_pWrtShell->IsHeaderFooterEdit() )
1510 m_pWrtShell->ToggleHeaderFooterEdit();
1512 if( bSelectObj )
1514 m_pWrtShell->SelectObj( aCursorPos );
1515 m_pWrtShell->EnterSelFrameMode( &aCursorPos );
1519 // reset flag value
1520 m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1523 if (bGotKeepRatio && bKeepRatio != pVOpt->IsKeepRatio())
1525 // Got a custom value, then it makes sense to trigger notifications.
1526 SwViewOption aUsrPref(*pVOpt);
1527 aUsrPref.SetKeepRatio(bKeepRatio);
1528 SW_MOD()->ApplyUsrPref(aUsrPref, this);
1531 // Set ViewLayoutSettings
1532 const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
1533 ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
1535 const bool bSetViewSettings = bGotZoomType && bGotZoomFactor &&
1536 ( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom );
1538 // In case we have a 'fixed' view layout of 2 or more columns,
1539 // we have to apply the view options *before* starting the action.
1540 // Otherwise the SetZoom function cannot work correctly, because
1541 // the view layout hasn't been calculated.
1542 const bool bZoomNeedsViewLayout = bSetViewLayoutSettings &&
1543 1 < nViewLayoutColumns &&
1544 bSetViewSettings &&
1545 eZoom != SvxZoomType::PERCENT;
1547 if ( !bZoomNeedsViewLayout )
1548 m_pWrtShell->StartAction();
1550 if ( bSetViewLayoutSettings )
1551 SetViewLayout( nViewLayoutColumns, bViewLayoutBookMode, true );
1553 if ( bZoomNeedsViewLayout )
1554 m_pWrtShell->StartAction();
1556 if ( bSetViewSettings )
1557 SetZoom( eZoom, nZoomFactor, true );
1559 // os: changed: The user data has to be read if the view is switched back from page preview
1560 // go to the last editing position when opening own files
1561 if(m_bOldShellWasPagePreview||bIsOwnDocument)
1563 if ( bGotVisibleLeft && bGotVisibleTop )
1565 Point aTopLeft(nLeft, nTop);
1566 // make sure the document is still centered
1567 const SwTwips lBorder = IsDocumentBorder() ? DOCUMENTBORDER : 2 * DOCUMENTBORDER;
1568 SwTwips nEditWidth = GetEditWin().GetOutDev()->GetOutputSize().Width();
1569 if(nEditWidth > (m_aDocSz.Width() + lBorder ))
1570 aTopLeft.setX( ( m_aDocSz.Width() + lBorder - nEditWidth ) / 2 );
1571 else
1573 //check if the values are possible
1574 tools::Long nXMax = m_pHScrollbar->GetRangeMax() - m_pHScrollbar->GetVisibleSize();
1575 if( aTopLeft.X() > nXMax )
1576 aTopLeft.setX( nXMax < 0 ? 0 : nXMax );
1578 SetVisArea( aTopLeft );
1582 m_pWrtShell->LockView( true );
1583 m_pWrtShell->EndAction();
1584 m_pWrtShell->LockView( false );
1585 m_pWrtShell->EnableSmooth( true );
1589 void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSequence )
1591 const SwRect& rRect = m_pWrtShell->GetCharRect();
1592 const tools::Rectangle& rVis = GetVisArea();
1594 std::vector<beans::PropertyValue> aVector;
1596 sal_uInt16 nViewID( GetViewFrame().GetCurViewId());
1597 aVector.push_back(comphelper::makePropertyValue("ViewId", "view" + OUString::number(nViewID)));
1599 aVector.push_back(comphelper::makePropertyValue("ViewLeft", convertTwipToMm100 ( rRect.Left() )));
1601 aVector.push_back(comphelper::makePropertyValue("ViewTop", convertTwipToMm100 ( rRect.Top() )));
1603 auto visibleLeft = convertTwipToMm100 ( rVis.Left() );
1604 aVector.push_back(comphelper::makePropertyValue("VisibleLeft", visibleLeft));
1606 auto visibleTop = convertTwipToMm100 ( rVis.Top() );
1607 aVector.push_back(comphelper::makePropertyValue("VisibleTop", visibleTop));
1609 // We don't read VisibleRight and VisibleBottom anymore, but write them,
1610 // because older versions rely on their presence to restore position
1612 auto visibleRight = rVis.IsWidthEmpty() ? visibleLeft : convertTwipToMm100 ( rVis.Right() );
1613 aVector.push_back(comphelper::makePropertyValue("VisibleRight", visibleRight));
1615 auto visibleBottom = rVis.IsHeightEmpty() ? visibleTop : convertTwipToMm100 ( rVis.Bottom() );
1616 aVector.push_back(comphelper::makePropertyValue("VisibleBottom", visibleBottom));
1618 const sal_Int16 nZoomType = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetZoomType());
1619 aVector.push_back(comphelper::makePropertyValue("ZoomType", nZoomType));
1621 const sal_Int16 nViewLayoutColumns = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetViewLayoutColumns());
1622 aVector.push_back(comphelper::makePropertyValue("ViewLayoutColumns", nViewLayoutColumns));
1624 aVector.push_back(comphelper::makePropertyValue("ViewLayoutBookMode", m_pWrtShell->GetViewOptions()->IsViewLayoutBookMode()));
1626 aVector.push_back(comphelper::makePropertyValue("ZoomFactor", static_cast < sal_Int16 > (m_pWrtShell->GetViewOptions()->GetZoom())));
1628 aVector.push_back(comphelper::makePropertyValue("IsSelectedFrame", FrameTypeFlags::NONE != m_pWrtShell->GetSelFrameType()));
1630 aVector.push_back(
1631 comphelper::makePropertyValue("KeepRatio", m_pWrtShell->GetViewOptions()->IsKeepRatio()));
1633 rSequence = comphelper::containerToSequence(aVector);
1635 // Common SdrModel processing
1636 GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->WriteUserDataSequence(rSequence);
1639 void SwView::ShowCursor( bool bOn )
1641 //don't scroll the cursor into the visible area
1642 bool bUnlockView = !m_pWrtShell->IsViewLocked();
1643 m_pWrtShell->LockView( true ); //lock visible section
1645 if( !bOn )
1646 m_pWrtShell->HideCursor();
1647 else if( !m_pWrtShell->IsFrameSelected() && !m_pWrtShell->IsObjSelected() )
1648 m_pWrtShell->ShowCursor();
1650 if( bUnlockView )
1651 m_pWrtShell->LockView( false );
1654 ErrCode SwView::DoVerb(sal_Int32 nVerb)
1656 if ( !GetViewFrame().GetFrame().IsInPlace() )
1658 SwWrtShell &rSh = GetWrtShell();
1659 const SelectionType nSel = rSh.GetSelectionType();
1660 if ( nSel & SelectionType::Ole )
1661 rSh.LaunchOLEObj( nVerb );
1663 return ERRCODE_NONE;
1666 // only return true for a text selection
1668 bool SwView::HasSelection( bool bText ) const
1670 return bText ? GetWrtShell().SwCursorShell::HasSelection()
1671 : GetWrtShell().HasSelection();
1674 OUString SwView::GetSelectionText( bool bCompleteWrds, bool /*bOnlyASample*/ )
1676 return GetSelectionTextParam( bCompleteWrds, true );
1679 OUString SwView::GetSelectionTextParam( bool bCompleteWrds, bool bEraseTrail )
1681 OUString sReturn;
1682 if( bCompleteWrds && !GetWrtShell().HasSelection() )
1683 GetWrtShell().SelWrd();
1685 GetWrtShell().GetSelectedText( sReturn );
1686 if( bEraseTrail )
1687 sReturn = comphelper::string::stripEnd(sReturn, ' ');
1688 return sReturn;
1691 SwGlossaryHdl* SwView::GetGlosHdl()
1693 if(!m_pGlosHdl)
1694 m_pGlosHdl.reset(new SwGlossaryHdl(GetViewFrame(), m_pWrtShell.get()));
1695 return m_pGlosHdl.get();
1698 void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1700 bool bCallBase = true;
1701 if(auto pChangedHint = dynamic_cast<const FmDesignModeChangedHint*>(&rHint))
1703 bool bDesignMode = pChangedHint->GetDesignMode();
1704 if (!bDesignMode && GetDrawFuncPtr())
1706 GetDrawFuncPtr()->Deactivate();
1707 SetDrawFuncPtr(nullptr);
1708 LeaveDrawCreate();
1709 AttrChangedNotify(nullptr);
1712 else
1714 SfxHintId nId = rHint.GetId();
1716 switch ( nId )
1718 // sub shells will be destroyed by the
1719 // dispatcher, if the view frame is dying. Thus, reset member <pShell>.
1720 case SfxHintId::Dying:
1722 if ( &rBC == &GetViewFrame() )
1724 ResetSubShell();
1727 break;
1728 case SfxHintId::ModeChanged:
1730 // Modal mode change-over?
1731 bool bModal = GetDocShell()->IsInModalMode();
1732 m_pHRuler->SetActive( !bModal );
1733 m_pVRuler->SetActive( !bModal );
1736 [[fallthrough]];
1738 case SfxHintId::TitleChanged:
1739 if ( GetDocShell()->IsReadOnly() != GetWrtShell().GetViewOptions()->IsReadonly() )
1741 SwWrtShell &rSh = GetWrtShell();
1742 rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
1744 if ( rSh.GetViewOptions()->IsViewVRuler() )
1745 CreateVRuler();
1746 else
1747 KillVRuler();
1748 if ( rSh.GetViewOptions()->IsViewHRuler() )
1749 CreateTab();
1750 else
1751 KillTab();
1752 bool bReadonly = GetDocShell()->IsReadOnly();
1753 // if document is to be opened in alive-mode then this has to be
1754 // regarded while switching from readonly-mode to edit-mode
1755 if( !bReadonly )
1757 SwDrawModel * pDrawDoc = GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
1758 if (pDrawDoc)
1760 if( !pDrawDoc->GetOpenInDesignMode() )
1761 break;// don't touch the design mode
1764 SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
1765 GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
1766 SfxCallMode::ASYNCHRON, { &aItem });
1768 break;
1770 case SfxHintId::SwDrawViewsCreated:
1772 bCallBase = false;
1773 if ( GetFormShell() )
1775 GetFormShell()->SetView(dynamic_cast<FmFormView*>(GetWrtShell().GetDrawView()));
1776 SfxBoolItem aItem( SID_FM_DESIGN_MODE, !GetDocShell()->IsReadOnly());
1777 GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
1778 SfxCallMode::SYNCHRON, { &aItem });
1781 break;
1782 case SfxHintId::RedlineChanged:
1784 static sal_uInt16 const aSlotRedLine[] = {
1785 FN_REDLINE_ACCEPT_DIRECT,
1786 FN_REDLINE_REJECT_DIRECT,
1787 FN_REDLINE_NEXT_CHANGE,
1788 FN_REDLINE_PREV_CHANGE,
1789 FN_REDLINE_ACCEPT_ALL,
1790 FN_REDLINE_REJECT_ALL,
1793 GetViewFrame().GetBindings().Invalidate(aSlotRedLine);
1795 break;
1796 default: break;
1800 if ( bCallBase )
1801 SfxViewShell::Notify(rBC, rHint);
1804 #if defined(_WIN32) || defined UNX
1806 void SwView::ScannerEventHdl()
1808 uno::Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
1809 if( xScanMgr.is() )
1811 const ScannerContext aContext( xScanMgr->getAvailableScanners().getConstArray()[ 0 ] );
1812 const ScanError eError = xScanMgr->getError( aContext );
1814 if( ScanError_ScanErrorNone == eError )
1816 const uno::Reference< awt::XBitmap > xBitmap( xScanMgr->getBitmap( aContext ) );
1818 if( xBitmap.is() )
1820 const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
1822 if( !aScanBmp.IsEmpty() )
1824 Graphic aGrf(aScanBmp);
1825 m_pWrtShell->InsertGraphic( OUString(), OUString(), aGrf );
1830 SfxBindings& rBind = GetViewFrame().GetBindings();
1831 rBind.Invalidate( SID_TWAIN_SELECT );
1832 rBind.Invalidate( SID_TWAIN_TRANSFER );
1834 #endif
1836 void SwView::StopShellTimer()
1838 if(m_aTimer.IsActive())
1840 m_aTimer.Stop();
1841 if ( m_bAttrChgNotifiedWithRegistrations )
1843 GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1844 m_bAttrChgNotifiedWithRegistrations = false;
1846 SelectShell();
1847 m_bAttrChgNotified = false;
1851 bool SwView::PrepareClose( bool bUI )
1853 SfxViewFrame& rVFrame = GetViewFrame();
1854 rVFrame.SetChildWindow( SwInputChild::GetChildWindowId(), false );
1855 if( rVFrame.GetDispatcher()->IsLocked() )
1856 rVFrame.GetDispatcher()->Lock(false);
1858 if ( m_pFormShell && !m_pFormShell->PrepareClose( bUI ) )
1860 return false;
1862 return SfxViewShell::PrepareClose( bUI );
1865 // status methods for clipboard.
1866 // Status changes now notified from the clipboard.
1867 bool SwView::IsPasteAllowed()
1869 SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1870 if( m_nLastPasteDestination != nPasteDestination )
1872 TransferableDataHelper aDataHelper(
1873 TransferableDataHelper::CreateFromSystemClipboard(
1874 &GetEditWin()) );
1875 if( aDataHelper.GetXTransferable().is() )
1877 m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1878 m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1879 *m_pWrtShell, aDataHelper );
1881 else
1882 m_bPasteState = m_bPasteSpecialState = false;
1884 if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value
1885 m_pViewImpl->AddClipboardListener();
1886 m_nLastPasteDestination = nPasteDestination;
1888 return m_bPasteState;
1891 bool SwView::IsPasteSpecialAllowed()
1893 if ( m_pFormShell && m_pFormShell->IsActiveControl() )
1894 return false;
1896 SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1897 if( m_nLastPasteDestination != nPasteDestination )
1899 TransferableDataHelper aDataHelper(
1900 TransferableDataHelper::CreateFromSystemClipboard(
1901 &GetEditWin()) );
1902 if( aDataHelper.GetXTransferable().is() )
1904 m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1905 m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1906 *m_pWrtShell, aDataHelper );
1908 else
1909 m_bPasteState = m_bPasteSpecialState = false;
1911 if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value
1912 m_pViewImpl->AddClipboardListener();
1914 return m_bPasteSpecialState;
1917 bool SwView::IsPasteSpreadsheet(bool bHasOwnTableCopied)
1919 TransferableDataHelper aDataHelper(
1920 TransferableDataHelper::CreateFromSystemClipboard(
1921 &GetEditWin()) );
1922 if( aDataHelper.GetXTransferable().is() )
1924 if (bHasOwnTableCopied && SwTransferable::IsPasteOwnFormat( aDataHelper ))
1925 return true;
1926 return aDataHelper.HasFormat( SotClipboardFormatId::SYLK ) || aDataHelper.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS );
1928 return false;
1931 void SwView::NotifyDBChanged()
1933 GetViewImpl()->GetUNOObject_Impl()->NotifyDBChanged();
1936 // Printing
1938 SfxObjectShellLock SwView::CreateTmpSelectionDoc()
1940 SwXTextView *const pTempImpl = GetViewImpl()->GetUNOObject_Impl();
1941 return pTempImpl->BuildTmpSelectionDoc();
1944 void SwView::AddTransferable(SwTransferable& rTransferable)
1946 GetViewImpl()->AddTransferable(rTransferable);
1949 tools::Rectangle SwView::getLOKVisibleArea() const
1951 if (SwViewShell* pVwSh = GetWrtShellPtr())
1952 return pVwSh->getLOKVisibleArea();
1953 else
1954 return tools::Rectangle();
1957 void SwView::flushPendingLOKInvalidateTiles()
1959 if (SwWrtShell* pSh = GetWrtShellPtr())
1960 pSh->FlushPendingLOKInvalidateTiles();
1963 std::optional<OString> SwView::getLOKPayload(int nType, int nViewId) const
1965 if (SwWrtShell* pSh = GetWrtShellPtr())
1966 return pSh->getLOKPayload(nType, nViewId);
1967 else
1968 return std::nullopt;
1971 OUString SwView::GetDataSourceName() const
1973 uno::Reference<lang::XMultiServiceFactory> xFactory(GetDocShell()->GetModel(), uno::UNO_QUERY);
1974 uno::Reference<beans::XPropertySet> xSettings(
1975 xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
1976 OUString sDataSourceName = "";
1977 xSettings->getPropertyValue("CurrentDatabaseDataSource") >>= sDataSourceName;
1979 return sDataSourceName;
1982 bool SwView::IsDataSourceAvailable(const OUString sDataSourceName)
1984 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1985 Reference< XDatabaseContext> xDatabaseContext = DatabaseContext::create(xContext);
1987 return xDatabaseContext->hasByName(sDataSourceName);
1990 namespace sw {
1992 void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)
1994 o_rData = *SW_MOD()->GetPrtOptions(bWeb);
1997 } // namespace sw
1999 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */