15900e8ecSAndrew Rist /**************************************************************
25900e8ecSAndrew Rist  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
105900e8ecSAndrew Rist  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
195900e8ecSAndrew Rist  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "svtools/table/tablecontrol.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "tabledatawindow.hxx"
30cdf0e10cSrcweir #include "tablecontrol_impl.hxx"
31cdf0e10cSrcweir #include "tablegeometry.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/help.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //......................................................................................................................
36cdf0e10cSrcweir namespace svt { namespace table
37cdf0e10cSrcweir {
38cdf0e10cSrcweir //......................................................................................................................
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     /** === begin UNO using === **/
41cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
42cdf0e10cSrcweir     /** === end UNO using === **/
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	//==================================================================================================================
45cdf0e10cSrcweir 	//= TableDataWindow
46cdf0e10cSrcweir 	//==================================================================================================================
47cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
TableDataWindow(TableControl_Impl & _rTableControl)48cdf0e10cSrcweir     TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl )
49cdf0e10cSrcweir         :Window( &_rTableControl.getAntiImpl() )
50cdf0e10cSrcweir         ,m_rTableControl( _rTableControl )
51cdf0e10cSrcweir         ,m_nTipWindowHandle( 0 )
52cdf0e10cSrcweir 	{
53cdf0e10cSrcweir         // by default, use the background as determined by the style settings
54cdf0e10cSrcweir         const Color aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
55cdf0e10cSrcweir 		SetBackground( Wallpaper( aWindowColor ) );
56cdf0e10cSrcweir 		SetFillColor( aWindowColor );
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~TableDataWindow()60cdf0e10cSrcweir     TableDataWindow::~TableDataWindow()
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         impl_hideTipWindow();
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
Paint(const Rectangle & rUpdateRect)66cdf0e10cSrcweir     void TableDataWindow::Paint( const Rectangle& rUpdateRect )
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         m_rTableControl.doPaintContent( rUpdateRect );
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
SetBackground(const Wallpaper & rColor)71cdf0e10cSrcweir     void TableDataWindow::SetBackground( const Wallpaper& rColor )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir 		Window::SetBackground( rColor );
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
SetControlBackground(const Color & rColor)76cdf0e10cSrcweir     void TableDataWindow::SetControlBackground( const Color& rColor )
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir 		Window::SetControlBackground( rColor );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
SetBackground()81cdf0e10cSrcweir     void TableDataWindow::SetBackground()
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir 		Window::SetBackground();
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
SetControlBackground()86cdf0e10cSrcweir     void TableDataWindow::SetControlBackground()
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir 		Window::SetControlBackground();
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
RequestHelp(const HelpEvent & rHEvt)92cdf0e10cSrcweir     void TableDataWindow::RequestHelp( const HelpEvent& rHEvt )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         sal_uInt16 const nHelpMode = rHEvt.GetMode();
95cdf0e10cSrcweir         if  (   ( IsMouseCaptured() )
96cdf0e10cSrcweir             ||  ( ( nHelpMode & HELPMODE_QUICK ) == 0 )
97cdf0e10cSrcweir             )
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             Window::RequestHelp( rHEvt );
100cdf0e10cSrcweir             return;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         ::rtl::OUString sHelpText;
104cdf0e10cSrcweir         sal_uInt16 nHelpStyle = 0;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
107cdf0e10cSrcweir         RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos );
108cdf0e10cSrcweir         ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         PTableModel const pTableModel( m_rTableControl.getModel() );
111cdf0e10cSrcweir         if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) )
112cdf0e10cSrcweir         {
113cdf0e10cSrcweir             if ( hitRow == ROW_COL_HEADERS )
114cdf0e10cSrcweir             {
115cdf0e10cSrcweir                 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText();
116cdf0e10cSrcweir             }
117cdf0e10cSrcweir             else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) )
118cdf0e10cSrcweir             {
119cdf0e10cSrcweir                 Any aCellToolTip;
120cdf0e10cSrcweir                 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip );
121cdf0e10cSrcweir                 if ( !aCellToolTip.hasValue() )
122cdf0e10cSrcweir                 {
123cdf0e10cSrcweir                     // use the cell content
124cdf0e10cSrcweir                     pTableModel->getCellContent( hitCol, hitRow, aCellToolTip );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir                     // use the cell content as tool tip only if it doesn't fit into the cell.
127cdf0e10cSrcweir                     bool const activeCell = ( hitRow == m_rTableControl.getCurrentRow() ) && ( hitCol == m_rTableControl.getCurrentColumn() );
128cdf0e10cSrcweir                     bool const selectedCell = m_rTableControl.isRowSelected( hitRow );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir                     Rectangle const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
131cdf0e10cSrcweir                     TableCellGeometry const aCell( m_rTableControl, aWindowRect, hitCol, hitRow );
132cdf0e10cSrcweir                     Rectangle const aCellRect( aCell.getRect() );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir                     PTableRenderer const pRenderer = pTableModel->getRenderer();
135cdf0e10cSrcweir                     if ( pRenderer->FitsIntoCell( aCellToolTip, hitCol, hitRow, activeCell, selectedCell, *this, aCellRect ) )
136cdf0e10cSrcweir                         aCellToolTip.clear();
137cdf0e10cSrcweir                 }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir                 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, hitCol, hitRow, sHelpText );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir                 if ( sHelpText.indexOf( '\n' ) >= 0 )
142cdf0e10cSrcweir                     nHelpStyle = QUICKHELP_TIP_STYLE_BALLOON;
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         if ( sHelpText.getLength() )
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             // hide the standard (singleton) help window, so we do not have two help windows open at the same time
149cdf0e10cSrcweir             Help::HideBalloonAndQuickHelp();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             Rectangle const aControlScreenRect(
152cdf0e10cSrcweir                 OutputToScreenPixel( Point( 0, 0 ) ),
153cdf0e10cSrcweir                 GetOutputSizePixel()
154cdf0e10cSrcweir             );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             if ( m_nTipWindowHandle )
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 Help::UpdateTip( m_nTipWindowHandle, this, aControlScreenRect, sHelpText );
159cdf0e10cSrcweir             }
160cdf0e10cSrcweir             else
161cdf0e10cSrcweir                 m_nTipWindowHandle = Help::ShowTip( this, aControlScreenRect, sHelpText, nHelpStyle );
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir         else
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             impl_hideTipWindow();
166cdf0e10cSrcweir             Window::RequestHelp( rHEvt );
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_hideTipWindow()171cdf0e10cSrcweir     void TableDataWindow::impl_hideTipWindow()
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         if ( m_nTipWindowHandle != 0 )
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             Help::HideTip( m_nTipWindowHandle );
176cdf0e10cSrcweir             m_nTipWindowHandle = 0;
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
MouseMove(const MouseEvent & rMEvt)181cdf0e10cSrcweir     void TableDataWindow::MouseMove( const MouseEvent& rMEvt )
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         if ( rMEvt.IsLeaveWindow() )
184cdf0e10cSrcweir             impl_hideTipWindow();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
187cdf0e10cSrcweir 		{
188cdf0e10cSrcweir 			Window::MouseMove( rMEvt );
189cdf0e10cSrcweir 		}
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
MouseButtonDown(const MouseEvent & rMEvt)192cdf0e10cSrcweir     void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt )
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         impl_hideTipWindow();
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	    Point const aPoint = rMEvt.GetPosPixel();
197cdf0e10cSrcweir 	    RowPos const hitRow = m_rTableControl.getRowAtPoint( aPoint );
198cdf0e10cSrcweir         bool const wasRowSelected = m_rTableControl.isRowSelected( hitRow );
199*90f3badfSAriel Constenla-Haile         size_t const nPrevSelRowCount = m_rTableControl.getSelectedRowCount();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) )
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir 			Window::MouseButtonDown( rMEvt );
204cdf0e10cSrcweir             return;
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         bool const isRowSelected = m_rTableControl.isRowSelected( hitRow );
208*90f3badfSAriel Constenla-Haile         size_t const nCurSelRowCount = m_rTableControl.getSelectedRowCount();
209*90f3badfSAriel Constenla-Haile         if ( isRowSelected != wasRowSelected || nCurSelRowCount != nPrevSelRowCount )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir 			m_aSelectHdl.Call( NULL );
212cdf0e10cSrcweir 		}
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)216cdf0e10cSrcweir     void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
219cdf0e10cSrcweir             Window::MouseButtonUp( rMEvt );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	    m_rTableControl.getAntiImpl().GrabFocus();
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
Notify(NotifyEvent & rNEvt)225cdf0e10cSrcweir 	long TableDataWindow::Notify(NotifyEvent& rNEvt )
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		long nDone = 0;
228cdf0e10cSrcweir 		if ( rNEvt.GetType() == EVENT_COMMAND )
229cdf0e10cSrcweir 		{
230cdf0e10cSrcweir 			const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
231cdf0e10cSrcweir 			if ( rCEvt.GetCommand() == COMMAND_WHEEL )
232cdf0e10cSrcweir 			{
233cdf0e10cSrcweir 				const CommandWheelData* pData = rCEvt.GetWheelData();
234cdf0e10cSrcweir 				if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) )
235cdf0e10cSrcweir 				{
236cdf0e10cSrcweir 					nDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
237cdf0e10cSrcweir 				}
238cdf0e10cSrcweir 			}
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 		return nDone ? nDone : Window::Notify( rNEvt );
241cdf0e10cSrcweir 	}
242cdf0e10cSrcweir //......................................................................................................................
243cdf0e10cSrcweir } } // namespace svt::table
244cdf0e10cSrcweir //......................................................................................................................
245