1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <com/sun/star/embed/XClassifiedObject.hpp>
32 #include <com/sun/star/embed/XEmbeddedObject.hpp>
33 #include <tools/rtti.hxx>
34 #include <svl/svarray.hxx>
36 #include <swtypes.hxx>
39 #include <boost/shared_ptr.hpp> // swmod 080115
41 #include <vcl/mapmod.hxx>
42 #include <vcl/print.hxx>
44 namespace com
{ namespace sun
{ namespace star
{ namespace accessibility
{
45 class XAccessible
; } } } }
47 class SfxObjectShellRef
;
49 class IDocumentSettingAccess
;
50 class IDocumentDeviceAccess
;
51 class IDocumentMarkAccess
;
52 class IDocumentDrawModelAccess
;
53 class IDocumentRedlineAccess
;
54 class IDocumentLayoutAccess
;
55 class IDocumentFieldsAccess
;
56 class IDocumentContentOperations
;
57 class IDocumentStylePoolAccess
;
58 class IDocumentStatistics
;
59 class IDocumentUndoRedo
;
60 class IDocumentListItems
;
61 class IDocumentOutlineNodes
;
72 class SwPagePreViewPrtData
;
79 class SvtAccessibilityOptions
;
80 class SwPagePreviewLayout
;
84 struct SwAccessibilityOptions
;
88 class SwAccessibleMap
;
92 class OldStylePrintAdaptor
;
96 // Define for flags needed in ctor or layers below.
97 // Currently the PreView flag is needed for DrawPage.
98 #define VSHELLFLAG_ISPREVIEW ((long)0x1)
99 #define VSHELLFLAG_SHARELAYOUT ((long)0x2)//swmod 080125 flag
100 typedef boost::shared_ptr
<SwRootFrm
> SwRootFrmPtr
;
102 class SW_DLLPUBLIC ViewShell
: public Ring
104 friend void SetOutDev( ViewShell
*pSh
, OutputDevice
*pOut
);
105 friend void SetOutDevAndWin( ViewShell
*pSh
, OutputDevice
*pOut
,
106 Window
*pWin
, sal_uInt16 nZoom
);
108 friend class SwViewImp
;
109 friend class SwLayIdle
;
111 // For setting visible area for page preview paint.
112 friend class SwPagePreviewLayout
;
115 // Set SwVisArea in order to enable clean formatting before printing.
116 friend void SetSwVisArea( ViewShell
*pSh
, const SwRect
&, sal_Bool bPDFExport
= sal_False
);
118 static BitmapEx
* pReplaceBmp
; // replaced display of still loaded images
119 static BitmapEx
* pErrorBmp
; // error display of missed images
121 static sal_Bool bLstAct
; // sal_True if EndAction of last Shell
122 // i.e. if the EndActions of the other
123 // Shells on the document are through.
125 Point aPrtOffst
; // Ofst for Printer,
126 // non-printable margin.
127 Size aBrowseBorder
; // Border for frame documents.
130 SfxViewShell
*pSfxViewShell
;
131 SwViewImp
*pImp
; // Core-internals of ViewShell.
132 // The pointer is never 0.
134 Window
*pWin
; // = 0 during printing or pdf export
135 OutputDevice
*pOut
; // Window, Printer, VirtDev, ...
136 OutputDevice
* mpTmpRef
; // Temporariy reference device. Is used
137 // during (printer depending) prospect
138 // and page preview printing
139 // (because a scaling has to be set at
140 // the original printer)
143 SwAccessibilityOptions
* pAccOptions
;
146 sal_Bool bDocSizeChgd
:1; // For DocChgNotify(): Announce new DocSize
147 // at EndAction to DocMDI.
148 sal_Bool bPaintWorks
:1; // Normal Painting if sal_True,
149 // remember Paint if sal_False.
150 sal_Bool bPaintInProgress
:1; // Block any double paint.
151 sal_Bool bViewLocked
:1; // Lock visible range;
152 // in this case MakeVisible is ineffectual.
153 sal_Bool bInEndAction
:1; // Avoid problems, cf. viewsh.cxx.
154 sal_Bool bPreView
:1; // If sal_True it is a PreView-ViewShell.
155 sal_Bool bFrameView
:1; // If sal_True it is a (HTML-)Frame.
156 sal_Bool bEnableSmooth
:1; // Disable SmoothScroll, e.g. for drag
158 sal_Bool bEndActionByVirDev
:1; // Paints from EndAction always via virtual device
159 sal_Bool bShowHeaderFooterSeparator
;
160 sal_Bool bHeaderFooterEdit
;
161 // (e.g. when browsing).
163 // boolean, indicating that class in in constructor.
164 bool mbInConstructor
:1;
166 SdrPaintWindow
* mpTargetPaintWindow
;
167 OutputDevice
* mpBufferedOut
;
169 SwRootFrmPtr pLayout
; //swmod 080116
171 // Initialization; called by the diverse constructors.
172 SW_DLLPRIVATE
void Init( const SwViewOption
*pNewOpt
);
174 inline void ResetInvalidRect();
176 SW_DLLPRIVATE
void Reformat(); // Invalidates complete Layout (ApplyViewOption).
178 SW_DLLPRIVATE
void PaintDesktop( const SwRect
& ); // Collect values for painting of desktop
180 // PaintDesktop split. This pars is also used by PreViewPage.
181 SW_DLLPRIVATE
void _PaintDesktop( const SwRegionRects
&rRegion
);
183 SW_DLLPRIVATE sal_Bool
CheckInvalidForPaint( const SwRect
& ); // Direct Paint or rather
184 // trigger an action.
186 SW_DLLPRIVATE
void PrepareForPrint( const SwPrintData
&rOptions
);
188 SW_DLLPRIVATE
void ImplApplyViewOptions( const SwViewOption
&rOpt
);
191 static ShellResource
* pShellRes
; // Resources for the Shell.
192 static Window
* pCareWindow
; // Avoid this window.
194 SwRect aVisArea
; // The modern version of VisArea.
195 SwDoc
*pDoc
; // The document; never 0.
197 sal_uInt16 nStartAction
; // != 0 if at least one ::com::sun::star::chaos::Action is active.
198 sal_uInt16 nLockPaint
; // != 0 if Paint is locked.
203 SwViewImp
*Imp() { return pImp
; }
204 const SwViewImp
*Imp() const { return pImp
; }
206 const SwNodes
& GetNodes() const;
208 // After change of printer; by Doc.
209 void InitPrt( OutputDevice
*pOutDev
);
211 // Bracketing of actions belonging together.
212 inline void StartAction();
213 void ImplStartAction();
214 inline void EndAction( const sal_Bool bIdleEnd
= sal_False
);
215 void ImplEndAction( const sal_Bool bIdleEnd
= sal_False
);
216 sal_uInt16
ActionCount() const { return nStartAction
; }
217 sal_Bool
ActionPend() const { return nStartAction
!= 0; }
218 sal_Bool
IsInEndAction() const { return bInEndAction
; }
220 void SetEndActionByVirDev( sal_Bool b
) { bEndActionByVirDev
= b
; }
221 sal_Bool
IsEndActionByVirDev() { return bEndActionByVirDev
; }
223 // The ActionCount for all Shells is temporarily set to zero and then
224 // restored at the RootFrame via UNO.
225 void SetRestoreActions(sal_uInt16 nSet
);
226 sal_uInt16
GetRestoreActions() const;
228 inline sal_Bool
HasInvalidRect() const { return aInvalidRect
.HasArea(); }
229 void ChgHyphenation() { Reformat(); }
230 void ChgNumberDigits();
232 sal_Bool
AddPaintRect( const SwRect
&rRect
);
234 void InvalidateWindows( const SwRect
&rRect
);
236 //////////////////////////////////////////////////////////////////////////////
237 // #i72754# set of Pre/PostPaints with lock counter and initial target OutDev
239 std::stack
<Region
> mPrePostPaintRegions
; // acts also as a lock counter (empty == not locked)
240 OutputDevice
* mpPrePostOutDev
;
241 MapMode maPrePostMapMode
;
244 void DLPrePaint2(const Region
& rRegion
);
245 void DLPostPaint2(bool bPaintFormLayer
);
246 const MapMode
& getPrePostMapMode() const { return maPrePostMapMode
; }
247 //////////////////////////////////////////////////////////////////////////////
249 virtual void Paint(const Rectangle
&rRect
);
250 sal_Bool
IsPaintInProgress() const { return bPaintInProgress
; }
251 bool IsDrawingLayerPaintInProgress() const { return !mPrePostPaintRegions
.empty(); }
253 // Notification that visible area has been changed.
254 // VisArea is reset, after that scrolling takes place.
255 // The passed rect is situated on pixel borders
256 // in order to avoid pixel errors when scrolling.
257 virtual void VisPortChgd( const SwRect
& );
258 sal_Bool
SmoothScroll( long lXDiff
, long lYDiff
, const Rectangle
* );//Browser
259 void EnableSmooth( sal_Bool b
) { bEnableSmooth
= b
; }
261 const SwRect
& VisArea() const { return aVisArea
; }
263 // If necessary scroll until passed Rect is situated in visible sector.
264 void MakeVisible( const SwRect
& );
266 // At nearest occasion pass new document size to UI.
267 void SizeChgNotify();
268 void UISizeNotify(); // Passing of current size.
270 Point
GetPagePos( sal_uInt16 nPageNum
) const;
272 sal_uInt16
GetNumPages(); // Ask count of current pages from layout.
273 sal_Bool
IsDummyPage( sal_uInt16 nPageNum
) const; // An empty page?
275 // Invalidate first visible page for all Shells in ring.
276 void SetFirstVisPageInvalid();
278 SwRootFrm
*GetLayout() const;// swmod 080116
279 sal_Bool
IsNewLayout() const; // Has Layout been loaded or created?
281 Size
GetDocSize() const; // Get document size.
283 void CalcLayout(); // Force complete formatting of layout.
285 sal_uInt16
GetPageCount() const;
287 const Size
GetPageSize( sal_uInt16 nPageNum
, bool bSkipEmptyPages
) const;
289 inline SwDoc
*GetDoc() const { return pDoc
; } //Never 0.
291 /** Provides access to the document setting interface
293 const IDocumentSettingAccess
* getIDocumentSettingAccess() const;
294 IDocumentSettingAccess
* getIDocumentSettingAccess();
296 /** Provides access to the document device interface
298 const IDocumentDeviceAccess
* getIDocumentDeviceAccess() const;
299 IDocumentDeviceAccess
* getIDocumentDeviceAccess();
301 /** Provides access to the document bookmark interface
303 const IDocumentMarkAccess
* getIDocumentMarkAccess() const;
304 IDocumentMarkAccess
* getIDocumentMarkAccess();
306 /** Provides access to the document draw model interface
308 const IDocumentDrawModelAccess
* getIDocumentDrawModelAccess() const;
309 IDocumentDrawModelAccess
* getIDocumentDrawModelAccess();
311 /** Provides access to the document redline interface
313 const IDocumentRedlineAccess
* getIDocumentRedlineAccess() const;
314 IDocumentRedlineAccess
* getIDocumentRedlineAccess();
316 /** Provides access to the document layout interface
318 const IDocumentLayoutAccess
* getIDocumentLayoutAccess() const;
319 IDocumentLayoutAccess
* getIDocumentLayoutAccess();
321 /** Provides access to the document fields administration interface
323 const IDocumentFieldsAccess
* getIDocumentFieldsAccess() const;
325 /** Provides access to the content operations interface
327 IDocumentContentOperations
* getIDocumentContentOperations();
329 /** Provides access to the document style pool interface
331 IDocumentStylePoolAccess
* getIDocumentStylePoolAccess();
333 /** Provides access to the document statistics interface
335 const IDocumentStatistics
* getIDocumentStatistics() const;
337 /** Provides access to the document undo/redo interface
339 IDocumentUndoRedo
const& GetIDocumentUndoRedo() const;
340 IDocumentUndoRedo
& GetIDocumentUndoRedo();
342 const IDocumentListItems
* getIDocumentListItemsAccess() const;
343 const IDocumentOutlineNodes
* getIDocumentOutlineNodesAccess() const;
345 // 1. GetRefDev: Either the printer or the virtual device from the doc
346 // 2. GetWin: Available if we not printing
347 // 3. GetOut: Printer, Window or Virtual device
348 OutputDevice
& GetRefDev() const;
349 inline Window
* GetWin() const { return pWin
; }
350 inline OutputDevice
* GetOut() const { return pOut
; }
352 static inline sal_Bool
IsLstEndAction() { return ViewShell::bLstAct
; }
354 // Change of all page descriptors.
355 void ChgAllPageOrientation( sal_uInt16 eOri
);
356 void ChgAllPageSize( Size
&rSz
);
358 // Printing of one page.
359 // bIsPDFExport == true is: do PDF Export (no printing!)
360 sal_Bool
PrintOrPDFExport( OutputDevice
*pOutDev
,
361 SwPrintData
const& rPrintData
,
362 sal_Int32 nRenderer
/* offset in vector of pages to print */ );
364 // Printing of one brochure page.
365 void PrintProspect( OutputDevice
*pOutDev
, const SwPrintData
&rPrintData
,
366 sal_Int32 nRenderer
/* offset in vector of page pairs for prospect printing */ );
368 // Printing for OLE 2.0.
369 static void PrtOle2( SwDoc
*pDoc
, const SwViewOption
*pOpt
, const SwPrintData
& rOptions
,
370 OutputDevice
* pOleOut
, const Rectangle
& rRect
);
372 // Fill temporary doc with selected text for Print or PDF export.
373 SwDoc
* FillPrtDoc( SwDoc
* pPrtDoc
, const SfxPrinter
* pPrt
);
375 // Called internally for Shell. Formats pages.
376 void CalcPagesForPrint( sal_uInt16 nMax
);
379 void UpdateFlds(sal_Bool bCloseDB
= sal_False
);
380 sal_Bool
IsAnyFieldInDoc() const;
381 // Update all charts, for that exists any table.
382 void UpdateAllCharts();
383 sal_Bool
HasCharts() const;
385 // DOCUMENT COMPATIBILITY FLAGS START
387 // Add or maximize paragraph spacing?
388 void SetParaSpaceMax( bool bNew
);
390 // Add or maximize paragraph spacing?
391 void SetParaSpaceMaxAtPages( bool bNew
);
393 // Compatible behaviour of tabs.
394 void SetTabCompat( bool bNew
);
396 // Font metric attribute "External Leading" should be considered.
397 void SetAddExtLeading( bool bNew
);
399 // Formatting by virtual device or printer.
400 void SetUseVirDev( bool nNew
);
402 // Adding paragraph and table spacing at bottom
404 void SetAddParaSpacingToTableCells( bool _bAddParaSpacingToTableCells
);
406 // Former formatting of text lines with
407 // proportional line spacing or not.
408 void SetUseFormerLineSpacing( bool _bUseFormerLineSpacing
);
410 // Former object positioning.
411 void SetUseFormerObjectPositioning( bool _bUseFormerObjPos
);
413 void SetConsiderWrapOnObjPos( bool _bConsiderWrapOnObjPos
);
415 void SetUseFormerTextWrapping( bool _bUseFormerTextWrapping
);
417 void SetDoNotJustifyLinesWithManualBreak( bool _bDoNotJustifyLinesWithManualBreak
);
419 // DOCUMENT COMPATIBILITY FLAGS END
421 // Calls Idle-formatter of Layout.
424 inline const SwViewOption
*GetViewOptions() const { return pOpt
; }
425 virtual void ApplyViewOptions( const SwViewOption
&rOpt
);
426 void SetUIOptions( const SwViewOption
&rOpt
);
427 virtual void SetReadonlyOption(sal_Bool bSet
); // Set readonly-bit of ViewOptions.
428 void SetPDFExportOption(sal_Bool bSet
); // Set/reset PDF export mode.
429 void SetPrtFormatOption(sal_Bool bSet
); // Set PrtFormat-Bit of ViewOptions.
430 void SetReadonlySelectionOption(sal_Bool bSet
); // Change the selection mode in readonly docs.
432 const SwAccessibilityOptions
* GetAccessibilityOptions() const { return pAccOptions
;}
434 static void SetShellRes( ShellResource
* pRes
) { pShellRes
= pRes
; }
435 static ShellResource
* GetShellRes();
437 static void SetCareWin( Window
* pNew
);
438 static Window
* GetCareWin(ViewShell
& rVSh
)
439 { return pCareWindow
? pCareWindow
: CareChildWin(rVSh
); }
440 static Window
* CareChildWin(ViewShell
& rVSh
);
442 inline SfxViewShell
*GetSfxViewShell() { return pSfxViewShell
; }
443 inline void SetSfxViewShell(SfxViewShell
*pNew
) { pSfxViewShell
= pNew
; }
445 // Selection of Draw ::com::sun::star::script::Engine has been changed.
446 virtual void DrawSelChanged();
448 SwPagePreviewLayout
* PagePreviewLayout();
450 /** adjust view options for page preview
452 Because page preview should show the document as it is printed -
453 page preview is print preview -, the view options are adjusted to the
454 same as for printing.
456 @param _rPrintOptions
457 input parameter - constant reference to print options, to which the
458 view option will be adjusted.
460 void AdjustOptionsForPagePreview( SwPrintData
const& rPrintOptions
);
462 sal_Bool
IsViewLocked() const { return bViewLocked
; }
463 void LockView( sal_Bool b
) { bViewLocked
= b
; }
465 inline void LockPaint();
466 void ImplLockPaint();
467 inline void UnlockPaint( sal_Bool bVirDev
= sal_False
);
468 void ImplUnlockPaint( sal_Bool bVirDev
);
469 sal_Bool
IsPaintLocked() const { return nLockPaint
!= 0; }
471 // Get/set DrawView and PageView.
472 sal_Bool
HasDrawView() const;
475 // DrawView may be used at UI.
476 SdrView
*GetDrawView();
477 const SdrView
*GetDrawView() const { return ((ViewShell
*)this)->GetDrawView(); }
479 // Take care that MarkList is up-to-date in any case (Bug 57153).
480 SdrView
*GetDrawViewWithValidMarkList();
482 // Query attribute pool.
483 inline const SfxItemPool
& GetAttrPool() const;
484 SfxItemPool
& GetAttrPool();
486 sal_Bool
IsPreView() const { return bPreView
; }
488 sal_Bool
IsFrameView() const { return bFrameView
; }
489 void SetFrameView( const Size
& rBrowseBorder
)
490 { bFrameView
= sal_True
; aBrowseBorder
= rBrowseBorder
; }
492 // Makes the necessary invalidations:
493 // If BrowseMode has changed bBrowseChgd == sal_True
494 // or bBrowseChgd == sal_False in BrowseMode
495 // if proportions have changed.
496 void CheckBrowseView( sal_Bool bBrowseChgd
);
498 const Size
& GetBrowseBorder() const;
499 sal_Int32
GetBrowseWidth() const;
500 void SetBrowseBorder( const Size
& rNew
);
502 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
504 ::com::sun::star::uno::Reference
<
505 ::com::sun::star::accessibility::XAccessible
>
506 CreateAccessiblePreview();
508 void ShowPreViewSelection( sal_uInt16 nSelPage
);
509 void InvalidateAccessibleFocus();
511 // Apply Accessiblity options.
512 void ApplyAccessiblityOptions(SvtAccessibilityOptions
& rAccessibilityOptions
);
514 /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
519 input parameter - paragraph frame, for which the relation CONTENT_FLOWS_FROM
520 has to be invalidated.
521 If NULL, no CONTENT_FLOWS_FROM relation has to be invalidated
524 input parameter - paragraph frame, for which the relation CONTENT_FLOWS_TO
525 has to be invalidated.
526 If NULL, no CONTENT_FLOWS_TO relation has to be invalidated
528 void InvalidateAccessibleParaFlowRelation( const SwTxtFrm
* _pFromTxtFrm
,
529 const SwTxtFrm
* _pToTxtFrm
);
531 /** invalidate text selection for paragraphs
535 void InvalidateAccessibleParaTextSelection();
537 /** invalidate attributes for paragraphs and paragraph's characters
539 usage also for changes of the attributes of
540 paragraph's characters.
545 input parameter - paragraph frame, whose attributes have changed
547 void InvalidateAccessibleParaAttrs( const SwTxtFrm
& rTxtFrm
);
549 SwAccessibleMap
* GetAccessibleMap();
551 ViewShell( ViewShell
&, Window
*pWin
= 0, OutputDevice
*pOut
= 0,
553 ViewShell( SwDoc
& rDoc
, Window
*pWin
,
554 const SwViewOption
*pOpt
= 0, OutputDevice
*pOut
= 0,
556 virtual ~ViewShell();
558 sal_Int32
GetPageNumAndSetOffsetForPDF( OutputDevice
& rOut
, const SwRect
& rRect
) const;
560 inline bool IsInConstructor() const { return mbInConstructor
; }
562 static const BitmapEx
& GetReplacementBitmap( bool bIsErrorState
);
563 static void DeleteReplacementBitmaps();
565 const SwPostItMgr
* GetPostItMgr() const { return (const_cast<ViewShell
*>(this))->GetPostItMgr(); }
566 SwPostItMgr
* GetPostItMgr();
568 void ToggleHeaderFooterEdit( );
569 sal_Bool
IsHeaderFooterEdit( ) const { return bHeaderFooterEdit
; }
570 sal_Bool
IsShowHeaderFooterSeparator( ) { return bShowHeaderFooterSeparator
; }
571 virtual void SetShowHeaderFooterSeparator( sal_Bool bShow
) { bShowHeaderFooterSeparator
= bShow
; }
574 //---- class CurrShell manages global ShellPointer -------------------
582 CurrShell( ViewShell
*pNew
);
586 inline void ViewShell::ResetInvalidRect()
588 aInvalidRect
.Clear();
591 inline void ViewShell::StartAction()
593 if ( !nStartAction
++ )
596 inline void ViewShell::EndAction( const sal_Bool bIdleEnd
)
598 if( 0 == (nStartAction
- 1) )
599 ImplEndAction( bIdleEnd
);
603 inline void ViewShell::LockPaint()
608 inline void ViewShell::UnlockPaint( sal_Bool bVirDev
)
610 if ( 0 == --nLockPaint
)
611 ImplUnlockPaint( bVirDev
);
613 inline const SfxItemPool
& ViewShell::GetAttrPool() const
615 return ((ViewShell
*)this)->GetAttrPool();
620 #endif // SW_VIEWSH_HXX
622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */