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: fldtdlg.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
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>
54 #include <fldwrap.hxx>
59 #include <flddinf.hxx>
68 #include <fldfunc.hxx>
76 #include <fldtdlg.hxx>
78 #include <swmodule.hxx>
87 #include <globals.hrc>
90 #include <fldtdlg.hrc>
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
)),
106 m_bDataBaseMode(FALSE
)
108 SetStyle(GetStyle()|WB_STDMODELESS
);
109 m_bHtmlMode
= (::GetHtmlMode((SwDocShell
*)SfxObjectShell::Current()) & HTMLMODE_ON
) != 0;
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
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);
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(),
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
;
148 AddTabPage(TP_FLD_DB
, SwFldDBPage::Create
, 0);
150 RemoveTabPage(TP_FLD_DB
);
154 RemoveTabPage(TP_FLD_REF
);
155 RemoveTabPage(TP_FLD_FUNC
);
156 RemoveTabPage(TP_FLD_DB
);
160 /*--------------------------------------------------------------------
162 --------------------------------------------------------------------*/
164 SwFldDlg::~SwFldDlg()
168 /*--------------------------------------------------------------------
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
);
180 /*--------------------------------------------------------------------
182 --------------------------------------------------------------------*/
184 void SwFldDlg::Initialize(SfxChildWinInfo
*pInfo
)
189 if ( pInfo
->aSize
.Width() != 0 && pInfo
->aSize
.Height() != 0 )
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
)
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;
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;
230 /*--------------------------------------------------------------------
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
) ) );
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
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
);
296 SwView
* pActiveView
= ::GetActiveView();
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
);
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
);
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();
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
);
347 ReInitTabPage( TP_FLD_REF
, TRUE
);
348 ReInitTabPage( TP_FLD_FUNC
, TRUE
);
353 /*--------------------------------------------------------------------
355 --------------------------------------------------------------------*/
357 void SwFldDlg::EnableInsert(BOOL bEnable
)
361 SwView
* pView
= ::GetActiveView();
362 DBG_ASSERT(pView
, "no view found");
364 (pView
->GetWrtShell().IsReadOnlyAvailable() &&
365 pView
->GetWrtShell().HasReadonlySel()) )
368 GetOKButton().Enable(bEnable
);
371 /*--------------------------------------------------------------------
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
);
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;
409 const TypeId aSwViewTypeId
= TYPE(SwView
);
410 SfxViewShell
* pViewShell
= SfxViewShell::GetFirst( &aSwViewTypeId
);
411 while(pViewShell
&& pViewShell
->GetViewFrame() != pViewFrame
)
413 pViewShell
= SfxViewShell::GetNext( *pViewShell
, &aSwViewTypeId
);
416 static_cast<SwFldDBPage
&>(rPage
).SetWrtShell(static_cast<SwView
*>(pViewShell
)->GetWrtShell());