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