1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/lstbox.hxx>
21 #include <svl/stritem.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/htmlmode.hxx>
27 #include <viewopt.hxx>
30 #include <swmodule.hxx>
34 #include <fldtdlg.hxx>
35 #include <fldpage.hxx>
36 #include <docufld.hxx>
38 #include <globals.hrc>
39 #include <sfx2/bindings.hxx>
40 #include <switerator.hxx>
42 using namespace ::com::sun::star
;
44 SwFldPage::SwFldPage( Window
*pParent
, const ResId
&rId
,
45 const SfxItemSet
&rAttrSet
)
46 :SfxTabPage (pParent
, rId
, rAttrSet
),
49 m_nPageId ( static_cast< sal_uInt16
>(rId
.GetId()) ),
50 m_nTypeSel (LISTBOX_ENTRY_NOTFOUND
),
51 m_nSelectionSel (LISTBOX_ENTRY_NOTFOUND
),
54 m_bFldDlgHtmlMode (sal_False
),
55 m_bRefresh (sal_False
),
56 m_bFirstHTMLInit (sal_True
)
61 SwFldPage::~SwFldPage()
65 /*--------------------------------------------------------------------
66 Description: initialise TabPage
67 --------------------------------------------------------------------*/
69 void SwFldPage::Init()
71 SwDocShell
* pDocSh
= (SwDocShell
*)SfxObjectShell::Current();
72 sal_Bool bNewMode
= 0 != (::GetHtmlMode(pDocSh
) & HTMLMODE_ON
);
74 m_bFldEdit
= 0 == GetTabDialog();
76 // newly initialise FieldManager. important for
77 // Dok-Switch (fldtdlg:ReInitTabPage)
78 m_pCurFld
= m_aMgr
.GetCurFld();
80 if( bNewMode
!= m_bFldDlgHtmlMode
)
82 m_bFldDlgHtmlMode
= bNewMode
;
84 // initialise Rangelistbox
85 if( m_bFldDlgHtmlMode
&& m_bFirstHTMLInit
)
87 m_bFirstHTMLInit
= sal_False
;
88 SwWrtShell
*pSh
= m_pWrtShell
;
90 pSh
= ::GetActiveWrtShell();
93 SwDoc
* pDoc
= pSh
->GetDoc();
94 pSh
->InsertFldType( SwSetExpFieldType( pDoc
,
95 OUString("HTML_ON"), 1));
96 pSh
->InsertFldType( SwSetExpFieldType(pDoc
,
97 OUString("HTML_OFF"), 1));
103 /*--------------------------------------------------------------------
104 Description: newly initialise page
105 --------------------------------------------------------------------*/
107 void SwFldPage::ActivatePage()
109 EnableInsert(m_bInsert
);
112 /*--------------------------------------------------------------------
113 Description: complete reset; edit new field
114 --------------------------------------------------------------------*/
116 void SwFldPage::EditNewField( sal_Bool bOnlyActivate
)
120 m_nTypeSel
= LISTBOX_ENTRY_NOTFOUND
;
122 m_nSelectionSel
= LISTBOX_ENTRY_NOTFOUND
;
123 m_bRefresh
= sal_True
;
124 Reset(*(SfxItemSet
*)0);
125 m_bRefresh
= sal_False
;
128 /*--------------------------------------------------------------------
129 Description: insert field
130 --------------------------------------------------------------------*/
132 sal_Bool
SwFldPage::InsertFld(sal_uInt16 nTypeId
, sal_uInt16 nSubType
, const String
& rPar1
,
133 const String
& rPar2
, sal_uLong nFormatId
,
134 sal_Unicode cSeparator
, sal_Bool bIsAutomaticLanguage
)
136 sal_Bool bRet
= sal_False
;
137 SwView
* pView
= GetActiveView();
138 SwWrtShell
*pSh
= m_pWrtShell
? m_pWrtShell
: pView
->GetWrtShellPtr();
140 if (!IsFldEdit()) // insert new field
142 SwInsertFld_Data
aData(nTypeId
, nSubType
, rPar1
, rPar2
, nFormatId
, 0, cSeparator
, bIsAutomaticLanguage
);
143 //#i26566# provide parent for SwWrtShell::StartInputFldDlg
144 aData
.pParent
= &GetTabDialog()->GetOKButton();
145 bRet
= m_aMgr
.InsertFld( aData
);
147 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
148 pView
->GetViewFrame()->GetBindings().GetRecorder();
149 if ( xRecorder
.is() )
151 bool bRecordDB
= TYP_DBFLD
== nTypeId
||
152 TYP_DBSETNUMBERFLD
== nTypeId
||
153 TYP_DBNUMSETFLD
== nTypeId
||
154 TYP_DBNEXTSETFLD
== nTypeId
||
155 TYP_DBNAMEFLD
== nTypeId
;
157 SfxRequest
aReq( pView
->GetViewFrame(),
158 bRecordDB
? FN_INSERT_DBFIELD
: FN_INSERT_FIELD
);
161 aReq
.AppendItem(SfxStringItem
162 (FN_INSERT_DBFIELD
,rPar1
.GetToken(0, DB_DELIM
)));
163 aReq
.AppendItem(SfxStringItem
164 (FN_PARAM_1
,rPar1
.GetToken(1, DB_DELIM
)));
165 aReq
.AppendItem(SfxInt32Item
166 (FN_PARAM_3
,rPar1
.GetToken(1, DB_DELIM
).ToInt32()));
167 aReq
.AppendItem(SfxStringItem
168 (FN_PARAM_2
,rPar1
.GetToken(3, DB_DELIM
)));
172 aReq
.AppendItem(SfxStringItem(FN_INSERT_FIELD
, rPar1
));
173 aReq
.AppendItem(SfxStringItem
174 (FN_PARAM_3
, OUString(cSeparator
)));
175 aReq
.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_SUBTYPE
, nSubType
));
177 aReq
.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_TYPE
, nTypeId
));
178 aReq
.AppendItem(SfxStringItem(FN_PARAM_FIELD_CONTENT
, rPar2
));
179 aReq
.AppendItem(SfxUInt32Item(FN_PARAM_FIELD_FORMAT
, nFormatId
));
186 SwField
*const pTmpFld
= m_pCurFld
->CopyField();
194 nSubType
= static_cast< sal_uInt16
>(((nTypeId
== TYP_DATEFLD
) ? DATEFLD
: TIMEFLD
) |
195 ((nSubType
== DATE_VAR
) ? 0 : FIXEDFLD
));
199 case TYP_DBNEXTSETFLD
:
200 case TYP_DBNUMSETFLD
:
201 case TYP_DBSETNUMBERFLD
:
206 aData
.sDataSource
= rPar1
.GetToken(0, DB_DELIM
, nPos
);
207 aData
.sCommand
= rPar1
.GetToken(0, DB_DELIM
, nPos
);
208 aData
.nCommandType
= rPar1
.GetToken(0, DB_DELIM
, nPos
).ToInt32();
209 sPar1
= rPar1
.Copy(nPos
);
211 ((SwDBNameInfField
*)pTmpFld
)->SetDBData(aData
);
218 aData
.sDataSource
= rPar1
.GetToken(0, DB_DELIM
);
219 aData
.sCommand
= rPar1
.GetToken(1, DB_DELIM
);
220 aData
.nCommandType
= rPar1
.GetToken(2, DB_DELIM
).ToInt32();
221 String sColumn
= rPar1
.GetToken(3, DB_DELIM
);
223 SwDBFieldType
* pOldTyp
= (SwDBFieldType
*)pTmpFld
->GetTyp();
224 SwDBFieldType
* pTyp
= (SwDBFieldType
*)pSh
->InsertFldType(
225 SwDBFieldType(pSh
->GetDoc(), sColumn
, aData
));
227 SwIterator
<SwFmtFld
,SwFieldType
> aIter( *pOldTyp
);
229 for( SwFmtFld
* pFmtFld
= aIter
.First(); pFmtFld
; pFmtFld
= aIter
.Next() )
231 if( pFmtFld
->GetFld() == m_pCurFld
)
233 pFmtFld
->RegisterToFieldType(*pTyp
);
234 pTmpFld
->ChgTyp(pTyp
);
243 SwSetExpFieldType
* pTyp
= (SwSetExpFieldType
*)pTmpFld
->GetTyp();
244 pTyp
->SetOutlineLvl( static_cast< sal_uInt8
>(nSubType
& 0xff));
245 pTyp
->SetDelimiter(OUString(cSeparator
));
247 nSubType
= nsSwGetSetExpType::GSE_SEQ
;
253 // User- or SetField ?
254 if (m_aMgr
.GetFldType(RES_USERFLD
, sPar1
) == 0 &&
255 !(pTmpFld
->GetSubType() & INP_TXT
)) // SETEXPFLD
257 SwSetExpField
* pFld
= (SwSetExpField
*)pTmpFld
;
258 pFld
->SetPromptText(sPar2
);
259 sPar2
= pFld
->GetPar2();
265 if( nSubType
== nsSwDocInfoSubType::DI_CUSTOM
)
267 SwDocInfoField
* pDocInfo
= static_cast<SwDocInfoField
*>( pTmpFld
);
268 pDocInfo
->SetName( rPar1
);
274 pSh
->StartAllAction();
276 pTmpFld
->SetSubType(nSubType
);
277 pTmpFld
->SetAutomaticLanguage(bIsAutomaticLanguage
);
279 m_aMgr
.UpdateCurFld( nFormatId
, sPar1
, sPar2
, pTmpFld
);
281 m_pCurFld
= m_aMgr
.GetCurFld();
285 case TYP_HIDDENTXTFLD
:
286 case TYP_HIDDENPARAFLD
:
287 m_aMgr
.EvalExpFlds(pSh
);
291 pSh
->SetUndoNoResetModified();
298 void SwFldPage::SavePos( const ListBox
* pLst1
, const ListBox
* pLst2
,
299 const ListBox
* pLst3
)
301 const ListBox
* aLBArr
[ coLBCount
] = { pLst1
, pLst2
, pLst3
};
303 const ListBox
** ppLB
= aLBArr
;
304 for( int i
= 0; i
< coLBCount
; ++i
, ++ppLB
)
305 if( (*ppLB
) && (*ppLB
)->GetEntryCount() )
306 m_aLstStrArr
[ i
] = (*ppLB
)->GetSelectEntry();
308 m_aLstStrArr
[ i
].Erase();
311 void SwFldPage::RestorePos(ListBox
* pLst1
, ListBox
* pLst2
, ListBox
* pLst3
)
314 ListBox
* aLBArr
[ coLBCount
] = { pLst1
, pLst2
, pLst3
};
315 ListBox
** ppLB
= aLBArr
;
316 for( int i
= 0; i
< coLBCount
; ++i
, ++ppLB
)
317 if( (*ppLB
) && (*ppLB
)->GetEntryCount() && m_aLstStrArr
[ i
].Len() &&
318 LISTBOX_ENTRY_NOTFOUND
!=
319 ( nPos
= (*ppLB
)->GetEntryPos(m_aLstStrArr
[ i
] ) ) )
320 (*ppLB
)->SelectEntryPos( nPos
);
323 /*--------------------------------------------------------------------
324 Description: Insert new fields
325 --------------------------------------------------------------------*/
327 IMPL_LINK( SwFldPage
, InsertHdl
, Button
*, pBtn
)
329 SwFldDlg
*pDlg
= (SwFldDlg
*)GetTabDialog();
336 pBtn
->GrabFocus(); // because of InputField-Dlg
340 SwFldEditDlg
*pEditDlg
= (SwFldEditDlg
*)GetParent();
341 pEditDlg
->InsertHdl();
347 /*--------------------------------------------------------------------
348 Description: enable/disable "Insert"-Button
349 --------------------------------------------------------------------*/
351 void SwFldPage::EnableInsert(sal_Bool bEnable
)
353 SwFldDlg
*pDlg
= (SwFldDlg
*)GetTabDialog();
357 if (pDlg
->GetCurPageId() == m_nPageId
)
358 pDlg
->EnableInsert(bEnable
);
362 SwFldEditDlg
*pEditDlg
= (SwFldEditDlg
*)GetParent();
363 pEditDlg
->EnableInsert(bEnable
);
369 IMPL_LINK_NOARG(SwFldPage
, NumFormatHdl
)
376 void SwFldPage::SetWrtShell( SwWrtShell
* pShell
)
378 m_pWrtShell
= pShell
;
379 m_aMgr
.SetWrtShell( pShell
);
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */