tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / toolkit / source / controls / table / tabledatawindow.cxx
blobfc49ee08d621dec411575402b4471389e3df8bc6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <controls/table/tablecontrol.hxx>
22 #include "tabledatawindow.hxx"
23 #include "tablecontrol_impl.hxx"
24 #include "tablegeometry.hxx"
26 #include <vcl/help.hxx>
27 #include <vcl/toolkit/scrbar.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/commandevent.hxx>
31 namespace svt::table
33 using css::uno::Any;
35 TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl )
36 :Window( &_rTableControl.getAntiImpl() )
37 ,m_rTableControl( _rTableControl )
39 // by default, use the background as determined by the style settings
40 const Color aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
41 SetBackground( Wallpaper( aWindowColor ) );
42 GetOutDev()->SetFillColor( aWindowColor );
45 TableDataWindow::~TableDataWindow()
47 disposeOnce();
50 void TableDataWindow::dispose()
52 impl_hideTipWindow();
53 Window::dispose();
56 void TableDataWindow::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rUpdateRect )
58 m_rTableControl.doPaintContent(rRenderContext, rUpdateRect);
61 void TableDataWindow::RequestHelp( const HelpEvent& rHEvt )
63 HelpEventMode const nHelpMode = rHEvt.GetMode();
64 if ( IsMouseCaptured()
65 || !( nHelpMode & HelpEventMode::QUICK )
68 Window::RequestHelp( rHEvt );
69 return;
72 OUString sHelpText;
73 QuickHelpFlags nHelpStyle = QuickHelpFlags::NONE;
75 Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
76 RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos );
77 ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos );
79 PTableModel const pTableModel( m_rTableControl.getModel() );
80 if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) )
82 if ( hitRow == ROW_COL_HEADERS )
84 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText();
86 else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) )
88 Any aCellToolTip;
89 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip );
90 if ( !aCellToolTip.hasValue() )
92 // use the cell content
93 pTableModel->getCellContent( hitCol, hitRow, aCellToolTip );
95 // use the cell content as tool tip only if it doesn't fit into the cell.
96 tools::Rectangle const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
97 TableCellGeometry const aCell( m_rTableControl, aWindowRect, hitCol, hitRow );
98 tools::Rectangle const aCellRect( aCell.getRect() );
100 PTableRenderer const pRenderer = pTableModel->getRenderer();
101 if ( pRenderer->FitsIntoCell( aCellToolTip, *GetOutDev(), aCellRect ) )
102 aCellToolTip.clear();
105 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, sHelpText );
107 if ( sHelpText.indexOf( '\n' ) >= 0 )
108 nHelpStyle = QuickHelpFlags::TipStyleBalloon;
112 if ( !sHelpText.isEmpty() )
114 // hide the standard (singleton) help window, so we do not have two help windows open at the same time
115 Help::HideBalloonAndQuickHelp();
117 tools::Rectangle const aControlScreenRect(
118 OutputToScreenPixel( Point( 0, 0 ) ),
119 GetOutputSizePixel()
122 Help::ShowQuickHelp(this, aControlScreenRect, sHelpText, nHelpStyle);
124 else
126 impl_hideTipWindow();
127 Window::RequestHelp( rHEvt );
131 void TableDataWindow::impl_hideTipWindow()
133 Help::HideBalloonAndQuickHelp();
136 void TableDataWindow::MouseMove( const MouseEvent& rMEvt )
138 if ( rMEvt.IsLeaveWindow() )
139 impl_hideTipWindow();
141 if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
143 Window::MouseMove( rMEvt );
147 void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt )
149 impl_hideTipWindow();
151 Point const aPoint = rMEvt.GetPosPixel();
152 RowPos const hitRow = m_rTableControl.getRowAtPoint( aPoint );
153 bool const wasRowSelected = m_rTableControl.isRowSelected( hitRow );
154 size_t const nPrevSelRowCount = m_rTableControl.getSelectedRowCount();
156 if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) )
158 Window::MouseButtonDown( rMEvt );
159 return;
162 bool const isRowSelected = m_rTableControl.isRowSelected( hitRow );
163 size_t const nCurSelRowCount = m_rTableControl.getSelectedRowCount();
164 if ( isRowSelected != wasRowSelected || nCurSelRowCount != nPrevSelRowCount )
166 m_aSelectHdl.Call( nullptr );
171 void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt )
173 if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
174 Window::MouseButtonUp( rMEvt );
176 m_rTableControl.getAntiImpl().GrabFocus();
180 bool TableDataWindow::EventNotify(NotifyEvent& rNEvt )
182 bool bDone = false;
183 if ( rNEvt.GetType() == NotifyEventType::COMMAND )
185 const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
186 if ( rCEvt.GetCommand() == CommandEventId::Wheel )
188 const CommandWheelData* pData = rCEvt.GetWheelData();
189 if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
191 bDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
195 return bDone || Window::EventNotify( rNEvt );
198 } // namespace svt::table
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */