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