Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svtools/fixedhyper.hxx>
31 : :
32 : : //.........................................................................
33 : : namespace svt
34 : : {
35 : : //.........................................................................
36 : :
37 : : // class FixedHyperlink --------------------------------------------------
38 : :
39 : 0 : FixedHyperlink::FixedHyperlink( Window* pParent, const ResId& rResId ) :
40 : : ::toolkit::FixedHyperlinkBase( pParent, rResId ),
41 [ # # ][ # # ]: 0 : m_nTextLen(0)
42 : : {
43 [ # # ]: 0 : Initialize();
44 : 0 : }
45 : :
46 : 0 : FixedHyperlink::FixedHyperlink( Window* pParent, WinBits nWinStyle ) :
47 : : ::toolkit::FixedHyperlinkBase( pParent, nWinStyle ),
48 [ # # ][ # # ]: 0 : m_nTextLen(0)
49 : : {
50 [ # # ]: 0 : Initialize();
51 : 0 : }
52 : :
53 [ # # ]: 0 : FixedHyperlink::~FixedHyperlink()
54 : : {
55 [ # # ]: 0 : }
56 : :
57 : 0 : void FixedHyperlink::Initialize()
58 : : {
59 : : // saves the old pointer
60 [ # # ]: 0 : m_aOldPointer = GetPointer();
61 : : // changes the font
62 [ # # ]: 0 : Font aFont = GetControlFont( );
63 : : // to underline
64 [ # # ]: 0 : aFont.SetUnderline( UNDERLINE_SINGLE );
65 [ # # ]: 0 : SetControlFont( aFont );
66 : : // changes the color to light blue
67 [ # # ]: 0 : SetTextColor( Color( COL_LIGHTBLUE ) );
68 : : // calculates text len
69 [ # # ][ # # ]: 0 : m_nTextLen = GetCtrlTextWidth( GetText() );
[ # # ][ # # ]
70 : 0 : }
71 : :
72 : 0 : void FixedHyperlink::MouseMove( const MouseEvent& rMEvt )
73 : : {
74 : : // changes the pointer if the control is enabled and the mouse is over the text.
75 [ # # ][ # # ]: 0 : if ( !rMEvt.IsLeaveWindow() && IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
76 [ # # ]: 0 : SetPointer( POINTER_REFHAND );
77 : : else
78 : 0 : SetPointer( m_aOldPointer );
79 : 0 : }
80 : :
81 : 0 : void FixedHyperlink::MouseButtonUp( const MouseEvent& )
82 : : {
83 : : // calls the link if the control is enabled and the mouse is over the text.
84 [ # # ][ # # ]: 0 : if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
85 : 0 : ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
86 : 0 : }
87 : :
88 : 0 : void FixedHyperlink::RequestHelp( const HelpEvent& rHEvt )
89 : : {
90 [ # # ][ # # ]: 0 : if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
91 : 0 : FixedText::RequestHelp( rHEvt );
92 : 0 : }
93 : :
94 : 0 : void FixedHyperlink::GetFocus()
95 : : {
96 [ # # ]: 0 : SetTextColor( Color( COL_LIGHTRED ) );
97 [ # # ][ # # ]: 0 : Paint( Rectangle( Point(), GetSizePixel() ) );
98 [ # # ][ # # ]: 0 : ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen + 4, GetSizePixel().Height() - 2 ) ) );
99 : 0 : }
100 : :
101 : 0 : void FixedHyperlink::LoseFocus()
102 : : {
103 [ # # ]: 0 : SetTextColor( Color( COL_LIGHTBLUE ) );
104 [ # # ][ # # ]: 0 : Paint( Rectangle( Point(), GetSizePixel() ) );
105 : 0 : HideFocus();
106 : 0 : }
107 : :
108 : 0 : void FixedHyperlink::KeyInput( const KeyEvent& rKEvt )
109 : : {
110 [ # # ]: 0 : switch ( rKEvt.GetKeyCode().GetCode() )
111 : : {
112 : : case KEY_SPACE:
113 : : case KEY_RETURN:
114 : 0 : m_aClickHdl.Call( this );
115 : 0 : break;
116 : :
117 : : default:
118 : 0 : FixedText::KeyInput( rKEvt );
119 : : }
120 : 0 : }
121 : :
122 : 0 : void FixedHyperlink::SetURL( const String& rNewURL )
123 : : {
124 : 0 : m_sURL = rNewURL;
125 : 0 : SetQuickHelpText( m_sURL );
126 : 0 : }
127 : :
128 : 0 : String FixedHyperlink::GetURL() const
129 : : {
130 : 0 : return m_sURL;
131 : : }
132 : :
133 : 0 : void FixedHyperlink::SetDescription( const String& rNewDescription )
134 : : {
135 : 0 : SetText( rNewDescription );
136 [ # # ]: 0 : m_nTextLen = GetCtrlTextWidth( GetText() );
137 : 0 : }
138 : :
139 : : //.........................................................................
140 : : } // namespace svt
141 : : //.........................................................................
142 : :
143 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|