xref: /trunk/main/sc/source/ui/view/preview.cxx (revision 88c764bff9c8901fbd5e0d89dee3bedcded6f1b3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sc.hxx"
24 
25 // INCLUDE ---------------------------------------------------------------
26 #include <tools/pstm.hxx>
27 #include "scitems.hxx"
28 #include <editeng/eeitem.hxx>
29 
30 
31 #include <svtools/colorcfg.hxx>
32 #include <svx/fmview.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svtools/accessibilityoptions.hxx>
39 #include <svl/itemset.hxx>
40 #include <tools/multisel.hxx>
41 #include <vcl/waitobj.hxx>
42 #include <vcl/sound.hxx>
43 
44 #include "preview.hxx"
45 #include "prevwsh.hxx"
46 #include "prevloc.hxx"
47 #include "docsh.hxx"
48 #include "docfunc.hxx"
49 #include "printfun.hxx"
50 #include "printopt.hxx"
51 #include "stlpool.hxx"
52 #include "undostyl.hxx"
53 #include "drwlayer.hxx"
54 #include "scmod.hxx"
55 #include "globstr.hrc"
56 #include "sc.hrc" // for ShellInvalidate
57 #include "AccessibleDocumentPagePreview.hxx"
58 #include <vcl/lineinfo.hxx>
59 #include <svx/algitem.hxx>
60 #include <editeng/lrspitem.hxx>
61 #include <editeng/ulspitem.hxx>
62 #include <editeng/sizeitem.hxx>
63 #include "attrib.hxx"
64 #include "pagepar.hxx"
65 #include <com/sun/star/accessibility/XAccessible.hpp>
66 #include "AccessibilityHints.hxx"
67 #include <vcl/svapp.hxx>
68 #include "viewutil.hxx"
69 
70 // STATIC DATA -----------------------------------------------------------
71 
72 //#define SC_PREVIEW_SHADOWSIZE 2
73 
lcl_GetDisplayStart(SCTAB nTab,ScDocument * pDoc,long * pPages)74 long lcl_GetDisplayStart( SCTAB nTab, ScDocument* pDoc, long* pPages )
75 {
76     long nDisplayStart = 0;
77     for (SCTAB i=0; i<nTab; i++)
78     {
79         if ( pDoc->NeedPageResetAfterTab(i) )
80             nDisplayStart = 0;
81         else
82             nDisplayStart += pPages[i];
83     }
84     return nDisplayStart;
85 }
86 
87 
ScPreview(Window * pParent,ScDocShell * pDocSh,ScPreviewShell * pViewSh)88 ScPreview::ScPreview( Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pViewSh ) :
89     Window( pParent ),
90     nPageNo( 0 ),
91     nZoom( 100 ),
92     bValid( sal_False ),
93     nTabsTested( 0 ),
94     nTab( 0 ),
95     nTabStart( 0 ),
96     nDisplayStart( 0 ),
97     nTotalPages( 0 ),
98     bStateValid( sal_False ),
99     bLocationValid( sal_False ),
100     pLocationData( NULL ),
101     pDrawView( NULL ),
102     bInPaint( false ),
103     bInSetZoom( false ),
104     bInGetState( sal_False ),
105     pDocShell( pDocSh ),
106     pViewShell( pViewSh ),
107     bLeftRulerMove( sal_False ),
108     bRightRulerMove( sal_False ),
109     bTopRulerMove( sal_False ),
110     bBottomRulerMove( sal_False ),
111     bHeaderRulerMove( sal_False ),
112     bFooterRulerMove( sal_False ),
113     bLeftRulerChange( sal_False ),
114     bRightRulerChange( sal_False ),
115     bTopRulerChange( sal_False ),
116     bBottomRulerChange( sal_False ),
117     bHeaderRulerChange( sal_False ),
118     bFooterRulerChange( sal_False ),
119     bPageMargin ( sal_False ),
120     bColRulerMove( sal_False ),
121     mnScale( 0 ),
122     nColNumberButttonDown( 0 ),
123     nHeaderHeight ( 0 ),
124     nFooterHeight ( 0 )
125 {
126     SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW ); // #106611#
127     SetBackground();
128 
129     SetHelpId( HID_SC_WIN_PREVIEW );
130     SetUniqueId( HID_SC_WIN_PREVIEW );
131 
132     SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
133 
134     for (SCCOL i=0; i<=MAXCOL; i++)
135         nRight[i] = 0; // initialized with actual positions when markers are drawn
136 }
137 
138 
~ScPreview()139 __EXPORT ScPreview::~ScPreview()
140 {
141     delete pDrawView;
142     delete pLocationData;
143 }
144 
UpdateDrawView()145 void ScPreview::UpdateDrawView() // nTab muss richtig sein
146 {
147     ScDocument* pDoc = pDocShell->GetDocument();
148     ScDrawLayer* pModel = pDoc->GetDrawLayer(); // is not 0
149 
150     // #114135#
151     if ( pModel )
152     {
153         SdrPage* pPage = pModel->GetPage(nTab);
154         if ( pDrawView && ( !pDrawView->GetSdrPageView() || pDrawView->GetSdrPageView()->GetPage() != pPage ) )
155         {
156             // die angezeigte Page der DrawView umzustellen (s.u.) funktioniert nicht ?!?
157             delete pDrawView;
158             pDrawView = NULL;
159         }
160 
161         if ( !pDrawView ) // neu anlegen?
162         {
163             pDrawView = new FmFormView( pModel, this );
164             // #55259# die DrawView übernimmt den Design-Modus vom Model
165             // (Einstellung "Im Entwurfsmodus öffnen"), darum hier zurücksetzen
166             pDrawView->SetDesignMode( sal_True );
167             pDrawView->SetPrintPreview( sal_True );
168             pDrawView->ShowSdrPage(pPage);
169         }
170 #if 0
171         else if ( !pDrawView->GetSdrPageView()) // angezeigte Page umstellen
172         {
173             pDrawView->HideSdrPage();
174             pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
175         }
176 #endif
177     }
178     else if ( pDrawView )
179     {
180         delete pDrawView; // für diese Tabelle nicht gebraucht
181         pDrawView = NULL;
182     }
183 }
184 
185 
TestLastPage()186 void ScPreview::TestLastPage()
187 {
188     if (nPageNo >= nTotalPages)
189     {
190         if (nTotalPages)
191         {
192             nPageNo = nTotalPages - 1;
193             nTab = nTabCount - 1;
194             while (nTab > 0 && !nPages[nTab]) // letzte nicht leere Tabelle
195                 --nTab;
196             DBG_ASSERT(nPages[nTab],"alle Tabellen leer?");
197             nTabPage = nPages[nTab] - 1;
198             nTabStart = 0;
199             for (sal_uInt16 i=0; i<nTab; i++)
200                 nTabStart += nPages[i];
201 
202             ScDocument* pDoc = pDocShell->GetDocument();
203             nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
204         }
205         else // empty document
206         {
207             nTab = 0;
208             nPageNo = nTabPage = nTabStart = nDisplayStart = 0;
209             aState.nPrintTab = 0;
210                         aState.nStartCol = aState.nEndCol = 0;
211                         aState.nStartRow = aState.nEndRow = 0;
212                         aState.nZoom = 0;
213             aState.nPagesX = aState.nPagesY = 0;
214             aState.nTabPages = aState.nTotalPages =
215             aState.nPageStart = aState.nDocPages = 0;
216         }
217     }
218 }
219 
220 
CalcPages(SCTAB)221 void ScPreview::CalcPages( SCTAB /*nToWhichTab*/ )
222 {
223     WaitObject( this );
224 
225     ScDocument* pDoc = pDocShell->GetDocument();
226     nTabCount = pDoc->GetTableCount();
227 
228     //SCTAB nAnz = Min( nTabCount, SCTAB(nToWhichTab+1) );
229     SCTAB nAnz = nTabCount;
230     SCTAB nStart = nTabsTested;
231     if (!bValid)
232     {
233         nStart = 0;
234         nTotalPages = 0;
235         nTabsTested = 0;
236     }
237 
238     // update all pending row heights with a single progress bar,
239     // instead of a separate progress for each sheet from ScPrintFunc
240     pDocShell->UpdatePendingRowHeights( nAnz-1, true );
241 
242     //  PrintOptions is passed to PrintFunc for SkipEmpty flag,
243     //  but always all sheets are used (there is no selected sheet)
244     ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
245 
246     for (SCTAB i=nStart; i<nAnz; i++)
247     {
248         long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;
249 
250         long nThisStart = nTotalPages;
251         ScPrintFunc aPrintFunc( this, pDocShell, i, nAttrPage, 0, NULL, &aOptions );
252         long nThisTab = aPrintFunc.GetTotalPages();
253         nPages[i] = nThisTab;
254         nTotalPages += nThisTab;
255         nFirstAttr[i] = aPrintFunc.GetFirstPageNo(); // behalten oder aus Vorlage
256 
257         if (nPageNo>=nThisStart && nPageNo<nTotalPages)
258         {
259             nTab = i;
260             nTabPage = nPageNo - nThisStart;
261             nTabStart = nThisStart;
262 
263             aPrintFunc.GetPrintState( aState );
264             aPageSize = aPrintFunc.GetPageSize();
265         }
266     }
267 
268     nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
269 
270     if (nAnz > nTabsTested)
271         nTabsTested = nAnz;
272 
273     // testen, ob hinter letzter Seite
274 
275     if ( nTabsTested >= nTabCount )
276         TestLastPage();
277 
278     aState.nDocPages = nTotalPages;
279 
280     bValid = sal_True;
281     bStateValid = sal_True;
282     DoInvalidate();
283 }
284 
285 
RecalcPages()286 void ScPreview::RecalcPages() // nur nPageNo geaendert
287 {
288     if (!bValid)
289         return; // dann wird CalcPages aufgerufen
290 
291     SCTAB nOldTab = nTab;
292 
293     sal_Bool bDone = sal_False;
294     while (nPageNo >= nTotalPages && nTabsTested < nTabCount)
295     {
296         CalcPages( nTabsTested );
297         bDone = sal_True;
298     }
299 
300     if (!bDone)
301     {
302         long nPartPages = 0;
303         for (SCTAB i=0; i<nTabsTested; i++)
304         {
305             long nThisStart = nPartPages;
306             nPartPages += nPages[i];
307 
308             if (nPageNo>=nThisStart && nPageNo<nPartPages)
309             {
310                 nTab = i;
311                 nTabPage = nPageNo - nThisStart;
312                 nTabStart = nThisStart;
313 
314 //              aPageSize = aPrintFunc.GetPageSize();
315             }
316         }
317 
318         ScDocument* pDoc = pDocShell->GetDocument();
319         nDisplayStart = lcl_GetDisplayStart( nTab, pDoc, nPages );
320     }
321 
322     TestLastPage(); // testen, ob hinter letzter Seite
323 
324     if ( nTab != nOldTab )
325         bStateValid = sal_False;
326 
327     DoInvalidate();
328 }
329 
330 
DoPrint(ScPreviewLocationData * pFillLocation)331 void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
332 {
333     if (!bValid)
334     {
335         CalcPages(0);
336         RecalcPages();
337         UpdateDrawView(); // Tabelle evtl. geaendert
338     }
339 
340     Fraction aPreviewZoom( nZoom, 100 );
341     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
342     MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
343 
344     sal_Bool bDoPrint = ( pFillLocation == NULL );
345     sal_Bool bValidPage = ( nPageNo < nTotalPages );
346 
347     ScModule* pScMod = SC_MOD();
348     const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
349     Color aBackColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
350 
351     if ( bDoPrint && ( aOffset.X() < 0 || aOffset.Y() < 0 ) && bValidPage )
352     {
353         SetMapMode( aMMMode );
354         SetLineColor();
355         SetFillColor(aBackColor);
356 
357         Size aWinSize = GetOutputSize();
358         if ( aOffset.X() < 0 )
359             DrawRect(Rectangle( 0, 0, -aOffset.X(), aWinSize.Height() ));
360         if ( aOffset.Y() < 0 )
361             DrawRect(Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
362     }
363 
364     long   nLeftMargin = 0;
365     long   nRightMargin = 0;
366     long   nTopMargin = 0;
367     long   nBottomMargin = 0;
368     sal_Bool bHeaderOn = sal_False;
369     sal_Bool bFooterOn = sal_False;
370 
371     ScDocument* pDoc = pDocShell->GetDocument();
372     sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
373 
374     Size aLocalPageSize;
375     if ( bValidPage )
376     {
377         ScPrintOptions aOptions = pScMod->GetPrintOptions();
378 
379         ScPrintFunc* pPrintFunc;
380         if (bStateValid)
381             pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
382         else
383             pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
384 
385         pPrintFunc->SetOffset(aOffset);
386         pPrintFunc->SetManualZoom(nZoom);
387         pPrintFunc->SetDateTime(aDate,aTime);
388         pPrintFunc->SetClearFlag(sal_True);
389         pPrintFunc->SetUseStyleColor( pScMod->GetAccessOptions().GetIsForPagePreviews() );
390 
391         pPrintFunc->SetDrawView( pDrawView );
392 
393         // MultiSelection für die eine Seite muss etwas umständlich erzeugt werden...
394         Range aPageRange( nPageNo+1, nPageNo+1 );
395         MultiSelection aPage( aPageRange );
396         aPage.SetTotalRange( Range(0,RANGE_MAX) );
397         aPage.Select( aPageRange );
398 
399         long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, pFillLocation );
400         DBG_ASSERT(nPrinted<=1, "was'n nu los?");
401 
402         SetMapMode(aMMMode);
403 
404         //init nLeftMargin ... in the ScPrintFunc::InitParam!!!
405         nLeftMargin = pPrintFunc->GetLeftMargin();
406         nRightMargin = pPrintFunc->GetRightMargin();
407         nTopMargin = pPrintFunc->GetTopMargin();
408         nBottomMargin = pPrintFunc->GetBottomMargin();
409         nHeaderHeight = pPrintFunc->GetHeader().nHeight;
410         nFooterHeight = pPrintFunc->GetFooter().nHeight;
411         bHeaderOn = pPrintFunc->GetHeader().bEnable;
412         bFooterOn = pPrintFunc->GetFooter().bEnable;
413         mnScale = pPrintFunc->GetZoom();
414 
415         if ( bDoPrint && bPageMargin && pLocationData ) // don't make use of pLocationData while filling it
416         {
417             Rectangle aPixRect;
418             Rectangle aRectCellPosition;
419             Rectangle aRectPosition;
420             pLocationData->GetMainCellRange( aPageArea, aPixRect );
421             if( !bLayoutRTL )
422             {
423                 pLocationData->GetCellPosition( aPageArea.aStart, aRectPosition );
424                 nLeftPosition = aRectPosition.Left();
425                 for( SCCOL i = aPageArea.aStart.Col(); i <= aPageArea.aEnd.Col(); i++ )
426                 {
427                     pLocationData->GetCellPosition( ScAddress( i,aPageArea.aStart.Row(),aPageArea.aStart.Tab()),aRectCellPosition );
428                     nRight[i] = aRectCellPosition.Right();
429                 }
430             }
431             else
432             {
433                 pLocationData->GetCellPosition( aPageArea.aEnd, aRectPosition );
434                 nLeftPosition = aRectPosition.Right()+1;
435 
436                 pLocationData->GetCellPosition( aPageArea.aStart,aRectCellPosition );
437                 nRight[ aPageArea.aEnd.Col() ] = aRectCellPosition.Left();
438                 for( SCCOL i = aPageArea.aEnd.Col(); i > aPageArea.aStart.Col(); i-- )
439                 {
440                     pLocationData->GetCellPosition( ScAddress( i,aPageArea.aEnd.Row(),aPageArea.aEnd.Tab()),aRectCellPosition );
441                     nRight[ i-1 ] = nRight[ i ] + aRectCellPosition.Right() - aRectCellPosition.Left() + 1;
442                 }
443             }
444         }
445 
446         if (nPrinted)   // wenn nichts, alles grau zeichnen
447         {
448             aLocalPageSize = pPrintFunc->GetPageSize();
449             aLocalPageSize.Width()  = (long) (aLocalPageSize.Width()  * HMM_PER_TWIPS );
450             aLocalPageSize.Height() = (long) (aLocalPageSize.Height() * HMM_PER_TWIPS );
451 
452             nLeftMargin = (long) ( nLeftMargin * HMM_PER_TWIPS );
453             nRightMargin = (long) ( nRightMargin * HMM_PER_TWIPS );
454             nTopMargin = (long) ( nTopMargin * HMM_PER_TWIPS );
455             nBottomMargin = (long) ( nBottomMargin * HMM_PER_TWIPS );
456             nHeaderHeight = (long) ( nHeaderHeight * HMM_PER_TWIPS * mnScale / 100 + nTopMargin );
457             nFooterHeight = (long) ( nFooterHeight * HMM_PER_TWIPS * mnScale / 100 + nBottomMargin );
458         }
459 
460         if (!bStateValid)
461         {
462             pPrintFunc->GetPrintState( aState );
463             aState.nDocPages = nTotalPages;
464             bStateValid = sal_True;
465         }
466         delete pPrintFunc;
467     }
468 
469     if ( bDoPrint )
470     {
471         long nPageEndX = aLocalPageSize.Width()  - aOffset.X();
472         long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
473         if ( !bValidPage )
474             nPageEndX = nPageEndY = 0;
475 
476         Size aWinSize = GetOutputSize();
477         Point aWinEnd( aWinSize.Width(), aWinSize.Height() );
478         sal_Bool bRight  = nPageEndX <= aWinEnd.X();
479         sal_Bool bBottom = nPageEndY <= aWinEnd.Y();
480 
481         if( bPageMargin && bValidPage )
482         {
483             SetMapMode(aMMMode);
484             SetLineColor( COL_BLACK );
485             DrawInvert( (long)( nTopMargin - aOffset.Y() ), POINTER_VSIZEBAR );
486             DrawInvert( (long)(nPageEndY - nBottomMargin ), POINTER_VSIZEBAR );
487             DrawInvert( (long)( nLeftMargin - aOffset.X() ), POINTER_HSIZEBAR );
488             DrawInvert( (long)( nPageEndX - nRightMargin ) , POINTER_HSIZEBAR );
489             if( bHeaderOn )
490             {
491                 DrawInvert( nHeaderHeight - aOffset.Y(), POINTER_VSIZEBAR );
492             }
493             if( bFooterOn )
494             {
495                 DrawInvert( nPageEndY - nFooterHeight, POINTER_VSIZEBAR );
496             }
497 
498             SetMapMode( MapMode( MAP_PIXEL ) );
499             for( int i= aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
500             {
501                 Point aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
502                 SetLineColor( COL_BLACK );
503                 SetFillColor( COL_BLACK );
504                 DrawRect( Rectangle( Point( nRight[i] - 2, aColumnTop.Y() ),Point( nRight[i] + 2 , 4 + aColumnTop.Y()) ));
505                 DrawLine( Point( nRight[i], aColumnTop.Y() ), Point( nRight[i], 10 + aColumnTop.Y()) );
506             }
507             SetMapMode( aMMMode );
508         }
509 
510         if (bRight || bBottom)
511         {
512             SetMapMode(aMMMode);
513             SetLineColor();
514             SetFillColor(aBackColor);
515             if (bRight)
516                 DrawRect(Rectangle(nPageEndX,0, aWinEnd.X(),aWinEnd.Y()));
517             if (bBottom)
518             {
519                 if (bRight)
520                     DrawRect(Rectangle(0,nPageEndY, nPageEndX,aWinEnd.Y())); // Ecke nicht doppelt
521                 else
522                     DrawRect(Rectangle(0,nPageEndY, aWinEnd.X(),aWinEnd.Y()));
523             }
524         }
525 
526         if ( bValidPage )
527         {
528             Color aBorderColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
529 
530             // draw border
531 
532             if ( aOffset.X() <= 0 || aOffset.Y() <= 0 || bRight || bBottom )
533             {
534                 SetLineColor( aBorderColor );
535                 SetFillColor();
536 
537                 Rectangle aPixel( LogicToPixel( Rectangle( -aOffset.X(), -aOffset.Y(), nPageEndX, nPageEndY ) ) );
538                 --aPixel.Right();
539                 --aPixel.Bottom();
540                 DrawRect( PixelToLogic( aPixel ) );
541             }
542 
543             //  draw shadow
544 
545 //          SetLineColor();
546 //          SetFillColor( aBorderColor );
547 
548 //          Rectangle aPixel;
549 
550 //          aPixel = LogicToPixel( Rectangle( nPageEndX, -aOffset.Y(), nPageEndX, nPageEndY ) );
551 //          aPixel.Top() += SC_PREVIEW_SHADOWSIZE;
552 //          aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
553 //          aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
554 //          DrawRect( PixelToLogic( aPixel ) );
555 
556 //          aPixel = LogicToPixel( Rectangle( -aOffset.X(), nPageEndY, nPageEndX, nPageEndY ) );
557 //          aPixel.Left() += SC_PREVIEW_SHADOWSIZE;
558 //          aPixel.Right() += SC_PREVIEW_SHADOWSIZE - 1;
559 //          aPixel.Bottom() += SC_PREVIEW_SHADOWSIZE - 1;
560 //          DrawRect( PixelToLogic( aPixel ) );
561         }
562     }
563 }
564 
565 // Issue51656 Add resizeable margin on page preview from maoyg
Paint(const Rectangle &)566 void __EXPORT ScPreview::Paint( const Rectangle& /* rRect */ )
567 {
568     bool bWasInPaint = bInPaint; // nested calls shouldn't be necessary, but allow for now
569     bInPaint = true;
570 
571     if (bPageMargin)
572         GetLocationData(); // fill location data for column positions
573     DoPrint( NULL );
574     pViewShell->UpdateScrollBars();
575 
576     bInPaint = bWasInPaint;
577 }
578 // Issue51656 Add resizeable margin on page preview from maoyg
579 
Command(const CommandEvent & rCEvt)580 void __EXPORT ScPreview::Command( const CommandEvent& rCEvt )
581 {
582     sal_uInt16 nCmd = rCEvt.GetCommand();
583     if ( nCmd == COMMAND_WHEEL || nCmd == COMMAND_STARTAUTOSCROLL || nCmd == COMMAND_AUTOSCROLL )
584     {
585         sal_Bool bDone = pViewShell->ScrollCommand( rCEvt );
586         if (!bDone)
587             Window::Command(rCEvt);
588     }
589     else if ( nCmd == COMMAND_CONTEXTMENU )
590         SfxDispatcher::ExecutePopup();
591     else
592         Window::Command( rCEvt );
593 }
594 
595 
KeyInput(const KeyEvent & rKEvt)596 void __EXPORT ScPreview::KeyInput( const KeyEvent& rKEvt )
597 {
598     // The + and - keys can't be configured as accelerator entries, so they must be handled directly
599     // (in ScPreview, not ScPreviewShell -> only if the preview window has the focus)
600 
601     const KeyCode& rKeyCode = rKEvt.GetKeyCode();
602     sal_uInt16 nKey = rKeyCode.GetCode();
603     sal_Bool bHandled = sal_False;
604     if(!rKeyCode.GetModifier())
605     {
606         sal_uInt16 nSlot = 0;
607         switch(nKey)
608         {
609             case KEY_ADD:      nSlot = SID_PREVIEW_ZOOMIN; break;
610             case KEY_ESCAPE:   nSlot = ScViewUtil::IsFullScreen( *pViewShell ) ? SID_CANCEL : SID_PREVIEW_CLOSE; break;
611             case KEY_SUBTRACT: nSlot = SID_PREVIEW_ZOOMOUT; break;
612         }
613         if(nSlot)
614         {
615             bHandled = sal_True;
616             pViewShell->GetViewFrame()->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_ASYNCHRON );
617         }
618     }
619 
620     if ( !bHandled && !pViewShell->KeyInput(rKEvt) )
621         Window::KeyInput(rKEvt);
622 }
623 
624 
GetLocationData()625 const ScPreviewLocationData& ScPreview::GetLocationData()
626 {
627     if ( !pLocationData )
628     {
629         pLocationData = new ScPreviewLocationData( pDocShell->GetDocument(), this );
630         bLocationValid = sal_False;
631     }
632     if ( !bLocationValid )
633     {
634         pLocationData->Clear();
635         DoPrint( pLocationData );
636         bLocationValid = sal_True;
637     }
638     return *pLocationData;
639 }
640 
641 
DataChanged(sal_Bool bNewTime)642 void ScPreview::DataChanged(sal_Bool bNewTime)
643 {
644     if (bNewTime)
645     {
646         aDate = Date();
647         aTime = Time();
648     }
649 
650     bValid = sal_False;
651     InvalidateLocationData( SC_HINT_DATACHANGED );
652     Invalidate();
653 }
654 
655 
GetPosString()656 String ScPreview::GetPosString()
657 {
658     if (!bValid)
659     {
660         CalcPages(nTab);
661         UpdateDrawView(); // Tabelle evtl. geändert
662     }
663 
664     String aString( ScGlobal::GetRscString( STR_PAGE ) );
665     aString += ' ';
666     aString += String::CreateFromInt32(nPageNo+1);
667 
668     if (nTabsTested >= nTabCount)
669     {
670         aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
671         aString += String::CreateFromInt32(nTotalPages);
672     }
673 
674     return aString;
675 }
676 
677 
SetZoom(sal_uInt16 nNewZoom)678 void ScPreview::SetZoom(sal_uInt16 nNewZoom)
679 {
680     if (nNewZoom < 20)
681         nNewZoom = 20;
682     if (nNewZoom > 400)
683         nNewZoom = 400;
684     if (nNewZoom != nZoom)
685     {
686         nZoom = nNewZoom;
687 
688         //  apply new MapMode and call UpdateScrollBars to update aOffset
689 
690         Fraction aPreviewZoom( nZoom, 100 );
691         Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
692         MapMode aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
693         SetMapMode( aMMMode );
694 
695         bInSetZoom = true; // don't scroll during SetYOffset in UpdateScrollBars
696         pViewShell->UpdateScrollBars();
697         bInSetZoom = false;
698 
699         bStateValid = sal_False;
700         InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
701         DoInvalidate();
702         Invalidate();
703     }
704 }
705 
706 
SetPageNo(long nPage)707 void ScPreview::SetPageNo( long nPage )
708 {
709     nPageNo = nPage;
710     RecalcPages();
711     UpdateDrawView(); // Tabelle evtl. geändert
712     InvalidateLocationData( SC_HINT_DATACHANGED );
713     Invalidate();
714 }
715 
716 
GetFirstPage(SCTAB nTabP)717 long ScPreview::GetFirstPage(SCTAB nTabP)
718 {
719     SCTAB nDocTabCount = pDocShell->GetDocument()->GetTableCount();
720     if (nTabP >= nDocTabCount)
721         nTabP = nDocTabCount-1;
722 
723     long nPage = 0;
724     if (nTabP>0)
725     {
726         CalcPages( nTabP );
727         UpdateDrawView(); // Tabelle evtl. geändert
728 
729         for (SCTAB i=0; i<nTabP; i++)
730             nPage += nPages[i];
731 
732         // bei leerer Tabelle vorhergehende Seite
733 
734         if ( nPages[nTabP]==0 && nPage > 0 )
735             --nPage;
736     }
737 
738     return nPage;
739 }
740 
741 
lcl_GetDocPageSize(ScDocument * pDoc,SCTAB nTab)742 Size lcl_GetDocPageSize( ScDocument* pDoc, SCTAB nTab )
743 {
744     String aName = pDoc->GetPageStyle( nTab );
745     ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
746     SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aName, SFX_STYLE_FAMILY_PAGE );
747     if ( pStyleSheet )
748     {
749         SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
750         return ((const SvxSizeItem&) rStyleSet.Get(ATTR_PAGE_SIZE)).GetSize();
751     }
752     else
753     {
754         DBG_ERROR( "PageStyle not found" );
755         return Size();
756     }
757 }
758 
759 
GetOptimalZoom(sal_Bool bWidthOnly)760 sal_uInt16 ScPreview::GetOptimalZoom(sal_Bool bWidthOnly)
761 {
762     double nWinScaleX = ScGlobal::nScreenPPTX / pDocShell->GetOutputFactor();
763     double nWinScaleY = ScGlobal::nScreenPPTY;
764     Size aWinSize = GetOutputSizePixel();
765 
766     //  desired margin is 0.25cm in default MapMode (like Writer),
767     //  but some additional margin is introduced by integer scale values
768     //  -> add only 0.10cm, so there is some margin in all cases.
769     Size aMarginSize( LogicToPixel( Size( 100, 100 ), MAP_100TH_MM ) );
770     aWinSize.Width()  -= 2 * aMarginSize.Width();
771     aWinSize.Height() -= 2 * aMarginSize.Height();
772 
773     Size aLocalPageSize = lcl_GetDocPageSize( pDocShell->GetDocument(), nTab );
774     if ( aLocalPageSize.Width() && aLocalPageSize.Height() )
775     {
776         long nZoomX = (long) ( aWinSize.Width() * 100  / ( aLocalPageSize.Width() * nWinScaleX ));
777         long nZoomY = (long) ( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));
778 
779         long nOptimal = nZoomX;
780         if (!bWidthOnly && nZoomY<nOptimal)
781             nOptimal = nZoomY;
782 
783         if (nOptimal<20)
784             nOptimal = 20;
785         if (nOptimal>400)
786             nOptimal = 400;
787 
788         return (sal_uInt16) nOptimal;
789     }
790     else
791         return nZoom;
792 }
793 
794 
SetXOffset(long nX)795 void ScPreview::SetXOffset( long nX )
796 {
797     if ( aOffset.X() == nX )
798         return;
799 
800     if (bValid)
801     {
802         long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
803         aOffset.X() = nX;
804         if (nDif && !bInSetZoom)
805         {
806             MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
807             Scroll( nDif, 0 );
808             SetMapMode(aOldMode);
809         }
810     }
811     else
812     {
813         aOffset.X() = nX;
814         if (!bInSetZoom)
815             Invalidate();
816     }
817     InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
818     Paint(Rectangle());
819 }
820 
821 
SetYOffset(long nY)822 void ScPreview::SetYOffset( long nY )
823 {
824     if ( aOffset.Y() == nY )
825         return;
826 
827     if (bValid)
828     {
829         long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
830         aOffset.Y() = nY;
831         if (nDif && !bInSetZoom)
832         {
833             MapMode aOldMode = GetMapMode(); SetMapMode(MAP_PIXEL);
834             Scroll( 0, nDif );
835             SetMapMode(aOldMode);
836         }
837     }
838     else
839     {
840         aOffset.Y() = nY;
841         if (!bInSetZoom)
842             Invalidate();
843     }
844     InvalidateLocationData( SC_HINT_ACC_VISAREACHANGED );
845     Paint(Rectangle());
846 }
847 
848 
DoInvalidate()849 void ScPreview::DoInvalidate()
850 {
851     // Wenn das ganze aus dem GetState der Shell gerufen wird,
852     // muss das Invalidate hinterher asynchron kommen...
853 
854     if (bInGetState)
855         Application::PostUserEvent( STATIC_LINK( this, ScPreview, InvalidateHdl ) );
856     else
857         StaticInvalidate();     // sofort
858 }
859 
StaticInvalidate()860 void ScPreview::StaticInvalidate()
861 {
862     // static method, because it's called asynchronously
863     // -> must use current viewframe
864 
865     SfxViewFrame* pViewFrm = SfxViewFrame::Current();
866     if (!pViewFrm)
867         return;
868 
869     SfxBindings& rBindings = pViewFrm->GetBindings();
870     rBindings.Invalidate(SID_STATUS_DOCPOS);
871     rBindings.Invalidate(SID_STATUS_PAGESTYLE);
872     rBindings.Invalidate(SID_PREVIEW_PREVIOUS);
873     rBindings.Invalidate(SID_PREVIEW_NEXT);
874     rBindings.Invalidate(SID_PREVIEW_FIRST);
875     rBindings.Invalidate(SID_PREVIEW_LAST);
876     rBindings.Invalidate(SID_ATTR_ZOOM);
877     rBindings.Invalidate(SID_PREVIEW_ZOOMIN);
878     rBindings.Invalidate(SID_PREVIEW_ZOOMOUT);
879     rBindings.Invalidate(SID_PREVIEW_SCALINGFACTOR);
880     rBindings.Invalidate(SID_ATTR_ZOOMSLIDER);
881 }
882 
IMPL_STATIC_LINK(ScPreview,InvalidateHdl,void *,EMPTYARG)883 IMPL_STATIC_LINK( ScPreview, InvalidateHdl, void*, EMPTYARG )
884 {
885     (void)pThis; // avoid warning
886 
887     StaticInvalidate();
888     return 0;
889 }
890 
DataChanged(const DataChangedEvent & rDCEvt)891 void ScPreview::DataChanged( const DataChangedEvent& rDCEvt )
892 {
893     Window::DataChanged(rDCEvt);
894 
895     if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
896          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
897          (rDCEvt.GetType() == DATACHANGED_FONTS) ||
898          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
899          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
900           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
901     {
902         if ( rDCEvt.GetType() == DATACHANGED_FONTS )
903             pDocShell->UpdateFontList();
904 
905         // #i114518# Paint of form controls may modify the window's settings.
906         // Ignore the event if it is called from within Paint.
907         if ( !bInPaint )
908         {
909             if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
910                 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
911             {
912                 // scroll bar size may have changed
913                 pViewShell->InvalidateBorder(); // calls OuterResizePixel
914             }
915 
916             Invalidate();
917             InvalidateLocationData( SC_HINT_DATACHANGED );
918         }
919     }
920 }
921 
922 // Issue51656 Add resizeable margin on page preview from maoyg
MouseButtonDown(const MouseEvent & rMEvt)923 void __EXPORT ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
924 {
925     Fraction  aPreviewZoom( nZoom, 100 );
926     Fraction  aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
927     MapMode   aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
928 
929     aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
930     aButtonDownPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
931 
932     CaptureMouse();
933 
934     if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
935     {
936         SetMapMode( aMMMode );
937         if( bLeftRulerChange )
938         {
939             DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
940             bLeftRulerMove = sal_True;
941             bRightRulerMove = sal_False;
942         }
943         else if( bRightRulerChange )
944         {
945             DrawInvert( aButtonDownChangePoint.X(), POINTER_HSIZEBAR );
946             bLeftRulerMove = sal_False;
947             bRightRulerMove = sal_True;
948         }
949     }
950 
951     if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
952     {
953         SetMapMode( aMMMode );
954         if( bTopRulerChange )
955         {
956             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
957             bTopRulerMove = sal_True;
958             bBottomRulerMove = sal_False;
959         }
960         else if( bBottomRulerChange )
961         {
962             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
963             bTopRulerMove = sal_False;
964             bBottomRulerMove = sal_True;
965         }
966         else if( bHeaderRulerChange )
967         {
968             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
969             bHeaderRulerMove = sal_True;
970             bFooterRulerMove = sal_False;
971         }
972         else if( bFooterRulerChange )
973         {
974             DrawInvert( aButtonDownChangePoint.Y(), POINTER_VSIZEBAR );
975             bHeaderRulerMove = sal_False;
976             bFooterRulerMove = sal_True;
977         }
978     }
979 
980     if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
981     {
982         Point  aNowPt = rMEvt.GetPosPixel();
983         SCCOL i = 0;
984         for( i = aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
985         {
986             if( aNowPt.X() < nRight[i] + 2 && aNowPt.X() > nRight[i] - 2 )
987             {
988                 nColNumberButttonDown = i;
989                 break;
990             }
991         }
992         if( i == aPageArea.aEnd.Col()+1 )
993             return;
994 
995         SetMapMode( aMMMode );
996         if( nColNumberButttonDown == aPageArea.aStart.Col() )
997             DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
998         else
999             DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1000 
1001         DrawInvert( aButtonDownChangePoint.X(), POINTER_HSPLIT );
1002         bColRulerMove = sal_True;
1003     }
1004 }
1005 
MouseButtonUp(const MouseEvent & rMEvt)1006 void __EXPORT ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
1007 {
1008         Fraction  aPreviewZoom( nZoom, 100 );
1009         Fraction  aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1010         MapMode   aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1011 
1012         aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
1013 
1014         long  nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
1015         long  nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
1016 
1017         if( rMEvt.IsLeft() && GetPointer() == POINTER_HSIZEBAR )
1018         {
1019             SetPointer( Pointer( POINTER_ARROW ) );
1020 
1021             sal_Bool bMoveRulerAction= sal_True;
1022 
1023             ScDocument * pDoc = pDocShell->GetDocument();
1024             String   aOldName = pDoc->GetPageStyle( nTab );
1025             sal_Bool  bUndo( pDoc->IsUndoEnabled() );
1026             ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
1027             SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1028 
1029             if ( pStyleSheet )
1030             {
1031                 ScStyleSaveData aOldData;
1032                 if( bUndo )
1033                     aOldData.InitFromStyle( pStyleSheet );
1034 
1035                 SfxItemSet&  rStyleSet = pStyleSheet->GetItemSet();
1036 
1037                 SvxLRSpaceItem aLRItem = ( const SvxLRSpaceItem& ) rStyleSet.Get( ATTR_LRSPACE );
1038 
1039                 if(( bLeftRulerChange || bRightRulerChange ) && ( aButtonUpPt.X() <= ( 0 - aOffset.X() ) || aButtonUpPt.X() > nWidth * HMM_PER_TWIPS - aOffset.X() ) )
1040                 {
1041                     bMoveRulerAction = sal_False;
1042                     Paint(Rectangle(0,0,10000,10000));
1043                 }
1044                 else if( bLeftRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS > nWidth - aLRItem.GetRight() - aOffset.X() / HMM_PER_TWIPS ) )
1045                 {
1046                     bMoveRulerAction = sal_False;
1047                     Paint(Rectangle(0,0,10000,10000));
1048                 }
1049                 else if( bRightRulerChange && ( aButtonUpPt.X() / HMM_PER_TWIPS < aLRItem.GetLeft() - aOffset.X() / HMM_PER_TWIPS ) )
1050                 {
1051                     bMoveRulerAction = sal_False;
1052                     Paint(Rectangle(0,0,10000,10000));
1053                 }
1054                 else if( aButtonDownPt.X() == aButtonUpPt.X() )
1055                 {
1056                     bMoveRulerAction = sal_False;
1057                     DrawInvert( aButtonUpPt.X(), POINTER_HSIZEBAR );
1058                 }
1059                 if( bMoveRulerAction )
1060                 {
1061                     ScDocShellModificator aModificator( *pDocShell );
1062                     if( bLeftRulerChange && bLeftRulerMove )
1063                     {
1064                        aLRItem.SetLeft( (long)( aButtonUpPt.X() / HMM_PER_TWIPS + aOffset.X() / HMM_PER_TWIPS ));
1065                        rStyleSet.Put( aLRItem );
1066                     }
1067                     else if( bRightRulerChange && bRightRulerMove )
1068                     {
1069                         aLRItem.SetRight( (long)( nWidth - aButtonUpPt.X() / HMM_PER_TWIPS - aOffset.X() / HMM_PER_TWIPS ));
1070                         rStyleSet.Put( aLRItem );
1071                     }
1072 
1073                     ScStyleSaveData aNewData;
1074                     aNewData.InitFromStyle( pStyleSheet );
1075                     if( bUndo )
1076                     {
1077                         pDocShell->GetUndoManager()->AddUndoAction(
1078                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
1079                             aOldData, aNewData ) );
1080                     }
1081 
1082                     if ( ValidTab( nTab ) )
1083                     {
1084                         ScPrintFunc aPrintFunc( this, pDocShell, nTab );
1085                         aPrintFunc.UpdatePages();
1086                     }
1087 
1088                     Rectangle aRect(0,0,10000,10000);
1089                     Paint( aRect );
1090                     aModificator.SetDocumentModified();
1091                     bLeftRulerChange = sal_False;
1092                     bRightRulerChange = sal_False;
1093                 }
1094             }
1095             bLeftRulerMove = sal_False;
1096             bRightRulerMove = sal_False;
1097         }
1098 
1099         if( rMEvt.IsLeft() && GetPointer() == POINTER_VSIZEBAR )
1100         {
1101             SetPointer( POINTER_ARROW );
1102 
1103             sal_Bool  bMoveRulerAction = sal_True;
1104             if( ( bTopRulerChange || bBottomRulerChange || bHeaderRulerChange || bFooterRulerChange ) && ( aButtonUpPt.Y() <= ( 0 - aOffset.Y() ) || aButtonUpPt.Y() > nHeight * HMM_PER_TWIPS -aOffset.Y() ) )
1105             {
1106                 bMoveRulerAction = sal_False;
1107                 Paint( Rectangle(0,0,10000,10000) );
1108             }
1109             else if( aButtonDownPt.Y() == aButtonUpPt.Y() )
1110             {
1111                 bMoveRulerAction = sal_False;
1112                 DrawInvert( aButtonUpPt.Y(), POINTER_VSIZEBAR );
1113             }
1114             if( bMoveRulerAction )
1115             {
1116                 ScDocument * pDoc = pDocShell->GetDocument();
1117                 sal_Bool  bUndo( pDoc->IsUndoEnabled() );
1118                 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
1119                 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
1120                 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1121                 if ( pStyleSheet )
1122                 {
1123                     ScDocShellModificator aModificator( *pDocShell );
1124                     ScStyleSaveData aOldData;
1125                     if( bUndo )
1126                         aOldData.InitFromStyle( pStyleSheet );
1127 
1128                     SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1129 
1130                     SvxULSpaceItem aULItem = ( const SvxULSpaceItem&)rStyleSet.Get( ATTR_ULSPACE );
1131 
1132                     if( bTopRulerMove && bTopRulerChange )
1133                     {
1134                         aULItem.SetUpperValue( (sal_uInt16)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS ) );
1135                         rStyleSet.Put( aULItem );
1136                     }
1137                     else if( bBottomRulerMove && bBottomRulerChange )
1138                     {
1139                         aULItem.SetLowerValue( (sal_uInt16)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS ) );
1140                         rStyleSet.Put( aULItem );
1141                     }
1142                     else if( bHeaderRulerMove && bHeaderRulerChange )
1143                     {
1144                         const SfxPoolItem* pItem = NULL;
1145                         if ( rStyleSet.GetItemState( ATTR_PAGE_HEADERSET, sal_False, &pItem ) == SFX_ITEM_SET )
1146                         {
1147                             SfxItemSet& pHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
1148                             Size  aHeaderSize = ((const SvxSizeItem&)pHeaderSet.Get(ATTR_PAGE_SIZE)).GetSize();
1149                             aHeaderSize.Height() = (long)( aButtonUpPt.Y() / HMM_PER_TWIPS + aOffset.Y() / HMM_PER_TWIPS - aULItem.GetUpper());
1150                             aHeaderSize.Height() = aHeaderSize.Height() * 100 / mnScale;
1151                             SvxSetItem  aNewHeader( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_HEADERSET) );
1152                             aNewHeader.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aHeaderSize ) );
1153                             rStyleSet.Put( aNewHeader );
1154                         }
1155                     }
1156                     else if( bFooterRulerMove && bFooterRulerChange )
1157                     {
1158                         const SfxPoolItem* pItem = NULL;
1159                         if( rStyleSet.GetItemState( ATTR_PAGE_FOOTERSET, sal_False, &pItem ) == SFX_ITEM_SET )
1160                         {
1161                             SfxItemSet& pFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
1162                             Size aFooterSize = ((const SvxSizeItem&)pFooterSet.Get(ATTR_PAGE_SIZE)).GetSize();
1163                             aFooterSize.Height() = (long)( nHeight - aButtonUpPt.Y() / HMM_PER_TWIPS - aOffset.Y() / HMM_PER_TWIPS - aULItem.GetLower() );
1164                             aFooterSize.Height() = aFooterSize.Height() * 100 / mnScale;
1165                             SvxSetItem  aNewFooter( (const SvxSetItem&)rStyleSet.Get(ATTR_PAGE_FOOTERSET) );
1166                             aNewFooter.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aFooterSize ) );
1167                             rStyleSet.Put( aNewFooter );
1168                         }
1169                     }
1170 
1171                     ScStyleSaveData aNewData;
1172                     aNewData.InitFromStyle( pStyleSheet );
1173                     if( bUndo )
1174                     {
1175                         pDocShell->GetUndoManager()->AddUndoAction(
1176                             new ScUndoModifyStyle( pDocShell, SFX_STYLE_FAMILY_PAGE,
1177                             aOldData, aNewData ) );
1178                     }
1179 
1180                     if ( ValidTab( nTab ) )
1181                     {
1182                         ScPrintFunc aPrintFunc( this, pDocShell, nTab );
1183                         aPrintFunc.UpdatePages();
1184                     }
1185 
1186                     Rectangle  aRect(0,0,10000,10000);
1187                     Paint( aRect );
1188                     aModificator.SetDocumentModified();
1189                     bTopRulerChange = sal_False;
1190                     bBottomRulerChange = sal_False;
1191                     bHeaderRulerChange = sal_False;
1192                     bFooterRulerChange = sal_False;
1193                 }
1194             }
1195             bTopRulerMove = sal_False;
1196             bBottomRulerMove = sal_False;
1197             bHeaderRulerMove = sal_False;
1198             bFooterRulerMove = sal_False;
1199         }
1200         if( rMEvt.IsLeft() && GetPointer() == POINTER_HSPLIT )
1201         {
1202             SetPointer(POINTER_ARROW);
1203             ScDocument* pDoc = pDocShell->GetDocument();
1204             sal_Bool  bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1205             sal_Bool  bMoveRulerAction = sal_True;
1206             if( aButtonDownPt.X() == aButtonUpPt.X() )
1207             {
1208                 bMoveRulerAction = sal_False;
1209                 if( nColNumberButttonDown == aPageArea.aStart.Col() )
1210                     DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1211                 else
1212                     DrawInvert( PixelToLogic( Point( nRight[ nColNumberButttonDown-1 ], 0 ),aMMMode ).X() ,POINTER_HSPLIT );
1213                 DrawInvert( aButtonUpPt.X(), POINTER_HSPLIT );
1214             }
1215             if( bMoveRulerAction )
1216             {
1217                 long  nNewColWidth = 0;
1218                 ScDocFunc aFunc(*pDocShell);
1219                 SCCOLROW nCols[2] = { nColNumberButttonDown, nColNumberButttonDown };
1220 
1221                 if( !bLayoutRTL )
1222                 {
1223                     nNewColWidth = (long) ( PixelToLogic( Point( rMEvt.GetPosPixel().X() - nRight[ nColNumberButttonDown ], 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
1224                     nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
1225                 }
1226                 else
1227                 {
1228 
1229                     nNewColWidth = (long) ( PixelToLogic( Point( nRight[ nColNumberButttonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X() / HMM_PER_TWIPS ) * 100 / mnScale;
1230                     nNewColWidth += pDocShell->GetDocument()->GetColWidth( nColNumberButttonDown, nTab );
1231                 }
1232 
1233                 if( nNewColWidth >= 0 )
1234                 {
1235                     aFunc.SetWidthOrHeight( sal_True, 1,nCols, nTab, SC_SIZE_DIRECT, (sal_uInt16)nNewColWidth, sal_True, sal_True);
1236                 }
1237                 if ( ValidTab( nTab ) )
1238                 {
1239                     ScPrintFunc aPrintFunc( this, pDocShell, nTab );
1240                     aPrintFunc.UpdatePages();
1241                 }
1242                 Rectangle  nRect(0,0,10000,10000);
1243                 Paint( nRect );
1244             }
1245             bColRulerMove = sal_False;
1246         }
1247         ReleaseMouse();
1248 }
1249 
MouseMove(const MouseEvent & rMEvt)1250 void __EXPORT ScPreview::MouseMove( const MouseEvent& rMEvt )
1251 {
1252     Fraction aPreviewZoom( nZoom, 100 );
1253     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1254     MapMode  aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1255     Point    aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode );
1256 
1257     long    nLeftMargin = 0;
1258     long    nRightMargin = 0;
1259     long    nTopMargin = 0;
1260     long    nBottomMargin = 0;
1261     Size    PageSize;
1262 
1263     long    nWidth = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Width();
1264     long    nHeight = (long) lcl_GetDocPageSize(pDocShell->GetDocument(), nTab).Height();
1265 
1266     if ( nPageNo < nTotalPages )
1267     {
1268         ScPrintOptions aOptions = SC_MOD()->GetPrintOptions();
1269 
1270         ScPrintFunc* pPrintFunc;
1271 
1272         if (bStateValid)
1273             pPrintFunc = new ScPrintFunc( this, pDocShell, aState, &aOptions );
1274         else
1275             pPrintFunc = new ScPrintFunc( this, pDocShell, nTab, nFirstAttr[nTab], nTotalPages, NULL, &aOptions );
1276 
1277         nLeftMargin = (long)( pPrintFunc->GetLeftMargin() * HMM_PER_TWIPS - aOffset.X() );
1278         nRightMargin = (long)( pPrintFunc->GetRightMargin() * HMM_PER_TWIPS );
1279         nRightMargin = (long)( nWidth * HMM_PER_TWIPS - nRightMargin - aOffset.X() );
1280         nTopMargin = (long)( pPrintFunc->GetTopMargin() * HMM_PER_TWIPS - aOffset.Y() );
1281         nBottomMargin = (long)( pPrintFunc->GetBottomMargin() * HMM_PER_TWIPS );
1282         nBottomMargin = (long)( nHeight * HMM_PER_TWIPS - nBottomMargin - aOffset.Y() );
1283         if( mnScale > 0 )
1284         {
1285             nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS * mnScale / 100 );
1286             nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS * mnScale / 100 );
1287         }
1288         else
1289         {
1290             nHeaderHeight = (long)( nTopMargin + pPrintFunc->GetHeader().nHeight * HMM_PER_TWIPS );
1291             nFooterHeight = (long)( nBottomMargin - pPrintFunc->GetFooter().nHeight * HMM_PER_TWIPS );
1292         }
1293         delete pPrintFunc;
1294     }
1295 
1296     Point   aPixPt( rMEvt.GetPosPixel() );
1297     Point   aLeftTop = LogicToPixel( Point( nLeftMargin, -aOffset.Y() ) , aMMMode );
1298     Point   aLeftBottom = LogicToPixel( Point( nLeftMargin ,(long)(nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
1299     Point   aRightTop = LogicToPixel( Point( nRightMargin, -aOffset.Y() ), aMMMode );
1300     Point   aTopLeft = LogicToPixel( Point( -aOffset.X(), nTopMargin ), aMMMode );
1301     Point   aTopRight = LogicToPixel( Point( (long)(nWidth * HMM_PER_TWIPS - aOffset.X()), nTopMargin ), aMMMode );
1302     Point   aBottomLeft = LogicToPixel( Point( -aOffset.X(), nBottomMargin ), aMMMode );
1303     Point   aHeaderLeft = LogicToPixel( Point( -aOffset.X(), nHeaderHeight ), aMMMode );
1304     Point   aFooderLeft = LogicToPixel( Point( -aOffset.X(), nFooterHeight ), aMMMode );
1305 
1306     sal_Bool   bOnColRulerChange = sal_False;
1307 
1308     for( SCCOL i=aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
1309     {
1310         Point   aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
1311         Point   aColumnBottom = LogicToPixel( Point( 0, (long)( nHeight * HMM_PER_TWIPS - aOffset.Y()) ), aMMMode );
1312         if( aPixPt.X() < ( nRight[i] + 2 ) && ( aPixPt.X() > ( nRight[i] - 2 ) ) && ( aPixPt.X() < aRightTop.X() ) && ( aPixPt.X() > aLeftTop.X() )
1313             && ( aPixPt.Y() > aColumnTop.Y() ) && ( aPixPt.Y() < aColumnBottom.Y() ) && !bLeftRulerMove && !bRightRulerMove
1314             && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1315         {
1316             bOnColRulerChange = sal_True;
1317             if( !rMEvt.GetButtons() && GetPointer() == POINTER_HSPLIT )
1318                 nColNumberButttonDown = i;
1319             break;
1320         }
1321     }
1322 
1323     if( aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 ) && !bRightRulerMove )
1324     {
1325         bLeftRulerChange = sal_True;
1326         bRightRulerChange = sal_False;
1327     }
1328     else if( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) && !bLeftRulerMove )
1329     {
1330         bLeftRulerChange = sal_False;
1331         bRightRulerChange = sal_True;
1332     }
1333     else if( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1334     {
1335         bTopRulerChange = sal_True;
1336         bBottomRulerChange = sal_False;
1337         bHeaderRulerChange = sal_False;
1338         bFooterRulerChange = sal_False;
1339     }
1340     else if( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) && !bTopRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1341     {
1342         bTopRulerChange = sal_False;
1343         bBottomRulerChange = sal_True;
1344         bHeaderRulerChange = sal_False;
1345         bFooterRulerChange = sal_False;
1346     }
1347     else if( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bFooterRulerMove )
1348     {
1349         bTopRulerChange = sal_False;
1350         bBottomRulerChange = sal_False;
1351         bHeaderRulerChange = sal_True;
1352         bFooterRulerChange = sal_False;
1353     }
1354     else if( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove )
1355     {
1356         bTopRulerChange = sal_False;
1357         bBottomRulerChange = sal_False;
1358         bHeaderRulerChange = sal_False;
1359         bFooterRulerChange = sal_True;
1360     }
1361 
1362     if( bPageMargin )
1363     {
1364         if(( (aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 )) || bLeftRulerMove ||
1365             ( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) ) || bRightRulerMove || bOnColRulerChange || bColRulerMove )
1366             && aPixPt.Y() > aLeftTop.Y() && aPixPt.Y() < aLeftBottom.Y() )
1367         {
1368             if( bOnColRulerChange || bColRulerMove )
1369             {
1370                 SetPointer( Pointer( POINTER_HSPLIT ) );
1371                 if( bColRulerMove )
1372                 {
1373                     if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1374                         DragMove( aMouseMovePoint.X(), POINTER_HSPLIT );
1375                 }
1376             }
1377             else
1378             {
1379                 if( bLeftRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1380                 {
1381                     SetPointer( Pointer( POINTER_HSIZEBAR ) );
1382                     if( bLeftRulerMove )
1383                     {
1384                        if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1385                            DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
1386                     }
1387                 }
1388                 else if( bRightRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1389                 {
1390                     SetPointer( Pointer( POINTER_HSIZEBAR ) );
1391                     if( bRightRulerMove )
1392                     {
1393                        if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < nWidth * HMM_PER_TWIPS - aOffset.X() )
1394                            DragMove( aMouseMovePoint.X(), POINTER_HSIZEBAR );
1395                     }
1396                 }
1397             }
1398         }
1399         else
1400         {
1401             if( ( ( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) ) || bTopRulerMove ||
1402                 ( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) ) || bBottomRulerMove ||
1403                 ( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) ) || bHeaderRulerMove ||
1404                 ( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) ) || bFooterRulerMove )
1405                 && aPixPt.X() > aTopLeft.X() && aPixPt.X() < aTopRight.X() )
1406             {
1407                 if( bTopRulerChange )
1408                 {
1409                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
1410                     if( bTopRulerMove )
1411                     {
1412                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1413                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1414                     }
1415                 }
1416                 else if( bBottomRulerChange )
1417                 {
1418                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
1419                     if( bBottomRulerMove )
1420                     {
1421                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1422                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1423                     }
1424                 }
1425                 else if( bHeaderRulerChange )
1426                 {
1427                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
1428                     if( bHeaderRulerMove )
1429                     {
1430                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1431                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1432                     }
1433                 }
1434                 else if( bFooterRulerChange )
1435                 {
1436                     SetPointer( Pointer( POINTER_VSIZEBAR ) );
1437                     if( bFooterRulerMove )
1438                     {
1439                         if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < nHeight * HMM_PER_TWIPS - aOffset.Y() )
1440                             DragMove( aMouseMovePoint.Y(), POINTER_VSIZEBAR );
1441                     }
1442                 }
1443             }
1444             else
1445                 SetPointer( Pointer( POINTER_ARROW ) );
1446         }
1447     }
1448 }
1449 // Issue51656 Add resizeable margin on page preview from maoyg
InvalidateLocationData(sal_uLong nId)1450 void ScPreview::InvalidateLocationData(sal_uLong nId)
1451 {
1452     bLocationValid = sal_False;
1453     if (pViewShell->HasAccessibilityObjects())
1454         pViewShell->BroadcastAccessibility( SfxSimpleHint( nId ) );
1455 }
1456 
GetFocus()1457 void ScPreview::GetFocus()
1458 {
1459     if (pViewShell->HasAccessibilityObjects())
1460         pViewShell->BroadcastAccessibility( ScAccWinFocusGotHint(GetAccessible()) );
1461 }
1462 
LoseFocus()1463 void ScPreview::LoseFocus()
1464 {
1465     if (pViewShell->HasAccessibilityObjects())
1466         pViewShell->BroadcastAccessibility( ScAccWinFocusLostHint(GetAccessible()) );
1467 }
1468 
CreateAccessible()1469 com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessible> ScPreview::CreateAccessible()
1470 {
1471     com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessible> xAcc= GetAccessible(sal_False);
1472     if (xAcc.is())
1473     {
1474         return xAcc;
1475     }
1476     ScAccessibleDocumentPagePreview* pAccessible =
1477         new ScAccessibleDocumentPagePreview( GetAccessibleParentWindow()->GetAccessible(), pViewShell );
1478     xAcc = pAccessible;
1479     SetAccessible(xAcc);
1480     pAccessible->Init();
1481     return xAcc;
1482 }
1483 // MT: Removed Windows::SwitchView() introduced with IA2 CWS.
1484 // There are other notifications for this when the active view has changed, so please update the code to use that event mechanism
SwitchView()1485 void ScPreview::SwitchView()
1486 {
1487     if (!Application::IsAccessibilityEnabled())
1488     {
1489         return ;
1490     }
1491     ScAccessibleDocumentBase* pAccDoc = static_cast<ScAccessibleDocumentBase*>(GetAccessible(sal_False).get());
1492     if (pAccDoc)
1493     {
1494         pAccDoc->SwitchViewFireFocus();
1495     }
1496 }
1497 // Issue51656 Add resizeable margin on page preview from maoyg
DragMove(long nDragMovePos,sal_uInt16 nFlags)1498 void ScPreview::DragMove( long nDragMovePos, sal_uInt16 nFlags )
1499 {
1500     Fraction aPreviewZoom( nZoom, 100 );
1501     Fraction aHorPrevZoom( (long)( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1502     MapMode  aMMMode( MAP_100TH_MM, Point(), aHorPrevZoom, aPreviewZoom );
1503     SetMapMode( aMMMode );
1504     long  nPos = nDragMovePos;
1505     if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
1506     {
1507         if( nDragMovePos != aButtonDownChangePoint.X() )
1508         {
1509             DrawInvert( aButtonDownChangePoint.X(), nFlags );
1510             aButtonDownChangePoint.X() = nPos;
1511             DrawInvert( aButtonDownChangePoint.X(), nFlags );
1512         }
1513     }
1514     else if( nFlags == POINTER_VSIZEBAR )
1515     {
1516         if( nDragMovePos != aButtonDownChangePoint.Y() )
1517         {
1518             DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1519             aButtonDownChangePoint.Y() = nPos;
1520             DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1521         }
1522     }
1523 }
1524 
DrawInvert(long nDragPos,sal_uInt16 nFlags)1525 void ScPreview::DrawInvert( long nDragPos, sal_uInt16 nFlags )
1526 {
1527     long  nHeight = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Height();
1528     long  nWidth = (long) lcl_GetDocPageSize( pDocShell->GetDocument(), nTab ).Width();
1529     if( nFlags == POINTER_HSIZEBAR || nFlags == POINTER_HSPLIT )
1530     {
1531         Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1,(long)( ( nHeight * HMM_PER_TWIPS ) - aOffset.Y()));
1532         Invert( aRect,INVERT_50 );
1533     }
1534     else if( nFlags == POINTER_VSIZEBAR )
1535     {
1536         Rectangle aRect( -aOffset.X(), nDragPos,(long)( ( nWidth * HMM_PER_TWIPS ) - aOffset.X() ), nDragPos + 1 );
1537         Invert( aRect,INVERT_50 );
1538     }
1539 }
1540 // Issue51656 Add resizeable margin on page preview from maoyg
1541 
1542 /* vim: set noet sw=4 ts=4: */
1543