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
20 #include <uielement/FixedTextToolbarController.hxx>
21
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24
25 #include <vcl/window.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/svapp.hxx>
29
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::awt;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::frame;
36 using namespace ::com::sun::star::util;
37
38 namespace framework
39 {
FixedTextToolbarController(const Reference<XComponentContext> & rxContext,const Reference<XFrame> & rFrame,ToolBox * pToolbar,sal_uInt16 nID,const OUString & aCommand)40 FixedTextToolbarController::FixedTextToolbarController(
41 const Reference<XComponentContext>& rxContext, const Reference<XFrame>& rFrame,
42 ToolBox* pToolbar, sal_uInt16 nID, const OUString& aCommand)
43 : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, aCommand)
44 {
45 m_pFixedTextControl = VclPtr<FixedText>::Create(m_pToolbar, WB_NOMULTILINE | WB_VCENTER
46 | WB_LEFT | WB_NOPOINTERFOCUS);
47 m_pToolbar->SetItemWindow(m_nID, m_pFixedTextControl);
48 m_pToolbar->SetItemBits(m_nID, ToolBoxItemBits::AUTOSIZE | m_pToolbar->GetItemBits(m_nID));
49 }
50
dispose()51 void SAL_CALL FixedTextToolbarController::dispose()
52 {
53 SolarMutexGuard aSolarMutexGuard;
54 m_pToolbar->SetItemWindow(m_nID, nullptr);
55 m_pFixedTextControl.disposeAndClear();
56 ComplexToolbarController::dispose();
57 }
58
getExecuteArgs(sal_Int16 KeyModifier) const59 Sequence<PropertyValue> FixedTextToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
60 {
61 Sequence<PropertyValue> aArgs(2);
62 const OUString aSelectedText = m_pFixedTextControl->GetText();
63
64 // Add key modifier to argument list
65 aArgs[0].Name = "KeyModifier";
66 aArgs[0].Value <<= KeyModifier;
67 aArgs[1].Name = "Text";
68 aArgs[1].Value <<= aSelectedText;
69 return aArgs;
70 }
71
executeControlCommand(const css::frame::ControlCommand & rControlCommand)72 void FixedTextToolbarController::executeControlCommand(
73 const css::frame::ControlCommand& rControlCommand)
74 {
75 SolarMutexGuard aSolarMutexGuard;
76
77 if (rControlCommand.Command == "SetText")
78 {
79 for (sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++)
80 {
81 if (rControlCommand.Arguments[i].Name == "Text")
82 {
83 OUString aText;
84 rControlCommand.Arguments[i].Value >>= aText;
85 m_pFixedTextControl->SetText(aText);
86 m_pFixedTextControl->SetSizePixel(m_pFixedTextControl->GetOptimalSize());
87
88 // send notification
89 notifyTextChanged(aText);
90 break;
91 }
92 }
93 }
94 }
95
96 } // namespace
97
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */