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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
24 #include <svtools/colorcfg.hxx>
25 #include <svx/fmview.hxx>
26 #include <editeng/sizeitem.hxx>
27 #include <svx/svdpagv.hxx>
28 #include <sfx2/bindings.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <svtools/accessibilityoptions.hxx>
32 #include <svl/itemset.hxx>
33 #include <tools/multisel.hxx>
34 #include <vcl/waitobj.hxx>
36 #include "preview.hxx"
37 #include "prevwsh.hxx"
38 #include "prevloc.hxx"
40 #include "docfunc.hxx"
41 #include "printfun.hxx"
42 #include "printopt.hxx"
43 #include "stlpool.hxx"
44 #include "undostyl.hxx"
45 #include "drwlayer.hxx"
47 #include "markdata.hxx"
48 #include "globstr.hrc"
49 #include "sc.hrc" // for ShellInvalidate
50 #include "AccessibleDocumentPagePreview.hxx"
51 #include <vcl/lineinfo.hxx>
52 #include <svx/algitem.hxx>
53 #include <editeng/lrspitem.hxx>
54 #include <editeng/ulspitem.hxx>
56 #include "pagepar.hxx"
57 #include <com/sun/star/accessibility/XAccessible.hpp>
58 #include "AccessibilityHints.hxx"
59 #include <vcl/svapp.hxx>
60 #include "viewutil.hxx"
62 // STATIC DATA -----------------------------------------------------------
64 //==================================================================
66 #define SC_PREVIEW_SHADOWSIZE 2
68 static long lcl_GetDisplayStart( SCTAB nTab
, ScDocument
* pDoc
, std::vector
<long>& nPages
)
70 long nDisplayStart
= 0;
71 for (SCTAB i
=0; i
<nTab
; i
++)
73 if ( pDoc
->NeedPageResetAfterTab(i
) )
76 nDisplayStart
+= nPages
[i
];
82 ScPreview::ScPreview( Window
* pParent
, ScDocShell
* pDocSh
, ScPreviewShell
* pViewSh
) :
92 aDate( Date::SYSTEM
),
93 aTime( Time::SYSTEM
),
95 pLocationData( NULL
),
98 pViewShell( pViewSh
),
101 bStateValid( false ),
102 bLocationValid( false ),
105 bLeftRulerMove( false ),
106 bRightRulerMove( false ),
107 bTopRulerMove( false ),
108 bBottomRulerMove( false ),
109 bHeaderRulerMove( false ),
110 bFooterRulerMove( false ),
111 bLeftRulerChange( false ),
112 bRightRulerChange( false ),
113 bTopRulerChange( false ),
114 bBottomRulerChange( false ),
115 bHeaderRulerChange( false ),
116 bFooterRulerChange( false ),
117 bPageMargin ( false ),
118 bColRulerMove( false ),
120 nColNumberButttonDown( 0 ),
124 SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW
); //#106611#
127 SetHelpId( HID_SC_WIN_PREVIEW
);
128 SetUniqueId( HID_SC_WIN_PREVIEW
);
130 SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
132 for (SCCOL i
=0; i
<=MAXCOL
; i
++)
133 nRight
[i
] = 0; // initialized with actual positions when markers are drawn
137 ScPreview::~ScPreview()
140 delete pLocationData
;
143 void ScPreview::UpdateDrawView() // nTab must be right
145 ScDocument
* pDoc
= pDocShell
->GetDocument();
146 ScDrawLayer
* pModel
= pDoc
->GetDrawLayer(); // is not 0
151 SdrPage
* pPage
= pModel
->GetPage(nTab
);
152 if ( pDrawView
&& ( !pDrawView
->GetSdrPageView() || pDrawView
->GetSdrPageView()->GetPage() != pPage
) )
154 // die angezeigte Page der DrawView umzustellen (s.u.) funktioniert nicht ?!?
159 if ( !pDrawView
) // New Drawing?
161 pDrawView
= new FmFormView( pModel
, this );
163 // The DrawView takes over the Design-Mode from the Model
164 // (Settings "In opening Draftmode"), therefore to restore here
165 pDrawView
->SetDesignMode( true );
166 pDrawView
->SetPrintPreview( true );
167 pDrawView
->ShowSdrPage(pPage
);
170 else if ( pDrawView
)
172 delete pDrawView
; // for this Chart is not needed
178 void ScPreview::TestLastPage()
180 if (nPageNo
>= nTotalPages
)
184 nPageNo
= nTotalPages
- 1;
185 nTab
= static_cast<SCTAB
>(nPages
.size()) -1;
186 while (nTab
> 0 && !nPages
[nTab
]) // not the last empty Table
188 OSL_ENSURE(0 < static_cast<SCTAB
>(nPages
.size()),"are all tables empty?");
189 nTabPage
= nPages
[nTab
] - 1;
191 for (sal_uInt16 i
=0; i
<nTab
; i
++)
192 nTabStart
+= nPages
[i
];
194 ScDocument
* pDoc
= pDocShell
->GetDocument();
195 nDisplayStart
= lcl_GetDisplayStart( nTab
, pDoc
, nPages
);
197 else // empty Document
200 nPageNo
= nTabPage
= nTabStart
= nDisplayStart
= 0;
201 aState
.nPrintTab
= 0;
202 aState
.nStartCol
= aState
.nEndCol
= 0;
203 aState
.nStartRow
= aState
.nEndRow
= 0;
205 aState
.nPagesX
= aState
.nPagesY
= 0;
206 aState
.nTabPages
= aState
.nTotalPages
=
207 aState
.nPageStart
= aState
.nDocPages
= 0;
213 void ScPreview::CalcPages()
215 WaitObject
aWait( this );
217 ScDocument
* pDoc
= pDocShell
->GetDocument();
218 nTabCount
= pDoc
->GetTableCount();
220 SCTAB nStart
= nTabsTested
;
228 // update all pending row heights with a single progress bar,
229 // instead of a separate progress for each sheet from ScPrintFunc
230 pDocShell
->UpdatePendingRowHeights( nTabCount
-1, true );
232 // PrintOptions is passed to PrintFunc for SkipEmpty flag,
233 // but always all sheets are used (there is no selected sheet)
234 ScPrintOptions aOptions
= SC_MOD()->GetPrintOptions();
236 while (nStart
> static_cast<SCTAB
>(nPages
.size()))
238 while (nStart
> static_cast<SCTAB
>(nFirstAttr
.size()))
239 nFirstAttr
.push_back(0);
241 for (SCTAB i
=nStart
; i
<nTabCount
; i
++)
243 if ( i
== static_cast<SCTAB
>(nPages
.size()))
245 if ( i
== static_cast<SCTAB
>(nFirstAttr
.size()))
246 nFirstAttr
.push_back(0);
247 if (!aOptions
.GetAllSheets() && maSelectedTabs
.count(i
) == 0)
254 long nAttrPage
= i
> 0 ? nFirstAttr
[i
-1] : 1;
256 long nThisStart
= nTotalPages
;
257 ScPrintFunc
aPrintFunc( this, pDocShell
, i
, nAttrPage
, 0, NULL
, &aOptions
);
258 long nThisTab
= aPrintFunc
.GetTotalPages();
259 nPages
[i
] = nThisTab
;
260 nTotalPages
+= nThisTab
;
261 nFirstAttr
[i
] = aPrintFunc
.GetFirstPageNo(); // to keep or from template
263 if (nPageNo
>=nThisStart
&& nPageNo
<nTotalPages
)
266 nTabPage
= nPageNo
- nThisStart
;
267 nTabStart
= nThisStart
;
269 aPrintFunc
.GetPrintState( aState
);
270 aPageSize
= aPrintFunc
.GetPageSize();
274 nDisplayStart
= lcl_GetDisplayStart( nTab
, pDoc
, nPages
);
276 if (nTabCount
> nTabsTested
)
277 nTabsTested
= nTabCount
;
281 aState
.nDocPages
= nTotalPages
;
289 void ScPreview::RecalcPages() // only nPageNo is changed
292 return; // then CalcPages is called
294 SCTAB nOldTab
= nTab
;
297 while (nPageNo
>= nTotalPages
&& nTabsTested
< nTabCount
)
306 for (SCTAB i
=0; i
<nTabsTested
&& nTab
< static_cast<SCTAB
>(nPages
.size()); i
++)
308 long nThisStart
= nPartPages
;
309 nPartPages
+= nPages
[i
];
311 if (nPageNo
>=nThisStart
&& nPageNo
<nPartPages
)
314 nTabPage
= nPageNo
- nThisStart
;
315 nTabStart
= nThisStart
;
319 ScDocument
* pDoc
= pDocShell
->GetDocument();
320 nDisplayStart
= lcl_GetDisplayStart( nTab
, pDoc
, nPages
);
323 TestLastPage(); // to test, if after last page
325 if ( nTab
!= nOldTab
)
332 void ScPreview::DoPrint( ScPreviewLocationData
* pFillLocation
)
338 UpdateDrawView(); // Spreedsheet eventually changes
341 Fraction
aPreviewZoom( nZoom
, 100 );
342 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
343 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
345 bool bDoPrint
= ( pFillLocation
== NULL
);
346 bool bValidPage
= ( nPageNo
< nTotalPages
);
348 ScModule
* pScMod
= SC_MOD();
349 const svtools::ColorConfig
& rColorCfg
= pScMod
->GetColorConfig();
350 Color
aBackColor( rColorCfg
.GetColorValue(svtools::APPBACKGROUND
).nColor
);
352 if ( bDoPrint
&& ( aOffset
.X() < 0 || aOffset
.Y() < 0 ) && bValidPage
)
354 SetMapMode( aMMMode
);
356 SetFillColor(aBackColor
);
358 Size aWinSize
= GetOutputSize();
359 if ( aOffset
.X() < 0 )
360 DrawRect(Rectangle( 0, 0, -aOffset
.X(), aWinSize
.Height() ));
361 if ( aOffset
.Y() < 0 )
362 DrawRect(Rectangle( 0, 0, aWinSize
.Width(), -aOffset
.Y() ));
365 long nLeftMargin
= 0;
366 long nRightMargin
= 0;
368 long nBottomMargin
= 0;
369 bool bHeaderOn
= false;
370 bool bFooterOn
= false;
372 ScDocument
* pDoc
= pDocShell
->GetDocument();
373 bool bLayoutRTL
= pDoc
->IsLayoutRTL( nTab
);
378 ScPrintOptions aOptions
= pScMod
->GetPrintOptions();
380 ScPrintFunc
* pPrintFunc
;
382 pPrintFunc
= new ScPrintFunc( this, pDocShell
, aState
, &aOptions
);
384 pPrintFunc
= new ScPrintFunc( this, pDocShell
, nTab
, nFirstAttr
[nTab
], nTotalPages
, NULL
, &aOptions
);
386 pPrintFunc
->SetOffset(aOffset
);
387 pPrintFunc
->SetManualZoom(nZoom
);
388 pPrintFunc
->SetDateTime(aDate
,aTime
);
389 pPrintFunc
->SetClearFlag(true);
390 pPrintFunc
->SetUseStyleColor( pScMod
->GetAccessOptions().GetIsForPagePreviews() );
392 pPrintFunc
->SetDrawView( pDrawView
);
394 // MultiSelection for the one Page must produce something inconvenient
395 Range
aPageRange( nPageNo
+1, nPageNo
+1 );
396 MultiSelection
aPage( aPageRange
);
397 aPage
.SetTotalRange( Range(0,RANGE_MAX
) );
398 aPage
.Select( aPageRange
);
400 long nPrinted
= pPrintFunc
->DoPrint( aPage
, nTabStart
, nDisplayStart
, bDoPrint
, pFillLocation
);
401 OSL_ENSURE(nPrinted
<=1, "was'n nu los?");
405 //init nLeftMargin ... in the ScPrintFunc::InitParam!!!
406 nLeftMargin
= pPrintFunc
->GetLeftMargin();
407 nRightMargin
= pPrintFunc
->GetRightMargin();
408 nTopMargin
= pPrintFunc
->GetTopMargin();
409 nBottomMargin
= pPrintFunc
->GetBottomMargin();
410 nHeaderHeight
= pPrintFunc
->GetHeader().nHeight
;
411 nFooterHeight
= pPrintFunc
->GetFooter().nHeight
;
412 bHeaderOn
= pPrintFunc
->GetHeader().bEnable
;
413 bFooterOn
= pPrintFunc
->GetFooter().bEnable
;
414 mnScale
= pPrintFunc
->GetZoom();
416 if ( bDoPrint
&& bPageMargin
&& pLocationData
) // don't make use of pLocationData while filling it
419 Rectangle aRectCellPosition
;
420 Rectangle aRectPosition
;
421 pLocationData
->GetMainCellRange( aPageArea
, aPixRect
);
424 pLocationData
->GetCellPosition( aPageArea
.aStart
, aRectPosition
);
425 nLeftPosition
= aRectPosition
.Left();
426 for( SCCOL i
= aPageArea
.aStart
.Col(); i
<= aPageArea
.aEnd
.Col(); i
++ )
428 pLocationData
->GetCellPosition( ScAddress( i
,aPageArea
.aStart
.Row(),aPageArea
.aStart
.Tab()),aRectCellPosition
);
429 nRight
[i
] = aRectCellPosition
.Right();
434 pLocationData
->GetCellPosition( aPageArea
.aEnd
, aRectPosition
);
435 nLeftPosition
= aRectPosition
.Right()+1;
437 pLocationData
->GetCellPosition( aPageArea
.aStart
,aRectCellPosition
);
438 nRight
[ aPageArea
.aEnd
.Col() ] = aRectCellPosition
.Left();
439 for( SCCOL i
= aPageArea
.aEnd
.Col(); i
> aPageArea
.aStart
.Col(); i
-- )
441 pLocationData
->GetCellPosition( ScAddress( i
,aPageArea
.aEnd
.Row(),aPageArea
.aEnd
.Tab()),aRectCellPosition
);
442 nRight
[ i
-1 ] = nRight
[ i
] + aRectCellPosition
.Right() - aRectCellPosition
.Left() + 1;
447 if (nPrinted
) // if not, draw everything grey
449 aLocalPageSize
= pPrintFunc
->GetPageSize();
450 aLocalPageSize
.Width() = (long) (aLocalPageSize
.Width() * HMM_PER_TWIPS
);
451 aLocalPageSize
.Height() = (long) (aLocalPageSize
.Height() * HMM_PER_TWIPS
);
453 nLeftMargin
= (long) ( nLeftMargin
* HMM_PER_TWIPS
);
454 nRightMargin
= (long) ( nRightMargin
* HMM_PER_TWIPS
);
455 nTopMargin
= (long) ( nTopMargin
* HMM_PER_TWIPS
);
456 nBottomMargin
= (long) ( nBottomMargin
* HMM_PER_TWIPS
);
457 nHeaderHeight
= (long) ( nHeaderHeight
* HMM_PER_TWIPS
* mnScale
/ 100 + nTopMargin
);
458 nFooterHeight
= (long) ( nFooterHeight
* HMM_PER_TWIPS
* mnScale
/ 100 + nBottomMargin
);
463 pPrintFunc
->GetPrintState( aState
);
464 aState
.nDocPages
= nTotalPages
;
472 long nPageEndX
= aLocalPageSize
.Width() - aOffset
.X();
473 long nPageEndY
= aLocalPageSize
.Height() - aOffset
.Y();
475 nPageEndX
= nPageEndY
= 0;
477 Size aWinSize
= GetOutputSize();
478 Point
aWinEnd( aWinSize
.Width(), aWinSize
.Height() );
479 bool bRight
= nPageEndX
<= aWinEnd
.X();
480 bool bBottom
= nPageEndY
<= aWinEnd
.Y();
482 if( bPageMargin
&& bValidPage
)
485 SetLineColor( COL_BLACK
);
486 DrawInvert( (long)( nTopMargin
- aOffset
.Y() ), POINTER_VSIZEBAR
);
487 DrawInvert( (long)(nPageEndY
- nBottomMargin
), POINTER_VSIZEBAR
);
488 DrawInvert( (long)( nLeftMargin
- aOffset
.X() ), POINTER_HSIZEBAR
);
489 DrawInvert( (long)( nPageEndX
- nRightMargin
) , POINTER_HSIZEBAR
);
492 DrawInvert( nHeaderHeight
- aOffset
.Y(), POINTER_VSIZEBAR
);
496 DrawInvert( nPageEndY
- nFooterHeight
, POINTER_VSIZEBAR
);
499 SetMapMode( MapMode( MAP_PIXEL
) );
500 for( int i
= aPageArea
.aStart
.Col(); i
<= aPageArea
.aEnd
.Col(); i
++ )
502 Point aColumnTop
= LogicToPixel( Point( 0, -aOffset
.Y() ) ,aMMMode
);
503 SetLineColor( COL_BLACK
);
504 SetFillColor( COL_BLACK
);
505 DrawRect( Rectangle( Point( nRight
[i
] - 2, aColumnTop
.Y() ),Point( nRight
[i
] + 2 , 4 + aColumnTop
.Y()) ));
506 DrawLine( Point( nRight
[i
], aColumnTop
.Y() ), Point( nRight
[i
], 10 + aColumnTop
.Y()) );
508 SetMapMode( aMMMode
);
511 if (bRight
|| bBottom
)
515 SetFillColor(aBackColor
);
517 DrawRect(Rectangle(nPageEndX
,0, aWinEnd
.X(),aWinEnd
.Y()));
521 DrawRect(Rectangle(0,nPageEndY
, nPageEndX
,aWinEnd
.Y())); // Corner not duplicated
523 DrawRect(Rectangle(0,nPageEndY
, aWinEnd
.X(),aWinEnd
.Y()));
529 Color
aBorderColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR
).nColor
);
533 if ( aOffset
.X() <= 0 || aOffset
.Y() <= 0 || bRight
|| bBottom
)
535 SetLineColor( aBorderColor
);
538 Rectangle
aPixel( LogicToPixel( Rectangle( -aOffset
.X(), -aOffset
.Y(), nPageEndX
, nPageEndY
) ) );
541 DrawRect( PixelToLogic( aPixel
) );
547 SetFillColor( aBorderColor
);
551 aPixel
= LogicToPixel( Rectangle( nPageEndX
, -aOffset
.Y(), nPageEndX
, nPageEndY
) );
552 aPixel
.Top() += SC_PREVIEW_SHADOWSIZE
;
553 aPixel
.Right() += SC_PREVIEW_SHADOWSIZE
- 1;
554 aPixel
.Bottom() += SC_PREVIEW_SHADOWSIZE
- 1;
555 DrawRect( PixelToLogic( aPixel
) );
557 aPixel
= LogicToPixel( Rectangle( -aOffset
.X(), nPageEndY
, nPageEndX
, nPageEndY
) );
558 aPixel
.Left() += SC_PREVIEW_SHADOWSIZE
;
559 aPixel
.Right() += SC_PREVIEW_SHADOWSIZE
- 1;
560 aPixel
.Bottom() += SC_PREVIEW_SHADOWSIZE
- 1;
561 DrawRect( PixelToLogic( aPixel
) );
566 void ScPreview::Paint( const Rectangle
& /* rRect */ )
568 bool bWasInPaint
= bInPaint
; // nested calls shouldn't be necessary, but allow for now
572 GetLocationData(); // fill location data for column positions
574 pViewShell
->UpdateScrollBars();
576 bInPaint
= bWasInPaint
;
579 void ScPreview::Command( const CommandEvent
& rCEvt
)
581 sal_uInt16 nCmd
= rCEvt
.GetCommand();
582 if ( nCmd
== COMMAND_WHEEL
|| nCmd
== COMMAND_STARTAUTOSCROLL
|| nCmd
== COMMAND_AUTOSCROLL
)
584 bool bDone
= pViewShell
->ScrollCommand( rCEvt
);
586 Window::Command(rCEvt
);
588 else if ( nCmd
== COMMAND_CONTEXTMENU
)
589 SfxDispatcher::ExecutePopup();
591 Window::Command( rCEvt
);
595 void ScPreview::KeyInput( const KeyEvent
& rKEvt
)
597 // The + and - keys can't be configured as accelerator entries, so they must be handled directly
598 // (in ScPreview, not ScPreviewShell -> only if the preview window has the focus)
600 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
601 sal_uInt16 nKey
= rKeyCode
.GetCode();
602 bool bHandled
= false;
603 if(!rKeyCode
.GetModifier())
605 sal_uInt16 nSlot
= 0;
608 case KEY_ADD
: nSlot
= SID_PREVIEW_ZOOMIN
; break;
609 case KEY_ESCAPE
: nSlot
= ScViewUtil::IsFullScreen( *pViewShell
) ? SID_CANCEL
: SID_PREVIEW_CLOSE
; break;
610 case KEY_SUBTRACT
: nSlot
= SID_PREVIEW_ZOOMOUT
; break;
615 pViewShell
->GetViewFrame()->GetDispatcher()->Execute( nSlot
, SFX_CALLMODE_ASYNCHRON
);
619 if ( !bHandled
&& !pViewShell
->KeyInput(rKEvt
) )
620 Window::KeyInput(rKEvt
);
624 const ScPreviewLocationData
& ScPreview::GetLocationData()
626 if ( !pLocationData
)
628 pLocationData
= new ScPreviewLocationData( pDocShell
->GetDocument(), this );
629 bLocationValid
= false;
631 if ( !bLocationValid
)
633 pLocationData
->Clear();
634 DoPrint( pLocationData
);
635 bLocationValid
= true;
637 return *pLocationData
;
641 void ScPreview::DataChanged(bool bNewTime
)
645 aDate
= Date( Date::SYSTEM
);
646 aTime
= Time( Time::SYSTEM
);
650 InvalidateLocationData( SC_HINT_DATACHANGED
);
655 String
ScPreview::GetPosString()
660 UpdateDrawView(); // The table eventually changes
663 String
aString( ScGlobal::GetRscString( STR_PAGE
) );
665 aString
+= String::CreateFromInt32(nPageNo
+1);
667 if (nTabsTested
>= nTabCount
)
669 aString
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
670 aString
+= String::CreateFromInt32(nTotalPages
);
677 void ScPreview::SetZoom(sal_uInt16 nNewZoom
)
683 if (nNewZoom
!= nZoom
)
687 // apply new MapMode and call UpdateScrollBars to update aOffset
689 Fraction
aPreviewZoom( nZoom
, 100 );
690 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
691 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
692 SetMapMode( aMMMode
);
694 bInSetZoom
= true; // don't scroll during SetYOffset in UpdateScrollBars
695 pViewShell
->UpdateNeededScrollBars(true);
699 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED
);
706 void ScPreview::SetPageNo( long nPage
)
710 UpdateDrawView(); // The table eventually changes
711 InvalidateLocationData( SC_HINT_DATACHANGED
);
716 long ScPreview::GetFirstPage(SCTAB nTabP
)
718 SCTAB nDocTabCount
= pDocShell
->GetDocument()->GetTableCount();
719 if (nTabP
>= nDocTabCount
)
720 nTabP
= nDocTabCount
-1;
726 if (nTabP
>= static_cast<SCTAB
>(nPages
.size()) )
727 OSL_FAIL("nPages out ouf bounds, FIX IT");
728 UpdateDrawView(); // The table eventually changes
730 for (SCTAB i
=0; i
<nTabP
; i
++)
733 // An empty Table on the previous Page
735 if ( nPages
[nTabP
]==0 && nPage
> 0 )
743 static Size
lcl_GetDocPageSize( ScDocument
* pDoc
, SCTAB nTab
)
745 String aName
= pDoc
->GetPageStyle( nTab
);
746 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
747 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aName
, SFX_STYLE_FAMILY_PAGE
);
750 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
751 return ((const SvxSizeItem
&) rStyleSet
.Get(ATTR_PAGE_SIZE
)).GetSize();
755 OSL_FAIL( "PageStyle not found" );
761 sal_uInt16
ScPreview::GetOptimalZoom(bool bWidthOnly
)
763 double nWinScaleX
= ScGlobal::nScreenPPTX
/ pDocShell
->GetOutputFactor();
764 double nWinScaleY
= ScGlobal::nScreenPPTY
;
765 Size aWinSize
= GetOutputSizePixel();
767 // desired margin is 0.25cm in default MapMode (like Writer),
768 // but some additional margin is introduced by integer scale values
769 // -> add only 0.10cm, so there is some margin in all cases.
770 Size
aMarginSize( LogicToPixel( Size( 100, 100 ), MAP_100TH_MM
) );
771 aWinSize
.Width() -= 2 * aMarginSize
.Width();
772 aWinSize
.Height() -= 2 * aMarginSize
.Height();
774 Size aLocalPageSize
= lcl_GetDocPageSize( pDocShell
->GetDocument(), nTab
);
775 if ( aLocalPageSize
.Width() && aLocalPageSize
.Height() )
777 long nZoomX
= (long) ( aWinSize
.Width() * 100 / ( aLocalPageSize
.Width() * nWinScaleX
));
778 long nZoomY
= (long) ( aWinSize
.Height() * 100 / ( aLocalPageSize
.Height() * nWinScaleY
));
780 long nOptimal
= nZoomX
;
781 if (!bWidthOnly
&& nZoomY
<nOptimal
)
789 return (sal_uInt16
) nOptimal
;
796 void ScPreview::SetXOffset( long nX
)
798 if ( aOffset
.X() == nX
)
803 long nDif
= LogicToPixel(aOffset
).X() - LogicToPixel(Point(nX
,0)).X();
805 if (nDif
&& !bInSetZoom
)
807 MapMode aOldMode
= GetMapMode(); SetMapMode(MAP_PIXEL
);
809 SetMapMode(aOldMode
);
818 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED
);
823 void ScPreview::SetYOffset( long nY
)
825 if ( aOffset
.Y() == nY
)
830 long nDif
= LogicToPixel(aOffset
).Y() - LogicToPixel(Point(0,nY
)).Y();
832 if (nDif
&& !bInSetZoom
)
834 MapMode aOldMode
= GetMapMode(); SetMapMode(MAP_PIXEL
);
836 SetMapMode(aOldMode
);
845 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED
);
850 void ScPreview::DoInvalidate()
852 // If the whole GetState of the shell is called
853 // The Invalidate must come behind asynchronously
856 Application::PostUserEvent( STATIC_LINK( this, ScPreview
, InvalidateHdl
) );
858 StaticInvalidate(); // Immediately
861 void ScPreview::StaticInvalidate()
863 // static method, because it's called asynchronously
864 // -> must use current viewframe
866 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
870 SfxBindings
& rBindings
= pViewFrm
->GetBindings();
871 rBindings
.Invalidate(SID_STATUS_DOCPOS
);
872 rBindings
.Invalidate(SID_STATUS_PAGESTYLE
);
873 rBindings
.Invalidate(SID_PREVIEW_PREVIOUS
);
874 rBindings
.Invalidate(SID_PREVIEW_NEXT
);
875 rBindings
.Invalidate(SID_PREVIEW_FIRST
);
876 rBindings
.Invalidate(SID_PREVIEW_LAST
);
877 rBindings
.Invalidate(SID_ATTR_ZOOM
);
878 rBindings
.Invalidate(SID_PREVIEW_ZOOMIN
);
879 rBindings
.Invalidate(SID_PREVIEW_ZOOMOUT
);
880 rBindings
.Invalidate(SID_PREVIEW_SCALINGFACTOR
);
881 rBindings
.Invalidate(SID_ATTR_ZOOMSLIDER
);
884 IMPL_STATIC_LINK( ScPreview
, InvalidateHdl
, void*, EMPTYARG
)
886 (void)pThis
; // avoid warning
892 void ScPreview::DataChanged( const DataChangedEvent
& rDCEvt
)
894 Window::DataChanged(rDCEvt
);
896 if ( (rDCEvt
.GetType() == DATACHANGED_PRINTER
) ||
897 (rDCEvt
.GetType() == DATACHANGED_DISPLAY
) ||
898 (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
899 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
900 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
901 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
903 if ( rDCEvt
.GetType() == DATACHANGED_FONTS
)
904 pDocShell
->UpdateFontList();
906 // #i114518# Paint of form controls may modify the window's settings.
907 // Ignore the event if it is called from within Paint.
910 if ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
&&
911 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
913 // scroll bar size may have changed
914 pViewShell
->InvalidateBorder(); // calls OuterResizePixel
917 InvalidateLocationData( SC_HINT_DATACHANGED
);
922 void ScPreview::MouseButtonDown( const MouseEvent
& rMEvt
)
924 Fraction
aPreviewZoom( nZoom
, 100 );
925 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
926 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
928 aButtonDownChangePoint
= PixelToLogic( rMEvt
.GetPosPixel(),aMMMode
);
929 aButtonDownPt
= PixelToLogic( rMEvt
.GetPosPixel(),aMMMode
);
933 if( rMEvt
.IsLeft() && GetPointer() == POINTER_HSIZEBAR
)
935 SetMapMode( aMMMode
);
936 if( bLeftRulerChange
)
938 DrawInvert( aButtonDownChangePoint
.X(), POINTER_HSIZEBAR
);
939 bLeftRulerMove
= true;
940 bRightRulerMove
= false;
942 else if( bRightRulerChange
)
944 DrawInvert( aButtonDownChangePoint
.X(), POINTER_HSIZEBAR
);
945 bLeftRulerMove
= false;
946 bRightRulerMove
= true;
950 if( rMEvt
.IsLeft() && GetPointer() == POINTER_VSIZEBAR
)
952 SetMapMode( aMMMode
);
953 if( bTopRulerChange
)
955 DrawInvert( aButtonDownChangePoint
.Y(), POINTER_VSIZEBAR
);
956 bTopRulerMove
= true;
957 bBottomRulerMove
= false;
959 else if( bBottomRulerChange
)
961 DrawInvert( aButtonDownChangePoint
.Y(), POINTER_VSIZEBAR
);
962 bTopRulerMove
= false;
963 bBottomRulerMove
= true;
965 else if( bHeaderRulerChange
)
967 DrawInvert( aButtonDownChangePoint
.Y(), POINTER_VSIZEBAR
);
968 bHeaderRulerMove
= true;
969 bFooterRulerMove
= false;
971 else if( bFooterRulerChange
)
973 DrawInvert( aButtonDownChangePoint
.Y(), POINTER_VSIZEBAR
);
974 bHeaderRulerMove
= false;
975 bFooterRulerMove
= true;
979 if( rMEvt
.IsLeft() && GetPointer() == POINTER_HSPLIT
)
981 Point aNowPt
= rMEvt
.GetPosPixel();
983 for( i
= aPageArea
.aStart
.Col(); i
<= aPageArea
.aEnd
.Col(); i
++ )
985 if( aNowPt
.X() < nRight
[i
] + 2 && aNowPt
.X() > nRight
[i
] - 2 )
987 nColNumberButttonDown
= i
;
991 if( i
== aPageArea
.aEnd
.Col()+1 )
994 SetMapMode( aMMMode
);
995 if( nColNumberButttonDown
== aPageArea
.aStart
.Col() )
996 DrawInvert( PixelToLogic( Point( nLeftPosition
, 0 ),aMMMode
).X() ,POINTER_HSPLIT
);
998 DrawInvert( PixelToLogic( Point( nRight
[ nColNumberButttonDown
-1 ], 0 ),aMMMode
).X() ,POINTER_HSPLIT
);
1000 DrawInvert( aButtonDownChangePoint
.X(), POINTER_HSPLIT
);
1001 bColRulerMove
= true;
1005 void ScPreview::MouseButtonUp( const MouseEvent
& rMEvt
)
1007 Fraction
aPreviewZoom( nZoom
, 100 );
1008 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
1009 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
1011 aButtonUpPt
= PixelToLogic( rMEvt
.GetPosPixel(),aMMMode
);
1013 long nWidth
= (long) lcl_GetDocPageSize(pDocShell
->GetDocument(), nTab
).Width();
1014 long nHeight
= (long) lcl_GetDocPageSize(pDocShell
->GetDocument(), nTab
).Height();
1016 if( rMEvt
.IsLeft() && GetPointer() == POINTER_HSIZEBAR
)
1018 SetPointer( Pointer( POINTER_ARROW
) );
1020 bool bMoveRulerAction
= true;
1022 ScDocument
* pDoc
= pDocShell
->GetDocument();
1023 String aOldName
= pDoc
->GetPageStyle( nTab
);
1024 bool bUndo
= pDoc
->IsUndoEnabled();
1025 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
1026 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
1030 ScStyleSaveData aOldData
;
1032 aOldData
.InitFromStyle( pStyleSheet
);
1034 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
1036 SvxLRSpaceItem aLRItem
= ( const SvxLRSpaceItem
& ) rStyleSet
.Get( ATTR_LRSPACE
);
1038 if(( bLeftRulerChange
|| bRightRulerChange
) && ( aButtonUpPt
.X() <= ( 0 - aOffset
.X() ) || aButtonUpPt
.X() > nWidth
* HMM_PER_TWIPS
- aOffset
.X() ) )
1040 bMoveRulerAction
= false;
1041 Paint(Rectangle(0,0,10000,10000));
1043 else if( bLeftRulerChange
&& ( aButtonUpPt
.X() / HMM_PER_TWIPS
> nWidth
- aLRItem
.GetRight() - aOffset
.X() / HMM_PER_TWIPS
) )
1045 bMoveRulerAction
= false;
1046 Paint(Rectangle(0,0,10000,10000));
1048 else if( bRightRulerChange
&& ( aButtonUpPt
.X() / HMM_PER_TWIPS
< aLRItem
.GetLeft() - aOffset
.X() / HMM_PER_TWIPS
) )
1050 bMoveRulerAction
= false;
1051 Paint(Rectangle(0,0,10000,10000));
1053 else if( aButtonDownPt
.X() == aButtonUpPt
.X() )
1055 bMoveRulerAction
= false;
1056 DrawInvert( aButtonUpPt
.X(), POINTER_HSIZEBAR
);
1058 if( bMoveRulerAction
)
1060 ScDocShellModificator
aModificator( *pDocShell
);
1061 if( bLeftRulerChange
&& bLeftRulerMove
)
1063 aLRItem
.SetLeft( (long)( aButtonUpPt
.X() / HMM_PER_TWIPS
+ aOffset
.X() / HMM_PER_TWIPS
));
1064 rStyleSet
.Put( aLRItem
);
1065 pDocShell
->SetModified(true);
1067 else if( bRightRulerChange
&& bRightRulerMove
)
1069 aLRItem
.SetRight( (long)( nWidth
- aButtonUpPt
.X() / HMM_PER_TWIPS
- aOffset
.X() / HMM_PER_TWIPS
));
1070 rStyleSet
.Put( aLRItem
);
1071 pDocShell
->SetModified(true);
1074 ScStyleSaveData aNewData
;
1075 aNewData
.InitFromStyle( pStyleSheet
);
1078 pDocShell
->GetUndoManager()->AddUndoAction(
1079 new ScUndoModifyStyle( pDocShell
, SFX_STYLE_FAMILY_PAGE
,
1080 aOldData
, aNewData
) );
1083 if ( ValidTab( nTab
) )
1085 ScPrintFunc
aPrintFunc( this, pDocShell
, nTab
);
1086 aPrintFunc
.UpdatePages();
1089 Rectangle
aRect(0,0,10000,10000);
1091 aModificator
.SetDocumentModified();
1092 bLeftRulerChange
= false;
1093 bRightRulerChange
= false;
1096 bLeftRulerMove
= false;
1097 bRightRulerMove
= false;
1100 if( rMEvt
.IsLeft() && GetPointer() == POINTER_VSIZEBAR
)
1102 SetPointer( POINTER_ARROW
);
1104 bool bMoveRulerAction
= true;
1105 if( ( bTopRulerChange
|| bBottomRulerChange
|| bHeaderRulerChange
|| bFooterRulerChange
) && ( aButtonUpPt
.Y() <= ( 0 - aOffset
.Y() ) || aButtonUpPt
.Y() > nHeight
* HMM_PER_TWIPS
-aOffset
.Y() ) )
1107 bMoveRulerAction
= false;
1108 Paint( Rectangle(0,0,10000,10000) );
1110 else if( aButtonDownPt
.Y() == aButtonUpPt
.Y() )
1112 bMoveRulerAction
= false;
1113 DrawInvert( aButtonUpPt
.Y(), POINTER_VSIZEBAR
);
1115 if( bMoveRulerAction
)
1117 ScDocument
* pDoc
= pDocShell
->GetDocument();
1118 bool bUndo
= pDoc
->IsUndoEnabled();
1119 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
1120 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( pDoc
->GetPageStyle( nTab
), SFX_STYLE_FAMILY_PAGE
);
1121 OSL_ENSURE( pStyleSheet
, "PageStyle not found" );
1124 ScDocShellModificator
aModificator( *pDocShell
);
1125 ScStyleSaveData aOldData
;
1127 aOldData
.InitFromStyle( pStyleSheet
);
1129 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
1131 SvxULSpaceItem aULItem
= ( const SvxULSpaceItem
&)rStyleSet
.Get( ATTR_ULSPACE
);
1133 if( bTopRulerMove
&& bTopRulerChange
)
1135 aULItem
.SetUpperValue( (sal_uInt16
)( aButtonUpPt
.Y() / HMM_PER_TWIPS
+ aOffset
.Y() / HMM_PER_TWIPS
) );
1136 rStyleSet
.Put( aULItem
);
1137 pDocShell
->SetModified(true);
1139 else if( bBottomRulerMove
&& bBottomRulerChange
)
1141 aULItem
.SetLowerValue( (sal_uInt16
)( nHeight
- aButtonUpPt
.Y() / HMM_PER_TWIPS
- aOffset
.Y() / HMM_PER_TWIPS
) );
1142 rStyleSet
.Put( aULItem
);
1143 pDocShell
->SetModified(true);
1145 else if( bHeaderRulerMove
&& bHeaderRulerChange
)
1147 const SfxPoolItem
* pItem
= NULL
;
1148 if ( rStyleSet
.GetItemState( ATTR_PAGE_HEADERSET
, false, &pItem
) == SFX_ITEM_SET
)
1150 SfxItemSet
& pHeaderSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
1151 Size aHeaderSize
= ((const SvxSizeItem
&)pHeaderSet
.Get(ATTR_PAGE_SIZE
)).GetSize();
1152 aHeaderSize
.Height() = (long)( aButtonUpPt
.Y() / HMM_PER_TWIPS
+ aOffset
.Y() / HMM_PER_TWIPS
- aULItem
.GetUpper());
1153 aHeaderSize
.Height() = aHeaderSize
.Height() * 100 / mnScale
;
1154 SvxSetItem
aNewHeader( (const SvxSetItem
&)rStyleSet
.Get(ATTR_PAGE_HEADERSET
) );
1155 aNewHeader
.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE
, aHeaderSize
) );
1156 rStyleSet
.Put( aNewHeader
);
1157 pDocShell
->SetModified(true);
1160 else if( bFooterRulerMove
&& bFooterRulerChange
)
1162 const SfxPoolItem
* pItem
= NULL
;
1163 if( rStyleSet
.GetItemState( ATTR_PAGE_FOOTERSET
, false, &pItem
) == SFX_ITEM_SET
)
1165 SfxItemSet
& pFooterSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
1166 Size aFooterSize
= ((const SvxSizeItem
&)pFooterSet
.Get(ATTR_PAGE_SIZE
)).GetSize();
1167 aFooterSize
.Height() = (long)( nHeight
- aButtonUpPt
.Y() / HMM_PER_TWIPS
- aOffset
.Y() / HMM_PER_TWIPS
- aULItem
.GetLower() );
1168 aFooterSize
.Height() = aFooterSize
.Height() * 100 / mnScale
;
1169 SvxSetItem
aNewFooter( (const SvxSetItem
&)rStyleSet
.Get(ATTR_PAGE_FOOTERSET
) );
1170 aNewFooter
.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE
, aFooterSize
) );
1171 rStyleSet
.Put( aNewFooter
);
1172 pDocShell
->SetModified(true);
1176 ScStyleSaveData aNewData
;
1177 aNewData
.InitFromStyle( pStyleSheet
);
1180 pDocShell
->GetUndoManager()->AddUndoAction(
1181 new ScUndoModifyStyle( pDocShell
, SFX_STYLE_FAMILY_PAGE
,
1182 aOldData
, aNewData
) );
1185 if ( ValidTab( nTab
) )
1187 ScPrintFunc
aPrintFunc( this, pDocShell
, nTab
);
1188 aPrintFunc
.UpdatePages();
1191 Rectangle
aRect(0,0,10000,10000);
1193 aModificator
.SetDocumentModified();
1194 bTopRulerChange
= false;
1195 bBottomRulerChange
= false;
1196 bHeaderRulerChange
= false;
1197 bFooterRulerChange
= false;
1200 bTopRulerMove
= false;
1201 bBottomRulerMove
= false;
1202 bHeaderRulerMove
= false;
1203 bFooterRulerMove
= false;
1205 if( rMEvt
.IsLeft() && GetPointer() == POINTER_HSPLIT
)
1207 SetPointer(POINTER_ARROW
);
1208 ScDocument
* pDoc
= pDocShell
->GetDocument();
1209 bool bLayoutRTL
= pDoc
->IsLayoutRTL( nTab
);
1210 bool bMoveRulerAction
= true;
1211 if( aButtonDownPt
.X() == aButtonUpPt
.X() )
1213 bMoveRulerAction
= false;
1214 if( nColNumberButttonDown
== aPageArea
.aStart
.Col() )
1215 DrawInvert( PixelToLogic( Point( nLeftPosition
, 0 ),aMMMode
).X() ,POINTER_HSPLIT
);
1217 DrawInvert( PixelToLogic( Point( nRight
[ nColNumberButttonDown
-1 ], 0 ),aMMMode
).X() ,POINTER_HSPLIT
);
1218 DrawInvert( aButtonUpPt
.X(), POINTER_HSPLIT
);
1220 if( bMoveRulerAction
)
1222 long nNewColWidth
= 0;
1223 SCCOLROW nCols
[2] = { nColNumberButttonDown
, nColNumberButttonDown
};
1227 nNewColWidth
= (long) ( PixelToLogic( Point( rMEvt
.GetPosPixel().X() - nRight
[ nColNumberButttonDown
], 0), aMMMode
).X() / HMM_PER_TWIPS
) * 100 / mnScale
;
1228 nNewColWidth
+= pDocShell
->GetDocument()->GetColWidth( nColNumberButttonDown
, nTab
);
1233 nNewColWidth
= (long) ( PixelToLogic( Point( nRight
[ nColNumberButttonDown
] - rMEvt
.GetPosPixel().X(), 0), aMMMode
).X() / HMM_PER_TWIPS
) * 100 / mnScale
;
1234 nNewColWidth
+= pDocShell
->GetDocument()->GetColWidth( nColNumberButttonDown
, nTab
);
1237 if( nNewColWidth
>= 0 )
1239 pDocShell
->GetDocFunc().SetWidthOrHeight(
1240 true, 1,nCols
, nTab
, SC_SIZE_DIRECT
,
1241 (sal_uInt16
)nNewColWidth
, true, true);
1242 pDocShell
->SetModified(true);
1244 if ( ValidTab( nTab
) )
1246 ScPrintFunc
aPrintFunc( this, pDocShell
, nTab
);
1247 aPrintFunc
.UpdatePages();
1249 Rectangle
nRect(0,0,10000,10000);
1252 bColRulerMove
= false;
1257 void ScPreview::MouseMove( const MouseEvent
& rMEvt
)
1259 Fraction
aPreviewZoom( nZoom
, 100 );
1260 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
1261 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
1262 Point aMouseMovePoint
= PixelToLogic( rMEvt
.GetPosPixel(), aMMMode
);
1264 long nLeftMargin
= 0;
1265 long nRightMargin
= 0;
1266 long nTopMargin
= 0;
1267 long nBottomMargin
= 0;
1270 long nWidth
= (long) lcl_GetDocPageSize(pDocShell
->GetDocument(), nTab
).Width();
1271 long nHeight
= (long) lcl_GetDocPageSize(pDocShell
->GetDocument(), nTab
).Height();
1273 if ( nPageNo
< nTotalPages
)
1275 ScPrintOptions aOptions
= SC_MOD()->GetPrintOptions();
1277 ScPrintFunc
* pPrintFunc
;
1280 pPrintFunc
= new ScPrintFunc( this, pDocShell
, aState
, &aOptions
);
1282 pPrintFunc
= new ScPrintFunc( this, pDocShell
, nTab
, nFirstAttr
[nTab
], nTotalPages
, NULL
, &aOptions
);
1284 nLeftMargin
= (long)( pPrintFunc
->GetLeftMargin() * HMM_PER_TWIPS
- aOffset
.X() );
1285 nRightMargin
= (long)( pPrintFunc
->GetRightMargin() * HMM_PER_TWIPS
);
1286 nRightMargin
= (long)( nWidth
* HMM_PER_TWIPS
- nRightMargin
- aOffset
.X() );
1287 nTopMargin
= (long)( pPrintFunc
->GetTopMargin() * HMM_PER_TWIPS
- aOffset
.Y() );
1288 nBottomMargin
= (long)( pPrintFunc
->GetBottomMargin() * HMM_PER_TWIPS
);
1289 nBottomMargin
= (long)( nHeight
* HMM_PER_TWIPS
- nBottomMargin
- aOffset
.Y() );
1292 nHeaderHeight
= (long)( nTopMargin
+ pPrintFunc
->GetHeader().nHeight
* HMM_PER_TWIPS
* mnScale
/ 100 );
1293 nFooterHeight
= (long)( nBottomMargin
- pPrintFunc
->GetFooter().nHeight
* HMM_PER_TWIPS
* mnScale
/ 100 );
1297 nHeaderHeight
= (long)( nTopMargin
+ pPrintFunc
->GetHeader().nHeight
* HMM_PER_TWIPS
);
1298 nFooterHeight
= (long)( nBottomMargin
- pPrintFunc
->GetFooter().nHeight
* HMM_PER_TWIPS
);
1303 Point
aPixPt( rMEvt
.GetPosPixel() );
1304 Point aLeftTop
= LogicToPixel( Point( nLeftMargin
, -aOffset
.Y() ) , aMMMode
);
1305 Point aLeftBottom
= LogicToPixel( Point( nLeftMargin
,(long)(nHeight
* HMM_PER_TWIPS
- aOffset
.Y()) ), aMMMode
);
1306 Point aRightTop
= LogicToPixel( Point( nRightMargin
, -aOffset
.Y() ), aMMMode
);
1307 Point aTopLeft
= LogicToPixel( Point( -aOffset
.X(), nTopMargin
), aMMMode
);
1308 Point aTopRight
= LogicToPixel( Point( (long)(nWidth
* HMM_PER_TWIPS
- aOffset
.X()), nTopMargin
), aMMMode
);
1309 Point aBottomLeft
= LogicToPixel( Point( -aOffset
.X(), nBottomMargin
), aMMMode
);
1310 Point aHeaderLeft
= LogicToPixel( Point( -aOffset
.X(), nHeaderHeight
), aMMMode
);
1311 Point aFooderLeft
= LogicToPixel( Point( -aOffset
.X(), nFooterHeight
), aMMMode
);
1313 bool bOnColRulerChange
= false;
1315 for( SCCOL i
=aPageArea
.aStart
.Col(); i
<= aPageArea
.aEnd
.Col(); i
++ )
1317 Point aColumnTop
= LogicToPixel( Point( 0, -aOffset
.Y() ) ,aMMMode
);
1318 Point aColumnBottom
= LogicToPixel( Point( 0, (long)( nHeight
* HMM_PER_TWIPS
- aOffset
.Y()) ), aMMMode
);
1319 if( aPixPt
.X() < ( nRight
[i
] + 2 ) && ( aPixPt
.X() > ( nRight
[i
] - 2 ) ) && ( aPixPt
.X() < aRightTop
.X() ) && ( aPixPt
.X() > aLeftTop
.X() )
1320 && ( aPixPt
.Y() > aColumnTop
.Y() ) && ( aPixPt
.Y() < aColumnBottom
.Y() ) && !bLeftRulerMove
&& !bRightRulerMove
1321 && !bTopRulerMove
&& !bBottomRulerMove
&& !bHeaderRulerMove
&& !bFooterRulerMove
)
1323 bOnColRulerChange
= true;
1324 if( !rMEvt
.GetButtons() && GetPointer() == POINTER_HSPLIT
)
1325 nColNumberButttonDown
= i
;
1330 if( aPixPt
.X() < ( aLeftTop
.X() + 2 ) && aPixPt
.X() > ( aLeftTop
.X() - 2 ) && !bRightRulerMove
)
1332 bLeftRulerChange
= true;
1333 bRightRulerChange
= false;
1335 else if( aPixPt
.X() < ( aRightTop
.X() + 2 ) && aPixPt
.X() > ( aRightTop
.X() - 2 ) && !bLeftRulerMove
)
1337 bLeftRulerChange
= false;
1338 bRightRulerChange
= true;
1340 else if( aPixPt
.Y() < ( aTopLeft
.Y() + 2 ) && aPixPt
.Y() > ( aTopLeft
.Y() - 2 ) && !bBottomRulerMove
&& !bHeaderRulerMove
&& !bFooterRulerMove
)
1342 bTopRulerChange
= true;
1343 bBottomRulerChange
= false;
1344 bHeaderRulerChange
= false;
1345 bFooterRulerChange
= false;
1347 else if( aPixPt
.Y() < ( aBottomLeft
.Y() + 2 ) && aPixPt
.Y() > ( aBottomLeft
.Y() - 2 ) && !bTopRulerMove
&& !bHeaderRulerMove
&& !bFooterRulerMove
)
1349 bTopRulerChange
= false;
1350 bBottomRulerChange
= true;
1351 bHeaderRulerChange
= false;
1352 bFooterRulerChange
= false;
1354 else if( aPixPt
.Y() < ( aHeaderLeft
.Y() + 2 ) && aPixPt
.Y() > ( aHeaderLeft
.Y() - 2 ) && !bTopRulerMove
&& !bBottomRulerMove
&& !bFooterRulerMove
)
1356 bTopRulerChange
= false;
1357 bBottomRulerChange
= false;
1358 bHeaderRulerChange
= true;
1359 bFooterRulerChange
= false;
1361 else if( aPixPt
.Y() < ( aFooderLeft
.Y() + 2 ) && aPixPt
.Y() > ( aFooderLeft
.Y() - 2 ) && !bTopRulerMove
&& !bBottomRulerMove
&& !bHeaderRulerMove
)
1363 bTopRulerChange
= false;
1364 bBottomRulerChange
= false;
1365 bHeaderRulerChange
= false;
1366 bFooterRulerChange
= true;
1371 if(( (aPixPt
.X() < ( aLeftTop
.X() + 2 ) && aPixPt
.X() > ( aLeftTop
.X() - 2 )) || bLeftRulerMove
||
1372 ( aPixPt
.X() < ( aRightTop
.X() + 2 ) && aPixPt
.X() > ( aRightTop
.X() - 2 ) ) || bRightRulerMove
|| bOnColRulerChange
|| bColRulerMove
)
1373 && aPixPt
.Y() > aLeftTop
.Y() && aPixPt
.Y() < aLeftBottom
.Y() )
1375 if( bOnColRulerChange
|| bColRulerMove
)
1377 SetPointer( Pointer( POINTER_HSPLIT
) );
1380 if( aMouseMovePoint
.X() > -aOffset
.X() && aMouseMovePoint
.X() < nWidth
* HMM_PER_TWIPS
- aOffset
.X() )
1381 DragMove( aMouseMovePoint
.X(), POINTER_HSPLIT
);
1386 if( bLeftRulerChange
&& !bTopRulerMove
&& !bBottomRulerMove
&& !bHeaderRulerMove
&& !bFooterRulerMove
)
1388 SetPointer( Pointer( POINTER_HSIZEBAR
) );
1389 if( bLeftRulerMove
)
1391 if( aMouseMovePoint
.X() > -aOffset
.X() && aMouseMovePoint
.X() < nWidth
* HMM_PER_TWIPS
- aOffset
.X() )
1392 DragMove( aMouseMovePoint
.X(), POINTER_HSIZEBAR
);
1395 else if( bRightRulerChange
&& !bTopRulerMove
&& !bBottomRulerMove
&& !bHeaderRulerMove
&& !bFooterRulerMove
)
1397 SetPointer( Pointer( POINTER_HSIZEBAR
) );
1398 if( bRightRulerMove
)
1400 if( aMouseMovePoint
.X() > -aOffset
.X() && aMouseMovePoint
.X() < nWidth
* HMM_PER_TWIPS
- aOffset
.X() )
1401 DragMove( aMouseMovePoint
.X(), POINTER_HSIZEBAR
);
1408 if( ( ( aPixPt
.Y() < ( aTopLeft
.Y() + 2 ) && aPixPt
.Y() > ( aTopLeft
.Y() - 2 ) ) || bTopRulerMove
||
1409 ( aPixPt
.Y() < ( aBottomLeft
.Y() + 2 ) && aPixPt
.Y() > ( aBottomLeft
.Y() - 2 ) ) || bBottomRulerMove
||
1410 ( aPixPt
.Y() < ( aHeaderLeft
.Y() + 2 ) && aPixPt
.Y() > ( aHeaderLeft
.Y() - 2 ) ) || bHeaderRulerMove
||
1411 ( aPixPt
.Y() < ( aFooderLeft
.Y() + 2 ) && aPixPt
.Y() > ( aFooderLeft
.Y() - 2 ) ) || bFooterRulerMove
)
1412 && aPixPt
.X() > aTopLeft
.X() && aPixPt
.X() < aTopRight
.X() )
1414 if( bTopRulerChange
)
1416 SetPointer( Pointer( POINTER_VSIZEBAR
) );
1419 if( aMouseMovePoint
.Y() > -aOffset
.Y() && aMouseMovePoint
.Y() < nHeight
* HMM_PER_TWIPS
- aOffset
.Y() )
1420 DragMove( aMouseMovePoint
.Y(), POINTER_VSIZEBAR
);
1423 else if( bBottomRulerChange
)
1425 SetPointer( Pointer( POINTER_VSIZEBAR
) );
1426 if( bBottomRulerMove
)
1428 if( aMouseMovePoint
.Y() > -aOffset
.Y() && aMouseMovePoint
.Y() < nHeight
* HMM_PER_TWIPS
- aOffset
.Y() )
1429 DragMove( aMouseMovePoint
.Y(), POINTER_VSIZEBAR
);
1432 else if( bHeaderRulerChange
)
1434 SetPointer( Pointer( POINTER_VSIZEBAR
) );
1435 if( bHeaderRulerMove
)
1437 if( aMouseMovePoint
.Y() > -aOffset
.Y() && aMouseMovePoint
.Y() < nHeight
* HMM_PER_TWIPS
- aOffset
.Y() )
1438 DragMove( aMouseMovePoint
.Y(), POINTER_VSIZEBAR
);
1441 else if( bFooterRulerChange
)
1443 SetPointer( Pointer( POINTER_VSIZEBAR
) );
1444 if( bFooterRulerMove
)
1446 if( aMouseMovePoint
.Y() > -aOffset
.Y() && aMouseMovePoint
.Y() < nHeight
* HMM_PER_TWIPS
- aOffset
.Y() )
1447 DragMove( aMouseMovePoint
.Y(), POINTER_VSIZEBAR
);
1452 SetPointer( Pointer( POINTER_ARROW
) );
1457 void ScPreview::InvalidateLocationData(sal_uLong nId
)
1459 bLocationValid
= false;
1460 if (pViewShell
->HasAccessibilityObjects())
1461 pViewShell
->BroadcastAccessibility( SfxSimpleHint( nId
) );
1464 void ScPreview::GetFocus()
1466 if (pViewShell
->HasAccessibilityObjects())
1467 pViewShell
->BroadcastAccessibility( ScAccWinFocusGotHint(GetAccessible()) );
1470 void ScPreview::LoseFocus()
1472 if (pViewShell
->HasAccessibilityObjects())
1473 pViewShell
->BroadcastAccessibility( ScAccWinFocusLostHint(GetAccessible()) );
1476 com::sun::star::uno::Reference
<com::sun::star::accessibility::XAccessible
> ScPreview::CreateAccessible()
1478 ScAccessibleDocumentPagePreview
* pAccessible
=
1479 new ScAccessibleDocumentPagePreview( GetAccessibleParentWindow()->GetAccessible(), pViewShell
);
1480 com::sun::star::uno::Reference
< com::sun::star::accessibility::XAccessible
> xAccessible
= pAccessible
;
1481 pAccessible
->Init();
1485 void ScPreview::DragMove( long nDragMovePos
, sal_uInt16 nFlags
)
1487 Fraction
aPreviewZoom( nZoom
, 100 );
1488 Fraction
aHorPrevZoom( (long)( 100 * nZoom
/ pDocShell
->GetOutputFactor() ), 10000 );
1489 MapMode
aMMMode( MAP_100TH_MM
, Point(), aHorPrevZoom
, aPreviewZoom
);
1490 SetMapMode( aMMMode
);
1491 long nPos
= nDragMovePos
;
1492 if( nFlags
== POINTER_HSIZEBAR
|| nFlags
== POINTER_HSPLIT
)
1494 if( nDragMovePos
!= aButtonDownChangePoint
.X() )
1496 DrawInvert( aButtonDownChangePoint
.X(), nFlags
);
1497 aButtonDownChangePoint
.X() = nPos
;
1498 DrawInvert( aButtonDownChangePoint
.X(), nFlags
);
1501 else if( nFlags
== POINTER_VSIZEBAR
)
1503 if( nDragMovePos
!= aButtonDownChangePoint
.Y() )
1505 DrawInvert( aButtonDownChangePoint
.Y(), nFlags
);
1506 aButtonDownChangePoint
.Y() = nPos
;
1507 DrawInvert( aButtonDownChangePoint
.Y(), nFlags
);
1512 void ScPreview::DrawInvert( long nDragPos
, sal_uInt16 nFlags
)
1514 long nHeight
= (long) lcl_GetDocPageSize( pDocShell
->GetDocument(), nTab
).Height();
1515 long nWidth
= (long) lcl_GetDocPageSize( pDocShell
->GetDocument(), nTab
).Width();
1516 if( nFlags
== POINTER_HSIZEBAR
|| nFlags
== POINTER_HSPLIT
)
1518 Rectangle
aRect( nDragPos
, -aOffset
.Y(), nDragPos
+ 1,(long)( ( nHeight
* HMM_PER_TWIPS
) - aOffset
.Y()));
1519 Invert( aRect
,INVERT_50
);
1521 else if( nFlags
== POINTER_VSIZEBAR
)
1523 Rectangle
aRect( -aOffset
.X(), nDragPos
,(long)( ( nWidth
* HMM_PER_TWIPS
) - aOffset
.X() ), nDragPos
+ 1 );
1524 Invert( aRect
,INVERT_50
);
1528 void ScPreview::SetSelectedTabs(const ScMarkData
& rMark
)
1530 maSelectedTabs
= rMark
.GetSelectedTabs();
1533 const ScMarkData::MarkedTabsType
& ScPreview::GetSelectedTabs() const
1535 return maSelectedTabs
;
1538 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */