/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include using namespace ::com::sun::star; using namespace css::uno; using namespace css::beans; using namespace css::lang; using namespace css::frame; using namespace css::util; namespace framework { // Wrapper class to notify controller about events from combobox. // Unfortunately the events are notified through virtual methods instead // of Listeners. class ComboBoxControl final : public InterimItemWindow { public: ComboBoxControl(vcl::Window* pParent, ComboboxToolbarController* pComboboxToolbarController); virtual ~ComboBoxControl() override; virtual void dispose() override; void set_active_or_entry_text(const OUString& rText); OUString get_active_text() const { return m_xWidget->get_active_text(); } void clear() { m_xWidget->clear(); } void remove(int nIndex) { m_xWidget->remove(nIndex); } void append_text(const OUString& rStr) { m_xWidget->append_text(rStr); } void insert_text(int pos, const OUString& rStr) { m_xWidget->insert_text(pos, rStr); } int get_count() const { return m_xWidget->get_count(); } int find_text(const OUString& rStr) const { return m_xWidget->find_text(rStr); } DECL_LINK(FocusInHdl, weld::Widget&, void); DECL_LINK(FocusOutHdl, weld::Widget&, void); DECL_LINK(ModifyHdl, weld::ComboBox&, void); DECL_LINK(ActivateHdl, weld::ComboBox&, bool); DECL_LINK(KeyInputHdl, const ::KeyEvent&, bool); private: std::unique_ptr m_xWidget; ComboboxToolbarController* m_pComboboxToolbarController; }; ComboBoxControl::ComboBoxControl(vcl::Window* pParent, ComboboxToolbarController* pComboboxToolbarController) : InterimItemWindow(pParent, "svt/ui/combocontrol.ui", "ComboControl") , m_xWidget(m_xBuilder->weld_combo_box("combobox")) , m_pComboboxToolbarController(pComboboxToolbarController) { InitControlBase(m_xWidget.get()); m_xWidget->connect_focus_in(LINK(this, ComboBoxControl, FocusInHdl)); m_xWidget->connect_focus_out(LINK(this, ComboBoxControl, FocusOutHdl)); m_xWidget->connect_changed(LINK(this, ComboBoxControl, ModifyHdl)); m_xWidget->connect_entry_activate(LINK(this, ComboBoxControl, ActivateHdl)); m_xWidget->connect_key_press(LINK(this, ComboBoxControl, KeyInputHdl)); m_xWidget->set_entry_width_chars(1); // so a smaller than default width can be used by ComboboxToolbarController SetSizePixel(get_preferred_size()); } IMPL_LINK(ComboBoxControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool) { return ChildKeyInput(rKEvt); } void ComboBoxControl::set_active_or_entry_text(const OUString& rText) { const int nFound = m_xWidget->find_text(rText); if (nFound != -1) m_xWidget->set_active(nFound); else m_xWidget->set_entry_text(rText); } ComboBoxControl::~ComboBoxControl() { disposeOnce(); } void ComboBoxControl::dispose() { m_pComboboxToolbarController = nullptr; m_xWidget.reset(); InterimItemWindow::dispose(); } IMPL_LINK_NOARG(ComboBoxControl, ModifyHdl, weld::ComboBox&, void) { if (m_pComboboxToolbarController) { if (m_xWidget->get_count() && m_xWidget->changed_by_direct_pick()) m_pComboboxToolbarController->Select(); else m_pComboboxToolbarController->Modify(); } } IMPL_LINK_NOARG(ComboBoxControl, FocusInHdl, weld::Widget&, void) { if (m_pComboboxToolbarController) m_pComboboxToolbarController->GetFocus(); } IMPL_LINK_NOARG(ComboBoxControl, FocusOutHdl, weld::Widget&, void) { if (m_pComboboxToolbarController) m_pComboboxToolbarController->LoseFocus(); } IMPL_LINK_NOARG(ComboBoxControl, ActivateHdl, weld::ComboBox&, bool) { if (m_pComboboxToolbarController) m_pComboboxToolbarController->Activate(); return true; } ComboboxToolbarController::ComboboxToolbarController( const Reference< XComponentContext >& rxContext, const Reference< XFrame >& rFrame, ToolBox* pToolbar, sal_uInt16 nID, sal_Int32 nWidth, const OUString& aCommand ) : ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ) , m_pComboBox( nullptr ) { m_pComboBox = VclPtr::Create(m_xToolbar, this); if ( nWidth == 0 ) nWidth = 100; // ComboBoxControl ctor has set a suitable height already auto nHeight = m_pComboBox->GetSizePixel().Height(); m_pComboBox->SetSizePixel( ::Size( nWidth, nHeight )); m_xToolbar->SetItemWindow( m_nID, m_pComboBox ); } ComboboxToolbarController::~ComboboxToolbarController() { } void SAL_CALL ComboboxToolbarController::dispose() { SolarMutexGuard aSolarMutexGuard; m_xToolbar->SetItemWindow( m_nID, nullptr ); m_pComboBox.disposeAndClear(); ComplexToolbarController::dispose(); } Sequence ComboboxToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const { Sequence aArgs( 2 ); OUString aSelectedText = m_pComboBox->get_active_text(); // Add key modifier to argument list aArgs[0].Name = "KeyModifier"; aArgs[0].Value <<= KeyModifier; aArgs[1].Name = "Text"; aArgs[1].Value <<= aSelectedText; return aArgs; } void ComboboxToolbarController::Select() { vcl::Window::PointerState aState = m_pComboBox->GetPointerState(); sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODIFIERS_MASK ); execute( nKeyModifier ); } void ComboboxToolbarController::Modify() { notifyTextChanged(m_pComboBox->get_active_text()); } void ComboboxToolbarController::GetFocus() { notifyFocusGet(); } void ComboboxToolbarController::LoseFocus() { notifyFocusLost(); } void ComboboxToolbarController::Activate() { // Call execute only with non-empty text if (!m_pComboBox->get_active_text().isEmpty()) execute(0); } void ComboboxToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand ) { if ( rControlCommand.Command == "SetText" ) { for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "Text" ) { OUString aText; rArg.Value >>= aText; m_pComboBox->set_active_or_entry_text(aText); // send notification notifyTextChanged( aText ); break; } } } else if ( rControlCommand.Command == "SetList" ) { for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "List" ) { Sequence< OUString > aList; m_pComboBox->clear(); rArg.Value >>= aList; for (OUString const & rName : std::as_const(aList)) m_pComboBox->append_text(rName); // send notification uno::Sequence< beans::NamedValue > aInfo { { "List", css::uno::makeAny(aList) } }; addNotifyInfo( "ListChanged", getDispatchFromCommand( m_aCommandURL ), aInfo ); break; } } } else if ( rControlCommand.Command == "AddEntry" ) { OUString aText; for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "Text" ) { if ( rArg.Value >>= aText ) m_pComboBox->append_text(aText); break; } } } else if ( rControlCommand.Command == "InsertEntry" ) { sal_Int32 nPos(-1); OUString aText; for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "Pos" ) { sal_Int32 nTmpPos = 0; if ( rArg.Value >>= nTmpPos ) { if (( nTmpPos >= 0 ) && ( nTmpPos < m_pComboBox->get_count() )) nPos = nTmpPos; } } else if ( rArg.Name == "Text" ) rArg.Value >>= aText; } m_pComboBox->insert_text(nPos, aText); } else if ( rControlCommand.Command == "RemoveEntryPos" ) { for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "Pos" ) { sal_Int32 nPos( -1 ); if ( rArg.Value >>= nPos ) { if (0 <= nPos && nPos < m_pComboBox->get_count()) m_pComboBox->remove(nPos); } break; } } } else if ( rControlCommand.Command == "RemoveEntryText" ) { for ( const NamedValue& rArg : rControlCommand.Arguments ) { if ( rArg.Name == "Text") { OUString aText; if ( rArg.Value >>= aText ) { auto nPos = m_pComboBox->find_text(aText); if (nPos != -1) m_pComboBox->remove(nPos); } break; } } } } } // namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ act45533 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2022-05-04Just use Any ctor instead of makeAny in cppuStephan Bergmann
2021-05-02throw() -> noexcept, part 2/3: Automatic loplugin:noexcept rewriteStephan Bergmann
2019-01-29tdf#42949 Fix IWYU warnings in cppu/Gabor Kelemen
2017-12-07loplugin:salcall handle static methodsNoel Grandin
2017-10-23loplugin:includeform: cppuStephan Bergmann
2017-07-02loplugin:casttovoid: cppuStephan Bergmann
2017-04-12clang-tidy: readability-else-after-returnNoel Grandin
2017-01-26Remove dynamic exception specificationsStephan Bergmann
2016-09-13loplugin:override: No more need for the "MSVC dtor override" workaroundStephan Bergmann
2016-05-31teach refcounting clang plugin about uno::ReferenceNoel Grandin
2016-05-30Some clean up of uses of css::uno::Any::setValueStephan Bergmann
2016-04-08tdf#94306 replace boost::noncopyable in cppuhelperJochen Nitschke
2015-10-12Replace "SAL_OVERRIDE" with "override" in LIBO_INTERNAL_ONLY codeStephan Bergmann
2015-10-12Replace "SAL_DELETED_FUNCTION" with "= delete" in LIBO_INTERNAL_ONLY codeStephan Bergmann
2015-04-01Replace remaining getCppuType et al with cppu::UnoTypeStephan Bergmann
2014-10-31Removed duplicated includesAndrea Gelmini
2014-04-09Clean up function declarationsStephan Bergmann
2014-04-03Cosmetics (to ease work related to finding unused functions)Stephan Bergmann
2014-03-26First batch of adding SAL_OVERRRIDE to overriding function declarationsStephan Bergmann
2014-02-27std::exception retrofit sequelStephan Bergmann
2013-05-07Avoid warnings about unused test functionsStephan Bergmann
2013-05-07Up-cast conversion constructor for css::uno::ReferenceStephan Bergmann
2012-09-17migrate some of the biggest consumer of osl_*InterlockedCount to osl_atomicNorbert Thiebaud
2012-08-01Bin no longer used iOS cppunit stuff that breaks build evenTor Lillqvist
2012-06-27targetted re-work of cppunit pieces.Michael Meeks
2012-06-26re-base on ALv2 code.Michael Meeks
2011-11-27remove include of pch header in cppuNorbert Thiebaud
2011-09-12sb140: #i113503# mixing system CppUnit and OOo STLport does not work, backed ...Stephan Bergmann
2011-08-01Add statically linked cppu unit test for iOSTor Lillqvist
2011-02-09Removing the ext_std masterpieceFridrich Štrba
2011-01-14cppunit: port these tests over to canonical cppunitCaolán McNamara