pyuno: call target only with internal python
[LibreOffice.git] / sc / source / core / tool / queryentry.cxx
blobd66382d2e2b84ed9e3b6b901e945086300f3aa0e
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 .
20 #include <queryentry.hxx>
22 #include <unotools/textsearch.hxx>
25 * dialog returns the special field values "empty"/"not empty"
26 * as constants SC_EMPTYFIELDS and SC_NONEMPTYFIELDS respectively in nVal in
27 * conjunctions with the flag bQueryByString = FALSE.
30 #define SC_EMPTYFIELDS (double(0x0042))
31 #define SC_NONEMPTYFIELDS (double(0x0043))
32 #define SC_TEXTCOLOR (double(0x0044))
33 #define SC_BACKGROUNDCOLOR (double(0x0045))
35 bool ScQueryEntry::Item::operator== (const Item& r) const
37 return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty
38 && mbRoundForFilter == r.mbRoundForFilter;
41 ScQueryEntry::ScQueryEntry() :
42 bDoQuery(false),
43 nField(0),
44 eOp(SC_EQUAL),
45 eConnect(SC_AND),
46 maQueryItems(1)
50 ScQueryEntry::ScQueryEntry(const ScQueryEntry& r) :
51 bDoQuery(r.bDoQuery),
52 nField(r.nField),
53 eOp(r.eOp),
54 eConnect(r.eConnect),
55 maQueryItems(r.maQueryItems)
59 ScQueryEntry::~ScQueryEntry()
63 ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
65 bDoQuery = r.bDoQuery;
66 eOp = r.eOp;
67 eConnect = r.eConnect;
68 nField = r.nField;
69 maQueryItems = r.maQueryItems;
71 pSearchParam.reset();
72 pSearchText.reset();
74 return *this;
77 void ScQueryEntry::SetQueryByEmpty()
79 eOp = SC_EQUAL;
80 maQueryItems.resize(1);
81 Item& rItem = maQueryItems[0];
82 rItem.meType = ByEmpty;
83 rItem.maString = svl::SharedString();
84 rItem.mfVal = SC_EMPTYFIELDS;
87 bool ScQueryEntry::IsQueryByEmpty() const
89 if (maQueryItems.size() != 1)
90 return false;
92 const Item& rItem = maQueryItems[0];
93 return eOp == SC_EQUAL &&
94 rItem.meType == ByEmpty &&
95 rItem.maString.isEmpty() &&
96 rItem.mfVal == SC_EMPTYFIELDS;
99 void ScQueryEntry::SetQueryByNonEmpty()
101 eOp = SC_EQUAL;
102 maQueryItems.resize(1);
103 Item& rItem = maQueryItems[0];
104 rItem.meType = ByEmpty;
105 rItem.maString = svl::SharedString();
106 rItem.mfVal = SC_NONEMPTYFIELDS;
109 bool ScQueryEntry::IsQueryByNonEmpty() const
111 if (maQueryItems.size() != 1)
112 return false;
114 const Item& rItem = maQueryItems[0];
115 return eOp == SC_EQUAL &&
116 rItem.meType == ByEmpty &&
117 rItem.maString.isEmpty() &&
118 rItem.mfVal == SC_NONEMPTYFIELDS;
121 void ScQueryEntry::SetQueryByTextColor(Color color)
123 eOp = SC_EQUAL;
124 maQueryItems.resize(1);
125 Item& rItem = maQueryItems[0];
126 rItem.meType = ByTextColor;
127 rItem.maString = svl::SharedString();
128 rItem.mfVal = SC_TEXTCOLOR;
129 rItem.maColor = color;
132 bool ScQueryEntry::IsQueryByTextColor() const
134 if (maQueryItems.size() != 1)
135 return false;
137 const Item& rItem = maQueryItems[0];
138 return eOp == SC_EQUAL &&
139 rItem.meType == ByTextColor;
142 void ScQueryEntry::SetQueryByBackgroundColor(Color color)
144 eOp = SC_EQUAL;
145 maQueryItems.resize(1);
146 Item& rItem = maQueryItems[0];
147 rItem.meType = ByBackgroundColor;
148 rItem.maString = svl::SharedString();
149 rItem.mfVal = SC_BACKGROUNDCOLOR;
150 rItem.maColor = color;
153 bool ScQueryEntry::IsQueryByBackgroundColor() const
155 if (maQueryItems.size() != 1)
156 return false;
158 const Item& rItem = maQueryItems[0];
159 return eOp == SC_EQUAL &&
160 rItem.meType == ByBackgroundColor;
163 ScQueryEntry::Item& ScQueryEntry::GetQueryItemImpl() const
165 if (maQueryItems.size() != 1)
166 // Reset to a single query mode.
167 maQueryItems.resize(1);
168 return maQueryItems[0];
171 void ScQueryEntry::Clear()
173 bDoQuery = false;
174 eOp = SC_EQUAL;
175 eConnect = SC_AND;
176 nField = 0;
177 maQueryItems.clear();
178 maQueryItems.emplace_back();
180 pSearchParam.reset();
181 pSearchText.reset();
184 bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
186 return bDoQuery == r.bDoQuery
187 && eOp == r.eOp
188 && eConnect == r.eConnect
189 && nField == r.nField
190 && maQueryItems == r.maQueryItems;
191 // do not compare pSearchParam and pSearchText!
194 utl::TextSearch* ScQueryEntry::GetSearchTextPtr( utl::SearchParam::SearchType eSearchType, bool bCaseSens,
195 bool bWildMatchSel ) const
197 if ( !pSearchParam )
199 OUString aStr = maQueryItems[0].maString.getString();
200 pSearchParam.reset(new utl::SearchParam(
201 aStr, eSearchType, bCaseSens, '~', bWildMatchSel));
202 pSearchText.reset(new utl::TextSearch( *pSearchParam, ScGlobal::getCharClass() ));
204 return pSearchText.get();
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */