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