122de8995SAndre Fischer /**************************************************************
222de8995SAndre Fischer  *
322de8995SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
422de8995SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
522de8995SAndre Fischer  * distributed with this work for additional information
622de8995SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
722de8995SAndre Fischer  * to you under the Apache License, Version 2.0 (the
822de8995SAndre Fischer  * "License"); you may not use this file except in compliance
922de8995SAndre Fischer  * with the License.  You may obtain a copy of the License at
1022de8995SAndre Fischer  *
1122de8995SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1222de8995SAndre Fischer  *
1322de8995SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1422de8995SAndre Fischer  * software distributed under the License is distributed on an
1522de8995SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1622de8995SAndre Fischer  * KIND, either express or implied.  See the License for the
1722de8995SAndre Fischer  * specific language governing permissions and limitations
1822de8995SAndre Fischer  * under the License.
1922de8995SAndre Fischer  *
2022de8995SAndre Fischer  *************************************************************/
2122de8995SAndre Fischer 
2222de8995SAndre Fischer #include "precompiled_sfx2.hxx"
2322de8995SAndre Fischer 
2422de8995SAndre Fischer #include "SidebarController.hxx"
2522de8995SAndre Fischer #include "Deck.hxx"
267a32b0c8SAndre Fischer #include "DeckTitleBar.hxx"
2722de8995SAndre Fischer #include "Panel.hxx"
28b9e67834SAndre Fischer #include "SidebarPanel.hxx"
29ff12d537SAndre Fischer #include "SidebarResource.hxx"
3022de8995SAndre Fischer #include "TabBar.hxx"
31b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
3213e1c3b4SAndre Fischer #include "sfx2/sidebar/SidebarChildWindow.hxx"
33f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
347a32b0c8SAndre Fischer #include "SidebarDockingWindow.hxx"
357a32b0c8SAndre Fischer #include "Context.hxx"
36ff12d537SAndre Fischer 
3722de8995SAndre Fischer #include "sfxresid.hxx"
3822de8995SAndre Fischer #include "sfx2/sfxsids.hrc"
397a32b0c8SAndre Fischer #include "sfx2/titledockwin.hxx"
40ff12d537SAndre Fischer #include "sfxlocal.hrc"
41ff12d537SAndre Fischer #include <vcl/floatwin.hxx>
4213e1c3b4SAndre Fischer #include <vcl/fixed.hxx>
437a32b0c8SAndre Fischer #include "splitwin.hxx"
4495a18594SAndre Fischer #include <svl/smplhint.hxx>
4595a18594SAndre Fischer #include <tools/link.hxx>
4622f77e9eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
4722f77e9eSAndre Fischer 
48ff12d537SAndre Fischer #include <comphelper/componentfactory.hxx>
4995a18594SAndre Fischer #include <comphelper/processfactory.hxx>
50ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx>
51ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
5222de8995SAndre Fischer 
53f120fe41SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp>
54f120fe41SAndre Fischer #include <com/sun/star/lang/XInitialization.hpp>
5522de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
5622de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp>
5795a18594SAndre Fischer #include <com/sun/star/ui/XUIElementFactory.hpp>
58f120fe41SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp>
59f120fe41SAndre Fischer #include <com/sun/star/util/URL.hpp>
6022f77e9eSAndre Fischer #include <com/sun/star/rendering/XSpriteCanvas.hpp>
6122de8995SAndre Fischer 
6222de8995SAndre Fischer #include <boost/bind.hpp>
63f120fe41SAndre Fischer #include <boost/function.hpp>
647a32b0c8SAndre Fischer #include <boost/scoped_array.hpp>
6522de8995SAndre Fischer 
6622de8995SAndre Fischer 
6722de8995SAndre Fischer using namespace css;
6822de8995SAndre Fischer using namespace cssu;
6995a18594SAndre Fischer using ::rtl::OUString;
7022de8995SAndre Fischer 
7102c50d82SAndre Fischer 
7256798e4bSAndre Fischer #undef VERBOSE
7322de8995SAndre Fischer 
7413e1c3b4SAndre Fischer namespace
7513e1c3b4SAndre Fischer {
7613e1c3b4SAndre Fischer     const static OUString gsReadOnlyCommandName (A2S(".uno:EditDoc"));
7713e1c3b4SAndre Fischer     const static sal_Int32 gnMaximumSidebarWidth (400);
7813e1c3b4SAndre Fischer     const static sal_Int32 gnWidthCloseThreshold (70);
7913e1c3b4SAndre Fischer     const static sal_Int32 gnWidthOpenThreshold (40);
8013e1c3b4SAndre Fischer }
8113e1c3b4SAndre Fischer 
8213e1c3b4SAndre Fischer 
83ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
8422de8995SAndre Fischer 
85ff12d537SAndre Fischer namespace {
86ff12d537SAndre Fischer     enum MenuId
87ff12d537SAndre Fischer     {
88ff12d537SAndre Fischer         MID_UNLOCK_TASK_PANEL = 1,
89ff12d537SAndre Fischer         MID_LOCK_TASK_PANEL,
90ff12d537SAndre Fischer         MID_CUSTOMIZATION,
91ff12d537SAndre Fischer         MID_RESTORE_DEFAULT,
92ff12d537SAndre Fischer         MID_FIRST_PANEL,
93ff12d537SAndre Fischer         MID_FIRST_HIDE = 1000
94ff12d537SAndre Fischer     };
95ff12d537SAndre Fischer }
9622de8995SAndre Fischer 
9722de8995SAndre Fischer 
9822de8995SAndre Fischer SidebarController::SidebarController (
997a32b0c8SAndre Fischer     SidebarDockingWindow* pParentWindow,
10022de8995SAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame)
10122de8995SAndre Fischer     : SidebarControllerInterfaceBase(m_aMutex),
102f120fe41SAndre Fischer       mpCurrentDeck(),
10322de8995SAndre Fischer       mpParentWindow(pParentWindow),
104ff12d537SAndre Fischer       mpTabBar(new TabBar(
105ff12d537SAndre Fischer               mpParentWindow,
106ff12d537SAndre Fischer               rxFrame,
10713e1c3b4SAndre Fischer               ::boost::bind(&SidebarController::OpenThenSwitchToDeck, this, _1),
10895a18594SAndre Fischer               ::boost::bind(&SidebarController::ShowPopupMenu, this, _1,_2,_3))),
10995a18594SAndre Fischer       mxFrame(rxFrame),
1107a32b0c8SAndre Fischer       maCurrentContext(OUString(), OUString()),
111*52d13b84SAndre Fischer       maRequestedContext(),
11295a18594SAndre Fischer       msCurrentDeckId(A2S("PropertyDeck")),
113*52d13b84SAndre Fischer       msCurrentDeckTitle(),
1147a32b0c8SAndre Fischer       maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)),
115239cbbc0SAndre Fischer       maContextChangeUpdate(::boost::bind(&SidebarController::UpdateConfigurations, this)),
11613e1c3b4SAndre Fischer       mbIsDeckRequestedOpen(),
11713e1c3b4SAndre Fischer       mbIsDeckOpen(),
11813e1c3b4SAndre Fischer       mbCanDeckBeOpened(true),
11913e1c3b4SAndre Fischer       mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()),
120*52d13b84SAndre Fischer       maFocusManager(::boost::bind(&SidebarController::ShowPanel, this, _1)),
12113e1c3b4SAndre Fischer       mxReadOnlyModeDispatch(),
12213e1c3b4SAndre Fischer       mbIsDocumentReadOnly(false),
12313e1c3b4SAndre Fischer       mpSplitWindow(NULL),
12413e1c3b4SAndre Fischer       mnWidthOnSplitterButtonDown(0),
12513e1c3b4SAndre Fischer       mpCloseIndicator()
12622de8995SAndre Fischer {
12722de8995SAndre Fischer     if (pParentWindow == NULL)
12822de8995SAndre Fischer     {
12922de8995SAndre Fischer         OSL_ASSERT(pParentWindow!=NULL);
13022de8995SAndre Fischer             return;
13122de8995SAndre Fischer     }
13222de8995SAndre Fischer 
13322de8995SAndre Fischer     // Listen for context change events.
13422de8995SAndre Fischer     cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
13522de8995SAndre Fischer         css::ui::ContextChangeEventMultiplexer::get(
13622de8995SAndre Fischer             ::comphelper::getProcessComponentContext()));
13722de8995SAndre Fischer     if (xMultiplexer.is())
13822de8995SAndre Fischer         xMultiplexer->addContextChangeEventListener(
13922de8995SAndre Fischer             static_cast<css::ui::XContextChangeEventListener*>(this),
14095a18594SAndre Fischer             mxFrame->getController());
14122de8995SAndre Fischer 
14222de8995SAndre Fischer     // Listen for window events.
14322de8995SAndre Fischer     mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
144b9e67834SAndre Fischer 
145b9e67834SAndre Fischer     // Listen for theme property changes.
146b9e67834SAndre Fischer     Theme::GetPropertySet()->addPropertyChangeListener(
147b9e67834SAndre Fischer         A2S(""),
148b9e67834SAndre Fischer         static_cast<css::beans::XPropertyChangeListener*>(this));
149f120fe41SAndre Fischer 
15013e1c3b4SAndre Fischer     // Get the dispatch object as preparation to listen for changes of
15113e1c3b4SAndre Fischer     // the read-only state.
152f35c6d02SAndre Fischer     const util::URL aURL (Tools::GetURL(gsReadOnlyCommandName));
153f35c6d02SAndre Fischer     mxReadOnlyModeDispatch = Tools::GetDispatch(mxFrame, aURL);
15413e1c3b4SAndre Fischer     if (mxReadOnlyModeDispatch.is())
15513e1c3b4SAndre Fischer         mxReadOnlyModeDispatch->addStatusListener(this, aURL);
15613e1c3b4SAndre Fischer 
157f120fe41SAndre Fischer     SwitchToDeck(A2S("default"));
15822de8995SAndre Fischer }
15922de8995SAndre Fischer 
16022de8995SAndre Fischer 
16122de8995SAndre Fischer 
16222de8995SAndre Fischer 
16322de8995SAndre Fischer SidebarController::~SidebarController (void)
16422de8995SAndre Fischer {
16522de8995SAndre Fischer }
16622de8995SAndre Fischer 
16722de8995SAndre Fischer 
16822de8995SAndre Fischer 
16922de8995SAndre Fischer 
17022de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void)
17122de8995SAndre Fischer {
17265908a7eSAndre Fischer     maFocusManager.Clear();
17365908a7eSAndre Fischer 
17422de8995SAndre Fischer     cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
17522de8995SAndre Fischer         css::ui::ContextChangeEventMultiplexer::get(
17622de8995SAndre Fischer             ::comphelper::getProcessComponentContext()));
17722de8995SAndre Fischer     if (xMultiplexer.is())
17822de8995SAndre Fischer         xMultiplexer->removeAllContextChangeEventListeners(
17922de8995SAndre Fischer             static_cast<css::ui::XContextChangeEventListener*>(this));
18022de8995SAndre Fischer 
18113e1c3b4SAndre Fischer     if (mxReadOnlyModeDispatch.is())
182f35c6d02SAndre Fischer         mxReadOnlyModeDispatch->removeStatusListener(this, Tools::GetURL(gsReadOnlyCommandName));
18313e1c3b4SAndre Fischer     if (mpSplitWindow != NULL)
18413e1c3b4SAndre Fischer     {
18513e1c3b4SAndre Fischer         mpSplitWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
18613e1c3b4SAndre Fischer         mpSplitWindow = NULL;
18713e1c3b4SAndre Fischer     }
18813e1c3b4SAndre Fischer 
18922de8995SAndre Fischer     if (mpParentWindow != NULL)
19022de8995SAndre Fischer     {
19122de8995SAndre Fischer         mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
19222de8995SAndre Fischer         mpParentWindow = NULL;
19322de8995SAndre Fischer     }
194b9e67834SAndre Fischer 
195f120fe41SAndre Fischer     if (mpCurrentDeck)
196b9e67834SAndre Fischer     {
197f120fe41SAndre Fischer         mpCurrentDeck->Dispose();
198f120fe41SAndre Fischer         mpCurrentDeck->PrintWindowTree();
199f120fe41SAndre Fischer         mpCurrentDeck.reset();
200b9e67834SAndre Fischer     }
201b9e67834SAndre Fischer 
202580828edSAndre Fischer     mpTabBar.reset();
203580828edSAndre Fischer 
204b9e67834SAndre Fischer     Theme::GetPropertySet()->removePropertyChangeListener(
205b9e67834SAndre Fischer         A2S(""),
206b9e67834SAndre Fischer         static_cast<css::beans::XPropertyChangeListener*>(this));
20722de8995SAndre Fischer }
20822de8995SAndre Fischer 
20922de8995SAndre Fischer 
21022de8995SAndre Fischer 
21122de8995SAndre Fischer 
21222de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
21322de8995SAndre Fischer     throw(cssu::RuntimeException)
21422de8995SAndre Fischer {
215239cbbc0SAndre Fischer     // Update to the requested new context asynchronously to avoid
216239cbbc0SAndre Fischer     // subtle errors caused by SFX2 which in rare cases can not
217239cbbc0SAndre Fischer     // properly handle a synchronous update.
218239cbbc0SAndre Fischer     maRequestedContext = Context(
219239cbbc0SAndre Fischer         rEvent.ApplicationName,
220239cbbc0SAndre Fischer         rEvent.ContextName);
221239cbbc0SAndre Fischer     if (maRequestedContext != maCurrentContext)
222239cbbc0SAndre Fischer         maContextChangeUpdate.RequestCall();
22322de8995SAndre Fischer }
22422de8995SAndre Fischer 
22522de8995SAndre Fischer 
22622de8995SAndre Fischer 
22722de8995SAndre Fischer 
22822de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject)
22922de8995SAndre Fischer     throw(cssu::RuntimeException)
23022de8995SAndre Fischer {
23195a18594SAndre Fischer     (void)rEventObject;
232f120fe41SAndre Fischer 
233f120fe41SAndre Fischer     dispose();
23422de8995SAndre Fischer }
23522de8995SAndre Fischer 
23622de8995SAndre Fischer 
23722de8995SAndre Fischer 
23822de8995SAndre Fischer 
239b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent)
240b9e67834SAndre Fischer     throw(cssu::RuntimeException)
24195a18594SAndre Fischer {
24295a18594SAndre Fischer     (void)rEvent;
24395a18594SAndre Fischer 
24495a18594SAndre Fischer     maPropertyChangeForwarder.RequestCall();
24595a18594SAndre Fischer }
24695a18594SAndre Fischer 
24795a18594SAndre Fischer 
24895a18594SAndre Fischer 
24995a18594SAndre Fischer 
25013e1c3b4SAndre Fischer void SAL_CALL SidebarController::statusChanged (const css::frame::FeatureStateEvent& rEvent)
25113e1c3b4SAndre Fischer     throw(cssu::RuntimeException)
25213e1c3b4SAndre Fischer {
25313e1c3b4SAndre Fischer     bool bIsReadWrite (true);
25413e1c3b4SAndre Fischer     if (rEvent.IsEnabled)
25513e1c3b4SAndre Fischer         rEvent.State >>= bIsReadWrite;
25613e1c3b4SAndre Fischer 
25713e1c3b4SAndre Fischer     if (mbIsDocumentReadOnly != !bIsReadWrite)
25813e1c3b4SAndre Fischer     {
25913e1c3b4SAndre Fischer         mbIsDocumentReadOnly = !bIsReadWrite;
26013e1c3b4SAndre Fischer 
26113e1c3b4SAndre Fischer         // Force the current deck to update its panel list.
26213e1c3b4SAndre Fischer         SwitchToDeck(msCurrentDeckId);
26313e1c3b4SAndre Fischer     }
26413e1c3b4SAndre Fischer }
26513e1c3b4SAndre Fischer 
26613e1c3b4SAndre Fischer 
26713e1c3b4SAndre Fischer 
26813e1c3b4SAndre Fischer 
2697a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void)
2707a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2717a32b0c8SAndre Fischer {
272f120fe41SAndre Fischer     if (mpCurrentDeck)
273f120fe41SAndre Fischer         mpCurrentDeck->RequestLayout();
2747a32b0c8SAndre Fischer     RestrictWidth();
2757a32b0c8SAndre Fischer }
2767a32b0c8SAndre Fischer 
2777a32b0c8SAndre Fischer 
2787a32b0c8SAndre Fischer 
2797a32b0c8SAndre Fischer 
28095a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void)
281b9e67834SAndre Fischer {
282b9e67834SAndre Fischer     DataChangedEvent aEvent (DATACHANGED_USER);
283b9e67834SAndre Fischer     mpParentWindow->NotifyAllChilds(aEvent);
284b9e67834SAndre Fischer     mpParentWindow->Invalidate(INVALIDATE_CHILDREN);
285b9e67834SAndre Fischer }
286b9e67834SAndre Fischer 
287b9e67834SAndre Fischer 
288b9e67834SAndre Fischer 
289b9e67834SAndre Fischer 
29022de8995SAndre Fischer void SidebarController::NotifyResize (void)
29122de8995SAndre Fischer {
29295a18594SAndre Fischer     if (mpTabBar == NULL)
29395a18594SAndre Fischer     {
29495a18594SAndre Fischer         OSL_ASSERT(mpTabBar!=NULL);
29595a18594SAndre Fischer         return;
29695a18594SAndre Fischer     }
29795a18594SAndre Fischer 
29895a18594SAndre Fischer     Window* pParentWindow = mpTabBar->GetParent();
29995a18594SAndre Fischer 
30095a18594SAndre Fischer     const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width());
30195a18594SAndre Fischer     const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height());
30295a18594SAndre Fischer 
30313e1c3b4SAndre Fischer     mbIsDeckOpen = (nWidth > TabBar::GetDefaultWidth());
30413e1c3b4SAndre Fischer 
30513e1c3b4SAndre Fischer     if (mnSavedSidebarWidth <= 0)
30613e1c3b4SAndre Fischer         mnSavedSidebarWidth = nWidth;
30713e1c3b4SAndre Fischer 
30813e1c3b4SAndre Fischer     bool bIsDeckVisible;
30913e1c3b4SAndre Fischer     if (mbCanDeckBeOpened)
31013e1c3b4SAndre Fischer     {
31113e1c3b4SAndre Fischer         const bool bIsOpening (nWidth > mnWidthOnSplitterButtonDown);
31213e1c3b4SAndre Fischer         if (bIsOpening)
31313e1c3b4SAndre Fischer             bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthOpenThreshold;
31413e1c3b4SAndre Fischer         else
31513e1c3b4SAndre Fischer             bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthCloseThreshold;
31613e1c3b4SAndre Fischer         mbIsDeckRequestedOpen = bIsDeckVisible;
31713e1c3b4SAndre Fischer         UpdateCloseIndicator(!bIsDeckVisible);
31813e1c3b4SAndre Fischer     }
31913e1c3b4SAndre Fischer     else
32013e1c3b4SAndre Fischer         bIsDeckVisible = false;
32113e1c3b4SAndre Fischer 
3227a32b0c8SAndre Fischer     // Place the deck.
323f120fe41SAndre Fischer     if (mpCurrentDeck)
3247a32b0c8SAndre Fischer     {
32513e1c3b4SAndre Fischer         if (bIsDeckVisible)
32613e1c3b4SAndre Fischer         {
32713e1c3b4SAndre Fischer             mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight);
32813e1c3b4SAndre Fischer             mpCurrentDeck->Show();
32913e1c3b4SAndre Fischer             mpCurrentDeck->RequestLayout();
33013e1c3b4SAndre Fischer         }
33113e1c3b4SAndre Fischer         else
33213e1c3b4SAndre Fischer             mpCurrentDeck->Hide();
33322de8995SAndre Fischer     }
33495a18594SAndre Fischer 
3357a32b0c8SAndre Fischer     // Place the tab bar.
33695a18594SAndre Fischer     mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight);
33795a18594SAndre Fischer     mpTabBar->Show();
3387a32b0c8SAndre Fischer 
3397a32b0c8SAndre Fischer     // Determine if the closer of the deck can be shown.
340f120fe41SAndre Fischer     if (mpCurrentDeck)
3417a32b0c8SAndre Fischer     {
342f120fe41SAndre Fischer         DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
3437a32b0c8SAndre Fischer         if (pTitleBar != NULL && pTitleBar->IsVisible())
3447a32b0c8SAndre Fischer             pTitleBar->SetCloserVisible(CanModifyChildWindowWidth());
3457a32b0c8SAndre Fischer     }
3467a32b0c8SAndre Fischer 
3477a32b0c8SAndre Fischer     RestrictWidth();
34813e1c3b4SAndre Fischer }
34913e1c3b4SAndre Fischer 
35013e1c3b4SAndre Fischer 
35113e1c3b4SAndre Fischer 
35213e1c3b4SAndre Fischer 
35313e1c3b4SAndre Fischer void SidebarController::ProcessNewWidth (const sal_Int32 nNewWidth)
35413e1c3b4SAndre Fischer {
35513e1c3b4SAndre Fischer     if ( ! mbIsDeckRequestedOpen)
35613e1c3b4SAndre Fischer         return;
35713e1c3b4SAndre Fischer 
35813e1c3b4SAndre Fischer     if (mbIsDeckRequestedOpen.get())
35913e1c3b4SAndre Fischer      {
36013e1c3b4SAndre Fischer         // Deck became large enough to be shown.  Show it.
36113e1c3b4SAndre Fischer         mnSavedSidebarWidth = nNewWidth;
36213e1c3b4SAndre Fischer         RequestOpenDeck();
36313e1c3b4SAndre Fischer     }
36413e1c3b4SAndre Fischer     else
3657a32b0c8SAndre Fischer     {
36613e1c3b4SAndre Fischer         // Deck became too small.  Close it completely.
36713e1c3b4SAndre Fischer         // If window is wider than the tab bar then mark the deck as being visible, even when it its not.
36813e1c3b4SAndre Fischer         // This is to trigger an adjustment of the width to the width of the tab bar.
36913e1c3b4SAndre Fischer         mbIsDeckOpen = true;
37013e1c3b4SAndre Fischer         RequestCloseDeck();
37113e1c3b4SAndre Fischer 
37213e1c3b4SAndre Fischer         if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
37313e1c3b4SAndre Fischer             mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
3747a32b0c8SAndre Fischer     }
37522de8995SAndre Fischer }
37622de8995SAndre Fischer 
37722de8995SAndre Fischer 
37822de8995SAndre Fischer 
37922de8995SAndre Fischer 
380239cbbc0SAndre Fischer void SidebarController::UpdateConfigurations (void)
38122de8995SAndre Fischer {
382239cbbc0SAndre Fischer     if (maCurrentContext != maRequestedContext)
38395a18594SAndre Fischer     {
384239cbbc0SAndre Fischer         maCurrentContext = maRequestedContext;
38595a18594SAndre Fischer 
38613e1c3b4SAndre Fischer         // Find the set of decks that could be displayed for the new context.
38713e1c3b4SAndre Fischer         ResourceManager::DeckContextDescriptorContainer aDecks;
38895a18594SAndre Fischer         ResourceManager::Instance().GetMatchingDecks (
38913e1c3b4SAndre Fischer             aDecks,
390239cbbc0SAndre Fischer             maCurrentContext,
39113e1c3b4SAndre Fischer             mbIsDocumentReadOnly,
39295a18594SAndre Fischer             mxFrame);
39313e1c3b4SAndre Fischer         mpTabBar->SetDecks(aDecks);
39495a18594SAndre Fischer 
39513e1c3b4SAndre Fischer         // Notify the tab bar about the updated set of decks.
39613e1c3b4SAndre Fischer         mpTabBar->SetDecks(aDecks);
39713e1c3b4SAndre Fischer 
39813e1c3b4SAndre Fischer         // Find the new deck.  By default that is the same as the old
39913e1c3b4SAndre Fischer         // one.  If that is not set or not enabled, then choose the
40013e1c3b4SAndre Fischer         // first enabled deck.
40113e1c3b4SAndre Fischer         OUString sNewDeckId;
40213e1c3b4SAndre Fischer         for (ResourceManager::DeckContextDescriptorContainer::const_iterator
40313e1c3b4SAndre Fischer                  iDeck(aDecks.begin()),
40413e1c3b4SAndre Fischer                  iEnd(aDecks.end());
40595a18594SAndre Fischer              iDeck!=iEnd;
40695a18594SAndre Fischer              ++iDeck)
40795a18594SAndre Fischer         {
40813e1c3b4SAndre Fischer             if (iDeck->mbIsEnabled)
40995a18594SAndre Fischer             {
41013e1c3b4SAndre Fischer                 if (iDeck->msId.equals(msCurrentDeckId))
41113e1c3b4SAndre Fischer                 {
41213e1c3b4SAndre Fischer                     sNewDeckId = msCurrentDeckId;
41313e1c3b4SAndre Fischer                     break;
41413e1c3b4SAndre Fischer                 }
41513e1c3b4SAndre Fischer                 else if (sNewDeckId.getLength() == 0)
41613e1c3b4SAndre Fischer                     sNewDeckId = iDeck->msId;
41795a18594SAndre Fischer             }
41895a18594SAndre Fischer         }
419ff12d537SAndre Fischer 
42013e1c3b4SAndre Fischer         if (sNewDeckId.getLength() == 0)
42195a18594SAndre Fischer         {
42213e1c3b4SAndre Fischer             // We did not find a valid deck.
42313e1c3b4SAndre Fischer             RequestCloseDeck();
42413e1c3b4SAndre Fischer             return;
42513e1c3b4SAndre Fischer 
42656798e4bSAndre Fischer             // Tell the tab bar to highlight the button associated
42756798e4bSAndre Fischer             // with the deck.
42813e1c3b4SAndre Fischer             mpTabBar->HighlightDeck(sNewDeckId);
42995a18594SAndre Fischer         }
43013e1c3b4SAndre Fischer 
43113e1c3b4SAndre Fischer         msCurrentDeckId = sNewDeckId;
43213e1c3b4SAndre Fischer         SwitchToDeck(
43313e1c3b4SAndre Fischer             *ResourceManager::Instance().GetDeckDescriptor(sNewDeckId),
43413e1c3b4SAndre Fischer             maCurrentContext);
43554eaaa32SAndre Fischer 
43654eaaa32SAndre Fischer #ifdef DEBUG
43754eaaa32SAndre Fischer         // Show the context name in the deck title bar.
43854eaaa32SAndre Fischer         if (mpCurrentDeck)
43954eaaa32SAndre Fischer         {
44054eaaa32SAndre Fischer             DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
44154eaaa32SAndre Fischer             if (pTitleBar != NULL)
442239cbbc0SAndre Fischer                 pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+maCurrentContext.msContext+A2S(")"));
44354eaaa32SAndre Fischer         }
44454eaaa32SAndre Fischer #endif
44595a18594SAndre Fischer     }
446ff12d537SAndre Fischer }
447ff12d537SAndre Fischer 
448ff12d537SAndre Fischer 
44922de8995SAndre Fischer 
450ff12d537SAndre Fischer 
45113e1c3b4SAndre Fischer void SidebarController::OpenThenSwitchToDeck (
45213e1c3b4SAndre Fischer     const ::rtl::OUString& rsDeckId)
45313e1c3b4SAndre Fischer {
45413e1c3b4SAndre Fischer     RequestOpenDeck();
45513e1c3b4SAndre Fischer     SwitchToDeck(rsDeckId);
45613e1c3b4SAndre Fischer }
45713e1c3b4SAndre Fischer 
45813e1c3b4SAndre Fischer 
45913e1c3b4SAndre Fischer 
46013e1c3b4SAndre Fischer 
461ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
46295a18594SAndre Fischer     const ::rtl::OUString& rsDeckId)
463ff12d537SAndre Fischer {
46413e1c3b4SAndre Fischer     if ( ! msCurrentDeckId.equals(rsDeckId) || ! mbIsDeckOpen)
46595a18594SAndre Fischer     {
46695a18594SAndre Fischer         const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId);
46795a18594SAndre Fischer         if (pDeckDescriptor != NULL)
46895a18594SAndre Fischer             SwitchToDeck(*pDeckDescriptor, maCurrentContext);
46995a18594SAndre Fischer     }
47022de8995SAndre Fischer }
47122de8995SAndre Fischer 
47222de8995SAndre Fischer 
47322de8995SAndre Fischer 
47422de8995SAndre Fischer 
475ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
47622de8995SAndre Fischer     const DeckDescriptor& rDeckDescriptor,
4777a32b0c8SAndre Fischer     const Context& rContext)
47822de8995SAndre Fischer {
47965908a7eSAndre Fischer     maFocusManager.Clear();
48065908a7eSAndre Fischer 
48195a18594SAndre Fischer     if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId))
48295a18594SAndre Fischer     {
48395a18594SAndre Fischer         // When the deck changes then destroy the deck and all panels
48495a18594SAndre Fischer         // and create everything new.
485f120fe41SAndre Fischer         if (mpCurrentDeck)
48695a18594SAndre Fischer         {
487f120fe41SAndre Fischer             mpCurrentDeck->Dispose();
488f120fe41SAndre Fischer             mpCurrentDeck.reset();
48995a18594SAndre Fischer         }
49095a18594SAndre Fischer 
49195a18594SAndre Fischer         msCurrentDeckId = rDeckDescriptor.msId;
49295a18594SAndre Fischer     }
4937a32b0c8SAndre Fischer 
494ff12d537SAndre Fischer     // Determine the panels to display in the deck.
495f120fe41SAndre Fischer     ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors;
496ff12d537SAndre Fischer     ResourceManager::Instance().GetMatchingPanels(
497f120fe41SAndre Fischer         aPanelContextDescriptors,
498ff12d537SAndre Fischer         rContext,
499ff12d537SAndre Fischer         rDeckDescriptor.msId,
500ff12d537SAndre Fischer         mxFrame);
501ff12d537SAndre Fischer 
50254eaaa32SAndre Fischer     if (aPanelContextDescriptors.empty())
50354eaaa32SAndre Fischer     {
50454eaaa32SAndre Fischer         // There are no panels to be displayed in the current context.
50554eaaa32SAndre Fischer         if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty)
50654eaaa32SAndre Fischer         {
50754eaaa32SAndre Fischer             // Switch to the "empty" context and try again.
50854eaaa32SAndre Fischer             SwitchToDeck(
50954eaaa32SAndre Fischer                 rDeckDescriptor,
51054eaaa32SAndre Fischer                 Context(
51154eaaa32SAndre Fischer                     rContext.msApplication,
51254eaaa32SAndre Fischer                     EnumContext::GetContextName(EnumContext::Context_Empty)));
51354eaaa32SAndre Fischer             return;
51454eaaa32SAndre Fischer         }
51554eaaa32SAndre Fischer         else
51654eaaa32SAndre Fischer         {
51754eaaa32SAndre Fischer             // This is already the "empty" context. Looks like we have
51854eaaa32SAndre Fischer             // to live with an empty deck.
51954eaaa32SAndre Fischer         }
52054eaaa32SAndre Fischer     }
52154eaaa32SAndre Fischer 
522f120fe41SAndre Fischer     if (mpCurrentDeck
523f120fe41SAndre Fischer         && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors))
52402c50d82SAndre Fischer     {
52502c50d82SAndre Fischer         // Requested set of panels is identical to the current set of
52602c50d82SAndre Fischer         // panels => Nothing to do.
52702c50d82SAndre Fischer         return;
52802c50d82SAndre Fischer     }
52913e1c3b4SAndre Fischer 
53013e1c3b4SAndre Fischer         // When the document is read-only, check if there are any panels that can still be displayed.
53113e1c3b4SAndre Fischer     if (mbIsDocumentReadOnly)
53213e1c3b4SAndre Fischer     {
53313e1c3b4SAndre Fischer     }
53413e1c3b4SAndre Fischer 
53513e1c3b4SAndre Fischer 
53695a18594SAndre Fischer     // Provide a configuration and Deck object.
537f120fe41SAndre Fischer     if ( ! mpCurrentDeck)
53822de8995SAndre Fischer     {
539f120fe41SAndre Fischer         mpCurrentDeck.reset(
540f120fe41SAndre Fischer             new Deck(
541f120fe41SAndre Fischer                 rDeckDescriptor,
542f120fe41SAndre Fischer                 mpParentWindow,
54313e1c3b4SAndre Fischer                 ::boost::bind(&SidebarController::RequestCloseDeck, this)));
54454eaaa32SAndre Fischer         msCurrentDeckTitle = rDeckDescriptor.msTitle;
54595a18594SAndre Fischer     }
546f120fe41SAndre Fischer     if ( ! mpCurrentDeck)
547f120fe41SAndre Fischer         return;
548f120fe41SAndre Fischer 
54995a18594SAndre Fischer     // Update the panel list.
550f120fe41SAndre Fischer     const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size());
551f120fe41SAndre Fischer     SharedPanelContainer aNewPanels;
552f120fe41SAndre Fischer     const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels());
55395a18594SAndre Fischer     aNewPanels.resize(nNewPanelCount);
5547a32b0c8SAndre Fischer     sal_Int32 nWriteIndex (0);
55502c50d82SAndre Fischer     bool bHasPanelSetChanged (false);
5567a32b0c8SAndre Fischer     for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex)
55795a18594SAndre Fischer     {
558f120fe41SAndre Fischer         const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor (
559f120fe41SAndre Fischer             aPanelContextDescriptors[nReadIndex]);
56095a18594SAndre Fischer 
56113e1c3b4SAndre Fischer         // Determine if the panel can be displayed.
56213e1c3b4SAndre Fischer         const bool bIsPanelVisible (!mbIsDocumentReadOnly || rPanelContexDescriptor.mbShowForReadOnlyDocuments);
56313e1c3b4SAndre Fischer         if ( ! bIsPanelVisible)
56413e1c3b4SAndre Fischer             continue;
56513e1c3b4SAndre Fischer 
56695a18594SAndre Fischer         // Find the corresponding panel among the currently active
56795a18594SAndre Fischer         // panels.
568f120fe41SAndre Fischer         SharedPanelContainer::const_iterator iPanel (::std::find_if(
569f120fe41SAndre Fischer                 rCurrentPanels.begin(),
570f120fe41SAndre Fischer                 rCurrentPanels.end(),
571f120fe41SAndre Fischer                 ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId))));
572f120fe41SAndre Fischer         if (iPanel != rCurrentPanels.end())
573ff12d537SAndre Fischer         {
574f120fe41SAndre Fischer             // Panel already exists in current deck.  Reuse it.
5757a32b0c8SAndre Fischer             aNewPanels[nWriteIndex] = *iPanel;
576ff12d537SAndre Fischer         }
577ff12d537SAndre Fischer         else
578ff12d537SAndre Fischer         {
57995a18594SAndre Fischer             // Panel does not yet exist.  Create it.
5807a32b0c8SAndre Fischer             aNewPanels[nWriteIndex] = CreatePanel(
581f120fe41SAndre Fischer                 rPanelContexDescriptor.msId,
582c545150fSOliver-Rainer Wittmann                 mpCurrentDeck->GetPanelParentWindow());
58302c50d82SAndre Fischer             bHasPanelSetChanged = true;
584ff12d537SAndre Fischer         }
5857a32b0c8SAndre Fischer         if (aNewPanels[nWriteIndex] != NULL)
58602c50d82SAndre Fischer         {
587f120fe41SAndre Fischer             // Depending on the context we have to collapse the panel.
588f120fe41SAndre Fischer             aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible);
589c545150fSOliver-Rainer Wittmann             // Depending on the context we have to apply the show menu functor.
590c545150fSOliver-Rainer Wittmann             aNewPanels[nWriteIndex]->SetShowMenuFunctor(
591c545150fSOliver-Rainer Wittmann                 rPanelContexDescriptor.msMenuCommand.getLength()>0
592c545150fSOliver-Rainer Wittmann                 ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rPanelContexDescriptor.msMenuCommand)
593c545150fSOliver-Rainer Wittmann                 : ::boost::function<void(void)>() );
594f120fe41SAndre Fischer 
595f120fe41SAndre Fischer             ++nWriteIndex;
59602c50d82SAndre Fischer         }
597f120fe41SAndre Fischer 
59895a18594SAndre Fischer     }
599f120fe41SAndre Fischer     aNewPanels.resize(nWriteIndex);
60095a18594SAndre Fischer 
60195a18594SAndre Fischer     // Activate the deck and the new set of panels.
602f120fe41SAndre Fischer     mpCurrentDeck->SetPosSizePixel(
60395a18594SAndre Fischer         0,
60495a18594SAndre Fischer         0,
60595a18594SAndre Fischer         mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(),
60695a18594SAndre Fischer         mpParentWindow->GetSizePixel().Height());
607f120fe41SAndre Fischer     mpCurrentDeck->SetPanels(aNewPanels);
608f120fe41SAndre Fischer     mpCurrentDeck->Show();
609ff12d537SAndre Fischer 
6107a32b0c8SAndre Fischer     mpParentWindow->SetText(rDeckDescriptor.msTitle);
6117a32b0c8SAndre Fischer 
61202c50d82SAndre Fischer     if (bHasPanelSetChanged)
61302c50d82SAndre Fischer         NotifyResize();
61465908a7eSAndre Fischer 
61565908a7eSAndre Fischer     // Tell the focus manager about the new panels and tab bar
61665908a7eSAndre Fischer     // buttons.
617*52d13b84SAndre Fischer     maFocusManager.SetDeckTitle(mpCurrentDeck->GetTitleBar());
61865908a7eSAndre Fischer     maFocusManager.SetPanels(aNewPanels);
61965908a7eSAndre Fischer     mpTabBar->UpdateFocusManager(maFocusManager);
6204e21436dSAndre Fischer     UpdateTitleBarIcons();
62102c50d82SAndre Fischer }
62202c50d82SAndre Fischer 
62302c50d82SAndre Fischer 
62402c50d82SAndre Fischer 
62502c50d82SAndre Fischer 
62602c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual (
627f120fe41SAndre Fischer     const SharedPanelContainer& rCurrentPanels,
628f120fe41SAndre Fischer     const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels)
62902c50d82SAndre Fischer {
630f120fe41SAndre Fischer     if (rCurrentPanels.size() != rRequestedPanels.size())
63102c50d82SAndre Fischer         return false;
63202c50d82SAndre Fischer     for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex)
63302c50d82SAndre Fischer     {
63402c50d82SAndre Fischer         if (rCurrentPanels[nIndex] == NULL)
63502c50d82SAndre Fischer             return false;
636f120fe41SAndre Fischer         if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId))
63702c50d82SAndre Fischer             return false;
63813e1c3b4SAndre Fischer 
63913e1c3b4SAndre Fischer         // Check if the panels still can be displayed.  This may not be the case when
64013e1c3b4SAndre Fischer         // the document just become rea-only.
64113e1c3b4SAndre Fischer         if (mbIsDocumentReadOnly && ! rRequestedPanels[nIndex].mbShowForReadOnlyDocuments)
64213e1c3b4SAndre Fischer             return false;
64302c50d82SAndre Fischer     }
64402c50d82SAndre Fischer     return true;
64522de8995SAndre Fischer }
64622de8995SAndre Fischer 
64722de8995SAndre Fischer 
64822de8995SAndre Fischer 
64922de8995SAndre Fischer 
650f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel (
65195a18594SAndre Fischer     const OUString& rsPanelId,
652c545150fSOliver-Rainer Wittmann     ::Window* pParentWindow )
65395a18594SAndre Fischer {
65495a18594SAndre Fischer     const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId);
65595a18594SAndre Fischer     if (pPanelDescriptor == NULL)
656f120fe41SAndre Fischer         return SharedPanel();
6577a32b0c8SAndre Fischer 
65895a18594SAndre Fischer     // Create the panel which is the parent window of the UIElement.
659f120fe41SAndre Fischer     SharedPanel pPanel (new Panel(
66095a18594SAndre Fischer         *pPanelDescriptor,
6617a32b0c8SAndre Fischer         pParentWindow,
662c545150fSOliver-Rainer Wittmann         ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()) ) );
66395a18594SAndre Fischer 
66495a18594SAndre Fischer     // Create the XUIElement.
66595a18594SAndre Fischer     Reference<ui::XUIElement> xUIElement (CreateUIElement(
66695a18594SAndre Fischer             pPanel->GetComponentInterface(),
66722f77e9eSAndre Fischer             pPanelDescriptor->msImplementationURL,
66822f77e9eSAndre Fischer             pPanelDescriptor->mbWantsCanvas));
66995a18594SAndre Fischer     if (xUIElement.is())
67095a18594SAndre Fischer     {
67195a18594SAndre Fischer         // Initialize the panel and add it to the active deck.
67295a18594SAndre Fischer         pPanel->SetUIElement(xUIElement);
67395a18594SAndre Fischer     }
67495a18594SAndre Fischer     else
67595a18594SAndre Fischer     {
676f120fe41SAndre Fischer         pPanel.reset();
67795a18594SAndre Fischer     }
67895a18594SAndre Fischer 
67995a18594SAndre Fischer     return pPanel;
68095a18594SAndre Fischer }
68195a18594SAndre Fischer 
68295a18594SAndre Fischer 
68395a18594SAndre Fischer 
68495a18594SAndre Fischer 
685ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement (
686ff12d537SAndre Fischer     const Reference<awt::XWindowPeer>& rxWindow,
68722f77e9eSAndre Fischer     const ::rtl::OUString& rsImplementationURL,
68822f77e9eSAndre Fischer     const bool bWantsCanvas)
68922de8995SAndre Fischer {
69022de8995SAndre Fischer     try
69122de8995SAndre Fischer     {
69222de8995SAndre Fischer         const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
69322de8995SAndre Fischer         const Reference<ui::XUIElementFactory> xUIElementFactory (
69422de8995SAndre Fischer             aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"),
69522de8995SAndre Fischer             UNO_QUERY_THROW);
696ff12d537SAndre Fischer 
6977a32b0c8SAndre Fischer        // Create the XUIElement.
69822de8995SAndre Fischer         ::comphelper::NamedValueCollection aCreationArguments;
69922de8995SAndre Fischer         aCreationArguments.put("Frame", makeAny(mxFrame));
700ff12d537SAndre Fischer         aCreationArguments.put("ParentWindow", makeAny(rxWindow));
701b9e67834SAndre Fischer         SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow);
702b9e67834SAndre Fischer         if (pSfxDockingWindow != NULL)
703b9e67834SAndre Fischer             aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings())));
7047a32b0c8SAndre Fischer         aCreationArguments.put("Theme", Theme::GetPropertySet());
7057a32b0c8SAndre Fischer         aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this))));
70622f77e9eSAndre Fischer         if (bWantsCanvas)
70722f77e9eSAndre Fischer         {
70822f77e9eSAndre Fischer             Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas());
70922f77e9eSAndre Fischer             aCreationArguments.put("Canvas", makeAny(xCanvas));
71022f77e9eSAndre Fischer         }
7117a32b0c8SAndre Fischer 
712b9e67834SAndre Fischer         Reference<ui::XUIElement> xUIElement(
713ff12d537SAndre Fischer             xUIElementFactory->createUIElement(
714ff12d537SAndre Fischer                 rsImplementationURL,
7157a32b0c8SAndre Fischer                 Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())),
716ff12d537SAndre Fischer             UNO_QUERY_THROW);
717b9e67834SAndre Fischer 
718b9e67834SAndre Fischer         return xUIElement;
71922de8995SAndre Fischer     }
72022de8995SAndre Fischer     catch(Exception& rException)
72122de8995SAndre Fischer     {
72222de8995SAndre Fischer         OSL_TRACE("caught exception: %s",
72322de8995SAndre Fischer             OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
72422de8995SAndre Fischer         // For some reason we can not create the actual panel.
72522de8995SAndre Fischer         // Probably because its factory was not properly registered.
72622de8995SAndre Fischer         // TODO: provide feedback to developer to better pinpoint the
72722de8995SAndre Fischer         // source of the error.
728ff12d537SAndre Fischer 
729ff12d537SAndre Fischer         return NULL;
73022de8995SAndre Fischer     }
73122de8995SAndre Fischer }
73222de8995SAndre Fischer 
73322de8995SAndre Fischer 
73422de8995SAndre Fischer 
73522de8995SAndre Fischer 
73622de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent)
73722de8995SAndre Fischer {
73813e1c3b4SAndre Fischer     if (pEvent==NULL)
73913e1c3b4SAndre Fischer         return sal_False;
74013e1c3b4SAndre Fischer 
74113e1c3b4SAndre Fischer     if (pEvent->GetWindow() == mpParentWindow)
74222de8995SAndre Fischer     {
74322de8995SAndre Fischer         switch (pEvent->GetId())
74422de8995SAndre Fischer         {
74522de8995SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
74622de8995SAndre Fischer             case VCLEVENT_WINDOW_RESIZE:
74722de8995SAndre Fischer                 NotifyResize();
74822de8995SAndre Fischer                 break;
74922de8995SAndre Fischer 
750ff12d537SAndre Fischer             case VCLEVENT_WINDOW_DATACHANGED:
751ff12d537SAndre Fischer                 // Force an update of deck and tab bar to reflect
752ff12d537SAndre Fischer                 // changes in theme (high contrast mode).
753ff12d537SAndre Fischer                 Theme::HandleDataChange();
7544e21436dSAndre Fischer                 UpdateTitleBarIcons();
755ff12d537SAndre Fischer                 mpParentWindow->Invalidate();
756ff12d537SAndre Fischer                 break;
757ff12d537SAndre Fischer 
75822de8995SAndre Fischer             case SFX_HINT_DYING:
75922de8995SAndre Fischer                 dispose();
76022de8995SAndre Fischer                 break;
76122de8995SAndre Fischer 
76213e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_PAINT:
76313e1c3b4SAndre Fischer                 OSL_TRACE("Paint");
76413e1c3b4SAndre Fischer                 break;
76513e1c3b4SAndre Fischer 
76622de8995SAndre Fischer             default:
76722de8995SAndre Fischer                 break;
76822de8995SAndre Fischer         }
76922de8995SAndre Fischer     }
77013e1c3b4SAndre Fischer     else if (pEvent->GetWindow()==mpSplitWindow && mpSplitWindow!=NULL)
77113e1c3b4SAndre Fischer     {
77213e1c3b4SAndre Fischer         switch (pEvent->GetId())
77313e1c3b4SAndre Fischer         {
77413e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
77513e1c3b4SAndre Fischer                 mnWidthOnSplitterButtonDown = mpParentWindow->GetSizePixel().Width();
77613e1c3b4SAndre Fischer                 break;
77713e1c3b4SAndre Fischer 
77813e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_MOUSEBUTTONUP:
77913e1c3b4SAndre Fischer             {
78013e1c3b4SAndre Fischer                 ProcessNewWidth(mpParentWindow->GetSizePixel().Width());
78113e1c3b4SAndre Fischer                 mnWidthOnSplitterButtonDown = 0;
78213e1c3b4SAndre Fischer                 break;
78313e1c3b4SAndre Fischer             }
78413e1c3b4SAndre Fischer 
78513e1c3b4SAndre Fischer             case SFX_HINT_DYING:
78613e1c3b4SAndre Fischer                 dispose();
78713e1c3b4SAndre Fischer                 break;
78813e1c3b4SAndre Fischer          }
78913e1c3b4SAndre Fischer     }
79022de8995SAndre Fischer 
79122de8995SAndre Fischer     return sal_True;
79222de8995SAndre Fischer }
79322de8995SAndre Fischer 
79422de8995SAndre Fischer 
79522de8995SAndre Fischer 
79622de8995SAndre Fischer 
79795a18594SAndre Fischer void SidebarController::ShowPopupMenu (
79895a18594SAndre Fischer     const Rectangle& rButtonBox,
79995a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
80095a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const
80122de8995SAndre Fischer {
80295a18594SAndre Fischer     ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData);
803ff12d537SAndre Fischer     pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected));
804ff12d537SAndre Fischer 
805ff12d537SAndre Fischer     // pass toolbox button rect so the menu can stay open on button up
806ff12d537SAndre Fischer     Rectangle aBox (rButtonBox);
807ff12d537SAndre Fischer     aBox.Move(mpTabBar->GetPosPixel().X(), 0);
808ff12d537SAndre Fischer     pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN);
80922de8995SAndre Fischer }
81022de8995SAndre Fischer 
81122de8995SAndre Fischer 
81222de8995SAndre Fischer 
81322de8995SAndre Fischer 
814f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const
815f120fe41SAndre Fischer {
816f120fe41SAndre Fischer     try
817f120fe41SAndre Fischer     {
818f35c6d02SAndre Fischer         const util::URL aURL (Tools::GetURL(rsMenuCommand));
819f35c6d02SAndre Fischer         Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
820f120fe41SAndre Fischer         if (xDispatch.is())
821f120fe41SAndre Fischer             xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
822f120fe41SAndre Fischer     }
823f120fe41SAndre Fischer     catch(Exception& rException)
824f120fe41SAndre Fischer     {
825f120fe41SAndre Fischer         OSL_TRACE("caught exception: %s",
826f120fe41SAndre Fischer             OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
827f120fe41SAndre Fischer     }
828f120fe41SAndre Fischer }
829f120fe41SAndre Fischer 
830f120fe41SAndre Fischer 
831f120fe41SAndre Fischer 
832f120fe41SAndre Fischer 
83395a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu (
83495a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
83595a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const
83622de8995SAndre Fischer {
837ff12d537SAndre Fischer     ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu());
838ff12d537SAndre Fischer     FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
839ff12d537SAndre Fischer     if (pMenuWindow != NULL)
840ff12d537SAndre Fischer     {
841ff12d537SAndre Fischer         pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
842ff12d537SAndre Fischer     }
843ff12d537SAndre Fischer 
844ff12d537SAndre Fischer     SidebarResource aLocalResource;
845ff12d537SAndre Fischer 
846ff12d537SAndre Fischer     // Add one entry for every tool panel element to individually make
847ff12d537SAndre Fischer     // them visible or hide them.
84822de8995SAndre Fischer     {
84995a18594SAndre Fischer         sal_Int32 nIndex (MID_FIRST_PANEL);
85095a18594SAndre Fischer         for(::std::vector<TabBar::DeckMenuData>::const_iterator
85195a18594SAndre Fischer                 iItem(rDeckSelectionData.begin()),
85295a18594SAndre Fischer                 iEnd(rDeckSelectionData.end());
85395a18594SAndre Fischer             iItem!=iEnd;
85495a18594SAndre Fischer             ++iItem)
85595a18594SAndre Fischer         {
85695a18594SAndre Fischer             pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK);
85795a18594SAndre Fischer             pMenu->CheckItem(nIndex, iItem->get<2>());
85895a18594SAndre Fischer             ++nIndex;
85995a18594SAndre Fischer         }
86022de8995SAndre Fischer     }
86122de8995SAndre Fischer 
86295a18594SAndre Fischer     pMenu->InsertSeparator();
86395a18594SAndre Fischer 
864ff12d537SAndre Fischer     // Add entry for docking or un-docking the tool panel.
865ff12d537SAndre Fischer     if (mpParentWindow->IsFloatingMode())
866ff12d537SAndre Fischer         pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK)));
867ff12d537SAndre Fischer     else
868ff12d537SAndre Fischer         pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK)));
869ff12d537SAndre Fischer 
870ff12d537SAndre Fischer     // Add sub menu for customization (hiding of deck tabs.)
871ff12d537SAndre Fischer     PopupMenu* pCustomizationMenu = new PopupMenu();
87295a18594SAndre Fischer     {
87395a18594SAndre Fischer         sal_Int32 nIndex (MID_FIRST_HIDE);
87495a18594SAndre Fischer         for(::std::vector<TabBar::DeckMenuData>::const_iterator
87595a18594SAndre Fischer                 iItem(rDeckShowData.begin()),
87695a18594SAndre Fischer                 iEnd(rDeckShowData.end());
87795a18594SAndre Fischer             iItem!=iEnd;
87895a18594SAndre Fischer             ++iItem)
87995a18594SAndre Fischer         {
88095a18594SAndre Fischer             pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE);
88195a18594SAndre Fischer             pCustomizationMenu->CheckItem(nIndex, iItem->get<2>());
88295a18594SAndre Fischer             ++nIndex;
88395a18594SAndre Fischer         }
88495a18594SAndre Fischer     }
88595a18594SAndre Fischer 
886ff12d537SAndre Fischer     pCustomizationMenu->InsertSeparator();
887ff12d537SAndre Fischer     pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE)));
888ff12d537SAndre Fischer 
889ff12d537SAndre Fischer     pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION)));
890ff12d537SAndre Fischer     pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu);
891ff12d537SAndre Fischer 
892ff12d537SAndre Fischer     pMenu->RemoveDisabledEntries(sal_False, sal_False);
893ff12d537SAndre Fischer 
894ff12d537SAndre Fischer     return pMenu;
89522de8995SAndre Fischer }
89622de8995SAndre Fischer 
89722de8995SAndre Fischer 
89822de8995SAndre Fischer 
89922de8995SAndre Fischer 
900ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu)
90122de8995SAndre Fischer {
902ff12d537SAndre Fischer     if (pMenu == NULL)
903ff12d537SAndre Fischer     {
9047a32b0c8SAndre Fischer         OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!");
905ff12d537SAndre Fischer         return 0;
906ff12d537SAndre Fischer     }
90722de8995SAndre Fischer 
908ff12d537SAndre Fischer     pMenu->Deactivate();
909ff12d537SAndre Fischer     const sal_Int32 nIndex (pMenu->GetCurItemId());
910ff12d537SAndre Fischer     switch (nIndex)
91122de8995SAndre Fischer     {
912ff12d537SAndre Fischer         case MID_UNLOCK_TASK_PANEL:
913ff12d537SAndre Fischer             mpParentWindow->SetFloatingMode(sal_True);
914ff12d537SAndre Fischer             break;
915ff12d537SAndre Fischer 
916ff12d537SAndre Fischer         case MID_LOCK_TASK_PANEL:
917ff12d537SAndre Fischer             mpParentWindow->SetFloatingMode(sal_False);
918ff12d537SAndre Fischer             break;
919ff12d537SAndre Fischer 
920ff12d537SAndre Fischer         case MID_RESTORE_DEFAULT:
921ff12d537SAndre Fischer             mpTabBar->RestoreHideFlags();
922ff12d537SAndre Fischer             break;
923ff12d537SAndre Fischer 
924ff12d537SAndre Fischer         default:
925ff12d537SAndre Fischer         {
926ff12d537SAndre Fischer             try
927ff12d537SAndre Fischer             {
928ff12d537SAndre Fischer                 if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE)
92995a18594SAndre Fischer                     SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL));
930ff12d537SAndre Fischer                 else if (nIndex >=MID_FIRST_HIDE)
931ff12d537SAndre Fischer                     mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE);
932ff12d537SAndre Fischer             }
933ff12d537SAndre Fischer             catch (RuntimeException&)
934ff12d537SAndre Fischer             {
935ff12d537SAndre Fischer             }
936ff12d537SAndre Fischer         }
937ff12d537SAndre Fischer         break;
93822de8995SAndre Fischer     }
939ff12d537SAndre Fischer 
940ff12d537SAndre Fischer     return 1;
94122de8995SAndre Fischer }
94222de8995SAndre Fischer 
94322de8995SAndre Fischer 
944ff12d537SAndre Fischer 
945ff12d537SAndre Fischer 
94613e1c3b4SAndre Fischer void SidebarController::RequestCloseDeck (void)
9477a32b0c8SAndre Fischer {
94813e1c3b4SAndre Fischer     mbIsDeckRequestedOpen = false;
94913e1c3b4SAndre Fischer     UpdateDeckOpenState();
9507a32b0c8SAndre Fischer }
9517a32b0c8SAndre Fischer 
9527a32b0c8SAndre Fischer 
9537a32b0c8SAndre Fischer 
9547a32b0c8SAndre Fischer 
95513e1c3b4SAndre Fischer void SidebarController::RequestOpenDeck (void)
9567a32b0c8SAndre Fischer {
95713e1c3b4SAndre Fischer     mbIsDeckRequestedOpen = true;
95813e1c3b4SAndre Fischer     UpdateDeckOpenState();
95913e1c3b4SAndre Fischer }
96013e1c3b4SAndre Fischer 
9617a32b0c8SAndre Fischer 
9627a32b0c8SAndre Fischer 
96313e1c3b4SAndre Fischer 
96413e1c3b4SAndre Fischer void SidebarController::UpdateDeckOpenState (void)
96513e1c3b4SAndre Fischer {
96613e1c3b4SAndre Fischer     if ( ! mbIsDeckRequestedOpen)
96713e1c3b4SAndre Fischer         // No state requested.
96813e1c3b4SAndre Fischer         return;
96913e1c3b4SAndre Fischer 
97013e1c3b4SAndre Fischer     // Update (change) the open state when it either has not yet been initialized
97113e1c3b4SAndre Fischer     // or when its value differs from the requested state.
97213e1c3b4SAndre Fischer     if ( ! mbIsDeckOpen
97313e1c3b4SAndre Fischer         || mbIsDeckOpen.get() != mbIsDeckRequestedOpen.get())
97413e1c3b4SAndre Fischer     {
97513e1c3b4SAndre Fischer         if (mbIsDeckRequestedOpen.get())
97613e1c3b4SAndre Fischer         {
97713e1c3b4SAndre Fischer             if (mnSavedSidebarWidth <= TabBar::GetDefaultWidth())
97813e1c3b4SAndre Fischer                 SetChildWindowWidth(SidebarChildWindow::GetDefaultWidth(mpParentWindow));
97913e1c3b4SAndre Fischer             else
98013e1c3b4SAndre Fischer                 SetChildWindowWidth(mnSavedSidebarWidth);
98113e1c3b4SAndre Fischer         }
98213e1c3b4SAndre Fischer         else
98313e1c3b4SAndre Fischer         {
98413e1c3b4SAndre Fischer             if ( ! mpParentWindow->IsFloatingMode())
98513e1c3b4SAndre Fischer                 mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth());
98613e1c3b4SAndre Fischer             if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
98713e1c3b4SAndre Fischer                 mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
98813e1c3b4SAndre Fischer             mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE);
98913e1c3b4SAndre Fischer         }
99013e1c3b4SAndre Fischer 
99113e1c3b4SAndre Fischer         mbIsDeckOpen = mbIsDeckRequestedOpen.get();
99213e1c3b4SAndre Fischer         if (mbIsDeckOpen.get() && mpCurrentDeck)
99313e1c3b4SAndre Fischer             mpCurrentDeck->Show(mbIsDeckOpen.get());
9947a32b0c8SAndre Fischer         NotifyResize();
9957a32b0c8SAndre Fischer     }
9967a32b0c8SAndre Fischer }
9977a32b0c8SAndre Fischer 
9987a32b0c8SAndre Fischer 
9997a32b0c8SAndre Fischer 
10007a32b0c8SAndre Fischer 
100165908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void)
100265908a7eSAndre Fischer {
100365908a7eSAndre Fischer     return maFocusManager;
100465908a7eSAndre Fischer }
100565908a7eSAndre Fischer 
100665908a7eSAndre Fischer 
100765908a7eSAndre Fischer 
100865908a7eSAndre Fischer 
100913e1c3b4SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void)
10107a32b0c8SAndre Fischer {
101113e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10127a32b0c8SAndre Fischer     if (pSplitWindow == NULL)
101313e1c3b4SAndre Fischer         return false;
10147a32b0c8SAndre Fischer 
10157a32b0c8SAndre Fischer     sal_uInt16 nRow (0xffff);
10167a32b0c8SAndre Fischer     sal_uInt16 nColumn (0xffff);
10177a32b0c8SAndre Fischer     pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow);
10187a32b0c8SAndre Fischer 
10197a32b0c8SAndre Fischer     sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn));
10207a32b0c8SAndre Fischer 
102113e1c3b4SAndre Fischer     return nRowCount==1;
10227a32b0c8SAndre Fischer }
10237a32b0c8SAndre Fischer 
10247a32b0c8SAndre Fischer 
10257a32b0c8SAndre Fischer 
10267a32b0c8SAndre Fischer 
10277a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth)
10287a32b0c8SAndre Fischer {
102913e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10307a32b0c8SAndre Fischer     if (pSplitWindow == NULL)
10317a32b0c8SAndre Fischer         return 0;
10327a32b0c8SAndre Fischer 
10337a32b0c8SAndre Fischer     sal_uInt16 nRow (0xffff);
10347a32b0c8SAndre Fischer     sal_uInt16 nColumn (0xffff);
10357a32b0c8SAndre Fischer     pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow);
10367a32b0c8SAndre Fischer     const long nColumnWidth (pSplitWindow->GetLineSize(nColumn));
10377a32b0c8SAndre Fischer 
10387a32b0c8SAndre Fischer     Window* pWindow = mpParentWindow;
10397a32b0c8SAndre Fischer     const Point aWindowPosition (pWindow->GetPosPixel());
10407a32b0c8SAndre Fischer     const Size aWindowSize (pWindow->GetSizePixel());
10417a32b0c8SAndre Fischer 
10427a32b0c8SAndre Fischer     pSplitWindow->MoveWindow(
10437a32b0c8SAndre Fischer         mpParentWindow,
10447a32b0c8SAndre Fischer         Size(nNewWidth, aWindowSize.Height()),
10457a32b0c8SAndre Fischer         nColumn,
10467a32b0c8SAndre Fischer         nRow);
104713e1c3b4SAndre Fischer     static_cast<SplitWindow*>(pSplitWindow)->Split();
104813e1c3b4SAndre Fischer 
10497a32b0c8SAndre Fischer     return static_cast<sal_Int32>(nColumnWidth);
10507a32b0c8SAndre Fischer }
10517a32b0c8SAndre Fischer 
10527a32b0c8SAndre Fischer 
10537a32b0c8SAndre Fischer 
10547a32b0c8SAndre Fischer 
10557a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void)
10567a32b0c8SAndre Fischer {
105713e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10587a32b0c8SAndre Fischer     if (pSplitWindow != NULL)
10597a32b0c8SAndre Fischer     {
10607a32b0c8SAndre Fischer         const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow));
10617a32b0c8SAndre Fischer         const sal_uInt16 nSetId (pSplitWindow->GetSet(nId));
10627a32b0c8SAndre Fischer         pSplitWindow->SetItemSizeRange(
10637a32b0c8SAndre Fischer             nSetId,
106413e1c3b4SAndre Fischer             Range(TabBar::GetDefaultWidth(), gnMaximumSidebarWidth));
106513e1c3b4SAndre Fischer     }
106613e1c3b4SAndre Fischer }
106713e1c3b4SAndre Fischer 
106813e1c3b4SAndre Fischer 
106913e1c3b4SAndre Fischer 
107013e1c3b4SAndre Fischer 
107113e1c3b4SAndre Fischer SfxSplitWindow* SidebarController::GetSplitWindow (void)
107213e1c3b4SAndre Fischer {
107313e1c3b4SAndre Fischer     if (mpSplitWindow == NULL)
107413e1c3b4SAndre Fischer     {
107513e1c3b4SAndre Fischer         if (mpParentWindow != NULL)
107613e1c3b4SAndre Fischer         {
107713e1c3b4SAndre Fischer             mpSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent());
107813e1c3b4SAndre Fischer             if (mpSplitWindow != NULL)
107913e1c3b4SAndre Fischer                 mpSplitWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
108013e1c3b4SAndre Fischer         }
108113e1c3b4SAndre Fischer     }
108213e1c3b4SAndre Fischer 
108313e1c3b4SAndre Fischer     return mpSplitWindow;
108413e1c3b4SAndre Fischer }
108513e1c3b4SAndre Fischer 
108613e1c3b4SAndre Fischer 
108713e1c3b4SAndre Fischer 
108813e1c3b4SAndre Fischer 
108913e1c3b4SAndre Fischer void SidebarController::UpdateCloseIndicator (const bool bCloseAfterDrag)
109013e1c3b4SAndre Fischer {
109113e1c3b4SAndre Fischer     if (mpParentWindow == NULL)
109213e1c3b4SAndre Fischer         return;
109313e1c3b4SAndre Fischer 
109413e1c3b4SAndre Fischer     if (bCloseAfterDrag)
109513e1c3b4SAndre Fischer     {
109613e1c3b4SAndre Fischer         // Make sure that the indicator exists.
109713e1c3b4SAndre Fischer         if ( ! mpCloseIndicator)
109813e1c3b4SAndre Fischer         {
109913e1c3b4SAndre Fischer             mpCloseIndicator.reset(new FixedImage(mpParentWindow));
110013e1c3b4SAndre Fischer             FixedImage* pFixedImage = static_cast<FixedImage*>(mpCloseIndicator.get());
110113e1c3b4SAndre Fischer             const Image aImage (Theme::GetImage(Theme::Image_CloseIndicator));
110213e1c3b4SAndre Fischer             pFixedImage->SetImage(aImage);
110313e1c3b4SAndre Fischer             pFixedImage->SetSizePixel(aImage.GetSizePixel());
110413e1c3b4SAndre Fischer             pFixedImage->SetBackground(Theme::GetWallpaper(Theme::Paint_DeckBackground));
110513e1c3b4SAndre Fischer         }
110613e1c3b4SAndre Fischer 
110713e1c3b4SAndre Fischer         // Place and show the indicator.
110813e1c3b4SAndre Fischer         const Size aWindowSize (mpParentWindow->GetSizePixel());
110913e1c3b4SAndre Fischer         const Size aImageSize (mpCloseIndicator->GetSizePixel());
111013e1c3b4SAndre Fischer         mpCloseIndicator->SetPosPixel(
111113e1c3b4SAndre Fischer             Point(
111213e1c3b4SAndre Fischer                 aWindowSize.Width() - TabBar::GetDefaultWidth() - aImageSize.Width(),
111313e1c3b4SAndre Fischer                 (aWindowSize.Height() - aImageSize.Height())/2));
111413e1c3b4SAndre Fischer         mpCloseIndicator->Show();
111513e1c3b4SAndre Fischer     }
111613e1c3b4SAndre Fischer     else
111713e1c3b4SAndre Fischer     {
111813e1c3b4SAndre Fischer         // Hide but don't delete the indicator.
111913e1c3b4SAndre Fischer         if (mpCloseIndicator)
112013e1c3b4SAndre Fischer             mpCloseIndicator->Hide();
11217a32b0c8SAndre Fischer     }
11227a32b0c8SAndre Fischer }
11237a32b0c8SAndre Fischer 
1124ff12d537SAndre Fischer 
11254e21436dSAndre Fischer 
11264e21436dSAndre Fischer 
11274e21436dSAndre Fischer void SidebarController::UpdateTitleBarIcons (void)
11284e21436dSAndre Fischer {
11294e21436dSAndre Fischer     if ( ! mpCurrentDeck)
11304e21436dSAndre Fischer         return;
11314e21436dSAndre Fischer 
11324e21436dSAndre Fischer     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
11334e21436dSAndre Fischer     const ResourceManager& rResourceManager (ResourceManager::Instance());
11344e21436dSAndre Fischer 
11354e21436dSAndre Fischer     // Update the deck icon.
11364e21436dSAndre Fischer     const DeckDescriptor* pDeckDescriptor = rResourceManager.GetDeckDescriptor(mpCurrentDeck->GetId());
11374e21436dSAndre Fischer     if (pDeckDescriptor != NULL && mpCurrentDeck->GetTitleBar())
11384e21436dSAndre Fischer     {
11394e21436dSAndre Fischer         const OUString sIconURL(
11404e21436dSAndre Fischer             bIsHighContrastModeActive
11414e21436dSAndre Fischer                 ? pDeckDescriptor->msHighContrastTitleBarIconURL
11424e21436dSAndre Fischer                 : pDeckDescriptor->msTitleBarIconURL);
11434e21436dSAndre Fischer         mpCurrentDeck->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
11444e21436dSAndre Fischer     }
11454e21436dSAndre Fischer 
11464e21436dSAndre Fischer     // Update the panel icons.
11474e21436dSAndre Fischer     const SharedPanelContainer& rPanels (mpCurrentDeck->GetPanels());
11484e21436dSAndre Fischer     for (SharedPanelContainer::const_iterator
11494e21436dSAndre Fischer              iPanel(rPanels.begin()), iEnd(rPanels.end());
11504e21436dSAndre Fischer              iPanel!=iEnd;
11514e21436dSAndre Fischer              ++iPanel)
11524e21436dSAndre Fischer     {
11534e21436dSAndre Fischer         if ( ! *iPanel)
11544e21436dSAndre Fischer             continue;
11554e21436dSAndre Fischer         if ((*iPanel)->GetTitleBar() == NULL)
11564e21436dSAndre Fischer             continue;
11574e21436dSAndre Fischer         const PanelDescriptor* pPanelDescriptor = rResourceManager.GetPanelDescriptor((*iPanel)->GetId());
11584e21436dSAndre Fischer         if (pPanelDescriptor == NULL)
11594e21436dSAndre Fischer             continue;
11604e21436dSAndre Fischer         const OUString sIconURL (
11614e21436dSAndre Fischer             bIsHighContrastModeActive
11624e21436dSAndre Fischer                ? pPanelDescriptor->msHighContrastTitleBarIconURL
11634e21436dSAndre Fischer                : pPanelDescriptor->msTitleBarIconURL);
11644e21436dSAndre Fischer         (*iPanel)->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
11654e21436dSAndre Fischer     }
11664e21436dSAndre Fischer }
11674e21436dSAndre Fischer 
11684e21436dSAndre Fischer 
1169*52d13b84SAndre Fischer 
1170*52d13b84SAndre Fischer 
1171*52d13b84SAndre Fischer void SidebarController::ShowPanel (const Panel& rPanel)
1172*52d13b84SAndre Fischer {
1173*52d13b84SAndre Fischer     if (mpCurrentDeck)
1174*52d13b84SAndre Fischer         mpCurrentDeck->ShowPanel(rPanel);
1175*52d13b84SAndre Fischer }
1176*52d13b84SAndre Fischer 
1177*52d13b84SAndre Fischer 
1178ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
1179