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