tickets_holder.anubis 2.41 KB

   
   
                             The Anubis/Paradize Project.
   
                               The ticket holder widget. 
   
                          Copyright (c) Alain Prouté 2004-2005. 

   
   Authors:   Alain Prouté

   
read widget.anubis   
read tools.anubis   

   
   This  file defines  the  'ticket holder'  widget.  This  widget  has a  content but  is
   invisible  by  itself. It  is  identical  to its  content  except  that  it offers  the
   possibility to hold a monitoring ticket (so that it is not garbage-collected while this
   widget exists).

   Monitoring tickets  may be of various  types. Hence, each ticket  is first encapsulated
   into a dummy function  of type One -> One. This allows to  make lists of tickets, since
   tir particular type does not appear.
   
public type TicketHolder:
   th(One -> One). 
   
   Put your tickets into ticket holders with:
   
public define TicketHolder
   ticket_holder
     (
       MonitoringTicket($T) ticket
     ). 
   
   Now keep your tickets beside a widget (content) with:
   
public define Widget
   create_tickets_holder
     (
       List(TicketHolder)     tickets, 
       Widget content
     ). 
   
   
   
   
   --- That's all for the public part ! --------------------------------------------------
   
   
   
public define TicketHolder
   ticket_holder
     (
       MonitoringTicket($T) ticket
     ) =
   th((One u) |-> forget(ticket)). 
   
   The above  function '(One u) |->  forget(ticket)' will never be  executed.  However, it
   contains  a reference  to the  monitoring  ticket. Hence,  since the  function will  be
   referenced   from   within   the   new   widget,   the   monitoring   ticket   is   not
   garbage-collected.   It  is   garbage-collected  only   when  the   widget   itself  is
   garbage-collected.
   
public define Widget   
   create_tickets_holder
     (
       List(TicketHolder) tickets, 
       Widget content
     ) =
   create_widget(
   
   /* set childs positions */ 
   (WidgetPositionToolBox ptb) |-> 
      set_position(content)(ptb,position(0,0)), 
      
   /* get size */ 
   get_size(content), 
   
   /* redraw */ 
   redraw(content), 
      
   /* Duplicate */ 
   (One u) |-> create_tickets_holder(tickets,duplicate(content)(unique)), 
   
   /* Change size */ 
   (Int32 w, Int32 h) |-> alert, 
   
   /* event handling */ 
   main_event_handler(content), 
   
   /* monitoring */ 
   [ ]
   ).