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 <vcl/scrbar.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
<ScrollBar
> m_pHScroll
;
57 VclPtr
<ScrollBar
> m_pVScroll
;
58 VclPtr
<ScrollBarBox
> m_pScrollCorner
;
59 RichTextEngine
* m_pEngine
;
60 std::unique_ptr
<EditView
> m_pView
;
61 ITextAttributeListener
* m_pTextAttrListener
;
62 ITextSelectionListener
* m_pSelectionListener
;
63 bool m_bHasEverBeenShown
;
66 struct GrantAccess
{ friend class RichTextControl
; private: GrantAccess() { } };
67 EditView
* getView( const GrantAccess
& ) const { return m_pView
.get(); }
68 RichTextEngine
* getEngine( const GrantAccess
& ) const { return m_pEngine
; }
69 vcl::Window
* getViewport( const GrantAccess
& ) const { return m_pViewport
; }
72 RichTextControlImpl( Control
* _pAntiImpl
, RichTextEngine
* _pEngine
,
73 ITextAttributeListener
* _pTextAttrListener
, ITextSelectionListener
* _pSelectionListener
);
74 virtual ~RichTextControlImpl();
76 /** updates the cache with the state of all attribute values from the given set, notifies
77 the listener if the state changed
79 void updateAllAttributes( );
81 /** updates the cache with the state of the attribute given by which id, notifies
82 the listener if the state changed
84 void updateAttribute( AttributeId _nAttribute
);
86 /// enables the callback for a particular attribute
87 void enableAttributeNotification( AttributeId _nAttributeId
, ITextAttributeListener
* _pListener
);
89 /// disables the change notifications for a particular attribute
90 void disableAttributeNotification( AttributeId _nAttributeId
);
92 /// executes a toggle of the given attribute
93 bool executeAttribute( const SfxItemSet
& _rCurrentAttribs
, SfxItemSet
& _rNewAttribs
, AttributeId _nAttribute
, const SfxPoolItem
* _pArgument
, SvtScriptType _nForScriptType
);
95 /// retrieves the state of the given attribute from the cache
96 AttributeState
getAttributeState( AttributeId _nAttributeId
) const;
98 /** normalizes the given item so that the state of script dependent attributes
99 is correct considering the current script type
101 There are some attributes which are script dependent, e.g. the CharPosture. This means
102 that in real, there are 3 attributes for this, one for every possible script type (latin,
103 asian, complex). However, to the out world, we behave as if there is only one attribute:
104 E.g., if the outer world asks for the state of the "CharPosture" attribute, we return
105 the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
106 on the script type of the current selection. (In real, it may be more complex since
107 the current selection may contain more than one script type.)
109 This method normalizes a script dependent attribute, so that it's state takes into account
110 the currently selected script type.
112 void normalizeScriptDependentAttribute( SvxScriptSetItem
& _rScriptSetItem
);
114 // gets the script type of the selection in our edit view (with fallback)
115 SvtScriptType
getSelectedScriptType() const;
117 /** re-arranges the view and the scrollbars
121 /** to be called when the style of our window changed
123 void notifyStyleChanged();
125 /** to be called when the zoom of our window changed
127 void notifyZoomChanged();
129 /** to be called when the StateChangedType::InitShow event arrives
131 void notifyInitShow();
134 void SetBackgroundColor( );
135 void SetBackgroundColor( const Color
& _rColor
);
137 void SetReadOnly( bool _bReadOnly
);
138 bool IsReadOnly() const;
140 void SetHideInactiveSelection( bool _bHide
);
141 bool GetHideInactiveSelection() const;
143 /// draws the control onto a given output device
144 void Draw( OutputDevice
* _pDev
, const Point
& _rPos
, const Size
& _rSize
);
146 /// handles command events arrived at the anti-impl control
147 bool HandleCommand( const CommandEvent
& _rEvent
);
150 // updates the cache with the state provided by the given attribute handler
151 void implUpdateAttribute( const AttributeHandlerPool::const_iterator
& _pHandler
);
153 // updates the cache with the given state, and calls listeners (if necessary)
154 void implCheckUpdateCache( AttributeId _nAttribute
, const AttributeState
& _rState
);
156 // updates range and position of our scrollbars
157 void updateScrollbars();
159 // determines whether automatic (soft) line breaks are ON
160 bool windowHasAutomaticLineBreak();
162 /// hides or shows our scrollbars, according to the current WinBits of the window
163 void ensureScrollbars();
165 /// ensures that our "automatic line break" setting matches the current WinBits of the window
166 void ensureLineBreakSetting();
168 bool hasVScrollBar( ) const { return m_pVScroll
!= nullptr; }
169 bool hasHScrollBar( ) const { return m_pHScroll
!= nullptr; }
171 // IEngineStatusListener overridables
172 virtual void EditEngineStatusChanged( const EditStatus
& _rStatus
) override
;
175 DECL_LINK( OnInvalidateAllAttributes
, LinkParamNone
*, void );
176 DECL_LINK( OnHScroll
, ScrollBar
*, void );
177 DECL_LINK( OnVScroll
, ScrollBar
*, void );
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */