tdf#164420 Fix unselected Check/Radio buttons not following themes in GTK
[LibreOffice.git] / sw / source / ui / inc / condedit.hxx
blobab07c0c597dd85b0a1b07cba8c5c75e1c7aa7353
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_CONDEDIT_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_CONDEDIT_HXX
22 #include <vcl/transfer.hxx>
23 #include <vcl/weld.hxx>
24 #include <svx/dbaexchange.hxx>
26 template <typename X> class ConditionEdit;
28 template <class T> class ConditionEditDropTarget final : public DropTargetHelper
30 private:
31 ConditionEdit<T>& m_rEdit;
33 virtual sal_Int8 AcceptDrop(const AcceptDropEvent&) override
35 return svx::OColumnTransferable::canExtractColumnDescriptor(
36 GetDataFlavorExVector(), ColumnTransferFormatFlags::COLUMN_DESCRIPTOR)
37 ? DND_ACTION_COPY
38 : DND_ACTION_NONE;
40 virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
42 sal_Int8 nRet = DND_ACTION_NONE;
43 if (m_rEdit.GetDropEnable())
45 TransferableDataHelper aData(rEvt.maDropEvent.Transferable);
47 const DataFlavorExVector& rVector = aData.GetDataFlavorExVector();
48 if (svx::OColumnTransferable::canExtractColumnDescriptor(
49 rVector, ColumnTransferFormatFlags::COLUMN_DESCRIPTOR))
51 svx::ODataAccessDescriptor aColDesc
52 = svx::OColumnTransferable::extractColumnDescriptor(aData);
53 OUString sDBName;
54 bool bBrackets = m_rEdit.GetBrackets();
55 if (bBrackets)
56 sDBName += "[";
57 OUString sTmp = aColDesc.getDataSource();
58 sDBName += sTmp + ".";
60 aColDesc[svx::DataAccessDescriptorProperty::Command] >>= sTmp;
61 sDBName += sTmp + ".";
63 aColDesc[svx::DataAccessDescriptorProperty::ColumnName] >>= sTmp;
64 sDBName += sTmp;
65 if (bBrackets)
66 sDBName += "]";
68 m_rEdit.get_widget().set_text(sDBName);
69 nRet = DND_ACTION_COPY;
72 return nRet;
75 public:
76 ConditionEditDropTarget(ConditionEdit<T>& rEdit)
77 : DropTargetHelper(rEdit.get_widget().get_drop_target())
78 , m_rEdit(rEdit)
83 //< weld::Entry >
84 template <class T> class ConditionEdit
86 std::unique_ptr<T> m_xControl;
87 ConditionEditDropTarget<T> m_aDropTargetHelper;
88 bool m_bBrackets, m_bEnableDrop;
90 public:
91 ConditionEdit(std::unique_ptr<T> xControl)
92 : m_xControl(std::move(xControl))
93 , m_aDropTargetHelper(*this)
94 , m_bBrackets(true)
95 , m_bEnableDrop(true)
99 OUString get_text() const { return m_xControl->get_text(); }
100 void set_text(const OUString& rText) { m_xControl->set_text(rText); }
101 void set_visible(bool bVisible) { m_xControl->set_visible(bVisible); }
102 void set_accessible_name(const OUString& rName) { m_xControl->set_accessible_name(rName); }
103 void save_value() { m_xControl->save_value(); }
104 bool get_value_changed_from_saved() const { return m_xControl->get_value_changed_from_saved(); }
105 void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
106 void connect_changed(const Link<T&, void>& rLink) { m_xControl->connect_changed(rLink); }
107 void replace_selection(const OUString& rText) { m_xControl->replace_selection(rText); }
108 void hide() { m_xControl->hide(); }
109 T& get_widget() { return *m_xControl; }
111 OUString get_buildable_name() const { return m_xControl->get_buildable_name(); }
112 void set_buildable_name(const OUString& rId) { m_xControl->set_buildable_name(rId); }
114 void ShowBrackets(bool bShow) { m_bBrackets = bShow; }
115 bool GetBrackets() const { return m_bBrackets; }
116 void SetDropEnable(bool bFlag) { m_bEnableDrop = bFlag; }
117 bool GetDropEnable() const { return m_bEnableDrop; }
120 #endif
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */