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 24 #ifndef _SDR_CONTACT_VIEWCONTACT_HXX 25 #define _SDR_CONTACT_VIEWCONTACT_HXX 26 27 #include <sal/types.h> 28 #include <tools/gen.hxx> 29 #include "svx/svxdllapi.h" 30 #include <drawinglayer/primitive2d/baseprimitive2d.hxx> 31 32 ////////////////////////////////////////////////////////////////////////////// 33 // predeclarations 34 35 class SetOfByte; 36 class SdrPage; 37 class SdrObject; 38 39 namespace sdr 40 { 41 namespace contact 42 { 43 class ObjectContact; 44 class ViewObjectContact; 45 } // end of namespace contact 46 } // end of namespace sdr 47 48 ////////////////////////////////////////////////////////////////////////////// 49 50 namespace sdr 51 { 52 namespace contact 53 { 54 class SVX_DLLPUBLIC ViewContact 55 { 56 private: 57 // make ViewObjectContact a friend to exclusively allow it to use 58 // AddViewObjectContact/RemoveViewObjectContact 59 friend class ViewObjectContact; 60 61 // List of ViewObjectContacts. This contains all VOCs which were constructed 62 // with this VC. Since the VOCs remember a reference to this VC, this list needs 63 // to be kept and is used e.g. at destructor to destroy all VOCs. 64 // Registering and de-registering is done in the VOC constructors/destructors. 65 std::vector< ViewObjectContact* > maViewObjectContactVector; 66 67 // Primitive2DSequence of the ViewContact. This contains all necessary information 68 // for the graphical visualisation and needs to be supported by all VCs which 69 // can be visualized. 70 drawinglayer::primitive2d::Primitive2DSequence mxViewIndependentPrimitive2DSequence; 71 72 // A new ViewObjectContact was created and shall be remembered. 73 void AddViewObjectContact(ViewObjectContact& rVOContact); 74 75 // A ViewObjectContact was deleted and shall be forgotten. 76 void RemoveViewObjectContact(ViewObjectContact& rVOContact); 77 78 // internal tooling to delete VOCs 79 void deleteAllVOCs(); 80 81 protected: 82 // Interface to allow derivates to travel over the registered VOC's getViewObjectContactCount() const83 sal_uInt32 getViewObjectContactCount() const { return maViewObjectContactVector.size(); } getViewObjectContact(sal_uInt32 a) const84 ViewObjectContact* getViewObjectContact(sal_uInt32 a) const { return maViewObjectContactVector[a]; } 85 86 // Create a Object-Specific ViewObjectContact, set ViewContact and 87 // ObjectContact. Always needs to return something. Default is to create 88 // a standard ViewObjectContact containing the given ObjectContact and *this 89 virtual ViewObjectContact& CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact); 90 91 // This method is responsible for creating the graphical visualisation data derived ONLY from 92 // the model data. It will be stored/buffered in mxViewIndependentPrimitive2DSequence. The default implementation 93 // creates a yellow replacement rectangle (1000, 1000, 5000, 3000) to visualize missing 94 // implementations. All implementations have to provide basic geometry here, this is the central 95 // visualisation method and will also be used for BoundRect computations in the long run. 96 // This means it's always an error when the default implementation is called and thus gets 97 // asserted there 98 virtual drawinglayer::primitive2d::Primitive2DSequence createViewIndependentPrimitive2DSequence() const; 99 100 // method for flushing View Independent Primitive2DSequence for VOC implementations flushViewIndependentPrimitive2DSequence()101 void flushViewIndependentPrimitive2DSequence() { mxViewIndependentPrimitive2DSequence.realloc(0); } 102 103 // basic constructor. Since this is a base class only, it shall 104 // never be called directly 105 ViewContact(); 106 107 // Methods to react on start getting viewed or stop getting 108 // viewed. This info is derived from the count of members of 109 // registered ViewObjectContacts. Default does nothing. 110 virtual void StartGettingViewed(); 111 virtual void StopGettingViewed(); 112 113 public: 114 // basic destructor with needed cleanups 115 virtual ~ViewContact(); 116 117 // get a Object-specific ViewObjectContact for a specific 118 // ObjectContact (->View). Always needs to return something. 119 ViewObjectContact& GetViewObjectContact(ObjectContact& rObjectContact); 120 121 // Test if this ViewContact has ViewObjectContacts at all. This can 122 // be used to test if this ViewContact is visualized ATM or not 123 bool HasViewObjectContacts(bool bExcludePreviews = false) const; 124 125 // Check if this primitive is animated in any OC (View) which means it has 126 // generated a PrimitiveAnimation in it's VOC 127 bool isAnimatedInAnyViewObjectContact() const; 128 129 // Access to possible sub-hierarchy and parent. GetObjectCount() default is 0L 130 // and GetViewContact default pops up an assert since it's an error if 131 // GetObjectCount has a result != 0 and it's not overloaded. 132 virtual sal_uInt32 GetObjectCount() const; 133 virtual ViewContact& GetViewContact(sal_uInt32 nIndex) const; 134 virtual ViewContact* GetParentContact() const; 135 136 // React on insertion of a child into DRawHierarchy starting 137 // from this object 138 void ActionChildInserted(ViewContact& rChild); 139 140 // React on changes of the object of this ViewContact 141 virtual void ActionChanged(); 142 143 // access to SdrObject and/or SdrPage. May return 0L like the default 144 // implementations do. Needs to be overloaded as needed. 145 virtual SdrObject* TryToGetSdrObject() const; 146 virtual SdrPage* TryToGetSdrPage() const; 147 148 // access to the local primitive. This will ensure that the primitive is 149 // current in comparing the local one with a fresh created incarnation 150 drawinglayer::primitive2d::Primitive2DSequence getViewIndependentPrimitive2DSequence() const; 151 152 // add Gluepoints (if available) 153 virtual drawinglayer::primitive2d::Primitive2DSequence createGluePointPrimitive2DSequence() const; 154 155 // allow embedding if needed (e.g. for SdrObjects, evtl. Name, Title and description get added). This 156 // is a helper normally used from getViewIndependentPrimitive2DSequence(), but there is one exception 157 // for 3D scenes 158 virtual drawinglayer::primitive2d::Primitive2DSequence embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DSequence& rSource) const; 159 160 // delete all existing VOCs including DrawHierarchy which will invalidate all 161 // visualisations, too. Used mostly at object removal from DrawHierarchy to 162 // delete all existing VOCs by purpose, but can also be used for other purposes. 163 // It is always possible to delete the VOCs, these are re-created on demand 164 void flushViewObjectContacts(bool bWithHierarchy = true); 165 }; 166 } // end of namespace contact 167 } // end of namespace sdr 168 169 ////////////////////////////////////////////////////////////////////////////// 170 171 #endif //_SDR_CONTACT_VIEWCONTACT_HXX 172 173 // eof 174