home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / splash.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.8 KB  |  353 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. // splash.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "splash.h"
  24.  
  25.  
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. #ifdef EDITOR
  32. #endif
  33.  
  34. #define STATUS_TEXT_HEIGHT -14
  35. #define COPYRIGHT_TEXT_HEIGHT 10
  36.  
  37. BEGIN_MESSAGE_MAP(CSplashWnd, CDialog)
  38.     //{{AFX_MSG_MAP(CSplashWnd)
  39.     ON_WM_TIMER()
  40.     ON_BN_CLICKED(IDC_BIGSPLASH, OnLogoClicked)
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CSplashWnd dialog
  45.  
  46. CSplashWnd::CSplashWnd()
  47. {
  48.     m_bNavBusyIniting = TRUE;
  49. }
  50.  
  51. BOOL CSplashWnd::Create(CWnd* pParent)
  52. {
  53.     //{{AFX_DATA_INIT(CSplashWnd)
  54.         // NOTE: the ClassWizard will add member initialization here
  55.     //}}AFX_DATA_INIT
  56.  
  57.     if (!CDialog::Create(CSplashWnd::IDD, pParent))
  58.     {
  59.         TRACE0("Warning: creation of CSplashWnd dialog failed\n");
  60.         return FALSE;
  61.     }
  62.  
  63.     int frameCX = ::GetSystemMetrics(SM_CXDLGFRAME);
  64.     int frameCY = ::GetSystemMetrics(SM_CYDLGFRAME);
  65.  
  66. #ifdef WIN32
  67.     // figure out whether to change for Win 95
  68.     if (sysInfo.m_bWin4) {
  69.         frameCX = ::GetSystemMetrics(SM_CXFIXEDFRAME);
  70.         frameCY = ::GetSystemMetrics(SM_CYFIXEDFRAME);
  71.     }
  72. #endif
  73.  
  74.     SetWindowPos(&wndTopMost,
  75.                  0, 0,
  76.                  m_sizeBitmap.cx + (frameCX * 2),
  77.                  m_sizeBitmap.cy + (frameCY * 2),
  78.                  SWP_NOMOVE);
  79.  
  80.     //Put this after we size the dialog with the bitmap.
  81.     CenterWindow();
  82.  
  83.     
  84.     return TRUE;
  85. }
  86.  
  87. BOOL CSplashWnd::OnInitDialog()
  88. {
  89.     const WORD  splashTimeout = 2000;
  90.  
  91.     CDialog::OnInitDialog();
  92.  
  93.     // initialize the big icon control
  94.     m_icon.SubclassDlgItem(IDC_BIGSPLASH, this);
  95.     m_icon.SizeToContent(m_sizeBitmap);
  96.  
  97.     m_timerID = 55; 
  98.     m_timerID = SetTimer(m_timerID, splashTimeout, NULL);   // N seconds
  99.  
  100.     return TRUE;  // return TRUE  unless you set the focus to a control
  101. }
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CSplashWnd message handlers
  105.  
  106. void CSplashWnd::OnLogoClicked()
  107. {
  108.     KillTimer(m_timerID);
  109.     EndDialog(NULL);
  110. }
  111.      
  112. void CSplashWnd::OnTimer(UINT uTimerID)
  113. {
  114.     if(m_bNavBusyIniting)
  115.         return; // wait for next timer interval
  116.  
  117.     OnLogoClicked();
  118. }
  119.  
  120. void CSplashWnd::NavDoneIniting()
  121. {
  122.     m_bNavBusyIniting = FALSE;
  123.     DestroyWindow();
  124.     m_icon.CleanupResources();
  125. }
  126.  
  127. void CSplashWnd::SafeHide()
  128. {
  129.     if (GetSafeHwnd()) {
  130.         ShowWindow(SW_HIDE);
  131.     }
  132. }
  133. void CSplashWnd::DisplayStatus(LPCSTR lpszStatus)
  134. {
  135.     ASSERT(lpszStatus);
  136.     m_icon.DisplayStatus(lpszStatus);
  137.     SetWindowText(lpszStatus);
  138. }
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CBigIcon
  142.  
  143. BEGIN_MESSAGE_MAP(CBigIcon, CButton)
  144.     //{{AFX_MSG_MAP(CBigIcon)
  145.     ON_WM_DRAWITEM()
  146.     ON_WM_ERASEBKGND()
  147.     //}}AFX_MSG_MAP
  148. END_MESSAGE_MAP()
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CBigIcon message handlers
  152.  
  153. CBigIcon::CBigIcon()
  154. {
  155.     HFONT hFont;
  156.     LOGFONT lf1, lf2;
  157.     int Adjustment = 0;
  158.  
  159. #if _WIN32 // Try to fix bug #37584 (unicode support)
  160.     
  161.     if( sysInfo.m_bWin4 )
  162.     {
  163.         hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  164.         Adjustment = 2;
  165.     }
  166.     else
  167.     {
  168.         hFont = (HFONT)GetStockObject( OEM_FIXED_FONT );
  169.     }
  170.  
  171. #else
  172.     hFont = (HFONT)GetStockObject( OEM_FIXED_FONT );
  173. #endif    
  174.  
  175.     
  176.  
  177.     VERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf1));
  178.     lf1.lfHeight = STATUS_TEXT_HEIGHT + Adjustment;
  179.     lf1.lfWidth = 2 + Adjustment;
  180.     VERIFY(m_font.CreateFontIndirect(&lf1));
  181.     VERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf2));
  182.     lf2.lfHeight = COPYRIGHT_TEXT_HEIGHT + Adjustment;
  183.     lf2.lfWidth = 2 + Adjustment;
  184.     VERIFY(m_copyrightFont.CreateFontIndirect(&lf2));
  185.     m_hBitmap = NULL;
  186. }
  187.  
  188. CBigIcon::~CBigIcon()
  189. {
  190. }
  191.  
  192. void CBigIcon::CleanupResources(void)
  193. {
  194.     if(m_hBitmap)
  195.         DeleteObject(m_hBitmap);
  196.  
  197.     m_copyrightFont.DeleteObject();
  198.     m_font.DeleteObject();
  199.  
  200. }
  201.  
  202. #ifdef XP_WIN16
  203. #define ADMNLIBNAME "adm1640.dll"
  204. #elif defined XP_WIN32
  205. #define ADMNLIBNAME "adm3240.dll"
  206. #endif
  207.  
  208. void CBigIcon::SizeToContent(CSize& SizeBitmap)
  209. {
  210.     // if admin kit library is here, load splash screen bitmap from it
  211.     HINSTANCE h = 0;
  212.     BOOL bFreeLibrary = FALSE;
  213.  
  214. #ifdef MOZ_ADMIN_LIB
  215.     h = LoadLibrary(ADMNLIBNAME);
  216. #endif   
  217.     UINT nBitmapID;
  218.     if (h < (HINSTANCE)HINSTANCE_ERROR) {
  219.         nBitmapID = IDB_PREVIEWSPLASH;
  220.         h = AfxGetResourceHandle();
  221.     } else {
  222.         nBitmapID = IDB_PREVIEWSPLASH;
  223.         bFreeLibrary = TRUE;
  224.     }
  225.  
  226.     HDC hDC = ::GetDC(m_hWnd);
  227.     WFE_InitializeUIPalette(hDC);
  228.     HPALETTE hPalette = WFE_GetUIPalette(NULL);
  229.     HPALETTE hOldPalette = ::SelectPalette(hDC, hPalette, FALSE);
  230.     ::RealizePalette(hDC);
  231.     m_hBitmap = wfe_LoadBitmap(h, hDC, MAKEINTRESOURCE(nBitmapID)); 
  232.  
  233.     if (!m_hBitmap && bFreeLibrary) {
  234.         m_hBitmap = wfe_LoadBitmap(AfxGetResourceHandle(), hDC, MAKEINTRESOURCE(nBitmapID));         
  235.     }
  236.  
  237.     ::SelectPalette(hDC, hOldPalette, TRUE);
  238.     ::ReleaseDC(m_hWnd, hDC);
  239.  
  240.     if (bFreeLibrary) 
  241.         FreeLibrary(h);
  242.  
  243.     BITMAP bm;
  244.     ::GetObject(m_hBitmap, sizeof(bm), &bm);
  245.     m_sizeBitmap = CSize(bm.bmWidth, bm.bmHeight);
  246.     SizeBitmap = m_sizeBitmap;
  247.  
  248.     SetWindowPos(NULL, 0, 0, bm.bmWidth, bm.bmHeight,
  249.         SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
  250. }
  251.  
  252. void CBigIcon::DisplayCopyright(void)
  253. {
  254.     CClientDC    dc(this);
  255.     CFont*        pOldFont = dc.SelectObject(&m_copyrightFont);
  256.     CRect        rect;
  257.     LPCSTR lpszCopyright = szLoadString(IDS_COPYRIGHT);
  258.     // The splash screen background is black, use light grey text
  259.     dc.SetBkColor(RGB(0,0,0));
  260.     dc.SetTextColor(RGB(192, 192, 192));
  261.  
  262.     CenterText(dc, lpszCopyright, 237);
  263.  
  264.     // Clean up
  265.     dc.SetBkColor(RGB(255,255,255));
  266.     dc.SetTextColor(RGB(0,0,0));
  267.     dc.SelectObject(pOldFont);
  268. }
  269.  
  270. void CBigIcon::DisplayStatus(LPCSTR lpszStatus)
  271. {
  272.     CClientDC    dc(this);
  273.     CFont*        pOldFont = dc.SelectObject(&m_font);
  274.  
  275.     // The splash screen background is black, so use white text
  276.     dc.SetBkColor(RGB(0,0,0));
  277.     dc.SetTextColor(RGB(255,255,255));
  278.  
  279.     CenterText(dc, lpszStatus, 219);
  280.  
  281.     // Clean up
  282.     dc.SetBkColor(RGB(255,255,255));
  283.     dc.SetTextColor(RGB(0,0,0));
  284.     dc.SelectObject(pOldFont);
  285. }
  286.  
  287. void CBigIcon::CenterText(CClientDC &dc, LPCSTR lpszStatus, int top)
  288. {
  289.     int            nMargin;
  290.     CRect        rect;
  291.     TEXTMETRIC    tm;
  292.  
  293.     // Leave a horizontal margin equal to the widest character
  294.     VERIFY(dc.GetTextMetrics(&tm));
  295.     nMargin = tm.tmMaxCharWidth;
  296.  
  297.     // Compute the opaque rect
  298.     rect.left = nMargin;
  299.     rect.right = m_sizeBitmap.cx - nMargin;
  300.     rect.top = top;
  301.     rect.bottom = rect.top + tm.tmHeight;
  302.  
  303.     // We need to compute where to draw the text so it is centered
  304.     // horizontally
  305.     int        x = rect.left;
  306.     CSize   extent = CIntlWin::GetTextExtent(0, dc.m_hDC, lpszStatus, XP_STRLEN(lpszStatus));
  307.  
  308.     if (extent.cx < rect.Width())
  309.         x += (rect.Width() - extent.cx) / 2;
  310.  
  311.     // Draw opaquely so we can avoid erasing the old text
  312.     dc.ExtTextOut(x, rect.top, ETO_OPAQUE, &rect, lpszStatus, strlen(lpszStatus), NULL);
  313.  
  314.  
  315. }
  316. void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  317. {
  318.     CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  319.     ASSERT(pDC != NULL);
  320.  
  321.     HPALETTE hPalette = WFE_GetUIPalette(NULL);
  322.     HPALETTE hOldPalette = ::SelectPalette(lpDrawItemStruct->hDC, hPalette, FALSE);
  323.     ::RealizePalette(lpDrawItemStruct->hDC);
  324.  
  325.     CRect rect;
  326.     GetClientRect(rect);
  327.     int cxClient = rect.Width();
  328.     int cyClient = rect.Height();
  329.  
  330.     // draw the bitmap contents
  331.     CDC dcMem;
  332.     if (!dcMem.CreateCompatibleDC(pDC))
  333.         return;
  334.     HBITMAP hOldBitmap = (HBITMAP)::SelectObject(dcMem.m_hDC, m_hBitmap);
  335.     if (hOldBitmap == NULL)
  336.         return;
  337.  
  338.     pDC->BitBlt(0, 0, m_sizeBitmap.cx, m_sizeBitmap.cy, &dcMem, 0, 0, SRCCOPY);
  339.  
  340.     ::SelectObject(dcMem.m_hDC, hOldBitmap);
  341.     DisplayCopyright();
  342.     ::SelectPalette(lpDrawItemStruct->hDC, hOldPalette, TRUE);
  343.  
  344.     ReleaseDC(pDC);
  345. }
  346.  
  347. BOOL CBigIcon::OnEraseBkgnd(CDC*)
  348. {
  349.     return TRUE;    // we don't do any erasing...
  350. }
  351.  
  352. /////////////////////////////////////////////////////////////////////////////
  353.