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 "hintids.hxx"
21 : #include <vcl/help.hxx>
22 : #include <svx/ruler.hxx>
23 : #include <editeng/paperinf.hxx>
24 : #include <editeng/lrspitem.hxx>
25 : #include <sfx2/bindings.hxx>
26 : #include <view.hxx>
27 : #include <wrtsh.hxx>
28 : #include <swmodule.hxx>
29 : #include <viewopt.hxx>
30 : #include <frmatr.hxx>
31 : #include <docsh.hxx>
32 : #include <cmdid.h>
33 : #include <edtwin.hxx>
34 : #include <scroll.hxx>
35 : #include <wview.hxx>
36 : #include <usrpref.hxx>
37 : #include <pagedesc.hxx>
38 : #include <workctrl.hxx>
39 : #include <crsskip.hxx>
40 :
41 : #include <PostItMgr.hxx>
42 :
43 : #include <IDocumentSettingAccess.hxx>
44 :
45 : #include <basegfx/tools/zoomtools.hxx>
46 :
47 : //Das SetVisArea der DocShell darf nicht vom InnerResizePixel gerufen werden.
48 : //Unsere Einstellungen muessen aber stattfinden.
49 : #ifndef WB_RIGHT_ALIGNED
50 : #define WB_RIGHT_ALIGNED ((WinBits)0x00008000)
51 : #endif
52 :
53 : static bool bProtectDocShellVisArea = false;
54 :
55 : static sal_uInt16 nPgNum = 0;
56 :
57 6327 : bool SwView::IsDocumentBorder()
58 : {
59 12654 : return GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
60 12431 : m_pWrtShell->GetViewOptions()->getBrowseMode() ||
61 12431 : SVX_ZOOM_PAGEWIDTH_NOBORDER == (SvxZoomType)m_pWrtShell->GetViewOptions()->GetZoomType();
62 : }
63 :
64 1 : inline long GetLeftMargin( SwView &rView )
65 : {
66 1 : SvxZoomType eType = (SvxZoomType)rView.GetWrtShell().GetViewOptions()->GetZoomType();
67 1 : long lRet = rView.GetWrtShell().GetAnyCurRect(RECT_PAGE_PRT).Left();
68 : return eType == SVX_ZOOM_PERCENT ? lRet + DOCUMENTBORDER :
69 0 : eType == SVX_ZOOM_PAGEWIDTH || eType == SVX_ZOOM_PAGEWIDTH_NOBORDER ? 0 :
70 1 : lRet + DOCUMENTBORDER + nLeftOfst;
71 : }
72 :
73 0 : static void lcl_GetPos(SwView* pView,
74 : Point& rPos,
75 : SwScrollbar* pScrollbar,
76 : bool bBorder)
77 : {
78 0 : SwWrtShell &rSh = pView->GetWrtShell();
79 0 : const Size m_aDocSz( rSh.GetDocSize() );
80 :
81 0 : const long lBorder = bBorder ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
82 0 : const bool bHori = pScrollbar->IsHoriScroll();
83 :
84 0 : const long lPos = pScrollbar->GetThumbPos() + (bBorder ? DOCUMENTBORDER : 0);
85 :
86 0 : long lDelta = lPos - (bHori ? rSh.VisArea().Pos().X() : rSh.VisArea().Pos().Y());
87 :
88 0 : const long lSize = (bHori ? m_aDocSz.A() : m_aDocSz.B()) + lBorder;
89 : // sollte rechts oder unten zuviel Wiese sein, dann muss
90 : // diese von der VisArea herausgerechnet werden!
91 0 : long nTmp = pView->GetVisArea().Right()+lDelta;
92 0 : if ( bHori && nTmp > lSize )
93 0 : lDelta -= nTmp - lSize;
94 0 : nTmp = pView->GetVisArea().Bottom()+lDelta;
95 0 : if ( !bHori && nTmp > lSize )
96 0 : lDelta -= nTmp - lSize;
97 :
98 : // use a reference to access/moodify the correct coordinate
99 : // returned by accessors to non-const object
100 0 : long & rCoord = bHori ? rPos.X() : rPos.Y();
101 0 : rCoord += lDelta;
102 0 : if ( bBorder && rCoord < DOCUMENTBORDER )
103 0 : rCoord = DOCUMENTBORDER;
104 0 : }
105 :
106 : /*--------------------------------------------------------------------
107 : Beschreibung: Nullpunkt Lineal setzen
108 : --------------------------------------------------------------------*/
109 3235 : void SwView::InvalidateRulerPos()
110 : {
111 : static sal_uInt16 aInval[] =
112 : {
113 : SID_ATTR_PARA_LRSPACE, SID_RULER_BORDERS, SID_RULER_PAGE_POS,
114 : SID_RULER_LR_MIN_MAX, SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
115 : SID_RULER_BORDER_DISTANCE,
116 : SID_ATTR_PARA_LRSPACE_VERTICAL, SID_RULER_BORDERS_VERTICAL,
117 : SID_RULER_TEXT_RIGHT_TO_LEFT,
118 : SID_RULER_ROWS, SID_RULER_ROWS_VERTICAL, FN_STAT_PAGE,
119 : 0
120 : };
121 :
122 3235 : GetViewFrame()->GetBindings().Invalidate(aInval);
123 :
124 : OSL_ENSURE(m_pHRuler, "warum ist das Lineal nicht da?");
125 3235 : m_pHRuler->ForceUpdate();
126 3235 : m_pVRuler->ForceUpdate();
127 3235 : }
128 :
129 : /*--------------------------------------------------------------------
130 : Beschreibung: begrenzt das Scrollen soweit, dass jeweils nur einen
131 : viertel Bildschirm bis vor das Ende des Dokumentes
132 : gescrollt werden kann.
133 : --------------------------------------------------------------------*/
134 3 : long SwView::SetHScrollMax( long lMax )
135 : {
136 3 : const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
137 3 : const long lSize = GetDocSz().Width() + lBorder - m_aVisArea.GetWidth();
138 :
139 : // bei negativen Werten ist das Dokument vollstaendig sichtbar;
140 : // in diesem Fall kein Scrollen
141 3 : return std::max( std::min( lMax, lSize ), 0L );
142 : }
143 :
144 288 : long SwView::SetVScrollMax( long lMax )
145 : {
146 288 : const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
147 288 : long lSize = GetDocSz().Height() + lBorder - m_aVisArea.GetHeight();
148 288 : return std::max( std::min( lMax, lSize), 0L ); // siehe horz.
149 : }
150 :
151 4225 : Point SwView::AlignToPixel(const Point &rPt) const
152 : {
153 4225 : return GetEditWin().PixelToLogic( GetEditWin().LogicToPixel( rPt ) );
154 : }
155 :
156 : /*--------------------------------------------------------------------
157 : Beschreibung: Dokumentgroesse hat sich geaendert
158 : --------------------------------------------------------------------*/
159 1667 : void SwView::DocSzChgd(const Size &rSz)
160 : {
161 :
162 : extern int bDocSzUpdated;
163 :
164 :
165 1667 : m_aDocSz = rSz;
166 :
167 1667 : if( !m_pWrtShell || m_aVisArea.IsEmpty() ) // keine Shell -> keine Aenderung
168 : {
169 1331 : bDocSzUpdated = sal_False;
170 2998 : return;
171 : }
172 :
173 : //Wenn Text geloescht worden ist, kann es sein, dass die VisArea hinter
174 : //den sichtbaren Bereich verweist
175 336 : Rectangle aNewVisArea( m_aVisArea );
176 336 : bool bModified = false;
177 336 : SwTwips lGreenOffset = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
178 336 : SwTwips lTmp = m_aDocSz.Width() + lGreenOffset;
179 :
180 336 : if ( aNewVisArea.Right() >= lTmp )
181 : {
182 41 : lTmp = aNewVisArea.Right() - lTmp;
183 41 : aNewVisArea.Right() -= lTmp;
184 41 : aNewVisArea.Left() -= lTmp;
185 41 : bModified = true;
186 : }
187 :
188 336 : lTmp = m_aDocSz.Height() + lGreenOffset;
189 336 : if ( aNewVisArea.Bottom() >= lTmp )
190 : {
191 29 : lTmp = aNewVisArea.Bottom() - lTmp;
192 29 : aNewVisArea.Bottom() -= lTmp;
193 29 : aNewVisArea.Top() -= lTmp;
194 29 : bModified = true;
195 : }
196 :
197 336 : if ( bModified )
198 50 : SetVisArea( aNewVisArea, sal_False );
199 :
200 338 : if ( UpdateScrollbars() && !m_bInOuterResizePixel && !m_bInInnerResizePixel &&
201 2 : !GetViewFrame()->GetFrame().IsInPlace())
202 : OuterResizePixel( Point(),
203 2 : GetViewFrame()->GetWindow().GetOutputSizePixel() );
204 : }
205 :
206 : /*--------------------------------------------------------------------
207 : Beschreibung: Visarea neu setzen
208 : --------------------------------------------------------------------*/
209 2099 : void SwView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
210 : {
211 2099 : const Size aOldSz( m_aVisArea.GetSize() );
212 :
213 2099 : const Point aTopLeft( AlignToPixel( rRect.TopLeft() ));
214 2099 : const Point aBottomRight( AlignToPixel( rRect.BottomRight() ));
215 2099 : Rectangle aLR( aTopLeft, aBottomRight );
216 :
217 2099 : if( aLR == m_aVisArea )
218 975 : return;
219 :
220 1631 : const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
221 :
222 : // keine negative Position, keine neg. Groesse
223 1631 : if( aLR.Top() < lMin )
224 : {
225 25 : aLR.Bottom() += lMin - aLR.Top();
226 25 : aLR.Top() = lMin;
227 : }
228 1631 : if( aLR.Left() < lMin )
229 : {
230 50 : aLR.Right() += lMin - aLR.Left();
231 50 : aLR.Left() = lMin;
232 : }
233 1631 : if( aLR.Right() < 0 )
234 0 : aLR.Right() = 0;
235 1631 : if( aLR.Bottom() < 0 )
236 0 : aLR.Bottom() = 0;
237 :
238 1631 : if( aLR == m_aVisArea )
239 39 : return;
240 :
241 1592 : const Size aSize( aLR.GetSize() );
242 1592 : if( aSize.Width() < 0 || aSize.Height() < 0 )
243 0 : return;
244 :
245 : //Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird
246 : //sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten
247 : //umgerechnet werden.
248 : //Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft,
249 : //denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden
250 : //lediglich (in Dokumentkoordinaten) vorgemerkt.
251 1592 : if ( m_pWrtShell && m_pWrtShell->ActionPend() )
252 1584 : m_pWrtShell->GetWin()->Update();
253 :
254 1592 : m_aVisArea = aLR;
255 :
256 1592 : const sal_Bool bOuterResize = bUpdateScrollbar && UpdateScrollbars();
257 :
258 1592 : if ( m_pWrtShell )
259 : {
260 1592 : m_pWrtShell->VisPortChgd( m_aVisArea );
261 4331 : if ( aOldSz != m_pWrtShell->VisArea().SSize() &&
262 1942 : ( std::abs(aOldSz.Width() - m_pWrtShell->VisArea().Width()) > 2 ||
263 550 : std::abs(aOldSz.Height() - m_pWrtShell->VisArea().Height()) > 2 ) )
264 1347 : m_pWrtShell->CheckBrowseView( sal_False );
265 : }
266 :
267 1592 : if ( !bProtectDocShellVisArea )
268 : {
269 : //Wenn die Groesse der VisArea unveraendert ist, reichen wir die
270 : //Groesse der VisArea vom InternalObject weiter. Damit soll der
271 : //Transport von Fehlern vermieden werden.
272 1592 : Rectangle aVis( m_aVisArea );
273 1592 : if ( aVis.GetSize() == aOldSz )
274 200 : aVis.SetSize( GetDocShell()->SfxObjectShell::GetVisArea(ASPECT_CONTENT).GetSize() );
275 : // TODO/LATER: why casting?!
276 : //GetDocShell()->SfxInPlaceObject::GetVisArea().GetSize() );
277 :
278 : //Bei embedded immer mit Modify...
279 : // TODO/LATER: why casting?!
280 1592 : GetDocShell()->SfxObjectShell::SetVisArea( aVis );
281 : /*
282 : if ( GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
283 : GetDocShell()->SfxInPlaceObject::SetVisArea( aVis );
284 : else
285 : GetDocShell()->SvEmbeddedObject::SetVisArea( aVis );*/
286 : }
287 :
288 1592 : SfxViewShell::VisAreaChanged( m_aVisArea );
289 :
290 1592 : InvalidateRulerPos();
291 :
292 1592 : if ( bOuterResize && !m_bInOuterResizePixel && !m_bInInnerResizePixel)
293 : OuterResizePixel( Point(),
294 19 : GetViewFrame()->GetWindow().GetOutputSizePixel() );
295 : }
296 :
297 : /*--------------------------------------------------------------------
298 : Beschreibung: Pos VisArea setzen
299 : --------------------------------------------------------------------*/
300 304 : void SwView::SetVisArea( const Point &rPt, sal_Bool bUpdateScrollbar )
301 : {
302 : //einmal alignen, damit Brushes korrekt angesetzt werden.
303 : //MA 31. May. 96: Das geht in der BrowseView schief, weil evlt.
304 : //nicht das ganze Dokument sichtbar wird. Da der Inhalt in Frames
305 : //passgenau ist, kann nicht aligned werden (bessere Idee?!?!)
306 : //MA 29. Oct. 96 (fix: Bild.de, 200%) ganz ohne Alignment geht es nicht
307 : //mal sehen wie weit wir mit der halben BrushSize kommen.
308 304 : Point aPt( rPt );
309 : // const long nTmp = GetWrtShell().IsFrameView() ? BRUSH_SIZE/2 : BRUSH_SIZE;
310 304 : const long nTmp = GetWrtShell().IsFrameView() ? 4 : 8;
311 304 : aPt = GetEditWin().LogicToPixel( aPt );
312 304 : aPt.X() -= aPt.X() % nTmp;
313 304 : aPt.Y() -= aPt.Y() % nTmp;
314 304 : aPt = GetEditWin().PixelToLogic( aPt );
315 :
316 304 : if ( aPt == m_aVisArea.TopLeft() )
317 409 : return;
318 :
319 199 : const long lXDiff = m_aVisArea.Left() - aPt.X();
320 199 : const long lYDiff = m_aVisArea.Top() - aPt.Y();
321 : SetVisArea( Rectangle( aPt,
322 398 : Point( m_aVisArea.Right() - lXDiff, m_aVisArea.Bottom() - lYDiff ) ),
323 597 : bUpdateScrollbar);
324 : }
325 :
326 2 : void SwView::CheckVisArea()
327 : {
328 4 : m_pHScrollbar->SetAuto( m_pWrtShell->GetViewOptions()->getBrowseMode() &&
329 4 : !GetViewFrame()->GetFrame().IsInPlace() );
330 2 : if ( IsDocumentBorder() )
331 : {
332 2 : if ( m_aVisArea.Left() != DOCUMENTBORDER ||
333 0 : m_aVisArea.Top() != DOCUMENTBORDER )
334 : {
335 2 : Rectangle aNewVisArea( m_aVisArea );
336 2 : aNewVisArea.Move( DOCUMENTBORDER - m_aVisArea.Left(),
337 4 : DOCUMENTBORDER - m_aVisArea.Top() );
338 2 : SetVisArea( aNewVisArea, sal_True );
339 : }
340 : }
341 2 : }
342 :
343 : /*--------------------------------------------------------------------
344 : Beschreibung: Sichtbaren Bereich berechnen
345 :
346 : OUT Point *pPt: neue Position des sichtbaren
347 : Bereiches
348 : IN Rectangle &rRect: Rechteck, das sich innerhalb des neuen
349 : sichtbaren Bereiches befinden soll
350 : sal_uInt16 nRange optional exakte Angabe des Bereiches,
351 : um den ggfs. gescrollt werden soll
352 : --------------------------------------------------------------------*/
353 298 : void SwView::CalcPt( Point *pPt, const Rectangle &rRect,
354 : sal_uInt16 nRangeX, sal_uInt16 nRangeY)
355 : {
356 :
357 298 : const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
358 :
359 298 : long nYScroll = GetYScroll();
360 298 : long nDesHeight = rRect.GetHeight();
361 298 : long nCurHeight = m_aVisArea.GetHeight();
362 298 : nYScroll = std::min(nYScroll, nCurHeight - nDesHeight); // wird es knapp, dann nicht zuviel scrollen
363 298 : if(nDesHeight > nCurHeight) // die Hoehe reicht nicht aus, dann interessiert nYScroll nicht mehr
364 : {
365 0 : pPt->Y() = rRect.Top();
366 0 : pPt->Y() = std::max( lMin, pPt->Y() );
367 : }
368 298 : else if ( rRect.Top() < m_aVisArea.Top() ) //Verschiebung nach oben
369 : {
370 9 : pPt->Y() = rRect.Top() - (nRangeY != USHRT_MAX ? nRangeY : nYScroll);
371 9 : pPt->Y() = std::max( lMin, pPt->Y() );
372 : }
373 289 : else if( rRect.Bottom() > m_aVisArea.Bottom() ) //Verschiebung nach unten
374 : {
375 576 : pPt->Y() = rRect.Bottom() -
376 576 : (m_aVisArea.GetHeight()) + ( nRangeY != USHRT_MAX ?
377 288 : nRangeY : nYScroll );
378 288 : pPt->Y() = SetVScrollMax( pPt->Y() );
379 : }
380 298 : long nXScroll = GetXScroll();
381 298 : if ( rRect.Right() > m_aVisArea.Right() ) //Verschiebung nach rechts
382 : {
383 6 : pPt->X() = rRect.Right() -
384 6 : (m_aVisArea.GetWidth()) +
385 3 : (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
386 3 : pPt->X() = SetHScrollMax( pPt->X() );
387 : }
388 295 : else if ( rRect.Left() < m_aVisArea.Left() ) //Verschiebung nach links
389 : {
390 1 : pPt->X() = rRect.Left() - (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
391 1 : pPt->X() = std::max( ::GetLeftMargin( *this ) + nLeftOfst, pPt->X() );
392 1 : pPt->X() = std::min( rRect.Left() - nScrollX, pPt->X() );
393 1 : pPt->X() = std::max( 0L, pPt->X() );
394 : }
395 298 : }
396 :
397 : /*--------------------------------------------------------------------
398 : Beschreibung: Scrolling
399 : --------------------------------------------------------------------*/
400 14446 : sal_Bool SwView::IsScroll( const Rectangle &rRect ) const
401 : {
402 14446 : return m_bCenterCrsr || m_bTopCrsr || !m_aVisArea.IsInside(rRect);
403 : }
404 :
405 410 : void SwView::Scroll( const Rectangle &rRect, sal_uInt16 nRangeX, sal_uInt16 nRangeY )
406 : {
407 410 : if ( m_aVisArea.IsEmpty() )
408 522 : return;
409 :
410 298 : Rectangle aOldVisArea( m_aVisArea );
411 298 : long nDiffY = 0;
412 :
413 298 : Window* pCareWn = ViewShell::GetCareWin(GetWrtShell());
414 298 : if ( pCareWn )
415 : {
416 0 : Rectangle aDlgRect( GetEditWin().PixelToLogic(
417 0 : pCareWn->GetWindowExtentsRelative( &GetEditWin() ) ) );
418 : // Nur, wenn der Dialog nicht rechts oder links der VisArea liegt:
419 0 : if ( aDlgRect.Left() < m_aVisArea.Right() &&
420 0 : aDlgRect.Right() > m_aVisArea.Left() )
421 : {
422 : // Falls wir nicht zentriert werden sollen, in der VisArea liegen
423 : // und nicht vom Dialog ueberdeckt werden ...
424 0 : if ( !m_bCenterCrsr && aOldVisArea.IsInside( rRect )
425 0 : && ( rRect.Left() > aDlgRect.Right()
426 0 : || rRect.Right() < aDlgRect.Left()
427 0 : || rRect.Top() > aDlgRect.Bottom()
428 0 : || rRect.Bottom() < aDlgRect.Top() ) )
429 0 : return;
430 :
431 : // Ist oberhalb oder unterhalb der Dialogs mehr Platz?
432 0 : long nTopDiff = aDlgRect.Top() - m_aVisArea.Top();
433 0 : long nBottomDiff = m_aVisArea.Bottom() - aDlgRect.Bottom();
434 0 : if ( nTopDiff < nBottomDiff )
435 : {
436 0 : if ( nBottomDiff > 0 ) // Ist unterhalb ueberhaupt Platz?
437 : { // dann verschieben wir die Oberkante und merken uns dies
438 0 : nDiffY = aDlgRect.Bottom() - m_aVisArea.Top();
439 0 : m_aVisArea.Top() += nDiffY;
440 : }
441 : }
442 : else
443 : {
444 0 : if ( nTopDiff > 0 ) // Ist oberhalb ueberhaupt Platz?
445 0 : m_aVisArea.Bottom() = aDlgRect.Top(); // Unterkante aendern
446 : }
447 : }
448 : }
449 :
450 : //s.o. !IsScroll()
451 298 : if( !(m_bCenterCrsr || m_bTopCrsr) && m_aVisArea.IsInside( rRect ) )
452 : {
453 0 : m_aVisArea = aOldVisArea;
454 0 : return;
455 : }
456 : //falls das Rechteck groesser als der sichtbare Bereich -->
457 : //obere linke Ecke
458 298 : Size aSize( rRect.GetSize() );
459 298 : const Size aVisSize( m_aVisArea.GetSize() );
460 817 : if( !m_aVisArea.IsEmpty() && (
461 596 : aSize.Width() + GetXScroll() > aVisSize.Width() ||
462 298 : aSize.Height()+ GetYScroll() > aVisSize.Height() ))
463 : {
464 221 : Point aPt( m_aVisArea.TopLeft() );
465 221 : aSize.Width() = std::min( aSize.Width(), aVisSize.Width() );
466 221 : aSize.Height()= std::min( aSize.Height(),aVisSize.Height());
467 :
468 : CalcPt( &aPt, Rectangle( rRect.TopLeft(), aSize ),
469 221 : static_cast< sal_uInt16 >((aVisSize.Width() - aSize.Width()) / 2),
470 442 : static_cast< sal_uInt16 >((aVisSize.Height()- aSize.Height())/ 2) );
471 :
472 221 : if( m_bTopCrsr )
473 : {
474 0 : const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
475 0 : aPt.Y() = std::min( std::max( nBorder, rRect.Top() ),
476 0 : m_aDocSz.Height() + nBorder -
477 0 : m_aVisArea.GetHeight() );
478 : }
479 221 : aPt.Y() -= nDiffY;
480 221 : m_aVisArea = aOldVisArea;
481 221 : SetVisArea( aPt );
482 221 : return;
483 : }
484 77 : if( !m_bCenterCrsr )
485 : {
486 77 : Point aPt( m_aVisArea.TopLeft() );
487 77 : CalcPt( &aPt, rRect, nRangeX, nRangeY );
488 :
489 77 : if( m_bTopCrsr )
490 : {
491 0 : const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
492 0 : aPt.Y() = std::min( std::max( nBorder, rRect.Top() ),
493 0 : m_aDocSz.Height() + nBorder -
494 0 : m_aVisArea.GetHeight() );
495 : }
496 :
497 77 : aPt.Y() -= nDiffY;
498 77 : m_aVisArea = aOldVisArea;
499 77 : SetVisArea( aPt );
500 77 : return;
501 : }
502 :
503 : //Cursor zentrieren
504 0 : Point aPnt( m_aVisArea.TopLeft() );
505 : // ... in Y-Richtung auf jeden Fall
506 0 : aPnt.Y() += ( rRect.Top() + rRect.Bottom()
507 0 : - m_aVisArea.Top() - m_aVisArea.Bottom() ) / 2 - nDiffY;
508 : // ... in X-Richtung nur, wenn das Rechteck rechts oder links aus der
509 : // VisArea hinausragt.
510 0 : if ( rRect.Right() > m_aVisArea.Right() || rRect.Left() < m_aVisArea.Left() )
511 : {
512 0 : aPnt.X() += ( rRect.Left() + rRect.Right()
513 0 : - m_aVisArea.Left() - m_aVisArea.Right() ) / 2;
514 0 : aPnt.X() = SetHScrollMax( aPnt.X() );
515 0 : const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
516 0 : aPnt.X() = std::max( (GetLeftMargin( *this ) - lMin) + nLeftOfst, aPnt.X() );
517 : }
518 0 : m_aVisArea = aOldVisArea;
519 0 : if( pCareWn )
520 : { // Wenn wir nur einem Dialog ausweichen wollen, wollen wir nicht ueber
521 : // das Ende des Dokument hinausgehen.
522 0 : aPnt.Y() = SetVScrollMax( aPnt.Y() );
523 : }
524 0 : SetVisArea( aPnt );
525 : }
526 :
527 : /*--------------------------------------------------------------------
528 : Beschreibung: Seitenweises Scrollen
529 : Liefern den Wert, um den bei PageUp / -Down gescrollt werden soll
530 : --------------------------------------------------------------------*/
531 0 : sal_Bool SwView::GetPageScrollUpOffset( SwTwips &rOff ) const
532 : {
533 0 : if ( !m_aVisArea.Top() || !m_aVisArea.GetHeight() )
534 0 : return sal_False;
535 0 : long nYScrl = GetYScroll() / 2;
536 0 : rOff = -(m_aVisArea.GetHeight() - nYScrl);
537 : //nicht vor den Dokumentanfang scrollen
538 0 : if( m_aVisArea.Top() - rOff < 0 )
539 0 : rOff = rOff - m_aVisArea.Top();
540 0 : else if( GetWrtShell().GetCharRect().Top() < (m_aVisArea.Top() + nYScrl))
541 0 : rOff += nYScrl;
542 0 : return sal_True;
543 : }
544 :
545 0 : sal_Bool SwView::GetPageScrollDownOffset( SwTwips &rOff ) const
546 : {
547 0 : if ( !m_aVisArea.GetHeight() ||
548 0 : (m_aVisArea.GetHeight() > m_aDocSz.Height()) )
549 0 : return sal_False;
550 0 : long nYScrl = GetYScroll() / 2;
551 0 : rOff = m_aVisArea.GetHeight() - nYScrl;
552 : //nicht hinter das Dokumentende scrollen
553 0 : if ( m_aVisArea.Top() + rOff > m_aDocSz.Height() )
554 0 : rOff = m_aDocSz.Height() - m_aVisArea.Bottom();
555 0 : else if( GetWrtShell().GetCharRect().Bottom() >
556 0 : ( m_aVisArea.Bottom() - nYScrl ))
557 0 : rOff -= nYScrl;
558 0 : return rOff > 0;
559 : }
560 :
561 : // Seitenweises Blaettern
562 0 : long SwView::PageUp()
563 : {
564 0 : if (!m_aVisArea.GetHeight())
565 0 : return 0;
566 :
567 0 : Point aPos(m_aVisArea.TopLeft());
568 0 : aPos.Y() -= m_aVisArea.GetHeight() - (GetYScroll() / 2);
569 0 : aPos.Y() = std::max(0L, aPos.Y());
570 0 : SetVisArea( aPos );
571 0 : return 1;
572 : }
573 :
574 0 : long SwView::PageDown()
575 : {
576 0 : if ( !m_aVisArea.GetHeight() )
577 0 : return 0;
578 0 : Point aPos( m_aVisArea.TopLeft() );
579 0 : aPos.Y() += m_aVisArea.GetHeight() - (GetYScroll() / 2);
580 0 : aPos.Y() = SetVScrollMax( aPos.Y() );
581 0 : SetVisArea( aPos );
582 0 : return 1;
583 : }
584 :
585 0 : long SwView::PhyPageUp()
586 : {
587 : //aktuell sichtbare Seite erfragen, nicht formatieren
588 0 : sal_uInt16 nActPage = m_pWrtShell->GetNextPrevPageNum( sal_False );
589 :
590 0 : if( USHRT_MAX != nActPage )
591 : {
592 0 : const Point aPt( m_aVisArea.Left(),
593 0 : m_pWrtShell->GetPagePos( nActPage ).Y() );
594 0 : Point aAlPt( AlignToPixel( aPt ) );
595 : // falls ein Unterschied besteht, wurde abgeschnitten --> dann
596 : // einen Pixel addieren, damit kein Rest der Vorgaengerseite
597 : // sichtbar ist
598 0 : if( aPt.Y() != aAlPt.Y() )
599 0 : aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
600 0 : SetVisArea( aAlPt );
601 : }
602 0 : return 1;
603 : }
604 :
605 0 : long SwView::PhyPageDown()
606 : {
607 : //aktuell sichtbare Seite erfragen, nicht formatieren
608 0 : sal_uInt16 nActPage = m_pWrtShell->GetNextPrevPageNum( sal_True );
609 : // falls die letzte Dokumentseite sichtbar ist, nichts tun
610 0 : if( USHRT_MAX != nActPage )
611 : {
612 0 : const Point aPt( m_aVisArea.Left(),
613 0 : m_pWrtShell->GetPagePos( nActPage ).Y() );
614 0 : Point aAlPt( AlignToPixel( aPt ) );
615 : // falls ein Unterschied besteht, wurde abgeschnitten --> dann
616 : // einen Pixel addieren, damit kein Rest der Vorgaengerseite sichtbar ist
617 0 : if( aPt.Y() != aAlPt.Y() )
618 0 : aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
619 0 : SetVisArea( aAlPt );
620 : }
621 0 : return 1;
622 : }
623 :
624 0 : long SwView::PageUpCrsr( sal_Bool bSelect )
625 : {
626 0 : if ( !bSelect )
627 : {
628 0 : const sal_uInt16 eType = m_pWrtShell->GetFrmType(0,sal_True);
629 0 : if ( eType & FRMTYPE_FOOTNOTE )
630 : {
631 0 : m_pWrtShell->MoveCrsr();
632 0 : m_pWrtShell->GotoFtnAnchor();
633 0 : m_pWrtShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
634 0 : return 1;
635 : }
636 : }
637 :
638 0 : SwTwips lOff = 0;
639 0 : if ( GetPageScrollUpOffset( lOff ) &&
640 0 : (m_pWrtShell->IsCrsrReadonly() ||
641 0 : !m_pWrtShell->PageCrsr( lOff, bSelect )) &&
642 0 : PageUp() )
643 : {
644 0 : m_pWrtShell->ResetCursorStack();
645 0 : return sal_True;
646 : }
647 0 : return sal_False;
648 : }
649 :
650 0 : long SwView::PageDownCrsr(sal_Bool bSelect)
651 : {
652 0 : SwTwips lOff = 0;
653 0 : if ( GetPageScrollDownOffset( lOff ) &&
654 0 : (m_pWrtShell->IsCrsrReadonly() ||
655 0 : !m_pWrtShell->PageCrsr( lOff, bSelect )) &&
656 0 : PageDown() )
657 : {
658 0 : m_pWrtShell->ResetCursorStack();
659 0 : return sal_True;
660 : }
661 0 : return sal_False;
662 : }
663 :
664 : /*------------------------------------------------------------------------
665 : Beschreibung: Handler der Scrollbars
666 : ------------------------------------------------------------------------*/
667 0 : IMPL_LINK( SwView, ScrollHdl, SwScrollbar *, pScrollbar )
668 : {
669 0 : if ( GetWrtShell().ActionPend() )
670 0 : return 0;
671 :
672 0 : if ( pScrollbar->GetType() == SCROLL_DRAG )
673 0 : m_pWrtShell->EnableSmooth( sal_False );
674 :
675 0 : if(!m_pWrtShell->GetViewOptions()->getBrowseMode() &&
676 0 : pScrollbar->GetType() == SCROLL_DRAG)
677 : {
678 : //Hier wieder auskommentieren wenn das mitscrollen nicht gewuenscht ist.
679 : // the end scrollhandler invalidate the FN_STAT_PAGE,
680 : // so we dont must do it agin.
681 0 : EndScrollHdl(pScrollbar);
682 :
683 0 : if ( !m_bWheelScrollInProgress && Help::IsQuickHelpEnabled() &&
684 0 : m_pWrtShell->GetViewOptions()->IsShowScrollBarTips())
685 : {
686 :
687 0 : Point aPos( m_aVisArea.TopLeft() );
688 0 : lcl_GetPos(this, aPos, pScrollbar, IsDocumentBorder());
689 :
690 0 : sal_uInt16 nPhNum = 1;
691 0 : sal_uInt16 nVirtNum = 1;
692 :
693 0 : String sDisplay;
694 0 : if(m_pWrtShell->GetPageNumber( aPos.Y(), sal_False, nPhNum, nVirtNum, sDisplay ))
695 : {
696 : // JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
697 : // so we dont must do it agin.
698 : // if(!GetViewFrame()->GetFrame().IsInPlace())
699 : // S F X_BINDINGS().Update(FN_STAT_PAGE);
700 :
701 : //QuickHelp:
702 0 : if( m_pWrtShell->GetPageCnt() > 1 )
703 : {
704 0 : Rectangle aRect;
705 0 : aRect.Left() = pScrollbar->GetParent()->OutputToScreenPixel(
706 0 : pScrollbar->GetPosPixel() ).X() -8;
707 0 : aRect.Top() = pScrollbar->OutputToScreenPixel(
708 0 : pScrollbar->GetPointerPosPixel() ).Y();
709 0 : aRect.Right() = aRect.Left();
710 0 : aRect.Bottom() = aRect.Top();
711 :
712 0 : String sPageStr( GetPageStr( nPhNum, nVirtNum, sDisplay ));
713 0 : SwContentAtPos aCnt( SwContentAtPos::SW_OUTLINE );
714 0 : m_pWrtShell->GetContentAtPos( aPos, aCnt );
715 0 : if( aCnt.sStr.Len() )
716 : {
717 0 : sPageStr += OUString(" - ");
718 0 : sPageStr.Insert( aCnt.sStr, 0, 80 );
719 0 : sPageStr.SearchAndReplaceAll( '\t', ' ' );
720 0 : sPageStr.SearchAndReplaceAll( 0x0a, ' ' );
721 : }
722 0 : nPgNum = nPhNum;
723 : }
724 0 : }
725 : }
726 : }
727 : else
728 0 : EndScrollHdl(pScrollbar);
729 :
730 0 : if ( pScrollbar->GetType() == SCROLL_DRAG )
731 0 : m_pWrtShell->EnableSmooth( sal_True );
732 :
733 0 : return 0;
734 : }
735 :
736 : /*------------------------------------------------------------------------
737 : Beschreibung: Handler der Scrollbars
738 : ------------------------------------------------------------------------*/
739 0 : IMPL_LINK( SwView, EndScrollHdl, SwScrollbar *, pScrollbar )
740 : {
741 0 : if ( !GetWrtShell().ActionPend() )
742 : {
743 0 : if(nPgNum)
744 : {
745 0 : nPgNum = 0;
746 0 : Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0);
747 : }
748 0 : Point aPos( m_aVisArea.TopLeft() );
749 0 : bool bBorder = IsDocumentBorder();
750 0 : lcl_GetPos(this, aPos, pScrollbar, bBorder);
751 0 : if ( bBorder && aPos == m_aVisArea.TopLeft() )
752 0 : UpdateScrollbars();
753 : else
754 0 : SetVisArea( aPos, sal_False );
755 :
756 0 : GetViewFrame()->GetBindings().Update(FN_STAT_PAGE);
757 : }
758 0 : return 0;
759 : }
760 :
761 : /*--------------------------------------------------------------------
762 : Beschreibung:
763 : berechnet die Groesse von m_aVisArea abhaengig von der Groesse
764 : des EditWin auf dem Schirm.
765 : --------------------------------------------------------------------*/
766 1848 : void SwView::CalcVisArea( const Size &rOutPixel )
767 : {
768 1848 : Point aTopLeft;
769 1848 : Rectangle aRect( aTopLeft, rOutPixel );
770 1848 : aTopLeft = GetEditWin().PixelToLogic( aTopLeft );
771 1848 : Point aBottomRight( GetEditWin().PixelToLogic( aRect.BottomRight() ) );
772 :
773 1848 : aRect.Left() = aTopLeft.X();
774 1848 : aRect.Top() = aTopLeft.Y();
775 1848 : aRect.Right() = aBottomRight.X();
776 1848 : aRect.Bottom() = aBottomRight.Y();
777 :
778 : //Die Verschiebungen nach rechts und/oder unten koennen jetzt falsch
779 : //sein (z.B. Zoom aendern, Viewgroesse aendern.
780 1848 : const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
781 1848 : if ( aRect.Left() )
782 : {
783 163 : const long lWidth = GetWrtShell().GetDocSize().Width() + lBorder;
784 163 : if ( aRect.Right() > lWidth )
785 : {
786 3 : long lDelta = aRect.Right() - lWidth;
787 3 : aRect.Left() -= lDelta;
788 3 : aRect.Right() -= lDelta;
789 : }
790 : }
791 1848 : if ( aRect.Top() )
792 : {
793 163 : const long lHeight = GetWrtShell().GetDocSize().Height() + lBorder;
794 163 : if ( aRect.Bottom() > lHeight )
795 : {
796 3 : long lDelta = aRect.Bottom() - lHeight;
797 3 : aRect.Top() -= lDelta;
798 3 : aRect.Bottom() -= lDelta;
799 : }
800 : }
801 1848 : SetVisArea( aRect );
802 1848 : GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
803 1848 : GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER ); // for snapping points
804 1848 : }
805 :
806 : /*--------------------------------------------------------------------
807 : Beschreibung: Bedienelemente neu anordnen
808 : --------------------------------------------------------------------*/
809 1763 : void SwView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ )
810 : {
811 1763 : sal_Bool bRightVRuler = m_pWrtShell->GetViewOptions()->IsVRulerRight();
812 1763 : if ( m_pVRuler->IsVisible() )
813 : {
814 1627 : long nWidth = m_pVRuler->GetSizePixel().Width();
815 1627 : if(bRightVRuler)
816 33 : rToFill.Right() = nWidth;
817 : else
818 1594 : rToFill.Left() = nWidth;
819 : }
820 :
821 : OSL_ENSURE(m_pHRuler, "warum ist das Lineal nicht da?");
822 1763 : if ( m_pHRuler->IsVisible() )
823 1638 : rToFill.Top() = m_pHRuler->GetSizePixel().Height();
824 :
825 1763 : const StyleSettings &rSet = GetEditWin().GetSettings().GetStyleSettings();
826 1763 : const long nTmp = rSet.GetScrollBarSize();
827 1763 : if( m_pVScrollbar->IsVisible(sal_True) )
828 : {
829 1574 : if(bRightVRuler)
830 0 : rToFill.Left() = nTmp;
831 : else
832 1574 : rToFill.Right() = nTmp;
833 : }
834 1763 : if ( m_pHScrollbar->IsVisible(sal_True) )
835 1521 : rToFill.Bottom() = nTmp;
836 :
837 1763 : SetBorderPixel( rToFill );
838 1763 : }
839 :
840 1763 : void ViewResizePixel( const Window &rRef,
841 : const Point &rOfst,
842 : const Size &rSize,
843 : const Size &rEditSz,
844 : const sal_Bool /*bInner*/,
845 : SwScrollbar& rVScrollbar,
846 : SwScrollbar& rHScrollbar,
847 : ImageButton* pPageUpBtn,
848 : ImageButton* pPageDownBtn,
849 : ImageButton* pNaviBtn,
850 : Window& rScrollBarBox,
851 : SvxRuler* pVRuler,
852 : SvxRuler* pHRuler,
853 : sal_Bool bWebView,
854 : sal_Bool bVRulerRight )
855 : {
856 : // ViewResizePixel wird auch von der PreView benutzt!!!
857 :
858 1763 : const sal_Bool bHRuler = pHRuler && pHRuler->IsVisible();
859 : const long nHLinSzHeight = bHRuler ?
860 1763 : pHRuler->GetSizePixel().Height() : 0;
861 1763 : const sal_Bool bVRuler = pVRuler && pVRuler->IsVisible();
862 : const long nVLinSzWidth = bVRuler ?
863 1763 : pVRuler->GetSizePixel().Width() : 0;
864 :
865 1763 : long nScrollBarSize = rRef.GetSettings().GetStyleSettings().GetScrollBarSize();
866 1763 : long nHBSzHeight = rHScrollbar.IsVisible(true) ? nScrollBarSize : 0;
867 1763 : long nVBSzWidth = rVScrollbar.IsVisible(true) ? nScrollBarSize : 0;
868 :
869 1763 : if(pVRuler)
870 : {
871 1763 : WinBits nStyle = pVRuler->GetStyle()&~WB_RIGHT_ALIGNED;
872 1763 : Point aPos( rOfst.X(), rOfst.Y()+nHLinSzHeight );
873 1763 : if(bVRulerRight)
874 : {
875 86 : aPos.X() += rSize.Width() - nVLinSzWidth;
876 86 : nStyle |= WB_RIGHT_ALIGNED;
877 : }
878 1763 : Size aSize( nVLinSzWidth, rEditSz.Height() );
879 1763 : if(!aSize.Width())
880 136 : aSize.Width() = pVRuler->GetSizePixel().Width();
881 1763 : pVRuler->SetStyle(nStyle);
882 1763 : pVRuler->SetPosSizePixel( aPos, aSize );
883 1763 : if(!pVRuler->IsVisible())
884 136 : pVRuler->Resize();
885 : }
886 : // Lineal braucht ein Resize, sonst funktioniert es nicht im unischtbaren Zustand
887 1763 : if(pHRuler)
888 : {
889 1763 : Size aSize( rSize.Width(), nHLinSzHeight );
890 1763 : if ( nVBSzWidth && !bVRulerRight)
891 1574 : aSize.Width() -= nVBSzWidth;
892 1763 : if(!aSize.Height())
893 125 : aSize.Height() = pHRuler->GetSizePixel().Height();
894 1763 : pHRuler->SetPosSizePixel( rOfst, aSize );
895 : // VCL ruft an unsichtbaren Fenstern kein Resize
896 : // fuer das Lineal ist das aber keine gute Idee
897 1763 : if(!pHRuler->IsVisible())
898 125 : pHRuler->Resize();
899 : }
900 :
901 : // Scrollbars und SizeBox anordnen
902 1763 : Point aScrollFillPos;
903 : {
904 : Point aPos( rOfst.X(),
905 1763 : rOfst.Y()+rSize.Height()-nHBSzHeight );
906 1763 : if(bVRulerRight)
907 : {
908 86 : aPos.X() += nVBSzWidth;
909 : }
910 :
911 1763 : Size aSize( rSize.Width(), nHBSzHeight );
912 1763 : if ( nVBSzWidth )
913 1574 : aSize.Width() -= nVBSzWidth;
914 1763 : rHScrollbar.SetPosSizePixel( aPos, aSize );
915 1763 : aScrollFillPos.Y() = aPos.Y();
916 : }
917 : {
918 1763 : Point aPos( rOfst.X()+rSize.Width()-nVBSzWidth,
919 3526 : rOfst.Y() );
920 1763 : Size aSize( nVBSzWidth, rSize.Height() );
921 1763 : if(bVRulerRight)
922 : {
923 86 : aPos.X() = rOfst.X();
924 86 : if(bHRuler)
925 : {
926 28 : aPos.Y() += nHLinSzHeight;
927 28 : aSize.Height() -= nHLinSzHeight;
928 : }
929 : }
930 :
931 1763 : Size aImgSz( nVBSzWidth, nVBSzWidth );
932 :
933 : // wenn der Platz fuer Scrollbar und Page-Buttons zu klein wird, dann
934 : // werden die Buttons versteckt
935 1763 : sal_uInt16 nCnt = pNaviBtn ? 3 : 2;
936 1763 : long nSubSize = (aImgSz.Width() * nCnt );
937 : //
938 1763 : sal_Bool bHidePageButtons = aSize.Height() < ((bWebView ? 3 : 2) * nSubSize);
939 1763 : if(!bHidePageButtons)
940 1763 : aSize.Height() -= nSubSize;
941 : else
942 0 : aImgSz.Width() = 0; // kein Hide, weil das im Update Scrollbar missverstanden wird
943 :
944 1763 : if ( nHBSzHeight )
945 1521 : aSize.Height() -= nHBSzHeight;
946 1763 : rVScrollbar.SetPosSizePixel( aPos, aSize );
947 :
948 1763 : aPos.Y() += aSize.Height();
949 1763 : pPageUpBtn->SetPosSizePixel( aPos, aImgSz );
950 1763 : if(pNaviBtn)
951 : {
952 1763 : aPos.Y() += aImgSz.Height();
953 1763 : pNaviBtn->SetPosSizePixel(aPos, aImgSz);
954 : }
955 :
956 1763 : aPos.Y() += aImgSz.Height();
957 1763 : pPageDownBtn->SetPosSizePixel( aPos, aImgSz );
958 :
959 1763 : aScrollFillPos.X() = aPos.X();
960 : }
961 :
962 1763 : rScrollBarBox.SetPosSizePixel( aScrollFillPos, Size( nHBSzHeight, nVBSzWidth) );
963 1763 : }
964 :
965 774 : void SwView::ShowAtResize()
966 : {
967 774 : m_bShowAtResize = sal_False;
968 774 : if ( m_pWrtShell->GetViewOptions()->IsViewHRuler() )
969 773 : m_pHRuler->Show();
970 774 : }
971 :
972 0 : void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize )
973 : {
974 0 : Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
975 0 : if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
976 : {
977 0 : SvBorder aBorder( GetBorderPixel() );
978 0 : Size aSize( rSize );
979 0 : aSize.Width() -= (aBorder.Left() + aBorder.Right());
980 0 : aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
981 0 : Size aObjSizePixel = GetWindow()->LogicToPixel( aObjSize, MAP_TWIP );
982 0 : SfxViewShell::SetZoomFactor( Fraction( aSize.Width(), aObjSizePixel.Width() ),
983 0 : Fraction( aSize.Height(), aObjSizePixel.Height() ) );
984 : }
985 :
986 0 : m_bInInnerResizePixel = sal_True;
987 0 : const sal_Bool bHScrollVisible = m_pHScrollbar->IsVisible(sal_True);
988 0 : const sal_Bool bVScrollVisible = m_pVScrollbar->IsVisible(sal_True);
989 0 : sal_Bool bRepeat = sal_False;
990 0 : do
991 : {
992 0 : Size aSz( rSize );
993 0 : SvBorder aBorder;
994 0 : CalcAndSetBorderPixel( aBorder, sal_True );
995 0 : if ( GetViewFrame()->GetFrame().IsInPlace() )
996 : {
997 0 : Size aViewSize( aSz );
998 0 : Point aViewPos( rOfst );
999 0 : aViewSize.Height() -= (aBorder.Top() + aBorder.Bottom());
1000 0 : aViewSize.Width() -= (aBorder.Left() + aBorder.Right());
1001 0 : aViewPos.X() += aBorder.Left();
1002 0 : aViewPos.Y() += aBorder.Top();
1003 0 : GetEditWin().SetPosSizePixel( aViewPos, aViewSize );
1004 : }
1005 : else
1006 : {
1007 0 : aSz.Height() += aBorder.Top() + aBorder.Bottom();
1008 0 : aSz.Width() += aBorder.Left() + aBorder.Right();
1009 : }
1010 :
1011 0 : Size aEditSz( GetEditWin().GetOutputSizePixel() );
1012 0 : ViewResizePixel( GetEditWin(), rOfst, aSz, aEditSz, sal_True, *m_pVScrollbar,
1013 : *m_pHScrollbar, m_pPageUpBtn, m_pPageDownBtn,
1014 : m_pNaviBtn,
1015 : *m_pScrollFill, m_pVRuler, m_pHRuler,
1016 0 : 0 != PTR_CAST(SwWebView, this),
1017 0 : m_pWrtShell->GetViewOptions()->IsVRulerRight());
1018 0 : if ( m_bShowAtResize )
1019 0 : ShowAtResize();
1020 :
1021 0 : if( m_pHRuler->IsVisible() || m_pVRuler->IsVisible() )
1022 : {
1023 0 : const Fraction& rFrac = GetEditWin().GetMapMode().GetScaleX();
1024 0 : sal_uInt16 nZoom = 100;
1025 0 : if (0 != rFrac.GetDenominator())
1026 0 : nZoom = sal_uInt16(rFrac.GetNumerator() * 100L / rFrac.GetDenominator());
1027 :
1028 0 : const Fraction aFrac( nZoom, 100 );
1029 0 : m_pVRuler->SetZoom( aFrac );
1030 0 : m_pHRuler->SetZoom( aFrac );
1031 0 : InvalidateRulerPos(); //Inhalt invalidieren.
1032 : }
1033 : //CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1034 : //nicht mehr zum aktuell sichtbaren Bereich passen
1035 0 : m_pWrtShell->ResetCursorStack();
1036 :
1037 : //EditWin niemals einstellen!
1038 :
1039 : //VisArea einstellen, aber dort nicht das SetVisArea der DocShell rufen!
1040 0 : bProtectDocShellVisArea = true;
1041 0 : CalcVisArea( aEditSz );
1042 : //visibility changes of the automatic horizontal scrollbar
1043 : //require to repeat the ViewResizePixel() call - but only once!
1044 0 : if(bRepeat)
1045 0 : bRepeat = sal_False;
1046 0 : else if(bHScrollVisible != m_pHScrollbar->IsVisible(sal_True) ||
1047 0 : bVScrollVisible != m_pVScrollbar->IsVisible(sal_True))
1048 0 : bRepeat = sal_True;
1049 : }while( bRepeat );
1050 0 : bProtectDocShellVisArea = false;
1051 0 : m_bInInnerResizePixel = sal_False;
1052 0 : }
1053 :
1054 2303 : void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
1055 : {
1056 : // #i16909# return, if no size (caused by minimize window).
1057 2303 : if ( m_bInOuterResizePixel || ( !rSize.Width() && !rSize.Height() ) )
1058 2853 : return;
1059 1753 : m_bInOuterResizePixel = sal_True;
1060 :
1061 : // feststellen, ob Scrollbars angezeigt werden duerfen
1062 1753 : sal_Bool bShowH = sal_True,
1063 1753 : bShowV = sal_True,
1064 1753 : bAuto = sal_True,
1065 1753 : bHAuto = sal_True;
1066 :
1067 1753 : const SwViewOption *pVOpt = m_pWrtShell->GetViewOptions();
1068 1753 : if ( !pVOpt->IsReadonly() || pVOpt->IsStarOneSetting() )
1069 : {
1070 1750 : bShowH = pVOpt->IsViewHScrollBar();
1071 1750 : bShowV = pVOpt->IsViewVScrollBar();
1072 : }
1073 :
1074 1753 : if (!m_bHScrollbarEnabled)
1075 : {
1076 67 : bHAuto = bShowH = false;
1077 : }
1078 1753 : if (!m_bVScrollbarEnabled)
1079 : {
1080 91 : bAuto = bShowV = false;
1081 : }
1082 :
1083 1753 : SwDocShell* pDocSh = GetDocShell();
1084 1753 : sal_Bool bIsPreview = pDocSh->IsPreview();
1085 1753 : if( bIsPreview )
1086 : {
1087 0 : bShowH = bShowV = bHAuto = bAuto = sal_False;
1088 : }
1089 1753 : if(m_pHScrollbar->IsVisible(sal_False) != bShowH && !bHAuto)
1090 1 : ShowHScrollbar(bShowH);
1091 1753 : m_pHScrollbar->SetAuto( bHAuto );
1092 1753 : if(m_pVScrollbar->IsVisible(sal_False) != bShowV && !bAuto)
1093 1 : ShowVScrollbar(bShowV);
1094 1753 : m_pVScrollbar->SetAuto(bAuto);
1095 :
1096 1753 : SET_CURR_SHELL( m_pWrtShell );
1097 1753 : sal_Bool bRepeat = sal_False;
1098 1753 : long nCnt = 0;
1099 :
1100 1753 : sal_Bool bUnLockView = !m_pWrtShell->IsViewLocked();
1101 1753 : m_pWrtShell->LockView( sal_True );
1102 1753 : m_pWrtShell->LockPaint();
1103 :
1104 1763 : do {
1105 1763 : ++nCnt;
1106 1763 : const sal_Bool bScroll1 = m_pVScrollbar->IsVisible(sal_True);
1107 1763 : const sal_Bool bScroll2 = m_pHScrollbar->IsVisible(sal_True);
1108 1763 : SvBorder aBorder;
1109 1763 : CalcAndSetBorderPixel( aBorder, sal_False );
1110 1763 : const Size aEditSz( GetEditWin().GetOutputSizePixel() );
1111 1763 : ViewResizePixel( GetEditWin(), rOfst, rSize, aEditSz, sal_False, *m_pVScrollbar,
1112 : *m_pHScrollbar, m_pPageUpBtn, m_pPageDownBtn,
1113 : m_pNaviBtn,
1114 : *m_pScrollFill, m_pVRuler, m_pHRuler,
1115 1763 : 0 != PTR_CAST(SwWebView, this),
1116 5289 : m_pWrtShell->GetViewOptions()->IsVRulerRight() );
1117 1763 : if ( m_bShowAtResize )
1118 774 : ShowAtResize();
1119 :
1120 1763 : if( m_pHRuler->IsVisible() || m_pVRuler->IsVisible() )
1121 1643 : InvalidateRulerPos(); //Inhalt invalidieren.
1122 :
1123 : //CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1124 : //nicht mehr zum aktuell sichtbaren Bereich passen
1125 1763 : m_pWrtShell->ResetCursorStack();
1126 :
1127 : OSL_ENSURE( !GetEditWin().IsVisible() ||
1128 : (( aEditSz.Width() > 0 && aEditSz.Height() > 0 )
1129 : || !m_aVisArea.IsEmpty()), "Small world, isn't it?" );
1130 :
1131 : //EditWin niemals einstellen!
1132 :
1133 : //Die VisArea muss aber natuerlich eingestellt werden.
1134 : //jetzt ist auch der richtige Zeitpunkt den Zoom neu zu berechnen wenn
1135 : //es kein einfacher Faktor ist.
1136 1763 : m_pWrtShell->StartAction();
1137 1763 : CalcVisArea( aEditSz );
1138 :
1139 : //Damit auch beim outplace editing die Seitenbreite sofort
1140 : //angepasst wird.
1141 : //TODO/LATER: is that still necessary?!
1142 : /*
1143 : if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1144 : pDocSh->SetVisArea(
1145 : pDocSh->SfxInPlaceObject::GetVisArea() );*/
1146 1917 : if ( m_pWrtShell->GetViewOptions()->GetZoomType() != SVX_ZOOM_PERCENT &&
1147 154 : !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1148 1 : _SetZoom( aEditSz, (SvxZoomType)m_pWrtShell->GetViewOptions()->GetZoomType(), 100, sal_True );
1149 1763 : m_pWrtShell->EndAction();
1150 :
1151 1763 : bRepeat = bScroll1 != m_pVScrollbar->IsVisible(sal_True);
1152 1763 : if ( !bRepeat )
1153 1761 : bRepeat = bScroll2 != m_pHScrollbar->IsVisible(sal_True);
1154 :
1155 : //Nicht endlosschleifen. Moeglichst dann stoppen wenn die
1156 : //(Auto-)Scrollbars sichtbar sind.
1157 1763 : if ( bRepeat &&
1158 10 : ( nCnt > 10 || ( nCnt > 3 && bHAuto && bAuto ) )
1159 : )
1160 : {
1161 0 : bRepeat = sal_False;
1162 : }
1163 :
1164 : }while ( bRepeat );
1165 :
1166 1753 : if( m_pVScrollbar->IsVisible(sal_False) || m_pVScrollbar->IsAuto())
1167 : {
1168 1662 : sal_Bool bShowButtons = m_pVScrollbar->IsVisible(sal_True);
1169 1662 : if(m_pPageUpBtn && m_pPageUpBtn->IsVisible() != bShowButtons)
1170 : {
1171 0 : m_pPageUpBtn->Show(bShowButtons);
1172 0 : if(m_pPageDownBtn)
1173 0 : m_pPageDownBtn->Show(bShowButtons);
1174 0 : if(m_pNaviBtn)
1175 0 : m_pNaviBtn->Show(bShowButtons);
1176 : }
1177 : }
1178 :
1179 1753 : m_pWrtShell->UnlockPaint();
1180 1753 : if( bUnLockView )
1181 1734 : m_pWrtShell->LockView( sal_False );
1182 :
1183 1753 : m_bInOuterResizePixel = sal_False;
1184 :
1185 1753 : if ( m_pPostItMgr )
1186 : {
1187 1753 : m_pPostItMgr->CalcRects();
1188 1753 : m_pPostItMgr->LayoutPostIts();
1189 1753 : }
1190 : }
1191 :
1192 0 : void SwView::SetZoomFactor( const Fraction &rX, const Fraction &rY )
1193 : {
1194 0 : const Fraction &rFrac = rX < rY ? rX : rY;
1195 0 : SetZoom( SVX_ZOOM_PERCENT, (short) long(rFrac * Fraction( 100, 1 )) );
1196 :
1197 : //Um Rundungsfehler zu minimieren lassen wir von der Basisklasse ggf.
1198 : //auch die krummen Werte einstellen
1199 0 : SfxViewShell::SetZoomFactor( rX, rY );
1200 0 : }
1201 :
1202 3507 : sal_Bool SwView::UpdateScrollbars()
1203 : {
1204 3507 : sal_Bool bRet = sal_False;
1205 3507 : if ( !m_aVisArea.IsEmpty() )
1206 : {
1207 1921 : const bool bBorder = IsDocumentBorder();
1208 1921 : Rectangle aTmpRect( m_aVisArea );
1209 1921 : if ( bBorder )
1210 : {
1211 27 : Point aPt( DOCUMENTBORDER, DOCUMENTBORDER );
1212 27 : aPt = AlignToPixel( aPt );
1213 27 : aTmpRect.Move( -aPt.X(), -aPt.Y() );
1214 : }
1215 :
1216 1921 : Size aTmpSz( m_aDocSz );
1217 1921 : const long lOfst = bBorder ? 0 : DOCUMENTBORDER * 2L;
1218 1921 : aTmpSz.Width() += lOfst; aTmpSz.Height() += lOfst;
1219 :
1220 : {
1221 1921 : const sal_Bool bVScrollVisible = m_pVScrollbar->IsVisible(sal_True);
1222 1921 : m_pVScrollbar->DocSzChgd( aTmpSz );
1223 1921 : m_pVScrollbar->ViewPortChgd( aTmpRect );
1224 :
1225 1921 : sal_Bool bShowButtons = m_pVScrollbar->IsVisible(sal_True);
1226 1921 : if(m_pPageUpBtn && m_pPageUpBtn->IsVisible() != bShowButtons)
1227 : {
1228 764 : m_pPageUpBtn->Show(bShowButtons);
1229 764 : if(m_pPageDownBtn)
1230 764 : m_pPageDownBtn->Show(bShowButtons);
1231 764 : if(m_pNaviBtn)
1232 764 : m_pNaviBtn->Show(bShowButtons);
1233 : }
1234 :
1235 1921 : if ( bVScrollVisible != m_pVScrollbar->IsVisible(sal_True) )
1236 15 : bRet = sal_True;
1237 : }
1238 : {
1239 1921 : const sal_Bool bHScrollVisible = m_pHScrollbar->IsVisible(sal_True);
1240 1921 : m_pHScrollbar->DocSzChgd( aTmpSz );
1241 1921 : m_pHScrollbar->ViewPortChgd( aTmpRect );
1242 1921 : if ( bHScrollVisible != m_pHScrollbar->IsVisible(sal_True) )
1243 33 : bRet = sal_True;
1244 1921 : m_pScrollFill->Show(m_pHScrollbar->IsVisible(sal_True) && m_pVScrollbar->IsVisible(sal_True) );
1245 : }
1246 : }
1247 3507 : return bRet;
1248 : }
1249 :
1250 0 : void SwView::Move()
1251 : {
1252 0 : if ( GetWrtShell().IsInSelect() )
1253 0 : GetWrtShell().EndSelect();
1254 0 : SfxViewShell::Move();
1255 0 : }
1256 :
1257 0 : sal_Bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
1258 : {
1259 0 : const CommandWheelData* pWData = rCEvt.GetWheelData();
1260 0 : if (!pWData)
1261 : {
1262 0 : return sal_False;
1263 : }
1264 :
1265 0 : sal_Bool bOk = sal_False;
1266 0 : if( COMMAND_WHEEL_ZOOM == pWData->GetMode() )
1267 : {
1268 0 : long nFact = m_pWrtShell->GetViewOptions()->GetZoom();
1269 0 : if( 0L > pWData->GetDelta() )
1270 0 : nFact = std::max( (long) 20, basegfx::zoomtools::zoomOut( nFact ));
1271 : else
1272 0 : nFact = std::min( (long) 600, basegfx::zoomtools::zoomIn( nFact ));
1273 :
1274 0 : SetZoom( SVX_ZOOM_PERCENT, nFact );
1275 0 : bOk = sal_True;
1276 : }
1277 0 : else if( COMMAND_WHEEL_ZOOM_SCALE == pWData->GetMode() )
1278 : {
1279 0 : int newZoom = 100 * (m_pWrtShell->GetViewOptions()->GetZoom() / 100.0) * (pWData->GetDelta() / 100.0);
1280 0 : SetZoom( SVX_ZOOM_PERCENT, std::max( 20, std::min( 600, newZoom ) ) );
1281 0 : bOk = sal_True;
1282 : }
1283 : else
1284 : {
1285 0 : if(pWData->GetMode()==COMMAND_WHEEL_SCROLL)
1286 : {
1287 : // This influences whether quick help is shown
1288 0 : m_bWheelScrollInProgress=true;
1289 : }
1290 :
1291 0 : if ((COMMAND_WHEEL_SCROLL==pWData->GetMode()) && (((sal_uLong)0xFFFFFFFF) == pWData->GetScrollLines()))
1292 : {
1293 0 : if (pWData->GetDelta()<0)
1294 0 : PhyPageDown();
1295 : else
1296 0 : PhyPageUp();
1297 0 : bOk = sal_True;
1298 : }
1299 : else
1300 0 : bOk = m_pEditWin->HandleScrollCommand(rCEvt, m_pHScrollbar, m_pVScrollbar);
1301 :
1302 : // Restore default state for case when scroll command comes from dragging scrollbar handle
1303 0 : m_bWheelScrollInProgress=false;
1304 : }
1305 0 : return bOk;
1306 99 : }
1307 :
1308 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|