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