merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uiview / pview.cxx
blob385cfdeee0aa24a482505c85f909ee7b9abce71f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pview.cxx,v $
10 * $Revision: 1.70 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <sfx2/objface.hxx>
37 #include <vcl/timer.hxx>
38 #include <vcl/field.hxx>
39 #include <vcl/fixed.hxx>
40 #include <vcl/help.hxx>
41 #include <vcl/cmdevt.hxx>
42 #include <vcl/button.hxx>
43 #include <svtools/printdlg.hxx>
44 #include <svtools/whiter.hxx>
45 #include <svtools/stritem.hxx>
46 #include <svtools/eitem.hxx>
47 #include <sfx2/printer.hxx>
48 #include <sfx2/app.hxx>
49 #include <sfx2/topfrm.hxx>
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/request.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <svx/stddlg.hxx>
55 #include <svx/paperinf.hxx>
56 #include <svx/srchitem.hxx>
57 #include <svx/svdview.hxx>
58 #include <svx/dlgutil.hxx>
59 #include <svx/zoomslideritem.hxx>
60 #ifndef _SVX_SVXIDS_HRC //autogen
61 #include <svx/svxids.hrc>
62 #endif
65 #include <swwait.hxx>
66 #include <globdoc.hxx>
67 #include <wdocsh.hxx>
68 #include <pvprtdat.hxx>
69 #include <swmodule.hxx>
70 #include <modcfg.hxx>
71 #include <wrtsh.hxx>
72 #include <docsh.hxx>
73 #include <viewopt.hxx>
74 #include <doc.hxx>
75 #include <pview.hxx>
76 #include <view.hxx>
77 #include <textsh.hxx>
78 #include <scroll.hxx>
79 #include <swprtopt.hxx>
80 #include <docstat.hxx>
81 #include <usrpref.hxx>
82 #include <viewfunc.hxx>
85 #ifndef _HELPID_H
86 #include <helpid.h>
87 #endif
88 #ifndef _CMDID_H
89 #include <cmdid.h>
90 #endif
91 #ifndef _GLOBALS_HRC
92 #include <globals.hrc>
93 #endif
94 #ifndef _POPUP_HRC
95 #include <popup.hrc>
96 #endif
97 #ifndef _PVIEW_HRC
98 #include <pview.hrc>
99 #endif
101 #define SwPagePreView
102 #include <sfx2/msg.hxx>
103 #include <swslots.hxx>
104 // OD 12.12.2002 #103492#
105 #include <pagepreviewlayout.hxx>
107 #include <svx/svxdlg.hxx>
108 #include <svx/dialogs.hrc>
109 #include <vos/mutex.hxx>
111 using namespace ::com::sun::star;
114 SFX_IMPL_VIEWFACTORY(SwPagePreView, SW_RES(STR_NONAME))
116 SFX_VIEW_REGISTRATION(SwDocShell);
117 SFX_VIEW_REGISTRATION(SwWebDocShell);
118 SFX_VIEW_REGISTRATION(SwGlobalDocShell);
121 SFX_IMPL_INTERFACE(SwPagePreView, SfxViewShell, SW_RES(RID_PVIEW_TOOLBOX))
123 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_PPREVIEW_POPUPMENU));
124 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|
125 SFX_VISIBILITY_CLIENT|SFX_VISIBILITY_FULLSCREEN|
126 SFX_VISIBILITY_READONLYDOC,
127 SW_RES(RID_PVIEW_TOOLBOX));
131 TYPEINIT1(SwPagePreView,SfxViewShell)
133 #define SWVIEWFLAGS ( SFX_VIEW_MAXIMIZE_FIRST|SFX_VIEW_OPTIMIZE_EACH| \
134 SFX_VIEW_CAN_PRINT|SFX_VIEW_HAS_PRINTOPTIONS )
136 #define MIN_PREVIEW_ZOOM 25
137 #define MAX_PREVIEW_ZOOM 600
138 /* \f */
139 /* -----------------26.11.2002 10:41-----------------
141 * --------------------------------------------------*/
142 USHORT lcl_GetNextZoomStep(USHORT nCurrentZoom, BOOL bZoomIn)
144 static USHORT aZoomArr[] =
146 25, 50, 75, 100, 150, 200, 400, 600
148 const sal_uInt16 nZoomArrSize = sizeof(aZoomArr)/sizeof(USHORT);
149 if(bZoomIn)
150 for(int i = nZoomArrSize - 1; i >= 0; --i)
152 if(nCurrentZoom > aZoomArr[i] || !i)
153 return aZoomArr[i];
155 else
156 for(int i = 0; i < nZoomArrSize; ++i)
158 if(nCurrentZoom < aZoomArr[i])
159 return aZoomArr[i];
161 return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM;
163 /* -----------------02.12.2002 09:11-----------------
165 * --------------------------------------------------*/
166 void lcl_InvalidateZoomSlots(SfxBindings& rBindings)
168 static USHORT __READONLY_DATA aInval[] =
170 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, FN_PREVIEW_ZOOM, FN_STAT_ZOOM,
173 rBindings.Invalidate( aInval );
175 /*--------------------------------------------------------------------
176 Beschreibung:
177 --------------------------------------------------------------------*/
179 // erstmal der Zoom-Dialog
181 class SwPreViewZoomDlg : public SvxStandardDialog
183 FixedText aRowLbl;
184 NumericField aRowEdit;
185 FixedText aColLbl;
186 NumericField aColEdit;
188 OKButton aOkBtn;
189 CancelButton aCancelBtn;
190 HelpButton aHelpBtn;
192 virtual void Apply();
194 public:
195 SwPreViewZoomDlg( SwPagePreViewWin& rParent );
196 ~SwPreViewZoomDlg();
199 /*--------------------------------------------------------------------
200 Beschreibung:
201 --------------------------------------------------------------------*/
204 SwPreViewZoomDlg::SwPreViewZoomDlg( SwPagePreViewWin& rParent ) :
205 SvxStandardDialog( &rParent, SW_RES(DLG_PAGEPREVIEW_ZOOM) ),
206 aRowLbl(this,SW_RES(FT_ROW)),
207 aRowEdit(this,SW_RES(ED_ROW)),
208 aColLbl(this,SW_RES(FT_COL)),
209 aColEdit(this,SW_RES(ED_COL)),
210 aOkBtn(this,SW_RES(BT_OK)),
211 aCancelBtn(this,SW_RES(BT_CANCEL)),
212 aHelpBtn(this,SW_RES(BT_HELP))
214 FreeResource();
216 aRowEdit.SetValue( rParent.GetRow() );
217 aColEdit.SetValue( rParent.GetCol() );
220 /*--------------------------------------------------------------------
221 Beschreibung:
222 --------------------------------------------------------------------*/
225 SwPreViewZoomDlg::~SwPreViewZoomDlg() {}
228 void SwPreViewZoomDlg::Apply()
230 ((SwPagePreViewWin*)GetParent())->CalcWish(
231 BYTE(aRowEdit.GetValue()),
232 BYTE(aColEdit.GetValue()) );
235 /* \f */
236 /* -----------------20.08.98 15:25-------------------
237 * Vorschau fuer den Seitendruck
238 * --------------------------------------------------*/
239 struct PrintSettingsStruct;
240 class PrtPrvWindow : public Window
242 const PrintSettingsStruct& rSettings;
244 virtual void Paint(const Rectangle&);
245 public :
246 PrtPrvWindow(Window* pParent, const ResId& rResId, const PrintSettingsStruct& rSett) :
247 Window(pParent, rResId), rSettings(rSett){}
249 /*--------------------------------------------------------------------
250 Beschreibung: Optionen fuer das Drucken der Preview
251 --------------------------------------------------------------------*/
252 struct PrintSettingsStruct
254 Size aPageMaxSize; // groesste Seite
255 Size aPrtSize; // Papiergroesse
256 Size aPrvPrtSize; // Groesse innerhalb der LRTB-Raender
257 Size aGridSize; // Groesse fuer jede Seite, enthaelt je
258 // die Haelfte von H- und V-Distance
260 long nLeft;
261 long nRight;
262 long nTop;
263 long nBottom;
264 long nHori;
265 long nVert;
267 USHORT nRows;
268 USHORT nCols;
270 BOOL bPrinterLandscape; // Ausrichtung
273 class SwPreviewPrintOptionsDialog : public SvxStandardDialog
275 FixedLine aRowColFL;
276 FixedText aRowsFT;
277 NumericField aRowsNF;
278 FixedText aColsFT;
279 NumericField aColsNF;
281 FixedLine aMarginFL;
282 FixedText aLSpaceFT;
283 MetricField aLSpaceMF;
284 FixedText aRSpaceFT;
285 MetricField aRSpaceMF;
286 FixedText aTSpaceFT;
287 MetricField aTSpaceMF;
288 FixedText aBSpaceFT;
289 MetricField aBSpaceMF;
290 FixedLine aDistanceFL;
291 FixedText aHSpaceFT;
292 MetricField aHSpaceMF;
293 FixedText aVSpaceFT;
294 MetricField aVSpaceMF;
296 RadioButton aLandscapeRB;
297 RadioButton aPortraitRB;
298 FixedLine aOrientationFL;
300 PrtPrvWindow aPreviewWin;
302 OKButton aOkBtn;
303 CancelButton aCancelBtn;
304 HelpButton aHelpBtn;
306 PushButton aStandardPB;
308 SwPagePreView& rPreView;
309 SwPagePreViewWin& rParentWin;
310 PrintSettingsStruct aSettings;
311 /* Size aPageMaxSize;
312 Size aPrtSize;
314 BOOL bOrientation;
316 BOOL bStandard;
318 virtual void Apply();
319 void FillControls(SwPagePreViewPrtData& rData);
321 DECL_LINK( ModifyHdl, Edit* );
322 DECL_LINK( StandardHdl, PushButton* );
324 public:
325 SwPreviewPrintOptionsDialog(SwPagePreViewWin& rParent, SwPagePreView& rView);
326 ~SwPreviewPrintOptionsDialog();
329 /* -----------------19.08.98 13:35-------------------
331 * --------------------------------------------------*/
332 SwPreviewPrintOptionsDialog::SwPreviewPrintOptionsDialog( SwPagePreViewWin& rParent, SwPagePreView& rView ) :
333 SvxStandardDialog( &rParent, SW_RES(DLG_PAGEPREVIEW_PRINTOPTIONS) ),
334 aRowColFL(this,SW_RES( FL_ROWCOL)),
335 aRowsFT(this,SW_RES( FT_ROWS)),
336 aRowsNF(this,SW_RES( NF_ROWS)),
337 aColsFT(this,SW_RES( FT_COLS)),
338 aColsNF(this,SW_RES( NF_COLS)),
339 aMarginFL(this,SW_RES( FL_MARGINS)),
340 aLSpaceFT(this,SW_RES( FT_LMARGIN)),
341 aLSpaceMF(this,SW_RES( MF_LMARGIN)),
342 aRSpaceFT(this,SW_RES( FT_RMARGIN)),
343 aRSpaceMF(this,SW_RES( MF_RMARGIN)),
344 aTSpaceFT(this,SW_RES( FT_TMARGIN)),
345 aTSpaceMF(this,SW_RES( MF_TMARGIN)),
346 aBSpaceFT(this,SW_RES( FT_BMARGIN)),
347 aBSpaceMF(this,SW_RES( MF_BMARGIN)),
348 aDistanceFL(this,SW_RES(FL_DISTANCE)),
349 aHSpaceFT(this,SW_RES( FT_HMARGIN)),
350 aHSpaceMF(this,SW_RES( MF_HMARGIN)),
351 aVSpaceFT(this,SW_RES( FT_VMARGIN)),
352 aVSpaceMF(this,SW_RES( MF_VMARGIN)),
353 aLandscapeRB(this,SW_RES( RB_LANDSCAPE)),
354 aPortraitRB(this,SW_RES( RB_PORTRAIT)),
355 aOrientationFL(this,SW_RES( FL_ORIENTATION)),
356 aPreviewWin(this,SW_RES( WIN_PREVIEW), aSettings),
357 aOkBtn(this,SW_RES(BT_OK)),
358 aCancelBtn(this,SW_RES(BT_CANCEL)),
359 aHelpBtn(this,SW_RES(BT_HELP)),
360 aStandardPB(this,SW_RES(PB_STANDARD)),
361 rPreView(rView),
362 rParentWin(rParent),
363 bStandard(TRUE)
365 FreeResource();
366 ViewShell& rViewSh = *rPreView.GetViewShell();
367 // OD 18.12.2002 #103492#
368 aSettings.aPageMaxSize = rViewSh.PagePreviewLayout()->GetMaxPageSize();
369 SfxPrinter* pPrinter = rViewSh.getIDocumentDeviceAccess()->getPrinter( true );
370 aSettings.aPrtSize = pPrinter->GetPaperSize();
371 //#97682# make sure that no division by zero occurs
372 if(!aSettings.aPrtSize.Width() || !aSettings.aPrtSize.Height())
373 aSettings.aPrtSize = SvxPaperInfo::GetPaperSize(PAPER_A4);
374 aSettings.bPrinterLandscape = pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE;
377 SwDocShell* pDocShell = rPreView.GetDocShell();
378 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(0 != PTR_CAST(SwWebDocShell, pDocShell));
379 FieldUnit eFieldUnit = pUsrPref->GetMetric();
380 ::SetFieldUnit( aLSpaceMF, eFieldUnit );
381 ::SetFieldUnit( aRSpaceMF, eFieldUnit );
382 ::SetFieldUnit( aTSpaceMF, eFieldUnit );
383 ::SetFieldUnit( aBSpaceMF, eFieldUnit );
384 ::SetFieldUnit( aHSpaceMF, eFieldUnit );
385 ::SetFieldUnit( aVSpaceMF, eFieldUnit );
387 SwDoc* pDoc = pDocShell->GetDoc();
388 SwPagePreViewPrtData aData;
389 if(pDoc->GetPreViewPrtData())
391 aData = *pDoc->GetPreViewPrtData();
392 bStandard = FALSE;
394 else
396 // Orientation der PreviewData an den Drucker anpassen
397 aData.SetLandscape(aSettings.bPrinterLandscape);
398 aData.SetRow(rParent.GetRow());
399 aData.SetCol(rParent.GetCol());
401 FillControls(aData);
403 aLSpaceMF.SaveValue();
404 aRSpaceMF.SaveValue();
405 aTSpaceMF.SaveValue();
406 aBSpaceMF.SaveValue();
407 aHSpaceMF.SaveValue();
408 aVSpaceMF.SaveValue();
409 aRowsNF.SaveValue();
410 aColsNF.SaveValue();
411 aLandscapeRB.SaveValue();
412 aPortraitRB.SaveValue();
414 aStandardPB.SetClickHdl(LINK(this, SwPreviewPrintOptionsDialog, StandardHdl));
415 Link aLk = LINK(this, SwPreviewPrintOptionsDialog, ModifyHdl);
416 aLSpaceMF.SetUpHdl(aLk);
417 aRSpaceMF.SetUpHdl(aLk);
418 aTSpaceMF.SetUpHdl(aLk);
419 aBSpaceMF.SetUpHdl(aLk);
420 aHSpaceMF.SetUpHdl(aLk);
421 aVSpaceMF.SetUpHdl(aLk);
422 aRowsNF.SetUpHdl(aLk);
423 aColsNF.SetUpHdl(aLk);
424 aLSpaceMF.SetDownHdl(aLk);
425 aRSpaceMF.SetDownHdl(aLk);
426 aTSpaceMF.SetDownHdl(aLk);
427 aBSpaceMF.SetDownHdl(aLk);
428 aHSpaceMF.SetDownHdl(aLk);
429 aVSpaceMF.SetDownHdl(aLk);
430 aRowsNF.SetDownHdl(aLk);
431 aColsNF.SetDownHdl(aLk);
432 aLSpaceMF.SetLoseFocusHdl(aLk);
433 aRSpaceMF.SetLoseFocusHdl(aLk);
434 aTSpaceMF.SetLoseFocusHdl(aLk);
435 aBSpaceMF.SetLoseFocusHdl(aLk);
436 aHSpaceMF.SetLoseFocusHdl(aLk);
437 aVSpaceMF.SetLoseFocusHdl(aLk);
438 aRowsNF.SetLoseFocusHdl(aLk);
439 aColsNF.SetLoseFocusHdl(aLk);
440 aLandscapeRB.SetClickHdl(aLk);
441 aPortraitRB.SetClickHdl(aLk);
443 ModifyHdl(0);
444 if(bStandard)
445 StandardHdl(&aStandardPB);
449 /* -----------------19.08.98 13:36-------------------
451 * --------------------------------------------------*/
452 SwPreviewPrintOptionsDialog::~SwPreviewPrintOptionsDialog()
455 /* -----------------12.11.98 11:32-------------------
457 * --------------------------------------------------*/
458 void SwPreviewPrintOptionsDialog::FillControls(SwPagePreViewPrtData& rData)
460 aLSpaceMF.SetValue(aLSpaceMF.Normalize(rData.GetLeftSpace() ), FUNIT_TWIP);
461 aRSpaceMF.SetValue(aRSpaceMF.Normalize(rData.GetRightSpace() ), FUNIT_TWIP);
462 aTSpaceMF.SetValue(aTSpaceMF.Normalize(rData.GetTopSpace() ), FUNIT_TWIP);
463 aBSpaceMF.SetValue(aBSpaceMF.Normalize(rData.GetBottomSpace()), FUNIT_TWIP);
464 aHSpaceMF.SetValue(aHSpaceMF.Normalize(rData.GetHorzSpace() ), FUNIT_TWIP);
465 aVSpaceMF.SetValue(aVSpaceMF.Normalize(rData.GetVertSpace() ), FUNIT_TWIP);
466 aRowsNF.SetValue(rData.GetRow());
467 aColsNF.SetValue(rData.GetCol());
468 aSettings.bPrinterLandscape ? aLandscapeRB.Check() : aPortraitRB.Check();
469 // wenn Drucker und Einstellungen nicht uebereinstimmen, dann Seiten tauschen
470 if( rData.GetLandscape() != aSettings.bPrinterLandscape )
472 Size aTmp(aSettings.aPrtSize.Height(), aSettings.aPrtSize.Width());
473 aSettings.aPrtSize = aTmp;
474 aSettings.bPrinterLandscape = !aSettings.bPrinterLandscape;
475 // nochmal setzen, denn auch wenn nur die Default-Orientierung dem Drucker
476 // angepasst wurde, sollen die Einstellungen gespeichert werden
477 aSettings.bPrinterLandscape ? aLandscapeRB.Check() : aPortraitRB.Check();
479 aLandscapeRB.SaveValue();
480 aPortraitRB.SaveValue();
482 aSettings.nLeft = rData.GetLeftSpace() ;
483 aSettings.nRight = rData.GetRightSpace() ;
484 aSettings.nTop = rData.GetTopSpace() ;
485 aSettings.nBottom = rData.GetBottomSpace();
486 aSettings.nHori = rData.GetHorzSpace() ;
487 aSettings.nVert = rData.GetVertSpace() ;
488 aSettings.nRows = rData.GetRow() ;
489 aSettings.nCols = rData.GetCol() ;
490 aSettings.aPrvPrtSize = aSettings.aPrtSize ;
493 /* -----------------19.08.98 14:31-------------------
495 * --------------------------------------------------*/
496 void SwPreviewPrintOptionsDialog::Apply()
499 SwDoc* pDoc = rPreView.GetDocShell()->GetDoc();
500 if(bStandard)
501 pDoc->SetPreViewPrtData(0);
502 else if( aLSpaceMF.GetSavedValue() != aLSpaceMF.GetText() ||
503 aRSpaceMF.GetSavedValue() != aRSpaceMF.GetText() ||
504 aTSpaceMF.GetSavedValue() != aTSpaceMF.GetText() ||
505 aBSpaceMF.GetSavedValue() != aBSpaceMF.GetText() ||
506 aHSpaceMF.GetSavedValue() != aHSpaceMF.GetText() ||
507 aVSpaceMF.GetSavedValue() != aVSpaceMF.GetText() ||
508 aRowsNF.GetSavedValue() != aRowsNF.GetText() ||
509 aColsNF.GetSavedValue() != aColsNF.GetText() ||
510 aLandscapeRB.GetSavedValue() != aLandscapeRB.IsChecked() ||
511 aPortraitRB.GetSavedValue() != aPortraitRB.IsChecked() )
513 SwPagePreViewPrtData aData;
514 if(pDoc->GetPreViewPrtData())
515 aData = *pDoc->GetPreViewPrtData();
516 aData.SetLeftSpace( static_cast< ULONG >(aLSpaceMF.Denormalize(aLSpaceMF.GetValue(FUNIT_TWIP))) );
517 aData.SetRightSpace( static_cast< ULONG >(aRSpaceMF.Denormalize(aRSpaceMF.GetValue(FUNIT_TWIP))) );
518 aData.SetTopSpace( static_cast< ULONG >(aTSpaceMF.Denormalize(aTSpaceMF.GetValue(FUNIT_TWIP))) );
519 aData.SetBottomSpace( static_cast< ULONG >(aBSpaceMF.Denormalize(aBSpaceMF.GetValue(FUNIT_TWIP))) );
521 aData.SetHorzSpace( static_cast< ULONG >(aHSpaceMF.Denormalize(aHSpaceMF.GetValue(FUNIT_TWIP))) );
522 aData.SetVertSpace( static_cast< ULONG >(aVSpaceMF.Denormalize(aVSpaceMF.GetValue(FUNIT_TWIP))) );
523 aData.SetRow((BYTE)aRowsNF.GetValue());
524 aData.SetCol((BYTE)aColsNF.GetValue());
525 aData.SetLandscape(aLandscapeRB.IsChecked());
527 ViewShell& rViewSh = *rPreView.GetViewShell();
528 SfxPrinter* pPrinter = rViewSh.getIDocumentDeviceAccess()->getPrinter( true );
529 if((pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE)
530 != aData.GetLandscape())
531 pPrinter->SetOrientation(aData.GetLandscape() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
534 pDoc->SetPreViewPrtData(&aData);
538 /* -----------------20.08.98 08:48-------------------
540 * --------------------------------------------------*/
541 IMPL_LINK( SwPreviewPrintOptionsDialog, ModifyHdl, Edit*, pEdit )
543 if(bStandard && pEdit)
545 aLSpaceMF.SetUserValue(aLSpaceMF.GetValue());
546 aRSpaceMF.SetUserValue(aRSpaceMF.GetValue());
547 aTSpaceMF.SetUserValue(aTSpaceMF.GetValue());
548 aBSpaceMF.SetUserValue(aBSpaceMF.GetValue());
549 aHSpaceMF.SetUserValue(aHSpaceMF.GetValue());
550 aVSpaceMF.SetUserValue(aVSpaceMF.GetValue());
551 aRowsNF. SetUserValue(aRowsNF .GetValue());
552 aColsNF. SetUserValue(aColsNF .GetValue());
554 bStandard = FALSE;
556 BOOL bOrientChanged = aSettings.bPrinterLandscape != aLandscapeRB.IsChecked();;
557 if(pEdit == &aLSpaceMF)
558 aSettings.nLeft = static_cast< long >(aLSpaceMF.Denormalize(aLSpaceMF.GetValue(FUNIT_TWIP)));
559 else if(pEdit == &aRSpaceMF)
560 aSettings.nRight = static_cast< long >(aRSpaceMF.Denormalize(aRSpaceMF.GetValue(FUNIT_TWIP)));
561 else if(pEdit == &aTSpaceMF)
562 aSettings.nTop = static_cast< long >(aTSpaceMF.Denormalize(aTSpaceMF.GetValue(FUNIT_TWIP)));
563 else if(pEdit == &aBSpaceMF)
564 aSettings.nBottom = static_cast< long >(aBSpaceMF.Denormalize(aBSpaceMF.GetValue(FUNIT_TWIP)));
565 else if(pEdit == &aHSpaceMF)
566 aSettings.nHori = static_cast< long >(aHSpaceMF.Denormalize(aHSpaceMF.GetValue(FUNIT_TWIP)));
567 else if(pEdit == &aVSpaceMF)
568 aSettings.nVert = static_cast< long >(aVSpaceMF.Denormalize(aVSpaceMF.GetValue(FUNIT_TWIP)));
569 else if(pEdit == &aRowsNF)
570 aSettings.nRows = (USHORT)aRowsNF.GetValue();
571 else if(pEdit == &aColsNF)
572 aSettings.nCols = (USHORT)aColsNF.GetValue();
573 else if(pEdit == (Edit*)&aLandscapeRB)
574 aSettings.bPrinterLandscape = aLandscapeRB.IsChecked();
575 else if(pEdit == (Edit*)&aPortraitRB)
576 aSettings.bPrinterLandscape = aLandscapeRB.IsChecked();
578 if(bOrientChanged)
580 Size aTmp(aSettings.aPrtSize.Height(), aSettings.aPrtSize.Width());
581 aSettings.aPrtSize = aTmp;
585 aSettings.aPrvPrtSize = Size(aSettings.aPrtSize.Width() - aSettings.nRight - aSettings.nLeft,
586 aSettings.aPrtSize.Height() - aSettings.nTop - aSettings.nBottom);
587 aSettings.aGridSize = Size(aSettings.aPrvPrtSize.Width() / aSettings.nCols,
588 aSettings.aPrvPrtSize.Height() / aSettings.nRows );
589 // was fehlt noch: Orientation auswerten, minimalrand ausrechnen, Beispiel fuettern
592 //am Ende Maximalwerte setzen
593 long n20Percent = aSettings.aPrtSize.Width() / 5;
594 aLSpaceMF.SetMax(aLSpaceMF.Normalize(aSettings.aPrtSize.Width() - aSettings.nRight - n20Percent), FUNIT_TWIP);
595 aRSpaceMF.SetMax(aRSpaceMF.Normalize(aSettings.aPrtSize.Width() - aSettings.nLeft - n20Percent), FUNIT_TWIP);
596 n20Percent = aSettings.aPrtSize.Height() / 5;
597 aTSpaceMF.SetMax(aTSpaceMF.Normalize(aSettings.aPrtSize.Height() - aSettings.nBottom - n20Percent), FUNIT_TWIP);
598 aBSpaceMF.SetMax(aBSpaceMF.Normalize(aSettings.aPrtSize.Height() - aSettings.nTop - n20Percent), FUNIT_TWIP);
600 long n80Percent = aSettings.aPrvPrtSize.Width() * 4 / 5;
601 aHSpaceMF.SetMax(aHSpaceMF.Normalize(n80Percent / aSettings.nRows), FUNIT_TWIP);
602 n80Percent = aSettings.aPrvPrtSize.Height()* 4 / 5;
603 aVSpaceMF.SetMax(aVSpaceMF.Normalize(n80Percent / aSettings.nCols), FUNIT_TWIP);
604 aHSpaceMF.Enable(aSettings.nCols > 1);
605 aVSpaceMF.Enable(aSettings.nRows > 1);
606 aRowsNF.SetMin(1);// nur damit auch nach Standard wieder der Inhalt angezeigt wird
607 aColsNF.SetMin(1);
610 aPreviewWin.Invalidate();
611 return 0;
613 /* -----------------28.08.98 14:59-------------------
615 * --------------------------------------------------*/
616 IMPL_LINK( SwPreviewPrintOptionsDialog, StandardHdl, PushButton*, EMPTYARG )
618 SetUpdateMode(TRUE);
619 SwPagePreViewPrtData aData;
620 aData.SetRow(rParentWin.GetRow());
621 aData.SetCol(rParentWin.GetCol());
622 FillControls(aData);
623 bStandard = TRUE;
624 aLSpaceMF.SetText(aEmptyStr);
625 aRSpaceMF.SetText(aEmptyStr);
626 aTSpaceMF.SetText(aEmptyStr);
627 aBSpaceMF.SetText(aEmptyStr);
628 aHSpaceMF.SetText(aEmptyStr);
629 aVSpaceMF.SetText(aEmptyStr);
630 aPreviewWin.Invalidate();
631 SetUpdateMode(FALSE);
632 return 0;
634 /* -----------------20.08.98 15:28-------------------
635 * Preview anzeigen
636 * --------------------------------------------------*/
637 void PrtPrvWindow::Paint(const Rectangle&)
639 Size aWinSize(GetOutputSizePixel());
640 long nWidth = rSettings.aPrtSize.Width();
641 long nHeight = rSettings.aPrtSize.Height();
642 BOOL bHoriValid = (aWinSize.Width() * 100 / aWinSize.Height()) <
643 (rSettings.aPrtSize.Width() * 100/ rSettings.aPrtSize.Height());
644 Fraction aXScale( aWinSize.Width(), Max( nWidth , 1L ) );
645 Fraction aYScale( aWinSize.Height(), Max( nHeight, 1L ) );
646 MapMode aMapMode( GetMapMode() );
647 aMapMode.SetScaleX( bHoriValid ? aXScale : aYScale);
648 aMapMode.SetScaleY( bHoriValid ? aXScale : aYScale);
649 SetMapMode( aMapMode );
651 aWinSize = GetOutputSize();
653 Point aOffset(0,0);
654 if(bHoriValid)
655 aOffset.Y() = (aWinSize.Height() - rSettings.aPrtSize.Height()) / 2;
656 else
657 aOffset.X() = (aWinSize.Width() - rSettings.aPrtSize.Width()) / 2;;
660 BOOL bUseSystemColors = SvtAccessibilityOptions().GetIsForPagePreviews()
661 && GetSettings().GetStyleSettings().GetHighContrastMode();
663 //der weisse Seitenhintergrund
664 Rectangle aRect(aOffset, rSettings.aPrtSize);
665 if(bUseSystemColors)
667 SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
668 SetLineColor( SwViewOption::GetFontColor() );
670 else
672 SetFillColor( Color( COL_WHITE ) );
673 SetLineColor(Color( COL_BLACK ) );
676 DrawRect(aRect);
678 Point aTL(aOffset);
679 aTL.X() += rSettings.nLeft;
680 aTL.Y() += rSettings.nTop;
682 Size aPrvPageSize((rSettings.aPrvPrtSize.Width() - (rSettings.nCols - 1) * rSettings.nHori) / rSettings.nCols,
683 (rSettings.aPrvPrtSize.Height() - (rSettings.nRows - 1) * rSettings.nVert) / rSettings.nRows);
684 // jetzt muss noch das unterschiedliche Groessenverhaeltnis berechnet werden, um es an
685 // der richtigen Seite abzuziehen.
686 //...
687 long nSourceScale = rSettings.aPageMaxSize.Width() * 100 / rSettings.aPageMaxSize.Height();
688 long nDestScale = aPrvPageSize.Width() * 100 / aPrvPageSize.Height() ;
689 if(nSourceScale > nDestScale) // die Seite ist relativ breiter als das vorhandene Rechteck
691 aPrvPageSize.Height() = aPrvPageSize.Width() * 100 / nSourceScale;
693 else
695 aPrvPageSize.Width() = aPrvPageSize.Height() * nSourceScale / 100;
698 if(bUseSystemColors)
699 SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
700 else
701 SetFillColor( Color( COL_GRAY ) );
704 aRect = Rectangle(aTL, aPrvPageSize);
705 for(USHORT i = 0; i < rSettings.nRows; i++)
707 for(USHORT j = 0; j < rSettings.nCols; j++)
709 DrawRect(aRect);
710 aRect.Move(aPrvPageSize.Width() + rSettings.nHori, 0);
713 aRect.Move( 0, aPrvPageSize.Height() + rSettings.nVert);
714 aRect.SetPos(Point(aTL.X(), aRect.TopLeft().Y()));
716 //rSettings;
719 /* \f */
720 /*--------------------------------------------------------------------
721 Beschreibung:
722 --------------------------------------------------------------------*/
724 // alles fuers SwPagePreViewWin
727 SwPagePreViewWin::SwPagePreViewWin( Window *pParent, SwPagePreView& rPView )
728 : Window( pParent, WinBits( WB_CLIPCHILDREN) ),
729 mpViewShell( 0 ),
730 mrView( rPView ),
731 mbCalcScaleForPreviewLayout( true ),
732 maPaintedPreviewDocRect( Rectangle(0,0,0,0) )
734 SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW ); //#106611#
735 SetHelpId(HID_PAGEPREVIEW);
736 SetFillColor( GetBackground().GetColor() );
737 SetLineColor( GetBackground().GetColor());
738 SetMapMode( MapMode(MAP_TWIP) );
740 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(FALSE);
741 mnRow = pUsrPref->GetPagePrevRow(); // 1 Zeile
742 mnCol = pUsrPref->GetPagePrevCol(); // 1 Spalte
743 // OD 24.03.2003 #108282# - member <mnVirtPage> no longer exists.
744 mnSttPage = USHRT_MAX;
747 /*--------------------------------------------------------------------
748 Beschreibung:
749 --------------------------------------------------------------------*/
752 SwPagePreViewWin::~SwPagePreViewWin()
754 if( mpViewShell )
755 delete mpViewShell;
758 /*--------------------------------------------------------------------
759 Beschreibung:
760 --------------------------------------------------------------------*/
763 void SwPagePreViewWin::Paint( const Rectangle& rRect )
765 if( !mpViewShell || !mpViewShell->GetLayout() )
766 return;
768 if( USHRT_MAX == mnSttPage ) // wurde noch nie berechnet ? (Init-Phase!)
770 // das ist die Size, auf die ich mich immer beziehe
771 if( !maPxWinSize.Height() || !maPxWinSize.Width() )
772 maPxWinSize = GetOutputSizePixel();
774 Rectangle aRect( LogicToPixel( rRect ));
775 mpPgPrevwLayout->Prepare( 1, Point(0,0), maPxWinSize,
776 mnSttPage, maPaintedPreviewDocRect );
777 SetSelectedPage( 1 );
778 mpPgPrevwLayout->Paint( PixelToLogic( aRect ) );
779 SetPagePreview(mnRow, mnCol);
781 else
783 MapMode aMM( GetMapMode() );
784 aMM.SetScaleX( maScale );
785 aMM.SetScaleY( maScale );
786 SetMapMode( aMM );
787 mpPgPrevwLayout->Paint( rRect );
791 /*--------------------------------------------------------------------
792 Beschreibung:
793 --------------------------------------------------------------------*/
794 void SwPagePreViewWin::CalcWish( BYTE nNewRow, BYTE nNewCol )
796 if( !mpViewShell || !mpViewShell->GetLayout() )
797 return;
799 USHORT nOldCol = mnCol;
800 // OD 02.12.2002 #103492# - update <mnRow> and <mnCol>.
801 mnRow = nNewRow;
802 mnCol = nNewCol;
803 USHORT nPages = mnRow * mnCol,
804 nLastSttPg = mrView.GetPageCount()+1 > nPages
805 ? mrView.GetPageCount()+1 - nPages : 0;
806 if( mnSttPage > nLastSttPg )
807 mnSttPage = nLastSttPg;
809 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
810 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
811 mnSttPage, maPaintedPreviewDocRect );
812 SetSelectedPage( mnSttPage );
813 SetPagePreview(mnRow, mnCol);
814 maScale = GetMapMode().GetScaleX();
816 // falls an der Spaltigkeit gedreht wurde, so muss der Sonderfall
817 // Einspaltig beachtet und ggfs. der Scrollbar korrigiert werden
818 if( (1 == nOldCol) ^ (1 == mnCol) )
819 mrView.ScrollDocSzChg();
821 // Sortierung muss eingehalten werden!!
822 // OD 24.03.2003 #108282# - additional invalidate page status.
823 static USHORT __READONLY_DATA aInval[] =
825 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN,
826 FN_PREVIEW_ZOOM,
827 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
828 FN_STAT_PAGE, FN_STAT_ZOOM,
829 FN_SHOW_TWO_PAGES, FN_SHOW_MULTIPLE_PAGES,
832 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
833 rBindings.Invalidate( aInval );
834 rBindings.Update( FN_SHOW_TWO_PAGES );
835 rBindings.Update( FN_SHOW_MULTIPLE_PAGES );
836 // OD 18.12.2002 #103492# - adjust scrollbars
837 mrView.ScrollViewSzChg();
839 /*--------------------------------------------------------------------
840 Beschreibung:, mnSttPage is Absolute
841 --------------------------------------------------------------------*/
844 int SwPagePreViewWin::MovePage( int eMoveMode )
846 // soviele Seiten hoch
847 USHORT nPages = mnRow * mnCol;
848 USHORT nNewSttPage = mnSttPage;
849 // OD 04.12.2002 #103492#
850 USHORT nPageCount = mrView.GetPageCount();
851 USHORT nDefSttPg = GetDefSttPage();
852 // OD 06.12.2002 #103492#
853 bool bPaintPageAtFirstCol = true;
855 switch( eMoveMode )
857 case MV_PAGE_UP:
859 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
860 const sal_uInt16 nNewAbsSttPage = nRelSttPage - nPages > 0 ?
861 mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage - nPages ) :
862 nDefSttPg;
863 nNewSttPage = nNewAbsSttPage;
865 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
866 const sal_uInt16 nNewRelSelPage = nRelSelPage - nPages > 0 ?
867 nRelSelPage - nPages :
869 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewRelSelPage ) );
871 break;
873 case MV_PAGE_DOWN:
875 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
876 const sal_uInt16 nNewAbsSttPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage + nPages );
877 nNewSttPage = nNewAbsSttPage < nPageCount ? nNewAbsSttPage : nPageCount;
879 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
880 const sal_uInt16 nNewAbsSelPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSelPage + nPages );
881 SetSelectedPage( nNewAbsSelPage < nPageCount ? nNewAbsSelPage : nPageCount );
883 break;
885 case MV_DOC_STT:
886 nNewSttPage = nDefSttPg;
887 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewSttPage ? nNewSttPage : 1 ) );
888 break;
889 case MV_DOC_END:
890 // OD 03.12.2002 #103492# - correct calculation of new start page.
891 nNewSttPage = nPageCount;
892 SetSelectedPage( nPageCount );
893 break;
894 // OD 12.12.2002 #103492# - add new move mode
895 case MV_SELPAGE:
896 // <nNewSttPage> and <SelectedPage()> are already set.
897 // OD 20.02.2003 #107369# - not start at first column, only if the
898 // complete preview layout columns doesn't fit into window.
899 if ( !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() )
900 bPaintPageAtFirstCol = false;
901 break;
902 case MV_SCROLL:
903 // OD 17.01.2003 #103492# - check, if paint page at first column
904 // has to be avoided
905 if ( !mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() ||
906 !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() )
907 bPaintPageAtFirstCol = false;
908 break;
909 case MV_NEWWINSIZE:
910 // OD 18.12.2002 #103492# - nothing special to do.
911 break;
912 case MV_CALC:
913 // OD 18.12.2002 #103492# - re-init page preview layout.
914 mpPgPrevwLayout->ReInit();
916 // OD 03.12.2002 #103492# - correct calculation of new start page.
917 if( nNewSttPage > nPageCount )
918 nNewSttPage = nPageCount;
920 // OD 18.12.2002 #103492# - correct selected page number
921 if( SelectedPage() > nPageCount )
922 SetSelectedPage( nNewSttPage ? nNewSttPage : 1 );
925 mpPgPrevwLayout->Prepare( nNewSttPage, Point(0,0), maPxWinSize,
926 nNewSttPage,
927 maPaintedPreviewDocRect, bPaintPageAtFirstCol );
928 if( nNewSttPage == mnSttPage &&
929 eMoveMode != MV_SELPAGE )
930 return FALSE;
932 SetPagePreview(mnRow, mnCol);
933 mnSttPage = nNewSttPage;
935 // OD 24.03.2003 #108282# - additional invalidate page status.
936 static USHORT __READONLY_DATA aInval[] =
938 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
939 FN_STAT_PAGE, 0
942 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
943 rBindings.Invalidate( aInval );
945 return TRUE;
948 /*--------------------------------------------------------------------
949 Beschreibung:
950 --------------------------------------------------------------------*/
953 void SwPagePreViewWin::SetWinSize( const Size& rNewSize )
955 // die Size wollen wir aber immer in Pixel-Einheiten haben
956 maPxWinSize = LogicToPixel( rNewSize );
958 if( USHRT_MAX == mnSttPage )
960 mnSttPage = GetDefSttPage();
961 SetSelectedPage( GetDefSttPage() );
964 if ( mbCalcScaleForPreviewLayout )
966 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
967 maScale = GetMapMode().GetScaleX();
969 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
970 mnSttPage, maPaintedPreviewDocRect );
971 if ( mbCalcScaleForPreviewLayout )
973 SetSelectedPage( mnSttPage );
974 mbCalcScaleForPreviewLayout = false;
976 SetPagePreview(mnRow, mnCol);
977 maScale = GetMapMode().GetScaleX();
981 /*--------------------------------------------------------------------
982 Beschreibung:
983 --------------------------------------------------------------------*/
986 void SwPagePreViewWin::GetStatusStr( String& rStr, USHORT nPageCnt ) const
988 // OD 24.03.2003 #108282# - show physical and virtual page number of
989 // selected page, if it's visible.
990 sal_uInt16 nPageNum;
991 if ( mpPgPrevwLayout->IsPageVisible( mpPgPrevwLayout->SelectedPage() ) )
993 nPageNum = mpPgPrevwLayout->SelectedPage();
995 else
997 nPageNum = mnSttPage > 1 ? mnSttPage : 1;
999 sal_uInt16 nVirtPageNum = mpPgPrevwLayout->GetVirtPageNumByPageNum( nPageNum );
1000 if( nVirtPageNum && nVirtPageNum != nPageNum )
1002 rStr += String::CreateFromInt32( nVirtPageNum );
1003 rStr += ' ';
1005 rStr += String::CreateFromInt32( nPageNum );
1006 rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" / "));
1007 rStr += String::CreateFromInt32( nPageCnt );
1010 /*--------------------------------------------------------------------
1011 Beschreibung:
1012 --------------------------------------------------------------------*/
1015 void SwPagePreViewWin::KeyInput( const KeyEvent &rKEvt )
1017 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
1018 USHORT nKey = rKeyCode.GetCode();
1019 BOOL bHandled = FALSE;
1020 if(!rKeyCode.GetModifier())
1022 USHORT nSlot = 0;
1023 switch(nKey)
1025 case KEY_ADD : nSlot = SID_ZOOM_OUT; break;
1026 case KEY_ESCAPE: nSlot = FN_CLOSE_PAGEPREVIEW; break;
1027 case KEY_SUBTRACT : nSlot = SID_ZOOM_IN; break;
1029 if(nSlot)
1031 bHandled = TRUE;
1032 mrView.GetViewFrame()->GetDispatcher()->Execute(
1033 nSlot, SFX_CALLMODE_ASYNCHRON );
1036 if( !bHandled && !mrView.KeyInput( rKEvt ) )
1037 Window::KeyInput( rKEvt );
1040 /******************************************************************************
1041 * Beschreibung:
1042 ******************************************************************************/
1044 void SwPagePreViewWin::Command( const CommandEvent& rCEvt )
1046 BOOL bCallBase = TRUE;
1047 switch( rCEvt.GetCommand() )
1049 case COMMAND_CONTEXTMENU:
1050 mrView.GetViewFrame()->GetDispatcher()->ExecutePopup();
1051 bCallBase = FALSE;
1052 break;
1054 case COMMAND_WHEEL:
1055 case COMMAND_STARTAUTOSCROLL:
1056 case COMMAND_AUTOSCROLL:
1058 const CommandWheelData* pData = rCEvt.GetWheelData();
1059 if( pData )
1061 const CommandWheelData aDataNew(pData->GetDelta(),pData->GetNotchDelta(),COMMAND_WHEEL_PAGESCROLL,
1062 pData->GetMode(),pData->GetModifier(),pData->IsHorz());
1063 const CommandEvent aEvent( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),rCEvt.IsMouseEvent(),&aDataNew);
1064 bCallBase = !mrView.HandleWheelCommands( aEvent );
1066 else
1067 bCallBase = !mrView.HandleWheelCommands( rCEvt );
1069 break;
1070 default:
1071 // OD 17.12.2002 #103492# - delete assertion
1075 if( bCallBase )
1076 Window::Command( rCEvt );
1079 void SwPagePreViewWin::MouseButtonDown( const MouseEvent& rMEvt )
1081 // OD 17.12.2002 #103492# - consider single-click to set selected page
1082 if( MOUSE_LEFT == ( rMEvt.GetModifier() + rMEvt.GetButtons() ) )
1084 Point aPrevwPos( PixelToLogic( rMEvt.GetPosPixel() ) );
1085 Point aDocPos;
1086 bool bPosInEmptyPage;
1087 sal_uInt16 nNewSelectedPage;
1088 bool bIsDocPos =
1089 mpPgPrevwLayout->IsPrevwPosInDocPrevwPage( aPrevwPos,
1090 aDocPos, bPosInEmptyPage, nNewSelectedPage );
1091 if ( bIsDocPos && rMEvt.GetClicks() == 2 )
1093 // close page preview, set new cursor position and switch to
1094 // normal view.
1095 String sNewCrsrPos( String::CreateFromInt32( aDocPos.X() ));
1096 ((( sNewCrsrPos += ';' )
1097 += String::CreateFromInt32( aDocPos.Y() )) )
1098 += ';';
1099 mrView.SetNewCrsrPos( sNewCrsrPos );
1101 SfxViewFrame *pTmpFrm = mrView.GetViewFrame();
1102 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
1103 SFX_CALLMODE_ASYNCHRON );
1105 else if ( bIsDocPos || bPosInEmptyPage )
1106 // OD 2004-03-04 #i20684# - add missing parenthesis
1108 // show clicked page as the selected one
1109 mpPgPrevwLayout->MarkNewSelectedPage( nNewSelectedPage );
1110 GetViewShell()->ShowPreViewSelection( nNewSelectedPage );
1111 // OD 19.02.2003 #107369# - adjust position at vertical scrollbar.
1112 if ( mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() )
1114 mrView.SetVScrollbarThumbPos( nNewSelectedPage );
1116 // OD 24.03.2003 #108282# - invalidate page status.
1117 static USHORT __READONLY_DATA aInval[] =
1119 FN_STAT_PAGE, 0
1121 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
1122 rBindings.Invalidate( aInval );
1127 /******************************************************************************
1128 * Beschreibung: Userprefs bzw Viewoptions setzen
1129 ******************************************************************************/
1132 void SwPagePreViewWin::SetPagePreview( BYTE nRow, BYTE nCol )
1134 SwMasterUsrPref *pOpt = (SwMasterUsrPref *)SW_MOD()->GetUsrPref(FALSE);
1136 if (nRow != pOpt->GetPagePrevRow() || nCol != pOpt->GetPagePrevCol())
1138 pOpt->SetPagePrevRow( nRow );
1139 pOpt->SetPagePrevCol( nCol );
1140 pOpt->SetModified();
1142 //Scrollbar updaten!
1143 mrView.ScrollViewSzChg();
1147 /** get selected page in document preview
1149 OD 13.12.2002 #103492#
1151 @author OD
1153 sal_uInt16 SwPagePreViewWin::SelectedPage() const
1155 return mpPgPrevwLayout->SelectedPage();
1158 /** set selected page number in document preview
1160 OD 13.12.2002 #103492#
1162 @author OD
1164 void SwPagePreViewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum )
1166 mpPgPrevwLayout->SetSelectedPage( _nSelectedPageNum );
1169 /** method to enable/disable book preview
1171 OD 2004-03-05 #i18143#
1173 @author OD
1175 bool SwPagePreViewWin::SetBookPreviewMode( const bool _bBookPreview )
1177 return mpPgPrevwLayout->SetBookPreviewMode( _bBookPreview,
1178 mnSttPage,
1179 maPaintedPreviewDocRect );
1182 void SwPagePreViewWin::DataChanged( const DataChangedEvent& rDCEvt )
1184 Window::DataChanged( rDCEvt );
1186 switch( rDCEvt.GetType() )
1188 case DATACHANGED_SETTINGS:
1189 // ScrollBars neu anordnen bzw. Resize ausloesen, da sich
1190 // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im
1191 // Resize-Handler aber auch die Groesse der ScrollBars aus
1192 // den Settings abgefragt werden.
1193 if( rDCEvt.GetFlags() & SETTINGS_STYLE )
1194 mrView.InvalidateBorder(); //Scrollbarbreiten
1195 //#106746# zoom has to be disabled if Accessibility support is switched on
1196 lcl_InvalidateZoomSlots(mrView.GetViewFrame()->GetBindings());
1197 break;
1199 case DATACHANGED_PRINTER:
1200 case DATACHANGED_DISPLAY:
1201 case DATACHANGED_FONTS:
1202 case DATACHANGED_FONTSUBSTITUTION:
1203 mrView.GetDocShell()->UpdateFontList(); //Fontwechsel
1204 if ( mpViewShell->GetWin() )
1205 mpViewShell->GetWin()->Invalidate();
1206 break;
1210 /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN
1212 OD 04.03.2003 #107369#
1214 @author OD
1216 void SwPagePreView::_ExecPgUpAndPgDown( const bool _bPgUp,
1217 SfxRequest* _pReq )
1219 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
1220 // check, if top/bottom of preview is *not* already visible.
1221 if( pPagePrevwLay->GetWinPagesScrollAmount( _bPgUp ? -1 : 1 ) != 0 )
1223 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() &&
1224 pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() )
1226 const int eMvMode = _bPgUp ?
1227 SwPagePreViewWin::MV_PAGE_UP :
1228 SwPagePreViewWin::MV_PAGE_DOWN;
1229 if ( ChgPage( eMvMode, TRUE ) )
1230 aViewWin.Invalidate();
1232 else
1234 SwTwips nScrollAmount;
1235 sal_uInt16 nNewSelectedPageNum = 0;
1236 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
1237 if( _bPgUp )
1239 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() )
1241 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( -1 );
1242 if ( (aViewWin.SelectedPage() - nVisPages) > 0 )
1243 nNewSelectedPageNum = aViewWin.SelectedPage() - nVisPages;
1244 else
1245 nNewSelectedPageNum = 1;
1247 else
1248 nScrollAmount = - Min( aViewWin.GetOutputSize().Height(),
1249 aViewWin.GetPaintedPreviewDocRect().Top() );
1251 else
1253 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() )
1255 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( 1 );
1256 if ( (aViewWin.SelectedPage() + nVisPages) <= mnPageCount )
1257 nNewSelectedPageNum = aViewWin.SelectedPage() + nVisPages;
1258 else
1259 nNewSelectedPageNum = mnPageCount;
1261 else
1262 nScrollAmount = Min( aViewWin.GetOutputSize().Height(),
1263 ( pPagePrevwLay->GetPrevwDocSize().Height() -
1264 aViewWin.GetPaintedPreviewDocRect().Bottom() ) );
1266 aViewWin.Scroll( 0, nScrollAmount );
1267 if ( nNewSelectedPageNum != 0 )
1269 aViewWin.SetSelectedPage( nNewSelectedPageNum );
1271 ScrollViewSzChg();
1272 // OD 24.03.2003 #108282# - additional invalidate page status.
1273 static USHORT __READONLY_DATA aInval[] =
1275 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
1276 FN_STAT_PAGE, 0
1278 SfxBindings& rBindings = GetViewFrame()->GetBindings();
1279 rBindings.Invalidate( aInval );
1280 aViewWin.Invalidate();
1284 if ( _pReq )
1285 _pReq->Done();
1288 /*--------------------------------------------------------------------
1289 Beschreibung:
1290 --------------------------------------------------------------------*/
1291 // dann mal alles fuer die SwPagePreView
1292 void SwPagePreView::Execute( SfxRequest &rReq )
1294 int eMvMode;
1295 BYTE nRow = 1;
1296 BOOL bRetVal = FALSE;
1297 bool bRefresh = true;
1299 switch(rReq.GetSlot())
1301 case FN_REFRESH_VIEW:
1302 case FN_STAT_PAGE:
1303 case FN_STAT_ZOOM:
1304 break;
1306 case FN_SHOW_MULTIPLE_PAGES:
1308 const SfxItemSet *pArgs = rReq.GetArgs();
1309 if( pArgs && pArgs->Count() >= 2 )
1311 BYTE nCols = (BYTE)((SfxUInt16Item &)pArgs->Get(
1312 SID_ATTR_TABLE_COLUMN)).GetValue();
1313 BYTE nRows = (BYTE)((SfxUInt16Item &)pArgs->Get(
1314 SID_ATTR_TABLE_ROW)).GetValue();
1315 aViewWin.CalcWish( nRows, nCols );
1318 else
1319 SwPreViewZoomDlg( aViewWin ).Execute();
1322 break;
1323 case FN_SHOW_BOOKVIEW:
1325 const SfxItemSet* pArgs = rReq.GetArgs();
1326 const SfxPoolItem* pItem;
1327 bool bBookPreview = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
1328 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_SHOW_BOOKVIEW, FALSE, &pItem ) )
1330 bBookPreview = static_cast< const SfxBoolItem* >( pItem )->GetValue();
1331 ( ( SwViewOption* ) GetViewShell()->GetViewOptions() )->SetPagePrevBookview( bBookPreview );
1332 // cast is not gentleman like, but it's common use in writer and in this case
1334 if ( aViewWin.SetBookPreviewMode( bBookPreview ) )
1336 // book preview mode changed. Thus, adjust scrollbars and
1337 // invalidate corresponding states.
1338 ScrollViewSzChg();
1339 static USHORT __READONLY_DATA aInval[] =
1341 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
1342 FN_STAT_PAGE, FN_SHOW_BOOKVIEW, 0
1344 SfxBindings& rBindings = GetViewFrame()->GetBindings();
1345 rBindings.Invalidate( aInval );
1346 aViewWin.Invalidate();
1350 break;
1351 case FN_SHOW_TWO_PAGES:
1352 aViewWin.CalcWish( nRow, 2 );
1353 break;
1355 case FN_PREVIEW_ZOOM:
1356 case SID_ATTR_ZOOM:
1358 const SfxItemSet *pArgs = rReq.GetArgs();
1359 const SfxPoolItem* pItem;
1360 AbstractSvxZoomDialog *pDlg = 0;
1361 if(!pArgs)
1363 SfxItemSet aCoreSet(GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
1364 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1365 SvxZoomItem aZoom( (SvxZoomType)pVOpt->GetZoomType(),
1366 pVOpt->GetZoom() );
1367 aZoom.SetValueSet(
1368 SVX_ZOOM_ENABLE_50|
1369 SVX_ZOOM_ENABLE_75|
1370 SVX_ZOOM_ENABLE_100|
1371 SVX_ZOOM_ENABLE_150|
1372 SVX_ZOOM_ENABLE_200|
1373 SVX_ZOOM_ENABLE_WHOLEPAGE);
1374 aCoreSet.Put( aZoom );
1376 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1377 if(pFact)
1379 pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aCoreSet, RID_SVXDLG_ZOOM);
1380 DBG_ASSERT(pDlg, "Dialogdiet fail!");
1383 pDlg->SetLimits( MINZOOM, MAXZOOM );
1385 if( pDlg->Execute() != RET_CANCEL )
1386 pArgs = pDlg->GetOutputItemSet();
1388 if( pArgs )
1390 enum SvxZoomType eType = SVX_ZOOM_PERCENT;
1391 USHORT nZoomFactor = USHRT_MAX;
1392 if(SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOM, TRUE, &pItem))
1394 eType = ((const SvxZoomItem *)pItem)->GetType();
1395 nZoomFactor = ((const SvxZoomItem *)pItem)->GetValue();
1397 else if(SFX_ITEM_SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, TRUE, &pItem))
1398 nZoomFactor = ((const SfxUInt16Item *)pItem)->GetValue();
1399 if(USHRT_MAX != nZoomFactor)
1400 SetZoom(eType, nZoomFactor);
1402 delete pDlg;
1404 break;
1405 case SID_ATTR_ZOOMSLIDER :
1407 const SfxItemSet *pArgs = rReq.GetArgs();
1408 const SfxPoolItem* pItem;
1410 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, TRUE, &pItem ) )
1412 const USHORT nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
1413 SetZoom( SVX_ZOOM_PERCENT, nCurrentZoom );
1416 break;
1417 case SID_ZOOM_IN:
1418 case SID_ZOOM_OUT:
1420 enum SvxZoomType eType = SVX_ZOOM_PERCENT;
1421 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1422 SetZoom(eType,
1423 lcl_GetNextZoomStep(pVOpt->GetZoom(), SID_ZOOM_IN == rReq.GetSlot()));
1425 break;
1426 case FN_CHAR_LEFT:
1427 case FN_CHAR_RIGHT:
1428 case FN_LINE_UP:
1429 case FN_LINE_DOWN:
1431 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
1432 sal_uInt16 nNewSelectedPage;
1433 sal_uInt16 nNewStartPage;
1434 Point aNewStartPos;
1435 sal_Int16 nHoriMove = 0;
1436 sal_Int16 nVertMove = 0;
1437 switch(rReq.GetSlot())
1439 case FN_CHAR_LEFT: nHoriMove = -1; break;
1440 case FN_CHAR_RIGHT: nHoriMove = 1; break;
1441 case FN_LINE_UP: nVertMove = -1; break;
1442 case FN_LINE_DOWN: nVertMove = 1; break;
1444 pPagePrevwLay->CalcStartValuesForSelectedPageMove( nHoriMove, nVertMove,
1445 nNewSelectedPage, nNewStartPage, aNewStartPos );
1446 if ( aViewWin.SelectedPage() != nNewSelectedPage )
1448 if ( pPagePrevwLay->IsPageVisible( nNewSelectedPage ) )
1450 pPagePrevwLay->MarkNewSelectedPage( nNewSelectedPage );
1451 // OD 19.02.2003 #107369# - adjust position at vertical scrollbar.
1452 SetVScrollbarThumbPos( nNewSelectedPage );
1453 bRefresh = false;
1455 else
1457 aViewWin.SetSelectedPage( nNewSelectedPage );
1458 aViewWin.SetSttPage( nNewStartPage );
1459 int nRet = ChgPage( SwPagePreViewWin::MV_SELPAGE, TRUE );
1460 bRefresh = 0 != nRet;
1462 GetViewShell()->ShowPreViewSelection( nNewSelectedPage );
1463 // OD 24.03.2003 #108282# - invalidate page status.
1464 static USHORT __READONLY_DATA aInval[] =
1466 FN_STAT_PAGE, 0
1468 SfxBindings& rBindings = GetViewFrame()->GetBindings();
1469 rBindings.Invalidate( aInval );
1470 rReq.Done();
1472 else
1474 bRefresh = false;
1476 break;
1478 case FN_PAGEUP:
1479 case FN_PAGEDOWN:
1481 _ExecPgUpAndPgDown( rReq.GetSlot() == FN_PAGEUP, &rReq );
1482 break;
1484 case FN_START_OF_LINE:
1485 case FN_START_OF_DOCUMENT:
1486 aViewWin.SetSelectedPage( 1 );
1487 eMvMode = SwPagePreViewWin::MV_DOC_STT; bRetVal = TRUE; goto MOVEPAGE;
1488 case FN_END_OF_LINE:
1489 case FN_END_OF_DOCUMENT:
1490 aViewWin.SetSelectedPage( mnPageCount );
1491 eMvMode = SwPagePreViewWin::MV_DOC_END; bRetVal = TRUE; goto MOVEPAGE;
1492 MOVEPAGE:
1494 int nRet = ChgPage( eMvMode, TRUE );
1495 // return value fuer Basic
1496 if(bRetVal)
1497 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), nRet == 0));
1499 bRefresh = 0 != nRet;
1500 rReq.Done();
1502 break;
1504 case FN_PRINT_PAGEPREVIEW:
1506 const SwPagePreViewPrtData* pPPVPD = aViewWin.GetViewShell()->GetDoc()->GetPreViewPrtData();
1507 // die Sache mit der Orientation
1508 if(pPPVPD)
1510 SfxPrinter* pPrinter = GetPrinter( TRUE );
1511 if((pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE)
1512 != pPPVPD->GetLandscape())
1513 pPrinter->SetOrientation(pPPVPD->GetLandscape() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
1515 ::SetAppPrintOptions( aViewWin.GetViewShell(), FALSE );
1516 bNormalPrint = FALSE;
1517 USHORT nPrtSlot = SID_PRINTDOC;
1518 rReq.SetSlot( nPrtSlot );
1519 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
1520 rReq.SetSlot( FN_PRINT_PAGEPREVIEW );
1521 return;
1523 case FN_PREVIEW_PRINT_OPTIONS :
1525 SwPreviewPrintOptionsDialog aDlg(aViewWin, *this);
1526 aDlg.Execute();
1528 break;
1529 case SID_PRINTDOCDIRECT:
1530 case SID_PRINTDOC:
1531 ::SetAppPrintOptions( aViewWin.GetViewShell(), FALSE );
1532 bNormalPrint = TRUE;
1533 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
1534 return;
1535 case FN_CLOSE_PAGEPREVIEW:
1536 case SID_PRINTPREVIEW:
1537 // print preview is now always in the same frame as the tab view
1538 // -> always switch this frame back to normal view
1539 // (ScTabViewShell ctor reads stored view data)
1540 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, 0, 0, SFX_CALLMODE_ASYNCHRON );
1541 break;
1542 case FN_INSERT_BREAK:
1544 USHORT nSelPage = aViewWin.SelectedPage();
1545 //if a dummy page is selected (e.g. a non-existing right/left page)
1546 //the direct neighbor is used
1547 if(GetViewShell()->IsDummyPage( nSelPage ) && GetViewShell()->IsDummyPage( --nSelPage ))
1548 nSelPage +=2;
1549 SetNewPage( nSelPage );
1550 SfxViewFrame *pTmpFrm = GetViewFrame();
1551 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
1552 SFX_CALLMODE_ASYNCHRON );
1554 break;
1555 default:
1556 ASSERT(!this, falscher Dispatcher);
1557 return;
1560 if( bRefresh )
1561 aViewWin.Invalidate();
1564 /*--------------------------------------------------------------------
1565 Beschreibung:
1566 --------------------------------------------------------------------*/
1569 void SwPagePreView::GetState( SfxItemSet& rSet )
1571 SfxWhichIter aIter(rSet);
1572 BYTE nRow = 1;
1573 USHORT nWhich = aIter.FirstWhich();
1574 ASSERT(nWhich, leeres Set);
1575 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
1576 //#106746# zoom has to be disabled if Accessibility support is switched on
1577 BOOL bZoomEnabled = !Application::GetSettings().GetMiscSettings().GetEnableATToolSupport();
1579 while(nWhich)
1581 switch(nWhich)
1583 case SID_BROWSER_MODE:
1584 case FN_PRINT_LAYOUT:
1585 rSet.DisableItem(nWhich);
1586 break;
1587 case FN_START_OF_DOCUMENT:
1589 if ( pPagePrevwLay->IsPageVisible( 1 ) )
1590 rSet.DisableItem(nWhich);
1591 break;
1593 case FN_END_OF_DOCUMENT:
1595 if ( pPagePrevwLay->IsPageVisible( mnPageCount ) )
1596 rSet.DisableItem(nWhich);
1597 break;
1599 case FN_PAGEUP:
1601 if( pPagePrevwLay->GetWinPagesScrollAmount( -1 ) == 0 )
1602 rSet.DisableItem(nWhich);
1603 break;
1605 case FN_PAGEDOWN:
1607 if( pPagePrevwLay->GetWinPagesScrollAmount( 1 ) == 0 )
1608 rSet.DisableItem(nWhich);
1609 break;
1612 case FN_STAT_PAGE:
1614 String aStr( sPageStr );
1615 aViewWin.GetStatusStr( aStr, mnPageCount );
1616 rSet.Put( SfxStringItem( nWhich, aStr) );
1618 break;
1620 case SID_ATTR_ZOOM:
1621 case FN_STAT_ZOOM:
1623 if(bZoomEnabled)
1625 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1626 SvxZoomItem aZoom((SvxZoomType)pVOpt->GetZoomType(),
1627 pVOpt->GetZoom());
1628 aZoom.SetValueSet(
1629 SVX_ZOOM_ENABLE_50|
1630 SVX_ZOOM_ENABLE_75|
1631 SVX_ZOOM_ENABLE_100|
1632 SVX_ZOOM_ENABLE_150|
1633 SVX_ZOOM_ENABLE_200);
1634 rSet.Put( aZoom );
1636 else
1637 rSet.DisableItem(nWhich);
1639 break;
1640 case SID_ATTR_ZOOMSLIDER :
1642 if(bZoomEnabled)
1644 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1645 const USHORT nCurrentZoom = pVOpt->GetZoom();
1646 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM );
1647 aZoomSliderItem.AddSnappingPoint( 100 );
1648 rSet.Put( aZoomSliderItem );
1650 else
1651 rSet.DisableItem(nWhich);
1653 break;
1654 case FN_PREVIEW_ZOOM:
1656 if(bZoomEnabled)
1658 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1659 rSet.Put(SfxUInt16Item(nWhich, pVOpt->GetZoom()));
1661 else
1662 rSet.DisableItem(nWhich);
1664 break;
1665 case SID_ZOOM_IN:
1666 case SID_ZOOM_OUT:
1668 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1669 if(!bZoomEnabled || (SID_ZOOM_OUT == nWhich && pVOpt->GetZoom() >= MAX_PREVIEW_ZOOM)||
1670 (SID_ZOOM_IN == nWhich && pVOpt->GetZoom() <= MIN_PREVIEW_ZOOM))
1672 rSet.DisableItem(nWhich);
1675 break;
1676 case FN_SHOW_MULTIPLE_PAGES:
1677 //should never be disabled
1678 break;
1679 case FN_SHOW_BOOKVIEW:
1681 BOOL b = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
1682 rSet.Put(SfxBoolItem(nWhich, b));
1684 break;
1686 case FN_SHOW_TWO_PAGES:
1687 if( 2 == aViewWin.GetCol() && nRow == aViewWin.GetRow() )
1688 rSet.DisableItem( nWhich );
1689 break;
1691 case FN_PRINT_PAGEPREVIEW:
1692 // hat den gleichen Status wie das normale Drucken
1694 const SfxPoolItem* pItem;
1695 SfxItemSet aSet( *rSet.GetPool(), SID_PRINTDOC, SID_PRINTDOC );
1696 GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet );
1697 if( SFX_ITEM_DISABLED == aSet.GetItemState( SID_PRINTDOC,
1698 FALSE, &pItem ))
1699 rSet.DisableItem( nWhich );
1700 else if( SFX_ITEM_SET == aSet.GetItemState( SID_PRINTDOC,
1701 FALSE, &pItem ))
1703 ((SfxPoolItem*)pItem)->SetWhich( FN_PRINT_PAGEPREVIEW );
1704 rSet.Put( *pItem );
1707 break;
1709 case SID_PRINTPREVIEW:
1710 rSet.Put( SfxBoolItem( nWhich, TRUE ) );
1711 break;
1713 case SID_PRINTDOC:
1714 case SID_PRINTDOCDIRECT:
1715 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet );
1716 break;
1718 nWhich = aIter.NextWhich();
1722 /*--------------------------------------------------------------------
1723 Beschreibung:
1724 --------------------------------------------------------------------*/
1727 void SwPagePreView::StateUndo(SfxItemSet& rSet)
1729 SfxWhichIter aIter(rSet);
1730 USHORT nWhich = aIter.FirstWhich();
1732 while (nWhich)
1734 rSet.DisableItem(nWhich);
1735 nWhich = aIter.NextWhich();
1739 /*--------------------------------------------------------------------
1740 Beschreibung:
1741 --------------------------------------------------------------------*/
1744 void SwPagePreView::Init(const SwViewOption * pPrefs)
1746 if ( GetViewShell()->HasDrawView() )
1747 GetViewShell()->GetDrawView()->SetAnimationEnabled( FALSE );
1749 bNormalPrint = TRUE;
1751 // Die DocSize erfragen und verarbeiten. Ueber die Handler konnte
1752 // die Shell nicht gefunden werden, weil die Shell innerhalb CTOR-Phase
1753 // nicht in der SFX-Verwaltung bekannt ist.
1755 if( !pPrefs )
1756 pPrefs = SW_MOD()->GetUsrPref(FALSE);
1758 // die Felder aktualisieren
1759 // ACHTUNG: hochcasten auf die EditShell, um die SS zu nutzen.
1760 // In den Methoden wird auf die akt. Shell abgefragt!
1761 SwEditShell* pESh = (SwEditShell*)GetViewShell();
1762 BOOL bIsModified = pESh->IsModified();
1765 SwViewOption aOpt( *pPrefs );
1766 aOpt.SetPagePreview(TRUE);
1767 aOpt.SetTab( FALSE );
1768 aOpt.SetBlank( FALSE );
1769 aOpt.SetHardBlank( FALSE );
1770 aOpt.SetParagraph( FALSE );
1771 aOpt.SetLineBreak( FALSE );
1772 aOpt.SetPageBreak( FALSE );
1773 aOpt.SetColumnBreak( FALSE );
1774 aOpt.SetSoftHyph( FALSE );
1775 aOpt.SetFldName( FALSE );
1776 aOpt.SetPostIts( FALSE );
1777 aOpt.SetShowHiddenChar( FALSE );
1778 aOpt.SetShowHiddenField( FALSE );
1779 aOpt.SetShowHiddenPara( FALSE );
1780 aOpt.SetViewHRuler( FALSE );
1781 aOpt.SetViewVRuler( FALSE );
1782 aOpt.SetGraphic( TRUE );
1783 aOpt.SetTable( TRUE );
1784 aOpt.SetSnap( FALSE );
1785 aOpt.SetGridVisible( FALSE );
1786 GetViewShell()->ApplyViewOptions( aOpt );
1787 GetViewShell()->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions());
1789 // OD 09.01.2003 #i6467# - adjust view shell option to the same as for print
1790 SwPrtOptions aPrintOptions( GetViewFrame()->GetObjectShell()->GetTitle(0) );
1791 SwView::MakeOptions( 0, aPrintOptions, 0, 0, false, 0, 0 );
1792 GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions );
1794 IDocumentSettingAccess* pIDSA = pESh->getIDocumentSettingAccess();
1795 if( pIDSA->get(IDocumentSettingAccess::BROWSE_MODE))
1797 pIDSA->set(IDocumentSettingAccess::BROWSE_MODE, false);
1798 pESh->CheckBrowseView( TRUE );
1801 GetViewShell()->CalcLayout();
1802 DocSzChgd( GetViewShell()->GetDocSize() );
1804 if( !bIsModified )
1805 pESh->ResetModified();
1807 pVScrollbar->ExtendedShow(pPrefs->IsViewVScrollBar());
1808 pHScrollbar->ExtendedShow(pPrefs->IsViewHScrollBar());
1809 pScrollFill->Show(pPrefs->IsViewVScrollBar() && pPrefs->IsViewHScrollBar());
1813 /*--------------------------------------------------------------------
1814 Beschreibung:
1815 --------------------------------------------------------------------*/
1818 SwPagePreView::SwPagePreView(SfxViewFrame *pViewFrame, SfxViewShell* pOldSh):
1819 SfxViewShell( pViewFrame, SWVIEWFLAGS ),
1820 aViewWin( &pViewFrame->GetWindow(), *this ),
1821 nNewPage(USHRT_MAX),
1822 pHScrollbar(0),
1823 pVScrollbar(0),
1824 pPageUpBtn(0),
1825 pPageDownBtn(0),
1826 pScrollFill(new ScrollBarBox( &pViewFrame->GetWindow(),
1827 pViewFrame->GetFrame()->GetParentFrame() ? 0 : WB_SIZEABLE )),
1828 mnPageCount( 0 ),
1829 // OD 09.01.2003 #106334#
1830 mbResetFormDesignMode( false ),
1831 mbFormDesignModeToReset( false )
1833 SetName(String::CreateFromAscii("PageView" ));
1834 SetWindow( &aViewWin );
1835 SetHelpId(SW_PAGEPREVIEW);
1836 _CreateScrollbar( TRUE );
1837 _CreateScrollbar( FALSE );
1839 SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
1840 if ( !pOldSh )
1842 //Gibt es schon eine Sicht auf das Dokument?
1843 SfxViewFrame *pF = SfxViewFrame::GetFirst( pObjShell );
1844 if ( pF == pViewFrame )
1845 pF = SfxViewFrame::GetNext( *pF, pObjShell );
1846 if ( pF )
1847 pOldSh = pF->GetViewShell();
1850 ViewShell *pVS, *pNew;
1852 if( pOldSh && pOldSh->IsA( TYPE( SwPagePreView ) ) )
1853 pVS = ((SwPagePreView*)pOldSh)->GetViewShell();
1854 else
1856 if( pOldSh && pOldSh->IsA( TYPE( SwView ) ) )
1858 pVS = ((SwView*)pOldSh)->GetWrtShellPtr();
1859 // save the current ViewData of the previous SwView
1860 pOldSh->WriteUserData( sSwViewData, FALSE );
1862 else
1863 pVS = GetDocShell()->GetWrtShell();
1864 if( pVS )
1866 // setze die akt. Seite als die erste
1867 USHORT nPhysPg, nVirtPg;
1868 ((SwCrsrShell*)pVS)->GetPageNum( nPhysPg, nVirtPg, /*FALSE*/TRUE, FALSE );
1869 if( 1 != aViewWin.GetCol() && 1 == nPhysPg )
1870 --nPhysPg;
1871 aViewWin.SetSttPage( nPhysPg );
1875 // OD 09.01.2003 #106334# - for form shell remember design mode of draw view
1876 // of previous view shell
1877 if ( pVS && pVS->HasDrawView() )
1879 mbResetFormDesignMode = true;
1880 mbFormDesignModeToReset = pVS->GetDrawView()->IsDesignMode();
1883 if( pVS )
1884 pNew = new ViewShell( *pVS, &aViewWin, 0, VSHELLFLAG_ISPREVIEW );
1885 else
1886 pNew = new ViewShell(
1887 *((SwDocShell*)pViewFrame->GetObjectShell())->GetDoc(),
1888 &aViewWin, 0, 0, VSHELLFLAG_ISPREVIEW );
1890 aViewWin.SetViewShell( pNew );
1891 pNew->SetSfxViewShell( this );
1892 Init();
1896 /*--------------------------------------------------------------------
1897 Beschreibung:
1898 --------------------------------------------------------------------*/
1901 SwPagePreView::~SwPagePreView()
1903 SetWindow( 0 );
1905 delete pScrollFill;
1906 delete pHScrollbar;
1907 delete pVScrollbar;
1908 delete pPageUpBtn;
1909 delete pPageDownBtn;
1911 /* SfxObjectShell* pDocSh = GetDocShell();
1912 TypeId aType = TYPE( SfxTopViewFrame );
1914 for( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocSh, aType );
1915 pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh, aType ) )
1916 if( pFrame != GetViewFrame() )
1918 // es gibt noch eine weitere Sicht auf unser Dokument, also
1919 // aktiviere dieses
1920 pFrame->GetFrame()->Appear();
1921 break;
1925 /*--------------------------------------------------------------------
1926 Beschreibung:
1927 --------------------------------------------------------------------*/
1930 SwDocShell* SwPagePreView::GetDocShell()
1932 return PTR_CAST(SwDocShell, GetViewFrame()->GetObjectShell());
1935 /*--------------------------------------------------------------------
1936 Beschreibung:
1937 --------------------------------------------------------------------*/
1940 int SwPagePreView::_CreateScrollbar( BOOL bHori )
1942 Window *pMDI = &GetViewFrame()->GetWindow();
1943 SwScrollbar** ppScrollbar = bHori ? &pHScrollbar : &pVScrollbar;
1945 ASSERT( !*ppScrollbar, "vorher abpruefen!" )
1947 if( !bHori )
1950 pPageUpBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEUP ) );
1951 pPageUpBtn->SetHelpId(FN_PAGEUP);
1952 pPageDownBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEDOWN ) );
1953 pPageDownBtn->SetHelpId(FN_PAGEDOWN);
1954 Link aLk( LINK( this, SwPagePreView, BtnPage ) );
1955 pPageUpBtn->SetClickHdl( aLk );
1956 pPageDownBtn->SetClickHdl( aLk );
1957 pPageUpBtn->Show();
1958 pPageDownBtn->Show();
1961 *ppScrollbar = new SwScrollbar( pMDI, bHori );
1963 ScrollDocSzChg();
1964 (*ppScrollbar)->EnableDrag( TRUE );
1965 (*ppScrollbar)->SetEndScrollHdl( LINK( this, SwPagePreView, EndScrollHdl ));
1968 (*ppScrollbar)->SetScrollHdl( LINK( this, SwPagePreView, ScrollHdl ));
1970 InvalidateBorder();
1971 (*ppScrollbar)->ExtendedShow();
1972 return 1;
1975 /*--------------------------------------------------------------------
1976 Beschreibung:
1977 --------------------------------------------------------------------*/
1981 /*--------------------------------------------------------------------
1982 Beschreibung:
1983 --------------------------------------------------------------------*/
1986 * Button-Handler
1988 IMPL_LINK_INLINE_START( SwPagePreView, BtnPage, Button *, pButton )
1990 // OD 04.03.2003 #107369# - use new helper method to perform page up
1991 // respectively page down.
1992 _ExecPgUpAndPgDown( pButton == pPageUpBtn );
1993 return 0;
1995 IMPL_LINK_INLINE_END( SwPagePreView, BtnPage, Button *, pButton )
1997 /*--------------------------------------------------------------------
1998 Beschreibung:
1999 --------------------------------------------------------------------*/
2002 int SwPagePreView::ChgPage( int eMvMode, int bUpdateScrollbar )
2004 Rectangle aPixVisArea( aViewWin.LogicToPixel( aVisArea ) );
2005 int bChg = aViewWin.MovePage( eMvMode ) ||
2006 eMvMode == SwPagePreViewWin::MV_CALC ||
2007 eMvMode == SwPagePreViewWin::MV_NEWWINSIZE;
2008 aVisArea = aViewWin.PixelToLogic( aPixVisArea );
2010 if( bChg )
2012 // Statusleiste updaten
2013 String aStr( sPageStr );
2014 aViewWin.GetStatusStr( aStr, mnPageCount );
2015 SfxBindings& rBindings = GetViewFrame()->GetBindings();
2017 if( bUpdateScrollbar )
2019 ScrollViewSzChg();
2021 static USHORT __READONLY_DATA aInval[] =
2023 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT,
2024 FN_PAGEUP, FN_PAGEDOWN, 0
2026 rBindings.Invalidate( aInval );
2028 rBindings.SetState( SfxStringItem( FN_STAT_PAGE, aStr ) );
2030 return bChg;
2034 /* \f */
2035 /*--------------------------------------------------------------------
2036 Beschreibung:
2037 --------------------------------------------------------------------*/
2040 // ab hier alles aus der SwView uebernommen
2043 void SwPagePreView::CalcAndSetBorderPixel( SvBorder &rToFill, BOOL /*bInner*/ )
2045 // const long nAdd = bInner ? 0 : ScrollBar::GetWindowOverlapPixel();
2046 const StyleSettings &rSet = aViewWin.GetSettings().GetStyleSettings();
2047 const long nTmp = rSet.GetScrollBarSize();// - nAdd;
2048 if ( pVScrollbar->IsVisible( FALSE ))
2049 rToFill.Right() = nTmp;
2050 if ( pHScrollbar->IsVisible( FALSE ) )
2051 rToFill.Bottom() = nTmp;
2052 SetBorderPixel( rToFill );
2055 /*--------------------------------------------------------------------
2056 Beschreibung:
2057 --------------------------------------------------------------------*/
2060 void SwPagePreView::InnerResizePixel( const Point &rOfst, const Size &rSize )
2062 SvBorder aBorder;
2063 CalcAndSetBorderPixel( aBorder, TRUE );
2064 Rectangle aRect( rOfst, rSize );
2065 aRect += aBorder;
2066 ViewResizePixel( aViewWin, aRect.TopLeft(), aRect.GetSize(),
2067 aViewWin.GetOutputSizePixel(),
2068 TRUE,
2069 *pVScrollbar, *pHScrollbar, pPageUpBtn, pPageDownBtn, 0,
2070 *pScrollFill );
2072 //EditWin niemals einstellen!
2073 //VisArea niemals einstellen!
2076 /*--------------------------------------------------------------------
2077 Beschreibung:
2078 --------------------------------------------------------------------*/
2081 void SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize )
2083 SvBorder aBorder;
2084 CalcAndSetBorderPixel( aBorder, FALSE );
2085 ViewResizePixel( aViewWin, rOfst, rSize, aViewWin.GetOutputSizePixel(),
2086 FALSE, *pVScrollbar,
2087 *pHScrollbar, pPageUpBtn, pPageDownBtn, 0, *pScrollFill );
2089 //EditWin niemals einstellen!
2091 Size aTmpSize( aViewWin.GetOutputSizePixel() );
2092 Point aBottomRight( aViewWin.PixelToLogic( Point( aTmpSize.Width(), aTmpSize.Height() ) ) );
2093 SetVisArea( Rectangle( Point(), aBottomRight ) );
2095 //Aufruf der DocSzChgd-Methode der Scrollbars ist noetig, da vom maximalen
2096 //Scrollrange immer die halbe Hoehe der VisArea abgezogen wird.
2097 if ( pVScrollbar )
2098 ScrollDocSzChg();
2101 /*--------------------------------------------------------------------
2102 Beschreibung:
2103 --------------------------------------------------------------------*/
2106 void SwPagePreView::SetVisArea( const Rectangle &rRect, BOOL bUpdateScrollbar )
2108 const Point aTopLeft(AlignToPixel(rRect.TopLeft()));
2109 const Point aBottomRight(AlignToPixel(rRect.BottomRight()));
2110 Rectangle aLR(aTopLeft,aBottomRight);
2112 if(aLR == aVisArea)
2113 return;
2114 // keine negative Position, keine neg. Groesse
2116 if(aLR.Top() < 0)
2118 aLR.Bottom() += Abs(aLR.Top());
2119 aLR.Top() = 0;
2122 if(aLR.Left() < 0)
2124 aLR.Right() += Abs(aLR.Left());
2125 aLR.Left() = 0;
2127 if(aLR.Right() < 0) aLR.Right() = 0;
2128 if(aLR.Bottom() < 0) aLR.Bottom() = 0;
2129 if(aLR == aVisArea ||
2130 // JP 29.10.97: Bug 45173 - Leeres Rechteck nicht beachten
2131 ( 0 == aLR.Bottom() - aLR.Top() && 0 == aLR.Right() - aLR.Left() ) )
2132 return;
2134 if( aLR.Left() > aLR.Right() || aLR.Top() > aLR.Bottom() )
2135 return;
2137 //Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird
2138 //sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten
2139 //umgerechnet werden.
2140 //Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft,
2141 //denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden
2142 //lediglich (in Dokumentkoordinaten) vorgemerkt.
2143 if( GetViewShell()->ActionPend() )
2144 aViewWin.Update();
2146 // setze am View-Win die aktuelle Size
2147 aVisArea = aLR;
2148 aViewWin.SetWinSize( aLR.GetSize() );
2149 // OD 18.12.2002 #103492# - use new mode
2150 ChgPage( SwPagePreViewWin::MV_NEWWINSIZE, bUpdateScrollbar );
2152 aViewWin.Invalidate();
2155 /*--------------------------------------------------------------------
2156 Beschreibung:
2157 --------------------------------------------------------------------*/
2160 IMPL_LINK( SwPagePreView, ScrollHdl, SwScrollbar *, pScrollbar )
2162 if(!GetViewShell())
2163 return 0;
2164 if( !pScrollbar->IsHoriScroll() &&
2165 pScrollbar->GetType() == SCROLL_DRAG &&
2166 Help::IsQuickHelpEnabled() &&
2167 GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
2169 // wieviele Seiten scrollen ??
2170 String sStateStr(sPageStr);
2171 USHORT nThmbPos = (USHORT)pScrollbar->GetThumbPos();
2172 if( 1 == aViewWin.GetCol() || !nThmbPos )
2173 ++nThmbPos;
2174 sStateStr += String::CreateFromInt32( nThmbPos );
2175 Point aPos = pScrollbar->GetParent()->OutputToScreenPixel(
2176 pScrollbar->GetPosPixel());
2177 aPos.Y() = pScrollbar->OutputToScreenPixel(pScrollbar->GetPointerPosPixel()).Y();
2178 Size aSize = pScrollbar->GetSizePixel();
2179 Rectangle aRect;
2180 aRect.Left() = aPos.X() -8;
2181 aRect.Right() = aRect.Left();
2182 aRect.Top() = aPos.Y();
2183 aRect.Bottom() = aRect.Top();
2185 Help::ShowQuickHelp(pScrollbar, aRect, sStateStr,
2186 QUICKHELP_RIGHT|QUICKHELP_VCENTER);
2189 else
2190 EndScrollHdl( pScrollbar );
2191 return 0;
2194 /*--------------------------------------------------------------------
2195 Beschreibung:
2196 --------------------------------------------------------------------*/
2199 IMPL_LINK( SwPagePreView, EndScrollHdl, SwScrollbar *, pScrollbar )
2201 if(!GetViewShell())
2202 return 0;
2204 // OD 04.03.2003 #107369# - boolean to avoid unnecessary invalidation of the window.
2205 bool bInvalidateWin = true;
2207 if( !pScrollbar->IsHoriScroll() ) // scroll vertically
2209 if ( Help::IsQuickHelpEnabled() )
2210 Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0);
2211 if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() )
2213 // wieviele Seiten scrollen ??
2214 USHORT nThmbPos = (USHORT)pScrollbar->GetThumbPos();
2215 // OD 05.12.2002 #103492# - adjust to new preview functionality
2216 if( nThmbPos != aViewWin.SelectedPage() )
2218 // OD 17.01.2003 #103492# - consider case that page <nThmbPos>
2219 // is already visible
2220 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
2221 if ( pPagePrevwLay->IsPageVisible( nThmbPos ) )
2223 pPagePrevwLay->MarkNewSelectedPage( nThmbPos );
2224 // OD 04.03.2003 #107369# - invalidation of window is unnecessary
2225 bInvalidateWin = false;
2227 else
2229 // OD 17.01.2003 #103492# - consider whether layout columns
2230 // fit or not.
2231 if ( !pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() )
2233 aViewWin.SetSttPage( nThmbPos );
2234 aViewWin.SetSelectedPage( nThmbPos );
2235 ChgPage( SwPagePreViewWin::MV_SCROLL, FALSE );
2236 // OD 20.01.2003 #103492# - update scrollbars
2237 ScrollViewSzChg();
2239 else
2241 // OD 04.03.2003 #107369# - correct scroll amount
2242 const sal_Int16 nPageDiff = nThmbPos - aViewWin.SelectedPage();
2243 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
2244 sal_Int16 nWinPagesToScroll = nPageDiff / nVisPages;
2245 if ( nPageDiff % nVisPages )
2247 // decrease/increase number of preview pages to scroll
2248 nPageDiff < 0 ? --nWinPagesToScroll : ++nWinPagesToScroll;
2250 aViewWin.SetSelectedPage( nThmbPos );
2251 aViewWin.Scroll( 0, pPagePrevwLay->GetWinPagesScrollAmount( nWinPagesToScroll ) );
2254 // OD 17.01.2003 #103492# - update accessibility
2255 GetViewShell()->ShowPreViewSelection( nThmbPos );
2257 else
2259 // OD 04.03.2003 #107369# - invalidation of window is unnecessary
2260 bInvalidateWin = false;
2263 else
2265 long nThmbPos = pScrollbar->GetThumbPos();
2266 aViewWin.Scroll(0, nThmbPos - aViewWin.GetPaintedPreviewDocRect().Top());
2269 else
2271 long nThmbPos = pScrollbar->GetThumbPos();
2272 aViewWin.Scroll(nThmbPos - aViewWin.GetPaintedPreviewDocRect().Left(), 0);
2274 // OD 24.03.2003 #108282# - additional invalidate page status.
2275 static USHORT __READONLY_DATA aInval[] =
2277 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
2278 FN_STAT_PAGE, 0
2280 SfxBindings& rBindings = GetViewFrame()->GetBindings();
2281 rBindings.Invalidate( aInval );
2282 // OD 04.03.2003 #107369# - control invalidation of window
2283 if ( bInvalidateWin )
2285 aViewWin.Invalidate();
2287 return 0;
2289 /*--------------------------------------------------------------------
2290 Beschreibung:
2291 --------------------------------------------------------------------*/
2294 Point SwPagePreView::AlignToPixel(const Point &rPt) const
2296 return aViewWin.PixelToLogic( aViewWin.LogicToPixel( rPt ) );
2299 /*--------------------------------------------------------------------
2300 Beschreibung:
2301 --------------------------------------------------------------------*/
2304 void SwPagePreView::DocSzChgd( const Size &rSz )
2306 if( aDocSz == rSz )
2307 return;
2309 aDocSz = rSz;
2311 // --> OD 2009-08-20 #i96726#
2312 // Due to the multiple page layout it is needed to trigger recalculation
2313 // of the page preview layout, even if the count of pages is not changing.
2314 mnPageCount = GetViewShell()->GetNumPages();
2316 if( aVisArea.GetWidth() )
2318 ChgPage( SwPagePreViewWin::MV_CALC, TRUE );
2319 ScrollDocSzChg();
2321 aViewWin.Invalidate();
2323 // <--
2326 /*--------------------------------------------------------------------
2327 Beschreibung:
2328 --------------------------------------------------------------------*/
2331 void SwPagePreView::ScrollViewSzChg()
2333 if(!GetViewShell())
2334 return ;
2335 if(pVScrollbar)
2337 if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
2339 //vertical scrolling by row
2340 // OD 04.12.2002 #103492# - adjust to new preview functionality
2341 USHORT nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
2342 pVScrollbar->SetVisibleSize( nVisPages );
2343 // OD 19.02.2003 #107369# - set selected page as scroll bar position,
2344 // if it is visible.
2345 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
2346 if ( pPagePrevwLay->IsPageVisible( aViewWin.SelectedPage() ) )
2348 pVScrollbar->SetThumbPos( aViewWin.SelectedPage() );
2350 else
2352 pVScrollbar->SetThumbPos( aViewWin.GetSttPage() );
2354 pVScrollbar->SetLineSize( aViewWin.GetCol() );
2355 pVScrollbar->SetPageSize( nVisPages );
2356 // calculate and set scrollbar range
2357 Range aScrollbarRange( 1, mnPageCount );
2358 // increase range by one, because left-top-corner is left blank.
2359 ++aScrollbarRange.Max();
2360 // OD 17.01.2003 #103492# - increase range in order to access all pages
2361 aScrollbarRange.Max() += ( nVisPages - 1 );
2362 pVScrollbar->SetRange( aScrollbarRange );
2364 else //vertical scrolling by pixel
2366 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect();
2367 const Size& rPreviewSize =
2368 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize();
2369 pVScrollbar->SetRangeMax(rPreviewSize.Height()) ;
2370 long nVisHeight = rDocRect.GetHeight();
2371 pVScrollbar->SetVisibleSize( nVisHeight );
2372 pVScrollbar->SetThumbPos( rDocRect.Top() );
2373 pVScrollbar->SetLineSize( nVisHeight / 10 );
2374 pVScrollbar->SetPageSize( nVisHeight / 2 );
2377 if(pHScrollbar)
2379 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect();
2380 const Size& rPreviewSize =
2381 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize();
2382 long nVisWidth = 0;
2383 long nThumb = 0;
2384 Range aRange(0,0);
2386 if(rDocRect.GetWidth() < rPreviewSize.Width())
2388 nVisWidth = rDocRect.GetWidth();
2389 nThumb = rDocRect.Left();
2390 aRange = Range(0, rPreviewSize.Width());
2392 pHScrollbar->SetRange( aRange );
2393 pHScrollbar->SetVisibleSize( nVisWidth );
2394 pHScrollbar->SetThumbPos( nThumb );
2395 pHScrollbar->SetLineSize( nVisWidth / 10 );
2396 pHScrollbar->SetPageSize( nVisWidth / 2 );
2400 /*--------------------------------------------------------------------
2401 Beschreibung:
2402 --------------------------------------------------------------------*/
2405 void SwPagePreView::ScrollDocSzChg()
2407 ScrollViewSzChg();
2411 /* \f */
2412 /*--------------------------------------------------------------------
2413 Beschreibung:
2414 --------------------------------------------------------------------*/
2417 // alles zum Thema Drucken
2419 USHORT SwPagePreView::Print( SfxProgress &rProgress, BOOL bIsAPI, PrintDialog *pDlg )
2421 ViewShell* pSh = aViewWin.GetViewShell();
2422 SfxPrinter* pPrinter = GetPrinter();
2423 if( !pPrinter || !pPrinter->InitJob( &aViewWin,
2424 pSh->HasDrawView() && !bIsAPI && pSh->GetDrawView()->GetModel()->HasTransparentObjects() ))
2425 return ERRCODE_IO_ABORT;
2427 SwWait aWait( *GetDocShell(), TRUE );
2429 USHORT nRowCol = ( aViewWin.GetRow() << 8 ) +
2430 aViewWin.GetCol(); // Zeilen / DoppelSeiten
2433 // die Felder aktualisieren
2434 // ACHTUNG: hochcasten auf die EditShell, um die SS zu nutzen.
2435 // In den Methoden wird auf die akt. Shell abgefragt!
2436 SwEditShell* pESh = (SwEditShell*)pSh;
2437 SwDocStat aDocStat;
2438 BOOL bIsModified = pESh->IsModified();
2440 pESh->StartAllAction();
2441 pESh->UpdateDocStat( aDocStat );
2442 pSh->UpdateFlds();
2443 pESh->EndAllAction();
2445 if( !bIsModified )
2446 pESh->ResetModified();
2449 // Druckauftrag starten
2450 SfxObjectShell *pObjShell = GetViewFrame()->GetObjectShell();
2451 SwPrtOptions aOpts( pObjShell->GetTitle(0) );
2453 BOOL bPrtPros;
2454 BOOL bPrtPros_RTL;
2455 SwView::MakeOptions( pDlg, aOpts, &bPrtPros, &bPrtPros_RTL, FALSE, GetPrinter(), GetDocShell()->GetDoc()->getPrintData() );
2457 if( bNormalPrint )
2459 if( bPrtPros )
2460 pSh->PrintProspect( aOpts, rProgress, bPrtPros_RTL );
2461 else
2462 pSh->Prt( aOpts, &rProgress );
2464 else
2466 const SwPagePreViewPrtData* pPPVPD = pSh->GetDoc()->GetPreViewPrtData();
2467 if( pPPVPD && pPPVPD->GetCol() && pPPVPD->GetRow() )
2469 // Zeilen / Seiten
2470 nRowCol = ( pPPVPD->GetRow() << 8 ) + pPPVPD->GetCol();
2472 else
2473 pPPVPD = 0;
2474 pSh->PrintPreViewPage( aOpts, nRowCol, rProgress, pPPVPD );
2477 return 0; // OK
2480 /*--------------------------------------------------------------------
2481 Beschreibung:
2482 --------------------------------------------------------------------*/
2485 SfxPrinter* SwPagePreView::GetPrinter( BOOL bCreate )
2487 return aViewWin.GetViewShell()->getIDocumentDeviceAccess()->getPrinter( bCreate );
2490 /*--------------------------------------------------------------------
2491 Beschreibung:
2492 --------------------------------------------------------------------*/
2495 USHORT SwPagePreView::SetPrinter( SfxPrinter *pNew, USHORT nDiffFlags, bool )
2497 ViewShell &rSh = *GetViewShell();
2498 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
2499 if ( pOld && pOld->IsPrinting() )
2500 return SFX_PRINTERROR_BUSY;
2502 SwEditShell &rESh = (SwEditShell&)rSh; //Buh...
2503 if( ( SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ) & nDiffFlags )
2505 rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
2506 if( nDiffFlags & SFX_PRINTER_PRINTER )
2507 rESh.SetModified();
2509 if ( ( nDiffFlags & SFX_PRINTER_OPTIONS ) == SFX_PRINTER_OPTIONS )
2510 ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, FALSE );
2512 const BOOL bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? TRUE : FALSE;
2513 const BOOL bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? TRUE : FALSE;
2514 if ( bChgOri || bChgSize )
2516 rESh.StartAllAction();
2517 if ( bChgOri )
2518 rSh.ChgAllPageOrientation( USHORT(pNew->GetOrientation()) );
2519 if ( bChgSize )
2521 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
2522 rSh.ChgAllPageSize( aSz );
2524 if( !bNormalPrint )
2525 aViewWin.CalcWish( aViewWin.GetRow(), aViewWin.GetCol() );
2526 rESh.SetModified();
2527 rESh.EndAllAction();
2529 static USHORT __READONLY_DATA aInval[] =
2531 SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
2532 SID_RULER_BORDERS, SID_RULER_PAGE_POS, 0
2534 #ifndef PRODUCT
2536 const USHORT* pPtr = aInval + 1;
2537 do {
2538 ASSERT( *(pPtr - 1) < *pPtr, "falsche Sortierung!" );
2539 } while( *++pPtr );
2541 #endif
2543 GetViewFrame()->GetBindings().Invalidate(aInval);
2546 return 0;
2549 /*--------------------------------------------------------------------
2550 Beschreibung:
2551 --------------------------------------------------------------------*/
2554 SfxTabPage* SwPagePreView::CreatePrintOptionsPage( Window *pParent,
2555 const SfxItemSet &rOptions )
2557 return ::CreatePrintOptionsPage( pParent, rOptions, !bNormalPrint );
2560 /*--------------------------------------------------------------------
2561 Beschreibung:
2562 --------------------------------------------------------------------*/
2565 PrintDialog* SwPagePreView::CreatePrintDialog( Window *pParent )
2567 PrintDialog *pDlg = ::CreatePrintDialog( pParent, 1, 0 );
2568 pDlg->DisableRange( PRINTDIALOG_SELECTION );
2569 return pDlg;
2572 /*--------------------------------------------------------------------
2573 Beschreibung:
2574 --------------------------------------------------------------------*/
2577 // OD 18.12.2002 #103492# - no longer needed ??
2578 Size SwPagePreView::GetOptimalSizePixel() const
2580 ASSERT( false, "overloaded virtual method <SwPagePreView::GetOptimalSizePixel()> needed ??" )
2581 return Size( -1, -1 );
2583 //JP 09.06.99: was wird hier errechnet ?????
2584 // ALT:
2585 // SfxApplicationWindow* pWin = SFX_APPWINDOW ;
2586 // Rectangle aRect = pWin->GetClientAreaPixel();
2588 Window& rWin = GetViewFrame()->GetWindow();
2589 Rectangle aRect( Point(0, 0), rWin.GetOutputSizePixel() );
2590 Size aMaxSize( aRect.GetWidth(), aRect.GetHeight() );
2591 Size aInSize = rWin.GetOutputSizePixel();
2592 Size aOutSize = rWin.GetSizePixel();
2593 USHORT nXBorder = USHORT(aOutSize.Width() - aInSize.Width());
2594 USHORT nYBorder = USHORT(aOutSize.Height() - aInSize.Height());
2595 aMaxSize.Width() -= nXBorder;
2596 //'auf Verdacht' etwas vom Border abziehen (Menue)
2597 nYBorder -= (nYBorder - nXBorder) / 2;
2598 aMaxSize.Height() -= nYBorder;
2599 //mit der max. moeglichen Outputsize guenstigstes Verhaeltnis ausrechnen
2600 aViewWin.GetOptimalSize(aMaxSize);
2601 // Border wieder dazuzaehlen
2602 aMaxSize.Height() += nYBorder;
2603 aMaxSize.Width() += nXBorder;
2604 return aMaxSize;
2608 /*--------------------------------------------------------------------
2609 Beschreibung:
2610 --------------------------------------------------------------------*/
2612 // OD 12.12.2002 #103492#
2613 void SwPagePreViewWin::SetViewShell( ViewShell* pShell )
2615 mpViewShell = pShell;
2616 if ( mpViewShell && mpViewShell->IsPreView() )
2618 mpPgPrevwLayout = mpViewShell->PagePreviewLayout();
2622 void SwPagePreViewWin::RepaintCoreRect( const SwRect& rRect )
2624 // OD 2004-03-04 #i24183#
2625 if ( mpPgPrevwLayout->PreviewLayoutValid() )
2627 mpPgPrevwLayout->Repaint( Rectangle( rRect.Pos(), rRect.SSize() ) );
2631 /** method to adjust preview to a new zoom factor
2633 OD 02.12.2002 #103492#
2634 OD 24.09.2003 #i19975# - also consider zoom type - adding parameter <_eZoomType>
2636 void SwPagePreViewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor,
2637 const SvxZoomType _eZoomType )
2639 // OD 24.09.2003 #i19975# - consider zoom type
2640 if ( _eZoomType == SVX_ZOOM_WHOLEPAGE )
2642 mnRow = 1;
2643 mnCol = 1;
2644 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
2645 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
2646 mnSttPage, maPaintedPreviewDocRect );
2647 SetSelectedPage( mnSttPage );
2648 SetPagePreview(mnRow, mnCol);
2649 maScale = GetMapMode().GetScaleX();
2651 else if ( _nZoomFactor != 0 )
2653 // calculate new scaling and set mapping mode appropriately.
2654 Fraction aNewScale( _nZoomFactor, 100 );
2655 MapMode aNewMapMode = GetMapMode();
2656 aNewMapMode.SetScaleX( aNewScale );
2657 aNewMapMode.SetScaleY( aNewScale );
2658 SetMapMode( aNewMapMode );
2660 // calculate new start position for preview paint
2661 Size aNewWinSize = PixelToLogic( maPxWinSize );
2662 Point aNewPaintStartPos =
2663 mpPgPrevwLayout->GetPreviewStartPosForNewScale( aNewScale, maScale, aNewWinSize );
2665 // remember new scaling and prepare preview paint
2666 // Note: paint of preview will be performed by a corresponding invalidate
2667 // due to property changes.
2668 maScale = aNewScale;
2669 mpPgPrevwLayout->Prepare( 0, aNewPaintStartPos, maPxWinSize,
2670 mnSttPage, maPaintedPreviewDocRect );
2674 /* -----------------04.12.2002 10:46-----------------
2675 * pixel scrolling - horizontally always or vertically
2676 * when less than the desired number of rows fits into
2677 * the view
2678 * --------------------------------------------------*/
2679 void SwPagePreViewWin::Scroll(long nXMove, long nYMove, USHORT /*nFlags*/)
2681 maPaintedPreviewDocRect.Move(nXMove, nYMove);
2682 mpPgPrevwLayout->Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
2683 maPxWinSize, mnSttPage,
2684 maPaintedPreviewDocRect );
2688 BOOL SwPagePreView::HandleWheelCommands( const CommandEvent& rCEvt )
2690 BOOL bOk = FALSE;
2691 const CommandWheelData* pWData = rCEvt.GetWheelData();
2692 if( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
2694 if(!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
2696 USHORT nFactor = GetViewShell()->GetViewOptions()->GetZoom();
2697 const USHORT nOffset = 10;
2698 if( 0L > pWData->GetDelta() )
2700 nFactor -= nOffset;
2701 if(nFactor < MIN_PREVIEW_ZOOM)
2702 nFactor = MIN_PREVIEW_ZOOM;
2704 else
2706 nFactor += nOffset;
2707 if(nFactor > MAX_PREVIEW_ZOOM)
2708 nFactor = MAX_PREVIEW_ZOOM;
2710 SetZoom(SVX_ZOOM_PERCENT, nFactor);
2712 bOk = TRUE;
2714 else
2715 bOk = aViewWin.HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar );
2716 return bOk;
2720 uno::Reference< ::com::sun::star::accessibility::XAccessible >
2721 SwPagePreViewWin::CreateAccessible()
2723 vos::OGuard aGuard(Application::GetSolarMutex()); // this should have
2724 // happend already!!!
2726 DBG_ASSERT( GetViewShell() != NULL, "We need a view shell" );
2727 return GetViewShell()->CreateAccessiblePreview();
2730 /* -----------------------------06.05.2002 13:18------------------------------
2732 ---------------------------------------------------------------------------*/
2733 void SwPagePreView::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
2735 GetViewShell()->ApplyAccessiblityOptions(rAccessibilityOptions);
2737 /* -----------------------------2002/06/26 14:30------------------------------
2739 ---------------------------------------------------------------------------*/
2740 void SwPagePreView::ShowHScrollbar(sal_Bool bShow)
2742 pHScrollbar->Show(bShow);
2743 InvalidateBorder();
2746 /* -----------------------------2002/06/26 14:30------------------------------
2748 ---------------------------------------------------------------------------*/
2749 void SwPagePreView::ShowVScrollbar(sal_Bool bShow)
2751 pVScrollbar->Show(bShow);
2752 InvalidateBorder();
2755 /* -----------------25.11.2002 16:36-----------------
2757 * --------------------------------------------------*/
2758 void SwPagePreView::SetZoom(SvxZoomType eType, USHORT nFactor)
2760 ViewShell& rSh = *GetViewShell();
2761 SwViewOption aOpt(*rSh.GetViewOptions());
2762 // OD 16.12.2002 #103492# - perform action only on changes of zoom or zoom type.
2763 if ( aOpt.GetZoom() != nFactor ||
2764 aOpt.GetZoomType() != eType )
2766 aOpt.SetZoom(nFactor);
2767 aOpt.SetZoomType(eType);
2768 rSh.ApplyViewOptions( aOpt );
2769 lcl_InvalidateZoomSlots(GetViewFrame()->GetBindings());
2770 // OD 02.12.2002 #103492#
2771 // OD 24.09.2003 #i19975# - also consider zoom type
2772 aViewWin.AdjustPreviewToNewZoom( nFactor, eType );
2773 ScrollViewSzChg();
2777 /** adjust position of vertical scrollbar
2779 OD 19.02.2003 #107369
2781 @author OD
2783 void SwPagePreView::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos )
2785 if ( pVScrollbar )
2787 pVScrollbar->SetThumbPos( _nNewThumbPos );