Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/msgbox.hxx>
30 : : #include <sfx2/basedlgs.hxx>
31 : : #include <sfx2/viewfrm.hxx>
32 : : #include <sfx2/request.hxx>
33 : : #include <sfx2/app.hxx>
34 : : #include <svx/optgenrl.hxx>
35 : : #include <docufld.hxx>
36 : : #include <view.hxx>
37 : : #include <dbfld.hxx>
38 : : #include <wrtsh.hxx>
39 : : #include <flddb.hxx>
40 : : #include <flddinf.hxx>
41 : : #include <fldvar.hxx>
42 : : #include <flddok.hxx>
43 : : #include <fldfunc.hxx>
44 : : #include <fldref.hxx>
45 : : #include <fldedt.hxx>
46 : : #include <crsskip.hxx>
47 : :
48 : :
49 : : #include <cmdid.h>
50 : : #include <helpid.h>
51 : : #include <globals.hrc>
52 : : #include <fldui.hrc>
53 : : #include "swabstdlg.hxx"
54 : : #include "dialog.hrc"
55 : :
56 : : #include <com/sun/star/document/XDocumentProperties.hpp>
57 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
58 : :
59 : : namespace swui
60 : : {
61 : : SwAbstractDialogFactory * GetFactory();
62 : : }
63 : :
64 : 0 : SwFldEditDlg::SwFldEditDlg(SwView& rVw) :
65 : 0 : SfxSingleTabDialog(&rVw.GetViewFrame()->GetWindow(), 0, 0),
66 : 0 : pSh (rVw.GetWrtShellPtr()),
67 : : aPrevBT (this, SW_RES(BTN_FLDEDT_PREV)),
68 : : aNextBT (this, SW_RES(BTN_FLDEDT_NEXT)),
69 : 0 : aAddressBT (this, SW_RES(PB_FLDEDT_ADDRESS))
70 : : {
71 : 0 : SwFldMgr aMgr(pSh);
72 : :
73 : 0 : SwField *pCurFld = aMgr.GetCurFld();
74 : 0 : if(!pCurFld)
75 : 0 : return;
76 : :
77 : 0 : pSh->SetCareWin(this);
78 : :
79 : : /* #108536# Only create selection if there is none
80 : : already. Normalize PaM instead of swapping. */
81 : 0 : if ( ! pSh->HasSelection() )
82 : 0 : pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
83 : :
84 : 0 : pSh->NormalizePam();
85 : :
86 : 0 : sal_uInt16 nGroup = aMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType());
87 : :
88 : 0 : CreatePage(nGroup);
89 : :
90 : 0 : GetOKButton()->SetClickHdl(LINK(this, SwFldEditDlg, OKHdl));
91 : :
92 : : // position buttons ourselves because otherwise when font sizes are
93 : : // varying, they are in the woods, and because PB uses fixed pixel sizes
94 : : // for its buttons and dialog width in SingleTabDlg.
95 : 0 : aPrevBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aPrevBT.GetPosPixel().Y()));
96 : 0 : sal_uInt16 nWidth = static_cast< sal_uInt16 >(GetOKButton()->GetOutputSize().Width() / 2 - 3);
97 : 0 : Size aNewSize(LogicToPixel(Size(nWidth, GetOKButton()->GetOutputSize().Height())));
98 : 0 : aPrevBT.SetSizePixel(aNewSize);
99 : :
100 : 0 : aNextBT.SetSizePixel(aPrevBT.GetSizePixel());
101 : :
102 : 0 : long nXPos = GetOKButton()->GetPosPixel().X() + GetOKButton()->GetSizePixel().Width()
103 : 0 : - aNextBT.GetSizePixel().Width() - 1;
104 : 0 : aNextBT.SetPosPixel(Point(nXPos, aNextBT.GetPosPixel().Y()));
105 : :
106 : 0 : aAddressBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aAddressBT.GetPosPixel().Y()));
107 : 0 : aAddressBT.SetSizePixel(GetOKButton()->GetSizePixel());
108 : :
109 : 0 : aPrevBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
110 : 0 : aNextBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
111 : :
112 : 0 : aAddressBT.SetClickHdl(LINK(this, SwFldEditDlg, AddressHdl));
113 : 0 : aAddressBT.SetHelpId(HID_FLDEDT_ADDRESS);
114 : :
115 : 0 : Init();
116 : : }
117 : :
118 : : /*--------------------------------------------------------------------
119 : : Description: initialise controls
120 : : --------------------------------------------------------------------*/
121 : 0 : void SwFldEditDlg::Init()
122 : : {
123 : 0 : SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
124 : :
125 : 0 : if( pTabPage )
126 : : {
127 : 0 : SwFldMgr& rMgr = pTabPage->GetFldMgr();
128 : :
129 : 0 : SwField *pCurFld = rMgr.GetCurFld();
130 : :
131 : 0 : if(!pCurFld)
132 : 0 : return;
133 : :
134 : : // Traveling only when more than one field
135 : 0 : pSh->StartAction();
136 : 0 : pSh->CreateCrsr();
137 : :
138 : 0 : sal_Bool bMove = rMgr.GoNext();
139 : 0 : if( bMove )
140 : 0 : rMgr.GoPrev();
141 : 0 : aNextBT.Enable(bMove);
142 : :
143 : 0 : if( 0 != ( bMove = rMgr.GoPrev() ) )
144 : 0 : rMgr.GoNext();
145 : 0 : aPrevBT.Enable( bMove );
146 : :
147 : 0 : if (pCurFld->GetTypeId() == TYP_EXTUSERFLD)
148 : 0 : aAddressBT.Show();
149 : :
150 : 0 : pSh->DestroyCrsr();
151 : 0 : pSh->EndAction();
152 : : }
153 : :
154 : 0 : GetOKButton()->Enable( !pSh->IsReadOnlyAvailable() ||
155 : 0 : !pSh->HasReadonlySel() );
156 : : }
157 : :
158 : 0 : SfxTabPage* SwFldEditDlg::CreatePage(sal_uInt16 nGroup)
159 : : {
160 : : // create TabPage
161 : 0 : SfxTabPage* pTabPage = 0;
162 : 0 : const char* pHelpId = 0;
163 : :
164 : 0 : switch (nGroup)
165 : : {
166 : : case GRP_DOC:
167 : 0 : pTabPage = SwFldDokPage::Create(this, *(SfxItemSet*)0);
168 : 0 : pHelpId = HID_EDIT_FLD_DOK;
169 : 0 : break;
170 : : case GRP_FKT:
171 : 0 : pTabPage = SwFldFuncPage::Create(this, *(SfxItemSet*)0);
172 : 0 : pHelpId = HID_EDIT_FLD_FUNC;
173 : 0 : break;
174 : : case GRP_REF:
175 : 0 : pTabPage = SwFldRefPage::Create(this, *(SfxItemSet*)0);
176 : 0 : pHelpId = HID_EDIT_FLD_REF;
177 : 0 : break;
178 : : case GRP_REG:
179 : : {
180 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
181 : 0 : SfxItemSet* pSet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
182 : : using namespace ::com::sun::star;
183 : : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
184 : 0 : pDocSh->GetModel(), uno::UNO_QUERY_THROW);
185 : : uno::Reference<document::XDocumentProperties> xDocProps
186 : 0 : = xDPS->getDocumentProperties();
187 : : uno::Reference< beans::XPropertySet > xUDProps(
188 : 0 : xDocProps->getUserDefinedProperties(),
189 : 0 : uno::UNO_QUERY_THROW);
190 : 0 : pSet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) );
191 : 0 : pTabPage = SwFldDokInfPage::Create(this, *pSet);
192 : 0 : pHelpId = HID_EDIT_FLD_DOKINF;
193 : 0 : break;
194 : : }
195 : : case GRP_DB:
196 : 0 : pTabPage = SwFldDBPage::Create(this, *(SfxItemSet*)0);
197 : 0 : static_cast<SwFldDBPage*>(pTabPage)->SetWrtShell(*pSh);
198 : 0 : pHelpId = HID_EDIT_FLD_DB;
199 : 0 : break;
200 : : case GRP_VAR:
201 : 0 : pTabPage = SwFldVarPage::Create(this, *(SfxItemSet*)0);
202 : 0 : pHelpId = HID_EDIT_FLD_VAR;
203 : 0 : break;
204 : :
205 : : }
206 : :
207 : 0 : pTabPage->SetHelpId(pHelpId);
208 : 0 : static_cast<SwFldPage*>(pTabPage)->SetWrtShell(pSh);
209 : :
210 : 0 : SetTabPage(pTabPage);
211 : :
212 : 0 : String sTitle(GetText());
213 : 0 : sTitle.Insert(rtl::OUString(": "), 0);
214 : 0 : sTitle.Insert(SW_RESSTR(STR_FLD_EDIT_DLG), 0);
215 : 0 : SetText(sTitle);
216 : :
217 : 0 : return pTabPage;
218 : : }
219 : :
220 : 0 : SwFldEditDlg::~SwFldEditDlg()
221 : : {
222 : 0 : pSh->SetCareWin(NULL);
223 : 0 : pSh->EnterStdMode();
224 : 0 : }
225 : :
226 : 0 : void SwFldEditDlg::EnableInsert(sal_Bool bEnable)
227 : : {
228 : 0 : if( bEnable && pSh->IsReadOnlyAvailable() && pSh->HasReadonlySel() )
229 : 0 : bEnable = sal_False;
230 : 0 : GetOKButton()->Enable( bEnable );
231 : 0 : }
232 : :
233 : 0 : void SwFldEditDlg::InsertHdl()
234 : : {
235 : 0 : GetOKButton()->Click();
236 : 0 : }
237 : :
238 : : /*--------------------------------------------------------------------
239 : : Description: kick off changing of the field
240 : : --------------------------------------------------------------------*/
241 : 0 : IMPL_LINK_NOARG(SwFldEditDlg, OKHdl)
242 : : {
243 : 0 : if (GetOKButton()->IsEnabled())
244 : : {
245 : 0 : SfxTabPage* pTabPage = GetTabPage();
246 : 0 : if (pTabPage)
247 : : {
248 : 0 : pTabPage->FillItemSet(*(SfxItemSet*)0);
249 : :
250 : : }
251 : 0 : EndDialog( RET_OK );
252 : : }
253 : :
254 : 0 : return 0;
255 : : }
256 : :
257 : 0 : short SwFldEditDlg::Execute()
258 : : {
259 : : // without TabPage no dialog
260 : 0 : return GetTabPage() ? Dialog::Execute() : RET_CANCEL;
261 : : }
262 : :
263 : : /*--------------------------------------------------------------------
264 : : Description: Traveling between fields of the same type
265 : : --------------------------------------------------------------------*/
266 : 0 : IMPL_LINK( SwFldEditDlg, NextPrevHdl, Button *, pButton )
267 : : {
268 : 0 : sal_Bool bNext = pButton == &aNextBT;
269 : :
270 : 0 : pSh->EnterStdMode();
271 : :
272 : 0 : SwFieldType *pOldTyp = 0;
273 : 0 : SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
274 : :
275 : : //#112462# FillItemSet may delete the current field
276 : : //that's why it has to be called before accessing the current field
277 : 0 : if( GetOKButton()->IsEnabled() )
278 : 0 : pTabPage->FillItemSet(*(SfxItemSet*)0);
279 : :
280 : 0 : SwFldMgr& rMgr = pTabPage->GetFldMgr();
281 : 0 : SwField *pCurFld = rMgr.GetCurFld();
282 : 0 : if (pCurFld->GetTypeId() == TYP_DBFLD)
283 : 0 : pOldTyp = (SwDBFieldType*)pCurFld->GetTyp();
284 : :
285 : 0 : rMgr.GoNextPrev( bNext, pOldTyp );
286 : 0 : pCurFld = rMgr.GetCurFld();
287 : :
288 : : /* #108536# Only create selection if there is none
289 : : already. Normalize PaM instead of swapping. */
290 : 0 : if ( ! pSh->HasSelection() )
291 : 0 : pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
292 : :
293 : 0 : pSh->NormalizePam();
294 : :
295 : 0 : sal_uInt16 nGroup = rMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType());
296 : :
297 : 0 : if (nGroup != pTabPage->GetGroup())
298 : 0 : pTabPage = (SwFldPage*)CreatePage(nGroup);
299 : :
300 : 0 : pTabPage->EditNewField();
301 : :
302 : 0 : Init();
303 : :
304 : 0 : return 0;
305 : : }
306 : :
307 : 0 : IMPL_LINK_NOARG(SwFldEditDlg, AddressHdl)
308 : : {
309 : 0 : SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
310 : 0 : SwFldMgr& rMgr = pTabPage->GetFldMgr();
311 : 0 : SwField *pCurFld = rMgr.GetCurFld();
312 : :
313 : 0 : SfxItemSet aSet( pSh->GetAttrPool(),
314 : : SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS,
315 : 0 : 0L );
316 : :
317 : 0 : sal_uInt16 nEditPos = UNKNOWN_EDIT;
318 : :
319 : 0 : switch(pCurFld->GetSubType())
320 : : {
321 : 0 : case EU_FIRSTNAME: nEditPos = FIRSTNAME_EDIT; break;
322 : 0 : case EU_NAME: nEditPos = LASTNAME_EDIT; break;
323 : 0 : case EU_SHORTCUT: nEditPos = SHORTNAME_EDIT; break;
324 : 0 : case EU_COMPANY: nEditPos = COMPANY_EDIT; break;
325 : 0 : case EU_STREET: nEditPos = STREET_EDIT; break;
326 : 0 : case EU_TITLE: nEditPos = TITLE_EDIT; break;
327 : 0 : case EU_POSITION: nEditPos = POSITION_EDIT; break;
328 : 0 : case EU_PHONE_PRIVATE:nEditPos = TELPRIV_EDIT; break;
329 : 0 : case EU_PHONE_COMPANY:nEditPos = TELCOMPANY_EDIT; break;
330 : 0 : case EU_FAX: nEditPos = FAX_EDIT; break;
331 : 0 : case EU_EMAIL: nEditPos = EMAIL_EDIT; break;
332 : 0 : case EU_COUNTRY: nEditPos = COUNTRY_EDIT; break;
333 : 0 : case EU_ZIP: nEditPos = PLZ_EDIT; break;
334 : 0 : case EU_CITY: nEditPos = CITY_EDIT; break;
335 : 0 : case EU_STATE: nEditPos = STATE_EDIT; break;
336 : :
337 : 0 : default: nEditPos = UNKNOWN_EDIT; break;
338 : :
339 : : }
340 : 0 : aSet.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS, nEditPos));
341 : 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
342 : : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
343 : :
344 : : SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aSet,
345 : 0 : pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(),
346 : 0 : RC_DLG_ADDR );
347 : : OSL_ENSURE(pDlg, "Dialogdiet fail!");
348 : 0 : if(RET_OK == pDlg->Execute())
349 : : {
350 : 0 : pSh->UpdateFlds( *pCurFld );
351 : : }
352 : 0 : delete pDlg;
353 : 0 : return 0;
354 : : }
355 : :
356 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|