add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / object.hg
1 /* $Id: object.hg,v 1.5 2006/04/07 14:11:37 gustin Exp $ */
2
3 /* Copyright (C) 1998-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 Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 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  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library 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 #include <glibmm/object.h>
21 #include <gtkmm/base.h>
22 #include <gtkmmconfig.h>
23 _DEFS(gtkmm,gtk)
24 _PINCLUDE(glibmm/private/object_p.h)
25
26 namespace Gtk
27 {
28
29 class Object;
30
31 /** Mark a Gtk::Object as owned by its parent container widget, so you don't need to delete it manually.
32  * For instance,
33  * @code
34  * Gtk::Button* button = Gtk::manage( new Gtk::Button("Hello") );
35  * vbox.pack_start(*button); //vbox will delete button when vbox is deleted.
36  * @endcode
37  *
38  * @param obj A Gtk::Object, such as a gtkmm widget.
39  * @result The Gtk::Object passed as the @a obj parameter.
40  */
41 template<class T>
42 T* manage(T* obj)
43 {
44   obj->set_manage();
45   return obj;
46 }
47
48 /** Gtk::Object is the base class for all widgets, and for a few non-widget objects such as 
49  * Gtk::Adjustment. Gtk::Object predates Glib::Object; non-widgets that derive from Gtk::Object 
50  * rather than Glib::Object do so for backward compatibility reasons.
51  *
52  * The most interesting difference between Gtk::Object and Glib::Object is the ability to use Gtk::manage() to delegate memory management to the container widget. Gtk::Objects can also be 
53  * explicitly deleted at any time, instead of using only reference-counting, and container widgets 
54  * can respond when their child objects are being deleted (for instance by removing the widget).
55  */
56 class GTKMM_API Object : public Glib::Object
57 {
58   _CLASS_GTKOBJECT(Object,GtkObject,GTK_OBJECT,Glib::Object,GObject)
59   _IGNORE(gtk_object_ref, gtk_object_unref, gtk_object_weakref, gtk_object_weakunref, gtk_object_set_data,
60           gtk_object_set_data_full, gtk_object_remove_data, gtk_object_get_data, gtk_object_remove_no_notify,
61           gtk_object_set_user_data, gtk_object_get_user_data, gtk_object_set_data_by_id, gtk_object_set_data_by_id_full,
62           gtk_object_get_data_by_id, gtk_object_remove_data_by_id, gtk_object_remove_no_notify_by_id, gtk_object_get,
63           gtk_object_set, gtk_object_add_arg_type, gtk_object_destroy, gtk_object_sink)
64   _CUSTOM_DTOR
65   _CUSTOM_CTOR_CAST
66
67 public:
68   //void shutdown(); //We probably don't need this.
69   //void finalize(); //We probably don't need this.
70
71   //void set_user_data(gpointer data);
72   //gpointer get_user_data();
73
74   #ifndef DOXYGEN_SHOULD_SKIP_THIS
75   /** Used by Gtk::manage(). You should not need to use this directly.
76    */
77   virtual void set_manage();
78   #endif //DOXYGEN_SHOULD_SKIP_THIS
79
80   _WRAP_PROPERTY("user-data", void*)
81
82   #ifndef DOXYGEN_SHOULD_SKIP_THIS
83   /** Private API.
84    */
85   bool is_managed_() const;
86   #endif //DOXYGEN_SHOULD_SKIP_THIS
87
88 protected:
89
90   #ifndef DOXYGEN_SHOULD_SKIP_THIS
91   /** Private API.
92    */
93   void destroy_();
94   #endif //DOXYGEN_SHOULD_SKIP_THIS
95
96   // If you need it, give me an example. murrayc. -- Me too. daniel.
97   //_WRAP_SIGNAL(void destroy(), "destroy")
98   _IGNORE_SIGNAL(destroy)
99
100   #ifndef DOXYGEN_SHOULD_SKIP_THIS
101   void _init_unmanage(bool is_toplevel = false);
102   virtual void destroy_notify_(); //override.
103   void disconnect_cpp_wrapper();
104   void _destroy_c_instance();
105   static void callback_destroy_(GObject* gobject, void* data); //only connected for a short time.
106
107   // set if flags used by derived classes.
108   bool referenced_; // = not managed.
109   bool gobject_disposed_;
110   #endif //DOXYGEN_SHOULD_SKIP_THIS
111 };
112
113 } // namespace Gtk
114