update dev300-m58
[ooovba.git] / sw / source / ui / fldui / flddinf.cxx
bloba8432eb6b84f60c527c637b5d6eae500bb401a7a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: flddinf.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
38 #include <sfx2/request.hxx>
39 #include <sfx2/frame.hxx>
40 #include <vcl/svapp.hxx>
41 #include <svtools/zforlist.hxx>
43 #ifndef _HELPID_H
44 #include <helpid.h>
45 #endif
46 #include <swtypes.hxx>
47 #ifndef _GLOBALS_HRC
48 #include <globals.hrc>
49 #endif
50 #include <fldbas.hxx>
51 #include <docufld.hxx>
52 #include <wrtsh.hxx>
54 #include <fldui.hrc>
56 #ifndef _FLDTDLG_HRC
57 #include <fldtdlg.hrc>
58 #endif
59 #ifndef _FLDDINF_HXX
60 #include <flddinf.hxx>
61 #endif
62 #include <swmodule.hxx>
63 #ifndef _VIEW_HXX
64 #include <view.hxx>
65 #endif
66 #include <svtools/zformat.hxx>
68 #define USER_DATA_VERSION_1 "1"
69 #define USER_DATA_VERSION USER_DATA_VERSION_1
71 using namespace nsSwDocInfoSubType;
73 /*--------------------------------------------------------------------
74 Beschreibung:
75 --------------------------------------------------------------------*/
77 SwFldDokInfPage::SwFldDokInfPage(Window* pWindow, const SfxItemSet& rCoreSet ) :
78 SwFldPage( pWindow, SW_RES( TP_FLD_DOKINF ), rCoreSet ),
80 aTypeFT (this, SW_RES(FT_DOKINFTYPE)),
81 aTypeTLB (this, SW_RES(TLB_DOKINFTYPE)),
82 aSelectionFT(this, SW_RES(FT_DOKINFSELECTION)),
83 aSelectionLB(this, SW_RES(LB_DOKINFSELECTION)),
84 aFormatFT (this, SW_RES(FT_DOKINFFORMAT)),
85 aFormatLB (this, SW_RES(LB_DOKINFFORMAT)),
86 aFixedCB (this, SW_RES(CB_DOKINFFIXEDCONTENT)),
88 pSelEntry (0),
89 aInfoStr (SW_RES(STR_DOKINF_INFO))
91 FreeResource();
93 aTypeTLB.SetHelpId(HID_FIELD_DINF_TYPE);
94 aTypeTLB.SetSelectionMode(SINGLE_SELECTION);
95 aTypeTLB.SetWindowBits(WB_HASLINES|WB_CLIPCHILDREN|WB_SORT|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
96 // Font nicht setzen, damit der Font des Controls uebernommen wird!
97 // Sonst bei falschem Font Bug an OV.
98 aTypeTLB.SetSpaceBetweenEntries(0);
100 aTypeTLB.SetNodeDefaultImages();
101 //enable 'active' language selection
102 aFormatLB.SetShowLanguageControl(TRUE);
104 SFX_ITEMSET_ARG( &rCoreSet, pItem, SfxUnoAnyItem, SID_DOCINFO, FALSE );
105 if ( pItem )
106 pItem->GetValue() >>= aPropertyNames;
109 /*--------------------------------------------------------------------
110 Beschreibung:
111 --------------------------------------------------------------------*/
113 __EXPORT SwFldDokInfPage::~SwFldDokInfPage()
117 /*--------------------------------------------------------------------
118 Beschreibung:
119 --------------------------------------------------------------------*/
121 void __EXPORT SwFldDokInfPage::Reset(const SfxItemSet& )
123 Init(); // Allgemeine initialisierung
125 // TypeListBox initialisieren
126 aTypeTLB.SetUpdateMode(FALSE);
127 aTypeTLB.Clear();
128 pSelEntry = 0;
130 // SubTypes in der TypeLB anzeigen
131 USHORT nTypeId = TYP_DOCINFOFLD;
132 SvLBoxEntry* pEntry = 0;
134 SvLBoxEntry* pInfo = 0;
136 USHORT nSubType = USHRT_MAX;
137 if (IsFldEdit())
139 const SwField* pCurField = GetCurField();
140 nSubType = ((SwDocInfoField*)pCurField)->GetSubType() & 0xff;
141 if( nSubType == DI_CUSTOM )
143 m_sOldCustomFieldName = static_cast<const SwDocInfoField*>(pCurField)->GetName();
145 aFormatLB.SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
146 SwWrtShell *pSh = GetWrtShell();
147 if(pSh)
149 const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
150 if(pFormat)
151 aFormatLB.SetLanguage(pFormat->GetLanguage());
155 USHORT nSelEntryData = USHRT_MAX;
156 String sUserData = GetUserData();
157 if(sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
159 String sVal = sUserData.GetToken(1, ';');
160 nSelEntryData = static_cast< USHORT >(sVal.ToInt32());
163 SvStringsDtor aLst;
164 GetFldMgr().GetSubTypes(nTypeId, aLst);
165 for (USHORT i = 0; i < aLst.Count(); ++i)
167 if (!IsFldEdit() || nSubType == i)
169 if (DI_CUSTOM == i)
171 if (aPropertyNames.getLength() )
173 //if ( !IsFldEdit() )
175 pInfo = aTypeTLB.InsertEntry( String(SW_RES( STR_CUSTOM )) );
176 pInfo->SetUserData(reinterpret_cast<void*>(USHRT_MAX));
179 for (sal_Int32 n=0; n<aPropertyNames.getLength(); n++)
181 rtl::OUString sEntry = aPropertyNames[n];
182 pEntry = aTypeTLB.InsertEntry(sEntry, pInfo);
183 if(m_sOldCustomFieldName.equals( sEntry ))
185 pSelEntry = pEntry;
186 aTypeTLB.Expand( pInfo );
188 pEntry->SetUserData(reinterpret_cast<void*>(i));
192 else
194 if (!(IsFldDlgHtmlMode() && (i == DI_EDIT || i == DI_THEMA || i == DI_PRINT)))
196 pEntry = aTypeTLB.InsertEntry(*aLst[i]);
197 pEntry->SetUserData(reinterpret_cast<void*>(i));
200 if(nSelEntryData == i)
201 pSelEntry = pEntry;
205 // alte Pos selektieren
206 if (pSelEntry != 0)
208 aTypeTLB.Select(pSelEntry);
209 nSubType = (USHORT)(ULONG)pSelEntry->GetUserData();
211 else if ( aTypeTLB.GetEntry(0) )
213 pSelEntry = aTypeTLB.GetEntry(0);
214 nSubType = (USHORT)(ULONG)pSelEntry->GetUserData();
217 FillSelectionLB(nSubType);
218 if ( pSelEntry )
219 TypeHdl();
221 aTypeTLB.SetUpdateMode(TRUE);
222 aTypeTLB.SetSelectHdl(LINK(this, SwFldDokInfPage, TypeHdl));
223 aTypeTLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
224 aSelectionLB.SetSelectHdl(LINK(this, SwFldDokInfPage, SubTypeHdl));
225 aSelectionLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
226 aFormatLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
228 if (IsFldEdit())
230 nOldSel = aSelectionLB.GetSelectEntryPos();
231 nOldFormat = GetCurField()->GetFormat();
232 aFixedCB.SaveValue();
236 /*--------------------------------------------------------------------
237 Beschreibung:
238 --------------------------------------------------------------------*/
240 IMPL_LINK( SwFldDokInfPage, TypeHdl, ListBox *, EMPTYARG )
242 // Alte ListBoxPos sichern
243 SvLBoxEntry* pOldEntry = pSelEntry;
245 // Aktuelle ListBoxPos
246 pSelEntry = aTypeTLB.FirstSelected();
248 if(!pSelEntry)
250 pSelEntry = aTypeTLB.GetEntry(0);
251 aTypeTLB.Select(pSelEntry);
253 else
255 if (pOldEntry != pSelEntry)
256 FillSelectionLB((USHORT)(ULONG)pSelEntry->GetUserData());
258 SubTypeHdl();
260 return 0;
263 /*--------------------------------------------------------------------
264 Beschreibung:
265 --------------------------------------------------------------------*/
267 IMPL_LINK( SwFldDokInfPage, SubTypeHdl, ListBox *, EMPTYARG )
269 USHORT nSubType = (USHORT)(ULONG)pSelEntry->GetUserData();
270 USHORT nPos = aSelectionLB.GetSelectEntryPos();
271 USHORT nExtSubType;
273 if (nSubType != DI_EDIT)
275 if (nPos == LISTBOX_ENTRY_NOTFOUND)
277 if (!aSelectionLB.GetEntryCount())
279 aFormatLB.Clear();
280 aFormatLB.Enable(FALSE);
281 aFormatFT.Enable(FALSE);
282 return 0;
284 nPos = 0;
287 nExtSubType = (USHORT)(ULONG)aSelectionLB.GetEntryData(nPos);
289 else
290 nExtSubType = DI_SUB_TIME;
292 USHORT nOldType = 0;
293 USHORT nNewType = 0;
294 BOOL bEnable = FALSE;
295 BOOL bOneArea = FALSE;
297 if (aFormatLB.IsEnabled())
298 nOldType = aFormatLB.GetFormatType();
300 switch (nExtSubType)
302 case DI_SUB_AUTHOR:
303 break;
305 case DI_SUB_DATE:
306 nNewType = NUMBERFORMAT_DATE;
307 bOneArea = TRUE;
308 break;
310 case DI_SUB_TIME:
311 nNewType = NUMBERFORMAT_TIME;
312 bOneArea = TRUE;
313 break;
316 if (!nNewType)
318 aFormatLB.Clear();
320 else
322 if (nOldType != nNewType)
324 aFormatLB.SetFormatType(nNewType);
325 aFormatLB.SetOneArea(bOneArea);
327 bEnable = TRUE;
330 ULONG nFormat = IsFldEdit() ? ((SwDocInfoField*)GetCurField())->GetFormat() : 0;
332 USHORT nOldSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
334 if (IsFldEdit())
336 nPos = aSelectionLB.GetSelectEntryPos();
337 if (nPos != LISTBOX_ENTRY_NOTFOUND)
339 nSubType = (USHORT)(ULONG)aSelectionLB.GetEntryData(nPos);
341 nOldSubType &= ~DI_SUB_FIXED;
342 if (nOldSubType == nSubType)
344 if (!nFormat && (nNewType == NUMBERFORMAT_DATE || nNewType == NUMBERFORMAT_TIME))
346 SwWrtShell *pSh = GetWrtShell();
347 if(pSh)
350 SvNumberFormatter* pFormatter = pSh->GetNumberFormatter();
351 LanguageType eLang = aFormatLB.GetCurLanguage();
352 if (nNewType == NUMBERFORMAT_DATE)
353 nFormat = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang);
354 else if (nNewType == NUMBERFORMAT_TIME)
355 nFormat = pFormatter->GetFormatIndex( NF_TIME_HHMM, eLang);
358 aFormatLB.SetDefFormat(nFormat);
363 aFormatLB.Enable(bEnable);
364 aFormatFT.Enable(bEnable);
366 if (bEnable && aFormatLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND)
368 aFormatLB.SelectEntryPos(0);
371 return 0;
374 /*--------------------------------------------------------------------
375 Beschreibung:
376 --------------------------------------------------------------------*/
378 USHORT SwFldDokInfPage::FillSelectionLB(USHORT nSubType)
380 // Format-Listbox fuellen
381 USHORT nTypeId = TYP_DOCINFOFLD;
383 EnableInsert(nSubType != USHRT_MAX);
385 if (nSubType == USHRT_MAX) // Info-Text
386 nSubType = DI_SUBTYPE_BEGIN;
388 aSelectionLB.Clear();
390 USHORT nSize = 0;
391 USHORT nSelPos = USHRT_MAX;
392 USHORT nExtSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
394 if (IsFldEdit())
396 aFixedCB.Check((nExtSubType & DI_SUB_FIXED) != 0);
397 nExtSubType = ((nExtSubType & ~DI_SUB_FIXED) >> 8) - 1;
400 if (nSubType < DI_CREATE || nSubType == DI_DOCNO || nSubType == DI_EDIT|| nSubType == DI_CUSTOM )
402 // Format Box ist fuer Title und Time leer
404 else
406 nSize = GetFldMgr().GetFormatCount(nTypeId, FALSE, IsFldDlgHtmlMode());
407 for (USHORT i = 0; i < nSize; i++)
409 USHORT nPos = aSelectionLB.InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
410 aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId(nTypeId, i)));
411 if (IsFldEdit() && i == nExtSubType)
412 nSelPos = nPos;
416 BOOL bEnable = nSize != 0;
418 if (nSize)
420 if (!aSelectionLB.GetSelectEntryCount())
421 aSelectionLB.SelectEntryPos(nSelPos == USHRT_MAX ? 0 : nSelPos);
423 bEnable = TRUE;
426 aSelectionFT.Enable(bEnable);
427 aSelectionLB.Enable(bEnable);
429 return nSize;
432 /*--------------------------------------------------------------------
433 Beschreibung:
434 --------------------------------------------------------------------*/
436 BOOL __EXPORT SwFldDokInfPage::FillItemSet(SfxItemSet& )
438 if (!pSelEntry || (USHORT)(ULONG)pSelEntry->GetUserData() == USHRT_MAX)
439 return FALSE;
441 USHORT nTypeId = TYP_DOCINFOFLD;
442 USHORT nSubType = (USHORT)(ULONG)pSelEntry->GetUserData();
444 ULONG nFormat = 0;
446 USHORT nPos = aSelectionLB.GetSelectEntryPos();
448 ::rtl::OUString aName;
449 if (DI_CUSTOM == nSubType)
450 aName = aTypeTLB.GetEntryText(pSelEntry);
452 if (nPos != LISTBOX_ENTRY_NOTFOUND)
453 nSubType |= (USHORT)(ULONG)aSelectionLB.GetEntryData(nPos);
455 if (aFixedCB.IsChecked())
456 nSubType |= DI_SUB_FIXED;
458 nPos = aFormatLB.GetSelectEntryPos();
459 if(nPos != LISTBOX_ENTRY_NOTFOUND)
460 nFormat = aFormatLB.GetFormat();
462 if (!IsFldEdit() || nOldSel != aSelectionLB.GetSelectEntryPos() ||
463 nOldFormat != nFormat || aFixedCB.GetState() != aFixedCB.GetSavedValue()
464 || (DI_CUSTOM == nSubType && !aName.equals( m_sOldCustomFieldName )))
466 InsertFld(nTypeId, nSubType, aName, aEmptyStr, nFormat,
467 ' ', aFormatLB.IsAutomaticLanguage());
470 return FALSE;
473 /*--------------------------------------------------------------------
474 Beschreibung:
475 --------------------------------------------------------------------*/
477 SfxTabPage* __EXPORT SwFldDokInfPage::Create( Window* pParent,
478 const SfxItemSet& rAttrSet )
480 return ( new SwFldDokInfPage( pParent, rAttrSet ) );
483 /*--------------------------------------------------------------------
484 Beschreibung:
485 --------------------------------------------------------------------*/
487 USHORT SwFldDokInfPage::GetGroup()
489 return GRP_REG;
491 /* -----------------12.01.99 11:21-------------------
493 * --------------------------------------------------*/
494 void SwFldDokInfPage::FillUserData()
496 String sData( String::CreateFromAscii(
497 RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION )));
498 sData += ';';
499 SvLBoxEntry* pEntry = aTypeTLB.FirstSelected();
500 USHORT nTypeSel = pEntry ? sal::static_int_cast< USHORT >(reinterpret_cast< sal_uIntPtr >(pEntry->GetUserData())) : USHRT_MAX;
501 sData += String::CreateFromInt32( nTypeSel );
502 SetUserData(sData);