Branch libreoffice-5-0-4
[LibreOffice.git] / svtools / source / contnr / ivctrl.cxx
blob56fff117da27d16619722b5a5d80bddfe8e34379
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 #include <vcl/settings.hxx>
28 using namespace ::com::sun::star::accessibility;
30 /*****************************************************************************
32 | class : SvxIconChoiceCtrlEntry
34 \*****************************************************************************/
36 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const OUString& rText,
37 const Image& rImage,
38 SvxIconViewFlags _nFlags )
39 : aImage(rImage)
40 , aText(rText)
41 , pUserData(NULL)
42 , nPos(0)
43 , pblink(0)
44 , pflink(0)
45 , eTextMode(IcnShowTextShort)
46 , nX(0)
47 , nY(0)
48 , nFlags(_nFlags)
52 OUString SvxIconChoiceCtrlEntry::GetDisplayText() const
54 return MnemonicGenerator::EraseAllMnemonicChars( aText );
59 SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& rInfo )
60 : aColText( rInfo.aColText ), aColImage( rInfo.aColImage )
62 nWidth = rInfo.nWidth;
63 eAlignment = rInfo.eAlignment;
64 nSubItem = rInfo.nSubItem;
67 /*****************************************************************************
69 | class : SvtIconChoiceCtrl
71 \*****************************************************************************/
73 SvtIconChoiceCtrl::SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle ) :
75 // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
76 Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
78 _pCurKeyEvent ( NULL ),
79 _pImp ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
80 _bAutoFontColor ( false )
83 SetLineColor();
84 _pImp->SetGrid( Size( 100, 70 ) );
85 _pImp->InitSettings();
86 _pImp->SetPositionMode( IcnViewPositionModeAutoArrange );
89 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
91 disposeOnce();
94 void SvtIconChoiceCtrl::dispose()
96 if (_pImp)
98 _pImp->CallEventListeners( VCLEVENT_OBJECT_DYING );
99 delete _pImp;
100 _pImp = NULL;
102 Control::dispose();
105 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const OUString& rText, const Image& rImage, sal_uLong nPos, const Point* pPos, SvxIconViewFlags nFlags )
107 SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage, nFlags);
109 _pImp->InsertEntry( pEntry, nPos, pPos );
111 return pEntry;
114 void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos, OutputDevice& rDev )
116 rDev.DrawImage( rPos, pEntry->GetImage() );
119 OUString SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry* pEntry, bool )
121 return pEntry->GetText();
124 void SvtIconChoiceCtrl::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
126 _pImp->Paint(rRenderContext, rRect);
129 void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent& rMEvt )
131 if( !_pImp->MouseButtonDown( rMEvt ) )
132 Control::MouseButtonDown( rMEvt );
135 void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent& rMEvt )
137 if( !_pImp->MouseButtonUp( rMEvt ) )
138 Control::MouseButtonUp( rMEvt );
141 void SvtIconChoiceCtrl::MouseMove( const MouseEvent& rMEvt )
143 if( !_pImp->MouseMove( rMEvt ) )
144 Control::MouseMove( rMEvt );
146 void SvtIconChoiceCtrl::ArrangeIcons()
148 if ( GetStyle() & WB_ALIGN_TOP )
150 Size aFullSize;
151 Rectangle aEntryRect;
153 for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
155 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
156 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
158 aFullSize.setWidth ( aFullSize.getWidth()+aEntryRect.GetWidth() );
161 _pImp->Arrange ( false, aFullSize.getWidth() );
163 else if ( GetStyle() & WB_ALIGN_LEFT )
165 Size aFullSize;
166 Rectangle aEntryRect;
168 for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
170 SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
171 aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
173 aFullSize.setHeight ( aFullSize.getHeight()+aEntryRect.GetHeight() );
176 _pImp->Arrange ( false, 0, aFullSize.getHeight() );
178 else
180 _pImp->Arrange();
182 _pImp->Arrange( false, 0, 1000 );
184 void SvtIconChoiceCtrl::Resize()
186 _pImp->Resize();
187 Control::Resize();
190 Point SvtIconChoiceCtrl::GetPixelPos( const Point& rPosLogic ) const
192 Point aPos( rPosLogic );
193 aPos += GetMapMode().GetOrigin();
194 return aPos;
197 void SvtIconChoiceCtrl::DocumentRectChanged()
199 _aDocRectChangedHdl.Call( this );
202 void SvtIconChoiceCtrl::VisibleRectChanged()
204 _aVisRectChangedHdl.Call( this );
207 void SvtIconChoiceCtrl::GetFocus()
209 _pImp->GetFocus();
210 Control::GetFocus();
211 sal_uLong nPos;
212 SvxIconChoiceCtrlEntry* pSelectedEntry = GetSelectedEntry ( nPos );
213 if ( pSelectedEntry )
214 _pImp->CallEventListeners( VCLEVENT_LISTBOX_SELECT, pSelectedEntry );
217 void SvtIconChoiceCtrl::LoseFocus()
219 if (_pImp)
220 _pImp->LoseFocus();
221 Control::LoseFocus();
224 void SvtIconChoiceCtrl::SetFont(const vcl::Font& rFont)
226 if (rFont != GetFont())
228 Control::SetFont(rFont);
229 _pImp->FontModified();
233 void SvtIconChoiceCtrl::SetPointFont(const vcl::Font& rFont)
235 if (rFont != GetPointFont(*this)) //FIXME
237 Control::SetPointFont(*this, rFont); //FIXME
238 _pImp->FontModified();
242 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( const Point& rPixPos, bool bHit ) const
244 Point aPos( rPixPos );
245 aPos -= GetMapMode().GetOrigin();
246 return const_cast<SvtIconChoiceCtrl*>(this)->_pImp->GetEntry( aPos, bHit );
249 void SvtIconChoiceCtrl::SetStyle( WinBits nWinStyle )
251 _pImp->SetStyle( nWinStyle );
254 WinBits SvtIconChoiceCtrl::GetStyle() const
256 return _pImp->GetStyle();
258 void SvtIconChoiceCtrl::Command( const CommandEvent& rCEvt )
260 _pImp->Command( rCEvt );
263 #ifdef DBG_UTIL
264 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry )
266 _pImp->SetEntryTextMode( eMode, pEntry );
268 #endif
270 sal_uLong SvtIconChoiceCtrl::GetEntryCount() const
272 return _pImp ? _pImp->GetEntryCount() : 0;
275 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( sal_uLong nPos ) const
277 return _pImp ? _pImp->GetEntry( nPos ) : NULL;
280 void SvtIconChoiceCtrl::CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics )
282 _pImp->CreateAutoMnemonics( &_rUsedMnemonics );
285 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetSelectedEntry( sal_uLong& rPos ) const
287 return _pImp ? _pImp->GetFirstSelectedEntry( rPos ) : NULL;
290 void SvtIconChoiceCtrl::ClickIcon()
292 sal_uLong nPos;
293 GetSelectedEntry ( nPos );
294 _aClickIconHdl.Call( this );
296 bool SvtIconChoiceCtrl::IsEntryEditing() const
298 return _pImp->IsEntryEditing();
301 bool SvtIconChoiceCtrl::SetChoiceWithCursor ( bool bDo )
303 return _pImp->SetChoiceWithCursor (bDo);
306 void SvtIconChoiceCtrl::KeyInput( const KeyEvent& rKEvt )
308 bool bKeyUsed = DoKeyInput( rKEvt );
309 if ( !bKeyUsed )
311 _pCurKeyEvent = const_cast<KeyEvent*>(&rKEvt);
312 Control::KeyInput( rKEvt );
313 _pCurKeyEvent = NULL;
316 bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent& rKEvt )
318 // under OS/2, we get key up/down even while editing
319 if( IsEntryEditing() )
320 return true;
321 _pCurKeyEvent = const_cast<KeyEvent*>(&rKEvt);
322 bool bHandled = _pImp->KeyInput( rKEvt );
323 _pCurKeyEvent = NULL;
324 return bHandled;
326 sal_uLong SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const
328 return _pImp->GetEntryListPos( pEntry );
330 SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetCursor( ) const
332 return _pImp->GetCurEntry( );
334 void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry* pEntry )
336 _pImp->SetCursor( pEntry );
338 void SvtIconChoiceCtrl::InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry )
340 _pImp->InvalidateEntry( pEntry );
343 void SvtIconChoiceCtrl::StateChanged( StateChangedType nType )
345 Control::StateChanged( nType );
349 void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent& rDCEvt )
351 if ( ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) ||
352 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
353 (rDCEvt.GetType() == DataChangedEventType::FONTS) ) &&
354 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
356 _pImp->InitSettings();
357 Invalidate(INVALIDATE_NOCHILDREN);
359 else
360 Control::DataChanged( rDCEvt );
363 void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper )
365 if( rPaper != GetBackground() )
367 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
368 Wallpaper aEmpty;
369 if( rPaper == aEmpty )
370 Control::SetBackground( rStyleSettings.GetFieldColor() );
371 else
373 Wallpaper aBackground( rPaper );
374 // HACK, as background might be transparent!
375 if( !aBackground.IsBitmap() )
376 aBackground.SetStyle( WALLPAPER_TILE );
378 WallpaperStyle eStyle = aBackground.GetStyle();
379 Color aBack( aBackground.GetColor());
380 Color aTrans( COL_TRANSPARENT );
381 if( aBack == aTrans && (
382 (!aBackground.IsBitmap() ||
383 aBackground.GetBitmap().IsTransparent() ||
384 (eStyle != WALLPAPER_TILE && eStyle != WALLPAPER_SCALE))))
386 aBackground.SetColor( rStyleSettings.GetFieldColor() );
388 if( aBackground.IsScrollable() )
390 Rectangle aRect;
391 aRect.SetSize( Size(32765, 32765) );
392 aBackground.SetRect( aRect );
394 else
396 Rectangle aRect( _pImp->GetOutputRect() );
397 aBackground.SetRect( aRect );
399 Control::SetBackground( aBackground );
402 // If text colors are attributed "hard," don't use automatism to select
403 // a readable text color.
404 vcl::Font aFont( GetFont() );
405 aFont.SetColor( rStyleSettings.GetFieldTextColor() );
406 SetFont( aFont );
408 Invalidate(INVALIDATE_NOCHILDREN);
412 void SvtIconChoiceCtrl::RequestHelp( const HelpEvent& rHEvt )
414 if ( !_pImp->RequestHelp( rHEvt ) )
415 Control::RequestHelp( rHEvt );
418 void SvtIconChoiceCtrl::SetSelectionMode( SelectionMode eMode )
420 _pImp->SetSelectionMode( eMode );
423 Rectangle SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const
425 return _pImp->GetEntryBoundRect( pEntry );
428 void SvtIconChoiceCtrl::FillLayoutData() const
430 CreateLayoutData();
431 const_cast<SvtIconChoiceCtrl*>(this)->Invalidate();
434 Rectangle SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
436 Rectangle aRect;
438 Pair aEntryCharacterRange = GetLineStartEnd( _nEntryPos );
439 if ( aEntryCharacterRange.A() + _nCharacterIndex < aEntryCharacterRange.B() )
441 aRect = GetCharacterBounds( aEntryCharacterRange.A() + _nCharacterIndex );
444 return aRect;
447 void SvtIconChoiceCtrl::SetNoSelection()
449 _pImp->SetNoSelection();
452 void SvtIconChoiceCtrl::CallImplEventListeners(sal_uLong nEvent, void* pData)
454 CallEventListeners(nEvent, pData);
456 ::com::sun::star::uno::Reference< XAccessible > SvtIconChoiceCtrl::CreateAccessible()
458 vcl::Window* pParent = GetAccessibleParentWindow();
459 DBG_ASSERT( pParent, "SvTreeListBox::CreateAccessible - accessible parent not found" );
461 ::com::sun::star::uno::Reference< XAccessible > xAccessible;
462 if ( pParent )
464 ::com::sun::star::uno::Reference< XAccessible > xAccParent = pParent->GetAccessible();
465 if ( xAccParent.is() )
467 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xTemp(GetComponentInterface());
468 xAccessible = _pImp->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent );
471 return xAccessible;
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */