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