1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 #ifdef SW_DLLIMPLEMENTATION 31 #undef SW_DLLIMPLEMENTATION 32 #endif 33 34 35 36 #include "dbmgr.hxx" 37 #include <sfx2/app.hxx> 38 #include <vcl/msgbox.hxx> 39 #include <swwait.hxx> 40 #include <viewopt.hxx> 41 42 #include "wrtsh.hxx" 43 #include "errhdl.hxx" 44 #include "cmdid.h" 45 #include "helpid.h" 46 #include "envfmt.hxx" 47 #include "envlop.hxx" 48 #include "envprt.hxx" 49 #include "fmtcol.hxx" 50 #include "poolfmt.hxx" 51 #include "view.hxx" 52 53 #include "envlop.hrc" 54 #include <comphelper/processfactory.hxx> 55 56 #include <unomid.h> 57 58 using namespace ::com::sun::star::lang; 59 using namespace ::com::sun::star::container; 60 using namespace ::com::sun::star::uno; 61 using namespace ::com::sun::star; 62 using namespace ::rtl; 63 64 65 //impl in envimg.cxx 66 extern SW_DLLPUBLIC String MakeSender(); 67 68 // -------------------------------------------------------------------------- 69 70 SwEnvPreview::SwEnvPreview(SfxTabPage* pParent, const ResId& rResID) : 71 72 Window(pParent, rResID) 73 74 { 75 SetMapMode(MapMode(MAP_PIXEL)); 76 } 77 78 // -------------------------------------------------------------------------- 79 80 81 82 SwEnvPreview::~SwEnvPreview() 83 { 84 } 85 86 // ---------------------------------------------------------------------------- 87 void SwEnvPreview::DataChanged( const DataChangedEvent& rDCEvt ) 88 { 89 Window::DataChanged( rDCEvt ); 90 if ( DATACHANGED_SETTINGS == rDCEvt.GetType() ) 91 SetBackground( GetSettings().GetStyleSettings().GetDialogColor() ); 92 } 93 94 // ---------------------------------------------------------------------------- 95 96 void SwEnvPreview::Paint(const Rectangle &) 97 { 98 const StyleSettings& rSettings = GetSettings().GetStyleSettings(); 99 100 const SwEnvItem& rItem = 101 ((SwEnvDlg*) GetParent()->GetParent()->GetParent())->aEnvItem; 102 103 sal_uInt16 nPageW = (sal_uInt16) Max(rItem.lWidth, rItem.lHeight), 104 nPageH = (sal_uInt16) Min(rItem.lWidth, rItem.lHeight); 105 106 float fx = (float)GetOutputSizePixel().Width () / (float)nPageW, 107 fy = (float)GetOutputSizePixel().Height() / (float)nPageH, 108 f = 0.8f * ( fx < fy ? fx : fy ); 109 110 Color aBack = rSettings.GetWindowColor( ); 111 Color aFront = SwViewOption::GetFontColor(); 112 Color aMedium = Color( ( aBack.GetRed() + aFront.GetRed() ) / 2, 113 ( aBack.GetGreen() + aFront.GetGreen() ) / 2, 114 ( aBack.GetBlue() + aFront.GetBlue() ) / 2 115 ); 116 117 SetLineColor( aFront ); 118 119 // Umschlag 120 long nW = (sal_uInt16) (f * nPageW), 121 nH = (sal_uInt16) (f * nPageH), 122 nX = (GetOutputSizePixel().Width () - nW) / 2, 123 nY = (GetOutputSizePixel().Height() - nH) / 2; 124 SetFillColor( aBack ); 125 DrawRect(Rectangle(Point(nX, nY), Size(nW, nH))); 126 127 // Absender 128 if (rItem.bSend) 129 { 130 long nSendX = nX + (sal_uInt16) (f * rItem.lSendFromLeft), 131 nSendY = nY + (sal_uInt16) (f * rItem.lSendFromTop ), 132 nSendW = (sal_uInt16) (f * (rItem.lAddrFromLeft - rItem.lSendFromLeft)), 133 nSendH = (sal_uInt16) (f * (rItem.lAddrFromTop - rItem.lSendFromTop - 566)); 134 SetFillColor( aMedium ); 135 136 DrawRect(Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH))); 137 } 138 139 // Empfaenger 140 long nAddrX = nX + (sal_uInt16) (f * rItem.lAddrFromLeft), 141 nAddrY = nY + (sal_uInt16) (f * rItem.lAddrFromTop ), 142 nAddrW = (sal_uInt16) (f * (nPageW - rItem.lAddrFromLeft - 566)), 143 nAddrH = (sal_uInt16) (f * (nPageH - rItem.lAddrFromTop - 566)); 144 SetFillColor( aMedium ); 145 DrawRect(Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH))); 146 147 // Briefmarke 148 long nStmpW = (sal_uInt16) (f * 1417 /* 2,5 cm */), 149 nStmpH = (sal_uInt16) (f * 1701 /* 3,0 cm */), 150 nStmpX = nX + nW - (sal_uInt16) (f * 566) - nStmpW, 151 nStmpY = nY + (sal_uInt16) (f * 566); 152 153 SetFillColor( aBack ); 154 DrawRect(Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH))); 155 } 156 157 // -------------------------------------------------------------------------- 158 159 160 161 SwEnvDlg::SwEnvDlg(Window* pParent, const SfxItemSet& rSet, 162 SwWrtShell* pWrtSh, Printer* pPrt, sal_Bool bInsert) : 163 164 SfxTabDialog(pParent, SW_RES(DLG_ENV), &rSet, sal_False, &aEmptyStr), 165 sInsert(SW_RES(ST_INSERT)), 166 sChange(SW_RES(ST_CHANGE)), 167 aEnvItem((const SwEnvItem&) rSet.Get(FN_ENVELOP)), 168 pSh(pWrtSh), 169 pPrinter(pPrt), 170 pAddresseeSet(0), 171 pSenderSet(0) 172 { 173 FreeResource(); 174 175 GetOKButton().SetText(String(SW_RES(STR_BTN_NEWDOC))); 176 GetOKButton().SetHelpId(HID_ENVELOP_PRINT); 177 GetOKButton().SetHelpText(aEmptyStr); // Damit generierter Hilfetext verwendet wird 178 if (GetUserButton()) 179 { 180 GetUserButton()->SetText(bInsert ? sInsert : sChange); 181 GetUserButton()->SetHelpId(HID_ENVELOP_INSERT); 182 } 183 184 AddTabPage(TP_ENV_ENV, SwEnvPage ::Create, 0); 185 AddTabPage(TP_ENV_FMT, SwEnvFmtPage::Create, 0); 186 AddTabPage(TP_ENV_PRT, SwEnvPrtPage::Create, 0); 187 } 188 189 // -------------------------------------------------------------------------- 190 191 192 193 SwEnvDlg::~SwEnvDlg() 194 { 195 delete pAddresseeSet; 196 delete pSenderSet; 197 } 198 199 // -------------------------------------------------------------------------- 200 201 202 203 void SwEnvDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage) 204 { 205 if (nId == TP_ENV_PRT) 206 { 207 ((SwEnvPrtPage*)&rPage)->SetPrt(pPrinter); 208 } 209 } 210 211 // -------------------------------------------------------------------------- 212 213 short SwEnvDlg::Ok() 214 { 215 short nRet = SfxTabDialog::Ok(); 216 217 if (nRet == RET_OK || nRet == RET_USER) 218 { 219 if (pAddresseeSet) 220 { 221 SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_JAKETADRESS); 222 pColl->SetFmtAttr(*pAddresseeSet); 223 } 224 if (pSenderSet) 225 { 226 SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_SENDADRESS); 227 pColl->SetFmtAttr(*pSenderSet); 228 } 229 } 230 231 return nRet; 232 } 233 234 // -------------------------------------------------------------------------- 235 236 237 238 SwEnvPage::SwEnvPage(Window* pParent, const SfxItemSet& rSet) : 239 240 SfxTabPage(pParent, SW_RES(TP_ENV_ENV), rSet), 241 242 aAddrText (this, SW_RES(TXT_ADDR )), 243 aAddrEdit (this, SW_RES(EDT_ADDR )), 244 aDatabaseFT (this, SW_RES(FT_DATABASE)), 245 aDatabaseLB (this, SW_RES(LB_DATABASE)), 246 aTableFT (this, SW_RES(FT_TABLE )), 247 aTableLB (this, SW_RES(LB_TABLE )), 248 aInsertBT (this, SW_RES(BTN_INSERT )), 249 aDBFieldFT (this, SW_RES(FT_DBFIELD )), 250 aDBFieldLB (this, SW_RES(LB_DBFIELD )), 251 aSenderBox (this, SW_RES(BOX_SEND )), 252 aSenderEdit (this, SW_RES(EDT_SEND )), 253 aPreview (this, SW_RES(WIN_PREVIEW)) 254 255 { 256 FreeResource(); 257 SetExchangeSupport(); 258 pSh = GetParent()->pSh; 259 260 // Handler installieren 261 aDatabaseLB .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl )); 262 aTableLB .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl )); 263 aInsertBT .SetClickHdl (LINK(this, SwEnvPage, FieldHdl )); 264 aSenderBox .SetClickHdl (LINK(this, SwEnvPage, SenderHdl )); 265 aPreview.SetBorderStyle( WINDOW_BORDER_MONO ); 266 267 SwDBData aData = pSh->GetDBData(); 268 sActDBName = aData.sDataSource; 269 sActDBName += DB_DELIM; 270 sActDBName += (String)aData.sCommand; 271 InitDatabaseBox(); 272 } 273 274 // -------------------------------------------------------------------------- 275 276 277 278 SwEnvPage::~SwEnvPage() 279 { 280 } 281 282 // -------------------------------------------------------------------------- 283 284 285 286 IMPL_LINK( SwEnvPage, DatabaseHdl, ListBox *, pListBox ) 287 { 288 SwWait aWait( *pSh->GetView().GetDocShell(), sal_True ); 289 290 if (pListBox == &aDatabaseLB) 291 { 292 sActDBName = pListBox->GetSelectEntry(); 293 pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sActDBName); 294 sActDBName += DB_DELIM; 295 } 296 else 297 sActDBName.SetToken(1, DB_DELIM, aTableLB.GetSelectEntry()); 298 pSh->GetNewDBMgr()->GetColumnNames( 299 &aDBFieldLB, aDatabaseLB.GetSelectEntry(), aTableLB.GetSelectEntry()); 300 return 0; 301 } 302 303 // -------------------------------------------------------------------------- 304 305 306 307 IMPL_LINK( SwEnvPage, FieldHdl, Button *, EMPTYARG ) 308 { 309 String aStr ( '<' ); 310 aStr += aDatabaseLB.GetSelectEntry(); 311 aStr += '.'; 312 // aStr += DB_DELIM; 313 aStr += aTableLB.GetSelectEntry(); 314 aStr += '.'; 315 aStr += aTableLB.GetEntryData(aTableLB.GetSelectEntryPos()) == 0 ? '0' : '1'; 316 aStr += '.'; 317 // aStr += DB_DELIM; 318 aStr += aDBFieldLB.GetSelectEntry(); 319 aStr += '>'; 320 aAddrEdit.ReplaceSelected(aStr); 321 Selection aSel = aAddrEdit.GetSelection(); 322 aAddrEdit.GrabFocus(); 323 aAddrEdit.SetSelection(aSel); 324 return 0; 325 } 326 327 // -------------------------------------------------------------------------- 328 329 330 331 IMPL_LINK( SwEnvPage, SenderHdl, Button *, EMPTYARG ) 332 { 333 const sal_Bool bEnable = aSenderBox.IsChecked(); 334 GetParent()->aEnvItem.bSend = bEnable; 335 aSenderEdit.Enable(bEnable); 336 if ( bEnable ) 337 { 338 aSenderEdit.GrabFocus(); 339 if(!aSenderEdit.GetText().Len()) 340 aSenderEdit.SetText(MakeSender()); 341 } 342 aPreview.Invalidate(); 343 return 0; 344 } 345 346 // -------------------------------------------------------------------------- 347 348 349 350 void SwEnvPage::InitDatabaseBox() 351 { 352 if (pSh->GetNewDBMgr()) 353 { 354 aDatabaseLB.Clear(); 355 Sequence<OUString> aDataNames = SwNewDBMgr::GetExistingDatabaseNames(); 356 const OUString* pDataNames = aDataNames.getConstArray(); 357 for (long i = 0; i < aDataNames.getLength(); i++) 358 aDatabaseLB.InsertEntry(pDataNames[i]); 359 360 String sDBName = sActDBName.GetToken( 0, DB_DELIM ); 361 String sTableName = sActDBName.GetToken( 1, DB_DELIM ); 362 aDatabaseLB.SelectEntry(sDBName); 363 if (pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sDBName)) 364 { 365 aTableLB.SelectEntry(sTableName); 366 pSh->GetNewDBMgr()->GetColumnNames(&aDBFieldLB, sDBName, sTableName); 367 } 368 else 369 aDBFieldLB.Clear(); 370 371 } 372 } 373 374 // -------------------------------------------------------------------------- 375 376 377 378 SfxTabPage* SwEnvPage::Create(Window* pParent, const SfxItemSet& rSet) 379 { 380 return new SwEnvPage(pParent, rSet); 381 } 382 383 // -------------------------------------------------------------------------- 384 385 386 387 void SwEnvPage::ActivatePage(const SfxItemSet& rSet) 388 { 389 SfxItemSet aSet(rSet); 390 aSet.Put(GetParent()->aEnvItem); 391 Reset(aSet); 392 } 393 394 // -------------------------------------------------------------------------- 395 396 397 398 int SwEnvPage::DeactivatePage(SfxItemSet* _pSet) 399 { 400 FillItem(GetParent()->aEnvItem); 401 if( _pSet ) 402 FillItemSet(*_pSet); 403 return SfxTabPage::LEAVE_PAGE; 404 } 405 406 // -------------------------------------------------------------------------- 407 408 409 410 void SwEnvPage::FillItem(SwEnvItem& rItem) 411 { 412 rItem.aAddrText = aAddrEdit .GetText(); 413 rItem.bSend = aSenderBox .IsChecked(); 414 rItem.aSendText = aSenderEdit.GetText(); 415 } 416 417 // -------------------------------------------------------------------------- 418 419 420 421 sal_Bool SwEnvPage::FillItemSet(SfxItemSet& rSet) 422 { 423 FillItem(GetParent()->aEnvItem); 424 rSet.Put(GetParent()->aEnvItem); 425 return sal_True; 426 } 427 428 // ---------------------------------------------------------------------------- 429 430 431 432 void SwEnvPage::Reset(const SfxItemSet& rSet) 433 { 434 SwEnvItem aItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP); 435 aAddrEdit .SetText(String(aItem.aAddrText).ConvertLineEnd()); 436 aSenderEdit.SetText(String(aItem.aSendText).ConvertLineEnd()); 437 aSenderBox .Check (aItem.bSend); 438 aSenderBox.GetClickHdl().Call(&aSenderBox); 439 } 440 441 442