/src/libreoffice/sc/source/ui/dbgui/filtdlg.cxx
Line | Count | Source |
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 | | #include <sfx2/dispatch.hxx> |
21 | | #include <sal/log.hxx> |
22 | | |
23 | | #include <uiitems.hxx> |
24 | | #include <reffact.hxx> |
25 | | #include <viewdata.hxx> |
26 | | #include <document.hxx> |
27 | | #include <docsh.hxx> |
28 | | #include <scresid.hxx> |
29 | | #include <queryentry.hxx> |
30 | | |
31 | | #include <foptmgr.hxx> |
32 | | |
33 | | #include <globstr.hrc> |
34 | | #include <strings.hrc> |
35 | | |
36 | | #include <filtdlg.hxx> |
37 | | #include <svx/colorwindow.hxx> |
38 | | #include <vcl/svapp.hxx> |
39 | | #include <vcl/settings.hxx> |
40 | | #include <vcl/virdev.hxx> |
41 | | #include <vcl/weld/weld.hxx> |
42 | | #include <svl/numformat.hxx> |
43 | | #include <svl/sharedstringpool.hxx> |
44 | | |
45 | | #include <limits> |
46 | | |
47 | 0 | #define QUERY_ENTRY_COUNT 4 |
48 | 0 | #define INVALID_HEADER_POS std::numeric_limits<size_t>::max() |
49 | | |
50 | | ScFilterDlg::EntryList::EntryList() : |
51 | 0 | mnHeaderPos(INVALID_HEADER_POS) {} |
52 | | |
53 | | ScFilterDlg::ScFilterDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, ScViewData& rData, |
54 | | const SfxItemSet& rArgSet) |
55 | 0 | : ScAnyRefDlgController(pB, pCW, pParent, |
56 | 0 | u"modules/scalc/ui/standardfilterdialog.ui"_ustr, u"StandardFilterDialog"_ustr) |
57 | 0 | , aStrUndefined(ScResId(SCSTR_UNDEFINED)) |
58 | 0 | , aStrNone(ScResId(SCSTR_NONE)) |
59 | 0 | , aStrEmpty(ScResId(SCSTR_FILTER_EMPTY)) |
60 | 0 | , aStrNotEmpty(ScResId(SCSTR_FILTER_NOTEMPTY)) |
61 | 0 | , aStrColumn(ScResId(SCSTR_COLUMN_LETTER)) |
62 | 0 | , aStrFontColor(ScResId(SCSTR_FILTER_FONT_COLOR_COND)) |
63 | 0 | , aStrBackgroundColor(ScResId(SCSTR_FILTER_BACKGROUND_COLOR_COND)) |
64 | 0 | , nWhichQuery(rArgSet.GetPool()->GetWhichIDFromSlotID(SID_QUERY)) |
65 | 0 | , theQueryData(static_cast<const ScQueryItem&>(rArgSet.Get(nWhichQuery)).GetQueryData()) |
66 | 0 | , rViewData(rData) |
67 | 0 | , rDoc(rViewData.GetDocument()) |
68 | 0 | , nSrcTab(rViewData.CurrentTabForData()) |
69 | 0 | , bRefInputMode(false) |
70 | 0 | , m_xLbConnect1(m_xBuilder->weld_combo_box(u"connect1"_ustr)) |
71 | 0 | , m_xLbField1(m_xBuilder->weld_combo_box(u"field1"_ustr)) |
72 | 0 | , m_xLbCond1(m_xBuilder->weld_combo_box(u"cond1"_ustr)) |
73 | 0 | , m_xEdVal1(m_xBuilder->weld_combo_box(u"val1"_ustr)) |
74 | 0 | , m_xLbColor1(m_xBuilder->weld_combo_box(u"color1"_ustr)) |
75 | 0 | , m_xBtnRemove1(m_xBuilder->weld_button(u"remove1"_ustr)) |
76 | 0 | , m_xLbConnect2(m_xBuilder->weld_combo_box(u"connect2"_ustr)) |
77 | 0 | , m_xLbField2(m_xBuilder->weld_combo_box(u"field2"_ustr)) |
78 | 0 | , m_xLbCond2(m_xBuilder->weld_combo_box(u"cond2"_ustr)) |
79 | 0 | , m_xEdVal2(m_xBuilder->weld_combo_box(u"val2"_ustr)) |
80 | 0 | , m_xLbColor2(m_xBuilder->weld_combo_box(u"color2"_ustr)) |
81 | 0 | , m_xBtnRemove2(m_xBuilder->weld_button(u"remove2"_ustr)) |
82 | 0 | , m_xLbConnect3(m_xBuilder->weld_combo_box(u"connect3"_ustr)) |
83 | 0 | , m_xLbField3(m_xBuilder->weld_combo_box(u"field3"_ustr)) |
84 | 0 | , m_xLbCond3(m_xBuilder->weld_combo_box(u"cond3"_ustr)) |
85 | 0 | , m_xEdVal3(m_xBuilder->weld_combo_box(u"val3"_ustr)) |
86 | 0 | , m_xLbColor3(m_xBuilder->weld_combo_box(u"color3"_ustr)) |
87 | 0 | , m_xBtnRemove3(m_xBuilder->weld_button(u"remove3"_ustr)) |
88 | 0 | , m_xLbConnect4(m_xBuilder->weld_combo_box(u"connect4"_ustr)) |
89 | 0 | , m_xLbField4(m_xBuilder->weld_combo_box(u"field4"_ustr)) |
90 | 0 | , m_xLbCond4(m_xBuilder->weld_combo_box(u"cond4"_ustr)) |
91 | 0 | , m_xEdVal4(m_xBuilder->weld_combo_box(u"val4"_ustr)) |
92 | 0 | , m_xLbColor4(m_xBuilder->weld_combo_box(u"color4"_ustr)) |
93 | 0 | , m_xBtnRemove4(m_xBuilder->weld_button(u"remove4"_ustr)) |
94 | 0 | , m_xContents(m_xBuilder->weld_widget(u"grid"_ustr)) |
95 | 0 | , m_xScrollBar(m_xBuilder->weld_scrolled_window(u"scrollbar"_ustr, true)) |
96 | 0 | , m_xExpander(m_xBuilder->weld_expander(u"more"_ustr)) |
97 | 0 | , m_xBtnClear(m_xBuilder->weld_button(u"clear"_ustr)) |
98 | 0 | , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr)) |
99 | 0 | , m_xBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr)) |
100 | 0 | , m_xBtnCase(m_xBuilder->weld_check_button(u"case"_ustr)) |
101 | 0 | , m_xBtnRegExp(m_xBuilder->weld_check_button(u"regexp"_ustr)) |
102 | 0 | , m_xBtnHeader(m_xBuilder->weld_check_button(u"header"_ustr)) |
103 | 0 | , m_xBtnUnique(m_xBuilder->weld_check_button(u"unique"_ustr)) |
104 | 0 | , m_xBtnCopyResult(m_xBuilder->weld_check_button(u"copyresult"_ustr)) |
105 | 0 | , m_xLbCopyArea(m_xBuilder->weld_combo_box(u"lbcopyarea"_ustr)) |
106 | 0 | , m_xEdCopyArea(new formula::RefEdit(m_xBuilder->weld_entry(u"edcopyarea"_ustr))) |
107 | 0 | , m_xRbCopyArea(new formula::RefButton(m_xBuilder->weld_button(u"rbcopyarea"_ustr))) |
108 | 0 | , m_xBtnDestPers(m_xBuilder->weld_check_button(u"destpers"_ustr)) |
109 | 0 | , m_xFtDbAreaLabel(m_xBuilder->weld_label(u"dbarealabel"_ustr)) |
110 | 0 | , m_xFtDbArea(m_xBuilder->weld_label(u"dbarea"_ustr)) |
111 | 0 | { |
112 | 0 | m_xExpander->connect_expanded(LINK(this, ScFilterDlg, MoreExpandedHdl)); |
113 | 0 | m_xEdCopyArea->SetReferences(this, m_xFtDbAreaLabel.get()); |
114 | 0 | m_xRbCopyArea->SetReferences(this, m_xEdCopyArea.get()); |
115 | |
|
116 | 0 | assert(m_xLbCond1->find_text(aStrFontColor) != -1); |
117 | 0 | assert(m_xLbCond1->find_text(aStrBackgroundColor) != -1); |
118 | |
|
119 | 0 | Init(); |
120 | | |
121 | | // Hack: RefInput control |
122 | 0 | pTimer.reset( new Timer("ScFilterTimer") ); |
123 | 0 | pTimer->SetTimeout( 50 ); // Wait 50ms |
124 | 0 | pTimer->SetInvokeHandler( LINK( this, ScFilterDlg, TimeOutHdl ) ); |
125 | 0 | } |
126 | | |
127 | | ScFilterDlg::~ScFilterDlg() |
128 | 0 | { |
129 | 0 | pOptionsMgr.reset(); |
130 | 0 | pOutItem.reset(); |
131 | | |
132 | | // Hack: RefInput control |
133 | 0 | pTimer->Stop(); |
134 | 0 | pTimer.reset(); |
135 | 0 | } |
136 | | |
137 | | namespace { |
138 | | VirtualDevice* lcl_getColorImage(const Color &rColor) |
139 | 0 | { |
140 | 0 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); |
141 | 0 | Size aImageSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize()); |
142 | |
|
143 | 0 | VclPtrInstance<VirtualDevice> xDevice; |
144 | 0 | xDevice->SetOutputSize(aImageSize); |
145 | 0 | const tools::Rectangle aRect(Point(0, 0), aImageSize); |
146 | 0 | if (rColor == COL_NONE_COLOR) |
147 | 0 | { |
148 | 0 | const Color aW(COL_WHITE); |
149 | 0 | const Color aG(0xef, 0xef, 0xef); |
150 | 0 | xDevice->DrawCheckered(aRect.TopLeft(), aRect.GetSize(), 8, aW, aG); |
151 | 0 | xDevice->SetFillColor(); |
152 | 0 | } |
153 | 0 | else |
154 | 0 | { |
155 | 0 | xDevice->SetFillColor(rColor); |
156 | 0 | } |
157 | |
|
158 | 0 | xDevice->DrawRect(aRect); |
159 | |
|
160 | 0 | return xDevice.get(); |
161 | 0 | } |
162 | | } |
163 | | |
164 | | void ScFilterDlg::Init() |
165 | 0 | { |
166 | 0 | m_xBtnClear->connect_clicked ( LINK( this, ScFilterDlg, BtnClearHdl ) ); |
167 | 0 | m_xBtnOk->connect_clicked ( LINK( this, ScFilterDlg, EndDlgHdl ) ); |
168 | 0 | m_xBtnCancel->connect_clicked ( LINK( this, ScFilterDlg, EndDlgHdl ) ); |
169 | 0 | m_xBtnHeader->connect_toggled ( LINK( this, ScFilterDlg, CheckBoxHdl ) ); |
170 | 0 | m_xBtnCase->connect_toggled ( LINK( this, ScFilterDlg, CheckBoxHdl ) ); |
171 | |
|
172 | 0 | m_xLbField1->connect_changed ( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
173 | 0 | m_xLbField2->connect_changed ( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
174 | 0 | m_xLbField3->connect_changed ( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
175 | 0 | m_xLbField4->connect_changed ( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
176 | 0 | m_xLbConnect1->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
177 | 0 | m_xLbConnect2->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
178 | 0 | m_xLbConnect3->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
179 | 0 | m_xLbConnect4->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
180 | |
|
181 | 0 | m_xLbField1->append_text(u"0000000000"_ustr); |
182 | 0 | m_xLbField1->set_active(0); |
183 | 0 | auto nPrefWidth = m_xLbField1->get_preferred_size().Width(); |
184 | 0 | m_xLbField1->clear(); |
185 | |
|
186 | 0 | m_xLbField1->set_size_request(nPrefWidth, -1); |
187 | 0 | m_xLbField2->set_size_request(nPrefWidth, -1); |
188 | 0 | m_xLbField3->set_size_request(nPrefWidth, -1); |
189 | 0 | m_xLbField4->set_size_request(nPrefWidth, -1); |
190 | |
|
191 | 0 | m_xLbCond1->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
192 | 0 | m_xLbCond2->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
193 | 0 | m_xLbCond3->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
194 | 0 | m_xLbCond4->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
195 | |
|
196 | 0 | m_xLbColor1->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
197 | 0 | m_xLbColor2->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
198 | 0 | m_xLbColor3->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
199 | 0 | m_xLbColor4->connect_changed( LINK( this, ScFilterDlg, LbSelectHdl ) ); |
200 | |
|
201 | 0 | m_xBtnRemove1->connect_clicked( LINK( this, ScFilterDlg, BtnRemoveHdl ) ); |
202 | 0 | m_xBtnRemove2->connect_clicked( LINK( this, ScFilterDlg, BtnRemoveHdl ) ); |
203 | 0 | m_xBtnRemove3->connect_clicked( LINK( this, ScFilterDlg, BtnRemoveHdl ) ); |
204 | 0 | m_xBtnRemove4->connect_clicked( LINK( this, ScFilterDlg, BtnRemoveHdl ) ); |
205 | | |
206 | | // for easier access: |
207 | 0 | maFieldLbArr.reserve(QUERY_ENTRY_COUNT); |
208 | 0 | maFieldLbArr.push_back(m_xLbField1.get()); |
209 | 0 | maFieldLbArr.push_back(m_xLbField2.get()); |
210 | 0 | maFieldLbArr.push_back(m_xLbField3.get()); |
211 | 0 | maFieldLbArr.push_back(m_xLbField4.get()); |
212 | 0 | maValueEdArr.reserve(QUERY_ENTRY_COUNT); |
213 | 0 | maValueEdArr.push_back(m_xEdVal1.get()); |
214 | 0 | maValueEdArr.push_back(m_xEdVal2.get()); |
215 | 0 | maValueEdArr.push_back(m_xEdVal3.get()); |
216 | 0 | maValueEdArr.push_back(m_xEdVal4.get()); |
217 | 0 | maCondLbArr.reserve(QUERY_ENTRY_COUNT); |
218 | 0 | maCondLbArr.push_back(m_xLbCond1.get()); |
219 | 0 | maCondLbArr.push_back(m_xLbCond2.get()); |
220 | 0 | maCondLbArr.push_back(m_xLbCond3.get()); |
221 | 0 | maCondLbArr.push_back(m_xLbCond4.get()); |
222 | 0 | maConnLbArr.reserve(QUERY_ENTRY_COUNT); |
223 | 0 | maConnLbArr.push_back(m_xLbConnect1.get()); |
224 | 0 | maConnLbArr.push_back(m_xLbConnect2.get()); |
225 | 0 | maConnLbArr.push_back(m_xLbConnect3.get()); |
226 | 0 | maConnLbArr.push_back(m_xLbConnect4.get()); |
227 | 0 | maColorLbArr.reserve(QUERY_ENTRY_COUNT); |
228 | 0 | maColorLbArr.push_back(m_xLbColor1.get()); |
229 | 0 | maColorLbArr.push_back(m_xLbColor2.get()); |
230 | 0 | maColorLbArr.push_back(m_xLbColor3.get()); |
231 | 0 | maColorLbArr.push_back(m_xLbColor4.get()); |
232 | 0 | maRemoveBtnArr.reserve(QUERY_ENTRY_COUNT); |
233 | 0 | maRemoveBtnArr.push_back(m_xBtnRemove1.get()); |
234 | 0 | maRemoveBtnArr.push_back(m_xBtnRemove2.get()); |
235 | 0 | maRemoveBtnArr.push_back(m_xBtnRemove3.get()); |
236 | 0 | maRemoveBtnArr.push_back(m_xBtnRemove4.get()); |
237 | | |
238 | | // Option initialization: |
239 | 0 | pOptionsMgr.reset( new ScFilterOptionsMgr( |
240 | 0 | rViewData, |
241 | 0 | theQueryData, |
242 | 0 | m_xBtnCase.get(), |
243 | 0 | m_xBtnRegExp.get(), |
244 | 0 | m_xBtnHeader.get(), |
245 | 0 | m_xBtnUnique.get(), |
246 | 0 | m_xBtnCopyResult.get(), |
247 | 0 | m_xBtnDestPers.get(), |
248 | 0 | m_xLbCopyArea.get(), |
249 | 0 | m_xEdCopyArea.get(), |
250 | 0 | m_xRbCopyArea.get(), |
251 | 0 | m_xFtDbAreaLabel.get(), |
252 | 0 | m_xFtDbArea.get(), |
253 | 0 | aStrUndefined ) ); |
254 | | // Read in field lists and select entries |
255 | |
|
256 | 0 | FillFieldLists(); |
257 | |
|
258 | 0 | for (size_t i = 0; i < QUERY_ENTRY_COUNT; ++i) |
259 | 0 | { |
260 | 0 | OUString aValStr; |
261 | 0 | size_t nCondPos = 0; |
262 | 0 | size_t nFieldSelPos = 0; |
263 | |
|
264 | 0 | maColorLbArr[i]->set_visible(false); |
265 | |
|
266 | 0 | ScQueryEntry& rEntry = theQueryData.GetEntry(i); |
267 | 0 | if ( rEntry.bDoQuery ) |
268 | 0 | { |
269 | 0 | nCondPos = static_cast<size_t>(rEntry.eOp); |
270 | 0 | nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) ); |
271 | 0 | if (rEntry.IsQueryByEmpty()) |
272 | 0 | { |
273 | 0 | aValStr = aStrEmpty; |
274 | 0 | maCondLbArr[i]->set_sensitive(false); |
275 | 0 | } |
276 | 0 | else if (rEntry.IsQueryByNonEmpty()) |
277 | 0 | { |
278 | 0 | aValStr = aStrNotEmpty; |
279 | 0 | maCondLbArr[i]->set_sensitive(false); |
280 | 0 | } |
281 | 0 | else if (rEntry.IsQueryByTextColor() || rEntry.IsQueryByBackgroundColor()) |
282 | 0 | { |
283 | 0 | nCondPos = maCondLbArr[i]->find_text( |
284 | 0 | rEntry.IsQueryByTextColor() ? aStrFontColor : aStrBackgroundColor); |
285 | 0 | maValueEdArr[i]->set_visible(false); |
286 | 0 | maColorLbArr[i]->set_visible(true); |
287 | 0 | maColorLbArr[i]->set_sensitive(true); |
288 | 0 | } |
289 | 0 | else |
290 | 0 | { |
291 | 0 | const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); |
292 | 0 | OUString aQueryStr = rItem.maString.getString(); |
293 | 0 | SetValString(aQueryStr, rItem, aValStr); |
294 | 0 | } |
295 | 0 | } |
296 | 0 | else if ( i == 0 ) |
297 | 0 | { |
298 | 0 | nFieldSelPos = GetFieldSelPos(rViewData.GetCurX()); |
299 | 0 | rEntry.nField = nFieldSelPos ? (theQueryData.nCol1 + |
300 | 0 | static_cast<SCCOL>(nFieldSelPos) - 1) : static_cast<SCCOL>(0); |
301 | 0 | rEntry.bDoQuery=true; |
302 | 0 | if (maRefreshExceptQuery.size() < i + 1) |
303 | 0 | maRefreshExceptQuery.resize(i + 1, false); |
304 | 0 | maRefreshExceptQuery[i] = true; |
305 | |
|
306 | 0 | } |
307 | 0 | maFieldLbArr[i]->set_active( nFieldSelPos ); |
308 | 0 | maCondLbArr [i]->set_active( nCondPos ); |
309 | 0 | maValueEdArr[i]->set_entry_text( aValStr ); |
310 | 0 | maValueEdArr[i]->set_entry_completion(false); |
311 | 0 | maValueEdArr[i]->connect_changed( LINK( this, ScFilterDlg, ValModifyHdl ) ); |
312 | 0 | UpdateValueList(i+1); |
313 | 0 | UpdateColorList(i+1); |
314 | 0 | } |
315 | |
|
316 | 0 | m_xScrollBar->connect_vadjustment_value_changed( LINK( this, ScFilterDlg, ScrollHdl ) ); |
317 | 0 | m_xScrollBar->vadjustment_configure(0, 8, 1, 3, 4); |
318 | 0 | Size aSize(m_xContents->get_preferred_size()); |
319 | 0 | m_xContents->set_size_request(aSize.Width(), aSize.Height()); |
320 | |
|
321 | 0 | m_xLbConnect1->hide(); |
322 | | // Disable/Enable Logic: |
323 | |
|
324 | 0 | (m_xLbField1->get_active() != 0) |
325 | 0 | && (m_xLbField2->get_active() != 0) |
326 | 0 | ? m_xLbConnect2->set_active( static_cast<sal_uInt16>(theQueryData.GetEntry(1).eConnect) ) |
327 | 0 | : m_xLbConnect2->set_active(-1); |
328 | |
|
329 | 0 | (m_xLbField2->get_active() != 0) |
330 | 0 | && (m_xLbField3->get_active() != 0) |
331 | 0 | ? m_xLbConnect3->set_active( static_cast<sal_uInt16>(theQueryData.GetEntry(2).eConnect) ) |
332 | 0 | : m_xLbConnect3->set_active(-1); |
333 | |
|
334 | 0 | (m_xLbField3->get_active() != 0) |
335 | 0 | && (m_xLbField4->get_active() != 0) |
336 | 0 | ? m_xLbConnect4->set_active( static_cast<sal_uInt16>(theQueryData.GetEntry(3).eConnect) ) |
337 | 0 | : m_xLbConnect4->set_active(-1); |
338 | 0 | if ( m_xLbField1->get_active() == 0 ) |
339 | 0 | { |
340 | 0 | m_xLbConnect2->set_sensitive(false); |
341 | 0 | m_xLbField2->set_sensitive(false); |
342 | 0 | m_xLbCond2->set_sensitive(false); |
343 | 0 | m_xEdVal2->set_sensitive(false); |
344 | 0 | m_xLbColor2->set_sensitive(false); |
345 | 0 | m_xBtnRemove2->set_sensitive(false); |
346 | 0 | } |
347 | 0 | else if ( m_xLbConnect2->get_active() == -1 ) |
348 | 0 | { |
349 | 0 | m_xLbField2->set_sensitive(false); |
350 | 0 | m_xLbCond2->set_sensitive(false); |
351 | 0 | m_xEdVal2->set_sensitive(false); |
352 | 0 | m_xLbColor2->set_sensitive(false); |
353 | 0 | m_xBtnRemove2->set_sensitive(false); |
354 | 0 | } |
355 | |
|
356 | 0 | if ( m_xLbField2->get_active() == 0 ) |
357 | 0 | { |
358 | 0 | m_xLbConnect3->set_sensitive(false); |
359 | 0 | m_xLbField3->set_sensitive(false); |
360 | 0 | m_xLbCond3->set_sensitive(false); |
361 | 0 | m_xEdVal3->set_sensitive(false); |
362 | 0 | m_xLbColor3->set_sensitive(false); |
363 | 0 | m_xBtnRemove3->set_sensitive(false); |
364 | 0 | } |
365 | 0 | else if ( m_xLbConnect3->get_active() == -1 ) |
366 | 0 | { |
367 | 0 | m_xLbField3->set_sensitive(false); |
368 | 0 | m_xLbCond3->set_sensitive(false); |
369 | 0 | m_xEdVal3->set_sensitive(false); |
370 | 0 | m_xLbColor3->set_sensitive(false); |
371 | 0 | m_xBtnRemove3->set_sensitive(false); |
372 | 0 | } |
373 | 0 | if ( m_xLbField3->get_active() == 0 ) |
374 | 0 | { |
375 | 0 | m_xLbConnect4->set_sensitive(false); |
376 | 0 | m_xLbField4->set_sensitive(false); |
377 | 0 | m_xLbCond4->set_sensitive(false); |
378 | 0 | m_xEdVal4->set_sensitive(false); |
379 | 0 | m_xLbColor4->set_sensitive(false); |
380 | 0 | m_xBtnRemove4->set_sensitive(false); |
381 | 0 | } |
382 | 0 | else if ( m_xLbConnect4->get_active() == -1 ) |
383 | 0 | { |
384 | 0 | m_xLbField4->set_sensitive(false); |
385 | 0 | m_xLbCond4->set_sensitive(false); |
386 | 0 | m_xEdVal4->set_sensitive(false); |
387 | 0 | m_xLbColor4->set_sensitive(false); |
388 | 0 | m_xBtnRemove4->set_sensitive(false); |
389 | 0 | } |
390 | |
|
391 | 0 | m_xEdVal1->set_entry_width_chars(10); |
392 | 0 | m_xEdVal2->set_entry_width_chars(10); |
393 | 0 | m_xEdVal3->set_entry_width_chars(10); |
394 | 0 | m_xEdVal4->set_entry_width_chars(10); |
395 | |
|
396 | 0 | if (rDoc.GetChangeTrack() != nullptr) |
397 | 0 | m_xBtnCopyResult->set_sensitive(false); |
398 | 0 | } |
399 | | |
400 | | void ScFilterDlg::Close() |
401 | 0 | { |
402 | 0 | rViewData.GetDocShell()->CancelAutoDBRange(); |
403 | |
|
404 | 0 | DoClose( ScFilterDlgWrapper::GetChildWindowId() ); |
405 | 0 | } |
406 | | |
407 | | // Mouse-selected cell area becomes the new selection and is shown in the |
408 | | // reference text box |
409 | | |
410 | | void ScFilterDlg::SetReference( const ScRange& rRef, ScDocument& rDocP ) |
411 | 0 | { |
412 | 0 | if ( bRefInputMode ) // Only possible if in reference edit mode |
413 | 0 | { |
414 | 0 | if ( rRef.aStart != rRef.aEnd ) |
415 | 0 | RefInputStart( m_xEdCopyArea.get() ); |
416 | 0 | OUString aRefStr(rRef.aStart.Format(ScRefFlags::ADDR_ABS_3D, &rDocP, rDocP.GetAddressConvention())); |
417 | 0 | m_xEdCopyArea->SetRefString( aRefStr ); |
418 | 0 | } |
419 | 0 | } |
420 | | |
421 | | void ScFilterDlg::SetActive() |
422 | 0 | { |
423 | 0 | if ( bRefInputMode ) |
424 | 0 | { |
425 | 0 | m_xEdCopyArea->GrabFocus(); |
426 | 0 | m_xEdCopyArea->GetModifyHdl().Call( *m_xEdCopyArea ); |
427 | 0 | } |
428 | 0 | else |
429 | 0 | m_xDialog->grab_focus(); |
430 | |
|
431 | 0 | RefInputDone(); |
432 | 0 | } |
433 | | |
434 | | void ScFilterDlg::FillFieldLists() |
435 | 0 | { |
436 | 0 | m_xLbField1->freeze(); |
437 | 0 | m_xLbField2->freeze(); |
438 | 0 | m_xLbField3->freeze(); |
439 | 0 | m_xLbField4->freeze(); |
440 | |
|
441 | 0 | m_xLbField1->clear(); |
442 | 0 | m_xLbField2->clear(); |
443 | 0 | m_xLbField3->clear(); |
444 | 0 | m_xLbField4->clear(); |
445 | 0 | m_xLbField1->append_text( aStrNone ); |
446 | 0 | m_xLbField2->append_text( aStrNone ); |
447 | 0 | m_xLbField3->append_text( aStrNone ); |
448 | 0 | m_xLbField4->append_text( aStrNone ); |
449 | |
|
450 | 0 | OUString aFieldName; |
451 | 0 | SCTAB nTab = nSrcTab; |
452 | 0 | SCCOL nFirstCol = theQueryData.nCol1; |
453 | 0 | SCROW nFirstRow = theQueryData.nRow1; |
454 | 0 | SCCOL nMaxCol = theQueryData.nCol2; |
455 | 0 | SCCOL col = 0; |
456 | |
|
457 | 0 | for ( col=nFirstCol; col<=nMaxCol; col++ ) |
458 | 0 | { |
459 | 0 | aFieldName = rDoc.GetString(col, nFirstRow, nTab); |
460 | 0 | if (!m_xBtnHeader->get_active() || aFieldName.isEmpty()) |
461 | 0 | { |
462 | 0 | aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, u"%1", ScColToAlpha( col )); |
463 | 0 | } |
464 | 0 | m_xLbField1->append_text( aFieldName ); |
465 | 0 | m_xLbField2->append_text( aFieldName ); |
466 | 0 | m_xLbField3->append_text( aFieldName ); |
467 | 0 | m_xLbField4->append_text( aFieldName ); |
468 | 0 | } |
469 | |
|
470 | 0 | m_xLbField4->thaw(); |
471 | 0 | m_xLbField3->thaw(); |
472 | 0 | m_xLbField2->thaw(); |
473 | 0 | m_xLbField1->thaw(); |
474 | 0 | } |
475 | | |
476 | | void ScFilterDlg::UpdateValueList( size_t nList ) |
477 | 0 | { |
478 | 0 | bool bCaseSens = m_xBtnCase->get_active(); |
479 | |
|
480 | 0 | if (nList > 0 && nList <= QUERY_ENTRY_COUNT) |
481 | 0 | { |
482 | 0 | weld::ComboBox* pValList = maValueEdArr[nList-1]; |
483 | 0 | const sal_Int32 nFieldSelPos = maFieldLbArr[nList-1]->get_active(); |
484 | 0 | OUString aCurValue = pValList->get_active_text(); |
485 | |
|
486 | 0 | std::unique_ptr<weld::WaitObject> xWaiter; |
487 | 0 | std::vector<weld::ComboBoxEntry> aEntries; |
488 | 0 | aEntries.emplace_back(aStrNotEmpty); |
489 | 0 | aEntries.emplace_back(aStrEmpty); |
490 | |
|
491 | 0 | if (nFieldSelPos) |
492 | 0 | { |
493 | 0 | xWaiter.reset(new weld::WaitObject(m_xDialog.get())); // even if only the list box has content |
494 | 0 | SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; |
495 | 0 | EntryList* pList = nullptr; |
496 | 0 | if (!m_EntryLists.count(nColumn)) |
497 | 0 | { |
498 | 0 | size_t nOffset = GetSliderPos(); |
499 | 0 | SCTAB nTab = nSrcTab; |
500 | 0 | SCROW nFirstRow = theQueryData.nRow1; |
501 | 0 | SCROW nLastRow = theQueryData.nRow2; |
502 | 0 | if (maHasDates.size() < nOffset+nList) |
503 | 0 | maHasDates.resize(nOffset+nList, false); |
504 | 0 | maHasDates[nOffset+nList-1] = false; |
505 | | |
506 | | // first without the first line |
507 | 0 | std::pair<EntryListsMap::iterator, bool> r = |
508 | 0 | m_EntryLists.insert(std::make_pair(nColumn, std::make_unique<EntryList>())); |
509 | 0 | if (!r.second) |
510 | | // insertion failed. |
511 | 0 | return; |
512 | | |
513 | 0 | pList = r.first->second.get(); |
514 | 0 | rDoc.GetFilterEntriesArea( |
515 | 0 | nColumn, nFirstRow+1, nLastRow, |
516 | 0 | nTab, bCaseSens, pList->maFilterEntries); |
517 | 0 | maHasDates[nOffset+nList-1] = pList->maFilterEntries.mbHasDates; |
518 | | |
519 | | // Entry for the first line |
520 | | //! Entry (pHdrEntry) doesn't generate collection? |
521 | |
|
522 | 0 | pList->mnHeaderPos = INVALID_HEADER_POS; |
523 | 0 | ScFilterEntries aHdrColl; |
524 | 0 | rDoc.GetFilterEntriesArea( |
525 | 0 | nColumn, nFirstRow, nFirstRow, nTab, true, aHdrColl ); |
526 | 0 | if (!aHdrColl.empty()) |
527 | 0 | { |
528 | | // See if the header value is already in the list. |
529 | 0 | std::vector<ScTypedStrData>::iterator itBeg = pList->maFilterEntries.begin(), itEnd = pList->maFilterEntries.end(); |
530 | 0 | if (std::none_of(itBeg, itEnd, FindTypedStrData(aHdrColl.front(), bCaseSens))) |
531 | 0 | { |
532 | | // Not in the list. Insert it. |
533 | 0 | pList->maFilterEntries.push_back(aHdrColl.front()); |
534 | 0 | if (bCaseSens) |
535 | 0 | std::sort(pList->maFilterEntries.begin(), pList->maFilterEntries.end(), ScTypedStrData::LessCaseSensitive()); |
536 | 0 | else |
537 | 0 | std::sort(pList->maFilterEntries.begin(), pList->maFilterEntries.end(), ScTypedStrData::LessCaseInsensitive()); |
538 | | |
539 | | // Record its position. |
540 | 0 | itBeg = pList->maFilterEntries.begin(); |
541 | 0 | itEnd = pList->maFilterEntries.end(); |
542 | 0 | auto it = std::find_if(itBeg, itEnd, FindTypedStrData(aHdrColl.front(), bCaseSens)); |
543 | 0 | pList->mnHeaderPos = std::distance(itBeg, it); |
544 | 0 | } |
545 | 0 | } |
546 | 0 | } |
547 | 0 | else |
548 | 0 | pList = m_EntryLists[nColumn].get(); |
549 | | |
550 | 0 | assert(pList); |
551 | |
|
552 | 0 | for (const auto& rEntry : pList->maFilterEntries) |
553 | 0 | aEntries.emplace_back(rEntry.GetString()); |
554 | 0 | } |
555 | 0 | pValList->insert_vector(aEntries, false); |
556 | 0 | pValList->set_entry_text(aCurValue); |
557 | 0 | } |
558 | | |
559 | 0 | UpdateHdrInValueList( nList ); |
560 | 0 | } |
561 | | |
562 | | void ScFilterDlg::UpdateHdrInValueList( size_t nList ) |
563 | 0 | { |
564 | | //! GetText / SetText ?? |
565 | |
|
566 | 0 | if (nList == 0 || nList > QUERY_ENTRY_COUNT) |
567 | 0 | return; |
568 | | |
569 | 0 | size_t nFieldSelPos = maFieldLbArr[nList-1]->get_active(); |
570 | 0 | if (!nFieldSelPos) |
571 | 0 | return; |
572 | | |
573 | 0 | SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; |
574 | 0 | if (!m_EntryLists.count(nColumn)) |
575 | 0 | { |
576 | 0 | OSL_FAIL("column not yet initialized"); |
577 | 0 | return; |
578 | 0 | } |
579 | | |
580 | 0 | size_t const nPos = m_EntryLists[nColumn]->mnHeaderPos; |
581 | 0 | if (nPos == INVALID_HEADER_POS) |
582 | 0 | return; |
583 | | |
584 | 0 | weld::ComboBox* pValList = maValueEdArr[nList-1]; |
585 | 0 | int nListPos = nPos + 2; // for "empty" and "non-empty" |
586 | |
|
587 | 0 | const ScTypedStrData& rHdrEntry = m_EntryLists[nColumn]->maFilterEntries.maStrData[nPos]; |
588 | |
|
589 | 0 | const OUString& aHdrStr = rHdrEntry.GetString(); |
590 | 0 | bool bWasThere = nListPos < pValList->get_count() && aHdrStr == pValList->get_text(nListPos); |
591 | 0 | bool bInclude = !m_xBtnHeader->get_active(); |
592 | |
|
593 | 0 | if (bInclude) // Include entry |
594 | 0 | { |
595 | 0 | if (!bWasThere) |
596 | 0 | pValList->insert_text(nListPos, aHdrStr); |
597 | 0 | } |
598 | 0 | else // Omit entry |
599 | 0 | { |
600 | 0 | if (bWasThere) |
601 | 0 | pValList->remove(nListPos); |
602 | 0 | } |
603 | 0 | } |
604 | | |
605 | | void ScFilterDlg::ClearValueList( size_t nList ) |
606 | 0 | { |
607 | 0 | if (nList > 0 && nList <= QUERY_ENTRY_COUNT) |
608 | 0 | { |
609 | 0 | weld::ComboBox* pValList = maValueEdArr[nList-1]; |
610 | 0 | pValList->clear(); |
611 | 0 | pValList->append_text( aStrNotEmpty ); |
612 | 0 | pValList->append_text( aStrEmpty ); |
613 | 0 | pValList->set_entry_text( OUString() ); |
614 | 0 | } |
615 | 0 | } |
616 | | |
617 | | void ScFilterDlg::UpdateColorList(size_t nList) |
618 | 0 | { |
619 | 0 | if (nList <= 0 || nList > QUERY_ENTRY_COUNT) |
620 | 0 | return; |
621 | | |
622 | 0 | size_t nPos = nList - 1; |
623 | 0 | ScQueryEntry& rEntry = theQueryData.GetEntry(nPos); |
624 | 0 | const sal_Int32 nFieldSelPos = maFieldLbArr[nPos]->get_active(); |
625 | 0 | if (!nFieldSelPos) |
626 | 0 | return; |
627 | | |
628 | 0 | SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; |
629 | 0 | EntryList* pList = m_EntryLists[nColumn].get(); |
630 | 0 | if (!pList) |
631 | 0 | return; |
632 | | |
633 | 0 | std::set<Color> aColors; |
634 | 0 | OUString sSelectedCondition = maCondLbArr[nPos]->get_active_text(); |
635 | 0 | if (sSelectedCondition == aStrFontColor) |
636 | 0 | aColors = pList->maFilterEntries.getTextColors(); |
637 | 0 | else if (sSelectedCondition == aStrBackgroundColor) |
638 | 0 | aColors = pList->maFilterEntries.getBackgroundColors(); |
639 | 0 | else |
640 | 0 | return; |
641 | | |
642 | 0 | maColorLbArr[nPos]->clear(); |
643 | 0 | for (const auto& rColor : aColors) |
644 | 0 | { |
645 | 0 | OUString sId = rColor.AsRGBHexString(); |
646 | 0 | if (rColor == COL_AUTO) |
647 | 0 | { |
648 | 0 | OUString sText = sSelectedCondition == aStrFontColor |
649 | 0 | ? ScResId(SCSTR_FILTER_AUTOMATIC_COLOR) |
650 | 0 | : ScResId(SCSTR_FILTER_NO_FILL); |
651 | 0 | maColorLbArr[nPos]->append(sId, sText); |
652 | 0 | } |
653 | 0 | else |
654 | 0 | { |
655 | 0 | VirtualDevice* pDev = lcl_getColorImage(rColor); |
656 | 0 | maColorLbArr[nPos]->append(sId, OUString(), *pDev); |
657 | 0 | } |
658 | |
|
659 | 0 | const auto& rItem = rEntry.GetQueryItem(); |
660 | 0 | if (rItem.maColor == rColor |
661 | 0 | && ((sSelectedCondition == aStrFontColor && rItem.meType == ScQueryEntry::ByTextColor) |
662 | 0 | || (sSelectedCondition == aStrBackgroundColor |
663 | 0 | && rItem.meType == ScQueryEntry::ByBackgroundColor))) |
664 | 0 | { |
665 | 0 | maColorLbArr[nPos]->set_active_id(sId); |
666 | 0 | } |
667 | 0 | } |
668 | 0 | } |
669 | | |
670 | | size_t ScFilterDlg::GetFieldSelPos( SCCOL nField ) |
671 | 0 | { |
672 | 0 | if ( nField >= theQueryData.nCol1 && nField <= theQueryData.nCol2 ) |
673 | 0 | return static_cast<size_t>(nField) - theQueryData.nCol1 + 1; |
674 | 0 | else |
675 | 0 | return 0; |
676 | 0 | } |
677 | | |
678 | | ScQueryItem* ScFilterDlg::GetOutputItem() |
679 | 0 | { |
680 | 0 | ScAddress theCopyPos; |
681 | 0 | ScQueryParam theParam( theQueryData ); |
682 | 0 | bool bCopyPosOk = false; |
683 | |
|
684 | 0 | if ( m_xBtnCopyResult->get_active() ) |
685 | 0 | { |
686 | 0 | ScRefFlags nResult = theCopyPos.Parse( |
687 | 0 | m_xEdCopyArea->GetText(), rDoc, rDoc.GetAddressConvention()); |
688 | 0 | bCopyPosOk = (nResult & ScRefFlags::VALID) == ScRefFlags::VALID; |
689 | 0 | } |
690 | |
|
691 | 0 | if ( m_xBtnCopyResult->get_active() && bCopyPosOk ) |
692 | 0 | { |
693 | 0 | theParam.bInplace = false; |
694 | 0 | theParam.nDestTab = theCopyPos.Tab(); |
695 | 0 | theParam.nDestCol = theCopyPos.Col(); |
696 | 0 | theParam.nDestRow = theCopyPos.Row(); |
697 | 0 | } |
698 | 0 | else |
699 | 0 | { |
700 | 0 | theParam.bInplace = true; |
701 | 0 | theParam.nDestTab = 0; |
702 | 0 | theParam.nDestCol = 0; |
703 | 0 | theParam.nDestRow = 0; |
704 | 0 | } |
705 | |
|
706 | 0 | theParam.bHasHeader = m_xBtnHeader->get_active(); |
707 | 0 | theParam.bByRow = true; |
708 | 0 | theParam.bDuplicate = !m_xBtnUnique->get_active(); |
709 | 0 | theParam.bCaseSens = m_xBtnCase->get_active(); |
710 | 0 | theParam.eSearchType = m_xBtnRegExp->get_active() ? utl::SearchParam::SearchType::Regexp : utl::SearchParam::SearchType::Normal; |
711 | 0 | theParam.bDestPers = m_xBtnDestPers->get_active(); |
712 | | |
713 | | // only set the three - reset everything else |
714 | |
|
715 | 0 | pOutItem.reset( new ScQueryItem( nWhichQuery, &theParam ) ); |
716 | |
|
717 | 0 | return pOutItem.get(); |
718 | 0 | } |
719 | | |
720 | | bool ScFilterDlg::IsRefInputMode() const |
721 | 0 | { |
722 | 0 | return bRefInputMode; |
723 | 0 | } |
724 | | |
725 | | // Handler: |
726 | | |
727 | | IMPL_LINK( ScFilterDlg, BtnClearHdl, weld::Button&, rBtn, void ) |
728 | 0 | { |
729 | 0 | if ( &rBtn != m_xBtnClear.get() ) |
730 | 0 | return; |
731 | | |
732 | | // scroll to the top |
733 | 0 | m_xScrollBar->vadjustment_set_value(0); |
734 | 0 | size_t nOffset = 0; |
735 | 0 | RefreshEditRow( nOffset); |
736 | | |
737 | | // clear all conditions |
738 | 0 | m_xLbConnect1->set_active(-1); |
739 | 0 | m_xLbConnect2->set_active(-1); |
740 | 0 | m_xLbConnect3->set_active(-1); |
741 | 0 | m_xLbConnect4->set_active(-1); |
742 | 0 | m_xLbField1->set_active(0); |
743 | 0 | m_xLbField2->set_active(0); |
744 | 0 | m_xLbField3->set_active(0); |
745 | 0 | m_xLbField4->set_active(0); |
746 | 0 | m_xLbCond1->set_active(0); |
747 | 0 | m_xLbCond2->set_active(0); |
748 | 0 | m_xLbCond3->set_active(0); |
749 | 0 | m_xLbCond4->set_active(0); |
750 | 0 | ClearValueList( 1 ); |
751 | 0 | ClearValueList( 2 ); |
752 | 0 | ClearValueList( 3 ); |
753 | 0 | ClearValueList( 4 ); |
754 | | |
755 | | // disable fields for second row onward |
756 | 0 | m_xLbConnect2->set_sensitive(false); |
757 | 0 | m_xLbConnect3->set_sensitive(false); |
758 | 0 | m_xLbConnect4->set_sensitive(false); |
759 | 0 | m_xLbField2->set_sensitive(false); |
760 | 0 | m_xLbField3->set_sensitive(false); |
761 | 0 | m_xLbField4->set_sensitive(false); |
762 | 0 | m_xLbCond2->set_sensitive(false); |
763 | 0 | m_xLbCond3->set_sensitive(false); |
764 | 0 | m_xLbCond4->set_sensitive(false); |
765 | 0 | m_xEdVal2->set_sensitive(false); |
766 | 0 | m_xEdVal3->set_sensitive(false); |
767 | 0 | m_xEdVal4->set_sensitive(false); |
768 | 0 | m_xLbColor2->set_sensitive(false); |
769 | 0 | m_xLbColor3->set_sensitive(false); |
770 | 0 | m_xLbColor4->set_sensitive(false); |
771 | 0 | m_xBtnRemove2->set_sensitive(false); |
772 | 0 | m_xBtnRemove3->set_sensitive(false); |
773 | 0 | m_xBtnRemove4->set_sensitive(false); |
774 | | |
775 | | // clear query data objects |
776 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
777 | 0 | if (maRefreshExceptQuery.size() < nCount + 1) |
778 | 0 | maRefreshExceptQuery.resize(nCount + 1, false); |
779 | 0 | for (SCSIZE i = 0; i < nCount; ++i) |
780 | 0 | { |
781 | 0 | theQueryData.GetEntry(i).bDoQuery = false; |
782 | 0 | maRefreshExceptQuery[i] = false; |
783 | 0 | theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0); |
784 | 0 | } |
785 | 0 | maRefreshExceptQuery[0] = true; |
786 | 0 | } |
787 | | |
788 | | IMPL_LINK( ScFilterDlg, EndDlgHdl, weld::Button&, rBtn, void ) |
789 | 0 | { |
790 | 0 | if ( &rBtn == m_xBtnOk.get() ) |
791 | 0 | { |
792 | 0 | bool bAreaInputOk = true; |
793 | |
|
794 | 0 | if ( m_xBtnCopyResult->get_active() ) |
795 | 0 | { |
796 | 0 | if ( !pOptionsMgr->VerifyPosStr( m_xEdCopyArea->GetText() ) ) |
797 | 0 | { |
798 | 0 | if (!m_xExpander->get_expanded()) |
799 | 0 | m_xExpander->set_expanded(true); |
800 | |
|
801 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), |
802 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
803 | 0 | ScResId(STR_INVALID_TABREF))); |
804 | 0 | xBox->run(); |
805 | 0 | m_xEdCopyArea->GrabFocus(); |
806 | 0 | bAreaInputOk = false; |
807 | 0 | } |
808 | 0 | } |
809 | |
|
810 | 0 | if ( bAreaInputOk ) |
811 | 0 | { |
812 | 0 | SetDispatcherLock( false ); |
813 | 0 | SwitchToDocument(); |
814 | 0 | GetBindings().GetDispatcher()->ExecuteList(FID_FILTER_OK, |
815 | 0 | SfxCallMode::SLOT | SfxCallMode::RECORD, |
816 | 0 | { GetOutputItem() }); |
817 | 0 | response(RET_OK); |
818 | 0 | } |
819 | 0 | } |
820 | 0 | else if ( &rBtn == m_xBtnCancel.get() ) |
821 | 0 | { |
822 | 0 | response(RET_CANCEL); |
823 | 0 | } |
824 | 0 | } |
825 | | |
826 | | IMPL_LINK_NOARG(ScFilterDlg, MoreExpandedHdl, weld::Expander&, void) |
827 | 0 | { |
828 | 0 | if ( m_xExpander->get_expanded() ) |
829 | 0 | pTimer->Start(); |
830 | 0 | else |
831 | 0 | { |
832 | 0 | pTimer->Stop(); |
833 | 0 | bRefInputMode = false; |
834 | | //@BugID 54702 Enable/disable only in Basic class |
835 | | //SFX_APPWINDOW->Disable(FALSE); //! general method in ScAnyRefDlg |
836 | 0 | } |
837 | 0 | } |
838 | | |
839 | | IMPL_LINK( ScFilterDlg, TimeOutHdl, Timer*, _pTimer, void ) |
840 | 0 | { |
841 | | // Check if RefInputMode is still true every 50ms |
842 | 0 | if (_pTimer == pTimer.get() && m_xDialog->has_toplevel_focus()) |
843 | 0 | bRefInputMode = (m_xEdCopyArea->GetWidget()->has_focus() || m_xRbCopyArea->GetWidget()->has_focus()); |
844 | |
|
845 | 0 | if ( m_xExpander->get_expanded() ) |
846 | 0 | pTimer->Start(); |
847 | 0 | } |
848 | | |
849 | | IMPL_LINK(ScFilterDlg, LbSelectHdl, weld::ComboBox&, rLb, void) |
850 | 0 | { |
851 | | /* |
852 | | * Handle enable/disable logic depending on which ListBox was selected |
853 | | */ |
854 | 0 | sal_uInt16 nOffset = GetSliderPos(); |
855 | |
|
856 | 0 | if ( &rLb == m_xLbConnect1.get() ) |
857 | 0 | { |
858 | 0 | m_xLbField1->set_sensitive(true); |
859 | 0 | m_xLbCond1->set_sensitive(true); |
860 | 0 | m_xEdVal1->set_sensitive(true); |
861 | 0 | m_xBtnRemove1->set_sensitive(true); |
862 | |
|
863 | 0 | const sal_Int32 nConnect1 = m_xLbConnect1->get_active(); |
864 | 0 | size_t nQE = nOffset; |
865 | 0 | theQueryData.GetEntry(nQE).eConnect =static_cast<ScQueryConnect>(nConnect1); |
866 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
867 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
868 | 0 | maRefreshExceptQuery[nQE] = true; |
869 | 0 | } |
870 | 0 | else if ( &rLb == m_xLbConnect2.get() ) |
871 | 0 | { |
872 | 0 | m_xLbField2->set_sensitive(true); |
873 | 0 | m_xLbCond2->set_sensitive(true); |
874 | 0 | m_xEdVal2->set_sensitive(true); |
875 | 0 | m_xBtnRemove2->set_sensitive(true); |
876 | |
|
877 | 0 | const sal_Int32 nConnect2 = m_xLbConnect2->get_active(); |
878 | 0 | size_t nQE = 1+nOffset; |
879 | 0 | theQueryData.GetEntry(nQE).eConnect =static_cast<ScQueryConnect>(nConnect2); |
880 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
881 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
882 | 0 | maRefreshExceptQuery[nQE]=true; |
883 | 0 | } |
884 | 0 | else if ( &rLb == m_xLbConnect3.get() ) |
885 | 0 | { |
886 | 0 | m_xLbField3->set_sensitive(true); |
887 | 0 | m_xLbCond3->set_sensitive(true); |
888 | 0 | m_xEdVal3->set_sensitive(true); |
889 | 0 | m_xBtnRemove3->set_sensitive(true); |
890 | |
|
891 | 0 | const sal_Int32 nConnect3 = m_xLbConnect3->get_active(); |
892 | 0 | size_t nQE = 2 + nOffset; |
893 | 0 | theQueryData.GetEntry(nQE).eConnect = static_cast<ScQueryConnect>(nConnect3); |
894 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
895 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
896 | 0 | maRefreshExceptQuery[nQE] = true; |
897 | |
|
898 | 0 | } |
899 | 0 | else if ( &rLb == m_xLbConnect4.get() ) |
900 | 0 | { |
901 | 0 | m_xLbField4->set_sensitive(true); |
902 | 0 | m_xLbCond4->set_sensitive(true); |
903 | 0 | m_xEdVal4->set_sensitive(true); |
904 | 0 | m_xLbColor4->set_sensitive(true); |
905 | 0 | m_xBtnRemove4->set_sensitive(true); |
906 | |
|
907 | 0 | const sal_Int32 nConnect4 = m_xLbConnect4->get_active(); |
908 | 0 | size_t nQE = 3 + nOffset; |
909 | 0 | theQueryData.GetEntry(nQE).eConnect = static_cast<ScQueryConnect>(nConnect4); |
910 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
911 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
912 | 0 | maRefreshExceptQuery[nQE] = true; |
913 | 0 | } |
914 | 0 | else if ( &rLb == m_xLbField1.get() ) |
915 | 0 | { |
916 | 0 | if ( m_xLbField1->get_active() == 0 ) |
917 | 0 | { |
918 | 0 | m_xLbConnect2->set_active(-1); |
919 | 0 | m_xLbConnect3->set_active(-1); |
920 | 0 | m_xLbConnect4->set_active(-1); |
921 | 0 | m_xLbField2->set_active( 0 ); |
922 | 0 | m_xLbField3->set_active( 0 ); |
923 | 0 | m_xLbField4->set_active( 0 ); |
924 | 0 | m_xLbCond2->set_active( 0 ); |
925 | 0 | m_xLbCond3->set_active( 0 ); |
926 | 0 | m_xLbCond4->set_active( 0 ); |
927 | 0 | ClearValueList( 1 ); |
928 | 0 | ClearValueList( 2 ); |
929 | 0 | ClearValueList( 3 ); |
930 | 0 | ClearValueList( 4 ); |
931 | |
|
932 | 0 | m_xLbConnect2->set_sensitive(false); |
933 | 0 | m_xLbConnect3->set_sensitive(false); |
934 | 0 | m_xLbConnect4->set_sensitive(false); |
935 | 0 | m_xLbField2->set_sensitive(false); |
936 | 0 | m_xLbField3->set_sensitive(false); |
937 | 0 | m_xLbField4->set_sensitive(false); |
938 | 0 | m_xLbCond2->set_sensitive(false); |
939 | 0 | m_xLbCond3->set_sensitive(false); |
940 | 0 | m_xLbCond4->set_sensitive(false); |
941 | 0 | m_xEdVal2->set_sensitive(false); |
942 | 0 | m_xEdVal3->set_sensitive(false); |
943 | 0 | m_xEdVal4->set_sensitive(false); |
944 | 0 | m_xLbColor2->set_sensitive(false); |
945 | 0 | m_xLbColor3->set_sensitive(false); |
946 | 0 | m_xLbColor4->set_sensitive(false); |
947 | 0 | m_xBtnRemove2->set_sensitive(false); |
948 | 0 | m_xBtnRemove3->set_sensitive(false); |
949 | 0 | m_xBtnRemove4->set_sensitive(false); |
950 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
951 | 0 | if (maRefreshExceptQuery.size() < nCount + 1) |
952 | 0 | maRefreshExceptQuery.resize(nCount + 1, false); |
953 | 0 | for (SCSIZE i = nOffset; i < nCount; ++i) |
954 | 0 | { |
955 | 0 | theQueryData.GetEntry(i).bDoQuery = false; |
956 | 0 | maRefreshExceptQuery[i] = false; |
957 | 0 | theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0); |
958 | 0 | } |
959 | 0 | maRefreshExceptQuery[nOffset] = true; |
960 | 0 | } |
961 | 0 | else |
962 | 0 | { |
963 | 0 | UpdateValueList( 1 ); |
964 | 0 | UpdateColorList( 1 ); |
965 | 0 | if ( !m_xLbConnect2->get_sensitive() ) |
966 | 0 | { |
967 | 0 | m_xLbConnect2->set_sensitive(true); |
968 | 0 | } |
969 | 0 | theQueryData.GetEntry(nOffset).bDoQuery = true; |
970 | 0 | const sal_Int32 nField = rLb.get_active(); |
971 | 0 | theQueryData.GetEntry(nOffset).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ; |
972 | 0 | } |
973 | 0 | } |
974 | 0 | else if ( &rLb == m_xLbField2.get() ) |
975 | 0 | { |
976 | 0 | if ( m_xLbField2->get_active() == 0 ) |
977 | 0 | { |
978 | 0 | m_xLbConnect3->set_active(-1); |
979 | 0 | m_xLbConnect4->set_active(-1); |
980 | 0 | m_xLbField3->set_active( 0 ); |
981 | 0 | m_xLbField4->set_active( 0 ); |
982 | 0 | m_xLbCond3->set_active( 0 ); |
983 | 0 | m_xLbCond4->set_active( 0 ); |
984 | 0 | ClearValueList( 2 ); |
985 | 0 | ClearValueList( 3 ); |
986 | 0 | ClearValueList( 4 ); |
987 | |
|
988 | 0 | m_xLbConnect3->set_sensitive(false); |
989 | 0 | m_xLbConnect4->set_sensitive(false); |
990 | 0 | m_xLbField3->set_sensitive(false); |
991 | 0 | m_xLbField4->set_sensitive(false); |
992 | 0 | m_xLbCond3->set_sensitive(false); |
993 | 0 | m_xLbCond4->set_sensitive(false); |
994 | 0 | m_xEdVal3->set_sensitive(false); |
995 | 0 | m_xEdVal4->set_sensitive(false); |
996 | 0 | m_xLbColor3->set_sensitive(false); |
997 | 0 | m_xLbColor4->set_sensitive(false); |
998 | 0 | m_xBtnRemove3->set_sensitive(false); |
999 | 0 | m_xBtnRemove4->set_sensitive(false); |
1000 | |
|
1001 | 0 | sal_uInt16 nTemp=nOffset+1; |
1002 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
1003 | 0 | if (maRefreshExceptQuery.size() < nCount) |
1004 | 0 | maRefreshExceptQuery.resize(nCount, false); |
1005 | 0 | for (SCSIZE i= nTemp; i< nCount; i++) |
1006 | 0 | { |
1007 | 0 | theQueryData.GetEntry(i).bDoQuery = false; |
1008 | 0 | maRefreshExceptQuery[i] = false; |
1009 | 0 | theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0); |
1010 | 0 | } |
1011 | 0 | maRefreshExceptQuery[nTemp] = true; |
1012 | 0 | } |
1013 | 0 | else |
1014 | 0 | { |
1015 | 0 | UpdateValueList( 2 ); |
1016 | 0 | UpdateColorList( 2 ); |
1017 | 0 | if ( !m_xLbConnect3->get_sensitive() ) |
1018 | 0 | { |
1019 | 0 | m_xLbConnect3->set_sensitive(true); |
1020 | 0 | } |
1021 | 0 | const sal_Int32 nField = rLb.get_active(); |
1022 | 0 | sal_uInt16 nQ=1+nOffset; |
1023 | 0 | theQueryData.GetEntry(nQ).bDoQuery = true; |
1024 | 0 | theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ; |
1025 | 0 | } |
1026 | 0 | } |
1027 | 0 | else if ( &rLb == m_xLbField3.get() ) |
1028 | 0 | { |
1029 | 0 | if ( m_xLbField3->get_active() == 0 ) |
1030 | 0 | { |
1031 | 0 | m_xLbConnect4->set_active(-1); |
1032 | 0 | m_xLbField4->set_active( 0 ); |
1033 | 0 | m_xLbCond4->set_active( 0 ); |
1034 | 0 | ClearValueList( 3 ); |
1035 | 0 | ClearValueList( 4 ); |
1036 | |
|
1037 | 0 | m_xLbConnect4->set_sensitive(false); |
1038 | 0 | m_xLbField4->set_sensitive(false); |
1039 | 0 | m_xLbCond4->set_sensitive(false); |
1040 | 0 | m_xEdVal4->set_sensitive(false); |
1041 | 0 | m_xLbColor4->set_sensitive(false); |
1042 | 0 | m_xBtnRemove4->set_sensitive(false); |
1043 | |
|
1044 | 0 | sal_uInt16 nTemp=nOffset+2; |
1045 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
1046 | 0 | if (maRefreshExceptQuery.size() < nCount) |
1047 | 0 | maRefreshExceptQuery.resize(nCount, false); |
1048 | 0 | for (SCSIZE i = nTemp; i < nCount; ++i) |
1049 | 0 | { |
1050 | 0 | theQueryData.GetEntry(i).bDoQuery = false; |
1051 | 0 | maRefreshExceptQuery[i] = false; |
1052 | 0 | theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0); |
1053 | 0 | } |
1054 | 0 | maRefreshExceptQuery[nTemp] = true; |
1055 | 0 | } |
1056 | 0 | else |
1057 | 0 | { |
1058 | 0 | UpdateValueList( 3 ); |
1059 | 0 | UpdateColorList( 3 ); |
1060 | 0 | if ( !m_xLbConnect4->get_sensitive() ) |
1061 | 0 | { |
1062 | 0 | m_xLbConnect4->set_sensitive(true); |
1063 | 0 | } |
1064 | |
|
1065 | 0 | const sal_Int32 nField = rLb.get_active(); |
1066 | 0 | sal_uInt16 nQ=2+nOffset; |
1067 | 0 | theQueryData.GetEntry(nQ).bDoQuery = true; |
1068 | 0 | theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ; |
1069 | |
|
1070 | 0 | } |
1071 | 0 | } |
1072 | 0 | else if ( &rLb == m_xLbField4.get() ) |
1073 | 0 | { |
1074 | 0 | if ( m_xLbField4->get_active() == 0 ) |
1075 | 0 | { |
1076 | 0 | ClearValueList( 4 ); |
1077 | 0 | sal_uInt16 nTemp=nOffset+3; |
1078 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
1079 | 0 | if (maRefreshExceptQuery.size() < nCount) |
1080 | 0 | maRefreshExceptQuery.resize(nCount, false); |
1081 | 0 | for (SCSIZE i = nTemp; i < nCount; ++i) |
1082 | 0 | { |
1083 | 0 | theQueryData.GetEntry(i).bDoQuery = false; |
1084 | 0 | maRefreshExceptQuery[i] = false; |
1085 | 0 | theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0); |
1086 | 0 | } |
1087 | 0 | maRefreshExceptQuery[nTemp] = true; |
1088 | 0 | } |
1089 | 0 | else |
1090 | 0 | { |
1091 | 0 | UpdateValueList( 4 ); |
1092 | 0 | UpdateColorList( 4 ); |
1093 | 0 | const sal_Int32 nField = rLb.get_active(); |
1094 | 0 | sal_uInt16 nQ=3+nOffset; |
1095 | 0 | theQueryData.GetEntry(nQ).bDoQuery = true; |
1096 | 0 | theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ; |
1097 | 0 | } |
1098 | |
|
1099 | 0 | } |
1100 | 0 | else if (&rLb == m_xLbCond1.get() || &rLb == m_xLbCond2.get() || &rLb == m_xLbCond3.get() |
1101 | 0 | || &rLb == m_xLbCond4.get()) |
1102 | 0 | { |
1103 | 0 | ScQueryOp op; |
1104 | 0 | sal_uInt16 nQ = 0; |
1105 | 0 | bool bEnableColorLb = false; |
1106 | 0 | if (rLb.get_active_text() == aStrFontColor || rLb.get_active_text() == aStrBackgroundColor) |
1107 | 0 | { |
1108 | 0 | bEnableColorLb = true; |
1109 | 0 | op = SC_EQUAL; |
1110 | 0 | } |
1111 | 0 | else |
1112 | 0 | { |
1113 | 0 | op = static_cast<ScQueryOp>(rLb.get_active()); |
1114 | 0 | } |
1115 | |
|
1116 | 0 | if (&rLb == m_xLbCond1.get()) |
1117 | 0 | { |
1118 | 0 | nQ = nOffset; |
1119 | 0 | m_xLbColor1->set_visible(bEnableColorLb); |
1120 | 0 | m_xLbColor1->set_sensitive(bEnableColorLb); |
1121 | 0 | m_xEdVal1->set_visible(!bEnableColorLb); |
1122 | 0 | UpdateColorList(1); |
1123 | 0 | } |
1124 | 0 | else if (&rLb == m_xLbCond2.get()) |
1125 | 0 | { |
1126 | 0 | nQ = 1 + nOffset; |
1127 | 0 | m_xLbColor2->set_visible(bEnableColorLb); |
1128 | 0 | m_xLbColor2->set_sensitive(bEnableColorLb); |
1129 | 0 | m_xEdVal2->set_visible(!bEnableColorLb); |
1130 | 0 | UpdateColorList(2); |
1131 | 0 | } |
1132 | 0 | else if (&rLb == m_xLbCond3.get()) |
1133 | 0 | { |
1134 | 0 | nQ = 2 + nOffset; |
1135 | 0 | m_xLbColor3->set_visible(bEnableColorLb); |
1136 | 0 | m_xLbColor3->set_sensitive(bEnableColorLb); |
1137 | 0 | m_xEdVal3->set_visible(!bEnableColorLb); |
1138 | 0 | UpdateColorList(3); |
1139 | 0 | } |
1140 | 0 | else if (&rLb == m_xLbCond4.get()) |
1141 | 0 | { |
1142 | 0 | nQ = 3 + nOffset; |
1143 | 0 | m_xLbColor4->set_visible(bEnableColorLb); |
1144 | 0 | m_xLbColor4->set_sensitive(bEnableColorLb); |
1145 | 0 | m_xEdVal4->set_visible(!bEnableColorLb); |
1146 | 0 | UpdateColorList(4); |
1147 | 0 | } |
1148 | |
|
1149 | 0 | theQueryData.GetEntry(nQ).eOp = op; |
1150 | 0 | } |
1151 | 0 | else if (&rLb == m_xLbColor1.get() || &rLb == m_xLbColor2.get() || &rLb == m_xLbColor3.get() |
1152 | 0 | || &rLb == m_xLbColor4.get()) |
1153 | 0 | { |
1154 | 0 | sal_uInt16 nQ = 0; |
1155 | 0 | if (&rLb == m_xLbColor1.get()) |
1156 | 0 | { |
1157 | 0 | nQ = nOffset; |
1158 | 0 | } |
1159 | 0 | else if (&rLb == m_xLbColor2.get()) |
1160 | 0 | { |
1161 | 0 | nQ = 1 + nOffset; |
1162 | 0 | } |
1163 | 0 | else if (&rLb == m_xLbColor3.get()) |
1164 | 0 | { |
1165 | 0 | nQ = 2 + nOffset; |
1166 | 0 | } |
1167 | 0 | else if (&rLb == m_xLbColor4.get()) |
1168 | 0 | { |
1169 | 0 | nQ = 3 + nOffset; |
1170 | 0 | } |
1171 | |
|
1172 | 0 | ScQueryEntry& aEntry = theQueryData.GetEntry(nQ); |
1173 | 0 | Color aColor = Color::STRtoRGB(maColorLbArr[nQ]->get_active_id()); |
1174 | 0 | if (maCondLbArr[nQ]->get_active_text() == aStrFontColor) |
1175 | 0 | { |
1176 | 0 | aEntry.SetQueryByTextColor(aColor); |
1177 | 0 | } |
1178 | 0 | else if (maCondLbArr[nQ]->get_active_text() == aStrBackgroundColor) |
1179 | 0 | { |
1180 | 0 | aEntry.SetQueryByBackgroundColor(aColor); |
1181 | 0 | } |
1182 | 0 | } |
1183 | 0 | } |
1184 | | |
1185 | | IMPL_LINK( ScFilterDlg, CheckBoxHdl, weld::Toggleable&, rBox, void ) |
1186 | 0 | { |
1187 | | // Column headers: |
1188 | | // Field list: Columnxx <-> column header string |
1189 | | // Value list: Column header value not applicable. |
1190 | | // Upper/lower case: |
1191 | | // Value list: completely new |
1192 | |
|
1193 | 0 | if ( &rBox == m_xBtnHeader.get() ) // Field list and value list |
1194 | 0 | { |
1195 | 0 | const sal_Int32 nCurSel1 = m_xLbField1->get_active(); |
1196 | 0 | const sal_Int32 nCurSel2 = m_xLbField2->get_active(); |
1197 | 0 | const sal_Int32 nCurSel3 = m_xLbField3->get_active(); |
1198 | 0 | const sal_Int32 nCurSel4 = m_xLbField4->get_active(); |
1199 | 0 | FillFieldLists(); |
1200 | 0 | m_xLbField1->set_active( nCurSel1 ); |
1201 | 0 | m_xLbField2->set_active( nCurSel2 ); |
1202 | 0 | m_xLbField3->set_active( nCurSel3 ); |
1203 | 0 | m_xLbField4->set_active( nCurSel4 ); |
1204 | |
|
1205 | 0 | UpdateHdrInValueList( 1 ); |
1206 | 0 | UpdateHdrInValueList( 2 ); |
1207 | 0 | UpdateHdrInValueList( 3 ); |
1208 | 0 | UpdateHdrInValueList( 4 ); |
1209 | 0 | } |
1210 | |
|
1211 | 0 | if ( &rBox != m_xBtnCase.get() ) // Complete value list |
1212 | 0 | return; |
1213 | | |
1214 | 0 | m_EntryLists.clear(); |
1215 | 0 | UpdateValueList( 1 ); // current text is recorded |
1216 | 0 | UpdateValueList( 2 ); |
1217 | 0 | UpdateValueList( 3 ); |
1218 | 0 | UpdateValueList( 4 ); |
1219 | |
|
1220 | 0 | UpdateColorList( 1 ); |
1221 | 0 | UpdateColorList( 2 ); |
1222 | 0 | UpdateColorList( 3 ); |
1223 | 0 | UpdateColorList( 4 ); |
1224 | 0 | } |
1225 | | |
1226 | | IMPL_LINK( ScFilterDlg, ValModifyHdl, weld::ComboBox&, rEd, void ) |
1227 | 0 | { |
1228 | 0 | size_t nOffset = GetSliderPos(); |
1229 | 0 | size_t i = 0; |
1230 | 0 | size_t nQE = i + nOffset; |
1231 | 0 | OUString aStrVal = rEd.get_active_text(); |
1232 | 0 | weld::ComboBox* pLbCond = m_xLbCond1.get(); |
1233 | 0 | weld::ComboBox* pLbField = m_xLbField1.get(); |
1234 | 0 | if ( &rEd == m_xEdVal2.get() ) |
1235 | 0 | { |
1236 | 0 | pLbCond = m_xLbCond2.get(); |
1237 | 0 | pLbField = m_xLbField2.get(); |
1238 | 0 | i=1; |
1239 | 0 | nQE=i+nOffset; |
1240 | 0 | } |
1241 | 0 | if ( &rEd == m_xEdVal3.get() ) |
1242 | 0 | { |
1243 | 0 | pLbCond = m_xLbCond3.get(); |
1244 | 0 | pLbField = m_xLbField3.get(); |
1245 | 0 | i=2; |
1246 | 0 | nQE=i+nOffset; |
1247 | 0 | } |
1248 | 0 | if ( &rEd == m_xEdVal4.get() ) |
1249 | 0 | { |
1250 | 0 | pLbCond = m_xLbCond4.get(); |
1251 | 0 | pLbField = m_xLbField4.get(); |
1252 | 0 | i=3; |
1253 | 0 | nQE=i+nOffset; |
1254 | 0 | } |
1255 | |
|
1256 | 0 | if ( aStrEmpty == aStrVal || aStrNotEmpty == aStrVal ) |
1257 | 0 | { |
1258 | 0 | pLbCond->set_active_text(OUString('=')); |
1259 | 0 | pLbCond->set_sensitive(false); |
1260 | 0 | } |
1261 | 0 | else |
1262 | 0 | pLbCond->set_sensitive(true); |
1263 | |
|
1264 | 0 | if (maHasDates.size() < nQE + 1) |
1265 | 0 | maHasDates.resize(nQE + 1, false); |
1266 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
1267 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
1268 | |
|
1269 | 0 | ScQueryEntry& rEntry = theQueryData.GetEntry( nQE ); |
1270 | 0 | ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); |
1271 | 0 | bool bDoThis = (pLbField->get_active() != 0); |
1272 | 0 | rEntry.bDoQuery = bDoThis; |
1273 | |
|
1274 | 0 | if ( !(rEntry.bDoQuery || maRefreshExceptQuery[nQE]) ) |
1275 | 0 | return; |
1276 | | |
1277 | 0 | bool bByEmptyOrNotByEmpty = false; |
1278 | 0 | if ( aStrEmpty == aStrVal ) |
1279 | 0 | { |
1280 | 0 | bByEmptyOrNotByEmpty = true; |
1281 | 0 | rEntry.SetQueryByEmpty(); |
1282 | 0 | } |
1283 | 0 | else if ( aStrNotEmpty == aStrVal ) |
1284 | 0 | { |
1285 | 0 | bByEmptyOrNotByEmpty = true; |
1286 | 0 | rEntry.SetQueryByNonEmpty(); |
1287 | 0 | } |
1288 | 0 | else |
1289 | 0 | { |
1290 | 0 | rItem.maString = rDoc.GetSharedStringPool().intern(aStrVal); |
1291 | 0 | rItem.mfVal = 0.0; |
1292 | |
|
1293 | 0 | sal_uInt32 nIndex = 0; |
1294 | 0 | bool bNumber = rDoc.GetFormatTable()->IsNumberFormat( |
1295 | 0 | rItem.maString.getString(), nIndex, rItem.mfVal); |
1296 | 0 | rItem.meType = bNumber ? ScQueryEntry::ByValue : ScQueryEntry::ByString; |
1297 | 0 | } |
1298 | |
|
1299 | 0 | const sal_Int32 nField = pLbField->get_active(); |
1300 | 0 | rEntry.nField = nField ? (theQueryData.nCol1 + |
1301 | 0 | static_cast<SCCOL>(nField) - 1) : static_cast<SCCOL>(0); |
1302 | |
|
1303 | 0 | ScQueryOp eOp = static_cast<ScQueryOp>(pLbCond->get_active()); |
1304 | 0 | rEntry.eOp = eOp; |
1305 | 0 | if (maHasDates[nQE] && !bByEmptyOrNotByEmpty) |
1306 | 0 | rItem.meType = ScQueryEntry::ByDate; |
1307 | 0 | } |
1308 | | |
1309 | | IMPL_LINK( ScFilterDlg, BtnRemoveHdl, weld::Button&, rBtn, void ) |
1310 | 0 | { |
1311 | | // Calculate the row to delete |
1312 | 0 | sal_uInt16 nOffset = GetSliderPos(); |
1313 | 0 | int nButtonIndex = 0; |
1314 | 0 | if ( &rBtn == m_xBtnRemove2.get() ) |
1315 | 0 | nButtonIndex = 1; |
1316 | 0 | if ( &rBtn == m_xBtnRemove3.get() ) |
1317 | 0 | nButtonIndex = 2; |
1318 | 0 | if ( &rBtn == m_xBtnRemove4.get() ) |
1319 | 0 | nButtonIndex = 3; |
1320 | 0 | SCSIZE nRowToDelete = nOffset + nButtonIndex; |
1321 | | |
1322 | | // Check that the index is sensible |
1323 | 0 | SCSIZE nCount = theQueryData.GetEntryCount(); |
1324 | 0 | if (nRowToDelete >= nCount) |
1325 | 0 | { |
1326 | 0 | SAL_WARN( "sc", "ScFilterDlg::BtnRemoveHdl: could not delete row - invalid index."); |
1327 | 0 | return; |
1328 | 0 | } |
1329 | | |
1330 | | // Resize maRefreshExceptQuery |
1331 | 0 | if (maRefreshExceptQuery.size() < nCount + 1) |
1332 | 0 | maRefreshExceptQuery.resize(nCount + 1, false); |
1333 | | |
1334 | | // Move all the subsequent rows back one position; |
1335 | | // also find the last row, which we will delete |
1336 | 0 | SCSIZE nRowToClear = nCount-1; |
1337 | 0 | for (SCSIZE i = nRowToDelete; i < nCount-1; ++i) |
1338 | 0 | { |
1339 | 0 | if (theQueryData.GetEntry(i+1).bDoQuery) |
1340 | 0 | { |
1341 | 0 | theQueryData.GetEntry(i) = theQueryData.GetEntry(i+1); |
1342 | 0 | } |
1343 | 0 | else |
1344 | 0 | { |
1345 | 0 | nRowToClear = i; |
1346 | 0 | break; |
1347 | 0 | } |
1348 | 0 | } |
1349 | | |
1350 | | // If the next row is being edited, but not confirmed, move it back |
1351 | | // one position |
1352 | 0 | if (nRowToClear < nCount-1 && maRefreshExceptQuery[nRowToClear+1]) |
1353 | 0 | { |
1354 | 0 | theQueryData.GetEntry(nRowToClear) = theQueryData.GetEntry(nRowToClear+1); |
1355 | 0 | maRefreshExceptQuery[nRowToClear] = true; |
1356 | 0 | maRefreshExceptQuery[nRowToClear+1] = false; |
1357 | 0 | } |
1358 | 0 | else |
1359 | 0 | { |
1360 | | // Remove the very last one, since everything has moved back |
1361 | 0 | theQueryData.GetEntry(nRowToClear).bDoQuery = false; |
1362 | 0 | theQueryData.GetEntry(nRowToClear).nField = static_cast<SCCOL>(0); |
1363 | 0 | maRefreshExceptQuery[nRowToClear] = false; |
1364 | 0 | } |
1365 | | |
1366 | | // Always enable the very first row |
1367 | 0 | if (!theQueryData.GetEntry(0).bDoQuery) |
1368 | 0 | { |
1369 | 0 | maRefreshExceptQuery[0] = true; |
1370 | 0 | } |
1371 | | |
1372 | | // Refresh the UI |
1373 | 0 | RefreshEditRow( nOffset ); |
1374 | | |
1375 | | // Special handling if the very first row was cleared |
1376 | 0 | if (!theQueryData.GetEntry(0).bDoQuery) |
1377 | 0 | { |
1378 | 0 | m_xLbConnect1->set_active(-1); |
1379 | 0 | m_xLbField1->set_active(0); |
1380 | 0 | m_xLbField1->set_sensitive(true); |
1381 | 0 | m_xLbCond1->set_active(0); |
1382 | 0 | m_xLbCond1->set_sensitive(true); |
1383 | 0 | ClearValueList(1); |
1384 | 0 | } |
1385 | 0 | } |
1386 | | |
1387 | | IMPL_LINK_NOARG(ScFilterDlg, ScrollHdl, weld::ScrolledWindow&, void) |
1388 | 0 | { |
1389 | 0 | SliderMoved(); |
1390 | 0 | } |
1391 | | |
1392 | | void ScFilterDlg::SliderMoved() |
1393 | 0 | { |
1394 | 0 | size_t nOffset = GetSliderPos(); |
1395 | 0 | RefreshEditRow( nOffset); |
1396 | 0 | } |
1397 | | |
1398 | | size_t ScFilterDlg::GetSliderPos() const |
1399 | 0 | { |
1400 | 0 | return static_cast<size_t>(m_xScrollBar->vadjustment_get_value()); |
1401 | 0 | } |
1402 | | |
1403 | | void ScFilterDlg::RefreshEditRow( size_t nOffset ) |
1404 | 0 | { |
1405 | 0 | if (nOffset==0) |
1406 | 0 | maConnLbArr[0]->hide(); |
1407 | 0 | else |
1408 | 0 | maConnLbArr[0]->show(); |
1409 | |
|
1410 | 0 | for (size_t i = 0; i < QUERY_ENTRY_COUNT; ++i) |
1411 | 0 | { |
1412 | 0 | OUString aValStr; |
1413 | 0 | size_t nCondPos = 0; |
1414 | 0 | size_t nFieldSelPos = 0; |
1415 | 0 | size_t nQE = i + nOffset; |
1416 | |
|
1417 | 0 | maColorLbArr[i]->set_visible(false); |
1418 | |
|
1419 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
1420 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
1421 | |
|
1422 | 0 | ScQueryEntry& rEntry = theQueryData.GetEntry( nQE); |
1423 | 0 | if ( rEntry.bDoQuery || maRefreshExceptQuery[nQE] ) |
1424 | 0 | { |
1425 | 0 | nCondPos = static_cast<size_t>(rEntry.eOp); |
1426 | 0 | if(rEntry.bDoQuery) |
1427 | 0 | nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) ); |
1428 | |
|
1429 | 0 | const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); |
1430 | 0 | OUString aQueryStr = rItem.maString.getString(); |
1431 | 0 | if (rEntry.IsQueryByEmpty()) |
1432 | 0 | { |
1433 | 0 | aValStr = aStrEmpty; |
1434 | 0 | maCondLbArr[i]->set_sensitive(false); |
1435 | 0 | } |
1436 | 0 | else if (rEntry.IsQueryByNonEmpty()) |
1437 | 0 | { |
1438 | 0 | aValStr = aStrNotEmpty; |
1439 | 0 | maCondLbArr[i]->set_sensitive(false); |
1440 | 0 | } |
1441 | 0 | else if (rEntry.IsQueryByTextColor() || rEntry.IsQueryByBackgroundColor()) |
1442 | 0 | { |
1443 | 0 | nCondPos = maCondLbArr[i]->find_text( |
1444 | 0 | rEntry.IsQueryByTextColor() ? aStrFontColor : aStrBackgroundColor); |
1445 | |
|
1446 | 0 | maValueEdArr[i]->set_visible(false); |
1447 | 0 | maColorLbArr[i]->set_visible(true); |
1448 | 0 | maColorLbArr[i]->set_sensitive(true); |
1449 | 0 | } |
1450 | 0 | else |
1451 | 0 | { |
1452 | 0 | SetValString(aQueryStr, rItem, aValStr); |
1453 | 0 | maCondLbArr[i]->set_sensitive(true); |
1454 | 0 | } |
1455 | 0 | maFieldLbArr[i]->set_sensitive(true); |
1456 | 0 | maValueEdArr[i]->set_sensitive(true); |
1457 | 0 | maRemoveBtnArr[i]->set_sensitive(true); |
1458 | |
|
1459 | 0 | if (nOffset==0) |
1460 | 0 | { |
1461 | 0 | if (i<3) |
1462 | 0 | { |
1463 | 0 | if(rEntry.bDoQuery) |
1464 | 0 | maConnLbArr[i+1]->set_sensitive(true); |
1465 | 0 | else |
1466 | 0 | maConnLbArr[i+1]->set_sensitive(false); |
1467 | 0 | size_t nQENext = nQE + 1; |
1468 | 0 | if (maRefreshExceptQuery.size() < nQENext + 1) |
1469 | 0 | maRefreshExceptQuery.resize(nQENext + 1, false); |
1470 | 0 | if (theQueryData.GetEntry(nQENext).bDoQuery || maRefreshExceptQuery[nQENext]) |
1471 | 0 | maConnLbArr[i+1]->set_active( static_cast<sal_uInt16>(theQueryData.GetEntry(nQENext).eConnect) ); |
1472 | 0 | else |
1473 | 0 | maConnLbArr[i+1]->set_active(-1); |
1474 | 0 | } |
1475 | 0 | } |
1476 | 0 | else |
1477 | 0 | { |
1478 | 0 | if(theQueryData.GetEntry( nQE-1).bDoQuery) |
1479 | 0 | maConnLbArr[i]->set_sensitive(true); |
1480 | 0 | else |
1481 | 0 | maConnLbArr[i]->set_sensitive(false); |
1482 | |
|
1483 | 0 | if (maRefreshExceptQuery.size() < nQE + 1) |
1484 | 0 | maRefreshExceptQuery.resize(nQE + 1, false); |
1485 | 0 | if(rEntry.bDoQuery || maRefreshExceptQuery[nQE]) |
1486 | 0 | maConnLbArr[i]->set_active( static_cast<sal_uInt16>(rEntry.eConnect) ); |
1487 | 0 | else |
1488 | 0 | maConnLbArr[i]->set_active(-1); |
1489 | 0 | } |
1490 | |
|
1491 | 0 | } |
1492 | 0 | else |
1493 | 0 | { |
1494 | 0 | if (nOffset==0) |
1495 | 0 | { |
1496 | 0 | if(i<3) |
1497 | 0 | { |
1498 | 0 | maConnLbArr[i+1]->set_active(-1); |
1499 | 0 | maConnLbArr[i+1]->set_sensitive(false); |
1500 | 0 | } |
1501 | 0 | } |
1502 | 0 | else |
1503 | 0 | { |
1504 | 0 | if(theQueryData.GetEntry( nQE-1).bDoQuery) |
1505 | 0 | maConnLbArr[i]->set_sensitive(true); |
1506 | 0 | else |
1507 | 0 | maConnLbArr[i]->set_sensitive(false); |
1508 | 0 | maConnLbArr[i]->set_active(-1); |
1509 | 0 | } |
1510 | 0 | maFieldLbArr[i]->set_sensitive(false); |
1511 | 0 | maCondLbArr[i]->set_sensitive(false); |
1512 | 0 | maValueEdArr[i]->set_sensitive(false); |
1513 | 0 | maRemoveBtnArr[i]->set_sensitive(false); |
1514 | 0 | } |
1515 | 0 | maFieldLbArr[i]->set_active( nFieldSelPos ); |
1516 | 0 | maCondLbArr [i]->set_active( nCondPos ); |
1517 | 0 | maValueEdArr[i]->set_entry_text( aValStr ); |
1518 | 0 | UpdateValueList(i+1); |
1519 | 0 | UpdateColorList(i+1); |
1520 | 0 | } |
1521 | 0 | } |
1522 | | |
1523 | | void ScFilterDlg::SetValString( const OUString& rQueryStr, const ScQueryEntry::Item& rItem, |
1524 | | OUString& rValStr ) |
1525 | 0 | { |
1526 | 0 | if (rQueryStr.isEmpty()) |
1527 | 0 | { |
1528 | 0 | if (rItem.meType == ScQueryEntry::ByValue) |
1529 | 0 | { |
1530 | 0 | rValStr = rDoc.GetFormatTable()->GetInputLineString(rItem.mfVal, 0); |
1531 | 0 | } |
1532 | 0 | else if (rItem.meType == ScQueryEntry::ByDate) |
1533 | 0 | { |
1534 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
1535 | 0 | rValStr = pFormatter->GetInputLineString(rItem.mfVal, |
1536 | 0 | pFormatter->GetStandardFormat( SvNumFormatType::DATE)); |
1537 | 0 | } |
1538 | 0 | else |
1539 | 0 | { |
1540 | 0 | SAL_WARN( "sc", "ScFilterDlg::SetValString: empty query string, really?"); |
1541 | 0 | rValStr = rQueryStr; |
1542 | 0 | } |
1543 | 0 | } |
1544 | 0 | else |
1545 | 0 | { |
1546 | | // XXX NOTE: if not ByString we just assume this has been |
1547 | | // set to a proper string corresponding to the numeric |
1548 | | // value earlier! |
1549 | 0 | rValStr = rQueryStr; |
1550 | 0 | } |
1551 | 0 | } |
1552 | | |
1553 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |