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/itempool.hxx>
50 #include <svl/itemset.hxx>
51 #include <editutil.hxx>
52 // *** edit engine ***
53 
54 namespace {
55 
56 struct Func_SetType
57 {
58  sal_Int32 mnType;
59  explicit Func_SetType( sal_Int32 nType ) : mnType( nType ) {}
60  void operator()( ScCsvColState& rState ) const
61  { rState.mnType = mnType; }
62 };
63 
64 struct Func_Select
65 {
66  bool mbSelect;
67  explicit Func_Select( bool bSelect ) : mbSelect( bSelect ) {}
68  void operator()( ScCsvColState& rState ) const
69  { rState.Select( mbSelect ); }
70 };
71 
72 }
73 
74 ScCsvGrid::ScCsvGrid(const ScCsvLayoutData& rData, std::unique_ptr<weld::Menu> xPopup, ScCsvTableBox* pTableBox)
75  : ScCsvControl(rData)
76  , mpTableBox(pTableBox)
77  , mpBackgrDev( VclPtr<VirtualDevice>::Create() )
78  , mpGridDev( VclPtr<VirtualDevice>::Create() )
79  , mxPopup(std::move(xPopup))
80  , mpColorConfig( nullptr )
81  , mpEditEngine( new ScEditEngineDefaulter( EditEngine::CreatePool().get(), true ) )
82  , maColStates( 1 )
83  , maTypeNames( 1 )
84  , mnFirstImpLine( 0 )
85  , mnRecentSelCol( CSV_COLUMN_INVALID )
86  , mnMTCurrCol( SAL_MAX_UINT32 )
87  , mbTracking( false )
88  , mbMTSelecting( false )
89 {
90  mpEditEngine->SetRefDevice( mpBackgrDev.get() );
91  mpEditEngine->SetRefMapMode( MapMode( MapUnit::MapPixel ) );
92  maEdEngSize = mpEditEngine->GetPaperSize();
93 }
94 
96 {
97  OutputDevice& rRefDevice = pDrawingArea->get_ref_device();
99 
100  // expand the point size of the desired font to the equivalent pixel size
101  weld::SetPointFont(rRefDevice, maHeaderFont);
102  maHeaderFont = rRefDevice.GetFont();
103 
104  // Because this is an always LeftToRight layout widget the initial size of
105  // this widget needs to be smaller than the size of the parent scrolling
106  // window (ScCsvTableBox ctor) because in RTL mode the alignment is against
107  // the right edge of the parent, and if larger than the scrolling window
108  // the left edge will be lost. If this widget is smaller than the scrolling
109  // window it is stretched to fit the parent and the problem doesn't arise.
110  Size aInitialSize(10, 10);
111  ScCsvControl::SetDrawingArea(pDrawingArea);
112  pDrawingArea->set_size_request(aInitialSize.Width(), aInitialSize.Height());
113  SetOutputSizePixel(aInitialSize);
114 
115  EnableRTL( false ); // RTL
116 
117  InitFonts();
118  ImplClearSplits();
119 }
120 
122 {
123  OSL_ENSURE(mpColorConfig, "the object hasn't been initialized properly");
124  if (mpColorConfig)
125  mpColorConfig->RemoveListener(this);
128 }
129 
130 void
132 {
133  OSL_PRECOND(!mpColorConfig, "the object has already been initialized");
134  mpColorConfig = &SC_MOD()->GetColorConfig();
135  InitColors();
136  mpColorConfig->AddListener(this);
137 }
138 
139 // common grid handling -------------------------------------------------------
140 
142 {
143  DisableRepaint();
144  OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
145  rRefDevice.SetFont(maMonoFont);
146  Execute(CSVCMD_SETCHARWIDTH, rRefDevice.GetTextWidth(OUString('X')));
147  Execute(CSVCMD_SETLINEHEIGHT, rRefDevice.GetTextHeight() + 1);
148  rRefDevice.SetFont(maHeaderFont);
149  Execute(CSVCMD_SETHDRHEIGHT, rRefDevice.GetTextHeight() + 1);
150  UpdateOffsetX();
151  EnableRepaint();
152 }
153 
155 {
156  sal_Int32 nLastLine = GetLastVisLine() + 1;
157  sal_Int32 nDigits = 2;
158  for (;;)
159  {
160  nLastLine /= 10;
161  if (!nLastLine)
162  break;
163  ++nDigits;
164  }
165  nDigits = std::max( nDigits, sal_Int32( 3 ) );
166  Execute(CSVCMD_SETHDRWIDTH, GetDrawingArea()->get_approximate_digit_width() * nDigits);
167 }
168 
170 {
171  ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData );
172  if( nDiff == ScCsvDiff::Equal ) return;
173 
174  DisableRepaint();
175 
176  if( nDiff & ScCsvDiff::RulerCursor )
177  {
178  ImplInvertCursor( rOldData.mnPosCursor );
180  }
181 
182  if( nDiff & ScCsvDiff::PosCount )
183  {
184  if( GetPosCount() < rOldData.mnPosCount )
185  {
186  SelectAll( false );
188  }
189  else
190  maSplits.Remove( rOldData.mnPosCount );
192  maColStates.resize( maSplits.Count() - 1 );
193  }
194 
195  if( nDiff & ScCsvDiff::LineOffset )
196  {
198  UpdateOffsetX();
199  }
200 
202  if( nHVDiff == ScCsvDiff::PosOffset )
203  ImplDrawHorzScrolled( rOldData.mnPosOffset );
204  else if( nHVDiff != ScCsvDiff::Equal )
205  InvalidateGfx();
206 
207  EnableRepaint();
208 
209  if( nDiff & (ScCsvDiff::PosOffset | ScCsvDiff::LineOffset) )
211 }
212 
213 void ScCsvGrid::SetFirstImportedLine( sal_Int32 nLine )
214 {
215  ImplDrawFirstLineSep( false );
216  mnFirstImpLine = nLine;
217  ImplDrawFirstLineSep( true );
218  ImplDrawGridDev();
219  Repaint();
220 }
221 
222 sal_Int32 ScCsvGrid::GetNoScrollCol( sal_Int32 nPos ) const
223 {
224  sal_Int32 nNewPos = nPos;
225  if( nNewPos != CSV_POS_INVALID )
226  {
227  if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST )
228  {
229  sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0;
230  nNewPos = GetFirstVisPos() + nScroll;
231  }
232  else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1 )
233  {
234  sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0;
235  nNewPos = GetLastVisPos() - nScroll - 1;
236  }
237  }
238  return nNewPos;
239 }
240 
242 {
243  OSL_PRECOND(mpColorConfig, "the object hasn't been initialized properly");
244  if ( !mpColorConfig )
245  return;
251 
256  maSelectColor = rSett.GetActiveColor();
257 
258  InvalidateGfx();
259 }
260 
262 {
263  maMonoFont = OutputDevice::GetDefaultFont( DefaultFontType::FIXED, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::NONE );
265 
266  /* *** Set edit engine defaults ***
267  maMonoFont for Latin script, smaller default font for Asian and Complex script. */
268 
269  // get default fonts
270  SvxFontItem aLatinItem( EE_CHAR_FONTINFO );
271  SvxFontItem aAsianItem( EE_CHAR_FONTINFO_CJK );
272  SvxFontItem aComplexItem( EE_CHAR_FONTINFO_CTL );
273  ::GetDefaultFonts( aLatinItem, aAsianItem, aComplexItem );
274 
275  // create item set for defaults
276  SfxItemSet aDefSet( mpEditEngine->GetEmptyItemSet() );
278  aDefSet.Put( aAsianItem );
279  aDefSet.Put( aComplexItem );
280 
281  // set Asian/Complex font size to height of character in Latin font
282  sal_uLong nFontHt = static_cast< sal_uLong >( maMonoFont.GetFontSize().Height() );
283  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
284  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
285 
286  // copy other items from default font
287  const SfxPoolItem& rWeightItem = aDefSet.Get( EE_CHAR_WEIGHT );
288  std::unique_ptr<SfxPoolItem> pNewItem(rWeightItem.Clone());
289  pNewItem->SetWhich(EE_CHAR_WEIGHT_CJK);
290  aDefSet.Put( *pNewItem );
291  pNewItem->SetWhich(EE_CHAR_WEIGHT_CTL);
292  aDefSet.Put( *pNewItem );
293  const SfxPoolItem& rItalicItem = aDefSet.Get( EE_CHAR_ITALIC );
294  pNewItem.reset(rItalicItem.Clone());
295  pNewItem->SetWhich(EE_CHAR_ITALIC_CJK);
296  aDefSet.Put( *pNewItem );
297  pNewItem->SetWhich(EE_CHAR_ITALIC_CTL);
298  aDefSet.Put( *pNewItem );
299  const SfxPoolItem& rLangItem = aDefSet.Get( EE_CHAR_LANGUAGE );
300  pNewItem.reset(rLangItem.Clone());
301  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CJK);
302  aDefSet.Put( *pNewItem );
303  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CTL);
304  aDefSet.Put( *pNewItem );
305 
306  mpEditEngine->SetDefaults( aDefSet );
307  InvalidateGfx();
308 }
309 
311 {
315  InvalidateGfx();
316 }
317 
318 // split handling -------------------------------------------------------------
319 
320 void ScCsvGrid::InsertSplit( sal_Int32 nPos )
321 {
322  if( ImplInsertSplit( nPos ) )
323  {
324  DisableRepaint();
327  sal_uInt32 nColIx = GetColumnFromPos( nPos );
328  ImplDrawColumn( nColIx - 1 );
329  ImplDrawColumn( nColIx );
330  ValidateGfx(); // performance: do not redraw all columns
331  EnableRepaint();
332  }
333 }
334 
335 void ScCsvGrid::RemoveSplit( sal_Int32 nPos )
336 {
337  if( ImplRemoveSplit( nPos ) )
338  {
339  DisableRepaint();
342  ImplDrawColumn( GetColumnFromPos( nPos ) );
343  ValidateGfx(); // performance: do not redraw all columns
344  EnableRepaint();
345  }
346 }
347 
348 void ScCsvGrid::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos )
349 {
350  sal_uInt32 nColIx = GetColumnFromPos( nPos );
351  if( nColIx == CSV_COLUMN_INVALID )
352  return;
353 
354  DisableRepaint();
355  if( (GetColumnPos( nColIx - 1 ) < nNewPos) && (nNewPos < GetColumnPos( nColIx + 1 )) )
356  {
357  // move a split in the range between 2 others -> keep selection state of both columns
358  maSplits.Remove( nPos );
359  maSplits.Insert( nNewPos );
361  ImplDrawColumn( nColIx - 1 );
362  ImplDrawColumn( nColIx );
363  ValidateGfx(); // performance: do not redraw all columns
364  AccSendTableUpdateEvent( nColIx - 1, nColIx );
365  }
366  else
367  {
368  ImplRemoveSplit( nPos );
369  ImplInsertSplit( nNewPos );
372  }
373  EnableRepaint();
374 }
375 
377 {
378  DisableRepaint();
379  ImplClearSplits();
382  EnableRepaint();
383 }
384 
385 void ScCsvGrid::SetSplits( const ScCsvSplits& rSplits )
386 {
387  DisableRepaint();
388  ImplClearSplits();
389  sal_uInt32 nCount = rSplits.Count();
390  for( sal_uInt32 nIx = 0; nIx < nCount; ++nIx )
391  maSplits.Insert( rSplits[ nIx ] );
392  maColStates.clear();
393  maColStates.resize( maSplits.Count() - 1 );
396  EnableRepaint();
397 }
398 
399 bool ScCsvGrid::ImplInsertSplit( sal_Int32 nPos )
400 {
401  sal_uInt32 nColIx = GetColumnFromPos( nPos );
402  bool bRet = (nColIx < GetColumnCount()) && maSplits.Insert( nPos );
403  if( bRet )
404  {
405  ScCsvColState aState( GetColumnType( nColIx ) );
406  aState.Select( IsSelected( nColIx ) && IsSelected( nColIx + 1 ) );
407  maColStates.insert( maColStates.begin() + nColIx + 1, aState );
408  AccSendInsertColumnEvent( nColIx + 1, nColIx + 1 );
409  AccSendTableUpdateEvent( nColIx, nColIx );
410  }
411  return bRet;
412 }
413 
414 bool ScCsvGrid::ImplRemoveSplit( sal_Int32 nPos )
415 {
416  bool bRet = maSplits.Remove( nPos );
417  if( bRet )
418  {
419  sal_uInt32 nColIx = GetColumnFromPos( nPos );
420  bool bSel = IsSelected( nColIx ) || IsSelected( nColIx + 1 );
421  maColStates.erase( maColStates.begin() + nColIx + 1 );
422  maColStates[ nColIx ].Select( bSel );
423  AccSendRemoveColumnEvent( nColIx + 1, nColIx + 1 );
424  AccSendTableUpdateEvent( nColIx, nColIx );
425  }
426  return bRet;
427 }
428 
430 {
431  sal_uInt32 nColumns = GetColumnCount();
432  maSplits.Clear();
433  maSplits.Insert( 0 );
435  maColStates.resize( 1 );
436  InvalidateGfx();
437  AccSendRemoveColumnEvent( 1, nColumns - 1 );
438 }
439 
440 // columns/column types -------------------------------------------------------
441 
443 {
444  return GetColumnFromPos( GetFirstVisPos() );
445 }
446 
447 sal_uInt32 ScCsvGrid::GetLastVisColumn() const
448 {
449  return GetColumnFromPos( std::min( GetLastVisPos(), GetPosCount() ) - 1 );
450 }
451 
452 bool ScCsvGrid::IsValidColumn( sal_uInt32 nColIndex ) const
453 {
454  return nColIndex < GetColumnCount();
455 }
456 
457 bool ScCsvGrid::IsVisibleColumn( sal_uInt32 nColIndex ) const
458 {
459  return IsValidColumn( nColIndex ) &&
460  (GetColumnPos( nColIndex ) < GetLastVisPos()) &&
461  (GetFirstVisPos() < GetColumnPos( nColIndex + 1 ));
462 }
463 
464 sal_Int32 ScCsvGrid::GetColumnX( sal_uInt32 nColIndex ) const
465 {
466  return GetX( GetColumnPos( nColIndex ) );
467 }
468 
469 sal_uInt32 ScCsvGrid::GetColumnFromX( sal_Int32 nX ) const
470 {
471  sal_Int32 nPos = (nX - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
472  return ((GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos())) ?
474 }
475 
476 sal_uInt32 ScCsvGrid::GetColumnFromPos( sal_Int32 nPos ) const
477 {
478  return maSplits.UpperBound( nPos );
479 }
480 
481 sal_Int32 ScCsvGrid::GetColumnWidth( sal_uInt32 nColIndex ) const
482 {
483  return IsValidColumn( nColIndex ) ? (GetColumnPos( nColIndex + 1 ) - GetColumnPos( nColIndex )) : 0;
484 }
485 
487 {
488  maColStates = std::move(rStates);
489  maColStates.resize( maSplits.Count() - 1 );
493 }
494 
495 sal_Int32 ScCsvGrid::GetColumnType( sal_uInt32 nColIndex ) const
496 {
497  return IsValidColumn( nColIndex ) ? maColStates[ nColIndex ].mnType : CSV_TYPE_NOSELECTION;
498 }
499 
500 void ScCsvGrid::SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType )
501 {
502  if( IsValidColumn( nColIndex ) )
503  {
504  maColStates[ nColIndex ].mnType = nColType;
505  AccSendTableUpdateEvent( nColIndex, nColIndex, false );
506  }
507 }
508 
510 {
511  sal_uInt32 nColIx = GetFirstSelected();
512  if( nColIx == CSV_COLUMN_INVALID )
513  return CSV_TYPE_NOSELECTION;
514 
515  sal_Int32 nType = GetColumnType( nColIx );
516  while( (nColIx != CSV_COLUMN_INVALID) && (nType != CSV_TYPE_MULTI) )
517  {
518  if( nType != GetColumnType( nColIx ) )
519  nType = CSV_TYPE_MULTI;
520  nColIx = GetNextSelected( nColIx );
521  }
522  return nType;
523 }
524 
526 {
527  if( (nType != CSV_TYPE_MULTI) && (nType != CSV_TYPE_NOSELECTION) )
528  {
529  for( sal_uInt32 nColIx = GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = GetNextSelected( nColIx ) )
530  SetColumnType( nColIx, nType );
531  Repaint( true );
533  }
534 }
535 
536 void ScCsvGrid::SetTypeNames( std::vector<OUString>&& rTypeNames )
537 {
538  OSL_ENSURE( !rTypeNames.empty(), "ScCsvGrid::SetTypeNames - vector is empty" );
539  maTypeNames = std::move(rTypeNames);
540  Repaint( true );
541 
542  mxPopup->clear();
543  sal_uInt32 nCount = maTypeNames.size();
544  for (sal_uInt32 nIx = 0; nIx < nCount; ++nIx)
545  mxPopup->append(OUString::number(nIx), maTypeNames[nIx]);
546 
547  ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) );
548 }
549 
550 OUString ScCsvGrid::GetColumnTypeName( sal_uInt32 nColIndex ) const
551 {
552  sal_uInt32 nTypeIx = static_cast< sal_uInt32 >( GetColumnType( nColIndex ) );
553  return (nTypeIx < maTypeNames.size()) ? maTypeNames[ nTypeIx ] : OUString();
554 }
555 
556 static sal_uInt8 lcl_GetExtColumnType( sal_Int32 nIntType )
557 {
558  static const sal_uInt8 pExtTypes[] =
560  static const sal_Int32 nExtTypeCount = SAL_N_ELEMENTS(pExtTypes);
561  return pExtTypes[ ((0 <= nIntType) && (nIntType < nExtTypeCount)) ? nIntType : 0 ];
562 }
563 
565 {
566  sal_uInt32 nCount = GetColumnCount();
567  ScCsvExpDataVec aDataVec;
568 
569  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
570  {
571  if( GetColumnType( nColIx ) != CSV_TYPE_DEFAULT )
572  // 1-based column index
573  aDataVec.emplace_back(
574  static_cast< sal_Int32 >( nColIx + 1 ),
575  lcl_GetExtColumnType( GetColumnType( nColIx ) ) );
576  }
577  rOptions.SetColumnInfo( aDataVec );
578 }
579 
581 {
582  sal_uInt32 nCount = std::min( GetColumnCount(), static_cast<sal_uInt32>(MAXCOLCOUNT) );
583  ScCsvExpDataVec aDataVec( nCount + 1 );
584 
585  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
586  {
587  ScCsvExpData& rData = aDataVec[ nColIx ];
588  rData.mnIndex = GetColumnPos( nColIx );
589  rData.mnType = lcl_GetExtColumnType( GetColumnType( nColIx ) );
590  }
591  aDataVec[ nCount ].mnIndex = SAL_MAX_INT32;
592  aDataVec[ nCount ].mnType = SC_COL_SKIP;
593  rOptions.SetColumnInfo( aDataVec );
594 }
595 
597 {
598  sal_Int32 nLine = GetFirstVisLine();
599  switch( eDir )
600  {
601  case MOVE_PREV: --nLine; break;
602  case MOVE_NEXT: ++nLine; break;
603  case MOVE_FIRST: nLine = 0; break;
604  case MOVE_LAST: nLine = GetMaxLineOffset(); break;
605  case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 2; break;
606  case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 2; break;
607  default:
608  {
609  // added to avoid warnings
610  }
611  }
612  Execute( CSVCMD_SETLINEOFFSET, nLine );
613 }
614 
615 void ScCsvGrid::ExecutePopup( const Point& rPos )
616 {
617  OString sItemId = mxPopup->popup_at_rect(GetDrawingArea(), tools::Rectangle(rPos, Size(1, 1)));
618  if (!sItemId.isEmpty()) // empty = cancelled
619  Execute(CSVCMD_SETCOLUMNTYPE, sItemId.toInt32());
620 }
621 
622 // selection handling ---------------------------------------------------------
623 
624 bool ScCsvGrid::IsSelected( sal_uInt32 nColIndex ) const
625 {
626  return IsValidColumn( nColIndex ) && maColStates[ nColIndex ].IsSelected();
627 }
628 
629 sal_uInt32 ScCsvGrid::GetFirstSelected() const
630 {
631  return IsSelected( 0 ) ? 0 : GetNextSelected( 0 );
632 }
633 
634 sal_uInt32 ScCsvGrid::GetNextSelected( sal_uInt32 nFromIndex ) const
635 {
636  sal_uInt32 nColCount = GetColumnCount();
637  for( sal_uInt32 nColIx = nFromIndex + 1; nColIx < nColCount; ++nColIx )
638  if( IsSelected( nColIx ) )
639  return nColIx;
640  return CSV_COLUMN_INVALID;
641 }
642 
643 void ScCsvGrid::Select( sal_uInt32 nColIndex, bool bSelect )
644 {
645  if( IsValidColumn( nColIndex ) )
646  {
647  maColStates[ nColIndex ].Select( bSelect );
648  ImplDrawColumnSelection( nColIndex );
649  Repaint();
651  if( bSelect )
652  mnRecentSelCol = nColIndex;
654  }
655 }
656 
657 void ScCsvGrid::ToggleSelect( sal_uInt32 nColIndex )
658 {
659  Select( nColIndex, !IsSelected( nColIndex ) );
660 }
661 
662 void ScCsvGrid::SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect )
663 {
664  if( nColIndex1 == CSV_COLUMN_INVALID )
665  Select( nColIndex2 );
666  else if( nColIndex2 == CSV_COLUMN_INVALID )
667  Select( nColIndex1 );
668  else if( nColIndex1 > nColIndex2 )
669  {
670  SelectRange( nColIndex2, nColIndex1, bSelect );
671  if( bSelect )
672  mnRecentSelCol = nColIndex1;
673  }
674  else if( IsValidColumn( nColIndex1 ) && IsValidColumn( nColIndex2 ) )
675  {
676  for( sal_uInt32 nColIx = nColIndex1; nColIx <= nColIndex2; ++nColIx )
677  {
678  maColStates[ nColIx ].Select( bSelect );
679  ImplDrawColumnSelection( nColIx );
680  }
681  Repaint();
683  if( bSelect )
684  mnRecentSelCol = nColIndex1;
686  }
687 }
688 
689 void ScCsvGrid::SelectAll( bool bSelect )
690 {
691  SelectRange( 0, GetColumnCount() - 1, bSelect );
692 }
693 
694 void ScCsvGrid::MoveCursor( sal_uInt32 nColIndex )
695 {
696  DisableRepaint();
697  if( IsValidColumn( nColIndex ) )
698  {
699  sal_Int32 nPosBeg = GetColumnPos( nColIndex );
700  sal_Int32 nPosEnd = GetColumnPos( nColIndex + 1 );
701  sal_Int32 nMinPos = std::max( nPosBeg - CSV_SCROLL_DIST, sal_Int32( 0 ) );
702  sal_Int32 nMaxPos = std::min( nPosEnd - GetVisPosCount() + CSV_SCROLL_DIST + sal_Int32( 1 ), nMinPos );
703  if( nPosBeg - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
704  Execute( CSVCMD_SETPOSOFFSET, nMinPos );
705  else if( nPosEnd + CSV_SCROLL_DIST >= GetLastVisPos() )
706  Execute( CSVCMD_SETPOSOFFSET, nMaxPos );
707  }
708  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
709  EnableRepaint();
710 }
711 
713 {
715  return;
716 
717  switch( eDir )
718  {
719  case MOVE_FIRST:
720  MoveCursor( 0 );
721  break;
722  case MOVE_LAST:
723  MoveCursor( GetColumnCount() - 1 );
724  break;
725  case MOVE_PREV:
726  if( GetFocusColumn() > 0 )
727  MoveCursor( GetFocusColumn() - 1 );
728  break;
729  case MOVE_NEXT:
730  if( GetFocusColumn() < GetColumnCount() - 1 )
731  MoveCursor( GetFocusColumn() + 1 );
732  break;
733  default:
734  {
735  // added to avoid warnings
736  }
737  }
738 }
739 
741 {
742  ::std::for_each( maColStates.begin(), maColStates.end(), Func_Select( false ) );
743  ImplDrawGridDev();
744 }
745 
746 void ScCsvGrid::DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier )
747 {
748  if( !(nModifier & KEY_MOD1) )
750  if( nModifier & KEY_SHIFT ) // SHIFT always expands
751  SelectRange( mnRecentSelCol, nColIndex );
752  else if( !(nModifier & KEY_MOD1) ) // no SHIFT/CTRL always selects 1 column
753  Select( nColIndex );
754  else if( mbTracking ) // CTRL in tracking does not toggle
755  Select( nColIndex, mbMTSelecting );
756  else // CTRL only toggles
757  ToggleSelect( nColIndex );
758  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
759 }
760 
761 // cell contents --------------------------------------------------------------
762 
764  sal_Int32 nLine, const OUString& rTextLine,
765  const OUString& rSepChars, sal_Unicode cTextSep, bool bMergeSep, bool bRemoveSpace )
766 {
767  if( nLine < GetFirstVisLine() ) return;
768 
769  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
770  while( maTexts.size() <= nLineIx )
771  maTexts.emplace_back( );
772  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
773  rStrVec.clear();
774 
775  // scan for separators
776  OUString aCellText;
777  const sal_Unicode* pSepChars = rSepChars.getStr();
778  const sal_Unicode* pChar = rTextLine.getStr();
779  sal_uInt32 nColIx = 0;
780 
781  while( *pChar && (nColIx < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT)) )
782  {
783  // scan for next cell text
784  bool bIsQuoted = false;
785  bool bOverflowCell = false;
786  pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText,
787  cTextSep, pSepChars, bMergeSep, bIsQuoted, bOverflowCell, bRemoveSpace );
788  /* TODO: signal overflow somewhere in UI */
789 
790  // update column width
791  sal_Int32 nWidth = std::max( CSV_MINCOLWIDTH, ScImportExport::CountVisualWidth( aCellText ) + 1 );
792  if( IsValidColumn( nColIx ) )
793  {
794  // expand existing column
795  sal_Int32 nDiff = nWidth - GetColumnWidth( nColIx );
796  if( nDiff > 0 )
797  {
798  Execute( CSVCMD_SETPOSCOUNT, GetPosCount() + nDiff );
799  for( sal_uInt32 nSplitIx = GetColumnCount() - 1; nSplitIx > nColIx; --nSplitIx )
800  {
801  sal_Int32 nPos = maSplits[ nSplitIx ];
802  maSplits.Remove( nPos );
803  maSplits.Insert( nPos + nDiff );
804  }
805  }
806  }
807  else
808  {
809  // append new column
810  sal_Int32 nLastPos = GetPosCount();
811  Execute( CSVCMD_SETPOSCOUNT, nLastPos + nWidth );
812  ImplInsertSplit( nLastPos );
813  }
814 
815  if( aCellText.getLength() <= CSV_MAXSTRLEN )
816  rStrVec.push_back( aCellText );
817  else
818  rStrVec.push_back( aCellText.copy( 0, CSV_MAXSTRLEN ) );
819  ++nColIx;
820  }
821  InvalidateGfx();
822 }
823 
824 void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine )
825 {
826  if( nLine < GetFirstVisLine() ) return;
827 
828  sal_Int32 nWidth = ScImportExport::CountVisualWidth( rTextLine );
829  if( nWidth > GetPosCount() )
830  Execute( CSVCMD_SETPOSCOUNT, nWidth );
831 
832  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
833  while( maTexts.size() <= nLineIx )
834  maTexts.emplace_back( );
835 
836  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
837  rStrVec.clear();
838  sal_uInt32 nColCount = GetColumnCount();
839  sal_Int32 nStrLen = rTextLine.getLength();
840  sal_Int32 nStrIx = 0;
841  for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx )
842  {
843  sal_Int32 nColWidth = GetColumnWidth( nColIx );
844  sal_Int32 nLastIx = nStrIx;
845  ScImportExport::CountVisualWidth( rTextLine, nLastIx, nColWidth );
846  sal_Int32 nLen = std::min( CSV_MAXSTRLEN, nLastIx - nStrIx );
847  rStrVec.push_back( rTextLine.copy( nStrIx, nLen ) );
848  nStrIx = nStrIx + nLen;
849  }
850  InvalidateGfx();
851 }
852 
853 OUString ScCsvGrid::GetCellText( sal_uInt32 nColIndex, sal_Int32 nLine ) const
854 {
855  if( nLine < GetFirstVisLine() ) return OUString();
856 
857  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
858  if( nLineIx >= maTexts.size() ) return OUString();
859 
860  const std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
861  if( nColIndex >= rStrVec.size() ) return OUString();
862 
863  return rStrVec[ nColIndex ];
864 }
865 
866 // event handling -------------------------------------------------------------
867 
869 {
871 
873  InitSizeData();
875 }
876 
878 {
881  Repaint();
882 }
883 
885 {
887  Repaint();
888 }
889 
891 {
892  DisableRepaint();
893  if( !HasFocus() )
894  GrabFocus();
895 
896  Point aPos( rMEvt.GetPosPixel() );
897  sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
898 
899  if( rMEvt.IsLeft() )
900  {
901  if( (GetFirstX() > aPos.X()) || (aPos.X() > GetLastX()) ) // in header column
902  {
903  if( aPos.Y() <= GetHdrHeight() )
904  SelectAll();
905  }
906  else if( IsValidColumn( nColIx ) )
907  {
908  DoSelectAction( nColIx, rMEvt.GetModifier() );
909  mnMTCurrCol = nColIx;
910  mbMTSelecting = IsSelected( nColIx );
911  mbTracking = true;
912  }
913  }
914  EnableRepaint();
915  return true;
916 }
917 
919 {
920  mbTracking = false;
921  return true;
922 }
923 
924 bool ScCsvGrid::MouseMove( const MouseEvent& rMEvt )
925 {
926  if (!mbTracking)
927  return true;
928 
929  DisableRepaint();
930 
931  sal_Int32 nPos = (rMEvt.GetPosPixel().X() - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
932  // on mouse tracking: keep position valid
933  nPos = std::clamp( nPos, sal_Int32(0), GetPosCount() - 1 );
935 
936  sal_uInt32 nColIx = GetColumnFromPos( nPos );
937  if( mnMTCurrCol != nColIx )
938  {
939  DoSelectAction( nColIx, rMEvt.GetModifier() );
940  mnMTCurrCol = nColIx;
941  }
942  EnableRepaint();
943 
944  return true;
945 }
946 
947 bool ScCsvGrid::KeyInput( const KeyEvent& rKEvt )
948 {
949  const vcl::KeyCode& rKCode = rKEvt.GetKeyCode();
950  sal_uInt16 nCode = rKCode.GetCode();
951  bool bShift = rKCode.IsShift();
952  bool bMod1 = rKCode.IsMod1();
953 
954  if( !rKCode.IsMod2() )
955  {
956  ScMoveMode eHDir = GetHorzDirection( nCode, !bMod1 );
957  ScMoveMode eVDir = GetVertDirection( nCode, bMod1 );
958 
959  if( eHDir != MOVE_NONE )
960  {
961  DisableRepaint();
962  MoveCursorRel( eHDir );
963  if( !bMod1 )
965  if( bShift )
967  else if( !bMod1 )
968  Select( GetFocusColumn() );
969  EnableRepaint();
970  }
971  else if( eVDir != MOVE_NONE )
972  ScrollVertRel( eVDir );
973  else if( nCode == KEY_SPACE )
974  {
975  if( !bMod1 )
977  if( bShift )
979  else if( bMod1 )
981  else
982  Select( GetFocusColumn() );
983  }
984  else if( !bShift && bMod1 )
985  {
986  if( nCode == KEY_A )
987  SelectAll();
988  else if( (KEY_1 <= nCode) && (nCode <= KEY_9) )
989  {
990  sal_uInt32 nType = nCode - KEY_1;
991  if( nType < maTypeNames.size() )
992  Execute( CSVCMD_SETCOLUMNTYPE, nType );
993  }
994  }
995  }
996 
997  return rKCode.GetGroup() == KEYGROUP_CURSOR;
998 }
999 
1000 bool ScCsvGrid::Command( const CommandEvent& rCEvt )
1001 {
1002  bool bConsumed = true;
1003  switch( rCEvt.GetCommand() )
1004  {
1005  case CommandEventId::ContextMenu:
1006  {
1007  if( rCEvt.IsMouseEvent() )
1008  {
1009  Point aPos( rCEvt.GetMousePosPixel() );
1010  sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
1011  if( IsValidColumn( nColIx ) && (GetFirstX() <= aPos.X()) && (aPos.X() <= GetLastX()) )
1012  {
1013  if( !IsSelected( nColIx ) )
1014  DoSelectAction( nColIx, 0 ); // focus & select
1015  ExecutePopup( aPos );
1016  }
1017  }
1018  else
1019  {
1020  sal_uInt32 nColIx = GetFocusColumn();
1021  if( !IsSelected( nColIx ) )
1022  Select( nColIx );
1023  sal_Int32 nX1 = std::max( GetColumnX( nColIx ), GetFirstX() );
1024  sal_Int32 nX2 = std::min( GetColumnX( nColIx + 1 ), GetWidth() );
1025  ExecutePopup( Point( (nX1 + nX2) / 2, GetHeight() / 2 ) );
1026  }
1027  break;
1028  }
1029  case CommandEventId::Wheel:
1030  {
1031  tools::Rectangle aRect( Point(), maWinSize );
1032  if( aRect.Contains( rCEvt.GetMousePosPixel() ) )
1033  {
1034  const CommandWheelData* pData = rCEvt.GetWheelData();
1035  if( pData && (pData->GetMode() == CommandWheelMode::SCROLL) && !pData->IsHorz() )
1037  }
1038  break;
1039  }
1040  default:
1041  bConsumed = false;
1042  break;
1043  }
1044  return bConsumed;
1045 }
1046 
1048 {
1049  InitColors();
1050  InitFonts();
1051  UpdateLayoutData();
1053 
1055 }
1056 
1058 {
1059  InitColors();
1060  Repaint();
1061 }
1062 
1063 // painting -------------------------------------------------------------------
1064 
1066 {
1067  ImplRedraw(rRenderContext);
1068 }
1069 
1071 {
1072  if( IsVisible() )
1073  {
1074  if( !IsValidGfx() )
1075  {
1076  ValidateGfx();
1078  ImplDrawGridDev();
1079  }
1080  rRenderContext.DrawOutDev( Point(), maWinSize, Point(), maWinSize, *mpGridDev );
1081  }
1082 }
1083 
1085 {
1086  return mpEditEngine.get();
1087 }
1088 
1089 void ScCsvGrid::ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex )
1090 {
1092  std::max( GetColumnX( nColIndex ), GetFirstX() ) + 1, 0,
1093  std::min( GetColumnX( nColIndex + 1 ), GetLastX() ), GetHeight() - 1 ) ) );
1094 }
1095 
1096 void ScCsvGrid::ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor )
1097 {
1098  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1099  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1100  sal_Int32 nHdrHt = GetHdrHeight();
1101 
1102  rOutDev.SetLineColor();
1103  rOutDev.SetFillColor( aFillColor );
1104  rOutDev.DrawRect( tools::Rectangle( nX1, 0, nX2, nHdrHt ) );
1105 
1106  rOutDev.SetFont( maHeaderFont );
1107  rOutDev.SetTextColor( maHeaderTextColor );
1108  rOutDev.SetTextFillColor();
1109  rOutDev.DrawText( Point( nX1 + 1, 0 ), GetColumnTypeName( nColIndex ) );
1110 
1111  rOutDev.SetLineColor( maHeaderGridColor );
1112  rOutDev.DrawLine( Point( nX1, nHdrHt ), Point( nX2, nHdrHt ) );
1113  rOutDev.DrawLine( Point( nX2, 0 ), Point( nX2, nHdrHt ) );
1114 }
1115 
1116 void ScCsvGrid::ImplDrawCellText( const Point& rPos, const OUString& rText )
1117 {
1118  OUString aPlainText = rText.replaceAll( "\t", " " );
1119  aPlainText = aPlainText.replaceAll( "\n", " " );
1120  mpEditEngine->SetPaperSize( maEdEngSize );
1121 
1122  /* #i60296# If string contains mixed script types, the space character
1123  U+0020 may be drawn with a wrong width (from non-fixed-width Asian or
1124  Complex font). Now we draw every non-space portion separately. */
1125  sal_Int32 nCharIxInt {aPlainText.isEmpty() ? -1 : 0};
1126  while (nCharIxInt>=0)
1127  {
1128  sal_Int32 nBeginIx = nCharIxInt;
1129  const OUString aToken = aPlainText.getToken( 0, ' ', nCharIxInt );
1130  if( !aToken.isEmpty() )
1131  {
1132  sal_Int32 nX = rPos.X() + GetCharWidth() * nBeginIx;
1133  mpEditEngine->SetTextCurrentDefaults( aToken );
1134  mpEditEngine->Draw(*mpBackgrDev, Point(nX, rPos.Y()));
1135  }
1136  }
1137 
1138  sal_Int32 nCharIx = 0;
1139  while( (nCharIx = rText.indexOf( '\t', nCharIx )) != -1 )
1140  {
1141  sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
1142  sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
1143  sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
1144  Color aColor( maTextColor );
1145  mpBackgrDev->SetLineColor( aColor );
1146  mpBackgrDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
1147  mpBackgrDev->DrawLine( Point( nX2 - 2, nY - 2 ), Point( nX2, nY ) );
1148  mpBackgrDev->DrawLine( Point( nX2 - 2, nY + 2 ), Point( nX2, nY ) );
1149  ++nCharIx;
1150  }
1151  nCharIx = 0;
1152  while( (nCharIx = rText.indexOf( '\n', nCharIx )) != -1 )
1153  {
1154  sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
1155  sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
1156  sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
1157  Color aColor( maTextColor );
1158  mpBackgrDev->SetLineColor( aColor );
1159  mpBackgrDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
1160  mpBackgrDev->DrawLine( Point( nX1 + 2, nY - 2 ), Point( nX1, nY ) );
1161  mpBackgrDev->DrawLine( Point( nX1 + 2, nY + 2 ), Point( nX1, nY ) );
1162  mpBackgrDev->DrawLine( Point( nX2, nY - 2 ), Point( nX2, nY ) );
1163  ++nCharIx;
1164  }
1165 }
1166 
1168 {
1170  {
1171  sal_Int32 nY = GetY( mnFirstImpLine );
1172  sal_Int32 nX = std::min( GetColumnX( GetLastVisColumn() + 1 ), GetLastX() );
1174  mpBackgrDev->DrawLine( Point( GetFirstX() + 1, nY ), Point( nX, nY ) );
1175  }
1176 }
1177 
1178 void ScCsvGrid::ImplDrawColumnBackgr( sal_uInt32 nColIndex )
1179 {
1180  if( !IsVisibleColumn( nColIndex ) )
1181  return;
1182 
1183  ImplSetColumnClipRegion( *mpBackgrDev, nColIndex );
1184 
1185  // grid
1188  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1189  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1190  sal_Int32 nY2 = GetY( GetLastVisLine() + 1 );
1191  sal_Int32 nHdrHt = GetHdrHeight();
1192  tools::Rectangle aRect( nX1, nHdrHt, nX2, nY2 );
1193  mpBackgrDev->DrawRect( aRect );
1195  mpBackgrDev->DrawGrid( aRect, Size( 1, GetLineHeight() ), DrawGridFlags::HorzLines );
1196  mpBackgrDev->DrawLine( Point( nX2, nHdrHt ), Point( nX2, nY2 ) );
1197  ImplDrawFirstLineSep( true );
1198 
1199  // cell texts
1200  mpEditEngine->SetDefaultItem( SvxColorItem( maTextColor, EE_CHAR_COLOR ) );
1201  size_t nLineCount = ::std::min( static_cast< size_t >( GetLastVisLine() - GetFirstVisLine() + 1 ), maTexts.size() );
1202  // #i67432# cut string to avoid edit engine performance problems with very large strings
1203  sal_Int32 nFirstVisPos = ::std::max( GetColumnPos( nColIndex ), GetFirstVisPos() );
1204  sal_Int32 nLastVisPos = ::std::min( GetColumnPos( nColIndex + 1 ), GetLastVisPos() );
1205  sal_Int32 nStrPos = nFirstVisPos - GetColumnPos( nColIndex );
1206  sal_Int32 nStrLen = nLastVisPos - nFirstVisPos + 1;
1207  sal_Int32 nStrX = GetX( nFirstVisPos );
1208  for( size_t nLine = 0; nLine < nLineCount; ++nLine )
1209  {
1210  std::vector<OUString>& rStrVec = maTexts[ nLine ];
1211  if( (nColIndex < rStrVec.size()) && (rStrVec[ nColIndex ].getLength() > nStrPos) )
1212  {
1213  const OUString& rStr = rStrVec[ nColIndex ];
1214  OUString aText = rStr.copy( nStrPos, ::std::min( nStrLen, rStr.getLength() - nStrPos) );
1215  ImplDrawCellText( Point( nStrX, GetY( GetFirstVisLine() + nLine ) ), aText );
1216  }
1217  }
1218 
1219  // header
1221 
1223 }
1224 
1226 {
1229  Point aPoint( GetHdrX(), 0 );
1230  tools::Rectangle aRect( aPoint, Size( GetHdrWidth() + 1, GetHeight() ) );
1231  mpBackgrDev->DrawRect( aRect );
1232 
1234  aRect.SetBottom( GetY( GetLastVisLine() + 1 ) );
1235  mpBackgrDev->DrawRect( aRect );
1236 
1237  // line numbers
1241  sal_Int32 nLastLine = GetLastVisLine();
1242  for( sal_Int32 nLine = GetFirstVisLine(); nLine <= nLastLine; ++nLine )
1243  {
1244  OUString aText( OUString::number( nLine + 1 ) );
1245  sal_Int32 nX = GetHdrX() + (GetHdrWidth() - mpBackgrDev->GetTextWidth( aText )) / 2;
1246  mpBackgrDev->DrawText( Point( nX, GetY( nLine ) ), aText );
1247  }
1248 
1249  // grid
1251  if( IsRTL() )
1252  {
1253  mpBackgrDev->DrawLine( Point( 0, 0 ), Point( 0, GetHeight() - 1 ) );
1254  mpBackgrDev->DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
1255  }
1256  else
1257  mpBackgrDev->DrawLine( aRect.TopRight(), aRect.BottomRight() );
1258  aRect.SetTop( GetHdrHeight() );
1259  mpBackgrDev->DrawGrid( aRect, Size( 1, GetLineHeight() ), DrawGridFlags::HorzLines );
1260 }
1261 
1263 {
1267  Point( GetFirstX() + 1, 0 ), Size( GetWidth() - GetHdrWidth(), GetHeight() ) ) );
1268 
1269  sal_uInt32 nLastCol = GetLastVisColumn();
1270  if (nLastCol == CSV_COLUMN_INVALID)
1271  return;
1272  for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
1273  ImplDrawColumnBackgr( nColIx );
1274 
1276 }
1277 
1278 void ScCsvGrid::ImplDrawColumnSelection( sal_uInt32 nColIndex )
1279 {
1281  ImplSetColumnClipRegion( *mpGridDev, nColIndex );
1283 
1284  if( IsSelected( nColIndex ) )
1285  {
1286  sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
1287  sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
1288 
1289  // header
1290  tools::Rectangle aRect( nX1, 0, nX2, GetHdrHeight() );
1292  if( maHeaderBackColor.IsDark() )
1293  // redraw with light gray background in dark mode
1295  else
1296  {
1297  // use transparent active color
1300  }
1301 
1302  // column selection
1303  aRect = tools::Rectangle( nX1, GetHdrHeight() + 1, nX2, GetY( GetLastVisLine() + 1 ) - 1 );
1304  ImplInvertRect( *mpGridDev, aRect );
1305  }
1306 
1309 }
1310 
1312 {
1314  sal_uInt32 nLastCol = GetLastVisColumn();
1315  if (nLastCol == CSV_COLUMN_INVALID)
1316  return;
1317  for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
1318  ImplDrawColumnSelection( nColIx );
1319 }
1320 
1321 void ScCsvGrid::ImplDrawColumn( sal_uInt32 nColIndex )
1322 {
1323  ImplDrawColumnBackgr( nColIndex );
1324  ImplDrawColumnSelection( nColIndex );
1325 }
1326 
1327 void ScCsvGrid::ImplDrawHorzScrolled( sal_Int32 nOldPos )
1328 {
1329  sal_Int32 nPos = GetFirstVisPos();
1330  if( !IsValidGfx() || (nPos == nOldPos) )
1331  return;
1332  if( std::abs( nPos - nOldPos ) > GetVisPosCount() / 2 )
1333  {
1335  ImplDrawGridDev();
1336  return;
1337  }
1338 
1339  Point aSrc, aDest;
1340  sal_uInt32 nFirstColIx, nLastColIx;
1341  if( nPos < nOldPos )
1342  {
1343  aSrc = Point( GetFirstX() + 1, 0 );
1344  aDest = Point( GetFirstX() + GetCharWidth() * (nOldPos - nPos) + 1, 0 );
1345  nFirstColIx = GetColumnFromPos( nPos );
1346  nLastColIx = GetColumnFromPos( nOldPos );
1347  }
1348  else
1349  {
1350  aSrc = Point( GetFirstX() + GetCharWidth() * (nPos - nOldPos) + 1, 0 );
1351  aDest = Point( GetFirstX() + 1, 0 );
1352  nFirstColIx = GetColumnFromPos( std::min( nOldPos + GetVisPosCount(), GetPosCount() ) - 1 );
1353  nLastColIx = GetColumnFromPos( std::min( nPos + GetVisPosCount(), GetPosCount() ) - 1 );
1354  }
1355 
1356  ImplInvertCursor( GetRulerCursorPos() + (nPos - nOldPos) );
1357  tools::Rectangle aRectangle( GetFirstX(), 0, GetLastX(), GetHeight() - 1 );
1358  vcl::Region aClipReg( aRectangle );
1359  mpBackgrDev->SetClipRegion( aClipReg );
1360  mpBackgrDev->CopyArea( aDest, aSrc, maWinSize );
1362  mpGridDev->SetClipRegion( aClipReg );
1363  mpGridDev->CopyArea( aDest, aSrc, maWinSize );
1366 
1367  for( sal_uInt32 nColIx = nFirstColIx; nColIx <= nLastColIx; ++nColIx )
1368  ImplDrawColumn( nColIx );
1369 
1370  sal_Int32 nLastX = GetX( GetPosCount() ) + 1;
1371  if( nLastX <= GetLastX() )
1372  {
1373  tools::Rectangle aRect( nLastX, 0, GetLastX(), GetHeight() - 1 );
1376  mpBackgrDev->DrawRect( aRect );
1379  mpGridDev->DrawRect( aRect );
1380  }
1381 }
1382 
1383 void ScCsvGrid::ImplInvertCursor( sal_Int32 nPos )
1384 {
1385  if( IsVisibleSplitPos( nPos ) )
1386  {
1387  sal_Int32 nX = GetX( nPos ) - 1;
1388  tools::Rectangle aRect( Point( nX, 0 ), Size( 3, GetHdrHeight() ) );
1389  ImplInvertRect( *mpGridDev, aRect );
1390  aRect.SetTop( GetHdrHeight() + 1 );
1391  aRect.SetBottom( GetY( GetLastVisLine() + 1 ) );
1392  ImplInvertRect( *mpGridDev, aRect );
1393  }
1394 }
1395 
1397 {
1398  auto nColIndex = GetFocusColumn();
1399  if( HasFocus() && IsVisibleColumn( nColIndex ) )
1400  {
1401  sal_Int32 nX1 = std::max( GetColumnX( nColIndex ), GetFirstX() ) + 1;
1402  sal_Int32 nX2 = std::min( GetColumnX( nColIndex + 1 ) - sal_Int32( 1 ), GetLastX() );
1403  sal_Int32 nY2 = std::min( GetY( GetLastVisLine() + 1 ), GetHeight() ) - 1;
1404  return tools::Rectangle( nX1, 0, nX2, nY2 );
1405  }
1407 }
1408 
1409 // accessibility ==============================================================
1410 
1411 css::uno::Reference<css::accessibility::XAccessible> ScCsvGrid::CreateAccessible()
1412 {
1414  mxAccessible = xRef;
1415  return xRef;
1416 }
1417 
1418 /* 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:556
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:335
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:890
virtual bool Command(const CommandEvent &rCEvt) override
Definition: csvgrid.cxx:1000
void SetFontSize(const Size &)
SAL_DLLPRIVATE void ImplDrawGridDev()
Draws all columns with selection and cursor to maGridDev.
Definition: csvgrid.cxx:1311
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:1116
::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:442
constexpr sal_uInt16 KEY_MOD1
bool IsValidColumn(sal_uInt32 nColIndex) const
Returns true, if nColIndex points to an existing column.
Definition: csvgrid.cxx:452
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:495
#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:141
const ScCsvLayoutData & GetLayoutData() const
Returns a reference to the current layout data.
Definition: csvcontrol.hxx:295
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
OUString GetCellText(sal_uInt32 nColIndex, sal_Int32 nLine) const
Returns the text of the specified cell.
Definition: csvgrid.cxx:853
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:349
bool Contains(const Point &rPOINT) const
std::unique_ptr< sal_Int32[]> pData
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
void SetTypeNames(std::vector< OUString > &&rTypeNames)
Sets new UI data type names.
Definition: csvgrid.cxx:536
sal_uInt32 GetColumnFromPos(sal_Int32 nPos) const
Returns column index from position.
Definition: csvgrid.cxx:476
sal_uInt32 GetLastVisColumn() const
Returns the index of the last visible column.
Definition: csvgrid.cxx:447
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:310
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:48
SAL_DLLPRIVATE void MoveCursorRel(ScMoveMode eDir)
Moves column cursor to the given direction.
Definition: csvgrid.cxx:712
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
Definition: csvgrid.cxx:1065
Accessible class representing the CSV grid control.
void ApplyLayout(const ScCsvLayoutData &rOldData)
Apply current layout data to the grid control.
Definition: csvgrid.cxx:169
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:1396
void MoveSplit(sal_Int32 nPos, sal_Int32 nNewPos)
Inserts a new or removes an existing split.
Definition: csvgrid.cxx:348
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:213
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:1096
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
void RemoveAllSplits()
Removes all splits.
Definition: csvgrid.cxx:376
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:1327
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:580
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:1321
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
Size const & GetOutputSizePixel() const
SAL_DLLPRIVATE void ImplDrawColumnBackgr(sal_uInt32 nColIndex)
Draws the column with index nColIndex to maBackgrDev.
Definition: csvgrid.cxx:1178
constexpr sal_uInt16 KEY_9
void ToggleSelect(sal_uInt32 nColIndex)
Toggles selection of the specified column.
Definition: csvgrid.cxx:657
#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:689
SAL_DLLPRIVATE bool ImplInsertSplit(sal_Int32 nPos)
Inserts a split and adjusts column data.
Definition: csvgrid.cxx:399
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:1167
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:154
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:1089
EditEngine * GetEditEngine()
Returns a pointer to the used edit engine.
Definition: csvgrid.cxx:1084
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:414
void Select(sal_uInt32 nColIndex, bool bSelect=true)
Selects or deselects the specified column.
Definition: csvgrid.cxx:643
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:241
void InsertSplit(sal_Int32 nPos)
Inserts a split.
Definition: csvgrid.cxx:320
constexpr sal_uInt16 KEYGROUP_CURSOR
sal_Int32 mnType
Definition: csvgrid.hxx:43
virtual void GetFocus() override
Definition: csvgrid.cxx:877
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:615
void DrawRect(const tools::Rectangle &rRect)
#define SAL_N_ELEMENTS(arr)
sal_uInt32 mnMTCurrCol
Index of most recently selected column.
Definition: csvgrid.hxx:90
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:763
virtual void ConfigurationChanged(::utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: csvgrid.cxx:1057
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:525
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:596
#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:74
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:1047
virtual ~ScCsvGrid() override
Definition: csvgrid.cxx:121
sal_Int32 mnType
OUString GetColumnTypeName(sal_uInt32 nColIndex) const
Returns the UI type name of the specified column.
Definition: csvgrid.cxx:550
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:457
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:249
tools::Long GetNotchDelta() const
void Clear()
Removes all elements from the vector.
Definition: csvsplits.cxx:61
void SetColumnStates(ScCsvColStateVec &&rColStates)
Sets all column states to the values in the passed vector.
Definition: csvgrid.cxx:486
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:947
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:564
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:1383
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
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:469
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:1278
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:824
sal_Int32 GetColumnWidth(sal_uInt32 nColIndex) const
Returns the character width of the column with the specified index.
Definition: csvgrid.cxx:481
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:868
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: csvgrid.cxx:918
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
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:662
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:1411
sal_uInt32 GetNextSelected(sal_uInt32 nFromIndex) const
Returns index of the first selected column really after nFromIndex.
Definition: csvgrid.cxx:634
bool IsShift() const
weld::DrawingArea * GetDrawingArea() const
sal_Int32 mnIndex
Definition: csvcontrol.hxx:65
void Init()
Finishes initialization.
Definition: csvgrid.cxx:131
SAL_DLLPRIVATE void ImplDrawRowHeaders()
Draws the row headers column to maBackgrDev.
Definition: csvgrid.cxx:1225
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:746
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:884
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:924
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:509
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:464
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:222
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:1262
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
SAL_DLLPRIVATE void ImplClearSelection()
Clears the entire selection without notify.
Definition: csvgrid.cxx:740
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:629
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:694
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:500
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:429
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:624
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:1810
::std::vector< ScCsvExpData > ScCsvExpDataVec
Definition: csvcontrol.hxx:73
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: csvgrid.cxx:95
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:1070
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:545
SAL_DLLPRIVATE void InitFonts()
Initializes all font settings.
Definition: csvgrid.cxx:261
Color maSelectColor
Text color for headers.
Definition: csvgrid.hxx:74
bool m_bDetectedRangeSegmentation false
void SetSplits(const ScCsvSplits &rSplits)
Removes all splits and inserts the splits from rSplits.
Definition: csvgrid.cxx:385
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