merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / preview.cxx
blob0756c8f27647a4b66ccf5fea465acd8a34a68b94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: preview.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include <tools/pstm.hxx>
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
42 #include <svtools/colorcfg.hxx>
43 #include <svx/fmview.hxx>
44 #include <svx/sizeitem.hxx>
45 #include <svx/svdpagv.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <svtools/accessibilityoptions.hxx>
50 #include <svtools/itemset.hxx>
51 #include <tools/multisel.hxx>
52 #include <vcl/waitobj.hxx>
53 #include <vcl/sound.hxx>
55 #include "preview.hxx"
56 #include "prevwsh.hxx"
57 #include "prevloc.hxx"
58 #include "docsh.hxx"
59 #include "docfunc.hxx"
60 #include "printfun.hxx"
61 #include "printopt.hxx"
62 #include "stlpool.hxx"
63 #include "undostyl.hxx"
64 #include "drwlayer.hxx"
65 #include "scmod.hxx"
66 #include "globstr.hrc"
67 #include "sc.hrc" // fuer ShellInvalidate
68 #include "AccessibleDocumentPagePreview.hxx"
69 #include <vcl/lineinfo.hxx>
70 #include <svx/algitem.hxx>
71 #include <svx/lrspitem.hxx>
72 #include <svx/ulspitem.hxx>
73 #include <svx/sizeitem.hxx>
74 #include "attrib.hxx"
75 #include "pagepar.hxx"
76 #include <com/sun/star/accessibility/XAccessible.hpp>
77 #include "AccessibilityHints.hxx"
78 #include <vcl/svapp.hxx>
79 #include "viewutil.hxx"
81 // STATIC DATA -----------------------------------------------------------
83 //==================================================================
85 #define SC_PREVIEW_SHADOWSIZE 2
87 long lcl_GetDisplayStart( SCTAB nTab, ScDocument* pDoc, long* pPages )
89 long nDisplayStart = 0;
90 for (SCTAB i=0; i<nTab; i++)
92 if ( pDoc->NeedPageResetAfterTab(i) )
93 nDisplayStart = 0;
94 else
95 nDisplayStart += pPages[i];
97 return nDisplayStart;
101 ScPreview::ScPreview( Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pViewSh ) :
102 Window( pParent ),
103 nPageNo( 0 ),
104 nZoom( 100 ),
105 bValid( FALSE ),
106 nTabsTested( 0 ),
107 nTab( 0 ),
108 nTabStart( 0 ),
109 nDisplayStart( 0 ),
110 nTotalPages( 0 ),
111 bStateValid( FALSE ),
112 bLocationValid( FALSE ),
113 pLocationData( NULL ),
114 pDrawView( NULL ),
115 nCurTab ( ScDocShell::GetCurTab() ),
116 bInPaint( FALSE ),
117 bInGetState( FALSE ),
118 pDocShell( pDocSh ),
119 pViewShell( pViewSh ),
120 bLeftRulerMove( FALSE ),
121 bRightRulerMove( FALSE ),
122 bTopRulerMove( FALSE ),
123 bBottomRulerMove( FALSE ),
124 bHeaderRulerMove( FALSE ),
125 bFooterRulerMove( FALSE ),
126 bLeftRulerChange( FALSE ),
127 bRightRulerChange( FALSE ),
128 bTopRulerChange( FALSE ),
129 bBottomRulerChange( FALSE ),
130 bHeaderRulerChange( FALSE ),
131 bFooterRulerChange( FALSE ),
132 bPageMargin ( FALSE ),
133 bColRulerMove( FALSE ),
134 mnScale( 0 ),
135 nColNumberButttonDown( 0 ),
136 nHeaderHeight ( 0 ),
137 nFooterHeight ( 0 )
139 SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW ); //#106611#
140 SetBackground();
142 SetHelpId( HID_SC_WIN_PREVIEW );
143 SetUniqueId( HID_SC_WIN_PREVIEW );
145 SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
149 __EXPORT ScPreview::~ScPreview()
151 delete pDrawView;
152 delete pLocationData;
155 void ScPreview::UpdateDrawView() // nTab muss richtig sein
157 ScDocument* pDoc = pDocShell->GetDocument();
158 ScDrawLayer* pModel = pDoc->GetDrawLayer(); // ist nicht 0
160 // #114135#
161 if ( pModel )
163 SdrPage* pPage = pModel->GetPage(nTab);
164 if ( pDrawView && ( !pDrawView->GetSdrPageView() || pDrawView->GetSdrPageView()->GetPage() != pPage ) )
166 // die angezeigte Page der DrawView umzustellen (s.u.) funktioniert nicht ?!?
167 delete pDrawView;
168 pDrawView = NULL;
171 if ( !pDrawView ) // neu anlegen?
173 pDrawView = new FmFormView( pModel, this );
174 // #55259# die DrawView uebernimmt den Design-Modus vom Model
175 // (Einstellung "Im Entwurfsmodus oeffnen"), darum hier zuruecksetzen
176 pDrawView->SetDesignMode( TRUE );
177 pDrawView->SetPrintPreview( TRUE );
178 pDrawView->ShowSdrPage(pPage);
180 #if 0
181 else if ( !pDrawView->GetSdrPageView()) // angezeigte Page umstellen
183 pDrawView->HideSdrPage();
184 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
186 #endif
188 else if ( pDrawView )
190 delete pDrawView; // fuer diese Tabelle nicht gebraucht
191 pDrawView = NULL;
196 void ScPreview::TestLastPage()
198 if (nPageNo >= nTotalPages)
200 if (nTotalPages)
202 nPageNo = nTotalPages - 1;
203 nTab = nTabCount - 1;
204 while (nTab > 0 && !nPages[nTab]) // letzte nicht leere Tabelle
205 --nTab;
206 DBG_ASSERT(nPages[nTab],"alle Tabellen leer?");
207 nTabPage = nPages[nTab] - 1;
208 nTabStart = 0;
209 for (USHORT i=0; i<nTab; i++)
210 nTabStart += nPages[i];
212 ScDocument* pDoc = pDocShell->GetDocument();
213 nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
215 else // leeres Dokument
217 nTab = 0;
218 nPageNo = nTabPage = nTabStart = nDisplayStart = 0;
219 aState.nPrintTab = 0;
220 aState.nStartCol = aState.nEndCol = 0;
221 aState.nStartRow = aState.nEndRow = 0;
222 aState.nZoom = 0;
223 aState.nPagesX = aState.nPagesY = 0;
224 aState.nTabPages = aState.nTotalPages =
225 aState.nPageStart = aState.nDocPages = 0;
231 void ScPreview::CalcPages( SCTAB /*nToWhichTab*/ )
233 WaitObject( this );
235 ScDocument* pDoc = pDocShell->GetDocument();
236 nTabCount = pDoc->GetTableCount();
238 //SCTAB nAnz = Min( nTabCount, SCTAB(nToWhichTab+1) );
239 SCTAB nAnz = nTabCount;
240 SCTAB nStart = nTabsTested;
241 if (!bValid)
243 nStart = 0;
244 nTotalPages = 0;
245 nTabsTested = 0;
248 // update all pending row heights with a single progress bar,
249 // instead of a separate progress for each sheet from ScPrintFunc
250 pDocShell->UpdatePendingRowHeights( nAnz-1, true );
252 // PrintOptions is passed to PrintFunc for SkipEmpty flag,
253 // but always all sheets are used (there is no selected sheet)
254 ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
256 ScMarkData aMarkData;
257 aMarkData.SelectTable( nCurTab, TRUE );
259 for (SCTAB i=nStart; i<nAnz; i++)
261 if (!aOptions.GetAllSheets() && !aMarkData.GetTableSelect( i )) {
262 nPages[i] = 0;
263 nFirstAttr[i] = 0;
264 continue;
267 long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;
269 long nThisStart = nTotalPages;
270 ScPrintFunc aPrintFunc( this, pDocShell, i, nAttrPage, 0, NULL, &aOptions );
271 long nThisTab = aPrintFunc.GetTotalPages();
272 nPages[i] = nThisTab;
273 nTotalPages += nThisTab;
274 nFirstAttr[i] = aPrintFunc.GetFirstPageNo(); // behalten oder aus Vorlage
276 if (nPageNo>=nThisStart && nPageNo<nTotalPages)
278 nTab = i;
279 nTabPage = nPageNo - nThisStart;
280 nTabStart = nThisStart;
282 aPrintFunc.GetPrintState( aState );
283 aPageSize = aPrintFunc.GetPageSize();
287 nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
289 if (nAnz > nTabsTested)
290 nTabsTested = nAnz;
292 // testen, ob hinter letzter Seite
294 if ( nTabsTested >= nTabCount )
295 TestLastPage();
297 aState.nDocPages = nTotalPages;
299 bValid = TRUE;
300 bStateValid = TRUE;
301 DoInvalidate();
305 void ScPreview::RecalcPages() // nur nPageNo geaendert
307 if (!bValid)
308 return; // dann wird CalcPages aufgerufen
310 SCTAB nOldTab = nTab;
312 BOOL bDone = FALSE;
313 while (nPageNo >= nTotalPages && nTabsTested < nTabCount)
315 CalcPages( nTabsTested );
316 bDone = TRUE;
319 if (!bDone)
321 long nPartPages = 0;
322 for (SCTAB i=0; i<nTabsTested; i++)
324 long nThisStart = nPartPages;
325 nPartPages += nPages[i];
327 if (nPageNo>=nThisStart && nPageNo<nPartPages)
329 nTab = i;
330 nTabPage = nPageNo - nThisStart;
331 nTabStart = nThisStart;
333 // aPageSize = aPrintFunc.GetPageSize();
337 ScDocument* pDoc = pDocShell->GetDocument();
338 nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
341 TestLastPage(); // testen, ob hinter letzter Seite
343 if ( nTab != nOldTab )
344 bStateValid = FALSE;
346 DoInvalidate();
350 void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
352 if (!bValid)
354 CalcPages(0);
355 RecalcPages();
356 UpdateDrawView(); // Tabelle evtl. geaendert
359 Fraction aPreviewZoom( nZoom, 100 );
360 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
361 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
363 BOOL bDoPrint = ( pFillLocation == NULL );
364 BOOL bValidPage = ( nPageNo < nTotalPages );
366 ScModule* pScMod = SC_MOD();
367 const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
368 Color aBackColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
370 if ( bDoPrint && ( aOffset.X() < 0 || aOffset.Y() < 0 ) && bValidPage )
372 SetMapMode( aMMMode );
373 SetLineColor();
374 SetFillColor(aBackColor);
376 Size aWinSize = GetOutputSize();
377 if ( aOffset.X() < 0 )
378 DrawRect(Rectangle( 0, 0, -aOffset.X(), aWinSize.Height() ));
379 if ( aOffset.Y() < 0 )
380 DrawRect(Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
383 Size aLocalPageSize;
384 if ( bValidPage )
386 ScPrintOptions aOptions = pScMod->GetPrintOptions();
388 ScPrintFunc* pPrintFunc;
389 if (bStateValid)
390 pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
391 else
392 pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
394 pPrintFunc->SetOffset(aOffset);
395 pPrintFunc->SetManualZoom(nZoom);
396 pPrintFunc->SetDateTime(aDate,aTime);
397 pPrintFunc->SetClearFlag(TRUE);
398 pPrintFunc->SetUseStyleColor( pScMod->GetAccessOptions().GetIsForPagePreviews() );
400 pPrintFunc->SetDrawView( pDrawView );
402 // MultiSelection fuer die eine Seite muss etwas umstaendlich erzeugt werden...
403 Range aPageRange( nPageNo+1, nPageNo+1 );
404 MultiSelection aPage( aPageRange );
405 aPage.SetTotalRange( Range(0,RANGE_MAX) );
406 aPage.Select( aPageRange );
408 long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, NULL, pFillLocation );
409 DBG_ASSERT(nPrinted<=1, "was'n nu los?");
411 SetMapMode(aMMMode);
412 // USHORT nPrintZoom = pPrintFunc->GetZoom();
414 if (nPrinted) // wenn nichts, alles grau zeichnen
416 aLocalPageSize = pPrintFunc->GetPageSize();
417 aLocalPageSize.Width() = (long) (aLocalPageSize.Width() * HMM_PER_TWIPS );
418 aLocalPageSize.Height() = (long) (aLocalPageSize.Height() * HMM_PER_TWIPS );
421 if (!bStateValid)
423 pPrintFunc->GetPrintState( aState );
424 aState.nDocPages = nTotalPages;
425 bStateValid = TRUE;
427 delete pPrintFunc;
430 if ( bDoPrint )
432 long nPageEndX = aLocalPageSize.Width() - aOffset.X();
433 long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
434 if ( !bValidPage )
435 nPageEndX = nPageEndY = 0;
437 Size aWinSize = GetOutputSize();
438 Point aWinEnd( aWinSize.Width(), aWinSize.Height() );
439 BOOL bRight = nPageEndX <= aWinEnd.X();
440 BOOL bBottom = nPageEndY <= aWinEnd.Y();
441 if (bRight || bBottom)
443 SetLineColor();
444 SetFillColor(aBackColor);
445 if (bRight)
446 DrawRect(Rectangle(nPageEndX,0, aWinEnd.X(),aWinEnd.Y()));
447 if (bBottom)
449 if (bRight)
450 DrawRect(Rectangle(0,nPageEndY, nPageEndX,aWinEnd.Y())); // Ecke nicht doppelt
451 else
452 DrawRect(Rectangle(0,nPageEndY, aWinEnd.X(),aWinEnd.Y()));
456 if ( bValidPage )
458 Color aBorderColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
460 // draw border
462 if ( aOffset.X() <= 0 || aOffset.Y() <= 0 || bRight || bBottom )
464 SetLineColor( aBorderColor );
465 SetFillColor();
467 Rectangle aPixel( LogicToPixel( Rectangle( -aOffset.X(), -aOffset.Y(), nPageEndX, nPageEndY ) ) );
468 --aPixel.Right();
469 --aPixel.Bottom();
470 DrawRect( PixelToLogic( aPixel ) );
473 // draw shadow
475 SetLineColor();
476 SetFillColor( aBorderColor );
478 Rectangle aPixel;
480 aPixel = LogicToPixel( Rectangle( nPageEndX, -aOffset.Y(), nPageEndX, nPageEndY ) );
481 aPixel.Top() += SC_PREVIEW_SHADOWSIZE;
482 aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
483 aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
484 DrawRect( PixelToLogic( aPixel ) );
486 aPixel = LogicToPixel( Rectangle( -aOffset.X(), nPageEndY, nPageEndX, nPageEndY ) );
487 aPixel.Left() += SC_PREVIEW_SHADOWSIZE;
488 aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
489 aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
490 DrawRect( PixelToLogic( aPixel ) );
495 //Issue51656 Add resizeable margin on page preview from maoyg
496 void __EXPORT ScPreview::Paint( const Rectangle& /* rRect */ )
498 if (!bValid)
500 CalcPages(0);
501 RecalcPages();
502 UpdateDrawView(); // Table possibly amended
505 Fraction aPreviewZoom( nZoom, 100 );
506 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
507 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
509 ScModule* pScMod = SC_MOD();
510 const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
511 Color aBackColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
513 if ( aOffset.X() < 0 || aOffset.Y() < 0 )
515 SetMapMode( aMMMode );
516 SetLineColor();
517 SetFillColor(aBackColor);
519 Size aWinSize = GetOutputSize();
520 if ( aOffset.X() < 0 )
521 DrawRect(Rectangle( 0, 0, -aOffset.X(), aWinSize.Height() ));
522 if ( aOffset.Y() < 0 )
523 DrawRect(Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
526 long nLeftMargin = 0;
527 long nRightMargin = 0;
528 long nTopMargin = 0;
529 long nBottomMargin = 0;
530 BOOL bHeaderOn = FALSE;
531 BOOL bFooterOn = FALSE;
533 ScDocument* pDoc = pDocShell->GetDocument();
534 BOOL bLayoutRTL = pDoc->IsLayoutRTL( nTab );
536 Size aPaintPageSize;
537 if ( nPageNo < nTotalPages )
539 ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
541 ScPrintFunc* pPrintFunc;
542 if ( bStateValid )
543 pPrintFunc = new ScPrintFunc( pDocShell, this, aState, &aOptions );
544 else
545 pPrintFunc = new ScPrintFunc( pDocShell, this, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
547 pPrintFunc->SetOffset(aOffset);
548 pPrintFunc->SetManualZoom(nZoom);
549 pPrintFunc->SetDateTime(aDate,aTime);
550 pPrintFunc->SetClearFlag(TRUE);
551 pPrintFunc->SetUseStyleColor( pScMod->GetAccessOptions().GetIsForPagePreviews() );
552 pPrintFunc->SetDrawView( pDrawView );
554 // Multi Selection for one side must be something umstaendlich generated ...
555 Range aPageRange( nPageNo+1, nPageNo+1 );
556 MultiSelection aPage( aPageRange );
557 aPage.SetTotalRange( Range(0,RANGE_MAX) );
558 aPage.Select( aPageRange );
560 long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart );
561 DBG_ASSERT(nPrinted<=1, "was'n nu los?");
563 SetMapMode(aMMMode);
565 //init nLeftMargin ... in the ScPrintFunc::InitParam!!!
566 nLeftMargin = pPrintFunc->GetLeftMargin();
567 nRightMargin = pPrintFunc->GetRightMargin();
568 nTopMargin = pPrintFunc->GetTopMargin();
569 nBottomMargin = pPrintFunc->GetBottomMargin();
570 nHeaderHeight = pPrintFunc->GetHeader().nHeight;
571 nFooterHeight = pPrintFunc->GetFooter().nHeight;
572 bHeaderOn = pPrintFunc->GetHeader().bEnable;
573 bFooterOn = pPrintFunc->GetFooter().bEnable;
574 mnScale = pPrintFunc->GetZoom();
576 Rectangle aPixRect;
577 Rectangle aRectCellPosition;
578 Rectangle aRectPosition;
579 GetLocationData().GetMainCellRange( aPageArea, aPixRect );
580 if( !bLayoutRTL )
582 GetLocationData().GetCellPosition( aPageArea.aStart, aRectPosition );
583 nLeftPosition = aRectPosition.Left();
584 for( SCCOL i = aPageArea.aStart.Col(); i <= aPageArea.aEnd.Col(); i++ )
586 GetLocationData().GetCellPosition( ScAddress( i,aPageArea.aStart.Row(),aPageArea.aStart.Tab()),aRectCellPosition );
587 nRight[i] = aRectCellPosition.Right();
590 else
592 GetLocationData().GetCellPosition( aPageArea.aEnd, aRectPosition );
593 nLeftPosition = aRectPosition.Right()+1;
595 GetLocationData().GetCellPosition( aPageArea.aStart,aRectCellPosition );
596 nRight[ aPageArea.aEnd.Col() ] = aRectCellPosition.Left();
597 for( SCCOL i = aPageArea.aEnd.Col(); i > aPageArea.aStart.Col(); i-- )
599 GetLocationData().GetCellPosition( ScAddress( i,aPageArea.aEnd.Row(),aPageArea.aEnd.Tab()),aRectCellPosition );
600 nRight[ i-1 ] = nRight[ i ] + aRectCellPosition.Right() - aRectCellPosition.Left() + 1;
604 if ( nPrinted ) // If nothing, all gray draw
606 aPaintPageSize = pPrintFunc->GetPageSize();
607 aPaintPageSize.Width() = (long) (aPaintPageSize.Width() * HMM_PER_TWIPS );
608 aPaintPageSize.Height() = (long) (aPaintPageSize.Height() * HMM_PER_TWIPS );
610 nLeftMargin = (long) ( nLeftMargin * HMM_PER_TWIPS );
611 nRightMargin = (long) ( nRightMargin * HMM_PER_TWIPS );
612 nTopMargin = (long) ( nTopMargin * HMM_PER_TWIPS );
613 nBottomMargin = (long) ( nBottomMargin * HMM_PER_TWIPS );
614 nHeaderHeight = (long) ( nHeaderHeight * HMM_PER_TWIPS * mnScale / 100 + nTopMargin );
615 nFooterHeight = (long) ( nFooterHeight * HMM_PER_TWIPS * mnScale / 100 + nBottomMargin );
618 if ( !bStateValid )
620 pPrintFunc->GetPrintState( aState );
621 aState.nDocPages = nTotalPages;
622 bStateValid = TRUE;
625 delete pPrintFunc;
629 long nPageEndX = aPaintPageSize.Width() - aOffset.X();
630 long nPageEndY = aPaintPageSize.Height() - aOffset.Y();
631 Size aWinSize = GetOutputSize();
632 Point aWinEnd( aWinSize.Width(), aWinSize.Height() );
633 BOOL bRight = nPageEndX <= aWinEnd.X();
634 BOOL bBottom = nPageEndY <= aWinEnd.Y();
636 if( bPageMargin )
638 SetMapMode(aMMMode);
639 SetLineColor( COL_BLACK );
640 DrawInvert( (long)( nTopMargin - aOffset.Y() ), POINTER_VSIZEBAR );
641 DrawInvert( (long)(nPageEndY - nBottomMargin ), POINTER_VSIZEBAR );
642 DrawInvert( (long)( nLeftMargin - aOffset.X() ), POINTER_HSIZEBAR );
643 DrawInvert( (long)( nPageEndX - nRightMargin ) , POINTER_HSIZEBAR );
644 if( bHeaderOn )
646 DrawInvert( nHeaderHeight - aOffset.Y(), POINTER_VSIZEBAR );
648 if( bFooterOn )
650 DrawInvert( nPageEndY - nFooterHeight, POINTER_VSIZEBAR );
653 SetMapMode( MapMode( MAP_PIXEL ) );
654 for( int i= aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
656 Point aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
657 SetLineColor( COL_BLACK );
658 SetFillColor( COL_BLACK );
659 DrawRect( Rectangle( Point( nRight[i] - 2, aColumnTop.Y() ),Point( nRight[i] + 2 , 4 + aColumnTop.Y()) ));
660 DrawLine( Point( nRight[i], aColumnTop.Y() ), Point( nRight[i], 10 + aColumnTop.Y()) );
662 SetMapMode( aMMMode );
665 if (bRight || bBottom)
667 SetMapMode(aMMMode);
668 SetLineColor();
669 SetFillColor(aBackColor);
670 if (bRight)
671 DrawRect(Rectangle(nPageEndX,0, aWinEnd.X(),aWinEnd.Y()));
672 if (bBottom)
674 if (bRight)
675 DrawRect(Rectangle(0,nPageEndY, nPageEndX,aWinEnd.Y())); // Ecke nicht doppelt
676 else
677 DrawRect(Rectangle(0,nPageEndY, aWinEnd.X(),aWinEnd.Y()));
680 pViewShell->UpdateScrollBars();
682 //Issue51656 Add resizeable margin on page preview from maoyg
684 void __EXPORT ScPreview::Command( const CommandEvent& rCEvt )
686 USHORT nCmd = rCEvt.GetCommand();
687 if ( nCmd == COMMAND_WHEEL || nCmd == COMMAND_STARTAUTOSCROLL || nCmd == COMMAND_AUTOSCROLL )
689 BOOL bDone = pViewShell->ScrollCommand( rCEvt );
690 if (!bDone)
691 Window::Command(rCEvt);
693 else if ( nCmd == COMMAND_CONTEXTMENU )
694 SfxDispatcher::ExecutePopup();
695 else
696 Window::Command( rCEvt );
700 void __EXPORT ScPreview::KeyInput( const KeyEvent& rKEvt )
702 // The + and - keys can't be configured as accelerator entries, so they must be handled directly
703 // (in ScPreview, not ScPreviewShell -> only if the preview window has the focus)
705 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
706 USHORT nKey = rKeyCode.GetCode();
707 BOOL bHandled = FALSE;
708 if(!rKeyCode.GetModifier())
710 USHORT nSlot = 0;
711 switch(nKey)
713 case KEY_ADD: nSlot = SID_PREVIEW_ZOOMIN; break;
714 case KEY_ESCAPE: nSlot = ScViewUtil::IsFullScreen( *pViewShell ) ? SID_CANCEL : SID_PREVIEW_CLOSE; break;
715 case KEY_SUBTRACT: nSlot = SID_PREVIEW_ZOOMOUT; break;
717 if(nSlot)
719 bHandled = TRUE;
720 pViewShell->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON );
724 if ( !bHandled && !pViewShell->KeyInput(rKEvt) )
725 Window::KeyInput(rKEvt);
729 const ScPreviewLocationData& ScPreview::GetLocationData()
731 if ( !pLocationData )
733 pLocationData = new ScPreviewLocationData( pDocShell->GetDocument(), this );
734 bLocationValid = FALSE;
736 if ( !bLocationValid )
738 pLocationData->Clear();
739 DoPrint( pLocationData );
740 bLocationValid = TRUE;
742 return *pLocationData;
746 void ScPreview::DataChanged(BOOL bNewTime)
748 if (bNewTime)
750 aDate = Date();
751 aTime = Time();
754 bValid = FALSE;
755 InvalidateLocationData( SC_HINT_DATACHANGED );
756 Invalidate();
760 String ScPreview::GetPosString()
762 if (!bValid)
764 CalcPages(nTab);
765 UpdateDrawView(); // Tabelle evtl. geaendert
768 String aString( ScGlobal::GetRscString( STR_PAGE ) );
769 aString += ' ';
770 aString += String::CreateFromInt32(nPageNo+1);
772 if (nTabsTested >= nTabCount)
774 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
775 aString += String::CreateFromInt32(nTotalPages);
778 return aString;
782 void ScPreview::SetZoom(USHORT nNewZoom)
784 if (nNewZoom < 20)
785 nNewZoom = 20;
786 if (nNewZoom > 400)
787 nNewZoom = 400;
788 if (nNewZoom != nZoom)
790 nZoom = nNewZoom;
792 // apply new MapMode and call UpdateScrollBars to update aOffset
794 Fraction aPreviewZoom( nZoom, 100 );
795 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
796 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
797 SetMapMode( aMMMode );
799 bInPaint = TRUE; // don't scroll during SetYOffset in UpdateScrollBars
800 pViewShell->UpdateScrollBars();
801 bInPaint = FALSE;
803 bStateValid = FALSE;
804 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
805 DoInvalidate();
806 Invalidate();
811 void ScPreview::SetPageNo( long nPage )
813 nPageNo = nPage;
814 RecalcPages();
815 UpdateDrawView(); // Tabelle evtl. geaendert
816 InvalidateLocationData( SC_HINT_DATACHANGED );
817 Invalidate();
821 long ScPreview::GetFirstPage(SCTAB nTabP)
823 SCTAB nDocTabCount = pDocShell->GetDocument()->GetTableCount();
824 if (nTabP >= nDocTabCount)
825 nTabP = nDocTabCount-1;
827 long nPage = 0;
828 if (nTabP>0)
830 CalcPages( nTabP );
831 UpdateDrawView(); // Tabelle evtl. geaendert
833 for (SCTAB i=0; i<nTabP; i++)
834 nPage += nPages[i];
836 // bei leerer Tabelle vorhergehende Seite
838 if ( nPages[nTabP]==0 && nPage > 0 )
839 --nPage;
842 return nPage;
846 Size lcl_GetDocPageSize( ScDocument* pDoc, SCTAB nTab )
848 String aName = pDoc->GetPageStyle( nTab );
849 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
850 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aName, SFX_STYLE_FAMILY_PAGE );
851 if ( pStyleSheet )
853 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
854 return ((const SvxSizeItem&) rStyleSet.Get(ATTR_PAGE_SIZE)).GetSize();
856 else
858 DBG_ERROR( "PageStyle not found" );
859 return Size();
864 USHORT ScPreview::GetOptimalZoom(BOOL bWidthOnly)
866 double nWinScaleX = ScGlobal::nScreenPPTX / pDocShell->GetOutputFactor();
867 double nWinScaleY = ScGlobal::nScreenPPTY;
868 Size aWinSize = GetOutputSizePixel();
870 // desired margin is 0.25cm in default MapMode (like Writer),
871 // but some additional margin is introduced by integer scale values
872 // -> add only 0.10cm, so there is some margin in all cases.
873 Size aMarginSize( LogicToPixel( Size( 100, 100 ), MAP_100TH_MM ) );
874 aWinSize.Width() -= 2 * aMarginSize.Width();
875 aWinSize.Height() -= 2 * aMarginSize.Height();
877 Size aLocalPageSize = lcl_GetDocPageSize( pDocShell->GetDocument(), nTab );
878 if ( aLocalPageSize.Width() && aLocalPageSize.Height() )
880 long nZoomX = (long) ( aWinSize.Width() * 100 / ( aLocalPageSize.Width() * nWinScaleX ));
881 long nZoomY = (long) ( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));
883 long nOptimal = nZoomX;
884 if (!bWidthOnly && nZoomY<nOptimal)
885 nOptimal = nZoomY;
887 if (nOptimal<20)
888 nOptimal = 20;
889 if (nOptimal>400)
890 nOptimal = 400;
892 return (USHORT) nOptimal;
894 else
895 return nZoom;
899 void ScPreview::SetXOffset( long nX )
901 if ( aOffset.X() == nX )
902 return;
904 if (bValid)
906 long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
907 aOffset.X() = nX;
908 if (nDif && !bInPaint)
910 MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
911 Scroll( nDif, 0 );
912 SetMapMode(aOldMode);
915 else
917 aOffset.X() = nX;
918 if (!bInPaint)
919 Invalidate();
921 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
922 Paint(Rectangle());
926 void ScPreview::SetYOffset( long nY )
928 if ( aOffset.Y() == nY )
929 return;
931 if (bValid)
933 long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
934 aOffset.Y() = nY;
935 if (nDif && !bInPaint)
937 MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
938 Scroll( 0, nDif );
939 SetMapMode(aOldMode);
942 else
944 aOffset.Y() = nY;
945 if (!bInPaint)
946 Invalidate();
948 InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
949 Paint(Rectangle());
953 void ScPreview::DoInvalidate()
955 // Wenn das ganze aus dem GetState der Shell gerufen wird,
956 // muss das Invalidate hinterher asynchron kommen...
958 if (bInGetState)
959 Application::PostUserEvent( STATIC_LINK( this, ScPreview, InvalidateHdl ) );
960 else
961 StaticInvalidate(); // sofort
964 void ScPreview::StaticInvalidate()
966 // static method, because it's called asynchronously
967 // -> must use current viewframe
969 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
970 if (!pViewFrm)
971 return;
973 SfxBindings& rBindings = pViewFrm->GetBindings();
974 rBindings.Invalidate(SID_STATUS_DOCPOS);
975 rBindings.Invalidate(SID_STATUS_PAGESTYLE);
976 rBindings.Invalidate(SID_PREVIEW_PREVIOUS);
977 rBindings.Invalidate(SID_PREVIEW_NEXT);
978 rBindings.Invalidate(SID_PREVIEW_FIRST);
979 rBindings.Invalidate(SID_PREVIEW_LAST);
980 rBindings.Invalidate(SID_ATTR_ZOOM);
981 rBindings.Invalidate(SID_PREVIEW_ZOOMIN);
982 rBindings.Invalidate(SID_PREVIEW_ZOOMOUT);
983 rBindings.Invalidate(SID_PREVIEW_SCALINGFACTOR);
984 rBindings.Invalidate(SID_ATTR_ZOOMSLIDER);
987 IMPL_STATIC_LINK( ScPreview, InvalidateHdl, void*, EMPTYARG )
989 (void)pThis; // avoid warning
991 StaticInvalidate();
992 return 0;
995 void ScPreview::DataChanged( const DataChangedEvent& rDCEvt )
997 Window::DataChanged(rDCEvt);
999 if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
1000 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1001 (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1002 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1003 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1004 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1006 if ( rDCEvt.GetType() == DATACHANGED_FONTS )
1007 pDocShell->UpdateFontList();
1009 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
1010 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1012 // scroll bar size may have changed
1013 pViewShell->InvalidateBorder(); // calls OuterResizePixel
1016 Invalidate();
1017 InvalidateLocationData( SC_HINT_DATACHANGED );
1021 //Issue51656 Add resizeable margin on page preview from maoyg
1022 void __EXPORT ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
1024 Fraction aPreviewZoom( nZoom, 100 );
1025 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1026 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1028 aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
1029 aButtonDownPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
1031 CaptureMouse();
1033 if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
1035 SetMapMode( aMMMode );
1036 if( bLeftRulerChange )
1038 DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
1039 bLeftRulerMove = TRUE;
1040 bRightRulerMove = FALSE;
1042 else if( bRightRulerChange )
1044 DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
1045 bLeftRulerMove = FALSE;
1046 bRightRulerMove = TRUE;
1050 if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
1052 SetMapMode( aMMMode );
1053 if( bTopRulerChange )
1055 DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
1056 bTopRulerMove = TRUE;
1057 bBottomRulerMove = FALSE;
1059 else if( bBottomRulerChange )
1061 DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
1062 bTopRulerMove = FALSE;
1063 bBottomRulerMove = TRUE;
1065 else if( bHeaderRulerChange )
1067 DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
1068 bHeaderRulerMove = TRUE;
1069 bFooterRulerMove = FALSE;
1071 else if( bFooterRulerChange )
1073 DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
1074 bHeaderRulerMove = FALSE;
1075 bFooterRulerMove = TRUE;
1079 if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
1081 Point aNowPt = rMEvt.GetPosPixel();
1082 SCCOL i = 0;
1083 for( i = aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
1085 if( aNowPt.X() < nRight[i] + 2 && aNowPt.X() > nRight[i] - 2 )
1087 nColNumberButttonDown = i;
1088 break;
1091 if( i == aPageArea.aEnd.Col()+1 )
1092 return;
1094 SetMapMode( aMMMode );
1095 if( nColNumberButttonDown == aPageArea.aStart.Col() )
1096 DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1097 else
1098 DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1100 DrawInvert( aButtonDownChangePoint.X(), POINTER_HSPLIT );
1101 bColRulerMove = TRUE;
1105 void __EXPORT ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
1107 Fraction aPreviewZoom( nZoom, 100 );
1108 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1109 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1111 aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
1113 long nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
1114 long nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
1116 if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
1118 SetPointer( Pointer( POINTER_ARROW ) );
1120 BOOL bMoveRulerAction= TRUE;
1122 ScDocument * pDoc = pDocShell->GetDocument();
1123 String aOldName = pDoc->GetPageStyle( nTab );
1124 BOOL bUndo( pDoc->IsUndoEnabled() );
1125 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
1126 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1128 if ( pStyleSheet )
1130 ScStyleSaveData aOldData;
1131 if( bUndo )
1132 aOldData.InitFromStyle( pStyleSheet );
1134 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1136 SvxLRSpaceItem aLRItem = ( const SvxLRSpaceItem& ) rStyleSet.Get( ATTR_LRSPACE );
1138 if(( bLeftRulerChange || bRightRulerChange ) && ( aButtonUpPt.X() <= ( 0 - aOffset.X() ) || aButtonUpPt.X() > nWidth * HMM_PER_TWIPS - aOffset.X() ) )
1140 bMoveRulerAction = FALSE;
1141 Paint(Rectangle(0,0,10000,10000));
1143 else if( bLeftRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS > nWidth - aLRItem.GetRight() - aOffset.X() / HMM_PER_TWIPS ) )
1145 bMoveRulerAction = FALSE;
1146 Paint(Rectangle(0,0,10000,10000));
1148 else if( bRightRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS < aLRItem.GetLeft() - aOffset.X() / HMM_PER_TWIPS ) )
1150 bMoveRulerAction = FALSE;
1151 Paint(Rectangle(0,0,10000,10000));
1153 else if( aButtonDownPt.X() == aButtonUpPt.X() )
1155 bMoveRulerAction = FALSE;
1156 DrawInvert( aButtonUpPt.X(), POINTER_HSIZEBAR );
1158 if( bMoveRulerAction )
1160 if( bLeftRulerChange && bLeftRulerMove )
1162 aLRItem.SetLeft( (long)( aButtonUpPt.X() / HMM_PER_TWIPS + aOffset.X() / HMM_PER_TWIPS ));
1163 rStyleSet.Put( aLRItem );
1165 else if( bRightRulerChange && bRightRulerMove )
1167 aLRItem.SetRight( (long)( nWidth - aButtonUpPt.X() / HMM_PER_TWIPS - aOffset.X() / HMM_PER_TWIPS ));
1168 rStyleSet.Put( aLRItem );
1171 ScStyleSaveData aNewData;
1172 aNewData.InitFromStyle( pStyleSheet );
1173 if( bUndo )
1175 pDocShell->GetUndoManager()->AddUndoAction(
1176 new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
1177 aOldData, aNewData ) );
1180 if ( ValidTab( nTab ) )
1182 ScPrintFunc aPrintFunc( pDocShell, this, nTab );
1183 aPrintFunc.UpdatePages();
1186 Rectangle aRect(0,0,10000,10000);
1187 Paint( aRect );
1188 bLeftRulerChange = FALSE;
1189 bRightRulerChange = FALSE;
1192 bLeftRulerMove = FALSE;
1193 bRightRulerMove = FALSE;
1196 if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
1198 SetPointer( POINTER_ARROW );
1200 BOOL bMoveRulerAction = TRUE;
1201 if( ( bTopRulerChange || bBottomRulerChange || bHeaderRulerChange || bFooterRulerChange ) && ( aButtonUpPt.Y() <= ( 0 - aOffset.Y() ) || aButtonUpPt.Y() > nHeight * HMM_PER_TWIPS -aOffset.Y() ) )
1203 bMoveRulerAction = FALSE;
1204 Paint( Rectangle(0,0,10000,10000) );
1206 else if( aButtonDownPt.Y() == aButtonUpPt.Y() )
1208 bMoveRulerAction = FALSE;
1209 DrawInvert( aButtonUpPt.Y(), POINTER_VSIZEBAR );
1211 if( bMoveRulerAction )
1213 ScDocument * pDoc = pDocShell->GetDocument();
1214 BOOL bUndo( pDoc->IsUndoEnabled() );
1215 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
1216 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
1217 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1218 if ( pStyleSheet )
1220 ScStyleSaveData aOldData;
1221 if( bUndo )
1222 aOldData.InitFromStyle( pStyleSheet );
1224 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1226 SvxULSpaceItem aULItem = ( const SvxULSpaceItem&)rStyleSet.Get( ATTR_ULSPACE );
1228 if( bTopRulerMove && bTopRulerChange )
1230 aULItem.SetUpperValue( (USHORT)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS ) );
1231 rStyleSet.Put( aULItem );
1233 else if( bBottomRulerMove && bBottomRulerChange )
1235 aULItem.SetLowerValue( (USHORT)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS ) );
1236 rStyleSet.Put( aULItem );
1238 else if( bHeaderRulerMove && bHeaderRulerChange )
1240 const SfxPoolItem* pItem = NULL;
1241 if ( rStyleSet.GetItemState( ATTR_PAGE_HEADERSET, FALSE, &pItem ) == SFX_ITEM_SET )
1243 SfxItemSet& pHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
1244 Size aHeaderSize = ((const SvxSizeItem&)pHeaderSet.Get(ATTR_PAGE_SIZE)).GetSize();
1245 aHeaderSize.Height() = (long)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS - aULItem.GetUpper());
1246 aHeaderSize.Height() = aHeaderSize.Height() * 100 / mnScale;
1247 SvxSetItem aNewHeader( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_HEADERSET) );
1248 aNewHeader.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aHeaderSize ) );
1249 rStyleSet.Put( aNewHeader );
1252 else if( bFooterRulerMove && bFooterRulerChange )
1254 const SfxPoolItem* pItem = NULL;
1255 if( rStyleSet.GetItemState( ATTR_PAGE_FOOTERSET, FALSE, &pItem ) == SFX_ITEM_SET )
1257 SfxItemSet& pFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
1258 Size aFooterSize = ((const SvxSizeItem&)pFooterSet.Get(ATTR_PAGE_SIZE)).GetSize();
1259 aFooterSize.Height() = (long)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS - aULItem.GetLower() );
1260 aFooterSize.Height() = aFooterSize.Height() * 100 / mnScale;
1261 SvxSetItem aNewFooter( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_FOOTERSET) );
1262 aNewFooter.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aFooterSize ) );
1263 rStyleSet.Put( aNewFooter );
1267 ScStyleSaveData aNewData;
1268 aNewData.InitFromStyle( pStyleSheet );
1269 if( bUndo )
1271 pDocShell->GetUndoManager()->AddUndoAction(
1272 new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
1273 aOldData, aNewData ) );
1276 if ( ValidTab( nTab ) )
1278 ScPrintFunc aPrintFunc( pDocShell, this, nTab );
1279 aPrintFunc.UpdatePages();
1282 Rectangle aRect(0,0,10000,10000);
1283 Paint( aRect );
1284 bTopRulerChange = FALSE;
1285 bBottomRulerChange = FALSE;
1286 bHeaderRulerChange = FALSE;
1287 bFooterRulerChange = FALSE;
1290 bTopRulerMove = FALSE;
1291 bBottomRulerMove = FALSE;
1292 bHeaderRulerMove = FALSE;
1293 bFooterRulerMove = FALSE;
1295 if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
1297 SetPointer(POINTER_ARROW);
1298 ScDocument* pDoc = pDocShell->GetDocument();
1299 BOOL bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1300 BOOL bMoveRulerAction = TRUE;
1301 if( aButtonDownPt.X() == aButtonUpPt.X() )
1303 bMoveRulerAction = FALSE;
1304 if( nColNumberButttonDown == aPageArea.aStart.Col() )
1305 DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1306 else
1307 DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1308 DrawInvert( aButtonUpPt.X(), POINTER_HSPLIT );
1310 if( bMoveRulerAction )
1312 long nNewColWidth = 0;
1313 ScDocFunc aFunc(*pDocShell);
1314 SCCOLROW nCols[2] = { nColNumberButttonDown, nColNumberButttonDown };
1316 if( !bLayoutRTL )
1318 nNewColWidth = (long) ( PixelToLogic( Point( rMEvt.GetPosPixel().X() - nRight[ nColNumberButttonDown ], 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
1319 nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
1321 else
1324 nNewColWidth = (long) ( PixelToLogic( Point( nRight[ nColNumberButttonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
1325 nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
1328 if( nNewColWidth >= 0 )
1330 aFunc.SetWidthOrHeight( TRUE, 1,nCols, nTab, SC_SIZE_DIRECT, (USHORT)nNewColWidth, TRUE, TRUE);
1332 if ( ValidTab( nTab ) )
1334 ScPrintFunc aPrintFunc( pDocShell, this, nTab );
1335 aPrintFunc.UpdatePages();
1337 Rectangle nRect(0,0,10000,10000);
1338 Paint( nRect );
1340 bColRulerMove = FALSE;
1342 ReleaseMouse();
1345 void __EXPORT ScPreview::MouseMove( const MouseEvent& rMEvt )
1347 Fraction aPreviewZoom( nZoom, 100 );
1348 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1349 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1350 Point aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode );
1352 long nLeftMargin = 0;
1353 long nRightMargin = 0;
1354 long nTopMargin = 0;
1355 long nBottomMargin = 0;
1356 Size PageSize;
1358 long nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
1359 long nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
1361 if ( nPageNo < nTotalPages )
1363 ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
1365 ScPrintFunc* pPrintFunc;
1367 if (bStateValid)
1368 pPrintFunc = new ScPrintFunc( pDocShell, this, aState, &aOptions );
1369 else
1370 pPrintFunc = new ScPrintFunc( pDocShell, this, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
1372 nLeftMargin = (long)( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
1373 nRightMargin = (long)( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
1374 nRightMargin = (long)( nWidth * HMM_PER_TWIPS - nRightMargin - aOffset.X() );
1375 nTopMargin = (long)( pPrintFunc->GetTopMargin() * HMM_PER_TWIPS - aOffset.Y() );
1376 nBottomMargin = (long)( pPrintFunc->GetBottomMargin() * HMM_PER_TWIPS );
1377 nBottomMargin = (long)( nHeight * HMM_PER_TWIPS - nBottomMargin - aOffset.Y() );
1378 if( mnScale > 0 )
1380 nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS * mnScale / 100 );
1381 nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS * mnScale / 100 );
1383 else
1385 nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
1386 nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
1388 delete pPrintFunc;
1391 Point aPixPt( rMEvt.GetPosPixel() );
1392 Point aLeftTop = LogicToPixel( Point( nLeftMargin, -aOffset.Y() ) , aMMMode );
1393 Point aLeftBottom = LogicToPixel( Point( nLeftMargin ,(long)(nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
1394 Point aRightTop = LogicToPixel( Point( nRightMargin, -aOffset.Y() ), aMMMode );
1395 Point aTopLeft = LogicToPixel( Point( -aOffset.X(), nTopMargin ), aMMMode );
1396 Point aTopRight = LogicToPixel( Point( (long)(nWidth * HMM_PER_TWIPS - aOffset.X()), nTopMargin ), aMMMode );
1397 Point aBottomLeft = LogicToPixel( Point( -aOffset.X(), nBottomMargin ), aMMMode );
1398 Point aHeaderLeft = LogicToPixel( Point( -aOffset.X(), nHeaderHeight ), aMMMode );
1399 Point aFooderLeft = LogicToPixel( Point( -aOffset.X(), nFooterHeight ), aMMMode );
1401 BOOL bOnColRulerChange = FALSE;
1403 for( SCCOL i=aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
1405 Point aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
1406 Point aColumnBottom = LogicToPixel( Point( 0, (long)( nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
1407 if( aPixPt.X() < ( nRight[i] + 2 ) && ( aPixPt.X() > ( nRight[i] - 2 ) ) && ( aPixPt.X() < aRightTop.X() ) && ( aPixPt.X() > aLeftTop.X() )
1408 && ( aPixPt.Y() > aColumnTop.Y() ) && ( aPixPt.Y() < aColumnBottom.Y() ) && !bLeftRulerMove && !bRightRulerMove
1409 && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1411 bOnColRulerChange = TRUE;
1412 if( !rMEvt.GetButtons() && GetPointer() == POINTER_HSPLIT )
1413 nColNumberButttonDown = i;
1414 break;
1418 if( aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 ) && !bRightRulerMove )
1420 bLeftRulerChange = TRUE;
1421 bRightRulerChange = FALSE;
1423 else if( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) && !bLeftRulerMove )
1425 bLeftRulerChange = FALSE;
1426 bRightRulerChange = TRUE;
1428 else if( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1430 bTopRulerChange = TRUE;
1431 bBottomRulerChange = FALSE;
1432 bHeaderRulerChange = FALSE;
1433 bFooterRulerChange = FALSE;
1435 else if( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) && !bTopRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1437 bTopRulerChange = FALSE;
1438 bBottomRulerChange = TRUE;
1439 bHeaderRulerChange = FALSE;
1440 bFooterRulerChange = FALSE;
1442 else if( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bFooterRulerMove )
1444 bTopRulerChange = FALSE;
1445 bBottomRulerChange = FALSE;
1446 bHeaderRulerChange = TRUE;
1447 bFooterRulerChange = FALSE;
1449 else if( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove )
1451 bTopRulerChange = FALSE;
1452 bBottomRulerChange = FALSE;
1453 bHeaderRulerChange = FALSE;
1454 bFooterRulerChange = TRUE;
1457 if( bPageMargin )
1459 if(( (aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 )) || bLeftRulerMove ||
1460 ( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) ) || bRightRulerMove || bOnColRulerChange || bColRulerMove )
1461 && aPixPt.Y() > aLeftTop.Y() && aPixPt.Y() < aLeftBottom.Y() )
1463 if( bOnColRulerChange || bColRulerMove )
1465 SetPointer( Pointer( POINTER_HSPLIT ) );
1466 if( bColRulerMove )
1468 if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1469 DragMove( aMouseMovePoint.X(), POINTER_HSPLIT );
1472 else
1474 if( bLeftRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1476 SetPointer( Pointer( POINTER_HSIZEBAR ) );
1477 if( bLeftRulerMove )
1479 if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1480 DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
1483 else if( bRightRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1485 SetPointer( Pointer( POINTER_HSIZEBAR ) );
1486 if( bRightRulerMove )
1488 if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1489 DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
1494 else
1496 if( ( ( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) ) || bTopRulerMove ||
1497 ( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) ) || bBottomRulerMove ||
1498 ( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) ) || bHeaderRulerMove ||
1499 ( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) ) || bFooterRulerMove )
1500 && aPixPt.X() > aTopLeft.X() && aPixPt.X() < aTopRight.X() )
1502 if( bTopRulerChange )
1504 SetPointer( Pointer( POINTER_VSIZEBAR ) );
1505 if( bTopRulerMove )
1507 if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1508 DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1511 else if( bBottomRulerChange )
1513 SetPointer( Pointer( POINTER_VSIZEBAR ) );
1514 if( bBottomRulerMove )
1516 if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1517 DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1520 else if( bHeaderRulerChange )
1522 SetPointer( Pointer( POINTER_VSIZEBAR ) );
1523 if( bHeaderRulerMove )
1525 if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1526 DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1529 else if( bFooterRulerChange )
1531 SetPointer( Pointer( POINTER_VSIZEBAR ) );
1532 if( bFooterRulerMove )
1534 if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1535 DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1539 else
1540 SetPointer( Pointer( POINTER_ARROW ) );
1544 //Issue51656 Add resizeable margin on page preview from maoyg
1545 void ScPreview::InvalidateLocationData(ULONG nId)
1547 bLocationValid = FALSE;
1548 if (pViewShell->HasAccessibilityObjects())
1549 pViewShell->BroadcastAccessibility( SfxSimpleHint( nId ) );
1552 void ScPreview::GetFocus()
1554 if (pViewShell->HasAccessibilityObjects())
1555 pViewShell->BroadcastAccessibility( ScAccWinFocusGotHint(GetAccessible()) );
1558 void ScPreview::LoseFocus()
1560 if (pViewShell->HasAccessibilityObjects())
1561 pViewShell->BroadcastAccessibility( ScAccWinFocusLostHint(GetAccessible()) );
1564 com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessible> ScPreview::CreateAccessible()
1566 ScAccessibleDocumentPagePreview* pAccessible =
1567 new ScAccessibleDocumentPagePreview( GetAccessibleParentWindow()->GetAccessible(), pViewShell );
1568 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xAccessible = pAccessible;
1569 pAccessible->Init();
1570 return xAccessible;
1573 //Issue51656 Add resizeable margin on page preview from maoyg
1574 void ScPreview::DragMove( long nDragMovePos, USHORT nFlags )
1576 Fraction aPreviewZoom( nZoom, 100 );
1577 Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1578 MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1579 SetMapMode( aMMMode );
1580 long nPos = nDragMovePos;
1581 if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
1583 if( nDragMovePos != aButtonDownChangePoint.X() )
1585 DrawInvert( aButtonDownChangePoint.X(), nFlags );
1586 aButtonDownChangePoint.X() = nPos;
1587 DrawInvert( aButtonDownChangePoint.X(), nFlags );
1590 else if( nFlags == POINTER_VSIZEBAR )
1592 if( nDragMovePos != aButtonDownChangePoint.Y() )
1594 DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1595 aButtonDownChangePoint.Y() = nPos;
1596 DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1601 void ScPreview::DrawInvert( long nDragPos, USHORT nFlags )
1603 long nHeight = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Height();
1604 long nWidth = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Width();
1605 if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
1607 Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1,(long)( ( nHeight * HMM_PER_TWIPS ) - aOffset.Y()));
1608 Invert( aRect,INVERT_50 );
1610 else if( nFlags == POINTER_VSIZEBAR )
1612 Rectangle aRect( -aOffset.X(), nDragPos,(long)( ( nWidth * HMM_PER_TWIPS ) - aOffset.X() ), nDragPos + 1 );
1613 Invert( aRect,INVERT_50 );
1616 //Issue51656 Add resizeable margin on page preview from maoyg