Update ooo320-m1
[ooovba.git] / sd / source / ui / dlg / masterlayoutdlg.cxx
blob411ad98133a4697b794de61c0a4655971a4fd2af
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: masterlayoutdlg.cxx,v $
10 * $Revision: 1.12 $
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"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
36 #endif
38 #ifndef _SVX_DIALOGS_HRC
39 #include <svx/dialogs.hrc>
40 #endif
42 #ifndef _SD_SDRESID_HXX
43 #include "sdresid.hxx"
44 #endif
46 #include "strings.hrc"
47 #include "dialogs.hrc"
48 #include "masterlayoutdlg.hxx"
49 #include "masterlayoutdlg.hrc"
50 #include "drawdoc.hxx"
52 using namespace ::sd;
54 MasterLayoutDialog::MasterLayoutDialog( Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage )
55 : ModalDialog( pParent, SdResId( RID_SD_DLG_MASTER_LAYOUT ) ),
56 mpDoc( pDoc ),
57 mpCurrentPage( pCurrentPage ),
58 maFLPlaceholders( this, SdResId( FL_PLACEHOLDERS ) ),
59 maCBDate( this, SdResId( CB_DATE ) ),
60 maCBPageNumber( this, SdResId( CB_PAGE_NUMBER ) ),
61 maCBHeader( this, SdResId( CB_HEADER ) ),
62 maCBFooter( this, SdResId( CB_FOOTER ) ),
63 maPBOK( this, SdResId( BT_OK ) ),
64 maPBCancel( this, SdResId( BT_CANCEL ) )
66 if( mpCurrentPage && !mpCurrentPage->IsMasterPage() )
68 mpCurrentPage = (SdPage*)(&(mpCurrentPage->TRG_GetMasterPage()));
71 if( mpCurrentPage == 0 )
73 mpCurrentPage = pDoc->GetMasterSdPage( 0, PK_STANDARD );
74 DBG_ERROR( "MasterLayoutDialog::MasterLayoutDialog() - no current page?" );
77 switch( mpCurrentPage->GetPageKind() )
79 case PK_STANDARD:
81 // aTitle = String( SdResId( STR_MASTER_LAYOUT_TITLE ) );
82 maCBHeader.Enable( FALSE );
83 String aSlideNumberStr( SdResId( STR_SLIDE_NUMBER ) );
84 maCBPageNumber.SetText( aSlideNumberStr );
85 break;
87 case PK_NOTES:
88 // aTitle = String( SdResId( STR_NOTES_MASTER_LAYOUT_TITLE ) );
89 break;
90 case PK_HANDOUT:
91 // aTitle = String( SdResId( STR_HANDOUT_TEMPLATE_LAYOUT_TITLE ) );
92 break;
94 String aTitle (SdResId( STR_MASTER_LAYOUT_TITLE ) );
96 SetText( aTitle );
98 FreeResource();
100 mbOldHeader = mpCurrentPage->GetPresObj( PRESOBJ_HEADER ) != NULL;
101 mbOldDate = mpCurrentPage->GetPresObj( PRESOBJ_DATETIME ) != NULL;
102 mbOldFooter = mpCurrentPage->GetPresObj( PRESOBJ_FOOTER ) != NULL;
103 mbOldPageNumber = mpCurrentPage->GetPresObj( PRESOBJ_SLIDENUMBER ) != NULL;
105 maCBHeader.Check( mbOldHeader );
106 maCBDate.Check( mbOldDate );
107 maCBFooter.Check( mbOldFooter );
108 maCBPageNumber.Check( mbOldPageNumber );
111 MasterLayoutDialog::~MasterLayoutDialog()
115 short MasterLayoutDialog::Execute()
117 if ( ModalDialog::Execute() )
118 applyChanges();
119 return 1;
122 void MasterLayoutDialog::applyChanges()
124 mpDoc->BegUndo(GetText());
126 if( (mpCurrentPage->GetPageKind() != PK_STANDARD) && (mbOldHeader != maCBHeader.IsChecked() ) )
128 if( mbOldHeader )
129 remove( PRESOBJ_HEADER );
130 else
131 create( PRESOBJ_HEADER );
134 if( mbOldFooter != maCBFooter.IsChecked() )
136 if( mbOldFooter )
137 remove( PRESOBJ_FOOTER );
138 else
139 create( PRESOBJ_FOOTER );
142 if( mbOldDate != maCBDate.IsChecked() )
144 if( mbOldDate )
145 remove( PRESOBJ_DATETIME );
146 else
147 create( PRESOBJ_DATETIME );
150 if( mbOldPageNumber != maCBPageNumber.IsChecked() )
152 if( mbOldPageNumber )
153 remove( PRESOBJ_SLIDENUMBER );
154 else
155 create( PRESOBJ_SLIDENUMBER );
158 mpDoc->EndUndo();
161 void MasterLayoutDialog::create( PresObjKind eKind )
163 mpCurrentPage->CreateDefaultPresObj( eKind, true );
166 void MasterLayoutDialog::remove( PresObjKind eKind )
168 SdrObject* pObject = mpCurrentPage->GetPresObj( eKind );
170 if( pObject )
172 const bool bUndo = mpDoc->IsUndoEnabled();
173 if( bUndo )
174 mpDoc->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pObject));
175 SdrObjList* pOL =pObject->GetObjList();
176 UINT32 nOrdNum=pObject->GetOrdNumDirect();
177 pOL->RemoveObject(nOrdNum);
179 if( !bUndo )
180 SdrObject::Free(pObject);