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 <vcl/ivctrl.hxx>
22 #include "imivctl.hxx"
23 #include <vcl/accessiblefactory.hxx>
24 #include <vcl/bitmapex.hxx>
25 #include <vcl/commandevent.hxx>
26 #include <vcl/mnemonic.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/tabctrl.hxx>
29 #include <vcl/vclevent.hxx>
31 using namespace ::com::sun::star::accessibility
;
33 /*****************************************************************************
35 | class : SvxIconChoiceCtrlEntry
37 \*****************************************************************************/
39 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const OUString
& rText
,
47 , eTextMode(SvxIconChoiceCtrlTextMode::Short
)
50 , nFlags(SvxIconViewFlags::NONE
)
54 OUString
SvxIconChoiceCtrlEntry::GetDisplayText() const
56 return MnemonicGenerator::EraseAllMnemonicChars( aText
);
60 SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo
& rInfo
)
62 nWidth
= rInfo
.nWidth
;
65 /*****************************************************************************
67 | class : SvtIconChoiceCtrl
69 \*****************************************************************************/
71 SvtIconChoiceCtrl::SvtIconChoiceCtrl( vcl::Window
* pParent
, WinBits nWinStyle
) :
73 // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
74 Control( pParent
, nWinStyle
| WB_CLIPCHILDREN
),
76 _pImpl ( new SvxIconChoiceCtrl_Impl( this, nWinStyle
) )
79 _pImpl
->InitSettings();
80 _pImpl
->SetPositionMode( SvxIconChoiceCtrlPositionMode::AutoArrange
);
83 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
88 void SvtIconChoiceCtrl::dispose()
92 _pImpl
->CallEventListeners( VclEventId::ObjectDying
, nullptr );
98 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::InsertEntry( const OUString
& rText
, const Image
& rImage
)
100 SvxIconChoiceCtrlEntry
* pEntry
= new SvxIconChoiceCtrlEntry( rText
, rImage
);
102 _pImpl
->InsertEntry(std::unique_ptr
<SvxIconChoiceCtrlEntry
>(pEntry
), _pImpl
->GetEntryCount());
107 void SvtIconChoiceCtrl::RemoveEntry(sal_Int32 nIndex
)
109 _pImpl
->RemoveEntry(nIndex
);
112 void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry
const * pEntry
, const Point
& rPos
, OutputDevice
& rDev
)
114 rDev
.DrawImage( rPos
, pEntry
->GetImage() );
117 OUString
SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry
const * pEntry
)
119 return pEntry
->GetText();
122 void SvtIconChoiceCtrl::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
124 _pImpl
->Paint(rRenderContext
, rRect
);
127 void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent
& rMEvt
)
129 if( !_pImpl
->MouseButtonDown( rMEvt
) )
130 Control::MouseButtonDown( rMEvt
);
133 void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent
& rMEvt
)
135 if( !_pImpl
->MouseButtonUp( rMEvt
) )
136 Control::MouseButtonUp( rMEvt
);
139 void SvtIconChoiceCtrl::MouseMove( const MouseEvent
& rMEvt
)
141 if( !_pImpl
->MouseMove( rMEvt
) )
142 Control::MouseMove( rMEvt
);
144 void SvtIconChoiceCtrl::ArrangeIcons()
146 if ( GetStyle() & WB_ALIGN_TOP
)
149 tools::Rectangle aEntryRect
;
151 for ( sal_Int32 i
= 0; i
< GetEntryCount(); i
++ )
153 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry ( i
);
154 aEntryRect
= _pImpl
->GetEntryBoundRect ( pEntry
);
156 aFullSize
.setWidth ( aFullSize
.getWidth()+aEntryRect
.GetWidth() );
159 _pImpl
->Arrange ( false, aFullSize
.getWidth(), 0 );
161 else if ( GetStyle() & WB_ALIGN_LEFT
)
164 tools::Rectangle aEntryRect
;
166 for ( sal_Int32 i
= 0; i
< GetEntryCount(); i
++ )
168 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry ( i
);
169 aEntryRect
= _pImpl
->GetEntryBoundRect ( pEntry
);
171 aFullSize
.setHeight ( aFullSize
.getHeight()+aEntryRect
.GetHeight() );
174 _pImpl
->Arrange ( false, 0, aFullSize
.getHeight() );
178 _pImpl
->Arrange(false, 0, 0);
180 _pImpl
->Arrange( false, 0, 1000 );
182 void SvtIconChoiceCtrl::Resize()
188 void SvtIconChoiceCtrl::GetFocus()
192 SvxIconChoiceCtrlEntry
* pSelectedEntry
= GetSelectedEntry();
193 if ( pSelectedEntry
)
194 _pImpl
->CallEventListeners( VclEventId::ListboxSelect
, pSelectedEntry
);
197 void SvtIconChoiceCtrl::LoseFocus()
201 Control::LoseFocus();
204 void SvtIconChoiceCtrl::SetFont(const vcl::Font
& rFont
)
206 if (rFont
!= GetFont())
208 Control::SetFont(rFont
);
209 _pImpl
->FontModified();
213 void SvtIconChoiceCtrl::SetPointFont(const vcl::Font
& rFont
)
215 if (rFont
!= GetPointFont(*this)) //FIXME
217 Control::SetPointFont(*this, rFont
); //FIXME
218 _pImpl
->FontModified();
222 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetEntry( const Point
& rPixPos
) const
224 Point
aPos( rPixPos
);
225 aPos
-= GetMapMode().GetOrigin();
226 return const_cast<SvtIconChoiceCtrl
*>(this)->_pImpl
->GetEntry( aPos
);
229 WinBits
SvtIconChoiceCtrl::GetStyle() const
231 return _pImpl
->GetStyle();
234 void SvtIconChoiceCtrl::Command(const CommandEvent
& rCEvt
)
236 _pImpl
->Command( rCEvt
);
237 //pass at least alt press/release to parent impl
238 if (rCEvt
.GetCommand() == CommandEventId::ModKeyChange
)
239 Control::Command(rCEvt
);
243 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode
, SvxIconChoiceCtrlEntry
* pEntry
)
245 _pImpl
->SetEntryTextMode( eMode
, pEntry
);
249 sal_Int32
SvtIconChoiceCtrl::GetEntryCount() const
251 return _pImpl
? _pImpl
->GetEntryCount() : 0;
254 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetEntry( sal_Int32 nPos
) const
256 return _pImpl
? _pImpl
->GetEntry( nPos
) : nullptr;
259 void SvtIconChoiceCtrl::CreateAutoMnemonics( MnemonicGenerator
& _rUsedMnemonics
)
261 _pImpl
->CreateAutoMnemonics( &_rUsedMnemonics
);
264 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetSelectedEntry() const
266 return _pImpl
? _pImpl
->GetFirstSelectedEntry() : nullptr;
269 void SvtIconChoiceCtrl::ClickIcon()
272 _aClickIconHdl
.Call( this );
275 void SvtIconChoiceCtrl::SetChoiceWithCursor()
277 _pImpl
->SetChoiceWithCursor();
280 void SvtIconChoiceCtrl::KeyInput( const KeyEvent
& rKEvt
)
282 bool bKeyUsed
= DoKeyInput( rKEvt
);
285 Control::KeyInput( rKEvt
);
288 bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent
& rKEvt
)
290 return _pImpl
->KeyInput( rKEvt
);
292 sal_Int32
SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry
const * pEntry
) const
294 return _pImpl
->GetEntryListPos( pEntry
);
296 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetCursor( ) const
298 return _pImpl
->GetCurEntry( );
300 void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry
* pEntry
)
302 _pImpl
->SetCursor( pEntry
);
304 void SvtIconChoiceCtrl::InvalidateEntry( SvxIconChoiceCtrlEntry
* pEntry
)
306 _pImpl
->InvalidateEntry( pEntry
);
309 void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent
& rDCEvt
)
311 if ( ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) ||
312 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
313 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ) &&
314 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
316 _pImpl
->InitSettings();
317 Invalidate(InvalidateFlags::NoChildren
);
320 Control::DataChanged( rDCEvt
);
323 void SvtIconChoiceCtrl::SetBackground( const Wallpaper
& rPaper
)
325 if( rPaper
== GetBackground() )
328 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
329 // if it is the default (empty) wallpaper
330 if (rPaper
.IsEmpty())
332 Control::SetBackground( rStyleSettings
.GetFieldColor() );
336 Wallpaper
aBackground( rPaper
);
337 // HACK, as background might be transparent!
338 if( !aBackground
.IsBitmap() )
339 aBackground
.SetStyle( WallpaperStyle::Tile
);
341 WallpaperStyle eStyle
= aBackground
.GetStyle();
342 Color
aBack( aBackground
.GetColor());
343 if( aBack
== COL_TRANSPARENT
&&
344 (!aBackground
.IsBitmap() ||
345 aBackground
.GetBitmap().IsTransparent() ||
346 (eStyle
!= WallpaperStyle::Tile
&& eStyle
!= WallpaperStyle::Scale
)) )
348 aBackground
.SetColor( rStyleSettings
.GetFieldColor() );
350 if( aBackground
.IsScrollable() )
352 tools::Rectangle aRect
;
353 aRect
.SetSize( Size(32765, 32765) );
354 aBackground
.SetRect( aRect
);
358 tools::Rectangle
aRect( _pImpl
->GetOutputRect() );
359 aBackground
.SetRect( aRect
);
361 Control::SetBackground( aBackground
);
364 // If text colors are attributed "hard," don't use automatism to select
365 // a readable text color.
366 vcl::Font
aFont( GetFont() );
367 aFont
.SetColor( rStyleSettings
.GetFieldTextColor() );
370 Invalidate(InvalidateFlags::NoChildren
);
373 void SvtIconChoiceCtrl::RequestHelp( const HelpEvent
& rHEvt
)
375 if ( !_pImpl
->RequestHelp( rHEvt
) )
376 Control::RequestHelp( rHEvt
);
379 void SvtIconChoiceCtrl::SetSelectionMode( SelectionMode eMode
)
381 _pImpl
->SetSelectionMode( eMode
);
384 tools::Rectangle
SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry
* pEntry
) const
386 return _pImpl
->GetEntryBoundRect( pEntry
);
389 void SvtIconChoiceCtrl::FillLayoutData() const
392 const_cast<SvtIconChoiceCtrl
*>(this)->Invalidate();
395 tools::Rectangle
SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const
397 tools::Rectangle aRect
;
399 Pair aEntryCharacterRange
= GetLineStartEnd( _nEntryPos
);
400 if ( aEntryCharacterRange
.A() + _nCharacterIndex
< aEntryCharacterRange
.B() )
402 aRect
= GetCharacterBounds( aEntryCharacterRange
.A() + _nCharacterIndex
);
408 void SvtIconChoiceCtrl::SetNoSelection()
410 _pImpl
->SetNoSelection();
413 void SvtIconChoiceCtrl::CallImplEventListeners(VclEventId nEvent
, void* pData
)
415 CallEventListeners(nEvent
, pData
);
417 css::uno::Reference
< XAccessible
> SvtIconChoiceCtrl::CreateAccessible()
419 vcl::Window
* pParent
= GetAccessibleParentWindow();
420 DBG_ASSERT( pParent
, "SvTreeListBox::CreateAccessible - accessible parent not found" );
422 css::uno::Reference
< XAccessible
> xAccessible
;
425 css::uno::Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
426 if ( xAccParent
.is() )
428 css::uno::Reference
< css::awt::XWindowPeer
> xTemp(GetComponentInterface());
429 xAccessible
= _pImpl
->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent
);
435 struct VerticalTabPageData
438 SvxIconChoiceCtrlEntry
* pEntry
;
439 VclPtr
<vcl::Window
> xPage
; ///< the TabPage itself
442 VerticalTabControl::VerticalTabControl(vcl::Window
* pParent
)
444 , m_xChooser(VclPtr
<SvtIconChoiceCtrl
>::Create(this, WB_3DLOOK
| WB_ICON
| WB_BORDER
|
445 WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
|
446 WB_NODRAGSELECTION
| WB_TABSTOP
| WB_CLIPCHILDREN
|
447 WB_ALIGN_LEFT
| WB_NOHSCROLL
))
448 , m_xBox(VclPtr
<VclVBox
>::Create(this))
450 SetType(WindowType::VERTICALTABCONTROL
);
451 m_xChooser
->SetClickHdl(LINK(this, VerticalTabControl
, ChosePageHdl_Impl
));
452 m_xChooser
->set_width_request(110);
453 m_xChooser
->set_height_request(400);
454 m_xChooser
->SetSizePixel(Size(110, 400));
455 m_xBox
->set_vexpand(true);
456 m_xBox
->set_hexpand(true);
457 m_xBox
->set_expand(true);
462 VerticalTabControl::~VerticalTabControl()
467 void VerticalTabControl::dispose()
469 m_xChooser
.disposeAndClear();
470 m_xBox
.disposeAndClear();
474 IMPL_LINK_NOARG(VerticalTabControl
, ChosePageHdl_Impl
, SvtIconChoiceCtrl
*, void)
476 SvxIconChoiceCtrlEntry
*pEntry
= m_xChooser
->GetSelectedEntry();
478 pEntry
= m_xChooser
->GetCursor();
480 VerticalTabPageData
* pData
= GetPageData(pEntry
);
482 if (pData
->sId
!= m_sCurrentPageId
)
483 SetCurPageId(pData
->sId
);
486 void VerticalTabControl::ActivatePage()
488 m_aActivateHdl
.Call( this );
491 bool VerticalTabControl::DeactivatePage()
493 return !m_aDeactivateHdl
.IsSet() || m_aDeactivateHdl
.Call(this);
496 VerticalTabPageData
* VerticalTabControl::GetPageData(const SvxIconChoiceCtrlEntry
* pEntry
) const
498 VerticalTabPageData
* pRet
= nullptr;
499 for (auto & pData
: maPageList
)
501 if (pData
->pEntry
== pEntry
)
510 VerticalTabPageData
* VerticalTabControl::GetPageData(const OString
& rId
) const
512 VerticalTabPageData
* pRet
= nullptr;
513 for (auto & pData
: maPageList
)
515 if (pData
->sId
== rId
)
524 void VerticalTabControl::SetCurPageId(const OString
& rId
)
526 OString sOldPageId
= GetCurPageId();
527 if (sOldPageId
== rId
)
530 VerticalTabPageData
* pOldData
= GetPageData(sOldPageId
);
531 if (pOldData
&& pOldData
->xPage
)
533 if (!DeactivatePage())
535 pOldData
->xPage
->Hide();
538 m_sCurrentPageId
= "";
540 VerticalTabPageData
* pNewData
= GetPageData(rId
);
541 if (pNewData
&& pNewData
->xPage
)
543 m_sCurrentPageId
= rId
;
544 m_xChooser
->SetCursor(pNewData
->pEntry
);
547 pNewData
->xPage
->Show();
551 OString
VerticalTabControl::GetPageId(sal_uInt16 nIndex
) const
553 return maPageList
[nIndex
]->sId
;
556 void VerticalTabControl::InsertPage(const rtl::OString
&rIdent
, const rtl::OUString
& rLabel
, const Image
& rImage
,
557 const rtl::OUString
& rTooltip
, VclPtr
<vcl::Window
> xPage
)
559 SvxIconChoiceCtrlEntry
* pEntry
= m_xChooser
->InsertEntry(rLabel
, rImage
);
560 pEntry
->SetQuickHelpText(rTooltip
);
561 m_xChooser
->ArrangeIcons();
562 maPageList
.emplace_back(new VerticalTabPageData
);
563 VerticalTabPageData
* pNew
= maPageList
.back().get();
565 pNew
->pEntry
= pEntry
;
567 Size
aOrigPrefSize(m_xBox
->get_preferred_size());
568 Size
aPagePrefSize(xPage
->get_preferred_size());
569 m_xBox
->set_width_request(std::max(aOrigPrefSize
.Width(), aPagePrefSize
.Width()));
570 m_xBox
->set_height_request(std::max(aOrigPrefSize
.Height(), aPagePrefSize
.Height()));
574 void VerticalTabControl::RemovePage(const rtl::OString
&rPageId
)
576 for (auto it
= maPageList
.begin(), end
= maPageList
.end(); it
!= end
; ++it
)
578 VerticalTabPageData
* pData
= it
->get();
579 if (pData
->sId
== rPageId
)
581 sal_Int32 nEntryListPos
= m_xChooser
->GetEntryListPos(pData
->pEntry
);
582 m_xChooser
->RemoveEntry(nEntryListPos
);
583 m_xChooser
->ArrangeIcons();
584 maPageList
.erase(it
);
590 sal_uInt16
VerticalTabControl::GetPagePos(const OString
& rPageId
) const
592 VerticalTabPageData
* pData
= GetPageData(rPageId
);
594 return TAB_PAGE_NOTFOUND
;
595 return m_xChooser
->GetEntryListPos(pData
->pEntry
);
598 VclPtr
<vcl::Window
> VerticalTabControl::GetPage(const OString
& rPageId
)
600 VerticalTabPageData
* pData
= GetPageData(rPageId
);
606 OUString
VerticalTabControl::GetPageText(const OString
& rPageId
) const
608 VerticalTabPageData
* pData
= GetPageData(rPageId
);
611 return pData
->pEntry
->GetText();
614 void VerticalTabControl::SetPageText(const OString
& rPageId
, const OUString
& rText
)
616 VerticalTabPageData
* pData
= GetPageData(rPageId
);
619 pData
->pEntry
->SetText(rText
);
622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */