// -*- c++ -*-
/* $Id: dragcontext.ccg,v 1.7 2005/02/13 13:01:36 murrayc Exp $ */

/*
 *
 * Copyright 2002 The gtkmm Development Team
 *
 * 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.
 */

#include <gdkmm/window.h>
#include <gtk/gtkdnd.h>
#include <gdk/gdkwindow.h>
#include <glibmm/utility.h> //For ScopedPtr<>.

namespace Gdk
{

void DragContext::find_window_for_screen(const Glib::RefPtr<Window>& drag_window, const Glib::RefPtr<Screen>& screen, int x_root, int y_root, Glib::RefPtr<Window>& dest_window, DragProtocol* protocol) const
{
  GdkWindow* cWindow = 0;
  gdk_drag_find_window_for_screen(const_cast<GdkDragContext*>(gobj()), drag_window->gobj(), screen->gobj(), x_root, y_root, &cWindow, (GdkDragProtocol*)(protocol));
  dest_window = Glib::wrap((GdkWindowObject*)cWindow);
}

void DragContext::drag_refuse(guint32 time)
{
  gdk_drag_status(gobj(), ((GdkDragAction)(0)) /* see GDK docs */, time);
}

Glib::StringArrayHandle DragContext::get_targets() const
{
  std::list<Glib::ustring> listTargets;

  //Get a newly-allocated array of atoms:
  GList* list = gobj()->targets;
  while(list)
  {
    GdkAtom atom = GDK_POINTER_TO_ATOM(list->data);
    
    //Convert the atom to a string:
    gchar* const atom_name = gdk_atom_name(atom);

    Glib::ustring target;
    if(atom_name)
      target = Glib::ScopedPtr<char>(atom_name).get(); //This frees the gchar*.
      
    listTargets.push_back(target);

    list = list->next;
  }

  return listTargets;
}

} /* namespace Gdk */
