winsite.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:97k
源码类别:

Symbian

开发平台:

C/C++

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