home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / nsadrlst.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  9.6 KB  |  271 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. // NSAdrLst.h : header file
  20. //
  21.  
  22. #ifndef __NSADRLST_H__
  23. #define __NSADRLST_H__
  24.  
  25. #include "nsadrtyp.h"
  26. #include "nsadrnam.h"
  27. #include "apiaddr.h"
  28.  
  29. #define NS_ADDRESSFONTSIZE          8
  30.  
  31. class CNSAddressTypeInfo {
  32. protected:
  33.     BOOL m_bHidden;
  34.     BOOL m_bExclusive;
  35.     BOOL m_bExpand;
  36.     UINT m_pidBitmap;
  37.     DWORD m_dwUserData;
  38.     char * m_pszValue;
  39. public:
  40.     CNSAddressTypeInfo(UINT pidBitmap = 0, BOOL bHidden = FALSE, BOOL bExclusive = FALSE, DWORD dwUserData = 0, BOOL bExpand = TRUE)
  41.     {
  42.         m_pidBitmap = pidBitmap;
  43.         m_bExclusive = bExclusive;
  44.         m_bHidden = bHidden;
  45.         m_dwUserData = dwUserData;
  46.         m_pszValue = NULL;
  47.         m_bExpand = bExpand;
  48.     }
  49.     ~CNSAddressTypeInfo()
  50.     {
  51.         if (m_pszValue)
  52.             free(m_pszValue);
  53.     }
  54.     inline void SetValue(const char * pszValue) { 
  55.         if (m_pszValue)
  56.             free(m_pszValue);
  57.         m_pszValue = NULL;
  58.         if (pszValue && strlen(pszValue))
  59.             m_pszValue = strdup(pszValue); 
  60.     }
  61.     inline char * GetValue(void) { return m_pszValue; }
  62.     inline BOOL GetHidden(void) { return m_bHidden; }
  63.     inline BOOL GetExclusive(void) { return m_bExclusive; }
  64.     inline BOOL GetExpand(void) { return m_bExpand; }
  65.     inline void SetHidden(BOOL bVal) { m_bHidden = bVal; }
  66.     inline void SetExclusive(BOOL bVal) { m_bExclusive = bVal; }
  67.     inline void SetExpand(BOOL bVal) { m_bExpand = bVal; }
  68.     inline UINT GetBitmap(void) { return m_pidBitmap; }
  69.     inline DWORD GetUserData(void) { return m_dwUserData; }
  70. };
  71.  
  72. class CNSAddressInfo {
  73. protected:
  74.     char * szType;
  75.     char * szName;
  76.     UINT idBitmap;
  77.     ULONG idEntry;
  78.     BOOL bAllowExpansion;
  79. public:
  80.     CNSAddressInfo() 
  81.     {
  82.         szType = NULL;
  83.         szName = NULL;
  84.         idBitmap = 0;
  85.         idEntry = 0xffffffff;
  86.         bAllowExpansion = FALSE;
  87.     }
  88.     ~CNSAddressInfo()
  89.     {
  90.         if (szType)
  91.             free(szType);
  92.         if (szName)
  93.             free(szName);
  94.     }
  95.     char * GetType(void) { return szType; }
  96.     char * GetName(void) { return szName; }
  97.     UINT GetBitmap(void) { return idBitmap; }
  98.     ULONG GetEntryID(void) { return idEntry; }
  99.     BOOL GetExpansion(void) { return bAllowExpansion; }
  100.     void SetExpansion(BOOL bExpand) { bAllowExpansion = bExpand; }
  101.     void SetName(const char *ptr = NULL) 
  102.     {
  103.         if (szName)
  104.             free(szName);
  105.         if (ptr)
  106.             szName = strdup(ptr);
  107.         else
  108.             szName = NULL;
  109.     }
  110.     void SetType(const char * ptr = NULL)
  111.     {
  112.       char * temp = szType;
  113.         if (ptr)
  114.             szType = strdup(ptr);
  115.         else
  116.             szType = NULL;
  117.         if (temp)
  118.             free(temp);
  119.     }
  120.     void SetBitmap(UINT id = 0) 
  121.     {
  122.         idBitmap = id;
  123.     }
  124.     void SetEntryID(unsigned long id = 0xffffffff) 
  125.     {
  126.         idEntry = id;
  127.     }
  128. };
  129.  
  130. /////////////////////////////////////////////////////////////////////////
  131. // These structures and methods are used to set, add, and retrieve
  132. // address list entries.  The structure AND strings are copied.  The
  133. // index is 0 based.
  134.  
  135. typedef struct
  136. {
  137.     LPCTSTR szType;        // must be in list of address choices
  138.     LPCTSTR szName;
  139.     UINT idBitmap;        // may be null to use bitmap provider API
  140.     unsigned long idEntry;
  141. } NSAddressListEntry;
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CNSAddressList window
  145.  
  146. class CNSAddressList :  public  CListBox,
  147.                         public  CGenericObject,
  148.                         public  IAddressControl
  149. {
  150. protected:
  151.     BOOL                    m_bParse;
  152.     BOOL                    m_bCreated;
  153.     HBRUSH                  m_hBrushNormal;
  154.     HPEN                    m_hPenNormal, m_hPenGrid, m_hPenGrey;
  155.     CNSAddressTypeControl    * m_pAddressTypeList;
  156.     CNSAddressNameEditField    * m_pNameField;
  157.     int                        m_nCurrentSelection;
  158.     int                        m_iFieldControlWidth;
  159.     int                        m_iBitmapWidth;
  160.     int                     m_iTypeBitmapWidth;
  161.     BOOL                    m_bGridLines;
  162.     BOOL                    m_bArrowDown;
  163.     BOOL                    m_bDrawTypeList;
  164.     HFONT                   m_hTextFont;
  165.     int                     m_iDefaultBitmapId;
  166.     int                     m_lastIndex;
  167.     LPADDRESSPARENT         m_pIAddressParent;
  168.     int                     m_iItemHeight;
  169.    
  170. public:
  171.     CNSAddressList();    // Construction
  172.     virtual ~CNSAddressList();
  173.  
  174.     // IUnknown
  175.     STDMETHODIMP QueryInterface(REFIID,LPVOID *);
  176.     STDMETHODIMP_(ULONG) Release(void);
  177.  
  178.     // IAddressControl
  179.    virtual int GetItemFromPoint(LPPOINT point);
  180.    virtual BOOL AddAddressType(char * pszChoice, UINT pidBitmap = 0, BOOL bExpande = TRUE,
  181.         BOOL bHidden = FALSE,BOOL bExclusive = FALSE,DWORD dwUserData = 0);
  182.    virtual void SetDefaultBitmapId(int id = 0) { m_iDefaultBitmapId = id; }
  183.    virtual int GetDefaultBitmapId(void) { return m_iDefaultBitmapId; }
  184.    virtual BOOL RemoveSelection(int nIndex = -1);
  185.     virtual BOOL DeleteEntry( int nIndex );
  186.     virtual int    FindEntry( int nStart, LPCTSTR lpszName );
  187.     virtual BOOL Create(CWnd *pParent, int id = 1000);
  188.     virtual CListBox * GetAddressTypeComboBox( void );
  189.     virtual CEdit * GetAddressNameField( void );
  190.     virtual void SetItemName(int nIndex, char * text);
  191.     virtual void SetItemBitmap(int nIndex, UINT id);
  192.     virtual void SetItemEntryID(int nIndex, unsigned long id);
  193.    virtual void SetControlParent(LPADDRESSPARENT pIAddressParent);
  194.    virtual int GetAddressList (LPNSADDRESSLIST * ppAddressList);
  195.    virtual int SetAddressList (LPNSADDRESSLIST pAddressList, int count);
  196.    virtual CListBox * GetListBox(void) { return (CListBox *)this; }
  197.    virtual BOOL IsCreated(void) { return m_bCreated; }
  198.     virtual int AppendEntry(BOOL expandName, LPCTSTR szType, LPCTSTR szName, UINT idBitmap, unsigned long idEntry );    
  199.     virtual int InsertEntry( int nIndex, BOOL expandName, LPCTSTR szType, LPCTSTR szName, UINT idBitmap, unsigned long idEntry );
  200.     virtual BOOL SetEntry( int nIndex, 
  201.         LPCTSTR szType, LPCTSTR szName, UINT idBitmap, unsigned long idEntry);
  202.     virtual BOOL GetEntry( int nIndex, 
  203.         char **szType, char **szName, UINT *idBitmap, unsigned long *idEntry);
  204.    virtual void GetTypeInfo(int nIndex, ADDRESS_TYPE_FLAG flag, void ** value);
  205.     virtual int SetSel(int nIndex, BOOL bSelect);
  206.     virtual void EnableParsing(BOOL bParse);
  207.     virtual void SetCSID (int16 csid);
  208.  
  209. protected:
  210.  
  211.     int     AppendEntry( NSAddressListEntry *pAddressEntry = NULL, BOOL expandName = TRUE );    // to end of list, NULL for empty entry
  212.     int     InsertEntry( int nIndex, NSAddressListEntry *pAddressEntry, BOOL expandName = TRUE);
  213.     BOOL    SetEntry( int nIndex, NSAddressListEntry *pAddressEntry );
  214.     BOOL    GetEntry( int nIndex, NSAddressListEntry *pAddressEntry );
  215.     void    EnableGridLines( BOOL bEnable );
  216.     void    DrawEntryBitmap(int iSel, CNSAddressInfo * pAddress = NULL, CDC * pDC = NULL, BOOL bErase = TRUE);
  217.     int     GetTypeFieldLength(void);
  218.     BOOL    ParseAddressEntry(int nSelection);
  219.     void    SetEditField(char * text) { m_pNameField->SetWindowText(text); }
  220.     void    HeaderCommand(int nID);
  221.     void    UpdateHeaderType(void);
  222.     void    UpdateHeaderContents(void);
  223.     void    DisplayTypeList(int item = -1);
  224.    inline int  GetActiveSelection() { return GetCurSel(); }
  225.     int     SetActiveSelection(int);
  226.  
  227.     virtual LRESULT DefWindowProc( UINT message, WPARAM wParam, LPARAM lParam );
  228.  
  229. // Overrides
  230.     // ClassWizard generated virtual function overrides
  231.     //{{AFX_VIRTUAL(CNSAddressList)
  232.     public:
  233.     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  234.     virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  235.     virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
  236.     //}}AFX_VIRTUAL
  237.  
  238.  
  239.     int     GetItemRect(HWND hwnd, int nIndex, LPRECT lpRect) const;
  240.     UINT    ItemFromPoint(HWND hwnd, LPPOINT lpPoint, BOOL * bOutside) const;        
  241.     BOOL    DoCommand( HWND hwnd, WPARAM wParam, LPARAM lParam );
  242.  
  243.     BOOL    OnKeyPress( CWnd *pChildControl, UINT nChar, UINT nRepCnt, UINT nFlags );
  244.     void    DrawAddress( int nIndex, CRect &rect, CDC *pDC, BOOL bSelect = FALSE );
  245.     void    DrawGridLine(CRect &rect, CDC *pDC);
  246.     void    ComputeFieldWidths(CDC * pDC);
  247.  
  248.     BOOL    DoEraseBkgnd(HWND hwnd, HDC hdc);
  249.     void    DoSetFocus(HWND);
  250.     void    DoKillFocus(HWND);
  251.     void    DoLButtonUp(HWND hwnd, UINT nFlags, LPPOINT point);
  252.     void    DoLButtonDown(HWND hwmd, UINT nFlags, LPPOINT point);
  253.     void    DoVScroll(HWND hwnd, UINT nSBCode, UINT nPos);
  254.     void    DoChildLostFocus();
  255.     int        DoNotifySelectionChange();
  256.     void    DoDisplayTypeList();
  257.  
  258.     friend class CNSAddressNameEditField;
  259.     friend class CNSAddressTypeControl;
  260.  
  261. };
  262.  
  263. void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor );
  264. void NS_FillSolidRect(HDC hdc, LPCRECT crRect, COLORREF rgbFill);
  265. void NS_Draw3dRect(HDC hdc, LPCRECT crRect, COLORREF rgbTL, COLORREF rgbBR);
  266. void NS_DrawRaisedRect( HDC hDC, LPRECT lpRect );
  267. void NS_DrawLoweredRect( HDC hDC, LPRECT lpRect );
  268. void NS_Draw3DButtonRect( HDC hDC, LPRECT lpRect, BOOL bPushed );
  269.  
  270. #endif __NSADRLST_H__    // end define of CNSAddressList
  271.