xref: /aoo41x/main/editeng/source/uno/unoviwou.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 #include <vcl/outdev.hxx>
31 #include <vcl/window.hxx>
32 
33 #include <editeng/unoviwou.hxx>
34 #include <editeng/outliner.hxx>
35 #include <editeng/editeng.hxx>
36 
37 SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl ) :
38     mrOutlinerView ( rOutl ), maTextShapeTopLeft()
39 {
40 }
41 
42 SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl, const Point& rShapePosTopLeft ) :
43     mrOutlinerView ( rOutl ), maTextShapeTopLeft( rShapePosTopLeft )
44 {
45 }
46 
47 SvxDrawOutlinerViewForwarder::~SvxDrawOutlinerViewForwarder()
48 {
49 }
50 
51 Point SvxDrawOutlinerViewForwarder::GetTextOffset() const
52 {
53     // #101029# calc text offset from shape anchor
54     Rectangle aOutputRect( mrOutlinerView.GetOutputArea() );
55 
56     return aOutputRect.TopLeft() - maTextShapeTopLeft;
57 }
58 
59 sal_Bool SvxDrawOutlinerViewForwarder::IsValid() const
60 {
61     return sal_True;
62 }
63 
64 Rectangle SvxDrawOutlinerViewForwarder::GetVisArea() const
65 {
66     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
67 
68     if( pOutDev )
69     {
70         Rectangle aVisArea = mrOutlinerView.GetVisArea();
71 
72         // #101029#
73         Point aTextOffset( GetTextOffset() );
74         aVisArea.Move( aTextOffset.X(), aTextOffset.Y() );
75 
76         // figure out map mode from edit engine
77         Outliner* pOutliner = mrOutlinerView.GetOutliner();
78 
79         if( pOutliner )
80         {
81             MapMode aMapMode(pOutDev->GetMapMode());
82             aVisArea = OutputDevice::LogicToLogic( aVisArea,
83                                                    pOutliner->GetRefMapMode(),
84                                                    aMapMode.GetMapUnit() );
85             aMapMode.SetOrigin(Point());
86             return pOutDev->LogicToPixel( aVisArea, aMapMode );
87         }
88     }
89 
90     return Rectangle();
91 }
92 
93 Point SvxDrawOutlinerViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
94 {
95     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
96 
97     if( pOutDev )
98     {
99         Point aPoint1( rPoint );
100         Point aTextOffset( GetTextOffset() );
101 
102         // #101029#
103         aPoint1.X() += aTextOffset.X();
104         aPoint1.Y() += aTextOffset.Y();
105 
106         MapMode aMapMode(pOutDev->GetMapMode());
107         Point aPoint2( OutputDevice::LogicToLogic( aPoint1, rMapMode,
108                                                    aMapMode.GetMapUnit() ) );
109         aMapMode.SetOrigin(Point());
110         return pOutDev->LogicToPixel( aPoint2, aMapMode );
111     }
112 
113     return Point();
114 }
115 
116 Point SvxDrawOutlinerViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
117 {
118     OutputDevice* pOutDev = mrOutlinerView.GetWindow();
119 
120     if( pOutDev )
121     {
122         MapMode aMapMode(pOutDev->GetMapMode());
123         aMapMode.SetOrigin(Point());
124         Point aPoint1( pOutDev->PixelToLogic( rPoint, aMapMode ) );
125         Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
126                                                    aMapMode.GetMapUnit(),
127                                                    rMapMode ) );
128         // #101029#
129         Point aTextOffset( GetTextOffset() );
130 
131         aPoint2.X() -= aTextOffset.X();
132         aPoint2.Y() -= aTextOffset.Y();
133 
134         return aPoint2;
135     }
136 
137     return Point();
138 }
139 
140 sal_Bool SvxDrawOutlinerViewForwarder::GetSelection( ESelection& rSelection ) const
141 {
142     rSelection = mrOutlinerView.GetSelection();
143     return sal_True;
144 }
145 
146 sal_Bool SvxDrawOutlinerViewForwarder::SetSelection( const ESelection& rSelection )
147 {
148     mrOutlinerView.SetSelection( rSelection );
149     return sal_True;
150 }
151 
152 sal_Bool SvxDrawOutlinerViewForwarder::Copy()
153 {
154     mrOutlinerView.Copy();
155     return sal_True;
156 }
157 
158 sal_Bool SvxDrawOutlinerViewForwarder::Cut()
159 {
160     mrOutlinerView.Cut();
161     return sal_True;
162 }
163 
164 sal_Bool SvxDrawOutlinerViewForwarder::Paste()
165 {
166     mrOutlinerView.Paste();
167     return sal_True;
168 }
169 
170 void SvxDrawOutlinerViewForwarder::SetShapePos( const Point& rShapePosTopLeft )
171 {
172     maTextShapeTopLeft = rShapePosTopLeft;
173 }
174