Debian Codegraph @

toolkit/source/controls/table/tabledatawindow.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <controls/table/tablecontrol.hxx>
21
22 #include "tabledatawindow.hxx"
23 #include "tablecontrol_impl.hxx"
24 #include "tablegeometry.hxx"
25
26 #include <vcl/help.hxx>
27 #include <vcl/toolkit/scrbar.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/commandevent.hxx>
30
31 namespace svt::table
32 {
33 using css::uno::Any;
34
35 TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl )
36 :Window( &_rTableControl.getAntiImpl() )
37 ,m_rTableControl( _rTableControl )
38 {
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 );
43 }
44
45 TableDataWindow::~TableDataWindow()
46 {
47 disposeOnce();
48 }
49
50 void TableDataWindow::dispose()
51 {
52 impl_hideTipWindow();
53 Window::dispose();
54 }
55
56 void TableDataWindow::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rUpdateRect )
57 {
58 m_rTableControl.doPaintContent(rRenderContext, rUpdateRect);
59 }
60
61 void TableDataWindow::RequestHelp( const HelpEvent& rHEvt )
62 {
63 HelpEventMode const nHelpMode = rHEvt.GetMode();
64 if ( IsMouseCaptured()
65 || !( nHelpMode & HelpEventMode::QUICK )
66 )
67 {
68 Window::RequestHelp( rHEvt );
69 return;
70 }
71
72 OUString sHelpText;
73 QuickHelpFlags nHelpStyle = QuickHelpFlags::NONE;
74
75 Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
76 RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos );
77 ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos );
78
79 PTableModel const pTableModel( m_rTableControl.getModel() );
80 if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) )
81 {
82 if ( hitRow == ROW_COL_HEADERS )
83 {
84 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText();
85 }
86 else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) )
87 {
88 Any aCellToolTip;
89 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip );
90 if ( !aCellToolTip.hasValue() )
91 {
92 // use the cell content
93 pTableModel->getCellContent( hitCol, hitRow, aCellToolTip );
94
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() );
99
100 PTableRenderer const pRenderer = pTableModel->getRenderer();
101 if ( pRenderer->FitsIntoCell( aCellToolTip, *GetOutDev(), aCellRect ) )
102 aCellToolTip.clear();
103 }
104
105 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, sHelpText );
106
107 if ( sHelpText.indexOf( '\n' ) >= 0 )
108 nHelpStyle = QuickHelpFlags::TipStyleBalloon;
109 }
110 }
111
112 if ( !sHelpText.isEmpty() )
113 {
114 // hide the standard (singleton) help window, so we do not have two help windows open at the same time
115 Help::HideBalloonAndQuickHelp();
116
117 tools::Rectangle const aControlScreenRect(
118 OutputToScreenPixel( Point( 0, 0 ) ),
119 GetOutputSizePixel()
120 );
121
122 Help::ShowQuickHelp(this, aControlScreenRect, sHelpText, nHelpStyle);
123 }
124 else
125 {
126 impl_hideTipWindow();
127 Window::RequestHelp( rHEvt );
128 }
129 }
130
131 void TableDataWindow::impl_hideTipWindow()
132 {
133 Help::HideBalloonAndQuickHelp();
134 }
135
136 void TableDataWindow::MouseMove( const MouseEvent& rMEvt )
137 {
138 if ( rMEvt.IsLeaveWindow() )
139 impl_hideTipWindow();
140
141 if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
142 {
143 Window::MouseMove( rMEvt );
144 }
145 }
146
147 void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt )
148 {
149 impl_hideTipWindow();
150
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();
155
156 if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) )
157 {
158 Window::MouseButtonDown( rMEvt );
159 return;
160 }
161
162 bool const isRowSelected = m_rTableControl.isRowSelected( hitRow );
163 size_t const nCurSelRowCount = m_rTableControl.getSelectedRowCount();
164 if ( isRowSelected != wasRowSelected || nCurSelRowCount != nPrevSelRowCount )
165 {
166 m_aSelectHdl.Call( nullptr );
167 }
168 }
169
170
171 void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt )
172 {
173 if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
174 Window::MouseButtonUp( rMEvt );
175
176 m_rTableControl.getAntiImpl().GrabFocus();
177 }
178
179
180 bool TableDataWindow::EventNotify(NotifyEvent& rNEvt )
181 {
182 bool bDone = false;
183 if ( rNEvt.GetType() == NotifyEventType::COMMAND )
184 {
185 const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
186 if ( rCEvt.GetCommand() == CommandEventId::Wheel )
187 {
188 const CommandWheelData* pData = rCEvt.GetWheelData();
189 if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
190 {
191 bDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
192 }
193 }
194 }
195 return bDone || Window::EventNotify( rNEvt );
196 }
197
198 } // namespace svt::table
199
200
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */