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/toolkit/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>
30 #include <vcl/uitest/uiobject.hxx>
31 #include <vcl/uitest/logger.hxx>
32 #include <vcl/uitest/eventdescription.hxx>
33 #include <verticaltabctrl.hxx>
35 using namespace ::com::sun::star::accessibility
;
39 void collectUIInformation( const OUString
& aID
, const OUString
& aPos
, const OUString
& aParent
)
41 EventDescription aDescription
;
42 aDescription
.aID
= aID
;
43 aDescription
.aParameters
= {{ "POS" , aPos
}};
44 aDescription
.aAction
= "SELECT";
45 aDescription
.aParent
= aParent
;
46 aDescription
.aKeyWord
= "VerticalTab";
47 UITestLogger::getInstance().logEvent(aDescription
);
51 /*****************************************************************************
53 | class : SvxIconChoiceCtrlEntry
55 \*****************************************************************************/
57 SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const OUString
& rText
,
64 , eTextMode(SvxIconChoiceCtrlTextMode::Short
)
67 , nFlags(SvxIconViewFlags::NONE
)
71 OUString
SvxIconChoiceCtrlEntry::GetDisplayText() const
73 return MnemonicGenerator::EraseAllMnemonicChars( aText
);
77 SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo
& rInfo
)
79 nWidth
= rInfo
.nWidth
;
82 /*****************************************************************************
84 | class : SvtIconChoiceCtrl
86 \*****************************************************************************/
88 SvtIconChoiceCtrl::SvtIconChoiceCtrl( vcl::Window
* pParent
, WinBits nWinStyle
) :
90 // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
91 Control( pParent
, nWinStyle
| WB_CLIPCHILDREN
),
93 _pImpl ( new SvxIconChoiceCtrl_Impl( this, nWinStyle
) )
96 _pImpl
->InitSettings();
97 _pImpl
->SetPositionMode( SvxIconChoiceCtrlPositionMode::AutoArrange
);
100 void SvtIconChoiceCtrl::SetSelectionMode(SelectionMode eMode
)
102 _pImpl
->SetSelectionMode(eMode
);
105 SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
110 void SvtIconChoiceCtrl::dispose()
114 _pImpl
->CallEventListeners( VclEventId::ObjectDying
, nullptr );
120 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::InsertEntry( const OUString
& rText
, const Image
& rImage
)
122 SvxIconChoiceCtrlEntry
* pEntry
= new SvxIconChoiceCtrlEntry( rText
, rImage
);
124 _pImpl
->InsertEntry(std::unique_ptr
<SvxIconChoiceCtrlEntry
>(pEntry
), _pImpl
->GetEntryCount());
129 void SvtIconChoiceCtrl::RemoveEntry(sal_Int32 nIndex
)
131 _pImpl
->RemoveEntry(nIndex
);
134 void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry
const * pEntry
, const Point
& rPos
, OutputDevice
& rDev
)
136 rDev
.DrawImage( rPos
, pEntry
->GetImage() );
139 OUString
SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry
const * pEntry
)
141 return pEntry
->GetText();
144 void SvtIconChoiceCtrl::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
146 _pImpl
->Paint(rRenderContext
, rRect
);
149 void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent
& rMEvt
)
151 if( !_pImpl
->MouseButtonDown( rMEvt
) )
152 Control::MouseButtonDown( rMEvt
);
155 void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent
& rMEvt
)
157 if( !_pImpl
->MouseButtonUp( rMEvt
) )
158 Control::MouseButtonUp( rMEvt
);
161 void SvtIconChoiceCtrl::MouseMove( const MouseEvent
& rMEvt
)
163 if( !_pImpl
->MouseMove( rMEvt
) )
164 Control::MouseMove( rMEvt
);
166 void SvtIconChoiceCtrl::ArrangeIcons()
168 if ( GetStyle() & WB_ALIGN_TOP
)
171 tools::Rectangle aEntryRect
;
173 for ( sal_Int32 i
= 0; i
< GetEntryCount(); i
++ )
175 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry ( i
);
176 aEntryRect
= _pImpl
->GetEntryBoundRect ( pEntry
);
178 aFullSize
.setWidth ( aFullSize
.getWidth()+aEntryRect
.GetWidth() );
181 _pImpl
->Arrange ( false, aFullSize
.getWidth(), 0 );
183 else if ( GetStyle() & WB_ALIGN_LEFT
)
186 tools::Rectangle aEntryRect
;
188 for ( sal_Int32 i
= 0; i
< GetEntryCount(); i
++ )
190 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry ( i
);
191 aEntryRect
= _pImpl
->GetEntryBoundRect ( pEntry
);
193 aFullSize
.setHeight ( aFullSize
.getHeight()+aEntryRect
.GetHeight() );
196 _pImpl
->Arrange ( false, 0, aFullSize
.getHeight() );
200 _pImpl
->Arrange(false, 0, 0);
202 _pImpl
->Arrange( false, 0, 1000 );
204 void SvtIconChoiceCtrl::Resize()
210 void SvtIconChoiceCtrl::GetFocus()
214 SvxIconChoiceCtrlEntry
* pSelectedEntry
= GetSelectedEntry();
215 if ( pSelectedEntry
)
216 _pImpl
->CallEventListeners( VclEventId::ListboxSelect
, pSelectedEntry
);
219 void SvtIconChoiceCtrl::LoseFocus()
223 Control::LoseFocus();
226 void SvtIconChoiceCtrl::SetFont(const vcl::Font
& rFont
)
228 if (rFont
!= GetFont())
230 Control::SetFont(rFont
);
231 _pImpl
->FontModified();
235 void SvtIconChoiceCtrl::SetPointFont(const vcl::Font
& rFont
)
237 if (rFont
!= GetPointFont(*this)) //FIXME
239 Control::SetPointFont(*this, rFont
); //FIXME
240 _pImpl
->FontModified();
244 WinBits
SvtIconChoiceCtrl::GetStyle() const
246 return _pImpl
->GetStyle();
249 void SvtIconChoiceCtrl::Command(const CommandEvent
& rCEvt
)
251 _pImpl
->Command( rCEvt
);
252 //pass at least alt press/release to parent impl
253 if (rCEvt
.GetCommand() == CommandEventId::ModKeyChange
)
254 Control::Command(rCEvt
);
258 void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode
, SvxIconChoiceCtrlEntry
* pEntry
)
260 _pImpl
->SetEntryTextMode( eMode
, pEntry
);
264 sal_Int32
SvtIconChoiceCtrl::GetEntryCount() const
266 return _pImpl
? _pImpl
->GetEntryCount() : 0;
269 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetEntry( sal_Int32 nPos
) const
271 return _pImpl
? _pImpl
->GetEntry( nPos
) : nullptr;
274 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetSelectedEntry() const
276 return _pImpl
? _pImpl
->GetFirstSelectedEntry() : nullptr;
279 void SvtIconChoiceCtrl::ClickIcon()
282 _aClickIconHdl
.Call( this );
285 void SvtIconChoiceCtrl::KeyInput( const KeyEvent
& rKEvt
)
287 bool bKeyUsed
= DoKeyInput( rKEvt
);
290 Control::KeyInput( rKEvt
);
293 bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent
& rKEvt
)
295 return _pImpl
->KeyInput( rKEvt
);
297 sal_Int32
SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry
const * pEntry
) const
299 return _pImpl
->GetEntryListPos( pEntry
);
301 SvxIconChoiceCtrlEntry
* SvtIconChoiceCtrl::GetCursor( ) const
303 return _pImpl
->GetCurEntry( );
305 void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry
* pEntry
)
307 _pImpl
->SetCursor( pEntry
);
310 void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent
& rDCEvt
)
312 if ( ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) ||
313 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
314 (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ) &&
315 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
317 _pImpl
->InitSettings();
318 Invalidate(InvalidateFlags::NoChildren
);
321 Control::DataChanged( rDCEvt
);
324 void SvtIconChoiceCtrl::SetBackground( const Wallpaper
& rPaper
)
326 if( rPaper
== GetBackground() )
329 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
330 // if it is the default (empty) wallpaper
331 if (rPaper
.IsEmpty())
333 Control::SetBackground( rStyleSettings
.GetFieldColor() );
337 Wallpaper
aBackground( rPaper
);
338 // HACK, as background might be transparent!
339 if( !aBackground
.IsBitmap() )
340 aBackground
.SetStyle( WallpaperStyle::Tile
);
342 WallpaperStyle eStyle
= aBackground
.GetStyle();
343 Color
aBack( aBackground
.GetColor());
344 if( aBack
== COL_TRANSPARENT
&&
345 (!aBackground
.IsBitmap() ||
346 aBackground
.GetBitmap().IsTransparent() ||
347 (eStyle
!= WallpaperStyle::Tile
&& eStyle
!= WallpaperStyle::Scale
)) )
349 aBackground
.SetColor( rStyleSettings
.GetFieldColor() );
351 if( aBackground
.IsScrollable() )
353 tools::Rectangle aRect
;
354 aRect
.SetSize( Size(32765, 32765) );
355 aBackground
.SetRect( aRect
);
359 tools::Rectangle
aRect( _pImpl
->GetOutputRect() );
360 aBackground
.SetRect( aRect
);
362 Control::SetBackground( aBackground
);
365 // If text colors are attributed "hard," don't use automatism to select
366 // a readable text color.
367 vcl::Font
aFont( GetFont() );
368 aFont
.SetColor( rStyleSettings
.GetFieldTextColor() );
371 Invalidate(InvalidateFlags::NoChildren
);
374 void SvtIconChoiceCtrl::RequestHelp( const HelpEvent
& rHEvt
)
376 if ( !_pImpl
->RequestHelp( rHEvt
) )
377 Control::RequestHelp( rHEvt
);
380 tools::Rectangle
SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry
* pEntry
) const
382 return _pImpl
->GetEntryBoundRect( pEntry
);
385 void SvtIconChoiceCtrl::FillLayoutData() const
388 const_cast<SvtIconChoiceCtrl
*>(this)->Invalidate();
391 tools::Rectangle
SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos
, const sal_Int32 _nCharacterIndex
) const
393 tools::Rectangle aRect
;
395 Pair aEntryCharacterRange
= GetLineStartEnd( _nEntryPos
);
396 if ( aEntryCharacterRange
.A() + _nCharacterIndex
< aEntryCharacterRange
.B() )
398 aRect
= GetCharacterBounds( aEntryCharacterRange
.A() + _nCharacterIndex
);
404 void SvtIconChoiceCtrl::SetNoSelection()
406 _pImpl
->SetNoSelection();
409 void SvtIconChoiceCtrl::CallImplEventListeners(VclEventId nEvent
, void* pData
)
411 CallEventListeners(nEvent
, pData
);
413 css::uno::Reference
< XAccessible
> SvtIconChoiceCtrl::CreateAccessible()
415 vcl::Window
* pParent
= GetAccessibleParentWindow();
416 DBG_ASSERT( pParent
, "SvTreeListBox::CreateAccessible - accessible parent not found" );
418 css::uno::Reference
< XAccessible
> xAccessible
;
421 css::uno::Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
422 if ( xAccParent
.is() )
424 css::uno::Reference
< css::awt::XWindowPeer
> xHoldAlive(GetComponentInterface());
425 xAccessible
= _pImpl
->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent
);
431 struct VerticalTabPageData
434 SvxIconChoiceCtrlEntry
* pEntry
;
435 VclPtr
<vcl::Window
> xPage
; ///< the TabPage itself
438 VerticalTabControl::VerticalTabControl(vcl::Window
* pParent
)
440 , m_xChooser(VclPtr
<SvtIconChoiceCtrl
>::Create(this, WB_3DLOOK
| WB_ICON
| WB_BORDER
|
441 WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
|
442 WB_NODRAGSELECTION
| WB_TABSTOP
| WB_CLIPCHILDREN
|
443 WB_ALIGN_LEFT
| WB_NOHSCROLL
))
444 , m_xBox(VclPtr
<VclVBox
>::Create(this))
446 SetStyle(GetStyle() | WB_DIALOGCONTROL
);
447 SetType(WindowType::VERTICALTABCONTROL
);
448 m_xChooser
->SetSelectionMode(SelectionMode::Single
);
449 m_xChooser
->SetClickHdl(LINK(this, VerticalTabControl
, ChosePageHdl_Impl
));
450 m_xChooser
->set_width_request(110);
451 m_xChooser
->set_height_request(400);
452 m_xChooser
->SetSizePixel(Size(110, 400));
453 m_xBox
->set_vexpand(true);
454 m_xBox
->set_hexpand(true);
455 m_xBox
->set_expand(true);
460 VerticalTabControl::~VerticalTabControl()
465 void VerticalTabControl::dispose()
467 m_xChooser
.disposeAndClear();
468 m_xBox
.disposeAndClear();
472 IMPL_LINK_NOARG(VerticalTabControl
, ChosePageHdl_Impl
, SvtIconChoiceCtrl
*, void)
474 SvxIconChoiceCtrlEntry
*pEntry
= m_xChooser
->GetSelectedEntry();
476 pEntry
= m_xChooser
->GetCursor();
478 VerticalTabPageData
* pData
= GetPageData(pEntry
);
480 if (pData
->sId
!= m_sCurrentPageId
)
481 SetCurPageId(pData
->sId
);
484 void VerticalTabControl::ActivatePage()
486 m_aActivateHdl
.Call( this );
489 bool VerticalTabControl::DeactivatePage()
491 return !m_aDeactivateHdl
.IsSet() || m_aDeactivateHdl
.Call(this);
494 VerticalTabPageData
* VerticalTabControl::GetPageData(const SvxIconChoiceCtrlEntry
* pEntry
) const
496 VerticalTabPageData
* pRet
= nullptr;
497 for (auto & pData
: maPageList
)
499 if (pData
->pEntry
== pEntry
)
508 VerticalTabPageData
* VerticalTabControl::GetPageData(const OString
& rId
) const
510 VerticalTabPageData
* pRet
= nullptr;
511 for (auto & pData
: maPageList
)
513 if (pData
->sId
== rId
)
522 void VerticalTabControl::SetCurPageId(const OString
& rId
)
524 OString sOldPageId
= GetCurPageId();
525 if (sOldPageId
== rId
)
528 VerticalTabPageData
* pOldData
= GetPageData(sOldPageId
);
529 if (pOldData
&& pOldData
->xPage
)
531 if (!DeactivatePage())
533 pOldData
->xPage
->Hide();
536 m_sCurrentPageId
= "";
538 VerticalTabPageData
* pNewData
= GetPageData(rId
);
539 if (pNewData
&& pNewData
->xPage
)
541 m_sCurrentPageId
= rId
;
542 m_xChooser
->SetCursor(pNewData
->pEntry
);
545 pNewData
->xPage
->Show();
547 collectUIInformation(get_id(),OStringToOUString(m_sCurrentPageId
,RTL_TEXTENCODING_UTF8
), GetPageParent()->get_id());
550 OString
VerticalTabControl::GetPageId(sal_uInt16 nIndex
) const
552 return maPageList
[nIndex
]->sId
;
555 void VerticalTabControl::InsertPage(const rtl::OString
&rIdent
, const rtl::OUString
& rLabel
, const Image
& rImage
,
556 const rtl::OUString
& rTooltip
, VclPtr
<vcl::Window
> xPage
, int nPos
)
558 SvxIconChoiceCtrlEntry
* pEntry
= m_xChooser
->InsertEntry(rLabel
, rImage
);
559 pEntry
->SetQuickHelpText(rTooltip
);
560 m_xChooser
->ArrangeIcons();
561 VerticalTabPageData
* pNew
;
564 maPageList
.emplace_back(new VerticalTabPageData
);
565 pNew
= maPageList
.back().get();
569 maPageList
.emplace(maPageList
.begin() + nPos
, new VerticalTabPageData
);
570 pNew
= maPageList
[nPos
].get();
573 pNew
->pEntry
= pEntry
;
575 Size
aOrigPrefSize(m_xBox
->get_preferred_size());
576 Size
aPagePrefSize(xPage
->get_preferred_size());
577 m_xBox
->set_width_request(std::max(aOrigPrefSize
.Width(), aPagePrefSize
.Width()));
578 m_xBox
->set_height_request(std::max(aOrigPrefSize
.Height(), aPagePrefSize
.Height()));
582 void VerticalTabControl::RemovePage(const rtl::OString
&rPageId
)
584 for (auto it
= maPageList
.begin(), end
= maPageList
.end(); it
!= end
; ++it
)
586 VerticalTabPageData
* pData
= it
->get();
587 if (pData
->sId
== rPageId
)
589 sal_Int32 nEntryListPos
= m_xChooser
->GetEntryListPos(pData
->pEntry
);
590 m_xChooser
->RemoveEntry(nEntryListPos
);
591 m_xChooser
->ArrangeIcons();
592 maPageList
.erase(it
);
598 sal_uInt16
VerticalTabControl::GetPagePos(const OString
& rPageId
) const
600 VerticalTabPageData
* pData
= GetPageData(rPageId
);
602 return TAB_PAGE_NOTFOUND
;
603 return m_xChooser
->GetEntryListPos(pData
->pEntry
);
606 VclPtr
<vcl::Window
> VerticalTabControl::GetPage(const OString
& rPageId
)
608 VerticalTabPageData
* pData
= GetPageData(rPageId
);
614 OUString
VerticalTabControl::GetPageText(const OString
& rPageId
) const
616 VerticalTabPageData
* pData
= GetPageData(rPageId
);
619 return pData
->pEntry
->GetText();
622 void VerticalTabControl::SetPageText(const OString
& rPageId
, const OUString
& rText
)
624 VerticalTabPageData
* pData
= GetPageData(rPageId
);
627 pData
->pEntry
->SetText(rText
);
630 FactoryFunction
VerticalTabControl::GetUITestFactory() const
632 return VerticalTabControlUIObject::create
;
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */