home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / nsadrtyp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.4 KB  |  281 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. // NSAdrTyp.cpp : implementation file
  20. // See NSAdrTyp.h for details on how to use this class
  21. //
  22.  
  23. #include "stdafx.h"
  24. #include "resource.h"
  25. #include "nsadrlst.h"
  26. #include "nsadrtyp.h"
  27. #include "compfrm.h"
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CNSAddressTypeComboBox
  31.  
  32. CNSAddressTypeControl::CNSAddressTypeControl()
  33. {
  34.     m_iTypeBitmapWidth = 0;
  35.  
  36.     penFace.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNFACE));
  37.     brushFace.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  38. #ifdef _WIN32
  39.     pen3dLight.CreatePen(PS_SOLID,1,GetSysColor(COLOR_3DLIGHT));
  40.     pen3dShadow.CreatePen(PS_SOLID,1,GetSysColor(COLOR_3DSHADOW));
  41.     pen3dHilight.CreatePen(PS_SOLID,1,GetSysColor(COLOR_3DHILIGHT));
  42.     pen3dDkShadow.CreatePen(PS_SOLID,1,GetSysColor(COLOR_3DDKSHADOW));
  43. #else
  44.     pen3dLight.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT));
  45.     pen3dShadow.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW));
  46.     pen3dHilight.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT));
  47.     pen3dDkShadow.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW));
  48. #endif
  49. }
  50.  
  51. CNSAddressTypeControl::~CNSAddressTypeControl()
  52. {
  53.     if (m_cfTextFont) {
  54.         theApp.ReleaseAppFont(m_cfTextFont);
  55.     }
  56. }
  57.  
  58. BOOL CNSAddressTypeControl::Create( CWnd *pParent )
  59. {
  60.     BOOL rv = CListBox::Create( 
  61.         LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | LBS_WANTKEYBOARDINPUT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
  62.         CRect(0,0,0,0), pParent, (UINT)5000 );
  63.     CBitmap cbitmap;
  64.     cbitmap.LoadBitmap(IDB_ARROW3D);
  65.     BITMAP bitmap;
  66.     cbitmap.GetObject(sizeof(BITMAP), &bitmap);
  67.     m_iTypeBitmapWidth = bitmap.bmWidth;
  68.     cbitmap.DeleteObject();
  69.     return rv;
  70. }
  71.  
  72. BEGIN_MESSAGE_MAP(CNSAddressTypeControl, CListBox)
  73.     //{{AFX_MSG_MAP(CNSAddressTypeControl)
  74.     ON_WM_KILLFOCUS()
  75.     ON_WM_SETFOCUS()
  76.     ON_WM_KEYDOWN()
  77.     ON_WM_CREATE()
  78.     ON_WM_LBUTTONDOWN()
  79.     ON_WM_MOUSEMOVE()
  80.     ON_WM_ENTERIDLE()
  81.     //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83.  
  84. void CNSAddressTypeControl::OnKillFocus(CWnd *pNewWnd) 
  85. {
  86.     GetParent()->SendMessage(WM_CHILDLOSTFOCUS);
  87.     CListBox::OnKillFocus(pNewWnd);
  88. }
  89.  
  90. BOOL CNSAddressTypeControl::PreTranslateMessage( MSG* pMsg ) 
  91. {
  92.     if ( (pMsg->message == WM_KEYDOWN) && ( (pMsg->wParam == VK_TAB) || (pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_BACK) ) )
  93.         return ((CNSAddressList *)GetParent())->OnKeyPress( this, pMsg->wParam, LOWORD( pMsg->lParam ), HIWORD( pMsg->lParam ) );
  94.  
  95.     return CListBox::PreTranslateMessage(pMsg);
  96. }
  97.  
  98. void CNSAddressTypeControl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
  99. {
  100.     CDC * pDC = GetDC();
  101.     TEXTMETRIC tm;
  102.     pDC->GetTextMetrics(&tm);
  103.     lpMeasureItemStruct->itemHeight = tm.tmHeight;
  104.     ReleaseDC(pDC);
  105. }
  106.  
  107.  
  108. void CNSAddressTypeControl::OnSetFocus(CWnd* pOldWnd) 
  109. {
  110.     CListBox::OnSetFocus(pOldWnd);
  111. }
  112.  
  113.  
  114. void CNSAddressTypeControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  115. {
  116.     switch (nChar) 
  117.     {
  118.         case VK_SPACE:
  119.             GetParent()->PostMessage(WM_DISPLAYTYPELIST);       
  120.             return;
  121.         case VK_UP:
  122.         case VK_DOWN:
  123.         case VK_HOME: 
  124.         case VK_END: 
  125.     case VK_DELETE:
  126.             ((CNSAddressList *)GetParent())->OnKeyPress(this,nChar,nRepCnt,nFlags); 
  127.             return;
  128.         break;
  129.     }
  130.     CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
  131. }
  132.  
  133.  
  134. void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor )
  135. {
  136. #ifdef FEATURE_DRAWTRANSBITMAP
  137. #include "nsadrtyp.i00"
  138. #endif
  139. }
  140.  
  141. int CNSAddressTypeControl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  142. {
  143.     if (CListBox::OnCreate(lpCreateStruct) == -1)
  144.         return -1;
  145.  
  146.     CComposeFrame * pFrame = (CComposeFrame*)GetParentFrame();
  147.     CDC * pdc = GetDC();
  148.     int16 resource_csid = INTL_CharSetNameToID(INTL_ResourceCharSet());
  149.     LOGFONT lf;                 
  150.     memset(&lf,0,sizeof(LOGFONT));
  151.     lf.lfPitchAndFamily = FF_MODERN | FIXED_PITCH;
  152.     lf.lfHeight = -MulDiv(NS_ADDRESSFONTSIZE,pdc->GetDeviceCaps(LOGPIXELSY), 72);
  153.     ReleaseDC ( pdc );
  154.     lf.lfQuality = PROOF_QUALITY;    
  155.     lf.lfCharSet = IntlGetLfCharset(resource_csid); 
  156.     strcpy(lf.lfFaceName, IntlGetUIFixFaceName(resource_csid));
  157.     m_cfTextFont = theApp.CreateAppFont( lf );
  158.     ::SendMessage(GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfTextFont, FALSE);
  159.     // TODO: Add your specialized creation code here
  160.     
  161.     return 0;
  162. }
  163.  
  164. void CNSAddressTypeControl::OnLButtonDown(UINT nFlags, CPoint point) 
  165. {
  166.     CListBox::OnLButtonDown(nFlags, point);
  167.     GetParent()->PostMessage(WM_DISPLAYTYPELIST);       
  168. }
  169.  
  170. void DrawTypeBitmap(CRect &rect, CDC * pDC, BOOL bPressed, BOOL bHighlight)
  171. {
  172.     CBitmap cbitmap;
  173.     cbitmap.LoadBitmap(bPressed?IDB_ARROW3D_PRESS:IDB_ARROW3D);
  174.     BITMAP bitmap;
  175.     cbitmap.GetObject(sizeof(BITMAP), &bitmap );
  176.     int center_y = rect.top + (rect.Height() - bitmap.bmHeight)/2;
  177.     DrawTransparentBitmap( 
  178.         pDC->GetSafeHdc(), 
  179.     (HBITMAP)cbitmap.GetSafeHandle(), 
  180.         2, 
  181.         center_y, 
  182.         RGB( 255, 0, 255 ) );
  183.     cbitmap.DeleteObject();
  184. }
  185.  
  186. void CNSAddressTypeControl::DrawHighlight(
  187.     HDC hDC, 
  188.     CRect &rect, 
  189.     HPEN hpenTopLeft, 
  190.     HPEN hpenBottomRight)
  191. {
  192.     HPEN hpenOld = (HPEN) ::SelectObject( hDC, hpenTopLeft );
  193.  
  194.     ::MoveToEx( hDC, rect.left, rect.bottom, NULL );
  195.     ::LineTo( hDC, rect.left, rect.top );
  196.     ::LineTo( hDC, rect.right - 1, rect.top );
  197.  
  198.     ::SelectObject( hDC, hpenBottomRight );
  199.     ::LineTo( hDC, rect.right - 1, rect.bottom - 1);
  200.     ::LineTo( hDC, rect.left, rect.bottom - 1);
  201.  
  202.     ::SelectObject( hDC, hpenOld );
  203. }
  204.  
  205. void CNSAddressTypeControl::DrawRaisedRect(HDC hDC, CRect &rect)
  206. {
  207.     rect.InflateRect(-1,-1);
  208.     DrawHighlight(hDC,rect,(HPEN)pen3dLight.GetSafeHandle(),(HPEN)pen3dShadow.GetSafeHandle());
  209.     rect.InflateRect(1,1);
  210.     DrawHighlight(hDC,rect,(HPEN)pen3dHilight.GetSafeHandle(),(HPEN)pen3dDkShadow.GetSafeHandle());
  211. }
  212.  
  213. void CNSAddressTypeControl::DrawItemSoItLooksLikeAButton(
  214.     CDC * pDC, CRect &rect, CString & cs )
  215. {
  216.     if (rect.Width() > 0 && rect.Height() > 0)
  217.     {
  218.         COLORREF cOldText = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  219.         COLORREF cOldBk = pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
  220.  
  221.         NS_FillSolidRect(pDC->GetSafeHdc(),rect,GetSysColor(COLOR_BTNFACE));
  222.  
  223.         CFont *oldFont = pDC->SelectObject(CFont::FromHandle(m_cfTextFont));
  224.  
  225.         TEXTMETRIC tm;
  226.         pDC->GetTextMetrics(&tm);
  227.         int y = ((rect.bottom - rect.top) - tm.tmHeight)/2;
  228.  
  229.         CBitmap cbitmap;
  230.         cbitmap.LoadBitmap(IDB_ARROW3D);
  231.         BITMAP bitmap;
  232.         cbitmap.GetObject(sizeof(BITMAP), &bitmap );
  233.  
  234.         rect.left += bitmap.bmWidth + TEXT_PAD;
  235.         rect.top += y;
  236.         CString csRight = cs.Right(cs.GetLength()-1);
  237.         pDC->DrawText(csRight,csRight.GetLength(),rect,DT_LEFT);
  238.  
  239.     pDC->SelectObject(oldFont);
  240.  
  241.         rect.top -= y;
  242.         rect.left -= bitmap.bmWidth + TEXT_PAD;
  243.         DrawRaisedRect(pDC->GetSafeHdc(), rect);
  244.  
  245.         DrawTransparentBitmap( 
  246.             pDC->GetSafeHdc(), 
  247.             (HBITMAP)cbitmap.GetSafeHandle(), 
  248.             2, 
  249.             rect.top + y, 
  250.             RGB( 255, 0, 255 ) );
  251.             cbitmap.DeleteObject();
  252.     }
  253. }
  254.  
  255. void CNSAddressTypeControl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
  256. {
  257.     if (lpDrawItemStruct->itemID != -1) 
  258.     {
  259.         CDC dc;
  260.         dc.Attach(lpDrawItemStruct->hDC);
  261.         CRect rect;
  262.         GetClientRect(rect);
  263.         CString cs;
  264.         GetText(lpDrawItemStruct->itemID,cs);
  265.         DrawItemSoItLooksLikeAButton(&dc,rect,cs);
  266.         if (lpDrawItemStruct->itemState & ODS_FOCUS)
  267.         {
  268.             rect.InflateRect(-4,-3);
  269.             dc.DrawFocusRect(rect);
  270.         }
  271.         dc.Detach();
  272.         ValidateRect(rect);
  273.     }
  274. }
  275.  
  276. void CNSAddressTypeControl::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct) 
  277. {
  278.     delete (CNSAddressTypeInfo *)GetItemDataPtr( lpDeleteItemStruct->itemID );
  279.     CListBox::DeleteItem(lpDeleteItemStruct);
  280. }
  281.