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