00001
00002
00003
00004
00005
00006 #include <streams.h>
00007
00008 #define CheckConnected(pin,code) \
00009 { \
00010 if (pin == NULL) { \
00011 ASSERT(!TEXT("Pin not set")); \
00012 } else if (pin->IsConnected() == FALSE) { \
00013 return (code); \
00014 } \
00015 }
00016
00017 BOOL WINAPI PossiblyEatMessage(HWND hwndDrain, UINT uMsg, WPARAM wParam, LPARAM lParam)
00018 {
00019 if (hwndDrain != NULL && !InSendMessage())
00020 {
00021 switch (uMsg)
00022 {
00023 case WM_CHAR:
00024 case WM_DEADCHAR:
00025 case WM_KEYDOWN:
00026 case WM_KEYUP:
00027 case WM_LBUTTONDBLCLK:
00028 case WM_LBUTTONDOWN:
00029 case WM_LBUTTONUP:
00030 case WM_MBUTTONDBLCLK:
00031 case WM_MBUTTONDOWN:
00032 case WM_MBUTTONUP:
00033 case WM_MOUSEACTIVATE:
00034 case WM_MOUSEMOVE:
00035
00036
00037 case WM_NCLBUTTONDBLCLK:
00038 case WM_NCLBUTTONDOWN:
00039 case WM_NCLBUTTONUP:
00040 case WM_NCMBUTTONDBLCLK:
00041 case WM_NCMBUTTONDOWN:
00042 case WM_NCMBUTTONUP:
00043 case WM_NCMOUSEMOVE:
00044 case WM_NCRBUTTONDBLCLK:
00045 case WM_NCRBUTTONDOWN:
00046 case WM_NCRBUTTONUP:
00047 case WM_RBUTTONDBLCLK:
00048 case WM_RBUTTONDOWN:
00049 case WM_RBUTTONUP:
00050 case WM_SYSCHAR:
00051 case WM_SYSDEADCHAR:
00052 case WM_SYSKEYDOWN:
00053 case WM_SYSKEYUP:
00054
00055 DbgLog((LOG_TRACE, 2, TEXT("Forwarding %x to drain")));
00056 PostMessage(hwndDrain, uMsg, wParam, lParam);
00057
00058 return TRUE;
00059 }
00060 }
00061 return FALSE;
00062 }
00063
00064 CBaseControlWindow::CBaseControlWindow(
00065 CBaseFilter *pFilter,
00066 CCritSec *pInterfaceLock,
00067 TCHAR *pName,
00068 LPUNKNOWN pUnk,
00069 HRESULT *phr) :
00070
00071 CBaseVideoWindow(pName,pUnk),
00072 m_pInterfaceLock(pInterfaceLock),
00073 m_hwndOwner(NULL),
00074 m_hwndDrain(NULL),
00075 m_bAutoShow(TRUE),
00076 m_pFilter(pFilter),
00077 m_bCursorHidden(FALSE),
00078 m_pPin(NULL)
00079 {
00080 ASSERT(m_pFilter);
00081 ASSERT(m_pInterfaceLock);
00082 ASSERT(phr);
00083 m_BorderColour = VIDEO_COLOUR;
00084 }
00085
00086 STDMETHODIMP CBaseControlWindow::put_Caption(BSTR strCaption)
00087 {
00088 CheckPointer(strCaption,E_POINTER);
00089 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00090 #ifdef UNICODE
00091 SetWindowText(m_hwnd, strCaption);
00092 #else
00093 CHAR Caption[CAPTION];
00094
00095 WideCharToMultiByte(CP_ACP,0,strCaption,-1,Caption,CAPTION,NULL,NULL);
00096 SetWindowText(m_hwnd, Caption);
00097 #endif
00098 return NOERROR;
00099 }
00100
00101 STDMETHODIMP CBaseControlWindow::get_Caption(BSTR *pstrCaption)
00102 {
00103 CheckPointer(pstrCaption,E_POINTER);
00104 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00105 WCHAR WideCaption[CAPTION];
00106
00107 #ifdef UNICODE
00108 GetWindowText(m_hwnd,WideCaption,CAPTION);
00109 #else
00110
00111
00112 TCHAR Caption[CAPTION];
00113 GetWindowText(m_hwnd,Caption,CAPTION);
00114 MultiByteToWideChar(CP_ACP,0,Caption,-1,WideCaption,CAPTION);
00115 #endif
00116 return WriteBSTR(pstrCaption,WideCaption);
00117 }
00118
00119 STDMETHODIMP CBaseControlWindow::put_WindowStyleEx(long WindowStyleEx)
00120 {
00121 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00122
00123
00124
00125 if (GetWindowLong(m_hwnd,GWL_EXSTYLE) & WS_EX_TOPMOST) {
00126 if ((WindowStyleEx & WS_EX_TOPMOST) == 0) {
00127 SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) FALSE,(LPARAM) 0);
00128 }
00129 }
00130
00131
00132
00133 if (WindowStyleEx & WS_EX_TOPMOST) {
00134 SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) TRUE,(LPARAM) 0);
00135 WindowStyleEx &= (~WS_EX_TOPMOST);
00136 if (WindowStyleEx == 0) return NOERROR;
00137 }
00138 return DoSetWindowStyle(WindowStyleEx,GWL_EXSTYLE);
00139 }
00140
00141 STDMETHODIMP CBaseControlWindow::get_WindowStyleEx(long *pWindowStyleEx)
00142 {
00143 CheckPointer(pWindowStyleEx,E_POINTER);
00144 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00145 return DoGetWindowStyle(pWindowStyleEx,GWL_EXSTYLE);
00146 }
00147
00148 STDMETHODIMP CBaseControlWindow::put_WindowStyle(long WindowStyle)
00149 {
00150
00151
00152 if ((WindowStyle & WS_DISABLED) ||
00153 (WindowStyle & WS_ICONIC) ||
00154 (WindowStyle & WS_MAXIMIZE) ||
00155 (WindowStyle & WS_MINIMIZE) ||
00156 (WindowStyle & WS_HSCROLL) ||
00157 (WindowStyle & WS_VSCROLL)) {
00158
00159 return E_INVALIDARG;
00160 }
00161
00162 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00163 return DoSetWindowStyle(WindowStyle,GWL_STYLE);
00164 }
00165
00166 STDMETHODIMP CBaseControlWindow::get_WindowStyle(long *pWindowStyle)
00167 {
00168 CheckPointer(pWindowStyle,E_POINTER);
00169 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00170 return DoGetWindowStyle(pWindowStyle,GWL_STYLE);
00171 }
00172
00173 HRESULT CBaseControlWindow::DoSetWindowStyle(long Style,long WindowLong)
00174 {
00175 RECT WindowRect;
00176
00177
00178 BOOL bVisible = IsWindowVisible(m_hwnd);
00179 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00180
00181
00182 SetWindowLong(m_hwnd,WindowLong,Style);
00183 UINT WindowFlags = SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00184 WindowFlags |= SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
00185
00186
00187
00188 if (bVisible == TRUE) {
00189
00190 SetWindowPos(m_hwnd,
00191 HWND_TOP,
00192 0,0,0,0,
00193 WindowFlags);
00194
00195 return NOERROR;
00196 }
00197
00198
00199
00200 MoveWindow((HWND) m_hwnd,
00201 GetSystemMetrics(SM_CXSCREEN),
00202 GetSystemMetrics(SM_CYSCREEN),
00203 WIDTH(&WindowRect),
00204 HEIGHT(&WindowRect),
00205 TRUE);
00206
00207
00208
00209 SetWindowPos(m_hwnd,
00210 HWND_TOP,
00211 0,0,0,0,
00212 WindowFlags);
00213
00214 EXECUTE_ASSERT(ShowWindow(m_hwnd,SW_HIDE));
00215
00216 if (GetParent(m_hwnd)) {
00217
00218 MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
00219 }
00220
00221 MoveWindow((HWND) m_hwnd,
00222 WindowRect.left,
00223 WindowRect.top,
00224 WIDTH(&WindowRect),
00225 HEIGHT(&WindowRect),
00226 TRUE);
00227
00228 return NOERROR;
00229 }
00230
00231 HRESULT CBaseControlWindow::DoGetWindowStyle(long *pStyle,long WindowLong)
00232 {
00233 *pStyle = GetWindowLong(m_hwnd,WindowLong);
00234 return NOERROR;
00235 }
00236
00237 STDMETHODIMP CBaseControlWindow::put_WindowState(long WindowState)
00238 {
00239 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00240 DoShowWindow(WindowState);
00241 return NOERROR;
00242 }
00243
00244 STDMETHODIMP CBaseControlWindow::get_WindowState(long *pWindowState)
00245 {
00246 CheckPointer(pWindowState,E_POINTER);
00247 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00248 ASSERT(pWindowState);
00249 *pWindowState = FALSE;
00250
00251
00252
00253
00254
00255 if (IsWindowVisible(m_hwnd) == TRUE) {
00256
00257
00258 if (IsIconic(m_hwnd) == TRUE) {
00259 *pWindowState |= SW_MINIMIZE;
00260 }
00261
00262
00263 else if (IsZoomed(m_hwnd) == TRUE) {
00264 *pWindowState |= SW_MAXIMIZE;
00265 }
00266
00267
00268 else {
00269 *pWindowState |= SW_SHOW;
00270 }
00271
00272 } else {
00273 *pWindowState |= SW_HIDE;
00274 }
00275 return NOERROR;
00276 }
00277
00278 STDMETHODIMP CBaseControlWindow::put_BackgroundPalette(long BackgroundPalette)
00279 {
00280 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00281 CAutoLock cWindowLock(&m_WindowLock);
00282
00283
00284
00285 if (BackgroundPalette != OATRUE) {
00286 if (BackgroundPalette != OAFALSE) {
00287 return E_INVALIDARG;
00288 }
00289 }
00290
00291
00292
00293 m_bBackground = (BackgroundPalette == OATRUE ? TRUE : FALSE);
00294 PostMessage(m_hwnd,m_RealizePalette,0,0);
00295 PaintWindow(FALSE);
00296
00297 return NOERROR;
00298 }
00299
00300 STDMETHODIMP
00301 CBaseControlWindow::get_BackgroundPalette(long *pBackgroundPalette)
00302 {
00303 CheckPointer(pBackgroundPalette,E_POINTER);
00304 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00305 CAutoLock cWindowLock(&m_WindowLock);
00306
00307
00308
00309 *pBackgroundPalette = (m_bBackground == TRUE ? OATRUE : OAFALSE);
00310 return NOERROR;
00311 }
00312
00313 STDMETHODIMP CBaseControlWindow::put_Visible(long Visible)
00314 {
00315 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00316
00317
00318
00319 if (Visible != OATRUE) {
00320 if (Visible != OAFALSE) {
00321 return E_INVALIDARG;
00322 }
00323 }
00324
00325
00326
00327 INT Mode = (Visible == OATRUE ? SW_SHOWNORMAL : SW_HIDE);
00328 DoShowWindow(Mode);
00329 return NOERROR;
00330 }
00331
00332 STDMETHODIMP CBaseControlWindow::get_Visible(long *pVisible)
00333 {
00334 CheckPointer(pVisible,E_POINTER);
00335 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00336
00337
00338
00339
00340
00341 BOOL Mode = IsWindowVisible(m_hwnd);
00342 *pVisible = (Mode == TRUE ? OATRUE : OAFALSE);
00343 return NOERROR;
00344 }
00345
00346 STDMETHODIMP CBaseControlWindow::put_Left(long Left)
00347 {
00348 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00349 BOOL bSuccess;
00350 RECT WindowRect;
00351
00352
00353 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00354
00355 if (GetParent(m_hwnd)) {
00356
00357 MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
00358 }
00359
00360
00361
00362
00363
00364 WindowRect.bottom = WindowRect.bottom - WindowRect.top;
00365 WindowRect.right = WindowRect.right - WindowRect.left;
00366 UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00367
00368 bSuccess = SetWindowPos(m_hwnd,
00369 HWND_TOP,
00370 Left,
00371 WindowRect.top,
00372 WindowRect.right,
00373 WindowRect.bottom,
00374 WindowFlags);
00375
00376 if (bSuccess == FALSE) {
00377 return E_INVALIDARG;
00378 }
00379 return NOERROR;
00380 }
00381
00382 STDMETHODIMP CBaseControlWindow::get_Left(long *pLeft)
00383 {
00384 CheckPointer(pLeft,E_POINTER);
00385 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00386 RECT WindowRect;
00387
00388 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00389 *pLeft = WindowRect.left;
00390 return NOERROR;
00391 }
00392
00393 STDMETHODIMP CBaseControlWindow::put_Width(long Width)
00394 {
00395 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00396 BOOL bSuccess;
00397 RECT WindowRect;
00398
00399
00400
00401
00402
00403 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00404
00405 if (GetParent(m_hwnd)) {
00406
00407 MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
00408 }
00409
00410 WindowRect.bottom = WindowRect.bottom - WindowRect.top;
00411 UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00412
00413
00414
00415
00416
00417 bSuccess = SetWindowPos(m_hwnd,
00418 HWND_TOP,
00419 WindowRect.left,
00420 WindowRect.top,
00421 Width,
00422 WindowRect.bottom,
00423 WindowFlags);
00424
00425 if (bSuccess == FALSE) {
00426 return E_INVALIDARG;
00427 }
00428 return NOERROR;
00429 }
00430
00431 STDMETHODIMP CBaseControlWindow::get_Width(long *pWidth)
00432 {
00433 CheckPointer(pWidth,E_POINTER);
00434 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00435 RECT WindowRect;
00436
00437 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00438 *pWidth = WindowRect.right - WindowRect.left;
00439 return NOERROR;
00440 }
00441
00442 STDMETHODIMP CBaseControlWindow::put_Top(long Top)
00443 {
00444 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00445 BOOL bSuccess;
00446 RECT WindowRect;
00447
00448
00449 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00450
00451 if (GetParent(m_hwnd)) {
00452
00453 MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
00454 }
00455
00456
00457
00458
00459
00460 WindowRect.bottom = WindowRect.bottom - WindowRect.top;
00461 WindowRect.right = WindowRect.right - WindowRect.left;
00462 UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00463
00464 bSuccess = SetWindowPos(m_hwnd,
00465 HWND_TOP,
00466 WindowRect.left,
00467 Top,
00468 WindowRect.right,
00469 WindowRect.bottom,
00470 WindowFlags);
00471
00472 if (bSuccess == FALSE) {
00473 return E_INVALIDARG;
00474 }
00475 return NOERROR;
00476 }
00477
00478 STDMETHODIMP CBaseControlWindow::get_Top(long *pTop)
00479 {
00480 CheckPointer(pTop,E_POINTER);
00481 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00482 RECT WindowRect;
00483
00484 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00485 *pTop = WindowRect.top;
00486 return NOERROR;
00487 }
00488
00489 STDMETHODIMP CBaseControlWindow::put_Height(long Height)
00490 {
00491 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00492 BOOL bSuccess;
00493 RECT WindowRect;
00494
00495
00496
00497
00498
00499 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00500
00501 if (GetParent(m_hwnd)) {
00502
00503 MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
00504 }
00505
00506 WindowRect.right = WindowRect.right - WindowRect.left;
00507 UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00508
00509 bSuccess = SetWindowPos(m_hwnd,
00510 HWND_TOP,
00511 WindowRect.left,
00512 WindowRect.top,
00513 WindowRect.right,
00514 Height,
00515 WindowFlags);
00516
00517 if (bSuccess == FALSE) {
00518 return E_INVALIDARG;
00519 }
00520 return NOERROR;
00521 }
00522
00523 STDMETHODIMP CBaseControlWindow::get_Height(long *pHeight)
00524 {
00525 CheckPointer(pHeight,E_POINTER);
00526 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00527 RECT WindowRect;
00528
00529 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00530 *pHeight = WindowRect.bottom - WindowRect.top;
00531 return NOERROR;
00532 }
00533
00534 STDMETHODIMP CBaseControlWindow::put_Owner(OAHWND Owner)
00535 {
00536
00537
00538 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00539 m_hwndOwner = (HWND) Owner;
00540 HWND hwndParent = m_hwndOwner;
00541
00542
00543
00544 LONG Style = GetWindowLong(m_hwnd,GWL_STYLE);
00545 if (Owner == NULL) {
00546 Style &= (~WS_CHILD);
00547 } else {
00548 Style |= (WS_CHILD);
00549 }
00550 SetWindowLong(m_hwnd,GWL_STYLE,Style);
00551
00552
00553
00554 SetParent(m_hwnd,hwndParent);
00555
00556 PaintWindow(TRUE);
00557 NOTE1("Changed parent %lx",hwndParent);
00558
00559 return NOERROR;
00560 }
00561
00562 STDMETHODIMP CBaseControlWindow::get_Owner(OAHWND *Owner)
00563 {
00564 CheckPointer(Owner,E_POINTER);
00565 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00566 *Owner = (OAHWND) m_hwndOwner;
00567 return NOERROR;
00568 }
00569
00570 STDMETHODIMP CBaseControlWindow::put_MessageDrain(OAHWND Drain)
00571 {
00572
00573
00574 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00575 m_hwndDrain = (HWND) Drain;
00576 return NOERROR;
00577 }
00578
00579 STDMETHODIMP CBaseControlWindow::get_MessageDrain(OAHWND *Drain)
00580 {
00581 CheckPointer(Drain,E_POINTER);
00582 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00583 *Drain = (OAHWND) m_hwndDrain;
00584 return NOERROR;
00585 }
00586
00587 STDMETHODIMP
00588 CBaseControlWindow::NotifyOwnerMessage(OAHWND hwnd,
00589 long uMsg,
00590 LONG_PTR wParam,
00591 LONG_PTR lParam)
00592 {
00593 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00594
00595
00596
00597 switch (uMsg) {
00598
00599 case WM_SYSCOLORCHANGE:
00600 case WM_PALETTECHANGED:
00601 case WM_PALETTEISCHANGING:
00602 case WM_QUERYNEWPALETTE:
00603 case WM_DEVMODECHANGE:
00604 case WM_DISPLAYCHANGE:
00605 case WM_ACTIVATEAPP:
00606
00607
00608
00609 if (m_hwndOwner == NULL) {
00610 return NOERROR;
00611 }
00612 SendMessage(m_hwnd,uMsg,(WPARAM)wParam,(LPARAM)lParam);
00613 break;
00614
00615
00616
00617
00618
00619 case WM_MOVE:
00620 PostMessage(m_hwnd,WM_PAINT,0,0);
00621 break;
00622 }
00623 return NOERROR;
00624 }
00625
00626 STDMETHODIMP CBaseControlWindow::SetWindowForeground(long Focus)
00627 {
00628
00629
00630 if (Focus != OATRUE) {
00631 if (Focus != OAFALSE) {
00632 return E_INVALIDARG;
00633 }
00634 }
00635
00636
00637
00638 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00639 BOOL bFocus = (Focus == OATRUE ? TRUE : FALSE);
00640 DoSetWindowForeground(bFocus);
00641
00642 return NOERROR;
00643 }
00644
00645 STDMETHODIMP
00646 CBaseControlWindow::SetWindowPosition(long Left,long Top,long Width,long Height)
00647 {
00648 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00649 BOOL bSuccess;
00650
00651
00652 UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
00653
00654 ASSERT(IsWindow(m_hwnd));
00655 bSuccess = SetWindowPos(m_hwnd,
00656 HWND_TOP,
00657 Left,
00658 Top,
00659 Width,
00660 Height,
00661 WindowFlags);
00662 ASSERT(bSuccess);
00663 #ifdef DEBUG
00664 DbgLog((LOG_TRACE, 1, TEXT("SWP failed error %d"), GetLastError()));
00665 #endif
00666 if (bSuccess == FALSE) {
00667 return E_INVALIDARG;
00668 }
00669 return NOERROR;
00670 }
00671
00672 STDMETHODIMP
00673 CBaseControlWindow::GetWindowPosition(long *pLeft,long *pTop,long *pWidth,long *pHeight)
00674 {
00675
00676
00677 CheckPointer(pLeft,E_POINTER);
00678 CheckPointer(pTop,E_POINTER);
00679 CheckPointer(pWidth,E_POINTER);
00680 CheckPointer(pHeight,E_POINTER);
00681 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00682 RECT WindowRect;
00683
00684
00685
00686 EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
00687
00688
00689
00690 *pLeft = WindowRect.left;
00691 *pTop = WindowRect.top;
00692 *pWidth = WindowRect.right - WindowRect.left;
00693 *pHeight = WindowRect.bottom - WindowRect.top;
00694
00695 return NOERROR;
00696 }
00697
00698 STDMETHODIMP
00699 CBaseControlWindow::GetRestorePosition(long *pLeft,long *pTop,long *pWidth,long *pHeight)
00700 {
00701
00702
00703 CheckPointer(pLeft,E_POINTER);
00704 CheckPointer(pTop,E_POINTER);
00705 CheckPointer(pWidth,E_POINTER);
00706 CheckPointer(pHeight,E_POINTER);
00707 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00708
00709
00710
00711 WINDOWPLACEMENT Place;
00712 Place.length = sizeof(WINDOWPLACEMENT);
00713 EXECUTE_ASSERT(GetWindowPlacement(m_hwnd,&Place));
00714
00715 RECT WorkArea;
00716
00717
00718
00719 if (SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,FALSE) == TRUE) {
00720 if (GetParent(m_hwnd) == NULL) {
00721 Place.rcNormalPosition.top += WorkArea.top;
00722 Place.rcNormalPosition.bottom += WorkArea.top;
00723 Place.rcNormalPosition.left += WorkArea.left;
00724 Place.rcNormalPosition.right += WorkArea.left;
00725 }
00726 }
00727
00728
00729
00730 *pLeft = Place.rcNormalPosition.left;
00731 *pTop = Place.rcNormalPosition.top;
00732 *pWidth = Place.rcNormalPosition.right - Place.rcNormalPosition.left;
00733 *pHeight = Place.rcNormalPosition.bottom - Place.rcNormalPosition.top;
00734
00735 return NOERROR;
00736 }
00737
00738 STDMETHODIMP CBaseControlWindow::get_BorderColor(long *Color)
00739 {
00740 CheckPointer(Color,E_POINTER);
00741 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00742 *Color = (long) m_BorderColour;
00743 return NOERROR;
00744 }
00745
00746 STDMETHODIMP CBaseControlWindow::put_BorderColor(long Color)
00747 {
00748 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00749
00750
00751
00752 m_BorderColour = (COLORREF) Color;
00753 PaintWindow(TRUE);
00754 return NOERROR;
00755 }
00756
00757 STDMETHODIMP CBaseControlWindow::get_FullScreenMode(long *FullScreenMode)
00758 {
00759 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00760 CheckPointer(FullScreenMode,E_POINTER);
00761 return E_NOTIMPL;
00762 }
00763
00764 STDMETHODIMP CBaseControlWindow::put_FullScreenMode(long FullScreenMode)
00765 {
00766 return E_NOTIMPL;
00767 }
00768
00769 STDMETHODIMP CBaseControlWindow::put_AutoShow(long AutoShow)
00770 {
00771 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00772
00773
00774
00775 if (AutoShow != OATRUE) {
00776 if (AutoShow != OAFALSE) {
00777 return E_INVALIDARG;
00778 }
00779 }
00780
00781 m_bAutoShow = (AutoShow == OATRUE ? TRUE : FALSE);
00782 return NOERROR;
00783 }
00784
00785 STDMETHODIMP CBaseControlWindow::get_AutoShow(long *AutoShow)
00786 {
00787 CheckPointer(AutoShow,E_POINTER);
00788 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00789 *AutoShow = (m_bAutoShow == TRUE ? OATRUE : OAFALSE);
00790 return NOERROR;
00791 }
00792
00793 STDMETHODIMP
00794 CBaseControlWindow::GetMinIdealImageSize(long *pWidth,long *pHeight)
00795 {
00796 CheckPointer(pWidth,E_POINTER);
00797 CheckPointer(pHeight,E_POINTER);
00798 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00799 FILTER_STATE State;
00800
00801
00802
00803 m_pFilter->GetState(0,&State);
00804 if (State == State_Stopped) {
00805 return VFW_E_WRONG_STATE;
00806 }
00807
00808 RECT DefaultRect = GetDefaultRect();
00809 *pWidth = WIDTH(&DefaultRect);
00810 *pHeight = HEIGHT(&DefaultRect);
00811 return NOERROR;
00812 }
00813
00814 STDMETHODIMP
00815 CBaseControlWindow::GetMaxIdealImageSize(long *pWidth,long *pHeight)
00816 {
00817 CheckPointer(pWidth,E_POINTER);
00818 CheckPointer(pHeight,E_POINTER);
00819 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00820 FILTER_STATE State;
00821
00822
00823
00824 m_pFilter->GetState(0,&State);
00825 if (State == State_Stopped) {
00826 return VFW_E_WRONG_STATE;
00827 }
00828
00829 RECT DefaultRect = GetDefaultRect();
00830 *pWidth = WIDTH(&DefaultRect);
00831 *pHeight = HEIGHT(&DefaultRect);
00832 return NOERROR;
00833 }
00834
00835 STDMETHODIMP
00836 CBaseControlWindow::HideCursor(long HideCursor)
00837 {
00838 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00839
00840
00841
00842 if (HideCursor != OATRUE) {
00843 if (HideCursor != OAFALSE) {
00844 return E_INVALIDARG;
00845 }
00846 }
00847
00848 m_bCursorHidden = (HideCursor == OATRUE ? TRUE : FALSE);
00849 return NOERROR;
00850 }
00851
00852 STDMETHODIMP CBaseControlWindow::IsCursorHidden(long *CursorHidden)
00853 {
00854 CheckPointer(CursorHidden,E_POINTER);
00855 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00856 *CursorHidden = (m_bCursorHidden == TRUE ? OATRUE : OAFALSE);
00857 return NOERROR;
00858 }
00859
00860 CBaseControlVideo::CBaseControlVideo(
00861 CBaseFilter *pFilter,
00862 CCritSec *pInterfaceLock,
00863 TCHAR *pName,
00864 LPUNKNOWN pUnk,
00865 HRESULT *phr) :
00866
00867 CBaseBasicVideo(pName,pUnk),
00868 m_pFilter(pFilter),
00869 m_pInterfaceLock(pInterfaceLock),
00870 m_pPin(NULL)
00871 {
00872 ASSERT(m_pFilter);
00873 ASSERT(m_pInterfaceLock);
00874 ASSERT(phr);
00875 }
00876
00877 STDMETHODIMP CBaseControlVideo::get_AvgTimePerFrame(REFTIME *pAvgTimePerFrame)
00878 {
00879 CheckPointer(pAvgTimePerFrame,E_POINTER);
00880 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00881 CAutoLock cInterfaceLock(m_pInterfaceLock);
00882
00883 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00884 if (pVideoInfo == NULL)
00885 return E_OUTOFMEMORY;
00886 COARefTime AvgTime(pVideoInfo->AvgTimePerFrame);
00887 *pAvgTimePerFrame = (REFTIME) AvgTime;
00888
00889 return NOERROR;
00890 }
00891
00892 STDMETHODIMP CBaseControlVideo::get_BitRate(long *pBitRate)
00893 {
00894 CheckPointer(pBitRate,E_POINTER);
00895 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00896 CAutoLock cInterfaceLock(m_pInterfaceLock);
00897
00898 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00899 if (pVideoInfo == NULL)
00900 return E_OUTOFMEMORY;
00901 *pBitRate = pVideoInfo->dwBitRate;
00902 return NOERROR;
00903 }
00904
00905 STDMETHODIMP CBaseControlVideo::get_BitErrorRate(long *pBitErrorRate)
00906 {
00907 CheckPointer(pBitErrorRate,E_POINTER);
00908 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00909 CAutoLock cInterfaceLock(m_pInterfaceLock);
00910
00911 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00912 if (pVideoInfo == NULL)
00913 return E_OUTOFMEMORY;
00914 *pBitErrorRate = pVideoInfo->dwBitErrorRate;
00915 return NOERROR;
00916 }
00917
00918 STDMETHODIMP CBaseControlVideo::get_VideoWidth(long *pVideoWidth)
00919 {
00920 CheckPointer(pVideoWidth,E_POINTER);
00921 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00922 CAutoLock cInterfaceLock(m_pInterfaceLock);
00923
00924 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00925 if (pVideoInfo == NULL)
00926 return E_OUTOFMEMORY;
00927 *pVideoWidth = pVideoInfo->bmiHeader.biWidth;
00928 return NOERROR;
00929 }
00930
00931 STDMETHODIMP CBaseControlVideo::get_VideoHeight(long *pVideoHeight)
00932 {
00933 CheckPointer(pVideoHeight,E_POINTER);
00934 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00935 CAutoLock cInterfaceLock(m_pInterfaceLock);
00936
00937 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00938 if (pVideoInfo == NULL)
00939 return E_OUTOFMEMORY;
00940 *pVideoHeight = pVideoInfo->bmiHeader.biHeight;
00941 return NOERROR;
00942 }
00943
00944 STDMETHODIMP CBaseControlVideo::GetVideoPaletteEntries(long StartIndex,
00945 long Entries,
00946 long *pRetrieved,
00947 long *pPalette)
00948 {
00949 CheckPointer(pRetrieved,E_POINTER);
00950 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
00951 CAutoLock cInterfaceLock(m_pInterfaceLock);
00952 CMediaType MediaType;
00953
00954
00955
00956 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
00957 if (pVideoInfo == NULL)
00958 return E_OUTOFMEMORY;
00959 BITMAPINFOHEADER *pHeader = HEADER(pVideoInfo);
00960
00961
00962
00963 if (PALETTISED(pVideoInfo) == FALSE) {
00964 *pRetrieved = 0;
00965 return VFW_E_NO_PALETTE_AVAILABLE;
00966 }
00967
00968
00969
00970 if (pPalette == NULL) {
00971 *pRetrieved = pHeader->biClrUsed;
00972 return NOERROR;
00973 }
00974
00975
00976
00977 if (StartIndex >= (LONG) pHeader->biClrUsed || StartIndex < 0) {
00978 *pRetrieved = 0;
00979 return E_INVALIDARG;
00980 }
00981
00982
00983
00984 LONG Available = (LONG) pHeader->biClrUsed - StartIndex;
00985 *pRetrieved = max(0,min(Available,Entries));
00986 if (*pRetrieved == 0) {
00987 return S_FALSE;
00988 }
00989
00990
00991
00992 PALETTEENTRY *pEntries = (PALETTEENTRY *) pPalette;
00993 RGBQUAD *pColours = COLORS(pVideoInfo) + StartIndex;
00994
00995 for (LONG Count = 0;Count < *pRetrieved;Count++) {
00996 pEntries[Count].peRed = pColours[Count].rgbRed;
00997 pEntries[Count].peGreen = pColours[Count].rgbGreen;
00998 pEntries[Count].peBlue = pColours[Count].rgbBlue;
00999 pEntries[Count].peFlags = 0;
01000 }
01001 return NOERROR;
01002 }
01003
01004 STDMETHODIMP CBaseControlVideo::GetVideoSize(long *pWidth,long *pHeight)
01005 {
01006 CheckPointer(pWidth,E_POINTER);
01007 CheckPointer(pHeight,E_POINTER);
01008 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01009 CAutoLock cInterfaceLock(m_pInterfaceLock);
01010
01011
01012 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
01013 if (pVideoInfo == NULL)
01014 return E_OUTOFMEMORY;
01015 *pWidth = pVideoInfo->bmiHeader.biWidth;
01016 *pHeight = pVideoInfo->bmiHeader.biHeight;
01017 return NOERROR;
01018 }
01019
01020 STDMETHODIMP
01021 CBaseControlVideo::SetSourcePosition(long Left,long Top,long Width,long Height)
01022 {
01023 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01024 CAutoLock cInterfaceLock(m_pInterfaceLock);
01025 RECT SourceRect;
01026 SourceRect.left = Left;
01027 SourceRect.top = Top;
01028 SourceRect.right = Left + Width;
01029 SourceRect.bottom = Top + Height;
01030
01031
01032
01033 HRESULT hr = CheckSourceRect(&SourceRect);
01034 if (FAILED(hr)) {
01035 return hr;
01036 }
01037
01038
01039
01040 hr = SetSourceRect(&SourceRect);
01041 if (FAILED(hr)) {
01042 return hr;
01043 }
01044 return OnUpdateRectangles();
01045 }
01046
01047 STDMETHODIMP
01048 CBaseControlVideo::GetSourcePosition(long *pLeft,long *pTop,long *pWidth,long *pHeight)
01049 {
01050
01051
01052 CheckPointer(pLeft,E_POINTER);
01053 CheckPointer(pTop,E_POINTER);
01054 CheckPointer(pWidth,E_POINTER);
01055 CheckPointer(pHeight,E_POINTER);
01056 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01057 RECT SourceRect;
01058
01059 CAutoLock cInterfaceLock(m_pInterfaceLock);
01060 GetSourceRect(&SourceRect);
01061
01062 *pLeft = SourceRect.left;
01063 *pTop = SourceRect.top;
01064 *pWidth = WIDTH(&SourceRect);
01065 *pHeight = HEIGHT(&SourceRect);
01066
01067 return NOERROR;
01068 }
01069
01070 STDMETHODIMP
01071 CBaseControlVideo::SetDestinationPosition(long Left,long Top,long Width,long Height)
01072 {
01073 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01074 CAutoLock cInterfaceLock(m_pInterfaceLock);
01075 RECT DestinationRect;
01076
01077 DestinationRect.left = Left;
01078 DestinationRect.top = Top;
01079 DestinationRect.right = Left + Width;
01080 DestinationRect.bottom = Top + Height;
01081
01082
01083
01084 HRESULT hr = CheckTargetRect(&DestinationRect);
01085 if (FAILED(hr)) {
01086 return hr;
01087 }
01088
01089
01090
01091 hr = SetTargetRect(&DestinationRect);
01092 if (FAILED(hr)) {
01093 return hr;
01094 }
01095 return OnUpdateRectangles();
01096 }
01097
01098 STDMETHODIMP
01099 CBaseControlVideo::GetDestinationPosition(long *pLeft,long *pTop,long *pWidth,long *pHeight)
01100 {
01101
01102
01103 CheckPointer(pLeft,E_POINTER);
01104 CheckPointer(pTop,E_POINTER);
01105 CheckPointer(pWidth,E_POINTER);
01106 CheckPointer(pHeight,E_POINTER);
01107 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01108 RECT DestinationRect;
01109
01110 CAutoLock cInterfaceLock(m_pInterfaceLock);
01111 GetTargetRect(&DestinationRect);
01112
01113 *pLeft = DestinationRect.left;
01114 *pTop = DestinationRect.top;
01115 *pWidth = WIDTH(&DestinationRect);
01116 *pHeight = HEIGHT(&DestinationRect);
01117
01118 return NOERROR;
01119 }
01120
01121 STDMETHODIMP CBaseControlVideo::put_SourceLeft(long SourceLeft)
01122 {
01123 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01124 CAutoLock cInterfaceLock(m_pInterfaceLock);
01125 RECT SourceRect;
01126 GetSourceRect(&SourceRect);
01127 SourceRect.right = SourceLeft + WIDTH(&SourceRect);
01128 SourceRect.left = SourceLeft;
01129
01130
01131
01132 HRESULT hr = CheckSourceRect(&SourceRect);
01133 if (FAILED(hr)) {
01134 return hr;
01135 }
01136
01137
01138
01139 hr = SetSourceRect(&SourceRect);
01140 if (FAILED(hr)) {
01141 return hr;
01142 }
01143 return OnUpdateRectangles();
01144 }
01145
01146 STDMETHODIMP CBaseControlVideo::get_SourceLeft(long *pSourceLeft)
01147 {
01148 CheckPointer(pSourceLeft,E_POINTER);
01149 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01150 CAutoLock cInterfaceLock(m_pInterfaceLock);
01151 RECT SourceRect;
01152
01153 GetSourceRect(&SourceRect);
01154 *pSourceLeft = SourceRect.left;
01155 return NOERROR;
01156 }
01157
01158 STDMETHODIMP CBaseControlVideo::put_SourceWidth(long SourceWidth)
01159 {
01160 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01161 CAutoLock cInterfaceLock(m_pInterfaceLock);
01162 RECT SourceRect;
01163 GetSourceRect(&SourceRect);
01164 SourceRect.right = SourceRect.left + SourceWidth;
01165
01166
01167
01168 HRESULT hr = CheckSourceRect(&SourceRect);
01169 if (FAILED(hr)) {
01170 return hr;
01171 }
01172
01173
01174
01175 hr = SetSourceRect(&SourceRect);
01176 if (FAILED(hr)) {
01177 return hr;
01178 }
01179 return OnUpdateRectangles();
01180 }
01181
01182 STDMETHODIMP CBaseControlVideo::get_SourceWidth(long *pSourceWidth)
01183 {
01184 CheckPointer(pSourceWidth,E_POINTER);
01185 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01186 CAutoLock cInterfaceLock(m_pInterfaceLock);
01187 RECT SourceRect;
01188
01189 GetSourceRect(&SourceRect);
01190 *pSourceWidth = WIDTH(&SourceRect);
01191 return NOERROR;
01192 }
01193
01194 STDMETHODIMP CBaseControlVideo::put_SourceTop(long SourceTop)
01195 {
01196 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01197 CAutoLock cInterfaceLock(m_pInterfaceLock);
01198 RECT SourceRect;
01199 GetSourceRect(&SourceRect);
01200 SourceRect.bottom = SourceTop + HEIGHT(&SourceRect);
01201 SourceRect.top = SourceTop;
01202
01203
01204
01205 HRESULT hr = CheckSourceRect(&SourceRect);
01206 if (FAILED(hr)) {
01207 return hr;
01208 }
01209
01210
01211
01212 hr = SetSourceRect(&SourceRect);
01213 if (FAILED(hr)) {
01214 return hr;
01215 }
01216 return OnUpdateRectangles();
01217 }
01218
01219 STDMETHODIMP CBaseControlVideo::get_SourceTop(long *pSourceTop)
01220 {
01221 CheckPointer(pSourceTop,E_POINTER);
01222 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01223 CAutoLock cInterfaceLock(m_pInterfaceLock);
01224 RECT SourceRect;
01225
01226 GetSourceRect(&SourceRect);
01227 *pSourceTop = SourceRect.top;
01228 return NOERROR;
01229 }
01230
01231 STDMETHODIMP CBaseControlVideo::put_SourceHeight(long SourceHeight)
01232 {
01233 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01234 CAutoLock cInterfaceLock(m_pInterfaceLock);
01235 RECT SourceRect;
01236 GetSourceRect(&SourceRect);
01237 SourceRect.bottom = SourceRect.top + SourceHeight;
01238
01239
01240
01241 HRESULT hr = CheckSourceRect(&SourceRect);
01242 if (FAILED(hr)) {
01243 return hr;
01244 }
01245
01246
01247
01248 hr = SetSourceRect(&SourceRect);
01249 if (FAILED(hr)) {
01250 return hr;
01251 }
01252 return OnUpdateRectangles();
01253 }
01254
01255 STDMETHODIMP CBaseControlVideo::get_SourceHeight(long *pSourceHeight)
01256 {
01257 CheckPointer(pSourceHeight,E_POINTER);
01258 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01259 CAutoLock cInterfaceLock(m_pInterfaceLock);
01260 RECT SourceRect;
01261
01262 GetSourceRect(&SourceRect);
01263 *pSourceHeight = HEIGHT(&SourceRect);
01264 return NOERROR;
01265 }
01266
01267 STDMETHODIMP CBaseControlVideo::put_DestinationLeft(long DestinationLeft)
01268 {
01269 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01270 CAutoLock cInterfaceLock(m_pInterfaceLock);
01271 RECT DestinationRect;
01272 GetTargetRect(&DestinationRect);
01273 DestinationRect.right = DestinationLeft + WIDTH(&DestinationRect);
01274 DestinationRect.left = DestinationLeft;
01275
01276
01277
01278 HRESULT hr = CheckTargetRect(&DestinationRect);
01279 if (FAILED(hr)) {
01280 return hr;
01281 }
01282
01283
01284
01285 hr = SetTargetRect(&DestinationRect);
01286 if (FAILED(hr)) {
01287 return hr;
01288 }
01289 return OnUpdateRectangles();
01290 }
01291
01292 STDMETHODIMP CBaseControlVideo::get_DestinationLeft(long *pDestinationLeft)
01293 {
01294 CheckPointer(pDestinationLeft,E_POINTER);
01295 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01296 CAutoLock cInterfaceLock(m_pInterfaceLock);
01297 RECT DestinationRect;
01298
01299 GetTargetRect(&DestinationRect);
01300 *pDestinationLeft = DestinationRect.left;
01301 return NOERROR;
01302 }
01303
01304 STDMETHODIMP CBaseControlVideo::put_DestinationWidth(long DestinationWidth)
01305 {
01306 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01307 CAutoLock cInterfaceLock(m_pInterfaceLock);
01308 RECT DestinationRect;
01309 GetTargetRect(&DestinationRect);
01310 DestinationRect.right = DestinationRect.left + DestinationWidth;
01311
01312
01313
01314 HRESULT hr = CheckTargetRect(&DestinationRect);
01315 if (FAILED(hr)) {
01316 return hr;
01317 }
01318
01319
01320
01321 hr = SetTargetRect(&DestinationRect);
01322 if (FAILED(hr)) {
01323 return hr;
01324 }
01325 return OnUpdateRectangles();
01326 }
01327
01328 STDMETHODIMP CBaseControlVideo::get_DestinationWidth(long *pDestinationWidth)
01329 {
01330 CheckPointer(pDestinationWidth,E_POINTER);
01331 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01332 CAutoLock cInterfaceLock(m_pInterfaceLock);
01333 RECT DestinationRect;
01334
01335 GetTargetRect(&DestinationRect);
01336 *pDestinationWidth = WIDTH(&DestinationRect);
01337 return NOERROR;
01338 }
01339
01340 STDMETHODIMP CBaseControlVideo::put_DestinationTop(long DestinationTop)
01341 {
01342 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01343 CAutoLock cInterfaceLock(m_pInterfaceLock);
01344 RECT DestinationRect;
01345 GetTargetRect(&DestinationRect);
01346 DestinationRect.bottom = DestinationTop + HEIGHT(&DestinationRect);
01347 DestinationRect.top = DestinationTop;
01348
01349
01350
01351 HRESULT hr = CheckTargetRect(&DestinationRect);
01352 if (FAILED(hr)) {
01353 return hr;
01354 }
01355
01356
01357
01358 hr = SetTargetRect(&DestinationRect);
01359 if (FAILED(hr)) {
01360 return hr;
01361 }
01362 return OnUpdateRectangles();
01363 }
01364
01365 STDMETHODIMP CBaseControlVideo::get_DestinationTop(long *pDestinationTop)
01366 {
01367 CheckPointer(pDestinationTop,E_POINTER);
01368 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01369 CAutoLock cInterfaceLock(m_pInterfaceLock);
01370 RECT DestinationRect;
01371
01372 GetTargetRect(&DestinationRect);
01373 *pDestinationTop = DestinationRect.top;
01374 return NOERROR;
01375 }
01376
01377 STDMETHODIMP CBaseControlVideo::put_DestinationHeight(long DestinationHeight)
01378 {
01379 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01380 CAutoLock cInterfaceLock(m_pInterfaceLock);
01381 RECT DestinationRect;
01382 GetTargetRect(&DestinationRect);
01383 DestinationRect.bottom = DestinationRect.top + DestinationHeight;
01384
01385
01386
01387 HRESULT hr = CheckTargetRect(&DestinationRect);
01388 if (FAILED(hr)) {
01389 return hr;
01390 }
01391
01392
01393
01394 hr = SetTargetRect(&DestinationRect);
01395 if (FAILED(hr)) {
01396 return hr;
01397 }
01398 return OnUpdateRectangles();
01399 }
01400
01401 STDMETHODIMP CBaseControlVideo::get_DestinationHeight(long *pDestinationHeight)
01402 {
01403 CheckPointer(pDestinationHeight,E_POINTER);
01404 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01405 CAutoLock cInterfaceLock(m_pInterfaceLock);
01406 RECT DestinationRect;
01407
01408 GetTargetRect(&DestinationRect);
01409 *pDestinationHeight = HEIGHT(&DestinationRect);
01410 return NOERROR;
01411 }
01412
01413 STDMETHODIMP CBaseControlVideo::SetDefaultSourcePosition()
01414 {
01415 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01416 CAutoLock cInterfaceLock(m_pInterfaceLock);
01417 HRESULT hr = SetDefaultSourceRect();
01418 if (FAILED(hr)) {
01419 return hr;
01420 }
01421 return OnUpdateRectangles();
01422 }
01423
01424 STDMETHODIMP CBaseControlVideo::IsUsingDefaultSource()
01425 {
01426 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01427 CAutoLock cInterfaceLock(m_pInterfaceLock);
01428 return IsDefaultSourceRect();
01429 }
01430
01431 STDMETHODIMP CBaseControlVideo::SetDefaultDestinationPosition()
01432 {
01433 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01434 CAutoLock cInterfaceLock(m_pInterfaceLock);
01435 HRESULT hr = SetDefaultTargetRect();
01436 if (FAILED(hr)) {
01437 return hr;
01438 }
01439 return OnUpdateRectangles();
01440 }
01441
01442 STDMETHODIMP CBaseControlVideo::IsUsingDefaultDestination()
01443 {
01444 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01445 CAutoLock cInterfaceLock(m_pInterfaceLock);
01446 return IsDefaultTargetRect();
01447 }
01448
01449 STDMETHODIMP
01450 CBaseControlVideo::GetCurrentImage(long *pBufferSize,long *pVideoImage)
01451 {
01452 CheckPointer(pBufferSize,E_POINTER);
01453 CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
01454 CAutoLock cInterfaceLock(m_pInterfaceLock);
01455 FILTER_STATE State;
01456
01457
01458
01459 if (pVideoImage != NULL) {
01460 m_pFilter->GetState(0,&State);
01461 if (State != State_Paused) {
01462 return VFW_E_NOT_PAUSED;
01463 }
01464 return GetStaticImage(pBufferSize,pVideoImage);
01465 }
01466
01467
01468
01469 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
01470 if (pVideoInfo == NULL)
01471 return E_OUTOFMEMORY;
01472 RECT SourceRect;
01473 GetSourceRect(&SourceRect);
01474 return GetImageSize(pVideoInfo,pBufferSize,&SourceRect);
01475 }
01476
01477 HRESULT CBaseControlVideo::GetImageSize(VIDEOINFOHEADER *pVideoInfo,
01478 LONG *pBufferSize,
01479 RECT *pSourceRect)
01480 {
01481 NOTE("Entering GetImageSize");
01482 ASSERT(pSourceRect);
01483
01484
01485
01486 if (pSourceRect == NULL ||
01487 pVideoInfo == NULL ||
01488 pBufferSize == NULL) {
01489
01490 return E_UNEXPECTED;
01491 }
01492
01493
01494
01495 if (pVideoInfo->bmiHeader.biCompression != BI_RGB) {
01496 if (pVideoInfo->bmiHeader.biCompression != BI_BITFIELDS) {
01497 return E_INVALIDARG;
01498 }
01499 }
01500
01501 ASSERT(IsRectEmpty(pSourceRect) == FALSE);
01502
01503 BITMAPINFOHEADER bih;
01504 bih.biWidth = WIDTH(pSourceRect);
01505 bih.biHeight = HEIGHT(pSourceRect);
01506 bih.biBitCount = pVideoInfo->bmiHeader.biBitCount;
01507 LONG Size = DIBSIZE(bih);
01508 Size += GetBitmapFormatSize(HEADER(pVideoInfo)) - SIZE_PREHEADER;
01509 *pBufferSize = Size;
01510
01511 return NOERROR;
01512 }
01513
01514 HRESULT CBaseControlVideo::CopyImage(IMediaSample *pMediaSample,
01515 VIDEOINFOHEADER *pVideoInfo,
01516 LONG *pBufferSize,
01517 BYTE *pVideoImage,
01518 RECT *pSourceRect)
01519 {
01520 NOTE("Entering CopyImage");
01521 ASSERT(pSourceRect);
01522 BYTE *pCurrentImage;
01523
01524
01525
01526 if (pMediaSample == NULL || pSourceRect == NULL ||
01527 pVideoInfo == NULL || pVideoImage == NULL ||
01528 pBufferSize == NULL) {
01529
01530 return E_UNEXPECTED;
01531 }
01532
01533
01534
01535 if (pVideoInfo->bmiHeader.biCompression != BI_RGB) {
01536 if (pVideoInfo->bmiHeader.biCompression != BI_BITFIELDS) {
01537 return E_INVALIDARG;
01538 }
01539 }
01540
01541 ASSERT(IsRectEmpty(pSourceRect) == FALSE);
01542
01543 BITMAPINFOHEADER bih;
01544 bih.biWidth = WIDTH(pSourceRect);
01545 bih.biHeight = HEIGHT(pSourceRect);
01546 bih.biBitCount = pVideoInfo->bmiHeader.biBitCount;
01547 LONG Size = GetBitmapFormatSize(HEADER(pVideoInfo)) - SIZE_PREHEADER;
01548 LONG Total = Size + DIBSIZE(bih);
01549
01550
01551
01552 if (*pBufferSize < Total) {
01553 return E_OUTOFMEMORY;
01554 }
01555
01556
01557
01558 CopyMemory((PVOID)pVideoImage, (PVOID)&pVideoInfo->bmiHeader, Size);
01559 ((BITMAPINFOHEADER *)pVideoImage)->biWidth = WIDTH(pSourceRect);
01560 ((BITMAPINFOHEADER *)pVideoImage)->biHeight = HEIGHT(pSourceRect);
01561 ((BITMAPINFOHEADER *)pVideoImage)->biSizeImage = DIBSIZE(bih);
01562 BYTE *pImageData = pVideoImage + Size;
01563
01564
01565
01566 HRESULT hr = pMediaSample->GetPointer(&pCurrentImage);
01567 if (FAILED(hr)) {
01568 return hr;
01569 }
01570
01571
01572
01573 LONG ScanLine = (pVideoInfo->bmiHeader.biBitCount / 8) * WIDTH(pSourceRect);
01574 LONG LinesToSkip = pVideoInfo->bmiHeader.biHeight;
01575 LinesToSkip -= pSourceRect->top + HEIGHT(pSourceRect);
01576 pCurrentImage += LinesToSkip * DIBWIDTHBYTES(pVideoInfo->bmiHeader);
01577 pCurrentImage += pSourceRect->left * (pVideoInfo->bmiHeader.biBitCount / 8);
01578
01579
01580
01581 for (LONG Line = 0;Line < HEIGHT(pSourceRect);Line++) {
01582 CopyMemory((PVOID)pImageData, (PVOID)pCurrentImage, ScanLine);
01583 pImageData += DIBWIDTHBYTES(*(BITMAPINFOHEADER *)pVideoImage);
01584 pCurrentImage += DIBWIDTHBYTES(pVideoInfo->bmiHeader);
01585 }
01586 return NOERROR;
01587 }
01588
01589 HRESULT CBaseControlVideo::OnVideoSizeChange()
01590 {
01591
01592
01593 VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
01594 if (pVideoInfo == NULL)
01595 return E_OUTOFMEMORY;
01596 WORD Width = (WORD) pVideoInfo->bmiHeader.biWidth;
01597 WORD Height = (WORD) pVideoInfo->bmiHeader.biHeight;
01598
01599 return m_pFilter->NotifyEvent(EC_VIDEO_SIZE_CHANGED,
01600 MAKELPARAM(Width,Height),
01601 MAKEWPARAM(0,0));
01602 }
01603
01604 HRESULT CBaseControlVideo::CheckSourceRect(RECT *pSourceRect)
01605 {
01606 CheckPointer(pSourceRect,E_POINTER);
01607 LONG Width,Height;
01608 GetVideoSize(&Width,&Height);
01609
01610
01611
01612
01613 if ((pSourceRect->left >= pSourceRect->right) ||
01614 (pSourceRect->left < 0) ||
01615 (pSourceRect->top >= pSourceRect->bottom) ||
01616 (pSourceRect->top < 0)) {
01617
01618 return E_INVALIDARG;
01619 }
01620
01621
01622
01623 if ((pSourceRect->right > Width) ||
01624 (pSourceRect->bottom > Height)) {
01625
01626 return E_INVALIDARG;
01627 }
01628 return NOERROR;
01629 }
01630
01631 HRESULT CBaseControlVideo::CheckTargetRect(RECT *pTargetRect)
01632 {
01633
01634
01635 if (pTargetRect == NULL) {
01636 return E_POINTER;
01637 }
01638
01639
01640
01641 if (pTargetRect->left > pTargetRect->right ||
01642 pTargetRect->top > pTargetRect->bottom) {
01643 return E_INVALIDARG;
01644 }
01645
01646
01647
01648 if (WIDTH(pTargetRect) <= 0 || HEIGHT(pTargetRect) <= 0) {
01649 return E_INVALIDARG;
01650 }
01651
01652 ASSERT(IsRectEmpty(pTargetRect) == FALSE);
01653 return NOERROR;
01654 }
01655