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_chart2.hxx"
30 #include "ChartWindow.hxx"
31 #include "ChartController.hxx"
32 #include "HelpIds.hrc"
33 
34 #include <vcl/help.hxx>
35 
36 using namespace ::com::sun::star;
37 
38 namespace
39 {
40 ::Rectangle lcl_AWTRectToVCLRect( const ::com::sun::star::awt::Rectangle & rAWTRect )
41 {
42     ::Rectangle aResult;
43     aResult.setX( rAWTRect.X );
44     aResult.setY( rAWTRect.Y );
45     aResult.setWidth( rAWTRect.Width );
46     aResult.setHeight( rAWTRect.Height );
47     return aResult;
48 }
49 } // anonymous namespace
50 
51 
52 //.............................................................................
53 namespace chart
54 {
55 //.............................................................................
56 
57 ChartWindow::ChartWindow( WindowController* pWindowController, Window* pParent, WinBits nStyle )
58         : Window(pParent, nStyle)
59         , m_pWindowController( pWindowController )
60         , m_bInPaint(false)
61 {
62     this->SetHelpId( HID_SCH_WIN_DOCUMENT );
63     this->SetMapMode( MapMode(MAP_100TH_MM) );
64     adjustHighContrastMode();
65     // chart does not depend on exact pixel painting => enable antialiased drawing
66     SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | GetAntialiasing() );
67     EnableRTL( sal_False );
68     if( pParent )
69         pParent->EnableRTL( sal_False );// #i96215# necessary for a correct position of the context menu in rtl mode
70 }
71 
72 ChartWindow::~ChartWindow()
73 {
74 }
75 
76 void ChartWindow::clear()
77 {
78     m_pWindowController=0;
79     this->ReleaseMouse();
80 }
81 
82 void ChartWindow::PrePaint()
83 {
84     // forward VCLs PrePaint window event to DrawingLayer
85     if( m_pWindowController )
86     {
87         m_pWindowController->PrePaint();
88     }
89 }
90 
91 void ChartWindow::Paint( const Rectangle& rRect )
92 {
93     m_bInPaint = true;
94     if( m_pWindowController )
95         m_pWindowController->execute_Paint( rRect );
96     else
97         Window::Paint( rRect );
98     m_bInPaint = false;
99 }
100 
101 void ChartWindow::MouseButtonDown(const MouseEvent& rMEvt)
102 {
103     if( m_pWindowController )
104         m_pWindowController->execute_MouseButtonDown(rMEvt);
105     else
106         Window::MouseButtonDown(rMEvt);
107 }
108 
109 void ChartWindow::MouseMove( const MouseEvent& rMEvt )
110 {
111     if( m_pWindowController )
112         m_pWindowController->execute_MouseMove( rMEvt );
113     else
114         Window::MouseMove( rMEvt );
115 }
116 
117 void ChartWindow::Tracking( const TrackingEvent& rTEvt )
118 {
119     if( m_pWindowController )
120         m_pWindowController->execute_Tracking( rTEvt );
121     else
122         Window::Tracking( rTEvt );
123 }
124 
125 void ChartWindow::MouseButtonUp( const MouseEvent& rMEvt )
126 {
127     if( m_pWindowController )
128         m_pWindowController->execute_MouseButtonUp( rMEvt );
129     else
130         Window::MouseButtonUp( rMEvt );
131 }
132 
133 void ChartWindow::Resize()
134 {
135     if( m_pWindowController )
136         m_pWindowController->execute_Resize();
137     else
138         Window::Resize();
139 }
140 
141 void ChartWindow::Activate()
142 {
143     if( m_pWindowController )
144         m_pWindowController->execute_Activate();
145     else
146         Window::Activate();
147 }
148 void ChartWindow::Deactivate()
149 {
150     if( m_pWindowController )
151         m_pWindowController->execute_Deactivate();
152     else
153         Window::Deactivate();
154 }
155 void ChartWindow::GetFocus()
156 {
157     if( m_pWindowController )
158         m_pWindowController->execute_GetFocus();
159     else
160         Window::GetFocus();
161 }
162 void ChartWindow::LoseFocus()
163 {
164     if( m_pWindowController )
165         m_pWindowController->execute_LoseFocus();
166     else
167         Window::LoseFocus();
168 }
169 
170 void ChartWindow::Command( const CommandEvent& rCEvt )
171 {
172     if( m_pWindowController )
173         m_pWindowController->execute_Command( rCEvt );
174     else
175         Window::Command( rCEvt );
176 }
177 
178 void ChartWindow::KeyInput( const KeyEvent& rKEvt )
179 {
180     if( m_pWindowController )
181     {
182         if( !m_pWindowController->execute_KeyInput(rKEvt) )
183             Window::KeyInput(rKEvt);
184     }
185     else
186         Window::KeyInput( rKEvt );
187 }
188 
189 uno::Reference< accessibility::XAccessible > ChartWindow::CreateAccessible()
190 {
191     if( m_pWindowController )
192         return m_pWindowController->CreateAccessible();
193     else
194         return Window::CreateAccessible();
195 }
196 
197 void ChartWindow::DataChanged( const DataChangedEvent& rDCEvt )
198 {
199 	::Window::DataChanged( rDCEvt );
200 
201     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
202          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
203     {
204         adjustHighContrastMode();
205     }
206 }
207 
208 void ChartWindow::RequestHelp( const HelpEvent& rHEvt )
209 {
210     bool bHelpHandled = false;
211 	if( ( rHEvt.GetMode() & HELPMODE_QUICK ) &&
212         m_pWindowController )
213     {
214 //         Point aLogicHitPos = PixelToLogic( rHEvt.GetMousePosPixel()); // old chart: GetPointerPosPixel()
215         Point aLogicHitPos = PixelToLogic( GetPointerPosPixel());
216         ::rtl::OUString aQuickHelpText;
217         awt::Rectangle aHelpRect;
218         bool bIsBalloonHelp( Help::IsBalloonHelpEnabled() );
219         bHelpHandled = m_pWindowController->requestQuickHelp( aLogicHitPos, bIsBalloonHelp, aQuickHelpText, aHelpRect );
220 
221         if( bHelpHandled )
222         {
223             if( bIsBalloonHelp )
224                 Help::ShowBalloon(
225                     this, rHEvt.GetMousePosPixel(), lcl_AWTRectToVCLRect( aHelpRect ), String( aQuickHelpText ));
226             else
227                 Help::ShowQuickHelp(
228                     this, lcl_AWTRectToVCLRect( aHelpRect ), String( aQuickHelpText ));
229         }
230     }
231 
232     if( !bHelpHandled )
233         ::Window::RequestHelp( rHEvt );
234 }
235 
236 void ChartWindow::adjustHighContrastMode()
237 {
238     static const sal_Int32 nContrastMode =
239         DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
240         DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT;
241 
242     bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
243     SetDrawMode( bUseContrast ? nContrastMode : DRAWMODE_DEFAULT );
244 }
245 
246 void ChartWindow::ForceInvalidate()
247 {
248     ::Window::Invalidate();
249 }
250 void ChartWindow::Invalidate( sal_uInt16 nFlags )
251 {
252     if( m_bInPaint ) // #i101928# superfluous paint calls while entering and editing charts"
253         return;
254     ::Window::Invalidate( nFlags );
255 }
256 void ChartWindow::Invalidate( const Rectangle& rRect, sal_uInt16 nFlags )
257 {
258     if( m_bInPaint ) // #i101928# superfluous paint calls while entering and editing charts"
259         return;
260     ::Window::Invalidate( rRect, nFlags );
261 }
262 void ChartWindow::Invalidate( const Region& rRegion, sal_uInt16 nFlags )
263 {
264     if( m_bInPaint ) // #i101928# superfluous paint calls while entering and editing charts"
265         return;
266     ::Window::Invalidate( rRegion, nFlags );
267 }
268 
269 //.............................................................................
270 } //namespace chart
271 //.............................................................................
272