kfind.h
00001 /* 00002 Copyright (C) 2001, S.R.Haque <srhaque@iee.org>. 00003 Copyright (C) 2002, David Faure <david@mandrakesoft.com> 00004 This file is part of the KDE project 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2, as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KFIND_H 00022 #define KFIND_H 00023 00024 #include <kdialogbase.h> 00025 #include <tqrect.h> 00026 00103 class TDEUTILS_EXPORT KFind : 00104 public TQObject 00105 { 00106 Q_OBJECT 00107 00108 00109 public: 00110 00118 KFind(const TQString &pattern, long options, TQWidget *parent); 00119 00130 KFind(const TQString &pattern, long options, TQWidget *parent, TQWidget* findDialog); 00131 00135 virtual ~KFind(); 00136 00140 enum Result { 00141 NoMatch, 00142 Match 00143 }; 00144 00151 bool needData() const; 00152 00162 void setData( const TQString& data, int startPos = -1 ); 00163 00177 void setData( int id, const TQString& data, int startPos = -1 ); 00178 00185 Result find(); 00186 00196 long options() const { return m_options; } 00197 00204 virtual void setOptions( long options ); 00205 00209 TQString pattern() const { return m_pattern; } 00210 00215 void setPattern( const TQString& pattern ); 00216 00224 int numMatches() const { return m_matches; } 00225 00232 virtual void resetCounts() { m_matches = 0; } 00233 00244 virtual bool validateMatch( const TQString & text, int index, int matchedlength ) { 00245 Q_UNUSED(text); Q_UNUSED(index); Q_UNUSED(matchedlength); return true; } 00246 00262 virtual bool shouldRestart( bool forceAsking = false, bool showNumMatches = true ) const; 00263 00278 static int find( const TQString &text, const TQString &pattern, int index, long options, int *matchedlength ); 00279 00293 static int find( const TQString &text, const TQRegExp &pattern, int index, long options, int *matchedlength ); 00294 00299 virtual void displayFinalDialog() const; 00300 00309 KDialogBase* findNextDialog( bool create = false ); 00310 00319 void closeFindNextDialog(); 00320 00328 int index() const; 00329 00330 signals: 00331 00348 void highlight(const TQString &text, int matchingIndex, int matchedLength); 00349 00368 void highlight(int id, int matchingIndex, int matchedLength); 00369 00370 // ## TODO docu 00371 // findprevious will also emit findNext, after temporarily switching the value 00372 // of FindBackwards 00373 void findNext(); 00374 00380 void optionsChanged(); 00381 00388 void dialogClosed(); 00389 00390 protected: 00391 00392 TQWidget* parentWidget() const { return (TQWidget *)parent(); } 00393 TQWidget* dialogsParent() const; 00394 00395 protected slots: 00396 00397 void slotFindNext(); 00398 void slotDialogClosed(); 00399 00400 private: 00401 void init( const TQString& pattern ); 00402 void startNewIncrementalSearch(); 00403 00404 static bool isInWord( TQChar ch ); 00405 static bool isWholeWords( const TQString &text, int starts, int matchedLength ); 00406 00407 friend class KReplace; 00408 00409 00410 TQString m_pattern; 00411 TQRegExp *m_regExp; 00412 KDialogBase* m_dialog; 00413 long m_options; 00414 unsigned m_matches; 00415 00416 TQString m_text; // the text set by setData 00417 int m_index; 00418 int m_matchedLength; 00419 bool m_dialogClosed; 00420 bool m_lastResult; 00421 00422 // Binary compatible extensibility. 00423 struct Private; 00424 Private *d; 00425 }; 00426 00427 #endif