1 #include "browser_window.h"
4 #include <l4/scout-gfx/sky_texture>
5 #include <l4/scout-gfx/stack_layout>
6 #include <l4/scout-gfx/box_layout>
7 #include <l4/scout-gfx/scroll_pane>
8 #include <l4/scout-gfx/fonts>
11 /****************************
12 ** External graphics data **
13 ****************************/
15 #define SIZER_RGBA _binary_sizer_rgba_start
16 #define TITLEBAR_RGBA _binary_titlebar_rgba_start
18 extern unsigned char SIZER_RGBA[];
19 extern unsigned char TITLEBAR_RGBA[];
21 static Mag_gfx::Font &title_font = Scout_gfx::Fonts::vera18;
23 class Browser_sizer_event_handler : public Scout_gfx::Sizer_event_handler
27 Browser_window *_browser_win;
28 Scout_gfx::Widget *_ca; /* original visible element */
31 * Event handler interface
35 Sizer_event_handler::start_drag();
36 _ca = _browser_win->curr_anchor();
41 Sizer_event_handler::do_drag();
42 _browser_win->go_to(_ca, 0);
50 Browser_sizer_event_handler(Browser_window *browser_win)
51 : Sizer_event_handler(browser_win)
53 _browser_win = browser_win;
58 /******************************
59 ** Browser window interface **
60 ******************************/
62 Browser_window::Browser_window(Factory *f,
63 Scout_gfx::Document *initial_content,
65 Area const &max_sz, int attr)
67 _titlebar(f, &title_font), _cont(0)
69 using namespace Mag_gfx;
70 using namespace Scout_gfx;
72 _document = initial_content;
75 Scout_gfx::Event_handler *mev = new Scout_gfx::Mover_event_handler(this);
76 _panel = f->create_panel(this);
77 _panel->event_handler(mev);
79 Scout_gfx::Sky_texture *txt = f->create_sky();
80 txt->generate(Area(512, 512));
82 Scout_gfx::Scroll_pane *sp = new Scout_gfx::Scroll_pane(f);
86 /* init docview and history with initial document */
87 //_docview.texture(_texture);
88 //_docview.voffset(doc_offset());
89 //voffset(doc_offset());
90 _history.add(initial_content);
94 _titlebar.rgba(TITLEBAR_RGBA);
95 _titlebar.text(_document->title);
96 _titlebar.event_handler(mev);
98 _min_sz = _panel->size() + Area(0, 250);
101 /* adopt widgets as child elements */
104 _shadow = f->create_shadow();
108 if (_attr & ATTR_SIZER)
110 _sizer = f->create_icon(SIZER_RGBA, Area(32, 32));
111 _sizer->event_handler(new Browser_sizer_event_handler(this));
113 sp->set_reserved_scrollbar_area(_sizer->min_size());
119 if (_attr & ATTR_TITLEBAR) append(&_titlebar);
121 Scout_gfx::Layout *l = Scout_gfx::Stack_layout::create();
124 Scout_gfx::Layout *n = Scout_gfx::Box_layout::create_vert();
127 n->set_alignment(Align_top);
128 if (_attr & ATTR_TITLEBAR)
129 n->add_item(&_titlebar);
132 n->add_item(_shadow);
134 n->add_item(sp->view_pane_layout_item());
135 Scout_gfx::Layout *vl1 = Scout_gfx::Box_layout::create_vert();
137 sp->set_child_layout(vl1);
140 Scout_gfx::Layout *n2 = Scout_gfx::Box_layout::create_horz();
141 n2->set_alignment(Align_bottom | Align_right);
143 n2->add_item(_sizer);
145 n2->add_item(new Scout_gfx::Spacer_item(Mag_gfx::Horizontal));
147 _content(initial_content);
152 /***********************
153 ** Browser interface **
154 ***********************/
156 Scout_gfx::Parent_widget *Browser_window::_content()
162 void Browser_window::_content(Parent_widget *content)
164 if (!content || (content == _cont))
167 content->fill_cache(view()->pixel_info());
170 _cont_pane->child_layout()->remove_item(_cont);
171 _cont_pane->remove(_cont);
174 _cont_pane->child_layout()->add_item(_cont);
175 _cont_pane->append(_cont);
176 _cont_pane->refresh_geometry();
181 Widget *Browser_window::curr_anchor()
182 { return _cont_pane->find(_cont_pane->child_layout()->geometry().p1() + Point (5, 5)); }