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