1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 #pragma once 20 21 #include <vcl/ctrl.hxx> 22 #include "rtattributes.hxx" 23 #include "textattributelistener.hxx" 24 #include <memory> 25 26 class EditView; 27 class EditEngine; 28 class SfxItemSet; 29 30 namespace frm 31 { 32 33 class RichTextControlImpl; 34 class RichTextEngine; 35 36 class RichTextControl : public Control, public IMultiAttributeDispatcher 37 { 38 private: 39 std::unique_ptr<RichTextControlImpl> m_pImpl; 40 41 public: 42 RichTextControl( 43 RichTextEngine* _pEngine, 44 vcl::Window* _pParent, 45 WinBits _nStyle, 46 ITextAttributeListener* _pTextAttribListener, 47 ITextSelectionListener* _pSelectionListener 48 ); 49 50 virtual ~RichTextControl( ) override; 51 virtual void dispose() override; 52 53 /* enables the change notifications for a particular attribute 54 55 If you want to be notified of any changes in the state of an attribute, you need to call enableAttributeNotification. 56 57 If you provide a dedicated listener for this attribute, this listener is called for every change in the state of 58 the attribute. 59 60 No matter whether you provide such a dedicated listener, the "global" listener which you specified 61 in the constructor of the control is also called for all changes in the attribute state. 62 63 If you previously already enabled the notification for this attribute, and specified a different listener, 64 then the previous listener will be replaced with the new listener, provided the latter is not <NULL/>. 65 */ 66 void enableAttributeNotification( AttributeId _nAttributeId, ITextAttributeListener* _pListener ); 67 68 /** disables the change notifications for a particular attribute 69 70 If there was a listener dedicated to this attribute, it will not be referenced and used anymore 71 after this method had been called 72 */ 73 void disableAttributeNotification( AttributeId _nAttributeId ); 74 75 /** determines whether a given slot can be mapped to an aspect of an attribute of the EditEngine 76 77 E.g. SID_ATTR_PARA_ADJUST_LEFT can, though it's not part of the EditEngine pool, be mapped 78 to the SID_ATTR_PARA_ADJUST slot, which in fact *is* usable with the EditEngine. 79 */ 80 static bool isMappableSlot( SfxSlotId _nSlotId ); 81 82 // IMultiAttributeDispatcher 83 virtual AttributeState getState( AttributeId _nAttributeId ) const override; 84 virtual void executeAttribute( AttributeId _nAttributeId, const SfxPoolItem* _pArgument ) override; 85 86 void SetBackgroundColor( ); 87 void SetBackgroundColor( const Color& _rColor ); 88 89 void SetReadOnly( bool _bReadOnly ); 90 bool IsReadOnly() const; 91 92 void SetHideInactiveSelection( bool _bHide ); 93 bool GetHideInactiveSelection() const; 94 95 const EditView& getView() const; 96 EditView& getView(); 97 98 // Window overridables 99 virtual void Draw( OutputDevice* _pDev, const Point& _rPos, DrawFlags _nFlags ) override; 100 101 protected: 102 // Window overridables 103 virtual void Resize() override; 104 virtual void GetFocus() override; 105 virtual void StateChanged( StateChangedType nStateChange ) override; 106 virtual bool PreNotify( NotifyEvent& _rNEvt ) override; 107 virtual bool EventNotify( NotifyEvent& _rNEvt ) override; 108 109 private: 110 void applyAttributes( const SfxItemSet& _rAttributesToApply ); 111 void implInit( RichTextEngine* _pEngine, ITextAttributeListener* _pTextAttribListener, ITextSelectionListener* _pSelectionListener ); 112 static WinBits implInitStyle( WinBits nStyle ); 113 114 private: 115 EditEngine& getEngine() const; 116 }; 117 118 119 } // namespace frm 120 121 122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 123