Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sfx2/objface.hxx>
21 : #include <vcl/timer.hxx>
22 : #include <vcl/field.hxx>
23 : #include <vcl/fixed.hxx>
24 : #include <vcl/help.hxx>
25 : #include <vcl/cmdevt.hxx>
26 : #include <vcl/button.hxx>
27 : #include <vcl/settings.hxx>
28 :
29 : #include <svl/whiter.hxx>
30 : #include <svl/stritem.hxx>
31 : #include <svl/eitem.hxx>
32 : #include <sfx2/printer.hxx>
33 : #include <sfx2/progress.hxx>
34 : #include <sfx2/app.hxx>
35 : #include <sfx2/bindings.hxx>
36 : #include <sfx2/request.hxx>
37 : #include <sfx2/dispatch.hxx>
38 : #include <vcl/msgbox.hxx>
39 : #include <svx/stddlg.hxx>
40 : #include <editeng/paperinf.hxx>
41 : #include <svl/srchitem.hxx>
42 : #include <svx/svdview.hxx>
43 : #include <svx/dlgutil.hxx>
44 : #include <svx/zoomslideritem.hxx>
45 : #include <svx/svxids.hrc>
46 :
47 : #include <swwait.hxx>
48 : #include <globdoc.hxx>
49 : #include <wdocsh.hxx>
50 : #include <pvprtdat.hxx>
51 : #include <swmodule.hxx>
52 : #include <modcfg.hxx>
53 : #include <wrtsh.hxx>
54 : #include <docsh.hxx>
55 : #include <viewopt.hxx>
56 : #include <doc.hxx>
57 : #include <IDocumentDeviceAccess.hxx>
58 : #include <pview.hxx>
59 : #include <view.hxx>
60 : #include <textsh.hxx>
61 : #include <scroll.hxx>
62 : #include <prtopt.hxx>
63 : #include <docstat.hxx>
64 : #include <usrpref.hxx>
65 : #include <viewfunc.hxx>
66 :
67 : #include <helpid.h>
68 : #include <cmdid.h>
69 : #include <globals.hrc>
70 : #include <popup.hrc>
71 : #include <view.hrc>
72 :
73 : #define SwPagePreview
74 : #include <sfx2/msg.hxx>
75 : #include <swslots.hxx>
76 : #include <pagepreviewlayout.hxx>
77 :
78 : #include <svx/svxdlg.hxx>
79 : #include <svx/dialogs.hrc>
80 : #include <osl/mutex.hxx>
81 :
82 : #include <boost/scoped_ptr.hpp>
83 :
84 : using namespace ::com::sun::star;
85 180 : SFX_IMPL_NAMED_VIEWFACTORY(SwPagePreview, "PrintPreview")
86 : {
87 90 : SFX_VIEW_REGISTRATION(SwDocShell);
88 90 : SFX_VIEW_REGISTRATION(SwWebDocShell);
89 90 : SFX_VIEW_REGISTRATION(SwGlobalDocShell);
90 90 : }
91 :
92 360 : SFX_IMPL_INTERFACE(SwPagePreview, SfxViewShell, SW_RES(RID_PVIEW_TOOLBOX))
93 :
94 90 : void SwPagePreview::InitInterface_Impl()
95 : {
96 90 : GetStaticInterface()->RegisterPopupMenu(SW_RES(MN_PPREVIEW_POPUPMENU));
97 :
98 : GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_CLIENT|SFX_VISIBILITY_FULLSCREEN|SFX_VISIBILITY_READONLYDOC,
99 90 : SW_RES(RID_PVIEW_TOOLBOX));
100 90 : }
101 :
102 1240 : TYPEINIT1(SwPagePreview,SfxViewShell)
103 :
104 : #define SWVIEWFLAGS ( SFX_VIEW_CAN_PRINT|SFX_VIEW_HAS_PRINTOPTIONS )
105 :
106 : #define MIN_PREVIEW_ZOOM 25
107 : #define MAX_PREVIEW_ZOOM 600
108 :
109 0 : static sal_uInt16 lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom, bool bZoomIn)
110 : {
111 : static const sal_uInt16 aZoomArr[] =
112 : {
113 : 25, 50, 75, 100, 150, 200, 400, 600
114 : };
115 0 : const int nZoomArrSize = static_cast<int>(SAL_N_ELEMENTS(aZoomArr));
116 0 : if (bZoomIn)
117 : {
118 0 : for(int i = nZoomArrSize - 1; i >= 0; --i)
119 : {
120 0 : if(nCurrentZoom > aZoomArr[i] || !i)
121 0 : return aZoomArr[i];
122 : }
123 : }
124 : else
125 : {
126 0 : for(int i = 0; i < nZoomArrSize; ++i)
127 : {
128 0 : if(nCurrentZoom < aZoomArr[i])
129 0 : return aZoomArr[i];
130 : }
131 : }
132 0 : return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM;
133 : };
134 :
135 0 : static void lcl_InvalidateZoomSlots(SfxBindings& rBindings)
136 : {
137 : static sal_uInt16 const aInval[] =
138 : {
139 : SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, FN_PREVIEW_ZOOM, FN_STAT_ZOOM,
140 : 0
141 : };
142 0 : rBindings.Invalidate( aInval );
143 0 : }
144 :
145 : // At first the zoom dialog
146 0 : class SwPreviewZoomDlg : public SvxStandardDialog
147 : {
148 : NumericField* m_pRowEdit;
149 : NumericField* m_pColEdit;
150 :
151 : virtual void Apply() SAL_OVERRIDE;
152 :
153 : public:
154 : SwPreviewZoomDlg( SwPagePreviewWin& rParent );
155 : };
156 :
157 0 : SwPreviewZoomDlg::SwPreviewZoomDlg( SwPagePreviewWin& rParent )
158 0 : : SvxStandardDialog(&rParent, "PreviewZoomDialog", "modules/swriter/ui/previewzoomdialog.ui")
159 : {
160 0 : get(m_pRowEdit, "rows");
161 0 : get(m_pColEdit, "cols");
162 :
163 0 : m_pRowEdit->SetValue( rParent.GetRow() );
164 0 : m_pColEdit->SetValue( rParent.GetCol() );
165 0 : }
166 :
167 0 : void SwPreviewZoomDlg::Apply()
168 : {
169 0 : ((SwPagePreviewWin*)GetParent())->CalcWish(
170 0 : sal_uInt8(m_pRowEdit->GetValue()),
171 0 : sal_uInt8(m_pColEdit->GetValue()) );
172 0 : }
173 :
174 : // all for SwPagePreviewWin
175 0 : SwPagePreviewWin::SwPagePreviewWin( vcl::Window *pParent, SwPagePreview& rPView )
176 : : Window(pParent, WinBits(WB_CLIPCHILDREN))
177 : , mpViewShell(0)
178 : , mrView(rPView)
179 : , mbCalcScaleForPreviewLayout(true)
180 : , maPaintedPreviewDocRect(Rectangle(0,0,0,0))
181 0 : , mpPgPreviewLayout(NULL)
182 : {
183 0 : SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW );
184 0 : SetHelpId(HID_PAGEPREVIEW);
185 0 : SetFillColor( GetBackground().GetColor() );
186 0 : SetLineColor( GetBackground().GetColor());
187 0 : SetMapMode( MapMode(MAP_TWIP) );
188 :
189 0 : const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(false);
190 0 : mnRow = pUsrPref->GetPagePrevRow(); // 1 row
191 0 : mnCol = pUsrPref->GetPagePrevCol(); // 1 column
192 0 : mnSttPage = USHRT_MAX;
193 0 : }
194 :
195 0 : SwPagePreviewWin::~SwPagePreviewWin()
196 : {
197 0 : }
198 :
199 0 : void SwPagePreviewWin::Paint( const Rectangle& rRect )
200 : {
201 0 : if( !mpViewShell || !mpViewShell->GetLayout() )
202 0 : return;
203 :
204 0 : if( USHRT_MAX == mnSttPage ) // was never calculated ? (Init-Phase!)
205 : {
206 : // This is the size to which I always relate.
207 0 : if( !maPxWinSize.Height() || !maPxWinSize.Width() )
208 0 : maPxWinSize = GetOutputSizePixel();
209 :
210 0 : Rectangle aRect( LogicToPixel( rRect ));
211 : mpPgPreviewLayout->Prepare( 1, Point(0,0), maPxWinSize,
212 0 : mnSttPage, maPaintedPreviewDocRect );
213 0 : SetSelectedPage( 1 );
214 0 : mpPgPreviewLayout->Paint( PixelToLogic( aRect ) );
215 0 : SetPagePreview(mnRow, mnCol);
216 : }
217 : else
218 : {
219 0 : MapMode aMM( GetMapMode() );
220 0 : aMM.SetScaleX( maScale );
221 0 : aMM.SetScaleY( maScale );
222 0 : SetMapMode( aMM );
223 0 : mpPgPreviewLayout->Paint( rRect );
224 : }
225 : }
226 :
227 0 : void SwPagePreviewWin::CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol )
228 : {
229 0 : if( !mpViewShell || !mpViewShell->GetLayout() )
230 0 : return;
231 :
232 0 : const sal_uInt8 nOldCol = mnCol;
233 0 : mnRow = nNewRow;
234 0 : mnCol = nNewCol;
235 0 : const sal_uInt16 nPages = mnRow * mnCol;
236 0 : const sal_uInt16 nLastSttPg = mrView.GetPageCount()+1 > nPages
237 0 : ? mrView.GetPageCount()+1 - nPages : 0;
238 0 : if( mnSttPage > nLastSttPg )
239 0 : mnSttPage = nLastSttPg;
240 :
241 0 : mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize, true );
242 : mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
243 0 : mnSttPage, maPaintedPreviewDocRect );
244 0 : SetSelectedPage( mnSttPage );
245 0 : SetPagePreview(mnRow, mnCol);
246 0 : maScale = GetMapMode().GetScaleX();
247 :
248 : // If changes have taken place at the columns, the special case "single column"
249 : // must be considered and corrected if necessary.
250 0 : if( (1 == nOldCol) != (1 == mnCol) )
251 0 : mrView.ScrollDocSzChg();
252 :
253 : // Order must be maintained!
254 : // additional invalidate page status.
255 : static sal_uInt16 aInval[] =
256 : {
257 : SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN,
258 : FN_PREVIEW_ZOOM,
259 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
260 : FN_STAT_PAGE, FN_STAT_ZOOM,
261 : FN_SHOW_TWO_PAGES, FN_SHOW_MULTIPLE_PAGES,
262 : 0
263 : };
264 0 : SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
265 0 : rBindings.Invalidate( aInval );
266 0 : rBindings.Update( FN_SHOW_TWO_PAGES );
267 0 : rBindings.Update( FN_SHOW_MULTIPLE_PAGES );
268 : // adjust scrollbars
269 0 : mrView.ScrollViewSzChg();
270 : }
271 :
272 : // mnSttPage is Absolute
273 0 : int SwPagePreviewWin::MovePage( int eMoveMode )
274 : {
275 : // number of pages up
276 0 : const sal_uInt16 nPages = mnRow * mnCol;
277 0 : sal_uInt16 nNewSttPage = mnSttPage;
278 0 : const sal_uInt16 nPageCount = mrView.GetPageCount();
279 0 : const sal_uInt16 nDefSttPg = GetDefSttPage();
280 0 : bool bPaintPageAtFirstCol = true;
281 :
282 0 : switch( eMoveMode )
283 : {
284 : case MV_PAGE_UP:
285 : {
286 0 : const sal_uInt16 nRelSttPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
287 0 : const sal_uInt16 nNewAbsSttPage = nRelSttPage - nPages > 0 ?
288 0 : mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage - nPages ) :
289 0 : nDefSttPg;
290 0 : nNewSttPage = nNewAbsSttPage;
291 :
292 0 : const sal_uInt16 nRelSelPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
293 0 : const sal_uInt16 nNewRelSelPage = nRelSelPage - nPages > 0 ?
294 : nRelSelPage - nPages :
295 0 : 1;
296 0 : SetSelectedPage( mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nNewRelSelPage ) );
297 :
298 0 : break;
299 : }
300 : case MV_PAGE_DOWN:
301 : {
302 0 : const sal_uInt16 nRelSttPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
303 0 : const sal_uInt16 nNewAbsSttPage = mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage + nPages );
304 0 : nNewSttPage = std::min(nNewAbsSttPage, nPageCount);
305 :
306 0 : const sal_uInt16 nRelSelPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
307 0 : const sal_uInt16 nNewAbsSelPage = mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSelPage + nPages );
308 0 : SetSelectedPage( std::min(nNewAbsSelPage, nPageCount) );
309 :
310 0 : break;
311 : }
312 : case MV_DOC_STT:
313 0 : nNewSttPage = nDefSttPg;
314 0 : SetSelectedPage( mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nNewSttPage ? nNewSttPage : 1 ) );
315 0 : break;
316 : case MV_DOC_END:
317 : // correct calculation of new start page.
318 0 : nNewSttPage = nPageCount;
319 0 : SetSelectedPage( nPageCount );
320 0 : break;
321 : case MV_SELPAGE:
322 : // <nNewSttPage> and <SelectedPage()> are already set.
323 : // not start at first column, only if the
324 : // complete preview layout columns doesn't fit into window.
325 0 : if ( !mpPgPreviewLayout->DoesPreviewLayoutColsFitIntoWindow() )
326 0 : bPaintPageAtFirstCol = false;
327 0 : break;
328 : case MV_SCROLL:
329 : // check, if paint page at first column
330 : // has to be avoided
331 0 : if ( !mpPgPreviewLayout->DoesPreviewLayoutRowsFitIntoWindow() ||
332 0 : !mpPgPreviewLayout->DoesPreviewLayoutColsFitIntoWindow() )
333 0 : bPaintPageAtFirstCol = false;
334 0 : break;
335 : case MV_NEWWINSIZE:
336 : // nothing special to do.
337 0 : break;
338 : case MV_CALC:
339 : // re-init page preview layout.
340 0 : mpPgPreviewLayout->ReInit();
341 :
342 : // correct calculation of new start page.
343 0 : if( nNewSttPage > nPageCount )
344 0 : nNewSttPage = nPageCount;
345 :
346 : // correct selected page number
347 0 : if( SelectedPage() > nPageCount )
348 0 : SetSelectedPage( nNewSttPage ? nNewSttPage : 1 );
349 : }
350 :
351 : mpPgPreviewLayout->Prepare( nNewSttPage, Point(0,0), maPxWinSize,
352 : nNewSttPage,
353 0 : maPaintedPreviewDocRect, bPaintPageAtFirstCol );
354 0 : if( nNewSttPage == mnSttPage &&
355 : eMoveMode != MV_SELPAGE )
356 0 : return sal_False;
357 :
358 0 : SetPagePreview(mnRow, mnCol);
359 0 : mnSttPage = nNewSttPage;
360 :
361 : // additional invalidate page status.
362 : static sal_uInt16 aInval[] =
363 : {
364 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
365 : FN_STAT_PAGE, 0
366 : };
367 :
368 0 : SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
369 0 : rBindings.Invalidate( aInval );
370 :
371 0 : return sal_True;
372 : }
373 :
374 0 : void SwPagePreviewWin::SetWinSize( const Size& rNewSize )
375 : {
376 : // We always want the size as pixel units.
377 0 : maPxWinSize = LogicToPixel( rNewSize );
378 :
379 0 : if( USHRT_MAX == mnSttPage )
380 : {
381 0 : mnSttPage = GetDefSttPage();
382 0 : SetSelectedPage( GetDefSttPage() );
383 : }
384 :
385 0 : if ( mbCalcScaleForPreviewLayout )
386 : {
387 0 : mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize, true );
388 0 : maScale = GetMapMode().GetScaleX();
389 : }
390 : mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
391 0 : mnSttPage, maPaintedPreviewDocRect );
392 0 : if ( mbCalcScaleForPreviewLayout )
393 : {
394 0 : SetSelectedPage( mnSttPage );
395 0 : mbCalcScaleForPreviewLayout = false;
396 : }
397 0 : SetPagePreview(mnRow, mnCol);
398 0 : maScale = GetMapMode().GetScaleX();
399 0 : }
400 :
401 0 : OUString SwPagePreviewWin::GetStatusStr( sal_uInt16 nPageCnt ) const
402 : {
403 : // show physical and virtual page number of
404 : // selected page, if it's visible.
405 0 : const sal_uInt16 nPageNum = mpPgPreviewLayout->IsPageVisible( mpPgPreviewLayout->SelectedPage() )
406 0 : ? mpPgPreviewLayout->SelectedPage() : std::max<sal_uInt16>(mnSttPage, 1);
407 :
408 0 : OUStringBuffer aStatusStr;
409 0 : const sal_uInt16 nVirtPageNum = mpPgPreviewLayout->GetVirtPageNumByPageNum( nPageNum );
410 0 : if( nVirtPageNum && nVirtPageNum != nPageNum )
411 : {
412 0 : aStatusStr.append( OUString::number(nVirtPageNum) + " " );
413 : }
414 0 : aStatusStr.append( OUString::number(nPageNum) + " / " + OUString::number(nPageCnt) );
415 0 : return aStatusStr.makeStringAndClear();
416 : }
417 :
418 0 : void SwPagePreviewWin::KeyInput( const KeyEvent &rKEvt )
419 : {
420 0 : const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
421 0 : bool bHandled = false;
422 0 : if(!rKeyCode.GetModifier())
423 : {
424 0 : sal_uInt16 nSlot = 0;
425 0 : switch(rKeyCode.GetCode())
426 : {
427 0 : case KEY_ADD : nSlot = SID_ZOOM_OUT; break;
428 0 : case KEY_ESCAPE: nSlot = FN_CLOSE_PAGEPREVIEW; break;
429 0 : case KEY_SUBTRACT : nSlot = SID_ZOOM_IN; break;
430 : }
431 0 : if(nSlot)
432 : {
433 0 : bHandled = true;
434 : mrView.GetViewFrame()->GetDispatcher()->Execute(
435 0 : nSlot, SfxCallMode::ASYNCHRON );
436 : }
437 : }
438 0 : if( !bHandled && !mrView.KeyInput( rKEvt ) )
439 0 : Window::KeyInput( rKEvt );
440 0 : }
441 :
442 0 : void SwPagePreviewWin::Command( const CommandEvent& rCEvt )
443 : {
444 0 : bool bCallBase = true;
445 0 : switch( rCEvt.GetCommand() )
446 : {
447 : case COMMAND_CONTEXTMENU:
448 0 : SfxDispatcher::ExecutePopup();
449 0 : bCallBase = false;
450 0 : break;
451 :
452 : case COMMAND_WHEEL:
453 : case COMMAND_STARTAUTOSCROLL:
454 : case COMMAND_AUTOSCROLL:
455 : {
456 0 : const CommandWheelData* pData = rCEvt.GetWheelData();
457 0 : if( pData )
458 : {
459 : const CommandWheelData aDataNew(pData->GetDelta(),pData->GetNotchDelta(),COMMAND_WHEEL_PAGESCROLL,
460 0 : pData->GetMode(),pData->GetModifier(),pData->IsHorz(), pData->IsDeltaPixel());
461 0 : const CommandEvent aEvent( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),rCEvt.IsMouseEvent(),&aDataNew);
462 0 : bCallBase = !mrView.HandleWheelCommands( aEvent );
463 : }
464 : else
465 0 : bCallBase = !mrView.HandleWheelCommands( rCEvt );
466 : }
467 0 : break;
468 : default:
469 : ;
470 : }
471 :
472 0 : if( bCallBase )
473 0 : Window::Command( rCEvt );
474 0 : }
475 :
476 0 : void SwPagePreviewWin::MouseButtonDown( const MouseEvent& rMEvt )
477 : {
478 : // consider single-click to set selected page
479 0 : if( MOUSE_LEFT == ( rMEvt.GetModifier() + rMEvt.GetButtons() ) )
480 : {
481 0 : Point aPreviewPos( PixelToLogic( rMEvt.GetPosPixel() ) );
482 0 : Point aDocPos;
483 : bool bPosInEmptyPage;
484 : sal_uInt16 nNewSelectedPage;
485 : bool bIsDocPos =
486 : mpPgPreviewLayout->IsPreviewPosInDocPreviewPage( aPreviewPos,
487 0 : aDocPos, bPosInEmptyPage, nNewSelectedPage );
488 0 : if ( bIsDocPos && rMEvt.GetClicks() == 2 )
489 : {
490 : // close page preview, set new cursor position and switch to
491 : // normal view.
492 0 : OUString sNewCrsrPos = OUString::number( aDocPos.X() ) + ";" +
493 0 : OUString::number( aDocPos.Y() ) + ";";
494 0 : mrView.SetNewCrsrPos( sNewCrsrPos );
495 :
496 0 : SfxViewFrame *pTmpFrm = mrView.GetViewFrame();
497 0 : pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
498 0 : SfxCallMode::ASYNCHRON );
499 : }
500 0 : else if ( bIsDocPos || bPosInEmptyPage )
501 : {
502 : // show clicked page as the selected one
503 0 : mpPgPreviewLayout->MarkNewSelectedPage( nNewSelectedPage );
504 0 : GetViewShell()->ShowPreviewSelection( nNewSelectedPage );
505 : // adjust position at vertical scrollbar.
506 0 : if ( mpPgPreviewLayout->DoesPreviewLayoutRowsFitIntoWindow() )
507 : {
508 0 : mrView.SetVScrollbarThumbPos( nNewSelectedPage );
509 : }
510 : // invalidate page status.
511 : static sal_uInt16 aInval[] =
512 : {
513 : FN_STAT_PAGE, 0
514 : };
515 0 : SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
516 0 : rBindings.Invalidate( aInval );
517 : }
518 : }
519 0 : }
520 :
521 : // Set user prefs or view options
522 :
523 0 : void SwPagePreviewWin::SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol )
524 : {
525 0 : SwMasterUsrPref *pOpt = (SwMasterUsrPref *)SW_MOD()->GetUsrPref(false);
526 :
527 0 : if (nRow != pOpt->GetPagePrevRow() || nCol != pOpt->GetPagePrevCol())
528 : {
529 0 : pOpt->SetPagePrevRow( nRow );
530 0 : pOpt->SetPagePrevCol( nCol );
531 0 : pOpt->SetModified();
532 :
533 : // Update scrollbar!
534 0 : mrView.ScrollViewSzChg();
535 : }
536 0 : }
537 :
538 : /** get selected page in document preview
539 :
540 : @author OD
541 : */
542 0 : sal_uInt16 SwPagePreviewWin::SelectedPage() const
543 : {
544 0 : return mpPgPreviewLayout->SelectedPage();
545 : }
546 :
547 : /** set selected page number in document preview
548 :
549 : @author OD
550 : */
551 0 : void SwPagePreviewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum )
552 : {
553 0 : mpPgPreviewLayout->SetSelectedPage( _nSelectedPageNum );
554 0 : }
555 :
556 : /** method to enable/disable book preview
557 :
558 : @author OD
559 : */
560 0 : bool SwPagePreviewWin::SetBookPreviewMode( const bool _bBookPreview )
561 : {
562 : return mpPgPreviewLayout->SetBookPreviewMode( _bBookPreview,
563 : mnSttPage,
564 0 : maPaintedPreviewDocRect );
565 : }
566 :
567 0 : void SwPagePreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
568 : {
569 0 : Window::DataChanged( rDCEvt );
570 :
571 0 : switch( rDCEvt.GetType() )
572 : {
573 : case DATACHANGED_SETTINGS:
574 : // Rearrange the scrollbars or trigger resize, because the
575 : // size of the scrollbars may have be changed. Also the
576 : // size of the scrollbars has to be retrieved from the settings
577 : // out of the resize handler.
578 0 : if( rDCEvt.GetFlags() & SETTINGS_STYLE )
579 0 : mrView.InvalidateBorder(); // Scrollbar widths
580 : // zoom has to be disabled if Accessibility support is switched on
581 0 : lcl_InvalidateZoomSlots(mrView.GetViewFrame()->GetBindings());
582 0 : break;
583 :
584 : case DATACHANGED_PRINTER:
585 : case DATACHANGED_DISPLAY:
586 : case DATACHANGED_FONTS:
587 : case DATACHANGED_FONTSUBSTITUTION:
588 0 : mrView.GetDocShell()->UpdateFontList(); // Font change
589 0 : if ( mpViewShell->GetWin() )
590 0 : mpViewShell->GetWin()->Invalidate();
591 0 : break;
592 : }
593 0 : }
594 :
595 : /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN
596 :
597 : @author OD
598 : */
599 0 : void SwPagePreview::_ExecPgUpAndPgDown( const bool _bPgUp,
600 : SfxRequest* _pReq )
601 : {
602 0 : SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout();
603 : // check, if top/bottom of preview is *not* already visible.
604 0 : if( pPagePreviewLay->GetWinPagesScrollAmount( _bPgUp ? -1 : 1 ) != 0 )
605 : {
606 0 : if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() &&
607 0 : pPagePreviewLay->DoesPreviewLayoutColsFitIntoWindow() )
608 : {
609 : const int eMvMode = _bPgUp ?
610 : SwPagePreviewWin::MV_PAGE_UP :
611 0 : SwPagePreviewWin::MV_PAGE_DOWN;
612 0 : if ( ChgPage( eMvMode, true ) )
613 0 : pViewWin->Invalidate();
614 : }
615 : else
616 : {
617 : SwTwips nScrollAmount;
618 0 : sal_uInt16 nNewSelectedPageNum = 0;
619 0 : const sal_uInt16 nVisPages = pViewWin->GetRow() * pViewWin->GetCol();
620 0 : if( _bPgUp )
621 : {
622 0 : if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() )
623 : {
624 0 : nScrollAmount = pPagePreviewLay->GetWinPagesScrollAmount( -1 );
625 0 : if ( (pViewWin->SelectedPage() - nVisPages) > 0 )
626 0 : nNewSelectedPageNum = pViewWin->SelectedPage() - nVisPages;
627 : else
628 0 : nNewSelectedPageNum = 1;
629 : }
630 : else
631 0 : nScrollAmount = - std::min( pViewWin->GetOutputSize().Height(),
632 0 : pViewWin->GetPaintedPreviewDocRect().Top() );
633 : }
634 : else
635 : {
636 0 : if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() )
637 : {
638 0 : nScrollAmount = pPagePreviewLay->GetWinPagesScrollAmount( 1 );
639 0 : if ( (pViewWin->SelectedPage() + nVisPages) <= mnPageCount )
640 0 : nNewSelectedPageNum = pViewWin->SelectedPage() + nVisPages;
641 : else
642 0 : nNewSelectedPageNum = mnPageCount;
643 : }
644 : else
645 0 : nScrollAmount = std::min( pViewWin->GetOutputSize().Height(),
646 0 : ( pPagePreviewLay->GetPreviewDocSize().Height() -
647 0 : pViewWin->GetPaintedPreviewDocRect().Bottom() ) );
648 : }
649 0 : pViewWin->Scroll( 0, nScrollAmount );
650 0 : if ( nNewSelectedPageNum != 0 )
651 : {
652 0 : pViewWin->SetSelectedPage( nNewSelectedPageNum );
653 : }
654 0 : ScrollViewSzChg();
655 : // additional invalidate page status.
656 : static sal_uInt16 aInval[] =
657 : {
658 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
659 : FN_STAT_PAGE, 0
660 : };
661 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
662 0 : rBindings.Invalidate( aInval );
663 0 : pViewWin->Invalidate();
664 : }
665 : }
666 :
667 0 : if ( _pReq )
668 0 : _pReq->Done();
669 0 : }
670 :
671 : // Then all for the SwPagePreview
672 0 : void SwPagePreview::Execute( SfxRequest &rReq )
673 : {
674 : int eMvMode;
675 0 : sal_uInt8 nRow = 1;
676 0 : bool bRetVal = false;
677 0 : bool bRefresh = true;
678 :
679 0 : switch(rReq.GetSlot())
680 : {
681 : case FN_REFRESH_VIEW:
682 : case FN_STAT_PAGE:
683 : case FN_STAT_ZOOM:
684 0 : break;
685 :
686 : case FN_SHOW_MULTIPLE_PAGES:
687 : {
688 0 : const SfxItemSet *pArgs = rReq.GetArgs();
689 0 : if( pArgs && pArgs->Count() >= 2 )
690 : {
691 : sal_uInt8 nCols = (sal_uInt8)((SfxUInt16Item &)pArgs->Get(
692 0 : SID_ATTR_TABLE_COLUMN)).GetValue();
693 : sal_uInt8 nRows = (sal_uInt8)((SfxUInt16Item &)pArgs->Get(
694 0 : SID_ATTR_TABLE_ROW)).GetValue();
695 0 : pViewWin->CalcWish( nRows, nCols );
696 :
697 : }
698 : else
699 0 : SwPreviewZoomDlg( *pViewWin ).Execute();
700 :
701 : }
702 0 : break;
703 : case FN_SHOW_BOOKVIEW:
704 : {
705 0 : const SfxItemSet* pArgs = rReq.GetArgs();
706 : const SfxPoolItem* pItem;
707 0 : bool bBookPreview = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
708 0 : if( pArgs && SfxItemState::SET == pArgs->GetItemState( FN_SHOW_BOOKVIEW, false, &pItem ) )
709 : {
710 0 : bBookPreview = static_cast< const SfxBoolItem* >( pItem )->GetValue();
711 0 : ( ( SwViewOption* ) GetViewShell()->GetViewOptions() )->SetPagePrevBookview( bBookPreview );
712 : // cast is not gentleman like, but it's common use in writer and in this case
713 : }
714 0 : if ( pViewWin->SetBookPreviewMode( bBookPreview ) )
715 : {
716 : // book preview mode changed. Thus, adjust scrollbars and
717 : // invalidate corresponding states.
718 0 : ScrollViewSzChg();
719 : static sal_uInt16 aInval[] =
720 : {
721 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
722 : FN_STAT_PAGE, FN_SHOW_BOOKVIEW, 0
723 : };
724 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
725 0 : rBindings.Invalidate( aInval );
726 0 : pViewWin->Invalidate();
727 : }
728 :
729 : }
730 0 : break;
731 : case FN_SHOW_TWO_PAGES:
732 0 : pViewWin->CalcWish( nRow, 2 );
733 0 : break;
734 :
735 : case FN_SHOW_SINGLE_PAGE:
736 0 : pViewWin->CalcWish( nRow, 1 );
737 0 : break;
738 :
739 : case FN_PREVIEW_ZOOM:
740 : case SID_ATTR_ZOOM:
741 : {
742 0 : const SfxItemSet *pArgs = rReq.GetArgs();
743 : const SfxPoolItem* pItem;
744 0 : boost::scoped_ptr<AbstractSvxZoomDialog> pDlg;
745 0 : if(!pArgs)
746 : {
747 0 : SfxItemSet aCoreSet(GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
748 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
749 : SvxZoomItem aZoom( (SvxZoomType)pVOpt->GetZoomType(),
750 0 : pVOpt->GetZoom() );
751 : aZoom.SetValueSet(
752 : SVX_ZOOM_ENABLE_50|
753 : SVX_ZOOM_ENABLE_75|
754 : SVX_ZOOM_ENABLE_100|
755 : SVX_ZOOM_ENABLE_150|
756 : SVX_ZOOM_ENABLE_200|
757 0 : SVX_ZOOM_ENABLE_WHOLEPAGE);
758 0 : aCoreSet.Put( aZoom );
759 :
760 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
761 0 : if(pFact)
762 : {
763 0 : pDlg.reset(pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aCoreSet));
764 : OSL_ENSURE(pDlg, "Dialog creation failed!");
765 : }
766 :
767 0 : pDlg->SetLimits( MINZOOM, MAXZOOM );
768 :
769 0 : if( pDlg->Execute() != RET_CANCEL )
770 0 : pArgs = pDlg->GetOutputItemSet();
771 : }
772 0 : if( pArgs )
773 : {
774 0 : enum SvxZoomType eType = SVX_ZOOM_PERCENT;
775 0 : sal_uInt16 nZoomFactor = USHRT_MAX;
776 0 : if(SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOM, true, &pItem))
777 : {
778 0 : eType = ((const SvxZoomItem *)pItem)->GetType();
779 0 : nZoomFactor = ((const SvxZoomItem *)pItem)->GetValue();
780 : }
781 0 : else if(SfxItemState::SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, true, &pItem))
782 0 : nZoomFactor = ((const SfxUInt16Item *)pItem)->GetValue();
783 0 : if(USHRT_MAX != nZoomFactor)
784 0 : SetZoom(eType, nZoomFactor);
785 0 : }
786 : }
787 0 : break;
788 : case SID_ATTR_ZOOMSLIDER :
789 : {
790 0 : const SfxItemSet *pArgs = rReq.GetArgs();
791 : const SfxPoolItem* pItem;
792 :
793 0 : if ( pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) )
794 : {
795 0 : const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
796 0 : SetZoom( SVX_ZOOM_PERCENT, nCurrentZoom );
797 : }
798 : }
799 0 : break;
800 : case SID_ZOOM_IN:
801 : case SID_ZOOM_OUT:
802 : {
803 0 : enum SvxZoomType eType = SVX_ZOOM_PERCENT;
804 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
805 : SetZoom(eType,
806 0 : lcl_GetNextZoomStep(pVOpt->GetZoom(), SID_ZOOM_IN == rReq.GetSlot()));
807 : }
808 0 : break;
809 : case FN_CHAR_LEFT:
810 : case FN_CHAR_RIGHT:
811 : case FN_LINE_UP:
812 : case FN_LINE_DOWN:
813 : {
814 0 : SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout();
815 : sal_uInt16 nNewSelectedPage;
816 : sal_uInt16 nNewStartPage;
817 0 : Point aNewStartPos;
818 0 : sal_Int16 nHoriMove = 0;
819 0 : sal_Int16 nVertMove = 0;
820 0 : switch(rReq.GetSlot())
821 : {
822 0 : case FN_CHAR_LEFT: nHoriMove = -1; break;
823 0 : case FN_CHAR_RIGHT: nHoriMove = 1; break;
824 0 : case FN_LINE_UP: nVertMove = -1; break;
825 0 : case FN_LINE_DOWN: nVertMove = 1; break;
826 : }
827 : pPagePreviewLay->CalcStartValuesForSelectedPageMove( nHoriMove, nVertMove,
828 0 : nNewSelectedPage, nNewStartPage, aNewStartPos );
829 0 : if ( pViewWin->SelectedPage() != nNewSelectedPage )
830 : {
831 0 : if ( pPagePreviewLay->IsPageVisible( nNewSelectedPage ) )
832 : {
833 0 : pPagePreviewLay->MarkNewSelectedPage( nNewSelectedPage );
834 : // adjust position at vertical scrollbar.
835 0 : SetVScrollbarThumbPos( nNewSelectedPage );
836 0 : bRefresh = false;
837 : }
838 : else
839 : {
840 0 : pViewWin->SetSelectedPage( nNewSelectedPage );
841 0 : pViewWin->SetSttPage( nNewStartPage );
842 0 : bRefresh = ChgPage( SwPagePreviewWin::MV_SELPAGE, true );
843 : }
844 0 : GetViewShell()->ShowPreviewSelection( nNewSelectedPage );
845 : // invalidate page status.
846 : static sal_uInt16 aInval[] =
847 : {
848 : FN_STAT_PAGE, 0
849 : };
850 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
851 0 : rBindings.Invalidate( aInval );
852 0 : rReq.Done();
853 : }
854 : else
855 : {
856 0 : bRefresh = false;
857 : }
858 0 : break;
859 : }
860 : case FN_PAGEUP:
861 : case FN_PAGEDOWN:
862 : {
863 0 : _ExecPgUpAndPgDown( rReq.GetSlot() == FN_PAGEUP, &rReq );
864 0 : break;
865 : }
866 : case FN_START_OF_LINE:
867 : case FN_START_OF_DOCUMENT:
868 0 : pViewWin->SetSelectedPage( 1 );
869 0 : eMvMode = SwPagePreviewWin::MV_DOC_STT; bRetVal = true; goto MOVEPAGE;
870 : case FN_END_OF_LINE:
871 : case FN_END_OF_DOCUMENT:
872 0 : pViewWin->SetSelectedPage( mnPageCount );
873 0 : eMvMode = SwPagePreviewWin::MV_DOC_END; bRetVal = true; goto MOVEPAGE;
874 : MOVEPAGE:
875 : {
876 0 : bool nRet = ChgPage( eMvMode, true );
877 : // return value fuer Basic
878 0 : if(bRetVal)
879 0 : rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), !nRet));
880 :
881 0 : bRefresh = nRet;
882 0 : rReq.Done();
883 : }
884 0 : break;
885 :
886 : case FN_PRINT_PAGEPREVIEW:
887 : {
888 0 : const SwPagePreviewPrtData* pPPVPD = pViewWin->GetViewShell()->GetDoc()->GetPreviewPrtData();
889 : // The thing with the orientation
890 0 : if(pPPVPD)
891 : {
892 0 : SfxPrinter* pPrinter = GetPrinter( true );
893 0 : if((pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE)
894 0 : != pPPVPD->GetLandscape())
895 0 : pPrinter->SetOrientation(pPPVPD->GetLandscape() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
896 : }
897 0 : ::SetAppPrintOptions( pViewWin->GetViewShell(), false );
898 0 : bNormalPrint = false;
899 0 : rReq.SetSlot( SID_PRINTDOC );
900 0 : SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
901 0 : rReq.SetSlot( FN_PRINT_PAGEPREVIEW );
902 0 : return;
903 : }
904 : case SID_PRINTDOCDIRECT:
905 : case SID_PRINTDOC:
906 0 : ::SetAppPrintOptions( pViewWin->GetViewShell(), false );
907 0 : bNormalPrint = true;
908 0 : SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
909 0 : return;
910 : case FN_CLOSE_PAGEPREVIEW:
911 : case SID_PRINTPREVIEW:
912 : // print preview is now always in the same frame as the tab view
913 : // -> always switch this frame back to normal view
914 : // (ScTabViewShell ctor reads stored view data)
915 0 : GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, SfxCallMode::ASYNCHRON );
916 0 : break;
917 : case FN_INSERT_BREAK:
918 : {
919 0 : sal_uInt16 nSelPage = pViewWin->SelectedPage();
920 : //if a dummy page is selected (e.g. a non-existing right/left page)
921 : //the direct neighbor is used
922 0 : if(GetViewShell()->IsDummyPage( nSelPage ) && GetViewShell()->IsDummyPage( --nSelPage ))
923 0 : nSelPage +=2;
924 0 : SetNewPage( nSelPage );
925 0 : SfxViewFrame *pTmpFrm = GetViewFrame();
926 0 : pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
927 0 : SfxCallMode::ASYNCHRON );
928 : }
929 0 : break;
930 : default:
931 : OSL_ENSURE(false, "wrong dispatcher");
932 0 : return;
933 : }
934 :
935 0 : if( bRefresh )
936 0 : pViewWin->Invalidate();
937 : }
938 :
939 0 : void SwPagePreview::GetState( SfxItemSet& rSet )
940 : {
941 0 : SfxWhichIter aIter(rSet);
942 0 : sal_uInt8 nRow = 1;
943 0 : sal_uInt16 nWhich = aIter.FirstWhich();
944 : OSL_ENSURE(nWhich, "empty set");
945 0 : SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout();
946 :
947 0 : while(nWhich)
948 : {
949 0 : switch(nWhich)
950 : {
951 : case SID_BROWSER_MODE:
952 : case FN_PRINT_LAYOUT:
953 0 : rSet.DisableItem(nWhich);
954 0 : break;
955 : case FN_START_OF_DOCUMENT:
956 : {
957 0 : if ( pPagePreviewLay->IsPageVisible( 1 ) )
958 0 : rSet.DisableItem(nWhich);
959 0 : break;
960 : }
961 : case FN_END_OF_DOCUMENT:
962 : {
963 0 : if ( pPagePreviewLay->IsPageVisible( mnPageCount ) )
964 0 : rSet.DisableItem(nWhich);
965 0 : break;
966 : }
967 : case FN_PAGEUP:
968 : {
969 0 : if( pPagePreviewLay->GetWinPagesScrollAmount( -1 ) == 0 )
970 0 : rSet.DisableItem(nWhich);
971 0 : break;
972 : }
973 : case FN_PAGEDOWN:
974 : {
975 0 : if( pPagePreviewLay->GetWinPagesScrollAmount( 1 ) == 0 )
976 0 : rSet.DisableItem(nWhich);
977 0 : break;
978 : }
979 :
980 : case FN_STAT_PAGE:
981 : {
982 0 : OUString aStr = sPageStr + pViewWin->GetStatusStr( mnPageCount );
983 0 : rSet.Put( SfxStringItem( nWhich, aStr) );
984 : }
985 0 : break;
986 :
987 : case SID_ATTR_ZOOM:
988 : case FN_STAT_ZOOM:
989 : {
990 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
991 : SvxZoomItem aZoom((SvxZoomType)pVOpt->GetZoomType(),
992 0 : pVOpt->GetZoom());
993 : aZoom.SetValueSet(
994 : SVX_ZOOM_ENABLE_50|
995 : SVX_ZOOM_ENABLE_75|
996 : SVX_ZOOM_ENABLE_100|
997 : SVX_ZOOM_ENABLE_150|
998 0 : SVX_ZOOM_ENABLE_200);
999 0 : rSet.Put( aZoom );
1000 : }
1001 0 : break;
1002 : case SID_ATTR_ZOOMSLIDER :
1003 : {
1004 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1005 0 : const sal_uInt16 nCurrentZoom = pVOpt->GetZoom();
1006 0 : SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM );
1007 0 : aZoomSliderItem.AddSnappingPoint( 100 );
1008 0 : rSet.Put( aZoomSliderItem );
1009 : }
1010 0 : break;
1011 : case FN_PREVIEW_ZOOM:
1012 : {
1013 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1014 0 : rSet.Put(SfxUInt16Item(nWhich, pVOpt->GetZoom()));
1015 : }
1016 0 : break;
1017 : case SID_ZOOM_IN:
1018 : case SID_ZOOM_OUT:
1019 : {
1020 0 : const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1021 0 : if((SID_ZOOM_OUT == nWhich && pVOpt->GetZoom() >= MAX_PREVIEW_ZOOM)||
1022 0 : (SID_ZOOM_IN == nWhich && pVOpt->GetZoom() <= MIN_PREVIEW_ZOOM))
1023 : {
1024 0 : rSet.DisableItem(nWhich);
1025 : }
1026 : }
1027 0 : break;
1028 : case FN_SHOW_MULTIPLE_PAGES:
1029 : // should never be disabled
1030 0 : break;
1031 : case FN_SHOW_BOOKVIEW:
1032 : {
1033 0 : bool b = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
1034 0 : rSet.Put(SfxBoolItem(nWhich, b));
1035 : }
1036 0 : break;
1037 :
1038 : case FN_SHOW_TWO_PAGES:
1039 0 : if( 2 == pViewWin->GetCol() && nRow == pViewWin->GetRow() )
1040 0 : rSet.DisableItem( nWhich );
1041 0 : break;
1042 :
1043 : case FN_PRINT_PAGEPREVIEW:
1044 : // has the same status like the normal printing
1045 : {
1046 : const SfxPoolItem* pItem;
1047 0 : SfxItemSet aSet( *rSet.GetPool(), SID_PRINTDOC, SID_PRINTDOC );
1048 0 : GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet );
1049 0 : if( SfxItemState::DISABLED == aSet.GetItemState( SID_PRINTDOC,
1050 0 : false, &pItem ))
1051 0 : rSet.DisableItem( nWhich );
1052 0 : else if( SfxItemState::SET == aSet.GetItemState( SID_PRINTDOC,
1053 0 : false, &pItem ))
1054 : {
1055 0 : ((SfxPoolItem*)pItem)->SetWhich( FN_PRINT_PAGEPREVIEW );
1056 0 : rSet.Put( *pItem );
1057 0 : }
1058 : }
1059 0 : break;
1060 :
1061 : case SID_PRINTPREVIEW:
1062 0 : rSet.Put( SfxBoolItem( nWhich, true ) );
1063 0 : break;
1064 :
1065 : case SID_PRINTDOC:
1066 : case SID_PRINTDOCDIRECT:
1067 0 : GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet );
1068 0 : break;
1069 : }
1070 0 : nWhich = aIter.NextWhich();
1071 0 : }
1072 0 : }
1073 :
1074 0 : void SwPagePreview::StateUndo(SfxItemSet& rSet)
1075 : {
1076 0 : SfxWhichIter aIter(rSet);
1077 0 : sal_uInt16 nWhich = aIter.FirstWhich();
1078 :
1079 0 : while (nWhich)
1080 : {
1081 0 : rSet.DisableItem(nWhich);
1082 0 : nWhich = aIter.NextWhich();
1083 0 : }
1084 0 : }
1085 :
1086 0 : void SwPagePreview::Init(const SwViewOption * pPrefs)
1087 : {
1088 0 : if ( GetViewShell()->HasDrawView() )
1089 0 : GetViewShell()->GetDrawView()->SetAnimationEnabled( false );
1090 :
1091 0 : bNormalPrint = true;
1092 :
1093 : // Check and process the DocSize. The shell could not be found via
1094 : // the handler, because the shell is unknown to the SFX management
1095 : // within the CTOR phase.
1096 :
1097 0 : if( !pPrefs )
1098 0 : pPrefs = SW_MOD()->GetUsrPref(false);
1099 :
1100 0 : mbHScrollbarEnabled = pPrefs->IsViewHScrollBar();
1101 0 : mbVScrollbarEnabled = pPrefs->IsViewVScrollBar();
1102 :
1103 : // Update the fields
1104 : // ATTENTION: Do cast the EditShell up, to use the SS.
1105 : // At the methodes the current shell will be queried!
1106 0 : SwEditShell* pESh = (SwEditShell*)GetViewShell();
1107 0 : bool bIsModified = pESh->IsModified();
1108 :
1109 0 : SwViewOption aOpt( *pPrefs );
1110 0 : aOpt.SetPagePreview(true);
1111 0 : aOpt.SetTab( false );
1112 0 : aOpt.SetBlank( false );
1113 0 : aOpt.SetHardBlank( false );
1114 0 : aOpt.SetParagraph( false );
1115 0 : aOpt.SetLineBreak( false );
1116 0 : aOpt.SetPageBreak( false );
1117 0 : aOpt.SetColumnBreak( false );
1118 0 : aOpt.SetSoftHyph( false );
1119 0 : aOpt.SetFldName( false );
1120 0 : aOpt.SetPostIts( false );
1121 0 : aOpt.SetShowHiddenChar( false );
1122 0 : aOpt.SetShowHiddenField( false );
1123 0 : aOpt.SetShowHiddenPara( false );
1124 0 : aOpt.SetViewHRuler( false );
1125 0 : aOpt.SetViewVRuler( false );
1126 0 : aOpt.SetGraphic( true );
1127 0 : aOpt.SetTable( true );
1128 0 : aOpt.SetSnap( false );
1129 0 : aOpt.SetGridVisible( false );
1130 :
1131 0 : GetViewShell()->ApplyViewOptions( aOpt );
1132 0 : GetViewShell()->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions());
1133 :
1134 : // adjust view shell option to the same as for print
1135 0 : SwPrintData const aPrintOptions = *SW_MOD()->GetPrtOptions(false);
1136 0 : GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions );
1137 :
1138 0 : GetViewShell()->CalcLayout();
1139 0 : DocSzChgd( GetViewShell()->GetDocSize() );
1140 :
1141 0 : if( !bIsModified )
1142 0 : pESh->ResetModified();
1143 0 : }
1144 :
1145 0 : SwPagePreview::SwPagePreview(SfxViewFrame *pViewFrame, SfxViewShell* pOldSh):
1146 : SfxViewShell( pViewFrame, SWVIEWFLAGS ),
1147 0 : pViewWin( new SwPagePreviewWin(&(GetViewFrame())->GetWindow(), *this ) ),
1148 : nNewPage(USHRT_MAX),
1149 : sPageStr(SW_RES(STR_PAGE)),
1150 : pHScrollbar(0),
1151 : pVScrollbar(0),
1152 : pScrollFill(new ScrollBarBox( &pViewFrame->GetWindow(),
1153 0 : pViewFrame->GetFrame().GetParentFrame() ? 0 : WB_SIZEABLE )),
1154 : mnPageCount( 0 ),
1155 : mbResetFormDesignMode( false ),
1156 0 : mbFormDesignModeToReset( false )
1157 : {
1158 0 : SetName(OUString("PageView" ));
1159 0 : SetWindow( pViewWin );
1160 0 : SetHelpId(SW_PAGEPREVIEW);
1161 0 : _CreateScrollbar( true );
1162 0 : _CreateScrollbar( false );
1163 :
1164 0 : SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
1165 0 : if ( !pOldSh )
1166 : {
1167 : // Exists already a view on the document?
1168 0 : SfxViewFrame *pF = SfxViewFrame::GetFirst( pObjShell );
1169 0 : if ( pF == pViewFrame )
1170 0 : pF = SfxViewFrame::GetNext( *pF, pObjShell );
1171 0 : if ( pF )
1172 0 : pOldSh = pF->GetViewShell();
1173 : }
1174 :
1175 : SwViewShell *pVS, *pNew;
1176 :
1177 0 : if( pOldSh && pOldSh->IsA( TYPE( SwPagePreview ) ) )
1178 0 : pVS = ((SwPagePreview*)pOldSh)->GetViewShell();
1179 : else
1180 : {
1181 0 : if( pOldSh && pOldSh->IsA( TYPE( SwView ) ) )
1182 : {
1183 0 : pVS = ((SwView*)pOldSh)->GetWrtShellPtr();
1184 : // save the current ViewData of the previous SwView
1185 0 : pOldSh->WriteUserData( sSwViewData, false );
1186 : }
1187 : else
1188 0 : pVS = GetDocShell()->GetWrtShell();
1189 0 : if( pVS )
1190 : {
1191 : // Set the current page as the first.
1192 : sal_uInt16 nPhysPg, nVirtPg;
1193 0 : ((SwCrsrShell*)pVS)->GetPageNum( nPhysPg, nVirtPg, true, false );
1194 0 : if( 1 != pViewWin->GetCol() && 1 == nPhysPg )
1195 0 : --nPhysPg;
1196 0 : pViewWin->SetSttPage( nPhysPg );
1197 : }
1198 : }
1199 :
1200 : // for form shell remember design mode of draw view
1201 : // of previous view shell
1202 0 : if ( pVS && pVS->HasDrawView() )
1203 : {
1204 0 : mbResetFormDesignMode = true;
1205 0 : mbFormDesignModeToReset = pVS->GetDrawView()->IsDesignMode();
1206 : }
1207 :
1208 0 : if( pVS )
1209 0 : pNew = new SwViewShell( *pVS, pViewWin, 0, VSHELLFLAG_ISPREVIEW );
1210 : else
1211 : pNew = new SwViewShell(
1212 0 : *((SwDocShell*)pViewFrame->GetObjectShell())->GetDoc(),
1213 0 : pViewWin, 0, 0, VSHELLFLAG_ISPREVIEW );
1214 :
1215 0 : pViewWin->SetViewShell( pNew );
1216 0 : pNew->SetSfxViewShell( this );
1217 0 : Init();
1218 0 : }
1219 :
1220 0 : SwPagePreview::~SwPagePreview()
1221 : {
1222 0 : SetWindow( 0 );
1223 0 : SwViewShell* pVShell = pViewWin->GetViewShell();
1224 0 : pVShell->SetWin(0);
1225 0 : delete pVShell;
1226 0 : delete pViewWin;
1227 :
1228 0 : delete pScrollFill;
1229 0 : delete pHScrollbar;
1230 0 : delete pVScrollbar;
1231 0 : }
1232 :
1233 0 : SwDocShell* SwPagePreview::GetDocShell()
1234 : {
1235 0 : return PTR_CAST(SwDocShell, GetViewFrame()->GetObjectShell());
1236 : }
1237 :
1238 0 : int SwPagePreview::_CreateScrollbar( bool bHori )
1239 : {
1240 0 : vcl::Window *pMDI = &GetViewFrame()->GetWindow();
1241 0 : SwScrollbar** ppScrollbar = bHori ? &pHScrollbar : &pVScrollbar;
1242 :
1243 : assert(!*ppScrollbar); //check beforehand!
1244 :
1245 0 : *ppScrollbar = new SwScrollbar( pMDI, bHori );
1246 :
1247 0 : ScrollDocSzChg();
1248 0 : (*ppScrollbar)->EnableDrag( true );
1249 0 : (*ppScrollbar)->SetEndScrollHdl( LINK( this, SwPagePreview, EndScrollHdl ));
1250 :
1251 0 : (*ppScrollbar)->SetScrollHdl( LINK( this, SwPagePreview, ScrollHdl ));
1252 :
1253 0 : InvalidateBorder();
1254 0 : (*ppScrollbar)->ExtendedShow();
1255 0 : return 1;
1256 : }
1257 :
1258 0 : bool SwPagePreview::ChgPage( int eMvMode, bool bUpdateScrollbar )
1259 : {
1260 0 : Rectangle aPixVisArea( pViewWin->LogicToPixel( aVisArea ) );
1261 0 : bool bChg = pViewWin->MovePage( eMvMode ) ||
1262 0 : eMvMode == SwPagePreviewWin::MV_CALC ||
1263 0 : eMvMode == SwPagePreviewWin::MV_NEWWINSIZE;
1264 0 : aVisArea = pViewWin->PixelToLogic( aPixVisArea );
1265 :
1266 0 : if( bChg )
1267 : {
1268 : // Update statusbar
1269 0 : OUString aStr = sPageStr + pViewWin->GetStatusStr( mnPageCount );
1270 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
1271 :
1272 0 : if( bUpdateScrollbar )
1273 : {
1274 0 : ScrollViewSzChg();
1275 :
1276 : static sal_uInt16 aInval[] =
1277 : {
1278 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT,
1279 : FN_PAGEUP, FN_PAGEDOWN, 0
1280 : };
1281 0 : rBindings.Invalidate( aInval );
1282 : }
1283 0 : rBindings.SetState( SfxStringItem( FN_STAT_PAGE, aStr ) );
1284 : }
1285 0 : return bChg;
1286 : }
1287 :
1288 : // From here, everything was taken from the SwView.
1289 0 : void SwPagePreview::CalcAndSetBorderPixel( SvBorder &rToFill, bool /*bInner*/ )
1290 : {
1291 0 : const StyleSettings &rSet = pViewWin->GetSettings().GetStyleSettings();
1292 0 : const long nTmp = rSet.GetScrollBarSize();
1293 0 : if ( pVScrollbar->IsVisible( true ) )
1294 0 : rToFill.Right() = nTmp;
1295 0 : if ( pHScrollbar->IsVisible( true ) )
1296 0 : rToFill.Bottom() = nTmp;
1297 0 : SetBorderPixel( rToFill );
1298 0 : }
1299 :
1300 0 : void SwPagePreview::InnerResizePixel( const Point &rOfst, const Size &rSize )
1301 : {
1302 0 : SvBorder aBorder;
1303 0 : CalcAndSetBorderPixel( aBorder, true );
1304 0 : Rectangle aRect( rOfst, rSize );
1305 0 : aRect += aBorder;
1306 : ViewResizePixel( *pViewWin, aRect.TopLeft(), aRect.GetSize(),
1307 0 : pViewWin->GetOutputSizePixel(),
1308 0 : *pVScrollbar, *pHScrollbar, *pScrollFill );
1309 :
1310 : // Never set EditWin !
1311 : // Never set VisArea !
1312 0 : }
1313 :
1314 0 : void SwPagePreview::OuterResizePixel( const Point &rOfst, const Size &rSize )
1315 : {
1316 0 : SvBorder aBorder;
1317 0 : CalcAndSetBorderPixel( aBorder, false );
1318 :
1319 : // Never set EditWin !
1320 :
1321 0 : Size aTmpSize( pViewWin->GetOutputSizePixel() );
1322 0 : Point aBottomRight( pViewWin->PixelToLogic( Point( aTmpSize.Width(), aTmpSize.Height() ) ) );
1323 0 : SetVisArea( Rectangle( Point(), aBottomRight ) );
1324 :
1325 : // Call of the DocSzChgd-Methode of the scrollbars is necessary,
1326 : // because from the maximum scoll range half the height of the
1327 : // VisArea is always deducted.
1328 0 : if ( pVScrollbar && aTmpSize.Width() > 0 && aTmpSize.Height() > 0 )
1329 : {
1330 0 : ScrollDocSzChg();
1331 : }
1332 :
1333 0 : SvBorder aBorderNew;
1334 0 : CalcAndSetBorderPixel( aBorderNew, false );
1335 0 : ViewResizePixel( *pViewWin, rOfst, rSize, pViewWin->GetOutputSizePixel(),
1336 0 : *pVScrollbar, *pHScrollbar, *pScrollFill );
1337 0 : }
1338 :
1339 0 : void SwPagePreview::SetVisArea( const Rectangle &rRect, bool bUpdateScrollbar )
1340 : {
1341 0 : const Point aTopLeft(AlignToPixel(rRect.TopLeft()));
1342 0 : const Point aBottomRight(AlignToPixel(rRect.BottomRight()));
1343 0 : Rectangle aLR(aTopLeft,aBottomRight);
1344 :
1345 0 : if(aLR == aVisArea)
1346 0 : return;
1347 : // No negative position, no negative size
1348 :
1349 0 : if(aLR.Top() < 0)
1350 : {
1351 0 : aLR.Bottom() += std::abs(aLR.Top());
1352 0 : aLR.Top() = 0;
1353 : }
1354 :
1355 0 : if(aLR.Left() < 0)
1356 : {
1357 0 : aLR.Right() += std::abs(aLR.Left());
1358 0 : aLR.Left() = 0;
1359 : }
1360 0 : if(aLR.Right() < 0) aLR.Right() = 0;
1361 0 : if(aLR.Bottom() < 0) aLR.Bottom() = 0;
1362 0 : if(aLR == aVisArea ||
1363 : // Ignore empty rectangle
1364 0 : ( 0 == aLR.Bottom() - aLR.Top() && 0 == aLR.Right() - aLR.Left() ) )
1365 0 : return;
1366 :
1367 0 : if( aLR.Left() > aLR.Right() || aLR.Top() > aLR.Bottom() )
1368 0 : return;
1369 :
1370 : // Before the data can be changed call an update if necessary.
1371 : // Thereby ensured, that adjacent paints are correctly converted into
1372 : // document coordinates.
1373 : // As a precaution, we do this only when at the shell runs an action,
1374 : // because then we do not really paint but the rectangles are just
1375 : // bookmarked (in document coordinates).
1376 0 : if( GetViewShell()->ActionPend() )
1377 0 : pViewWin->Update();
1378 :
1379 : // Set at View-Win the current size
1380 0 : aVisArea = aLR;
1381 0 : pViewWin->SetWinSize( aLR.GetSize() );
1382 0 : ChgPage( SwPagePreviewWin::MV_NEWWINSIZE, bUpdateScrollbar );
1383 :
1384 0 : pViewWin->Invalidate();
1385 : }
1386 :
1387 0 : IMPL_LINK( SwPagePreview, ScrollHdl, SwScrollbar *, pScrollbar )
1388 : {
1389 0 : if(!GetViewShell())
1390 0 : return 0;
1391 0 : if( !pScrollbar->IsHoriScroll() &&
1392 0 : pScrollbar->GetType() == SCROLL_DRAG &&
1393 0 : Help::IsQuickHelpEnabled() &&
1394 0 : GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1395 : {
1396 : // Scroll how many pages??
1397 0 : OUString sStateStr(sPageStr);
1398 0 : long nThmbPos = pScrollbar->GetThumbPos();
1399 0 : if( 1 == pViewWin->GetCol() || !nThmbPos )
1400 0 : ++nThmbPos;
1401 0 : sStateStr += OUString::number( nThmbPos );
1402 : Point aPos = pScrollbar->GetParent()->OutputToScreenPixel(
1403 0 : pScrollbar->GetPosPixel());
1404 0 : aPos.Y() = pScrollbar->OutputToScreenPixel(pScrollbar->GetPointerPosPixel()).Y();
1405 0 : Rectangle aRect;
1406 0 : aRect.Left() = aPos.X() -8;
1407 0 : aRect.Right() = aRect.Left();
1408 0 : aRect.Top() = aPos.Y();
1409 0 : aRect.Bottom() = aRect.Top();
1410 :
1411 : Help::ShowQuickHelp(pScrollbar, aRect, sStateStr,
1412 0 : QUICKHELP_RIGHT|QUICKHELP_VCENTER);
1413 :
1414 : }
1415 : else
1416 0 : EndScrollHdl( pScrollbar );
1417 0 : return 0;
1418 : }
1419 :
1420 0 : IMPL_LINK( SwPagePreview, EndScrollHdl, SwScrollbar *, pScrollbar )
1421 : {
1422 0 : if(!GetViewShell())
1423 0 : return 0;
1424 :
1425 : // boolean to avoid unnecessary invalidation of the window.
1426 0 : bool bInvalidateWin = true;
1427 :
1428 0 : if( !pScrollbar->IsHoriScroll() ) // scroll vertically
1429 : {
1430 0 : if ( Help::IsQuickHelpEnabled() )
1431 0 : Help::ShowQuickHelp(pScrollbar, Rectangle(), OUString(), 0);
1432 0 : if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() )
1433 : {
1434 : // Scroll how many pages ??
1435 0 : const sal_uInt16 nThmbPos = (sal_uInt16)pScrollbar->GetThumbPos();
1436 : // adjust to new preview functionality
1437 0 : if( nThmbPos != pViewWin->SelectedPage() )
1438 : {
1439 : // consider case that page <nThmbPos>
1440 : // is already visible
1441 0 : SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout();
1442 0 : if ( pPagePreviewLay->IsPageVisible( nThmbPos ) )
1443 : {
1444 0 : pPagePreviewLay->MarkNewSelectedPage( nThmbPos );
1445 : // invalidation of window is unnecessary
1446 0 : bInvalidateWin = false;
1447 : }
1448 : else
1449 : {
1450 : // consider whether layout columns
1451 : // fit or not.
1452 0 : if ( !pPagePreviewLay->DoesPreviewLayoutColsFitIntoWindow() )
1453 : {
1454 0 : pViewWin->SetSttPage( nThmbPos );
1455 0 : pViewWin->SetSelectedPage( nThmbPos );
1456 0 : ChgPage( SwPagePreviewWin::MV_SCROLL, false );
1457 : // update scrollbars
1458 0 : ScrollViewSzChg();
1459 : }
1460 : else
1461 : {
1462 : // correct scroll amount
1463 0 : const sal_Int16 nPageDiff = nThmbPos - pViewWin->SelectedPage();
1464 0 : const sal_uInt16 nVisPages = pViewWin->GetRow() * pViewWin->GetCol();
1465 0 : sal_Int16 nWinPagesToScroll = nPageDiff / nVisPages;
1466 0 : if ( nPageDiff % nVisPages )
1467 : {
1468 : // decrease/increase number of preview pages to scroll
1469 0 : nPageDiff < 0 ? --nWinPagesToScroll : ++nWinPagesToScroll;
1470 : }
1471 0 : pViewWin->SetSelectedPage( nThmbPos );
1472 0 : pViewWin->Scroll( 0, pPagePreviewLay->GetWinPagesScrollAmount( nWinPagesToScroll ) );
1473 : }
1474 : }
1475 : // update accessibility
1476 0 : GetViewShell()->ShowPreviewSelection( nThmbPos );
1477 : }
1478 : else
1479 : {
1480 : // invalidation of window is unnecessary
1481 0 : bInvalidateWin = false;
1482 : }
1483 : }
1484 : else
1485 : {
1486 0 : long nThmbPos = pScrollbar->GetThumbPos();
1487 0 : pViewWin->Scroll(0, nThmbPos - pViewWin->GetPaintedPreviewDocRect().Top());
1488 : }
1489 : }
1490 : else
1491 : {
1492 0 : long nThmbPos = pScrollbar->GetThumbPos();
1493 0 : pViewWin->Scroll(nThmbPos - pViewWin->GetPaintedPreviewDocRect().Left(), 0);
1494 : }
1495 : // additional invalidate page status.
1496 : static sal_uInt16 aInval[] =
1497 : {
1498 : FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
1499 : FN_STAT_PAGE, 0
1500 : };
1501 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
1502 0 : rBindings.Invalidate( aInval );
1503 : // control invalidation of window
1504 0 : if ( bInvalidateWin )
1505 : {
1506 0 : pViewWin->Invalidate();
1507 : }
1508 0 : return 0;
1509 : }
1510 :
1511 0 : Point SwPagePreview::AlignToPixel(const Point &rPt) const
1512 : {
1513 0 : return pViewWin->PixelToLogic( pViewWin->LogicToPixel( rPt ) );
1514 : }
1515 :
1516 0 : void SwPagePreview::DocSzChgd( const Size &rSz )
1517 : {
1518 0 : if( aDocSz == rSz )
1519 0 : return;
1520 :
1521 0 : aDocSz = rSz;
1522 :
1523 : // #i96726#
1524 : // Due to the multiple page layout it is needed to trigger recalculation
1525 : // of the page preview layout, even if the count of pages is not changing.
1526 0 : mnPageCount = GetViewShell()->GetNumPages();
1527 :
1528 0 : if( aVisArea.GetWidth() )
1529 : {
1530 0 : ChgPage( SwPagePreviewWin::MV_CALC, true );
1531 0 : ScrollDocSzChg();
1532 :
1533 0 : pViewWin->Invalidate();
1534 : }
1535 : }
1536 :
1537 0 : void SwPagePreview::ScrollViewSzChg()
1538 : {
1539 0 : if(!GetViewShell())
1540 0 : return ;
1541 :
1542 0 : bool bShowVScrollbar = false, bShowHScrollbar = false;
1543 :
1544 0 : if(pVScrollbar)
1545 : {
1546 0 : if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1547 : {
1548 : //vertical scrolling by row
1549 : // adjust to new preview functionality
1550 0 : const sal_uInt16 nVisPages = pViewWin->GetRow() * pViewWin->GetCol();
1551 :
1552 0 : pVScrollbar->SetVisibleSize( nVisPages );
1553 : // set selected page as scroll bar position,
1554 : // if it is visible.
1555 0 : SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout();
1556 0 : if ( pPagePreviewLay->IsPageVisible( pViewWin->SelectedPage() ) )
1557 : {
1558 0 : pVScrollbar->SetThumbPos( pViewWin->SelectedPage() );
1559 : }
1560 : else
1561 : {
1562 0 : pVScrollbar->SetThumbPos( pViewWin->GetSttPage() );
1563 : }
1564 0 : pVScrollbar->SetLineSize( pViewWin->GetCol() );
1565 0 : pVScrollbar->SetPageSize( nVisPages );
1566 : // calculate and set scrollbar range
1567 0 : Range aScrollbarRange( 1, mnPageCount );
1568 : // increase range by one, because left-top-corner is left blank.
1569 0 : ++aScrollbarRange.Max();
1570 : // increase range in order to access all pages
1571 0 : aScrollbarRange.Max() += ( nVisPages - 1 );
1572 0 : pVScrollbar->SetRange( aScrollbarRange );
1573 :
1574 0 : bShowVScrollbar = nVisPages < mnPageCount;
1575 : }
1576 : else //vertical scrolling by pixel
1577 : {
1578 0 : const Rectangle& rDocRect = pViewWin->GetPaintedPreviewDocRect();
1579 : const Size& rPreviewSize =
1580 0 : GetViewShell()->PagePreviewLayout()->GetPreviewDocSize();
1581 0 : pVScrollbar->SetRangeMax(rPreviewSize.Height()) ;
1582 0 : long nVisHeight = rDocRect.GetHeight();
1583 0 : pVScrollbar->SetVisibleSize( nVisHeight );
1584 0 : pVScrollbar->SetThumbPos( rDocRect.Top() );
1585 0 : pVScrollbar->SetLineSize( nVisHeight / 10 );
1586 0 : pVScrollbar->SetPageSize( nVisHeight / 2 );
1587 :
1588 0 : bShowVScrollbar = true;
1589 : }
1590 :
1591 0 : if (!mbVScrollbarEnabled)
1592 0 : bShowVScrollbar = false;
1593 :
1594 0 : ShowVScrollbar(bShowVScrollbar);
1595 : }
1596 0 : if(pHScrollbar)
1597 : {
1598 0 : const Rectangle& rDocRect = pViewWin->GetPaintedPreviewDocRect();
1599 : const Size& rPreviewSize =
1600 0 : GetViewShell()->PagePreviewLayout()->GetPreviewDocSize();
1601 0 : long nVisWidth = 0;
1602 0 : long nThumb = 0;
1603 0 : Range aRange(0,0);
1604 :
1605 0 : if(rDocRect.GetWidth() < rPreviewSize.Width())
1606 : {
1607 0 : bShowHScrollbar = true;
1608 :
1609 0 : nVisWidth = rDocRect.GetWidth();
1610 0 : nThumb = rDocRect.Left();
1611 0 : aRange = Range(0, rPreviewSize.Width());
1612 :
1613 0 : pHScrollbar->SetRange( aRange );
1614 0 : pHScrollbar->SetVisibleSize( nVisWidth );
1615 0 : pHScrollbar->SetThumbPos( nThumb );
1616 0 : pHScrollbar->SetLineSize( nVisWidth / 10 );
1617 0 : pHScrollbar->SetPageSize( nVisWidth / 2 );
1618 : }
1619 :
1620 0 : if (!mbHScrollbarEnabled)
1621 0 : bShowHScrollbar = false;
1622 :
1623 0 : ShowHScrollbar(bShowHScrollbar);
1624 : }
1625 0 : pScrollFill->Show(bShowVScrollbar && bShowHScrollbar);
1626 : }
1627 :
1628 0 : void SwPagePreview::ScrollDocSzChg()
1629 : {
1630 0 : ScrollViewSzChg();
1631 0 : }
1632 :
1633 : // All about printing
1634 0 : SfxPrinter* SwPagePreview::GetPrinter( bool bCreate )
1635 : {
1636 0 : return pViewWin->GetViewShell()->getIDocumentDeviceAccess()->getPrinter( bCreate );
1637 : }
1638 :
1639 0 : sal_uInt16 SwPagePreview::SetPrinter( SfxPrinter *pNew, sal_uInt16 nDiffFlags, bool )
1640 : {
1641 0 : SwViewShell &rSh = *GetViewShell();
1642 0 : SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
1643 0 : if ( pOld && pOld->IsPrinting() )
1644 0 : return SFX_PRINTERROR_BUSY;
1645 :
1646 0 : SwEditShell &rESh = (SwEditShell&)rSh; //Buh...
1647 0 : if( ( SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ) & nDiffFlags )
1648 : {
1649 0 : rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
1650 0 : if( nDiffFlags & SFX_PRINTER_PRINTER )
1651 0 : rESh.SetModified();
1652 : }
1653 0 : if ( ( nDiffFlags & SFX_PRINTER_OPTIONS ) == SFX_PRINTER_OPTIONS )
1654 0 : ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, false );
1655 :
1656 0 : const bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION;
1657 0 : const bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE;
1658 0 : if ( bChgOri || bChgSize )
1659 : {
1660 0 : rESh.StartAllAction();
1661 0 : if ( bChgOri )
1662 0 : rSh.ChgAllPageOrientation( pNew->GetOrientation() );
1663 0 : if ( bChgSize )
1664 : {
1665 0 : Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
1666 0 : rSh.ChgAllPageSize( aSz );
1667 : }
1668 0 : if( !bNormalPrint )
1669 0 : pViewWin->CalcWish( pViewWin->GetRow(), pViewWin->GetCol() );
1670 0 : rESh.SetModified();
1671 0 : rESh.EndAllAction();
1672 :
1673 : static sal_uInt16 aInval[] =
1674 : {
1675 : SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
1676 : SID_RULER_BORDERS, SID_RULER_PAGE_POS, 0
1677 : };
1678 : #if OSL_DEBUG_LEVEL > 0
1679 : {
1680 : const sal_uInt16* pPtr = aInval + 1;
1681 : do {
1682 : OSL_ENSURE( *(pPtr - 1) < *pPtr, "wrong sorting!" );
1683 : } while( *++pPtr );
1684 : }
1685 : #endif
1686 :
1687 0 : GetViewFrame()->GetBindings().Invalidate(aInval);
1688 : }
1689 :
1690 0 : return 0;
1691 : }
1692 :
1693 0 : bool SwPagePreview::HasPrintOptionsPage() const
1694 : {
1695 0 : return true;
1696 : }
1697 :
1698 0 : SfxTabPage* SwPagePreview::CreatePrintOptionsPage( vcl::Window *pParent,
1699 : const SfxItemSet &rOptions )
1700 : {
1701 0 : return ::CreatePrintOptionsPage( pParent, rOptions, !bNormalPrint );
1702 : }
1703 :
1704 0 : void SwPagePreviewWin::SetViewShell( SwViewShell* pShell )
1705 : {
1706 0 : mpViewShell = pShell;
1707 0 : if ( mpViewShell && mpViewShell->IsPreview() )
1708 : {
1709 0 : mpPgPreviewLayout = mpViewShell->PagePreviewLayout();
1710 : }
1711 0 : }
1712 :
1713 0 : void SwPagePreviewWin::RepaintCoreRect( const SwRect& rRect )
1714 : {
1715 : // #i24183#
1716 0 : if ( mpPgPreviewLayout->PreviewLayoutValid() )
1717 : {
1718 0 : mpPgPreviewLayout->Repaint( Rectangle( rRect.Pos(), rRect.SSize() ) );
1719 : }
1720 0 : }
1721 :
1722 : /** method to adjust preview to a new zoom factor
1723 :
1724 : #i19975# also consider zoom type - adding parameter <_eZoomType>
1725 : */
1726 0 : void SwPagePreviewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor,
1727 : const SvxZoomType _eZoomType )
1728 : {
1729 : // #i19975# consider zoom type
1730 0 : if ( _eZoomType == SVX_ZOOM_WHOLEPAGE )
1731 : {
1732 0 : mnRow = 1;
1733 0 : mnCol = 1;
1734 0 : mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize, true );
1735 : mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
1736 0 : mnSttPage, maPaintedPreviewDocRect );
1737 0 : SetSelectedPage( mnSttPage );
1738 0 : SetPagePreview(mnRow, mnCol);
1739 0 : maScale = GetMapMode().GetScaleX();
1740 : }
1741 0 : else if ( _nZoomFactor != 0 )
1742 : {
1743 : // calculate new scaling and set mapping mode appropriately.
1744 0 : Fraction aNewScale( _nZoomFactor, 100 );
1745 0 : MapMode aNewMapMode = GetMapMode();
1746 0 : aNewMapMode.SetScaleX( aNewScale );
1747 0 : aNewMapMode.SetScaleY( aNewScale );
1748 0 : SetMapMode( aNewMapMode );
1749 :
1750 : // calculate new start position for preview paint
1751 0 : Size aNewWinSize = PixelToLogic( maPxWinSize );
1752 : Point aNewPaintStartPos =
1753 0 : mpPgPreviewLayout->GetPreviewStartPosForNewScale( aNewScale, maScale, aNewWinSize );
1754 :
1755 : // remember new scaling and prepare preview paint
1756 : // Note: paint of preview will be performed by a corresponding invalidate
1757 : // due to property changes.
1758 0 : maScale = aNewScale;
1759 : mpPgPreviewLayout->Prepare( 0, aNewPaintStartPos, maPxWinSize,
1760 0 : mnSttPage, maPaintedPreviewDocRect );
1761 : }
1762 :
1763 0 : }
1764 :
1765 : /**
1766 : * pixel scrolling - horizontally always or vertically
1767 : * when less than the desired number of rows fits into
1768 : * the view
1769 : */
1770 0 : void SwPagePreviewWin::Scroll(long nXMove, long nYMove, sal_uInt16 /*nFlags*/)
1771 : {
1772 0 : maPaintedPreviewDocRect.Move(nXMove, nYMove);
1773 : mpPgPreviewLayout->Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
1774 : maPxWinSize, mnSttPage,
1775 0 : maPaintedPreviewDocRect );
1776 :
1777 0 : }
1778 :
1779 0 : bool SwPagePreview::HandleWheelCommands( const CommandEvent& rCEvt )
1780 : {
1781 0 : bool bOk = false;
1782 0 : const CommandWheelData* pWData = rCEvt.GetWheelData();
1783 0 : if( pWData && CommandWheelMode::ZOOM == pWData->GetMode() )
1784 : {
1785 : //only the Preference shouldn't control the Zoom, it is better to detect AT tools running. So the bridge can be used here
1786 0 : if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
1787 : {
1788 0 : sal_uInt16 nFactor = GetViewShell()->GetViewOptions()->GetZoom();
1789 0 : const sal_uInt16 nOffset = 10;
1790 0 : if( 0L > pWData->GetDelta() )
1791 : {
1792 0 : nFactor -= nOffset;
1793 0 : if(nFactor < MIN_PREVIEW_ZOOM)
1794 0 : nFactor = MIN_PREVIEW_ZOOM;
1795 : }
1796 : else
1797 : {
1798 0 : nFactor += nOffset;
1799 0 : if(nFactor > MAX_PREVIEW_ZOOM)
1800 0 : nFactor = MAX_PREVIEW_ZOOM;
1801 : }
1802 0 : SetZoom(SVX_ZOOM_PERCENT, nFactor);
1803 : }
1804 0 : bOk = true;
1805 : }
1806 : else
1807 0 : bOk = pViewWin->HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar );
1808 0 : return bOk;
1809 : }
1810 :
1811 : uno::Reference< ::com::sun::star::accessibility::XAccessible >
1812 0 : SwPagePreviewWin::CreateAccessible()
1813 : {
1814 0 : SolarMutexGuard aGuard; // this should have happened already!!!
1815 :
1816 : OSL_ENSURE( GetViewShell() != NULL, "We need a view shell" );
1817 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc = GetAccessible( false );
1818 0 : if (xAcc.is())
1819 : {
1820 0 : return xAcc;
1821 : }
1822 0 : if (mpViewShell)
1823 : {
1824 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccPreview = mpViewShell->CreateAccessiblePreview();
1825 0 : SetAccessible(xAccPreview);
1826 : }
1827 0 : return GetAccessible( false );
1828 : }
1829 :
1830 : // MT: Removed Windows::SwitchView() introduced with IA2 CWS.
1831 : // There are other notifications for this when the active view has chnaged, so please update the code to use that event mechanism
1832 0 : void SwPagePreviewWin::SwitchView()
1833 : {
1834 : #ifdef ACCESSIBLE_LAYOUT
1835 : if (!Application::IsAccessibilityEnabled())
1836 : {
1837 : return ;
1838 : }
1839 : if (mpViewShell)
1840 : {
1841 : mpViewShell->InvalidateAccessibleFocus();
1842 : }
1843 : #endif
1844 0 : }
1845 :
1846 0 : void SwPagePreview::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
1847 : {
1848 0 : GetViewShell()->ApplyAccessiblityOptions(rAccessibilityOptions);
1849 0 : }
1850 :
1851 0 : void SwPagePreview::ShowHScrollbar(bool bShow)
1852 : {
1853 0 : pHScrollbar->Show(bShow);
1854 0 : InvalidateBorder();
1855 0 : }
1856 :
1857 0 : void SwPagePreview::ShowVScrollbar(bool bShow)
1858 : {
1859 0 : pVScrollbar->Show(bShow);
1860 0 : InvalidateBorder();
1861 0 : }
1862 :
1863 0 : void SwPagePreview::EnableHScrollbar(bool bEnable)
1864 : {
1865 0 : if (mbHScrollbarEnabled != bEnable)
1866 : {
1867 0 : mbHScrollbarEnabled = bEnable;
1868 0 : ScrollViewSzChg();
1869 : }
1870 0 : }
1871 :
1872 0 : void SwPagePreview::EnableVScrollbar(bool bEnable)
1873 : {
1874 0 : if (mbVScrollbarEnabled != bEnable)
1875 : {
1876 0 : mbVScrollbarEnabled = bEnable;
1877 0 : ScrollViewSzChg();
1878 : }
1879 0 : }
1880 :
1881 0 : void SwPagePreview::SetZoom(SvxZoomType eType, sal_uInt16 nFactor)
1882 : {
1883 0 : SwViewShell& rSh = *GetViewShell();
1884 0 : SwViewOption aOpt(*rSh.GetViewOptions());
1885 : // perform action only on changes of zoom or zoom type.
1886 0 : if ( aOpt.GetZoom() != nFactor ||
1887 0 : aOpt.GetZoomType() != eType )
1888 : {
1889 0 : aOpt.SetZoom(nFactor);
1890 0 : aOpt.SetZoomType(eType);
1891 0 : rSh.ApplyViewOptions( aOpt );
1892 0 : lcl_InvalidateZoomSlots(GetViewFrame()->GetBindings());
1893 : // #i19975# also consider zoom type
1894 0 : pViewWin->AdjustPreviewToNewZoom( nFactor, eType );
1895 0 : ScrollViewSzChg();
1896 0 : }
1897 0 : }
1898 :
1899 : /** adjust position of vertical scrollbar
1900 :
1901 : @author OD
1902 : */
1903 0 : void SwPagePreview::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos )
1904 : {
1905 0 : if ( pVScrollbar )
1906 : {
1907 0 : pVScrollbar->SetThumbPos( _nNewThumbPos );
1908 : }
1909 270 : }
1910 :
1911 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|