update dev300-m58
[ooovba.git] / sc / source / ui / dbgui / fieldwnd.cxx
blob13b7ed2daeca130ed9d41b626dd1612a6c97a9ba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fieldwnd.cxx,v $
10 * $Revision: 1.20 $
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"
34 #include <vcl/virdev.hxx>
35 #include <vcl/decoview.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/mnemonic.hxx>
38 #include <vcl/help.hxx>
39 #include <tools/debug.hxx>
41 #include "fieldwnd.hxx"
42 #include "pvlaydlg.hxx"
43 #include "pvglob.hxx"
44 #include "AccessibleDataPilotControl.hxx"
45 #include "scresid.hxx"
46 #include "sc.hrc"
48 const size_t INVALID_INDEX = static_cast< size_t >( -1 );
50 //===================================================================
52 ScDPFieldWindow::ScDPFieldWindow(
53 ScDPLayoutDlg* pDialog,
54 const ResId& rResId,
55 ScDPFieldType eFieldType,
56 FixedText* pFtFieldCaption ) :
57 Control( pDialog, rResId ),
58 pDlg( pDialog ),
59 pFtCaption( pFtFieldCaption ),
60 eType( eFieldType ),
61 nFieldSelected( 0 ),
62 pAccessible( NULL )
64 Init();
65 if (eType != TYPE_SELECT && pFtCaption)
66 aName = MnemonicGenerator::EraseAllMnemonicChars( pFtCaption->GetText() );
69 ScDPFieldWindow::ScDPFieldWindow(
70 ScDPLayoutDlg* pDialog,
71 const ResId& rResId,
72 ScDPFieldType eFieldType,
73 const String& rName ) :
74 Control( pDialog, rResId ),
75 aName(rName),
76 pDlg( pDialog ),
77 pFtCaption( NULL ),
78 eType( eFieldType ),
79 nFieldSelected( 0 ),
80 pAccessible( NULL )
82 Init();
85 void ScDPFieldWindow::Init()
87 aWndRect = Rectangle( GetPosPixel(), GetSizePixel() );
88 nFieldSize = (eType == TYPE_SELECT) ? PAGE_SIZE : ((eType == TYPE_PAGE) ? MAX_PAGEFIELDS : MAX_FIELDS);
90 if( pFtCaption )
92 Size aWinSize( aWndRect.GetSize() );
93 Size aTextSize( GetTextWidth( pFtCaption->GetText() ), GetTextHeight() );
94 aTextPos.X() = (aWinSize.Width() - aTextSize.Width()) / 2;
95 aTextPos.Y() = (aWinSize.Height() - aTextSize.Height()) / 2;
98 GetStyleSettings();
101 __EXPORT ScDPFieldWindow::~ScDPFieldWindow()
103 if (pAccessible)
105 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
106 if (xTempAcc.is())
107 pAccessible->dispose();
111 //-------------------------------------------------------------------
113 void ScDPFieldWindow::GetStyleSettings()
115 const StyleSettings& rStyleSet = GetSettings().GetStyleSettings();
116 aFaceColor = rStyleSet.GetFaceColor();
117 aWinColor = rStyleSet.GetWindowColor();
118 aTextColor = rStyleSet.GetButtonTextColor();
119 aWinTextColor = rStyleSet.GetWindowTextColor();
122 //-------------------------------------------------------------------
124 Point ScDPFieldWindow::GetFieldPosition( size_t nIndex ) const
126 Point aPos;
127 switch( eType )
129 case TYPE_PAGE:
130 aPos.X() = OWIDTH * (nIndex % (MAX_PAGEFIELDS / 2));
131 aPos.Y() = OHEIGHT * (nIndex / (MAX_PAGEFIELDS / 2));
132 break;
133 case TYPE_COL:
134 aPos.X() = OWIDTH * (nIndex % (MAX_FIELDS / 2));
135 aPos.Y() = OHEIGHT * (nIndex / (MAX_FIELDS / 2));
136 break;
137 case TYPE_ROW:
138 case TYPE_DATA:
139 aPos.X() = 0;
140 aPos.Y() = OHEIGHT * nIndex;
141 break;
142 case TYPE_SELECT:
143 aPos.X() = (OWIDTH + SSPACE) * (nIndex / LINE_SIZE);
144 aPos.Y() = (OHEIGHT + SSPACE) * (nIndex % LINE_SIZE);
145 break;
147 return aPos;
150 Size ScDPFieldWindow::GetFieldSize() const
152 return Size( (eType == TYPE_DATA) ? GetSizePixel().Width() : OWIDTH, OHEIGHT );
155 Point ScDPFieldWindow::GetLastPosition() const
157 return OutputToScreenPixel( GetFieldPosition( nFieldSize - 1 ) );
160 bool ScDPFieldWindow::GetFieldIndex( const Point& rPos, size_t& rnIndex ) const
162 rnIndex = INVALID_INDEX;
163 if( (rPos.X() >= 0) && (rPos.Y() >= 0) )
165 switch( eType )
167 case TYPE_ROW:
168 case TYPE_DATA:
169 rnIndex = rPos.Y() / OHEIGHT;
170 break;
171 case TYPE_PAGE:
173 size_t nRow = rPos.Y() / OHEIGHT;
174 size_t nCol = rPos.X() / OWIDTH;
175 rnIndex = nRow * MAX_PAGEFIELDS / 2 + nCol;
177 break;
178 case TYPE_COL:
180 size_t nRow = rPos.Y() / OHEIGHT;
181 size_t nCol = rPos.X() / OWIDTH;
182 rnIndex = nRow * MAX_FIELDS / 2 + nCol;
184 break;
185 case TYPE_SELECT:
187 size_t nRow = rPos.Y() / (OHEIGHT + SSPACE);
188 size_t nCol = rPos.X() / (OWIDTH + SSPACE);
189 // is not between controls?
190 if( (rPos.Y() % (OHEIGHT + SSPACE) < OHEIGHT) && (rPos.X() % (OWIDTH + SSPACE) < OWIDTH) )
191 rnIndex = nCol * LINE_SIZE + nRow;
193 break;
196 return IsValidIndex( rnIndex );
199 //-------------------------------------------------------------------
201 void ScDPFieldWindow::DrawBackground( OutputDevice& rDev )
203 Point aPos0;
204 Size aSize( GetSizePixel() );
206 if ( eType == TYPE_SELECT )
208 rDev.SetLineColor();
209 rDev.SetFillColor( aFaceColor );
210 rDev.DrawRect( Rectangle( aPos0, aSize ) );
212 else
214 rDev.SetLineColor( aWinTextColor );
215 rDev.SetFillColor( aWinColor );
216 rDev.DrawRect( Rectangle( aPos0, aSize ) );
218 rDev.SetTextColor( aWinTextColor );
220 /* Draw the caption text. This needs some special handling, because we
221 support hard line breaks here. This part will draw each line of the
222 text for itself. */
224 xub_StrLen nTokenCnt = GetText().GetTokenCount( '\n' );
225 long nY = (aSize.Height() - nTokenCnt * rDev.GetTextHeight()) / 2;
226 for( xub_StrLen nToken = 0, nStringIx = 0; nToken < nTokenCnt; ++nToken )
228 String aLine( GetText().GetToken( 0, '\n', nStringIx ) );
229 Point aLinePos( (aSize.Width() - rDev.GetCtrlTextWidth( aLine )) / 2, nY );
230 rDev.DrawCtrlText( aLinePos, aLine );
231 nY += rDev.GetTextHeight();
236 void ScDPFieldWindow::DrawField(
237 OutputDevice& rDev, const Rectangle& rRect, FieldString& rText, bool bFocus )
239 VirtualDevice aVirDev( rDev );
240 // #i97623# VirtualDevice is always LTR while other windows derive direction from parent
241 aVirDev.EnableRTL( IsRTLEnabled() );
243 String aText = rText.first;
244 Size aDevSize( rRect.GetSize() );
245 long nWidth = aDevSize.Width();
246 long nHeight = aDevSize.Height();
247 long nLabelWidth = rDev.GetTextWidth( aText );
248 long nLabelHeight = rDev.GetTextHeight();
250 // #i31600# if text is too long, cut and add ellipsis
251 rText.second = nLabelWidth + 6 <= nWidth;
252 if( !rText.second )
254 xub_StrLen nMinLen = 0;
255 xub_StrLen nMaxLen = aText.Len();
256 bool bFits = false;
259 xub_StrLen nCurrLen = (nMinLen + nMaxLen) / 2;
260 aText = String( rText.first, 0, nCurrLen ).AppendAscii( "..." );
261 nLabelWidth = rDev.GetTextWidth( aText );
262 bFits = nLabelWidth + 6 <= nWidth;
263 (bFits ? nMinLen : nMaxLen) = nCurrLen;
265 while( !bFits || (nMinLen + 1 < nMaxLen) );
267 Point aLabelPos( (nWidth - nLabelWidth) / 2, ::std::max< long >( (nHeight - nLabelHeight) / 2, 3 ) );
269 aVirDev.SetOutputSizePixel( aDevSize );
270 aVirDev.SetFont( rDev.GetFont() );
271 DecorationView aDecoView( &aVirDev );
272 aDecoView.DrawButton( Rectangle( Point( 0, 0 ), aDevSize ), bFocus ? BUTTON_DRAW_DEFAULT : 0 );
273 aVirDev.SetTextColor( aTextColor );
274 aVirDev.DrawText( aLabelPos, aText );
275 rDev.DrawBitmap( rRect.TopLeft(), aVirDev.GetBitmap( Point( 0, 0 ), aDevSize ) );
278 void ScDPFieldWindow::Redraw()
280 VirtualDevice aVirDev;
281 // #i97623# VirtualDevice is always LTR while other windows derive direction from parent
282 aVirDev.EnableRTL( IsRTLEnabled() );
283 aVirDev.SetMapMode( MAP_PIXEL );
285 Point aPos0;
286 Size aSize( GetSizePixel() );
287 Font aFont( GetFont() ); // Font vom Window
288 aFont.SetTransparent( TRUE );
289 aVirDev.SetFont( aFont );
290 aVirDev.SetOutputSizePixel( aSize );
292 DrawBackground( aVirDev );
294 if( !aFieldArr.empty() && (nFieldSelected >= aFieldArr.size()) )
295 nFieldSelected = aFieldArr.size() - 1;
296 Rectangle aFieldRect( aPos0, GetFieldSize() );
297 for( size_t nIx = 0; nIx < aFieldArr.size(); ++nIx )
299 aFieldRect.SetPos( GetFieldPosition( nIx ) );
300 bool bFocus = HasFocus() && (nIx == nFieldSelected);
301 DrawField( aVirDev, aFieldRect, aFieldArr[ nIx ], bFocus );
303 DrawBitmap( aPos0, aVirDev.GetBitmap( aPos0, aSize ) );
305 if( HasFocus() && (nFieldSelected < aFieldArr.size()) )
307 long nFieldWidth = aFieldRect.GetWidth();
308 long nSelectionWidth = Min( GetTextWidth( aFieldArr[ nFieldSelected ].first ) + 4, nFieldWidth - 6 );
309 Rectangle aSelection(
310 GetFieldPosition( nFieldSelected ) + Point( (nFieldWidth - nSelectionWidth) / 2, 3 ),
311 Size( nSelectionWidth, aFieldRect.GetHeight() - 6 ) );
312 InvertTracking( aSelection, SHOWTRACK_SMALL | SHOWTRACK_WINDOW );
315 UpdateStyle();
318 void ScDPFieldWindow::UpdateStyle()
320 WinBits nMask = ~(WB_TABSTOP | WB_NOTABSTOP);
321 SetStyle( (GetStyle() & nMask) | (IsEmpty() ? WB_NOTABSTOP : WB_TABSTOP) );
324 //-------------------------------------------------------------------
326 bool ScDPFieldWindow::IsValidIndex( size_t nIndex ) const
328 return nIndex < nFieldSize;
331 bool ScDPFieldWindow::IsExistingIndex( size_t nIndex ) const
333 return nIndex < aFieldArr.size();
336 bool ScDPFieldWindow::IsShortenedText( size_t nIndex ) const
338 return (nIndex < aFieldArr.size()) && !aFieldArr[ nIndex ].second;
341 size_t ScDPFieldWindow::CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const
343 size_t nNewField = nFieldSelected;
344 switch( eType )
346 case TYPE_PAGE:
347 nNewField += static_cast<SCsCOLROW>(nDX) + nDY * MAX_PAGEFIELDS / 2;
348 break;
349 case TYPE_COL:
350 nNewField += static_cast<SCsCOLROW>(nDX) + nDY * MAX_FIELDS / 2;
351 break;
352 case TYPE_ROW:
353 case TYPE_DATA:
354 nNewField += nDY;
355 break;
356 case TYPE_SELECT:
357 nNewField += static_cast<SCsCOLROW>(nDX) * LINE_SIZE + nDY;
358 break;
361 return IsExistingIndex( nNewField ) ? nNewField : nFieldSelected;
364 void ScDPFieldWindow::SetSelection( size_t nIndex )
366 if( !aFieldArr.empty() )
368 if( nFieldSelected >= aFieldArr.size() )
369 nFieldSelected = aFieldArr.size() - 1;
370 if( nFieldSelected != nIndex )
372 sal_Int32 nOldSelected(nFieldSelected);
373 nFieldSelected = nIndex;
374 Redraw();
376 if (pAccessible && HasFocus())
378 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
379 if (xTempAcc.is())
380 pAccessible->FieldFocusChange(nOldSelected, nFieldSelected);
381 else
382 pAccessible = NULL;
388 void ScDPFieldWindow::SetSelectionHome()
390 if( !aFieldArr.empty() )
392 if( eType == TYPE_SELECT )
393 pDlg->NotifyMoveSlider( KEY_HOME );
394 SetSelection( 0 );
398 void ScDPFieldWindow::SetSelectionEnd()
400 if( !aFieldArr.empty() )
402 if( eType == TYPE_SELECT )
403 pDlg->NotifyMoveSlider( KEY_END );
404 SetSelection( aFieldArr.size() - 1 );
408 void ScDPFieldWindow::MoveSelection( USHORT nKeyCode, SCsCOL nDX, SCsROW nDY )
410 size_t nNewIndex = CalcNewFieldIndex( nDX, nDY );
411 if( (eType == TYPE_SELECT) && (nNewIndex == nFieldSelected) )
413 if( pDlg->NotifyMoveSlider( nKeyCode ) )
415 switch( nKeyCode )
417 case KEY_UP: nNewIndex += (LINE_SIZE - 1); break;
418 case KEY_DOWN: nNewIndex -= (LINE_SIZE - 1); break;
422 SetSelection( nNewIndex );
425 void ScDPFieldWindow::ModifySelectionOffset( long nOffsetDiff )
427 nFieldSelected -= nOffsetDiff;
428 Redraw();
431 void ScDPFieldWindow::SelectNext()
433 if( eType == TYPE_SELECT )
434 MoveSelection( KEY_DOWN, 0, 1 );
437 void ScDPFieldWindow::GrabFocusWithSel( size_t nIndex )
439 SetSelection( nIndex );
440 if( !HasFocus() )
441 GrabFocus();
444 void ScDPFieldWindow::MoveField( size_t nDestIndex )
446 if( nDestIndex != nFieldSelected )
448 // "recycle" existing functionality
449 pDlg->NotifyMouseButtonDown( eType, nFieldSelected );
450 pDlg->NotifyMouseButtonUp( OutputToScreenPixel( GetFieldPosition( nDestIndex ) ) );
454 void ScDPFieldWindow::MoveFieldRel( SCsCOL nDX, SCsROW nDY )
456 MoveField( CalcNewFieldIndex( nDX, nDY ) );
459 //-------------------------------------------------------------------
461 void __EXPORT ScDPFieldWindow::Paint( const Rectangle& /* rRect */ )
463 // #124828# hiding the caption is now done from StateChanged
464 Redraw();
467 void ScDPFieldWindow::UseMnemonic()
469 // Now the FixedText has its mnemonic char. Grab the text and hide the
470 // FixedText to be able to handle tabstop and mnemonics separately.
471 if( pFtCaption )
473 SetText( pFtCaption->GetText() );
474 pFtCaption->Hide();
477 // after reading the mnemonics, tab stop style bits can be updated
478 UpdateStyle();
481 void __EXPORT ScDPFieldWindow::DataChanged( const DataChangedEvent& rDCEvt )
483 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
485 GetStyleSettings();
486 Redraw();
488 Control::DataChanged( rDCEvt );
491 void __EXPORT ScDPFieldWindow::MouseButtonDown( const MouseEvent& rMEvt )
493 if( rMEvt.IsLeft() )
495 size_t nIndex = 0;
496 if( GetFieldIndex( rMEvt.GetPosPixel(), nIndex ) && IsExistingIndex( nIndex ) )
498 GrabFocusWithSel( nIndex );
500 if( rMEvt.GetClicks() == 1 )
502 PointerStyle ePtr = pDlg->NotifyMouseButtonDown( eType, nIndex );
503 CaptureMouse();
504 SetPointer( Pointer( ePtr ) );
506 else
507 pDlg->NotifyDoubleClick( eType, nIndex );
512 void __EXPORT ScDPFieldWindow::MouseButtonUp( const MouseEvent& rMEvt )
514 if( rMEvt.IsLeft() )
516 if( rMEvt.GetClicks() == 1 )
518 pDlg->NotifyMouseButtonUp( OutputToScreenPixel( rMEvt.GetPosPixel() ) );
519 SetPointer( Pointer( POINTER_ARROW ) );
522 if( IsMouseCaptured() )
523 ReleaseMouse();
527 void __EXPORT ScDPFieldWindow::MouseMove( const MouseEvent& rMEvt )
529 if( IsMouseCaptured() )
531 PointerStyle ePtr = pDlg->NotifyMouseMove( OutputToScreenPixel( rMEvt.GetPosPixel() ) );
532 SetPointer( Pointer( ePtr ) );
534 size_t nIndex = 0;
535 if( GetFieldIndex( rMEvt.GetPosPixel(), nIndex ) && IsShortenedText( nIndex ) )
537 Point aPos = OutputToScreenPixel( rMEvt.GetPosPixel() );
538 Rectangle aRect( aPos, GetSizePixel() );
539 String aHelpText = GetFieldText(nIndex);
540 Help::ShowQuickHelp( this, aRect, aHelpText );
544 void __EXPORT ScDPFieldWindow::KeyInput( const KeyEvent& rKEvt )
546 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
547 USHORT nCode = rKeyCode.GetCode();
548 BOOL bKeyEvaluated = FALSE;
550 if( rKeyCode.IsMod1() && (eType != TYPE_SELECT) )
552 bKeyEvaluated = TRUE;
553 switch( nCode )
555 case KEY_UP: MoveFieldRel( 0, -1 ); break;
556 case KEY_DOWN: MoveFieldRel( 0, 1 ); break;
557 case KEY_LEFT: MoveFieldRel( -1, 0 ); break;
558 case KEY_RIGHT: MoveFieldRel( 1, 0 ); break;
559 case KEY_HOME: MoveField( 0 ); break;
560 case KEY_END: MoveField( aFieldArr.size() - 1 ); break;
561 default: bKeyEvaluated = FALSE;
564 else
566 bKeyEvaluated = TRUE;
567 switch( nCode )
569 case KEY_UP: MoveSelection( nCode, 0, -1 ); break;
570 case KEY_DOWN: MoveSelection( nCode, 0, 1 ); break;
571 case KEY_LEFT: MoveSelection( nCode, -1, 0 ); break;
572 case KEY_RIGHT: MoveSelection( nCode, 1, 0 ); break;
573 case KEY_HOME: SetSelectionHome(); break;
574 case KEY_END: SetSelectionEnd(); break;
575 case KEY_DELETE:
576 pDlg->NotifyRemoveField( eType, nFieldSelected ); break;
577 default: bKeyEvaluated = FALSE;
581 if( !bKeyEvaluated )
582 Control::KeyInput( rKEvt );
585 void __EXPORT ScDPFieldWindow::GetFocus()
587 Control::GetFocus();
588 Redraw();
589 if( GetGetFocusFlags() & GETFOCUS_MNEMONIC ) // move field on shortcut
590 pDlg->NotifyMoveField( eType );
591 else // else change focus
592 pDlg->NotifyFieldFocus( eType, TRUE );
594 if (pAccessible)
596 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
597 if (xTempAcc.is())
598 pAccessible->GotFocus();
599 else
600 pAccessible = NULL;
604 void __EXPORT ScDPFieldWindow::LoseFocus()
606 Control::LoseFocus();
607 Redraw();
608 pDlg->NotifyFieldFocus( eType, FALSE );
610 if (pAccessible)
612 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
613 if (xTempAcc.is())
614 pAccessible->LostFocus();
615 else
616 pAccessible = NULL;
620 //-------------------------------------------------------------------
622 void ScDPFieldWindow::AddField( const String& rText, size_t nNewIndex )
624 DBG_ASSERT( nNewIndex == aFieldArr.size(), "ScDPFieldWindow::AddField - invalid index" );
625 if( IsValidIndex( nNewIndex ) )
627 aFieldArr.push_back( FieldString( rText, true ) );
628 if (pAccessible)
630 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
631 if (xTempAcc.is())
632 pAccessible->AddField(nNewIndex);
633 else
634 pAccessible = NULL;
639 void ScDPFieldWindow::DelField( size_t nDelIndex )
641 if( IsExistingIndex( nDelIndex ) )
643 if (pAccessible) // before decrement fieldcount
645 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
646 if (xTempAcc.is())
647 pAccessible->RemoveField(nDelIndex);
648 else
649 pAccessible = NULL;
651 aFieldArr.erase( aFieldArr.begin() + nDelIndex );
652 Redraw();
656 void ScDPFieldWindow::ClearFields()
658 if( eType == TYPE_SELECT || eType == TYPE_PAGE || eType == TYPE_COL || eType == TYPE_ROW || eType == TYPE_DATA)
660 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
661 if (!xTempAcc.is() && pAccessible)
662 pAccessible = NULL;
663 if (pAccessible)
664 for( size_t nIdx = aFieldArr.size(); nIdx > 0; --nIdx )
665 pAccessible->RemoveField( nIdx - 1 );
667 aFieldArr.clear();
671 void ScDPFieldWindow::SetFieldText( const String& rText, size_t nIndex )
673 if( IsExistingIndex( nIndex ) )
675 aFieldArr[ nIndex ] = FieldString( rText, true );
676 Redraw();
678 if (pAccessible)
680 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
681 if (xTempAcc.is())
682 pAccessible->FieldNameChange(nIndex);
683 else
684 pAccessible = NULL;
689 const String& ScDPFieldWindow::GetFieldText( size_t nIndex ) const
691 if( IsExistingIndex( nIndex ) )
692 return aFieldArr[ nIndex ].first;
693 return EMPTY_STRING;
696 //-------------------------------------------------------------------
698 bool ScDPFieldWindow::AddField( const String& rText, const Point& rPos, size_t& rnIndex )
700 if ( aFieldArr.size() == nFieldSize )
701 return FALSE;
703 size_t nNewIndex = 0;
704 if( GetFieldIndex( rPos, nNewIndex ) )
706 if( nNewIndex > aFieldArr.size() )
707 nNewIndex = aFieldArr.size();
709 aFieldArr.insert( aFieldArr.begin() + nNewIndex, FieldString( rText, true ) );
710 nFieldSelected = nNewIndex;
711 Redraw();
712 rnIndex = nNewIndex;
714 if (pAccessible)
716 com::sun::star::uno::Reference < com::sun::star::accessibility::XAccessible > xTempAcc = xAccessible;
717 if (xTempAcc.is())
718 pAccessible->AddField(nNewIndex);
719 else
720 pAccessible = NULL;
723 return true;
726 return false;
729 void ScDPFieldWindow::GetExistingIndex( const Point& rPos, size_t& rnIndex )
731 if( !aFieldArr.empty() && (eType != TYPE_SELECT) && GetFieldIndex( rPos, rnIndex ) )
733 if( rnIndex >= aFieldArr.size() )
734 rnIndex = aFieldArr.size() - 1;
736 else
737 rnIndex = 0;
740 String ScDPFieldWindow::GetDescription() const
742 String sDescription;
743 switch( eType )
745 case TYPE_COL:
746 sDescription = ScResId(STR_ACC_DATAPILOT_COL_DESCR);
747 break;
748 case TYPE_ROW:
749 sDescription = ScResId(STR_ACC_DATAPILOT_ROW_DESCR);
750 break;
751 case TYPE_DATA:
752 sDescription = ScResId(STR_ACC_DATAPILOT_DATA_DESCR);
753 break;
754 case TYPE_SELECT:
755 sDescription = ScResId(STR_ACC_DATAPILOT_SEL_DESCR);
756 break;
757 default:
759 // added to avoid warnings
762 return sDescription;
765 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScDPFieldWindow::CreateAccessible()
767 pAccessible =
768 new ScAccessibleDataPilotControl(GetAccessibleParentWindow()->GetAccessible(), this);
770 com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xReturn = pAccessible;
772 pAccessible->Init();
773 xAccessible = xReturn;
775 return xReturn;
778 //===================================================================