LibreOffice Module sc (master)  1
csvgrid.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 
20 #include <csvgrid.hxx>
21 #include <csvtablebox.hxx>
22 
23 #include <algorithm>
24 #include <memory>
25 
26 #include <svtools/colorcfg.hxx>
27 #include <sal/macros.h>
28 #include <tools/poly.hxx>
29 #include <scmod.hxx>
30 #include <asciiopt.hxx>
31 #include <impex.hxx>
32 #include <AccessibleCsvControl.hxx>
33 
34 // *** edit engine ***
35 #include <editeng/eeitem.hxx>
36 #include <vcl/commandevent.hxx>
37 #include <vcl/event.hxx>
38 #include <vcl/settings.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/virdev.hxx>
41 #include <vcl/weldutils.hxx>
42 
43 #include <editeng/colritem.hxx>
44 #include <editeng/fhgtitem.hxx>
45 #include <editeng/fontitem.hxx>
46 #include <editeng/wghtitem.hxx>
47 #include <editeng/postitem.hxx>
48 #include <editeng/langitem.hxx>
49 #include <svl/itemset.hxx>
50 #include <editutil.hxx>
51 // *** edit engine ***
52 
53 namespace {
54 
55 struct Func_SetType
56 {
57  sal_Int32 mnType;
58  explicit Func_SetType( sal_Int32 nType ) : mnType( nType ) {}
59  void operator()( ScCsvColState& rState ) const
60  { rState.mnType = mnType; }
61 };
62 
63 struct Func_Select
64 {
65  bool mbSelect;
66  explicit Func_Select( bool bSelect ) : mbSelect( bSelect ) {}
67  void operator()( ScCsvColState& rState ) const
68  { rState.Select( mbSelect ); }
69 };
70 
71 }
72 
73 ScCsvGrid::ScCsvGrid(const ScCsvLayoutData& rData, std::unique_ptr<weld::Menu> xPopup, ScCsvTableBox* pTableBox)
74  : ScCsvControl(rData)
75  , mpTableBox(pTableBox)
76  , mpBackgrDev( VclPtr<VirtualDevice>::Create() )
77  , mpGridDev( VclPtr<VirtualDevice>::Create() )
78  , mxPopup(std::move(xPopup))
79  , mpColorConfig( nullptr )
80  , mpEditEngine( new ScEditEngineDefaulter( EditEngine::CreatePool().get(), true ) )
81  , maColStates( 1 )
82  , maTypeNames( 1 )
83  , mnFirstImpLine( 0 )
84  , mnRecentSelCol( CSV_COLUMN_INVALID )
85  , mnMTCurrCol( SAL_MAX_UINT32 )
86  , mbTracking( false )
87  , mbMTSelecting( false )
88 {
89  mpEditEngine->SetRefDevice( mpBackgrDev.get() );
90  mpEditEngine->SetRefMapMode( MapMode( MapUnit::MapPixel ) );
91  maEdEngSize = mpEditEngine->GetPaperSize();
92 }
93 
95 {
96  OutputDevice& rRefDevice = pDrawingArea->get_ref_device();
98 
99  // expand the point size of the desired font to the equivalent pixel size
100  weld::SetPointFont(rRefDevice, maHeaderFont);
101  maHeaderFont = rRefDevice.GetFont();
102 
103  // Because this is an always LeftToRight layout widget the initial size of
104  // this widget needs to be smaller than the size of the parent scrolling
105  // window (ScCsvTableBox ctor) because in RTL mode the alignment is against
106  // the right edge of the parent, and if larger than the scrolling window
107  // the left edge will be lost. If this widget is smaller than the scrolling
108  // window it is stretched to fit the parent and the problem doesn't arise.
109  Size aInitialSize(10, 10);
110  ScCsvControl::SetDrawingArea(pDrawingArea);
111  pDrawingArea->set_size_request(aInitialSize.Width(), aInitialSize.Height());
112  SetOutputSizePixel(aInitialSize);
113 
114  EnableRTL( false ); // RTL
115 
116  InitFonts();
117  ImplClearSplits();
118 }
119 
121 {
122  OSL_ENSURE(mpColorConfig, "the object hasn't been initialized properly");
123  if (mpColorConfig)
124  mpColorConfig->RemoveListener(this);
127 }
128 
129 void
131 {
132  OSL_PRECOND(!mpColorConfig, "the object has already been initialized");
133  mpColorConfig = &SC_MOD()->GetColorConfig();
134  InitColors();
135  mpColorConfig->AddListener(this);
136 }
137 
138 // common grid handling -------------------------------------------------------
139 
141 {
142  DisableRepaint();
143  OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
144  rRefDevice.SetFont(maMonoFont);
145  Execute(CSVCMD_SETCHARWIDTH, rRefDevice.GetTextWidth(OUString('X')));
146  Execute(CSVCMD_SETLINEHEIGHT, rRefDevice.GetTextHeight() + 1);
147  rRefDevice.SetFont(maHeaderFont);
148  Execute(CSVCMD_SETHDRHEIGHT, rRefDevice.GetTextHeight() + 1);
149  UpdateOffsetX();
150  EnableRepaint();
151 }
152 
154 {
155  sal_Int32 nLastLine = GetLastVisLine() + 1;
156  sal_Int32 nDigits = 2;
157  for (;;)
158  {
159  nLastLine /= 10;
160  if (!nLastLine)
161  break;
162  ++nDigits;
163  }
164  nDigits = std::max( nDigits, sal_Int32( 3 ) );
165  Execute(CSVCMD_SETHDRWIDTH, GetDrawingArea()->get_approximate_digit_width() * nDigits);
166 }
167 
169 {
170  ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData );
171  if( nDiff == ScCsvDiff::Equal ) return;
172 
173  DisableRepaint();
174 
175  if( nDiff & ScCsvDiff::RulerCursor )
176  {
177  ImplInvertCursor( rOldData.mnPosCursor );
179  }
180 
181  if( nDiff & ScCsvDiff::PosCount )
182  {
183  if( GetPosCount() < rOldData.mnPosCount )
184  {
185  SelectAll( false );
187  }
188  else
189  maSplits.Remove( rOldData.mnPosCount );
191  maColStates.resize( maSplits.Count() - 1 );
192  }
193 
194  if( nDiff & ScCsvDiff::LineOffset )
195  {
197  UpdateOffsetX();
198  }
199 
201  if( nHVDiff == ScCsvDiff::PosOffset )
202  ImplDrawHorzScrolled( rOldData.mnPosOffset );
203  else if( nHVDiff != ScCsvDiff::Equal )
204  InvalidateGfx();
205 
206  EnableRepaint();
207 
208  if( nDiff & (ScCsvDiff::PosOffset | ScCsvDiff::LineOffset) )
210 }
211 
212 void ScCsvGrid::SetFirstImportedLine( sal_Int32 nLine )
213 {
214  ImplDrawFirstLineSep( false );
215  mnFirstImpLine = nLine;
216  ImplDrawFirstLineSep( true );
217  ImplDrawGridDev();
218  Repaint();
219 }
220 
221 sal_Int32 ScCsvGrid::GetNoScrollCol( sal_Int32 nPos ) const
222 {
223  sal_Int32 nNewPos = nPos;
224  if( nNewPos != CSV_POS_INVALID )
225  {
226  if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST )
227  {
228  sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0;
229  nNewPos = GetFirstVisPos() + nScroll;
230  }
231  else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1 )
232  {
233  sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0;
234  nNewPos = GetLastVisPos() - nScroll - 1;
235  }
236  }
237  return nNewPos;
238 }
239 
241 {
242  OSL_PRECOND(mpColorConfig, "the object hasn't been initialized properly");
243  if ( !mpColorConfig )
244  return;
250 
255  maSelectColor = rSett.GetActiveColor();
256 
257  InvalidateGfx();
258 }
259 
261 {
262  maMonoFont = OutputDevice::GetDefaultFont( DefaultFontType::FIXED, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::NONE );
264 
265  /* *** Set edit engine defaults ***
266  maMonoFont for Latin script, smaller default font for Asian and Complex script. */
267 
268  // get default fonts
269  SvxFontItem aLatinItem( EE_CHAR_FONTINFO );
270  SvxFontItem aAsianItem( EE_CHAR_FONTINFO_CJK );
271  SvxFontItem aComplexItem( EE_CHAR_FONTINFO_CTL );
272  ::GetDefaultFonts( aLatinItem, aAsianItem, aComplexItem );
273 
274  // create item set for defaults
275  SfxItemSet aDefSet( mpEditEngine->GetEmptyItemSet() );
277  aDefSet.Put( aAsianItem );
278  aDefSet.Put( aComplexItem );
279 
280  // set Asian/Complex font size to height of character in Latin font
281  sal_uLong nFontHt = static_cast< sal_uLong >( maMonoFont.GetFontSize().Height() );
282  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
283  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
284 
285  // copy other items from default font
286  const SfxPoolItem& rWeightItem = aDefSet.Get( EE_CHAR_WEIGHT );
287  std::unique_ptr<SfxPoolItem> pNewItem(rWeightItem.Clone());
288  pNewItem->SetWhich(EE_CHAR_WEIGHT_CJK);
289  aDefSet.Put( *pNewItem );
290  pNewItem->SetWhich(EE_CHAR_WEIGHT_CTL);
291  aDefSet.Put( *pNewItem );
292  const SfxPoolItem& rItalicItem = aDefSet.Get( EE_CHAR_ITALIC );
293  pNewItem.reset(rItalicItem.Clone());
294  pNewItem->SetWhich(EE_CHAR_ITALIC_CJK);
295  aDefSet.Put( *pNewItem );
296  pNewItem->SetWhich(EE_CHAR_ITALIC_CTL);
297  aDefSet.Put( *pNewItem );
298  const SfxPoolItem& rLangItem = aDefSet.Get( EE_CHAR_LANGUAGE );
299  pNewItem.reset(rLangItem.Clone());
300  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CJK);
301  aDefSet.Put( *pNewItem );
302  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CTL);
303  aDefSet.Put( *pNewItem );
304 
305  mpEditEngine->SetDefaults( aDefSet );
306  InvalidateGfx();
307 }
308 
310 {
314  InvalidateGfx();
315 }
316 
317 // split handling -------------------------------------------------------------
318 
319 void ScCsvGrid::InsertSplit( sal_Int32 nPos )
320 {
321  if( ImplInsertSplit( nPos ) )
322  {
323  DisableRepaint();
326  sal_uInt32 nColIx = GetColumnFromPos( nPos );
327  ImplDrawColumn( nColIx - 1 );
328  ImplDrawColumn( nColIx );
329  ValidateGfx(); // performance: do not redraw all columns
330  EnableRepaint();
331  }
332 }
333 
334 void ScCsvGrid::RemoveSplit( sal_Int32 nPos )
335 {
336  if( ImplRemoveSplit( nPos ) )
337  {
338  DisableRepaint();
341  ImplDrawColumn( GetColumnFromPos( nPos ) );
342  ValidateGfx(); // performance: do not redraw all columns
343  EnableRepaint();
344  }
345 }
346 
347 void ScCsvGrid::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos )
348 {
349  sal_uInt32 nColIx = GetColumnFromPos( nPos );
350  if( nColIx == CSV_COLUMN_INVALID )
351  return;
352 
353  DisableRepaint();
354  if( (GetColumnPos( nColIx - 1 ) < nNewPos) && (nNewPos < GetColumnPos( nColIx + 1 )) )
355  {
356  // move a split in the range between 2 others -> keep selection state of both columns
357  maSplits.Remove( nPos );
358  maSplits.Insert( nNewPos );
360  ImplDrawColumn( nColIx - 1 );
361  ImplDrawColumn( nColIx );
362  ValidateGfx(); // performance: do not redraw all columns
363  AccSendTableUpdateEvent( nColIx - 1, nColIx );
364  }
365  else
366  {
367  ImplRemoveSplit( nPos );
368  ImplInsertSplit( nNewPos );
371  }
372  EnableRepaint();
373 }
374 
376 {
377  DisableRepaint();
378  ImplClearSplits();
381  EnableRepaint();
382 }
383 
384 void ScCsvGrid::SetSplits( const ScCsvSplits& rSplits )
385 {
386  DisableRepaint();
387  ImplClearSplits();
388  sal_uInt32 nCount = rSplits.Count();
389  for( sal_uInt32 nIx = 0; nIx < nCount; ++nIx )
390  maSplits.Insert( rSplits[ nIx ] );
391  maColStates.clear();
392  maColStates.resize( maSplits.Count() - 1 );
395  EnableRepaint();
396 }
397 
398 bool ScCsvGrid::ImplInsertSplit( sal_Int32 nPos )
399 {
400  sal_uInt32 nColIx = GetColumnFromPos( nPos );
401  bool bRet = (nColIx < GetColumnCount()) && maSplits.Insert( nPos );
402  if( bRet )
403  {
404  ScCsvColState aState( GetColumnType( nColIx ) );
405  aState.Select( IsSelected( nColIx ) && IsSelected( nColIx + 1 ) );
406  maColStates.insert( maColStates.begin() + nColIx + 1, aState );
407  AccSendInsertColumnEvent( nColIx + 1, nColIx + 1 );
408  AccSendTableUpdateEvent( nColIx, nColIx );
409  }
410  return bRet;
411 }
412 
413 bool ScCsvGrid::ImplRemoveSplit( sal_Int32 nPos )
414 {
415  bool bRet = maSplits.Remove( nPos );
416  if( bRet )
417  {
418  sal_uInt32 nColIx = GetColumnFromPos( nPos );
419  bool bSel = IsSelected( nColIx ) || IsSelected( nColIx + 1 );
420  maColStates.erase( maColStates.begin() + nColIx + 1 );
421  maColStates[ nColIx ].Select( bSel );
422  AccSendRemoveColumnEvent( nColIx + 1, nColIx + 1 );
423  AccSendTableUpdateEvent( nColIx, nColIx );
424  }
425  return bRet;
426 }
427 
429 {
430  sal_uInt32 nColumns = GetColumnCount();
431  maSplits.Clear();
432  maSplits.Insert( 0 );
434  maColStates.resize( 1 );
435  InvalidateGfx();
436  AccSendRemoveColumnEvent( 1, nColumns - 1 );
437 }
438 
439 // columns/column types -------------------------------------------------------
440 
442 {
443  return GetColumnFromPos( GetFirstVisPos() );
444 }
445 
446 sal_uInt32 ScCsvGrid::GetLastVisColumn() const
447 {
448  return GetColumnFromPos( std::min( GetLastVisPos(), GetPosCount() ) - 1 );
449 }
450 
451 bool ScCsvGrid::IsValidColumn( sal_uInt32 nColIndex ) const
452 {
453  return nColIndex < GetColumnCount();
454 }
455 
456 bool ScCsvGrid::IsVisibleColumn( sal_uInt32 nColIndex ) const
457 {
458  return IsValidColumn( nColIndex ) &&
459  (GetColumnPos( nColIndex ) < GetLastVisPos()) &&
460  (GetFirstVisPos() < GetColumnPos( nColIndex + 1 ));
461 }
462 
463 sal_Int32 ScCsvGrid::GetColumnX( sal_uInt32 nColIndex ) const
464 {
465  return GetX( GetColumnPos( nColIndex ) );
466 }
467 
468 sal_uInt32 ScCsvGrid::GetColumnFromX( sal_Int32 nX ) const
469 {
470  sal_Int32 nPos = (nX - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
471  return ((GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos())) ?
473 }
474 
475 sal_uInt32 ScCsvGrid::GetColumnFromPos( sal_Int32 nPos ) const
476 {
477  return maSplits.UpperBound( nPos );
478 }
479 
480 sal_Int32 ScCsvGrid::GetColumnWidth( sal_uInt32 nColIndex ) const
481 {
482  return IsValidColumn( nColIndex ) ? (GetColumnPos( nColIndex + 1 ) - GetColumnPos( nColIndex )) : 0;
483 }
484 
486 {
487  maColStates = rStates;
488  maColStates.resize( maSplits.Count() - 1 );
492 }
493 
494 sal_Int32 ScCsvGrid::GetColumnType( sal_uInt32 nColIndex ) const
495 {
496  return IsValidColumn( nColIndex ) ? maColStates[ nColIndex ].mnType : CSV_TYPE_NOSELECTION;
497 }
498 
499 void ScCsvGrid::SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType )
500 {
501  if( IsValidColumn( nColIndex ) )
502  {
503  maColStates[ nColIndex ].mnType = nColType;
504  AccSendTableUpdateEvent( nColIndex, nColIndex, false );
505  }
506 }
507 
509 {
510  sal_uInt32 nColIx = GetFirstSelected();
511  if( nColIx == CSV_COLUMN_INVALID )
512  return CSV_TYPE_NOSELECTION;
513 
514  sal_Int32 nType = GetColumnType( nColIx );
515  while( (nColIx != CSV_COLUMN_INVALID) && (nType != CSV_TYPE_MULTI) )
516  {
517  if( nType != GetColumnType( nColIx ) )
518  nType = CSV_TYPE_MULTI;
519  nColIx = GetNextSelected( nColIx );
520  }
521  return nType;
522 }
523 
525 {
526  if( (nType != CSV_TYPE_MULTI) && (nType != CSV_TYPE_NOSELECTION) )
527  {
528  for( sal_uInt32 nColIx = GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = GetNextSelected( nColIx ) )
529  SetColumnType( nColIx, nType );
530  Repaint( true );
532  }
533 }
534 
535 void ScCsvGrid::SetTypeNames( const std::vector<OUString>& rTypeNames )
536 {
537  OSL_ENSURE( !rTypeNames.empty(), "ScCsvGrid::SetTypeNames - vector is empty" );
538  maTypeNames = rTypeNames;
539  Repaint( true );
540 
541  mxPopup->clear();
542  sal_uInt32 nCount = maTypeNames.size();
543  for (sal_uInt32 nIx = 0; nIx < nCount; ++nIx)
544  mxPopup->append(OUString::number(nIx), maTypeNames[nIx]);
545 
546  ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) );
547 }
548 
549 const OUString& ScCsvGrid::GetColumnTypeName( sal_uInt32 nColIndex ) const
550 {
551  sal_uInt32 nTypeIx = static_cast< sal_uInt32 >( GetColumnType( nColIndex ) );
552  return (nTypeIx < maTypeNames.size()) ? maTypeNames[ nTypeIx ] : EMPTY_OUSTRING;
553 }
554 
555 static sal_uInt8 lcl_GetExtColumnType( sal_Int32 nIntType )
556 {
557  static const sal_uInt8 pExtTypes[] =
559  static const sal_Int32 nExtTypeCount = SAL_N_ELEMENTS(pExtTypes);
560  return pExtTypes[ ((0 <= nIntType) && (nIntType < nExtTypeCount)) ? nIntType : 0 ];
561 }
562 
564 {
565  sal_uInt32 nCount = GetColumnCount();
566  ScCsvExpDataVec aDataVec;
567 
568  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
569  {
570  if( GetColumnType( nColIx ) != CSV_TYPE_DEFAULT )
571  // 1-based column index
572  aDataVec.emplace_back(
573  static_cast< sal_Int32 >( nColIx + 1 ),
574  lcl_GetExtColumnType( GetColumnType( nColIx ) ) );
575  }
576  rOptions.SetColumnInfo( aDataVec );
577 }
578 
580 {
581  sal_uInt32 nCount = std::min( GetColumnCount(), static_cast<sal_uInt32>(MAXCOLCOUNT) );
582  ScCsvExpDataVec aDataVec( nCount + 1 );
583 
584  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
585  {
586  ScCsvExpData& rData = aDataVec[ nColIx ];
587  rData.mnIndex = GetColumnPos( nColIx );
588  rData.mnType = lcl_GetExtColumnType( GetColumnType( nColIx ) );
589  }
590  aDataVec[ nCount ].mnIndex = SAL_MAX_INT32;
591  aDataVec[ nCount ].mnType = SC_COL_SKIP;
592  rOptions.SetColumnInfo( aDataVec );
593 }
594 
596 {
597  sal_Int32 nLine = GetFirstVisLine();
598  switch( eDir )
599  {
600  case MOVE_PREV: --nLine; break;
601  case MOVE_NEXT: ++nLine; break;
602  case MOVE_FIRST: nLine = 0; break;
603  case MOVE_LAST: nLine = GetMaxLineOffset(); break;
604  case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 2; break;
605  case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 2; break;
606  default:
607  {
608  // added to avoid warnings
609  }
610  }
611  Execute( CSVCMD_SETLINEOFFSET, nLine );
612 }
613 
614 void ScCsvGrid::ExecutePopup( const Point& rPos )
615 {
616  OString sItemId = mxPopup->popup_at_rect(GetDrawingArea(), tools::Rectangle(rPos, Size(1, 1)));
617  if (!sItemId.isEmpty()) // empty = cancelled
618  Execute(CSVCMD_SETCOLUMNTYPE, sItemId.toInt32());
619 }
620 
621 // selection handling ---------------------------------------------------------
622 
623 bool ScCsvGrid::IsSelected( sal_uInt32 nColIndex ) const
624 {
625  return IsValidColumn( nColIndex ) && maColStates[ nColIndex ].IsSelected();
626 }
627 
628 sal_uInt32 ScCsvGrid::GetFirstSelected() const
629 {
630  return IsSelected( 0 ) ? 0 : GetNextSelected( 0 );
631 }
632 
633 sal_uInt32 ScCsvGrid::GetNextSelected( sal_uInt32 nFromIndex ) const
634 {
635  sal_uInt32 nColCount = GetColumnCount();
636  for( sal_uInt32 nColIx = nFromIndex + 1; nColIx < nColCount; ++nColIx )
637  if( IsSelected( nColIx ) )
638  return nColIx;
639  return CSV_COLUMN_INVALID;
640 }
641 
642 void ScCsvGrid::Select( sal_uInt32 nColIndex, bool bSelect )
643 {
644  if( IsValidColumn( nColIndex ) )
645  {
646  maColStates[ nColIndex ].Select( bSelect );
647  ImplDrawColumnSelection( nColIndex );
648  Repaint();
650  if( bSelect )
651  mnRecentSelCol = nColIndex;
653  }
654 }
655 
656 void ScCsvGrid::ToggleSelect( sal_uInt32 nColIndex )
657 {
658  Select( nColIndex, !IsSelected( nColIndex ) );
659 }
660 
661 void ScCsvGrid::SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect )
662 {
663  if( nColIndex1 == CSV_COLUMN_INVALID )
664  Select( nColIndex2 );
665  else if( nColIndex2 == CSV_COLUMN_INVALID )
666  Select( nColIndex1 );
667  else if( nColIndex1 > nColIndex2 )
668  {
669  SelectRange( nColIndex2, nColIndex1, bSelect );
670  if( bSelect )
671  mnRecentSelCol = nColIndex1;
672  }
673  else if( IsValidColumn( nColIndex1 ) && IsValidColumn( nColIndex2 ) )
674  {
675  for( sal_uInt32 nColIx = nColIndex1; nColIx <= nColIndex2; ++nColIx )
676  {
677  maColStates[ nColIx ].Select( bSelect );
678  ImplDrawColumnSelection( nColIx );
679  }
680  Repaint();
682  if( bSelect )
683  mnRecentSelCol = nColIndex1;
685  }
686 }
687 
688 void ScCsvGrid::SelectAll( bool bSelect )
689 {
690  SelectRange( 0, GetColumnCount() - 1, bSelect );
691 }
692 
693 void ScCsvGrid::MoveCursor( sal_uInt32 nColIndex )
694 {
695  DisableRepaint();
696  if( IsValidColumn( nColIndex ) )
697  {
698  sal_Int32 nPosBeg = GetColumnPos( nColIndex );
699  sal_Int32 nPosEnd = GetColumnPos( nColIndex + 1 );
700  sal_Int32 nMinPos = std::max( nPosBeg - CSV_SCROLL_DIST, sal_Int32( 0 ) );
701  sal_Int32 nMaxPos = std::min( nPosEnd - GetVisPosCount() + CSV_SCROLL_DIST + sal_Int32( 1 ), nMinPos );
702  if( nPosBeg - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
703  Execute( CSVCMD_SETPOSOFFSET, nMinPos );
704  else if( nPosEnd + CSV_SCROLL_DIST >= GetLastVisPos() )
705  Execute( CSVCMD_SETPOSOFFSET, nMaxPos );
706  }
707  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
708  EnableRepaint();
709 }
710 
712 {
714  return;
715 
716  switch( eDir )
717  {
718  case MOVE_FIRST:
719  MoveCursor( 0 );
720  break;
721  case MOVE_LAST:
722  MoveCursor( GetColumnCount() - 1 );
723  break;
724  case MOVE_PREV:
725  if( GetFocusColumn() > 0 )
726  MoveCursor( GetFocusColumn() - 1 );
727  break;
728  case MOVE_NEXT:
729  if( GetFocusColumn() < GetColumnCount() - 1 )
730  MoveCursor( GetFocusColumn() + 1 );
731  break;
732  default:
733  {
734  // added to avoid warnings
735  }
736  }
737 }
738 
740 {
741  ::std::for_each( maColStates.begin(), maColStates.end(), Func_Select( false ) );
742  ImplDrawGridDev();
743 }
744 
745 void ScCsvGrid::DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier )
746 {
747  if( !(nModifier & KEY_MOD1) )
749  if( nModifier & KEY_SHIFT ) // SHIFT always expands
750  SelectRange( mnRecentSelCol, nColIndex );
751  else if( !(nModifier & KEY_MOD1) ) // no SHIFT/CTRL always selects 1 column
752  Select( nColIndex );
753  else if( mbTracking ) // CTRL in tracking does not toggle
754  Select( nColIndex, mbMTSelecting );
755  else // CTRL only toggles
756  ToggleSelect( nColIndex );
757  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
758 }
759 
760 // cell contents --------------------------------------------------------------
761 
763  sal_Int32 nLine, const OUString& rTextLine,
764  const OUString& rSepChars, sal_Unicode cTextSep, bool bMergeSep, bool bRemoveSpace )
765 {
766  if( nLine < GetFirstVisLine() ) return;
767 
768  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
769  while( maTexts.size() <= nLineIx )
770  maTexts.emplace_back( );
771  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
772  rStrVec.clear();
773 
774  // scan for separators
775  OUString aCellText;
776  const sal_Unicode* pSepChars = rSepChars.getStr();
777  const sal_Unicode* pChar = rTextLine.getStr();
778  sal_uInt32 nColIx = 0;
779 
780  while( *pChar && (nColIx < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT)) )
781  {
782  // scan for next cell text
783  bool bIsQuoted = false;
784  bool bOverflowCell = false;
785  pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText,
786  cTextSep, pSepChars, bMergeSep, bIsQuoted, bOverflowCell, bRemoveSpace );
787  /* TODO: signal overflow somewhere in UI */
788 
789  // update column width
790  sal_Int32 nWidth = std::max( CSV_MINCOLWIDTH, ScImportExport::CountVisualWidth( aCellText ) + 1 );
791  if( IsValidColumn( nColIx ) )
792  {
793  // expand existing column
794  sal_Int32 nDiff = nWidth - GetColumnWidth( nColIx );
795  if( nDiff > 0 )
796  {
797  Execute( CSVCMD_SETPOSCOUNT, GetPosCount() + nDiff );
798  for( sal_uInt32 nSplitIx = GetColumnCount() - 1; nSplitIx > nColIx; --nSplitIx )
799  {
800  sal_Int32 nPos = maSplits[ nSplitIx ];
801  maSplits.Remove( nPos );
802  maSplits.Insert( nPos + nDiff );
803  }
804  }
805  }
806  else
807  {
808  // append new column
809  sal_Int32 nLastPos = GetPosCount();
810  Execute( CSVCMD_SETPOSCOUNT, nLastPos + nWidth );
811  ImplInsertSplit( nLastPos );
812  }
813 
814  if( aCellText.getLength() <= CSV_MAXSTRLEN )
815  rStrVec.push_back( aCellText );
816  else
817  rStrVec.push_back( aCellText.copy( 0, CSV_MAXSTRLEN ) );
818  ++nColIx;
819  }
820  InvalidateGfx();
821 }
822 
823 void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine )
824 {
825  if( nLine < GetFirstVisLine() ) return;
826 
827  sal_Int32 nWidth = ScImportExport::CountVisualWidth( rTextLine );
828  if( nWidth > GetPosCount() )
829  Execute( CSVCMD_SETPOSCOUNT, nWidth );
830 
831  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
832  while( maTexts.size() <= nLineIx )
833  maTexts.emplace_back( );
834 
835  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
836  rStrVec.clear();
837  sal_uInt32 nColCount = GetColumnCount();
838  sal_Int32 nStrLen = rTextLine.getLength();
839  sal_Int32 nStrIx = 0;
840  for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx )
841  {
842  sal_Int32 nColWidth = GetColumnWidth( nColIx );
843  sal_Int32 nLastIx = nStrIx;
844  ScImportExport::CountVisualWidth( rTextLine, nLastIx, nColWidth );
845  sal_Int32 nLen = std::min( CSV_MAXSTRLEN, nLastIx - nStrIx );
846  rStrVec.push_back( rTextLine.copy( nStrIx, nLen ) );
847  nStrIx = nStrIx + nLen;
848  }
849  InvalidateGfx();
850 }
851 
852 const OUString& ScCsvGrid::GetCellText( sal_uInt32 nColIndex, sal_Int32 nLine ) const
853 {
854  if( nLine < GetFirstVisLine() ) return EMPTY_OUSTRING;
855 
856  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
857  if( nLineIx >= maTexts.size() ) return EMPTY_OUSTRING;
858 
859  const std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
860  if( nColIndex >= rStrVec.size() ) return EMPTY_OUSTRING;
861 
862  return rStrVec[ nColIndex ];
863 }
864 
865 // event handling -------------------------------------------------------------
866 
868 {
870 
872  InitSizeData();
874 }
875 
877 {
880  Repaint();
881 }
882 
884 {
886  Repaint();
887 }
888 
890 {
891  DisableRepaint();
892  if( !HasFocus() )
893  GrabFocus();
894 
895  Point aPos( rMEvt.GetPosPixel() );
896  sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
897 
898  if( rMEvt.IsLeft() )
899  {
900  if( (GetFirstX() > aPos.X()) || (aPos.X() > GetLastX()) ) // in header column
901  {
902  if( aPos.Y() <= GetHdrHeight() )
903  SelectAll();
904  }
905  else if( IsValidColumn( nColIx ) )
906  {
907  DoSelectAction( nColIx, rMEvt.GetModifier() );
908  mnMTCurrCol = nColIx;
909  mbMTSelecting = IsSelected( nColIx );
910  mbTracking = true;
911  }
912  }
913  EnableRepaint();
914  return true;
915 }
916 
918 {
919  mbTracking = false;
920  return true;
921 }
922 
923 bool ScCsvGrid::MouseMove( const MouseEvent& rMEvt )
924 {
925  if (!mbTracking)
926  return true;
927 
928  DisableRepaint();
929 
930  sal_Int32 nPos = (rMEvt.GetPosPixel().X() - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
931  // on mouse tracking: keep position valid
932  nPos = std::clamp( nPos, sal_Int32(0), GetPosCount() - 1 );
934 
935  sal_uInt32 nColIx = GetColumnFromPos( nPos );
936  if( mnMTCurrCol != nColIx )
937  {
938  DoSelectAction( nColIx, rMEvt.GetModifier() );
939  mnMTCurrCol = nColIx;
940  }
941  EnableRepaint();
942 
943  return true;
944 }
945 
946 bool ScCsvGrid::KeyInput( const KeyEvent& rKEvt )
947 {
948  const vcl::KeyCode& rKCode = rKEvt.GetKeyCode();
949  sal_uInt16 nCode = rKCode.GetCode();
950  bool bShift = rKCode.IsShift();
951  bool bMod1 = rKCode.IsMod1();
952 
953  if( !rKCode.IsMod2() )
954  {
955  ScMoveMode eHDir = GetHorzDirection( nCode, !bMod1 );
956  ScMoveMode eVDir = GetVertDirection( nCode, bMod1 );
957 
958  if( eHDir != MOVE_NONE )
959  {
960  DisableRepaint();
961  MoveCursorRel( eHDir );
962  if( !bMod1 )
964  if( bShift )
966  else if( !bMod1 )
967  Select( GetFocusColumn() );
968  EnableRepaint();
969  }
970  else if( eVDir != MOVE_NONE )
971  ScrollVertRel( eVDir );
972  else if( nCode == KEY_SPACE )
973  {
974  if( !bMod1 )
976  if( bShift )
978  else if( bMod1 )
980  else
981  Select( GetFocusColumn() );
982  }
983  else if( !bShift && bMod1 )
984  {
985  if( nCode == KEY_A )
986  SelectAll();
987  else if( (KEY_1 <= nCode) && (nCode <= KEY_9) )
988  {
989  sal_uInt32 nType = nCode - KEY_1;
990  if( nType < maTypeNames.size() )
991  Execute( CSVCMD_SETCOLUMNTYPE, nType );
992  }
993  }
994  }
995 
996  return rKCode.GetGroup() == KEYGROUP_CURSOR;
997 }
998 
999 bool ScCsvGrid::Command( const CommandEvent& rCEvt )
1000 {
1001  bool bConsumed = true;
1002  switch( rCEvt.GetCommand() )
1003  {
1004  case CommandEventId::ContextMenu:
1005  {
1006  if( rCEvt.IsMouseEvent() )
1007  {
1008  Point aPos( rCEvt.GetMousePosPixel() );
1009  sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
1010  if( IsValidColumn( nColIx ) && (GetFirstX() <= aPos.X()) && (aPos.X() <= GetLastX()) )
1011  {
1012  if( !IsSelected( nColIx ) )
1013  DoSelectAction( nColIx, 0 ); // focus & select
1014  ExecutePopup( aPos );
1015  }
1016  }
1017  else
1018  {
1019  sal_uInt32 nColIx = GetFocusColumn();
1020  if( !IsSelected( nColIx ) )
1021  Select( nColIx );
1022  sal_Int32 nX1 = std::max( GetColumnX( nColIx ), GetFirstX() );
1023  sal_Int32 nX2 = std::min( GetColumnX( nColIx + 1 ), GetWidth() );
1024  ExecutePopup( Point( (nX1 + nX2) / 2, GetHeight() / 2 ) );
1025  }
1026  break;
1027  }
1028  case CommandEventId::Wheel:
1029  {
1030  tools::Rectangle aRect( Point(), maWinSize );
1031  if( aRect.IsInside( rCEvt.GetMousePosPixel() ) )
1032  {
1033  const CommandWheelData* pData = rCEvt.GetWheelData();
1034  if( pData && (pData->GetMode() == CommandWheelMode::SCROLL) && !pData->IsHorz() )
1036  }
1037  break;
1038  }
1039  default:
1040  bConsumed = false;
1041  break;
1042  }
1043  return bConsumed;
1044 }
1045 
1047 {
1048  InitColors();
1049  InitFonts();
1050  UpdateLayoutData();
1052 
1054 }
1055 
1057 {
1058  InitColors();
1059  Repaint();
1060 }
1061 
1062 // painting -------------------------------------------------------------------
1063 
1065 {
1066  ImplRedraw(rRenderContext);
1067 }
1068 
1070 {
1071  if( IsVisible() )
1072  {
1073  if( !IsValidGfx() )
1074  {
1075  ValidateGfx();
1077  ImplDrawGridDev();
1078  }
1079  rRenderContext.DrawOutDev( Point(), maWinSize, Point(), maWinSize, *mpGridDev );
1080  }
1081 }
1082 
1084 {
1085  return mpEditEngine.get();
1086 }
1087 
1088 void ScCsvGrid::ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex )
1089 {
1091  std::max( GetColumnX( nColIndex ), GetFirstX() ) + 1, 0,
1092  std::min( GetColumnX( nColIndex + 1 ), GetLastX() ), GetHeight() - 1 ) ) );
1093 }
1094 
1095 void ScCsvGrid::ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor )
1096 {
1097  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1098  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1099  sal_Int32 nHdrHt = GetHdrHeight();
1100 
1101  rOutDev.SetLineColor();
1102  rOutDev.SetFillColor( aFillColor );
1103  rOutDev.DrawRect( tools::Rectangle( nX1, 0, nX2, nHdrHt ) );
1104 
1105  rOutDev.SetFont( maHeaderFont );
1106  rOutDev.SetTextColor( maHeaderTextColor );
1107  rOutDev.SetTextFillColor();
1108  rOutDev.DrawText( Point( nX1 + 1, 0 ), GetColumnTypeName( nColIndex ) );
1109 
1110  rOutDev.SetLineColor( maHeaderGridColor );
1111  rOutDev.DrawLine( Point( nX1, nHdrHt ), Point( nX2, nHdrHt ) );
1112  rOutDev.DrawLine( Point( nX2, 0 ), Point( nX2, nHdrHt ) );
1113 }
1114 
1115 void ScCsvGrid::ImplDrawCellText( const Point& rPos, const OUString& rText )
1116 {
1117  OUString aPlainText = rText.replaceAll( "\t", " " );
1118  aPlainText = aPlainText.replaceAll( "\n", " " );
1119  mpEditEngine->SetPaperSize( maEdEngSize );
1120 
1121  /* #i60296# If string contains mixed script types, the space character
1122  U+0020 may be drawn with a wrong width (from non-fixed-width Asian or
1123  Complex font). Now we draw every non-space portion separately. */
1124  sal_Int32 nCharIxInt {aPlainText.isEmpty() ? -1 : 0};
1125  while (nCharIxInt>=0)
1126  {
1127  sal_Int32 nBeginIx = nCharIxInt;
1128  const OUString aToken = aPlainText.getToken( 0, ' ', nCharIxInt );
1129  if( !aToken.isEmpty() )
1130  {
1131  sal_Int32 nX = rPos.X() + GetCharWidth() * nBeginIx;
1132  mpEditEngine->SetTextCurrentDefaults( aToken );
1133  mpEditEngine->Draw(*mpBackgrDev, Point(nX, rPos.Y()));
1134  }
1135  }
1136 
1137  sal_Int32 nCharIx = 0;
1138  while( (nCharIx = rText.indexOf( '\t', nCharIx )) != -1 )
1139  {
1140  sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
1141  sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
1142  sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
1143  Color aColor( maTextColor );
1144  mpBackgrDev->SetLineColor( aColor );
1145  mpBackgrDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
1146  mpBackgrDev->DrawLine( Point( nX2 - 2, nY - 2 ), Point( nX2, nY ) );
1147  mpBackgrDev->DrawLine( Point( nX2 - 2, nY + 2 ), Point( nX2, nY ) );
1148  ++nCharIx;
1149  }
1150  nCharIx = 0;
1151  while( (nCharIx = rText.indexOf( '\n', nCharIx )) != -1 )
1152  {
1153  sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
1154  sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
1155  sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
1156  Color aColor( maTextColor );
1157  mpBackgrDev->SetLineColor( aColor );
1158  mpBackgrDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
1159  mpBackgrDev->DrawLine( Point( nX1 + 2, nY - 2 ), Point( nX1, nY ) );
1160  mpBackgrDev->DrawLine( Point( nX1 + 2, nY + 2 ), Point( nX1, nY ) );
1161  mpBackgrDev->DrawLine( Point( nX2, nY - 2 ), Point( nX2, nY ) );
1162  ++nCharIx;
1163  }
1164 }
1165 
1167 {
1169  {
1170  sal_Int32 nY = GetY( mnFirstImpLine );
1171  sal_Int32 nX = std::min( GetColumnX( GetLastVisColumn() + 1 ), GetLastX() );
1173  mpBackgrDev->DrawLine( Point( GetFirstX() + 1, nY ), Point( nX, nY ) );
1174  }
1175 }
1176 
1177 void ScCsvGrid::ImplDrawColumnBackgr( sal_uInt32 nColIndex )
1178 {
1179  if( !IsVisibleColumn( nColIndex ) )
1180  return;
1181 
1182  ImplSetColumnClipRegion( *mpBackgrDev, nColIndex );
1183 
1184  // grid
1187  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1188  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1189  sal_Int32 nY2 = GetY( GetLastVisLine() + 1 );
1190  sal_Int32 nHdrHt = GetHdrHeight();
1191  tools::Rectangle aRect( nX1, nHdrHt, nX2, nY2 );
1192  mpBackgrDev->DrawRect( aRect );
1194  mpBackgrDev->DrawGrid( aRect, Size( 1, GetLineHeight() ), DrawGridFlags::HorzLines );
1195  mpBackgrDev->DrawLine( Point( nX2, nHdrHt ), Point( nX2, nY2 ) );
1196  ImplDrawFirstLineSep( true );
1197 
1198  // cell texts
1199  mpEditEngine->SetDefaultItem( SvxColorItem( maTextColor, EE_CHAR_COLOR ) );
1200  size_t nLineCount = ::std::min( static_cast< size_t >( GetLastVisLine() - GetFirstVisLine() + 1 ), maTexts.size() );
1201  // #i67432# cut string to avoid edit engine performance problems with very large strings
1202  sal_Int32 nFirstVisPos = ::std::max( GetColumnPos( nColIndex ), GetFirstVisPos() );
1203  sal_Int32 nLastVisPos = ::std::min( GetColumnPos( nColIndex + 1 ), GetLastVisPos() );
1204  sal_Int32 nStrPos = nFirstVisPos - GetColumnPos( nColIndex );
1205  sal_Int32 nStrLen = nLastVisPos - nFirstVisPos + 1;
1206  sal_Int32 nStrX = GetX( nFirstVisPos );
1207  for( size_t nLine = 0; nLine < nLineCount; ++nLine )
1208  {
1209  std::vector<OUString>& rStrVec = maTexts[ nLine ];
1210  if( (nColIndex < rStrVec.size()) && (rStrVec[ nColIndex ].getLength() > nStrPos) )
1211  {
1212  const OUString& rStr = rStrVec[ nColIndex ];
1213  OUString aText = rStr.copy( nStrPos, ::std::min( nStrLen, rStr.getLength() - nStrPos) );
1214  ImplDrawCellText( Point( nStrX, GetY( GetFirstVisLine() + nLine ) ), aText );
1215  }
1216  }
1217 
1218  // header
1220 
1222 }
1223 
1225 {
1228  Point aPoint( GetHdrX(), 0 );
1229  tools::Rectangle aRect( aPoint, Size( GetHdrWidth() + 1, GetHeight() ) );
1230  mpBackgrDev->DrawRect( aRect );
1231 
1233  aRect.SetBottom( GetY( GetLastVisLine() + 1 ) );
1234  mpBackgrDev->DrawRect( aRect );
1235 
1236  // line numbers
1240  sal_Int32 nLastLine = GetLastVisLine();
1241  for( sal_Int32 nLine = GetFirstVisLine(); nLine <= nLastLine; ++nLine )
1242  {
1243  OUString aText( OUString::number( nLine + 1 ) );
1244  sal_Int32 nX = GetHdrX() + (GetHdrWidth() - mpBackgrDev->GetTextWidth( aText )) / 2;
1245  mpBackgrDev->DrawText( Point( nX, GetY( nLine ) ), aText );
1246  }
1247 
1248  // grid
1250  if( IsRTL() )
1251  {
1252  mpBackgrDev->DrawLine( Point( 0, 0 ), Point( 0, GetHeight() - 1 ) );
1253  mpBackgrDev->DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
1254  }
1255  else
1256  mpBackgrDev->DrawLine( aRect.TopRight(), aRect.BottomRight() );
1257  aRect.SetTop( GetHdrHeight() );
1258  mpBackgrDev->DrawGrid( aRect, Size( 1, GetLineHeight() ), DrawGridFlags::HorzLines );
1259 }
1260 
1262 {
1266  Point( GetFirstX() + 1, 0 ), Size( GetWidth() - GetHdrWidth(), GetHeight() ) ) );
1267 
1268  sal_uInt32 nLastCol = GetLastVisColumn();
1269  if (nLastCol == CSV_COLUMN_INVALID)
1270  return;
1271  for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
1272  ImplDrawColumnBackgr( nColIx );
1273 
1275 }
1276 
1277 void ScCsvGrid::ImplDrawColumnSelection( sal_uInt32 nColIndex )
1278 {
1280  ImplSetColumnClipRegion( *mpGridDev, nColIndex );
1282 
1283  if( IsSelected( nColIndex ) )
1284  {
1285  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1286  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1287 
1288  // header
1289  tools::Rectangle aRect( nX1, 0, nX2, GetHdrHeight() );
1291  if( maHeaderBackColor.IsDark() )
1292  // redraw with light gray background in dark mode
1294  else
1295  {
1296  // use transparent active color
1299  }
1300 
1301  // column selection
1302  aRect = tools::Rectangle( nX1, GetHdrHeight() + 1, nX2, GetY( GetLastVisLine() + 1 ) - 1 );
1303  ImplInvertRect( *mpGridDev, aRect );
1304  }
1305 
1308 }
1309 
1311 {
1313  sal_uInt32 nLastCol = GetLastVisColumn();
1314  if (nLastCol == CSV_COLUMN_INVALID)
1315  return;
1316  for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
1317  ImplDrawColumnSelection( nColIx );
1318 }
1319 
1320 void ScCsvGrid::ImplDrawColumn( sal_uInt32 nColIndex )
1321 {
1322  ImplDrawColumnBackgr( nColIndex );
1323  ImplDrawColumnSelection( nColIndex );
1324 }
1325 
1326 void ScCsvGrid::ImplDrawHorzScrolled( sal_Int32 nOldPos )
1327 {
1328  sal_Int32 nPos = GetFirstVisPos();
1329  if( !IsValidGfx() || (nPos == nOldPos) )
1330  return;
1331  if( std::abs( nPos - nOldPos ) > GetVisPosCount() / 2 )
1332  {
1334  ImplDrawGridDev();
1335  return;
1336  }
1337 
1338  Point aSrc, aDest;
1339  sal_uInt32 nFirstColIx, nLastColIx;
1340  if( nPos < nOldPos )
1341  {
1342  aSrc = Point( GetFirstX() + 1, 0 );
1343  aDest = Point( GetFirstX() + GetCharWidth() * (nOldPos - nPos) + 1, 0 );
1344  nFirstColIx = GetColumnFromPos( nPos );
1345  nLastColIx = GetColumnFromPos( nOldPos );
1346  }
1347  else
1348  {
1349  aSrc = Point( GetFirstX() + GetCharWidth() * (nPos - nOldPos) + 1, 0 );
1350  aDest = Point( GetFirstX() + 1, 0 );
1351  nFirstColIx = GetColumnFromPos( std::min( nOldPos + GetVisPosCount(), GetPosCount() ) - 1 );
1352  nLastColIx = GetColumnFromPos( std::min( nPos + GetVisPosCount(), GetPosCount() ) - 1 );
1353  }
1354 
1355  ImplInvertCursor( GetRulerCursorPos() + (nPos - nOldPos) );
1356  tools::Rectangle aRectangle( GetFirstX(), 0, GetLastX(), GetHeight() - 1 );
1357  vcl::Region aClipReg( aRectangle );
1358  mpBackgrDev->SetClipRegion( aClipReg );
1359  mpBackgrDev->CopyArea( aDest, aSrc, maWinSize );
1361  mpGridDev->SetClipRegion( aClipReg );
1362  mpGridDev->CopyArea( aDest, aSrc, maWinSize );
1365 
1366  for( sal_uInt32 nColIx = nFirstColIx; nColIx <= nLastColIx; ++nColIx )
1367  ImplDrawColumn( nColIx );
1368 
1369  sal_Int32 nLastX = GetX( GetPosCount() ) + 1;
1370  if( nLastX <= GetLastX() )
1371  {
1372  tools::Rectangle aRect( nLastX, 0, GetLastX(), GetHeight() - 1 );
1375  mpBackgrDev->DrawRect( aRect );
1378  mpGridDev->DrawRect( aRect );
1379  }
1380 }
1381 
1382 void ScCsvGrid::ImplInvertCursor( sal_Int32 nPos )
1383 {
1384  if( IsVisibleSplitPos( nPos ) )
1385  {
1386  sal_Int32 nX = GetX( nPos ) - 1;
1387  tools::Rectangle aRect( Point( nX, 0 ), Size( 3, GetHdrHeight() ) );
1388  ImplInvertRect( *mpGridDev, aRect );
1389  aRect.SetTop( GetHdrHeight() + 1 );
1390  aRect.SetBottom( GetY( GetLastVisLine() + 1 ) );
1391  ImplInvertRect( *mpGridDev, aRect );
1392  }
1393 }
1394 
1396 {
1397  auto nColIndex = GetFocusColumn();
1398  if( HasFocus() && IsVisibleColumn( nColIndex ) )
1399  {
1400  sal_Int32 nX1 = std::max( GetColumnX( nColIndex ), GetFirstX() ) + 1;
1401  sal_Int32 nX2 = std::min( GetColumnX( nColIndex + 1 ) - sal_Int32( 1 ), GetLastX() );
1402  sal_Int32 nY2 = std::min( GetY( GetLastVisLine() + 1 ), GetHeight() ) - 1;
1403  return tools::Rectangle( nX1, 0, nX2, nY2 );
1404  }
1406 }
1407 
1408 // accessibility ==============================================================
1409 
1410 css::uno::Reference<css::accessibility::XAccessible> ScCsvGrid::CreateAccessible()
1411 {
1413  mxAccessible = xRef;
1414  return xRef;
1415 }
1416 
1417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCsvDiff GetDiff(const ScCsvLayoutData &rData) const
Returns differences to rData.
Definition: csvcontrol.cxx:43
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Color maGridPBColor
Table grid color.
Definition: csvgrid.hxx:68
static sal_uInt8 lcl_GetExtColumnType(sal_Int32 nIntType)
Definition: csvgrid.cxx:555
void SetClipRegion()
const Color & GetActiveColor() const
ConfigurationHints
vcl::Font maMonoFont
Font for column and row headers.
Definition: csvgrid.hxx:79
bool mbTracking
Current column of mouse tracking.
Definition: csvgrid.hxx:91
static void ImplInvertRect(OutputDevice &rOutDev, const tools::Rectangle &rRect)
Inverts a rectangle in the specified output device.
Definition: csvcontrol.cxx:242
sal_uInt32 UpperBound(sal_Int32 nPos) const
Returns index of the last split less than or equal to nPos.
Definition: csvsplits.cxx:82
Repaint all controls. [-].
Definition: csvcontrol.hxx:165
sal_Int32 mnPosOffset
Number of positions.
Definition: csvcontrol.hxx:115
void RemoveSplit(sal_Int32 nPos)
Removes a split.
Definition: csvgrid.cxx:334
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: csvgrid.cxx:889
virtual bool Command(const CommandEvent &rCEvt) override
Definition: csvgrid.cxx:999
void SetFontSize(const Size &)
SAL_DLLPRIVATE void ImplDrawGridDev()
Draws all columns with selection and cursor to maGridDev.
Definition: csvgrid.cxx:1310
ScCsvSplits maSplits
Paper size for edit engine.
Definition: csvgrid.hxx:83
SAL_DLLPRIVATE void ImplDrawCellText(const Point &rPos, const OUString &rText)
Draws the text at the specified position to maBackgrDev.
Definition: csvgrid.cxx:1115
::svtools::ColorConfig * mpColorConfig
Popup menu for column types.
Definition: csvgrid.hxx:65
void AccSendTableUpdateEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows=true)
Sends a table model changed event for changed cell contents to the accessibility object.
Definition: csvcontrol.cxx:110
const sal_uInt8 SC_COL_STANDARD
Definition: csvcontrol.hxx:54
Color maGridColor
Cell background color.
Definition: csvgrid.hxx:67
void EnableRepaint()
Decreases no-repaint counter and repaints if counter reaches 0.
Definition: csvcontrol.cxx:143
const sal_uInt8 SC_COL_TEXT
Definition: csvcontrol.hxx:55
sal_uInt32 GetFirstVisColumn() const
Returns the index of the first visible column.
Definition: csvgrid.cxx:441
constexpr sal_uInt16 KEY_MOD1
bool IsValidColumn(sal_uInt32 nColIndex) const
Returns true, if nColIndex points to an existing column.
Definition: csvgrid.cxx:451
#define EMPTY_OUSTRING
Definition: global.hxx:213
const sal_Int32 CSV_POS_INVALID
Constant for an invalid ruler position.
Definition: csvsplits.hxx:29
SAL_DLLPRIVATE sal_Int32 GetColumnType(sal_uInt32 nColIndex) const
Returns the data type of the specified column.
Definition: csvgrid.cxx:494
#define LANGUAGE_ENGLISH_US
sal_Int32 GetPosCount() const
Returns the number of available positions.
Definition: csvcontrol.hxx:300
void UpdateLayoutData()
Updates layout data dependent from the control's state.
Definition: csvgrid.cxx:140
const ScCsvLayoutData & GetLayoutData() const
Returns a reference to the current layout data.
Definition: csvcontrol.hxx:295
std::unique_ptr< ContentProperties > pData
sal_uInt8 mnType
Index of a column.
Definition: csvcontrol.hxx:66
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:76
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:349
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
sal_Int32 GetX(sal_Int32 nPos) const
Returns output X coordinate of the specified position.
Definition: csvcontrol.cxx:195
void AccSendVisibleEvent()
Sends a visible area changed event to the accessibility object.
Definition: csvcontrol.cxx:98
sal_uInt32 GetColumnFromPos(sal_Int32 nPos) const
Returns column index from position.
Definition: csvgrid.cxx:475
sal_uInt32 GetLastVisColumn() const
Returns the index of the last visible column.
Definition: csvgrid.cxx:446
sal_uIntPtr sal_uLong
Change position/column count. [character count].
Definition: csvcontrol.hxx:166
SAL_DLLPRIVATE void InitSizeData()
Initializes all data dependent from the control's size.
Definition: csvgrid.cxx:309
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
constexpr sal_uInt16 KEY_A
Update cell texts with current split settings. [-].
Definition: csvcontrol.hxx:184
const Color & GetFaceColor() const
static ScMoveMode GetHorzDirection(sal_uInt16 nCode, bool bHomeEnd)
Returns direction code for the keys LEFT, RIGHT, HOME, END.
Definition: csvcontrol.cxx:252
void SetColumnInfo(const ScCsvExpDataVec &rDataVec)
Definition: asciiopt.cxx:47
SAL_DLLPRIVATE void MoveCursorRel(ScMoveMode eDir)
Moves column cursor to the given direction.
Definition: csvgrid.cxx:711
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
Definition: csvgrid.cxx:1064
Accessible class representing the CSV grid control.
void ApplyLayout(const ScCsvLayoutData &rOldData)
Apply current layout data to the grid control.
Definition: csvgrid.cxx:168
void AccSendRemoveColumnEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn)
Sends a table model changed event for a removed column to the accessibility object.
Definition: csvcontrol.cxx:122
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
const ContentProperties & rData
sal_uInt16 GetGroup() const
void SetTextFillColor()
sal_uInt16 GetCode() const
bool IsValidGfx() const
Returns true, if cached graphic is valid.
Definition: csvcontrol.hxx:267
Color maHeaderBackColor
Text color for data area.
Definition: csvgrid.hxx:71
virtual tools::Rectangle GetFocusRect() override
Definition: csvgrid.cxx:1395
void MoveSplit(sal_Int32 nPos, sal_Int32 nNewPos)
Inserts a new or removes an existing split.
Definition: csvgrid.cxx:347
vcl::Font maHeaderFont
For drawing cell texts.
Definition: csvgrid.hxx:78
sal_Int32 GetHdrHeight() const
Returns the height of the header line.
Definition: csvcontrol.hxx:347
void SetFirstImportedLine(sal_Int32 nLine)
Sets the number of the first imported line (for visual feedback).
Definition: csvgrid.cxx:212
SAL_DLLPRIVATE void ImplDrawColumnHeader(OutputDevice &rOutDev, sal_uInt32 nColIndex, Color aFillColor)
Draws the header of the specified column to the specified output device.
Definition: csvgrid.cxx:1095
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
void RemoveAllSplits()
Removes all splits.
Definition: csvgrid.cxx:375
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
const CommandWheelData * GetWheelData() const
const SCCOL MAXCOLCOUNT
Definition: address.hxx:63
constexpr sal_uInt16 KEY_SPACE
Change width of the header column. [width in pixel].
Definition: csvcontrol.hxx:168
VclPtr< VirtualDevice > mpGridDev
Grid background, headers, cell texts.
Definition: csvgrid.hxx:62
SAL_DLLPRIVATE void ImplDrawHorzScrolled(sal_Int32 nOldPos)
Optimized drawing: Scrolls horizontally and redraws only missing parts.
Definition: csvgrid.cxx:1326
Change height of top header line. [height in pixel].
Definition: csvcontrol.hxx:174
void FillColumnDataFix(ScAsciiOptions &rOptions) const
Fills the options object with column data for fixed width mode.
Definition: csvgrid.cxx:579
Base class for the CSV ruler and the data grid control.
Definition: csvcontrol.hxx:222
bool IsHorz() const
SAL_DLLPRIVATE void ImplDrawColumn(sal_uInt32 nColIndex)
Redraws the entire column (background and selection).
Definition: csvgrid.cxx:1320
const sal_Int32 CSV_MAXSTRLEN
Maximum length of a cell string.
Definition: csvcontrol.hxx:35
Move ruler cursor to new position. [position].
Definition: csvcontrol.hxx:178
void SetColumnStates(const ScCsvColStateVec &rColStates)
Sets all column states to the values in the passed vector.
Definition: csvgrid.cxx:485
Size const & GetOutputSizePixel() const
SAL_DLLPRIVATE void ImplDrawColumnBackgr(sal_uInt32 nColIndex)
Draws the column with index nColIndex to maBackgrDev.
Definition: csvgrid.cxx:1177
constexpr sal_uInt16 KEY_9
void ToggleSelect(sal_uInt32 nColIndex)
Toggles selection of the specified column.
Definition: csvgrid.cxx:656
#define SAL_MAX_UINT32
constexpr tools::Long Width() const
bool mbMTSelecting
True if Mouse tracking.
Definition: csvgrid.hxx:92
Predecessor of current element in current context.
Definition: csvcontrol.hxx:82
Color maTextColor
Background color for unused area.
Definition: csvgrid.hxx:70
void SelectAll(bool bSelect=true)
Selects or deselects all columns.
Definition: csvgrid.cxx:688
SAL_DLLPRIVATE bool ImplInsertSplit(sal_Int32 nPos)
Inserts a split and adjusts column data.
Definition: csvgrid.cxx:398
sal_uInt16 sal_Unicode
virtual void GetFocus() override
Definition: csvcontrol.cxx:74
sal_Int32 GetLastX() const
Returns the X position of the last pixel of the data area.
Definition: csvcontrol.cxx:190
SAL_DLLPRIVATE void ImplDrawFirstLineSep(bool bSet)
Draws the "first imported line" separator to maBackgrDev (or erases, if bSet is false).
Definition: csvgrid.cxx:1166
sal_Int32 GetY(sal_Int32 nLine) const
Returns output Y coordinate of the specified line.
Definition: csvcontrol.cxx:230
const sal_Int32 CSV_SCROLL_DIST
Minimum distance to border for auto scroll.
Definition: csvcontrol.hxx:39
sal_Int32 GetCharWidth() const
Returns the width of one character column.
Definition: csvcontrol.hxx:318
bool IsVisibleLine(sal_Int32 nLine) const
Returns true, if nLine is a valid and visible line index.
Definition: csvcontrol.cxx:225
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
const vcl::Font & GetFont() const
Exported data of a column (data used in the dialog).
Definition: csvcontrol.hxx:63
void UpdateOffsetX()
Updates X coordinate of first visible position dependent from line numbers.
Definition: csvgrid.cxx:153
bool Remove(sal_Int32 nPos)
Removes a split by position.
Definition: csvsplits.cxx:43
constexpr sal_uInt16 KEY_1
bool IsMouseEvent() const
std::vector< std::vector< OUString > > maTexts
UI names of data types.
Definition: csvgrid.hxx:86
constexpr Point BottomLeft() const
int nCount
SAL_DLLPRIVATE void ImplSetColumnClipRegion(OutputDevice &rOutDev, sal_uInt32 nColIndex)
Sets a clip region in the specified output device for the specified column.
Definition: csvgrid.cxx:1088
EditEngine * GetEditEngine()
Returns a pointer to the used edit engine.
Definition: csvgrid.cxx:1083
VclPtr< VirtualDevice > mpBackgrDev
Grid Parent.
Definition: csvgrid.hxx:61
SAL_DLLPRIVATE bool ImplRemoveSplit(sal_Int32 nPos)
Removes a split and adjusts column data.
Definition: csvgrid.cxx:413
void Select(sal_uInt32 nColIndex, bool bSelect=true)
Selects or deselects the specified column.
Definition: csvgrid.cxx:642
bool IsRTL() const
Returns true, if the Right-to-Left layout mode is active.
Definition: csvcontrol.hxx:297
SAL_DLLPRIVATE void InitColors()
Reads colors from system settings.
Definition: csvgrid.cxx:240
void InsertSplit(sal_Int32 nPos)
Inserts a split.
Definition: csvgrid.cxx:319
constexpr sal_uInt16 KEYGROUP_CURSOR
sal_Int32 mnType
Definition: csvgrid.hxx:43
virtual void GetFocus() override
Definition: csvgrid.cxx:876
const sal_Int32 CSV_TYPE_NOSELECTION
No column selected.
Definition: csvcontrol.hxx:51
virtual OutputDevice & get_ref_device()=0
const sal_Int32 CSV_MINCOLWIDTH
Minimum character count for a column in separators mode.
Definition: csvcontrol.hxx:33
sal_Int32 GetFirstX() const
Returns the X position of the first pixel of the data area.
Definition: csvcontrol.cxx:185
void DrawLine(const Point &rStartPt, const Point &rEndPt)
sal_uInt16 nCode
ScCsvTableBox * mpTableBox
Definition: csvgrid.hxx:60
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
Change number of data lines. [line count].
Definition: csvcontrol.hxx:172
SAL_DLLPRIVATE void ExecutePopup(const Point &rPos)
Executes the data type popup menu.
Definition: csvgrid.cxx:614
void DrawRect(const tools::Rectangle &rRect)
#define SAL_N_ELEMENTS(arr)
sal_uInt32 mnMTCurrCol
Index of most recently selected column.
Definition: csvgrid.hxx:90
const OUString & GetCellText(sal_uInt32 nColIndex, sal_Int32 nLine) const
Returns the text of the specified cell.
Definition: csvgrid.cxx:852
void ImplSetTextLineSep(sal_Int32 nLine, const OUString &rTextLine, const OUString &rSepChars, sal_Unicode cTextSep, bool bMergeSep, bool bRemoveSpace=false)
Fills all cells of a line with the passed text (separators mode).
Definition: csvgrid.cxx:762
virtual void ConfigurationChanged(::utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: csvgrid.cxx:1056
void Repaint(bool bInvalidate=false)
Repaints all controls.
Definition: csvcontrol.cxx:130
virtual void CopyArea(const Point &rDestPt, const Point &rSrcPt, const Size &rSrcSize, bool bWindowInvalidate=false)
void SetSelColumnType(sal_Int32 nType)
Changes the data type of all selected columns.
Definition: csvgrid.cxx:524
const Color & GetDarkShadowColor() const
sal_Int32 GetLastVisPos() const
Returns the last visible position.
Definition: csvcontrol.hxx:306
void SetLineColor()
SAL_DLLPRIVATE void ScrollVertRel(ScMoveMode eDir)
Scrolls data grid vertically.
Definition: csvgrid.cxx:595
const OUString & GetColumnTypeName(sal_uInt32 nColIndex) const
Returns the UI type name of the specified column.
Definition: csvgrid.cxx:549
#define SAL_MAX_INT32
ScCsvGrid(const ScCsvLayoutData &rData, std::unique_ptr< weld::Menu > xPopup, ScCsvTableBox *pTableBox)
Mouse tracking mode: true = select, false = deselect.
Definition: csvgrid.cxx:73
Last element in current context.
Definition: csvcontrol.hxx:81
Successor of current element in current context.
Definition: csvcontrol.hxx:83
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
std::vector< OUString > maTypeNames
State of each column.
Definition: csvgrid.hxx:85
bool IsDark() const
virtual void StyleUpdated() override
Definition: csvgrid.cxx:1046
virtual ~ScCsvGrid() override
Definition: csvgrid.cxx:120
sal_Int32 mnType
SAL_DLLPRIVATE void InitControls()
Initializes the children controls (pos/size, scroll bars, ...).
bool IsVisibleColumn(sal_uInt32 nColIndex) const
Returns true, if column with index nColIndex is (at least partly) visible.
Definition: csvgrid.cxx:456
Color maAppBackColor
Grid color for "first imported line" delimiter.
Definition: csvgrid.hxx:69
const sal_uInt32 CSV_COLUMN_INVALID
Definition: csvgrid.hxx:38
sal_Int32 mnPosCount
Definition: csvcontrol.hxx:114
#define SC_MOD()
Definition: scmod.hxx:250
tools::Long GetNotchDelta() const
void Clear()
Removes all elements from the vector.
Definition: csvsplits.cxx:61
static ScMoveMode GetVertDirection(sal_uInt16 nCode, bool bHomeEnd)
Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
Definition: csvcontrol.cxx:267
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
void DrawTransparent(const tools::PolyPolygon &rPolyPoly, sal_uInt16 nTransparencePercent)
CommandWheelMode GetMode() const
Move data grid cursor to new column. [position].
Definition: csvcontrol.hxx:179
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: csvgrid.cxx:946
void SetFillColor()
void AccSendInsertColumnEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn)
Sends a table model changed event for an inserted column to the accessibility object.
Definition: csvcontrol.cxx:116
CommandEventId GetCommand() const
virtual tools::Rectangle GetFocusRect()
A vector of column splits that supports inserting, removing and moving splits.
Definition: csvsplits.hxx:32
void SetTextColor(const Color &rColor)
void FillColumnDataSep(ScAsciiOptions &rOptions) const
Fills the options object with column data for separators mode.
Definition: csvgrid.cxx:563
void Select(bool bSel)
Definition: csvgrid.hxx:50
sal_Int32 GetFirstVisLine() const
Returns index of first visible line.
Definition: csvcontrol.hxx:335
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CJK(EE_CHAR_START+21)
sal_Int32 GetVisLineCount() const
Returns the number of visible lines (including partly visible bottom line).
Definition: csvcontrol.cxx:205
SAL_DLLPRIVATE void ImplInvertCursor(sal_Int32 nPos)
Inverts the cursor bar at the specified position in maGridDev.
Definition: csvgrid.cxx:1382
rtl::Reference< ScAccessibleCsvControl > mxAccessible
Content of virtual devices valid?
Definition: csvcontrol.hxx:232
const Size & GetFontSize() const
sal_uInt32 GetFocusColumn() const
Returns index of the focused column.
Definition: csvgrid.hxx:219
bool IsVisibleSplitPos(sal_Int32 nPos) const
Returns true, if nPos is an allowed AND visible split position.
Definition: csvcontrol.cxx:175
bool IsInside(const Point &rPOINT) const
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CTL(EE_CHAR_START+24)
sal_uInt32 GetColumnFromX(sal_Int32 nX) const
Returns column index from output coordinate.
Definition: csvgrid.cxx:468
Change data type of selected columns. [column type].
Definition: csvcontrol.hxx:185
constexpr void SetBottom(tools::Long v)
SAL_DLLPRIVATE void ImplDrawColumnSelection(sal_uInt32 nColIndex)
Draws the column with index nColIndex with its selection state to maGridDev.
Definition: csvgrid.cxx:1277
void ValidateGfx()
Sets the graphic valid (next Redraw() will use cached graphic).
Definition: csvcontrol.hxx:265
sal_uInt16 GetModifier() const
void ImplSetTextLineFix(sal_Int32 nLine, const OUString &rTextLine)
Fills all cells of a line with the passed text (fixed width mode).
Definition: csvgrid.cxx:823
sal_Int32 GetColumnWidth(sal_uInt32 nColIndex) const
Returns the character width of the column with the specified index.
Definition: csvgrid.cxx:480
sal_Int32 mnFirstImpLine
2D-vector for cell texts.
Definition: csvgrid.hxx:88
First element in current context.
Definition: csvcontrol.hxx:80
sal_uInt32 GetColumnCount() const
Returns the number of columns.
Definition: csvgrid.hxx:149
const sal_Int32 CSV_TYPE_DEFAULT
Default column data type.
Definition: csvcontrol.hxx:47
::std::vector< ScCsvColState > ScCsvColStateVec
Definition: csvgrid.hxx:53
void SetOutputSizePixel(const Size &rSize)
constexpr void SetTop(tools::Long v)
No action.
Definition: csvcontrol.hxx:79
sal_Int32 GetMaxPosOffset() const
Returns highest possible position for first visible character.
Definition: csvcontrol.cxx:165
virtual void Resize() override
Definition: csvgrid.cxx:867
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: csvgrid.cxx:917
sal_Int32 GetMaxLineOffset() const
Returns highest possible index for first line.
Definition: csvcontrol.cxx:215
sal_Int32 mnPosCursor
Height of a data line.
Definition: csvcontrol.hxx:130
constexpr Point TopLeft() const
void SetTypeNames(const std::vector< OUString > &rTypeNames)
Sets new UI data type names.
Definition: csvgrid.cxx:535
The control in the CSV import dialog that contains a ruler and a data grid to visualize and modify th...
Definition: csvtablebox.hxx:43
void SelectRange(sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect=true)
Selects or deselects the specified column range.
Definition: csvgrid.cxx:661
const Point & GetMousePosPixel() const
Change position offset (scroll pos). [position].
Definition: csvcontrol.hxx:167
const sal_uInt16 CSV_HDR_TRANSPARENCY
Transparency for header color of selected columns.
Definition: csvcontrol.hxx:37
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
const vcl::KeyCode & GetKeyCode() const
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
Creates a new accessible object.
Definition: csvgrid.cxx:1410
sal_uInt32 GetNextSelected(sal_uInt32 nFromIndex) const
Returns index of the first selected column really after nFromIndex.
Definition: csvgrid.cxx:633
bool IsShift() const
weld::DrawingArea * GetDrawingArea() const
sal_Int32 mnIndex
Definition: csvcontrol.hxx:65
void Init()
Finishes initialization.
Definition: csvgrid.cxx:130
SAL_DLLPRIVATE void ImplDrawRowHeaders()
Draws the row headers column to maBackgrDev.
Definition: csvgrid.cxx:1224
Change first visible line. [line index].
Definition: csvcontrol.hxx:173
virtual void LoseFocus() override
Definition: csvcontrol.cxx:80
sal_Int32 GetRulerCursorPos() const
Returns the ruler cursor position.
Definition: csvcontrol.hxx:356
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
const Color & GetButtonTextColor() const
void Execute(ScCsvCmdType eType, sal_Int32 nParam1=CSV_POS_INVALID, sal_Int32 nParam2=CSV_POS_INVALID)
Executes a command by calling command handler.
Definition: csvcontrol.cxx:152
SAL_DLLPRIVATE void DoSelectAction(sal_uInt32 nColIndex, sal_uInt16 nModifier)
Executes selection action for a specific column.
Definition: csvgrid.cxx:745
constexpr tools::Long Height() const
std::unique_ptr< ScEditEngineDefaulter > mpEditEngine
Header color of selected columns.
Definition: csvgrid.hxx:77
unsigned char sal_uInt8
virtual void LoseFocus() override
Definition: csvgrid.cxx:883
sal_Int32 GetLastVisLine() const
Returns index of last visible line.
Definition: csvcontrol.cxx:210
const sal_Int32 CSV_TYPE_MULTI
Multi selection with different types.
Definition: csvcontrol.hxx:49
ScCsvColStateVec maColStates
Vector with split positions.
Definition: csvgrid.hxx:84
void SetFont(const vcl::Font &rNewFont)
tools::Long GetTextHeight() const
void SetWhich(sal_uInt16 nId)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CTL(EE_CHAR_START+22)
sal_Int32 GetVisPosCount() const
Returns the number of visible positions.
Definition: csvcontrol.cxx:160
constexpr Point TopRight() const
Color maHeaderGridColor
Background color for headers.
Definition: csvgrid.hxx:72
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
bool IsLeft() const
Color maBackColor
Application color configuration.
Definition: csvgrid.hxx:66
bool IsMod1() const
void DrawGrid(const tools::Rectangle &rRect, const Size &rDist, DrawGridFlags nFlags)
const sal_uInt8 SC_COL_MDY
Definition: csvcontrol.hxx:56
const sal_uInt8 SC_COL_ENGLISH
Definition: csvcontrol.hxx:60
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: csvgrid.cxx:923
sal_Int32 GetHeight() const
Returns the height of the control.
Definition: csvgrid.hxx:277
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
sal_Int32 GetSelColumnType() const
Returns the data type of the selected columns.
Definition: csvgrid.cxx:508
sal_Int32 GetHdrWidth() const
Returns the width of the header column.
Definition: csvcontrol.hxx:316
sal_Int32 GetColumnX(sal_uInt32 nColIndex) const
Returns X coordinate of the specified column.
Definition: csvgrid.cxx:463
void AccSendSelectionEvent()
Sends a selection changed event to the accessibility object.
Definition: csvcontrol.cxx:104
sal_Int32 GetNoScrollCol(sal_Int32 nPos) const
Finds a column position nearest to nPos which does not cause scrolling the visible area...
Definition: csvgrid.cxx:221
Size maWinSize
Monospace font for data cells.
Definition: csvgrid.hxx:80
ScCsvDiff
Flags for comparison of old and new control layout data.
Definition: csvcontrol.hxx:88
sal_uInt32 mnRecentSelCol
First imported line (0-based).
Definition: csvgrid.hxx:89
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
void RemoveRange(sal_Int32 nPosStart, sal_Int32 nPosEnd)
Removes a range of splits in the given position range.
Definition: csvsplits.cxx:53
SAL_DLLPRIVATE void ImplDrawBackgrDev()
Draws all columns and the row headers column to maBackgrDev.
Definition: csvgrid.cxx:1261
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
SAL_DLLPRIVATE void ImplClearSelection()
Clears the entire selection without notify.
Definition: csvgrid.cxx:739
const char * pChar
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
const Point & GetPosPixel() const
Previous page relative to current context.
Definition: csvcontrol.hxx:84
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
double getLength(const B2DPolygon &rCandidate)
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
sal_uInt32 GetFirstSelected() const
Returns index of the first selected column.
Definition: csvgrid.cxx:628
Size maEdEngSize
Size of the control.
Definition: csvgrid.hxx:81
static void SetFontInfoInItemSet(SfxItemSet &rItemSet, const vcl::Font &rFont)
void DisableRepaint()
Increases no-repaint counter (controls do not repaint until the last EnableRepaint()).
Definition: csvcontrol.cxx:138
const vcl::Font & GetAppFont() const
constexpr Point BottomRight() const
void InvalidateGfx()
Sets the graphic invalid (next Redraw() will not use cached graphic).
Definition: csvcontrol.hxx:263
SAL_DLLPRIVATE void MoveCursor(sal_uInt32 nColIndex)
Moves column cursor to a new position.
Definition: csvgrid.cxx:693
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CJK(EE_CHAR_START+23)
VirtualDevice * get() const
const sal_Int32 CSV_MAXCOLCOUNT
Maximum count of columns.
Definition: csvcontrol.hxx:44
bool Insert(sal_Int32 nPos)
The split container.
Definition: csvsplits.cxx:26
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
SAL_DLLPRIVATE void SetColumnType(sal_uInt32 nColIndex, sal_Int32 nColType)
Sets the data type of the specified column.
Definition: csvgrid.cxx:499
const sal_uInt8 SC_COL_DMY
Definition: csvcontrol.hxx:57
SAL_DLLPRIVATE void ImplClearSplits()
Clears the split array and re-inserts boundary splits.
Definition: csvgrid.cxx:428
sal_Int32 GetHdrX() const
Returns the start position of the header column.
Definition: csvcontrol.cxx:180
constexpr sal_uInt16 KEY_SHIFT
bool IsSelected(sal_uInt32 nColIndex) const
Returns true, if the specified column is selected.
Definition: csvgrid.cxx:623
virtual void set_size_request(int nWidth, int nHeight)=0
static const sal_Unicode * ScanNextFieldFromString(const sal_Unicode *p, OUString &rField, sal_Unicode cStr, const sal_Unicode *pSeps, bool bMergeSeps, bool &rbIsQuoted, bool &rbOverflowCell, bool bRemoveSpace)
Definition: impex.cxx:1645
::std::vector< ScCsvExpData > ScCsvExpDataVec
Definition: csvcontrol.hxx:73
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: csvgrid.cxx:94
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const sal_uInt8 SC_COL_SKIP
Definition: csvcontrol.hxx:59
Color maHeaderTextColor
Grid color for headers.
Definition: csvgrid.hxx:73
Recalculate splits and cell texts. [-].
Definition: csvcontrol.hxx:183
sal_Int32 GetFirstVisPos() const
Returns the first visible position.
Definition: csvcontrol.hxx:304
sal_uInt32 Count() const
Returns the number of splits.
Definition: csvsplits.hxx:68
void ImplRedraw(vcl::RenderContext &rRenderContext)
Redraws the entire data grid.
Definition: csvgrid.cxx:1069
sal_Int32 GetWidth() const
Returns the width of the control.
Definition: csvgrid.hxx:275
sal_Int32 GetGridCursorPos() const
Returns the data grid cursor position (not column index!).
Definition: csvcontrol.hxx:358
SAL_DLLPRIVATE void DrawOutDev(const Point &, const Size &, const Point &, const Size &, const Printer &)=delete
sal_uInt16 nPos
sal_Int32 GetColumnPos(sal_uInt32 nColIndex) const
Returns start position of the column with the specified index.
Definition: csvgrid.hxx:166
static sal_Int32 CountVisualWidth(const OUString &rStr, sal_Int32 &nIdx, sal_Int32 nMaxWidth)
ScImportExport::CountVisualWidth Count the width of string visually ( in multiple of western characte...
Definition: impex.cxx:541
SAL_DLLPRIVATE void InitFonts()
Initializes all font settings.
Definition: csvgrid.cxx:260
Color maSelectColor
Text color for headers.
Definition: csvgrid.hxx:74
void SetSplits(const ScCsvSplits &rSplits)
Removes all splits and inserts the splits from rSplits.
Definition: csvgrid.cxx:384
const sal_uInt8 SC_COL_YMD
Definition: csvcontrol.hxx:58
void EnableRTL(bool bEnable)
std::unique_ptr< weld::Menu > mxPopup
Data grid with selection and cursor.
Definition: csvgrid.hxx:63
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:111
bool IsMod2() const
This struct contains the state of one table column.
Definition: csvgrid.hxx:41