1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edtwin2.cxx,v $
10 * $Revision: 1.31.130.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <tools/ref.hxx>
34 #include <hintids.hxx>
41 #ifndef _HELP_HXX //autogen
42 #include <vcl/help.hxx>
44 #include <svtools/stritem.hxx>
45 #include <svtools/securityoptions.hxx>
46 #include <tools/urlobj.hxx>
47 #include <txtrfmrk.hxx>
48 #include <fmtrfmrk.hxx>
49 #include <svx/flditem.hxx>
50 #include <svtools/urihelper.hxx>
51 #include <svx/svdotext.hxx>
52 #ifndef _OUTLINER_HXX //autogen
54 #include <svx/outliner.hxx>
56 #include <svtools/itemiter.hxx>
57 #include <svx/svdview.hxx>
58 #include <svx/svdpagv.hxx>
59 #include <swmodule.hxx>
72 #include <shellres.hxx>
73 #include <docufld.hxx>
76 #include <cellatr.hxx>
77 #include <shdwcrsr.hxx>
79 #include <charfmt.hxx>
81 #include <redline.hxx>
83 #include <txttxmrk.hxx>
85 #include <viewopt.hxx>
94 #include <PostItMgr.hxx>
97 // --> OD 2009-08-18 #i104300#
98 #include <IDocumentMarkAccess.hxx>
102 /*--------------------------------------------------------------------
103 Beschreibung: KeyEvents
104 --------------------------------------------------------------------*/
105 static void lcl_GetRedlineHelp( const SwRedline
& rRedl
, String
& rTxt
, BOOL bBalloon
)
108 switch( rRedl
.GetType() )
110 case nsRedlineType_t::REDLINE_INSERT
: nResId
= STR_REDLINE_INSERT
; break;
111 case nsRedlineType_t::REDLINE_DELETE
: nResId
= STR_REDLINE_DELETE
; break;
112 case nsRedlineType_t::REDLINE_FORMAT
: nResId
= STR_REDLINE_FORMAT
; break;
113 case nsRedlineType_t::REDLINE_TABLE
: nResId
= STR_REDLINE_TABLE
; break;
114 case nsRedlineType_t::REDLINE_FMTCOLL
: nResId
= STR_REDLINE_FMTCOLL
; break;
119 rTxt
= SW_RESSTR( nResId
);
120 rTxt
.AppendAscii( RTL_CONSTASCII_STRINGPARAM(": " ));
121 rTxt
+= rRedl
.GetAuthorString();
122 rTxt
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ));
123 rTxt
+= GetAppLangDateTimeString( rRedl
.GetTimeStamp() );
124 if( bBalloon
&& rRedl
.GetComment().Len() )
125 ( rTxt
+= '\n' ) += rRedl
.GetComment();
130 void SwEditWin::RequestHelp(const HelpEvent
&rEvt
)
132 SwWrtShell
&rSh
= rView
.GetWrtShell();
133 BOOL bQuickBalloon
= 0 != (rEvt
.GetMode() & ( HELPMODE_QUICK
| HELPMODE_BALLOON
));
134 if(bQuickBalloon
&& rSh
.GetViewOptions()->IsPreventTips())
137 SET_CURR_SHELL(&rSh
);
139 Point
aPos( PixelToLogic( ScreenToOutputPixel( rEvt
.GetMousePosPixel() ) ));
140 BOOL bBalloon
= static_cast< BOOL
>(rEvt
.GetMode() & HELPMODE_BALLOON
);
142 SdrView
*pSdrView
= rSh
.GetDrawView();
148 SdrPageView
* pPV
= pSdrView
->GetSdrPageView();
149 SwDPage
* pPage
= pPV
? ((SwDPage
*)pPV
->GetPage()) : 0;
150 bWeiter
= pPage
&& pPage
->RequestHelp(this, pSdrView
, rEvt
);
154 if( bWeiter
&& bQuickBalloon
)
157 USHORT nStyle
= 0; // style of quick help
158 SwContentAtPos
aCntntAtPos( SwContentAtPos::SW_FIELD
|
159 SwContentAtPos::SW_INETATTR
|
160 SwContentAtPos::SW_FTN
|
161 SwContentAtPos::SW_REDLINE
|
162 SwContentAtPos::SW_TOXMARK
|
163 SwContentAtPos::SW_REFMARK
|
164 SwContentAtPos::SW_SMARTTAG
|
166 SwContentAtPos::SW_TABLEBOXVALUE
|
167 ( bBalloon
? SwContentAtPos::SW_CURR_ATTRS
: 0) |
169 SwContentAtPos::SW_TABLEBOXFML
);
171 if( rSh
.GetContentAtPos( aPos
, aCntntAtPos
, FALSE
, &aFldRect
) )
173 switch( aCntntAtPos
.eCntntAtPos
)
175 case SwContentAtPos::SW_TABLEBOXFML
:
176 sTxt
.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "= " ));
177 sTxt
+= ((SwTblBoxFormula
*)aCntntAtPos
.aFnd
.pAttr
)->GetFormula();
180 case SwContentAtPos::SW_TABLEBOXVALUE
:
183 ByteString::CreateFromDouble(
184 ((SwTblBoxValue
*)aCntntAtPos
.aFnd
.pAttr
)->GetValue() )
185 , gsl_getSystemTextEncoding());
188 case SwContentAtPos::SW_CURR_ATTRS
:
189 sTxt
= aCntntAtPos
.sStr
;
193 case SwContentAtPos::SW_INETATTR
:
195 sTxt
= ((SfxStringItem
*)aCntntAtPos
.aFnd
.pAttr
)->GetValue();
196 sTxt
= URIHelper::removePassword( sTxt
,
197 INetURLObject::WAS_ENCODED
,
198 INetURLObject::DECODE_UNAMBIGUOUS
);
199 //#i63832# remove the link target type
200 xub_StrLen nFound
= sTxt
.Search(cMarkSeperator
);
201 if( nFound
!= STRING_NOTFOUND
&& (++nFound
) < sTxt
.Len() )
203 String
sSuffix( sTxt
.Copy(nFound
) );
204 if( sSuffix
.EqualsAscii( pMarkToTable
) ||
205 sSuffix
.EqualsAscii( pMarkToFrame
) ||
206 sSuffix
.EqualsAscii( pMarkToRegion
) ||
207 sSuffix
.EqualsAscii( pMarkToOutline
) ||
208 sSuffix
.EqualsAscii( pMarkToText
) ||
209 sSuffix
.EqualsAscii( pMarkToGraphic
) ||
210 sSuffix
.EqualsAscii( pMarkToOLE
))
211 sTxt
= sTxt
.Copy( 0, nFound
- 1);
213 // --> OD 2009-08-18 #i104300#
214 // special handling if target is a cross-reference bookmark
216 String sTmpSearchStr
= sTxt
.Copy( 1, sTxt
.Len() );
217 IDocumentMarkAccess
* const pMarkAccess
=
218 rSh
.getIDocumentMarkAccess();
219 IDocumentMarkAccess::const_iterator_t ppBkmk
=
220 pMarkAccess
->findBookmark( sTmpSearchStr
);
221 if ( ppBkmk
!= pMarkAccess
->getBookmarksEnd() &&
222 IDocumentMarkAccess::GetType( *(ppBkmk
->get()) )
223 == IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK
)
225 SwTxtNode
* pTxtNode
= ppBkmk
->get()->GetMarkStart().nNode
.GetNode().GetTxtNode();
228 sTxt
= pTxtNode
->GetExpandTxt( 0, pTxtNode
->Len(), true, true );
232 sTxt
.EraseAllChars( 0xad );
233 for( sal_Unicode
* p
= sTxt
.GetBufferAccess(); *p
; ++p
)
237 else if(*p
== 0x2011)
245 // --> OD 2007-07-26 #i80029#
246 BOOL bExecHyperlinks
= rView
.GetDocShell()->IsReadOnly();
247 if ( !bExecHyperlinks
)
249 SvtSecurityOptions aSecOpts
;
250 bExecHyperlinks
= !aSecOpts
.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK
);
252 if ( !bExecHyperlinks
)
254 sTxt
.InsertAscii( ": ", 0 );
255 sTxt
.Insert( ViewShell::GetShellRes()->aHyperlinkClick
, 0 );
261 case SwContentAtPos::SW_SMARTTAG
:
263 sTxt
= SW_RESSTR(STR_SMARTTAG_CLICK
);
265 KeyCode
aCode( KEY_SPACE
);
266 KeyCode
aModifiedCode( KEY_SPACE
, KEY_MOD1
);
267 String
aModStr( aModifiedCode
.GetName() );
268 aModStr
.SearchAndReplace( aCode
.GetName(), String() );
269 aModStr
.SearchAndReplaceAllAscii( "+", String() );
270 sTxt
.SearchAndReplaceAllAscii( "%s", aModStr
);
274 case SwContentAtPos::SW_FTN
:
275 if( aCntntAtPos
.pFndTxtAttr
&& aCntntAtPos
.aFnd
.pAttr
)
277 const SwFmtFtn
* pFtn
= (SwFmtFtn
*)aCntntAtPos
.aFnd
.pAttr
;
278 pFtn
->GetFtnText( sTxt
);
279 sTxt
.Insert( SW_RESSTR( pFtn
->IsEndNote()
280 ? STR_ENDNOTE
: STR_FTNNOTE
), 0 );
281 if( aCntntAtPos
.IsInRTLText() )
282 nStyle
|= QUICKHELP_BIDI_RTL
;
286 case SwContentAtPos::SW_REDLINE
:
287 lcl_GetRedlineHelp( *aCntntAtPos
.aFnd
.pRedl
, sTxt
, bBalloon
);
290 case SwContentAtPos::SW_TOXMARK
:
291 sTxt
= aCntntAtPos
.sStr
;
292 if( sTxt
.Len() && aCntntAtPos
.pFndTxtAttr
)
294 const SwTOXType
* pTType
= aCntntAtPos
.pFndTxtAttr
->
295 GetTOXMark().GetTOXType();
296 if( pTType
&& pTType
->GetTypeName().Len() )
298 sTxt
.InsertAscii( ": ", 0 );
299 sTxt
.Insert( pTType
->GetTypeName(), 0 );
303 case SwContentAtPos::SW_REFMARK
:
304 if(aCntntAtPos
.aFnd
.pAttr
)
306 sTxt
= SW_RES(STR_CONTENT_TYPE_SINGLE_REFERENCE
);
307 sTxt
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": "));
308 sTxt
+= ((const SwFmtRefMark
*)aCntntAtPos
.aFnd
.pAttr
)->GetRefName();
314 SwModuleOptions
* pModOpt
= SW_MOD()->GetModuleConfig();
315 if(!pModOpt
->IsHideFieldTips())
317 const SwField
* pFld
= aCntntAtPos
.aFnd
.pFld
;
318 switch( pFld
->Which() )
324 USHORT nOldSubType
= pFld
->GetSubType();
325 ((SwField
*)pFld
)->SetSubType(nsSwExtendedSubType::SUB_CMD
);
326 sTxt
= pFld
->Expand();
327 ((SwField
*)pFld
)->SetSubType(nOldSubType
);
334 SwPostItMgr* pMgr = rView.GetPostItMgr();
335 if (pMgr->ShowNotes())
337 SwFmtFld* pSwFmtFld = 0;
338 if (pMgr->ShowPreview(pFld,pSwFmtFld))
340 SwPostIt* pPostIt = new SwPostIt(static_cast<Window*>(this),0,pSwFmtFld,pMgr,PB_Preview);
341 pPostIt->InitControls();
342 pPostIt->SetReadonly(true);
343 pMgr->SetColors(pPostIt,static_cast<SwPostItField*>(pSwFmtFld->GetFld()));
344 pPostIt->SetVirtualPosSize(rEvt.GetMousePosPixel(),Size(180,70));
346 SetPointerPosPixel(pPostIt->GetPosPixel() + Point(20,20));
353 case RES_INPUTFLD
: // BubbleHelp, da der Hinweis ggf ziemlich lang sein kann
356 case RES_JUMPEDITFLD
:
357 sTxt
= pFld
->GetPar2();
361 sTxt
= ((SwDBField
*)pFld
)->GetCntnt(TRUE
);
365 case RES_HIDDENTXTFLD
:
366 sTxt
= pFld
->GetPar1();
373 sTxt
= ((const SwMacroField
*)pFld
)->GetMacro();
378 // --> OD 2008-01-09 #i85090#
379 const SwGetRefField
* pRefFld( dynamic_cast<const SwGetRefField
*>(pFld
) );
381 "<SwEditWin::RequestHelp(..)> - unexpected type of <pFld>" );
384 if ( pRefFld
->IsRefToHeadingCrossRefBookmark() ||
385 pRefFld
->IsRefToNumItemCrossRefBookmark() )
387 sTxt
= pRefFld
->GetExpandedTxtOfReferencedTxtNode();
388 if ( sTxt
.Len() > 80 )
398 sTxt
= ((SwGetRefField
*)pFld
)->GetSetRefName();
409 aCntntAtPos
.eCntntAtPos
= SwContentAtPos::SW_REDLINE
;
410 if( rSh
.GetContentAtPos( aPos
, aCntntAtPos
, FALSE
, &aFldRect
) )
411 lcl_GetRedlineHelp( *aCntntAtPos
.aFnd
.pRedl
,
419 Help::ShowBalloon( this, rEvt
.GetMousePosPixel(), sTxt
);
422 // dann zeige die Hilfe mal an:
423 Rectangle
aRect( aFldRect
.SVRect() );
424 Point
aPt( OutputToScreenPixel( LogicToPixel( aRect
.TopLeft() )));
425 aRect
.Left() = aPt
.X();
426 aRect
.Top() = aPt
.Y();
427 aPt
= OutputToScreenPixel( LogicToPixel( aRect
.BottomRight() ));
428 aRect
.Right() = aPt
.X();
429 aRect
.Bottom() = aPt
.Y();
430 Help::ShowQuickHelp( this, aRect
, sTxt
, nStyle
);
438 BYTE nTabCols
= rSh
.WhichMouseTabCol(aPos
);
444 nTabRes
= STR_TABLE_COL_ADJUST
;
448 nTabRes
= STR_TABLE_ROW_ADJUST
;
450 // --> FME 2004-07-30 #i32329# Enhanced table selection
452 case SW_TABSEL_HORI_RTL
:
454 nTabRes
= STR_TABLE_SELECT_ALL
;
456 case SW_TABROWSEL_HORI
:
457 case SW_TABROWSEL_HORI_RTL
:
458 case SW_TABROWSEL_VERT
:
459 nTabRes
= STR_TABLE_SELECT_ROW
;
461 case SW_TABCOLSEL_HORI
:
462 case SW_TABCOLSEL_VERT
:
463 nTabRes
= STR_TABLE_SELECT_COL
;
469 sTxt
= SW_RESSTR(nTabRes
);
470 Size
aTxtSize( GetTextWidth(sTxt
), GetTextHeight());
471 Rectangle
aRect(rEvt
.GetMousePosPixel(), aTxtSize
);
472 Help::ShowQuickHelp(this, aRect
, sTxt
);
479 aktuelle Zeichenvorlage anzeigen?
480 if( bWeiter && rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON ))
482 SwCharFmt* pChrFmt = rSh.GetCurCharFmt();
486 if( bWeiter
&& pSdrView
&& bQuickBalloon
)
489 SdrHitKind eHit
= pSdrView
->PickAnything(aPos
, aVEvt
);
490 const SvxURLField
*pField
;
491 SdrObject
* pObj
= NULL
;
493 if ((pField
= aVEvt
.pURLField
) != 0)
495 // URL-Feld getroffen
499 sTxt
= pField
->GetURL();
504 if (bWeiter
&& eHit
== SDRHIT_TEXTEDIT
)
506 // URL-Feld in zum Editieren ge?ffneten DrawText-Objekt suchen
507 OutlinerView
* pOLV
= pSdrView
->GetTextEditOutlinerView();
508 const SvxFieldItem
* pFieldItem
;
510 if (pSdrView
->AreObjectsMarked())
512 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
514 if (rMarkList
.GetMarkCount() == 1)
515 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
518 if (pObj
&& pObj
->ISA(SdrTextObj
) && pOLV
&&
519 (pFieldItem
= pOLV
->GetFieldUnderMousePointer()) != 0)
521 pField
= dynamic_cast<const SvxURLField
*>(pFieldItem
->GetField());
525 sTxt
= ((const SvxURLField
*) pField
)->GetURL();
530 if (sTxt
.Len() && pObj
)
532 sTxt
= URIHelper::removePassword( sTxt
, INetURLObject::WAS_ENCODED
,
533 INetURLObject::DECODE_UNAMBIGUOUS
);
535 Rectangle aLogicPix
= LogicToPixel(pObj
->GetLogicRect());
536 Rectangle
aScreenRect(OutputToScreenPixel(aLogicPix
.TopLeft()),
537 OutputToScreenPixel(aLogicPix
.BottomRight()));
540 Help::ShowBalloon(this, rEvt
.GetMousePosPixel(), aScreenRect
, sTxt
);
542 Help::ShowQuickHelp(this, aScreenRect
, sTxt
);
547 Window::RequestHelp( rEvt
);
550 void SwEditWin::PrePaint()
552 SwWrtShell
* pWrtShell
= GetView().GetWrtShellPtr();
556 pWrtShell
->PrePaint();
560 void SwEditWin::Paint(const Rectangle
& rRect
)
566 SYSTICK( "Start SwEditWin::Paint" );
572 SwWrtShell
* pWrtShell
= GetView().GetWrtShellPtr();
575 BOOL bPaintShadowCrsr
= FALSE
;
578 Rectangle
aRect( pShadCrsr
->GetRect());
579 // liegt vollstaendig drin?
580 if( rRect
.IsInside( aRect
) )
582 delete pShadCrsr
, pShadCrsr
= 0;
583 else if( rRect
.IsOver( aRect
))
585 // liegt irgendwie drueber, dann ist alles ausserhalb geclippt
586 // und wir muessen den "inneren Teil" am Ende vom Paint
587 // wieder sichtbar machen. Sonst kommt es zu Paintfehlern!
588 bPaintShadowCrsr
= TRUE
;
592 //TODO/LATER: what's the replacement for this? Do we need it?
593 SwDocShell* pDocShell = GetView().GetDocShell();
595 SvInPlaceEnvironment *pIpEnv = pDocShell ?
596 pDocShell->GetIPEnv() : 0;
597 if ( pIpEnv && pIpEnv->GetRectsChangedLockCount() )
598 //Wir stehen in Groessenverhandlungen (MM), Paint verzoegern
601 if ( GetView().GetVisArea().GetWidth() <= 0 ||
602 GetView().GetVisArea().GetHeight() <= 0 )
605 pWrtShell
->Paint( rRect
);
607 if( bPaintShadowCrsr
)