fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / dbgui / csvtablebox.cxx
blob785cb91b71d3b5537829c60a28796d0036f69745
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "csvtablebox.hxx"
21 #include <vcl/builderfactory.hxx>
22 #include <vcl/lstbox.hxx>
23 #include <vcl/settings.hxx>
24 #include "editutil.hxx"
26 ScCsvTableBox::ScCsvTableBox( vcl::Window* pParent, WinBits nBits ) :
27 ScCsvControl( pParent, maData, nBits ),
28 maRuler( VclPtr<ScCsvRuler>::Create(*this) ),
29 maGrid( VclPtr<ScCsvGrid>::Create(*this) ),
30 maHScroll( VclPtr<ScrollBar>::Create( this, WB_HORZ | WB_DRAG ) ),
31 maVScroll( VclPtr<ScrollBar>::Create( this, WB_VERT | WB_DRAG ) ),
32 maScrollBox( VclPtr<ScrollBarBox>::Create(this) )
34 mbFixedMode = false;
35 mnFixedWidth = 1;
37 maHScroll->EnableRTL( false ); // RTL
38 maHScroll->SetLineSize( 1 );
39 maVScroll->SetLineSize( 1 );
41 Link<> aLink = LINK( this, ScCsvTableBox, CsvCmdHdl );
42 SetCmdHdl( aLink );
43 maRuler->SetCmdHdl( aLink );
44 maGrid->SetCmdHdl( aLink );
46 aLink = LINK( this, ScCsvTableBox, ScrollHdl );
47 maHScroll->SetScrollHdl( aLink );
48 maVScroll->SetScrollHdl( aLink );
50 aLink = LINK( this, ScCsvTableBox, ScrollEndHdl );
51 maHScroll->SetEndScrollHdl( aLink );
52 maVScroll->SetEndScrollHdl( aLink );
54 InitControls();
57 ScCsvTableBox::~ScCsvTableBox()
59 disposeOnce();
62 void ScCsvTableBox::dispose()
64 maRuler.disposeAndClear();
65 maGrid.disposeAndClear();
66 maHScroll.disposeAndClear();
67 maVScroll.disposeAndClear();
68 maScrollBox.disposeAndClear();
69 ScCsvControl::dispose();
72 VCL_BUILDER_FACTORY_ARGS(ScCsvTableBox, WB_BORDER)
74 Size ScCsvTableBox::GetOptimalSize() const
76 Size aDefault(LogicToPixel(Size(243, 82), MapMode(MAP_APPFONT)));
77 return aDefault;
80 // common table box handling --------------------------------------------------
82 void ScCsvTableBox::SetSeparatorsMode()
84 if( mbFixedMode )
86 // rescue data for fixed width mode
87 mnFixedWidth = GetPosCount();
88 maFixColStates = maGrid->GetColumnStates();
89 // switch to separators mode
90 mbFixedMode = false;
91 // reset and reinitialize controls
92 DisableRepaint();
93 Execute( CSVCMD_SETLINEOFFSET, 0 );
94 Execute( CSVCMD_SETPOSCOUNT, 1 );
95 Execute( CSVCMD_NEWCELLTEXTS );
96 maGrid->SetColumnStates( maSepColStates );
97 InitControls();
98 EnableRepaint();
102 void ScCsvTableBox::SetFixedWidthMode()
104 if( !mbFixedMode )
106 // rescue data for separators mode
107 maSepColStates = maGrid->GetColumnStates();
108 // switch to fixed width mode
109 mbFixedMode = true;
110 // reset and reinitialize controls
111 DisableRepaint();
112 Execute( CSVCMD_SETLINEOFFSET, 0 );
113 Execute( CSVCMD_SETPOSCOUNT, mnFixedWidth );
114 maGrid->SetSplits( maRuler->GetSplits() );
115 maGrid->SetColumnStates( maFixColStates );
116 InitControls();
117 EnableRepaint();
121 void ScCsvTableBox::Init()
123 maGrid->Init();
126 void ScCsvTableBox::InitControls()
128 maGrid->UpdateLayoutData();
130 long nScrollBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
131 Size aWinSize = CalcOutputSize( GetSizePixel() );
132 long nDataWidth = aWinSize.Width() - nScrollBarSize;
133 long nDataHeight = aWinSize.Height() - nScrollBarSize;
135 maData.mnWinWidth = nDataWidth;
136 maData.mnWinHeight = nDataHeight;
138 if( mbFixedMode )
140 // ruler sets height internally
141 maRuler->setPosSizePixel( 0, 0, nDataWidth, 0 );
142 sal_Int32 nY = maRuler->GetSizePixel().Height();
143 maData.mnWinHeight -= nY;
144 maGrid->setPosSizePixel( 0, nY, nDataWidth, maData.mnWinHeight );
146 else
147 maGrid->setPosSizePixel( 0, 0, nDataWidth, nDataHeight );
148 maGrid->Show();
149 maRuler->Show( mbFixedMode );
151 // scrollbars always visible
152 maHScroll->setPosSizePixel( 0, nDataHeight, nDataWidth, nScrollBarSize );
153 InitHScrollBar();
154 maHScroll->Show();
156 // scrollbars always visible
157 maVScroll->setPosSizePixel( nDataWidth, 0, nScrollBarSize, nDataHeight );
158 InitVScrollBar();
159 maVScroll->Show();
161 bool bScrBox = maHScroll->IsVisible() && maVScroll->IsVisible();
162 if( bScrBox )
163 maScrollBox->setPosSizePixel( nDataWidth, nDataHeight, nScrollBarSize, nScrollBarSize );
164 maScrollBox->Show( bScrBox );
166 // let the controls self-adjust to visible area
167 Execute( CSVCMD_SETPOSOFFSET, GetFirstVisPos() );
168 Execute( CSVCMD_SETLINEOFFSET, GetFirstVisLine() );
171 void ScCsvTableBox::InitHScrollBar()
173 maHScroll->SetRange( Range( 0, GetPosCount() + 2 ) );
174 maHScroll->SetVisibleSize( GetVisPosCount() );
175 maHScroll->SetPageSize( GetVisPosCount() * 3 / 4 );
176 maHScroll->SetThumbPos( GetFirstVisPos() );
179 void ScCsvTableBox::InitVScrollBar()
181 maVScroll->SetRange( Range( 0, GetLineCount() + 1 ) );
182 maVScroll->SetVisibleSize( GetVisLineCount() );
183 maVScroll->SetPageSize( GetVisLineCount() - 2 );
184 maVScroll->SetThumbPos( GetFirstVisLine() );
187 void ScCsvTableBox::MakePosVisible( sal_Int32 nPos )
189 if( (0 <= nPos) && (nPos < GetPosCount()) )
191 if( nPos - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
192 Execute( CSVCMD_SETPOSOFFSET, nPos - CSV_SCROLL_DIST );
193 else if( nPos + CSV_SCROLL_DIST >= GetLastVisPos() )
194 Execute( CSVCMD_SETPOSOFFSET, nPos - GetVisPosCount() + CSV_SCROLL_DIST );
198 // cell contents --------------------------------------------------------------
200 void ScCsvTableBox::SetUniStrings(
201 const OUString* pTextLines, const OUString& rSepChars,
202 sal_Unicode cTextSep, bool bMergeSep )
204 // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
205 // -> will be dynamic sometime
206 DisableRepaint();
207 sal_Int32 nEndLine = GetFirstVisLine() + CSV_PREVIEW_LINES;
208 const OUString* pString = pTextLines;
209 for( sal_Int32 nLine = GetFirstVisLine(); nLine < nEndLine; ++nLine, ++pString )
211 if( mbFixedMode )
212 maGrid->ImplSetTextLineFix( nLine, *pString );
213 else
214 maGrid->ImplSetTextLineSep( nLine, *pString, rSepChars, cTextSep, bMergeSep );
216 EnableRepaint();
219 // column settings ------------------------------------------------------------
221 void ScCsvTableBox::InitTypes( const ListBox& rListBox )
223 sal_uInt16 nTypeCount = rListBox.GetEntryCount();
224 StringVec aTypeNames( nTypeCount );
225 for( sal_uInt16 nIndex = 0; nIndex < nTypeCount; ++nIndex )
226 aTypeNames[ nIndex ] = rListBox.GetEntry( nIndex );
227 maGrid->SetTypeNames( aTypeNames );
230 void ScCsvTableBox::FillColumnData( ScAsciiOptions& rOptions ) const
232 if( mbFixedMode )
233 maGrid->FillColumnDataFix( rOptions );
234 else
235 maGrid->FillColumnDataSep( rOptions );
238 // event handling -------------------------------------------------------------
240 void ScCsvTableBox::Resize()
242 ScCsvControl::Resize();
243 InitControls();
246 void ScCsvTableBox::DataChanged( const DataChangedEvent& rDCEvt )
248 if( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
249 InitControls();
250 ScCsvControl::DataChanged( rDCEvt );
253 IMPL_LINK( ScCsvTableBox, CsvCmdHdl, ScCsvControl*, pCtrl )
255 OSL_ENSURE( pCtrl, "ScCsvTableBox::CsvCmdHdl - missing sender" );
257 const ScCsvCmd& rCmd = pCtrl->GetCmd();
258 ScCsvCmdType eType = rCmd.GetType();
259 sal_Int32 nParam1 = rCmd.GetParam1();
260 sal_Int32 nParam2 = rCmd.GetParam2();
262 bool bFound = true;
263 switch( eType )
265 case CSVCMD_REPAINT:
266 if( !IsNoRepaint() )
268 maGrid->ImplRedraw();
269 maRuler->ImplRedraw();
270 InitHScrollBar();
271 InitVScrollBar();
273 break;
274 case CSVCMD_MAKEPOSVISIBLE:
275 MakePosVisible( nParam1 );
276 break;
278 case CSVCMD_NEWCELLTEXTS:
279 if( mbFixedMode )
280 Execute( CSVCMD_UPDATECELLTEXTS );
281 else
283 DisableRepaint();
284 ScCsvColStateVec aStates( maGrid->GetColumnStates() );
285 sal_Int32 nPos = GetFirstVisPos();
286 Execute( CSVCMD_SETPOSCOUNT, 1 );
287 Execute( CSVCMD_UPDATECELLTEXTS );
288 Execute( CSVCMD_SETPOSOFFSET, nPos );
289 maGrid->SetColumnStates( aStates );
290 EnableRepaint();
292 break;
293 case CSVCMD_UPDATECELLTEXTS:
294 maUpdateTextHdl.Call( this );
295 break;
296 case CSVCMD_SETCOLUMNTYPE:
297 maGrid->SetSelColumnType( nParam1 );
298 break;
299 case CSVCMD_EXPORTCOLUMNTYPE:
300 maColTypeHdl.Call( this );
301 break;
302 case CSVCMD_SETFIRSTIMPORTLINE:
303 maGrid->SetFirstImportedLine( nParam1 );
304 break;
306 case CSVCMD_INSERTSPLIT:
307 OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::InsertSplit - invalid call" );
308 if( maRuler->GetSplitCount() + 1 < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT) )
310 maRuler->InsertSplit( nParam1 );
311 maGrid->InsertSplit( nParam1 );
313 break;
314 case CSVCMD_REMOVESPLIT:
315 OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveSplit - invalid call" );
316 maRuler->RemoveSplit( nParam1 );
317 maGrid->RemoveSplit( nParam1 );
318 break;
319 case CSVCMD_TOGGLESPLIT:
320 Execute( maRuler->HasSplit( nParam1 ) ? CSVCMD_REMOVESPLIT : CSVCMD_INSERTSPLIT, nParam1 );
321 break;
322 case CSVCMD_MOVESPLIT:
323 OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::MoveSplit - invalid call" );
324 maRuler->MoveSplit( nParam1, nParam2 );
325 maGrid->MoveSplit( nParam1, nParam2 );
326 break;
327 case CSVCMD_REMOVEALLSPLITS:
328 OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveAllSplits - invalid call" );
329 maRuler->RemoveAllSplits();
330 maGrid->RemoveAllSplits();
331 break;
332 default:
333 bFound = false;
335 if( bFound )
336 return 0;
338 const ScCsvLayoutData aOldData( maData );
339 switch( eType )
341 case CSVCMD_SETPOSCOUNT:
342 maData.mnPosCount = std::max( nParam1, sal_Int32( 1 ) );
343 ImplSetPosOffset( GetFirstVisPos() );
344 break;
345 case CSVCMD_SETPOSOFFSET:
346 ImplSetPosOffset( nParam1 );
347 break;
348 case CSVCMD_SETHDRWIDTH:
349 maData.mnHdrWidth = std::max( nParam1, sal_Int32( 0 ) );
350 ImplSetPosOffset( GetFirstVisPos() );
351 break;
352 case CSVCMD_SETCHARWIDTH:
353 maData.mnCharWidth = std::max( nParam1, sal_Int32( 1 ) );
354 ImplSetPosOffset( GetFirstVisPos() );
355 break;
356 case CSVCMD_SETLINECOUNT:
357 maData.mnLineCount = std::max( nParam1, sal_Int32( 1 ) );
358 ImplSetLineOffset( GetFirstVisLine() );
359 break;
360 case CSVCMD_SETLINEOFFSET:
361 ImplSetLineOffset( nParam1 );
362 break;
363 case CSVCMD_SETHDRHEIGHT:
364 maData.mnHdrHeight = std::max( nParam1, sal_Int32( 0 ) );
365 ImplSetLineOffset( GetFirstVisLine() );
366 break;
367 case CSVCMD_SETLINEHEIGHT:
368 maData.mnLineHeight = std::max( nParam1, sal_Int32( 1 ) );
369 ImplSetLineOffset( GetFirstVisLine() );
370 break;
371 case CSVCMD_MOVERULERCURSOR:
372 maData.mnPosCursor = IsVisibleSplitPos( nParam1 ) ? nParam1 : CSV_POS_INVALID;
373 break;
374 case CSVCMD_MOVEGRIDCURSOR:
375 maData.mnColCursor = ((0 <= nParam1) && (nParam1 < GetPosCount())) ? nParam1 : CSV_POS_INVALID;
376 break;
377 default:
379 // added to avoid warnings
383 if( maData != aOldData )
385 DisableRepaint();
386 maRuler->ApplyLayout( aOldData );
387 maGrid->ApplyLayout( aOldData );
388 EnableRepaint();
391 return 0;
394 IMPL_LINK( ScCsvTableBox, ScrollHdl, ScrollBar*, pScrollBar )
396 OSL_ENSURE( pScrollBar, "ScCsvTableBox::ScrollHdl - missing sender" );
398 if( pScrollBar == maHScroll.get() )
399 Execute( CSVCMD_SETPOSOFFSET, pScrollBar->GetThumbPos() );
400 else if( pScrollBar == maVScroll.get() )
401 Execute( CSVCMD_SETLINEOFFSET, pScrollBar->GetThumbPos() );
403 return 0;
406 IMPL_LINK( ScCsvTableBox, ScrollEndHdl, ScrollBar*, pScrollBar )
408 OSL_ENSURE( pScrollBar, "ScCsvTableBox::ScrollEndHdl - missing sender" );
410 if( pScrollBar == maHScroll.get() )
412 if( GetRulerCursorPos() != CSV_POS_INVALID )
413 Execute( CSVCMD_MOVERULERCURSOR, maRuler->GetNoScrollPos( GetRulerCursorPos() ) );
414 if( GetGridCursorPos() != CSV_POS_INVALID )
415 Execute( CSVCMD_MOVEGRIDCURSOR, maGrid->GetNoScrollCol( GetGridCursorPos() ) );
418 return 0;
421 // accessibility --------------------------------------------------------------
423 ScCsvTableBox::XAccessibleRef ScCsvTableBox::CreateAccessible()
425 // do not use the ScCsvControl mechanism, return default accessible object
426 return Control::CreateAccessible();
429 ScAccessibleCsvControl* ScCsvTableBox::ImplCreateAccessible()
431 return NULL; // not used, see CreateAccessible()
434 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */