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

Generated by: LCOV version 1.10