home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / navcontv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  202 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 "navcontv.h"
  21. #include "htrdf.h"
  22. #include "rdfliner.h"
  23. #include "pain.h"
  24. #include "navcntr.h"
  25. //-------------------------------------------------------------------------------------
  26. // Start Nav center Content View.
  27. //-------------------------------------------------------------------------------------
  28.  
  29.  
  30. //IMPLEMENT_DYNAMIC(CContentView, CScrollView)
  31. IMPLEMENT_DYNAMIC(CContentView, CView)
  32. BEGIN_MESSAGE_MAP(CContentView, CView)
  33.     //{{AFX_MSG_MAP(CMainFrame)
  34.         // NOTE - the ClassWizard will add and remove mapping macros here.
  35.         //    DO NOT EDIT what you see in these blocks of generated code !
  36.     ON_WM_SIZE()
  37.     ON_WM_CREATE()
  38.     ON_WM_SETFOCUS()
  39.     ON_WM_MOUSEMOVE()
  40.     ON_MESSAGE(WM_NAVCENTER_QUERYPOSITION, OnNavCenterQueryPosition)
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. CContentView::CContentView()
  44. {
  45.     m_pChildSizeInfo = NULL;
  46. }
  47.  
  48. CContentView::~CContentView()
  49. {
  50.     ASSERT(m_pChildSizeInfo == NULL);
  51. }
  52.  
  53. LRESULT CContentView::OnNavCenterQueryPosition(WPARAM wParam, LPARAM lParam)
  54. {
  55.     NAVCENTPOS *pPos = (NAVCENTPOS *)lParam;
  56.     
  57.     //  We like being in the middle.
  58.     pPos->m_iYDisposition = 0;
  59.     
  60.     //  We like being this many units in size.
  61.     pPos->m_iYVector = 100;
  62.     
  63.     //  Handled.
  64.     return(NULL);
  65. }
  66.  
  67. // MHW need this to fool MFC.  We have the CView without a CDocument object.
  68. int CContentView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  69. {
  70.     return 0;
  71. }
  72.  
  73. void CContentView::OnMouseMove( UINT nFlags, CPoint point )
  74. {
  75. }
  76.  
  77. void CContentView::OnDraw(CDC* pDC)  // overridden to draw this view
  78. {
  79. }
  80.  
  81. BOOL CALLBACK QuerySizeCallback(HWND hwnd, LPARAM lParam)  {
  82.     CContentView *pThis = (CContentView *)lParam;
  83.     
  84.     //  Must be direct child and visible.
  85.     if(GetParent(hwnd) == pThis->GetSafeHwnd() && ::IsWindowVisible(hwnd)) {
  86.         NAVCENTPOS ncp;
  87.         memset(&ncp, 0, sizeof(ncp));
  88.         
  89.         LRESULT lHandled = SendMessage(hwnd, WM_NAVCENTER_QUERYPOSITION, 0, (LPARAM)&ncp);
  90.         ASSERT(lHandled == NULL);  // You must handle this message.
  91.         ncp.m_hChild = hwnd;
  92.         
  93.         pThis->AddChildSizeInfo(&ncp);
  94.     }
  95.     
  96.     return(TRUE);
  97. }
  98.  
  99. void CContentView::AddChildSizeInfo(NAVCENTPOS *pPreference)
  100. {
  101.     if(m_pChildSizeInfo == NULL) {
  102.         m_pChildSizeInfo = XP_ListNew();
  103.     }
  104.     
  105.     NAVCENTPOS *pNew = (NAVCENTPOS *)XP_ALLOC(sizeof(NAVCENTPOS));
  106.     memcpy(pNew, pPreference, sizeof(NAVCENTPOS));
  107.     
  108.     XP_ListAddObject(m_pChildSizeInfo, pNew);
  109. }
  110.  
  111. void CContentView::OnActivateView( BOOL bActivate, CView* pActivateView, CView* pDeactiveView )
  112. {
  113.     CView *pView = (CView*)GetDescendantWindow( NC_IDW_OUTLINER );
  114.     // The default implementation is to give the focus to RDF tree view( NC_IDW_OUTLINER).
  115.     // If we can not find a RDF tree view, we will call the base class to set focus properly.
  116.     if (pView)
  117.         pView->SetFocus();
  118.     else
  119.         CView::OnActivateView(bActivate, pActivateView,pDeactiveView); 
  120. }
  121.  
  122.  
  123. void CContentView::OnSize( UINT nType, int cx, int cy )
  124. {
  125.     CView::OnSize(nType, cx, cy);
  126.     
  127.     //  Calculate the information.
  128.     CalcChildSizes();
  129. }
  130.  
  131. void CContentView::CalcChildSizes()
  132. {
  133.     //  Ask each descendant window what size it would like to be.
  134.     ::EnumChildWindows(GetSafeHwnd(), QuerySizeCallback, (LPARAM)this);
  135.  
  136.     CRect crClient;
  137.     GetClientRect(crClient);
  138.     int cx = crClient.Width();
  139.     int cy = crClient.Height();
  140.  
  141.     //  Total the sizes of all the child window vectors.
  142.     //  This will let us scale by percentage.
  143.     XP_List *pTraverse = m_pChildSizeInfo;
  144.     NAVCENTPOS *pPos = NULL;
  145.     int iTotalHeight = 0;
  146.     while(pPos = (NAVCENTPOS *)XP_ListNextObject(pTraverse)) {
  147.         iTotalHeight += pPos->m_iYVector;
  148.     }
  149.     
  150.     //  Find the child with the lowest Y disposition.
  151.     int iCurPos;
  152.     int iNextY = 0;
  153.     while(XP_ListCount(m_pChildSizeInfo)) {
  154.         pTraverse = m_pChildSizeInfo;
  155.         iCurPos = INT_MAX;
  156.         //  Find topmost position.
  157.         while(pPos = (NAVCENTPOS *)XP_ListNextObject(pTraverse)) {
  158.             if(pPos->m_iYDisposition < iCurPos) {
  159.                 iCurPos = pPos->m_iYDisposition;
  160.             }
  161.         }
  162.         pTraverse = m_pChildSizeInfo;
  163.         while(pPos = (NAVCENTPOS *)XP_ListNextObject(pTraverse)) {
  164.             if(pPos->m_iYDisposition == iCurPos) {
  165.                 //  Resize it.
  166.                 float fPercent = (float)(pPos->m_iYVector) / (float)iTotalHeight;
  167.                 int iNewHeight = (int)(fPercent * (float)cy);
  168.                 
  169.                 //  Handle rounding errors.
  170.                 if(iNextY + iNewHeight > cy) {
  171.                     iNewHeight = cy - iNextY;
  172.                 }
  173.                 
  174.                 RECT rect;
  175.                 ::GetClientRect(pPos->m_hChild, &rect);
  176.                 ::SetWindowPos(pPos->m_hChild, HWND_BOTTOM, 0, iNextY, cx, iNewHeight, SWP_NOZORDER);
  177.                 
  178.                 iNextY += iNewHeight;
  179.                 
  180.                 //  Remove this one from the list.
  181.                 XP_ListRemoveObject(m_pChildSizeInfo, pPos);
  182.                 XP_FREE(pPos);
  183.                 break;
  184.             }
  185.         }
  186.     }
  187.     
  188.     if(m_pChildSizeInfo) {
  189.         XP_ListDestroy(m_pChildSizeInfo);
  190.         m_pChildSizeInfo = NULL;
  191.     }
  192. }
  193.  
  194. void CContentView::OnSetFocus ( CWnd * pOldWnd )
  195. {
  196.     CView *pView = (CView*)GetDescendantWindow( NC_IDW_OUTLINER );
  197.     if (pView)
  198.         pView->SetFocus();
  199. }
  200.  
  201. //////////////////////////////////////////////////////////////////////////////
  202.