diff --git a/Gtkmm3/gtk80_treeview2/CMakeLists.txt b/Gtkmm3/gtk80_treeview2/CMakeLists.txt new file mode 100644 index 0000000..b6e6903 --- /dev/null +++ b/Gtkmm3/gtk80_treeview2/CMakeLists.txt @@ -0,0 +1,18 @@ +set(CMAKE_CXX_STANDARD 17) +cmake_minimum_required(VERSION 3.0.0) +project(gtk80 VERSION 0.1.0) + +include(CTest) +enable_testing() + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) + +find_package (PkgConfig REQUIRED) +pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0) +include_directories (${GTKMM3_INCLUDE_DIRS}) +link_directories (${GTKMM3_LIBRARY_DIRS}) +add_executable(gtk80 src/main.cc src/MyWin.cc) +add_definitions (${GTKMM3_CFLAGS_OTHER}) +target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES}) diff --git a/Gtkmm3/gtk80_treeview2/src/MyWin.cc b/Gtkmm3/gtk80_treeview2/src/MyWin.cc new file mode 100644 index 0000000..7add17e --- /dev/null +++ b/Gtkmm3/gtk80_treeview2/src/MyWin.cc @@ -0,0 +1,81 @@ +#include "MyWin.hh" +#include + +MyWin::MyWin() +:m_vbox(Gtk::ORIENTATION_VERTICAL,0), +btn_quit("Exit") +{ + //Initalize window + set_icon_name("org.gtk.daleclack"); + set_default_size(400,300); + set_title("TreeView Test1"); + + //Add widgets + add(m_vbox); + sw.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC); + sw.add(m_treeview); + m_vbox.pack_start(sw); + + //Create the store + ref_treestore=Gtk::TreeStore::create(m_columns); + m_treeview.set_model(ref_treestore); + m_treeview.set_reorderable(); + + //Append items + //Node 1 + row=*(ref_treestore->append()); + row[m_columns.m_col_num]=1; + row[m_columns.m_col_text]="List 1"; + + //Child Nodes + childrow=*(ref_treestore->append(row.children())); + childrow[m_columns.m_col_num]=1; + childrow[m_columns.m_col_text]="Text 1"; + + childrow=*(ref_treestore->append(row.children())); + childrow[m_columns.m_col_num]=2; + childrow[m_columns.m_col_text]="Text 2"; + + //Node 2 + row=*(ref_treestore->append()); + row[m_columns.m_col_num]=2; + row[m_columns.m_col_text]="List 2"; + + //Child Nodes + childrow=*(ref_treestore->append(row.children())); + childrow[m_columns.m_col_num]=3; + childrow[m_columns.m_col_text]="Text 3"; + + childrow=*(ref_treestore->append(row.children())); + childrow[m_columns.m_col_num]=4; + childrow[m_columns.m_col_text]="Text 4"; + + //Node 3 + row=*(ref_treestore->append()); + row[m_columns.m_col_num]=3; + row[m_columns.m_col_text]="List 3"; + + //Child Nodes + childrow=*(ref_treestore->append(row.children())); + childrow[m_columns.m_col_num]=5; + childrow[m_columns.m_col_text]="Text 5"; + + m_treeview.append_column("ID",m_columns.m_col_num); + m_treeview.append_column("List",m_columns.m_col_text); + + //"Exit" button + btn_quit.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::on_btnquit_clicked)); + m_buttonbox.pack_end(btn_quit,Gtk::PACK_SHRINK); + m_vbox.pack_end(m_buttonbox,Gtk::PACK_SHRINK); + + //Show all widgets + show_all_children(); +} + +void MyWin::on_btnquit_clicked(){ + hide(); +} + +MyWin::~MyWin(){ + +} diff --git a/Gtkmm3/gtk80_treeview2/src/MyWin.hh b/Gtkmm3/gtk80_treeview2/src/MyWin.hh new file mode 100644 index 0000000..c87a8ca --- /dev/null +++ b/Gtkmm3/gtk80_treeview2/src/MyWin.hh @@ -0,0 +1,34 @@ +#pragma once + +#include + +class MyWin : public Gtk::Window{ +public: + MyWin(); + virtual ~MyWin(); +protected: + //Signal Handlers + void on_btnquit_clicked(); + + //TreeModel Columns + class ModelColumn : public Gtk::TreeModelColumnRecord{ + public: + ModelColumn() + {add(m_col_num);add(m_col_text);} + Gtk::TreeModelColumn m_col_num; + Gtk::TreeModelColumn m_col_text; + }; + + ModelColumn m_columns; + Gtk::TreeModel::Row row; + Gtk::TreeModel::Row childrow; + Glib::RefPtr ref_treestore; + Glib::RefPtr ref_selection; + + //Child widgets + Gtk::Box m_vbox; + Gtk::ButtonBox m_buttonbox; + Gtk::ScrolledWindow sw; + Gtk::TreeView m_treeview; + Gtk::Button btn_quit; +}; \ No newline at end of file diff --git a/Gtkmm3/gtk80_treeview2/src/main.cc b/Gtkmm3/gtk80_treeview2/src/main.cc new file mode 100644 index 0000000..0c49a3a --- /dev/null +++ b/Gtkmm3/gtk80_treeview2/src/main.cc @@ -0,0 +1,7 @@ +#include "MyWin.hh" + +int main(int argc,char **argv){ + auto app=Gtk::Application::create(argc,argv,"org.gtk.daleclack"); + MyWin window; + return app->run(window); +} \ No newline at end of file