Debian Codegraph @

gtk/src/selectiondata.hg

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