1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <rtl/strbuf.hxx>
#include "svx/fmresids.hrc"
#include "svx/fmtools.hxx"
#include "svx/fmsrccfg.hxx"
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include <tools/wldcrd.hxx>
#include <vcl/msgbox.hxx>
#include <svx/dialmgr.hxx>
#include <vcl/svapp.hxx>
#include <unotools/textsearch.hxx>
#include <com/sun/star/util/SearchOptions.hpp>
#include <com/sun/star/util/SearchAlgorithms.hpp>
#include <com/sun/star/util/SearchResult.hpp>
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/i18n/TransliterationModules.hpp>
#include <com/sun/star/i18n/CollatorOptions.hpp>
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#include <com/sun/star/util/NumberFormatter.hpp>
#include <com/sun/star/util/NumberFormat.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
#include <comphelper/processfactory.hxx>
#include "fmprop.hrc"
#include "fmservs.hxx"
#include "svx/fmsrcimp.hxx"
#include <svx/fmsearch.hxx>
#include <comphelper/numbers.hxx>
#include <unotools/syslocale.hxx>
#define EQUAL_BOOKMARKS(a, b) a == b
#define IFACECAST(c) ((const Reference< XInterface >&)c)
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::beans;
using namespace ::svxform;
// = FmSearchThread
void FmSearchThread::run()
{
osl_setThreadName("FmSearchThread");
m_pEngine->SearchNextImpl();
};
void FmSearchThread::onTerminated()
{
if (m_aTerminationHdl.IsSet())
m_aTerminationHdl.Call(this);
delete this;
}
// = FmRecordCountListener
// SMART_UNO_IMPLEMENTATION(FmRecordCountListener, UsrObject);
FmRecordCountListener::FmRecordCountListener(const Reference< ::com::sun::star::sdbc::XResultSet > & dbcCursor)
{
m_xListening = Reference< ::com::sun::star::beans::XPropertySet > (dbcCursor, UNO_QUERY);
if (!m_xListening.is())
return;
if (::comphelper::getBOOL(m_xListening->getPropertyValue(FM_PROP_ROWCOUNTFINAL)))
{
m_xListening = NULL;
// there's nothing to do as the record count is already known
return;
}
m_xListening->addPropertyChangeListener(FM_PROP_ROWCOUNT, (::com::sun::star::beans::XPropertyChangeListener*)this);
}
Link<> FmRecordCountListener::SetPropChangeHandler(const Link<>& lnk)
{
Link<> lnkReturn = m_lnkWhoWantsToKnow;
m_lnkWhoWantsToKnow = lnk;
if (m_xListening.is())
NotifyCurrentCount();
return lnkReturn;
}
FmRecordCountListener::~FmRecordCountListener()
{
}
void FmRecordCountListener::DisConnect()
{
if(m_xListening.is())
m_xListening->removePropertyChangeListener(FM_PROP_ROWCOUNT, (::com::sun::star::beans::XPropertyChangeListener*)this);
m_xListening = NULL;
}
void SAL_CALL FmRecordCountListener::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException, std::exception )
{
DBG_ASSERT(m_xListening.is(), "FmRecordCountListener::disposing should never have been called without a propset !");
DisConnect();
}
void FmRecordCountListener::NotifyCurrentCount()
{
if (m_lnkWhoWantsToKnow.IsSet())
{
DBG_ASSERT(m_xListening.is(), "FmRecordCountListener::NotifyCurrentCount : I have no propset ... !?");
void* pTheCount = reinterpret_cast<void*>(::comphelper::getINT32(m_xListening->getPropertyValue(FM_PROP_ROWCOUNT)));
m_lnkWhoWantsToKnow.Call(pTheCount);
}
}
void FmRecordCountListener::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& /*evt*/) throw(::com::sun::star::uno::RuntimeException, std::exception)
{
NotifyCurrentCount();
}
// FmSearchEngine - local classes
SimpleTextWrapper::SimpleTextWrapper(const Reference< ::com::sun::star::awt::XTextComponent > & _xText)
:ControlTextWrapper(_xText.get())
,m_xText(_xText)
{
DBG_ASSERT(m_xText.is(), "FmSearchEngine::SimpleTextWrapper::SimpleTextWrapper : invalid argument !");
}
OUString SimpleTextWrapper::getCurrentText() const
{
return m_xText->getText();
}
ListBoxWrapper::ListBoxWrapper(const Reference< ::com::sun::star::awt::XListBox > & _xBox)
:ControlTextWrapper(_xBox.get())
,m_xBox(_xBox)
{
DBG_ASSERT(m_xBox.is(), "FmSearchEngine::ListBoxWrapper::ListBoxWrapper : invalid argument !");
}
OUString ListBoxWrapper::getCurrentText() const
{
return m_xBox->getSelectedItem();
}
CheckBoxWrapper::CheckBoxWrapper(const Reference< ::com::sun::star::awt::XCheckBox > & _xBox)
:ControlTextWrapper(_xBox.get())
,m_xBox(_xBox)
{
DBG_ASSERT(m_xBox.is(), "FmSearchEngine::CheckBoxWrapper::CheckBoxWrapper : invalid argument !");
}
OUString CheckBoxWrapper::getCurrentText() const
{
switch ((TriState)m_xBox->getState())
{
case TRISTATE_FALSE: return OUString("0");
case TRISTATE_TRUE: return OUString("1");
default: break;
}
return OUString();
}
// = FmSearchEngine
bool FmSearchEngine::MoveCursor()
{
bool bSuccess = true;
try
{
if (m_bForward)
if (m_xSearchCursor.isLast())
m_xSearchCursor.first();
else
m_xSearchCursor.next();
else
if (m_xSearchCursor.isFirst())
{
FmRecordCountListener* prclListener = new FmRecordCountListener(m_xSearchCursor);
prclListener->acquire();
prclListener->SetPropChangeHandler(LINK(this, FmSearchEngine, OnNewRecordCount));
m_xSearchCursor.last();
prclListener->DisConnect();
prclListener->release();
}
else
m_xSearchCursor.previous();
}
catch(::com::sun::star::sdbc::SQLException const& e)
{
#if OSL_DEBUG_LEVEL > 0
OStringBuffer sDebugMessage("FmSearchEngine::MoveCursor : catched a DatabaseException (");
sDebugMessage.append(OUStringToOString(e.SQLState, RTL_TEXTENCODING_ASCII_US));
sDebugMessage.append(") !");
OSL_FAIL(sDebugMessage.getStr());
#else
(void)e;
#endif
bSuccess = false;
}
catch(Exception const& e)
{
#if OSL_DEBUG_LEVEL > 0
OStringBuffer sDebugMessage("FmSearchEngine::MoveCursor : catched an Exception (");
sDebugMessage.append(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US));
sDebugMessage.append(") !");
OSL_FAIL(sDebugMessage.getStr());
#else
(void)e;
#endif
bSuccess = false;
}
catch(...)
{
OSL_FAIL("FmSearchEngine::MoveCursor : catched an unknown Exception !");
bSuccess = false;
}
return bSuccess;
}
bool FmSearchEngine::MoveField(sal_Int32& nPos, FieldCollection::iterator& iter, const FieldCollection::iterator& iterBegin, const FieldCollection::iterator& iterEnd)
{
bool bSuccess(true);
if (m_bForward)
{
++iter;
++nPos;
if (iter == iterEnd)
{
bSuccess = MoveCursor();
iter = iterBegin;
nPos = 0;
}
} else
{
if (iter == iterBegin)
{
bSuccess = MoveCursor();
iter = iterEnd;
nPos = iter-iterBegin;
}
--iter;
--nPos;
}
return bSuccess;
}
void FmSearchEngine::BuildAndInsertFieldInfo(const Reference< ::com::sun::star::container::XIndexAccess > & xAllFields, sal_Int32 nField)
{
DBG_ASSERT( xAllFields.is() && ( nField >= 0 ) && ( nField < xAllFields->getCount() ),
"FmSearchEngine::BuildAndInsertFieldInfo: invalid field descriptor!" );
// das Feld selber
Reference< XInterface > xCurrentField;
xAllFields->getByIndex(nField) >>= xCurrentField;
// von dem weiss ich jetzt, dass es den DatabaseRecord-Service unterstuetzt (hoffe ich)
// fuer den FormatKey und den Typ brauche ich das PropertySet
Reference< ::com::sun::star::beans::XPropertySet > xProperties(xCurrentField, UNO_QUERY);
// die FieldInfo dazu aufbauen
FieldInfo fiCurrent;
fiCurrent.xContents = Reference< ::com::sun::star::sdb::XColumn > (xCurrentField, UNO_QUERY);
fiCurrent.nFormatKey = ::comphelper::getINT32(xProperties->getPropertyValue(FM_PROP_FORMATKEY));
fiCurrent.bDoubleHandling = false;
if (m_xFormatSupplier.is())
{
Reference< ::com::sun::star::util::XNumberFormats > xNumberFormats(m_xFormatSupplier->getNumberFormats());
sal_Int16 nFormatType = ::comphelper::getNumberFormatType(xNumberFormats, fiCurrent.nFormatKey) & ~((sal_Int16)::com::sun::star::util::NumberFormat::DEFINED);
fiCurrent.bDoubleHandling = (nFormatType != ::com::sun::star::util::NumberFormat::TEXT);
}
// und merken
m_arrUsedFields.insert(m_arrUsedFields.end(), fiCurrent);
}
OUString FmSearchEngine::FormatField(const FieldInfo& rField)
{
DBG_ASSERT(!m_bUsingTextComponents, "FmSearchEngine::FormatField : im UsingTextComponents-Mode bitte FormatField(sal_Int32) benutzen !");
if (!m_xFormatter.is())
return OUString();
// sonst werden Datumsflder zum Beispiel zu irgendeinem Default-Wert formatiert
OUString sReturn;
try
{
if (rField.bDoubleHandling)
{
double fValue = rField.xContents->getDouble();
if (!rField.xContents->wasNull())
sReturn = m_xFormatter->convertNumberToString(rField.nFormatKey, fValue);
}
else
{
OUString sValue = rField.xContents->getString();
if (!rField.xContents->wasNull())
sReturn = m_xFormatter->formatString(rField.nFormatKey, sValue);
}
}
catch(...)
{
}
return sReturn;
}
OUString FmSearchEngine::FormatField(sal_Int32 nWhich)
{
if (m_bUsingTextComponents)
{
DBG_ASSERT((sal_uInt32)nWhich < m_aControlTexts.size(), "FmSearchEngine::FormatField(sal_Int32) : invalid position !");
DBG_ASSERT(m_aControlTexts[nWhich] != NULL, "FmSearchEngine::FormatField(sal_Int32) : invalid object in array !");
DBG_ASSERT(m_aControlTexts[nWhich]->getControl().is(), "FmSearchEngine::FormatField : invalid control !");
if (m_nCurrentFieldIndex != -1)
{
DBG_ASSERT((nWhich == 0) || (nWhich == m_nCurrentFieldIndex), "FmSearchEngine::FormatField : Parameter nWhich ist ungueltig");
// analoge Situation wie unten
nWhich = m_nCurrentFieldIndex;
}
DBG_ASSERT((nWhich >= 0) && ((sal_uInt32)nWhich < m_aControlTexts.size()),
"FmSearchEngine::FormatField : invalid argument nWhich !");
return m_aControlTexts[m_nCurrentFieldIndex == -1 ? nWhich : m_nCurrentFieldIndex]->getCurrentText();
}
else
{
if (m_nCurrentFieldIndex != -1)
{
DBG_ASSERT((nWhich == 0) || (nWhich == m_nCurrentFieldIndex), "FmSearchEngine::FormatField : Parameter nWhich ist ungueltig");
// ich bin im single-field-modus, da ist auch die richtige Feld-Nummer erlaubt, obwohl dann der richtige ::com::sun::star::sdbcx::Index
// fuer meinen Array-Zugriff natuerlich 0 ist
nWhich = 0;
}
DBG_ASSERT((nWhich>=0) && (nWhich < (m_arrUsedFields.end() - m_arrUsedFields.begin())),
"FmSearchEngine::FormatField : Parameter nWhich ist ungueltig");
return FormatField(m_arrUsedFields[nWhich]);
}
}
FmSearchEngine::SEARCH_RESULT FmSearchEngine::SearchSpecial(bool _bSearchForNull, sal_Int32& nFieldPos,
FieldCollection::iterator& iterFieldLoop, const FieldCollection::iterator& iterBegin, const FieldCollection::iterator& iterEnd)
{
// die Startposition merken
Any aStartMark;
try { aStartMark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
FieldCollection::iterator iterInitialField = iterFieldLoop;
bool bFound(false);
bool bMovedAround(false);
do
{
if (m_eMode == SM_ALLOWSCHEDULE)
{
Application::Reschedule();
Application::Reschedule();
// do 2 reschedules because of #70226# : some things done within this loop's body may cause an user event
// to be posted (deep within vcl), and these user events will be handled before any keyinput or paintings
// or anything like that. So within each loop we create one user event and handle one user event (and no
// paintings and these), so the office seems to be frozen while searching.
// FS - 70226 - 02.12.99
}
// der aktuell zu vergleichende Inhalt
iterFieldLoop->xContents->getString(); // needed for wasNull
bFound = _bSearchForNull == bool(iterFieldLoop->xContents->wasNull());
if (bFound)
break;
// naechstes Feld (implizit naechster Datensatz, wenn noetig)
if (!MoveField(nFieldPos, iterFieldLoop, iterBegin, iterEnd))
{ // beim Bewegen auf das naechste Feld ging was schief ... weitermachen ist nicht drin, da das naechste Mal genau
// das selbe bestimmt wieder schief geht, also Abbruch
// vorher aber noch, damit das Weitersuchen an der aktuellen Position weitermacht :
try { m_aPreviousLocBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
m_iterPreviousLocField = iterFieldLoop;
// und wech
return SR_ERROR;
}
Any aCurrentBookmark;
try { aCurrentBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
bMovedAround = EQUAL_BOOKMARKS(aStartMark, aCurrentBookmark) && (iterFieldLoop == iterInitialField);
if (nFieldPos == 0)
// das heisst, ich habe mich auf einen neuen Datensatz bewegt
PropagateProgress(bMovedAround);
// if we moved to the starting position we don't have to propagate an 'overflow' message
// FS - 07.12.99 - 68530
// abbrechen gefordert ?
if (CancelRequested())
return SR_CANCELED;
} while (!bMovedAround);
return bFound ? SR_FOUND : SR_NOTFOUND;
}
FmSearchEngine::SEARCH_RESULT FmSearchEngine::SearchWildcard(const OUString& strExpression, sal_Int32& nFieldPos,
FieldCollection::iterator& iterFieldLoop, const FieldCollection::iterator& iterBegin, const FieldCollection::iterator& iterEnd)
{
// die Startposition merken
Any aStartMark;
try { aStartMark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
FieldCollection::iterator iterInitialField = iterFieldLoop;
WildCard aSearchExpression(strExpression);
bool bFound(false);
bool bMovedAround(false);
do
{
if (m_eMode == SM_ALLOWSCHEDULE)
{
Application::Reschedule();
Application::Reschedule();
// do 2 reschedules because of #70226# : some things done within this loop's body may cause an user event
// to be posted (deep within vcl), and these user events will be handled before any keyinput or paintings
// or anything like that. So within each loop we create one user event and hanel one user event (and no
// paintings and these), so the office seems to be frozen while searching.
// FS - 70226 - 02.12.99
}
// der aktuell zu vergleichende Inhalt
OUString sCurrentCheck;
if (m_bFormatter)
sCurrentCheck = FormatField(nFieldPos);
else
sCurrentCheck = iterFieldLoop->xContents->getString();
if (!GetCaseSensitive())
// norm the string
sCurrentCheck = m_aCharacterClassficator.lowercase(sCurrentCheck);
// jetzt ist der Test einfach ...
bFound = aSearchExpression.Matches(sCurrentCheck);
if (bFound)
break;
// naechstes Feld (implizit naechster Datensatz, wenn noetig)
if (!MoveField(nFieldPos, iterFieldLoop, iterBegin, iterEnd))
{ // beim Bewegen auf das naechste Feld ging was schief ... weitermachen ist nicht drin, da das naechste Mal genau
// das selbe bestimmt wieder schief geht, also Abbruch
// vorher aber noch, damit das Weitersuchen an der aktuellen Position weitermacht :
try { m_aPreviousLocBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
m_iterPreviousLocField = iterFieldLoop;
// und wech
return SR_ERROR;
}
Any aCurrentBookmark;
try { aCurrentBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
bMovedAround = EQUAL_BOOKMARKS(aStartMark, aCurrentBookmark) && (iterFieldLoop == iterInitialField);
if (nFieldPos == 0)
// das heisst, ich habe mich auf einen neuen Datensatz bewegt
PropagateProgress(bMovedAround);
// if we moved to the starting position we don't have to propagate an 'overflow' message
// FS - 07.12.99 - 68530
// abbrechen gefordert ?
if (CancelRequested())
return SR_CANCELED;
} while (!bMovedAround);
return bFound ? SR_FOUND : SR_NOTFOUND;
}
FmSearchEngine::SEARCH_RESULT FmSearchEngine::SearchRegularApprox(const OUString& strExpression, sal_Int32& nFieldPos,
FieldCollection::iterator& iterFieldLoop, const FieldCollection::iterator& iterBegin, const FieldCollection::iterator& iterEnd)
{
DBG_ASSERT(m_bLevenshtein || m_bRegular,
"FmSearchEngine::SearchRegularApprox : ungueltiger Suchmodus !");
DBG_ASSERT(!m_bLevenshtein || !m_bRegular,
"FmSearchEngine::SearchRegularApprox : kann nicht nach regulaeren Ausdruecken und nach Aehnlichkeiten gleichzeitig suchen !");
// Startposition merken
Any aStartMark;
try { aStartMark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
FieldCollection::iterator iterInitialField = iterFieldLoop;
// Parameter sammeln
SearchOptions aParam;
aParam.algorithmType = m_bRegular ? SearchAlgorithms_REGEXP : SearchAlgorithms_APPROXIMATE;
aParam.searchFlag = 0;
aParam.transliterateFlags = GetTransliterationFlags();
if ( !GetTransliteration() )
{ // if transliteration is not enabled, the only flags which matter are IGNORE_CASE and IGNORE_WIDTH
aParam.transliterateFlags &= TransliterationModules_IGNORE_CASE | TransliterationModules_IGNORE_WIDTH;
}
if (m_bLevenshtein)
{
if (m_bLevRelaxed)
aParam.searchFlag |= SearchFlags::LEV_RELAXED;
aParam.changedChars = m_nLevOther;
aParam.deletedChars = m_nLevShorter;
aParam.insertedChars = m_nLevLonger;
}
aParam.searchString = strExpression;
aParam.Locale = SvtSysLocale().GetLanguageTag().getLocale();
::utl::TextSearch aLocalEngine(aParam);
bool bFound = false;
bool bMovedAround(false);
do
{
if (m_eMode == SM_ALLOWSCHEDULE)
{
Application::Reschedule();
Application::Reschedule();
// do 2 reschedules because of #70226# : some things done within this loop's body may cause an user event
// to be posted (deep within vcl), and these user events will be handled before any keyinput or paintings
// or anything like that. So within each loop we create one user event and handle one user event (and no
// paintings and these), so the office seems to be frozen while searching.
// FS - 70226 - 02.12.99
}
// der aktuell zu vergleichende Inhalt
OUString sCurrentCheck;
if (m_bFormatter)
sCurrentCheck = FormatField(nFieldPos);
else
sCurrentCheck = iterFieldLoop->xContents->getString();
// (don't care about case here, this is done by the TextSearch object, 'cause we passed our case parameter to it)
sal_Int32 nStart = 0, nEnd = sCurrentCheck.getLength();
bFound = aLocalEngine.SearchForward(sCurrentCheck, &nStart, &nEnd);
// das heisst hier 'forward' aber das bezieht sich nur auf die Suche innerhalb von sCurrentCheck, hat also mit
// der Richtung meines Datensatz-Durchwanderns nix zu tun (darum kuemmert sich MoveField)
// checken, ob die Position stimmt
if (bFound)
{
switch (m_nPosition)
{
case MATCHING_WHOLETEXT :
if (nEnd != sCurrentCheck.getLength())
{
bFound = false;
break;
}
// laeuft in den naechsten Case rein !
case MATCHING_BEGINNING :
if (nStart != 0)
bFound = false;
break;
case MATCHING_END :
if (nEnd != sCurrentCheck.getLength())
bFound = false;
break;
}
}
if (bFound) // immer noch ?
break;
// naechstes Feld (implizit naechster Datensatz, wenn noetig)
if (!MoveField(nFieldPos, iterFieldLoop, iterBegin, iterEnd))
{ // beim Bewegen auf das naechste Feld ging was schief ... weitermachen ist nicht drin, da das naechste Mal genau
// das selbe bestimmt wieder schief geht, also Abbruch (ohne Fehlermeldung, von der erwarte ich, dass sie im Move
// angezeigt wurde)
// vorher aber noch, damit das Weitersuchen an der aktuellen Position weitermacht :
try { m_aPreviousLocBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
m_iterPreviousLocField = iterFieldLoop;
// und wech
return SR_ERROR;
}
Any aCurrentBookmark;
try { aCurrentBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); return SR_ERROR; }
bMovedAround = EQUAL_BOOKMARKS(aStartMark, aCurrentBookmark) && (iterFieldLoop == iterInitialField);
if (nFieldPos == 0)
// das heisst, ich habe mich auf einen neuen Datensatz bewegt
PropagateProgress(bMovedAround);
// if we moved to the starting position we don't have to propagate an 'overflow' message
// FS - 07.12.99 - 68530
// abbrechen gefordert ?
if (CancelRequested())
return SR_CANCELED;
} while (!bMovedAround);
return bFound ? SR_FOUND : SR_NOTFOUND;
}
FmSearchEngine::FmSearchEngine(const Reference< XComponentContext >& _rxContext,
const Reference< XResultSet > & xCursor, const OUString& sVisibleFields,
const Reference< XNumberFormatsSupplier > & xFormatSupplier, FMSEARCH_MODE eMode)
:m_xSearchCursor(xCursor)
,m_xFormatSupplier(xFormatSupplier)
,m_aCharacterClassficator( _rxContext, SvtSysLocale().GetLanguageTag() )
,m_aStringCompare( _rxContext )
,m_nCurrentFieldIndex(-2) // -1 hat schon eine Bedeutung, also nehme ich -2 fuer 'ungueltig'
,m_bUsingTextComponents(false)
,m_eSearchForType(SEARCHFOR_STRING)
,m_srResult(SR_FOUND)
,m_bSearchingCurrently(false)
,m_bCancelAsynchRequest(false)
,m_eMode(eMode)
,m_bFormatter(false)
,m_bForward(false)
,m_bWildcard(false)
,m_bRegular(false)
,m_bLevenshtein(false)
,m_bTransliteration(false)
,m_bLevRelaxed(false)
,m_nLevOther(0)
,m_nLevShorter(0)
,m_nLevLonger(0)
,m_nPosition(MATCHING_ANYWHERE)
,m_nTransliterationFlags(0)
{
m_xFormatter = Reference< ::com::sun::star::util::XNumberFormatter >(
::com::sun::star::util::NumberFormatter::create( ::comphelper::getProcessComponentContext() ),
UNO_QUERY_THROW);
m_xFormatter->attachNumberFormatsSupplier(m_xFormatSupplier);
Init(sVisibleFields);
}
FmSearchEngine::FmSearchEngine(const Reference< XComponentContext >& _rxContext,
const Reference< XResultSet > & xCursor, const OUString& sVisibleFields,
const InterfaceArray& arrFields, FMSEARCH_MODE eMode)
:m_xSearchCursor(xCursor)
,m_aCharacterClassficator( _rxContext, SvtSysLocale().GetLanguageTag() )
,m_aStringCompare( _rxContext )
,m_nCurrentFieldIndex(-2) // -1 hat schon eine Bedeutung, also nehme ich -2 fuer 'ungueltig'
,m_bUsingTextComponents(true)
,m_xOriginalIterator(xCursor)
,m_xClonedIterator(m_xOriginalIterator, true)
,m_eSearchForType(SEARCHFOR_STRING)
,m_srResult(SR_FOUND)
,m_bSearchingCurrently(false)
,m_bCancelAsynchRequest(false)
,m_eMode(eMode)
,m_bFormatter(true) // das muss konsistent sein mit m_xSearchCursor, der i.A. == m_xOriginalIterator ist
,m_bForward(false)
,m_bWildcard(false)
,m_bRegular(false)
,m_bLevenshtein(false)
,m_bTransliteration(false)
,m_bLevRelaxed(false)
,m_nLevOther(0)
,m_nLevShorter(0)
,m_nLevLonger(0)
,m_nPosition(MATCHING_ANYWHERE)
,m_nTransliterationFlags(0)
{
fillControlTexts(arrFields);
Init(sVisibleFields);
}
FmSearchEngine::~FmSearchEngine()
{
clearControlTexts();
}
void FmSearchEngine::SetIgnoreWidthCJK(bool bSet)
{
if (bSet)
m_nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
else
m_nTransliterationFlags &= ~TransliterationModules_IGNORE_WIDTH;
}
bool FmSearchEngine::GetIgnoreWidthCJK() const
{
return 0 != (m_nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
}
void FmSearchEngine::SetCaseSensitive(bool bSet)
{
if (bSet)
m_nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
else
m_nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
}
bool FmSearchEngine::GetCaseSensitive() const
{
return 0 == (m_nTransliterationFlags & TransliterationModules_IGNORE_CASE);
}
void FmSearchEngine::clearControlTexts()
{
for ( ControlTextSuppliers::iterator aIter = m_aControlTexts.begin();
aIter < m_aControlTexts.end();
++aIter
)
{
delete *aIter;
}
m_aControlTexts.clear();
}
void FmSearchEngine::fillControlTexts(const InterfaceArray& arrFields)
{
clearControlTexts();
Reference< XInterface > xCurrent;
for (sal_uInt32 i=0; i<arrFields.size(); ++i)
{
xCurrent = arrFields.at(i);
DBG_ASSERT(xCurrent.is(), "FmSearchEngine::fillControlTexts : invalid field interface !");
// check which type of control this is
Reference< ::com::sun::star::awt::XTextComponent > xAsText(xCurrent, UNO_QUERY);
if (xAsText.is())
{
m_aControlTexts.insert(m_aControlTexts.end(), new SimpleTextWrapper(xAsText));
continue;
}
Reference< ::com::sun::star::awt::XListBox > xAsListBox(xCurrent, UNO_QUERY);
if (xAsListBox.is())
{
m_aControlTexts.insert(m_aControlTexts.end(), new ListBoxWrapper(xAsListBox));
continue;
}
Reference< ::com::sun::star::awt::XCheckBox > xAsCheckBox(xCurrent, UNO_QUERY);
DBG_ASSERT(xAsCheckBox.is(), "FmSearchEngine::fillControlTexts : invalid field interface (no supported type) !");
// we don't have any more options ...
m_aControlTexts.insert(m_aControlTexts.end(), new CheckBoxWrapper(xAsCheckBox));
}
}
void FmSearchEngine::Init(const OUString& sVisibleFields)
{
// analyze the fields
// additionally, create the mapping: because the list of used columns can be shorter than the list
// of columns of the cursor, we need a mapping: "used column numer n" -> "cursor column m"
m_arrFieldMapping.clear();
// important: The case of the columns does not need to be exact - for instance:
// - a user created a form which works on a table, for which the driver returns a column name "COLUMN"
// - the driver itself works case-insensitve with column names
// - a control in the form is bound to "column" - not the different case
// In such a scenario, the form and the field would work okay, but we here need to case for the different case
// explicitly
// #i8755#
// so first of all, check if the database handles identifiers case sensitive
Reference< XConnection > xConn;
Reference< XDatabaseMetaData > xMeta;
Reference< XPropertySet > xCursorProps( IFACECAST( m_xSearchCursor ), UNO_QUERY );
if ( xCursorProps.is() )
{
try
{
xCursorProps->getPropertyValue( FM_PROP_ACTIVE_CONNECTION ) >>= xConn;
}
catch( const Exception& ) { /* silent this - will be asserted below */ }
}
if ( xConn.is() )
xMeta = xConn->getMetaData();
OSL_ENSURE( xMeta.is(), "FmSearchEngine::Init: very strange cursor (could not derive connection meta data from it)!" );
bool bCaseSensitiveIdentifiers = true; // assume case sensivity
if ( xMeta.is() )
bCaseSensitiveIdentifiers = xMeta->supportsMixedCaseQuotedIdentifiers();
// now that we have this information, we need a collator which is able to case (in)sentively compare strings
m_aStringCompare.loadDefaultCollator( SvtSysLocale().GetLanguageTag().getLocale(),
bCaseSensitiveIdentifiers ? 0 : ::com::sun::star::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
try
{
// der Cursor kann mir einen Record (als PropertySet) liefern, dieser unterstuetzt den DatabaseRecord-Service
Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(IFACECAST(m_xSearchCursor), UNO_QUERY);
DBG_ASSERT(xSupplyCols.is(), "FmSearchEngine::Init : invalid cursor (no columns supplier) !");
Reference< ::com::sun::star::container::XNameAccess > xAllFieldNames = xSupplyCols->getColumns();
Sequence< OUString > seqFieldNames = xAllFieldNames->getElementNames();
OUString* pFieldNames = seqFieldNames.getArray();
OUString sCurrentField;
OUString sVis(sVisibleFields.getStr());
sal_Int32 nIndex = 0;
do
{
sCurrentField = sVis.getToken(0, ';' , nIndex);
// in der Feld-Sammlung suchen
sal_Int32 nFoundIndex = -1;
for (sal_Int32 j=0; j<seqFieldNames.getLength(); ++j, ++pFieldNames)
{
if ( 0 == m_aStringCompare.compareString( *pFieldNames, sCurrentField ) )
{
nFoundIndex = j;
break;
}
}
// set the field selection back to the first
pFieldNames = seqFieldNames.getArray();
DBG_ASSERT(nFoundIndex != -1, "FmSearchEngine::Init : Invalid field name were given !");
m_arrFieldMapping.push_back(nFoundIndex);
}
while ( nIndex >= 0 );
}
catch (const Exception&)
{
OSL_FAIL("Exception occurred!");
}
}
void FmSearchEngine::SetFormatterUsing(bool bSet)
{
if (m_bFormatter == bSet)
return;
m_bFormatter = bSet;
if (m_bUsingTextComponents)
{
// ich benutzte keinen Formatter, sondern TextComponents -> der SearchIterator muss angepasst werden
try
{
if (m_bFormatter)
{
DBG_ASSERT(m_xSearchCursor == m_xClonedIterator, "FmSearchEngine::SetFormatterUsing : inkonsistenter Zustand !");
m_xSearchCursor = m_xOriginalIterator;
m_xSearchCursor.moveToBookmark(m_xClonedIterator.getBookmark());
// damit ich mit dem neuen Iterator wirklich dort weitermache, wo ich vorher aufgehoert habe
}
else
{
DBG_ASSERT(m_xSearchCursor == m_xOriginalIterator, "FmSearchEngine::SetFormatterUsing : inkonsistenter Zustand !");
m_xSearchCursor = m_xClonedIterator;
m_xSearchCursor.moveToBookmark(m_xOriginalIterator.getBookmark());
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
// ich muss die Fields neu binden, da der Textaustausch eventuell ueber diese Fields erfolgt und sich der unterliegende Cursor
// geaendert hat
RebuildUsedFields(m_nCurrentFieldIndex, true);
}
else
InvalidatePreviousLoc();
}
void FmSearchEngine::PropagateProgress(bool _bDontPropagateOverflow)
{
if (m_aProgressHandler.IsSet())
{
FmSearchProgress aProgress;
try
{
aProgress.aSearchState = FmSearchProgress::STATE_PROGRESS;
aProgress.nCurrentRecord = m_xSearchCursor.getRow() - 1;
if (m_bForward)
aProgress.bOverflow = !_bDontPropagateOverflow && m_xSearchCursor.isFirst();
else
aProgress.bOverflow = !_bDontPropagateOverflow && m_xSearchCursor.isLast();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
m_aProgressHandler.Call(&aProgress);
}
}
void FmSearchEngine::SearchNextImpl()
{
DBG_ASSERT(!(m_bWildcard && m_bRegular) && !(m_bRegular && m_bLevenshtein) && !(m_bLevenshtein && m_bWildcard),
"FmSearchEngine::SearchNextImpl : Suchparameter schliessen sich gegenseitig aus !");
DBG_ASSERT(m_xSearchCursor.is(), "FmSearchEngine::SearchNextImpl : habe ungueltigen Iterator !");
// die Parameter der Suche
OUString strSearchExpression(m_strSearchExpression); // brauche ich non-const
if (!GetCaseSensitive())
// norm the string
strSearchExpression = m_aCharacterClassficator.lowercase(strSearchExpression);
if (!m_bRegular && !m_bLevenshtein)
{ // 'normale' Suche fuehre ich auf jeden Fall ueber WildCards durch, muss aber vorher je nach Modus den OUString anpassen
if (!m_bWildcard)
{ // da natuerlich in allen anderen Faellen auch * und ? im Suchstring erlaubt sind, aber nicht als WildCards zaehlen
// sollen, muss ich normieren
OUString aTmp(strSearchExpression);
const OUString s_sStar("\\*");
const OUString s_sQuotation("\\?");
aTmp = aTmp.replaceAll("*", s_sStar);
aTmp = aTmp.replaceAll("?", s_sQuotation);
strSearchExpression = aTmp;
switch (m_nPosition)
{
case MATCHING_ANYWHERE :
strSearchExpression = "*" + strSearchExpression + "*";
break;
case MATCHING_BEGINNING :
strSearchExpression = strSearchExpression + "*";
break;
case MATCHING_END :
strSearchExpression = "*" + strSearchExpression;
break;
case MATCHING_WHOLETEXT :
break;
default :
OSL_FAIL("FmSearchEngine::SearchNextImpl() : die Methoden-Listbox duerfte nur 4 Eintraege enthalten ...");
}
}
}
// fuer Arbeit auf Feldliste
FieldCollection::iterator iterBegin = m_arrUsedFields.begin();
FieldCollection::iterator iterEnd = m_arrUsedFields.end();
FieldCollection::iterator iterFieldCheck;
sal_Int32 nFieldPos;
if (HasPreviousLoc())
{
DBG_ASSERT(EQUAL_BOOKMARKS(m_aPreviousLocBookmark, m_xSearchCursor.getBookmark()),
"FmSearchEngine::SearchNextImpl : ungueltige Position !");
iterFieldCheck = m_iterPreviousLocField;
// im Feld nach (oder vor) der letzten Fundstelle weitermachen
nFieldPos = iterFieldCheck - iterBegin;
MoveField(nFieldPos, iterFieldCheck, iterBegin, iterEnd);
}
else
{
if (m_bForward)
iterFieldCheck = iterBegin;
else
{
iterFieldCheck = iterEnd;
--iterFieldCheck;
}
nFieldPos = iterFieldCheck - iterBegin;
}
PropagateProgress(true);
SEARCH_RESULT srResult;
if (m_eSearchForType != SEARCHFOR_STRING)
srResult = SearchSpecial(m_eSearchForType == SEARCHFOR_NULL, nFieldPos, iterFieldCheck, iterBegin, iterEnd);
else if (!m_bRegular && !m_bLevenshtein)
srResult = SearchWildcard(strSearchExpression, nFieldPos, iterFieldCheck, iterBegin, iterEnd);
else
srResult = SearchRegularApprox(strSearchExpression, nFieldPos, iterFieldCheck, iterBegin, iterEnd);
m_srResult = srResult;
if (SR_ERROR == m_srResult)
return;
// gefunden ?
if (SR_FOUND == m_srResult)
{
// die Pos merken
try { m_aPreviousLocBookmark = m_xSearchCursor.getBookmark(); }
catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
m_iterPreviousLocField = iterFieldCheck;
}
else
// die "letzte Fundstelle" invalidieren
InvalidatePreviousLoc();
}
IMPL_LINK(FmSearchEngine, OnSearchTerminated, FmSearchThread*, /*pThread*/)
{
if (!m_aProgressHandler.IsSet())
return 0L;
FmSearchProgress aProgress;
try
{
switch (m_srResult)
{
case SR_ERROR :
aProgress.aSearchState = FmSearchProgress::STATE_ERROR;
break;
case SR_FOUND :
aProgress.aSearchState = FmSearchProgress::STATE_SUCCESSFULL;
aProgress.aBookmark = m_aPreviousLocBookmark;
aProgress.nFieldIndex = m_iterPreviousLocField - m_arrUsedFields.begin();
break;
case SR_NOTFOUND :
aProgress.aSearchState = FmSearchProgress::STATE_NOTHINGFOUND;
aProgress.aBookmark = m_xSearchCursor.getBookmark();
break;
case SR_CANCELED :
aProgress.aSearchState = FmSearchProgress::STATE_CANCELED;
aProgress.aBookmark = m_xSearchCursor.getBookmark();
break;
}
aProgress.nCurrentRecord = m_xSearchCursor.getRow() - 1;
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
// per definitionem muss der Link Thread-sicher sein (das verlange ich einfach), so dass ich mich um so etwas hier nicht kuemmern muss
m_aProgressHandler.Call(&aProgress);
m_bSearchingCurrently = false;
return 0L;
}
IMPL_LINK(FmSearchEngine, OnNewRecordCount, void*, pCounterAsVoid)
{
if (!m_aProgressHandler.IsSet())
return 0L;
FmSearchProgress aProgress;
aProgress.nCurrentRecord = reinterpret_cast<sal_uIntPtr>(pCounterAsVoid);
aProgress.aSearchState = FmSearchProgress::STATE_PROGRESS_COUNTING;
m_aProgressHandler.Call(&aProgress);
return 0L;
}
bool FmSearchEngine::CancelRequested()
{
m_aCancelAsynchAccess.acquire();
bool bReturn = m_bCancelAsynchRequest;
m_aCancelAsynchAccess.release();
return bReturn;
}
void FmSearchEngine::CancelSearch()
{
m_aCancelAsynchAccess.acquire();
m_bCancelAsynchRequest = true;
m_aCancelAsynchAccess.release();
}
bool FmSearchEngine::SwitchToContext(const Reference< ::com::sun::star::sdbc::XResultSet > & xCursor, const OUString& sVisibleFields, const InterfaceArray& arrFields,
sal_Int32 nFieldIndex)
{
DBG_ASSERT(!m_bSearchingCurrently, "FmSearchEngine::SwitchToContext : please do not call while I'm searching !");
if (m_bSearchingCurrently)
return false;
m_xSearchCursor = xCursor;
m_xOriginalIterator = xCursor;
m_xClonedIterator = CursorWrapper(m_xOriginalIterator, true);
m_bUsingTextComponents = true;
fillControlTexts(arrFields);
Init(sVisibleFields);
RebuildUsedFields(nFieldIndex, true);
return true;
}
void FmSearchEngine::ImplStartNextSearch()
{
m_bCancelAsynchRequest = false;
m_bSearchingCurrently = true;
if (m_eMode == SM_USETHREAD)
{
FmSearchThread* pSearcher = new FmSearchThread(this);
// der loescht sich nach Beendigung selber ...
pSearcher->setTerminationHandler(LINK(this, FmSearchEngine, OnSearchTerminated));
pSearcher->createSuspended();
pSearcher->setPriority(osl_Thread_PriorityLowest);
pSearcher->resume();
}
else
{
SearchNextImpl();
LINK(this, FmSearchEngine, OnSearchTerminated).Call(NULL);
}
}
void FmSearchEngine::SearchNext(const OUString& strExpression)
{
m_strSearchExpression = strExpression;
m_eSearchForType = SEARCHFOR_STRING;
ImplStartNextSearch();
}
void FmSearchEngine::SearchNextSpecial(bool _bSearchForNull)
{
m_eSearchForType = _bSearchForNull ? SEARCHFOR_NULL : SEARCHFOR_NOTNULL;
ImplStartNextSearch();
}
void FmSearchEngine::StartOver(const OUString& strExpression)
{
try
{
if (m_bForward)
m_xSearchCursor.first();
else
m_xSearchCursor.last();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
return;
}
InvalidatePreviousLoc();
SearchNext(strExpression);
}
void FmSearchEngine::StartOverSpecial(bool _bSearchForNull)
{
try
{
if (m_bForward)
m_xSearchCursor.first();
else
m_xSearchCursor.last();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
return;
}
InvalidatePreviousLoc();
SearchNextSpecial(_bSearchForNull);
}
void FmSearchEngine::InvalidatePreviousLoc()
{
m_aPreviousLocBookmark.setValue(0,cppu::UnoType<void>::get());
m_iterPreviousLocField = m_arrUsedFields.end();
}
void FmSearchEngine::RebuildUsedFields(sal_Int32 nFieldIndex, bool bForce)
{
if (!bForce && (nFieldIndex == m_nCurrentFieldIndex))
return;
// (da ich keinen Wechsel des Iterators von aussen zulasse, heisst selber ::com::sun::star::sdbcx::Index auch immer selbe Spalte, also habe ich nix zu tun)
DBG_ASSERT((nFieldIndex == -1) ||
((nFieldIndex >= 0) &&
(static_cast<size_t>(nFieldIndex) < m_arrFieldMapping.size())),
"FmSearchEngine::RebuildUsedFields : nFieldIndex is invalid!");
// alle Felder, die ich durchsuchen muss, einsammeln
m_arrUsedFields.clear();
if (nFieldIndex == -1)
{
Reference< ::com::sun::star::container::XIndexAccess > xFields;
for (size_t i=0; i<m_arrFieldMapping.size(); ++i)
{
Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(IFACECAST(m_xSearchCursor), UNO_QUERY);
DBG_ASSERT(xSupplyCols.is(), "FmSearchEngine::RebuildUsedFields : invalid cursor (no columns supplier) !");
xFields = Reference< ::com::sun::star::container::XIndexAccess > (xSupplyCols->getColumns(), UNO_QUERY);
BuildAndInsertFieldInfo(xFields, m_arrFieldMapping[i]);
}
}
else
{
Reference< ::com::sun::star::container::XIndexAccess > xFields;
Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(IFACECAST(m_xSearchCursor), UNO_QUERY);
DBG_ASSERT(xSupplyCols.is(), "FmSearchEngine::RebuildUsedFields : invalid cursor (no columns supplier) !");
xFields = Reference< ::com::sun::star::container::XIndexAccess > (xSupplyCols->getColumns(), UNO_QUERY);
BuildAndInsertFieldInfo(xFields, m_arrFieldMapping[static_cast< size_t >(nFieldIndex)]);
}
m_nCurrentFieldIndex = nFieldIndex;
// und natuerlich beginne ich die naechste Suche wieder jungfraeulich
InvalidatePreviousLoc();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|