Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00053
00055 #ifndef __WXWIDGETSWINDOW_H__
00056 #define __WXWIDGETSWINDOW_H__
00057
00058 #include <wx/wx.h>
00059 #include <H3D/H3DWindowNode.h>
00060 #include <wx/glcanvas.h>
00061 #include <wx/dnd.h>
00062 #if !wxUSE_GLCANVAS
00063 #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
00064 #endif
00065
00066
00067
00068
00069
00070
00071 namespace H3D {
00072
00080 class WxWidgetsWindow: public H3DWindowNode {
00081 public:
00082
00083 class MyWxGLCanvas: public wxGLCanvas {
00084 public:
00085 MyWxGLCanvas(WxWidgetsWindow *_myOwner, wxWindow* _parent,
00086 wxGLContext *shared_context,
00087 wxWindowID _id, const wxPoint& _pos, const wxSize& _size,
00088 int* _attribList = 0, long _style = 0,
00089 const wxString& _name = _("Drawing window"),
00090 const wxPalette& _palette = wxNullPalette);
00091
00092 MyWxGLCanvas(WxWidgetsWindow *_myOwner, wxWindow* _parent,
00093 wxWindowID _id, const wxPoint& _pos, const wxSize& _size,
00094 int* _attribList = 0, long _style = 0,
00095 const wxString& _name = _("Drawing window"),
00096 const wxPalette& _palette = wxNullPalette);
00097
00098 void OnSize(wxSizeEvent& event);
00099 void OnPaint(wxPaintEvent& WXUNUSED(event));
00100 void OnEraseBackground(wxEraseEvent& WXUNUSED(event));
00101 void OnIdle(wxIdleEvent& event);
00102 #ifndef WIN32
00103 void OnKeyDown(wxKeyEvent& event);
00104 void OnKeyUp(wxKeyEvent& event);
00105 void OnCharDown(wxKeyEvent& event);
00106 void onLeftMouseButtonDown(wxMouseEvent & event);
00107 void onLeftMouseButtonUp(wxMouseEvent & event);
00108 void onMiddleMouseButtonDown(wxMouseEvent & event);
00109 void onMiddleMouseButtonUp(wxMouseEvent & event);
00110 void onRightMouseButtonDown(wxMouseEvent & event);
00111 void onRightMouseButtonUp(wxMouseEvent & event);
00112 void onMouseMotion(wxMouseEvent & event);
00113 void onMouseWheelRotation(wxMouseEvent & event);
00114 #endif
00115
00116 virtual bool ProcessEvent(wxCommandEvent &event);
00117
00118 protected:
00119 WxWidgetsWindow * myOwner;
00120 DECLARE_EVENT_TABLE()
00121 };
00122
00124 WxWidgetsWindow(wxWindow *_theParent = 0, Inst<SFInt32> _width = 0, Inst<
00125 SFInt32> _height = 0, Inst<SFBool> _fullscreen = 0,
00126 Inst<SFBool> _mirrored = 0, Inst<RenderMode> _renderMode = 0, Inst<
00127 SFViewpoint> _viewpoint = 0, Inst<SFInt32> _posX = 0, Inst<
00128 SFInt32> _posY = 0, Inst<SFBool> _manualCursorControl = 0,
00129 Inst<SFString> _cursorType = 0);
00130
00132 ~WxWidgetsWindow() {
00133 if (!have_parent) {
00134 theWindow->Destroy();
00135 }
00136 }
00137
00139 virtual void swapBuffers();
00140
00142 virtual void initWindow();
00143
00145 virtual void initWindowHandler() {
00146 }
00147
00149 virtual void setFullscreen(bool fullscreen);
00150
00152 virtual void makeWindowActive();
00153
00155 static H3DNodeDatabase database;
00156
00157 typedef void (*OnDropFileFunc)(wxCoord x, wxCoord y, const wxArrayString&,
00158 void *);
00159
00162 void onFileDraggedAndDroppedFunction(OnDropFileFunc func, void * arg = NULL) {
00163 drag_file_func = func;
00164 drag_file_func_arg = arg;
00165 }
00166
00167 inline MyWxGLCanvas* getGlCanvas(){
00168 return theWxGLCanvas;
00169 }
00170
00171 protected:
00172
00176 virtual int setCursorType(const std::string & cursor_type);
00177
00186 string getCursorForMode(const string &mode);
00187
00190 void getSupportedCursorsTypes(vector<string> &types);
00191
00192 #if wxUSE_DRAG_AND_DROP
00193
00194 class DragAndDropFile: public wxFileDropTarget {
00195 public:
00196 DragAndDropFile(WxWidgetsWindow *_owner) {
00197 owner = _owner;
00198 }
00199
00200 virtual bool OnDropFiles(wxCoord x, wxCoord y,
00201 const wxArrayString& filenames) {
00202 if (owner->drag_file_func) {
00203 owner->drag_file_func(x, y, filenames,
00204 owner->drag_file_func_arg);
00205 }
00206 return true;
00207 }
00208 protected:
00209 WxWidgetsWindow *owner;
00210 };
00211 #endif
00212
00213 friend class DragAndDropFile;
00214 OnDropFileFunc drag_file_func;
00215 void *drag_file_func_arg;
00216
00217 bool is_initialized;
00218 bool have_parent;
00219 wxWindow * theWindow;
00220 MyWxGLCanvas * theWxGLCanvas;
00221 #ifdef USE_EXPLICIT_GLCONTEXT
00222 wxGLContext * theWxGLContext;
00223 #endif
00224 bool last_fullscreen;
00225 };
00226 }
00227
00228 #endif