diff options
Diffstat (limited to 'sd/source/ui/sidebar')
47 files changed, 10681 insertions, 0 deletions
diff --git a/sd/source/ui/sidebar/AllMasterPagesSelector.cxx b/sd/source/ui/sidebar/AllMasterPagesSelector.cxx new file mode 100644 index 000000000000..dbeb63f0b0b8 --- /dev/null +++ b/sd/source/ui/sidebar/AllMasterPagesSelector.cxx @@ -0,0 +1,231 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "AllMasterPagesSelector.hxx" +#include "PreviewValueSet.hxx" +#include "ViewShellBase.hxx" +#include "SidebarShellManager.hxx" +#include "MasterPageContainer.hxx" +#include "MasterPageDescriptor.hxx" +#include "app.hrc" +#include "helpids.h" + +#include <tools/link.hxx> +#include <set> + +namespace { + +using namespace sd::sidebar; + +int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor) +{ + int nPriority (0); + switch (rpDescriptor->GetURLClassification()) + { + case MasterPageDescriptor::URLCLASS_USER: nPriority = 0; break; + case MasterPageDescriptor::URLCLASS_LAYOUT: nPriority = 1; break; + case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break; + case MasterPageDescriptor::URLCLASS_OTHER: nPriority = 3; break; + case MasterPageDescriptor::URLCLASS_UNKNOWN: nPriority = 4; break; + default: + case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break; + } + return nPriority; +} + + +class MasterPageDescriptorOrder +{ +public: + bool operator() ( + const SharedMasterPageDescriptor& rp1, + const SharedMasterPageDescriptor& rp2) + { + if (rp1->meOrigin == MasterPageContainer::DEFAULT) + return true; + else if (rp2->meOrigin == MasterPageContainer::DEFAULT) + return false; + else if (rp1->GetURLClassification() == rp2->GetURLClassification()) + return rp1->mnTemplateIndex < rp2->mnTemplateIndex; + else + return GetURLPriority(rp1) < GetURLPriority(rp2); + } +}; + +} // end of anonymous namespace + + + +namespace sd { namespace sidebar { + +class AllMasterPagesSelector::SortedMasterPageDescriptorList + : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder> +{ +public: + SortedMasterPageDescriptorList (void) {} +}; + + + + +MasterPagesSelector* AllMasterPagesSelector::Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) +{ + SdDrawDocument* pDocument = rViewShellBase.GetDocument(); + if (pDocument == NULL) + return NULL; + + ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer()); + + MasterPagesSelector* pSelector( + new AllMasterPagesSelector ( + pParent, + *pDocument, + rViewShellBase, + pContainer, + rxSidebar)); + pSelector->LateInit(); + pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_ALL); + + return pSelector; +} + + + + +AllMasterPagesSelector::AllMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) + : MasterPagesSelector(pParent, rDocument, rBase, rpContainer, rxSidebar), + mpSortedMasterPages(new SortedMasterPageDescriptorList()) +{ + MasterPagesSelector::Fill(); +} + + + + +AllMasterPagesSelector::~AllMasterPagesSelector (void) +{ +} + + + + +void AllMasterPagesSelector::Fill (ItemList& rItemList) +{ + if (mpSortedMasterPages->empty()) + UpdateMasterPageList(); + UpdatePageSet(rItemList); +} + + + + +void AllMasterPagesSelector::NotifyContainerChangeEvent ( + const MasterPageContainerChangeEvent& rEvent) +{ + switch (rEvent.meEventType) + { + case MasterPageContainerChangeEvent::CHILD_ADDED: + AddItem(rEvent.maChildToken); + MasterPagesSelector::Fill(); + break; + + case MasterPageContainerChangeEvent::INDEX_CHANGED: + case MasterPageContainerChangeEvent::INDEXES_CHANGED: + mpSortedMasterPages->clear(); + MasterPagesSelector::Fill(); + break; + + default: + MasterPagesSelector::NotifyContainerChangeEvent(rEvent); + break; + } +} + + + + +void AllMasterPagesSelector::UpdateMasterPageList (void) +{ + mpSortedMasterPages->clear(); + int nTokenCount = mpContainer->GetTokenCount(); + for (int i=0; i<nTokenCount; i++) + AddItem(mpContainer->GetTokenForIndex(i)); +} + + + + +void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken) +{ + switch (mpContainer->GetOriginForToken(aToken)) + { + case MasterPageContainer::DEFAULT: + case MasterPageContainer::TEMPLATE: + // Templates are added only when coming from the + // MasterPageContainerFiller so that they have an id which + // defines their place in the list. Templates (pre) loaded from + // RecentlyUsedMasterPages are ignored (they will be loaded + // later by the MasterPageContainerFiller.) + if (mpContainer->GetTemplateIndexForToken(aToken) >= 0) + mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken)); + break; + + default: + break; + } +} + + + + +void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList) +{ + SortedMasterPageDescriptorList::const_iterator iDescriptor; + SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end()); + for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor) + rItemList.push_back((*iDescriptor)->maToken); +} + + + + +void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet) +{ + // MasterPagesSelector::GetState(rItemSet); + + if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE) + rItemSet.DisableItem(SID_TP_EDIT_MASTER); +} + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/AllMasterPagesSelector.hxx b/sd/source/ui/sidebar/AllMasterPagesSelector.hxx new file mode 100644 index 000000000000..f5e79015d207 --- /dev/null +++ b/sd/source/ui/sidebar/AllMasterPagesSelector.hxx @@ -0,0 +1,91 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_ALL_MASTER_PAGES_SELECTOR_HXX +#define SD_SIDEBAR_PANELS_ALL_MASTER_PAGES_SELECTOR_HXX + +#include "MasterPagesSelector.hxx" + +#include <memory> + +namespace sd { namespace sidebar { + + +/** Show a list of all available master pages so that the user can assign + them to the document. +*/ +class AllMasterPagesSelector + : public MasterPagesSelector +{ +public: + static MasterPagesSelector* Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + + /** Scan the set of templates for the ones whose first master pages are + shown by this control and store them in the MasterPageContainer. + */ + virtual void Fill (ItemList& rItemList); + + virtual void GetState (SfxItemSet& rItemSet); + +protected: + virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent); + +private: + /** The list of master pages displayed by this class. + */ + class SortedMasterPageDescriptorList; + ::std::auto_ptr<SortedMasterPageDescriptorList> mpSortedMasterPages; + + AllMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + virtual ~AllMasterPagesSelector (void); + + void AddTemplate (const TemplateEntry& rEntry); + + /** This filter returns <TRUE/> when the master page specified by the + given file name belongs to the set of Impress master pages. + */ + bool FileFilter (const String& sFileName); + + void AddItem (MasterPageContainer::Token aToken); + + /** Add all items in the internal master page list into the given list. + */ + void UpdatePageSet (ItemList& rItemList); + + /** Update the internal list of master pages that are to show in the + control. + */ + void UpdateMasterPageList (void); + + using MasterPagesSelector::Fill; +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx b/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx new file mode 100644 index 000000000000..4d4ff45f0c0c --- /dev/null +++ b/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx @@ -0,0 +1,355 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "CurrentMasterPagesSelector.hxx" +#include "PreviewValueSet.hxx" +#include "ViewShellBase.hxx" +#include "SidebarShellManager.hxx" +#include "DrawViewShell.hxx" +#include "drawdoc.hxx" +#include "sdpage.hxx" +#include "MasterPageContainer.hxx" +#include "MasterPageDescriptor.hxx" +#include "EventMultiplexer.hxx" +#include "app.hrc" +#include "DrawDocShell.hxx" +#include "DrawViewShell.hxx" +#include "res_bmp.hrc" +#include "sdresid.hxx" +#include "helpids.h" + +#include <vcl/image.hxx> +#include <svx/svdmodel.hxx> +#include <sfx2/request.hxx> + +#include <set> + + +using namespace ::com::sun::star; + +namespace sd { namespace sidebar { + +MasterPagesSelector* CurrentMasterPagesSelector::Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) +{ + SdDrawDocument* pDocument = rViewShellBase.GetDocument(); + if (pDocument == NULL) + return NULL; + + ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer()); + + MasterPagesSelector* pSelector( + new CurrentMasterPagesSelector ( + pParent, + *pDocument, + rViewShellBase, + pContainer, + rxSidebar)); + pSelector->LateInit(); + pSelector->SetHelpId( HID_SD_TASK_PANE_PREVIEW_CURRENT ); + + return pSelector; +} + + + + +CurrentMasterPagesSelector::CurrentMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) + : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar) +{ + // For this master page selector only we change the default action for + // left clicks. + mnDefaultClickAction = SID_TP_APPLY_TO_SELECTED_SLIDES; + + Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener)); + rBase.GetEventMultiplexer()->AddEventListener(aLink, + sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE + | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL + | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER + | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER + | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED + | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED + | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED); +} + + + + +CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void) +{ + if (mrDocument.GetDocSh() != NULL) + { + EndListening(*mrDocument.GetDocSh()); + } + else + { + OSL_ASSERT(mrDocument.GetDocSh() != NULL); + } + + Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener)); + mrBase.GetEventMultiplexer()->RemoveEventListener(aLink); +} + + + + +void CurrentMasterPagesSelector::LateInit (void) +{ + MasterPagesSelector::LateInit(); + MasterPagesSelector::Fill(); + if (mrDocument.GetDocSh() != NULL) + { + StartListening(*mrDocument.GetDocSh()); + } + else + { + OSL_ASSERT(mrDocument.GetDocSh() != NULL); + } +} + + + + +void CurrentMasterPagesSelector::Fill (ItemList& rItemList) +{ + sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD); + SdPage* pMasterPage; + // Remember the names of the master pages that have been inserted to + // avoid double insertion. + ::std::set<String> aMasterPageNames; + for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++) + { + pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD); + if (pMasterPage == NULL) + continue; + + // Use the name of the master page to avoid duplicate entries. + String sName (pMasterPage->GetName()); + if (aMasterPageNames.find(sName)!=aMasterPageNames.end()) + continue; + aMasterPageNames.insert (sName); + + // Look up the master page in the container and, when it is not yet + // in it, insert it. + MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage); + if (aToken == MasterPageContainer::NIL_TOKEN) + { + SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( + MasterPageContainer::MASTERPAGE, + nIndex, + String(), + pMasterPage->GetName(), + String(), + pMasterPage->IsPrecious(), + ::boost::shared_ptr<PageObjectProvider>(new ExistingPageProvider(pMasterPage)), + ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider()))); + aToken = mpContainer->PutMasterPage(pDescriptor); + } + + rItemList.push_back(aToken); + } +} + + + + +ResId CurrentMasterPagesSelector::GetContextMenuResId (void) const +{ + return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP); +} + + + + +void CurrentMasterPagesSelector::UpdateSelection (void) +{ + // Iterate over all pages and for the selected ones put the name of + // their master page into a set. + sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD); + SdPage* pPage; + ::std::set<String> aNames; + sal_uInt16 nIndex; + bool bLoop (true); + for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++) + { + pPage = mrDocument.GetSdPage (nIndex, PK_STANDARD); + if (pPage != NULL && pPage->IsSelected()) + { + if ( ! pPage->TRG_HasMasterPage()) + { + // One of the pages has no master page. This is an + // indicator for that this method is called in the middle of + // a document change and that the model is not in a valid + // state. Therefore we stop update the selection and wait + // for another call to UpdateSelection when the model is + // valid again. + bLoop = false; + } + else + { + SdrPage& rMasterPage (pPage->TRG_GetMasterPage()); + SdPage* pMasterPage = static_cast<SdPage*>(&rMasterPage); + if (pMasterPage != NULL) + aNames.insert (pMasterPage->GetName()); + } + } + } + + // Find the items for the master pages in the set. + sal_uInt16 nItemCount (PreviewValueSet::GetItemCount()); + for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++) + { + String sName (PreviewValueSet::GetItemText (nIndex)); + if (aNames.find(sName) != aNames.end()) + { + PreviewValueSet::SelectItem (nIndex); + } + } +} + + + + +void CurrentMasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId) +{ + if (nCommandId == SID_DELETE_MASTER_PAGE) + { + // Check once again that the master page can safely be deleted, + // i.e. is not used. + SdPage* pMasterPage = GetSelectedMasterPage(); + if (pMasterPage != NULL + && mrDocument.GetMasterPageUserCount(pMasterPage) == 0) + { + // Removing the precious flag so that the following call to + // RemoveUnnessesaryMasterPages() will remove this master page. + pMasterPage->SetPrecious(false); + mrDocument.RemoveUnnecessaryMasterPages(pMasterPage, sal_False, sal_True); + } + } + else + MasterPagesSelector::ExecuteCommand(nCommandId); +} + + + + +void CurrentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu) +{ + // Disable the SID_DELTE_MASTER slot when there is only one master page. + if (mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0) + { + if (rMenu.GetItemPos(SID_DELETE_MASTER_PAGE) != MENU_ITEM_NOTFOUND) + rMenu.EnableItem(SID_DELETE_MASTER_PAGE, sal_False); + } + + ::boost::shared_ptr<DrawViewShell> pDrawViewShell ( + ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell())); + if (pDrawViewShell + && pDrawViewShell->GetEditMode() == EM_MASTERPAGE) + { + if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND) + rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False); + } + + MasterPagesSelector::ProcessPopupMenu(rMenu); +} + + + + + + +IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener, + sd::tools::EventMultiplexerEvent*,pEvent) +{ + if (pEvent != NULL) + { + switch (pEvent->meEventId) + { + case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE: + case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL: + case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER: + case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION: + UpdateSelection(); + break; + + case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER: + // This is tricky. If a master page is removed, moved, or + // added we have to wait until both the notes master page + // and the standard master page have been removed, moved, + // or added. We do this by looking at the number of master + // pages which has to be odd in the consistent state (the + // handout master page is always present). If the number is + // even we ignore the hint. + if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1) + MasterPagesSelector::Fill(); + break; + + case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED: + case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED: + case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED: + InvalidatePreview((const SdPage*)pEvent->mpUserData); + break; + } + } + + return 0; +} + + + + +void CurrentMasterPagesSelector::Notify (SfxBroadcaster&, const SfxHint& rHint) +{ + const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint); + if (pSimpleHint != NULL) + { + if (pSimpleHint->GetId() == SFX_HINT_DOCCHANGED) + { + // Is the edit view visible in the center pane? + ::boost::shared_ptr<DrawViewShell> pDrawViewShell ( + ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell())); + if (pDrawViewShell.get() != NULL) + { + // Is the edit view in master page mode? + if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE) + { + // Mark the currently edited master page as precious. + SdPage* pCurrentMasterPage = pDrawViewShell->getCurrentPage(); + if (pCurrentMasterPage != NULL) + pCurrentMasterPage->SetPrecious(true); + } + } + } + } +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx b/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx new file mode 100644 index 000000000000..45f1b2018a8b --- /dev/null +++ b/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx @@ -0,0 +1,88 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_CURRENT_MASTER_PAGES_SELECTOR_HXX +#define SD_SIDEBAR_PANELS_CURRENT_MASTER_PAGES_SELECTOR_HXX + +#include "MasterPagesSelector.hxx" +#include <com/sun/star/lang/XComponent.hpp> + + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + + +namespace sd { namespace tools { class EventMultiplexerEvent; } } + + +namespace sd { namespace sidebar { + + +/** Show the master pages currently used by a SdDrawDocument. +*/ +class CurrentMasterPagesSelector + : public MasterPagesSelector, + public SfxListener +{ +public: + static MasterPagesSelector* Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + + /** Set the selection so that the master page is selected that is + used by the currently selected page of the document in the + center pane. + */ + virtual void UpdateSelection (void); + + /** Copy all master pages that are to be shown into the given list. + */ + virtual void Fill (ItemList& rItemList); + + using MasterPagesSelector::Fill; + +protected: + virtual ResId GetContextMenuResId (void) const; + + virtual void ProcessPopupMenu (Menu& rMenu); + virtual void ExecuteCommand (const sal_Int32 nCommandId); + +private: + cssu::Reference<css::lang::XComponent> mxListener; + + CurrentMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + virtual ~CurrentMasterPagesSelector (void); + + virtual void LateInit (void); + + DECL_LINK(EventMultiplexerListener,sd::tools::EventMultiplexerEvent*); + void Notify (SfxBroadcaster&, const SfxHint& rHint); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/CustomAnimationPanel.cxx b/sd/source/ui/sidebar/CustomAnimationPanel.cxx new file mode 100644 index 000000000000..5fd87d2a2a00 --- /dev/null +++ b/sd/source/ui/sidebar/CustomAnimationPanel.cxx @@ -0,0 +1,79 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "CustomAnimationPanel.hxx" + +#include "ViewShellBase.hxx" + + +namespace sd { + extern ::Window * createCustomAnimationPanel (::Window* pParent, ViewShellBase& rBase); + extern sal_Int32 getCustomAnimationPanelMinimumHeight (::Window* pParent); +} + + + + +namespace sd { namespace sidebar { + + +CustomAnimationPanel::CustomAnimationPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) + : PanelBase( + pParentWindow, + rViewShellBase) +{ +#ifdef DEBUG + SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:CustomAnimationPanel"))); +#endif +} + + + + +CustomAnimationPanel::~CustomAnimationPanel (void) +{ +} + + + + +::Window* CustomAnimationPanel::CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) +{ + return createCustomAnimationPanel(pParentWindow, rViewShellBase); +} + + + + +css::ui::LayoutSize CustomAnimationPanel::GetHeightForWidth (const sal_Int32 nWidth) +{ + const sal_Int32 nMinimumHeight(getCustomAnimationPanelMinimumHeight(mpWrappedControl.get())); + return css::ui::LayoutSize(nMinimumHeight,-1, nMinimumHeight); +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/CustomAnimationPanel.hxx b/sd/source/ui/sidebar/CustomAnimationPanel.hxx new file mode 100644 index 000000000000..12f2316c63c9 --- /dev/null +++ b/sd/source/ui/sidebar/CustomAnimationPanel.hxx @@ -0,0 +1,50 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_CUSTOM_ANIMATION_PANEL_HXX +#define SD_SIDEBAR_CUSTOM_ANIMATION_PANEL_HXX + +#include "PanelBase.hxx" + + +namespace sd { namespace sidebar { + +class CustomAnimationPanel + : public PanelBase +{ +public: + CustomAnimationPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); + virtual ~CustomAnimationPanel (void); + + // ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + +protected: + virtual ::Window* CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/DocumentHelper.cxx b/sd/source/ui/sidebar/DocumentHelper.cxx new file mode 100644 index 000000000000..1ae5a2154865 --- /dev/null +++ b/sd/source/ui/sidebar/DocumentHelper.cxx @@ -0,0 +1,578 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "DocumentHelper.hxx" + +#include "drawdoc.hxx" +#include "DrawDocShell.hxx" +#include "sdpage.hxx" +#include "glob.hxx" +#include "unmovss.hxx" +#include "strings.hrc" +#include "sdresid.hxx" +#include "undoback.hxx" +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include "stlpool.hxx" +#include <svx/xfillit0.hxx> +#include <tools/diagnose_ex.h> + +using namespace ::com::sun::star; + +namespace sd { namespace sidebar { + +SdPage* DocumentHelper::CopyMasterPageToLocalDocument ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage) +{ + SdPage* pNewMasterPage = NULL; + + do + { + if (pMasterPage == NULL) + break; + + // Check the presence of the source document. + SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>( + pMasterPage->GetModel()); + if (pSourceDocument == NULL) + break; + + // When the given master page already belongs to the target document + // then there is nothing more to do. + if (pSourceDocument == &rTargetDocument) + { + pNewMasterPage = pMasterPage; + break; + } + + // Test if the master pages of both the slide and its notes page are + // present. This is not the case when we are called during the + // creation of the slide master page because then the notes master + // page is not there. + sal_uInt16 nSourceMasterPageCount = pSourceDocument->GetMasterPageCount(); + if (nSourceMasterPageCount%2 == 0) + // There should be 1 handout page + n slide masters + n notes + // masters = 2*n+1. An even value indicates that a new slide + // master but not yet the notes master has been inserted. + break; + sal_uInt16 nIndex = pMasterPage->GetPageNum(); + if (nSourceMasterPageCount <= nIndex+1) + break; + // Get the slide master page. + if (pMasterPage != static_cast<SdPage*>( + pSourceDocument->GetMasterPage(nIndex))) + break; + // Get the notes master page. + SdPage* pNotesMasterPage = static_cast<SdPage*>( + pSourceDocument->GetMasterPage(nIndex+1)); + if (pNotesMasterPage == NULL) + break; + + + // Check if a master page with the same name as that of the given + // master page already exists. + bool bPageExists (false); + sal_uInt16 nMasterPageCount(rTargetDocument.GetMasterSdPageCount(PK_STANDARD)); + for (sal_uInt16 nMaster=0; nMaster<nMasterPageCount; nMaster++) + { + SdPage* pCandidate = static_cast<SdPage*>( + rTargetDocument.GetMasterSdPage (nMaster, PK_STANDARD)); + if (pMasterPage!=NULL + && pCandidate->GetName().CompareTo(pMasterPage->GetName())==0) + { + bPageExists = true; + pNewMasterPage = pCandidate; + break; + } + } + if (bPageExists) + break; + + // Create a new slide (and its notes page.) + uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier ( + rTargetDocument.getUnoModel(), uno::UNO_QUERY); + if ( ! xSlideSupplier.is()) + break; + uno::Reference<drawing::XDrawPages> xSlides ( + xSlideSupplier->getDrawPages(), uno::UNO_QUERY); + if ( ! xSlides.is()) + break; + xSlides->insertNewByIndex (xSlides->getCount()); + + // Set a layout. + SdPage* pSlide = rTargetDocument.GetSdPage( + rTargetDocument.GetSdPageCount(PK_STANDARD)-1, + PK_STANDARD); + if (pSlide == NULL) + break; + pSlide->SetAutoLayout(AUTOLAYOUT_TITLE, sal_True); + + // Create a copy of the master page and the associated notes + // master page and insert them into our document. + pNewMasterPage = AddMasterPage(rTargetDocument, pMasterPage); + if (pNewMasterPage==NULL) + break; + SdPage* pNewNotesMasterPage + = AddMasterPage(rTargetDocument, pNotesMasterPage); + if (pNewNotesMasterPage==NULL) + break; + + // Make the connection from the new slide to the master page + // (and do the same for the notes page.) + rTargetDocument.SetMasterPage ( + rTargetDocument.GetSdPageCount(PK_STANDARD)-1, + pNewMasterPage->GetName(), + &rTargetDocument, + sal_False, // Connect the new master page with the new slide but + // do not modify other (master) pages. + sal_True); + } + while (false); + + // We are not interested in any automatisms for our modified internal + // document. + rTargetDocument.SetChanged (sal_False); + + return pNewMasterPage; +} + + + + +SdPage* DocumentHelper::GetSlideForMasterPage (SdPage* pMasterPage) +{ + SdPage* pCandidate = NULL; + + SdDrawDocument* pDocument = NULL; + if (pMasterPage != NULL) + pDocument = dynamic_cast<SdDrawDocument*>(pMasterPage->GetModel()); + + // Iterate over all pages and check if it references the given master + // page. + if (pDocument!=NULL && pDocument->GetSdPageCount(PK_STANDARD) > 0) + { + // In most cases a new slide has just been inserted so start with + // the last page. + sal_uInt16 nPageIndex (pDocument->GetSdPageCount(PK_STANDARD)-1); + bool bFound (false); + while ( ! bFound) + { + pCandidate = pDocument->GetSdPage( + nPageIndex, + PK_STANDARD); + if (pCandidate != NULL) + { + if (static_cast<SdPage*>(&pCandidate->TRG_GetMasterPage()) + == pMasterPage) + { + bFound = true; + break; + } + } + + if (nPageIndex == 0) + break; + else + nPageIndex --; + } + + // If no page was found that refernced the given master page reset + // the pointer that is returned. + if ( ! bFound) + pCandidate = NULL; + } + + return pCandidate; +} + + + + +SdPage* DocumentHelper::AddMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage) +{ + SdPage* pClonedMasterPage = NULL; + + if (pMasterPage!=NULL) + { + try + { + // Duplicate the master page. + pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone()); + + // Copy the necessary styles. + SdDrawDocument* pSourceDocument + = static_cast<SdDrawDocument*>(pMasterPage->GetModel()); + if (pSourceDocument != NULL) + ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage); + + // Copy the precious flag. + pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious()); + + // Now that the styles are available we can insert the cloned + // master page. + rTargetDocument.InsertMasterPage (pClonedMasterPage); + } + catch (uno::Exception& rException) + { + pClonedMasterPage = NULL; + DBG_UNHANDLED_EXCEPTION(); + } + catch (::std::exception rException) + { + pClonedMasterPage = NULL; + OSL_TRACE ("caught general exception"); + } + catch (...) + { + pClonedMasterPage = NULL; + OSL_TRACE ("caught general exception"); + } + } + + return pClonedMasterPage; +} + + + + +void DocumentHelper::ProvideStyles ( + SdDrawDocument& rSourceDocument, + SdDrawDocument& rTargetDocument, + SdPage* pPage) +{ + // Get the layout name of the given page. + String sLayoutName (pPage->GetLayoutName()); + sLayoutName.Erase (sLayoutName.SearchAscii (SD_LT_SEPARATOR)); + + // Copy the style sheet from source to target document. + SdStyleSheetPool* pSourceStyleSheetPool = + static_cast<SdStyleSheetPool*>(rSourceDocument.GetStyleSheetPool()); + SdStyleSheetPool* pTargetStyleSheetPool = + static_cast<SdStyleSheetPool*>(rTargetDocument.GetStyleSheetPool()); + SdStyleSheetVector aCreatedStyles; + pTargetStyleSheetPool->CopyLayoutSheets ( + sLayoutName, + *pSourceStyleSheetPool, + aCreatedStyles); + + // Add an undo action for the copied style sheets. + if( !aCreatedStyles.empty() ) + { + ::svl::IUndoManager* pUndoManager = rTargetDocument.GetDocSh()->GetUndoManager(); + if (pUndoManager != NULL) + { + SdMoveStyleSheetsUndoAction* pMovStyles = + new SdMoveStyleSheetsUndoAction ( + &rTargetDocument, + aCreatedStyles, + sal_True); + pUndoManager->AddUndoAction (pMovStyles); + } + } +} + + + + +void DocumentHelper::AssignMasterPageToPageList ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList) +{ + do + { + if (pMasterPage == NULL && pMasterPage->IsMasterPage()) + break; + + // Make the layout name by stripping ouf the layout postfix from the + // layout name of the given master page. + String sFullLayoutName (pMasterPage->GetLayoutName()); + String sBaseLayoutName (sFullLayoutName); + sBaseLayoutName.Erase (sBaseLayoutName.SearchAscii (SD_LT_SEPARATOR)); + + if (rpPageList->empty()) + break; + + // Create a second list that contains only the valid pointers to + // pages for which an assignment is necessary. + ::std::vector<SdPage*>::const_iterator iPage; + ::std::vector<SdPage*> aCleanedList; + for (iPage=rpPageList->begin(); iPage!=rpPageList->end(); ++iPage) + { + OSL_ASSERT(*iPage!=NULL && (*iPage)->GetModel() == &rTargetDocument); + if (*iPage != NULL + && (*iPage)->GetLayoutName().CompareTo(sFullLayoutName)!=0) + { + aCleanedList.push_back(*iPage); + } + } + if (aCleanedList.empty() ) + break; + + ::svl::IUndoManager* pUndoMgr = rTargetDocument.GetDocSh()->GetUndoManager(); + if( pUndoMgr ) + pUndoMgr->EnterListAction(String(SdResId(STR_UNDO_SET_PRESLAYOUT)), String()); + + SdPage* pMasterPageInDocument = ProvideMasterPage(rTargetDocument,pMasterPage,rpPageList); + if (pMasterPageInDocument == NULL) + break; + + // Assign the master pages to the given list of pages. + for (iPage=aCleanedList.begin(); + iPage!=aCleanedList.end(); + ++iPage) + { + AssignMasterPageToPage ( + pMasterPageInDocument, + sBaseLayoutName, + *iPage); + } + + if( pUndoMgr ) + pUndoMgr->LeaveListAction(); + } + while (false); +} + + + + +SdPage* DocumentHelper::AddMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + sal_uInt16 nInsertionIndex) +{ + SdPage* pClonedMasterPage = NULL; + + if (pMasterPage!=NULL) + { + // Duplicate the master page. + pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone()); + + // Copy the precious flag. + pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious()); + + // Copy the necessary styles. + SdDrawDocument* pSourceDocument + = static_cast<SdDrawDocument*>(pMasterPage->GetModel()); + if (pSourceDocument != NULL) + { + ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage); + + // Now that the styles are available we can insert the cloned + // master page. + rTargetDocument.InsertMasterPage (pClonedMasterPage, nInsertionIndex); + + // Adapt the size of the new master page to that of the pages in + // the document. + Size aNewSize (rTargetDocument.GetSdPage(0, pMasterPage->GetPageKind())->GetSize()); + Rectangle aBorders ( + pClonedMasterPage->GetLftBorder(), + pClonedMasterPage->GetUppBorder(), + pClonedMasterPage->GetRgtBorder(), + pClonedMasterPage->GetLwrBorder()); + pClonedMasterPage->ScaleObjects(aNewSize, aBorders, sal_True); + pClonedMasterPage->SetSize(aNewSize); + pClonedMasterPage->CreateTitleAndLayout(sal_True); + } + } + + return pClonedMasterPage; +} + + + + +/** In here we have to handle three cases: + 1. pPage is a normal slide. We can use SetMasterPage to assign the + master pages to it. + 2. pPage is a master page that is used by at least one slide. We can + assign the master page to these slides. + 3. pPage is a master page that is currently not used by any slide. + We can delete that page and add copies of the given master pages + instead. + + For points 2 and 3 where one master page A is assigned to another B we have + to keep in mind that the master page that page A has already been + inserted into the target document. +*/ +void DocumentHelper::AssignMasterPageToPage ( + SdPage* pMasterPage, + const String& rsBaseLayoutName, + SdPage* pPage) +{ + // Leave early when the parameters are invalid. + if (pPage == NULL || pMasterPage == NULL) + return; + SdDrawDocument* pDocument = dynamic_cast<SdDrawDocument*>(pPage->GetModel()); + if (pDocument == NULL) + return; + + if ( ! pPage->IsMasterPage()) + { + // 1. Remove the background object (so that that, if it exists, does + // not override the new master page) and assign the master page to + // the regular slide. + pDocument->GetDocSh()->GetUndoManager()->AddUndoAction( + new SdBackgroundObjUndoAction( + *pDocument, *pPage, pPage->getSdrPageProperties().GetItemSet()), + sal_True); + pPage->getSdrPageProperties().PutItem(XFillStyleItem(XFILL_NONE)); + + pDocument->SetMasterPage ( + (pPage->GetPageNum()-1)/2, + rsBaseLayoutName, + pDocument, + sal_False, + sal_False); + } + else + { + // Find first slide that uses the master page. + SdPage* pSlide = NULL; + sal_uInt16 nPageCount = pDocument->GetSdPageCount(PK_STANDARD); + for (sal_uInt16 nPage=0; nPage<nPageCount&&pSlide==NULL; nPage++) + { + SdrPage* pCandidate = pDocument->GetSdPage(nPage,PK_STANDARD); + if (pCandidate != NULL + && pCandidate->TRG_HasMasterPage() + && &(pCandidate->TRG_GetMasterPage()) == pPage) + { + pSlide = static_cast<SdPage*>(pCandidate); + } + } + + if (pSlide != NULL) + { + // 2. Assign the given master pages to the first slide that was + // found above that uses the master page. + pDocument->SetMasterPage ( + (pSlide->GetPageNum()-1)/2, + rsBaseLayoutName, + pDocument, + sal_False, + sal_False); + } + else + { + // 3. Replace the master page A by a copy of the given master + // page B. + pDocument->RemoveUnnecessaryMasterPages ( + pPage, sal_False); + } + } +} + + + + +SdPage* DocumentHelper::ProvideMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList) +{ + // Make sure that both the master page and its notes master exist + // in the source document. If one is missing then return without + // making any changes. + if (pMasterPage == NULL) + { + // The caller should make sure that the master page is valid. + OSL_ASSERT(pMasterPage != NULL); + return NULL; + } + SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>(pMasterPage->GetModel()); + if (pSourceDocument == NULL) + return NULL; + SdPage* pNotesMasterPage = static_cast<SdPage*>( + pSourceDocument->GetMasterPage(pMasterPage->GetPageNum()+1)); + if (pNotesMasterPage == NULL) + { + // The model is not in a valid state. Maybe a new master page + // is being (not finished yet) created? Return without making + // any changes. + return NULL; + } + + SdPage* pMasterPageInDocument = NULL; + // Search for a master page with the same name as the given one in + // the target document. + const XubString sMasterPageLayoutName (pMasterPage->GetLayoutName()); + for (sal_uInt16 nIndex=0,nCount=rTargetDocument.GetMasterPageCount(); nIndex<nCount; ++nIndex) + { + SdPage* pCandidate = static_cast<SdPage*>(rTargetDocument.GetMasterPage(nIndex)); + if (pCandidate!=NULL + && sMasterPageLayoutName==pCandidate->GetLayoutName()) + { + // The requested master page does already exist in the + // target document, return it. + return pCandidate; + } + } + + // The given master page does not already belong to the target + // document so we have to create copies and insert them into the + // targer document. + + // Determine the position where the new master pages are inserted. + // By default they are inserted at the end. When we assign to a + // master page then insert after the last of the (selected) pages. + sal_uInt16 nInsertionIndex = rTargetDocument.GetMasterPageCount(); + if (rpPageList->front()->IsMasterPage()) + { + nInsertionIndex = rpPageList->back()->GetPageNum(); + } + + // Clone the master page. + if (pMasterPage->GetModel() != &rTargetDocument) + { + pMasterPageInDocument = AddMasterPage (rTargetDocument, pMasterPage, nInsertionIndex); + if( rTargetDocument.IsUndoEnabled() ) + rTargetDocument.AddUndo( + rTargetDocument.GetSdrUndoFactory().CreateUndoNewPage(*pMasterPageInDocument)); + } + else + pMasterPageInDocument = pMasterPage; + + // Clone the notes master. + if (pNotesMasterPage->GetModel() != &rTargetDocument) + { + SdPage* pClonedNotesMasterPage + = AddMasterPage (rTargetDocument, pNotesMasterPage, nInsertionIndex+1); + if( rTargetDocument.IsUndoEnabled() ) + rTargetDocument.AddUndo( + rTargetDocument.GetSdrUndoFactory().CreateUndoNewPage(*pClonedNotesMasterPage)); + } + + return pMasterPageInDocument; +} + + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/DocumentHelper.hxx b/sd/source/ui/sidebar/DocumentHelper.hxx new file mode 100644 index 000000000000..a5f7d8b35950 --- /dev/null +++ b/sd/source/ui/sidebar/DocumentHelper.hxx @@ -0,0 +1,110 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_DCUMENT_HELPER_HXX +#define SD_SIDEBAR_PANELS_DCUMENT_HELPER_HXX + +#include <tools/solar.h> +#include <boost/shared_ptr.hpp> +#include <vector> + +class SdDrawDocument; +class SdPage; +class String; + +namespace sd { namespace sidebar { + +/** A collection of methods supporting the handling of master pages. +*/ +class DocumentHelper +{ +public: + /** Return a copy of the given master page in the given document. + */ + static SdPage* CopyMasterPageToLocalDocument ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage); + + /** Return and, when not yet present, create a slide that uses the given + masster page. + */ + static SdPage* GetSlideForMasterPage (SdPage* pMasterPage); + + /** Copy the styles used by the given page from the source document to + the target document. + */ + static void ProvideStyles ( + SdDrawDocument& rSourceDocument, + SdDrawDocument& rTargetDocument, + SdPage* pPage); + + /** Assign the given master page to the list of pages. + @param rTargetDocument + The document that is the owner of the pages in rPageList. + @param pMasterPage + This master page will usually be a member of the list of all + available master pages as provided by the MasterPageContainer. + @param rPageList + The pages to which to assign the master page. These pages may + be slides or master pages themselves. + */ + static void AssignMasterPageToPageList ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rPageList); + +private: + static SdPage* AddMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage); + static SdPage* AddMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + sal_uInt16 nInsertionIndex); + static SdPage* ProvideMasterPage ( + SdDrawDocument& rTargetDocument, + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList); + + /** Assign the given master page to the given page. + @param pMasterPage + In contrast to AssignMasterPageToPageList() this page is assumed + to be in the target document, i.e. the same document that pPage + is in. The caller will usually call AddMasterPage() to create a + clone of a master page in a another document to create it. + @param rsBaseLayoutName + The layout name of the given master page. It is given so that + it has not to be created on every call. It could be generated + from the given master page, though. + @param pPage + The page to which to assign the master page. It can be a slide + or a master page itself. + */ + static void AssignMasterPageToPage ( + SdPage* pMasterPage, + const String& rsBaseLayoutName, + SdPage* pPage); +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/IDisposable.hxx b/sd/source/ui/sidebar/IDisposable.hxx new file mode 100644 index 000000000000..f7cb3448626e --- /dev/null +++ b/sd/source/ui/sidebar/IDisposable.hxx @@ -0,0 +1,44 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + + +#ifndef SD_SIDEBAR_DISPOSABLE_INTERFACE_HXX +#define SD_SIDEBAR_DISPOSABLE_INTERFACE_HXX + +#include <tools/gen.hxx> +#include <sal/types.h> + +class Window; + +namespace sd { namespace sidebar { + + +class IDisposable +{ +public: + virtual void Dispose (void) = 0; +}; + + +} } // end of namespace ::sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/ISidebarReceiver.hxx b/sd/source/ui/sidebar/ISidebarReceiver.hxx new file mode 100644 index 000000000000..1755ad681aa7 --- /dev/null +++ b/sd/source/ui/sidebar/ISidebarReceiver.hxx @@ -0,0 +1,40 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_RECEIVER_INTERFACE_HXX +#define SD_SIDEBAR_RECEIVER_INTERFACE_HXX + +#include <com/sun/star/ui/XSidebar.hpp> + +namespace sd { namespace sidebar { + + +class ISidebarReceiver +{ +public: + virtual void SetSidebar (const ::com::sun::star::uno::Reference< + ::com::sun::star::ui::XSidebar>& rxSidebar) = 0; +}; + + +} } // end of namespace ::sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/LayoutMenu.cxx b/sd/source/ui/sidebar/LayoutMenu.cxx new file mode 100644 index 000000000000..e775f426121f --- /dev/null +++ b/sd/source/ui/sidebar/LayoutMenu.cxx @@ -0,0 +1,984 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "LayoutMenu.hxx" + +#include "SidebarShellManager.hxx" +#include "app.hrc" +#include "drawdoc.hxx" +#include "framework/FrameworkHelper.hxx" +#include "glob.hrc" +#include "glob.hxx" +#include "helpids.h" +#include "pres.hxx" +#include "res_bmp.hrc" +#include "sdpage.hxx" +#include "sdresid.hxx" +#include "strings.hrc" +#include "tools/SlotStateListener.hxx" +#include "DrawController.hxx" +#include "DrawDocShell.hxx" +#include "DrawViewShell.hxx" +#include "EventMultiplexer.hxx" +#include "SlideSorterViewShell.hxx" +#include "ViewShellBase.hxx" +#include <sfx2/sidebar/Theme.hxx> + +#include <comphelper/processfactory.hxx> +#include <sfx2/app.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/objface.hxx> +#include <sfx2/request.hxx> +#include <sfx2/viewfrm.hxx> +#include <svl/languageoptions.hxx> +#include <vcl/image.hxx> +#include <vcl/floatwin.hxx> + +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/drawing/framework/XControllerManager.hpp> +#include <com/sun/star/drawing/framework/XView.hpp> +#include <com/sun/star/drawing/framework/ResourceId.hpp> + +#include <vector> +#include <memory> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::drawing::framework; +using namespace ::sd::slidesorter; +using ::sd::framework::FrameworkHelper; + +namespace sd { namespace sidebar { + + + +struct snewfoil_value_info +{ + sal_uInt16 mnBmpResId; + sal_uInt16 mnHCBmpResId; + sal_uInt16 mnStrResId; + WritingMode meWritingMode; + AutoLayout maAutoLayout; +}; + +static snewfoil_value_info notes[] = +{ + {BMP_FOILN_01, BMP_FOILN_01_H, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB, + AUTOLAYOUT_NOTES}, + {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}, +}; + +static snewfoil_value_info handout[] = +{ + {BMP_FOILH_01, BMP_FOILH_01_H, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT1}, + {BMP_FOILH_02, BMP_FOILH_02_H, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT2}, + {BMP_FOILH_03, BMP_FOILH_03_H, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT3}, + {BMP_FOILH_04, BMP_FOILH_04_H, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT4}, + {BMP_FOILH_06, BMP_FOILH_06_H, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT6}, + {BMP_FOILH_09, BMP_FOILH_09_H, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB, + AUTOLAYOUT_HANDOUT9}, + {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}, +}; + +static snewfoil_value_info standard[] = +{ + {BMP_LAYOUT_EMPTY, BMP_LAYOUT_EMPTY_H, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB, AUTOLAYOUT_NONE}, + {BMP_LAYOUT_HEAD03, BMP_LAYOUT_HEAD03_H, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB, AUTOLAYOUT_TITLE}, + {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AUTOLAYOUT_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_ENUM}, + {BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AUTOLAYOUT_2CONTENT, WritingMode_LR_TB, AUTOLAYOUT_2TEXT}, + {BMP_LAYOUT_HEAD01, BMP_LAYOUT_HEAD01_H, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB, AUTOLAYOUT_ONLY_TITLE}, + {BMP_LAYOUT_TEXTONLY, BMP_LAYOUT_TEXTONLY_H, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB, AUTOLAYOUT_ONLY_TEXT}, + {BMP_LAYOUT_HEAD03B, BMP_LAYOUT_HEAD03B_H, STR_AUTOLAYOUT_2CONTENT_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_2OBJTEXT}, + {BMP_LAYOUT_HEAD03C, BMP_LAYOUT_HEAD03C_H, STR_AUTOLAYOUT_CONTENT_2CONTENT, WritingMode_LR_TB, AUTOLAYOUT_TEXT2OBJ}, + {BMP_LAYOUT_HEAD03A, BMP_LAYOUT_HEAD03A_H, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT}, + {BMP_LAYOUT_HEAD02B, BMP_LAYOUT_HEAD02B_H, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT}, + {BMP_LAYOUT_HEAD04, BMP_LAYOUT_HEAD04_H, STR_AUTOLAYOUT_4CONTENT, WritingMode_LR_TB, AUTOLAYOUT_4OBJ}, + {BMP_LAYOUT_HEAD06, BMP_LAYOUT_HEAD06_H, STR_AUTOLAYOUT_6CONTENT, WritingMode_LR_TB, AUTOLAYOUT_6CLIPART}, + + // vertical + {BMP_LAYOUT_VERTICAL02, BMP_LAYOUT_VERTICAL02_H, STR_AL_VERT_TITLE_TEXT_CHART, WritingMode_TB_RL,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART}, + {BMP_LAYOUT_VERTICAL01, BMP_LAYOUT_VERTICAL01_H, STR_AL_VERT_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE}, + {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE}, + {BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AL_TITLE_VERT_OUTLINE_CLIPART, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART}, + {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE} +}; + + + + +LayoutMenu::LayoutMenu ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) + : ValueSet (pParent), + DragSourceHelper(this), + DropTargetHelper(this), + mrBase(rViewShellBase), + mbUseOwnScrollBar(false), + mnPreferredColumnCount(3), + mxListener(NULL), + mbSelectionUpdatePending(true), + mbIsMainViewChangePending(false), + mxSidebar(rxSidebar), + mbIsDisposed(false) +{ + implConstruct( *mrBase.GetDocument()->GetDocSh() ); + OSL_TRACE("created LayoutMenu at %x", this); + + SetStyle(GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_TABSTOP); + + SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground)); + SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground)); + +#ifdef DEBUG + SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:LayoutMenu"))); +#endif +} + + + + +void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell ) +{ + OSL_ENSURE( mrBase.GetDocument()->GetDocSh() == &rDocumentShell, + "LayoutMenu::implConstruct: hmm?" ); + // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ... + + SetStyle ( + ( GetStyle() & ~(WB_ITEMBORDER) ) + | WB_TABSTOP + | WB_MENUSTYLEVALUESET + | WB_NO_DIRECTSELECT + ); + if (mbUseOwnScrollBar) + SetStyle (GetStyle() | WB_VSCROLL); + SetExtraSpacing(2); + SetSelectHdl (LINK(this, LayoutMenu, ClickHandler)); + InvalidateContent(); + + Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener)); + mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink, + ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE + | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION + | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED + | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED + | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED + | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL + | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER); + + Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS); + SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE)); + + Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler)); + mxListener = new ::sd::tools::SlotStateListener( + aStateChangeLink, + Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY), + ::rtl::OUString::createFromAscii(".uno:VerticalTextState")); + + SetSizePixel(GetParent()->GetSizePixel()); + Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler)); + GetParent()->AddEventListener(aWindowEventHandlerLink); +} + + + + +LayoutMenu::~LayoutMenu (void) +{ + OSL_TRACE("destroying LayoutMenu at %x", this); + Dispose(); +} + + + + +void LayoutMenu::Dispose (void) +{ + if (mbIsDisposed) + return; + + OSL_TRACE("disposing LayoutMenu at %x", this); + + mbIsDisposed = true; + + Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY); + if (xComponent.is()) + xComponent->dispose(); + + Clear(); + Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener)); + mrBase.GetEventMultiplexer()->RemoveEventListener (aLink); + + Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler)); + GetParent()->RemoveEventListener(aWindowEventHandlerLink); +} + + + + +AutoLayout LayoutMenu::GetSelectedAutoLayout (void) +{ + AutoLayout aResult = AUTOLAYOUT_NONE; + + if ( ! IsNoSelection() && GetSelectItemId()!=0) + { + AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId())); + if (pLayout != NULL) + aResult = *pLayout; + } + + return aResult; +} + + + + +/** The preferred size depends on the preferred number of columns, the + number of items, and the size of the items. +*/ +Size LayoutMenu::GetPreferredSize (void) +{ + Size aItemSize = CalcItemSizePixel (Size()); + Size aPreferredWindowSize = CalcWindowSizePixel ( + aItemSize, + (sal_uInt16)mnPreferredColumnCount, + (sal_uInt16)CalculateRowCount (aItemSize,mnPreferredColumnCount)); + return aPreferredWindowSize; +} + + + + +sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight) +{ + sal_Int32 nPreferredWidth = 100; + if (GetItemCount() > 0) + { + Image aImage = GetItemImage(GetItemId(0)); + Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel()); + if (nHeight>0 && aItemSize.Height()>0) + { + int nRowCount = nHeight / aItemSize.Height(); + if (nRowCount <= 0) + nRowCount = 1; + int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount; + nPreferredWidth = nColumnCount * aItemSize.Width(); + } + } + + return nPreferredWidth; +} + + + + +ui::LayoutSize LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth) +{ + sal_Int32 nPreferredHeight = 200; + if ( ! mbUseOwnScrollBar && GetItemCount()>0) + { + Image aImage = GetItemImage(GetItemId(0)); + Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel()); + if (nWidth>0 && aItemSize.Width()>0) + { + aItemSize.Width() += 8; + aItemSize.Height() += 8; + int nColumnCount = nWidth / aItemSize.Width(); + if (nColumnCount <= 0) + nColumnCount = 1; + else if (nColumnCount > 4) + nColumnCount = 4; + int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount; + nPreferredHeight = nRowCount * aItemSize.Height(); + } + } + return ui::LayoutSize(nPreferredHeight,nPreferredHeight,nPreferredHeight); +} + + + + +sal_Int32 LayoutMenu::GetMinimumWidth (void) +{ + sal_Int32 nMinimumWidth = 0; + if (GetItemCount()>0) + { + Image aImage = GetItemImage(GetItemId(0)); + Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel()); + nMinimumWidth = aItemSize.Width(); + } + return nMinimumWidth; +} + + + + +void LayoutMenu::UpdateEnabledState (const MasterMode eMode) +{ + bool bIsEnabled (false); + + ::boost::shared_ptr<ViewShell> pMainViewShell (mrBase.GetMainViewShell()); + if (pMainViewShell) + { + switch (pMainViewShell->GetShellType()) + { + case ViewShell::ST_NONE: + case ViewShell::ST_OUTLINE: + case ViewShell::ST_PRESENTATION: + case ViewShell::ST_SIDEBAR: + // The complete task pane is disabled for these values or + // not even visible. Disabling the LayoutMenu would be + // logical but unnecessary. The main disadvantage is that + // after re-enabling it (typically) another panel is + // expanded. + bIsEnabled = true; + break; + + case ViewShell::ST_DRAW: + case ViewShell::ST_IMPRESS: + { + switch (eMode) + { + case MM_UNKNOWN: + { + ::boost::shared_ptr<DrawViewShell> pDrawViewShell ( + ::boost::dynamic_pointer_cast<DrawViewShell>(pMainViewShell)); + if (pDrawViewShell) + bIsEnabled = pDrawViewShell->GetEditMode() != EM_MASTERPAGE; + break; + } + case MM_NORMAL: + bIsEnabled = true; + break; + + case MM_MASTER: + bIsEnabled = false; + break; + } + break; + } + + case ViewShell::ST_HANDOUT: + case ViewShell::ST_NOTES: + case ViewShell::ST_SLIDE_SORTER: + default: + bIsEnabled = true; + break; + } + } +} + + + + +void LayoutMenu::Paint (const Rectangle& rRect) +{ + if (mbSelectionUpdatePending) + { + mbSelectionUpdatePending = false; + UpdateSelection(); + } + ValueSet::Paint (rRect); +} + + + + +void LayoutMenu::Resize (void) +{ + Size aWindowSize = GetOutputSizePixel(); + if (IsVisible() && aWindowSize.Width() > 0) + { + // Calculate the number of rows and columns. + if (GetItemCount() > 0) + { + Image aImage = GetItemImage(GetItemId(0)); + Size aItemSize = CalcItemSizePixel ( + aImage.GetSizePixel()); + aItemSize.Width() += 8; + aItemSize.Height() += 8; + int nColumnCount = aWindowSize.Width() / aItemSize.Width(); + if (nColumnCount < 1) + nColumnCount = 1; + else if (nColumnCount > 4) + nColumnCount = 4; + + int nRowCount = CalculateRowCount (aItemSize, nColumnCount); + + SetColCount ((sal_uInt16)nColumnCount); + SetLineCount ((sal_uInt16)nRowCount); + } + } + + ValueSet::Resize (); +} + + + + +void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent) +{ + // As a preparation for the context menu the item under the mouse is + // selected. + if (rEvent.IsRight()) + { + ReleaseMouse(); + sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel()); + if (nIndex > 0) + SelectItem(nIndex); + } + + ValueSet::MouseButtonDown (rEvent); +} + + + + +void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout) +{ + ViewShell* pViewShell = mrBase.GetMainViewShell().get(); + if (pViewShell == NULL) + return; + + SfxViewFrame* pViewFrame = mrBase.GetViewFrame(); + if (pViewFrame == NULL) + return; + + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + if (pDispatcher == NULL) + return; + + // Call SID_INSERTPAGE with the right arguments. This is because + // the popup menu can not call this slot with arguments directly. + SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout)); + if (aRequest.GetArgs() != NULL) + { + pDispatcher->Execute( + SID_INSERTPAGE, + SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, + *aRequest.GetArgs()); + } + UpdateSelection(); +} + + + + +void LayoutMenu::InvalidateContent (void) +{ + // Throw away the current set and fill the menu anew according to the + // current settings (this includes the support for vertical writing.) + Fill(); + + if (mxSidebar.is()) + mxSidebar->requestLayout(); +} + + + + +int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount) +{ + int nRowCount = 0; + + if (GetItemCount() > 0 && nColumnCount > 0) + { + nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount; + // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height(); + if (nRowCount < 1) + nRowCount = 1; + } + + return nRowCount; +} + + + + +IMPL_LINK(LayoutMenu, ClickHandler, ValueSet*, EMPTYARG) +{ + AssignLayoutToSelectedSlides (GetSelectedAutoLayout()); + return 0; +} + + + + +/** The specified layout is assigned to the current page of the view shell + in the center pane. +*/ +void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout) +{ + using namespace ::sd::slidesorter; + using namespace ::sd::slidesorter::controller; + + do + { + // The view shell in the center pane has to be present. + ViewShell* pMainViewShell = mrBase.GetMainViewShell().get(); + if (pMainViewShell == NULL) + break; + + // Determine if the current view is in an invalid master page mode. + // The handout view is always in master page mode and therefore not + // invalid. + bool bMasterPageMode (false); + switch (pMainViewShell->GetShellType()) + { + case ViewShell::ST_NOTES: + case ViewShell::ST_IMPRESS: + { + DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell); + if (pDrawViewShell != NULL) + if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE) + bMasterPageMode = true; + } + default: + break; + } + if (bMasterPageMode) + break; + + // Get a list of all selected slides and call the SID_MODIFYPAGE + // slot for all of them. + ::sd::slidesorter::SharedPageSelection pPageSelection; + + // Get a list of selected pages. + // First we try to obtain this list from a slide sorter. This is + // possible only some of the view shells in the center pane. When + // no valid slide sorter is available then ask the main view shell + // for its current page. + SlideSorterViewShell* pSlideSorter = NULL; + switch (pMainViewShell->GetShellType()) + { + case ViewShell::ST_IMPRESS: + case ViewShell::ST_NOTES: + case ViewShell::ST_SLIDE_SORTER: + pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase); + break; + default: + break; + } + if (pSlideSorter != NULL) + { + // There is a slide sorter visible so get the list of selected pages from it. + pPageSelection = pSlideSorter->GetPageSelection(); + } + + if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() ) + { + // No valid slide sorter available. Ask the main view shell for + // its current page. + pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection()); + pPageSelection->push_back(pMainViewShell->GetActualPage()); + } + + + if (pPageSelection->empty()) + break; + + ::std::vector<SdPage*>::iterator iPage; + for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage) + { + if ((*iPage) == NULL) + continue; + + // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters. + SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT); + aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2)); + aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout)); + pMainViewShell->ExecuteSlot (aRequest, sal_Bool(sal_False)); + } + } + while(false); +} + + + + +SfxRequest LayoutMenu::CreateRequest ( + sal_uInt16 nSlotId, + AutoLayout aLayout) +{ + SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId); + + do + { + SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin()); + sal_uInt8 aBackground (rLayerAdmin.GetLayerID( + String(SdResId(STR_LAYER_BCKGRND)), sal_False)); + sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID( + String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False)); + ViewShell* pViewShell = mrBase.GetMainViewShell().get(); + if (pViewShell == NULL) + break; + SdPage* pPage = pViewShell->GetActualPage(); + if (pPage == NULL) + break; + + SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers()); + + aRequest.AppendItem( + SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName())); + aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout)); + aRequest.AppendItem( + SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground))); + aRequest.AppendItem( + SfxBoolItem( + ID_VAL_ISPAGEOBJ, + aVisibleLayers.IsSet(aBackgroundObject))); + } + while (false); + + return aRequest; +} + + + + +void LayoutMenu::Fill (void) +{ + const bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); + SvtLanguageOptions aLanguageOptions; + sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled(); + SdDrawDocument* pDocument = mrBase.GetDocument(); + sal_Bool bRightToLeft = (pDocument!=NULL + && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB); + + // Get URL of the view in the center pane. + ::rtl::OUString sCenterPaneViewName; + try + { + Reference<XControllerManager> xControllerManager ( + Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW); + Reference<XResourceId> xPaneId (ResourceId::create( + ::comphelper::getProcessComponentContext(), + FrameworkHelper::msCenterPaneURL)); + Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId)); + if (xView.is()) + sCenterPaneViewName = xView->getResourceId()->getResourceURL(); + } + catch (RuntimeException&) + {} + + snewfoil_value_info* pInfo = NULL; + if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL)) + { + pInfo = notes; + } + else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL)) + { + pInfo = handout; + } + else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL) + || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL)) + { + pInfo = standard; + } + else + { + pInfo = NULL; + } + + Clear(); + int n = 0; + for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++) + { + if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical) + { + BitmapEx aBmp (SdResId (bHighContrast + ? pInfo->mnHCBmpResId + : pInfo->mnBmpResId)); + + if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode)) + aBmp.Mirror (BMP_MIRROR_HORZ); + + InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId))); + SetItemData (i, new AutoLayout(pInfo->maAutoLayout)); + n++; + } + } + + mbSelectionUpdatePending = true; +} + + + + +void LayoutMenu::Clear (void) +{ + for (sal_uInt16 nId=1; nId<=GetItemCount(); nId++) + delete static_cast<AutoLayout*>(GetItemData(nId)); + ValueSet::Clear(); +} + + + +void LayoutMenu::StartDrag (sal_Int8 , const Point& ) +{ +} + + + + +sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& ) +{ + return 0; +} + + + + +sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& ) +{ + return 0; +} + + + + +void LayoutMenu::Command (const CommandEvent& rEvent) +{ + switch (rEvent.GetCommand()) + { + case COMMAND_CONTEXTMENU: + if ( ! SD_MOD()->GetWaterCan()) + { + // Determine the position where to show the menu. + Point aMenuPosition; + if (rEvent.IsMouseEvent()) + { + if (GetItemId(rEvent.GetMousePosPixel()) <= 0) + return; + aMenuPosition = rEvent.GetMousePosPixel(); + } + else + { + if (GetSelectItemId() == (sal_uInt16)-1) + return; + Rectangle aBBox (GetItemRect(GetSelectItemId())); + aMenuPosition = aBBox.Center(); + } + + // Setup the menu. + ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP))); + FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); + if (pMenuWindow != NULL) + pMenuWindow->SetPopupModeFlags( + pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); + pMenu->SetSelectHdl(LINK(this, LayoutMenu, OnMenuItemSelected)); + + // Disable the SID_INSERTPAGE_LAYOUT_MENU item when + // the document is read-only. + const SfxPoolItem* pItem = NULL; + const SfxItemState aState ( + mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem)); + if (aState == SFX_ITEM_DISABLED) + pMenu->EnableItem(SID_INSERTPAGE_LAYOUT_MENU, sal_False); + + // Show the menu. + pMenu->Execute(this, Rectangle(aMenuPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN); + } + break; + + default: + ValueSet::Command(rEvent); + break; + } +} + + + + +IMPL_LINK(LayoutMenu, StateChangeHandler, ::rtl::OUString*, EMPTYARG) +{ + InvalidateContent(); + return 0; +} + + + + +IMPL_LINK(LayoutMenu, OnMenuItemSelected, Menu*, pMenu) +{ + if (pMenu == NULL) + { + OSL_ENSURE(pMenu!=NULL, "LayoutMenu::OnMenuItemSelected: illegal menu!"); + return 0; + } + + pMenu->Deactivate(); + const sal_Int32 nIndex (pMenu->GetCurItemId()); + + if (nIndex == SID_TP_APPLY_TO_SELECTED_SLIDES) + { + AssignLayoutToSelectedSlides(GetSelectedAutoLayout()); + } + else if (nIndex == SID_INSERTPAGE_LAYOUT_MENU) + { + // Add arguments to this slot and forward it to the main view + // shell. + InsertPageWithLayout(GetSelectedAutoLayout()); + } + + return 0; +} + + + + +void LayoutMenu::UpdateSelection (void) +{ + bool bItemSelected = false; + + do + { + // Get current page of main view. + ViewShell* pViewShell = mrBase.GetMainViewShell().get(); + if (pViewShell == NULL) + break; + + SdPage* pCurrentPage = pViewShell->getCurrentPage(); + if (pCurrentPage == NULL) + break; + + // Get layout of current page. + AutoLayout aLayout (pCurrentPage->GetAutoLayout()); + if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END) + break; + + // Find the entry of the menu for to the layout. + sal_uInt16 nItemCount (GetItemCount()); + for (sal_uInt16 nId=1; nId<=nItemCount; nId++) + { + if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout) + { + SelectItem(nId); + bItemSelected = true; + break; + } + } + } + while (false); + + if ( ! bItemSelected) + SetNoSelection(); +} + + + + +IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent) +{ + switch (pEvent->meEventId) + { + case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE: + case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION: + if ( ! mbSelectionUpdatePending) + UpdateSelection(); + break; + + case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED: + mbIsMainViewChangePending = true; + UpdateEnabledState(MM_UNKNOWN); + break; + + case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED: + HideFocus(); + break; + + case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED: + if (mbIsMainViewChangePending) + { + mbIsMainViewChangePending = false; + InvalidateContent(); + } + break; + + case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL: + UpdateEnabledState(MM_NORMAL); + break; + + case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER: + UpdateEnabledState(MM_MASTER); + break; + + default: + /* Ignored */ + break; + } + + return 0; +} + + + + +IMPL_LINK(LayoutMenu, WindowEventHandler, VclWindowEvent*, pEvent) +{ + if (pEvent != NULL) + { + switch (pEvent->GetId()) + { + case VCLEVENT_WINDOW_SHOW: + case VCLEVENT_WINDOW_RESIZE: + SetSizePixel(GetParent()->GetSizePixel()); + return sal_True; + + default: + return sal_False; + } + + const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, pEvent); + if (pSimpleHint != NULL + && pSimpleHint->GetId() == SFX_HINT_DYING) + { + return sal_True; + } + } + + return sal_False; +} + + + + +void LayoutMenu::DataChanged (const DataChangedEvent& rEvent) +{ + Fill(); + ValueSet::DataChanged(rEvent); + SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground)); + SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground)); +} + + + + + +} } // end of namespace ::sd::sidebar diff --git a/sd/source/ui/sidebar/LayoutMenu.hxx b/sd/source/ui/sidebar/LayoutMenu.hxx new file mode 100644 index 000000000000..f8deb8fc312f --- /dev/null +++ b/sd/source/ui/sidebar/LayoutMenu.hxx @@ -0,0 +1,225 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_LAYOUT_MENU_HXX +#define SD_SIDEBAR_LAYOUT_MENU_HXX + +#include "IDisposable.hxx" +#include "ISidebarReceiver.hxx" +#include <sfx2/sidebar/ILayoutableWindow.hxx> + +#include "glob.hxx" +#include "pres.hxx" + +#include <vcl/ctrl.hxx> +#include <svtools/valueset.hxx> +#include <svtools/transfer.hxx> +#include <sfx2/shell.hxx> + +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/ui/XSidebar.hpp> + + +class SfxModule; + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + +namespace sd { +class DrawDocShell; +class PaneManagerEvent; +class ViewShellBase; +} + + +namespace sd { namespace tools { +class EventMultiplexerEvent; +} } + + +namespace sd { namespace sidebar { + +class ControlFactory; +class SidebarViewShell; +class SidebarShellManager; + + +class LayoutMenu + : public ValueSet, + public DragSourceHelper, + public DropTargetHelper, + public sfx2::sidebar::ILayoutableWindow +{ +public: + /** Create a new layout menu. Depending on the given flag it + displays its own scroll bar or lets a surrounding window + handle that. + @param i_pParent + the parent node in the control tree + @param i_rPanelViewShell + the view shell of the task pane. + */ + LayoutMenu ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + virtual ~LayoutMenu (void); + + virtual void Dispose (void); + + /** Return a numerical value representing the currently selected + layout. + */ + AutoLayout GetSelectedAutoLayout (void); + + Size GetPreferredSize (void); + sal_Int32 GetPreferredWidth (sal_Int32 nHeight); + sal_Int32 GetMinimumWidth (void); + + // From ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + + // From ::Window + virtual void Paint (const Rectangle& rRect); + virtual void Resize (void); + + /** Show a context menu when the right mouse button is pressed. + */ + virtual void MouseButtonDown (const MouseEvent& rEvent); + + /** The LayoutMenu does not support some main views. In this case the + LayoutMenu is disabled. This state is updated in this method. + @param eMode + On some occasions the edit mode is being switched when this + method is called can not (yet) be reliably detected. Luckily, + in these cases the new value is provided by some broadcaster. + On other occasions the edit mode is not modified and is also not + provided. Therefore the Unknown value. + */ + enum MasterMode { MM_NORMAL, MM_MASTER, MM_UNKNOWN }; + void UpdateEnabledState (const MasterMode eMode); + + /** Call this method when the set of displayed layouts is not up-to-date + anymore. It will re-assemple this set according to the current + settings. + */ + void InvalidateContent (void); + + // DragSourceHelper + virtual void StartDrag (sal_Int8 nAction, const Point& rPosPixel); + + // DropTargetHelper + virtual sal_Int8 AcceptDrop (const AcceptDropEvent& rEvent); + virtual sal_Int8 ExecuteDrop (const ExecuteDropEvent& rEvent); + + /** The context menu is requested over this Command() method. + */ + virtual void Command (const CommandEvent& rEvent); + + /** Call Fill() when switching to or from high contrast mode so that the + correct set of icons is displayed. + */ + virtual void DataChanged (const DataChangedEvent& rEvent); + + using Window::GetWindow; + using ValueSet::StartDrag; + +private: + ViewShellBase& mrBase; + + /** Do we use our own scroll bar or is viewport handling done by + our parent? + */ + bool mbUseOwnScrollBar; + + /** If we are asked for the preferred window size, then use this + many columns for the calculation. + */ + const int mnPreferredColumnCount; + cssu::Reference<css::frame::XStatusListener> mxListener; + bool mbSelectionUpdatePending; + bool mbIsMainViewChangePending; + cssu::Reference<css::ui::XSidebar> mxSidebar; + bool mbIsDisposed; + + /** Calculate the number of displayed rows. This depends on the given + item size, the given number of columns, and the size of the + control. Note that this is not the number of rows managed by the + valueset. This number may be larger. In that case a vertical + scroll bar is displayed. + */ + int CalculateRowCount (const Size& rItemSize, int nColumnCount); + + /** Fill the value set with the layouts that are applicable to the + current main view shell. + */ + void Fill (void); + + /** Remove all items from the value set. + */ + void Clear (void); + + /** Assign the given layout to all selected slides of a slide sorter. + If no slide sorter is active then this call is ignored. The slide + sorter in the center pane is preferred if the choice exists. + */ + void AssignLayoutToSelectedSlides (AutoLayout aLayout); + + /** Insert a new page with the given layout. The page is inserted via + the main view shell, i.e. its SID_INSERTPAGE slot is called. It it + does not support this slot then inserting a new page does not take + place. The new page is inserted after the currently active one (the + one returned by ViewShell::GetActualPage().) + */ + void InsertPageWithLayout (AutoLayout aLayout); + + /** Create a request structure that can be used with the SID_INSERTPAGE + and SID_MODIFYPAGE slots. The parameters are set so that the given + layout is assigned to the current page of the main view shell. + @param nSlotId + Supported slots are SID_INSERTPAGE and SID_MODIFYPAGE. + @param aLayout + Layout of the page to insert or to assign. + */ + SfxRequest CreateRequest ( + sal_uInt16 nSlotId, + AutoLayout aLayout); + + /** Select the layout that is used by the current page. + */ + void UpdateSelection (void); + + // internal ctor + void implConstruct( DrawDocShell& rDocumentShell ); + + /** When clicked then set the current page of the view in the center pane. + */ + DECL_LINK(ClickHandler, ValueSet*); + DECL_LINK(RightClickHandler, MouseEvent*); + DECL_LINK(StateChangeHandler, ::rtl::OUString*); + DECL_LINK(EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*); + DECL_LINK(WindowEventHandler, VclWindowEvent*); + DECL_LINK(OnMenuItemSelected, Menu*); +}; + +} } // end of namespace ::sd::toolpanel + +#endif diff --git a/sd/source/ui/sidebar/MasterPageContainer.cxx b/sd/source/ui/sidebar/MasterPageContainer.cxx new file mode 100644 index 000000000000..d32629419245 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainer.cxx @@ -0,0 +1,1212 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageContainer.hxx" + +#include "MasterPageDescriptor.hxx" +#include "MasterPageContainerFiller.hxx" +#include "MasterPageContainerQueue.hxx" +#include "TemplateScanner.hxx" +#include "tools/AsynchronousTask.hxx" +#include "strings.hrc" +#include <algorithm> +#include <list> +#include <set> + +#include "unomodel.hxx" +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/processfactory.hxx> +#include <tools/urlobj.hxx> +#include <sfx2/app.hxx> +#include <svx/svdpage.hxx> +#include "DrawDocShell.hxx" +#include "drawdoc.hxx" +#include "sdpage.hxx" +#include <svl/itemset.hxx> +#include <svl/eitem.hxx> +#include "sdresid.hxx" +#include "tools/TimerBasedTaskExecution.hxx" +#include "pres.hxx" +#include <osl/mutex.hxx> +#include <boost/weak_ptr.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace { + +typedef ::std::vector<sd::sidebar::SharedMasterPageDescriptor> MasterPageContainerType; + +} // end of anonymous namespace + + +namespace sd { namespace sidebar { + + +/** Inner implementation class of the MasterPageContainer. +*/ +class MasterPageContainer::Implementation + : public SdGlobalResource, + public MasterPageContainerFiller::ContainerAdapter, + public MasterPageContainerQueue::ContainerAdapter +{ +public: + mutable ::osl::Mutex maMutex; + + static ::boost::weak_ptr<Implementation> mpInstance; + MasterPageContainerType maContainer; + + static ::boost::shared_ptr<Implementation> Instance (void); + + void LateInit (void); + void AddChangeListener (const Link& rLink); + void RemoveChangeListener (const Link& rLink); + void UpdatePreviewSizePixel (void); + Size GetPreviewSizePixel (PreviewSize eSize) const; + + bool HasToken (Token aToken) const; + const SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken) const; + SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken); + virtual Token PutMasterPage (const SharedMasterPageDescriptor& rDescriptor); + void InvalidatePreview (Token aToken); + Image GetPreviewForToken ( + Token aToken, + PreviewSize ePreviewSize); + PreviewState GetPreviewState (Token aToken) const; + bool RequestPreview (Token aToken); + + Reference<frame::XModel> GetModel (void); + SdDrawDocument* GetDocument (void); + + void FireContainerChange ( + MasterPageContainerChangeEvent::EventType eType, + Token aToken, + bool bNotifyAsynchronously = false); + + virtual bool UpdateDescriptor ( + const SharedMasterPageDescriptor& rpDescriptor, + bool bForcePageObject, + bool bForcePreview, + bool bSendEvents); + + void ReleaseDescriptor (Token aToken); + + /** Called by the MasterPageContainerFiller to notify that all master + pages from template documents have been added. + */ + virtual void FillingDone (void); + +private: + Implementation (void); + virtual ~Implementation (void); + + class Deleter { public: + void operator() (Implementation* pObject) { delete pObject; } + }; + friend class Deleter; + + enum InitializationState { NOT_INITIALIZED, INITIALIZING, INITIALIZED } meInitializationState; + + ::boost::scoped_ptr<MasterPageContainerQueue> mpRequestQueue; + ::com::sun::star::uno::Reference<com::sun::star::frame::XModel> mxModel; + SdDrawDocument* mpDocument; + PreviewRenderer maPreviewRenderer; + /** Remember whether the first page object has already been used to + determine the correct size ratio. + */ + bool mbFirstPageObjectSeen; + + // The widths for the previews contain two pixels for the border that is + // painted arround the preview. + static const int SMALL_PREVIEW_WIDTH = 72 + 2; + static const int LARGE_PREVIEW_WIDTH = 2*72 + 2; + + /** This substition of page preview shows "Preparing preview" and is + shown as long as the actual previews are not being present. + */ + Image maLargePreviewBeingCreated; + Image maSmallPreviewBeingCreated; + + /** This substition of page preview is shown when a preview can not be + created and thus is not available. + */ + Image maLargePreviewNotAvailable; + Image maSmallPreviewNotAvailable; + + ::std::vector<Link> maChangeListeners; + + // We have to remember the tasks for initialization and filling in case + // a MasterPageContainer object is destroyed before these tasks have + // been completed. + ::boost::weak_ptr<sd::tools::TimerBasedTaskExecution> mpFillerTask; + + Size maSmallPreviewSizePixel; + Size maLargePreviewSizePixel; + bool mbPageRatioKnown; + + bool mbContainerCleaningPending; + + typedef ::std::pair<MasterPageContainerChangeEvent::EventType,Token> EventData; + DECL_LINK(AsynchronousNotifyCallback, EventData*); + ::sd::DrawDocShell* LoadDocument ( + const String& sFileName, + SfxObjectShellLock& rxDocumentShell); + + Image GetPreviewSubstitution (sal_uInt16 nId, PreviewSize ePreviewSize); + + void CleanContainer (void); +}; + + + + +//===== MasterPageContainer =================================================== + +::boost::weak_ptr<MasterPageContainer::Implementation> + MasterPageContainer::Implementation::mpInstance; +static const MasterPageContainer::Token NIL_TOKEN (-1); + + + + +::boost::shared_ptr<MasterPageContainer::Implementation> + MasterPageContainer::Implementation::Instance (void) +{ + ::boost::shared_ptr<MasterPageContainer::Implementation> pInstance; + + if (Implementation::mpInstance.expired()) + { + ::osl::GetGlobalMutex aMutexFunctor; + ::osl::MutexGuard aGuard (aMutexFunctor()); + if (Implementation::mpInstance.expired()) + { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>( + new MasterPageContainer::Implementation(), + MasterPageContainer::Implementation::Deleter()); + SdGlobalResourceContainer::Instance().AddResource(pInstance); + Implementation::mpInstance = pInstance; + } + else + pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>( + Implementation::mpInstance); + } + else + { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>( + Implementation::mpInstance); + } + + DBG_ASSERT (pInstance.get()!=NULL, + "MasterPageContainer::Implementation::Instance(): instance is NULL"); + return pInstance; +} + + + + +MasterPageContainer::MasterPageContainer (void) + : mpImpl(Implementation::Instance()), + mePreviewSize(SMALL) +{ + mpImpl->LateInit(); +} + + + + +MasterPageContainer::~MasterPageContainer (void) +{ +} + + + + +void MasterPageContainer::AddChangeListener (const Link& rLink) +{ + mpImpl->AddChangeListener(rLink); +} + + + + +void MasterPageContainer::RemoveChangeListener (const Link& rLink) +{ + mpImpl->RemoveChangeListener(rLink); +} + + + + +void MasterPageContainer::SetPreviewSize (PreviewSize eSize) +{ + mePreviewSize = eSize; + mpImpl->FireContainerChange( + MasterPageContainerChangeEvent::SIZE_CHANGED, + NIL_TOKEN); +} + + + + +MasterPageContainer::PreviewSize MasterPageContainer::GetPreviewSize (void) const +{ + return mePreviewSize; +} + + + + +Size MasterPageContainer::GetPreviewSizePixel (void) const +{ + return mpImpl->GetPreviewSizePixel(mePreviewSize); +} + + + + +MasterPageContainer::Token MasterPageContainer::PutMasterPage ( + const SharedMasterPageDescriptor& rDescriptor) +{ + return mpImpl->PutMasterPage(rDescriptor); +} + + + + +void MasterPageContainer::AcquireToken (Token aToken) +{ + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + { + ++pDescriptor->mnUseCount; + } +} + + + + +void MasterPageContainer::ReleaseToken (Token aToken) +{ + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + { + OSL_ASSERT(pDescriptor->mnUseCount>0); + --pDescriptor->mnUseCount; + if (pDescriptor->mnUseCount <= 0) + { + switch (pDescriptor->meOrigin) + { + case DEFAULT: + case TEMPLATE: + default: + break; + + case MASTERPAGE: + mpImpl->ReleaseDescriptor(aToken); + break; + } + } + } +} + + + + +int MasterPageContainer::GetTokenCount (void) const +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + return mpImpl->maContainer.size(); +} + + + + +bool MasterPageContainer::HasToken (Token aToken) const +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + return mpImpl->HasToken(aToken); +} + + + + +MasterPageContainer::Token MasterPageContainer::GetTokenForIndex (int nIndex) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + Token aResult (NIL_TOKEN); + if (HasToken(nIndex)) + aResult = mpImpl->maContainer[nIndex]->maToken; + return aResult; +} + + + + +MasterPageContainer::Token MasterPageContainer::GetTokenForURL ( + const String& sURL) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + Token aResult (NIL_TOKEN); + if (sURL.Len() > 0) + { + MasterPageContainerType::iterator iEntry ( + ::std::find_if ( + mpImpl->maContainer.begin(), + mpImpl->maContainer.end(), + MasterPageDescriptor::URLComparator(sURL))); + if (iEntry != mpImpl->maContainer.end()) + aResult = (*iEntry)->maToken; + } + return aResult; +} + + + + +MasterPageContainer::Token MasterPageContainer::GetTokenForStyleName (const String& sStyleName) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + Token aResult (NIL_TOKEN); + if (sStyleName.Len() > 0) + { + MasterPageContainerType::iterator iEntry ( + ::std::find_if ( + mpImpl->maContainer.begin(), + mpImpl->maContainer.end(), + MasterPageDescriptor::StyleNameComparator(sStyleName))); + if (iEntry != mpImpl->maContainer.end()) + aResult = (*iEntry)->maToken; + } + return aResult; +} + + + + +MasterPageContainer::Token MasterPageContainer::GetTokenForPageObject ( + const SdPage* pPage) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + Token aResult (NIL_TOKEN); + if (pPage != NULL) + { + MasterPageContainerType::iterator iEntry ( + ::std::find_if ( + mpImpl->maContainer.begin(), + mpImpl->maContainer.end(), + MasterPageDescriptor::PageObjectComparator(pPage))); + if (iEntry != mpImpl->maContainer.end()) + aResult = (*iEntry)->maToken; + } + return aResult; +} + + + + +String MasterPageContainer::GetURLForToken ( + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return pDescriptor->msURL; + else + return String(); +} + + + + +String MasterPageContainer::GetPageNameForToken ( + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return pDescriptor->msPageName; + else + return String(); +} + + + + +String MasterPageContainer::GetStyleNameForToken ( + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return pDescriptor->msStyleName; + else + return String(); +} + + + + +SdPage* MasterPageContainer::GetPageObjectForToken ( + MasterPageContainer::Token aToken, + bool bLoad) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SdPage* pPageObject = NULL; + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + { + pPageObject = pDescriptor->mpMasterPage; + if (pPageObject == NULL) + { + // The page object is not (yet) present. Call + // UpdateDescriptor() to trigger the PageObjectProvider() to + // provide it. + if (bLoad) + mpImpl->GetModel(); + if (mpImpl->UpdateDescriptor(pDescriptor,bLoad,false, true)) + pPageObject = pDescriptor->mpMasterPage; + } + } + return pPageObject; +} + + + + +MasterPageContainer::Origin MasterPageContainer::GetOriginForToken (Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return pDescriptor->meOrigin; + else + return UNKNOWN; +} + + + + +sal_Int32 MasterPageContainer::GetTemplateIndexForToken (Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return pDescriptor->mnTemplateIndex; + else + return -1; +} + + + + +SharedMasterPageDescriptor MasterPageContainer::GetDescriptorForToken ( + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (mpImpl->maMutex); + + return mpImpl->GetDescriptor(aToken); +} + + + +void MasterPageContainer::InvalidatePreview (MasterPageContainer::Token aToken) +{ + mpImpl->InvalidatePreview(aToken); +} + + + + +Image MasterPageContainer::GetPreviewForToken (MasterPageContainer::Token aToken) +{ + return mpImpl->GetPreviewForToken(aToken,mePreviewSize); +} + + + + +MasterPageContainer::PreviewState MasterPageContainer::GetPreviewState (Token aToken) +{ + return mpImpl->GetPreviewState(aToken); +} + + + + +bool MasterPageContainer::RequestPreview (Token aToken) +{ + return mpImpl->RequestPreview(aToken); +} + + + + +//==== Implementation ================================================ + +MasterPageContainer::Implementation::Implementation (void) + : maMutex(), + maContainer(), + meInitializationState(NOT_INITIALIZED), + mpRequestQueue(NULL), + mxModel(NULL), + mpDocument(NULL), + maPreviewRenderer(), + mbFirstPageObjectSeen(false), + maLargePreviewBeingCreated(), + maSmallPreviewBeingCreated(), + maLargePreviewNotAvailable(), + maSmallPreviewNotAvailable(), + maChangeListeners(), + maSmallPreviewSizePixel(), + maLargePreviewSizePixel(), + mbPageRatioKnown(false), + mbContainerCleaningPending(true) + +{ + UpdatePreviewSizePixel(); +} + + + + +MasterPageContainer::Implementation::~Implementation (void) +{ + // When the initializer or filler tasks are still running then we have + // to stop them now in order to prevent them from calling us back. + tools::TimerBasedTaskExecution::ReleaseTask(mpFillerTask); + + mpRequestQueue.reset(); + + uno::Reference<util::XCloseable> xCloseable (mxModel, uno::UNO_QUERY); + if (xCloseable.is()) + { + try + { + xCloseable->close(true); + } + catch (::com::sun::star::util::CloseVetoException aException) + { + } + } + mxModel = NULL; +} + + + + +void MasterPageContainer::Implementation::LateInit (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + if (meInitializationState == NOT_INITIALIZED) + { + meInitializationState = INITIALIZING; + + OSL_ASSERT(Instance().get()==this); + mpRequestQueue.reset(MasterPageContainerQueue::Create( + ::boost::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance()))); + + mpFillerTask = ::sd::tools::TimerBasedTaskExecution::Create( + ::boost::shared_ptr<tools::AsynchronousTask>(new MasterPageContainerFiller(*this)), + 5, + 50); + + meInitializationState = INITIALIZED; + } +} + + + + +void MasterPageContainer::Implementation::AddChangeListener (const Link& rLink) +{ + const ::osl::MutexGuard aGuard (maMutex); + + ::std::vector<Link>::iterator iListener ( + ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink)); + if (iListener == maChangeListeners.end()) + maChangeListeners.push_back(rLink); + +} + + + + +void MasterPageContainer::Implementation::RemoveChangeListener (const Link& rLink) +{ + const ::osl::MutexGuard aGuard (maMutex); + + ::std::vector<Link>::iterator iListener ( + ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink)); + if (iListener != maChangeListeners.end()) + maChangeListeners.erase(iListener); +} + + + + +void MasterPageContainer::Implementation::UpdatePreviewSizePixel (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + // The default aspect ratio is 4:3 + int nWidth (4); + int nHeight (3); + + // Search for the first entry with an existing master page. + MasterPageContainerType::const_iterator iDescriptor; + MasterPageContainerType::const_iterator iContainerEnd(maContainer.end()); + for (iDescriptor=maContainer.begin(); iDescriptor!=iContainerEnd; ++iDescriptor) + if (*iDescriptor!=NULL && (*iDescriptor)->mpMasterPage != NULL) + { + Size aPageSize ((*iDescriptor)->mpMasterPage->GetSize()); + nWidth = aPageSize.Width(); + nHeight = aPageSize.Height(); + mbFirstPageObjectSeen = true; + break; + } + + maSmallPreviewSizePixel.Width() = SMALL_PREVIEW_WIDTH; + maLargePreviewSizePixel.Width() = LARGE_PREVIEW_WIDTH; + + int nNewSmallHeight ((maSmallPreviewSizePixel.Width()-2) * nHeight / nWidth + 2); + int nNewLargeHeight ((maLargePreviewSizePixel.Width()-2) * nHeight / nWidth + 2); + + if (nNewSmallHeight!=maSmallPreviewSizePixel.Height() + || nNewLargeHeight!=maLargePreviewSizePixel.Height()) + { + maSmallPreviewSizePixel.Height() = nNewSmallHeight; + maLargePreviewSizePixel.Height() = nNewLargeHeight; + FireContainerChange( + MasterPageContainerChangeEvent::SIZE_CHANGED, + NIL_TOKEN); + } +} + + + + +Size MasterPageContainer::Implementation::GetPreviewSizePixel (PreviewSize eSize) const +{ + if (eSize == SMALL) + return maSmallPreviewSizePixel; + else + return maLargePreviewSizePixel; +} + + + + +IMPL_LINK(MasterPageContainer::Implementation,AsynchronousNotifyCallback, EventData*, pData) +{ + const ::osl::MutexGuard aGuard (maMutex); + + if (pData != NULL) + { + FireContainerChange(pData->first, pData->second, false); + delete pData; + } + + return 0; +} + + + + +MasterPageContainer::Token MasterPageContainer::Implementation::PutMasterPage ( + const SharedMasterPageDescriptor& rpDescriptor) +{ + const ::osl::MutexGuard aGuard (maMutex); + + Token aResult (NIL_TOKEN); + + // Get page object and preview when that is inexpensive. + UpdateDescriptor(rpDescriptor,false,false, false); + + // Look up the new MasterPageDescriptor and either insert it or update + // an already existing one. + MasterPageContainerType::iterator aEntry ( + ::std::find_if ( + maContainer.begin(), + maContainer.end(), + MasterPageDescriptor::AllComparator(rpDescriptor))); + if (aEntry == maContainer.end()) + { + // Insert a new MasterPageDescriptor. + bool bIgnore (rpDescriptor->mpPageObjectProvider.get()==NULL + && rpDescriptor->msURL.getLength()==0); + + if ( ! bIgnore) + { + if (mbContainerCleaningPending) + CleanContainer(); + + aResult = maContainer.size(); + rpDescriptor->SetToken(aResult); + + // Templates are precious, i.e. we lock them so that they will + // not be destroyed when (temporarily) no one references them. + // They will only be deleted when the container is destroyed. + switch (rpDescriptor->meOrigin) + { + case TEMPLATE: + case DEFAULT: + ++rpDescriptor->mnUseCount; + break; + + default: + break; + } + + maContainer.push_back(rpDescriptor); + aEntry = maContainer.end()-1; + + FireContainerChange(MasterPageContainerChangeEvent::CHILD_ADDED,aResult); + } + } + else + { + // Update an existing MasterPageDescriptor. + aResult = (*aEntry)->maToken; + ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pEventTypes( + (*aEntry)->Update(*rpDescriptor)); + if (pEventTypes.get()!=NULL && pEventTypes->size()>0) + { + // One or more aspects of the descriptor have changed. Send + // appropriate events to the listeners. + UpdateDescriptor(*aEntry,false,false, true); + + std::vector<MasterPageContainerChangeEvent::EventType>::const_iterator iEventType; + for (iEventType=pEventTypes->begin(); iEventType!=pEventTypes->end(); ++iEventType) + { + FireContainerChange( + *iEventType, + (*aEntry)->maToken, + false); + } + } + } + + return aResult; +} + + + + +bool MasterPageContainer::Implementation::HasToken (Token aToken) const +{ + return aToken>=0 + && (unsigned)aToken<maContainer.size() + && maContainer[aToken].get()!=NULL; +} + + + + +const SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor ( + Token aToken) const +{ + if (aToken>=0 && (unsigned)aToken<maContainer.size()) + return maContainer[aToken]; + else + return SharedMasterPageDescriptor(); +} + + + + +SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (Token aToken) +{ + if (aToken>=0 && (unsigned)aToken<maContainer.size()) + return maContainer[aToken]; + else + return SharedMasterPageDescriptor(); +} + + + + +void MasterPageContainer::Implementation::InvalidatePreview (Token aToken) +{ + const ::osl::MutexGuard aGuard (maMutex); + + SharedMasterPageDescriptor pDescriptor (GetDescriptor(aToken)); + if (pDescriptor.get() != NULL) + { + pDescriptor->maSmallPreview = Image(); + pDescriptor->maLargePreview = Image(); + RequestPreview(aToken); + } +} + + + + +Image MasterPageContainer::Implementation::GetPreviewForToken ( + MasterPageContainer::Token aToken, + PreviewSize ePreviewSize) +{ + const ::osl::MutexGuard aGuard (maMutex); + + Image aPreview; + PreviewState ePreviewState (GetPreviewState(aToken)); + + SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken); + + // When the preview is missing but inexpensively creatable then do that + // now. + if (pDescriptor.get()!=NULL) + { + if (ePreviewState == PS_CREATABLE) + if (UpdateDescriptor(pDescriptor, false,false, true)) + if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0) + ePreviewState = PS_AVAILABLE; + + switch (ePreviewState) + { + case PS_AVAILABLE: + aPreview = pDescriptor->GetPreview(ePreviewSize); + break; + + case PS_PREPARING: + aPreview = GetPreviewSubstitution( + STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION, + ePreviewSize); + break; + + case PS_CREATABLE: + aPreview = GetPreviewSubstitution( + STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION, + ePreviewSize); + break; + + case PS_NOT_AVAILABLE: + aPreview = GetPreviewSubstitution( + STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION, + ePreviewSize); + if (ePreviewSize == SMALL) + pDescriptor->maSmallPreview = aPreview; + else + pDescriptor->maLargePreview = aPreview; + break; + } + } + + return aPreview; +} + + + + +MasterPageContainer::PreviewState MasterPageContainer::Implementation::GetPreviewState ( + Token aToken) const +{ + const ::osl::MutexGuard aGuard (maMutex); + + PreviewState eState (PS_NOT_AVAILABLE); + + SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + { + if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0) + eState = PS_AVAILABLE; + else if (pDescriptor->mpPreviewProvider.get() != NULL) + { + // The preview does not exist but can be created. When that is + // not expensive then do it at once. + if (mpRequestQueue->HasRequest(aToken)) + eState = PS_PREPARING; + else + eState = PS_CREATABLE; + } + else + eState = PS_NOT_AVAILABLE; + } + + return eState; +} + + + + +bool MasterPageContainer::Implementation::RequestPreview (Token aToken) +{ + SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken); + if (pDescriptor.get() != NULL) + return mpRequestQueue->RequestPreview(pDescriptor); + else + return false; +} + + + + +Reference<frame::XModel> MasterPageContainer::Implementation::GetModel (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + if ( ! mxModel.is()) + { + // Get the desktop a s service factory. + ::rtl::OUString sDesktopServiceName ( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")); + uno::Reference<frame::XComponentLoader> xDesktop ( + ::comphelper::getProcessServiceFactory()->createInstance( + sDesktopServiceName), + uno::UNO_QUERY); + + // Create a new model. + ::rtl::OUString sModelServiceName ( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.presentation.PresentationDocument")); + mxModel = uno::Reference<frame::XModel>( + ::comphelper::getProcessServiceFactory()->createInstance( + sModelServiceName), + uno::UNO_QUERY); + + // Initialize the model. + uno::Reference<frame::XLoadable> xLoadable (mxModel,uno::UNO_QUERY); + if (xLoadable.is()) + xLoadable->initNew(); + + // Use its tunnel to get a pointer to its core implementation. + uno::Reference<lang::XUnoTunnel> xUnoTunnel (mxModel, uno::UNO_QUERY); + if (xUnoTunnel.is()) + { + mpDocument = reinterpret_cast<SdXImpressDocument*>( + xUnoTunnel->getSomething( + SdXImpressDocument::getUnoTunnelId()))->GetDoc(); + } + + // Create a default page. + uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier (mxModel, uno::UNO_QUERY); + if (xSlideSupplier.is()) + { + uno::Reference<drawing::XDrawPages> xSlides ( + xSlideSupplier->getDrawPages(), uno::UNO_QUERY); + if (xSlides.is()) + { + sal_Int32 nIndex (0); + uno::Reference<drawing::XDrawPage> xNewPage (xSlides->insertNewByIndex(nIndex)); + uno::Reference<beans::XPropertySet> xProperties(xNewPage, uno::UNO_QUERY); + if (xProperties.is()) + xProperties->setPropertyValue( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Layout")), + makeAny((sal_Int16)AUTOLAYOUT_TITLE)); + } + } + } + return mxModel; +} + + + + +SdDrawDocument* MasterPageContainer::Implementation::GetDocument (void) +{ + GetModel(); + return mpDocument; +} + + + + +Image MasterPageContainer::Implementation::GetPreviewSubstitution ( + sal_uInt16 nId, + PreviewSize ePreviewSize) +{ + const ::osl::MutexGuard aGuard (maMutex); + + Image aPreview; + + switch (nId) + { + case STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION: + { + Image& rPreview (ePreviewSize==SMALL + ? maSmallPreviewBeingCreated + : maLargePreviewBeingCreated); + if (rPreview.GetSizePixel().Width() == 0) + { + rPreview = maPreviewRenderer.RenderSubstitution( + ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel, + SdResId(STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION)); + } + aPreview = rPreview; + } + break; + + case STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION: + { + Image& rPreview (ePreviewSize==SMALL + ? maSmallPreviewNotAvailable + : maLargePreviewNotAvailable); + if (rPreview.GetSizePixel().Width() == 0) + { + rPreview = maPreviewRenderer.RenderSubstitution( + ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel, + SdResId(STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION)); + } + aPreview = rPreview; + } + break; + } + + return aPreview; +} + + + + +void MasterPageContainer::Implementation::CleanContainer (void) +{ + // Remove the empty elements at the end of the container. The empty + // elements in the middle can not be removed because that would + // invalidate the references still held by others. + int nIndex (maContainer.size()-1); + while (nIndex>=0 && maContainer[nIndex].get()==NULL) + --nIndex; + maContainer.resize(++nIndex); +} + + + + +void MasterPageContainer::Implementation::FireContainerChange ( + MasterPageContainerChangeEvent::EventType eType, + Token aToken, + bool bNotifyAsynchronously) +{ + if (bNotifyAsynchronously) + { + Application::PostUserEvent( + LINK(this,Implementation,AsynchronousNotifyCallback), + new EventData(eType,aToken)); + } + else + { + ::std::vector<Link> aCopy(maChangeListeners.begin(),maChangeListeners.end()); + ::std::vector<Link>::iterator iListener; + MasterPageContainerChangeEvent aEvent; + aEvent.meEventType = eType; + aEvent.maChildToken = aToken; + for (iListener=aCopy.begin(); iListener!=aCopy.end(); ++iListener) + iListener->Call(&aEvent); + } +} + + + + +bool MasterPageContainer::Implementation::UpdateDescriptor ( + const SharedMasterPageDescriptor& rpDescriptor, + bool bForcePageObject, + bool bForcePreview, + bool bSendEvents) +{ + const ::osl::MutexGuard aGuard (maMutex); + + // We have to create the page object when the preview provider needs it + // and the caller needs the preview. + bForcePageObject |= (bForcePreview + && rpDescriptor->mpPreviewProvider->NeedsPageObject() + && rpDescriptor->mpMasterPage==NULL); + + // Define a cost threshold so that an update or page object or preview + // that is at least this cost are made at once. Updates with higher cost + // are scheduled for later. + sal_Int32 nCostThreshold (mpRequestQueue->IsEmpty() ? 5 : 0); + + // Update the page object (which may be used for the preview update). + if (bForcePageObject) + GetDocument(); + bool bPageObjectModified (rpDescriptor->UpdatePageObject( + (bForcePageObject ? -1 : nCostThreshold), + mpDocument)); + if (bPageObjectModified && bSendEvents) + FireContainerChange( + MasterPageContainerChangeEvent::DATA_CHANGED, + rpDescriptor->maToken); + if (bPageObjectModified && ! mbFirstPageObjectSeen) + UpdatePreviewSizePixel(); + + // Update the preview. + bool bPreviewModified (rpDescriptor->UpdatePreview( + (bForcePreview ? -1 : nCostThreshold), + maSmallPreviewSizePixel, + maLargePreviewSizePixel, + maPreviewRenderer)); + + if (bPreviewModified && bSendEvents) + FireContainerChange( + MasterPageContainerChangeEvent::PREVIEW_CHANGED, + rpDescriptor->maToken); + + return bPageObjectModified || bPreviewModified; +} + + + + +void MasterPageContainer::Implementation::ReleaseDescriptor (Token aToken) +{ + if (aToken>=0 && (unsigned)aToken<maContainer.size()) + { + maContainer[aToken].reset(); + mbContainerCleaningPending = true; + } +} + + + + +void MasterPageContainer::Implementation::FillingDone (void) +{ + mpRequestQueue->ProcessAllRequests(); +} + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPageContainer.hxx b/sd/source/ui/sidebar/MasterPageContainer.hxx new file mode 100644 index 000000000000..e1502082b743 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainer.hxx @@ -0,0 +1,214 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_HXX + +#include "MasterPageContainerProviders.hxx" + +#include <osl/mutex.hxx> +#include <tools/string.hxx> +#include <vcl/image.hxx> +#include <memory> +#include "PreviewRenderer.hxx" +#include <com/sun/star/frame/XModel.hpp> +#include <vcl/timer.hxx> +#include "tools/SdGlobalResourceContainer.hxx" + +#include <boost/shared_ptr.hpp> + +class SdPage; +class SdDrawDocument; +class SfxObjectShellLock; + +namespace sd { +class DrawDocShell; +} + +namespace sd { namespace sidebar { + +class MasterPageDescriptor; + +/** This container manages the master pages used by the MasterPagesSelector + controls. It uses internally a singleton implementation object. + Therefore, all MasterPageContainer object operator on the same set of + master pages. Each MasterPageContainer, however, has its own + PreviewSize value and thus can independantly switch between large and + small previews. + + The container maintains its own document to store master page objects. + + For each master page container stores its URL, preview bitmap, page + name, and, if available, the page object. + + Entries are accessed via a Token, which is mostly a numerical index but + whose values do not neccessarily have to be consecutive. +*/ +class MasterPageContainer +{ +public: + typedef int Token; + static const Token NIL_TOKEN = -1; + + MasterPageContainer (void); + virtual ~MasterPageContainer (void); + + void AddChangeListener (const Link& rLink); + void RemoveChangeListener (const Link& rLink); + + enum PreviewSize { SMALL, LARGE }; + /** There are two different preview sizes, a small one and a large one. + Which one is used by the called container can be changed with this + method. + When the preview size is changed then all change listeners are + notified of this. + */ + void SetPreviewSize (PreviewSize eSize); + + /** Returns the preview size. + */ + PreviewSize GetPreviewSize (void) const; + + /** Return the preview size in pixels. + */ + Size GetPreviewSizePixel (void) const; + + enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE }; + PreviewState GetPreviewState (Token aToken); + + /** This method is typically called for entries in the container for + which GetPreviewState() returns OS_CREATABLE. The creation of the + preview is then scheduled to be executed asynchronously at a later + point in time. When the preview is available the change listeners + will be notified. + */ + bool RequestPreview (Token aToken); + + /** Each entry of the container is either the first page of a template + document or is a master page of an Impress document. + */ + enum Origin { + MASTERPAGE, // Master page of a document. + TEMPLATE, // First page of a template file. + DEFAULT, // Empty master page with default style. + UNKNOWN + }; + + /** Put the master page identified and described by the given parameters + into the container. When there already is a master page with the + given URL, page name, or object pointer (when that is not NULL) then + the existing entry is replaced/updated by the given one. Otherwise + a new entry is inserted. + */ + Token PutMasterPage (const ::boost::shared_ptr<MasterPageDescriptor>& rDescriptor); + void AcquireToken (Token aToken); + void ReleaseToken (Token aToken); + + /** This and the GetTokenForIndex() methods can be used to iterate over + all members of the container. + */ + int GetTokenCount (void) const; + + /** Determine whether the container has a member for the given token. + */ + bool HasToken (Token aToken) const; + + /** Return a token for an index in the range + 0 <= index < GetTokenCount(). + */ + Token GetTokenForIndex (int nIndex); + + Token GetTokenForURL (const String& sURL); + Token GetTokenForStyleName (const String& sStyleName); + Token GetTokenForPageObject (const SdPage* pPage); + + String GetURLForToken (Token aToken); + String GetPageNameForToken (Token aToken); + String GetStyleNameForToken (Token aToken); + SdPage* GetPageObjectForToken (Token aToken, bool bLoad=true); + Origin GetOriginForToken (Token aToken); + sal_Int32 GetTemplateIndexForToken (Token aToken); + ::boost::shared_ptr<MasterPageDescriptor> GetDescriptorForToken (Token aToken); + + void InvalidatePreview (Token aToken); + + /** Return a preview for the specified token. When the preview is not + present then the PreviewProvider associated with the token is + executed only when that is not expensive. It is the responsibility + of the caller to call RequestPreview() to do the same + (asynchronously) for expensive PreviewProviders. + Call GetPreviewState() to find out if that is necessary. + @param aToken + This token specifies for which master page to return the prview. + Tokens are returned for example by the GetTokenFor...() methods. + @return + The returned image is the requested preview or a substitution. + */ + Image GetPreviewForToken (Token aToken); + +private: + class Implementation; + ::boost::shared_ptr<Implementation> mpImpl; + PreviewSize mePreviewSize; + + /** Retrieve the preview of the document specified by the given URL. + */ + static BitmapEx LoadPreviewFromURL (const ::rtl::OUString& aURL); +}; + + + + +/** For some changes to the set of master pages in a MasterPageContainer or + to the data stored for each master page one or more events are sent to + registered listeners. + Each event has an event type and a token that tells the listener where + the change took place. +*/ +class MasterPageContainerChangeEvent +{ +public: + enum EventType { + // A master page was added to the container. + CHILD_ADDED, + // A master page was removed from the container. + CHILD_REMOVED, + // The preview of a master page has changed. + PREVIEW_CHANGED, + // The size of a preview has changed. + SIZE_CHANGED, + // Some of the data stored for a master page has changed. + DATA_CHANGED, + // The TemplateIndex of a master page has changed. + INDEX_CHANGED, + // More than one entries changed their TemplateIndex + INDEXES_CHANGED + } meEventType; + + // Token of the container entry whose data changed or which was added or + // removed. + MasterPageContainer::Token maChildToken; +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/MasterPageContainerFiller.cxx b/sd/source/ui/sidebar/MasterPageContainerFiller.cxx new file mode 100644 index 000000000000..2ace8e2f781f --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerFiller.cxx @@ -0,0 +1,191 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageContainerFiller.hxx" + +#include "MasterPageDescriptor.hxx" +#include "MasterPageContainerProviders.hxx" +#include "TemplateScanner.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +namespace sd { namespace sidebar { + +MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter& rpAdapter) + : mrContainerAdapter(rpAdapter), + meState(INITIALIZE_TEMPLATE_SCANNER), + mpScannerTask(), + mpLastAddedEntry(NULL), + mnIndex(1) +{ + // Add one entry for the default master page. We use temporarily the + // DefaultPagePreviewProvider to prevent the rendering (and the + // expensive creation) of the default page. It is replaced later on by + // another. + SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( + MasterPageContainer::DEFAULT, + 0, + String(), + String(), + String(), + false, + ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()), + ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider()))); + mrContainerAdapter.PutMasterPage(pDescriptor); +} + + + + +MasterPageContainerFiller::~MasterPageContainerFiller (void) +{ +} + + + + +void MasterPageContainerFiller::RunNextStep (void) +{ + switch (meState) + { + case INITIALIZE_TEMPLATE_SCANNER: + mpScannerTask.reset(new TemplateScanner()); + meState = SCAN_TEMPLATE; + break; + + case SCAN_TEMPLATE: + meState = ScanTemplate(); + break; + + case ADD_TEMPLATE: + meState = AddTemplate(); + break; + + case DONE: + case ERROR: + default: + break; + } + + // When the state has just been set to DONE or ERROR then tell the + // container that no more templates will be coming and stop the + // scanning. + switch (meState) + { + case DONE: + case ERROR: + if (mpScannerTask.get() != NULL) + { + mrContainerAdapter.FillingDone(); + mpScannerTask.reset(); + } + default: + break; + } +} + + + + +bool MasterPageContainerFiller::HasNextStep (void) +{ + switch (meState) + { + case DONE: + case ERROR: + return false; + + default: + return true; + } +} + + + + +MasterPageContainerFiller::State MasterPageContainerFiller::ScanTemplate (void) +{ + State eState (ERROR); + + if (mpScannerTask.get() != NULL) + { + if (mpScannerTask->HasNextStep()) + { + mpScannerTask->RunNextStep(); + if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry) + { + mpLastAddedEntry = mpScannerTask->GetLastAddedEntry(); + if (mpLastAddedEntry != NULL) + eState = ADD_TEMPLATE; + else + eState = SCAN_TEMPLATE; + } + else + eState = SCAN_TEMPLATE; + } + else + eState = DONE; + } + + return eState; +} + + + + +MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate (void) +{ + if (mpLastAddedEntry != NULL) + { + SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( + MasterPageContainer::TEMPLATE, + mnIndex, + mpLastAddedEntry->msPath, + mpLastAddedEntry->msTitle, + String(), + false, + ::boost::shared_ptr<PageObjectProvider>( + new TemplatePageObjectProvider(mpLastAddedEntry->msPath)), + ::boost::shared_ptr<PreviewProvider>( + new TemplatePreviewProvider(mpLastAddedEntry->msPath)))); + // For user supplied templates we use a different preview provider: + // The preview in the document shows not only shapes on the master + // page but also shapes on the foreground. This is misleading and + // therefore these previews are discarded and created directly from + // the page objects. + if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER) + pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>( + new PagePreviewProvider()); + + mrContainerAdapter.PutMasterPage(pDescriptor); + ++mnIndex; + } + + return SCAN_TEMPLATE; +} + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPageContainerFiller.hxx b/sd/source/ui/sidebar/MasterPageContainerFiller.hxx new file mode 100644 index 000000000000..e475d84ffe67 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerFiller.hxx @@ -0,0 +1,89 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_FILLER_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_FILLER_HXX + +#include "MasterPageContainer.hxx" +#include "MasterPageDescriptor.hxx" +#include "tools/AsynchronousTask.hxx" + +namespace sd { +class TemplateScanner; +class TemplateEntry; +} + +namespace sd { namespace sidebar { + +/** Fill a MasterPageContainer with information about the available master + pages. These are provided by one default page and from the existing + Impress templates. This is done asynchronously. +*/ +class MasterPageContainerFiller + : public ::sd::tools::AsynchronousTask +{ +public: + class ContainerAdapter + { + public: + virtual MasterPageContainer::Token PutMasterPage ( + const SharedMasterPageDescriptor& rpDescriptor) = 0; + /** This method is called when all Impress templates have been added + to the container via the PutMasterPage() method. + */ + virtual void FillingDone (void) = 0; + }; + + MasterPageContainerFiller (ContainerAdapter& rContainerAdapter); + virtual ~MasterPageContainerFiller (void); + + /** Run the next step of the task. After HasNextStep() returns false + this method should ignore further calls. + */ + virtual void RunNextStep (void); + + /** Return <TRUE/> when there is at least one more step to execute. + When the task has been executed completely then <FALSE/> is + returned. + */ + virtual bool HasNextStep (void); + +private: + ContainerAdapter& mrContainerAdapter; + // Remember what the next step has to do. + enum State { + INITIALIZE_TEMPLATE_SCANNER, + SCAN_TEMPLATE, + ADD_TEMPLATE, + ERROR, + DONE + } meState; + ::std::auto_ptr<TemplateScanner> mpScannerTask; + const TemplateEntry* mpLastAddedEntry; + int mnIndex; + + State ScanTemplate (void); + State AddTemplate (void); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/MasterPageContainerProviders.cxx b/sd/source/ui/sidebar/MasterPageContainerProviders.cxx new file mode 100644 index 000000000000..2a583185f937 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerProviders.cxx @@ -0,0 +1,420 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageContainerProviders.hxx" + +#include "DrawDocShell.hxx" +#include "drawdoc.hxx" +#include "PreviewRenderer.hxx" +#include <comphelper/processfactory.hxx> +#include <sfx2/app.hxx> +#include <sfx2/sfxsids.hrc> +#include <unotools/ucbstreamhelper.hxx> +#include <vcl/image.hxx> +#include <vcl/pngread.hxx> +#include <com/sun/star/embed/ElementModes.hpp> +#include <tools/diagnose_ex.h> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace sd { namespace sidebar { + + +//===== PagePreviewProvider =================================================== + +PagePreviewProvider::PagePreviewProvider (void) +{ +} + + + + +Image PagePreviewProvider::operator () ( + int nWidth, + SdPage* pPage, + ::sd::PreviewRenderer& rRenderer) +{ + Image aPreview; + + if (pPage != NULL) + { + // Use the given renderer to create a preview of the given page + // object. + aPreview = rRenderer.RenderPage( + pPage, + nWidth, + String::CreateFromAscii(""), + false); + } + + return aPreview; +} + + + + +int PagePreviewProvider::GetCostIndex (void) +{ + return 5; +} + + + + +bool PagePreviewProvider::NeedsPageObject (void) +{ + return true; +} + + + + +//===== TemplatePreviewProvider =============================================== + +TemplatePreviewProvider::TemplatePreviewProvider (const ::rtl::OUString& rsURL) + : msURL(rsURL) +{ +} + + + + +Image TemplatePreviewProvider::operator() ( + int nWidth, + SdPage* pPage, + ::sd::PreviewRenderer& rRenderer) +{ + // Unused parameters. + (void)nWidth; + (void)pPage; + (void)rRenderer; + + // Load the thumbnail from a template document. + uno::Reference<io::XInputStream> xIStream; + + uno::Reference< lang::XMultiServiceFactory > xServiceManager ( + ::comphelper::getProcessServiceFactory()); + if (xServiceManager.is()) + { + try + { + uno::Reference<lang::XSingleServiceFactory> xStorageFactory( + xServiceManager->createInstance( + ::rtl::OUString::createFromAscii( + "com.sun.star.embed.StorageFactory")), + uno::UNO_QUERY); + + if (xStorageFactory.is()) + { + uno::Sequence<uno::Any> aArgs (2); + aArgs[0] <<= msURL; + aArgs[1] <<= embed::ElementModes::READ; + uno::Reference<embed::XStorage> xDocStorage ( + xStorageFactory->createInstanceWithArguments(aArgs), + uno::UNO_QUERY); + + try + { + if (xDocStorage.is()) + { + uno::Reference<embed::XStorage> xStorage ( + xDocStorage->openStorageElement( + ::rtl::OUString::createFromAscii("Thumbnails"), + embed::ElementModes::READ)); + if (xStorage.is()) + { + uno::Reference<io::XStream> xThumbnailCopy ( + xStorage->cloneStreamElement( + ::rtl::OUString::createFromAscii( + "thumbnail.png"))); + if (xThumbnailCopy.is()) + xIStream = xThumbnailCopy->getInputStream(); + } + } + } + catch (uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + + try + { + // An (older) implementation had a bug - The storage + // name was "Thumbnail" instead of "Thumbnails". The + // old name is still used as fallback but this code can + // be removed soon. + if ( ! xIStream.is()) + { + uno::Reference<embed::XStorage> xStorage ( + xDocStorage->openStorageElement( + ::rtl::OUString::createFromAscii("Thumbnail"), + embed::ElementModes::READ)); + if (xStorage.is()) + { + uno::Reference<io::XStream> xThumbnailCopy ( + xStorage->cloneStreamElement( + ::rtl::OUString::createFromAscii( + "thumbnail.png"))); + if (xThumbnailCopy.is()) + xIStream = xThumbnailCopy->getInputStream(); + } + } + } + catch (uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + } + } + catch (uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access tuhmbnail of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + } + + // Extract the image from the stream. + BitmapEx aThumbnail; + if (xIStream.is()) + { + ::std::auto_ptr<SvStream> pStream ( + ::utl::UcbStreamHelper::CreateStream (xIStream)); + ::vcl::PNGReader aReader (*pStream); + aThumbnail = aReader.Read (); + } + + // Note that the preview is returned without scaling it to the desired + // width. This gives the caller the chance to take advantage of a + // possibly larger resolution then was asked for. + return aThumbnail; +} + + + + +int TemplatePreviewProvider::GetCostIndex (void) +{ + return 10; +} + + + + +bool TemplatePreviewProvider::NeedsPageObject (void) +{ + return false; +} + + + + +//===== TemplatePageObjectProvider ============================================= + +TemplatePageObjectProvider::TemplatePageObjectProvider (const ::rtl::OUString& rsURL) + : msURL(rsURL), + mxDocumentShell() +{ +} + + + + +SdPage* TemplatePageObjectProvider::operator() (SdDrawDocument* pContainerDocument) +{ + // Unused parameters. + (void)pContainerDocument; + + SdPage* pPage = NULL; + + mxDocumentShell = NULL; + ::sd::DrawDocShell* pDocumentShell = NULL; + try + { + // Load the template document and return its first page. + pDocumentShell = LoadDocument (msURL); + if (pDocumentShell != NULL) + { + SdDrawDocument* pDocument = pDocumentShell->GetDoc(); + if (pDocument != NULL) + { + pPage = pDocument->GetMasterSdPage(0, PK_STANDARD); + // In order to make the newly loaded master page deletable + // when copied into documents it is marked as no "precious". + // When it is modified then it is marked as "precious". + if (pPage != NULL) + pPage->SetPrecious(false); + } + } + } + catch (uno::RuntimeException) + { + DBG_UNHANDLED_EXCEPTION(); + pPage = NULL; + } + + return pPage; +} + + + + +::sd::DrawDocShell* TemplatePageObjectProvider::LoadDocument (const ::rtl::OUString& sFileName) +{ + SfxApplication* pSfxApp = SFX_APP(); + SfxItemSet* pSet = new SfxAllItemSet (pSfxApp->GetPool()); + pSet->Put (SfxBoolItem (SID_TEMPLATE, sal_True)); + pSet->Put (SfxBoolItem (SID_PREVIEW, sal_True)); + if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, sal_True, pSet)) + { + mxDocumentShell = NULL; + } + SfxObjectShell* pShell = mxDocumentShell; + return PTR_CAST(::sd::DrawDocShell,pShell); +} + + + + +int TemplatePageObjectProvider::GetCostIndex (void) +{ + return 20; +} + + + + +bool TemplatePageObjectProvider::operator== (const PageObjectProvider& rProvider) +{ + const TemplatePageObjectProvider* pTemplatePageObjectProvider + = dynamic_cast<const TemplatePageObjectProvider*>(&rProvider); + if (pTemplatePageObjectProvider != NULL) + return (msURL == pTemplatePageObjectProvider->msURL); + else + return false; +} + + + + +//===== DefaultPageObjectProvider ============================================== + +DefaultPageObjectProvider::DefaultPageObjectProvider (void) +{ +} + + + + +SdPage* DefaultPageObjectProvider::operator () (SdDrawDocument* pContainerDocument) +{ + SdPage* pLocalMasterPage = NULL; + if (pContainerDocument != NULL) + { + sal_Int32 nIndex (0); + SdPage* pLocalSlide = pContainerDocument->GetSdPage((sal_uInt16)nIndex, PK_STANDARD); + if (pLocalSlide!=NULL && pLocalSlide->TRG_HasMasterPage()) + pLocalMasterPage = dynamic_cast<SdPage*>(&pLocalSlide->TRG_GetMasterPage()); + } + + if (pLocalMasterPage == NULL) + { + DBG_ASSERT(false, "can not create master page for slide"); + } + + return pLocalMasterPage; +} + + + + +int DefaultPageObjectProvider::GetCostIndex (void) +{ + return 15; +} + + + + +bool DefaultPageObjectProvider::operator== (const PageObjectProvider& rProvider) +{ + return (dynamic_cast<const DefaultPageObjectProvider*>(&rProvider) != NULL); +} + + + + +//===== ExistingPageProvider ================================================== + +ExistingPageProvider::ExistingPageProvider (SdPage* pPage) + : mpPage(pPage) +{ +} + + + + +SdPage* ExistingPageProvider::operator() (SdDrawDocument* pDocument) +{ + (void)pDocument; // Unused parameter. + + return mpPage; +} + + + + +int ExistingPageProvider::GetCostIndex (void) +{ + return 0; +} + + + + +bool ExistingPageProvider::operator== (const PageObjectProvider& rProvider) +{ + const ExistingPageProvider* pExistingPageProvider + = dynamic_cast<const ExistingPageProvider*>(&rProvider); + if (pExistingPageProvider != NULL) + return (mpPage == pExistingPageProvider->mpPage); + else + return false; +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPageContainerProviders.hxx b/sd/source/ui/sidebar/MasterPageContainerProviders.hxx new file mode 100644 index 000000000000..eaf6fc9de9d9 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerProviders.hxx @@ -0,0 +1,183 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_PROVIDERS_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_PROVIDERS_HXX + +#include <rtl/ustring.hxx> +#include <sfx2/objsh.hxx> + +class Image; +class SdDrawDocument; +class SdPage; +namespace sd { class PreviewRenderer; } +namespace sd { class DrawDocShell; } + + +namespace sd { namespace sidebar { + + +/** Interface for a provider of page objects. It is used by the + MasterPageDescriptor to create master page objects on demand. +*/ +class PageObjectProvider +{ +public: + /** Return a master page either by returning an already existing one, by + creating a new page, or by loading a document. + @param pDocument + The document of the MasterPageContainer. It may be used to + create new pages. + */ + virtual SdPage* operator() (SdDrawDocument* pDocument) = 0; + + /** An abstract value for the expected cost of providing a master page + object. + @return + A value of 0 represents for the lowest cost, i.e. an almost + immediate return. Positive values stand for higher costs. + Negative values are not supported. + */ + virtual int GetCostIndex (void) = 0; + + virtual bool operator== (const PageObjectProvider& rProvider) = 0; +}; + + + + +class PreviewProvider +{ +public: + /** Create a preview image in the specified width. + @param nWidth + Requested width of the preview. The calling method can cope + with other sizes as well but the resulting image quality is + better when the returned image has the requested size. + @param pPage + Page object for which a preview is requested. This may be NULL + when the page object is expensive to get and the PreviewProvider + does not need this object (NeedsPageObject() returns false.) + @param rRenderer + This PreviewRenderer may be used by the PreviewProvider to + create a preview image. + */ + virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) = 0; + + /** Return a value that indicates how expensive the creation of a + preview image is. The higher the returned value the more expensive + is the preview creation. Return 0 when the preview is already + present and can be returned immediately. + */ + virtual int GetCostIndex (void) = 0; + + /** Return whether the page object passed is necessary to create a + preview. + */ + virtual bool NeedsPageObject (void) = 0; +}; + + + + +/** Provide previews of existing page objects by rendering them. +*/ +class PagePreviewProvider : public PreviewProvider +{ +public: + PagePreviewProvider (void); + virtual Image operator () (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer); + virtual int GetCostIndex (void); + virtual bool NeedsPageObject (void); +private: +}; + + + + +/** Provide master page objects for template documents for which only the + URL is given. +*/ +class TemplatePageObjectProvider : public PageObjectProvider +{ +public: + TemplatePageObjectProvider (const ::rtl::OUString& rsURL); + virtual ~TemplatePageObjectProvider (void) {}; + virtual SdPage* operator () (SdDrawDocument* pDocument); + virtual int GetCostIndex (void); + virtual bool operator== (const PageObjectProvider& rProvider); +private: + ::rtl::OUString msURL; + SfxObjectShellLock mxDocumentShell; + ::sd::DrawDocShell* LoadDocument (const ::rtl::OUString& sFileName); +}; + + + + +/** Provide previews for template documents by loading the thumbnails from + the documents. +*/ +class TemplatePreviewProvider : public PreviewProvider +{ +public: + TemplatePreviewProvider (const ::rtl::OUString& rsURL); + virtual ~TemplatePreviewProvider (void) {}; + virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer); + virtual int GetCostIndex (void); + virtual bool NeedsPageObject (void); +private: + ::rtl::OUString msURL; +}; + + + + +/** Create an empty default master page. +*/ +class DefaultPageObjectProvider : public PageObjectProvider +{ +public: + DefaultPageObjectProvider (void); + virtual SdPage* operator () (SdDrawDocument* pDocument); + virtual int GetCostIndex (void); + virtual bool operator== (const PageObjectProvider& rProvider); +}; + + + +/** This implementation of the PageObjectProvider simply returns an already + existing master page object. +*/ +class ExistingPageProvider : public PageObjectProvider +{ +public: + ExistingPageProvider (SdPage* pPage); + virtual SdPage* operator() (SdDrawDocument* pDocument); + virtual int GetCostIndex (void); + virtual bool operator== (const PageObjectProvider& rProvider); +private: + SdPage* mpPage; +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/MasterPageContainerQueue.cxx b/sd/source/ui/sidebar/MasterPageContainerQueue.cxx new file mode 100644 index 000000000000..c55354d8b62a --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerQueue.cxx @@ -0,0 +1,297 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageContainerQueue.hxx" + +#include "tools/IdleDetection.hxx" + +#include <set> + +namespace sd { namespace sidebar { + +const sal_Int32 MasterPageContainerQueue::snDelayedCreationTimeout (15); +const sal_Int32 MasterPageContainerQueue::snDelayedCreationTimeoutWhenNotIdle (100); +const sal_Int32 MasterPageContainerQueue::snMasterPagePriorityBoost (5); +const sal_Int32 MasterPageContainerQueue::snWaitForMoreRequestsPriorityThreshold (-10); +sal_uInt32 MasterPageContainerQueue::snWaitForMoreRequestsCount(15); + +//===== MasterPageContainerQueue::PreviewCreationRequest ====================== + +class MasterPageContainerQueue::PreviewCreationRequest +{ +public: + PreviewCreationRequest (const SharedMasterPageDescriptor& rpDescriptor, int nPriority) + : mpDescriptor(rpDescriptor), + mnPriority(nPriority) + {} + SharedMasterPageDescriptor mpDescriptor; + int mnPriority; + class Compare {public: + bool operator() (const PreviewCreationRequest& r1,const PreviewCreationRequest& r2) + { + if (r1.mnPriority != r2.mnPriority) + { + // Prefer requests with higher priority. + return r1.mnPriority > r2.mnPriority; + } + else + { + // Prefer tokens that have been earlier created (those with lower + // value). + return r1.mpDescriptor->maToken < r2.mpDescriptor->maToken; + } + } + }; + class CompareToken {public: + MasterPageContainer::Token maToken; + CompareToken(MasterPageContainer::Token aToken) : maToken(aToken) {} + bool operator() (const PreviewCreationRequest& rRequest) + { return maToken==rRequest.mpDescriptor->maToken; } + }; +}; + + + + +//===== MasterPageContainerQueue::RequestQueue ================================ + +class MasterPageContainerQueue::RequestQueue + : public ::std::set<PreviewCreationRequest,PreviewCreationRequest::Compare> +{ +public: + RequestQueue (void) {} +}; + + + + +//===== MasterPageContainerQueue ============================================== + +MasterPageContainerQueue* MasterPageContainerQueue::Create ( + const ::boost::weak_ptr<ContainerAdapter>& rpContainer) +{ + MasterPageContainerQueue* pQueue = new MasterPageContainerQueue(rpContainer); + pQueue->LateInit(); + return pQueue; +} + + + + +MasterPageContainerQueue::MasterPageContainerQueue ( + const ::boost::weak_ptr<ContainerAdapter>& rpContainer) + : mpWeakContainer(rpContainer), + mpRequestQueue(new RequestQueue()), + maDelayedPreviewCreationTimer(), + mnRequestsServedCount(0) +{ +} + + + + +MasterPageContainerQueue::~MasterPageContainerQueue (void) +{ + maDelayedPreviewCreationTimer.Stop(); + while ( ! mpRequestQueue->empty()) + mpRequestQueue->erase(mpRequestQueue->begin()); +} + + + + +void MasterPageContainerQueue::LateInit (void) +{ + // Set up the timer for the delayed creation of preview bitmaps. + maDelayedPreviewCreationTimer.SetTimeout (snDelayedCreationTimeout); + Link aLink (LINK(this,MasterPageContainerQueue,DelayedPreviewCreation)); + maDelayedPreviewCreationTimer.SetTimeoutHdl(aLink); +} + + + + +bool MasterPageContainerQueue::RequestPreview (const SharedMasterPageDescriptor& rpDescriptor) +{ + bool bSuccess (false); + if (rpDescriptor.get() != NULL + && rpDescriptor->maLargePreview.GetSizePixel().Width() == 0) + { + sal_Int32 nPriority (CalculatePriority(rpDescriptor)); + + // Add a new or replace an existing request. + RequestQueue::iterator iRequest (::std::find_if( + mpRequestQueue->begin(), + mpRequestQueue->end(), + PreviewCreationRequest::CompareToken(rpDescriptor->maToken))); + // When a request for the same token exists then the lowest of the + // two priorities is used. + if (iRequest != mpRequestQueue->end()) + if (iRequest->mnPriority < nPriority) + { + mpRequestQueue->erase(iRequest); + iRequest = mpRequestQueue->end(); + } + + // Add a new request when none exists (or has just been erased). + if (iRequest == mpRequestQueue->end()) + { + mpRequestQueue->insert(PreviewCreationRequest(rpDescriptor,nPriority)); + maDelayedPreviewCreationTimer.Start(); + bSuccess = true; + } + } + return bSuccess; +} + + + + +sal_Int32 MasterPageContainerQueue::CalculatePriority ( + const SharedMasterPageDescriptor& rpDescriptor) const +{ + sal_Int32 nPriority; + + // The cost is used as a starting value. + int nCost (0); + if (rpDescriptor->mpPreviewProvider.get() != NULL) + { + nCost = rpDescriptor->mpPreviewProvider->GetCostIndex(); + if (rpDescriptor->mpPreviewProvider->NeedsPageObject()) + if (rpDescriptor->mpPageObjectProvider.get() != NULL) + nCost += rpDescriptor->mpPageObjectProvider->GetCostIndex(); + } + + // Its negative value is used so that requests with a low cost are + // preferred over those with high costs. + nPriority = -nCost; + + // Add a term that introduces an order based on the appearance in the + // AllMasterPagesSelector. + nPriority -= rpDescriptor->maToken / 3; + + // Process requests for the CurrentMasterPagesSelector first. + if (rpDescriptor->meOrigin == MasterPageContainer::MASTERPAGE) + nPriority += snMasterPagePriorityBoost; + + return nPriority; +} + + + + +IMPL_LINK(MasterPageContainerQueue, DelayedPreviewCreation, Timer*, pTimer) +{ + bool bIsShowingFullScreenShow (false); + bool bWaitForMoreRequests (false); + + do + { + if (mpRequestQueue->size() == 0) + break; + + // First check whether the system is idle. + sal_Int32 nIdleState (tools::IdleDetection::GetIdleState()); + if (nIdleState != tools::IdleDetection::IDET_IDLE) + { + if ((nIdleState&tools::IdleDetection::IDET_FULL_SCREEN_SHOW_ACTIVE) != 0) + bIsShowingFullScreenShow = true; + break; + } + + PreviewCreationRequest aRequest (*mpRequestQueue->begin()); + + // Check if the request should really be processed right now. + // Reasons to not do it are when its cost is high and not many other + // requests have been inserted into the queue that would otherwise + // be processed first. + if (aRequest.mnPriority < snWaitForMoreRequestsPriorityThreshold + && (mnRequestsServedCount+mpRequestQueue->size() < snWaitForMoreRequestsCount)) + { + // Wait for more requests before this one is processed. Note + // that the queue processing is not started anew when this + // method is left. That is done when the next request is + // inserted. + bWaitForMoreRequests = true; + break; + } + + mpRequestQueue->erase(mpRequestQueue->begin()); + + if (aRequest.mpDescriptor.get() != NULL) + { + mnRequestsServedCount += 1; + if ( ! mpWeakContainer.expired()) + { + ::boost::shared_ptr<ContainerAdapter> pContainer (mpWeakContainer); + if (pContainer.get() != NULL) + pContainer->UpdateDescriptor(aRequest.mpDescriptor,false,true,true); + } + } + } + while (false); + + if (mpRequestQueue->size() > 0 && ! bWaitForMoreRequests) + { + int nTimeout (snDelayedCreationTimeout); + if (bIsShowingFullScreenShow) + nTimeout = snDelayedCreationTimeoutWhenNotIdle; + maDelayedPreviewCreationTimer.SetTimeout(nTimeout); + pTimer->Start(); + } + + return 0; +} + + + + +bool MasterPageContainerQueue::HasRequest (MasterPageContainer::Token aToken) const +{ + RequestQueue::iterator iRequest (::std::find_if( + mpRequestQueue->begin(), + mpRequestQueue->end(), + PreviewCreationRequest::CompareToken(aToken))); + return (iRequest != mpRequestQueue->end()); +} + + + + +bool MasterPageContainerQueue::IsEmpty (void) const +{ + return mpRequestQueue->empty(); +} + + + + +void MasterPageContainerQueue::ProcessAllRequests (void) +{ + snWaitForMoreRequestsCount = 0; + if (mpRequestQueue->size() > 0) + maDelayedPreviewCreationTimer.Start(); +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPageContainerQueue.hxx b/sd/source/ui/sidebar/MasterPageContainerQueue.hxx new file mode 100644 index 000000000000..48f048de14ed --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageContainerQueue.hxx @@ -0,0 +1,130 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_QUEUE_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_QUEUE_HXX + +#include "MasterPageContainer.hxx" +#include "MasterPageDescriptor.hxx" + +#include <boost/scoped_ptr.hpp> +#include <boost/weak_ptr.hpp> + +namespace sd { namespace sidebar { + + +/** The queue stores and processes all requests from a MasterPageContainer + for the creation of previews. + The order of request processing and its timing is controlled by a + heuristic that uses values given with each request and which is + controlled by various parameters that are described below. +*/ +class MasterPageContainerQueue +{ +public: + class ContainerAdapter { public: + virtual bool UpdateDescriptor ( + const SharedMasterPageDescriptor& rpDescriptor, + bool bForcePageObject, + bool bForcePreview, + bool bSendEvents) = 0; + }; + + static MasterPageContainerQueue* Create ( + const ::boost::weak_ptr<ContainerAdapter>& rpContainer); + virtual ~MasterPageContainerQueue (void); + + /** This method is typically called for entries in the container for + which GetPreviewState() returns OS_CREATABLE. The creation of the + preview is then scheduled to be executed asynchronously at a later + point in time. When the preview is available the change listeners + will be notified. + */ + bool RequestPreview (const SharedMasterPageDescriptor& rDescriptor); + + /** Return <TRUE/> when there is a request currently in the queue for + the given token. + */ + bool HasRequest (MasterPageContainer::Token aToken) const; + + /** Return <TRUE/> when there is at least one request in the queue. + */ + bool IsEmpty (void) const; + + /** After this call the queue does not wait anymore for requests with + higher priority when only a small number of requests with lower + priority are present. This method should be called when all + templates are inserted into the MasterPageContainer. + */ + void ProcessAllRequests (void); + +private: + ::boost::weak_ptr<ContainerAdapter> mpWeakContainer; + class PreviewCreationRequest; + class RequestQueue; + ::boost::scoped_ptr<RequestQueue> mpRequestQueue; + Timer maDelayedPreviewCreationTimer; + sal_uInt32 mnRequestsServedCount; + + // There are a couple of values that define various aspects of the + // heuristic that defines the order and timing in which requests for + // preview creation are processed. + + /** The time to wait (in milliseconds) between the creation of previews. + */ + static const sal_Int32 snDelayedCreationTimeout; + + /** The time to wait when the system is not idle. + */ + static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle; + + /** Requests for previews of master pages in a document have their + priority increased by this value. + */ + static const sal_Int32 snMasterPagePriorityBoost; + + /** When only requests which a priority lower than this threshold exist + and not many requests have been made yet then wait with processing + them until more requests are present. + */ + static const sal_Int32 snWaitForMoreRequestsPriorityThreshold; + + /** When only requests which a priority lower than a threshold exist + and not more requests than this number have been made or already + processed then wait with processing them until more requests are + present. + */ + static sal_uInt32 snWaitForMoreRequestsCount; + + MasterPageContainerQueue (const ::boost::weak_ptr<ContainerAdapter>& rpContainer); + void LateInit (void); + + /** Calculate the priority that defines the order in which requests + are processed. + */ + sal_Int32 CalculatePriority (const SharedMasterPageDescriptor& rDescriptor) const; + + DECL_LINK(DelayedPreviewCreation, Timer *); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/MasterPageDescriptor.cxx b/sd/source/ui/sidebar/MasterPageDescriptor.cxx new file mode 100644 index 000000000000..310838180430 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageDescriptor.cxx @@ -0,0 +1,416 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageDescriptor.hxx" + +#include "DocumentHelper.hxx" +#include "sdpage.hxx" +#include <tools/urlobj.hxx> + +namespace sd { namespace sidebar { + + +//===== MasterPageDescriptor ================================================== + +MasterPageDescriptor::MasterPageDescriptor ( + MasterPageContainer::Origin eOrigin, + const sal_Int32 nTemplateIndex, + const String& rsURL, + const String& rsPageName, + const String& rsStyleName, + const bool bIsPrecious, + const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider, + const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider) + : maToken(MasterPageContainer::NIL_TOKEN), + meOrigin(eOrigin), + msURL(INetURLObject(rsURL).GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS)), + msPageName(rsPageName), + msStyleName(rsStyleName), + mbIsPrecious(bIsPrecious), + mpMasterPage(NULL), + mpSlide(NULL), + maSmallPreview(), + maLargePreview(), + mpPreviewProvider(rpPreviewProvider), + mpPageObjectProvider(rpPageObjectProvider), + mnTemplateIndex(nTemplateIndex), + meURLClassification(URLCLASS_UNDETERMINED), + mnUseCount(0) +{ +} + + + + +MasterPageDescriptor::MasterPageDescriptor (const MasterPageDescriptor& rDescriptor) + : maToken(rDescriptor.maToken), + meOrigin(rDescriptor.meOrigin), + msURL(rDescriptor.msURL), + msPageName(rDescriptor.msPageName), + msStyleName(rDescriptor.msStyleName), + mbIsPrecious(rDescriptor.mbIsPrecious), + mpMasterPage(rDescriptor.mpMasterPage), + mpSlide(rDescriptor.mpSlide), + maSmallPreview(rDescriptor.maSmallPreview), + maLargePreview(rDescriptor.maLargePreview), + mpPreviewProvider(rDescriptor.mpPreviewProvider), + mpPageObjectProvider(rDescriptor.mpPageObjectProvider), + mnTemplateIndex(rDescriptor.mnTemplateIndex), + meURLClassification(rDescriptor.meURLClassification), + mnUseCount(rDescriptor.mnUseCount) +{ +} + + + + +MasterPageDescriptor::~MasterPageDescriptor (void) +{ +} + + + + +void MasterPageDescriptor::SetToken (MasterPageContainer::Token aToken) +{ + maToken = aToken; +} + + + + +Image MasterPageDescriptor::GetPreview (MasterPageContainer::PreviewSize eSize) +{ + if (eSize == MasterPageContainer::SMALL) + return maSmallPreview; + else + return maLargePreview; +} + + + + +::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > + MasterPageDescriptor::Update ( + const MasterPageDescriptor& rDescriptor) +{ + bool bDataChanged (false); + bool bIndexChanged (false); + bool bPreviewChanged (false); + + if (meOrigin==MasterPageContainer::UNKNOWN + && rDescriptor.meOrigin!=MasterPageContainer::UNKNOWN) + { + meOrigin = rDescriptor.meOrigin; + bIndexChanged = true; + } + + if (msURL.getLength()==0 && rDescriptor.msURL.getLength()!=0) + { + msURL = rDescriptor.msURL; + bDataChanged = true; + } + + if (msPageName.getLength()==0 && rDescriptor.msPageName.getLength()!=0) + { + msPageName = rDescriptor.msPageName; + bDataChanged = true; + } + + if (msStyleName.getLength()==0 && rDescriptor.msStyleName.getLength()!=0) + { + msStyleName = rDescriptor.msStyleName; + bDataChanged = true; + } + + if (mpPageObjectProvider.get()==NULL && rDescriptor.mpPageObjectProvider.get()!=NULL) + { + mpPageObjectProvider = rDescriptor.mpPageObjectProvider; + bDataChanged = true; + } + + if (mpPreviewProvider.get()==NULL && rDescriptor.mpPreviewProvider.get()!=NULL) + { + mpPreviewProvider = rDescriptor.mpPreviewProvider; + bPreviewChanged = true; + } + + if (mnTemplateIndex<0 && rDescriptor.mnTemplateIndex>=0) + { + mnTemplateIndex = rDescriptor.mnTemplateIndex; + bIndexChanged = true; + } + + // Prepare the list of event types that will be returned. + ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pResult; + if (bDataChanged || bIndexChanged || bPreviewChanged) + { + pResult.reset(new std::vector<MasterPageContainerChangeEvent::EventType>()); + if (bDataChanged) + pResult->push_back(MasterPageContainerChangeEvent::DATA_CHANGED); + if (bIndexChanged) + pResult->push_back(MasterPageContainerChangeEvent::INDEX_CHANGED); + if (bPreviewChanged) + pResult->push_back(MasterPageContainerChangeEvent::PREVIEW_CHANGED); + } + + return pResult; +} + + + + +bool MasterPageDescriptor::UpdatePageObject ( + sal_Int32 nCostThreshold, + SdDrawDocument* pDocument) +{ + bool bModified (false); + + // Update the page object when that is not yet known. + if (mpMasterPage == NULL + && mpPageObjectProvider.get()!=NULL + && (nCostThreshold<0 || mpPageObjectProvider->GetCostIndex()<=nCostThreshold)) + { + // Note that pDocument may be NULL. + + SdPage* pPage = (*mpPageObjectProvider)(pDocument); + if (meOrigin == MasterPageContainer::MASTERPAGE) + { + mpMasterPage = pPage; + if (mpMasterPage != NULL) + mpMasterPage->SetPrecious(mbIsPrecious); + } + else + { + // Master pages from templates are copied into the local document. + if (pDocument != NULL) + mpMasterPage = DocumentHelper::CopyMasterPageToLocalDocument(*pDocument,pPage); + mpSlide = DocumentHelper::GetSlideForMasterPage(mpMasterPage); + } + + if (mpMasterPage != NULL) + { + // Update page name and style name. + if (msPageName.getLength() == 0) + msPageName = mpMasterPage->GetName(); + msStyleName = mpMasterPage->GetName(); + + // Delete an existing substitution. The next request for a preview + // will create the real one. + maSmallPreview = Image(); + maLargePreview = Image(); + mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider()); + } + else + { + DBG_ASSERT(false, "UpdatePageObject: master page is NULL"); + } + + bModified = true; + } + + return bModified; +} + + + + +bool MasterPageDescriptor::UpdatePreview ( + sal_Int32 nCostThreshold, + const Size& rSmallSize, + const Size& rLargeSize, + ::sd::PreviewRenderer& rRenderer) +{ + bool bModified (false); + + // Update the preview when that is not yet known. + if (maLargePreview.GetSizePixel().Width()==0 + && mpPreviewProvider.get()!=NULL + && (nCostThreshold<0 || mpPreviewProvider->GetCostIndex()<=nCostThreshold)) + { + SdPage* pPage = mpSlide; + if (pPage == NULL) + { + pPage = mpMasterPage; + } + maLargePreview = (*mpPreviewProvider)( + rLargeSize.Width(), + pPage, + rRenderer); + if (maLargePreview.GetSizePixel().Width() > 0) + { + // Create the small preview by scaling the large one down. + maSmallPreview = rRenderer.ScaleBitmap( + maLargePreview.GetBitmapEx(), + rSmallSize.Width()); + // The large preview may not have the desired width. Scale it + // accrodingly. + if (maLargePreview.GetSizePixel().Width() != rLargeSize.Width()) + maLargePreview = rRenderer.ScaleBitmap( + maLargePreview.GetBitmapEx(), + rLargeSize.Width()); + bModified = true; + } + } + + return bModified; +} + + + + +MasterPageDescriptor::URLClassification MasterPageDescriptor::GetURLClassification (void) +{ + if (meURLClassification == URLCLASS_UNDETERMINED) + { + if (msURL.getLength() == 0) + meURLClassification = URLCLASS_UNKNOWN; + else if (msURL.indexOf(::rtl::OUString::createFromAscii("presnt"))>=0) + { + meURLClassification = URLCLASS_PRESENTATION; + } + else if (msURL.indexOf(::rtl::OUString::createFromAscii("layout"))>=0) + { + meURLClassification = URLCLASS_LAYOUT; + } + else if (msURL.indexOf(::rtl::OUString::createFromAscii("educate"))>=0) + { + meURLClassification = URLCLASS_OTHER; + } + else + { + meURLClassification = URLCLASS_USER; + } + } + + return meURLClassification; +} + + + +//===== URLComparator ========================================================= + +MasterPageDescriptor::URLComparator::URLComparator (const ::rtl::OUString& sURL) + : msURL(sURL) +{ +} + + + + +bool MasterPageDescriptor::URLComparator::operator() ( + const SharedMasterPageDescriptor& rDescriptor) +{ + if (rDescriptor.get() == NULL) + return false; + else + return rDescriptor->msURL.equals(msURL); +} + + + + +// ===== StyleNameComparator ================================================== + +MasterPageDescriptor::StyleNameComparator::StyleNameComparator (const ::rtl::OUString& sStyleName) + : msStyleName(sStyleName) +{ +} + + + + +bool MasterPageDescriptor::StyleNameComparator::operator() ( + const SharedMasterPageDescriptor& rDescriptor) +{ + if (rDescriptor.get() == NULL) + return false; + else + return rDescriptor->msStyleName.equals(msStyleName); +} + + + + +//===== PageObjectComparator ================================================== + +MasterPageDescriptor::PageObjectComparator::PageObjectComparator (const SdPage* pPageObject) + : mpMasterPage(pPageObject) +{ +} + + + + +bool MasterPageDescriptor::PageObjectComparator::operator() ( + const SharedMasterPageDescriptor& rDescriptor) +{ + if (rDescriptor.get() == NULL) + return false; + else + return rDescriptor->mpMasterPage==mpMasterPage; +} + + + + +//===== AllComparator ========================================================= + +MasterPageDescriptor::AllComparator::AllComparator(const SharedMasterPageDescriptor& rDescriptor) + : mpDescriptor(rDescriptor) +{ +} + + + + +bool MasterPageDescriptor::AllComparator::operator() (const SharedMasterPageDescriptor&rDescriptor) +{ + if (rDescriptor.get() == NULL) + return false; + else + { + // Take URL, page name, style name, and page object into account + // when comparing two descriptors. When two descriptors are + // identical in any of these values then their are thought of as + // equivalent. Only the Origin has to be the same in both + // descriptors. + return + mpDescriptor->meOrigin == rDescriptor->meOrigin + && ( + (mpDescriptor->msURL.getLength()>0 + && mpDescriptor->msURL.equals(rDescriptor->msURL)) + || (mpDescriptor->msPageName.getLength()>0 + && mpDescriptor->msPageName.equals(rDescriptor->msPageName)) + || (mpDescriptor->msStyleName.getLength()>0 + && mpDescriptor->msStyleName.equals(rDescriptor->msStyleName)) + || (mpDescriptor->mpMasterPage!=NULL + && mpDescriptor->mpMasterPage==rDescriptor->mpMasterPage) + || (mpDescriptor->mpPageObjectProvider.get()!=NULL + && rDescriptor->mpPageObjectProvider.get()!=NULL + && mpDescriptor->mpPageObjectProvider==rDescriptor->mpPageObjectProvider)); + } +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPageDescriptor.hxx b/sd/source/ui/sidebar/MasterPageDescriptor.hxx new file mode 100644 index 000000000000..a3f3b73c9551 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageDescriptor.hxx @@ -0,0 +1,234 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX + +#include "MasterPageContainer.hxx" +#include <boost/shared_ptr.hpp> + +namespace sd { namespace sidebar { + +class PageObjectProvider; +class PreviewProvider; + +class MasterPageDescriptor; +typedef ::boost::shared_ptr<MasterPageDescriptor> SharedMasterPageDescriptor; + +/** A collection of data that is stored for every master page in the + MasterpageContainer. +*/ +class MasterPageDescriptor +{ +public: + MasterPageDescriptor ( + MasterPageContainer::Origin eOrigin, + const sal_Int32 nTemplateIndex, + const String& rURL, + const String& rPageName, + const String& rStyleName, + const bool bIsPrecious, + const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider, + const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider); + MasterPageDescriptor (const MasterPageDescriptor& rDescriptor); + ~MasterPageDescriptor (void); + + void SetToken (MasterPageContainer::Token aToken); + + /** Update the called MasterPageDescriptor object with values from the + given one. Only those values are updated that have default values + in the called object and that have non-default values in the given + one. + @return + Returns a list of event types for which event notifications have + to be sent to listeners. The list may be empty or NULL. + */ + ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > + Update ( + const MasterPageDescriptor& rDescriptor); + + /** This convenience method returns either a small or a large preview, + depending on the given size specifier. + Note that the previews are not created when they are not present. + @return + The returned preview may be empty. + */ + Image GetPreview (MasterPageContainer::PreviewSize ePreviewSize); + + /** Use the PreviewProvider to get access to a preview of the master + page. + + Note that this is only done, when either bForce is <TRUE/> or + the PreviewProvider::GetCostIndex() returns 0. + + The small preview is created by scaling the large one, not by + calling PreviewProvider::operator() a second time. + + It is the responsibility of the caller to call UpdatePageObject() + before calling this method when the PreviewProvider can only work + when the master page object is present, i.e. its NeedsPageObject() + method returns <TRUE/>. + + @param nCostThreshold + When this is zero or positive then the preview is created only + when the preview provider has a cost equal to or smaller than + this threshold. A negative value forces the preview to be + created, regardless of the cost. + @param rSmallSize + Size of the small preview. + @param rLargeSize + Size of the large preview. + @param rRenderer + A PreviewRenderer object that may be used to create a preview. + @return + When the previews are successfully provided then <TRUE/> is + returned. + */ + bool UpdatePreview ( + sal_Int32 nCostThreshold, + const Size& rSmallSize, + const Size& rLargeSize, + ::sd::PreviewRenderer& rRenderer); + + /** Use the PageObjectProvider to get access to the master page object. + + Note that this is only done, when either bForce is <TRUE/> or the + PreviewProvider::GetCostIndex() returns 0. + + @param nCostThreshold + When this is zero or positive then the page object is created + only when the page object provider has a cost equal to or + smaller than this threshold. A negative value forces the + page object be created, regardless of the cost. + @param pDocument + This document of the MasterPageContainer may be used to create + a page object with or store one in. + @return + When the master page object is successfully provided then + <TRUE/> is returned. + */ + bool UpdatePageObject ( + sal_Int32 nCostThreshold, + SdDrawDocument* pDocument); + + enum URLClassification { + URLCLASS_USER, + URLCLASS_LAYOUT, + URLCLASS_PRESENTATION, + URLCLASS_OTHER, + URLCLASS_UNKNOWN, + URLCLASS_UNDETERMINED + }; + + URLClassification GetURLClassification (void); + + /** The Token under which the MasterPageContainer gives access to the + object. + */ + MasterPageContainer::Token maToken; + + /** A rough specification of the origin of the master page. + */ + MasterPageContainer::Origin meOrigin; + + /** The URL is not empty for master pages loaded from a template + document. + */ + ::rtl::OUString msURL; + + /** Taken from the title of the template file. + */ + ::rtl::OUString msPageName; + + /** Taken from the master page object. + */ + ::rtl::OUString msStyleName; + + const bool mbIsPrecious; + + /** The actual master page. + */ + SdPage* mpMasterPage; + + /** A slide that uses the master page. + */ + SdPage* mpSlide; + + /** A small (the default size) preview of the master page. May be + empty. When this smaller preview is not empty then the larger one + is not empty, too. + */ + Image maSmallPreview; + + /** A large preview of the master page. May be empty. When this larger + preview is not empty then the smaller one is not empty, too. + */ + Image maLargePreview; + + /** The prewview provider. May be empty. May be replaced during the + lifetime of a MasterPageDescriptor object. + */ + ::boost::shared_ptr<PreviewProvider> mpPreviewProvider; + + /** The master page provider. May be empty. May be replaced during + the lifetime of a MasterPageDescriptor object. + */ + ::boost::shared_ptr<PageObjectProvider> mpPageObjectProvider; + + /** This index represents the order in which templates are provided via + the TemplateScanner. It defines the order in which the entries in + the AllMasterPagesSelector are displayed. The default value is -1. + */ + sal_Int32 mnTemplateIndex; + + URLClassification meURLClassification; + + sal_Int32 mnUseCount; + + class URLComparator { public: + ::rtl::OUString msURL; + URLComparator (const ::rtl::OUString& sURL); + bool operator() (const SharedMasterPageDescriptor& rDescriptor); + }; + class StyleNameComparator { public: + ::rtl::OUString msStyleName; + StyleNameComparator (const ::rtl::OUString& sStyleName); + bool operator() (const SharedMasterPageDescriptor& rDescriptor); + }; + class PageObjectComparator { public: + const SdPage* mpMasterPage; + PageObjectComparator (const SdPage* pPageObject); + bool operator() (const SharedMasterPageDescriptor& rDescriptor); + }; + class AllComparator { public: + AllComparator(const SharedMasterPageDescriptor& rDescriptor); + bool operator() (const SharedMasterPageDescriptor& rDescriptor); + private: + SharedMasterPageDescriptor mpDescriptor; + }; + + +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/MasterPageObserver.cxx b/sd/source/ui/sidebar/MasterPageObserver.cxx new file mode 100644 index 000000000000..328493a91f24 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPageObserver.cxx @@ -0,0 +1,419 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPageObserver.hxx" + +#include <algorithm> +#include "drawdoc.hxx" +#include "sdpage.hxx" +#include <hash_map> +#include <set> +#include <vector> +#include <svl/lstner.hxx> +#include <osl/doublecheckedlocking.h> +#include <osl/getglobalmutex.hxx> + + +namespace sd { + +class MasterPageObserver::Implementation + : public SfxListener +{ +public: + /** The single instance of this class. It is created on demand when + Instance() is called for the first time. + */ + static MasterPageObserver* mpInstance; + + /** The master page observer will listen to events of this document and + detect changes of the use of master pages. + */ + void RegisterDocument (SdDrawDocument& rDocument); + + /** The master page observer will stop to listen to events of this + document. + */ + void UnregisterDocument (SdDrawDocument& rDocument); + + /** Add a listener that is informed of master pages that are newly + assigned to slides or become unassigned. + @param rEventListener + The event listener to call for future events. Call + RemoveEventListener() before the listener is destroyed. + */ + void AddEventListener (const Link& rEventListener); + + /** Remove the given listener from the list of listeners. + @param rEventListener + After this method returns the given listener is not called back + from this object. Passing a listener that has not + been registered before is safe and is silently ignored. + */ + void RemoveEventListener (const Link& rEventListener); + + /** Return a set of the names of master pages for the given document. + This convenience method exists because this set is part of the + internal data structure and thus takes no time to create. + */ + inline MasterPageObserver::MasterPageNameSet GetMasterPageNames ( + SdDrawDocument& rDocument); + +private: + ::std::vector<Link> maListeners; + + struct DrawDocHash { + size_t operator()(SdDrawDocument* argument) const + { return reinterpret_cast<unsigned long>(argument); } + }; + typedef ::std::hash_map<SdDrawDocument*, + MasterPageObserver::MasterPageNameSet, + DrawDocHash> + MasterPageContainer; + MasterPageContainer maUsedMasterPages; + + virtual void Notify( + SfxBroadcaster& rBroadcaster, + const SfxHint& rHint); + + void AnalyzeUsedMasterPages (SdDrawDocument& rDocument); + + void SendEvent (MasterPageObserverEvent& rEvent); +}; + +MasterPageObserver* MasterPageObserver::Implementation::mpInstance = NULL; + + + +//===== MasterPageObserver ==================================================== + +MasterPageObserver& MasterPageObserver::Instance (void) +{ + if (Implementation::mpInstance == NULL) + { + ::osl::GetGlobalMutex aMutexFunctor; + ::osl::MutexGuard aGuard (aMutexFunctor()); + if (Implementation::mpInstance == NULL) + { + MasterPageObserver* pInstance = new MasterPageObserver (); + SdGlobalResourceContainer::Instance().AddResource ( + ::std::auto_ptr<SdGlobalResource>(pInstance)); + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + Implementation::mpInstance = pInstance; + } + } + else + { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + } + + DBG_ASSERT(Implementation::mpInstance!=NULL, + "MasterPageObserver::Instance(): instance is NULL"); + return *Implementation::mpInstance; +} + + + + +void MasterPageObserver::RegisterDocument (SdDrawDocument& rDocument) +{ + mpImpl->RegisterDocument (rDocument); +} + + + + +void MasterPageObserver::UnregisterDocument (SdDrawDocument& rDocument) +{ + mpImpl->UnregisterDocument (rDocument); +} + + + + +void MasterPageObserver::AddEventListener (const Link& rEventListener) +{ + + mpImpl->AddEventListener (rEventListener); +} + + + + +void MasterPageObserver::RemoveEventListener (const Link& rEventListener) +{ + mpImpl->RemoveEventListener (rEventListener); +} + + + + +MasterPageObserver::MasterPageObserver (void) + : mpImpl (new Implementation()) +{} + + + + +MasterPageObserver::~MasterPageObserver (void) +{} + + + + +//===== MasterPageObserver::Implementation ==================================== + +void MasterPageObserver::Implementation::RegisterDocument ( + SdDrawDocument& rDocument) +{ + // Gather the names of all the master pages in the given document. + MasterPageContainer::data_type aMasterPageSet; + sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PK_STANDARD); + for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++) + { + SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PK_STANDARD); + if (pMasterPage != NULL) + aMasterPageSet.insert (pMasterPage->GetName()); + } + + maUsedMasterPages[&rDocument] = aMasterPageSet; + + StartListening (rDocument); +} + + + + +void MasterPageObserver::Implementation::UnregisterDocument ( + SdDrawDocument& rDocument) +{ + EndListening (rDocument); + + MasterPageContainer::iterator aMasterPageDescriptor(maUsedMasterPages.find(&rDocument)); + if(aMasterPageDescriptor != maUsedMasterPages.end()) + maUsedMasterPages.erase(aMasterPageDescriptor); +} + + + + +void MasterPageObserver::Implementation::AddEventListener ( + const Link& rEventListener) +{ + if (::std::find ( + maListeners.begin(), + maListeners.end(), + rEventListener) == maListeners.end()) + { + maListeners.push_back (rEventListener); + + // Tell the new listener about all the master pages that are + // currently in use. + typedef ::std::vector<String> StringList; + StringList aNewMasterPages; + StringList aRemovedMasterPages; + MasterPageContainer::iterator aDocumentIterator; + for (aDocumentIterator=maUsedMasterPages.begin(); + aDocumentIterator!=maUsedMasterPages.end(); + ++aDocumentIterator) + { + ::std::set<String>::reverse_iterator aNameIterator; + for (aNameIterator=aDocumentIterator->second.rbegin(); + aNameIterator!=aDocumentIterator->second.rend(); + ++aNameIterator) + { + MasterPageObserverEvent aEvent ( + MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS, + *aDocumentIterator->first, + *aNameIterator); + SendEvent (aEvent); + } + } + } +} + + + + +void MasterPageObserver::Implementation::RemoveEventListener ( + const Link& rEventListener) +{ + maListeners.erase ( + ::std::find ( + maListeners.begin(), + maListeners.end(), + rEventListener)); +} + + + + +MasterPageObserver::MasterPageNameSet + MasterPageObserver::Implementation::GetMasterPageNames ( + SdDrawDocument& rDocument) +{ + MasterPageContainer::iterator aMasterPageDescriptor ( + maUsedMasterPages.find(&rDocument)); + if (aMasterPageDescriptor != maUsedMasterPages.end()) + return aMasterPageDescriptor->second; + else + // Not found so return an empty set. + return MasterPageObserver::MasterPageNameSet(); +} + + + + +void MasterPageObserver::Implementation::Notify( + SfxBroadcaster& rBroadcaster, + const SfxHint& rHint) +{ + if (rHint.ISA(SdrHint)) + { + SdrHint& rSdrHint (*PTR_CAST(SdrHint,&rHint)); + switch (rSdrHint.GetKind()) + { + case HINT_PAGEORDERCHG: + // Process the modified set of pages only when the number of + // standard and notes master pages are equal. This test + // filters out events that are sent in between the insertion + // of a new standard master page and a new notes master + // page. + if (rBroadcaster.ISA(SdDrawDocument)) + { + SdDrawDocument& rDocument ( + static_cast<SdDrawDocument&>(rBroadcaster)); + if (rDocument.GetMasterSdPageCount(PK_STANDARD) + == rDocument.GetMasterSdPageCount(PK_NOTES)) + { + AnalyzeUsedMasterPages (rDocument); + } + } + break; + + default: + break; + } + } +} + + + + +void MasterPageObserver::Implementation::AnalyzeUsedMasterPages ( + SdDrawDocument& rDocument) +{ + // Create a set of names of the master pages used by the given document. + sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PK_STANDARD); + ::std::set<String> aCurrentMasterPages; + for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++) + { + SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PK_STANDARD); + if (pMasterPage != NULL) + aCurrentMasterPages.insert (pMasterPage->GetName()); + OSL_TRACE("currently used master page %d is %s", + nIndex, + ::rtl::OUStringToOString(pMasterPage->GetName(), + RTL_TEXTENCODING_UTF8).getStr()); + } + + typedef ::std::vector<String> StringList; + StringList aNewMasterPages; + StringList aRemovedMasterPages; + MasterPageContainer::iterator aOldMasterPagesDescriptor ( + maUsedMasterPages.find(&rDocument)); + if (aOldMasterPagesDescriptor != maUsedMasterPages.end()) + { + StringList::iterator I; + + ::std::set<String>::iterator J; + int i=0; + for (J=aOldMasterPagesDescriptor->second.begin(); + J!=aOldMasterPagesDescriptor->second.end(); + ++J) + OSL_TRACE("old used master page %d is %s", + i++, + ::rtl::OUStringToOString(*J, + RTL_TEXTENCODING_UTF8).getStr()); + + // Send events about the newly used master pages. + ::std::set_difference ( + aCurrentMasterPages.begin(), + aCurrentMasterPages.end(), + aOldMasterPagesDescriptor->second.begin(), + aOldMasterPagesDescriptor->second.end(), + ::std::back_insert_iterator<StringList>(aNewMasterPages)); + for (I=aNewMasterPages.begin(); I!=aNewMasterPages.end(); ++I) + { + OSL_TRACE(" added master page %s", + ::rtl::OUStringToOString(*I, + RTL_TEXTENCODING_UTF8).getStr()); + + MasterPageObserverEvent aEvent ( + MasterPageObserverEvent::ET_MASTER_PAGE_ADDED, + rDocument, + *I); + SendEvent (aEvent); + } + + // Send events about master pages that are not used any longer. + ::std::set_difference ( + aOldMasterPagesDescriptor->second.begin(), + aOldMasterPagesDescriptor->second.end(), + aCurrentMasterPages.begin(), + aCurrentMasterPages.end(), + ::std::back_insert_iterator<StringList>(aRemovedMasterPages)); + for (I=aRemovedMasterPages.begin(); I!=aRemovedMasterPages.end(); ++I) + { + OSL_TRACE(" removed master page %s", + ::rtl::OUStringToOString(*I, + RTL_TEXTENCODING_UTF8).getStr()); + + MasterPageObserverEvent aEvent ( + MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED, + rDocument, + *I); + SendEvent (aEvent); + } + + // Store the new list of master pages. + aOldMasterPagesDescriptor->second = aCurrentMasterPages; + } +} + + + + +void MasterPageObserver::Implementation::SendEvent ( + MasterPageObserverEvent& rEvent) +{ + ::std::vector<Link>::iterator aLink (maListeners.begin()); + ::std::vector<Link>::iterator aEnd (maListeners.end()); + while (aLink!=aEnd) + { + aLink->Call (&rEvent); + ++aLink; + } +} + + +} // end of namespace sd diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx new file mode 100644 index 000000000000..694ee21b404b --- /dev/null +++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx @@ -0,0 +1,849 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "MasterPagesSelector.hxx" + +#include "MasterPageContainer.hxx" +#include "DocumentHelper.hxx" +#include "SidebarShellManager.hxx" +#include "pres.hxx" +#include "drawdoc.hxx" +#include "DrawDocShell.hxx" +#include "sdpage.hxx" +#include "glob.hxx" +#include "glob.hrc" +#include "app.hrc" +#include "res_bmp.hrc" +#include "strings.hrc" +#include "DrawViewShell.hxx" +#include "DrawController.hxx" +#include "SlideSorterViewShell.hxx" +#include "PreviewValueSet.hxx" +#include "ViewShellBase.hxx" +#include <sfx2/objface.hxx> +#include "sdresid.hxx" +#include "drawview.hxx" +#include <vcl/image.hxx> +#include <vcl/floatwin.hxx> +#include <svl/languageoptions.hxx> +#include <sfx2/app.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/mnumgr.hxx> +#include <svl/itemset.hxx> +#include <svl/eitem.hxx> +#include <svx/dlgutil.hxx> +#include <svx/svdpagv.hxx> +#include <svx/svxids.hrc> +#include "FrameView.hxx" +#include "sdpage.hxx" +#include "stlpool.hxx" +#include "unmovss.hxx" +#include <sfx2/request.hxx> +#include <svl/itempool.hxx> +#include <sfx2/sidebar/Theme.hxx> + + +using namespace ::com::sun::star::text; + + + +namespace sd { namespace sidebar { + + +MasterPagesSelector::MasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) + : PreviewValueSet(pParent), + maMutex(), + mpContainer(rpContainer), + mrDocument(rDocument), + mrBase(rBase), + mnDefaultClickAction(SID_TP_APPLY_TO_ALL_SLIDES), + maPreviewUpdateQueue(), + maCurrentItemList(), + maTokenToValueSetIndex(), + maLockedMasterPages(), + mxSidebar(rxSidebar) +{ + PreviewValueSet::SetSelectHdl ( + LINK(this, MasterPagesSelector, ClickHandler)); + PreviewValueSet::SetRightMouseClickHandler ( + LINK(this, MasterPagesSelector, RightClickHandler)); + PreviewValueSet::SetStyle(PreviewValueSet::GetStyle() | WB_NO_DIRECTSELECT); + PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel()); + PreviewValueSet::Show(); + + SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground)); + SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground)); + + Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener)); + mpContainer->AddChangeListener(aChangeListener); +} + + + + +MasterPagesSelector::~MasterPagesSelector (void) +{ + Clear(); + UpdateLocks(ItemList()); + + Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener)); + mpContainer->RemoveChangeListener(aChangeListener); +} + + + + +void MasterPagesSelector::LateInit (void) +{ +} + + + + +sal_Int32 MasterPagesSelector::GetPreferredWidth (sal_Int32 nHeight) +{ + const ::osl::MutexGuard aGuard (maMutex); + + return PreviewValueSet::GetPreferredWidth (nHeight); +} + + + + +sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth) +{ + const ::osl::MutexGuard aGuard (maMutex); + + return PreviewValueSet::GetPreferredHeight (nWidth); +} + + + + +Size MasterPagesSelector::GetPreferredSize (void) +{ + int nPreferredWidth = GetPreferredWidth( + PreviewValueSet::GetOutputSizePixel().Height()); + int nPreferredHeight = GetPreferredHeight(nPreferredWidth); + return Size (nPreferredWidth, nPreferredHeight); + +} + + + + +void MasterPagesSelector::UpdateLocks (const ItemList& rItemList) +{ + ItemList aNewLockList; + + // In here we first lock the master pages in the given list and then + // release the locks acquired in a previous call to this method. When + // this were done the other way round the lock count of some master + // pages might drop temporarily to 0 and would lead to unnecessary + // deletion and re-creation of MasterPageDescriptor objects. + + // Lock the master pages in the given list. + ItemList::const_iterator iItem; + for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem) + { + mpContainer->AcquireToken(*iItem); + aNewLockList.push_back(*iItem); + } + + // Release the previously locked master pages. + ItemList::const_iterator iPage; + ItemList::const_iterator iEnd (maLockedMasterPages.end()); + for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage) + mpContainer->ReleaseToken(*iPage); + + maLockedMasterPages.swap(aNewLockList); +} + + + + +void MasterPagesSelector::Fill (void) +{ + ::std::auto_ptr<ItemList> pItemList (new ItemList()); + + Fill(*pItemList); + + UpdateLocks(*pItemList); + UpdateItemList(pItemList); +} + + + + +ResId MasterPagesSelector::GetContextMenuResId (void) const +{ + return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP); +} + + + + +IMPL_LINK(MasterPagesSelector, ClickHandler, PreviewValueSet*, EMPTYARG) +{ + // We use the framework to assign the clicked-on master page because we + // so use the same mechanism as the context menu does (where we do not + // have the option to call the assignment method directly.) + ExecuteCommand(mnDefaultClickAction); + + return 0; +} + + + + +IMPL_LINK(MasterPagesSelector, RightClickHandler, MouseEvent*, pEvent) +{ + // Here we only prepare the display of the context menu: the item under + // the mouse is selected. The actual display of the context menu is + // done in ContextMenuCallback which is called indirectly through + // PreviewValueSet::Command(). + PreviewValueSet::GrabFocus (); + PreviewValueSet::ReleaseMouse(); + SfxViewFrame* pViewFrame = mrBase.GetViewFrame(); + if (pViewFrame != NULL) + { + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + if (pDispatcher != NULL && pEvent != NULL) + { + sal_uInt16 nIndex = PreviewValueSet::GetItemId (pEvent->GetPosPixel()); + if (nIndex > 0) + PreviewValueSet::SelectItem (nIndex); + } + } + return 0; +} + + + + +void MasterPagesSelector::Command (const CommandEvent& rEvent) +{ + switch (rEvent.GetCommand()) + { + case COMMAND_CONTEXTMENU: + { + // Use the currently selected item and show the popup menu in its + // center. + const sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId(); + if (nIndex > 0) + { + // The position of the upper left corner of the context menu is + // taken either from the mouse position (when the command was sent + // as reaction to a right click) or in the center of the selected + // item (when the command was sent as reaction to Shift+F10.) + Point aPosition (rEvent.GetMousePosPixel()); + if ( ! rEvent.IsMouseEvent()) + { + Rectangle aBBox (PreviewValueSet::GetItemRect(nIndex)); + aPosition = aBBox.Center(); + } + + // Setup the menu. + ::boost::scoped_ptr<PopupMenu> pMenu (new PopupMenu(GetContextMenuResId())); + FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); + if (pMenuWindow != NULL) + pMenuWindow->SetPopupModeFlags( + pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); + pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected)); + + ProcessPopupMenu(*pMenu); + + // Show the menu. + pMenu->Execute(this, Rectangle(aPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN); + } + break; + } + } +} + + + + +void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu) +{ + // Disable some entries. + if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL) + rMenu.EnableItem(SID_TP_SHOW_SMALL_PREVIEW, sal_False); + else + rMenu.EnableItem(SID_TP_SHOW_LARGE_PREVIEW, sal_False); +} + + + + +IMPL_LINK(MasterPagesSelector, OnMenuItemSelected, Menu*, pMenu) +{ + if (pMenu == NULL) + { + OSL_ENSURE(pMenu!=NULL, "MasterPagesSelector::OnMenuItemSelected: illegal menu!"); + return 0; + } + + pMenu->Deactivate(); + ExecuteCommand(pMenu->GetCurItemId()); + return 0; +} + + + + +void MasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId) +{ + switch (nCommandId) + { + case SID_TP_APPLY_TO_ALL_SLIDES: + mrBase.SetBusyState (true); + AssignMasterPageToAllSlides (GetSelectedMasterPage()); + mrBase.SetBusyState (false); + break; + + case SID_TP_APPLY_TO_SELECTED_SLIDES: + mrBase.SetBusyState (true); + AssignMasterPageToSelectedSlides (GetSelectedMasterPage()); + mrBase.SetBusyState (false); + break; + + case SID_TP_USE_FOR_NEW_PRESENTATIONS: + DBG_ASSERT (false, + "Using slides as default for new presentations" + " is not yet implemented"); + break; + + case SID_TP_SHOW_SMALL_PREVIEW: + case SID_TP_SHOW_LARGE_PREVIEW: + { + mrBase.SetBusyState (true); + mpContainer->SetPreviewSize( + nCommandId==SID_TP_SHOW_SMALL_PREVIEW + ? MasterPageContainer::SMALL + : MasterPageContainer::LARGE); + mrBase.SetBusyState (false); + if (mxSidebar.is()) + mxSidebar->requestLayout(); + break; + } + + case SID_TP_EDIT_MASTER: + { + using namespace ::com::sun::star; + uno::Reference<drawing::XDrawPage> xSelectedMaster ( + GetSelectedMasterPage()->getUnoPage(), uno::UNO_QUERY); + SfxViewFrame* pViewFrame = mrBase.GetViewFrame(); + if (pViewFrame != NULL && xSelectedMaster.is()) + { + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + if (pDispatcher != NULL) + { + sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId(); + pDispatcher->Execute(SID_MASTERPAGE, SFX_CALLMODE_SYNCHRON); + PreviewValueSet::SelectItem (nIndex); + mrBase.GetDrawController().setCurrentPage(xSelectedMaster); + } + } + break; + } + + case SID_CUT: + case SID_COPY: + case SID_PASTE: + // Cut, copy, and paste are not supported and thus are ignored. + break; + } +} + + + + +IMPL_LINK(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent*, pEvent) +{ + if (pEvent) + NotifyContainerChangeEvent(*pEvent); + return 0; +} + + + + +SdPage* MasterPagesSelector::GetSelectedMasterPage (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + SdPage* pMasterPage = NULL; + sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId(); + UserData* pData = GetUserData(nIndex); + if (pData != NULL) + { + pMasterPage = mpContainer->GetPageObjectForToken(pData->second); + } + return pMasterPage; +} + + + + +/** Assemble a list of all slides of the document and pass it to + AssignMasterPageToPageList(). +*/ +void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage) +{ + do + { + if (pMasterPage == NULL) + break; + + sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD); + if (nPageCount == 0) + break; + + // Get a list of all pages. As a little optimization we only + // include pages that do not already have the given master page + // assigned. + String sFullLayoutName (pMasterPage->GetLayoutName()); + ::sd::slidesorter::SharedPageSelection pPageList ( + new ::sd::slidesorter::SlideSorterViewShell::PageSelection()); + for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++) + { + SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD); + if (pPage != NULL + && pPage->GetLayoutName().CompareTo(sFullLayoutName)!=0) + { + pPageList->push_back (pPage); + } + } + + AssignMasterPageToPageList(pMasterPage, pPageList); + } + while (false); +} + + + + +/** Assemble a list of the currently selected slides (selected in a visible + slide sorter) and pass it to AssignMasterPageToPageList(). +*/ +void MasterPagesSelector::AssignMasterPageToSelectedSlides ( + SdPage* pMasterPage) +{ + do + { + using namespace ::std; + using namespace ::sd::slidesorter; + using namespace ::sd::slidesorter::controller; + + if (pMasterPage == NULL) + break; + + // Find a visible slide sorter. + SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase); + if (pSlideSorter == NULL) + break; + + // Get a list of selected pages. + ::sd::slidesorter::SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection(); + if (pPageSelection->empty()) + break; + + AssignMasterPageToPageList(pMasterPage, pPageSelection); + + // Restore the previous selection. + pSlideSorter->SetPageSelection(pPageSelection); + } + while (false); +} + + + + +void MasterPagesSelector::AssignMasterPageToPageList ( + SdPage* pMasterPage, + const ::sd::slidesorter::SharedPageSelection& rPageList) +{ + DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList); +} + + + + +void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent) +{ + const ::osl::MutexGuard aGuard (maMutex); + + switch (rEvent.meEventType) + { + case MasterPageContainerChangeEvent::SIZE_CHANGED: + PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel()); + UpdateAllPreviews(); + break; + + case MasterPageContainerChangeEvent::PREVIEW_CHANGED: + { + int nIndex (GetIndexForToken(rEvent.maChildToken)); + if (nIndex >= 0) + { + PreviewValueSet::SetItemImage ( + (sal_uInt16)nIndex, + mpContainer->GetPreviewForToken(rEvent.maChildToken)); + PreviewValueSet::Invalidate(PreviewValueSet::GetItemRect((sal_uInt16)nIndex)); + } + } + break; + + case MasterPageContainerChangeEvent::DATA_CHANGED: + { + InvalidateItem(rEvent.maChildToken); + Fill(); + } + break; + + default: + break; + } +} + + + + +MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData ( + int nIndex, + MasterPageContainer::Token aToken) const +{ + return new UserData(nIndex,aToken); +} + + + + +MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const +{ + const ::osl::MutexGuard aGuard (maMutex); + + if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount()) + return reinterpret_cast<UserData*>(PreviewValueSet::GetItemData((sal_uInt16)nIndex)); + else + return NULL; +} + + + + +void MasterPagesSelector::SetUserData (int nIndex, UserData* pData) +{ + const ::osl::MutexGuard aGuard (maMutex); + + if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount()) + { + UserData* pOldData = GetUserData(nIndex); + if (pOldData!=NULL && pOldData!=pData) + delete pOldData; + PreviewValueSet::SetItemData((sal_uInt16)nIndex, pData); + } +} + + + + +bool MasterPagesSelector::IsResizable (void) +{ + return false; +} + + + + +::Window* MasterPagesSelector::GetWindow (void) +{ + return this; +} + + + + +sal_Int32 MasterPagesSelector::GetMinimumWidth (void) +{ + return mpContainer->GetPreviewSizePixel().Width() + 2*3; +} + + + + +void MasterPagesSelector::UpdateSelection (void) +{ +} + + + + +void MasterPagesSelector::SetItem ( + sal_uInt16 nIndex, + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (maMutex); + + RemoveTokenToIndexEntry(nIndex,aToken); + + if (nIndex > 0) + { + if (aToken != MasterPageContainer::NIL_TOKEN) + { + Image aPreview (mpContainer->GetPreviewForToken(aToken)); + MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken)); + + if (aPreview.GetSizePixel().Width()>0) + { + if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND) + { + PreviewValueSet::SetItemImage(nIndex,aPreview); + PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken)); + } + else + { + PreviewValueSet::InsertItem ( + nIndex, + aPreview, + mpContainer->GetPageNameForToken(aToken), + nIndex); + } + SetUserData(nIndex, CreateUserData(nIndex,aToken)); + + AddTokenToIndexEntry(nIndex,aToken); + } + + if (eState == MasterPageContainer::PS_CREATABLE) + mpContainer->RequestPreview(aToken); + } + else + { + PreviewValueSet::RemoveItem(nIndex); + } + } + +} + + + + +void MasterPagesSelector::AddTokenToIndexEntry ( + sal_uInt16 nIndex, + MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (maMutex); + + maTokenToValueSetIndex[aToken] = nIndex; +} + + + + +void MasterPagesSelector::RemoveTokenToIndexEntry ( + sal_uInt16 nIndex, + MasterPageContainer::Token aNewToken) +{ + const ::osl::MutexGuard aGuard (maMutex); + + UserData* pData = GetUserData(nIndex); + if (pData != NULL) + { + // Get the token that the index pointed to previously. + MasterPageContainer::Token aOldToken (pData->second); + + if (aNewToken != aOldToken + && nIndex == GetIndexForToken(aOldToken)) + { + maTokenToValueSetIndex[aOldToken] = 0; + } + } +} + + + + +void MasterPagesSelector::InvalidatePreview (const SdPage* pPage) +{ + const ::osl::MutexGuard aGuard (maMutex); + + for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++) + { + UserData* pData = GetUserData(nIndex); + if (pData != NULL) + { + MasterPageContainer::Token aToken (pData->second); + if (pPage == mpContainer->GetPageObjectForToken(aToken,false)) + { + mpContainer->InvalidatePreview(aToken); + mpContainer->RequestPreview(aToken); + break; + } + } + } +} + +void MasterPagesSelector::UpdateAllPreviews (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++) + { + UserData* pData = GetUserData(nIndex); + if (pData != NULL) + { + MasterPageContainer::Token aToken (pData->second); + PreviewValueSet::SetItemImage( + nIndex, + mpContainer->GetPreviewForToken(aToken)); + if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE) + mpContainer->RequestPreview(aToken); + } + } + PreviewValueSet::Rearrange(true); +} + + + + +void MasterPagesSelector::ClearPageSet (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++) + { + UserData* pData = GetUserData(nIndex); + if (pData != NULL) + delete pData; + } + PreviewValueSet::Clear(); +} + + + + +void MasterPagesSelector::SetHelpId( const rtl::OString& aId ) +{ + const ::osl::MutexGuard aGuard (maMutex); + + PreviewValueSet::SetHelpId( aId ); +} + + + + +sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const +{ + const ::osl::MutexGuard aGuard (maMutex); + + TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken)); + if (iIndex != maTokenToValueSetIndex.end()) + return iIndex->second; + else + return -1; +} + + + + +void MasterPagesSelector::Clear (void) +{ + const ::osl::MutexGuard aGuard (maMutex); + + ClearPageSet(); +} + + + + +void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken) +{ + const ::osl::MutexGuard aGuard (maMutex); + + ItemList::iterator iItem; + for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem) + { + if (*iItem == aToken) + { + *iItem = MasterPageContainer::NIL_TOKEN; + break; + } + } +} + + + + +void MasterPagesSelector::UpdateItemList (::std::auto_ptr<ItemList> pNewItemList) +{ + const ::osl::MutexGuard aGuard (maMutex); + + ItemList::const_iterator iNewItem (pNewItemList->begin()); + ItemList::const_iterator iCurrentItem (maCurrentItemList.begin()); + ItemList::const_iterator iNewEnd (pNewItemList->end()); + ItemList::const_iterator iCurrentEnd (maCurrentItemList.end()); + sal_uInt16 nIndex (1); + + // Update existing items. + for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex) + { + if (*iNewItem != *iCurrentItem) + { + SetItem(nIndex,*iNewItem); + } + } + + // Append new items. + for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex) + { + SetItem(nIndex,*iNewItem); + } + + // Remove trailing items. + for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex) + { + SetItem(nIndex,MasterPageContainer::NIL_TOKEN); + } + + maCurrentItemList.swap(*pNewItemList); + + PreviewValueSet::Rearrange(); + if (mxSidebar.is()) + mxSidebar->requestLayout(); +} + + + + +css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth (const sal_Int32 nWidth) +{ + const sal_Int32 nHeight (GetPreferredHeight(nWidth)); + return css::ui::LayoutSize(nHeight,nHeight,nHeight); +} + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/MasterPagesSelector.hxx b/sd/source/ui/sidebar/MasterPagesSelector.hxx new file mode 100644 index 000000000000..f58ddefffae1 --- /dev/null +++ b/sd/source/ui/sidebar/MasterPagesSelector.hxx @@ -0,0 +1,242 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX +#define SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX + +#include "MasterPageContainer.hxx" +#include "SlideSorterViewShell.hxx" +#include "PreviewValueSet.hxx" +#include "ISidebarReceiver.hxx" +#include <sfx2/sidebar/ILayoutableWindow.hxx> + +#include "pres.hxx" +#include <sfx2/shell.hxx> +#include <vcl/image.hxx> +#include "glob.hxx" +#include <osl/mutex.hxx> +#include <com/sun/star/ui/XSidebar.hpp> + +#include <queue> + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + +class MouseEvent; +class SdDrawDocument; +class SdPage; +class SfxModule; + +namespace sd { +class DrawViewShell; +class TemplateEntry; +class TemplateDir; +class ViewShellBase; +} + +namespace sd { namespace sidebar { + +class PreviewValueSet; +class SidebarShellManager; + + +/** Base class of a menu that lets the user select from a list of + templates or designs that are loaded from files. +*/ +class MasterPagesSelector + : public PreviewValueSet, + public sfx2::sidebar::ILayoutableWindow +{ +public: + MasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + virtual ~MasterPagesSelector (void); + + virtual void LateInit (void); + + /** Return the height that this control needs to show all of its lines. + */ + long GetRequiredHeight (int nWidth) const; + + /** The given master page, either the master page of a slide or a notes + page, is cloned and inserted into mrDocument. The necessary styles + are copied as well. + */ + static SdPage* AddMasterPage ( + SdDrawDocument* pTargetDocument, + SdPage* pMasterPage, + sal_uInt16 nInsertionIndex); + + virtual Size GetPreferredSize (void); + virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight); + virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth); + virtual bool IsResizable (void); + virtual ::Window* GetWindow (void); + virtual sal_Int32 GetMinimumWidth (void); + + /** Update the selection of previews according to whatever + influences them appart from mouse and keyboard. If, for + example, the current page of the main pane changes, then call + this method at the CurrentMasterPagesSelector to select the + previews of the master pages that are assigned to the new + current page. + + The default implementation of this method ignores the call. This is + used by e.g. the RecentMasterPagesSelector because it does not show + the currently used master pages by default and thus is not + influenced by its changes. + */ + virtual void UpdateSelection (void); + + void FillPageSet (void); + + /** Make the selector empty. This method clear the value set from any + entries. Overload this method to add functionality, especially to + destroy objects set as data items at the value set. + */ + void ClearPageSet (void); + + void SetHelpId( const rtl::OString& aId ); + + /** Mark the preview that belongs to the given index as not up-to-date + anymore with respect to page content or preview size. + The implementation of this method will either sunchronously or + asynchronously call UpdatePreview(). + @param nIndex + Index into the value set control that is used for displaying the + previews. + */ + void InvalidatePreview (const SdPage* pPage); + + void UpdateAllPreviews (void); + + // ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + +protected: + mutable ::osl::Mutex maMutex; + ::boost::shared_ptr<MasterPageContainer> mpContainer; + + SdDrawDocument& mrDocument; + bool mbSmallPreviewSize; + ViewShellBase& mrBase; + /** Slot that is executed as default action when the left mouse button is + clicked over a master page. + */ + sal_uInt16 mnDefaultClickAction; + /** Pages with pointers in this queue have their previews updated + eventually. Filled by InvalidatePreview() and operated upon by + UpdatePreviews(). + */ + ::std::queue<sal_uInt16> maPreviewUpdateQueue; + + virtual SdPage* GetSelectedMasterPage (void); + + /** Assign the given master page to all slides of the document. + @param pMasterPage + The master page to assign to all slides. + */ + void AssignMasterPageToAllSlides (SdPage* pMasterPage); + + /** Assign the given master page to all slides that are selected in a + slide sorter that is displayed in the lef or center pane. When both + panes display a slide sorter then the one in the center pane is + used. + */ + void AssignMasterPageToSelectedSlides (SdPage* pMasterPage); + + virtual void AssignMasterPageToPageList ( + SdPage* pMasterPage, + const ::sd::slidesorter::SharedPageSelection& rPageList); + + virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent); + + typedef ::std::pair<int, MasterPageContainer::Token> UserData; + UserData* CreateUserData (int nIndex, MasterPageContainer::Token aToken) const; + UserData* GetUserData (int nIndex) const; + void SetUserData (int nIndex, UserData* pData); + + virtual sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const; + typedef ::std::vector<MasterPageContainer::Token> ItemList; + void UpdateItemList (::std::auto_ptr<ItemList> pList); + void Clear (void); + /** Invalidate the specified item so that on the next Fill() this item + is updated. + */ + void InvalidateItem (MasterPageContainer::Token aToken); + + // For every item in the ValueSet we store its associated token. This + // allows a faster access and easier change tracking. + ItemList maCurrentItemList; + typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex; + TokenToValueSetIndex maTokenToValueSetIndex; + + ItemList maLockedMasterPages; + /** Lock master pages in the given list and release locks that where + previously aquired. + */ + void UpdateLocks (const ItemList& rItemList); + + void Fill (void); + virtual void Fill (ItemList& rItemList) = 0; + + /** Give derived classes the oportunity to provide their own context + menu. If they do then they probably have to provide their own + Execute() and GetState() methods as well. + */ + virtual ResId GetContextMenuResId (void) const; + + virtual void Command (const CommandEvent& rEvent); + + virtual void ProcessPopupMenu (Menu& rMenu); + virtual void ExecuteCommand (const sal_Int32 nCommandId); + +private: + cssu::Reference<css::ui::XSidebar> mxSidebar; + + /** The offset between ValueSet index and MasterPageContainer::Token + last seen. This value is used heuristically to speed up the lookup + of an index for a token. + */ + DECL_LINK(ClickHandler, PreviewValueSet*); + DECL_LINK(RightClickHandler, MouseEvent*); + DECL_LINK(ContextMenuCallback, CommandEvent*); + DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent*); + DECL_LINK(OnMenuItemSelected, Menu*); + + void SetItem ( + sal_uInt16 nIndex, + MasterPageContainer::Token aToken); + void AddTokenToIndexEntry ( + sal_uInt16 nIndex, + MasterPageContainer::Token aToken); + void RemoveTokenToIndexEntry ( + sal_uInt16 nIndex, + MasterPageContainer::Token aToken); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/NavigatorWrapper.cxx b/sd/source/ui/sidebar/NavigatorWrapper.cxx new file mode 100644 index 000000000000..6a4f3bc104cb --- /dev/null +++ b/sd/source/ui/sidebar/NavigatorWrapper.cxx @@ -0,0 +1,89 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "NavigatorWrapper.hxx" +#include "navigatr.hrc" +#include "ViewShellBase.hxx" + +#include <sfx2/sidebar/Theme.hxx> + +#include <boost/bind.hpp> + + +namespace sd { namespace sidebar { + +NavigatorWrapper::NavigatorWrapper ( + ::Window* pParent, + sd::ViewShellBase& rViewShellBase, + SfxBindings* pBindings) + : Control(pParent, 0), + mrViewShellBase(rViewShellBase), + maNavigator( + this, + NULL, + SdResId(FLT_NAVIGATOR), + pBindings, + ::boost::bind(&NavigatorWrapper::UpdateNavigator, this)) +{ + maNavigator.SetPosSizePixel( + Point(0,0), + GetSizePixel()); + maNavigator.SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground)); + maNavigator.Show(); +} + + + + +NavigatorWrapper::~NavigatorWrapper (void) +{ +} + + + + +void NavigatorWrapper::Resize (void) +{ + maNavigator.SetSizePixel(GetSizePixel()); +} + + + + +css::ui::LayoutSize NavigatorWrapper::GetHeightForWidth (const sal_Int32 nWidth) +{ + (void)nWidth; + + return css::ui::LayoutSize(-1,-1,-1); +} + + + + +void NavigatorWrapper::UpdateNavigator (void) +{ + maNavigator.InitTreeLB(mrViewShellBase.GetDocument()); +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/NavigatorWrapper.hxx b/sd/source/ui/sidebar/NavigatorWrapper.hxx new file mode 100644 index 000000000000..83370d1da444 --- /dev/null +++ b/sd/source/ui/sidebar/NavigatorWrapper.hxx @@ -0,0 +1,72 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_NAVIGATOR_WRAPPER_HXX +#define SD_SIDEBAR_NAVIGATOR_WRAPPER_HXX + +#include <sfx2/sidebar/ILayoutableWindow.hxx> +#include <vcl/ctrl.hxx> +#include "navigatr.hxx" + + +class SfxBindings; +namespace sd { class ViewShellBase; } + +namespace css = ::com::sun::star; + +namespace sd { namespace sidebar { + +/** Present the navigator as control that can be displayed inside the + sidebar. + This wrapper has two main responsibilities: + - Watch for document changes and update the navigator when one + happens. + - Forward size changes from sidebar to navigator. +*/ +class NavigatorWrapper + : public Control, + public sfx2::sidebar::ILayoutableWindow +{ +public: + NavigatorWrapper ( + ::Window* pParent, + sd::ViewShellBase& rViewShellBase, + SfxBindings* pBindings); + + virtual ~NavigatorWrapper (void); + + // Control + virtual void Resize (void); + + // From ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + +private: + ViewShellBase& mrViewShellBase; + SdNavigatorWin maNavigator; + + void UpdateNavigator (void); +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/PanelBase.cxx b/sd/source/ui/sidebar/PanelBase.cxx new file mode 100644 index 000000000000..ba2519c67712 --- /dev/null +++ b/sd/source/ui/sidebar/PanelBase.cxx @@ -0,0 +1,130 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "TableDesignPanel.hxx" + + + +namespace sd { namespace sidebar { + + +PanelBase::PanelBase ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) + : Control(pParentWindow), + mpWrappedControl(NULL), + mxSidebar(), + mrViewShellBase(rViewShellBase) +{ + OSL_TRACE("created PanelBase at %x for parent %x", this, pParentWindow); + +#ifdef DEBUG + SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:PanelBase"))); +#endif +} + + + + +PanelBase::~PanelBase (void) +{ + OSL_TRACE("deleting wrapped control at %x", mpWrappedControl.get()); + mpWrappedControl.reset(); + OSL_TRACE("deleting PanelBase at %x from parent %x", this, GetParent()); +} + + + + + +void PanelBase::Dispose (void) +{ + OSL_TRACE("PanelBase::DisposeL: deleting wrapped control at %x", mpWrappedControl.get()); + mpWrappedControl.reset(); +} + + + + +css::ui::LayoutSize PanelBase::GetHeightForWidth (const sal_Int32 nWidth) +{ + sal_Int32 nHeight (0); + if (ProvideWrappedControl()) + nHeight = mpWrappedControl->GetSizePixel().Height(); + return css::ui::LayoutSize(nHeight,nHeight,nHeight); +} + + + + +void PanelBase::Resize (void) +{ + if (ProvideWrappedControl()) + { + Size aNewSize (GetSizePixel()); + mpWrappedControl->SetOutputSizePixel(aNewSize); + } +} + + + + +::com::sun::star::uno::Reference< + ::com::sun::star::accessibility::XAccessible> PanelBase::CreateAccessibleObject ( + const ::com::sun::star::uno::Reference< + ::com::sun::star::accessibility::XAccessible>& ) +{ + if (ProvideWrappedControl()) + return mpWrappedControl->GetAccessible(); + else + return NULL; +} + + + + +void PanelBase::SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar) +{ + mxSidebar = rxSidebar; + if (mxSidebar.is() && mpWrappedControl!=NULL) + mxSidebar->requestLayout(); +} + + + + +bool PanelBase::ProvideWrappedControl (void) +{ + if ( ! mpWrappedControl) + { + mpWrappedControl.reset(CreateWrappedControl(this, mrViewShellBase)); + OSL_TRACE("created wrapped control at %x for parent PanelBase at %x", mpWrappedControl.get(), this); + if (mpWrappedControl) + mpWrappedControl->Show(); + if (mxSidebar.is()) + mxSidebar->requestLayout(); + } + return mpWrappedControl.get() != NULL; +} + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/PanelBase.hxx b/sd/source/ui/sidebar/PanelBase.hxx new file mode 100644 index 000000000000..3deddc81f1a6 --- /dev/null +++ b/sd/source/ui/sidebar/PanelBase.hxx @@ -0,0 +1,90 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_PANEL_BASE_HXX +#define SD_SIDEBAR_PANELS_PANEL_BASE_HXX + +#include "IDisposable.hxx" +#include "ISidebarReceiver.hxx" +#include <sfx2/sidebar/ILayoutableWindow.hxx> + +#include <vcl/ctrl.hxx> + +#include <boost/scoped_ptr.hpp> + + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + +namespace sd { + class ViewShellBase; +} + + + + +namespace sd { namespace sidebar { + + +class PanelBase + : public Control, + public sfx2::sidebar::ILayoutableWindow, + public IDisposable, + public ISidebarReceiver +{ +public: + PanelBase ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); + virtual ~PanelBase (void); + + virtual void Resize (void); + + // IDisposable + virtual void Dispose (void); + + // ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + + // ISidebarReceiver + virtual void SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar); + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::accessibility::XAccessible > CreateAccessibleObject ( + const ::com::sun::star::uno::Reference< + ::com::sun::star::accessibility::XAccessible>& rxParent); + +protected: + ::boost::scoped_ptr< ::Window> mpWrappedControl; + virtual ::Window* CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) = 0; + +private: + cssu::Reference<css::ui::XSidebar> mxSidebar; + ViewShellBase& mrViewShellBase; + + bool ProvideWrappedControl (void); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/PanelFactory.cxx b/sd/source/ui/sidebar/PanelFactory.cxx new file mode 100644 index 000000000000..7dba3eea3afa --- /dev/null +++ b/sd/source/ui/sidebar/PanelFactory.cxx @@ -0,0 +1,212 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "PanelFactory.hxx" +#include "framework/Pane.hxx" +#include "ViewShellBase.hxx" +#include "DrawController.hxx" +#include "LayoutMenu.hxx" +#include "CurrentMasterPagesSelector.hxx" +#include "RecentMasterPagesSelector.hxx" +#include "AllMasterPagesSelector.hxx" +#include "CustomAnimationPanel.hxx" +#include "SlideTransitionPanel.hxx" +#include "NavigatorWrapper.hxx" + +#include <sfx2/viewfrm.hxx> +#include <sfx2/sidebar/SidebarPanelBase.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <vcl/window.hxx> +#include <toolkit/helper/vclunohelper.hxx> + +using namespace css; +using namespace cssu; +using namespace ::sd::framework; +using ::rtl::OUString; + +#define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) + +namespace sd { + extern ::Window * createTableDesignPanel (::Window* pParent, ViewShellBase& rBase); +} + +namespace sd { namespace sidebar { + +namespace { + /** Note that these names have to be identical to (the tail of) + the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu + for the TaskPanelFactory. + */ + const static char* gsResourceNameCustomAnimations = "/CustomAnimations"; + const static char* gsResourceNameLayouts = "/Layouts"; + const static char* gsResourceNameAllMasterPages = "/AllMasterPages"; + const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages"; + const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages"; + const static char* gsResourceNameSlideTransitions = "/SlideTransitions"; + const static char* gsResourceNameTableDesign = "/TableDesign"; + const static char* gsResourceNameNavigator = "/NavigatorPanel"; +} + +Reference<lang::XEventListener> mxControllerDisposeListener; + + + +// ----- Service functions ---------------------------------------------------- + +Reference<XInterface> SAL_CALL PanelFactory_createInstance ( + const Reference<XComponentContext>& rxContext) +{ + return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext))); +} + + + + +::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException) +{ + return ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.PanelFactory")); +} + + + + +Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void) + throw (RuntimeException) +{ + static const ::rtl::OUString sServiceName( + ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.PanelFactory")); + return Sequence<rtl::OUString>(&sServiceName, 1); +} + + + + +//----- PanelFactory -------------------------------------------------------- + +PanelFactory::PanelFactory( + const css::uno::Reference<css::uno::XComponentContext>& rxContext) + : PanelFactoryInterfaceBase(m_aMutex) +{ +} + + + + +PanelFactory::~PanelFactory (void) +{ +} + + + + +void SAL_CALL PanelFactory::disposing (void) +{ +} + + + + +// XUIElementFactory + +Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( + const ::rtl::OUString& rsUIElementResourceURL, + const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) + throw( + css::container::NoSuchElementException, + css::lang::IllegalArgumentException, + cssu::RuntimeException) +{ + // Process arguments. + const ::comphelper::NamedValueCollection aArguments (rArguments); + Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); + Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); + Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); + + // Throw exceptions when the arguments are not as expected. + ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); + if ( ! xParentWindow.is() || pParentWindow==NULL) + throw RuntimeException( + A2S("PanelFactory::createUIElement called without ParentWindow"), + NULL); + if ( ! xFrame.is()) + throw RuntimeException( + A2S("PanelFactory::createUIElement called without XFrame"), + NULL); + + // Tunnel through the controller to obtain a ViewShellBase. + ViewShellBase* pBase = NULL; + Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY); + if (xTunnel.is()) + { + ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( + xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); + if (pController != NULL) + pBase = pController->GetViewShellBase(); + } + if (pBase == NULL) + throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL); + + // Get bindings from given arguments. + const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); + SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); + + // Create a framework view. + ::Window* pControl = NULL; + css::ui::LayoutSize aLayoutSize (-1,-1,-1); + +#define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t)) + if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations)) + pControl = new CustomAnimationPanel(pParentWindow, *pBase); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts)) + pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages)) + pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages)) + pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages)) + pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions)) + pControl = new SlideTransitionPanel(pParentWindow, *pBase); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign)) + pControl = createTableDesignPanel(pParentWindow, *pBase); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator)) + pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings); +#undef EndsWith + + if (pControl == NULL) + throw lang::IllegalArgumentException(); + + // Create a wrapper around the control that implements the + // necessary UNO interfaces. + return sfx2::sidebar::SidebarPanelBase::Create( + rsUIElementResourceURL, + xFrame, + pControl, + aLayoutSize); +} + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/PanelFactory.hxx b/sd/source/ui/sidebar/PanelFactory.hxx new file mode 100644 index 000000000000..392b0dc1a0cb --- /dev/null +++ b/sd/source/ui/sidebar/PanelFactory.hxx @@ -0,0 +1,88 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANEL_FACTORY_HXX +#define SD_SIDEBAR_PANEL_FACTORY_HXX + +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/basemutex.hxx> +#include <rtl/ref.hxx> +#include "framework/Pane.hxx" + +#include <com/sun/star/ui/XUIElementFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XInitialization.hpp> + +#include <map> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> + + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + + +namespace sd { + class ViewShellBase; +} + +namespace sd { namespace sidebar { + +namespace +{ + typedef ::cppu::WeakComponentImplHelper1 < + css::ui::XUIElementFactory + > PanelFactoryInterfaceBase; +} + + +class PanelFactory + : private ::boost::noncopyable, + private ::cppu::BaseMutex, + public PanelFactoryInterfaceBase +{ +public: + static ::rtl::OUString SAL_CALL getImplementationName (void); + static cssu::Reference<cssu::XInterface> SAL_CALL createInstance ( + const cssu::Reference<css::lang::XMultiServiceFactory>& rxFactory); + static cssu::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames (void); + + PanelFactory (const cssu::Reference<cssu::XComponentContext>& rxContext); + virtual ~PanelFactory (void); + + virtual void SAL_CALL disposing (void); + + + // XUIElementFactory + + cssu::Reference<css::ui::XUIElement> SAL_CALL createUIElement ( + const ::rtl::OUString& rsResourceURL, + const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) + throw( + css::container::NoSuchElementException, + css::lang::IllegalArgumentException, + cssu::RuntimeException); +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/PreviewValueSet.cxx b/sd/source/ui/sidebar/PreviewValueSet.cxx new file mode 100644 index 000000000000..556073f242e5 --- /dev/null +++ b/sd/source/ui/sidebar/PreviewValueSet.cxx @@ -0,0 +1,185 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "PreviewValueSet.hxx" +#include <vcl/image.hxx> + + +namespace sd { namespace sidebar { + + +PreviewValueSet::PreviewValueSet (::Window* pParent) + : ValueSet (pParent, WB_TABSTOP), + maPreviewSize(10,10), + mnBorderWidth(3), + mnBorderHeight(3), + mnMaxColumnCount(-1) +{ + SetStyle ( + GetStyle() + & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET) + // | WB_FLATVALUESET); + ); + SetColCount(2); + SetExtraSpacing (2); +} + + + + +PreviewValueSet::~PreviewValueSet (void) +{ +} + + + + +void PreviewValueSet::SetPreviewSize (const Size& rSize) +{ + maPreviewSize = rSize; +} + + + + +void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink) +{ + maRightMouseClickHandler = rLink; +} + + + + +void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent) +{ + if (rEvent.IsRight()) + maRightMouseClickHandler.Call(reinterpret_cast<void*>( + &const_cast<MouseEvent&>(rEvent))); + else + ValueSet::MouseButtonDown (rEvent); + +} + + + + +void PreviewValueSet::Resize (void) +{ + ValueSet::Resize (); + + Size aWindowSize (GetOutputSizePixel()); + if (aWindowSize.Width()>0 && aWindowSize.Height()>0) + { + Rearrange(); + } +} + + + + +void PreviewValueSet::Rearrange (bool bForceRequestResize) +{ + sal_uInt16 nOldColumnCount (GetColCount()); + sal_uInt16 nOldRowCount (GetLineCount()); + + sal_uInt16 nNewColumnCount (CalculateColumnCount ( + GetOutputSizePixel().Width())); + sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount)); + + SetColCount(nNewColumnCount); + SetLineCount(nNewRowCount); +} + + + + +sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const +{ + int nColumnCount = 0; + if (nWidth > 0) + { + nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth); + if (nColumnCount < 1) + nColumnCount = 1; + else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount) + nColumnCount = mnMaxColumnCount; + } + return (sal_uInt16)nColumnCount; +} + + + + +sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const +{ + int nRowCount = 0; + int nItemCount = GetItemCount(); + if (nColumnCount > 0) + { + nRowCount = (nItemCount+nColumnCount-1) / nColumnCount; + if (nRowCount < 1) + nRowCount = 1; + } + + return (sal_uInt16)nRowCount; +} + + + + +sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight) +{ + int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth); + + // Get height of each row. + int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight); + + // Calculate the row- and column count and from the later the preferred + // width. + int nRowCount = nHeight / nItemHeight; + if (nRowCount > 0) + { + int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount; + if (nColumnCount > 0) + nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth) + * nColumnCount; + } + + return nPreferredWidth; +} + + + + +sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth) +{ + int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth))); + int nItemHeight (maPreviewSize.Height()); + + return nRowCount * (nItemHeight + 2*mnBorderHeight); +} + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/PreviewValueSet.hxx b/sd/source/ui/sidebar/PreviewValueSet.hxx new file mode 100644 index 000000000000..5a0c55c18d10 --- /dev/null +++ b/sd/source/ui/sidebar/PreviewValueSet.hxx @@ -0,0 +1,69 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_PREVIEW_VALUE_SET_HXX +#define SD_SIDEBAR_PANELS_PREVIEW_VALUE_SET_HXX + +#include <svtools/valueset.hxx> + + +namespace sd { namespace sidebar { + + +/** Adapt the svtools valueset to the needs of the master page controlls. +*/ +class PreviewValueSet + : public ValueSet +{ +public: + PreviewValueSet (::Window* pParent); + ~PreviewValueSet (void); + + void SetRightMouseClickHandler (const Link& rLink); + virtual void Resize (void); + + void SetPreviewSize (const Size& rSize); + + sal_Int32 GetPreferredWidth (sal_Int32 nHeight); + sal_Int32 GetPreferredHeight (sal_Int32 nWidth); + + /** Set the number of rows and columns according to the current number + of items. Call this method when new items have been inserted. + */ + void Rearrange (bool bForceRequestResize = false); + +protected: + virtual void MouseButtonDown (const MouseEvent& rEvent); + +private: + Link maRightMouseClickHandler; + Size maPreviewSize; + const int mnBorderWidth; + const int mnBorderHeight; + const int mnMaxColumnCount; + + sal_uInt16 CalculateColumnCount (int nWidth) const; + sal_uInt16 CalculateRowCount (sal_uInt16 nColumnCount) const; +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/RecentMasterPagesSelector.cxx b/sd/source/ui/sidebar/RecentMasterPagesSelector.cxx new file mode 100644 index 000000000000..c107a5e43384 --- /dev/null +++ b/sd/source/ui/sidebar/RecentMasterPagesSelector.cxx @@ -0,0 +1,181 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "RecentMasterPagesSelector.hxx" + +#include "ViewShellBase.hxx" +#include "RecentlyUsedMasterPages.hxx" +#include "MasterPageContainerProviders.hxx" +#include "MasterPageObserver.hxx" +#include "SidebarShellManager.hxx" +#include "sdpage.hxx" +#include "drawdoc.hxx" +#include "app.hrc" +#include "helpids.h" + +#include <vcl/bitmap.hxx> +#include <tools/color.hxx> + +namespace sd { namespace sidebar { + + +MasterPagesSelector* RecentMasterPagesSelector::Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) +{ + SdDrawDocument* pDocument = rViewShellBase.GetDocument(); + if (pDocument == NULL) + return NULL; + + ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer()); + + MasterPagesSelector* pSelector( + new RecentMasterPagesSelector ( + pParent, + *pDocument, + rViewShellBase, + pContainer, + rxSidebar)); + pSelector->LateInit(); + pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT); + + return pSelector; +} + + + + +RecentMasterPagesSelector::RecentMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar) + : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar) +{ +} + + + + +RecentMasterPagesSelector::~RecentMasterPagesSelector (void) +{ + RecentlyUsedMasterPages::Instance().RemoveEventListener ( + LINK(this,RecentMasterPagesSelector,MasterPageListListener)); +} + + + + +void RecentMasterPagesSelector::LateInit (void) +{ + MasterPagesSelector::LateInit(); + + MasterPagesSelector::Fill(); + RecentlyUsedMasterPages::Instance().AddEventListener ( + LINK(this,RecentMasterPagesSelector,MasterPageListListener)); +} + + + + +IMPL_LINK(RecentMasterPagesSelector,MasterPageListListener, void*, EMPTYARG) +{ + MasterPagesSelector::Fill(); + return 0; +} + + + + +void RecentMasterPagesSelector::Fill (ItemList& rItemList) +{ + // Create a set of names of the master pages used by the document. + MasterPageObserver::MasterPageNameSet aCurrentNames; + sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD); + sal_uInt16 nIndex; + for (nIndex=0; nIndex<nMasterPageCount; nIndex++) + { + SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD); + if (pMasterPage != NULL) + aCurrentNames.insert (pMasterPage->GetName()); + } + MasterPageObserver::MasterPageNameSet::iterator aI; + + // Insert the recently used master pages that are currently not used. + RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance()); + int nPageCount = rInstance.GetMasterPageCount(); + for (nIndex=0; nIndex<nPageCount; nIndex++) + { + // Add an entry when a) the page is already known to the + // MasterPageContainer, b) the style name is empty, i.e. it has not yet + // been loaded (and thus can not be in use) or otherwise c) the + // style name is not currently in use. + MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex)); + if (aToken != MasterPageContainer::NIL_TOKEN) + { + String sStyleName (mpContainer->GetStyleNameForToken(aToken)); + if (sStyleName.Len()==0 + || aCurrentNames.find(sStyleName) == aCurrentNames.end()) + { + rItemList.push_back(aToken); + } + } + } +} + + + + +void RecentMasterPagesSelector::AssignMasterPageToPageList ( + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList) +{ + sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectItemId(); + + MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList); + + // Restore the selection. + if (PreviewValueSet::GetItemCount() > 0) + { + if (PreviewValueSet::GetItemCount() >= nSelectedItemId) + PreviewValueSet::SelectItem(nSelectedItemId); + else + PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount()); + } +} + + + + +void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu) +{ + if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND) + rMenu.EnableItem(SID_TP_EDIT_MASTER, sal_False); +} + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/RecentMasterPagesSelector.hxx b/sd/source/ui/sidebar/RecentMasterPagesSelector.hxx new file mode 100644 index 000000000000..da9bcc90fbd5 --- /dev/null +++ b/sd/source/ui/sidebar/RecentMasterPagesSelector.hxx @@ -0,0 +1,79 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + + +#ifndef SD_SIDEBAR_PANELS_RECENT_MASTER_PAGES_SELECTOR_HXX +#define SD_SIDEBAR_PANELS_RECENT_MASTER_PAGES_SELECTOR_HXX + +#include "MasterPagesSelector.hxx" + +namespace sd { namespace sidebar { + + +/** Show the recently used master pages (that are not currently used). +*/ +class RecentMasterPagesSelector + : public MasterPagesSelector +{ +public: + static MasterPagesSelector* Create ( + ::Window* pParent, + ViewShellBase& rViewShellBase, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + +protected: + DECL_LINK(MasterPageListListener, void*); + virtual void Fill (ItemList& rItemList); + + using sd::sidebar::MasterPagesSelector::Fill; + + /** Forward this call to the base class but save and restore the + currently selected item. + Assign the given master page to the list of pages. + @param pMasterPage + This master page will usually be a member of the list of all + available master pages as provided by the MasterPageContainer. + @param rPageList + The pages to which to assign the master page. These pages may + be slides or master pages themselves. + */ + virtual void AssignMasterPageToPageList ( + SdPage* pMasterPage, + const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList); + + virtual void ProcessPopupMenu (Menu& rMenu); + +private: + RecentMasterPagesSelector ( + ::Window* pParent, + SdDrawDocument& rDocument, + ViewShellBase& rBase, + const ::boost::shared_ptr<MasterPageContainer>& rpContainer, + const cssu::Reference<css::ui::XSidebar>& rxSidebar); + virtual ~RecentMasterPagesSelector (void); + + virtual void LateInit (void); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx b/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx new file mode 100644 index 000000000000..9c71f68f4b10 --- /dev/null +++ b/sd/source/ui/sidebar/RecentlyUsedMasterPages.cxx @@ -0,0 +1,494 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "RecentlyUsedMasterPages.hxx" +#include "MasterPageObserver.hxx" +#include "MasterPagesSelector.hxx" +#include "MasterPageDescriptor.hxx" +#include "tools/ConfigurationAccess.hxx" +#include "drawdoc.hxx" +#include "sdpage.hxx" + +#include <algorithm> +#include <vector> + +#include <comphelper/processfactory.hxx> +#include "unomodel.hxx" +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/PropertyState.hpp> +#include <tools/urlobj.hxx> +#include <unotools/confignode.hxx> +#include <osl/doublecheckedlocking.h> +#include <osl/getglobalmutex.hxx> + +using namespace ::std; +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +namespace { + +static const OUString& GetPathToImpressConfigurationRoot (void) +{ + static const OUString sPathToImpressConfigurationRoot ( + RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/")); + return sPathToImpressConfigurationRoot; +} +static const OUString& GetPathToSetNode (void) +{ + static const OUString sPathToSetNode( + RTL_CONSTASCII_USTRINGPARAM( + "MultiPaneGUI/ToolPanel/RecentlyUsedMasterPages")); + return sPathToSetNode; +} + + +class Descriptor +{ +public: + ::rtl::OUString msURL; + ::rtl::OUString msName; + ::sd::sidebar::MasterPageContainer::Token maToken; + Descriptor (const ::rtl::OUString& rsURL, const ::rtl::OUString& rsName) + : msURL(rsURL), + msName(rsName), + maToken(::sd::sidebar::MasterPageContainer::NIL_TOKEN) + {} + Descriptor (::sd::sidebar::MasterPageContainer::Token aToken, + const ::rtl::OUString& rsURL, const ::rtl::OUString& rsName) + : msURL(rsURL), + msName(rsName), + maToken(aToken) + {} + class TokenComparator + { public: + TokenComparator(::sd::sidebar::MasterPageContainer::Token aToken) + : maToken(aToken) {} + bool operator () (const Descriptor& rDescriptor) + { return maToken==rDescriptor.maToken; } + private: ::sd::sidebar::MasterPageContainer::Token maToken; + }; +}; + +} // end of anonymous namespace + + + + +namespace sd { namespace sidebar { + +class RecentlyUsedMasterPages::MasterPageList : public ::std::vector<Descriptor> +{ +public: + MasterPageList (void) {} +}; + + +RecentlyUsedMasterPages* RecentlyUsedMasterPages::mpInstance = NULL; + + +RecentlyUsedMasterPages& RecentlyUsedMasterPages::Instance (void) +{ + if (mpInstance == NULL) + { + ::osl::GetGlobalMutex aMutexFunctor; + ::osl::MutexGuard aGuard (aMutexFunctor()); + if (mpInstance == NULL) + { + RecentlyUsedMasterPages* pInstance = new RecentlyUsedMasterPages(); + pInstance->LateInit(); + SdGlobalResourceContainer::Instance().AddResource ( + ::std::auto_ptr<SdGlobalResource>(pInstance)); + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + mpInstance = pInstance; + } + } + else { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + } + + return *mpInstance; +} + + + + +RecentlyUsedMasterPages::RecentlyUsedMasterPages (void) + : maListeners(), + mpMasterPages(new MasterPageList()), + mnMaxListSize(8), + mpContainer(new MasterPageContainer()) +{ +} + + + + +RecentlyUsedMasterPages::~RecentlyUsedMasterPages (void) +{ + Link aLink (LINK(this,RecentlyUsedMasterPages,MasterPageContainerChangeListener)); + mpContainer->RemoveChangeListener(aLink); + + MasterPageObserver::Instance().RemoveEventListener( + LINK(this,RecentlyUsedMasterPages,MasterPageChangeListener)); +} + + + + +void RecentlyUsedMasterPages::LateInit (void) +{ + Link aLink (LINK(this,RecentlyUsedMasterPages,MasterPageContainerChangeListener)); + mpContainer->AddChangeListener(aLink); + + LoadPersistentValues (); + MasterPageObserver::Instance().AddEventListener( + LINK(this,RecentlyUsedMasterPages,MasterPageChangeListener)); +} + + + + +void RecentlyUsedMasterPages::LoadPersistentValues (void) +{ + try + { + do + { + tools::ConfigurationAccess aConfiguration ( + GetPathToImpressConfigurationRoot(), + tools::ConfigurationAccess::READ_ONLY); + Reference<container::XNameAccess> xSet ( + aConfiguration.GetConfigurationNode(GetPathToSetNode()), + UNO_QUERY); + if ( ! xSet.is()) + break; + + const String sURLMemberName (OUString::createFromAscii("URL")); + const String sNameMemberName (OUString::createFromAscii("Name")); + OUString sURL; + OUString sName; + + // Read the names and URLs of the master pages. + Sequence<OUString> aKeys (xSet->getElementNames()); + mpMasterPages->clear(); + mpMasterPages->reserve(aKeys.getLength()); + for (int i=0; i<aKeys.getLength(); i++) + { + Reference<container::XNameAccess> xSetItem ( + xSet->getByName(aKeys[i]), UNO_QUERY); + if (xSetItem.is()) + { + Any aURL (xSetItem->getByName(sURLMemberName)); + Any aName (xSetItem->getByName(sNameMemberName)); + aURL >>= sURL; + aName >>= sName; + SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( + MasterPageContainer::TEMPLATE, + -1, + sURL, + String(), + sName, + false, + ::boost::shared_ptr<PageObjectProvider>( + new TemplatePageObjectProvider(sURL)), + ::boost::shared_ptr<PreviewProvider>( + new TemplatePreviewProvider(sURL)))); + // For user supplied templates we use a different + // preview provider: The preview in the document shows + // not only shapes on the master page but also shapes on + // the foreground. This is misleading and therefore + // these previews are discarded and created directly + // from the page objects. + if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER) + pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>( + new PagePreviewProvider()); + MasterPageContainer::Token aToken (mpContainer->PutMasterPage(pDescriptor)); + mpMasterPages->push_back(Descriptor(aToken,sURL,sName)); + } + } + + ResolveList(); + } + while (false); + } + catch (Exception&) + { + // Ignore exception. + } +} + + + + +void RecentlyUsedMasterPages::SavePersistentValues (void) +{ + try + { + do + { + tools::ConfigurationAccess aConfiguration ( + GetPathToImpressConfigurationRoot(), + tools::ConfigurationAccess::READ_WRITE); + Reference<container::XNameContainer> xSet ( + aConfiguration.GetConfigurationNode(GetPathToSetNode()), + UNO_QUERY); + if ( ! xSet.is()) + break; + + // Clear the set. + Sequence<OUString> aKeys (xSet->getElementNames()); + sal_Int32 i; + for (i=0; i<aKeys.getLength(); i++) + xSet->removeByName (aKeys[i]); + + // Fill it with the URLs of this object. + const String sURLMemberName (OUString::createFromAscii("URL")); + const String sNameMemberName (OUString::createFromAscii("Name")); + Any aValue; + Reference<lang::XSingleServiceFactory> xChildFactory ( + xSet, UNO_QUERY); + if ( ! xChildFactory.is()) + break; + MasterPageList::const_iterator iDescriptor; + sal_Int32 nIndex(0); + for (iDescriptor=mpMasterPages->begin(); + iDescriptor!=mpMasterPages->end(); + ++iDescriptor,++nIndex) + { + // Create new child. + OUString sKey (OUString::createFromAscii("index_")); + sKey += OUString::valueOf(nIndex); + Reference<container::XNameReplace> xChild( + xChildFactory->createInstance(), UNO_QUERY); + if (xChild.is()) + { + xSet->insertByName (sKey, makeAny(xChild)); + + aValue <<= OUString(iDescriptor->msURL); + xChild->replaceByName (sURLMemberName, aValue); + + aValue <<= OUString(iDescriptor->msName); + xChild->replaceByName (sNameMemberName, aValue); + } + } + + // Write the data back to disk. + aConfiguration.CommitChanges(); + } + while (false); + } + catch (Exception&) + { + // Ignore exception. + } +} + + + + +void RecentlyUsedMasterPages::AddEventListener (const Link& rEventListener) +{ + if (::std::find ( + maListeners.begin(), + maListeners.end(), + rEventListener) == maListeners.end()) + { + maListeners.push_back (rEventListener); + } +} + + + + +void RecentlyUsedMasterPages::RemoveEventListener (const Link& rEventListener) +{ + maListeners.erase ( + ::std::find ( + maListeners.begin(), + maListeners.end(), + rEventListener)); +} + + + + +int RecentlyUsedMasterPages::GetMasterPageCount (void) const +{ + return mpMasterPages->size(); +} + + + + +MasterPageContainer::Token RecentlyUsedMasterPages::GetTokenForIndex (sal_uInt32 nIndex) const +{ + if(nIndex<mpMasterPages->size()) + return (*mpMasterPages)[nIndex].maToken; + else + return MasterPageContainer::NIL_TOKEN; +} + + + + +void RecentlyUsedMasterPages::SendEvent (void) +{ + ::std::vector<Link>::iterator aLink (maListeners.begin()); + ::std::vector<Link>::iterator aEnd (maListeners.end()); + while (aLink!=aEnd) + { + aLink->Call (NULL); + ++aLink; + } +} + + + + +IMPL_LINK(RecentlyUsedMasterPages, MasterPageChangeListener, + MasterPageObserverEvent*, pEvent) +{ + switch (pEvent->meType) + { + case MasterPageObserverEvent::ET_MASTER_PAGE_ADDED: + case MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS: + AddMasterPage( + mpContainer->GetTokenForStyleName(pEvent->mrMasterPageName)); + break; + + case MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED: + // Do not change the list of recently master pages (the deleted + // page was recently used) but tell the listeners. They may want + // to update their lists. + SendEvent(); + break; + } + return 0; +} + + + + +IMPL_LINK(RecentlyUsedMasterPages, MasterPageContainerChangeListener, + MasterPageContainerChangeEvent*, pEvent) +{ + if (pEvent != NULL) + switch (pEvent->meEventType) + { + case MasterPageContainerChangeEvent::CHILD_ADDED: + case MasterPageContainerChangeEvent::CHILD_REMOVED: + case MasterPageContainerChangeEvent::INDEX_CHANGED: + case MasterPageContainerChangeEvent::INDEXES_CHANGED: + ResolveList(); + break; + + default: + // Ignored. + break; + } + return 0; +} + + + + +void RecentlyUsedMasterPages::AddMasterPage ( + MasterPageContainer::Token aToken, + bool bMakePersistent) +{ + // For the page to be inserted the token has to be valid and the page + // has to have a valid URL. This excludes master pages that do not come + // from template files. + if (aToken != MasterPageContainer::NIL_TOKEN + && mpContainer->GetURLForToken(aToken).Len()>0) + { + + MasterPageList::iterator aIterator ( + ::std::find_if(mpMasterPages->begin(),mpMasterPages->end(), + Descriptor::TokenComparator(aToken))); + if (aIterator != mpMasterPages->end()) + { + // When an entry for the given token already exists then remove + // it now and insert it later at the head of the list. + mpMasterPages->erase (aIterator); + } + + mpMasterPages->insert(mpMasterPages->begin(), + Descriptor( + aToken, + mpContainer->GetURLForToken(aToken), + mpContainer->GetStyleNameForToken(aToken))); + + // Shorten list to maximal size. + while (mpMasterPages->size() > mnMaxListSize) + { + mpMasterPages->pop_back (); + } + + if (bMakePersistent) + SavePersistentValues (); + SendEvent(); + } +} + + + + +void RecentlyUsedMasterPages::ResolveList (void) +{ + bool bNotify (false); + + MasterPageList::iterator iDescriptor; + for (iDescriptor=mpMasterPages->begin(); iDescriptor!=mpMasterPages->end(); ++iDescriptor) + { + if (iDescriptor->maToken == MasterPageContainer::NIL_TOKEN) + { + MasterPageContainer::Token aToken (mpContainer->GetTokenForURL(iDescriptor->msURL)); + iDescriptor->maToken = aToken; + if (aToken != MasterPageContainer::NIL_TOKEN) + bNotify = true; + } + else + { + if ( ! mpContainer->HasToken(iDescriptor->maToken)) + { + iDescriptor->maToken = MasterPageContainer::NIL_TOKEN; + bNotify = true; + } + } + } + + if (bNotify) + SendEvent(); +} + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/RecentlyUsedMasterPages.hxx b/sd/source/ui/sidebar/RecentlyUsedMasterPages.hxx new file mode 100644 index 000000000000..936c2ef2e1a0 --- /dev/null +++ b/sd/source/ui/sidebar/RecentlyUsedMasterPages.hxx @@ -0,0 +1,124 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + + +#ifndef SD_SIDEBAR_PANELS_RECENTLY_USED_MASTER_PAGES_HXX +#define SD_SIDEBAR_PANELS_RECENTLY_USED_MASTER_PAGES_HXX + +#include "tools/SdGlobalResourceContainer.hxx" +#include <osl/mutex.hxx> +#include <tools/link.hxx> +#include <vcl/image.hxx> +#include <vector> +#include <tools/string.hxx> + +#include "DrawDocShell.hxx" +#include "MasterPageContainer.hxx" +#include <com/sun/star/uno/XInterface.hpp> + +class SdPage; + +namespace sd { +class MasterPageObserverEvent; +} + + +namespace sd { namespace sidebar { + +/** This singleton holds a list of the most recently used master pages. +*/ +class RecentlyUsedMasterPages + : public SdGlobalResource +{ +public: + /** Return the single instance of this class. + */ + static RecentlyUsedMasterPages& Instance (void); + + void AddEventListener (const Link& rEventListener); + void RemoveEventListener (const Link& rEventListener); + + int GetMasterPageCount (void) const; + MasterPageContainer::Token GetTokenForIndex (sal_uInt32 nIndex) const; + +private: + /** The single instance of this class. It is created on demand when + Instance() is called for the first time. + */ + static RecentlyUsedMasterPages* mpInstance; + + ::std::vector<Link> maListeners; + + class MasterPageList; + ::std::auto_ptr<MasterPageList> mpMasterPages; + unsigned long int mnMaxListSize; + ::boost::shared_ptr<MasterPageContainer> mpContainer; + + RecentlyUsedMasterPages (void); + virtual ~RecentlyUsedMasterPages (void); + + /** Call this method after a new object has been created. + */ + void LateInit (void); + + /// The copy constructor is not implemented. Do not use! + RecentlyUsedMasterPages (const RecentlyUsedMasterPages&); + + /// The assignment operator is not implemented. Do not use! + RecentlyUsedMasterPages& operator= (const RecentlyUsedMasterPages&); + + void SendEvent (void); + DECL_LINK(MasterPageChangeListener, MasterPageObserverEvent*); + DECL_LINK(MasterPageContainerChangeListener, MasterPageContainerChangeEvent*); + + /** Add a descriptor for the specified master page to the end of the + list of most recently used master pages. When the page is already a + member of that list the associated descriptor is moved to the end of + the list to make it the most recently used entry. + @param bMakePersistent + When <TRUE/> is given then the new list of recently used master + pages is written back into the configuration to make it + persistent. Giving <FALSE/> to ommit this is used while loading + the persistent list from the configuration. + */ + void AddMasterPage ( + MasterPageContainer::Token aToken, + bool bMakePersistent = true); + + /** Load the list of recently used master pages from the registry where + it was saved to make it persistent. + */ + void LoadPersistentValues (void); + + /** Save the list of recently used master pages to the registry to make + it presistent. + */ + void SavePersistentValues (void); + + void ResolveList (void); +}; + + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/SidebarFactory.cxx b/sd/source/ui/sidebar/SidebarFactory.cxx new file mode 100644 index 000000000000..7eb2b6b65b30 --- /dev/null +++ b/sd/source/ui/sidebar/SidebarFactory.cxx @@ -0,0 +1,240 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "SidebarFactory.hxx" +#include "framework/Pane.hxx" +#include "ViewShellBase.hxx" +#include "DrawController.hxx" +#include "LayoutMenu.hxx" +#include "CurrentMasterPagesSelector.hxx" +#include "RecentMasterPagesSelector.hxx" +#include "AllMasterPagesSelector.hxx" +#include "CustomAnimationPanel.hxx" +#include "TableDesignPanel.hxx" +#include "SlideTransitionPanel.hxx" + +#include <sfx2/viewfrm.hxx> +#include <sfx2/sidebar/SidebarPanelBase.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <vcl/window.hxx> +#include <toolkit/helper/vclunohelper.hxx> + +using namespace css; +using namespace cssu; +using namespace ::sd::framework; +using ::rtl::OUString; + +#define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) + +namespace sd { namespace sidebar { + +namespace { + /** Note that these names have to be identical to (the tail of) + the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu + for the TaskPanelFactory. + */ + const static char* gsResourceNameCustomAnimations = "/CustomAnimations"; + const static char* gsResourceNameLayouts = "/Layouts"; + const static char* gsResourceNameAllMasterPages = "/AllMasterPages"; + const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages"; + const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages"; + const static char* gsResourceNameSlideTransitions = "/SlideTransitions"; + const static char* gsResourceNameTableDesign = "/TableDesign"; +} + +Reference<lang::XEventListener> mxControllerDisposeListener; + + + +// ----- Service functions ---------------------------------------------------- + +Reference<XInterface> SAL_CALL SidebarFactory_createInstance ( + const Reference<XComponentContext>& rxContext) +{ + return Reference<XInterface>(static_cast<XWeak*>(new SidebarFactory(rxContext))); +} + + + + +::rtl::OUString SidebarFactory_getImplementationName (void) throw(RuntimeException) +{ + return ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.SidebarFactory")); +} + + + + +Sequence<rtl::OUString> SAL_CALL SidebarFactory_getSupportedServiceNames (void) + throw (RuntimeException) +{ + static const ::rtl::OUString sServiceName( + ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.SidebarFactory")); + return Sequence<rtl::OUString>(&sServiceName, 1); +} + + + + +//----- SidebarFactory -------------------------------------------------------- + +SidebarFactory::SidebarFactory( + const css::uno::Reference<css::uno::XComponentContext>& rxContext) + : SidebarFactoryInterfaceBase(m_aMutex) +{ +} + + + + +SidebarFactory::~SidebarFactory (void) +{ +} + + + + +void SAL_CALL SidebarFactory::disposing (void) +{ +} + + + + +// XInitialization + +void SAL_CALL SidebarFactory::initialize (const Sequence<Any>& aArguments) + throw (Exception, RuntimeException) +{ +} + + + + +// XUIElementFactory + +Reference<ui::XUIElement> SAL_CALL SidebarFactory::createUIElement ( + const ::rtl::OUString& rsUIElementResourceURL, + const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) + throw( + css::container::NoSuchElementException, + css::lang::IllegalArgumentException, + cssu::RuntimeException) +{ + // Process arguments. + const ::comphelper::NamedValueCollection aArguments (rArguments); + Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); + Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); + Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); + + // Throw exceptions when the arguments are not as expected. + ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); + if ( ! xParentWindow.is() || pParentWindow==NULL) + throw RuntimeException( + A2S("SidebarFactory::createUIElement called without ParentWindow"), + NULL); + if ( ! xFrame.is()) + throw RuntimeException( + A2S("SidebarFactory::createUIElement called without XFrame"), + NULL); + + // Tunnel through the controller to obtain a ViewShellBase. + ViewShellBase* pBase = NULL; + Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY); + if (xTunnel.is()) + { + ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( + xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); + if (pController != NULL) + pBase = pController->GetViewShellBase(); + } + if (pBase == NULL) + throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL); + + // Create a framework view. + ::Window* pControl = NULL; + +#define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t)) + if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations)) + pControl = new CustomAnimationPanel(pParentWindow, *pBase); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts)) + pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages)) + pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages)) + pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages)) + pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions)) + pControl = new SlideTransitionPanel(pParentWindow, *pBase); + else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign)) + pControl = new TableDesignPanel(pParentWindow, *pBase); +#undef EndsWith + + if (pControl == NULL) + throw lang::IllegalArgumentException(); + + // Create a wrapper around pane and view and return it as + // XUIElement. + Reference<ui::XUIElement> xUIElement; + try + { + xUIElement.set( + sfx2::sidebar::SidebarPanelBase::Create( + rsUIElementResourceURL, + xFrame, + pControl, + ui::LayoutSize(-1,-1,-1))); + } + catch(Exception& rException) + { + // Creation of XUIElement failed. mxUIElement remains empty. + } + + Reference<lang::XComponent> xComponent (xUIElement, UNO_QUERY); + if (xComponent.is()) + xComponent->addEventListener(this); + + return xUIElement; +} + + + + +void SAL_CALL SidebarFactory::disposing (const ::css::lang::EventObject& rEvent) + throw(cssu::RuntimeException) +{ + /* + if (mpImplementation + && rEvent.Source == mpImplementation->mxUIElement) + { + mpImplementation->mxUIElement.clear(); + } + */ +} + + + + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/SidebarFactory.hxx b/sd/source/ui/sidebar/SidebarFactory.hxx new file mode 100644 index 000000000000..0b4ae9542bf6 --- /dev/null +++ b/sd/source/ui/sidebar/SidebarFactory.hxx @@ -0,0 +1,120 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_FACTORY_HXX +#define SD_SIDEBAR_FACTORY_HXX + +#include <cppuhelper/compbase4.hxx> +#include <cppuhelper/basemutex.hxx> +#include <rtl/ref.hxx> +#include "framework/Pane.hxx" + +#include <com/sun/star/ui/XUIElementFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XInitialization.hpp> + +#include <map> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> + + +namespace css = ::com::sun::star; +namespace cssu = ::com::sun::star::uno; + + +namespace sd { + class ViewShellBase; +} + +namespace sd { namespace sidebar { + +namespace +{ + typedef ::cppu::WeakComponentImplHelper3 < + css::lang::XInitialization, + css::ui::XUIElementFactory, + css::lang::XEventListener + > SidebarFactoryInterfaceBase; +} + + +/** This factory creates both XUIElements (for sidebar panels) and + a drawing framework pane. + + The drawing framework pane is a container for the SidebarViewShell + which is necessary to run the legacy implementations of the task + pane panels. + + Control and information flow is like this: + + When one of the old task panels is requested to be displayed in + the sidebar this factory is called for + XUIElementFactory::createUIElement(). + One of the arguments, the window, is then exported into the + drawing framework as pane. After this the drawing framework is + used to create the SidebarViewShell (once known as + TaskPaneViewShell or ToolPanelViewShell) and the requested panel. +*/ +class SidebarFactory + : private ::boost::noncopyable, + private ::cppu::BaseMutex, + public SidebarFactoryInterfaceBase +{ +public: + static ::rtl::OUString SAL_CALL getImplementationName (void); + static cssu::Reference<cssu::XInterface> SAL_CALL createInstance ( + const cssu::Reference<css::lang::XMultiServiceFactory>& rxFactory); + static cssu::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames (void); + + SidebarFactory (const cssu::Reference<cssu::XComponentContext>& rxContext); + virtual ~SidebarFactory (void); + + virtual void SAL_CALL disposing (void); + + + // XInitialization + + virtual void SAL_CALL initialize( + const css::uno::Sequence<css::uno::Any>& aArguments) + throw (css::uno::Exception, css::uno::RuntimeException); + + + // XUIElementFactory + + cssu::Reference<css::ui::XUIElement> SAL_CALL createUIElement ( + const ::rtl::OUString& rsResourceURL, + const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) + throw( + css::container::NoSuchElementException, + css::lang::IllegalArgumentException, + cssu::RuntimeException); + + + // XEventListener + + virtual void SAL_CALL disposing (const ::css::lang::EventObject& rEvent) + throw(cssu::RuntimeException); +}; + + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/SidebarFocusManager.hxx b/sd/source/ui/sidebar/SidebarFocusManager.hxx new file mode 100644 index 000000000000..c77b5a96126d --- /dev/null +++ b/sd/source/ui/sidebar/SidebarFocusManager.hxx @@ -0,0 +1,130 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + + +#ifndef SD_TOOLPANEL_FOCUS_MANAGER_HXX +#define SD_TOOLPANEL_FOCUS_MANAGER_HXX + +#include <tools/link.hxx> + +#include <memory> + +class KeyCode; +class VclSimpleEvent; +class Window; + +namespace sd { namespace toolpanel { + +/** On certain key presses the focus is moved from one window to another. + For this to work every window that wants its focus managed has to + register or be registered and tell where to put the focus on what key + press. +*/ +class FocusManager +{ +public: + /** Return an instance of the focus manager. + */ + static FocusManager& Instance (void); + + /** Register a link from one window to another so that any time the + specified key is pressed while the source window is focused, the + focus is transferred to the target window. + @param pSource + The window from which the focus will be transferred. + @param pTarget + The window to which the focus will be transferred. + @param rKey + The key for which the focus is transferred from the source + window to the target window. + */ + void RegisterLink ( + ::Window* pSource, + ::Window* pTarget, + const KeyCode& rKey); + + /** Register a link that will move the focus from the source window to + the target window when the source window is focused and KEY_ESCAPE + is pressed. + @param pSource + The window from which the focus will be transferred. + @param pTarget + The window to which the focus will be transferred. + */ + void RegisterUpLink (::Window* pSource, ::Window* pTarget); + + /** Register a link that will move the focus from the source window to + the target window when the source window is focused and KEY_RETURN + is pressed. + @param pSource + The window from which the focus will be transferred. + @param pTarget + The window to which the focus will be transferred. + */ + void RegisterDownLink (::Window* pSource, ::Window* pTarget); + + /** Remove all links from the source window to the target window. When + there are links from the target window to the source window then + these are not touced. + */ + void RemoveLinks ( + ::Window* pSource, + ::Window* pTarget); + + /** Let the focus manager transfer the focus from the specified source + window to a target window that is determined according the the + registered links and the given key code. + When there is no rule for this combination of source window and key + code then the focus stays where it is. + */ + bool TransferFocus (::Window* pSource, const KeyCode& rCode); + +private: + class LinkMap; + ::std::auto_ptr<LinkMap> mpLinks; + + FocusManager (void); + ~FocusManager (void); + + /** Clear the list of focus transfer links. This removes all window + listeners. + */ + void Clear (void); + + /** Remove all links from or to the given window. + */ + void RemoveLinks (::Window* pWindow); + + /** Unregister as event listener from the given window when there are no + links from this window anymore. + */ + void RemoveUnusedEventListener (::Window* pWindow); + + /** Listen for key events and on KEY_RETURN go down and on + KEY_ESCAPE go up. + */ + DECL_LINK(WindowEventListener, VclSimpleEvent*); +}; + +} } // end of namespace ::sd::toolpanel + +#endif diff --git a/sd/source/ui/sidebar/SidebarShellManager.cxx b/sd/source/ui/sidebar/SidebarShellManager.cxx new file mode 100644 index 000000000000..ffecd014c5f9 --- /dev/null +++ b/sd/source/ui/sidebar/SidebarShellManager.cxx @@ -0,0 +1,176 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "SidebarShellManager.hxx" + +#include "ViewShellManager.hxx" +#include <tools/diagnose_ex.h> +#include <vcl/window.hxx> + +#include <algorithm> + +namespace sd { namespace sidebar { + +SidebarShellManager::SidebarShellManager ( + const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager, + const ViewShell& rViewShell) + : mpViewShellManager(rpViewShellManager), + mrViewShell(rViewShell), + maSubShells() +{ +} + + + + +SidebarShellManager::~SidebarShellManager (void) +{ + while ( ! maSubShells.empty()) + RemoveSubShell(maSubShells.begin()->second.mpShell); +} + + + + +SfxShell* SidebarShellManager::CreateShell( ShellId nId, ::Window* , FrameView* ) +{ + SubShells::const_iterator iShell (maSubShells.find(nId)); + if (iShell != maSubShells.end()) + return iShell->second.mpShell; + else + return NULL; +} + + + + +void SidebarShellManager::ReleaseShell (SfxShell* ) +{ + // Nothing to do. +} + +void SidebarShellManager::AddSubShell ( + ShellId nId, + SfxShell* pShell, + ::Window* pWindow) +{ + if (pShell != NULL) + { + maSubShells[nId] = ShellDescriptor(pShell,pWindow); + if (pWindow != NULL) + { + pWindow->AddEventListener(LINK(this,SidebarShellManager,WindowCallback)); + if (pWindow->IsReallyVisible()) + mpViewShellManager->ActivateSubShell(mrViewShell, nId); + } + else + mpViewShellManager->ActivateSubShell(mrViewShell, nId); + } +} + + + + +void SidebarShellManager::RemoveSubShell (const ShellId i_nShellId) +{ + SubShells::iterator pos = maSubShells.find( i_nShellId ); + ENSURE_OR_RETURN_VOID( pos != maSubShells.end(), "no shell for this ID" ); + if ( pos->second.mpWindow != NULL ) + { + pos->second.mpWindow->RemoveEventListener( LINK( this, SidebarShellManager, WindowCallback ) ); + } + mpViewShellManager->DeactivateSubShell( mrViewShell, pos->first ); + maSubShells.erase( pos ); +} + + + + +void SidebarShellManager::RemoveSubShell (const SfxShell* pShell) +{ + if (pShell != NULL) + { + SubShells::iterator iShell; + for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell) + if (iShell->second.mpShell == pShell) + { + if (iShell->second.mpWindow != NULL) + iShell->second.mpWindow->RemoveEventListener( + LINK(this,SidebarShellManager,WindowCallback)); + mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first); + maSubShells.erase(iShell); + break; + } + } +} + + + + +void SidebarShellManager::MoveToTop (SfxShell* pShell) +{ + SubShells::const_iterator iShell; + for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell) + if (iShell->second.mpShell == pShell) + { + ViewShellManager::UpdateLock aLocker (mpViewShellManager); + mpViewShellManager->MoveSubShellToTop(mrViewShell,iShell->first); + mpViewShellManager->MoveToTop(mrViewShell); + break; + } +} + + + + +IMPL_LINK(SidebarShellManager, WindowCallback, VclWindowEvent*, pEvent) +{ + if (pEvent != NULL) + { + SubShells::const_iterator iShell; + ::Window* pWindow = pEvent->GetWindow(); + for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell) + if (iShell->second.mpWindow == pWindow) + break; + if (iShell != maSubShells.end()) + switch (pEvent->GetId()) + { + case VCLEVENT_WINDOW_SHOW: + mpViewShellManager->ActivateSubShell(mrViewShell,iShell->first); + break; + + case VCLEVENT_WINDOW_HIDE: + // Do not activate the sub shell. This leads to + // problems with shapes currently being in text edit + // mode: Deactivating the shell leads to leaving the + // text editing mode. + // mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first); + break; + } + } + + return 0; +} + + +} } // end of namespace ::sd::sidebar diff --git a/sd/source/ui/sidebar/SidebarShellManager.hxx b/sd/source/ui/sidebar/SidebarShellManager.hxx new file mode 100644 index 000000000000..809f8ecf883e --- /dev/null +++ b/sd/source/ui/sidebar/SidebarShellManager.hxx @@ -0,0 +1,117 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + + +#ifndef SD_SIDEBAR_SHELL_MANAGER_HXX +#define SD_SIDEBAR_SHELL_MANAGER_HXX + +#include "ShellFactory.hxx" +#include "ViewShellManager.hxx" +#include <map> + +class FrameView; +class SfxShell; +class VclWindowEvent; +class Window; + +namespace sd { +class ViewShell; +} + +namespace sd { namespace sidebar { + +/** The TaskPaneShellManager implements the ViewShellManager::ShellFactory + interface. However, it does not create or delete shells. It only + gives the ViewShellManager access to the sub shells of the + ToolPanelViewShell. Life time control of the sub shells is managed by + the sub shells themselves. +*/ +class SidebarShellManager + : public ShellFactory<SfxShell> +{ +public: + /** Create a shell manager that manages the stacked shells for the given + view shell. It works together with the given view shell manager. + */ + SidebarShellManager ( + const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager, + const ViewShell& rViewShell); + ~SidebarShellManager (void); + + /** Return the requested sub shell. + @param nId + The id of the requested sub shell. + @return + When there is no sub shell currently registered under the given + id then NULL is returned. + */ + virtual SfxShell* CreateShell ( + ShellId nId, + ::Window* pParentWindow, + FrameView* pFrameView = NULL); + + virtual void ReleaseShell (SfxShell* pShell); + + /** Add a sub shell to the set of sub shells managed by the + TaskPaneShellManager. Only shells added by this method are returned + by CreateShell(). + */ + void AddSubShell (ShellId nId, SfxShell* pShell, ::Window* pWindow); + + /** Remove the given shell from the set of sub shells managed by the + TaskPaneShellManager. Following calls to CreateShell() will return + NULL when this shell is requested. + */ + void RemoveSubShell (const SfxShell* pShell); + /** removes the shell given by its ID from the set of sub shells managed by the + TaskPaneShellManager. Subsequent calls to CreateShell() will return + NULL when this shell is requested. + */ + void RemoveSubShell (const ShellId i_nShellId); + + /** Move the given sub-shell to the top of the local shell stack. + Furthermore move the view shell whose sub-shells this class manages + to the top of the global shell stack. + */ + void MoveToTop (SfxShell* pShell); + + DECL_LINK(WindowCallback,VclWindowEvent*); + +private: + ::boost::shared_ptr<ViewShellManager> mpViewShellManager; + + /// The view shell whose sub-shells this class manages. + const ViewShell& mrViewShell; + + class ShellDescriptor { public: + SfxShell* mpShell; + ::Window* mpWindow; + ShellDescriptor(void) : mpShell(NULL),mpWindow(NULL){} + ShellDescriptor(SfxShell*pShell,::Window*pWindow) : mpShell(pShell),mpWindow(pWindow){} + }; + typedef ::std::map<ShellId,ShellDescriptor> SubShells; + SubShells maSubShells; +}; + +} } // end of namespace ::sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/SlideTransitionPanel.cxx b/sd/source/ui/sidebar/SlideTransitionPanel.cxx new file mode 100644 index 000000000000..c23ebc135c7c --- /dev/null +++ b/sd/source/ui/sidebar/SlideTransitionPanel.cxx @@ -0,0 +1,76 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "SlideTransitionPanel.hxx" + +#include "ViewShellBase.hxx" + + +namespace sd { + extern ::Window* createSlideTransitionPanel (::Window* pParent, ViewShellBase& rBase); + extern sal_Int32 getSlideTransitionPanelMinimumHeight (::Window* pParent); +} + + + + +namespace sd { namespace sidebar { + + +SlideTransitionPanel::SlideTransitionPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) + : PanelBase(pParentWindow, rViewShellBase) +{ +#ifdef DEBUG + SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:SlideTransitionPanel"))); +#endif +} + + + + +SlideTransitionPanel::~SlideTransitionPanel (void) +{ +} + + + + +::Window* SlideTransitionPanel::CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) +{ + return createSlideTransitionPanel(pParentWindow, rViewShellBase); +} + + + + +css::ui::LayoutSize SlideTransitionPanel::GetHeightForWidth (const sal_Int32 nWidth) +{ + const sal_Int32 nMinimumHeight(getSlideTransitionPanelMinimumHeight(mpWrappedControl.get())); + return css::ui::LayoutSize(nMinimumHeight,-1, nMinimumHeight); +} + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/SlideTransitionPanel.hxx b/sd/source/ui/sidebar/SlideTransitionPanel.hxx new file mode 100644 index 000000000000..f3843bc26b14 --- /dev/null +++ b/sd/source/ui/sidebar/SlideTransitionPanel.hxx @@ -0,0 +1,51 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + +#ifndef SD_SIDEBAR_PANELS_SLIDE_TRANSITION_PANEL_HXX +#define SD_SIDEBAR_PANELS_SLIDE_TRANSITION_PANEL_HXX + +#include "PanelBase.hxx" + +namespace sd { namespace sidebar { + +class SlideTransitionPanel + : public PanelBase +{ +public: + SlideTransitionPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); + virtual ~SlideTransitionPanel (void); + + // ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + +protected: + virtual ::Window* CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); +}; + +} } // end of namespace sd::sidebar + + +#endif diff --git a/sd/source/ui/sidebar/TableDesignPanel.cxx b/sd/source/ui/sidebar/TableDesignPanel.cxx new file mode 100644 index 000000000000..27df5b584a65 --- /dev/null +++ b/sd/source/ui/sidebar/TableDesignPanel.cxx @@ -0,0 +1,73 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "precompiled_sd.hxx" + +#include "TableDesignPanel.hxx" + +#include "ViewShellBase.hxx" + + +namespace sd { + extern ::Window * createTableDesignPanel (::Window* pParent, ViewShellBase& rBase); +} + + +namespace sd { namespace sidebar { + + +TableDesignPanel::TableDesignPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) + : PanelBase(pParentWindow, rViewShellBase) +{ +#ifdef DEBUG + SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:TableDesignPanel"))); +#endif +} + + + + +TableDesignPanel::~TableDesignPanel (void) +{ +} + + + + +::Window* TableDesignPanel::CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase) +{ + return createTableDesignPanel(pParentWindow, rViewShellBase); +} + + + + +css::ui::LayoutSize TableDesignPanel::GetHeightForWidth (const sal_Int32 nWidth) +{ + //TODO: make the sizes depend on the font size. + return css::ui::LayoutSize(350,-1, 400); +} + +} } // end of namespace sd::sidebar diff --git a/sd/source/ui/sidebar/TableDesignPanel.hxx b/sd/source/ui/sidebar/TableDesignPanel.hxx new file mode 100644 index 000000000000..75bf411640d3 --- /dev/null +++ b/sd/source/ui/sidebar/TableDesignPanel.hxx @@ -0,0 +1,49 @@ +/************************************************************** + * + * 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 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SD_SIDEBAR_PANELS_TABLE_DESIGN_PANEL_HXX +#define SD_SIDEBAR_PANELS_TABLE_DESIGN_PANEL_HXX + +#include "PanelBase.hxx" + +namespace sd { namespace sidebar { + +class TableDesignPanel + : public PanelBase +{ +public: + TableDesignPanel ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); + virtual ~TableDesignPanel (void); + + // ILayoutableWindow + virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth); + +protected: + virtual ::Window* CreateWrappedControl ( + ::Window* pParentWindow, + ViewShellBase& rViewShellBase); +}; + +} } // end of namespace sd::sidebar + +#endif diff --git a/sd/source/ui/sidebar/makefile.mk b/sd/source/ui/sidebar/makefile.mk new file mode 100644 index 000000000000..eb23504bebe1 --- /dev/null +++ b/sd/source/ui/sidebar/makefile.mk @@ -0,0 +1,65 @@ +#************************************************************** +# +# 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 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** + + + +PRJ=..$/..$/.. + +PROJECTPCH=sd +PROJECTPCHSOURCE=$(PRJ)$/util$/sd +PRJNAME=sd +TARGET=sidebar +ENABLE_EXCEPTIONS=TRUE +AUTOSEG=true +PRJINC=.. + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/AllMasterPagesSelector.obj \ + $(SLO)$/CurrentMasterPagesSelector.obj \ + $(SLO)$/CustomAnimationPanel.obj \ + $(SLO)$/DocumentHelper.obj \ + $(SLO)$/LayoutMenu.obj \ + $(SLO)$/MasterPageContainer.obj \ + $(SLO)$/MasterPageContainerFiller.obj \ + $(SLO)$/MasterPageContainerProviders.obj\ + $(SLO)$/MasterPageContainerQueue.obj \ + $(SLO)$/MasterPageDescriptor.obj \ + $(SLO)$/MasterPageObserver.obj \ + $(SLO)$/MasterPagesSelector.obj \ + $(SLO)$/NavigatorWrapper.obj \ + $(SLO)$/PanelBase.obj \ + $(SLO)$/PanelFactory.obj \ + $(SLO)$/PreviewValueSet.obj \ + $(SLO)$/RecentlyUsedMasterPages.obj \ + $(SLO)$/RecentMasterPagesSelector.obj \ + $(SLO)$/SlideTransitionPanel.obj + +# --- Tagets ------------------------------------------------------- + +.INCLUDE : target.mk + |