/* $Id: selectiondata.hg,v 1.9 2006/07/05 16:59:28 murrayc Exp $ */

/* Copyright(C) 2002 The gtkmm Development Team
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(gtkmm,gtk)

#include <gdkmm/display.h>


namespace Gtk
{

#ifndef DOXYGEN_SHOULD_SKIP_THIS
class TextBuffer;
#endif //DOXYGEN_SHOULD_SKIP_THIS

class SelectionData
{
  _CLASS_BOXEDTYPE(SelectionData, GtkSelectionData, NONE, gtk_selection_data_copy, gtk_selection_data_free)
  _IGNORE(gtk_selection_data_copy, gtk_selection_data_free)
public:

  //TODO : document this. It's like the other set(), but it uses this SelectionData's target type.
  //Why would you ever want to use any other type?
  void set(int format, const guint8* data, int length);
  
  /** Assign a memory block of raw data.
   * Store new data into the Gtk::SelectionData object. Should _only_ by called
   * from a selection handler callback.  A 0-byte terminates the stored data.
   * @param type The type of the selection.
   * @param format The data format, i.e. the number of bits in a unit.
   * @param data Pointer to the data (will be copied).
   * @param length The length of the data block in bytes.
   */
  void set(const std::string& type, int format, const guint8* data, int length);

  /** Assign a string of raw data.
   * Store new data into the Gtk::SelectionData object. Should _only_ by called
   * from a selection handler callback. 
   * @param type The type of the selection.
   * @param data A string that contains the data (does not have to be text).
   */
  void set(const std::string& type, const std::string& data);
  _IGNORE(gtk_selection_data_set)

  /** Assign UTF-8 encoded text.
   * Sets the contents of the selection from a UTF-8 encoded string.
   * The string is converted to the form determined by get_target().
   * @param data A UTF-8 encoded string.
   * @return <tt>true</tt> if the selection was successfully set,
   * otherwise <tt>false</tt>.
   */
  bool set_text(const Glib::ustring& data);
  _IGNORE(gtk_selection_data_set_text)

  /** Gets the contents of the selection data as a UTF-8 string.
   * @return If the selection data contained a recognized text type and
   * it could be converted to UTF-8, a string containing the converted text,
   * otherwise an empty string.
   */
  Glib::ustring get_text() const;
  _IGNORE(gtk_selection_data_get_text)

  _WRAP_METHOD(bool set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_selection_data_set_pixbuf)
  _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_pixbuf(), gtk_selection_data_get_pixbuf)
  _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_pixbuf() const, gtk_selection_data_get_pixbuf, constversion)
  
#dnl The constness of gtk_selection_data_set_uris() is not quite right:
#m4 _CONVERSION(`const Glib::StringArrayHandle&',`gchar**',`const_cast<char**>(($3).data())') 
  _WRAP_METHOD(bool set_uris(const Glib::StringArrayHandle& uris), gtk_selection_data_set_uris)
  _WRAP_METHOD(Glib::StringArrayHandle get_uris() const, gtk_selection_data_get_uris)


  _WRAP_METHOD(const guchar* get_data() const, gtk_selection_data_get_data)
  _WRAP_METHOD(int get_length() const, gtk_selection_data_get_length)

  std::string get_data_as_string() const;

  //TODO: Change the return type to std::string, when we can break ABI:
  _WRAP_METHOD(GdkAtom get_selection() const, gtk_selection_data_get_selection)

  /** Retrieves the target of the selection.
   *
   * @newin{2,14}
   **/
  std::string get_target() const;
  _IGNORE(gtk_selection_data_get_target)

  /// See also Gtk::Clipboard::request_targets()
  Gdk::ArrayHandle_AtomString get_targets() const;
  _IGNORE(gtk_selection_data_get_targets)

  /** Returns the type of the data as set by SelectionData::set().
   */
  std::string get_data_type() const; // get_type() already exists
  _IGNORE(gtk_selection_data_get_data_type)

  _WRAP_METHOD(int get_format() const, gtk_selection_data_get_format)

  _WRAP_METHOD(Glib::RefPtr<Gdk::Display> get_display(), gtk_selection_data_get_display, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gdk::Display> get_display() const, gtk_selection_data_get_display, refreturn, constversion)

  _WRAP_METHOD(bool targets_include_uri() const, gtk_selection_data_targets_include_uri)
  _WRAP_METHOD(bool targets_include_text() const, gtk_selection_data_targets_include_text)
  _WRAP_METHOD(bool targets_include_rich_text(const Glib::RefPtr<TextBuffer>& buffer) const, gtk_selection_data_targets_include_rich_text)
  _WRAP_METHOD(bool targets_include_image(bool writable = true) const, gtk_selection_data_targets_include_image)
};

} // namespace Gtk

