/*************************************************************************** * Copyright (C) 2006 by Ian Reinhart Geiser * * geiseri@yahoo.com * * Based off of macspellchecker.mm by Trolltech. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "macspell.h" #include "mac_private.h" #include #include #import #include #include bool QMacSpell::checkWord( const QString &word) { const QtMacCocoaAutoReleasePool pool; const QtCFString string(word); const NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:(NSString *)(CFStringRef)string startingAt:0]; if( range.location == INT_MAX ) return true; else return false; } QStringList QMacSpell::getSuggestions( const QString &word) { const QtMacCocoaAutoReleasePool pool; NSArray * const array = [[NSSpellChecker sharedSpellChecker] guessesForWord : (NSString *)QtCFString::toCFStringRef(word)]; QStringList suggestions; if (array == 0) return suggestions; for (unsigned int i = 0; i < [array count]; ++i) { QString suggestion = QtCFString::toQString((CFStringRef)[array objectAtIndex: i]); if( suggestion != word ) suggestions.append( suggestion ); } return suggestions; }