00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "StdAfx.h"
00033
00034 #include <vlMFC/MDIWindow.hpp>
00035 #include <vlWin32/Win32Window.hpp>
00036 #include <vlCore/Log.hpp>
00037 #include <vlCore/Say.hpp>
00038 #include <vlCore/Time.hpp>
00039 #include <shellapi.h>
00040
00041 using namespace vl;
00042 using namespace vlMFC;
00043
00044
00045 BEGIN_MESSAGE_MAP(MDIWindow, CView)
00046 ON_WM_CHAR()
00047 ON_WM_CLOSE()
00048 ON_WM_CREATE()
00049 ON_WM_KEYDOWN()
00050 ON_WM_KEYUP()
00051 ON_WM_LBUTTONDBLCLK()
00052 ON_WM_LBUTTONDOWN()
00053 ON_WM_LBUTTONUP()
00054 ON_WM_MBUTTONDBLCLK()
00055 ON_WM_MBUTTONDOWN()
00056 ON_WM_MBUTTONUP()
00057 ON_WM_MOUSEMOVE()
00058 ON_WM_MOUSEWHEEL()
00059 ON_WM_PAINT()
00060 ON_WM_RBUTTONDBLCLK()
00061 ON_WM_RBUTTONDOWN()
00062 ON_WM_RBUTTONUP()
00063 ON_WM_SIZE()
00064 ON_WM_TIMER()
00065 ON_WM_DROPFILES()
00066 ON_WM_DESTROY()
00067 END_MESSAGE_MAP()
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 BOOL MDIWindow::PreCreateWindow(CREATESTRUCT & cs)
00078 {
00079 cs.dwExStyle |= WS_EX_ACCEPTFILES;
00080 cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
00081 return CView::PreCreateWindow(cs);
00082 }
00083
00084 MDIWindow::~MDIWindow()
00085 {
00086 dispatchDestroyEvent();
00087 }
00088
00089 void MDIWindow::destroyGLContext()
00090 {
00091
00092 if (hwnd())
00093 {
00094 if (mHGLRC)
00095 {
00096 if ( wglDeleteContext(mHGLRC) == FALSE )
00097 {
00098 MessageBox( L"OpenGL context creation failed.\n"
00099 L"The handle either doesn't specify a valid context or the context is being used by another thread.", L" MDIWindow::destroyGLContext() error!", MB_OK);
00100 }
00101 mHGLRC = NULL;
00102 }
00103
00104 if (mHDC)
00105 {
00106 DeleteDC(mHDC);
00107 mHDC = NULL;
00108 }
00109 }
00110 }
00111
00112 void MDIWindow::OnDestroy()
00113 {
00114 dispatchDestroyEvent();
00115 destroyGLContext();
00116 }
00117
00118 void MDIWindow::OnPaint()
00119 {
00120 if (hwnd() && hdc() && hglrc())
00121 dispatchRunEvent();
00122 ValidateRect(NULL);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void MDIWindow::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
00138 {
00139 unsigned short unicode_out = 0;
00140 vl::EKey key_out = Key_None;
00141 vlWin32::translateKeyEvent(nChar, nFlags, unicode_out, key_out);
00142 dispatchKeyPressEvent(unicode_out, key_out);
00143 }
00144
00145 void MDIWindow::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
00146 {
00147 unsigned short unicode_out = 0;
00148 vl::EKey key_out = Key_None;
00149 vlWin32::translateKeyEvent(nChar, nFlags, unicode_out, key_out);
00150 dispatchKeyReleaseEvent(unicode_out, key_out);
00151 }
00152
00153 void MDIWindow::countAndCapture()
00154 {
00155 mMouseDownCount++;
00156 if (mMouseDownCount == 1)
00157 ::SetCapture(hwnd());
00158 }
00159
00160 void MDIWindow::countAndRelease()
00161 {
00162 mMouseDownCount--;
00163 if (mMouseDownCount <= 0)
00164 {
00165 ReleaseCapture();
00166 mMouseDownCount = 0;
00167 }
00168 }
00169
00170 void MDIWindow::OnLButtonDblClk(UINT nFlags, CPoint point)
00171 {
00172 countAndCapture();
00173 dispatchMouseDownEvent( LeftButton, point.x, point.y );
00174 }
00175
00176 void MDIWindow::OnLButtonDown(UINT nFlags, CPoint point)
00177 {
00178 countAndCapture();
00179 dispatchMouseDownEvent( LeftButton, point.x, point.y );
00180 }
00181
00182 void MDIWindow::OnLButtonUp(UINT nFlags, CPoint point)
00183 {
00184 countAndRelease();
00185 dispatchMouseUpEvent( LeftButton, point.x, point.y );
00186 }
00187
00188 void MDIWindow::OnMButtonDblClk(UINT nFlags, CPoint point)
00189 {
00190 countAndCapture();
00191 dispatchMouseDownEvent( MiddleButton, point.x, point.y );
00192 }
00193
00194 void MDIWindow::OnMButtonDown(UINT nFlags, CPoint point)
00195 {
00196 countAndCapture();
00197 dispatchMouseDownEvent( MiddleButton, point.x, point.y );
00198 }
00199
00200 void MDIWindow::OnMButtonUp(UINT nFlags, CPoint point)
00201 {
00202 countAndRelease();
00203 dispatchMouseUpEvent( MiddleButton, point.x, point.y );
00204 }
00205
00206 void MDIWindow::OnMouseMove(UINT nFlags, CPoint point)
00207 {
00208 dispatchMouseMoveEvent( point.x, point.y );
00209 }
00210
00211 BOOL MDIWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
00212 {
00213 dispatchMouseWheelEvent (zDelta/120);
00214 return FALSE;
00215 }
00216
00217 void MDIWindow::OnRButtonDblClk(UINT nFlags, CPoint point)
00218 {
00219 countAndCapture();
00220 dispatchMouseDownEvent( RightButton, point.x, point.y );
00221 }
00222
00223 void MDIWindow::OnRButtonDown(UINT nFlags, CPoint point)
00224 {
00225 countAndCapture();
00226 dispatchMouseDownEvent( RightButton, point.x, point.y );
00227 }
00228
00229 void MDIWindow::OnRButtonUp(UINT nFlags, CPoint point)
00230 {
00231 countAndRelease();
00232 dispatchMouseUpEvent( RightButton, point.x, point.y );
00233 }
00234
00235 void MDIWindow::OnDropFiles(HDROP hDrop)
00236 {
00237 int count = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0);
00238 const int char_count = 1024;
00239 std::vector<String> files;
00240 for(int i=0; i<count; ++i)
00241 {
00242 wchar_t file_path[char_count];
00243 memset(file_path, 0, char_count);
00244 DragQueryFile(hDrop,i,file_path,char_count);
00245 files.push_back(file_path);
00246 }
00247 dispatchFileDroppedEvent(files);
00248 }
00249
00250 void MDIWindow::OnSize (UINT nType, int cx, int cy)
00251 {
00252 CWnd::OnSize(nType, cx, cy);
00253
00254 if (0 >= cx || 0 >= cy || nType == SIZE_MINIMIZED)
00255 return;
00256
00257 framebuffer()->setWidth(cx);
00258 framebuffer()->setHeight(cy);
00259 dispatchResizeEvent(cx, cy);
00260 }
00261