LibreOffice Module vcl (master)  1
notebookbar.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #include <sal/config.h>
11 
12 #include <string_view>
13 
14 #include <vcl/layout.hxx>
16 #include <vcl/syswin.hxx>
17 #include <vcl/taskpanelist.hxx>
19 #include <cppuhelper/implbase.hxx>
21 #include <rtl/bootstrap.hxx>
22 #include <osl/file.hxx>
23 #include <config_folders.h>
24 #include <com/sun/star/frame/XFrame.hpp>
25 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
26 #include <comphelper/lok.hxx>
27 
28 static OUString getCustomizedUIRootDir()
29 {
30  OUString sShareLayer("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE(
31  "bootstrap") ":UserInstallation}/user/config/soffice.cfg/");
32  rtl::Bootstrap::expandMacros(sShareLayer);
33  return sShareLayer;
34 }
35 
36 static bool doesFileExist(std::u16string_view sUIDir, std::u16string_view sUIFile)
37 {
38  OUString sUri = OUString::Concat(sUIDir) + sUIFile;
39  osl::File file(sUri);
40  return( file.open(0) == osl::FileBase::E_None );
41 }
42 
46 class NotebookBarContextChangeEventListener : public ::cppu::WeakImplHelper<css::ui::XContextChangeEventListener>
47 {
49 public:
50  explicit NotebookBarContextChangeEventListener(NotebookBar *p) : mpParent(p) {}
51 
52  // XContextChangeEventListener
53  virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent) override;
54 
55  virtual void SAL_CALL disposing(const ::css::lang::EventObject&) override;
56 };
57 
58 NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
59  const css::uno::Reference<css::frame::XFrame>& rFrame,
60  const NotebookBarAddonsItem& aNotebookBarAddonsItem)
61  : Control(pParent)
62  , m_pEventListener(new NotebookBarContextChangeEventListener(this))
63  , m_pViewShell(nullptr)
64  , m_bIsWelded(false)
65  , m_sUIXMLDescription(rUIXMLDescription)
66 {
67  mxFrame = rFrame;
68 
70  OUString sUIDir = AllSettings::GetUIRootDir();
71  bool doesCustomizedUIExist = doesFileExist(getCustomizedUIRootDir(), rUIXMLDescription);
72  if ( doesCustomizedUIExist )
73  sUIDir = getCustomizedUIRootDir();
74 
75  bool bIsWelded = comphelper::LibreOfficeKit::isActive();
76  if (bIsWelded)
77  {
78  m_bIsWelded = true;
81  // now access it using GetMainContainer and set dispose callback with SetDisposeCallback
82  }
83  else
84  {
85  m_pUIBuilder.reset(
86  new VclBuilder(this, sUIDir, rUIXMLDescription, rID, rFrame, true, &aNotebookBarAddonsItem));
87 
88  // In the Notebookbar's .ui file must exist control handling context
89  // - implementing NotebookbarContextControl interface with id "ContextContainer"
90  // or "ContextContainerX" where X is a number >= 1
91  NotebookbarContextControl* pContextContainer = nullptr;
92  int i = 0;
93  do
94  {
95  OUString aName = "ContextContainer";
96  if (i)
97  aName += OUString::number(i);
98 
99  pContextContainer = dynamic_cast<NotebookbarContextControl*>(m_pUIBuilder->get<Window>(OUStringToOString(aName, RTL_TEXTENCODING_UTF8)));
100  if (pContextContainer)
101  m_pContextContainers.push_back(pContextContainer);
102  i++;
103  }
104  while( pContextContainer != nullptr );
105  }
106 
108 }
109 
110 void NotebookBar::SetDisposeCallback(const Link<const SfxViewShell*, void> rDisposeCallback, const SfxViewShell* pViewShell)
111 {
112  m_rDisposeLink = rDisposeCallback;
113  m_pViewShell = pViewShell;
114 }
115 
117 {
118  disposeOnce();
119 }
120 
122 {
123  m_pContextContainers.clear();
127 
128  if (m_rDisposeLink.IsSet())
130 
131  if (m_bIsWelded)
133  else
134  disposeBuilder();
135 
136  assert(m_alisteningControllers.empty());
137  m_pEventListener.clear();
138 
140 }
141 
143 {
144  // capture KeyEvents for taskpane cycling
145  if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
146  {
147  if (m_pSystemWindow)
148  return m_pSystemWindow->PreNotify(rNEvt);
149  }
150  return Window::PreNotify( rNEvt );
151 }
152 
154 {
155  if (isLayoutEnabled(this))
157 
158  return Control::GetOptimalSize();
159 }
160 
162 {
163  bool bCanHandleSmallerWidth = false;
164  bool bCanHandleSmallerHeight = false;
165 
166  bool bIsLayoutEnabled = isLayoutEnabled(this);
168 
169  if (bIsLayoutEnabled && pChild->GetType() == WindowType::SCROLLWINDOW)
170  {
171  WinBits nStyle = pChild->GetStyle();
172  if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL))
173  bCanHandleSmallerWidth = true;
174  if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL))
175  bCanHandleSmallerHeight = true;
176  }
177 
178  Size aSize(GetOptimalSize());
179  if (!bCanHandleSmallerWidth)
180  nWidth = std::max(nWidth, aSize.Width());
181  if (!bCanHandleSmallerHeight)
182  nHeight = std::max(nHeight, aSize.Height());
183 
184  Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
185 
186  if (bIsLayoutEnabled && (nFlags & PosSizeFlags::Size))
187  VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
188 }
189 
191 {
192  if(m_pUIBuilder && m_pUIBuilder->get_widget_root())
193  {
194  vcl::Window* pWindow = m_pUIBuilder->get_widget_root()->GetChild(0);
195  if (pWindow)
196  {
197  Size aSize = pWindow->GetSizePixel();
198  aSize.setWidth( GetSizePixel().Width() );
199  pWindow->SetSizePixel(aSize);
200  }
201  }
202  if(m_bIsWelded)
203  {
205  assert(pChild);
207  Control::Resize();
208  }
209  Control::Resize();
210 }
211 
213 {
214  m_pSystemWindow = pSystemWindow;
217 }
218 
219 void SAL_CALL NotebookBarContextChangeEventListener::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
220 {
221  if (mpParent)
222  {
224  pControl->SetContext(vcl::EnumContext::GetContextEnum(rEvent.ContextName));
225  }
226 }
227 
229 {
231  return;
232 
233  auto xController = mxFrame->getController();
234  if(bListen)
235  {
236  // add listeners
237  if (m_alisteningControllers.count(xController) == 0)
238  {
239  auto xMultiplexer(css::ui::ContextChangeEventMultiplexer::get(
241  xMultiplexer->addContextChangeEventListener(m_pEventListener, xController);
243  }
244  }
245  else
246  {
247  // remove listeners
249  {
250  auto xMultiplexer(css::ui::ContextChangeEventMultiplexer::get(
252  xMultiplexer->removeContextChangeEventListener(m_pEventListener, xController);
254  }
255  }
256 }
257 
259 {
261  return;
262 
263  auto xMultiplexer(
264  css::ui::ContextChangeEventMultiplexer::get(comphelper::getProcessComponentContext()));
265  xMultiplexer->removeAllContextChangeEventListeners(m_pEventListener);
266  m_alisteningControllers.clear();
267 }
268 
269 void SAL_CALL NotebookBarContextChangeEventListener::disposing(const ::css::lang::EventObject&)
270 {
271  mpParent.clear();
272 }
273 
275 {
277  Control::DataChanged(rDCEvt);
278 }
279 
281 {
283  Control::StateChanged(nStateChange);
284  Invalidate();
285 }
286 
288 {
289  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
290  const BitmapEx& aPersona = rStyleSettings.GetPersonaHeader();
291  Wallpaper aWallpaper(aPersona);
293  if (!aPersona.IsEmpty())
294  {
295  SetBackground(aWallpaper);
298  }
299  else
300  {
301  SetBackground(rStyleSettings.GetDialogColor());
304  }
305 
307 }
308 
310 {
311  AllSettings aAllSettings( GetSettings() );
312  StyleSettings aStyleSet( aAllSettings.GetStyleSettings() );
313 
314  ::Color aTextColor = aStyleSet.GetFieldTextColor();
315  aStyleSet.SetDialogTextColor( aTextColor );
316  aStyleSet.SetButtonTextColor( aTextColor );
317  aStyleSet.SetRadioCheckTextColor( aTextColor );
318  aStyleSet.SetGroupTextColor( aTextColor );
319  aStyleSet.SetLabelTextColor( aTextColor );
320  aStyleSet.SetWindowTextColor( aTextColor );
321  aStyleSet.SetTabTextColor(aTextColor);
322  aStyleSet.SetToolTextColor(aTextColor);
323 
324  aAllSettings.SetStyleSettings(aStyleSet);
325  DefaultSettings = aAllSettings;
326 }
327 
329 {
330  AllSettings aAllSettings( GetSettings() );
331  StyleSettings aStyleSet( aAllSettings.GetStyleSettings() );
332 
333  ::Color aTextColor = aStyleSet.GetPersonaMenuBarTextColor().value_or(COL_BLACK );
334  aStyleSet.SetDialogTextColor( aTextColor );
335  aStyleSet.SetButtonTextColor( aTextColor );
336  aStyleSet.SetRadioCheckTextColor( aTextColor );
337  aStyleSet.SetGroupTextColor( aTextColor );
338  aStyleSet.SetLabelTextColor( aTextColor );
339  aStyleSet.SetWindowTextColor( aTextColor );
340  aStyleSet.SetTabTextColor(aTextColor);
341  aStyleSet.SetToolTextColor(aTextColor);
342 
343  aAllSettings.SetStyleSettings(aStyleSet);
344  PersonaSettings = aAllSettings;
345 }
346 
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetBackground()
Definition: window3.cxx:100
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:76
const Color & GetDialogColor() const
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
void setWidth(tools::Long nWidth)
AllSettings PersonaSettings
Definition: notebookbar.hxx:69
void SetStyleSettings(const StyleSettings &rSet)
std::vector< NotebookbarContextControl * > m_pContextContainers
Definition: notebookbar.hxx:59
virtual Size GetOptimalSize() const override
static Context GetContextEnum(const OUString &rsContextName)
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:151
long Long
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
static OUString getCustomizedUIRootDir()
Definition: notebookbar.cxx:28
BitmapEx const & GetPersonaHeader() const
VclPtr< vcl::Window > m_xVclContentArea
Definition: notebookbar.hxx:63
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:255
virtual Size GetSizePixel() const
Definition: window.cxx:2399
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1256
WinBits const WB_AUTOVSCROLL
PosSizeFlags
Definition: window.hxx:125
WinBits const WB_VSCROLL
virtual void SetSettings(const AllSettings &rSettings)
Definition: outdev.cxx:218
void UpdateDefaultSettings()
VclPtr< SystemWindow > m_pSystemWindow
Definition: notebookbar.hxx:56
StateChangedType
Definition: window.hxx:289
constexpr tools::Long Width() const
sal_Int64 WinBits
void UpdateBackground()
Reference< XController > xController
Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar, etc.
Definition: builder.hxx:66
virtual bool PreNotify(NotifyEvent &rNEvt) override
WinBits const WB_HSCROLL
void SetSystemWindow(SystemWindow *pSystemWindow)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::set< css::uno::Reference< css::frame::XController > > m_alisteningControllers
Definition: notebookbar.hxx:58
NotebookBarContextChangeEventListener(NotebookBar *p)
Definition: notebookbar.cxx:50
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All) override
css::uno::Reference< css::ui::XContextChangeEventListener > m_pEventListener
Definition: notebookbar.hxx:57
static OUString GetUIRootDir()
Definition: dialog.cxx:556
WinBits const WB_DIALOGCONTROL
bool IsEmpty() const
Definition: BitmapEx.cxx:177
#define SAL_CONFIGFILE(name)
void clear()
Definition: vclptr.hxx:190
void DataChanged(const DataChangedEvent &rDCEvt) override
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: syswin.cxx:196
Window(WindowType nType)
Definition: window.cxx:92
int i
virtual void Resize() override
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:165
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1164
static bool doesFileExist(std::u16string_view sUIDir, std::u16string_view sUIFile)
Definition: notebookbar.cxx:36
void ControlListenerForCurrentController(bool bListen)
void StateChanged(const StateChangedType nStateChange) override
const AllSettings & GetSettings() const
Definition: window3.cxx:129
std::unique_ptr< VclBuilder > m_pUIBuilder
Definition: syswin.hxx:86
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2904
MouseNotifyEvent GetType() const
Definition: event.hxx:308
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:57
NotebookBar(Window *pParent, const OString &rID, const OUString &rUIXMLDescription, const css::uno::Reference< css::frame::XFrame > &rFrame, const NotebookBarAddonsItem &aNotebookBarAddonsItem)
Definition: notebookbar.cxx:58
AllSettings DefaultSettings
Definition: notebookbar.hxx:68
void SetDisposeCallback(const Link< const SfxViewShell *, void > rDisposeCallback, const SfxViewShell *pViewShell)
void SetStyle(WinBits nStyle)
Definition: window.cxx:1959
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
void disposeBuilder()
Definition: dialog.cxx:550
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2663
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:368
SAL_DLLPRIVATE bool ImplIsInTaskPaneList(vcl::Window *pWin)
Definition: syswin.cxx:955
Link< const SfxViewShell *, void > m_rDisposeLink
Definition: notebookbar.hxx:66
virtual void Resize() override
Definition: ctrl.cxx:73
void UpdatePersonaSettings()
css::uno::Reference< css::frame::XFrame > mxFrame
Definition: notebookbar.hxx:60
Definition: ctrl.hxx:81
constexpr tools::Long Height() const
OUString aName
::OutputDevice const * GetOutDev() const
Definition: window.cxx:565
virtual ~NotebookBar() override
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
Reference< XComponentContext > getProcessComponentContext()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject &rEvent) override
void RemoveWindow(vcl::Window *pWindow)
WinBits const WB_AUTOHSCROLL
const SfxViewShell * m_pViewShell
Definition: notebookbar.hxx:61
virtual void SAL_CALL disposing(const ::css::lang::EventObject &) override
WinBits GetStyle() const
Definition: window2.cxx:947
void AddWindow(vcl::Window *pWindow)
TaskPaneList * GetTaskPaneList()
Definition: syswin.cxx:238
virtual void SetContext(vcl::EnumContext::Context eContext)=0
void StopListeningAllControllers()
bool m_bIsWelded
Definition: notebookbar.hxx:64
This implements Widget Layout-based notebook-like menu bar.
Definition: notebookbar.hxx:26
split from the main class since it needs different ref-counting mana
Definition: notebookbar.cxx:46
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2184