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 #include <tools/ref.hxx> 31 #include <hintids.hxx> 32 33 #include <doc.hxx> 34 #ifdef DBG_UTIL 35 #include <stdio.h> 36 #endif 37 38 #include <vcl/help.hxx> 39 #include <svl/stritem.hxx> 40 #include <unotools/securityoptions.hxx> 41 #include <tools/urlobj.hxx> 42 #include <txtrfmrk.hxx> 43 #include <fmtrfmrk.hxx> 44 #include <editeng/flditem.hxx> 45 #include <svl/urihelper.hxx> 46 #include <svx/svdotext.hxx> 47 #include <editeng/outliner.hxx> 48 #include <svl/itemiter.hxx> 49 #include <svx/svdview.hxx> 50 #include <svx/svdpagv.hxx> 51 #include <swmodule.hxx> 52 #include <modcfg.hxx> 53 #include <view.hxx> 54 #include <wrtsh.hxx> 55 #include <docsh.hxx> 56 #include <edtwin.hxx> 57 #include <dpage.hxx> 58 #include <shellres.hxx> 59 #include <docufld.hxx> 60 #include <dbfld.hxx> 61 #include <reffld.hxx> 62 #include <cellatr.hxx> 63 #include <shdwcrsr.hxx> 64 #include <fmtcol.hxx> 65 #include <charfmt.hxx> 66 #include <fmtftn.hxx> 67 #include <redline.hxx> 68 #include <tox.hxx> 69 #include <txttxmrk.hxx> 70 #include <uitool.hxx> 71 #include <viewopt.hxx> 72 #include <docvw.hrc> 73 #include <utlui.hrc> 74 75 #include <PostItMgr.hxx> 76 #include <fmtfld.hxx> 77 78 // --> OD 2009-08-18 #i104300# 79 #include <IDocumentMarkAccess.hxx> 80 #include <ndtxt.hxx> 81 // <-- 82 83 /*-------------------------------------------------------------------- 84 Beschreibung: KeyEvents 85 --------------------------------------------------------------------*/ 86 static void lcl_GetRedlineHelp( const SwRedline& rRedl, String& rTxt, sal_Bool bBalloon ) 87 { 88 sal_uInt16 nResId = 0; 89 switch( rRedl.GetType() ) 90 { 91 case nsRedlineType_t::REDLINE_INSERT: nResId = STR_REDLINE_INSERT; break; 92 case nsRedlineType_t::REDLINE_DELETE: nResId = STR_REDLINE_DELETE; break; 93 case nsRedlineType_t::REDLINE_FORMAT: nResId = STR_REDLINE_FORMAT; break; 94 case nsRedlineType_t::REDLINE_TABLE: nResId = STR_REDLINE_TABLE; break; 95 case nsRedlineType_t::REDLINE_FMTCOLL: nResId = STR_REDLINE_FMTCOLL; break; 96 } 97 98 if( nResId ) 99 { 100 rTxt = SW_RESSTR( nResId ); 101 rTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM(": " )); 102 rTxt += rRedl.GetAuthorString(); 103 rTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " )); 104 rTxt += GetAppLangDateTimeString( rRedl.GetTimeStamp() ); 105 if( bBalloon && rRedl.GetComment().Len() ) 106 ( rTxt += '\n' ) += rRedl.GetComment(); 107 } 108 } 109 110 111 void SwEditWin::RequestHelp(const HelpEvent &rEvt) 112 { 113 SwWrtShell &rSh = rView.GetWrtShell(); 114 sal_Bool bQuickBalloon = 0 != (rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON )); 115 if(bQuickBalloon && rSh.GetViewOptions()->IsPreventTips()) 116 return; 117 sal_Bool bWeiter = sal_True; 118 SET_CURR_SHELL(&rSh); 119 String sTxt; 120 Point aPos( PixelToLogic( ScreenToOutputPixel( rEvt.GetMousePosPixel() ) )); 121 sal_Bool bBalloon = static_cast< sal_Bool >(rEvt.GetMode() & HELPMODE_BALLOON); 122 123 SdrView *pSdrView = rSh.GetDrawView(); 124 125 if( bQuickBalloon ) 126 { 127 if( pSdrView ) 128 { 129 SdrPageView* pPV = pSdrView->GetSdrPageView(); 130 SwDPage* pPage = pPV ? ((SwDPage*)pPV->GetPage()) : 0; 131 bWeiter = pPage && pPage->RequestHelp(this, pSdrView, rEvt); 132 } 133 } 134 135 if( bWeiter && bQuickBalloon) 136 { 137 SwRect aFldRect; 138 sal_uInt16 nStyle = 0; // style of quick help 139 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_FIELD | 140 SwContentAtPos::SW_INETATTR | 141 SwContentAtPos::SW_FTN | 142 SwContentAtPos::SW_REDLINE | 143 SwContentAtPos::SW_TOXMARK | 144 SwContentAtPos::SW_REFMARK | 145 SwContentAtPos::SW_SMARTTAG | 146 #ifdef DBG_UTIL 147 SwContentAtPos::SW_TABLEBOXVALUE | 148 ( bBalloon ? SwContentAtPos::SW_CURR_ATTRS : 0) | 149 #endif 150 SwContentAtPos::SW_TABLEBOXFML ); 151 152 if( rSh.GetContentAtPos( aPos, aCntntAtPos, sal_False, &aFldRect ) ) 153 { 154 switch( aCntntAtPos.eCntntAtPos ) 155 { 156 case SwContentAtPos::SW_TABLEBOXFML: 157 sTxt.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "= " )); 158 sTxt += ((SwTblBoxFormula*)aCntntAtPos.aFnd.pAttr)->GetFormula(); 159 break; 160 #ifdef DBG_UTIL 161 case SwContentAtPos::SW_TABLEBOXVALUE: 162 { 163 sTxt = UniString( 164 ByteString::CreateFromDouble( 165 ((SwTblBoxValue*)aCntntAtPos.aFnd.pAttr)->GetValue() ) 166 , gsl_getSystemTextEncoding()); 167 } 168 break; 169 case SwContentAtPos::SW_CURR_ATTRS: 170 sTxt = aCntntAtPos.sStr; 171 break; 172 #endif 173 174 case SwContentAtPos::SW_INETATTR: 175 { 176 sTxt = ((SfxStringItem*)aCntntAtPos.aFnd.pAttr)->GetValue(); 177 sTxt = URIHelper::removePassword( sTxt, 178 INetURLObject::WAS_ENCODED, 179 INetURLObject::DECODE_UNAMBIGUOUS); 180 //#i63832# remove the link target type 181 xub_StrLen nFound = sTxt.Search(cMarkSeperator); 182 if( nFound != STRING_NOTFOUND && (++nFound) < sTxt.Len() ) 183 { 184 String sSuffix( sTxt.Copy(nFound) ); 185 if( sSuffix.EqualsAscii( pMarkToTable ) || 186 sSuffix.EqualsAscii( pMarkToFrame ) || 187 sSuffix.EqualsAscii( pMarkToRegion ) || 188 sSuffix.EqualsAscii( pMarkToOutline ) || 189 sSuffix.EqualsAscii( pMarkToText ) || 190 sSuffix.EqualsAscii( pMarkToGraphic ) || 191 sSuffix.EqualsAscii( pMarkToOLE )) 192 sTxt = sTxt.Copy( 0, nFound - 1); 193 } 194 // --> OD 2009-08-18 #i104300# 195 // special handling if target is a cross-reference bookmark 196 { 197 String sTmpSearchStr = sTxt.Copy( 1, sTxt.Len() ); 198 IDocumentMarkAccess* const pMarkAccess = 199 rSh.getIDocumentMarkAccess(); 200 IDocumentMarkAccess::const_iterator_t ppBkmk = 201 pMarkAccess->findBookmark( sTmpSearchStr ); 202 if ( ppBkmk != pMarkAccess->getBookmarksEnd() && 203 IDocumentMarkAccess::GetType( *(ppBkmk->get()) ) 204 == IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK ) 205 { 206 SwTxtNode* pTxtNode = ppBkmk->get()->GetMarkStart().nNode.GetNode().GetTxtNode(); 207 if ( pTxtNode ) 208 { 209 sTxt = pTxtNode->GetExpandTxt( 0, pTxtNode->Len(), true, true ); 210 211 if( sTxt.Len() ) 212 { 213 sTxt.EraseAllChars( 0xad ); 214 for( sal_Unicode* p = sTxt.GetBufferAccess(); *p; ++p ) 215 { 216 if( *p < 0x20 ) 217 *p = 0x20; 218 else if(*p == 0x2011) 219 *p = '-'; 220 } 221 } 222 } 223 } 224 } 225 // <-- 226 // --> OD 2007-07-26 #i80029# 227 sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly(); 228 if ( !bExecHyperlinks ) 229 { 230 SvtSecurityOptions aSecOpts; 231 bExecHyperlinks = !aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK ); 232 233 if ( !bExecHyperlinks ) 234 { 235 sTxt.InsertAscii( ": ", 0 ); 236 sTxt.Insert( ViewShell::GetShellRes()->aHyperlinkClick, 0 ); 237 } 238 } 239 // <-- 240 break; 241 } 242 case SwContentAtPos::SW_SMARTTAG: 243 { 244 sTxt = SW_RESSTR(STR_SMARTTAG_CLICK); 245 246 KeyCode aCode( KEY_SPACE ); 247 KeyCode aModifiedCode( KEY_SPACE, KEY_MOD1 ); 248 String aModStr( aModifiedCode.GetName() ); 249 aModStr.SearchAndReplace( aCode.GetName(), String() ); 250 aModStr.SearchAndReplaceAllAscii( "+", String() ); 251 sTxt.SearchAndReplaceAllAscii( "%s", aModStr ); 252 } 253 break; 254 255 case SwContentAtPos::SW_FTN: 256 if( aCntntAtPos.pFndTxtAttr && aCntntAtPos.aFnd.pAttr ) 257 { 258 const SwFmtFtn* pFtn = (SwFmtFtn*)aCntntAtPos.aFnd.pAttr; 259 pFtn->GetFtnText( sTxt ); 260 sTxt.Insert( SW_RESSTR( pFtn->IsEndNote() 261 ? STR_ENDNOTE : STR_FTNNOTE ), 0 ); 262 if( aCntntAtPos.IsInRTLText() ) 263 nStyle |= QUICKHELP_BIDI_RTL; 264 } 265 break; 266 267 case SwContentAtPos::SW_REDLINE: 268 lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl, sTxt, bBalloon ); 269 break; 270 271 case SwContentAtPos::SW_TOXMARK: 272 sTxt = aCntntAtPos.sStr; 273 if( sTxt.Len() && aCntntAtPos.pFndTxtAttr ) 274 { 275 const SwTOXType* pTType = aCntntAtPos.pFndTxtAttr-> 276 GetTOXMark().GetTOXType(); 277 if( pTType && pTType->GetTypeName().Len() ) 278 { 279 sTxt.InsertAscii( ": ", 0 ); 280 sTxt.Insert( pTType->GetTypeName(), 0 ); 281 } 282 } 283 break; 284 case SwContentAtPos::SW_REFMARK: 285 if(aCntntAtPos.aFnd.pAttr) 286 { 287 sTxt = SW_RES(STR_CONTENT_TYPE_SINGLE_REFERENCE); 288 sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": ")); 289 sTxt += ((const SwFmtRefMark*)aCntntAtPos.aFnd.pAttr)->GetRefName(); 290 } 291 break; 292 293 default: 294 { 295 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); 296 if(!pModOpt->IsHideFieldTips()) 297 { 298 const SwField* pFld = aCntntAtPos.aFnd.pFld; 299 switch( pFld->Which() ) 300 { 301 case RES_SETEXPFLD: 302 case RES_TABLEFLD: 303 case RES_GETEXPFLD: 304 { 305 sal_uInt16 nOldSubType = pFld->GetSubType(); 306 ((SwField*)pFld)->SetSubType(nsSwExtendedSubType::SUB_CMD); 307 sTxt = pFld->ExpandField(true); 308 ((SwField*)pFld)->SetSubType(nOldSubType); 309 } 310 break; 311 312 case RES_POSTITFLD: 313 { 314 /* 315 SwPostItMgr* pMgr = rView.GetPostItMgr(); 316 if (pMgr->ShowNotes()) 317 { 318 SwFmtFld* pSwFmtFld = 0; 319 if (pMgr->ShowPreview(pFld,pSwFmtFld)) 320 { 321 SwPostIt* pPostIt = new SwPostIt(static_cast<Window*>(this),0,pSwFmtFld,pMgr,PB_Preview); 322 pPostIt->InitControls(); 323 pPostIt->SetReadonly(true); 324 pMgr->SetColors(pPostIt,static_cast<SwPostItField*>(pSwFmtFld->GetFld())); 325 pPostIt->SetVirtualPosSize(rEvt.GetMousePosPixel(),Size(180,70)); 326 pPostIt->ShowNote(); 327 SetPointerPosPixel(pPostIt->GetPosPixel() + Point(20,20)); 328 } 329 return; 330 } 331 */ 332 break; 333 } 334 case RES_INPUTFLD: // BubbleHelp, da der Hinweis ggf ziemlich lang sein kann 335 bBalloon = sal_True; 336 /* no break */ 337 case RES_JUMPEDITFLD: 338 sTxt = pFld->GetPar2(); 339 break; 340 341 case RES_DBFLD: 342 sTxt = pFld->GetFieldName(); 343 break; 344 345 case RES_USERFLD: 346 case RES_HIDDENTXTFLD: 347 sTxt = pFld->GetPar1(); 348 break; 349 350 case RES_DOCSTATFLD: 351 break; 352 353 case RES_MACROFLD: 354 sTxt = ((const SwMacroField*)pFld)->GetMacro(); 355 break; 356 357 case RES_GETREFFLD: 358 { 359 // --> OD 2008-01-09 #i85090# 360 const SwGetRefField* pRefFld( dynamic_cast<const SwGetRefField*>(pFld) ); 361 ASSERT( pRefFld, 362 "<SwEditWin::RequestHelp(..)> - unexpected type of <pFld>" ); 363 if ( pRefFld ) 364 { 365 if ( pRefFld->IsRefToHeadingCrossRefBookmark() || 366 pRefFld->IsRefToNumItemCrossRefBookmark() ) 367 { 368 sTxt = pRefFld->GetExpandedTxtOfReferencedTxtNode(); 369 if ( sTxt.Len() > 80 ) 370 { 371 sTxt.Erase( 80 ); 372 sTxt += '.'; 373 sTxt += '.'; 374 sTxt += '.'; 375 } 376 } 377 else 378 { 379 sTxt = ((SwGetRefField*)pFld)->GetSetRefName(); 380 } 381 } 382 // <-- 383 } 384 break; 385 } 386 } 387 388 if( !sTxt.Len() ) 389 { 390 aCntntAtPos.eCntntAtPos = SwContentAtPos::SW_REDLINE; 391 if( rSh.GetContentAtPos( aPos, aCntntAtPos, sal_False, &aFldRect ) ) 392 lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl, 393 sTxt, bBalloon ); 394 } 395 } 396 } 397 if (sTxt.Len() ) 398 { 399 if( bBalloon ) 400 Help::ShowBalloon( this, rEvt.GetMousePosPixel(), sTxt ); 401 else 402 { 403 // dann zeige die Hilfe mal an: 404 Rectangle aRect( aFldRect.SVRect() ); 405 Point aPt( OutputToScreenPixel( LogicToPixel( aRect.TopLeft() ))); 406 aRect.Left() = aPt.X(); 407 aRect.Top() = aPt.Y(); 408 aPt = OutputToScreenPixel( LogicToPixel( aRect.BottomRight() )); 409 aRect.Right() = aPt.X(); 410 aRect.Bottom() = aPt.Y(); 411 Help::ShowQuickHelp( this, aRect, sTxt, nStyle ); 412 } 413 } 414 415 bWeiter = sal_False; 416 } 417 if( bWeiter ) 418 { 419 sal_uInt8 nTabCols = rSh.WhichMouseTabCol(aPos); 420 sal_uInt16 nTabRes = 0; 421 switch(nTabCols) 422 { 423 case SW_TABCOL_HORI: 424 case SW_TABCOL_VERT: 425 nTabRes = STR_TABLE_COL_ADJUST; 426 break; 427 case SW_TABROW_HORI: 428 case SW_TABROW_VERT: 429 nTabRes = STR_TABLE_ROW_ADJUST; 430 break; 431 // --> FME 2004-07-30 #i32329# Enhanced table selection 432 case SW_TABSEL_HORI: 433 case SW_TABSEL_HORI_RTL: 434 case SW_TABSEL_VERT: 435 nTabRes = STR_TABLE_SELECT_ALL; 436 break; 437 case SW_TABROWSEL_HORI: 438 case SW_TABROWSEL_HORI_RTL: 439 case SW_TABROWSEL_VERT: 440 nTabRes = STR_TABLE_SELECT_ROW; 441 break; 442 case SW_TABCOLSEL_HORI: 443 case SW_TABCOLSEL_VERT: 444 nTabRes = STR_TABLE_SELECT_COL; 445 break; 446 // <-- 447 } 448 if(nTabRes) 449 { 450 sTxt = SW_RESSTR(nTabRes); 451 Size aTxtSize( GetTextWidth(sTxt), GetTextHeight()); 452 Rectangle aRect(rEvt.GetMousePosPixel(), aTxtSize); 453 Help::ShowQuickHelp(this, aRect, sTxt); 454 } 455 bWeiter = sal_False; 456 } 457 } 458 459 /* 460 aktuelle Zeichenvorlage anzeigen? 461 if( bWeiter && rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON )) 462 { 463 SwCharFmt* pChrFmt = rSh.GetCurCharFmt(); 464 465 } 466 */ 467 if( bWeiter && pSdrView && bQuickBalloon) 468 { 469 SdrViewEvent aVEvt; 470 SdrHitKind eHit = pSdrView->PickAnything(aPos, aVEvt); 471 const SvxURLField *pField; 472 SdrObject* pObj = NULL; 473 474 if ((pField = aVEvt.pURLField) != 0) 475 { 476 // URL-Feld getroffen 477 if (pField) 478 { 479 pObj = aVEvt.pObj; 480 sTxt = pField->GetURL(); 481 482 bWeiter = sal_False; 483 } 484 } 485 if (bWeiter && eHit == SDRHIT_TEXTEDIT) 486 { 487 // URL-Feld in zum Editieren ge?ffneten DrawText-Objekt suchen 488 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView(); 489 const SvxFieldItem* pFieldItem; 490 491 if (pSdrView->AreObjectsMarked()) 492 { 493 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); 494 495 if (rMarkList.GetMarkCount() == 1) 496 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 497 } 498 499 if (pObj && pObj->ISA(SdrTextObj) && pOLV && 500 (pFieldItem = pOLV->GetFieldUnderMousePointer()) != 0) 501 { 502 pField = dynamic_cast<const SvxURLField*>(pFieldItem->GetField()); 503 504 if (pField ) 505 { 506 sTxt = ((const SvxURLField*) pField)->GetURL(); 507 bWeiter = sal_False; 508 } 509 } 510 } 511 if (sTxt.Len() && pObj) 512 { 513 sTxt = URIHelper::removePassword( sTxt, INetURLObject::WAS_ENCODED, 514 INetURLObject::DECODE_UNAMBIGUOUS); 515 516 Rectangle aLogicPix = LogicToPixel(pObj->GetLogicRect()); 517 Rectangle aScreenRect(OutputToScreenPixel(aLogicPix.TopLeft()), 518 OutputToScreenPixel(aLogicPix.BottomRight())); 519 520 if (bBalloon) 521 Help::ShowBalloon(this, rEvt.GetMousePosPixel(), aScreenRect, sTxt); 522 else 523 Help::ShowQuickHelp(this, aScreenRect, sTxt); 524 } 525 } 526 527 if( bWeiter ) 528 Window::RequestHelp( rEvt ); 529 } 530 531 void SwEditWin::PrePaint() 532 { 533 SwWrtShell* pWrtShell = GetView().GetWrtShellPtr(); 534 535 if(pWrtShell) 536 { 537 pWrtShell->PrePaint(); 538 } 539 } 540 541 void SwEditWin::Paint(const Rectangle& rRect) 542 { 543 #if defined(MYDEBUG) 544 // StartUp-Statistik 545 if ( pTickList ) 546 { 547 SYSTICK( "Start SwEditWin::Paint" ); 548 READ_FIRST_TICKS() 549 FLUSH_TICKS() 550 } 551 #endif 552 553 SwWrtShell* pWrtShell = GetView().GetWrtShellPtr(); 554 if(!pWrtShell) 555 return; 556 sal_Bool bPaintShadowCrsr = sal_False; 557 if( pShadCrsr ) 558 { 559 Rectangle aRect( pShadCrsr->GetRect()); 560 // liegt vollstaendig drin? 561 if( rRect.IsInside( aRect ) ) 562 // dann aufheben 563 delete pShadCrsr, pShadCrsr = 0; 564 else if( rRect.IsOver( aRect )) 565 { 566 // liegt irgendwie drueber, dann ist alles ausserhalb geclippt 567 // und wir muessen den "inneren Teil" am Ende vom Paint 568 // wieder sichtbar machen. Sonst kommt es zu Paintfehlern! 569 bPaintShadowCrsr = sal_True; 570 } 571 } 572 /* 573 //TODO/LATER: what's the replacement for this? Do we need it? 574 SwDocShell* pDocShell = GetView().GetDocShell(); 575 576 SvInPlaceEnvironment *pIpEnv = pDocShell ? 577 pDocShell->GetIPEnv() : 0; 578 if ( pIpEnv && pIpEnv->GetRectsChangedLockCount() ) 579 //Wir stehen in Groessenverhandlungen (MM), Paint verzoegern 580 Invalidate( rRect ); 581 else */ 582 if ( GetView().GetVisArea().GetWidth() <= 0 || 583 GetView().GetVisArea().GetHeight() <= 0 ) 584 Invalidate( rRect ); 585 else 586 pWrtShell->Paint( rRect ); 587 588 if( bPaintShadowCrsr ) 589 pShadCrsr->Paint(); 590 } 591 592 593