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 #pragma once
21 
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/form/XBoundComponent.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/util/XNumberFormatter.hpp>
27 #include <com/sun/star/awt/XTextComponent.hpp>
28 #include <com/sun/star/sdb/SQLContext.hpp>
29 #include <com/sun/star/sdbc/XConnection.hpp>
30 #include <toolkit/controls/unocontrol.hxx>
31 
32 #include <toolkit/helper/listenermultiplexer.hxx>
33 #include <cppuhelper/implbase5.hxx>
34 #include <comphelper/uno3.hxx>
35 #include <svx/ParseContext.hxx>
36 
37 #include <unordered_map>
38 
39 
40 namespace frm
41 {
42 
43 
44     // OFilterControl
45 
46     typedef ::cppu::ImplHelper5 <   css::awt::XTextComponent
47                                 ,   css::awt::XFocusListener
48                                 ,   css::awt::XItemListener
49                                 ,   css::form::XBoundComponent
50                                 ,   css::lang::XInitialization
51                                 >   OFilterControl_BASE;
52 
53     class OFilterControl final :public UnoControl
54                             ,public OFilterControl_BASE
55                             ,public ::svxform::OParseContextClient
56     {
57         TextListenerMultiplexer     m_aTextListeners;
58 
59         css::uno::Reference< css::uno::XComponentContext >            m_xContext;
60         css::uno::Reference< css::beans::XPropertySet >               m_xField;
61         css::uno::Reference< css::util::XNumberFormatter >            m_xFormatter;
62         css::uno::Reference< css::sdbc::XConnection >                 m_xConnection;
63         css::uno::Reference< css::awt::XWindow >                      m_xMessageParent;
64 
65         typedef std::unordered_map< OUString, OUString > MapString2String;
66         MapString2String                m_aDisplayItemToValueItem;
67 
68         OUString                        m_aText;
69         sal_Int16                       m_nControlClass;        // which kind of control do we use?
70         bool                            m_bFilterList : 1;
71         bool                            m_bMultiLine : 1;
72         bool                            m_bFilterListFilled : 1;
73 
74         void implInitFilterList();
75         void initControlModel(css::uno::Reference< css::beans::XPropertySet > const & xControlModel);
76 
77     public:
78         explicit OFilterControl( const css::uno::Reference< css::uno::XComponentContext >& _rxORB );
79 
80         DECLARE_UNO3_AGG_DEFAULTS(OFilterControl,OWeakAggObject)
81         css::uno::Any  SAL_CALL queryAggregation( const css::uno::Type & rType ) override;
82 
83         virtual OUString GetComponentServiceName() override;
84         virtual void SAL_CALL   createPeer( const css::uno::Reference< css::awt::XToolkit > & rxToolkit, const css::uno::Reference< css::awt::XWindowPeer >  & rParentPeer ) override;
85 
86     // css::lang::XComponent
87         virtual void SAL_CALL   dispose() override;
88 
89     // css::awt::XTextComponent
90         virtual void            SAL_CALL addTextListener( const css::uno::Reference< css::awt::XTextListener > & l ) override;
91         virtual void            SAL_CALL removeTextListener( const css::uno::Reference< css::awt::XTextListener > & l ) override;
92         virtual void            SAL_CALL setText( const OUString& aText ) override;
93         virtual void            SAL_CALL insertText( const css::awt::Selection& rSel, const OUString& aText ) override;
94         virtual OUString SAL_CALL getText() override;
95         virtual OUString SAL_CALL getSelectedText() override;
96         virtual void            SAL_CALL setSelection( const css::awt::Selection& aSelection ) override;
97         virtual css::awt::Selection SAL_CALL getSelection() override;
98         virtual sal_Bool        SAL_CALL isEditable() override;
99         virtual void            SAL_CALL setEditable( sal_Bool bEditable ) override;
100         virtual void            SAL_CALL setMaxTextLen( sal_Int16 nLength ) override;
101         virtual sal_Int16       SAL_CALL getMaxTextLen() override;
102 
103     // css::form::XBoundComponent
addUpdateListener(const css::uno::Reference<css::form::XUpdateListener> &)104         virtual void            SAL_CALL addUpdateListener(const css::uno::Reference< css::form::XUpdateListener > & /*l*/) override {}
removeUpdateListener(const css::uno::Reference<css::form::XUpdateListener> &)105         virtual void            SAL_CALL removeUpdateListener(const css::uno::Reference< css::form::XUpdateListener > & /*l*/) override {}
106         virtual sal_Bool        SAL_CALL commit() override;
107 
108     // css::lang::XEventListener
109         virtual void            SAL_CALL disposing(const css::lang::EventObject& Source) override;
110 
111     // css::awt::XFocusListener
112         virtual void            SAL_CALL focusGained(const css::awt::FocusEvent& e) override;
113         virtual void            SAL_CALL focusLost(const css::awt::FocusEvent& e) override;
114 
115     // css::awt::XItemListener
116         virtual void            SAL_CALL itemStateChanged(const css::awt::ItemEvent& rEvent) override;
117 
118     // css::util::XInitialization
119         virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
120 
121         // XServiceInfo
122         virtual OUString SAL_CALL getImplementationName(  ) override;
123         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
124         virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
125 
126     private:
127         virtual void PrepareWindowDescriptor( css::awt::WindowDescriptor& rDesc ) override;
128         virtual void ImplSetPeerProperty( const OUString& rPropName, const css::uno::Any& rVal ) override;
129 
130         bool ensureInitialized( );
131 
132         void displayException( const css::sdb::SQLContext& _rExcept );
133     };
134 
135 }   // namespace frm
136 
137 
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
139