1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10*5b190011SAndrew Rist *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19*5b190011SAndrew Rist *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "ViewTabBar.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #define USE_TAB_CONTROL
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "ViewShell.hxx"
32cdf0e10cSrcweir #include "ViewShellBase.hxx"
33cdf0e10cSrcweir #include "DrawViewShell.hxx"
34cdf0e10cSrcweir #include "FrameView.hxx"
35cdf0e10cSrcweir #include "EventMultiplexer.hxx"
36cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
37cdf0e10cSrcweir #include "framework/Pane.hxx"
38cdf0e10cSrcweir #include "DrawController.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include "sdresid.hxx"
41cdf0e10cSrcweir #include "strings.hrc"
42cdf0e10cSrcweir #include "helpids.h"
43cdf0e10cSrcweir #include "Client.hxx"
44cdf0e10cSrcweir #include <vcl/svapp.hxx>
45cdf0e10cSrcweir #include <vcl/tabpage.hxx>
46cdf0e10cSrcweir #include <vos/mutex.hxx>
47cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
48cdf0e10cSrcweir #include <com/sun/star/drawing/framework/ResourceId.hpp>
49cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
50cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
51cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
52cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
53cdf0e10cSrcweir #include <tools/diagnose_ex.h>
54cdf0e10cSrcweir
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
58cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
59cdf0e10cSrcweir using ::sd::tools::EventMultiplexerEvent;
60cdf0e10cSrcweir using ::rtl::OUString;
61cdf0e10cSrcweir
62cdf0e10cSrcweir namespace sd {
63cdf0e10cSrcweir
64cdf0e10cSrcweir namespace {
IsEqual(const TabBarButton & rButton1,const TabBarButton & rButton2)65cdf0e10cSrcweir bool IsEqual (const TabBarButton& rButton1, const TabBarButton& rButton2)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return (
68cdf0e10cSrcweir (rButton1.ResourceId.is()
69cdf0e10cSrcweir && rButton2.ResourceId.is()
70cdf0e10cSrcweir && rButton1.ResourceId->compareTo(rButton2.ResourceId)==0)
71cdf0e10cSrcweir || rButton1.ButtonLabel == rButton2.ButtonLabel);
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir class TabBarControl : public ::TabControl
75cdf0e10cSrcweir {
76cdf0e10cSrcweir public:
77cdf0e10cSrcweir TabBarControl (
78cdf0e10cSrcweir ::Window* pParentWindow,
79cdf0e10cSrcweir const ::rtl::Reference<ViewTabBar>& rpViewTabBar);
80cdf0e10cSrcweir virtual void Paint (const Rectangle& rRect);
81cdf0e10cSrcweir virtual void ActivatePage (void);
82cdf0e10cSrcweir private:
83cdf0e10cSrcweir ::rtl::Reference<ViewTabBar> mpViewTabBar;
84cdf0e10cSrcweir };
85cdf0e10cSrcweir
86cdf0e10cSrcweir } // end of anonymous namespace
87cdf0e10cSrcweir
88cdf0e10cSrcweir
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir
92cdf0e10cSrcweir class ViewTabPage : public TabPage
93cdf0e10cSrcweir {
94cdf0e10cSrcweir public:
ViewTabPage(Window * pParent)95cdf0e10cSrcweir ViewTabPage (Window* pParent) : TabPage(pParent) {}
Resize(void)96cdf0e10cSrcweir virtual void Resize (void)
97cdf0e10cSrcweir { SetPosSizePixel(Point(0,0),GetParent()->GetOutputSizePixel()); }
98cdf0e10cSrcweir };
99cdf0e10cSrcweir
100cdf0e10cSrcweir
101cdf0e10cSrcweir
102cdf0e10cSrcweir
103cdf0e10cSrcweir //===== ViewTabBar ============================================================
104cdf0e10cSrcweir
ViewTabBar(const Reference<XResourceId> & rxViewTabBarId,const Reference<frame::XController> & rxController)105cdf0e10cSrcweir ViewTabBar::ViewTabBar (
106cdf0e10cSrcweir const Reference<XResourceId>& rxViewTabBarId,
107cdf0e10cSrcweir const Reference<frame::XController>& rxController)
108cdf0e10cSrcweir : ViewTabBarInterfaceBase(maMutex),
109cdf0e10cSrcweir mpTabControl(new TabBarControl(GetAnchorWindow(rxViewTabBarId,rxController), this)),
110cdf0e10cSrcweir mxController(rxController),
111cdf0e10cSrcweir maTabBarButtons(),
112cdf0e10cSrcweir mpTabPage(NULL),
113cdf0e10cSrcweir mxViewTabBarId(rxViewTabBarId),
114cdf0e10cSrcweir mpViewShellBase(NULL)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir // Set one new tab page for all tab entries. We need it only to
117cdf0e10cSrcweir // determine the height of the tab bar.
118cdf0e10cSrcweir mpTabPage.reset(new TabPage (mpTabControl.get()));
119cdf0e10cSrcweir mpTabPage->Hide();
120cdf0e10cSrcweir
121cdf0e10cSrcweir // add some space before the tabitems
122cdf0e10cSrcweir mpTabControl->SetItemsOffset(Point(5, 3));
123cdf0e10cSrcweir
124cdf0e10cSrcweir // Tunnel through the controller and use the ViewShellBase to obtain the
125cdf0e10cSrcweir // view frame.
126cdf0e10cSrcweir try
127cdf0e10cSrcweir {
128cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
129cdf0e10cSrcweir DrawController* pController = reinterpret_cast<DrawController*>(
130cdf0e10cSrcweir xTunnel->getSomething(DrawController::getUnoTunnelId()));
131cdf0e10cSrcweir mpViewShellBase = pController->GetViewShellBase();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir catch(RuntimeException&)
134cdf0e10cSrcweir {}
135cdf0e10cSrcweir
136cdf0e10cSrcweir // Register as listener at XConfigurationController.
137cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (mxController, UNO_QUERY);
138cdf0e10cSrcweir if (xControllerManager.is())
139cdf0e10cSrcweir {
140cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController();
141cdf0e10cSrcweir if (mxConfigurationController.is())
142cdf0e10cSrcweir {
143cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener(
144cdf0e10cSrcweir this,
145cdf0e10cSrcweir FrameworkHelper::msResourceActivationEvent,
146cdf0e10cSrcweir Any());
147cdf0e10cSrcweir }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir mpTabControl->Show();
151cdf0e10cSrcweir
152cdf0e10cSrcweir if (mpViewShellBase != NULL
153cdf0e10cSrcweir && rxViewTabBarId->isBoundToURL(
154cdf0e10cSrcweir FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
155cdf0e10cSrcweir {
156cdf0e10cSrcweir mpViewShellBase->SetViewTabBar(this);
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir
161cdf0e10cSrcweir
162cdf0e10cSrcweir
~ViewTabBar(void)163cdf0e10cSrcweir ViewTabBar::~ViewTabBar (void)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir
169cdf0e10cSrcweir
disposing(void)170cdf0e10cSrcweir void ViewTabBar::disposing (void)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir if (mpViewShellBase != NULL
173cdf0e10cSrcweir && mxViewTabBarId->isBoundToURL(
174cdf0e10cSrcweir FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
175cdf0e10cSrcweir {
176cdf0e10cSrcweir mpViewShellBase->SetViewTabBar(NULL);
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir if (mxConfigurationController.is())
180cdf0e10cSrcweir {
181cdf0e10cSrcweir // Unregister listener from XConfigurationController.
182cdf0e10cSrcweir try
183cdf0e10cSrcweir {
184cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir catch (lang::DisposedException e)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir // Receiving a disposed exception is the normal case. Is there
189cdf0e10cSrcweir // a way to avoid it?
190cdf0e10cSrcweir }
191cdf0e10cSrcweir mxConfigurationController = NULL;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir {
195cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
196cdf0e10cSrcweir // Set all references to the one tab page to NULL and delete the page.
197cdf0e10cSrcweir for (sal_uInt16 nIndex=0; nIndex<mpTabControl->GetPageCount(); ++nIndex)
198cdf0e10cSrcweir mpTabControl->SetTabPage(nIndex, NULL);
199cdf0e10cSrcweir mpTabPage.reset();
200cdf0e10cSrcweir mpTabControl.reset();
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir mxController = NULL;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir
207cdf0e10cSrcweir
208cdf0e10cSrcweir
GetTabControl(void) const209cdf0e10cSrcweir ::boost::shared_ptr< ::TabControl> ViewTabBar::GetTabControl (void) const
210cdf0e10cSrcweir {
211cdf0e10cSrcweir return mpTabControl;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir
215cdf0e10cSrcweir
216cdf0e10cSrcweir
GetAnchorWindow(const Reference<XResourceId> & rxViewTabBarId,const Reference<frame::XController> & rxController)217cdf0e10cSrcweir ::Window* ViewTabBar::GetAnchorWindow(
218cdf0e10cSrcweir const Reference<XResourceId>& rxViewTabBarId,
219cdf0e10cSrcweir const Reference<frame::XController>& rxController)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir ::Window* pWindow = NULL;
222cdf0e10cSrcweir ViewShellBase* pBase = NULL;
223cdf0e10cSrcweir
224cdf0e10cSrcweir // Tunnel through the controller and use the ViewShellBase to obtain the
225cdf0e10cSrcweir // view frame.
226cdf0e10cSrcweir try
227cdf0e10cSrcweir {
228cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY_THROW);
229cdf0e10cSrcweir DrawController* pController = reinterpret_cast<DrawController*>(
230cdf0e10cSrcweir xTunnel->getSomething(DrawController::getUnoTunnelId()));
231cdf0e10cSrcweir pBase = pController->GetViewShellBase();
232cdf0e10cSrcweir }
233cdf0e10cSrcweir catch(RuntimeException&)
234cdf0e10cSrcweir {}
235cdf0e10cSrcweir
236cdf0e10cSrcweir // The ViewTabBar supports at the moment only the center pane.
237cdf0e10cSrcweir if (rxViewTabBarId.is()
238cdf0e10cSrcweir && rxViewTabBarId->isBoundToURL(
239cdf0e10cSrcweir FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
240cdf0e10cSrcweir {
241cdf0e10cSrcweir if (pBase != NULL && pBase->GetViewFrame() != NULL)
242cdf0e10cSrcweir pWindow = &pBase->GetViewFrame()->GetWindow();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir // The rest is (at the moment) just for the emergency case.
246cdf0e10cSrcweir if (pWindow == NULL)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir Reference<XPane> xPane;
249cdf0e10cSrcweir try
250cdf0e10cSrcweir {
251cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY_THROW);
252cdf0e10cSrcweir Reference<XConfigurationController> xCC (
253cdf0e10cSrcweir xControllerManager->getConfigurationController());
254cdf0e10cSrcweir if (xCC.is())
255cdf0e10cSrcweir xPane = Reference<XPane>(xCC->getResource(rxViewTabBarId->getAnchor()), UNO_QUERY);
256cdf0e10cSrcweir }
257cdf0e10cSrcweir catch (RuntimeException&)
258cdf0e10cSrcweir {}
259cdf0e10cSrcweir
260cdf0e10cSrcweir // Tunnel through the XWindow to the VCL side.
261cdf0e10cSrcweir try
262cdf0e10cSrcweir {
263cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (xPane, UNO_QUERY_THROW);
264cdf0e10cSrcweir framework::Pane* pPane = reinterpret_cast<framework::Pane*>(
265cdf0e10cSrcweir xTunnel->getSomething(framework::Pane::getUnoTunnelId()));
266cdf0e10cSrcweir if (pPane != NULL)
267cdf0e10cSrcweir pWindow = pPane->GetWindow()->GetParent();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir catch (RuntimeException&)
270cdf0e10cSrcweir {}
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir return pWindow;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
276cdf0e10cSrcweir
277cdf0e10cSrcweir
278cdf0e10cSrcweir
279cdf0e10cSrcweir //----- XConfigurationChangeListener ------------------------------------------
280cdf0e10cSrcweir
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)281cdf0e10cSrcweir void SAL_CALL ViewTabBar::notifyConfigurationChange (
282cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent)
283cdf0e10cSrcweir throw (RuntimeException)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent)
286cdf0e10cSrcweir && rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix)
287cdf0e10cSrcweir && rEvent.ResourceId->isBoundTo(mxViewTabBarId->getAnchor(), AnchorBindingMode_DIRECT))
288cdf0e10cSrcweir {
289cdf0e10cSrcweir UpdateActiveButton();
290cdf0e10cSrcweir }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir
294cdf0e10cSrcweir
295cdf0e10cSrcweir
296cdf0e10cSrcweir //----- XEventListener --------------------------------------------------------
297cdf0e10cSrcweir
disposing(const lang::EventObject & rEvent)298cdf0e10cSrcweir void SAL_CALL ViewTabBar::disposing(
299cdf0e10cSrcweir const lang::EventObject& rEvent)
300cdf0e10cSrcweir throw (RuntimeException)
301cdf0e10cSrcweir {
302cdf0e10cSrcweir if (rEvent.Source == mxConfigurationController)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir mxConfigurationController = NULL;
305cdf0e10cSrcweir mxController = NULL;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir
310cdf0e10cSrcweir
311cdf0e10cSrcweir
312cdf0e10cSrcweir //----- XTabBar ---------------------------------------------------------------
313cdf0e10cSrcweir
addTabBarButtonAfter(const TabBarButton & rButton,const TabBarButton & rAnchor)314cdf0e10cSrcweir void SAL_CALL ViewTabBar::addTabBarButtonAfter (
315cdf0e10cSrcweir const TabBarButton& rButton,
316cdf0e10cSrcweir const TabBarButton& rAnchor)
317cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
320cdf0e10cSrcweir AddTabBarButton(rButton, rAnchor);
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
323cdf0e10cSrcweir
324cdf0e10cSrcweir
325cdf0e10cSrcweir
appendTabBarButton(const TabBarButton & rButton)326cdf0e10cSrcweir void SAL_CALL ViewTabBar::appendTabBarButton (const TabBarButton& rButton)
327cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
330cdf0e10cSrcweir AddTabBarButton(rButton);
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir
334cdf0e10cSrcweir
removeTabBarButton(const TabBarButton & rButton)335cdf0e10cSrcweir void SAL_CALL ViewTabBar::removeTabBarButton (const TabBarButton& rButton)
336cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
339cdf0e10cSrcweir RemoveTabBarButton(rButton);
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir
343cdf0e10cSrcweir
344cdf0e10cSrcweir
hasTabBarButton(const TabBarButton & rButton)345cdf0e10cSrcweir sal_Bool SAL_CALL ViewTabBar::hasTabBarButton (const TabBarButton& rButton)
346cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
349cdf0e10cSrcweir return HasTabBarButton(rButton);
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir
353cdf0e10cSrcweir
354cdf0e10cSrcweir
getTabBarButtons(void)355cdf0e10cSrcweir Sequence<TabBarButton> SAL_CALL ViewTabBar::getTabBarButtons (void)
356cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
359cdf0e10cSrcweir return GetTabBarButtons();
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
362cdf0e10cSrcweir
363cdf0e10cSrcweir
364cdf0e10cSrcweir
365cdf0e10cSrcweir //----- XResource -------------------------------------------------------------
366cdf0e10cSrcweir
getResourceId(void)367cdf0e10cSrcweir Reference<XResourceId> SAL_CALL ViewTabBar::getResourceId (void)
368cdf0e10cSrcweir throw (RuntimeException)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir return mxViewTabBarId;
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
373cdf0e10cSrcweir
374cdf0e10cSrcweir
375cdf0e10cSrcweir
isAnchorOnly(void)376cdf0e10cSrcweir sal_Bool SAL_CALL ViewTabBar::isAnchorOnly (void)
377cdf0e10cSrcweir throw (RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir return false;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir
383cdf0e10cSrcweir
384cdf0e10cSrcweir
385cdf0e10cSrcweir //----- XUnoTunnel ------------------------------------------------------------
386cdf0e10cSrcweir
getUnoTunnelId(void)387cdf0e10cSrcweir const Sequence<sal_Int8>& ViewTabBar::getUnoTunnelId (void)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir static Sequence<sal_Int8>* pSequence = NULL;
390cdf0e10cSrcweir if (pSequence == NULL)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
393cdf0e10cSrcweir if (pSequence == NULL)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
396cdf0e10cSrcweir rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
397cdf0e10cSrcweir pSequence = &aSequence;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir }
400cdf0e10cSrcweir return *pSequence;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir
403cdf0e10cSrcweir
404cdf0e10cSrcweir
405cdf0e10cSrcweir
getSomething(const Sequence<sal_Int8> & rId)406cdf0e10cSrcweir sal_Int64 SAL_CALL ViewTabBar::getSomething (const Sequence<sal_Int8>& rId)
407cdf0e10cSrcweir throw (RuntimeException)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir sal_Int64 nResult = 0;
410cdf0e10cSrcweir
411cdf0e10cSrcweir if (rId.getLength() == 16
412cdf0e10cSrcweir && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir nResult = reinterpret_cast<sal_Int64>(this);
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
417cdf0e10cSrcweir return nResult;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
420cdf0e10cSrcweir
421cdf0e10cSrcweir
422cdf0e10cSrcweir
423cdf0e10cSrcweir //-----------------------------------------------------------------------------
424cdf0e10cSrcweir
ActivatePage(void)425cdf0e10cSrcweir bool ViewTabBar::ActivatePage (void)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir try
428cdf0e10cSrcweir {
429cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (mxController,UNO_QUERY_THROW);
430cdf0e10cSrcweir Reference<XConfigurationController> xConfigurationController (
431cdf0e10cSrcweir xControllerManager->getConfigurationController());
432cdf0e10cSrcweir if ( ! xConfigurationController.is())
433cdf0e10cSrcweir throw RuntimeException();
434cdf0e10cSrcweir Reference<XView> xView;
435cdf0e10cSrcweir try
436cdf0e10cSrcweir {
437cdf0e10cSrcweir xView = Reference<XView>(xConfigurationController->getResource(
438cdf0e10cSrcweir ResourceId::create(
439cdf0e10cSrcweir ::comphelper::getProcessComponentContext(),
440cdf0e10cSrcweir FrameworkHelper::msCenterPaneURL)),
441cdf0e10cSrcweir UNO_QUERY);
442cdf0e10cSrcweir }
443cdf0e10cSrcweir catch (DeploymentException)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir }
446cdf0e10cSrcweir
447cdf0e10cSrcweir Client* pIPClient = NULL;
448cdf0e10cSrcweir if (mpViewShellBase != NULL)
449cdf0e10cSrcweir pIPClient = dynamic_cast<Client*>(mpViewShellBase->GetIPClient());
450cdf0e10cSrcweir if (pIPClient==NULL || ! pIPClient->IsObjectInPlaceActive())
451cdf0e10cSrcweir {
452cdf0e10cSrcweir sal_uInt16 nIndex (mpTabControl->GetCurPageId() - 1);
453cdf0e10cSrcweir if (nIndex < maTabBarButtons.size())
454cdf0e10cSrcweir {
455cdf0e10cSrcweir xConfigurationController->requestResourceActivation(
456cdf0e10cSrcweir maTabBarButtons[nIndex].ResourceId,
457cdf0e10cSrcweir ResourceActivationMode_REPLACE);
458cdf0e10cSrcweir }
459cdf0e10cSrcweir
460cdf0e10cSrcweir return true;
461cdf0e10cSrcweir }
462cdf0e10cSrcweir else
463cdf0e10cSrcweir {
464cdf0e10cSrcweir // When we run into this else branch then we have an active OLE
465cdf0e10cSrcweir // object. We ignore the request to switch views. Additionally
466cdf0e10cSrcweir // we put the active tab back to the one for the current view.
467cdf0e10cSrcweir UpdateActiveButton();
468cdf0e10cSrcweir }
469cdf0e10cSrcweir }
470cdf0e10cSrcweir catch (RuntimeException&)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
475cdf0e10cSrcweir return false;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir
479cdf0e10cSrcweir
480cdf0e10cSrcweir
GetHeight(void)481cdf0e10cSrcweir int ViewTabBar::GetHeight (void)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir int nHeight (0);
484cdf0e10cSrcweir
485cdf0e10cSrcweir if (!maTabBarButtons.empty())
486cdf0e10cSrcweir {
487cdf0e10cSrcweir TabPage* pActivePage (mpTabControl->GetTabPage(
488cdf0e10cSrcweir mpTabControl->GetCurPageId()));
489cdf0e10cSrcweir if (pActivePage!=NULL && mpTabControl->IsReallyVisible())
490cdf0e10cSrcweir nHeight = pActivePage->GetPosPixel().Y();
491cdf0e10cSrcweir
492cdf0e10cSrcweir if (nHeight <= 0)
493cdf0e10cSrcweir // Using a default when the real height can not be determined.
494cdf0e10cSrcweir // To get correct height this method should be called when the
495cdf0e10cSrcweir // control is visible.
496cdf0e10cSrcweir nHeight = 21;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
499cdf0e10cSrcweir return nHeight;
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
502cdf0e10cSrcweir
503cdf0e10cSrcweir
504cdf0e10cSrcweir
AddTabBarButton(const::com::sun::star::drawing::framework::TabBarButton & rButton,const::com::sun::star::drawing::framework::TabBarButton & rAnchor)505cdf0e10cSrcweir void ViewTabBar::AddTabBarButton (
506cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rButton,
507cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rAnchor)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir sal_uInt32 nIndex;
510cdf0e10cSrcweir
511cdf0e10cSrcweir if ( ! rAnchor.ResourceId.is()
512cdf0e10cSrcweir || (rAnchor.ResourceId->getResourceURL().getLength() == 0
513cdf0e10cSrcweir && rAnchor.ButtonLabel.getLength() == 0))
514cdf0e10cSrcweir {
515cdf0e10cSrcweir nIndex = 0;
516cdf0e10cSrcweir }
517cdf0e10cSrcweir else
518cdf0e10cSrcweir {
519cdf0e10cSrcweir for (nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
520cdf0e10cSrcweir {
521cdf0e10cSrcweir if (IsEqual(maTabBarButtons[nIndex], rAnchor))
522cdf0e10cSrcweir {
523cdf0e10cSrcweir ++nIndex;
524cdf0e10cSrcweir break;
525cdf0e10cSrcweir }
526cdf0e10cSrcweir }
527cdf0e10cSrcweir }
528cdf0e10cSrcweir
529cdf0e10cSrcweir AddTabBarButton(rButton,nIndex);
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
532cdf0e10cSrcweir
533cdf0e10cSrcweir
534cdf0e10cSrcweir
AddTabBarButton(const::com::sun::star::drawing::framework::TabBarButton & rButton)535cdf0e10cSrcweir void ViewTabBar::AddTabBarButton (
536cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rButton)
537cdf0e10cSrcweir {
538cdf0e10cSrcweir AddTabBarButton(rButton, maTabBarButtons.size());
539cdf0e10cSrcweir }
540cdf0e10cSrcweir
541cdf0e10cSrcweir
542cdf0e10cSrcweir
543cdf0e10cSrcweir
AddTabBarButton(const::com::sun::star::drawing::framework::TabBarButton & rButton,sal_Int32 nPosition)544cdf0e10cSrcweir void ViewTabBar::AddTabBarButton (
545cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rButton,
546cdf0e10cSrcweir sal_Int32 nPosition)
547cdf0e10cSrcweir {
548cdf0e10cSrcweir if (nPosition>=0
549cdf0e10cSrcweir && nPosition<=mpTabControl->GetPageCount())
550cdf0e10cSrcweir {
551cdf0e10cSrcweir sal_uInt16 nIndex ((sal_uInt16)nPosition);
552cdf0e10cSrcweir
553cdf0e10cSrcweir // Insert the button into our local array.
554cdf0e10cSrcweir maTabBarButtons.insert(maTabBarButtons.begin()+nIndex, rButton);
555cdf0e10cSrcweir UpdateTabBarButtons();
556cdf0e10cSrcweir UpdateActiveButton();
557cdf0e10cSrcweir }
558cdf0e10cSrcweir }
559cdf0e10cSrcweir
560cdf0e10cSrcweir
561cdf0e10cSrcweir
562cdf0e10cSrcweir
RemoveTabBarButton(const::com::sun::star::drawing::framework::TabBarButton & rButton)563cdf0e10cSrcweir void ViewTabBar::RemoveTabBarButton (
564cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rButton)
565cdf0e10cSrcweir {
566cdf0e10cSrcweir sal_uInt16 nIndex;
567cdf0e10cSrcweir for (nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir if (IsEqual(maTabBarButtons[nIndex], rButton))
570cdf0e10cSrcweir {
571cdf0e10cSrcweir maTabBarButtons.erase(maTabBarButtons.begin()+nIndex);
572cdf0e10cSrcweir UpdateTabBarButtons();
573cdf0e10cSrcweir UpdateActiveButton();
574cdf0e10cSrcweir break;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir }
578cdf0e10cSrcweir
579cdf0e10cSrcweir
580cdf0e10cSrcweir
581cdf0e10cSrcweir
HasTabBarButton(const::com::sun::star::drawing::framework::TabBarButton & rButton)582cdf0e10cSrcweir bool ViewTabBar::HasTabBarButton (
583cdf0e10cSrcweir const ::com::sun::star::drawing::framework::TabBarButton& rButton)
584cdf0e10cSrcweir {
585cdf0e10cSrcweir bool bResult (false);
586cdf0e10cSrcweir
587cdf0e10cSrcweir for (sal_uInt32 nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir if (IsEqual(maTabBarButtons[nIndex], rButton))
590cdf0e10cSrcweir {
591cdf0e10cSrcweir bResult = true;
592cdf0e10cSrcweir break;
593cdf0e10cSrcweir }
594cdf0e10cSrcweir }
595cdf0e10cSrcweir
596cdf0e10cSrcweir return bResult;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir
599cdf0e10cSrcweir
600cdf0e10cSrcweir
601cdf0e10cSrcweir
602cdf0e10cSrcweir ::com::sun::star::uno::Sequence<com::sun::star::drawing::framework::TabBarButton>
GetTabBarButtons(void)603cdf0e10cSrcweir ViewTabBar::GetTabBarButtons (void)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir sal_uInt32 nCount (maTabBarButtons.size());
606cdf0e10cSrcweir ::com::sun::star::uno::Sequence<com::sun::star::drawing::framework::TabBarButton>
607cdf0e10cSrcweir aList (nCount);
608cdf0e10cSrcweir
609cdf0e10cSrcweir for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
610cdf0e10cSrcweir aList[nIndex] = maTabBarButtons[nIndex];
611cdf0e10cSrcweir
612cdf0e10cSrcweir return aList;
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
615cdf0e10cSrcweir
616cdf0e10cSrcweir
617cdf0e10cSrcweir
UpdateActiveButton(void)618cdf0e10cSrcweir void ViewTabBar::UpdateActiveButton (void)
619cdf0e10cSrcweir {
620cdf0e10cSrcweir Reference<XView> xView;
621cdf0e10cSrcweir if (mpViewShellBase != NULL)
622cdf0e10cSrcweir xView = FrameworkHelper::Instance(*mpViewShellBase)->GetView(
623cdf0e10cSrcweir mxViewTabBarId->getAnchor());
624cdf0e10cSrcweir if (xView.is())
625cdf0e10cSrcweir {
626cdf0e10cSrcweir Reference<XResourceId> xViewId (xView->getResourceId());
627cdf0e10cSrcweir for (sal_uInt16 nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir if (maTabBarButtons[nIndex].ResourceId->compareTo(xViewId) == 0)
630cdf0e10cSrcweir {
631cdf0e10cSrcweir mpTabControl->SetCurPageId(nIndex+1);
632cdf0e10cSrcweir mpTabControl->::TabControl::ActivatePage();
633cdf0e10cSrcweir break;
634cdf0e10cSrcweir }
635cdf0e10cSrcweir }
636cdf0e10cSrcweir }
637cdf0e10cSrcweir }
638cdf0e10cSrcweir
639cdf0e10cSrcweir
640cdf0e10cSrcweir
641cdf0e10cSrcweir
UpdateTabBarButtons(void)642cdf0e10cSrcweir void ViewTabBar::UpdateTabBarButtons (void)
643cdf0e10cSrcweir {
644cdf0e10cSrcweir TabBarButtonList::const_iterator iTab;
645cdf0e10cSrcweir sal_uInt16 nPageCount (mpTabControl->GetPageCount());
646cdf0e10cSrcweir sal_uInt16 nIndex;
647cdf0e10cSrcweir for (iTab=maTabBarButtons.begin(),nIndex=1; iTab!=maTabBarButtons.end(); ++iTab,++nIndex)
648cdf0e10cSrcweir {
649cdf0e10cSrcweir // Create a new tab when there are not enough.
650cdf0e10cSrcweir if (nPageCount < nIndex)
651cdf0e10cSrcweir mpTabControl->InsertPage(nIndex, iTab->ButtonLabel);
652cdf0e10cSrcweir
653cdf0e10cSrcweir // Update the tab.
654cdf0e10cSrcweir mpTabControl->SetPageText(nIndex, iTab->ButtonLabel);
655cdf0e10cSrcweir mpTabControl->SetHelpText(nIndex, iTab->HelpText);
656cdf0e10cSrcweir mpTabControl->SetTabPage(nIndex, mpTabPage.get());
657cdf0e10cSrcweir }
658cdf0e10cSrcweir
659cdf0e10cSrcweir // Delete tabs that are no longer used.
660cdf0e10cSrcweir for (; nIndex<=nPageCount; ++nIndex)
661cdf0e10cSrcweir mpTabControl->RemovePage(nIndex);
662cdf0e10cSrcweir
663cdf0e10cSrcweir mpTabPage->Hide();
664cdf0e10cSrcweir }
665cdf0e10cSrcweir
666cdf0e10cSrcweir
667cdf0e10cSrcweir
668cdf0e10cSrcweir
669cdf0e10cSrcweir //===== TabBarControl =========================================================
670cdf0e10cSrcweir
TabBarControl(::Window * pParentWindow,const::rtl::Reference<ViewTabBar> & rpViewTabBar)671cdf0e10cSrcweir TabBarControl::TabBarControl (
672cdf0e10cSrcweir ::Window* pParentWindow,
673cdf0e10cSrcweir const ::rtl::Reference<ViewTabBar>& rpViewTabBar)
674cdf0e10cSrcweir : ::TabControl(pParentWindow),
675cdf0e10cSrcweir mpViewTabBar(rpViewTabBar)
676cdf0e10cSrcweir {
677cdf0e10cSrcweir }
678cdf0e10cSrcweir
679cdf0e10cSrcweir
680cdf0e10cSrcweir
681cdf0e10cSrcweir
Paint(const Rectangle & rRect)682cdf0e10cSrcweir void TabBarControl::Paint (const Rectangle& rRect)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir Color aOriginalFillColor (GetFillColor());
685cdf0e10cSrcweir Color aOriginalLineColor (GetLineColor());
686cdf0e10cSrcweir
687cdf0e10cSrcweir // Because the actual window background is transparent--to avoid
688cdf0e10cSrcweir // flickering due to multiple background paintings by this and by child
689cdf0e10cSrcweir // windows--we have to paint the background for this control explicitly:
690cdf0e10cSrcweir // the actual control is not painted over its whole bounding box.
691cdf0e10cSrcweir SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
692cdf0e10cSrcweir SetLineColor ();
693cdf0e10cSrcweir DrawRect (rRect);
694cdf0e10cSrcweir ::TabControl::Paint (rRect);
695cdf0e10cSrcweir
696cdf0e10cSrcweir SetFillColor (aOriginalFillColor);
697cdf0e10cSrcweir SetLineColor (aOriginalLineColor);
698cdf0e10cSrcweir }
699cdf0e10cSrcweir
700cdf0e10cSrcweir
701cdf0e10cSrcweir
702cdf0e10cSrcweir
ActivatePage(void)703cdf0e10cSrcweir void TabBarControl::ActivatePage (void)
704cdf0e10cSrcweir {
705cdf0e10cSrcweir if (mpViewTabBar->ActivatePage())
706cdf0e10cSrcweir {
707cdf0e10cSrcweir // Call the parent so that the correct tab is highlighted.
708cdf0e10cSrcweir this->::TabControl::ActivatePage();
709cdf0e10cSrcweir }
710cdf0e10cSrcweir }
711cdf0e10cSrcweir
712cdf0e10cSrcweir } // end of namespace sd
713