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: ivctrl.cxx,v $
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"
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
)
58 eTextMode
= IcnShowTextShort
;
63 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const String
& rText
, const Image
& rImage
, const Image
& rImageHC
, USHORT _nFlags
)
71 eTextMode
= IcnShowTextShort
;
76 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( USHORT _nFlags
)
81 eTextMode
= IcnShowTextShort
;
86 void SvxIconChoiceCtrlEntry::SetMoved( BOOL bMoved
)
89 nFlags
|= ICNVIEW_FLAG_POS_MOVED
;
91 nFlags
&= ~ICNVIEW_FLAG_POS_MOVED
;
94 void SvxIconChoiceCtrlEntry::LockPos( BOOL bLock
)
97 nFlags
|= ICNVIEW_FLAG_POS_LOCKED
;
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 );
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
)
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
)
158 _pImp
->SetGrid( Size( 100, 70 ) );
159 _pImp
->InitSettings();
160 _pImp
->SetPositionMode( IcnViewPositionModeAutoArrange
);
163 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
165 _pImp
->CallEventListeners( VCLEVENT_OBJECT_DYING
);
169 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::InsertEntry( ULONG nPos
, const Point
* pPos
, USHORT nFlags
)
171 SvxIconChoiceCtrlEntry
* pEntry
= new SvxIconChoiceCtrlEntry( nFlags
);
172 _pImp
->InsertEntry( pEntry
, nPos
, pPos
);
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
);
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
);
194 BOOL
SvtIconChoiceCtrl::EditedEntry( SvxIconChoiceCtrlEntry
*, const XubString
&, BOOL
)
198 BOOL
SvtIconChoiceCtrl::EditingEntry( SvxIconChoiceCtrlEntry
* )
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
214 BOOL
SvtIconChoiceCtrl::HasFont() const
218 BOOL
SvtIconChoiceCtrl::HasFontTextColor() const
222 BOOL
SvtIconChoiceCtrl::HasFontFillColor() const
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
)
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
)
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() );
285 _pImp
->Arrange( FALSE
, 0, 1000 );
287 void SvtIconChoiceCtrl::Resize()
293 Point
SvtIconChoiceCtrl::GetLogicPos( const Point
& rPosPixel
) const
295 Point
aPos( rPosPixel
);
296 aPos
-= GetMapMode().GetOrigin();
300 Point
SvtIconChoiceCtrl::GetPixelPos( const Point
& rPosLogic
) const
302 Point
aPos( rPosLogic
);
303 aPos
+= GetMapMode().GetOrigin();
307 void SvtIconChoiceCtrl::DocumentRectChanged()
309 _aDocRectChangedHdl
.Call( this );
312 void SvtIconChoiceCtrl::VisibleRectChanged()
314 _aVisRectChangedHdl
.Call( this );
317 void SvtIconChoiceCtrl::GetFocus()
322 SvxIconChoiceCtrlEntry
* pSelectedEntry
= GetSelectedEntry ( nPos
);
323 if ( pSelectedEntry
)
324 _pImp
->CallEventListeners( VCLEVENT_LISTBOX_SELECT
, pSelectedEntry
);
327 void SvtIconChoiceCtrl::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()
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
);
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() )
460 _pCurKeyEvent
= (KeyEvent
*)&rKEvt
;
461 BOOL bHandled
= _pImp
->KeyInput( rKEvt
);
462 _pCurKeyEvent
= NULL
;
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()
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
);
502 Control::DataChanged( rDCEvt
);
505 void SvtIconChoiceCtrl::SetBackground( const Wallpaper
& rPaper
)
507 if( rPaper
!= GetBackground() )
509 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
511 if( rPaper
== aEmpty
)
512 Control::SetBackground( rStyleSettings
.GetFieldColor() );
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() )
533 aRect
.SetSize( Size(32765, 32765) );
534 aBackground
.SetRect( aRect
);
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() );
550 Invalidate(INVALIDATE_NOCHILDREN
);
554 void SvtIconChoiceCtrl::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();
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
);
607 Rectangle
SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const
611 Pair aEntryCharacterRange
= GetLineStartEnd( _nEntryPos
);
612 if ( aEntryCharacterRange
.A() + _nCharacterIndex
< aEntryCharacterRange
.B() )
614 aRect
= GetCharacterBounds( aEntryCharacterRange
.A() + _nCharacterIndex
);
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
;
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
);