home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
RiscOS
/
APP
/
DEVS
/
LIB
/
POPUP.ZIP
/
PopUp
/
!PopUpTest
/
!RunImage
(
.txt
)
< prev
next >
Wrap
RISC OS BBC BASIC V Source
|
1993-05-25
|
16KB
|
447 lines
>!PopUpTest.!RunImage
Test/Demonstration application for PopUps
Find a Wimp_OpenTemplate/LoadTemplate/CreateWindow/OpenWindow
call in this program if you can!
By Jason Williams 1993
This code is (truly) Public Domain
(You may use useful portions of this code in your own programs)
26,4,7:
"PopUpTest quitting due to error: ";
$;" /";
--- Global constants -----------------------------------------------------
OPopUpAsWindow = 0 :
Application flags - standalone MENU PopUp
LPopUpAsSubmenu = 1 :
- SubMenu MENU PopUp
FPopUpIsStatic = 2 :
- STATIC PopUp
:Message_Quit = 0 :
Wimp message numbers
Message_DataSave = 1
Message_DataSaveAck = 2
Message_DataLoad = 3
!Message_MenuWarn = &400C0
!Message_PopUpRequest = &46D40
!Message_PopUpState = &46D41
OSaveAs_OKClick = %00000001 :
Save-As returned flagword bits
$SaveAs_ShiftDown = %00000010
Report_CancelOnly = 1
Report_OKOnly = 2
Report_OKAndCancel = 3
--- PopUp data -----------------------------------------------------------
popup% 256 :
Block for PopUp data
F%=0
250
4 :
Which we clear out (I'm a tidy chap ;-)
popup%!F% = 0
*.popuphandle% = 0 :
No valid popup
,:MagMul% = 1:MagDiv% = 1 :
Default Magnifier settings
.JDefaultSaveName$ = "PopUpFile" :
Name to put in SaveAs writable icon
0QNewWimpColour% = 7 :
WimpColour initially defaults to colour 7 (black)
2AColourFormat% = 0 :
TrueColour initially defaults to:
3FNewTrueColour% = 0 :
Colour = black, specified as RGB value
4/NewTransparent% = 0 :
NO transparency
--- Wimp initialisation --------------------------------------------------
b% 256, m% 256
$b%="TASK"
"Wimp_Initialise", 200, !b%, "PopUp Tester"
,taskhandle%
--- Ensure PopUp Manager/Server running ----------------------------------
?C*RMEnsure PopUpManager 0.86 WimpTask Run <PopUpServer$Dir>.!Run
--- Create IconBar icon --------------------------------------------------
CHb%!0 = -1: b%!4 = 0: b%!8 = 0: b%!12 = 68: b%!16 = 68: b%!20 = &3002
D@$(b%+24) = "!PopUpTest":
"Wimp_CreateIcon",,b%
baricon%
--- Wimp_Poll loop -------------------------------------------------------
quit%=
"Wimp_Poll", 1, b%
reasoncode%
reasoncode%
MK
6:
click -------------------------------
N6
b%!12 < 0
b%!16 = baricon%
createmenu
PK
9:
menu choice -------------------------
!b%
R,
7:
"Quit"
quit%=
U<
:
"Info" and the demo PopUps.
VM
User clicked on the menu item instead of following the arrow.
WO
We thus open the PopUp conveniently under the pointer position.
Y.
"Wimp_GetPointerInfo",,b% + 4
Z?
popup(b%!0, b%!4 - 64, b%!8 + 64, PopUpAsWindow)
]K
17, 18:
Incoming message --------------------
b%!16
Message_Quit:
quit% =
b"
Message_DataSaveAck:
cN
Our SaveAs procedure has sent a DataSave message to the filer,
dF
and this is the reply telling us to go ahead and save.
e3
The full file pathname is at b%+44.
g+
savedata(
zerostring(b%+44))
Message_MenuWarn:
j;
Menu Warning (A submenu needs to be opened)
kG
b%!20 = the sublink number we gave in Wimp_CreateMenu
l@
b%!24, b%!28 = x,y position to open submenu at
mK
b%!32... list of menu selection values terminated by a -1
o9
popup(b%!32, b%!24, b%!28, PopUpAsSubmenu)
q#
Message_PopUpRequest:
rJ
Request from the PopUp Manager for us to attach its window
sL
to our menu tree. Simply call CreateSubMenu with the data it
t+
has sent us in the message.
v:
"Wimp_CreateSubMenu",,b%!20, b%!24, b%!28
x!
Message_PopUpState:
y=
A PopUp is trying to return new values to us.
zH
The following is the handle we were given - this is only
{B
important, however, if the PopUp is a STATIC PopUp
|" PopUpHandle% = b%!20
~%
zerostring(b%+24)
"Magnify":
! MagMul% = b%!36
! MagDiv% = b%!40
26, 4, 7
N
"PopUpTest: New Magnification is ";MagMul%;":";MagDiv%;" "
"Print":
+ NumCopiesToPrint% = b%!36
26, 4, 7
M
"PopUpTest: Time to print ";NumCopiesToPrint%;" copies! "
C
"Report" handled separately in PROCreport() below
"SaveAs":
savefile
"WimpColour":
) NewWimpColour% = b%?36
26, 4, 7
C
"PopUpTest: New colour is ";NewWimpColour%;" "
"TrueColour":
) ColourFormat% = b%!36
) NewTrueColour% = b%!40
) NewTransparent% = b%!44
quit%
"Wimp_CloseDown"
--------------------------------------------------------------------------
createmenu :
Show our iconbar menu
$(m%) = "PopUp Test"
m%!12 = &70207
m%!16 = 16 * 12
m%!20 = 44
m%!24 = 0
Menu flags used below: 8 = Warn on submenu opening, } 8 + 2 = &0A
2 = followed by dotted line }
80 = last item in the menu
Menu flags Sublink Icon flags Text
~~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
M p%=m%+28: p%!0 = &0A: p%!4 = 1: p%!8 = &7000021: $(p% + 12) = "Info"
P p%+=24: p%!0 = &08: p%!4 = 2: p%!8 = &7000021: $(p% + 12) = "Magnify"
N p%+=24: p%!0 = &08: p%!4 = 3: p%!8 = &7000021: $(p% + 12) = "Print"
Q p%+=24: p%!0 = &08: p%!4 = 4: p%!8 = &7000021: $(p% + 12) = "ProgInfo"
R p%+=24: p%!0 = &00: p%!4 = -1: p%!8 = &7000021: $(p% + 12) = "Report..."
O p%+=24: p%!0 = &08: p%!4 = 6: p%!8 = &7000021: $(p% + 12) = "SaveAs"
S p%+=24: p%!0 = &0A: p%!4 = 7: p%!8 = &7000021: $(p% + 12) = "WimpColour"
M p%+=24: p%!0 = &80: p%!4 = -1: p%!8 = &7000021: $(p% + 12) = "Quit"
& numitems% = (p% - (m% + 4)) / 24
"Wimp_CreateMenu",,m%, b%!0 - 64, 96 + (2 * 24) + (44 * numitems%)
--------------------------------------------------------------------------
popup(mainitem%, x%, y%, flags%)
fillpopupblock(x%, y%, flags%)
mainitem%
0: :
"Info" menu item
7 $popup% = "ProgInfo" :
PopUp Name
( $(popup% + &18) = "PopUp tester"
. $(popup% + &38) = "Test PopUp modules"
7 $(popup% + &58) = "
Copyright 1993 J.Williams"
, $(popup% + &78) = "2.00 (21 May 93)"
1: :
"Magnify" menu item
7 $(popup%) = "Magnify" :
Popup Name
J popup%!24 = MagMul% :
Default multiplier icon value
G popup%!28 = MagDiv% :
Default divisor icon value
H popup%!32 = 1 :
} Multiplier must be in the
G popup%!36 = 100 :
} range 1 to 100 inclusive
E popup%!40 = 1 :
} Divisor must be in the
E popup%!44 = 4 :
} range 1 to 4 inclusive
F $(popup% + 48) = "Ratio" :
Text for window title bar
2: :
"Print" menu item
7 $popup% = "Print" :
PopUp Name
F popup%!24 = 1 :
Number of copies to print
3: :
"ProgInfo" menu item
7 $popup% = "ProgInfo" :
PopUp Name
1 $(popup% + &18) = "ProgInfo PopUp Sample"
7 $(popup% + &38) = "(A display-only MENU PopUp)"
7 $(popup% + &58) = "
Copyright 1993 J.Williams"
, $(popup% + &78) = "1.00 (01 Jan 01)"
4: :
"Report ..." menu item
x message$ = "Please do not choose that menu item again. Click 'Continue' to continue, or 'Abort' to continue ;-)"
F
report(Report_OKAndCancel, "Continue", "Abort", message$)
H
26,4,7:
"PopUpTest: You opted to CONTINUE. Am I right? ;-) "
L
26,4,7:
"PopUpTest: I will ignore that and continue anyway ;-) "
F
:
Exit from this PROC immediately
5: :
"Save As" menu item
7 $popup% = "SaveAs" :
PopUp Name
B $(popup% + 24) = "file_fff" :
File icon sprite name
N $(popup% + 36) = DefaultSaveName$:
Default text for save-as writable
6: :
"WimpColour" menu item
7 $popup% = "WimpColour" :
PopUp Name
C popup%?24 = NewWimpColour% :
Default to this colour
"PopUp_Open", popup%
popuphandle%
fillpopupblock(x%, y%, flags%)
Set up the generic part of the application parameter block...
(Used by 2 places in the program, so I've made it a procedure)
7popup%!12 = x% :
PopUp XPos
7popup%!16 = y% :
PopUp YPos
Opopup%?20 = flags% :
Flags: Leaf or 'submenu' dialogue?
I :
Menu or Static PopUp?
*
Bpopup%?21 = 0 :
Plus 3 reserved bytes
?popup%?22 = 0 :
Which must be zero
popup%?23 = 0
--------------------------------------------------------------------------
zerostring(address%) :
Read a zero-terminated string
A%=address%
?A% > 31: A%+=1:
?A%=&0d
=$address%
--------------------------------------------------------------------------
savefile
flags%, window, icon, xpos, ypos
ON Entry, the pollblock (b%) contains the Message_PopUpState from the
SaveAs PopUp.
flags% = b%!36
flags%
SaveAs_OKClick
The SaveAs 'OK' button was clicked (or RETURN pressed), and the filename
appears valid, so we can just try saving to the given name.
savedata(
zerostring(b%+44))
The SaveAs file icon was dragged and dropped onto another window.
We thus build a DataSave message and send it to the window under the
pointer, to initiate a save.
"Wimp_GetPointerInfo",,b%
>< window = b%!12 :
window under pointer
?: icon = b%!16 :
icon under pointer
@1 xpos = b%!0 :
pointer x
A1 ypos = b%!4 :
pointer y
C= b%!0 = 256 :
Message header : size
D? b%!4 = 0 :
sender
E? b%!8 = 0 :
my-ref
FA b%!12 = 0 :
your-ref
G? b%!16 = Message_DataSave :
action
IF b%!20 = window :
DataSave msg: window handle
JD b%!24 = icon :
icon handle
KK b%!28 = xpos :
pointer position x
LK b%!32 = ypos :
pointer position y
ML b%!36 = 80 :
Estimated file size
NO b%!40 = &FFF :
File type (FFF = Text)
b%+44 onwards already contains the proposed leafname, as returned
by the SaveAs popup in the Message_PopUpState.
"Wimp_SendMessage", 17, b%, window, icon
savedata(filepathname$)
(filepathname$)
(F% = 0)
:
ERROR - can't open output file
#F%, "Output for testing/demonstrating SaveAs PopUp operation"
("SetType "+filepathname$+" Text")
bMDefaultSaveName$ = filepathname$ :
emeber this as new SaveAs icon default
--------------------------------------------------------------------------
report(reportflags%, oktext$, canceltext$, message$)
done%, result%
26,4,7:
"PopUpTest Fatal Error: ";
If we want to report an error/problem/message, then we call this function.
It is sortof equivalent to SYS "Wimp_ReportError", but allows other
tasks to CONTINUE MULTITASKING while we are reporting the problem.
Parameters:
IN
reportflags% = Report_OKOnly, ReportCancelOnly, or Report_OKAndCancel
the strings are text for OK/Cancel buttons and Message to report
OUT
Returns TRUE if 'OK' was clicked, or FALSE if 'Cancel' was clicked
EXPLANATION
It first creates a PopUp "Report", and then waits for it to return a
result to us before allowing the user to do anything else. This is
achieved by using a new Wimp_Poll loop that ignores all events except
a) those events that we MUST process (redraws, open window requests)
b) those events that we want to process (quit, Report state return)
Note that this can be called at any time, and will not return until
the user has ackknowledged the report dialogue box - perfect in
cases when you want to ask about something before continuing.
Note also that I am repeating a bit of code here - this is to provide
a function that you can copy & paste into your own programs which will
(with slight modifications) allow you to show a problem/message report
by just calling this function. Simple!
(BTW, remember to also copy fillpopupblock, and use popup%!)
"Wimp_GetPointerInfo",,b%
fillpopupblock(b%!0 - 64, b%!4 + 64, PopUpAsWindow)
3$popup% = "Report" :
PopUp Name
"popup%!24 = reportflags%
#$(popup% + 28) =
oktext$, 11)
'$(popup% + 40) =
canceltext$, 11)
P$(popup% + 52) = "PopUp Test" :
**** Put 12-char application name here!
%$(popup% + 64) =
message$, 187)
"Wimp_CreateMenu",,-1 :
Ensure menu is killed
"PopUp_Open", popup%
popuphandle%
popuphandle% = 0
Failed! Argh!
done% =
result% =
"Wimp_Poll", 1, b%
reasoncode%
reasoncode%
P
emeber that you MUST handle REDRAW, OPEN requests for your own windows!
17, 18:
b%!16
Message_Quit:
quit% =
done% =
#
Message_PopUpRequest:
:
"Wimp_CreateSubMenu",,b%!20, b%!24, b%!28
!
Message_PopUpState:
&
b%!20 = popuphandle%
6 result% = (b%!36
Report_OKOnly) <> 0
done% =
done%
= result%