1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <com/sun/star/drawing/framework/TabBarButton.hpp>
23 #include <com/sun/star/drawing/framework/XTabBar.hpp>
24 #include <com/sun/star/drawing/framework/XToolBar.hpp>
25 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
26 #include <comphelper/compbase.hxx>
27 #include <vcl/InterimItemWindow.hxx>
31 namespace com::sun::star::drawing::framework
{ class XConfigurationController
; }
32 namespace com::sun::star::drawing::framework
{ class XResourceId
; }
33 namespace com::sun::star::drawing::framework
{ struct ConfigurationChangeEvent
; }
34 namespace com::sun::star::frame
{ class XController
; }
35 namespace vcl
{ class Window
; }
45 class TabBarControl final
: public InterimItemWindow
48 TabBarControl(vcl::Window
* pParentWindow
, ::rtl::Reference
<ViewTabBar
> pViewTabBar
);
49 virtual void dispose() override
;
50 virtual ~TabBarControl() override
;
51 weld::Notebook
& GetNotebook() { return *mxTabControl
; }
52 int GetAllocatedWidth() const { return mnAllocatedWidth
; }
54 std::unique_ptr
<weld::Notebook
> mxTabControl
;
55 ::rtl::Reference
<ViewTabBar
> mpViewTabBar
;
58 DECL_LINK(ActivatePageHdl
, const OUString
&, void);
59 DECL_LINK(NotebookSizeAllocHdl
, const Size
&, void);
62 typedef comphelper::WeakComponentImplHelper
<
63 css::drawing::framework::XToolBar
,
64 css::drawing::framework::XTabBar
,
65 css::drawing::framework::XConfigurationChangeListener
66 > ViewTabBarInterfaceBase
;
68 /** Tab control for switching between views in the center pane.
70 class ViewTabBar final
71 : public ViewTabBarInterfaceBase
75 const css::uno::Reference
< css::drawing::framework::XResourceId
>& rxViewTabBarId
,
76 const rtl::Reference
< ::sd::DrawController
>& rxController
);
77 virtual ~ViewTabBar() override
;
79 virtual void disposing(std::unique_lock
<std::mutex
>&) override
;
81 const VclPtr
<TabBarControl
>& GetTabControl() const { return mpTabControl
; }
83 bool ActivatePage(size_t nIndex
);
85 //----- drawing::framework::XConfigurationChangeListener ------------------
88 notifyConfigurationChange (
89 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
) override
;
91 //----- XEventListener ----------------------------------------------------
93 virtual void SAL_CALL
disposing(
94 const css::lang::EventObject
& rEvent
) override
;
96 //----- XTabBar -----------------------------------------------------------
99 SAL_CALL
addTabBarButtonAfter (
100 const css::drawing::framework::TabBarButton
& rButton
,
101 const css::drawing::framework::TabBarButton
& rAnchor
) override
;
104 SAL_CALL
appendTabBarButton (
105 const css::drawing::framework::TabBarButton
& rButton
) override
;
108 SAL_CALL
removeTabBarButton (
109 const css::drawing::framework::TabBarButton
& rButton
) override
;
112 SAL_CALL
hasTabBarButton (
113 const css::drawing::framework::TabBarButton
& rButton
) override
;
115 virtual css::uno::Sequence
<css::drawing::framework::TabBarButton
>
116 SAL_CALL
getTabBarButtons() override
;
118 //----- XResource ---------------------------------------------------------
120 virtual css::uno::Reference
<
121 css::drawing::framework::XResourceId
> SAL_CALL
getResourceId() override
;
123 virtual sal_Bool SAL_CALL
isAnchorOnly() override
;
125 /** The returned value is calculated as the difference between the
126 total height of the control and the height of its first tab page.
127 This can be considered a hack.
128 This procedure works only when the control is visible. Calling this
129 method when the control is not visible results in returning a
131 To be on the safe side wait for this control to become visible and
132 the call this method again.
134 int GetHeight() const;
136 void UpdateActiveButton();
138 void AddTabBarButton (
139 const css::drawing::framework::TabBarButton
& rButton
,
140 const css::drawing::framework::TabBarButton
& rAnchor
);
141 void AddTabBarButton (
142 const css::drawing::framework::TabBarButton
& rButton
);
143 void RemoveTabBarButton (
144 const css::drawing::framework::TabBarButton
& rButton
);
145 bool HasTabBarButton (
146 const css::drawing::framework::TabBarButton
& rButton
);
147 css::uno::Sequence
<css::drawing::framework::TabBarButton
>
151 VclPtr
<TabBarControl
> mpTabControl
;
152 rtl::Reference
<::sd::DrawController
> mxController
;
153 css::uno::Reference
<css::drawing::framework::XConfigurationController
> mxConfigurationController
;
154 typedef ::std::vector
<css::drawing::framework::TabBarButton
> TabBarButtonList
;
155 TabBarButtonList maTabBarButtons
;
156 css::uno::Reference
<css::drawing::framework::XResourceId
> mxViewTabBarId
;
157 ViewShellBase
* mpViewShellBase
;
158 int mnNoteBookWidthPadding
;
160 void AddTabBarButton (
161 const css::drawing::framework::TabBarButton
& rButton
,
162 sal_Int32 nPosition
);
163 void UpdateTabBarButtons();
165 /** This method is called from the constructor to get the window for an
166 anchor ResourceId and pass it to our base class. It has to be
167 static because it must not access any of the, not yet initialized
170 static vcl::Window
* GetAnchorWindow(
171 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxViewTabBarId
,
172 const rtl::Reference
<::sd::DrawController
>& rxController
);
175 } // end of namespace sd
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */