bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / iconcdlg.cxx
blob83bb944b1bb9752e8a1ea70f2e5246db137ac9b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /**********************************************************************
35 | Ctor / Dtor
37 \**********************************************************************/
39 IconChoicePage::IconChoicePage( vcl::Window *pParent, const OString& rID,
40 const OUString& rUIXMLDescription,
41 const SfxItemSet* pItemSet )
42 : TabPage ( pParent, rID, rUIXMLDescription ),
43 pSet ( pItemSet ),
44 bHasExchangeSupport ( false )
46 SetStyle ( GetStyle() | WB_DIALOGCONTROL | WB_HIDE );
50 IconChoicePage::~IconChoicePage()
52 disposeOnce();
55 /**********************************************************************
57 | Activate / Deactivate
59 \**********************************************************************/
61 void IconChoicePage::ActivatePage( const SfxItemSet& )
66 DeactivateRC IconChoicePage::DeactivatePage( SfxItemSet* )
68 return DeactivateRC::LeavePage;
71 bool IconChoicePage::QueryClose()
73 return true;
76 /**********************************************************************
78 | window-methods
80 \**********************************************************************/
82 void IconChoicePage::ImplInitSettings()
84 vcl::Window* pParent = GetParent();
85 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
87 EnableChildTransparentMode();
88 SetParentClipMode( ParentClipMode::NoClip );
89 SetPaintTransparent( true );
90 SetBackground();
92 else
94 EnableChildTransparentMode( false );
95 SetParentClipMode();
96 SetPaintTransparent( false );
98 if ( IsControlBackground() )
99 SetBackground( GetControlBackground() );
100 else
101 SetBackground( pParent->GetBackground() );
106 void IconChoicePage::StateChanged( StateChangedType nType )
108 Window::StateChanged( nType );
110 if ( nType == StateChangedType::ControlBackground )
112 ImplInitSettings();
113 Invalidate();
118 void IconChoicePage::DataChanged( const DataChangedEvent& rDCEvt )
120 Window::DataChanged( rDCEvt );
122 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
123 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
125 ImplInitSettings();
126 Invalidate();
131 // Class IconChoiceDialog
134 /**********************************************************************
136 | Ctor / Dtor
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 ),
150 pSet ( nullptr ),
151 pExampleSet ( nullptr )
153 get(m_pOKBtn, "ok");
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");
161 SetCtrlStyle();
162 m_pIconCtrl->SetClickHdl ( LINK ( this, IconChoiceDialog , ChosePageHdl_Impl ) );
163 m_pIconCtrl->Show();
164 m_pIconCtrl->SetChoiceWithCursor();
165 m_pIconCtrl->SetSelectionMode( SelectionMode::Single );
167 // ItemSet
168 if ( pSet )
170 pExampleSet = new SfxItemSet( *pSet );
171 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
174 // Buttons
175 m_pOKBtn->SetClickHdl ( LINK( this, IconChoiceDialog, OkHdl ) );
176 m_pApplyBtn->SetClickHdl ( LINK( this, IconChoiceDialog, ApplyHdl ) );
177 m_pResetBtn->SetClickHdl( LINK( this, IconChoiceDialog, ResetHdl ) );
178 m_pOKBtn->Show();
179 m_pApplyBtn->Show();
180 m_pCancelBtn->Show();
181 m_pHelpBtn->Show();
182 m_pResetBtn->Show();
185 IconChoiceDialog ::~IconChoiceDialog ()
187 disposeOnce();
190 void IconChoiceDialog::dispose()
192 // save configuration at INI-Manager
193 // and remove pages
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)
200 if ( pData->pPage )
201 pData->pPage.disposeAndClear();
203 maPageList.clear();
205 pRanges.reset();
206 pOutSet.reset();
208 m_pIconCtrl.clear();
209 m_pOKBtn.clear();
210 m_pApplyBtn.clear();
211 m_pCancelBtn.clear();
212 m_pHelpBtn.clear();
213 m_pResetBtn.clear();
214 m_pTabContainer.clear();
215 SfxModalDialog::dispose();
218 /**********************************************************************
220 | add new page
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) );
235 return pEntry;
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 )
253 if ( pData->pPage )
254 pData->pPage->Show();
258 void IconChoiceDialog::HidePageImpl ( IconChoicePageData const * pData )
260 if ( pData->pPage )
261 pData->pPage->Hide();
264 void IconChoiceDialog::ShowPage(HyperLinkPageType nId)
266 HyperLinkPageType nOldPageId = GetCurPageId();
267 bool bInvalidate = nOldPageId != nId;
268 if (bInvalidate)
270 IconChoicePageData* pOldData = GetPageData(nOldPageId);
271 if (pOldData && pOldData->pPage)
273 DeActivatePageImpl();
274 HidePageImpl(pOldData);
277 Invalidate();
279 SetCurPageId(nId);
280 ActivatePageImpl();
281 IconChoicePageData* pNewData = GetPageData(nId);
282 if (pNewData && pNewData->pPage)
283 ShowPageImpl(pNewData);
286 /**********************************************************************
288 | select a page
290 \**********************************************************************/
291 IMPL_LINK_NOARG(IconChoiceDialog , ChosePageHdl_Impl, SvtIconChoiceCtrl*, void)
293 SvxIconChoiceCtrlEntry *pEntry = m_pIconCtrl->GetSelectedEntry();
294 if ( !pEntry )
295 pEntry = m_pIconCtrl->GetCursor( );
297 HyperLinkPageType nId = static_cast<HyperLinkPageType>(reinterpret_cast<sal_uIntPtr>(pEntry->GetUserData()));
299 if( nId != mnCurrentPageId )
301 ShowPage(nId);
305 /**********************************************************************
307 | Button-handler
309 \**********************************************************************/
311 IMPL_LINK_NOARG(IconChoiceDialog, OkHdl, Button*, void)
313 if ( OK_Impl() )
315 Ok();
316 Close();
321 IMPL_LINK_NOARG(IconChoiceDialog, ApplyHdl, Button*, void)
323 if ( OK_Impl() )
325 Ok();
326 Close();
330 IMPL_LINK_NOARG(IconChoiceDialog, ResetHdl, Button*, void)
332 ResetPageImpl ();
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)
343 Close();
346 /**********************************************************************
348 | call page
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" );
357 if ( pData )
359 if ( !pData->pPage )
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;
372 if ( pExampleSet )
373 pData->pPage->ActivatePage( *pExampleSet );
374 SetHelpId( pData->pPage->GetHelpId() );
377 m_pResetBtn->Show();
381 void IconChoiceDialog::DeActivatePageImpl ()
383 IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
385 DeactivateRC nRet = DeactivateRC::LeavePage;
387 if ( pData )
389 IconChoicePage * pPage = pData->pPage;
391 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
392 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
394 if ( pSet )
396 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
398 if ( pPage->HasExchangeSupport() )
399 nRet = pPage->DeactivatePage( &aTmp );
401 if ( ( DeactivateRC::LeavePage & nRet ) &&
402 aTmp.Count() )
404 if (pExampleSet)
405 pExampleSet->Put(aTmp);
406 pOutSet->Put( aTmp );
409 else
411 if ( pPage->HasExchangeSupport() ) //!!!
413 if ( !pExampleSet )
415 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
416 pExampleSet =
417 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
419 nRet = pPage->DeactivatePage( pExampleSet );
421 else
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;
433 else
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 /**********************************************************************
452 | handling itemsets
454 \**********************************************************************/
456 const sal_uInt16* IconChoiceDialog::GetInputRanges( const SfxItemPool& )
458 if ( pSet )
460 SAL_WARN( "cui.dialogs", "Set does already exist!" );
461 return pSet->GetRanges();
464 if ( pRanges )
465 return pRanges.get();
467 pRanges.reset(new sal_uInt16[1]);
468 pRanges[0] = 0;
470 return pRanges.get();
474 void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet )
476 bool bSet = ( pSet != nullptr );
478 pSet = pInSet;
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*/ )
490 // not interested in
494 /**********************************************************************
496 | start dialog
498 \**********************************************************************/
500 short IconChoiceDialog::Execute()
502 if ( maPageList.empty() )
503 return RET_CANCEL;
505 Start_Impl();
507 return Dialog::Execute();
511 void IconChoiceDialog::Start()
513 m_pCancelBtn->SetClickHdl( LINK( this, IconChoiceDialog, CancelHdl ) );
515 Start_Impl();
519 bool IconChoiceDialog::QueryClose()
521 bool bRet = true;
522 for (auto & pData : maPageList)
524 if ( pData->pPage && !pData->pPage->QueryClose() )
526 bRet = false;
527 break;
530 return bRet;
533 void IconChoiceDialog::Start_Impl()
535 FocusOnIcon( mnCurrentPageId );
536 ActivatePageImpl();
539 /**********************************************************************
541 | tool-methods
543 \**********************************************************************/
545 IconChoicePageData* IconChoiceDialog::GetPageData ( HyperLinkPageType nId )
547 IconChoicePageData *pRet = nullptr;
548 for (auto & pData : maPageList)
550 if ( pData->nId == nId )
552 pRet = pData.get();
553 break;
556 return pRet;
559 /**********************************************************************
561 | OK-Status
563 \**********************************************************************/
565 bool IconChoiceDialog::OK_Impl()
567 IconChoicePage* pPage = GetPageData ( mnCurrentPageId )->pPage;
569 bool bEnd = !pPage;
570 if ( pPage )
572 DeactivateRC nRet = DeactivateRC::LeavePage;
573 if ( pSet )
575 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
577 if ( pPage->HasExchangeSupport() )
578 nRet = pPage->DeactivatePage( &aTmp );
580 if ( ( DeactivateRC::LeavePage & nRet )
581 && aTmp.Count() )
583 pExampleSet->Put( aTmp );
584 pOutSet->Put( aTmp );
587 else
588 nRet = pPage->DeactivatePage( nullptr );
589 bEnd = nRet != DeactivateRC::KeepPage;
592 return bEnd;
596 void IconChoiceDialog::Ok()
598 if ( !pOutSet )
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;
612 if ( pPage )
614 if ( pSet && !pPage->HasExchangeSupport() )
616 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
618 if ( pPage->FillItemSet( &aTmp ) )
620 if (pExampleSet)
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 );
640 break;
646 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */