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

Generated by: LCOV version 1.10