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 .
20 #include "table/tablecontrol.hxx"
22 #include "tabledatawindow.hxx"
23 #include "tablecontrol_impl.hxx"
24 #include "tablegeometry.hxx"
26 #include <vcl/help.hxx>
27 #include <vcl/settings.hxx>
29 namespace svt
{ namespace table
33 TableDataWindow::TableDataWindow( TableControl_Impl
& _rTableControl
)
34 :Window( &_rTableControl
.getAntiImpl() )
35 ,m_rTableControl( _rTableControl
)
36 ,m_nTipWindowHandle( 0 )
38 // by default, use the background as determined by the style settings
39 const Color
aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
40 SetBackground( Wallpaper( aWindowColor
) );
41 SetFillColor( aWindowColor
);
44 TableDataWindow::~TableDataWindow()
49 void TableDataWindow::dispose()
55 void TableDataWindow::Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& rUpdateRect
)
57 m_rTableControl
.doPaintContent(rRenderContext
, rUpdateRect
);
60 void TableDataWindow::SetBackground( const Wallpaper
& rColor
)
62 Window::SetBackground( rColor
);
65 void TableDataWindow::RequestHelp( const HelpEvent
& rHEvt
)
67 HelpEventMode
const nHelpMode
= rHEvt
.GetMode();
68 if ( IsMouseCaptured()
69 || !( nHelpMode
& HelpEventMode::QUICK
)
72 Window::RequestHelp( rHEvt
);
77 QuickHelpFlags nHelpStyle
= QuickHelpFlags::NONE
;
79 Point
const aMousePos( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
80 RowPos
const hitRow
= m_rTableControl
.getRowAtPoint( aMousePos
);
81 ColPos
const hitCol
= m_rTableControl
.getColAtPoint( aMousePos
);
83 PTableModel
const pTableModel( m_rTableControl
.getModel() );
84 if ( ( hitCol
>= 0 ) && ( hitCol
< pTableModel
->getColumnCount() ) )
86 if ( hitRow
== ROW_COL_HEADERS
)
88 sHelpText
= pTableModel
->getColumnModel( hitCol
)->getHelpText();
90 else if ( ( hitRow
>= 0 ) && ( hitRow
< pTableModel
->getRowCount() ) )
93 pTableModel
->getCellToolTip( hitCol
, hitRow
, aCellToolTip
);
94 if ( !aCellToolTip
.hasValue() )
96 // use the cell content
97 pTableModel
->getCellContent( hitCol
, hitRow
, aCellToolTip
);
99 // use the cell content as tool tip only if it doesn't fit into the cell.
100 bool const activeCell
= ( hitRow
== m_rTableControl
.getCurrentRow() ) && ( hitCol
== m_rTableControl
.getCurrentColumn() );
101 bool const selectedCell
= m_rTableControl
.isRowSelected( hitRow
);
103 Rectangle
const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
104 TableCellGeometry
const aCell( m_rTableControl
, aWindowRect
, hitCol
, hitRow
);
105 Rectangle
const aCellRect( aCell
.getRect() );
107 PTableRenderer
const pRenderer
= pTableModel
->getRenderer();
108 if ( pRenderer
->FitsIntoCell( aCellToolTip
, hitCol
, hitRow
, activeCell
, selectedCell
, *this, aCellRect
) )
109 aCellToolTip
.clear();
112 pTableModel
->getRenderer()->GetFormattedCellString( aCellToolTip
, hitCol
, hitRow
, sHelpText
);
114 if ( sHelpText
.indexOf( '\n' ) >= 0 )
115 nHelpStyle
= QuickHelpFlags::TipStyleBalloon
;
119 if ( !sHelpText
.isEmpty() )
121 // hide the standard (singleton) help window, so we do not have two help windows open at the same time
122 Help::HideBalloonAndQuickHelp();
124 Rectangle
const aControlScreenRect(
125 OutputToScreenPixel( Point( 0, 0 ) ),
129 if ( m_nTipWindowHandle
)
131 Help::UpdateTip( m_nTipWindowHandle
, this, aControlScreenRect
, sHelpText
);
134 m_nTipWindowHandle
= Help::ShowTip( this, aControlScreenRect
, sHelpText
, nHelpStyle
);
138 impl_hideTipWindow();
139 Window::RequestHelp( rHEvt
);
144 void TableDataWindow::impl_hideTipWindow()
146 if ( m_nTipWindowHandle
!= 0 )
148 Help::HideTip( m_nTipWindowHandle
);
149 m_nTipWindowHandle
= 0;
154 void TableDataWindow::MouseMove( const MouseEvent
& rMEvt
)
156 if ( rMEvt
.IsLeaveWindow() )
157 impl_hideTipWindow();
159 if ( !m_rTableControl
.getInputHandler()->MouseMove( m_rTableControl
, rMEvt
) )
161 Window::MouseMove( rMEvt
);
165 void TableDataWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
167 impl_hideTipWindow();
169 Point
const aPoint
= rMEvt
.GetPosPixel();
170 RowPos
const hitRow
= m_rTableControl
.getRowAtPoint( aPoint
);
171 bool const wasRowSelected
= m_rTableControl
.isRowSelected( hitRow
);
172 size_t const nPrevSelRowCount
= m_rTableControl
.getSelectedRowCount();
174 if ( !m_rTableControl
.getInputHandler()->MouseButtonDown( m_rTableControl
, rMEvt
) )
176 Window::MouseButtonDown( rMEvt
);
180 bool const isRowSelected
= m_rTableControl
.isRowSelected( hitRow
);
181 size_t const nCurSelRowCount
= m_rTableControl
.getSelectedRowCount();
182 if ( isRowSelected
!= wasRowSelected
|| nCurSelRowCount
!= nPrevSelRowCount
)
184 m_aSelectHdl
.Call( NULL
);
189 void TableDataWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
191 if ( !m_rTableControl
.getInputHandler()->MouseButtonUp( m_rTableControl
, rMEvt
) )
192 Window::MouseButtonUp( rMEvt
);
194 m_rTableControl
.getAntiImpl().GrabFocus();
198 bool TableDataWindow::Notify(NotifyEvent
& rNEvt
)
201 if ( rNEvt
.GetType() == MouseNotifyEvent::COMMAND
)
203 const CommandEvent
& rCEvt
= *rNEvt
.GetCommandEvent();
204 if ( rCEvt
.GetCommand() == CommandEventId::Wheel
)
206 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
207 if( !pData
->GetModifier() && ( pData
->GetMode() == CommandWheelMode::SCROLL
) )
209 nDone
= HandleScrollCommand( rCEvt
, m_rTableControl
.getHorzScrollbar(), m_rTableControl
.getVertScrollbar() );
213 return nDone
|| Window::Notify( rNEvt
);
216 }} // namespace svt::table
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */