~ubuntu-branches/ubuntu/karmic/gtkmm2.4/karmic

« back to all changes in this revision

Viewing changes to gtk/gtkmm/clipboard.cc

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-09-22 10:14:59 UTC
  • mfrom: (1.2.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20090922101459-pespb00fbm1mlqbd
Tags: 1:2.18.1-0ubuntu1
* New upstream release: (LP: #434355)
  - RecentManager: Undeprecate get_default().
  - Clipboard: wait_for_targets): Fix a crash.
  - Window: Added set_icon_name().
  - Require a recent pangomm.
  - Style: Fix a compiler error with the Intel C++ compiler.
  - Fix recently-introduced problems with disable-deprecated options.
* debian/control.in:
  - Bump libpangomm-1.4-dev depends and build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <gtkmm/clipboard.h>
5
5
#include <gtkmm/private/clipboard_p.h>
6
6
 
7
 
// -*- c++ -*-
8
 
/* $Id: clipboard.ccg,v 1.11 2006/06/13 17:16:26 murrayc Exp $ */
9
 
 
10
7
/* 
11
8
 *
12
9
 * Copyright 2002 The gtkmm Development Team
124
121
  delete the_slot;
125
122
}
126
123
 
127
 
//This is not public API:
128
 
typedef std::list<Glib::ustring> listStrings;
129
 
static listStrings util_convert_atoms_to_strings(GdkAtom* targets, int n_targets)
130
 
{
131
 
  listStrings listTargets;
132
 
 
133
 
  //Add the targets to the C++ container:
134
 
  for(int i = 0; i < n_targets; i++)
135
 
  {
136
 
    //Convert the atom to a string:
137
 
    char* atom_name = gdk_atom_name(targets[i]);
138
 
    if(atom_name)
139
 
    {
140
 
      listTargets.push_back( Glib::ustring(atom_name) );
141
 
      g_free(atom_name);
142
 
    }
143
 
  }
144
 
 
145
 
  return listTargets;
146
 
}
147
 
 
148
 
static void SignalProxy_TargetsReceived_gtk_callback(GtkClipboard*, GdkAtom* atoms, gint n_atoms, gpointer data)
149
 
{
150
 
  Gtk::Clipboard::SlotTargetsReceived* the_slot = static_cast<Gtk::Clipboard::SlotTargetsReceived*>(data);
151
 
 
152
 
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
 
124
static void SignalProxy_TargetsReceived_gtk_callback(GtkClipboard*, GdkAtom* atoms,
 
125
                                                     gint n_atoms, gpointer data)
 
126
{
 
127
  Gtk::Clipboard::SlotTargetsReceived *const
 
128
    slot = static_cast<Gtk::Clipboard::SlotTargetsReceived*>(data);
 
129
 
 
130
#ifdef GLIBMM_EXCEPTIONS_ENABLED
153
131
  try
 
132
#endif
154
133
  {
155
 
  #endif //GLIBMM_EXCEPTIONS_ENABLED
156
 
    listStrings listTargets = util_convert_atoms_to_strings(atoms, n_atoms);
157
 
    (*the_slot)(listTargets);
158
 
    //I guess that GTK+ does a g_free of the GdkAtoms* array itself, so we do not need to. murrayc.
159
 
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
 
134
    // TODO: This conversion should normally be performed in a custom
 
135
    // Traits implementation.  Alternatively, a real container could
 
136
    // have been used as the argument instead of handle.
 
137
    const unsigned int n_names = (n_atoms > 0) ? n_atoms : 0;
 
138
    char** names = g_new(char*, n_names);
 
139
 
 
140
    std::transform(&atoms[0], &atoms[n_names], &names[0], &gdk_atom_name);
 
141
 
 
142
    (*slot)(Glib::StringArrayHandle(names, n_names, Glib::OWNERSHIP_DEEP));
160
143
  }
161
 
  catch(...)
 
144
#ifdef GLIBMM_EXCEPTIONS_ENABLED
 
145
  catch (...)
162
146
  {
163
147
    Glib::exception_handlers_invoke();
164
148
  }
165
 
  #endif //GLIBMM_EXCEPTIONS_ENABLED
166
 
 
167
 
  delete the_slot; // the callback is only used once
 
149
#endif
 
150
  delete slot; // the callback is only used once
168
151
}
169
152
 
170
153
 
188
171
  delete the_slot; // the callback is only used once
189
172
}
190
173
 
191
 
static void SignalProxy_RichTextReceived_gtk_callback(GtkClipboard*, GdkAtom format, const guint8* text, gsize             length, void* data)
 
174
static void SignalProxy_RichTextReceived_gtk_callback(GtkClipboard*, GdkAtom format,
 
175
                                                      const guint8* text, gsize length, void* data)
192
176
{
193
 
  Gtk::Clipboard::SlotRichTextReceived* the_slot = static_cast<Gtk::Clipboard::SlotRichTextReceived*>(data);
 
177
  Gtk::Clipboard::SlotRichTextReceived *const
 
178
    slot = static_cast<Gtk::Clipboard::SlotRichTextReceived*>(data);
194
179
 
195
 
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
 
180
#ifdef GLIBMM_EXCEPTIONS_ENABLED
196
181
  try
 
182
#endif
197
183
  {
198
 
  #endif //GLIBMM_EXCEPTIONS_ENABLED
199
 
    gchar* format_atom_name = gdk_atom_name(format);
200
 
    (*the_slot)( (format_atom_name ? Glib::ustring(format_atom_name) : Glib::ustring()), (text ? std::string((char*)text, length) : std::string()) );
201
 
    g_free(format_atom_name);
202
 
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
 
184
    (*slot)(Glib::convert_return_gchar_ptr_to_ustring(gdk_atom_name(format)),
 
185
            (text) ? std::string(reinterpret_cast<const char*>(text), length) : std::string());
203
186
  }
 
187
#ifdef GLIBMM_EXCEPTIONS_ENABLED
204
188
  catch(...)
205
189
  {
206
190
    Glib::exception_handlers_invoke();
207
191
  }
208
 
  #endif //GLIBMM_EXCEPTIONS_ENABLED
209
 
 
210
 
  delete the_slot; // the callback is only used once
 
192
#endif
 
193
  delete slot; // the callback is only used once
211
194
}
212
195
 
213
196
static void SignalProxy_UrisReceived_gtk_callback(GtkClipboard*, gchar** uris, void* data)
335
318
 
336
319
Glib::StringArrayHandle Clipboard::wait_for_targets() const
337
320
{
338
 
  std::list<Glib::ustring> listTargets;
339
 
 
340
 
  //Get a newly-allocated array of atoms:
341
 
  GdkAtom* targets = 0;
342
 
  gint n_targets = 0;
343
 
  gboolean test = gtk_clipboard_wait_for_targets( const_cast<GtkClipboard*>(gobj()), &targets, &n_targets );
344
 
  if(!test)
345
 
    n_targets = 0; //otherwise it will be -1.
346
 
 
347
 
  //Add the targets to the C++ container:
348
 
  for(int i = 0; i < n_targets; i++)
 
321
  char**   names = 0;
 
322
  GdkAtom* atoms = 0;
 
323
  int  n_targets = 0;
 
324
 
 
325
  // TODO: This works, but is not the intended way to use the array handles.
 
326
  // Normally one would define custom Traits for the conversion, but that is
 
327
  // not possible here because it would break binary compatibility.
 
328
  if (gtk_clipboard_wait_for_targets(const_cast<GtkClipboard*>(gobj()), &atoms, &n_targets))
349
329
  {
350
 
    //Convert the atom to a string:
351
 
    gchar* const atom_name = gdk_atom_name(targets[i]);
352
 
 
353
 
    Glib::ustring target;
354
 
    if(atom_name)
355
 
      target = Glib::ScopedPtr<char>(atom_name).get(); //This frees the gchar*.
356
 
 
357
 
    listTargets.push_back(target);
 
330
    names = g_new(char*, n_targets);
 
331
    std::transform(&atoms[0], &atoms[n_targets], &names[0], &gdk_atom_name);
 
332
    g_free(atoms);
358
333
  }
 
334
  else
 
335
    n_targets = 0;
359
336
 
360
 
  return listTargets;
 
337
  return Glib::StringArrayHandle(names, n_targets, Glib::OWNERSHIP_DEEP);
361
338
}
362
339
 
363
340
void Clipboard::set_can_store(const ArrayHandle_TargetEntry& targets)