Ginga  0.13.6
 All Classes Namespaces Functions Variables
BerkeliumHandler.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef BerkeliumHandler_h_
51 #define BerkeliumHandler_h_
52 
53 #include "mb/IInputManager.h"
54 #include "mb/interface/CodeMap.h"
55 #include "mb/interface/IWindow.h"
56 #include "mb/interface/IInputEventListener.h"
57 
58 #include "mb/ILocalScreenManager.h"
59 #include "mb/interface/IWindow.h"
60 using namespace ::br::pucrio::telemidia::ginga::core::mb;
61 
62 #include "system/thread/Thread.h"
63 using namespace ::br::pucrio::telemidia::ginga::core::system::thread;
64 
65 #include "berkelium/Berkelium.hpp"
66 #include "berkelium/Window.hpp"
67 #include "berkelium/WindowDelegate.hpp"
68 #include "berkelium/Context.hpp"
69 
70 #include <stdio.h>
71 #include <sys/types.h>
72 #include <sstream>
73 #include <iostream>
74 #include <memory>
75 
76 using namespace Berkelium;
77 
78 namespace br {
79 namespace pucrio {
80 namespace telemidia {
81 namespace ginga {
82 namespace core {
83 namespace player {
85  public WindowDelegate,
86  public IInputEventListener,
87  public IMotionEventListener {
88 
89  private:
90  static map<int, int> fromGingaToBklm;
91  std::string mURL;
92  ILocalScreenManager* dm;
93  GingaScreenID myScreen;
94  IInputManager* im;
95  ISurface* surface;
96  int xOffset, yOffset;
97  int x, y;
98  int w, h;
99  Context* context;
100  std::auto_ptr<Window> bWindow;
101  bool isValid;
102  bool mouseClick;
103  bool mouseMoved;
104  bool textEvent;
105  int keyCode;
106  static int callCount;
107  bool needs_full_refresh;
108  unsigned char* scroll_buffer;
109 
110  pthread_mutex_t sMutex; //surface mutex
111 
112  public:
114  GingaScreenID myScreen, int x, int y, int w, int h);
115 
116  virtual ~BerkeliumHandler();
117 
118  private:
119  void initInputMap();
120 
121  public:
122  void stop();
123  void setKeyHandler(bool handler);
124 
125  void setContext(Context* context);
126  void setWindow(std::auto_ptr<Window> window);
127  void getSize(int* w, int* h);
128  void setBounds(int x, int y, int w, int h);
129  void setUrl(string url);
130  string getUrl();
131  ISurface* getSurface();
132 
133  void updateEvents();
134 
135  bool userEventReceived(IInputEvent* ev);
136  bool motionEventReceived(int x, int y, int z);
137 
138  virtual void onAddressBarChanged(Window *win, URLString newURL);
139  virtual void onStartLoading(Window *win, URLString newURL);
140  void onLoadingStateChanged(Window *win, bool isLoading);
141  virtual void onLoad(Window *win);
142  virtual void onLoadError(Window *win, WideString error);
143  virtual void onResponsive(Window *win);
144  virtual void onUnresponsive(Window *win);
145 
146  private:
147  bool mapOnPaintToTexture(
148  Berkelium::Window *wini,
149  const unsigned char* bitmap_in, const Berkelium::Rect& bitmap_rect,
150  size_t num_copy_rects, const Berkelium::Rect *copy_rects,
151  int dx, int dy,
152  const Berkelium::Rect& scroll_rect,
153  unsigned int dest_texture_width,
154  unsigned int dest_texture_height,
155  bool ignore_partial,
156  unsigned char* scroll_buffer);
157 
158  ISurface* createRenderedSurface(string fileName);
159 
160  string createFile(
161  const unsigned char *sourceBuffer,
162  int width, int height);
163 
164  public:
165  virtual void onPaint(
166  Window *wini,
167  const unsigned char *bitmap_in,
168  const Rect &bitmap_rect,
169  size_t num_copy_rects,
170  const Rect *copy_rects,
171  int dx,
172  int dy,
173  const Rect &scroll_rect);
174 
175  virtual void onCrashed(Window *win);
176  virtual void onCreatedWindow(
177  Window *win, Window *newWindow, const Rect &initialRect);
178  virtual void onExternalHost(
179  Window *win,
180  WideString message,
181  URLString origin,
182  URLString target);
183 
184  virtual void onPaintPluginTexture(
185  Window *win,
186  void* sourceGLTexture,
187  const std::vector<Rect> srcRects,
188  const Rect &destRect);
189 
190  virtual void onWidgetCreated(
191  Window *win, Widget *newWidget, int zIndex);
192 
193  virtual void onWidgetDestroyed(Window *win, Widget *newWidget);
194 
195  virtual void onWidgetResize(
196  Window *win, Widget *wid, int newWidth, int newHeight);
197 
198  virtual void onWidgetMove(Window *win, Widget *wid, int newX, int newY);
199 
200  virtual void onWidgetPaint(
201  Window *win,
202  Widget *wid,
203  const unsigned char *sourceBuffer,
204  const Rect &rect,
205  size_t num_copy_rects,
206  const Rect *copy_rects,
207  int dx,
208  int dy,
209  const Rect &scrollRect);
210  };
211 }
212 }
213 }
214 }
215 }
216 }
217 
218 #endif /*BerkeliumHandler_h_*/