box.anubis 3.52 KB

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

   
   Authors:   Alain Prouté
              Olivier Duvernois


read tools/basis.anubis   
read widget.anubis   
read tools.anubis   

   
   This file  defines the 'box'  widget. A box  is just a  frame (shown with  some relief)
   surrounding a widget (the content of the box).
   
   Boxes are available in different styles: 
   
public type BoxStyle:
   frame  (WidgetParameters),
   relief (WidgetParameters),
   relief (RGB). 
   
public define Widget
   create_box
     (
       BoxStyle   style, 
       Int32      border_width,
       Widget     content
     ). 
   
   
   
   
   
   --- That's all for the public part ! --------------------------------------------------
   
   
   
define One -> (Int32,Int32)
   box_get_size
     (
       Widget content,
       Int32 border_width
     ) =
   (One u) |-> if get_size(content)(unique) is (c_w,c_h) then 
      (c_w+2*border_width,c_h+2*border_width). 

   
public define Widget   
   create_box
     (
       BoxStyle   style, 
       Int32      border_width, 
       Widget     content
     ) =
   with          b_width = if border_width >= 0 then border_width else 0, 
        content_impacted = var((Bool)false), 
   create_widget(
   
   /* set childs positions */ 
   (WidgetPositionToolBox ptb) |-> 
      set_position(content)(ptb,position(b_width,b_width)), 
   
   /* get size */ 
   box_get_size(content,b_width),
   
   /* redraw */ 
   (WidgetDrawToolBox dtb) |-> 
     if box_get_size(content,b_width)(unique) is (w,h) then 
     if style is 
       {
         frame(parms) then 
           with color = *main_color_v(parms),
                light = *light_color_v(parms), 
                 dark = *dark_color_v(parms), 
           draw(dtb)(rect(0,0,w,b_width),color); 
           draw(dtb)(rect(0,b_width,b_width,h-b_width),color); 
           draw(dtb)(rect(w-b_width,b_width,w,h-b_width),color); 
           draw(dtb)(rect(0,h-b_width,w,h),color);
           draw_relief_edge(dtb,1,rect(0,0,w,h),light,dark);
           draw_hollow_edge(dtb,1,rect(b_width-1,b_width-1,w-b_width+1,h-b_width+1),light,dark), 
   
         relief(parms) then 
           with color = *main_color_v(parms),
                light = *light_color_v(parms), 
                 dark = *dark_color_v(parms), 
           draw_relief_area(dtb,1,rect(0,0,w,h),color,light,dark),
   
         relief(color) then
           with light = lighten(color), 
                 dark = darken(color), 
           draw_relief_area(dtb,1,rect(0,0,w,h),color,light,dark)
       };
     redraw(content)(dtb), 
      
   /* Duplicate */ 
   (One u) |-> create_box(style,border_width,duplicate(content)(unique)), 
   
   /* Change size */ 
   (Int32 w, Int32 h) |-> 
     with d = 2*border_width, 
     change_size(content)(w-d,h-d), 
   
   /* event handling */ 
   (WidgetEventToolBox etb, WidgetNormalEvent e) |-> 
     if box_get_size(content,b_width)(unique) is (w,h) then    
     if x(e) < b_width | x(e) >= w-b_width
      | y(e) < b_width | y(e) >= h-b_width
     then (
            if *content_impacted
            then (
                   content_impacted <- false; 
                   main_event_handler(content)(etb,mouse_gone)
                 )
            else not_handled([])
          )
     else (
            content_impacted <- true; 
            main_event_handler(content)(etb,e)
          ), 
   
   /* monitoring */ 
   [ ]
   ).