/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>

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

You should have received a copy of the GNU Lesser 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, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/


#include "../include/scol_gtk_easy.h"



int SCOL_gtkEasyTextGetList (mmachine m)
{
    int mlist;
    int i = 0;
    const char *t;
    gchar *s;
    GtkWidget *widget = NULL;

    g_message ("SCOL_gtkEasyTextGetList : entering");

    mlist = MMpull (m);
    if (mlist == NIL)
    {
        g_warning ("SCOL_gtkEasyTextGetList error : list is nil");
        MMpush (m, NIL);
        return 0;
    }

    while (mlist != NIL)
    {
        widget = (GtkWidget*) MMfetch (m, MTOP (MMfetch (m, MTOP (mlist), 0)), OBJ2DGTK_WIDGET_HANDLE);
        t = G_OBJECT_TYPE_NAME (G_OBJECT (widget));
        if (!strcmp (t, "GtkEntry"))
        {
            scol_gtk_entry_get (widget, &s);
            Mpushstrbloc (m, s);
            g_free (s);
        }
        else if (!strcmp (t, "GtkLabel"))
        {
            scol_gtk_label_get (widget, &s);
            Mpushstrbloc (m, s);
            g_free (s);
        }
        else if (!strcmp (t, "GtkTextView"))
        {
            /* TODO */
        }
        i++;
        mlist = MMfetch (m, MTOP (mlist), 1);
    }
    MMpush (m, NIL);
    for (; i > 0; i--)
    {
        MMpush (m, 2*2);
        MBdeftab (m);
    }
    return 0;
}



/* API definitions : */

char* gtk_easy_name[GTK_EASY_PKG_NB]=
{
    "_gtkEasyTextGetList"
};

int (*gtk_easy_fun[GTK_EASY_PKG_NB])(mmachine m)=
{
    SCOL_gtkEasyTextGetList
};

int gtk_easy_narg[GTK_EASY_PKG_NB]=
{
    1           /* SCOL_gtkEasyTextGetList */
};

char* gtk_easy_type[GTK_EASY_PKG_NB]=
{
    "fun [[ObjGtkWidget r1]] [S r1]"                /* SCOL_gtkEasyTextGetList */
};

int SCOLloadGTKeasy (mmachine m)
{
    int k;

    MMechostr (0, "SCOLloadGTKeasy : entering\n");

    k = PKhardpak (m, "GTK2DeasyEngine", GTK_EASY_PKG_NB, gtk_easy_name, gtk_easy_fun, gtk_easy_narg, gtk_easy_type);
    return k;
}




