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