Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.5 KiB

  1. // FILE: udict.h
  2. // Internal API for User dictionary.
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. // Status values returned from User Dictionary procedures.
  8. enum {
  9. udError, // Externally caused error, E.g. out of memory.
  10. udFail, // Operation failed because requested action not possable.
  11. udSuccess, // Operation completed successfully.
  12. udWordFound, // Word was in dictionary.
  13. udWordNotFound, // Word was NOT in dictionary.
  14. udWordAdded, // Word was added to dictinary.
  15. udWordDeleted, // Word was deleted from dictionary.
  16. udWordChanged, // Word tag information was changed in dictionary.
  17. udNoTag, // Word has no tags.
  18. udStopEarly, // Stop processing early (not an error).
  19. udNumStatus
  20. };
  21. // Flags for UD_NODE_INFO flags field.
  22. #define UDNIF_VALID 0x0001 // End of valid word.
  23. #define UDNIF_HAS_RIGHT 0x0002 // There is a node to the right of this one.
  24. #define UDNIF_HAS_DOWN 0x0004 // There is a node down from of this one.
  25. #define UDNIF_HAS_TAG 0x0008 // Tag information stored for this node.
  26. // Information that can be fetched from a node.
  27. // Note: tags only occur on nodes that are valid.
  28. // Note: if fValid is true and fHasTag is false, then then there is no tag.
  29. // If fHasTag is valid, then you have to
  30. // check out the tags to find out what versions exist (e.g. don't assume that
  31. // an untagged version exists).
  32. typedef struct tagUD_NODE_INFO {
  33. wchar_t wchLabel;
  34. WORD flags; // Node flags.
  35. HANDLE hRight; // Handle on right node, only valid if fHasRight.
  36. HANDLE hDown; // Handle on down node, only valid if fHasDown.
  37. HANDLE hTag; // Handle on tag, only valid if hsHasTag.
  38. } UD_NODE_INFO;
  39. // Longest word allowed in user dictionary.
  40. #define UDICT_MAX_WORD 128
  41. //
  42. // User dictionary APIs.
  43. //
  44. // Create a new User Dictionary
  45. // Return:
  46. // NULL Could not allocate memory for Dictionary
  47. // !NULL Handle on dictionary.
  48. HANDLE UDictCreate();
  49. // Destroy a User Dictionary, free all allocated memory.
  50. // Return:
  51. // udError Error freeing memory
  52. // udSuccess All memory successfully freed.
  53. int UDictDestroy(HANDLE hUDict);
  54. // Get Handle on root node.
  55. // Return:
  56. // udFail User dictionary is empty, no root node available.
  57. // udSuccess Root node successfully filled in.
  58. int UDictRootNode(HANDLE hUDict, HANDLE *phRoot);
  59. // Move one node to the right (e.g. alternate character to current one).
  60. // Fill in phNode with your current node. On success, it will be replaced
  61. // with the new node.
  62. // Return:
  63. // udFail No right node available.
  64. // udSuccess Right node successfully filled in.
  65. int UDictRightNode(HANDLE hUDict, HANDLE *phNode);
  66. // Move one node to the down (e.g. character following current one).
  67. // Fill in *phNode with your current node. On success, it will be replaced
  68. // with the new node.
  69. // Return:
  70. // udFail No down node available.
  71. // udSuccess Right node successfully filled in.
  72. int UDictDownNode(HANDLE hUDict, HANDLE *phNode);
  73. // Fetch the character label on the node.
  74. // Return:
  75. // The character label on the node.
  76. wchar_t UDictNodeLabel(HANDLE hUDict, HANDLE hNode);
  77. // Fetch information about node. Passed in node info structure will be filled
  78. // in with contents of hNode.
  79. // Return:
  80. // udSuccess Node values successfully filled in.
  81. int UDictGetNode(HANDLE hUDict, HANDLE hNode, UD_NODE_INFO *pNodeInfo);
  82. // Fetch tag. You must pass in a valid tag handle.
  83. // Note that the returned pointer is to memory allocated by user dictionary.
  84. // If you want to keep the value around, copy it into memory you control, because
  85. // the returned copy may go away the next time the udict is modified.
  86. // Return:
  87. // !NULL Pointer to tag.
  88. const wchar_t *UDictFetchTag(HANDLE hUDict, HANDLE hTag);
  89. // Add a word to the user dictionary. Optional tag allowed.
  90. // Return:
  91. // udError Could not grow dictinary to hold new word.
  92. // udFail Zero length word can not be added.
  93. // udWordFound Word (and tag) already in dictinary, no update needed.
  94. // udWordAdded Word added to dictionary.
  95. // udWordChanged New word tag was set for existing word in dictionary.
  96. // Note: word and tag are copied into User dictionary, so that callers memory
  97. // may be reused or freed after call returns.
  98. int UDictAddWord(HANDLE hUDict, const wchar_t *pwchWord, const wchar_t *pTag);
  99. // Delete a word from the user dictionary.
  100. // Return:
  101. // udError Error adjusting size of dictionary (?possable?).
  102. // udWordNotFound Word was not in dictionary. no update needed.
  103. // udWordDeleted Word was deleted from dictionary.
  104. int UDictDeleteWord(HANDLE hUDict, const wchar_t *pwchWord);
  105. // Find a word, also gets its tag if it has one.
  106. // Return:
  107. // udWordNotFound Word was not in dictionary, no tag returned.
  108. // udWordFound Word found, tag pointer for node filled in.
  109. // Note that the returned tag pointer is to memory allocated by user dictionary.
  110. // If you want to keep the value around, copy it into memory you control, because
  111. // the returned copy may go away the next time the udict is modified.
  112. int UDictFindWord(
  113. HANDLE hUDict,
  114. const wchar_t *pwchWord,
  115. const wchar_t **ppTag // Out: pointer tag.
  116. );
  117. // Enumerate the tree. Call a callback function for each word in selected range.
  118. // Return:
  119. // udFail Invalid range of words or call back failed.
  120. // udSuccess Right node successfully filled in.
  121. // The enumeration function must return one of the following three values:
  122. // udFail Error in processing, abort traversal and return error.
  123. // udStopEarly Successfully prcessed word, but we don't need to see any more.
  124. // udSuccess Successfully prcessed word, continue to next..
  125. #define UDICT_ENUM_TO_END -1 // Value for lastWord to go to end of dictionary.
  126. typedef int (*P_UD_ENUM_CALL_BACK)(
  127. void *pCallBackData,
  128. int wordNumber,
  129. const wchar_t *pWord,
  130. const wchar_t *pTag
  131. );
  132. int UDictEnumerate(
  133. HANDLE hUDict,
  134. P_UD_ENUM_CALL_BACK pCallBack, // Function to call on each selected word.
  135. void *pCallBackData // Data to pass to callback function
  136. );
  137. // Merge one word list into another
  138. // Supply both the Source and Destination word Lists
  139. // The merge directly merges the tries rather than expanding
  140. // adding
  141. //
  142. // CAVEATES:
  143. // 1) Before merging we allocate enough memory to guarantee
  144. // the merge completes, but this may leave memory unused
  145. // Code changes at the expense of speed will be required to modify this
  146. // 2) If a word in both the source and destination both contain
  147. // tags, we retain only the original (destination) tag.
  148. // (The code does not support multiple tags)
  149. //
  150. // Returns TRUE if the merge completed successfully, FALSE
  151. // otherwise
  152. //
  153. int UDictMerge(HANDLE hUSrc, HANDLE hUDest);
  154. #ifdef __cplusplus
  155. };
  156. #endif