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