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