/*
 *  Copyright (C) 2010 Collabora Ltd.
 *
 *  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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "webkitipopupmenu.h"

/**
 * SECTION:webkitipopupmenu
 * @short_description: Fill the description here.
 *
 * Descriptions are needed.
 */

enum
{
    ITEM_ACTIVATED,
    HIDDEN,

    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = {0, };

/* Default implementations. */
void webkit_ipopup_menu_base_show(WebKitIPopupMenu* popup, guint x, guint y)
{
    return;
}

void webkit_ipopup_menu_base_add_item(WebKitIPopupMenu* popup,
                                gint index,
                                WebKitIPopupMenuItemData* item)
{
    return;
}

void webkit_ipopup_menu_base_hide(WebKitIPopupMenu*)
{
    return;
}

/* Initialization */
static void webkit_ipopup_menu_base_init(WebKitIPopupMenuInterface* iface)
{
    static gboolean initialised = FALSE;

    if (!initialised) {
        initialised = TRUE;
        GType iface_type = G_TYPE_FROM_INTERFACE(iface);

        signals[ITEM_ACTIVATED] = g_signal_new("item-activated",
                iface_type,
                (GSignalFlags)G_SIGNAL_RUN_LAST,
                0,
                NULL,
                NULL,
                g_cclosure_marshal_VOID__INT,
                G_TYPE_NONE, 1,
                G_TYPE_INT);

        signals[ITEM_ACTIVATED] = g_signal_new("hidden",
                iface_type,
                (GSignalFlags)G_SIGNAL_RUN_LAST,
                0,
                NULL,
                NULL,
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0);

        iface->show = webkit_ipopup_menu_base_show;
        iface->add_item = webkit_ipopup_menu_base_add_item;
        iface->hide = webkit_ipopup_menu_base_hide;
    }
}

GType webkit_ipopup_menu_get_type()
{
    static GType type = 0;

    if (G_UNLIKELY (!type))
      {
        const GTypeInfo typeInfo =
        {
          sizeof (WebKitIPopupMenuInterface),
          (GBaseInitFunc)webkit_ipopup_menu_base_init,
          NULL, NULL, NULL, NULL, 0, 0, NULL, NULL
        };

        type = g_type_register_static (G_TYPE_INTERFACE,
                                       "WebKitIPopupMenu",
                                       &typeInfo, (GTypeFlags)0);

        g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
      }

    return type;
}

/* Generic functions. */
void webkit_ipopup_menu_show(WebKitIPopupMenu* popup, guint x, guint y)
{
    WEBKIT_IPOPUP_MENU_GET_INTERFACE(popup)->show(popup, x, y);
}

void webkit_ipopup_menu_add_item(WebKitIPopupMenu* popup,
                                gint index,
                                WebKitIPopupMenuItemData* item)
{
    WEBKIT_IPOPUP_MENU_GET_INTERFACE(popup)->add_item(popup, index, item);
}

void webkit_ipopup_menu_hide(WebKitIPopupMenu* popup)
{
    WEBKIT_IPOPUP_MENU_GET_INTERFACE(popup)->hide(popup);
}
