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 "richtextviewport.hxx"
21 #include <editeng/editview.hxx>
22 
23 namespace frm
24 {
RichTextViewPort(vcl::Window * _pParent)25     RichTextViewPort::RichTextViewPort( vcl::Window* _pParent )
26         : Control ( _pParent )
27         , m_pView(nullptr)
28         , m_bHideInactiveSelection( true )
29     {
30     }
31 
setView(EditView & _rView)32     void RichTextViewPort::setView( EditView& _rView )
33     {
34         m_pView = &_rView;
35         SetPointer( _rView.GetPointer() );
36     }
37 
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle & _rRect)38     void RichTextViewPort::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect )
39     {
40         m_pView->Paint(_rRect, &rRenderContext);
41     }
42 
GetFocus()43     void RichTextViewPort::GetFocus()
44     {
45         Control::GetFocus();
46         if (m_pView)
47         {
48             m_pView->SetSelectionMode( EESelectionMode::Std );
49             m_pView->ShowCursor();
50         }
51     }
52 
LoseFocus()53     void RichTextViewPort::LoseFocus()
54     {
55         if (m_pView)
56         {
57             m_pView->HideCursor();
58             m_pView->SetSelectionMode( m_bHideInactiveSelection ? EESelectionMode::Hidden : EESelectionMode::Std );
59         }
60         Control::LoseFocus();
61     }
62 
KeyInput(const KeyEvent & _rKEvt)63     void RichTextViewPort::KeyInput( const KeyEvent& _rKEvt )
64     {
65         if ( !m_pView->PostKeyEvent( _rKEvt ) )
66             Control::KeyInput( _rKEvt );
67         else
68             implInvalidateAttributes();
69     }
70 
MouseMove(const MouseEvent & _rMEvt)71     void RichTextViewPort::MouseMove( const MouseEvent& _rMEvt )
72     {
73         Control::MouseMove( _rMEvt );
74         m_pView->MouseMove( _rMEvt );
75     }
76 
MouseButtonDown(const MouseEvent & _rMEvt)77     void RichTextViewPort::MouseButtonDown( const MouseEvent& _rMEvt )
78     {
79         Control::MouseButtonDown( _rMEvt );
80         m_pView->MouseButtonDown( _rMEvt );
81         GrabFocus();
82     }
83 
MouseButtonUp(const MouseEvent & _rMEvt)84     void RichTextViewPort::MouseButtonUp( const MouseEvent& _rMEvt )
85     {
86         Control::MouseButtonUp( _rMEvt );
87         m_pView->MouseButtonUp( _rMEvt );
88         implInvalidateAttributes();
89     }
90 
SetHideInactiveSelection(bool _bHide)91     void RichTextViewPort::SetHideInactiveSelection( bool _bHide )
92     {
93         if ( m_bHideInactiveSelection == _bHide )
94             return;
95         m_bHideInactiveSelection = _bHide;
96         if ( !HasFocus() )
97             m_pView->SetSelectionMode( m_bHideInactiveSelection ? EESelectionMode::Hidden : EESelectionMode::Std );
98     }
99 
100 }   // namespace frm
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
103