xref: /aoo42x/main/sd/source/ui/view/viewshe2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/chart2/XChartDocument.hpp>
33 #include <com/sun/star/drawing/FillStyle.hpp>
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 
36 #include "ViewShell.hxx"
37 #include "ViewShellHint.hxx"
38 
39 #include "ViewShellImplementation.hxx"
40 #include "FactoryIds.hxx"
41 
42 #ifndef _SVXIDS_HRC
43 #include <svx/svxids.hrc>
44 #endif
45 #ifndef _SCRBAR_HXX //autogen
46 #include <vcl/scrbar.hxx>
47 #endif
48 #include <svx/svdpagv.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/app.hxx>
51 #include <svx/ruler.hxx>
52 #include <editeng/outliner.hxx>
53 #include <svtools/ehdl.hxx>
54 #include <svx/svdoole2.hxx>
55 #include <svtools/sfxecode.hxx>
56 #include <svx/fmshell.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <rtl/ustrbuf.hxx>
59 #include <unotools/moduleoptions.hxx>
60 #ifndef _SVX_DIALOGS_HRC
61 #include <svx/dialogs.hrc>
62 #endif
63 #include <sot/clsids.hxx>
64 
65 #include "misc.hxx"
66 #include "strings.hrc"
67 #include "app.hrc"
68 #include "unokywds.hxx"
69 
70 #include "sdundogr.hxx"
71 #include "FrameView.hxx"
72 #include "undopage.hxx"
73 #include "sdresid.hxx"
74 #include "drawdoc.hxx"
75 #include "View.hxx"
76 #include "fupoor.hxx"
77 #include "Client.hxx"
78 #include "DrawDocShell.hxx"
79 #include "fusearch.hxx"
80 #include "slideshow.hxx"
81 #include "sdpage.hxx"
82 #include "DrawViewShell.hxx"
83 #include "ViewShellBase.hxx"
84 
85 #include "Window.hxx"
86 
87 #include <sfx2/viewfrm.hxx>
88 #include <svtools/soerr.hxx>
89 #include <toolkit/helper/vclunohelper.hxx>
90 
91 #ifdef _MSC_VER
92 #pragma optimize ( "", off )
93 #endif
94 
95 using namespace com::sun::star;
96 
97 const String aEmptyStr;
98 
99 namespace sd {
100 
101 /*************************************************************************
102 |*
103 |* Scrollbar-Update: Thumbpos und VisibleSize anpassen
104 |*
105 \************************************************************************/
106 
107 void ViewShell::UpdateScrollBars()
108 {
109 	if (mpHorizontalScrollBar.get() != NULL)
110 	{
111 		long nW = (long)(mpContentWindow->GetVisibleWidth() * 32000);
112 		long nX = (long)(mpContentWindow->GetVisibleX() * 32000);
113 		mpHorizontalScrollBar->SetVisibleSize(nW);
114 		mpHorizontalScrollBar->SetThumbPos(nX);
115 		nW = 32000 - nW;
116 		long nLine = (long) (mpContentWindow->GetScrlLineWidth() * nW);
117 		long nPage = (long) (mpContentWindow->GetScrlPageWidth() * nW);
118 		mpHorizontalScrollBar->SetLineSize(nLine);
119 		mpHorizontalScrollBar->SetPageSize(nPage);
120 	}
121 
122 	if (mpVerticalScrollBar.get() != NULL)
123 	{
124 		long nH = (long)(mpContentWindow->GetVisibleHeight() * 32000);
125 		long nY = (long)(mpContentWindow->GetVisibleY() * 32000);
126 
127 		if(IsPageFlipMode()) // ie in zoom mode where no panning
128 		{
129 			SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
130 			sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) / 2;
131 			sal_uInt16 nTotalPages = GetDoc()->GetSdPageCount(pPage->GetPageKind());
132 			mpVerticalScrollBar->SetRange(Range(0,256*nTotalPages));
133 			mpVerticalScrollBar->SetVisibleSize(256);
134 			mpVerticalScrollBar->SetThumbPos(256*nCurPage);
135 			mpVerticalScrollBar->SetLineSize(256);
136 			mpVerticalScrollBar->SetPageSize(256);
137 		}
138 		else
139 		{
140 			mpVerticalScrollBar->SetRange(Range(0,32000));
141 			mpVerticalScrollBar->SetVisibleSize(nH);
142 			mpVerticalScrollBar->SetThumbPos(nY);
143 			nH = 32000 - nH;
144 			long nLine = (long) (mpContentWindow->GetScrlLineHeight() * nH);
145 			long nPage = (long) (mpContentWindow->GetScrlPageHeight() * nH);
146 			mpVerticalScrollBar->SetLineSize(nLine);
147 			mpVerticalScrollBar->SetPageSize(nPage);
148 		}
149 	}
150 
151 	if (mbHasRulers)
152 	{
153 		UpdateHRuler();
154 		UpdateVRuler();
155 	}
156 
157 }
158 /*************************************************************************
159 |*
160 |* Handling fuer horizontale Scrollbars
161 |*
162 \************************************************************************/
163 
164 IMPL_LINK_INLINE_START(ViewShell, HScrollHdl, ScrollBar *, pHScroll )
165 {
166 	return VirtHScrollHdl(pHScroll);
167 }
168 IMPL_LINK_INLINE_END(ViewShell, HScrollHdl, ScrollBar *, pHScroll )
169 
170 /*************************************************************************
171 |*
172 |* virtueller Scroll-Handler fuer horizontale Scrollbars
173 |*
174 \************************************************************************/
175 
176 long ViewShell::VirtHScrollHdl(ScrollBar* pHScroll)
177 {
178 	long nDelta = pHScroll->GetDelta();
179 
180 	if (nDelta != 0)
181 	{
182 		double fX = (double) pHScroll->GetThumbPos() / pHScroll->GetRange().Len();
183 
184 		// alle Fenster der Spalte scrollen
185         ::sd::View* pView = GetView();
186         OutlinerView* pOLV = NULL;
187 
188         if (pView)
189             pOLV = pView->GetTextEditOutlinerView();
190 
191         if (pOLV)
192             pOLV->HideCursor();
193 
194         mpContentWindow->SetVisibleXY(fX, -1);
195 
196         Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
197         Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
198         aVisArea.SetPos(aVisAreaPos);
199         GetDocSh()->SetVisArea(aVisArea);
200 
201         Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
202         Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
203         VisAreaChanged(aVisAreaWin);
204 
205         if (pView)
206         {
207             pView->VisAreaChanged(GetActiveWindow());
208         }
209 
210         if (pOLV)
211             pOLV->ShowCursor();
212 
213 		if (mbHasRulers)
214 			UpdateHRuler();
215 
216 	}
217 
218 	return 0;
219 }
220 
221 /*************************************************************************
222 |*
223 |* Handling fuer vertikale Scrollbars
224 |*
225 \************************************************************************/
226 
227 IMPL_LINK_INLINE_START(ViewShell, VScrollHdl, ScrollBar *, pVScroll )
228 {
229 	return VirtVScrollHdl(pVScroll);
230 }
231 IMPL_LINK_INLINE_END(ViewShell, VScrollHdl, ScrollBar *, pVScroll )
232 
233 /*************************************************************************
234 |*
235 |* Handling fuer vertikale Scrollbars
236 |*
237 \************************************************************************/
238 
239 long ViewShell::VirtVScrollHdl(ScrollBar* pVScroll)
240 {
241 	if(IsPageFlipMode())
242 	{
243 		SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
244 		sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) >> 1;
245 		sal_uInt16 nNewPage = (sal_uInt16)pVScroll->GetThumbPos()/256;
246 		if( nCurPage != nNewPage )
247 			static_cast<DrawViewShell*>(this)->SwitchPage(nNewPage);
248 	}
249 	else //panning mode
250 	{
251 		double fY = (double) pVScroll->GetThumbPos() / pVScroll->GetRange().Len();
252 
253         ::sd::View* pView = GetView();
254         OutlinerView* pOLV = NULL;
255 
256         if (pView)
257             pOLV = pView->GetTextEditOutlinerView();
258 
259         if (pOLV)
260             pOLV->HideCursor();
261 
262         mpContentWindow->SetVisibleXY(-1, fY);
263 
264         Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
265         Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
266         aVisArea.SetPos(aVisAreaPos);
267         GetDocSh()->SetVisArea(aVisArea);
268 
269         Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
270         Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
271         VisAreaChanged(aVisAreaWin);
272 
273         if (pView)
274         {
275             pView->VisAreaChanged(GetActiveWindow());
276         }
277 
278         if (pOLV)
279             pOLV->ShowCursor();
280 
281 		if (mbHasRulers)
282 			UpdateVRuler();
283 
284 	}
285 
286 	return 0;
287 }
288 
289 SvxRuler* ViewShell::CreateHRuler(::sd::Window* , sal_Bool )
290 {
291 	return NULL;
292 }
293 
294 SvxRuler* ViewShell::CreateVRuler(::sd::Window* )
295 {
296 	return NULL;
297 }
298 
299 void ViewShell::UpdateHRuler()
300 {
301 }
302 
303 void ViewShell::UpdateVRuler()
304 {
305 }
306 
307 long ViewShell::GetHCtrlWidth()
308 {
309 	return 0;
310 }
311 
312 /*************************************************************************
313 |*
314 |* Eine bestimmte Anzahl von Zeilen scrollen (wird beim automatischen
315 |* Scrollen (Zeichen/Draggen) verwendet)
316 |*
317 \************************************************************************/
318 
319 void ViewShell::ScrollLines(long nLinesX, long nLinesY)
320 {
321 	if ( nLinesX )
322 	{
323 		nLinesX *= mpHorizontalScrollBar->GetLineSize();
324 	}
325 	if ( nLinesY )
326 	{
327 		nLinesY *= mpVerticalScrollBar->GetLineSize();
328 	}
329 
330 	Scroll(nLinesX, nLinesY);
331 }
332 
333 /*************************************************************************
334 |*
335 |* Window um nScrollX, nScrollY scrollen
336 |*
337 \************************************************************************/
338 
339 void ViewShell::Scroll(long nScrollX, long nScrollY)
340 {
341 	if (nScrollX)
342 	{
343 		long nNewThumb = mpHorizontalScrollBar->GetThumbPos() + nScrollX;
344 		mpHorizontalScrollBar->SetThumbPos(nNewThumb);
345 	}
346 	if (nScrollY)
347 	{
348 		long nNewThumb = mpVerticalScrollBar->GetThumbPos() + nScrollY;
349 		mpVerticalScrollBar->SetThumbPos(nNewThumb);
350 	}
351 	double	fX = (double) mpHorizontalScrollBar->GetThumbPos() /
352 							mpHorizontalScrollBar->GetRange().Len();
353 	double	fY = (double) mpVerticalScrollBar->GetThumbPos() /
354 							mpVerticalScrollBar->GetRange().Len();
355 
356 	GetActiveWindow()->SetVisibleXY(fX, fY);
357 
358 	Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
359 	Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
360 	aVisArea.SetPos(aVisAreaPos);
361 	GetDocSh()->SetVisArea(aVisArea);
362 
363 	Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
364 	Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
365 	VisAreaChanged(aVisAreaWin);
366 
367 	::sd::View* pView = GetView();
368 	if (pView)
369 	{
370 		pView->VisAreaChanged(GetActiveWindow());
371 	}
372 
373 	if (mbHasRulers)
374 	{
375 		UpdateHRuler();
376 		UpdateVRuler();
377 	}
378 }
379 
380 /*************************************************************************
381 |*
382 |* Den Zoomfaktor fuer alle Split-Windows setzen
383 |*
384 \************************************************************************/
385 
386 void ViewShell::SetZoom(long nZoom)
387 {
388 	Fraction aUIScale(nZoom, 100);
389 	aUIScale *= GetDoc()->GetUIScale();
390 
391     if (mpHorizontalRuler.get() != NULL)
392         mpHorizontalRuler->SetZoom(aUIScale);
393 
394     if (mpVerticalRuler.get() != NULL)
395         mpVerticalRuler->SetZoom(aUIScale);
396 
397     if (mpContentWindow.get() != NULL)
398     {
399         mpContentWindow->SetZoomIntegral(nZoom);
400 
401 		// #i74769# Here is a 2nd way (besides Window::Scroll) to set the visible prt
402 		// of the window. It needs - like Scroll(SCROLL_CHILDREN) does - also to move
403 		// the child windows. I am trying INVALIDATE_CHILDREN here which makes things better,
404 		// but does not solve the problem completely. Neet to ask PL.
405         mpContentWindow->Invalidate(INVALIDATE_CHILDREN);
406     }
407 
408 	Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
409 	Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
410 	VisAreaChanged(aVisAreaWin);
411 
412 	::sd::View* pView = GetView();
413 	if (pView)
414 	{
415 		pView->VisAreaChanged(GetActiveWindow());
416 	}
417 
418 	UpdateScrollBars();
419 }
420 
421 /*************************************************************************
422 |*
423 |* Zoomrechteck fuer aktives Fenster einstellen und alle Split-Windows
424 |* auf den gleichen Zoomfaktor setzen
425 |*
426 \************************************************************************/
427 
428 void ViewShell::SetZoomRect(const Rectangle& rZoomRect)
429 {
430 	long nZoom = GetActiveWindow()->SetZoomRect(rZoomRect);
431 	Fraction aUIScale(nZoom, 100);
432 	aUIScale *= GetDoc()->GetUIScale();
433 
434 	Point aPos = GetActiveWindow()->GetWinViewPos();
435 
436     if (mpHorizontalRuler.get() != NULL)
437         mpHorizontalRuler->SetZoom(aUIScale);
438 
439     if (mpVerticalRuler.get() != NULL)
440         mpVerticalRuler->SetZoom(aUIScale);
441 
442     if (mpContentWindow.get() != NULL)
443     {
444         Point aNewPos = mpContentWindow->GetWinViewPos();
445         aNewPos.X() = aPos.X();
446         aNewPos.Y() = aPos.Y();
447         mpContentWindow->SetZoomIntegral(nZoom);
448         mpContentWindow->SetWinViewPos(aNewPos);
449         mpContentWindow->UpdateMapOrigin();
450 
451 		// #i74769# see above
452         mpContentWindow->Invalidate(INVALIDATE_CHILDREN);
453     }
454 
455 	Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
456 	Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
457 	VisAreaChanged(aVisAreaWin);
458 
459 	::sd::View* pView = GetView();
460 	if (pView)
461 	{
462 		pView->VisAreaChanged(GetActiveWindow());
463 	}
464 
465 	UpdateScrollBars();
466 }
467 
468 /*************************************************************************
469 |*
470 |* Abbildungsparameter fuer alle Split-Windows initialisieren
471 |*
472 \************************************************************************/
473 
474 void ViewShell::InitWindows(const Point& rViewOrigin, const Size& rViewSize,
475 							  const Point& rWinPos, sal_Bool bUpdate)
476 {
477     if (mpContentWindow.get() != NULL)
478     {
479         mpContentWindow->SetViewOrigin(rViewOrigin);
480         mpContentWindow->SetViewSize(rViewSize);
481         mpContentWindow->SetWinViewPos(rWinPos);
482 
483         if ( bUpdate )
484         {
485             mpContentWindow->UpdateMapOrigin();
486             mpContentWindow->Invalidate();
487         }
488     }
489 
490 	Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
491 	Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
492 	VisAreaChanged(aVisAreaWin);
493 
494 	::sd::View* pView = GetView();
495 	if (pView)
496 	{
497 		pView->VisAreaChanged(GetActiveWindow());
498 	}
499 }
500 
501 /*************************************************************************
502 |*
503 |* Alle Split-Windows unter dem uebergebenen Rechteck invalidieren
504 |*
505 \************************************************************************/
506 
507 void ViewShell::InvalidateWindows()
508 {
509     if (mpContentWindow.get() != NULL)
510         mpContentWindow->Invalidate();
511 }
512 
513 
514 /*************************************************************************
515 |*
516 |* Auf allen Split-Windows ein Markierungsrechteck mit dem
517 |* uebergebenen Pen zeichnen
518 |*
519 \************************************************************************/
520 
521 void ViewShell::DrawMarkRect(const Rectangle& rRect) const
522 {
523     if (mpContentWindow.get() != NULL)
524     {
525         mpContentWindow->InvertTracking(rRect, SHOWTRACK_OBJECT | SHOWTRACK_WINDOW);
526     }
527 }
528 
529 /*************************************************************************
530 |*
531 |* Groesse und Raender aller Seiten setzen
532 |*
533 \************************************************************************/
534 
535 void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize,
536 									   long nLeft, long nRight,
537 									   long nUpper, long nLower, sal_Bool bScaleAll,
538 									   Orientation eOrientation, sal_uInt16 nPaperBin,
539 							           sal_Bool bBackgroundFullSize)
540 {
541 	SdPage* pPage = 0;
542 	SdUndoGroup* pUndoGroup = NULL;
543 	pUndoGroup = new SdUndoGroup(GetDoc());
544 	String aString(SdResId(STR_UNDO_CHANGE_PAGEFORMAT));
545 	pUndoGroup->SetComment(aString);
546     SfxViewShell* pViewShell = GetViewShell();
547     OSL_ASSERT (pViewShell!=NULL);
548 
549 	sal_uInt16 i, nPageCnt = GetDoc()->GetMasterSdPageCount(ePageKind);
550 
551     Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_START));
552 
553 	for (i = 0; i < nPageCnt; i++)
554 	{
555 		/**********************************************************************
556 		* Erst alle MasterPages bearbeiten
557 		**********************************************************************/
558 		pPage = GetDoc()->GetMasterSdPage(i, ePageKind);
559 
560 		SdUndoAction* pUndo = new SdPageFormatUndoAction(GetDoc(), pPage,
561 							pPage->GetSize(),
562 							pPage->GetLftBorder(), pPage->GetRgtBorder(),
563 							pPage->GetUppBorder(), pPage->GetLwrBorder(),
564 							pPage->IsScaleObjects(),
565 							pPage->GetOrientation(),
566 							pPage->GetPaperBin(),
567 							pPage->IsBackgroundFullSize(),
568 							rNewSize,
569 							nLeft, nRight,
570 							nUpper, nLower,
571 							bScaleAll,
572 							eOrientation,
573 							nPaperBin,
574 							bBackgroundFullSize);
575 		pUndoGroup->AddAction(pUndo);
576 
577 		if (rNewSize.Width() > 0 ||
578 			nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0)
579 		{
580 			Rectangle aNewBorderRect(nLeft, nUpper, nRight, nLower);
581 			pPage->ScaleObjects(rNewSize, aNewBorderRect, bScaleAll);
582 
583 			if (rNewSize.Width() > 0)
584 				pPage->SetSize(rNewSize);
585 		}
586 
587 		if( nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0 )
588 		{
589 			pPage->SetBorder(nLeft, nUpper, nRight, nLower);
590 		}
591 
592 		pPage->SetOrientation(eOrientation);
593 		pPage->SetPaperBin( nPaperBin );
594 		pPage->SetBackgroundFullSize( bBackgroundFullSize );
595 
596 		if ( ePageKind == PK_STANDARD )
597 			GetDoc()->GetMasterSdPage(i, PK_NOTES)->CreateTitleAndLayout();
598 
599 		pPage->CreateTitleAndLayout();
600 	}
601 
602 	nPageCnt = GetDoc()->GetSdPageCount(ePageKind);
603 
604 	for (i = 0; i < nPageCnt; i++)
605 	{
606 		/**********************************************************************
607 		* Danach alle Pages bearbeiten
608 		**********************************************************************/
609 		pPage = GetDoc()->GetSdPage(i, ePageKind);
610 
611 		SdUndoAction* pUndo = new SdPageFormatUndoAction(GetDoc(), pPage,
612 								pPage->GetSize(),
613 								pPage->GetLftBorder(), pPage->GetRgtBorder(),
614 								pPage->GetUppBorder(), pPage->GetLwrBorder(),
615 								pPage->IsScaleObjects(),
616 								pPage->GetOrientation(),
617 								pPage->GetPaperBin(),
618 								pPage->IsBackgroundFullSize(),
619 								rNewSize,
620 								nLeft, nRight,
621 								nUpper, nLower,
622 								bScaleAll,
623 								eOrientation,
624 								nPaperBin,
625 								bBackgroundFullSize);
626 		pUndoGroup->AddAction(pUndo);
627 
628 		if (rNewSize.Width() > 0 ||
629 			nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0)
630 		{
631 			Rectangle aNewBorderRect(nLeft, nUpper, nRight, nLower);
632 			pPage->ScaleObjects(rNewSize, aNewBorderRect, bScaleAll);
633 
634 			if (rNewSize.Width() > 0)
635 				pPage->SetSize(rNewSize);
636 		}
637 
638 		if( nLeft  >= 0 || nRight >= 0 || nUpper >= 0 || nLower >= 0 )
639 		{
640 			pPage->SetBorder(nLeft, nUpper, nRight, nLower);
641 		}
642 
643 		pPage->SetOrientation(eOrientation);
644 		pPage->SetPaperBin( nPaperBin );
645 		pPage->SetBackgroundFullSize( bBackgroundFullSize );
646 
647 		if ( ePageKind == PK_STANDARD )
648 		{
649 			SdPage* pNotesPage = GetDoc()->GetSdPage(i, PK_NOTES);
650 			pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
651 		}
652 
653 		pPage->SetAutoLayout( pPage->GetAutoLayout() );
654 	}
655 
656 	// Handoutseite an neues Format der Standardseiten anpassen
657 	if( (ePageKind == PK_STANDARD) || (ePageKind == PK_HANDOUT) )
658 		GetDoc()->GetSdPage(0, PK_HANDOUT)->CreateTitleAndLayout(sal_True);
659 
660 	// Undo Gruppe dem Undo Manager uebergeben
661 	pViewShell->GetViewFrame()->GetObjectShell()
662         ->GetUndoManager()->AddUndoAction(pUndoGroup);
663 
664 	long nWidth = pPage->GetSize().Width();
665 	long nHeight = pPage->GetSize().Height();
666 
667 	Point aPageOrg = Point(nWidth, nHeight / 2);
668 	Size aViewSize = Size(nWidth * 3, nHeight * 2);
669 
670 	InitWindows(aPageOrg, aViewSize, Point(-1, -1), sal_True);
671 
672 	Point aVisAreaPos;
673 
674 	if ( GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
675 	{
676 		aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
677 	}
678 
679 	::sd::View* pView = GetView();
680 	if (pView)
681 	{
682 		pView->SetWorkArea(Rectangle(Point() - aVisAreaPos - aPageOrg, aViewSize));
683 	}
684 
685 	UpdateScrollBars();
686 
687 	Point aNewOrigin(pPage->GetLftBorder(), pPage->GetUppBorder());
688 
689 	if (pView)
690 	{
691 		pView->GetSdrPageView()->SetPageOrigin(aNewOrigin);
692 	}
693 
694 	pViewShell->GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
695 
696 	// auf (neue) Seitengroesse zoomen
697 	pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE,
698 			SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
699 
700     Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_END));
701 }
702 
703 /*************************************************************************
704 |*
705 |* Zoom-Faktor fuer InPlace einstellen
706 |*
707 \************************************************************************/
708 
709 void ViewShell::SetZoomFactor(const Fraction& rZoomX, const Fraction&)
710 {
711 	long nZoom = (long)((double) rZoomX * 100);
712 	SetZoom(nZoom);
713 }
714 
715 
716 /*************************************************************************
717 |*
718 |* Aktives Fenster setzen
719 |*
720 \************************************************************************/
721 
722 void ViewShell::SetActiveWindow (::sd::Window* pWin)
723 {
724     SfxViewShell* pViewShell = GetViewShell();
725     OSL_ASSERT (pViewShell!=NULL);
726 
727     if (pViewShell->GetWindow() != pWin)
728 	{
729 		// #i31551# was wrong, it may have been a problem with the repaint at that time.
730 		// For transparent form controls, it is necessary to have that flag set, all apps
731 		// do set it. Enabling again.
732 		if (pWin)
733 		{
734 			pWin->EnableChildTransparentMode();
735 		}
736 	}
737 
738     if (mpActiveWindow != pWin)
739         mpActiveWindow = pWin;
740 
741     // The rest of this function is not guarded anymore against calling this
742     // method with an already active window because the functions may still
743     // point to the old window when the new one has already been assigned to
744     // pWindow elsewhere.
745     ::sd::View* pView = GetView();
746     if (pView)
747     {
748         pView->SetActualWin(pWin);
749     }
750     if(HasCurrentFunction())
751     {
752         GetCurrentFunction()->SetWindow(pWin);
753     }
754 }
755 
756 
757 
758 /*************************************************************************
759 |*
760 |* RequestHelp event
761 |*
762 \************************************************************************/
763 
764 sal_Bool ViewShell::RequestHelp(const HelpEvent& rHEvt, ::sd::Window*)
765 {
766 	sal_Bool bReturn = sal_False;
767 
768 	if (rHEvt.GetMode())
769 	{
770 		if( GetView() )
771 			bReturn = GetView()->getSmartTags().RequestHelp(rHEvt);
772 
773 		if(!bReturn && HasCurrentFunction())
774 		{
775 			bReturn = GetCurrentFunction()->RequestHelp(rHEvt);
776 		}
777 	}
778 
779 	return(bReturn);
780 }
781 
782 
783 
784 
785 FrameView* ViewShell::GetFrameView (void)
786 {
787     return mpFrameView;
788 }
789 
790 
791 
792 
793 void ViewShell::SetFrameView (FrameView* pNewFrameView)
794 {
795     mpFrameView = pNewFrameView;
796     ReadFrameViewData (mpFrameView);
797 }
798 
799 
800 
801 
802 /*************************************************************************
803 |*
804 |* Read FrameViews data and set actual views data
805 |*
806 \************************************************************************/
807 
808 void ViewShell::ReadFrameViewData(FrameView*)
809 {
810 }
811 
812 
813 
814 /*************************************************************************
815 |*
816 |* Write actual views data to FrameView
817 |*
818 \************************************************************************/
819 
820 void ViewShell::WriteFrameViewData()
821 {
822 }
823 
824 /*************************************************************************
825 |*
826 |* OLE-Object aktivieren
827 |*
828 \************************************************************************/
829 
830 sal_Bool ViewShell::ActivateObject(SdrOle2Obj* pObj, long nVerb)
831 {
832 	ErrCode aErrCode = 0;
833 
834 	SfxErrorContext aEC(ERRCTX_SO_DOVERB, GetActiveWindow(), RID_SO_ERRCTX);
835 	sal_Bool bAbort = sal_False;
836 	GetDocSh()->SetWaitCursor( sal_True );
837     SfxViewShell* pViewShell = GetViewShell();
838     OSL_ASSERT (pViewShell!=NULL);
839     bool bChangeDefaultsForChart = false;
840 
841     uno::Reference < embed::XEmbeddedObject > xObj = pObj->GetObjRef();
842     if ( !xObj.is() )
843 	{
844 		/**********************************************************
845 		* Leeres OLE-Objekt mit OLE-Objekt versehen
846 		**********************************************************/
847 		String aName = pObj->GetProgName();
848         ::rtl::OUString aObjName;
849         SvGlobalName aClass;
850 
851         if( aName.EqualsAscii( "StarChart" ) || aName.EqualsAscii("StarOrg") )
852 		{
853 			if( SvtModuleOptions().IsChart() )
854             {
855                 aClass = SvGlobalName( SO3_SCH_CLASSID );
856                 bChangeDefaultsForChart = true;
857             }
858 		}
859 		else if( aName.EqualsAscii( "StarCalc" ))
860 		{
861 			if( SvtModuleOptions().IsCalc() )
862                 aClass = SvGlobalName( SO3_SC_CLASSID );
863 		}
864 		else if( aName.EqualsAscii( "StarMath" ))
865 		{
866 			if( SvtModuleOptions().IsMath() )
867                 aClass = SvGlobalName( SO3_SM_CLASSID );
868 		}
869 
870         if ( aClass != SvGlobalName() )
871             xObj = GetDocSh()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClass.GetByteSequence(), aObjName );
872 
873         if( !xObj.is() )
874 		{
875 			aName = String();
876 
877 			// Dialog "OLE-Objekt einfuegen" aufrufen
878 			GetDocSh()->SetWaitCursor( sal_False );
879 			pViewShell->GetViewFrame()->GetDispatcher()->Execute(
880                 SID_INSERT_OBJECT,
881                 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
882             xObj = pObj->GetObjRef();
883 			GetDocSh()->SetWaitCursor( sal_True );
884 
885             if (!xObj.is())
886 			{
887 				bAbort = sal_True;
888 			}
889 		}
890 
891         if ( xObj.is() )
892 		{
893 			/******************************************************
894 			* OLE-Objekt ist nicht mehr leer
895 			******************************************************/
896 			pObj->SetEmptyPresObj(sal_False);
897 			pObj->SetOutlinerParaObject(NULL);
898 			pObj->SetGraphic(NULL);
899 
900 			/******************************************************
901 			* Das leere OLE-Objekt bekommt ein neues IPObj
902 			******************************************************/
903 			if (aName.Len())
904 			{
905                 pObj->SetObjRef(xObj);
906 				pObj->SetName(aObjName);
907     			pObj->SetPersistName(aObjName);
908 			}
909 			else
910 			{
911 				// Das Einfuegen hat der Dialog schon gemacht
912                 pObj->SetObjRef(xObj);
913 			}
914 
915 			Rectangle aRect = pObj->GetLogicRect();
916 
917 			if ( pObj->GetAspect() != embed::Aspects::MSOLE_ICON )
918 			{
919             	awt::Size aSz;
920             	aSz.Width = aRect.GetWidth();
921             	aSz.Height = aRect.GetHeight();
922             	xObj->setVisualAreaSize( pObj->GetAspect(), aSz );
923 			}
924 
925             GetViewShellBase().SetVerbs( xObj->getSupportedVerbs() );
926 
927 			nVerb = SVVERB_SHOW;
928 		}
929 		else
930 		{
931 			aErrCode = ERRCODE_SFX_OLEGENERAL;
932 		}
933 	}
934 
935 	if( aErrCode == 0 )
936 	{
937 		::sd::View* pView = GetView();
938 
939 		if (pView->IsTextEdit())
940 		{
941 			pView->SdrEndTextEdit();
942 		}
943 
944         SfxInPlaceClient* pSdClient =
945             static_cast<Client*>(pViewShell->FindIPClient(
946                 pObj->GetObjRef(), GetActiveWindow()));
947 
948         if ( !pSdClient )
949 		{
950 			pSdClient = new Client(pObj, this, GetActiveWindow());
951 		}
952 
953 		Rectangle aRect = pObj->GetLogicRect();
954         Size aDrawSize = aRect.GetSize();
955 
956 		MapMode aMapMode( GetDoc()->GetScaleUnit() );
957         Size aObjAreaSize = pObj->GetOrigObjSize( &aMapMode );
958         if( pObj->IsChart() ) //charts never should be stretched see #i84323# for example
959             aObjAreaSize = aDrawSize;
960 
961         Fraction aScaleWidth (aDrawSize.Width(),  aObjAreaSize.Width() );
962         Fraction aScaleHeight(aDrawSize.Height(), aObjAreaSize.Height() );
963         aScaleWidth.ReduceInaccurate(10);       // kompatibel zum SdrOle2Obj
964         aScaleHeight.ReduceInaccurate(10);
965         pSdClient->SetSizeScale(aScaleWidth, aScaleHeight);
966 
967         // sichtbarer Ausschnitt wird nur inplace veraendert!
968         aRect.SetSize(aObjAreaSize);
969 		// the object area size must be set after scaling, since it triggers the resizing
970         pSdClient->SetObjArea(aRect);
971 
972         if( bChangeDefaultsForChart && xObj.is())
973         {
974             AdaptDefaultsForChart( xObj );
975         }
976 
977         pSdClient->DoVerb(nVerb);   // ErrCode wird ggf. vom Sfx ausgegeben
978 		pViewShell->GetViewFrame()->GetBindings().Invalidate(
979             SID_NAVIGATOR_STATE, sal_True, sal_False);
980 	}
981 
982 	GetDocSh()->SetWaitCursor( sal_False );
983 
984 	if (aErrCode != 0 && !bAbort)
985 	{
986 		ErrorHandler::HandleError(* new StringErrorInfo(aErrCode, String() ) );
987 	}
988 
989 	return aErrCode == 0;
990 }
991 
992 /*************************************************************************
993 |*
994 |* umschliessendes Rechteck aller (Split-)Fenster zurueckgeben.
995 |*
996 \************************************************************************/
997 
998 const Rectangle& ViewShell::GetAllWindowRect()
999 {
1000 	maAllWindowRectangle.SetPos(
1001         mpContentWindow->OutputToScreenPixel(Point(0,0)));
1002 	return maAllWindowRectangle;
1003 }
1004 
1005 /*************************************************************************
1006 |*
1007 |* Read user data
1008 |*
1009 \************************************************************************/
1010 void ViewShell::ReadUserData(const String&)
1011 {
1012 	// Auf an FrameView gemerkte VisArea zoomen
1013 	GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_VISAREA,
1014         SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
1015 }
1016 
1017 /*************************************************************************
1018 |*
1019 |* Write user data
1020 |*
1021 \************************************************************************/
1022 
1023 void ViewShell::WriteUserData(String&)
1024 {
1025 	// Das Schreiben unserer Daten erfolgt stets in WriteFrameViewData()
1026 	WriteFrameViewData();
1027 }
1028 
1029 
1030 /*************************************************************************
1031 |*
1032 |* Lineale ein- / ausschalten
1033 |*
1034 \************************************************************************/
1035 
1036 void ViewShell::SetRuler(sal_Bool bRuler)
1037 {
1038     mbHasRulers = ( bRuler && !GetDocSh()->IsPreview() ); // no rulers on preview mode
1039 
1040     if (mpHorizontalRuler.get() != NULL)
1041     {
1042         if (mbHasRulers)
1043         {
1044             mpHorizontalRuler->Show();
1045         }
1046         else
1047         {
1048             mpHorizontalRuler->Hide();
1049         }
1050     }
1051 
1052     if (mpVerticalRuler.get() != NULL)
1053     {
1054         if (mbHasRulers)
1055         {
1056             mpVerticalRuler->Show();
1057         }
1058         else
1059         {
1060             mpVerticalRuler->Hide();
1061         }
1062     }
1063 
1064     OSL_ASSERT(GetViewShell()!=NULL);
1065     if (IsMainViewShell())
1066         GetViewShell()->InvalidateBorder();
1067 }
1068 
1069 /*************************************************************************
1070 |*
1071 |* AcceptDrop
1072 |*
1073 \************************************************************************/
1074 
1075 sal_Int8 ViewShell::AcceptDrop (
1076     const AcceptDropEvent& rEvt,
1077     DropTargetHelper& rTargetHelper,
1078     ::sd::Window* pTargetWindow,
1079     sal_uInt16 nPage,
1080     sal_uInt16 nLayer)
1081 {
1082 	::sd::View* pView = GetView();
1083 	return( pView ? pView->AcceptDrop( rEvt, rTargetHelper, pTargetWindow, nPage, nLayer ) : DND_ACTION_NONE );
1084 }
1085 
1086 /*************************************************************************
1087 |*
1088 |* ExecuteDrop
1089 |*
1090 \************************************************************************/
1091 
1092 sal_Int8 ViewShell::ExecuteDrop (
1093     const ExecuteDropEvent& rEvt,
1094     DropTargetHelper& rTargetHelper,
1095     ::sd::Window* pTargetWindow,
1096     sal_uInt16 nPage,
1097     sal_uInt16 nLayer)
1098 {
1099 	::sd::View*	pView = GetView();
1100 	return( pView ? pView->ExecuteDrop( rEvt, rTargetHelper, pTargetWindow, nPage, nLayer ) : DND_ACTION_NONE );
1101 }
1102 
1103 #ifdef _MSC_VER
1104 #pragma optimize ( "", on )
1105 #endif
1106 
1107 void ViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence <
1108     ::com::sun::star::beans::PropertyValue >& rSequence, sal_Bool bBrowse)
1109 {
1110 	const sal_Int32 nIndex = rSequence.getLength();
1111 	rSequence.realloc( nIndex + 1 );
1112 
1113     OSL_ASSERT (GetViewShell()!=NULL);
1114     // Get the view id from the view shell in the center pane.  This will
1115     // usually be the called view shell, but to be on the safe side we call
1116     // the main view shell explicitly.
1117     sal_uInt16 nViewID (IMPRESS_FACTORY_ID);
1118     if (GetViewShellBase().GetMainViewShell().get() != NULL)
1119         nViewID = GetViewShellBase().GetMainViewShell()->mpImpl->GetViewId();
1120 	rSequence[nIndex].Name = rtl::OUString (
1121         RTL_CONSTASCII_USTRINGPARAM( sUNO_View_ViewId ) );
1122 	rtl::OUStringBuffer sBuffer (
1123         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "view" ) ) );
1124 	sBuffer.append( static_cast<sal_Int32>(nViewID));
1125 	rSequence[nIndex].Value <<= sBuffer.makeStringAndClear();
1126 
1127 	mpFrameView->WriteUserDataSequence( rSequence, bBrowse );
1128 }
1129 
1130 
1131 void ViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rSequence, sal_Bool bBrowse )
1132 {
1133 	mpFrameView->ReadUserDataSequence( rSequence, bBrowse );
1134 }
1135 
1136 void ViewShell::VisAreaChanged(const Rectangle& rRect)
1137 {
1138     OSL_ASSERT (GetViewShell()!=NULL);
1139 	GetViewShell()->VisAreaChanged(rRect);
1140 }
1141 
1142 void ViewShell::SetWinViewPos(const Point& rWinPos, bool bUpdate)
1143 {
1144     if (mpContentWindow.get() != NULL)
1145     {
1146         mpContentWindow->SetWinViewPos(rWinPos);
1147 
1148         if ( bUpdate )
1149         {
1150             mpContentWindow->UpdateMapOrigin();
1151             mpContentWindow->Invalidate();
1152         }
1153     }
1154 
1155 	if (mbHasRulers)
1156 	{
1157 		UpdateHRuler();
1158 		UpdateVRuler();
1159 	}
1160 
1161 	UpdateScrollBars();
1162 
1163 	Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
1164 	Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
1165 	VisAreaChanged(aVisAreaWin);
1166 
1167 	::sd::View* pView = GetView();
1168 	if (pView)
1169 	{
1170 		pView->VisAreaChanged(GetActiveWindow());
1171 	}
1172 }
1173 
1174 Point ViewShell::GetWinViewPos() const
1175 {
1176 	return mpContentWindow->GetWinViewPos();
1177 }
1178 
1179 Point ViewShell::GetViewOrigin() const
1180 {
1181 	return mpContentWindow->GetViewOrigin();
1182 }
1183 
1184 void ViewShell::AdaptDefaultsForChart(
1185     const uno::Reference < embed::XEmbeddedObject > & xEmbObj )
1186 {
1187     if( xEmbObj.is())
1188     {
1189         uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
1190         OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
1191         if( !xChartDoc.is())
1192             return;
1193 
1194         try
1195         {
1196             // set background to transparent (none)
1197             uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
1198             if( xPageProp.is())
1199                 xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FillStyle")),
1200                                              uno::makeAny( drawing::FillStyle_NONE ));
1201             // set no border
1202             if( xPageProp.is())
1203                 xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")),
1204                                              uno::makeAny( drawing::LineStyle_NONE ));
1205         }
1206         catch( const uno::Exception & )
1207         {
1208             OSL_ENSURE( false, "Exception caught in AdaptDefaultsForChart" );
1209         }
1210     }
1211 }
1212 
1213 } // end of namespace sd
1214