1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir // ============================================================================ 29cdf0e10cSrcweir #include "csvgrid.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <algorithm> 32cdf0e10cSrcweir #include <svtools/colorcfg.hxx> 33cdf0e10cSrcweir #include <svl/smplhint.hxx> 34cdf0e10cSrcweir #include <tools/poly.hxx> 35cdf0e10cSrcweir #include "scmod.hxx" 36cdf0e10cSrcweir #include "asciiopt.hxx" 37cdf0e10cSrcweir #include "impex.hxx" 38cdf0e10cSrcweir #include "AccessibleCsvControl.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir // *** edit engine *** 41cdf0e10cSrcweir #include "scitems.hxx" 42cdf0e10cSrcweir #include <editeng/eeitem.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <editeng/colritem.hxx> 46cdf0e10cSrcweir #include <editeng/fhgtitem.hxx> 47cdf0e10cSrcweir #include <editeng/fontitem.hxx> 48cdf0e10cSrcweir #include <svl/itemset.hxx> 49cdf0e10cSrcweir #include "editutil.hxx" 50cdf0e10cSrcweir // *** edit engine *** 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ============================================================================ 54cdf0e10cSrcweir 55cdf0e10cSrcweir struct Func_SetType 56cdf0e10cSrcweir { 57cdf0e10cSrcweir sal_Int32 mnType; 58cdf0e10cSrcweir inline Func_SetType( sal_Int32 nType ) : mnType( nType ) {} 59cdf0e10cSrcweir inline void operator()( ScCsvColState& rState ) { rState.mnType = mnType; } 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir 62cdf0e10cSrcweir struct Func_Select 63cdf0e10cSrcweir { 64cdf0e10cSrcweir bool mbSelect; 65cdf0e10cSrcweir inline Func_Select( bool bSelect ) : mbSelect( bSelect ) {} 66cdf0e10cSrcweir inline void operator()( ScCsvColState& rState ) { rState.Select( mbSelect ); } 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ============================================================================ 71cdf0e10cSrcweir 72cdf0e10cSrcweir ScCsvGrid::ScCsvGrid( ScCsvControl& rParent ) : 73cdf0e10cSrcweir ScCsvControl( rParent ), 74cdf0e10cSrcweir mrColorConfig( SC_MOD()->GetColorConfig() ), 75cdf0e10cSrcweir mpEditEngine( new ScEditEngineDefaulter( EditEngine::CreatePool(), sal_True ) ), 76cdf0e10cSrcweir maHeaderFont( GetFont() ), 77cdf0e10cSrcweir maColStates( 1 ), 78cdf0e10cSrcweir maTypeNames( 1 ), 79cdf0e10cSrcweir mnFirstImpLine( 0 ), 80cdf0e10cSrcweir mnRecentSelCol( CSV_COLUMN_INVALID ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir mpEditEngine->SetRefDevice( &maBackgrDev ); 83cdf0e10cSrcweir mpEditEngine->SetRefMapMode( MapMode( MAP_PIXEL ) ); 84cdf0e10cSrcweir maEdEngSize = mpEditEngine->GetPaperSize(); 85cdf0e10cSrcweir 86cdf0e10cSrcweir maPopup.SetMenuFlags( maPopup.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir EnableRTL( false ); // #107812# RTL 89cdf0e10cSrcweir InitColors(); 90cdf0e10cSrcweir InitFonts(); 91cdf0e10cSrcweir ImplClearSplits(); 92cdf0e10cSrcweir mrColorConfig.AddListener(this); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir ScCsvGrid::~ScCsvGrid() 96cdf0e10cSrcweir { 97cdf0e10cSrcweir mrColorConfig.RemoveListener(this); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir 101cdf0e10cSrcweir // common grid handling ------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir void ScCsvGrid::UpdateLayoutData() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir DisableRepaint(); 106cdf0e10cSrcweir SetFont( maMonoFont ); 107cdf0e10cSrcweir Execute( CSVCMD_SETCHARWIDTH, GetTextWidth( String( 'X' ) ) ); 108cdf0e10cSrcweir Execute( CSVCMD_SETLINEHEIGHT, GetTextHeight() + 1 ); 109cdf0e10cSrcweir SetFont( maHeaderFont ); 110cdf0e10cSrcweir Execute( CSVCMD_SETHDRHEIGHT, GetTextHeight() + 1 ); 111cdf0e10cSrcweir UpdateOffsetX(); 112cdf0e10cSrcweir EnableRepaint(); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir void ScCsvGrid::UpdateOffsetX() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir sal_Int32 nLastLine = GetLastVisLine() + 1; 118cdf0e10cSrcweir sal_Int32 nDigits = 2; 119cdf0e10cSrcweir while( nLastLine /= 10 ) ++nDigits; 120cdf0e10cSrcweir nDigits = Max( nDigits, sal_Int32( 3 ) ); 121cdf0e10cSrcweir Execute( CSVCMD_SETHDRWIDTH, GetTextWidth( String( '0' ) ) * nDigits ); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir void ScCsvGrid::ApplyLayout( const ScCsvLayoutData& rOldData ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData ); 127cdf0e10cSrcweir if( nDiff == CSV_DIFF_EQUAL ) return; 128cdf0e10cSrcweir 129cdf0e10cSrcweir DisableRepaint(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if( nDiff & CSV_DIFF_RULERCURSOR ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir ImplInvertCursor( rOldData.mnPosCursor ); 134cdf0e10cSrcweir ImplInvertCursor( GetRulerCursorPos() ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir if( nDiff & CSV_DIFF_POSCOUNT ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if( GetPosCount() < rOldData.mnPosCount ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir SelectAll( false ); 142cdf0e10cSrcweir maSplits.RemoveRange( GetPosCount(), rOldData.mnPosCount ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir else 145cdf0e10cSrcweir maSplits.Remove( rOldData.mnPosCount ); 146cdf0e10cSrcweir maSplits.Insert( GetPosCount() ); 147cdf0e10cSrcweir maColStates.resize( maSplits.Count() - 1 ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir if( nDiff & CSV_DIFF_LINEOFFSET ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 153cdf0e10cSrcweir UpdateOffsetX(); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir ScCsvDiff nHVDiff = nDiff & (CSV_DIFF_HORIZONTAL | CSV_DIFF_VERTICAL); 157cdf0e10cSrcweir if( nHVDiff == CSV_DIFF_POSOFFSET ) 158cdf0e10cSrcweir ImplDrawHorzScrolled( rOldData.mnPosOffset ); 159cdf0e10cSrcweir else if( nHVDiff != CSV_DIFF_EQUAL ) 160cdf0e10cSrcweir InvalidateGfx(); 161cdf0e10cSrcweir 162cdf0e10cSrcweir EnableRepaint(); 163cdf0e10cSrcweir 164cdf0e10cSrcweir if( nDiff & (CSV_DIFF_POSOFFSET | CSV_DIFF_LINEOFFSET) ) 165cdf0e10cSrcweir AccSendVisibleEvent(); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir void ScCsvGrid::SetFirstImportedLine( sal_Int32 nLine ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir ImplDrawFirstLineSep( false ); 171cdf0e10cSrcweir mnFirstImpLine = nLine; 172cdf0e10cSrcweir ImplDrawFirstLineSep( true ); 173cdf0e10cSrcweir ImplDrawGridDev(); 174cdf0e10cSrcweir Repaint(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir sal_Int32 ScCsvGrid::GetNoScrollCol( sal_Int32 nPos ) const 178cdf0e10cSrcweir { 179cdf0e10cSrcweir sal_Int32 nNewPos = nPos; 180cdf0e10cSrcweir if( nNewPos != CSV_POS_INVALID ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0; 185cdf0e10cSrcweir nNewPos = GetFirstVisPos() + nScroll; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1L ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0; 190cdf0e10cSrcweir nNewPos = GetLastVisPos() - nScroll - 1; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir return nNewPos; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir void ScCsvGrid::InitColors() 197cdf0e10cSrcweir { 198cdf0e10cSrcweir maBackColor.SetColor( static_cast< sal_uInt32 >( mrColorConfig.GetColorValue( ::svtools::DOCCOLOR ).nColor ) ); 199cdf0e10cSrcweir maGridColor.SetColor( static_cast< sal_uInt32 >( mrColorConfig.GetColorValue( ::svtools::CALCGRID ).nColor ) ); 200cdf0e10cSrcweir maGridPBColor.SetColor( static_cast< sal_uInt32 >( mrColorConfig.GetColorValue( ::svtools::CALCPAGEBREAK ).nColor ) ); 201cdf0e10cSrcweir maAppBackColor.SetColor( static_cast< sal_uInt32 >( mrColorConfig.GetColorValue( ::svtools::APPBACKGROUND ).nColor ) ); 202cdf0e10cSrcweir maTextColor.SetColor( static_cast< sal_uInt32 >( mrColorConfig.GetColorValue( ::svtools::FONTCOLOR ).nColor ) ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir const StyleSettings& rSett = GetSettings().GetStyleSettings(); 205cdf0e10cSrcweir maHeaderBackColor = rSett.GetFaceColor(); 206cdf0e10cSrcweir maHeaderGridColor = rSett.GetDarkShadowColor(); 207cdf0e10cSrcweir maHeaderTextColor = rSett.GetButtonTextColor(); 208cdf0e10cSrcweir maSelectColor = rSett.GetActiveColor(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir InvalidateGfx(); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir void ScCsvGrid::InitFonts() 214cdf0e10cSrcweir { 215cdf0e10cSrcweir maMonoFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_ENGLISH_US, 0 ); 216cdf0e10cSrcweir maMonoFont.SetSize( Size( maMonoFont.GetSize().Width(), maHeaderFont.GetSize().Height() ) ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir /* *** Set edit engine defaults *** 219cdf0e10cSrcweir maMonoFont for Latin script, smaller default font for Asian and Complex script. */ 220cdf0e10cSrcweir 221cdf0e10cSrcweir // get default fonts 222cdf0e10cSrcweir SvxFontItem aLatinItem( EE_CHAR_FONTINFO ); 223cdf0e10cSrcweir SvxFontItem aAsianItem( EE_CHAR_FONTINFO_CJK ); 224cdf0e10cSrcweir SvxFontItem aComplexItem( EE_CHAR_FONTINFO_CTL ); 225cdf0e10cSrcweir ::GetDefaultFonts( aLatinItem, aAsianItem, aComplexItem ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir // create item set for defaults 228cdf0e10cSrcweir SfxItemSet aDefSet( mpEditEngine->GetEmptyItemSet() ); 229cdf0e10cSrcweir EditEngine::SetFontInfoInItemSet( aDefSet, maMonoFont ); 230cdf0e10cSrcweir aDefSet.Put( aAsianItem ); 231cdf0e10cSrcweir aDefSet.Put( aComplexItem ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir // set Asian/Complex font size to height of character in Latin font 234cdf0e10cSrcweir sal_uLong nFontHt = static_cast< sal_uLong >( maMonoFont.GetSize().Height() ); 235cdf0e10cSrcweir aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CJK ) ); 236cdf0e10cSrcweir aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CTL ) ); 237cdf0e10cSrcweir 238cdf0e10cSrcweir // copy other items from default font 239cdf0e10cSrcweir const SfxPoolItem& rWeightItem = aDefSet.Get( EE_CHAR_WEIGHT ); 240cdf0e10cSrcweir aDefSet.Put( rWeightItem, EE_CHAR_WEIGHT_CJK ); 241cdf0e10cSrcweir aDefSet.Put( rWeightItem, EE_CHAR_WEIGHT_CTL ); 242cdf0e10cSrcweir const SfxPoolItem& rItalicItem = aDefSet.Get( EE_CHAR_ITALIC ); 243cdf0e10cSrcweir aDefSet.Put( rItalicItem, EE_CHAR_ITALIC_CJK ); 244cdf0e10cSrcweir aDefSet.Put( rItalicItem, EE_CHAR_ITALIC_CTL ); 245cdf0e10cSrcweir const SfxPoolItem& rLangItem = aDefSet.Get( EE_CHAR_LANGUAGE ); 246cdf0e10cSrcweir aDefSet.Put( rLangItem, EE_CHAR_LANGUAGE_CJK ); 247cdf0e10cSrcweir aDefSet.Put( rLangItem, EE_CHAR_LANGUAGE_CTL ); 248cdf0e10cSrcweir 249cdf0e10cSrcweir mpEditEngine->SetDefaults( aDefSet ); 250cdf0e10cSrcweir InvalidateGfx(); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir void ScCsvGrid::InitSizeData() 254cdf0e10cSrcweir { 255cdf0e10cSrcweir maWinSize = GetSizePixel(); 256cdf0e10cSrcweir maBackgrDev.SetOutputSizePixel( maWinSize ); 257cdf0e10cSrcweir maGridDev.SetOutputSizePixel( maWinSize ); 258cdf0e10cSrcweir InvalidateGfx(); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir 262cdf0e10cSrcweir // split handling ------------------------------------------------------------- 263cdf0e10cSrcweir 264cdf0e10cSrcweir void ScCsvGrid::InsertSplit( sal_Int32 nPos ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir if( ImplInsertSplit( nPos ) ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir DisableRepaint(); 269cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 270cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 271cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromPos( nPos ); 272cdf0e10cSrcweir ImplDrawColumn( nColIx - 1 ); 273cdf0e10cSrcweir ImplDrawColumn( nColIx ); 274cdf0e10cSrcweir ValidateGfx(); // performance: do not redraw all columns 275cdf0e10cSrcweir EnableRepaint(); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir void ScCsvGrid::RemoveSplit( sal_Int32 nPos ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir if( ImplRemoveSplit( nPos ) ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir DisableRepaint(); 284cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 285cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 286cdf0e10cSrcweir ImplDrawColumn( GetColumnFromPos( nPos ) ); 287cdf0e10cSrcweir ValidateGfx(); // performance: do not redraw all columns 288cdf0e10cSrcweir EnableRepaint(); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir void ScCsvGrid::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromPos( nPos ); 295cdf0e10cSrcweir if( nColIx != CSV_COLUMN_INVALID ) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir DisableRepaint(); 298cdf0e10cSrcweir if( (GetColumnPos( nColIx - 1 ) < nNewPos) && (nNewPos < GetColumnPos( nColIx + 1 )) ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir // move a split in the range between 2 others -> keep selection state of both columns 301cdf0e10cSrcweir maSplits.Remove( nPos ); 302cdf0e10cSrcweir maSplits.Insert( nNewPos ); 303cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 304cdf0e10cSrcweir ImplDrawColumn( nColIx - 1 ); 305cdf0e10cSrcweir ImplDrawColumn( nColIx ); 306cdf0e10cSrcweir ValidateGfx(); // performance: do not redraw all columns 307cdf0e10cSrcweir AccSendTableUpdateEvent( nColIx - 1, nColIx ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir else 310cdf0e10cSrcweir { 311cdf0e10cSrcweir ImplRemoveSplit( nPos ); 312cdf0e10cSrcweir ImplInsertSplit( nNewPos ); 313cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 314cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir EnableRepaint(); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir void ScCsvGrid::RemoveAllSplits() 321cdf0e10cSrcweir { 322cdf0e10cSrcweir DisableRepaint(); 323cdf0e10cSrcweir ImplClearSplits(); 324cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 325cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 326cdf0e10cSrcweir EnableRepaint(); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir void ScCsvGrid::SetSplits( const ScCsvSplits& rSplits ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir DisableRepaint(); 332cdf0e10cSrcweir ImplClearSplits(); 333cdf0e10cSrcweir sal_uInt32 nCount = rSplits.Count(); 334cdf0e10cSrcweir for( sal_uInt32 nIx = 0; nIx < nCount; ++nIx ) 335cdf0e10cSrcweir maSplits.Insert( rSplits[ nIx ] ); 336cdf0e10cSrcweir maColStates.clear(); 337cdf0e10cSrcweir maColStates.resize( maSplits.Count() - 1 ); 338cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 339cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 340cdf0e10cSrcweir EnableRepaint(); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir bool ScCsvGrid::ImplInsertSplit( sal_Int32 nPos ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromPos( nPos ); 346cdf0e10cSrcweir bool bRet = (nColIx < GetColumnCount()) && maSplits.Insert( nPos ); 347cdf0e10cSrcweir if( bRet ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir ScCsvColState aState( GetColumnType( nColIx ) ); 350cdf0e10cSrcweir aState.Select( IsSelected( nColIx ) && IsSelected( nColIx + 1 ) ); 351cdf0e10cSrcweir maColStates.insert( maColStates.begin() + nColIx + 1, aState ); 352cdf0e10cSrcweir AccSendInsertColumnEvent( nColIx + 1, nColIx + 1 ); 353cdf0e10cSrcweir AccSendTableUpdateEvent( nColIx, nColIx ); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir return bRet; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir bool ScCsvGrid::ImplRemoveSplit( sal_Int32 nPos ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir bool bRet = maSplits.Remove( nPos ); 361cdf0e10cSrcweir if( bRet ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromPos( nPos ); 364cdf0e10cSrcweir bool bSel = IsSelected( nColIx ) || IsSelected( nColIx + 1 ); 365cdf0e10cSrcweir maColStates.erase( maColStates.begin() + nColIx + 1 ); 366cdf0e10cSrcweir maColStates[ nColIx ].Select( bSel ); 367cdf0e10cSrcweir AccSendRemoveColumnEvent( nColIx + 1, nColIx + 1 ); 368cdf0e10cSrcweir AccSendTableUpdateEvent( nColIx, nColIx ); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir return bRet; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir void ScCsvGrid::ImplClearSplits() 374cdf0e10cSrcweir { 375cdf0e10cSrcweir sal_uInt32 nColumns = GetColumnCount(); 376cdf0e10cSrcweir maSplits.Clear(); 377cdf0e10cSrcweir maSplits.Insert( 0 ); 378cdf0e10cSrcweir maSplits.Insert( GetPosCount() ); 379cdf0e10cSrcweir maColStates.resize( 1 ); 380cdf0e10cSrcweir InvalidateGfx(); 381cdf0e10cSrcweir AccSendRemoveColumnEvent( 1, nColumns - 1 ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir // columns/column types ------------------------------------------------------- 385cdf0e10cSrcweir 386cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetFirstVisColumn() const 387cdf0e10cSrcweir { 388cdf0e10cSrcweir return GetColumnFromPos( GetFirstVisPos() ); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetLastVisColumn() const 392cdf0e10cSrcweir { 393cdf0e10cSrcweir return GetColumnFromPos( Min( GetLastVisPos(), GetPosCount() ) - 1 ); 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir bool ScCsvGrid::IsValidColumn( sal_uInt32 nColIndex ) const 397cdf0e10cSrcweir { 398cdf0e10cSrcweir return nColIndex < GetColumnCount(); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir bool ScCsvGrid::IsVisibleColumn( sal_uInt32 nColIndex ) const 402cdf0e10cSrcweir { 403cdf0e10cSrcweir return IsValidColumn( nColIndex ) && 404cdf0e10cSrcweir (GetColumnPos( nColIndex ) < GetLastVisPos()) && 405cdf0e10cSrcweir (GetFirstVisPos() < GetColumnPos( nColIndex + 1 )); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir sal_Int32 ScCsvGrid::GetColumnX( sal_uInt32 nColIndex ) const 409cdf0e10cSrcweir { 410cdf0e10cSrcweir return GetX( GetColumnPos( nColIndex ) ); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetColumnFromX( sal_Int32 nX ) const 414cdf0e10cSrcweir { 415cdf0e10cSrcweir sal_Int32 nPos = (nX - GetFirstX()) / GetCharWidth() + GetFirstVisPos(); 416cdf0e10cSrcweir return ((GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos())) ? 417cdf0e10cSrcweir GetColumnFromPos( nPos ) : CSV_COLUMN_INVALID; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetColumnFromPos( sal_Int32 nPos ) const 421cdf0e10cSrcweir { 422cdf0e10cSrcweir return maSplits.UpperBound( nPos ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir sal_Int32 ScCsvGrid::GetColumnWidth( sal_uInt32 nColIndex ) const 426cdf0e10cSrcweir { 427cdf0e10cSrcweir return IsValidColumn( nColIndex ) ? (GetColumnPos( nColIndex + 1 ) - GetColumnPos( nColIndex )) : 0; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir void ScCsvGrid::SetColumnStates( const ScCsvColStateVec& rStates ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir maColStates = rStates; 433cdf0e10cSrcweir maColStates.resize( maSplits.Count() - 1 ); 434cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 435cdf0e10cSrcweir AccSendTableUpdateEvent( 0, GetColumnCount(), false ); 436cdf0e10cSrcweir AccSendSelectionEvent(); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir sal_Int32 ScCsvGrid::GetColumnType( sal_uInt32 nColIndex ) const 440cdf0e10cSrcweir { 441cdf0e10cSrcweir return IsValidColumn( nColIndex ) ? maColStates[ nColIndex ].mnType : CSV_TYPE_NOSELECTION; 442cdf0e10cSrcweir } 443cdf0e10cSrcweir 444cdf0e10cSrcweir void ScCsvGrid::SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir if( IsValidColumn( nColIndex ) ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir maColStates[ nColIndex ].mnType = nColType; 449cdf0e10cSrcweir AccSendTableUpdateEvent( nColIndex, nColIndex, false ); 450cdf0e10cSrcweir } 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir sal_Int32 ScCsvGrid::GetSelColumnType() const 454cdf0e10cSrcweir { 455cdf0e10cSrcweir sal_uInt32 nColIx = GetFirstSelected(); 456cdf0e10cSrcweir if( nColIx == CSV_COLUMN_INVALID ) 457cdf0e10cSrcweir return CSV_TYPE_NOSELECTION; 458cdf0e10cSrcweir 459cdf0e10cSrcweir sal_Int32 nType = GetColumnType( nColIx ); 460cdf0e10cSrcweir while( (nColIx != CSV_COLUMN_INVALID) && (nType != CSV_TYPE_MULTI) ) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if( nType != GetColumnType( nColIx ) ) 463cdf0e10cSrcweir nType = CSV_TYPE_MULTI; 464cdf0e10cSrcweir nColIx = GetNextSelected( nColIx ); 465cdf0e10cSrcweir } 466cdf0e10cSrcweir return nType; 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir void ScCsvGrid::SetSelColumnType( sal_Int32 nType ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir if( (nType != CSV_TYPE_MULTI) && (nType != CSV_TYPE_NOSELECTION) ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir for( sal_uInt32 nColIx = GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = GetNextSelected( nColIx ) ) 474cdf0e10cSrcweir SetColumnType( nColIx, nType ); 475cdf0e10cSrcweir Repaint( true ); 476cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir void ScCsvGrid::SetTypeNames( const StringVec& rTypeNames ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir DBG_ASSERT( !rTypeNames.empty(), "ScCsvGrid::SetTypeNames - vector is empty" ); 483cdf0e10cSrcweir maTypeNames = rTypeNames; 484cdf0e10cSrcweir Repaint( true ); 485cdf0e10cSrcweir 486cdf0e10cSrcweir maPopup.Clear(); 487cdf0e10cSrcweir sal_uInt32 nCount = maTypeNames.size(); 488cdf0e10cSrcweir sal_uInt32 nIx; 489cdf0e10cSrcweir sal_uInt16 nItemId; 490cdf0e10cSrcweir for( nIx = 0, nItemId = 1; nIx < nCount; ++nIx, ++nItemId ) 491cdf0e10cSrcweir maPopup.InsertItem( nItemId, maTypeNames[ nIx ] ); 492cdf0e10cSrcweir 493cdf0e10cSrcweir ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) ); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir const String& ScCsvGrid::GetColumnTypeName( sal_uInt32 nColIndex ) const 497cdf0e10cSrcweir { 498cdf0e10cSrcweir sal_uInt32 nTypeIx = static_cast< sal_uInt32 >( GetColumnType( nColIndex ) ); 499cdf0e10cSrcweir return (nTypeIx < maTypeNames.size()) ? maTypeNames[ nTypeIx ] : EMPTY_STRING; 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir sal_uInt8 lcl_GetExtColumnType( sal_Int32 nIntType ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir static sal_uInt8 pExtTypes[] = 505cdf0e10cSrcweir { SC_COL_STANDARD, SC_COL_TEXT, SC_COL_DMY, SC_COL_MDY, SC_COL_YMD, SC_COL_ENGLISH, SC_COL_SKIP }; 506cdf0e10cSrcweir static sal_Int32 nExtTypeCount = sizeof( pExtTypes ) / sizeof( *pExtTypes ); 507cdf0e10cSrcweir return pExtTypes[ ((0 <= nIntType) && (nIntType < nExtTypeCount)) ? nIntType : 0 ]; 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir void ScCsvGrid::FillColumnDataSep( ScAsciiOptions& rOptions ) const 511cdf0e10cSrcweir { 512cdf0e10cSrcweir sal_uInt32 nCount = GetColumnCount(); 513cdf0e10cSrcweir ScCsvExpDataVec aDataVec; 514cdf0e10cSrcweir 515cdf0e10cSrcweir for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir if( GetColumnType( nColIx ) != CSV_TYPE_DEFAULT ) 518cdf0e10cSrcweir // 1-based column index 519cdf0e10cSrcweir aDataVec.push_back( ScCsvExpData( 520cdf0e10cSrcweir static_cast< xub_StrLen >( nColIx + 1 ), 521cdf0e10cSrcweir lcl_GetExtColumnType( GetColumnType( nColIx ) ) ) ); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir rOptions.SetColumnInfo( aDataVec ); 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir void ScCsvGrid::FillColumnDataFix( ScAsciiOptions& rOptions ) const 527cdf0e10cSrcweir { 528cdf0e10cSrcweir sal_uInt32 nCount = Min( GetColumnCount(), static_cast<sal_uInt32>(MAXCOLCOUNT) ); 529cdf0e10cSrcweir ScCsvExpDataVec aDataVec( nCount + 1 ); 530cdf0e10cSrcweir 531cdf0e10cSrcweir for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir ScCsvExpData& rData = aDataVec[ nColIx ]; 534cdf0e10cSrcweir rData.mnIndex = static_cast< xub_StrLen >( 535cdf0e10cSrcweir Min( static_cast< sal_Int32 >( STRING_MAXLEN ), GetColumnPos( nColIx ) ) ); 536cdf0e10cSrcweir rData.mnType = lcl_GetExtColumnType( GetColumnType( nColIx ) ); 537cdf0e10cSrcweir } 538cdf0e10cSrcweir aDataVec[ nCount ].mnIndex = STRING_MAXLEN; 539cdf0e10cSrcweir aDataVec[ nCount ].mnType = SC_COL_SKIP; 540cdf0e10cSrcweir rOptions.SetColumnInfo( aDataVec ); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir 543cdf0e10cSrcweir void ScCsvGrid::ScrollVertRel( ScMoveMode eDir ) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir sal_Int32 nLine = GetFirstVisLine(); 546cdf0e10cSrcweir switch( eDir ) 547cdf0e10cSrcweir { 548cdf0e10cSrcweir case MOVE_PREV: --nLine; break; 549cdf0e10cSrcweir case MOVE_NEXT: ++nLine; break; 550cdf0e10cSrcweir case MOVE_FIRST: nLine = 0; break; 551cdf0e10cSrcweir case MOVE_LAST: nLine = GetMaxLineOffset(); break; 552cdf0e10cSrcweir case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 2; break; 553cdf0e10cSrcweir case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 2; break; 554cdf0e10cSrcweir default: 555cdf0e10cSrcweir { 556cdf0e10cSrcweir // added to avoid warnings 557cdf0e10cSrcweir } 558cdf0e10cSrcweir } 559cdf0e10cSrcweir Execute( CSVCMD_SETLINEOFFSET, nLine ); 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir void ScCsvGrid::ExecutePopup( const Point& rPos ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir sal_uInt16 nItemId = maPopup.Execute( this, rPos ); 565cdf0e10cSrcweir if( nItemId ) // 0 = cancelled 566cdf0e10cSrcweir Execute( CSVCMD_SETCOLUMNTYPE, maPopup.GetItemPos( nItemId ) ); 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir 570cdf0e10cSrcweir // selection handling --------------------------------------------------------- 571cdf0e10cSrcweir 572cdf0e10cSrcweir bool ScCsvGrid::IsSelected( sal_uInt32 nColIndex ) const 573cdf0e10cSrcweir { 574cdf0e10cSrcweir return IsValidColumn( nColIndex ) && maColStates[ nColIndex ].IsSelected(); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetFirstSelected() const 578cdf0e10cSrcweir { 579cdf0e10cSrcweir return IsSelected( 0 ) ? 0 : GetNextSelected( 0 ); 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582cdf0e10cSrcweir sal_uInt32 ScCsvGrid::GetNextSelected( sal_uInt32 nFromIndex ) const 583cdf0e10cSrcweir { 584cdf0e10cSrcweir sal_uInt32 nColCount = GetColumnCount(); 585cdf0e10cSrcweir for( sal_uInt32 nColIx = nFromIndex + 1; nColIx < nColCount; ++nColIx ) 586cdf0e10cSrcweir if( IsSelected( nColIx ) ) 587cdf0e10cSrcweir return nColIx; 588cdf0e10cSrcweir return CSV_COLUMN_INVALID; 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir void ScCsvGrid::Select( sal_uInt32 nColIndex, bool bSelect ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir if( IsValidColumn( nColIndex ) ) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir maColStates[ nColIndex ].Select( bSelect ); 596cdf0e10cSrcweir ImplDrawColumnSelection( nColIndex ); 597cdf0e10cSrcweir Repaint(); 598cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 599cdf0e10cSrcweir if( bSelect ) 600cdf0e10cSrcweir mnRecentSelCol = nColIndex; 601cdf0e10cSrcweir AccSendSelectionEvent(); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir } 604cdf0e10cSrcweir 605cdf0e10cSrcweir void ScCsvGrid::ToggleSelect( sal_uInt32 nColIndex ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir Select( nColIndex, !IsSelected( nColIndex ) ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610cdf0e10cSrcweir void ScCsvGrid::SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir if( nColIndex1 == CSV_COLUMN_INVALID ) 613cdf0e10cSrcweir Select( nColIndex2 ); 614cdf0e10cSrcweir else if( nColIndex2 == CSV_COLUMN_INVALID ) 615cdf0e10cSrcweir Select( nColIndex1 ); 616cdf0e10cSrcweir else if( nColIndex1 > nColIndex2 ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir SelectRange( nColIndex2, nColIndex1, bSelect ); 619cdf0e10cSrcweir if( bSelect ) 620cdf0e10cSrcweir mnRecentSelCol = nColIndex1; 621cdf0e10cSrcweir } 622cdf0e10cSrcweir else if( IsValidColumn( nColIndex1 ) && IsValidColumn( nColIndex2 ) ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir for( sal_uInt32 nColIx = nColIndex1; nColIx <= nColIndex2; ++nColIx ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir maColStates[ nColIx ].Select( bSelect ); 627cdf0e10cSrcweir ImplDrawColumnSelection( nColIx ); 628cdf0e10cSrcweir } 629cdf0e10cSrcweir Repaint(); 630cdf0e10cSrcweir Execute( CSVCMD_EXPORTCOLUMNTYPE ); 631cdf0e10cSrcweir if( bSelect ) 632cdf0e10cSrcweir mnRecentSelCol = nColIndex1; 633cdf0e10cSrcweir AccSendSelectionEvent(); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir } 636cdf0e10cSrcweir 637cdf0e10cSrcweir void ScCsvGrid::SelectAll( bool bSelect ) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir SelectRange( 0, GetColumnCount() - 1, bSelect ); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir void ScCsvGrid::MoveCursor( sal_uInt32 nColIndex ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir DisableRepaint(); 645cdf0e10cSrcweir if( IsValidColumn( nColIndex ) ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir sal_Int32 nPosBeg = GetColumnPos( nColIndex ); 648cdf0e10cSrcweir sal_Int32 nPosEnd = GetColumnPos( nColIndex + 1 ); 649cdf0e10cSrcweir sal_Int32 nMinPos = Max( nPosBeg - CSV_SCROLL_DIST, sal_Int32( 0 ) ); 650cdf0e10cSrcweir sal_Int32 nMaxPos = Min( nPosEnd - GetVisPosCount() + CSV_SCROLL_DIST + sal_Int32( 1 ), nMinPos ); 651cdf0e10cSrcweir if( nPosBeg - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() ) 652cdf0e10cSrcweir Execute( CSVCMD_SETPOSOFFSET, nMinPos ); 653cdf0e10cSrcweir else if( nPosEnd + CSV_SCROLL_DIST >= GetLastVisPos() ) 654cdf0e10cSrcweir Execute( CSVCMD_SETPOSOFFSET, nMaxPos ); 655cdf0e10cSrcweir } 656cdf0e10cSrcweir Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) ); 657cdf0e10cSrcweir EnableRepaint(); 658cdf0e10cSrcweir } 659cdf0e10cSrcweir 660cdf0e10cSrcweir void ScCsvGrid::MoveCursorRel( ScMoveMode eDir ) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir if( GetFocusColumn() != CSV_COLUMN_INVALID ) 663cdf0e10cSrcweir { 664cdf0e10cSrcweir switch( eDir ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir case MOVE_FIRST: 667cdf0e10cSrcweir MoveCursor( 0 ); 668cdf0e10cSrcweir break; 669cdf0e10cSrcweir case MOVE_LAST: 670cdf0e10cSrcweir MoveCursor( GetColumnCount() - 1 ); 671cdf0e10cSrcweir break; 672cdf0e10cSrcweir case MOVE_PREV: 673cdf0e10cSrcweir if( GetFocusColumn() > 0 ) 674cdf0e10cSrcweir MoveCursor( GetFocusColumn() - 1 ); 675cdf0e10cSrcweir break; 676cdf0e10cSrcweir case MOVE_NEXT: 677cdf0e10cSrcweir if( GetFocusColumn() < GetColumnCount() - 1 ) 678cdf0e10cSrcweir MoveCursor( GetFocusColumn() + 1 ); 679cdf0e10cSrcweir break; 680cdf0e10cSrcweir default: 681cdf0e10cSrcweir { 682cdf0e10cSrcweir // added to avoid warnings 683cdf0e10cSrcweir } 684cdf0e10cSrcweir } 685cdf0e10cSrcweir } 686cdf0e10cSrcweir } 687cdf0e10cSrcweir 688cdf0e10cSrcweir void ScCsvGrid::ImplClearSelection() 689cdf0e10cSrcweir { 690cdf0e10cSrcweir ::std::for_each( maColStates.begin(), maColStates.end(), Func_Select( false ) ); 691cdf0e10cSrcweir ImplDrawGridDev(); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir void ScCsvGrid::DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir if( !(nModifier & KEY_MOD1) ) 697cdf0e10cSrcweir ImplClearSelection(); 698cdf0e10cSrcweir if( nModifier & KEY_SHIFT ) // SHIFT always expands 699cdf0e10cSrcweir SelectRange( mnRecentSelCol, nColIndex ); 700cdf0e10cSrcweir else if( !(nModifier & KEY_MOD1) ) // no SHIFT/CTRL always selects 1 column 701cdf0e10cSrcweir Select( nColIndex ); 702cdf0e10cSrcweir else if( IsTracking() ) // CTRL in tracking does not toggle 703cdf0e10cSrcweir Select( nColIndex, mbMTSelecting ); 704cdf0e10cSrcweir else // CTRL only toggles 705cdf0e10cSrcweir ToggleSelect( nColIndex ); 706cdf0e10cSrcweir Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) ); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir 709cdf0e10cSrcweir 710cdf0e10cSrcweir // cell contents -------------------------------------------------------------- 711cdf0e10cSrcweir 712cdf0e10cSrcweir void ScCsvGrid::ImplSetTextLineSep( 713cdf0e10cSrcweir sal_Int32 nLine, const String& rTextLine, 714cdf0e10cSrcweir const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep ) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir if( nLine < GetFirstVisLine() ) return; 717cdf0e10cSrcweir 718cdf0e10cSrcweir sal_uInt32 nLineIx = nLine - GetFirstVisLine(); 719cdf0e10cSrcweir while( maTexts.size() <= nLineIx ) 720cdf0e10cSrcweir maTexts.push_back( StringVec() ); 721cdf0e10cSrcweir StringVec& rStrVec = maTexts[ nLineIx ]; 722cdf0e10cSrcweir rStrVec.clear(); 723cdf0e10cSrcweir 724cdf0e10cSrcweir // scan for separators 725cdf0e10cSrcweir String aCellText; 726cdf0e10cSrcweir const sal_Unicode* pSepChars = rSepChars.GetBuffer(); 727cdf0e10cSrcweir const sal_Unicode* pChar = rTextLine.GetBuffer(); 728cdf0e10cSrcweir sal_uInt32 nColIx = 0; 729cdf0e10cSrcweir 730cdf0e10cSrcweir while( *pChar && (nColIx < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT)) ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir // scan for next cell text 733cdf0e10cSrcweir bool bIsQuoted = false; 734cdf0e10cSrcweir pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText, cTextSep, pSepChars, bMergeSep, bIsQuoted ); 735cdf0e10cSrcweir 736cdf0e10cSrcweir // update column width 737cdf0e10cSrcweir sal_Int32 nWidth = Max( CSV_MINCOLWIDTH, aCellText.Len() + sal_Int32( 1 ) ); 738cdf0e10cSrcweir if( IsValidColumn( nColIx ) ) 739cdf0e10cSrcweir { 740cdf0e10cSrcweir // expand existing column 741cdf0e10cSrcweir sal_Int32 nDiff = nWidth - GetColumnWidth( nColIx ); 742cdf0e10cSrcweir if( nDiff > 0 ) 743cdf0e10cSrcweir { 744cdf0e10cSrcweir Execute( CSVCMD_SETPOSCOUNT, GetPosCount() + nDiff ); 745cdf0e10cSrcweir for( sal_uInt32 nSplitIx = GetColumnCount() - 1; nSplitIx > nColIx; --nSplitIx ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir sal_Int32 nPos = maSplits[ nSplitIx ]; 748cdf0e10cSrcweir maSplits.Remove( nPos ); 749cdf0e10cSrcweir maSplits.Insert( nPos + nDiff ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir } 752cdf0e10cSrcweir } 753cdf0e10cSrcweir else 754cdf0e10cSrcweir { 755cdf0e10cSrcweir // append new column 756cdf0e10cSrcweir sal_Int32 nLastPos = GetPosCount(); 757cdf0e10cSrcweir Execute( CSVCMD_SETPOSCOUNT, nLastPos + nWidth ); 758cdf0e10cSrcweir ImplInsertSplit( nLastPos ); 759cdf0e10cSrcweir } 760cdf0e10cSrcweir 761cdf0e10cSrcweir if( aCellText.Len() <= CSV_MAXSTRLEN ) 762cdf0e10cSrcweir rStrVec.push_back( aCellText ); 763cdf0e10cSrcweir else 764cdf0e10cSrcweir rStrVec.push_back( aCellText.Copy( 0, CSV_MAXSTRLEN ) ); 765cdf0e10cSrcweir ++nColIx; 766cdf0e10cSrcweir } 767cdf0e10cSrcweir InvalidateGfx(); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir 770cdf0e10cSrcweir void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const String& rTextLine ) 771cdf0e10cSrcweir { 772cdf0e10cSrcweir if( nLine < GetFirstVisLine() ) return; 773cdf0e10cSrcweir 774cdf0e10cSrcweir sal_Int32 nChars = rTextLine.Len(); 775cdf0e10cSrcweir if( nChars > GetPosCount() ) 776cdf0e10cSrcweir Execute( CSVCMD_SETPOSCOUNT, nChars ); 777cdf0e10cSrcweir 778cdf0e10cSrcweir sal_uInt32 nLineIx = nLine - GetFirstVisLine(); 779cdf0e10cSrcweir while( maTexts.size() <= nLineIx ) 780cdf0e10cSrcweir maTexts.push_back( StringVec() ); 781cdf0e10cSrcweir 782cdf0e10cSrcweir StringVec& rStrVec = maTexts[ nLineIx ]; 783cdf0e10cSrcweir rStrVec.clear(); 784cdf0e10cSrcweir sal_uInt32 nColCount = GetColumnCount(); 785cdf0e10cSrcweir xub_StrLen nStrLen = rTextLine.Len(); 786cdf0e10cSrcweir xub_StrLen nStrIx = 0; 787cdf0e10cSrcweir for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir xub_StrLen nColWidth = static_cast< xub_StrLen >( GetColumnWidth( nColIx ) ); 790cdf0e10cSrcweir rStrVec.push_back( rTextLine.Copy( nStrIx, Max( nColWidth, CSV_MAXSTRLEN ) ) ); 791cdf0e10cSrcweir nStrIx = sal::static_int_cast<xub_StrLen>( nStrIx + nColWidth ); 792cdf0e10cSrcweir } 793cdf0e10cSrcweir InvalidateGfx(); 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir const String& ScCsvGrid::GetCellText( sal_uInt32 nColIndex, sal_Int32 nLine ) const 797cdf0e10cSrcweir { 798cdf0e10cSrcweir if( nLine < GetFirstVisLine() ) return EMPTY_STRING; 799cdf0e10cSrcweir 800cdf0e10cSrcweir sal_uInt32 nLineIx = nLine - GetFirstVisLine(); 801cdf0e10cSrcweir if( nLineIx >= maTexts.size() ) return EMPTY_STRING; 802cdf0e10cSrcweir 803cdf0e10cSrcweir const StringVec& rStrVec = maTexts[ nLineIx ]; 804cdf0e10cSrcweir if( nColIndex >= rStrVec.size() ) return EMPTY_STRING; 805cdf0e10cSrcweir 806cdf0e10cSrcweir return rStrVec[ nColIndex ]; 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir 810cdf0e10cSrcweir // event handling ------------------------------------------------------------- 811cdf0e10cSrcweir 812cdf0e10cSrcweir void ScCsvGrid::Resize() 813cdf0e10cSrcweir { 814cdf0e10cSrcweir ScCsvControl::Resize(); 815cdf0e10cSrcweir InitSizeData(); 816cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 817cdf0e10cSrcweir } 818cdf0e10cSrcweir 819cdf0e10cSrcweir void ScCsvGrid::GetFocus() 820cdf0e10cSrcweir { 821cdf0e10cSrcweir ScCsvControl::GetFocus(); 822cdf0e10cSrcweir Execute( CSVCMD_MOVEGRIDCURSOR, GetNoScrollCol( GetGridCursorPos() ) ); 823cdf0e10cSrcweir Repaint(); 824cdf0e10cSrcweir } 825cdf0e10cSrcweir 826cdf0e10cSrcweir void ScCsvGrid::LoseFocus() 827cdf0e10cSrcweir { 828cdf0e10cSrcweir ScCsvControl::LoseFocus(); 829cdf0e10cSrcweir Repaint(); 830cdf0e10cSrcweir } 831cdf0e10cSrcweir 832cdf0e10cSrcweir void ScCsvGrid::MouseButtonDown( const MouseEvent& rMEvt ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir DisableRepaint(); 835cdf0e10cSrcweir if( !HasFocus() ) 836cdf0e10cSrcweir GrabFocus(); 837cdf0e10cSrcweir 838cdf0e10cSrcweir Point aPos( rMEvt.GetPosPixel() ); 839cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromX( aPos.X() ); 840cdf0e10cSrcweir 841cdf0e10cSrcweir if( rMEvt.IsLeft() ) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir if( (GetFirstX() > aPos.X()) || (aPos.X() > GetLastX()) ) // in header column 844cdf0e10cSrcweir { 845cdf0e10cSrcweir if( aPos.Y() <= GetHdrHeight() ) 846cdf0e10cSrcweir SelectAll(); 847cdf0e10cSrcweir } 848cdf0e10cSrcweir else if( IsValidColumn( nColIx ) ) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir DoSelectAction( nColIx, rMEvt.GetModifier() ); 851cdf0e10cSrcweir mnMTCurrCol = nColIx; 852cdf0e10cSrcweir mbMTSelecting = IsSelected( nColIx ); 853cdf0e10cSrcweir StartTracking( STARTTRACK_BUTTONREPEAT ); 854cdf0e10cSrcweir } 855cdf0e10cSrcweir } 856cdf0e10cSrcweir EnableRepaint(); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir 859cdf0e10cSrcweir void ScCsvGrid::Tracking( const TrackingEvent& rTEvt ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir if( rTEvt.IsTrackingEnded() || rTEvt.IsTrackingRepeat() ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir DisableRepaint(); 864cdf0e10cSrcweir const MouseEvent& rMEvt = rTEvt.GetMouseEvent(); 865cdf0e10cSrcweir 866cdf0e10cSrcweir sal_Int32 nPos = (rMEvt.GetPosPixel().X() - GetFirstX()) / GetCharWidth() + GetFirstVisPos(); 867cdf0e10cSrcweir // on mouse tracking: keep position valid 868cdf0e10cSrcweir nPos = Max( Min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 0 ) ); 869cdf0e10cSrcweir Execute( CSVCMD_MAKEPOSVISIBLE, nPos ); 870cdf0e10cSrcweir 871cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromPos( nPos ); 872cdf0e10cSrcweir if( mnMTCurrCol != nColIx ) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir DoSelectAction( nColIx, rMEvt.GetModifier() ); 875cdf0e10cSrcweir mnMTCurrCol = nColIx; 876cdf0e10cSrcweir } 877cdf0e10cSrcweir EnableRepaint(); 878cdf0e10cSrcweir } 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir void ScCsvGrid::KeyInput( const KeyEvent& rKEvt ) 882cdf0e10cSrcweir { 883cdf0e10cSrcweir const KeyCode& rKCode = rKEvt.GetKeyCode(); 884cdf0e10cSrcweir sal_uInt16 nCode = rKCode.GetCode(); 885cdf0e10cSrcweir bool bShift = rKCode.IsShift() == sal_True; 886cdf0e10cSrcweir bool bMod1 = rKCode.IsMod1() == sal_True; 887cdf0e10cSrcweir 888cdf0e10cSrcweir if( !rKCode.IsMod2() ) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir ScMoveMode eHDir = GetHorzDirection( nCode, !bMod1 ); 891cdf0e10cSrcweir ScMoveMode eVDir = GetVertDirection( nCode, bMod1 ); 892cdf0e10cSrcweir 893cdf0e10cSrcweir if( eHDir != MOVE_NONE ) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir DisableRepaint(); 896cdf0e10cSrcweir MoveCursorRel( eHDir ); 897cdf0e10cSrcweir if( !bMod1 ) 898cdf0e10cSrcweir ImplClearSelection(); 899cdf0e10cSrcweir if( bShift ) 900cdf0e10cSrcweir SelectRange( mnRecentSelCol, GetFocusColumn() ); 901cdf0e10cSrcweir else if( !bMod1 ) 902cdf0e10cSrcweir Select( GetFocusColumn() ); 903cdf0e10cSrcweir EnableRepaint(); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir else if( eVDir != MOVE_NONE ) 906cdf0e10cSrcweir ScrollVertRel( eVDir ); 907cdf0e10cSrcweir else if( nCode == KEY_SPACE ) 908cdf0e10cSrcweir { 909cdf0e10cSrcweir if( !bMod1 ) 910cdf0e10cSrcweir ImplClearSelection(); 911cdf0e10cSrcweir if( bShift ) 912cdf0e10cSrcweir SelectRange( mnRecentSelCol, GetFocusColumn() ); 913cdf0e10cSrcweir else if( bMod1 ) 914cdf0e10cSrcweir ToggleSelect( GetFocusColumn() ); 915cdf0e10cSrcweir else 916cdf0e10cSrcweir Select( GetFocusColumn() ); 917cdf0e10cSrcweir } 918cdf0e10cSrcweir else if( !bShift && bMod1 ) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir if( nCode == KEY_A ) 921cdf0e10cSrcweir SelectAll(); 922cdf0e10cSrcweir else if( (KEY_1 <= nCode) && (nCode <= KEY_9) ) 923cdf0e10cSrcweir { 924cdf0e10cSrcweir sal_uInt32 nType = nCode - KEY_1; 925cdf0e10cSrcweir if( nType < maTypeNames.size() ) 926cdf0e10cSrcweir Execute( CSVCMD_SETCOLUMNTYPE, nType ); 927cdf0e10cSrcweir } 928cdf0e10cSrcweir } 929cdf0e10cSrcweir } 930cdf0e10cSrcweir 931cdf0e10cSrcweir if( rKCode.GetGroup() != KEYGROUP_CURSOR ) 932cdf0e10cSrcweir ScCsvControl::KeyInput( rKEvt ); 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935cdf0e10cSrcweir void ScCsvGrid::Command( const CommandEvent& rCEvt ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir switch( rCEvt.GetCommand() ) 938cdf0e10cSrcweir { 939cdf0e10cSrcweir case COMMAND_CONTEXTMENU: 940cdf0e10cSrcweir { 941cdf0e10cSrcweir if( rCEvt.IsMouseEvent() ) 942cdf0e10cSrcweir { 943cdf0e10cSrcweir Point aPos( rCEvt.GetMousePosPixel() ); 944cdf0e10cSrcweir sal_uInt32 nColIx = GetColumnFromX( aPos.X() ); 945cdf0e10cSrcweir if( IsValidColumn( nColIx ) && (GetFirstX() <= aPos.X()) && (aPos.X() <= GetLastX()) ) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir if( !IsSelected( nColIx ) ) 948cdf0e10cSrcweir DoSelectAction( nColIx, 0 ); // focus & select 949cdf0e10cSrcweir ExecutePopup( aPos ); 950cdf0e10cSrcweir } 951cdf0e10cSrcweir } 952cdf0e10cSrcweir else 953cdf0e10cSrcweir { 954cdf0e10cSrcweir sal_uInt32 nColIx = GetFocusColumn(); 955cdf0e10cSrcweir if( !IsSelected( nColIx ) ) 956cdf0e10cSrcweir Select( nColIx ); 957cdf0e10cSrcweir sal_Int32 nX1 = Max( GetColumnX( nColIx ), GetFirstX() ); 958cdf0e10cSrcweir sal_Int32 nX2 = Min( GetColumnX( nColIx + 1 ), GetWidth() ); 959cdf0e10cSrcweir ExecutePopup( Point( (nX1 + nX2) / 2, GetHeight() / 2 ) ); 960cdf0e10cSrcweir } 961cdf0e10cSrcweir } 962cdf0e10cSrcweir break; 963cdf0e10cSrcweir case COMMAND_WHEEL: 964cdf0e10cSrcweir { 965cdf0e10cSrcweir Point aPoint; 966cdf0e10cSrcweir Rectangle aRect( aPoint, maWinSize ); 967cdf0e10cSrcweir if( aRect.IsInside( rCEvt.GetMousePosPixel() ) ) 968cdf0e10cSrcweir { 969cdf0e10cSrcweir const CommandWheelData* pData = rCEvt.GetWheelData(); 970cdf0e10cSrcweir if( pData && (pData->GetMode() == COMMAND_WHEEL_SCROLL) && !pData->IsHorz() ) 971cdf0e10cSrcweir Execute( CSVCMD_SETLINEOFFSET, GetFirstVisLine() - pData->GetNotchDelta() ); 972cdf0e10cSrcweir } 973cdf0e10cSrcweir } 974cdf0e10cSrcweir break; 975cdf0e10cSrcweir default: 976cdf0e10cSrcweir ScCsvControl::Command( rCEvt ); 977cdf0e10cSrcweir } 978cdf0e10cSrcweir } 979cdf0e10cSrcweir 980cdf0e10cSrcweir void ScCsvGrid::DataChanged( const DataChangedEvent& rDCEvt ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 983cdf0e10cSrcweir { 984cdf0e10cSrcweir InitColors(); 985cdf0e10cSrcweir InitFonts(); 986cdf0e10cSrcweir UpdateLayoutData(); 987cdf0e10cSrcweir Execute( CSVCMD_UPDATECELLTEXTS ); 988cdf0e10cSrcweir } 989cdf0e10cSrcweir ScCsvControl::DataChanged( rDCEvt ); 990cdf0e10cSrcweir } 991cdf0e10cSrcweir 992cdf0e10cSrcweir void ScCsvGrid::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 ) 993cdf0e10cSrcweir { 994cdf0e10cSrcweir InitColors(); 995cdf0e10cSrcweir Repaint(); 996cdf0e10cSrcweir } 997cdf0e10cSrcweir 998cdf0e10cSrcweir 999cdf0e10cSrcweir // painting ------------------------------------------------------------------- 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir void ScCsvGrid::Paint( const Rectangle& ) 1002cdf0e10cSrcweir { 1003cdf0e10cSrcweir Repaint(); 1004cdf0e10cSrcweir } 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir void ScCsvGrid::ImplRedraw() 1007cdf0e10cSrcweir { 1008cdf0e10cSrcweir if( IsVisible() ) 1009cdf0e10cSrcweir { 1010cdf0e10cSrcweir if( !IsValidGfx() ) 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir ValidateGfx(); 1013cdf0e10cSrcweir ImplDrawBackgrDev(); 1014cdf0e10cSrcweir ImplDrawGridDev(); 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir DrawOutDev( Point(), maWinSize, Point(), maWinSize, maGridDev ); 1017cdf0e10cSrcweir ImplDrawTrackingRect( GetFocusColumn() ); 1018cdf0e10cSrcweir } 1019cdf0e10cSrcweir } 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir EditEngine* ScCsvGrid::GetEditEngine() 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir return mpEditEngine.get(); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir void ScCsvGrid::ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex ) 1027cdf0e10cSrcweir { 1028cdf0e10cSrcweir rOutDev.SetClipRegion( Region( Rectangle( 1029cdf0e10cSrcweir Max( GetColumnX( nColIndex ), GetFirstX() ) + 1, 0, 1030cdf0e10cSrcweir Min( GetColumnX( nColIndex + 1 ), GetLastX() ), GetHeight() - 1 ) ) ); 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir void ScCsvGrid::ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor ) 1034cdf0e10cSrcweir { 1035cdf0e10cSrcweir sal_Int32 nX1 = GetColumnX( nColIndex ) + 1; 1036cdf0e10cSrcweir sal_Int32 nX2 = GetColumnX( nColIndex + 1 ); 1037cdf0e10cSrcweir sal_Int32 nHdrHt = GetHdrHeight(); 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir rOutDev.SetLineColor(); 1040cdf0e10cSrcweir rOutDev.SetFillColor( aFillColor ); 1041cdf0e10cSrcweir rOutDev.DrawRect( Rectangle( nX1, 0, nX2, nHdrHt ) ); 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir rOutDev.SetFont( maHeaderFont ); 1044cdf0e10cSrcweir rOutDev.SetTextColor( maHeaderTextColor ); 1045cdf0e10cSrcweir rOutDev.SetTextFillColor(); 1046cdf0e10cSrcweir rOutDev.DrawText( Point( nX1 + 1, 0 ), GetColumnTypeName( nColIndex ) ); 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir rOutDev.SetLineColor( maHeaderGridColor ); 1049cdf0e10cSrcweir rOutDev.DrawLine( Point( nX1, nHdrHt ), Point( nX2, nHdrHt ) ); 1050cdf0e10cSrcweir rOutDev.DrawLine( Point( nX2, 0 ), Point( nX2, nHdrHt ) ); 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir void ScCsvGrid::ImplDrawCellText( const Point& rPos, const String& rText ) 1054cdf0e10cSrcweir { 1055cdf0e10cSrcweir String aPlainText( rText ); 1056cdf0e10cSrcweir aPlainText.SearchAndReplaceAll( '\t', ' ' ); 1057cdf0e10cSrcweir aPlainText.SearchAndReplaceAll( '\n', ' ' ); 1058cdf0e10cSrcweir mpEditEngine->SetPaperSize( maEdEngSize ); 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir /* #i60296# If string contains mixed script types, the space character 1061cdf0e10cSrcweir U+0020 may be drawn with a wrong width (from non-fixed-width Asian or 1062cdf0e10cSrcweir Complex font). Now we draw every non-space portion separately. */ 1063cdf0e10cSrcweir xub_StrLen nTokenCount = aPlainText.GetTokenCount( ' ' ); 1064cdf0e10cSrcweir xub_StrLen nCharIx = 0; 1065cdf0e10cSrcweir for( xub_StrLen nToken = 0; nToken < nTokenCount; ++nToken ) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir xub_StrLen nBeginIx = nCharIx; 1068cdf0e10cSrcweir String aToken = aPlainText.GetToken( 0, ' ', nCharIx ); 1069cdf0e10cSrcweir if( aToken.Len() > 0 ) 1070cdf0e10cSrcweir { 1071cdf0e10cSrcweir sal_Int32 nX = rPos.X() + GetCharWidth() * nBeginIx; 1072cdf0e10cSrcweir mpEditEngine->SetText( aToken ); 1073cdf0e10cSrcweir mpEditEngine->Draw( &maBackgrDev, Point( nX, rPos.Y() ) ); 1074cdf0e10cSrcweir } 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir nCharIx = 0; 1078cdf0e10cSrcweir while( (nCharIx = rText.Search( '\t', nCharIx )) != STRING_NOTFOUND ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx; 1081cdf0e10cSrcweir sal_Int32 nX2 = nX1 + GetCharWidth() - 2; 1082cdf0e10cSrcweir sal_Int32 nY = rPos.Y() + GetLineHeight() / 2; 1083cdf0e10cSrcweir Color aColor( maTextColor ); 1084cdf0e10cSrcweir maBackgrDev.SetLineColor( aColor ); 1085cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX1, nY ), Point( nX2, nY ) ); 1086cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX2 - 2, nY - 2 ), Point( nX2, nY ) ); 1087cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX2 - 2, nY + 2 ), Point( nX2, nY ) ); 1088cdf0e10cSrcweir ++nCharIx; 1089cdf0e10cSrcweir } 1090cdf0e10cSrcweir nCharIx = 0; 1091cdf0e10cSrcweir while( (nCharIx = rText.Search( '\n', nCharIx )) != STRING_NOTFOUND ) 1092cdf0e10cSrcweir { 1093cdf0e10cSrcweir sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx; 1094cdf0e10cSrcweir sal_Int32 nX2 = nX1 + GetCharWidth() - 2; 1095cdf0e10cSrcweir sal_Int32 nY = rPos.Y() + GetLineHeight() / 2; 1096cdf0e10cSrcweir Color aColor( maTextColor ); 1097cdf0e10cSrcweir maBackgrDev.SetLineColor( aColor ); 1098cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX1, nY ), Point( nX2, nY ) ); 1099cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX1 + 2, nY - 2 ), Point( nX1, nY ) ); 1100cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX1 + 2, nY + 2 ), Point( nX1, nY ) ); 1101cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX2, nY - 2 ), Point( nX2, nY ) ); 1102cdf0e10cSrcweir ++nCharIx; 1103cdf0e10cSrcweir } 1104cdf0e10cSrcweir } 1105cdf0e10cSrcweir 1106cdf0e10cSrcweir void ScCsvGrid::ImplDrawFirstLineSep( bool bSet ) 1107cdf0e10cSrcweir { 1108cdf0e10cSrcweir if( IsVisibleLine( mnFirstImpLine ) && (mnFirstImpLine != GetFirstVisLine() ) ) 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir sal_Int32 nY = GetY( mnFirstImpLine ); 1111cdf0e10cSrcweir sal_Int32 nX = Min( GetColumnX( GetLastVisColumn() + 1 ), GetLastX() ); 1112cdf0e10cSrcweir maBackgrDev.SetLineColor( bSet ? maGridPBColor : maGridColor ); 1113cdf0e10cSrcweir maBackgrDev.DrawLine( Point( GetFirstX() + 1, nY ), Point( nX, nY ) ); 1114cdf0e10cSrcweir } 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir void ScCsvGrid::ImplDrawColumnBackgr( sal_uInt32 nColIndex ) 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir if( !IsVisibleColumn( nColIndex ) ) 1120cdf0e10cSrcweir return; 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir ImplSetColumnClipRegion( maBackgrDev, nColIndex ); 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir // grid 1125cdf0e10cSrcweir maBackgrDev.SetLineColor(); 1126cdf0e10cSrcweir maBackgrDev.SetFillColor( maBackColor ); 1127cdf0e10cSrcweir sal_Int32 nX1 = GetColumnX( nColIndex ) + 1; 1128cdf0e10cSrcweir sal_Int32 nX2 = GetColumnX( nColIndex + 1 ); 1129cdf0e10cSrcweir sal_Int32 nY2 = GetY( GetLastVisLine() + 1 ); 1130cdf0e10cSrcweir sal_Int32 nHdrHt = GetHdrHeight(); 1131cdf0e10cSrcweir Rectangle aRect( nX1, nHdrHt, nX2, nY2 ); 1132cdf0e10cSrcweir maBackgrDev.DrawRect( aRect ); 1133cdf0e10cSrcweir maBackgrDev.SetLineColor( maGridColor ); 1134cdf0e10cSrcweir maBackgrDev.DrawGrid( aRect, Size( 1, GetLineHeight() ), GRID_HORZLINES ); 1135cdf0e10cSrcweir maBackgrDev.DrawLine( Point( nX2, nHdrHt ), Point( nX2, nY2 ) ); 1136cdf0e10cSrcweir ImplDrawFirstLineSep( true ); 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir // cell texts 1139cdf0e10cSrcweir mpEditEngine->SetDefaultItem( SvxColorItem( maTextColor, EE_CHAR_COLOR ) ); 1140cdf0e10cSrcweir size_t nLineCount = ::std::min( static_cast< size_t >( GetLastVisLine() - GetFirstVisLine() + 1 ), maTexts.size() ); 1141cdf0e10cSrcweir // #i67432# cut string to avoid edit engine performance problems with very large strings 1142cdf0e10cSrcweir sal_Int32 nFirstVisPos = ::std::max( GetColumnPos( nColIndex ), GetFirstVisPos() ); 1143cdf0e10cSrcweir sal_Int32 nLastVisPos = ::std::min( GetColumnPos( nColIndex + 1 ), GetLastVisPos() ); 1144cdf0e10cSrcweir xub_StrLen nStrPos = static_cast< xub_StrLen >( nFirstVisPos - GetColumnPos( nColIndex ) ); 1145cdf0e10cSrcweir xub_StrLen nStrLen = static_cast< xub_StrLen >( nLastVisPos - nFirstVisPos + 1 ); 1146cdf0e10cSrcweir sal_Int32 nStrX = GetX( nFirstVisPos ); 1147cdf0e10cSrcweir for( size_t nLine = 0; nLine < nLineCount; ++nLine ) 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir StringVec& rStrVec = maTexts[ nLine ]; 1150cdf0e10cSrcweir if( (nColIndex < rStrVec.size()) && (rStrVec[ nColIndex ].Len() > nStrPos) ) 1151cdf0e10cSrcweir { 1152cdf0e10cSrcweir String aText( rStrVec[ nColIndex ], nStrPos, nStrLen ); 1153cdf0e10cSrcweir ImplDrawCellText( Point( nStrX, GetY( GetFirstVisLine() + nLine ) ), aText ); 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir 1157cdf0e10cSrcweir // header 1158cdf0e10cSrcweir ImplDrawColumnHeader( maBackgrDev, nColIndex, maHeaderBackColor ); 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir maBackgrDev.SetClipRegion(); 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir void ScCsvGrid::ImplDrawRowHeaders() 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir maBackgrDev.SetLineColor(); 1166cdf0e10cSrcweir maBackgrDev.SetFillColor( maAppBackColor ); 1167cdf0e10cSrcweir Point aPoint( GetHdrX(), 0 ); 1168cdf0e10cSrcweir Rectangle aRect( aPoint, Size( GetHdrWidth() + 1, GetHeight() ) ); 1169cdf0e10cSrcweir maBackgrDev.DrawRect( aRect ); 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir maBackgrDev.SetFillColor( maHeaderBackColor ); 1172cdf0e10cSrcweir aRect.Bottom() = GetY( GetLastVisLine() + 1 ); 1173cdf0e10cSrcweir maBackgrDev.DrawRect( aRect ); 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir // line numbers 1176cdf0e10cSrcweir maBackgrDev.SetFont( maHeaderFont ); 1177cdf0e10cSrcweir maBackgrDev.SetTextColor( maHeaderTextColor ); 1178cdf0e10cSrcweir maBackgrDev.SetTextFillColor(); 1179cdf0e10cSrcweir sal_Int32 nLastLine = GetLastVisLine(); 1180cdf0e10cSrcweir for( sal_Int32 nLine = GetFirstVisLine(); nLine <= nLastLine; ++nLine ) 1181cdf0e10cSrcweir { 1182cdf0e10cSrcweir String aText( String::CreateFromInt32( nLine + 1 ) ); 1183cdf0e10cSrcweir sal_Int32 nX = GetHdrX() + (GetHdrWidth() - maBackgrDev.GetTextWidth( aText )) / 2; 1184cdf0e10cSrcweir maBackgrDev.DrawText( Point( nX, GetY( nLine ) ), aText ); 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir // grid 1188cdf0e10cSrcweir maBackgrDev.SetLineColor( maHeaderGridColor ); 1189cdf0e10cSrcweir if( IsRTL() ) 1190cdf0e10cSrcweir { 1191cdf0e10cSrcweir maBackgrDev.DrawLine( Point( 0, 0 ), Point( 0, GetHeight() - 1 ) ); 1192cdf0e10cSrcweir maBackgrDev.DrawLine( aRect.TopLeft(), aRect.BottomLeft() ); 1193cdf0e10cSrcweir } 1194cdf0e10cSrcweir else 1195cdf0e10cSrcweir maBackgrDev.DrawLine( aRect.TopRight(), aRect.BottomRight() ); 1196cdf0e10cSrcweir aRect.Top() = GetHdrHeight(); 1197cdf0e10cSrcweir maBackgrDev.DrawGrid( aRect, Size( 1, GetLineHeight() ), GRID_HORZLINES ); 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir void ScCsvGrid::ImplDrawBackgrDev() 1201cdf0e10cSrcweir { 1202cdf0e10cSrcweir maBackgrDev.SetLineColor(); 1203cdf0e10cSrcweir maBackgrDev.SetFillColor( maAppBackColor ); 1204cdf0e10cSrcweir maBackgrDev.DrawRect( Rectangle( 1205cdf0e10cSrcweir Point( GetFirstX() + 1, 0 ), Size( GetWidth() - GetHdrWidth(), GetHeight() ) ) ); 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir sal_uInt32 nLastCol = GetLastVisColumn(); 1208cdf0e10cSrcweir for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx ) 1209cdf0e10cSrcweir ImplDrawColumnBackgr( nColIx ); 1210cdf0e10cSrcweir 1211cdf0e10cSrcweir ImplDrawRowHeaders(); 1212cdf0e10cSrcweir } 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir void ScCsvGrid::ImplDrawColumnSelection( sal_uInt32 nColIndex ) 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir ImplInvertCursor( GetRulerCursorPos() ); 1217cdf0e10cSrcweir ImplSetColumnClipRegion( maGridDev, nColIndex ); 1218cdf0e10cSrcweir maGridDev.DrawOutDev( Point(), maWinSize, Point(), maWinSize, maBackgrDev ); 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir if( IsSelected( nColIndex ) ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir sal_Int32 nX1 = GetColumnX( nColIndex ) + 1; 1223cdf0e10cSrcweir sal_Int32 nX2 = GetColumnX( nColIndex + 1 ); 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir // header 1226cdf0e10cSrcweir Rectangle aRect( nX1, 0, nX2, GetHdrHeight() ); 1227cdf0e10cSrcweir maGridDev.SetLineColor(); 1228cdf0e10cSrcweir if( maHeaderBackColor.IsDark() ) 1229cdf0e10cSrcweir // redraw with light gray background in dark mode 1230cdf0e10cSrcweir ImplDrawColumnHeader( maGridDev, nColIndex, COL_LIGHTGRAY ); 1231cdf0e10cSrcweir else 1232cdf0e10cSrcweir { 1233cdf0e10cSrcweir // use transparent active color 1234cdf0e10cSrcweir maGridDev.SetFillColor( maSelectColor ); 1235cdf0e10cSrcweir maGridDev.DrawTransparent( PolyPolygon( Polygon( aRect ) ), CSV_HDR_TRANSPARENCY ); 1236cdf0e10cSrcweir } 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir // column selection 1239cdf0e10cSrcweir aRect = Rectangle( nX1, GetHdrHeight() + 1, nX2, GetY( GetLastVisLine() + 1 ) - 1 ); 1240cdf0e10cSrcweir ImplInvertRect( maGridDev, aRect ); 1241cdf0e10cSrcweir } 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir maGridDev.SetClipRegion(); 1244cdf0e10cSrcweir ImplInvertCursor( GetRulerCursorPos() ); 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir void ScCsvGrid::ImplDrawGridDev() 1248cdf0e10cSrcweir { 1249cdf0e10cSrcweir maGridDev.DrawOutDev( Point(), maWinSize, Point(), maWinSize, maBackgrDev ); 1250cdf0e10cSrcweir sal_uInt32 nLastCol = GetLastVisColumn(); 1251cdf0e10cSrcweir for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx ) 1252cdf0e10cSrcweir ImplDrawColumnSelection( nColIx ); 1253cdf0e10cSrcweir } 1254cdf0e10cSrcweir 1255cdf0e10cSrcweir void ScCsvGrid::ImplDrawColumn( sal_uInt32 nColIndex ) 1256cdf0e10cSrcweir { 1257cdf0e10cSrcweir ImplDrawColumnBackgr( nColIndex ); 1258cdf0e10cSrcweir ImplDrawColumnSelection( nColIndex ); 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir void ScCsvGrid::ImplDrawHorzScrolled( sal_Int32 nOldPos ) 1262cdf0e10cSrcweir { 1263cdf0e10cSrcweir sal_Int32 nPos = GetFirstVisPos(); 1264cdf0e10cSrcweir if( !IsValidGfx() || (nPos == nOldPos) ) 1265cdf0e10cSrcweir return; 1266cdf0e10cSrcweir if( Abs( nPos - nOldPos ) > GetVisPosCount() / 2 ) 1267cdf0e10cSrcweir { 1268cdf0e10cSrcweir ImplDrawBackgrDev(); 1269cdf0e10cSrcweir ImplDrawGridDev(); 1270cdf0e10cSrcweir return; 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir Point aSrc, aDest; 1274cdf0e10cSrcweir sal_uInt32 nFirstColIx, nLastColIx; 1275cdf0e10cSrcweir if( nPos < nOldPos ) 1276cdf0e10cSrcweir { 1277cdf0e10cSrcweir aSrc = Point( GetFirstX() + 1, 0 ); 1278cdf0e10cSrcweir aDest = Point( GetFirstX() + GetCharWidth() * (nOldPos - nPos) + 1, 0 ); 1279cdf0e10cSrcweir nFirstColIx = GetColumnFromPos( nPos ); 1280cdf0e10cSrcweir nLastColIx = GetColumnFromPos( nOldPos ); 1281cdf0e10cSrcweir } 1282cdf0e10cSrcweir else 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir aSrc = Point( GetFirstX() + GetCharWidth() * (nPos - nOldPos) + 1, 0 ); 1285cdf0e10cSrcweir aDest = Point( GetFirstX() + 1, 0 ); 1286cdf0e10cSrcweir nFirstColIx = GetColumnFromPos( Min( nOldPos + GetVisPosCount(), GetPosCount() ) - 1 ); 1287cdf0e10cSrcweir nLastColIx = GetColumnFromPos( Min( nPos + GetVisPosCount(), GetPosCount() ) - 1 ); 1288cdf0e10cSrcweir } 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir ImplInvertCursor( GetRulerCursorPos() + (nPos - nOldPos) ); 1291cdf0e10cSrcweir Rectangle aRectangle( GetFirstX(), 0, GetLastX(), GetHeight() - 1 ); 1292cdf0e10cSrcweir Region aClipReg( aRectangle ); 1293cdf0e10cSrcweir maBackgrDev.SetClipRegion( aClipReg ); 1294cdf0e10cSrcweir maBackgrDev.CopyArea( aDest, aSrc, maWinSize ); 1295cdf0e10cSrcweir maBackgrDev.SetClipRegion(); 1296cdf0e10cSrcweir maGridDev.SetClipRegion( aClipReg ); 1297cdf0e10cSrcweir maGridDev.CopyArea( aDest, aSrc, maWinSize ); 1298cdf0e10cSrcweir maGridDev.SetClipRegion(); 1299cdf0e10cSrcweir ImplInvertCursor( GetRulerCursorPos() ); 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir for( sal_uInt32 nColIx = nFirstColIx; nColIx <= nLastColIx; ++nColIx ) 1302cdf0e10cSrcweir ImplDrawColumn( nColIx ); 1303cdf0e10cSrcweir 1304cdf0e10cSrcweir sal_Int32 nLastX = GetX( GetPosCount() ) + 1; 1305cdf0e10cSrcweir if( nLastX <= GetLastX() ) 1306cdf0e10cSrcweir { 1307cdf0e10cSrcweir Rectangle aRect( nLastX, 0, GetLastX(), GetHeight() - 1 ); 1308cdf0e10cSrcweir maBackgrDev.SetLineColor(); 1309cdf0e10cSrcweir maBackgrDev.SetFillColor( maAppBackColor ); 1310cdf0e10cSrcweir maBackgrDev.DrawRect( aRect ); 1311cdf0e10cSrcweir maGridDev.SetLineColor(); 1312cdf0e10cSrcweir maGridDev.SetFillColor( maAppBackColor ); 1313cdf0e10cSrcweir maGridDev.DrawRect( aRect ); 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir } 1316cdf0e10cSrcweir 1317cdf0e10cSrcweir void ScCsvGrid::ImplInvertCursor( sal_Int32 nPos ) 1318cdf0e10cSrcweir { 1319cdf0e10cSrcweir if( IsVisibleSplitPos( nPos ) ) 1320cdf0e10cSrcweir { 1321cdf0e10cSrcweir sal_Int32 nX = GetX( nPos ) - 1; 1322cdf0e10cSrcweir Rectangle aRect( Point( nX, 0 ), Size( 3, GetHdrHeight() ) ); 1323cdf0e10cSrcweir ImplInvertRect( maGridDev, aRect ); 1324cdf0e10cSrcweir aRect.Top() = GetHdrHeight() + 1; 1325cdf0e10cSrcweir aRect.Bottom() = GetY( GetLastVisLine() + 1 ); 1326cdf0e10cSrcweir ImplInvertRect( maGridDev, aRect ); 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir } 1329cdf0e10cSrcweir 1330cdf0e10cSrcweir void ScCsvGrid::ImplDrawTrackingRect( sal_uInt32 nColIndex ) 1331cdf0e10cSrcweir { 1332cdf0e10cSrcweir if( HasFocus() && IsVisibleColumn( nColIndex ) ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir sal_Int32 nX1 = Max( GetColumnX( nColIndex ), GetFirstX() ) + 1; 1335cdf0e10cSrcweir sal_Int32 nX2 = Min( GetColumnX( nColIndex + 1 ) - sal_Int32( 1 ), GetLastX() ); 1336cdf0e10cSrcweir sal_Int32 nY2 = Min( GetY( GetLastVisLine() + 1 ), GetHeight() ) - 1; 1337cdf0e10cSrcweir InvertTracking( Rectangle( nX1, 0, nX2, nY2 ), SHOWTRACK_SMALL | SHOWTRACK_WINDOW ); 1338cdf0e10cSrcweir } 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir // accessibility ============================================================== 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir ScAccessibleCsvControl* ScCsvGrid::ImplCreateAccessible() 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir return new ScAccessibleCsvGrid( *this ); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir // ============================================================================ 1351cdf0e10cSrcweir 1352