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_svtools.hxx"
26 
27 #include "svtools/table/tablecontrol.hxx"
28 
29 #include "tabledatawindow.hxx"
30 #include "tablecontrol_impl.hxx"
31 #include "tablegeometry.hxx"
32 
33 #include <vcl/help.hxx>
34 
35 //......................................................................................................................
36 namespace svt { namespace table
37 {
38 //......................................................................................................................
39 
40     /** === begin UNO using === **/
41     using ::com::sun::star::uno::Any;
42     /** === end UNO using === **/
43 
44 	//==================================================================================================================
45 	//= TableDataWindow
46 	//==================================================================================================================
47 	//------------------------------------------------------------------------------------------------------------------
TableDataWindow(TableControl_Impl & _rTableControl)48     TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl )
49         :Window( &_rTableControl.getAntiImpl() )
50         ,m_rTableControl( _rTableControl )
51         ,m_nTipWindowHandle( 0 )
52 	{
53         // by default, use the background as determined by the style settings
54         const Color aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
55 		SetBackground( Wallpaper( aWindowColor ) );
56 		SetFillColor( aWindowColor );
57     }
58 
59 	//------------------------------------------------------------------------------------------------------------------
~TableDataWindow()60     TableDataWindow::~TableDataWindow()
61     {
62         impl_hideTipWindow();
63     }
64 
65     //------------------------------------------------------------------------------------------------------------------
Paint(const Rectangle & rUpdateRect)66     void TableDataWindow::Paint( const Rectangle& rUpdateRect )
67     {
68         m_rTableControl.doPaintContent( rUpdateRect );
69     }
70 	//------------------------------------------------------------------------------------------------------------------
SetBackground(const Wallpaper & rColor)71     void TableDataWindow::SetBackground( const Wallpaper& rColor )
72     {
73 		Window::SetBackground( rColor );
74     }
75 	//------------------------------------------------------------------------------------------------------------------
SetControlBackground(const Color & rColor)76     void TableDataWindow::SetControlBackground( const Color& rColor )
77     {
78 		Window::SetControlBackground( rColor );
79     }
80 	//------------------------------------------------------------------------------------------------------------------
SetBackground()81     void TableDataWindow::SetBackground()
82     {
83 		Window::SetBackground();
84     }
85 	//------------------------------------------------------------------------------------------------------------------
SetControlBackground()86     void TableDataWindow::SetControlBackground()
87     {
88 		Window::SetControlBackground();
89     }
90 
91     //------------------------------------------------------------------------------------------------------------------
RequestHelp(const HelpEvent & rHEvt)92     void TableDataWindow::RequestHelp( const HelpEvent& rHEvt )
93     {
94         sal_uInt16 const nHelpMode = rHEvt.GetMode();
95         if  (   ( IsMouseCaptured() )
96             ||  ( ( nHelpMode & HELPMODE_QUICK ) == 0 )
97             )
98         {
99             Window::RequestHelp( rHEvt );
100             return;
101         }
102 
103         ::rtl::OUString sHelpText;
104         sal_uInt16 nHelpStyle = 0;
105 
106         Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
107         RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos );
108         ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos );
109 
110         PTableModel const pTableModel( m_rTableControl.getModel() );
111         if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) )
112         {
113             if ( hitRow == ROW_COL_HEADERS )
114             {
115                 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText();
116             }
117             else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) )
118             {
119                 Any aCellToolTip;
120                 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip );
121                 if ( !aCellToolTip.hasValue() )
122                 {
123                     // use the cell content
124                     pTableModel->getCellContent( hitCol, hitRow, aCellToolTip );
125 
126                     // use the cell content as tool tip only if it doesn't fit into the cell.
127                     bool const activeCell = ( hitRow == m_rTableControl.getCurrentRow() ) && ( hitCol == m_rTableControl.getCurrentColumn() );
128                     bool const selectedCell = m_rTableControl.isRowSelected( hitRow );
129 
130                     Rectangle const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
131                     TableCellGeometry const aCell( m_rTableControl, aWindowRect, hitCol, hitRow );
132                     Rectangle const aCellRect( aCell.getRect() );
133 
134                     PTableRenderer const pRenderer = pTableModel->getRenderer();
135                     if ( pRenderer->FitsIntoCell( aCellToolTip, hitCol, hitRow, activeCell, selectedCell, *this, aCellRect ) )
136                         aCellToolTip.clear();
137                 }
138 
139                 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, hitCol, hitRow, sHelpText );
140 
141                 if ( sHelpText.indexOf( '\n' ) >= 0 )
142                     nHelpStyle = QUICKHELP_TIP_STYLE_BALLOON;
143             }
144         }
145 
146         if ( sHelpText.getLength() )
147         {
148             // hide the standard (singleton) help window, so we do not have two help windows open at the same time
149             Help::HideBalloonAndQuickHelp();
150 
151             Rectangle const aControlScreenRect(
152                 OutputToScreenPixel( Point( 0, 0 ) ),
153                 GetOutputSizePixel()
154             );
155 
156             if ( m_nTipWindowHandle )
157             {
158                 Help::UpdateTip( m_nTipWindowHandle, this, aControlScreenRect, sHelpText );
159             }
160             else
161                 m_nTipWindowHandle = Help::ShowTip( this, aControlScreenRect, sHelpText, nHelpStyle );
162         }
163         else
164         {
165             impl_hideTipWindow();
166             Window::RequestHelp( rHEvt );
167         }
168     }
169 
170     //------------------------------------------------------------------------------------------------------------------
impl_hideTipWindow()171     void TableDataWindow::impl_hideTipWindow()
172     {
173         if ( m_nTipWindowHandle != 0 )
174         {
175             Help::HideTip( m_nTipWindowHandle );
176             m_nTipWindowHandle = 0;
177         }
178     }
179 
180     //------------------------------------------------------------------------------------------------------------------
MouseMove(const MouseEvent & rMEvt)181     void TableDataWindow::MouseMove( const MouseEvent& rMEvt )
182     {
183         if ( rMEvt.IsLeaveWindow() )
184             impl_hideTipWindow();
185 
186 		if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
187 		{
188 			Window::MouseMove( rMEvt );
189 		}
190     }
191     //------------------------------------------------------------------------------------------------------------------
MouseButtonDown(const MouseEvent & rMEvt)192     void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt )
193     {
194         impl_hideTipWindow();
195 
196 	    Point const aPoint = rMEvt.GetPosPixel();
197 	    RowPos const hitRow = m_rTableControl.getRowAtPoint( aPoint );
198         bool const wasRowSelected = m_rTableControl.isRowSelected( hitRow );
199         size_t const nPrevSelRowCount = m_rTableControl.getSelectedRowCount();
200 
201         if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) )
202         {
203 			Window::MouseButtonDown( rMEvt );
204             return;
205         }
206 
207         bool const isRowSelected = m_rTableControl.isRowSelected( hitRow );
208         size_t const nCurSelRowCount = m_rTableControl.getSelectedRowCount();
209         if ( isRowSelected != wasRowSelected || nCurSelRowCount != nPrevSelRowCount )
210         {
211 			m_aSelectHdl.Call( NULL );
212 		}
213     }
214 
215     //------------------------------------------------------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)216     void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt )
217     {
218         if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
219             Window::MouseButtonUp( rMEvt );
220 
221 	    m_rTableControl.getAntiImpl().GrabFocus();
222     }
223 
224 	//------------------------------------------------------------------------------------------------------------------
Notify(NotifyEvent & rNEvt)225 	long TableDataWindow::Notify(NotifyEvent& rNEvt )
226 	{
227 		long nDone = 0;
228 		if ( rNEvt.GetType() == EVENT_COMMAND )
229 		{
230 			const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
231 			if ( rCEvt.GetCommand() == COMMAND_WHEEL )
232 			{
233 				const CommandWheelData* pData = rCEvt.GetWheelData();
234 				if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) )
235 				{
236 					nDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
237 				}
238 			}
239 		}
240 		return nDone ? nDone : Window::Notify( rNEvt );
241 	}
242 //......................................................................................................................
243 } } // namespace svt::table
244 //......................................................................................................................
245