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