1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
38 SvxIconViewFlags _nFlags
)
45 , eTextMode(IcnShowTextShort
)
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 )
84 _pImp
->SetGrid( Size( 100, 70 ) );
85 _pImp
->InitSettings();
86 _pImp
->SetPositionMode( IcnViewPositionModeAutoArrange
);
89 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
94 void SvtIconChoiceCtrl::dispose()
98 _pImp
->CallEventListeners( VCLEVENT_OBJECT_DYING
);
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
);
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
)
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
)
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() );
182 _pImp
->Arrange( false, 0, 1000 );
184 void SvtIconChoiceCtrl::Resize()
190 Point
SvtIconChoiceCtrl::GetPixelPos( const Point
& rPosLogic
) const
192 Point
aPos( rPosLogic
);
193 aPos
+= GetMapMode().GetOrigin();
197 void SvtIconChoiceCtrl::DocumentRectChanged()
199 _aDocRectChangedHdl
.Call( this );
202 void SvtIconChoiceCtrl::VisibleRectChanged()
204 _aVisRectChangedHdl
.Call( this );
207 void SvtIconChoiceCtrl::GetFocus()
212 SvxIconChoiceCtrlEntry
* pSelectedEntry
= GetSelectedEntry ( nPos
);
213 if ( pSelectedEntry
)
214 _pImp
->CallEventListeners( VCLEVENT_LISTBOX_SELECT
, pSelectedEntry
);
217 void SvtIconChoiceCtrl::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
);
264 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode
, SvxIconChoiceCtrlEntry
* pEntry
)
266 _pImp
->SetEntryTextMode( eMode
, pEntry
);
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()
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
);
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() )
321 _pCurKeyEvent
= const_cast<KeyEvent
*>(&rKEvt
);
322 bool bHandled
= _pImp
->KeyInput( rKEvt
);
323 _pCurKeyEvent
= NULL
;
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
);
360 Control::DataChanged( rDCEvt
);
363 void SvtIconChoiceCtrl::SetBackground( const Wallpaper
& rPaper
)
365 if( rPaper
!= GetBackground() )
367 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
369 if( rPaper
== aEmpty
)
370 Control::SetBackground( rStyleSettings
.GetFieldColor() );
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() )
391 aRect
.SetSize( Size(32765, 32765) );
392 aBackground
.SetRect( aRect
);
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() );
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
431 const_cast<SvtIconChoiceCtrl
*>(this)->Invalidate();
434 Rectangle
SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const
438 Pair aEntryCharacterRange
= GetLineStartEnd( _nEntryPos
);
439 if ( aEntryCharacterRange
.A() + _nCharacterIndex
< aEntryCharacterRange
.B() )
441 aRect
= GetCharacterBounds( aEntryCharacterRange
.A() + _nCharacterIndex
);
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
;
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
);
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */