Created
July 16, 2016 16:20
-
-
Save icarofreire/bbfe2586541036da5f7baa1ea15a3036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //$Id: helloworld.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*- | |
| /* gtkmm example Copyright (C) 2002 gtkmm development team | |
| * | |
| * This program is free software; you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License version 2 | |
| * as published by the Free Software Foundation. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program; if not, write to the Free Software | |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| */ | |
| #include "helloworld.h" | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| HelloWorld::HelloWorld() | |
| : m_button("Hello World"), // creates a new button with label "Hello World". | |
| m_VBox(Gtk::ORIENTATION_VERTICAL), | |
| m_Button_Quit("Fechar") | |
| { | |
| // Sets the border width of the window. | |
| set_border_width(10); | |
| set_title("Visualizador de logs"); | |
| set_default_size(400, 400); | |
| add_arquivo.set_label("Adicionar arquivo"); | |
| remover_aba.set_label("Remover Aba"); | |
| // -- | |
| // Gtk::TreeView *treeview = Gtk::manage(new Gtk::TreeView); | |
| // treeview.set_hexpand(true); | |
| // treeview.set_vexpand(true); | |
| // | |
| // refTreeModel = Gtk::ListStore::create(columns); | |
| // treeview.set_model(refTreeModel); | |
| // treeview.append_column("Cnt", columns.col_cnt); | |
| // treeview.append_column("Text", columns.col_text); | |
| // add_lista("teste 1"); | |
| // add_lista("teste 2"); | |
| // add_lista_em_aba(); | |
| // add_lista_em_aba(); | |
| // -- | |
| add(m_VBox); | |
| //Add the Notebook, with the button underneath: | |
| m_Notebook.set_border_width(10); | |
| m_VBox.pack_start(m_Notebook); | |
| m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK); | |
| m_ButtonBox.pack_start(add_arquivo, Gtk::PACK_SHRINK); | |
| m_ButtonBox.pack_start(remover_aba, Gtk::PACK_SHRINK); | |
| m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK); | |
| m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this, | |
| &HelloWorld::on_button_quit) ); | |
| add_arquivo.signal_clicked().connect(sigc::mem_fun(*this, | |
| &HelloWorld::evento_botao_add_arquivo) ); | |
| remover_aba.signal_clicked().connect(sigc::mem_fun(*this, | |
| &HelloWorld::evento_botao_remover_aba) ); | |
| //Add the Notebook pages: | |
| add_aba("Primeiro"); | |
| m_Notebook.signal_switch_page().connect(sigc::mem_fun(*this, | |
| &HelloWorld::on_notebook_switch_page) ); | |
| show_all_children(); | |
| } | |
| HelloWorld::~HelloWorld() | |
| { | |
| } | |
| void HelloWorld::on_button_clicked() | |
| { | |
| std::cout << "Hello World" << std::endl; | |
| } | |
| void HelloWorld::evento_botao_add_arquivo() | |
| { | |
| add_aba("xip"); | |
| std::cout << "Add um novo arquivo" << std::endl; | |
| } | |
| void HelloWorld::evento_botao_remover_aba() | |
| { | |
| int aba = m_Notebook.get_current_page(); | |
| std::cout << "remover aba: " << aba << std::endl; | |
| if( m_Notebook.get_n_pages() > 1 ){ | |
| m_Notebook.remove_page(aba); | |
| } | |
| } | |
| void HelloWorld::on_button_quit() | |
| { | |
| hide(); | |
| } | |
| void HelloWorld::on_notebook_switch_page(Gtk::Widget* /* page */, guint page_num) | |
| { | |
| std::cout << "Switched to tab with index " << page_num << std::endl; | |
| //You can also use m_Notebook.get_current_page() to get this index. | |
| } | |
| void HelloWorld::add_aba(Glib::ustring titulo_da_aba) | |
| { | |
| int indice_nova_aba = m_Notebook.get_n_pages(); | |
| vector<Glib::ustring> linhas; | |
| for(int i=0; i<100; i++){ | |
| linhas.push_back("item "); | |
| } | |
| add_lista_em_aba(indice_nova_aba, linhas); | |
| m_Notebook.append_page(scroll[indice_nova_aba], titulo_da_aba); | |
| lista.show_all(); | |
| show_all_children(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //$Id: helloworld.h 2 2003-01-21 13:41:59Z murrayc $ -*- c++ -*- | |
| /* gtkmm example Copyright (C) 2002 gtkmm development team | |
| * | |
| * This program is free software; you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License version 2 | |
| * as published by the Free Software Foundation. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program; if not, write to the Free Software | |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| */ | |
| #ifndef GTKMM_EXAMPLE_HELLOWORLD_H | |
| #define GTKMM_EXAMPLE_HELLOWORLD_H | |
| // #include <gtkmm/button.h> | |
| // #include <gtkmm/window.h> | |
| #include <gtkmm.h> | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| #define MAXIMO_ABAS 100 | |
| class HelloWorld : public Gtk::Window | |
| { | |
| public: | |
| HelloWorld(); | |
| virtual ~HelloWorld(); | |
| protected: | |
| //Signal handlers: | |
| void on_button_clicked(); | |
| void evento_botao_add_arquivo(); | |
| void evento_botao_remover_aba(); | |
| void on_notebook_switch_page(Gtk::Widget* page, guint page_num); | |
| void on_button_quit(); | |
| //Member widgets: | |
| Gtk::Button m_button; | |
| Gtk::Button add_arquivo; | |
| Gtk::Button remover_aba; | |
| // int numero_abas = 0; | |
| //Child widgets: | |
| Gtk::Box m_VBox; | |
| Gtk::Notebook m_Notebook; | |
| // Glib::RefPtr<Gio::ListStore<Glib::ustring>> m_store; | |
| Gtk::Label abas[MAXIMO_ABAS]; | |
| Gtk::ListBox lista; | |
| Gtk::ScrolledWindow scroll[MAXIMO_ABAS]; | |
| Gtk::ButtonBox m_ButtonBox; | |
| Gtk::Button m_Button_Quit; | |
| void add_aba(Glib::ustring); | |
| //---******************************************************--- | |
| Gtk::TreeView treeview[MAXIMO_ABAS]; | |
| class ModelColumns : public Gtk::TreeModel::ColumnRecord | |
| { | |
| public: | |
| ModelColumns() | |
| { add(col_cnt); add(col_text); } | |
| int rowcount = 0; | |
| Gtk::TreeModelColumn<int> col_cnt; | |
| Gtk::TreeModelColumn<Glib::ustring> col_text; | |
| }; | |
| ModelColumns columns; | |
| Glib::RefPtr<Gtk::ListStore> refTreeModel; | |
| void add_lista(Glib::ustring conteudo) | |
| { | |
| columns.rowcount++; | |
| Gtk::TreeModel::Row row = *(refTreeModel->append()); | |
| row[columns.col_cnt] = columns.rowcount; | |
| row[columns.col_text] = conteudo; | |
| } | |
| void add_lista_em_aba(int indice_aba, vector<Glib::ustring>& linhas) | |
| { | |
| scroll[ indice_aba ].set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); | |
| treeview[ indice_aba ].set_hexpand(true); | |
| treeview[ indice_aba ].set_vexpand(true); | |
| refTreeModel = Gtk::ListStore::create(columns); | |
| treeview[ indice_aba ].set_model(refTreeModel); | |
| treeview[ indice_aba ].append_column("Cnt", columns.col_cnt); | |
| treeview[ indice_aba ].append_column("Text", columns.col_text); | |
| // add_lista("teste 1"); | |
| // add_lista("teste 2"); | |
| // add_lista("teste 3"); | |
| for(vector<Glib::ustring>::iterator i = linhas.begin(); i != linhas.end(); i++){ | |
| add_lista( *i ); | |
| } | |
| scroll[ indice_aba ].add( treeview[ indice_aba ] ); | |
| columns.rowcount = 0; | |
| } | |
| //---******************************************************--- | |
| }; | |
| #endif // GTKMM_EXAMPLE_HELLOWORLD_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //$Id: main.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*- | |
| /* gtkmm example Copyright (C) 2002 gtkmm development team | |
| * | |
| * This program is free software; you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License version 2 | |
| * as published by the Free Software Foundation. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program; if not, write to the Free Software | |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| */ | |
| #include "helloworld.h" | |
| #include "helloworld.cpp" | |
| #include <gtkmm/application.h> | |
| int main (int argc, char *argv[]) | |
| { | |
| Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); | |
| HelloWorld helloworld; | |
| //Shows the window and returns when it is closed. | |
| return app->run(helloworld); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment