update dev300-m58
[ooovba.git] / sw / source / ui / fldui / fldpage.cxx
blobe3a286aa0e814ddacbbf41e52742a7b596879114
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: fldpage.cxx,v $
10 * $Revision: 1.20 $
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
39 #include <vcl/lstbox.hxx>
40 #include <svtools/stritem.hxx>
41 #include <sfx2/request.hxx>
42 #include <svx/htmlmode.hxx>
43 #include <dbfld.hxx>
44 #include <flddat.hxx>
45 #include <fmtfld.hxx>
46 #include <viewopt.hxx>
47 #include <fldedt.hxx>
48 #ifndef _DOCSH_HXX
49 #include <docsh.hxx>
50 #endif
51 #include <swmodule.hxx>
52 #ifndef _VIEW_HXX
53 #include <view.hxx>
54 #endif
55 #include <wrtsh.hxx>
56 #include <expfld.hxx>
57 #ifndef _FLDTDLG_HXX
58 #include <fldtdlg.hxx>
59 #endif
60 #ifndef _FLDPAGE_HXX
61 #include <fldpage.hxx>
62 #endif
63 #include <docufld.hxx>
64 #ifndef _CMDID_H
65 #include <cmdid.h>
66 #endif
67 #ifndef _GLOBALS_HRC
68 #include <globals.hrc>
69 #endif
70 #include <sfx2/bindings.hxx>
72 using namespace ::com::sun::star;
74 /*--------------------------------------------------------------------
75 Beschreibung:
76 --------------------------------------------------------------------*/
78 SwFldPage::SwFldPage( Window *pParent, const ResId &rId,
79 const SfxItemSet &rAttrSet )
80 :SfxTabPage (pParent, rId, rAttrSet),
81 m_pCurFld (0),
82 m_pWrtShell (0),
83 m_nPageId ( static_cast< USHORT >(rId.GetId()) ),
84 m_nTypeSel (LISTBOX_ENTRY_NOTFOUND),
85 m_nSelectionSel (LISTBOX_ENTRY_NOTFOUND),
86 m_bFldEdit (FALSE),
87 m_bInsert (TRUE),
88 m_bFldDlgHtmlMode (FALSE),
89 m_bRefresh (FALSE),
90 m_bFirstHTMLInit (TRUE)
92 // FreeResource();
95 /*--------------------------------------------------------------------
96 Beschreibung:
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;
127 if(! pSh)
128 pSh = ::GetActiveWrtShell();
129 if(pSh)
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 )
156 if( !bOnlyActivate )
158 m_nTypeSel = LISTBOX_ENTRY_NOTFOUND;
160 m_nSelectionSel = LISTBOX_ENTRY_NOTFOUND;
161 m_bRefresh = TRUE;
162 Reset(*(SfxItemSet*)0);
163 m_bRefresh = FALSE;
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)
174 BOOL bRet = FALSE;
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 );
197 if(bRecordDB)
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)));
208 else
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));
218 aReq.Done();
222 else // Feld aendern
224 SwField * pTmpFld = m_pCurFld->Copy();
226 String sPar1(rPar1);
227 String sPar2(rPar2);
228 BOOL bDBChanged = FALSE;
229 switch( nTypeId )
231 case TYP_DATEFLD:
232 case TYP_TIMEFLD:
233 nSubType = static_cast< USHORT >(((nTypeId == TYP_DATEFLD) ? DATEFLD : TIMEFLD) |
234 ((nSubType == DATE_VAR) ? 0 : FIXEDFLD));
235 break;
237 case TYP_DBNAMEFLD:
238 case TYP_DBNEXTSETFLD:
239 case TYP_DBNUMSETFLD:
240 case TYP_DBSETNUMBERFLD:
242 xub_StrLen nPos = 0;
243 SwDBData aData;
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);
251 bDBChanged = TRUE;
253 break;
255 case TYP_DBFLD:
257 SwDBData 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);
276 break;
279 bDBChanged = TRUE;
281 break;
283 case TYP_SEQFLD:
285 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pTmpFld->GetTyp();
286 pTyp->SetOutlineLvl( static_cast< BYTE >(nSubType & 0xff));
287 pTyp->SetDelimiter(cSeparator);
289 nSubType = nsSwGetSetExpType::GSE_SEQ;
291 break;
293 case TYP_INPUTFLD:
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();
304 break;
305 case TYP_DOCINFOFLD:
307 if( nSubType == nsSwDocInfoSubType::DI_CUSTOM )
309 SwDocInfoField* pDocInfo = static_cast<SwDocInfoField*>( pTmpFld );
310 pDocInfo->SetName( rPar1 );
313 break;
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();
325 switch (nTypeId)
327 case TYP_HIDDENTXTFLD:
328 case TYP_HIDDENPARAFLD:
329 m_aMgr.EvalExpFlds(pSh);
330 break;
333 pSh->SetUndoNoResetModified();
334 pSh->EndAllAction();
337 return bRet;
340 /*--------------------------------------------------------------------
341 Beschreibung:
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();
353 else
354 m_aLstStrArr[ i ].Erase();
357 /*--------------------------------------------------------------------
358 Beschreibung:
359 --------------------------------------------------------------------*/
361 void SwFldPage::RestorePos(ListBox* pLst1, ListBox* pLst2, ListBox* pLst3)
363 USHORT nPos = 0;
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();
381 if (pDlg)
383 pDlg->InsertHdl();
385 if (pBtn)
386 pBtn->GrabFocus(); // Wegen InputField-Dlg
388 else
390 SwFldEditDlg *pEditDlg = (SwFldEditDlg *)GetParent();
391 pEditDlg->InsertHdl();
394 return 0;
397 /*--------------------------------------------------------------------
398 Beschreibung: "Einfuegen"-Button Enablen/Disablen
399 --------------------------------------------------------------------*/
401 void SwFldPage::EnableInsert(BOOL bEnable)
403 SwFldDlg *pDlg = (SwFldDlg*)GetTabDialog();
405 if (pDlg)
407 if (pDlg->GetCurPageId() == m_nPageId)
408 pDlg->EnableInsert(bEnable);
410 else
412 SwFldEditDlg *pEditDlg = (SwFldEditDlg *)GetParent();
413 pEditDlg->EnableInsert(bEnable);
416 m_bInsert = bEnable;
419 /*--------------------------------------------------------------------
420 Beschreibung:
421 --------------------------------------------------------------------*/
423 IMPL_LINK( SwFldPage, NumFormatHdl, ListBox *, EMPTYARG )
425 InsertHdl();
427 return 0;
429 /*-- 19.12.2005 14:05:47---------------------------------------------------
431 -----------------------------------------------------------------------*/
432 void SwFldPage::SetWrtShell( SwWrtShell* pShell )
434 m_pWrtShell = pShell;
435 m_aMgr.SetWrtShell( pShell );