winsite.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:96k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: winsite.cpp,v 1.4.34.2 2004/07/26 08:59:45 pankajgupta Exp $
  3.  *
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  *
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  *
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  *
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  *
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  *
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  *
  46.  * Contributor(s):
  47.  *
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxcom.h"
  50. #include "hxtypes.h"
  51. #include "hxwintyp.h"
  52. #include "ihxpckts.h"
  53. #include "hxwin.h"
  54. #include "hxengin.h"
  55. #include "hxsite2.h"
  56. #include "hxevent.h"
  57. #include "hxcomm.h"
  58. #include "hxstrutl.h"
  59. #include "hxvsurf.h"
  60. #include "basesite.h"
  61. #include "winsite.h"
  62. //#include "hxwinver.h"
  63. #include "diballoc.h"
  64. #include "ihxpckts.h"
  65. #include "hxprefs.h"
  66. #include "hxtick.h"
  67. #include "sitetext.h"
  68. #include "hxcore.h"
  69. #include "hxthread.h"
  70. #include "hxheap.h"
  71. #include "basesurf.h"
  72. #include "mmx_util.h"
  73. #include "colormap.h"
  74. #ifdef _DEBUG
  75. #undef HX_THIS_FILE
  76. static const char HX_THIS_FILE[] = __FILE__;
  77. #endif
  78. #define MODE_SEPERATOR                          "|"
  79. #define REGKEY_FULLSCREEN_DATA                  "FullScreenData"
  80. #define REGKEY_FULLSCREEN_TEST_MODES            "TestModes"
  81. #define REGKEY_FULLSCREEN_PREFERED_MODE         "PreferedMode"
  82. #define TEST_THRESHOLD                          30
  83. #define REGKEY_FULLSCREEN_POSTAGE_STAMP         "PostageStamp"
  84. #define TEST_LENGTH                             6000
  85. // These SPI_ flags are not defined in header files with MSDEV 5.0, so
  86. // that is why these are needed.  These can be removed when we compile
  87. // with a newer version of the compiler
  88. #ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
  89. #define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
  90. #endif /* SPI_GETFOREGROUNDLOCKTIMEOUT */
  91. #ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
  92. #define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
  93. #endif /* SPI_SETFOREGROUNDLOCKTIMEOUT */
  94. #define NO_HOOK_FOUND_RETURNING_WITH_ZERO 0
  95. CHXMapPtrToPtr      CHXWinSite::zm_ParentWnds;
  96. CHXMapPtrToPtr      CHXWinSite::zm_ParentsThreadList;
  97. CHXMapPtrToPtr      CHXWinSite::zm_SubclassedWnds;
  98. CHXMapPtrToPtr      CHXWinSite::zm_ScrollBarWnds;
  99. CHXMapPtrToPtr      CHXWinSite::zm_ListOfHiddenWindows;
  100. char*               CHXWinSite::zm_pszWindowClassName       = "HXWinVideoClass";
  101. char*               CHXWinSite::zm_pszWindowName            = "HXWinVideoWindow";
  102. INT32               CHXWinSite::zm_nInstanceCount           = 0;
  103. BOOL g_bPrintSiteData = FALSE;
  104. // convert from HXxPoint pt to Windows POINT
  105. POINT WINPOINT(HXxPoint pt)
  106. {
  107.     POINT winPt;
  108.     winPt.x = pt.x;
  109.     winPt.y = pt.y;
  110.     return winPt;
  111. }
  112. BOOL CALLBACK HXxRemoveWindows( HWND hwnd, LPARAM lParam)
  113. {
  114.     void* This;
  115.     BOOL bVisible;
  116.     if (!CHXWinSite::zm_SubclassedWnds.Lookup((void*)hwnd,This))
  117.     {
  118.         bVisible = IsWindowVisible(hwnd);
  119.         if (bVisible)
  120.         {
  121.             CHXWinSite::zm_ListOfHiddenWindows.SetAt(hwnd, hwnd);
  122.             ::ShowWindow(hwnd, SW_HIDE);
  123.         }
  124.     }
  125.     return TRUE;
  126. }
  127. /************************************************************************
  128.  *  Method:
  129.  *    Constructor
  130.  */
  131. CHXWinSite::CHXWinSite(IUnknown* pContext, IUnknown* pUnkOuter, INT32 lZorder)
  132.     : CHXBaseSite(pContext, pUnkOuter, lZorder)
  133.     , m_oldWndProc(NULL)
  134.     , m_hXSlider(NULL)
  135.     , m_hYSlider(NULL)
  136.     , m_windowParent(NULL)
  137.     , m_pContainingWindow(NULL)
  138. {
  139.     InitializeCriticalSection(&m_CriticalSection);
  140.     m_ulSiteThreadID = GetCurrentThreadId();
  141. }
  142. /************************************************************************
  143.  *  Method:
  144.  *    Destructor
  145.  */
  146. CHXWinSite::~CHXWinSite()
  147. {
  148.     DeleteCriticalSection(&m_CriticalSection);
  149.     UnHookParents();
  150. }
  151. void
  152. CHXWinSite::_NeedWindowedSite()
  153. {
  154.     UINT32 ulFlags = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  155.     if (m_bIsVisible)
  156.     {
  157.         ulFlags |= WS_VISIBLE;
  158.     }
  159.     if (m_pTopLevelSite && m_pTopLevelSite->m_pWindow)
  160.     {
  161.         Create(m_pTopLevelSite->m_pWindow->window, ulFlags);
  162.     }
  163. }
  164. /************************************************************************
  165.  *  Method:
  166.  *    IHXSiteWindowed::Create
  167.  */
  168. void*
  169. CHXWinSite::_Create(void* ParentWindow, UINT32 style)
  170. {
  171. /*
  172.  * Make sure the window class is registered.
  173.  */
  174.     RegisterClass();
  175.     HWND hWnd = CreateWindowEx(NULL,
  176.                                zm_pszWindowClassName,
  177.                                zm_pszWindowName,
  178.                                style,
  179.                                0,
  180.                                0,
  181.                                0,
  182.                                0,
  183.                                (HWND)ParentWindow,
  184.                                NULL,
  185.                                GetModuleHandle(NULL),
  186.                                NULL);
  187.     return hWnd;
  188. }
  189. /************************************************************************
  190.  *  Method:
  191.  *    IHXSiteWindowed::Destroy
  192.  */
  193. void
  194. CHXWinSite::_Destroy(HXxWindow* pWindow)
  195. {
  196.     BOOL retVal = ::DestroyWindow((HWND) pWindow->window);
  197.     UnRegisterClass();
  198. }
  199. /************************************************************************
  200.  *  Method:
  201.  *    CHXBaseSite::AttachWindow
  202.  */
  203. void
  204. CHXWinSite::_AttachWindow()
  205. {
  206.     HX_ASSERT(GetWindow() && GetWindow()->window);
  207.     m_oldWndProc = (WNDPROC)::GetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC);
  208.     ::SetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC,(DWORD)HXxWinHookSiteProc);
  209.     zm_SubclassedWnds.SetAt(GetWindow()->window,this);
  210.     if (!m_pParentSite)
  211.     {
  212.         HookParents();
  213.     }
  214. }
  215. /************************************************************************
  216.  *  Method:
  217.  *    IHXSiteWindowed::DetachWindow
  218.  */
  219. void CHXWinSite::_DetachWindow()
  220. {
  221.     ::SetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC,(DWORD)m_oldWndProc);
  222.     zm_SubclassedWnds.RemoveKey(GetWindow()->window);
  223.     UnHookParents();
  224.     m_oldWndProc = NULL;
  225. }
  226. /************************************************************************
  227.  *  Function:
  228.  *    CHXWinSiteWindowedProc
  229.  */
  230. LRESULT HXEXPORT CHXWinSiteWindowedProc
  231. (
  232.     HWND hWnd,
  233.     UINT message,
  234.     WPARAM uParam,
  235.     LPARAM lParam
  236.     )
  237. {
  238.     return (DefWindowProc(hWnd, message, uParam, lParam));
  239. }
  240. /************************************************************************
  241.  *  Function:
  242.  *    RegisterClass
  243.  */
  244. void
  245. CHXWinSite::RegisterClass()
  246. {
  247.     if (0 == zm_nInstanceCount)
  248.     {
  249.         WNDCLASS wndClass;
  250.         ATOM result;
  251.         wndClass.style = 0;
  252.         wndClass.lpfnWndProc = CHXWinSiteWindowedProc;
  253.         wndClass.cbClsExtra = 0;
  254.         wndClass.cbWndExtra = 0;
  255.         wndClass.hInstance = GetModuleHandle(NULL);
  256.         wndClass.hIcon = NULL;
  257.         wndClass.hCursor = NULL;
  258.         wndClass.hbrBackground = NULL;
  259.         wndClass.lpszMenuName = NULL;
  260.         wndClass.lpszClassName = zm_pszWindowClassName;
  261.         result = ::RegisterClass(&wndClass);
  262.         HX_ASSERT(result);
  263.     }
  264.     zm_nInstanceCount++;
  265. }
  266. /************************************************************************
  267.  *  Function:
  268.  *    UnRegisterClass
  269.  */
  270. void
  271. CHXWinSite::UnRegisterClass()
  272. {
  273.     HX_ASSERT(zm_nInstanceCount > 0);
  274.     if (zm_nInstanceCount > 0)
  275.     {
  276.         zm_nInstanceCount--;
  277.     }
  278.     if (0 == zm_nInstanceCount)
  279.     {
  280.         BOOL result = ::UnregisterClass(zm_pszWindowClassName,GetModuleHandle(NULL));
  281.         HX_ASSERT(result);
  282.     }
  283. }
  284. void CHXWinSite::HookParents()
  285. {
  286.     HWND hWnd = (HWND)GetWindow()->window;
  287.     DWORD process = 0;
  288.     while (hWnd)
  289.     {
  290.         int thread = GetWindowThreadProcessId(hWnd, &process);
  291.         CParentWindowThreadData* pData = NULL;
  292.         int threadRefCount = 0;
  293.         if (!CHXWinSite::zm_ParentsThreadList.Lookup((void*)thread, (void*&) pData))
  294.         {
  295.             pData = new CParentWindowThreadData();
  296.             pData->m_hHook              = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)HXxWinHookChar, NULL, thread);
  297.             pData->m_hHookAllMessage    = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)HXxWinHookAllMessages, NULL, thread);
  298.             CHXWinSite::zm_ParentsThreadList.SetAt((void*)thread, (void*)pData);
  299.         }
  300.         /*
  301.          *  Don't I wish I could keep a simple RefCount. The problem with that
  302.          *  would be if ANY of these parent poped out of the chain (a possiblility)
  303.          *  then we would not remove the hook. And you know what happens if we
  304.          *  do not remove the hook ... boom *crash IE*. And people do not like that.
  305.          */
  306.         if (!pData->m_ListOfTopLevelSites.Find(m_pTopLevelSite))
  307.         {
  308.             pData->m_ListOfTopLevelSites.AddTail(m_pTopLevelSite);
  309.         }
  310.         CHXSimpleList* pChildrenList;
  311.         if (!CHXWinSite::zm_ParentWnds.Lookup((void*)hWnd,(void*&) pChildrenList))
  312.         {
  313.             pChildrenList = new CHXSimpleList;
  314.             CHXWinSite::zm_ParentWnds.SetAt((void*)hWnd, (void*)pChildrenList);
  315.         }
  316.         LISTPOSITION pos = pChildrenList->Find(this);
  317.         HX_ASSERT(pos == NULL);
  318.         if (!pos)
  319.         {
  320.             pChildrenList->AddTail(this);
  321.         }
  322.         hWnd = GetParent(hWnd);
  323.     }
  324. }
  325. void
  326. CHXWinSite::UnHookParents()
  327. {
  328. /*
  329.  * make sure to remove any reference to this object from the parent map.
  330.  * We do not use Getparent calls here since the parent chain may have
  331.  * changed AFTER call to HookParents().
  332.  *
  333.  */
  334.     HWND hWnd;
  335.     CHXSimpleList* pChildrenList;
  336.     POSITION pos = zm_ParentWnds.GetStartPosition();
  337.     while (pos)
  338.     {
  339.         zm_ParentWnds.GetNextAssoc(pos, (void*&) hWnd, (void*&) pChildrenList);
  340.         LISTPOSITION listpos = pChildrenList->Find(this);
  341.         if (listpos)
  342.         {
  343.             pChildrenList->RemoveAt(listpos);
  344.             if (!pChildrenList->GetCount())
  345.             {
  346.                 pos = CHXWinSite::zm_ParentWnds.Remove((void*)hWnd);
  347.                 HX_DELETE(pChildrenList);
  348.             }
  349.         }
  350.     }
  351.     /* are we a top level site? If so we may have to clean up
  352.      * some of our Window Hooks.
  353.      */
  354.     if (m_pTopLevelSite == this)
  355.     {
  356.         DWORD thread;
  357.         CParentWindowThreadData* pData = NULL;
  358.         POSITION pos = zm_ParentsThreadList.GetStartPosition();
  359.         while (pos)
  360.         {
  361.             zm_ParentsThreadList.GetNextAssoc(pos, (void*&) thread, (void*&) pData);
  362.             LISTPOSITION listpos = pData->m_ListOfTopLevelSites.Find(this);
  363.             if (listpos)
  364.             {
  365.                 pData->m_ListOfTopLevelSites.RemoveAt(listpos);
  366.                 if (!pData->m_ListOfTopLevelSites.GetCount())
  367.                 {
  368.                     UnhookWindowsHookEx(pData->m_hHook);
  369.                     UnhookWindowsHookEx(pData->m_hHookAllMessage);
  370.                     pos = CHXWinSite::zm_ParentsThreadList.Remove((void*)thread);
  371.                     delete pData;
  372.                 }
  373.             }
  374.         }
  375.     }
  376. }
  377. void
  378. CHXWinSite::_SetSize(HXxSize size)
  379. {
  380.     // generate an OS event
  381.     HX_ASSERT(m_pWindow && m_pWindow->window);
  382.     /*
  383.      * Change the size of the window using platform specific calls.
  384.      * Note: the size being requested is the "client" size for the
  385.      * window, so we need to actually determine the outer rect size.
  386.      * We do this by getting the current window rect and client rect,
  387.      * the difference is the "extra" size associated with any window
  388.      * dressing.
  389.      */
  390.     HWND tempHwnd = (HWND) GetWindow()->window;
  391.     RECT rect1;
  392.     ::GetWindowRect(tempHwnd,&rect1);
  393.     MapWindowPoints(NULL, GetParent(tempHwnd), (POINT*)&rect1, 2);
  394.     SafeMoveWindow( tempHwnd,
  395.                     (int)rect1.left, (int)rect1.top,
  396.                     (int)size.cx, (int)size.cy,
  397.                     m_bIsVisible);
  398. }
  399. void CHXWinSite::_SetPosition(HXxPoint position)
  400. {
  401.     //Since I just flattened the window structure this function has to
  402.     //me modified to take that into account.
  403.     if(m_pWindow->window && !m_bWindowCreatedByCreate)
  404.     {
  405.         SafeMoveWindow((HWND)m_pWindow->window,
  406.                        (int)m_topleft.x,
  407.                        (int)m_topleft.y,
  408.                        (int)m_size.cx ,
  409.                        (int)m_size.cy ,
  410.                        m_bIsVisible);
  411.     }
  412.     else
  413.     {
  414.         SafeMoveWindow((HWND) GetWindow()->window,
  415.                        (int)position.x,
  416.                        (int)position.y,
  417.                        (int)m_size.cx ,
  418.                        (int)m_size.cy ,
  419.                        m_bIsVisible);
  420.     }
  421. }
  422. void CHXWinSite::_DamageRect(HXxRect rect)
  423. {
  424. //     if (m_pVideoSurface && m_pVideoSurface->m_nBltMode == HX_OVERLAY_BLT)
  425. //     {
  426. //         return;
  427. //     }
  428. //     // We need to tell the os that we are modifing the video window.
  429. //     // The mechanism for doing this is to call invaliadteRect, and
  430. //     // then to respond to the WM_PAINT. Of course we are going to
  431. //     // respond to the 'WM_PAINT' before we get the WM_PAINT by the
  432. //     // renderer calling forceRedraw. Thus, we will remember the rect
  433. //     // and see if it bounds the PaintStruct we get in our subsequent
  434. //     // paint. If so then we will ignore it. While this is not the
  435. //     // optimal solution, we have little choice due to dead locking
  436. //     // issues.
  437. //     HXxWindow* pwindow = GetWindow();
  438. //     if(pwindow && pwindow->window)
  439. //     {
  440. //         RECT overAllrect;
  441. //         HDC hdc = ::GetDC((HWND)pwindow->window);
  442. //         int retVal = ::GetClipBox(hdc, &overAllrect);
  443. //         ::IntersectRect( (RECT*)&rect, (RECT*)&rect, &overAllrect );
  444. //         if (retVal != NULLREGION)
  445. //         {
  446. //             //If any of a set of test points is not visible, then we
  447. //             //will assume there is a drop down menu over us and invalidate
  448. //             //it.
  449. //             //XXXgfw Currect test points will be four corners and center point.
  450. //             BOOL bVisible = TRUE;
  451. //             int  middleY  = rect.top+(rect.bottom-rect.top)/2;
  452. //             int  middleX  = rect.left+(rect.right-rect.left)/2;
  453. //             bVisible = bVisible && ::PtVisible( hdc, rect.left,    rect.top);
  454. //             bVisible = bVisible && ::PtVisible( hdc, rect.right-1, rect.top);
  455. //             bVisible = bVisible && ::PtVisible( hdc, rect.left,    rect.bottom-1);
  456. //             bVisible = bVisible && ::PtVisible( hdc, rect.right-1, rect.bottom-1);
  457. //             bVisible = bVisible && ::PtVisible( hdc, middleX,      middleY );
  458. //             //XXXgfw We are still getting artifacts from drop down
  459. //             //menus that go too fast. Guess we have to invalidate our
  460. //             //whole window.
  461. //             if( !bVisible )
  462. //             {
  463. //                 ::InvalidateRect((HWND)pwindow->window, (RECT*)NULL, FALSE);
  464. //             }
  465. //         }
  466. //         ReleaseDC((HWND)pwindow->window, hdc);
  467. //     }
  468. }
  469. BOOL CHXWinSite::_ShouldEnterForceRedraw()
  470. {
  471.     if (InterlockedIncrement(&m_lBltEntryCount) > 1)
  472.     {
  473.         InterlockedDecrement(&m_lBltEntryCount);
  474.         return FALSE;
  475.     }
  476.     return TRUE;
  477. }
  478. void
  479. CHXWinSite::_ExitForceRedraw()
  480. {
  481.     InterlockedDecrement(&m_lBltEntryCount);
  482. }
  483. void
  484. CHXWinSite::_SendOSUpdateMessage()
  485. {
  486.     InvalidateRect((HWND) GetWindow()->window, NULL, FALSE);
  487.     SafeUpdateWindow((HWND) GetWindow()->window);
  488. }
  489. void
  490. CHXWinSite::_ShowSite(BOOL bShow)
  491. {
  492.     if( m_pWindow && m_pWindow->window)
  493.     {
  494.         SafeShowWindow((HWND)m_pWindow->window, bShow ? SW_SHOW : SW_HIDE);
  495.     }
  496. }
  497. BOOL
  498. CHXWinSite::_AtSystemTime()
  499. {
  500.     return (m_ulSiteThreadID == GetCurrentThreadId());
  501. }
  502. BOOL
  503. CHXWinSite::_HandleOSEvents(HXxEvent* /*IN*/ pEvent)
  504. {
  505.     BOOL ret = FALSE;
  506.     switch (pEvent->event)
  507.     {
  508.        case WM_NCHITTEST:
  509.            if (m_pTopLevelSite->m_bSetCaptureOn)
  510.            {
  511.                if( m_pTopLevelSite->m_pCaptureUser )
  512.                    m_pTopLevelSite->m_pCaptureUser->HandleEvent(pEvent);
  513.            }
  514.            ret = TRUE;
  515.            break;
  516.        case WM_CHAR:
  517.        case WM_KEYDOWN:
  518.        case WM_KEYUP:
  519.        {
  520.            //Check to see if focus has been set if so send the message
  521.            //only to that window.
  522.            //XXXgfw, we need to revisit this idea of a focus site.
  523.            //with this code added only the site that was last clicked
  524.            //gets the native event. No children, no nothing. The user
  525.            //is bound to click a site at random just to bring the player
  526.            //to the top of the window stack for example...
  527. //           CHXBaseSite* pFocusSite;
  528. //           pFocusSite = m_pTopLevelSite->GetFocusSite();
  529. //           if (pFocusSite)
  530. //           {
  531. //              if (pFocusSite == this)
  532. //              {
  533. //                 // we have already called HandleEvent on the original
  534. //                 // user in HandleWndProc
  535. //                 if (pEvent->window != GetWindow()->window)
  536. //                 {
  537. //                    m_pUser->HandleEvent(pEvent);
  538. //                 }
  539. //                 else
  540. //                 {
  541. //                    goto cleanup;
  542. //                 }
  543. //              }
  544. //              else
  545. //              {
  546. //                 pFocusSite->EventOccurred(pEvent);
  547. //              }
  548. //           }
  549. //           else
  550.        {
  551.            //Tell our user that the event has occured.
  552.            if (m_pUser)
  553.                m_pUser->HandleEvent(pEvent);
  554.            if( !pEvent->handled )
  555.            {
  556.              mapchanged1:
  557.                int mapCount = m_ChildrenMap.GetCount();
  558.                CHXMapPtrToPtr::Iterator i = m_ChildrenMap.Begin();
  559.                while( i!= m_ChildrenMap.End() && !pEvent->handled)
  560.                {
  561.                    CHXWinSite* pSite = (CHXWinSite*) *i;
  562.                    pSite->EventOccurred(pEvent);
  563.                    //wow. :-(
  564.                    if (m_ChildrenMap.GetCount() != mapCount)
  565.                    {
  566.                        goto mapchanged1;
  567.                    }
  568.                    ++i;
  569.                }
  570.            }
  571.        }
  572.        //We always convert the event to an generic event now.
  573.        //If we don't we don't get generic events....
  574.        ret = FALSE;
  575.        break;
  576.        }
  577.     }
  578. //  cleanup:
  579.     return ret;
  580. }
  581. //XXXgfw, remove this if we end up not using it after release.
  582. void CHXWinSite::_SizeSliders()
  583. {
  584. }
  585. /************************************************************************
  586.  *  Function:
  587.  *    HXxWinHookSiteProc
  588.  *
  589.  */
  590. LRESULT HXEXPORT
  591. HXxWinHookSiteProc
  592. (
  593.     HWND hWnd,
  594.     UINT message,
  595.     WPARAM uParam,
  596.     LPARAM lParam
  597.     )
  598. {
  599.     LRESULT             lResult = 0;
  600.     CHXWinSite* pThis = 0;
  601.     CHXWinSite::zm_SubclassedWnds.Lookup((void*)hWnd,(void*&)pThis);
  602.     if (!pThis)
  603.     {
  604.         HX_ASSERT(0);
  605.         return DefWindowProc(hWnd, message, uParam, lParam);
  606.     }
  607.     if (pThis->HandleWndProc(hWnd,message,uParam,lParam,lResult))
  608.     {
  609.         return (lResult);
  610.     }
  611.     return CallWindowProc(pThis->m_oldWndProc, hWnd, message, uParam, lParam);
  612. }
  613. /************************************************************************
  614.  *  Function:
  615.  *    HXxWinHookChar
  616.  *
  617.  */
  618. //LRESULT HXEXPORT
  619. LRESULT CALLBACK
  620. HXxWinHookChar(int nCode,WPARAM wParam,LPARAM lParam)
  621. {
  622.     if (nCode <0 || nCode != HC_NOREMOVE)
  623.     {
  624.         int isKeyDown = (KF_UP & lParam);
  625.         if (!isKeyDown)
  626.         {
  627.             LRESULT             lResult = 0;
  628.             CHXWinSite* pThis;
  629.             CHXMapPtrToPtr::Iterator i = CHXWinSite::zm_SubclassedWnds.Begin();
  630.             for(;i!= CHXWinSite::zm_SubclassedWnds.End(); ++i)
  631.             {
  632.                 pThis = (CHXWinSite*) *i;
  633.                 if (pThis->IsFullScreen())
  634.                 {
  635.                     if (pThis->HandleWndProc((HWND)i.get_key(),WM_CHAR,wParam,lParam,lResult))
  636.                     {
  637.                         return (lResult);
  638.                     }
  639.                 }
  640.             }
  641.         }
  642.     }
  643.     /*
  644.      *  Sweet Jesus. They do not give us a window handle. Ok. Call GetCurrentThreadId.
  645.      */
  646.     DWORD id = GetCurrentThreadId();
  647.     CParentWindowThreadData* pData = NULL;
  648.     if (CHXWinSite::zm_ParentsThreadList.Lookup((void*)id, (void*&) pData))
  649.     {
  650.         return CallNextHookEx(pData->m_hHook,nCode,wParam,lParam);
  651.     }
  652.     /*
  653.      *  If we get here we are in some SERIOUS hurt.
  654.      */
  655.     HX_ASSERT(NO_HOOK_FOUND_RETURNING_WITH_ZERO);
  656.     return 0;
  657. }
  658. /************************************************************************
  659.  *  Function:
  660.  *    WinDrawHelperCallWndProc
  661.  */
  662. LRESULT HXEXPORT
  663. HXxWinHookAllMessages
  664. (
  665.     int        nCode,
  666.     WPARAM  wParam,
  667.     LPARAM  lParam
  668.     )
  669. {
  670.     CWPSTRUCT*  pCWPStruct  = (CWPSTRUCT*)lParam;
  671.     HWND        hWnd        = pCWPStruct->hwnd;
  672.     UINT        message     = pCWPStruct->message;
  673.     /*
  674.      * We watch for movement of the topmost parent of any of our
  675.      * windraw objects, and if so then we tell windraw to update
  676.      * the frame for those windraw objects. Outter check is for
  677.      * the message in question so that we don't waste too much time.
  678.      */
  679.     const UINT msgMoving        = WM_MOVING;
  680.     const UINT msgPosChanging   = WM_WINDOWPOSCHANGING;
  681.     /*
  682.      *  If I see any reason to use these other messages in the future
  683.      *   message == WM_MOVING || message == WM_WINDOWPOSCHANGING
  684.      */
  685.     if (message == WM_MOVE)
  686.     {
  687.         CHXSimpleList* pChildrenList;
  688.         if (CHXWinSite::zm_ParentWnds.Lookup((void*)hWnd,(void*&)pChildrenList))
  689.         {
  690.             CHXSimpleList::Iterator i = pChildrenList->Begin();
  691.             for(; i!= pChildrenList->End(); ++i)
  692.             {
  693.                 CHXWinSite* pSite = (CHXWinSite*) *i;
  694.                 pSite->HandleParentMessages(pCWPStruct->hwnd,pCWPStruct->message,pCWPStruct->wParam,pCWPStruct->lParam);
  695.             }
  696.         }
  697.         else
  698.         {
  699.             //Try to detect reparenting.
  700.             HWND hTmpWnd;
  701.             BOOL areWeDone = FALSE;
  702.             POSITION pos = CHXWinSite::zm_ParentWnds.GetStartPosition();
  703.             while(pos && !areWeDone)
  704.             {
  705.                 CHXWinSite::zm_ParentWnds.GetNextAssoc(pos, (void*&) hTmpWnd, (void*&) pChildrenList);
  706.                 //hTmpWnd = ::GetParent(hTmpWnd);
  707.                 while( hTmpWnd && !areWeDone )
  708.                 {
  709.                     if( hTmpWnd == hWnd )
  710.                     {
  711.                         //reparent and leave
  712.                         LISTPOSITION listpos = pChildrenList->GetHeadPosition();
  713.                         CHXWinSite* pSite = (CHXWinSite*)pChildrenList->GetAt(listpos);
  714.                         if( pSite && pSite->m_pTopLevelSite )
  715.                             ((CHXWinSite*)pSite->m_pTopLevelSite)->ReHookParents();
  716.                         areWeDone = TRUE;
  717.                     }
  718.                     hTmpWnd = ::GetParent(hTmpWnd);
  719.                 }
  720.             }
  721.         }
  722.     }
  723.     if (message == WM_DISPLAYCHANGE)
  724.     {
  725.         CHXSimpleList* pChildrenList;
  726.         if (CHXWinSite::zm_ParentWnds.Lookup((void*)hWnd,(void*&)pChildrenList))
  727.         {
  728.             CHXSimpleList::Iterator i = pChildrenList->Begin();
  729.             for(; i!= pChildrenList->End(); ++i)
  730.             {
  731.                 CHXWinSite* pSite = (CHXWinSite*) *i;
  732.                 pSite->CheckDisplayMode(NULL);
  733.             }
  734.         }
  735.     }
  736.     /*
  737.      *  Sweet Jesus, they did not give us a window handle in the keyboard hook. So we might as
  738.      *  well use the same messed up method here. Call GetCurrentThreadId. I hope to heck this
  739.      *  works out.
  740.      */
  741.     DWORD id = GetCurrentThreadId();
  742.     CParentWindowThreadData* pData = NULL;
  743.     if (CHXWinSite::zm_ParentsThreadList.Lookup((void*)id, (void*&) pData))
  744.     {
  745.         return CallNextHookEx(pData->m_hHookAllMessage,nCode,wParam,lParam);
  746.     }
  747.     /*
  748.      *  If we get here we are in some SERIOUS hurt.
  749.      */
  750.     HX_ASSERT(NO_HOOK_FOUND_RETURNING_WITH_ZERO);
  751.     return 0;
  752. }
  753. void
  754. CHXWinSite::HandleParentMessages(HWND hWnd,UINT message,WPARAM uParam,LPARAM lParam)
  755. {
  756.     AddRef();
  757.     if (m_ulSiteThreadID != GetCurrentThreadId())
  758.     {
  759.         if (m_pTopLevelSite)
  760.         {
  761.             // If we are in overlay mode, we need a SiteMoving to
  762.             // update the overaly's location - a repaint will not
  763.             // help us here.  Proxy a MOVE message to the main app thread.
  764.             if (m_pVideoSurface->m_nBltMode == HX_OVERLAY_BLT)
  765.                 m_pTopLevelSite->ScheduleCallback(MOVE, 0);
  766.             else
  767.             {
  768.                 m_pTopLevelSite->ScheduleCallback(REPAINT, 0);
  769.                 m_bRepaintScheduled = TRUE;
  770.             }
  771.         }
  772.     }
  773.     else
  774.     {
  775.         if (message == WM_MOVE)
  776.         {
  777.             _TLSLock();
  778.             /*
  779.              * Site moving used to take an X, Y parameter, but since we changed it to
  780.              * go to GDI mode, that is no longer relevant.
  781.              */
  782.             m_pTopLevelSite->SiteMoving(0, 0);
  783.             m_pTopLevelSite->m_nLastMoveTime = HX_GET_TICKCOUNT();
  784.             m_pTopLevelSite->ScheduleCallback(MOUSE, 100);
  785.             _TLSUnlock();
  786.         }
  787.     }
  788.     Release();
  789.     return;
  790. }
  791. BOOL
  792. CHXWinSite::HandleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT& lResult)
  793. {
  794.     //Give the event to windraw, we may be in 8 bit mode, and it will
  795.     //want to know about it.
  796.     if (m_pRootSurface)
  797.     {
  798.         WINDRAW* pWindraw;
  799.         pWindraw = ((CWinBaseRootSurface*)m_pRootSurface)->GetWinDraw();
  800.         WinDraw2_OnPaletteChange(pWindraw, hWnd, message);
  801.     }
  802.     //Before we do anything we give the native event to the renderer.
  803.     HXxEvent     event = {0,0,0,0,0,0};
  804.     AddRef();
  805.     BOOL retValue = FALSE;
  806.     if (m_pUser)
  807.     {
  808.         HXxEvent event = {message, (void*)hWnd, (void*)wParam, (void*)lParam, 0, 0};
  809.         if (message == WM_DESTROY && m_bDetachWndMsgPending && m_pUser)
  810.         {
  811.             m_bDetachWndMsgPending = FALSE;
  812.             event.event   = HX_DETACH_WINDOW;
  813.             if (HXR_OK == m_pUser->HandleEvent(&event))
  814.             {
  815.                 lResult = (LRESULT)event.result;
  816.             }
  817.             event.event  = WM_DESTROY;
  818.         }
  819.         if (!event.handled && m_pUser)
  820.         {
  821.             m_pUser->HandleEvent(&event);
  822.         }
  823.         if (event.handled)
  824.         {
  825.             retValue = TRUE;
  826.             goto leave;
  827.         }
  828.         //This is an iffy decision. It could go either way. This does
  829.         //not fix any bug that I am aware of, and may create others so
  830.         //perhaps it should not go in.  The idea is that if the
  831.         //renderer needs windowed sites, then we should not do any
  832.         //further processing on the message. Don't know if this would
  833.         //be a good thing.
  834.         if (m_pUser && m_pUser->NeedsWindowedSites())
  835.         {
  836.             //retValue = FALSE;
  837.             //goto leave;
  838.         }
  839.     }
  840.     // Was this a scroll message? If so we need to process it here.
  841.     if (message == WM_HSCROLL || message == WM_VSCROLL )
  842.     {
  843.         CHXWinSite* pParent;
  844.         void* hwndScrollBar = (void*) lParam;
  845.         if (zm_ScrollBarWnds.Lookup(hwndScrollBar, (void*&)pParent))
  846.         {
  847.             int nScrollCode = (int) LOWORD(wParam); // scroll bar value
  848.             int nPos = (int) HIWORD(wParam);   // scroll box position
  849.             BOOL bNeedRedraw = FALSE;
  850.             SCROLLINFO info;
  851.             memset(&info, 0, sizeof(SCROLLINFO));
  852.             info.cbSize = sizeof(SCROLLINFO);
  853.             info.fMask     = SIF_POS;
  854.             info.nPos      = nPos;
  855.             HXxSize size;
  856.             HXxRect rect;
  857.             pParent->GetWindowRect(&rect);
  858.             size.cx = rect.right - rect.left;
  859.             size.cy = rect.bottom - rect.top;
  860.             if (SB_THUMBPOSITION == nScrollCode || SB_THUMBTRACK == nScrollCode)
  861.             {
  862.                 SetScrollInfo((HWND)hwndScrollBar, SB_CTL, &info, FALSE);
  863.                 /* !(*&*(@ Shitty code becuase GetScrollInfo seems to be causing deadlocks. */
  864.                 if (message == WM_HSCROLL)
  865.                 {
  866.                     pParent->m_XSliderPos = nPos;
  867.                 }
  868.                 else
  869.                 {
  870.                     pParent->m_YSliderPos = nPos;
  871.                 }
  872.                 bNeedRedraw = TRUE;
  873.             }
  874.             if (SB_LINEUP == nScrollCode)
  875.             {
  876.                 if (message == WM_HSCROLL)
  877.                 {
  878.                     if (pParent->m_XSliderPos) pParent->m_XSliderPos--;
  879.                     info.nPos = pParent->m_XSliderPos;
  880.                 }
  881.                 else
  882.                 {
  883.                     if (pParent->m_YSliderPos) pParent->m_YSliderPos--;
  884.                     info.nPos = pParent->m_YSliderPos;
  885.                 }
  886.                 SetScrollInfo((HWND)hwndScrollBar, SB_CTL, &info, TRUE);
  887.                 bNeedRedraw = TRUE;
  888.             }
  889.             if (SB_LINEDOWN == nScrollCode)
  890.             {
  891.                 if (message == WM_HSCROLL)
  892.                 {
  893.                     if (pParent->m_XSliderPos < (pParent->m_XSliderRange - size.cx) ) pParent->m_XSliderPos++;
  894.                     info.nPos = pParent->m_XSliderPos;
  895.                 }
  896.                 else
  897.                 {
  898.                     if (pParent->m_YSliderPos < (pParent->m_YSliderRange - size.cy) ) pParent->m_YSliderPos++;
  899.                     info.nPos = pParent->m_YSliderPos;
  900.                 }
  901.                 SetScrollInfo((HWND)hwndScrollBar, SB_CTL, &info, TRUE);
  902.                 bNeedRedraw = TRUE;
  903.             }
  904.             if (SB_PAGEUP == nScrollCode)
  905.             {
  906.                 if (message == WM_HSCROLL)
  907.                 {
  908.                     pParent->m_XSliderPos -= size.cx;
  909.                     if (pParent->m_XSliderPos < 0)
  910.                     {
  911.                         pParent->m_XSliderPos = 0;
  912.                     }
  913.                     info.nPos = pParent->m_XSliderPos;
  914.                 }
  915.                 else
  916.                 {
  917.                     pParent->m_YSliderPos -= size.cy;
  918.                     if (pParent->m_YSliderPos < 0)
  919.                     {
  920.                         pParent->m_YSliderPos = 0;
  921.                     }
  922.                     info.nPos = pParent->m_YSliderPos;
  923.                 }
  924.                 SetScrollInfo((HWND)hwndScrollBar, SB_CTL, &info, TRUE);
  925.                 bNeedRedraw = TRUE;
  926.             }
  927.             if (SB_PAGEDOWN == nScrollCode)
  928.             {
  929.                 if (message == WM_HSCROLL)
  930.                 {
  931.                     pParent->m_XSliderPos += size.cx;
  932.                     if (pParent->m_XSliderPos > pParent->m_XSliderRange - size.cx)
  933.                     {
  934.                         pParent->m_XSliderPos = pParent->m_XSliderRange - size.cx;
  935.                     }
  936.                     info.nPos = pParent->m_XSliderPos;
  937.                 }
  938.                 else
  939.                 {
  940.                     pParent->m_YSliderPos += size.cy;
  941.                     if (pParent->m_YSliderPos > pParent->m_YSliderRange - size.cy)
  942.                     {
  943.                         pParent->m_YSliderPos = pParent->m_YSliderRange - size.cy;
  944.                     }
  945.                     info.nPos = pParent->m_YSliderPos;
  946.                 }
  947.                 SetScrollInfo((HWND)hwndScrollBar, SB_CTL, &info, TRUE);
  948.                 bNeedRedraw = TRUE;
  949.             }
  950.             if (bNeedRedraw)
  951.             {
  952. //We have scrolled by at least one line. This invalidates the
  953. //whole rect.
  954. HXxRect pTmp = { pParent->m_topleft.x,
  955. pParent->m_topleft.y,
  956. pParent->m_topleft.x + pParent->m_size.cx,
  957. pParent->m_topleft.y + pParent->m_size.cy };
  958. m_pTopLevelSite->_RecursiveDamageRect(&pTmp, TRUE);
  959. pParent->InternalForceRedraw();
  960.             }
  961.         }
  962.         retValue = TRUE;
  963.         goto leave;
  964.     }
  965.     //
  966.     // Need to translate native events to HXxEvents.
  967.     //
  968.     UINT32       hxEventType;
  969.     hxEventType = 0;
  970.     HXxPoint     pxMouse;
  971.     HXxRect      boundsRect;
  972.     pxMouse.x = LOWORD(lParam) - m_screenOffset.x;
  973.     pxMouse.y = HIWORD(lParam) - m_screenOffset.y;
  974.                    // XXXAH WHOOPS! Currently in the paint function I am
  975.                // assuming that you are painting the enitire rectangle.
  976.                // So for the moment we will be painting the whole thing.
  977.                boundsRect.left     = 0;
  978.                boundsRect.right    = m_size.cx;
  979.                boundsRect.top      = 0;
  980.                boundsRect.bottom   = m_size.cy;
  981.     UINT32 flags;
  982.     flags = 0;
  983.     if (wParam & MK_SHIFT)
  984.         flags += HX_SHIFT_KEY;
  985.     if (wParam & MK_CONTROL)
  986.         flags += HX_CTRL_KEY;
  987.     if (GetAsyncKeyState(VK_MENU) & (1<<16))
  988.         flags += HX_ALT_COMMAND_KEY;
  989.     if (wParam & MK_LBUTTON)
  990.         flags += HX_PRIMARY_BUTTON;
  991.     if (wParam & MK_RBUTTON)
  992.         flags += HX_CONTEXT_BUTTON;
  993.     if (wParam & MK_MBUTTON)
  994.         flags += HX_THIRD_BUTTON;
  995.     switch (message)
  996.     {
  997.        case WM_PAINT:
  998.            PAINTSTRUCT ps;
  999.            ::BeginPaint(hWnd,&ps);
  1000.            boundsRect.left    = ps.rcPaint.left;
  1001.            boundsRect.right   = ps.rcPaint.right;
  1002.            boundsRect.top     = ps.rcPaint.top;
  1003.            boundsRect.bottom  = ps.rcPaint.bottom;
  1004.            m_pTopLevelSite->CheckDisplayMode(ps.hdc);
  1005.            ::EndPaint(hWnd,&ps);
  1006.            //Take care of all the dirty rects for all sites
  1007.            m_pTopLevelSite->ManageExposeEvents(&boundsRect);
  1008. //            // Check to see if this is a spurrious WM_PAINT generated by
  1009. //            // our Invalidate rect calls.
  1010. //            if (!(m_pDirtyRegion->numRects &&
  1011. //                  boundsRect.left   >= m_pDirtyRegion->extents.x1   &&
  1012. //                  boundsRect.right  <= m_pDirtyRegion->extents.x2   &&
  1013. //                  boundsRect.top    >= m_pDirtyRegion->extents.y1   &&
  1014. //                  boundsRect.bottom <= m_pDirtyRegion->extents.y2 ) &&
  1015. //                (boundsRect.left != boundsRect.right && boundsRect.top != boundsRect.bottom)
  1016. //                )
  1017. //            {
  1018. //                FillColorKey();
  1019. //                //Tell all of my children to update their overlays next time.
  1020. //                ResetUpdateOverlay();
  1021. //                if (m_pParentSite)
  1022. //                {
  1023. //                    // Taking the easy way out (would you expect anything
  1024. //                    // less of me?)  The hard, but better, way would be to
  1025. //                    // extract from the composition surface.  *sigh* but I
  1026. //                    // am too lazy right now ... maybe later ... AS IF!
  1027. //                    // XXXAH
  1028. //                    m_bDoNotGenerateWMPPaint = TRUE;
  1029. //                    InternalForceRedraw();
  1030. //                    m_bDoNotGenerateWMPPaint = FALSE;
  1031. //                    m_pTopLevelSite->_ForceRedrawAll();
  1032. //                }
  1033. //                else
  1034. //                {
  1035. //                    m_pTopLevelSite->_ForceRedrawAll();
  1036. //                }
  1037. //                RecursiveSizeSliders();
  1038. //           }
  1039.            lResult = 0;
  1040.            retValue = TRUE;
  1041.            goto leave;
  1042.            break;
  1043.        case WM_MOUSEMOVE:
  1044.            CheckCapture();
  1045.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1046.            SetEvent(event, HX_MOUSE_MOVE, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1047.            break;
  1048.        case WM_LBUTTONDOWN:
  1049. #ifdef _DEBUG
  1050.            if( wParam & MK_CONTROL )
  1051.            {
  1052.                DisplayAllSiteData();
  1053.            }
  1054.            if( wParam & MK_SHIFT)
  1055.            {
  1056.                DisplaySiteData("");
  1057.            }
  1058. #endif
  1059.            CheckCapture();
  1060.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1061.            SetEvent(event, HX_PRIMARY_BUTTON_DOWN, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1062.            break;
  1063.        case WM_RBUTTONDOWN:
  1064.            CheckCapture();
  1065.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1066.            SetEvent(event, HX_CONTEXT_BUTTON_DOWN, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1067.            break;
  1068.        case WM_LBUTTONUP:
  1069.            CheckCapture();
  1070.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1071.            SetEvent(event, HX_PRIMARY_BUTTON_UP, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1072.            break;
  1073.        case WM_RBUTTONUP:
  1074.            CheckCapture();
  1075.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1076.            SetEvent(event, HX_CONTEXT_BUTTON_UP, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1077.            break;
  1078.        case WM_LBUTTONDBLCLK:
  1079.            CheckCapture();
  1080.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1081.            SetEvent(event, HX_PRIMARY_DBLCLK, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1082.            break;
  1083.        case WM_RBUTTONDBLCLK:
  1084.            CheckCapture();
  1085.            SetCaptureMessage(hWnd, message, wParam, lParam);
  1086.            SetEvent(event, HX_CONTEXT_DBLCLK, (void*)hWnd, (void*)&pxMouse, (void*)&flags);
  1087.            break;
  1088.        case WM_CHAR:
  1089.        case WM_KEYDOWN:
  1090.        case WM_KEYUP:
  1091.        case WM_NCHITTEST:
  1092.            SetEvent(event, message, (void*)hWnd, (void*)wParam, (void*)&lParam);
  1093.            break;
  1094.            /*
  1095.             *  Some silly plugins call SetCapture. SO we have to keep on sending them mouse messages
  1096.             *  like crazy.
  1097.             */
  1098.        case WM_CAPTURECHANGED:
  1099.            m_pTopLevelSite->m_bSetCaptureOn = (void*)lParam == GetWindow()->window;
  1100.            if (m_pTopLevelSite->m_bSetCaptureOn)
  1101.            {
  1102.                if( m_pTopLevelSite->m_pCaptureUser)
  1103.                    m_pTopLevelSite->m_pCaptureUser = m_pTopLevelSite->m_pLastUser;
  1104.            }
  1105.            else
  1106.            {
  1107.                if( m_pTopLevelSite->m_pCaptureUser)
  1108.                    m_pTopLevelSite->m_pCaptureUser = NULL;
  1109.            }
  1110.            break;
  1111.        case WM_SIZE:
  1112.        case WM_MOVE:
  1113.        case WM_SIZING:
  1114.        case WM_MOVING:
  1115.        case WM_WINDOWPOSCHANGED:
  1116.        case WM_WINDOWPOSCHANGING:
  1117. #ifdef _CHECK_CREATE
  1118.        {
  1119.            RECT rect;
  1120.            ::GetWindowRect((HWND)GetWindow()->window, &rect);
  1121.            FILE* f1 = fopen("c:\create.txt", "a+"); /* Flawfinder: ignore */
  1122.            fprintf(f1, "%p WM_SIZE: %p  hwnd: %p  internalSize: (%d, %d) external Size: (%d, %d)n", GetCurrentThreadId(),this, GetWindow()->window, m_size.cx, m_size.cy, rect.right -rect.left, rect.bottom - rect.top);
  1123.            fclose(f1);
  1124.        }
  1125. #endif
  1126.        if (m_bInFullScreen)
  1127.        {
  1128.            lResult = DefWindowProc( hWnd, message, wParam, lParam);
  1129.            retValue = TRUE;
  1130.            goto leave;
  1131.        }
  1132.        else
  1133.        {
  1134.            retValue = FALSE;
  1135.            goto leave;
  1136.        }
  1137.        break;
  1138. #ifndef _HAMEL
  1139.        case WM_ACTIVATE:
  1140.        case WM_ACTIVATEAPP:
  1141.        {
  1142.            DWORD fActive = LOWORD(wParam);
  1143.            if (m_bInFullScreen && m_pUser && !fActive)
  1144.            {
  1145.                HXxEvent event = {WM_CHAR, GetWindow()->window, (void*)VK_ESCAPE, 0, 0, 0};
  1146.                m_pUser->HandleEvent(&event);
  1147.            }
  1148.            retValue = FALSE;
  1149.            goto leave;
  1150.        }
  1151. #endif
  1152.        case WM_CLOSE:
  1153.        {
  1154.            if (m_bInFullScreen && m_pUser)
  1155.            {
  1156.                HXxEvent event = {WM_CHAR, GetWindow()->window, (void*)VK_ESCAPE, 0, 0, 0};
  1157.                m_pUser->HandleEvent(&event);
  1158.                lResult = TRUE;
  1159.                retValue = TRUE;
  1160.                goto leave;
  1161.            }
  1162.            retValue = FALSE;
  1163.            goto leave;
  1164.        }
  1165.        case WM_SETFOCUS:
  1166.            lResult = 1;
  1167.            break;
  1168.        case WM_KILLFOCUS :
  1169.            lResult = 1;
  1170.            break;
  1171.     }
  1172.     if (event.window)
  1173.     {
  1174.         EventOccurred(&event);
  1175.         lResult = event.handled;
  1176.         retValue = event.handled;
  1177.         goto leave;
  1178.     }
  1179.     if (message == WM_SETCURSOR)
  1180.     {
  1181.         lResult = TRUE;
  1182.         retValue = TRUE;
  1183.         goto leave;
  1184.     }
  1185.     retValue = FALSE;
  1186.     goto leave;
  1187.   leave:
  1188.     Release();
  1189.     return retValue;
  1190. }
  1191. /************************************************************************
  1192.  *  Function:
  1193.  *    HXxHookSiteProc
  1194.  *
  1195.  */
  1196. LRESULT HXEXPORT
  1197. HXxHookSiteProc
  1198. (
  1199.     HWND hWnd,
  1200.     UINT message,
  1201.     WPARAM uParam,
  1202.     LPARAM lParam
  1203.     )
  1204. {
  1205.     LRESULT             lResult = 0;
  1206.     CHXWinSite*         pThis = 0;
  1207.     CHXWinSite::zm_SubclassedWnds.Lookup((void*)hWnd,(void*&)pThis);
  1208.     if (!pThis)
  1209.     {
  1210.         HX_ASSERT(0);
  1211.         return DefWindowProc(hWnd, message, uParam, lParam);
  1212.     }
  1213.     if (pThis->HandleWndProc(hWnd,message,uParam,lParam,lResult))
  1214.     {
  1215.         return (lResult);
  1216.     }
  1217.     return CallWindowProc(pThis->m_oldWndProc, hWnd, message, uParam, lParam);
  1218. }
  1219. /************************************************************************
  1220.  *  Function:
  1221.  *    HXxHookChar
  1222.  *
  1223.  *   Uhm, why is this function here?
  1224.  */
  1225. LRESULT HXEXPORT
  1226. HXxHookChar(int nCode,WPARAM wParam,LPARAM lParam)
  1227. {
  1228.     if (nCode <0 || nCode != HC_NOREMOVE)
  1229.     {
  1230.         int isKeyDown = (KF_UP & lParam);
  1231.         if (!isKeyDown)
  1232.         {
  1233.             LRESULT             lResult = 0;
  1234.             CHXWinSite*         pThis;
  1235.             CHXMapPtrToPtr::Iterator i = CHXWinSite::zm_SubclassedWnds.Begin();
  1236.             for(;i!= CHXWinSite::zm_SubclassedWnds.End(); ++i)
  1237.             {
  1238.                 pThis = (CHXWinSite*) *i;
  1239.                 if (pThis->IsFullScreen())
  1240.                 {
  1241.                     if (pThis->HandleWndProc((HWND)i.get_key(),WM_CHAR,wParam,lParam,lResult))
  1242.                     {
  1243.                         return (lResult);
  1244.                     }
  1245.                 }
  1246.             }
  1247.         }
  1248.     }
  1249.     /*
  1250.      *  Sweet Jesus. They do not give us a window handle. Ok. Call GetCurrentThreadId.
  1251.      */
  1252.     DWORD id = GetCurrentThreadId();
  1253.     CParentWindowThreadData* pData = NULL;
  1254.     if (CHXWinSite::zm_ParentsThreadList.Lookup((void*)id, (void*&) pData))
  1255.     {
  1256.         return CallNextHookEx(pData->m_hHook,nCode,wParam,lParam);
  1257.     }
  1258.     /*
  1259.      *  If we get here we are in some SERIOUS hurt.
  1260.      */
  1261.     HX_ASSERT(NO_HOOK_FOUND_RETURNING_WITH_ZERO);
  1262.     return 0;
  1263. }
  1264. void CHXWinSite::_GetDeviceCaps(void* h, UINT16& uBitesPerPixel, UINT16& uHorzRes, UINT16& uVertRes)
  1265. {
  1266.     HDC hdc = (HDC) h;
  1267.     if (!hdc)
  1268.     {
  1269.         hdc = GetDC(0);
  1270.     }
  1271.     uBitesPerPixel  = ::GetDeviceCaps(hdc, BITSPIXEL);
  1272.     uHorzRes        = ::GetDeviceCaps(hdc, HORZRES);
  1273.     uVertRes        = ::GetDeviceCaps(hdc, VERTRES);
  1274.     // did we create it? if so, release it as well
  1275.     if (hdc && hdc != h)
  1276.     {
  1277.         ReleaseDC(0, hdc);
  1278.     }
  1279. }
  1280. void CHXWinSite::_DestroySliders()
  1281. {
  1282.     if(m_hXSlider)
  1283.     {
  1284.         ::DestroyWindow(m_hXSlider);
  1285.         zm_ScrollBarWnds.RemoveKey(m_hXSlider);
  1286.         m_hXSlider = NULL;
  1287.     }
  1288.     if(m_hYSlider)
  1289.     {
  1290.         ::DestroyWindow(m_hYSlider);
  1291.         zm_ScrollBarWnds.RemoveKey(m_hYSlider);
  1292.         m_hYSlider = NULL;
  1293.     }
  1294. }
  1295. void CHXWinSite::_GenerateOSEvent(HXxEvent* pEvent, HXxEvent* pEvent2)
  1296. {
  1297.     //  Give all of those crappy renderers (you know who I am talking
  1298.     //  about flash!)  a WM_ message.
  1299.     HXxEvent winDozEvent;
  1300.     if(NULL==m_pUser)
  1301.         return;
  1302.     memcpy(&winDozEvent, pEvent, sizeof(HXxEvent)); /* Flawfinder: ignore */
  1303.     winDozEvent.param1 = pEvent->param2;
  1304.     winDozEvent.param2 = (void*) ((INT32) ((HXxPoint*)pEvent->param1)->y << 16 | ((HXxPoint*)pEvent->param1)->x);
  1305.     switch(pEvent2->event)
  1306.     {
  1307.        case HX_CONTEXT_BUTTON_DOWN:
  1308.            winDozEvent.event  = WM_RBUTTONDOWN;
  1309.            break;
  1310.        case HX_CONTEXT_BUTTON_UP:
  1311.            winDozEvent.event  = WM_RBUTTONUP;
  1312.            break;
  1313.        case HX_PRIMARY_BUTTON_DOWN:
  1314.            winDozEvent.event  = WM_LBUTTONDOWN;
  1315.            break;
  1316.        case HX_PRIMARY_BUTTON_UP:
  1317.            winDozEvent.event  = WM_LBUTTONUP;
  1318.            break;
  1319.        case HX_MOUSE_MOVE:
  1320.            winDozEvent.event  = WM_MOUSEMOVE;
  1321.            break;
  1322.        case HX_PRIMARY_DBLCLK:
  1323.            winDozEvent.event = WM_LBUTTONDBLCLK;
  1324.            break;
  1325.        case HX_CONTEXT_DBLCLK:
  1326.            winDozEvent.event = WM_RBUTTONDBLCLK;
  1327.            break;
  1328.        default:
  1329.            HX_ASSERT( "invalid RMA event for translation" );
  1330.            break;
  1331.     }
  1332.     m_pUser->HandleEvent(&winDozEvent);
  1333.     pEvent2->handled = winDozEvent.handled;
  1334. }
  1335. void CHXWinSite::_GenerateSetCursorEvent()
  1336. {
  1337.     HXxEvent setCursorEvent = {WM_SETCURSOR, GetWindow()->window, 0, 0, 0, FALSE};
  1338.     m_pUser->HandleEvent(&setCursorEvent);
  1339. }
  1340. HX_RESULT CHXWinSite::_EnterFullScreen()
  1341. {
  1342.     /* for the moment this will be COMPLETLY OS Specific */
  1343.     m_windowParent = GetParent((HWND) GetWindow()->window);
  1344.     HWND hParent = (HWND) GetWindow()->window;
  1345.     HWND hNextParent = NULL;
  1346.     while ((hNextParent = GetParent(hParent)) != NULL)
  1347.     {
  1348.         hParent = hNextParent;
  1349.     }
  1350.     // ask if it is topmost
  1351.     m_bWasTopMost = (GetWindowLong(hParent, GWL_EXSTYLE) & WS_EX_TOPMOST);
  1352.     if (m_bWasTopMost)
  1353.     {
  1354.         SafeSetWindowPos(hParent, HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
  1355.     }
  1356.     POINT point;
  1357.     memset(&point, 0, sizeof(POINT));
  1358.     MapWindowPoints( (HWND) GetWindow()->window, m_windowParent, &point, 1);
  1359.     RECT rect;
  1360.     ::GetWindowRect( (HWND) GetWindow()->window, &rect);
  1361.     m_windowPosition.x = point.x;
  1362.     m_windowPosition.y = point.y;
  1363.     m_windowSize.cx = rect.right - rect.left;
  1364.     m_windowSize.cy = rect.bottom - rect.top;
  1365.     m_bDisableForceRedraw = TRUE;
  1366.     if (zm_bInFullScreenTest)
  1367.     {
  1368.         HWND retVal = SetParent( (HWND) GetWindow()->window, NULL);
  1369.     }
  1370.     else
  1371.     {
  1372.         m_pContainingWindow = new CHXWinFullScreenWindow(this);
  1373.         m_pContainingWindow->Create();
  1374.         m_pContainingWindow->Show();
  1375.         HWND retVal = SetParent( (HWND) GetWindow()->window, m_pContainingWindow->GetWindow());
  1376.     }
  1377.     SetDisplayMode();
  1378.     // calculate new position
  1379. //      double stretchRatio, xRatio, yRatio;
  1380. //      IHXPreferences*        pPreferences    = NULL;
  1381. //      IHXBuffer*             pBuffer         = NULL;
  1382. //      BOOL            bPostageStamp   = FALSE;
  1383. //      char            szBuffer[255];
  1384. //      xRatio = (double)GetSystemMetrics(SM_CXSCREEN)/ (double)m_size.cx ;
  1385. //      yRatio = (double)GetSystemMetrics(SM_CYSCREEN)/ (double)m_size.cy ;
  1386. //      if (xRatio<yRatio)
  1387. //      {
  1388. //      stretchRatio = xRatio;
  1389. //      }
  1390. //      else
  1391. //      {
  1392. //      stretchRatio = yRatio;
  1393. //      }
  1394. //      m_screenOffset.x = (GetSystemMetrics(SM_CXSCREEN) - (int)((double)m_size.cx*stretchRatio))/2;
  1395. //      m_screenOffset.y = (GetSystemMetrics(SM_CYSCREEN) - (int)((double)m_size.cy*stretchRatio))/2;
  1396. //      HXxSize size;
  1397. //      size.cx = (int) ((double) m_size.cx * stretchRatio + 0.5);
  1398. //      size.cy = (int) ((double) m_size.cy * stretchRatio + 0.5);
  1399.     //Say we are in full screen mode
  1400.     m_bInFullScreen = TRUE;
  1401.     //Set up the windowing
  1402.     HXxSize newsize;
  1403.     newsize.cx = GetSystemMetrics(SM_CXSCREEN);
  1404.     newsize.cy = GetSystemMetrics(SM_CYSCREEN);
  1405.     //Tell the top level site that it has changed.
  1406. //    SetSize(size);
  1407.     SetSize(m_size);
  1408.     if (zm_bInFullScreenTest)
  1409.     {
  1410.         SafeSetWindowPos((HWND) GetWindow()->window, HWND_TOPMOST, 0, 0, newsize.cx, newsize.cy, NULL);
  1411.     }
  1412.     else
  1413.     {
  1414.         SafeMoveWindow((HWND) GetWindow()->window, 0, 0, newsize.cx, newsize.cy, FALSE);
  1415.     }
  1416.     /*
  1417.      * Get rid of all child windows.
  1418.      */
  1419.     zm_ListOfHiddenWindows.RemoveAll();
  1420.     EnumChildWindows( (HWND) GetWindow()->window, (WNDENUMPROC)HXxRemoveWindows, NULL);
  1421.     /*
  1422.      * Tell all renderers to repaint themselves
  1423.      */
  1424.     m_pTopLevelSite->m_bDisableForceRedraw = FALSE;
  1425.     ((CWinBaseRootSurface*)m_pRootSurface)->PrepareFullScreen();
  1426.     _ForceRedrawAll();
  1427.     ((CWinBaseRootSurface*)m_pRootSurface)->SetFullScreen();
  1428.     ((CWinBaseRootSurface*)m_pRootSurface)->FillBorders();
  1429.     if (zm_ListOfHiddenWindows.GetCount())
  1430.     {
  1431.         CHXMapPtrToPtr::Iterator i = zm_ListOfHiddenWindows.Begin();
  1432.         for(;i!=zm_ListOfHiddenWindows.End();++i)
  1433.         {
  1434.             SafeShowWindow((HWND) i.get_key(), SW_SHOW);
  1435.         }
  1436.         zm_ListOfHiddenWindows.RemoveAll();
  1437.     }
  1438.     m_nDelayFillBorders = 3;
  1439.     ScheduleCallback(MOUSE, 0);
  1440.     SetFocus((HWND)GetWindow()->window);
  1441.     /*
  1442.      * Now tell the status text that it's parent has changed size.
  1443.      */
  1444.     if (m_pStatusText)
  1445.     {
  1446.         m_pStatusText->ParentChangedSize();
  1447.     }
  1448.     return HXR_OK;
  1449. }
  1450. HX_RESULT CHXWinSite::_ExitFullScreen()
  1451. {
  1452.     m_pTopLevelSite->m_bDisableForceRedraw = TRUE;
  1453.     memset(&m_screenOffset, 0, sizeof(HXxPoint));
  1454.     //  SetSize(m_windowSize);
  1455.     ((CWinBaseRootSurface*)m_pRootSurface)->PrepareExitFullScreen();
  1456.     EnterCriticalSection(&(((CHXWinSite*)m_pTopLevelSite)->m_CriticalSection));
  1457.     DestroySurfaces();
  1458.     ((CWinBaseRootSurface*)m_pRootSurface)->RestoreResolution();
  1459.     ReInitSurfaces();
  1460.     LeaveCriticalSection(&(((CHXWinSite*)m_pTopLevelSite)->m_CriticalSection));
  1461.     HWND retVal = SetParent((HWND)GetWindow()->window, m_windowParent);
  1462.     if (!zm_bInFullScreenTest)
  1463.     {
  1464.         m_pContainingWindow->Hide();
  1465.         m_pContainingWindow->Destroy();
  1466.         HX_DELETE(m_pContainingWindow);
  1467.     }
  1468.     SafeSetWindowPos((HWND) GetWindow()->window, HWND_TOP, 0,0,0,0,SWP_NOMOVE  | SWP_NOSIZE );
  1469.     SafeMoveWindow((HWND) GetWindow()->window, m_windowPosition.x, m_windowPosition.y, m_windowSize.cx, m_windowSize.cy, FALSE);
  1470.     m_pTopLevelSite->m_bDisableForceRedraw = FALSE;
  1471.     memset(&m_screenOffset, 0, sizeof(HXxPoint));
  1472.     HWND hParent = (HWND) GetWindow()->window;
  1473.     HWND hNextParent = NULL;
  1474.     while ((hNextParent = GetParent(hParent)) != NULL)
  1475.     {
  1476.         hParent = hNextParent;
  1477.     }
  1478.     if (m_bWasTopMost)
  1479.     {
  1480.         /*
  1481.          *  Check to see if the player is playing, if it is then reset the player window to
  1482.          *   topmost.
  1483.          */
  1484.         IHXClientEngine* pEngine;
  1485.         IUnknown* pUnknown;
  1486.         IHXPlayer* pPlayer;
  1487.         BOOL bIsDone  = TRUE;
  1488.         if (HXR_OK == m_pContext->QueryInterface(IID_IHXClientEngine, (void**) &pEngine))
  1489.         {
  1490.             UINT16 count = pEngine->GetPlayerCount();
  1491.             while(count)
  1492.             {
  1493.                 count--;
  1494.                 if (HXR_OK == pEngine->GetPlayer(count, pUnknown))
  1495.                 {
  1496.                     if (HXR_OK == pUnknown->QueryInterface(IID_IHXPlayer, (void**) &pPlayer))
  1497.                     {
  1498.                         bIsDone &= pPlayer->IsDone();
  1499.                         HX_RELEASE(pPlayer);
  1500.                     }
  1501.                     HX_RELEASE(pUnknown);
  1502.                 }
  1503.             }
  1504.             HX_RELEASE(pEngine);
  1505.         }
  1506.         if (!bIsDone)
  1507.         {
  1508.             SafeSetWindowPos(hParent, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
  1509.         }
  1510.         m_bWasTopMost = FALSE;
  1511.     }
  1512.     m_bInFullScreen = FALSE;
  1513.     SetSize(m_windowSize);
  1514.     m_pTopLevelSite->_ForceRedrawAll();
  1515.     if (m_pStatusText)
  1516.     {
  1517.         m_pStatusText->ParentChangedSize();
  1518.         m_pStatusText->Hide();
  1519.     }
  1520.     m_nDelayFillBorders = 0;
  1521.     SetFocus((HWND)GetWindow()->window);
  1522.     return HXR_OK;
  1523. }
  1524. HX_RESULT CHXWinSite::_TestFullScreen(void* hTestBitmap,const char* pszStatusText)
  1525. {
  1526.     EnterCriticalSection(&(((CHXWinSite*)m_pTopLevelSite)->m_CriticalSection));
  1527.     HX_RESULT retVal = HXR_FAIL;
  1528.     CHXWinSite* pTempWindow = new CHXWinSite(m_pContext, FALSE);
  1529.     zm_bInFullScreenTest = TRUE;
  1530.     if (pTempWindow)
  1531.     {
  1532.         pTempWindow->AddRef();
  1533.         retVal = pTempWindow->InternalTestFullScreen(hTestBitmap, pszStatusText);
  1534.         zm_bInFullScreenTest = FALSE;
  1535.         pTempWindow->Release();
  1536.     }
  1537.     LeaveCriticalSection(&(((CHXWinSite*)m_pTopLevelSite)->m_CriticalSection));
  1538.     return retVal;
  1539. }
  1540. /*
  1541.  *  XXXAH all of this code that reads prefs can be move to the cross platform code.
  1542.  */
  1543. HX_RESULT CHXWinSite::InternalTestFullScreen(LPVOID hTestBitmap,const char* pszStatusText)
  1544. {
  1545. /*
  1546.  *       Check to see if we have a HWND.
  1547.  *       If not, create one, DirectDraw is going to require one.
  1548.  */
  1549.     BOOL bInternalTestWindow = FALSE;
  1550.     if (!m_pWindow || !m_pWindow->window)
  1551.     {
  1552.         bInternalTestWindow = TRUE;
  1553.         Create(NULL, WS_POPUP);
  1554.     }
  1555.     /*
  1556.      * Get the modes to be tested from the regestry.
  1557.      */
  1558.     IHXPreferences*    pPreferences    = NULL;
  1559.     IHXBuffer*         pBuffer         = NULL;
  1560.     char*               pszModesToTest  = NULL;
  1561.     char                szBuffer[255]; /* Flawfinder: ignore */
  1562.     m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences);
  1563.     SafeStrCpy(szBuffer, REGKEY_FULLSCREEN_DATA, 255);
  1564.     SafeStrCat(szBuffer, "\", 255);
  1565.     SafeStrCat(szBuffer, REGKEY_FULLSCREEN_TEST_MODES, 255);
  1566.     pPreferences->ReadPref(szBuffer, pBuffer);
  1567.     // if we were called without a mode to test this means that
  1568.     // the top level client wants to know what modes are
  1569.     // availiable. So we will call enumerate modes fix-up the
  1570.     // regestry and return.
  1571.     if (pBuffer && strlen((char*)pBuffer->GetBuffer()))
  1572.     {
  1573.         char* pszModesToTest = (char*)pBuffer->GetBuffer();
  1574.         /*
  1575.          *  Test each of the modes which are in the Mode Description
  1576.          *  String.
  1577.          */
  1578.         int stringLength = strlen(pszModesToTest);
  1579.         char* pszTempString = new char[stringLength+1];
  1580.         CHXSimpleList modesList;
  1581.         memcpy(pszTempString, pszModesToTest, stringLength+1); /* Flawfinder: ignore */
  1582.         // Whoops! Since we use strtok in the following calls we
  1583.         // had better strtok this here and store the
  1584.         // tokens in a list!
  1585.         char* token = strtok( pszTempString, MODE_SEPERATOR);
  1586.         while( token != NULL )
  1587.         {
  1588.             modesList.AddTail(token);
  1589.             token  = strtok( NULL, MODE_SEPERATOR);
  1590.         }
  1591.         if (bInternalTestWindow)
  1592.         {
  1593.             ShowSite(TRUE);
  1594.         }
  1595.         CHXSimpleList::Iterator i;
  1596.         for(i = modesList.Begin(); i!=modesList.End(); ++i)
  1597.         {
  1598.             TestMode((const char*) *i, hTestBitmap, pszStatusText);
  1599.         }
  1600.         delete[] pszTempString;
  1601.     }
  1602.     else
  1603.     {
  1604.         UpdateModes();
  1605.     }
  1606.     HX_RELEASE(pBuffer);
  1607.     HX_RELEASE(pPreferences);
  1608.     if (bInternalTestWindow)
  1609.     {
  1610.         Destroy();
  1611.     }
  1612.     return HXR_OK;
  1613. }
  1614. HX_RESULT CHXWinSite::TestMode(const char* pszModeDescription, void* hTestBitmap, const char* pszText)
  1615. {
  1616. /*
  1617.  *       1st Parse the Modes Description string
  1618.  *
  1619.  */
  1620.     INT32                       resolutionX     = 0;
  1621.     INT32                       resolutionY     = 0;
  1622.     INT32                       colorDepth      = 0;
  1623.     IHXPreferences*    pPreferences    = NULL;
  1624.     IHXBuffer*         pBuffer         = NULL;
  1625.     char*               pszModesToTest  = NULL;
  1626.     char                szBuffer[255]; /* Flawfinder: ignore */
  1627.     if (HXR_OK == ConvertStringToXYDepth(pszModeDescription, resolutionX, resolutionY, colorDepth))
  1628.     {
  1629.         if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  1630.         {
  1631.             /*
  1632.              * Set the Size and Position
  1633.              */
  1634.             HXxSize     oldSize;
  1635.             HXxPoint    oldPos;
  1636.             HXxSize     newSize;
  1637.             HXxPoint    newPosition;
  1638.             memcpy(&oldSize, &m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  1639.             GetPosition(oldPos);
  1640.             newSize.cx  = GetSystemMetrics(SM_CXSCREEN);
  1641.             newSize.cy  = GetSystemMetrics(SM_CYSCREEN);
  1642.             SetSize(newSize);
  1643.             memset(&newPosition,0,sizeof(HXxPoint));
  1644.             SetPosition(newPosition);
  1645.             /* tell full screen what mode to use */
  1646.             pBuffer = new CHXBuffer();
  1647.             pBuffer->Set((UCHAR*) pszModeDescription, strlen(pszModeDescription)+1);
  1648.             SafeStrCpy(szBuffer, REGKEY_FULLSCREEN_DATA, 255);
  1649.             SafeStrCat(szBuffer, "\", 255);
  1650.             SafeStrCat(szBuffer, REGKEY_FULLSCREEN_PREFERED_MODE, 255);
  1651.             pPreferences->WritePref(szBuffer, pBuffer);
  1652.             HX_RELEASE(pBuffer);
  1653.             EnterFullScreen();
  1654.             int testResult = TestFullScreenPerformance(hTestBitmap, pszText);
  1655.             ExitFullScreen();
  1656.             SetSize(oldSize);
  1657.             SetPosition(oldPos);
  1658.             // update the prefs.
  1659.             if (testResult)
  1660.             {
  1661.                 UpdatePrefs(resolutionX, resolutionY, colorDepth, testResult, testResult>TEST_THRESHOLD, 1);
  1662.             }
  1663.         }
  1664.     }
  1665.     return HXR_OK;
  1666. }
  1667. int CHXWinSite::TestFullScreenPerformance(void* hTestBitmap, const char* pszText)
  1668. {
  1669.     HBITMAP hBitmap = (HBITMAP)hTestBitmap;
  1670.     HXxRect destRect;
  1671.     /*
  1672.      *  Get the bits
  1673.      */
  1674.     HDC hDC = GetDC((HWND)GetWindow()->window);
  1675.     CHXDIBits dib;
  1676.     LPBITMAPINFOHEADER      pinfo = NULL;
  1677.     UCHAR* pBits = NULL;
  1678.     if (HXR_OK != dib.GetDIBits(hDC, hBitmap, pBits, pinfo))
  1679.     {
  1680.         return 0;
  1681.     }
  1682.     /*
  1683.      *  Setup the font
  1684.      */
  1685.     HFONT hFont;
  1686.     int oldMappingMode = SetMapMode( hDC, MM_TEXT );
  1687.     int nHeight = -MulDiv(15, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  1688.     hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Ariel");
  1689.     SetMapMode( hDC, oldMappingMode);
  1690.     HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
  1691.     SIZE textSize;
  1692.     GetTextExtentPoint(hDC, "XXX", 4, &textSize);
  1693.     int textHeight = textSize.cy + 2;
  1694.     /*
  1695.      * Setup our drawing tools
  1696.      */
  1697.     HBRUSH  hBlackBrush = (HBRUSH) GetStockObject(BLACK_BRUSH);
  1698.     HBRUSH  hOldBrush   = (HBRUSH) SelectObject(hDC, hBlackBrush);
  1699.     HPEN    hNullPen    = (HPEN) GetStockObject(NULL_PEN);
  1700.     HPEN    hOldPen     = (HPEN) SelectObject(hDC, hNullPen);
  1701.     COLORREF oldColor   = SetTextColor(hDC, 0x0000FF00);
  1702.     COLORREF oldBkColor = SetBkColor(hDC, 0x00000000);
  1703.     /*
  1704.      *  Set up our rects
  1705.      */
  1706.     HXxRect srcRect;
  1707.     memset(&destRect, 0, sizeof(HXxRect));
  1708.     memset(&srcRect, 0, sizeof(HXxRect));
  1709.     srcRect.right   = pinfo->biWidth;
  1710.     srcRect.bottom  = pinfo->biHeight;
  1711.     int offsetY = (GetSystemMetrics(SM_CYSCREEN) - pinfo->biHeight * 2) / 2;
  1712.     int offsetX = (GetSystemMetrics(SM_CXSCREEN) - pinfo->biWidth * 2) / 2;
  1713.     destRect.top    = (long) offsetY;
  1714.     destRect.left   = (long) offsetX;
  1715.     destRect.bottom = (long) offsetY + pinfo->biHeight * 2;
  1716.     destRect.right  = (long) offsetX + pinfo->biWidth * 2;
  1717.     /*
  1718.      *  Start timing.
  1719.      */
  1720.     GetAsyncKeyState(VK_ESCAPE);
  1721.     UINT32  nStartTime = HX_GET_TICKCOUNT();
  1722.     UINT32  nNowTime;
  1723.     UINT32  timeToUpdateCounter = 0;
  1724.     char    szStatus[255]; /* Flawfinder: ignore */
  1725.     int     counter = 0;
  1726.     while(1)
  1727.     {
  1728.         m_pRootSurface->Lock(0);
  1729.         m_pRootSurface->Blt((UCHAR*)pBits, (HXBitmapInfoHeader*) pinfo, destRect, srcRect, this);
  1730.         m_pRootSurface->Unlock(0, GetWindow());
  1731.         //      m_pVideoSurface->Blt((UCHAR*)pBits, (HXBitmapInfoHeader*) &info.bmiHeader, destRect, srcRect);
  1732.         /*
  1733.          *  Ok now blt to the primary surface
  1734.          */
  1735.         nNowTime = HX_GET_TICKCOUNT();
  1736.         if (nNowTime - nStartTime > timeToUpdateCounter)
  1737.         {
  1738.             /*
  1739.              * Update the display
  1740.              */
  1741.             RECT rect;
  1742.             rect.left = 0;
  1743.             rect.bottom = GetSystemMetrics(SM_CYSCREEN) + 1;
  1744.             rect.top = rect.bottom - textHeight;
  1745.             rect.right =  GetSystemMetrics(SM_CXSCREEN) + 1;
  1746.             Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
  1747.             timeToUpdateCounter += 1000;
  1748.             SafeSprintf(szStatus, 255, "%s %d", pszText, (TEST_LENGTH - timeToUpdateCounter)/1000);
  1749.             DrawText(hDC, szStatus, strlen(szStatus), &rect, DT_CENTER | DT_VCENTER);
  1750.             if (timeToUpdateCounter == TEST_LENGTH)
  1751.             {
  1752.                 break;
  1753.             }
  1754.         }
  1755.         counter++;
  1756.         /*
  1757.          *  Was escape pressed? If so break
  1758.          */
  1759.         if (GetAsyncKeyState(VK_ESCAPE))
  1760.         {
  1761.             // eat the key stroke
  1762.             MSG msg;
  1763.             while (PeekMessage (&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
  1764.             break;
  1765.         }
  1766.     }
  1767.     SetTextColor(hDC, oldColor);
  1768.     SetBkColor(hDC, oldBkColor);
  1769.     SelectObject(hDC, hOldPen);
  1770.     SelectObject(hDC, hOldBrush);
  1771.     ReleaseDC((HWND)GetWindow()->window, hDC);
  1772.     nNowTime = HX_GET_TICKCOUNT();
  1773.     int bltsPerSecond = counter*1000 / CALCULATE_ELAPSED_TICKS(nStartTime, nNowTime);
  1774.     return bltsPerSecond;
  1775. #if 0
  1776.     /*
  1777.      *   The following code will take the given bit map and blt it
  1778.      *   multiple times to the screen. Each time it will change the
  1779.      *    saturation, and contrast causing the bitmap to fade in and out
  1780.      *    at the same time it will shrink and expand the bitmap. This
  1781.      *    will make a pretty animation.
  1782.      *    However, this exercises the YUV->RGB code. This code has some problems
  1783.      *    currently. When the YUV->RGB code is fixed we may re-instate this code.
  1784.      *
  1785.      */
  1786.     /*
  1787.      *  Get information on the bitmap
  1788.      */
  1789.     char szStatus[255]; /* Flawfinder: ignore */
  1790.     HDC hDC = GetDC(NULL);
  1791.     BITMAPINFO info;
  1792.     memset(&info, 0, sizeof(BITMAPINFO));
  1793.     info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1794.     int retVal = GetDIBits(hDC, (HBITMAP)hTestBitmap, 0, 1, NULL, &info, DIB_RGB_COLORS);
  1795.     // add the relevant black border to the bitmap (the bitmap looks like crap if
  1796.     // if is stretched to the whole width of the screen).
  1797.     int bitmapX = info.bmiHeader.biWidth *2;
  1798.     bitmapX +=  bitmapX % 8 ? 8 - bitmapX % 8 : 0;
  1799.     int bitmapY = info.bmiHeader.biHeight * 2;
  1800.     HBITMAP hBitmap = CreateCompatibleBitmap(hDC, bitmapX, bitmapY);
  1801.     HDC hMemDC = CreateCompatibleDC(hDC);
  1802.     HBITMAP hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);
  1803.     HBRUSH  hBlackBrush = (HBRUSH) GetStockObject(BLACK_BRUSH);
  1804.     HBRUSH  hOldBrush   = (HBRUSH) SelectObject(hMemDC, hBlackBrush);
  1805.     HPEN    hNullPen    = (HPEN) GetStockObject(NULL_PEN);
  1806.     HPEN    hOldPen     = (HPEN) SelectObject(hMemDC, hNullPen);
  1807.     Rectangle(hMemDC, 0, 0, bitmapX, bitmapY);
  1808.     HXxRect destRect;
  1809.     destRect.left   = (bitmapX - info.bmiHeader.biWidth) / 2;
  1810.     destRect.top    = (bitmapY - info.bmiHeader.biHeight) / 2;
  1811.     destRect.right  = destRect.left + info.bmiHeader.biWidth;
  1812.     destRect.bottom = destRect.top + info.bmiHeader.biHeight;
  1813.     HDC hMemDC2 = CreateCompatibleDC(hDC);
  1814.     HBITMAP hOldBitmap2 = (HBITMAP) SelectObject(hMemDC2, (HBITMAP)hTestBitmap);
  1815.     BitBlt(hMemDC, destRect.left, destRect.top, info.bmiHeader.biWidth, info.bmiHeader.biHeight, hMemDC2, 0, 0, SRCCOPY);
  1816.     SelectObject(hMemDC, hOldPen);
  1817.     SelectObject(hMemDC, hOldBrush);
  1818.     SelectObject(hMemDC, hOldBitmap);
  1819.     SelectObject(hMemDC2, hOldBitmap2);
  1820.     DeleteDC(hMemDC);
  1821.     DeleteDC(hMemDC2);
  1822.     hOldPen             = (HPEN)SelectObject(hDC, hNullPen);
  1823.     hOldBrush           = (HBRUSH)SelectObject(hDC, hBlackBrush);
  1824.     COLORREF oldColor   = SetTextColor(hDC, 0x0000FF00);
  1825.     COLORREF oldBkColor = SetBkColor(hDC, 0x00000000);
  1826.     /*
  1827.      *  Get the Bits
  1828.      */
  1829.     memset(&info, 0, sizeof(BITMAPINFO));
  1830.     info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1831.     retVal = GetDIBits(hDC, (HBITMAP)hBitmap, 0, 1, NULL, &info, DIB_RGB_COLORS);
  1832.     void* pBits = (void*) new char[info.bmiHeader.biSizeImage];
  1833.     retVal = GetDIBits(hDC, (HBITMAP)hBitmap, 0, info.bmiHeader.biHeight, pBits, &info, DIB_RGB_COLORS);
  1834.     DeleteObject(hBitmap);
  1835.     // Create a YUV BITMAPINFO
  1836.     BITMAPINFO YUVBmi;
  1837.     memset(&YUVBmi, 0, sizeof (BITMAPINFO));
  1838.     MakeBitmap((LPBITMAPINFO)&YUVBmi, sizeof(BMI), CID_I420, info.bmiHeader.biWidth, info.bmiHeader.biHeight, NULL, NULL);
  1839.     // Convert to YUV
  1840.     int pitchIn = GetBitmapPitch((LPBITMAPINFO)&info);
  1841.     int pitchOut = GetBitmapPitch((LPBITMAPINFO)&YUVBmi);
  1842.     int cidIn = GetBitmapColor((LPBITMAPINFO) &info);
  1843.     void* pYUVBits = (void*) new char[info.bmiHeader.biSizeImage];
  1844.     BOOL bConverter = zm_pColorAcc->CheckColorConverter(cidIn, CID_I420);
  1845.     ColorConverterRequest(cidIn, CID_I420, bConverter);
  1846.     int returnVal       = 0;
  1847.     if (bConverter)
  1848.     {
  1849.         zm_pColorAcc->ColorConvert(CID_I420, (UCHAR*)pYUVBits, info.bmiHeader.biWidth, info.bmiHeader.biHeight,
  1850.                             pitchOut, 0,0, info.bmiHeader.biWidth, info.bmiHeader.biHeight,
  1851.                             cidIn, (UCHAR*)pBits, info.bmiHeader.biWidth, info.bmiHeader.biHeight, pitchIn,
  1852.                             0,0,info.bmiHeader.biWidth, info.bmiHeader.biHeight);
  1853.     }
  1854.     // now just blt like crazy.
  1855.     /*
  1856.      *  However for efficient blt-ing we should REALLY be using windraw2 directly
  1857.      *  since rootSurface is simply not up to snuff right now.
  1858.      *   We will create a temporary RGB surface of the same dimensions as the RGB bitmap
  1859.      *  we created above.
  1860.      *   We will then color-convert to this surface.
  1861.      *   We will then blt to the destination rect (stretching with direct draw).
  1862.      */
  1863.     /*
  1864.      *  Create RGB surface.
  1865.      */
  1866.     WINDRAW* pWinDraw = ((CWinBaseRootSurface*)m_pRootSurface)->GetWinDraw();
  1867.     ((CWinBaseRootSurface*)m_pRootSurface)->OpenWindraw();
  1868.     BMI primaryBMI;
  1869.     memset(&primaryBMI, 0, sizeof(BMI));
  1870.     WinDraw2_GetDisplayFormat(pWinDraw, &primaryBMI);
  1871.     int nCID = GetBitmapColor((LPBITMAPINFO)&primaryBMI);
  1872.     memset(&primaryBMI, 0, sizeof(BMI));
  1873.     MakeBitmap((LPBITMAPINFO)&primaryBMI, sizeof(BMI), nCID, info.bmiHeader.biWidth, info.bmiHeader.biHeight, NULL, NULL);
  1874.     WINDRAWSURFACE surface;
  1875.     UCHAR*   pSurfaceLock = NULL;
  1876.     LONG     nPitchOut = 0;
  1877.     memset(&surface, 0, sizeof(WINDRAWSURFACE));
  1878.     IHXPreferences*    pPreferences    = NULL;
  1879.     IHXBuffer*         pBuffer         = NULL;
  1880.     BOOL    bUseWindraw     = TRUE;
  1881.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  1882.     {
  1883.         if (pPreferences->ReadPref("UseWinDraw", pBuffer) == HXR_OK)
  1884.         {
  1885.             bUseWindraw = ::atoi((char*) pBuffer->GetBuffer()) == 1;
  1886.         }
  1887.         HX_RELEASE(pBuffer);
  1888.     }
  1889.     HX_RELEASE(pPreferences);
  1890.     if (NOERROR != WinDraw2_CreateSurface(pWinDraw, &surface, &primaryBMI, bUseWindraw ? WINDRAWSURFACE_DIRECTDRAW : 0, 0, 0))
  1891.     {
  1892.         return 0;
  1893.     }
  1894.     /*
  1895.      *  Setup the font
  1896.      */
  1897.     HFONT hFont;
  1898.     int oldMappingMode = SetMapMode( hDC, MM_TEXT );
  1899.     int nHeight = -MulDiv(15, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  1900.     hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Ariel");
  1901.     SetMapMode( hDC, oldMappingMode);
  1902.     HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
  1903.     SIZE textSize;
  1904.     GetTextExtentPoint(hDC, "XXX", 4, &textSize);
  1905.     int textHeight = textSize.cy + 2;
  1906.     HXxRect srcRect;
  1907.     memset(&destRect, 0, sizeof(HXxRect));
  1908.     memset(&srcRect, 0, sizeof(HXxRect));
  1909.     srcRect.right   = info.bmiHeader.biWidth;
  1910.     srcRect.bottom  = info.bmiHeader.biHeight;
  1911.     UINT32 timeToUpdateCounter = 0;
  1912.     UINT32 nNowTime;
  1913.     float sat = DEF_SATURATION;
  1914.     float inc = (float)0.1;
  1915.     int   counter = 0;
  1916.     float tolerance_x = 100.0;
  1917.     float tolerance_y = tolerance_x * (float) GetSystemMetrics(SM_CYSCREEN) / (float)(GetSystemMetrics(SM_CXSCREEN) - textHeight);
  1918.     float currentModifier_x = (float) 0.0;
  1919.     float currentModifier_y = (float) 0.0;
  1920.     float currentVelocity_x = (float) 1.0;
  1921.     float currentVelocity_y = (float) (tolerance_y / tolerance_x);
  1922.     GetAsyncKeyState(VK_ESCAPE);
  1923.     UINT32 nStartTime = HX_GET_TICKCOUNT();
  1924.     while(1)
  1925.     {
  1926.         sat += inc;
  1927.         if (sat> MAX_SATURATION || sat< MIN_SATURATION )
  1928.         {
  1929.             inc *= -1;
  1930.         }
  1931.         destRect.top    = (long) currentModifier_x;
  1932.         destRect.left   = (long) currentModifier_y;
  1933.         destRect.bottom = (long) (GetSystemMetrics(SM_CYSCREEN) - currentModifier_x - textHeight);
  1934.         destRect.right  = (long) (GetSystemMetrics(SM_CXSCREEN) - currentModifier_y);
  1935.         /*
  1936.          * Color convert onto the small RGB surface
  1937.          */
  1938.         int cidIn   = GetBitmapColor((LPBITMAPINFO) &YUVBmi);
  1939.         int pitchIn = GetBitmapPitch((LPBITMAPINFO) &YUVBmi);
  1940.         bConverter = zm_pColorAcc->CheckColorConverter(cidIn, nCID);
  1941.         ColorConverterRequest(cidIn, nCID, bConverter);
  1942.         //      CWinBaseRootSurface::zm_pColorAcc->SetColorAdjustments(sat, sat, sat, sat);
  1943.         zm_pColorAcc->SetColorAdjustments(sat, sat, sat, DEF_HUE);
  1944.         if (NOERROR == WinDrawSurface_Lock(pWinDraw, &surface, 0, (void**) &pSurfaceLock, (LONG*)&nPitchOut))
  1945.         {
  1946.             if (bConverter)
  1947.             {
  1948.                 zm_pColorAcc->CheckColorConvert(nCID, pSurfaceLock,
  1949.                                         info.bmiHeader.biWidth, info.bmiHeader.biHeight, nPitchOut,
  1950.                                         0, 0, info.bmiHeader.biWidth, info.bmiHeader.biHeight,
  1951.                                         cidIn, (UCHAR*)pYUVBits,
  1952.                                         info.bmiHeader.biWidth, info.bmiHeader.biHeight, pitchIn,
  1953.                                         0,0, info.bmiHeader.biWidth, info.bmiHeader.biHeight);
  1954.             }
  1955.             WinDrawSurface_Unlock(pWinDraw, &surface, 0);
  1956.         }
  1957.         /*
  1958.          *  Ok now blt to the primary surface
  1959.          */
  1960.         HRESULT res = WinDrawSurface_Blt(pWinDraw, &surface, (RECT*)&destRect, (RECT*)&srcRect);
  1961.         nNowTime = HX_GET_TICKCOUNT();
  1962.         if (nNowTime - nStartTime > timeToUpdateCounter)
  1963.         {
  1964.             /*
  1965.              * Update the display
  1966.              */
  1967.             RECT rect;
  1968.             rect.left = 0;
  1969.             rect.bottom = GetSystemMetrics(SM_CYSCREEN) + 1;
  1970.             rect.top = rect.bottom - textHeight;
  1971.             rect.right =  GetSystemMetrics(SM_CXSCREEN) + 1;
  1972.             Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
  1973.             timeToUpdateCounter += 1000;
  1974.             SafeSprintf(szStatus, 255, "%s %d", pszText, (TEST_LENGTH - timeToUpdateCounter)/1000);
  1975.             DrawText(hDC, szStatus, strlen(szStatus), &rect, DT_CENTER | DT_VCENTER);
  1976.             if (timeToUpdateCounter == TEST_LENGTH)
  1977.             {
  1978.                 break;
  1979.             }
  1980.         }
  1981.         counter++;
  1982.         if (currentModifier_x > tolerance_x || currentModifier_x < 0)
  1983.         {
  1984.             currentVelocity_x *=-1;
  1985.             currentVelocity_y *=-1;
  1986.         }
  1987.         currentModifier_x += currentVelocity_x;
  1988.         currentModifier_y += currentVelocity_y;
  1989.         /*
  1990.          *  Was escape pressed? If so break
  1991.          */
  1992.         if (GetAsyncKeyState(VK_ESCAPE))
  1993.         {
  1994.             // eat the key stroke
  1995.             MSG msg;
  1996.             while (PeekMessage (&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
  1997.             break;
  1998.         }
  1999.     }
  2000.     WinDraw2_ReleaseSurface(pWinDraw, &surface);
  2001.     zm_pColorAcc->SetColorAdjustments(DEF_BRIGHTNESS, DEF_CONTRAST, DEF_SATURATION, DEF_HUE);
  2002.     SetTextColor(hDC, oldColor);
  2003.     SetBkColor(hDC, oldBkColor);
  2004.     SelectObject(hDC, hOldPen);
  2005.     SelectObject(hDC, hOldBrush);
  2006.     HX_DELETE(pYUVBits);
  2007.     ReleaseDC(NULL, hDC);
  2008.     nNowTime = HX_GET_TICKCOUNT();
  2009.     int bltsPerSecond = counter*1000 / CALCULATE_ELAPSED_TICKS(nStartTime, nNowTime);
  2010.     return bltsPerSecond;
  2011. #endif
  2012. }
  2013. void CHXWinSite::_TryCreateXSlider()
  2014. {
  2015. //      if (!m_hXSlider)
  2016. //      {
  2017. //        _CreateXSlider(range);
  2018. //      }
  2019. }
  2020. void CHXWinSite::_SetXSliderValues(INT32 range, INT32 pageSize)
  2021. {
  2022.     if (!m_hXSlider)
  2023.     {
  2024.         _CreateXSlider(range);
  2025.     }
  2026.     SCROLLINFO info;
  2027.     memset(&info, 0, sizeof(SCROLLINFO));
  2028.     info.cbSize = sizeof(SCROLLINFO);
  2029.     info.fMask  = SIF_PAGE | SIF_RANGE;
  2030.     info.nMax   = range;
  2031.     info.nPage  = pageSize;
  2032.     SetScrollInfo( m_hXSlider, SB_CTL, &info, TRUE);
  2033.     m_XSliderRange = range;
  2034. }
  2035. void CHXWinSite::_TryCreateYSlider()
  2036. {
  2037. //      if (!m_hYSlider)
  2038. //      {
  2039. //        _CreateYSlider(range);
  2040. //      }
  2041. }
  2042. int CHXWinSite::_CreateXSlider(int range)
  2043. {
  2044.     HXxWindow* pwindow = GetParentWindow();
  2045.     HWND hwnd = (HWND)pwindow->window;
  2046.     int height = GetSystemMetrics(SM_CYHSCROLL);
  2047.     HXxPoint* pPoint = GetOrigin();
  2048.     HX_ASSERT(m_size.cy > height);
  2049.     if (m_size.cy < height)
  2050.     {
  2051.         height = m_size.cy /2;
  2052.     }
  2053.     m_hXSlider = CreateWindowEx(0, "SCROLLBAR", (LPSTR) NULL, WS_CHILD | SBS_HORZ,
  2054.                                 pPoint->x, pPoint->y + m_size.cy - height,
  2055.                                 m_size.cx, height,
  2056.                                 hwnd, (HMENU) NULL, GetModuleHandle(NULL), (LPVOID) NULL);
  2057.     zm_ScrollBarWnds.SetAt(m_hXSlider, this);
  2058.     SCROLLINFO info;
  2059.     memset(&info, 0, sizeof(SCROLLINFO));
  2060.     info.cbSize = sizeof(SCROLLINFO);
  2061.     info.fMask    = SIF_PAGE | SIF_RANGE;
  2062.     HXxSize parentSize;
  2063.     memset(&parentSize, 0, sizeof(HXxSize));
  2064.     if (m_pParentSite)
  2065.     {
  2066.         m_pParentSite->GetSize(parentSize);
  2067.     }
  2068.     info.nPage    = parentSize.cx;
  2069.     info.nMax   = range;
  2070.     SetScrollInfo( m_hXSlider, SB_CTL, &info, TRUE);
  2071.     m_XSliderRange  = range;
  2072.     SizeSliders();
  2073.     return (int) m_hXSlider;
  2074. }
  2075. int CHXWinSite::_CreateYSlider(int range)
  2076. {
  2077.     HXxWindow* pwindow = GetParentWindow();
  2078.     HWND hwnd = (HWND) pwindow->window;
  2079.     int width = GetSystemMetrics(SM_CXVSCROLL);
  2080.     HXxPoint* pPoint = GetOrigin();
  2081.     HX_ASSERT(m_size.cx > width);
  2082.     if (m_size.cx < width)
  2083.     {
  2084.         width = m_size.cx /2;
  2085.     }
  2086.     m_hYSlider = CreateWindowEx(0, "SCROLLBAR", (LPSTR) NULL, WS_CHILD | SBS_VERT,
  2087.                                 pPoint->x + m_size.cx - width, pPoint->y,
  2088.                                 width, m_size.cy,
  2089.                                 hwnd, (HMENU) NULL, GetModuleHandle(NULL), (LPVOID) NULL);
  2090.     zm_ScrollBarWnds.SetAt(m_hYSlider, this);
  2091.     SCROLLINFO info;
  2092.     memset(&info, 0, sizeof(SCROLLINFO));
  2093.     info.cbSize = sizeof(SCROLLINFO);
  2094.     info.fMask    = SIF_PAGE | SIF_RANGE;
  2095.     HXxSize parentSize;
  2096.     memset(&parentSize, 0, sizeof(HXxSize));
  2097.     if (m_pParentSite)
  2098.     {
  2099.         m_pParentSite->GetSize(parentSize);
  2100.     }
  2101.     info.nPage    = parentSize.cy;
  2102.     info.nMax   = range;
  2103.     SetScrollInfo( m_hYSlider, SB_CTL, &info, TRUE);
  2104.     m_YSliderRange  = range;
  2105.     SizeSliders();
  2106.     return (int) m_hYSlider;
  2107. }
  2108. void CHXWinSite::_SetYSliderValues(INT32 range, INT32 pageSize)
  2109. {
  2110.     if (!m_hYSlider)
  2111.     {
  2112.         _CreateYSlider(range);
  2113.     }
  2114.     SCROLLINFO info;
  2115.     memset(&info, 0, sizeof(SCROLLINFO));
  2116.     info.cbSize = sizeof(SCROLLINFO);
  2117.     info.fMask  = SIF_PAGE | SIF_RANGE;
  2118.     info.nMax   = range;
  2119.     info.nPage  = pageSize;
  2120.     SetScrollInfo( m_hYSlider, SB_CTL, &info, TRUE);
  2121.     m_YSliderRange = range;
  2122. }
  2123. void CHXWinSite::_GetSystemSizeOfSliders(INT32* pWidth, INT32* pHeight)
  2124. {
  2125.     *pWidth     = GetSystemMetrics(SM_CXVSCROLL);
  2126.     *pHeight    = GetSystemMetrics(SM_CYHSCROLL);
  2127. }
  2128. BOOL CHXWinSite::_IsWindowVisible()
  2129. {
  2130.     BOOL siteVisible = FALSE;
  2131.     RECT overAllrect;
  2132.     HXxWindow* pwindow = GetWindow();
  2133.     if (pwindow && pwindow->window)
  2134.     {
  2135.         HDC hdc = GetDC((HWND)pwindow->window);
  2136.         int retVal = GetClipBox(hdc, &overAllrect);
  2137.         if (retVal != NULLREGION)
  2138.         {
  2139.             siteVisible = TRUE;
  2140.         }
  2141.         ReleaseDC((HWND)pwindow->window, hdc);
  2142.     }
  2143.     return siteVisible;
  2144. }
  2145. void CHXWinSite::_ShowXSlider(BOOL bShow)
  2146. {
  2147.     if (m_hXSlider)
  2148.     {
  2149.         SafeShowWindow(m_hXSlider, bShow? SW_SHOW : SW_HIDE);
  2150.     }
  2151. }
  2152. void CHXWinSite::_MoveXSlider(INT32 left, INT32 top, INT32 right, INT32 bottom, BOOL bRedraw)
  2153. {
  2154.     if (m_hXSlider)
  2155.     {
  2156.         SafeMoveWindow(m_hXSlider, left, top, right, bottom, bRedraw);
  2157.     }
  2158. }
  2159. void CHXWinSite::_ShowYSlider(BOOL bShow)
  2160. {
  2161.     if (m_hYSlider)
  2162.     {
  2163.         SafeShowWindow(m_hYSlider, bShow? SW_SHOW : SW_HIDE);
  2164.     }
  2165. }
  2166. void CHXWinSite::_MoveYSlider(INT32 left, INT32 top, INT32 right, INT32 bottom, BOOL bRedraw)
  2167. {
  2168.     if (m_hYSlider)
  2169.     {
  2170.         SafeMoveWindow(m_hYSlider, left, top, right, bottom, bRedraw);
  2171.     }
  2172. }
  2173. BOOL CHXWinSite::_DoesXSliderExist()
  2174. {
  2175.     return m_hXSlider ? TRUE : FALSE;
  2176. }
  2177. void CHXWinSite::_GetCursorPos(HXxPoint* ptMouse)
  2178. {
  2179.     POINT pt;
  2180.     GetCursorPos(&pt);
  2181.     ptMouse->x = pt.x;
  2182.     ptMouse->y = pt.y;
  2183. }
  2184. void* CHXWinSite::_GetWindowWithCursor()
  2185. {
  2186.     HXxPoint pt;
  2187.     _GetCursorPos(&pt);
  2188.     return (void*)WindowFromPoint(WINPOINT(pt));
  2189. }
  2190. void CHXWinSite::_MapPointToOSWindow(HXxPoint* pPt, void** pWindowHandle)
  2191. {
  2192.     //    pWindowHandle = (void*) WindowFromPoint(WINPOINT(*pPt));
  2193. }
  2194. void CHXWinSite::SetCaptureMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  2195. {
  2196.     HXxEvent theEvent;
  2197.     if (m_pTopLevelSite->m_bSetCaptureOn)
  2198.     {
  2199.         /*
  2200.          *  XXXAH I have to figure out if I have to translate the x and y coords to
  2201.          *        some other origin when I find a renderer that exercises this code.
  2202.          */
  2203.         theEvent.event  = message;
  2204.         theEvent.window = (void*)hWnd;
  2205.         theEvent.param1 = (void*)wParam;
  2206.         theEvent.param2 = (void*)lParam;
  2207.         theEvent.result = 0;
  2208.         theEvent.handled = FALSE;
  2209.         if( m_pTopLevelSite->m_pCaptureUser )
  2210.             m_pTopLevelSite->m_pCaptureUser->HandleEvent(&theEvent);
  2211.     }
  2212. }
  2213. void CHXWinSite::_ReInitPrimarySurface()
  2214. {
  2215.     WINDRAW* pWindraw = ((CWinBaseRootSurface*)m_pRootSurface)->GetWinDraw();
  2216.     WinDraw2_RestorePrimarySurface(pWindraw);
  2217. }
  2218. void* CHXWinSite::_GetContainingWindow()
  2219. {
  2220.     return m_pContainingWindow->GetWindow();
  2221. }
  2222. /************************************************************************
  2223.  *  Class: CHXWinFullScreenWindow
  2224.  *
  2225.  *  The window used to contain the full screen windows.
  2226.  */
  2227. UINT32  CHXWinFullScreenWindow::zm_nInstanceCount           = 0;
  2228. char*   CHXWinFullScreenWindow::zm_pszWindowClassName       = "HXFullScreenWindowClass";
  2229. char*   CHXWinFullScreenWindow::zm_pszWindowName            = "HXFullScreenWindow";
  2230. BOOL    CHXWinFullScreenWindow::zm_bHideFullScreenWindow    = FALSE;
  2231. #define FULL_SCREEN_WINDOW_CLASSNAME
  2232. CHXWinFullScreenWindow::CHXWinFullScreenWindow(CHXWinSite* pSite) :
  2233.     m_hWnd(0)
  2234.                                                                   ,       m_pWindowless(pSite)
  2235.                                                                   ,       m_bIsVisible(FALSE)
  2236. {
  2237. }
  2238. CHXWinFullScreenWindow::~CHXWinFullScreenWindow()
  2239. {
  2240.     Destroy();
  2241. }
  2242. void
  2243. CHXWinFullScreenWindow::RegisterClass()
  2244. {
  2245.     if (0 == zm_nInstanceCount)
  2246.     {
  2247.         WNDCLASS wndClass;
  2248.         ATOM result;
  2249.         wndClass.style = CS_HREDRAW | CS_VREDRAW;
  2250.         wndClass.lpfnWndProc = CHXWinFullScreenWindow::WindowProc;
  2251.         wndClass.cbClsExtra = 0;
  2252.         wndClass.cbWndExtra = sizeof(this);
  2253.         wndClass.hInstance = GetModuleHandle(NULL);
  2254.         wndClass.hIcon = NULL;
  2255.         wndClass.hCursor = NULL;
  2256.         wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  2257.         wndClass.lpszMenuName = NULL;
  2258.         wndClass.lpszClassName = zm_pszWindowClassName;
  2259.         result = ::RegisterClass(&wndClass);
  2260.         HX_ASSERT(result);
  2261.     }
  2262.     zm_nInstanceCount++;
  2263. }
  2264. void
  2265. CHXWinFullScreenWindow::UnRegisterClass()
  2266. {
  2267.     HX_ASSERT(zm_nInstanceCount > 0);
  2268.     if (zm_nInstanceCount > 0)
  2269.     {
  2270.         zm_nInstanceCount--;
  2271.     }
  2272.     if (0 == zm_nInstanceCount)
  2273.     {
  2274.         BOOL result = ::UnregisterClass(zm_pszWindowClassName,GetModuleHandle(NULL));
  2275.         HX_ASSERT(result);
  2276.     }
  2277. }
  2278. HX_RESULT CHXWinFullScreenWindow::Create()
  2279. {
  2280. /*
  2281.  * Make sure the window class is registered.
  2282.  */
  2283.     RegisterClass();
  2284.     HXxWindow* ptempWindow = m_pWindowless->GetWindow();
  2285.     HWND hwnd = (HWND) ptempWindow->window;
  2286.     HWND oldHwnd = hwnd;
  2287.     while(hwnd)
  2288.     {
  2289.         hwnd = ::GetParent(hwnd);
  2290.         if (hwnd)
  2291.             oldHwnd = hwnd;
  2292.     }
  2293.     HWND parentWindow = GetParent((HWND)ptempWindow->window);
  2294.     m_hWnd = CreateWindowEx(
  2295.         NULL,
  2296.         zm_pszWindowClassName,
  2297.         zm_pszWindowName,
  2298.         WS_POPUP,
  2299.         0,
  2300.         0,
  2301.         100,
  2302.         100,
  2303.         oldHwnd,
  2304.         NULL,
  2305.         GetModuleHandle(NULL),
  2306.         NULL);
  2307.     if (!m_hWnd)
  2308.         return HXR_FAIL;
  2309.     SetWindowLong( m_hWnd, GWL_USERDATA, (long) this );
  2310.     return HXR_OK;
  2311. }
  2312. HX_RESULT CHXWinFullScreenWindow::Destroy()
  2313. {
  2314.     if (m_hWnd)
  2315.     {
  2316.         BOOL bDidDestroy = ::DestroyWindow(m_hWnd);
  2317. #ifdef _DEBUGGING_DESTROY_WINDOWS
  2318.         HX_ASSERT(bDidDestroy);
  2319. #endif
  2320.         m_hWnd = 0;
  2321.         UnRegisterClass();
  2322.         return HXR_OK;
  2323.     }
  2324.     return HXR_FAIL;
  2325. }
  2326. HX_RESULT CHXWinFullScreenWindow::Show()
  2327. {
  2328.     if (m_hWnd)
  2329.     {
  2330.         // resize the window the full screen
  2331.         int temp_sx = GetSystemMetrics(SM_CXSCREEN);
  2332.         int temp_sy = GetSystemMetrics(SM_CYSCREEN);
  2333.         // when we exit full screen mode via F1 the
  2334.         // full screen window gets minimized.
  2335.         ::ShowWindow(m_hWnd, SW_RESTORE);
  2336. #ifdef _HAMEL
  2337.         ::MoveWindow(m_hWnd, 0, 0, temp_sx, temp_sy, TRUE);
  2338. #else
  2339.         ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, temp_sx, temp_sy, NULL);
  2340. #endif
  2341.         ::ShowWindow(m_hWnd, SW_SHOW);
  2342.         m_bIsVisible = TRUE;
  2343.         m_hOldForegroudWindow = GetForegroundWindow();
  2344.         // from HXGui ...
  2345.         DWORD   dwLockTimeout = 0;
  2346.         // These are new flags that work on Win98 and WinNT5 ONLY.  First get the current foreground lock timeout and save
  2347.         // it off and then set it to 0.
  2348.         ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&dwLockTimeout,0);
  2349.         ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,0);
  2350.         // We should actually be able to become the foreground window now
  2351.         SetForegroundWindow(m_hWnd);
  2352.         // Restore the old foreground lock timeout
  2353.         ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)dwLockTimeout,0);
  2354.         m_hOldFocus = SetFocus(m_hWnd);
  2355.         ::SetActiveWindow(m_hWnd);
  2356.         return HXR_OK;
  2357.     }
  2358.     return HXR_FAIL;
  2359. }
  2360. HX_RESULT CHXWinFullScreenWindow::Hide()
  2361. {
  2362.     if (m_hWnd)
  2363.     {
  2364.         m_bIsVisible = FALSE;
  2365. #ifdef _ALAINDEBUG
  2366.         ::MoveWindow(m_hWnd, 0, 0, 100, 100, FALSE);
  2367. #else
  2368.         ::SetWindowPos(m_hWnd, HWND_NOTOPMOST , 0, 0, 100, 100, NULL);
  2369. #endif
  2370.         ::ShowWindow(m_hWnd, SW_HIDE);
  2371.         DWORD   dwLockTimeout = 0;
  2372.         // These are new flags that work on Win98 and WinNT5 ONLY.  First get the current foreground lock timeout and save
  2373.         // it off and then set it to 0.
  2374.         ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&dwLockTimeout,0);
  2375.         ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,0);
  2376.         // We should actually be able to become the foreground window now
  2377.         SetForegroundWindow(m_hOldForegroudWindow);
  2378.         // Restore the old foreground lock timeout
  2379.         ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)dwLockTimeout,0);
  2380.         ::SetFocus(m_hOldFocus);
  2381.         return HXR_OK;
  2382.     }
  2383.     return HXR_FAIL;
  2384. }
  2385. /************************************************************************
  2386.  *  Method:
  2387.  *    CHXWinFullScreenWindow::WindowProc
  2388.  *
  2389.  */
  2390. LRESULT HXEXPORT
  2391. CHXWinFullScreenWindow::WindowProc
  2392. (
  2393.     HWND    hWnd,
  2394.     UINT    message,
  2395.     WPARAM  wParam,
  2396.     LPARAM  lParam
  2397.     )
  2398. {
  2399.     CHXWinFullScreenWindow* pThis = NULL;
  2400.     pThis = (CHXWinFullScreenWindow*)GetWindowLong( hWnd, GWL_USERDATA );
  2401.     if (pThis != NULL)
  2402.     {
  2403.         switch( message )
  2404.         {
  2405. #ifndef _HAMEL
  2406.            case WM_ACTIVATE:
  2407.            {
  2408.                BOOL bIsActive = (BOOL)wParam;
  2409.                if (bIsActive==WA_INACTIVE && pThis->m_bIsVisible)
  2410.                {
  2411.                    pThis->ForceExitFullScreen(WM_CHAR, VK_ESCAPE, 0);
  2412.                }
  2413.            }
  2414.            break;
  2415.            case WM_ACTIVATEAPP:
  2416.            {
  2417.                BOOL    fActive = (BOOL) wParam;        // activation flag
  2418.                if (!fActive && pThis->m_bIsVisible)
  2419.                {
  2420.                    pThis->ForceExitFullScreen(WM_CHAR, VK_ESCAPE, 0);
  2421.                }
  2422.            }
  2423.            break;
  2424.            case WM_SYSKEYUP:
  2425.            {
  2426.                if (wParam == VK_TAB && pThis->m_bIsVisible)
  2427.                {
  2428.                    pThis->ForceExitFullScreen(WM_CHAR, VK_ESCAPE, 0);
  2429.                }
  2430.            }
  2431.            break;
  2432. #endif
  2433.            case WM_CLOSE:
  2434.            {
  2435.                pThis->ForceExitFullScreen(WM_CHAR, VK_ESCAPE, 0);
  2436.                return 0;
  2437.            }
  2438.            case WM_SYSCOMMAND:
  2439.            {
  2440.                int uCmdType = wParam;
  2441.                if (wParam == SC_SCREENSAVE)
  2442.                {
  2443.                    return 1;
  2444.                }
  2445.                else
  2446.                {
  2447.                    return DefWindowProc(hWnd, message, wParam, lParam);
  2448.                }
  2449.            }
  2450.         }
  2451.     }
  2452.     return DefWindowProc(hWnd, message, wParam, lParam);
  2453. }
  2454. void CHXWinFullScreenWindow::ForceExitFullScreen(UINT message, WPARAM  wParam, LPARAM  lParam)
  2455. {
  2456.     IHXSiteUser* pUser = NULL;
  2457.     if (m_pWindowless->GetUser(pUser) == HXR_OK && pUser)
  2458.     {
  2459.         HXxWindow* pwin = m_pWindowless->GetWindow();
  2460.         HXxEvent event = {message, (void*)pwin->window, (void*)wParam, (void*)lParam, 0, 0};
  2461.         pUser->HandleEvent(&event);
  2462.         HX_RELEASE(pUser);
  2463.     }
  2464. }
  2465. // crap from windowless here
  2466. void CHXWinSite::_SetFocus(void* pWindow)
  2467. {
  2468.     HX_ASSERT( pWindow );
  2469.     HWND hTmp = ::GetForegroundWindow();
  2470.     if( ::IsChild(hTmp, (HWND)GetWindow()->window ))
  2471.     {
  2472.         ::SetFocus((HWND)pWindow);
  2473.     }
  2474. }
  2475. BOOL CHXWinSite::_SetWindowRgn(void* hWnd, HXREGION* hRgn, BOOL bRedraw)
  2476. {
  2477.     HX_ASSERT( hWnd );
  2478.     HRGN rgn = CreateRectRgn(0,0,0,0);
  2479.     for(int i = 0; i< hRgn->numRects; i++)
  2480.     {
  2481.         HRGN tempRgn = CreateRectRgn(   hRgn->rects[i].x1 - m_topleft.x,
  2482.                                         hRgn->rects[i].y1 - m_topleft.y,
  2483.                                         hRgn->rects[i].x2 - m_topleft.x,
  2484.                                         hRgn->rects[i].y2 - m_topleft.y);
  2485.         CombineRgn(rgn, tempRgn, rgn, RGN_OR);
  2486.         DeleteObject(tempRgn);
  2487.     }
  2488.     int returnVal = ::SetWindowRgn((HWND)hWnd,rgn,bRedraw);
  2489.     //    DeleteObject(rgn);  OMG. What a messed up API.
  2490.     return returnVal;
  2491. }
  2492. BOOL CHXWinSite::_SetWindowPos(void* hWnd,
  2493.                                void* hWndInsertAfter,
  2494.                                INT32 X,
  2495.                                INT32 Y,
  2496.                                INT32 cx,
  2497.                                INT32 cy,
  2498.                                INT32 uFlags)
  2499. {
  2500.     // XXXSMJ As far as I can tell this is only a Windows thing and there aren't any
  2501.     // RMA flags.  This gets called from SafeSetWindowPos which in turn is only
  2502.     // called from WinSite.
  2503.     HX_ASSERT( GetWindow() );
  2504.     return ::SetWindowPos((HWND)hWnd,(HWND)hWndInsertAfter,X,Y,cx,cy,uFlags);
  2505. }
  2506. BOOL CHXWinSite::_MoveWindow( void* win,
  2507.                               INT32 X,
  2508.                               INT32 Y,
  2509.                               INT32 nWidth,
  2510.                               INT32 nHeight,
  2511.                               BOOL bRepaint)
  2512. {
  2513.     HX_ASSERT( GetWindow() );
  2514.     return ::MoveWindow((HWND)win,X,Y,nWidth,nHeight,bRepaint);
  2515. }
  2516. BOOL CHXWinSite::_ShowWindow(void* hWnd, INT32 nCmdShow)
  2517. {
  2518.     HX_ASSERT( GetWindow() );
  2519.     HX_ASSERT( nCmdShow==HX_SHOW_WINDOW || nCmdShow==HX_HIDE_WINDOW);
  2520.     int flags = (nCmdShow & HX_SHOW_WINDOW) ? SW_SHOW : SW_HIDE;
  2521.     ::ShowWindow((HWND)hWnd, flags);
  2522.     return TRUE;
  2523. }
  2524. BOOL CHXWinSite::_UpdateWindow(void* hWnd)
  2525. {
  2526.     return ::UpdateWindow((HWND)hWnd);
  2527. }
  2528. void CHXWinSite::_GetWindowRect(HXxRect* destRect)
  2529. {
  2530.     HX_ASSERT( GetWindow() );
  2531.     ::GetWindowRect((HWND)GetWindow()->window,(RECT*)destRect);
  2532. }
  2533. HX_RESULT CHXWinSite::_EventOccurred(HXxEvent* pEvent)
  2534. {
  2535.     return HXR_OK;
  2536. }
  2537. void CHXWinSite::_DamageRegion(HXxRegion pRegion)
  2538. {
  2539.     HXREGION* reg = (HXREGION*)pRegion;
  2540.     HXxRect rect;
  2541.     rect.left   = reg->extents.x1;
  2542.     rect.top    = reg->extents.y1;
  2543.     rect.right  = reg->extents.x2;
  2544.     rect.bottom = reg->extents.y2;
  2545.     _DamageRect(rect);
  2546. }
  2547. BOOL CHXWinSite::_ConvertToHXEvent(HXxEvent* pEvent)
  2548. {
  2549.     switch( pEvent->event )
  2550.     {
  2551.        case WM_KEYUP:
  2552.            pEvent->event = HX_KEY_UP;
  2553.            break;
  2554.        case WM_KEYDOWN:
  2555.            pEvent->event = HX_KEY_DOWN;
  2556.            break;
  2557.        case WM_CHAR:
  2558.            pEvent->event = HX_CHAR;
  2559.            break;
  2560.        case WM_LBUTTONUP:
  2561.            pEvent->event = HX_PRIMARY_BUTTON_UP;
  2562.            break;
  2563.        case WM_LBUTTONDOWN:
  2564.            pEvent->event = HX_PRIMARY_BUTTON_DOWN;
  2565.            break;
  2566.        case WM_RBUTTONUP:
  2567.            pEvent->event = HX_CONTEXT_BUTTON_UP;
  2568.            break;
  2569.        case WM_RBUTTONDOWN:
  2570.            pEvent->event = HX_CONTEXT_BUTTON_DOWN;
  2571.            break;
  2572.        case WM_MOUSEMOVE:
  2573.            pEvent->event = HX_MOUSE_MOVE;
  2574.            break;
  2575.        case WM_SETFOCUS:
  2576.            pEvent->event = HX_SET_FOCUS;
  2577.            break;
  2578.        case WM_KILLFOCUS:
  2579.            pEvent->event = HX_LOSE_FOCUS;
  2580.            break;
  2581.        case WM_LBUTTONDBLCLK:
  2582.            pEvent->event = HX_PRIMARY_DBLCLK;
  2583.            break;
  2584.        case WM_RBUTTONDBLCLK:
  2585.            pEvent->event = HX_CONTEXT_DBLCLK;
  2586.            break;
  2587.        default:
  2588.            HX_ASSERT("unkown event type...." );
  2589.     }
  2590.     return pEvent->handled;
  2591. }
  2592. void CHXWinSite::_DrawFocusRect(UCHAR* pImage,
  2593.                                 HXBitmapInfoHeader* pImageInfo,
  2594.                                 HXxRect* pImageSize,
  2595.                                 void* pOsSpecificData)
  2596. {
  2597. #if 1
  2598.     CHXBaseSite::_DrawFocusRect(pImage,
  2599.                                 pImageInfo,
  2600.                                 pImageSize,
  2601.                                 pOsSpecificData);
  2602.     return;
  2603. #else
  2604.     // Do we have an active rect
  2605.     if (!m_rcFocusRect.bRectActive)
  2606.         return;
  2607.     // Only support rgb for now
  2608.     if (IsYUV(GETBITMAPCOLOR(pImageInfo)))
  2609.         return;
  2610.     if (!pOsSpecificData)
  2611.         return;
  2612.     HDC hdc = *((HDC*)pOsSpecificData);
  2613.     // Create the proper pen style and color
  2614.     UINT32  ulPenStyle = PS_SOLID;
  2615.     if (m_rcFocusRect.ulLineStyle == HX_DASHED_LINE)
  2616.         ulPenStyle = PS_DASH;
  2617.     else if (m_rcFocusRect.ulLineStyle == HX_DOTTED_LINE)
  2618.         ulPenStyle = PS_DOT;
  2619.     HPEN hPen = CreatePen(ulPenStyle,
  2620.                           m_rcFocusRect.ulLineWidth,
  2621.                           RGB(m_rcFocusRect.red,
  2622.                               m_rcFocusRect.green,
  2623.                               m_rcFocusRect.blue));
  2624.     HGDIOBJ hOldPen = SelectObject(hdc, hPen);
  2625.     POINT p;
  2626.     if (m_rcFocusRect.ulShape & DRAW_RECT)
  2627.     {
  2628.         // Draw the rect
  2629.         MoveToEx(hdc, m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.bottom, &p);
  2630.         LineTo(hdc, m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.top);
  2631.         LineTo(hdc, m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.top);
  2632.         LineTo(hdc, m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.bottom);
  2633.         LineTo(hdc, m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.bottom);
  2634.     }
  2635.     else if (m_rcFocusRect.ulShape & DRAW_ELLIPSE)
  2636.     {
  2637.         // Draw the ellipse
  2638.         MoveToEx(hdc,
  2639.                  m_rcFocusRect.rcFocus.left,
  2640.                  (m_rcFocusRect.rcFocus.bottom-m_rcFocusRect.rcFocus.top)/2,
  2641.                  &p);
  2642.         ArcTo(hdc,
  2643.               m_rcFocusRect.rcFocus.left, m_rcFocusRect.rcFocus.top,
  2644.               m_rcFocusRect.rcFocus.right, m_rcFocusRect.rcFocus.bottom,
  2645.               m_rcFocusRect.rcFocus.left,
  2646.               (m_rcFocusRect.rcFocus.bottom-m_rcFocusRect.rcFocus.top)/2,
  2647.               m_rcFocusRect.rcFocus.left,
  2648.               (m_rcFocusRect.rcFocus.bottom-m_rcFocusRect.rcFocus.top)/2);
  2649.     }
  2650.     else if (m_rcFocusRect.ulShape & DRAW_POLYGON)
  2651.     {
  2652.         // Draw the polygon
  2653.         MoveToEx(hdc,
  2654.                  m_rcFocusRect.polygon.pFocusPoints[m_rcFocusRect.polygon.ulFocusPoints-1].x,
  2655.                  m_rcFocusRect.polygon.pFocusPoints[m_rcFocusRect.polygon.ulFocusPoints-1].y,
  2656.                  &p);
  2657.         PolylineTo(hdc, (CONST POINT*)(m_rcFocusRect.polygon.pFocusPoints), m_rcFocusRect.polygon.ulFocusPoints);
  2658.     }
  2659.     // Resotre old pen
  2660.     SelectObject(hdc, hOldPen);
  2661.     DeleteObject(hPen);
  2662. #endif
  2663. }
  2664. void CHXWinSite::CheckCapture()
  2665. {
  2666.     HWND                captureHwnd = GetCapture();
  2667.     CHXWinSite*  pTempThis   = NULL;
  2668.     if (m_pTopLevelSite && !m_pTopLevelSite->m_bSetCaptureOn)
  2669.     {
  2670.         if (CHXWinSite::zm_SubclassedWnds.Lookup((void*)captureHwnd,(void*&)pTempThis))
  2671.         {
  2672.             m_pTopLevelSite->m_bSetCaptureOn = TRUE;
  2673.             m_pTopLevelSite->m_pCaptureUser = m_pTopLevelSite->m_pLastUser;
  2674.         }
  2675.     }
  2676. }
  2677. void CHXWinSite::ReHookParents()
  2678. {
  2679.     //Remove all hooks.
  2680.     HWND hWnd;
  2681.     CHXSimpleList* pChildrenList;
  2682.     POSITION pos = CHXWinSite::zm_ParentWnds.GetStartPosition();
  2683.     while(pos)
  2684.     {
  2685.         zm_ParentWnds.GetNextAssoc(pos, (void*&) hWnd, (void*&) pChildrenList);
  2686.         pChildrenList->RemoveAll();
  2687.         HX_DELETE(pChildrenList);
  2688.     }
  2689.     CHXWinSite::zm_ParentWnds.RemoveAll();
  2690.     CHXMapPtrToPtr::Iterator i = m_ChildrenMap.Begin();
  2691.     for ( ; i != m_ChildrenMap.End(); ++i)
  2692.     {
  2693.         CHXBaseSite* pSite = (CHXBaseSite*) *i;
  2694.         HWND hWnd = (HWND)(pSite->GetWindow()->window);
  2695.         HX_ASSERT( hWnd );
  2696.         while (hWnd)
  2697.         {
  2698.             CHXSimpleList* pChildrenList;
  2699.             if (!CHXWinSite::zm_ParentWnds.Lookup((void*)hWnd,(void*&) pChildrenList))
  2700.             {
  2701.                 pChildrenList = new CHXSimpleList;
  2702.                 CHXWinSite::zm_ParentWnds.SetAt((void*)hWnd, (void*)pChildrenList);
  2703.             }
  2704.             LISTPOSITION pos = pChildrenList->Find(pSite);
  2705.             HX_ASSERT(pos == NULL);
  2706.             if (!pos)
  2707.             {
  2708.                 pChildrenList->AddTail(pSite);
  2709.             }
  2710.             hWnd = GetParent(hWnd);
  2711.         }
  2712.     }
  2713. }