/* $Id: ANSITerminalPane,v 1.21 2009/02/28 21:53:33 kiesling Exp $ -*-C-*-*/

/*
  This file is part of Ctalk.
  Copyright  2005-2009  Robert Kiesling, ctalk@ctalklang.org.
  Permission is granted to copy this software provided that this copyright
  notice is included in all source code modules.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

Pane class ANSITerminalPane;
ANSITerminalPane instanceVariable paneStream ANSITerminalStream NULL;
ANSITerminalPane instanceVariable shadow Integer 0;
ANSITerminalPane instanceVariable border Integer 0;
ANSITerminalPane instanceVariable parentOrigin Point 0;
ANSITerminalPane instanceVariable parentClip Point 0;
ANSITerminalPane instanceVariable graphicsBits Integer 0;

ANSITerminalPane instanceMethod new (char *__paneName) {
  OBJECT *old_stream_var_alias, *new_stream_var_alias,
    *new_stream_var_copy;
  ANSITerminalPane super new __paneName;
  /*
   *  Initialize an ANSITerminalStream object.
   */
  ANSITerminalStream new __newStream;
  __ctalkInstanceVarsFromClassObject (__paneName);
  __paneName paneStream become __newStream;
  methodReturnObject (__paneName);
}

ANSITerminalPane instanceMethod childRefresh (void) {
  if (self mapped)
    __ctalkANSITerminalPaneRefresh ();
  methodReturnNULL;
}


ANSITerminalPane instanceMethod refresh (void) {
  Exception new e;
  __ctalkANSITerminalPaneRefresh ();
  if (!self children isEmpty)
    self children map childRefresh;
  if (e pending)
    e handle;
  methodReturnNULL;
}

ANSITerminalPane instanceMethod putCharXY (int x, int y, char c) {
  __ctalkANSITerminalPanePutChar (x, y, c);
  methodReturnNULL;
}

ANSITerminalPane instanceMethod printOn (char *__fmt, ...) {
  String new buf;
  Integer new i;
  Integer new l;
  __ctalkObjectPrintOn (buf);
  l = buf length;
  for (i = 0; i < l; i = i + 1) {
    self putChar buf at i;
  }
  methodReturnSelf;
}

ANSITerminalPane instanceMethod putChar (char c) {
  __ctalkANSITerminalPanePutChar (self cursor x, self cursor y, c);
  self cursor x = self cursor x + 1;
  methodReturnNULL;
}

ANSITerminalPane instanceMethod cursorPos (int __x, int __y) {
  /***/
  self cursor x = __x;
  self cursor y = __y;
  methodReturnNULL;
}

ANSITerminalPane instanceMethod gotoXY (int __x, int __y) {
  /***/
  self cursor x = __x;
  self cursor y = __y;
  methodReturnNULL;
}

ANSITerminalPane instanceMethod initialize (int x_org, int y_org,
					    int x_size, int y_size) {
  OBJECT *paneBuffer_value_alias;
  paneBuffer_value_alias = self paneBuffer value;
  sprintf (paneBuffer_value_alias -> __o_value, "%#x",
	   __ctalkCreateWinBuffer (x_size, y_size, 1));
  self origin x = x_org;
  self origin y = y_org;
  self size x = x_size;
  self size y = y_size;
  self cursor x = 1;
  self cursor y = 1;
  methodReturnSelf;
}

ANSITerminalPane instanceMethod withBorder (void) {
  self border = TRUE;
  methodReturnNULL;
}
ANSITerminalPane instanceMethod withShadow (void) {
  self shadow = TRUE;
  methodReturnNULL;
}

ANSITerminalPane instanceMethod map (ANSITerminalPane __child) {

  __child mapped = 1;
  __ctalkANSITerminalPaneMapWindow (__child);
  methodReturnNULL;
}

ANSITerminalPane instanceMethod unmap (ANSITerminalPane __child) {
  __child mapped = 0;
  __ctalkANSITerminalPaneUnMapWindow (__child);
  methodReturnNULL;
}

#define BOLD    (1 << 0)
#define REVERSE (1 << 1)
#define UNDERLINE (1 << 2)
#define BLINK (1 << 3)

ANSITerminalPane instanceMethod resetGraphics (void) {
  self graphicsBits = 0;
  methodReturnSelf;
}

ANSITerminalPane instanceMethod boldOnOff (void) {
  self graphicsBits = self graphicsBits ^ BOLD;
  methodReturnSelf;
}

ANSITerminalPane instanceMethod blinkOnOff (void) {
  self graphicsBits = self graphicsBits ^ BLINK;
  methodReturnSelf;
}

ANSITerminalPane instanceMethod reverseOnOff (void) {
  self graphicsBits = self graphicsBits ^ REVERSE;
  methodReturnSelf;
}

ANSITerminalPane instanceMethod underlineOnOff (void) {
  self graphicsBits = self graphicsBits ^ UNDERLINE;
  methodReturnSelf;
}

