plugins/multimedia/wmp/qwmpvideooverlay.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qwmpvideooverlay.h"
       
    43 
       
    44 #include "qwmpglobal.h"
       
    45 
       
    46 QWmpVideoOverlay::QWmpVideoOverlay(IWMPPlayer4 *player, IOleObject *object, QWmpPlayerService *service)
       
    47     : m_service(service)
       
    48     , m_player(player)
       
    49     , m_object(object)
       
    50     , m_inPlaceObject(0)
       
    51     , m_winId(0)
       
    52     , m_aspectRatioMode(Qt::KeepAspectRatio)
       
    53     , m_fullScreen(false)
       
    54 {
       
    55     HRESULT hr;
       
    56 
       
    57     if ((hr = m_object->QueryInterface(
       
    58             __uuidof(IOleInPlaceObject),
       
    59             reinterpret_cast<void **>(&m_inPlaceObject))) != S_OK) {
       
    60         qWarning("No IOleInPlaceObject interface, %x: %s", hr, qwmp_error_string(hr));
       
    61     }
       
    62 }
       
    63 
       
    64 QWmpVideoOverlay::~QWmpVideoOverlay()
       
    65 {
       
    66     if (m_inPlaceObject)
       
    67         m_inPlaceObject->Release();
       
    68 }
       
    69 
       
    70 WId QWmpVideoOverlay::winId() const
       
    71 {
       
    72     return m_winId;
       
    73 }
       
    74 
       
    75 void QWmpVideoOverlay::setWinId(WId id)
       
    76 {
       
    77     m_winId = id;
       
    78 
       
    79     if (m_inPlaceObject && m_winId) {
       
    80         RECT rcPos = 
       
    81         { 
       
    82             m_displayRect.left(),
       
    83             m_displayRect.top(),
       
    84             m_displayRect.right(),
       
    85             m_displayRect.bottom() 
       
    86         };
       
    87 
       
    88         m_inPlaceObject->InPlaceDeactivate();
       
    89         m_object->DoVerb(OLEIVERB_INPLACEACTIVATE, 0, m_service, 0, m_winId, &rcPos);
       
    90     }
       
    91 
       
    92 
       
    93 }
       
    94 
       
    95 extern HDC Q_GUI_EXPORT qt_win_display_dc();
       
    96 
       
    97 #define HIMETRIC_PER_INCH   2540
       
    98 #define MAP_PIX_TO_LOGHIM(x,ppli)   ((HIMETRIC_PER_INCH*(x) + ((ppli)>>1)) / (ppli))
       
    99 #define MAP_LOGHIM_TO_PIX(x,ppli)   (((ppli)*(x) + HIMETRIC_PER_INCH/2) / HIMETRIC_PER_INCH)
       
   100 
       
   101 QRect QWmpVideoOverlay::displayRect() const
       
   102 {
       
   103     return m_displayRect;
       
   104 }
       
   105 
       
   106 void QWmpVideoOverlay::setDisplayRect(const QRect &rect)
       
   107 {
       
   108     m_displayRect = rect;
       
   109 
       
   110     if (m_inPlaceObject) {
       
   111         HDC gdc = QT_PREPEND_NAMESPACE(qt_win_display_dc)();
       
   112 
       
   113         SIZEL hmSize = {
       
   114                 MAP_PIX_TO_LOGHIM(rect.width(), GetDeviceCaps(gdc, LOGPIXELSX)),
       
   115                 MAP_PIX_TO_LOGHIM(rect.height(), GetDeviceCaps(gdc, LOGPIXELSY)) };
       
   116 
       
   117         m_object->SetExtent(DVASPECT_CONTENT, &hmSize);
       
   118 
       
   119         RECT rcClip = { rect.left(), rect.top(), rect.right(), rect.bottom() };
       
   120 
       
   121         if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
       
   122             QSize size = m_sizeHint;
       
   123             size.scale(rect.width(), rect.height(), Qt::KeepAspectRatioByExpanding);
       
   124 
       
   125             QRect positionRect(QPoint(0, 0), size);
       
   126             positionRect.moveCenter(rect.center());
       
   127 
       
   128             RECT rcPos = 
       
   129             { 
       
   130                 positionRect.left(),
       
   131                 positionRect.top(),
       
   132                 positionRect.right(),
       
   133                 positionRect.bottom()
       
   134             };
       
   135 
       
   136             m_inPlaceObject->SetObjectRects(&rcPos, &rcClip);
       
   137         } else {
       
   138             m_inPlaceObject->SetObjectRects(&rcClip, &rcClip);
       
   139         }
       
   140     }
       
   141 }
       
   142 
       
   143 bool QWmpVideoOverlay::isFullScreen() const
       
   144 {
       
   145     return m_fullScreen;
       
   146 }
       
   147 
       
   148 void QWmpVideoOverlay::setFullScreen(bool fullScreen)
       
   149 {
       
   150     m_player->put_fullScreen(fullScreen);
       
   151 
       
   152     emit fullScreenChanged(m_fullScreen = fullScreen);
       
   153 }
       
   154 
       
   155 QSize QWmpVideoOverlay::nativeSize() const
       
   156 {
       
   157     return m_sizeHint;
       
   158 }
       
   159 
       
   160 void QWmpVideoOverlay::setNativeSize(const QSize &size)
       
   161 {    
       
   162     if (m_sizeHint != size) {
       
   163         m_sizeHint = size;
       
   164 
       
   165         emit nativeSizeChanged();
       
   166     }
       
   167 }
       
   168 
       
   169 Qt::AspectRatioMode QWmpVideoOverlay::aspectRatioMode() const
       
   170 {
       
   171     return m_aspectRatioMode;
       
   172 }
       
   173 
       
   174 void QWmpVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode)
       
   175 {
       
   176     m_aspectRatioMode = mode;
       
   177 
       
   178     m_player->put_stretchToFit(mode != Qt::KeepAspectRatio);
       
   179 
       
   180     setDisplayRect(m_displayRect);
       
   181 }
       
   182 
       
   183 void QWmpVideoOverlay::repaint()
       
   184 {
       
   185 }
       
   186 
       
   187 int QWmpVideoOverlay::brightness() const
       
   188 {
       
   189     return 0;
       
   190 }
       
   191 
       
   192 void QWmpVideoOverlay::setBrightness(int)
       
   193 {
       
   194 }
       
   195 
       
   196 int QWmpVideoOverlay::contrast() const
       
   197 {
       
   198     return 0;
       
   199 }
       
   200 
       
   201 void QWmpVideoOverlay::setContrast(int)
       
   202 {
       
   203 }
       
   204 
       
   205 int QWmpVideoOverlay::hue() const
       
   206 {
       
   207     return 0;
       
   208 }
       
   209 
       
   210 void QWmpVideoOverlay::setHue(int)
       
   211 {
       
   212 }
       
   213 
       
   214 int QWmpVideoOverlay::saturation() const
       
   215 {
       
   216     return 0;
       
   217 }
       
   218 
       
   219 void QWmpVideoOverlay::setSaturation(int)
       
   220 {
       
   221 }
       
   222 
       
   223 // IUnknown
       
   224 HRESULT QWmpVideoOverlay::QueryInterface(REFIID riid, void **object)
       
   225 {
       
   226     return m_service->QueryInterface(riid, object);
       
   227 }
       
   228 
       
   229 ULONG QWmpVideoOverlay::AddRef()
       
   230 {
       
   231     return m_service->AddRef();
       
   232 }
       
   233 
       
   234 ULONG QWmpVideoOverlay::Release()
       
   235 {
       
   236     return m_service->Release();
       
   237 }
       
   238 
       
   239 // IOleWindow
       
   240 HRESULT QWmpVideoOverlay::GetWindow(HWND *phwnd)
       
   241 {
       
   242     if (!phwnd) {
       
   243         return E_POINTER;
       
   244     } else {
       
   245         *phwnd = m_winId;
       
   246         return S_OK;
       
   247     }
       
   248 }
       
   249 
       
   250 HRESULT QWmpVideoOverlay::ContextSensitiveHelp(BOOL fEnterMode)
       
   251 {
       
   252     Q_UNUSED(fEnterMode);
       
   253 
       
   254     return E_NOTIMPL;
       
   255 }
       
   256 
       
   257 // IOleInPlaceSite
       
   258 HRESULT QWmpVideoOverlay::CanInPlaceActivate()
       
   259 {
       
   260     return S_OK;
       
   261 }
       
   262 
       
   263 HRESULT QWmpVideoOverlay::OnInPlaceActivate()
       
   264 {
       
   265     return S_OK;
       
   266 }
       
   267 
       
   268 HRESULT QWmpVideoOverlay::OnUIActivate()
       
   269 {
       
   270     return S_OK;
       
   271 }
       
   272 
       
   273 HRESULT QWmpVideoOverlay::GetWindowContext(
       
   274         IOleInPlaceFrame **ppFrame,
       
   275         IOleInPlaceUIWindow **ppDoc,
       
   276         LPRECT lprcPosRect,
       
   277         LPRECT lprcClipRect,
       
   278         LPOLEINPLACEFRAMEINFO lpFrameInfo)
       
   279 {
       
   280     if (!ppFrame || !ppDoc || !lprcPosRect || !lprcClipRect || !lpFrameInfo)
       
   281         return E_POINTER;
       
   282 
       
   283     QueryInterface(IID_IOleInPlaceFrame, reinterpret_cast<void **>(ppFrame));
       
   284     QueryInterface(IID_IOleInPlaceUIWindow, reinterpret_cast<void **>(ppDoc));
       
   285 
       
   286     if (m_winId) {
       
   287         SetRect(lprcClipRect,
       
   288                 m_displayRect.left(),
       
   289                 m_displayRect.top(),
       
   290                 m_displayRect.right(),
       
   291                 m_displayRect.bottom());
       
   292 
       
   293         if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
       
   294             QSize size = m_sizeHint;
       
   295             size.scale(
       
   296                 m_displayRect.width(),
       
   297                 m_displayRect.height(),
       
   298                 Qt::KeepAspectRatioByExpanding);
       
   299 
       
   300             QRect positionRect(QPoint(0, 0), size);
       
   301             positionRect.moveCenter(m_displayRect.center());
       
   302 
       
   303             SetRect(lprcPosRect,
       
   304                     positionRect.left(),
       
   305                     positionRect.top(),
       
   306                     positionRect.right(),
       
   307                     positionRect.bottom());
       
   308         } else {
       
   309             *lprcPosRect = *lprcClipRect;
       
   310         }
       
   311     } else {
       
   312         SetRectEmpty(lprcPosRect);
       
   313         SetRectEmpty(lprcClipRect);
       
   314     }
       
   315 
       
   316     lpFrameInfo->fMDIApp = FALSE;
       
   317     lpFrameInfo->haccel = 0;
       
   318     lpFrameInfo->cAccelEntries = 0;
       
   319     lpFrameInfo->hwndFrame = m_winId;
       
   320 
       
   321     return S_OK;
       
   322 }
       
   323 
       
   324 HRESULT QWmpVideoOverlay::Scroll(SIZE scrollExtant)
       
   325 {
       
   326     Q_UNUSED(scrollExtant);
       
   327 
       
   328     return S_FALSE;
       
   329 }
       
   330 
       
   331 HRESULT QWmpVideoOverlay::OnUIDeactivate(BOOL fUndoable)
       
   332 {
       
   333     Q_UNUSED(fUndoable);
       
   334 
       
   335     return S_OK;
       
   336 }
       
   337 
       
   338 HRESULT QWmpVideoOverlay::OnInPlaceDeactivate()
       
   339 {
       
   340     return S_OK;
       
   341 }
       
   342 
       
   343 HRESULT QWmpVideoOverlay::DiscardUndoState()
       
   344 {
       
   345     return S_OK;
       
   346 }
       
   347 
       
   348 HRESULT QWmpVideoOverlay::DeactivateAndUndo()
       
   349 {
       
   350     if (m_inPlaceObject)
       
   351         m_inPlaceObject->UIDeactivate();
       
   352 
       
   353     return S_OK;
       
   354 }
       
   355 
       
   356 HRESULT QWmpVideoOverlay::OnPosRectChange(LPCRECT lprcPosRect)
       
   357 {
       
   358     Q_UNUSED(lprcPosRect);
       
   359 
       
   360     return S_OK;
       
   361 }
       
   362 
       
   363 // IOleInPlaceUIWindow
       
   364 HRESULT QWmpVideoOverlay::GetBorder(LPRECT lprectBorder)
       
   365 {
       
   366     Q_UNUSED(lprectBorder);
       
   367 
       
   368     return INPLACE_E_NOTOOLSPACE;
       
   369 }
       
   370 
       
   371 HRESULT QWmpVideoOverlay::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths)
       
   372 {
       
   373     Q_UNUSED(pborderwidths);
       
   374 
       
   375     return INPLACE_E_NOTOOLSPACE;
       
   376 }
       
   377 
       
   378 HRESULT QWmpVideoOverlay::SetBorderSpace(LPCBORDERWIDTHS pborderwidths)
       
   379 {
       
   380     Q_UNUSED(pborderwidths);
       
   381 
       
   382     return OLE_E_INVALIDRECT;
       
   383 }
       
   384 
       
   385 HRESULT QWmpVideoOverlay::SetActiveObject(
       
   386         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
       
   387 {
       
   388     Q_UNUSED(pActiveObject);
       
   389     Q_UNUSED(pszObjName);
       
   390 
       
   391     return  S_OK;
       
   392 }
       
   393 
       
   394 // IOleInPlaceFrame
       
   395 HRESULT QWmpVideoOverlay::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
       
   396 {
       
   397     Q_UNUSED(hmenuShared);
       
   398     Q_UNUSED(lpMenuWidths);
       
   399 
       
   400     return E_NOTIMPL;
       
   401 }
       
   402 
       
   403 HRESULT QWmpVideoOverlay::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
       
   404 {
       
   405     Q_UNUSED(hmenuShared);
       
   406     Q_UNUSED(holemenu);
       
   407     Q_UNUSED(hwndActiveObject);
       
   408 
       
   409     return E_NOTIMPL;
       
   410 }
       
   411 
       
   412 HRESULT QWmpVideoOverlay::RemoveMenus(HMENU hmenuShared)
       
   413 {
       
   414     Q_UNUSED(hmenuShared);
       
   415 
       
   416     return E_NOTIMPL;
       
   417 }
       
   418 
       
   419 HRESULT QWmpVideoOverlay::SetStatusText(LPCOLESTR pszStatusText)
       
   420 {
       
   421     Q_UNUSED(pszStatusText);
       
   422 
       
   423     return E_NOTIMPL;
       
   424 }
       
   425 
       
   426 HRESULT QWmpVideoOverlay::EnableModeless(BOOL fEnable)
       
   427 {
       
   428     Q_UNUSED(fEnable);
       
   429 
       
   430     return E_NOTIMPL;
       
   431 }
       
   432 
       
   433 HRESULT QWmpVideoOverlay::TranslateAccelerator(LPMSG lpmsg, WORD wID)
       
   434 {
       
   435     return TranslateAccelerator(lpmsg, static_cast<DWORD>(wID));
       
   436 }