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 .
19 #ifndef INCLUDED_FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTROL_HXX
20 #define INCLUDED_FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTROL_HXX
22 #include "rtattributehandler.hxx"
23 #include "richtextviewport.hxx"
24 #include "richtextengine.hxx"
25 #include <vcl/scrbar.hxx>
26 #include <editeng/editdata.hxx>
32 namespace vcl
{ class Window
; }
33 class SvxScriptSetItem
;
39 class ITextAttributeListener
;
40 class ITextSelectionListener
;
41 class RichTextViewPort
;
43 class RichTextControlImpl
: public IEngineStatusListener
45 typedef ::std::map
< AttributeId
, AttributeState
> StateCache
;
46 typedef ::std::map
< AttributeId
, ::rtl::Reference
< AttributeHandler
> > AttributeHandlerPool
;
47 typedef ::std::map
< AttributeId
, ITextAttributeListener
* > AttributeListenerPool
;
49 StateCache m_aLastKnownStates
;
50 AttributeHandlerPool m_aAttributeHandlers
;
51 AttributeListenerPool m_aAttributeListeners
;
53 ESelection m_aLastKnownSelection
;
55 VclPtr
<Control
> m_pAntiImpl
;
56 VclPtr
<RichTextViewPort
> m_pViewport
;
57 VclPtr
<ScrollBar
> m_pHScroll
;
58 VclPtr
<ScrollBar
> m_pVScroll
;
59 VclPtr
<ScrollBarBox
> m_pScrollCorner
;
60 RichTextEngine
* m_pEngine
;
62 ITextAttributeListener
* m_pTextAttrListener
;
63 ITextSelectionListener
* m_pSelectionListener
;
64 bool m_bHasEverBeenShown
;
67 struct GrantAccess
{ friend class RichTextControl
; private: GrantAccess() { } };
68 inline EditView
* getView( const GrantAccess
& ) const { return m_pView
; }
69 inline RichTextEngine
* getEngine( const GrantAccess
& ) const { return m_pEngine
; }
70 inline vcl::Window
* getViewport( const GrantAccess
& ) const { return m_pViewport
; }
73 RichTextControlImpl( Control
* _pAntiImpl
, RichTextEngine
* _pEngine
,
74 ITextAttributeListener
* _pTextAttrListener
, ITextSelectionListener
* _pSelectionListener
);
75 virtual ~RichTextControlImpl();
77 /** updates the cache with the state of all attribute values from the given set, notifies
78 the listener if the state changed
80 void updateAllAttributes( );
82 /** updates the cache with the state of the attribute given by which id, notifies
83 the listener if the state changed
85 void updateAttribute( AttributeId _nAttribute
);
87 /// enables the callback for a particular attribute
88 void enableAttributeNotification( AttributeId _nAttributeId
, ITextAttributeListener
* _pListener
= nullptr );
90 /// disables the change notifications for a particular attribute
91 void disableAttributeNotification( AttributeId _nAttributeId
);
93 /// executes a toggle of the given attribute
94 bool executeAttribute( const SfxItemSet
& _rCurrentAttribs
, SfxItemSet
& _rNewAttribs
, AttributeId _nAttribute
, const SfxPoolItem
* _pArgument
, SvtScriptType _nForScriptType
);
96 /// retrieves the state of the given attribute from the cache
97 AttributeState
getAttributeState( AttributeId _nAttributeId
) const;
99 /** normalizes the given item so that the state of script dependent attributes
100 is correct considering the current script type
102 There are some attributes which are script dependent, e.g. the CharPosture. This means
103 that in real, there are 3 attributes for this, one for every possible script type (latin,
104 asian, complex). However, to the out world, we behave as if there is only one attribute:
105 E.g., if the outer world asks for the state of the "CharPosture" attribute, we return
106 the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
107 on the script type of the current selection. (In real, it may be more complex since
108 the current selection may contain more than one script type.)
110 This method normalizes a script dependent attribute, so that it's state takes into account
111 the currently selected script type.
113 void normalizeScriptDependentAttribute( SvxScriptSetItem
& _rScriptSetItem
);
115 // gets the script type of the selection in our edit view (with fallback)
116 SvtScriptType
getSelectedScriptType() const;
118 /** re-arranges the view and the scrollbars
122 /** to be called when the style of our window changed
124 void notifyStyleChanged();
126 /** to be called when the zoom of our window changed
128 void notifyZoomChanged();
130 /** to be called when the StateChangedType::InitShow event arrives
132 void notifyInitShow();
135 void SetBackgroundColor( );
136 void SetBackgroundColor( const Color
& _rColor
);
138 void SetReadOnly( bool _bReadOnly
);
139 bool IsReadOnly() const;
141 void SetHideInactiveSelection( bool _bHide
);
142 bool GetHideInactiveSelection() const;
144 /// draws the control onto a given output device
145 void Draw( OutputDevice
* _pDev
, const Point
& _rPos
, const Size
& _rSize
, DrawFlags _nFlags
);
147 /// handles command events arrived at the anti-impl control
148 long HandleCommand( const CommandEvent
& _rEvent
);
151 // updates the cache with the state provided by the given attribute handler
152 void implUpdateAttribute( const AttributeHandlerPool::const_iterator
& _pHandler
);
154 // updates the cache with the given state, and calls listeners (if necessary)
155 void implCheckUpdateCache( AttributeId _nAttribute
, const AttributeState
& _rState
);
157 // updates range and position of our scrollbars
158 void updateScrollbars();
160 // determines whether automatic (soft) line breaks are ON
161 bool windowHasAutomaticLineBreak();
163 /// hides or shows our scrollbars, according to the current WinBits of the window
164 void ensureScrollbars();
166 /// ensures that our "automatic line break" setting matches the current WinBits of the window
167 void ensureLineBreakSetting();
169 inline bool hasVScrollBar( ) const { return m_pVScroll
!= nullptr; }
170 inline bool hasHScrollBar( ) const { return m_pHScroll
!= nullptr; }
172 // IEngineStatusListener overridables
173 virtual void EditEngineStatusChanged( const EditStatus
& _rStatus
) override
;
176 DECL_LINK_TYPED( OnInvalidateAllAttributes
, LinkParamNone
*, void );
177 DECL_LINK_TYPED( OnHScroll
, ScrollBar
*, void );
178 DECL_LINK_TYPED( OnVScroll
, ScrollBar
*, void );
185 #endif // INCLUDED_FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTROL_HXX
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */