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