1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
31 ConditionEdit
<T
>& m_rEdit
;
33 virtual sal_Int8
AcceptDrop(const AcceptDropEvent
&) override
35 return svx::OColumnTransferable::canExtractColumnDescriptor(
36 GetDataFlavorExVector(), ColumnTransferFormatFlags::COLUMN_DESCRIPTOR
)
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
);
54 bool bBrackets
= m_rEdit
.GetBrackets();
57 OUString sTmp
= aColDesc
.getDataSource();
58 sDBName
+= sTmp
+ ".";
60 aColDesc
[svx::DataAccessDescriptorProperty::Command
] >>= sTmp
;
61 sDBName
+= sTmp
+ ".";
63 aColDesc
[svx::DataAccessDescriptorProperty::ColumnName
] >>= sTmp
;
68 m_rEdit
.get_widget().set_text(sDBName
);
69 nRet
= DND_ACTION_COPY
;
76 ConditionEditDropTarget(ConditionEdit
<T
>& rEdit
)
77 : DropTargetHelper(rEdit
.get_widget().get_drop_target())
84 template <class T
> class ConditionEdit
86 std::unique_ptr
<T
> m_xControl
;
87 ConditionEditDropTarget
<T
> m_aDropTargetHelper
;
88 bool m_bBrackets
, m_bEnableDrop
;
91 ConditionEdit(std::unique_ptr
<T
> xControl
)
92 : m_xControl(std::move(xControl
))
93 , m_aDropTargetHelper(*this)
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
; }
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */