xref: /AOO41X/main/forms/source/richtext/richtextimplcontrol.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
28*cdf0e10cSrcweir #define FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "rtattributehandler.hxx"
31*cdf0e10cSrcweir #include "richtextviewport.hxx"
32*cdf0e10cSrcweir #include "richtextengine.hxx"
33*cdf0e10cSrcweir #include <vcl/scrbar.hxx>
34*cdf0e10cSrcweir #include <editeng/editdata.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <map>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir class EditView;
39*cdf0e10cSrcweir class EditStatus;
40*cdf0e10cSrcweir class Window;
41*cdf0e10cSrcweir class SvxScriptSetItem;
42*cdf0e10cSrcweir //........................................................................
43*cdf0e10cSrcweir namespace frm
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir //........................................................................
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     class ITextAttributeListener;
48*cdf0e10cSrcweir     class ITextSelectionListener;
49*cdf0e10cSrcweir     class RichTextViewPort;
50*cdf0e10cSrcweir 	//====================================================================
51*cdf0e10cSrcweir 	//= RichTextControlImpl
52*cdf0e10cSrcweir 	//====================================================================
53*cdf0e10cSrcweir     class RichTextControlImpl : public IEngineStatusListener
54*cdf0e10cSrcweir     {
55*cdf0e10cSrcweir         typedef ::std::map< AttributeId, AttributeState >                           StateCache;
56*cdf0e10cSrcweir         typedef ::std::map< AttributeId, ::rtl::Reference< IAttributeHandler > >    AttributeHandlerPool;
57*cdf0e10cSrcweir         typedef ::std::map< AttributeId, ITextAttributeListener* >                  AttributeListenerPool;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir         StateCache              m_aLastKnownStates;
60*cdf0e10cSrcweir         AttributeHandlerPool    m_aAttributeHandlers;
61*cdf0e10cSrcweir         AttributeListenerPool   m_aAttributeListeners;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir         ESelection              m_aLastKnownSelection;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir         Control*                m_pAntiImpl;
66*cdf0e10cSrcweir         RichTextViewPort*       m_pViewport;
67*cdf0e10cSrcweir         ScrollBar*              m_pHScroll;
68*cdf0e10cSrcweir         ScrollBar*              m_pVScroll;
69*cdf0e10cSrcweir         ScrollBarBox*           m_pScrollCorner;
70*cdf0e10cSrcweir         RichTextEngine*         m_pEngine;
71*cdf0e10cSrcweir         EditView*               m_pView;
72*cdf0e10cSrcweir         ITextAttributeListener* m_pTextAttrListener;
73*cdf0e10cSrcweir         ITextSelectionListener* m_pSelectionListener;
74*cdf0e10cSrcweir         bool                    m_bHasEverBeenShown;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     public:
77*cdf0e10cSrcweir         struct GrantAccess { friend class RichTextControl; private: GrantAccess() { } };
78*cdf0e10cSrcweir         inline EditView*        getView( const GrantAccess& ) const     { return m_pView; }
79*cdf0e10cSrcweir         inline RichTextEngine*  getEngine( const GrantAccess& ) const   { return m_pEngine; }
80*cdf0e10cSrcweir         inline Window*          getViewport( const GrantAccess& ) const { return m_pViewport; }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     public:
83*cdf0e10cSrcweir         RichTextControlImpl( Control* _pAntiImpl, RichTextEngine* _pEngine,
84*cdf0e10cSrcweir             ITextAttributeListener* _pTextAttrListener, ITextSelectionListener* _pSelectionListener );
85*cdf0e10cSrcweir         virtual ~RichTextControlImpl();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         /** updates the cache with the state of all attribute values from the given set, notifies
88*cdf0e10cSrcweir             the listener if the state changed
89*cdf0e10cSrcweir         */
90*cdf0e10cSrcweir         void    updateAllAttributes( );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         /** updates the cache with the state of the attribute given by which id, notifies
93*cdf0e10cSrcweir             the listener if the state changed
94*cdf0e10cSrcweir         */
95*cdf0e10cSrcweir         void    updateAttribute( AttributeId _nAttribute );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         /// enables the callback for a particular attribute
98*cdf0e10cSrcweir         void    enableAttributeNotification( AttributeId _nAttributeId, ITextAttributeListener* _pListener = NULL );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         /// disables the change notifications for a particular attribute
101*cdf0e10cSrcweir         void    disableAttributeNotification( AttributeId _nAttributeId );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         /// executes a toggle of the given attribute
104*cdf0e10cSrcweir         bool    executeAttribute( const SfxItemSet& _rCurrentAttribs, SfxItemSet& _rNewAttribs, AttributeId _nAttribute, const SfxPoolItem* _pArgument, ScriptType _nForScriptType );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         /// retrieves the state of the given attribute from the cache
107*cdf0e10cSrcweir         AttributeState  getAttributeState( AttributeId _nAttributeId ) const;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         /** normalizes the given item so that the state of script dependent attributes
110*cdf0e10cSrcweir             is correct considering the current script type
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir             There are some attributes which are script dependent, e.g. the CharPosture. This means
113*cdf0e10cSrcweir             that in real, there are 3 attributes for this, one for every possible script type (latin,
114*cdf0e10cSrcweir             asian, complex). However, to the out world, we behave as if there is only one attribute:
115*cdf0e10cSrcweir             E.g., if the outter world asks for the state of the "CharPosture" attribute, we return
116*cdf0e10cSrcweir             the state of either CharPostureLatin, CharPostureAsian, or CharPostureComplex, depending
117*cdf0e10cSrcweir             on the script type of the current selection. (In real, it may be more complex since
118*cdf0e10cSrcweir             the current selection may contain more than one script type.)
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir             This method normalizes a script dependent attribute, so that it's state takes into account
121*cdf0e10cSrcweir             the currently selected script type.
122*cdf0e10cSrcweir         */
123*cdf0e10cSrcweir         void        normalizeScriptDependentAttribute( SvxScriptSetItem& _rScriptSetItem );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir         // gets the script type of the selection in our edit view (with fallback)
126*cdf0e10cSrcweir         ScriptType  getSelectedScriptType() const;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         /** re-arranges the view and the scrollbars
129*cdf0e10cSrcweir         */
130*cdf0e10cSrcweir         void    layoutWindow();
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         /** to be called when the style of our window changed
133*cdf0e10cSrcweir         */
134*cdf0e10cSrcweir         void    notifyStyleChanged();
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         /** to be called when the zoom of our window changed
137*cdf0e10cSrcweir         */
138*cdf0e10cSrcweir         void    notifyZoomChanged();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         /** to be called when the STATE_CHANGE_INITSHOW event arrives
141*cdf0e10cSrcweir         */
142*cdf0e10cSrcweir         void    notifyInitShow();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         // VCL "overrides"
145*cdf0e10cSrcweir         void    SetBackgroundColor( );
146*cdf0e10cSrcweir         void    SetBackgroundColor( const Color& _rColor );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         void    SetReadOnly( bool _bReadOnly );
149*cdf0e10cSrcweir         bool    IsReadOnly() const;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir         void    SetHideInactiveSelection( bool _bHide );
152*cdf0e10cSrcweir         bool    GetHideInactiveSelection() const;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         /// draws the control onto a given output device
155*cdf0e10cSrcweir         void    Draw( OutputDevice* _pDev, const Point& _rPos, const Size& _rSize, sal_uLong _nFlags );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir         /// handles command events arrived at the anti-impl control
158*cdf0e10cSrcweir         long    HandleCommand( const CommandEvent& _rEvent );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     private:
161*cdf0e10cSrcweir         // updates the cache with the state provided by the given attribut handler
162*cdf0e10cSrcweir         void    implUpdateAttribute( AttributeHandlerPool::const_iterator _pHandler );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         // updates the cache with the given state, and calls listeners (if necessary)
165*cdf0e10cSrcweir         void    implCheckUpdateCache( AttributeId _nAttribute, const AttributeState& _rState );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         // updates range and position of our scrollbars
168*cdf0e10cSrcweir         void    updateScrollbars();
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         // determines whether automatic (soft) line breaks are ON
171*cdf0e10cSrcweir         bool    windowHasAutomaticLineBreak();
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         /// hides or shows our scrollbars, according to the current WinBits of the window
174*cdf0e10cSrcweir         void    ensureScrollbars();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         /// ensures that our "automatic line break" setting matches the current WinBits of the window
177*cdf0e10cSrcweir         void    ensureLineBreakSetting();
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         inline  bool    hasVScrollBar( ) const { return m_pVScroll != NULL; }
180*cdf0e10cSrcweir         inline  bool    hasHScrollBar( ) const { return m_pHScroll != NULL; }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         // IEngineStatusListener overridables
183*cdf0e10cSrcweir         virtual void EditEngineStatusChanged( const EditStatus& _rStatus );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     private:
186*cdf0e10cSrcweir         DECL_LINK( OnInvalidateAllAttributes, void* );
187*cdf0e10cSrcweir 	    DECL_LINK( OnHScroll, ScrollBar* );
188*cdf0e10cSrcweir 	    DECL_LINK( OnVScroll, ScrollBar* );
189*cdf0e10cSrcweir     };
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //........................................................................
192*cdf0e10cSrcweir } // namespace frm
193*cdf0e10cSrcweir //........................................................................
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir #endif // FORMS_SOURCE_RICHTEXT_RICHTEXTIMPLCONTOL_HXX
196*cdf0e10cSrcweir 
197