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