Berkelium

include/berkelium/Window.hpp

Go to the documentation of this file.
00001 /*  Berkelium - Embedded Chromium
00002  *  Window.hpp
00003  *
00004  *  Copyright (c) 2009, Daniel Reiter Horn
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions are
00009  *  met:
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in
00014  *    the documentation and/or other materials provided with the
00015  *    distribution.
00016  *  * Neither the name of Sirikata nor the names of its contributors may
00017  *    be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00021  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00022  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00024  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef _BERKELIUM_WINDOW_HPP_
00034 #define _BERKELIUM_WINDOW_HPP_
00035 
00036 #include <vector>
00037 
00038 #include "berkelium/WeakString.hpp"
00039 
00040 namespace Berkelium {
00041 
00042 class Widget;
00043 class WindowDelegate;
00044 class Context;
00045 
00046 namespace Script{
00047 class Variant;
00048 }
00049 
00050 enum KeyModifier {
00051     SHIFT_MOD      = 1 << 0,
00052     CONTROL_MOD    = 1 << 1,
00053     ALT_MOD        = 1 << 2,
00054     META_MOD       = 1 << 3,
00055     KEYPAD_KEY     = 1 << 4, // If the key is on the keypad (use instead of keypad-specific keycodes)
00056     AUTOREPEAT_KEY = 1 << 5, // If this is not the first KeyPress event for this key
00057     SYSTEM_KEY     = 1 << 6 // if the keypress is a system event (WM_SYS* messages in windows)
00058 };
00059 
00068 class BERKELIUM_EXPORT Window {
00069 protected:
00070     typedef std::vector<Widget*> WidgetList;
00071 
00072 public:
00073     typedef WidgetList::const_iterator BackToFrontIter;
00074     typedef WidgetList::const_reverse_iterator FrontToBackIter;
00075 
00076 protected:
00080     Window ();
00084     Window (const Context*otherContext);
00085 
00086 public:
00093     static Window* create (const Context * context);
00094 
00097     void destroy();
00098 
00102     virtual ~Window();
00103 
00108     virtual Widget* getWidget() const=0;
00109 
00111     inline Context *getContext() const {
00112         return mContext;
00113     }
00114 
00120     void setDelegate(WindowDelegate *delegate) {
00121         mDelegate = delegate;
00122     }
00123 
00127     BackToFrontIter backIter() const {
00128         return mWidgets.begin();
00129     }
00130 
00132     BackToFrontIter backEnd() const {
00133         return mWidgets.end();
00134     }
00135 
00139     FrontToBackIter frontIter() const {
00140         return mWidgets.rbegin();
00141     }
00142 
00144     FrontToBackIter frontEnd() const {
00145         return mWidgets.rend();
00146     }
00147 
00156     Widget *getWidgetAtPoint(int xPos, int yPos, bool returnRootIfOutside=false) const;
00157 
00161     virtual int getId() const = 0;
00162 
00169     virtual void setTransparent(bool istrans)=0;
00170 
00173     virtual void focus()=0;
00174 
00177     virtual void unfocus()=0;
00178 
00183     virtual void mouseMoved(int xPos, int yPos)=0;
00191     virtual void mouseButton(unsigned int buttonID, bool down, int clickCount=1)=0;
00196     virtual void mouseWheel(int xScroll, int yScroll)=0;
00197 
00202     virtual void textEvent(const wchar_t *evt, size_t evtLength)=0;
00203 
00211     virtual void keyEvent(bool pressed, int mods, int vk_code, int scancode)=0;
00212 
00213 
00219     virtual void resize(int width, int height)=0;
00220 
00225     virtual void adjustZoom (int mode)=0;
00226 
00232     virtual void executeJavascript (WideString javascript) = 0;
00233 
00241     virtual void insertCSS (WideString css, WideString elementId) = 0;
00242 
00247     virtual bool navigateTo(URLString url)=0;
00248 
00256     inline bool navigateTo(const char *url, size_t url_length) {
00257         return navigateTo(URLString::point_to(url,url_length));
00258     }
00259 
00261     virtual void refresh() = 0;
00262 
00264     virtual void stop() = 0;
00265 
00267     virtual void goBack() = 0;
00268 
00270     virtual void goForward() = 0;
00271 
00273     virtual bool canGoBack() const = 0;
00274 
00276     virtual bool canGoForward() const = 0;
00277 
00279     virtual void cut()=0;
00280 
00282     virtual void copy()=0;
00283 
00287     virtual void paste()=0;
00288 
00290     virtual void undo()=0;
00291 
00293     virtual void redo()=0;
00294 
00296     virtual void del()=0;
00297 
00299     virtual void selectAll()=0;
00300 
00304     virtual void filesSelected(FileString *files)=0;
00305 
00313     virtual void synchronousScriptReturn(void *handle, const Script::Variant &result)=0;
00314 
00316     virtual void bind(WideString lvalue, const Script::Variant &rvalue)=0;
00317 
00319     virtual void addBindOnStartLoading(WideString lvalue, const Script::Variant &rvalue)=0;
00320 
00322     virtual void addEvalOnStartLoading(WideString script)=0;
00323 
00325     virtual void clearStartLoading()=0;
00326 
00327 protected:
00328     void appendWidget(Widget *wid) {
00329         mWidgets.push_back(wid);
00330     }
00331     void removeWidget(Widget *wid) {
00332         for (WidgetList::iterator it = mWidgets.begin();
00333              it != backEnd();
00334              ++it)
00335         {
00336             if (*it == wid) {
00337                 mWidgets.erase(it);
00338                 return;
00339             }
00340         }
00341     }
00342 
00343 protected:
00344     Context *mContext;
00345     WindowDelegate *mDelegate;
00346 
00347     WidgetList mWidgets;
00348 };
00349 
00350 }
00351 
00352 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated on 22 Nov 2013