LibreOffice Module svx (master)  1
verttexttbxctrl.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  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
21 #include <svx/verttexttbxctrl.hxx>
22 #include <svl/languageoptions.hxx>
23 #include <vcl/toolbox.hxx>
24 #include <vcl/weld.hxx>
25 #include <rtl/ustring.hxx>
26 
28  const css::uno::Reference<css::uno::XComponentContext>& rContext)
29  : SvxVertCTLTextTbxCtrl(rContext)
30 {
31  addStatusListener(".uno:CTLFontState");
32 }
33 
35 {
36  return "com.sun.star.comp.svx.CTLToolBoxControl";
37 }
38 
39 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
40 com_sun_star_comp_svx_CTLToolBoxControl_get_implementation(css::uno::XComponentContext* rContext,
41  css::uno::Sequence<css::uno::Any> const&)
42 {
43  return cppu::acquire(new SvxCTLTextTbxCtrl(rContext));
44 }
45 
47  const css::uno::Reference<css::uno::XComponentContext>& rContext)
48  : SvxVertCTLTextTbxCtrl(rContext)
49 {
50  addStatusListener(".uno:VerticalTextState");
51 }
52 
54 {
55  return "com.sun.star.comp.svx.VertTextToolBoxControl";
56 }
57 
58 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
60  css::uno::XComponentContext* rContext, css::uno::Sequence<css::uno::Any> const&)
61 {
62  return cppu::acquire(new SvxVertTextTbxCtrl(rContext));
63 }
64 
66  const css::uno::Reference<css::uno::XComponentContext>& rContext)
67  : SvxVertCTLTextTbxCtrl_Base(rContext, nullptr, OUString())
68  , m_bVisible(false)
69 {
70 }
71 
73 
74 void SAL_CALL SvxVertCTLTextTbxCtrl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
75 {
76  SvxVertCTLTextTbxCtrl_Base::initialize(rArguments);
77  // fdo#83320 Hide vertical text commands early
78  setFastPropertyValue_NoBroadcast(1, css::uno::makeAny(true));
79 
80  if (m_pToolbar)
81  {
82  m_bVisible = m_pToolbar->get_item_visible(m_aCommandURL.toUtf8());
83  return;
84  }
85 
86  ToolBox* pToolBox = nullptr;
87  sal_uInt16 nItemId = 0;
88  if (getToolboxId(nItemId, &pToolBox))
89  m_bVisible = pToolBox->IsItemVisible(nItemId);
90 }
91 
92 void SAL_CALL SvxVertCTLTextTbxCtrl::statusChanged(const css::frame::FeatureStateEvent& rEvent)
93 {
94  ToolBox* pToolBox = nullptr;
95  sal_uInt16 nItemId = 0;
96  bool bVclToolBox = getToolboxId(nItemId, &pToolBox);
97 
98  bool bEnabled = false;
99  if (rEvent.FeatureURL.Complete == ".uno:VerticalTextState")
100  {
101  SvtLanguageOptions aLangOptions;
102  bEnabled = m_bVisible && aLangOptions.IsVerticalTextEnabled();
103  }
104  else if (rEvent.FeatureURL.Complete == ".uno:CTLFontState")
105  {
106  SvtLanguageOptions aLangOptions;
107  bEnabled = m_bVisible && aLangOptions.IsCTLFontEnabled();
108  }
109  else
110  {
111  // normal command
112  bool bValue = false;
113  rEvent.State >>= bValue;
114 
115  if (m_pToolbar)
116  {
117  OString sId = m_aCommandURL.toUtf8();
118  m_pToolbar->set_item_active(sId, bValue);
119  m_pToolbar->set_item_sensitive(sId, rEvent.IsEnabled);
120  }
121 
122  if (bVclToolBox)
123  {
124  pToolBox->CheckItem(nItemId, bValue);
125  pToolBox->EnableItem(nItemId, rEvent.IsEnabled);
126  }
127 
128  return;
129  }
130 
131  if (m_pToolbar)
132  {
133  m_pToolbar->set_item_visible(m_aCommandURL.toUtf8(), bEnabled);
134  return;
135  }
136 
137  if (bVclToolBox)
138  {
139  pToolBox->ShowItem(nItemId, bEnabled);
140 
141  vcl::Window* pParent = pToolBox->GetParent();
142  if (WindowType::FLOATINGWINDOW == pParent->GetType())
143  {
144  Size aSize(pToolBox->CalcWindowSizePixel());
145  pToolBox->SetPosSizePixel(Point(), aSize);
146  pParent->SetOutputSizePixel(aSize);
147  }
148  }
149 }
150 
151 // XServiceInfo
152 sal_Bool SAL_CALL SvxVertCTLTextTbxCtrl::supportsService(const OUString& ServiceName)
153 {
154  return cppu::supportsService(this, ServiceName);
155 }
156 
158 {
159  return { "com.sun.star.frame.ToolbarController" };
160 }
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxVertTextTbxCtrl(const css::uno::Reference< css::uno::XComponentContext > &rContext)
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &rEvent) override
void ShowItem(sal_uInt16 nItemId, bool bVisible=true)
virtual OUString SAL_CALL getImplementationName() override
bool IsVerticalTextEnabled() const
Size CalcWindowSizePixel()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_CTLToolBoxControl_get_implementation(css::uno::XComponentContext *rContext, css::uno::Sequence< css::uno::Any > const &)
virtual void SetOutputSizePixel(const Size &rNewSize)
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
SvxCTLTextTbxCtrl(const css::uno::Reference< css::uno::XComponentContext > &rContext)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_VertTextToolBoxControl_get_implementation(css::uno::XComponentContext *rContext, css::uno::Sequence< css::uno::Any > const &)
void CheckItem(sal_uInt16 nItemId, bool bCheck=true)
unsigned char sal_Bool
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
vcl::Window * GetParent() const
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
bool IsItemVisible(sal_uInt16 nItemId) const
virtual ~SvxVertCTLTextTbxCtrl() override
bool IsCTLFontEnabled() const
WindowType GetType() const
OUString sId
SvxVertCTLTextTbxCtrl(const css::uno::Reference< css::uno::XComponentContext > &rContext)