Line data Source code
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 :
20 : #include <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
24 : #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
25 : #include <svx/sdr/contact/objectcontactofpageview.hxx>
26 : #include <svx/sdr/contact/displayinfo.hxx>
27 : #include <svx/svdouno.hxx>
28 : #include <svx/svdpagv.hxx>
29 : #include <svx/svdview.hxx>
30 : #include <svx/sdrpagewindow.hxx>
31 :
32 : #include <com/sun/star/awt/XWindow2.hpp>
33 :
34 : #include "svx/sdrpaintwindow.hxx"
35 : #include <tools/diagnose_ex.h>
36 : #include <vcl/pdfextoutdevdata.hxx>
37 : #include <basegfx/matrix/b2dhommatrix.hxx>
38 : #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
39 : #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
40 :
41 :
42 : namespace sdr { namespace contact {
43 :
44 :
45 : using ::com::sun::star::awt::XControl;
46 : using ::com::sun::star::uno::Reference;
47 : using ::com::sun::star::awt::XControlContainer;
48 : using ::com::sun::star::awt::XControlModel;
49 : using ::com::sun::star::awt::XWindow2;
50 : using ::com::sun::star::uno::UNO_QUERY;
51 : using ::com::sun::star::uno::Exception;
52 :
53 :
54 : //= ViewContactOfUnoControl
55 :
56 : class ViewContactOfUnoControl_Impl: private boost::noncopyable
57 : {
58 : public:
59 : ViewContactOfUnoControl_Impl();
60 : ~ViewContactOfUnoControl_Impl();
61 : };
62 :
63 :
64 0 : ViewContactOfUnoControl_Impl::ViewContactOfUnoControl_Impl()
65 : {
66 0 : }
67 :
68 :
69 0 : ViewContactOfUnoControl_Impl::~ViewContactOfUnoControl_Impl()
70 : {
71 0 : }
72 :
73 :
74 : //= ViewContactOfUnoControl
75 :
76 :
77 0 : ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj& _rUnoObject )
78 : :ViewContactOfSdrObj( _rUnoObject )
79 0 : ,m_pImpl( new ViewContactOfUnoControl_Impl )
80 : {
81 0 : }
82 :
83 :
84 0 : ViewContactOfUnoControl::~ViewContactOfUnoControl()
85 : {
86 0 : }
87 :
88 :
89 0 : Reference< XControl > ViewContactOfUnoControl::getTemporaryControlForWindow(
90 : const Window& _rWindow, Reference< XControlContainer >& _inout_ControlContainer ) const
91 : {
92 0 : SdrUnoObj* pUnoObject = dynamic_cast< SdrUnoObj* >( TryToGetSdrObject() );
93 : OSL_ENSURE( pUnoObject, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
94 0 : if ( !pUnoObject )
95 0 : return NULL;
96 0 : return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow, _inout_ControlContainer, *pUnoObject );
97 : }
98 :
99 :
100 0 : ViewObjectContact& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact& _rObjectContact )
101 : {
102 : // print or print preview requires special handling
103 0 : const OutputDevice* pDevice = _rObjectContact.TryToGetOutputDevice();
104 0 : bool bPrintOrPreview = ( pDevice != NULL ) && ( pDevice->GetOutDevType() == OUTDEV_PRINTER );
105 :
106 0 : ObjectContactOfPageView* pPageViewContact = dynamic_cast< ObjectContactOfPageView* >( &_rObjectContact );
107 0 : bPrintOrPreview |= ( pPageViewContact != NULL ) && pPageViewContact->GetPageWindow().GetPageView().GetView().IsPrintPreview();
108 :
109 0 : if ( bPrintOrPreview )
110 0 : return *new UnoControlPrintOrPreviewContact( *pPageViewContact, *this );
111 :
112 : // all others are nowadays served by the same implementation
113 0 : return *new ViewObjectContactOfUnoControl( _rObjectContact, *this );
114 : }
115 :
116 :
117 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence() const
118 : {
119 : // create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
120 : // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
121 : // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
122 0 : Rectangle aRectangle(GetSdrUnoObj().GetGeoRect());
123 : // Hack for calc, transform position of object according
124 : // to current zoom so as objects relative position to grid
125 : // appears stable
126 0 : Point aGridOffset = GetSdrUnoObj().GetGridOffset();
127 0 : aRectangle += aGridOffset;
128 : const basegfx::B2DRange aRange(
129 0 : aRectangle.Left(), aRectangle.Top(),
130 0 : aRectangle.Right(), aRectangle.Bottom());
131 :
132 : // create object transform
133 0 : basegfx::B2DHomMatrix aTransform;
134 :
135 0 : aTransform.set(0, 0, aRange.getWidth());
136 0 : aTransform.set(1, 1, aRange.getHeight());
137 0 : aTransform.set(0, 2, aRange.getMinX());
138 0 : aTransform.set(1, 2, aRange.getMinY());
139 :
140 0 : Reference< XControlModel > xControlModel = GetSdrUnoObj().GetUnoControlModel();
141 :
142 0 : if(xControlModel.is())
143 : {
144 : // create control primitive WITHOUT possibly existing XControl; this would be done in
145 : // the VOC in createPrimitive2DSequence()
146 : const drawinglayer::primitive2d::Primitive2DReference xRetval(
147 : new drawinglayer::primitive2d::ControlPrimitive2D(
148 : aTransform,
149 0 : xControlModel));
150 :
151 0 : return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
152 : }
153 : else
154 : {
155 : // always append an invisible outline for the cases where no visible content exists
156 : const drawinglayer::primitive2d::Primitive2DReference xRetval(
157 : drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
158 0 : false, aTransform));
159 :
160 0 : return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
161 0 : }
162 : }
163 :
164 :
165 : } } // namespace sdr::contact
166 :
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|