xref: /aoo41x/main/sd/source/ui/dlg/masterlayoutdlg.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _SVX_DIALOGS_HRC
32cdf0e10cSrcweir #include <svx/dialogs.hrc>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _SD_SDRESID_HXX
36cdf0e10cSrcweir #include "sdresid.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "strings.hrc"
40cdf0e10cSrcweir #include "dialogs.hrc"
41cdf0e10cSrcweir #include "masterlayoutdlg.hxx"
42cdf0e10cSrcweir #include "masterlayoutdlg.hrc"
43cdf0e10cSrcweir #include "drawdoc.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace ::sd;
46cdf0e10cSrcweir 
MasterLayoutDialog(Window * pParent,SdDrawDocument * pDoc,SdPage * pCurrentPage)47cdf0e10cSrcweir MasterLayoutDialog::MasterLayoutDialog( Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage )
48cdf0e10cSrcweir :	ModalDialog( pParent, SdResId( RID_SD_DLG_MASTER_LAYOUT ) ),
49cdf0e10cSrcweir 	mpDoc( pDoc ),
50cdf0e10cSrcweir 	mpCurrentPage( pCurrentPage ),
51cdf0e10cSrcweir 	maFLPlaceholders( this, SdResId( FL_PLACEHOLDERS ) ),
52cdf0e10cSrcweir 	maCBDate( this, SdResId( CB_DATE ) ),
53cdf0e10cSrcweir 	maCBPageNumber( this, SdResId( CB_PAGE_NUMBER ) ),
54cdf0e10cSrcweir 	maCBHeader( this, SdResId( CB_HEADER ) ),
55cdf0e10cSrcweir 	maCBFooter( this, SdResId( CB_FOOTER ) ),
56cdf0e10cSrcweir 	maPBOK( this, SdResId( BT_OK ) ),
57cdf0e10cSrcweir 	maPBCancel( this, SdResId( BT_CANCEL ) )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	if( mpCurrentPage && !mpCurrentPage->IsMasterPage() )
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir         mpCurrentPage = (SdPage*)(&(mpCurrentPage->TRG_GetMasterPage()));
62cdf0e10cSrcweir 	}
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	if( mpCurrentPage == 0 )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		mpCurrentPage = pDoc->GetMasterSdPage( 0, PK_STANDARD );
67cdf0e10cSrcweir 		DBG_ERROR( "MasterLayoutDialog::MasterLayoutDialog() - no current page?" );
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	switch( mpCurrentPage->GetPageKind() )
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 	case PK_STANDARD:
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir         //		aTitle = String( SdResId( STR_MASTER_LAYOUT_TITLE ) );
75cdf0e10cSrcweir 		maCBHeader.Enable( sal_False );
76cdf0e10cSrcweir 	String aSlideNumberStr( SdResId( STR_SLIDE_NUMBER ) );
77cdf0e10cSrcweir 		maCBPageNumber.SetText( aSlideNumberStr );
78cdf0e10cSrcweir 		break;
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir 	case PK_NOTES:
81cdf0e10cSrcweir         //		aTitle = String( SdResId( STR_NOTES_MASTER_LAYOUT_TITLE ) );
82cdf0e10cSrcweir 		break;
83cdf0e10cSrcweir 	case PK_HANDOUT:
84cdf0e10cSrcweir         //		aTitle = String( SdResId( STR_HANDOUT_TEMPLATE_LAYOUT_TITLE ) );
85cdf0e10cSrcweir 		break;
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	String aTitle (SdResId( STR_MASTER_LAYOUT_TITLE ) );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	SetText( aTitle );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	FreeResource();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	mbOldHeader = mpCurrentPage->GetPresObj( PRESOBJ_HEADER ) != NULL;
94cdf0e10cSrcweir 	mbOldDate = mpCurrentPage->GetPresObj( PRESOBJ_DATETIME ) != NULL;
95cdf0e10cSrcweir 	mbOldFooter = mpCurrentPage->GetPresObj( PRESOBJ_FOOTER ) != NULL;
96cdf0e10cSrcweir 	mbOldPageNumber = mpCurrentPage->GetPresObj( PRESOBJ_SLIDENUMBER ) != NULL;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	maCBHeader.Check( mbOldHeader );
99cdf0e10cSrcweir 	maCBDate.Check( mbOldDate );
100cdf0e10cSrcweir 	maCBFooter.Check( mbOldFooter );
101cdf0e10cSrcweir 	maCBPageNumber.Check( mbOldPageNumber );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
~MasterLayoutDialog()104cdf0e10cSrcweir MasterLayoutDialog::~MasterLayoutDialog()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
Execute()108cdf0e10cSrcweir short MasterLayoutDialog::Execute()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	if ( ModalDialog::Execute() )
111cdf0e10cSrcweir 		applyChanges();
112cdf0e10cSrcweir     return 1;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
applyChanges()115cdf0e10cSrcweir void MasterLayoutDialog::applyChanges()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	mpDoc->BegUndo(GetText());
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	if( (mpCurrentPage->GetPageKind() != PK_STANDARD) && (mbOldHeader != maCBHeader.IsChecked() ) )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		if( mbOldHeader )
122cdf0e10cSrcweir 			remove( PRESOBJ_HEADER );
123cdf0e10cSrcweir 		else
124cdf0e10cSrcweir 			create( PRESOBJ_HEADER );
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	if( mbOldFooter != maCBFooter.IsChecked() )
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		if( mbOldFooter )
130cdf0e10cSrcweir 			remove( PRESOBJ_FOOTER );
131cdf0e10cSrcweir 		else
132cdf0e10cSrcweir 			create( PRESOBJ_FOOTER );
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if( mbOldDate != maCBDate.IsChecked() )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		if( mbOldDate )
138cdf0e10cSrcweir 			remove( PRESOBJ_DATETIME );
139cdf0e10cSrcweir 		else
140cdf0e10cSrcweir 			create( PRESOBJ_DATETIME );
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	if( mbOldPageNumber != maCBPageNumber.IsChecked() )
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		if( mbOldPageNumber )
146cdf0e10cSrcweir 			remove( PRESOBJ_SLIDENUMBER );
147cdf0e10cSrcweir 		else
148cdf0e10cSrcweir 			create( PRESOBJ_SLIDENUMBER );
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	mpDoc->EndUndo();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
create(PresObjKind eKind)154cdf0e10cSrcweir void MasterLayoutDialog::create( PresObjKind eKind )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     mpCurrentPage->CreateDefaultPresObj( eKind, true );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
remove(PresObjKind eKind)159cdf0e10cSrcweir void MasterLayoutDialog::remove( PresObjKind eKind )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	SdrObject* pObject = mpCurrentPage->GetPresObj( eKind );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	if( pObject )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		const bool bUndo = mpDoc->IsUndoEnabled();
166cdf0e10cSrcweir 		if( bUndo )
167cdf0e10cSrcweir 			mpDoc->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pObject));
168cdf0e10cSrcweir 		SdrObjList* pOL =pObject->GetObjList();
169cdf0e10cSrcweir 		sal_uInt32 nOrdNum=pObject->GetOrdNumDirect();
170cdf0e10cSrcweir 		pOL->RemoveObject(nOrdNum);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		if( !bUndo )
173cdf0e10cSrcweir 			SdrObject::Free(pObject);
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir }
176