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 INCLUDED_DRAWINGLAYER_PRIMITIVE2D_CONTROLPRIMITIVE2D_HXX
25 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_CONTROLPRIMITIVE2D_HXX
26 
27 #include <drawinglayer/drawinglayerdllapi.h>
28 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <com/sun/star/awt/XControlModel.hpp>
31 #include <com/sun/star/awt/XControl.hpp>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace drawinglayer
36 {
37 	namespace primitive2d
38 	{
39         /** ControlPrimitive2D class
40 
41             Base class for ControlPrimitive handling. It decoposes to a
42             graphical representation (Bitmap data) of the control. This
43             representation is limited to a quadratic pixel maximum defined
44             in the applicatin settings.
45          */
46 		class DRAWINGLAYER_DLLPUBLIC ControlPrimitive2D : public BufferedDecompositionPrimitive2D
47 		{
48 		private:
49 			/// object's base data
50 			basegfx::B2DHomMatrix													maTransform;
51 			com::sun::star::uno::Reference< com::sun::star::awt::XControlModel >	mxControlModel;
52 
53 			/// the created an cached awt::XControl
54 			com::sun::star::uno::Reference< com::sun::star::awt::XControl >			mxXControl;
55 
56 			/// the last used scaling, used from getDecomposition for buffering
57 			basegfx::B2DVector														maLastViewScaling;
58 
59 			/** used from getXControl() to create a local awt::XControl which is remembered in mxXControl
60 			    and from thereon always used and returned by getXControl()
61              */
62 			void createXControl();
63 
64 			/// single local decompositions, used from create2DDecomposition()
65 			Primitive2DReference createBitmapDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
66 			Primitive2DReference createPlaceholderDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
67 
68 		protected:
69 			/// local decomposition
70 			virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
71 
72 		public:
73             /// constructor
74 			ControlPrimitive2D(
75 				const basegfx::B2DHomMatrix& rTransform,
76 				const com::sun::star::uno::Reference< com::sun::star::awt::XControlModel >& rxControlModel);
77 
78 			/** constructor with an additional XControl as parameter to allow to hand it over at incarnation time
79 			    if it exists. This will avoid to create a 2nd one on demand in createXControl()
80 			    and thus double the XControls.
81              */
82 			ControlPrimitive2D(
83 				const basegfx::B2DHomMatrix& rTransform,
84 				const com::sun::star::uno::Reference< com::sun::star::awt::XControlModel >& rxControlModel,
85 				const com::sun::star::uno::Reference< com::sun::star::awt::XControl >& rxXControl);
86 
87 			/// data read access
getTransform() const88 			const basegfx::B2DHomMatrix& getTransform() const { return maTransform; }
getControlModel() const89 			const com::sun::star::uno::Reference< com::sun::star::awt::XControlModel >& getControlModel() const { return mxControlModel; }
90 
91 			/** mxControl access. This will on demand create the awt::XControl using createXControl()
92 			    if it does not exist. It may already have been created or even handed over at
93 			    incarnation
94              */
95 			const com::sun::star::uno::Reference< com::sun::star::awt::XControl >& getXControl() const;
96 
97 			/// compare operator
98 			virtual bool operator==(const BasePrimitive2D& rPrimitive) const;
99 
100 			/// get range
101 			virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
102 
103 			/// provide unique ID
104 			DeclPrimitrive2DIDBlock()
105 
106 			/// Overload standard getDecomposition call to be view-dependent here
107 			virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
108 		};
109 	} // end of namespace primitive2d
110 } // end of namespace drawinglayer
111 
112 //////////////////////////////////////////////////////////////////////////////
113 
114 #endif // INCLUDED_DRAWINGLAYER_PRIMITIVE2D_CONTROLPRIMITIVE2D_HXX
115 
116 //////////////////////////////////////////////////////////////////////////////
117 // eof
118