/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace com::sun::star; // static ---------------------------------------------------------------- enum FillType { TRANSPARENT, SOLID, GRADIENT, HATCH, BITMAP, PATTERN }; const sal_uInt16 SvxAreaTabPage::pAreaRanges[] = { XATTR_GRADIENTSTEPCOUNT, XATTR_GRADIENTSTEPCOUNT, SID_ATTR_FILL_STYLE, SID_ATTR_FILL_BITMAP, 0 }; namespace { void lclExtendSize(Size& rSize, const Size& rInputSize) { if (rSize.Width() < rInputSize.Width()) rSize.setWidth( rInputSize.Width() ); if (rSize.Height() < rInputSize.Height()) rSize.setHeight( rInputSize.Height() ); } } // end anonymous namespace /************************************************************************* |* |* Dialog to modify fill-attributes |* \************************************************************************/ SvxAreaTabPage::SvxAreaTabPage(TabPageParent pParent, const SfxItemSet& rInAttrs) : SfxTabPage(pParent, "cui/ui/areatabpage.ui", "AreaTabPage", &rInAttrs) // local fixed not o be changed values for local pointers , maFixed_ChangeType(ChangeType::NONE) // init with pointers to fixed ChangeType , m_pnColorListState(&maFixed_ChangeType) , m_pnBitmapListState(&maFixed_ChangeType) , m_pnPatternListState(&maFixed_ChangeType) , m_pnGradientListState(&maFixed_ChangeType) , m_pnHatchingListState(&maFixed_ChangeType) , m_aXFillAttr(rInAttrs.GetPool()) , m_rXFSet(m_aXFillAttr.GetItemSet()) , m_xFillTab(m_xBuilder->weld_container("fillstylebox")) , m_xBtnNone(m_xBuilder->weld_toggle_button("btnnone")) , m_xBtnColor(m_xBuilder->weld_toggle_button("btncolor")) , m_xBtnGradient(m_xBuilder->weld_toggle_button("btngradient")) , m_xBtnHatch(m_xBuilder->weld_toggle_button("btnhatch")) , m_xBtnBitmap(m_xBuilder->weld_toggle_button("btnbitmap")) , m_xBtnPattern(m_xBuilder->weld_toggle_button("btnpattern")) { maBox.AddButton(m_xBtnNone.get()); maBox.AddButton(m_xBtnColor.get()); maBox.AddButton(m_xBtnGradient.get()); maBox.AddButton(m_xBtnHatch.get()); maBox.AddButton(m_xBtnBitmap.get()); maBox.AddButton(m_xBtnPattern.get()); Link aLink = LINK(this, SvxAreaTabPage, SelectFillTypeHdl_Impl); m_xBtnNone->connect_toggled(aLink); m_xBtnColor->connect_toggled(aLink); m_xBtnGradient->connect_toggled(aLink); m_xBtnHatch->connect_toggled(aLink); m_xBtnBitmap->connect_toggled(aLink); m_xBtnPattern->connect_toggled(aLink); SetExchangeSupport(); TabPageParent aFillTab(m_xFillTab.get(), pParent.pController); // TEMP if (!aFillTab.pController) aFillTab.pParent = GetParentDialog(); // Calculate optimal size of all pages.. m_pFillTabPage.disposeAndReset(SvxColorTabPage::Create(aFillTab, &m_rXFSet)); m_aColorSize = m_xFillTab->get_preferred_size(); m_pFillTabPage.disposeAndReset(SvxGradientTabPage::Create(aFillTab, &m_rXFSet)); Size aGradientSize = m_xFillTab->get_preferred_size(); m_pFillTabPage.disposeAndReset(SvxBitmapTabPage::Create(aFillTab, &m_rXFSet)); Size aBitmapSize = m_xFillTab->get_preferred_size(); m_pFillTabPage.disposeAndReset(SvxHatchTabPage::Create(aFillTab, &m_rXFSet)); Size aHatchSize = m_xFillTab->get_preferred_size(); m_pFillTabPage.disposeAndReset(SvxPatternTabPage::Create(aFillTab, &m_rXFSet)); Size aPatternSize = m_xFillTab->get_preferred_size(); m_pFillTabPage.disposeAndClear(); Size aSize(m_aColorSize); lclExtendSize(aSize, aGradientSize); lclExtendSize(aSize, aBitmapSize); lclExtendSize(aSize, aHatchSize); lclExtendSize(aSize, aPatternSize); m_xFillTab->set_size_request(aSize.Width(), aSize.Height()); } SvxAreaTabPage::~SvxAreaTabPage() { disposeOnce(); } void SvxAreaTabPage::dispose() { m_pFillTabPage.disposeAndClear(); SfxTabPage::dispose(); } void SvxAreaTabPage::ActivatePage( const SfxItemSet& rSet ) { drawing::FillStyle eXFS = drawing::FillStyle_NONE; if( rSet.GetItemState( XATTR_FILLSTYLE ) != SfxItemState::DONTCARE ) { XFillStyleItem aFillStyleItem( static_cast( rSet.Get( GetWhich( XATTR_FILLSTYLE ) ) ) ); eXFS = aFillStyleItem.GetValue(); m_rXFSet.Put( aFillStyleItem ); } switch(eXFS) { default: case drawing::FillStyle_NONE: { SelectFillTypeHdl_Impl(*m_xBtnNone); break; } case drawing::FillStyle_SOLID: { m_rXFSet.Put( static_cast( rSet.Get( GetWhich( XATTR_FILLCOLOR ) ) ) ); SelectFillTypeHdl_Impl(*m_xBtnColor); break; } case drawing::FillStyle_GRADIENT: { m_rXFSet.Put( static_cast( rSet.Get( GetWhich( XATTR_FILLGRADIENT ) ) ) ); SelectFillTypeHdl_Impl(*m_xBtnGradient); break; } case drawing::FillStyle_HATCH: { m_rXFSet.Put( rSet.Get(XATTR_FILLHATCH) ); m_rXFSet.Put( rSet.Get(XATTR_FILLBACKGROUND) ); m_rXFSet.Put( rSet.Get(XATTR_FILLCOLOR) ); SelectFillTypeHdl_Impl(*m_xBtnHatch); break; } case drawing::FillStyle_BITMAP: { XFillBitmapItem aItem(static_cast( rSet.Get( GetWhich( XATTR_FILLBITMAP ) ) )); // pass full item set here, bitmap fill has many attributes (tiling, size, offset etc.) m_rXFSet.Put( rSet ); if(!aItem.isPattern()) SelectFillTypeHdl_Impl(*m_xBtnBitmap); else SelectFillTypeHdl_Impl(*m_xBtnPattern); break; } } } template< typename TTabPage > DeactivateRC SvxAreaTabPage::DeactivatePage_Impl( SfxItemSet* _pSet ) { return static_cast(*m_pFillTabPage).DeactivatePage(_pSet); } DeactivateRC SvxAreaTabPage::DeactivatePage( SfxItemSet* _pSet ) { FillType eFillType = static_cast(maBox.GetCurrentButtonPos()); switch( eFillType ) { case TRANSPARENT: { // Fill: None doesn't have its own tabpage and thus // implementation of FillItemSet, so we supply it here XFillStyleItem aStyleItem( drawing::FillStyle_NONE ); _pSet->Put( aStyleItem ); break; } case SOLID: return DeactivatePage_Impl(_pSet); case GRADIENT: return DeactivatePage_Impl(_pSet); case HATCH: return DeactivatePage_Impl(_pSet); case BITMAP: return DeactivatePage_Impl(_pSet); case PATTERN: return DeactivatePage_Impl(_pSet); default: break; } return DeactivateRC::LeavePage; } template< typename TTabPage > bool SvxAreaTabPage::FillItemSet_Impl( SfxItemSet* rAttrs) { return static_cast( *m_pFillTabPage ).FillItemSet( rAttrs ); } bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) { FillType eFillType = static_cast(maBox.GetCurrentButtonPos()); switch( eFillType ) { case TRANSPARENT: { rAttrs->Put( XFillStyleItem( drawing::FillStyle_NONE ) ); return true; } case SOLID: { return FillItemSet_Impl( rAttrs ); } case GRADIENT: { return FillItemSet_Impl( rAttrs ); } case HATCH: { return FillItemSet_Impl( rAttrs ); } case BITMAP: { return FillItemSet_Impl( rAttrs ); } case PATTERN: { return FillItemSet_Impl( rAttrs ); } default: return false; } } template< typename TTabPage > void SvxAreaTabPage::Reset_Impl( const SfxItemSet* rAttrs ) { static_cast( *m_pFillTabPage ).Reset( rAttrs ); } void SvxAreaTabPage::Reset( const SfxItemSet* rAttrs ) { auto eFillType = maBox.GetCurrentButtonPos(); switch(eFillType) { case SOLID: { Reset_Impl( rAttrs ); break; } case GRADIENT: { Reset_Impl( rAttrs ); break; } case HATCH: { Reset_Impl( rAttrs ); break; } case BITMAP: { Reset_Impl( rAttrs ); break; } case PATTERN: { Reset_Impl( rAttrs ); break; } default: break; } } VclPtr SvxAreaTabPage::Create(TabPageParent pParent, const SfxItemSet* rAttrs) { return VclPtr::Create(pParent, *rAttrs); } namespace { VclPtr lcl_CreateFillStyleTabPage(sal_uInt16 nId, TabPageParent pParent, const SfxItemSet& rSet) { CreateTabPage fnCreate = nullptr; switch(nId) { case TRANSPARENT: fnCreate = nullptr; break; case SOLID: fnCreate = &SvxColorTabPage::Create; break; case GRADIENT: fnCreate = &SvxGradientTabPage::Create; break; case HATCH: fnCreate = &SvxHatchTabPage::Create; break; case BITMAP: fnCreate = &SvxBitmapTabPage::Create; break; case PATTERN: fnCreate = &SvxPatternTabPage::Create; break; } VclPtr pRet = fnCreate ? (*fnCreate)( pParent, &rSet ) : nullptr; return pRet; } } IMPL_LINK(SvxAreaTabPage, SelectFillTypeHdl_Impl, weld::ToggleButton&, rButton, void) { sal_Int32 nPos = maBox.GetButtonPos(&rButton); if(nPos != -1 && nPos != maBox.GetCurrentButtonPos()) { maBox.SelectButton(&rButton); FillType eFillType = static_cast(maBox.GetCurrentButtonPos()); TabPageParent aFillTab(m_xFillTab.get(), GetDialogController()); // TEMP if (!aFillTab.pController) aFillTab.pParent = GetParentDialog(); m_pFillTabPage.disposeAndReset(lcl_CreateFillStyleTabPage(eFillType, aFillTab, m_rXFSet)); if (m_pFillTabPage) { m_pFillTabPage->SetTabDialog(GetTabDialog()); m_pFillTabPage->SetDialogController(GetDialogController()); } CreatePage( eFillType , m_pFillTabPage); } } void SvxAreaTabPage::PageCreated(const SfxAllItemSet& aSet) { const SvxColorListItem* pColorListItem = aSet.GetItem(SID_COLOR_TABLE, false); const SvxGradientListItem* pGradientListItem = aSet.GetItem(SID_GRADIENT_LIST, false); const SvxHatchListItem* pHatchingListItem = aSet.GetItem(SID_HATCH_LIST, false); const SvxBitmapListItem* pBitmapListItem = aSet.GetItem(SID_BITMAP_LIST, false); const SvxPatternListItem* pPatternListItem = aSet.GetItem(SID_PATTERN_LIST, false); if (pColorListItem) SetColorList(pColorListItem->GetColorList()); if (pGradientListItem) SetGradientList(pGradientListItem->GetGradientList()); if (pHatchingListItem) SetHatchingList(pHatchingListItem->GetHatchList()); if (pBitmapListItem) SetBitmapList(pBitmapListItem->GetBitmapList()); if (pPatternListItem) SetPatternList(pPatternListItem->GetPatternList()); } void SvxAreaTabPage::CreatePage( sal_Int32 nId, SfxTabPage* pTab ) { if(nId == SOLID ) { static_cast(pTab)->SetColorList( m_pColorList ); static_cast(pTab)->SetColorChgd( m_pnColorListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); static_cast(pTab)->Reset(&m_rXFSet); static_cast(pTab)->Show(); } else if(nId == GRADIENT) { static_cast(pTab)->SetColorList( m_pColorList ); static_cast(pTab)->SetGradientList( m_pGradientList ); static_cast(pTab)->SetGrdChgd( m_pnGradientListState ); static_cast(pTab)->SetColorChgd( m_pnColorListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); static_cast(pTab)->Reset(&m_rXFSet); static_cast(pTab)->Show(); } else if(nId == HATCH) { static_cast(pTab)->SetColorList( m_pColorList ); static_cast(pTab)->SetHatchingList( m_pHatchingList ); static_cast(pTab)->SetHtchChgd( m_pnHatchingListState ); static_cast(pTab)->SetColorChgd( m_pnColorListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); static_cast(pTab)->Reset(&m_rXFSet); static_cast(pTab)->Show(); } else if(nId == BITMAP) { static_cast(pTab)->SetBitmapList( m_pBitmapList ); static_cast(pTab)->SetBmpChgd( m_pnBitmapListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); static_cast(pTab)->Reset(&m_rXFSet); static_cast(pTab)->Show(); } else if(nId == PATTERN) { static_cast(pTab)->SetColorList( m_pColorList ); static_cast(pTab)->SetPatternList( m_pPatternList ); static_cast(pTab)->SetPtrnChgd( m_pnPatternListState ); static_cast(pTab)->SetColorChgd( m_pnColorListState ); static_cast(pTab)->Construct(); static_cast(pTab)->ActivatePage( m_rXFSet ); static_cast(pTab)->Reset( &m_rXFSet ); static_cast(pTab)->Show(); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */