Add gtk80
This commit is contained in:
parent
1aee277463
commit
96f86c1e01
|
@ -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})
|
|
@ -0,0 +1,81 @@
|
|||
#include "MyWin.hh"
|
||||
#include <iostream>
|
||||
|
||||
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(){
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
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<int> m_col_num;
|
||||
Gtk::TreeModelColumn<Glib::ustring> m_col_text;
|
||||
};
|
||||
|
||||
ModelColumn m_columns;
|
||||
Gtk::TreeModel::Row row;
|
||||
Gtk::TreeModel::Row childrow;
|
||||
Glib::RefPtr<Gtk::TreeStore> ref_treestore;
|
||||
Glib::RefPtr<Gtk::TreeSelection> ref_selection;
|
||||
|
||||
//Child widgets
|
||||
Gtk::Box m_vbox;
|
||||
Gtk::ButtonBox m_buttonbox;
|
||||
Gtk::ScrolledWindow sw;
|
||||
Gtk::TreeView m_treeview;
|
||||
Gtk::Button btn_quit;
|
||||
};
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue