xref: /trunk/main/sd/source/ui/app/sdpopup.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
32 #include <editeng/eeitem.hxx>
33 
34 #include <editeng/editeng.hxx>
35 #include <editeng/flditem.hxx>
36 #include <svl/zforlist.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <unotools/useroptions.hxx>
40 
41 #include "strings.hrc"
42 #include "sdpopup.hxx"
43 #include "sdresid.hxx"
44 #include "sdmod.hxx"
45 #include "drawdoc.hxx"
46 #include "DrawDocShell.hxx"
47 
48 /*************************************************************************
49 |*
50 |* PopupMenu zum Bearbeiten von Feldbefehlen
51 |*
52 \************************************************************************/
53 
54 SdFieldPopup::SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage ) :
55         PopupMenu   (),
56         pField      ( pInField )
57 {
58     Fill( eLanguage );
59 }
60 
61 /*************************************************************************
62 |*
63 |* Dtor
64 |*
65 \************************************************************************/
66 
67 SdFieldPopup::~SdFieldPopup()
68 {
69 }
70 
71 /*************************************************************************
72 |*
73 |* Fill
74 |*
75 \************************************************************************/
76 
77 void SdFieldPopup::Fill( LanguageType eLanguage )
78 {
79     sal_uInt16 nID = 1;
80     sal_uInt16 nStyle = MIB_RADIOCHECK | MIB_AUTOCHECK;
81     InsertItem( nID++, String( SdResId( STR_FIX ) ), nStyle );
82     InsertItem( nID++, String( SdResId( STR_VAR ) ), nStyle );
83     InsertSeparator();
84 
85     if( pField->ISA( SvxDateField ) )
86     {
87         const SvxDateField* pDateField = (const SvxDateField*) pField;
88         SvxDateField aDateField( *pDateField );
89 
90         if( pDateField->GetType() == SVXDATETYPE_FIX )
91             CheckItem( 1 );
92         else
93             CheckItem( 2 );
94 
95         //SVXDATEFORMAT_APPDEFAULT,     // Wird nicht benutzt
96         //SVXDATEFORMAT_SYSTEM,         // Wird nicht benutzt
97         InsertItem( nID++, String( SdResId( STR_STANDARD_SMALL ) ), nStyle );
98         InsertItem( nID++, String( SdResId( STR_STANDARD_BIG ) ), nStyle );
99 
100         SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
101         aDateField.SetFormat( SVXDATEFORMAT_A );    // 13.02.96
102         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
103         aDateField.SetFormat( SVXDATEFORMAT_B );    // 13.02.1996
104         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
105         aDateField.SetFormat( SVXDATEFORMAT_C );    // 13.Feb 1996
106         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
107 
108         aDateField.SetFormat( SVXDATEFORMAT_D );    // 13.Februar 1996
109         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
110         aDateField.SetFormat( SVXDATEFORMAT_E );    // Die, 13.Februar 1996
111         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
112         aDateField.SetFormat( SVXDATEFORMAT_F );    // Dienstag, 13.Februar 1996
113         InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
114 
115         CheckItem( (sal_uInt16) ( pDateField->GetFormat() ) + 1 ); // - 2 + 3 !
116     }
117     else if( pField->ISA( SvxExtTimeField ) )
118     {
119         const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
120         SvxExtTimeField aTimeField( *pTimeField );
121 
122         if( pTimeField->GetType() == SVXTIMETYPE_FIX )
123             CheckItem( 1 );
124         else
125             CheckItem( 2 );
126 
127         //SVXTIMEFORMAT_APPDEFAULT,     // Wird nicht benutzt
128         //SVXTIMEFORMAT_SYSTEM,         // Wird nicht benutzt
129         InsertItem( nID++, String( SdResId( STR_STANDARD_NORMAL ) ), nStyle );
130 
131         SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
132         aTimeField.SetFormat( SVXTIMEFORMAT_24_HM );    // 13:49
133         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
134         aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS );   // 13:49:38
135         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
136         aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH );  // 13:49:38.78
137         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
138 
139         aTimeField.SetFormat( SVXTIMEFORMAT_12_HM );    // 01:49
140         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
141         aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS );   // 01:49:38
142         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
143         aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH );  // 01:49:38.78
144         InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
145         //SVXTIMEFORMAT_AM_HM,  // 01:49 PM
146         //SVXTIMEFORMAT_AM_HMS, // 01:49:38 PM
147         //SVXTIMEFORMAT_AM_HMSH // 01:49:38.78 PM
148 
149         CheckItem( (sal_uInt16) ( pTimeField->GetFormat() ) + 1 ); // - 2 + 3 !
150     }
151     else if( pField->ISA( SvxExtFileField ) )
152     {
153         const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
154         //SvxExtFileField aFileField( *pFileField );
155 
156         if( pFileField->GetType() == SVXFILETYPE_FIX )
157             CheckItem( 1 );
158         else
159             CheckItem( 2 );
160 
161         InsertItem( nID++, String( SdResId( STR_FILEFORMAT_NAME_EXT ) ), nStyle );
162         InsertItem( nID++, String( SdResId( STR_FILEFORMAT_FULLPATH ) ), nStyle );
163         InsertItem( nID++, String( SdResId( STR_FILEFORMAT_PATH ) ), nStyle );
164         InsertItem( nID++, String( SdResId( STR_FILEFORMAT_NAME ) ), nStyle );
165 
166         CheckItem( (sal_uInt16) ( pFileField->GetFormat() ) + 3 );
167     }
168     else if( pField->ISA( SvxAuthorField ) )
169     {
170         const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
171         SvxAuthorField aAuthorField( *pAuthorField );
172 
173         if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX )
174             CheckItem( 1 );
175         else
176             CheckItem( 2 );
177 
178         for( sal_uInt16 i = 0; i < 4; i++ )
179         {
180             aAuthorField.SetFormat( (SvxAuthorFormat) i );
181             InsertItem( nID++, aAuthorField.GetFormatted(), nStyle );
182         }
183         CheckItem( (sal_uInt16) ( pAuthorField->GetFormat() ) + 3 );
184     }
185 }
186 
187 /*************************************************************************
188 |*
189 |* Gibt das neue Feld zurueck, gehoert dem Caller.
190 |* Liefert NULL, wenn sich nichts geaendert hat.
191 |*
192 \************************************************************************/
193 
194 SvxFieldData* SdFieldPopup::GetField()
195 {
196     SvxFieldData* pNewField = NULL;
197     sal_uInt16 nCount = GetItemCount();
198 
199     if( pField->ISA( SvxDateField ) )
200     {
201         const SvxDateField* pDateField = (const SvxDateField*) pField;
202         SvxDateType   eType;
203         SvxDateFormat eFormat;
204         sal_uInt16 i;
205 
206         if( IsItemChecked( 1 ) )
207             eType = SVXDATETYPE_FIX;
208         else
209             eType = SVXDATETYPE_VAR;
210 
211         for( i = 3; i <= nCount; i++ )
212         {
213             if( IsItemChecked( i ) )
214                 break;
215         }
216         eFormat = (SvxDateFormat) ( i - 1 );
217 
218         if( pDateField->GetFormat() != eFormat ||
219             pDateField->GetType() != eType )
220         {
221             pNewField = new SvxDateField( *pDateField );
222             ( (SvxDateField*) pNewField )->SetType( eType );
223             ( (SvxDateField*) pNewField )->SetFormat( eFormat );
224 
225             if( (pDateField->GetType() == SVXDATETYPE_VAR) && (eType == SVXDATETYPE_FIX) )
226             {
227                 Date aDate;
228                 ( (SvxDateField*) pNewField )->SetFixDate( aDate );
229             }
230         }
231     }
232     else if( pField->ISA( SvxExtTimeField ) )
233     {
234         const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
235         SvxTimeType   eType;
236         SvxTimeFormat eFormat;
237         sal_uInt16 i;
238 
239         if( IsItemChecked( 1 ) )
240             eType = SVXTIMETYPE_FIX;
241         else
242             eType = SVXTIMETYPE_VAR;
243 
244         for( i = 3; i <= nCount; i++ )
245         {
246             if( IsItemChecked( i ) )
247                 break;
248         }
249         eFormat = (SvxTimeFormat) ( i - 1 );
250 
251         if( pTimeField->GetFormat() != eFormat ||
252             pTimeField->GetType() != eType )
253         {
254             pNewField = new SvxExtTimeField( *pTimeField );
255             ( (SvxExtTimeField*) pNewField )->SetType( eType );
256             ( (SvxExtTimeField*) pNewField )->SetFormat( eFormat );
257 
258             if( (pTimeField->GetType() == SVXTIMETYPE_VAR) && (eType == SVXTIMETYPE_FIX) )
259             {
260                 Time aTime;
261                 ( (SvxExtTimeField*) pNewField )->SetFixTime( aTime );
262             }
263 
264         }
265     }
266     else if( pField->ISA( SvxExtFileField ) )
267     {
268         const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
269         SvxFileType   eType;
270         SvxFileFormat eFormat;
271         sal_uInt16 i;
272 
273         if( IsItemChecked( 1 ) )
274             eType = SVXFILETYPE_FIX;
275         else
276             eType = SVXFILETYPE_VAR;
277 
278         for( i = 3; i <= nCount; i++ )
279         {
280             if( IsItemChecked( i ) )
281                 break;
282         }
283         eFormat = (SvxFileFormat) ( i - 3 );
284 
285         if( pFileField->GetFormat() != eFormat ||
286             pFileField->GetType() != eType )
287         {
288             ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell,
289                 SfxObjectShell::Current() );
290 
291             if( pDocSh )
292             {
293                 SvxExtFileField aFileField( *pFileField );
294 
295                 String aName;
296                 if( pDocSh->HasName() )
297                     aName = pDocSh->GetMedium()->GetName();
298 
299                 // #91225# Get current filename, not the one stored in the old field
300                 pNewField = new SvxExtFileField( aName );
301                 ( (SvxExtFileField*) pNewField )->SetType( eType );
302                 ( (SvxExtFileField*) pNewField )->SetFormat( eFormat );
303             }
304         }
305     }
306     else if( pField->ISA( SvxAuthorField ) )
307     {
308         const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
309         SvxAuthorType   eType;
310         SvxAuthorFormat eFormat;
311         sal_uInt16 i;
312 
313         if( IsItemChecked( 1 ) )
314             eType = SVXAUTHORTYPE_FIX;
315         else
316             eType = SVXAUTHORTYPE_VAR;
317 
318         for( i = 3; i <= nCount; i++ )
319         {
320             if( IsItemChecked( i ) )
321                 break;
322         }
323         eFormat = (SvxAuthorFormat) ( i - 3 );
324 
325         if( pAuthorField->GetFormat() != eFormat ||
326             pAuthorField->GetType() != eType )
327         {
328             // #91225# Get current state of address, not the old one
329             SvtUserOptions aUserOptions;
330             pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
331             ( (SvxAuthorField*) pNewField )->SetType( eType );
332             ( (SvxAuthorField*) pNewField )->SetFormat( eFormat );
333         }
334     }
335     return( pNewField );
336 }
337 
338 
339