// Swarm library. Copyright © 1996-2000 Swarm Development Group.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// 
// The Swarm Development Group can be reached via our website at:
// http://www.swarm.org/

#import <tkobjc/Canvas.h>
#import <tkobjc/global.h>

@implementation Canvas

PHASE(Creating)

- createEnd
{
  [super createEnd];
  [globalTkInterp eval: "canvas %s", widgetName];
  [self updateSize];
  return self;
}

PHASE(Using)

- addWidget: widget X: (int)x Y: (int)y centerFlag: (BOOL)centerFlag
{
  [globalTkInterp eval: "%s create window %d %d -anchor %s -window %s",
                  [self getWidgetName],
                  x, y,
                  (centerFlag ? "w" : "nw"),
                  [widget getWidgetName]];
  return self;
}

- removeWidget: widget
{
  [globalTkInterp eval: "%s delete %s", 
                  [self getWidgetName],
                  [widget getWidgetName]];
  return self;
}

- checkGeometry: frame
{
  const char *canvasName = [self getWidgetName];
  const char *frameName = [frame getWidgetName];
  
  [globalTkInterp eval:
                    "tkwait visibility %s ;"
                  "set width [winfo width %s] ;"
                  "set height [winfo height %s] ;"
                  "%s configure -scrollregion [list 0 0 $width $height] ;"
                  "if {$height > 500} {set height 500} ;"
                  "if {$width > 809} {set width 809} ;"
                  "%s configure -width $width -height $height",
                  frameName, frameName, frameName,
                  canvasName, canvasName];
  return self;
}
@end
