home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / lastacti.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  113 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "slavewnd.h"
  21. #include "xp_ncent.h"
  22.  
  23. void laxpg_frameactive(CFrameGlue *pFrame)
  24. {
  25.     MWContext *pLastActive = NULL;
  26.  
  27.     if(pFrame) {
  28.         if(pFrame->GetActiveContext() &&
  29.            pFrame->GetActiveContext()->GetContext() &&
  30.            FALSE == pFrame->GetActiveContext()->IsDestroyed()) {
  31.             pLastActive = pFrame->GetActiveContext()->GetContext();
  32.         }
  33.         else if(pFrame->GetMainContext() &&
  34.                 pFrame->GetMainContext()->GetContext() &&
  35.                 FALSE == pFrame->GetMainContext()->IsDestroyed()) {
  36.             pLastActive = pFrame->GetMainContext()->GetContext();
  37.         }
  38.     }
  39.  
  40.     if(pLastActive) {
  41.         XP_SetLastActiveContext(pLastActive);
  42.     }
  43. }
  44.  
  45. void laxpg_contextactive(CFrameGlue *pFrame, CAbstractCX *pCX)
  46. {
  47.     MWContext *pLastActive = NULL;
  48.     
  49.     if(pFrame && pCX) {
  50.         CFrameWnd *pFWnd = pFrame->GetFrameWnd();
  51.         HWND hFWnd = pFWnd ? pFWnd->m_hWnd : NULL;
  52.         if(hFWnd) {
  53.             //  Must be active, or we do not want to reflect into
  54.             //      xp active layer.
  55.             HWND hFocus = ::GetFocus();
  56.             if(hFocus && (hFocus == hFWnd || ::IsChild(hFWnd, hFocus))) {
  57.                 if(pCX->GetContext() && FALSE == pCX->IsDestroyed()) {
  58.                     pLastActive = pCX->GetContext();
  59.                 }
  60.             }
  61.         }
  62.     }
  63.     
  64.     if(pLastActive) {
  65.         XP_SetLastActiveContext(pLastActive);
  66.     }
  67. }
  68.  
  69. void laxpg_init(UINT uMsg, WPARAM wParam, LPARAM lParam)
  70. {
  71.     //  Register with FrameGlue to be notified when
  72.     //      frame level activation changes.
  73.     CFrameGlue::AddActiveNotifyCB(laxpg_frameactive);
  74.     
  75.     //  Register with GenView to be notified when
  76.     //      view level activation changes.
  77.     CFrameGlue::AddActiveContextCB(laxpg_contextactive);
  78. }
  79.  
  80. void laxpg_exit(UINT uMsg, WPARAM wParam, LPARAM lParam)
  81. {
  82.     CFrameGlue::RemoveActiveNotifyCB(laxpg_frameactive);
  83.     CFrameGlue::RemoveActiveContextCB(laxpg_contextactive);
  84. }
  85.  
  86. class CLastActiveXPGlue {
  87. private:
  88.     void *m_pInitCookie;
  89.     void *m_pExitCookie;
  90. public:
  91.     CLastActiveXPGlue();
  92.     ~CLastActiveXPGlue();
  93. } laxpg;
  94.  
  95. CLastActiveXPGlue::CLastActiveXPGlue()
  96. {
  97.     m_pInitCookie = slavewnd.Register(SLAVE_INITINSTANCE, laxpg_init);
  98.     m_pExitCookie = slavewnd.Register(SLAVE_EXITINSTANCE, laxpg_exit);
  99. }
  100.  
  101. CLastActiveXPGlue::~CLastActiveXPGlue()
  102. {
  103.     if(m_pInitCookie) {
  104.         slavewnd.UnRegister(m_pInitCookie);
  105.         m_pInitCookie = NULL;
  106.     }
  107.     if(m_pExitCookie) {
  108.         slavewnd.UnRegister(m_pExitCookie);
  109.         m_pExitCookie = NULL;
  110.     }
  111. }
  112.  
  113.