xref: /aoo4110/main/editeng/source/uno/unoviwou.cxx (revision b1cdbd2c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 #include <vcl/outdev.hxx>
27 #include <vcl/window.hxx>
28 
29 #include <editeng/unoviwou.hxx>
30 #include <editeng/outliner.hxx>
31 #include <editeng/editeng.hxx>
32 
SvxDrawOutlinerViewForwarder(OutlinerView & rOutl)33 SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl ) :
34     mrOutlinerView ( rOutl ), maTextShapeTopLeft()
35 {
36 }
37 
SvxDrawOutlinerViewForwarder(OutlinerView & rOutl,const Point & rShapePosTopLeft)38 SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl, const Point& rShapePosTopLeft ) :
39     mrOutlinerView ( rOutl ), maTextShapeTopLeft( rShapePosTopLeft )
40 {
41 }
42 
~SvxDrawOutlinerViewForwarder()43 SvxDrawOutlinerViewForwarder::~SvxDrawOutlinerViewForwarder()
44 {
45 }
46 
GetTextOffset() const47 Point SvxDrawOutlinerViewForwarder::GetTextOffset() const
48 {
49     // #101029# calc text offset from shape anchor
50     Rectangle aOutputRect( mrOutlinerView.GetOutputArea() );
51 
52     return aOutputRect.TopLeft() - maTextShapeTopLeft;
53 }
54 
IsValid() const55 sal_Bool SvxDrawOutlinerViewForwarder::IsValid() const
56 {
57     return sal_True;
58 }
59 
GetVisArea() const60 Rectangle SvxDrawOutlinerViewForwarder::GetVisArea() const
61 {
62     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
63 
64     if( pOutDev )
65     {
66         Rectangle aVisArea = mrOutlinerView.GetVisArea();
67 
68         // #101029#
69         Point aTextOffset( GetTextOffset() );
70         aVisArea.Move( aTextOffset.X(), aTextOffset.Y() );
71 
72         // figure out map mode from edit engine
73         Outliner* pOutliner = mrOutlinerView.GetOutliner();
74 
75         if( pOutliner )
76         {
77             MapMode aMapMode(pOutDev->GetMapMode());
78             aVisArea = OutputDevice::LogicToLogic( aVisArea,
79                                                    pOutliner->GetRefMapMode(),
80                                                    aMapMode.GetMapUnit() );
81             aMapMode.SetOrigin(Point());
82             return pOutDev->LogicToPixel( aVisArea, aMapMode );
83         }
84     }
85 
86     return Rectangle();
87 }
88 
LogicToPixel(const Point & rPoint,const MapMode & rMapMode) const89 Point SvxDrawOutlinerViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
90 {
91     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
92 
93     if( pOutDev )
94     {
95         Point aPoint1( rPoint );
96         Point aTextOffset( GetTextOffset() );
97 
98         // #101029#
99         aPoint1.X() += aTextOffset.X();
100         aPoint1.Y() += aTextOffset.Y();
101 
102         MapMode aMapMode(pOutDev->GetMapMode());
103         Point aPoint2( OutputDevice::LogicToLogic( aPoint1, rMapMode,
104                                                    aMapMode.GetMapUnit() ) );
105         aMapMode.SetOrigin(Point());
106         return pOutDev->LogicToPixel( aPoint2, aMapMode );
107     }
108 
109     return Point();
110 }
111 
PixelToLogic(const Point & rPoint,const MapMode & rMapMode) const112 Point SvxDrawOutlinerViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
113 {
114     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
115 
116     if( pOutDev )
117     {
118         MapMode aMapMode(pOutDev->GetMapMode());
119         aMapMode.SetOrigin(Point());
120         Point aPoint1( pOutDev->PixelToLogic( rPoint, aMapMode ) );
121         Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
122                                                    aMapMode.GetMapUnit(),
123                                                    rMapMode ) );
124         // #101029#
125         Point aTextOffset( GetTextOffset() );
126 
127         aPoint2.X() -= aTextOffset.X();
128         aPoint2.Y() -= aTextOffset.Y();
129 
130         return aPoint2;
131     }
132 
133     return Point();
134 }
135 
GetSelection(ESelection & rSelection) const136 sal_Bool SvxDrawOutlinerViewForwarder::GetSelection( ESelection& rSelection ) const
137 {
138     rSelection = mrOutlinerView.GetSelection();
139     return sal_True;
140 }
141 
SetSelection(const ESelection & rSelection)142 sal_Bool SvxDrawOutlinerViewForwarder::SetSelection( const ESelection& rSelection )
143 {
144     mrOutlinerView.SetSelection( rSelection );
145     return sal_True;
146 }
147 
Copy()148 sal_Bool SvxDrawOutlinerViewForwarder::Copy()
149 {
150     mrOutlinerView.Copy();
151     return sal_True;
152 }
153 
Cut()154 sal_Bool SvxDrawOutlinerViewForwarder::Cut()
155 {
156     mrOutlinerView.Cut();
157     return sal_True;
158 }
159 
Paste()160 sal_Bool SvxDrawOutlinerViewForwarder::Paste()
161 {
162     mrOutlinerView.Paste();
163     return sal_True;
164 }
165 
SetShapePos(const Point & rShapePosTopLeft)166 void SvxDrawOutlinerViewForwarder::SetShapePos( const Point& rShapePosTopLeft )
167 {
168     maTextShapeTopLeft = rShapePosTopLeft;
169 }
170