2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // ChildView.cpp : implementation of the CChildView class
27 #include "ChildView.h"
34 static char THIS_FILE
[] = __FILE__
;
37 /////////////////////////////////////////////////////////////////////////////
40 CChildView::CChildView() : m_vrect(0,0,0,0)
43 m_lastlmdownpoint
.SetPoint(0, 0);
48 CChildView::~CChildView()
52 BOOL
CChildView::PreCreateWindow(CREATESTRUCT
& cs
)
54 if(!CWnd::PreCreateWindow(cs
))
57 cs
.style
&= ~WS_BORDER
;
58 cs
.lpszClass
= AfxRegisterWndClass(CS_HREDRAW
|CS_VREDRAW
|CS_DBLCLKS
,
59 ::LoadCursor(NULL
, IDC_HAND
), HBRUSH(COLOR_WINDOW
+1), NULL
);
64 BOOL
CChildView::PreTranslateMessage(MSG
* pMsg
)
66 if(pMsg
->message
>= WM_MOUSEFIRST
&& pMsg
->message
<= WM_MYMOUSELAST
)
68 CWnd
* pParent
= GetParent();
69 CPoint
p(pMsg
->lParam
);
70 ::MapWindowPoints(pMsg
->hwnd
, pParent
->m_hWnd
, &p
, 1);
72 bool fDblClick
= false;
74 bool fInteractiveVideo
= ((CMainFrame
*)AfxGetMainWnd())->IsInteractiveVideo();
78 if(pMsg->message == WM_LBUTTONDOWN)
80 if((pMsg->time - m_lastlmdowntime) <= GetDoubleClickTime()
81 && abs(pMsg->pt.x - m_lastlmdownpoint.x) <= GetSystemMetrics(SM_CXDOUBLECLK)
82 && abs(pMsg->pt.y - m_lastlmdownpoint.y) <= GetSystemMetrics(SM_CYDOUBLECLK))
86 m_lastlmdownpoint.SetPoint(0, 0);
90 m_lastlmdowntime = pMsg->time;
91 m_lastlmdownpoint = pMsg->pt;
94 else if(pMsg->message == WM_LBUTTONDBLCLK)
96 m_lastlmdowntime = pMsg->time;
97 m_lastlmdownpoint = pMsg->pt;
101 if((pMsg
->message
== WM_LBUTTONDOWN
|| pMsg
->message
== WM_LBUTTONUP
|| pMsg
->message
== WM_MOUSEMOVE
)
102 && fInteractiveVideo
)
104 if(pMsg
->message
== WM_MOUSEMOVE
)
106 pParent
->PostMessage(pMsg
->message
, pMsg
->wParam
, MAKELPARAM(p
.x
, p
.y
));
111 pParent
->PostMessage(WM_LBUTTONDOWN
, pMsg
->wParam
, MAKELPARAM(p
.x
, p
.y
));
112 pParent
->PostMessage(WM_LBUTTONDBLCLK
, pMsg
->wParam
, MAKELPARAM(p
.x
, p
.y
));
117 pParent
->PostMessage(pMsg
->message
, pMsg
->wParam
, MAKELPARAM(p
.x
, p
.y
));
122 return CWnd::PreTranslateMessage(pMsg
);
125 void CChildView::SetVideoRect(CRect r
)
132 void CChildView::LoadLogo()
134 AppSettings
& s
= AfxGetAppSettings();
136 CAutoLock
cAutoLock(&m_csLogo
);
142 if(AfxGetAppSettings().fXpOrBetter
)
143 m_logo
.Load(s
.logofn
);
144 else if(HANDLE h
= LoadImage(NULL
, s
.logofn
, IMAGE_BITMAP
, 0, 0, LR_LOADFROMFILE
))
145 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
150 m_logo
.LoadFromResource(s
.logoid
);
151 // m_logo.LoadFromResource(AfxGetInstanceHandle(), s.logoid);
154 if(m_hWnd
) Invalidate();
157 CSize
CChildView::GetLogoSize()
161 ret
.SetSize(m_logo
.GetWidth(), m_logo
.GetHeight());
165 IMPLEMENT_DYNAMIC(CChildView
, CWnd
)
167 BEGIN_MESSAGE_MAP(CChildView
, CWnd
)
168 //{{AFX_MSG_MAP(CChildView)
172 ON_WM_WINDOWPOSCHANGED()
173 ON_COMMAND_EX(ID_PLAY_PLAYPAUSE
, OnPlayPlayPauseStop
)
174 ON_COMMAND_EX(ID_PLAY_PLAY
, OnPlayPlayPauseStop
)
175 ON_COMMAND_EX(ID_PLAY_PAUSE
, OnPlayPlayPauseStop
)
176 ON_COMMAND_EX(ID_PLAY_STOP
, OnPlayPlayPauseStop
)
184 /////////////////////////////////////////////////////////////////////////////
185 // CChildView message handlers
187 void CChildView::OnPaint()
189 CPaintDC
dc(this); // device context for painting
191 ((CMainFrame
*)GetParentFrame())->RepaintVideo();
193 // Do not call CWnd::OnPaint() for painting messages
196 BOOL
CChildView::OnEraseBkgnd(CDC
* pDC
)
200 CAutoLock
cAutoLock(&m_csLogo
);
202 if(((CMainFrame
*)GetParentFrame())->IsSomethingLoaded())
204 pDC
->ExcludeClipRect(m_vrect
);
206 else if(!m_logo
.IsNull() /*&& ((CMainFrame*)GetParentFrame())->IsPlaylistEmpty()*/)
209 GetObject(m_logo
, sizeof(bm
), &bm
);
212 int w
= min(bm
.bmWidth
, r
.Width());
213 int h
= min(abs(bm
.bmHeight
), r
.Height());
214 // int w = min(m_logo.GetWidth(), r.Width());
215 // int h = min(m_logo.GetHeight(), r.Height());
216 int x
= (r
.Width() - w
) / 2;
217 int y
= (r
.Height() - h
) / 2;
218 r
= CRect(CPoint(x
, y
), CSize(w
, h
));
220 int oldmode
= pDC
->SetStretchBltMode(STRETCH_HALFTONE
);
221 m_logo
.StretchBlt(*pDC
, r
, CRect(0,0,bm
.bmWidth
,abs(bm
.bmHeight
)));
222 // m_logo.Draw(*pDC, r);
223 pDC
->SetStretchBltMode(oldmode
);
225 pDC
->ExcludeClipRect(r
);
229 pDC
->FillSolidRect(r
, 0);
234 void CChildView::OnSize(UINT nType
, int cx
, int cy
)
236 CWnd::OnSize(nType
, cx
, cy
);
238 ((CMainFrame
*)GetParentFrame())->MoveVideoWindow();
241 void CChildView::OnWindowPosChanged(WINDOWPOS
* lpwndpos
)
243 CWnd::OnWindowPosChanged(lpwndpos
);
245 ((CMainFrame
*)GetParentFrame())->MoveVideoWindow();
248 BOOL
CChildView::OnPlayPlayPauseStop(UINT nID
)
250 if(nID
== ID_PLAY_STOP
) SetVideoRect();
254 BOOL
CChildView::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
256 if(((CMainFrame
*)GetParentFrame())->m_fHideCursor
)
262 return CWnd::OnSetCursor(pWnd
, nHitTest
, message
);
265 void CChildView::OnNcCalcSize(BOOL bCalcValidRects
, NCCALCSIZE_PARAMS
* lpncsp
)
267 if(!((CMainFrame
*)GetParentFrame())->IsFrameLessWindow())
269 InflateRect(&lpncsp
->rgrc
[0], -1, -1);
272 CWnd::OnNcCalcSize(bCalcValidRects
, lpncsp
);
275 void CChildView::OnNcPaint()
277 if(!((CMainFrame
*)GetParentFrame())->IsFrameLessWindow())
281 r
.OffsetRect(-r
.left
, -r
.top
);
283 CWindowDC(this).Draw3dRect(&r
, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));