]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout/lib/src/browser.h
8d075988a9c8d06be1e0db4227cd4fcc1cf22701
[l4.git] / l4 / pkg / scout / lib / src / browser.h
1 /*
2  * \brief   Browser interface
3  * \date    2005-11-03
4  * \author  Norman Feske <norman.feske@genode-labs.com>
5  */
6
7 /*
8  * Copyright (C) 2005-2009
9  * Genode Labs, Feske & Helmuth Systementwicklung GbR
10  *
11  * This file is part of the Genode OS framework, which is distributed
12  * under the terms of the GNU General Public License version 2.
13  */
14
15 #ifndef _BROWSER_H_
16 #define _BROWSER_H_
17
18 #include <l4/scout-gfx/document>
19 #include <l4/scout-gfx/doc/link>
20
21 #include "browser_if.h"
22 #include "history.h"
23
24 using Mag_gfx::Area;
25 using Mag_gfx::Rect;
26 using Mag_gfx::Point;
27 using Scout_gfx::Widget;
28
29 extern Scout_gfx::Document *create_about();
30
31 class Scout_browser : public Scout_gfx::Browser, public Browser_if
32 {
33 protected:
34
35   Scout_gfx::Document *_document;
36   Scout_gfx::Document *_about;
37   History   _history;
38   int       _voffset;
39
40   /**
41    * Define content to present in browser window
42    */
43   virtual void _content(Scout_gfx::Parent_widget *content) = 0;
44
45   /**
46    * Request current content
47    */
48   virtual Scout_gfx::Parent_widget *_content() = 0;
49
50 public:
51
52   /**
53    * Constructor
54    */
55   explicit Scout_browser(int voffset = 0)
56   : _document(0), _about(create_about()), _voffset(voffset)
57   {}
58
59   virtual ~Scout_browser() { }
60
61   void voffset(int voffset)
62   { _voffset = voffset; }
63
64   /**
65    * Travel backward in history
66    *
67    * \retval 1 success
68    * \retval 0 end of history is reached
69    */
70   virtual bool go_backward()
71   {
72     _history.assign(curr_anchor());
73     if (!_history.go(History::BACKWARD)) return 0;
74     go_to(_history.curr(), 0);
75     return 1;
76   }
77
78   /**
79    * Follow history forward
80    *
81    * \retval 1 success,
82    * \retval 0 end of history is reached
83    */
84   virtual bool go_forward()
85   {
86     _history.assign(curr_anchor());
87     if (!_history.go(History::FORWARD)) return 0;
88     go_to(_history.curr(), 0);
89     return 1;
90   }
91
92   /**
93    * Follow specified link location
94    *
95    * \param add_history  if set to 1, add new location to history
96    */
97   virtual void go_to(Widget *anchor, int add_history = 1)
98   {
99     if (!anchor) return;
100
101     if (add_history)
102       {
103         _history.assign(curr_anchor());
104         _history.add(anchor);
105       }
106
107     Scout_gfx::Parent_widget *new_content = Scout_gfx::Anchor::chapter(anchor);
108     if (new_content)
109       _content(new_content);
110
111     //ypos(0);
112     //ypos(_ypos - anchor->abs().y() + _voffset);
113
114     if (new_content)
115       {
116         //new_content->curr_link_destination(0);
117         new_content->refresh();
118       }
119   }
120
121   /**
122    * Get current anchor
123    *
124    * The current anchor is the element that is visible at the
125    * top of the browser window. It depends on the scroll position.
126    * We need to store these elements in the history to recover
127    * the right viewport on the history entries even after
128    * reformatting the document.
129    */
130   virtual Widget *curr_anchor() = 0;
131
132   /**
133    * Display table of contents
134    */
135   bool go_toc() { go_to(_document->toc, 1); return 1; }
136
137   /**
138    * Go to title page
139    */
140   bool go_home() { go_to(_document); return 1; }
141
142   /**
143    * Go to about page
144    */
145   bool go_about() { go_to(_about); return 1; }
146 };
147
148
149 #endif /* _BROWSER_H_ */