1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 #ifdef SW_DLLIMPLEMENTATION 27 #undef SW_DLLIMPLEMENTATION 28 #endif 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 <expfld.hxx> 37 #include <view.hxx> 38 #include <dbfld.hxx> 39 #include <wrtsh.hxx> 40 #include <flddb.hxx> 41 #include <flddinf.hxx> 42 #include <fldvar.hxx> 43 #include <flddok.hxx> 44 #include <fldfunc.hxx> 45 #include <fldref.hxx> 46 #include <fldedt.hxx> 47 #include <crsskip.hxx> 48 49 50 #include <cmdid.h> 51 #include <helpid.h> 52 #include <globals.hrc> 53 #include <fldui.hrc> 54 #include "swabstdlg.hxx" 55 #include "dialog.hrc" 56 57 #include <com/sun/star/document/XDocumentProperties.hpp> 58 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 59 60 61 namespace swui 62 { 63 SwAbstractDialogFactory * GetFactory(); 64 } 65 66 /*-------------------------------------------------------------------- 67 Beschreibung: 68 --------------------------------------------------------------------*/ 69 70 SwFldEditDlg::SwFldEditDlg(SwView& rVw) : 71 SfxSingleTabDialog(&rVw.GetViewFrame()->GetWindow(), 0, 0), 72 pSh (rVw.GetWrtShellPtr()), 73 aPrevBT (this, SW_RES(BTN_FLDEDT_PREV)), 74 aNextBT (this, SW_RES(BTN_FLDEDT_NEXT)), 75 aAddressBT (this, SW_RES(PB_FLDEDT_ADDRESS)) 76 { 77 SwFldMgr aMgr(pSh); 78 79 SwField *pCurFld = aMgr.GetCurFld(); 80 if(!pCurFld) 81 return; 82 83 pSh->SetCareWin(this); 84 85 if ( pSh->CrsrInsideInputFld() ) 86 { 87 // move cursor to start of Input Field 88 SwInputField* pInputFld = dynamic_cast<SwInputField*>(pCurFld); 89 if ( pInputFld != NULL 90 && pInputFld->GetFmtFld() != NULL ) 91 { 92 pSh->GotoField( *(pInputFld->GetFmtFld()) ); 93 } 94 } 95 96 if ( ! pSh->HasSelection() ) 97 { 98 pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False ); 99 } 100 101 pSh->NormalizePam(); 102 103 sal_uInt16 nGroup = aMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType()); 104 105 CreatePage(nGroup); 106 107 GetOKButton()->SetClickHdl(LINK(this, SwFldEditDlg, OKHdl)); 108 109 // Buttons selbst positionieren, da sie sonst bei unterschiedlichen 110 // Fontgroessen im Wald stehen, und da PB im SingleTabDlg feste Pixelgroessen 111 // fuer seine Buttons und die Dialogbreite verwendet. 112 aPrevBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aPrevBT.GetPosPixel().Y())); 113 sal_uInt16 nWidth = static_cast< sal_uInt16 >(GetOKButton()->GetOutputSize().Width() / 2 - 3); 114 Size aNewSize(LogicToPixel(Size(nWidth, GetOKButton()->GetOutputSize().Height()))); 115 aPrevBT.SetSizePixel(aNewSize); 116 117 aNextBT.SetSizePixel(aPrevBT.GetSizePixel()); 118 119 long nXPos = GetOKButton()->GetPosPixel().X() + GetOKButton()->GetSizePixel().Width() 120 - aNextBT.GetSizePixel().Width() - 1; 121 aNextBT.SetPosPixel(Point(nXPos, aNextBT.GetPosPixel().Y())); 122 123 aAddressBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aAddressBT.GetPosPixel().Y())); 124 aAddressBT.SetSizePixel(GetOKButton()->GetSizePixel()); 125 126 aPrevBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl)); 127 aNextBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl)); 128 129 aAddressBT.SetClickHdl(LINK(this, SwFldEditDlg, AddressHdl)); 130 aAddressBT.SetHelpId(HID_FLDEDT_ADDRESS); 131 132 Init(); 133 } 134 135 /*-------------------------------------------------------------------- 136 Beschreibung: Controlls initialisieren 137 --------------------------------------------------------------------*/ 138 139 void SwFldEditDlg::Init() 140 { 141 SwFldPage* pTabPage = (SwFldPage*)GetTabPage(); 142 143 if( pTabPage ) 144 { 145 SwFldMgr& rMgr = pTabPage->GetFldMgr(); 146 147 SwField *pCurFld = rMgr.GetCurFld(); 148 149 if(!pCurFld) 150 return; 151 152 // Traveling nur bei mehr als einem Feld 153 pSh->StartAction(); 154 pSh->CreateCrsr(); 155 156 sal_Bool bMove = rMgr.GoNext(); 157 if( bMove ) 158 rMgr.GoPrev(); 159 aNextBT.Enable(bMove); 160 161 if( 0 != ( bMove = rMgr.GoPrev() ) ) 162 rMgr.GoNext(); 163 aPrevBT.Enable( bMove ); 164 165 if (pCurFld->GetTypeId() == TYP_EXTUSERFLD) 166 aAddressBT.Show(); 167 168 pSh->DestroyCrsr(); 169 pSh->EndAction(); 170 } 171 172 GetOKButton()->Enable( !pSh->IsReadOnlyAvailable() || 173 !pSh->HasReadonlySel() ); 174 } 175 176 /*-------------------------------------------------------------------- 177 Beschreibung: 178 --------------------------------------------------------------------*/ 179 180 SfxTabPage* SwFldEditDlg::CreatePage(sal_uInt16 nGroup) 181 { 182 // TabPage erzeugen 183 SfxTabPage* pTabPage = 0; 184 const char* pHelpId = 0; 185 186 switch (nGroup) 187 { 188 case GRP_DOC: 189 pTabPage = SwFldDokPage::Create(this, *(SfxItemSet*)0); 190 pHelpId = HID_EDIT_FLD_DOK; 191 break; 192 case GRP_FKT: 193 pTabPage = SwFldFuncPage::Create(this, *(SfxItemSet*)0); 194 pHelpId = HID_EDIT_FLD_FUNC; 195 break; 196 case GRP_REF: 197 pTabPage = SwFldRefPage::Create(this, *(SfxItemSet*)0); 198 pHelpId = HID_EDIT_FLD_REF; 199 break; 200 case GRP_REG: 201 { 202 SfxObjectShell* pDocSh = SfxObjectShell::Current(); 203 SfxItemSet* pSet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO ); 204 using namespace ::com::sun::star; 205 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 206 pDocSh->GetModel(), uno::UNO_QUERY_THROW); 207 uno::Reference<document::XDocumentProperties> xDocProps 208 = xDPS->getDocumentProperties(); 209 uno::Reference< beans::XPropertySet > xUDProps( 210 xDocProps->getUserDefinedProperties(), 211 uno::UNO_QUERY_THROW); 212 // uno::Reference< beans::XPropertySetInfo > xSetInfo 213 // = xUDProps->getPropertySetInfo(); 214 // const uno::Sequence< beans::Property > props 215 // = xSetInfo->getProperties(); 216 // uno::Sequence< ::rtl::OUString > names(props.getLength()); 217 // for (sal_Int32 i = 0; i < props.getLength(); ++i) { 218 // names[i] = props[i].Name; 219 // } 220 pSet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) ); 221 pTabPage = SwFldDokInfPage::Create(this, *pSet); 222 pHelpId = HID_EDIT_FLD_DOKINF; 223 break; 224 } 225 case GRP_DB: 226 pTabPage = SwFldDBPage::Create(this, *(SfxItemSet*)0); 227 static_cast<SwFldDBPage*>(pTabPage)->SetWrtShell(*pSh); 228 pHelpId = HID_EDIT_FLD_DB; 229 break; 230 case GRP_VAR: 231 pTabPage = SwFldVarPage::Create(this, *(SfxItemSet*)0); 232 pHelpId = HID_EDIT_FLD_VAR; 233 break; 234 235 } 236 237 pTabPage->SetHelpId(pHelpId); 238 static_cast<SwFldPage*>(pTabPage)->SetWrtShell(pSh); 239 240 SetTabPage(pTabPage); 241 242 String sTitle(GetText()); 243 sTitle.Insert(String::CreateFromAscii(": "), 0); 244 sTitle.Insert(SW_RESSTR(STR_FLD_EDIT_DLG), 0); 245 SetText(sTitle); 246 247 return pTabPage; 248 } 249 250 /*-------------------------------------------------------------------- 251 Beschreibung: 252 --------------------------------------------------------------------*/ 253 254 SwFldEditDlg::~SwFldEditDlg() 255 { 256 pSh->SetCareWin(NULL); 257 pSh->EnterStdMode(); 258 } 259 260 /*-------------------------------------------------------------------- 261 Beschreibung: 262 --------------------------------------------------------------------*/ 263 264 void SwFldEditDlg::EnableInsert(sal_Bool bEnable) 265 { 266 if( bEnable && pSh->IsReadOnlyAvailable() && pSh->HasReadonlySel() ) 267 bEnable = sal_False; 268 GetOKButton()->Enable( bEnable ); 269 } 270 271 /*-------------------------------------------------------------------- 272 Beschreibung: 273 --------------------------------------------------------------------*/ 274 275 void SwFldEditDlg::InsertHdl() 276 { 277 GetOKButton()->Click(); 278 } 279 280 /*-------------------------------------------------------------------- 281 Beschreibung: Aendern des Feldes anstossen 282 --------------------------------------------------------------------*/ 283 284 IMPL_LINK( SwFldEditDlg, OKHdl, Button *, EMPTYARG ) 285 { 286 if (GetOKButton()->IsEnabled()) 287 { 288 SfxTabPage* pTabPage = GetTabPage(); 289 if (pTabPage) 290 { 291 pTabPage->FillItemSet(*(SfxItemSet*)0); 292 293 } 294 EndDialog( RET_OK ); 295 } 296 297 return 0; 298 } 299 300 /*-------------------------------------------------------------------- 301 Beschreibung: 302 --------------------------------------------------------------------*/ 303 304 short SwFldEditDlg::Execute() 305 { 306 // Ohne TabPage kein Dialog 307 return GetTabPage() ? Dialog::Execute() : RET_CANCEL; 308 } 309 310 /*-------------------------------------------------------------------- 311 Beschreibung: Traveling zwishen Feldern gleichen Typs 312 --------------------------------------------------------------------*/ 313 314 IMPL_LINK( SwFldEditDlg, NextPrevHdl, Button *, pButton ) 315 { 316 sal_Bool bNext = pButton == &aNextBT; 317 318 pSh->EnterStdMode(); 319 320 SwFieldType *pOldTyp = 0; 321 SwFldPage* pTabPage = (SwFldPage*)GetTabPage(); 322 323 //#112462# FillItemSet may delete the current field 324 //that's why it has to be called before accessing the current field 325 if( GetOKButton()->IsEnabled() ) 326 pTabPage->FillItemSet(*(SfxItemSet*)0); 327 328 SwFldMgr& rMgr = pTabPage->GetFldMgr(); 329 SwField *pCurFld = rMgr.GetCurFld(); 330 if (pCurFld->GetTypeId() == TYP_DBFLD) 331 pOldTyp = (SwDBFieldType*)pCurFld->GetTyp(); 332 333 rMgr.GoNextPrev( bNext, pOldTyp ); 334 pCurFld = rMgr.GetCurFld(); 335 336 /* #108536# Only create selection if there is none 337 already. Normalize PaM instead of swapping. */ 338 if ( ! pSh->HasSelection() ) 339 pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False ); 340 341 pSh->NormalizePam(); 342 343 sal_uInt16 nGroup = rMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType()); 344 345 if (nGroup != pTabPage->GetGroup()) 346 pTabPage = (SwFldPage*)CreatePage(nGroup); 347 348 pTabPage->EditNewField(); 349 350 Init(); 351 352 return 0; 353 } 354 355 /*-------------------------------------------------------------------- 356 Beschreibung: 357 --------------------------------------------------------------------*/ 358 359 IMPL_LINK( SwFldEditDlg, AddressHdl, PushButton *, EMPTYARG ) 360 { 361 SwFldPage* pTabPage = (SwFldPage*)GetTabPage(); 362 SwFldMgr& rMgr = pTabPage->GetFldMgr(); 363 SwField *pCurFld = rMgr.GetCurFld(); 364 365 SfxItemSet aSet( pSh->GetAttrPool(), 366 SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS, 367 0L ); 368 369 sal_uInt16 nEditPos = UNKNOWN_EDIT; 370 371 switch(pCurFld->GetSubType()) 372 { 373 case EU_FIRSTNAME: nEditPos = FIRSTNAME_EDIT; break; 374 case EU_NAME: nEditPos = LASTNAME_EDIT; break; 375 case EU_SHORTCUT: nEditPos = SHORTNAME_EDIT; break; 376 case EU_COMPANY: nEditPos = COMPANY_EDIT; break; 377 case EU_STREET: nEditPos = STREET_EDIT; break; 378 case EU_TITLE: nEditPos = TITLE_EDIT; break; 379 case EU_POSITION: nEditPos = POSITION_EDIT; break; 380 case EU_PHONE_PRIVATE:nEditPos = TELPRIV_EDIT; break; 381 case EU_PHONE_COMPANY:nEditPos = TELCOMPANY_EDIT; break; 382 case EU_FAX: nEditPos = FAX_EDIT; break; 383 case EU_EMAIL: nEditPos = EMAIL_EDIT; break; 384 case EU_COUNTRY: nEditPos = COUNTRY_EDIT; break; 385 case EU_ZIP: nEditPos = PLZ_EDIT; break; 386 case EU_CITY: nEditPos = CITY_EDIT; break; 387 case EU_STATE: nEditPos = STATE_EDIT; break; 388 389 default: nEditPos = UNKNOWN_EDIT; break; 390 391 } 392 aSet.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS, nEditPos)); 393 SwAbstractDialogFactory* pFact = swui::GetFactory(); 394 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!"); 395 396 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aSet, 397 pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(), 398 RC_DLG_ADDR ); 399 DBG_ASSERT(pDlg, "Dialogdiet fail!"); 400 if(RET_OK == pDlg->Execute()) 401 { 402 pSh->UpdateFlds( *pCurFld ); 403 } 404 delete pDlg; 405 return 0; 406 } 407 408 409