1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 #include "richtextviewport.hxx"
27 #include <editeng/editview.hxx>
28 
29 //........................................................................
30 namespace frm
31 {
32 //........................................................................
33 
34 	//====================================================================
35 	//= RichTextViewPort
36 	//====================================================================
37     //--------------------------------------------------------------------
RichTextViewPort(Window * _pParent)38     RichTextViewPort::RichTextViewPort( Window* _pParent )
39         :Control ( _pParent )
40         ,m_bHideInactiveSelection( true )
41     {
42     }
43 
44     //--------------------------------------------------------------------
setView(EditView & _rView)45     void RichTextViewPort::setView( EditView& _rView )
46     {
47         m_pView = &_rView;
48         SetPointer( _rView.GetPointer() );
49     }
50 
51     //--------------------------------------------------------------------
Paint(const Rectangle & _rRect)52     void RichTextViewPort::Paint( const Rectangle& _rRect )
53     {
54         m_pView->Paint( _rRect );
55     }
56 
57     //--------------------------------------------------------------------
GetFocus()58     void RichTextViewPort::GetFocus()
59     {
60         Control::GetFocus();
61         m_pView->SetSelectionMode( EE_SELMODE_STD );
62         m_pView->ShowCursor( sal_True );
63     }
64 
65     //--------------------------------------------------------------------
LoseFocus()66     void RichTextViewPort::LoseFocus()
67     {
68         m_pView->HideCursor();
69         m_pView->SetSelectionMode( m_bHideInactiveSelection ? EE_SELMODE_HIDDEN : EE_SELMODE_STD );
70         Control::LoseFocus();
71     }
72 
73     //--------------------------------------------------------------------
KeyInput(const KeyEvent & _rKEvt)74     void RichTextViewPort::KeyInput( const KeyEvent& _rKEvt )
75     {
76         if ( !m_pView->PostKeyEvent( _rKEvt ) )
77             Control::KeyInput( _rKEvt );
78         else
79             implInvalidateAttributes();
80     }
81 
82     //--------------------------------------------------------------------
MouseMove(const MouseEvent & _rMEvt)83     void RichTextViewPort::MouseMove( const MouseEvent& _rMEvt )
84     {
85         Control::MouseMove( _rMEvt );
86         m_pView->MouseMove( _rMEvt );
87     }
88 
89     //--------------------------------------------------------------------
MouseButtonDown(const MouseEvent & _rMEvt)90     void RichTextViewPort::MouseButtonDown( const MouseEvent& _rMEvt )
91     {
92         Control::MouseButtonDown( _rMEvt );
93         m_pView->MouseButtonDown( _rMEvt );
94         GrabFocus();
95     }
96 
97     //--------------------------------------------------------------------
MouseButtonUp(const MouseEvent & _rMEvt)98     void RichTextViewPort::MouseButtonUp( const MouseEvent& _rMEvt )
99     {
100         Control::MouseButtonUp( _rMEvt );
101         m_pView->MouseButtonUp( _rMEvt );
102         implInvalidateAttributes();
103     }
104 
105     //--------------------------------------------------------------------
SetHideInactiveSelection(bool _bHide)106     void RichTextViewPort::SetHideInactiveSelection( bool _bHide )
107     {
108         if ( m_bHideInactiveSelection == _bHide )
109             return;
110         m_bHideInactiveSelection = _bHide;
111         if ( !HasFocus() )
112             m_pView->SetSelectionMode( m_bHideInactiveSelection ? EE_SELMODE_HIDDEN : EE_SELMODE_STD );
113     }
114 
115     //--------------------------------------------------------------------
GetHideInactiveSelection() const116     bool RichTextViewPort::GetHideInactiveSelection() const
117     {
118         return m_bHideInactiveSelection;
119     }
120 
121 //........................................................................
122 }   // namespace frm
123 //........................................................................
124