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 <vcl/layout.hxx>
11 #include <vcl/notebookbar.hxx>
12 #include <vcl/syswin.hxx>
13 #include <vcl/taskpanelist.hxx>
15 #include <cppuhelper/implbase.hxx>
17 #include <rtl/bootstrap.hxx>
18 #include <osl/file.hxx>
19 #include <config_folders.h>
20 #include <com/sun/star/frame/XFrame.hpp>
21 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
22 
23 static OUString getCustomizedUIRootDir()
24 {
25  OUString sShareLayer("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE(
26  "bootstrap") ":UserInstallation}/user/config/soffice.cfg/");
27  rtl::Bootstrap::expandMacros(sShareLayer);
28  return sShareLayer;
29 }
30 
31 static bool doesFileExist(const OUString& sUIDir, const OUString& sUIFile)
32 {
33  OUString sUri = sUIDir + sUIFile;
34  osl::File file(sUri);
35  return( file.open(0) == osl::FileBase::E_None );
36 }
37 
41 class NotebookBarContextChangeEventListener : public ::cppu::WeakImplHelper<css::ui::XContextChangeEventListener>
42 {
44 public:
45  explicit NotebookBarContextChangeEventListener(NotebookBar *p) : mpParent(p) {}
46 
47  // XContextChangeEventListener
48  virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent) override;
49 
50  virtual void SAL_CALL disposing(const ::css::lang::EventObject&) override;
51 };
52 
53 NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
54  const css::uno::Reference<css::frame::XFrame>& rFrame,
55  const NotebookBarAddonsItem& aNotebookBarAddonsItem)
56  : Control(pParent)
57  , m_pEventListener(new NotebookBarContextChangeEventListener(this))
58 {
60  OUString sUIDir = getUIRootDir();
61  bool doesCustomizedUIExist = doesFileExist(getCustomizedUIRootDir(), rUIXMLDescription);
62  if ( doesCustomizedUIExist )
63  sUIDir = getCustomizedUIRootDir();
64  m_pUIBuilder.reset(
65  new VclBuilder(this, sUIDir, rUIXMLDescription, rID, rFrame, true, &aNotebookBarAddonsItem));
66  mxFrame = rFrame;
67  // In the Notebookbar's .ui file must exist control handling context
68  // - implementing NotebookbarContextControl interface with id "ContextContainer"
69  // or "ContextContainerX" where X is a number >= 1
70  NotebookbarContextControl* pContextContainer = nullptr;
71  int i = 0;
72  do
73  {
74  OUString aName = "ContextContainer";
75  if (i)
76  aName += OUString::number(i);
77 
78  pContextContainer = dynamic_cast<NotebookbarContextControl*>(m_pUIBuilder->get<Window>(OUStringToOString(aName, RTL_TEXTENCODING_UTF8)));
79  if (pContextContainer)
80  m_pContextContainers.push_back(pContextContainer);
81  i++;
82  }
83  while( pContextContainer != nullptr );
84 
86 }
87 
89 {
90  disposeOnce();
91 }
92 
94 {
95  m_pContextContainers.clear();
100  m_pEventListener.clear();
102 }
103 
105 {
106  // capture KeyEvents for taskpane cycling
107  if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
108  {
109  if (m_pSystemWindow)
110  return m_pSystemWindow->PreNotify(rNEvt);
111  }
112  return Window::PreNotify( rNEvt );
113 }
114 
116 {
117  if (isLayoutEnabled(this))
119 
120  return Control::GetOptimalSize();
121 }
122 
123 void NotebookBar::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags)
124 {
125  bool bCanHandleSmallerWidth = false;
126  bool bCanHandleSmallerHeight = false;
127 
128  bool bIsLayoutEnabled = isLayoutEnabled(this);
130 
131  if (bIsLayoutEnabled && pChild->GetType() == WindowType::SCROLLWINDOW)
132  {
133  WinBits nStyle = pChild->GetStyle();
134  if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL))
135  bCanHandleSmallerWidth = true;
136  if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL))
137  bCanHandleSmallerHeight = true;
138  }
139 
140  Size aSize(GetOptimalSize());
141  if (!bCanHandleSmallerWidth)
142  nWidth = std::max(nWidth, aSize.Width());
143  if (!bCanHandleSmallerHeight)
144  nHeight = std::max(nHeight, aSize.Height());
145 
146  Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
147 
148  if (bIsLayoutEnabled && (nFlags & PosSizeFlags::Size))
149  VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
150 }
151 
153 {
154  if(m_pUIBuilder && m_pUIBuilder->get_widget_root())
155  {
156  vcl::Window* pWindow = m_pUIBuilder->get_widget_root()->GetChild(0);
157  if (pWindow)
158  {
159  Size aSize = pWindow->GetSizePixel();
160  aSize.setWidth( GetSizePixel().Width() );
161  pWindow->SetSizePixel(aSize);
162  }
163  }
164  Control::Resize();
165 }
166 
168 {
169  m_pSystemWindow = pSystemWindow;
172 }
173 
174 void SAL_CALL NotebookBarContextChangeEventListener::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
175 {
176  if (mpParent)
177  {
179  pControl->SetContext(vcl::EnumContext::GetContextEnum(rEvent.ContextName));
180  }
181 }
182 
184 {
185  if(bListen)
186  {
187  // remove listeners
188  css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (css::ui::ContextChangeEventMultiplexer::get(
190  xMultiplexer->removeContextChangeEventListener(getContextChangeEventListener(),mxFrame->getController());
191  }
192  else
193  {
194  // add listeners
195  css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (css::ui::ContextChangeEventMultiplexer::get(
197  xMultiplexer->addContextChangeEventListener(getContextChangeEventListener(),mxFrame->getController());
198  }
199 }
200 
201 void SAL_CALL NotebookBarContextChangeEventListener::disposing(const ::css::lang::EventObject&)
202 {
203  mpParent.clear();
204 }
205 
207 {
209  Control::DataChanged(rDCEvt);
210 }
211 
213 {
215  Control::StateChanged(nStateChange);
216  Invalidate();
217 }
218 
220 {
221  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
222  const BitmapEx& aPersona = rStyleSettings.GetPersonaHeader();
223  Wallpaper aWallpaper(aPersona);
225  if (!aPersona.IsEmpty())
226  {
227  SetBackground(aWallpaper);
230  }
231  else
232  {
233  SetBackground(rStyleSettings.GetDialogColor());
236  }
237 
239 }
240 
242 {
243  AllSettings aAllSettings( GetSettings() );
244  StyleSettings aStyleSet( aAllSettings.GetStyleSettings() );
245 
246  ::Color aTextColor = aStyleSet.GetFieldTextColor();
247  aStyleSet.SetDialogTextColor( aTextColor );
248  aStyleSet.SetButtonTextColor( aTextColor );
249  aStyleSet.SetRadioCheckTextColor( aTextColor );
250  aStyleSet.SetGroupTextColor( aTextColor );
251  aStyleSet.SetLabelTextColor( aTextColor );
252  aStyleSet.SetWindowTextColor( aTextColor );
253  aStyleSet.SetTabTextColor(aTextColor);
254  aStyleSet.SetToolTextColor(aTextColor);
255 
256  aAllSettings.SetStyleSettings(aStyleSet);
257  DefaultSettings = aAllSettings;
258 }
259 
261 {
262  AllSettings aAllSettings( GetSettings() );
263  StyleSettings aStyleSet( aAllSettings.GetStyleSettings() );
264 
265  ::Color aTextColor = aStyleSet.GetPersonaMenuBarTextColor().get_value_or(COL_BLACK );
266  aStyleSet.SetDialogTextColor( aTextColor );
267  aStyleSet.SetButtonTextColor( aTextColor );
268  aStyleSet.SetRadioCheckTextColor( aTextColor );
269  aStyleSet.SetGroupTextColor( aTextColor );
270  aStyleSet.SetLabelTextColor( aTextColor );
271  aStyleSet.SetWindowTextColor( aTextColor );
272  aStyleSet.SetTabTextColor(aTextColor);
273  aStyleSet.SetToolTextColor(aTextColor);
274 
275  aAllSettings.SetStyleSettings(aStyleSet);
276  PersonaSettings = aAllSettings;
277 }
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:63
const Color & GetDialogColor() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: notebookbar.cxx:93
AllSettings PersonaSettings
Definition: notebookbar.hxx:57
void SetStyleSettings(const StyleSettings &rSet)
long Height() const
std::vector< NotebookbarContextControl * > m_pContextContainers
Definition: notebookbar.hxx:53
virtual Size GetOptimalSize() const override
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All) override
static Context GetContextEnum(const OUString &rsContextName)
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:138
const StyleSettings & GetStyleSettings() const
static OUString getCustomizedUIRootDir()
Definition: notebookbar.cxx:23
BitmapEx const & GetPersonaHeader() const
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
virtual Size GetSizePixel() const
Definition: window.cxx:2364
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1256
WinBits const WB_AUTOVSCROLL
PosSizeFlags
Definition: window.hxx:139
WinBits const WB_VSCROLL
virtual void SetSettings(const AllSettings &rSettings) override
void UpdateDefaultSettings()
const css::uno::Reference< css::ui::XContextChangeEventListener > & getContextChangeEventListener() const
Definition: notebookbar.hxx:42
VclPtr< SystemWindow > m_pSystemWindow
Definition: notebookbar.hxx:51
StateChangedType
Definition: window.hxx:309
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2685
sal_Int64 WinBits
void SetBackground()
void UpdateBackground()
virtual bool PreNotify(NotifyEvent &rNEvt) override
WinBits const WB_HSCROLL
void SetSystemWindow(SystemWindow *pSystemWindow)
void ControlListener(bool bListen)
NotebookBarContextChangeEventListener(NotebookBar *p)
Definition: notebookbar.cxx:45
css::uno::Reference< css::ui::XContextChangeEventListener > m_pEventListener
Definition: notebookbar.hxx:52
WinBits const WB_DIALOGCONTROL
bool IsEmpty() const
Definition: bitmapex.cxx:203
#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:198
Window(WindowType nType)
Definition: window.cxx:84
virtual void Resize() override
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:208
int i
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1153
void StateChanged(const StateChangedType nStateChange) override
std::unique_ptr< VclBuilder > m_pUIBuilder
Definition: builder.hxx:501
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2666
MouseNotifyEvent GetType() const
Definition: event.hxx:294
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
NotebookBar(Window *pParent, const OString &rID, const OUString &rUIXMLDescription, const css::uno::Reference< css::frame::XFrame > &rFrame, const NotebookBarAddonsItem &aNotebookBarAddonsItem)
Definition: notebookbar.cxx:53
static OUString getUIRootDir()
Definition: dialog.cxx:543
AllSettings DefaultSettings
Definition: notebookbar.hxx:56
void SetStyle(WinBits nStyle)
Definition: window.cxx:1925
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
void disposeBuilder()
Definition: dialog.cxx:537
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
SAL_DLLPRIVATE bool ImplIsInTaskPaneList(vcl::Window *pWin)
Definition: syswin.cxx:1005
virtual void Resize() override
Definition: ctrl.cxx:74
void UpdatePersonaSettings()
css::uno::Reference< css::frame::XFrame > mxFrame
Definition: notebookbar.hxx:54
Definition: ctrl.hxx:33
static bool doesFileExist(const OUString &sUIDir, const OUString &sUIFile)
Definition: notebookbar.cxx:31
virtual ~NotebookBar() override
Definition: notebookbar.cxx:88
Reference< XComponentContext > getProcessComponentContext()
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject &rEvent) override
void RemoveWindow(vcl::Window *pWindow)
WinBits const WB_AUTOHSCROLL
OString const aName
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:240
virtual void SetContext(vcl::EnumContext::Context eContext)=0
void setWidth(long nWidth)
This implements Widget Layout-based notebook-like menu bar.
Definition: notebookbar.hxx:25
split from the main class since it needs different ref-counting mana
Definition: notebookbar.cxx:41
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35