1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewmdi.cxx,v $
10 * $Revision: 1.24.140.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
38 #include "hintids.hxx"
39 #include <vcl/svapp.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <svx/ruler.hxx>
42 #include <svx/lrspitem.hxx>
43 #include <svx/srchitem.hxx>
44 #include <sfx2/request.hxx>
45 #include <swmodule.hxx>
53 #include <viewopt.hxx>
60 #include <pagedesc.hxx>
63 #include <workctrl.hxx>
64 #include <usrpref.hxx>
83 #include <globals.hrc>
86 #include <IDocumentSettingAccess.hxx>
87 #include <PostItMgr.hxx>
90 USHORT
SwView::nMoveType
= NID_PGE
;
91 sal_Int32
SwView::nActMark
= 0;
94 #define VIEW_IMAGECOLOR COL_LIGHTBLUE
96 using namespace ::com::sun::star::uno
;
97 using namespace ::com::sun::star::frame
;
99 void SwView::SetZoom( SvxZoomType eZoomType
, short nFactor
, BOOL bViewOnly
)
101 _SetZoom( GetEditWin().GetOutputSizePixel(), eZoomType
, nFactor
, bViewOnly
);
104 void SwView::_SetZoom( const Size
&rEditSize
, SvxZoomType eZoomType
,
105 short nFactor
, BOOL bViewOnly
)
107 BOOL bUnLockView
= !pWrtShell
->IsViewLocked();
108 pWrtShell
->LockView( TRUE
);
109 pWrtShell
->LockPaint();
112 ACT_KONTEXT(pWrtShell
);
116 BOOL bWeb
= 0 != PTR_CAST(SwWebView
, this);
117 SwMasterUsrPref
*pUsrPref
= (SwMasterUsrPref
*)SW_MOD()->GetUsrPref(bWeb
);
119 const SwPageDesc
&rDesc
= pWrtShell
->GetPageDesc( pWrtShell
->GetCurPageDesc() );
120 const SvxLRSpaceItem
&rLRSpace
= rDesc
.GetMaster().GetLRSpace();
121 const SwViewOption
*pOpt
= pWrtShell
->GetViewOptions();
122 long lLeftMargin
= 0;
124 if( eZoomType
!= SVX_ZOOM_PERCENT
)
126 const bool bAutomaticViewLayout
= 0 == pOpt
->GetViewLayoutColumns();
128 const SwRect
aPageRect( pWrtShell
->GetAnyCurRect( RECT_PAGE_CALC
) );
129 const SwRect
aRootRect( pWrtShell
->GetAnyCurRect( RECT_PAGES_AREA
) );
130 Size
aPageSize( aPageRect
.SSize() );
131 Size
aRootSize( aRootRect
.SSize() );
133 //mod #i6193# added sidebar width
134 SwPostItMgr
* pPostItMgr
= GetPostItMgr();
135 if (pPostItMgr
->HasNotes() && pPostItMgr
->ShowNotes())
136 aPageSize
.Width() += pPostItMgr
->GetSidebarWidth() + pPostItMgr
->GetSidebarBorderWidth();
138 const MapMode
aTmpMap( MAP_TWIP
);
139 const Size
aWindowSize( GetEditWin().PixelToLogic( rEditSize
, aTmpMap
) );
141 if( nsUseOnPage::PD_MIRROR
== rDesc
.GetUseOn() ) // gespiegelte Seiten
143 const SvxLRSpaceItem
&rLeftLRSpace
= rDesc
.GetLeft().GetLRSpace();
144 aPageSize
.Width() += Abs( long(rLeftLRSpace
.GetLeft()) - long(rLRSpace
.GetLeft()) );
147 if( SVX_ZOOM_OPTIMAL
== eZoomType
)
149 if (pPostItMgr
->HasNotes() && pPostItMgr
->ShowNotes())
151 lLeftMargin
= long(rLRSpace
.GetLeft()) + aPageRect
.Left() + nLeftOfst
;
155 aPageSize
.Width() -= ( rLRSpace
.GetLeft() + rLRSpace
.GetRight() + nLeftOfst
* 2 );
156 lLeftMargin
= long(rLRSpace
.GetLeft()) + aPageRect
.Left() + nLeftOfst
;
158 nFac
= aWindowSize
.Width() * 100 / aPageSize
.Width();
160 else if(SVX_ZOOM_WHOLEPAGE
== eZoomType
|| SVX_ZOOM_PAGEWIDTH
== eZoomType
)
162 const long nOf
= DOCUMENTBORDER
* 2L;
163 long nTmpWidth
= bAutomaticViewLayout
? aPageSize
.Width() : aRootSize
.Width();
165 aPageSize
.Height() += nOf
;
166 nFac
= aWindowSize
.Width() * 100 / nTmpWidth
;
168 if ( SVX_ZOOM_WHOLEPAGE
== eZoomType
)
170 long nVisPercent
= aWindowSize
.Height() * 100 / aPageSize
.Height();
171 nFac
= Min( nFac
, nVisPercent
);
174 else /*if( SVX_ZOOM_PAGEWIDTH_NOBORDER == eZoomType )*/
176 const long nTmpWidth
= bAutomaticViewLayout
? aPageSize
.Width() : aRootSize
.Width();
177 nFac
= aWindowSize
.Width() * 100 / nTmpWidth
;
181 nFac
= Max( long( MINZOOM
), nFac
);
183 SwViewOption
aOpt( *pOpt
);
184 if ( !GetViewFrame()->GetFrame()->IsInPlace() )
186 //MasterUsrPrefs updaten UND DANACH die ViewOptions der aktuellen
189 (USHORT(nFac
) != pUsrPref
->GetZoom() ||
190 BYTE (eZoomType
) != pUsrPref
->GetZoomType()) )
192 pUsrPref
->SetZoom ( USHORT(nFac
) );
193 pUsrPref
->SetZoomType( eZoomType
);
194 SW_MOD()->ApplyUsrPref( *pUsrPref
,
196 bViewOnly
? VIEWOPT_DEST_VIEW_ONLY
: 0 );
197 pUsrPref
->SetModified();
199 if ( pOpt
->GetZoom() != (USHORT
) nFac
)
201 aOpt
.SetZoom ( USHORT(nFac
) );
202 aOpt
.SetReadonly(pOpt
->IsReadonly());
203 pWrtShell
->ApplyViewOptions( aOpt
);
205 if ( eZoomType
!= SVX_ZOOM_PERCENT
)
209 if ( eZoomType
== SVX_ZOOM_WHOLEPAGE
)
210 aPos
.Y() = pWrtShell
->GetAnyCurRect(RECT_PAGE
).Top() - DOCUMENTBORDER
;
213 //sicherstellen, dass sich der Cursor im sichtbaren
214 //Bereich befindet, damit nur 1x gescrollt wird
215 aPos
.X() = lLeftMargin
;
216 const SwRect
&rCharRect
= pWrtShell
->GetCharRect();
217 if ( rCharRect
.Top() > GetVisArea().Bottom() ||
218 rCharRect
.Bottom() < aPos
.Y() )
219 aPos
.Y() = rCharRect
.Top() - rCharRect
.Height();
221 aPos
.Y() = GetVisArea().Top();
225 // OS: Notloesung - in CalcVisArea wird u.U. wieder SetZoom gerufen und
226 // dann werden falsche Werte eingestellt
227 ((SwViewOption
*)pWrtShell
->GetViewOptions())->SetZoomType( eZoomType
);
228 CalcVisArea( rEditSize
); //fuer das Neuberechnen des sichtbaren Bereiches
230 else if ( USHORT(nFac
) != pOpt
->GetZoom() )
232 aOpt
.SetZoom ( USHORT(nFac
) );
233 pWrtShell
->ApplyViewOptions( aOpt
);
236 const Fraction
aFrac( nFac
, 100 );
237 pVRuler
->SetZoom( aFrac
);
238 pVRuler
->ForceUpdate();
239 pHRuler
->SetZoom( aFrac
);
240 pHRuler
->ForceUpdate();
241 ((SwViewOption
*)pWrtShell
->GetViewOptions())->SetZoomType( eZoomType
);
243 pWrtShell
->UnlockPaint();
245 pWrtShell
->LockView( FALSE
);
249 mpPostItMgr
->Rescale();
250 mpPostItMgr
->CalcRects();
251 mpPostItMgr
->LayoutPostIts();
254 // eZoom = eZoomType;
257 void SwView::SetViewLayout( USHORT nColumns
, bool bBookMode
, BOOL bViewOnly
)
259 const BOOL bUnLockView
= !pWrtShell
->IsViewLocked();
260 pWrtShell
->LockView( TRUE
);
261 pWrtShell
->LockPaint();
265 ACT_KONTEXT(pWrtShell
);
267 if ( !GetViewFrame()->GetFrame()->IsInPlace() && !bViewOnly
)
269 const BOOL bWeb
= 0 != PTR_CAST(SwWebView
, this);
270 SwMasterUsrPref
*pUsrPref
= (SwMasterUsrPref
*)SW_MOD()->GetUsrPref(bWeb
);
272 //MasterUsrPrefs updaten UND DANACH die ViewOptions der aktuellen
274 if ( nColumns
!= pUsrPref
->GetViewLayoutColumns() ||
275 bBookMode
!= pUsrPref
->IsViewLayoutBookMode() )
277 pUsrPref
->SetViewLayoutColumns( nColumns
);
278 pUsrPref
->SetViewLayoutBookMode( bBookMode
);
279 SW_MOD()->ApplyUsrPref( *pUsrPref
,
281 bViewOnly
? VIEWOPT_DEST_VIEW_ONLY
: 0 );
282 pUsrPref
->SetModified();
286 const SwViewOption
*pOpt
= pWrtShell
->GetViewOptions();
288 if ( nColumns
!= pOpt
->GetViewLayoutColumns() ||
289 bBookMode
!= pOpt
->IsViewLayoutBookMode() )
291 SwViewOption
aOpt( *pOpt
);
292 aOpt
.SetViewLayoutColumns( nColumns
);
293 aOpt
.SetViewLayoutBookMode( bBookMode
);
294 pWrtShell
->ApplyViewOptions( aOpt
);
297 pVRuler
->ForceUpdate();
298 pHRuler
->ForceUpdate();
302 pWrtShell
->UnlockPaint();
304 pWrtShell
->LockView( FALSE
);
306 SfxBindings
& rBnd
= GetViewFrame()->GetBindings();
307 rBnd
.Invalidate( SID_ATTR_VIEWLAYOUT
);
308 rBnd
.Invalidate( SID_ATTR_ZOOMSLIDER
);
312 * Scrollbar - Handler
315 int SwView::_CreateScrollbar( BOOL bHori
)
317 Window
*pMDI
= &GetViewFrame()->GetWindow();
318 SwScrollbar
** ppScrollbar
= bHori
? &pHScrollbar
: &pVScrollbar
;
320 ASSERT( !*ppScrollbar
, "vorher abpruefen!" )
323 CreatePageButtons( !bShowAtResize
);
325 *ppScrollbar
= new SwScrollbar( pMDI
, bHori
);
328 (*ppScrollbar
)->SetScrollHdl( LINK( this, SwView
, EndScrollHdl
));
330 (*ppScrollbar
)->SetScrollHdl( LINK( this, SwView
, ScrollHdl
));
331 (*ppScrollbar
)->SetEndScrollHdl( LINK( this, SwView
, EndScrollHdl
));
333 (*ppScrollbar
)->EnableDrag( TRUE
);
338 // Scrollbar muss nochmals getestet werden, da im InvalidateBorder u.U. der
339 // Scrollbar wieder geloescht wurde
340 if ( !bShowAtResize
&& (*ppScrollbar
))
341 (*ppScrollbar
)->ExtendedShow();
346 void SwView::CreatePageButtons(BOOL bShow
)
348 Window
*pMDI
= &GetViewFrame()->GetWindow();
349 pPageUpBtn
= new SwHlpImageButton(pMDI
, SW_RES( BTN_PAGEUP
), TRUE
);
350 pPageUpBtn
->SetHelpId(HID_SCRL_PAGEUP
);
351 pPageDownBtn
= new SwHlpImageButton(pMDI
, SW_RES( BTN_PAGEDOWN
), FALSE
);
352 pPageDownBtn
->SetHelpId(HID_SCRL_PAGEDOWN
);
353 Reference
< XFrame
> xFrame
= GetViewFrame()->GetFrame()->GetFrameInterface();
354 pNaviBtn
= new SwNaviImageButton(pMDI
, xFrame
);
355 pNaviBtn
->SetHelpId(HID_SCRL_NAVI
);
356 Link
aLk( LINK( this, SwView
, BtnPage
) );
357 pPageUpBtn
->SetClickHdl( aLk
);
358 pPageDownBtn
->SetClickHdl( aLk
);
359 if(nMoveType
!= NID_PGE
)
361 Color
aColor(VIEW_IMAGECOLOR
);
362 SetImageButtonColor(aColor
);
368 pPageDownBtn
->Show();
376 IMPL_LINK( SwView
, BtnPage
, Button
*, pButton
)
378 // #i75416# move the execution of the search to an asynchronously called static link
379 bool* pbNext
= new bool( (pButton
== pPageDownBtn
) );
380 Application::PostUserEvent( STATIC_LINK(this, SwView
, MoveNavigationHdl
), pbNext
);
383 /*-----------------20.06.97 10:46-------------------
385 --------------------------------------------------*/
386 IMPL_STATIC_LINK( SwView
, MoveNavigationHdl
, bool *, pbNext
)
390 bool bNext
= *pbNext
;
391 SwWrtShell
& rSh
= pThis
->GetWrtShell();
395 bNext
? pThis
->PhyPageDown() : pThis
->PhyPageUp();
400 rSh
.MoveTable(fnTableNext
, fnTableStart
);
402 rSh
.MoveTable(fnTablePrev
, fnTableStart
);
408 USHORT eType
= GOTOOBJ_FLY_FRM
;
409 if(nMoveType
== NID_GRF
)
410 eType
= GOTOOBJ_FLY_GRF
;
411 else if(nMoveType
== NID_OLE
)
412 eType
= GOTOOBJ_FLY_OLE
;
413 BOOL bSuccess
= bNext
?
414 rSh
.GotoNextFly(eType
) :
415 rSh
.GotoPrevFly(eType
);
419 rSh
.EnterSelFrmMode();
426 nMoveType
== NID_DRW
?
427 GOTOOBJ_DRAW_SIMPLE
:
428 GOTOOBJ_DRAW_CONTROL
);
433 rSh
.MoveRegion(fnRegionNext
, fnRegionStart
);
435 rSh
.MoveRegion(fnRegionPrev
, fnRegionStart
);
440 pThis
->GetViewFrame()->GetDispatcher()->Execute(bNext
?
446 bNext
? rSh
.GotoNextOutline() : rSh
.GotoPrevOutline();
449 bNext
? rSh
.GoNextCrsr() : rSh
.GoPrevCrsr();
454 rSh
.GotoNextFtnAnchor() :
455 rSh
.GotoPrevFtnAnchor();
463 // collect navigator reminders
464 IDocumentMarkAccess
* const pMarkAccess
= rSh
.getIDocumentMarkAccess();
465 ::std::vector
< const ::sw::mark::IMark
* > vNavMarks
;
466 for( IDocumentMarkAccess::const_iterator_t ppMark
= pMarkAccess
->getMarksBegin();
467 ppMark
!= pMarkAccess
->getMarksEnd();
470 if( IDocumentMarkAccess::GetType(**ppMark
) == IDocumentMarkAccess::NAVIGATOR_REMINDER
)
471 vNavMarks
.push_back(ppMark
->get());
480 if (nActMark
>= MAX_MARKS
|| nActMark
>= static_cast<sal_Int32
>(vNavMarks
.size()))
486 if (nActMark
< 0 || nActMark
>= static_cast<sal_Int32
>(vNavMarks
.size()))
487 nActMark
= vNavMarks
.size()-1;
489 rSh
.GotoMark(vNavMarks
[nActMark
]);
495 SwMarginWin
* pPostIt
= pThis
->GetPostItMgr()->GetActivePostIt();
497 pThis
->GetPostItMgr()->SetActivePostIt(0);
498 SwFieldType
* pFldType
= rSh
.GetFldType(0, RES_POSTITFLD
);
499 if (rSh
.MoveFldType(pFldType
, bNext
))
500 pThis
->GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT
);
503 pThis
->GetPostItMgr()->SetActivePostIt(pPostIt
);
509 BOOL bBackward
= pSrchItem
->GetBackward();
510 if(rSh
.HasSelection() && !bNext
== rSh
.IsCrsrPtAtEnd())
512 pSrchItem
->SetBackward(!bNext
);
513 SfxRequest
aReq(FN_REPEAT_SEARCH
, SFX_CALLMODE_SLOT
, pThis
->GetPool());
514 pThis
->ExecSearch(aReq
);
515 pSrchItem
->SetBackward(bBackward
);
518 case NID_INDEX_ENTRY
:
519 rSh
.GotoNxtPrvTOXMark(bNext
);
522 case NID_TABLE_FORMULA
:
523 rSh
.GotoNxtPrvTblFormula( bNext
);
526 case NID_TABLE_FORMULA_ERROR
:
527 rSh
.GotoNxtPrvTblFormula( bNext
, TRUE
);
530 pThis
->pEditWin
->GrabFocus();
535 /*************************************************************************
537 |* SwView::CreateTab()
540 |* Ersterstellung VB 29.05.91
541 |* Letzte Aenderung OS 09.05.96
543 *************************************************************************/
545 int SwView::CreateTab()
547 pHRuler
->SetActive(GetFrame() && IsActive());
554 /*************************************************************************
559 |* Ersterstellung VB 29.05.91
560 |* Letzte Aenderung OS 09.05.96
562 *************************************************************************/
564 int SwView::KillTab()
571 void SwView::ChangeTabMetric( FieldUnit eUnit
)
573 if(pHRuler
->GetUnit() != eUnit
)
575 pHRuler
->SetUnit( eUnit
);
576 pHRuler
->Invalidate();
580 void SwView::ChangeVLinealMetric( FieldUnit eUnit
)
582 if(pVRuler
->GetUnit() != eUnit
)
584 pVRuler
->SetUnit( eUnit
);
585 pVRuler
->Invalidate();
588 /* -----------------------------07.04.01 17:09--------------------------------
590 ---------------------------------------------------------------------------*/
591 void SwView::GetVLinealMetric(FieldUnit
& eToFill
) const
593 eToFill
= pVRuler
->GetUnit();
595 /* -----------------------------07.04.01 17:09--------------------------------
597 ---------------------------------------------------------------------------*/
598 void SwView::GetHLinealMetric(FieldUnit
& eToFill
) const
600 eToFill
= pHRuler
->GetUnit();
602 /*************************************************************************
604 |* SwView::CreateVLineal()
607 |* Ersterstellung VB 29.05.91
609 *************************************************************************/
611 int SwView::CreateVLineal()
613 pHRuler
->SetBorderPos( pVRuler
->GetSizePixel().Width()-1 );
615 pVRuler
->SetActive(GetFrame() && IsActive());
621 /*************************************************************************
623 |* SwView::KillVLineal()
626 |* Ersterstellung VB 29.05.91
628 *************************************************************************/
630 int SwView::KillVLineal()
633 pHRuler
->SetBorderPos( 0 );
637 /*************************************************************************
639 |* SwView::ExecRulerClick()
642 |* Ersterstellung OS 15.06.95
645 *************************************************************************/
647 IMPL_LINK( SwView
, ExecRulerClick
, Ruler
*, pRuler
)
650 switch( pRuler
->GetClickType() )
652 case RULER_TYPE_DONTKNOW
:
653 case RULER_TYPE_OUTSIDE
:
654 case RULER_TYPE_INDENT
:
655 case RULER_TYPE_MARGIN1
:
656 case RULER_TYPE_MARGIN2
:
657 nDefPage
= TP_PARA_STD
;
660 nDefPage
= TP_TABULATOR
;
664 SfxUInt16Item
aDefPage(SID_PARA_DLG
, nDefPage
);
665 GetViewFrame()->GetDispatcher()->Execute( SID_PARA_DLG
,
666 SFX_CALLMODE_SYNCHRON
|SFX_CALLMODE_RECORD
,
672 /*-----------------20.02.97 09:11-------------------
674 --------------------------------------------------*/
676 USHORT
SwView::GetMoveType()
680 /*-----------------20.02.97 09:11-------------------
682 --------------------------------------------------*/
684 void SwView::SetMoveType(USHORT nSet
)
686 BOOL bLastPage
= nMoveType
== NID_PGE
;
688 BOOL bNewPage
= nMoveType
== NID_PGE
;
689 if(bNewPage
!= bLastPage
)
691 Color
aColor(bNewPage
? COL_BLACK
: VIEW_IMAGECOLOR
);
692 const TypeId aTypeId
= TYPE(SwView
);
693 SwView
* pView
= (SwView
*)SfxViewShell::GetFirst(&aTypeId
);
696 pView
->SetImageButtonColor(aColor
);
697 pView
= (SwView
*)SfxViewShell::GetNext(*pView
, &aTypeId
);
702 /*-----------------20.06.97 11:18-------------------
704 --------------------------------------------------*/
705 void SwView::SetActMark(sal_Int32 nSet
)
710 /*-----------------15.03.97 10:53-------------------
712 --------------------------------------------------*/
714 void SwView::SetImageButtonColor(Color
& rColor
)
718 pPageUpBtn
->SetControlForeground(rColor
);
719 pPageDownBtn
->SetControlForeground(rColor
);
722 /* -----------------------------2002/06/26 13:57------------------------------
724 ---------------------------------------------------------------------------*/
725 void SwView::ShowHScrollbar(sal_Bool bShow
)
727 DBG_ASSERT(pHScrollbar
, "Scrollbar invalid");
728 pHScrollbar
->ExtendedShow(bShow
);
730 /* -----------------------------2002/06/26 13:57------------------------------
732 ---------------------------------------------------------------------------*/
733 sal_Bool
SwView::IsHScrollbarVisible()const
735 DBG_ASSERT(pHScrollbar
, "Scrollbar invalid");
736 return pHScrollbar
->IsVisible( FALSE
) || pHScrollbar
->IsAuto();
738 /* -----------------------------2002/06/26 13:57------------------------------
740 ---------------------------------------------------------------------------*/
741 void SwView::ShowVScrollbar(sal_Bool bShow
)
743 DBG_ASSERT(pVScrollbar
, "Scrollbar invalid");
744 pVScrollbar
->ExtendedShow(bShow
);
745 pPageUpBtn
->Show(bShow
);
746 pPageDownBtn
->Show(bShow
);
747 pNaviBtn
->Show(bShow
);
749 /* -----------------------------2002/06/26 13:57------------------------------
751 ---------------------------------------------------------------------------*/
752 sal_Bool
SwView::IsVScrollbarVisible()const
754 DBG_ASSERT(pVScrollbar
, "Scrollbar invalid");
755 return pVScrollbar
->IsVisible( FALSE
);