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 #ifndef INCLUDED_SC_SOURCE_UI_INC_FILTDLG_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_FILTDLG_HXX
22 
23 #include <address.hxx>
24 #include "anyrefdg.hxx"
25 #include <queryparam.hxx>
26 #include <filterentries.hxx>
27 
28 #include <memory>
29 #include <deque>
30 #include <vector>
31 #include <map>
32 
33 class ScFilterOptionsMgr;
34 class ScViewData;
35 class ScDocument;
36 class ScQueryItem;
37 
38 class ScFilterDlg : public ScAnyRefDlgController
39 {
40     struct EntryList
41     {
42         ScFilterEntries maFilterEntries;
43         size_t mnHeaderPos;
44 
45         EntryList(const EntryList&) = delete;
46         const EntryList& operator=(const EntryList&) = delete;
47 
48         EntryList();
49     };
50     typedef std::map<SCCOL, std::unique_ptr<EntryList>> EntryListsMap;
51 public:
52     ScFilterDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
53                 const SfxItemSet& rArgSet);
54     virtual ~ScFilterDlg() override;
55 
56     virtual void    SetReference( const ScRange& rRef, ScDocument* pDoc ) override;
57 
58     virtual bool    IsRefInputMode() const override;
59     virtual void    SetActive() override;
60 
61     virtual void    Close() override;
62     void            SliderMoved();
63     size_t          GetSliderPos() const;
64     void            RefreshEditRow( size_t nOffset );
65 
66 private:
67     const OUString aStrUndefined;
68     const OUString aStrNone;
69 
70     const OUString aStrEmpty;
71     const OUString aStrNotEmpty;
72     const OUString aStrColumn;
73 
74     std::unique_ptr<ScFilterOptionsMgr> pOptionsMgr;
75 
76     const sal_uInt16        nWhichQuery;
77     ScQueryParam        theQueryData;
78     std::unique_ptr<ScQueryItem> pOutItem;
79     ScViewData*         pViewData;
80     ScDocument*         pDoc;
81     SCTAB               nSrcTab;
82 
83     std::vector<weld::ComboBox*> maValueEdArr;
84     std::vector<weld::ComboBox*> maFieldLbArr;
85     std::vector<weld::ComboBox*> maCondLbArr;
86     std::vector<weld::ComboBox*> maConnLbArr;
87 
88     std::deque<bool>   maHasDates;
89     std::deque<bool>   maRefreshExceptQuery;
90     bool                bRefInputMode;
91 
92     EntryListsMap m_EntryLists;
93 
94     // Hack: RefInput control
95     std::unique_ptr<Timer>  pTimer;
96 
97     std::unique_ptr<weld::ComboBox> m_xLbConnect1;
98     std::unique_ptr<weld::ComboBox> m_xLbField1;
99     std::unique_ptr<weld::ComboBox> m_xLbCond1;
100     std::unique_ptr<weld::ComboBox> m_xEdVal1;
101 
102     std::unique_ptr<weld::ComboBox> m_xLbConnect2;
103     std::unique_ptr<weld::ComboBox> m_xLbField2;
104     std::unique_ptr<weld::ComboBox> m_xLbCond2;
105     std::unique_ptr<weld::ComboBox> m_xEdVal2;
106 
107     std::unique_ptr<weld::ComboBox> m_xLbConnect3;
108     std::unique_ptr<weld::ComboBox> m_xLbField3;
109     std::unique_ptr<weld::ComboBox> m_xLbCond3;
110     std::unique_ptr<weld::ComboBox> m_xEdVal3;
111 
112     std::unique_ptr<weld::ComboBox> m_xLbConnect4;
113     std::unique_ptr<weld::ComboBox> m_xLbField4;
114     std::unique_ptr<weld::ComboBox> m_xLbCond4;
115     std::unique_ptr<weld::ComboBox> m_xEdVal4;
116 
117     std::unique_ptr<weld::Widget> m_xContents;
118     std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
119     std::unique_ptr<weld::Expander> m_xExpander;
120 
121     std::unique_ptr<weld::Button> m_xBtnOk;
122     std::unique_ptr<weld::Button> m_xBtnCancel;
123 
124     std::unique_ptr<weld::CheckButton> m_xBtnCase;
125     std::unique_ptr<weld::CheckButton> m_xBtnRegExp;
126     std::unique_ptr<weld::CheckButton> m_xBtnHeader;
127     std::unique_ptr<weld::CheckButton> m_xBtnUnique;
128     std::unique_ptr<weld::CheckButton> m_xBtnCopyResult;
129     std::unique_ptr<weld::ComboBox> m_xLbCopyArea;
130     std::unique_ptr<formula::RefEdit> m_xEdCopyArea;
131     std::unique_ptr<formula::RefButton> m_xRbCopyArea;
132     std::unique_ptr<weld::CheckButton> m_xBtnDestPers;
133     std::unique_ptr<weld::Label> m_xFtDbAreaLabel;
134     std::unique_ptr<weld::Label> m_xFtDbArea;
135 
136 private:
137     void            Init            ( const SfxItemSet& rArgSet );
138     void            FillFieldLists  ();
139     void            UpdateValueList ( size_t nList );
140     void            UpdateHdrInValueList( size_t nList );
141     void            ClearValueList  ( size_t nList );
142     size_t          GetFieldSelPos  ( SCCOL nField );
143     ScQueryItem*    GetOutputItem   ();
144 
145     // Handler:
146     DECL_LINK( LbSelectHdl,  weld::ComboBox&, void );
147     DECL_LINK( ValModifyHdl, weld::ComboBox&, void );
148     DECL_LINK( CheckBoxHdl,  weld::Button&, void );
149     DECL_LINK( EndDlgHdl,    weld::Button&, void );
150     DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
151     DECL_LINK( MoreExpandedHdl, weld::Expander&, void );
152 
153     // Hack: RefInput control
154     DECL_LINK( TimeOutHdl, Timer*, void );
155 };
156 
157 class ScSpecialFilterDlg : public ScAnyRefDlgController
158 {
159 public:
160     ScSpecialFilterDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
161                        const SfxItemSet& rArgSet);
162     virtual ~ScSpecialFilterDlg() override;
163 
164     virtual void    SetReference( const ScRange& rRef, ScDocument* pDoc ) override;
165 
166     virtual bool    IsRefInputMode() const override;
167     virtual void    SetActive() override;
168 
169     virtual void    Close() override;
170 
171 private:
172     const OUString aStrUndefined;
173 
174     std::unique_ptr<ScFilterOptionsMgr> pOptionsMgr;
175 
176     const sal_uInt16    nWhichQuery;
177     const ScQueryParam  theQueryData;
178     std::unique_ptr<ScQueryItem> pOutItem;
179     ScViewData*         pViewData;
180     ScDocument*         pDoc;
181 
182     bool                bRefInputMode;
183 
184     formula::RefEdit* m_pRefInputEdit;
185 
186     std::unique_ptr<weld::ComboBox> m_xLbFilterArea;
187     std::unique_ptr<formula::RefEdit> m_xEdFilterArea;
188     std::unique_ptr<formula::RefButton> m_xRbFilterArea;
189 
190     std::unique_ptr<weld::Expander> m_xExpander;
191     std::unique_ptr<weld::CheckButton> m_xBtnCase;
192     std::unique_ptr<weld::CheckButton> m_xBtnRegExp;
193     std::unique_ptr<weld::CheckButton> m_xBtnHeader;
194     std::unique_ptr<weld::CheckButton> m_xBtnUnique;
195     std::unique_ptr<weld::CheckButton> m_xBtnCopyResult;
196     std::unique_ptr<weld::ComboBox> m_xLbCopyArea;
197     std::unique_ptr<formula::RefEdit> m_xEdCopyArea;
198     std::unique_ptr<formula::RefButton> m_xRbCopyArea;
199     std::unique_ptr<weld::CheckButton> m_xBtnDestPers;
200     std::unique_ptr<weld::Label> m_xFtDbAreaLabel;
201     std::unique_ptr<weld::Label> m_xFtDbArea;
202 
203     std::unique_ptr<weld::Button> m_xBtnOk;
204     std::unique_ptr<weld::Button> m_xBtnCancel;
205 
206     std::unique_ptr<weld::Frame> m_xFilterFrame;
207     std::unique_ptr<weld::Label> m_xFilterLabel;
208 
209 private:
210     void            Init( const SfxItemSet& rArgSet );
211     ScQueryItem*    GetOutputItem( const ScQueryParam& rParam,
212                                     const ScRange& rSource );
213 
214     // Handler
215     DECL_LINK( FilterAreaSelHdl, weld::ComboBox&, void );
216     DECL_LINK( FilterAreaModHdl, formula::RefEdit&, void );
217     DECL_LINK( EndDlgHdl,  weld::Button&, void );
218 
219     // RefInput control
220     DECL_LINK( RefInputEditHdl, formula::RefEdit&, void );
221     DECL_LINK( RefInputButtonHdl, formula::RefButton&, void );
222     void RefInputHdl();
223 };
224 
225 #endif // INCLUDED_SC_SOURCE_UI_INC_FILTDLG_HXX
226 
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
228