]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout/lib/src/browser.h
update
[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   /**
42    * Define content to present in browser window
43    */
44   virtual void _content(Scout_gfx::Parent_widget *content) = 0;
45
46   /**
47    * Request current content
48    */
49   virtual Scout_gfx::Parent_widget *_content() = 0;
50
51 public:
52
53   /**
54    * Constructor
55    */
56   explicit Scout_browser(int voffset = 0)
57   : _document(0), _about(create_about()), _voffset(voffset)
58   {}
59
60   virtual ~Scout_browser() { }
61
62   char const *title() const { return _document->title; }
63
64   void voffset(int voffset)
65   { _voffset = voffset; }
66
67   /**
68    * Travel backward in history
69    *
70    * \retval 1 success
71    * \retval 0 end of history is reached
72    */
73   virtual bool go_backward()
74   {
75     _history.assign(curr_anchor());
76     if (!_history.go(History::BACKWARD)) return 0;
77     go_to(_history.curr(), 0);
78     return 1;
79   }
80
81   /**
82    * Follow history forward
83    *
84    * \retval 1 success,
85    * \retval 0 end of history is reached
86    */
87   virtual bool go_forward()
88   {
89     _history.assign(curr_anchor());
90     if (!_history.go(History::FORWARD)) return 0;
91     go_to(_history.curr(), 0);
92     return 1;
93   }
94
95   /**
96    * Follow specified link location
97    *
98    * \param add_history  if set to 1, add new location to history
99    */
100   virtual void go_to(Widget *anchor, int add_history = 1)
101   {
102     if (!anchor) return;
103
104     if (add_history)
105       {
106         _history.assign(curr_anchor());
107         _history.add(anchor);
108       }
109
110     Scout_gfx::Parent_widget *new_content = Scout_gfx::Anchor::chapter(anchor);
111     if (new_content)
112       _content(new_content);
113
114     //ypos(0);
115     //ypos(_ypos - anchor->abs().y() + _voffset);
116
117     if (new_content)
118       {
119         //new_content->curr_link_destination(0);
120         new_content->refresh();
121       }
122   }
123
124   /**
125    * Get current anchor
126    *
127    * The current anchor is the element that is visible at the
128    * top of the browser window. It depends on the scroll position.
129    * We need to store these elements in the history to recover
130    * the right viewport on the history entries even after
131    * reformatting the document.
132    */
133   virtual Widget *curr_anchor() = 0;
134
135   /**
136    * Display table of contents
137    */
138   bool go_toc() { go_to(_document->toc, 1); return 1; }
139
140   /**
141    * Go to title page
142    */
143   bool go_home() { go_to(_document); return 1; }
144
145   /**
146    * Go to about page
147    */
148   bool go_about() { go_to(_about); return 1; }
149 };
150
151
152 #endif /* _BROWSER_H_ */