panthera-www.cc
C++ source, ASCII text
1#include "gpanthera.hh" 2#include <gtkmm.h> 3#include <glibmm.h> 4#include <glibmm/ustring.h> 5#include <iostream> 6#include <memory> 7#include <libintl.h> 8#include <locale.h> 9#include <gtk/gtk.h> 10#include <webkit/webkit.h> 11 12class PantheraWww : public Gtk::Application { 13Gtk::Window *window = Gtk::make_managed<Gtk::Window>(); 14protected: 15void on_startup() override { 16Gtk::Application::on_startup(); 17add_window(*window); 18window->set_default_size(600, 400); 19auto layout_manager = std::make_shared<gPanthera::LayoutManager>(); 20auto dock_stack_1 = Gtk::make_managed<gPanthera::DockStack>(layout_manager, "One"); 21auto switcher_1 = Gtk::make_managed<gPanthera::DockStackSwitcher>(dock_stack_1, Gtk::Orientation::HORIZONTAL); 22auto dock_stack_2 = Gtk::make_managed<gPanthera::DockStack>(layout_manager, "Two"); 23auto switcher_2 = Gtk::make_managed<gPanthera::DockStackSwitcher>(dock_stack_2, Gtk::Orientation::VERTICAL); 24auto pane_1_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 25pane_1_content->append(*Gtk::make_managed<Gtk::Label>("Pane 1 content")); 26auto pane_2_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 27pane_2_content->append(*Gtk::make_managed<Gtk::Label>("Pane 2 content")); 28auto pane_3_content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 29pane_3_content->append(*Gtk::make_managed<Gtk::Label>("Pane 3 content")); 30auto pane_1_icon = Gtk::make_managed<Gtk::Image>(); 31pane_1_icon->set_from_icon_name("go-home-symbolic"); 32auto pane_2_icon = Gtk::make_managed<Gtk::Image>(); 33pane_2_icon->set_from_icon_name("folder-symbolic"); 34auto pane_3_icon = Gtk::make_managed<Gtk::Image>(); 35pane_3_icon->set_from_icon_name("network-transmit-receive-symbolic"); 36auto pane_1 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_1_content, "pane1", "Pane 1", pane_1_icon); 37auto pane_2 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_2_content, "pane2", "Pane 2", pane_2_icon); 38auto pane_3 = Gtk::make_managed<gPanthera::DockablePane>(layout_manager, *pane_3_content, "pane3", "Pane 3", pane_3_icon); 39 40dock_stack_1->set_transition_type(Gtk::StackTransitionType::SLIDE_LEFT_RIGHT); 41dock_stack_1->set_transition_duration(125); 42dock_stack_1->set_expand(true); 43dock_stack_2->set_transition_type(Gtk::StackTransitionType::SLIDE_UP_DOWN); 44dock_stack_2->set_transition_duration(125); 45dock_stack_2->set_expand(true); 46 47dock_stack_1->add_pane(*pane_1); 48dock_stack_1->add_pane(*pane_3); 49dock_stack_2->add_pane(*pane_2); 50 51auto outer_grid = Gtk::make_managed<Gtk::Grid>(); 52outer_grid->attach(*switcher_2, 0, 1, 1, 1); 53outer_grid->attach(*switcher_1, 1, 2, 1, 1); 54auto outer_paned = Gtk::make_managed<Gtk::Paned>(Gtk::Orientation::HORIZONTAL); 55outer_paned->set_start_child(*dock_stack_2); 56auto inner_paned = Gtk::make_managed<Gtk::Paned>(Gtk::Orientation::VERTICAL); 57auto content = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 0); 58auto content_manager = std::make_shared<gPanthera::ContentManager>(); 59std::function<bool(gPanthera::ContentPage*)> detach_handler; 60detach_handler = [](gPanthera::ContentPage *widget) { 61auto new_stack = Gtk::make_managed<gPanthera::ContentStack>(widget->content_manager, widget->get_stack()->get_detach_handler()); 62auto new_switcher = Gtk::make_managed<gPanthera::ContentTabBar>(new_stack, Gtk::Orientation::HORIZONTAL, dynamic_cast<gPanthera::ContentTabBar*>(widget->get_stack()->get_parent()->get_first_child())->get_extra_child_function()); 63auto new_notebook = Gtk::make_managed<gPanthera::ContentNotebook>(new_stack, new_switcher); 64auto window = new gPanthera::ContentWindow(new_notebook); 65widget->redock(new_stack); 66window->present(); 67new_stack->signal_leave_empty.connect([window]() { 68window->close(); 69delete window; 70}); 71return true; 72}; 73 74auto return_extra_child = [](Gtk::Widget *switcher) { 75auto label = Gtk::make_managed<Gtk::Label>("Test"); 76return label; 77}; 78auto content_stack = Gtk::make_managed<gPanthera::ContentStack>(content_manager, detach_handler); 79auto content_stack_switcher = Gtk::make_managed<gPanthera::ContentTabBar>(content_stack, Gtk::Orientation::HORIZONTAL, return_extra_child); 80content_manager->add_stack(content_stack); 81WebKitWebView *webview = WEBKIT_WEB_VIEW(webkit_web_view_new()); 82webkit_web_view_load_uri(webview, "https://www.example.com"); 83gtk_widget_set_hexpand(GTK_WIDGET(webview), true); 84gtk_widget_set_vexpand(GTK_WIDGET(webview), true); 85auto page_1_content = Gtk::make_managed<Gtk::Box>(); 86gtk_box_append(page_1_content->gobj(), GTK_WIDGET(webview)); 87auto page_1_tab = new Gtk::Label("Page 1"); 88auto page_1 = Gtk::make_managed<gPanthera::ContentPage>(content_manager, content_stack, page_1_content, page_1_tab); 89auto page_2_content = Gtk::make_managed<Gtk::Label>("Page 2..."); 90auto page_2_tab = new Gtk::Label("Page 2"); 91auto page_2 = Gtk::make_managed<gPanthera::ContentPage>(content_manager, content_stack, page_2_content, page_2_tab); 92content->set_name("content_box"); 93auto content_notebook = Gtk::make_managed<gPanthera::ContentNotebook>(content_stack, content_stack_switcher, Gtk::PositionType::TOP); 94content->append(*content_notebook); 95inner_paned->set_start_child(*content); 96inner_paned->set_end_child(*dock_stack_1); 97outer_paned->set_end_child(*inner_paned); 98outer_grid->attach(*outer_paned, 1, 1, 1, 1); 99window->set_child(*outer_grid); 100} 101 102void on_activate() override { 103window->present(); 104} 105public: 106static Glib::RefPtr<PantheraWww> create() { 107return Glib::make_refptr_for_instance<PantheraWww>(new PantheraWww()); 108} 109}; 110 111int main(int argc, char *argv[]) { 112gPanthera::init(); 113auto app = PantheraWww::create(); 114return app->run(argc, argv); 115} 116