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: fldedt.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"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
36 #include <vcl/msgbox.hxx>
37 #include <sfx2/basedlgs.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/request.hxx>
40 #include <sfx2/app.hxx>
41 #include <svx/optgenrl.hxx>
42 #include <docufld.hxx>
52 #include <flddinf.hxx>
61 #include <fldfunc.hxx>
67 #include <crsskip.hxx>
77 #include <globals.hrc>
82 #include "swabstdlg.hxx"
85 #include <com/sun/star/document/XDocumentProperties.hpp>
86 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
91 SwAbstractDialogFactory
* GetFactory();
94 /*--------------------------------------------------------------------
96 --------------------------------------------------------------------*/
98 SwFldEditDlg::SwFldEditDlg(SwView
& rVw
) :
99 SfxSingleTabDialog(&rVw
.GetViewFrame()->GetWindow(), 0, 0),
100 pSh (rVw
.GetWrtShellPtr()),
101 aPrevBT (this, SW_RES(BTN_FLDEDT_PREV
)),
102 aNextBT (this, SW_RES(BTN_FLDEDT_NEXT
)),
103 aAddressBT (this, SW_RES(PB_FLDEDT_ADDRESS
))
107 SwField
*pCurFld
= aMgr
.GetCurFld();
111 pSh
->SetCareWin(this);
113 /* #108536# Only create selection if there is none
114 already. Normalize PaM instead of swapping. */
115 if ( ! pSh
->HasSelection() )
116 pSh
->Right(CRSR_SKIP_CHARS
, TRUE
, 1, FALSE
);
120 USHORT nGroup
= aMgr
.GetGroup(FALSE
, pCurFld
->GetTypeId(), pCurFld
->GetSubType());
124 GetOKButton()->SetClickHdl(LINK(this, SwFldEditDlg
, OKHdl
));
126 // Buttons selbst positionieren, da sie sonst bei unterschiedlichen
127 // Fontgroessen im Wald stehen, und da PB im SingleTabDlg feste Pixelgroessen
128 // fuer seine Buttons und die Dialogbreite verwendet.
129 aPrevBT
.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aPrevBT
.GetPosPixel().Y()));
130 USHORT nWidth
= static_cast< USHORT
>(GetOKButton()->GetOutputSize().Width() / 2 - 3);
131 Size
aNewSize(LogicToPixel(Size(nWidth
, GetOKButton()->GetOutputSize().Height())));
132 aPrevBT
.SetSizePixel(aNewSize
);
134 aNextBT
.SetSizePixel(aPrevBT
.GetSizePixel());
136 long nXPos
= GetOKButton()->GetPosPixel().X() + GetOKButton()->GetSizePixel().Width()
137 - aNextBT
.GetSizePixel().Width() - 1;
138 aNextBT
.SetPosPixel(Point(nXPos
, aNextBT
.GetPosPixel().Y()));
140 aAddressBT
.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aAddressBT
.GetPosPixel().Y()));
141 aAddressBT
.SetSizePixel(GetOKButton()->GetSizePixel());
143 aPrevBT
.SetClickHdl(LINK(this, SwFldEditDlg
, NextPrevHdl
));
144 aNextBT
.SetClickHdl(LINK(this, SwFldEditDlg
, NextPrevHdl
));
146 aAddressBT
.SetClickHdl(LINK(this, SwFldEditDlg
, AddressHdl
));
147 aAddressBT
.SetHelpId(HID_FLDEDT_ADDRESS
);
152 /*--------------------------------------------------------------------
153 Beschreibung: Controlls initialisieren
154 --------------------------------------------------------------------*/
156 void SwFldEditDlg::Init()
158 SwFldPage
* pTabPage
= (SwFldPage
*)GetTabPage();
162 SwFldMgr
& rMgr
= pTabPage
->GetFldMgr();
164 SwField
*pCurFld
= rMgr
.GetCurFld();
169 // Traveling nur bei mehr als einem Feld
173 BOOL bMove
= rMgr
.GoNext();
176 aNextBT
.Enable(bMove
);
178 if( 0 != ( bMove
= rMgr
.GoPrev() ) )
180 aPrevBT
.Enable( bMove
);
182 if (pCurFld
->GetTypeId() == TYP_EXTUSERFLD
)
189 GetOKButton()->Enable( !pSh
->IsReadOnlyAvailable() ||
190 !pSh
->HasReadonlySel() );
193 /*--------------------------------------------------------------------
195 --------------------------------------------------------------------*/
197 SfxTabPage
* SwFldEditDlg::CreatePage(USHORT nGroup
)
200 SfxTabPage
* pTabPage
= 0;
206 pTabPage
= SwFldDokPage::Create(this, *(SfxItemSet
*)0);
207 nHelpId
= HID_EDIT_FLD_DOK
;
210 pTabPage
= SwFldFuncPage::Create(this, *(SfxItemSet
*)0);
211 nHelpId
= HID_EDIT_FLD_FUNC
;
214 pTabPage
= SwFldRefPage::Create(this, *(SfxItemSet
*)0);
215 nHelpId
= HID_EDIT_FLD_REF
;
219 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
220 SfxItemSet
* pSet
= new SfxItemSet( pDocSh
->GetPool(), SID_DOCINFO
, SID_DOCINFO
);
221 using namespace ::com::sun::star
;
222 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
223 pDocSh
->GetModel(), uno::UNO_QUERY_THROW
);
224 uno::Reference
<document::XDocumentProperties
> xDocProps
225 = xDPS
->getDocumentProperties();
226 uno::Reference
< beans::XPropertySet
> xUDProps(
227 xDocProps
->getUserDefinedProperties(),
228 uno::UNO_QUERY_THROW
);
229 uno::Reference
< beans::XPropertySetInfo
> xSetInfo
230 = xUDProps
->getPropertySetInfo();
231 const uno::Sequence
< beans::Property
> props
232 = xSetInfo
->getProperties();
233 uno::Sequence
< ::rtl::OUString
> names(props
.getLength());
234 for (sal_Int32 i
= 0; i
< props
.getLength(); ++i
) {
235 names
[i
] = props
[i
].Name
;
237 pSet
->Put( SfxUnoAnyItem( SID_DOCINFO
, uno::makeAny(names
) ) );
238 pTabPage
= SwFldDokInfPage::Create(this, *pSet
);
239 nHelpId
= HID_EDIT_FLD_DOKINF
;
243 pTabPage
= SwFldDBPage::Create(this, *(SfxItemSet
*)0);
244 static_cast<SwFldDBPage
*>(pTabPage
)->SetWrtShell(*pSh
);
245 nHelpId
= HID_EDIT_FLD_DB
;
248 pTabPage
= SwFldVarPage::Create(this, *(SfxItemSet
*)0);
249 nHelpId
= HID_EDIT_FLD_VAR
;
253 pTabPage
->SetHelpId(nHelpId
);
254 static_cast<SwFldPage
*>(pTabPage
)->SetWrtShell(pSh
);
256 SetTabPage(pTabPage
);
258 String
sTitle(GetText());
259 sTitle
.Insert(String::CreateFromAscii(": "), 0);
260 sTitle
.Insert(SW_RESSTR(STR_FLD_EDIT_DLG
), 0);
266 /*--------------------------------------------------------------------
268 --------------------------------------------------------------------*/
270 SwFldEditDlg::~SwFldEditDlg()
272 pSh
->SetCareWin(NULL
);
276 /*--------------------------------------------------------------------
278 --------------------------------------------------------------------*/
280 void SwFldEditDlg::EnableInsert(BOOL bEnable
)
282 if( bEnable
&& pSh
->IsReadOnlyAvailable() && pSh
->HasReadonlySel() )
284 GetOKButton()->Enable( bEnable
);
287 /*--------------------------------------------------------------------
289 --------------------------------------------------------------------*/
291 void SwFldEditDlg::InsertHdl()
293 GetOKButton()->Click();
296 /*--------------------------------------------------------------------
297 Beschreibung: Aendern des Feldes anstossen
298 --------------------------------------------------------------------*/
300 IMPL_LINK( SwFldEditDlg
, OKHdl
, Button
*, EMPTYARG
)
302 if (GetOKButton()->IsEnabled())
304 SfxTabPage
* pTabPage
= GetTabPage();
307 pTabPage
->FillItemSet(*(SfxItemSet
*)0);
316 /*--------------------------------------------------------------------
318 --------------------------------------------------------------------*/
320 short SwFldEditDlg::Execute()
322 // Ohne TabPage kein Dialog
323 return GetTabPage() ? Dialog::Execute() : RET_CANCEL
;
326 /*--------------------------------------------------------------------
327 Beschreibung: Traveling zwishen Feldern gleichen Typs
328 --------------------------------------------------------------------*/
330 IMPL_LINK( SwFldEditDlg
, NextPrevHdl
, Button
*, pButton
)
332 BOOL bNext
= pButton
== &aNextBT
;
336 SwFieldType
*pOldTyp
= 0;
337 SwFldPage
* pTabPage
= (SwFldPage
*)GetTabPage();
339 //#112462# FillItemSet may delete the current field
340 //that's why it has to be called before accessing the current field
341 if( GetOKButton()->IsEnabled() )
342 pTabPage
->FillItemSet(*(SfxItemSet
*)0);
344 SwFldMgr
& rMgr
= pTabPage
->GetFldMgr();
345 SwField
*pCurFld
= rMgr
.GetCurFld();
346 if (pCurFld
->GetTypeId() == TYP_DBFLD
)
347 pOldTyp
= (SwDBFieldType
*)pCurFld
->GetTyp();
349 rMgr
.GoNextPrev( bNext
, pOldTyp
);
350 pCurFld
= rMgr
.GetCurFld();
352 /* #108536# Only create selection if there is none
353 already. Normalize PaM instead of swapping. */
354 if ( ! pSh
->HasSelection() )
355 pSh
->Right(CRSR_SKIP_CHARS
, TRUE
, 1, FALSE
);
359 USHORT nGroup
= rMgr
.GetGroup(FALSE
, pCurFld
->GetTypeId(), pCurFld
->GetSubType());
361 if (nGroup
!= pTabPage
->GetGroup())
362 pTabPage
= (SwFldPage
*)CreatePage(nGroup
);
364 pTabPage
->EditNewField();
371 /*--------------------------------------------------------------------
373 --------------------------------------------------------------------*/
375 IMPL_LINK( SwFldEditDlg
, AddressHdl
, PushButton
*, EMPTYARG
)
377 SwFldPage
* pTabPage
= (SwFldPage
*)GetTabPage();
378 SwFldMgr
& rMgr
= pTabPage
->GetFldMgr();
379 SwField
*pCurFld
= rMgr
.GetCurFld();
381 SfxItemSet
aSet( pSh
->GetAttrPool(),
382 SID_FIELD_GRABFOCUS
, SID_FIELD_GRABFOCUS
,
385 USHORT nEditPos
= UNKNOWN_EDIT
;
387 switch(pCurFld
->GetSubType())
389 case EU_FIRSTNAME
: nEditPos
= FIRSTNAME_EDIT
; break;
390 case EU_NAME
: nEditPos
= LASTNAME_EDIT
; break;
391 case EU_SHORTCUT
: nEditPos
= SHORTNAME_EDIT
; break;
392 case EU_COMPANY
: nEditPos
= COMPANY_EDIT
; break;
393 case EU_STREET
: nEditPos
= STREET_EDIT
; break;
394 case EU_TITLE
: nEditPos
= TITLE_EDIT
; break;
395 case EU_POSITION
: nEditPos
= POSITION_EDIT
; break;
396 case EU_PHONE_PRIVATE
:nEditPos
= TELPRIV_EDIT
; break;
397 case EU_PHONE_COMPANY
:nEditPos
= TELCOMPANY_EDIT
; break;
398 case EU_FAX
: nEditPos
= FAX_EDIT
; break;
399 case EU_EMAIL
: nEditPos
= EMAIL_EDIT
; break;
400 case EU_COUNTRY
: nEditPos
= COUNTRY_EDIT
; break;
401 case EU_ZIP
: nEditPos
= PLZ_EDIT
; break;
402 case EU_CITY
: nEditPos
= CITY_EDIT
; break;
403 case EU_STATE
: nEditPos
= STATE_EDIT
; break;
405 default: nEditPos
= UNKNOWN_EDIT
; break;
408 aSet
.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS
, nEditPos
));
409 SwAbstractDialogFactory
* pFact
= swui::GetFactory();
410 DBG_ASSERT(pFact
, "SwAbstractDialogFactory fail!");
412 SfxAbstractDialog
* pDlg
= pFact
->CreateSfxDialog( this, aSet
,
413 pSh
->GetView().GetViewFrame()->GetFrame()->GetFrameInterface(),
415 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
416 if(RET_OK
== pDlg
->Execute())
418 pSh
->UpdateFlds( *pCurFld
);