update dev300-m58
[ooovba.git] / sw / source / ui / docvw / edtwin2.cxx
blobb277c13949111b5ecf1298d46bf6ed683d23c5a3
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>
36 #include <doc.hxx>
37 #ifndef PRODUCT
38 #include <stdio.h>
39 #endif
41 #ifndef _HELP_HXX //autogen
42 #include <vcl/help.hxx>
43 #endif
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
53 #define _EEITEMID_HXX
54 #include <svx/outliner.hxx>
55 #endif
56 #include <svtools/itemiter.hxx>
57 #include <svx/svdview.hxx>
58 #include <svx/svdpagv.hxx>
59 #include <swmodule.hxx>
60 #ifndef _MODCFG_HXX
61 #include <modcfg.hxx>
62 #endif
63 #ifndef _VIEW_HXX
64 #include <view.hxx>
65 #endif
66 #include <wrtsh.hxx>
67 #ifndef _DOCSH_HXX
68 #include <docsh.hxx>
69 #endif
70 #include <edtwin.hxx>
71 #include <dpage.hxx>
72 #include <shellres.hxx>
73 #include <docufld.hxx>
74 #include <dbfld.hxx>
75 #include <reffld.hxx>
76 #include <cellatr.hxx>
77 #include <shdwcrsr.hxx>
78 #include <fmtcol.hxx>
79 #include <charfmt.hxx>
80 #include <fmtftn.hxx>
81 #include <redline.hxx>
82 #include <tox.hxx>
83 #include <txttxmrk.hxx>
84 #include <uitool.hxx>
85 #include <viewopt.hxx>
86 #ifndef _DOCVW_HRC
87 #include <docvw.hrc>
88 #endif
89 #ifndef _UTLUI_HRC
90 #include <utlui.hrc>
91 #endif
93 #include <postit.hxx>
94 #include <PostItMgr.hxx>
95 #include <fmtfld.hxx>
97 // --> OD 2009-08-18 #i104300#
98 #include <IDocumentMarkAccess.hxx>
99 #include <ndtxt.hxx>
100 // <--
102 /*--------------------------------------------------------------------
103 Beschreibung: KeyEvents
104 --------------------------------------------------------------------*/
105 static void lcl_GetRedlineHelp( const SwRedline& rRedl, String& rTxt, BOOL bBalloon )
107 USHORT nResId = 0;
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;
117 if( nResId )
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())
135 return;
136 BOOL bWeiter = TRUE;
137 SET_CURR_SHELL(&rSh);
138 String sTxt;
139 Point aPos( PixelToLogic( ScreenToOutputPixel( rEvt.GetMousePosPixel() ) ));
140 BOOL bBalloon = static_cast< BOOL >(rEvt.GetMode() & HELPMODE_BALLOON);
142 SdrView *pSdrView = rSh.GetDrawView();
144 if( bQuickBalloon )
146 if( pSdrView )
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)
156 SwRect aFldRect;
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 |
165 #ifndef PRODUCT
166 SwContentAtPos::SW_TABLEBOXVALUE |
167 ( bBalloon ? SwContentAtPos::SW_CURR_ATTRS : 0) |
168 #endif
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();
178 break;
179 #ifndef PRODUCT
180 case SwContentAtPos::SW_TABLEBOXVALUE:
182 sTxt = UniString(
183 ByteString::CreateFromDouble(
184 ((SwTblBoxValue*)aCntntAtPos.aFnd.pAttr)->GetValue() )
185 , gsl_getSystemTextEncoding());
187 break;
188 case SwContentAtPos::SW_CURR_ATTRS:
189 sTxt = aCntntAtPos.sStr;
190 break;
191 #endif
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();
226 if ( pTxtNode )
228 sTxt = pTxtNode->GetExpandTxt( 0, pTxtNode->Len(), true, true );
230 if( sTxt.Len() )
232 sTxt.EraseAllChars( 0xad );
233 for( sal_Unicode* p = sTxt.GetBufferAccess(); *p; ++p )
235 if( *p < 0x20 )
236 *p = 0x20;
237 else if(*p == 0x2011)
238 *p = '-';
244 // <--
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 );
258 // <--
259 break;
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 );
272 break;
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;
284 break;
286 case SwContentAtPos::SW_REDLINE:
287 lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl, sTxt, bBalloon );
288 break;
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 );
302 break;
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();
310 break;
312 default:
314 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
315 if(!pModOpt->IsHideFieldTips())
317 const SwField* pFld = aCntntAtPos.aFnd.pFld;
318 switch( pFld->Which() )
320 case RES_SETEXPFLD:
321 case RES_TABLEFLD:
322 case RES_GETEXPFLD:
324 USHORT nOldSubType = pFld->GetSubType();
325 ((SwField*)pFld)->SetSubType(nsSwExtendedSubType::SUB_CMD);
326 sTxt = pFld->Expand();
327 ((SwField*)pFld)->SetSubType(nOldSubType);
329 break;
331 case RES_POSTITFLD:
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));
345 pPostIt->ShowNote();
346 SetPointerPosPixel(pPostIt->GetPosPixel() + Point(20,20));
348 return;
351 break;
353 case RES_INPUTFLD: // BubbleHelp, da der Hinweis ggf ziemlich lang sein kann
354 bBalloon = TRUE;
355 /* no break */
356 case RES_JUMPEDITFLD:
357 sTxt = pFld->GetPar2();
358 break;
360 case RES_DBFLD:
361 sTxt = ((SwDBField*)pFld)->GetCntnt(TRUE);
362 break;
364 case RES_USERFLD:
365 case RES_HIDDENTXTFLD:
366 sTxt = pFld->GetPar1();
367 break;
369 case RES_DOCSTATFLD:
370 break;
372 case RES_MACROFLD:
373 sTxt = ((const SwMacroField*)pFld)->GetMacro();
374 break;
376 case RES_GETREFFLD:
378 // --> OD 2008-01-09 #i85090#
379 const SwGetRefField* pRefFld( dynamic_cast<const SwGetRefField*>(pFld) );
380 ASSERT( pRefFld,
381 "<SwEditWin::RequestHelp(..)> - unexpected type of <pFld>" );
382 if ( pRefFld )
384 if ( pRefFld->IsRefToHeadingCrossRefBookmark() ||
385 pRefFld->IsRefToNumItemCrossRefBookmark() )
387 sTxt = pRefFld->GetExpandedTxtOfReferencedTxtNode();
388 if ( sTxt.Len() > 80 )
390 sTxt.Erase( 80 );
391 sTxt += '.';
392 sTxt += '.';
393 sTxt += '.';
396 else
398 sTxt = ((SwGetRefField*)pFld)->GetSetRefName();
401 // <--
403 break;
407 if( !sTxt.Len() )
409 aCntntAtPos.eCntntAtPos = SwContentAtPos::SW_REDLINE;
410 if( rSh.GetContentAtPos( aPos, aCntntAtPos, FALSE, &aFldRect ) )
411 lcl_GetRedlineHelp( *aCntntAtPos.aFnd.pRedl,
412 sTxt, bBalloon );
416 if (sTxt.Len() )
418 if( bBalloon )
419 Help::ShowBalloon( this, rEvt.GetMousePosPixel(), sTxt );
420 else
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 );
434 bWeiter = FALSE;
436 if( bWeiter )
438 BYTE nTabCols = rSh.WhichMouseTabCol(aPos);
439 USHORT nTabRes = 0;
440 switch(nTabCols)
442 case SW_TABCOL_HORI:
443 case SW_TABCOL_VERT:
444 nTabRes = STR_TABLE_COL_ADJUST;
445 break;
446 case SW_TABROW_HORI:
447 case SW_TABROW_VERT:
448 nTabRes = STR_TABLE_ROW_ADJUST;
449 break;
450 // --> FME 2004-07-30 #i32329# Enhanced table selection
451 case SW_TABSEL_HORI:
452 case SW_TABSEL_HORI_RTL:
453 case SW_TABSEL_VERT:
454 nTabRes = STR_TABLE_SELECT_ALL;
455 break;
456 case SW_TABROWSEL_HORI:
457 case SW_TABROWSEL_HORI_RTL:
458 case SW_TABROWSEL_VERT:
459 nTabRes = STR_TABLE_SELECT_ROW;
460 break;
461 case SW_TABCOLSEL_HORI:
462 case SW_TABCOLSEL_VERT:
463 nTabRes = STR_TABLE_SELECT_COL;
464 break;
465 // <--
467 if(nTabRes)
469 sTxt = SW_RESSTR(nTabRes);
470 Size aTxtSize( GetTextWidth(sTxt), GetTextHeight());
471 Rectangle aRect(rEvt.GetMousePosPixel(), aTxtSize);
472 Help::ShowQuickHelp(this, aRect, sTxt);
474 bWeiter = FALSE;
479 aktuelle Zeichenvorlage anzeigen?
480 if( bWeiter && rEvt.GetMode() & ( HELPMODE_QUICK | HELPMODE_BALLOON ))
482 SwCharFmt* pChrFmt = rSh.GetCurCharFmt();
486 if( bWeiter && pSdrView && bQuickBalloon)
488 SdrViewEvent aVEvt;
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
496 if (pField)
498 pObj = aVEvt.pObj;
499 sTxt = pField->GetURL();
501 bWeiter = FALSE;
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());
523 if (pField )
525 sTxt = ((const SvxURLField*) pField)->GetURL();
526 bWeiter = FALSE;
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()));
539 if (bBalloon)
540 Help::ShowBalloon(this, rEvt.GetMousePosPixel(), aScreenRect, sTxt);
541 else
542 Help::ShowQuickHelp(this, aScreenRect, sTxt);
546 if( bWeiter )
547 Window::RequestHelp( rEvt );
550 void SwEditWin::PrePaint()
552 SwWrtShell* pWrtShell = GetView().GetWrtShellPtr();
554 if(pWrtShell)
556 pWrtShell->PrePaint();
560 void SwEditWin::Paint(const Rectangle& rRect)
562 #if defined(MYDEBUG)
563 // StartUp-Statistik
564 if ( pTickList )
566 SYSTICK( "Start SwEditWin::Paint" );
567 READ_FIRST_TICKS()
568 FLUSH_TICKS()
570 #endif
572 SwWrtShell* pWrtShell = GetView().GetWrtShellPtr();
573 if(!pWrtShell)
574 return;
575 BOOL bPaintShadowCrsr = FALSE;
576 if( pShadCrsr )
578 Rectangle aRect( pShadCrsr->GetRect());
579 // liegt vollstaendig drin?
580 if( rRect.IsInside( aRect ) )
581 // dann aufheben
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
599 Invalidate( rRect );
600 else */
601 if ( GetView().GetVisArea().GetWidth() <= 0 ||
602 GetView().GetVisArea().GetHeight() <= 0 )
603 Invalidate( rRect );
604 else
605 pWrtShell->Paint( rRect );
607 if( bPaintShadowCrsr )
608 pShadCrsr->Paint();