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"
32*13e1c3b4SAndre Fischer #include "sfx2/sidebar/SidebarChildWindow.hxx"
337a32b0c8SAndre Fischer #include "SidebarDockingWindow.hxx"
347a32b0c8SAndre Fischer #include "Context.hxx"
3554eaaa32SAndre Fischer #include "Tools.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>
42*13e1c3b4SAndre 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 
74*13e1c3b4SAndre Fischer namespace
75*13e1c3b4SAndre Fischer {
76*13e1c3b4SAndre Fischer     const static OUString gsReadOnlyCommandName (A2S(".uno:EditDoc"));
77*13e1c3b4SAndre Fischer     const static sal_Int32 gnMaximumSidebarWidth (400);
78*13e1c3b4SAndre Fischer     const static sal_Int32 gnWidthCloseThreshold (70);
79*13e1c3b4SAndre Fischer     const static sal_Int32 gnWidthOpenThreshold (40);
80*13e1c3b4SAndre Fischer }
81*13e1c3b4SAndre Fischer 
82*13e1c3b4SAndre 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,
107*13e1c3b4SAndre 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()),
11195a18594SAndre Fischer       msCurrentDeckId(A2S("PropertyDeck")),
1127a32b0c8SAndre Fischer       maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)),
113239cbbc0SAndre Fischer       maContextChangeUpdate(::boost::bind(&SidebarController::UpdateConfigurations, this)),
114*13e1c3b4SAndre Fischer       mbIsDeckRequestedOpen(),
115*13e1c3b4SAndre Fischer       mbIsDeckOpen(),
116*13e1c3b4SAndre Fischer       mbCanDeckBeOpened(true),
117*13e1c3b4SAndre Fischer       mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()),
118*13e1c3b4SAndre Fischer       mxReadOnlyModeDispatch(),
119*13e1c3b4SAndre Fischer       mbIsDocumentReadOnly(false),
120*13e1c3b4SAndre Fischer       mpSplitWindow(NULL),
121*13e1c3b4SAndre Fischer       mnWidthOnSplitterButtonDown(0),
122*13e1c3b4SAndre Fischer       mpCloseIndicator()
12322de8995SAndre Fischer {
12422de8995SAndre Fischer     if (pParentWindow == NULL)
12522de8995SAndre Fischer     {
12622de8995SAndre Fischer         OSL_ASSERT(pParentWindow!=NULL);
12722de8995SAndre Fischer             return;
12822de8995SAndre Fischer     }
12922de8995SAndre Fischer 
13022de8995SAndre Fischer     // Listen for context change events.
13122de8995SAndre Fischer     cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
13222de8995SAndre Fischer         css::ui::ContextChangeEventMultiplexer::get(
13322de8995SAndre Fischer             ::comphelper::getProcessComponentContext()));
13422de8995SAndre Fischer     if (xMultiplexer.is())
13522de8995SAndre Fischer         xMultiplexer->addContextChangeEventListener(
13622de8995SAndre Fischer             static_cast<css::ui::XContextChangeEventListener*>(this),
13795a18594SAndre Fischer             mxFrame->getController());
13822de8995SAndre Fischer 
13922de8995SAndre Fischer     // Listen for window events.
14022de8995SAndre Fischer     mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
141b9e67834SAndre Fischer 
142b9e67834SAndre Fischer     // Listen for theme property changes.
143b9e67834SAndre Fischer     Theme::GetPropertySet()->addPropertyChangeListener(
144b9e67834SAndre Fischer         A2S(""),
145b9e67834SAndre Fischer         static_cast<css::beans::XPropertyChangeListener*>(this));
146f120fe41SAndre Fischer 
147*13e1c3b4SAndre Fischer     // Get the dispatch object as preparation to listen for changes of
148*13e1c3b4SAndre Fischer     // the read-only state.
149*13e1c3b4SAndre Fischer     const util::URL aURL (GetURL(gsReadOnlyCommandName));
150*13e1c3b4SAndre Fischer     mxReadOnlyModeDispatch = GetDispatch(aURL);
151*13e1c3b4SAndre Fischer     if (mxReadOnlyModeDispatch.is())
152*13e1c3b4SAndre Fischer         mxReadOnlyModeDispatch->addStatusListener(this, aURL);
153*13e1c3b4SAndre Fischer 
154f120fe41SAndre Fischer     SwitchToDeck(A2S("default"));
15522de8995SAndre Fischer }
15622de8995SAndre Fischer 
15722de8995SAndre Fischer 
15822de8995SAndre Fischer 
15922de8995SAndre Fischer 
16022de8995SAndre Fischer SidebarController::~SidebarController (void)
16122de8995SAndre Fischer {
16222de8995SAndre Fischer }
16322de8995SAndre Fischer 
16422de8995SAndre Fischer 
16522de8995SAndre Fischer 
16622de8995SAndre Fischer 
16722de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void)
16822de8995SAndre Fischer {
16965908a7eSAndre Fischer     maFocusManager.Clear();
17065908a7eSAndre Fischer 
17122de8995SAndre Fischer     cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
17222de8995SAndre Fischer         css::ui::ContextChangeEventMultiplexer::get(
17322de8995SAndre Fischer             ::comphelper::getProcessComponentContext()));
17422de8995SAndre Fischer     if (xMultiplexer.is())
17522de8995SAndre Fischer         xMultiplexer->removeAllContextChangeEventListeners(
17622de8995SAndre Fischer             static_cast<css::ui::XContextChangeEventListener*>(this));
17722de8995SAndre Fischer 
178*13e1c3b4SAndre Fischer     if (mxReadOnlyModeDispatch.is())
179*13e1c3b4SAndre Fischer         mxReadOnlyModeDispatch->removeStatusListener(this, GetURL(gsReadOnlyCommandName));
180*13e1c3b4SAndre Fischer     if (mpSplitWindow != NULL)
181*13e1c3b4SAndre Fischer     {
182*13e1c3b4SAndre Fischer         mpSplitWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
183*13e1c3b4SAndre Fischer         mpSplitWindow = NULL;
184*13e1c3b4SAndre Fischer     }
185*13e1c3b4SAndre Fischer 
18622de8995SAndre Fischer     if (mpParentWindow != NULL)
18722de8995SAndre Fischer     {
18822de8995SAndre Fischer         mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
18922de8995SAndre Fischer         mpParentWindow = NULL;
19022de8995SAndre Fischer     }
191b9e67834SAndre Fischer 
192f120fe41SAndre Fischer     if (mpCurrentDeck)
193b9e67834SAndre Fischer     {
194f120fe41SAndre Fischer         mpCurrentDeck->Dispose();
195f120fe41SAndre Fischer         mpCurrentDeck->PrintWindowTree();
196f120fe41SAndre Fischer         mpCurrentDeck.reset();
197b9e67834SAndre Fischer     }
198b9e67834SAndre Fischer 
199580828edSAndre Fischer     mpTabBar.reset();
200580828edSAndre Fischer 
201b9e67834SAndre Fischer     Theme::GetPropertySet()->removePropertyChangeListener(
202b9e67834SAndre Fischer         A2S(""),
203b9e67834SAndre Fischer         static_cast<css::beans::XPropertyChangeListener*>(this));
20422de8995SAndre Fischer }
20522de8995SAndre Fischer 
20622de8995SAndre Fischer 
20722de8995SAndre Fischer 
20822de8995SAndre Fischer 
20922de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
21022de8995SAndre Fischer     throw(cssu::RuntimeException)
21122de8995SAndre Fischer {
212239cbbc0SAndre Fischer     // Update to the requested new context asynchronously to avoid
213239cbbc0SAndre Fischer     // subtle errors caused by SFX2 which in rare cases can not
214239cbbc0SAndre Fischer     // properly handle a synchronous update.
215239cbbc0SAndre Fischer     maRequestedContext = Context(
216239cbbc0SAndre Fischer         rEvent.ApplicationName,
217239cbbc0SAndre Fischer         rEvent.ContextName);
218239cbbc0SAndre Fischer     if (maRequestedContext != maCurrentContext)
219239cbbc0SAndre Fischer         maContextChangeUpdate.RequestCall();
22022de8995SAndre Fischer }
22122de8995SAndre Fischer 
22222de8995SAndre Fischer 
22322de8995SAndre Fischer 
22422de8995SAndre Fischer 
22522de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject)
22622de8995SAndre Fischer     throw(cssu::RuntimeException)
22722de8995SAndre Fischer {
22895a18594SAndre Fischer     (void)rEventObject;
229f120fe41SAndre Fischer 
230f120fe41SAndre Fischer     dispose();
23122de8995SAndre Fischer }
23222de8995SAndre Fischer 
23322de8995SAndre Fischer 
23422de8995SAndre Fischer 
23522de8995SAndre Fischer 
236b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent)
237b9e67834SAndre Fischer     throw(cssu::RuntimeException)
23895a18594SAndre Fischer {
23995a18594SAndre Fischer     (void)rEvent;
24095a18594SAndre Fischer 
24195a18594SAndre Fischer     maPropertyChangeForwarder.RequestCall();
24295a18594SAndre Fischer }
24395a18594SAndre Fischer 
24495a18594SAndre Fischer 
24595a18594SAndre Fischer 
24695a18594SAndre Fischer 
247*13e1c3b4SAndre Fischer void SAL_CALL SidebarController::statusChanged (const css::frame::FeatureStateEvent& rEvent)
248*13e1c3b4SAndre Fischer     throw(cssu::RuntimeException)
249*13e1c3b4SAndre Fischer {
250*13e1c3b4SAndre Fischer     bool bIsReadWrite (true);
251*13e1c3b4SAndre Fischer     if (rEvent.IsEnabled)
252*13e1c3b4SAndre Fischer         rEvent.State >>= bIsReadWrite;
253*13e1c3b4SAndre Fischer 
254*13e1c3b4SAndre Fischer     if (mbIsDocumentReadOnly != !bIsReadWrite)
255*13e1c3b4SAndre Fischer     {
256*13e1c3b4SAndre Fischer         mbIsDocumentReadOnly = !bIsReadWrite;
257*13e1c3b4SAndre Fischer 
258*13e1c3b4SAndre Fischer         // Force the current deck to update its panel list.
259*13e1c3b4SAndre Fischer         SwitchToDeck(msCurrentDeckId);
260*13e1c3b4SAndre Fischer     }
261*13e1c3b4SAndre Fischer }
262*13e1c3b4SAndre Fischer 
263*13e1c3b4SAndre Fischer 
264*13e1c3b4SAndre Fischer 
265*13e1c3b4SAndre Fischer 
2667a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void)
2677a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2687a32b0c8SAndre Fischer {
269f120fe41SAndre Fischer     if (mpCurrentDeck)
270f120fe41SAndre Fischer         mpCurrentDeck->RequestLayout();
2717a32b0c8SAndre Fischer     RestrictWidth();
2727a32b0c8SAndre Fischer }
2737a32b0c8SAndre Fischer 
2747a32b0c8SAndre Fischer 
2757a32b0c8SAndre Fischer 
2767a32b0c8SAndre Fischer 
27795a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void)
278b9e67834SAndre Fischer {
279b9e67834SAndre Fischer     DataChangedEvent aEvent (DATACHANGED_USER);
280b9e67834SAndre Fischer     mpParentWindow->NotifyAllChilds(aEvent);
281b9e67834SAndre Fischer     mpParentWindow->Invalidate(INVALIDATE_CHILDREN);
282b9e67834SAndre Fischer }
283b9e67834SAndre Fischer 
284b9e67834SAndre Fischer 
285b9e67834SAndre Fischer 
286b9e67834SAndre Fischer 
28722de8995SAndre Fischer void SidebarController::NotifyResize (void)
28822de8995SAndre Fischer {
28995a18594SAndre Fischer     if (mpTabBar == NULL)
29095a18594SAndre Fischer     {
29195a18594SAndre Fischer         OSL_ASSERT(mpTabBar!=NULL);
29295a18594SAndre Fischer         return;
29395a18594SAndre Fischer     }
29495a18594SAndre Fischer 
29595a18594SAndre Fischer     Window* pParentWindow = mpTabBar->GetParent();
29695a18594SAndre Fischer 
29795a18594SAndre Fischer     const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width());
29895a18594SAndre Fischer     const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height());
29995a18594SAndre Fischer 
300*13e1c3b4SAndre Fischer     mbIsDeckOpen = (nWidth > TabBar::GetDefaultWidth());
301*13e1c3b4SAndre Fischer 
302*13e1c3b4SAndre Fischer     if (mnSavedSidebarWidth <= 0)
303*13e1c3b4SAndre Fischer         mnSavedSidebarWidth = nWidth;
304*13e1c3b4SAndre Fischer 
305*13e1c3b4SAndre Fischer     bool bIsDeckVisible;
306*13e1c3b4SAndre Fischer     if (mbCanDeckBeOpened)
307*13e1c3b4SAndre Fischer     {
308*13e1c3b4SAndre Fischer         const bool bIsOpening (nWidth > mnWidthOnSplitterButtonDown);
309*13e1c3b4SAndre Fischer         if (bIsOpening)
310*13e1c3b4SAndre Fischer             bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthOpenThreshold;
311*13e1c3b4SAndre Fischer         else
312*13e1c3b4SAndre Fischer             bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthCloseThreshold;
313*13e1c3b4SAndre Fischer         mbIsDeckRequestedOpen = bIsDeckVisible;
314*13e1c3b4SAndre Fischer         UpdateCloseIndicator(!bIsDeckVisible);
315*13e1c3b4SAndre Fischer     }
316*13e1c3b4SAndre Fischer     else
317*13e1c3b4SAndre Fischer         bIsDeckVisible = false;
318*13e1c3b4SAndre Fischer 
3197a32b0c8SAndre Fischer     // Place the deck.
320f120fe41SAndre Fischer     if (mpCurrentDeck)
3217a32b0c8SAndre Fischer     {
322*13e1c3b4SAndre Fischer         if (bIsDeckVisible)
323*13e1c3b4SAndre Fischer         {
324*13e1c3b4SAndre Fischer             mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight);
325*13e1c3b4SAndre Fischer             mpCurrentDeck->Show();
326*13e1c3b4SAndre Fischer             mpCurrentDeck->RequestLayout();
327*13e1c3b4SAndre Fischer         }
328*13e1c3b4SAndre Fischer         else
329*13e1c3b4SAndre Fischer             mpCurrentDeck->Hide();
33022de8995SAndre Fischer     }
33195a18594SAndre Fischer 
3327a32b0c8SAndre Fischer     // Place the tab bar.
33395a18594SAndre Fischer     mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight);
33495a18594SAndre Fischer     mpTabBar->Show();
3357a32b0c8SAndre Fischer 
3367a32b0c8SAndre Fischer     // Determine if the closer of the deck can be shown.
337f120fe41SAndre Fischer     if (mpCurrentDeck)
3387a32b0c8SAndre Fischer     {
339f120fe41SAndre Fischer         DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
3407a32b0c8SAndre Fischer         if (pTitleBar != NULL && pTitleBar->IsVisible())
3417a32b0c8SAndre Fischer             pTitleBar->SetCloserVisible(CanModifyChildWindowWidth());
3427a32b0c8SAndre Fischer     }
3437a32b0c8SAndre Fischer 
3447a32b0c8SAndre Fischer     RestrictWidth();
345*13e1c3b4SAndre Fischer }
346*13e1c3b4SAndre Fischer 
347*13e1c3b4SAndre Fischer 
348*13e1c3b4SAndre Fischer 
349*13e1c3b4SAndre Fischer 
350*13e1c3b4SAndre Fischer void SidebarController::ProcessNewWidth (const sal_Int32 nNewWidth)
351*13e1c3b4SAndre Fischer {
352*13e1c3b4SAndre Fischer     if ( ! mbIsDeckRequestedOpen)
353*13e1c3b4SAndre Fischer         return;
354*13e1c3b4SAndre Fischer 
355*13e1c3b4SAndre Fischer     if (mbIsDeckRequestedOpen.get())
356*13e1c3b4SAndre Fischer      {
357*13e1c3b4SAndre Fischer         // Deck became large enough to be shown.  Show it.
358*13e1c3b4SAndre Fischer         mnSavedSidebarWidth = nNewWidth;
359*13e1c3b4SAndre Fischer         RequestOpenDeck();
360*13e1c3b4SAndre Fischer     }
361*13e1c3b4SAndre Fischer     else
3627a32b0c8SAndre Fischer     {
363*13e1c3b4SAndre Fischer         // Deck became too small.  Close it completely.
364*13e1c3b4SAndre Fischer         // If window is wider than the tab bar then mark the deck as being visible, even when it its not.
365*13e1c3b4SAndre Fischer         // This is to trigger an adjustment of the width to the width of the tab bar.
366*13e1c3b4SAndre Fischer         mbIsDeckOpen = true;
367*13e1c3b4SAndre Fischer         RequestCloseDeck();
368*13e1c3b4SAndre Fischer 
369*13e1c3b4SAndre Fischer         if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
370*13e1c3b4SAndre Fischer             mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
3717a32b0c8SAndre Fischer     }
37222de8995SAndre Fischer }
37322de8995SAndre Fischer 
37422de8995SAndre Fischer 
37522de8995SAndre Fischer 
37622de8995SAndre Fischer 
377239cbbc0SAndre Fischer void SidebarController::UpdateConfigurations (void)
37822de8995SAndre Fischer {
379239cbbc0SAndre Fischer     if (maCurrentContext != maRequestedContext)
38095a18594SAndre Fischer     {
381239cbbc0SAndre Fischer         maCurrentContext = maRequestedContext;
38295a18594SAndre Fischer 
383*13e1c3b4SAndre Fischer         // Find the set of decks that could be displayed for the new context.
384*13e1c3b4SAndre Fischer         ResourceManager::DeckContextDescriptorContainer aDecks;
38595a18594SAndre Fischer         ResourceManager::Instance().GetMatchingDecks (
386*13e1c3b4SAndre Fischer             aDecks,
387239cbbc0SAndre Fischer             maCurrentContext,
388*13e1c3b4SAndre Fischer             mbIsDocumentReadOnly,
38995a18594SAndre Fischer             mxFrame);
390*13e1c3b4SAndre Fischer         mpTabBar->SetDecks(aDecks);
39195a18594SAndre Fischer 
392*13e1c3b4SAndre Fischer         // Notify the tab bar about the updated set of decks.
393*13e1c3b4SAndre Fischer         mpTabBar->SetDecks(aDecks);
394*13e1c3b4SAndre Fischer 
395*13e1c3b4SAndre Fischer         // Find the new deck.  By default that is the same as the old
396*13e1c3b4SAndre Fischer         // one.  If that is not set or not enabled, then choose the
397*13e1c3b4SAndre Fischer         // first enabled deck.
398*13e1c3b4SAndre Fischer         OUString sNewDeckId;
399*13e1c3b4SAndre Fischer         for (ResourceManager::DeckContextDescriptorContainer::const_iterator
400*13e1c3b4SAndre Fischer                  iDeck(aDecks.begin()),
401*13e1c3b4SAndre Fischer                  iEnd(aDecks.end());
40295a18594SAndre Fischer              iDeck!=iEnd;
40395a18594SAndre Fischer              ++iDeck)
40495a18594SAndre Fischer         {
405*13e1c3b4SAndre Fischer             if (iDeck->mbIsEnabled)
40695a18594SAndre Fischer             {
407*13e1c3b4SAndre Fischer                 if (iDeck->msId.equals(msCurrentDeckId))
408*13e1c3b4SAndre Fischer                 {
409*13e1c3b4SAndre Fischer                     sNewDeckId = msCurrentDeckId;
410*13e1c3b4SAndre Fischer                     break;
411*13e1c3b4SAndre Fischer                 }
412*13e1c3b4SAndre Fischer                 else if (sNewDeckId.getLength() == 0)
413*13e1c3b4SAndre Fischer                     sNewDeckId = iDeck->msId;
41495a18594SAndre Fischer             }
41595a18594SAndre Fischer         }
416ff12d537SAndre Fischer 
417*13e1c3b4SAndre Fischer         if (sNewDeckId.getLength() == 0)
41895a18594SAndre Fischer         {
419*13e1c3b4SAndre Fischer             // We did not find a valid deck.
420*13e1c3b4SAndre Fischer             RequestCloseDeck();
421*13e1c3b4SAndre Fischer             return;
422*13e1c3b4SAndre Fischer 
42356798e4bSAndre Fischer             // Tell the tab bar to highlight the button associated
42456798e4bSAndre Fischer             // with the deck.
425*13e1c3b4SAndre Fischer             mpTabBar->HighlightDeck(sNewDeckId);
42695a18594SAndre Fischer         }
427*13e1c3b4SAndre Fischer 
428*13e1c3b4SAndre Fischer         msCurrentDeckId = sNewDeckId;
429*13e1c3b4SAndre Fischer         SwitchToDeck(
430*13e1c3b4SAndre Fischer             *ResourceManager::Instance().GetDeckDescriptor(sNewDeckId),
431*13e1c3b4SAndre Fischer             maCurrentContext);
43254eaaa32SAndre Fischer 
43354eaaa32SAndre Fischer #ifdef DEBUG
43454eaaa32SAndre Fischer         // Show the context name in the deck title bar.
43554eaaa32SAndre Fischer         if (mpCurrentDeck)
43654eaaa32SAndre Fischer         {
43754eaaa32SAndre Fischer             DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
43854eaaa32SAndre Fischer             if (pTitleBar != NULL)
439239cbbc0SAndre Fischer                 pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+maCurrentContext.msContext+A2S(")"));
44054eaaa32SAndre Fischer         }
44154eaaa32SAndre Fischer #endif
44295a18594SAndre Fischer     }
443ff12d537SAndre Fischer }
444ff12d537SAndre Fischer 
445ff12d537SAndre Fischer 
44622de8995SAndre Fischer 
447ff12d537SAndre Fischer 
448*13e1c3b4SAndre Fischer void SidebarController::OpenThenSwitchToDeck (
449*13e1c3b4SAndre Fischer     const ::rtl::OUString& rsDeckId)
450*13e1c3b4SAndre Fischer {
451*13e1c3b4SAndre Fischer     RequestOpenDeck();
452*13e1c3b4SAndre Fischer     SwitchToDeck(rsDeckId);
453*13e1c3b4SAndre Fischer }
454*13e1c3b4SAndre Fischer 
455*13e1c3b4SAndre Fischer 
456*13e1c3b4SAndre Fischer 
457*13e1c3b4SAndre Fischer 
458ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
45995a18594SAndre Fischer     const ::rtl::OUString& rsDeckId)
460ff12d537SAndre Fischer {
461*13e1c3b4SAndre Fischer     if ( ! msCurrentDeckId.equals(rsDeckId) || ! mbIsDeckOpen)
46295a18594SAndre Fischer     {
46395a18594SAndre Fischer         const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId);
46495a18594SAndre Fischer         if (pDeckDescriptor != NULL)
46595a18594SAndre Fischer             SwitchToDeck(*pDeckDescriptor, maCurrentContext);
46695a18594SAndre Fischer     }
46722de8995SAndre Fischer }
46822de8995SAndre Fischer 
46922de8995SAndre Fischer 
47022de8995SAndre Fischer 
47122de8995SAndre Fischer 
472ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
47322de8995SAndre Fischer     const DeckDescriptor& rDeckDescriptor,
4747a32b0c8SAndre Fischer     const Context& rContext)
47522de8995SAndre Fischer {
47665908a7eSAndre Fischer     maFocusManager.Clear();
47765908a7eSAndre Fischer 
47895a18594SAndre Fischer     if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId))
47995a18594SAndre Fischer     {
48095a18594SAndre Fischer         // When the deck changes then destroy the deck and all panels
48195a18594SAndre Fischer         // and create everything new.
482f120fe41SAndre Fischer         if (mpCurrentDeck)
48395a18594SAndre Fischer         {
484f120fe41SAndre Fischer             mpCurrentDeck->Dispose();
485f120fe41SAndre Fischer             mpCurrentDeck.reset();
48695a18594SAndre Fischer         }
48795a18594SAndre Fischer 
48895a18594SAndre Fischer         msCurrentDeckId = rDeckDescriptor.msId;
48995a18594SAndre Fischer     }
4907a32b0c8SAndre Fischer 
491ff12d537SAndre Fischer     // Determine the panels to display in the deck.
492f120fe41SAndre Fischer     ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors;
493ff12d537SAndre Fischer     ResourceManager::Instance().GetMatchingPanels(
494f120fe41SAndre Fischer         aPanelContextDescriptors,
495ff12d537SAndre Fischer         rContext,
496ff12d537SAndre Fischer         rDeckDescriptor.msId,
497ff12d537SAndre Fischer         mxFrame);
498ff12d537SAndre Fischer 
49954eaaa32SAndre Fischer     if (aPanelContextDescriptors.empty())
50054eaaa32SAndre Fischer     {
50154eaaa32SAndre Fischer         // There are no panels to be displayed in the current context.
50254eaaa32SAndre Fischer         if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty)
50354eaaa32SAndre Fischer         {
50454eaaa32SAndre Fischer             // Switch to the "empty" context and try again.
50554eaaa32SAndre Fischer             SwitchToDeck(
50654eaaa32SAndre Fischer                 rDeckDescriptor,
50754eaaa32SAndre Fischer                 Context(
50854eaaa32SAndre Fischer                     rContext.msApplication,
50954eaaa32SAndre Fischer                     EnumContext::GetContextName(EnumContext::Context_Empty)));
51054eaaa32SAndre Fischer             return;
51154eaaa32SAndre Fischer         }
51254eaaa32SAndre Fischer         else
51354eaaa32SAndre Fischer         {
51454eaaa32SAndre Fischer             // This is already the "empty" context. Looks like we have
51554eaaa32SAndre Fischer             // to live with an empty deck.
51654eaaa32SAndre Fischer         }
51754eaaa32SAndre Fischer     }
51854eaaa32SAndre Fischer 
519f120fe41SAndre Fischer     if (mpCurrentDeck
520f120fe41SAndre Fischer         && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors))
52102c50d82SAndre Fischer     {
52202c50d82SAndre Fischer         // Requested set of panels is identical to the current set of
52302c50d82SAndre Fischer         // panels => Nothing to do.
52402c50d82SAndre Fischer         return;
52502c50d82SAndre Fischer     }
526*13e1c3b4SAndre Fischer 
527*13e1c3b4SAndre Fischer         // When the document is read-only, check if there are any panels that can still be displayed.
528*13e1c3b4SAndre Fischer     if (mbIsDocumentReadOnly)
529*13e1c3b4SAndre Fischer     {
530*13e1c3b4SAndre Fischer     }
531*13e1c3b4SAndre Fischer 
532*13e1c3b4SAndre Fischer 
53395a18594SAndre Fischer     // Provide a configuration and Deck object.
534f120fe41SAndre Fischer     if ( ! mpCurrentDeck)
53522de8995SAndre Fischer     {
536f120fe41SAndre Fischer         mpCurrentDeck.reset(
537f120fe41SAndre Fischer             new Deck(
538f120fe41SAndre Fischer                 rDeckDescriptor,
539f120fe41SAndre Fischer                 mpParentWindow,
540*13e1c3b4SAndre Fischer                 ::boost::bind(&SidebarController::RequestCloseDeck, this)));
54154eaaa32SAndre Fischer         msCurrentDeckTitle = rDeckDescriptor.msTitle;
54295a18594SAndre Fischer     }
543f120fe41SAndre Fischer     if ( ! mpCurrentDeck)
544f120fe41SAndre Fischer         return;
545f120fe41SAndre Fischer 
54695a18594SAndre Fischer     // Update the panel list.
547f120fe41SAndre Fischer     const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size());
548f120fe41SAndre Fischer     SharedPanelContainer aNewPanels;
549f120fe41SAndre Fischer     const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels());
55095a18594SAndre Fischer     aNewPanels.resize(nNewPanelCount);
5517a32b0c8SAndre Fischer     sal_Int32 nWriteIndex (0);
55202c50d82SAndre Fischer     bool bHasPanelSetChanged (false);
5537a32b0c8SAndre Fischer     for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex)
55495a18594SAndre Fischer     {
555f120fe41SAndre Fischer         const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor (
556f120fe41SAndre Fischer             aPanelContextDescriptors[nReadIndex]);
55795a18594SAndre Fischer 
558*13e1c3b4SAndre Fischer         // Determine if the panel can be displayed.
559*13e1c3b4SAndre Fischer         const bool bIsPanelVisible (!mbIsDocumentReadOnly || rPanelContexDescriptor.mbShowForReadOnlyDocuments);
560*13e1c3b4SAndre Fischer         if ( ! bIsPanelVisible)
561*13e1c3b4SAndre Fischer             continue;
562*13e1c3b4SAndre Fischer 
56395a18594SAndre Fischer         // Find the corresponding panel among the currently active
56495a18594SAndre Fischer         // panels.
565f120fe41SAndre Fischer         SharedPanelContainer::const_iterator iPanel (::std::find_if(
566f120fe41SAndre Fischer                 rCurrentPanels.begin(),
567f120fe41SAndre Fischer                 rCurrentPanels.end(),
568f120fe41SAndre Fischer                 ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId))));
569f120fe41SAndre Fischer         if (iPanel != rCurrentPanels.end())
570ff12d537SAndre Fischer         {
571f120fe41SAndre Fischer             // Panel already exists in current deck.  Reuse it.
5727a32b0c8SAndre Fischer             aNewPanels[nWriteIndex] = *iPanel;
573ff12d537SAndre Fischer         }
574ff12d537SAndre Fischer         else
575ff12d537SAndre Fischer         {
57695a18594SAndre Fischer             // Panel does not yet exist.  Create it.
5777a32b0c8SAndre Fischer             aNewPanels[nWriteIndex] = CreatePanel(
578f120fe41SAndre Fischer                 rPanelContexDescriptor.msId,
579c545150fSOliver-Rainer Wittmann                 mpCurrentDeck->GetPanelParentWindow());
58002c50d82SAndre Fischer             bHasPanelSetChanged = true;
581ff12d537SAndre Fischer         }
5827a32b0c8SAndre Fischer         if (aNewPanels[nWriteIndex] != NULL)
58302c50d82SAndre Fischer         {
584f120fe41SAndre Fischer             // Depending on the context we have to collapse the panel.
585f120fe41SAndre Fischer             aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible);
586c545150fSOliver-Rainer Wittmann             // Depending on the context we have to apply the show menu functor.
587c545150fSOliver-Rainer Wittmann             aNewPanels[nWriteIndex]->SetShowMenuFunctor(
588c545150fSOliver-Rainer Wittmann                 rPanelContexDescriptor.msMenuCommand.getLength()>0
589c545150fSOliver-Rainer Wittmann                 ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rPanelContexDescriptor.msMenuCommand)
590c545150fSOliver-Rainer Wittmann                 : ::boost::function<void(void)>() );
591f120fe41SAndre Fischer 
592f120fe41SAndre Fischer             ++nWriteIndex;
59302c50d82SAndre Fischer         }
594f120fe41SAndre Fischer 
59595a18594SAndre Fischer     }
596f120fe41SAndre Fischer     aNewPanels.resize(nWriteIndex);
59795a18594SAndre Fischer 
59895a18594SAndre Fischer     // Activate the deck and the new set of panels.
599f120fe41SAndre Fischer     mpCurrentDeck->SetPosSizePixel(
60095a18594SAndre Fischer         0,
60195a18594SAndre Fischer         0,
60295a18594SAndre Fischer         mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(),
60395a18594SAndre Fischer         mpParentWindow->GetSizePixel().Height());
604f120fe41SAndre Fischer     mpCurrentDeck->SetPanels(aNewPanels);
605f120fe41SAndre Fischer     mpCurrentDeck->Show();
606ff12d537SAndre Fischer 
6077a32b0c8SAndre Fischer     mpParentWindow->SetText(rDeckDescriptor.msTitle);
6087a32b0c8SAndre Fischer 
60902c50d82SAndre Fischer     if (bHasPanelSetChanged)
61002c50d82SAndre Fischer         NotifyResize();
61165908a7eSAndre Fischer 
61265908a7eSAndre Fischer     // Tell the focus manager about the new panels and tab bar
61365908a7eSAndre Fischer     // buttons.
61465908a7eSAndre Fischer     maFocusManager.SetPanels(aNewPanels);
61565908a7eSAndre Fischer     mpTabBar->UpdateFocusManager(maFocusManager);
6164e21436dSAndre Fischer     UpdateTitleBarIcons();
61702c50d82SAndre Fischer }
61802c50d82SAndre Fischer 
61902c50d82SAndre Fischer 
62002c50d82SAndre Fischer 
62102c50d82SAndre Fischer 
62202c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual (
623f120fe41SAndre Fischer     const SharedPanelContainer& rCurrentPanels,
624f120fe41SAndre Fischer     const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels)
62502c50d82SAndre Fischer {
626f120fe41SAndre Fischer     if (rCurrentPanels.size() != rRequestedPanels.size())
62702c50d82SAndre Fischer         return false;
62802c50d82SAndre Fischer     for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex)
62902c50d82SAndre Fischer     {
63002c50d82SAndre Fischer         if (rCurrentPanels[nIndex] == NULL)
63102c50d82SAndre Fischer             return false;
632f120fe41SAndre Fischer         if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId))
63302c50d82SAndre Fischer             return false;
634*13e1c3b4SAndre Fischer 
635*13e1c3b4SAndre Fischer         // Check if the panels still can be displayed.  This may not be the case when
636*13e1c3b4SAndre Fischer         // the document just become rea-only.
637*13e1c3b4SAndre Fischer         if (mbIsDocumentReadOnly && ! rRequestedPanels[nIndex].mbShowForReadOnlyDocuments)
638*13e1c3b4SAndre Fischer             return false;
63902c50d82SAndre Fischer     }
64002c50d82SAndre Fischer     return true;
64122de8995SAndre Fischer }
64222de8995SAndre Fischer 
64322de8995SAndre Fischer 
64422de8995SAndre Fischer 
64522de8995SAndre Fischer 
646f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel (
64795a18594SAndre Fischer     const OUString& rsPanelId,
648c545150fSOliver-Rainer Wittmann     ::Window* pParentWindow )
64995a18594SAndre Fischer {
65095a18594SAndre Fischer     const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId);
65195a18594SAndre Fischer     if (pPanelDescriptor == NULL)
652f120fe41SAndre Fischer         return SharedPanel();
6537a32b0c8SAndre Fischer 
65495a18594SAndre Fischer     // Create the panel which is the parent window of the UIElement.
655f120fe41SAndre Fischer     SharedPanel pPanel (new Panel(
65695a18594SAndre Fischer         *pPanelDescriptor,
6577a32b0c8SAndre Fischer         pParentWindow,
658c545150fSOliver-Rainer Wittmann         ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()) ) );
65995a18594SAndre Fischer 
66095a18594SAndre Fischer     // Create the XUIElement.
66195a18594SAndre Fischer     Reference<ui::XUIElement> xUIElement (CreateUIElement(
66295a18594SAndre Fischer             pPanel->GetComponentInterface(),
66322f77e9eSAndre Fischer             pPanelDescriptor->msImplementationURL,
66422f77e9eSAndre Fischer             pPanelDescriptor->mbWantsCanvas));
66595a18594SAndre Fischer     if (xUIElement.is())
66695a18594SAndre Fischer     {
66795a18594SAndre Fischer         // Initialize the panel and add it to the active deck.
66895a18594SAndre Fischer         pPanel->SetUIElement(xUIElement);
66995a18594SAndre Fischer     }
67095a18594SAndre Fischer     else
67195a18594SAndre Fischer     {
672f120fe41SAndre Fischer         pPanel.reset();
67395a18594SAndre Fischer     }
67495a18594SAndre Fischer 
67595a18594SAndre Fischer     return pPanel;
67695a18594SAndre Fischer }
67795a18594SAndre Fischer 
67895a18594SAndre Fischer 
67995a18594SAndre Fischer 
68095a18594SAndre Fischer 
681ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement (
682ff12d537SAndre Fischer     const Reference<awt::XWindowPeer>& rxWindow,
68322f77e9eSAndre Fischer     const ::rtl::OUString& rsImplementationURL,
68422f77e9eSAndre Fischer     const bool bWantsCanvas)
68522de8995SAndre Fischer {
68622de8995SAndre Fischer     try
68722de8995SAndre Fischer     {
68822de8995SAndre Fischer         const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
68922de8995SAndre Fischer         const Reference<ui::XUIElementFactory> xUIElementFactory (
69022de8995SAndre Fischer             aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"),
69122de8995SAndre Fischer             UNO_QUERY_THROW);
692ff12d537SAndre Fischer 
6937a32b0c8SAndre Fischer        // Create the XUIElement.
69422de8995SAndre Fischer         ::comphelper::NamedValueCollection aCreationArguments;
69522de8995SAndre Fischer         aCreationArguments.put("Frame", makeAny(mxFrame));
696ff12d537SAndre Fischer         aCreationArguments.put("ParentWindow", makeAny(rxWindow));
697b9e67834SAndre Fischer         SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow);
698b9e67834SAndre Fischer         if (pSfxDockingWindow != NULL)
699b9e67834SAndre Fischer             aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings())));
7007a32b0c8SAndre Fischer         aCreationArguments.put("Theme", Theme::GetPropertySet());
7017a32b0c8SAndre Fischer         aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this))));
70222f77e9eSAndre Fischer         if (bWantsCanvas)
70322f77e9eSAndre Fischer         {
70422f77e9eSAndre Fischer             Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas());
70522f77e9eSAndre Fischer             aCreationArguments.put("Canvas", makeAny(xCanvas));
70622f77e9eSAndre Fischer         }
7077a32b0c8SAndre Fischer 
708b9e67834SAndre Fischer         Reference<ui::XUIElement> xUIElement(
709ff12d537SAndre Fischer             xUIElementFactory->createUIElement(
710ff12d537SAndre Fischer                 rsImplementationURL,
7117a32b0c8SAndre Fischer                 Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())),
712ff12d537SAndre Fischer             UNO_QUERY_THROW);
713b9e67834SAndre Fischer 
714b9e67834SAndre Fischer         return xUIElement;
71522de8995SAndre Fischer     }
71622de8995SAndre Fischer     catch(Exception& rException)
71722de8995SAndre Fischer     {
71822de8995SAndre Fischer         OSL_TRACE("caught exception: %s",
71922de8995SAndre Fischer             OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
72022de8995SAndre Fischer         // For some reason we can not create the actual panel.
72122de8995SAndre Fischer         // Probably because its factory was not properly registered.
72222de8995SAndre Fischer         // TODO: provide feedback to developer to better pinpoint the
72322de8995SAndre Fischer         // source of the error.
724ff12d537SAndre Fischer 
725ff12d537SAndre Fischer         return NULL;
72622de8995SAndre Fischer     }
72722de8995SAndre Fischer }
72822de8995SAndre Fischer 
72922de8995SAndre Fischer 
73022de8995SAndre Fischer 
73122de8995SAndre Fischer 
73222de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent)
73322de8995SAndre Fischer {
734*13e1c3b4SAndre Fischer     if (pEvent==NULL)
735*13e1c3b4SAndre Fischer         return sal_False;
736*13e1c3b4SAndre Fischer 
737*13e1c3b4SAndre Fischer     if (pEvent->GetWindow() == mpParentWindow)
73822de8995SAndre Fischer     {
73922de8995SAndre Fischer         switch (pEvent->GetId())
74022de8995SAndre Fischer         {
74122de8995SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
74222de8995SAndre Fischer             case VCLEVENT_WINDOW_RESIZE:
74322de8995SAndre Fischer                 NotifyResize();
74422de8995SAndre Fischer                 break;
74522de8995SAndre Fischer 
746ff12d537SAndre Fischer             case VCLEVENT_WINDOW_DATACHANGED:
747ff12d537SAndre Fischer                 // Force an update of deck and tab bar to reflect
748ff12d537SAndre Fischer                 // changes in theme (high contrast mode).
749ff12d537SAndre Fischer                 Theme::HandleDataChange();
7504e21436dSAndre Fischer                 UpdateTitleBarIcons();
751ff12d537SAndre Fischer                 mpParentWindow->Invalidate();
752ff12d537SAndre Fischer                 break;
753ff12d537SAndre Fischer 
75422de8995SAndre Fischer             case SFX_HINT_DYING:
75522de8995SAndre Fischer                 dispose();
75622de8995SAndre Fischer                 break;
75722de8995SAndre Fischer 
758*13e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_PAINT:
759*13e1c3b4SAndre Fischer                 OSL_TRACE("Paint");
760*13e1c3b4SAndre Fischer                 break;
761*13e1c3b4SAndre Fischer 
76222de8995SAndre Fischer             default:
76322de8995SAndre Fischer                 break;
76422de8995SAndre Fischer         }
76522de8995SAndre Fischer     }
766*13e1c3b4SAndre Fischer     else if (pEvent->GetWindow()==mpSplitWindow && mpSplitWindow!=NULL)
767*13e1c3b4SAndre Fischer     {
768*13e1c3b4SAndre Fischer         switch (pEvent->GetId())
769*13e1c3b4SAndre Fischer         {
770*13e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
771*13e1c3b4SAndre Fischer                 mnWidthOnSplitterButtonDown = mpParentWindow->GetSizePixel().Width();
772*13e1c3b4SAndre Fischer                 break;
773*13e1c3b4SAndre Fischer 
774*13e1c3b4SAndre Fischer             case VCLEVENT_WINDOW_MOUSEBUTTONUP:
775*13e1c3b4SAndre Fischer             {
776*13e1c3b4SAndre Fischer                 ProcessNewWidth(mpParentWindow->GetSizePixel().Width());
777*13e1c3b4SAndre Fischer                 mnWidthOnSplitterButtonDown = 0;
778*13e1c3b4SAndre Fischer                 break;
779*13e1c3b4SAndre Fischer             }
780*13e1c3b4SAndre Fischer 
781*13e1c3b4SAndre Fischer             case SFX_HINT_DYING:
782*13e1c3b4SAndre Fischer                 dispose();
783*13e1c3b4SAndre Fischer                 break;
784*13e1c3b4SAndre Fischer          }
785*13e1c3b4SAndre Fischer     }
78622de8995SAndre Fischer 
78722de8995SAndre Fischer     return sal_True;
78822de8995SAndre Fischer }
78922de8995SAndre Fischer 
79022de8995SAndre Fischer 
79122de8995SAndre Fischer 
79222de8995SAndre Fischer 
79395a18594SAndre Fischer void SidebarController::ShowPopupMenu (
79495a18594SAndre Fischer     const Rectangle& rButtonBox,
79595a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
79695a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const
79722de8995SAndre Fischer {
79895a18594SAndre Fischer     ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData);
799ff12d537SAndre Fischer     pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected));
800ff12d537SAndre Fischer 
801ff12d537SAndre Fischer     // pass toolbox button rect so the menu can stay open on button up
802ff12d537SAndre Fischer     Rectangle aBox (rButtonBox);
803ff12d537SAndre Fischer     aBox.Move(mpTabBar->GetPosPixel().X(), 0);
804ff12d537SAndre Fischer     pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN);
80522de8995SAndre Fischer }
80622de8995SAndre Fischer 
80722de8995SAndre Fischer 
80822de8995SAndre Fischer 
80922de8995SAndre Fischer 
810f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const
811f120fe41SAndre Fischer {
812f120fe41SAndre Fischer     try
813f120fe41SAndre Fischer     {
814*13e1c3b4SAndre Fischer         const util::URL aURL (GetURL(rsMenuCommand));
815*13e1c3b4SAndre Fischer         Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
816f120fe41SAndre Fischer         if (xDispatch.is())
817f120fe41SAndre Fischer             xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
818f120fe41SAndre Fischer     }
819f120fe41SAndre Fischer     catch(Exception& rException)
820f120fe41SAndre Fischer     {
821f120fe41SAndre Fischer         OSL_TRACE("caught exception: %s",
822f120fe41SAndre Fischer             OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
823f120fe41SAndre Fischer     }
824f120fe41SAndre Fischer }
825f120fe41SAndre Fischer 
826f120fe41SAndre Fischer 
827f120fe41SAndre Fischer 
828f120fe41SAndre Fischer 
829*13e1c3b4SAndre Fischer util::URL SidebarController::GetURL (const ::rtl::OUString& rsCommand) const
830*13e1c3b4SAndre Fischer {
831*13e1c3b4SAndre Fischer     util::URL aURL;
832*13e1c3b4SAndre Fischer     aURL.Complete = rsCommand;
833*13e1c3b4SAndre Fischer 
834*13e1c3b4SAndre Fischer     const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
835*13e1c3b4SAndre Fischer     const Reference<util::XURLTransformer> xParser (
836*13e1c3b4SAndre Fischer         aComponentContext.createComponent("com.sun.star.util.URLTransformer"),
837*13e1c3b4SAndre Fischer             UNO_QUERY_THROW);
838*13e1c3b4SAndre Fischer     xParser->parseStrict(aURL);
839*13e1c3b4SAndre Fischer 
840*13e1c3b4SAndre Fischer     return aURL;
841*13e1c3b4SAndre Fischer }
842*13e1c3b4SAndre Fischer 
843*13e1c3b4SAndre Fischer 
844*13e1c3b4SAndre Fischer 
845*13e1c3b4SAndre Fischer 
846*13e1c3b4SAndre Fischer Reference<frame::XDispatch> SidebarController::GetDispatch (const util::URL& rURL) const
847*13e1c3b4SAndre Fischer {
848*13e1c3b4SAndre Fischer     Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW);
849*13e1c3b4SAndre Fischer     Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, OUString(), 0));
850*13e1c3b4SAndre Fischer     return xDispatch;
851*13e1c3b4SAndre Fischer }
852*13e1c3b4SAndre Fischer 
853*13e1c3b4SAndre Fischer 
854*13e1c3b4SAndre Fischer 
855*13e1c3b4SAndre Fischer 
85695a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu (
85795a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
85895a18594SAndre Fischer     const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const
85922de8995SAndre Fischer {
860ff12d537SAndre Fischer     ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu());
861ff12d537SAndre Fischer     FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
862ff12d537SAndre Fischer     if (pMenuWindow != NULL)
863ff12d537SAndre Fischer     {
864ff12d537SAndre Fischer         pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
865ff12d537SAndre Fischer     }
866ff12d537SAndre Fischer 
867ff12d537SAndre Fischer     SidebarResource aLocalResource;
868ff12d537SAndre Fischer 
869ff12d537SAndre Fischer     // Add one entry for every tool panel element to individually make
870ff12d537SAndre Fischer     // them visible or hide them.
87122de8995SAndre Fischer     {
87295a18594SAndre Fischer         sal_Int32 nIndex (MID_FIRST_PANEL);
87395a18594SAndre Fischer         for(::std::vector<TabBar::DeckMenuData>::const_iterator
87495a18594SAndre Fischer                 iItem(rDeckSelectionData.begin()),
87595a18594SAndre Fischer                 iEnd(rDeckSelectionData.end());
87695a18594SAndre Fischer             iItem!=iEnd;
87795a18594SAndre Fischer             ++iItem)
87895a18594SAndre Fischer         {
87995a18594SAndre Fischer             pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK);
88095a18594SAndre Fischer             pMenu->CheckItem(nIndex, iItem->get<2>());
88195a18594SAndre Fischer             ++nIndex;
88295a18594SAndre Fischer         }
88322de8995SAndre Fischer     }
88422de8995SAndre Fischer 
88595a18594SAndre Fischer     pMenu->InsertSeparator();
88695a18594SAndre Fischer 
887ff12d537SAndre Fischer     // Add entry for docking or un-docking the tool panel.
888ff12d537SAndre Fischer     if (mpParentWindow->IsFloatingMode())
889ff12d537SAndre Fischer         pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK)));
890ff12d537SAndre Fischer     else
891ff12d537SAndre Fischer         pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK)));
892ff12d537SAndre Fischer 
893ff12d537SAndre Fischer     // Add sub menu for customization (hiding of deck tabs.)
894ff12d537SAndre Fischer     PopupMenu* pCustomizationMenu = new PopupMenu();
89595a18594SAndre Fischer     {
89695a18594SAndre Fischer         sal_Int32 nIndex (MID_FIRST_HIDE);
89795a18594SAndre Fischer         for(::std::vector<TabBar::DeckMenuData>::const_iterator
89895a18594SAndre Fischer                 iItem(rDeckShowData.begin()),
89995a18594SAndre Fischer                 iEnd(rDeckShowData.end());
90095a18594SAndre Fischer             iItem!=iEnd;
90195a18594SAndre Fischer             ++iItem)
90295a18594SAndre Fischer         {
90395a18594SAndre Fischer             pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE);
90495a18594SAndre Fischer             pCustomizationMenu->CheckItem(nIndex, iItem->get<2>());
90595a18594SAndre Fischer             ++nIndex;
90695a18594SAndre Fischer         }
90795a18594SAndre Fischer     }
90895a18594SAndre Fischer 
909ff12d537SAndre Fischer     pCustomizationMenu->InsertSeparator();
910ff12d537SAndre Fischer     pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE)));
911ff12d537SAndre Fischer 
912ff12d537SAndre Fischer     pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION)));
913ff12d537SAndre Fischer     pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu);
914ff12d537SAndre Fischer 
915ff12d537SAndre Fischer     pMenu->RemoveDisabledEntries(sal_False, sal_False);
916ff12d537SAndre Fischer 
917ff12d537SAndre Fischer     return pMenu;
91822de8995SAndre Fischer }
91922de8995SAndre Fischer 
92022de8995SAndre Fischer 
92122de8995SAndre Fischer 
92222de8995SAndre Fischer 
923ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu)
92422de8995SAndre Fischer {
925ff12d537SAndre Fischer     if (pMenu == NULL)
926ff12d537SAndre Fischer     {
9277a32b0c8SAndre Fischer         OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!");
928ff12d537SAndre Fischer         return 0;
929ff12d537SAndre Fischer     }
93022de8995SAndre Fischer 
931ff12d537SAndre Fischer     pMenu->Deactivate();
932ff12d537SAndre Fischer     const sal_Int32 nIndex (pMenu->GetCurItemId());
933ff12d537SAndre Fischer     switch (nIndex)
93422de8995SAndre Fischer     {
935ff12d537SAndre Fischer         case MID_UNLOCK_TASK_PANEL:
936ff12d537SAndre Fischer             mpParentWindow->SetFloatingMode(sal_True);
937ff12d537SAndre Fischer             break;
938ff12d537SAndre Fischer 
939ff12d537SAndre Fischer         case MID_LOCK_TASK_PANEL:
940ff12d537SAndre Fischer             mpParentWindow->SetFloatingMode(sal_False);
941ff12d537SAndre Fischer             break;
942ff12d537SAndre Fischer 
943ff12d537SAndre Fischer         case MID_RESTORE_DEFAULT:
944ff12d537SAndre Fischer             mpTabBar->RestoreHideFlags();
945ff12d537SAndre Fischer             break;
946ff12d537SAndre Fischer 
947ff12d537SAndre Fischer         default:
948ff12d537SAndre Fischer         {
949ff12d537SAndre Fischer             try
950ff12d537SAndre Fischer             {
951ff12d537SAndre Fischer                 if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE)
95295a18594SAndre Fischer                     SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL));
953ff12d537SAndre Fischer                 else if (nIndex >=MID_FIRST_HIDE)
954ff12d537SAndre Fischer                     mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE);
955ff12d537SAndre Fischer             }
956ff12d537SAndre Fischer             catch (RuntimeException&)
957ff12d537SAndre Fischer             {
958ff12d537SAndre Fischer             }
959ff12d537SAndre Fischer         }
960ff12d537SAndre Fischer         break;
96122de8995SAndre Fischer     }
962ff12d537SAndre Fischer 
963ff12d537SAndre Fischer     return 1;
96422de8995SAndre Fischer }
96522de8995SAndre Fischer 
96622de8995SAndre Fischer 
967ff12d537SAndre Fischer 
968ff12d537SAndre Fischer 
969*13e1c3b4SAndre Fischer void SidebarController::RequestCloseDeck (void)
9707a32b0c8SAndre Fischer {
971*13e1c3b4SAndre Fischer     mbIsDeckRequestedOpen = false;
972*13e1c3b4SAndre Fischer     UpdateDeckOpenState();
9737a32b0c8SAndre Fischer }
9747a32b0c8SAndre Fischer 
9757a32b0c8SAndre Fischer 
9767a32b0c8SAndre Fischer 
9777a32b0c8SAndre Fischer 
978*13e1c3b4SAndre Fischer void SidebarController::RequestOpenDeck (void)
9797a32b0c8SAndre Fischer {
980*13e1c3b4SAndre Fischer     mbIsDeckRequestedOpen = true;
981*13e1c3b4SAndre Fischer     UpdateDeckOpenState();
982*13e1c3b4SAndre Fischer }
983*13e1c3b4SAndre Fischer 
9847a32b0c8SAndre Fischer 
9857a32b0c8SAndre Fischer 
986*13e1c3b4SAndre Fischer 
987*13e1c3b4SAndre Fischer void SidebarController::UpdateDeckOpenState (void)
988*13e1c3b4SAndre Fischer {
989*13e1c3b4SAndre Fischer     if ( ! mbIsDeckRequestedOpen)
990*13e1c3b4SAndre Fischer         // No state requested.
991*13e1c3b4SAndre Fischer         return;
992*13e1c3b4SAndre Fischer 
993*13e1c3b4SAndre Fischer     // Update (change) the open state when it either has not yet been initialized
994*13e1c3b4SAndre Fischer     // or when its value differs from the requested state.
995*13e1c3b4SAndre Fischer     if ( ! mbIsDeckOpen
996*13e1c3b4SAndre Fischer         || mbIsDeckOpen.get() != mbIsDeckRequestedOpen.get())
997*13e1c3b4SAndre Fischer     {
998*13e1c3b4SAndre Fischer         if (mbIsDeckRequestedOpen.get())
999*13e1c3b4SAndre Fischer         {
1000*13e1c3b4SAndre Fischer             if (mnSavedSidebarWidth <= TabBar::GetDefaultWidth())
1001*13e1c3b4SAndre Fischer                 SetChildWindowWidth(SidebarChildWindow::GetDefaultWidth(mpParentWindow));
1002*13e1c3b4SAndre Fischer             else
1003*13e1c3b4SAndre Fischer                 SetChildWindowWidth(mnSavedSidebarWidth);
1004*13e1c3b4SAndre Fischer         }
1005*13e1c3b4SAndre Fischer         else
1006*13e1c3b4SAndre Fischer         {
1007*13e1c3b4SAndre Fischer             if ( ! mpParentWindow->IsFloatingMode())
1008*13e1c3b4SAndre Fischer                 mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth());
1009*13e1c3b4SAndre Fischer             if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
1010*13e1c3b4SAndre Fischer                 mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
1011*13e1c3b4SAndre Fischer             mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE);
1012*13e1c3b4SAndre Fischer         }
1013*13e1c3b4SAndre Fischer 
1014*13e1c3b4SAndre Fischer         mbIsDeckOpen = mbIsDeckRequestedOpen.get();
1015*13e1c3b4SAndre Fischer         if (mbIsDeckOpen.get() && mpCurrentDeck)
1016*13e1c3b4SAndre Fischer             mpCurrentDeck->Show(mbIsDeckOpen.get());
10177a32b0c8SAndre Fischer         NotifyResize();
10187a32b0c8SAndre Fischer     }
10197a32b0c8SAndre Fischer }
10207a32b0c8SAndre Fischer 
10217a32b0c8SAndre Fischer 
10227a32b0c8SAndre Fischer 
10237a32b0c8SAndre Fischer 
102465908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void)
102565908a7eSAndre Fischer {
102665908a7eSAndre Fischer     return maFocusManager;
102765908a7eSAndre Fischer }
102865908a7eSAndre Fischer 
102965908a7eSAndre Fischer 
103065908a7eSAndre Fischer 
103165908a7eSAndre Fischer 
1032*13e1c3b4SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void)
10337a32b0c8SAndre Fischer {
1034*13e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10357a32b0c8SAndre Fischer     if (pSplitWindow == NULL)
1036*13e1c3b4SAndre Fischer         return false;
10377a32b0c8SAndre Fischer 
10387a32b0c8SAndre Fischer     sal_uInt16 nRow (0xffff);
10397a32b0c8SAndre Fischer     sal_uInt16 nColumn (0xffff);
10407a32b0c8SAndre Fischer     pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow);
10417a32b0c8SAndre Fischer 
10427a32b0c8SAndre Fischer     sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn));
10437a32b0c8SAndre Fischer 
1044*13e1c3b4SAndre Fischer     return nRowCount==1;
10457a32b0c8SAndre Fischer }
10467a32b0c8SAndre Fischer 
10477a32b0c8SAndre Fischer 
10487a32b0c8SAndre Fischer 
10497a32b0c8SAndre Fischer 
10507a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth)
10517a32b0c8SAndre Fischer {
1052*13e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10537a32b0c8SAndre Fischer     if (pSplitWindow == NULL)
10547a32b0c8SAndre Fischer         return 0;
10557a32b0c8SAndre Fischer 
10567a32b0c8SAndre Fischer     sal_uInt16 nRow (0xffff);
10577a32b0c8SAndre Fischer     sal_uInt16 nColumn (0xffff);
10587a32b0c8SAndre Fischer     pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow);
10597a32b0c8SAndre Fischer     const long nColumnWidth (pSplitWindow->GetLineSize(nColumn));
10607a32b0c8SAndre Fischer 
10617a32b0c8SAndre Fischer     Window* pWindow = mpParentWindow;
10627a32b0c8SAndre Fischer     const Point aWindowPosition (pWindow->GetPosPixel());
10637a32b0c8SAndre Fischer     const Size aWindowSize (pWindow->GetSizePixel());
10647a32b0c8SAndre Fischer 
10657a32b0c8SAndre Fischer     pSplitWindow->MoveWindow(
10667a32b0c8SAndre Fischer         mpParentWindow,
10677a32b0c8SAndre Fischer         Size(nNewWidth, aWindowSize.Height()),
10687a32b0c8SAndre Fischer         nColumn,
10697a32b0c8SAndre Fischer         nRow);
1070*13e1c3b4SAndre Fischer     static_cast<SplitWindow*>(pSplitWindow)->Split();
1071*13e1c3b4SAndre Fischer 
10727a32b0c8SAndre Fischer     return static_cast<sal_Int32>(nColumnWidth);
10737a32b0c8SAndre Fischer }
10747a32b0c8SAndre Fischer 
10757a32b0c8SAndre Fischer 
10767a32b0c8SAndre Fischer 
10777a32b0c8SAndre Fischer 
10787a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void)
10797a32b0c8SAndre Fischer {
1080*13e1c3b4SAndre Fischer     SfxSplitWindow* pSplitWindow = GetSplitWindow();
10817a32b0c8SAndre Fischer     if (pSplitWindow != NULL)
10827a32b0c8SAndre Fischer     {
10837a32b0c8SAndre Fischer         const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow));
10847a32b0c8SAndre Fischer         const sal_uInt16 nSetId (pSplitWindow->GetSet(nId));
10857a32b0c8SAndre Fischer         pSplitWindow->SetItemSizeRange(
10867a32b0c8SAndre Fischer             nSetId,
1087*13e1c3b4SAndre Fischer             Range(TabBar::GetDefaultWidth(), gnMaximumSidebarWidth));
1088*13e1c3b4SAndre Fischer     }
1089*13e1c3b4SAndre Fischer }
1090*13e1c3b4SAndre Fischer 
1091*13e1c3b4SAndre Fischer 
1092*13e1c3b4SAndre Fischer 
1093*13e1c3b4SAndre Fischer 
1094*13e1c3b4SAndre Fischer SfxSplitWindow* SidebarController::GetSplitWindow (void)
1095*13e1c3b4SAndre Fischer {
1096*13e1c3b4SAndre Fischer     if (mpSplitWindow == NULL)
1097*13e1c3b4SAndre Fischer     {
1098*13e1c3b4SAndre Fischer         if (mpParentWindow != NULL)
1099*13e1c3b4SAndre Fischer         {
1100*13e1c3b4SAndre Fischer             mpSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent());
1101*13e1c3b4SAndre Fischer             if (mpSplitWindow != NULL)
1102*13e1c3b4SAndre Fischer                 mpSplitWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
1103*13e1c3b4SAndre Fischer         }
1104*13e1c3b4SAndre Fischer     }
1105*13e1c3b4SAndre Fischer 
1106*13e1c3b4SAndre Fischer     return mpSplitWindow;
1107*13e1c3b4SAndre Fischer }
1108*13e1c3b4SAndre Fischer 
1109*13e1c3b4SAndre Fischer 
1110*13e1c3b4SAndre Fischer 
1111*13e1c3b4SAndre Fischer 
1112*13e1c3b4SAndre Fischer void SidebarController::UpdateCloseIndicator (const bool bCloseAfterDrag)
1113*13e1c3b4SAndre Fischer {
1114*13e1c3b4SAndre Fischer     if (mpParentWindow == NULL)
1115*13e1c3b4SAndre Fischer         return;
1116*13e1c3b4SAndre Fischer 
1117*13e1c3b4SAndre Fischer     if (bCloseAfterDrag)
1118*13e1c3b4SAndre Fischer     {
1119*13e1c3b4SAndre Fischer         // Make sure that the indicator exists.
1120*13e1c3b4SAndre Fischer         if ( ! mpCloseIndicator)
1121*13e1c3b4SAndre Fischer         {
1122*13e1c3b4SAndre Fischer             mpCloseIndicator.reset(new FixedImage(mpParentWindow));
1123*13e1c3b4SAndre Fischer             FixedImage* pFixedImage = static_cast<FixedImage*>(mpCloseIndicator.get());
1124*13e1c3b4SAndre Fischer             const Image aImage (Theme::GetImage(Theme::Image_CloseIndicator));
1125*13e1c3b4SAndre Fischer             pFixedImage->SetImage(aImage);
1126*13e1c3b4SAndre Fischer             pFixedImage->SetSizePixel(aImage.GetSizePixel());
1127*13e1c3b4SAndre Fischer             pFixedImage->SetBackground(Theme::GetWallpaper(Theme::Paint_DeckBackground));
1128*13e1c3b4SAndre Fischer         }
1129*13e1c3b4SAndre Fischer 
1130*13e1c3b4SAndre Fischer         // Place and show the indicator.
1131*13e1c3b4SAndre Fischer         const Size aWindowSize (mpParentWindow->GetSizePixel());
1132*13e1c3b4SAndre Fischer         const Size aImageSize (mpCloseIndicator->GetSizePixel());
1133*13e1c3b4SAndre Fischer         mpCloseIndicator->SetPosPixel(
1134*13e1c3b4SAndre Fischer             Point(
1135*13e1c3b4SAndre Fischer                 aWindowSize.Width() - TabBar::GetDefaultWidth() - aImageSize.Width(),
1136*13e1c3b4SAndre Fischer                 (aWindowSize.Height() - aImageSize.Height())/2));
1137*13e1c3b4SAndre Fischer         mpCloseIndicator->Show();
1138*13e1c3b4SAndre Fischer     }
1139*13e1c3b4SAndre Fischer     else
1140*13e1c3b4SAndre Fischer     {
1141*13e1c3b4SAndre Fischer         // Hide but don't delete the indicator.
1142*13e1c3b4SAndre Fischer         if (mpCloseIndicator)
1143*13e1c3b4SAndre Fischer             mpCloseIndicator->Hide();
11447a32b0c8SAndre Fischer     }
11457a32b0c8SAndre Fischer }
11467a32b0c8SAndre Fischer 
1147ff12d537SAndre Fischer 
11484e21436dSAndre Fischer 
11494e21436dSAndre Fischer 
11504e21436dSAndre Fischer void SidebarController::UpdateTitleBarIcons (void)
11514e21436dSAndre Fischer {
11524e21436dSAndre Fischer     if ( ! mpCurrentDeck)
11534e21436dSAndre Fischer         return;
11544e21436dSAndre Fischer 
11554e21436dSAndre Fischer     const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
11564e21436dSAndre Fischer     const ResourceManager& rResourceManager (ResourceManager::Instance());
11574e21436dSAndre Fischer 
11584e21436dSAndre Fischer     // Update the deck icon.
11594e21436dSAndre Fischer     const DeckDescriptor* pDeckDescriptor = rResourceManager.GetDeckDescriptor(mpCurrentDeck->GetId());
11604e21436dSAndre Fischer     if (pDeckDescriptor != NULL && mpCurrentDeck->GetTitleBar())
11614e21436dSAndre Fischer     {
11624e21436dSAndre Fischer         const OUString sIconURL(
11634e21436dSAndre Fischer             bIsHighContrastModeActive
11644e21436dSAndre Fischer                 ? pDeckDescriptor->msHighContrastTitleBarIconURL
11654e21436dSAndre Fischer                 : pDeckDescriptor->msTitleBarIconURL);
11664e21436dSAndre Fischer         mpCurrentDeck->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
11674e21436dSAndre Fischer     }
11684e21436dSAndre Fischer 
11694e21436dSAndre Fischer     // Update the panel icons.
11704e21436dSAndre Fischer     const SharedPanelContainer& rPanels (mpCurrentDeck->GetPanels());
11714e21436dSAndre Fischer     for (SharedPanelContainer::const_iterator
11724e21436dSAndre Fischer              iPanel(rPanels.begin()), iEnd(rPanels.end());
11734e21436dSAndre Fischer              iPanel!=iEnd;
11744e21436dSAndre Fischer              ++iPanel)
11754e21436dSAndre Fischer     {
11764e21436dSAndre Fischer         if ( ! *iPanel)
11774e21436dSAndre Fischer             continue;
11784e21436dSAndre Fischer         if ((*iPanel)->GetTitleBar() == NULL)
11794e21436dSAndre Fischer             continue;
11804e21436dSAndre Fischer         const PanelDescriptor* pPanelDescriptor = rResourceManager.GetPanelDescriptor((*iPanel)->GetId());
11814e21436dSAndre Fischer         if (pPanelDescriptor == NULL)
11824e21436dSAndre Fischer             continue;
11834e21436dSAndre Fischer         const OUString sIconURL (
11844e21436dSAndre Fischer             bIsHighContrastModeActive
11854e21436dSAndre Fischer                ? pPanelDescriptor->msHighContrastTitleBarIconURL
11864e21436dSAndre Fischer                : pPanelDescriptor->msTitleBarIconURL);
11874e21436dSAndre Fischer         (*iPanel)->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
11884e21436dSAndre Fischer     }
11894e21436dSAndre Fischer }
11904e21436dSAndre Fischer 
11914e21436dSAndre Fischer 
1192ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
1193