update dev300-m58
[ooovba.git] / sw / source / ui / fldui / fldtdlg.cxx
blob63570d75385ee7736707066376f81e7927d96dc5
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: fldtdlg.cxx,v $
10 * $Revision: 1.21 $
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
40 #ifndef _CMDID_H
41 #include <cmdid.h>
42 #endif
43 #include <swtypes.hxx>
44 #include <unotools/confignode.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <sfx2/basedlgs.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <vcl/msgbox.hxx>
49 #include <svx/htmlmode.hxx>
50 #include <viewopt.hxx>
51 #ifndef _DOCSH_HXX
52 #include <docsh.hxx>
53 #endif
54 #include <fldwrap.hxx>
55 #ifndef _FLDDB_HXX
56 #include <flddb.hxx>
57 #endif
58 #ifndef _FLDDINF_HXX
59 #include <flddinf.hxx>
60 #endif
61 #ifndef _FLDVAR_HXX
62 #include <fldvar.hxx>
63 #endif
64 #ifndef _FLDDOK_HXX
65 #include <flddok.hxx>
66 #endif
67 #ifndef _FLDFUNC_HXX
68 #include <fldfunc.hxx>
69 #endif
70 #ifndef _FLDREF_HXX
71 #include <fldref.hxx>
72 #endif
73 #include <wrtsh.hxx>
74 #include <view.hxx>
75 #ifndef _FLDTDLG_HXX
76 #include <fldtdlg.hxx>
77 #endif
78 #include <swmodule.hxx>
80 #ifndef _HELPID_H
81 #include <helpid.h>
82 #endif
83 #ifndef _FLDUI_HRC
84 #include <fldui.hrc>
85 #endif
86 #ifndef _GLOBALS_HRC
87 #include <globals.hrc>
88 #endif
89 #ifndef _FLDTDLG_HRC
90 #include <fldtdlg.hrc>
91 #endif
93 #include <com/sun/star/document/XDocumentProperties.hpp>
94 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
97 /*--------------------------------------------------------------------
98 Beschreibung: Der Traeger des Dialoges
99 --------------------------------------------------------------------*/
102 SwFldDlg::SwFldDlg(SfxBindings* pB, SwChildWinWrapper* pCW, Window *pParent)
103 : SfxTabDialog( pParent, SW_RES( DLG_FLD_INSERT )),
104 m_pChildWin(pCW),
105 m_pBindings(pB),
106 m_bDataBaseMode(FALSE)
108 SetStyle(GetStyle()|WB_STDMODELESS);
109 m_bHtmlMode = (::GetHtmlMode((SwDocShell*)SfxObjectShell::Current()) & HTMLMODE_ON) != 0;
111 RemoveResetButton();
113 GetOKButton().SetText(String(SW_RES(STR_FLD_INSERT)));
114 GetOKButton().SetHelpId(HID_FIELD_INSERT);
115 GetOKButton().SetHelpText(aEmptyStr); // Damit generierter Hilfetext verwendet wird
117 GetCancelButton().SetText(String(SW_RES(STR_FLD_CLOSE)));
118 GetCancelButton().SetHelpId(HID_FIELD_CLOSE);
119 GetCancelButton().SetHelpText(aEmptyStr); // Damit generierter Hilfetext verwendet wird
121 FreeResource();
123 GetOKButton().SetClickHdl(LINK(this, SwFldDlg, OKHdl));
125 AddTabPage(TP_FLD_DOK, SwFldDokPage::Create, 0);
126 AddTabPage(TP_FLD_VAR, SwFldVarPage::Create, 0);
127 AddTabPage(TP_FLD_DOKINF, SwFldDokInfPage::Create, 0);
129 if (!m_bHtmlMode)
131 AddTabPage(TP_FLD_REF, SwFldRefPage::Create, 0);
132 AddTabPage(TP_FLD_FUNC, SwFldFuncPage::Create, 0);
134 utl::OConfigurationTreeRoot aCfgRoot
135 = utl::OConfigurationTreeRoot::createWithServiceFactory(
136 ::comphelper::getProcessServiceFactory(),
137 rtl::OUString(
138 RTL_CONSTASCII_USTRINGPARAM(
139 "/org.openoffice.Office.DataAccess/ApplicationIntegration/InstalledFeatures/Writer" ) ),
141 utl::OConfigurationTreeRoot::CM_READONLY);
143 sal_Bool bDatabaseFields = sal_True;
144 aCfgRoot.getNodeValue(
145 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseFields"))) >>= bDatabaseFields;
147 if (bDatabaseFields)
148 AddTabPage(TP_FLD_DB, SwFldDBPage::Create, 0);
149 else
150 RemoveTabPage(TP_FLD_DB);
152 else
154 RemoveTabPage(TP_FLD_REF);
155 RemoveTabPage(TP_FLD_FUNC);
156 RemoveTabPage(TP_FLD_DB);
160 /*--------------------------------------------------------------------
161 Beschreibung:
162 --------------------------------------------------------------------*/
164 SwFldDlg::~SwFldDlg()
168 /*--------------------------------------------------------------------
169 Beschreibung:
170 --------------------------------------------------------------------*/
172 BOOL SwFldDlg::Close()
174 m_pBindings->GetDispatcher()->
175 Execute(m_bDataBaseMode ? FN_INSERT_FIELD_DATA_ONLY : FN_INSERT_FIELD,
176 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
177 return TRUE;
180 /*--------------------------------------------------------------------
181 Beschreibung:
182 --------------------------------------------------------------------*/
184 void SwFldDlg::Initialize(SfxChildWinInfo *pInfo)
186 Point aPos;
187 Size aSize;
189 if ( pInfo->aSize.Width() != 0 && pInfo->aSize.Height() != 0 )
191 aPos = pInfo->aPos;
192 if ( GetStyle() & WB_SIZEABLE )
193 SetSizePixel( pInfo->aSize );
195 // Initiale Gr"o\se aus pInfo merken
196 aSize = GetSizePixel();
198 // Soll das FloatingWindow eingezoomt werden ?
199 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
200 RollUp();
202 else
204 // Initiale Gr"o\se aus Resource oder ctor merken
205 aSize = GetSizePixel();
207 Size aParentSize = GetParent()->GetOutputSizePixel();
208 aPos.X() += ( aParentSize.Width() - aSize.Width() ) / 2;
209 aPos.Y() += ( aParentSize.Height() - aSize.Height() ) / 2;
212 Point aPoint;
213 Rectangle aRect = GetDesktopRectPixel();
214 aPoint.X() = aRect.Right() - aSize.Width();
215 aPoint.Y() = aRect.Bottom() - aSize.Height();
217 aPoint = OutputToScreenPixel( aPoint );
219 if ( aPos.X() > aPoint.X() )
220 aPos.X() = aPoint.X() ;
221 if ( aPos.Y() > aPoint.Y() )
222 aPos.Y() = aPoint.Y();
224 if ( aPos.X() < 0 ) aPos.X() = 0;
225 if ( aPos.Y() < 0 ) aPos.Y() = 0;
227 SetPosPixel( aPos );
230 /*--------------------------------------------------------------------
231 Beschreibung:
232 --------------------------------------------------------------------*/
234 SfxItemSet* SwFldDlg::CreateInputItemSet( USHORT nID )
236 if ( nID == TP_FLD_DOKINF )
238 SwDocShell* pDocSh = (SwDocShell*)SfxObjectShell::Current();
239 SfxItemSet* pISet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
240 using namespace ::com::sun::star;
241 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
242 pDocSh->GetModel(), uno::UNO_QUERY_THROW);
243 uno::Reference<document::XDocumentProperties> xDocProps
244 = xDPS->getDocumentProperties();
245 uno::Reference< beans::XPropertySet > xUDProps(
246 xDocProps->getUserDefinedProperties(),
247 uno::UNO_QUERY_THROW);
248 uno::Reference< beans::XPropertySetInfo > xSetInfo
249 = xUDProps->getPropertySetInfo();
250 const uno::Sequence< beans::Property > props
251 = xSetInfo->getProperties();
252 uno::Sequence< ::rtl::OUString > names(props.getLength());
253 for (sal_Int32 i = 0; i < props.getLength(); ++i) {
254 names[i] = props[i].Name;
256 pISet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(names) ) );
257 return pISet;
259 else
260 return 0;
263 /*--------------------------------------------------------------------
264 Beschreibung: Einfuegen von neuen Feldern anstossen
265 --------------------------------------------------------------------*/
267 IMPL_LINK( SwFldDlg, OKHdl, Button *, EMPTYARG )
269 if (GetOKButton().IsEnabled())
271 SfxTabPage* pPage = GetTabPage(GetCurPageId());
272 pPage->FillItemSet(*(SfxItemSet*)0);
274 GetOKButton().GrabFocus(); // Wegen InputField-Dlg
277 return 0;
280 /*--------------------------------------------------------------------
281 Beschreibung: Nach Dok-Wechsel Dialog neu initialisieren
282 --------------------------------------------------------------------*/
284 void SwFldDlg::ReInitDlg()
286 SwDocShell* pDocSh = (SwDocShell*)SfxObjectShell::Current();
287 BOOL bNewMode = (::GetHtmlMode(pDocSh) & HTMLMODE_ON) != 0;
289 if (bNewMode != m_bHtmlMode)
291 SfxViewFrame::Current()->GetDispatcher()->
292 Execute(FN_INSERT_FIELD, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
293 Close();
296 SwView* pActiveView = ::GetActiveView();
297 if(!pActiveView)
298 return;
299 const SwWrtShell& rSh = pActiveView->GetWrtShell();
300 GetOKButton().Enable( !rSh.IsReadOnlyAvailable() ||
301 !rSh.HasReadonlySel() );
303 ReInitTabPage(TP_FLD_DOK);
304 ReInitTabPage(TP_FLD_VAR);
305 ReInitTabPage(TP_FLD_DOKINF);
307 if (!m_bHtmlMode)
309 ReInitTabPage(TP_FLD_REF);
310 ReInitTabPage(TP_FLD_FUNC);
311 ReInitTabPage(TP_FLD_DB);
314 m_pChildWin->SetOldDocShell(pDocSh);
317 /*--------------------------------------------------------------------
318 Beschreibung: Nach Dok-Wechsel TabPage neu initialisieren
319 --------------------------------------------------------------------*/
321 void SwFldDlg::ReInitTabPage( USHORT nPageId, BOOL bOnlyActivate )
323 SwFldPage* pPage = (SwFldPage* )GetTabPage(nPageId);
325 if ( pPage )
326 pPage->EditNewField( bOnlyActivate ); // TabPage neu initialisieren
329 /*--------------------------------------------------------------------
330 Beschreibung: Nach Aktivierung einige TabPages neu initialisieren
331 --------------------------------------------------------------------*/
333 void SwFldDlg::Activate()
335 SwView* pView = ::GetActiveView();
336 if( pView )
338 BOOL bHtmlMode = (::GetHtmlMode((SwDocShell*)SfxObjectShell::Current()) & HTMLMODE_ON) != 0;
339 const SwWrtShell& rSh = pView->GetWrtShell();
340 GetOKButton().Enable( !rSh.IsReadOnlyAvailable() ||
341 !rSh.HasReadonlySel() );
343 ReInitTabPage( TP_FLD_VAR, TRUE );
345 if( !bHtmlMode )
347 ReInitTabPage( TP_FLD_REF, TRUE );
348 ReInitTabPage( TP_FLD_FUNC, TRUE );
353 /*--------------------------------------------------------------------
354 Beschreibung:
355 --------------------------------------------------------------------*/
357 void SwFldDlg::EnableInsert(BOOL bEnable)
359 if( bEnable )
361 SwView* pView = ::GetActiveView();
362 DBG_ASSERT(pView, "no view found");
363 if( !pView ||
364 (pView->GetWrtShell().IsReadOnlyAvailable() &&
365 pView->GetWrtShell().HasReadonlySel()) )
366 bEnable = FALSE;
368 GetOKButton().Enable(bEnable);
371 /*--------------------------------------------------------------------
372 Beschreibung:
373 --------------------------------------------------------------------*/
375 void SwFldDlg::InsertHdl()
377 GetOKButton().Click();
379 /* -----------------27.11.2002 15:24-----------------
381 * --------------------------------------------------*/
382 void SwFldDlg::ActivateDatabasePage()
384 m_bDataBaseMode = TRUE;
385 ShowPage( TP_FLD_DB );
386 SfxTabPage* pDBPage = GetTabPage( TP_FLD_DB );
387 if( pDBPage )
389 ((SwFldDBPage*)pDBPage)->ActivateMailMergeAddress();
391 //remove all other pages
392 RemoveTabPage(TP_FLD_DOK);
393 RemoveTabPage(TP_FLD_VAR);
394 RemoveTabPage(TP_FLD_DOKINF);
395 RemoveTabPage(TP_FLD_REF);
396 RemoveTabPage(TP_FLD_FUNC);
398 /*-- 07.10.2003 14:01:44---------------------------------------------------
400 -----------------------------------------------------------------------*/
401 void SwFldDlg::PageCreated(USHORT nId, SfxTabPage& rPage)
403 if( TP_FLD_DB == nId)
405 SfxDispatcher* pDispatch = m_pBindings->GetDispatcher();
406 SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
407 if(pViewFrame)
409 const TypeId aSwViewTypeId = TYPE(SwView);
410 SfxViewShell* pViewShell = SfxViewShell::GetFirst( &aSwViewTypeId );
411 while(pViewShell && pViewShell->GetViewFrame() != pViewFrame)
413 pViewShell = SfxViewShell::GetNext( *pViewShell, &aSwViewTypeId );
415 if(pViewShell)
416 static_cast<SwFldDBPage&>(rPage).SetWrtShell(static_cast<SwView*>(pViewShell)->GetWrtShell());