| 1 |
/* gtkmm example Copyright (C) 2016 gtkmm development team |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program 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 |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "myobject.h" |
| 18 |
#include <iostream> |
| 19 |
|
| 20 |
MyObject::MyObject(int id, const Glib::ustring& label) |
| 21 |
: |
| 22 |
Glib::ObjectBase(typeid(MyObject)), // because MyObject contains Glib::Property<> |
| 23 |
m_id(id), |
| 24 |
m_property_label(*this, "label", label) |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
Glib::RefPtr<MyObject> MyObject::create(int id, const Glib::ustring& label) |
| 29 |
{ |
| 30 |
return Glib::make_refptr_for_instance(new MyObject(id, label)); |
| 31 |
} |
| 32 |
|
| 33 |
Glib::PropertyProxy<Glib::ustring> MyObject::property_label() |
| 34 |
{ |
| 35 |
return m_property_label.get_proxy(); |
| 36 |
} |
| 37 |
|
| 38 |
int MyObject::compare(const Glib::RefPtr<const MyObject>& a, |
| 39 |
const Glib::RefPtr<const MyObject>& b) |
| 40 |
{ |
| 41 |
if (!a || !b) |
| 42 |
{ |
| 43 |
std::cout << "MyObject::compare(): Empty RefPtr" << std::endl; |
| 44 |
return 0; |
| 45 |
} |
| 46 |
return a->get_id() - b->get_id(); |
| 47 |
} |