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: fldpage.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
39 #include <vcl/lstbox.hxx>
40 #include <svtools/stritem.hxx>
41 #include <sfx2/request.hxx>
42 #include <svx/htmlmode.hxx>
46 #include <viewopt.hxx>
51 #include <swmodule.hxx>
58 #include <fldtdlg.hxx>
61 #include <fldpage.hxx>
63 #include <docufld.hxx>
68 #include <globals.hrc>
70 #include <sfx2/bindings.hxx>
72 using namespace ::com::sun::star
;
74 /*--------------------------------------------------------------------
76 --------------------------------------------------------------------*/
78 SwFldPage::SwFldPage( Window
*pParent
, const ResId
&rId
,
79 const SfxItemSet
&rAttrSet
)
80 :SfxTabPage (pParent
, rId
, rAttrSet
),
83 m_nPageId ( static_cast< USHORT
>(rId
.GetId()) ),
84 m_nTypeSel (LISTBOX_ENTRY_NOTFOUND
),
85 m_nSelectionSel (LISTBOX_ENTRY_NOTFOUND
),
88 m_bFldDlgHtmlMode (FALSE
),
90 m_bFirstHTMLInit (TRUE
)
95 /*--------------------------------------------------------------------
97 --------------------------------------------------------------------*/
99 SwFldPage::~SwFldPage()
103 /*--------------------------------------------------------------------
104 Beschreibung: TabPage initialisieren
105 --------------------------------------------------------------------*/
107 void SwFldPage::Init()
109 SwDocShell
* pDocSh
= (SwDocShell
*)SfxObjectShell::Current();
110 BOOL bNewMode
= 0 != (::GetHtmlMode(pDocSh
) & HTMLMODE_ON
);
112 m_bFldEdit
= 0 == GetTabDialog();
114 // FieldManager neu initialisieren wichtig fuer
115 // Dok-Wechsel (fldtdlg:ReInitTabPage)
116 m_pCurFld
= m_aMgr
.GetCurFld();
118 if( bNewMode
!= m_bFldDlgHtmlMode
)
120 m_bFldDlgHtmlMode
= bNewMode
;
122 // Bereichslistbox initialisieren
123 if( m_bFldDlgHtmlMode
&& m_bFirstHTMLInit
)
125 m_bFirstHTMLInit
= FALSE
;
126 SwWrtShell
*pSh
= m_pWrtShell
;
128 pSh
= ::GetActiveWrtShell();
131 SwDoc
* pDoc
= pSh
->GetDoc();
132 pSh
->InsertFldType( SwSetExpFieldType( pDoc
,
133 String::CreateFromAscii("HTML_ON"), 1));
134 pSh
->InsertFldType( SwSetExpFieldType(pDoc
,
135 String::CreateFromAscii("HTML_OFF"), 1));
141 /*--------------------------------------------------------------------
142 Beschreibung: Seite neu initialisieren
143 --------------------------------------------------------------------*/
145 void SwFldPage::ActivatePage()
147 EnableInsert(m_bInsert
);
150 /*--------------------------------------------------------------------
151 Beschreibung: Kompletter Reset; neues Feld editieren
152 --------------------------------------------------------------------*/
154 void SwFldPage::EditNewField( BOOL bOnlyActivate
)
158 m_nTypeSel
= LISTBOX_ENTRY_NOTFOUND
;
160 m_nSelectionSel
= LISTBOX_ENTRY_NOTFOUND
;
162 Reset(*(SfxItemSet
*)0);
166 /*--------------------------------------------------------------------
167 Beschreibung: Feld einfuegen
168 --------------------------------------------------------------------*/
170 BOOL
SwFldPage::InsertFld(USHORT nTypeId
, USHORT nSubType
, const String
& rPar1
,
171 const String
& rPar2
, ULONG nFormatId
,
172 sal_Unicode cSeparator
, BOOL bIsAutomaticLanguage
)
175 SwView
* pView
= GetActiveView();
176 SwWrtShell
*pSh
= m_pWrtShell
? m_pWrtShell
: pView
->GetWrtShellPtr();
178 if (!IsFldEdit()) // Neues Feld einfuegen
180 SwInsertFld_Data
aData(nTypeId
, nSubType
, rPar1
, rPar2
, nFormatId
, 0, cSeparator
, bIsAutomaticLanguage
);
181 //#i26566# provide parent for SwWrtShell::StartInputFldDlg
182 aData
.pParent
= &GetTabDialog()->GetOKButton();
183 bRet
= m_aMgr
.InsertFld( aData
);
185 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
186 pView
->GetViewFrame()->GetBindings().GetRecorder();
187 if ( xRecorder
.is() )
189 BOOL bRecordDB
= TYP_DBFLD
== nTypeId
||
190 TYP_DBSETNUMBERFLD
== nTypeId
||
191 TYP_DBNUMSETFLD
== nTypeId
||
192 TYP_DBNEXTSETFLD
== nTypeId
||
193 TYP_DBNAMEFLD
== nTypeId
;
195 SfxRequest
aReq( pView
->GetViewFrame(),
196 bRecordDB
? FN_INSERT_DBFIELD
: FN_INSERT_FIELD
);
199 aReq
.AppendItem(SfxStringItem
200 (FN_INSERT_DBFIELD
,rPar1
.GetToken(0, DB_DELIM
)));
201 aReq
.AppendItem(SfxStringItem
202 (FN_PARAM_1
,rPar1
.GetToken(1, DB_DELIM
)));
203 aReq
.AppendItem(SfxInt32Item
204 (FN_PARAM_3
,rPar1
.GetToken(1, DB_DELIM
).ToInt32()));
205 aReq
.AppendItem(SfxStringItem
206 (FN_PARAM_2
,rPar1
.GetToken(3, DB_DELIM
)));
210 aReq
.AppendItem(SfxStringItem(FN_INSERT_FIELD
, rPar1
));
211 aReq
.AppendItem(SfxStringItem
212 (FN_PARAM_3
,String(cSeparator
)));
213 aReq
.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_SUBTYPE
, nSubType
));
215 aReq
.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_TYPE
, nTypeId
));
216 aReq
.AppendItem(SfxStringItem(FN_PARAM_FIELD_CONTENT
, rPar2
));
217 aReq
.AppendItem(SfxUInt32Item(FN_PARAM_FIELD_FORMAT
, nFormatId
));
224 SwField
* pTmpFld
= m_pCurFld
->Copy();
228 BOOL bDBChanged
= FALSE
;
233 nSubType
= static_cast< USHORT
>(((nTypeId
== TYP_DATEFLD
) ? DATEFLD
: TIMEFLD
) |
234 ((nSubType
== DATE_VAR
) ? 0 : FIXEDFLD
));
238 case TYP_DBNEXTSETFLD
:
239 case TYP_DBNUMSETFLD
:
240 case TYP_DBSETNUMBERFLD
:
245 aData
.sDataSource
= rPar1
.GetToken(0, DB_DELIM
, nPos
);
246 aData
.sCommand
= rPar1
.GetToken(0, DB_DELIM
, nPos
);
247 aData
.nCommandType
= rPar1
.GetToken(0, DB_DELIM
, nPos
).ToInt32();
248 sPar1
= rPar1
.Copy(nPos
);
250 ((SwDBNameInfField
*)pTmpFld
)->SetDBData(aData
);
258 aData
.sDataSource
= rPar1
.GetToken(0, DB_DELIM
);
259 aData
.sCommand
= rPar1
.GetToken(1, DB_DELIM
);
260 aData
.nCommandType
= rPar1
.GetToken(2, DB_DELIM
).ToInt32();
261 String sColumn
= rPar1
.GetToken(3, DB_DELIM
);
263 SwDBFieldType
* pOldTyp
= (SwDBFieldType
*)pTmpFld
->GetTyp();
264 SwDBFieldType
* pTyp
= (SwDBFieldType
*)pSh
->InsertFldType(
265 SwDBFieldType(pSh
->GetDoc(), sColumn
, aData
));
267 SwClientIter
aIter( *pOldTyp
);
269 for( SwFmtFld
* pFmtFld
= (SwFmtFld
*)aIter
.First( TYPE(SwFmtFld
) );
270 pFmtFld
; pFmtFld
= (SwFmtFld
*)aIter
.Next() )
272 if( pFmtFld
->GetFld() == m_pCurFld
)
274 pTyp
->Add(pFmtFld
); // Feld auf neuen Typ umhaengen
275 pTmpFld
->ChgTyp(pTyp
);
285 SwSetExpFieldType
* pTyp
= (SwSetExpFieldType
*)pTmpFld
->GetTyp();
286 pTyp
->SetOutlineLvl( static_cast< BYTE
>(nSubType
& 0xff));
287 pTyp
->SetDelimiter(cSeparator
);
289 nSubType
= nsSwGetSetExpType::GSE_SEQ
;
295 // User- oder SetField ?
296 if (m_aMgr
.GetFldType(RES_USERFLD
, sPar1
) == 0 &&
297 !(pTmpFld
->GetSubType() & INP_TXT
)) // SETEXPFLD
299 SwSetExpField
* pFld
= (SwSetExpField
*)pTmpFld
;
300 pFld
->SetPromptText(sPar2
);
301 sPar2
= pFld
->GetPar2();
307 if( nSubType
== nsSwDocInfoSubType::DI_CUSTOM
)
309 SwDocInfoField
* pDocInfo
= static_cast<SwDocInfoField
*>( pTmpFld
);
310 pDocInfo
->SetName( rPar1
);
316 pSh
->StartAllAction();
318 pTmpFld
->SetSubType(nSubType
);
319 pTmpFld
->SetAutomaticLanguage(bIsAutomaticLanguage
);
321 m_aMgr
.UpdateCurFld( nFormatId
, sPar1
, sPar2
, pTmpFld
);
323 m_pCurFld
= m_aMgr
.GetCurFld();
327 case TYP_HIDDENTXTFLD
:
328 case TYP_HIDDENPARAFLD
:
329 m_aMgr
.EvalExpFlds(pSh
);
333 pSh
->SetUndoNoResetModified();
340 /*--------------------------------------------------------------------
342 --------------------------------------------------------------------*/
344 void SwFldPage::SavePos( const ListBox
* pLst1
, const ListBox
* pLst2
,
345 const ListBox
* pLst3
)
347 const ListBox
* aLBArr
[ coLBCount
] = { pLst1
, pLst2
, pLst3
};
349 const ListBox
** ppLB
= aLBArr
;
350 for( int i
= 0; i
< coLBCount
; ++i
, ++ppLB
)
351 if( (*ppLB
) && (*ppLB
)->GetEntryCount() )
352 m_aLstStrArr
[ i
] = (*ppLB
)->GetSelectEntry();
354 m_aLstStrArr
[ i
].Erase();
357 /*--------------------------------------------------------------------
359 --------------------------------------------------------------------*/
361 void SwFldPage::RestorePos(ListBox
* pLst1
, ListBox
* pLst2
, ListBox
* pLst3
)
364 ListBox
* aLBArr
[ coLBCount
] = { pLst1
, pLst2
, pLst3
};
365 ListBox
** ppLB
= aLBArr
;
366 for( int i
= 0; i
< coLBCount
; ++i
, ++ppLB
)
367 if( (*ppLB
) && (*ppLB
)->GetEntryCount() && m_aLstStrArr
[ i
].Len() &&
368 LISTBOX_ENTRY_NOTFOUND
!=
369 ( nPos
= (*ppLB
)->GetEntryPos(m_aLstStrArr
[ i
] ) ) )
370 (*ppLB
)->SelectEntryPos( nPos
);
373 /*--------------------------------------------------------------------
374 Beschreibung: Einfuegen von neuen Feldern
375 --------------------------------------------------------------------*/
377 IMPL_LINK( SwFldPage
, InsertHdl
, Button
*, pBtn
)
379 SwFldDlg
*pDlg
= (SwFldDlg
*)GetTabDialog();
386 pBtn
->GrabFocus(); // Wegen InputField-Dlg
390 SwFldEditDlg
*pEditDlg
= (SwFldEditDlg
*)GetParent();
391 pEditDlg
->InsertHdl();
397 /*--------------------------------------------------------------------
398 Beschreibung: "Einfuegen"-Button Enablen/Disablen
399 --------------------------------------------------------------------*/
401 void SwFldPage::EnableInsert(BOOL bEnable
)
403 SwFldDlg
*pDlg
= (SwFldDlg
*)GetTabDialog();
407 if (pDlg
->GetCurPageId() == m_nPageId
)
408 pDlg
->EnableInsert(bEnable
);
412 SwFldEditDlg
*pEditDlg
= (SwFldEditDlg
*)GetParent();
413 pEditDlg
->EnableInsert(bEnable
);
419 /*--------------------------------------------------------------------
421 --------------------------------------------------------------------*/
423 IMPL_LINK( SwFldPage
, NumFormatHdl
, ListBox
*, EMPTYARG
)
429 /*-- 19.12.2005 14:05:47---------------------------------------------------
431 -----------------------------------------------------------------------*/
432 void SwFldPage::SetWrtShell( SwWrtShell
* pShell
)
434 m_pWrtShell
= pShell
;
435 m_aMgr
.SetWrtShell( pShell
);