// -*- c++ -*-
/*  Generated by gensig from base.gen_h. DO NOT MODIFY!!! */
#ifndef GTKMM_BASE_HEADER
#define GTKMM_BASE_HEADER
/* $Id: base.gen_h,v 1.50.2.10 1999/07/29 01:53:50 kenelson Exp $ */

/* base.h
 * 
 * Copyright (C) 1998-1999 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

// GCC 2.7.2 won't compile unless these three are there in this exact order.
#include <string>
#include <list>
#include <vector>

#include <gtk--config.h>
#include <gdk--.h>
/* ifndef here makes compilation alot faster */
#ifndef GTK_MINUS_MINUS_SIG_H
#include <gtk--sig.h>
#endif
#ifdef GTKMM_CXX_HAVE_AUTO_PTR
#include <memory>
#endif

#line 37 "base.gen_h"


/* This aint pretty, but I don't know a better way to make
   sure things work when the stl classes are defined in a namespace */
#ifdef GTKMM_CXX_HAVE_NAMESPACES
namespace std{}
using namespace std;
#endif /* GTKMM_CXX_HAVE_NAMESPACES */

// Gtk-- Base and other utility classes
#define GTK_VERSION_GT(major,minor) ((GTK_MAJOR_VERSION>major)||(GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION>minor))
#define GTK_VERSION_GE(major,minor) ((GTK_MAJOR_VERSION>major)||(GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION>=minor))
#define GTK_VERSION_EQ(major,minor) ((GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION==minor))
#define GTK_VERSION_NE(major,minor) ((GTK_MAJOR_VERSION!=major)||(GTK_MINOR_VERSION!=minor))
#define GTK_VERSION_LE(major,minor) ((GTK_MAJOR_VERSION<major)||(GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION<=minor))
#define GTK_VERSION_LT(major,minor) ((GTK_MAJOR_VERSION<major)||(GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION<minor))

#define GTK_VERSION_GT_MICRO(major,minor,micro) \
  ((GTK_MAJOR_VERSION>major)|| \
  (GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION>minor)||\
  (GTK_MAJOR_VERSION==major)&&(GTK_MINOR_VERSION==minor)&&(GTK_MICRO_VERSION>minor))


/********************************************************************/
/* this class is a required stub implementation which does nothing! */
struct GtkBase { };
struct GtkBaseClass { };

struct Gtk_Base_Class 
  {
  static void class_init_function( GtkBaseClass *b) 
    {(void)b;}
  };

//: This is an empty class needed by our code generator
class Gtk_Base : public virtual Gtk_Signal_Base { };

/********************************************************************/

//: Input filter to screen out NULL inputs
// This class should not be used outside Gtk-- parameter lists.
// It is intended to be used whereever a string is passed
// as an input that may be NULL.  (Gtk-- internal)
class _gtk_string : public string {
  bool null_;
public:
  explicit _gtk_string ():
    string(),null_(false) {}

  _gtk_string(string str):
    string(str) , null_(false) {}

  // lets not use "NULL" in gtk--. 0 is much more portable in c++.
  _gtk_string(const char *s):string(),null_(false)
    {
      if (s==0) 
	null_=true;
      else
	*this=string(s);
    }

  ~_gtk_string() {};

  // this function should be used in place of c_str 
  // if NULL is a valid value. 
  const char * gc_str() const
    {
      if (null_) return (char*)0;
      return c_str();
    }

  // returns 1 if this was created from a NULL pointer
  int null()  const
    {return null_;}

};

template <class T>
struct G_List_Iterator;

/* in G_List and G_List_Iterator, we have everything inline, because
   gcc2.7.2 does not support non-inline templates (afaik) */
template <class T>
class G_List
{
public:
  typedef G_List_Iterator<T> iterator;
private:
  GList *list;

public:
  G_List() { list = 0; }
  G_List(GList *l) : list(l) {}
private:
  G_List( const G_List& x) { }
public:
  ~G_List() {g_list_free(list);}
  
  G_List* append(T* mydata)
    { list = g_list_append(list, static_cast<T*>(mydata)); return this; }
  G_List* prepend(T* mydata)
    { list = g_list_prepend(list, static_cast<T*>(mydata)); return this; }
  G_List* insert(T* mydata, gint myposition)
    { list = g_list_insert(list, static_cast<T*>(mydata), myposition); return this; }
  G_List* concat(G_List &list2)
    { list = g_list_concat(list, list2.glist()); return this; }

  G_List* remove(T* mydata)
    { list = g_list_remove(list, static_cast<T*>(mydata)); return this; }
  G_List* remove_link(G_List &mylink)
    { list = g_list_remove_link(list, mylink.glist()); return this; }

  G_List* reverse() { list = g_list_reverse(list); return this; }

  G_List* nth(guint n) { list = g_list_nth(list, n); return this; }
  T* nth_data(guint n) { return static_cast<T*>(g_list_nth_data(list, n)); }
  T* data() { return (T*)list->data; }

  G_List* find(T* mydata) { list = g_list_find(list, static_cast<T*>(mydata)); return this; }

  gint position(G_List &mylink) { return g_list_position(list, mylink.glist()); }

  // renamed from "index" since this causes a clash with macros in
  // X11/Xos.h and string.h
  gint index_of(T* mydata) { return g_list_index(list, static_cast<T*>(mydata)); }

  G_List* next() { if(list->next) list = list->next; return this; }
  G_List* prev() { if(list->prev) list = list->prev; return this; }
  
  G_List* first() { list = g_list_first(list); return this; }
  G_List* last() { list = g_list_last(list); return this; }

  guint length() { return g_list_length(list); }

  void foreach(GFunc func, T* user_data)
    { g_list_foreach(list, func, static_cast<T*>(user_data)); } // make one for methods ?

  G_List* insert_sorted(T* mydata, GCompareFunc func)
    { g_list_insert_sorted(list, static_cast<T*>(mydata), func); return this; }

  GList* glist() const { return list; }

  iterator begin() { first(); return iterator(this); }
  iterator end() { return iterator((GList*)0); }

  friend struct G_List_Iterator<T>;
};


template <class T>
struct G_List_Iterator {
  GList *node;
  typedef G_List_Iterator<T> self;

  G_List_Iterator(G_List<T> *x)  { if(x) node = x->glist(); else node = 0; }
  G_List_Iterator(GList *n)  : node(n) { }
  G_List_Iterator() {}
  G_List_Iterator(const G_List_Iterator& x)  : node(x.node) {}

  bool operator==(const self& x) const { return node == x.node; }
  bool operator!=(const self& x) const { return node != x.node; }


  self&  operator++() {
    node = ((*node).next);
    return *this;
  }
  self operator++(int) { 
    self tmp = *this;
    ++*this;
    return tmp;
  }
  self& operator--() {
    if(!node)
      node = g_list_last(node);
    else
      node = ((*node).prev);
    return *this;
  }
  self operator--(int) { 
    self tmp = *this;
    --*this;
    return tmp;
  }

  T* operator -> () {if (node) return static_cast<T*>((*node).data); return 0; }
  T* operator*() { if (node) return static_cast<T*>((*node).data); return 0; }
};

template <class T>
struct G_List_ConstIterator {
  GList *node;
  typedef G_List_ConstIterator<T> self;

  G_List_ConstIterator(G_List<T> *x)  { if(x) node = x->glist(); else node = 0; }
  G_List_ConstIterator(GList *n)  : node(n) { }
  G_List_ConstIterator() {}
  G_List_ConstIterator(const G_List_ConstIterator& x)  : node(x.node) {}

  bool operator==(const self& x) const { return node == x.node; }
  bool operator!=(const self& x) const { return node != x.node; }


  self&  operator++() {
    node = ((*node).next);
    return *this;
  }
  self operator++(int) { 
    self tmp = *this;
    ++*this;
    return tmp;
  }
  self& operator--() {
    if(!node)
      node = g_list_last(node);
    else
      node = ((*node).prev);
    return *this;
  }
  self operator--(int) { 
    self tmp = *this;
    --*this;
    return tmp;
  }

  const T* operator*() const { if (node) return static_cast<T*>((*node).data); return 0; }
};

template <class T>
struct G_SList_Iterator 
{
  GSList *node;
  typedef G_SList_Iterator<T> self;

//  G_SList_Iterator(G_SList<T> *x)  { if(x) node = x->glist(); else node = 0; }
  G_SList_Iterator(GSList *n)  : node(n) { }
  G_SList_Iterator() {}
  G_SList_Iterator(const G_SList_Iterator& x)  : node(x.node) {}

  bool operator==(const self& x) const { return node == x.node; }
  bool operator!=(const self& x) const { return node != x.node; }


  self&  operator++() {
    node = ((*node).next);
    return *this;
  }
  self operator++(int) { 
    self tmp = *this;
    ++*this;
    return tmp;
  }
#ifdef JUNK
	// no operator-- for G_SList_Iterator	
  self& operator--() {
    if(!node)
      node = g_list_last(node);
    else
      node = ((*node).prev);
    return *this;
  }
  self operator--(int) { 
    self tmp = *this;
    --*this;
    return tmp;
  }
#endif

  T* operator*() { if (node) return static_cast<T*>((*node).data); return 0; }
};

// this iterator variation returns Gtk_Widget*'s and *skips* those
// widgets that has no c++ wrapper existing!
template<class impl, class interf>
struct G_List_Cpp_Iterator {
  typedef G_List_Cpp_Iterator<impl,interf> self;
private:
  /*  since we dont have ownership of the node, default operator=() will
      do fine */
  GList *node;
public:

  bool operator==(const self& x) const { return node == x.node; }
  bool operator!=(const self& x) const { return node != x.node; }

  G_List_Cpp_Iterator(G_List<impl> *x)  { if(x) node = x->glist(); else node = 0; }
  G_List_Cpp_Iterator(GList *n) : node(n) { }
  G_List_Cpp_Iterator() {}
  G_List_Cpp_Iterator(const G_List_Cpp_Iterator<impl,interf>& x) 
	: node(x.node) {}

  interf *operator*() const { 
    if (node && node->data) 
      return static_cast<interf*>(gtk_object_get_data(GTK_OBJECT((*node).data),"cpp")); 
    return 0;
  }
  self&  operator++() {
    /* node will be 0 at the end, also we'll skip objects that has no C++
       wrapper */
    node = node->next;
    while(node && !gtk_object_get_data(GTK_OBJECT(node->data),"cpp")) 
	node = node->next;
    return *this;
  }
  self operator++(int) { 
    self tmp = *this;
    ++*this;
    return tmp;
  }
  self& operator--() {
    /* if we were at end(), we'll get last item - otherwise
       go to previous item */
    if (!node) node=g_list_last(node); else node = node->prev;

    /* the loop will go until we have an object which have a c++ wrapper,
       usually will not go inside the while loop...  */
    while(node && !gtk_object_get_data(GTK_OBJECT(node->data),"cpp")) {
        node = node->prev;
    }
    return *this;
  }
  self operator--(int) { 
    self tmp = *this;
    --*this;
    return tmp;
  }
};


/* the next one is private - its not inside Gtk_ObjectHandle to make it
   work on more compilers. */
template<class T> struct Gtk_ObjectHandle_ref {
  T *ptr;
  Gtk_ObjectHandle_ref(T *p) : ptr(p) { }
};



//: Convenience class to ease management of "cached" data-members,
//e.g. Gtk-- objects which reflect a gtk object. Kinda like auto_ptr,
//in that it lets you set whether the handled object is "owned" (in
//which case it will be deleted along with the object) or not (it's
//left alone).
//
// See Gtk_Widget::[gs]et_parent() for an example among others. The
// issue is rather complex because there are a lot of different
// cases.
//
// The overall principle of those "cached" data members is to wrap "on
// the fly" the gtk object resulting from a gtk_get_whatever() call
// and store it in the data-member. On the next call, the content of
// the cache is compared with the result of the actual gtk+ query. If
// it is still valid, the cache is returned, otherwise it is deleted
// and recreated.
//
// Things get more complicated when there is also a corresponding
// gtk_set_whatever() call. In this case, we obviously want to replace
// the content of the cache by the argument passed to set(). But in
// this case, the argument does not belong to us therefore, we must
// not destroy it.
// 

template <class OBJECT>
class Gtk_ObjectHandle
{
public:
  // ctor's dtors
  explicit Gtk_ObjectHandle( OBJECT* obj=0, bool owned = true)
    : object_(obj), owned_(owned) {}
#ifdef GTKMM_CXX_HAVE_AUTO_PTR
  Gtk_ObjectHandle(auto_ptr<OBJECT> &obj)
    : object_(obj.release()), owned_(true) {}
#endif
  Gtk_ObjectHandle(Gtk_ObjectHandle_ref<OBJECT> ref)
  : object_(ref.ptr) { }
  ~Gtk_ObjectHandle() { if(owned_) delete object_; }
  // accessors 
  const OBJECT*     get_object() const { return object_; }
  OBJECT &          operator*() const { return *object_; }
  OBJECT *          operator->() const { return object_; }
  bool              owner() const { return owned_;}
  // manipulators
#ifdef GTKMM_CXX_HAVE_MEMBER_TEMPLATES
  template <class _Tp1> operator Gtk_ObjectHandle_ref<_Tp1>()
    { return Gtk_ObjectHandle_ref<OBJECT>(this->release()); }
#ifdef GTKMM_CXX_HAVE_AUTO_PTR
  template <class _Tp1> operator auto_ptr<_Tp1>()
    { return auto_ptr<_Tp1>(this->release()); }
#endif
  template <class _Tp1> operator Gtk_ObjectHandle<_Tp1>()
    { return Gtk_ObjectHandle<_Tp1>(this->release()); }
#endif
  Gtk_ObjectHandle(const Gtk_ObjectHandle &a)
   : object_(a.release()), owned_(true) {}
  /* a must have ownership to call this, and this object gets
     the ownership */
  Gtk_ObjectHandle& operator=(const Gtk_ObjectHandle &a) {
    if (&a != this) {
      if ((a.object_ != object_) && owned_) {
	delete object_;	
      }
      object_=a.release();
      owned_ = true;
    } 
    return *this;
  }
  // get() is standard from auto_ptr, we should have one too...
  OBJECT *      get() /* const */ { return object_; }
  OBJECT *      get_object() { return object_;}
  OBJECT *      release() const { g_return_val_if_fail(owned_,0); 
		      owned_=false; return object_; 
                     }
  void          set_owned(bool owned) { owned_ = owned; };
  void          set_object( OBJECT *obj, bool own = true ) {
    // no suicides here
    if(owned_ && (obj != object_)) delete object_;
    object_ = const_cast<OBJECT *>(obj);	
    owned_ = own;
  }
  // data
private:
  OBJECT *object_;
  mutable bool owned_;
};

/* this is helper function for objecthandles to handle situation when
gtk+'s object might not be available in constructor, see
Gtk_ColorSelectionDialog::get_ok_button() about how to use it */

template<class T, class K>
T* Gtkmm_ObjectHandle_create_object(Gtk_ObjectHandle<T> &oh, K* gtkobj)
{
  if (!oh.get_object() && gtkobj)
    {
      oh.set_object(new T(gtkobj));
      oh.set_owned(true);
    }
  return oh.get_object();
}

//: This function is used to let the user give up ownership of a widget
//: to a container widget. That is, the container will delete the
//: object when it is itself destroyed.
//: The object must obviously be a pointer.
//: For instance :
//:
//: Gtk_Button *my_button = new Gtk_Button("my button");
//: Gtk_Box box;
//:
//: box.add(manage(my_button));
//:
template <class T> Gtk_ObjectHandle<T> manage(T *obj);


/**********************************************************************/
//: functions for glists which abuse the data pointer for integers
//    (not uncommon)

struct G_IntList;
struct G_IntList_Iterator {
  GList *node;
  typedef G_IntList_Iterator self;

  G_IntList_Iterator(G_IntList *x);
  G_IntList_Iterator(GList *n)  : node(n) { }
  G_IntList_Iterator() {}
  G_IntList_Iterator(const G_IntList_Iterator& x)  : node(x.node) {}

  bool operator==(const self& x) const { return node == x.node; }
  bool operator!=(const self& x) const { return node != x.node; }


  self&  operator++() {
    node = ((*node).next);
    return *this;
  }
  self operator++(int) {
    self tmp = *this;
    ++*this;
    return tmp;
  }
  self& operator--() {
    if(!node)
      node = g_list_last(node);
    else
      node = ((*node).prev);
    return *this;
  }
  self operator--(int) {
    self tmp = *this;
    --*this;
    return tmp;
  }

  gint operator*() const { if (node) return GPOINTER_TO_INT((*node).data); return 0; }
};

/* inlines do not harm here */
class G_IntList
{
  typedef G_IntList_Iterator iterator;
  GList *list;

public:
  G_IntList() { list = 0; }
  G_IntList(GList *l) : list(l) {}
private:
  G_IntList( const G_IntList&) { }
public:
  ~G_IntList() {g_list_free(list);}

  G_IntList* append(gint mydata)
    { list = g_list_append(list, GINT_TO_POINTER(mydata)); return this; }
  G_IntList* prepend(gint mydata)
    { list = g_list_prepend(list, GINT_TO_POINTER(mydata)); return this; }
  G_IntList* insert(gint mydata, gint myposition)
    { list = g_list_insert(list, GINT_TO_POINTER(mydata), myposition); return this; }
  G_IntList* concat(G_IntList &list2)
    { list = g_list_concat(list, list2.glist()); return this; }

  G_IntList* remove(gint mydata)
    { list = g_list_remove(list, GINT_TO_POINTER(mydata)); return this; }
  G_IntList* remove_link(G_IntList &mylink)
    { list = g_list_remove_link(list, mylink.glist()); return this; }

  G_IntList* reverse() { list = g_list_reverse(list); return this; }

  G_IntList* nth(guint n) { list = g_list_nth(list, n); return this; }
  gint nth_data(guint n) { return GPOINTER_TO_INT(g_list_nth_data(list,n)); }
  gint data() { return GPOINTER_TO_INT(list->data); }

  G_IntList* find(gint mydata) { list = g_list_find(list, GINT_TO_POINTER(mydata)); return this; }

  gint position(G_IntList &mylink) { return g_list_position(list, mylink.glist()); }

  // renamed from "index" since this causes a clash with macros in
  // X11/Xos.h and string.h
  gint index_of(gint mydata) { return g_list_index(list, GINT_TO_POINTER(mydata)); }

  G_IntList* next() { if(list->next) list = list->next; return this; }
  G_IntList* prev() { if(list->prev) list = list->prev; return this; }

  G_IntList* first() { list = g_list_first(list); return this; }
  G_IntList* last() { list = g_list_last(list); return this; }

  guint length() { return g_list_length(list); }

  void foreach(GFunc func, gpointer user_data)
    { g_list_foreach(list, func, user_data); } // make one for methods ?

  G_IntList* insert_sorted(gint mydata, GCompareFunc func)
    { g_list_insert_sorted(list, GINT_TO_POINTER(mydata), func); return this; }

  GList* glist() const { return list; }

  iterator begin() { first(); return iterator(this); }
  iterator end() { return iterator((GList*)0); }

  friend struct G_IntList_Iterator;
};

vector<string> _gtk_char_ptr_array_to_vector_string(char **strings,
						    unsigned int nbstrings);

// strings is NULL-terminated
vector<string> _gtk_char_ptr_array_to_string_vector(char **strings);

//: THIS FUNCTION RETURNS AN ALLOCATED OBJECT
const char** _gtk_string_vector_to_char_ptr_array(const vector<string> &stringv);

template <class T> Gtk_ObjectHandle<T> manage(T *obj)
{
  return Gtk_ObjectHandle<T>(obj);
}

#endif
