home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / msgtmpl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.9 KB  |  135 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. #include "stdafx.h"
  19. #include "msgtmpl.h"
  20. #include "mailfrm.h"
  21. #include "thrdfrm.h"
  22. #include "msgfrm.h"
  23. #include "prefapi.h"
  24.  
  25. void CMsgTemplate::_InitialUpdate(CFrameWnd *pFrame, CFrameWnd *pPrevFrame,
  26.                                   BOOL bMakeVisible, 
  27.                                   LPSTR lpszPosPref, LPSTR lpszShowPref)
  28. {
  29.     int32 prefInt;
  30.     int16 left, top, width, height;
  31.     PREF_GetIntPref(lpszShowPref, &prefInt);
  32.     PREF_GetRectPref(lpszPosPref, &left, &top, &width, &height);
  33.  
  34.     POINT ptPos;
  35.     SIZE size;
  36.     int show = SW_NORMAL;
  37.  
  38.     ptPos.x = left;
  39.     ptPos.y = top;
  40.     size.cx = width;
  41.     size.cy = height;
  42.     show = (prefInt == SW_MAXIMIZE) ? SW_MAXIMIZE : 0;
  43.  
  44.     if ( pPrevFrame ) {
  45.         WINDOWPLACEMENT wp;
  46.         wp.length = sizeof(WINDOWPLACEMENT);
  47.         pPrevFrame->GetWindowPlacement(&wp);
  48.         
  49.         if ( wp.showCmd == SW_MAXIMIZE ) {
  50.             // Previous frame is maximized, 
  51.             //  so show the new frame in maximized state
  52.             show = SW_MAXIMIZE;                    
  53.         }
  54.  
  55.         CRect rectLast = wp.rcNormalPosition;
  56.  
  57.         int titleY = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYFRAME);
  58.  
  59.         ptPos.x = rectLast.left + titleY;
  60.         ptPos.y = rectLast.top + titleY;
  61.         size.cx = rectLast.right - rectLast.left;
  62.         size.cy = rectLast.bottom - rectLast.top;
  63.     }    
  64.  
  65.     if (ptPos.x != -1) {
  66.         int sx = GetSystemMetrics(SM_CXFULLSCREEN);
  67.         int sy = GetSystemMetrics(SM_CYFULLSCREEN);
  68.  
  69.         // Sanity check size
  70.         if (size.cx > sx)
  71.             size.cx = sx;
  72.         if (size.cx < 300)
  73.             size.cx = 300;
  74.         if (size.cy > sy)
  75.             size.cy = sy;
  76.         if (size.cy < 300)
  77.             size.cy = 300;
  78.  
  79.         // Sanity check position
  80.         if (ptPos.x + size.cx > sx)
  81.             ptPos.x = 0;
  82.         if (ptPos.x < 0)
  83.             ptPos.x = 0;
  84.         if (ptPos.y + size.cy > sy)
  85.             ptPos.y = 0;
  86.         if (ptPos.y < 0)
  87.             ptPos.y = 0;
  88.  
  89.         WINDOWPLACEMENT wp;
  90.         memset(&wp, 0, sizeof(WINDOWPLACEMENT));
  91.         wp.length = sizeof(WINDOWPLACEMENT);
  92.         pFrame->GetWindowPlacement(&wp);
  93.  
  94.         wp.showCmd = show;
  95.         ::SetRect(&wp.rcNormalPosition, ptPos.x, ptPos.y,
  96.                   ptPos.x + size.cx, ptPos.y + size.cy);
  97.  
  98.         pFrame->SetWindowPlacement(&wp);
  99.     }
  100.     pFrame->ActivateFrame(SW_SHOW);
  101. }
  102.  
  103. void CFolderTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
  104.                                          BOOL bMakeVisible)
  105. {
  106.     _InitialUpdate(pFrame, NULL, bMakeVisible,
  107.                    "mailnews.folder_window_rect",
  108.                    "mailnews.folder_window_showwindow");
  109.  
  110.     CMsgTemplate::InitialUpdateFrame(pFrame, pDoc, bMakeVisible);
  111. }
  112.  
  113. void CThreadTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
  114.                                        BOOL bMakeVisible)
  115. {
  116.     CFrameWnd *pPrevFrame = CMailNewsFrame::GetLastThreadFrame(pFrame);
  117.     _InitialUpdate(pFrame, pPrevFrame, bMakeVisible,
  118.                    "mailnews.thread_window_rect",
  119.                    "mailnews.thread_window_showwindow");
  120.  
  121.     CMsgTemplate::InitialUpdateFrame(pFrame, pDoc, bMakeVisible);
  122. }
  123.  
  124. void CMessageTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
  125.                                         BOOL bMakeVisible)
  126. {
  127.     CFrameWnd *pPrevFrame = CMailNewsFrame::GetLastMessageFrame(pFrame);
  128.     _InitialUpdate(pFrame, pPrevFrame, bMakeVisible,
  129.                    "mailnews.message_window_rect",
  130.                    "mailnews.message_window_showwindow");
  131.  
  132.     CMsgTemplate::InitialUpdateFrame(pFrame, pDoc, bMakeVisible);
  133. }
  134.  
  135.