xref: /aoo42x/main/sw/source/ui/docvw/edtwin2.cxx (revision b174fd2f)
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  --------------------------------------------------------------------*/
lcl_GetRedlineHelp(const SwRedline & rRedl,String & rTxt,sal_Bool bBalloon)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 
RequestHelp(const HelpEvent & rEvt)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()->IsShowContentTips())
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                     // special handling if target is a cross-reference bookmark
191                     {
192                         String sTmpSearchStr = sTxt.Copy( 1, sTxt.Len() );
193                         IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
194                         IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findBookmark( sTmpSearchStr );
195                         if ( ppBkmk != pMarkAccess->getBookmarksEnd()
196                              && IDocumentMarkAccess::GetType( *(ppBkmk->get()) ) == IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK )
197                         {
198                             SwTxtNode* pTxtNode = ppBkmk->get()->GetMarkStart().nNode.GetNode().GetTxtNode();
199                             if ( pTxtNode )
200                             {
201                                 sTxt = pTxtNode->GetExpandTxt( 0, pTxtNode->Len(), true, true );
202 
203                                 if( sTxt.Len() )
204                                 {
205                                     sTxt.EraseAllChars( 0xad );
206                                     for( sal_Unicode* p = sTxt.GetBufferAccess(); *p; ++p )
207                                     {
208                                         if( *p < 0x20 )
209                                             *p = 0x20;
210                                         else if(*p == 0x2011)
211                                             *p = '-';
212                                     }
213                                 }
214                             }
215                         }
216                     }
217 
218                     sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
219                     if ( !bExecHyperlinks )
220                     {
221                         SvtSecurityOptions aSecOpts;
222                         bExecHyperlinks = !aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
223 
224                         if ( !bExecHyperlinks )
225                         {
226                             sTxt.InsertAscii( ": ", 0 );
227                             sTxt.Insert( ViewShell::GetShellRes()->aHyperlinkClick, 0 );
228                         }
229                     }
230                     break;
231                 }
232             case SwContentAtPos::SW_SMARTTAG:
233                 {
234                     sTxt = SW_RESSTR(STR_SMARTTAG_CLICK);
235 
236                     KeyCode aCode( KEY_SPACE );
237                     KeyCode aModifiedCode( KEY_SPACE, KEY_MOD1 );
238                     String aModStr( aModifiedCode.GetName() );
239                     aModStr.SearchAndReplace( aCode.GetName(), String() );
240                     aModStr.SearchAndReplaceAllAscii( "+", String() );
241                     sTxt.SearchAndReplaceAllAscii( "%s", aModStr );
242                 }
243                 break;
244 
245             case SwContentAtPos::SW_FTN:
246                 if( aCntntAtPos.pFndTxtAttr && aCntntAtPos.aFnd.pAttr )
247                 {
248                     const SwFmtFtn* pFtn = (SwFmtFtn*)aCntntAtPos.aFnd.pAttr;
249                     pFtn->GetFtnText( sTxt );
250                     sTxt.Insert( SW_RESSTR( pFtn->IsEndNote()
251                         ? STR_ENDNOTE : STR_FTNNOTE ), 0 );
252                     if( aCntntAtPos.IsInRTLText() )
253                         nStyle |= QUICKHELP_BIDI_RTL;
254                 }
255                 break;
256 
257             case SwContentAtPos::SW_REDLINE:
258                 lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl, sTxt, bBalloon );
259                 break;
260 
261             case SwContentAtPos::SW_TOXMARK:
262                 sTxt = aCntntAtPos.sStr;
263                 if( sTxt.Len() && aCntntAtPos.pFndTxtAttr )
264                 {
265                     const SwTOXType* pTType = aCntntAtPos.pFndTxtAttr->
266                         GetTOXMark().GetTOXType();
267                     if( pTType && pTType->GetTypeName().Len() )
268                     {
269                         sTxt.InsertAscii( ": ", 0 );
270                         sTxt.Insert( pTType->GetTypeName(), 0 );
271                     }
272                 }
273                 break;
274 
275             case SwContentAtPos::SW_REFMARK:
276                 if(aCntntAtPos.aFnd.pAttr)
277                 {
278                     sTxt = SW_RES(STR_CONTENT_TYPE_SINGLE_REFERENCE);
279                     sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": "));
280                     sTxt += ((const SwFmtRefMark*)aCntntAtPos.aFnd.pAttr)->GetRefName();
281                 }
282                 break;
283 
284             default:
285                 {
286                     SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
287                     if(!pModOpt->IsHideFieldTips())
288                     {
289                         const SwField* pFld = aCntntAtPos.aFnd.pFld;
290                         switch( pFld->Which() )
291                         {
292                         case RES_SETEXPFLD:
293                         case RES_TABLEFLD:
294                         case RES_GETEXPFLD:
295                             {
296                                 sal_uInt16 nOldSubType = pFld->GetSubType();
297                                 ((SwField*)pFld)->SetSubType(nsSwExtendedSubType::SUB_CMD);
298                                 sTxt = pFld->ExpandField(true);
299                                 ((SwField*)pFld)->SetSubType(nOldSubType);
300                             }
301                             break;
302 
303                         case RES_POSTITFLD:
304                             {
305                                 break;
306                             }
307                         case RES_INPUTFLD:	// BubbleHelp, da der Hinweis ggf ziemlich lang sein kann
308                             bBalloon = sal_True;
309                             /* no break */
310                         case RES_JUMPEDITFLD:
311                             sTxt = pFld->GetPar2();
312                             break;
313 
314                         case RES_DBFLD:
315                             sTxt = pFld->GetFieldName();
316                             break;
317 
318                         case RES_USERFLD:
319                         case RES_HIDDENTXTFLD:
320                             sTxt = pFld->GetPar1();
321                             break;
322 
323                         case RES_DOCSTATFLD:
324                             break;
325 
326                         case RES_MACROFLD:
327                             sTxt = ((const SwMacroField*)pFld)->GetMacro();
328                             break;
329 
330                         case RES_GETREFFLD:
331                             {
332                                 const SwGetRefField* pRefFld( dynamic_cast<const SwGetRefField*>(pFld) );
333                                 ASSERT( pRefFld,
334                                     "<SwEditWin::RequestHelp(..)> - unexpected type of <pFld>" );
335                                 if ( pRefFld )
336                                 {
337                                     if ( pRefFld->IsRefToHeadingCrossRefBookmark() ||
338                                         pRefFld->IsRefToNumItemCrossRefBookmark() )
339                                     {
340                                         sTxt = pRefFld->GetExpandedTxtOfReferencedTxtNode();
341                                         if ( sTxt.Len() > 80  )
342                                         {
343                                             sTxt.Erase( 80 );
344                                             sTxt += '.';
345                                             sTxt += '.';
346                                             sTxt += '.';
347                                         }
348                                     }
349                                     else
350                                     {
351                                         sTxt = ((SwGetRefField*)pFld)->GetSetRefName();
352                                     }
353                                 }
354                             }
355                             break;
356                         }
357                     }
358 
359                     if( !sTxt.Len() )
360                     {
361                         aCntntAtPos.eCntntAtPos = SwContentAtPos::SW_REDLINE;
362                         if( rSh.GetContentAtPos( aPos, aCntntAtPos, sal_False, &aFldRect ) )
363                             lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl, sTxt, bBalloon );
364                     }
365                 }
366             }
367             if (sTxt.Len() )
368             {
369                 if( bBalloon )
370                     Help::ShowBalloon( this, rEvt.GetMousePosPixel(), sTxt );
371                 else
372                 {
373                     // dann zeige die Hilfe mal an:
374                     Rectangle aRect( aFldRect.SVRect() );
375                     Point aPt( OutputToScreenPixel( LogicToPixel( aRect.TopLeft() )));
376                     aRect.Left()   = aPt.X();
377                     aRect.Top()    = aPt.Y();
378                     aPt = OutputToScreenPixel( LogicToPixel( aRect.BottomRight() ));
379                     aRect.Right()  = aPt.X();
380                     aRect.Bottom() = aPt.Y();
381                     Help::ShowQuickHelp( this, aRect, sTxt, nStyle );
382                 }
383             }
384 
385             bWeiter = sal_False;
386         }
387         if( bWeiter )
388         {
389             sal_uInt8 nTabCols = rSh.WhichMouseTabCol(aPos);
390             sal_uInt16 nTabRes = 0;
391             switch(nTabCols)
392             {
393                 case SW_TABCOL_HORI:
394                 case SW_TABCOL_VERT:
395                     nTabRes = STR_TABLE_COL_ADJUST;
396                     break;
397                 case SW_TABROW_HORI:
398                 case SW_TABROW_VERT:
399                     nTabRes = STR_TABLE_ROW_ADJUST;
400                     break;
401                 case SW_TABSEL_HORI:
402                 case SW_TABSEL_HORI_RTL:
403                 case SW_TABSEL_VERT:
404                     nTabRes = STR_TABLE_SELECT_ALL;
405                     break;
406                 case SW_TABROWSEL_HORI:
407                 case SW_TABROWSEL_HORI_RTL:
408                 case SW_TABROWSEL_VERT:
409                     nTabRes = STR_TABLE_SELECT_ROW;
410                     break;
411                 case SW_TABCOLSEL_HORI:
412                 case SW_TABCOLSEL_VERT:
413                     nTabRes = STR_TABLE_SELECT_COL;
414                     break;
415             }
416             if(nTabRes)
417             {
418                 sTxt = SW_RESSTR(nTabRes);
419                 Size aTxtSize( GetTextWidth(sTxt), GetTextHeight());
420                 Rectangle aRect(rEvt.GetMousePosPixel(), aTxtSize);
421                 Help::ShowQuickHelp(this, aRect, sTxt);
422             }
423             bWeiter = sal_False;
424         }
425     }
426 
427 /*
428 aktuelle Zeichenvorlage anzeigen?
429 	if( bWeiter && rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON ))
430 	{
431 		SwCharFmt* pChrFmt = rSh.GetCurCharFmt();
432 
433 	}
434 */
435     if( bWeiter && pSdrView && bQuickBalloon)
436 	{
437 		SdrViewEvent aVEvt;
438 		SdrHitKind eHit = pSdrView->PickAnything(aPos, aVEvt);
439 		const SvxURLField *pField;
440 		SdrObject* pObj = NULL;
441 
442 		if ((pField = aVEvt.pURLField) != 0)
443 		{
444 			// URL-Feld getroffen
445 			if (pField)
446 			{
447 				pObj = aVEvt.pObj;
448 				sTxt = pField->GetURL();
449 
450 				bWeiter = sal_False;
451 			}
452 		}
453 		if (bWeiter && eHit == SDRHIT_TEXTEDIT)
454 		{
455 			// URL-Feld in zum Editieren ge?ffneten DrawText-Objekt suchen
456 			OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
457 			const SvxFieldItem* pFieldItem;
458 
459 			if (pSdrView->AreObjectsMarked())
460 			{
461 				const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
462 
463 				if (rMarkList.GetMarkCount() == 1)
464 					pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
465 			}
466 
467 			if (pObj && pObj->ISA(SdrTextObj) && pOLV &&
468 					(pFieldItem = pOLV->GetFieldUnderMousePointer()) != 0)
469 			{
470                 pField = dynamic_cast<const SvxURLField*>(pFieldItem->GetField());
471 
472                 if (pField )
473 				{
474 					sTxt = ((const SvxURLField*) pField)->GetURL();
475 					bWeiter = sal_False;
476 				}
477 			}
478 		}
479 		if (sTxt.Len() && pObj)
480 		{
481 			sTxt = URIHelper::removePassword( sTxt, INetURLObject::WAS_ENCODED,
482 			   							INetURLObject::DECODE_UNAMBIGUOUS);
483 
484 			Rectangle aLogicPix = LogicToPixel(pObj->GetLogicRect());
485 			Rectangle aScreenRect(OutputToScreenPixel(aLogicPix.TopLeft()),
486 								OutputToScreenPixel(aLogicPix.BottomRight()));
487 
488 			if (bBalloon)
489 				Help::ShowBalloon(this, rEvt.GetMousePosPixel(), aScreenRect, sTxt);
490 			else
491 				Help::ShowQuickHelp(this, aScreenRect, sTxt);
492 		}
493 	}
494 
495 	if( bWeiter )
496 		Window::RequestHelp( rEvt );
497 }
498 
PrePaint()499 void SwEditWin::PrePaint()
500 {
501 	SwWrtShell* pWrtShell = GetView().GetWrtShellPtr();
502 
503     if(pWrtShell)
504     {
505 		pWrtShell->PrePaint();
506     }
507 }
508 
Paint(const Rectangle & rRect)509 void  SwEditWin::Paint(const Rectangle& rRect)
510 {
511 #if defined(MYDEBUG)
512 	// StartUp-Statistik
513 	if ( pTickList )
514 	{
515 		SYSTICK( "Start SwEditWin::Paint" );
516 		READ_FIRST_TICKS()
517 		FLUSH_TICKS()
518 	}
519 #endif
520 
521 	SwWrtShell* pWrtShell = GetView().GetWrtShellPtr();
522 	if(!pWrtShell)
523 		return;
524 	sal_Bool bPaintShadowCrsr = sal_False;
525 	if( pShadCrsr )
526 	{
527 		Rectangle aRect( pShadCrsr->GetRect());
528 		// liegt vollstaendig drin?
529 		if( rRect.IsInside( aRect ) )
530 			// dann aufheben
531 			delete pShadCrsr, pShadCrsr = 0;
532 		else if( rRect.IsOver( aRect ))
533 		{
534 			// liegt irgendwie drueber, dann ist alles ausserhalb geclippt
535 			// und wir muessen den "inneren Teil" am Ende vom Paint
536 			// wieder sichtbar machen. Sonst kommt es zu Paintfehlern!
537 			bPaintShadowCrsr = sal_True;
538 		}
539 	}
540 /*
541     //TODO/LATER: what's the replacement for this? Do we need it?
542 	SwDocShell* pDocShell = GetView().GetDocShell();
543 
544   SvInPlaceEnvironment *pIpEnv =  pDocShell ?
545 								  pDocShell->GetIPEnv() : 0;
546 	if ( pIpEnv && pIpEnv->GetRectsChangedLockCount() )
547 		//Wir stehen in Groessenverhandlungen (MM), Paint verzoegern
548 		Invalidate( rRect );
549     else */
550     if ( GetView().GetVisArea().GetWidth()  <= 0 ||
551 			  GetView().GetVisArea().GetHeight() <= 0 )
552 		Invalidate( rRect );
553 	else
554 		pWrtShell->Paint( rRect );
555 
556 	if( bPaintShadowCrsr )
557 		pShadCrsr->Paint();
558 }
559 
560 
561