LCOV - code coverage report
Current view: top level - vcl/source/control - fixedhyper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 65 1.5 %
Date: 2015-06-13 12:38:46 Functions: 2 14 14.3 %
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 <vcl/fixedhyper.hxx>
      21             : 
      22           0 : FixedHyperlink::FixedHyperlink(vcl::Window* pParent, WinBits nWinStyle)
      23             :     : FixedText(pParent, nWinStyle)
      24           0 :     , m_nTextLen(0)
      25             : {
      26           0 :     Initialize();
      27           0 : }
      28             : 
      29           0 : void FixedHyperlink::Initialize()
      30             : {
      31             :     // saves the old pointer
      32           0 :     m_aOldPointer = GetPointer();
      33             :     // changes the font
      34           0 :     vcl::Font aFont = GetControlFont( );
      35             :     // to underline
      36           0 :     aFont.SetUnderline( UNDERLINE_SINGLE );
      37           0 :     SetControlFont( aFont );
      38             :     // changes the color to light blue
      39           0 :     SetControlForeground( Color( COL_LIGHTBLUE ) );
      40             :     // calculates text len
      41           0 :     m_nTextLen = GetCtrlTextWidth( GetText() );
      42           0 : }
      43             : 
      44           0 : bool FixedHyperlink::ImplIsOverText(Point aPosition)
      45             : {
      46           0 :     Size aSize = GetOutputSizePixel();
      47             : 
      48           0 :     bool bIsOver = false;
      49             : 
      50           0 :     if (GetStyle() & WB_RIGHT)
      51             :     {
      52           0 :         return aPosition.X() > (aSize.Width() - m_nTextLen);
      53             :     }
      54           0 :     else if (GetStyle() & WB_CENTER)
      55             :     {
      56           0 :         bIsOver = aPosition.X() > (aSize.Width() / 2 - m_nTextLen / 2) &&
      57           0 :                   aPosition.X() < (aSize.Width() / 2 + m_nTextLen / 2);
      58             :     }
      59             :     else
      60             :     {
      61           0 :         bIsOver = aPosition.X() < m_nTextLen;
      62             :     }
      63             : 
      64           0 :     return bIsOver;
      65             : }
      66             : 
      67           0 : void FixedHyperlink::MouseMove( const MouseEvent& rMEvt )
      68             : {
      69             :     // changes the pointer if the control is enabled and the mouse is over the text.
      70           0 :     if ( !rMEvt.IsLeaveWindow() && IsEnabled() && ImplIsOverText(GetPointerPosPixel()) )
      71           0 :         SetPointer( PointerStyle::RefHand );
      72             :     else
      73           0 :         SetPointer( m_aOldPointer );
      74           0 : }
      75             : 
      76           0 : void FixedHyperlink::MouseButtonUp( const MouseEvent& )
      77             : {
      78             :     // calls the link if the control is enabled and the mouse is over the text.
      79           0 :     if ( IsEnabled() && ImplIsOverText(GetPointerPosPixel()) )
      80           0 :         ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
      81           0 : }
      82             : 
      83           0 : void FixedHyperlink::RequestHelp( const HelpEvent& rHEvt )
      84             : {
      85           0 :     if ( IsEnabled() && ImplIsOverText(GetPointerPosPixel()) )
      86           0 :         FixedText::RequestHelp( rHEvt );
      87           0 : }
      88             : 
      89           0 : void FixedHyperlink::GetFocus()
      90             : {
      91           0 :     SetTextColor( Color( COL_LIGHTRED ) );
      92           0 :     Invalidate(Rectangle(Point(), GetSizePixel()));
      93           0 :     ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen + 4, GetSizePixel().Height() - 2 ) ) );
      94           0 : }
      95             : 
      96           0 : void FixedHyperlink::LoseFocus()
      97             : {
      98           0 :     SetTextColor( GetControlForeground() );
      99           0 :     Invalidate(Rectangle(Point(), GetSizePixel()));
     100           0 :     HideFocus();
     101           0 : }
     102             : 
     103           0 : void FixedHyperlink::KeyInput( const KeyEvent& rKEvt )
     104             : {
     105           0 :     switch ( rKEvt.GetKeyCode().GetCode() )
     106             :     {
     107             :         case KEY_SPACE:
     108             :         case KEY_RETURN:
     109           0 :             m_aClickHdl.Call( this );
     110           0 :             break;
     111             : 
     112             :         default:
     113           0 :             FixedText::KeyInput( rKEvt );
     114             :     }
     115           0 : }
     116             : 
     117           0 : void FixedHyperlink::SetURL( const OUString& rNewURL )
     118             : {
     119           0 :     m_sURL = rNewURL;
     120           0 :     SetQuickHelpText( m_sURL );
     121           0 : }
     122             : 
     123             : 
     124           0 : void FixedHyperlink::SetText(const OUString& rNewDescription)
     125             : {
     126           0 :     FixedText::SetText(rNewDescription);
     127           0 :     m_nTextLen = GetCtrlTextWidth(GetText());
     128           0 : }
     129             : 
     130           0 : bool FixedHyperlink::set_property(const OString &rKey, const OString &rValue)
     131             : {
     132           0 :     if (rKey == "uri")
     133           0 :         SetURL(OStringToOUString(rValue, RTL_TEXTENCODING_UTF8));
     134             :     else
     135           0 :         return FixedText::set_property(rKey, rValue);
     136           0 :     return true;
     137         801 : }
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11