home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 August / PCWorld_2000-08_cd.bin / Software / TemaCD / xbasic / xbpro.exe / xb / aeditors.x < prev    next >
Text File  |  1999-05-07  |  7KB  |  296 lines

  1. '
  2. ' ####################
  3. ' #####  PROLOG  #####
  4. ' ####################
  5. '
  6. PROGRAM "aeditors"
  7. VERSION "0.0000"
  8. '
  9. IMPORT  "xst"
  10. IMPORT  "xgr"
  11. IMPORT  "xui"
  12. '
  13. ' This program is a "GuiDesigner convenience function program"
  14. ' version of "editors.x", which does the same thing but is written
  15. ' as a "conventional GuiDesigner" program.
  16. '
  17. INTERNAL FUNCTION  Entry        ()
  18. INTERNAL FUNCTION  CloseWindow  (grid)
  19. INTERNAL FUNCTION  CreateWindow (grid, v0, v1)
  20. INTERNAL FUNCTION  File         (grid, v0, v1, kid)
  21. INTERNAL FUNCTION  FileLoad     (grid)
  22. INTERNAL FUNCTION  FileSave     (grid)
  23. INTERNAL FUNCTION  FileQuit     (grid)
  24. INTERNAL FUNCTION  Edit         (grid, v0, v1, kid)
  25. INTERNAL FUNCTION  EditCut      (grid)
  26. INTERNAL FUNCTION  EditGrab     (grid)
  27. INTERNAL FUNCTION  EditPaste    (grid)
  28. INTERNAL FUNCTION  EditErase    (grid)
  29. '
  30. '
  31. ' ###################
  32. ' #####  Entry  #####
  33. ' ###################
  34. '
  35. FUNCTION  Entry ()
  36.   SHARED  count
  37. '
  38.   $Edit      =   0  ' kid   0 grid type = XuiMenuTextArea1B
  39.   $Menu      =   1  ' kid   1 grid type = XuiMenu
  40.   $Text      =   2  ' kid   2 grid type = XuiTextArea
  41.   $Button    =   3  ' kid   3 grid type = XuiPushButton
  42.   $UpperKid  =   3  ' kid maximum
  43. '
  44. ' get information about the display, windows, and execution environment
  45. '
  46.   XgrGetDisplaySize ("", @dw, @dh, @wbw, @wth)
  47.     XstGetApplicationEnvironment (@standalone, 0)
  48. '
  49. ' standalone programs don't want the console
  50. '
  51.     IF standalone THEN
  52.         XstGetConsoleGrid (@grid)
  53.         XuiSendStringMessage (grid, "HideWindow", 0, 0, 0, 0, 0, 0)
  54.     END IF
  55. '
  56. ' create an initial "editor" window
  57. '
  58.   CreateWindow (@grid, wbw, wbw+wth)
  59. '
  60. ' convenience function message loop
  61. '
  62.   DO
  63.     XgrProcessMessages (1)
  64.     DO WHILE XuiGetNextCallback (@grid, @message$, @v0, @v1, @v2, @v3, @kid, @r1$)
  65.       GOSUB Callback
  66.     LOOP
  67.   LOOP
  68.   RETURN
  69. '
  70. ' *****  Callback  *****
  71. '
  72. SUB Callback
  73.   win = kid >> 16
  74.   kid = kid AND 0xFF
  75.   SELECT CASE message$
  76.     CASE "CloseWindow" : GOSUB CloseWindow
  77.     CASE "Selection"   : GOSUB Selection
  78.   END SELECT
  79. END SUB
  80. '
  81. '
  82. ' *****  CloseWindow  *****
  83. '
  84. SUB CloseWindow
  85.   DEC count
  86.   XuiSendStringMessage (grid, "DestroyWindow", 0, 0, 0, 0, 0, 0)
  87.   IF (count < 0) THEN QUIT (0)
  88. END SUB
  89. '
  90. '
  91. ' *****  Selection  *****
  92. '
  93. SUB Selection
  94.   SELECT CASE kid
  95.     CASE $Edit    :
  96.     CASE $Menu    : GOSUB Menu
  97.     CASE $Text    :
  98.     CASE $Button  : GOSUB Another
  99.   END SELECT
  100. END SUB
  101. '
  102. '
  103. ' *****  Menu  *****
  104. '
  105. SUB Menu
  106.   SELECT CASE v0
  107.     CASE 1  : File (grid, v0, v1, kid)
  108.     CASE 2  : Edit (grid, v0, v1, kid)
  109.   END SELECT
  110. END SUB
  111. '
  112. '
  113. ' *****  Another  *****
  114. '
  115. SUB Another
  116.   INC count
  117.   XuiSendStringMessage (grid, @"GetWindowSize", @wx, @wy, 0, 0, 0, 0)
  118.   CreateWindow (@g, wx+wbw, wy+wbw+wth)
  119. END SUB
  120. END FUNCTION
  121. '
  122. '
  123. ' ############################
  124. ' #####  CloseWindow ()  #####
  125. ' ############################
  126. '
  127. FUNCTION  CloseWindow (grid)
  128.   SHARED  count
  129. '
  130.   DEC count
  131.   XuiSendStringMessage (grid, "DestroyWindow", 0, 0, 0, 0, 0, 0)
  132.   IF (count < 0) THEN QUIT (0)
  133. END FUNCTION
  134. '
  135. '
  136. ' #############################
  137. ' #####  CreateWindow ()  #####
  138. ' #############################
  139. '
  140. FUNCTION  CreateWindow (grid, v0, v1)
  141. '
  142.   XuiCreateWindow      (@grid, @"XuiMenuTextArea1B", v0, v1, 0, 0, 0, "")
  143.   XuiSendStringMessage ( grid, @"SetCallback", grid, &XuiQueueCallbacks(), -1, -1, 0, -1)
  144.   XuiSendStringMessage ( grid, @"SetWindowTitle", 0, 0, 0, 0, 0, @"Editor")
  145.   XuiSendStringMessage ( grid, @"SetGridName", 0, 0, 0, 0, 0, @"Editor")
  146.   XuiSendStringMessage ( grid, @"DisplayWindow", 0, 0, 0, 0, 0, 0)
  147. END FUNCTION
  148. '
  149. '
  150. ' #####################
  151. ' #####  File ()  #####
  152. ' #####################
  153. '
  154. FUNCTION  File (grid, v0, v1, kid)
  155. '
  156.   SELECT CASE v1
  157.     CASE 0  : FileLoad (grid)
  158.     CASE 1  : FileSave (grid)
  159.     CASE 2  : FileQuit (grid)
  160.   END SELECT
  161. END FUNCTION
  162. '
  163. '
  164. ' #########################
  165. ' #####  FileLoad ()  #####
  166. ' #########################
  167. '
  168. FUNCTION  FileLoad (grid)
  169. '
  170.   gridType$ = "XuiFile"
  171.   title$ = "Select File"
  172.   message$ = ""
  173.   strings$ = ""
  174.   reply$ = ""
  175.   XuiGetResponse (@gridType$, @title$, @message$, @strings$, @v0, @v1, @kid, @reply$)
  176.   IF reply$ THEN
  177.     XstLoadStringArray (@reply$, @text$[])
  178.     XuiSendStringMessage (grid, "SetTextArray", 0, 0, 0, 0, 2, @text$[])
  179.     XuiSendStringMessage (grid, "Redraw", 0, 0, 0, 0, 0, 0)
  180.   END IF
  181. END FUNCTION
  182. '
  183. '
  184. ' #########################
  185. ' #####  FileSave ()  #####
  186. ' #########################
  187. '
  188. FUNCTION  FileSave (grid)
  189. '
  190.   gridType$ = "XuiFile"
  191.   title$ = "Select File"
  192.   message$ = ""
  193.   strings$ = ""
  194.   reply$ = ""
  195.   XuiGetResponse (@gridType$, @title$, @message$, @strings$, @v0, @v1, @kid, @reply$)
  196.   IF reply$ THEN
  197.     XuiSendStringMessage (grid, "GetTextArray", 0, 0, 0, 0, 2, @text$[])
  198.     XstSaveStringArray (@reply$, @text$[])
  199.   END IF
  200. END FUNCTION
  201. '
  202. '
  203. ' #########################
  204. ' #####  FileQuit ()  #####
  205. ' #########################
  206. '
  207. FUNCTION  FileQuit (grid)
  208.   CloseWindow (grid)
  209. END FUNCTION
  210. '
  211. '
  212. ' #####################
  213. ' #####  Edit ()  #####
  214. ' #####################
  215. '
  216. FUNCTION  Edit (grid, v0, v1, kid)
  217. '
  218.   SELECT CASE v1
  219.     CASE 0  : EditCut (grid)
  220.     CASE 1  : EditGrab (grid)
  221.     CASE 2  : EditPaste (grid)
  222.     CASE 3  : EditErase (grid)
  223.   END SELECT
  224. END FUNCTION
  225. '
  226. '
  227. ' ########################
  228. ' #####  EditCut ()  #####
  229. ' ########################
  230. '
  231. FUNCTION  EditCut (grid)
  232.     UBYTE  null[]
  233. '
  234.     XgrGetTextSelectionGrid (@g)
  235.     IF g THEN
  236.         XuiSendStringMessage (g, "GetTextSelection", @begPos, @begLine, @endPos, @endLine, 0, @text$)
  237.         IFZ text$ THEN RETURN
  238.         XgrSetClipboard (0, $$ClipboardTypeText, @text$, @null[])
  239.         XuiSendStringMessage (g, "TextReplace", begPos, begLine, endPos, endLine, 0, "")
  240.         XuiSendStringMessage (g, "RedrawText", 0, 0, 0, 0, 0, 0)
  241.     END IF
  242. END FUNCTION
  243. '
  244. '
  245. ' #########################
  246. ' #####  EditGrab ()  #####
  247. ' #########################
  248. '
  249. FUNCTION  EditGrab (grid)
  250.     UBYTE  null[]
  251. '
  252.     XgrGetTextSelectionGrid (@g)
  253.     IF g THEN
  254.         XuiSendStringMessage (g, "GetTextSelection", 0, 0, 0, 0, 0, @text$)
  255.         XuiSendStringMessage (g, "RedrawText", 0, 0, $$SelectCancel, 0, 0, 0)
  256.         IF text$ THEN XgrSetClipboard (0, $$ClipboardTypeText, @text$, @null[])
  257.     END IF
  258. END FUNCTION
  259. '
  260. '
  261. ' ##########################
  262. ' #####  EditPaste ()  #####
  263. ' ##########################
  264. '
  265. FUNCTION  EditPaste (grid)
  266.     UBYTE  null[]
  267. '
  268.     XgrGetClipboard (0, $$ClipboardTypeText, @text$, @null[])
  269.     IF text$ THEN
  270.         XgrGetSelectedWindow (@window)
  271.         XgrSendStringMessage (window, "WindowGetKeyboardFocusGrid", @g, 0, 0, 0, 0, 0)
  272.         IF g THEN
  273.             XuiSendStringMessage (g, "GetTextCursor", @cursorPos, @cursorLine, 0, 0, 0, 0)
  274.             XuiSendStringMessage (g, "TextReplace", cursorPos, cursorLine, cursorPos, cursorLine, 0, @text$)
  275.             XuiSendStringMessage (g, "RedrawText", 0, 0, 0, 0, 0, 0)
  276.         END IF
  277.     END IF
  278. END FUNCTION
  279. '
  280. '
  281. ' ##########################
  282. ' #####  EditErase ()  #####
  283. ' ##########################
  284. '
  285. FUNCTION  EditErase (grid)
  286. '
  287.     XgrGetTextSelectionGrid (@g)
  288.     IF g THEN
  289.         XuiSendStringMessage (g, "GetTextSelection", @begPos, @begLine, @endPos, @endLine, 0, @text$)
  290.         IFZ text$ THEN RETURN
  291.         XuiSendStringMessage (g, "TextReplace", begPos, begLine, endPos, endLine, 0, "")
  292.         XuiSendStringMessage (g, "RedrawText", 0, 0, 0, 0, 0, 0)
  293.     END IF
  294. END FUNCTION
  295. END PROGRAM
  296.