Back to index

texmacs  1.0.7.15
Functions | Variables
mac_spellservice.mm File Reference
#include "MacOS/mac_spellservice.h"
#include "converter.hpp"
#include "language.hpp"
#include "Cocoa/mac_cocoa.h"

Go to the source code of this file.

Functions

static string from_nsstring (NSString *s)
static NSString * to_nsstring_utf8 (string s)
static bool mac_spelling_language (string lang)
void mac_init_dictionary ()
string mac_spell_start (string lan)
tree mac_spell_check (string lan, string s)
void mac_spell_accept (string lan, string s)
void mac_spell_insert (string lan, string s)
void mac_spell_done (string lan)

Variables

static hashmap< string, stringavailable_dicts ("")
static string current_lang = ""
static NSInteger current_tag = 0

Function Documentation

static string from_nsstring ( NSString *  s) [static]

Definition at line 20 of file mac_spellservice.mm.

                            {
  const char *cstr = [s cStringUsingEncoding:NSUTF8StringEncoding];
  return utf8_to_cork(string((char*)cstr));
}

Here is the call graph for this function:

Definition at line 56 of file mac_spellservice.mm.

                       {
  if (N(available_dicts) == 0) {
    hashmap<string,string> the_dicts ("");

    //FIXME: Complete dictionary list
    the_dicts("en") = "english";
    the_dicts("fr") = "french";
    the_dicts("it") = "italian";

    NSArray *arr = [[NSSpellChecker sharedSpellChecker] availableLanguages];
    NSEnumerator *enumerator = [arr objectEnumerator];
    NSString *nsdict;
    
    while ((nsdict = (NSString*)[enumerator nextObject])) {
      string dict = from_nsstring(nsdict);
//      available_dicts(the_dicts(dict)) = dict;
      available_dicts (locale_to_language (dict)) = dict;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mac_spell_accept ( string  lan,
string  s 
)

Definition at line 144 of file mac_spellservice.mm.

                                        {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  if ((lan != current_lang) && (! mac_spelling_language (lan))) {
    // do nothing
    ;
  } else {
    [[NSSpellChecker sharedSpellChecker]  ignoreWord:to_nsstring_utf8 (s) inSpellDocumentWithTag:current_tag];
  }  
  //  ispell_send (lan, "@" * s);
  [pool release];
}

Here is the call graph for this function:

tree mac_spell_check ( string  lan,
string  s 
)

Definition at line 104 of file mac_spellservice.mm.

                                       {
  if (DEBUG_EVENTS) cout << "spell_check " << lan << " :: " << s << LF;
  tree t;
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  if ((lan != current_lang) && (! mac_spelling_language (lan))) {
      t = "Error: dictionary not available";
  } else {
    NSString *nss = to_nsstring_utf8 (s);
    NSRange r =  [[NSSpellChecker sharedSpellChecker]  
                  checkSpellingOfString: nss
                  startingAt: 0
                  language: nil
                  wrap: NO
                  inSpellDocumentWithTag: current_tag
                  wordCount: NULL];
    if (r.length == 0) 
      t = "ok";
    else {
      NSArray *arr = [[NSSpellChecker sharedSpellChecker] guessesForWord: nss];
      if ([arr count] == 0) {
        t = tree (TUPLE, "0");
      } else {
        NSEnumerator *enumerator = [arr objectEnumerator];
        NSString *sugg;
        tree a (TUPLE);
        while ((sugg = (NSString*)[enumerator nextObject])) {
          a << from_nsstring (sugg);
        }
        t= tree (TUPLE, as_string((int)[arr count]));
        t << A (a);        
      }
    }
  }
  [pool release];

  if (DEBUG_EVENTS)   cout << t << LF;     
  return t;
}

Here is the call graph for this function:

void mac_spell_done ( string  lan)

Definition at line 170 of file mac_spellservice.mm.

                            {
  (void) lan;
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  [[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:current_tag];
  current_tag = 0;
  [pool release];
}
void mac_spell_insert ( string  lan,
string  s 
)

Definition at line 157 of file mac_spellservice.mm.

                                        {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  if ((lan != current_lang) && (! mac_spelling_language (lan))) {
    // do nothing
    ;
  } else {
    [[NSSpellChecker sharedSpellChecker] learnWord:to_nsstring_utf8 (s)];
  }  
  //  ispell_send (lan, "*" * s);
  [pool release];
}

Here is the call graph for this function:

Definition at line 84 of file mac_spellservice.mm.

                             {
  string r;
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  // we need to be sure that the Cocoa application infrastructure is initialized 
  // (apparently Qt does not do this properly and the NSSpellChecker instance returns null
  //  without the following instruction)
  NSApplication *NSApp=[NSApplication sharedApplication]; (void) NSApp;
  mac_init_dictionary ();
  if (mac_spelling_language (lan)) {
    // warning: we must be sure that the tag is relased by the appropriate message to sharedSpellChecker
    current_tag = [NSSpellChecker uniqueSpellDocumentTag];
    r = "ok";
  } else {
    r = "Error: no dictionary for#" * lan;
  }  
  [pool release];
  return r;
}

Here is the call graph for this function:

static bool mac_spelling_language ( string  lang) [static]

Definition at line 44 of file mac_spellservice.mm.

{
  if (available_dicts->contains (lang)) {
    current_lang = lang;
    [[NSSpellChecker sharedSpellChecker]  setLanguage: to_nsstring_utf8(available_dicts(lang))];
    if (DEBUG_EVENTS) cout << "setting lang:"  << lang << LF;
    return true;
    }
  return false;
}

Here is the caller graph for this function:

static NSString* to_nsstring_utf8 ( string  s) [static]

Definition at line 27 of file mac_spellservice.mm.

                            {
  s= cork_to_utf8 (s);
  char *p = as_charp(s);
  NSString *nss = [NSString stringWithCString:p encoding:NSUTF8StringEncoding];
  tm_delete_array (p);      
  return nss;
}

Here is the call graph for this function:


Variable Documentation

string current_lang = "" [static]

Definition at line 41 of file mac_spellservice.mm.

NSInteger current_tag = 0 [static]

Definition at line 42 of file mac_spellservice.mm.