/*
   _mbuttonbar001.pkg - jun '98 - by Marc Barilley

   This package provides a button bar. It provides 2 new types :
    . ObjBbar : the button bar
    . ObjBbarItem : the items in the bar
   
   By default, buttons added to the bar must be 16*16
   
   There are several flags to define the look :
    . BBAR_MENU      : draws the bar at the top of the client zone of its parent
    . BBAR_CAN_FLOAT : unused for the moment

  files needed :
    locked/lib/const.pkg
    locked/lib/_mlistlib001.pkg
*/

/* public section */
var BBAR_MENU      = 0b01;;
var BBAR_CAN_FLOAT = 0b10;;

/* private section */
struct ObjBbarItem = [
  buttonBbarItem : ObjButton,
  rflBbarItem : fun [] I
  ] mkObjBbarItem;;

struct ObjBbar = [
  winBbar : ObjWin,
  bbarItemsBbar : [ObjBbarItem r1]
  ] mkObjBbar;;


/* user callable functions */
fun _CRbuttonBar (channel, parent, x, y, cols, flags, title)=
  if (channel==nil) || (parent==nil) ||
     (flags==nil) ||
     (((x==nil) || (y==nil) || (cols==nil)) && !(flags&BBAR_MENU)) || (cols < 1) ||
     (flags==nil) || 
     (title==nil)
  then
    nil
  else
    let
      if flags&BBAR_MENU
      then
        let _GETwindowSizePosition parent -> [px py pw ph] in
          [0 0 pw]
      else
        [x y 16*cols]
    -> [wx wy ww] in
    let _CRwindow channel parent wx wy ww 16 WN_CHILD|WN_NOBORDER title -> win in
    {
      mkObjBbar [win nil]
    };;