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: fupage.cxx,v $
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_sd.hxx"
37 #include <sfx2/viewfrm.hxx>
39 // Seite einrichten Tab-Page
41 #include <svx/svxids.hrc>
42 #include <svx/dialogs.hrc>
43 #include <svtools/itempool.hxx>
44 #ifndef _MSGBOX_HXX //autogen
45 #include <vcl/msgbox.hxx>
47 #include <sfx2/request.hxx>
48 #include <svtools/stritem.hxx>
49 #include <vcl/prntypes.hxx>
50 #include <svtools/style.hxx>
51 #include <stlsheet.hxx>
52 #ifndef _SVX_SVDORECT_HXX
53 #include <svx/svdorect.hxx>
55 #ifndef _SVX_SVDUNDO_HXX
56 #include <svx/svdundo.hxx>
58 #include <svx/eeitem.hxx>
59 #include <svx/frmdiritem.hxx>
60 #include <svx/xbtmpit.hxx>
61 #include <svx/xsetit.hxx>
62 #include <svtools/itempool.hxx>
63 #include <svx/ulspitem.hxx>
64 #include <svx/lrspitem.hxx>
67 #include <svx/shaditem.hxx>
68 #include <svx/boxitem.hxx>
69 #include <svx/sizeitem.hxx>
70 #include <svx/ulspitem.hxx>
71 #include <svx/lrspitem.hxx>
72 #include <svx/pbinitem.hxx>
73 #include <sfx2/app.hxx>
74 #include <svx/opengrf.hxx>
76 #include "strings.hrc"
81 #include "drawdoc.hxx"
82 #include "DrawDocShell.hxx"
83 #include "ViewShell.hxx"
84 #include "DrawViewShell.hxx"
87 #include "undoback.hxx"
88 #include "sdabstdlg.hxx"
89 #include "sdresid.hxx"
97 // erstmal vom Writer uebernommen
98 #define MAXHEIGHT 28350
99 #define MAXWIDTH 28350
102 TYPEINIT1( FuPage
, FuPoor
);
104 void mergeItemSetsImpl( SfxItemSet
& rTarget
, const SfxItemSet
& rSource
)
106 const USHORT
* pPtr
= rSource
.GetRanges();
113 // make ranges discret
114 while(pPtr
[2] && (pPtr
[2] - p2
== 1))
119 rTarget
.MergeRange( p1
, p2
);
123 rTarget
.Put(rSource
);
126 /*************************************************************************
130 \************************************************************************/
132 FuPage::FuPage( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
133 SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
134 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
136 mpArgs( rReq
.GetArgs() ),
137 mpBackgroundObjUndoAction( 0 ),
138 mbPageBckgrdDeleted( false ),
139 mbMasterPage( false ),
140 mbDisplayBackgroundTabPage( true ),
145 FunctionReference
FuPage::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
147 FunctionReference
xFunc( new FuPage( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
148 xFunc
->DoExecute(rReq
);
152 void FuPage::DoExecute( SfxRequest
& )
154 mpDrawViewShell
= dynamic_cast<DrawViewShell
*>(mpViewShell
);
155 DBG_ASSERT( mpDrawViewShell
, "sd::FuPage::FuPage(), called without a current DrawViewShell!" );
156 if( mpDrawViewShell
)
158 mbMasterPage
= mpDrawViewShell
->GetEditMode() == EM_MASTERPAGE
;
159 mbDisplayBackgroundTabPage
= (mpDrawViewShell
->GetPageKind() == PK_STANDARD
);
160 mpPage
= mpDrawViewShell
->getCurrentPage();
165 // if there are no arguments given, open the dialog
168 mpView
->SdrEndTextEdit();
169 mpArgs
= ExecuteDialog(mpWindow
);
172 // if we now have arguments, apply them to current page
174 ApplyItemSet( mpArgs
);
180 delete mpBackgroundObjUndoAction
;
183 void FuPage::Activate()
187 void FuPage::Deactivate()
191 const SfxItemSet
* FuPage::ExecuteDialog( Window
* pParent
)
193 PageKind ePageKind
= mpDrawViewShell
->GetPageKind();
195 SfxItemSet
aNewAttr(mpDoc
->GetPool(),
196 mpDoc
->GetPool().GetWhich(SID_ATTR_LRSPACE
),
197 mpDoc
->GetPool().GetWhich(SID_ATTR_ULSPACE
),
198 SID_ATTR_PAGE
, SID_ATTR_PAGE_BSP
,
199 SID_ATTR_BORDER_OUTER
, SID_ATTR_BORDER_OUTER
,
200 SID_ATTR_BORDER_SHADOW
, SID_ATTR_BORDER_SHADOW
,
201 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
202 EE_PARA_WRITINGDIR
, EE_PARA_WRITINGDIR
,
205 ///////////////////////////////////////////////////////////////////////
206 // Retrieve additional data for dialog
208 SvxShadowItem
aShadowItem(SID_ATTR_BORDER_SHADOW
);
209 aNewAttr
.Put( aShadowItem
);
210 SvxBoxItem
aBoxItem( SID_ATTR_BORDER_OUTER
);
211 aNewAttr
.Put( aBoxItem
);
213 aNewAttr
.Put( SvxFrameDirectionItem(
214 mpDoc
->GetDefaultWritingMode() == ::com::sun::star::text::WritingMode_RL_TB
? FRMDIR_HORI_RIGHT_TOP
: FRMDIR_HORI_LEFT_TOP
,
215 EE_PARA_WRITINGDIR
) );
217 ///////////////////////////////////////////////////////////////////////
218 // Retrieve page-data for dialog
220 SvxPageItem
aPageItem( SID_ATTR_PAGE
);
221 aPageItem
.SetDescName( mpPage
->GetName() );
222 aPageItem
.SetPageUsage( (SvxPageUsage
) SVX_PAGE_ALL
);
223 aPageItem
.SetLandscape( mpPage
->GetOrientation() == ORIENTATION_LANDSCAPE
? TRUE
: FALSE
);
224 aPageItem
.SetNumType( mpDoc
->GetPageNumType() );
225 aNewAttr
.Put( aPageItem
);
228 maSize
= mpPage
->GetSize();
229 SvxSizeItem
aSizeItem( SID_ATTR_PAGE_SIZE
, maSize
);
230 aNewAttr
.Put( aSizeItem
);
233 SvxSizeItem
aMaxSizeItem( SID_ATTR_PAGE_MAXSIZE
, Size( MAXWIDTH
, MAXHEIGHT
) );
234 aNewAttr
.Put( aMaxSizeItem
);
237 SvxPaperBinItem
aPaperBinItem( SID_ATTR_PAGE_PAPERBIN
, (const BYTE
)mpPage
->GetPaperBin() );
238 aNewAttr
.Put( aPaperBinItem
);
240 SvxLRSpaceItem
aLRSpaceItem( (USHORT
)mpPage
->GetLftBorder(), (USHORT
)mpPage
->GetRgtBorder(), 0, 0, mpDoc
->GetPool().GetWhich(SID_ATTR_LRSPACE
));
241 aNewAttr
.Put( aLRSpaceItem
);
243 SvxULSpaceItem
aULSpaceItem( (USHORT
)mpPage
->GetUppBorder(), (USHORT
)mpPage
->GetLwrBorder(), mpDoc
->GetPool().GetWhich(SID_ATTR_ULSPACE
));
244 aNewAttr
.Put( aULSpaceItem
);
247 bool bScale
= mpDoc
->GetDocumentType() != DOCUMENT_TYPE_DRAW
;
248 aNewAttr
.Put( SfxBoolItem( SID_ATTR_PAGE_EXT1
, bScale
? TRUE
: FALSE
) );
250 BOOL bFullSize
= mpPage
->IsMasterPage() ?
251 mpPage
->IsBackgroundFullSize() : ((SdPage
&)mpPage
->TRG_GetMasterPage()).IsBackgroundFullSize();
253 aNewAttr
.Put( SfxBoolItem( SID_ATTR_PAGE_EXT2
, bFullSize
) );
255 ///////////////////////////////////////////////////////////////////////
256 // Merge ItemSet for dialog
258 const USHORT
* pPtr
= aNewAttr
.GetRanges();
259 USHORT p1
= pPtr
[0], p2
= pPtr
[1];
260 while(pPtr
[2] && (pPtr
[2] - p2
== 1))
266 SfxItemSet
aMergedAttr( *aNewAttr
.GetPool(), p1
, p2
);
268 mergeItemSetsImpl( aMergedAttr
, aNewAttr
);
270 SdStyleSheet
* pStyleSheet
= mpPage
->getPresentationStyle(HID_PSEUDOSHEET_BACKGROUND
);
272 // merge page background filling to the dialogs input set
273 if( mbDisplayBackgroundTabPage
)
278 mergeItemSetsImpl( aMergedAttr
, pStyleSheet
->GetItemSet() );
282 // Only this page, check if there is a background-object on that page
283 SdrObject
* pObj
= mpPage
->GetBackgroundObj();
286 aMergedAttr
.Put(pObj
->GetMergedItemSet());
290 // if the page hasn't got a background-object, than use
291 // the fillstyle-settings of the masterpage for the dialog
292 if( pStyleSheet
&& pStyleSheet
->GetItemSet().GetItemState( XATTR_FILLSTYLE
) != SFX_ITEM_DEFAULT
)
293 mergeItemSetsImpl( aMergedAttr
, pStyleSheet
->GetItemSet() );
295 aMergedAttr
.Put( XFillStyleItem( XFILL_NONE
) );
300 std::auto_ptr
< SfxItemSet
> pTempSet
;
302 if( GetSlotID() == SID_SELECT_BACKGROUND
)
304 SvxOpenGraphicDialog
aDlg(SdResId(STR_SET_BACKGROUND_PICTURE
));
306 if( aDlg
.Execute() == GRFILTER_OK
)
309 int nError
= aDlg
.GetGraphic(aGraphic
);
310 if( nError
== GRFILTER_OK
)
312 pTempSet
.reset( new SfxItemSet( mpDoc
->GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
, 0) );
314 pTempSet
->Put( XFillStyleItem( XFILL_BITMAP
) );
315 pTempSet
->Put( XFillBitmapItem( String(RTL_CONSTASCII_USTRINGPARAM("background")), XOBitmap(aGraphic
) ) );
316 pTempSet
->Put( XFillBmpStretchItem( TRUE
));
317 pTempSet
->Put( XFillBmpTileItem( FALSE
));
324 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
325 std::auto_ptr
<SfxAbstractTabDialog
> pDlg( pFact
? pFact
->CreateSdTabPageDialog(NULL
, &aMergedAttr
, mpDocSh
, mbDisplayBackgroundTabPage
) : 0 );
326 if( pDlg
.get() && pDlg
->Execute() == RET_OK
)
327 pTempSet
.reset( new SfxItemSet(*pDlg
->GetOutputItemSet()) );
332 pStyleSheet
->AdjustToFontHeight(*pTempSet
);
334 if( mbDisplayBackgroundTabPage
)
336 // if some fillstyle-items are not set in the dialog, then
337 // try to use the items before
338 BOOL bChanges
= FALSE
;
339 for( USHORT i
=XATTR_FILL_FIRST
; i
<XATTR_FILL_LAST
; i
++ )
341 if( aMergedAttr
.GetItemState( i
) != SFX_ITEM_DEFAULT
)
343 if( pTempSet
->GetItemState( i
) == SFX_ITEM_DEFAULT
)
344 pTempSet
->Put( aMergedAttr
.Get( i
) );
346 if( aMergedAttr
.GetItem( i
) != pTempSet
->GetItem( i
) )
351 // if the background for this page was set to invisible, the background-object has to be deleted, too.
352 if( ( ( (XFillStyleItem
*) pTempSet
->GetItem( XATTR_FILLSTYLE
) )->GetValue() == XFILL_NONE
) ||
353 ( ( pTempSet
->GetItemState( XATTR_FILLSTYLE
) == SFX_ITEM_DEFAULT
) &&
354 ( ( (XFillStyleItem
*) aMergedAttr
.GetItem( XATTR_FILLSTYLE
) )->GetValue() == XFILL_NONE
) ) )
355 mbPageBckgrdDeleted
= TRUE
;
357 // Ask, wether the setting are for the background-page or for the current page
358 if( !mbMasterPage
&& bChanges
)
360 // But don't ask in notice-view, because we can't change the background of
361 // notice-masterpage (at the moment)
362 if( ePageKind
!= PK_NOTES
)
364 String
aTit(SdResId( STR_PAGE_BACKGROUND_TITLE
));
365 String
aTxt(SdResId( STR_PAGE_BACKGROUND_TXT
));
366 MessBox
aQuestionBox (
368 WB_YES_NO
| WB_DEF_YES
,
371 aQuestionBox
.SetImage( QueryBox::GetStandardImage() );
372 mbMasterPage
= ( RET_YES
== aQuestionBox
.Execute() );
375 if( mbPageBckgrdDeleted
)
377 mpBackgroundObjUndoAction
= new SdBackgroundObjUndoAction( *mpDoc
, *mpPage
, mpPage
->GetBackgroundObj() );
378 mpPage
->SetBackgroundObj( NULL
);
381 // tell the page that it's visualization has changed
382 mpPage
->ActionChanged();
386 // Sonderbehandlung: die INVALIDS auf NULL-Pointer
387 // zurueckgesetzen (sonst landen INVALIDs oder
388 // Pointer auf die DefaultItems in der Vorlage;
389 // beides wuerde die Attribut-Vererbung unterbinden)
390 pTempSet
->ClearInvalidItems();
394 StyleSheetUndoAction
* pAction
= new StyleSheetUndoAction(mpDoc
, (SfxStyleSheet
*)pStyleSheet
, &(*pTempSet
.get()));
395 mpDocSh
->GetUndoManager()->AddUndoAction(pAction
);
396 pStyleSheet
->GetItemSet().Put( *(pTempSet
.get()) );
397 pStyleSheet
->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED
));
400 const SfxPoolItem
*pItem
;
401 if( SFX_ITEM_SET
== pTempSet
->GetItemState( EE_PARA_WRITINGDIR
, sal_False
, &pItem
) )
403 sal_uInt32 nVal
= ((SvxFrameDirectionItem
*)pItem
)->GetValue();
404 mpDoc
->SetDefaultWritingMode( nVal
== FRMDIR_HORI_RIGHT_TOP
? ::com::sun::star::text::WritingMode_RL_TB
: ::com::sun::star::text::WritingMode_LR_TB
);
407 mpDoc
->SetChanged(TRUE
);
409 SdrObject
* pObj
= mpPage
->IsMasterPage() ?
410 mpPage
->GetPresObj( PRESOBJ_BACKGROUND
) :
411 ((SdPage
&)(mpPage
->TRG_GetMasterPage())).GetPresObj( PRESOBJ_BACKGROUND
);
414 // BackgroundObj: no hard attributes allowed
415 SfxItemSet
aSet( mpDoc
->GetPool() );
416 pObj
->SetMergedItemSet(aSet
);
420 aNewAttr
.Put(*(pTempSet
.get()));
421 mrReq
.Done( aNewAttr
);
423 return mrReq
.GetArgs();
431 void FuPage::ApplyItemSet( const SfxItemSet
* pArgs
)
436 ///////////////////////////////////////////////////////////////////////////
437 // Set new page-attributes
438 PageKind ePageKind
= mpDrawViewShell
->GetPageKind();
439 const SfxPoolItem
* pPoolItem
;
440 BOOL bSetPageSizeAndBorder
= FALSE
;
441 Size
aNewSize(maSize
);
442 INT32 nLeft
= -1, nRight
= -1, nUpper
= -1, nLower
= -1;
443 BOOL bScaleAll
= TRUE
;
444 Orientation eOrientation
= mpPage
->GetOrientation();
445 SdPage
* pMasterPage
= mpPage
->IsMasterPage() ? mpPage
: &(SdPage
&)(mpPage
->TRG_GetMasterPage());
446 BOOL bFullSize
= pMasterPage
->IsBackgroundFullSize();
447 USHORT nPaperBin
= mpPage
->GetPaperBin();
449 if( pArgs
->GetItemState(SID_ATTR_PAGE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
451 mpDoc
->SetPageNumType(((const SvxPageItem
*) pPoolItem
)->GetNumType());
453 eOrientation
= (((const SvxPageItem
*) pPoolItem
)->IsLandscape() == ORIENTATION_LANDSCAPE
) ?
454 ORIENTATION_LANDSCAPE
: ORIENTATION_PORTRAIT
;
456 if( mpPage
->GetOrientation() != eOrientation
)
457 bSetPageSizeAndBorder
= TRUE
;
459 mpDrawViewShell
->ResetActualPage();
462 if( pArgs
->GetItemState(SID_ATTR_PAGE_SIZE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
464 aNewSize
= ((const SvxSizeItem
*) pPoolItem
)->GetSize();
466 if( mpPage
->GetSize() != aNewSize
)
467 bSetPageSizeAndBorder
= TRUE
;
470 if( pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_ATTR_LRSPACE
),
471 TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
473 nLeft
= ((const SvxLRSpaceItem
*) pPoolItem
)->GetLeft();
474 nRight
= ((const SvxLRSpaceItem
*) pPoolItem
)->GetRight();
476 if( mpPage
->GetLftBorder() != nLeft
|| mpPage
->GetRgtBorder() != nRight
)
477 bSetPageSizeAndBorder
= TRUE
;
481 if( pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_ATTR_ULSPACE
),
482 TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
484 nUpper
= ((const SvxULSpaceItem
*) pPoolItem
)->GetUpper();
485 nLower
= ((const SvxULSpaceItem
*) pPoolItem
)->GetLower();
487 if( mpPage
->GetUppBorder() != nUpper
|| mpPage
->GetLwrBorder() != nLower
)
488 bSetPageSizeAndBorder
= TRUE
;
491 if( pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_ATTR_PAGE_EXT1
), TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
493 bScaleAll
= ((const SfxBoolItem
*) pPoolItem
)->GetValue();
496 if( pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_ATTR_PAGE_EXT2
), TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
498 bFullSize
= ((const SfxBoolItem
*) pPoolItem
)->GetValue();
500 if(pMasterPage
->IsBackgroundFullSize() != bFullSize
)
501 bSetPageSizeAndBorder
= TRUE
;
504 // Papierschacht (PaperBin)
505 if( pArgs
->GetItemState(mpDoc
->GetPool().GetWhich(SID_ATTR_PAGE_PAPERBIN
), TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
507 nPaperBin
= ((const SvxPaperBinItem
*) pPoolItem
)->GetValue();
509 if( mpPage
->GetPaperBin() != nPaperBin
)
510 bSetPageSizeAndBorder
= TRUE
;
513 if (nLeft
== -1 && nUpper
!= -1)
515 bSetPageSizeAndBorder
= TRUE
;
516 nLeft
= mpPage
->GetLftBorder();
517 nRight
= mpPage
->GetRgtBorder();
519 else if (nLeft
!= -1 && nUpper
== -1)
521 bSetPageSizeAndBorder
= TRUE
;
522 nUpper
= mpPage
->GetUppBorder();
523 nLower
= mpPage
->GetLwrBorder();
526 if( bSetPageSizeAndBorder
|| !mbMasterPage
)
527 mpDrawViewShell
->SetPageSizeAndBorder(ePageKind
, aNewSize
, nLeft
, nRight
, nUpper
, nLower
, bScaleAll
, eOrientation
, nPaperBin
, bFullSize
);
529 ////////////////////////////////////////////////////////////////////////////////
531 // if bMasterPage==FALSE then create a background-object for this page with the
532 // properties set in the dialog before, but if mbPageBckgrdDeleted==TRUE then
533 // the background of this page was set to invisible, so it would be a mistake
534 // to create a new background-object for this page !
537 if( mbDisplayBackgroundTabPage
)
539 if( !mbMasterPage
&& !mbPageBckgrdDeleted
)
542 SdrObject
* pObj
= mpPage
->GetBackgroundObj();
544 delete mpBackgroundObjUndoAction
;
545 mpBackgroundObjUndoAction
= new SdBackgroundObjUndoAction( *mpDoc
, *mpPage
, pObj
);
549 pObj
= new SdrRectObj();
550 mpPage
->SetBackgroundObj( pObj
);
553 Point
aPos ( nLeft
, nUpper
);
554 Size
aSize( mpPage
->GetSize() );
555 aSize
.Width() -= nLeft
+ nRight
- 1;
556 aSize
.Height() -= nUpper
+ nLower
- 1;
557 Rectangle
aRect( aPos
, aSize
);
558 pObj
->SetLogicRect( aRect
);
559 pObj
->SetMergedItemSet(*pArgs
);
562 // tell the page that it's visualization has changed
563 mpPage
->ActionChanged();
567 // add undo action for background object
568 if( mpBackgroundObjUndoAction
)
570 // set merge flag, because a SdUndoGroupAction could have been inserted before
571 mpDocSh
->GetUndoManager()->AddUndoAction( mpBackgroundObjUndoAction
, TRUE
);
572 mpBackgroundObjUndoAction
= 0;
575 ///////////////////////////////////////////////////////////////////////////
577 // Objekte koennen max. so gross wie die ViewSize werden
579 Size aPageSize
= mpDoc
->GetSdPage(0, ePageKind
)->GetSize();
580 Size aViewSize
= Size(aPageSize
.Width() * 3, aPageSize
.Height() * 2);
581 mpDoc
->SetMaxObjSize(aViewSize
);
583 ///////////////////////////////////////////////////////////////////////////
585 // ggfs. Preview den neuen Kontext mitteilen
587 mpDrawViewShell
->UpdatePreview( mpDrawViewShell
->GetActualPage() );
590 } // end of namespace sd