home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / drawedit / !DrawEdit / Source61 (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1997-03-05  |  22KB  |  756 lines

  1.  *****************************************************************
  2.  *                     Initiallisation code                      *
  3.  *****************************************************************
  4. !version$="1.61 (05-Mar-1997)"
  5.  "Wimp_Initialise",200,&4B534154,"DrawEdit" 
  6.  riscos%,myid%
  7. _Heap_Initialise
  8.     6stack% = 
  9. _Heap_Claim(4) :
  10.  this is the main stack
  11. unloaded%=
  12.          
  13.  Block% 256
  14. Iiconbar_icon%=
  15. _Icon_Create(-1,0,0,88,68,%10000000000010,"!DrawEdit")
  16. _ErrorHandler
  17.  "MenuUtil_Initialise",010,0
  18. _TemplatesLoad 
  19. _Menu_CreateMain
  20. _ScreenReadSize
  21.     n%=-4
  22. _Icon_Write(info%,7,version$)
  23.  *****************************************************************
  24.  *                         Wimp Poll                             *
  25.  *****************************************************************
  26.  "Wimp_Poll",,Block% 
  27.  reason%
  28.  reason% 
  29.  )   
  30.  2 : 
  31.  "Wimp_OpenWindow",,Block%
  32. !*   
  33.  3 : 
  34.  "Wimp_CloseWindow",,Block%
  35. "7   
  36.  6 : 
  37. _MouseClick(Block%!12,Block%!16,Block%!8)
  38. #>   
  39.  7 : 
  40. _DragBoxEnd(
  41. _Icon_Read(save%,0)) :
  42.  End of drag
  43. $6   
  44.  8 : 
  45. _KeyPressed(Block%!0,Block%!4,Block%!24)
  46.  9 : 
  47. _Menu_Decode
  48. &$   
  49.  17,18,19: 
  50. _Message_Receive
  51.  *****************************************************************
  52.  *                     Menu definitions                          *
  53.  *****************************************************************
  54. _Menu_CreateMain
  55.  "MenuUtil_New",,"DrawEdit" 
  56.  menu_iconbar%
  57. 1!   
  58.  "MenuUtil_Add",,"Info" 
  59. 2&      
  60.  "MenuUtil_SubMenu",,info%
  61.       
  62.  "MenuUtil_Dots",,
  63. 4'   
  64.  "MenuUtil_Add",,"Quit","Quit"
  65.  "MenuUtil_New",,"DrawEdit" 
  66.  menu_window%
  67. 7    
  68.  "MenuUtil_Add",,"Info"
  69. 8&      
  70.  "MenuUtil_SubMenu",,info%
  71. 95   
  72.  "MenuUtil_Add",,"Save
  73. ","Save" 
  74.  menu_save%
  75. :&      
  76.  "MenuUtil_SubMenu",,save%
  77. ;'      
  78.  "MenuUtil_Fade",,unloaded%
  79. _Menu_Decode
  80.  handler$,handler%,adjust%
  81.  "MenuUtil_Decode",,Block% 
  82.  handler%,adjust%
  83. handler$=$handler%
  84.  handler$ 
  85. C"   
  86.  "Quit"      : 
  87. _CloseDown
  88. D1   
  89.  "Save"      : 
  90. _Window_Open(save%,-1,-1)
  91.  adjust% 
  92.  "MenuUtil_Show"
  93.  *****************************************************************
  94.  *                    Template definitions                       *
  95.  *****************************************************************
  96. _TemplatesLoad
  97.  Version 1.48
  98.  template_Block% 6000
  99.  make sure maxws% is large enough for all icons
  100. Q/maxws%=6204:
  101.  ws% maxws%:curws%=ws%        
  102. "Wimp_OpenTemplate",,"<DrawEdit$Dir>.Templates"
  103. "Wimp_LoadTemplate",,template_Block%,ws%,ws%+maxws%,-1,"info",0 
  104.  ,,curws%
  105. "Wimp_CreateWindow",,template_Block% 
  106.  info%
  107. "Wimp_LoadTemplate",,template_Block%,curws%,ws%+maxws%,-1,"save",0 
  108.  ,,curws%
  109. "Wimp_CreateWindow",,template_Block% 
  110.  save%
  111. "Wimp_LoadTemplate",,template_Block%,curws%,ws%+maxws%,-1,"options",0 
  112.  ,,curws%
  113. "Wimp_CreateWindow",,template_Block% 
  114.  main%
  115. "Wimp_CloseTemplate"
  116.  *****************************************************************
  117.  *                         Mouse actions                         *
  118.  *****************************************************************
  119. _MouseClick(window%,icon%,button%)
  120.  window_height%
  121.  window%=-2 
  122.  icon%=iconbar_icon% 
  123.  button% 
  124. d6      
  125.  "MenuUtil_Show",menu_iconbar%,Block%
  126. e)      
  127. _Window_Open(main%,-1,-1)
  128.  window% 
  129.       
  130.  save%
  131.       
  132.  icon% 
  133. mB         
  134.  1  : 
  135. _DragSave(save%)      :
  136.  Start drag operation
  137.       
  138.  main%
  139.       
  140.  button% 
  141. r:         
  142.  2  : 
  143.  "MenuUtil_Show",menu_window%,Block%
  144.       
  145.  *****************************************************************
  146.  *         Actions when message is received from the WIMP        *
  147.  *****************************************************************
  148. _Message_Receive
  149.  Version 1.58
  150.  Block%!16 
  151.  0      : 
  152. _CloseDown
  153.  1      : 
  154. _Message_Data_Save
  155.  2      : 
  156. _Message_AcknowlegeSave
  157.  3      : 
  158. _Message_LoadOpen(Block%)
  159.  10     : 
  160. _Message_DesktopSave(Block%!20)
  161.  &502   : 
  162. _HelpDefinitions
  163.  &400C2 : 
  164. _Message_NewTask
  165.  &400CC : 
  166. _Window_Iconise
  167. _Message_Data_Save
  168. )Block%!0=(48+
  169. ("<Wimp$Scrap> "))
  170. Block%!12=Block%!8
  171. "Block%!16=2     :
  172.  DataSaveAck
  173. $(Block%+44)="<Wimp$Scrap>"
  174.  "Wimp_SendMessage",17,Block%,Block%!4
  175. _Message_NewTask
  176. newtaskid%=Block%!4
  177. /newtask$=
  178. _Convert_BlockToString(Block%+28)
  179.  newtask$="DrawEdit" 
  180.  newtaskid%<>myid% 
  181. _CloseDown
  182. _Message_LoadOpen(Block%)
  183.  Block%!40 
  184.  &AFF
  185. _Drawfile_Load(
  186. _Convert_BlockToString(Block%+44)) :
  187.  loads the file
  188. _Window_Open(main%,-1,-1)
  189.  2002,""  
  190. _CloseDown
  191.  Version 1.64
  192. "Wimp_CloseDown"
  193. _Message_DesktopSave(file%)
  194.  Block%!12=Block%!8:
  195. "Wimp_SendMessage",19,Block%,Block%!4:
  196.  The above line acknowledges the message if an error occurs, thereby
  197.  aborting the desktop save.
  198. #file%,"Run <DrawEdit$Dir>.!RunImage"
  199. _Message_AcknowlegeSave
  200.  Version 1.61
  201.  pathname$
  202. 0pathname$=
  203. _Convert_BlockToString(Block%+44)
  204. _Icon_Write(save%,0,pathname$)
  205. _Drawfile_Save(pathname$)
  206. Block%!0=40+
  207.  pathname$+4
  208. Block%!0+=4-(Block%!0 
  209. $Block%!16=3 : 
  210.  Message_DataLoad
  211. Block%!36=0
  212. Block%!40=&FF8
  213. $(Block%+44)=pathname$+
  214.  "Wimp_SendMessage",18,Block%,senderwindow%,sendericon%
  215.  *****************************************************************
  216.  *                        Error Handling                         *
  217.  *****************************************************************
  218. _ErrorHandler
  219.  sel%
  220.  "Wimp_DragBox",,-1
  221. error$=
  222.  2001  : error$="Could not extend block."+" at Line "+
  223.  2002  : error$="This File type ("+
  224. ~Block%!40+") cannot be handled by DrawEdit."
  225.  2003  : error$=file$+" is too long to be handled by DrawEdit or Draw. Split it up, and reload it.":
  226. #file%
  227.  2004  : error$="The concatenated data is too long to be handled by DrawEdit or Draw. Split it up, and reload it.":
  228. #file%
  229.   : error$="Error "+
  230. )+" at Line "+
  231. )+": "+
  232.  !Block%=
  233. :$(Block%+4)=error$
  234.  "Wimp_ReportError",Block%,%10011,"DrawEdit" 
  235.  ,sel%
  236.  sel%=2 
  237. _CloseDown
  238.  *****************************************************************
  239.  *                         Drag routines                         *
  240.  *****************************************************************
  241. _DragSave(window%)
  242.  Version 1.60
  243.  LOCAL offset_x%,offset_y%
  244. !Block%=window%
  245.  "Wimp_GetWindowState",,Block%
  246.  offset_x%=Block%!4-Block%!20
  247. !offset_y%=Block%!16-Block%!24
  248. QBlock%!0=window%                                    :
  249.  Window owning the icon
  250. MBlock%!4=1                                          :
  251.  Icon to be dragged
  252.  "Wimp_GetIconState",,Block%
  253. Block%!0=Block%!8+offset_x%
  254.  Block%!4=Block%!12+offset_y%
  255.  Block%!8=Block%!16+offset_x%
  256. !Block%!12=Block%!20+offset_y%
  257.  SYS "Wimp_DragBox",,Block%
  258.  "DragASprite_Start",%11001111,1,"file_aff",Block%
  259. _DragBoxEnd(leafname$)
  260.  "DragASprite_Stop"
  261.  pointer%
  262. pointer%=
  263.  leafname$
  264.  pointer%>0 
  265. leafname$,pointer%,1)<>"."
  266. pointer%-=1
  267. $leafname$=
  268. leafname$,pointer%+1)
  269.  "Wimp_GetPointerInfo",,Block%
  270. senderwindow%=Block%!12
  271. sendericon%=Block%!16
  272. Block%!20=senderwindow%
  273. Block%!24=sendericon%
  274. Block%!28=Block%!0
  275. Block%!32=Block%!4
  276. Block%!0=44+
  277.  leafname$
  278. Block%!0+=4-(Block%!0 
  279. Block%!4=0
  280. Block%!8=0
  281. Block%!12=0
  282. $Block%!16=1 : 
  283.  Message_DataSave
  284. +Block%!36=0 : 
  285.  Length of proposed save
  286. Block%!40=&AFF
  287. $(Block%+44)=leafname$+
  288.  "Wimp_SendMessage",17,Block%,senderwindow%,sendericon%
  289.  *****************************************************************
  290.  *                         Icon handling                         *
  291.  *****************************************************************
  292. _Icon_Read(window%,icon%)
  293.  result$
  294. Block%!0=window%
  295. Block%!4=icon%
  296.  "Wimp_GetIconState",,Block%
  297.  (Block%!24 
  298.  (1<<8))<>0 
  299.  result$=$(Block%!28) 
  300.  result$=$(Block%+28)
  301. =result$
  302. _Icon_Write(window%,icon%,text$)
  303. BBlock%!0=window%:Block%!4=icon%:
  304.  "Wimp_GetIconState",,Block%
  305. (text$)>(Block%!36)-1 
  306.  ((Block%!24) 
  307.  (1<<9))=(1<<9) 
  308.  Right-justified
  309. '    text$="
  310. text$,(Block%!36)-2)
  311. #    
  312.  Left-justified or centred
  313. /    text$=
  314. text$,(Block%!36)-1):
  315. text$)="
  316.  ^ Ensures the text can't overflow the maximum space in the icon.
  317.  $(Block%!28)<>text$ 
  318. /  $(Block%!28)=text$:Block%!8=0:Block%!12=0
  319.  "Wimp_SetIconState",,Block%
  320.  "Wimp_GetCaretPosition",,Block%
  321.  Block%!0=window% 
  322.  Block%!4=icon% 
  323.  If this icon owns the caret, then put it at the end.
  324.  "Wimp_SetCaretPosition",window%,icon%,0,0,-1,
  325. (text$)
  326. _Icon_State_Selected(window%,icon%)
  327.  sel%
  328. sel%=
  329. +BBlock%!0=window%:Block%!4=icon%:
  330.  "Wimp_GetIconState",,Block%
  331.  ((Block%!24) 
  332.  (1<<21))=(1<<21) 
  333.  sel%=
  334. -    =sel%
  335. _Icon_Alter_Flags(window%,icon%,bit%,sel%)
  336. Bl