122de8995SAndre Fischer /**************************************************************
2*6b5a962bSmseidel *
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
10*6b5a962bSmseidel *
1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12*6b5a962bSmseidel *
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.
19*6b5a962bSmseidel *
2022de8995SAndre Fischer *************************************************************/
2122de8995SAndre Fischer
22*6b5a962bSmseidel
23*6b5a962bSmseidel
2422de8995SAndre Fischer #include "precompiled_sfx2.hxx"
2522de8995SAndre Fischer
2622de8995SAndre Fischer #include "SidebarController.hxx"
2722de8995SAndre Fischer #include "Deck.hxx"
287a32b0c8SAndre Fischer #include "DeckTitleBar.hxx"
2922de8995SAndre Fischer #include "Panel.hxx"
308a1a651aSAndre Fischer #include "PanelTitleBar.hxx"
31b9e67834SAndre Fischer #include "SidebarPanel.hxx"
32ff12d537SAndre Fischer #include "SidebarResource.hxx"
3322de8995SAndre Fischer #include "TabBar.hxx"
34b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
3513e1c3b4SAndre Fischer #include "sfx2/sidebar/SidebarChildWindow.hxx"
36f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
377a32b0c8SAndre Fischer #include "SidebarDockingWindow.hxx"
387a32b0c8SAndre Fischer #include "Context.hxx"
39ff12d537SAndre Fischer
4022de8995SAndre Fischer #include "sfxresid.hxx"
4122de8995SAndre Fischer #include "sfx2/sfxsids.hrc"
427a32b0c8SAndre Fischer #include "sfx2/titledockwin.hxx"
43ff12d537SAndre Fischer #include "sfxlocal.hrc"
44ff12d537SAndre Fischer #include <vcl/floatwin.hxx>
4513e1c3b4SAndre Fischer #include <vcl/fixed.hxx>
467a32b0c8SAndre Fischer #include "splitwin.hxx"
4795a18594SAndre Fischer #include <svl/smplhint.hxx>
4895a18594SAndre Fischer #include <tools/link.hxx>
4922f77e9eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
5022f77e9eSAndre Fischer
51ff12d537SAndre Fischer #include <comphelper/componentfactory.hxx>
5295a18594SAndre Fischer #include <comphelper/processfactory.hxx>
53ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx>
54ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
5522de8995SAndre Fischer
56f120fe41SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp>
57f120fe41SAndre Fischer #include <com/sun/star/lang/XInitialization.hpp>
5822de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
5922de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp>
6095a18594SAndre Fischer #include <com/sun/star/ui/XUIElementFactory.hpp>
61f120fe41SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp>
62f120fe41SAndre Fischer #include <com/sun/star/util/URL.hpp>
6322f77e9eSAndre Fischer #include <com/sun/star/rendering/XSpriteCanvas.hpp>
6422de8995SAndre Fischer
6522de8995SAndre Fischer #include <boost/bind.hpp>
66f120fe41SAndre Fischer #include <boost/function.hpp>
677a32b0c8SAndre Fischer #include <boost/scoped_array.hpp>
6822de8995SAndre Fischer
6922de8995SAndre Fischer
7022de8995SAndre Fischer using namespace css;
7122de8995SAndre Fischer using namespace cssu;
7295a18594SAndre Fischer using ::rtl::OUString;
7322de8995SAndre Fischer
7402c50d82SAndre Fischer
7556798e4bSAndre Fischer #undef VERBOSE
7622de8995SAndre Fischer
7713e1c3b4SAndre Fischer namespace
7813e1c3b4SAndre Fischer {
7913e1c3b4SAndre Fischer const static OUString gsReadOnlyCommandName (A2S(".uno:EditDoc"));
8013e1c3b4SAndre Fischer const static sal_Int32 gnMaximumSidebarWidth (400);
8113e1c3b4SAndre Fischer const static sal_Int32 gnWidthCloseThreshold (70);
8213e1c3b4SAndre Fischer const static sal_Int32 gnWidthOpenThreshold (40);
8313e1c3b4SAndre Fischer }
8413e1c3b4SAndre Fischer
8513e1c3b4SAndre Fischer
86ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
8722de8995SAndre Fischer
883091fa8aSAndre Fischer SidebarController::SidebarControllerContainer SidebarController::maSidebarControllerContainer;
893091fa8aSAndre Fischer
90ff12d537SAndre Fischer namespace {
91ff12d537SAndre Fischer enum MenuId
92ff12d537SAndre Fischer {
93ff12d537SAndre Fischer MID_UNLOCK_TASK_PANEL = 1,
94ff12d537SAndre Fischer MID_LOCK_TASK_PANEL,
95ff12d537SAndre Fischer MID_CUSTOMIZATION,
96ff12d537SAndre Fischer MID_RESTORE_DEFAULT,
97ff12d537SAndre Fischer MID_FIRST_PANEL,
98ff12d537SAndre Fischer MID_FIRST_HIDE = 1000
99ff12d537SAndre Fischer };
100309fba80SAndre Fischer
101309fba80SAndre Fischer /** When in doubt, show this deck.
102309fba80SAndre Fischer */
103309fba80SAndre Fischer static const ::rtl::OUString gsDefaultDeckId(A2S("PropertyDeck"));
104ff12d537SAndre Fischer }
10522de8995SAndre Fischer
10622de8995SAndre Fischer
SidebarController(SidebarDockingWindow * pParentWindow,const cssu::Reference<css::frame::XFrame> & rxFrame)10722de8995SAndre Fischer SidebarController::SidebarController (
1087a32b0c8SAndre Fischer SidebarDockingWindow* pParentWindow,
10922de8995SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame)
11022de8995SAndre Fischer : SidebarControllerInterfaceBase(m_aMutex),
111f120fe41SAndre Fischer mpCurrentDeck(),
11222de8995SAndre Fischer mpParentWindow(pParentWindow),
113ff12d537SAndre Fischer mpTabBar(new TabBar(
114ff12d537SAndre Fischer mpParentWindow,
115ff12d537SAndre Fischer rxFrame,
11613e1c3b4SAndre Fischer ::boost::bind(&SidebarController::OpenThenSwitchToDeck, this, _1),
117be6d8c25SAndre Fischer ::boost::bind(&SidebarController::ShowPopupMenu, this, _1,_2))),
11895a18594SAndre Fischer mxFrame(rxFrame),
1197a32b0c8SAndre Fischer maCurrentContext(OUString(), OUString()),
12052d13b84SAndre Fischer maRequestedContext(),
121a5297dafSAndre Fischer mnRequestedForceFlags(SwitchFlag_NoForce),
122309fba80SAndre Fischer msCurrentDeckId(gsDefaultDeckId),
12352d13b84SAndre Fischer msCurrentDeckTitle(),
1247a32b0c8SAndre Fischer maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)),
125239cbbc0SAndre Fischer maContextChangeUpdate(::boost::bind(&SidebarController::UpdateConfigurations, this)),
1263091fa8aSAndre Fischer maAsynchronousDeckSwitch(),
12713e1c3b4SAndre Fischer mbIsDeckRequestedOpen(),
12813e1c3b4SAndre Fischer mbIsDeckOpen(),
12913e1c3b4SAndre Fischer mbCanDeckBeOpened(true),
13013e1c3b4SAndre Fischer mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()),
13152d13b84SAndre Fischer maFocusManager(::boost::bind(&SidebarController::ShowPanel, this, _1)),
13213e1c3b4SAndre Fischer mxReadOnlyModeDispatch(),
13313e1c3b4SAndre Fischer mbIsDocumentReadOnly(false),
13413e1c3b4SAndre Fischer mpSplitWindow(NULL),
13513e1c3b4SAndre Fischer mnWidthOnSplitterButtonDown(0),
13613e1c3b4SAndre Fischer mpCloseIndicator()
13722de8995SAndre Fischer {
13822de8995SAndre Fischer if (pParentWindow == NULL)
13922de8995SAndre Fischer {
14022de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL);
14122de8995SAndre Fischer return;
14222de8995SAndre Fischer }
14322de8995SAndre Fischer
14422de8995SAndre Fischer // Listen for context change events.
14522de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
14622de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get(
14722de8995SAndre Fischer ::comphelper::getProcessComponentContext()));
14822de8995SAndre Fischer if (xMultiplexer.is())
14922de8995SAndre Fischer xMultiplexer->addContextChangeEventListener(
15022de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this),
15195a18594SAndre Fischer mxFrame->getController());
15222de8995SAndre Fischer
15322de8995SAndre Fischer // Listen for window events.
15422de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
155b9e67834SAndre Fischer
156b9e67834SAndre Fischer // Listen for theme property changes.
157b9e67834SAndre Fischer Theme::GetPropertySet()->addPropertyChangeListener(
158b9e67834SAndre Fischer A2S(""),
159b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this));
160f120fe41SAndre Fischer
16113e1c3b4SAndre Fischer // Get the dispatch object as preparation to listen for changes of
16213e1c3b4SAndre Fischer // the read-only state.
163f35c6d02SAndre Fischer const util::URL aURL (Tools::GetURL(gsReadOnlyCommandName));
164f35c6d02SAndre Fischer mxReadOnlyModeDispatch = Tools::GetDispatch(mxFrame, aURL);
16513e1c3b4SAndre Fischer if (mxReadOnlyModeDispatch.is())
16613e1c3b4SAndre Fischer mxReadOnlyModeDispatch->addStatusListener(this, aURL);
16713e1c3b4SAndre Fischer
168f120fe41SAndre Fischer SwitchToDeck(A2S("default"));
1693091fa8aSAndre Fischer
1703091fa8aSAndre Fischer WeakReference<SidebarController> xWeakController (this);
1713091fa8aSAndre Fischer maSidebarControllerContainer.insert(
1723091fa8aSAndre Fischer SidebarControllerContainer::value_type(
1733091fa8aSAndre Fischer rxFrame,
1743091fa8aSAndre Fischer xWeakController));
17522de8995SAndre Fischer }
17622de8995SAndre Fischer
17722de8995SAndre Fischer
17822de8995SAndre Fischer
17922de8995SAndre Fischer
~SidebarController(void)18022de8995SAndre Fischer SidebarController::~SidebarController (void)
18122de8995SAndre Fischer {
18222de8995SAndre Fischer }
18322de8995SAndre Fischer
18422de8995SAndre Fischer
18522de8995SAndre Fischer
18622de8995SAndre Fischer
GetSidebarControllerForFrame(const cssu::Reference<css::frame::XFrame> & rxFrame)1873091fa8aSAndre Fischer SidebarController* SidebarController::GetSidebarControllerForFrame (
1883091fa8aSAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame)
1893091fa8aSAndre Fischer {
1903091fa8aSAndre Fischer SidebarControllerContainer::iterator iEntry (maSidebarControllerContainer.find(rxFrame));
1913091fa8aSAndre Fischer if (iEntry == maSidebarControllerContainer.end())
1923091fa8aSAndre Fischer return NULL;
1933091fa8aSAndre Fischer
1943091fa8aSAndre Fischer cssu::Reference<XInterface> xController (iEntry->second.get());
1953091fa8aSAndre Fischer if ( ! xController.is())
1963091fa8aSAndre Fischer return NULL;
1973091fa8aSAndre Fischer
1983091fa8aSAndre Fischer return dynamic_cast<SidebarController*>(xController.get());
1993091fa8aSAndre Fischer }
2003091fa8aSAndre Fischer
2013091fa8aSAndre Fischer
2023091fa8aSAndre Fischer
2033091fa8aSAndre Fischer
disposing(void)20422de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void)
20522de8995SAndre Fischer {
2063091fa8aSAndre Fischer SidebarControllerContainer::iterator iEntry (maSidebarControllerContainer.find(mxFrame));
2073091fa8aSAndre Fischer if (iEntry != maSidebarControllerContainer.end())
2083091fa8aSAndre Fischer maSidebarControllerContainer.erase(iEntry);
209*6b5a962bSmseidel
21065908a7eSAndre Fischer maFocusManager.Clear();
21165908a7eSAndre Fischer
21222de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
21322de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get(
21422de8995SAndre Fischer ::comphelper::getProcessComponentContext()));
21522de8995SAndre Fischer if (xMultiplexer.is())
21622de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners(
21722de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this));
21822de8995SAndre Fischer
21913e1c3b4SAndre Fischer if (mxReadOnlyModeDispatch.is())
220f35c6d02SAndre Fischer mxReadOnlyModeDispatch->removeStatusListener(this, Tools::GetURL(gsReadOnlyCommandName));
22113e1c3b4SAndre Fischer if (mpSplitWindow != NULL)
22213e1c3b4SAndre Fischer {
22313e1c3b4SAndre Fischer mpSplitWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
22413e1c3b4SAndre Fischer mpSplitWindow = NULL;
22513e1c3b4SAndre Fischer }
22613e1c3b4SAndre Fischer
22722de8995SAndre Fischer if (mpParentWindow != NULL)
22822de8995SAndre Fischer {
22922de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
23022de8995SAndre Fischer mpParentWindow = NULL;
23122de8995SAndre Fischer }
232b9e67834SAndre Fischer
233f120fe41SAndre Fischer if (mpCurrentDeck)
234b9e67834SAndre Fischer {
235f120fe41SAndre Fischer mpCurrentDeck->Dispose();
236f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree();
237f120fe41SAndre Fischer mpCurrentDeck.reset();
238b9e67834SAndre Fischer }
239b9e67834SAndre Fischer
240580828edSAndre Fischer mpTabBar.reset();
241580828edSAndre Fischer
242b9e67834SAndre Fischer Theme::GetPropertySet()->removePropertyChangeListener(
243b9e67834SAndre Fischer A2S(""),
244b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this));
245b358a5b6SAndre Fischer
246b358a5b6SAndre Fischer maContextChangeUpdate.CancelRequest();
2473091fa8aSAndre Fischer maAsynchronousDeckSwitch.CancelRequest();
24822de8995SAndre Fischer }
24922de8995SAndre Fischer
25022de8995SAndre Fischer
25122de8995SAndre Fischer
25222de8995SAndre Fischer
notifyContextChangeEvent(const css::ui::ContextChangeEventObject & rEvent)25322de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
25422de8995SAndre Fischer throw(cssu::RuntimeException)
25522de8995SAndre Fischer {
256239cbbc0SAndre Fischer // Update to the requested new context asynchronously to avoid
257239cbbc0SAndre Fischer // subtle errors caused by SFX2 which in rare cases can not
258239cbbc0SAndre Fischer // properly handle a synchronous update.
259239cbbc0SAndre Fischer maRequestedContext = Context(
260239cbbc0SAndre Fischer rEvent.ApplicationName,
261239cbbc0SAndre Fischer rEvent.ContextName);
262239cbbc0SAndre Fischer if (maRequestedContext != maCurrentContext)
2633091fa8aSAndre Fischer {
2643091fa8aSAndre Fischer maAsynchronousDeckSwitch.CancelRequest();
265239cbbc0SAndre Fischer maContextChangeUpdate.RequestCall();
2663091fa8aSAndre Fischer }
26722de8995SAndre Fischer }
26822de8995SAndre Fischer
26922de8995SAndre Fischer
27022de8995SAndre Fischer
27122de8995SAndre Fischer
disposing(const css::lang::EventObject & rEventObject)27222de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject)
27322de8995SAndre Fischer throw(cssu::RuntimeException)
27422de8995SAndre Fischer {
27595a18594SAndre Fischer (void)rEventObject;
276f120fe41SAndre Fischer
277f120fe41SAndre Fischer dispose();
27822de8995SAndre Fischer }
27922de8995SAndre Fischer
28022de8995SAndre Fischer
28122de8995SAndre Fischer
28222de8995SAndre Fischer
propertyChange(const css::beans::PropertyChangeEvent & rEvent)283b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent)
284b9e67834SAndre Fischer throw(cssu::RuntimeException)
28595a18594SAndre Fischer {
28695a18594SAndre Fischer (void)rEvent;
287*6b5a962bSmseidel
28895a18594SAndre Fischer maPropertyChangeForwarder.RequestCall();
28995a18594SAndre Fischer }
29095a18594SAndre Fischer
29195a18594SAndre Fischer
29295a18594SAndre Fischer
29395a18594SAndre Fischer
statusChanged(const css::frame::FeatureStateEvent & rEvent)29413e1c3b4SAndre Fischer void SAL_CALL SidebarController::statusChanged (const css::frame::FeatureStateEvent& rEvent)
29513e1c3b4SAndre Fischer throw(cssu::RuntimeException)
29613e1c3b4SAndre Fischer {
29713e1c3b4SAndre Fischer bool bIsReadWrite (true);
29813e1c3b4SAndre Fischer if (rEvent.IsEnabled)
29913e1c3b4SAndre Fischer rEvent.State >>= bIsReadWrite;
30013e1c3b4SAndre Fischer
30113e1c3b4SAndre Fischer if (mbIsDocumentReadOnly != !bIsReadWrite)
30213e1c3b4SAndre Fischer {
30313e1c3b4SAndre Fischer mbIsDocumentReadOnly = !bIsReadWrite;
30413e1c3b4SAndre Fischer
30513e1c3b4SAndre Fischer // Force the current deck to update its panel list.
306309fba80SAndre Fischer if ( ! mbIsDocumentReadOnly)
307309fba80SAndre Fischer msCurrentDeckId = gsDefaultDeckId;
308a5297dafSAndre Fischer mnRequestedForceFlags |= SwitchFlag_ForceSwitch;
3093091fa8aSAndre Fischer maAsynchronousDeckSwitch.CancelRequest();
310309fba80SAndre Fischer maContextChangeUpdate.RequestCall();
31113e1c3b4SAndre Fischer }
31213e1c3b4SAndre Fischer }
31313e1c3b4SAndre Fischer
31413e1c3b4SAndre Fischer
31513e1c3b4SAndre Fischer
31613e1c3b4SAndre Fischer
requestLayout(void)3177a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void)
3187a32b0c8SAndre Fischer throw(cssu::RuntimeException)
3197a32b0c8SAndre Fischer {
320f120fe41SAndre Fischer if (mpCurrentDeck)
321f120fe41SAndre Fischer mpCurrentDeck->RequestLayout();
3227a32b0c8SAndre Fischer RestrictWidth();
3237a32b0c8SAndre Fischer }
3247a32b0c8SAndre Fischer
3257a32b0c8SAndre Fischer
3267a32b0c8SAndre Fischer
3277a32b0c8SAndre Fischer
BroadcastPropertyChange(void)32895a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void)
329b9e67834SAndre Fischer {
330b9e67834SAndre Fischer DataChangedEvent aEvent (DATACHANGED_USER);
331b9e67834SAndre Fischer mpParentWindow->NotifyAllChilds(aEvent);
332b9e67834SAndre Fischer mpParentWindow->Invalidate(INVALIDATE_CHILDREN);
333b9e67834SAndre Fischer }
334b9e67834SAndre Fischer
335b9e67834SAndre Fischer
336b9e67834SAndre Fischer
337b9e67834SAndre Fischer
NotifyResize(void)33822de8995SAndre Fischer void SidebarController::NotifyResize (void)
33922de8995SAndre Fischer {
340b862c97cSHerbert Dürr if( !bool(mpTabBar))
34195a18594SAndre Fischer {
342b862c97cSHerbert Dürr OSL_ASSERT( bool(mpTabBar));
34395a18594SAndre Fischer return;
34495a18594SAndre Fischer }
345*6b5a962bSmseidel
34695a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent();
347*6b5a962bSmseidel
34895a18594SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width());
34995a18594SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height());
35095a18594SAndre Fischer
35113e1c3b4SAndre Fischer mbIsDeckOpen = (nWidth > TabBar::GetDefaultWidth());
352*6b5a962bSmseidel
35313e1c3b4SAndre Fischer if (mnSavedSidebarWidth <= 0)
35413e1c3b4SAndre Fischer mnSavedSidebarWidth = nWidth;
355*6b5a962bSmseidel
35613e1c3b4SAndre Fischer bool bIsDeckVisible;
35713e1c3b4SAndre Fischer if (mbCanDeckBeOpened)
35813e1c3b4SAndre Fischer {
35913e1c3b4SAndre Fischer const bool bIsOpening (nWidth > mnWidthOnSplitterButtonDown);
36013e1c3b4SAndre Fischer if (bIsOpening)
36113e1c3b4SAndre Fischer bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthOpenThreshold;
36213e1c3b4SAndre Fischer else
36313e1c3b4SAndre Fischer bIsDeckVisible = nWidth >= TabBar::GetDefaultWidth() + gnWidthCloseThreshold;
36413e1c3b4SAndre Fischer mbIsDeckRequestedOpen = bIsDeckVisible;
36513e1c3b4SAndre Fischer UpdateCloseIndicator(!bIsDeckVisible);
36613e1c3b4SAndre Fischer }
36713e1c3b4SAndre Fischer else
36813e1c3b4SAndre Fischer bIsDeckVisible = false;
369*6b5a962bSmseidel
3707a32b0c8SAndre Fischer // Place the deck.
371f120fe41SAndre Fischer if (mpCurrentDeck)
3727a32b0c8SAndre Fischer {
37313e1c3b4SAndre Fischer if (bIsDeckVisible)
37413e1c3b4SAndre Fischer {
37513e1c3b4SAndre Fischer mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight);
37613e1c3b4SAndre Fischer mpCurrentDeck->Show();
37713e1c3b4SAndre Fischer mpCurrentDeck->RequestLayout();
37813e1c3b4SAndre Fischer }
37913e1c3b4SAndre Fischer else
38013e1c3b4SAndre Fischer mpCurrentDeck->Hide();
38122de8995SAndre Fischer }
38295a18594SAndre Fischer
3837a32b0c8SAndre Fischer // Place the tab bar.
38495a18594SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight);
38595a18594SAndre Fischer mpTabBar->Show();
3867a32b0c8SAndre Fischer
3877a32b0c8SAndre Fischer // Determine if the closer of the deck can be shown.
388f120fe41SAndre Fischer if (mpCurrentDeck)
3897a32b0c8SAndre Fischer {
390f120fe41SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
3917a32b0c8SAndre Fischer if (pTitleBar != NULL && pTitleBar->IsVisible())
3927a32b0c8SAndre Fischer pTitleBar->SetCloserVisible(CanModifyChildWindowWidth());
3937a32b0c8SAndre Fischer }
3947a32b0c8SAndre Fischer
3957a32b0c8SAndre Fischer RestrictWidth();
39613e1c3b4SAndre Fischer }
39713e1c3b4SAndre Fischer
39813e1c3b4SAndre Fischer
39913e1c3b4SAndre Fischer
40013e1c3b4SAndre Fischer
ProcessNewWidth(const sal_Int32 nNewWidth)40113e1c3b4SAndre Fischer void SidebarController::ProcessNewWidth (const sal_Int32 nNewWidth)
40213e1c3b4SAndre Fischer {
40313e1c3b4SAndre Fischer if ( ! mbIsDeckRequestedOpen)
40413e1c3b4SAndre Fischer return;
40513e1c3b4SAndre Fischer
40613e1c3b4SAndre Fischer if (mbIsDeckRequestedOpen.get())
40713e1c3b4SAndre Fischer {
408*6b5a962bSmseidel // Deck became large enough to be shown. Show it.
40913e1c3b4SAndre Fischer mnSavedSidebarWidth = nNewWidth;
41013e1c3b4SAndre Fischer RequestOpenDeck();
41113e1c3b4SAndre Fischer }
41213e1c3b4SAndre Fischer else
4137a32b0c8SAndre Fischer {
414*6b5a962bSmseidel // Deck became too small. Close it completely.
415*6b5a962bSmseidel // If window is wider than the tab bar then mark the deck as being visible, even when it's not.
41613e1c3b4SAndre Fischer // This is to trigger an adjustment of the width to the width of the tab bar.
41713e1c3b4SAndre Fischer mbIsDeckOpen = true;
41813e1c3b4SAndre Fischer RequestCloseDeck();
41913e1c3b4SAndre Fischer
42013e1c3b4SAndre Fischer if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
42113e1c3b4SAndre Fischer mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
4227a32b0c8SAndre Fischer }
42322de8995SAndre Fischer }
42422de8995SAndre Fischer
42522de8995SAndre Fischer
42622de8995SAndre Fischer
42722de8995SAndre Fischer
UpdateConfigurations(void)428239cbbc0SAndre Fischer void SidebarController::UpdateConfigurations (void)
42922de8995SAndre Fischer {
430a5297dafSAndre Fischer if (maCurrentContext != maRequestedContext
431a5297dafSAndre Fischer || mnRequestedForceFlags!=SwitchFlag_NoForce)
43295a18594SAndre Fischer {
433239cbbc0SAndre Fischer maCurrentContext = maRequestedContext;
43495a18594SAndre Fischer
43513e1c3b4SAndre Fischer // Find the set of decks that could be displayed for the new context.
43613e1c3b4SAndre Fischer ResourceManager::DeckContextDescriptorContainer aDecks;
43795a18594SAndre Fischer ResourceManager::Instance().GetMatchingDecks (
43813e1c3b4SAndre Fischer aDecks,
439239cbbc0SAndre Fischer maCurrentContext,
44013e1c3b4SAndre Fischer mbIsDocumentReadOnly,
44195a18594SAndre Fischer mxFrame);
44295a18594SAndre Fischer
44313e1c3b4SAndre Fischer // Notify the tab bar about the updated set of decks.
44413e1c3b4SAndre Fischer mpTabBar->SetDecks(aDecks);
44513e1c3b4SAndre Fischer
446*6b5a962bSmseidel // Find the new deck. By default that is the same as the old
447*6b5a962bSmseidel // one. If that is not set or not enabled, then choose the
44813e1c3b4SAndre Fischer // first enabled deck.
44913e1c3b4SAndre Fischer OUString sNewDeckId;
45013e1c3b4SAndre Fischer for (ResourceManager::DeckContextDescriptorContainer::const_iterator
45113e1c3b4SAndre Fischer iDeck(aDecks.begin()),
45213e1c3b4SAndre Fischer iEnd(aDecks.end());
45395a18594SAndre Fischer iDeck!=iEnd;
45495a18594SAndre Fischer ++iDeck)
45595a18594SAndre Fischer {
45613e1c3b4SAndre Fischer if (iDeck->mbIsEnabled)
45795a18594SAndre Fischer {
45813e1c3b4SAndre Fischer if (iDeck->msId.equals(msCurrentDeckId))
45913e1c3b4SAndre Fischer {
46013e1c3b4SAndre Fischer sNewDeckId = msCurrentDeckId;
46113e1c3b4SAndre Fischer break;
46213e1c3b4SAndre Fischer }
46313e1c3b4SAndre Fischer else if (sNewDeckId.getLength() == 0)
46413e1c3b4SAndre Fischer sNewDeckId = iDeck->msId;
46595a18594SAndre Fischer }
46695a18594SAndre Fischer }
467ff12d537SAndre Fischer
46813e1c3b4SAndre Fischer if (sNewDeckId.getLength() == 0)
46995a18594SAndre Fischer {
47013e1c3b4SAndre Fischer // We did not find a valid deck.
47113e1c3b4SAndre Fischer RequestCloseDeck();
47213e1c3b4SAndre Fischer return;
47395a18594SAndre Fischer }
47413e1c3b4SAndre Fischer
475609f33b4SAndre Fischer // Tell the tab bar to highlight the button associated
476609f33b4SAndre Fischer // with the deck.
477609f33b4SAndre Fischer mpTabBar->HighlightDeck(sNewDeckId);
478*6b5a962bSmseidel
47913e1c3b4SAndre Fischer SwitchToDeck(
48013e1c3b4SAndre Fischer *ResourceManager::Instance().GetDeckDescriptor(sNewDeckId),
48113e1c3b4SAndre Fischer maCurrentContext);
48295a18594SAndre Fischer }
483ff12d537SAndre Fischer }
484ff12d537SAndre Fischer
485ff12d537SAndre Fischer
48622de8995SAndre Fischer
487ff12d537SAndre Fischer
OpenThenSwitchToDeck(const::rtl::OUString & rsDeckId)48813e1c3b4SAndre Fischer void SidebarController::OpenThenSwitchToDeck (
48913e1c3b4SAndre Fischer const ::rtl::OUString& rsDeckId)
49013e1c3b4SAndre Fischer {
49113e1c3b4SAndre Fischer RequestOpenDeck();
49213e1c3b4SAndre Fischer SwitchToDeck(rsDeckId);
4933091fa8aSAndre Fischer mpTabBar->Invalidate();
4943091fa8aSAndre Fischer }
4953091fa8aSAndre Fischer
4963091fa8aSAndre Fischer
4973091fa8aSAndre Fischer
4983091fa8aSAndre Fischer
RequestSwitchToDeck(const::rtl::OUString & rsDeckId)4993091fa8aSAndre Fischer void SidebarController::RequestSwitchToDeck (
5003091fa8aSAndre Fischer const ::rtl::OUString& rsDeckId)
5013091fa8aSAndre Fischer {
5023091fa8aSAndre Fischer maContextChangeUpdate.CancelRequest();
5033091fa8aSAndre Fischer maAsynchronousDeckSwitch.RequestCall(
5043091fa8aSAndre Fischer ::boost::bind(&SidebarController::OpenThenSwitchToDeck, this, rsDeckId));
50513e1c3b4SAndre Fischer }
50613e1c3b4SAndre Fischer
50713e1c3b4SAndre Fischer
50813e1c3b4SAndre Fischer
50913e1c3b4SAndre Fischer
SwitchToDeck(const::rtl::OUString & rsDeckId)510ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
51195a18594SAndre Fischer const ::rtl::OUString& rsDeckId)
512ff12d537SAndre Fischer {
513a5297dafSAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId)
514a5297dafSAndre Fischer || ! mbIsDeckOpen
515a5297dafSAndre Fischer || mnRequestedForceFlags!=SwitchFlag_NoForce)
51695a18594SAndre Fischer {
51795a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId);
51895a18594SAndre Fischer if (pDeckDescriptor != NULL)
51995a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext);
52095a18594SAndre Fischer }
52122de8995SAndre Fischer }
52222de8995SAndre Fischer
52322de8995SAndre Fischer
52422de8995SAndre Fischer
52522de8995SAndre Fischer
SwitchToDeck(const DeckDescriptor & rDeckDescriptor,const Context & rContext)526ff12d537SAndre Fischer void SidebarController::SwitchToDeck (
52722de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor,
5287a32b0c8SAndre Fischer const Context& rContext)
52922de8995SAndre Fischer {
53065908a7eSAndre Fischer maFocusManager.Clear();
53165908a7eSAndre Fischer
532a5297dafSAndre Fischer const bool bForceNewDeck ((mnRequestedForceFlags&SwitchFlag_ForceNewDeck)!=0);
533a5297dafSAndre Fischer const bool bForceNewPanels ((mnRequestedForceFlags&SwitchFlag_ForceNewPanels)!=0);
534a5297dafSAndre Fischer mnRequestedForceFlags = SwitchFlag_NoForce;
535a5297dafSAndre Fischer
536a5297dafSAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)
537a5297dafSAndre Fischer || bForceNewDeck)
53895a18594SAndre Fischer {
53995a18594SAndre Fischer // When the deck changes then destroy the deck and all panels
54095a18594SAndre Fischer // and create everything new.
541f120fe41SAndre Fischer if (mpCurrentDeck)
54295a18594SAndre Fischer {
543f120fe41SAndre Fischer mpCurrentDeck->Dispose();
544f120fe41SAndre Fischer mpCurrentDeck.reset();
54595a18594SAndre Fischer }
54695a18594SAndre Fischer
54795a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId;
54895a18594SAndre Fischer }
54911fa8afeSAndre Fischer mpTabBar->HighlightDeck(msCurrentDeckId);
5507a32b0c8SAndre Fischer
551ff12d537SAndre Fischer // Determine the panels to display in the deck.
552f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors;
553ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels(
554f120fe41SAndre Fischer aPanelContextDescriptors,
555ff12d537SAndre Fischer rContext,
556ff12d537SAndre Fischer rDeckDescriptor.msId,
557ff12d537SAndre Fischer mxFrame);
558ff12d537SAndre Fischer
55954eaaa32SAndre Fischer if (aPanelContextDescriptors.empty())
56054eaaa32SAndre Fischer {
56154eaaa32SAndre Fischer // There are no panels to be displayed in the current context.
56254eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty)
56354eaaa32SAndre Fischer {
56454eaaa32SAndre Fischer // Switch to the "empty" context and try again.
56554eaaa32SAndre Fischer SwitchToDeck(
56654eaaa32SAndre Fischer rDeckDescriptor,
56754eaaa32SAndre Fischer Context(
56854eaaa32SAndre Fischer rContext.msApplication,
56954eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty)));
57054eaaa32SAndre Fischer return;
57154eaaa32SAndre Fischer }
57254eaaa32SAndre Fischer else
57354eaaa32SAndre Fischer {
57454eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have
57554eaaa32SAndre Fischer // to live with an empty deck.
57654eaaa32SAndre Fischer }
57754eaaa32SAndre Fischer }
57854eaaa32SAndre Fischer
57995a18594SAndre Fischer // Provide a configuration and Deck object.
580f120fe41SAndre Fischer if ( ! mpCurrentDeck)
58122de8995SAndre Fischer {
582f120fe41SAndre Fischer mpCurrentDeck.reset(
583f120fe41SAndre Fischer new Deck(
584f120fe41SAndre Fischer rDeckDescriptor,
585f120fe41SAndre Fischer mpParentWindow,
58613e1c3b4SAndre Fischer ::boost::bind(&SidebarController::RequestCloseDeck, this)));
58754eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle;
588*6b5a962bSmseidel
58995a18594SAndre Fischer }
590f120fe41SAndre Fischer if ( ! mpCurrentDeck)
591f120fe41SAndre Fischer return;
5923091fa8aSAndre Fischer
5933091fa8aSAndre Fischer #ifdef DEBUG
5943091fa8aSAndre Fischer // Show the context name in the deck title bar.
5953091fa8aSAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar();
5963091fa8aSAndre Fischer if (pTitleBar != NULL)
5973091fa8aSAndre Fischer pTitleBar->SetTitle(rDeckDescriptor.msTitle+A2S(" (")+maCurrentContext.msContext+A2S(")"));
5983091fa8aSAndre Fischer #endif
5993091fa8aSAndre Fischer
60095a18594SAndre Fischer // Update the panel list.
601f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size());
602f120fe41SAndre Fischer SharedPanelContainer aNewPanels;
603f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels());
60495a18594SAndre Fischer aNewPanels.resize(nNewPanelCount);
6057a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0);
60602c50d82SAndre Fischer bool bHasPanelSetChanged (false);
6077a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex)
60895a18594SAndre Fischer {
609f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor (
610f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]);
61195a18594SAndre Fischer
61213e1c3b4SAndre Fischer // Determine if the panel can be displayed.
61313e1c3b4SAndre Fischer const bool bIsPanelVisible (!mbIsDocumentReadOnly || rPanelContexDescriptor.mbShowForReadOnlyDocuments);
61413e1c3b4SAndre Fischer if ( ! bIsPanelVisible)
61513e1c3b4SAndre Fischer continue;
616a5297dafSAndre Fischer
61795a18594SAndre Fischer // Find the corresponding panel among the currently active
61895a18594SAndre Fischer // panels.
619a5297dafSAndre Fischer SharedPanelContainer::const_iterator iPanel;
620a5297dafSAndre Fischer if (bForceNewPanels)
621a5297dafSAndre Fischer {
622*6b5a962bSmseidel // All panels have to be created in any case. There is no
623a5297dafSAndre Fischer // point in searching already existing panels.
624a5297dafSAndre Fischer iPanel = rCurrentPanels.end();
625a5297dafSAndre Fischer }
626a5297dafSAndre Fischer else
627a5297dafSAndre Fischer {
628a5297dafSAndre Fischer iPanel = ::std::find_if(
629f120fe41SAndre Fischer rCurrentPanels.begin(),
630f120fe41SAndre Fischer rCurrentPanels.end(),
631a5297dafSAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)));
632a5297dafSAndre Fischer }
633f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end())
634ff12d537SAndre Fischer {
635*6b5a962bSmseidel // Panel already exists in current deck. Reuse it.
6367a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel;
6377e429a12SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible);
638ff12d537SAndre Fischer }
639ff12d537SAndre Fischer else
640ff12d537SAndre Fischer {
641a5297dafSAndre Fischer // Panel does not yet exist or creation of new panels is forced.
642a5297dafSAndre Fischer // Create it.
6437a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel(
644f120fe41SAndre Fischer rPanelContexDescriptor.msId,
6457e429a12SAndre Fischer mpCurrentDeck->GetPanelParentWindow(),
646ae13266dSAndre Fischer rPanelContexDescriptor.mbIsInitiallyVisible,
647ae13266dSAndre Fischer rContext);
64802c50d82SAndre Fischer bHasPanelSetChanged = true;
649ff12d537SAndre Fischer }
650b862c97cSHerbert Dürr if( bool(aNewPanels[nWriteIndex]))
65102c50d82SAndre Fischer {
6528a1a651aSAndre Fischer // Depending on the context we have to change the command
6538a1a651aSAndre Fischer // for the "more options" dialog.
6548a1a651aSAndre Fischer PanelTitleBar* pTitleBar = aNewPanels[nWriteIndex]->GetTitleBar();
6558a1a651aSAndre Fischer if (pTitleBar != NULL)
6568a1a651aSAndre Fischer {
6578a1a651aSAndre Fischer pTitleBar->SetMoreOptionsCommand(
6588a1a651aSAndre Fischer rPanelContexDescriptor.msMenuCommand,
6598a1a651aSAndre Fischer mxFrame);
6608a1a651aSAndre Fischer }
661f120fe41SAndre Fischer
662f120fe41SAndre Fischer ++nWriteIndex;
66302c50d82SAndre Fischer }
664f120fe41SAndre Fischer
66595a18594SAndre Fischer }
666f120fe41SAndre Fischer aNewPanels.resize(nWriteIndex);
66795a18594SAndre Fischer
66895a18594SAndre Fischer // Activate the deck and the new set of panels.
669f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel(
67095a18594SAndre Fischer 0,
67195a18594SAndre Fischer 0,
67295a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(),
67395a18594SAndre Fischer mpParentWindow->GetSizePixel().Height());
674f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels);
675f120fe41SAndre Fischer mpCurrentDeck->Show();
676ff12d537SAndre Fischer
6777a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle);
6787a32b0c8SAndre Fischer
67902c50d82SAndre Fischer if (bHasPanelSetChanged)
68002c50d82SAndre Fischer NotifyResize();
68165908a7eSAndre Fischer
68265908a7eSAndre Fischer // Tell the focus manager about the new panels and tab bar
68365908a7eSAndre Fischer // buttons.
68452d13b84SAndre Fischer maFocusManager.SetDeckTitle(mpCurrentDeck->GetTitleBar());
68565908a7eSAndre Fischer maFocusManager.SetPanels(aNewPanels);
68665908a7eSAndre Fischer mpTabBar->UpdateFocusManager(maFocusManager);
6874e21436dSAndre Fischer UpdateTitleBarIcons();
68802c50d82SAndre Fischer }
68902c50d82SAndre Fischer
69002c50d82SAndre Fischer
69102c50d82SAndre Fischer
69202c50d82SAndre Fischer
CreatePanel(const OUString & rsPanelId,::Window * pParentWindow,const bool bIsInitiallyExpanded,const Context & rContext)693f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel (
69495a18594SAndre Fischer const OUString& rsPanelId,
6957e429a12SAndre Fischer ::Window* pParentWindow,
696ae13266dSAndre Fischer const bool bIsInitiallyExpanded,
697ae13266dSAndre Fischer const Context& rContext)
69895a18594SAndre Fischer {
69995a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId);
70095a18594SAndre Fischer if (pPanelDescriptor == NULL)
701f120fe41SAndre Fischer return SharedPanel();
7027a32b0c8SAndre Fischer
70395a18594SAndre Fischer // Create the panel which is the parent window of the UIElement.
704f120fe41SAndre Fischer SharedPanel pPanel (new Panel(
70595a18594SAndre Fischer *pPanelDescriptor,
7067a32b0c8SAndre Fischer pParentWindow,
7077e429a12SAndre Fischer bIsInitiallyExpanded,
7087e429a12SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()),
7097e429a12SAndre Fischer ::boost::bind(&SidebarController::GetCurrentContext, this)));
71095a18594SAndre Fischer
71195a18594SAndre Fischer // Create the XUIElement.
71295a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement(
71395a18594SAndre Fischer pPanel->GetComponentInterface(),
71422f77e9eSAndre Fischer pPanelDescriptor->msImplementationURL,
715ae13266dSAndre Fischer pPanelDescriptor->mbWantsCanvas,
716ae13266dSAndre Fischer rContext));
71795a18594SAndre Fischer if (xUIElement.is())
71895a18594SAndre Fischer {
71995a18594SAndre Fischer // Initialize the panel and add it to the active deck.
72095a18594SAndre Fischer pPanel->SetUIElement(xUIElement);
72195a18594SAndre Fischer }
72295a18594SAndre Fischer else
72395a18594SAndre Fischer {
724f120fe41SAndre Fischer pPanel.reset();
72595a18594SAndre Fischer }
72695a18594SAndre Fischer
72795a18594SAndre Fischer return pPanel;
72895a18594SAndre Fischer }
72995a18594SAndre Fischer
73095a18594SAndre Fischer
73195a18594SAndre Fischer
73295a18594SAndre Fischer
CreateUIElement(const Reference<awt::XWindowPeer> & rxWindow,const::rtl::OUString & rsImplementationURL,const bool bWantsCanvas,const Context & rContext)733ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement (
734ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow,
73522f77e9eSAndre Fischer const ::rtl::OUString& rsImplementationURL,
736ae13266dSAndre Fischer const bool bWantsCanvas,
737ae13266dSAndre Fischer const Context& rContext)
73822de8995SAndre Fischer {
73922de8995SAndre Fischer try
74022de8995SAndre Fischer {
74122de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
74222de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory (
74322de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"),
74422de8995SAndre Fischer UNO_QUERY_THROW);
745ff12d537SAndre Fischer
7467a32b0c8SAndre Fischer // Create the XUIElement.
74722de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments;
74822de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame));
749ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow));
750b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow);
751b9e67834SAndre Fischer if (pSfxDockingWindow != NULL)
752b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings())));
7537a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet());
7547a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this))));
75522f77e9eSAndre Fischer if (bWantsCanvas)
75622f77e9eSAndre Fischer {
75722f77e9eSAndre Fischer Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas());
75822f77e9eSAndre Fischer aCreationArguments.put("Canvas", makeAny(xCanvas));
759*6b5a962bSmseidel }
760ae13266dSAndre Fischer aCreationArguments.put("ApplicationName", makeAny(rContext.msApplication));
761ae13266dSAndre Fischer aCreationArguments.put("ContextName", makeAny(rContext.msContext));
762*6b5a962bSmseidel
763b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement(
764ff12d537SAndre Fischer xUIElementFactory->createUIElement(
765ff12d537SAndre Fischer rsImplementationURL,
7667a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())),
767ff12d537SAndre Fischer UNO_QUERY_THROW);
768b9e67834SAndre Fischer
769b9e67834SAndre Fischer return xUIElement;
77022de8995SAndre Fischer }
77122de8995SAndre Fischer catch(Exception& rException)
77222de8995SAndre Fischer {
77322de8995SAndre Fischer OSL_TRACE("caught exception: %s",
77422de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
77522de8995SAndre Fischer // For some reason we can not create the actual panel.
77622de8995SAndre Fischer // Probably because its factory was not properly registered.
77722de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the
77822de8995SAndre Fischer // source of the error.
779ff12d537SAndre Fischer
780ff12d537SAndre Fischer return NULL;
78122de8995SAndre Fischer }
78222de8995SAndre Fischer }
78322de8995SAndre Fischer
78422de8995SAndre Fischer
78522de8995SAndre Fischer
78622de8995SAndre Fischer
IMPL_LINK(SidebarController,WindowEventHandler,VclWindowEvent *,pEvent)78722de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent)
78822de8995SAndre Fischer {
78913e1c3b4SAndre Fischer if (pEvent==NULL)
79013e1c3b4SAndre Fischer return sal_False;
79113e1c3b4SAndre Fischer
79213e1c3b4SAndre Fischer if (pEvent->GetWindow() == mpParentWindow)
79322de8995SAndre Fischer {
79422de8995SAndre Fischer switch (pEvent->GetId())
79522de8995SAndre Fischer {
79622de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW:
79722de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE:
79822de8995SAndre Fischer NotifyResize();
79922de8995SAndre Fischer break;
80022de8995SAndre Fischer
801ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED:
802ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect
803ff12d537SAndre Fischer // changes in theme (high contrast mode).
804ff12d537SAndre Fischer Theme::HandleDataChange();
8054e21436dSAndre Fischer UpdateTitleBarIcons();
806ff12d537SAndre Fischer mpParentWindow->Invalidate();
807a5297dafSAndre Fischer mnRequestedForceFlags |= SwitchFlag_ForceNewDeck | SwitchFlag_ForceNewPanels;
8083091fa8aSAndre Fischer maAsynchronousDeckSwitch.CancelRequest();
809a5297dafSAndre Fischer maContextChangeUpdate.RequestCall();
810ff12d537SAndre Fischer break;
811*6b5a962bSmseidel
81222de8995SAndre Fischer case SFX_HINT_DYING:
81322de8995SAndre Fischer dispose();
81422de8995SAndre Fischer break;
815*6b5a962bSmseidel
81613e1c3b4SAndre Fischer case VCLEVENT_WINDOW_PAINT:
81713e1c3b4SAndre Fischer OSL_TRACE("Paint");
81813e1c3b4SAndre Fischer break;
81913e1c3b4SAndre Fischer
82022de8995SAndre Fischer default:
82122de8995SAndre Fischer break;
82222de8995SAndre Fischer }
82322de8995SAndre Fischer }
82413e1c3b4SAndre Fischer else if (pEvent->GetWindow()==mpSplitWindow && mpSplitWindow!=NULL)
82513e1c3b4SAndre Fischer {
82613e1c3b4SAndre Fischer switch (pEvent->GetId())
82713e1c3b4SAndre Fischer {
82813e1c3b4SAndre Fischer case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
82913e1c3b4SAndre Fischer mnWidthOnSplitterButtonDown = mpParentWindow->GetSizePixel().Width();
83013e1c3b4SAndre Fischer break;
83113e1c3b4SAndre Fischer
83213e1c3b4SAndre Fischer case VCLEVENT_WINDOW_MOUSEBUTTONUP:
83313e1c3b4SAndre Fischer {
83413e1c3b4SAndre Fischer ProcessNewWidth(mpParentWindow->GetSizePixel().Width());
83513e1c3b4SAndre Fischer mnWidthOnSplitterButtonDown = 0;
83613e1c3b4SAndre Fischer break;
83713e1c3b4SAndre Fischer }
83813e1c3b4SAndre Fischer
83913e1c3b4SAndre Fischer case SFX_HINT_DYING:
84013e1c3b4SAndre Fischer dispose();
84113e1c3b4SAndre Fischer break;
84213e1c3b4SAndre Fischer }
84313e1c3b4SAndre Fischer }
84422de8995SAndre Fischer
84522de8995SAndre Fischer return sal_True;
84622de8995SAndre Fischer }
84722de8995SAndre Fischer
84822de8995SAndre Fischer
84922de8995SAndre Fischer
85022de8995SAndre Fischer
ShowPopupMenu(const Rectangle & rButtonBox,const::std::vector<TabBar::DeckMenuData> & rMenuData) const85195a18594SAndre Fischer void SidebarController::ShowPopupMenu (
85295a18594SAndre Fischer const Rectangle& rButtonBox,
853be6d8c25SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rMenuData) const
85422de8995SAndre Fischer {
855be6d8c25SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rMenuData);
856ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected));
857*6b5a962bSmseidel
858ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up
859ff12d537SAndre Fischer Rectangle aBox (rButtonBox);
860ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0);
861ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN);
86222de8995SAndre Fischer }
86322de8995SAndre Fischer
86422de8995SAndre Fischer
86522de8995SAndre Fischer
86622de8995SAndre Fischer
ShowDetailMenu(const::rtl::OUString & rsMenuCommand) const867f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const
868f120fe41SAndre Fischer {
869f120fe41SAndre Fischer try
870f120fe41SAndre Fischer {
871f35c6d02SAndre Fischer const util::URL aURL (Tools::GetURL(rsMenuCommand));
872f35c6d02SAndre Fischer Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
873f120fe41SAndre Fischer if (xDispatch.is())
874f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
875f120fe41SAndre Fischer }
876f120fe41SAndre Fischer catch(Exception& rException)
877f120fe41SAndre Fischer {
878f120fe41SAndre Fischer OSL_TRACE("caught exception: %s",
879f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
880f120fe41SAndre Fischer }
881f120fe41SAndre Fischer }
882f120fe41SAndre Fischer
883f120fe41SAndre Fischer
884f120fe41SAndre Fischer
885f120fe41SAndre Fischer
CreatePopupMenu(const::std::vector<TabBar::DeckMenuData> & rMenuData) const88695a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu (
887be6d8c25SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rMenuData) const
88822de8995SAndre Fischer {
889be6d8c25SAndre Fischer // Create the top level popup menu.
890ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu());
891ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
892ff12d537SAndre Fischer if (pMenuWindow != NULL)
893ff12d537SAndre Fischer {
894ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
895ff12d537SAndre Fischer }
896ff12d537SAndre Fischer
897be6d8c25SAndre Fischer // Create sub menu for customization (hiding of deck tabs.)
898be6d8c25SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu();
899be6d8c25SAndre Fischer
900ff12d537SAndre Fischer SidebarResource aLocalResource;
901*6b5a962bSmseidel
902ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make
903ff12d537SAndre Fischer // them visible or hide them.
904be6d8c25SAndre Fischer sal_Int32 nIndex (0);
905be6d8c25SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator
906be6d8c25SAndre Fischer iItem(rMenuData.begin()),
907be6d8c25SAndre Fischer iEnd(rMenuData.end());
908be6d8c25SAndre Fischer iItem!=iEnd;
909be6d8c25SAndre Fischer ++iItem,++nIndex)
910be6d8c25SAndre Fischer {
911be6d8c25SAndre Fischer const sal_Int32 nMenuIndex (nIndex+MID_FIRST_PANEL);
912be6d8c25SAndre Fischer pMenu->InsertItem(nMenuIndex, iItem->msDisplayName, MIB_RADIOCHECK);
913be6d8c25SAndre Fischer pMenu->CheckItem(nMenuIndex, iItem->mbIsCurrentDeck ? sal_True : sal_False);
914be6d8c25SAndre Fischer pMenu->EnableItem(nMenuIndex, (iItem->mbIsEnabled&&iItem->mbIsActive) ? sal_True : sal_False);
915be6d8c25SAndre Fischer
916be6d8c25SAndre Fischer const sal_Int32 nSubMenuIndex (nIndex+MID_FIRST_HIDE);
917be6d8c25SAndre Fischer if (iItem->mbIsCurrentDeck)
918be6d8c25SAndre Fischer {
919be6d8c25SAndre Fischer // Don't allow the currently visible deck to be disabled.
920be6d8c25SAndre Fischer pCustomizationMenu->InsertItem(nSubMenuIndex, iItem->msDisplayName, MIB_RADIOCHECK);
921be6d8c25SAndre Fischer pCustomizationMenu->CheckItem(nSubMenuIndex, sal_True);
922be6d8c25SAndre Fischer }
923be6d8c25SAndre Fischer else
92495a18594SAndre Fischer {
925be6d8c25SAndre Fischer pCustomizationMenu->InsertItem(nSubMenuIndex, iItem->msDisplayName, MIB_CHECKABLE);
926be6d8c25SAndre Fischer pCustomizationMenu->CheckItem(nSubMenuIndex, iItem->mbIsActive ? sal_True : sal_False);
92795a18594SAndre Fischer }
92822de8995SAndre Fischer }
92922de8995SAndre Fischer
93095a18594SAndre Fischer pMenu->InsertSeparator();
93195a18594SAndre Fischer
932ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel.
933ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode())
934ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK)));
935ff12d537SAndre Fischer else
936ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK)));
937ff12d537SAndre Fischer
938ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator();
939ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE)));
940*6b5a962bSmseidel
941ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION)));
942ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu);
943ff12d537SAndre Fischer
944ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False);
945*6b5a962bSmseidel
946ff12d537SAndre Fischer return pMenu;
94722de8995SAndre Fischer }
94822de8995SAndre Fischer
94922de8995SAndre Fischer
95022de8995SAndre Fischer
95122de8995SAndre Fischer
IMPL_LINK(SidebarController,OnMenuItemSelected,Menu *,pMenu)952ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu)
95322de8995SAndre Fischer {
954ff12d537SAndre Fischer if (pMenu == NULL)
955ff12d537SAndre Fischer {
9567a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!");
957ff12d537SAndre Fischer return 0;
958ff12d537SAndre Fischer }
95922de8995SAndre Fischer
960ff12d537SAndre Fischer pMenu->Deactivate();
961ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId());
962ff12d537SAndre Fischer switch (nIndex)
96322de8995SAndre Fischer {
964ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL:
965ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True);
966ff12d537SAndre Fischer break;
967ff12d537SAndre Fischer
968ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL:
969ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False);
970ff12d537SAndre Fischer break;
971ff12d537SAndre Fischer
972ff12d537SAndre Fischer case MID_RESTORE_DEFAULT:
973ff12d537SAndre Fischer mpTabBar->RestoreHideFlags();
974ff12d537SAndre Fischer break;
975*6b5a962bSmseidel
976ff12d537SAndre Fischer default:
977ff12d537SAndre Fischer {
978ff12d537SAndre Fischer try
979ff12d537SAndre Fischer {
980ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE)
98195a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL));
982ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE)
983be6d8c25SAndre Fischer if (pMenu->GetItemBits(nIndex) == MIB_CHECKABLE)
984be6d8c25SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE);
985ff12d537SAndre Fischer }
986ff12d537SAndre Fischer catch (RuntimeException&)
987ff12d537SAndre Fischer {
988ff12d537SAndre Fischer }
989ff12d537SAndre Fischer }
990ff12d537SAndre Fischer break;
99122de8995SAndre Fischer }
992ff12d537SAndre Fischer
993ff12d537SAndre Fischer return 1;
99422de8995SAndre Fischer }
99522de8995SAndre Fischer
99622de8995SAndre Fischer
997ff12d537SAndre Fischer
998ff12d537SAndre Fischer
RequestCloseDeck(void)99913e1c3b4SAndre Fischer void SidebarController::RequestCloseDeck (void)
10007a32b0c8SAndre Fischer {
100113e1c3b4SAndre Fischer mbIsDeckRequestedOpen = false;
100213e1c3b4SAndre Fischer UpdateDeckOpenState();
10037a32b0c8SAndre Fischer }
10047a32b0c8SAndre Fischer
10057a32b0c8SAndre Fischer
10067a32b0c8SAndre Fischer
10077a32b0c8SAndre Fischer
RequestOpenDeck(void)100813e1c3b4SAndre Fischer void SidebarController::RequestOpenDeck (void)
10097a32b0c8SAndre Fischer {
101013e1c3b4SAndre Fischer mbIsDeckRequestedOpen = true;
101113e1c3b4SAndre Fischer UpdateDeckOpenState();
101213e1c3b4SAndre Fischer }
101313e1c3b4SAndre Fischer
10147a32b0c8SAndre Fischer
10157a32b0c8SAndre Fischer
101613e1c3b4SAndre Fischer
UpdateDeckOpenState(void)101713e1c3b4SAndre Fischer void SidebarController::UpdateDeckOpenState (void)
101813e1c3b4SAndre Fischer {
101913e1c3b4SAndre Fischer if ( ! mbIsDeckRequestedOpen)
102013e1c3b4SAndre Fischer // No state requested.
102113e1c3b4SAndre Fischer return;
102213e1c3b4SAndre Fischer
102313e1c3b4SAndre Fischer // Update (change) the open state when it either has not yet been initialized
102413e1c3b4SAndre Fischer // or when its value differs from the requested state.
102513e1c3b4SAndre Fischer if ( ! mbIsDeckOpen
102613e1c3b4SAndre Fischer || mbIsDeckOpen.get() != mbIsDeckRequestedOpen.get())
102713e1c3b4SAndre Fischer {
102813e1c3b4SAndre Fischer if (mbIsDeckRequestedOpen.get())
102913e1c3b4SAndre Fischer {
103013e1c3b4SAndre Fischer if (mnSavedSidebarWidth <= TabBar::GetDefaultWidth())
103113e1c3b4SAndre Fischer SetChildWindowWidth(SidebarChildWindow::GetDefaultWidth(mpParentWindow));
103213e1c3b4SAndre Fischer else
103313e1c3b4SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth);
103413e1c3b4SAndre Fischer }
103513e1c3b4SAndre Fischer else
103613e1c3b4SAndre Fischer {
103713e1c3b4SAndre Fischer if ( ! mpParentWindow->IsFloatingMode())
103813e1c3b4SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth());
103913e1c3b4SAndre Fischer if (mnWidthOnSplitterButtonDown > TabBar::GetDefaultWidth())
104013e1c3b4SAndre Fischer mnSavedSidebarWidth = mnWidthOnSplitterButtonDown;
104113e1c3b4SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE);
104213e1c3b4SAndre Fischer }
104313e1c3b4SAndre Fischer
104413e1c3b4SAndre Fischer mbIsDeckOpen = mbIsDeckRequestedOpen.get();
104513e1c3b4SAndre Fischer if (mbIsDeckOpen.get() && mpCurrentDeck)
104613e1c3b4SAndre Fischer mpCurrentDeck->Show(mbIsDeckOpen.get());
10477a32b0c8SAndre Fischer NotifyResize();
10487a32b0c8SAndre Fischer }
10497a32b0c8SAndre Fischer }
10507a32b0c8SAndre Fischer
10517a32b0c8SAndre Fischer
10527a32b0c8SAndre Fischer
10537a32b0c8SAndre Fischer
GetFocusManager(void)105465908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void)
105565908a7eSAndre Fischer {
105665908a7eSAndre Fischer return maFocusManager;
105765908a7eSAndre Fischer }
105865908a7eSAndre Fischer
105965908a7eSAndre Fischer
106065908a7eSAndre Fischer
106165908a7eSAndre Fischer
CanModifyChildWindowWidth(void)106213e1c3b4SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void)
10637a32b0c8SAndre Fischer {
106413e1c3b4SAndre Fischer SfxSplitWindow* pSplitWindow = GetSplitWindow();
10657a32b0c8SAndre Fischer if (pSplitWindow == NULL)
106613e1c3b4SAndre Fischer return false;
10677a32b0c8SAndre Fischer
10687a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff);
10697a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff);
10706fa16b61SAndre Fischer if (pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow))
10716fa16b61SAndre Fischer {
10726fa16b61SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn));
10736fa16b61SAndre Fischer return nRowCount==1;
10746fa16b61SAndre Fischer }
10756fa16b61SAndre Fischer else
10766fa16b61SAndre Fischer return false;
10777a32b0c8SAndre Fischer }
10787a32b0c8SAndre Fischer
10797a32b0c8SAndre Fischer
10807a32b0c8SAndre Fischer
10817a32b0c8SAndre Fischer
SetChildWindowWidth(const sal_Int32 nNewWidth)10827a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth)
10837a32b0c8SAndre Fischer {
108413e1c3b4SAndre Fischer SfxSplitWindow* pSplitWindow = GetSplitWindow();
10857a32b0c8SAndre Fischer if (pSplitWindow == NULL)
10867a32b0c8SAndre Fischer return 0;
10877a32b0c8SAndre Fischer
10887a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff);
10897a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff);
10907a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow);
10917a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn));
10927a32b0c8SAndre Fischer
10937a32b0c8SAndre Fischer Window* pWindow = mpParentWindow;
10947a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel());
10957a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel());
10967a32b0c8SAndre Fischer
10977a32b0c8SAndre Fischer pSplitWindow->MoveWindow(
10987a32b0c8SAndre Fischer mpParentWindow,
10997a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()),
11007a32b0c8SAndre Fischer nColumn,
11017a32b0c8SAndre Fischer nRow);
110213e1c3b4SAndre Fischer static_cast<SplitWindow*>(pSplitWindow)->Split();
110313e1c3b4SAndre Fischer
11047a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth);
11057a32b0c8SAndre Fischer }
11067a32b0c8SAndre Fischer
11077a32b0c8SAndre Fischer
11087a32b0c8SAndre Fischer
11097a32b0c8SAndre Fischer
RestrictWidth(void)11107a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void)
11117a32b0c8SAndre Fischer {
111213e1c3b4SAndre Fischer SfxSplitWindow* pSplitWindow = GetSplitWindow();
11137a32b0c8SAndre Fischer if (pSplitWindow != NULL)
11147a32b0c8SAndre Fischer {
11157a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow));
11167a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId));
11177a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange(
11187a32b0c8SAndre Fischer nSetId,
111913e1c3b4SAndre Fischer Range(TabBar::GetDefaultWidth(), gnMaximumSidebarWidth));
112013e1c3b4SAndre Fischer }
112113e1c3b4SAndre Fischer }
112213e1c3b4SAndre Fischer
112313e1c3b4SAndre Fischer
112413e1c3b4SAndre Fischer
112513e1c3b4SAndre Fischer
GetSplitWindow(void)112613e1c3b4SAndre Fischer SfxSplitWindow* SidebarController::GetSplitWindow (void)
112713e1c3b4SAndre Fischer {
11286fa16b61SAndre Fischer if (mpParentWindow != NULL)
112913e1c3b4SAndre Fischer {
11306fa16b61SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent());
11316fa16b61SAndre Fischer if (pSplitWindow != mpSplitWindow)
113213e1c3b4SAndre Fischer {
11336fa16b61SAndre Fischer if (mpSplitWindow != NULL)
11346fa16b61SAndre Fischer mpSplitWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler));
11356fa16b61SAndre Fischer
11366fa16b61SAndre Fischer mpSplitWindow = pSplitWindow;
1137*6b5a962bSmseidel
113813e1c3b4SAndre Fischer if (mpSplitWindow != NULL)
113913e1c3b4SAndre Fischer mpSplitWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler));
114013e1c3b4SAndre Fischer }
11416fa16b61SAndre Fischer return mpSplitWindow;
114213e1c3b4SAndre Fischer }
11436fa16b61SAndre Fischer else
11446fa16b61SAndre Fischer return NULL;
114513e1c3b4SAndre Fischer }
114613e1c3b4SAndre Fischer
114713e1c3b4SAndre Fischer
114813e1c3b4SAndre Fischer
114913e1c3b4SAndre Fischer
UpdateCloseIndicator(const bool bCloseAfterDrag)115013e1c3b4SAndre Fischer void SidebarController::UpdateCloseIndicator (const bool bCloseAfterDrag)
115113e1c3b4SAndre Fischer {
115213e1c3b4SAndre Fischer if (mpParentWindow == NULL)
115313e1c3b4SAndre Fischer return;
115413e1c3b4SAndre Fischer
115513e1c3b4SAndre Fischer if (bCloseAfterDrag)
115613e1c3b4SAndre Fischer {
115713e1c3b4SAndre Fischer // Make sure that the indicator exists.
115813e1c3b4SAndre Fischer if ( ! mpCloseIndicator)
115913e1c3b4SAndre Fischer {
116013e1c3b4SAndre Fischer mpCloseIndicator.reset(new FixedImage(mpParentWindow));
116113e1c3b4SAndre Fischer FixedImage* pFixedImage = static_cast<FixedImage*>(mpCloseIndicator.get());
116213e1c3b4SAndre Fischer const Image aImage (Theme::GetImage(Theme::Image_CloseIndicator));
116313e1c3b4SAndre Fischer pFixedImage->SetImage(aImage);
116413e1c3b4SAndre Fischer pFixedImage->SetSizePixel(aImage.GetSizePixel());
116513e1c3b4SAndre Fischer pFixedImage->SetBackground(Theme::GetWallpaper(Theme::Paint_DeckBackground));
116613e1c3b4SAndre Fischer }
1167*6b5a962bSmseidel
116813e1c3b4SAndre Fischer // Place and show the indicator.
116913e1c3b4SAndre Fischer const Size aWindowSize (mpParentWindow->GetSizePixel());
117013e1c3b4SAndre Fischer const Size aImageSize (mpCloseIndicator->GetSizePixel());
117113e1c3b4SAndre Fischer mpCloseIndicator->SetPosPixel(
117213e1c3b4SAndre Fischer Point(
117313e1c3b4SAndre Fischer aWindowSize.Width() - TabBar::GetDefaultWidth() - aImageSize.Width(),
117413e1c3b4SAndre Fischer (aWindowSize.Height() - aImageSize.Height())/2));
117513e1c3b4SAndre Fischer mpCloseIndicator->Show();
117613e1c3b4SAndre Fischer }
117713e1c3b4SAndre Fischer else
117813e1c3b4SAndre Fischer {
117913e1c3b4SAndre Fischer // Hide but don't delete the indicator.
118013e1c3b4SAndre Fischer if (mpCloseIndicator)
118113e1c3b4SAndre Fischer mpCloseIndicator->Hide();
11827a32b0c8SAndre Fischer }
11837a32b0c8SAndre Fischer }
11847a32b0c8SAndre Fischer
1185ff12d537SAndre Fischer
11864e21436dSAndre Fischer
11874e21436dSAndre Fischer
UpdateTitleBarIcons(void)11884e21436dSAndre Fischer void SidebarController::UpdateTitleBarIcons (void)
11894e21436dSAndre Fischer {
11904e21436dSAndre Fischer if ( ! mpCurrentDeck)
11914e21436dSAndre Fischer return;
1192*6b5a962bSmseidel
11934e21436dSAndre Fischer const bool bIsHighContrastModeActive (Theme::IsHighContrastMode());
11944e21436dSAndre Fischer const ResourceManager& rResourceManager (ResourceManager::Instance());
1195*6b5a962bSmseidel
11964e21436dSAndre Fischer // Update the deck icon.
11974e21436dSAndre Fischer const DeckDescriptor* pDeckDescriptor = rResourceManager.GetDeckDescriptor(mpCurrentDeck->GetId());
11984e21436dSAndre Fischer if (pDeckDescriptor != NULL && mpCurrentDeck->GetTitleBar())
11994e21436dSAndre Fischer {
12004e21436dSAndre Fischer const OUString sIconURL(
12014e21436dSAndre Fischer bIsHighContrastModeActive
12024e21436dSAndre Fischer ? pDeckDescriptor->msHighContrastTitleBarIconURL
12034e21436dSAndre Fischer : pDeckDescriptor->msTitleBarIconURL);
12044e21436dSAndre Fischer mpCurrentDeck->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
12054e21436dSAndre Fischer }
12064e21436dSAndre Fischer
12074e21436dSAndre Fischer // Update the panel icons.
12084e21436dSAndre Fischer const SharedPanelContainer& rPanels (mpCurrentDeck->GetPanels());
12094e21436dSAndre Fischer for (SharedPanelContainer::const_iterator
12104e21436dSAndre Fischer iPanel(rPanels.begin()), iEnd(rPanels.end());
12114e21436dSAndre Fischer iPanel!=iEnd;
12124e21436dSAndre Fischer ++iPanel)
12134e21436dSAndre Fischer {
12144e21436dSAndre Fischer if ( ! *iPanel)
12154e21436dSAndre Fischer continue;
12164e21436dSAndre Fischer if ((*iPanel)->GetTitleBar() == NULL)
12174e21436dSAndre Fischer continue;
12184e21436dSAndre Fischer const PanelDescriptor* pPanelDescriptor = rResourceManager.GetPanelDescriptor((*iPanel)->GetId());
12194e21436dSAndre Fischer if (pPanelDescriptor == NULL)
12204e21436dSAndre Fischer continue;
12214e21436dSAndre Fischer const OUString sIconURL (
12224e21436dSAndre Fischer bIsHighContrastModeActive
12234e21436dSAndre Fischer ? pPanelDescriptor->msHighContrastTitleBarIconURL
12244e21436dSAndre Fischer : pPanelDescriptor->msTitleBarIconURL);
12254e21436dSAndre Fischer (*iPanel)->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame));
12264e21436dSAndre Fischer }
12274e21436dSAndre Fischer }
12284e21436dSAndre Fischer
12294e21436dSAndre Fischer
123052d13b84SAndre Fischer
123152d13b84SAndre Fischer
ShowPanel(const Panel & rPanel)123252d13b84SAndre Fischer void SidebarController::ShowPanel (const Panel& rPanel)
123352d13b84SAndre Fischer {
123452d13b84SAndre Fischer if (mpCurrentDeck)
123552d13b84SAndre Fischer mpCurrentDeck->ShowPanel(rPanel);
123652d13b84SAndre Fischer }
123752d13b84SAndre Fischer
123852d13b84SAndre Fischer
12397e429a12SAndre Fischer
12407e429a12SAndre Fischer
GetCurrentContext(void) const12417e429a12SAndre Fischer Context SidebarController::GetCurrentContext (void) const
12427e429a12SAndre Fischer {
12437e429a12SAndre Fischer return maCurrentContext;
12447e429a12SAndre Fischer }
12457e429a12SAndre Fischer
12467e429a12SAndre Fischer
1247ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
1248