home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / c / charter / !Charter / Source203 (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1997-05-20  |  41.9 KB  |  1,746 lines

  1.  *****************************************************************
  2.  *                     Initiallisation code                      *
  3.  *****************************************************************
  4. >version$="2.03 (19-May-1997)"                             
  5. myid$="Charter 2.03"
  6. _Initialise
  7.  Block% 256    
  8. _ErrorHandler
  9. _Variables
  10. Giconbar_icon%=
  11. _IconCreate(-1,0,0,88,68,%10000000000010,"!Charter")
  12. _TemplatesLoad 
  13. _Menus
  14. _ScreenReadSize
  15. _OptionsLoad
  16. _Messages
  17. _IconWrite(info%,7,version$)
  18. _IconFlags(toolbox%,0,22,
  19.  Pointer icon selected
  20. _IconFlags(edit%,5,23,
  21. )    : 
  22.  Undo Button greyed out
  23. _IconFlags(options%,3,22,
  24. _LoadFiles(
  25. _ReadSysVar("Charter$Default"))
  26. _TextLoad
  27. _ErrorHandler
  28.  *****************************************************************
  29.  *                         Wimp Poll                             *
  30.  *****************************************************************
  31.  "Wimp_Poll",,Block% 
  32.  reason%
  33.  reason% 
  34. )8   
  35.  0 : 
  36.  getpos%=
  37. _CalculateCoords            
  38.  1 : 
  39. _Redraw
  40.  2 : 
  41.  Block%!0=main% 
  42. ,$               
  43. _Window_OpenMany
  44. -.            
  45.  "Wimp_OpenWindow",,Block%
  46.             
  47.  3 : 
  48.  Block%!0=main% 
  49. 0$              
  50. _Window_CloseMany
  51. 1/            
  52.  "Wimp_CloseWindow",,Block%
  53.             
  54. 3    
  55.  4 : 
  56. _Window_PointerOut
  57.  5 : 
  58. _Window_PointerIn
  59. 5I   
  60.  6 : 
  61. _MouseClick(Block%!12,Block%!16,Block%!8,Block%!0,Block%!4)
  62. 6,   
  63.  7 : 
  64. _DragEnd(
  65. _IconRead(save%,0)) 
  66. 76   
  67.  8 : 
  68. _KeyPressed(Block%!0,Block%!4,Block%!24)
  69.  9 : 
  70. _Menu_Decode
  71.  17,18,19: 
  72. _Receive
  73.  *****************************************************************
  74.  *                     Menu definitions                          *
  75.  *****************************************************************
  76. _Initialise
  77.  usermsg% 44
  78. usermsg%!0=0
  79. usermsg%!4=1
  80. usermsg%!8=2
  81. usermsg%!12=3
  82. usermsg%!16=5
  83. usermsg%!20=10
  84. usermsg%!24=&502
  85. usermsg%!28=&503
  86. usermsg%!32=&400C2
  87. usermsg%!36=&400CC
  88. usermsg%!40=0
  89.  "Wimp_Initialise",300,&4B534154,myid$,usermsg% 
  90.  riscos%,myid%
  91. _Variables
  92.  "THHeap_CreateGranular","Charter Data",200000,12 
  93.  heap%
  94.  "THHeap_CreateGranular","Charter Memory",200000,12 
  95.  memory%
  96.  "THHeap_Claim",memory%,8 
  97.  ,,undo% : 
  98.  this is the undo buffer
  99. V8undosize%=0 : 
  100.  this is the index of the undo buffer
  101.  header% 40   
  102.  table% 24    :
  103.  Font table
  104.  header2% 88  
  105. pos%=0
  106. [5n%=-4            :
  107.  current position in the stack
  108. max%=0           
  109. ]Lgetpos%=
  110.     :
  111.  Determines whether to calculate and display coordinates.
  112. clear%=
  113. textopen%=
  114. dragicon$="file_aff"
  115. stackmade%=
  116. notext%=
  117.  "THHeap_Claim",memory%,256 
  118.  ,,Buffer%
  119.  "THHeap_Claim",memory%,4 
  120.  ,,textbuf%
  121. textpos%=0
  122. f!currentfont$="Trinity.Medium"
  123. fontsize%=16
  124. textobj%=0
  125. helpfile$="!Help"
  126. j)textwidth%=960:maxlines%=256:lines%=0
  127. _Menus
  128.  "MenuUtil_Initialise",010,0
  129.  "MenuUtil_New",,"Font List" 
  130.  menu_fonts%
  131.  count%,font$
  132. s9   
  133.  "Font_ListFonts",,Block%,count%,-1 
  134.  ,,count%  
  135.    font$=
  136. _String(Block%)
  137. u/   
  138.  "MenuUtil_Add",menu_fonts%,font$,"
  139.  count%=-1
  140.  "MenuUtil_New",,"Charter" 
  141.  menu_iconbar%
  142. y!   
  143.  "MenuUtil_Add",,"Info" 
  144. z&      
  145.  "MenuUtil_SubMenu",,info%
  146. {$   
  147.  "MenuUtil_Add",,"Options
  148.       
  149.  "MenuUtil_Dots",,
  150. }    
  151.  "MenuUtil_Add",,"Quit"
  152.  "MenuUtil_New",,"Size" 
  153.  menu_size%
  154.  "MenuUtil_Add",,"12","!" 
  155.  "MenuUtil_Add",,"16","!"
  156.  "MenuUtil_Add",,"24","!"
  157.  "MenuUtil_Add",,
  158. (fontsize%),"!"
  159. ,      
  160.  "MenuUtil_Writable",,
  161. ,3,"A0-9"
  162.  "MenuUtil_New",,"Text" 
  163.  menu_text%
  164.  "MenuUtil_Add",,"Font"
  165. ,      
  166.  "MenuUtil_SubMenu",,menu_fonts%
  167.  "MenuUtil_Add",,"Size"
  168. +      
  169.  "MenuUtil_SubMenu",,menu_size%
  170.       
  171.  "MenuUtil_Dots",,
  172.  "MenuUtil_Add",,"Undo" 
  173.  menu_undo%
  174. /      
  175.  "MenuUtil_Fade",menu_undo%,notext%
  176.  "MenuUtil_New",,"Save as
  177.  menu_save%
  178.  "MenuUtil_Add",,"Drawfile" 
  179.  "MenuUtil_Add",,"CSV"
  180.  "MenuUtil_Add",,"Data"
  181.  "MenuUtil_Add",,"DXF"
  182.  "MenuUtil_New",,"Charter" 
  183.  menu_window%
  184.  "MenuUtil_Add",,"Info"
  185. &      
  186.  "MenuUtil_SubMenu",,info%
  187.  "MenuUtil_Add",,"Help"
  188. )      
  189.  "MenuUtil_SubMenu",,helpwin%
  190.  "MenuUtil_Add",,"Text"
  191. .      
  192.  "MenuUtil_SubMenu",,menu_text%   
  193.  "MenuUtil_Add",,"Save
  194.  "MenuUtil_Add",,"Edit
  195.  "MenuUtil_Add",,"Options
  196. _Menu_Decode
  197.  handler%,adjust%,item%,handler$
  198.  "MenuUtil_Decode",,Block% 
  199.  handler%,adjust%,item%
  200. item$=$(item%!12)
  201. handler$=$(handler%)
  202.  item$ 
  203.  "Quit"         : 
  204. _CloseDown
  205.  "Edit
  206. "        : 
  207. _Window_Open(edit%,-1,-1)
  208.  "Save
  209. "        : 
  210. _Window_Open(save%,-1,-1)
  211.  "Options
  212. "     : 
  213. _Window_Open(options%,-1,-1)
  214.  "Drawfile"     : 
  215. _IconSwap("file_aff",item$)
  216.  "CSV"          : 
  217. _IconSwap("file_2ad",item$)
  218.  "Data"         : 
  219. _IconSwap("file_ffd",item$)
  220.  "DXF"          : 
  221. _IconSwap("file_dea",item$)
  222.  "Undo"         : 
  223. _TextUndoLast
  224.  handler$="!" 
  225.  fontsize%=
  226. (item$)
  227. 5              
  228.  handler$="
  229.  currentfont$=item$
  230.  adjust% 
  231.  "MenuUtil_Show"
  232. _IconSwap(filetype$,item$)
  233.  save_icon%,iminx%,iminy%,imaxx%,imaxy%
  234. _IconWrite(save%,3,item$)
  235. Block%!0=save%
  236. Block%!4=1
  237.  "Wimp_GetIconState",,Block%
  238. iminx%=Block%!8
  239. iminy%=Block%!12
  240. imaxx%=Block%!16
  241. imaxy%=Block%!20
  242.  "Wimp_DeleteIcon",,Block%
  243. Rsave_icon%=
  244. _IconCreate(save%,iminx%,iminy%,imaxx%,imaxy%,&C000601A,filetype$)
  245.  "Wimp_ForceRedraw",save%,iminx%,iminy%,imaxx%,imaxy%
  246. dragicon$=filetype$
  247.  *****************************************************************
  248.  *                    Template definitions                       *
  249.  *****************************************************************
  250. _TemplatesLoad
  251.  templates% 622
  252. (maxws%=1010 :
  253.  Indirected data total
  254.  ws% maxws%:curws%=ws%        
  255. "Wimp_OpenTemplate",,"<Charter$Dir>.Templates"
  256. &info%=   
  257. _TemplatesCreate("info")
  258. &save%=   
  259. _TemplatesCreate("save")
  260. )options%=
  261. _TemplatesCreate("options")
  262. &main%=   
  263. _TemplatesCreate("main")
  264. &pane%=   
  265. _TemplatesCreate("pane")
  266. )toolbox%=
  267. _TemplatesCreate("toolbox")
  268. &edit%=   
  269. _TemplatesCreate("edit")
  270. &text%=   
  271. _TemplatesCreate("text")
  272. )helpwin%=   
  273. _TemplatesCreate("help")
  274. "Wimp_CloseTemplate"
  275. _TemplatesCreate(window$)
  276. "Wimp_LoadTemplate",,templates%,curws%,ws%+maxws%,-1,window$,0 
  277.  ,,curws%
  278. "Wimp_CreateWindow",,templates% 
  279.  result%
  280. =result%
  281.  *****************************************************************
  282.  *                         Mouse actions                         *
  283.  *****************************************************************
  284. _MouseClick(window%,icon%,button%,mousex%,mousey%)
  285.  window%=-2 
  286.  icon%=iconbar_icon% 
  287.  button% 
  288. 6      
  289.  "MenuUtil_Show",menu_iconbar%,Block%
  290.       
  291.  4: Block%!0=main%
  292.               
  293.  wsizey%
  294. 2              
  295.  "Wimp_GetWindowState",,Block%
  296. ,              wsizey%=Block%!16-Block%!8
  297. B              
  298. _Window_Open(main%,64,sch%-wsizey%-
  299. _TitleSize)
  300. 2              Block%!0=main%:
  301. _Window_OpenMany
  302.  window% 
  303.  options%
  304.       
  305.  icon% 
  306.          
  307.  3 : clear%=
  308.          
  309.  2 : clear%=
  310.       
  311.       
  312.  save%
  313.       
  314.  icon% 
  315. ,         
  316.  1  : 
  317. _DragStart(save%)      
  318. 8         
  319.  3  : 
  320.  "MenuUtil_Show",menu_save%,Block%
  321.       
  322.  text%
  323.       
  324.  icon% 
  325. F         
  326.  2  : 
  327.  button%=2 
  328.  "MenuUtil_Show",menu_text%,Block%
  329.       
  330.  main%
  331.       
  332.  button% 
  333. :         
  334.  2  : 
  335.  "MenuUtil_Show",menu_window%,Block%
  336. .         
  337.  4  : 
  338. _WindowVisible(text%) 
  339.     6                      
  340. _TextPlace(mousex%,mousey%)
  341.                    
  342.       
  343.  edit%
  344.       
  345.  icon% 
  346.          
  347.  4  : 
  348. _ValueEdit
  349.          
  350.  5  : 
  351. _ValueUndo
  352. ?         
  353.  6  : 
  354. _IconValueIncrement(edit%,1,-1,
  355. ,1,n%/4)
  356. .                 : 
  357. _ValueCurrent         
  358. ?         
  359.  7  : 
  360. _IconValueIncrement(edit%,1,+1,
  361. ,1,n%/4)
  362. %                 : 
  363. _ValueCurrent
  364. <         
  365.  8  : 
  366. _IconValueIncrement(edit%,3,-1,
  367. ,0,0)
  368. <         
  369.  9  : 
  370. _IconValueIncrement(edit%,3,+1,
  371. ,0,0)
  372.                      
  373.       
  374.  toolbox%
  375.       
  376.  icon% 
  377. +         
  378.  0 : textopen%=
  379. _TextToggle
  380. 9         
  381.  1 : textopen%=textopen% 
  382.  -1 :
  383. _TextToggle
  384.       
  385.         
  386.  *****************************************************************
  387.  *         Actions when message is received from the WIMP        *
  388.  *****************************************************************
  389. _Receive
  390.  Block%!16 
  391.  0 : 
  392. _CloseDown
  393. (2   
  394.  1 : Block%!0=(48+
  395. ("<Wimp$Scrap> "))
  396. )"            Block%!12=Block%!8
  397. *.            Block%!16=2     :
  398.  DataSaveAck
  399. ++            $(Block%+44)="<Wimp$Scrap>"
  400. ,8            
  401.  "Wimp_SendMessage",17,Block%,Block%!4
  402.  2 : 
  403. _MessageSaveAck
  404.  3,5 :
  405.       
  406.  Block%!40 
  407.          
  408.  &2AD,&2AC,&FFD
  409. 1"            Block%!12=Block%!8
  410. 23            Block%!16=4 : 
  411.  Message_DataLoadAck
  412. 37            
  413.  "Wimp_SendMessage",17,Block%,main%,0
  414. 47            
  415.  This stops the run action being taken
  416. 50            
  417. _LoadFiles(
  418. _String(Block%+44))
  419.       
  420. 7!   
  421.  &502 : 
  422. _HelpDefinitions
  423. 8!   
  424.  &400CC : 
  425. _WindowIconise
  426. 9@   
  427.  &400C2:newtaskid%=Block%!4:newtask$=
  428. _String(Block%+28)
  429. :9   
  430.  newtask$=myid$ 
  431.  newtaskid%<>myid% 
  432. _CloseDown
  433. ;%   
  434.  10: 
  435. _SaveDesktop(Block%!20)
  436.         
  437. _SaveDesktop(file%)
  438.  Block%!12=Block%!8:
  439. "Wimp_SendMessage",19,Block%,Block%!4:
  440.  The above line acknowledges the message if an error occurs, thereby
  441.  aborting the desktop save.
  442. #file%,"Run <Charter$Dir>.!RunImage"
  443. _SaveAs(filename$)
  444.  filetype$
  445. J!filetype$=
  446. _IconRead(save%,3)
  447.  filetype$ 
  448. L+   
  449.  "Drawfile" : 
  450. _SaveDraw(filename$)
  451. M3                     
  452. _SaveEnd("AFF",filename$)
  453. N*   
  454.  "CSV"      : 
  455. _SaveCSV(filename$)
  456. O3                     
  457. _SaveEnd("2AD",filename$)
  458. P+   
  459.  "Data"     : 
  460. _SaveData(filename$)
  461. Q3                     
  462. _SaveEnd("FFD",filename$)
  463. R*   
  464.  "DXF"      : 
  465. _SaveDXF(filename$)
  466. S3                     
  467. _SaveEnd("DEA",filename$)
  468. _MessageSaveAck
  469.  filename$
  470. Y!filename$=
  471. _String(Block%+44)
  472. _IconWrite(save%,0,filename$)
  473. _SaveAs(filename$)
  474. Block%!0=40+
  475.  filename$+4
  476. Block%!0+=4-(Block%!0 
  477. _$Block%!16=3 : 
  478.  Message_DataLoad
  479. Block%!36=0
  480. Block%!40=&FF8
  481. $(Block%+44)=filename$+
  482.  "Wimp_SendMessage",18,Block%,senderwindow%,sendericon%
  483. _CloseDown
  484.  "THHeap_RemoveHeap",heap%
  485.  "THHeap_RemoveHeap",memory%
  486.  "Wimp_CloseDown"
  487.  *****************************************************************
  488.  *                        Error Handling                         *
  489.  *****************************************************************
  490. _ErrorHandler
  491.  "Wimp_CloseDown":
  492.  result%
  493.  "Wimp_DragBox",,-1
  494. w4   
  495.  2001  : error$=
  496. _LookupString("ERRHP",
  497. x;   
  498.  2002  : error$=
  499. _LookupString("ERRF1",
  500. ~Block%!40)
  501. yA   
  502.  2003  : error$=
  503. _LookupString("ERRTL",thisfile$):
  504. #file%
  505. z1   
  506.  2004  : error$=
  507. _Lookup("ERRCD"):
  508. #file%
  509. {2   
  510.  2005  : error$=
  511. _Lookup("ERRNRD"):
  512. #file%
  513. |9   
  514.   : error$="Error "+
  515. )+" at Line "+
  516. )+": "+
  517.  !Block%=
  518. :$(Block%+4)=error$
  519.  "Wimp_ReportError",Block%,%10011,"Charter" 
  520.  ,result%
  521.  result%=2 
  522. _CloseDown
  523.  *****************************************************************
  524.  *                         Drag routines                         *
  525.  *****************************************************************
  526. _DragStart(window%)
  527. !Block%=window%
  528.  "Wimp_GetWindowState",,Block%
  529. wposx%=Block%!4-Block%!20
  530. wposy%=Block%!16-Block%!24
  531. @Block%!0=window%                   :
  532.  Window owning the icon
  533. <Block%!4=1                         :
  534.  Icon to be dragged
  535.  "Wimp_GetIconState",,Block%
  536. Block%!0=Block%!8+wposx%
  537. Block%!4=Block%!12+wposy%
  538. Block%!8=Block%!16+wposx%
  539. Block%!12=Block%!20+wposy%
  540.  "DragASprite_Start",%11001111,1,dragicon$,Block%
  541. _DragEnd(leafname$)
  542.  "DragASprite_Stop"
  543.  pointer%
  544. pointer%=
  545.  leafname$
  546.  pointer%>0 
  547. leafname$,pointer%,1)<>"."
  548. pointer%-=1
  549. $leafname$=
  550. leafname$,pointer%+1)
  551.  "Wimp_GetPointerInfo",,Block%
  552. senderwindow%=Block%!12
  553. sendericon%=Block%!16
  554. Block%!20=senderwindow%
  555. Block%!24=sendericon%
  556. Block%!28=Block%!0
  557. Block%!32=Block%!4
  558. Block%!0=44+
  559.  leafname$
  560. Block%!0+=4-(Block%!0 
  561. Block%!4=0
  562. Block%!8=0
  563. Block%!12=0
  564. $Block%!16=1 : 
  565.  Message_DataSave
  566. +Block%!36=0 : 
  567.  Length of proposed save
  568. Block%!40=&AFF
  569. $(Block%+44)=leafname$+
  570.  "Wimp_SendMessage",17,Block%,senderwindow%,sendericon%
  571.  *****************************************************************
  572.  *                         Icon handling                         *
  573.  *****************************************************************
  574. _IconRead(window%,icon%)
  575.  result$
  576. Block%!0=window%
  577. Block%!4=icon%
  578.  "Wimp_GetIconState",,Block%
  579.  (Block%!24 
  580.  (1<<8))<>0 
  581.  result$=$(Block%!28) 
  582.  result$=$(Block%+28)
  583. =result$
  584. _IconWrite(window%,icon%,text$)
  585. BBlock%!0=window%:Block%!4=icon%:
  586.  "Wimp_GetIconState",,Block%
  587. (text$)>(Block%!36)-1 
  588.  ((Block%!24) 
  589.  (1<<9))=(1<<9) 
  590.  Right-justified
  591. '    text$="
  592. text$,(Block%!36)-2)
  593. #    
  594.  Left-justified or centred
  595. /    text$=
  596. text$,(Block%!36)-1):
  597. text$)="
  598.  ^ Ensures the text can't overflow the maximum space in the icon.
  599.  $(Block%!28)<>text$ 
  600. /  $(Block%!28)=text$:Block%!8=0:Block%!12=0
  601.  "Wimp_SetIconState",,Block%
  602.  "Wimp_GetCaretPosition",,Block%
  603.  Block%!0=window% 
  604.  Block%!4=icon% 
  605.  If this icon owns the caret, then put it at the end.
  606.  "Wimp_SetCaretPosition",window%,icon%,0,0,-1,
  607. (text$)
  608. _IconFlags(window%,icon%,bit%,status%)
  609. Block%!0=window%
  610. Block%!4=icon%
  611.  status% 
  612.   Block%!8=1<<(bit%-1)
  613.   Block%!8=0
  614. Block%!12=1<<(bit%-1)
  615.  "Wimp_SetIconState",,Block%
  616. _IconValueIncrement(window%,icon%,change%,minlimit%,maxlimit%,minval%,maxval%)
  617.  size%
  618. &size%=
  619. _IconRead(window%,icon%))
  620. size%+=change%
  621.  maxlimit%=-1 
  622.  size%>maxval% 
  623.  size%=maxval%
  624.  minlimit%=-1 
  625.  size%<minval% 
  626.  size%=minval%
  627. _IconWrite(window%,icon%,
  628. (size%))
  629. _IconCreate(window%,xmin%,ymin%,xmax%,ymax%,flags%,sprite$)
  630.  icon%
  631. Block%!0=window%
  632. Block%!4=xmin%
  633. Block%!8=ymin%
  634. Block%!12=xmax%
  635. Block%!16=ymax%
  636. Block%!20=flags%
  637. $(Block%+24)=sprite$
  638.  "Wimp_CreateIcon",,Block% 
  639.  icon%
  640. =icon%
  641.  *****************************************************************
  642.  *                         Miscellaneous                         *
  643.  *****************************************************************
  644. _ScreenReadSize
  645.  xw%,xh%,xf%,yf%
  646.  "OS_ReadModeVariable",
  647.  ,,xw%
  648.  "OS_ReadModeVariable",
  649.  ,,xh%
  650.  "OS_ReadModeVariable",
  651.  ,,xf%
  652.  "OS_ReadModeVariable",
  653.  ,,yf%
  654. scw%=xw%<<xf%
  655. sch%=xh%<<yf%
  656. _String(pointer%)
  657.  Reads a zero terminated string
  658.  result$
  659.    result$+=
  660. ?pointer%
  661.    pointer%+=1
  662.  ?pointer%=0 
  663.  ?pointer%=13
  664. =result$
  665. _KeyPressed(window%,icon%,char%)
  666.  "Wimp_GetPointerInfo",,Block%
  667.  Block%!12 
  668.  main%
  669.       
  670.  char% 
  671. 9         
  672.  &184 : 
  673. _IconWrite(edit%,1,
  674. (relative_x%))
  675. <                     
  676. _IconWrite(edit%,3,
  677. (relative_y%))
  678. 3                     
  679. _Window_Open(edit%,-1,-1)
  680. 0         
  681.  &188 : 
  682. _TextUndoLast            
  683. (        
  684.  "Wimp_ProcessKey",char%
  685.       
  686.       
  687.  edit%
  688.       
  689.  char% 
  690. -         
  691.  13   : 
  692.  icon%=3 
  693. _ValueEdit
  694. !         
  695.  &188 : 
  696. _ValueUndo
  697. )         
  698.  "Wimp_ProcessKey",char%
  699.       
  700.  #   
  701.  "Wimp_ProcessKey",char%
  702. _Filetype(filename$)
  703.  loadaddress%,type%,result%
  704.  "OS_File",17,filename$ 
  705.  type%,,loadaddress%
  706.  type%<>1 
  707.  result%=-2
  708.  (loadaddress%>>>20)=&FFF 
  709.  result%=0 
  710.  result%=(loadaddress%>>>8)
  711.  result%=0 
  712.  result%=-1
  713. =result%
  714. _Pad(text$)
  715.  result$,count%
  716. result$=text$
  717. (text$) 
  718.  4<>0 
  719. 0%   
  720.  count%= 1 
  721. (text$) 
  722.       result$+=
  723. =result$
  724. _TitleSize
  725.  result%
  726. 8Qresult%=
  727.  ((Block%!32) 
  728.  (1<<26))=(1<<26) 
  729.  ((Block%!32) 
  730.  1)=1 
  731.  result%=
  732.  result%
  733. _ReadSysVar(sysvar$)
  734.  eg. FN_ReadSysVar("Charter$Default")
  735.  var% 256
  736. $(var%)=sysvar$
  737.  "OS_ReadVarVal",var%,Buffer%,256,,3 
  738.  ,,pointer%
  739. Buffer%?(pointer%)=13
  740. =$Buffer%
  741.  *****************************************************************
  742.  *                       Window routines                         *
  743.  *****************************************************************
  744. _Window_Open(window%,x%,y%)
  745.  If x% and y% =-1 (TRUE) then the window is centered
  746.  wsizex%,wsizey%
  747. Block%!0=window%
  748.  "Wimp_GetWindowState",,Block%
  749. wsizex%=Block%!12-Block%!4
  750. wsizey%=Block%!16-Block%!8
  751. Q!    Block%!4=(scw%-wsizex%)/2
  752. R!    Block%!8=(sch%-wsizey%)/2
  753.   Block%!4=x%
  754.   Block%!8=y%
  755. Block%!12=Block%!4+wsizex%
  756. Block%!16=Block%!8+wsizey%
  757. Block%!28=-1
  758.  "Wimp_OpenWindow",,Block%
  759. _WindowVisible(window%)
  760.  result%
  761.  Returns TRUE if window is open; false otherwise
  762. a5Block%!0=window%:
  763.  "Wimp_GetWindowState",,Block%
  764.  ((Block%!32) 
  765.  (1<<16))=(1<<16) 
  766.  result%=
  767.  result%=
  768. =result%
  769. _Window_PointerIn
  770. getpos%=
  771.  "Wimp_GetPointerInfo",,Block%
  772.  "Wimp_SetCaretPosition",Block%!12,-1,0,0,-1,-1
  773. _Window_PointerOut
  774. getpos%=
  775. _IconWrite(pane%,0,"(x,y)")
  776. _Window_Close(window%)
  777. Block%!0=window%
  778.  "Wimp_GetWindowState",,Block%
  779.  "Wimp_CloseWindow",,Block%
  780. _Window_Resize(window%,xmin%,ymin%,xmax%,ymax%)
  781. Block%!0=xmin%
  782. Block%!4=ymin%
  783. Block%!8=xmax%
  784. Block%!12=0-ymax%
  785.  "Wimp_SetExtent",window%,Block%
  786. Block%!0=window%
  787.  "Wimp_GetWindowState",,Block%
  788. Block%!4=xmin%+64
  789. Block%!8=ymin%-
  790. _TitleSize
  791. Block%!12=xmax%+64
  792. Block%!16=sch%-
  793. _TitleSize
  794. Block%!28=-1
  795. _Window_OpenMany
  796.  window%=helpwin% 
  797. Block%!0=window%
  798.  "Wimp_GetWindowState",,Block%
  799. Block%!4=xmin%
  800. Block%!8=ymin%
  801. Block%!12=xmax%
  802. Block%!16=sch%
  803. Block%!28=-1
  804. _Window_OpenMany
  805.  main_minx%,main_miny%,main_maxx%
  806. Block%!0=main%
  807.  "Wimp_OpenWindow",,Block%
  808.  "Wimp_GetWindowOutline",,Block%
  809. main_minx%=Block%!4
  810. main_miny%=Block%!8
  811. main_maxx%=Block%!12
  812. main_maxy%=Block%!16
  813. Block%!0=pane%
  814. Block%!4=main_minx%+42
  815. Block%!8=main_miny%-38
  816. Block%!12=main_maxx%
  817. Block%!16=main_miny%
  818.  "Wimp_OpenWindow",,Block%
  819. Block%!0=toolbox%
  820. Block%!4=main_minx%-64
  821. -Block%!8=312:
  822.  for resizing main_miny%+38
  823. Block%!12=main_minx%
  824. Block%!16=main_maxy%-38
  825.  "Wimp_OpenWindow",,Block%
  826.  textopen%=
  827.    Block%!0=text%
  828.    Block%!4=main_minx%+250
  829.    Block%!8=main_miny%-38
  830.    Block%!12=main_maxx%
  831.    Block%!16=main_miny%
  832.  "Wimp_OpenWindow",,Block%
  833. _Window_CloseMany
  834. _Window_Close(main%)
  835. _Window_Close(pane%)
  836. _Window_Close(text%)
  837. _Window_Close(toolbox%)
  838. _WindowIconise
  839. HBlock%!0=56:Block%!12=Block%!8:Block%!16=&400CC:
  840.  Message_WindowInfo
  841.  Block%!20<>0 
  842.    Block%!24=0
  843. <   $(Block%+28)="charter"+
  844. 0    :
  845.  uses sprite ic_<name>
  846. :   $(Block%+36)="Charter"          :
  847.  uses text <name>
  848.  "Wimp_SendMessage",17,Block%,Block%!4
  849.  *****************************************************************
  850.  *                      Interactive Help                         *
  851.  *****************************************************************
  852. _HelpDefinitions
  853. 9Block%!12=Block%!8:Block%!16=&503:helpinfo%=Block%+20
  854.  Block%!32 
  855. _HelpSend(
  856. _Lookup("PRG1"))
  857. (        
  858. _HelpSend(
  859. _Lookup("PRG2"))
  860. (        
  861. _HelpSend(
  862. _Lookup("PRG3"))
  863.  options%:
  864.  Block%!36 
  865. /      
  866.  2  : 
  867. _HelpSend(
  868. _Lookup("OPTCON"))
  869. .      
  870.  3  : 
  871. _HelpSend(
  872. _Lookup("OPTCL"))
  873.  save%
  874.  Block%!36 
  875. +      
  876. _HelpSend(
  877. _Lookup("SAVD"))
  878. +      
  879. _HelpSend(
  880. _Lookup("SAVT"))
  881. .              
  882. _HelpSend(
  883. _Lookup("SAVF"))
  884. +      
  885. _HelpSend(
  886. _Lookup("SAVN"))
  887.  pane%
  888.  Block%!36 
  889. +      
  890. _HelpSend(
  891. _Lookup("COOD"))
  892.  text%
  893.  Block%!36 
  894. *      
  895. _HelpSend(
  896. _Lookup("TXT"))
  897.  toolbox%
  898.  Block%!36 
  899. +      
  900.  0 : 
  901. _HelpSend(
  902. _Lookup("TBP"))
  903. +      
  904.  1 : 
  905. _HelpSend(
  906. _Lookup("TBT"))
  907.  edit%
  908.  Block%!36 
  909. +      
  910. _HelpSend(
  911. _Lookup("EDDP"))
  912. +      
  913. _HelpSend(
  914. _Lookup("EDNV"))
  915. +      
  916. _HelpSend(
  917. _Lookup("EDCV"))
  918. +      
  919. _HelpSend(
  920. _Lookup("EDUN"))
  921. 0      
  922.  6,7,8,9:
  923. _HelpSend(
  924. _Lookup("EDAL"))
  925.  info%:
  926. _HelpSend(
  927. _Lookup("INF"))
  928.  main%:
  929. _HelpSend(
  930. _LookupString("MAIN",thisfile$))
  931. 9           
  932.  textopen% 
  933. _HelpSend(
  934. _Lookup("TXTN"))
  935.  "Wimp_GetMenuState",1,Buffer%,Block%!32,Block%!36
  936.             
  937.  item%,item$
  938. ?            
  939.  "MenuUtil_Decode",,Buffer% 
  940.  handler%,,item%
  941. !            item$=$(item%!12)
  942. $            handler$=$(handler%)
  943.             
  944.  item$ 
  945. ;               
  946.  "Info" : 
  947. _HelpSend(
  948. _Lookup("MNINF"))
  949. ;               
  950.  "Text" : 
  951. _HelpSend(
  952. _Lookup("MNTXT"))
  953. ;               
  954.  "Save
  955. _HelpSend(
  956. _Lookup("MNSV"))
  957. ;               
  958.  "Edit
  959. _HelpSend(
  960. _Lookup("MNED"))
  961. ?               
  962.  "Options
  963. _HelpSend(
  964. _Lookup("MNOPT"))
  965. :               
  966.  "Font" : 
  967. _HelpSend(
  968. _Lookup("MNFO"))
  969. :               
  970.  "Size" : 
  971. _HelpSend(
  972. _Lookup("MNSZ"))
  973. :               
  974.  "Undo" : 
  975. _HelpSend(
  976. _Lookup("MNUN"))
  977.     ?               
  978.  "Drawfile" : 
  979. _HelpSend(
  980. _Lookup("MNAFF"))
  981. ;               
  982.  "Data" : 
  983. _HelpSend(
  984. _Lookup("MNFFD"))
  985. ?                             
  986. _HelpSend(
  987. _Lookup("MNFFD2"))
  988. :               
  989.  "CSV" : 
  990. _HelpSend(
  991. _Lookup("MN2AD"))
  992. >                            
  993. _HelpSend(
  994. _Lookup("MN2AD2"))
  995. :               
  996.  "DXF" : 
  997. _HelpSend(
  998. _Lookup("MNDEA"))
  999. >                            
  1000. _HelpSend(
  1001. _Lookup("MNDEA2"))
  1002. &               
  1003.  handler$="
  1004. H                          
  1005. _HelpSend(
  1006. _LookupString("MNFONT",item$))
  1007.                           
  1008. .                          
  1009.  handler$="!" 
  1010. H                          
  1011. _HelpSend(
  1012. _LookupString("MNSIZE",item$))
  1013.                           
  1014.             
  1015. ?helpinfo%=0
  1016. 'Block%!0=(helpinfo%+4-Block%) 
  1017.  "Wimp_SendMessage",17,Block%,Block%!4
  1018. _HelpSend(text$)
  1019. $helpinfo%=text$+"|M"
  1020. helpinfo%+=
  1021. (text$)+2
  1022.  *****************************************************************
  1023.  *                    Data Loading Routines                      *
  1024.  *****************************************************************
  1025. _LoadFiles(filename$)
  1026. thisfile$=filename$
  1027. _Filetype(filename$) 
  1028. *)   
  1029.  &2AC,&2AD : 
  1030. _LoadCSV(filename$)
  1031. +*   
  1032.  &FFD      : 
  1033. _LoadData(filename$)
  1034. _LoadStart(filename$,type%)
  1035. max%=0
  1036.  clear% 
  1037.    n%=-4   
  1038. _StackRemove
  1039.  "Hourglass_On"
  1040.  type%<> &FFD 
  1041. _StackExtend(100000)
  1042.    oldn%=n%   
  1043.    file%=
  1044.  filename$
  1045.  oldn%=0
  1046. _LoadEnd(type%)
  1047. #file%       
  1048.  a%=0 
  1049. A(   
  1050.  stack%!a%>max% 
  1051.  max%=stack%!a%
  1052. _Window_Resize(main%,0,-max%,n%,0)
  1053.  "Wimp_ForceRedraw",main%,0,-max%,n%,0
  1054. _Redraw
  1055. _ValueCurrent
  1056.  "Hourglass_Off"
  1057.  clear% 
  1058.    newn%=n%
  1059.    newn%=n%-oldn%
  1060.  type%<>&FFD 
  1061.  "THHeap_Extend",heap%,(newn%+4-100000),stack%
  1062. _LoadCSV(filename$)
  1063. _LoadStart(filename$,&2AD)
  1064.  stringfromfile$
  1065. #file%
  1066. U    n%+=4
  1067.  "String_Get$#",Buffer%,file%,256,10,0 
  1068.  stringfromfile$
  1069. W"  stack%!n%=
  1070. (stringfromfile$)
  1071.  "Hourglass_Percentage",(n%/
  1072. #file%)*100
  1073. _LoadEnd(&2AD)
  1074. _LoadData(filename$)
  1075.  a%,byte%,string$,textpos1%,textpos2%
  1076. file%=
  1077. (filename$)
  1078.  "String_Get$#",Buffer%,file%,14,0,0 
  1079.  string$
  1080. string$,1,7)="Charter" 
  1081.    textobj%=
  1082. #file%
  1083.    textpos1%=
  1084. #file%
  1085.    textpos2%=
  1086. #file%
  1087. e)   textpos%=(textpos1%<<8) +textpos2%
  1088. f(   
  1089. #file%=
  1090. #file%+1 :
  1091.  1 spare byte
  1092. g&   datalength%=
  1093. #file%-textpos%-16
  1094.  textobj%>0 
  1095.       
  1096.  End of header
  1097. j+      
  1098.  "THHeap_Free",memory%,textbuf%
  1099. k9      
  1100.  "THHeap_Claim",memory%,textpos% 
  1101.  ,,textbuf%
  1102. lD      
  1103.  "OS_GBPB",3,file%,textbuf%,textpos%,
  1104. #file% 
  1105.  ,,,,fptr%
  1106.       
  1107. #file%=fptr%
  1108. o"   
  1109. _LoadStart(filename$,&FFD)
  1110. q;   
  1111.  "THHeap_Claim",memory%,datalength% 
  1112.  ,,tempstack%
  1113. r?   
  1114.  "OS_GBPB",3,file%,tempstack%,
  1115. #file%-textpos%,
  1116. #file%
  1117. s!   
  1118. _StackExtend(datalength%)
  1119. tM   
  1120.  "Wimp_TransferBlock",myid%,tempstack%,myid%,stack%+n%+4,datalength%
  1121.    n%=n%+datalength%
  1122. _LoadEnd(&FFD)
  1123. w*   
  1124.  "THHeap_Free",memory%,tempstack%
  1125.  2005,"" :
  1126.  Not the right format
  1127.  *****************************************************************
  1128.  *                     Data Saving Routines                      *
  1129.  *****************************************************************
  1130. _SaveEnd(type$,filename$)
  1131. #file%
  1132.  "Hourglass_Off"
  1133. "SetType "+filename$+" "+type$
  1134.  "Wimp_CreateMenu",,-1
  1135. _WindowVisible(save%))=
  1136. _Window_Close(save%)
  1137. _SaveCSV(filename$)
  1138.  "Hourglass_On"
  1139.  offset%,current_datapoint%,y%
  1140. &offset%=
  1141. _IconRead(options%,43))
  1142. file%=
  1143.  filename$  
  1144.  current_datapoint%=0 
  1145. .    y%=(stack%!current_datapoint%)+offset%
  1146. #file%,
  1147. =    
  1148.  "Hourglass_Percentage",(current_datapoint%/n%)*100
  1149. _SaveData(filename$)
  1150.  "Hourglass_On"
  1151. file%=
  1152.  filename$
  1153.  title% 12
  1154.  a%=0 
  1155. "   title%?a%=
  1156. myid$,a%+1,1))
  1157.  "OS_GBPB",1,file%,title%,12
  1158. #file%,0:
  1159.  End of Header byte
  1160. #file%,textobj%
  1161. #file%,(textpos%>>8)
  1162. #file%,(textpos% 
  1163.  256) :
  1164.  cos textpos% is likely to be >255
  1165. #file%,&0D                :
  1166.  a spare byte - glad I had the last one!
  1167.  textobj%>0 
  1168.  "OS_GBPB",2,file%,textbuf%,textpos%,
  1169. #file%+4
  1170.  "OS_GBPB",2,file%,stack%,n%+4 
  1171.  ,,,fptr%
  1172. _SaveDraw(filename$)
  1173.  "Hourglass_On"
  1174.  count%,elements%,maxelements%,x%,y%
  1175. maxelements%=100
  1176. %pathsize%=(68+(maxelements%*4*3))
  1177. file%=
  1178.  filename$
  1179. fptr%=0
  1180.  "OS_GBPB",1,file%,header%,40,fptr% 
  1181.  ,,,,fptr%
  1182.  "OS_GBPB",1,file%,table%,24,fptr% 
  1183.  ,,,,fptr%
  1184.  "OS_GBPB",1,file%,header2%,88,fptr% 
  1185.  ,,,,fptr%
  1186. _PathStart
  1187. _PathMove(x%,0)
  1188.  count%=0 
  1189.    x%+=900
  1190. &   y%=max%*220-(stack%!count%)*220
  1191. _PathDraw(x%,y%)
  1192.    elements%+=1
  1193.  elements%>maxelements% 
  1194.       elements%=0
  1195.       
  1196. _PathEnd
  1197.       
  1198. _PathStart
  1199.       
  1200. _PathMove(x%,y%)
  1201.  "Hourglass_Percentage",(count%*100/n%)
  1202. _PathEnd
  1203.  textobj%>0 
  1204. _SaveDrawText
  1205. _SaveDrawText
  1206.  count%,font%,units%,endpos%
  1207.  textlength%,objlength%,size%,x%,y%,text$,font$
  1208.  object%=1 
  1209.  textobj%
  1210. #textlength%=textbuf%?(count%+2)
  1211. #objlength%= textbuf%?(count%+1)
  1212. 'size%=      textbuf%?(count%+3)*640
  1213. #x%=         textbuf%!(count%+4)
  1214. #y%=         textbuf%!(count%+8)
  1215. &text$       =$(textbuf%+12+count%)
  1216. 2font$       =$(textbuf%+12+count%+textlength%)
  1217. font%=1
  1218. text$=
  1219. _Pad(text$)
  1220. endpos%=52+
  1221. (text$)
  1222.  "THHeap_Claim",memory%,endpos%+4 
  1223.  ,,drawstack%
  1224. x%=x%*225
  1225. y%=(max%*221)+(y%*227)
  1226. Ddrawstack%!0=1                     :
  1227.  Beginning of a Text Object
  1228. 4drawstack%!8=(0)                   :
  1229.  Bound Left
  1230. 6drawstack%!12=(0)                  :
  1231.  Bound Bottom
  1232. 5drawstack%!16=(0)                  :
  1233.  Bound Right
  1234. 2drawstack%!20=(0)                  :
  1235.  BoundTop
  1236. 0drawstack%!24=0                    :
  1237.  Colour
  1238. ;drawstack%!28=(&FFFFFF00)          :
  1239.  Background colour
  1240. 5drawstack%!32=font%                :
  1241.  Font number
  1242. 3drawstack%!36=size%                :
  1243.  Font size
  1244. 5drawstack%!40=size%                :
  1245.  Font height
  1246. >drawstack%!44=x%                   :
  1247.  X Coordinate of text
  1248. >drawstack%!48=y%                   :
  1249.  Y Coordinate of text
  1250. $(drawstack%+52)=text$
  1251. drawstack%!(endpos%)=0
  1252. drawstack%!4=endpos%+4
  1253.  "OS_GBPB",1,file%,drawstack%,endpos%+4,fptr% 
  1254.  ,,,,fptr%
  1255.  "THHeap_Free",memory%,,drawstack%
  1256. count%+=objlength%
  1257.  "Hourglass_Percentage",(count%*100/textpos%)
  1258. _SaveDXF(filename$)
  1259.  "Hourglass_On"
  1260.  offset%,count%,y%
  1261. file%=
  1262.  filename$
  1263. _DXF_Header
  1264. _DXF_Move(0,0)
  1265.  count%=0 
  1266.     x%=count%
  1267.     y%=(stack%!count%)
  1268. _DXF_Draw(x%,y%)
  1269. _DXF_Move(x%,y%)
  1270. 1    
  1271.  "Hourglass_Percentage",(count%/n%)*100
  1272. _DXF_Footer
  1273.  *****************************************************************
  1274.  *                         DXF Routines                          *
  1275.  *****************************************************************
  1276. _DXF_Header
  1277. #file%,"0"
  1278. #file%,"SECTION"
  1279. #file%,"2"
  1280. #file%,"ENTITIES"
  1281. _DXF_Move(x%,y%)
  1282. #file%,"0"
  1283. #file%,"LINE"
  1284. #file%,"8"
  1285. #file%,"0"
  1286. #file%,"10"
  1287. #file%,
  1288. (x%/10)
  1289. #file%,"20"
  1290. #file%,
  1291. (y%/10)
  1292. _DXF_Draw(x%,y%)
  1293. #file%,"11"
  1294. #file%,
  1295. (x%/10)
  1296. #file%,"21"
  1297. #file%,
  1298. (y%/10)
  1299. _DXF_Footer
  1300. #file%,"0"
  1301. #file%,"ENDSEC"
  1302. #file%,"0"
  1303. #file%,"EOF"
  1304.  *****************************************************************
  1305.  *                        Drawfile Routines                      *
  1306.  *****************************************************************
  1307. _PathStart
  1308.  "THHeap_Claim",memory%,pathsize% 
  1309.  ,,drawstack%
  1310. 'Ddrawstack%!0=(&2)                  :
  1311.  Beginning of a Path Object
  1312. (4drawstack%!8=(0)                   :
  1313.  Bound Left
  1314. )6drawstack%!12=(0)                  :
  1315.  Bound Bottom
  1316. *5drawstack%!16=(0)                  :
  1317.  Bound Right
  1318. +2drawstack%!20=(0)                  :
  1319.  BoundTop
  1320. ,>drawstack%!24=(&FFFFFFFF)          :
  1321.  Fill colour BBGGRRFi
  1322. -8drawstack%!28=(0)                  :
  1323.  Outline colour
  1324. .7drawstack%!32=(0)                  :
  1325.  Outline width
  1326. /4drawstack%!36=(&20100042)          :
  1327.  Path style
  1328. drawstack_pos%=36
  1329. _PathMove(x%,y%)
  1330. 47drawstack%!(drawstack_pos%+4)=&2    :
  1331.  Move command
  1332. 5Bdrawstack%!(drawstack_pos%+8)=x%    :
  1333.  X Coordinate to move to
  1334. 6Bdrawstack%!(drawstack_pos%+12)=y%   :
  1335.  Y Coordinate to move to
  1336. drawstack_pos%+=12
  1337. _PathDraw(x%,y%)
  1338. ;7drawstack%!(drawstack_pos%+4)=&8    :
  1339.  Draw command
  1340. <Bdrawstack%!(drawstack_pos%+8)=x%    :
  1341.  X Coordinate to draw to
  1342. =Bdrawstack%!(drawstack_pos%+12)=y%   :
  1343.  Y Coordinate to draw to
  1344. drawstack_pos%+=12
  1345. _PathEnd
  1346. B;drawstack%!(drawstack_pos%+4)=0     :
  1347.  End Path command
  1348. drawstack_pos%+=8
  1349. drawstack%!4=drawstack_pos%
  1350.  "OS_GBPB",1,file%,drawstack%,drawstack_pos%,fptr% 
  1351.  ,,,,fptr%
  1352.  "THHeap_Free",memory%,,drawstack%
  1353.  *****************************************************************
  1354.  *                      Graphics routines                        *
  1355.  *****************************************************************
  1356. _Redraw
  1357.  "Wimp_RedrawWindow",,Block% 
  1358.  more%
  1359.  more%
  1360.       
  1361.  Block%!0 
  1362. Q5         
  1363.  main%    : 
  1364.  textobj%>0 
  1365. _RedrawText
  1366. R6                         
  1367.  n%>0 
  1368. _RedrawGraphics
  1369. S$         
  1370.  helpwin% : 
  1371. _TextDraw
  1372.       
  1373.             
  1374. U0      
  1375.  "Wimp_GetRectangle",,Block% 
  1376.  more%
  1377. _RedrawGraphics
  1378.  wposx%,wposy%,x%,count%,y%,wsizex%,scrollx%,scrolly%
  1379. Block%!0=main%
  1380.  "Wimp_GetWindowOutline",,Block%
  1381. ^"wposx%=Block%!4-(Block%!4 
  1382. _;wposy%=Block%!16-
  1383. _TitleSize :
  1384.  to allow for tool icons
  1385.  wposx%,wposy%
  1386.  "Wimp_GetWindowState",,Block%
  1387. wsizex%=Block%!12-Block%!4
  1388. scrollx%=Block%!20
  1389. scrolly%=Block%!24
  1390.  scrollx% 
  1391.  4 <>0 
  1392. g#   scrollx%+=(4-(scrollx% 
  1393.  count%=scrollx% 
  1394. y%=(stack%!count%)+scrolly%
  1395.  wposx%+x%,wposy%-y%
  1396. o    x%+=4
  1397. _RedrawText
  1398.  count%,object%,textlength%,objlength%,size%,x%,y%,text$,font$
  1399.  object%=1 
  1400.  textobj%
  1401. v#textlength%=textbuf%?(count%+2)
  1402. w#objlength%= textbuf%?(count%+1)
  1403. x#size%=      textbuf%?(count%+3)
  1404. y#x%=         textbuf%!(count%+4)
  1405. z#y%=         textbuf%!(count%+8)
  1406. {&text$       =$(textbuf%+12+count%)
  1407. |2font$       =$(textbuf%+12+count%+textlength%)
  1408. _RelativeToMouse(x%,y%,text$,font$,size%)
  1409. count%+=objlength%
  1410.  *****************************************************************
  1411.  *                    Coordinate Calulation                      *
  1412.  *****************************************************************
  1413. _CalculateCoords
  1414. 4relative_x%=0:relative_y%=0  :
  1415.  DO NOT LOCALISE!
  1416.  mousex%,mousey%,window%,scrollx%,scrolly%
  1417.  wminx%,wmaxy%,temp$
  1418.  "Wimp_GetPointerInfo",,Block%
  1419. 7mousex%=Block%!0:mousey%=Block%!4:window%=Block%!12
  1420.  window%=main% 
  1421.    Block%!0=window%
  1422.  "Wimp_GetWindowOutline",,Block%
  1423. '   wminx%=Block%!4:wmaxy%=Block%!16
  1424.  "Wimp_GetWindowState",,Block%
  1425. ,   scrollx%=Block%!20:scrolly%=Block%!24
  1426. .   relative_x%=(mousex%-wminx%)+scrollx%-2
  1427. :   relative_y%=(mousey%-wmaxy%)+scrolly%+2+
  1428. _TitleSize
  1429.  relative_y%<0 
  1430.  relative_x%>0 
  1431.  relative_x%<n% 
  1432. (      relative_x%=2+
  1433. (relative_x%/4)
  1434. "      temp$="("+
  1435. (relative_x%)
  1436. 0      relative_y%=stack%!((relative_x%*4)-4)
  1437. 8      temp$+=","+
  1438. (relative_y%)+")"                 
  1439. 2      
  1440. _IconWrite(pane%,0,temp$)              
  1441. &      
  1442. _IconWrite(pane%,0,"(x,y)")
  1443.  *****************************************************************
  1444.  *                      Data Edit Routines                       *
  1445.  *****************************************************************
  1446. _ValueCurrent
  1447. #x%=(
  1448. _IconRead(edit%,1))*4)-4
  1449. _IconWrite(edit%,3,
  1450. (stack%!x%))
  1451. _ValueEdit
  1452. #x%=(
  1453. _IconRead(edit%,1))*4)-4
  1454. undobuffer%=stack%!x%
  1455.  stack%!x%<>(
  1456. _IconRead(edit%,3))) 
  1457.    undo%!undosize%=x%
  1458. $   undo%!(undosize%+4)=stack%!x%
  1459.  "THHeap_Extend",memory%,8,undo% 
  1460.  ,,undo%
  1461.    undosize%+=8
  1462. '   stack%!x%=
  1463. _IconRead(edit%,3))
  1464.  "Wimp_ForceRedraw",main%,x%-8,-sch%,x%+8,0 
  1465.    Block%!0=main%
  1466. _Redraw
  1467. _IconFlags(edit%, 5,23,
  1468. _ValueUndo
  1469.  x%,y%
  1470.  undosize%>0 
  1471.    x%=(undo%!(undosize%-8))
  1472.    y%=(undo%!(undosize%-4))
  1473.    stack%!x%=y%
  1474.  "THHeap_Extend",memory%,-8,undo% 
  1475.  ,,undo%
  1476.    undosize%+=(-8)
  1477.  undosize%<8 
  1478. $      
  1479. _IconFlags(edit%, 5,23,
  1480. 7      
  1481.  This IF statement controls the undo button.
  1482. _IconWrite(edit%,3,
  1483. (stack%!x%))
  1484.  "Wimp_ForceRedraw",main%,x%-8,-sch%,x%+8,0 :
  1485.  cheating a bit...
  1486. _Redraw
  1487.  *****************************************************************
  1488.  *               Drawfile Option handling routines               *
  1489.  *****************************************************************
  1490. _OptionsLoad
  1491. "file%=
  1492.  "<Charter$Dir>.Header"
  1493.  "OS_GBPB",3,file%,header%,40 
  1494.  ,,,,fptr%
  1495.  "OS_GBPB",3,file%,header2%,88,fptr%
  1496. #file%
  1497. ,table%!0=0                 :
  1498.  font table
  1499. table%!4=&18
  1500. table%?8=1
  1501. '$(table%+9)=
  1502. _Pad("Trinity.Medium")
  1503.  *****************************************************************
  1504.  *                     Stack Handling Routines                   *
  1505.  *****************************************************************
  1506. _StackRemove
  1507.  stackmade%=
  1508.  "THHeap_Free",heap%,,stack% :stackmade%=
  1509. _StackExtend(value%)
  1510.  stackmade%=
  1511.    stackmade%=
  1512.  "THHeap_Claim",heap%,value% 
  1513.  ,,stack%
  1514.  "THHeap_Extend",heap%,value%,stack% 
  1515.  ,,stack%  
  1516.  *****************************************************************
  1517.  *                         Text handling                         *
  1518.  *****************************************************************
  1519. _RelativeToMouse(relx%,rely%,text$,font$,size%)
  1520.  wminx%,wmaxy%,scrollx%,scrolly%,mousex%,mousey%
  1521. Block%!0=main%
  1522.  "Wimp_GetWindowOutline",,Block%
  1523. $wminx%=Block%!4:wmaxy%=Block%!16
  1524.  "Wimp_GetWindowState",,Block%
  1525. )scrollx%=Block%!20:scrolly%=Block%!24
  1526. #mousex%=relx%+wminx%+2-scrollx%
  1527. /mousey%=rely%+wmaxy%-scrolly%-2-
  1528. _TitleSize
  1529. _FontPaint(mousex%,mousey%,text$,font$,size%)
  1530. _FontPaint(mousex%,mousey%,text$,font$,size%)
  1531.  flags%,handle%
  1532.  "XFont_FindFont",,font$,size%*16,size%*16 
  1533.  handle% ;flags%
  1534.  "XWimp_SetFontColours",,0,7
  1535.  "XFont_Paint",,text$,%10010,mousex%,mousey%
  1536. _TextAddToBuffer(mousex%,mousey%,text$,font$,size%)
  1537. textobj%+=1
  1538.  wminx%,wmaxy%,scrollx%,scrolly%,relx%,rely%
  1539. Block%!0=main%
  1540.  "Wimp_GetWindowOutline",,Block%
  1541. $wminx%=Block%!4:wmaxy%=Block%!16
  1542.  "Wimp_GetWindowState",,Block%
  1543. )scrollx%=Block%!20:scrolly%=Block%!24
  1544. %relx%=(mousex%-wminx%)+scrollx%-2
  1545. 2rely%=(mousey%-wmaxy%)+scrolly%+2+
  1546. _TitleSize 
  1547. )fontblocksize%=12+
  1548. (font$)+
  1549. (text$)+2
  1550.  "THHeap_Extend",memory%,fontblocksize%,textbuf% 
  1551.  ,,textbuf%
  1552. #textbuf%?(textpos%+0)=textobj% 
  1553. 2textbuf%?(textpos%+1)=12+
  1554. (text$)+1+
  1555. (font$)+1
  1556. $textbuf%?(textpos%+2)=
  1557. (text$)+1
  1558. textbuf%?(textpos%+3)=size%
  1559. Ftextbuf%!(textpos%+4)=relx% : 
  1560.  needs a word, as likely to be >255
  1561. Ftextbuf%!(textpos%+8)=rely% : 
  1562.  needs a word, as likely to be >255
  1563.  :$(textbuf%+textpos%+12)=text$ :
  1564.  text$, &0D terminated
  1565. !F$(textbuf%+textpos%+12+
  1566. (text$)+1)=font$ :
  1567.  font$, &0D terminated 
  1568. textpos%+=fontblocksize%
  1569. _FontPaint(mousex%,mousey%,text$,font$,size%)
  1570. _TextPlace(mousex%,mousey%)
  1571.  text$
  1572. text$=
  1573. _IconRead(text%,1)
  1574. (text$)>0 
  1575. +F   
  1576. _TextAddToBuffer(mousex%,mousey%,text$,currentfont$,fontsize%)
  1577.  notext%=
  1578. ./      
  1579.  "MenuUtil_Fade",menu_undo%,notext%
  1580.       notext%=
  1581. _TextUndoLast
  1582.  count%,object%,obj%
  1583.  textobj%>0 
  1584.  object%=1 
  1585.  textobj%
  1586. 8#      obj%= textbuf%?(count%+1)
  1587.       count%+=obj%
  1588.    count%-=obj%
  1589.    Block%!0=main%
  1590. ><   
  1591. "THHeap_Extend",memory%,-obj%,textbuf% 
  1592.  ,,textbuf%
  1593.    textobj%-=1
  1594.    textpos%-=obj%
  1595. _Redraw
  1596.  textobj%=0 
  1597.  notext%=
  1598.  notext%=
  1599.  "MenuUtil_Fade",menu_undo%,notext%
  1600. _TextToggle
  1601. Block%!0=main%
  1602.  "Wimp_GetWindowState",,Block%
  1603.  "Wimp_OpenWindow",,Block%
  1604.  textopen% 
  1605. _Window_OpenMany
  1606. N"   
  1607. _Window_Close(text%)
  1608. _IconFlags(toolbox%, 1,22,textopen%)
  1609. _IconFlags(toolbox%, 0,22,(textopen% 
  1610.  -1))
  1611.  *****************************************************************
  1612.  *                           Messages                            *
  1613.  *****************************************************************
  1614. _Messages
  1615.  msgfile$,held%,msgbuffersize%,msgbuffer%
  1616. Z%msgfile$="<Charter$Dir>.Messages"
  1617.  "MessageTrans_FileInfo",,msgfile$ 
  1618.  held%,,msgbuffersize%
  1619.  held% 
  1620. ]7   msgbuffer%=0      :
  1621.  bit 0 set if held in memory
  1622. _>   
  1623.  "THHeap_Claim",memory%,msgbuffersize% 
  1624.  ,,msgbuffer%
  1625.  "THHeap_Claim",memory%,(17+
  1626. (msgfile$)) 
  1627.  ,,msg%
  1628. $(msg%+16)=msgfile$
  1629. "MessageTrans_OpenFile",msg%,msg%+16,msgbuffer%
  1630. _Lookup(token$)
  1631.  resultstring%
  1632.  "MessageTrans_Lookup",msg%,token$,0 
  1633. ,,resultstring%
  1634. _ConvertTokenToString(resultstring%)
  1635. _LookupString(token$,string$)
  1636.  resultstring%
  1637.  "MessageTrans_Lookup",msg%,token$,Buffer%,256,string$ 
  1638. ,,resultstring%
  1639. _ConvertTokenToString(resultstring%)
  1640. _ConvertTokenToString(string%)
  1641.  pointer%,result$
  1642. pointer%=0
  1643.  (string%?pointer%>=32) 
  1644.  (pointer%<255)
  1645. t#   result$+=
  1646. (string%?pointer%)
  1647.    pointer%+=1
  1648.                                
  1649. =result$
  1650. _TextLoad
  1651.  file$
  1652. {$file$="<Charter$Dir>."+helpfile$
  1653.  "OS_File",5,file$ 
  1654.  ,,,,origlength%
  1655. "THHeap_Claim",memory%,origlength% 
  1656.  ,,origtext%
  1657.  "OS_File",255,file$,origtext%,0
  1658. "THHeap_Claim",memory%,origlength%+maxlines% 
  1659.  ,,displaytext%
  1660. "THHeap_Claim",memory%,4*maxlines% 
  1661.  ,,textindx%
  1662. _TextSortOut
  1663. _FontFind(font$,sizex%,sizey%)
  1664.  result%,flags%
  1665.  "XFont_FindFont",,font$,sizex%*16,sizey%*16,0,0 
  1666.  result%;flags%
  1667.  (flags% 
  1668.  result%=
  1669. =result%
  1670. _TextDraw
  1671. !Block%=helpwin%
  1672.  "Wimp_GetWindowState",,Block%
  1673. wx%=Block%!4-Block%!20
  1674. wy%=Block%!16-Block%!24
  1675. ,font%=
  1676. _FontFind("Trinity.Medium",12,12)
  1677. 0    font%=
  1678. _FontFind("Trinity.Medium",12,12)
  1679. %    
  1680.  "Wimp_SetFontColours",,0,7
  1681. 1    first%=(wy%-Block%!16-margin%) 
  1682.  spacing%
  1683. /    last%=(wy%-Block%!8-margin%) 
  1684.  spacing%
  1685.  first%<0 first%=0
  1686. &    
  1687.  last%>=lines% last%=lines%-1
  1688.  i%=first% 
  1689.  last%
  1690. Z      
  1691.  "Font_Paint",,displaytext%+textindx%!(4*i%),&10,wx%+32,wy%-32-spacing%*(i%+1)
  1692.         
  1693. _TextSortOut
  1694. lines%=0
  1695. spacing%=12*3
  1696. margin%=32
  1697. ptr%=0:lastptr%=0
  1698. s$="":w$=""
  1699. ,font%=
  1700. _FontFind("Trinity.Medium",12,12)
  1701.  font%>=0 
  1702.  "Font_Converttopoints",,textwidth%,0 
  1703.  ,width%
  1704.  lines%<maxlines% 
  1705.  ptr%<origlength%
  1706.   newline%=
  1707.   c%=origtext%?ptr%
  1708.  c%<32 
  1709. &    
  1710.  w$<>"" 
  1711.  c%<>13 
  1712.  newline%=
  1713.     w$+=
  1714.  c%=32 
  1715. N    
  1716.  "Font_StringWidth",,s$+w$,&FFFFFFF,&FFFFFFF,-1,
  1717.  ,,xsize%
  1718.       
  1719.  xsize%>width% 
  1720.         newline%=
  1721.       
  1722.         s$+=w$
  1723.         w$=""
  1724.       
  1725.         
  1726.  ptr%=origlength%-1 
  1727.  newline%=
  1728.  newline% 
  1729. N    
  1730.  "Font_StringWidth",,s$+w$,&FFFFFFF,&FFFFFFF,-1,
  1731.  ,,xsize%
  1732. '    
  1733.  xsize%<=width% 
  1734.  s$+=w$:w$=""
  1735. #    $(displaytext%+lastptr%)=s$
  1736. &    displaytext%?(lastptr%+
  1737.  s$)=0
  1738. %    textindx%!(4*lines%)=lastptr%
  1739.     lines%+=1
  1740.     lastptr%+=
  1741.  s$+1
  1742.     s$=w$
  1743.     w$=""
  1744.   ptr%+=1
  1745. _Window_Resize(helpwin%,0,(-64-spacing%*lines%),1000,0)
  1746.