xref: /aoo41x/main/sd/source/ui/dlg/dlgfield.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 #ifdef SD_DLLIMPLEMENTATION
28 #undef SD_DLLIMPLEMENTATION
29 #endif
30 
31 
32 
33 #include <editeng/editeng.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <editeng/flditem.hxx>
36 #include <svl/zforlist.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <svl/itemset.hxx>
40 #include <editeng/langitem.hxx>
41 #include <unotools/useroptions.hxx>
42 
43 #include "strings.hrc"
44 #include "dlgfield.hrc"
45 #include "sdattr.hxx"
46 #include "sdresid.hxx"
47 #include "sdmod.hxx"
48 #include "dlgfield.hxx"
49 #include "drawdoc.hxx"
50 #include "DrawDocShell.hxx"
51 
52 /*************************************************************************
53 |*
54 |* Dialog zum Bearbeiten von Feldbefehlen
55 |*
56 \************************************************************************/
57 
SdModifyFieldDlg(Window * pWindow,const SvxFieldData * pInField,const SfxItemSet & rSet)58 SdModifyFieldDlg::SdModifyFieldDlg( Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet ) :
59 	ModalDialog ( pWindow, SdResId( DLG_FIELD_MODIFY ) ),
60 	aGrpType	( this, SdResId( GRP_TYPE ) ),
61 	aRbtFix		( this, SdResId( RBT_FIX ) ),
62 	aRbtVar		( this, SdResId( RBT_VAR ) ),
63 	maFtLanguage( this, SdResId( FT_LANGUAGE ) ),
64 	maLbLanguage( this, SdResId( LB_LANGUAGE ) ),
65 	aFtFormat	( this, SdResId( FT_FORMAT ) ),
66 	aLbFormat	( this, SdResId( LB_FORMAT ) ),
67 	aBtnOK      ( this, SdResId( BTN_OK ) ),
68 	aBtnCancel  ( this, SdResId( BTN_CANCEL ) ),
69 	aBtnHelp    ( this, SdResId( BTN_HELP ) ),
70 	maInputSet	( rSet ),
71 	pField		( pInField )
72 {
73 	FreeResource();
74 
75 	maLbLanguage.SetLanguageList( LANG_LIST_ALL|LANG_LIST_ONLY_KNOWN, false );
76 	maLbLanguage.SetSelectHdl( LINK( this, SdModifyFieldDlg, LanguageChangeHdl ) );
77 	FillControls();
78 }
79 
80 /*************************************************************************
81 |*
82 |* Gibt das neue Feld zurueck, gehoert dem Caller.
83 |* Liefert NULL, wenn sich nichts geaendert hat.
84 |*
85 \************************************************************************/
86 
GetField()87 SvxFieldData* SdModifyFieldDlg::GetField()
88 {
89 	SvxFieldData* pNewField = NULL;
90 
91 	if( aRbtFix.IsChecked() != aRbtFix.GetSavedValue() ||
92 		aRbtVar.IsChecked() != aRbtVar.GetSavedValue() ||
93 		aLbFormat.GetSelectEntryPos() != aLbFormat.GetSavedValue() )
94 	{
95 		if( pField->ISA( SvxDateField ) )
96 		{
97 			const SvxDateField* pDateField = (const SvxDateField*) pField;
98 			SvxDateType	  eType;
99 			SvxDateFormat eFormat;
100 
101 			if( aRbtFix.IsChecked() )
102 				eType = SVXDATETYPE_FIX;
103 			else
104 				eType = SVXDATETYPE_VAR;
105 
106 			eFormat = (SvxDateFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
107 
108 			pNewField = new SvxDateField( *pDateField );
109 			( (SvxDateField*) pNewField )->SetType( eType );
110 			( (SvxDateField*) pNewField )->SetFormat( eFormat );
111 		}
112 		else if( pField->ISA( SvxExtTimeField ) )
113 		{
114 			const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
115 			SvxTimeType	  eType;
116 			SvxTimeFormat eFormat;
117 
118 			if( aRbtFix.IsChecked() )
119 				eType = SVXTIMETYPE_FIX;
120 			else
121 				eType = SVXTIMETYPE_VAR;
122 
123 			eFormat = (SvxTimeFormat) ( aLbFormat.GetSelectEntryPos() + 2 );
124 
125 			pNewField = new SvxExtTimeField( *pTimeField );
126 			( (SvxExtTimeField*) pNewField )->SetType( eType );
127 			( (SvxExtTimeField*) pNewField )->SetFormat( eFormat );
128 		}
129 		else if( pField->ISA( SvxExtFileField ) )
130 		{
131 			const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
132 			SvxFileType	  eType;
133 			SvxFileFormat eFormat;
134 
135 			if( aRbtFix.IsChecked() )
136 				eType = SVXFILETYPE_FIX;
137 			else
138 				eType = SVXFILETYPE_VAR;
139 
140 			eFormat = (SvxFileFormat) ( aLbFormat.GetSelectEntryPos() );
141 
142 			::sd::DrawDocShell* pDocSh = PTR_CAST( ::sd::DrawDocShell,
143 											   SfxObjectShell::Current() );
144 
145 			if( pDocSh )
146 			{
147 				SvxExtFileField aFileField( *pFileField );
148 
149 				String aName;
150 				if( pDocSh->HasName() )
151 					aName = pDocSh->GetMedium()->GetName();
152 
153 				// #91225# Get current filename, not the one stored in the old field
154 				pNewField = new SvxExtFileField( aName );
155 				( (SvxExtFileField*) pNewField )->SetType( eType );
156 				( (SvxExtFileField*) pNewField )->SetFormat( eFormat );
157 			}
158 		}
159 		else if( pField->ISA( SvxAuthorField ) )
160 		{
161 			SvxAuthorType	eType;
162 			SvxAuthorFormat eFormat;
163 
164 			if( aRbtFix.IsChecked() )
165 				eType = SVXAUTHORTYPE_FIX;
166 			else
167 				eType = SVXAUTHORTYPE_VAR;
168 
169 			eFormat = (SvxAuthorFormat) ( aLbFormat.GetSelectEntryPos() );
170 
171 			// #91225# Get current state of address, not the old one
172             SvtUserOptions aUserOptions;
173             pNewField = new SvxAuthorField( aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() );
174 			( (SvxAuthorField*) pNewField )->SetType( eType );
175 			( (SvxAuthorField*) pNewField )->SetFormat( eFormat );
176 		}
177 	}
178 
179 	return( pNewField );
180 }
181 
182 /*************************************************************************
183 |*
184 |*
185 |*
186 \************************************************************************/
187 
FillFormatList()188 void SdModifyFieldDlg::FillFormatList()
189 {
190 	LanguageType eLangType = maLbLanguage.GetSelectLanguage();
191 
192 	aLbFormat.Clear();
193 
194 	if( pField->ISA( SvxDateField ) )
195 	{
196 		const SvxDateField* pDateField = (const SvxDateField*) pField;
197 		SvxDateField aDateField( *pDateField );
198 
199 		//SVXDATEFORMAT_APPDEFAULT, 	// Wird nicht benutzt
200 		//SVXDATEFORMAT_SYSTEM, 		// Wird nicht benutzt
201 		aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_SMALL ) ) );
202 		aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_BIG ) ) );
203 
204 		SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
205 		aDateField.SetFormat( SVXDATEFORMAT_A );	// 13.02.96
206 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
207 		aDateField.SetFormat( SVXDATEFORMAT_B );	// 13.02.1996
208 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
209 		aDateField.SetFormat( SVXDATEFORMAT_C );	// 13.Feb 1996
210 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
211 		aDateField.SetFormat( SVXDATEFORMAT_D );	// 13.Februar 1996
212 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
213 		aDateField.SetFormat( SVXDATEFORMAT_E );	// Die, 13.Februar 1996
214 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
215 		aDateField.SetFormat( SVXDATEFORMAT_F );	// Dienstag, 13.Februar 1996
216 		aLbFormat.InsertEntry( aDateField.GetFormatted( *pNumberFormatter, eLangType ) );
217 
218 		aLbFormat.SelectEntryPos( (sal_uInt16) ( pDateField->GetFormat() - 2 ) );
219 	}
220 	else if( pField->ISA( SvxExtTimeField ) )
221 	{
222 		const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
223 		SvxExtTimeField aTimeField( *pTimeField );
224 
225 		//SVXTIMEFORMAT_APPDEFAULT, 	// Wird nicht benutzt
226 		//SVXTIMEFORMAT_SYSTEM, 		// Wird nicht benutzt
227 		aLbFormat.InsertEntry( String( SdResId( STR_STANDARD_NORMAL ) ) );
228 
229 		SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
230 		aTimeField.SetFormat( SVXTIMEFORMAT_24_HM );	// 13:49
231 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
232 		aTimeField.SetFormat( SVXTIMEFORMAT_24_HMS );	// 13:49:38
233 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
234 		aTimeField.SetFormat( SVXTIMEFORMAT_24_HMSH );	// 13:49:38.78
235 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
236 		aTimeField.SetFormat( SVXTIMEFORMAT_12_HM );	// 01:49
237 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
238 		aTimeField.SetFormat( SVXTIMEFORMAT_12_HMS );	// 01:49:38
239 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
240 		aTimeField.SetFormat( SVXTIMEFORMAT_12_HMSH );	// 01:49:38.78
241 		aLbFormat.InsertEntry( aTimeField.GetFormatted( *pNumberFormatter, eLangType ) );
242 		//SVXTIMEFORMAT_AM_HM,	// 01:49 PM
243 		//SVXTIMEFORMAT_AM_HMS,	// 01:49:38 PM
244 		//SVXTIMEFORMAT_AM_HMSH	// 01:49:38.78 PM
245 
246 		aLbFormat.SelectEntryPos( (sal_uInt16) ( pTimeField->GetFormat() - 2 ) );
247 	}
248 	else if( pField->ISA( SvxExtFileField ) )
249 	{
250 		const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
251 		SvxExtFileField aFileField( *pFileField );
252 
253 		aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME_EXT ) ) );
254 		aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_FULLPATH ) ) );
255 		aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_PATH ) ) );
256 		aLbFormat.InsertEntry( String( SdResId( STR_FILEFORMAT_NAME ) ) );
257 
258 		aLbFormat.SelectEntryPos( (sal_uInt16) ( pFileField->GetFormat() ) );
259 	}
260 	else if( pField->ISA( SvxAuthorField ) )
261 	{
262 		const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
263 		SvxAuthorField aAuthorField( *pAuthorField );
264 
265 		for( sal_uInt16 i = 0; i < 4; i++ )
266 		{
267 			aAuthorField.SetFormat( (SvxAuthorFormat) i );
268 			aLbFormat.InsertEntry( aAuthorField.GetFormatted() );
269 		}
270 
271 		aLbFormat.SelectEntryPos( (sal_uInt16) ( pAuthorField->GetFormat() ) );
272 
273 	}
274 
275 
276 }
277 
FillControls()278 void SdModifyFieldDlg::FillControls()
279 {
280 	aLbFormat.Clear();
281 
282 	if( pField->ISA( SvxDateField ) )
283 	{
284 		const SvxDateField* pDateField = (const SvxDateField*) pField;
285 		SvxDateField aDateField( *pDateField );
286 
287 		if( pDateField->GetType() == SVXDATETYPE_FIX )
288 			aRbtFix.Check();
289 		else
290 			aRbtVar.Check();
291 	}
292 	else if( pField->ISA( SvxExtTimeField ) )
293 	{
294 		const SvxExtTimeField* pTimeField = (const SvxExtTimeField*) pField;
295 		SvxExtTimeField aTimeField( *pTimeField );
296 
297 		if( pTimeField->GetType() == SVXTIMETYPE_FIX )
298 			aRbtFix.Check();
299 		else
300 			aRbtVar.Check();
301 	}
302 	else if( pField->ISA( SvxExtFileField ) )
303 	{
304 		const SvxExtFileField* pFileField = (const SvxExtFileField*) pField;
305 		SvxExtFileField aFileField( *pFileField );
306 
307 		if( pFileField->GetType() == SVXFILETYPE_FIX )
308 			aRbtFix.Check();
309 		else
310 			aRbtVar.Check();
311 	}
312 	else if( pField->ISA( SvxAuthorField ) )
313 	{
314 		const SvxAuthorField* pAuthorField = (const SvxAuthorField*) pField;
315 		SvxAuthorField aAuthorField( *pAuthorField );
316 
317 		if( pAuthorField->GetType() == SVXAUTHORTYPE_FIX )
318 			aRbtFix.Check();
319 		else
320 			aRbtVar.Check();
321 	}
322 	aRbtFix.SaveValue();
323 	aRbtVar.SaveValue();
324 
325 	const SfxPoolItem* pItem;
326 	if( SFX_ITEM_SET == maInputSet.GetItemState(EE_CHAR_LANGUAGE, sal_True, &pItem ) )
327 		maLbLanguage.SelectLanguage( static_cast<const SvxLanguageItem*>(pItem)->GetLanguage() );
328 
329 	maLbLanguage.SaveValue();
330 
331 	FillFormatList();
332 	aLbFormat.SaveValue();
333 }
334 
335 
IMPL_LINK(SdModifyFieldDlg,LanguageChangeHdl,void *,EMPTYARG)336 IMPL_LINK( SdModifyFieldDlg, LanguageChangeHdl, void *, EMPTYARG )
337 {
338 	FillFormatList();
339 
340 	return 0L;
341 }
342 
GetItemSet()343 SfxItemSet SdModifyFieldDlg::GetItemSet()
344 {
345 	SfxItemSet aOutput( *maInputSet.GetPool(), EE_CHAR_LANGUAGE, EE_CHAR_LANGUAGE_CTL );
346 
347 	if( maLbLanguage.GetSelectEntryPos() != maLbLanguage.GetSavedValue() )
348 	{
349 		LanguageType eLangType = maLbLanguage.GetSelectLanguage();
350 		SvxLanguageItem aItem( eLangType, EE_CHAR_LANGUAGE );
351 		aOutput.Put( aItem );
352 
353 		SvxLanguageItem aItemCJK( eLangType, EE_CHAR_LANGUAGE_CJK );
354 		aOutput.Put( aItemCJK );
355 
356 		SvxLanguageItem aItemCTL( eLangType, EE_CHAR_LANGUAGE_CTL );
357 		aOutput.Put( aItemCTL );
358 	}
359 
360 	return aOutput;
361 }
362 
363