window.anubis 6.97 KB

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

   
   Authors:   Alain Prouté
              Olivier Duvernois

   
read widget.anubis
read tools.anubis   
read table.anubis
read simple_window.anubis
read scrollbar.anubis
read box.anubis
read resizer.anubis
read tickets_holder.anubis

   This 'window' widget is a combination of several 'atomic' widgets. Actually, the window
   widget is a table designed as follows:
   
   
       +-----------------------+---+
       |                       |   |
       |                       |   |
       |                       |   |
       |                       |   |
       |                       |   |
       |          1            | 2 |
       |                       |   |
       |                       |   |
       |                       |   |
       |                       |   |
       |                       |   |
       +-----------------------+---+
       |          3            | 4 |
       +-----------------------+---+
   
   where cell 1 contains a simple window, cells 2 and 3 scrollbars, and cell 4 is empty. 
   
   However, the  vertical scrollbar or  the horizontal scrollbar  may be absent.   We also
   provide  a  function for  creating  a  window  whoses scrollbars  appear  automatically
   depending  on the  size of  the window  and the  size of  the content.  Use one  of the
   following for creating a window:
   
     create_window_both          for creating a window with two scrollbars
     create_window_vertical      for creating a window with only a vertical scrollbar
     create_window_horizontal    for creating a window with only an horizontal scrollbar
     create_window_automatic     for creating a window with automatic scrollbars
   

public define Widget       
   create_window_both
     (
       WidgetParameters      parameters, 
       Var(Int32)                 width,    // dimensions of cell 1
       Var(Int32)                height, 
       Widget                   content     // content of simple window in cell 1
     ). 
   
public define Widget
   create_window_vertical
     (
       WidgetParameters      parameters, 
       Var(Int32)                 width,
       Var(Int32)                height, 
       Widget                   content 
     ). 
   
public define Widget
   create_window_horizontal
     (
       WidgetParameters      parameters, 
       Var(Int32)                 width,
       Var(Int32)                height, 
       Widget                   content 
     ). 
   
public define Widget
   create_window_automatic
     (
       WidgetParameters      parameters, 
       Var(Int32)                 width,
       Var(Int32)                height, 
       Widget                   content 
     ). 
   
   
   --- That's all for the public part ! --------------------------------------------------
   
   

public define Widget       
   create_window_both
     (
       WidgetParameters      parms, 
       Var(Int32)          width_v, 
       Var(Int32)         height_v, 
       Widget              content
     ) = 
   if get_size(content)(unique) is (cont_w,cont_h) then
   with   win_x_v = var((Int32)0), 
          win_y_v = var((Int32)0), 
       v_domain_v = var((Int32)(*height_v)-24),
       h_domain_v = var((Int32)(*width_v)-24),
         cont_w_v = var((Int32)cont_w), 
         cont_h_v = var((Int32)cont_h), 
              w_v = var((Int32)12), 
   
   
     create_tickets_holder([
       ticket_holder(register_monitor(height_v,(One u) |-> v_domain_v <- (*height_v)-24)),
       ticket_holder(register_monitor(width_v ,(One u) |-> h_domain_v <- (*width_v )-24)),
                          ],
     create_table(borders(parms,0,0),
                  0,0,
       [
         [
           cell(center,center,
             create_simple_window(width_v,height_v,win_x_v,win_y_v,content)),
           cell(center,center,
             create_vertical_scrollbar(parms,v_domain_v,w_v,cont_h_v,win_y_v,height_v))
         ],
         [
           cell(center,center,
             create_horizontal_scrollbar(parms,h_domain_v,w_v,cont_w_v,win_x_v,width_v)),
           cell(center,center,
             create_resizer(parms,width_v,height_v,w_v))
         ]
       ])).
   
   
public define Widget       
   create_window_vertical
     (
       WidgetParameters      parms, 
       Var(Int32)          width_v, 
       Var(Int32)         height_v, 
       Widget              content
     ) = 
   if get_size(content)(unique) is (cont_w,cont_h) then
   with   win_x_v = var((Int32)0), 
          win_y_v = var((Int32)0), 
       v_domain_v = var((Int32)(*height_v)-24),
       h_domain_v = var((Int32)(*width_v)-24),
         cont_w_v = var((Int32)cont_w), 
         cont_h_v = var((Int32)cont_h), 
              w_v = var((Int32)12), 
   
     create_table(borders(parms,0,0),
                  0,0,
       [
         [
           cell(center,center,
             create_simple_window(width_v,height_v,win_x_v,win_y_v,content)),
           cell(center,center,
             create_vertical_scrollbar(parms,v_domain_v,w_v,cont_h_v,win_y_v,height_v))
         ]
       ]).
   
   
public define Widget       
   create_window_horizontal
     (
       WidgetParameters      parms, 
       Var(Int32)          width_v, 
       Var(Int32)         height_v, 
       Widget              content
     ) = 
   if get_size(content)(unique) is (cont_w,cont_h) then
   with   win_x_v = var((Int32)0), 
          win_y_v = var((Int32)0), 
       v_domain_v = var((Int32)(*height_v)-24),
       h_domain_v = var((Int32)(*width_v)-24),
         cont_w_v = var((Int32)cont_w), 
         cont_h_v = var((Int32)cont_h), 
              w_v = var((Int32)12), 
   
     create_table(borders(parms,0,0),
                  0,0,
       [
         [
           cell(center,center,
             create_simple_window(width_v,height_v,win_x_v,win_y_v,content)),
         ],
         [
           cell(center,center,
             create_horizontal_scrollbar(parms,h_domain_v,w_v,cont_w_v,win_x_v,width_v))
         ]
       ]).
   
   
public define Widget
   create_window_automatic
     (
       WidgetParameters           parms, 
       Var(Int32)                 width,
       Var(Int32)                height, 
       Widget                   content 
     ) =
   if get_size(content)(unique) is (mw,mh) then 
   if (*width < mw)
   then if (*height < mh)
        then // content is both too wide and too high
          create_box(relief(parms),2,
             create_window_both(parms,var((Int32)(*width)-30),var((Int32)(*height)-30),content))
        else // content is just too wide 
          create_box(relief(parms),2,
             create_window_horizontal(parms,var((Int32)(*width)-30),var((Int32)mh),content))
   else if (*height < mh)
        then // content is just too high
          create_box(relief(parms),2,
             create_window_vertical(parms,var((Int32)mw),var((Int32)(*height)-30),content))
        else // content fits
             content.