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 .
20 #include <sfx2/app.hxx>
22 #include <iconcdlg.hxx>
23 #include <cuihyperdlg.hxx>
25 #include <sal/log.hxx>
26 #include <unotools/viewoptions.hxx>
27 #include <svtools/apearcfg.hxx>
28 #include <vcl/mnemonic.hxx>
29 #include <vcl/i18nhelp.hxx>
30 #include <vcl/settings.hxx>
31 #include <vcl/builderfactory.hxx>
33 /**********************************************************************
37 \**********************************************************************/
39 IconChoicePage::IconChoicePage( vcl::Window
*pParent
, const OString
& rID
,
40 const OUString
& rUIXMLDescription
,
41 const SfxItemSet
* pItemSet
)
42 : TabPage ( pParent
, rID
, rUIXMLDescription
),
44 bHasExchangeSupport ( false )
46 SetStyle ( GetStyle() | WB_DIALOGCONTROL
| WB_HIDE
);
50 IconChoicePage::~IconChoicePage()
55 /**********************************************************************
57 | Activate / Deactivate
59 \**********************************************************************/
61 void IconChoicePage::ActivatePage( const SfxItemSet
& )
66 DeactivateRC
IconChoicePage::DeactivatePage( SfxItemSet
* )
68 return DeactivateRC::LeavePage
;
71 bool IconChoicePage::QueryClose()
76 /**********************************************************************
80 \**********************************************************************/
82 void IconChoicePage::ImplInitSettings()
84 vcl::Window
* pParent
= GetParent();
85 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
87 EnableChildTransparentMode();
88 SetParentClipMode( ParentClipMode::NoClip
);
89 SetPaintTransparent( true );
94 EnableChildTransparentMode( false );
96 SetPaintTransparent( false );
98 if ( IsControlBackground() )
99 SetBackground( GetControlBackground() );
101 SetBackground( pParent
->GetBackground() );
106 void IconChoicePage::StateChanged( StateChangedType nType
)
108 Window::StateChanged( nType
);
110 if ( nType
== StateChangedType::ControlBackground
)
118 void IconChoicePage::DataChanged( const DataChangedEvent
& rDCEvt
)
120 Window::DataChanged( rDCEvt
);
122 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
123 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
131 // Class IconChoiceDialog
134 /**********************************************************************
138 \**********************************************************************/
140 VCL_BUILDER_FACTORY_ARGS(SvtIconChoiceCtrl
,
141 WB_3DLOOK
| WB_ICON
| WB_BORDER
|
142 WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
|
143 WB_NODRAGSELECTION
| WB_TABSTOP
);
145 IconChoiceDialog::IconChoiceDialog ( vcl::Window
* pParent
, const OUString
& rID
,
146 const OUString
& rUIXMLDescription
)
147 : SfxModalDialog ( pParent
, rID
, rUIXMLDescription
),
148 mnCurrentPageId ( HyperLinkPageType::NONE
),
151 pExampleSet ( nullptr )
154 get(m_pApplyBtn
, "apply");
155 get(m_pCancelBtn
, "cancel");
156 get(m_pHelpBtn
, "help");
157 get(m_pResetBtn
, "reset");
158 get(m_pIconCtrl
, "icon_control");
159 get(m_pTabContainer
, "tab");
162 m_pIconCtrl
->SetClickHdl ( LINK ( this, IconChoiceDialog
, ChosePageHdl_Impl
) );
164 m_pIconCtrl
->SetChoiceWithCursor();
165 m_pIconCtrl
->SetSelectionMode( SelectionMode::Single
);
170 pExampleSet
= new SfxItemSet( *pSet
);
171 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
175 m_pOKBtn
->SetClickHdl ( LINK( this, IconChoiceDialog
, OkHdl
) );
176 m_pApplyBtn
->SetClickHdl ( LINK( this, IconChoiceDialog
, ApplyHdl
) );
177 m_pResetBtn
->SetClickHdl( LINK( this, IconChoiceDialog
, ResetHdl
) );
180 m_pCancelBtn
->Show();
185 IconChoiceDialog ::~IconChoiceDialog ()
190 void IconChoiceDialog::dispose()
192 // save configuration at INI-Manager
194 //SvtViewOptions aTabDlgOpt( EViewType::TabDialog, rId );
195 //aTabDlgOpt.SetWindowState(OStringToOUString(GetWindowState((WindowStateMask::X | WindowStateMask::Y | WindowStateMask::State | WindowStateMask::Minimized)), RTL_TEXTENCODING_ASCII_US));
196 //aTabDlgOpt.SetPageID( mnCurrentPageId );
198 for (std::unique_ptr
<IconChoicePageData
> & pData
: maPageList
)
201 pData
->pPage
.disposeAndClear();
211 m_pCancelBtn
.clear();
214 m_pTabContainer
.clear();
215 SfxModalDialog::dispose();
218 /**********************************************************************
222 \**********************************************************************/
224 SvxIconChoiceCtrlEntry
* IconChoiceDialog::AddTabPage(
225 HyperLinkPageType nId
,
226 const OUString
& rIconText
,
227 const Image
& rChoiceIcon
,
228 CreatePage pCreateFunc
/* != 0 */
231 maPageList
.emplace_back( new IconChoicePageData ( nId
, pCreateFunc
) );
233 SvxIconChoiceCtrlEntry
* pEntry
= m_pIconCtrl
->InsertEntry( rIconText
, rChoiceIcon
);
234 pEntry
->SetUserData ( reinterpret_cast<void*>(nId
) );
238 void IconChoiceDialog::SetCtrlStyle()
240 WinBits
const aWinBits
= WB_3DLOOK
| WB_ICON
| WB_BORDER
| WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
| WB_NODRAGSELECTION
| WB_TABSTOP
| WB_CLIPCHILDREN
| WB_ALIGN_LEFT
| WB_NOHSCROLL
;
241 m_pIconCtrl
->SetStyle(aWinBits
);
242 m_pIconCtrl
->ArrangeIcons();
245 /**********************************************************************
247 | Show / Hide page or button
249 \**********************************************************************/
251 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData
const * pData
)
254 pData
->pPage
->Show();
258 void IconChoiceDialog::HidePageImpl ( IconChoicePageData
const * pData
)
261 pData
->pPage
->Hide();
264 void IconChoiceDialog::ShowPage(HyperLinkPageType nId
)
266 HyperLinkPageType nOldPageId
= GetCurPageId();
267 bool bInvalidate
= nOldPageId
!= nId
;
270 IconChoicePageData
* pOldData
= GetPageData(nOldPageId
);
271 if (pOldData
&& pOldData
->pPage
)
273 DeActivatePageImpl();
274 HidePageImpl(pOldData
);
281 IconChoicePageData
* pNewData
= GetPageData(nId
);
282 if (pNewData
&& pNewData
->pPage
)
283 ShowPageImpl(pNewData
);
286 /**********************************************************************
290 \**********************************************************************/
291 IMPL_LINK_NOARG(IconChoiceDialog
, ChosePageHdl_Impl
, SvtIconChoiceCtrl
*, void)
293 SvxIconChoiceCtrlEntry
*pEntry
= m_pIconCtrl
->GetSelectedEntry();
295 pEntry
= m_pIconCtrl
->GetCursor( );
297 HyperLinkPageType nId
= static_cast<HyperLinkPageType
>(reinterpret_cast<sal_uIntPtr
>(pEntry
->GetUserData()));
299 if( nId
!= mnCurrentPageId
)
305 /**********************************************************************
309 \**********************************************************************/
311 IMPL_LINK_NOARG(IconChoiceDialog
, OkHdl
, Button
*, void)
321 IMPL_LINK_NOARG(IconChoiceDialog
, ApplyHdl
, Button
*, void)
330 IMPL_LINK_NOARG(IconChoiceDialog
, ResetHdl
, Button
*, void)
334 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
335 DBG_ASSERT( pData
, "ID not known" );
337 pData
->pPage
->Reset( *pSet
);
341 IMPL_LINK_NOARG(IconChoiceDialog
, CancelHdl
, Button
*, void)
346 /**********************************************************************
350 \**********************************************************************/
352 void IconChoiceDialog::ActivatePageImpl ()
354 DBG_ASSERT( !maPageList
.empty(), "no Pages registered" );
355 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
356 DBG_ASSERT( pData
, "ID not known" );
361 pData
->pPage
= (pData
->fnCreatePage
)( m_pTabContainer
, this, pSet
);
362 pData
->pPage
->Reset( *pSet
);
363 PageCreated( mnCurrentPageId
, *pData
->pPage
);
365 else if ( pData
->bRefresh
)
367 pData
->pPage
->Reset( *pSet
);
370 pData
->bRefresh
= false;
373 pData
->pPage
->ActivatePage( *pExampleSet
);
374 SetHelpId( pData
->pPage
->GetHelpId() );
381 void IconChoiceDialog::DeActivatePageImpl ()
383 IconChoicePageData
*pData
= GetPageData ( mnCurrentPageId
);
385 DeactivateRC nRet
= DeactivateRC::LeavePage
;
389 IconChoicePage
* pPage
= pData
->pPage
;
391 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
392 pExampleSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
396 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
398 if ( pPage
->HasExchangeSupport() )
399 nRet
= pPage
->DeactivatePage( &aTmp
);
401 if ( ( DeactivateRC::LeavePage
& nRet
) &&
405 pExampleSet
->Put(aTmp
);
406 pOutSet
->Put( aTmp
);
411 if ( pPage
->HasExchangeSupport() ) //!!!
415 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
417 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) );
419 nRet
= pPage
->DeactivatePage( pExampleSet
);
422 nRet
= pPage
->DeactivatePage( nullptr );
425 if ( nRet
& DeactivateRC::RefreshSet
)
427 // TODO refresh input set
428 // flag all pages to be newly initialized
429 for (auto & pObj
: maPageList
)
431 if ( pObj
->pPage
.get() != pPage
)
432 pObj
->bRefresh
= true;
434 pObj
->bRefresh
= false;
441 void IconChoiceDialog::ResetPageImpl ()
443 IconChoicePageData
*pData
= GetPageData ( mnCurrentPageId
);
445 DBG_ASSERT( pData
, "ID not known" );
447 pData
->pPage
->Reset( *pSet
);
450 /**********************************************************************
454 \**********************************************************************/
456 const sal_uInt16
* IconChoiceDialog::GetInputRanges( const SfxItemPool
& )
460 SAL_WARN( "cui.dialogs", "Set does already exist!" );
461 return pSet
->GetRanges();
465 return pRanges
.get();
467 pRanges
.reset(new sal_uInt16
[1]);
470 return pRanges
.get();
474 void IconChoiceDialog::SetInputSet( const SfxItemSet
* pInSet
)
476 bool bSet
= ( pSet
!= nullptr );
480 if ( !bSet
&& !pExampleSet
&& !pOutSet
)
482 pExampleSet
= new SfxItemSet( *pSet
);
483 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
488 void IconChoiceDialog::PageCreated( HyperLinkPageType
/*nId*/, IconChoicePage
& /*rPage*/ )
494 /**********************************************************************
498 \**********************************************************************/
500 short IconChoiceDialog::Execute()
502 if ( maPageList
.empty() )
507 return Dialog::Execute();
511 void IconChoiceDialog::Start()
513 m_pCancelBtn
->SetClickHdl( LINK( this, IconChoiceDialog
, CancelHdl
) );
519 bool IconChoiceDialog::QueryClose()
522 for (auto & pData
: maPageList
)
524 if ( pData
->pPage
&& !pData
->pPage
->QueryClose() )
533 void IconChoiceDialog::Start_Impl()
535 FocusOnIcon( mnCurrentPageId
);
539 /**********************************************************************
543 \**********************************************************************/
545 IconChoicePageData
* IconChoiceDialog::GetPageData ( HyperLinkPageType nId
)
547 IconChoicePageData
*pRet
= nullptr;
548 for (auto & pData
: maPageList
)
550 if ( pData
->nId
== nId
)
559 /**********************************************************************
563 \**********************************************************************/
565 bool IconChoiceDialog::OK_Impl()
567 IconChoicePage
* pPage
= GetPageData ( mnCurrentPageId
)->pPage
;
572 DeactivateRC nRet
= DeactivateRC::LeavePage
;
575 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
577 if ( pPage
->HasExchangeSupport() )
578 nRet
= pPage
->DeactivatePage( &aTmp
);
580 if ( ( DeactivateRC::LeavePage
& nRet
)
583 pExampleSet
->Put( aTmp
);
584 pOutSet
->Put( aTmp
);
588 nRet
= pPage
->DeactivatePage( nullptr );
589 bEnd
= nRet
!= DeactivateRC::KeepPage
;
596 void IconChoiceDialog::Ok()
600 if ( !pExampleSet
&& pSet
)
601 pOutSet
= pSet
->Clone( false ); // without items
602 else if ( pExampleSet
)
603 pOutSet
.reset(new SfxItemSet( *pExampleSet
));
606 for ( size_t i
= 0, nCount
= maPageList
.size(); i
< nCount
; ++i
)
608 IconChoicePageData
* pData
= GetPageData ( maPageList
[i
]->nId
);
610 IconChoicePage
* pPage
= pData
->pPage
;
614 if ( pSet
&& !pPage
->HasExchangeSupport() )
616 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
618 if ( pPage
->FillItemSet( &aTmp
) )
621 pExampleSet
->Put(aTmp
);
622 pOutSet
->Put( aTmp
);
629 void IconChoiceDialog::FocusOnIcon( HyperLinkPageType nId
)
631 // set focus to icon for the current visible page
632 for ( sal_Int32 i
=0; i
<m_pIconCtrl
->GetEntryCount(); i
++)
634 SvxIconChoiceCtrlEntry
* pEntry
= m_pIconCtrl
->GetEntry ( i
);
635 HyperLinkPageType nUserData
= static_cast<HyperLinkPageType
>(reinterpret_cast<sal_uIntPtr
>(pEntry
->GetUserData()));
637 if ( nUserData
== nId
)
639 m_pIconCtrl
->SetCursor( pEntry
);
646 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */