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 
27 SvxCTLTextTbxCtrl::SvxCTLTextTbxCtrl(const css::uno::Reference<css::uno::XComponentContext>& rContext)
28  : SvxVertCTLTextTbxCtrl(rContext)
29 {
30  addStatusListener(".uno:CTLFontState");
31 }
32 
34 {
35  return "com.sun.star.comp.svx.CTLToolBoxControl";
36 }
37 
38 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
40  css::uno::XComponentContext* rContext,
41  css::uno::Sequence<css::uno::Any> const & )
42 {
43  return cppu::acquire(new SvxCTLTextTbxCtrl(rContext));
44 }
45 
46 SvxVertTextTbxCtrl::SvxVertTextTbxCtrl(const css::uno::Reference<css::uno::XComponentContext>& rContext)
47  : SvxVertCTLTextTbxCtrl(rContext)
48 {
49  addStatusListener(".uno:VerticalTextState");
50 }
51 
53 {
54  return "com.sun.star.comp.svx.VertTextToolBoxControl";
55 }
56 
57 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
59  css::uno::XComponentContext* rContext,
60  css::uno::Sequence<css::uno::Any> const & )
61 {
62  return cppu::acquire(new SvxVertTextTbxCtrl(rContext));
63 }
64 
65 SvxVertCTLTextTbxCtrl::SvxVertCTLTextTbxCtrl(const css::uno::Reference<css::uno::XComponentContext>& rContext)
66  : SvxVertCTLTextTbxCtrl_Base(rContext, nullptr, OUString())
67  , m_bVisible(false)
68 {
69 }
70 
72 {
73 }
74 
75 void SAL_CALL SvxVertCTLTextTbxCtrl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
76 {
77  SvxVertCTLTextTbxCtrl_Base::initialize(rArguments);
78  // fdo#83320 Hide vertical text commands early
79  setFastPropertyValue_NoBroadcast(1, css::uno::makeAny(true));
80 
81  if (m_pToolbar)
82  {
83  m_bVisible = m_pToolbar->get_item_visible(m_aCommandURL.toUtf8());
84  return;
85  }
86 
87  ToolBox* pToolBox = nullptr;
88  sal_uInt16 nItemId = 0;
89  if (getToolboxId(nItemId, &pToolBox))
90  m_bVisible = pToolBox->IsItemVisible(nItemId);
91 }
92 
93 void SAL_CALL SvxVertCTLTextTbxCtrl::statusChanged(const css::frame::FeatureStateEvent& rEvent)
94 {
95  ToolBox* pToolBox = nullptr;
96  sal_uInt16 nItemId = 0;
97  bool bVclToolBox = getToolboxId(nItemId, &pToolBox);
98 
99  bool bEnabled = false;
100  if (rEvent.FeatureURL.Complete == ".uno:VerticalTextState")
101  {
102  SvtLanguageOptions aLangOptions;
103  bEnabled = m_bVisible && aLangOptions.IsVerticalTextEnabled();
104  }
105  else if (rEvent.FeatureURL.Complete == ".uno:CTLFontState")
106  {
107  SvtLanguageOptions aLangOptions;
108  bEnabled = m_bVisible && aLangOptions.IsCTLFontEnabled();
109  }
110  else
111  {
112  // normal command
113  bool bValue = false;
114  rEvent.State >>= bValue;
115 
116  if (m_pToolbar)
117  {
118  OString sId = m_aCommandURL.toUtf8();
119  m_pToolbar->set_item_active(sId, bValue);
120  m_pToolbar->set_item_sensitive(sId, rEvent.IsEnabled);
121  }
122 
123  if (bVclToolBox)
124  {
125  pToolBox->CheckItem(nItemId, bValue);
126  pToolBox->EnableItem(nItemId, rEvent.IsEnabled);
127  }
128 
129  return;
130  }
131 
132  if (m_pToolbar)
133  {
134  m_pToolbar->set_item_visible(m_aCommandURL.toUtf8(), bEnabled);
135  return;
136  }
137 
138  if (bVclToolBox)
139  {
140  pToolBox->ShowItem(nItemId, bEnabled);
141 
142  vcl::Window* pParent = pToolBox->GetParent();
143  if (WindowType::FLOATINGWINDOW == pParent->GetType())
144  {
145  Size aSize(pToolBox->CalcWindowSizePixel());
146  pToolBox->SetPosSizePixel( Point(), aSize );
147  pParent->SetOutputSizePixel( aSize );
148  }
149  }
150 }
151 
152 // XServiceInfo
153 sal_Bool SAL_CALL SvxVertCTLTextTbxCtrl::supportsService( const OUString& ServiceName )
154 {
155  return cppu::supportsService(this, ServiceName);
156 }
157 
158 css::uno::Sequence< OUString > SvxVertCTLTextTbxCtrl::getSupportedServiceNames()
159 {
160  return { "com.sun.star.frame.ToolbarController" };
161 }
162 
163 /* 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)