1*2d785d7eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2d785d7eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2d785d7eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2d785d7eSAndrew Rist  * distributed with this work for additional information
6*2d785d7eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2d785d7eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2d785d7eSAndrew Rist  * "License"); you may not use this file except in compliance
9*2d785d7eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2d785d7eSAndrew Rist  *
11*2d785d7eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2d785d7eSAndrew Rist  *
13*2d785d7eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2d785d7eSAndrew Rist  * software distributed under the License is distributed on an
15*2d785d7eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2d785d7eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2d785d7eSAndrew Rist  * specific language governing permissions and limitations
18*2d785d7eSAndrew Rist  * under the License.
19*2d785d7eSAndrew Rist  *
20*2d785d7eSAndrew Rist  *************************************************************/
21*2d785d7eSAndrew Rist 
22*2d785d7eSAndrew Rist 
23cdf0e10cSrcweir #ifndef FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
24cdf0e10cSrcweir #define FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "rtattributehandler.hxx"
27cdf0e10cSrcweir #include "richtextviewport.hxx"
28cdf0e10cSrcweir #include "richtextengine.hxx"
29cdf0e10cSrcweir #include <vcl/scrbar.hxx>
30cdf0e10cSrcweir #include <editeng/editdata.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <map>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir class EditView;
35cdf0e10cSrcweir class EditStatus;
36cdf0e10cSrcweir class Window;
37cdf0e10cSrcweir class SvxScriptSetItem;
38cdf0e10cSrcweir //........................................................................
39cdf0e10cSrcweir namespace frm
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     class ITextAttributeListener;
44cdf0e10cSrcweir     class ITextSelectionListener;
45cdf0e10cSrcweir     class RichTextViewPort;
46cdf0e10cSrcweir 	//====================================================================
47cdf0e10cSrcweir 	//= RichTextControlImpl
48cdf0e10cSrcweir 	//====================================================================
49cdf0e10cSrcweir     class RichTextControlImpl : public IEngineStatusListener
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         typedef ::std::map< AttributeId, AttributeState >                           StateCache;
52cdf0e10cSrcweir         typedef ::std::map< AttributeId, ::rtl::Reference< IAttributeHandler > >    AttributeHandlerPool;
53cdf0e10cSrcweir         typedef ::std::map< AttributeId, ITextAttributeListener* >                  AttributeListenerPool;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         StateCache              m_aLastKnownStates;
56cdf0e10cSrcweir         AttributeHandlerPool    m_aAttributeHandlers;
57cdf0e10cSrcweir         AttributeListenerPool   m_aAttributeListeners;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         ESelection              m_aLastKnownSelection;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         Control*                m_pAntiImpl;
62cdf0e10cSrcweir         RichTextViewPort*       m_pViewport;
63cdf0e10cSrcweir         ScrollBar*              m_pHScroll;
64cdf0e10cSrcweir         ScrollBar*              m_pVScroll;
65cdf0e10cSrcweir         ScrollBarBox*           m_pScrollCorner;
66cdf0e10cSrcweir         RichTextEngine*         m_pEngine;
67cdf0e10cSrcweir         EditView*               m_pView;
68cdf0e10cSrcweir         ITextAttributeListener* m_pTextAttrListener;
69cdf0e10cSrcweir         ITextSelectionListener* m_pSelectionListener;
70cdf0e10cSrcweir         bool                    m_bHasEverBeenShown;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     public:
GrantAccessfrm::RichTextControlImpl::GrantAccess73cdf0e10cSrcweir         struct GrantAccess { friend class RichTextControl; private: GrantAccess() { } };
getView(const GrantAccess &) const74cdf0e10cSrcweir         inline EditView*        getView( const GrantAccess& ) const     { return m_pView; }
getEngine(const GrantAccess &) const75cdf0e10cSrcweir         inline RichTextEngine*  getEngine( const GrantAccess& ) const   { return m_pEngine; }
getViewport(const GrantAccess &) const76cdf0e10cSrcweir         inline Window*          getViewport( const GrantAccess& ) const { return m_pViewport; }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     public:
79cdf0e10cSrcweir         RichTextControlImpl( Control* _pAntiImpl, RichTextEngine* _pEngine,
80cdf0e10cSrcweir             ITextAttributeListener* _pTextAttrListener, ITextSelectionListener* _pSelectionListener );
81cdf0e10cSrcweir         virtual ~RichTextControlImpl();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         /** updates the cache with the state of all attribute values from the given set, notifies
84cdf0e10cSrcweir             the listener if the state changed
85cdf0e10cSrcweir         */
86cdf0e10cSrcweir         void    updateAllAttributes( );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         /** updates the cache with the state of the attribute given by which id, notifies
89cdf0e10cSrcweir             the listener if the state changed
90cdf0e10cSrcweir         */
91cdf0e10cSrcweir         void    updateAttribute( AttributeId _nAttribute );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         /// enables the callback for a particular attribute
94cdf0e10cSrcweir         void    enableAttributeNotification( AttributeId _nAttributeId, ITextAttributeListener* _pListener = NULL );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         /// disables the change notifications for a particular attribute
97cdf0e10cSrcweir         void    disableAttributeNotification( AttributeId _nAttributeId );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         /// executes a toggle of the given attribute
100cdf0e10cSrcweir         bool    executeAttribute( const SfxItemSet& _rCurrentAttribs, SfxItemSet& _rNewAttribs, AttributeId _nAttribute, const SfxPoolItem* _pArgument, ScriptType _nForScriptType );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         /// retrieves the state of the given attribute from the cache
103cdf0e10cSrcweir         AttributeState  getAttributeState( AttributeId _nAttributeId ) const;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         /** normalizes the given item so that the state of script dependent attributes
106cdf0e10cSrcweir             is correct considering the current script type
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             There are some attributes which are script dependent, e.g. the CharPosture. This means
109cdf0e10cSrcweir             that in real, there are 3 attributes for this, one for every possible script type (latin,
110cdf0e10cSrcweir             asian, complex). However, to the out world, we behave as if there is only one attribute:
111cdf0e10cSrcweir             E.g., if the outter world asks for the state of the "CharPosture" attribute, we return
112cdf0e10cSrcweir             the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
113cdf0e10cSrcweir             on the script type of the current selection. (In real, it may be more complex since
114cdf0e10cSrcweir             the current selection may contain more than one script type.)
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             This method normalizes a script dependent attribute, so that it's state takes into account
117cdf0e10cSrcweir             the currently selected script type.
118cdf0e10cSrcweir         */
119cdf0e10cSrcweir         void        normalizeScriptDependentAttribute( SvxScriptSetItem& _rScriptSetItem );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         // gets the script type of the selection in our edit view (with fallback)
122cdf0e10cSrcweir         ScriptType  getSelectedScriptType() const;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         /** re-arranges the view and the scrollbars
125cdf0e10cSrcweir         */
126cdf0e10cSrcweir         void    layoutWindow();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         /** to be called when the style of our window changed
129cdf0e10cSrcweir         */
130cdf0e10cSrcweir         void    notifyStyleChanged();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         /** to be called when the zoom of our window changed
133cdf0e10cSrcweir         */
134cdf0e10cSrcweir         void    notifyZoomChanged();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         /** to be called when the STATE_CHANGE_INITSHOW event arrives
137cdf0e10cSrcweir         */
138cdf0e10cSrcweir         void    notifyInitShow();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         // VCL "overrides"
141cdf0e10cSrcweir         void    SetBackgroundColor( );
142cdf0e10cSrcweir         void    SetBackgroundColor( const Color& _rColor );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         void    SetReadOnly( bool _bReadOnly );
145cdf0e10cSrcweir         bool    IsReadOnly() const;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         void    SetHideInactiveSelection( bool _bHide );
148cdf0e10cSrcweir         bool    GetHideInactiveSelection() const;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         /// draws the control onto a given output device
151cdf0e10cSrcweir         void    Draw( OutputDevice* _pDev, const Point& _rPos, const Size& _rSize, sal_uLong _nFlags );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         /// handles command events arrived at the anti-impl control
154cdf0e10cSrcweir         long    HandleCommand( const CommandEvent& _rEvent );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     private:
157cdf0e10cSrcweir         // updates the cache with the state provided by the given attribut handler
158cdf0e10cSrcweir         void    implUpdateAttribute( AttributeHandlerPool::const_iterator _pHandler );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         // updates the cache with the given state, and calls listeners (if necessary)
161cdf0e10cSrcweir         void    implCheckUpdateCache( AttributeId _nAttribute, const AttributeState& _rState );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         // updates range and position of our scrollbars
164cdf0e10cSrcweir         void    updateScrollbars();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         // determines whether automatic (soft) line breaks are ON
167cdf0e10cSrcweir         bool    windowHasAutomaticLineBreak();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         /// hides or shows our scrollbars, according to the current WinBits of the window
170cdf0e10cSrcweir         void    ensureScrollbars();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         /// ensures that our "automatic line break" setting matches the current WinBits of the window
173cdf0e10cSrcweir         void    ensureLineBreakSetting();
174cdf0e10cSrcweir 
hasVScrollBar() const175cdf0e10cSrcweir         inline  bool    hasVScrollBar( ) const { return m_pVScroll != NULL; }
hasHScrollBar() const176cdf0e10cSrcweir         inline  bool    hasHScrollBar( ) const { return m_pHScroll != NULL; }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         // IEngineStatusListener overridables
179cdf0e10cSrcweir         virtual void EditEngineStatusChanged( const EditStatus& _rStatus );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     private:
182cdf0e10cSrcweir         DECL_LINK( OnInvalidateAllAttributes, void* );
183cdf0e10cSrcweir 	    DECL_LINK( OnHScroll, ScrollBar* );
184cdf0e10cSrcweir 	    DECL_LINK( OnVScroll, ScrollBar* );
185cdf0e10cSrcweir     };
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //........................................................................
188cdf0e10cSrcweir } // namespace frm
189cdf0e10cSrcweir //........................................................................
190cdf0e10cSrcweir 
191cdf0e10cSrcweir #endif // FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
192cdf0e10cSrcweir 
193