/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   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 can find this license in the file 'gpl.txt'.
 *
 *   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
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 *********************************************************************/

#include "constants.h"

#ifdef USE_UI_GTK

#include "pixmap.h"

#include "../../misc/setting.h"

namespace GTK_DOKO {
#include <gtk/gtkpixmap.h>

  /*****************************************************************************
   *
   * vector<Pixmap>& Pixmap::load_and_rotate(vector<Pixmap>& pixmap,
   *					   string const& filename)
   *
   * Parameters:	pixmap	 - vector, in which the pixmaps are to be written
   *		filename - name of the file with the graphic
   *
   * Result:	the vector with the pixmaps
   * 
   * Version:	0.3.6
   *
   * Description:	loads the pixmap from the file and rotates it
   *
   ****************************************************************************/
  vector<Pixmap>&
    Pixmap::load_and_rotate(vector<Pixmap>& pixmap,
			    string const& filename)
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::load_and_rotate()");

      DEBUG_ASSERTION((pixmap.size() >= ROTATION_NUMBER),
		      "Pixmap::load_and_rotate()\n"
		      "  vector 'pixmap' has not enough elements\n");

      static Pixmap pixmap_new;

      // test, if the .0.xpm-file exists, otherwise take the .xpm-file
      if (!(pixmap_new = Pixmap(filename + ".0."
				+ setting(Setting::GRAPHIC_EXTENSION), false)))
	pixmap_new = Pixmap(filename + "." + setting(Setting::GRAPHIC_EXTENSION), false);

      if (!pixmap_new)
	DEBUG_RETURNING(pixmap,
			INFO_GTK_PIXMAP && INFO_GTK_INIT,
			"Pixmap::load_and_rotate()");

      // rotate the pixmap
      // test, whether the pixmap could be loaded
      pixmap[0] = pixmap_new;
      pixmap[1] = pixmap_new.rotated(RIGHT);
      pixmap[2] = pixmap_new.rotated(DOWN);
      pixmap[3] = pixmap_new.rotated(LEFT);

      DEBUG_RETURNING(pixmap,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::load_and_rotate()");
    } // Pixmap::load_and_rotate(pixmap, file)

  /*****************************************************************************
   *
   * Pixmap::Pixmap()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	constructs the pixmap
   *
   ****************************************************************************/
  Pixmap::Pixmap() :
    pixmap_p(NULL),
  mask_p(NULL),
  width_p(0),
  height_p(0)
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		  "Pixmap::Pixmap()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::Pixmap()");
  } // Pixmap::Pixmap()


  /*****************************************************************************
   *
   * Pixmap::Pixmap(string const& filename, bool const errorout)
   *
   * Parameters:	filename - the file, the pixmap is loaded from
   *		errorout - whether error should be written to stderr
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	constructs a pixmap out of the file data
   *
   ****************************************************************************/
  Pixmap::Pixmap(string const& filename, bool const errorout) :
    pixmap_p(NULL),
  mask_p(NULL),
  width_p(0),
  height_p(0)
    // load the pixmap from the file
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		  "Pixmap::Pixmap(filename, errorout)");

    // load the pixmap (and the mask)
    pixmap_p = 
      gdk_pixmap_colormap_create_from_xpm(NULL, gdk_colormap_get_system(),
					  &mask_p, NULL,
					  filename.c_str());
    if ((pixmap_p == NULL) && errorout) {
      DEBUG_RETURNING(VOID,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::Pixmap(filename, errorout)");

    }

    // get the size of the pixmap
    size_set();

    DEBUG_RETURNING(VOID,
		    INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::Pixmap(filename, errorout)");
  } // Pixmap::Pixmap(filename)


  /*****************************************************************************
   *
   * Pixmap::Pixmap(Pixmap const& pixmap)
   *
   * Parameters:	pixmap - the pixmap to be copied
   *
   * Result:	none
   * 
   * Version:	0.4.3
   *
   * Description:	constructs a copy of the given pixmap
   *
   ****************************************************************************/
  Pixmap::Pixmap(Pixmap const& pixmap) :
    pixmap_p(NULL),
  mask_p(NULL),
  width_p(0),
  height_p(0)
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		  "Pixmap::Pixmap(pixmap)");

    if (pixmap_p != NULL)
      gdk_pixmap_unref(pixmap_p);
    if (mask_p != NULL)
      gdk_bitmap_unref(mask_p);

    if (!pixmap) {
      pixmap_p = mask_p = NULL;
    } else {

      this->pixmap_p = gdk_pixmap_new(NULL,
				      pixmap.width(), pixmap.height(),
				      gdk_visual_get_best_depth());
      this->mask_p = gdk_bitmap_create_from_data(NULL, "",
						 pixmap.width(),
						 pixmap.height());

      GdkGC* gc;
      gc = gdk_gc_new(pixmap.pixmap());

      gdk_window_copy_area(this->pixmap_p,
			   gc,
			   0, 0,
			   pixmap.pixmap(),
			   0, 0, pixmap.width(), pixmap.height());
      gdk_gc_unref(gc);

      gc = gdk_gc_new(pixmap.mask());
      gdk_window_copy_area(this->mask_p,
			   gc,
			   0, 0,
			   pixmap.mask(),
			   0, 0, pixmap.width(), pixmap.height());
      gdk_gc_unref(gc);
      //    pixmap_p = gdk_pixmap_ref(pixmap.pixmap());
      //    mask_p = gdk_bitmap_ref(pixmap.mask());
    }

    size_set();

    DEBUG_RETURNING(VOID,
		    INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::Pixmap(pixmap)");
  } // Pixmap::Pixmap(Pixmap)

  /*****************************************************************************
   *
   * Pixmap::Pixmap(GdkPixmap* pixmap_a, GdkBitmap* mask_a)
   *
   * Parameters:	pixmap_a - the pixmap to be copied
   *		mask_a   - the mask
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	constructs a copy of the given pixmap
   *
   ****************************************************************************/
  Pixmap::Pixmap(GdkPixmap* pixmap_a, GdkBitmap* mask_a) :
    pixmap_p(NULL),
  mask_p(NULL),
  width_p(0),
  height_p(0)
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		  "Pixmap::Pixmap(pixmap, mask)");

    if (!pixmap_a) {
      pixmap_p = mask_p = NULL;
    } else {
      pixmap_p = gdk_pixmap_ref(pixmap_a);
      mask_p = gdk_bitmap_ref(mask_a);
    }

    this->size_set();

    DEBUG_RETURNING(VOID,
		    INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::Pixmap(pixmap, mask)");
  } // Pixmap::Pixmap(Pixmap, mask)

  /*****************************************************************************
   *
   * Pixmap& Pixmap::operator=(Pixmap const& pixmap_a)
   *
   * Parameters:	pixmap_a - the pixmap to be copied
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	copies the given pixmap
   *
   ****************************************************************************/
  Pixmap&
    Pixmap::operator=(Pixmap const& pixmap_a)
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::operator=(pixmap)");

      if (pixmap_p != NULL)
	gdk_pixmap_unref(pixmap_p);
      if (mask_p != NULL)
	gdk_bitmap_unref(mask_p);

      if (!pixmap_a) {
	pixmap_p = mask_p = NULL;
      } else {
	pixmap_p = gdk_pixmap_ref(pixmap_a.pixmap());
	mask_p = gdk_bitmap_ref(pixmap_a.mask());
      }

      size_set();

      DEBUG_RETURNING(*this,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::operator=(pixmap)");
    } // Pixmap& Pixmap::operator=(Pixmap)

  /*****************************************************************************
   *
   * Pixmap::~Pixmap()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	Destructor (Some error with linux)
   *
   ****************************************************************************/
  Pixmap::~Pixmap()
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		  "Pixmap::~Pixmap()");

    if (pixmap_p != NULL)
      gdk_pixmap_unref(this->pixmap_p);
    if (mask_p != NULL)
      gdk_bitmap_unref(this->mask_p);

    DEBUG_RETURNING(VOID,
		    INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::~Pixmap()");
  } // Pixmap::~Pixmap()

  /*****************************************************************************
   *
   * GdkPixmap* Pixmap::pixmap() const
   *
   * Parameters:	none
   *
   * Result:	The GdkPixmap
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  GdkPixmap*
    Pixmap::pixmap() const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::pixmap()");

      DEBUG_RETURNING(pixmap_p,
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::pixmap()");
    } // GdkPixmap* pixmap()

  /*****************************************************************************
   *
   * GdkBitmap* Pixmap::mask() const
   *
   * Parameters:	none
   *
   * Result:	The mask of the pixmap
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  GdkBitmap*
    Pixmap::mask() const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::mask()");

      DEBUG_RETURNING(mask_p,
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::mask()");
    } // GdkBitmap* Pixmap::mask()

  /*****************************************************************************
   *
   * unsigned Pixmap::width() const
   *
   * Parameters:	none
   *
   * Result:	the width of the pixmap
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  unsigned
    Pixmap::width() const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::width()");

      DEBUG_RETURNING(width_p,
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::width()");
    } // unsigned Pixmap::width()

  /*****************************************************************************
   *
   * unsigned Pixmap::height() const
   *
   * Parameters:	none
   *
   * Result:	the height of the pixmap
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  unsigned
    Pixmap::height() const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::height()");

      DEBUG_RETURNING(height_p,
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::height()");
    } // unsigned Pixmap::height()

  /*****************************************************************************
   *
   * bool Pixmap::is_transparent(unsigned const x, unsigned const y) const
   *
   * Parameters:	x - x-position
   *		y - y-position
   *
   * Result:	whether the pixel (x, y) is transparent
   * 
   * Version:	0.3.7
   *
   * Description:	-> result
   *
   ****************************************************************************/
  bool
    Pixmap::is_transparent(unsigned const x, unsigned const y) const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::is_transparent()");

      GdkImage* pixel = gdk_image_get(mask(), x, y,
				      1, 1);

      DEBUG_RETURNING((gdk_image_get_pixel(pixel, 0, 0) == 0),
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::is_transparent()");
    } // bool Pixmap::is_transparent(unsigned const x, unsigned const y) const

  /*****************************************************************************
   *
   * GtkWidget* Pixmap::widget() const
   *
   * Parameters:	none
   *
   * Result:	The gtk-widget of the pixmap
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  GtkWidget*
    Pixmap::widget() const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::widget()");

      GtkWidget* widget = gtk_pixmap_new(pixmap(), mask());

      gtk_widget_show(widget);

      DEBUG_RETURNING(widget,
		      INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		      "Pixmap::widget()");
    } // GtkWidget* Pixmap::widget()

  /*****************************************************************************
   *
   * Pixmap::operator bool() const
   *
   * Parameters:	none
   *
   * Result:	whether the pixmap does contain data
   * 
   * Version:	0.3.6
   *
   * Description:	-> result
   *
   ****************************************************************************/
  Pixmap::operator bool() const
  {
    DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		  "Pixmap::operator bool()");

    DEBUG_RETURNING((pixmap() != NULL),
		    INFO_GTK_PIXMAP && INFO_GTK_VALUE,
		    "Pixmap::operator bool()");
  } // Pixmap::operator bool()

  /*****************************************************************************
   *
   * Pixmap& Pixmap::rotate(Rotation const rotation = RIGHT)
   *
   * Parameters:	rotation - how to rotate
   *
   * Result:	the rotated pixmap
   * 
   * Version:	0.3.6
   *
   * Description:	rotates the Pixmap (90 degrees clockwise)
   *
   ****************************************************************************/
  Pixmap&
    Pixmap::rotate(Rotation const rotation)
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::rotate()");

      if (pixmap_p != NULL) {
	pixmap_rotate(rotation);
	mask_rotate(rotation);

	size_set();
      }

      DEBUG_RETURNING(*this,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::rotate()");
    } // Pixmap& Pixmap::rotate(Rotation const rotation = RIGHT)

  /*****************************************************************************
   *
   * Pixmap Pixmap::rotated(Rotation const rotation = RIGHT) const
   *
   * Parameters:	rotation - how to rotate
   *
   * Result:	the pixmap rotated
   * 
   * Version:	0.3.6
   *
   * Description:	creates and returns a new Pixmap that is the original rotated
   *		(90 degrees clockwise)
   *
   ****************************************************************************/
  Pixmap
    Pixmap::rotated(Rotation const rotation) const
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::rotated()");

      DEBUG_RETURNING(Pixmap(*this).rotate(rotation),
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::rotated()");
    } // Pixmap Pixmap::rotated(Rotation const rotation = RIGHT)

  /*****************************************************************************
   *
   * void Pixmap::rotated(GdkDrawable* drawable, int const x, int const y)
   *
   * Parameters:	drawable - in which drawable to draw the pixmap
   *		x - x-position to draw the pixmap
   *		y - y-position to draw the pixmap
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	draws the pixmap in the drawable on the given position
   *
   ****************************************************************************/
  void
    Pixmap::draw(GdkDrawable* drawable, int const x, int const y)
    // draw the pixmap at the given position
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_DRAW,
		    "Pixmap::draw(drawable, x, y)");

      // use a separate gc
      GdkGC* gc = gdk_gc_new(drawable);

      gdk_gc_set_clip_mask(gc, mask());
      gdk_gc_set_clip_origin(gc, x, y);

      gdk_draw_pixmap(drawable, gc, pixmap(),
		      0, 0,
		      x, y,
		      -1, -1);

      gdk_gc_unref(gc);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_PIXMAP && INFO_GTK_DRAW,
		      "Pixmap::draw(drawable, x, y)");
    } // void Pixmap::draw(drawable, x, y)



  /*****************************************************************************
   *
   * void Pixmap::pixmap_rotate(Rotation const rotation = RIGHT)
   *
   * Parameters:	rotation - how to rotate
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	rotates the pixmap (90 degrees clockwise)
   *
   ****************************************************************************/
  void
    Pixmap::pixmap_rotate(Rotation const rotation)
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::pixmap_rotate()");

      GdkGC* gc = gdk_gc_new(pixmap());

      unsigned const width_new = (((rotation == UP)
				   || (rotation == DOWN))
				  ? this->width()
				  : this->height());
      unsigned const height_new = (((rotation == UP)
				    || (rotation == DOWN))
				   ? this->height()
				   : this->width());

      // create the pixmap with the new size
      GdkPixmap* pixmap_rotate = gdk_pixmap_new(NULL,
						width_new, height_new,
						gdk_visual_get_best_depth());
      // use images for changing the pixels, because it is much faster
      GdkImage* image = gdk_image_get(pixmap(), 0, 0,
				      width(), height());

      GdkImage* image_rotate = gdk_image_new(GDK_IMAGE_FASTEST,
					     gdk_visual_get_system(),
					     width_new, height_new);
      // copy the pixels
      for (unsigned y = 0; y < this->height(); y++) {
	unsigned y2 = 0;
	unsigned x2 = 0;
	for (unsigned x = 0; x < this->width(); x++) {
	  switch(rotation) {
	  case UP:
	    x2 = x;
	    y2 = y;
	    break;
	  case RIGHT:
	    x2 = this->height() - 1 - y;
	    y2 = x;
	    break;
	  case DOWN:
	    x2 = this->width() - 1 - x;
	    y2 = this->height() - 1 - y;
	    break;
	  case LEFT:
	    x2 = y;
	    y2 = this->width() - 1 - x;
	    break;
	  } // switch(rotation)
	  gdk_image_put_pixel(image_rotate, x2, y2,
			      gdk_image_get_pixel(image, x, y));
	} // for (x)
      } // for (y)


      gdk_pixmap_unref(pixmap_p);
      pixmap_p = pixmap_rotate;

      // copy the image into the pixmap
      gdk_draw_image(pixmap_p, gc, image_rotate, 0, 0, 0, 0,
		     width_new, height_new);

      // destroy the images
      gdk_image_destroy(image);
      gdk_image_destroy(image_rotate);

      gdk_gc_unref(gc);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::pixmap_rotate()");
    } // void Pixmap::pixmap_rotate(Rotation const rotation = RIGHT)

  /*****************************************************************************
   *
   * void Pixmap::mask_rotate(Rotation const rotation = RIGHT)
   *
   * Parameters:	rotation - how to rotate
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	rotates the mask (90 degrees clockwise)
   *
   ****************************************************************************/
  void
    Pixmap::mask_rotate(Rotation const rotation)
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::mask_rotate()");

      unsigned const width_new = (((rotation == UP)
				   || (rotation == DOWN))
				  ? this->width()
				  : this->height());
      unsigned const height_new = (((rotation == UP)
				    || (rotation == DOWN))
				   ? this->height()
				   : this->width());

      // create the bitmap
      GdkBitmap* mask_rotate = gdk_bitmap_create_from_data(NULL, "",
							   width_new, height_new);
      GdkGC* gc = gdk_gc_new(mask_rotate);

      GdkImage* image = gdk_image_get(mask(), 0, 0,
				      width(), height());
#if !defined(WINDOWS) || defined(GTK_2_0)
      GdkImage* image_rotate = gdk_image_get(mask_rotate, 0, 0,
					     width_new, height_new);
#else
      GdkImage* image_rotate
	= gdk_image_new_bitmap(gdk_visual_get_best_with_depth(1),
			       gpointer(""),
			       width_new, height_new);
#endif

      // copy the pixels
      for (unsigned y = 0; y < height(); y++) {
	unsigned x2 = 0;
	unsigned y2 = 0;
	for (unsigned x = 0; x < width(); x++) {
	  switch(rotation) {
	  case UP:
	    x2 = x;
	    y2 = y;
	    break;
	  case RIGHT:
	    x2 = this->height() - 1 - y;
	    y2 = x;
	    break;
	  case DOWN:
	    x2 = this->width() - 1 - x;
	    y2 = this->height() - 1 - y;
	    break;
	  case LEFT:
	    x2 = y;
	    y2 = this->width() - 1 - x;
	    break;
	  } // switch(rotation)

	  gdk_image_put_pixel(image_rotate, x2, y2,
#ifndef WINDOWS
			      gdk_image_get_pixel(image, x, y)
#else
			      // *** DK
			      // don't ask me, why I have to change the color
			      ((gdk_image_get_pixel(image, x, y) == 0)
			       ? 1
			       : 0)
#endif
			     );
	} // for (x)
      } // for (y)

      // create the pixmap with the new size
      gdk_bitmap_unref(mask_p);

      mask_p = mask_rotate;

      // copy the image into the pixmap
      gdk_draw_image(mask_p, gc, image_rotate, 0, 0, 0, 0,
		     width_new, height_new);

      // destroy the images
      gdk_image_destroy(image);
      gdk_image_destroy(image_rotate);

      gdk_gc_unref(gc);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::mask_rotate()");
    } // void Pixmap::mask_rotate(Rotation const rotation = RIGHT)

  /*****************************************************************************
   *
   * void Pixmap::size_set()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	reads the size of the pixmap and sets the size of the Pixmap
   *
   ****************************************************************************/
  void
    Pixmap::size_set()
    // get the size of the pixmap and set the values
    {
      DEBUG_CALLING(INFO_GTK_PIXMAP && INFO_GTK_INIT,
		    "Pixmap::size_set()");

      int width_a, height_a;

      // get the size of the pixmap
      if (pixmap_p != NULL) {
	gdk_window_get_size(pixmap(), &width_a, &height_a);
	DEBUG_ASSERTION(((width_a >= 0) && (height_a >= 0)),
			"Pixmap::size_set()\n"
			"  width/height of the pixmap is less than zero");
	width_p = width_a;
	height_p = height_a;
      }
      else
	width_p = height_p = 0;

      DEBUG_RETURNING(VOID,
		      INFO_GTK_PIXMAP && INFO_GTK_INIT,
		      "Pixmap::size_set()");
    } // void Pixmap::size_set()

} // namespace GTK_DOKO

#endif // #ifdef USE_UI_GTK
