GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / contnr / ivctrl.cxx
blob09f46caf5473b1a76ca187c3d6ec0d44355e71f5
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 .
21 #include <svtools/ivctrl.hxx>
22 #include "imivctl.hxx"
23 #include <vcl/bitmapex.hxx>
24 #include <vcl/controllayout.hxx>
25 #include <vcl/mnemonic.hxx>
26 using namespace ::com::sun::star::accessibility;
28 /*****************************************************************************
30 | class : SvxIconChoiceCtrlEntry
32 \*****************************************************************************/
34 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage, sal_uInt16 _nFlags )
36 aText = rText;
37 aImage = rImage;
38 pUserData = NULL;
40 nFlags = _nFlags;
41 eTextMode = IcnShowTextShort;
42 pblink = 0;
43 pflink = 0;
46 OUString SvxIconChoiceCtrlEntry::GetDisplayText() const
48 return MnemonicGenerator::EraseAllMnemonicChars( aText );
51 // ----------------------------------------------------------------------------
53 SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& rInfo )
54 : aColText( rInfo.aColText ), aColImage( rInfo.aColImage )
56 nWidth = rInfo.nWidth;
57 eAlignment = rInfo.eAlignment;
58 nSubItem = rInfo.nSubItem;
61 /*****************************************************************************
63 | class : SvtIconChoiceCtrl
65 \*****************************************************************************/
67 SvtIconChoiceCtrl::SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle ) :
69 // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
70 Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
72 _pCurKeyEvent ( NULL ),
73 _pImp ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
74 _bAutoFontColor ( sal_False )
77 SetLineColor();
78 _pImp->SetGrid( Size( 100, 70 ) );
79 _pImp->InitSettings();
80 _pImp->SetPositionMode( IcnViewPositionModeAutoArrange );
83 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
85 _pImp->CallEventListeners( VCLEVENT_OBJECT_DYING );
86 delete _pImp;
89 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const OUString& rText, const Image& rImage, sal_uLong nPos, const Point* pPos, sal_uInt16 nFlags )
91 SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage, nFlags);
93 _pImp->InsertEntry( pEntry, nPos, pPos );
95 return pEntry;
98 sal_Bool SvtIconChoiceCtrl::EditedEntry( SvxIconChoiceCtrlEntry*, const OUString&, sal_Bool )
100 return sal_True;
103 sal_Bool SvtIconChoiceCtrl::EditingEntry( SvxIconChoiceCtrlEntry* )
105 return sal_True;
108 void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos, OutputDevice& rDev )
110 rDev.DrawImage( rPos, pEntry->GetImage() );
113 OUString SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry* pEntry, sal_Bool )
115 return pEntry->GetText();
118 sal_Bool SvtIconChoiceCtrl::HasBackground() const
120 return sal_False;
123 sal_Bool SvtIconChoiceCtrl::HasFont() const
125 return sal_False;
128 sal_Bool SvtIconChoiceCtrl::HasFontTextColor() const
130 return sal_True;
133 sal_Bool SvtIconChoiceCtrl::HasFontFillColor() const
135 return sal_True;
138 void SvtIconChoiceCtrl::Paint( const Rectangle& rRect )
140 _pImp->Paint( rRect );
143 void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent& rMEvt )
145 if( !_pImp->MouseButtonDown( rMEvt ) )
146 Control::MouseButtonDown( rMEvt );
149 void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent& rMEvt )
151 if( !_pImp->MouseButtonUp( rMEvt ) )
152 Control::MouseButtonUp( rMEvt );
155 void SvtIconChoiceCtrl::MouseMove( const MouseEvent& rMEvt )
157 if( !_pImp->MouseMove( rMEvt ) )
158 Control::MouseMove( rMEvt );
160 void SvtIconChoiceCtrl::ArrangeIcons()
162 if ( GetStyle() & WB_ALIGN_TOP )
164 Size aFullSize;
165 Rectangle aEntryRect;
167 for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
169 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
170 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
172 aFullSize.setWidth ( aFullSize.getWidth()+aEntryRect.GetWidth() );
175 _pImp->Arrange ( sal_False, aFullSize.getWidth() );
177 else if ( GetStyle() & WB_ALIGN_LEFT )
179 Size aFullSize;
180 Rectangle aEntryRect;
182 for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
184 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
185 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
187 aFullSize.setHeight ( aFullSize.getHeight()+aEntryRect.GetHeight() );
190 _pImp->Arrange ( sal_False, 0, aFullSize.getHeight() );
192 else
194 _pImp->Arrange();
196 _pImp->Arrange( sal_False, 0, 1000 );
198 void SvtIconChoiceCtrl::Resize()
200 _pImp->Resize();
201 Control::Resize();
204 Point SvtIconChoiceCtrl::GetPixelPos( const Point& rPosLogic ) const
206 Point aPos( rPosLogic );
207 aPos += GetMapMode().GetOrigin();
208 return aPos;
211 void SvtIconChoiceCtrl::DocumentRectChanged()
213 _aDocRectChangedHdl.Call( this );
216 void SvtIconChoiceCtrl::VisibleRectChanged()
218 _aVisRectChangedHdl.Call( this );
221 void SvtIconChoiceCtrl::GetFocus()
223 _pImp->GetFocus();
224 Control::GetFocus();
225 sal_uLong nPos;
226 SvxIconChoiceCtrlEntry* pSelectedEntry = GetSelectedEntry ( nPos );
227 if ( pSelectedEntry )
228 _pImp->CallEventListeners( VCLEVENT_LISTBOX_SELECT, pSelectedEntry );
231 void SvtIconChoiceCtrl::LoseFocus()
233 _pImp->LoseFocus();
234 Control::LoseFocus();
237 void SvtIconChoiceCtrl::SetFont( const Font& rFont )
239 if( rFont != GetFont() )
241 Control::SetFont( rFont );
242 _pImp->FontModified();
246 void SvtIconChoiceCtrl::SetPointFont( const Font& rFont )
248 if( rFont != GetPointFont() )
250 Control::SetPointFont( rFont );
251 _pImp->FontModified();
254 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( const Point& rPixPos, sal_Bool bHit ) const
256 Point aPos( rPixPos );
257 aPos -= GetMapMode().GetOrigin();
258 return ((SvtIconChoiceCtrl*)this)->_pImp->GetEntry( aPos, bHit );
261 void SvtIconChoiceCtrl::SetStyle( WinBits nWinStyle )
263 _pImp->SetStyle( nWinStyle );
266 WinBits SvtIconChoiceCtrl::GetStyle() const
268 return _pImp->GetStyle();
270 void SvtIconChoiceCtrl::Command( const CommandEvent& rCEvt )
272 _pImp->Command( rCEvt );
275 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry )
277 _pImp->SetEntryTextMode( eMode, pEntry );
280 sal_uLong SvtIconChoiceCtrl::GetEntryCount() const
282 return _pImp->GetEntryCount();
285 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( sal_uLong nPos ) const
287 return _pImp->GetEntry( nPos );
290 void SvtIconChoiceCtrl::CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics )
292 _pImp->CreateAutoMnemonics( &_rUsedMnemonics );
295 void SvtIconChoiceCtrl::CreateAutoMnemonics( void )
297 _pImp->CreateAutoMnemonics();
300 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetSelectedEntry( sal_uLong& rPos ) const
302 return _pImp->GetFirstSelectedEntry( rPos );
305 void SvtIconChoiceCtrl::ClickIcon()
307 sal_uLong nPos;
308 GetSelectedEntry ( nPos );
309 _aClickIconHdl.Call( this );
311 sal_Bool SvtIconChoiceCtrl::IsEntryEditing() const
313 return _pImp->IsEntryEditing();
316 sal_Bool SvtIconChoiceCtrl::SetChoiceWithCursor ( sal_Bool bDo )
318 return _pImp->SetChoiceWithCursor (bDo);
321 void SvtIconChoiceCtrl::KeyInput( const KeyEvent& rKEvt )
323 sal_Bool bKeyUsed = DoKeyInput( rKEvt );
324 if ( !bKeyUsed )
326 _pCurKeyEvent = (KeyEvent*)&rKEvt;
327 Control::KeyInput( rKEvt );
328 _pCurKeyEvent = NULL;
331 sal_Bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent& rKEvt )
333 // under OS/2, we get key up/down even while editing
334 if( IsEntryEditing() )
335 return sal_True;
336 _pCurKeyEvent = (KeyEvent*)&rKEvt;
337 sal_Bool bHandled = _pImp->KeyInput( rKEvt );
338 _pCurKeyEvent = NULL;
339 return bHandled;
341 sal_uLong SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const
343 return _pImp->GetEntryListPos( pEntry );
345 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetCursor( ) const
347 return _pImp->GetCurEntry( );
349 void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry* pEntry )
351 _pImp->SetCursor( pEntry );
353 void SvtIconChoiceCtrl::InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry )
355 _pImp->InvalidateEntry( pEntry );
358 void SvtIconChoiceCtrl::StateChanged( StateChangedType nType )
360 Control::StateChanged( nType );
364 void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent& rDCEvt )
366 if ( ((rDCEvt.GetType() == DATACHANGED_SETTINGS) ||
367 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
368 (rDCEvt.GetType() == DATACHANGED_FONTS) ) &&
369 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
371 _pImp->InitSettings();
372 Invalidate(INVALIDATE_NOCHILDREN);
374 else
375 Control::DataChanged( rDCEvt );
378 void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper )
380 if( rPaper != GetBackground() )
382 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
383 Wallpaper aEmpty;
384 if( rPaper == aEmpty )
385 Control::SetBackground( rStyleSettings.GetFieldColor() );
386 else
388 Wallpaper aBackground( rPaper );
389 // HACK, as background might be transparent!
390 if( !aBackground.IsBitmap() )
391 aBackground.SetStyle( WALLPAPER_TILE );
393 WallpaperStyle eStyle = aBackground.GetStyle();
394 Color aBack( aBackground.GetColor());
395 Color aTrans( COL_TRANSPARENT );
396 if( aBack == aTrans && (
397 (!aBackground.IsBitmap() ||
398 aBackground.GetBitmap().IsTransparent() ||
399 (eStyle != WALLPAPER_TILE && eStyle != WALLPAPER_SCALE))))
401 aBackground.SetColor( rStyleSettings.GetFieldColor() );
403 if( aBackground.IsScrollable() )
405 Rectangle aRect;
406 aRect.SetSize( Size(32765, 32765) );
407 aBackground.SetRect( aRect );
409 else
411 Rectangle aRect( _pImp->GetOutputRect() );
412 aBackground.SetRect( aRect );
414 Control::SetBackground( aBackground );
417 // If text colors are attributed "hard," don't use automatism to select
418 // a readable text color.
419 Font aFont( GetFont() );
420 aFont.SetColor( rStyleSettings.GetFieldTextColor() );
421 SetFont( aFont );
423 Invalidate(INVALIDATE_NOCHILDREN);
427 void SvtIconChoiceCtrl::RequestHelp( const HelpEvent& rHEvt )
429 if ( !_pImp->RequestHelp( rHEvt ) )
430 Control::RequestHelp( rHEvt );
433 void SvtIconChoiceCtrl::SetSelectionMode( SelectionMode eMode )
435 _pImp->SetSelectionMode( eMode );
438 Rectangle SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const
440 return _pImp->GetEntryBoundRect( pEntry );
443 void SvtIconChoiceCtrl::FillLayoutData() const
445 CreateLayoutData();
447 SvtIconChoiceCtrl* pNonConstMe = const_cast< SvtIconChoiceCtrl* >( this );
449 // loop through all entries
450 sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
451 sal_uInt16 nPos = 0;
452 while ( nPos < nCount )
454 SvxIconChoiceCtrlEntry* pEntry = GetEntry( nPos );
456 Point aPos = _pImp->GetEntryBoundRect( pEntry ).TopLeft();
457 OUString sEntryText = pEntry->GetDisplayText( );
458 Rectangle aTextRect = _pImp->CalcTextRect( pEntry, &aPos, sal_False, &sEntryText );
460 sal_Bool bLargeIconMode = WB_ICON == ( _pImp->GetStyle() & ( VIEWMODE_MASK ) );
461 sal_uInt16 nTextPaintFlags = bLargeIconMode ? PAINTFLAG_HOR_CENTERED : PAINTFLAG_VER_CENTERED;
463 _pImp->PaintItem( aTextRect, IcnViewFieldTypeText, pEntry, nTextPaintFlags, pNonConstMe, &sEntryText, GetLayoutData() );
465 ++nPos;
469 Rectangle SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
471 Rectangle aRect;
473 Pair aEntryCharacterRange = GetLineStartEnd( _nEntryPos );
474 if ( aEntryCharacterRange.A() + _nCharacterIndex < aEntryCharacterRange.B() )
476 aRect = GetCharacterBounds( aEntryCharacterRange.A() + _nCharacterIndex );
479 return aRect;
482 void SvtIconChoiceCtrl::SetNoSelection()
484 _pImp->SetNoSelection();
487 void SvtIconChoiceCtrl::CallImplEventListeners(sal_uLong nEvent, void* pData)
489 CallEventListeners(nEvent, pData);
491 ::com::sun::star::uno::Reference< XAccessible > SvtIconChoiceCtrl::CreateAccessible()
493 Window* pParent = GetAccessibleParentWindow();
494 DBG_ASSERT( pParent, "SvTreeListBox::CreateAccessible - accessible parent not found" );
496 ::com::sun::star::uno::Reference< XAccessible > xAccessible;
497 if ( pParent )
499 ::com::sun::star::uno::Reference< XAccessible > xAccParent = pParent->GetAccessible();
500 if ( xAccParent.is() )
502 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xTemp(GetComponentInterface());
503 xAccessible = _pImp->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent );
506 return xAccessible;
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */