1 // Generated by gmmproc 2.60.0 -- DO NOT MODIFY!
2
3
4 #include <glibmm.h>
5
6 #include <gtkmm/clipboard.h>
7 #include <gtkmm/private/clipboard_p.h>
8
9
10 /*
11 * Copyright 2002 The gtkmm Development Team
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 #include <glibmm/vectorutils.h>
29
30 #include <gdkmm/types.h>
31
32 #include <gtkmm/textbuffer.h>
33 #include <gtkmm/selectiondata_private.h>
34 #include <glibmm/utility.h> //For make_unique_ptr_gfree<>.
35 #include <gtk/gtk.h>
36
37 namespace
38 {
39
40 // SignalProxy_GetClear:
41 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
42 class SignalProxy_GetClear
43 {
44 public:
45 SignalProxy_GetClear(const Gtk::Clipboard::SlotGet& slot_get,
46 const Gtk::Clipboard::SlotClear& slot_clear);
47
48 static void gtk_callback_get(GtkClipboard* clipboard, GtkSelectionData* selection_data,
49 unsigned int info, void* data);
50 static void gtk_callback_clear(GtkClipboard* clipboard, void* data);
51
52 Gtk::Clipboard::SlotGet slot_get_;
53 Gtk::Clipboard::SlotClear slot_clear_;
54 };
55
SignalProxy_GetClear(const Gtk::Clipboard::SlotGet & slot_get,const Gtk::Clipboard::SlotClear & slot_clear)56 SignalProxy_GetClear::SignalProxy_GetClear(const Gtk::Clipboard::SlotGet& slot_get,
57 const Gtk::Clipboard::SlotClear& slot_clear)
58 :
59 slot_get_ (slot_get),
60 slot_clear_ (slot_clear)
61 {}
62
SignalProxy_GetClear_gtk_callback_get(GtkClipboard *,GtkSelectionData * selection_data,unsigned int info,void * data)63 static void SignalProxy_GetClear_gtk_callback_get(GtkClipboard*, GtkSelectionData* selection_data,
64 unsigned int info, void* data)
65 {
66 const auto self = static_cast<SignalProxy_GetClear*>(data);
67
68 try
69 {
70 Gtk::SelectionData_WithoutOwnership cppSelectionData(selection_data);
71 (self->slot_get_)(cppSelectionData, info);
72 }
73 catch(...)
74 {
75 Glib::exception_handlers_invoke();
76 }
77 }
78
SignalProxy_GetClear_gtk_callback_clear(GtkClipboard *,void * data)79 static void SignalProxy_GetClear_gtk_callback_clear(GtkClipboard*, void* data)
80 {
81 const auto self = static_cast<SignalProxy_GetClear*>(data);
82
83 try
84 {
85 (self->slot_clear_)();
86 }
87 catch(...)
88 {
89 Glib::exception_handlers_invoke();
90 }
91
92 delete self; // After this callback has been called, none of the 2 callbacks will be called again.
93
94 //This might leak the last SignalProxy_GetClear(), but only the last one,
95 //because clear() is called when set() is called again.
96 }
97
98 } //anonymous namespace
99
100
SignalProxy_Received_gtk_callback(GtkClipboard *,GtkSelectionData * selection_data,void * data)101 static void SignalProxy_Received_gtk_callback(GtkClipboard*, GtkSelectionData* selection_data, void* data)
102 {
103 auto the_slot = static_cast<Gtk::Clipboard::SlotReceived*>(data);
104
105 try
106 {
107 Gtk::SelectionData cppSelectionData(selection_data, true /*take_copy=true*/);
108 (*the_slot)(cppSelectionData);
109 }
110 catch(...)
111 {
112 Glib::exception_handlers_invoke();
113 }
114
115 delete the_slot;
116 }
117
SignalProxy_TargetsReceived_gtk_callback(GtkClipboard *,GdkAtom * atoms,gint n_atoms,gpointer data)118 static void SignalProxy_TargetsReceived_gtk_callback(GtkClipboard*, GdkAtom* atoms,
119 gint n_atoms, gpointer data)
120 {
121 Gtk::Clipboard::SlotTargetsReceived *const
122 slot = static_cast<Gtk::Clipboard::SlotTargetsReceived*>(data);
123
124 try
125 {
126 // TODO: check if the ownership is good.
127 (*slot) (Glib::ArrayHandler<Glib::ustring, Gdk::AtomStringTraits>::array_to_vector(atoms, n_atoms > 0 ? n_atoms : 0, Glib::OWNERSHIP_NONE));
128 }
129 catch (...)
130 {
131 Glib::exception_handlers_invoke();
132 }
133 delete slot; // the callback is only used once
134 }
135
136
SignalProxy_TextReceived_gtk_callback(GtkClipboard *,const char * text,void * data)137 static void SignalProxy_TextReceived_gtk_callback(GtkClipboard*, const char* text, void* data)
138 {
139 auto the_slot = static_cast<Gtk::Clipboard::SlotTextReceived*>(data);
140
141 try
142 {
143 (*the_slot)((text) ? Glib::ustring(text) : Glib::ustring());
144 }
145 catch(...)
146 {
147 Glib::exception_handlers_invoke();
148 }
149
150 delete the_slot; // the callback is only used once
151 }
152
SignalProxy_RichTextReceived_gtk_callback(GtkClipboard *,GdkAtom format,const guint8 * text,gsize length,void * data)153 static void SignalProxy_RichTextReceived_gtk_callback(GtkClipboard*, GdkAtom format,
154 const guint8* text, gsize length, void* data)
155 {
156 Gtk::Clipboard::SlotRichTextReceived *const
157 slot = static_cast<Gtk::Clipboard::SlotRichTextReceived*>(data);
158
159 try
160 {
161 (*slot)(Glib::convert_return_gchar_ptr_to_ustring(gdk_atom_name(format)),
162 (text) ? std::string(reinterpret_cast<const char*>(text), length) : std::string());
163 }
164 catch(...)
165 {
166 Glib::exception_handlers_invoke();
167 }
168 delete slot; // the callback is only used once
169 }
170
SignalProxy_UrisReceived_gtk_callback(GtkClipboard *,gchar ** uris,void * data)171 static void SignalProxy_UrisReceived_gtk_callback(GtkClipboard*, gchar** uris, void* data)
172 {
173 auto the_slot = static_cast<Gtk::Clipboard::SlotUrisReceived*>(data);
174
175 try
176 {
177 // TODO: check if the ownetship is good. krnowak.
178 //Handle: Does this take ownership? It should probalby copy. murrayc.
179 (*the_slot)( Glib::ArrayHandler<Glib::ustring>::array_to_vector(uris, Glib::OWNERSHIP_NONE) );
180 }
181 catch(...)
182 {
183 Glib::exception_handlers_invoke();
184 }
185
186 delete the_slot; // the callback is only used once
187 }
188
SignalProxy_ImageReceived_gtk_callback(GtkClipboard *,GdkPixbuf * image,void * data)189 static void SignalProxy_ImageReceived_gtk_callback(GtkClipboard*, GdkPixbuf* image, void* data)
190 {
191 auto the_slot = static_cast<Gtk::Clipboard::SlotImageReceived*>(data);
192
193 try
194 {
195 (*the_slot)(Glib::wrap(image, true /* take_ref */));
196 }
197 catch(...)
198 {
199 Glib::exception_handlers_invoke();
200 }
201
202 delete the_slot; // the callback is only used once
203 }
204
205
206 namespace Gtk
207 {
208
set(const std::vector<TargetEntry> & targets,const SlotGet & slot_get,const SlotClear & slot_clear)209 bool Clipboard::set(const std::vector<TargetEntry>& targets,
210 const SlotGet& slot_get, const SlotClear& slot_clear)
211 {
212 // Create a signal proxy. A pointer to this will be passed through the callback's data parameter.
213 const auto pSignalProxy = new SignalProxy_GetClear(slot_get, slot_clear);
214
215 return gtk_clipboard_set_with_data(
216 gobj(),
217 Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data (),
218 targets.size(),
219 &SignalProxy_GetClear_gtk_callback_get,
220 &SignalProxy_GetClear_gtk_callback_clear,
221 pSignalProxy);
222 }
223
set_text(const Glib::ustring & text)224 void Clipboard::set_text(const Glib::ustring& text)
225 {
226 gtk_clipboard_set_text(gobj(), text.c_str(), text.bytes());
227 }
228
229
request_contents(const Glib::ustring & target,const SlotReceived & slot)230 void Clipboard::request_contents(const Glib::ustring& target, const SlotReceived& slot)
231 {
232 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
233 auto slot_copy = new SlotReceived(slot);
234
235 gtk_clipboard_request_contents(gobj(), gdk_atom_intern(target.c_str(), FALSE),
236 &SignalProxy_Received_gtk_callback, slot_copy);
237 }
238
request_text(const SlotTextReceived & slot)239 void Clipboard::request_text(const SlotTextReceived& slot)
240 {
241 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
242 auto slot_copy = new SlotTextReceived(slot);
243
244 gtk_clipboard_request_text(gobj(),
245 &SignalProxy_TextReceived_gtk_callback, slot_copy);
246 }
247
request_rich_text(const Glib::RefPtr<TextBuffer> & buffer,const SlotRichTextReceived & slot)248 void Clipboard::request_rich_text(const Glib::RefPtr<TextBuffer>& buffer, const SlotRichTextReceived& slot)
249 {
250 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
251 auto slot_copy = new SlotRichTextReceived(slot);
252
253 gtk_clipboard_request_rich_text(gobj(), buffer->gobj(),
254 &SignalProxy_RichTextReceived_gtk_callback, slot_copy);
255 }
256
request_uris(const SlotUrisReceived & slot)257 void Clipboard::request_uris(const SlotUrisReceived& slot)
258 {
259 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
260 auto slot_copy = new SlotUrisReceived(slot);
261
262 gtk_clipboard_request_uris(gobj(), &SignalProxy_UrisReceived_gtk_callback, slot_copy);
263 }
264
request_image(const SlotImageReceived & slot)265 void Clipboard::request_image(const SlotImageReceived& slot)
266 {
267 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
268 auto slot_copy = new SlotImageReceived(slot);
269
270 gtk_clipboard_request_image(gobj(),
271 &SignalProxy_ImageReceived_gtk_callback, slot_copy);
272 }
273
request_targets(const SlotTargetsReceived & slot)274 void Clipboard::request_targets(const SlotTargetsReceived& slot)
275 {
276 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
277 auto slot_copy = new SlotTargetsReceived(slot);
278
279 gtk_clipboard_request_targets(gobj(), &SignalProxy_TargetsReceived_gtk_callback, slot_copy);
280 }
281
wait_for_contents(const Glib::ustring & target) const282 SelectionData Clipboard::wait_for_contents(const Glib::ustring& target) const
283 {
284 //gtk_clipboard_wait_for_contents returns a newly-allocated GtkSelectionData, or NULL.
285 auto cData = gtk_clipboard_wait_for_contents( const_cast<GtkClipboard*>(gobj()), gdk_atom_intern(target.c_str(), FALSE) );
286 return SelectionData(cData, false /* take_copy */);
287 }
288
wait_for_targets() const289 std::vector<Glib::ustring> Clipboard::wait_for_targets() const
290 {
291 GdkAtom* atoms (nullptr);
292 int n_targets (0);
293
294 if (!gtk_clipboard_wait_for_targets(const_cast<GtkClipboard*>(gobj()), &atoms, &n_targets))
295 {
296 n_targets = 0;
297 }
298
299 return Glib::ArrayHandler<Glib::ustring, Gdk::AtomStringTraits>::array_to_vector(atoms, n_targets, Glib::OWNERSHIP_SHALLOW);
300 }
301
set_can_store(const std::vector<TargetEntry> & targets)302 void Clipboard::set_can_store(const std::vector<TargetEntry>& targets)
303 {
304 gtk_clipboard_set_can_store( gobj(), Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data (), targets.size() );
305 }
306
set_can_store()307 void Clipboard::set_can_store()
308 {
309 gtk_clipboard_set_can_store( gobj(), nullptr, 0 /* See C docs */ );
310 }
311
wait_for_rich_text(const Glib::RefPtr<TextBuffer> & buffer,std::string & format)312 std::string Clipboard::wait_for_rich_text(const Glib::RefPtr<TextBuffer>& buffer, std::string& format)
313 {
314 std::string result;
315
316 GdkAtom format_atom = GDK_NONE;
317 gsize length = 0;
318 guint8* text = gtk_clipboard_wait_for_rich_text(const_cast<GtkClipboard*>(gobj()), buffer->gobj(), &format_atom, &length);
319 if(text && length)
320 {
321 gchar* format_atom_name = gdk_atom_name(format_atom);
322 if(format_atom_name)
323 format = Glib::make_unique_ptr_gfree(format_atom_name).get(); //This frees the buffer.
324
325 result = std::string((char*)text, length);
326 g_free(text);
327 }
328
329 return result;
330 }
331
332
333 } //namespace Gtk
334
335
336 namespace
337 {
338
339
Clipboard_signal_owner_change_callback(GtkClipboard * self,GdkEventOwnerChange * p0,void * data)340 static void Clipboard_signal_owner_change_callback(GtkClipboard* self, GdkEventOwnerChange* p0,void* data)
341 {
342 using namespace Gtk;
343 using SlotType = sigc::slot< void,GdkEventOwnerChange* >;
344
345 auto obj = dynamic_cast<Clipboard*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self));
346 // Do not try to call a signal on a disassociated wrapper.
347 if(obj)
348 {
349 try
350 {
351 if(const auto slot = Glib::SignalProxyNormal::data_to_slot(data))
352 (*static_cast<SlotType*>(slot))(p0);
353 }
354 catch(...)
355 {
356 Glib::exception_handlers_invoke();
357 }
358 }
359 }
360
361 static const Glib::SignalProxyInfo Clipboard_signal_owner_change_info =
362 {
363 "owner_change",
364 (GCallback) &Clipboard_signal_owner_change_callback,
365 (GCallback) &Clipboard_signal_owner_change_callback
366 };
367
368
369 } // anonymous namespace
370
371
372 namespace Glib
373 {
374
wrap(GtkClipboard * object,bool take_copy)375 Glib::RefPtr<Gtk::Clipboard> wrap(GtkClipboard* object, bool take_copy)
376 {
377 return Glib::RefPtr<Gtk::Clipboard>( dynamic_cast<Gtk::Clipboard*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
378 //We use dynamic_cast<> in case of multiple inheritance.
379 }
380
381 } /* namespace Glib */
382
383
384 namespace Gtk
385 {
386
387
388 /* The *_Class implementation: */
389
init()390 const Glib::Class& Clipboard_Class::init()
391 {
392 if(!gtype_) // create the GType if necessary
393 {
394 // Glib::Class has to know the class init function to clone custom types.
395 class_init_func_ = &Clipboard_Class::class_init_function;
396
397 // This is actually just optimized away, apparently with no harm.
398 // Make sure that the parent type has been created.
399 //CppClassParent::CppObjectType::get_type();
400
401 // Create the wrapper type, with the same class/instance size as the base type.
402 register_derived_type(gtk_clipboard_get_type());
403
404 // Add derived versions of interfaces, if the C type implements any interfaces:
405
406 }
407
408 return *this;
409 }
410
411
class_init_function(void * g_class,void * class_data)412 void Clipboard_Class::class_init_function(void* g_class, void* class_data)
413 {
414 const auto klass = static_cast<BaseClassType*>(g_class);
415 CppClassParent::class_init_function(klass, class_data);
416
417
418 }
419
420
wrap_new(GObject * object)421 Glib::ObjectBase* Clipboard_Class::wrap_new(GObject* object)
422 {
423 return new Clipboard((GtkClipboard*)object);
424 }
425
426
427 /* The implementation: */
428
gobj_copy()429 GtkClipboard* Clipboard::gobj_copy()
430 {
431 reference();
432 return gobj();
433 }
434
Clipboard(const Glib::ConstructParams & construct_params)435 Clipboard::Clipboard(const Glib::ConstructParams& construct_params)
436 :
437 Glib::Object(construct_params)
438 {
439
440 }
441
Clipboard(GtkClipboard * castitem)442 Clipboard::Clipboard(GtkClipboard* castitem)
443 :
444 Glib::Object((GObject*)(castitem))
445 {}
446
447
Clipboard(Clipboard && src)448 Clipboard::Clipboard(Clipboard&& src) noexcept
449 : Glib::Object(std::move(src))
450 {}
451
operator =(Clipboard && src)452 Clipboard& Clipboard::operator=(Clipboard&& src) noexcept
453 {
454 Glib::Object::operator=(std::move(src));
455 return *this;
456 }
457
458
~Clipboard()459 Clipboard::~Clipboard() noexcept
460 {}
461
462
463 Clipboard::CppClassType Clipboard::clipboard_class_; // initialize static member
464
get_type()465 GType Clipboard::get_type()
466 {
467 return clipboard_class_.init().get_type();
468 }
469
470
get_base_type()471 GType Clipboard::get_base_type()
472 {
473 return gtk_clipboard_get_type();
474 }
475
476
get(GdkAtom selection)477 Glib::RefPtr<Clipboard> Clipboard::get(GdkAtom selection)
478 {
479
480 Glib::RefPtr<Clipboard> retvalue = Glib::wrap(gtk_clipboard_get(selection));
481 if(retvalue)
482 retvalue->reference(); //The function does not do a ref for us
483 return retvalue;
484 }
485
get_for_display(const Glib::RefPtr<Gdk::Display> & display,GdkAtom selection)486 Glib::RefPtr<Clipboard> Clipboard::get_for_display(const Glib::RefPtr<Gdk::Display>& display, GdkAtom selection)
487 {
488
489 Glib::RefPtr<Clipboard> retvalue = Glib::wrap(gtk_clipboard_get_for_display(Glib::unwrap(display), selection));
490 if(retvalue)
491 retvalue->reference(); //The function does not do a ref for us
492 return retvalue;
493 }
494
get_display()495 Glib::RefPtr<Gdk::Display> Clipboard::get_display()
496 {
497 Glib::RefPtr<Gdk::Display> retvalue = Glib::wrap(gtk_clipboard_get_display(gobj()));
498 if(retvalue)
499 retvalue->reference(); //The function does not do a ref for us.
500 return retvalue;
501 }
502
get_display() const503 Glib::RefPtr<const Gdk::Display> Clipboard::get_display() const
504 {
505 return const_cast<Clipboard*>(this)->get_display();
506 }
507
get_owner()508 Glib::RefPtr<Glib::Object> Clipboard::get_owner()
509 {
510 Glib::RefPtr<Glib::Object> retvalue = Glib::wrap(gtk_clipboard_get_owner(gobj()));
511 if(retvalue)
512 retvalue->reference(); //The function does not do a ref for us.
513 return retvalue;
514 }
515
get_owner() const516 Glib::RefPtr<const Glib::Object> Clipboard::get_owner() const
517 {
518 return const_cast<Clipboard*>(this)->get_owner();
519 }
520
clear()521 void Clipboard::clear()
522 {
523 gtk_clipboard_clear(gobj());
524 }
525
set_image(const Glib::RefPtr<Gdk::Pixbuf> & pixbuf)526 void Clipboard::set_image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
527 {
528 gtk_clipboard_set_image(gobj(), Glib::unwrap(pixbuf));
529 }
530
wait_for_text() const531 Glib::ustring Clipboard::wait_for_text() const
532 {
533 return Glib::convert_return_gchar_ptr_to_ustring(gtk_clipboard_wait_for_text(const_cast<GtkClipboard*>(gobj())));
534 }
535
wait_for_image() const536 Glib::RefPtr<Gdk::Pixbuf> Clipboard::wait_for_image() const
537 {
538 return Glib::wrap(gtk_clipboard_wait_for_image(const_cast<GtkClipboard*>(gobj())));
539 }
540
wait_is_text_available() const541 bool Clipboard::wait_is_text_available() const
542 {
543 return gtk_clipboard_wait_is_text_available(const_cast<GtkClipboard*>(gobj()));
544 }
545
wait_is_rich_text_available(const Glib::RefPtr<TextBuffer> & buffer) const546 bool Clipboard::wait_is_rich_text_available(const Glib::RefPtr<TextBuffer>& buffer) const
547 {
548 return gtk_clipboard_wait_is_rich_text_available(const_cast<GtkClipboard*>(gobj()), Glib::unwrap(buffer));
549 }
550
wait_is_image_available() const551 bool Clipboard::wait_is_image_available() const
552 {
553 return gtk_clipboard_wait_is_image_available(const_cast<GtkClipboard*>(gobj()));
554 }
555
wait_is_uris_available() const556 bool Clipboard::wait_is_uris_available() const
557 {
558 return gtk_clipboard_wait_is_uris_available(const_cast<GtkClipboard*>(gobj()));
559 }
560
wait_is_target_available(const Glib::ustring & target)561 bool Clipboard::wait_is_target_available(const Glib::ustring& target)
562 {
563 return gtk_clipboard_wait_is_target_available(gobj(), Gdk::AtomString::to_c_type(target));
564 }
565
wait_for_uris() const566 std::vector<Glib::ustring> Clipboard::wait_for_uris() const
567 {
568 return Glib::ArrayHandler<Glib::ustring>::array_to_vector(gtk_clipboard_wait_for_uris(const_cast<GtkClipboard*>(gobj())), Glib::OWNERSHIP_DEEP);
569 }
570
store()571 void Clipboard::store()
572 {
573 gtk_clipboard_store(gobj());
574 }
575
get_selection() const576 GdkAtom Clipboard::get_selection() const
577 {
578 return gtk_clipboard_get_selection(const_cast<GtkClipboard*>(gobj()));
579 }
580
581
signal_owner_change()582 Glib::SignalProxy< void,GdkEventOwnerChange* > Clipboard::signal_owner_change()
583 {
584 return Glib::SignalProxy< void,GdkEventOwnerChange* >(this, &Clipboard_signal_owner_change_info);
585 }
586
587
588 } // namespace Gtk
589
590
591