1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 #include "richtextviewport.hxx"
31 #include <editeng/editview.hxx>
32 
33 //........................................................................
34 namespace frm
35 {
36 //........................................................................
37 
38 	//====================================================================
39 	//= RichTextViewPort
40 	//====================================================================
41     //--------------------------------------------------------------------
42     RichTextViewPort::RichTextViewPort( Window* _pParent )
43         :Control ( _pParent )
44         ,m_bHideInactiveSelection( true )
45     {
46     }
47 
48     //--------------------------------------------------------------------
49     void RichTextViewPort::setView( EditView& _rView )
50     {
51         m_pView = &_rView;
52         SetPointer( _rView.GetPointer() );
53     }
54 
55     //--------------------------------------------------------------------
56     void RichTextViewPort::Paint( const Rectangle& _rRect )
57     {
58         m_pView->Paint( _rRect );
59     }
60 
61     //--------------------------------------------------------------------
62     void RichTextViewPort::GetFocus()
63     {
64         Control::GetFocus();
65         m_pView->SetSelectionMode( EE_SELMODE_STD );
66         m_pView->ShowCursor( sal_True );
67     }
68 
69     //--------------------------------------------------------------------
70     void RichTextViewPort::LoseFocus()
71     {
72         m_pView->HideCursor();
73         m_pView->SetSelectionMode( m_bHideInactiveSelection ? EE_SELMODE_HIDDEN : EE_SELMODE_STD );
74         Control::LoseFocus();
75     }
76 
77     //--------------------------------------------------------------------
78     void RichTextViewPort::KeyInput( const KeyEvent& _rKEvt )
79     {
80         if ( !m_pView->PostKeyEvent( _rKEvt ) )
81             Control::KeyInput( _rKEvt );
82         else
83             implInvalidateAttributes();
84     }
85 
86     //--------------------------------------------------------------------
87     void RichTextViewPort::MouseMove( const MouseEvent& _rMEvt )
88     {
89         Control::MouseMove( _rMEvt );
90         m_pView->MouseMove( _rMEvt );
91     }
92 
93     //--------------------------------------------------------------------
94     void RichTextViewPort::MouseButtonDown( const MouseEvent& _rMEvt )
95     {
96         Control::MouseButtonDown( _rMEvt );
97         m_pView->MouseButtonDown( _rMEvt );
98         GrabFocus();
99     }
100 
101     //--------------------------------------------------------------------
102     void RichTextViewPort::MouseButtonUp( const MouseEvent& _rMEvt )
103     {
104         Control::MouseButtonUp( _rMEvt );
105         m_pView->MouseButtonUp( _rMEvt );
106         implInvalidateAttributes();
107     }
108 
109     //--------------------------------------------------------------------
110     void RichTextViewPort::SetHideInactiveSelection( bool _bHide )
111     {
112         if ( m_bHideInactiveSelection == _bHide )
113             return;
114         m_bHideInactiveSelection = _bHide;
115         if ( !HasFocus() )
116             m_pView->SetSelectionMode( m_bHideInactiveSelection ? EE_SELMODE_HIDDEN : EE_SELMODE_STD );
117     }
118 
119     //--------------------------------------------------------------------
120     bool RichTextViewPort::GetHideInactiveSelection() const
121     {
122         return m_bHideInactiveSelection;
123     }
124 
125 //........................................................................
126 }   // namespace frm
127 //........................................................................
128