home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1997-03-05 | 21.0 KB | 756 lines |
- *****************************************************************
- * Initiallisation code *
- *****************************************************************
- !version$="1.61 (05-Mar-1997)"
- "Wimp_Initialise",200,&4B534154,"DrawEdit"
- riscos%,myid%
- _Heap_Initialise
- 6stack% =
- _Heap_Claim(4) :
- this is the main stack
- unloaded%=
-
- Block% 256
- Iiconbar_icon%=
- _Icon_Create(-1,0,0,88,68,%10000000000010,"!DrawEdit")
- _ErrorHandler
- "MenuUtil_Initialise",010,0
- _TemplatesLoad
- _Menu_CreateMain
- _ScreenReadSize
- n%=-4
- _Icon_Write(info%,7,version$)
- *****************************************************************
- * Wimp Poll *
- *****************************************************************
- "Wimp_Poll",,Block%
- reason%
- reason%
- )
- 2 :
- "Wimp_OpenWindow",,Block%
- !*
- 3 :
- "Wimp_CloseWindow",,Block%
- "7
- 6 :
- _MouseClick(Block%!12,Block%!16,Block%!8)
- #>
- 7 :
- _DragBoxEnd(
- _Icon_Read(save%,0)) :
- End of drag
- $6
- 8 :
- _KeyPressed(Block%!0,Block%!4,Block%!24)
- 9 :
- _Menu_Decode
- &$
- 17,18,19:
- _Message_Receive
- *****************************************************************
- * Menu definitions *
- *****************************************************************
- _Menu_CreateMain
- "MenuUtil_New",,"DrawEdit"
- menu_iconbar%
- 1!
- "MenuUtil_Add",,"Info"
- 2&
- "MenuUtil_SubMenu",,info%
-
- "MenuUtil_Dots",,
- 4'
- "MenuUtil_Add",,"Quit","Quit"
- "MenuUtil_New",,"DrawEdit"
- menu_window%
- 7
- "MenuUtil_Add",,"Info"
- 8&
- "MenuUtil_SubMenu",,info%
- 95
- "MenuUtil_Add",,"Save
- ","Save"
- menu_save%
- :&
- "MenuUtil_SubMenu",,save%
- ;'
- "MenuUtil_Fade",,unloaded%
- _Menu_Decode
- handler$,handler%,adjust%
- "MenuUtil_Decode",,Block%
- handler%,adjust%
- handler$=$handler%
- handler$
- C"
- "Quit" :
- _CloseDown
- D1
- "Save" :
- _Window_Open(save%,-1,-1)
- adjust%
- "MenuUtil_Show"
- *****************************************************************
- * Template definitions *
- *****************************************************************
- _TemplatesLoad
- Version 1.48
- template_Block% 6000
- make sure maxws% is large enough for all icons
- Q/maxws%=6204:
- ws% maxws%:curws%=ws%
- "Wimp_OpenTemplate",,"<DrawEdit$Dir>.Templates"
- "Wimp_LoadTemplate",,template_Block%,ws%,ws%+maxws%,-1,"info",0
- ,,curws%
- "Wimp_CreateWindow",,template_Block%
- info%
- "Wimp_LoadTemplate",,template_Block%,curws%,ws%+maxws%,-1,"save",0
- ,,curws%
- "Wimp_CreateWindow",,template_Block%
- save%
- "Wimp_LoadTemplate",,template_Block%,curws%,ws%+maxws%,-1,"options",0
- ,,curws%
- "Wimp_CreateWindow",,template_Block%
- main%
- "Wimp_CloseTemplate"
- *****************************************************************
- * Mouse actions *
- *****************************************************************
- _MouseClick(window%,icon%,button%)
- window_height%
- window%=-2
- icon%=iconbar_icon%
- button%
- d6
- "MenuUtil_Show",menu_iconbar%,Block%
- e)
- _Window_Open(main%,-1,-1)
- window%
-
- save%
-
- icon%
- mB
- 1 :
- _DragSave(save%) :
- Start drag operation
-
- main%
-
- button%
- r:
- 2 :
- "MenuUtil_Show",menu_window%,Block%
-
- *****************************************************************
- * Actions when message is received from the WIMP *
- *****************************************************************
- _Message_Receive
- Version 1.58
- Block%!16
- 0 :
- _CloseDown
- 1 :
- _Message_Data_Save
- 2 :
- _Message_AcknowlegeSave
- 3 :
- _Message_LoadOpen(Block%)
- 10 :
- _Message_DesktopSave(Block%!20)
- &502 :
- _HelpDefinitions
- &400C2 :
- _Message_NewTask
- &400CC :
- _Window_Iconise
- _Message_Data_Save
- )Block%!0=(48+
- ("<Wimp$Scrap> "))
- Block%!12=Block%!8
- "Block%!16=2 :
- DataSaveAck
- $(Block%+44)="<Wimp$Scrap>"
- "Wimp_SendMessage",17,Block%,Block%!4
- _Message_NewTask
- newtaskid%=Block%!4
- /newtask$=
- _Convert_BlockToString(Block%+28)
- newtask$="DrawEdit"
- newtaskid%<>myid%
- _CloseDown
- _Message_LoadOpen(Block%)
- Block%!40
- &AFF
- _Drawfile_Load(
- _Convert_BlockToString(Block%+44)) :
- loads the file
- _Window_Open(main%,-1,-1)
- 2002,""
- _CloseDown
- Version 1.64
- "Wimp_CloseDown"
- _Message_DesktopSave(file%)
- Block%!12=Block%!8:
- "Wimp_SendMessage",19,Block%,Block%!4:
- The above line acknowledges the message if an error occurs, thereby
- aborting the desktop save.
- #file%,"Run <DrawEdit$Dir>.!RunImage"
- _Message_AcknowlegeSave
- Version 1.61
- pathname$
- 0pathname$=
- _Convert_BlockToString(Block%+44)
- _Icon_Write(save%,0,pathname$)
- _Drawfile_Save(pathname$)
- Block%!0=40+
- pathname$+4
- Block%!0+=4-(Block%!0
- $Block%!16=3 :
- Message_DataLoad
- Block%!36=0
- Block%!40=&FF8
- $(Block%+44)=pathname$+
- "Wimp_SendMessage",18,Block%,senderwindow%,sendericon%
- *****************************************************************
- * Error Handling *
- *****************************************************************
- _ErrorHandler
- sel%
- "Wimp_DragBox",,-1
- error$=
- 2001 : error$="Could not extend block."+" at Line "+
- 2002 : error$="This File type ("+
- ~Block%!40+") cannot be handled by DrawEdit."
- 2003 : error$=file$+" is too long to be handled by DrawEdit or Draw. Split it up, and reload it.":
- #file%
- 2004 : error$="The concatenated data is too long to be handled by DrawEdit or Draw. Split it up, and reload it.":
- #file%
- : error$="Error "+
- )+" at Line "+
- )+": "+
- !Block%=
- :$(Block%+4)=error$
- "Wimp_ReportError",Block%,%10011,"DrawEdit"
- ,sel%
- sel%=2
- _CloseDown
- *****************************************************************
- * Drag routines *
- *****************************************************************
- _DragSave(window%)
- Version 1.60
- LOCAL offset_x%,offset_y%
- !Block%=window%
- "Wimp_GetWindowState",,Block%
- offset_x%=Block%!4-Block%!20
- !offset_y%=Block%!16-Block%!24
- QBlock%!0=window% :
- Window owning the icon
- MBlock%!4=1 :
- Icon to be dragged
- "Wimp_GetIconState",,Block%
- Block%!0=Block%!8+offset_x%
- Block%!4=Block%!12+offset_y%
- Block%!8=Block%!16+offset_x%
- !Block%!12=Block%!20+offset_y%
- SYS "Wimp_DragBox",,Block%
- "DragASprite_Start",%11001111,1,"file_aff",Block%
- _DragBoxEnd(leafname$)
- "DragASprite_Stop"
- pointer%
- pointer%=
- leafname$
- pointer%>0
- leafname$,pointer%,1)<>"."
- pointer%-=1
- $leafname$=
- leafname$,pointer%+1)
- "Wimp_GetPointerInfo",,Block%
- senderwindow%=Block%!12
- sendericon%=Block%!16
- Block%!20=senderwindow%
- Block%!24=sendericon%
- Block%!28=Block%!0
- Block%!32=Block%!4
- Block%!0=44+
- leafname$
- Block%!0+=4-(Block%!0
- Block%!4=0
- Block%!8=0
- Block%!12=0
- $Block%!16=1 :
- Message_DataSave
- +Block%!36=0 :
- Length of proposed save
- Block%!40=&AFF
- $(Block%+44)=leafname$+
- "Wimp_SendMessage",17,Block%,senderwindow%,sendericon%
- *****************************************************************
- * Icon handling *
- *****************************************************************
- _Icon_Read(window%,icon%)
- result$
- Block%!0=window%
- Block%!4=icon%
- "Wimp_GetIconState",,Block%
- (Block%!24
- (1<<8))<>0
- result$=$(Block%!28)
- result$=$(Block%+28)
- =result$
- _Icon_Write(window%,icon%,text$)
- BBlock%!0=window%:Block%!4=icon%:
- "Wimp_GetIconState",,Block%
- (text$)>(Block%!36)-1
- ((Block%!24)
- (1<<9))=(1<<9)
- Right-justified
- ' text$="
- text$,(Block%!36)-2)
- #
- Left-justified or centred
- / text$=
- text$,(Block%!36)-1):
- text$)="
- ^ Ensures the text can't overflow the maximum space in the icon.
- $(Block%!28)<>text$
- / $(Block%!28)=text$:Block%!8=0:Block%!12=0
- "Wimp_SetIconState",,Block%
- "Wimp_GetCaretPosition",,Block%
- Block%!0=window%
- Block%!4=icon%
- If this icon owns the caret, then put it at the end.
- "Wimp_SetCaretPosition",window%,icon%,0,0,-1,
- (text$)
- _Icon_State_Selected(window%,icon%)
- sel%
- sel%=
- +BBlock%!0=window%:Block%!4=icon%:
- "Wimp_GetIconState",,Block%
- ((Block%!24)
- (1<<21))=(1<<21)
- sel%=
- - =sel%
- _Icon_Alter_Flags(window%,icon%,bit%,sel%)
- Block%!0=window%
- Block%!4=icon%
- sel%
- Block%!8=1<<(bit%-1)
- Block%!8=0
- Block%!12=1<<(bit%-1)
- "Wimp_SetIconState",,Block%
- _Icon_Create(window%,xmin%,ymin%,xmax%,ymax%,flags%,sprite$)
- icon%
- Block%!0=window%
- Block%!4=xmin%
- Block%!8=ymin%
- Block%!12=xmax%
- Block%!16=ymax%
- Block%!20=flags%
- $(Block%+24)=sprite$
- "Wimp_CreateIcon",,Block%
- icon%
- =icon%
- *****************************************************************
- * Miscellaneous *
- *****************************************************************
- _ScreenReadSize
- xw%,xh%,xf%,yf%
- "OS_ReadModeVariable",
- ,,xw%
- "OS_ReadModeVariable",
- ,,xh%
- "OS_ReadModeVariable",
- ,,xf%
- "OS_ReadModeVariable",
- ,,yf%
- scw%=xw%<<xf%
- sch%=xh%<<yf%
- _Convert_BlockToString(pointer%) :
- Reads a zero terminated string
- result$
- result$+=
- ?pointer%
- pointer%+=1
- ?pointer%=0
- ?pointer%=13
- =result$
- _KeyPressed(window%,icon%,char%)
- "Wimp_GetPointerInfo",,Block%
- CASE Block%!12 OF
- ENDCASE
- "Wimp_ProcessKey",char%
- *****************************************************************
- * Window routines *
- *****************************************************************
- _Window_Open(window%,x%,y%) :
- If x% or y% =-1 (TRUE) then the window is centered
- window_xsize%,window_ysize%
- Block%!0=window%
- "Wimp_GetWindowState",,Block%
- o$window_xsize%=Block%!12-Block%!4
- p$window_ysize%=Block%!16-Block%!8
- s' Block%!4=(scw%-window_xsize%)/2
- t' Block%!8=(sch%-window_ysize%)/2
- Block%!4=x%
- Block%!8=y%
- z$Block%!12=Block%!4+window_xsize%
- {$Block%!16=Block%!8+window_ysize%
- Block%!28=-1
- "Wimp_OpenWindow",,Block%
- _WindowState_Open(window%)
- result%
- Returns TRUE if window is open; false otherwise
- 5Block%!0=window%:
- "Wimp_GetWindowState",,Block%
- ((Block%!32)
- (1<<16))=(1<<16)
- result%=
- result%=
- =result%
- _Window_Close(window%)
- Block%!0=window%
- "Wimp_GetWindowState",,Block%
- "Wimp_CloseWindow",,Block%
- _Window_Iconise
- HBlock%!0=56:Block%!12=Block%!8:Block%!16=&400CC:
- Message_WindowInfo
- Block%!20=0
- Window handle
- Block%!24=0
- :$(Block%+28)="DrawEdit"+
- 0 :
- uses sprite ic_<name>
- 8$(Block%+36)="DrawEdit" :
- uses text <name>
- "Wimp_SendMessage",17,Block%,Block%!4
- *****************************************************************
- * Interactive Help *
- *****************************************************************
- _HelpDefinitions
- 9Block%!12=Block%!8:Block%!16=&503:helpinfo%=Block%+20
- Block%!32 gives window, Block%!36 gives icon
- Block%!32
- _HelpSend("This is the DrawEdit icon.")
- @
- _HelpSend("Click MENU for information or to quit.")
- C
- _HelpSend("Click SELECT to open the DrawEdit window.")
- main%:
- Block%!36
- 2
- 8 :
- _HelpSend("Toggle Grid On/Off.")
- 7
- 9 :
- _HelpSend("Toggle Grid Lock On/Off.")
- >
- 10 :
- _HelpSend("Toggle Grid Auto Adjust On/Off.")
- <
- 19 :
- _HelpSend("Toggle Isometric Grid On/Off.")
- 1
- 22 :
- _HelpSend("Toggle Grid Units.")
- 8
- 21 :
- _HelpSend("Enter Grid Subdivisions.")
- A
- 11,12,13,14,15,16 :
- _HelpSend("Select Paper Size.")
- <
- 17,18 :
- _HelpSend("Select Paper Orientation.")
- 8
- 23,25 :
- _HelpSend("Enter the Zoom Scale.")
- 8
- 26 :
- _HelpSend("Toggle Zoom Lock On/Off.")
- 6
- 27 :
- _HelpSend("Toggle Toolbox On/Off.")
- save%
- Block%!36
- O
- _HelpSend("Drag this icon to a filer window to save the file.")
- W
- _HelpSend("CSV, Data, Drawfile, DXF and Screenshots are supported.")
- 5
- _HelpSend("Enter the filename here.")
- info%:
- _HelpSend("This window displays information about DrawEdit.")
- ?helpinfo%=0
- 'Block%!0=(helpinfo%+4-Block%)
- "Wimp_SendMessage",17,Block%,Block%!4
- _HelpSend(text$)
- $helpinfo%=text$+"|M"
- helpinfo%+=
- (text$)+2
- *****************************************************************
- * Drawfile handling *
- *****************************************************************
- _Drawfile_Load(filename$)
- a%,file%
- unloaded%=
- "MenuUtil_Fade",menu_save%,unloaded%
- stack%=
- _Heap_Free(stack%)
- stack% =
- _Heap_Claim(4)
- "Hourglass_On"
- file%=
- filename$
- file$=filename$
- )temp% =
- _Heap_Extend(stack%,
- #file%)
- temp% <> 0
- stack% = temp%
- 2001,""
- "OS_GBPB",3,file%,stack%,
- #file%
- #file%-4
- #file%
- _Read_Paper
- _Read_Aspect
- _Read_Divisions
- _Read_AutoAdjust
- _Read_Grid
- _Read_GridLock
- _Read_Units
- _Read_ZoomScale
- _Read_ZoomLock
- _Read_Toolbox
- "Hourglass_Off"
- _Drawfile_Save(pathname$)
- "Hourglass_On"
- file%=
- pathname$
- _Drawfile_CheckOptionValidity
- _Drawfile_Alter
- "SetType "+pathname$+" AFF"
- #file%
- "Hourglass_Off"
- "Wimp_CreateMenu",,-1
- _WindowState_Open(save%))=
- _Window_Close(save%)
- _Drawfile_CheckOptionValidity
- Version 1.49
- #divs%=
- _Icon_Read(main%,21))
- #zooma%=
- _Icon_Read(main%,23))
- #zoomb%=
- _Icon_Read(main%,25))
- divs%=0
- divs%=10:
- _Icon_Write(main%,21,
- (divs%))
- zooma%=0
- zooma%=4:
- _Icon_Write(main%,23,
- (zooma%))
- zoomb%=0
- zoomb%=1:
- _Icon_Write(main%,25,
- (zoomb%))
- _Drawfile_Alter
- Version 1.50
- grid%,lock%,autoadj%,paper%,portrait%,isom%,inches%,zlock%,toolbox%
- papernumber%
- inches%=0:paper%=&100
- _Icon_State_Selected(main%,8)
- grid%=1
- _Icon_State_Selected(main%,9)
- lock%=1
- _Icon_State_Selected(main%,10)
- autoadj%=1
- papernumber%=1
- _Icon_State_Selected(main%,10+papernumber%)
- paper%=&100*papernumber%
- _Icon_State_Selected(main%,18)
- portrait%=&10
- _Icon_State_Selected(main%,19)
- isom%=1
- _Icon_State_Selected(main%,22)
- inches%=1
- _Icon_State_Selected(main%,26)
- zlock%=1
- _Icon_State_Selected(main%,27)
- toolbox%=1
- #stack%!64=(paper%)
- $stack%!68=(portrait%)
- #stack%!80=(divs%)
- *stack%!84=(isom%)
- #stack%!88=(autoadj%)
- &stack%!92=(grid%)
- #stack%!96=(lock%)
- (stack%!100=(inches%)
- stack%!104=(zooma%)
- stack%!108=(zoomb%)
- $stack%!112=(zlock%)
- stack%!116=(toolbox%)
- "OS_GBPB",1,file%,stack%,n%+4
- *****************************************************************
- * Wimp Heap Routines *
- *****************************************************************
- _Heap_Initialise
- heap_temp%
- "OS_ReadMemMapInfo"
- _wh_pagesize%
- (# _wh_heapsize% = _wh_pagesize%
- "Wimp_SlotSize",-1,-1
- heap_temp%
- *' _wh_heaploc% = heap_temp% + &8000
- "Wimp_SlotSize",_wh_heaploc% + _wh_heapsize% - &8000,-1
- "OS_Heap",0,_wh_heaploc%,,_wh_heapsize%
- _Heap_Claim(heapsize%)
- heap_temp%,result%
- "XOS_Heap",2,_wh_heaploc%,,heapsize%
- ,,heap_temp%
- heap_temp% <> 0
- result%=heap_temp%
- 51
- _Heap_InternalExtend(heapsize%) =
- result%=0
-
- 8?
- "XOS_Heap",2,_wh_heaploc%,,heapsize%
- ,,result%
- 9!
- _Heap_InternalShrink
-
- =result%
- _Heap_Extend(block%, change%)
- heap_temp%,heap_temp2%,heap_temp3%,result%
- result%=0
- "XOS_Heap",4,_wh_heaploc%,block%,change%
- ,,heap_temp% ;heap_temp2%
- (heap_temp2%
- 1) = 0
- result%=heap_temp%
- E<
- "OS_Heap",6,_wh_heaploc%,block%
- ,,,heap_temp3%
- F;
- _Heap_InternalExtend(heap_temp3%+change%) =
- result%=0
-
- IS
- "XOS_Heap",4,_wh_heaploc%,block%,change%
- ,,heap_temp% ;heap_temp2%
- J7
- (heap_temp2%
- 1) = 0
- result%=heap_temp%
-
- =result%
- _Heap_Free(block%)
- "OS_Heap",3,_wh_heaploc%,block%
- _Heap_InternalShrink
- _Heap_LargestFree
- result%
- "OS_Heap",1,_wh_heaploc%
- ,,result%
- =result%
- *****************************************************************
- * Wimp Heap Routines (Internal) *
- *****************************************************************
- _Heap_InternalExtend(size%)
- heap_temp%,heap_temp2%,result%
- _@ heap_temp% =
- _Heap_InternalRoundup(_wh_heapsize% + size%)
- "XWimp_SlotSize",_wh_heaploc% + heap_temp% - &8000,-1
- ;heap_temp2%
- (heap_temp2%
- 1) = 1
- result%=
- d@
- "OS_Heap",5,_wh_heaploc%,,heap_temp% - _wh_heapsize%
- e# _wh_heapsize% = heap_temp%
- result%=
- =result%
- _Heap_InternalShrink
- heap_temp%,heap_temp2%
- l heap_temp% = _wh_heapsize%
- "XOS_Heap",5,_wh_heaploc%,,-heap_temp%
- ,,,heap_temp2%
- heap_temp2% = -heap_temp%
- heap_temp2% = heap_temp%
- oI _wh_heapsize% =
- _Heap_InternalRoundup(_wh_heapsize% - heap_temp2%)
- "XOS_Heap",5,_wh_heaploc%,,_wh_heapsize% - (heap_temp% - heap_temp2%)
- "Wimp_SlotSize",_wh_heaploc% + _wh_heapsize% - &8000,-1
- _Heap_InternalRoundup(result%)
- heap_temp%
- (result%
- _wh_pagesize%) <> 0
- w> heap_temp% = _wh_pagesize% - (result%
- _wh_pagesize%)
- result% += heap_temp%
- =result%
- *****************************************************************
- * Read Drawfile Options *
- *****************************************************************
- _Read_Paper
- paper%=stack%!64/&100
- a%=1
- a%=paper%
- _Icon_Alter_Flags(main%, 10+a%,22,
- _Icon_Alter_Flags(main%, 10+a%,22,
- _Read_Aspect
- portrait%=stack%!68
- portrait%=&10
- _Icon_Alter_Flags(main%, 18,22,
- _Icon_Alter_Flags(main%, 17,22,
- _Icon_Alter_Flags(main%, 17,22,
- _Icon_Alter_Flags(main%, 18,22,
- _Read_Divisions
- divs%=stack%!80
- _Icon_Write(main%,21,
- (divs%))
- isom%=stack%!84
- isom%=1
- _Icon_Alter_Flags(main%, 19,22,
- _Icon_Alter_Flags(main%, 19,22,
- _Read_AutoAdjust
- autoadj%=stack%!88
- autoadj%=1
- _Icon_Alter_Flags(main%, 10,22,
- _Icon_Alter_Flags(main%, 10,22,
- _Read_Grid
- grid%=stack%!92
- grid%=1
- _Icon_Alter_Flags(main%,8,22,
- _Icon_Alter_Flags(main%,8,22,
- _Read_GridLock
- lock%=stack%!96
- lock%=1
- _Icon_Alter_Flags(main%,9,22,
- _Icon_Alter_Flags(main%,9,22,
- _Read_Units
- inches%=stack%!100
- inches%=1
- _Icon_Alter_Flags(main%,22,22,
- _Icon_Alter_Flags(main%,22,22,
- _Read_ZoomScale
- zooma%=stack%!104
- zoomb%=stack%!108
- _Icon_Write(main%,23,
- (zooma%))
- _Icon_Write(main%,25,
- (zoomb%))
- _Read_ZoomLock
- zlock%=stack%!112
- zlock%=1
- _Icon_Alter_Flags(main%,26,22,
- _Icon_Alter_Flags(main%,26,22,
- _Read_Toolbox
- toolbox%=stack%!116
- toolbox%=1
- _Icon_Alter_Flags(main%,27,22,
- _Icon_Alter_Flags(main%,27,22,
-