Line data Source code
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 <string>
23 : #include <stdlib.h>
24 : #include <hintids.hxx>
25 : #include <comphelper/string.hxx>
26 : #include <officecfg/Office/Common.hxx>
27 : #include <vcl/graph.hxx>
28 : #include <vcl/inputctx.hxx>
29 : #include <basic/sbxobj.hxx>
30 : #include <svl/eitem.hxx>
31 : #include <unotools/lingucfg.hxx>
32 : #include <unotools/useroptions.hxx>
33 : #include <sfx2/dispatch.hxx>
34 : #include <sfx2/request.hxx>
35 : #include <sfx2/docfile.hxx>
36 : #include <sfx2/printer.hxx>
37 : #include <sfx2/app.hxx>
38 : #include <svx/ruler.hxx>
39 : #include <svx/srchdlg.hxx>
40 : #include <editeng/protitem.hxx>
41 : #include <svx/fmshell.hxx>
42 : #include <svx/extrusionbar.hxx>
43 : #include <svx/fontworkbar.hxx>
44 : #include <unotxvw.hxx>
45 : #include <cmdid.h>
46 : #include <swhints.hxx>
47 : #include <swmodule.hxx>
48 : #include <inputwin.hxx>
49 : #include <chartins.hxx>
50 : #include <uivwimp.hxx>
51 : #include <uitool.hxx>
52 : #include <edtwin.hxx>
53 : #include <textsh.hxx>
54 : #include <listsh.hxx>
55 : #include <tabsh.hxx>
56 : #include <grfsh.hxx>
57 : #include <mediash.hxx>
58 : #include <docsh.hxx>
59 : #include <frmsh.hxx>
60 : #include <olesh.hxx>
61 : #include <drawsh.hxx>
62 : #include <drawbase.hxx>
63 : #include <drformsh.hxx>
64 : #include <drwtxtsh.hxx>
65 : #include <beziersh.hxx>
66 : #include <navsh.hxx>
67 : #include <globdoc.hxx>
68 : #include <scroll.hxx>
69 : #include <navipi.hxx>
70 : #include <gloshdl.hxx>
71 : #include <usrpref.hxx>
72 : #include <srcview.hxx>
73 : #include <doc.hxx>
74 : #include <IDocumentUndoRedo.hxx>
75 : #include <IDocumentSettingAccess.hxx>
76 : #include <IDocumentDrawModelAccess.hxx>
77 : #include <DocumentFieldsManager.hxx>
78 : #include <IDocumentState.hxx>
79 : #include <IDocumentLayoutAccess.hxx>
80 : #include <drawdoc.hxx>
81 : #include <wdocsh.hxx>
82 : #include <wview.hxx>
83 : #include <workctrl.hxx>
84 : #include <wrtsh.hxx>
85 : #include <barcfg.hxx>
86 : #include <pview.hxx>
87 : #include <swdtflvr.hxx>
88 : #include <view.hrc>
89 : #include <globdoc.hrc>
90 : #include <frmui.hrc>
91 : #include <cfgitems.hxx>
92 : #include <prtopt.hxx>
93 : #include <linguistic/lngprops.hxx>
94 : #include <editeng/unolingu.hxx>
95 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
96 : #include <com/sun/star/scanner/ScannerContext.hpp>
97 : #include <com/sun/star/scanner/XScannerManager2.hpp>
98 : #include <toolkit/helper/vclunohelper.hxx>
99 : #include <rtl/ustrbuf.hxx>
100 : #include <sax/tools/converter.hxx>
101 :
102 : #include "formatclipboard.hxx"
103 : #include <PostItMgr.hxx>
104 : #include <annotsh.hxx>
105 : #include <swruler.hxx>
106 :
107 : #include <fldbas.hxx>
108 :
109 : #include <unomid.h>
110 :
111 : #include <com/sun/star/document/XDocumentProperties.hpp>
112 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
113 :
114 : #include <svl/cjkoptions.hxx>
115 :
116 : using namespace ::com::sun::star;
117 : using namespace ::com::sun::star::uno;
118 : using namespace ::com::sun::star::lang;
119 : using namespace ::com::sun::star::scanner;
120 :
121 : extern bool g_bNoInterrupt; // in swmodule.cxx
122 :
123 : #define SWVIEWFLAGS ( SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::HAS_PRINTOPTIONS)
124 :
125 : // Statics. OMG.
126 :
127 : bool bDocSzUpdated = true;
128 :
129 : SvxSearchItem* SwView::m_pSrchItem = 0;
130 :
131 : sal_uInt16 SwView::m_nInsertCtrlState = FN_INSERT_TABLE;
132 : sal_uInt16 SwView::m_nWebInsertCtrlState = FN_INSERT_TABLE;
133 : sal_uInt16 SwView::m_nInsertObjectCtrlState = SID_INSERT_DIAGRAM;
134 :
135 : bool SwView::m_bExtra = false;
136 : bool SwView::m_bFound = false;
137 : bool SwView::m_bJustOpened = false;
138 :
139 59 : VclPtr<SvxSearchDialog> SwView::m_pSrchDlg = nullptr;
140 : SearchAttrItemList* SwView::m_pSrchList = 0;
141 : SearchAttrItemList* SwView::m_pReplList = 0;
142 :
143 29666 : inline SfxDispatcher &SwView::GetDispatcher()
144 : {
145 29666 : return *GetViewFrame()->GetDispatcher();
146 : }
147 :
148 2778 : void SwView::ImpSetVerb( int nSelType )
149 : {
150 2778 : bool bResetVerbs = m_bVerbsActive;
151 5556 : if ( !GetViewFrame()->GetFrame().IsInPlace() &&
152 2778 : (nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF) & nSelType )
153 : {
154 0 : if ( m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE )
155 : {
156 0 : if ( nSelType & nsSelectionType::SEL_OLE )
157 : {
158 0 : SetVerbs( GetWrtShell().GetOLEObject()->getSupportedVerbs() );
159 0 : m_bVerbsActive = true;
160 0 : bResetVerbs = false;
161 : }
162 : }
163 : }
164 2778 : if ( bResetVerbs )
165 : {
166 0 : SetVerbs( Sequence< embed::VerbDescriptor >() );
167 0 : m_bVerbsActive = false;
168 : }
169 2778 : }
170 :
171 : // Called by the SwEditWin when it gets the focus.
172 :
173 2466 : void SwView::GotFocus() const
174 : {
175 : // if we got the focus, and the form shell *is* on the top of the dispatcher
176 : // stack, then we need to rebuild the stack (the form shell doesn't belong to
177 : // the top then)
178 2466 : const SfxDispatcher& rDispatcher = const_cast< SwView* >( this )->GetDispatcher();
179 2466 : SfxShell* pTopShell = rDispatcher.GetShell( 0 );
180 2466 : FmFormShell* pAsFormShell = PTR_CAST( FmFormShell, pTopShell );
181 2466 : if ( pAsFormShell )
182 : {
183 0 : pAsFormShell->ForgetActiveControl();
184 0 : const_cast< SwView* >( this )->AttrChangedNotify( m_pWrtShell );
185 : }
186 2466 : else if ( m_pPostItMgr )
187 : {
188 2466 : SwAnnotationShell* pAsAnnotationShell = PTR_CAST( SwAnnotationShell, pTopShell );
189 2466 : if ( pAsAnnotationShell )
190 : {
191 0 : m_pPostItMgr->SetActiveSidebarWin(0);
192 0 : const_cast< SwView* >( this )->AttrChangedNotify( m_pWrtShell );
193 : }
194 : }
195 2466 : if( GetWrtShellPtr() )
196 : {
197 2466 : SwWrtShell& rWrtShell = GetWrtShell();
198 2466 : rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( GetWrtShellPtr() );
199 2466 : rWrtShell.GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::BROWSE_MODE,
200 2466 : rWrtShell.GetViewOptions()->getBrowseMode() );
201 : }
202 2466 : }
203 :
204 : // called by the FormShell when a form control is focused. This is
205 : // a request to put the form shell on the top of the dispatcher stack
206 :
207 2 : IMPL_LINK_NOARG(SwView, FormControlActivated)
208 : {
209 : // if a form control has been activated, and the form shell is not on the top
210 : // of the dispatcher stack, then we need to activate it
211 1 : const SfxDispatcher& rDispatcher = GetDispatcher();
212 1 : const SfxShell* pTopShell = rDispatcher.GetShell( 0 );
213 1 : const FmFormShell* pAsFormShell = PTR_CAST( FmFormShell, pTopShell );
214 1 : if ( !pAsFormShell )
215 : {
216 : // if we're editing text currently, cancel this
217 1 : SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : NULL;
218 1 : if ( pSdrView && pSdrView->IsTextEdit() )
219 0 : pSdrView->SdrEndTextEdit( true );
220 :
221 1 : AttrChangedNotify( m_pWrtShell );
222 : }
223 :
224 1 : return 0L;
225 : }
226 :
227 14447 : void SwView::SelectShell()
228 : {
229 : // Attention: Maintain the SelectShell for the WebView additionally
230 :
231 14447 : if(m_bInDtor)
232 14447 : return;
233 :
234 : // Decision if the UpdateTable has to be called
235 14447 : bool bUpdateTable = false;
236 14447 : const SwFrameFormat* pCurTableFormat = m_pWrtShell->GetTableFormat();
237 14447 : if(pCurTableFormat && pCurTableFormat != m_pLastTableFormat)
238 : {
239 215 : bUpdateTable = true; // can only be executed later
240 : }
241 14447 : m_pLastTableFormat = pCurTableFormat;
242 :
243 : //SEL_TBL and SEL_TBL_CELLS can be ORed!
244 14447 : int nNewSelectionType = (m_pWrtShell->GetSelectionType()
245 14447 : & ~nsSelectionType::SEL_TBL_CELLS);
246 :
247 14447 : if ( m_pFormShell && m_pFormShell->IsActiveControl() )
248 1 : nNewSelectionType |= nsSelectionType::SEL_FOC_FRM_CTRL;
249 :
250 14447 : if ( nNewSelectionType == m_nSelectionType )
251 : {
252 11671 : GetViewFrame()->GetBindings().InvalidateAll( false );
253 23342 : if ( m_nSelectionType & nsSelectionType::SEL_OLE ||
254 11671 : m_nSelectionType & nsSelectionType::SEL_GRF )
255 : // For graphs and OLE the verb can be modified of course!
256 0 : ImpSetVerb( nNewSelectionType );
257 : }
258 : else
259 : {
260 :
261 2776 : SfxDispatcher &rDispatcher = GetDispatcher();
262 2776 : SwToolbarConfigItem *pBarCfg = SW_MOD()->GetToolbarConfig();
263 :
264 2776 : if ( m_pShell )
265 : {
266 24 : rDispatcher.Flush(); // Really erase all cached shells
267 : //Remember to the old selection which toolbar was visible
268 24 : sal_uInt16 nId = static_cast< sal_uInt16 >( rDispatcher.GetObjectBarId( SFX_OBJECTBAR_OBJECT ));
269 24 : if ( nId )
270 23 : pBarCfg->SetTopToolbar( m_nSelectionType, nId );
271 :
272 105 : for ( sal_uInt16 i = 0; true; ++i )
273 : {
274 105 : SfxShell *pSfxShell = rDispatcher.GetShell( i );
275 210 : if ( pSfxShell->ISA( SwBaseShell )
276 48 : || pSfxShell->ISA( SwDrawTextShell )
277 48 : || pSfxShell->ISA( svx::ExtrusionBar )
278 48 : || pSfxShell->ISA( svx::FontworkBar )
279 153 : || pSfxShell->ISA( SwAnnotationShell )
280 : )
281 : {
282 57 : rDispatcher.Pop( *pSfxShell, SfxDispatcherPopFlags::POP_DELETE );
283 : }
284 48 : else if ( pSfxShell->ISA( FmFormShell ) )
285 : {
286 24 : rDispatcher.Pop( *pSfxShell );
287 : }
288 : else
289 24 : break;
290 81 : }
291 : }
292 :
293 2776 : bool bInitFormShell = false;
294 2776 : if (!m_pFormShell)
295 : {
296 2752 : bInitFormShell = true;
297 2752 : m_pFormShell = new FmFormShell( this );
298 2752 : m_pFormShell->SetControlActivationHandler( LINK( this, SwView, FormControlActivated ) );
299 2752 : StartListening(*m_pFormShell);
300 : }
301 :
302 2776 : bool bSetExtInpCntxt = false;
303 2776 : m_nSelectionType = nNewSelectionType;
304 : ShellModes eShellMode;
305 :
306 2776 : if ( !( m_nSelectionType & nsSelectionType::SEL_FOC_FRM_CTRL ) )
307 2775 : rDispatcher.Push( *m_pFormShell );
308 :
309 2776 : eShellMode = SHELL_MODE_NAVIGATION;
310 2776 : m_pShell = new SwNavigationShell( *this );
311 2776 : rDispatcher.Push( *m_pShell );
312 :
313 2776 : if ( m_nSelectionType & nsSelectionType::SEL_OLE )
314 : {
315 0 : eShellMode = SHELL_MODE_OBJECT;
316 0 : m_pShell = new SwOleShell( *this );
317 0 : rDispatcher.Push( *m_pShell );
318 : }
319 2776 : else if ( m_nSelectionType & nsSelectionType::SEL_FRM
320 2776 : || m_nSelectionType & nsSelectionType::SEL_GRF)
321 : {
322 0 : eShellMode = SHELL_MODE_FRAME;
323 0 : m_pShell = new SwFrameShell( *this );
324 0 : rDispatcher.Push( *m_pShell );
325 0 : if(m_nSelectionType & nsSelectionType::SEL_GRF )
326 : {
327 0 : eShellMode = SHELL_MODE_GRAPHIC;
328 0 : m_pShell = new SwGrfShell( *this );
329 0 : rDispatcher.Push( *m_pShell );
330 : }
331 : }
332 2776 : else if ( m_nSelectionType & nsSelectionType::SEL_DRW )
333 : {
334 0 : eShellMode = SHELL_MODE_DRAW;
335 0 : m_pShell = new SwDrawShell( *this );
336 0 : rDispatcher.Push( *m_pShell );
337 :
338 0 : if ( m_nSelectionType & nsSelectionType::SEL_BEZ )
339 : {
340 0 : eShellMode = SHELL_MODE_BEZIER;
341 0 : m_pShell = new SwBezierShell( *this );
342 0 : rDispatcher.Push( *m_pShell );
343 : }
344 : #if HAVE_FEATURE_AVMEDIA
345 0 : else if( m_nSelectionType & nsSelectionType::SEL_MEDIA )
346 : {
347 0 : eShellMode = SHELL_MODE_MEDIA;
348 0 : m_pShell = new SwMediaShell( *this );
349 0 : rDispatcher.Push( *m_pShell );
350 : }
351 : #endif
352 0 : if (m_nSelectionType & nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE)
353 : {
354 0 : eShellMode = SHELL_MODE_EXTRUDED_CUSTOMSHAPE;
355 0 : m_pShell = new svx::ExtrusionBar(this);
356 0 : rDispatcher.Push( *m_pShell );
357 : }
358 0 : if (m_nSelectionType & nsSelectionType::SEL_FONTWORK)
359 : {
360 0 : eShellMode = SHELL_MODE_FONTWORK;
361 0 : m_pShell = new svx::FontworkBar(this);
362 0 : rDispatcher.Push( *m_pShell );
363 : }
364 : }
365 2776 : else if ( m_nSelectionType & nsSelectionType::SEL_DRW_FORM )
366 : {
367 0 : eShellMode = SHELL_MODE_DRAW_FORM;
368 0 : m_pShell = new SwDrawFormShell( *this );
369 :
370 0 : rDispatcher.Push( *m_pShell );
371 : }
372 2776 : else if ( m_nSelectionType & nsSelectionType::SEL_DRW_TXT )
373 : {
374 0 : bSetExtInpCntxt = true;
375 0 : eShellMode = SHELL_MODE_DRAWTEXT;
376 0 : rDispatcher.Push( *(new SwBaseShell( *this )) );
377 0 : m_pShell = new SwDrawTextShell( *this );
378 0 : rDispatcher.Push( *m_pShell );
379 : }
380 2776 : else if ( m_nSelectionType & nsSelectionType::SEL_POSTIT )
381 : {
382 0 : eShellMode = SHELL_MODE_POSTIT;
383 0 : m_pShell = new SwAnnotationShell( *this );
384 0 : rDispatcher.Push( *m_pShell );
385 : }
386 : else
387 : {
388 2776 : bSetExtInpCntxt = true;
389 2776 : eShellMode = SHELL_MODE_TEXT;
390 2776 : sal_uInt32 nHelpId = 0;
391 2776 : if ( m_nSelectionType & nsSelectionType::SEL_NUM )
392 : {
393 130 : eShellMode = SHELL_MODE_LIST_TEXT;
394 130 : m_pShell = new SwListShell( *this );
395 130 : nHelpId = m_pShell->GetHelpId();
396 130 : rDispatcher.Push( *m_pShell );
397 : }
398 2776 : m_pShell = new SwTextShell(*this);
399 2776 : if(nHelpId)
400 130 : m_pShell->SetHelpId(nHelpId);
401 2776 : rDispatcher.Push( *m_pShell );
402 2776 : if ( m_nSelectionType & nsSelectionType::SEL_TBL )
403 : {
404 : eShellMode = eShellMode == SHELL_MODE_LIST_TEXT ? SHELL_MODE_TABLE_LIST_TEXT
405 209 : : SHELL_MODE_TABLE_TEXT;
406 209 : m_pShell = new SwTableShell( *this );
407 209 : rDispatcher.Push( *m_pShell );
408 : }
409 : }
410 :
411 2776 : if ( m_nSelectionType & nsSelectionType::SEL_FOC_FRM_CTRL )
412 1 : rDispatcher.Push( *m_pFormShell );
413 :
414 2776 : m_pViewImpl->SetShellMode(eShellMode);
415 2776 : ImpSetVerb( m_nSelectionType );
416 :
417 2776 : if( !GetDocShell()->IsReadOnly() )
418 : {
419 2774 : if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
420 10 : bSetExtInpCntxt = false;
421 :
422 2774 : InputContext aCntxt( GetEditWin().GetInputContext() );
423 : aCntxt.SetOptions( bSetExtInpCntxt
424 : ? (aCntxt.GetOptions() |
425 : ( InputContextFlags::Text |
426 2764 : InputContextFlags::ExtText ))
427 : : (aCntxt.GetOptions() & ~
428 2794 : InputContextFlags( InputContextFlags::Text |
429 8312 : InputContextFlags::ExtText )) );
430 2774 : GetEditWin().SetInputContext( aCntxt );
431 : }
432 :
433 : // Activate the toolbar to the new selection which also was active last time.
434 : // Before a flush () must be, but does not affect the UI according to MBA and
435 : // is not a performance problem.
436 : // TODO/LATER: maybe now the Flush() command is superfluous?!
437 2776 : rDispatcher.Flush();
438 :
439 2776 : Point aPnt = GetEditWin().OutputToScreenPixel(GetEditWin().GetPointerPosPixel());
440 2776 : aPnt = GetEditWin().PixelToLogic(aPnt);
441 2776 : GetEditWin().UpdatePointer(aPnt);
442 :
443 2776 : SdrView* pDView = GetWrtShell().GetDrawView();
444 2776 : if ( bInitFormShell && pDView )
445 2752 : m_pFormShell->SetView(PTR_CAST(FmFormView, pDView));
446 :
447 : }
448 : // Opportune time for the communication with OLE objects?
449 14447 : if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
450 25 : GetDocShell()->GetDoc()->PrtOLENotify( false );
451 :
452 : // now the table-update
453 14447 : if(bUpdateTable)
454 215 : m_pWrtShell->UpdateTable();
455 :
456 14447 : GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
457 : }
458 :
459 : // Interaction: AttrChangedNotify() and TimeoutHdl.
460 : // No Update if actions are still open, since the cursor on the core side
461 : // can be somewhere in no man's land.
462 : // But since we can no longer supply status and we want instead lock
463 : // the dispatcher.
464 :
465 : extern "C"
466 : {
467 381 : static int lcl_CmpIds( const void *pFirst, const void *pSecond)
468 : {
469 381 : return *static_cast<sal_uInt16 const *>(pFirst) - *static_cast<sal_uInt16 const *>(pSecond);
470 : }
471 : }
472 :
473 21855 : IMPL_LINK_NOARG(SwView, AttrChangedNotify)
474 : {
475 12312 : if ( GetEditWin().IsChainMode() )
476 0 : GetEditWin().SetChainMode( false );
477 :
478 : //Opt: Not if PaintLocked. During unlock a notify will be once more triggered.
479 24477 : if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt &&
480 12165 : GetDocShell()->IsReadOnly() )
481 2 : _CheckReadonlyState();
482 :
483 12312 : if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt )
484 12165 : _CheckReadonlySelection();
485 :
486 12312 : if( !m_bAttrChgNotified )
487 : {
488 49053 : if ( m_pWrtShell->BasicActionPend() || g_bNoInterrupt ||
489 36297 : GetDispatcher().IsLocked() || //do not confuse the SFX
490 11775 : GetViewFrame()->GetBindings().IsInUpdate() )//do not confuse the SFX
491 : {
492 493 : m_bAttrChgNotified = true;
493 493 : m_aTimer.Start();
494 :
495 : const SfxPoolItem *pItem;
496 986 : if ( SfxItemState::SET != GetObjectShell()->GetMedium()->GetItemSet()->
497 986 : GetItemState( SID_HIDDEN, false, &pItem ) ||
498 0 : !static_cast<const SfxBoolItem*>(pItem)->GetValue() )
499 : {
500 493 : GetViewFrame()->GetBindings().ENTERREGISTRATIONS();
501 493 : m_bAttrChgNotifiedWithRegistrations = true;
502 : }
503 :
504 : }
505 : else
506 11775 : SelectShell();
507 :
508 : }
509 :
510 : // change ui if cursor is at a SwPostItField
511 12312 : if (m_pPostItMgr)
512 : {
513 : // only perform the code that is needed to determine, if at the
514 : // actual cursor position is a post-it field
515 12312 : m_pPostItMgr->SetShadowState( m_pWrtShell->GetPostItFieldAtCursor() );
516 : }
517 :
518 12312 : return 0;
519 : }
520 :
521 2 : IMPL_LINK_NOARG_TYPED(SwView, TimeoutHdl, Timer *, void)
522 : {
523 1 : if( m_pWrtShell->BasicActionPend() || g_bNoInterrupt )
524 : {
525 0 : m_aTimer.Start();
526 1 : return;
527 : }
528 :
529 1 : if ( m_bAttrChgNotifiedWithRegistrations )
530 : {
531 1 : GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
532 1 : m_bAttrChgNotifiedWithRegistrations = false;
533 : }
534 :
535 1 : _CheckReadonlyState();
536 1 : _CheckReadonlySelection();
537 :
538 1 : bool bOldUndo = m_pWrtShell->DoesUndo();
539 1 : m_pWrtShell->DoUndo( false );
540 1 : SelectShell();
541 1 : m_pWrtShell->DoUndo( bOldUndo );
542 1 : m_bAttrChgNotified = false;
543 1 : GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
544 : }
545 :
546 3 : void SwView::_CheckReadonlyState()
547 : {
548 3 : SfxDispatcher &rDis = GetDispatcher();
549 : // To be able to recognize if it is already disabled!
550 : SfxItemState eStateRO, eStateProtAll;
551 : const SfxPoolItem *pItem;
552 : // Query the status from a slot which is only known to us.
553 : // Otherwise the slot is known from other; like the BasidIde
554 3 : eStateRO = rDis.QueryState( FN_INSERT_BOOKMARK, pItem );
555 3 : eStateProtAll = rDis.QueryState( FN_EDIT_REGION, pItem );
556 3 : bool bChgd = false;
557 :
558 3 : if ( !m_pWrtShell->IsCrsrReadonly() )
559 : {
560 : static sal_uInt16 aROIds[] =
561 : {
562 : SID_DELETE, FN_BACKSPACE, FN_SHIFT_BACKSPACE,
563 : SID_UNDO,
564 : SID_REDO, SID_REPEAT, SID_PASTE,
565 : SID_PASTE_UNFORMATTED,
566 : SID_PASTE_SPECIAL, SID_SBA_BRW_INSERT,
567 : SID_BACKGROUND_COLOR, FN_INSERT_BOOKMARK,
568 : SID_CHARMAP, FN_INSERT_SOFT_HYPHEN,
569 : FN_INSERT_HARDHYPHEN, FN_INSERT_HARD_SPACE, FN_INSERT_BREAK,
570 : FN_INSERT_LINEBREAK, FN_INSERT_COLUMN_BREAK, FN_INSERT_BREAK_DLG,
571 : FN_DELETE_SENT, FN_DELETE_BACK_SENT, FN_DELETE_WORD,
572 : FN_DELETE_BACK_WORD, FN_DELETE_LINE, FN_DELETE_BACK_LINE,
573 : FN_DELETE_PARA, FN_DELETE_BACK_PARA, FN_DELETE_WHOLE_LINE,
574 : FN_CALCULATE, FN_FORMAT_RESET,
575 : FN_POSTIT, FN_JAVAEDIT, SID_ATTR_PARA_ADJUST_LEFT,
576 : SID_ATTR_PARA_ADJUST_RIGHT, SID_ATTR_PARA_ADJUST_CENTER,SID_ATTR_PARA_ADJUST_BLOCK,
577 : SID_ATTR_PARA_LINESPACE_10, SID_ATTR_PARA_LINESPACE_15, SID_ATTR_PARA_LINESPACE_20,
578 : SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONTHEIGHT, SID_ATTR_CHAR_COLOR_BACKGROUND,
579 : SID_ATTR_CHAR_COLOR_BACKGROUND_EXT, SID_ATTR_CHAR_COLOR_EXT,
580 : SID_ATTR_CHAR_COLOR, SID_ATTR_CHAR_WEIGHT, SID_ATTR_CHAR_POSTURE,
581 : SID_ATTR_CHAR_OVERLINE,
582 : SID_ATTR_CHAR_UNDERLINE, SID_ATTR_FLASH, SID_ATTR_CHAR_STRIKEOUT,
583 : FN_UNDERLINE_DOUBLE, SID_ATTR_CHAR_CONTOUR, SID_ATTR_CHAR_SHADOWED,
584 : SID_ATTR_CHAR_AUTOKERN, SID_ATTR_CHAR_ESCAPEMENT, FN_SET_SUPER_SCRIPT,
585 : FN_SET_SUB_SCRIPT, SID_ATTR_CHAR_CASEMAP, SID_ATTR_CHAR_LANGUAGE,
586 : SID_ATTR_CHAR_KERNING, SID_CHAR_DLG, SID_ATTR_CHAR_WORDLINEMODE,
587 : FN_GROW_FONT_SIZE, FN_SHRINK_FONT_SIZE, FN_TXTATR_INET,
588 : FN_FORMAT_DROPCAPS, SID_ATTR_PARA_ADJUST, SID_ATTR_PARA_LINESPACE,
589 : SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_KEEP, SID_ATTR_PARA_WIDOWS,
590 : SID_ATTR_PARA_ORPHANS,
591 : SID_ATTR_PARA_MODEL, SID_PARA_DLG,
592 : FN_SELECT_PARA, SID_DEC_INDENT,
593 : SID_INC_INDENT
594 : };
595 : static bool bFirst = true;
596 1 : if ( bFirst )
597 : {
598 1 : qsort( static_cast<void*>(aROIds), sizeof(aROIds)/sizeof(sal_uInt16), sizeof(sal_uInt16), lcl_CmpIds );
599 1 : bFirst = false;
600 : }
601 1 : if ( SfxItemState::DISABLED == eStateRO )
602 : {
603 0 : rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, sizeof(aROIds)/sizeof(sal_uInt16), aROIds );
604 0 : bChgd = true;
605 : }
606 : }
607 2 : else if( m_pWrtShell->IsAllProtect() )
608 : {
609 0 : if ( SfxItemState::DISABLED == eStateProtAll )
610 : {
611 : static sal_uInt16 aAllProtIds[] = { SID_SAVEDOC, FN_EDIT_REGION };
612 : static bool bAllProtFirst = true;
613 0 : if ( bAllProtFirst )
614 : {
615 0 : qsort( static_cast<void*>(aAllProtIds), sizeof(aAllProtIds)/sizeof(sal_uInt16), sizeof(sal_uInt16), lcl_CmpIds );
616 0 : bAllProtFirst = false;
617 : }
618 : rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY,
619 0 : sizeof(aAllProtIds)/sizeof(sal_uInt16),
620 0 : aAllProtIds );
621 0 : bChgd = true;
622 : }
623 : }
624 2 : else if ( SfxItemState::DISABLED != eStateRO ||
625 : SfxItemState::DISABLED != eStateProtAll )
626 : {
627 0 : bChgd = true;
628 0 : rDis.SetSlotFilter();
629 : }
630 3 : if ( bChgd )
631 0 : GetViewFrame()->GetBindings().InvalidateAll(true);
632 3 : }
633 :
634 12166 : void SwView::_CheckReadonlySelection()
635 : {
636 12166 : sal_uInt32 nDisableFlags = 0;
637 12166 : SfxDispatcher &rDis = GetDispatcher();
638 :
639 12194 : if( m_pWrtShell->HasReadonlySel(m_bAnnotationMode) &&
640 28 : ( !m_pWrtShell->GetDrawView() ||
641 14 : !m_pWrtShell->GetDrawView()->GetMarkedObjectList().GetMarkCount() ))
642 14 : nDisableFlags |= SW_DISABLE_ON_PROTECTED_CURSOR;
643 :
644 12166 : if( (SW_DISABLE_ON_PROTECTED_CURSOR & nDisableFlags ) !=
645 12166 : (SW_DISABLE_ON_PROTECTED_CURSOR & rDis.GetDisableFlags() ) )
646 : {
647 : // Additionally move at the Window the InputContext, so that
648 : // in japanese / chinese versions the external input will be
649 : // turned on or off. This but only if the correct shell is on
650 : // the stack.
651 12 : switch( m_pViewImpl->GetShellMode() )
652 : {
653 : case SHELL_MODE_TEXT:
654 : case SHELL_MODE_LIST_TEXT:
655 : case SHELL_MODE_TABLE_TEXT:
656 : case SHELL_MODE_TABLE_LIST_TEXT:
657 : {
658 : // Temporary solution!!! Should set the font of the current insertion point
659 : // at each cursor movement, so outside of this "if". But TH does not
660 : // evaluates the font at this time and the "purchase" appears to me
661 : // as too expensive.
662 : // Moreover, we don't have a font, but only attributes from which the
663 : // text formatting and the correct font will be build together.
664 :
665 12 : InputContext aCntxt( GetEditWin().GetInputContext() );
666 12 : aCntxt.SetOptions( SW_DISABLE_ON_PROTECTED_CURSOR & nDisableFlags
667 : ? (aCntxt.GetOptions() & ~
668 34 : InputContextFlags( InputContextFlags::Text |
669 11 : InputContextFlags::ExtText ))
670 : : (aCntxt.GetOptions() |
671 : ( InputContextFlags::Text |
672 35 : InputContextFlags::ExtText )) );
673 12 : GetEditWin().SetInputContext( aCntxt );
674 : }
675 12 : break;
676 : default:
677 : ;
678 : }
679 :
680 : }
681 :
682 12166 : if( nDisableFlags != rDis.GetDisableFlags() )
683 : {
684 12 : rDis.SetDisableFlags( nDisableFlags );
685 12 : GetViewFrame()->GetBindings().InvalidateAll( true );
686 : }
687 12166 : }
688 :
689 2761 : SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh )
690 5522 : : SfxViewShell( _pFrame, SWVIEWFLAGS ),
691 : m_nNewPage(USHRT_MAX),
692 : m_nOldPageNum(0),
693 : m_pNumRuleNodeFromDoc(0),
694 2761 : m_pEditWin( VclPtr<SwEditWin>::Create( &_pFrame->GetWindow(), *this ) ),
695 : m_pWrtShell(0),
696 : m_pShell(0),
697 : m_pFormShell(0),
698 : m_pHScrollbar(0),
699 : m_pVScrollbar(0),
700 5522 : m_pScrollFill(VclPtr<ScrollBarBox>::Create( &_pFrame->GetWindow(), _pFrame->GetFrame().GetParentFrame() ? 0 : WB_SIZEABLE )),
701 2761 : m_pVRuler(VclPtr<SvxRuler>::Create(&GetViewFrame()->GetWindow(), m_pEditWin,
702 : SvxRulerSupportFlags::TABS | SvxRulerSupportFlags::PARAGRAPH_MARGINS_VERTICAL|
703 5522 : SvxRulerSupportFlags::BORDERS | SvxRulerSupportFlags::REDUCED_METRIC,
704 2761 : GetViewFrame()->GetBindings(),
705 : WB_VSCROLL | WB_EXTRAFIELD | WB_BORDER )),
706 : m_pTogglePageBtn(0),
707 : m_pGlosHdl(0),
708 : m_pDrawActual(0),
709 : m_pLastTableFormat(0),
710 0 : m_pFormatClipboard(new SwFormatClipboard()),
711 : m_pPostItMgr(0),
712 : m_nSelectionType( INT_MAX ),
713 : m_nPageCnt(0),
714 : m_nDrawSfxId( USHRT_MAX ),
715 : m_nFormSfxId( USHRT_MAX ),
716 : m_nLastPasteDestination( static_cast<SotExchangeDest>(0xFFFF) ),
717 : m_nLeftBorderDistance( 0 ),
718 : m_nRightBorderDistance( 0 ),
719 : m_bWheelScrollInProgress(false),
720 : m_bInMailMerge(false),
721 : m_bInDtor(false),
722 : m_bOldShellWasPagePreview(false),
723 : m_bIsPreviewDoubleClick(false),
724 22088 : m_bAnnotationMode(false)
725 : {
726 : // According to discussion with MBA and further
727 : // investigations, no old SfxViewShell will be set as parameter <pOldSh>,
728 : // if function "New Window" is performed to open an additional view beside
729 : // an already existing one.
730 : // If the view is switch from one to another, the 'old' view is given by
731 : // parameter <pOldSh>.
732 :
733 : m_bCenterCrsr = m_bTopCrsr = m_bAlwaysShowSel = m_bTabColFromDoc = m_bTabRowFromDoc =
734 : m_bSetTabColFromDoc = m_bSetTabRowFromDoc = m_bAttrChgNotified = m_bAttrChgNotifiedWithRegistrations =
735 : m_bVerbsActive = m_bDrawRotate = m_bInOuterResizePixel = m_bInInnerResizePixel =
736 2761 : m_bPasteState = m_bPasteSpecialState = m_bMakeSelectionVisible = false;
737 :
738 2761 : m_bShowAtResize = m_bDrawSelMode = bDocSzUpdated = true;
739 :
740 2761 : _CreateScrollbar( true );
741 2761 : _CreateScrollbar( false );
742 :
743 2761 : m_pViewImpl = new SwView_Impl(this);
744 2761 : SetName(OUString("View"));
745 2761 : SetWindow( m_pEditWin );
746 :
747 2761 : m_aTimer.SetTimeout( 120 );
748 :
749 2761 : SwDocShell* pDocSh = PTR_CAST( SwDocShell, _pFrame->GetObjectShell() );
750 : OSL_ENSURE( pDocSh, "view without DocShell." );
751 2761 : bool bOldModifyFlag = pDocSh->IsEnableSetModified();
752 2761 : if(bOldModifyFlag)
753 2759 : pDocSh->EnableSetModified( false );
754 : // HACK: SwDocShell has some cached font info, VCL informs about font updates,
755 : // but loading of docs with embedded fonts happens after SwDocShell is created
756 : // but before SwEditWin (which handles the VCL event) is created. So update
757 : // manually.
758 2761 : if( pDocSh->GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
759 0 : pDocSh->UpdateFontList();
760 2761 : bool bWebDShell = pDocSh->ISA(SwWebDocShell);
761 :
762 2761 : const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(bWebDShell);
763 2761 : SwViewOption aUsrPref( *pUsrPref);
764 :
765 : //! get lingu options without loading lingu DLL
766 5522 : SvtLinguOptions aLinguOpt;
767 2761 : SvtLinguConfig().GetOptions( aLinguOpt );
768 2761 : aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto );
769 :
770 2761 : bool bOldShellWasSrcView = false;
771 :
772 : // determine if there is an existing view for
773 : // document
774 2761 : SfxViewShell* pExistingSh = 0;
775 2761 : if ( pOldSh )
776 : {
777 0 : pExistingSh = pOldSh;
778 : // determine type of existing view
779 0 : if( pExistingSh->IsA( TYPE( SwPagePreview ) ) )
780 : {
781 0 : m_sSwViewData = static_cast<SwPagePreview*>(pExistingSh)->GetPrevSwViewData();
782 0 : m_sNewCrsrPos = static_cast<SwPagePreview*>(pExistingSh)->GetNewCrsrPos();
783 0 : m_nNewPage = static_cast<SwPagePreview*>(pExistingSh)->GetNewPage();
784 0 : m_bOldShellWasPagePreview = true;
785 0 : m_bIsPreviewDoubleClick = !m_sNewCrsrPos.isEmpty() || m_nNewPage != USHRT_MAX;
786 : }
787 0 : else if( pExistingSh->IsA( TYPE( SwSrcView ) ) )
788 0 : bOldShellWasSrcView = true;
789 : }
790 :
791 : SAL_INFO( "sw.ui", "before create WrtShell" );
792 2761 : if(PTR_CAST( SwView, pExistingSh))
793 : {
794 : m_pWrtShell = new SwWrtShell( *static_cast<SwView*>(pExistingSh)->m_pWrtShell,
795 0 : m_pEditWin, *this);
796 : }
797 2761 : else if( dynamic_cast<SwWrtShell*>( pDocSh->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() ) )
798 : {
799 0 : m_pWrtShell = new SwWrtShell( *static_cast<SwWrtShell*>(pDocSh->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()),
800 0 : m_pEditWin, *this);
801 : }
802 : else
803 : {
804 2761 : SwDoc& rDoc = *static_cast<SwDocShell*>(pDocSh)->GetDoc();
805 :
806 2761 : if( !bOldShellWasSrcView && bWebDShell && !m_bOldShellWasPagePreview )
807 2 : aUsrPref.setBrowseMode( true );
808 : else
809 2759 : aUsrPref.setBrowseMode( rDoc.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) );
810 :
811 : //For the BrowseMode we do not assume a factor.
812 2761 : if( aUsrPref.getBrowseMode() && aUsrPref.GetZoomType() != SvxZoomType::PERCENT )
813 : {
814 0 : aUsrPref.SetZoomType( SvxZoomType::PERCENT );
815 0 : aUsrPref.SetZoom( 100 );
816 : }
817 2761 : if(pDocSh->IsPreview())
818 : {
819 0 : aUsrPref.SetZoomType( SvxZoomType::WHOLEPAGE );
820 0 : aUsrPref.SetViewLayoutBookMode( false );
821 0 : aUsrPref.SetViewLayoutColumns( 1 );
822 : }
823 2761 : m_pWrtShell = new SwWrtShell( rDoc, m_pEditWin, *this, &aUsrPref );
824 : // creating an SwView from a SwPagePreview needs to
825 : // add the SwViewShell to the ring of the other SwViewShell(s)
826 2761 : if(m_bOldShellWasPagePreview)
827 : {
828 0 : SwViewShell& rPreviewViewShell = *static_cast<SwPagePreview*>(pExistingSh)->GetViewShell();
829 0 : m_pWrtShell->MoveTo(&rPreviewViewShell);
830 : // to update the field command et.al. if necessary
831 0 : const SwViewOption* pPreviewOpt = rPreviewViewShell.GetViewOptions();
832 0 : if( pPreviewOpt->IsFieldName() != aUsrPref.IsFieldName() ||
833 0 : pPreviewOpt->IsShowHiddenField() != aUsrPref.IsShowHiddenField() ||
834 0 : pPreviewOpt->IsShowHiddenPara() != aUsrPref.IsShowHiddenPara() ||
835 0 : pPreviewOpt->IsShowHiddenChar() != aUsrPref.IsShowHiddenChar() )
836 0 : rPreviewViewShell.ApplyViewOptions(aUsrPref);
837 : // reset design mode at draw view for form
838 : // shell, if needed.
839 0 : if ( static_cast<SwPagePreview*>(pExistingSh)->ResetFormDesignMode() &&
840 0 : m_pWrtShell->HasDrawView() )
841 : {
842 0 : SdrView* pDrawView = m_pWrtShell->GetDrawView();
843 0 : pDrawView->SetDesignMode( static_cast<SwPagePreview*>(pExistingSh)->FormDesignModeToReset() );
844 : }
845 : }
846 : }
847 : SAL_INFO( "sw.ui", "after create WrtShell" );
848 11044 : m_pHRuler = VclPtr<SwCommentRuler>::Create(m_pWrtShell, &GetViewFrame()->GetWindow(), m_pEditWin,
849 : SvxRulerSupportFlags::TABS |
850 : SvxRulerSupportFlags::PARAGRAPH_MARGINS |
851 : SvxRulerSupportFlags::BORDERS |
852 5522 : SvxRulerSupportFlags::NEGATIVE_MARGINS|
853 2761 : SvxRulerSupportFlags::REDUCED_METRIC,
854 2761 : GetViewFrame()->GetBindings(),
855 2761 : WB_STDRULER | WB_EXTRAFIELD | WB_BORDER);
856 :
857 : // assure that modified state of document
858 : // isn't reset, if document is already modified.
859 2761 : const bool bIsDocModified = m_pWrtShell->GetDoc()->getIDocumentState().IsModified();
860 :
861 : // Thus among other things, the HRuler is not displayed in the read-only case.
862 2761 : aUsrPref.SetReadonly( m_pWrtShell->GetViewOptions()->IsReadonly() );
863 :
864 : // no margin for OLE!
865 2761 : Size aBrwsBorder;
866 2761 : if( SfxObjectCreateMode::EMBEDDED != pDocSh->GetCreateMode() )
867 2760 : aBrwsBorder = GetMargin();
868 :
869 2761 : m_pWrtShell->SetBrowseBorder( aBrwsBorder );
870 :
871 : // In CTOR no shell changes may take place, which must be temporarily stored
872 : // with the timer. Otherwise, the SFX removes them from the stack!
873 2761 : bool bOld = g_bNoInterrupt;
874 2761 : g_bNoInterrupt = true;
875 :
876 2761 : m_pHRuler->SetActive( true );
877 2761 : m_pVRuler->SetActive( true );
878 :
879 2761 : SfxViewFrame* pViewFrame = GetViewFrame();
880 2761 : if( pViewFrame->GetFrame().GetParentFrame())
881 : {
882 0 : aUsrPref.SetViewHRuler(false);
883 0 : aUsrPref.SetViewVRuler(false);
884 : }
885 :
886 2761 : StartListening( *pViewFrame, true );
887 2761 : StartListening( *pDocSh, true );
888 :
889 : // Set Zoom-factor from HRuler
890 5522 : Fraction aZoomFract( aUsrPref.GetZoom(), 100 );
891 2761 : m_pHRuler->SetZoom( aZoomFract );
892 2761 : m_pVRuler->SetZoom( aZoomFract );
893 2761 : m_pHRuler->SetDoubleClickHdl(LINK( this, SwView, ExecRulerClick ));
894 2761 : FieldUnit eMetric = pUsrPref->GetHScrollMetric();
895 2761 : m_pHRuler->SetUnit( eMetric );
896 :
897 2761 : eMetric = pUsrPref->GetVScrollMetric();
898 2761 : m_pVRuler->SetUnit( eMetric );
899 :
900 2761 : m_pHRuler->SetCharWidth( 371 ); // default character width
901 2761 : m_pVRuler->SetLineHeight( 551 ); // default line height
902 :
903 : // Set DocShell
904 2761 : pDocSh->SetView( this );
905 2761 : SW_MOD()->SetView( this );
906 :
907 2761 : m_pPostItMgr = new SwPostItMgr(this);
908 :
909 : // Check and process the DocSize. Via the handler, the shell could not
910 : // be found, because the shell is not known in the SFX management
911 : // within the CTOR phase.
912 2761 : DocSzChgd( m_pWrtShell->GetDocSize() );
913 :
914 : // Set AttrChangedNotify link
915 2761 : m_pWrtShell->SetChgLnk(LINK(this, SwView, AttrChangedNotify));
916 :
917 8284 : if( pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
918 2764 : !pDocSh->GetVisArea(ASPECT_CONTENT).IsEmpty() )
919 1 : SetVisArea( pDocSh->GetVisArea(ASPECT_CONTENT),false);
920 :
921 : SAL_WARN_IF(
922 : officecfg::Office::Common::Undo::Steps::get() <= 0,
923 : "sw", "/org.openoffice.Office.Common/Undo/Steps <= 0");
924 2761 : m_pWrtShell->DoUndo( true );
925 :
926 2761 : const bool bBrowse = m_pWrtShell->GetViewOptions()->getBrowseMode();
927 : // Disable "multiple window"
928 2761 : SetNewWindowAllowed(!bBrowse);
929 : // End of disabled multiple window
930 :
931 2761 : m_bVScrollbarEnabled = aUsrPref.IsViewVScrollBar();
932 2761 : m_bHScrollbarEnabled = aUsrPref.IsViewHScrollBar();
933 2761 : m_pHScrollbar->SetAuto(bBrowse);
934 2761 : if( aUsrPref.IsViewHRuler() )
935 2760 : CreateTab();
936 2761 : if( aUsrPref.IsViewVRuler() )
937 0 : CreateVRuler();
938 :
939 2761 : m_pWrtShell->SetUIOptions( aUsrPref );
940 2761 : m_pWrtShell->SetReadOnlyAvailable( aUsrPref.IsCursorInProtectedArea() );
941 2761 : m_pWrtShell->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions());
942 :
943 2761 : if( m_pWrtShell->GetDoc()->getIDocumentState().IsUpdateExpField() )
944 : {
945 98 : if (m_pWrtShell->GetDoc()->GetDocumentFieldsManager().containsUpdatableFields())
946 : {
947 14 : SET_CURR_SHELL( m_pWrtShell );
948 14 : m_pWrtShell->StartAction();
949 14 : m_pWrtShell->CalcLayout();
950 14 : m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().UpdateFields(NULL, false);
951 14 : m_pWrtShell->EndAction();
952 : }
953 98 : m_pWrtShell->GetDoc()->getIDocumentState().SetUpdateExpFieldStat( false );
954 : }
955 :
956 : // Update all tables if necessary:
957 2761 : if( m_pWrtShell->GetDoc()->IsUpdateTOX() )
958 : {
959 0 : SfxRequest aSfxRequest( FN_UPDATE_TOX, SfxCallMode::SLOT, GetPool() );
960 0 : Execute( aSfxRequest );
961 0 : m_pWrtShell->GetDoc()->SetUpdateTOX( false ); // reset again
962 0 : m_pWrtShell->SttEndDoc(true);
963 : }
964 :
965 : // No ResetModified, if there is already a view to this doc.
966 2761 : SfxViewFrame* pVFrame = GetViewFrame();
967 2761 : SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh);
968 : // Currently(360) the view is registered firstly after the CTOR,
969 : // the following expression is also working if this changes.
970 : // If the modification cannot be canceled by undo, then do NOT set
971 : // the modify back.
972 : // no reset of modified state, if document
973 : // was already modified.
974 8283 : if (!m_pWrtShell->GetDoc()->GetIDocumentUndoRedo().IsUndoNoResetModified() &&
975 5522 : ( !pFirst || pFirst == pVFrame ) &&
976 2761 : !bIsDocModified )
977 : {
978 2713 : m_pWrtShell->ResetModified();
979 : }
980 :
981 2761 : g_bNoInterrupt = bOld;
982 :
983 : // If a new GlobalDoc will be created, the navigator will also be generated.
984 2761 : if( pDocSh->IsA(SwGlobalDocShell::StaticType()) &&
985 0 : !pVFrame->GetChildWindow( SID_NAVIGATOR ))
986 : {
987 0 : SfxBoolItem aNavi(SID_NAVIGATOR, true);
988 0 : GetDispatcher().Execute(SID_NAVIGATOR, SfxCallMode::ASYNCHRON, &aNavi, 0L);
989 : }
990 :
991 5522 : uno::Reference< frame::XFrame > xFrame = pVFrame->GetFrame().GetFrameInterface();
992 :
993 2761 : uno::Reference< frame::XFrame > xBeamerFrame = xFrame->findFrame(
994 5522 : OUString("_beamer"), frame::FrameSearchFlag::CHILDREN);
995 2761 : if(xBeamerFrame.is())
996 : {
997 0 : SwDBData aData = m_pWrtShell->GetDBData();
998 0 : SwModule::ShowDBObj( *this, aData );
999 : }
1000 :
1001 : // has anybody calls the attrchanged handler in the constructor?
1002 2761 : if( m_bAttrChgNotifiedWithRegistrations )
1003 : {
1004 8 : GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1005 8 : if( m_aTimer.IsActive() )
1006 8 : m_aTimer.Stop();
1007 : }
1008 :
1009 2761 : m_aTimer.SetTimeoutHdl(LINK(this, SwView, TimeoutHdl));
1010 2761 : m_bAttrChgNotified = m_bAttrChgNotifiedWithRegistrations = false;
1011 2761 : if(bOldModifyFlag)
1012 2759 : pDocSh->EnableSetModified( true );
1013 2761 : InvalidateBorder();
1014 :
1015 2761 : if( !m_pHScrollbar->IsVisible( true ) )
1016 2758 : ShowHScrollbar( false );
1017 2761 : if( !m_pVScrollbar->IsVisible( true ) )
1018 2761 : ShowVScrollbar( false );
1019 :
1020 5522 : GetViewFrame()->GetWindow().AddChildEventListener( LINK( this, SwView, WindowChildEventListener ) );
1021 2761 : }
1022 :
1023 8269 : SwView::~SwView()
1024 : {
1025 2757 : GetViewFrame()->GetWindow().RemoveChildEventListener( LINK( this, SwView, WindowChildEventListener ) );
1026 2757 : delete m_pPostItMgr;
1027 2757 : m_pPostItMgr = 0;
1028 :
1029 2757 : m_bInDtor = true;
1030 2757 : m_pEditWin->Hide(); // prevent problems with painting
1031 :
1032 : // Set pointer in SwDocShell to the view again
1033 2757 : SwDocShell* pDocSh = GetDocShell();
1034 2757 : if( pDocSh && pDocSh->GetView() == this )
1035 2757 : pDocSh->SetView( 0 );
1036 2757 : if ( SW_MOD()->GetView() == this )
1037 2724 : SW_MOD()->SetView( 0 );
1038 :
1039 2757 : if( m_aTimer.IsActive() && m_bAttrChgNotifiedWithRegistrations )
1040 484 : GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1041 :
1042 : // the last view must end the text edit
1043 2757 : SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : 0;
1044 2757 : if( pSdrView && pSdrView->IsTextEdit() )
1045 0 : pSdrView->SdrEndTextEdit( true );
1046 :
1047 2757 : SetWindow( 0 );
1048 :
1049 2757 : m_pViewImpl->Invalidate();
1050 2757 : EndListening(*GetViewFrame());
1051 2757 : EndListening(*GetDocShell());
1052 2757 : m_pScrollFill.disposeAndClear();
1053 2757 : delete m_pWrtShell;
1054 2757 : m_pWrtShell = 0; // Set to 0, so that it is not accessible by the following dtors cannot.
1055 2757 : m_pShell = 0;
1056 2757 : m_pHScrollbar.disposeAndClear();
1057 2757 : m_pVScrollbar.disposeAndClear();
1058 2757 : m_pHRuler.disposeAndClear();
1059 2757 : m_pVRuler.disposeAndClear();
1060 2757 : m_pTogglePageBtn.disposeAndClear();
1061 2757 : delete m_pGlosHdl;
1062 2757 : delete m_pViewImpl;
1063 2757 : m_pEditWin.disposeAndClear();
1064 2757 : delete m_pFormatClipboard;
1065 5512 : }
1066 :
1067 201828 : SwDocShell* SwView::GetDocShell()
1068 : {
1069 201828 : SfxObjectShell* pDocShell = GetViewFrame()->GetObjectShell();
1070 201828 : return PTR_CAST(SwDocShell, pDocShell);
1071 : }
1072 :
1073 : // Remember CursorPos
1074 :
1075 0 : void SwView::WriteUserData( OUString &rUserData, bool bBrowse )
1076 : {
1077 : // The browse flag will be passed from Sfx when documents are browsed
1078 : // (not to be confused with the BrowseMode).
1079 : // Then that stored data are not persistent!
1080 :
1081 0 : const SwRect& rRect = m_pWrtShell->GetCharRect();
1082 0 : const Rectangle& rVis = GetVisArea();
1083 :
1084 0 : rUserData = OUString::number( rRect.Left() );
1085 0 : rUserData += ";";
1086 0 : rUserData += OUString::number( rRect.Top() );
1087 0 : rUserData += ";";
1088 0 : rUserData += OUString::number( m_pWrtShell->GetViewOptions()->GetZoom() );
1089 0 : rUserData += ";";
1090 0 : rUserData += OUString::number( rVis.Left() );
1091 0 : rUserData += ";";
1092 0 : rUserData += OUString::number( rVis.Top() );
1093 0 : rUserData += ";";
1094 0 : rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Right());
1095 0 : rUserData += ";";
1096 0 : rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Bottom());
1097 0 : rUserData += ";";
1098 0 : rUserData += OUString::number(
1099 0 : (sal_uInt16)m_pWrtShell->GetViewOptions()->GetZoomType());//eZoom;
1100 0 : rUserData += ";";
1101 0 : rUserData += FrmTypeFlags::NONE == m_pWrtShell->GetSelFrmType() ? OUString("0") : OUString("1");
1102 0 : }
1103 :
1104 : // Set CursorPos
1105 :
1106 2685 : static bool lcl_IsOwnDocument( SwView& rView )
1107 : {
1108 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1109 2685 : rView.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
1110 : uno::Reference<document::XDocumentProperties> xDocProps
1111 5370 : = xDPS->getDocumentProperties();
1112 5370 : OUString Created = xDocProps->getAuthor();
1113 5370 : OUString Changed = xDocProps->getModifiedBy();
1114 5370 : OUString FullName = SW_MOD()->GetUserOptions().GetFullName();
1115 2685 : return (!FullName.isEmpty() &&
1116 5370 : (!Changed.isEmpty() && Changed == FullName )) ||
1117 9304 : (Changed.isEmpty() && !Created.isEmpty() && Created == FullName );
1118 : }
1119 :
1120 0 : void SwView::ReadUserData( const OUString &rUserData, bool bBrowse )
1121 : {
1122 0 : if ( comphelper::string::getTokenCount(rUserData, ';') > 1 &&
1123 : // For document without layout only in the onlinelayout or
1124 : // while forward/backward
1125 0 : (!m_pWrtShell->IsNewLayout() || m_pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse) )
1126 : {
1127 0 : bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1128 :
1129 0 : SET_CURR_SHELL(m_pWrtShell);
1130 :
1131 0 : sal_Int32 nPos = 0;
1132 :
1133 : // No it is *no* good idea to call GetToken within Point-Konstr. immediately,
1134 : // because which parameter is evaluated first?
1135 0 : long nX = rUserData.getToken( 0, ';', nPos ).toInt32(),
1136 0 : nY = rUserData.getToken( 0, ';', nPos ).toInt32();
1137 0 : Point aCrsrPos( nX, nY );
1138 :
1139 : sal_uInt16 nZoomFactor =
1140 0 : static_cast< sal_uInt16 >( rUserData.getToken(0, ';', nPos ).toInt32() );
1141 :
1142 0 : long nLeft = rUserData.getToken(0, ';', nPos ).toInt32(),
1143 0 : nTop = rUserData.getToken(0, ';', nPos ).toInt32(),
1144 0 : nRight = rUserData.getToken(0, ';', nPos ).toInt32(),
1145 0 : nBottom= rUserData.getToken(0, ';', nPos ).toInt32();
1146 :
1147 0 : const long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1148 0 : if ( nBottom <= (m_pWrtShell->GetDocSize().Height()+nAdd) )
1149 : {
1150 0 : m_pWrtShell->EnableSmooth( false );
1151 :
1152 0 : const Rectangle aVis( nLeft, nTop, nRight, nBottom );
1153 :
1154 0 : sal_Int32 nOff = 0;
1155 : SvxZoomType eZoom;
1156 0 : if( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1157 0 : eZoom = (SvxZoomType) (sal_uInt16)rUserData.getToken(nOff, ';', nPos ).toInt32();
1158 : else
1159 : {
1160 0 : eZoom = SvxZoomType::PERCENT;
1161 0 : ++nOff;
1162 : }
1163 :
1164 0 : bool bSelectObj = (0 != rUserData.getToken( nOff, ';', nPos ).toInt32())
1165 0 : && m_pWrtShell->IsObjSelectable( aCrsrPos );
1166 :
1167 : // restore editing position
1168 0 : m_pViewImpl->SetRestorePosition(aCrsrPos, bSelectObj);
1169 : // set flag value to avoid macro execution.
1170 0 : bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1171 0 : m_pWrtShell->SetMacroExecAllowed( false );
1172 : // os: changed: The user data has to be read if the view is switched back from page preview
1173 : // go to the last editing position when opening own files
1174 0 : if(m_bOldShellWasPagePreview || bIsOwnDocument)
1175 : {
1176 0 : m_pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos, !bSelectObj );
1177 0 : if( bSelectObj )
1178 : {
1179 0 : m_pWrtShell->SelectObj( aCrsrPos );
1180 0 : m_pWrtShell->EnterSelFrmMode( &aCrsrPos );
1181 : }
1182 : }
1183 :
1184 : // reset flag value
1185 0 : m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1186 :
1187 : // set visible area before applying
1188 : // information from print preview. Otherwise, the applied information
1189 : // is lost.
1190 : // os: changed: The user data has to be read if the view is switched back from page preview
1191 : // go to the last editing position when opening own files
1192 0 : if(m_bOldShellWasPagePreview || bIsOwnDocument )
1193 : {
1194 0 : if ( bBrowse )
1195 0 : SetVisArea( aVis.TopLeft() );
1196 : else
1197 0 : SetVisArea( aVis );
1198 : }
1199 :
1200 : //apply information from print preview - if available
1201 0 : if( !m_sNewCrsrPos.isEmpty() )
1202 : {
1203 0 : long nXTmp = m_sNewCrsrPos.getToken( 0, ';' ).toInt32(),
1204 0 : nYTmp = m_sNewCrsrPos.getToken( 1, ';' ).toInt32();
1205 0 : Point aCrsrPos2( nXTmp, nYTmp );
1206 0 : bSelectObj = m_pWrtShell->IsObjSelectable( aCrsrPos2 );
1207 :
1208 0 : m_pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos2, false );
1209 0 : if( bSelectObj )
1210 : {
1211 0 : m_pWrtShell->SelectObj( aCrsrPos2 );
1212 0 : m_pWrtShell->EnterSelFrmMode( &aCrsrPos2 );
1213 : }
1214 0 : m_pWrtShell->MakeSelVisible();
1215 0 : m_sNewCrsrPos.clear();
1216 : }
1217 0 : else if(USHRT_MAX != m_nNewPage)
1218 : {
1219 0 : m_pWrtShell->GotoPage(m_nNewPage, true);
1220 0 : m_nNewPage = USHRT_MAX;
1221 : }
1222 :
1223 0 : SelectShell();
1224 :
1225 0 : m_pWrtShell->StartAction();
1226 0 : const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1227 0 : if( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom )
1228 0 : SetZoom( eZoom, nZoomFactor);
1229 :
1230 0 : m_pWrtShell->LockView( true );
1231 0 : m_pWrtShell->EndAction();
1232 0 : m_pWrtShell->LockView( false );
1233 0 : m_pWrtShell->EnableSmooth( true );
1234 0 : }
1235 : }
1236 0 : }
1237 :
1238 2685 : void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence, bool bBrowse )
1239 : {
1240 2685 : if(GetDocShell()->IsPreview()||m_bIsPreviewDoubleClick)
1241 2685 : return;
1242 2685 : bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1243 2685 : sal_Int32 nLength = rSequence.getLength();
1244 2685 : if (nLength && (!m_pWrtShell->IsNewLayout() || m_pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse) )
1245 : {
1246 2685 : SET_CURR_SHELL(m_pWrtShell);
1247 2685 : const beans::PropertyValue *pValue = rSequence.getConstArray();
1248 2685 : const SwRect& rRect = m_pWrtShell->GetCharRect();
1249 2685 : const Rectangle &rVis = GetVisArea();
1250 2685 : const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1251 :
1252 2685 : sal_Int64 nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top();
1253 2685 : sal_Int64 nRight = bBrowse ? LONG_MIN : rVis.Right(), nBottom = bBrowse ? LONG_MIN : rVis.Bottom();
1254 2685 : sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType());
1255 2685 : sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom());
1256 2685 : bool bViewLayoutBookMode = pVOpt->IsViewLayoutBookMode();
1257 2685 : sal_Int16 nViewLayoutColumns = pVOpt->GetViewLayoutColumns();
1258 :
1259 2685 : bool bSelectedFrame = ( m_pWrtShell->GetSelFrmType() != FrmTypeFlags::NONE ),
1260 2685 : bGotVisibleLeft = false,
1261 2685 : bGotVisibleTop = false, bGotVisibleRight = false,
1262 2685 : bGotVisibleBottom = false, bGotZoomType = false,
1263 2685 : bGotZoomFactor = false, bGotIsSelectedFrame = false,
1264 2685 : bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false;
1265 :
1266 19635 : for (sal_Int32 i = 0 ; i < nLength; i++)
1267 : {
1268 16950 : if ( pValue->Name == "ViewLeft" )
1269 : {
1270 989 : pValue->Value >>= nX;
1271 989 : nX = convertMm100ToTwip( nX );
1272 : }
1273 15961 : else if ( pValue->Name == "ViewTop" )
1274 : {
1275 989 : pValue->Value >>= nY;
1276 989 : nY = convertMm100ToTwip( nY );
1277 : }
1278 14972 : else if ( pValue->Name == "VisibleLeft" )
1279 : {
1280 989 : pValue->Value >>= nLeft;
1281 989 : nLeft = convertMm100ToTwip( nLeft );
1282 989 : bGotVisibleLeft = true;
1283 : }
1284 13983 : else if ( pValue->Name == "VisibleTop" )
1285 : {
1286 989 : pValue->Value >>= nTop;
1287 989 : nTop = convertMm100ToTwip( nTop );
1288 989 : bGotVisibleTop = true;
1289 : }
1290 12994 : else if ( pValue->Name == "VisibleRight" )
1291 : {
1292 989 : pValue->Value >>= nRight;
1293 989 : nRight = convertMm100ToTwip( nRight );
1294 989 : bGotVisibleRight = true;
1295 : }
1296 12005 : else if ( pValue->Name == "VisibleBottom" )
1297 : {
1298 2685 : pValue->Value >>= nBottom;
1299 2685 : nBottom = convertMm100ToTwip( nBottom );
1300 2685 : bGotVisibleBottom = true;
1301 : }
1302 9320 : else if ( pValue->Name == "ZoomType" )
1303 : {
1304 2685 : pValue->Value >>= nZoomType;
1305 2685 : bGotZoomType = true;
1306 : }
1307 6635 : else if ( pValue->Name == "ZoomFactor" )
1308 : {
1309 2685 : pValue->Value >>= nZoomFactor;
1310 2685 : bGotZoomFactor = true;
1311 : }
1312 3950 : else if ( pValue->Name == "ViewLayoutColumns" )
1313 : {
1314 986 : pValue->Value >>= nViewLayoutColumns;
1315 986 : bGotViewLayoutColumns = true;
1316 : }
1317 2964 : else if ( pValue->Name == "ViewLayoutBookMode" )
1318 : {
1319 986 : bViewLayoutBookMode = * static_cast<sal_Bool const *>(pValue->Value.getValue());
1320 986 : bGotViewLayoutBookMode = true;
1321 : }
1322 1978 : else if ( pValue->Name == "IsSelectedFrame" )
1323 : {
1324 989 : pValue->Value >>= bSelectedFrame;
1325 989 : bGotIsSelectedFrame = true;
1326 : }
1327 16950 : pValue++;
1328 : }
1329 2685 : if (bGotVisibleBottom)
1330 : {
1331 2685 : Point aCrsrPos( nX, nY );
1332 2685 : const long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1333 2685 : if (nBottom <= (m_pWrtShell->GetDocSize().Height()+nAdd) )
1334 : {
1335 2675 : m_pWrtShell->EnableSmooth( false );
1336 2675 : const Rectangle aVis( nLeft, nTop, nRight, nBottom );
1337 :
1338 : SvxZoomType eZoom;
1339 2675 : if ( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1340 2673 : eZoom = static_cast < SvxZoomType > ( nZoomType );
1341 : else
1342 : {
1343 2 : eZoom = SvxZoomType::PERCENT;
1344 : }
1345 2675 : if (bGotIsSelectedFrame)
1346 : {
1347 979 : bool bSelectObj = bSelectedFrame && m_pWrtShell->IsObjSelectable( aCrsrPos );
1348 :
1349 : // set flag value to avoid macro execution.
1350 979 : bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1351 979 : m_pWrtShell->SetMacroExecAllowed( false );
1352 : // os: changed: The user data has to be read if the view is switched back from page preview
1353 : // go to the last editing position when opening own files
1354 979 : m_pViewImpl->SetRestorePosition(aCrsrPos, bSelectObj);
1355 979 : if(m_bOldShellWasPagePreview|| bIsOwnDocument)
1356 : {
1357 0 : m_pWrtShell->SwCrsrShell::SetCrsr( aCrsrPos, !bSelectObj );
1358 :
1359 : // Update the shell to toggle Header/Footer edit if needed
1360 0 : bool bInHeader = true;
1361 0 : if ( m_pWrtShell->IsInHeaderFooter( &bInHeader ) )
1362 : {
1363 0 : if ( !bInHeader )
1364 : {
1365 0 : m_pWrtShell->SetShowHeaderFooterSeparator( Footer, true );
1366 0 : m_pWrtShell->SetShowHeaderFooterSeparator( Header, false );
1367 : }
1368 : else
1369 : {
1370 0 : m_pWrtShell->SetShowHeaderFooterSeparator( Header, true );
1371 0 : m_pWrtShell->SetShowHeaderFooterSeparator( Footer, false );
1372 : }
1373 :
1374 : // Force repaint
1375 0 : m_pWrtShell->GetWin()->Invalidate();
1376 : }
1377 0 : if ( m_pWrtShell->IsInHeaderFooter() != m_pWrtShell->IsHeaderFooterEdit() )
1378 0 : m_pWrtShell->ToggleHeaderFooterEdit();
1379 :
1380 0 : if( bSelectObj )
1381 : {
1382 0 : m_pWrtShell->SelectObj( aCrsrPos );
1383 0 : m_pWrtShell->EnterSelFrmMode( &aCrsrPos );
1384 : }
1385 : }
1386 :
1387 : // reset flag value
1388 979 : m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1389 : }
1390 2675 : SelectShell();
1391 :
1392 : // Set ViewLayoutSettings
1393 3821 : const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
1394 4457 : ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
1395 :
1396 6250 : const bool bSetViewSettings = bGotZoomType && bGotZoomFactor &&
1397 7129 : ( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom );
1398 :
1399 : // In case we have a 'fixed' view layout of 2 or more columns,
1400 : // we have to apply the view options *before* starting the action.
1401 : // Otherwsie the SetZoom function cannot work correctly, because
1402 : // the view layout hasn't been calculated.
1403 170 : const bool bZoomNeedsViewLayout = bSetViewLayoutSettings &&
1404 170 : 1 < nViewLayoutColumns &&
1405 2675 : bSetViewSettings &&
1406 2675 : eZoom != SvxZoomType::PERCENT;
1407 :
1408 2675 : if ( !bZoomNeedsViewLayout )
1409 2675 : m_pWrtShell->StartAction();
1410 :
1411 2675 : if ( bSetViewLayoutSettings )
1412 170 : SetViewLayout( nViewLayoutColumns, bViewLayoutBookMode, true );
1413 :
1414 2675 : if ( bZoomNeedsViewLayout )
1415 0 : m_pWrtShell->StartAction();
1416 :
1417 2675 : if ( bSetViewSettings )
1418 900 : SetZoom( eZoom, nZoomFactor, true );
1419 :
1420 : // os: changed: The user data has to be read if the view is switched back from page preview
1421 : // go to the last editing position when opening own files
1422 2675 : if(m_bOldShellWasPagePreview||bIsOwnDocument)
1423 : {
1424 0 : if ( bBrowse && bGotVisibleLeft && bGotVisibleTop )
1425 : {
1426 0 : Point aTopLeft(aVis.TopLeft());
1427 : // make sure the document is still centered
1428 0 : const SwTwips lBorder = IsDocumentBorder() ? DOCUMENTBORDER : 2 * DOCUMENTBORDER;
1429 0 : SwTwips nEditWidth = GetEditWin().GetOutputSize().Width();
1430 0 : if(nEditWidth > (m_aDocSz.Width() + lBorder ))
1431 0 : aTopLeft.X() = ( m_aDocSz.Width() + lBorder - nEditWidth ) / 2;
1432 : else
1433 : {
1434 : //check if the values are possible
1435 0 : long nXMax = m_pHScrollbar->GetRangeMax() - m_pHScrollbar->GetVisibleSize();
1436 0 : if( aTopLeft.X() > nXMax )
1437 0 : aTopLeft.X() = nXMax < 0 ? 0 : nXMax;
1438 : }
1439 0 : SetVisArea( aTopLeft );
1440 : }
1441 0 : else if (bGotVisibleLeft && bGotVisibleTop && bGotVisibleRight && bGotVisibleBottom )
1442 0 : SetVisArea( aVis );
1443 : }
1444 :
1445 2675 : m_pWrtShell->LockView( true );
1446 2675 : m_pWrtShell->EndAction();
1447 2675 : m_pWrtShell->LockView( false );
1448 2675 : m_pWrtShell->EnableSmooth( true );
1449 : }
1450 2685 : }
1451 : }
1452 : }
1453 :
1454 : #define NUM_VIEW_SETTINGS 12
1455 778 : void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSequence, bool bBrowse )
1456 : {
1457 778 : const SwRect& rRect = m_pWrtShell->GetCharRect();
1458 778 : const Rectangle& rVis = GetVisArea();
1459 :
1460 778 : rSequence.realloc ( NUM_VIEW_SETTINGS );
1461 778 : sal_Int16 nIndex = 0;
1462 778 : beans::PropertyValue *pValue = rSequence.getArray();
1463 :
1464 778 : sal_uInt16 nViewID( GetViewFrame()->GetCurViewId());
1465 778 : pValue->Name = "ViewId";
1466 778 : OUStringBuffer sBuffer ( OUString( "view" ) );
1467 778 : ::sax::Converter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID));
1468 778 : pValue->Value <<= sBuffer.makeStringAndClear();
1469 778 : pValue++;nIndex++;
1470 :
1471 778 : pValue->Name = "ViewLeft";
1472 778 : pValue->Value <<= convertTwipToMm100 ( rRect.Left() );
1473 778 : pValue++;nIndex++;
1474 :
1475 778 : pValue->Name = "ViewTop";
1476 778 : pValue->Value <<= convertTwipToMm100 ( rRect.Top() );
1477 778 : pValue++;nIndex++;
1478 :
1479 778 : pValue->Name = "VisibleLeft";
1480 778 : pValue->Value <<= convertTwipToMm100 ( rVis.Left() );
1481 778 : pValue++;nIndex++;
1482 :
1483 778 : pValue->Name = "VisibleTop";
1484 778 : pValue->Value <<= convertTwipToMm100 ( rVis.Top() );
1485 778 : pValue++;nIndex++;
1486 :
1487 778 : pValue->Name = "VisibleRight";
1488 778 : pValue->Value <<= convertTwipToMm100 ( bBrowse ? LONG_MIN : rVis.Right() );
1489 778 : pValue++;nIndex++;
1490 :
1491 778 : pValue->Name = "VisibleBottom";
1492 778 : pValue->Value <<= convertTwipToMm100 ( bBrowse ? LONG_MIN : rVis.Bottom() );
1493 778 : pValue++;nIndex++;
1494 :
1495 778 : pValue->Name = "ZoomType";
1496 778 : const sal_Int16 nZoomType = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetZoomType());
1497 778 : pValue->Value <<= nZoomType;
1498 778 : pValue++;nIndex++;
1499 :
1500 778 : pValue->Name = "ViewLayoutColumns";
1501 778 : const sal_Int16 nViewLayoutColumns = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetViewLayoutColumns());
1502 778 : pValue->Value <<= nViewLayoutColumns;
1503 778 : pValue++;nIndex++;
1504 :
1505 778 : pValue->Name = "ViewLayoutBookMode";
1506 778 : pValue->Value <<= m_pWrtShell->GetViewOptions()->IsViewLayoutBookMode();
1507 778 : pValue++;nIndex++;
1508 :
1509 778 : pValue->Name = "ZoomFactor";
1510 778 : pValue->Value <<= static_cast < sal_Int16 > (m_pWrtShell->GetViewOptions()->GetZoom());
1511 778 : pValue++;nIndex++;
1512 :
1513 778 : pValue->Name = "IsSelectedFrame";
1514 778 : pValue->Value <<= FrmTypeFlags::NONE != m_pWrtShell->GetSelFrmType();
1515 778 : nIndex++;
1516 :
1517 : assert(nIndex == NUM_VIEW_SETTINGS);
1518 778 : (void)nIndex;
1519 778 : }
1520 : #undef NUM_VIEW_SETTINGS
1521 :
1522 1289 : void SwView::ShowCursor( bool bOn )
1523 : {
1524 : //don't scroll the cursor into the visible area
1525 1289 : bool bUnlockView = !m_pWrtShell->IsViewLocked();
1526 1289 : m_pWrtShell->LockView( true ); //lock visible section
1527 :
1528 1289 : if( !bOn )
1529 646 : m_pWrtShell->HideCrsr();
1530 643 : else if( !m_pWrtShell->IsFrmSelected() && !m_pWrtShell->IsObjSelected() )
1531 643 : m_pWrtShell->ShowCrsr();
1532 :
1533 1289 : if( bUnlockView )
1534 1289 : m_pWrtShell->LockView( false );
1535 1289 : }
1536 :
1537 0 : ErrCode SwView::DoVerb( long nVerb )
1538 : {
1539 0 : if ( !GetViewFrame()->GetFrame().IsInPlace() )
1540 : {
1541 0 : SwWrtShell &rSh = GetWrtShell();
1542 0 : const int nSel = rSh.GetSelectionType();
1543 0 : if ( nSel & nsSelectionType::SEL_OLE )
1544 0 : rSh.LaunchOLEObj( nVerb );
1545 : }
1546 0 : return ERRCODE_NONE;
1547 : }
1548 :
1549 : // only return true for a text selection
1550 :
1551 1 : bool SwView::HasSelection( bool bText ) const
1552 : {
1553 0 : return bText ? GetWrtShell().SwCrsrShell::HasSelection()
1554 1 : : GetWrtShell().HasSelection();
1555 : }
1556 :
1557 0 : OUString SwView::GetSelectionText( bool bCompleteWrds )
1558 : {
1559 0 : return GetSelectionTextParam( bCompleteWrds, true );
1560 : }
1561 :
1562 0 : OUString SwView::GetSelectionTextParam( bool bCompleteWrds, bool bEraseTrail )
1563 : {
1564 0 : OUString sReturn;
1565 0 : if( bCompleteWrds && !GetWrtShell().HasSelection() )
1566 0 : GetWrtShell().SelWrd();
1567 :
1568 0 : GetWrtShell().GetSelectedText( sReturn );
1569 0 : if( bEraseTrail )
1570 0 : sReturn = comphelper::string::stripEnd(sReturn, ' ');
1571 0 : return sReturn;
1572 : }
1573 :
1574 2 : SwGlossaryHdl* SwView::GetGlosHdl()
1575 : {
1576 2 : if(!m_pGlosHdl)
1577 1 : m_pGlosHdl = new SwGlossaryHdl(GetViewFrame(), m_pWrtShell);
1578 2 : return m_pGlosHdl;
1579 : }
1580 :
1581 70075 : void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1582 : {
1583 70075 : bool bCallBase = true;
1584 70075 : if ( dynamic_cast<const SfxSimpleHint*>(&rHint) )
1585 : {
1586 45078 : sal_uInt32 nId = static_cast<const SfxSimpleHint&>(rHint).GetId();
1587 45078 : switch ( nId )
1588 : {
1589 : // sub shells will be destroyed by the
1590 : // dispatcher, if the view frame is dying. Thus, reset member <pShell>.
1591 : case SFX_HINT_DYING:
1592 : {
1593 5505 : if ( &rBC == GetViewFrame() )
1594 : {
1595 2757 : ResetSubShell();
1596 : }
1597 : }
1598 5505 : break;
1599 : case SFX_HINT_MODECHANGED:
1600 : {
1601 : // Modal mode change-over?
1602 34 : bool bModal = GetDocShell()->IsInModalMode();
1603 34 : m_pHRuler->SetActive( !bModal );
1604 34 : m_pVRuler->SetActive( !bModal );
1605 : }
1606 :
1607 : /* no break here */
1608 :
1609 : case SFX_HINT_TITLECHANGED:
1610 3925 : if ( GetDocShell()->IsReadOnly() != GetWrtShell().GetViewOptions()->IsReadonly() )
1611 : {
1612 0 : SwWrtShell &rSh = GetWrtShell();
1613 0 : rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
1614 :
1615 0 : if ( rSh.GetViewOptions()->IsViewVRuler() )
1616 0 : CreateVRuler();
1617 : else
1618 0 : KillVRuler();
1619 0 : if ( rSh.GetViewOptions()->IsViewHRuler() )
1620 0 : CreateTab();
1621 : else
1622 0 : KillTab();
1623 0 : bool bReadonly = GetDocShell()->IsReadOnly();
1624 : // if document is to be opened in alive-mode then this has to be
1625 : // regarded while switching from readonly-mode to edit-mode
1626 0 : if( !bReadonly )
1627 : {
1628 0 : SwDrawModel * pDrawDoc = GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
1629 0 : if (pDrawDoc)
1630 : {
1631 0 : if( !pDrawDoc->GetOpenInDesignMode() )
1632 0 : break;// don't touch the design mode
1633 : }
1634 : }
1635 0 : SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
1636 0 : GetDispatcher().Execute( SID_FM_DESIGN_MODE, SfxCallMode::ASYNCHRON,
1637 0 : &aItem, 0L );
1638 : }
1639 3925 : break;
1640 :
1641 : case SW_BROADCAST_DRAWVIEWS_CREATED:
1642 : {
1643 0 : bCallBase = false;
1644 0 : if ( GetFormShell() )
1645 : {
1646 0 : GetFormShell()->SetView(
1647 0 : PTR_CAST(FmFormView, GetWrtShell().GetDrawView()) );
1648 0 : SfxBoolItem aItem( SID_FM_DESIGN_MODE, !GetDocShell()->IsReadOnly());
1649 0 : GetDispatcher().Execute( SID_FM_DESIGN_MODE, SfxCallMode::SYNCHRON,
1650 0 : &aItem, 0L );
1651 : }
1652 : }
1653 0 : break;
1654 45078 : }
1655 : }
1656 24997 : else if(dynamic_cast<const FmDesignModeChangedHint*>(&rHint))
1657 : {
1658 2774 : bool bDesignMode = static_cast<const FmDesignModeChangedHint&>(rHint).GetDesignMode();
1659 2774 : if (!bDesignMode && GetDrawFuncPtr())
1660 : {
1661 0 : GetDrawFuncPtr()->Deactivate();
1662 0 : SetDrawFuncPtr(NULL);
1663 0 : LeaveDrawCreate();
1664 0 : AttrChangedNotify(m_pWrtShell);
1665 : }
1666 : }
1667 :
1668 70075 : if ( bCallBase )
1669 70075 : SfxViewShell::Notify(rBC, rHint);
1670 70075 : }
1671 :
1672 : #if defined WNT || defined UNX
1673 :
1674 0 : void SwView::ScannerEventHdl( const EventObject& /*rEventObject*/ )
1675 : {
1676 0 : uno::Reference< XScannerManager2 > xScanMgr = SW_MOD()->GetScannerManager();
1677 0 : if( xScanMgr.is() )
1678 : {
1679 0 : const ScannerContext aContext( xScanMgr->getAvailableScanners().getConstArray()[ 0 ] );
1680 0 : const ScanError eError = xScanMgr->getError( aContext );
1681 :
1682 0 : if( ScanError_ScanErrorNone == eError )
1683 : {
1684 0 : const uno::Reference< awt::XBitmap > xBitmap( xScanMgr->getBitmap( aContext ) );
1685 :
1686 0 : if( xBitmap.is() )
1687 : {
1688 0 : const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
1689 :
1690 0 : if( !!aScanBmp )
1691 : {
1692 0 : Graphic aGrf(aScanBmp);
1693 0 : m_pWrtShell->Insert( OUString(), OUString(), aGrf );
1694 0 : }
1695 0 : }
1696 0 : }
1697 : }
1698 0 : SfxBindings& rBind = GetViewFrame()->GetBindings();
1699 0 : rBind.Invalidate( SID_TWAIN_SELECT );
1700 0 : rBind.Invalidate( SID_TWAIN_TRANSFER );
1701 0 : }
1702 : #endif
1703 :
1704 1 : void SwView::StopShellTimer()
1705 : {
1706 1 : if(m_aTimer.IsActive())
1707 : {
1708 0 : m_aTimer.Stop();
1709 0 : if ( m_bAttrChgNotifiedWithRegistrations )
1710 : {
1711 0 : GetViewFrame()->GetBindings().LEAVEREGISTRATIONS();
1712 0 : m_bAttrChgNotifiedWithRegistrations = false;
1713 : }
1714 0 : SelectShell();
1715 0 : m_bAttrChgNotified = false;
1716 : }
1717 1 : }
1718 :
1719 5459 : bool SwView::PrepareClose( bool bUI )
1720 : {
1721 5459 : SfxViewFrame* pVFrame = GetViewFrame();
1722 5459 : pVFrame->SetChildWindow( SwInputChild::GetChildWindowId(), false );
1723 5459 : if( pVFrame->GetDispatcher()->IsLocked() )
1724 2 : pVFrame->GetDispatcher()->Lock(false);
1725 :
1726 5459 : if ( m_pFormShell && !m_pFormShell->PrepareClose( bUI ) )
1727 : {
1728 0 : return false;
1729 : }
1730 5459 : return SfxViewShell::PrepareClose( bUI );
1731 : }
1732 :
1733 : // status methods for clipboard.
1734 : // Status changes now notified from the clipboard.
1735 1325 : bool SwView::IsPasteAllowed()
1736 : {
1737 1325 : SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1738 1325 : if( m_nLastPasteDestination != nPasteDestination )
1739 : {
1740 : TransferableDataHelper aDataHelper(
1741 : TransferableDataHelper::CreateFromSystemClipboard(
1742 338 : &GetEditWin()) );
1743 338 : if( aDataHelper.GetXTransferable().is() )
1744 : {
1745 0 : m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1746 : m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1747 0 : *m_pWrtShell, aDataHelper );
1748 : }
1749 : else
1750 338 : m_bPasteState = m_bPasteSpecialState = false;
1751 :
1752 338 : if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value
1753 338 : m_pViewImpl->AddClipboardListener();
1754 338 : m_nLastPasteDestination = nPasteDestination;
1755 : }
1756 1325 : return m_bPasteState;
1757 : }
1758 :
1759 12 : bool SwView::IsPasteSpecialAllowed()
1760 : {
1761 12 : if ( m_pFormShell && m_pFormShell->IsActiveControl() )
1762 0 : return false;
1763 :
1764 12 : SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1765 12 : if( m_nLastPasteDestination != nPasteDestination )
1766 : {
1767 : TransferableDataHelper aDataHelper(
1768 : TransferableDataHelper::CreateFromSystemClipboard(
1769 0 : &GetEditWin()) );
1770 0 : if( aDataHelper.GetXTransferable().is() )
1771 : {
1772 0 : m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1773 : m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1774 0 : *m_pWrtShell, aDataHelper );
1775 : }
1776 : else
1777 0 : m_bPasteState = m_bPasteSpecialState = false;
1778 :
1779 0 : if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value
1780 0 : m_pViewImpl->AddClipboardListener();
1781 : }
1782 12 : return m_bPasteSpecialState;
1783 : }
1784 :
1785 8 : void SwView::NotifyDBChanged()
1786 : {
1787 8 : GetViewImpl()->GetUNOObject_Impl()->NotifyDBChanged();
1788 8 : }
1789 :
1790 : // Printing
1791 :
1792 0 : SfxObjectShellLock SwView::CreateTmpSelectionDoc()
1793 : {
1794 0 : SwXTextView *const pImpl = GetViewImpl()->GetUNOObject_Impl();
1795 0 : return pImpl->BuildTmpSelectionDoc();
1796 : }
1797 :
1798 51 : void SwView::AddTransferable(SwTransferable& rTransferable)
1799 : {
1800 51 : GetViewImpl()->AddTransferable(rTransferable);
1801 51 : }
1802 :
1803 : namespace sw {
1804 :
1805 1 : void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)
1806 : {
1807 1 : o_rData = *SW_MOD()->GetPrtOptions(bWeb);
1808 1 : }
1809 :
1810 177 : } // namespace sw
1811 :
1812 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|