1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "svtools/table/tablecontrol.hxx"
23 #include "tabledatawindow.hxx"
24 #include "tablecontrol_impl.hxx"
25 #include "tablegeometry.hxx"
27 #include <vcl/help.hxx>
29 //......................................................................................................................
30 namespace svt
{ namespace table
32 //......................................................................................................................
34 using ::com::sun::star::uno::Any
;
36 //==================================================================================================================
38 //==================================================================================================================
39 //------------------------------------------------------------------------------------------------------------------
40 TableDataWindow::TableDataWindow( TableControl_Impl
& _rTableControl
)
41 :Window( &_rTableControl
.getAntiImpl() )
42 ,m_rTableControl( _rTableControl
)
43 ,m_nTipWindowHandle( 0 )
45 // by default, use the background as determined by the style settings
46 const Color
aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
47 SetBackground( Wallpaper( aWindowColor
) );
48 SetFillColor( aWindowColor
);
51 //------------------------------------------------------------------------------------------------------------------
52 TableDataWindow::~TableDataWindow()
57 //------------------------------------------------------------------------------------------------------------------
58 void TableDataWindow::Paint( const Rectangle
& rUpdateRect
)
60 m_rTableControl
.doPaintContent( rUpdateRect
);
62 //------------------------------------------------------------------------------------------------------------------
63 void TableDataWindow::SetBackground( const Wallpaper
& rColor
)
65 Window::SetBackground( rColor
);
67 //------------------------------------------------------------------------------------------------------------------
68 void TableDataWindow::SetControlBackground( const Color
& rColor
)
70 Window::SetControlBackground( rColor
);
72 //------------------------------------------------------------------------------------------------------------------
73 void TableDataWindow::SetControlBackground()
75 Window::SetControlBackground();
78 //------------------------------------------------------------------------------------------------------------------
79 void TableDataWindow::RequestHelp( const HelpEvent
& rHEvt
)
81 sal_uInt16
const nHelpMode
= rHEvt
.GetMode();
82 if ( ( IsMouseCaptured() )
83 || ( ( nHelpMode
& HELPMODE_QUICK
) == 0 )
86 Window::RequestHelp( rHEvt
);
91 sal_uInt16 nHelpStyle
= 0;
93 Point
const aMousePos( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
94 RowPos
const hitRow
= m_rTableControl
.getRowAtPoint( aMousePos
);
95 ColPos
const hitCol
= m_rTableControl
.getColAtPoint( aMousePos
);
97 PTableModel
const pTableModel( m_rTableControl
.getModel() );
98 if ( ( hitCol
>= 0 ) && ( hitCol
< pTableModel
->getColumnCount() ) )
100 if ( hitRow
== ROW_COL_HEADERS
)
102 sHelpText
= pTableModel
->getColumnModel( hitCol
)->getHelpText();
104 else if ( ( hitRow
>= 0 ) && ( hitRow
< pTableModel
->getRowCount() ) )
107 pTableModel
->getCellToolTip( hitCol
, hitRow
, aCellToolTip
);
108 if ( !aCellToolTip
.hasValue() )
110 // use the cell content
111 pTableModel
->getCellContent( hitCol
, hitRow
, aCellToolTip
);
113 // use the cell content as tool tip only if it doesn't fit into the cell.
114 bool const activeCell
= ( hitRow
== m_rTableControl
.getCurrentRow() ) && ( hitCol
== m_rTableControl
.getCurrentColumn() );
115 bool const selectedCell
= m_rTableControl
.isRowSelected( hitRow
);
117 Rectangle
const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
118 TableCellGeometry
const aCell( m_rTableControl
, aWindowRect
, hitCol
, hitRow
);
119 Rectangle
const aCellRect( aCell
.getRect() );
121 PTableRenderer
const pRenderer
= pTableModel
->getRenderer();
122 if ( pRenderer
->FitsIntoCell( aCellToolTip
, hitCol
, hitRow
, activeCell
, selectedCell
, *this, aCellRect
) )
123 aCellToolTip
.clear();
126 pTableModel
->getRenderer()->GetFormattedCellString( aCellToolTip
, hitCol
, hitRow
, sHelpText
);
128 if ( sHelpText
.indexOf( '\n' ) >= 0 )
129 nHelpStyle
= QUICKHELP_TIP_STYLE_BALLOON
;
133 if ( !sHelpText
.isEmpty() )
135 // hide the standard (singleton) help window, so we do not have two help windows open at the same time
136 Help::HideBalloonAndQuickHelp();
138 Rectangle
const aControlScreenRect(
139 OutputToScreenPixel( Point( 0, 0 ) ),
143 if ( m_nTipWindowHandle
)
145 Help::UpdateTip( m_nTipWindowHandle
, this, aControlScreenRect
, sHelpText
);
148 m_nTipWindowHandle
= Help::ShowTip( this, aControlScreenRect
, sHelpText
, nHelpStyle
);
152 impl_hideTipWindow();
153 Window::RequestHelp( rHEvt
);
157 //------------------------------------------------------------------------------------------------------------------
158 void TableDataWindow::impl_hideTipWindow()
160 if ( m_nTipWindowHandle
!= 0 )
162 Help::HideTip( m_nTipWindowHandle
);
163 m_nTipWindowHandle
= 0;
167 //------------------------------------------------------------------------------------------------------------------
168 void TableDataWindow::MouseMove( const MouseEvent
& rMEvt
)
170 if ( rMEvt
.IsLeaveWindow() )
171 impl_hideTipWindow();
173 if ( !m_rTableControl
.getInputHandler()->MouseMove( m_rTableControl
, rMEvt
) )
175 Window::MouseMove( rMEvt
);
178 //------------------------------------------------------------------------------------------------------------------
179 void TableDataWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
181 impl_hideTipWindow();
183 Point
const aPoint
= rMEvt
.GetPosPixel();
184 RowPos
const hitRow
= m_rTableControl
.getRowAtPoint( aPoint
);
185 bool const wasRowSelected
= m_rTableControl
.isRowSelected( hitRow
);
186 size_t const nPrevSelRowCount
= m_rTableControl
.getSelectedRowCount();
188 if ( !m_rTableControl
.getInputHandler()->MouseButtonDown( m_rTableControl
, rMEvt
) )
190 Window::MouseButtonDown( rMEvt
);
194 bool const isRowSelected
= m_rTableControl
.isRowSelected( hitRow
);
195 size_t const nCurSelRowCount
= m_rTableControl
.getSelectedRowCount();
196 if ( isRowSelected
!= wasRowSelected
|| nCurSelRowCount
!= nPrevSelRowCount
)
198 m_aSelectHdl
.Call( NULL
);
202 //------------------------------------------------------------------------------------------------------------------
203 void TableDataWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
205 if ( !m_rTableControl
.getInputHandler()->MouseButtonUp( m_rTableControl
, rMEvt
) )
206 Window::MouseButtonUp( rMEvt
);
208 m_rTableControl
.getAntiImpl().GrabFocus();
211 //------------------------------------------------------------------------------------------------------------------
212 long TableDataWindow::Notify(NotifyEvent
& rNEvt
)
215 if ( rNEvt
.GetType() == EVENT_COMMAND
)
217 const CommandEvent
& rCEvt
= *rNEvt
.GetCommandEvent();
218 if ( rCEvt
.GetCommand() == COMMAND_WHEEL
)
220 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
221 if( !pData
->GetModifier() && ( pData
->GetMode() == COMMAND_WHEEL_SCROLL
) )
223 nDone
= HandleScrollCommand( rCEvt
, m_rTableControl
.getHorzScrollbar(), m_rTableControl
.getVertScrollbar() );
227 return nDone
? nDone
: Window::Notify( rNEvt
);
229 //......................................................................................................................
230 } } // namespace svt::table
231 //......................................................................................................................
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */