LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/docvw - SidebarTxtControl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 186 3.8 %
Date: 2012-12-17 Functions: 3 20 15.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <SidebarTxtControl.hxx>
      21             : 
      22             : #include <SidebarTxtControlAcc.hxx>
      23             : 
      24             : #include <SidebarWin.hxx>
      25             : #include <PostItMgr.hxx>
      26             : 
      27             : #include <cmdid.h>
      28             : #include <docvw.hrc>
      29             : 
      30             : #include <unotools/securityoptions.hxx>
      31             : 
      32             : #include <sfx2/viewfrm.hxx>
      33             : #include <sfx2/bindings.hxx>
      34             : #include <sfx2/dispatch.hxx>
      35             : #include <sfx2/mnumgr.hxx>
      36             : 
      37             : #include <vcl/svapp.hxx>
      38             : #include <vcl/help.hxx>
      39             : #include <vcl/msgbox.hxx>
      40             : #include <vcl/gradient.hxx>
      41             : #include <vcl/scrbar.hxx>
      42             : 
      43             : #include <editeng/outliner.hxx>
      44             : #include <editeng/editeng.hxx>
      45             : #include <editeng/editview.hxx>
      46             : #include <editeng/flditem.hxx>
      47             : 
      48             : #include <uitool.hxx>
      49             : #include <view.hxx>
      50             : #include <wrtsh.hxx>
      51             : #include <shellres.hxx>
      52             : #include <SwRewriter.hxx>
      53             : 
      54             : namespace sw { namespace sidebarwindows {
      55             : 
      56          12 : SidebarTxtControl::SidebarTxtControl( SwSidebarWin& rSidebarWin,
      57             :                                       WinBits nBits,
      58             :                                       SwView& rDocView,
      59             :                                       SwPostItMgr& rPostItMgr )
      60             :     : Control( &rSidebarWin, nBits )
      61             :     , mrSidebarWin( rSidebarWin )
      62             :     , mrDocView( rDocView )
      63          12 :     , mrPostItMgr( rPostItMgr )
      64             : {
      65          12 :     AddEventListener( LINK( &mrSidebarWin, SwSidebarWin, WindowEventListener ) );
      66          12 : }
      67             : 
      68          12 : SidebarTxtControl::~SidebarTxtControl()
      69             : {
      70           4 :     RemoveEventListener( LINK( &mrSidebarWin, SwSidebarWin, WindowEventListener ) );
      71           8 : }
      72             : 
      73           0 : OutlinerView* SidebarTxtControl::GetTextView() const
      74             : {
      75           0 :     return mrSidebarWin.GetOutlinerView();
      76             : }
      77             : 
      78           0 : void SidebarTxtControl::GetFocus()
      79             : {
      80           0 :     Window::GetFocus();
      81           0 :     if ( !mrSidebarWin.IsMouseOver() )
      82             :     {
      83           0 :         Invalidate();
      84             :     }
      85           0 : }
      86             : 
      87           0 : void SidebarTxtControl::LoseFocus()
      88             : {
      89             :     // write the visible text back into the SwField
      90           0 :     mrSidebarWin.UpdateData();
      91             : 
      92           0 :     Window::LoseFocus();
      93           0 :     if ( !mrSidebarWin.IsMouseOver() )
      94             :     {
      95           0 :         Invalidate();
      96             :     }
      97           0 : }
      98             : 
      99           0 : void SidebarTxtControl::RequestHelp(const HelpEvent &rEvt)
     100             : {
     101           0 :     sal_uInt16 nResId = 0;
     102           0 :     switch( mrSidebarWin.GetLayoutStatus() )
     103             :     {
     104           0 :         case SwPostItHelper::INSERTED:  nResId = STR_REDLINE_INSERT; break;
     105           0 :         case SwPostItHelper::DELETED:   nResId = STR_REDLINE_DELETE; break;
     106           0 :         default: nResId = 0;
     107             :     }
     108             : 
     109           0 :     SwContentAtPos aCntntAtPos( SwContentAtPos::SW_REDLINE );
     110           0 :     if ( nResId &&
     111           0 :          mrDocView.GetWrtShell().GetContentAtPos( mrSidebarWin.GetAnchorPos(), aCntntAtPos ) )
     112             :     {
     113           0 :         String sTxt;
     114           0 :         sTxt = SW_RESSTR( nResId );
     115           0 :         sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM(": " ));
     116           0 :         sTxt += aCntntAtPos.aFnd.pRedl->GetAuthorString();
     117           0 :         sTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ));
     118           0 :         sTxt += GetAppLangDateTimeString( aCntntAtPos.aFnd.pRedl->GetTimeStamp() );
     119           0 :         Help::ShowQuickHelp( this,PixelToLogic(Rectangle(rEvt.GetMousePosPixel(),Size(50,10))),sTxt);
     120           0 :     }
     121           0 : }
     122             : 
     123           0 : void SidebarTxtControl::Paint( const Rectangle& rRect)
     124             : {
     125           0 :     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
     126             :     {
     127           0 :         if ( mrSidebarWin.IsMouseOverSidebarWin() ||
     128           0 :              HasFocus() )
     129             :         {
     130           0 :             DrawGradient( Rectangle( Point(0,0), PixelToLogic(GetSizePixel()) ),
     131             :                           Gradient( GradientStyle_LINEAR,
     132           0 :                                     mrSidebarWin.ColorDark(),
     133           0 :                                     mrSidebarWin.ColorDark() ) );
     134             :         }
     135             :         else
     136             :         {
     137           0 :             DrawGradient( Rectangle( Point(0,0), PixelToLogic(GetSizePixel()) ),
     138             :                           Gradient( GradientStyle_LINEAR,
     139           0 :                                     mrSidebarWin.ColorLight(),
     140           0 :                                     mrSidebarWin.ColorDark()));
     141             :         }
     142             :     }
     143             : 
     144           0 :     if ( GetTextView() )
     145             :     {
     146           0 :         GetTextView()->Paint( rRect );
     147             :     }
     148             : 
     149           0 :     if ( mrSidebarWin.GetLayoutStatus()==SwPostItHelper::DELETED )
     150             :     {
     151           0 :         SetLineColor(mrSidebarWin.GetChangeColor());
     152           0 :         DrawLine( PixelToLogic( GetPosPixel() ),
     153           0 :                   PixelToLogic( GetPosPixel() +
     154           0 :                                 Point( GetSizePixel().Width(),
     155           0 :                                        GetSizePixel().Height() ) ) );
     156           0 :         DrawLine( PixelToLogic( GetPosPixel() +
     157           0 :                                 Point( GetSizePixel().Width(),0) ),
     158           0 :                   PixelToLogic( GetPosPixel() +
     159           0 :                                 Point( 0, GetSizePixel().Height() ) ) );
     160             :     }
     161           0 : }
     162             : 
     163           0 : void SidebarTxtControl::KeyInput( const KeyEvent& rKeyEvt )
     164             : {
     165           0 :     const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
     166           0 :     sal_uInt16 nKey = rKeyCode.GetCode();
     167           0 :     if ( ( rKeyCode.IsMod1() && rKeyCode.IsMod2() ) &&
     168             :          ( (nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN) ) )
     169             :     {
     170           0 :         mrSidebarWin.SwitchToPostIt(nKey);
     171             :     }
     172           0 :     else if ( nKey == KEY_ESCAPE ||
     173           0 :               ( rKeyCode.IsMod1() &&
     174             :                 ( nKey == KEY_PAGEUP ||
     175             :                   nKey == KEY_PAGEDOWN ) ) )
     176             :     {
     177           0 :         mrSidebarWin.SwitchToFieldPos();
     178             :     }
     179           0 :     else if ( nKey == KEY_INSERT )
     180             :     {
     181           0 :         if ( !rKeyCode.IsMod1() && !rKeyCode.IsMod2() )
     182             :         {
     183           0 :             mrSidebarWin.ToggleInsMode();
     184             :         }
     185             :     }
     186             :     else
     187             :     {
     188             :         //let's make sure we see our note
     189           0 :         mrPostItMgr.MakeVisible(&mrSidebarWin);
     190             : 
     191           0 :         long aOldHeight = mrSidebarWin.GetPostItTextHeight();
     192           0 :         bool bDone = false;
     193             : 
     194             :         /// HACK: need to switch off processing of Undo/Redo in Outliner
     195           0 :         if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
     196             :         {
     197           0 :             bool bIsProtected = mrSidebarWin.IsProtected();
     198           0 :             if ( !bIsProtected ||
     199             :                  ( bIsProtected &&
     200           0 :                    !mrSidebarWin.GetOutlinerView()->GetOutliner()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) )
     201             :             {
     202           0 :                 bDone = GetTextView() && GetTextView()->PostKeyEvent( rKeyEvt );
     203             :             }
     204             :             else
     205             :             {
     206           0 :                 InfoBox( this, SW_RES( MSG_READONLY_CONTENT )).Execute();
     207             :             }
     208             :         }
     209           0 :         if (bDone)
     210           0 :             mrSidebarWin.ResizeIfNeccessary( aOldHeight, mrSidebarWin.GetPostItTextHeight() );
     211             :         else
     212             :         {
     213             :             // write back data first when showing navigator
     214           0 :             if ( nKey==KEY_F5 )
     215           0 :                 mrSidebarWin.UpdateData();
     216           0 :             if (!mrDocView.KeyInput(rKeyEvt))
     217           0 :                 Window::KeyInput(rKeyEvt);
     218             :         }
     219             :     }
     220             : 
     221           0 :     mrDocView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
     222           0 : }
     223             : 
     224           0 : void SidebarTxtControl::MouseMove( const MouseEvent& rMEvt )
     225             : {
     226           0 :     if ( GetTextView() )
     227             :     {
     228           0 :         OutlinerView* pOutlinerView( GetTextView() );
     229           0 :         pOutlinerView->MouseMove( rMEvt );
     230             :         // mba: why does OutlinerView not handle the modifier setting?!
     231             :         // this forces the postit to handle *all* pointer types
     232           0 :         SetPointer( pOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
     233             : 
     234           0 :         const EditView& aEV = pOutlinerView->GetEditView();
     235           0 :         const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
     236           0 :         if ( pItem )
     237             :         {
     238           0 :             const SvxFieldData* pFld = pItem->GetField();
     239           0 :             const SvxURLField* pURL = PTR_CAST( SvxURLField, pFld );
     240           0 :             if ( pURL )
     241             :             {
     242           0 :                 String sURL( pURL->GetURL() );
     243           0 :                 SvtSecurityOptions aSecOpts;
     244           0 :                 if ( aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK) )
     245             :                 {
     246           0 :                     sURL.InsertAscii( ": ", 0 );
     247           0 :                     sURL.Insert( ViewShell::GetShellRes()->aHyperlinkClick, 0 );
     248             :                 }
     249           0 :                 Help::ShowQuickHelp( this,PixelToLogic(Rectangle(GetPosPixel(),Size(50,10))),sURL);
     250             :             }
     251             :         }
     252             :     }
     253           0 : }
     254             : 
     255           0 : void SidebarTxtControl::MouseButtonDown( const MouseEvent& rMEvt )
     256             : {
     257           0 :     if ( GetTextView() )
     258             :     {
     259           0 :         SvtSecurityOptions aSecOpts;
     260           0 :         bool bExecuteMod = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK);
     261             : 
     262           0 :         if ( !bExecuteMod || (bExecuteMod && rMEvt.GetModifier() == KEY_MOD1))
     263             :         {
     264           0 :             const EditView& aEV = GetTextView()->GetEditView();
     265           0 :             const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
     266           0 :             if ( pItem )
     267             :             {
     268           0 :                 const SvxFieldData* pFld = pItem->GetField();
     269           0 :                 const SvxURLField* pURL = PTR_CAST( SvxURLField, pFld );
     270           0 :                 if ( pURL )
     271             :                 {
     272           0 :                     GetTextView()->MouseButtonDown( rMEvt );
     273           0 :                     SwWrtShell &rSh = mrDocView.GetWrtShell();
     274           0 :                     String sURL( pURL->GetURL() );
     275           0 :                     String sTarget( pURL->GetTargetFrame() );
     276           0 :                     ::LoadURL(rSh, sURL, URLLOAD_NOFILTER, sTarget);
     277           0 :                     return;
     278             :                 }
     279             :             }
     280           0 :         }
     281             :     }
     282             : 
     283           0 :     GrabFocus();
     284           0 :     if ( GetTextView() )
     285             :     {
     286           0 :         GetTextView()->MouseButtonDown( rMEvt );
     287             :     }
     288           0 :     mrDocView.GetViewFrame()->GetBindings().InvalidateAll(sal_False);
     289             : }
     290             : 
     291           0 : void SidebarTxtControl::MouseButtonUp( const MouseEvent& rMEvt )
     292             : {
     293           0 :     if ( GetTextView() )
     294           0 :         GetTextView()->MouseButtonUp( rMEvt );
     295           0 : }
     296             : 
     297           0 : IMPL_LINK( SidebarTxtControl, OnlineSpellCallback, SpellCallbackInfo*, pInfo )
     298             : {
     299           0 :     if ( pInfo->nCommand == SPELLCMD_STARTSPELLDLG )
     300             :     {
     301           0 :         mrDocView.GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON);
     302             :     }
     303           0 :     return 0;
     304             : }
     305             : 
     306           0 : IMPL_LINK( SidebarTxtControl, Select, Menu*, pSelMenu )
     307             : {
     308           0 :     mrSidebarWin.ExecuteCommand( pSelMenu->GetCurItemId() );
     309           0 :     return 0;
     310             : }
     311             : 
     312           0 : void SidebarTxtControl::Command( const CommandEvent& rCEvt )
     313             : {
     314           0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
     315             :     {
     316           0 :         if ( !mrSidebarWin.IsProtected() &&
     317           0 :              GetTextView() &&
     318           0 :              GetTextView()->IsWrongSpelledWordAtPos( rCEvt.GetMousePosPixel(),sal_True ))
     319             :         {
     320           0 :             Link aLink = LINK(this, SidebarTxtControl, OnlineSpellCallback);
     321           0 :             GetTextView()->ExecuteSpellPopup(rCEvt.GetMousePosPixel(),&aLink);
     322             :         }
     323             :         else
     324             :         {
     325           0 :             SfxPopupMenuManager* pMgr = mrDocView.GetViewFrame()->GetDispatcher()->Popup(0, this,&rCEvt.GetMousePosPixel());
     326           0 :             ((PopupMenu*)pMgr->GetSVMenu())->SetSelectHdl( LINK(this, SidebarTxtControl, Select) );
     327             : 
     328             :             {
     329           0 :                 XubString aText = ((PopupMenu*)pMgr->GetSVMenu())->GetItemText( FN_DELETE_NOTE_AUTHOR );
     330           0 :                 SwRewriter aRewriter;
     331           0 :                 aRewriter.AddRule(UndoArg1, mrSidebarWin.GetAuthor());
     332           0 :                 aText = aRewriter.Apply(aText);
     333           0 :                 ((PopupMenu*)pMgr->GetSVMenu())->SetItemText(FN_DELETE_NOTE_AUTHOR,aText);
     334             :             }
     335             : 
     336           0 :             Point aPos;
     337           0 :             if (rCEvt.IsMouseEvent())
     338           0 :                 aPos = rCEvt.GetMousePosPixel();
     339             :             else
     340             :             {
     341           0 :                 const Size aSize = GetSizePixel();
     342           0 :                 aPos = Point( aSize.getWidth()/2, aSize.getHeight()/2 );
     343             :             }
     344             : 
     345             :             //!! call different Execute function to get rid of the new thesaurus sub menu
     346             :             //!! pointer created in the call to Popup.
     347             :             //!! Otherwise we would have a memory leak (see also #i107205#)
     348           0 :             pMgr->Execute( aPos, this );
     349           0 :             delete pMgr;
     350             :         }
     351             :     }
     352             :     else
     353           0 :     if (rCEvt.GetCommand() == COMMAND_WHEEL)
     354             :     {
     355           0 :         if (mrSidebarWin.IsScrollbarVisible())
     356             :         {
     357           0 :             const CommandWheelData* pData = rCEvt.GetWheelData();
     358           0 :             if (pData->IsShift() || pData->IsMod1() || pData->IsMod2())
     359             :             {
     360           0 :                 mrDocView.HandleWheelCommands(rCEvt);
     361             :             }
     362             :             else
     363             :             {
     364           0 :                 HandleScrollCommand( rCEvt, 0 , mrSidebarWin.Scrollbar());
     365             :             }
     366             :         }
     367             :         else
     368             :         {
     369           0 :             mrDocView.HandleWheelCommands(rCEvt);
     370             :         }
     371             :     }
     372             :     else
     373             :     {
     374           0 :         if ( GetTextView() )
     375           0 :             GetTextView()->Command( rCEvt );
     376             :         else
     377           0 :             Window::Command(rCEvt);
     378             :     }
     379           0 : }
     380             : 
     381           0 : rtl::OUString SidebarTxtControl::GetSurroundingText() const
     382             : {
     383           0 :     if (GetTextView())
     384           0 :         return GetTextView()->GetSurroundingText();
     385           0 :     return rtl::OUString();
     386             : }
     387             : 
     388           0 : Selection SidebarTxtControl::GetSurroundingTextSelection() const
     389             : {
     390           0 :     if( GetTextView() )
     391           0 :         return GetTextView()->GetSurroundingTextSelection();
     392             :     else
     393           0 :         return Selection( 0, 0 );
     394             : }
     395             : 
     396           0 : css::uno::Reference< css::accessibility::XAccessible > SidebarTxtControl::CreateAccessible()
     397             : {
     398             : 
     399           0 :     SidebarTxtControlAccessible* pAcc( new SidebarTxtControlAccessible( *this ) );
     400           0 :     css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
     401           0 :     SetWindowPeer( xWinPeer, pAcc );
     402             : 
     403           0 :     css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
     404           0 :     return xAcc;
     405             : }
     406             : 
     407             : } } // end of namespace sw::sidebarwindows
     408             : 
     409             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10