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