home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / subnews.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  51.7 KB  |  1,976 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. #include "stdafx.h"
  20.  
  21. #include "property.h"
  22. #include "styles.h"
  23.  
  24. #include "helper.h"
  25. #include "display.h"
  26. #include "dialog.h"
  27.  
  28. #include "secnav.h"
  29. #include "custom.h"
  30. #include "cxabstra.h"
  31.  
  32. #include "msgcom.h"
  33. #include "subnews.h"
  34. #include "wfemsg.h"
  35. #include "mnprefs.h"
  36. #include "nethelp.h"    // help
  37. #include "xp_help.h"     
  38. #include "prefapi.h"     
  39. #include "thrdfrm.h"     
  40. #include "fldrfrm.h"     
  41.  
  42. #ifdef _DEBUG
  43. #undef THIS_FILE
  44. static char BASED_CODE THIS_FILE[] = __FILE__;
  45. #endif
  46.  
  47. #define LEVEL_ROOT        0
  48. #define LEVEL_1            1
  49. #define SUBSCRIBE_VISIBLE_TIMER   999
  50.  
  51. extern "C" BOOL IsNumeric(char* pStr);
  52. extern "C" void HelperInitFonts( HDC hdc , HFONT *phFont, HFONT *phBoldFont);
  53. extern "C" MSG_Host *DoAddNewsServer(CWnd* pParent, int nFromWhere);
  54. extern "C" MSG_Host *DoAddIMAPServer(CWnd* pParent, char* pServerName, BOOL bImap);
  55.  
  56.  
  57. extern "C" XP_Bool FE_CreateSubscribePaneOnHost(MSG_Master* master, 
  58.            MWContext* parentContext, MSG_Host* host)
  59. {
  60.     CGenericFrame *pFrame = theApp.m_pFrameList;
  61.     while (pFrame) {
  62.         if (pFrame->IsKindOf(RUNTIME_CLASS(C3PaneMailFrame))) {
  63.             C3PaneMailFrame *pThreadFrame = DYNAMIC_DOWNCAST(C3PaneMailFrame, pFrame);
  64.             pThreadFrame->SendMessage(WM_COMMAND, ID_FILE_SUBSCRIBE, (LPARAM)host);
  65.             return TRUE;
  66.         }
  67.         pFrame = pFrame->m_pNext;
  68.     }
  69.     pFrame = theApp.m_pFrameList;
  70.     while (pFrame) {
  71.         if (pFrame->IsKindOf(RUNTIME_CLASS(CFolderFrame))) {
  72.             CFolderFrame *pFolderFrame = DYNAMIC_DOWNCAST(CFolderFrame, pFrame);
  73.             pFolderFrame->SendMessage(WM_COMMAND, ID_FILE_SUBSCRIBE, (LPARAM)host);
  74.             return TRUE;
  75.         }
  76.         pFrame = pFrame->m_pNext;
  77.     }
  78.     return FALSE;
  79. }
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CServersCombo  
  83.  
  84. #define SERVER_BUTTONWIDTH    24
  85. #define SERVER_BUTTONHEIGHT    16
  86.  
  87. CServersCombo::CServersCombo()
  88. {
  89.     m_bStaticCtl = FALSE;
  90.  
  91.     m_hFont = NULL;
  92.     m_hBoldFont = NULL;
  93.     ApiApiPtr(api);
  94.  
  95.     m_pIImageUnk = api->CreateClassInstance(APICLASS_IMAGEMAP);
  96.     ASSERT(m_pIImageUnk);
  97.     if (m_pIImageUnk) {
  98.         m_pIImageUnk->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIImageMap);
  99.         ASSERT(m_pIImageMap);
  100.         m_pIImageMap->Initialize(IDB_MAILNEWS,16,16);
  101.     }
  102. }
  103.  
  104. CServersCombo::~CServersCombo()
  105. {
  106.     if (m_hFont)
  107.         theApp.ReleaseAppFont(m_hFont);
  108.     if (m_hBoldFont)
  109.         theApp.ReleaseAppFont(m_hBoldFont);
  110. }
  111.  
  112. void CServersCombo::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
  113. {
  114.     HDC hDC = lpDrawItemStruct->hDC;
  115.     RECT rcItem = lpDrawItemStruct->rcItem;
  116.     RECT rcTemp = rcItem;
  117.     RECT rcText;
  118.     DWORD dwItemData = lpDrawItemStruct->itemData;
  119.     HBRUSH hBrushWindow = ::CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  120.     HBRUSH hBrushHigh = ::CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) );
  121.     HBRUSH hBrushFill = NULL;
  122.  
  123.     if ( !m_hFont ) {
  124.         HelperInitFonts( hDC, &m_hFont, &m_hBoldFont);
  125.     }
  126.  
  127.     HFONT hOldFont = NULL;
  128.     if ( m_hFont ) {
  129.         hOldFont = (HFONT) ::SelectObject( hDC,(HFONT)&m_hFont );
  130.     }
  131.  
  132.     if ( lpDrawItemStruct->itemState & ODS_SELECTED ) {
  133.         hBrushFill = hBrushHigh;
  134.         ::SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) );
  135.         ::SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
  136.         m_pIImageMap->UseHighlight( );
  137.     } else {
  138.         hBrushFill = hBrushWindow;
  139.         ::SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) );
  140.         ::SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) );
  141.         m_pIImageMap->UseNormal( );
  142.     }
  143.  
  144.     VERIFY(::FillRect( hDC, &rcItem, hBrushFill ));
  145.  
  146.     if ( lpDrawItemStruct->itemID != -1 &&  dwItemData )
  147.     {
  148.         int idxImage;
  149.  
  150.         MSG_Host *pServer = (MSG_Host *) lpDrawItemStruct->itemData;
  151.  
  152.         if (MSG_IsNewsHost(pServer))
  153.             idxImage = IDX_NEWSHOST;
  154.         else
  155.             idxImage = IDX_REMOTEMAIL;
  156.  
  157.         BOOL bStatic = FALSE;
  158. #ifdef _WIN32
  159.     if ( sysInfo.m_bWin4 )
  160.         bStatic = ( lpDrawItemStruct->itemState & ODS_COMBOBOXEDIT ) ? TRUE : FALSE;
  161.     else 
  162. #endif
  163.         bStatic = m_bStaticCtl;
  164.  
  165.         //Draw the news bitmap
  166.         int iIndent = 4;
  167.  
  168.         m_pIImageMap->DrawImage( idxImage, iIndent, rcItem.top, hDC, FALSE );
  169.  
  170.         //Draw the text
  171.         LPCTSTR name = (LPCTSTR) MSG_GetHostUIName(pServer);
  172.  
  173.         int iWidth = rcTemp.right - rcTemp.left;
  174.  
  175.         rcTemp = rcItem;
  176.         rcText = rcItem;
  177.         rcTemp.left = iIndent + 20;
  178.         rcTemp.right = rcTemp.left + iWidth + 4;
  179.  
  180.         VERIFY(::FillRect( hDC, &rcTemp, hBrushFill ));
  181.         rcText.left = rcTemp.left + 2;
  182.         rcText.right = rcTemp.right - 2;
  183.         ::DrawText( hDC, name, -1, &rcText, DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX );
  184.  
  185.         //Draw the focus
  186.         if ( lpDrawItemStruct->itemAction & ODA_FOCUS && 
  187.              lpDrawItemStruct->itemState & ODS_SELECTED )
  188.         {
  189.             ::DrawFocusRect( hDC, &rcItem);
  190.         }    
  191.     }
  192.  
  193.     if ( hBrushHigh ) 
  194.         VERIFY( ::DeleteObject( hBrushHigh ));
  195.     if ( hBrushWindow ) 
  196.         VERIFY( ::DeleteObject( hBrushWindow ));
  197.  
  198.     if ( hOldFont )
  199.         ::SelectObject( hDC, hOldFont );
  200. }
  201.  
  202. BEGIN_MESSAGE_MAP( CServersCombo, CComboBox )
  203. END_MESSAGE_MAP()
  204.  
  205. /////////////////////////////////////////////////////////////////////////////
  206. // CSubscribeCX
  207. CSubscribeCX::CSubscribeCX(CNetscapePropertySheet *pSheet)  
  208. : CStubsCX(NewsCX, MWContextNews)
  209. {
  210.     m_pSheet = (CSubscribePropertySheet*)pSheet;
  211.     m_lPercent = 0;
  212.     m_bAnimated = FALSE;
  213. }
  214.  
  215. void CSubscribeCX::SetProgressBarPercent(MWContext *pContext, int32 lPercent )  
  216. {
  217.     //    Ensure the safety of the value.
  218.  
  219.     lPercent = lPercent < 0 ? 0 : ( lPercent > 100 ? 100 : lPercent );
  220.  
  221.     if ( m_lPercent == lPercent )  
  222.         return;
  223.  
  224.     m_lPercent = lPercent;
  225.     if (m_pSheet)  
  226.         m_pSheet->SetProgressBarPercent(lPercent);
  227. }
  228.  
  229. void CSubscribeCX::Progress(MWContext *pContext, const char *pMessage)
  230. {
  231.     m_csProgress = pMessage;
  232.     if (m_pSheet)  
  233.         m_pSheet->SetStatusText(pMessage);
  234. }
  235.  
  236. int32 CSubscribeCX::QueryProgressPercent()    
  237. {
  238.     return m_lPercent;
  239. }
  240.  
  241. void CSubscribeCX::AllConnectionsComplete(MWContext *pContext)    
  242. {
  243.     //  Call the base.
  244.     CStubsCX::AllConnectionsComplete(pContext);
  245.  
  246.     //    Also, we can clear the progress bar now.
  247.     m_lPercent = 0;
  248.     if ( m_pSheet ) 
  249.     {
  250.         m_pSheet->SetProgressBarPercent(m_lPercent);
  251.         m_pSheet->AllConnectionsComplete(pContext);
  252.     }
  253. #ifdef _WIN32
  254.     if (m_pSheet) 
  255.     {
  256.         m_pSheet->SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  257.         m_pSheet->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  258.     }
  259. #endif
  260. }
  261.  
  262. void CSubscribeCX::UpdateStopState( MWContext *pContext )
  263. {
  264. #ifdef _WIN32
  265.     if (m_pSheet) 
  266.     {
  267.         m_pSheet->SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  268.         m_pSheet->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  269.     }
  270. #endif
  271. }
  272.  
  273. /////////////////////////////////////////////////////////////////////////////
  274. // CSubscribeList
  275. STDMETHODIMP CSubscribeList::QueryInterface(REFIID refiid, LPVOID * ppv)
  276. {
  277.     *ppv = NULL;
  278.     if (IsEqualIID(refiid,IID_IUnknown))
  279.            *ppv = (LPUNKNOWN) this;
  280.     else if (IsEqualIID(refiid,IID_IMsgList))
  281.            *ppv = (LPMSGLIST) this;
  282.  
  283.     if (*ppv != NULL) {
  284.            ((LPUNKNOWN) *ppv)->AddRef();
  285.         return NOERROR;
  286.     }
  287.             
  288.     return ResultFromScode(E_NOINTERFACE);
  289. }
  290.  
  291. STDMETHODIMP_(ULONG) CSubscribeList::AddRef(void)
  292. {
  293.     return ++m_ulRefCount;
  294. }
  295.  
  296. STDMETHODIMP_(ULONG) CSubscribeList::Release(void)
  297. {
  298.     ULONG ulRef;
  299.     ulRef = --m_ulRefCount;
  300.     if (m_ulRefCount == 0) 
  301.         delete this;       
  302.     return ulRef;       
  303. }
  304.  
  305. void CSubscribeList::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  306.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  307.                                        int32 num)
  308. {
  309.     if (m_pSubscribePage) 
  310.         m_pSubscribePage->ListChangeStarting( pane, asynchronous,
  311.                                                  notify, where, num );
  312. }
  313.  
  314. void CSubscribeList::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  315.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  316.                                        int32 num)
  317. {
  318.     if (m_pSubscribePage) 
  319.         m_pSubscribePage->ListChangeFinished( pane, asynchronous,
  320.                                                  notify, where, num );
  321. }
  322.  
  323. void CSubscribeList::GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  324.                                 int *focus)
  325. {
  326. }
  327.  
  328. void CSubscribeList::SelectItem( MSG_Pane* pane, int item )
  329. {
  330. }
  331.  
  332. /////////////////////////////////////////////////////////////////////////////
  333. // CNewsgroupsOutlinerParent
  334.  
  335. BEGIN_MESSAGE_MAP(CNewsgroupsOutlinerParent, COutlinerParent)
  336. END_MESSAGE_MAP()
  337.  
  338. CNewsgroupsOutlinerParent::CNewsgroupsOutlinerParent()
  339. {
  340. }
  341.  
  342.  
  343. CNewsgroupsOutlinerParent::~CNewsgroupsOutlinerParent()
  344. {
  345.  
  346. }
  347.  
  348. // Draw Column text and Sort indicator
  349. BOOL CNewsgroupsOutlinerParent::RenderData (int idColumn, CRect & rect, CDC &dc, const char * text)
  350. {
  351.     CNewsgroupsOutliner* pOutliner = (CNewsgroupsOutliner*) m_pOutliner;
  352.  
  353.     // Draw Text String
  354.     if (idColumn == ID_COLNEWS_SUBSCRIBE)
  355.         dc.DrawText(text,  _tcslen(text), &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  356.     else
  357.         dc.DrawText(text,  _tcslen(text), &rect, DT_SINGLELINE | DT_VCENTER);
  358.  
  359.     // Draw Sort Indicator
  360.     MSG_COMMAND_CHECK_STATE sortType = 
  361.         pOutliner->m_attribSortBy == idColumn ? MSG_Checked : MSG_Unchecked;
  362.  
  363.     int idxImage = pOutliner->m_bSortAscending ? IDX_SORTINDICATORDOWN : IDX_SORTINDICATORUP;
  364.     CSize cs = dc.GetTextExtent(text, _tcslen(text));
  365.  
  366.     if (idColumn == pOutliner->m_attribSortBy && cs.cx + 22 <= rect.Width()) {
  367.         m_pIImage->DrawTransImage( idxImage,
  368.                                    rect.left + 8 + cs.cx,
  369.                                    (rect.top + rect.bottom) / 2 - 4,
  370.                                    &dc );
  371.     }
  372.  
  373.     return TRUE;
  374. }
  375.  
  376.  
  377. COutliner * CNewsgroupsOutlinerParent::GetOutliner ( void )
  378. {
  379.     return new CNewsgroupsOutliner;
  380. }
  381.  
  382. void CNewsgroupsOutlinerParent::CreateColumns ( void )
  383. {
  384.     CString text, newName; 
  385.     CRect colRect;
  386.     int col1, col2, col3, nPos;
  387.     int pos1, pos2, pos3;
  388.  
  389.     if (m_pSheet->nameWidth == -1)
  390.     {
  391.         CDC* pDC = GetDC();
  392.         text.LoadString(IDS_SUBSCRIBE);
  393.         CSize textSize = pDC->GetTextExtent(LPCTSTR(text), text.GetLength());
  394.         ReleaseDC(pDC);
  395.              
  396.         GetClientRect(colRect);     
  397.         col2 = textSize.cx + 10;
  398.         col3 = col2;
  399.         int nScrollWidth = ::GetSystemMetrics(SM_CXVSCROLL);
  400.         col1 = (colRect.right - colRect.left - nScrollWidth) - (col2 + col3);
  401.         m_pSheet->nameWidth = col1;
  402.         m_pSheet->subscribeWidth  = col2;
  403.         m_pSheet->postWidth = col3;
  404.         m_pSheet->namePos = 0;
  405.         m_pSheet->subscribePos = 1;
  406.         m_pSheet->postPos = 2;
  407.     }
  408.     else
  409.     {
  410.         col1 = m_pSheet->nameWidth;
  411.         col2 = m_pSheet->subscribeWidth;
  412.         col3 = m_pSheet->postWidth;
  413.         pos1 = m_pSheet->namePos;
  414.         pos2 = m_pSheet->subscribePos;
  415.         pos3 = m_pSheet->postPos;
  416.     }
  417.  
  418.     text.LoadString(IDS_NEWSGROUP_NAME);
  419.     m_pOutliner->AddColumn (text, ID_COLNEWS_NAME,        col1, colRect.right, 
  420.                             ColumnVariable, col1, FALSE);
  421.     text.LoadString(IDS_SUBSCRIBE);    
  422.     nPos = text.Find('&');
  423.     if (nPos >= 0)
  424.         newName = text.Left(nPos) + text.Right(text.GetLength() - nPos - 1);
  425.     else
  426.         newName = text;    
  427.     m_pOutliner->AddColumn (newName, ID_COLNEWS_SUBSCRIBE,    col2, colRect.right, 
  428.                             ColumnVariable, col2, FALSE);
  429.     text.LoadString(IDS_POSTINGS);
  430.     m_pOutliner->AddColumn (text, ID_COLNEWS_POSTINGS,    col3, colRect.right, 
  431.                             ColumnVariable, col3, FALSE); 
  432.  
  433.     m_pOutliner->SetColumnPos( ID_COLNEWS_NAME, pos1 );
  434.     m_pOutliner->SetColumnPos( ID_COLNEWS_SUBSCRIBE, pos2 );
  435.     m_pOutliner->SetColumnPos( ID_COLNEWS_POSTINGS, pos3 );
  436.  
  437.     m_pOutliner->SetImageColumn( ID_COLNEWS_NAME );
  438. }
  439.  
  440. //////////////////////////////////////////////////////////////////////////////
  441. // CNewsgroupsOutliner
  442.  
  443. CNewsgroupsOutliner::CNewsgroupsOutliner()
  444. {
  445.     ApiApiPtr(api);
  446.     m_pUnkUserImage = api->CreateClassInstance(APICLASS_IMAGEMAP);
  447.     if (m_pUnkUserImage) {
  448.         m_pUnkUserImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIUserImage);
  449.         ASSERT(m_pIUserImage);
  450.         m_pIUserImage->Initialize(IDB_MAILNEWS,16,16);
  451.     }
  452.  
  453.     m_pAncestor = NULL;
  454.     m_pszExtraText = new char[256];
  455.     m_pPage = NULL;
  456. }
  457.  
  458. CNewsgroupsOutliner::~CNewsgroupsOutliner ( )
  459. {
  460.     if (m_pUnkUserImage) {
  461.         if (m_pIUserImage)
  462.             m_pUnkUserImage->Release();
  463.     }
  464.  
  465.     delete [] m_pAncestor;
  466.     delete [] m_pszExtraText;
  467. }
  468.  
  469. int CNewsgroupsOutliner::GetDepth( int iLine )
  470. {
  471.     MSG_GroupNameLine groupLine;
  472.     MSG_GetGroupNameLineByIndex(m_pPane, (MSG_ViewIndex) iLine, 1, &groupLine );
  473.  
  474.     return groupLine.level;
  475. }
  476.  
  477. int CNewsgroupsOutliner::GetNumChildren( int iLine )
  478. {
  479.     MSG_GroupNameLine groupLine;
  480.     MSG_GetGroupNameLineByIndex(m_pPane, (MSG_ViewIndex) iLine, 1, &groupLine );
  481.  
  482.     return groupLine.flags & MSG_GROUPNAME_FLAG_HASCHILDREN ? 1 : 0;
  483. }
  484.  
  485. BOOL CNewsgroupsOutliner::IsCollapsed( int iLine )
  486. {
  487.     MSG_GroupNameLine groupLine;
  488.     MSG_GetGroupNameLineByIndex(m_pPane, (MSG_ViewIndex) iLine, 1, &groupLine );
  489.  
  490.     return (groupLine.flags & MSG_GROUPNAME_FLAG_ELIDED) ? TRUE : FALSE;
  491. }
  492.  
  493. BOOL CNewsgroupsOutliner::RenderData(UINT iColumn, CRect &rect, CDC &dc, const char * text )
  494. {
  495.     if (iColumn != ID_COLNEWS_SUBSCRIBE)
  496.         return FALSE;
  497.  
  498.     MSG_Host* pHost = ((CSubscribePropertySheet*)(GetPage()->GetParent()))->GetHost();
  499.     if ((m_GroupLine.flags & MSG_GROUPNAME_FLAG_HASCHILDREN) && MSG_IsNewsHost(pHost))
  500.         return TRUE;
  501.  
  502.     int idxImage = -1;
  503.  
  504.     if (m_GroupLine.flags & MSG_GROUPNAME_FLAG_SUBSCRIBED) 
  505.         idxImage = IDX_CHECKMARK; 
  506.     else
  507.         idxImage = IDX_CHECKBOX; 
  508.  
  509.     m_pIUserImage->DrawImage(idxImage, rect.left + ( ( rect.Width ( ) - 16 ) / 2 ),
  510.                              rect.top, &dc, FALSE);
  511.     return TRUE;
  512. }
  513.  
  514.  
  515. int CNewsgroupsOutliner::TranslateIcon(void * pLineData)
  516. {
  517.     ASSERT(pLineData);
  518.     MSG_GroupNameLine *pGroup = (MSG_GroupNameLine*)pLineData;
  519.     if (pGroup->flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  520.     {
  521.         if (pGroup->flags & MSG_GROUPNAME_FLAG_ELIDED) 
  522.             return IDX_MAILFOLDERCLOSED;
  523.         else 
  524.             return IDX_MAILFOLDEROPEN;
  525.     }
  526.     else 
  527.     {
  528.         if (pGroup->flags & MSG_GROUPNAME_FLAG_NEW_GROUP) 
  529.             return IDX_NEWSNEW; 
  530.         else
  531.             return IDX_NEWSGROUP; 
  532.     }
  533. }
  534.  
  535. int CNewsgroupsOutliner::TranslateIconFolder (void * pData)
  536. {
  537.     ASSERT(pData);
  538.  
  539.     MSG_GroupNameLine *pGroup = (MSG_GroupNameLine*)pData;
  540.     
  541.     if (pGroup->flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  542.     {
  543.         if (pGroup->flags & MSG_GROUPNAME_FLAG_ELIDED) 
  544.             return(OUTLINER_CLOSEDFOLDER);  
  545.         else 
  546.             return(OUTLINER_OPENFOLDER);
  547.     }
  548.     return (OUTLINER_ITEM);
  549. }
  550.  
  551. BOOL CNewsgroupsOutliner::ColumnCommand(int iColumn, int iLine)
  552. {
  553.     if (iColumn == ID_COLNEWS_SUBSCRIBE)
  554.     {
  555.         MSG_ViewIndex indices;
  556.         indices = (MSG_ViewIndex)iLine;
  557.         MSG_Command(GetPane(), MSG_ToggleSubscribed, &indices, 1);
  558.     }
  559.     return FALSE;
  560. }
  561.  
  562.  
  563. void* CNewsgroupsOutliner::AcquireLineData(int line)
  564. {
  565.     MSG_Pane *pPane = GetPane();
  566.     if (pPane && m_pPage)
  567.     {
  568.         if (MSG_SubscribeGetMode(pPane) != m_pPage->GetMode())
  569.             return NULL;
  570.     }
  571.     else
  572.         return NULL;
  573.     
  574.     delete [] m_pAncestor;
  575.     m_pAncestor = NULL;
  576.  
  577.     m_pszExtraText[ 0 ] = '\0';
  578.     if ( line >= m_iTotalLines)
  579.         return NULL;
  580.  
  581.     if ( !MSG_GetGroupNameLineByIndex(m_pPane, line, 1, &m_GroupLine ))
  582.         return NULL;
  583.  
  584.     return &m_GroupLine;
  585. }
  586.  
  587.  
  588. void CNewsgroupsOutliner::GetTreeInfo( int iLine, uint32 * pFlags, int* pDepth, 
  589.                                        OutlinerAncestorInfo** pAncestor)
  590. {
  591.     delete [] m_pAncestor;
  592.     m_pAncestor = NULL;
  593.  
  594.     MSG_GroupNameLine groupLine;
  595.     MSG_GetGroupNameLineByIndex(m_pPane, (MSG_ViewIndex) iLine, 1, &groupLine );
  596.  
  597.     if ( pAncestor ) {
  598.         m_pAncestor = new OutlinerAncestorInfo[groupLine.level + 1];
  599.  
  600.         int i = groupLine.level;
  601.         int idx = iLine + 1;
  602.         while ( i > 0 ) {
  603.             if ( idx < m_iTotalLines ) {
  604.                 MSG_GroupNameLine groupLine;
  605.                 MSG_GetGroupNameLineByIndex( m_pPane, idx, 1, &groupLine );
  606.                 if ( groupLine.level == i ) {
  607.                     m_pAncestor[i].has_prev = TRUE;
  608.                     m_pAncestor[i].has_next = TRUE;
  609.                     i--;
  610.                     idx++;
  611.                 } else if ( groupLine.level < i ) {
  612.                     m_pAncestor[i].has_prev = FALSE;
  613.                     m_pAncestor[i].has_next = FALSE;
  614.                     i--;
  615.                 } else {
  616.                     idx++;
  617.                 }
  618.             } else {
  619.                 m_pAncestor[i].has_prev = FALSE;
  620.                 m_pAncestor[i].has_next = FALSE;
  621.                 i--;
  622.             }
  623.         }
  624.         m_pAncestor[i].has_prev = FALSE;
  625.         m_pAncestor[i].has_next = FALSE;
  626.  
  627.         *pAncestor = m_pAncestor;
  628.     }
  629.  
  630.     if ( pFlags ) *pFlags = groupLine.flags;
  631.     if ( pDepth ) *pDepth = groupLine.level;// do not -1 
  632. }
  633.  
  634.  
  635. void CNewsgroupsOutliner::ReleaseLineData(void *)
  636. {
  637.     delete [] m_pAncestor;
  638.     m_pAncestor = NULL;
  639. }
  640.  
  641.  
  642. LPCTSTR CNewsgroupsOutliner::GetColumnText(UINT iColumn, void* pLineData)
  643. {
  644.     MSG_GroupNameLine* pGroup = (MSG_GroupNameLine*)pLineData;
  645.  
  646.     memset(m_pszExtraText, '\0',  256);
  647.     switch (iColumn) 
  648.     {
  649.         case ID_COLNEWS_NAME:
  650.             strncpy(m_pszExtraText, pGroup->name, strlen(pGroup->name));
  651.             break;
  652.         case ID_COLNEWS_POSTINGS:
  653.             if (pGroup->total >= 0) {
  654.                 sprintf(m_pszExtraText, "%ld", pGroup->total);
  655.             }
  656.             break;
  657.         default:
  658.             break;
  659.     } 
  660.     return m_pszExtraText;
  661. }                                                                    
  662.  
  663. void CNewsgroupsOutliner::OnSelChanged()
  664. {
  665.     if (!GetPage())
  666.         return;
  667.     if (GetPage()->m_bFromTyping)
  668.     {
  669.         GetPage()->m_bFromTyping = FALSE;
  670.         return;
  671.     }
  672.     MSG_GroupNameLine group;
  673.  
  674.     MSG_ViewIndex *indices;
  675.     int count;
  676.  
  677.     GetSelection( indices, count );
  678.     if ( count == 1 && MSG_GetGroupNameLineByIndex(m_pPane, indices[0], 1, &group))
  679.         GetPage()->DoSelChanged(&group);
  680. }
  681.  
  682. void CNewsgroupsOutliner::OnSelDblClk()
  683. {
  684.     MSG_ViewIndex *indices;
  685.     int count;
  686.     MSG_GroupNameLine group;
  687.  
  688.     GetSelection( indices, count );
  689.     if ( count == 1 && MSG_GetGroupNameLineByIndex(m_pPane, indices[0], 1, &group))
  690.     {
  691.         if (group.flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  692.             ToggleExpansion(indices[0]);
  693.         else
  694.             MSG_Command(GetPane(), MSG_ToggleSubscribed, &indices[0], 1);
  695.     }
  696. }
  697.  
  698. int CNewsgroupsOutliner::ToggleExpansion(int iLine)
  699. {
  700.     int count;
  701.     MSG_ViewIndex *indices;
  702.     MSG_GroupNameLine group;
  703.  
  704.     int nResult = CMailNewsOutliner::ToggleExpansion(iLine);
  705.  
  706.     GetSelection(indices, count);
  707.  
  708.     if (indices[0] == iLine && 
  709.         MSG_GetGroupNameLineByIndex(m_pPane, iLine, 1, &group) &&
  710.         GetPage()->GetMode() == MSG_SubscribeAll)
  711.     {
  712.         if (group.flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  713.         {
  714.             if (group.flags & MSG_GROUPNAME_FLAG_ELIDED) 
  715.                 GetPage()->GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(TRUE);  
  716.             else 
  717.                 GetPage()->GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  718.         }
  719.         else
  720.         {
  721.             GetPage()->GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  722.         }
  723.     }
  724.     return nResult;
  725. }
  726.  
  727. // for select the first item in the outliner,
  728. // so user can tab through
  729. BOOL CNewsgroupsOutliner::SelectInitialItem()
  730. {
  731.     int count;
  732.     MSG_ViewIndex *indices;
  733.     GetSelection( indices, count );
  734.  
  735.     if (GetPage() && GetPage()->m_bFromTyping)
  736.         return TRUE;
  737.  
  738.     if (GetTotalLines() && !count )
  739.     {
  740.         SelectItem(0);
  741.         InvalidateLine(0); 
  742.         return TRUE;
  743.     }
  744.     if (count)
  745.         return TRUE;
  746.     return FALSE;
  747. }
  748.  
  749. /////////////////////////////////////////////////////////////////////////////
  750. // CSubscribePropertyPage
  751.  
  752. CSubscribePropertyPage::CSubscribePropertyPage(CWnd *pParent,
  753.     MWContext *pContext, MSG_SubscribeMode nMode, UINT nID)
  754.     : CNetscapePropertyPage(nID)
  755. {
  756.     m_pParent = (CSubscribePropertySheet*)pParent;
  757.     m_bActivated = FALSE;
  758.     m_bSelChanged = FALSE;
  759.     m_bNotifyAll = FALSE;
  760.     m_bInitDialog = FALSE;
  761.     m_bFromTyping = FALSE;
  762.     m_bDoShowWindow = TRUE;
  763.     m_nMode = nMode;
  764.     m_uTimer = 0;
  765.  
  766.     m_hNewsHost = NULL;
  767.     m_pOutliner = NULL;
  768.  
  769.     m_bProcessGetDeletion = FALSE;
  770.     m_bListChangeStarting = FALSE;
  771. }
  772.  
  773. CSubscribePropertyPage::~CSubscribePropertyPage()
  774. {
  775.     if (m_hNewsHost)
  776.         delete [] m_hNewsHost;
  777.     m_hNewsHost = NULL;
  778. }
  779.  
  780. MWContext* CSubscribePropertyPage::GetContext()
  781. {
  782.     CSubscribePropertySheet* pSheet = (CSubscribePropertySheet*)GetParent();
  783.     CSubscribeCX*  pCX = pSheet->GetSubscribeContext();
  784.     if (pCX)
  785.         return pCX->GetContext();
  786.     else
  787.         return NULL;
  788. }
  789.  
  790. CSubscribeCX * CSubscribePropertyPage::GetSubscribeContext() 
  791.     { return ((CSubscribePropertySheet*)GetParent())->GetSubscribeContext(); }
  792.  
  793. MSG_Pane * CSubscribePropertyPage::GetPane() 
  794.     { return ((CSubscribePropertySheet*)GetParent())->GetSubscribePane(); }
  795.  
  796. CSubscribeList*  CSubscribePropertyPage::GetList()          
  797.     { return ((CSubscribePropertySheet*)GetParent())->GetSubscribeList(); }
  798.  
  799. CSubscribeList**  CSubscribePropertyPage::GetListHandle()          
  800.     { return ((CSubscribePropertySheet*)GetParent())->GetSubscribeHandle(); }
  801.  
  802. void CSubscribePropertyPage::SetSubscribeContext(CSubscribeCX *pCX)  
  803.     { ((CSubscribePropertySheet*)GetParent())->SetSubscribeContext(pCX); }
  804.  
  805. void CSubscribePropertyPage::SetPane(MSG_Pane *pPane)  
  806.     { ((CSubscribePropertySheet*)GetParent())->SetSubscribePane(pPane); }
  807.  
  808. void CSubscribePropertyPage::SetList(CSubscribeList* pList) 
  809.     { ((CSubscribePropertySheet*)GetParent())->SetSubscribeList(pList); }
  810.  
  811. BOOL CSubscribePropertyPage::IsOutlinerHasFocus()
  812. {
  813.     if (GetFocus() == m_pOutliner)
  814.         return TRUE;
  815.     else
  816.         return FALSE;
  817. }
  818.  
  819.  
  820. static void
  821. DoFetchGroups(MSG_Pane* pane, void* closure)
  822. {
  823.     CSubscribePropertySheet* tmp = (CSubscribePropertySheet*) closure;
  824.     tmp->GetAllGroupPage()->OnGetDeletions();
  825. }
  826.  
  827. static void
  828. DoEnableAllControls(MSG_Pane* pane, void* closure)
  829. {
  830.     CSubscribePropertySheet* tmp = (CSubscribePropertySheet*) closure;
  831.     if (tmp->GetAllGroupPage()->m_bProcessGetDeletion)
  832.     {
  833.         tmp->GetAllGroupPage()->m_bProcessGetDeletion = FALSE;
  834.         tmp->GetAllGroupPage()->EnableAllControls(TRUE);
  835.     }
  836.  
  837.     CNewsgroupsOutliner* pOutliner = tmp->GetAllGroupPage()->GetOutliner();
  838.     if (pOutliner)
  839.         pOutliner->SelectInitialItem();
  840. }
  841.  
  842. static MSG_SubscribeCallbacks CallbackStruct = {
  843.     DoFetchGroups,
  844.     DoEnableAllControls            
  845. };
  846.  
  847.  
  848. BOOL CSubscribePropertyPage::OnInitDialog()
  849. {
  850.     BOOL ret = CNetscapePropertyPage::OnInitDialog();
  851.  
  852.     m_ServerCombo.SubclassDlgItem( IDC_COMBO_SERVER, this );
  853.  
  854.     m_bInitDialog = TRUE;
  855.  
  856.       CRect winRect, ctlRect;
  857.     GetDlgItem(IDC_NEWSGROUPS)->ShowWindow( SW_HIDE );
  858.     GetDlgItem(IDC_NEWSGROUPS)->GetWindowRect(ctlRect);
  859.     GetWindowRect(winRect);
  860.     ctlRect.OffsetRect(-winRect.left, -winRect.top);
  861.     ctlRect.InflateRect(-1, -1);
  862.  
  863. #ifdef _WIN32
  864.     m_OutlinerParent.CreateEx ( WS_EX_CLIENTEDGE, NULL, _T("NSOutlinerParent"), 
  865.                             WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_TABSTOP,
  866.                             ctlRect.left, ctlRect.top, 
  867.                             ctlRect.right - ctlRect.left, ctlRect.bottom - ctlRect.top,
  868.                             this->m_hWnd, NULL);
  869. #else
  870.     m_OutlinerParent.Create( NULL, _T("NSOutlinerParent"), 
  871.                              WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_TABSTOP,
  872.                              ctlRect, this, NULL);
  873. #endif
  874.  
  875.     m_OutlinerParent.SetPropertySheet(m_pParent);
  876.     m_OutlinerParent.CreateColumns();
  877.     m_pOutliner = (CNewsgroupsOutliner *) m_OutlinerParent.m_pOutliner;
  878.     m_pOutliner->SetPage(this);
  879.  
  880.     if (m_nMode != MSG_SubscribeNew)
  881.     {
  882.     #ifdef _WIN32
  883.         ((CEdit*)GetDlgItem(IDC_EDIT_NEWSGROUP))->SetLimitText(MSG_MAXGROUPNAMELENGTH - 1);
  884.     #else
  885.         ((CEdit*)GetDlgItem(IDC_EDIT_NEWSGROUP))->LimitText(MSG_MAXGROUPNAMELENGTH - 1);
  886.     #endif
  887.     }
  888.     if (m_pOutliner)
  889.         m_pOutliner->SelectInitialItem();
  890.     return ret;
  891. }
  892.  
  893. void CSubscribePropertyPage::OnShowWindow(BOOL bShow, UINT nStatus)
  894. {
  895.     if (bShow)
  896.     {   
  897.         if (m_uTimer == 0)
  898.             m_uTimer = SetTimer(SUBSCRIBE_VISIBLE_TIMER, 100, NULL);
  899.         if (m_uTimer)
  900.             m_bDoShowWindow = TRUE;
  901.         else   
  902.         {
  903.             if (!InitSubscribePage())
  904.                 m_pParent->EndDialog(IDCANCEL);
  905.         }
  906.     }
  907. }
  908.  
  909. BOOL CSubscribePropertyPage::InitSubscribePage()
  910. {
  911.     BOOL result = TRUE;
  912.  
  913.     if (m_bInitDialog)
  914.     {
  915.         m_bInitDialog = FALSE;
  916.         result = CreateSubscribePage();
  917.     }
  918.     if (result && GetPane() &&
  919.         m_nMode != MSG_SubscribeGetMode(GetPane()))
  920.     {
  921.         MSG_SubscribeSetMode(GetPane(), m_nMode); 
  922.         if (GetList())
  923.             GetList()->SetSubscribePage(this);
  924.         m_pOutliner->SetPane(GetPane());
  925.     }
  926.     return result;
  927. }
  928.  
  929. BOOL CSubscribePropertyPage::CreateSubscribePage()
  930. {
  931.     MSG_Master * pMaster = WFE_MSGGetMaster();
  932.  
  933.     SetNewsHosts(pMaster);
  934.  
  935.     //create CSubscribePane for subscribe newsgroup
  936.     MSG_Pane* pPane = GetPane();
  937.     if (pPane == NULL)
  938.     {
  939.         CSubscribeCX* pCX = new CSubscribeCX(m_pParent);
  940.  
  941.         pCX->GetContext()->fancyFTP = TRUE;
  942.         pCX->GetContext()->fancyNews = TRUE;
  943.         pCX->GetContext()->intrupt = FALSE;
  944.         pCX->GetContext()->reSize = FALSE;
  945.         pCX->GetContext()->type = MWContextNews;
  946.         SetSubscribeContext(pCX);
  947.  
  948.         MSG_Host *pCurrentHost = ((CSubscribePropertySheet*)GetParent())->GetHost();
  949.          pPane = MSG_CreateSubscribePaneForHost(pCX->GetContext(), pMaster, pCurrentHost);
  950.  
  951.         if (!pPane)
  952.             return FALSE;
  953.  
  954.         ((CSubscribePropertySheet*)GetParent())->SetSubscribePane(pPane);
  955.         if (m_pOutliner)
  956.             m_pOutliner->SetPane(pPane);
  957.  
  958.         //use  CSubscribeList to hook up with the backend
  959.         CSubscribeList *pInstance = new CSubscribeList(this);
  960.         SetList(pInstance);
  961.         CSubscribeList** hList = GetListHandle();
  962.         pInstance->QueryInterface(IID_IMsgList, (LPVOID *)hList);
  963.         MSG_SetFEData((MSG_Pane*)pPane, (void *)pInstance);
  964.  
  965.         if (GetList())
  966.             GetList()->SetSubscribePage(this);
  967.  
  968.         MSG_SubscribeSetCallbacks(pPane, &CallbackStruct, GetParent());
  969.  
  970.     }
  971.  
  972.     return TRUE;
  973.  
  974. }
  975.  
  976. void CSubscribePropertyPage::SetNewsHosts(MSG_Master* pMaster)
  977. {
  978.     int nDefaultHost = 0;
  979.     MSG_Host *pNewsHost = NULL;
  980.  
  981.     int32 nTotal =  MSG_GetSubscribingHosts(pMaster, NULL, 0);
  982.     if (nTotal)
  983.     {
  984.         m_hNewsHost = new MSG_Host* [nTotal];
  985.         MSG_GetSubscribingHosts(pMaster, m_hNewsHost, nTotal);
  986.         for (int i = 0; i < nTotal; i++)
  987.         {
  988.             int addedIndex = GetServerCombo()->AddString(MSG_GetHostUIName(m_hNewsHost[i]));
  989.             if (addedIndex != CB_ERR)
  990.             {
  991.                 GetServerCombo()->SetItemDataPtr(addedIndex, m_hNewsHost[i]);
  992.             }
  993.         }
  994.         MSG_Host *pCurrentHost = ((CSubscribePropertySheet*)GetParent())->GetHost();
  995.         if (pCurrentHost)
  996.         {
  997.             for (i = 0; i < nTotal; i++)
  998.             {
  999.                 pNewsHost = (MSG_Host *) GetServerCombo()->GetItemDataPtr(i);
  1000.                 if (pNewsHost == pCurrentHost)
  1001.                 {
  1002.                     nDefaultHost = i;
  1003.                     break;
  1004.                 }
  1005.             }
  1006.         }
  1007.         else
  1008.         {
  1009.             MSG_Host* pDefhost = MSG_GetMSGHostFromNewsHost(MSG_GetDefaultNewsHost(pMaster));
  1010.             for (i = 0; i < nTotal; i++)
  1011.             {
  1012.                 pNewsHost = (MSG_Host *) GetServerCombo()->GetItemDataPtr(i);
  1013.                 if     (pDefhost == pNewsHost)
  1014.                 {
  1015.                     nDefaultHost = i;
  1016.                     ((CSubscribePropertySheet*)GetParent())->SetHost(pNewsHost);
  1017.                     break;
  1018.                 }
  1019.             }
  1020.         }
  1021.         GetServerCombo()->SetCurSel(i);
  1022.         if (pNewsHost && MSG_IsIMAPHost(pNewsHost))
  1023.             m_pParent->EnableNonImapPages(FALSE);
  1024.     }
  1025. }
  1026.  
  1027. BOOL CSubscribePropertyPage::OnSetActive()
  1028. {
  1029.     if(!CNetscapePropertyPage::OnSetActive())
  1030.         return(FALSE);
  1031.  
  1032.     if(!m_bActivated)
  1033.         m_bActivated = TRUE;
  1034.  
  1035.     if (m_pParent)  
  1036.         m_pParent->SetStatusText("");
  1037.  
  1038.     if (GetOutliner())
  1039.     {
  1040.         GetOutliner()->SetColumnSize(ID_COLNEWS_NAME, m_pParent->nameWidth);
  1041.         GetOutliner()->SetColumnSize(ID_COLNEWS_SUBSCRIBE, m_pParent->subscribeWidth);
  1042.         GetOutliner()->SetColumnSize(ID_COLNEWS_POSTINGS, m_pParent->postWidth);
  1043.         GetOutliner()->SetColumnPos(ID_COLNEWS_NAME, m_pParent->namePos);
  1044.         GetOutliner()->SetColumnPos(ID_COLNEWS_SUBSCRIBE, m_pParent->subscribePos);
  1045.         GetOutliner()->SetColumnPos(ID_COLNEWS_POSTINGS, m_pParent->postPos);
  1046.     }
  1047.  
  1048.     ClearNewsgroupSelection();
  1049.     //set news host
  1050.     int nSelection = GetServerCombo()->GetCurSel();
  1051.     MSG_Host *pSelHost = (MSG_Host *)GetServerCombo()->GetItemDataPtr(nSelection);
  1052.     MSG_Host *pCurrentHost = ((CSubscribePropertySheet*)GetParent())->GetHost();
  1053.     if (pSelHost !=  pCurrentHost)    //not the current selected server
  1054.     {
  1055.         int nNewIndex = 0;
  1056.         int nTotal = GetServerCombo()->GetCount();
  1057.         for (int i = 0; i < nTotal; i++)
  1058.         {
  1059.             MSG_Host *pNewsHost = (MSG_Host *)GetServerCombo()->GetItemDataPtr(i);
  1060.             if (pNewsHost == pCurrentHost)
  1061.             {
  1062.                 nNewIndex = i;
  1063.                 break;
  1064.             }
  1065.         }
  1066.         // the checking id for if can't fiind a match and nSelection != nNewIndex
  1067.         if (nNewIndex != nSelection)  
  1068.             GetServerCombo()->SetCurSel(nNewIndex);
  1069.     }
  1070.  
  1071.     if (GetOutliner())
  1072.     {
  1073.         if (GetOutliner()->SelectInitialItem())
  1074.         {
  1075.             int count;
  1076.             MSG_ViewIndex *indices;
  1077.             MSG_GroupNameLine group;
  1078.  
  1079.             GetOutliner()->GetSelection( indices, count );
  1080.             if (MSG_GetGroupNameLineByIndex(GetPane(), indices[0], 1, &group))
  1081.                 CheckSubscribeButton(&group);
  1082.         }
  1083.         if (m_nMode == MSG_SubscribeNew)
  1084.         {
  1085.             if (GetOutliner()->GetTotalLines())
  1086.                 GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(TRUE);
  1087.             else
  1088.                 GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(FALSE);
  1089.         }
  1090.     }
  1091.  
  1092.     return(TRUE);
  1093. }
  1094.  
  1095. BOOL CSubscribePropertyPage::OnKillActive()
  1096. {
  1097.     m_pParent->nameWidth = GetOutliner()->GetColumnSize(ID_COLNEWS_NAME);
  1098.     m_pParent->subscribeWidth = GetOutliner()->GetColumnSize(ID_COLNEWS_SUBSCRIBE);
  1099.     m_pParent->postWidth = GetOutliner()->GetColumnSize(ID_COLNEWS_POSTINGS);
  1100.     m_pParent->namePos = GetOutliner()->GetColumnPos(ID_COLNEWS_NAME);
  1101.     m_pParent->subscribePos = GetOutliner()->GetColumnPos(ID_COLNEWS_SUBSCRIBE);
  1102.     m_pParent->postPos = GetOutliner()->GetColumnPos(ID_COLNEWS_POSTINGS);
  1103.  
  1104.     ShowWindow(SW_HIDE); // Hide window to prevent flash list
  1105.  
  1106.     return CNetscapePropertyPage::OnKillActive();
  1107. }
  1108.  
  1109. void CSubscribePropertyPage::DoSelChanged(MSG_GroupNameLine* pGroup)
  1110. {
  1111.     if (m_nMode == MSG_SubscribeAll)
  1112.     {
  1113.         
  1114.         if (!(pGroup->flags & MSG_GROUPNAME_FLAG_HASCHILDREN))
  1115.         {
  1116.             m_bSelChanged = TRUE;
  1117.             GetDlgItem(IDC_EDIT_NEWSGROUP)->SetWindowText(pGroup->name);
  1118.         }
  1119.  
  1120.         if (m_bProcessGetDeletion)
  1121.             return;
  1122.  
  1123.         if (pGroup->flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  1124.         {
  1125.             if (pGroup->flags & MSG_GROUPNAME_FLAG_ELIDED) 
  1126.                 GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(TRUE);  
  1127.             else 
  1128.                 GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  1129.         }
  1130.         else
  1131.         {
  1132.             GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  1133.         }
  1134.     }
  1135.     CheckSubscribeButton(pGroup);
  1136. }
  1137.  
  1138. void CSubscribePropertyPage::CheckSubscribeButton(MSG_GroupNameLine* pGroup)
  1139. {
  1140.     if (!pGroup)
  1141.         return;
  1142.     
  1143.     if (pGroup->flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  1144.     {
  1145.         GetDlgItem(IDC_SUBSCRIBE)->EnableWindow(FALSE);  
  1146.         GetDlgItem(IDC_UNSUBSCRIBE)->EnableWindow(FALSE);  
  1147.     }
  1148.     else
  1149.     {    
  1150.         GetDlgItem(IDC_SUBSCRIBE)->EnableWindow(TRUE);
  1151.         GetDlgItem(IDC_UNSUBSCRIBE)->EnableWindow(TRUE);  
  1152.     }
  1153. }
  1154.  
  1155. void CSubscribePropertyPage::DoDataExchange(CDataExchange* pDX)
  1156. {
  1157.     CDialog::DoDataExchange(pDX);
  1158. }
  1159.  
  1160. void CSubscribePropertyPage::CleanupOnClose()
  1161. {
  1162.     CSubscribeList* pList = GetList();
  1163.     if (pList)
  1164.     {
  1165.         pList->Release();
  1166.         SetList(NULL);
  1167.     }
  1168.  
  1169.     CSubscribeCX* pCX = GetSubscribeContext();
  1170.     if (pCX)
  1171.     {
  1172.         if(!pCX->IsDestroyed())  
  1173.             pCX->DestroyContext();
  1174.         SetSubscribeContext(NULL);
  1175.     }
  1176.     MSG_Pane * pPane = GetPane();
  1177.     if (pPane)
  1178.     {
  1179.         MSG_DestroyPane(pPane);    
  1180.         SetPane(NULL);
  1181.     }
  1182.  
  1183. }
  1184.  
  1185. void CSubscribePropertyPage::OnOK() 
  1186. {
  1187.     if (!m_bActivated)    // this is to fix the crash below when m_pOutliner 
  1188.         return;            // is NULL.
  1189.  
  1190.     if (m_bProcessGetDeletion && GetSubscribeContext())
  1191.     {
  1192.         if (XP_IsContextBusy(GetContext()))
  1193.             XP_InterruptContext(GetContext());
  1194.     }
  1195.     CPropertyPage::OnOK();
  1196.     CleanupOnClose();
  1197. }
  1198.  
  1199. void CSubscribePropertyPage::OnCancel() 
  1200. {
  1201.     if (m_bProcessGetDeletion && GetSubscribeContext())
  1202.     {
  1203.         if (XP_IsContextBusy(GetContext()))
  1204.             XP_InterruptContext(GetContext());
  1205.     }
  1206.     if (GetPane())
  1207.         MSG_SubscribeCancel(GetPane());
  1208.  
  1209.     CNetscapePropertyPage::OnCancel();
  1210.     CleanupOnClose();
  1211. }
  1212.  
  1213. void CSubscribePropertyPage::OnAddServer()
  1214. {
  1215.     CServerTypeDialog serverTypeDialog(this->GetParent());
  1216.  
  1217.     if (IDOK == serverTypeDialog.DoModal())
  1218.     {
  1219.         MSG_Host *pNewHost = serverTypeDialog.GetNewHost();
  1220.                      
  1221.         if (pNewHost)
  1222.         {
  1223.             int nIndex = GetServerCombo()->AddString(MSG_GetHostUIName(pNewHost));
  1224.  
  1225.             ((CSubscribePropertySheet*)GetParent())->AddServer(pNewHost);
  1226.             if (nIndex != CB_ERR)
  1227.             {
  1228.                 m_bFromTyping = FALSE;
  1229.                 GetServerCombo()->SetItemDataPtr(nIndex, pNewHost);
  1230.                 GetServerCombo()->SetCurSel(nIndex);
  1231.                 OnChangeServer();
  1232.             }
  1233.         }
  1234.     }
  1235. }
  1236.  
  1237. void CSubscribePropertyPage::OnSubscribeNewsgroup()
  1238. {
  1239.     int count;
  1240.     MSG_ViewIndex *indices;
  1241.     MSG_GroupNameLine group;
  1242.  
  1243.     m_pOutliner->GetSelection( indices, count );
  1244.     for (int i = 0; i < count; i++)
  1245.     {
  1246.         MSG_GetGroupNameLineByIndex(GetPane(), indices[i], 1, &group);
  1247.         if (!(group.flags & MSG_GROUPNAME_FLAG_SUBSCRIBED))
  1248.             MSG_Command(GetPane(), MSG_ToggleSubscribed, &indices[i], 1);
  1249.     }
  1250.     //Get updated info
  1251.     MSG_GetGroupNameLineByIndex(GetPane(), indices[0], 1, &group);
  1252.     CheckSubscribeButton(&group);
  1253. }
  1254.  
  1255. void CSubscribePropertyPage::OnUnsubscribeNewsgroup()
  1256. {
  1257.     int count;
  1258.     MSG_ViewIndex *indices;
  1259.     MSG_GroupNameLine group;
  1260.  
  1261.     m_pOutliner->GetSelection( indices, count );
  1262.     for (int i = 0; i < count; i++)
  1263.     {
  1264.         MSG_GetGroupNameLineByIndex(GetPane(), indices[i], 1, &group);
  1265.         if (group.flags & MSG_GROUPNAME_FLAG_SUBSCRIBED)
  1266.             MSG_Command(GetPane(), MSG_ToggleSubscribed, &indices[i], 1);
  1267.     }
  1268.     //Get updated info
  1269.     MSG_GetGroupNameLineByIndex(GetPane(), indices[0], 1, &group);
  1270.     CheckSubscribeButton(&group);
  1271. }
  1272.  
  1273. void CSubscribePropertyPage::OnChangeServer()
  1274. {
  1275.     CSubscribePropertySheet* pParent = (CSubscribePropertySheet*)GetParent();
  1276.     MSG_Host *pCurrentHost = pParent->GetHost();
  1277.     int nIndex = GetServerCombo()->GetCurSel();
  1278.     MSG_Host *pHost = (MSG_Host *)GetServerCombo()->GetItemDataPtr(nIndex);
  1279.     if (pHost == pCurrentHost)
  1280.         return;
  1281.  
  1282.     DoStopListChange();
  1283.     ClearNewsgroupSelection();
  1284.     if (m_nMode != MSG_SubscribeNew && GetDlgItem(IDC_EDIT_NEWSGROUP))
  1285.     {
  1286.         GetDlgItem(IDC_EDIT_NEWSGROUP)->SetWindowText("");
  1287.         //SetWindowText() caused call to OnChangeNewsgroup() and set 
  1288.         //m_bFromTyping == TRUE,  reset it back to FALSE 
  1289.         m_bFromTyping = FALSE;      
  1290.     }
  1291.     GetOutliner()->SetTotalLines(0);    // fix for bug# 38007
  1292.     pParent->SetHost(pHost);
  1293.     MSG_SubscribeSetHost(GetPane(), pHost);
  1294.     if (MSG_IsIMAPHost(pHost))
  1295.         m_pParent->EnableNonImapPages(FALSE);
  1296.     else
  1297.         m_pParent->EnableNonImapPages(TRUE);
  1298. }
  1299.  
  1300. void CSubscribePropertyPage::EnableAllControls(BOOL bEnable)
  1301. {
  1302.     CWnd *wnd = NULL;
  1303.     if (wnd = GetDlgItem(IDC_EDIT_NEWSGROUP))
  1304.       wnd->EnableWindow(bEnable);
  1305.     if (wnd = GetDlgItem(IDC_SUBSCRIBE))
  1306.       wnd->EnableWindow(bEnable);
  1307.     if (wnd = GetDlgItem(IDC_UNSUBSCRIBE))
  1308.       wnd->EnableWindow(bEnable);
  1309.     if (wnd = GetDlgItem(IDC_EXPAND_ALL))
  1310.       wnd->EnableWindow(bEnable);
  1311.     if (wnd = GetDlgItem(IDC_COLLAPSE_ALL))
  1312.       wnd->EnableWindow(bEnable);
  1313.     if (wnd = GetDlgItem(IDC_GET_DELETE))
  1314.       wnd->EnableWindow(bEnable);
  1315.     if (wnd = GetDlgItem(IDC_ADD_SERVER))
  1316.       wnd->EnableWindow(bEnable);
  1317.     if (wnd = GetDlgItem(IDC_COMBO_SERVER))
  1318.       wnd->EnableWindow(bEnable);
  1319.     if (wnd = GetParent()->GetDlgItem(IDOK))
  1320.       wnd->EnableWindow(bEnable);
  1321.     if (bEnable == TRUE)
  1322.         m_pParent->StopAnimation();
  1323.  
  1324. }
  1325.  
  1326. void CSubscribePropertyPage::DoStopListChange()
  1327. {
  1328.     if (m_bListChangeStarting)
  1329.     {
  1330.         if (GetSubscribeContext() && XP_IsContextBusy(GetContext()))
  1331.             XP_InterruptContext(GetContext());
  1332.         m_bListChangeStarting = FALSE;
  1333.     }
  1334. }
  1335.  
  1336. void CSubscribePropertyPage::ClearNewsgroupSelection()
  1337. {
  1338.     if (m_pOutliner && m_pOutliner->IsWindowVisible())
  1339.     {
  1340.         if (m_pOutliner->GetTotalLines())
  1341.         {
  1342.             int count;
  1343.             MSG_ViewIndex *indices;
  1344.             m_pOutliner->GetSelection(indices, count);
  1345.  
  1346.             if (count)
  1347.                 m_pOutliner->SelectItem(-1);
  1348.         }
  1349.     }
  1350. }
  1351.  
  1352. void CSubscribePropertyPage::ListChangeStarting(MSG_Pane* pane, XP_Bool asynchronous,
  1353.     MSG_NOTIFY_CODE notify, MSG_ViewIndex where, int32 num)
  1354. {
  1355.     if ( pane == GetPane() ) 
  1356.     {
  1357.         m_bListChangeStarting = TRUE;
  1358.         
  1359.         if (m_pOutliner) 
  1360.             m_pOutliner->MysticStuffStarting(asynchronous, notify, where, num );
  1361.     }
  1362. }
  1363.  
  1364. void CSubscribePropertyPage::OnTimer(UINT nIDEvent)
  1365. {
  1366.     if (m_uTimer == nIDEvent)
  1367.     {
  1368.         if (m_bNotifyAll && m_pOutliner->IsWindowVisible())
  1369.         {
  1370.             m_pOutliner->MysticStuffFinishing(m_bAsynchronous, MSG_NotifyAll, 0, 0);
  1371.             m_pOutliner->SetTotalLines(CASTINT(MSG_GetNumLines(GetPane())));
  1372.             m_bNotifyAll = FALSE;
  1373.             KillTimer(m_uTimer);
  1374.             m_uTimer = 0;
  1375.         }
  1376.         if (IsWindowVisible() && m_bDoShowWindow)
  1377.         {
  1378.             BOOL result = InitSubscribePage();
  1379.             m_bDoShowWindow = FALSE;
  1380.             KillTimer(m_uTimer);
  1381.             m_uTimer = 0;
  1382.             if (!result)
  1383.                 m_pParent->EndDialog(IDCANCEL);
  1384.  
  1385.         }
  1386.     }
  1387. }
  1388.  
  1389. void CSubscribePropertyPage::ListChangeFinished(MSG_Pane* pane, XP_Bool asynchronous,
  1390.     MSG_NOTIFY_CODE notify, MSG_ViewIndex where, int32 num)
  1391. {
  1392.     if ( pane == GetPane() )
  1393.     {
  1394.         m_bListChangeStarting = FALSE;
  1395.         if (m_pOutliner)
  1396.         {
  1397.             //check if there's a MSG_NotifyAll and the outliner is not visible,
  1398.             //when it is visible, do MSG_NotifyAll at that time
  1399.             if (notify == MSG_NotifyAll && !m_pOutliner->IsWindowVisible())
  1400.             {
  1401.                 m_uTimer = SetTimer(SUBSCRIBE_VISIBLE_TIMER, 100, NULL);
  1402.                 if (m_uTimer)
  1403.                 {
  1404.                     m_bNotifyAll = TRUE;
  1405.                     m_bAsynchronous = asynchronous;
  1406.                     return;
  1407.                 }
  1408.             }
  1409.             if (m_bNotifyAll && m_pOutliner->IsWindowVisible() &&
  1410.                 notify != MSG_NotifyAll)
  1411.             {
  1412.                 if (notify != MSG_NotifyAll)
  1413.                     m_pOutliner->MysticStuffFinishing(asynchronous, MSG_NotifyAll, 0, 0);
  1414.                 m_bNotifyAll = FALSE;
  1415.             }
  1416.             m_pOutliner->MysticStuffFinishing(asynchronous, notify, where, num);
  1417.             m_pOutliner->SetTotalLines(CASTINT(MSG_GetNumLines(GetPane())));
  1418.         }
  1419.     }
  1420. }
  1421.  
  1422. BEGIN_MESSAGE_MAP(CSubscribePropertyPage, CNetscapePropertyPage)
  1423.     ON_WM_TIMER()
  1424.     ON_WM_SHOWWINDOW()
  1425.     ON_BN_CLICKED(IDC_ADD_SERVER, OnAddServer)
  1426.     ON_BN_CLICKED(IDC_SUBSCRIBE, OnSubscribeNewsgroup)
  1427.     ON_BN_CLICKED(IDC_UNSUBSCRIBE, OnUnsubscribeNewsgroup)
  1428.     ON_CBN_SELCHANGE(IDC_COMBO_SERVER, OnChangeServer)
  1429.     ON_BN_CLICKED(IDOK, OnOK)
  1430.     ON_BN_CLICKED(IDCANCEL, OnCancel)
  1431. END_MESSAGE_MAP()
  1432.  
  1433. /////////////////////////////////////////////////////////////////////////////
  1434. // CAllNewsgroupsPage
  1435.  
  1436. CAllNewsgroupsPage::CAllNewsgroupsPage(CWnd *pParent,
  1437.     MWContext *pContext, MSG_SubscribeMode nMode)
  1438.     : CSubscribePropertyPage(pParent, pContext, nMode, IDD)
  1439. {
  1440. }
  1441.  
  1442. BOOL CAllNewsgroupsPage::OnInitDialog()
  1443. {
  1444.     BOOL ret = CSubscribePropertyPage::OnInitDialog();
  1445.  
  1446.     return ret;
  1447. }
  1448.  
  1449. BOOL CAllNewsgroupsPage::OnKillActive()
  1450. {
  1451.     OnStop();
  1452.  
  1453.     return CSubscribePropertyPage::OnKillActive();
  1454. }
  1455.  
  1456. void CAllNewsgroupsPage::OnChangeNewsgroup()
  1457. {
  1458.     if (m_bSelChanged)    
  1459.     {    //change from user click outliner, change the selection
  1460.         m_bSelChanged = FALSE;
  1461.         return;
  1462.     }
  1463.     m_bFromTyping = TRUE;
  1464.  
  1465.     CString group;
  1466.     GetDlgItem(IDC_EDIT_NEWSGROUP)->GetWindowText(group);
  1467.     MSG_ViewIndex index = MSG_SubscribeFindFirst(GetPane(), 
  1468.                                                 LPCTSTR(group));
  1469.  
  1470.     if (index != MSG_VIEWINDEXNONE )
  1471.     {
  1472.         MSG_GroupNameLine newsGroup;
  1473.  
  1474.         m_pOutliner->SelectItem(CASTINT(index));
  1475.         m_pOutliner->ScrollIntoView(CASTINT(index));
  1476.         int len = group.GetLength();
  1477.          ((CEdit*)GetDlgItem(IDC_EDIT_NEWSGROUP))->SetSel(len, len);
  1478.         if (MSG_GetGroupNameLineByIndex(GetPane(), index, 1, &newsGroup))
  1479.             CheckSubscribeButton(&newsGroup);
  1480.     } 
  1481. }
  1482.  
  1483. void CAllNewsgroupsPage::OnExpandAll()
  1484. {
  1485.     DoStopListChange();
  1486.     MSG_ViewIndex *indices;
  1487.     int count;
  1488.     m_pOutliner->GetSelection( indices, count );
  1489.     MSG_Command(GetPane(), MSG_ExpandAll, indices, count);
  1490.     GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  1491. }
  1492.  
  1493. void CAllNewsgroupsPage::OnCollapseAll()
  1494. {
  1495.     int count;
  1496.     MSG_ViewIndex *indices;
  1497.     MSG_GroupNameLine group;
  1498.  
  1499.     DoStopListChange();
  1500.     MSG_Command(GetPane(), MSG_CollapseAll, NULL, 0);
  1501.  
  1502.     m_pOutliner->GetSelection(indices, count);
  1503.     if (MSG_GetGroupNameLineByIndex(GetPane(), indices[0], 1, &group))
  1504.     {
  1505.         if (group.flags & MSG_GROUPNAME_FLAG_HASCHILDREN)
  1506.         {
  1507.             if (group.flags & MSG_GROUPNAME_FLAG_ELIDED) 
  1508.                 GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(TRUE);  
  1509.             else 
  1510.                 GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  1511.         }
  1512.         else
  1513.         {
  1514.             GetDlgItem(IDC_EXPAND_ALL)->EnableWindow(FALSE);  
  1515.         }
  1516.     }
  1517. }
  1518.  
  1519. void CAllNewsgroupsPage::OnGetDeletions()
  1520. {
  1521.     if (IsWindowVisible())
  1522.         ClearNewsgroupSelection();
  1523.     m_bProcessGetDeletion = TRUE;
  1524.     EnableAllControls(FALSE);
  1525.     m_pParent->StartAnimation();
  1526.     MSG_Command(GetPane(), MSG_FetchGroupList, NULL, 0);
  1527. }
  1528.  
  1529. void CAllNewsgroupsPage::OnStop()
  1530. {
  1531.     m_pParent->StopAnimation();
  1532.     if (GetSubscribeContext() && XP_IsContextBusy(GetContext()))
  1533.         XP_InterruptContext(GetContext());
  1534.     if (m_bListChangeStarting)
  1535.         m_bListChangeStarting = FALSE;
  1536.     if (m_bProcessGetDeletion)
  1537.     {
  1538.         m_bProcessGetDeletion = FALSE;
  1539.         EnableAllControls(TRUE);
  1540.     }
  1541.     GetOutliner()->SelectInitialItem();
  1542. }
  1543.  
  1544. void CAllNewsgroupsPage::DoDataExchange(CDataExchange* pDX)
  1545. {
  1546.     CDialog::DoDataExchange(pDX);
  1547. }
  1548.  
  1549. BEGIN_MESSAGE_MAP(CAllNewsgroupsPage, CSubscribePropertyPage)
  1550.     ON_EN_CHANGE(IDC_EDIT_NEWSGROUP, OnChangeNewsgroup)
  1551.     ON_BN_CLICKED(IDC_EXPAND_ALL, OnExpandAll)
  1552.     ON_BN_CLICKED(IDC_COLLAPSE_ALL, OnCollapseAll)
  1553.     ON_BN_CLICKED(IDC_GET_DELETE, OnGetDeletions)
  1554.     ON_BN_CLICKED(IDC_STOP, OnStop)
  1555. END_MESSAGE_MAP()
  1556.  
  1557. /////////////////////////////////////////////////////////////////////////////
  1558. // CSearchNewsgroupPage
  1559.  
  1560. CSearchNewsgroupPage::CSearchNewsgroupPage(CWnd *pParent,
  1561.     MWContext *pContext, MSG_SubscribeMode nMode)
  1562.     : CSubscribePropertyPage(pParent, pContext, nMode, IDD)
  1563. {
  1564. }
  1565.  
  1566. BOOL CSearchNewsgroupPage::OnInitDialog()
  1567. {
  1568.     GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1569.  
  1570.     BOOL ret = CSubscribePropertyPage::OnInitDialog();
  1571.     return ret;
  1572. }
  1573.  
  1574. void CSearchNewsgroupPage::OnSearchNow()
  1575. {
  1576.     CString group;
  1577.  
  1578.     ClearNewsgroupSelection();
  1579.     GetDlgItem(IDC_EDIT_NEWSGROUP)->GetWindowText(group);
  1580.     GetDlgItem(IDC_STOP)->EnableWindow(TRUE);
  1581.     MSG_SubscribeFindAll(GetPane(), LPCTSTR(group));
  1582.     if (m_pOutliner->GetTotalLines())
  1583.         m_pOutliner->SelectItem(0);
  1584.     GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1585. }
  1586.  
  1587. void CSearchNewsgroupPage::OnStop()
  1588. {
  1589.     m_pParent->StopAnimation();
  1590.     if (GetSubscribeContext() && XP_IsContextBusy(GetContext()))
  1591.         XP_InterruptContext(GetContext());
  1592.     if (m_bListChangeStarting)
  1593.         m_bListChangeStarting = FALSE;
  1594.     GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1595. }
  1596.  
  1597. void CSearchNewsgroupPage::DoDataExchange(CDataExchange* pDX)
  1598. {
  1599.     CDialog::DoDataExchange(pDX);
  1600. }
  1601.  
  1602. BEGIN_MESSAGE_MAP(CSearchNewsgroupPage, CSubscribePropertyPage)
  1603.     ON_BN_CLICKED(IDC_SEARCH_NOW, OnSearchNow)
  1604.     ON_BN_CLICKED(IDC_STOP, OnStop)
  1605. END_MESSAGE_MAP()
  1606.  
  1607. /////////////////////////////////////////////////////////////////////////////
  1608. // CNewNewsgroupsPage
  1609.  
  1610. CNewNewsgroupsPage::CNewNewsgroupsPage(CWnd *pParent,
  1611.     MWContext *pContext, MSG_SubscribeMode nMode)
  1612.     : CSubscribePropertyPage(pParent, pContext, nMode, IDD)
  1613. {
  1614.     m_bGetNew = FALSE;
  1615. }
  1616.  
  1617. BOOL CNewNewsgroupsPage::OnInitDialog()
  1618. {
  1619.     GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1620.     return  CSubscribePropertyPage::OnInitDialog();
  1621. }
  1622.  
  1623. BOOL CNewNewsgroupsPage::OnKillActive()
  1624. {
  1625.     OnStop();
  1626.  
  1627.     return CSubscribePropertyPage::OnKillActive();
  1628. }
  1629.  
  1630. void CNewNewsgroupsPage::OnGetNew()
  1631. {
  1632.     m_pParent->StartAnimation();
  1633.     MSG_Command(GetPane(), MSG_CheckForNew, NULL, 0);
  1634.     GetDlgItem(IDC_GET_NEW)->EnableWindow(FALSE);
  1635.     GetDlgItem(IDC_STOP)->EnableWindow(TRUE);
  1636.     m_bGetNew = TRUE;
  1637. }
  1638.  
  1639. void CNewNewsgroupsPage::OnClearNew()
  1640. {
  1641.      ClearNewsgroupSelection();
  1642.     GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(FALSE);
  1643.     MSG_Command(GetPane(), MSG_ClearNew, NULL, 0);
  1644. }
  1645.  
  1646. void CNewNewsgroupsPage::OnStop()
  1647. {
  1648.     if (GetSubscribeContext() && XP_IsContextBusy(GetContext()))
  1649.         XP_InterruptContext(GetContext());
  1650.     if (m_bListChangeStarting)
  1651.         m_bListChangeStarting = FALSE;
  1652.  
  1653.     if (m_bGetNew)
  1654.     {
  1655.         m_bGetNew = FALSE;
  1656.         m_pParent->StopAnimation();
  1657.         GetDlgItem(IDC_GET_NEW)->EnableWindow(TRUE);
  1658.         if (GetOutliner()->GetTotalLines())
  1659.             GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(TRUE);
  1660.         else
  1661.             GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(FALSE);
  1662.         GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1663.     }
  1664. }
  1665.  
  1666. void CNewNewsgroupsPage::DoDataExchange(CDataExchange* pDX)
  1667. {
  1668.     CDialog::DoDataExchange(pDX);
  1669. }
  1670.  
  1671. BEGIN_MESSAGE_MAP(CNewNewsgroupsPage, CSubscribePropertyPage)
  1672.     ON_BN_CLICKED(IDC_GET_NEW, OnGetNew)
  1673.     ON_BN_CLICKED(IDC_CLEAR_NEW, OnClearNew)
  1674.     ON_BN_CLICKED(IDC_STOP, OnStop)
  1675. END_MESSAGE_MAP()
  1676.  
  1677. /////////////////////////////////////////////////////////////////////////////
  1678. // CSubscibePropertySheet           
  1679. CSubscribePropertySheet::CSubscribePropertySheet
  1680. (CWnd *pParent, MWContext *pContext, const char* pName)
  1681.     : CNetscapePropertySheet(pName, pParent, 0, pContext)
  1682. {
  1683.     m_pCX = NULL;
  1684.     m_pSubscribePane = NULL;
  1685.     m_pSubscribeList = NULL;
  1686.     m_pCurrentHost = NULL;
  1687.     m_pNewPage = NULL;
  1688.  
  1689.     m_bCommitingStart = FALSE;
  1690.  
  1691.     nameWidth = -1;
  1692.     subscribeWidth = -1;
  1693.     postWidth = -1;
  1694.     namePos = -1;
  1695.     subscribePos = -1;
  1696.     postPos = -1;
  1697.  
  1698.     int32 lPrefInt;
  1699.     PREF_GetIntPref("news.subscribe.name_width",&lPrefInt);
  1700.     nameWidth = CASTINT(lPrefInt);
  1701.     PREF_GetIntPref("news.subscribe.join_width",&lPrefInt);
  1702.     subscribeWidth = CASTINT(lPrefInt);
  1703.     PREF_GetIntPref("news.subscribe.post_width",&lPrefInt);
  1704.     postWidth = CASTINT(lPrefInt);
  1705.     PREF_GetIntPref("news.subscribe.name_pos",&lPrefInt);
  1706.     namePos = CASTINT(lPrefInt);
  1707.     PREF_GetIntPref("news.subscribe.join_pos",&lPrefInt);
  1708.     subscribePos = CASTINT(lPrefInt);
  1709.     PREF_GetIntPref("news.subscribe.post_pos",&lPrefInt);
  1710.     postPos = CASTINT(lPrefInt);
  1711.  
  1712.     m_pAllGroupPage = new CAllNewsgroupsPage(this, pContext);
  1713.     m_pSearchGroupPage = new CSearchNewsgroupPage(this, pContext);
  1714.     m_pNewGroupPage = new CNewNewsgroupsPage(this, pContext);
  1715.  
  1716.     AddPage(m_pAllGroupPage);
  1717.     AddPage(m_pSearchGroupPage);
  1718.     AddPage(m_pNewGroupPage);
  1719. }
  1720.  
  1721. CSubscribePropertySheet::~CSubscribePropertySheet()
  1722. {
  1723.     PREF_SetIntPref("news.subscribe.name_width", (int32)nameWidth);
  1724.     PREF_SetIntPref("news.subscribe.join_width", (int32)subscribeWidth);
  1725.     PREF_SetIntPref("news.subscribe.post_width", (int32)postWidth);
  1726.     PREF_SetIntPref("news.subscribe.name_pos", (int32)namePos);
  1727.     PREF_SetIntPref("news.subscribe.join_pos", (int32)subscribePos);
  1728.     PREF_SetIntPref("news.subscribe.post_pos", (int32)postPos);
  1729.  
  1730.     if (m_pAllGroupPage)
  1731.         delete m_pAllGroupPage;
  1732.     if (m_pSearchGroupPage)
  1733.         delete m_pSearchGroupPage;
  1734.     if (m_pNewGroupPage)
  1735.         delete m_pNewGroupPage;   
  1736. }
  1737.  
  1738. BOOL CSubscribePropertySheet::OnCommand(WPARAM wParam, LPARAM lParam)
  1739. {
  1740. #ifdef _WIN32
  1741.     if (!m_bCommitingStart && (
  1742.         IDOK == LOWORD(wParam) && HIWORD(wParam) == BN_CLICKED))
  1743. #else
  1744.     if (!m_bCommitingStart && (IDOK == wParam && HIWORD(lParam) == BN_CLICKED))
  1745. #endif
  1746.     {
  1747.         if (GetActivePage() == m_pSearchGroupPage)
  1748.         {
  1749.             if (GetFocus() == m_pSearchGroupPage->GetDlgItem(IDC_EDIT_NEWSGROUP))
  1750.             {
  1751. #ifdef _WIN32
  1752.                 m_pSearchGroupPage->SendMessage(WM_COMMAND, MAKELONG(IDC_SEARCH_NOW, BN_CLICKED),
  1753.                                     (LPARAM)(m_pSearchGroupPage->GetDlgItem(IDC_SEARCH_NOW)->GetSafeHwnd()));
  1754. #else
  1755.                 m_pSearchGroupPage->SendMessage(WM_COMMAND, IDC_SEARCH_NOW, 
  1756.                     MAKELONG(m_pSearchGroupPage->GetDlgItem(IDC_SEARCH_NOW)->GetSafeHwnd(), BN_CLICKED));
  1757. #endif
  1758.                 return TRUE;
  1759.             }
  1760.         }
  1761.         if (XP_IsContextBusy(GetSubscribeContext()->GetContext()))
  1762.             XP_InterruptContext(GetSubscribeContext()->GetContext());
  1763.         ((CSubscribePropertyPage*)GetActivePage())->EnableAllControls(FALSE);
  1764.         m_bCommitingStart = TRUE;
  1765.         MSG_SubscribeCommit(GetSubscribePane());
  1766.         return TRUE;
  1767.     }
  1768.  
  1769.     return CNetscapePropertySheet::OnCommand(wParam, lParam);
  1770. }
  1771.  
  1772. #ifdef _WIN32
  1773.  
  1774. BOOL CSubscribePropertySheet::OnInitDialog()
  1775. {
  1776.     BOOL ret = CNetscapePropertySheet::OnInitDialog();
  1777.  
  1778.     CreateProgressBar();
  1779.  
  1780.     return ret;
  1781. }
  1782.  
  1783. #else
  1784.  
  1785. int CSubscribePropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
  1786. {
  1787.     int ret = CNetscapePropertySheet::OnCreate(lpCreateStruct);
  1788.     
  1789.     CreateProgressBar();
  1790.  
  1791.     return ret;
  1792. }
  1793.  
  1794. #endif
  1795.  
  1796. void CSubscribePropertySheet::CreateProgressBar()
  1797. {
  1798.     TEXTMETRIC tm;
  1799.       CRect winRect, pageRect;
  1800.  
  1801.     HDC hDC = ::GetDC(GetSafeHwnd());
  1802.     GetTextMetrics(hDC, &tm);
  1803.     ::ReleaseDC(GetSafeHwnd(), hDC);
  1804.     
  1805.     int nStatusHeight = tm.tmHeight + tm.tmInternalLeading+ tm.tmExternalLeading;
  1806.  
  1807.     GetWindowRect(winRect);
  1808.     SetWindowPos(NULL, 0, 0, winRect.right - winRect.left, 
  1809.           winRect.bottom - winRect.top + nStatusHeight, SWP_NOMOVE);
  1810.  
  1811.     m_barStatus.Create(this, FALSE, FALSE);
  1812.  
  1813.     GetClientRect(winRect);
  1814.     m_barStatus.MoveWindow(0, winRect.bottom - winRect.top - nStatusHeight, 
  1815.         winRect.right - winRect.left, nStatusHeight, TRUE);
  1816. }
  1817.  
  1818. void CSubscribePropertySheet::SetStatusText(const char* pMessage)
  1819. {
  1820.     if (IsWindow(m_barStatus.GetSafeHwnd()))
  1821.         m_barStatus.SetPaneText(m_barStatus.CommandToIndex(ID_SEPARATOR), 
  1822.                                 pMessage, TRUE );
  1823. }
  1824.  
  1825. void CSubscribePropertySheet::Progress(const char *pMessage)
  1826. {
  1827.     if (IsWindow(m_barStatus.GetSafeHwnd()))
  1828.         m_barStatus.SetPaneText(m_barStatus.CommandToIndex(ID_SEPARATOR), 
  1829.                                 pMessage, TRUE );
  1830. }
  1831.  
  1832. void CSubscribePropertySheet::SetProgressBarPercent(int32 lPercent)
  1833. {
  1834.     if (::IsWindow(m_barStatus.GetSafeHwnd()))
  1835.         m_barStatus.SetPercentDone( lPercent );
  1836. }  
  1837.  
  1838. void CSubscribePropertySheet::StartAnimation()
  1839. {
  1840.     if (::IsWindow(m_barStatus.GetSafeHwnd()))
  1841.     {
  1842.         m_barStatus.StartAnimation();
  1843.     }
  1844. }
  1845.  
  1846. void CSubscribePropertySheet::StopAnimation()
  1847. {
  1848.     if (::IsWindow(m_barStatus.GetSafeHwnd()))
  1849.     {
  1850.         m_barStatus.StopAnimation();
  1851.     }
  1852. }
  1853.  
  1854. void CSubscribePropertySheet::AllConnectionsComplete(MWContext *pContext )
  1855. {
  1856.     if (m_bCommitingStart)
  1857.     {
  1858.         SendMessage(WM_COMMAND, IDOK, 0);
  1859.         return;
  1860.     }
  1861.     SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  1862.  
  1863.     StopAnimation();
  1864.     CSubscribePropertyPage* pPage = (CSubscribePropertyPage*)GetActivePage();
  1865.     if (pPage)
  1866.     {
  1867.         CNewsgroupsOutliner* pOutliner = pPage->GetOutliner();
  1868.         if (pOutliner)
  1869.         {
  1870.             if (pOutliner->SelectInitialItem())
  1871.             {
  1872.                 int count;
  1873.                 MSG_ViewIndex *indices;
  1874.                 MSG_GroupNameLine group;
  1875.  
  1876.                 pOutliner->GetSelection(indices, count);
  1877.                 if (MSG_GetGroupNameLineByIndex(GetSubscribePane(), indices[0], 
  1878.                                                 1, &group))
  1879.                     pPage->CheckSubscribeButton(&group);
  1880.             }
  1881.         }
  1882.  
  1883.         if (pPage->GetMode() == MSG_SubscribeNew)
  1884.         {
  1885.             StopAnimation();
  1886.             ((CNewNewsgroupsPage*)pPage)->m_bGetNew = FALSE;
  1887.             pPage->GetDlgItem(IDC_GET_NEW)->EnableWindow(TRUE);
  1888.             if (pPage->GetOutliner()->GetTotalLines())
  1889.                 pPage->GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(TRUE);
  1890.             else
  1891.                 pPage->GetDlgItem(IDC_CLEAR_NEW)->EnableWindow(FALSE);
  1892.             pPage->GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
  1893.         }
  1894.     }
  1895. }
  1896.  
  1897. void CSubscribePropertySheet::AddServer(MSG_Host* pHost)
  1898. {
  1899.     if (::IsWindow(m_pSearchGroupPage->GetSafeHwnd()))
  1900.     {
  1901.         int nIndex = m_pSearchGroupPage->GetServerCombo()->AddString(MSG_GetHostUIName(pHost));
  1902.         if (nIndex != CB_ERR)
  1903.             m_pSearchGroupPage->GetServerCombo()->SetItemDataPtr(nIndex, pHost);
  1904.     }
  1905.  
  1906.     if (::IsWindow(m_pNewGroupPage->GetSafeHwnd()))
  1907.     {
  1908.         int nIndex = m_pNewGroupPage->GetServerCombo()->AddString(MSG_GetHostUIName(pHost));
  1909.         if (nIndex != CB_ERR)
  1910.             m_pNewGroupPage->GetServerCombo()->SetItemDataPtr(nIndex, pHost);
  1911.     }
  1912. }
  1913.  
  1914. void CSubscribePropertySheet::EnableNonImapPages(BOOL bEnable)
  1915. {
  1916.     if (::IsWindow(m_pSearchGroupPage->GetSafeHwnd()))
  1917.         m_pSearchGroupPage->EnableAllControls(bEnable);
  1918.     if (::IsWindow(m_pNewGroupPage->GetSafeHwnd()))
  1919.         m_pNewGroupPage->EnableAllControls(bEnable);
  1920. }
  1921.  
  1922. void CSubscribePropertySheet::OnHelp()
  1923. {
  1924.     if (GetActivePage() == m_pAllGroupPage)
  1925.         NetHelp(HELP_SUBSCRIBE_LIST_ALL);
  1926.     else if (GetActivePage() == m_pSearchGroupPage)
  1927.         NetHelp(HELP_SUBSCRIBE_SEARCH);
  1928.     else if (GetActivePage() == m_pNewGroupPage)
  1929.         NetHelp(HELP_SUBSCRIBE_LIST_NEW);
  1930. }
  1931.  
  1932. BEGIN_MESSAGE_MAP(CSubscribePropertySheet, CNetscapePropertySheet)
  1933. #ifndef _WIN32
  1934.     ON_WM_CREATE()
  1935. #endif
  1936. END_MESSAGE_MAP()
  1937.  
  1938. /////////////////////////////////////////////////////////////////////////////
  1939. // CServerTypeDialog    
  1940. //       
  1941. CServerTypeDialog::CServerTypeDialog(CWnd *pParent)
  1942.     : CDialog(CServerTypeDialog::IDD, pParent)
  1943. {
  1944.     m_pHost = NULL;
  1945. }
  1946.  
  1947. BOOL CServerTypeDialog::OnInitDialog()
  1948. {
  1949.     CheckDlgButton(IDC_RADIO_NNTP, TRUE);
  1950.     return CDialog::OnInitDialog();
  1951. }
  1952.  
  1953. void CServerTypeDialog::DoDataExchange(CDataExchange* pDX)
  1954. {
  1955.     CDialog::DoDataExchange(pDX);
  1956. }
  1957.  
  1958. void CServerTypeDialog::OnOK() 
  1959. {
  1960.     CDialog::OnOK();
  1961.  
  1962.     if (IsDlgButtonChecked(IDC_RADIO_NNTP))
  1963.     {
  1964.         m_pHost = DoAddNewsServer(GetParent(), FROM_SUBSCRIBEUI);
  1965.     }
  1966.     else if (IsDlgButtonChecked(IDC_RADIO_IMAP))
  1967.     {
  1968.         m_pHost = DoAddIMAPServer(GetParent(), NULL, TRUE);
  1969.     }
  1970. }
  1971.  
  1972. BEGIN_MESSAGE_MAP(CServerTypeDialog, CDialog)
  1973.     ON_BN_CLICKED(IDOK, OnOK)
  1974. END_MESSAGE_MAP()
  1975.  
  1976.