home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / compbar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  58.0 KB  |  1,918 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. /* COMPBAR.CPP Contains all the code for the dialog bar portion of the compose
  20.  * window.  This currently comprises the addressing block and attachment 
  21.  * blocks. 
  22.  *
  23.  */
  24.  
  25. #include "stdafx.h"
  26. #include "resource.h"
  27. #include "compstd.h"
  28. #include "compbar.h"
  29. #include "compfrm.h"
  30. #include "compfile.h"
  31. #include "apiaddr.h"
  32.  
  33. #include "msg_srch.h"
  34.  
  35. #define TOTAL_TABS              3
  36. #define TAB_SPACING_X           24
  37. #define TAB_SPACING_Y           20
  38. #define TAB_HORIZONTAL_OFFSET   2
  39. #define TAB_ICON_SIZE           16
  40. #define PIXEL_OFFSET_Y          4
  41. #define PIX_X_FACTOR            20
  42. #define PIX_Y_FACTOR            25
  43. #define COMP_VTAB_WIDTH         9
  44. #define COMP_LEFT_MARGIN        4
  45. #define COMP_HTAB_HEIGHT        10
  46. #define COMP_VTAB_TOP_HEIGHT        7
  47. #define COMP_VTAB_BOTTOM_HEIGHT     3
  48. #define COMP_VTAB_SECTION_HEIGHT    6
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CComposeBar
  52.  
  53. BEGIN_MESSAGE_MAP(CComposeBar, CDialogBar)
  54.     ON_COMMAND(IDC_BUTTON_ATTACH,OnButtonAttach)
  55.     ON_WM_CREATE()
  56.     ON_WM_TIMER()
  57.     ON_WM_SIZE()
  58.     ON_WM_PAINT()
  59.     ON_WM_MOUSEMOVE()
  60.     ON_WM_SETCURSOR()
  61.     ON_WM_LBUTTONDOWN()
  62.     ON_WM_LBUTTONUP()
  63.     ON_WM_ERASEBKGND()
  64.     ON_WM_DROPFILES()
  65.     ON_BN_CLICKED(ID_ENCRYPTED,OnUpdateOptions)
  66.     ON_BN_CLICKED(ID_SIGNED,OnUpdateOptions)
  67.      ON_MESSAGE(WM_LEAVINGLASTFIELD,OnLeavingLastField)
  68.  
  69. END_MESSAGE_MAP()
  70.  
  71. extern "C" char * wfe_ExpandForNameCompletion(char * pString);
  72. extern "C" char * wfe_ExpandName(char * pString);
  73.  
  74. CComposeBar::CComposeBar () :
  75.     CDialogBar ()
  76. {
  77.     m_iBoxHeight = 0;
  78.     m_pAttachmentList = NULL;       // widget for attachment list
  79.     m_bSizing =         FALSE;      // for resizing dialog bar (needs work)
  80.     // start off with the address block displayed
  81.     m_iSelectedTab =    IDX_COMPOSEADDRESS;
  82.     m_pSubjectEdit =    NULL;       // text for subject field
  83.     m_pPriority    =    NULL;       // message priority
  84.     m_bClosed =         FALSE;      // dialog bar is collapsed or expanded
  85.     m_bHidden =         FALSE;      // dialog bar is "hidden" (collapsed with no widget) or showing full size
  86.     m_pComposeEdit =    NULL;       // pointer to the composition editor
  87.     m_pWidget =         NULL;
  88.     m_iPriorityIdx =    2;            // 0 based index; 0-lowest 1-low 2-normal 3-high 4-highest
  89.     m_bCanSize =        FALSE;
  90.     m_iTotalAttachments = 0;
  91.     m_iHeight            = 0;
  92.     m_iPrevHeight       = 0;
  93.     m_iMinSize          = 0;
  94.     m_iMaxSize          = 0;
  95.     m_pReturnReceipt =  NULL;
  96.     m_pEncrypted =      NULL;
  97.     m_pSigned =         NULL;
  98.     m_bReceipt =        FALSE;
  99.     m_bSigned =         FALSE;
  100.     m_bEncrypted =      FALSE;
  101.     m_pDropTarget =     NULL;
  102.     m_pMessageFormat =  NULL;
  103.     m_pMessageFormatText = NULL;
  104.     m_pszMessageFormat = NULL;
  105. //    m_bUse8Bit =        FALSE;
  106.     m_bUseUUENCODE =    FALSE;
  107. //    m_pUse8Bit =        NULL;
  108.     m_pUseUUENCODE =    NULL;
  109.     m_pUnkImage = NULL;
  110.     m_pUnkAddressControl = NULL;
  111.     ApiApiPtr(api);
  112.     m_pUnkImage = api->CreateClassInstance(
  113.         APICLASS_IMAGEMAP,NULL,(APISIGNATURE)IDB_COMPOSETABS);
  114.     m_pUnkImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIImage);
  115.     ASSERT(m_pIImage);
  116.     if (!m_pIImage->GetResourceID())
  117.         m_pIImage->Initialize(IDB_COMPOSETABS,16,16);
  118. }
  119.  
  120. CComposeBar::~CComposeBar ( )
  121. {
  122.     // free up any allocated resources and release any used apis
  123.    if (m_pszMessageFormat)
  124.       free(m_pszMessageFormat);
  125.    if (m_pUnkImage) {
  126.       if (m_pIImage)
  127.          m_pUnkImage->Release();
  128.    }
  129.    if (m_pUnkAddressControl)
  130.       m_pUnkAddressControl->Release();
  131.    delete m_pToolTip;
  132.    if (m_pDropTarget)
  133.    {
  134.       m_pDropTarget->Revoke();
  135.       delete m_pDropTarget;
  136.    }
  137. }
  138.  
  139. /////////////////////////////////////////////////////////////////////////////
  140. // GetAddressWidget() returns a pointer to the NSAddressList object.
  141.  
  142. LPADDRESSCONTROL CComposeBar::GetAddressWidgetInterface()
  143. {
  144.     ASSERT(m_pIAddressList);
  145.     return(m_pIAddressList);
  146. }
  147.  
  148. /////////////////////////////////////////////////////////////////////////////
  149. // TabControl() controls the tabbing order between the controls in
  150. // the composition window.  The controls are parented at different
  151. // levels which make focus issues a little confusing. This function
  152. // returns TRUE if it knew where to put focus, if it couldn't figure 
  153. // out where it should go, FALSE is returned.
  154.  
  155. BOOL CComposeBar::TabControl(BOOL bShift, BOOL bControl, CWnd * pWnd)
  156. {
  157.     // get a pointer to the parent frame (FIXME JRE).  The child
  158.     // really shouldn't need to know anything about the parent.
  159.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  160.     CListBox * pListBox = NULL;
  161.  
  162.     switch (m_iSelectedTab)
  163.     {
  164.         case IDX_COMPOSEADDRESS:
  165.             pListBox = m_pIAddressList->GetListBox();
  166.             break;
  167.         case IDX_COMPOSEATTACH:
  168.             pListBox = (CListBox*)m_pAttachmentList;
  169.             break;
  170.     }
  171.     if (pWnd == (CWnd*)TABCTRL_HOME)    // this value position to address list
  172.     {
  173.         pListBox->SetFocus();
  174.         pCompose->SetFocusField(pListBox);
  175.         return TRUE;
  176.     }
  177.     else if (bControl)
  178.     {
  179.       TabChanging(m_iSelectedTab);
  180.       switch (m_iSelectedTab)
  181.       {
  182.          case IDX_COMPOSEADDRESS:
  183.             TabChanged(bShift ? IDX_COMPOSEOPTIONS : IDX_COMPOSEATTACH);
  184.             break;
  185.          case IDX_COMPOSEATTACH:
  186.             TabChanged(bShift ? IDX_COMPOSEADDRESS: IDX_COMPOSEOPTIONS);
  187.             break;
  188.          case IDX_COMPOSEOPTIONS:
  189.             TabChanged(bShift ? IDX_COMPOSEATTACH : IDX_COMPOSEADDRESS);
  190.             break;
  191.       }
  192.       
  193.       return TRUE;
  194.     }
  195.     else if (pWnd == pCompose->GetEditorWnd()) 
  196.     {
  197.         // if the editor has focus and the shift-tab was hit, position to the
  198.         // subject field
  199.         if (bShift)
  200.         {
  201.             m_pSubjectEdit->SetFocus();
  202.             pCompose->SetFocusField(m_pSubjectEdit);
  203.             return TRUE;
  204.         }
  205.     }
  206.     else if (pWnd == m_pSubjectEdit)
  207.     {
  208.         // if the subject field has focus, give focus to the address list
  209.         // if shift-tab was pressed.
  210.         if (bShift)
  211.         {
  212.             switch (m_iSelectedTab)
  213.             {
  214.                 case IDX_COMPOSEATTACH:
  215.                 case IDX_COMPOSEADDRESS:
  216.                     pListBox->SetFocus();
  217.                     pCompose->SetFocusField(pListBox);
  218.                     break;
  219.                 case IDX_COMPOSEOPTIONS:
  220.                     if (pCompose->UseHtml())
  221.                     {
  222.                         m_pMessageFormat->SetFocus();
  223.                         pCompose->SetFocusField(m_pMessageFormat);
  224.                     }
  225.                     else
  226.                     {
  227.                         m_pPriority->SetFocus();
  228.                         pCompose->SetFocusField(m_pPriority);
  229.                     }
  230.                     break;
  231.             }
  232.             return TRUE;
  233.         }
  234.         else if (pCompose && pCompose->GetEditorWnd())
  235.         {
  236.             pCompose->GetEditorWnd()->SetFocus();
  237.             pCompose->SetFocusField(pCompose->GetEditorWnd());
  238.         }
  239.         return TRUE;
  240.     } 
  241.  
  242.     return FALSE;   // couldn't figure out who to give focus to
  243. }
  244.  
  245. BOOL CComposeBar::OnEraseBkgnd(CDC* pDC)
  246. {
  247.     CRect WinRect, rect;
  248.     GetClientRect(WinRect);
  249.     GetWidgetRect(WinRect,rect);
  250.     rect.InflateRect(-2,-2);
  251.     CBrush brush(GetSysColor(COLOR_BTNFACE)), *pOldBrush;
  252.     CPen pen(PS_SOLID,1,GetSysColor(COLOR_BTNFACE)), *pOldPen;
  253.     pOldBrush = pDC->SelectObject(&brush);
  254.     pOldPen = pDC->SelectObject(&pen);
  255.  
  256.     if ((m_iSelectedTab != IDX_COMPOSEOPTIONS) && !m_bClosed)
  257.     {
  258.         CRect fillrect;
  259.         fillrect = WinRect;
  260.         fillrect.right = rect.left + 2;
  261.         pDC->Rectangle(fillrect);
  262.         fillrect = WinRect;
  263.         fillrect.left = rect.right;
  264.         pDC->Rectangle(fillrect);
  265.         fillrect = WinRect;
  266.         fillrect.bottom = rect.top;
  267.         pDC->Rectangle(fillrect);
  268.         fillrect = WinRect;
  269.         fillrect.top = rect.bottom;
  270.         pDC->Rectangle(fillrect);
  271.     }
  272.     else
  273.         pDC->Rectangle(WinRect);
  274.  
  275.  
  276.     pDC->SelectObject(pOldBrush);
  277.     pDC->SelectObject(pOldPen);
  278.     return TRUE;
  279. }
  280. /////////////////////////////////////////////////////////////////////////////
  281. // OnLeavingLastField() is a responded to the WM_LEAVINGLASTFIELD message
  282. // which is generated by the address list widget.  When the focus is on
  283. // the last valid entry in the address list and tab is pressed, this
  284. // message is sent.
  285.  
  286. LONG CComposeBar::OnLeavingLastField(UINT, LONG)
  287. {
  288.     // when leaving the last field of the address widget, give focus to
  289.     // the subject field
  290.     if (m_pSubjectEdit)
  291.     {
  292.         CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  293.         m_pSubjectEdit->SetFocus();
  294.         pCompose->SetFocusField(m_pSubjectEdit);
  295.     }
  296.     return 0;
  297. }
  298.  
  299. void CComposeBar::OnLButtonUp( UINT nFlags, CPoint point )
  300. {
  301.     ReleaseCapture();
  302.     m_bSizing = FALSE;
  303.     CDialogBar::OnLButtonUp(nFlags,point);
  304. }
  305.  
  306. void CComposeBar::OnLButtonDown( UINT nFlags, CPoint point )
  307. {
  308.     if (m_bCanSize && !m_bClosed)
  309.     {
  310.         SetCapture();
  311.         m_iY = point.y;
  312.         m_bSizing = TRUE;
  313.     }
  314.     else if (!m_bClosed && !collapser.ButtonPress(point))
  315.     {
  316.        for (int i = 0; i < MAX_TIPS; i++)
  317.        {
  318.            if (m_ToolTipInfo[i].m_rect.PtInRect(point))
  319.            {
  320.                if (i != m_iSelectedTab)
  321.                {
  322.                    SendMessage(WM_COMMAND,(WPARAM)m_ToolTipInfo[i].m_idCommand);
  323.                    Invalidate();
  324.                    break;
  325.                }
  326.            }
  327.        }
  328.     }
  329.     CDialogBar::OnLButtonDown(nFlags,point);
  330. }
  331.  
  332. BOOL CComposeBar::OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message )
  333. {
  334.     if (!m_bClosed)
  335.     {
  336.         CRect WinRect;
  337.         POINT point;
  338.         GetCursorPos(&point);
  339.         ScreenToClient(&point);
  340.         GetClientRect(WinRect);
  341.         CRect rect;
  342.         if (m_pWidget)
  343.         {
  344.             m_pWidget->GetWindowRect(rect);
  345.             ScreenToClient(rect);
  346.             WinRect.top = rect.bottom;
  347.             WinRect.bottom = WinRect.top + GetSystemMetrics(SM_CYFRAME)*2;
  348.             if ( nHitTest == HTCLIENT && PtInRect( &WinRect, point ))
  349.             {
  350.                 SetCursor( theApp.LoadCursor ( AFX_IDC_VSPLITBAR ) );
  351.                 m_bCanSize = TRUE;
  352.                 return TRUE;
  353.             }
  354.         }
  355.         m_bCanSize = FALSE;
  356.     }
  357.     return CDialogBar::OnSetCursor( pWnd, nHitTest, message );
  358. }
  359.  
  360. void CComposeBar::OnMouseMove( UINT nFlags, CPoint point )
  361. {
  362.     if (m_bSizing) 
  363.     {
  364.         if (m_iY != point.y)
  365.         {
  366.             m_iHeight += (point.y - m_iY);
  367.             m_iHeight = max(m_iHeight,m_iMinSize);
  368.             m_iHeight = min(m_iHeight,m_iMaxSize);
  369.             m_iY = point.y;
  370.             GetParentFrame()->RecalcLayout();
  371.             CalcFieldLayout();
  372.             Invalidate();
  373.             UpdateWindow();
  374.         }
  375.     }
  376.     CDialogBar::OnMouseMove(nFlags,point);
  377.     if (!m_bClosed)
  378.         collapser.MouseAround(point);
  379. }
  380.  
  381. static SIZE sizeSelTab = { 2, 2 };
  382.  
  383. BOOL CComposeBar::IsAttachmentsMailOnly(void)
  384. {
  385.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  386.    if (pCompose->GetMsgPane())
  387.    {
  388.       const MSG_AttachmentData * pDataList = MSG_GetAttachmentList(pCompose->GetMsgPane());
  389.       if(pDataList) 
  390.       {
  391.           for (int i = 0; pDataList[i].url!=NULL; i++) 
  392.              if (strncmp(pDataList[i].url,"mailbox:",8))
  393.                   return FALSE;
  394.       }
  395.       return TRUE;
  396.    }
  397.    return FALSE;
  398. }
  399.  
  400.  
  401. void CComposeBar::DrawVerticalTab(CDC & dc, int index, CRect &rect)
  402. {
  403.     int x = m_cxChar + COMP_VTAB_WIDTH + COMP_LEFT_MARGIN;
  404.     int y = PIXEL_OFFSET_Y + 5;
  405.     BOOL bSelected = m_iSelectedTab == index;
  406.  
  407.     rect.SetRect(
  408.         x,
  409.         y+(index*TAB_SPACING_Y),
  410.         0,0);
  411.     rect.right = rect.left + TAB_SPACING_X - 1;
  412.     rect.bottom = rect.top + TAB_SPACING_Y;
  413.  
  414.     HPEN hPenHilite, hPenShadow, hPenDark;
  415.     hPenHilite = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNHIGHLIGHT ) );
  416.     hPenShadow = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNSHADOW ) );
  417. #ifdef XP_WIN32
  418.     hPenDark = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_3DDKSHADOW ) );    
  419.     HPEN hPenLite = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_3DLIGHT ) );
  420. #else
  421.     hPenDark = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNTEXT ) );       
  422.     HPEN hPenLite = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNHIGHLIGHT ) );
  423. #endif
  424.  
  425.     if (bSelected)
  426.     {
  427.         InflateRect(&rect, sizeSelTab.cx, sizeSelTab.cy);
  428.         rect.right++;
  429.         rect.bottom -= 2;
  430.     }
  431.  
  432.     HBRUSH hBrush = (HBRUSH)(COLOR_BTNFACE + 1);
  433.     ::FillRect(dc.GetSafeHdc(), &rect, hBrush);
  434.  
  435.     rect.right -= 2;
  436.     rect.bottom += 2;
  437.  
  438.     HPEN hOldPen = (HPEN)dc.SelectObject(hPenDark);
  439.     dc.MoveTo(rect.right - (bSelected ? 2 : 0),rect.bottom-1);
  440.     dc.LineTo(rect.left+2,rect.bottom-1);
  441.     dc.LineTo(rect.left,rect.bottom-3);
  442.     dc.SelectObject(hPenHilite);
  443.     dc.LineTo(rect.left,rect.top+2);
  444.     dc.LineTo(rect.left+2,rect.top);
  445.     dc.LineTo(rect.right + ((bSelected&&!index) ? 2 : 0 ),rect.top);
  446.  
  447.     dc.SelectObject(hPenShadow);
  448.     dc.MoveTo(rect.right - (bSelected ? 1 : 0),rect.bottom-2);
  449.     dc.LineTo(rect.left+2,rect.bottom-2);
  450.     dc.LineTo(rect.left+1,rect.bottom-3);
  451.     dc.SelectObject(hPenLite);
  452.     dc.LineTo(rect.left+1,rect.top+2);
  453.     dc.LineTo(rect.left+2,rect.top+1);
  454.     if (!bSelected && index)
  455.         dc.LineTo(rect.right + ((bSelected&&!index) ? 2 : 0),rect.top+1);
  456.  
  457.     //update the attachment count here since the attachments may have come
  458.     //from the command line and need a way of notifying the control.
  459.     if (GetTotalAttachments() && !m_iTotalAttachments)
  460.         m_iTotalAttachments = GetTotalAttachments();
  461.  
  462.     int idxImage = index;
  463.     if (index == IDX_COMPOSEATTACH)
  464.     {
  465.         if (m_iTotalAttachments > 0)
  466.         {
  467.             if (IsAttachmentsMailOnly())
  468.                 idxImage = IDX_COMPOSEATTACHMAIL;
  469.             else
  470.                 idxImage = IDX_COMPOSEATTACHFILE;
  471.         }
  472.     }
  473.     m_pIImage->DrawImage(
  474.         idxImage,
  475.         rect.left + (TAB_SPACING_X-TAB_ICON_SIZE)/2,
  476.         rect.top + (TAB_SPACING_Y-TAB_ICON_SIZE)/2,
  477.         dc.GetSafeHdc(), TRUE);
  478.  
  479.     if (hOldPen != NULL)
  480.         dc.SelectObject(hOldPen);
  481.  
  482.     ::DeleteObject((HGDIOBJ) hPenHilite);
  483.     ::DeleteObject((HGDIOBJ) hPenShadow);
  484.     ::DeleteObject((HGDIOBJ) hPenDark);
  485.     ::DeleteObject((HGDIOBJ) hPenLite);
  486. }
  487.  
  488. void CComposeBar::GetWidgetRect(CRect &WinRect, CRect &rect)
  489. {
  490.      int y = PIXEL_OFFSET_Y;
  491.     int x = TAB_SPACING_X + 6 + COMP_VTAB_WIDTH + COMP_LEFT_MARGIN;
  492.     int iHeight = (WinRect.Height() - (m_iBoxHeight * 3)/2) - 5;
  493.     rect.SetRect(
  494.         x, y, 
  495.         WinRect.Width()-4, 
  496.         iHeight);
  497. }
  498.  
  499. void CComposeBar::Draw3DStaticEdgeSimulation(CDC & dc, CRect &rect, BOOL bReverse)
  500. {
  501.     CPen ShadowPen (PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
  502.     CPen HilitePen (PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
  503.     CPen * pOldPen = dc.SelectObject(bReverse ? &HilitePen : &ShadowPen);
  504.  
  505.     dc.MoveTo(rect.left,rect.bottom-1);
  506.     dc.LineTo(rect.left,rect.top);
  507.     dc.LineTo(rect.right-1,rect.top);
  508.     dc.SelectObject(bReverse ? &ShadowPen : &HilitePen);
  509.     dc.LineTo(rect.right-1,rect.bottom-1);
  510.     dc.LineTo(rect.left-1,rect.bottom-1);
  511.  
  512.     dc.SelectObject(pOldPen);
  513. }
  514.  
  515. void CComposeBar::OnPaint()
  516. {
  517.    CPaintDC dc(this);
  518.  
  519.    // draw shadow around address widget and line at top
  520.    // of compose bar
  521.    CRect WinRect, rect;
  522.    GetClientRect(&WinRect);
  523.  
  524.    GetWidgetRect(WinRect,rect);
  525.    if (!m_bClosed)
  526.    {
  527.       rect.left = COMP_VTAB_WIDTH + 2;
  528.       rect.InflateRect(2,2);
  529.       Draw3DStaticEdgeSimulation(dc, rect, TRUE);
  530.    }
  531.  
  532.    if (m_pSubjectEdit && m_pSubjectEdit->IsWindowVisible())
  533.    {
  534.       m_pSubjectEdit->GetWindowRect(rect);
  535.       ScreenToClient(rect);
  536.       rect.InflateRect(1,1);
  537.       Draw3DStaticEdgeSimulation(dc, rect);
  538.    }
  539.  
  540.    if (!m_bClosed)
  541.    {
  542.        GetWidgetRect(WinRect,rect);
  543.        rect.InflateRect(-1,-1);
  544.        rect.left = COMP_VTAB_WIDTH + 3;
  545.        Draw3DStaticEdgeSimulation(dc, rect);
  546.    }
  547.  
  548.    if (!m_bClosed)
  549.    {
  550.       HPEN hPenHilite = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNHIGHLIGHT ) );
  551.       HPEN hPenShadow = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_BTNSHADOW ) );
  552.       HPEN hOldPen = (HPEN)dc.SelectObject(hPenShadow);
  553.        GetWidgetRect(WinRect,rect);
  554.       rect.InflateRect(2,0);
  555.       rect.top++ ;
  556.       rect.bottom -= 2;
  557.       dc.MoveTo(rect.left,rect.top);
  558.       dc.LineTo(rect.left,rect.bottom);
  559.       dc.SelectObject(hPenHilite);
  560.       dc.MoveTo(rect.left + 2,rect.top);
  561.       dc.LineTo(rect.left + 2,rect.bottom);
  562.       CPoint point1(rect.left+1,rect.top);
  563.       CPoint point2(rect.left+1,rect.bottom);
  564.       dc.SetPixel(point1, GetSysColor(COLOR_BTNFACE));
  565.       dc.SetPixel(point2, GetSysColor(COLOR_BTNFACE));
  566.       if (hOldPen != NULL)
  567.            dc.SelectObject(hOldPen);
  568.       ::DeleteObject((HGDIOBJ) hPenHilite);
  569.       ::DeleteObject((HGDIOBJ) hPenShadow);
  570.  
  571.       // paint the tabs here
  572.       for (int i =0; i< TOTAL_TABS; i++)
  573.       {
  574.          if (i != m_iSelectedTab)
  575.          {
  576.             DrawVerticalTab(dc,i, rect);
  577.             rect.InflateRect(0,-3);
  578.             m_ToolTipInfo[i].m_rect = rect;
  579.  
  580.          }
  581.       }
  582.       DrawVerticalTab(dc,m_iSelectedTab,rect);
  583.       rect.InflateRect(0,-3);
  584.       m_ToolTipInfo[m_iSelectedTab].m_rect = rect;
  585.    }
  586.    else
  587.    {
  588.       for (int i =0; i< TOTAL_TABS; i++)
  589.       {
  590.          m_ToolTipInfo[i].m_rect.SetRect(0,0,0,0);
  591.       }
  592.    }
  593.  
  594.    int iHeight = (WinRect.Height() - (m_iBoxHeight * 3)/2) - 3;
  595.  
  596.    if (!m_bClosed){
  597.       collapser.DrawCollapseWidget(dc, collapse_open, FALSE, WinRect.Height() - iHeight);
  598.       collapser.GetRect(m_ToolTipInfo[IDX_TOOL_COLLAPSE].m_rect);
  599.    }
  600. }
  601.  
  602. void CComposeBar::ShowTab(int idx)
  603. {
  604. }
  605.  
  606. int CComposeBar::GetTab()
  607. {
  608.     return m_iSelectedTab;
  609. }
  610.  
  611. void CComposeBar::Cleanup(void)
  612. {
  613.     TabChanging(m_iSelectedTab);
  614.     if (m_pAttachmentList && ::IsWindow(m_pAttachmentList->m_hWnd))
  615.     {
  616.         m_pAttachmentList->DestroyWindow();
  617.         delete m_pAttachmentList;
  618.     }
  619.     DestroyStandardFields();
  620. }
  621.  
  622. void CComposeBar::TabChanging(int tab)
  623. {
  624.     switch (tab)
  625.     {
  626.         case IDX_COMPOSEADDRESS:
  627.             DestroyAddressPage();
  628.             break;
  629.         case IDX_COMPOSEATTACH:
  630.             DestroyAttachmentsPage();
  631.             break;
  632.         case IDX_COMPOSEOPTIONS:
  633.             DestroyOptionsPage();
  634.             break;
  635.         default:
  636.             ASSERT(0);
  637.    }
  638.  
  639. }
  640.  
  641. void CComposeBar::TabChanged(int tab)
  642. {
  643.     m_pIAddressList->EnableParsing(tab == IDX_COMPOSEADDRESS);
  644.    m_iSelectedTab = tab;
  645.    switch (m_iSelectedTab) 
  646.    {
  647.        case IDX_COMPOSEADDRESS:
  648.            CreateAddressPage();
  649.            m_pWidget->SetFocus();
  650.            break;
  651.        case IDX_COMPOSEATTACH:
  652.            CreateAttachmentsPage();
  653.            m_pWidget->SetFocus();
  654.            break;
  655.        case IDX_COMPOSEOPTIONS:
  656.            CreateOptionsPage();
  657.            m_pReturnReceipt->SetFocus();
  658.            m_pWidget = NULL;
  659.            break;
  660.        default:
  661.            ASSERT(0);
  662.    }
  663.  
  664.    GetParentFrame()->RecalcLayout();
  665.    
  666.    if (!m_pSubjectEdit)
  667.       CreateStandardFields();
  668.       
  669.    Invalidate();
  670. }
  671.  
  672. void CComposeBar::OnAddressTab(void)
  673. {
  674.     if (m_iSelectedTab != IDX_COMPOSEADDRESS)
  675.     {
  676.         TabChanging(m_iSelectedTab);
  677.         TabChanged(IDX_COMPOSEADDRESS);
  678.     }
  679. }
  680.  
  681. void CComposeBar::OnAttachTab(void)
  682. {
  683.     if (m_iSelectedTab != IDX_COMPOSEATTACH)
  684.     {
  685.         TabChanging(m_iSelectedTab);
  686.         TabChanged(IDX_COMPOSEATTACH);
  687.     }
  688. }
  689.  
  690. void CComposeBar::OnOptionsTab(void)
  691. {
  692.     if (m_iSelectedTab != IDX_COMPOSEOPTIONS)
  693.     {
  694.         TabChanging(m_iSelectedTab);
  695.         TabChanged(IDX_COMPOSEOPTIONS);
  696.     }
  697. }
  698.  
  699. void CComposeBar::OnToggleShow(void)
  700. {
  701.     if (m_bHidden)
  702.     {
  703.         m_bHidden = FALSE;
  704.         // Always uncollapse when showing
  705.         if (m_bClosed)
  706.         {
  707.             OnCollapse();
  708.         } 
  709.         else if (m_pWidget && ::IsWindow(m_pWidget->m_hWnd))
  710.         {
  711.             m_pWidget->ShowWindow(SW_NORMAL);
  712.         }
  713.     } else {
  714.         m_bHidden = TRUE;
  715.  
  716.         // Always collapse when hidding
  717.         if (!m_bClosed) {
  718.             OnCollapse();
  719.         } 
  720.         else if (m_pWidget && ::IsWindow(m_pWidget->m_hWnd))
  721.         {
  722.             m_pWidget->ShowWindow(SW_HIDE);
  723.             Invalidate();
  724.         }
  725.         // The only difference between Hiding and collapsing is the 
  726.         //  removal of the collapsed tab
  727.         CGenericFrame * pFrame = (CGenericFrame*)GetParent();
  728.         CCustToolbar * pToolbar = pFrame->GetChrome()->GetCustomizableToolbar();
  729.         if( pToolbar ){
  730.             pToolbar->RemoveExternalTab(1);
  731.         }
  732.            GetParentFrame()->RecalcLayout();
  733.     }
  734. }
  735.  
  736. void CComposeBar::OnCollapse(void)
  737. {
  738.     if (!m_bClosed)
  739.     {
  740.         m_iPrevHeight = m_iHeight;
  741.         m_bClosed = TRUE;
  742.         if (m_pWidget && ::IsWindow(m_pWidget->m_hWnd))
  743.             m_pWidget->ShowWindow(SW_HIDE);
  744.         m_iHeight = m_iBoxHeight + /*COMP_HTAB_HEIGHT +*/ 13;
  745.         if (m_iSelectedTab == IDX_COMPOSEOPTIONS)
  746.             DestroyOptionsPage();
  747.  
  748.         CGenericFrame * pFrame = (CGenericFrame*)GetParent();
  749.         CCustToolbar * pToolbar = pFrame->GetChrome()->GetCustomizableToolbar();
  750.         if( pToolbar ){
  751.             pToolbar->AddExternalTab(pFrame, eLARGE_HTAB, IDS_COMPOSECLOSE,  1);
  752.         }
  753.         GetParentFrame()->RecalcLayout();
  754.         Invalidate();
  755.     }
  756.     else 
  757.     {
  758.         m_bClosed = FALSE;
  759.         m_iHeight = m_iPrevHeight;
  760.         GetParentFrame()->RecalcLayout();
  761.         if (m_iSelectedTab == IDX_COMPOSEADDRESS || m_iSelectedTab == IDX_COMPOSEATTACH)
  762.             m_pWidget->ShowWindow(SW_NORMAL);
  763.         if (m_iSelectedTab == IDX_COMPOSEOPTIONS)
  764.             CreateOptionsPage();
  765.         Invalidate();
  766.     }
  767. }
  768.  
  769. #define BORDER_WIDTH 5
  770.  
  771. int CComposeBar::GetTotalAttachments(void)
  772. {
  773.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  774.     if (pCompose->GetMsgPane())
  775.     {
  776.         const MSG_AttachmentData * pDataList = MSG_GetAttachmentList(pCompose->GetMsgPane());
  777.         if(pDataList) 
  778.         {
  779.         for (int i = 0; pDataList[i].url!=NULL; i++) 
  780.             ;
  781.         return i;
  782.         }
  783.     }
  784.     return 0;
  785. }
  786.  
  787. void CComposeBar::OnSize( UINT nType, int cx, int cy )
  788. {
  789.     CDialogBar::OnSize( nType, cx, cy );
  790.     if (m_pSubjectEdit)
  791.     CalcFieldLayout();
  792. }
  793.  
  794. void CComposeBar::OnButtonAttach(void)
  795. {
  796.     CWnd * pWnd = GetFocus();
  797.     GetParent()->SendMessage(WM_COMMAND,ID_FILE_ATTACH);
  798.     if (pWnd)
  799.        pWnd->SetFocus();
  800. }
  801.  
  802. void CComposeBar::OnTimer( UINT  nIDEvent )
  803. {
  804.    if( !m_bClosed )
  805.        collapser.TimerEvent(nIDEvent);
  806.    else 
  807.       KillTimer(nIDEvent);
  808.  
  809.    CDialogBar::OnTimer(nIDEvent);
  810. }
  811.  
  812. int CComposeBar::OnCreate( LPCREATESTRUCT lpCreateStruct )
  813. {
  814.     int retval = CDialogBar::OnCreate ( lpCreateStruct );
  815.  
  816.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  817.     collapser.Initialize(this,IDC_COLLAPSE);
  818.  
  819.     m_pszMessageFormat = strdup(szLoadString(pCompose->UseHtml() ? IDS_FORMAT_ASKME : IDS_FORMAT_PLAIN));
  820.  
  821.     ApiApiPtr(api);
  822.     m_pUnkAddressControl = api->CreateClassInstance(
  823.         APICLASS_ADDRESSCONTROL, NULL, (APISIGNATURE)pCompose);
  824.     m_pUnkAddressControl->QueryInterface(IID_IAddressControl,(LPVOID*)&m_pIAddressList);
  825.     m_pIAddressList->SetControlParent(this);
  826.  
  827.     // Static text is translated to many languages
  828.     // That's why we choose font name based on resource definition.
  829.     CClientDC dc(this);
  830.  
  831.     LOGFONT lf;
  832.     memset(&lf,0,sizeof(LOGFONT));
  833.     lf.lfCharSet = DEFAULT_CHARSET;
  834.     lf.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
  835.     strcpy(lf.lfFaceName, szLoadString(IDS_FONT_PROPNAME));
  836.     lf.lfHeight = -MulDiv(8, dc.GetDeviceCaps(LOGPIXELSY), 72);
  837.     lf.lfQuality = PROOF_QUALITY;    
  838.     m_cfStaticFont = theApp.CreateAppFont( lf );
  839.  
  840.     SetCSID(INTL_DefaultWinCharSetID(0)); 
  841.  
  842.     m_ToolTipInfo[IDX_TOOL_ADDRESS].Initialize(IDS_ADDRESSMESSAGE,CRect(0,0,0,0),IDC_ADDRESSTAB);
  843.     m_ToolTipInfo[IDX_TOOL_ATTACH].Initialize(IDS_ATTACHFILE,CRect(0,0,0,0),IDC_ATTACHTAB);
  844.     m_ToolTipInfo[IDX_TOOL_OPTIONS].Initialize(IDS_COMPOSEOPTIONS,CRect(0,0,0,0),IDC_OPTIONSTAB);
  845.     m_ToolTipInfo[IDX_TOOL_COLLAPSE].Initialize(IDS_COMPOSEOPEN,CRect(0,0,0,0),IDC_COLLAPSE);
  846.     
  847.     m_pToolTip = new CNSToolTip2;
  848.     m_pToolTip->Create(this, TTS_ALWAYSTIP);
  849.     m_pToolTip->SetDelayTime(250);
  850.     m_pToolTip->Activate(TRUE);
  851.  
  852.     EnableToolTips(TRUE);
  853.  
  854.    UpdateFixedSize();
  855.    if(!m_pDropTarget) {
  856.        m_pDropTarget = new CNSAttachDropTarget;
  857.        m_pDropTarget->Register(this);
  858.    }
  859.    DragAcceptFiles();
  860.    return retval;
  861. }
  862.     
  863. void CComposeBar::SetCSID(int iCSID)
  864. {
  865.    CClientDC pdc ( this );
  866.    LOGFONT lf;
  867.  
  868.    if (m_cfTextFont) {
  869.       theApp.ReleaseAppFont(m_cfTextFont);
  870.    }
  871.    if (m_cfSubjectFont) {
  872.       theApp.ReleaseAppFont(m_cfSubjectFont);
  873.    }
  874.    memset(&lf,0,sizeof(LOGFONT));
  875.    if (iCSID == CS_LATIN1)
  876.       strcpy(lf.lfFaceName, "MS Sans Serif");
  877.    else
  878.       strcpy(lf.lfFaceName, IntlGetUIPropFaceName(iCSID));
  879.    lf.lfCharSet = IntlGetLfCharset(iCSID);
  880.    lf.lfHeight = -MulDiv(8,pdc.GetDeviceCaps(LOGPIXELSY), 72);
  881.    lf.lfQuality = PROOF_QUALITY;    
  882.  
  883.    lf.lfPitchAndFamily = FF_SWISS;
  884.     m_cfTextFont = theApp.CreateAppFont( lf );
  885.  
  886.    XP_MEMSET(&lf,0,sizeof(LOGFONT));
  887.    lf.lfPitchAndFamily = FF_MODERN | FIXED_PITCH;
  888.    strcpy(lf.lfFaceName, IntlGetUIFixFaceName(iCSID));
  889.    lf.lfCharSet = IntlGetLfCharset(iCSID); 
  890.    lf.lfHeight = -MulDiv(9,pdc.GetDeviceCaps(LOGPIXELSY), 72);
  891.    lf.lfQuality = PROOF_QUALITY;    
  892.     m_cfSubjectFont = theApp.CreateAppFont( lf );
  893.  
  894.     CClientDC dc(this);
  895.     CFont * pOldFont = dc.SelectObject(CFont::FromHandle(m_cfSubjectFont));
  896.    TEXTMETRIC tm;
  897.    dc.GetTextMetrics(&tm);
  898.    m_iBoxHeight = tm.tmHeight + tm.tmExternalLeading;
  899.    m_cxChar = tm.tmAveCharWidth;
  900.    CString cs;
  901.    cs.LoadString(IDS_COMPOSE_SUBJECT);
  902.    m_iFirstX = dc.GetTextExtent(cs,cs.GetLength()).cx + (m_cxChar * 2);
  903.    dc.SelectObject(pOldFont);
  904.    
  905.     if (m_pSubjectEdit) {
  906.         ::SendMessage(m_pSubjectEdit->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfSubjectFont, FALSE);
  907.         CalcFieldLayout();
  908.     }
  909.     if (m_pIAddressList) {
  910.         m_pIAddressList->SetCSID(iCSID);
  911.         CListBox * pListBox = m_pIAddressList->GetListBox();
  912.         if (pListBox && pListBox->m_hWnd)
  913.         {
  914.             m_iMinSize = pListBox->GetItemHeight(0)*4;
  915.             m_iMinSize += (14 + PIXEL_OFFSET_Y + m_iBoxHeight);
  916.             if (m_iHeight < m_iMinSize) {
  917.                 m_iHeight = m_iMinSize;
  918.             }
  919.         }
  920.     }
  921.     UpdateFixedSize();
  922. }
  923.  
  924. void CComposeBar::UpdateAttachmentInfo(int total)
  925. {
  926.     if (total != m_iTotalAttachments)
  927.     {
  928.         m_iTotalAttachments = total;
  929.         Invalidate();
  930.     }
  931. }
  932.  
  933.  
  934.  
  935. void CComposeBar::UpdateFixedSize ( void )    
  936. {
  937.  
  938. }
  939.  
  940. CSize CComposeBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)   
  941. {
  942.     CSize size;
  943.     size.cx = (bStretch && bHorz ? 32767 : 8 );
  944.     size.cy = GetHeightNeeded ( );
  945.     return size;
  946. }
  947.  
  948. void CComposeBar::UpdateHeaderInfo ( void )
  949. {
  950.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  951.     MSG_Pane *pComposePane = pCompose->GetMsgPane();
  952.     ASSERT(pComposePane);
  953.     UpdateOptionsInfo();
  954.     if (m_pIAddressList->IsCreated())
  955.     {
  956.         MSG_HeaderEntry * entry = NULL;
  957.         CListBox * pTypeList = m_pIAddressList->GetAddressTypeComboBox();
  958.  
  959.         // read all the entries (minus hidden fields) from the list
  960.         CListBox * pListBox = m_pIAddressList->GetListBox();
  961.         int count = pListBox->GetCount();
  962.         int iTotalFields = count;
  963.         int iTypeCount = pTypeList->GetCount();
  964.         int i;
  965.  
  966.         for (i = 0; i < iTypeCount; i++)
  967.         {
  968.             int32 bHidden;
  969.             char * pszValue;
  970.             m_pIAddressList->GetTypeInfo(i,ADDRESS_TYPE_FLAG_HIDDEN, (void**)&bHidden);
  971.             m_pIAddressList->GetTypeInfo(i,ADDRESS_TYPE_FLAG_VALUE,  (void**)&pszValue);
  972.                if (bHidden && pszValue)
  973.                iTotalFields++;
  974.         }
  975.         if (count)
  976.             entry = (MSG_HeaderEntry*)XP_ALLOC(sizeof(MSG_HeaderEntry)*iTotalFields);
  977.         MSG_ClearComposeHeaders(pComposePane);
  978.         if (entry == NULL)
  979.             return;
  980.         int iRealCount = 0;
  981.         for (i=0; i<count; i++)
  982.         {
  983.             char * szName, * szType;
  984.             if(m_pIAddressList->GetEntry(i,&szType, &szName))
  985.             {
  986.                 entry[iRealCount].header_value = XP_STRDUP(szName);
  987.                 if (!strcmp(szType,szLoadString(IDS_ADDRESSTO)))
  988.                     entry[iRealCount].header_type = MSG_TO_HEADER_MASK;
  989.                 else if(!strcmp(szType,szLoadString(IDS_ADDRESSCC)))
  990.                     entry[iRealCount].header_type = MSG_CC_HEADER_MASK;
  991.                 else if(!strcmp(szType,szLoadString(IDS_ADDRESSBCC)))
  992.                     entry[iRealCount].header_type = MSG_BCC_HEADER_MASK;
  993.                 else if(!strcmp(szType,szLoadString(IDS_ADDRESSNEWSGROUP)))
  994.                     entry[iRealCount].header_type = MSG_NEWSGROUPS_HEADER_MASK;
  995.                 else if(!strcmp(szType,szLoadString(IDS_ADDRESSFOLLOWUPTO)))
  996.                     entry[iRealCount].header_type = MSG_FOLLOWUP_TO_HEADER_MASK;
  997.                 else if(!strcmp(szType,szLoadString(IDS_ADDRESSREPLYTO)))
  998.                     entry[iRealCount].header_type = MSG_REPLY_TO_HEADER_MASK;
  999.                 iRealCount++;
  1000.             }
  1001.         }
  1002.  
  1003.         // read all hidden fields from the list
  1004.         for (int j = 0; j < iTypeCount; j++)
  1005.         {
  1006.             int32 bHidden;
  1007.             char * pszValue;
  1008.             MSG_HEADER_SET header_set;
  1009.             m_pIAddressList->GetTypeInfo(j,ADDRESS_TYPE_FLAG_HIDDEN,(void**)&bHidden);
  1010.             m_pIAddressList->GetTypeInfo(j,ADDRESS_TYPE_FLAG_VALUE, (void**)&pszValue);
  1011.             m_pIAddressList->GetTypeInfo(j,ADDRESS_TYPE_FLAG_USER,  (void**)&header_set);
  1012.                if (bHidden && pszValue)
  1013.             {
  1014.                 entry[iRealCount].header_type = header_set;
  1015.                 entry[iRealCount].header_value = XP_STRDUP(pszValue);
  1016.                 iRealCount++;
  1017.             }
  1018.         }
  1019.  
  1020.         MSG_HeaderEntry * list;     
  1021.         count = MSG_CompressHeaderEntries(entry,iRealCount,&list);
  1022.         MSG_SetHeaderEntries(pComposePane,list,count);
  1023.  
  1024.         if (m_pSubjectEdit)
  1025.         {
  1026.             CString cs;
  1027.             m_pSubjectEdit->GetWindowText(cs);
  1028.             MSG_SetCompHeader(pComposePane,MSG_SUBJECT_HEADER_MASK,cs);
  1029.         }
  1030.  
  1031.         char untranslatedPriority[32];
  1032.         MSG_GetUntranslatedPriorityName((MSG_PRIORITY) (m_iPriorityIdx+2),
  1033.                                           untranslatedPriority, 32);
  1034.         MSG_SetCompHeader(pComposePane, MSG_PRIORITY_HEADER_MASK, untranslatedPriority);
  1035.         MSG_SetCompBoolHeader(pComposePane, MSG_RETURN_RECEIPT_BOOL_HEADER_MASK, m_bReceipt);
  1036.         MSG_SetCompBoolHeader(pComposePane, MSG_ENCRYPTED_BOOL_HEADER_MASK, m_bEncrypted);
  1037.         MSG_SetCompBoolHeader(pComposePane, MSG_SIGNED_BOOL_HEADER_MASK, m_bSigned);
  1038.           MSG_SetCompBoolHeader(pComposePane, MSG_UUENCODE_BINARY_BOOL_HEADER_MASK, m_bUseUUENCODE);
  1039.         MSG_SetCompBoolHeader(pComposePane, MSG_ATTACH_VCARD_BOOL_HEADER_MASK, m_bAttachVCard);
  1040.  
  1041.         if (!strcmp(m_pszMessageFormat,szLoadString(IDS_FORMAT_ASKME)))
  1042.             MSG_SetHTMLAction(pComposePane,MSG_HTMLAskUser);
  1043.         else if (!strcmp(m_pszMessageFormat,szLoadString(IDS_FORMAT_PLAIN)))
  1044.             MSG_SetHTMLAction(pComposePane,MSG_HTMLConvertToPlaintext);
  1045.         else if (!strcmp(m_pszMessageFormat,szLoadString(IDS_FORMAT_HTML)))
  1046.             MSG_SetHTMLAction(pComposePane,MSG_HTMLSendAsHTML);
  1047.         else if (!strcmp(m_pszMessageFormat,szLoadString(IDS_FORMAT_BOTH)))
  1048.             MSG_SetHTMLAction(pComposePane,MSG_HTMLUseMultipartAlternative);
  1049.         else
  1050.             ASSERT(0);
  1051.     }
  1052. }
  1053.  
  1054. void CComposeBar::DisplayHeaders ( MSG_HEADER_SET headers )
  1055. {
  1056.     DestroyAttachmentsPage();
  1057.     DestroyAddressPage();
  1058.     ::SendMessage(GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfTextFont, FALSE);
  1059.     CreateStandardFields();
  1060.     CreateAddressPage();
  1061.     GetParentFrame()->PostMessage(WM_IDLEUPDATECMDUI);
  1062. }
  1063.  
  1064. int CComposeBar::GetHeightNeeded ( void )
  1065. {
  1066.     return m_iHeight;
  1067. }                 
  1068.  
  1069. void CComposeBar::DestroyAttachmentsPage()
  1070. {
  1071.     if (m_pAttachmentList && ::IsWindow(m_pAttachmentList->m_hWnd))
  1072.         m_pAttachmentList->ShowWindow(SW_HIDE);
  1073.     m_pWidget = NULL;
  1074. }
  1075.  
  1076. void CComposeBar::DestroyAddressPage()
  1077. {
  1078.     CListBox * pListBox = m_pIAddressList->GetListBox();
  1079.     if (pListBox && ::IsWindow(pListBox->m_hWnd))
  1080.         pListBox->ShowWindow(SW_HIDE);
  1081.     m_pWidget = NULL;
  1082. }
  1083.  
  1084. void CComposeBar::DestroyStandardFields()
  1085. {
  1086.     if (m_pSubjectEdit && ::IsWindow(m_pSubjectEdit->m_hWnd))
  1087.     {
  1088.         m_pSubjectEdit->DestroyWindow();
  1089.         delete m_pSubjectEdit;
  1090.         m_pSubjectEdit = NULL;
  1091.     }
  1092.     if (m_pSubjectEditText && ::IsWindow(m_pSubjectEditText->m_hWnd))
  1093.     {
  1094.         m_pSubjectEditText->DestroyWindow();
  1095.         delete m_pSubjectEditText;
  1096.         m_pSubjectEditText = NULL;
  1097.     }
  1098. }
  1099.  
  1100. void CComposeBar::CreateOptionsPage()
  1101. {
  1102.     CString cs;
  1103.  
  1104.     // create the options on the left
  1105.     m_pEncrypted = new CButton;
  1106.     m_pEncrypted->Create(
  1107.         szLoadString(IDS_ENCRYPTED),WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,
  1108.         CRect(0,0,0,0),this,ID_ENCRYPTED);
  1109.     ::SendMessage(m_pEncrypted->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1110.     m_pEncrypted->SetCheck(m_bEncrypted);
  1111.  
  1112.     m_pSigned = new CButton;
  1113.     m_pSigned->Create(
  1114.         szLoadString(IDS_SIGNED),WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,
  1115.         CRect(0,0,0,0),this,ID_SIGNED);
  1116.     ::SendMessage(m_pSigned->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1117.     m_pSigned->SetCheck(m_bSigned);
  1118.  
  1119.     m_pUseUUENCODE = new CButton;
  1120.     m_pUseUUENCODE->Create(
  1121.         szLoadString(IDS_USEUUENCODE),WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,
  1122.         CRect(0,0,0,0),this,1013);
  1123.     ::SendMessage(m_pUseUUENCODE->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1124.     m_pUseUUENCODE->SetCheck(m_bUseUUENCODE);
  1125.  
  1126.     m_pReturnReceipt = new CButton;
  1127.     m_pReturnReceipt->Create(
  1128.         szLoadString(IDS_RETURNRECEIPT),WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,
  1129.         CRect(0,0,0,0),this,1010);
  1130.     ::SendMessage(m_pReturnReceipt->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1131.     m_pReturnReceipt->SetCheck(m_bReceipt);
  1132.  
  1133.     // create priority combo box
  1134.     m_pPriorityText = new CStatic;
  1135.     cs.LoadString(IDS_COMPOSE_PRIORITY);
  1136.     m_pPriorityText->Create( cs, WS_CHILD | WS_VISIBLE, CRect(0,0,0,0),this,1500);
  1137.     ::SendMessage(m_pPriorityText->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1138.     m_pPriority = new CComboBox;
  1139.     m_pPriority->Create(
  1140.         CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP,
  1141.         CRect(0,0,0,0), this, 1501);
  1142.     ::SendMessage(m_pPriority->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfTextFont, FALSE);
  1143.  
  1144.     char priStr[32];
  1145.     MSG_GetPriorityName(MSG_LowestPriority, priStr, 32);
  1146.     m_pPriority->AddString (priStr);
  1147.     MSG_GetPriorityName(MSG_LowPriority, priStr, 32);
  1148.     m_pPriority->AddString (priStr);
  1149.     MSG_GetPriorityName(MSG_NormalPriority, priStr, 32);
  1150.     m_pPriority->AddString (priStr);
  1151.     MSG_GetPriorityName(MSG_HighPriority, priStr, 32);
  1152.     m_pPriority->AddString (priStr);
  1153.     MSG_GetPriorityName(MSG_HighestPriority, priStr, 32);
  1154.     m_pPriority->AddString (priStr);
  1155.     m_pPriority->SetCurSel(m_iPriorityIdx);
  1156.  
  1157.     CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  1158.     m_pMessageFormatText = new CStatic;
  1159.     cs.LoadString(IDS_MESSAGEFORMAT);
  1160.     m_pMessageFormatText->Create( cs, WS_CHILD | WS_VISIBLE, CRect(0,0,0,0),this,1504);
  1161.     ::SendMessage(m_pMessageFormatText->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1162.     m_pMessageFormat = new CComboBox;
  1163.     m_pMessageFormat->Create(
  1164.         CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP,
  1165.         CRect(0,0,0,0), this, 1505);
  1166.     ::SendMessage(m_pMessageFormat->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfTextFont, FALSE);
  1167.     m_pMessageFormat->AddString(szLoadString(IDS_FORMAT_ASKME));
  1168.     m_pMessageFormat->AddString(szLoadString(IDS_FORMAT_PLAIN));
  1169.     m_pMessageFormat->AddString(szLoadString(IDS_FORMAT_HTML));
  1170.     m_pMessageFormat->AddString(szLoadString(IDS_FORMAT_BOTH ));
  1171.     int idx = m_pMessageFormat->FindString(0,m_pszMessageFormat);
  1172.     if (idx == LB_ERR)
  1173.         m_pMessageFormat->SetCurSel(pCompose->UseHtml() ? 0 : 1);     // default to askme
  1174.     else
  1175.         m_pMessageFormat->SetCurSel(idx);
  1176.  
  1177.     if (!pCompose->UseHtml())
  1178.         m_pMessageFormat->EnableWindow(FALSE);
  1179.     CalcFieldLayout();
  1180. }
  1181.  
  1182. void CComposeBar::UpdateOptionsInfo()
  1183. {
  1184.     if (m_pReturnReceipt && ::IsWindow(m_pReturnReceipt->m_hWnd))
  1185.         m_bReceipt = m_pReturnReceipt->GetCheck();
  1186.     if (m_pPriority && ::IsWindow(m_pPriority->m_hWnd))
  1187.     {
  1188.         m_iPriorityIdx = m_pPriority->GetCurSel();
  1189.         if (m_iPriorityIdx < 0)
  1190.           m_iPriorityIdx = 2;
  1191.     }
  1192.     if (m_pMessageFormat && ::IsWindow(m_pMessageFormat->m_hWnd))
  1193.     {
  1194.         CString cs;
  1195.         int idx = m_pMessageFormat->GetCurSel();
  1196.         m_pMessageFormat->GetLBText(idx, cs);
  1197.         if (m_pszMessageFormat)
  1198.             free(m_pszMessageFormat);
  1199.         m_pszMessageFormat = strdup(cs);
  1200.     }
  1201.     if (m_pSigned && ::IsWindow(m_pSigned->m_hWnd))
  1202.         m_bSigned = m_pSigned->GetCheck();
  1203.     if (m_pEncrypted && ::IsWindow(m_pEncrypted->m_hWnd))
  1204.         m_bEncrypted = m_pEncrypted->GetCheck();
  1205.     if (m_pUseUUENCODE && ::IsWindow(m_pUseUUENCODE->m_hWnd))
  1206.         m_bUseUUENCODE = m_pUseUUENCODE->GetCheck();
  1207. }
  1208.  
  1209. void CComposeBar::DestroyOptionsPage()
  1210. {
  1211.     UpdateOptionsInfo();
  1212.     if (m_pPriorityText && ::IsWindow(m_pPriorityText->m_hWnd))
  1213.     {
  1214.         m_pPriorityText->DestroyWindow();
  1215.         delete m_pPriorityText;
  1216.         m_pPriorityText = NULL;
  1217.     }
  1218.     if (m_pPriority && ::IsWindow(m_pPriority->m_hWnd))
  1219.     {
  1220.         m_pPriority->DestroyWindow();
  1221.         delete m_pPriority;
  1222.         m_pPriority = NULL;
  1223.     }
  1224.     if (m_pReturnReceipt && ::IsWindow(m_pReturnReceipt->m_hWnd))
  1225.     {
  1226.         m_pReturnReceipt->DestroyWindow();
  1227.         delete m_pReturnReceipt;
  1228.         m_pReturnReceipt = NULL;
  1229.     }
  1230.     if (m_pEncrypted && ::IsWindow(m_pEncrypted->m_hWnd))
  1231.     {
  1232.         m_pEncrypted->DestroyWindow();
  1233.         delete m_pEncrypted;
  1234.         m_pEncrypted = NULL;
  1235.     }
  1236.     if (m_pUseUUENCODE && ::IsWindow(m_pUseUUENCODE->m_hWnd))
  1237.     {
  1238.         m_pUseUUENCODE->DestroyWindow();
  1239.         delete m_pUseUUENCODE;
  1240.         m_pUseUUENCODE = NULL;
  1241.     }
  1242.     if (m_pSigned && ::IsWindow(m_pSigned->m_hWnd))
  1243.     {
  1244.         m_pSigned->DestroyWindow();
  1245.         delete m_pSigned;
  1246.         m_pSigned = NULL;
  1247.     }
  1248.     if (m_pMessageFormat && ::IsWindow(m_pMessageFormat->m_hWnd))
  1249.     {
  1250.         m_pMessageFormat->DestroyWindow();
  1251.         delete m_pMessageFormat;
  1252.         m_pMessageFormat = NULL;
  1253.     }
  1254.     if (m_pMessageFormatText && ::IsWindow(m_pMessageFormatText->m_hWnd))
  1255.     {
  1256.         m_pMessageFormatText->DestroyWindow();
  1257.         delete m_pMessageFormatText;
  1258.         m_pMessageFormatText = NULL;
  1259.     }
  1260. }
  1261.  
  1262. void CComposeBar::CreateAttachmentsPage()
  1263. {
  1264.     CString cs;                                                                                                                                                 
  1265.     // the attachment control
  1266.     MSG_Pane *pComposePane = ((CComposeFrame *)GetParent())->GetMsgPane();
  1267.     if (!m_pAttachmentList)
  1268.     {
  1269.         m_pAttachmentList = new CNSAttachmentList(pComposePane);
  1270.         m_pAttachmentList->Create(this,1550);
  1271.     }
  1272.     else if (!m_pAttachmentList->IsWindowVisible())
  1273.         m_pAttachmentList->ShowWindow(SW_SHOW);
  1274.  
  1275.     m_pWidget = (CWnd *)m_pAttachmentList;
  1276.     CalcFieldLayout();
  1277. }
  1278.  
  1279. void CComposeBar::CreateAddressPage()
  1280. {
  1281.     CreateAddressingBlock();
  1282.     CalcFieldLayout();
  1283. }
  1284.  
  1285.  
  1286. void CComposeBar::Enable3d(BOOL bEnable)
  1287. {
  1288.  
  1289. }
  1290.  
  1291. void CComposeBar::CreateAddressingBlock(void)
  1292. {
  1293.     Enable3d(FALSE);
  1294.     CListBox * pListBox = m_pIAddressList->GetListBox();
  1295.     if (!m_pIAddressList->IsCreated()) 
  1296.     {
  1297.         m_pIAddressList->Create(this,IDC_ADDRESSLIST);
  1298.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSTO),IDB_PERSON);
  1299.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSCC),IDB_PERSON);
  1300.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSBCC),IDB_PERSON);
  1301.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSNEWSGROUP),IDB_NEWSART, FALSE);
  1302.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSREPLYTO),IDB_PERSON, FALSE, TRUE, TRUE,(DWORD)MSG_REPLY_TO_HEADER_MASK);
  1303.         m_pIAddressList->AddAddressType(szLoadString(IDS_ADDRESSFOLLOWUPTO), IDB_PERSON, FALSE, TRUE, TRUE, (DWORD)MSG_FOLLOWUP_TO_HEADER_MASK);
  1304.         CComposeFrame *pCompose = (CComposeFrame *)GetParentFrame();
  1305.         m_pIAddressList->SetCSID(pCompose->m_iCSID);
  1306.     }
  1307.     else if (!pListBox->IsWindowVisible())
  1308.         pListBox->ShowWindow(SW_SHOW);
  1309.     pListBox->Invalidate();
  1310.     pListBox->UpdateWindow();
  1311.     m_iMinSize = pListBox->GetItemHeight(0)*4;
  1312.     m_iMinSize += (14 + PIXEL_OFFSET_Y + m_iBoxHeight);
  1313.     if (m_iHeight < m_iMinSize)
  1314.     {
  1315.         m_iHeight = m_iMinSize;
  1316.     }
  1317.     m_pWidget = (CWnd *)pListBox;
  1318.     Enable3d(TRUE);
  1319. }
  1320.  
  1321.  
  1322.  
  1323. void CComposeBar::AddedItem (HWND hwnd, LONG id,int index)
  1324. {
  1325.     char * szName = NULL;
  1326.     BOOL bRetVal = m_pIAddressList->GetEntry(index, NULL, &szName);
  1327.     if (bRetVal)
  1328.     {
  1329.         char * pszFullName = NULL;
  1330.         ChangedItem(szName, index, hwnd, &pszFullName);
  1331.         if (pszFullName != NULL)
  1332.         {
  1333.             m_pIAddressList->SetItemName(index,pszFullName);
  1334.             free(pszFullName);
  1335.         }
  1336.     }
  1337. }
  1338.  
  1339. int CComposeBar::ChangedItem(char * pString, int, HWND, char** ppszFullName, unsigned long* entryID, UINT* bitmapID)
  1340. {
  1341.     (*ppszFullName) = wfe_ExpandName(pString);
  1342.     return TRUE;
  1343. }
  1344.  
  1345. void CComposeBar::DeletedItem (HWND hwnd, LONG id,int index)
  1346. {
  1347. }
  1348.  
  1349. char * CComposeBar::NameCompletion(char * pString)
  1350. {
  1351.     return wfe_ExpandForNameCompletion(pString);
  1352. }
  1353.  
  1354. void CComposeBar::CreateStandardFields(void)
  1355. {
  1356.     // create subject edit field
  1357.     m_pSubjectEditText = new CStatic;
  1358.     CString cs;
  1359.     cs.LoadString(IDS_COMPOSE_SUBJECT);
  1360.     m_pSubjectEditText->Create( cs, WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, 1500 );
  1361.     ::SendMessage(m_pSubjectEditText->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfStaticFont, FALSE);
  1362.  
  1363.     m_pSubjectEdit = new CComposeSubjectEdit;
  1364.     m_pSubjectEdit->Create(
  1365.         WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, 
  1366.         CRect(0,0,0,0), (CWnd *) this, IDC_SUBJECT_EDIT );
  1367.     ::SendMessage(m_pSubjectEdit->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfSubjectFont, FALSE);
  1368. #ifdef XP_WIN32
  1369.     if (sysInfo.m_bWin4)
  1370.     {
  1371.         ::SendMessage(m_pSubjectEdit->m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN, 0L);
  1372.         ::SendMessage(m_pSubjectEdit->m_hWnd, EM_SETMARGINS, EC_RIGHTMARGIN, 0L);
  1373.     }
  1374. #endif
  1375.     m_pSubjectEdit->SetWindowText( "" );
  1376. }
  1377.  
  1378. // This function recalculates the field layout based on the window width
  1379. // for the subject, priority, address widget, and buttons...
  1380. // This function assumes that the fields are created already.
  1381.  
  1382. #define FIELD_PIXEL_OFFSET  3
  1383. #define TEXT_PIXEL_OFFSET   4
  1384.  
  1385. void CComposeBar::CalcFieldLayout(void)
  1386. {
  1387.     CRect WinRect, rect;
  1388.     GetClientRect(WinRect);
  1389.     int x = WinRect.Width();
  1390.     int controlWidth;
  1391.     
  1392.     CDC * pDC = m_pSubjectEditText->GetDC();
  1393.     CString cs;
  1394.     m_pSubjectEditText->GetWindowText(cs);
  1395. #ifdef _WIN32
  1396.     controlWidth = pDC->GetTextExtent(cs).cx - 16;
  1397. #else
  1398.     controlWidth = pDC->GetTextExtent(LPCTSTR(cs), cs.GetLength()).cx - 16;
  1399. #endif
  1400.     ReleaseDC(pDC);
  1401.  
  1402.     pDC = GetDC();
  1403.     int pix_per_inch_x = pDC->GetDeviceCaps(LOGPIXELSX);
  1404.     int pix_per_inch_y = pDC->GetDeviceCaps(LOGPIXELSY);
  1405.     ReleaseDC(pDC);
  1406.  
  1407.     GetWidgetRect(WinRect,rect);
  1408.     rect.bottom = WinRect.Height() - 2;
  1409.     CRect rect2 = rect;
  1410.     rect2.bottom -= 2;
  1411.     rect2.left = COMP_VTAB_WIDTH + COMP_LEFT_MARGIN;
  1412.     rect2.right = rect2.left + controlWidth;
  1413.     rect2.top = rect2.bottom - m_iBoxHeight;
  1414.  
  1415.     m_pSubjectEditText->MoveWindow(rect2);
  1416.  
  1417.     rect2.left = rect2.right + 4;
  1418.     rect2.right = rect.right;
  1419.     rect2.top--;
  1420.     m_pSubjectEdit->MoveWindow(rect2);
  1421.     
  1422.     // resize and position the buttons.
  1423.     BOOL bHasButtons = FALSE;
  1424.  
  1425.     x = m_cxChar + TAB_SPACING_X + 4;
  1426.     int y = PIXEL_OFFSET_Y + 2;
  1427.     int iButtonWidth = 0;
  1428.  
  1429.     CRect parentRect;
  1430.     GetParentFrame()->GetWindowRect(parentRect);
  1431.     m_iMaxSize = parentRect.Height()-(m_iBoxHeight*3);
  1432.     if (m_iMaxSize <= 0)
  1433.        m_iMaxSize = m_iBoxHeight*3;
  1434.  
  1435.     if (m_pWidget)
  1436.     {
  1437.         ASSERT(::IsWindow(m_pWidget->m_hWnd));
  1438.         GetWidgetRect(WinRect,rect);
  1439.         int pix_x = 2; //pix_per_inch_x/PIX_X_FACTOR;
  1440.         int pix_y = 2; //pix_per_inch_y/PIX_Y_FACTOR;
  1441.         rect.InflateRect(-pix_x,-pix_y);
  1442.         rect.left += pix_x;
  1443.         m_pWidget->MoveWindow(rect);
  1444.     }
  1445.  
  1446.     // options page
  1447.     if (m_iSelectedTab == IDX_COMPOSEOPTIONS && 
  1448.        m_pPriority && ::IsWindow(m_pPriority->m_hWnd))
  1449.     {
  1450.         // allign the text
  1451.         rect.top = (PIXEL_OFFSET_Y+TEXT_PIXEL_OFFSET);
  1452.         rect.bottom = rect.top + m_iBoxHeight;
  1453.         rect.left = x + m_cxChar * 3;
  1454.         rect.right = (WinRect.Width()/2) + 24;
  1455.         m_pEncrypted->MoveWindow(rect);
  1456.  
  1457.         rect.top = rect.bottom + 1;
  1458.         rect.bottom = rect.top + m_iBoxHeight;
  1459.         m_pSigned->MoveWindow(rect);
  1460.  
  1461.         rect.top = rect.bottom + 1;
  1462.         rect.bottom = rect.top + m_iBoxHeight;
  1463.         m_pUseUUENCODE->MoveWindow(rect);
  1464.  
  1465.         ASSERT(::IsWindow(m_pPriorityText->m_hWnd));
  1466.         pDC = m_pPriorityText->GetDC();
  1467.         m_pPriorityText->GetWindowText(cs);
  1468. #ifdef _WIN32
  1469.         controlWidth = pDC->GetTextExtent(cs).cx - 16;
  1470. #else
  1471.         controlWidth = pDC->GetTextExtent(LPCTSTR(cs), cs.GetLength()).cx - 16;
  1472. #endif
  1473.         m_pMessageFormatText->GetWindowText(cs);
  1474. #ifdef _WIN32
  1475.         controlWidth = max(controlWidth,pDC->GetTextExtent(cs).cx - 16);
  1476. #else
  1477.         controlWidth = max(controlWidth,pDC->GetTextExtent(LPCTSTR(cs), cs.GetLength()).cx - 16);
  1478. #endif
  1479.         ReleaseDC(pDC);
  1480.  
  1481.        CRect rect3;
  1482.           GetWidgetRect(WinRect,rect3);
  1483.         rect.top = (PIXEL_OFFSET_Y+TEXT_PIXEL_OFFSET);
  1484.         rect.bottom = rect.top + m_iBoxHeight;
  1485.         rect.left = rect.right + 2;
  1486.        rect.right = rect3.right - 2;
  1487.        m_pReturnReceipt->MoveWindow(rect);
  1488.  
  1489.         rect.right = rect.left + controlWidth;
  1490.         rect.top = rect.bottom + 7;
  1491.         rect.bottom = rect.top + m_iBoxHeight;
  1492.        rect2 = rect;
  1493.  
  1494.         m_pPriorityText->MoveWindow(rect);
  1495.  
  1496.         CDC * pDC = m_pPriority->GetDC();
  1497.         int i, maxwidth = 0;
  1498.         CString cs;
  1499.         // find the longest string in the priority box
  1500.         for (i=0; i<m_pPriority->GetCount(); i++)
  1501.         {
  1502.             m_pPriority->GetLBText(i,cs);
  1503. #ifdef _WIN32
  1504.             CSize size = pDC->GetTextExtent(cs);
  1505. #else
  1506.             CSize size = pDC->GetTextExtent(LPCTSTR(cs), cs.GetLength());
  1507. #endif
  1508.             maxwidth = max(size.cx,maxwidth);
  1509.         }
  1510.  
  1511.         for (i=0; i<m_pMessageFormat->GetCount(); i++)
  1512.         {
  1513.             m_pMessageFormat->GetLBText(i,cs);
  1514. #ifdef _WIN32
  1515.             CSize size = pDC->GetTextExtent(cs);
  1516. #else
  1517.             CSize size = pDC->GetTextExtent(LPCTSTR(cs), cs.GetLength());
  1518. #endif
  1519.             maxwidth = max(size.cx,maxwidth);
  1520.         }
  1521.  
  1522.         ReleaseDC(pDC);
  1523.  
  1524.         // right allign it    
  1525.         rect2.top -= TEXT_PIXEL_OFFSET;
  1526.         rect2.bottom = rect2.top + (m_iBoxHeight+2)*8;
  1527.         rect2.left = rect2.right;
  1528.         rect2.right = rect2.left + maxwidth + GetSystemMetrics(SM_CXHSCROLL) + 2;
  1529.         int iOldHeight = rect2.Height();
  1530.         m_pPriority->MoveWindow(rect2);
  1531.  
  1532.         rect.top = rect.bottom + TEXT_PIXEL_OFFSET + 4;
  1533.         rect.bottom = rect.top + m_iBoxHeight;
  1534.         m_pMessageFormatText->MoveWindow(rect);
  1535.  
  1536.         rect2.top = rect.top - TEXT_PIXEL_OFFSET;
  1537.         rect2.bottom = rect2.top + (m_iBoxHeight+2)*8;
  1538.         m_pMessageFormat->MoveWindow(rect2);
  1539.  
  1540.     }
  1541. }
  1542.  
  1543. int CComposeBar::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
  1544. {
  1545.     if (pTI != NULL)
  1546.     {
  1547.         for (int i = 0; i < MAX_TIPS; i++)
  1548.         {
  1549.             if (m_ToolTipInfo[i].m_rect.PtInRect(point))
  1550.             {
  1551.  
  1552.             pTI->hwnd = m_hWnd;
  1553.             pTI->rect = m_ToolTipInfo[i].m_rect;
  1554.             if (i == IDX_TOOL_COLLAPSE && m_bClosed == TRUE)
  1555.             {
  1556.                 CString cs;
  1557.                 cs.LoadString(IDS_COMPOSECLOSE);
  1558.                 pTI->lpszText = strdup(cs);
  1559.             }
  1560.             else
  1561.                 pTI->lpszText = strdup(m_ToolTipInfo[i].m_csToolTip);
  1562.             pTI->uId = i;
  1563.             return 1;
  1564.             }
  1565.         }
  1566.     }
  1567. #ifdef XP_WIN32
  1568.     return CDialogBar::OnToolHitTest(point,pTI);
  1569. #else
  1570.     return FALSE;
  1571. #endif
  1572. }
  1573.  
  1574. void CComposeBar::UpdateRecipientInfo ( char *pTo, char *pCc, char *pBcc )
  1575. {
  1576. }
  1577.  
  1578. void CComposeBar::AttachFile(void)
  1579. {
  1580.     ASSERT(m_pAttachmentList);
  1581.     m_pAttachmentList->AttachFile();
  1582. }
  1583.  
  1584. void CComposeBar::AttachUrl(void)
  1585. {
  1586.    CComposeFrame *pCompose = (CComposeFrame *)GetParent();
  1587.    MSG_Pane *pComposePane = pCompose->GetMsgPane();
  1588.    ASSERT(m_pAttachmentList);
  1589.    char * pUrl =  (char*)MSG_GetAssociatedURL(pComposePane);
  1590.    m_pAttachmentList->AttachUrl(pUrl);
  1591. }
  1592.     
  1593. extern "C" char * wfe_ExpandForNameCompletion(char * pString)
  1594. {
  1595.     ABID entryID = -1;
  1596.     ABID field = -1;
  1597.     DIR_Server* pab  = NULL;
  1598.  
  1599.     DIR_GetComposeNameCompletionAddressBook (theApp.m_directories, &pab);
  1600.     if (pab != NULL && theApp.m_pABook)
  1601.     {
  1602.     AB_GetIDForNameCompletion(
  1603.         theApp.m_pABook,
  1604.         pab, 
  1605.         &entryID,&field,(LPCTSTR)pString);
  1606.     if (entryID != -1)
  1607.     {
  1608.             if (field == ABNickname) {
  1609.                 char szNickname[kMaxNameLength];
  1610.                 AB_GetNickname(
  1611.                     pab, 
  1612.                     theApp.m_pABook, entryID, szNickname);
  1613.                 if (strlen(szNickname))
  1614.                     return strdup(szNickname);
  1615.             }
  1616.         else {
  1617.                 char szFullname[kMaxFullNameLength];
  1618.                 AB_GetFullName(pab, theApp.m_pABook, 
  1619.                     entryID, szFullname);
  1620.                 if (strlen(szFullname))
  1621.                     return strdup(szFullname);
  1622.             }
  1623.         }
  1624.     }
  1625.  
  1626.     return NULL;
  1627. }
  1628.  
  1629. extern "C" char * wfe_ExpandName(char * pString)
  1630. {
  1631.     ABID entryID = -1;
  1632.     ABID field = -1;
  1633.     char * fullname = NULL;
  1634.  
  1635.     DIR_Server* pab  = NULL;
  1636.  
  1637.     DIR_GetComposeNameCompletionAddressBook (theApp.m_directories, &pab);
  1638.     if (pab != NULL && theApp.m_pABook)
  1639.     {
  1640.         AB_GetIDForNameCompletion(
  1641.             theApp.m_pABook,
  1642.             pab,
  1643.             &entryID, &field,pString);
  1644.         if (entryID != -1)
  1645.         {
  1646.             AB_GetExpandedName(
  1647.                 pab, 
  1648.                 theApp.m_pABook, entryID, &fullname);
  1649.             if (fullname)
  1650.                 return fullname;
  1651.         }
  1652.     }
  1653.     return NULL;
  1654. }
  1655.  
  1656.  
  1657. void CComposeBar::OnDropFiles( HDROP hDropInfo )
  1658. {
  1659.    UINT wNumFilesDropped = ::DragQueryFile(hDropInfo,(UINT)-1,NULL,0);
  1660.    if (wNumFilesDropped > 0)
  1661.    {
  1662.       OnAttachTab();
  1663.       UpdateWindow();
  1664.       if (m_pAttachmentList && ::IsWindow(m_pAttachmentList->m_hWnd))
  1665.          m_pAttachmentList->OnDropFiles(hDropInfo);
  1666.    }
  1667. }
  1668.  
  1669. BOOL CComposeBar::ProcessVCardData(COleDataObject * pDataObject, CPoint &point)
  1670. {
  1671.    UINT clipFormat;
  1672.    BOOL retVal;
  1673.    CWnd * pWnd = GetFocus();
  1674.    if(pDataObject->IsDataAvailable(
  1675.       clipFormat = ::RegisterClipboardFormat(vCardClipboardFormat))) 
  1676.    {
  1677.       HGLOBAL hAddresses = pDataObject->GetGlobalData(clipFormat);
  1678.       LPSTR pAddresses = (LPSTR)GlobalLock(hAddresses);
  1679.       ASSERT(pAddresses);
  1680.       XP_List * pEntries;
  1681.       int32 iEntries;
  1682.         CComposeFrame *pCompose = (CComposeFrame *)GetParentFrame();
  1683.        ApiApiPtr(api);
  1684.        LPUNKNOWN pUnk = api->CreateClassInstance(
  1685.             APICLASS_ADDRESSCONTROL, NULL, (APISIGNATURE)pCompose);
  1686.          LPADDRESSCONTROL pIAddressControl = NULL;
  1687.        if (pUnk)
  1688.        {
  1689.            HRESULT hRes = pUnk->QueryInterface(IID_IAddressControl,(LPVOID*)&pIAddressControl);
  1690.            ASSERT(hRes==NOERROR);
  1691.        }
  1692.       if (pIAddressControl)
  1693.       {
  1694.          int itemNum = pIAddressControl->GetItemFromPoint(&point);
  1695.          char * szType = NULL;
  1696.          char * szName = NULL;
  1697.          CListBox * pListBox = pIAddressControl->GetListBox();
  1698.          if (itemNum <= pListBox->GetCount())
  1699.             pIAddressControl->GetEntry (itemNum, &szType, &szName); 
  1700.          char * pszType = strdup(szType);
  1701.          if (!AB_ConvertVCardsToExpandedName(theApp.m_pABook,pAddresses,&pEntries,&iEntries))
  1702.          {
  1703.             XP_List * node = pEntries;
  1704.             if (pListBox->GetCount() == 1 && (!szName || !strlen(szName)))
  1705.                pListBox->ResetContent();
  1706.             else
  1707.                if (!szName || !strlen(szName))
  1708.                   pIAddressControl->DeleteEntry(itemNum);
  1709.             for (int32 i = 0; i < iEntries+1; i++)
  1710.             {
  1711.                char * pString = (char *)node->object;
  1712.                if (pString != NULL)
  1713.                   pIAddressControl->AppendEntry(FALSE, pszType,pString,IDB_PERSON);
  1714.                node = node->next;
  1715.                if (!node)
  1716.                   break;
  1717.             }
  1718.             XP_ListDestroy(pEntries);
  1719.          }
  1720.          if (pUnk)
  1721.             pUnk->Release();
  1722.          if (pszType)
  1723.             free(pszType);
  1724.          GlobalUnlock(hAddresses);
  1725.          retVal = TRUE;
  1726.       }
  1727.    }
  1728.    if (pWnd && ::IsWindow(pWnd->m_hWnd))
  1729.       pWnd->SetFocus();
  1730.    return retVal;
  1731. }
  1732.  
  1733.  
  1734. //////////////////////////////////////////////////////////////////////////////
  1735. // CNSCollapser
  1736.  
  1737. #define IDT_CNSCOLLAPSER 16425
  1738.  
  1739. CNSCollapser::CNSCollapser()
  1740. {
  1741.    m_hVertSectionBitmap =  NULL;
  1742.    m_hHTabBitmap =         NULL;
  1743.    m_bHilite =             FALSE;
  1744. }
  1745.  
  1746. CNSCollapser::~CNSCollapser()
  1747. {
  1748.    if (m_hVertSectionBitmap)
  1749.       VERIFY(::DeleteObject( (HGDIOBJ) m_hVertSectionBitmap ));
  1750.    if (m_hHTabBitmap)
  1751.       VERIFY(::DeleteObject( (HGDIOBJ) m_hHTabBitmap ));
  1752. }
  1753.  
  1754. void CNSCollapser::Initialize(CWnd * pWnd, UINT nCmdId)
  1755. {
  1756.    m_pWnd = pWnd;
  1757.    m_cmdId = nCmdId;
  1758. }
  1759.  
  1760. void CNSCollapser::DrawCollapseWidget(CDC &dc, COLLAPSE_STATE state, BOOL bHilite, int iSubtract)
  1761. {
  1762.    // this is the flippy thing
  1763.    if ( !m_hVertSectionBitmap ) 
  1764.    {
  1765.        m_hVertSectionBitmap = WFE_LoadSysColorBitmap( 
  1766.            AfxGetResourceHandle(), 
  1767.           MAKEINTRESOURCE(IDB_VERTICALTAB));
  1768.    }
  1769.    if ( !m_hHTabBitmap ) 
  1770.    {
  1771.        m_hHTabBitmap = WFE_LoadSysColorBitmap( 
  1772.            AfxGetResourceHandle(), 
  1773.           MAKEINTRESOURCE(IDB_LARGE_HFTAB));
  1774.    }
  1775.  
  1776.    m_cState = state;
  1777.    m_iSubtract = iSubtract;
  1778.    CDC dcVSection;
  1779.    dcVSection.CreateCompatibleDC(&dc);
  1780.    HBITMAP hOldBitmap = (HBITMAP)dcVSection.SelectObject(
  1781.       state == collapse_closed ? m_hHTabBitmap : m_hVertSectionBitmap);
  1782.  
  1783.    CRect rect, WinRect;
  1784.    m_pWnd->GetClientRect(&WinRect);
  1785.  
  1786.    rect.left   = 0;
  1787.    rect.top    = 2;
  1788.    rect.right  = COMP_VTAB_WIDTH;
  1789.    rect.bottom = WinRect.Height() - iSubtract;
  1790.  
  1791.    if (state == collapse_closed)
  1792.    {
  1793.       BITMAP bm;
  1794.       ::GetObject(m_hHTabBitmap,sizeof(BITMAP),(LPVOID)&bm);
  1795.       rect.right = bm.bmWidth;
  1796.       rect.bottom = 2 + COMP_HTAB_HEIGHT;
  1797.    }
  1798.    
  1799.    m_rect = rect;
  1800.  
  1801.    if (state == collapse_closed)
  1802.    {
  1803.       int ySrc = bHilite ? COMP_HTAB_HEIGHT : 0;
  1804.       dc.BitBlt( 
  1805.           rect.left, rect.top, rect.Width(), COMP_HTAB_HEIGHT,
  1806.           &dcVSection, 0, ySrc, SRCCOPY );
  1807.    }
  1808.    else 
  1809.    {
  1810.       int xSrc = bHilite ? COMP_VTAB_WIDTH : 0;
  1811.       dc.BitBlt( 
  1812.           rect.left, rect.top, COMP_VTAB_WIDTH, COMP_VTAB_TOP_HEIGHT,
  1813.           &dcVSection, xSrc, 0, SRCCOPY );
  1814.       int iMidSectionHeight = rect.Height()-(COMP_VTAB_TOP_HEIGHT+COMP_VTAB_BOTTOM_HEIGHT);
  1815.       int iRemainingHeight = iMidSectionHeight%COMP_VTAB_SECTION_HEIGHT;
  1816.       rect.top += COMP_VTAB_TOP_HEIGHT;
  1817.       if (iMidSectionHeight > COMP_VTAB_SECTION_HEIGHT)
  1818.       {
  1819.          int iSections = iMidSectionHeight/COMP_VTAB_SECTION_HEIGHT;
  1820.          for (int i = 0; i < iSections; i++)
  1821.          {
  1822.             dc.BitBlt( 
  1823.                rect.left, rect.top, COMP_VTAB_WIDTH, COMP_VTAB_SECTION_HEIGHT,
  1824.                  &dcVSection, xSrc, COMP_VTAB_TOP_HEIGHT+1, SRCCOPY );
  1825.             rect.top += COMP_VTAB_SECTION_HEIGHT;            
  1826.          }
  1827.       }
  1828.       if (iRemainingHeight)
  1829.       {
  1830.          dc.BitBlt( 
  1831.             rect.left, rect.top, COMP_VTAB_WIDTH, iRemainingHeight,
  1832.               &dcVSection, xSrc, COMP_VTAB_TOP_HEIGHT + 1, SRCCOPY );
  1833.          rect.top += iRemainingHeight;
  1834.       }
  1835.  
  1836.       dc.BitBlt( 
  1837.          rect.left, rect.top, COMP_VTAB_WIDTH, COMP_VTAB_BOTTOM_HEIGHT,
  1838.            &dcVSection, xSrc, COMP_VTAB_TOP_HEIGHT + COMP_VTAB_SECTION_HEIGHT + 2, SRCCOPY );
  1839.    }
  1840.  
  1841.    dcVSection.SelectObject(hOldBitmap);
  1842.    VERIFY(dcVSection.DeleteDC());
  1843. }
  1844.  
  1845. void CNSCollapser::TimerEvent(UINT nIDEvent)
  1846. {
  1847.     CRect rect;
  1848.     m_pWnd->GetWindowRect(&rect);
  1849.     POINT pt;
  1850.     GetCursorPos(&pt);
  1851.  
  1852.     if(nIDEvent == IDT_CNSCOLLAPSER)
  1853.     {
  1854.         if(!rect.PtInRect(pt))
  1855.         {
  1856.          m_bHilite = FALSE;
  1857.             m_pWnd->KillTimer(m_nTimer);
  1858.          CDC * pDC = m_pWnd->GetDC();
  1859.          DrawCollapseWidget(*pDC, m_cState, FALSE, m_iSubtract);
  1860.          m_pWnd->ReleaseDC(pDC);
  1861.         }
  1862.     }
  1863. }
  1864.  
  1865. BOOL CNSCollapser::ButtonPress(POINT & point)
  1866. {
  1867.    if (m_rect.PtInRect(point))
  1868.    {
  1869.       m_pWnd->SendMessage(WM_COMMAND, m_cmdId);
  1870.       return TRUE;
  1871.    }
  1872.    return FALSE;
  1873. }
  1874.  
  1875. void CNSCollapser::MouseAround(POINT & point)
  1876. {
  1877.    if (m_rect.PtInRect(point))
  1878.    {
  1879.       if (!m_bHilite)
  1880.       {
  1881.          m_bHilite = TRUE;
  1882.             m_nTimer = m_pWnd->SetTimer(IDT_CNSCOLLAPSER, 100, NULL);
  1883.          CDC * pDC = m_pWnd->GetDC();
  1884.          DrawCollapseWidget(*pDC, m_cState, m_bHilite, m_iSubtract);
  1885.          m_pWnd->ReleaseDC(pDC);
  1886.       }
  1887.    }
  1888.    else
  1889.    {
  1890.       if (m_bHilite)
  1891.       {
  1892.          m_bHilite = FALSE;
  1893.          CDC * pDC = m_pWnd->GetDC();
  1894.          DrawCollapseWidget(*pDC, m_cState, m_bHilite, m_iSubtract);
  1895.          m_pWnd->ReleaseDC(pDC);
  1896.       }
  1897.    }
  1898. }
  1899.  
  1900.  
  1901.  
  1902. void CComposeBar::OnUpdateOptions(void)
  1903. {
  1904.    UpdateOptionsInfo();
  1905. }
  1906.  
  1907. void CComposeBar::UpdateSecurityOptions(void)
  1908. {
  1909.     if (m_iSelectedTab == IDX_COMPOSEOPTIONS)
  1910.     {
  1911.         if (m_pEncrypted && ::IsWindow(m_pEncrypted->m_hWnd))
  1912.            m_pEncrypted->SetCheck(m_bEncrypted);
  1913.         if (m_pSigned && ::IsWindow(m_pSigned->m_hWnd))
  1914.             m_pSigned->SetCheck(m_bSigned);
  1915.     }
  1916.  
  1917. }
  1918.