2
/* $Id: selectiondata.ccg,v 1.5 2006/07/05 16:59:28 murrayc Exp $ */
4
/* Copyright 2002 The gtkmm Development Team
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free
18
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <glibmm/vectorutils.h>
23
#include <gtkmm/textbuffer.h>
24
#include <gdkmm/pixbuf.h>
25
#include <glibmm/utility.h> //For ScopedPtr<>.
33
void SelectionData::set(const std::string& type, int format, const guint8* data, int length)
35
gtk_selection_data_set(gobj(), gdk_atom_intern(type.c_str(), 0), format, data, length);
38
void SelectionData::set(int format, const guint8* data, int length)
40
//The C examples do this - that's why I added this method overload. murrayc.
41
set(get_target(), format, data, length);
44
void SelectionData::set(const std::string& type, const std::string& data)
46
gtk_selection_data_set(gobj(), gdk_atom_intern(type.c_str(), 0),
47
sizeof(char) * 8, // format is 8 bits per unit
48
reinterpret_cast<const guint8*>(data.data()), data.size());
51
bool SelectionData::set_text(const Glib::ustring& data)
53
return gtk_selection_data_set_text(gobj(), data.data(), data.bytes());
56
Glib::ustring SelectionData::get_text() const
58
return Glib::convert_return_gchar_ptr_to_ustring(
59
reinterpret_cast<char*>(gtk_selection_data_get_text(const_cast<GtkSelectionData*>(gobj()))));
62
std::string SelectionData::get_data_as_string() const
64
const guchar* data = get_data();
65
const int length = get_length();
66
if(data && length > 0)
67
return std::string(reinterpret_cast<const char*>(data), length);
72
std::string SelectionData::get_target() const
74
return Glib::convert_return_gchar_ptr_to_stdstring(
75
gdk_atom_name( gtk_selection_data_get_target(const_cast<GtkSelectionData*>(gobj())) ) );
78
std::vector<std::string> SelectionData::get_targets() const
83
if(!gtk_selection_data_get_targets(const_cast<GtkSelectionData*>(gobj()), &targets, &n_targets))
84
n_targets = 0; // it's set to -1 otherwise
86
//Note that we free the GdkAtom* array, but we don't need to free its items:
87
return Glib::ArrayHandler<std::string, Gdk::AtomStringTraits>::array_to_vector(targets, n_targets, Glib::OWNERSHIP_SHALLOW);
91
std::string SelectionData::get_data_type() const
93
return Glib::convert_return_gchar_ptr_to_stdstring(
94
gdk_atom_name( gtk_selection_data_get_data_type(const_cast<GtkSelectionData*>(gobj())) ) );