hipp  1.0
hipp/gui/WxWidgetsWindow.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2011 Certec, Lund University, Sweden
00003 
00004     This file is part of HIPP.
00005 
00006     HIPP is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     HIPP is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with HIPP.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019  */
00020 
00027 #ifndef __WXWIDGETSWINDOW_H__
00028 #define __WXWIDGETSWINDOW_H__
00029 
00030 #include <wx/wx.h>
00031 #include <H3D/H3DWindowNode.h>
00032 #include <wx/glcanvas.h>
00033 #include <wx/dnd.h>
00034 #if !wxUSE_GLCANVAS
00035 #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
00036 #endif
00037 
00038 // Define this if you want the gl context be created explicitly. This does
00039 // not work under OSX v2.8 wxWidgets and does not really add anything unless
00040 // you want to share rendering contexts. So by default we do not use it.
00041 //#define USE_EXPLICIT_GLCONTEXT
00042 
00043 namespace H3D {
00044 
00052 class WxWidgetsWindow: public H3DWindowNode {
00053 public:
00054 
00055         class MyWxGLCanvas: public wxGLCanvas {
00056         public:
00057                 MyWxGLCanvas(WxWidgetsWindow *_myOwner, wxWindow* _parent,
00058                                 wxGLContext *shared_context, 
00059                 wxWindowID _id, const wxPoint& _pos, const wxSize& _size, 
00060                 int* _attribList = 0, long _style = 0, 
00061                 const wxString& _name = _("Drawing window"),
00062                                 const wxPalette& _palette = wxNullPalette);
00063 
00064                 MyWxGLCanvas(WxWidgetsWindow *_myOwner, wxWindow* _parent,
00065                                 wxWindowID _id, const wxPoint& _pos, const wxSize& _size,
00066                                 int* _attribList = 0, long _style = 0, 
00067                 const wxString& _name = _("Drawing window"), 
00068                 const wxPalette& _palette =     wxNullPalette);
00069 
00070                 void OnSize(wxSizeEvent& event);
00071                 void OnPaint(wxPaintEvent& WXUNUSED(event));
00072                 void OnEraseBackground(wxEraseEvent& WXUNUSED(event));
00073                 void OnIdle(wxIdleEvent& event);
00074 #ifndef WIN32
00075                 void OnKeyDown(wxKeyEvent& event);
00076                 void OnKeyUp(wxKeyEvent& event);
00077                 void OnCharDown(wxKeyEvent& event);
00078                 void onLeftMouseButtonDown(wxMouseEvent & event);
00079                 void onLeftMouseButtonUp(wxMouseEvent & event);
00080                 void onMiddleMouseButtonDown(wxMouseEvent & event);
00081                 void onMiddleMouseButtonUp(wxMouseEvent & event);
00082                 void onRightMouseButtonDown(wxMouseEvent & event);
00083                 void onRightMouseButtonUp(wxMouseEvent & event);
00084                 void onMouseMotion(wxMouseEvent & event);
00085                 void onMouseWheelRotation(wxMouseEvent & event);
00086 #endif
00087 
00088                 virtual bool ProcessEvent(wxCommandEvent &event);
00089 
00090         protected:
00091                 WxWidgetsWindow * myOwner;
00092         DECLARE_EVENT_TABLE()
00093         };
00094 
00096         WxWidgetsWindow(wxWindow *_theParent = 0, Inst<SFInt32> _width = 0, Inst<
00097                         SFInt32> _height = 0, Inst<SFBool> _fullscreen = 0,
00098                         Inst<SFBool> _mirrored = 0, Inst<RenderMode> _renderMode = 0, Inst<
00099                                         SFViewpoint> _viewpoint = 0, Inst<SFInt32> _posX = 0, Inst<
00100                                         SFInt32> _posY = 0, Inst<SFBool> _manualCursorControl = 0,
00101                         Inst<SFString> _cursorType = 0);
00102 
00104         ~WxWidgetsWindow() {
00105                 if (!have_parent) {
00106                         theWindow->Destroy();
00107                 }
00108         }
00109 
00111         virtual void swapBuffers();
00112 
00114         virtual void initWindow();
00115 
00117         virtual void initWindowHandler() {
00118         }
00119 
00121         virtual void setFullscreen(bool fullscreen);
00122 
00124         virtual void makeWindowActive();
00125 
00127         static H3DNodeDatabase database;
00128 
00129         typedef void (*OnDropFileFunc)(wxCoord x, wxCoord y, const wxArrayString&,
00130                         void *);
00131 
00134         void onFileDraggedAndDroppedFunction(OnDropFileFunc func, void * arg = NULL) {
00135                 drag_file_func = func;
00136                 drag_file_func_arg = arg;
00137         }
00138 
00139         inline MyWxGLCanvas* getGlCanvas(){
00140                 return theWxGLCanvas;
00141         }
00142 
00143 protected:
00144 
00148         virtual int setCursorType(const std::string & cursor_type);
00149 
00158         string getCursorForMode(const string &mode);
00159 
00162         void getSupportedCursorsTypes(vector<string> &types);
00163 
00164 #if wxUSE_DRAG_AND_DROP
00165 
00166         class DragAndDropFile: public wxFileDropTarget {
00167         public:
00168                 DragAndDropFile(WxWidgetsWindow *_owner) {
00169                         owner = _owner;
00170                 }
00171 
00172                 virtual bool OnDropFiles(wxCoord x, wxCoord y,
00173                                 const wxArrayString& filenames) {
00174                         if (owner->drag_file_func) {
00175                                 owner->drag_file_func(x, y, filenames,
00176                                                 owner->drag_file_func_arg);
00177                         }
00178                         return true;
00179                 }
00180         protected:
00181                 WxWidgetsWindow *owner;
00182         };
00183 #endif
00184 
00185         friend class DragAndDropFile;
00186         OnDropFileFunc drag_file_func;
00187         void *drag_file_func_arg;
00188 
00189         bool is_initialized;
00190         bool have_parent;
00191         wxWindow * theWindow;
00192         MyWxGLCanvas * theWxGLCanvas;
00193 #ifdef USE_EXPLICIT_GLCONTEXT
00194         wxGLContext * theWxGLContext;
00195 #endif
00196         bool last_fullscreen;
00197 };
00198 }
00199 
00200 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines