xref: /trunk/main/sw/source/ui/fldui/flddinf.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sfx2/request.hxx>
32cdf0e10cSrcweir #include <sfx2/frame.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <svl/zforlist.hxx>
35cdf0e10cSrcweir #include <svl/zformat.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <helpid.h>
38cdf0e10cSrcweir #include <swtypes.hxx>
39cdf0e10cSrcweir #include <globals.hrc>
40cdf0e10cSrcweir #include <fldbas.hxx>
41cdf0e10cSrcweir #include <docufld.hxx>
42cdf0e10cSrcweir #include <wrtsh.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <fldui.hrc>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #ifndef _FLDTDLG_HRC
47cdf0e10cSrcweir #include <fldtdlg.hrc>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #ifndef _FLDDINF_HXX
50cdf0e10cSrcweir #include <flddinf.hxx>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #include <swmodule.hxx>
53cdf0e10cSrcweir #ifndef _VIEW_HXX
54cdf0e10cSrcweir #include <view.hxx>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
57cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
58cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
59cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #define USER_DATA_VERSION_1 "1"
62cdf0e10cSrcweir #define USER_DATA_VERSION USER_DATA_VERSION_1
63cdf0e10cSrcweir 
64cdf0e10cSrcweir using namespace nsSwDocInfoSubType;
65cdf0e10cSrcweir using namespace com::sun::star;
66cdf0e10cSrcweir /*--------------------------------------------------------------------
67cdf0e10cSrcweir 	Beschreibung:
68cdf0e10cSrcweir  --------------------------------------------------------------------*/
69cdf0e10cSrcweir 
SwFldDokInfPage(Window * pWindow,const SfxItemSet & rCoreSet)70cdf0e10cSrcweir SwFldDokInfPage::SwFldDokInfPage(Window* pWindow, const SfxItemSet& rCoreSet ) :
71cdf0e10cSrcweir 	SwFldPage( pWindow, SW_RES( TP_FLD_DOKINF ), rCoreSet ),
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	aTypeFT		(this, SW_RES(FT_DOKINFTYPE)),
74cdf0e10cSrcweir 	aTypeTLB	(this, SW_RES(TLB_DOKINFTYPE)),
75cdf0e10cSrcweir 	aSelectionFT(this, SW_RES(FT_DOKINFSELECTION)),
76cdf0e10cSrcweir 	aSelectionLB(this, SW_RES(LB_DOKINFSELECTION)),
77cdf0e10cSrcweir 	aFormatFT	(this, SW_RES(FT_DOKINFFORMAT)),
78cdf0e10cSrcweir 	aFormatLB	(this, SW_RES(LB_DOKINFFORMAT)),
79cdf0e10cSrcweir 	aFixedCB	(this, SW_RES(CB_DOKINFFIXEDCONTENT)),
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     pSelEntry   (0),
82cdf0e10cSrcweir     aInfoStr    (SW_RES(STR_DOKINF_INFO))
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	FreeResource();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	aTypeTLB.SetHelpId(HID_FIELD_DINF_TYPE);
87cdf0e10cSrcweir 	aTypeTLB.SetSelectionMode(SINGLE_SELECTION);
88cdf0e10cSrcweir 	aTypeTLB.SetStyle(aTypeTLB.GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_SORT|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
89cdf0e10cSrcweir 	// Font nicht setzen, damit der Font des Controls uebernommen wird!
90cdf0e10cSrcweir 	// Sonst bei falschem Font Bug an OV.
91cdf0e10cSrcweir 	aTypeTLB.SetSpaceBetweenEntries(0);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	aTypeTLB.SetNodeDefaultImages();
94cdf0e10cSrcweir     //enable 'active' language selection
95cdf0e10cSrcweir     aFormatLB.SetShowLanguageControl(sal_True);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	SFX_ITEMSET_ARG( &rCoreSet, pItem, SfxUnoAnyItem, SID_DOCINFO, sal_False );
98cdf0e10cSrcweir 	if ( pItem )
99cdf0e10cSrcweir         pItem->GetValue() >>= xCustomPropertySet;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir /*--------------------------------------------------------------------
103cdf0e10cSrcweir 	Beschreibung:
104cdf0e10cSrcweir  --------------------------------------------------------------------*/
105cdf0e10cSrcweir 
~SwFldDokInfPage()106cdf0e10cSrcweir __EXPORT SwFldDokInfPage::~SwFldDokInfPage()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir /*--------------------------------------------------------------------
111cdf0e10cSrcweir 	Beschreibung:
112cdf0e10cSrcweir  --------------------------------------------------------------------*/
113cdf0e10cSrcweir 
Reset(const SfxItemSet &)114cdf0e10cSrcweir void __EXPORT SwFldDokInfPage::Reset(const SfxItemSet& )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	Init();	// Allgemeine initialisierung
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	// TypeListBox initialisieren
119cdf0e10cSrcweir 	aTypeTLB.SetUpdateMode(sal_False);
120cdf0e10cSrcweir 	aTypeTLB.Clear();
121cdf0e10cSrcweir 	pSelEntry = 0;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	// SubTypes in der TypeLB anzeigen
124cdf0e10cSrcweir 	sal_uInt16 nTypeId = TYP_DOCINFOFLD;
125cdf0e10cSrcweir 	SvLBoxEntry* pEntry = 0;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	SvLBoxEntry* pInfo = 0;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	sal_uInt16 nSubType = USHRT_MAX;
130cdf0e10cSrcweir 	if (IsFldEdit())
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         const SwField* pCurField = GetCurField();
133cdf0e10cSrcweir         nSubType = ((SwDocInfoField*)pCurField)->GetSubType() & 0xff;
134cdf0e10cSrcweir         if( nSubType == DI_CUSTOM )
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             m_sOldCustomFieldName = static_cast<const SwDocInfoField*>(pCurField)->GetName();
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir         aFormatLB.SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
139cdf0e10cSrcweir         SwWrtShell *pSh = GetWrtShell();
140cdf0e10cSrcweir         if(pSh)
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
143cdf0e10cSrcweir             if(pFormat)
144cdf0e10cSrcweir                 aFormatLB.SetLanguage(pFormat->GetLanguage());
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	sal_uInt16 nSelEntryData = USHRT_MAX;
149cdf0e10cSrcweir 	String sUserData = GetUserData();
150cdf0e10cSrcweir 	if(sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		String sVal = sUserData.GetToken(1, ';');
153cdf0e10cSrcweir         nSelEntryData = static_cast< sal_uInt16 >(sVal.ToInt32());
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     SvStringsDtor aLst;
157cdf0e10cSrcweir     GetFldMgr().GetSubTypes(nTypeId, aLst);
158cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < aLst.Count(); ++i)
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		if (!IsFldEdit() || nSubType == i)
161cdf0e10cSrcweir 		{
162cdf0e10cSrcweir 			if (DI_CUSTOM == i)
163cdf0e10cSrcweir 			{
164cdf0e10cSrcweir                 if(xCustomPropertySet.is() )
165cdf0e10cSrcweir 				{
166cdf0e10cSrcweir                     uno::Reference< beans::XPropertySetInfo > xSetInfo = xCustomPropertySet->getPropertySetInfo();
167cdf0e10cSrcweir                     const uno::Sequence< beans::Property > rProperties = xSetInfo->getProperties();
168cdf0e10cSrcweir //                    uno::Sequence< ::rtl::OUString > aPropertyNames(rProperties.getLength());
169cdf0e10cSrcweir //                    for (sal_Int32 i = 0; i < rProperties.getLength(); ++i) {
170cdf0e10cSrcweir //                        aPropertyNames[i] = rProperties[i].Name;
171cdf0e10cSrcweir //                    }
172cdf0e10cSrcweir                     //if ( !IsFldEdit() )
173cdf0e10cSrcweir                     if( rProperties.getLength() )
174cdf0e10cSrcweir                     {
175cdf0e10cSrcweir                         pInfo = aTypeTLB.InsertEntry( String(SW_RES( STR_CUSTOM )) );
176cdf0e10cSrcweir 						pInfo->SetUserData(reinterpret_cast<void*>(USHRT_MAX));
177cdf0e10cSrcweir 
178cdf0e10cSrcweir                         for (sal_Int32 n=0; n < rProperties.getLength(); n++)
179cdf0e10cSrcweir                         {
180cdf0e10cSrcweir                             rtl::OUString sEntry = rProperties[n].Name;
181cdf0e10cSrcweir                             pEntry = aTypeTLB.InsertEntry(sEntry, pInfo);
182cdf0e10cSrcweir                             if(m_sOldCustomFieldName.equals( sEntry ))
183cdf0e10cSrcweir                             {
184cdf0e10cSrcweir                                 pSelEntry = pEntry;
185cdf0e10cSrcweir                                 aTypeTLB.Expand( pInfo );
186cdf0e10cSrcweir                             }
187cdf0e10cSrcweir                             pEntry->SetUserData(reinterpret_cast<void*>(i));
188cdf0e10cSrcweir                         }
189cdf0e10cSrcweir                     }
190cdf0e10cSrcweir 				}
191cdf0e10cSrcweir 			}
192cdf0e10cSrcweir 			else
193cdf0e10cSrcweir 			{
194cdf0e10cSrcweir 				if (!(IsFldDlgHtmlMode() && (i == DI_EDIT || i == DI_THEMA || i == DI_PRINT)))
195cdf0e10cSrcweir 				{
196cdf0e10cSrcweir                     pEntry = aTypeTLB.InsertEntry(*aLst[i]);
197cdf0e10cSrcweir                     pEntry->SetUserData(reinterpret_cast<void*>(i));
198cdf0e10cSrcweir 				}
199cdf0e10cSrcweir 			}
200cdf0e10cSrcweir 			if(nSelEntryData == i)
201cdf0e10cSrcweir 				pSelEntry = pEntry;
202cdf0e10cSrcweir 		}
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	// alte Pos selektieren
206cdf0e10cSrcweir 	if (pSelEntry != 0)
207cdf0e10cSrcweir 	{
208cdf0e10cSrcweir 		aTypeTLB.Select(pSelEntry);
209cdf0e10cSrcweir 		nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
210cdf0e10cSrcweir 	}
211cdf0e10cSrcweir     else if ( aTypeTLB.GetEntry(0) )
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir 		pSelEntry = aTypeTLB.GetEntry(0);
214cdf0e10cSrcweir 		nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	FillSelectionLB(nSubType);
218cdf0e10cSrcweir     if ( pSelEntry )
219cdf0e10cSrcweir         TypeHdl();
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	aTypeTLB.SetUpdateMode(sal_True);
222cdf0e10cSrcweir 	aTypeTLB.SetSelectHdl(LINK(this, SwFldDokInfPage, TypeHdl));
223cdf0e10cSrcweir 	aTypeTLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
224cdf0e10cSrcweir 	aSelectionLB.SetSelectHdl(LINK(this, SwFldDokInfPage, SubTypeHdl));
225cdf0e10cSrcweir 	aSelectionLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
226cdf0e10cSrcweir 	aFormatLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if (IsFldEdit())
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 		nOldSel = aSelectionLB.GetSelectEntryPos();
231cdf0e10cSrcweir 		nOldFormat = GetCurField()->GetFormat();
232cdf0e10cSrcweir 		aFixedCB.SaveValue();
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir /*--------------------------------------------------------------------
237cdf0e10cSrcweir 	Beschreibung:
238cdf0e10cSrcweir  --------------------------------------------------------------------*/
239cdf0e10cSrcweir 
IMPL_LINK(SwFldDokInfPage,TypeHdl,ListBox *,EMPTYARG)240cdf0e10cSrcweir IMPL_LINK( SwFldDokInfPage, TypeHdl, ListBox *, EMPTYARG )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	// Alte ListBoxPos sichern
243cdf0e10cSrcweir 	SvLBoxEntry* pOldEntry = pSelEntry;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	// Aktuelle ListBoxPos
246cdf0e10cSrcweir 	pSelEntry = aTypeTLB.FirstSelected();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 	if(!pSelEntry)
249cdf0e10cSrcweir 	{
250cdf0e10cSrcweir 		pSelEntry = aTypeTLB.GetEntry(0);
251cdf0e10cSrcweir 		aTypeTLB.Select(pSelEntry);
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 	else
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	if (pOldEntry != pSelEntry)
256cdf0e10cSrcweir 		FillSelectionLB((sal_uInt16)(sal_uLong)pSelEntry->GetUserData());
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	SubTypeHdl();
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	return 0;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir /*--------------------------------------------------------------------
264cdf0e10cSrcweir 	Beschreibung:
265cdf0e10cSrcweir  --------------------------------------------------------------------*/
IMPL_LINK(SwFldDokInfPage,SubTypeHdl,ListBox *,EMPTYARG)266cdf0e10cSrcweir IMPL_LINK( SwFldDokInfPage, SubTypeHdl, ListBox *, EMPTYARG )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
269cdf0e10cSrcweir 	sal_uInt16 nPos = aSelectionLB.GetSelectEntryPos();
270cdf0e10cSrcweir 	sal_uInt16 nExtSubType;
271cdf0e10cSrcweir 	sal_uInt16 nNewType = 0;
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	if (nSubType != DI_EDIT)
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		if (nPos == LISTBOX_ENTRY_NOTFOUND)
276cdf0e10cSrcweir 		{
277cdf0e10cSrcweir 			if (!aSelectionLB.GetEntryCount())
278cdf0e10cSrcweir 			{
279cdf0e10cSrcweir 				aFormatLB.Clear();
280cdf0e10cSrcweir 				aFormatLB.Enable(sal_False);
281cdf0e10cSrcweir 				aFormatFT.Enable(sal_False);
282cdf0e10cSrcweir                 if( nSubType == DI_CUSTOM )
283cdf0e10cSrcweir                 {
284cdf0e10cSrcweir                     //find out which type the custom field has - for a start set to DATE format
285cdf0e10cSrcweir                     ::rtl::OUString sName = aTypeTLB.GetEntryText(pSelEntry);
286cdf0e10cSrcweir                     try
287cdf0e10cSrcweir                     {
288cdf0e10cSrcweir                         uno::Any aVal = xCustomPropertySet->getPropertyValue( sName );
289cdf0e10cSrcweir                         const uno::Type& rValueType = aVal.getValueType();
290cdf0e10cSrcweir                         if( rValueType == ::getCppuType( (util::DateTime*)0 ))
291cdf0e10cSrcweir                         {
292cdf0e10cSrcweir                             nNewType = NUMBERFORMAT_DATETIME;
293cdf0e10cSrcweir                         }
294cdf0e10cSrcweir                         else if( rValueType == ::getCppuType( (util::Date*)0 ))
295cdf0e10cSrcweir                         {
296cdf0e10cSrcweir                             nNewType = NUMBERFORMAT_DATE;
297cdf0e10cSrcweir                         }
298cdf0e10cSrcweir                         else if( rValueType == ::getCppuType( (util::Time*)0 ))
299cdf0e10cSrcweir                         {
300cdf0e10cSrcweir                             nNewType = NUMBERFORMAT_TIME;
301cdf0e10cSrcweir                         }
302cdf0e10cSrcweir                     }
303cdf0e10cSrcweir                     catch( const uno::Exception& )
304cdf0e10cSrcweir                     {
305cdf0e10cSrcweir                     }
306cdf0e10cSrcweir                 }
307cdf0e10cSrcweir                 else
308cdf0e10cSrcweir                     return 0;
309cdf0e10cSrcweir 			}
310cdf0e10cSrcweir 			nPos = 0;
311cdf0e10cSrcweir 		}
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 		nExtSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
314cdf0e10cSrcweir 	}
315cdf0e10cSrcweir 	else
316cdf0e10cSrcweir 		nExtSubType = DI_SUB_TIME;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	sal_uInt16 nOldType = 0;
319cdf0e10cSrcweir 	sal_Bool bEnable = sal_False;
320cdf0e10cSrcweir 	sal_Bool bOneArea = sal_False;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	if (aFormatLB.IsEnabled())
323cdf0e10cSrcweir 		nOldType = aFormatLB.GetFormatType();
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	switch (nExtSubType)
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		case DI_SUB_AUTHOR:
328cdf0e10cSrcweir 			break;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 		case DI_SUB_DATE:
331cdf0e10cSrcweir 			nNewType = NUMBERFORMAT_DATE;
332cdf0e10cSrcweir 			bOneArea = sal_True;
333cdf0e10cSrcweir 			break;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 		case DI_SUB_TIME:
336cdf0e10cSrcweir 			nNewType = NUMBERFORMAT_TIME;
337cdf0e10cSrcweir 			bOneArea = sal_True;
338cdf0e10cSrcweir 			break;
339cdf0e10cSrcweir 	}
340cdf0e10cSrcweir 	if (!nNewType)
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		aFormatLB.Clear();
343cdf0e10cSrcweir 	}
344cdf0e10cSrcweir 	else
345cdf0e10cSrcweir 	{
346cdf0e10cSrcweir 		if (nOldType != nNewType)
347cdf0e10cSrcweir 		{
348cdf0e10cSrcweir 			aFormatLB.SetFormatType(nNewType);
349cdf0e10cSrcweir 			aFormatLB.SetOneArea(bOneArea);
350cdf0e10cSrcweir 		}
351cdf0e10cSrcweir 		bEnable = sal_True;
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	sal_uLong nFormat = IsFldEdit() ? ((SwDocInfoField*)GetCurField())->GetFormat() : 0;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	sal_uInt16 nOldSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	if (IsFldEdit())
359cdf0e10cSrcweir 	{
360cdf0e10cSrcweir         nPos = aSelectionLB.GetSelectEntryPos();
361cdf0e10cSrcweir 		if (nPos != LISTBOX_ENTRY_NOTFOUND )
362cdf0e10cSrcweir 		{
363cdf0e10cSrcweir 			nSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 			nOldSubType &= ~DI_SUB_FIXED;
366cdf0e10cSrcweir 			if (nOldSubType == nSubType)
367cdf0e10cSrcweir 			{
368cdf0e10cSrcweir 				if (!nFormat && (nNewType == NUMBERFORMAT_DATE || nNewType == NUMBERFORMAT_TIME))
369cdf0e10cSrcweir 				{
370cdf0e10cSrcweir                     SwWrtShell *pSh = GetWrtShell();
371cdf0e10cSrcweir                     if(pSh)
372cdf0e10cSrcweir                     {
373cdf0e10cSrcweir                         SvNumberFormatter* pFormatter = pSh->GetNumberFormatter();
374cdf0e10cSrcweir                         LanguageType eLang = aFormatLB.GetCurLanguage();
375cdf0e10cSrcweir                         if (nNewType == NUMBERFORMAT_DATE)
376cdf0e10cSrcweir                             nFormat = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang);
377cdf0e10cSrcweir                         else if (nNewType == NUMBERFORMAT_TIME)
378cdf0e10cSrcweir                             nFormat = pFormatter->GetFormatIndex( NF_TIME_HHMM, eLang);
379cdf0e10cSrcweir                     }
380cdf0e10cSrcweir 				}
381cdf0e10cSrcweir 				aFormatLB.SetDefFormat(nFormat);
382cdf0e10cSrcweir 			}
383cdf0e10cSrcweir 		}
384cdf0e10cSrcweir         else if( (nSubType == DI_CUSTOM)  && (nNewType != 0) )
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir     		aFormatLB.SetDefFormat(nFormat);
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	aFormatLB.Enable(bEnable);
391cdf0e10cSrcweir 	aFormatFT.Enable(bEnable);
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 	if (bEnable && aFormatLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND)
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir 		aFormatLB.SelectEntryPos(0);
396cdf0e10cSrcweir 	}
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	return 0;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir /*--------------------------------------------------------------------
402cdf0e10cSrcweir 	Beschreibung:
403cdf0e10cSrcweir  --------------------------------------------------------------------*/
404cdf0e10cSrcweir 
FillSelectionLB(sal_uInt16 nSubType)405cdf0e10cSrcweir sal_uInt16 SwFldDokInfPage::FillSelectionLB(sal_uInt16 nSubType)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	// Format-Listbox fuellen
408cdf0e10cSrcweir 	sal_uInt16 nTypeId = TYP_DOCINFOFLD;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	EnableInsert(nSubType != USHRT_MAX);
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 	if (nSubType == USHRT_MAX)	// Info-Text
413cdf0e10cSrcweir 		nSubType = DI_SUBTYPE_BEGIN;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	aSelectionLB.Clear();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 	sal_uInt16 nSize = 0;
418cdf0e10cSrcweir 	sal_uInt16 nSelPos = USHRT_MAX;
419cdf0e10cSrcweir 	sal_uInt16 nExtSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	if (IsFldEdit())
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		aFixedCB.Check((nExtSubType & DI_SUB_FIXED) != 0);
424cdf0e10cSrcweir 		nExtSubType = ((nExtSubType & ~DI_SUB_FIXED) >> 8) - 1;
425cdf0e10cSrcweir 	}
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 	if (nSubType < DI_CREATE || nSubType == DI_DOCNO || nSubType == DI_EDIT|| nSubType == DI_CUSTOM )
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir 		// Format Box ist fuer Title und Time leer
430cdf0e10cSrcweir 	}
431cdf0e10cSrcweir 	else
432cdf0e10cSrcweir 	{
433cdf0e10cSrcweir 		nSize = GetFldMgr().GetFormatCount(nTypeId, sal_False, IsFldDlgHtmlMode());
434cdf0e10cSrcweir 		for (sal_uInt16 i = 0; i < nSize; i++)
435cdf0e10cSrcweir 		{
436cdf0e10cSrcweir 			sal_uInt16 nPos = aSelectionLB.InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
437cdf0e10cSrcweir             aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId(nTypeId, i)));
438cdf0e10cSrcweir 			if (IsFldEdit() && i == nExtSubType)
439cdf0e10cSrcweir 				nSelPos = nPos;
440cdf0e10cSrcweir 		}
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	sal_Bool bEnable = nSize != 0;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 	if (nSize)
446cdf0e10cSrcweir 	{
447cdf0e10cSrcweir 		if (!aSelectionLB.GetSelectEntryCount())
448cdf0e10cSrcweir 			aSelectionLB.SelectEntryPos(nSelPos == USHRT_MAX ? 0 : nSelPos);
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 		bEnable = sal_True;
451cdf0e10cSrcweir 	}
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 	aSelectionFT.Enable(bEnable);
454cdf0e10cSrcweir 	aSelectionLB.Enable(bEnable);
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 	return nSize;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir /*--------------------------------------------------------------------
460cdf0e10cSrcweir 	Beschreibung:
461cdf0e10cSrcweir  --------------------------------------------------------------------*/
462cdf0e10cSrcweir 
FillItemSet(SfxItemSet &)463cdf0e10cSrcweir sal_Bool __EXPORT SwFldDokInfPage::FillItemSet(SfxItemSet& )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir 	if (!pSelEntry || (sal_uInt16)(sal_uLong)pSelEntry->GetUserData() == USHRT_MAX)
466cdf0e10cSrcweir 		return sal_False;
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	sal_uInt16 nTypeId = TYP_DOCINFOFLD;
469cdf0e10cSrcweir 	sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	sal_uLong nFormat = 0;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 	sal_uInt16 nPos = aSelectionLB.GetSelectEntryPos();
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     ::rtl::OUString aName;
476cdf0e10cSrcweir     if (DI_CUSTOM == nSubType)
477cdf0e10cSrcweir         aName = aTypeTLB.GetEntryText(pSelEntry);
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	if (nPos != LISTBOX_ENTRY_NOTFOUND)
480cdf0e10cSrcweir 		nSubType |= (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	if (aFixedCB.IsChecked())
483cdf0e10cSrcweir 		nSubType |= DI_SUB_FIXED;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	nPos = aFormatLB.GetSelectEntryPos();
486cdf0e10cSrcweir 	if(nPos != LISTBOX_ENTRY_NOTFOUND)
487cdf0e10cSrcweir 		nFormat = aFormatLB.GetFormat();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	if (!IsFldEdit() || nOldSel != aSelectionLB.GetSelectEntryPos() ||
490cdf0e10cSrcweir 		nOldFormat != nFormat || aFixedCB.GetState() != aFixedCB.GetSavedValue()
491cdf0e10cSrcweir         || (DI_CUSTOM == nSubType && !aName.equals( m_sOldCustomFieldName )))
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir         InsertFld(nTypeId, nSubType, aName, aEmptyStr, nFormat,
494cdf0e10cSrcweir                 ' ', aFormatLB.IsAutomaticLanguage());
495cdf0e10cSrcweir 	}
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 	return sal_False;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir /*--------------------------------------------------------------------
501cdf0e10cSrcweir 	Beschreibung:
502cdf0e10cSrcweir  --------------------------------------------------------------------*/
503cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rAttrSet)504cdf0e10cSrcweir SfxTabPage* __EXPORT SwFldDokInfPage::Create( 	Window* pParent,
505cdf0e10cSrcweir 						const SfxItemSet& rAttrSet )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir 	return ( new SwFldDokInfPage( pParent, rAttrSet ) );
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir /*--------------------------------------------------------------------
511cdf0e10cSrcweir 	Beschreibung:
512cdf0e10cSrcweir  --------------------------------------------------------------------*/
513cdf0e10cSrcweir 
GetGroup()514cdf0e10cSrcweir sal_uInt16 SwFldDokInfPage::GetGroup()
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	return GRP_REG;
517cdf0e10cSrcweir }
518cdf0e10cSrcweir /* -----------------12.01.99 11:21-------------------
519cdf0e10cSrcweir  *
520cdf0e10cSrcweir  * --------------------------------------------------*/
FillUserData()521cdf0e10cSrcweir void	SwFldDokInfPage::FillUserData()
522cdf0e10cSrcweir {
523cdf0e10cSrcweir 	String sData( String::CreateFromAscii(
524cdf0e10cSrcweir 							RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION )));
525cdf0e10cSrcweir 	sData += ';';
526cdf0e10cSrcweir 	SvLBoxEntry* pEntry = aTypeTLB.FirstSelected();
527cdf0e10cSrcweir     sal_uInt16 nTypeSel = pEntry ? sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(pEntry->GetUserData())) : USHRT_MAX;
528cdf0e10cSrcweir 	sData += String::CreateFromInt32( nTypeSel );
529cdf0e10cSrcweir 	SetUserData(sData);
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 
534