Dynamic creation of controls. Was: Re: [clean-list] (no
subject)
Peter Achten
peter88@cs.kun.nl
Fri, 24 Aug 2001 13:10:47 +0200
--=====================_70695035==_
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 11:55 24-8-01 +0200, Fabien Todescato wrote:
>Dear Cleaners, and ObjectIO1.2.1 users,
>
>I am at the moment considering the development of a small application
>needing dialogues with a dynamically computed set of controls. I had a quick
>glance at the StdControl.dcl definition module and noticed the functions
>openControls and closeControls that seem to adress my problems. As there is
>to my knowledge no examples about the use of these functions in the
>documentation, I have about these the following questions.
Thank you for bringing this to my attention. I will include a short example
about dynamically creating and closing controls in windows/dialogues in the
next version of the Object I/O Tutorial.
>Can anyone share some of his/her experience using these functions ?
>Is the layout of the dialogue automatically recomputed when the sets of its
>control is dynamically changed with the above functions ?
I have digged in my set of test examples and found the attached module. You
can play around with it to see what happens when you use different types of
controls, different layout directions, and windows/dialogues.
Regards,
Peter
--=====================_70695035==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="windowcontrolstest.icl"
module windowcontrolstest
/* This module tests the addition/removal of controls in a Window.
You can change it easily to a Dialog by replacing the following:
openWindow --> openDialog (line 17)
Window "Window" --> Dialog "Dialog" (line 19)
Tested with Clean 1.3.3 and Object I/O 1.2.1
*/
import StdEnv, StdIO, StdDebug
:: DialogState
:== [Id]
Start :: *World -> *World
Start world
# (addId,world) = openId world
= startIO SDI Void (snd o openWindow [] (ddef addId)) [ProcessClose closeProcess] world
ddef addId = Window "Window"
( ButtonControl "Remove" [ControlFunction remove,ControlPos (Right, zero)]
:+: ButtonControl "Add" [ControlFunction add, ControlPos (BelowPrev,zero)]
)
[ WindowClose (noLS closeProcess)
, WindowViewSize {w=100,h=200}
, WindowId addId
]
where
add (ids,pst)
# (id,pst) = openId pst
# (error,pst) = openControls addId Void
// ( TextControl (toString n) [posAtt,ControlId id]
// ( CustomControl {w=20,h=20} (intbox n) [posAtt,ControlId id]
( CustomButtonControl {w=20,h=20} (intbox n) [posAtt,ControlId id]
// ( ButtonControl (toString n) [posAtt,ControlId id]
) pst
| error==NoError
= ([id:ids],pst)
| otherwise
= trace_n (toString error) (ids,pst)
where
n = length ids
// ALTERNATIVE LAYOUT POSITIONS OF THE NEW CONTROLS:
posAtt = ControlPos (Fix,OffsetVector {vx=0,vy=n*20})
// posAtt = ControlPos (Center,zero)
intbox n _ {newFrame}
= drawAt {x=3,y=15} (toString n) o draw newFrame o unfill newFrame
remove ([last:ids],pst)
= (ids,appPIO (closeControls addId [last] True) pst)
remove st
= st
--=====================_70695035==_--