PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/scintilla/dfl/test.d

http://gool.googlecode.com/
D | 106 lines | 75 code | 20 blank | 11 comment | 2 complexity | 5c7819fff05e7b15dc71c7b76c987e2e MD5 | raw file
  1. // This source code is public domain.
  2. // Written by Christopher E. Miller
  3. // Scintilla Control example for DFL
  4. // http://www.dprogramming.com/dfl.php
  5. // http://wiki.dprogramming.com/Dfl/ScintillaControl
  6. // To compile:
  7. // dfl -gui dflscitest.d dflscintilla.lib
  8. // Remember to have access to scilexer.dll from \lib
  9. // For more information on using Scintilla, see http://www.scintilla.org/ScintillaDoc.html
  10. // Scintilla.sendEditor() is used to send messages to a Scintilla control in DFL.
  11. private import dfl.all;
  12. private import dfl.scintilla; // DFL control.
  13. class SciTestForm: dfl.form.Form {
  14. static char[] KeyWords =
  15. "asm auto bool break "
  16. "case catch char class compl const const_cast continue "
  17. "default delete do double dynamic_cast else enum explicit export extern false float for "
  18. "friend goto if inline int long mutable namespace new not not_eq "
  19. "operator or or_eq private protected public "
  20. "register reinterpret_cast return short signed sizeof static static_cast struct switch "
  21. "template this throw true try typedef typeid typename union unsigned using "
  22. "virtual void volatile wchar dchar while xor module ";
  23. static char[] text_1 = " module test ;
  24. // com1
  25. void main(){
  26. int foo = 42 ;
  27. char[] t0 = \"string\" ;
  28. wchar[] t1 = r\"stringr\" ;
  29. dchar[]t2 = `stringb` ;
  30. }
  31. ";
  32. Scintilla sci;
  33. this() {
  34. startPosition = FormStartPosition.WINDOWS_DEFAULT_BOUNDS;
  35. text = "Scintilla Test Form";
  36. //with(sci = new Scintilla("dlex.dll"))
  37. with(sci = new Scintilla) {
  38. text = text_1 ;
  39. dock = DockStyle.FILL;
  40. parent = this;
  41. handleCreated ~= &sci_handleCreated;
  42. }
  43. }
  44. void setAStyle(int style, int fore, int back = 0xffffff, int size = -1, char[] face = null){
  45. with(sci){
  46. sendEditor(SCI_STYLESETFORE , style, fore );
  47. sendEditor(SCI_STYLESETBACK, style, back );
  48. }
  49. if (size >= 1){
  50. sci.sendEditor(SCI_STYLESETSIZE, style, size);
  51. }
  52. if (face){
  53. sci.sendEditor(SCI_STYLESETFONT, style, face);
  54. }
  55. }
  56. private void sci_handleCreated(Object sender, EventArgs ea) {
  57. with(sci){
  58. sendEditor(SCI_SETLEXER, SCLEX_D); // Set the lexer. CPP one is for C/C++/D/etc.
  59. sendEditor(SCI_STYLESETFONT, STYLE_DEFAULT, "Courier New"); // Default font name.
  60. sendEditor(SCI_STYLESETSIZE, STYLE_DEFAULT, 10 ); // Default font size.
  61. sendEditor(SCI_SETKEYWORDS, 0, KeyWords ); // Set keywords.
  62. setAStyle(SCE_D_DEFAULT, 0 );
  63. setAStyle(SCE_D_COMMENT, 0x8000 );
  64. setAStyle(SCE_D_COMMENTLINE, 0x8000);
  65. setAStyle(SCE_D_COMMENTDOC, 0x8000 );
  66. setAStyle(SCE_D_COMMENTLINEDOC, 0x8000 );
  67. setAStyle(SCE_D_COMMENTDOCKEYWORD, 0x8000 );
  68. setAStyle(SCE_D_COMMENTDOCKEYWORDERROR, 0x8000 );
  69. setAStyle(SCE_D_NUMBER, 0x8080 );
  70. setAStyle(SCE_D_WORD, 0xf00000 );
  71. setAStyle(SCE_D_STRING, 0x880000);
  72. setAStyle(SCE_D_STRINGB, 0x8800);
  73. setAStyle(SCE_D_STRINGR, 0x88);
  74. sci.sendEditor(SCI_SETCODEPAGE, SC_CP_UTF8, 0);
  75. }
  76. }
  77. }
  78. int main(){
  79. try{
  80. Application.run(new SciTestForm());
  81. }catch(Object o){
  82. msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
  83. return 1;
  84. }
  85. return 0;
  86. }