xref: /trunk/main/sd/source/ui/dlg/masterlayoutdlg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 #ifndef _SVX_DIALOGS_HRC
36 #include <svx/dialogs.hrc>
37 #endif
38 
39 #ifndef _SD_SDRESID_HXX
40 #include "sdresid.hxx"
41 #endif
42 
43 #include "strings.hrc"
44 #include "dialogs.hrc"
45 #include "masterlayoutdlg.hxx"
46 #include "masterlayoutdlg.hrc"
47 #include "drawdoc.hxx"
48 
49 using namespace ::sd;
50 
51 MasterLayoutDialog::MasterLayoutDialog( Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage )
52 :   ModalDialog( pParent, SdResId( RID_SD_DLG_MASTER_LAYOUT ) ),
53     mpDoc( pDoc ),
54     mpCurrentPage( pCurrentPage ),
55     maFLPlaceholders( this, SdResId( FL_PLACEHOLDERS ) ),
56     maCBDate( this, SdResId( CB_DATE ) ),
57     maCBPageNumber( this, SdResId( CB_PAGE_NUMBER ) ),
58     maCBHeader( this, SdResId( CB_HEADER ) ),
59     maCBFooter( this, SdResId( CB_FOOTER ) ),
60     maPBOK( this, SdResId( BT_OK ) ),
61     maPBCancel( this, SdResId( BT_CANCEL ) )
62 {
63     if( mpCurrentPage && !mpCurrentPage->IsMasterPage() )
64     {
65         mpCurrentPage = (SdPage*)(&(mpCurrentPage->TRG_GetMasterPage()));
66     }
67 
68     if( mpCurrentPage == 0 )
69     {
70         mpCurrentPage = pDoc->GetMasterSdPage( 0, PK_STANDARD );
71         DBG_ERROR( "MasterLayoutDialog::MasterLayoutDialog() - no current page?" );
72     }
73 
74     switch( mpCurrentPage->GetPageKind() )
75     {
76     case PK_STANDARD:
77     {
78         //      aTitle = String( SdResId( STR_MASTER_LAYOUT_TITLE ) );
79         maCBHeader.Enable( sal_False );
80     String aSlideNumberStr( SdResId( STR_SLIDE_NUMBER ) );
81         maCBPageNumber.SetText( aSlideNumberStr );
82         break;
83     }
84     case PK_NOTES:
85         //      aTitle = String( SdResId( STR_NOTES_MASTER_LAYOUT_TITLE ) );
86         break;
87     case PK_HANDOUT:
88         //      aTitle = String( SdResId( STR_HANDOUT_TEMPLATE_LAYOUT_TITLE ) );
89         break;
90     }
91     String aTitle (SdResId( STR_MASTER_LAYOUT_TITLE ) );
92 
93     SetText( aTitle );
94 
95     FreeResource();
96 
97     mbOldHeader = mpCurrentPage->GetPresObj( PRESOBJ_HEADER ) != NULL;
98     mbOldDate = mpCurrentPage->GetPresObj( PRESOBJ_DATETIME ) != NULL;
99     mbOldFooter = mpCurrentPage->GetPresObj( PRESOBJ_FOOTER ) != NULL;
100     mbOldPageNumber = mpCurrentPage->GetPresObj( PRESOBJ_SLIDENUMBER ) != NULL;
101 
102     maCBHeader.Check( mbOldHeader );
103     maCBDate.Check( mbOldDate );
104     maCBFooter.Check( mbOldFooter );
105     maCBPageNumber.Check( mbOldPageNumber );
106 }
107 
108 MasterLayoutDialog::~MasterLayoutDialog()
109 {
110 }
111 
112 short MasterLayoutDialog::Execute()
113 {
114     if ( ModalDialog::Execute() )
115         applyChanges();
116     return 1;
117 }
118 
119 void MasterLayoutDialog::applyChanges()
120 {
121     mpDoc->BegUndo(GetText());
122 
123     if( (mpCurrentPage->GetPageKind() != PK_STANDARD) && (mbOldHeader != maCBHeader.IsChecked() ) )
124     {
125         if( mbOldHeader )
126             remove( PRESOBJ_HEADER );
127         else
128             create( PRESOBJ_HEADER );
129     }
130 
131     if( mbOldFooter != maCBFooter.IsChecked() )
132     {
133         if( mbOldFooter )
134             remove( PRESOBJ_FOOTER );
135         else
136             create( PRESOBJ_FOOTER );
137     }
138 
139     if( mbOldDate != maCBDate.IsChecked() )
140     {
141         if( mbOldDate )
142             remove( PRESOBJ_DATETIME );
143         else
144             create( PRESOBJ_DATETIME );
145     }
146 
147     if( mbOldPageNumber != maCBPageNumber.IsChecked() )
148     {
149         if( mbOldPageNumber )
150             remove( PRESOBJ_SLIDENUMBER );
151         else
152             create( PRESOBJ_SLIDENUMBER );
153     }
154 
155     mpDoc->EndUndo();
156 }
157 
158 void MasterLayoutDialog::create( PresObjKind eKind )
159 {
160     mpCurrentPage->CreateDefaultPresObj( eKind, true );
161 }
162 
163 void MasterLayoutDialog::remove( PresObjKind eKind )
164 {
165     SdrObject* pObject = mpCurrentPage->GetPresObj( eKind );
166 
167     if( pObject )
168     {
169         const bool bUndo = mpDoc->IsUndoEnabled();
170         if( bUndo )
171             mpDoc->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pObject));
172         SdrObjList* pOL =pObject->GetObjList();
173         sal_uInt32 nOrdNum=pObject->GetOrdNumDirect();
174         pOL->RemoveObject(nOrdNum);
175 
176         if( !bUndo )
177             SdrObject::Free(pObject);
178     }
179 }
180