1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include "hintids.hxx"
24 #include <vcl/svapp.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <svx/ruler.hxx>
27 #include <editeng/lrspitem.hxx>
28 #include <svl/srchitem.hxx>
29 #include <sfx2/request.hxx>
30 #include <swmodule.hxx>
34 #include <viewopt.hxx>
39 #include <pagedesc.hxx>
42 #include <workctrl.hxx>
43 #include <usrpref.hxx>
51 #include <globals.hrc>
53 #include <IDocumentSettingAccess.hxx>
54 #include <PostItMgr.hxx>
56 sal_uInt16
SwView::m_nMoveType
= NID_PGE
;
57 sal_Int32
SwView::m_nActMark
= 0;
60 #define VIEW_IMAGECOLOR COL_LIGHTBLUE
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::frame
;
65 void SwView::SetZoom( SvxZoomType eZoomType
, short nFactor
, sal_Bool bViewOnly
)
67 bool const bCrsrIsVisible(m_pWrtShell
->IsCrsrVisible());
68 _SetZoom( GetEditWin().GetOutputSizePixel(), eZoomType
, nFactor
, bViewOnly
);
69 // fdo#40465 force the cursor to stay in view whilst zooming
71 m_pWrtShell
->ShowCrsr();
74 void SwView::_SetZoom( const Size
&rEditSize
, SvxZoomType eZoomType
,
75 short nFactor
, sal_Bool bViewOnly
)
77 sal_Bool bUnLockView
= !m_pWrtShell
->IsViewLocked();
78 m_pWrtShell
->LockView( sal_True
);
79 m_pWrtShell
->LockPaint();
82 SwActContext
aActContext(m_pWrtShell
);
86 sal_Bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
87 SwMasterUsrPref
*pUsrPref
= (SwMasterUsrPref
*)SW_MOD()->GetUsrPref(bWeb
);
89 const SwPageDesc
&rDesc
= m_pWrtShell
->GetPageDesc( m_pWrtShell
->GetCurPageDesc() );
90 const SvxLRSpaceItem
&rLRSpace
= rDesc
.GetMaster().GetLRSpace();
91 const SwViewOption
*pOpt
= m_pWrtShell
->GetViewOptions();
94 if( eZoomType
!= SVX_ZOOM_PERCENT
)
96 const bool bAutomaticViewLayout
= 0 == pOpt
->GetViewLayoutColumns();
98 const SwRect
aPageRect( m_pWrtShell
->GetAnyCurRect( RECT_PAGE_CALC
) );
99 const SwRect
aRootRect( m_pWrtShell
->GetAnyCurRect( RECT_PAGES_AREA
) );
100 Size
aPageSize( aPageRect
.SSize() );
101 Size
aRootSize( aRootRect
.SSize() );
103 //mod #i6193# added sidebar width
104 SwPostItMgr
* pPostItMgr
= GetPostItMgr();
105 if (pPostItMgr
->HasNotes() && pPostItMgr
->ShowNotes())
106 aPageSize
.Width() += pPostItMgr
->GetSidebarWidth() + pPostItMgr
->GetSidebarBorderWidth();
108 const MapMode
aTmpMap( MAP_TWIP
);
109 const Size
aWindowSize( GetEditWin().PixelToLogic( rEditSize
, aTmpMap
) );
111 if( nsUseOnPage::PD_MIRROR
== rDesc
.GetUseOn() ) // gespiegelte Seiten
113 const SvxLRSpaceItem
&rLeftLRSpace
= rDesc
.GetLeft().GetLRSpace();
114 aPageSize
.Width() += std::abs( long(rLeftLRSpace
.GetLeft()) - long(rLRSpace
.GetLeft()) );
117 if( SVX_ZOOM_OPTIMAL
== eZoomType
)
119 if (!pPostItMgr
->HasNotes() || !pPostItMgr
->ShowNotes())
120 aPageSize
.Width() -= ( rLRSpace
.GetLeft() + rLRSpace
.GetRight() + nLeftOfst
* 2 );
121 lLeftMargin
= long(rLRSpace
.GetLeft()) + DOCUMENTBORDER
+ nLeftOfst
;
122 nFac
= aWindowSize
.Width() * 100 / aPageSize
.Width();
124 else if(SVX_ZOOM_WHOLEPAGE
== eZoomType
|| SVX_ZOOM_PAGEWIDTH
== eZoomType
)
126 const long nOf
= DOCUMENTBORDER
* 2L;
127 long nTmpWidth
= bAutomaticViewLayout
? aPageSize
.Width() : aRootSize
.Width();
129 aPageSize
.Height() += nOf
;
130 nFac
= aWindowSize
.Width() * 100 / nTmpWidth
;
132 if ( SVX_ZOOM_WHOLEPAGE
== eZoomType
)
134 long nVisPercent
= aWindowSize
.Height() * 100 / aPageSize
.Height();
135 nFac
= std::min( nFac
, nVisPercent
);
140 const long nTmpWidth
= bAutomaticViewLayout
? aPageSize
.Width() : aRootSize
.Width();
141 nFac
= aWindowSize
.Width() * 100 / nTmpWidth
;
145 nFac
= std::max( long( MINZOOM
), nFac
);
147 SwViewOption
aOpt( *pOpt
);
148 if ( !GetViewFrame()->GetFrame().IsInPlace() )
150 //MasterUsrPrefs updaten UND DANACH die ViewOptions der aktuellen
153 (sal_uInt16(nFac
) != pUsrPref
->GetZoom() ||
154 sal_uInt8 (eZoomType
) != pUsrPref
->GetZoomType()) )
156 pUsrPref
->SetZoom ( sal_uInt16(nFac
) );
157 pUsrPref
->SetZoomType( eZoomType
);
158 SW_MOD()->ApplyUsrPref( *pUsrPref
,
160 bViewOnly
? VIEWOPT_DEST_VIEW_ONLY
: 0 );
161 pUsrPref
->SetModified();
163 if ( pOpt
->GetZoom() != (sal_uInt16
) nFac
)
165 aOpt
.SetZoom ( sal_uInt16(nFac
) );
166 aOpt
.SetReadonly(pOpt
->IsReadonly());
167 m_pWrtShell
->ApplyViewOptions( aOpt
);
169 if ( eZoomType
!= SVX_ZOOM_PERCENT
)
173 if ( eZoomType
== SVX_ZOOM_WHOLEPAGE
)
174 aPos
.Y() = m_pWrtShell
->GetAnyCurRect(RECT_PAGE
).Top() - DOCUMENTBORDER
;
177 //sicherstellen, dass sich der Cursor im sichtbaren
178 //Bereich befindet, damit nur 1x gescrollt wird
179 aPos
.X() = lLeftMargin
;
180 const SwRect
&rCharRect
= m_pWrtShell
->GetCharRect();
181 if ( rCharRect
.Top() > GetVisArea().Bottom() ||
182 rCharRect
.Bottom() < aPos
.Y() )
183 aPos
.Y() = rCharRect
.Top() - rCharRect
.Height();
185 aPos
.Y() = GetVisArea().Top();
189 // OS: Notloesung - in CalcVisArea wird u.U. wieder SetZoom gerufen und
190 // dann werden falsche Werte eingestellt
191 ((SwViewOption
*)m_pWrtShell
->GetViewOptions())->SetZoomType( eZoomType
);
192 CalcVisArea( rEditSize
); //fuer das Neuberechnen des sichtbaren Bereiches
194 else if ( sal_uInt16(nFac
) != pOpt
->GetZoom() )
196 aOpt
.SetZoom ( sal_uInt16(nFac
) );
197 m_pWrtShell
->ApplyViewOptions( aOpt
);
200 const Fraction
aFrac( nFac
, 100 );
201 m_pVRuler
->SetZoom( aFrac
);
202 m_pVRuler
->ForceUpdate();
203 m_pHRuler
->SetZoom( aFrac
);
204 m_pHRuler
->ForceUpdate();
205 ((SwViewOption
*)m_pWrtShell
->GetViewOptions())->SetZoomType( eZoomType
);
207 m_pWrtShell
->UnlockPaint();
209 m_pWrtShell
->LockView( sal_False
);
212 void SwView::SetViewLayout( sal_uInt16 nColumns
, bool bBookMode
, sal_Bool bViewOnly
)
214 const sal_Bool bUnLockView
= !m_pWrtShell
->IsViewLocked();
215 m_pWrtShell
->LockView( sal_True
);
216 m_pWrtShell
->LockPaint();
220 SwActContext
aActContext(m_pWrtShell
);
222 if ( !GetViewFrame()->GetFrame().IsInPlace() && !bViewOnly
)
224 const sal_Bool bWeb
= 0 != PTR_CAST(SwWebView
, this);
225 SwMasterUsrPref
*pUsrPref
= (SwMasterUsrPref
*)SW_MOD()->GetUsrPref(bWeb
);
227 //MasterUsrPrefs updaten UND DANACH die ViewOptions der aktuellen
229 if ( nColumns
!= pUsrPref
->GetViewLayoutColumns() ||
230 bBookMode
!= pUsrPref
->IsViewLayoutBookMode() )
232 pUsrPref
->SetViewLayoutColumns( nColumns
);
233 pUsrPref
->SetViewLayoutBookMode( bBookMode
);
234 SW_MOD()->ApplyUsrPref( *pUsrPref
,
236 bViewOnly
? VIEWOPT_DEST_VIEW_ONLY
: 0 );
237 pUsrPref
->SetModified();
241 const SwViewOption
*pOpt
= m_pWrtShell
->GetViewOptions();
243 if ( nColumns
!= pOpt
->GetViewLayoutColumns() ||
244 bBookMode
!= pOpt
->IsViewLayoutBookMode() )
246 SwViewOption
aOpt( *pOpt
);
247 aOpt
.SetViewLayoutColumns( nColumns
);
248 aOpt
.SetViewLayoutBookMode( bBookMode
);
249 m_pWrtShell
->ApplyViewOptions( aOpt
);
252 m_pVRuler
->ForceUpdate();
253 m_pHRuler
->ForceUpdate();
257 m_pWrtShell
->UnlockPaint();
259 m_pWrtShell
->LockView( sal_False
);
261 SfxBindings
& rBnd
= GetViewFrame()->GetBindings();
262 rBnd
.Invalidate( SID_ATTR_VIEWLAYOUT
);
263 rBnd
.Invalidate( SID_ATTR_ZOOMSLIDER
);
267 * Scrollbar - Handler
269 IMPL_LINK( SwView
, WindowChildEventListener
, VclSimpleEvent
*, pEvent
)
271 OSL_ENSURE( pEvent
&& pEvent
->ISA( VclWindowEvent
), "Unknown WindowEvent!" );
272 if ( pEvent
&& pEvent
->ISA( VclWindowEvent
) )
274 VclWindowEvent
*pVclEvent
= static_cast< VclWindowEvent
* >( pEvent
);
275 OSL_ENSURE( pVclEvent
->GetWindow(), "Window???" );
276 Window
* pChildWin
= static_cast< Window
* >( pVclEvent
->GetData() );
278 switch ( pVclEvent
->GetId() )
280 case VCLEVENT_WINDOW_HIDE
:
281 if( pChildWin
== m_pHScrollbar
)
282 ShowHScrollbar( sal_False
);
283 else if( pChildWin
== m_pVScrollbar
)
284 ShowVScrollbar( sal_False
);
286 case VCLEVENT_WINDOW_SHOW
:
287 if( pChildWin
== m_pHScrollbar
)
288 ShowHScrollbar( sal_True
);
289 else if( pChildWin
== m_pVScrollbar
)
290 ShowVScrollbar( sal_True
);
298 int SwView::_CreateScrollbar( sal_Bool bHori
)
300 Window
*pMDI
= &GetViewFrame()->GetWindow();
301 SwScrollbar
** ppScrollbar
= bHori
? &m_pHScrollbar
: &m_pVScrollbar
;
303 OSL_ENSURE( !*ppScrollbar
, "vorher abpruefen!" );
306 CreatePageButtons( !m_bShowAtResize
);
308 *ppScrollbar
= new SwScrollbar( pMDI
, bHori
);
311 (*ppScrollbar
)->SetScrollHdl( LINK( this, SwView
, EndScrollHdl
));
313 (*ppScrollbar
)->SetScrollHdl( LINK( this, SwView
, ScrollHdl
));
314 (*ppScrollbar
)->SetEndScrollHdl( LINK( this, SwView
, EndScrollHdl
));
316 (*ppScrollbar
)->EnableDrag( sal_True
);
321 // Scrollbar muss nochmals getestet werden, da im InvalidateBorder u.U. der
322 // Scrollbar wieder geloescht wurde
323 if ( !m_bShowAtResize
&& (*ppScrollbar
))
324 (*ppScrollbar
)->ExtendedShow();
329 void SwView::CreatePageButtons(sal_Bool bShow
)
331 Window
*pMDI
= &GetViewFrame()->GetWindow();
332 m_pPageUpBtn
= new SwHlpImageButton(pMDI
, SW_RES( BTN_PAGEUP
), sal_True
);
333 m_pPageUpBtn
->SetHelpId(HID_SCRL_PAGEUP
);
334 m_pPageDownBtn
= new SwHlpImageButton(pMDI
, SW_RES( BTN_PAGEDOWN
), sal_False
);
335 m_pPageDownBtn
->SetHelpId(HID_SCRL_PAGEDOWN
);
336 Reference
< XFrame
> xFrame
= GetViewFrame()->GetFrame().GetFrameInterface();
337 m_pNaviBtn
= new SwNaviImageButton(pMDI
, xFrame
);
338 m_pNaviBtn
->SetHelpId(HID_SCRL_NAVI
);
339 Link
aLk( LINK( this, SwView
, BtnPage
) );
340 m_pPageUpBtn
->SetClickHdl( aLk
);
341 m_pPageDownBtn
->SetClickHdl( aLk
);
342 if(m_nMoveType
!= NID_PGE
)
344 Color
aColor(VIEW_IMAGECOLOR
);
345 SetImageButtonColor(aColor
);
350 m_pPageUpBtn
->Show();
351 m_pPageDownBtn
->Show();
359 IMPL_LINK( SwView
, BtnPage
, Button
*, pButton
)
361 // #i75416# move the execution of the search to an asynchronously called static link
362 bool* pbNext
= new bool( (pButton
== m_pPageDownBtn
) );
363 Application::PostUserEvent( STATIC_LINK(this, SwView
, MoveNavigationHdl
), pbNext
);
367 IMPL_STATIC_LINK( SwView
, MoveNavigationHdl
, bool *, pbNext
)
371 bool bNext
= *pbNext
;
372 SwWrtShell
& rSh
= pThis
->GetWrtShell();
373 switch( m_nMoveType
)
376 bNext
? pThis
->PhyPageDown() : pThis
->PhyPageUp();
381 rSh
.MoveTable(fnTableNext
, fnTableStart
);
383 rSh
.MoveTable(fnTablePrev
, fnTableStart
);
389 sal_uInt16 eType
= GOTOOBJ_FLY_FRM
;
390 if(m_nMoveType
== NID_GRF
)
391 eType
= GOTOOBJ_FLY_GRF
;
392 else if(m_nMoveType
== NID_OLE
)
393 eType
= GOTOOBJ_FLY_OLE
;
394 sal_Bool bSuccess
= bNext
?
395 rSh
.GotoNextFly(eType
) :
396 rSh
.GotoPrevFly(eType
);
400 rSh
.EnterSelFrmMode();
407 m_nMoveType
== NID_DRW
?
408 GOTOOBJ_DRAW_SIMPLE
:
409 GOTOOBJ_DRAW_CONTROL
);
414 rSh
.MoveRegion(fnRegionNext
, fnRegionStart
);
416 rSh
.MoveRegion(fnRegionPrev
, fnRegionStart
);
421 pThis
->GetViewFrame()->GetDispatcher()->Execute(bNext
?
427 bNext
? rSh
.GotoNextOutline() : rSh
.GotoPrevOutline();
430 bNext
? rSh
.GoNextCrsr() : rSh
.GoPrevCrsr();
435 rSh
.GotoNextFtnAnchor() :
436 rSh
.GotoPrevFtnAnchor();
444 // collect navigator reminders
445 IDocumentMarkAccess
* const pMarkAccess
= rSh
.getIDocumentMarkAccess();
446 ::std::vector
< const ::sw::mark::IMark
* > vNavMarks
;
447 for( IDocumentMarkAccess::const_iterator_t ppMark
= pMarkAccess
->getMarksBegin();
448 ppMark
!= pMarkAccess
->getMarksEnd();
451 if( IDocumentMarkAccess::GetType(**ppMark
) == IDocumentMarkAccess::NAVIGATOR_REMINDER
)
452 vNavMarks
.push_back(ppMark
->get());
456 if(!vNavMarks
.empty())
461 if (m_nActMark
>= MAX_MARKS
|| m_nActMark
>= static_cast<sal_Int32
>(vNavMarks
.size()))
467 if (m_nActMark
< 0 || m_nActMark
>= static_cast<sal_Int32
>(vNavMarks
.size()))
468 m_nActMark
= vNavMarks
.size()-1;
470 rSh
.GotoMark(vNavMarks
[m_nActMark
]);
476 sw::sidebarwindows::SwSidebarWin
* pPostIt
= pThis
->GetPostItMgr()->GetActiveSidebarWin();
478 pThis
->GetPostItMgr()->SetActiveSidebarWin(0);
479 SwFieldType
* pFldType
= rSh
.GetFldType(0, RES_POSTITFLD
);
480 if (rSh
.MoveFldType(pFldType
, bNext
))
481 pThis
->GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT
);
484 pThis
->GetPostItMgr()->SetActiveSidebarWin(pPostIt
);
490 sal_Bool bBackward
= m_pSrchItem
->GetBackward();
491 if(rSh
.HasSelection() && !bNext
== rSh
.IsCrsrPtAtEnd())
493 m_pSrchItem
->SetBackward(!bNext
);
494 SfxRequest
aReq(FN_REPEAT_SEARCH
, SFX_CALLMODE_SLOT
, pThis
->GetPool());
495 pThis
->ExecSearch(aReq
);
496 m_pSrchItem
->SetBackward(bBackward
);
499 case NID_INDEX_ENTRY
:
500 rSh
.GotoNxtPrvTOXMark(bNext
);
503 case NID_TABLE_FORMULA
:
504 rSh
.GotoNxtPrvTblFormula( bNext
);
507 case NID_TABLE_FORMULA_ERROR
:
508 rSh
.GotoNxtPrvTblFormula( bNext
, sal_True
);
511 pThis
->m_pEditWin
->GrabFocus();
516 int SwView::CreateTab()
518 m_pHRuler
->SetActive(GetFrame() && IsActive());
525 int SwView::KillTab()
532 void SwView::ChangeTabMetric( FieldUnit eUnit
)
534 if(m_pHRuler
->GetUnit() != eUnit
)
536 m_pHRuler
->SetUnit( eUnit
);
537 m_pHRuler
->Invalidate();
541 void SwView::ChangeVRulerMetric( FieldUnit eUnit
)
543 if(m_pVRuler
->GetUnit() != eUnit
)
545 m_pVRuler
->SetUnit( eUnit
);
546 m_pVRuler
->Invalidate();
550 void SwView::GetVRulerMetric(FieldUnit
& eToFill
) const
552 eToFill
= m_pVRuler
->GetUnit();
555 void SwView::GetHRulerMetric(FieldUnit
& eToFill
) const
557 eToFill
= m_pHRuler
->GetUnit();
560 int SwView::CreateVRuler()
562 m_pHRuler
->SetBorderPos( m_pVRuler
->GetSizePixel().Width()-1 );
564 m_pVRuler
->SetActive(GetFrame() && IsActive());
570 int SwView::KillVRuler()
573 m_pHRuler
->SetBorderPos( 0 );
578 IMPL_LINK( SwView
, ExecRulerClick
, Ruler
*, pRuler
)
580 sal_uInt16 nDefPage
= 0;
581 switch( pRuler
->GetClickType() )
583 case RULER_TYPE_DONTKNOW
:
584 case RULER_TYPE_OUTSIDE
:
585 case RULER_TYPE_INDENT
:
586 case RULER_TYPE_MARGIN1
:
587 case RULER_TYPE_MARGIN2
:
588 nDefPage
= TP_PARA_STD
;
591 nDefPage
= TP_TABULATOR
;
595 SfxUInt16Item
aDefPage(SID_PARA_DLG
, nDefPage
);
596 GetViewFrame()->GetDispatcher()->Execute( SID_PARA_DLG
,
597 SFX_CALLMODE_SYNCHRON
|SFX_CALLMODE_RECORD
,
602 sal_uInt16
SwView::GetMoveType()
607 void SwView::SetMoveType(sal_uInt16 nSet
)
609 sal_Bool bLastPage
= m_nMoveType
== NID_PGE
;
611 sal_Bool bNewPage
= m_nMoveType
== NID_PGE
;
612 if(bNewPage
!= bLastPage
)
614 Color
aColor(bNewPage
? COL_BLACK
: VIEW_IMAGECOLOR
);
615 const TypeId aTypeId
= TYPE(SwView
);
616 SwView
* pView
= (SwView
*)SfxViewShell::GetFirst(&aTypeId
);
619 pView
->SetImageButtonColor(aColor
);
620 pView
= (SwView
*)SfxViewShell::GetNext(*pView
, &aTypeId
);
625 void SwView::SetActMark(sal_Int32 nSet
)
630 void SwView::SetImageButtonColor(Color
& rColor
)
634 m_pPageUpBtn
->SetControlForeground(rColor
);
635 m_pPageDownBtn
->SetControlForeground(rColor
);
639 void SwView::ShowHScrollbar(sal_Bool bShow
)
641 OSL_ENSURE(m_pHScrollbar
, "Scrollbar invalid");
642 m_pHScrollbar
->ExtendedShow(bShow
);
645 sal_Bool
SwView::IsHScrollbarVisible()const
647 OSL_ENSURE(m_pHScrollbar
, "Scrollbar invalid");
648 return m_pHScrollbar
->IsVisible( sal_False
) || m_pHScrollbar
->IsAuto();
651 void SwView::ShowVScrollbar(sal_Bool bShow
)
653 OSL_ENSURE(m_pVScrollbar
, "Scrollbar invalid");
654 m_pVScrollbar
->ExtendedShow(bShow
);
655 m_pPageUpBtn
->Show(bShow
);
656 m_pPageDownBtn
->Show(bShow
);
657 m_pNaviBtn
->Show(bShow
);
660 sal_Bool
SwView::IsVScrollbarVisible()const
662 OSL_ENSURE(m_pVScrollbar
, "Scrollbar invalid");
663 return m_pVScrollbar
->IsVisible( sal_False
);
666 void SwView::EnableHScrollbar(bool bEnable
)
668 if (m_bHScrollbarEnabled
!= bEnable
)
670 m_bHScrollbarEnabled
= bEnable
;
675 void SwView::EnableVScrollbar(bool bEnable
)
677 if (m_bVScrollbarEnabled
!= bEnable
)
679 m_bVScrollbarEnabled
= bEnable
;
684 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */