TextEditorWrapper.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #include "TextEditorWrapper.h"
  2. #include "TextEditor.h"
  3. #include "WrapperConverter.h"
  4. IggTextEditorLanguageDefinition IggNewLanguageDef()
  5. {
  6. TextEditor::LanguageDefinition *ld = new TextEditor::LanguageDefinition();
  7. return static_cast<IggTextEditorLanguageDefinition>(ld);
  8. }
  9. void IggTextEditorLDSetName(IggTextEditorLanguageDefinition handle, const char *name)
  10. {
  11. TextEditor::LanguageDefinition *ld = reinterpret_cast<TextEditor::LanguageDefinition*>(handle);
  12. ld->mName = name;
  13. }
  14. void IggTextEditorLDSetKeywords(IggTextEditorLanguageDefinition handle, const char **keywords, int length)
  15. {
  16. TextEditor::LanguageDefinition *ld = reinterpret_cast<TextEditor::LanguageDefinition*>(handle);
  17. int i = 0;
  18. for (i = 0; i < length; i++)
  19. ld->mKeywords.insert(keywords[i]);
  20. }
  21. IggTextEditor IggNewTextEditor()
  22. {
  23. TextEditor *editor = new TextEditor();
  24. return static_cast<IggTextEditor>(editor);
  25. }
  26. void IggTextEditorRender(IggTextEditor handle, const char* aTitle, IggVec2 const *size, int aBorder)
  27. {
  28. Vec2Wrapper sizeArg(size);
  29. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  30. editor->Render(aTitle, *sizeArg, aBorder != 0);
  31. }
  32. void IggTextEditorSetShowWhitespaces(IggTextEditor handle, int aValue)
  33. {
  34. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  35. editor->SetShowWhitespaces(aValue != 0);
  36. }
  37. void IggTextEditorSetTabSize(IggTextEditor handle, int size)
  38. {
  39. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  40. editor->SetTabSize(size);
  41. }
  42. void IggTextEditorSetText(IggTextEditor handle, const char* text)
  43. {
  44. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  45. editor->SetText(text);
  46. }
  47. void IggTextEditorInsertText(IggTextEditor handle, const char *text)
  48. {
  49. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  50. editor->InsertText(text);
  51. }
  52. IggBool IggTextEditorHasSelection(IggTextEditor handle)
  53. {
  54. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  55. return editor->HasSelection() ? 1 : 0;
  56. }
  57. char const *IggTextEditorGetText(IggTextEditor handle)
  58. {
  59. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  60. std::string str = editor->GetText();
  61. char* c = strcpy(new char[str.length() + 1], str.c_str());
  62. return c;
  63. }
  64. char const *IggTextEditorGetWordUnderCursor(IggTextEditor handle)
  65. {
  66. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  67. std::string str = editor->GetWordUnderCursor();
  68. char* c = strcpy(new char[str.length() + 1], str.c_str());
  69. return c;
  70. }
  71. char const *IggTextEditorGetSelectedText(IggTextEditor handle)
  72. {
  73. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  74. std::string str = editor->GetSelectedText();
  75. char* c = strcpy(new char[str.length() + 1], str.c_str());
  76. return c;
  77. }
  78. char const *IggTextEditorGetCurrentLineText(IggTextEditor handle)
  79. {
  80. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  81. std::string str = editor->GetCurrentLineText();
  82. char* c = strcpy(new char[str.length() + 1], str.c_str());
  83. return c;
  84. }
  85. IggBool IggTextEditorIsTextChanged(IggTextEditor handle)
  86. {
  87. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  88. return editor->IsTextChanged() ? 1 : 0;
  89. }
  90. void IggTextEditorGetScreenCursorPos(IggTextEditor handle, int *x, int* y)
  91. {
  92. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  93. TextEditor::Coordinates col = editor->GetScreenCursorPosition();
  94. *x = (float)col.mColumn;
  95. *y = (float)col.mLine;
  96. }
  97. void IggTextEditorGetCursorPos(IggTextEditor handle, int* column, int* line)
  98. {
  99. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  100. TextEditor::Coordinates col = editor->GetCursorPosition();
  101. *column = (float)col.mColumn;
  102. *line = (float)col.mLine;
  103. }
  104. void IggTextEditorSetCursorPos(IggTextEditor handle, int column, int line)
  105. {
  106. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  107. TextEditor::Coordinates col(line, column);
  108. editor->SetCursorPosition(col);
  109. }
  110. void IggTextEditorGetSelectionStart(IggTextEditor handle, int* column, int* line)
  111. {
  112. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  113. TextEditor::Coordinates col = editor->GetSelectionStart();
  114. *column = (float)col.mColumn;
  115. *line = (float)col.mLine;
  116. }
  117. void IggTextEditorSetLanguageDefinition(IggTextEditor handle, IggTextEditorLanguageDefinition defHandle)
  118. {
  119. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  120. TextEditor::LanguageDefinition *def = static_cast<TextEditor::LanguageDefinition*>(defHandle);
  121. editor->SetLanguageDefinition(*def);
  122. }
  123. void IggTextEditorSetLanguageDefinitionSQL(IggTextEditor handle)
  124. {
  125. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  126. editor->SetLanguageDefinition(TextEditor::LanguageDefinition::SQL());
  127. }
  128. void IggTextEditorSetLanguageDefinitionCPP(IggTextEditor handle)
  129. {
  130. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  131. editor->SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
  132. }
  133. void IggTextEditorSetLanguageDefinitionC(IggTextEditor handle)
  134. {
  135. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  136. editor->SetLanguageDefinition(TextEditor::LanguageDefinition::C());
  137. }
  138. void IggTextEditorSetLanguageDefinitionLua(IggTextEditor handle)
  139. {
  140. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  141. editor->SetLanguageDefinition(TextEditor::LanguageDefinition::Lua());
  142. }
  143. IggTextEditorErrorMarkers IggTextEditorNewErrorMarkers()
  144. {
  145. TextEditor::ErrorMarkers *markers = new TextEditor::ErrorMarkers();
  146. return static_cast<IggTextEditorErrorMarkers>(markers);
  147. }
  148. void IggTextEditorErrorMarkersInsert(IggTextEditorErrorMarkers handle, int pos, const char* errMsg)
  149. {
  150. TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(handle);
  151. markers->insert(std::pair<int, std::string>(pos, errMsg));
  152. }
  153. void IggTextEditorErrorMarkersClear(IggTextEditorErrorMarkers marker)
  154. {
  155. TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(marker);
  156. markers->clear();
  157. }
  158. unsigned int IggTextEditorErrorMarkersSize(IggTextEditorErrorMarkers handle)
  159. {
  160. TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(handle);
  161. return markers->size();
  162. }
  163. void IggTextEditorSetErrorMarkers(IggTextEditor handle, IggTextEditorErrorMarkers marker)
  164. {
  165. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  166. TextEditor::ErrorMarkers *markers = reinterpret_cast<TextEditor::ErrorMarkers*>(marker);
  167. editor->SetErrorMarkers(*markers);
  168. }
  169. void IggTextEditorCopy(IggTextEditor handle)
  170. {
  171. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  172. editor->Copy();
  173. }
  174. void IggTextEditorCut(IggTextEditor handle)
  175. {
  176. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  177. editor->Cut();
  178. }
  179. void IggTextEditorPaste(IggTextEditor handle)
  180. {
  181. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  182. editor->Paste();
  183. }
  184. void IggTextEditorDelete(IggTextEditor handle)
  185. {
  186. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  187. editor->Delete();
  188. }
  189. void IggTextEditorSelectWordUnderCursor(IggTextEditor handle)
  190. {
  191. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  192. editor->SelectWordUnderCursor();
  193. }
  194. void IggTextEditorSelectAll(IggTextEditor handle)
  195. {
  196. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  197. editor->SelectAll();
  198. }
  199. void IggTextEditorSetHandleKeyboardInputs(IggTextEditor handle, int aValue)
  200. {
  201. TextEditor *editor = reinterpret_cast<TextEditor*>(handle);
  202. editor->SetHandleKeyboardInputs(aValue);
  203. }