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