ChildView.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // ChildView.cpp : implementation of the CChildView class
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "ChildView.h"
00028 #include "MainFrm.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00037 // CChildView
00038 
00039 CChildView::CChildView() : m_vrect(0,0,0,0)
00040 {
00041         m_lastlmdowntime = 0;
00042         m_lastlmdownpoint.SetPoint(0, 0);
00043 
00044         LoadLogo();
00045 }
00046 
00047 CChildView::~CChildView()
00048 {
00049 }
00050 
00051 BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
00052 {
00053         if(!CWnd::PreCreateWindow(cs))
00054                 return FALSE;
00055 
00056         cs.style &= ~WS_BORDER;
00057         cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
00058                 ::LoadCursor(NULL, IDC_HAND), HBRUSH(COLOR_WINDOW+1), NULL);
00059 
00060         return TRUE;
00061 }
00062 
00063 BOOL CChildView::PreTranslateMessage(MSG* pMsg)
00064 {
00065         if(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MYMOUSELAST)
00066         {
00067                 CWnd* pParent = GetParent();
00068                 CPoint p(pMsg->lParam);
00069                 ::MapWindowPoints(pMsg->hwnd, pParent->m_hWnd, &p, 1);
00070 
00071                 bool fDblClick = false;
00072 
00073                 bool fInteractiveVideo = ((CMainFrame*)AfxGetMainWnd())->IsInteractiveVideo();
00074 /*
00075                 if(fInteractiveVideo)
00076                 {
00077                         if(pMsg->message == WM_LBUTTONDOWN)
00078                         {
00079                                 if((pMsg->time - m_lastlmdowntime) <= GetDoubleClickTime()
00080                                 && abs(pMsg->pt.x - m_lastlmdownpoint.x) <= GetSystemMetrics(SM_CXDOUBLECLK)
00081                                 && abs(pMsg->pt.y - m_lastlmdownpoint.y) <= GetSystemMetrics(SM_CYDOUBLECLK))
00082                                 {
00083                                         fDblClick = true;
00084                                         m_lastlmdowntime = 0;
00085                                         m_lastlmdownpoint.SetPoint(0, 0);
00086                                 }
00087                                 else
00088                                 {
00089                                         m_lastlmdowntime = pMsg->time;
00090                                         m_lastlmdownpoint = pMsg->pt;
00091                                 }
00092                         }
00093                         else if(pMsg->message == WM_LBUTTONDBLCLK)
00094                         {
00095                                 m_lastlmdowntime = pMsg->time;
00096                                 m_lastlmdownpoint = pMsg->pt;
00097                         }
00098                 }
00099 */
00100                 if((pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP || pMsg->message == WM_MOUSEMOVE)
00101                 && fInteractiveVideo)
00102                 {
00103                         if(pMsg->message == WM_MOUSEMOVE)
00104                         {
00105                                 pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
00106                         }
00107 
00108                         if(fDblClick)
00109                         {
00110                                 pParent->PostMessage(WM_LBUTTONDOWN, pMsg->wParam, MAKELPARAM(p.x, p.y));
00111                                 pParent->PostMessage(WM_LBUTTONDBLCLK, pMsg->wParam, MAKELPARAM(p.x, p.y));
00112                         }
00113                 }
00114                 else
00115                 {
00116                         pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
00117             return TRUE;
00118                 }
00119         }
00120 
00121         return CWnd::PreTranslateMessage(pMsg);
00122 }
00123 
00124 void CChildView::SetVideoRect(CRect r)
00125 {
00126         m_vrect = r;
00127 
00128         Invalidate();
00129 }
00130 
00131 void CChildView::LoadLogo()
00132 {
00133         AppSettings& s = AfxGetAppSettings();
00134 
00135         CAutoLock cAutoLock(&m_csLogo);
00136 
00137         m_logo.Destroy();
00138 
00139         if(s.logoext)
00140         {
00141                 if(AfxGetAppSettings().fXpOrBetter)
00142                         m_logo.Load(s.logofn);
00143                 else if(HANDLE h = LoadImage(NULL, s.logofn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE))
00144                         m_logo.Attach((HBITMAP)h); // win9x bug: Inside Attach GetObject() will return all zeros in DIBSECTION and silly CImage uses that to init width, height, bpp, ... so we can't use CImage::Draw later
00145         }
00146 
00147         if(m_logo.IsNull())
00148         {
00149                 m_logo.LoadFromResource(AfxGetInstanceHandle(), s.logoid);
00150         }
00151 
00152         if(m_hWnd) Invalidate();
00153 }
00154 
00155 CSize CChildView::GetLogoSize()
00156 {
00157         CSize ret(0,0);
00158         if(!m_logo.IsNull())
00159                 ret.SetSize(m_logo.GetWidth(), m_logo.GetHeight());
00160         return ret;
00161 }
00162 
00163 IMPLEMENT_DYNAMIC(CChildView, CWnd)
00164 
00165 BEGIN_MESSAGE_MAP(CChildView, CWnd)
00166         //{{AFX_MSG_MAP(CChildView)
00167         ON_WM_PAINT()
00168         ON_WM_ERASEBKGND()
00169         ON_WM_SIZE()
00170         ON_WM_WINDOWPOSCHANGED()
00171         ON_COMMAND_EX(ID_PLAY_PLAYPAUSE, OnPlayPlayPauseStop)
00172         ON_COMMAND_EX(ID_PLAY_PLAY, OnPlayPlayPauseStop)
00173         ON_COMMAND_EX(ID_PLAY_PAUSE, OnPlayPlayPauseStop)
00174         ON_COMMAND_EX(ID_PLAY_STOP, OnPlayPlayPauseStop)
00175         ON_WM_SETCURSOR()
00176         ON_WM_NCCALCSIZE()
00177         ON_WM_NCPAINT()
00178         //}}AFX_MSG_MAP
00179 END_MESSAGE_MAP()
00180 
00181 
00182 
00183 // CChildView message handlers
00184 
00185 void CChildView::OnPaint() 
00186 {
00187         CPaintDC dc(this); // device context for painting
00188 
00189         ((CMainFrame*)GetParentFrame())->RepaintVideo();
00190 
00191         // Do not call CWnd::OnPaint() for painting messages
00192 }
00193 
00194 BOOL CChildView::OnEraseBkgnd(CDC* pDC)
00195 {
00196         CRect r;
00197 
00198         CAutoLock cAutoLock(&m_csLogo);
00199 
00200         if(((CMainFrame*)GetParentFrame())->IsSomethingLoaded())
00201         {
00202                 pDC->ExcludeClipRect(m_vrect);
00203         }
00204         else if(!m_logo.IsNull() /*&& ((CMainFrame*)GetParentFrame())->IsPlaylistEmpty()*/)
00205         {
00206                 BITMAP bm;
00207                 GetObject(m_logo, sizeof(bm), &bm);
00208 
00209                 GetClientRect(r);
00210                 int w = min(bm.bmWidth, r.Width());
00211                 int h = min(abs(bm.bmHeight), r.Height());
00212 //              int w = min(m_logo.GetWidth(), r.Width());
00213 //              int h = min(m_logo.GetHeight(), r.Height());
00214                 int x = (r.Width() - w) / 2;
00215                 int y = (r.Height() - h) / 2;
00216                 r = CRect(CPoint(x, y), CSize(w, h));
00217 
00218                 int oldmode = pDC->SetStretchBltMode(STRETCH_HALFTONE);
00219                 m_logo.StretchBlt(*pDC, r, CRect(0,0,bm.bmWidth,abs(bm.bmHeight)));
00220 //              m_logo.Draw(*pDC, r);
00221                 pDC->SetStretchBltMode(oldmode);
00222 
00223                 pDC->ExcludeClipRect(r);
00224         }
00225 
00226         GetClientRect(r);
00227         pDC->FillSolidRect(r, 0);
00228 
00229         return TRUE;
00230 }
00231 
00232 void CChildView::OnSize(UINT nType, int cx, int cy)
00233 {
00234         CWnd::OnSize(nType, cx, cy);
00235 
00236         ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
00237 }
00238 
00239 void CChildView::OnWindowPosChanged(WINDOWPOS* lpwndpos)
00240 {
00241         CWnd::OnWindowPosChanged(lpwndpos);
00242 
00243         ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
00244 }
00245 
00246 BOOL CChildView::OnPlayPlayPauseStop(UINT nID)
00247 {
00248         if(nID == ID_PLAY_STOP) SetVideoRect();
00249         return FALSE;
00250 }
00251 
00252 BOOL CChildView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00253 {
00254         if(((CMainFrame*)GetParentFrame())->m_fHideCursor)
00255         {
00256                 SetCursor(NULL);
00257                 return TRUE;
00258         }
00259 
00260         return CWnd::OnSetCursor(pWnd, nHitTest, message);
00261 }
00262 
00263 void CChildView::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
00264 {
00265         if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow()) 
00266         {
00267                 InflateRect(&lpncsp->rgrc[0], -1, -1);
00268         }
00269 
00270         CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
00271 }
00272 
00273 void CChildView::OnNcPaint()
00274 {
00275         if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow()) 
00276         {
00277                 CRect r;
00278                 GetWindowRect(r);
00279                 r.OffsetRect(-r.left, -r.top);
00280 
00281                 CWindowDC(this).Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); 
00282         }
00283 }
00284 

Generated on Tue Dec 13 14:46:47 2005 for guliverkli by  doxygen 1.4.5