File: main.cc

package info (click to toggle)
gtkmm3.0 3.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,712 kB
  • sloc: xml: 121,333; cpp: 8,571; sh: 4,301; makefile: 265; perl: 236
file content (55 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>

class AppWindow
    : public Gtk::Window
{
public:
    AppWindow();

private:
    void on_button_clicked();

    Gtk::Label* m_label;
};

AppWindow::AppWindow()
    : m_label (nullptr)
{
    Gtk::Box* vbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, 5);
    add(*vbox);

    Gtk::Button* button = Gtk::make_managed<Gtk::Button>("Delete Label");
    vbox->pack_start(*button, Gtk::PACK_SHRINK);

    //m_label = Gtk::make_managed<Gtk::Label>("test");
    m_label = new Gtk::Label("test");
    g_warning("m_label -> ref_count: %d\n", G_OBJECT(m_label->gobj())->ref_count);
    vbox->pack_start(*m_label, Gtk::PACK_SHRINK);
    g_warning("m_label -> ref_count: %d\n", G_OBJECT(m_label->gobj())->ref_count);

    button->signal_clicked().connect( sigc::mem_fun(*this, &AppWindow::on_button_clicked));

    show_all_children();
}

void AppWindow::on_button_clicked()
{
  if(m_label)
  {
    g_warning("AppWindow::on_button_clicked(): label refcount=%d", G_OBJECT(m_label->gobj())->ref_count);
    delete m_label;
    m_label = nullptr;
  }
}

int main(int argc, char *argv[])
{
  Glib::RefPtr<Gtk::Application> app =
    Gtk::Application::create(argc, argv);
  AppWindow window;
  return app->run(window);
}