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