1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: flddinf.cxx,v $
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
38 #include <sfx2/request.hxx>
39 #include <sfx2/frame.hxx>
40 #include <vcl/svapp.hxx>
41 #include <svtools/zforlist.hxx>
46 #include <swtypes.hxx>
48 #include <globals.hrc>
51 #include <docufld.hxx>
57 #include <fldtdlg.hrc>
60 #include <flddinf.hxx>
62 #include <swmodule.hxx>
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 /*--------------------------------------------------------------------
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
)),
89 aInfoStr (SW_RES(STR_DOKINF_INFO
))
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
);
106 pItem
->GetValue() >>= aPropertyNames
;
109 /*--------------------------------------------------------------------
111 --------------------------------------------------------------------*/
113 __EXPORT
SwFldDokInfPage::~SwFldDokInfPage()
117 /*--------------------------------------------------------------------
119 --------------------------------------------------------------------*/
121 void __EXPORT
SwFldDokInfPage::Reset(const SfxItemSet
& )
123 Init(); // Allgemeine initialisierung
125 // TypeListBox initialisieren
126 aTypeTLB
.SetUpdateMode(FALSE
);
130 // SubTypes in der TypeLB anzeigen
131 USHORT nTypeId
= TYP_DOCINFOFLD
;
132 SvLBoxEntry
* pEntry
= 0;
134 SvLBoxEntry
* pInfo
= 0;
136 USHORT nSubType
= USHRT_MAX
;
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();
149 const SvNumberformat
* pFormat
= pSh
->GetNumberFormatter()->GetEntry(pCurField
->GetFormat());
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());
164 GetFldMgr().GetSubTypes(nTypeId
, aLst
);
165 for (USHORT i
= 0; i
< aLst
.Count(); ++i
)
167 if (!IsFldEdit() || nSubType
== 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
))
186 aTypeTLB
.Expand( pInfo
);
188 pEntry
->SetUserData(reinterpret_cast<void*>(i
));
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
)
205 // alte Pos selektieren
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
);
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
));
230 nOldSel
= aSelectionLB
.GetSelectEntryPos();
231 nOldFormat
= GetCurField()->GetFormat();
232 aFixedCB
.SaveValue();
236 /*--------------------------------------------------------------------
238 --------------------------------------------------------------------*/
240 IMPL_LINK( SwFldDokInfPage
, TypeHdl
, ListBox
*, EMPTYARG
)
242 // Alte ListBoxPos sichern
243 SvLBoxEntry
* pOldEntry
= pSelEntry
;
245 // Aktuelle ListBoxPos
246 pSelEntry
= aTypeTLB
.FirstSelected();
250 pSelEntry
= aTypeTLB
.GetEntry(0);
251 aTypeTLB
.Select(pSelEntry
);
255 if (pOldEntry
!= pSelEntry
)
256 FillSelectionLB((USHORT
)(ULONG
)pSelEntry
->GetUserData());
263 /*--------------------------------------------------------------------
265 --------------------------------------------------------------------*/
267 IMPL_LINK( SwFldDokInfPage
, SubTypeHdl
, ListBox
*, EMPTYARG
)
269 USHORT nSubType
= (USHORT
)(ULONG
)pSelEntry
->GetUserData();
270 USHORT nPos
= aSelectionLB
.GetSelectEntryPos();
273 if (nSubType
!= DI_EDIT
)
275 if (nPos
== LISTBOX_ENTRY_NOTFOUND
)
277 if (!aSelectionLB
.GetEntryCount())
280 aFormatLB
.Enable(FALSE
);
281 aFormatFT
.Enable(FALSE
);
287 nExtSubType
= (USHORT
)(ULONG
)aSelectionLB
.GetEntryData(nPos
);
290 nExtSubType
= DI_SUB_TIME
;
294 BOOL bEnable
= FALSE
;
295 BOOL bOneArea
= FALSE
;
297 if (aFormatLB
.IsEnabled())
298 nOldType
= aFormatLB
.GetFormatType();
306 nNewType
= NUMBERFORMAT_DATE
;
311 nNewType
= NUMBERFORMAT_TIME
;
322 if (nOldType
!= nNewType
)
324 aFormatLB
.SetFormatType(nNewType
);
325 aFormatLB
.SetOneArea(bOneArea
);
330 ULONG nFormat
= IsFldEdit() ? ((SwDocInfoField
*)GetCurField())->GetFormat() : 0;
332 USHORT nOldSubType
= IsFldEdit() ? (((SwDocInfoField
*)GetCurField())->GetSubType() & 0xff00) : 0;
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();
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);
374 /*--------------------------------------------------------------------
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();
391 USHORT nSelPos
= USHRT_MAX
;
392 USHORT nExtSubType
= IsFldEdit() ? (((SwDocInfoField
*)GetCurField())->GetSubType() & 0xff00) : 0;
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
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
)
416 BOOL bEnable
= nSize
!= 0;
420 if (!aSelectionLB
.GetSelectEntryCount())
421 aSelectionLB
.SelectEntryPos(nSelPos
== USHRT_MAX
? 0 : nSelPos
);
426 aSelectionFT
.Enable(bEnable
);
427 aSelectionLB
.Enable(bEnable
);
432 /*--------------------------------------------------------------------
434 --------------------------------------------------------------------*/
436 BOOL __EXPORT
SwFldDokInfPage::FillItemSet(SfxItemSet
& )
438 if (!pSelEntry
|| (USHORT
)(ULONG
)pSelEntry
->GetUserData() == USHRT_MAX
)
441 USHORT nTypeId
= TYP_DOCINFOFLD
;
442 USHORT nSubType
= (USHORT
)(ULONG
)pSelEntry
->GetUserData();
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());
473 /*--------------------------------------------------------------------
475 --------------------------------------------------------------------*/
477 SfxTabPage
* __EXPORT
SwFldDokInfPage::Create( Window
* pParent
,
478 const SfxItemSet
& rAttrSet
)
480 return ( new SwFldDokInfPage( pParent
, rAttrSet
) );
483 /*--------------------------------------------------------------------
485 --------------------------------------------------------------------*/
487 USHORT
SwFldDokInfPage::GetGroup()
491 /* -----------------12.01.99 11:21-------------------
493 * --------------------------------------------------*/
494 void SwFldDokInfPage::FillUserData()
496 String
sData( String::CreateFromAscii(
497 RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION
)));
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
);