1/* $Id: selectiondata.hg,v 1.9 2006/07/05 16:59:28 murrayc Exp $ */ 2 3/* Copyright(C) 2002 The gtkmm Development Team 4 * 5 * This library is free software, ) you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation, ) either 8 * version 2.1 of the License, or(at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY, ) without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library, ) if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20_DEFS(gtkmm,gtk) 21 22#include <gdkmm/display.h> 23 24 25namespace Gtk 26{ 27 28#ifndef DOXYGEN_SHOULD_SKIP_THIS 29class TextBuffer; 30#endif //DOXYGEN_SHOULD_SKIP_THIS 31 32class SelectionData 33{ 34 _CLASS_BOXEDTYPE(SelectionData, GtkSelectionData, NONE, gtk_selection_data_copy, gtk_selection_data_free) 35 _IGNORE(gtk_selection_data_copy, gtk_selection_data_free) 36public: 37 38 //TODO : document this. It's like the other set(), but it uses this SelectionData's target type. 39 //Why would you ever want to use any other type? 40 void set(int format, const guint8* data, int length); 41 42 /** Assign a memory block of raw data. 43 * Store new data into the Gtk::SelectionData object. Should _only_ by called 44 * from a selection handler callback. A 0-byte terminates the stored data. 45 * @param type The type of the selection. 46 * @param format The data format, i.e. the number of bits in a unit. 47 * @param data Pointer to the data (will be copied). 48 * @param length The length of the data block in bytes. 49 */ 50 void set(const std::string& type, int format, const guint8* data, int length); 51 52 /** Assign a string of raw data. 53 * Store new data into the Gtk::SelectionData object. Should _only_ by called 54 * from a selection handler callback. 55 * @param type The type of the selection. 56 * @param data A string that contains the data (does not have to be text). 57 */ 58 void set(const std::string& type, const std::string& data); 59 _IGNORE(gtk_selection_data_set) 60 61 /** Assign UTF-8 encoded text. 62 * Sets the contents of the selection from a UTF-8 encoded string. 63 * The string is converted to the form determined by get_target(). 64 * @param data A UTF-8 encoded string. 65 * @return <tt>true</tt> if the selection was successfully set, 66 * otherwise <tt>false</tt>. 67 */ 68 bool set_text(const Glib::ustring& data); 69 _IGNORE(gtk_selection_data_set_text) 70 71 /** Gets the contents of the selection data as a UTF-8 string. 72 * @return If the selection data contained a recognized text type and 73 * it could be converted to UTF-8, a string containing the converted text, 74 * otherwise an empty string. 75 */ 76 Glib::ustring get_text() const; 77 _IGNORE(gtk_selection_data_get_text) 78 79 _WRAP_METHOD(bool set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_selection_data_set_pixbuf) 80 _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_pixbuf(), gtk_selection_data_get_pixbuf) 81 _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_pixbuf() const, gtk_selection_data_get_pixbuf, constversion) 82 83#dnl The constness of gtk_selection_data_set_uris() is not quite right: 84#m4 _CONVERSION(`const Glib::StringArrayHandle&',`gchar**',`const_cast<char**>(($3).data())') 85 _WRAP_METHOD(bool set_uris(const Glib::StringArrayHandle& uris), gtk_selection_data_set_uris) 86 _WRAP_METHOD(Glib::StringArrayHandle get_uris() const, gtk_selection_data_get_uris) 87 88 89 _WRAP_METHOD(const guchar* get_data() const, gtk_selection_data_get_data) 90 _WRAP_METHOD(int get_length() const, gtk_selection_data_get_length) 91 92 std::string get_data_as_string() const; 93 94 //TODO: Change the return type to std::string, when we can break ABI: 95 _WRAP_METHOD(GdkAtom get_selection() const, gtk_selection_data_get_selection) 96 97 /** Retrieves the target of the selection. 98 * 99 * @newin{2,14} 100 **/ 101 std::string get_target() const; 102 _IGNORE(gtk_selection_data_get_target) 103 104 /// See also Gtk::Clipboard::request_targets() 105 Gdk::ArrayHandle_AtomString get_targets() const; 106 _IGNORE(gtk_selection_data_get_targets) 107 108 /** Returns the type of the data as set by SelectionData::set(). 109 */ 110 std::string get_data_type() const; // get_type() already exists 111 _IGNORE(gtk_selection_data_get_data_type) 112 113 _WRAP_METHOD(int get_format() const, gtk_selection_data_get_format) 114 115 _WRAP_METHOD(Glib::RefPtr<Gdk::Display> get_display(), gtk_selection_data_get_display, refreturn) 116 _WRAP_METHOD(Glib::RefPtr<const Gdk::Display> get_display() const, gtk_selection_data_get_display, refreturn, constversion) 117 118 _WRAP_METHOD(bool targets_include_uri() const, gtk_selection_data_targets_include_uri) 119 _WRAP_METHOD(bool targets_include_text() const, gtk_selection_data_targets_include_text) 120 _WRAP_METHOD(bool targets_include_rich_text(const Glib::RefPtr<TextBuffer>& buffer) const, gtk_selection_data_targets_include_rich_text) 121 _WRAP_METHOD(bool targets_include_image(bool writable = true) const, gtk_selection_data_targets_include_image) 122}; 123 124} // namespace Gtk 125 126