Update ooo320-m1
[ooovba.git] / svtools / source / contnr / ivctrl.cxx
blobae2f3314c951598ec2a5e0e3722fd07ac6c3118b
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: ivctrl.cxx,v $
10 * $Revision: 1.24 $
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_svtools.hxx"
34 #ifndef GCC
35 #endif
37 #include "ivctrl.hxx"
38 #include "imivctl.hxx"
39 #include <vcl/bitmapex.hxx>
40 #include <vcl/controllayout.hxx>
41 #include <vcl/mnemonic.hxx>
42 using namespace ::com::sun::star::accessibility;
44 /*****************************************************************************
46 | class : SvxIconChoiceCtrlEntry
48 \*****************************************************************************/
50 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, USHORT _nFlags )
52 aText = rText;
53 aImage = rImage;
54 aImageHC = rImage;
55 pUserData = NULL;
57 nFlags = _nFlags;
58 eTextMode = IcnShowTextShort;
59 pblink = 0;
60 pflink = 0;
63 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const String& rText, const Image& rImage, const Image& rImageHC, USHORT _nFlags )
65 aText = rText;
66 aImage = rImage;
67 aImageHC = rImageHC;
68 pUserData = NULL;
70 nFlags = _nFlags;
71 eTextMode = IcnShowTextShort;
72 pblink = 0;
73 pflink = 0;
76 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( USHORT _nFlags )
78 pUserData = NULL;
80 nFlags = _nFlags;
81 eTextMode = IcnShowTextShort;
82 pblink = 0;
83 pflink = 0;
86 void SvxIconChoiceCtrlEntry::SetMoved( BOOL bMoved )
88 if( bMoved )
89 nFlags |= ICNVIEW_FLAG_POS_MOVED;
90 else
91 nFlags &= ~ICNVIEW_FLAG_POS_MOVED;
94 void SvxIconChoiceCtrlEntry::LockPos( BOOL bLock )
96 if( bLock )
97 nFlags |= ICNVIEW_FLAG_POS_LOCKED;
98 else
99 nFlags &= ~ICNVIEW_FLAG_POS_LOCKED;
102 /*sal_Unicode SvxIconChoiceCtrlEntry::GetMnemonicChar() const
104 sal_Unicode cChar = 0;
105 xub_StrLen nPos = aText.Search( '~' );
106 if ( nPos != STRING_NOTFOUND && nPos < ( aText.Len() ) - 1 )
107 cChar = aText.GetChar( nPos + 1 );
108 return cChar;
111 String SvxIconChoiceCtrlEntry::GetDisplayText() const
113 return MnemonicGenerator::EraseAllMnemonicChars( aText );
116 // ----------------------------------------------------------------------------
118 SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& rInfo )
119 : aColText( rInfo.aColText ), aColImage( rInfo.aColImage )
121 nWidth = rInfo.nWidth;
122 eAlignment = rInfo.eAlignment;
123 nSubItem = rInfo.nSubItem;
126 /*****************************************************************************
128 | class : SvtIconChoiceCtrl
130 \*****************************************************************************/
132 SvtIconChoiceCtrl::SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle ) :
134 // WB_CLIPCHILDREN an, da ScrollBars auf dem Fenster liegen!
135 Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
137 _pCurKeyEvent ( NULL ),
138 _pImp ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
139 _bAutoFontColor ( FALSE )
142 SetLineColor();
143 _pImp->SetGrid( Size( 100, 70 ) );
144 _pImp->InitSettings();
145 _pImp->SetPositionMode( IcnViewPositionModeAutoArrange );
148 SvtIconChoiceCtrl::SvtIconChoiceCtrl( Window* pParent, const ResId& rResId ) :
150 Control( pParent, rResId ),
152 _pCurKeyEvent ( NULL ),
153 _pImp ( new SvxIconChoiceCtrl_Impl( this, WB_BORDER ) ),
154 _bAutoFontColor ( FALSE )
157 SetLineColor();
158 _pImp->SetGrid( Size( 100, 70 ) );
159 _pImp->InitSettings();
160 _pImp->SetPositionMode( IcnViewPositionModeAutoArrange );
163 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
165 _pImp->CallEventListeners( VCLEVENT_OBJECT_DYING );
166 delete _pImp;
169 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( ULONG nPos, const Point* pPos, USHORT nFlags )
171 SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( nFlags );
172 _pImp->InsertEntry( pEntry, nPos, pPos );
173 return pEntry;
176 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const String& rText, const Image& rImage, ULONG nPos, const Point* pPos, USHORT nFlags )
178 SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage, nFlags);
180 _pImp->InsertEntry( pEntry, nPos, pPos );
182 return pEntry;
185 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const String& rText, const Image& rImage, const Image& rImageHC, ULONG nPos, const Point* pPos, USHORT nFlags )
187 SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage, rImageHC, nFlags);
189 _pImp->InsertEntry( pEntry, nPos, pPos );
191 return pEntry;
194 BOOL SvtIconChoiceCtrl::EditedEntry( SvxIconChoiceCtrlEntry*, const XubString&, BOOL )
196 return TRUE;
198 BOOL SvtIconChoiceCtrl::EditingEntry( SvxIconChoiceCtrlEntry* )
200 return TRUE;
202 void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos, OutputDevice& rDev )
204 rDev.DrawImage ( rPos, GetDisplayBackground().GetColor().IsDark() ? pEntry->GetImageHC() : pEntry->GetImage() );
206 String SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry* pEntry, BOOL )
208 return pEntry->GetText();
210 BOOL SvtIconChoiceCtrl::HasBackground() const
212 return FALSE;
214 BOOL SvtIconChoiceCtrl::HasFont() const
216 return FALSE;
218 BOOL SvtIconChoiceCtrl::HasFontTextColor() const
220 return TRUE;
222 BOOL SvtIconChoiceCtrl::HasFontFillColor() const
224 return TRUE;
227 void SvtIconChoiceCtrl::Paint( const Rectangle& rRect )
229 _pImp->Paint( rRect );
232 void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent& rMEvt )
234 if( !_pImp->MouseButtonDown( rMEvt ) )
235 Control::MouseButtonDown( rMEvt );
238 void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent& rMEvt )
240 if( !_pImp->MouseButtonUp( rMEvt ) )
241 Control::MouseButtonUp( rMEvt );
244 void SvtIconChoiceCtrl::MouseMove( const MouseEvent& rMEvt )
246 if( !_pImp->MouseMove( rMEvt ) )
247 Control::MouseMove( rMEvt );
249 void SvtIconChoiceCtrl::ArrangeIcons()
251 if ( GetStyle() & WB_ALIGN_TOP )
253 Size aFullSize;
254 Rectangle aEntryRect;
256 for ( ULONG i = 0; i < GetEntryCount(); i++ )
258 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
259 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
261 aFullSize.setWidth ( aFullSize.getWidth()+aEntryRect.GetWidth() );
264 _pImp->Arrange ( FALSE, aFullSize.getWidth() );
266 else if ( GetStyle() & WB_ALIGN_LEFT )
268 Size aFullSize;
269 Rectangle aEntryRect;
271 for ( ULONG i = 0; i < GetEntryCount(); i++ )
273 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
274 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
276 aFullSize.setHeight ( aFullSize.getHeight()+aEntryRect.GetHeight() );
279 _pImp->Arrange ( FALSE, 0, aFullSize.getHeight() );
281 else
283 _pImp->Arrange();
285 _pImp->Arrange( FALSE, 0, 1000 );
287 void SvtIconChoiceCtrl::Resize()
289 _pImp->Resize();
290 Control::Resize();
293 Point SvtIconChoiceCtrl::GetLogicPos( const Point& rPosPixel ) const
295 Point aPos( rPosPixel );
296 aPos -= GetMapMode().GetOrigin();
297 return aPos;
300 Point SvtIconChoiceCtrl::GetPixelPos( const Point& rPosLogic ) const
302 Point aPos( rPosLogic );
303 aPos += GetMapMode().GetOrigin();
304 return aPos;
307 void SvtIconChoiceCtrl::DocumentRectChanged()
309 _aDocRectChangedHdl.Call( this );
312 void SvtIconChoiceCtrl::VisibleRectChanged()
314 _aVisRectChangedHdl.Call( this );
317 void SvtIconChoiceCtrl::GetFocus()
319 _pImp->GetFocus();
320 Control::GetFocus();
321 ULONG nPos;
322 SvxIconChoiceCtrlEntry* pSelectedEntry = GetSelectedEntry ( nPos );
323 if ( pSelectedEntry )
324 _pImp->CallEventListeners( VCLEVENT_LISTBOX_SELECT, pSelectedEntry );
327 void SvtIconChoiceCtrl::LoseFocus()
329 _pImp->LoseFocus();
330 Control::LoseFocus();
333 void SvtIconChoiceCtrl::SetUpdateMode( BOOL bUpdate )
335 Control::SetUpdateMode( bUpdate );
336 _pImp->SetUpdateMode( bUpdate );
338 void SvtIconChoiceCtrl::SetFont( const Font& rFont )
340 if( rFont != GetFont() )
342 Control::SetFont( rFont );
343 _pImp->FontModified();
347 void SvtIconChoiceCtrl::SetPointFont( const Font& rFont )
349 if( rFont != GetPointFont() )
351 Control::SetPointFont( rFont );
352 _pImp->FontModified();
355 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( const Point& rPixPos, BOOL bHit ) const
357 Point aPos( rPixPos );
358 aPos -= GetMapMode().GetOrigin();
359 return ((SvtIconChoiceCtrl*)this)->_pImp->GetEntry( aPos, bHit );
362 void SvtIconChoiceCtrl::SetStyle( WinBits nWinStyle )
364 _pImp->SetStyle( nWinStyle );
367 WinBits SvtIconChoiceCtrl::GetStyle() const
369 return _pImp->GetStyle();
371 void SvtIconChoiceCtrl::Command( const CommandEvent& rCEvt )
373 _pImp->Command( rCEvt );
376 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry )
378 _pImp->SetEntryTextMode( eMode, pEntry );
381 SvxIconChoiceCtrlTextMode SvtIconChoiceCtrl::GetEntryTextMode( const SvxIconChoiceCtrlEntry* pEntry ) const
383 return _pImp->GetEntryTextModeSmart( pEntry );
386 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetNextEntry( const Point& rPixPos, SvxIconChoiceCtrlEntry* pCurEntry, BOOL ) const
388 Point aPos( rPixPos );
389 aPos -= GetMapMode().GetOrigin();
390 return ((SvtIconChoiceCtrl*)this)->_pImp->GetNextEntry( aPos, pCurEntry );
393 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetPrevEntry( const Point& rPixPos, SvxIconChoiceCtrlEntry* pCurEntry, BOOL ) const
395 Point aPos( rPixPos );
396 aPos -= GetMapMode().GetOrigin();
397 return ((SvtIconChoiceCtrl*)this)->_pImp->GetPrevEntry( aPos, pCurEntry );
399 ULONG SvtIconChoiceCtrl::GetEntryCount() const
401 return _pImp->GetEntryCount();
404 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( ULONG nPos ) const
406 return _pImp->GetEntry( nPos );
409 void SvtIconChoiceCtrl::CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics )
411 _pImp->CreateAutoMnemonics( &_rUsedMnemonics );
414 void SvtIconChoiceCtrl::CreateAutoMnemonics( void )
416 _pImp->CreateAutoMnemonics();
419 void SvtIconChoiceCtrl::RemoveEntry( SvxIconChoiceCtrlEntry* pEntry )
421 _pImp->RemoveEntry( pEntry );
424 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetSelectedEntry( ULONG& rPos ) const
426 return _pImp->GetFirstSelectedEntry( rPos );
429 void SvtIconChoiceCtrl::ClickIcon()
431 ULONG nPos;
432 GetSelectedEntry ( nPos );
433 _aClickIconHdl.Call( this );
435 BOOL SvtIconChoiceCtrl::IsEntryEditing() const
437 return _pImp->IsEntryEditing();
440 BOOL SvtIconChoiceCtrl::SetChoiceWithCursor ( BOOL bDo )
442 return _pImp->SetChoiceWithCursor (bDo);
445 void SvtIconChoiceCtrl::KeyInput( const KeyEvent& rKEvt )
447 BOOL bKeyUsed = DoKeyInput( rKEvt );
448 if ( !bKeyUsed )
450 _pCurKeyEvent = (KeyEvent*)&rKEvt;
451 Control::KeyInput( rKEvt );
452 _pCurKeyEvent = NULL;
455 BOOL SvtIconChoiceCtrl::DoKeyInput( const KeyEvent& rKEvt )
457 // unter OS/2 bekommen wir auch beim Editieren Key-Up/Down
458 if( IsEntryEditing() )
459 return TRUE;
460 _pCurKeyEvent = (KeyEvent*)&rKEvt;
461 BOOL bHandled = _pImp->KeyInput( rKEvt );
462 _pCurKeyEvent = NULL;
463 return bHandled;
465 ULONG SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const
467 return _pImp->GetEntryListPos( pEntry );
469 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetCursor( ) const
471 return _pImp->GetCurEntry( );
473 void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry* pEntry )
475 _pImp->SetCursor( pEntry );
477 void SvtIconChoiceCtrl::InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry )
479 _pImp->InvalidateEntry( pEntry );
481 void SvtIconChoiceCtrl::Clear()
483 _pImp->Clear();
485 void SvtIconChoiceCtrl::StateChanged( StateChangedType nType )
487 Control::StateChanged( nType );
491 void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent& rDCEvt )
493 if ( ((rDCEvt.GetType() == DATACHANGED_SETTINGS) ||
494 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
495 (rDCEvt.GetType() == DATACHANGED_FONTS) ) &&
496 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
498 _pImp->InitSettings();
499 Invalidate(INVALIDATE_NOCHILDREN);
501 else
502 Control::DataChanged( rDCEvt );
505 void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper )
507 if( rPaper != GetBackground() )
509 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
510 Wallpaper aEmpty;
511 if( rPaper == aEmpty )
512 Control::SetBackground( rStyleSettings.GetFieldColor() );
513 else
515 Wallpaper aBackground( rPaper );
516 // HACK, da Hintergrund sonst transparent sein koennte
517 if( !aBackground.IsBitmap() )
518 aBackground.SetStyle( WALLPAPER_TILE );
520 WallpaperStyle eStyle = aBackground.GetStyle();
521 Color aBack( aBackground.GetColor());
522 Color aTrans( COL_TRANSPARENT );
523 if( aBack == aTrans && (
524 (!aBackground.IsBitmap() ||
525 aBackground.GetBitmap().IsTransparent() ||
526 (eStyle != WALLPAPER_TILE && eStyle != WALLPAPER_SCALE))))
528 aBackground.SetColor( rStyleSettings.GetFieldColor() );
530 if( aBackground.IsScrollable() )
532 Rectangle aRect;
533 aRect.SetSize( Size(32765, 32765) );
534 aBackground.SetRect( aRect );
536 else
538 Rectangle aRect( _pImp->GetOutputRect() );
539 aBackground.SetRect( aRect );
541 Control::SetBackground( aBackground );
544 // bei hart attributierter Textfarbe keine 'Automatik', die eine
545 // lesbare Textfarbe einstellt.
546 Font aFont( GetFont() );
547 aFont.SetColor( rStyleSettings.GetFieldTextColor() );
548 SetFont( aFont );
550 Invalidate(INVALIDATE_NOCHILDREN);
554 void SvtIconChoiceCtrl::Flush()
556 _pImp->Flush();
559 void SvtIconChoiceCtrl::RequestHelp( const HelpEvent& rHEvt )
561 if ( !_pImp->RequestHelp( rHEvt ) )
562 Control::RequestHelp( rHEvt );
565 void SvtIconChoiceCtrl::SetSelectionMode( SelectionMode eMode )
567 _pImp->SetSelectionMode( eMode );
570 BOOL SvtIconChoiceCtrl::HandleShortCutKey( const KeyEvent& r )
572 return _pImp->HandleShortCutKey( r );
575 Rectangle SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const
577 return _pImp->GetEntryBoundRect( pEntry );
580 void SvtIconChoiceCtrl::FillLayoutData() const
582 DBG_ASSERT( !mpLayoutData, "SvtIconChoiceCtrl::FillLayoutData: shouldn't this be called with non-existent layout data only?" );
583 mpLayoutData = new ::vcl::ControlLayoutData();
585 SvtIconChoiceCtrl* pNonConstMe = const_cast< SvtIconChoiceCtrl* >( this );
587 // loop through all entries
588 sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
589 sal_uInt16 nPos = 0;
590 while ( nPos < nCount )
592 SvxIconChoiceCtrlEntry* pEntry = GetEntry( nPos );
594 Point aPos = _pImp->GetEntryBoundRect( pEntry ).TopLeft();
595 String sEntryText = pEntry->GetDisplayText( );
596 Rectangle aTextRect = _pImp->CalcTextRect( pEntry, &aPos, sal_False, &sEntryText );
598 sal_Bool bLargeIconMode = WB_ICON == ( _pImp->GetStyle() & ( VIEWMODE_MASK ) );
599 sal_uInt16 nTextPaintFlags = bLargeIconMode ? PAINTFLAG_HOR_CENTERED : PAINTFLAG_VER_CENTERED;
601 _pImp->PaintItem( aTextRect, IcnViewFieldTypeText, pEntry, nTextPaintFlags, pNonConstMe, &sEntryText, mpLayoutData );
603 ++nPos;
607 Rectangle SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
609 Rectangle aRect;
611 Pair aEntryCharacterRange = GetLineStartEnd( _nEntryPos );
612 if ( aEntryCharacterRange.A() + _nCharacterIndex < aEntryCharacterRange.B() )
614 aRect = GetCharacterBounds( aEntryCharacterRange.A() + _nCharacterIndex );
617 return aRect;
620 void SvtIconChoiceCtrl::SetNoSelection()
622 _pImp->SetNoSelection();
625 void SvtIconChoiceCtrl::CallImplEventListeners(ULONG nEvent, void* pData)
627 CallEventListeners(nEvent, pData);
629 ::com::sun::star::uno::Reference< XAccessible > SvtIconChoiceCtrl::CreateAccessible()
631 Window* pParent = GetAccessibleParentWindow();
632 DBG_ASSERT( pParent, "SvTreeListBox::CreateAccessible - accessible parent not found" );
634 ::com::sun::star::uno::Reference< XAccessible > xAccessible;
635 if ( pParent )
637 ::com::sun::star::uno::Reference< XAccessible > xAccParent = pParent->GetAccessible();
638 if ( xAccParent.is() )
640 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xTemp(GetComponentInterface());
641 xAccessible = _pImp->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent );
644 return xAccessible;