home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / assembly / FontWindow / !Demo / EditorSrc (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1993-01-27  |  9.2 KB  |  329 lines

  1.   >EditorSrc
  2.      Demonstration of use of FontWindow module
  3.      Multi-document application, windows with anti-aliased title bars
  4.      Windows are demand-created
  5.      Look for REM### to see where I've put the FontModule code
  6.      documents are kept in a simple linked list
  7.   MACHINE:  Archimedes
  8.   LANGUAGE: BBC BASIC V (v1.05)
  9.   AUTHOR:   Cy Booker,
  10.             86 Church View, Main Road, Crockenhill, Swanley, Kent.
  11.             BR8 8JW
  12.      apologies for the crappy coding, but it is done in a hurry
  13. main(FontWindow, Title$)
  14.  = &8000+64*1024
  15.   Debug% = 
  16.  q% 256
  17.   $q%="TASK"
  18.  "Wimp_Initialise",200,!q%, Title$ 
  19.  , TaskHandle%
  20.  need local error handlers before poll loop...
  21. ### --- note the 1,1 see docs
  22.  FontWindow 
  23. Q    
  24.  "FontWindow_Initialise", TaskHandle%, 0,0, 1,1, 0, 0, 100 
  25.  FontTable%
  26. =    
  27.  FontTable% 256:
  28.  i%= 0 
  29.  255:FontTable%?i% = 0:
  30.  Documents 4               :
  31.   pointer to pointer to linked list of'em
  32. #$  !Documents = 0                
  33. $L  DocNumber = 1                 :
  34.   so can tell documents apart visually
  35.  Each document is stored in the following structure:
  36. (E  Doc_Next      = 0 << 2        :
  37.  pointer to next in linked list
  38. )9  Doc_Window    = 1 << 2        :
  39.  wimp window handle
  40. *R  Doc_Title     = 2 << 2        :
  41.  pointer to indirected title bar icon buffer
  42.   sizeof_Doc    = 3 << 2
  43. loadtemplates
  44. makemenus
  45. makeiconbaricon
  46. reporterror
  47. 5"    
  48.  "Wimp_Poll",&31,q% 
  49. 7%    
  50.  "Wimp_OpenWindow",, q%
  51. closewindow
  52. mouseclick
  53. menuselect
  54.  17,18:
  55. message
  56. <        
  57.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. closewindow
  59. docwindow_p(doc, !q%) 
  60. quitdocument(doc)
  61. G"    
  62.  "Wimp_CloseWindow",, q%
  63.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. createdocument
  65.  doc, dx, dy, len
  66.  doc sizeof_Doc            :
  67.   claim memory [kludge]
  68.  we now redirect the indirected data
  69.  this is a kludge (a bad one) because only redirect the title bar
  70.  should be re-directing all the indirected icons as well...
  71.   len = Document_WDef%!80
  72.  doc!Doc_Title len
  73. U'  Document_WDef%!72 = doc!Doc_Title
  74. putz(doc!Doc_Title, 
  75. "Document number "+ 
  76. (DocNumber), len-1))
  77.   DocNumber += 1
  78. ### -- note the TO parameter in the next line
  79.  FontWindow 
  80. Zb    
  81.  "FontWindow_CreateWindow", TaskHandle%, Document_WDef%, doc+Doc_Window 
  82.  doc!Doc_Window
  83. \@    
  84.  "Wimp_CreateWindow",, Document_WDef% 
  85.  doc!Doc_Window
  86.   !q% = doc!Doc_Window
  87.  "Wimp_GetWindowState",, q%
  88. `D  dx = (
  89. (64) - &1F) * 16         :
  90.  so not on top of eachother!
  91.   dy = (
  92. (64) - &1F) * 16
  93.   q%!4 += dx
  94.   q%!8 += dy
  95.   q%!12 += dx
  96.   q%!16 += dy
  97.   q%!28 = -1
  98.  "Wimp_OpenWindow",, q%    :
  99.   no need to fontwindow_openwindow, although could
  100.   doc!Doc_Next = !Documents
  101. jG  !Documents = doc                      :
  102.   new head of linked list
  103.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. quitdocument(doc)
  105.  parent
  106.   parent = Documents
  107.  !parent <> doc
  108. s%    parent = (!parent) + Doc_Next
  109.  FontWindow 
  110. wA    
  111.  "FontWindow_DeleteWindow", TaskHandle%, doc+Doc_Window
  112. y/    
  113.  "Wimp_DeleteWindow",, doc+Doc_Window
  114.   !parent = doc!Doc_Next
  115.   <release memory used by document>
  116.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117.      returns TRUE if window belongs to a document, setting doc
  118.      if true
  119. docwindow_p(
  120.  doc, w%)
  121.   rc% = 
  122.   doc = !Documents
  123.  doc 
  124. #    rc% = (doc!Doc_Window = w%)
  125. $    
  126.  rc% 
  127.  doc = doc!Doc_Next
  128.     = rc%
  129.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  130. closedown
  131.  !Documents
  132. !    
  133. quitdocument(!Documents)
  134.  FontWindow 
  135. 4    
  136.  "FontWindow_CloseDown", TaskHandle%, 
  137.  i%=0 
  138.       
  139.  FontTable%?i%
  140. #        
  141.  "XFont_LoseFont", i%
  142.         FontTable%?i% -= 1
  143.       
  144.  "Wimp_CloseDown"
  145.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146.   doesn't actually load window, but saves definition in memory
  147.   if make multiple clones of a windows then need to redirect
  148.   all of the indirected data... 
  149. loadtemplate(name$, 
  150.  wh%)
  151.  siz, i, pos
  152.   $q% = name$+ 
  153.  "Wimp_LoadTemplate",, buf%, indrove%, ind%+bufsiz%, FontTable%, q%, 0 
  154.  ,, indrove%,,,, pos
  155.  pos=0 
  156.  1, "Can't find template "+ name$
  157.   siz = 88+((buf%!84)*32)
  158.  wh% siz
  159.  i = 0 
  160.  siz-1 
  161.     wh%!i = buf%!i
  162.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. message_modechange
  164.  FontWindow 
  165. /    
  166.  "FontWindow_ModeChange", TaskHandle%
  167.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. message_menuwarning
  169.   x% = q%!24
  170.   y% = q%!28
  171.   item% = q%!32
  172.  item% 
  173.  ProgInfo_WDef% 
  174.       
  175.  ProgInfo_WPtr% 4
  176.       
  177.  FontWindow 
  178. g        
  179.  "FontWindow_CreateWindow", TaskHandle%, ProgInfo_WDef%, ProgInfo_WPtr% 
  180.  !ProgInfo_WPtr%
  181.       
  182. E        
  183.  "Wimp_CreateWindow",, ProgInfo_WDef% 
  184.  !ProgInfo_WPtr%
  185.       
  186. 5      ProgInfo_WDef% = 0        :
  187.  release memory
  188.         
  189.       
  190.  FontWindow 
  191. E        
  192.  "FontWindow_UpdateWindow", TaskHandle%, ProgInfo_WPtr%
  193.       
  194.         
  195. 9    
  196.  "Wimp_CreateSubMenu",, !ProgInfo_WPtr%, x%, y%
  197.  SaveAs_WDef% 
  198.       
  199.  SaveAs_WPtr% 4
  200.       
  201.  FontWindow 
  202. a        
  203.  "FontWindow_CreateWindow", TaskHandle%, SaveAs_WDef%, SaveAs_WPtr% 
  204.  !SaveAs_WPtr%
  205.       
  206. A        
  207.  "Wimp_CreateWindow",, SaveAs_WDef% 
  208.  !SaveAs_WPtr%
  209.       
  210. 3      SaveAs_WDef% = 0        :
  211.  release memory
  212.         
  213.       
  214.  FontWindow 
  215. C        
  216.  "FontWindow_UpdateWindow", TaskHandle%, SaveAs_WPtr%
  217.       
  218.         
  219. 7    
  220.  "Wimp_CreateSubMenu",, !SaveAs_WPtr%, x%, y%
  221.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. mouseclick
  223.  (q%!12 = -2) 
  224.  (q%!16 = IconBarIcon%) 
  225.  (q%!8 
  226. L      
  227.  "Wimp_CreateMenu",, Menu%, q%!0 - ((Menu%!16)>>1), 96+44*3+24*0
  228.         
  229.       
  230. createdocument
  231.         
  232. menuselect
  233.  !q% = 2 
  234. closedown
  235.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  236. reporterror
  237.   !q% = 
  238.  Debug% 
  239. '    
  240. putz(q%+4, 
  241. $+ " code "+ 
  242. putz(q%+4, 
  243.  "Wimp_ReportError", q%, 3, Title$ 
  244.  , choice%
  245.  choice% = 2 
  246. closedown
  247.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248. loadtemplates
  249.   bufsiz% = 10*1024
  250.  buf% bufsiz%  :
  251.  kludge
  252.  ind% bufsiz%  :
  253.  kludge
  254.   indrove% = ind%
  255.  "Wimp_OpenTemplate",, "<DemoFontWindow$Dir>.Templates"
  256.  local error handler...
  257. loadtemplate("ProgInfo", ProgInfo_WDef%)
  258. loadtemplate("SaveAs", SaveAs_WDef%)
  259. loadtemplate("Document", Document_WDef%)
  260.   the following window will not be cached, as it contains no
  261.   anti-aliased fonts.
  262. loadtemplate("Query", Query_WDef%)
  263.  "Wimp_CreateWindow",, Query_WDef% 
  264.  Query_W%
  265.  "Wimp_CloseTemplate"
  266.   free buf% memory
  267.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268. makemenus
  269.   menusiz% = 10*1024
  270.  Menu% menusiz%
  271.   menu% = Menu%
  272. menutitle(Title$)
  273. menuitem("Info", 1 << 3, &8004)
  274. menuitem("Save as", 1 << 3, &8004)
  275. menuitem("Quit", 1 << 7, -1)
  276. menutitle(title$)
  277.   $menu% = title$
  278.   menu%?12 = 7
  279.   menu%?13 = 2
  280.   menu%?14 = 7
  281.   menu%?15 = 0
  282.   menu%!16 = 11*16
  283.   menu%!20 = 44
  284.   menu%!24 = 0
  285.   menu% += 28
  286. menuitem(item$, flags%, data%)
  287.   menu%!0 = flags% 
  288.   menu%!4 = data%
  289.   menu%!8 = &07000021
  290. <&  $(menu%+12) = item$+ 
  291. (13))
  292.   menu%+=24
  293.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  294. makeiconbaricon
  295.  name% 13
  296.   $name% = "!demo"
  297.   q%!0 = -1
  298.   q%!4 = 0
  299.   q%!8 = 0
  300.   q%!12 = 68
  301.   q%!16 = 68
  302.   q%!20 = &07006102
  303.   q%!24 = name%
  304.   q%!28 = +1
  305.   q%!32 = 
  306. ($name%) + 1
  307.  "Wimp_CreateIcon",, q% 
  308.  IconBarIcon%
  309.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310. message
  311.  q%!16 
  312. closedown
  313.  &400C0:
  314. message_menuwarning
  315.  &400C1:
  316. message_modechange
  317.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  318.  Debug% 
  319. _!    
  320. $+ ", ["+ 
  321. )+ "]"
  322. getz(q%)
  323. ?q%:V$+=
  324. (?q%):q%+=1:
  325. putz(z%, z$)
  326.   $z% = z$
  327.   z%?
  328. z$ = 0
  329.