LibreOffice Module toolkit (master) 1
tabledatawindow.cxx
Go to the documentation of this file.
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
21
22#include "tabledatawindow.hxx"
23#include "tablecontrol_impl.hxx"
24#include "tablegeometry.hxx"
25
26#include <vcl/help.hxx>
28#include <vcl/settings.hxx>
29#include <vcl/commandevent.hxx>
30
31namespace svt::table
32{
33 using css::uno::Any;
34
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
46 {
48 }
49
51 {
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
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
116
117 tools::Rectangle const aControlScreenRect(
118 OutputToScreenPixel( Point( 0, 0 ) ),
120 );
121
122 Help::ShowQuickHelp(this, aControlScreenRect, sHelpText, nHelpStyle);
123 }
124 else
125 {
127 Window::RequestHelp( rHEvt );
128 }
129 }
130
132 {
134 }
135
137 {
138 if ( rMEvt.IsLeaveWindow() )
140
141 if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
142 {
143 Window::MouseMove( rMEvt );
144 }
145 }
146
148 {
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
172 {
173 if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
174 Window::MouseButtonUp( rMEvt );
175
177 }
178
179
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 {
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: */
CommandEventId GetCommand() const
const CommandWheelData * GetWheelData() const
HelpEventMode GetMode() const
const Point & GetMousePosPixel() const
static void HideBalloonAndQuickHelp()
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
bool IsLeaveWindow() const
const Point & GetPosPixel() const
const CommandEvent * GetCommandEvent() const
NotifyEventType GetType() const
void SetFillColor()
a helper representing geometry information of a cell
tools::Rectangle getRect() const
RowPos getRowAtPoint(const Point &rPoint) const
const PTableInputHandler & getInputHandler() const
ColPos getColAtPoint(const Point &rPoint) const
const TableControl & getAntiImpl() const
void doPaintContent(vcl::RenderContext &rRenderContext, const tools::Rectangle &_rUpdateRect)
paints the table control content which intersects with the given rectangle
virtual PTableModel getModel() const override
returns the table model
virtual bool isRowSelected(RowPos i_row) const override
determines whether a given row is selected
virtual void GrabFocus() override
virtual bool EventNotify(NotifyEvent &rNEvt) override
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void dispose() override
TableControl_Impl & m_rTableControl
TableDataWindow(TableControl_Impl &_rTableControl)
virtual ~TableDataWindow() override
virtual void RequestHelp(const HelpEvent &rHEvt) override
virtual void MouseMove(const MouseEvent &rMEvt) override
Link< LinkParamNone *, void > m_aSelectHdl
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Point OutputToScreenPixel(const Point &rPos) const
bool IsMouseCaptured() const
bool HandleScrollCommand(const CommandEvent &rCmd, Scrollable *pHScrl, Scrollable *pVScrl)
const AllSettings & GetSettings() const
::OutputDevice const * GetOutDev() const
Size GetOutputSizePixel() const
Point ScreenToOutputPixel(const Point &rPos) const
void SetBackground()
HelpEventMode
QuickHelpFlags
std::unique_ptr< sal_Int32[]> pData
sal_Int32 RowPos
a value denoting a row position within a table
Definition: tabletypes.hxx:34
std::shared_ptr< ITableModel > PTableModel
Definition: tablemodel.hxx:448
std::shared_ptr< ITableRenderer > PTableRenderer
sal_Int32 ColPos
a value denoting a column position within a table
Definition: tabletypes.hxx:32
#define ROW_COL_HEADERS
denotes the row containing the column headers
Definition: tabletypes.hxx:41