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 FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
20 #define FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
22 #include "rtattributehandler.hxx"
23 #include "richtextviewport.hxx"
24 #include "richtextengine.hxx"
25 #include <vcl/scrbar.hxx>
26 #include <editeng/editdata.hxx>
33 class SvxScriptSetItem
;
34 //........................................................................
37 //........................................................................
39 class ITextAttributeListener
;
40 class ITextSelectionListener
;
41 class RichTextViewPort
;
42 //====================================================================
43 //= RichTextControlImpl
44 //====================================================================
45 class RichTextControlImpl
: public IEngineStatusListener
47 typedef ::std::map
< AttributeId
, AttributeState
> StateCache
;
48 typedef ::std::map
< AttributeId
, ::rtl::Reference
< IAttributeHandler
> > AttributeHandlerPool
;
49 typedef ::std::map
< AttributeId
, ITextAttributeListener
* > AttributeListenerPool
;
51 StateCache m_aLastKnownStates
;
52 AttributeHandlerPool m_aAttributeHandlers
;
53 AttributeListenerPool m_aAttributeListeners
;
55 ESelection m_aLastKnownSelection
;
58 RichTextViewPort
* m_pViewport
;
59 ScrollBar
* m_pHScroll
;
60 ScrollBar
* m_pVScroll
;
61 ScrollBarBox
* m_pScrollCorner
;
62 RichTextEngine
* m_pEngine
;
64 ITextAttributeListener
* m_pTextAttrListener
;
65 ITextSelectionListener
* m_pSelectionListener
;
66 bool m_bHasEverBeenShown
;
69 struct GrantAccess
{ friend class RichTextControl
; private: GrantAccess() { } };
70 inline EditView
* getView( const GrantAccess
& ) const { return m_pView
; }
71 inline RichTextEngine
* getEngine( const GrantAccess
& ) const { return m_pEngine
; }
72 inline Window
* getViewport( const GrantAccess
& ) const { return m_pViewport
; }
75 RichTextControlImpl( Control
* _pAntiImpl
, RichTextEngine
* _pEngine
,
76 ITextAttributeListener
* _pTextAttrListener
, ITextSelectionListener
* _pSelectionListener
);
77 virtual ~RichTextControlImpl();
79 /** updates the cache with the state of all attribute values from the given set, notifies
80 the listener if the state changed
82 void updateAllAttributes( );
84 /** updates the cache with the state of the attribute given by which id, notifies
85 the listener if the state changed
87 void updateAttribute( AttributeId _nAttribute
);
89 /// enables the callback for a particular attribute
90 void enableAttributeNotification( AttributeId _nAttributeId
, ITextAttributeListener
* _pListener
= NULL
);
92 /// disables the change notifications for a particular attribute
93 void disableAttributeNotification( AttributeId _nAttributeId
);
95 /// executes a toggle of the given attribute
96 bool executeAttribute( const SfxItemSet
& _rCurrentAttribs
, SfxItemSet
& _rNewAttribs
, AttributeId _nAttribute
, const SfxPoolItem
* _pArgument
, ScriptType _nForScriptType
);
98 /// retrieves the state of the given attribute from the cache
99 AttributeState
getAttributeState( AttributeId _nAttributeId
) const;
101 /** normalizes the given item so that the state of script dependent attributes
102 is correct considering the current script type
104 There are some attributes which are script dependent, e.g. the CharPosture. This means
105 that in real, there are 3 attributes for this, one for every possible script type (latin,
106 asian, complex). However, to the out world, we behave as if there is only one attribute:
107 E.g., if the outter world asks for the state of the "CharPosture" attribute, we return
108 the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
109 on the script type of the current selection. (In real, it may be more complex since
110 the current selection may contain more than one script type.)
112 This method normalizes a script dependent attribute, so that it's state takes into account
113 the currently selected script type.
115 void normalizeScriptDependentAttribute( SvxScriptSetItem
& _rScriptSetItem
);
117 // gets the script type of the selection in our edit view (with fallback)
118 ScriptType
getSelectedScriptType() const;
120 /** re-arranges the view and the scrollbars
124 /** to be called when the style of our window changed
126 void notifyStyleChanged();
128 /** to be called when the zoom of our window changed
130 void notifyZoomChanged();
132 /** to be called when the STATE_CHANGE_INITSHOW event arrives
134 void notifyInitShow();
137 void SetBackgroundColor( );
138 void SetBackgroundColor( const Color
& _rColor
);
140 void SetReadOnly( bool _bReadOnly
);
141 bool IsReadOnly() const;
143 void SetHideInactiveSelection( bool _bHide
);
144 bool GetHideInactiveSelection() const;
146 /// draws the control onto a given output device
147 void Draw( OutputDevice
* _pDev
, const Point
& _rPos
, const Size
& _rSize
, sal_uLong _nFlags
);
149 /// handles command events arrived at the anti-impl control
150 long HandleCommand( const CommandEvent
& _rEvent
);
153 // updates the cache with the state provided by the given attribut handler
154 void implUpdateAttribute( AttributeHandlerPool::const_iterator _pHandler
);
156 // updates the cache with the given state, and calls listeners (if necessary)
157 void implCheckUpdateCache( AttributeId _nAttribute
, const AttributeState
& _rState
);
159 // updates range and position of our scrollbars
160 void updateScrollbars();
162 // determines whether automatic (soft) line breaks are ON
163 bool windowHasAutomaticLineBreak();
165 /// hides or shows our scrollbars, according to the current WinBits of the window
166 void ensureScrollbars();
168 /// ensures that our "automatic line break" setting matches the current WinBits of the window
169 void ensureLineBreakSetting();
171 inline bool hasVScrollBar( ) const { return m_pVScroll
!= NULL
; }
172 inline bool hasHScrollBar( ) const { return m_pHScroll
!= NULL
; }
174 // IEngineStatusListener overridables
175 virtual void EditEngineStatusChanged( const EditStatus
& _rStatus
);
178 DECL_LINK( OnInvalidateAllAttributes
, void* );
179 DECL_LINK( OnHScroll
, ScrollBar
* );
180 DECL_LINK( OnVScroll
, ScrollBar
* );
183 //........................................................................
185 //........................................................................
187 #endif // FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */