1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 * 25 ************************************************************************/ 26 27 // MARKER(update_precomp.py): autogen include statement, do not remove 28 #include "precompiled_svtools.hxx" 29 30 #include "svtools/table/tablecontrol.hxx" 31 32 #include "tabledatawindow.hxx" 33 #include "tablecontrol_impl.hxx" 34 #include "tablegeometry.hxx" 35 36 #include <vcl/help.hxx> 37 38 //...................................................................................................................... 39 namespace svt { namespace table 40 { 41 //...................................................................................................................... 42 43 /** === begin UNO using === **/ 44 using ::com::sun::star::uno::Any; 45 /** === end UNO using === **/ 46 47 //================================================================================================================== 48 //= TableDataWindow 49 //================================================================================================================== 50 //------------------------------------------------------------------------------------------------------------------ 51 TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl ) 52 :Window( &_rTableControl.getAntiImpl() ) 53 ,m_rTableControl( _rTableControl ) 54 ,m_nTipWindowHandle( 0 ) 55 { 56 // by default, use the background as determined by the style settings 57 const Color aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() ); 58 SetBackground( Wallpaper( aWindowColor ) ); 59 SetFillColor( aWindowColor ); 60 } 61 62 //------------------------------------------------------------------------------------------------------------------ 63 TableDataWindow::~TableDataWindow() 64 { 65 impl_hideTipWindow(); 66 } 67 68 //------------------------------------------------------------------------------------------------------------------ 69 void TableDataWindow::Paint( const Rectangle& rUpdateRect ) 70 { 71 m_rTableControl.doPaintContent( rUpdateRect ); 72 } 73 //------------------------------------------------------------------------------------------------------------------ 74 void TableDataWindow::SetBackground( const Wallpaper& rColor ) 75 { 76 Window::SetBackground( rColor ); 77 } 78 //------------------------------------------------------------------------------------------------------------------ 79 void TableDataWindow::SetControlBackground( const Color& rColor ) 80 { 81 Window::SetControlBackground( rColor ); 82 } 83 //------------------------------------------------------------------------------------------------------------------ 84 void TableDataWindow::SetBackground() 85 { 86 Window::SetBackground(); 87 } 88 //------------------------------------------------------------------------------------------------------------------ 89 void TableDataWindow::SetControlBackground() 90 { 91 Window::SetControlBackground(); 92 } 93 94 //------------------------------------------------------------------------------------------------------------------ 95 void TableDataWindow::RequestHelp( const HelpEvent& rHEvt ) 96 { 97 sal_uInt16 const nHelpMode = rHEvt.GetMode(); 98 if ( ( IsMouseCaptured() ) 99 || ( ( nHelpMode & HELPMODE_QUICK ) == 0 ) 100 ) 101 { 102 Window::RequestHelp( rHEvt ); 103 return; 104 } 105 106 ::rtl::OUString sHelpText; 107 sal_uInt16 nHelpStyle = 0; 108 109 Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) ); 110 RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos ); 111 ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos ); 112 113 PTableModel const pTableModel( m_rTableControl.getModel() ); 114 if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) ) 115 { 116 if ( hitRow == ROW_COL_HEADERS ) 117 { 118 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText(); 119 } 120 else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) ) 121 { 122 Any aCellToolTip; 123 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip ); 124 if ( !aCellToolTip.hasValue() ) 125 { 126 // use the cell content 127 pTableModel->getCellContent( hitCol, hitRow, aCellToolTip ); 128 129 // use the cell content as tool tip only if it doesn't fit into the cell. 130 bool const activeCell = ( hitRow == m_rTableControl.getCurrentRow() ) && ( hitCol == m_rTableControl.getCurrentColumn() ); 131 bool const selectedCell = m_rTableControl.isRowSelected( hitRow ); 132 133 Rectangle const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() ); 134 TableCellGeometry const aCell( m_rTableControl, aWindowRect, hitCol, hitRow ); 135 Rectangle const aCellRect( aCell.getRect() ); 136 137 PTableRenderer const pRenderer = pTableModel->getRenderer(); 138 if ( pRenderer->FitsIntoCell( aCellToolTip, hitCol, hitRow, activeCell, selectedCell, *this, aCellRect ) ) 139 aCellToolTip.clear(); 140 } 141 142 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, hitCol, hitRow, sHelpText ); 143 144 if ( sHelpText.indexOf( '\n' ) >= 0 ) 145 nHelpStyle = QUICKHELP_TIP_STYLE_BALLOON; 146 } 147 } 148 149 if ( sHelpText.getLength() ) 150 { 151 // hide the standard (singleton) help window, so we do not have two help windows open at the same time 152 Help::HideBalloonAndQuickHelp(); 153 154 Rectangle const aControlScreenRect( 155 OutputToScreenPixel( Point( 0, 0 ) ), 156 GetOutputSizePixel() 157 ); 158 159 if ( m_nTipWindowHandle ) 160 { 161 Help::UpdateTip( m_nTipWindowHandle, this, aControlScreenRect, sHelpText ); 162 } 163 else 164 m_nTipWindowHandle = Help::ShowTip( this, aControlScreenRect, sHelpText, nHelpStyle ); 165 } 166 else 167 { 168 impl_hideTipWindow(); 169 Window::RequestHelp( rHEvt ); 170 } 171 } 172 173 //------------------------------------------------------------------------------------------------------------------ 174 void TableDataWindow::impl_hideTipWindow() 175 { 176 if ( m_nTipWindowHandle != 0 ) 177 { 178 Help::HideTip( m_nTipWindowHandle ); 179 m_nTipWindowHandle = 0; 180 } 181 } 182 183 //------------------------------------------------------------------------------------------------------------------ 184 void TableDataWindow::MouseMove( const MouseEvent& rMEvt ) 185 { 186 if ( rMEvt.IsLeaveWindow() ) 187 impl_hideTipWindow(); 188 189 if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) ) 190 { 191 Window::MouseMove( rMEvt ); 192 } 193 } 194 //------------------------------------------------------------------------------------------------------------------ 195 void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt ) 196 { 197 impl_hideTipWindow(); 198 199 Point const aPoint = rMEvt.GetPosPixel(); 200 RowPos const hitRow = m_rTableControl.getRowAtPoint( aPoint ); 201 bool const wasRowSelected = m_rTableControl.isRowSelected( hitRow ); 202 203 if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) ) 204 { 205 Window::MouseButtonDown( rMEvt ); 206 return; 207 } 208 209 bool const isRowSelected = m_rTableControl.isRowSelected( hitRow ); 210 if ( isRowSelected != wasRowSelected ) 211 { 212 m_aSelectHdl.Call( NULL ); 213 } 214 } 215 216 //------------------------------------------------------------------------------------------------------------------ 217 void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt ) 218 { 219 if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) ) 220 Window::MouseButtonUp( rMEvt ); 221 222 m_rTableControl.getAntiImpl().GrabFocus(); 223 } 224 225 //------------------------------------------------------------------------------------------------------------------ 226 long TableDataWindow::Notify(NotifyEvent& rNEvt ) 227 { 228 long nDone = 0; 229 if ( rNEvt.GetType() == EVENT_COMMAND ) 230 { 231 const CommandEvent& rCEvt = *rNEvt.GetCommandEvent(); 232 if ( rCEvt.GetCommand() == COMMAND_WHEEL ) 233 { 234 const CommandWheelData* pData = rCEvt.GetWheelData(); 235 if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) ) 236 { 237 nDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() ); 238 } 239 } 240 } 241 return nDone ? nDone : Window::Notify( rNEvt ); 242 } 243 //...................................................................................................................... 244 } } // namespace svt::table 245 //...................................................................................................................... 246