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 
42 #include <editeng/colritem.hxx>
43 #include <editeng/fhgtitem.hxx>
44 #include <editeng/fontitem.hxx>
45 #include <editeng/wghtitem.hxx>
46 #include <editeng/postitem.hxx>
47 #include <editeng/langitem.hxx>
48 #include <svl/itemset.hxx>
49 #include <editutil.hxx>
50 // *** edit engine ***
51 
52 namespace {
53 
54 struct Func_SetType
55 {
56  sal_Int32 mnType;
57  explicit Func_SetType( sal_Int32 nType ) : mnType( nType ) {}
58  void operator()( ScCsvColState& rState ) const
59  { rState.mnType = mnType; }
60 };
61 
62 struct Func_Select
63 {
64  bool mbSelect;
65  explicit Func_Select( bool bSelect ) : mbSelect( bSelect ) {}
66  void operator()( ScCsvColState& rState ) const
67  { rState.Select( mbSelect ); }
68 };
69 
70 }
71 
72 ScCsvGrid::ScCsvGrid(const ScCsvLayoutData& rData, std::unique_ptr<weld::Menu> xPopup, ScCsvTableBox* pTableBox)
73  : ScCsvControl(rData)
74  , mpTableBox(pTableBox)
75  , mpBackgrDev( VclPtr<VirtualDevice>::Create() )
76  , mpGridDev( VclPtr<VirtualDevice>::Create() )
77  , mxPopup(std::move(xPopup))
78  , mpColorConfig( nullptr )
79  , mpEditEngine( new ScEditEngineDefaulter( EditEngine::CreatePool(), true ) )
80  , maColStates( 1 )
81  , maTypeNames( 1 )
82  , mnFirstImpLine( 0 )
83  , mnRecentSelCol( CSV_COLUMN_INVALID )
84  , mnMTCurrCol( SAL_MAX_UINT32 )
85  , mbTracking( false )
86  , mbMTSelecting( false )
87 {
88  mpEditEngine->SetRefDevice( mpBackgrDev.get() );
89  mpEditEngine->SetRefMapMode( MapMode( MapUnit::MapPixel ) );
90  maEdEngSize = mpEditEngine->GetPaperSize();
91 }
92 
94 {
95  OutputDevice& rRefDevice = pDrawingArea->get_ref_device();
97 
98  // expand the point size of the desired font to the equivalent pixel size
99  if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice()))
100  {
101  pDefaultDevice->SetPointFont(rRefDevice, maHeaderFont);
102  maHeaderFont = rRefDevice.GetFont();
103  }
104 
105  // Because this is an always LeftToRight layout widget the initial size of
106  // this widget needs to be smaller than the size of the parent scrolling
107  // window (ScCsvTableBox ctor) because in RTL mode the alignment is against
108  // the right edge of the parent, and if larger than the scrolling window
109  // the left edge will be lost. If this widget is smaller than the scrolling
110  // window it is stretched to fit the parent and the problem doesn't arise.
111  Size aInitialSize(10, 10);
112  ScCsvControl::SetDrawingArea(pDrawingArea);
113  pDrawingArea->set_size_request(aInitialSize.Width(), aInitialSize.Height());
114  SetOutputSizePixel(aInitialSize);
115 
116  EnableRTL( false ); // RTL
117 
118  InitFonts();
119  ImplClearSplits();
120 }
121 
123 {
124  OSL_ENSURE(mpColorConfig, "the object hasn't been initialized properly");
125  if (mpColorConfig)
126  mpColorConfig->RemoveListener(this);
129 }
130 
131 void
133 {
134  OSL_PRECOND(!mpColorConfig, "the object has already been initialized");
135  mpColorConfig = &SC_MOD()->GetColorConfig();
136  InitColors();
137  mpColorConfig->AddListener(this);
138 }
139 
140 // common grid handling -------------------------------------------------------
141 
143 {
144  DisableRepaint();
145  OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
146  rRefDevice.SetFont(maMonoFont);
147  Execute(CSVCMD_SETCHARWIDTH, rRefDevice.GetTextWidth(OUString('X')));
148  Execute(CSVCMD_SETLINEHEIGHT, rRefDevice.GetTextHeight() + 1);
149  rRefDevice.SetFont(maHeaderFont);
150  Execute(CSVCMD_SETHDRHEIGHT, rRefDevice.GetTextHeight() + 1);
151  UpdateOffsetX();
152  EnableRepaint();
153 }
154 
156 {
157  sal_Int32 nLastLine = GetLastVisLine() + 1;
158  sal_Int32 nDigits = 2;
159  for (;;)
160  {
161  nLastLine /= 10;
162  if (!nLastLine)
163  break;
164  ++nDigits;
165  }
166  nDigits = std::max( nDigits, sal_Int32( 3 ) );
167  Execute(CSVCMD_SETHDRWIDTH, GetDrawingArea()->get_approximate_digit_width() * nDigits);
168 }
169 
171 {
172  ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData );
173  if( nDiff == ScCsvDiff::Equal ) return;
174 
175  DisableRepaint();
176 
177  if( nDiff & ScCsvDiff::RulerCursor )
178  {
179  ImplInvertCursor( rOldData.mnPosCursor );
181  }
182 
183  if( nDiff & ScCsvDiff::PosCount )
184  {
185  if( GetPosCount() < rOldData.mnPosCount )
186  {
187  SelectAll( false );
189  }
190  else
191  maSplits.Remove( rOldData.mnPosCount );
193  maColStates.resize( maSplits.Count() - 1 );
194  }
195 
196  if( nDiff & ScCsvDiff::LineOffset )
197  {
199  UpdateOffsetX();
200  }
201 
203  if( nHVDiff == ScCsvDiff::PosOffset )
204  ImplDrawHorzScrolled( rOldData.mnPosOffset );
205  else if( nHVDiff != ScCsvDiff::Equal )
206  InvalidateGfx();
207 
208  EnableRepaint();
209 
210  if( nDiff & (ScCsvDiff::PosOffset | ScCsvDiff::LineOffset) )
212 }
213 
214 void ScCsvGrid::SetFirstImportedLine( sal_Int32 nLine )
215 {
216  ImplDrawFirstLineSep( false );
217  mnFirstImpLine = nLine;
218  ImplDrawFirstLineSep( true );
219  ImplDrawGridDev();
220  Repaint();
221 }
222 
223 sal_Int32 ScCsvGrid::GetNoScrollCol( sal_Int32 nPos ) const
224 {
225  sal_Int32 nNewPos = nPos;
226  if( nNewPos != CSV_POS_INVALID )
227  {
228  if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST )
229  {
230  sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0;
231  nNewPos = GetFirstVisPos() + nScroll;
232  }
233  else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1 )
234  {
235  sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0;
236  nNewPos = GetLastVisPos() - nScroll - 1;
237  }
238  }
239  return nNewPos;
240 }
241 
243 {
244  OSL_PRECOND(mpColorConfig, "the object hasn't been initialized properly");
245  if ( !mpColorConfig )
246  return;
252 
257  maSelectColor = rSett.GetActiveColor();
258 
259  InvalidateGfx();
260 }
261 
263 {
264  maMonoFont = OutputDevice::GetDefaultFont( DefaultFontType::FIXED, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::NONE );
266 
267  /* *** Set edit engine defaults ***
268  maMonoFont for Latin script, smaller default font for Asian and Complex script. */
269 
270  // get default fonts
271  SvxFontItem aLatinItem( EE_CHAR_FONTINFO );
272  SvxFontItem aAsianItem( EE_CHAR_FONTINFO_CJK );
273  SvxFontItem aComplexItem( EE_CHAR_FONTINFO_CTL );
274  ::GetDefaultFonts( aLatinItem, aAsianItem, aComplexItem );
275 
276  // create item set for defaults
277  SfxItemSet aDefSet( mpEditEngine->GetEmptyItemSet() );
279  aDefSet.Put( aAsianItem );
280  aDefSet.Put( aComplexItem );
281 
282  // set Asian/Complex font size to height of character in Latin font
283  sal_uLong nFontHt = static_cast< sal_uLong >( maMonoFont.GetFontSize().Height() );
284  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
285  aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
286 
287  // copy other items from default font
288  const SfxPoolItem& rWeightItem = aDefSet.Get( EE_CHAR_WEIGHT );
289  std::unique_ptr<SfxPoolItem> pNewItem(rWeightItem.Clone());
290  pNewItem->SetWhich(EE_CHAR_WEIGHT_CJK);
291  aDefSet.Put( *pNewItem );
292  pNewItem->SetWhich(EE_CHAR_WEIGHT_CTL);
293  aDefSet.Put( *pNewItem );
294  const SfxPoolItem& rItalicItem = aDefSet.Get( EE_CHAR_ITALIC );
295  pNewItem.reset(rItalicItem.Clone());
296  pNewItem->SetWhich(EE_CHAR_ITALIC_CJK);
297  aDefSet.Put( *pNewItem );
298  pNewItem->SetWhich(EE_CHAR_ITALIC_CTL);
299  aDefSet.Put( *pNewItem );
300  const SfxPoolItem& rLangItem = aDefSet.Get( EE_CHAR_LANGUAGE );
301  pNewItem.reset(rLangItem.Clone());
302  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CJK);
303  aDefSet.Put( *pNewItem );
304  pNewItem->SetWhich(EE_CHAR_LANGUAGE_CTL);
305  aDefSet.Put( *pNewItem );
306 
307  mpEditEngine->SetDefaults( aDefSet );
308  InvalidateGfx();
309 }
310 
312 {
316  InvalidateGfx();
317 }
318 
319 // split handling -------------------------------------------------------------
320 
321 void ScCsvGrid::InsertSplit( sal_Int32 nPos )
322 {
323  if( ImplInsertSplit( nPos ) )
324  {
325  DisableRepaint();
328  sal_uInt32 nColIx = GetColumnFromPos( nPos );
329  ImplDrawColumn( nColIx - 1 );
330  ImplDrawColumn( nColIx );
331  ValidateGfx(); // performance: do not redraw all columns
332  EnableRepaint();
333  }
334 }
335 
336 void ScCsvGrid::RemoveSplit( sal_Int32 nPos )
337 {
338  if( ImplRemoveSplit( nPos ) )
339  {
340  DisableRepaint();
343  ImplDrawColumn( GetColumnFromPos( nPos ) );
344  ValidateGfx(); // performance: do not redraw all columns
345  EnableRepaint();
346  }
347 }
348 
349 void ScCsvGrid::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos )
350 {
351  sal_uInt32 nColIx = GetColumnFromPos( nPos );
352  if( nColIx == CSV_COLUMN_INVALID )
353  return;
354 
355  DisableRepaint();
356  if( (GetColumnPos( nColIx - 1 ) < nNewPos) && (nNewPos < GetColumnPos( nColIx + 1 )) )
357  {
358  // move a split in the range between 2 others -> keep selection state of both columns
359  maSplits.Remove( nPos );
360  maSplits.Insert( nNewPos );
362  ImplDrawColumn( nColIx - 1 );
363  ImplDrawColumn( nColIx );
364  ValidateGfx(); // performance: do not redraw all columns
365  AccSendTableUpdateEvent( nColIx - 1, nColIx );
366  }
367  else
368  {
369  ImplRemoveSplit( nPos );
370  ImplInsertSplit( nNewPos );
373  }
374  EnableRepaint();
375 }
376 
378 {
379  DisableRepaint();
380  ImplClearSplits();
383  EnableRepaint();
384 }
385 
386 void ScCsvGrid::SetSplits( const ScCsvSplits& rSplits )
387 {
388  DisableRepaint();
389  ImplClearSplits();
390  sal_uInt32 nCount = rSplits.Count();
391  for( sal_uInt32 nIx = 0; nIx < nCount; ++nIx )
392  maSplits.Insert( rSplits[ nIx ] );
393  maColStates.clear();
394  maColStates.resize( maSplits.Count() - 1 );
397  EnableRepaint();
398 }
399 
400 bool ScCsvGrid::ImplInsertSplit( sal_Int32 nPos )
401 {
402  sal_uInt32 nColIx = GetColumnFromPos( nPos );
403  bool bRet = (nColIx < GetColumnCount()) && maSplits.Insert( nPos );
404  if( bRet )
405  {
406  ScCsvColState aState( GetColumnType( nColIx ) );
407  aState.Select( IsSelected( nColIx ) && IsSelected( nColIx + 1 ) );
408  maColStates.insert( maColStates.begin() + nColIx + 1, aState );
409  AccSendInsertColumnEvent( nColIx + 1, nColIx + 1 );
410  AccSendTableUpdateEvent( nColIx, nColIx );
411  }
412  return bRet;
413 }
414 
415 bool ScCsvGrid::ImplRemoveSplit( sal_Int32 nPos )
416 {
417  bool bRet = maSplits.Remove( nPos );
418  if( bRet )
419  {
420  sal_uInt32 nColIx = GetColumnFromPos( nPos );
421  bool bSel = IsSelected( nColIx ) || IsSelected( nColIx + 1 );
422  maColStates.erase( maColStates.begin() + nColIx + 1 );
423  maColStates[ nColIx ].Select( bSel );
424  AccSendRemoveColumnEvent( nColIx + 1, nColIx + 1 );
425  AccSendTableUpdateEvent( nColIx, nColIx );
426  }
427  return bRet;
428 }
429 
431 {
432  sal_uInt32 nColumns = GetColumnCount();
433  maSplits.Clear();
434  maSplits.Insert( 0 );
436  maColStates.resize( 1 );
437  InvalidateGfx();
438  AccSendRemoveColumnEvent( 1, nColumns - 1 );
439 }
440 
441 // columns/column types -------------------------------------------------------
442 
444 {
445  return GetColumnFromPos( GetFirstVisPos() );
446 }
447 
448 sal_uInt32 ScCsvGrid::GetLastVisColumn() const
449 {
450  return GetColumnFromPos( std::min( GetLastVisPos(), GetPosCount() ) - 1 );
451 }
452 
453 bool ScCsvGrid::IsValidColumn( sal_uInt32 nColIndex ) const
454 {
455  return nColIndex < GetColumnCount();
456 }
457 
458 bool ScCsvGrid::IsVisibleColumn( sal_uInt32 nColIndex ) const
459 {
460  return IsValidColumn( nColIndex ) &&
461  (GetColumnPos( nColIndex ) < GetLastVisPos()) &&
462  (GetFirstVisPos() < GetColumnPos( nColIndex + 1 ));
463 }
464 
465 sal_Int32 ScCsvGrid::GetColumnX( sal_uInt32 nColIndex ) const
466 {
467  return GetX( GetColumnPos( nColIndex ) );
468 }
469 
470 sal_uInt32 ScCsvGrid::GetColumnFromX( sal_Int32 nX ) const
471 {
472  sal_Int32 nPos = (nX - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
473  return ((GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos())) ?
475 }
476 
477 sal_uInt32 ScCsvGrid::GetColumnFromPos( sal_Int32 nPos ) const
478 {
479  return maSplits.UpperBound( nPos );
480 }
481 
482 sal_Int32 ScCsvGrid::GetColumnWidth( sal_uInt32 nColIndex ) const
483 {
484  return IsValidColumn( nColIndex ) ? (GetColumnPos( nColIndex + 1 ) - GetColumnPos( nColIndex )) : 0;
485 }
486 
488 {
489  maColStates = rStates;
490  maColStates.resize( maSplits.Count() - 1 );
494 }
495 
496 sal_Int32 ScCsvGrid::GetColumnType( sal_uInt32 nColIndex ) const
497 {
498  return IsValidColumn( nColIndex ) ? maColStates[ nColIndex ].mnType : CSV_TYPE_NOSELECTION;
499 }
500 
501 void ScCsvGrid::SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType )
502 {
503  if( IsValidColumn( nColIndex ) )
504  {
505  maColStates[ nColIndex ].mnType = nColType;
506  AccSendTableUpdateEvent( nColIndex, nColIndex, false );
507  }
508 }
509 
511 {
512  sal_uInt32 nColIx = GetFirstSelected();
513  if( nColIx == CSV_COLUMN_INVALID )
514  return CSV_TYPE_NOSELECTION;
515 
516  sal_Int32 nType = GetColumnType( nColIx );
517  while( (nColIx != CSV_COLUMN_INVALID) && (nType != CSV_TYPE_MULTI) )
518  {
519  if( nType != GetColumnType( nColIx ) )
520  nType = CSV_TYPE_MULTI;
521  nColIx = GetNextSelected( nColIx );
522  }
523  return nType;
524 }
525 
527 {
528  if( (nType != CSV_TYPE_MULTI) && (nType != CSV_TYPE_NOSELECTION) )
529  {
530  for( sal_uInt32 nColIx = GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = GetNextSelected( nColIx ) )
531  SetColumnType( nColIx, nType );
532  Repaint( true );
534  }
535 }
536 
537 void ScCsvGrid::SetTypeNames( const std::vector<OUString>& rTypeNames )
538 {
539  OSL_ENSURE( !rTypeNames.empty(), "ScCsvGrid::SetTypeNames - vector is empty" );
540  maTypeNames = rTypeNames;
541  Repaint( true );
542 
543  mxPopup->clear();
544  sal_uInt32 nCount = maTypeNames.size();
545  for (sal_uInt32 nIx = 0; nIx < nCount; ++nIx)
546  mxPopup->append(OUString::number(nIx), maTypeNames[nIx]);
547 
548  ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) );
549 }
550 
551 const OUString& ScCsvGrid::GetColumnTypeName( sal_uInt32 nColIndex ) const
552 {
553  sal_uInt32 nTypeIx = static_cast< sal_uInt32 >( GetColumnType( nColIndex ) );
554  return (nTypeIx < maTypeNames.size()) ? maTypeNames[ nTypeIx ] : EMPTY_OUSTRING;
555 }
556 
557 static sal_uInt8 lcl_GetExtColumnType( sal_Int32 nIntType )
558 {
559  static const sal_uInt8 pExtTypes[] =
561  static const sal_Int32 nExtTypeCount = SAL_N_ELEMENTS(pExtTypes);
562  return pExtTypes[ ((0 <= nIntType) && (nIntType < nExtTypeCount)) ? nIntType : 0 ];
563 }
564 
566 {
567  sal_uInt32 nCount = GetColumnCount();
568  ScCsvExpDataVec aDataVec;
569 
570  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
571  {
572  if( GetColumnType( nColIx ) != CSV_TYPE_DEFAULT )
573  // 1-based column index
574  aDataVec.emplace_back(
575  static_cast< sal_Int32 >( nColIx + 1 ),
576  lcl_GetExtColumnType( GetColumnType( nColIx ) ) );
577  }
578  rOptions.SetColumnInfo( aDataVec );
579 }
580 
582 {
583  sal_uInt32 nCount = std::min( GetColumnCount(), static_cast<sal_uInt32>(MAXCOLCOUNT) );
584  ScCsvExpDataVec aDataVec( nCount + 1 );
585 
586  for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
587  {
588  ScCsvExpData& rData = aDataVec[ nColIx ];
589  rData.mnIndex = GetColumnPos( nColIx );
590  rData.mnType = lcl_GetExtColumnType( GetColumnType( nColIx ) );
591  }
592  aDataVec[ nCount ].mnIndex = SAL_MAX_INT32;
593  aDataVec[ nCount ].mnType = SC_COL_SKIP;
594  rOptions.SetColumnInfo( aDataVec );
595 }
596 
598 {
599  sal_Int32 nLine = GetFirstVisLine();
600  switch( eDir )
601  {
602  case MOVE_PREV: --nLine; break;
603  case MOVE_NEXT: ++nLine; break;
604  case MOVE_FIRST: nLine = 0; break;
605  case MOVE_LAST: nLine = GetMaxLineOffset(); break;
606  case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 2; break;
607  case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 2; break;
608  default:
609  {
610  // added to avoid warnings
611  }
612  }
613  Execute( CSVCMD_SETLINEOFFSET, nLine );
614 }
615 
616 void ScCsvGrid::ExecutePopup( const Point& rPos )
617 {
618  OString sItemId = mxPopup->popup_at_rect(GetDrawingArea(), tools::Rectangle(rPos, Size(1, 1)));
619  if (!sItemId.isEmpty()) // empty = cancelled
620  Execute(CSVCMD_SETCOLUMNTYPE, sItemId.toInt32());
621 }
622 
623 // selection handling ---------------------------------------------------------
624 
625 bool ScCsvGrid::IsSelected( sal_uInt32 nColIndex ) const
626 {
627  return IsValidColumn( nColIndex ) && maColStates[ nColIndex ].IsSelected();
628 }
629 
630 sal_uInt32 ScCsvGrid::GetFirstSelected() const
631 {
632  return IsSelected( 0 ) ? 0 : GetNextSelected( 0 );
633 }
634 
635 sal_uInt32 ScCsvGrid::GetNextSelected( sal_uInt32 nFromIndex ) const
636 {
637  sal_uInt32 nColCount = GetColumnCount();
638  for( sal_uInt32 nColIx = nFromIndex + 1; nColIx < nColCount; ++nColIx )
639  if( IsSelected( nColIx ) )
640  return nColIx;
641  return CSV_COLUMN_INVALID;
642 }
643 
644 void ScCsvGrid::Select( sal_uInt32 nColIndex, bool bSelect )
645 {
646  if( IsValidColumn( nColIndex ) )
647  {
648  maColStates[ nColIndex ].Select( bSelect );
649  ImplDrawColumnSelection( nColIndex );
650  Repaint();
652  if( bSelect )
653  mnRecentSelCol = nColIndex;
655  }
656 }
657 
658 void ScCsvGrid::ToggleSelect( sal_uInt32 nColIndex )
659 {
660  Select( nColIndex, !IsSelected( nColIndex ) );
661 }
662 
663 void ScCsvGrid::SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect )
664 {
665  if( nColIndex1 == CSV_COLUMN_INVALID )
666  Select( nColIndex2 );
667  else if( nColIndex2 == CSV_COLUMN_INVALID )
668  Select( nColIndex1 );
669  else if( nColIndex1 > nColIndex2 )
670  {
671  SelectRange( nColIndex2, nColIndex1, bSelect );
672  if( bSelect )
673  mnRecentSelCol = nColIndex1;
674  }
675  else if( IsValidColumn( nColIndex1 ) && IsValidColumn( nColIndex2 ) )
676  {
677  for( sal_uInt32 nColIx = nColIndex1; nColIx <= nColIndex2; ++nColIx )
678  {
679  maColStates[ nColIx ].Select( bSelect );
680  ImplDrawColumnSelection( nColIx );
681  }
682  Repaint();
684  if( bSelect )
685  mnRecentSelCol = nColIndex1;
687  }
688 }
689 
690 void ScCsvGrid::SelectAll( bool bSelect )
691 {
692  SelectRange( 0, GetColumnCount() - 1, bSelect );
693 }
694 
695 void ScCsvGrid::MoveCursor( sal_uInt32 nColIndex )
696 {
697  DisableRepaint();
698  if( IsValidColumn( nColIndex ) )
699  {
700  sal_Int32 nPosBeg = GetColumnPos( nColIndex );
701  sal_Int32 nPosEnd = GetColumnPos( nColIndex + 1 );
702  sal_Int32 nMinPos = std::max( nPosBeg - CSV_SCROLL_DIST, sal_Int32( 0 ) );
703  sal_Int32 nMaxPos = std::min( nPosEnd - GetVisPosCount() + CSV_SCROLL_DIST + sal_Int32( 1 ), nMinPos );
704  if( nPosBeg - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
705  Execute( CSVCMD_SETPOSOFFSET, nMinPos );
706  else if( nPosEnd + CSV_SCROLL_DIST >= GetLastVisPos() )
707  Execute( CSVCMD_SETPOSOFFSET, nMaxPos );
708  }
709  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
710  EnableRepaint();
711 }
712 
714 {
716  return;
717 
718  switch( eDir )
719  {
720  case MOVE_FIRST:
721  MoveCursor( 0 );
722  break;
723  case MOVE_LAST:
724  MoveCursor( GetColumnCount() - 1 );
725  break;
726  case MOVE_PREV:
727  if( GetFocusColumn() > 0 )
728  MoveCursor( GetFocusColumn() - 1 );
729  break;
730  case MOVE_NEXT:
731  if( GetFocusColumn() < GetColumnCount() - 1 )
732  MoveCursor( GetFocusColumn() + 1 );
733  break;
734  default:
735  {
736  // added to avoid warnings
737  }
738  }
739 }
740 
742 {
743  ::std::for_each( maColStates.begin(), maColStates.end(), Func_Select( false ) );
744  ImplDrawGridDev();
745 }
746 
747 void ScCsvGrid::DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier )
748 {
749  if( !(nModifier & KEY_MOD1) )
751  if( nModifier & KEY_SHIFT ) // SHIFT always expands
752  SelectRange( mnRecentSelCol, nColIndex );
753  else if( !(nModifier & KEY_MOD1) ) // no SHIFT/CTRL always selects 1 column
754  Select( nColIndex );
755  else if( mbTracking ) // CTRL in tracking does not toggle
756  Select( nColIndex, mbMTSelecting );
757  else // CTRL only toggles
758  ToggleSelect( nColIndex );
759  Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
760 }
761 
762 // cell contents --------------------------------------------------------------
763 
765  sal_Int32 nLine, const OUString& rTextLine,
766  const OUString& rSepChars, sal_Unicode cTextSep, bool bMergeSep, bool bRemoveSpace )
767 {
768  if( nLine < GetFirstVisLine() ) return;
769 
770  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
771  while( maTexts.size() <= nLineIx )
772  maTexts.emplace_back( );
773  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
774  rStrVec.clear();
775 
776  // scan for separators
777  OUString aCellText;
778  const sal_Unicode* pSepChars = rSepChars.getStr();
779  const sal_Unicode* pChar = rTextLine.getStr();
780  sal_uInt32 nColIx = 0;
781 
782  while( *pChar && (nColIx < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT)) )
783  {
784  // scan for next cell text
785  bool bIsQuoted = false;
786  bool bOverflowCell = false;
787  pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText,
788  cTextSep, pSepChars, bMergeSep, bIsQuoted, bOverflowCell, bRemoveSpace );
789  /* TODO: signal overflow somewhere in UI */
790 
791  // update column width
792  sal_Int32 nWidth = std::max( CSV_MINCOLWIDTH, aCellText.getLength() + 1 );
793  if( IsValidColumn( nColIx ) )
794  {
795  // expand existing column
796  sal_Int32 nDiff = nWidth - GetColumnWidth( nColIx );
797  if( nDiff > 0 )
798  {
799  Execute( CSVCMD_SETPOSCOUNT, GetPosCount() + nDiff );
800  for( sal_uInt32 nSplitIx = GetColumnCount() - 1; nSplitIx > nColIx; --nSplitIx )
801  {
802  sal_Int32 nPos = maSplits[ nSplitIx ];
803  maSplits.Remove( nPos );
804  maSplits.Insert( nPos + nDiff );
805  }
806  }
807  }
808  else
809  {
810  // append new column
811  sal_Int32 nLastPos = GetPosCount();
812  Execute( CSVCMD_SETPOSCOUNT, nLastPos + nWidth );
813  ImplInsertSplit( nLastPos );
814  }
815 
816  if( aCellText.getLength() <= CSV_MAXSTRLEN )
817  rStrVec.push_back( aCellText );
818  else
819  rStrVec.push_back( aCellText.copy( 0, CSV_MAXSTRLEN ) );
820  ++nColIx;
821  }
822  InvalidateGfx();
823 }
824 
825 void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine )
826 {
827  if( nLine < GetFirstVisLine() ) return;
828 
829  sal_Int32 nChars = rTextLine.getLength();
830  if( nChars > GetPosCount() )
831  Execute( CSVCMD_SETPOSCOUNT, nChars );
832 
833  sal_uInt32 nLineIx = nLine - GetFirstVisLine();
834  while( maTexts.size() <= nLineIx )
835  maTexts.emplace_back( );
836 
837  std::vector<OUString>& rStrVec = maTexts[ nLineIx ];
838  rStrVec.clear();
839  sal_uInt32 nColCount = GetColumnCount();
840  sal_Int32 nStrLen = rTextLine.getLength();
841  sal_Int32 nStrIx = 0;
842  for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx )
843  {
844  sal_Int32 nColWidth = GetColumnWidth( nColIx );
845  sal_Int32 nLen = std::min( std::min( nColWidth, CSV_MAXSTRLEN ), nStrLen - nStrIx);
846  rStrVec.push_back( rTextLine.copy( nStrIx, nLen ) );
847  nStrIx = nStrIx + nColWidth;
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::max( std::min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 0 ) );
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.get(), 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.set(xRef.get());
1414  return css::uno::Reference<css::accessibility::XAccessible>(xRef.get());
1415 }
1416 
1417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCsvDiff GetDiff(const ScCsvLayoutData &rData) const
Returns differences to rData.
Definition: csvcontrol.cxx:43
Color maGridPBColor
Table grid color.
Definition: csvgrid.hxx:71
static sal_uInt8 lcl_GetExtColumnType(sal_Int32 nIntType)
Definition: csvgrid.cxx:557
Point TopLeft() const
void SetClipRegion()
long Width() const
const Color & GetActiveColor() const
const int nColCount
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
ConfigurationHints
vcl::Font maMonoFont
Font for column and row headers.
Definition: csvgrid.hxx:81
bool mbTracking
Current column of mouse tracking.
Definition: csvgrid.hxx:93
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:167
sal_Int32 mnPosOffset
Number of positions.
Definition: csvcontrol.hxx:117
void RemoveSplit(sal_Int32 nPos)
Removes a split.
Definition: csvgrid.cxx:336
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:85
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:68
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:56
Color maGridColor
Cell background color.
Definition: csvgrid.hxx:70
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:57
sal_uInt32 GetFirstVisColumn() const
Returns the index of the first visible column.
Definition: csvgrid.cxx:443
constexpr sal_uInt16 KEY_MOD1
bool IsValidColumn(sal_uInt32 nColIndex) const
Returns true, if nColIndex points to an existing column.
Definition: csvgrid.cxx:453
#define EMPTY_OUSTRING
Definition: global.hxx:214
const sal_Int32 CSV_POS_INVALID
Constant for an invalid ruler position.
Definition: csvsplits.hxx:30
SAL_DLLPRIVATE sal_Int32 GetColumnType(sal_uInt32 nColIndex) const
Returns the data type of the specified column.
Definition: csvgrid.cxx:496
#define LANGUAGE_ENGLISH_US
sal_Int32 GetPosCount() const
Returns the number of available positions.
Definition: csvcontrol.hxx:302
void UpdateLayoutData()
Updates layout data dependent from the control's state.
Definition: csvgrid.cxx:142
const ScCsvLayoutData & GetLayoutData() const
Returns a reference to the current layout data.
Definition: csvcontrol.hxx:297
std::unique_ptr< ContentProperties > pData
sal_uInt8 mnType
Index of a column.
Definition: csvcontrol.hxx:68
long Height() const
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:78
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:351
Point BottomLeft() const
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:477
sal_uInt32 GetLastVisColumn() const
Returns the index of the last visible column.
Definition: csvgrid.cxx:448
sal_uIntPtr sal_uLong
Change position/column count. [character count].
Definition: csvcontrol.hxx:168
SAL_DLLPRIVATE void InitSizeData()
Initializes all data dependent from the control's size.
Definition: csvgrid.cxx:311
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
constexpr sal_uInt16 KEY_A
Update cell texts with current split settings. [-].
Definition: csvcontrol.hxx:186
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:46
SAL_DLLPRIVATE void MoveCursorRel(ScMoveMode eDir)
Moves column cursor to the given direction.
Definition: csvgrid.cxx:713
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:170
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:269
Color maHeaderBackColor
Text color for data area.
Definition: csvgrid.hxx:74
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:349
long GetNotchDelta() const
vcl::Font maHeaderFont
For drawing cell texts.
Definition: csvgrid.hxx:80
sal_Int32 GetHdrHeight() const
Returns the height of the header line.
Definition: csvcontrol.hxx:349
void SetFirstImportedLine(sal_Int32 nLine)
Sets the number of the first imported line (for visual feedback).
Definition: csvgrid.cxx:214
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:377
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
const CommandWheelData * GetWheelData() const
const SCCOL MAXCOLCOUNT
Definition: address.hxx:64
constexpr sal_uInt16 KEY_SPACE
Change width of the header column. [width in pixel].
Definition: csvcontrol.hxx:170
VclPtr< VirtualDevice > mpGridDev
Grid background, headers, cell texts.
Definition: csvgrid.hxx:65
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:176
void FillColumnDataFix(ScAsciiOptions &rOptions) const
Fills the options object with column data for fixed width mode.
Definition: csvgrid.cxx:581
Base class for the CSV ruler and the data grid control.
Definition: csvcontrol.hxx:224
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:37
Move ruler cursor to new position. [position].
Definition: csvcontrol.hxx:180
void SetColumnStates(const ScCsvColStateVec &rColStates)
Sets all column states to the values in the passed vector.
Definition: csvgrid.cxx:487
Size const & GetOutputSizePixel() const
SAL_DLLPRIVATE void ImplDrawColumnBackgr(sal_uInt32 nColIndex)
Draws the column with index nColIndex to maBackgrDev.
Definition: csvgrid.cxx:1177
static OutputDevice * GetDefaultDevice()
constexpr sal_uInt16 KEY_9
void ToggleSelect(sal_uInt32 nColIndex)
Toggles selection of the specified column.
Definition: csvgrid.cxx:658
#define SAL_MAX_UINT32
bool mbMTSelecting
True if Mouse tracking.
Definition: csvgrid.hxx:94
Predecessor of current element in current context.
Definition: csvcontrol.hxx:84
Color maTextColor
Background color for unused area.
Definition: csvgrid.hxx:73
void SelectAll(bool bSelect=true)
Selects or deselects all columns.
Definition: csvgrid.cxx:690
SAL_DLLPRIVATE bool ImplInsertSplit(sal_Int32 nPos)
Inserts a split and adjusts column data.
Definition: csvgrid.cxx:400
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:41
sal_Int32 GetCharWidth() const
Returns the width of one character column.
Definition: csvcontrol.hxx:320
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:65
void UpdateOffsetX()
Updates X coordinate of first visible position dependent from line numbers.
Definition: csvgrid.cxx:155
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:88
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:64
SAL_DLLPRIVATE bool ImplRemoveSplit(sal_Int32 nPos)
Removes a split and adjusts column data.
Definition: csvgrid.cxx:415
void Select(sal_uInt32 nColIndex, bool bSelect=true)
Selects or deselects the specified column.
Definition: csvgrid.cxx:644
bool IsRTL() const
Returns true, if the Right-to-Left layout mode is active.
Definition: csvcontrol.hxx:299
SAL_DLLPRIVATE void InitColors()
Reads colors from system settings.
Definition: csvgrid.cxx:242
void InsertSplit(sal_Int32 nPos)
Inserts a split.
Definition: csvgrid.cxx:321
constexpr sal_uInt16 KEYGROUP_CURSOR
sal_Int32 mnType
Definition: csvgrid.hxx:44
virtual void GetFocus() override
Definition: csvgrid.cxx:876
const sal_Int32 CSV_TYPE_NOSELECTION
No column selected.
Definition: csvcontrol.hxx:53
virtual OutputDevice & get_ref_device()=0
const sal_Int32 CSV_MINCOLWIDTH
Minimum character count for a column in separators mode.
Definition: csvcontrol.hxx:35
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:63
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
Change number of data lines. [line count].
Definition: csvcontrol.hxx:174
SAL_DLLPRIVATE void ExecutePopup(const Point &rPos)
Executes the data type popup menu.
Definition: csvgrid.cxx:616
void DrawRect(const tools::Rectangle &rRect)
#define SAL_N_ELEMENTS(arr)
sal_uInt32 mnMTCurrCol
Index of most recently selected column.
Definition: csvgrid.hxx:92
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:764
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:526
Point BottomRight() const
const Color & GetDarkShadowColor() const
sal_Int32 GetLastVisPos() const
Returns the last visible position.
Definition: csvcontrol.hxx:308
void SetLineColor()
SAL_DLLPRIVATE void ScrollVertRel(ScMoveMode eDir)
Scrolls data grid vertically.
Definition: csvgrid.cxx:597
const OUString & GetColumnTypeName(sal_uInt32 nColIndex) const
Returns the UI type name of the specified column.
Definition: csvgrid.cxx:551
void SetTop(long v)
#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:72
Last element in current context.
Definition: csvcontrol.hxx:83
Successor of current element in current context.
Definition: csvcontrol.hxx:85
std::vector< OUString > maTypeNames
State of each column.
Definition: csvgrid.hxx:87
bool IsDark() const
virtual void StyleUpdated() override
Definition: csvgrid.cxx:1046
virtual ~ScCsvGrid() override
Definition: csvgrid.cxx:122
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:458
Color maAppBackColor
Grid color for "first imported line" delimiter.
Definition: csvgrid.hxx:72
const sal_uInt32 CSV_COLUMN_INVALID
Definition: csvgrid.hxx:39
sal_Int32 mnPosCount
Definition: csvcontrol.hxx:116
#define SC_MOD()
Definition: scmod.hxx:253
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:181
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:33
void SetTextColor(const Color &rColor)
void FillColumnDataSep(ScAsciiOptions &rOptions) const
Fills the options object with column data for separators mode.
Definition: csvgrid.cxx:565
void Select(bool bSel)
Definition: csvgrid.hxx:51
sal_Int32 GetFirstVisLine() const
Returns index of first visible line.
Definition: csvcontrol.hxx:337
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:234
const Size & GetFontSize() const
sal_uInt32 GetFocusColumn() const
Returns index of the focused column.
Definition: csvgrid.hxx:221
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:470
Change data type of selected columns. [column type].
Definition: csvcontrol.hxx:187
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:267
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:825
sal_Int32 GetColumnWidth(sal_uInt32 nColIndex) const
Returns the character width of the column with the specified index.
Definition: csvgrid.cxx:482
sal_Int32 mnFirstImpLine
2D-vector for cell texts.
Definition: csvgrid.hxx:90
First element in current context.
Definition: csvcontrol.hxx:82
sal_uInt32 GetColumnCount() const
Returns the number of columns.
Definition: csvgrid.hxx:151
const sal_Int32 CSV_TYPE_DEFAULT
Default column data type.
Definition: csvcontrol.hxx:49
long GetTextHeight() const
::std::vector< ScCsvColState > ScCsvColStateVec
Definition: csvgrid.hxx:54
void SetOutputSizePixel(const Size &rSize)
No action.
Definition: csvcontrol.hxx:81
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:132
void SetTypeNames(const std::vector< OUString > &rTypeNames)
Sets new UI data type names.
Definition: csvgrid.cxx:537
The control in the CSV import dialog that contains a ruler and a data grid to visualize and modify th...
Definition: csvtablebox.hxx:44
void SelectRange(sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect=true)
Selects or deselects the specified column range.
Definition: csvgrid.cxx:663
const Point & GetMousePosPixel() const
Change position offset (scroll pos). [position].
Definition: csvcontrol.hxx:169
const sal_uInt16 CSV_HDR_TRANSPARENCY
Transparency for header color of selected columns.
Definition: csvcontrol.hxx:39
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:635
bool IsShift() const
weld::DrawingArea * GetDrawingArea() const
sal_Int32 mnIndex
Definition: csvcontrol.hxx:67
void Init()
Finishes initialization.
Definition: csvgrid.cxx:132
SAL_DLLPRIVATE void ImplDrawRowHeaders()
Draws the row headers column to maBackgrDev.
Definition: csvgrid.cxx:1224
Change first visible line. [line index].
Definition: csvcontrol.hxx:175
virtual void LoseFocus() override
Definition: csvcontrol.cxx:80
sal_Int32 GetRulerCursorPos() const
Returns the ruler cursor position.
Definition: csvcontrol.hxx:358
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
ScEditEnginePtr mpEditEngine
Header color of selected columns.
Definition: csvgrid.hxx:79
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:747
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:51
ScCsvColStateVec maColStates
Vector with split positions.
Definition: csvgrid.hxx:86
void SetFont(const vcl::Font &rNewFont)
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
Color maHeaderGridColor
Background color for headers.
Definition: csvgrid.hxx:75
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
bool IsLeft() const
Color maBackColor
Application color configuration.
Definition: csvgrid.hxx:69
bool IsMod1() const
void DrawGrid(const tools::Rectangle &rRect, const Size &rDist, DrawGridFlags nFlags)
const sal_uInt8 SC_COL_MDY
Definition: csvcontrol.hxx:58
const sal_uInt8 SC_COL_ENGLISH
Definition: csvcontrol.hxx:62
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: csvgrid.cxx:923
sal_Int32 GetHeight() const
Returns the height of the control.
Definition: csvgrid.hxx:279
void SetBottom(long v)
sal_Int32 GetSelColumnType() const
Returns the data type of the selected columns.
Definition: csvgrid.cxx:510
sal_Int32 GetHdrWidth() const
Returns the width of the header column.
Definition: csvcontrol.hxx:318
sal_Int32 GetColumnX(sal_uInt32 nColIndex) const
Returns X coordinate of the specified column.
Definition: csvgrid.cxx:465
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:223
Size maWinSize
Monospace font for data cells.
Definition: csvgrid.hxx:82
ScCsvDiff
Flags for comparison of old and new control layout data.
Definition: csvcontrol.hxx:90
sal_uInt32 mnRecentSelCol
First imported line (0-based).
Definition: csvgrid.hxx:91
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:401
SAL_DLLPRIVATE void ImplClearSelection()
Clears the entire selection without notify.
Definition: csvgrid.cxx:741
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:86
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:630
Size maEdEngSize
Size of the control.
Definition: csvgrid.hxx:83
long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
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
void InvalidateGfx()
Sets the graphic invalid (next Redraw() will not use cached graphic).
Definition: csvcontrol.hxx:265
SAL_DLLPRIVATE void MoveCursor(sal_uInt32 nColIndex)
Moves column cursor to a new position.
Definition: csvgrid.cxx:695
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:46
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:501
const sal_uInt8 SC_COL_DMY
Definition: csvcontrol.hxx:59
SAL_DLLPRIVATE void ImplClearSplits()
Clears the split array and re-inserts boundary splits.
Definition: csvgrid.cxx:430
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:625
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:1549
::std::vector< ScCsvExpData > ScCsvExpDataVec
Definition: csvcontrol.hxx:75
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: csvgrid.cxx:93
const int nLineCount
const sal_uInt8 SC_COL_SKIP
Definition: csvcontrol.hxx:61
Color maHeaderTextColor
Grid color for headers.
Definition: csvgrid.hxx:76
Recalculate splits and cell texts. [-].
Definition: csvcontrol.hxx:185
sal_Int32 GetFirstVisPos() const
Returns the first visible position.
Definition: csvcontrol.hxx:306
Point TopRight() const
sal_uInt32 Count() const
Returns the number of splits.
Definition: csvsplits.hxx:69
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:277
sal_Int32 GetGridCursorPos() const
Returns the data grid cursor position (not column index!).
Definition: csvcontrol.hxx:360
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:168
SAL_DLLPRIVATE void InitFonts()
Initializes all font settings.
Definition: csvgrid.cxx:262
Color maSelectColor
Text color for headers.
Definition: csvgrid.hxx:77
void SetSplits(const ScCsvSplits &rSplits)
Removes all splits and inserts the splits from rSplits.
Definition: csvgrid.cxx:386
const sal_uInt8 SC_COL_YMD
Definition: csvcontrol.hxx:60
void EnableRTL(bool bEnable)
std::unique_ptr< weld::Menu > mxPopup
Data grid with selection and cursor.
Definition: csvgrid.hxx:66
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:113
bool IsMod2() const
This struct contains the state of one table column.
Definition: csvgrid.hxx:42