1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "rtattributehandler.hxx"
22 #include "richtextviewport.hxx"
23 #include "richtextengine.hxx"
24 #include <svtools/scrolladaptor.hxx>
25 #include <editeng/editdata.hxx>
31 namespace vcl
{ class Window
; }
32 class SvxScriptSetItem
;
38 class ITextAttributeListener
;
39 class ITextSelectionListener
;
40 class RichTextViewPort
;
42 class RichTextControlImpl
: public IEngineStatusListener
44 typedef ::std::map
< AttributeId
, AttributeState
> StateCache
;
45 typedef ::std::map
< AttributeId
, ::rtl::Reference
< AttributeHandler
> > AttributeHandlerPool
;
46 typedef ::std::map
< AttributeId
, ITextAttributeListener
* > AttributeListenerPool
;
48 StateCache m_aLastKnownStates
;
49 AttributeHandlerPool m_aAttributeHandlers
;
50 AttributeListenerPool m_aAttributeListeners
;
52 ESelection m_aLastKnownSelection
;
54 VclPtr
<Control
> m_pAntiImpl
;
55 VclPtr
<RichTextViewPort
> m_pViewport
;
56 VclPtr
<ScrollAdaptor
> m_pHScroll
;
57 VclPtr
<ScrollAdaptor
> m_pVScroll
;
58 RichTextEngine
* m_pEngine
;
59 std::unique_ptr
<EditView
> m_pView
;
60 ITextAttributeListener
* m_pTextAttrListener
;
61 ITextSelectionListener
* m_pSelectionListener
;
62 bool m_bHasEverBeenShown
;
65 struct GrantAccess
{ friend class RichTextControl
; private: GrantAccess() { } };
66 EditView
* getView( const GrantAccess
& ) const { return m_pView
.get(); }
67 RichTextEngine
* getEngine( const GrantAccess
& ) const { return m_pEngine
; }
68 vcl::Window
* getViewport( const GrantAccess
& ) const { return m_pViewport
; }
71 RichTextControlImpl( Control
* _pAntiImpl
, RichTextEngine
* _pEngine
,
72 ITextAttributeListener
* _pTextAttrListener
, ITextSelectionListener
* _pSelectionListener
);
73 virtual ~RichTextControlImpl();
75 /** updates the cache with the state of all attribute values from the given set, notifies
76 the listener if the state changed
78 void updateAllAttributes( );
80 /** updates the cache with the state of the attribute given by which id, notifies
81 the listener if the state changed
83 void updateAttribute( AttributeId _nAttribute
);
85 /// enables the callback for a particular attribute
86 void enableAttributeNotification( AttributeId _nAttributeId
, ITextAttributeListener
* _pListener
);
88 /// disables the change notifications for a particular attribute
89 void disableAttributeNotification( AttributeId _nAttributeId
);
91 /// executes a toggle of the given attribute
92 bool executeAttribute( const SfxItemSet
& _rCurrentAttribs
, SfxItemSet
& _rNewAttribs
, AttributeId _nAttribute
, const SfxPoolItem
* _pArgument
, SvtScriptType _nForScriptType
);
94 /// retrieves the state of the given attribute from the cache
95 AttributeState
getAttributeState( AttributeId _nAttributeId
) const;
97 /** normalizes the given item so that the state of script dependent attributes
98 is correct considering the current script type
100 There are some attributes which are script dependent, e.g. the CharPosture. This means
101 that in real, there are 3 attributes for this, one for every possible script type (latin,
102 asian, complex). However, to the out world, we behave as if there is only one attribute:
103 E.g., if the outer world asks for the state of the "CharPosture" attribute, we return
104 the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
105 on the script type of the current selection. (In real, it may be more complex since
106 the current selection may contain more than one script type.)
108 This method normalizes a script dependent attribute, so that it's state takes into account
109 the currently selected script type.
111 void normalizeScriptDependentAttribute( SvxScriptSetItem
& _rScriptSetItem
);
113 // gets the script type of the selection in our edit view (with fallback)
114 SvtScriptType
getSelectedScriptType() const;
116 /** re-arranges the view and the scrollbars
120 /** to be called when the style of our window changed
122 void notifyStyleChanged();
124 /** to be called when the zoom of our window changed
126 void notifyZoomChanged();
128 /** to be called when the StateChangedType::InitShow event arrives
130 void notifyInitShow();
133 void SetBackgroundColor( );
134 void SetBackgroundColor( const Color
& _rColor
);
136 void SetReadOnly( bool _bReadOnly
);
137 bool IsReadOnly() const;
139 void SetHideInactiveSelection( bool _bHide
);
140 bool GetHideInactiveSelection() const;
142 /// draws the control onto a given output device
143 void Draw( OutputDevice
* _pDev
, const Point
& _rPos
, const Size
& _rSize
);
145 /// handles command events arrived at the anti-impl control
146 bool HandleCommand( const CommandEvent
& _rEvent
);
149 // updates the cache with the state provided by the given attribute handler
150 void implUpdateAttribute( const AttributeHandlerPool::const_iterator
& _pHandler
);
152 // updates the cache with the given state, and calls listeners (if necessary)
153 void implCheckUpdateCache( AttributeId _nAttribute
, const AttributeState
& _rState
);
155 // updates range and position of our scrollbars
156 void updateScrollbars();
158 // determines whether automatic (soft) line breaks are ON
159 bool windowHasAutomaticLineBreak();
161 /// hides or shows our scrollbars, according to the current WinBits of the window
162 void ensureScrollbars();
164 /// ensures that our "automatic line break" setting matches the current WinBits of the window
165 void ensureLineBreakSetting();
167 bool hasVScrollBar( ) const { return m_pVScroll
!= nullptr; }
168 bool hasHScrollBar( ) const { return m_pHScroll
!= nullptr; }
170 // IEngineStatusListener overridables
171 virtual void EditEngineStatusChanged( const EditStatus
& _rStatus
) override
;
174 DECL_LINK( OnInvalidateAllAttributes
, LinkParamNone
*, void );
175 DECL_LINK( OnHScroll
, weld::Scrollbar
&, void );
176 DECL_LINK( OnVScroll
, weld::Scrollbar
&, void );
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */