Update ooo320-m1
[ooovba.git] / sc / source / ui / dbgui / csvtablebox.cxx
blobc2c9f4a3d0addff337f4a210648d845e219878ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: csvtablebox.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 // ============================================================================
36 #include "csvtablebox.hxx"
37 #include <tools/debug.hxx>
38 #include <vcl/lstbox.hxx>
40 // ause
41 #include "editutil.hxx"
43 // ============================================================================
45 //UNUSED2009-05 ScCsvTableBox::ScCsvTableBox( Window* pParent ) :
46 //UNUSED2009-05 ScCsvControl( pParent, maData, WB_BORDER | WB_TABSTOP | WB_DIALOGCONTROL ),
47 //UNUSED2009-05 maRuler( *this ),
48 //UNUSED2009-05 maGrid( *this ),
49 //UNUSED2009-05 maHScroll( this, WB_HORZ | WB_DRAG ),
50 //UNUSED2009-05 maVScroll( this, WB_VERT | WB_DRAG ),
51 //UNUSED2009-05 maScrollBox( this )
52 //UNUSED2009-05 {
53 //UNUSED2009-05 Init();
54 //UNUSED2009-05 }
56 ScCsvTableBox::ScCsvTableBox( Window* pParent, const ResId& rResId ) :
57 ScCsvControl( pParent, maData, rResId ),
58 maRuler( *this ),
59 maGrid( *this ),
60 maHScroll( this, WB_HORZ | WB_DRAG ),
61 maVScroll( this, WB_VERT | WB_DRAG ),
62 maScrollBox( this )
64 Init();
68 // common table box handling --------------------------------------------------
70 void ScCsvTableBox::SetSeparatorsMode()
72 if( mbFixedMode )
74 // rescue data for fixed width mode
75 mnFixedWidth = GetPosCount();
76 maFixColStates = maGrid.GetColumnStates();
77 // switch to separators mode
78 mbFixedMode = false;
79 // reset and reinitialize controls
80 DisableRepaint();
81 Execute( CSVCMD_SETLINEOFFSET, 0 );
82 Execute( CSVCMD_SETPOSCOUNT, 1 );
83 Execute( CSVCMD_NEWCELLTEXTS );
84 maGrid.SetColumnStates( maSepColStates );
85 InitControls();
86 EnableRepaint();
90 void ScCsvTableBox::SetFixedWidthMode()
92 if( !mbFixedMode )
94 // rescue data for separators mode
95 maSepColStates = maGrid.GetColumnStates();
96 // switch to fixed width mode
97 mbFixedMode = true;
98 // reset and reinitialize controls
99 DisableRepaint();
100 Execute( CSVCMD_SETLINEOFFSET, 0 );
101 Execute( CSVCMD_SETPOSCOUNT, mnFixedWidth );
102 maGrid.SetSplits( maRuler.GetSplits() );
103 maGrid.SetColumnStates( maFixColStates );
104 InitControls();
105 EnableRepaint();
109 void ScCsvTableBox::Init()
111 mbFixedMode = false;
112 mnFixedWidth = 1;
114 maHScroll.EnableRTL( false ); // #107812# RTL
115 maHScroll.SetLineSize( 1 );
116 maVScroll.SetLineSize( 1 );
118 Link aLink = LINK( this, ScCsvTableBox, CsvCmdHdl );
119 SetCmdHdl( aLink );
120 maRuler.SetCmdHdl( aLink );
121 maGrid.SetCmdHdl( aLink );
123 aLink = LINK( this, ScCsvTableBox, ScrollHdl );
124 maHScroll.SetScrollHdl( aLink );
125 maVScroll.SetScrollHdl( aLink );
127 aLink = LINK( this, ScCsvTableBox, ScrollEndHdl );
128 maHScroll.SetEndScrollHdl( aLink );
129 maVScroll.SetEndScrollHdl( aLink );
131 InitControls();
134 void ScCsvTableBox::InitControls()
136 maGrid.UpdateLayoutData();
138 long nScrollBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
139 Size aWinSize = CalcOutputSize( GetSizePixel() );
140 long nDataWidth = aWinSize.Width() - nScrollBarSize;
141 long nDataHeight = aWinSize.Height() - nScrollBarSize;
143 maData.mnWinWidth = nDataWidth;
144 maData.mnWinHeight = nDataHeight;
146 if( mbFixedMode )
148 // ruler sets height internally
149 maRuler.SetPosSizePixel( 0, 0, nDataWidth, 0 );
150 sal_Int32 nY = maRuler.GetSizePixel().Height();
151 maData.mnWinHeight -= nY;
152 maGrid.SetPosSizePixel( 0, nY, nDataWidth, maData.mnWinHeight );
154 else
155 maGrid.SetPosSizePixel( 0, 0, nDataWidth, nDataHeight );
156 maGrid.Show();
157 maRuler.Show( mbFixedMode );
159 // scrollbars always visible
160 maHScroll.SetPosSizePixel( 0, nDataHeight, nDataWidth, nScrollBarSize );
161 InitHScrollBar();
162 maHScroll.Show();
164 // scrollbars always visible
165 maVScroll.SetPosSizePixel( nDataWidth, 0, nScrollBarSize, nDataHeight );
166 InitVScrollBar();
167 maVScroll.Show();
169 bool bScrBox = maHScroll.IsVisible() && maVScroll.IsVisible();
170 if( bScrBox )
171 maScrollBox.SetPosSizePixel( nDataWidth, nDataHeight, nScrollBarSize, nScrollBarSize );
172 maScrollBox.Show( bScrBox );
174 // let the controls self-adjust to visible area
175 Execute( CSVCMD_SETPOSOFFSET, GetFirstVisPos() );
176 Execute( CSVCMD_SETLINEOFFSET, GetFirstVisLine() );
179 void ScCsvTableBox::InitHScrollBar()
181 maHScroll.SetRange( Range( 0, GetPosCount() + 2 ) );
182 maHScroll.SetVisibleSize( GetVisPosCount() );
183 maHScroll.SetPageSize( GetVisPosCount() * 3 / 4 );
184 maHScroll.SetThumbPos( GetFirstVisPos() );
187 void ScCsvTableBox::InitVScrollBar()
189 maVScroll.SetRange( Range( 0, GetLineCount() + 1 ) );
190 maVScroll.SetVisibleSize( GetVisLineCount() );
191 maVScroll.SetPageSize( GetVisLineCount() - 2 );
192 maVScroll.SetThumbPos( GetFirstVisLine() );
195 void ScCsvTableBox::MakePosVisible( sal_Int32 nPos )
197 if( (0 <= nPos) && (nPos < GetPosCount()) )
199 if( nPos - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
200 Execute( CSVCMD_SETPOSOFFSET, nPos - CSV_SCROLL_DIST );
201 else if( nPos + CSV_SCROLL_DIST >= GetLastVisPos() )
202 Execute( CSVCMD_SETPOSOFFSET, nPos - GetVisPosCount() + CSV_SCROLL_DIST );
207 // cell contents --------------------------------------------------------------
209 void ScCsvTableBox::SetUniStrings(
210 const String* pTextLines, const String& rSepChars,
211 sal_Unicode cTextSep, bool bMergeSep )
213 // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
214 // -> will be dynamic sometime
215 DisableRepaint();
216 sal_Int32 nEndLine = GetFirstVisLine() + CSV_PREVIEW_LINES;
217 const String* pString = pTextLines;
218 for( sal_Int32 nLine = GetFirstVisLine(); nLine < nEndLine; ++nLine, ++pString )
220 if( mbFixedMode )
221 maGrid.ImplSetTextLineFix( nLine, *pString );
222 else
223 maGrid.ImplSetTextLineSep( nLine, *pString, rSepChars, cTextSep, bMergeSep );
225 EnableRepaint();
228 //UNUSED2009-05 void ScCsvTableBox::SetByteStrings(
229 //UNUSED2009-05 const ByteString* pTextLines, CharSet eCharSet,
230 //UNUSED2009-05 const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep )
231 //UNUSED2009-05 {
232 //UNUSED2009-05 // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
233 //UNUSED2009-05 // -> will be dynamic sometime
234 //UNUSED2009-05 DisableRepaint();
235 //UNUSED2009-05 sal_Int32 nEndLine = GetFirstVisLine() + CSV_PREVIEW_LINES;
236 //UNUSED2009-05 const ByteString* pString = pTextLines;
237 //UNUSED2009-05 for( sal_Int32 nLine = GetFirstVisLine(); nLine < nEndLine; ++nLine, ++pString )
238 //UNUSED2009-05 {
239 //UNUSED2009-05 if( mbFixedMode )
240 //UNUSED2009-05 maGrid.ImplSetTextLineFix( nLine, String( *pString, eCharSet ) );
241 //UNUSED2009-05 else
242 //UNUSED2009-05 maGrid.ImplSetTextLineSep( nLine, String( *pString, eCharSet ), rSepChars, cTextSep, bMergeSep );
243 //UNUSED2009-05 }
244 //UNUSED2009-05 EnableRepaint();
245 //UNUSED2009-05 }
248 // column settings ------------------------------------------------------------
250 void ScCsvTableBox::InitTypes( const ListBox& rListBox )
252 sal_uInt16 nTypeCount = rListBox.GetEntryCount();
253 StringVec aTypeNames( nTypeCount );
254 for( sal_uInt16 nIndex = 0; nIndex < nTypeCount; ++nIndex )
255 aTypeNames[ nIndex ] = rListBox.GetEntry( nIndex );
256 maGrid.SetTypeNames( aTypeNames );
259 void ScCsvTableBox::FillColumnData( ScAsciiOptions& rOptions ) const
261 if( mbFixedMode )
262 maGrid.FillColumnDataFix( rOptions );
263 else
264 maGrid.FillColumnDataSep( rOptions );
268 // event handling -------------------------------------------------------------
270 void ScCsvTableBox::Resize()
272 ScCsvControl::Resize();
273 InitControls();
276 void ScCsvTableBox::DataChanged( const DataChangedEvent& rDCEvt )
278 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
279 InitControls();
280 ScCsvControl::DataChanged( rDCEvt );
283 IMPL_LINK( ScCsvTableBox, CsvCmdHdl, ScCsvControl*, pCtrl )
285 DBG_ASSERT( pCtrl, "ScCsvTableBox::CsvCmdHdl - missing sender" );
287 const ScCsvCmd& rCmd = pCtrl->GetCmd();
288 ScCsvCmdType eType = rCmd.GetType();
289 sal_Int32 nParam1 = rCmd.GetParam1();
290 sal_Int32 nParam2 = rCmd.GetParam2();
292 bool bFound = true;
293 switch( eType )
295 case CSVCMD_REPAINT:
296 if( !IsNoRepaint() )
298 maGrid.ImplRedraw();
299 maRuler.ImplRedraw();
300 InitHScrollBar();
301 InitVScrollBar();
303 break;
304 case CSVCMD_MAKEPOSVISIBLE:
305 MakePosVisible( nParam1 );
306 break;
308 case CSVCMD_NEWCELLTEXTS:
309 if( mbFixedMode )
310 Execute( CSVCMD_UPDATECELLTEXTS );
311 else
313 DisableRepaint();
314 ScCsvColStateVec aStates( maGrid.GetColumnStates() );
315 sal_Int32 nPos = GetFirstVisPos();
316 Execute( CSVCMD_SETPOSCOUNT, 1 );
317 Execute( CSVCMD_UPDATECELLTEXTS );
318 Execute( CSVCMD_SETPOSOFFSET, nPos );
319 maGrid.SetColumnStates( aStates );
320 EnableRepaint();
322 break;
323 case CSVCMD_UPDATECELLTEXTS:
324 maUpdateTextHdl.Call( this );
325 break;
326 case CSVCMD_SETCOLUMNTYPE:
327 maGrid.SetSelColumnType( nParam1 );
328 break;
329 case CSVCMD_EXPORTCOLUMNTYPE:
330 maColTypeHdl.Call( this );
331 break;
332 case CSVCMD_SETFIRSTIMPORTLINE:
333 maGrid.SetFirstImportedLine( nParam1 );
334 break;
336 case CSVCMD_INSERTSPLIT:
337 DBG_ASSERT( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::InsertSplit - invalid call" );
338 if( maRuler.GetSplitCount() + 1 < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT) )
340 maRuler.InsertSplit( nParam1 );
341 maGrid.InsertSplit( nParam1 );
343 break;
344 case CSVCMD_REMOVESPLIT:
345 DBG_ASSERT( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveSplit - invalid call" );
346 maRuler.RemoveSplit( nParam1 );
347 maGrid.RemoveSplit( nParam1 );
348 break;
349 case CSVCMD_TOGGLESPLIT:
350 Execute( maRuler.HasSplit( nParam1 ) ? CSVCMD_REMOVESPLIT : CSVCMD_INSERTSPLIT, nParam1 );
351 break;
352 case CSVCMD_MOVESPLIT:
353 DBG_ASSERT( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::MoveSplit - invalid call" );
354 maRuler.MoveSplit( nParam1, nParam2 );
355 maGrid.MoveSplit( nParam1, nParam2 );
356 break;
357 case CSVCMD_REMOVEALLSPLITS:
358 DBG_ASSERT( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveAllSplits - invalid call" );
359 maRuler.RemoveAllSplits();
360 maGrid.RemoveAllSplits();
361 break;
362 default:
363 bFound = false;
365 if( bFound )
366 return 0;
368 const ScCsvLayoutData aOldData( maData );
369 switch( eType )
371 case CSVCMD_SETPOSCOUNT:
372 maData.mnPosCount = Max( nParam1, sal_Int32( 1 ) );
373 ImplSetPosOffset( GetFirstVisPos() );
374 break;
375 case CSVCMD_SETPOSOFFSET:
376 ImplSetPosOffset( nParam1 );
377 break;
378 case CSVCMD_SETHDRWIDTH:
379 maData.mnHdrWidth = Max( nParam1, sal_Int32( 0 ) );
380 ImplSetPosOffset( GetFirstVisPos() );
381 break;
382 case CSVCMD_SETCHARWIDTH:
383 maData.mnCharWidth = Max( nParam1, sal_Int32( 1 ) );
384 ImplSetPosOffset( GetFirstVisPos() );
385 break;
386 case CSVCMD_SETLINECOUNT:
387 maData.mnLineCount = Max( nParam1, sal_Int32( 1 ) );
388 ImplSetLineOffset( GetFirstVisLine() );
389 break;
390 case CSVCMD_SETLINEOFFSET:
391 ImplSetLineOffset( nParam1 );
392 break;
393 case CSVCMD_SETHDRHEIGHT:
394 maData.mnHdrHeight = Max( nParam1, sal_Int32( 0 ) );
395 ImplSetLineOffset( GetFirstVisLine() );
396 break;
397 case CSVCMD_SETLINEHEIGHT:
398 maData.mnLineHeight = Max( nParam1, sal_Int32( 1 ) );
399 ImplSetLineOffset( GetFirstVisLine() );
400 break;
401 case CSVCMD_MOVERULERCURSOR:
402 maData.mnPosCursor = IsVisibleSplitPos( nParam1 ) ? nParam1 : CSV_POS_INVALID;
403 break;
404 case CSVCMD_MOVEGRIDCURSOR:
405 maData.mnColCursor = ((0 <= nParam1) && (nParam1 < GetPosCount())) ? nParam1 : CSV_POS_INVALID;
406 break;
407 default:
409 // added to avoid warnings
413 if( maData != aOldData )
415 DisableRepaint();
416 maRuler.ApplyLayout( aOldData );
417 maGrid.ApplyLayout( aOldData );
418 EnableRepaint();
421 return 0;
424 IMPL_LINK( ScCsvTableBox, ScrollHdl, ScrollBar*, pScrollBar )
426 DBG_ASSERT( pScrollBar, "ScCsvTableBox::ScrollHdl - missing sender" );
428 if( pScrollBar == &maHScroll )
429 Execute( CSVCMD_SETPOSOFFSET, pScrollBar->GetThumbPos() );
430 else if( pScrollBar == &maVScroll )
431 Execute( CSVCMD_SETLINEOFFSET, pScrollBar->GetThumbPos() );
433 return 0;
436 IMPL_LINK( ScCsvTableBox, ScrollEndHdl, ScrollBar*, pScrollBar )
438 DBG_ASSERT( pScrollBar, "ScCsvTableBox::ScrollEndHdl - missing sender" );
440 if( pScrollBar == &maHScroll )
442 if( GetRulerCursorPos() != CSV_POS_INVALID )
443 Execute( CSVCMD_MOVERULERCURSOR, maRuler.GetNoScrollPos( GetRulerCursorPos() ) );
444 if( GetGridCursorPos() != CSV_POS_INVALID )
445 Execute( CSVCMD_MOVEGRIDCURSOR, maGrid.GetNoScrollCol( GetGridCursorPos() ) );
448 return 0;
452 // accessibility --------------------------------------------------------------
454 ScCsvTableBox::XAccessibleRef ScCsvTableBox::CreateAccessible()
456 // do not use the ScCsvControl mechanism, return default accessible object
457 return Control::CreateAccessible();
460 ScAccessibleCsvControl* ScCsvTableBox::ImplCreateAccessible()
462 return NULL; // not used, see CreateAccessible()
466 // ============================================================================