home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / fldrfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  20.5 KB  |  757 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. #include "prefapi.h"
  21. #include "template.h"
  22. #include "fldrfrm.h"
  23. #include "thrdfrm.h"
  24. #include "msgfrm.h"
  25. #include "msgcom.h"
  26. #include "wfemsg.h"
  27. #include "mailpriv.h"
  28. #include "prefs.h"
  29. #include "dspppage.h"
  30.  
  31. #ifndef _AFXDLL
  32. #undef new
  33. #endif
  34. IMPLEMENT_DYNCREATE(CFolderFrame, CMsgListFrame)
  35. #ifndef _AFXDLL
  36. #define new DEBUG_NEW
  37. #endif
  38.  
  39. #ifdef _DEBUG
  40. #undef THIS_FILE
  41. static char BASED_CODE THIS_FILE[] = __FILE__;
  42. #endif
  43.  
  44. CFolderFrame *g_pFolderFrame = NULL;
  45.  
  46. const UINT FolderCodes[] = {
  47.     ID_FILE_GETNEWMAIL,
  48.     ID_FILE_NEWMESSAGE,
  49.     ID_FILE_NEWFOLDER,
  50.     ID_FILE_SUBSCRIBE,
  51.     ID_NAVIGATE_INTERRUPT
  52. };
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CFolderFrame
  56.  
  57. CFolderFrame::CFolderFrame()
  58. {
  59.     m_iMessageMenuPos = 2;
  60.     m_iMoveMenuPos = 3;
  61.     m_iCopyMenuPos = -1;
  62.  
  63.     m_iFileMenuPos = -1;
  64.     m_iAttachMenuPos = -1;
  65. }
  66.  
  67. void CFolderFrame::SelectFolder( MSG_FolderInfo *folderInfo )
  68. {
  69.     ASSERT( m_pPane && m_pOutliner );
  70.     if ( m_pPane && m_pOutliner ) {
  71.         MSG_ViewIndex index = MSG_GetFolderIndexForInfo( m_pPane, folderInfo, TRUE );
  72.         if ( index != MSG_VIEWINDEXNONE ) {
  73.             m_pOutliner->SelectItem( CASTINT(index) );
  74.         }
  75.     }
  76. }
  77.  
  78. void CFolderFrame::PaneChanged( MSG_Pane *pane, XP_Bool asynchronous, 
  79.                                 MSG_PANE_CHANGED_NOTIFY_CODE notify, int32 value)
  80. {
  81.     if ( notify == MSG_PaneNotifySelectNewFolder ) {
  82.         if ( value >= 0 ) {
  83.             m_pOutliner->SelectItem( CASTINT(value) );
  84.         }
  85.     }
  86. }
  87.  
  88. void CFolderFrame::GetMessageString( UINT nID, CString& rMessage ) const
  89. {
  90.     if (nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID) {
  91.         rMessage.LoadString(IDS_STATUS_MOVEFOLDER);
  92.     } else {
  93.         CMsgListFrame::GetMessageString(nID, rMessage);
  94.     }
  95. }
  96.  
  97. BOOL CFolderFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
  98. {
  99.     BOOL res = CMsgListFrame::OnCreateClient( lpcs, pContext );
  100.     if (res) {
  101.         CMailNewsCX *pCX;
  102.  
  103.         pCX = new CMailNewsCX( MailCX, this );
  104.  
  105.         SetMainContext(pCX);
  106.         SetActiveContext(pCX);
  107.  
  108.         pCX->GetContext()->fancyFTP = TRUE;
  109.         pCX->GetContext()->fancyNews = TRUE;
  110.         pCX->GetContext()->intrupt = FALSE;
  111.         pCX->GetContext()->reSize = FALSE;
  112.         pCX->GetContext()->type = MWContextMail;
  113.  
  114.         m_pMaster = WFE_MSGGetMaster();
  115.         m_pPane = MSG_CreateFolderPane( GetMainContext()->GetContext(), m_pMaster );
  116.  
  117.         CFolderView *pView = (CFolderView *) GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
  118.         ASSERT(pView && pView->IsKindOf(RUNTIME_CLASS(CFolderView)));
  119.  
  120.         m_pOutliner = (CMailNewsOutliner *) pView->m_pOutlinerParent->m_pOutliner;
  121.         pView->m_pOutlinerParent->CreateColumns ( );
  122.         m_pOutliner->SetPane(m_pPane);
  123.  
  124.         MSG_SetFEData( m_pPane, (LPVOID) (LPUNKNOWN) (LPMSGLIST) this );
  125.  
  126.         m_pOutliner->SelectItem(0);
  127.     }
  128.     return res;
  129. }
  130.  
  131. BEGIN_MESSAGE_MAP( CFolderFrame, CMsgListFrame )
  132.     ON_WM_SETFOCUS()
  133.     ON_WM_QUERYNEWPALETTE()
  134.     ON_WM_CREATE()
  135.     ON_WM_CLOSE()
  136.     ON_WM_DESTROY()
  137.  
  138.     ON_COMMAND(ID_FILE_NEWFOLDER, OnNew)
  139.     ON_UPDATE_COMMAND_UI(ID_FILE_NEWFOLDER, OnUpdateNew)
  140.  
  141.     ON_COMMAND(ID_FILE_UPDATECOUNTS, OnUpdateView)
  142.     ON_UPDATE_COMMAND_UI(ID_FILE_UPDATECOUNTS, OnUpdateUpdateView)
  143.     ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
  144.     ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTIES, OnUpdateViewProperties)
  145.     // Organize Menu
  146. #ifdef ON_COMMAND_RANGE
  147.     ON_COMMAND_RANGE(FIRST_MOVE_MENU_ID, LAST_MOVE_MENU_ID, OnMove )
  148.     ON_COMMAND_RANGE(FIRST_COPY_MENU_ID, LAST_COPY_MENU_ID, OnCopy )
  149. #endif
  150.     ON_COMMAND(ID_FOLDER_SELECT, OnSelect)
  151.  
  152.     ON_COMMAND(ID_FILE_OPENFOLDER, OnOpen )
  153.     ON_UPDATE_COMMAND_UI(ID_FILE_OPENFOLDER, OnUpdateOpen )
  154.     ON_COMMAND(ID_FILE_OPENFOLDERNEW, OnOpenNew )
  155.     ON_UPDATE_COMMAND_UI(ID_FILE_OPENFOLDERNEW, OnUpdateOpen )
  156.     ON_COMMAND(ID_FILE_OPENFOLDERREUSE, OnOpenReuse )
  157.     ON_UPDATE_COMMAND_UI(ID_FILE_OPENFOLDERREUSE, OnUpdateOpen )
  158.  
  159.     ON_COMMAND(ID_HOTLIST_ADDCURRENTTOHOTLIST, OnFileBookmark)
  160.     ON_UPDATE_COMMAND_UI(ID_HOTLIST_ADDCURRENTTOHOTLIST, OnUpdateFileBookmark)
  161. END_MESSAGE_MAP()
  162.  
  163. #ifndef ON_COMMAND_RANGE
  164.  
  165. BOOL CFolderFrame::OnCommand( WPARAM wParam, LPARAM lParam )
  166. {
  167.     UINT nID = wParam;
  168.  
  169.     if ( nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID ) {
  170.         OnMove( nID );
  171.         return TRUE;
  172.     }
  173.     if ( nID >= FIRST_COPY_MENU_ID && nID <= LAST_COPY_MENU_ID ) {
  174.         OnCopy( nID );
  175.         return TRUE;
  176.     }
  177.     return CMailNewsFrame::OnCommand( wParam, lParam );
  178. }
  179.  
  180. BOOL CFolderFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  181.     if (nCode == CN_UPDATE_COMMAND_UI) {
  182.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  183.         if ( nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID ) {
  184.             OnUpdateFile( pCmdUI );
  185.             return TRUE;
  186.         }
  187.     }
  188.     return CMsgListFrame::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  189. }
  190.  
  191. #endif
  192.  
  193. void CFolderFrame::OnSetFocus( CWnd *pWndOld )
  194. {
  195.     CMsgListFrame::OnSetFocus( pWndOld );
  196.     if (m_pOutliner)
  197.         m_pOutliner->SetFocus();
  198. }
  199.  
  200. int CFolderFrame::OnCreate( LPCREATESTRUCT lpCreateStruct )
  201. {
  202.     int res = CMsgListFrame::OnCreate( lpCreateStruct );
  203.  
  204.     if ( res != -1 ) {
  205.         // Set up toolbar
  206.  
  207.         CString csFullString, cs;
  208.         csFullString.LoadString( IDR_MAILFRAME );
  209.         AfxExtractSubString( cs, csFullString, 0 );
  210.         m_pChrome->SetWindowTitle(cs);
  211.  
  212.         //I'm hardcoding string since I don't want it translated.
  213.         m_pChrome->CreateCustomizableToolbar("Folders", 3, TRUE);
  214.         CButtonToolbarWindow *pWindow;
  215.         BOOL bOpen, bShowing;
  216.  
  217.         int32 nPos;
  218.  
  219.         //I'm hardcoding because I don't want this translated
  220.         m_pChrome->LoadToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"), nPos, bOpen, bShowing);
  221.  
  222.         LPNSTOOLBAR pIToolBar;
  223.         m_pChrome->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  224.         if ( pIToolBar ) {
  225.             pIToolBar->Create( this, WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|CBRS_TOP );
  226.             pIToolBar->SetButtons( FolderCodes, sizeof(FolderCodes) / sizeof(UINT) );
  227.             pIToolBar->SetSizes( CSize( 29, 27 ), CSize( 23, 21 ) );
  228.             pIToolBar->LoadBitmap( MAKEINTRESOURCE( IDB_FOLDERTOOLBAR ) );
  229.             pIToolBar->SetToolbarStyle( theApp.m_pToolbarStyle );
  230.             pWindow = new CButtonToolbarWindow(CWnd::FromHandlePermanent(pIToolBar->GetHWnd()), theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  231.             m_pChrome->GetCustomizableToolbar()->AddNewWindow(ID_NAVIGATION_TOOLBAR, pWindow,nPos, 50, 37, 0, CString(szLoadString(ID_NAVIGATION_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  232.             m_pChrome->ShowToolbar(ID_NAVIGATION_TOOLBAR, bShowing);
  233.  
  234.             pIToolBar->Release();
  235.         }
  236.  
  237.         m_pInfoBar = new CContainerInfoBar;
  238.         m_pInfoBar->Create(this, m_pPane);
  239.  
  240.         //I'm hardcoding because I don't want this translated
  241.         m_pChrome->LoadToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"), nPos, bOpen, bShowing);
  242.  
  243.         CToolbarWindow *pToolWindow = new CToolbarWindow(m_pInfoBar, theApp.m_pToolbarStyle, 27, 27, eSMALL_HTAB);
  244.         m_pChrome->GetCustomizableToolbar()->AddNewWindow(ID_LOCATION_TOOLBAR, pToolWindow,nPos, 27, 27, 0, CString(szLoadString(ID_LOCATION_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  245.         m_pChrome->ShowToolbar(ID_LOCATION_TOOLBAR, bShowing);
  246.  
  247.         m_barStatus.Create(this, FALSE, TRUE);
  248.  
  249.         LPNSSTATUSBAR pIStatusBar = NULL;
  250.         m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  251.         if ( pIStatusBar ) {
  252.             pIStatusBar->Attach(&m_barStatus);
  253.             pIStatusBar->Release();
  254.         }
  255.  
  256.         RecalcLayout();
  257.  
  258.         ((CMailNewsCX *) GetMainContext())->SetChrome( m_pChrome );
  259.         g_pFolderFrame = this;
  260.  
  261.         m_pInfoBar->Update();
  262.     }
  263.     return res;
  264. }
  265.  
  266. void CFolderFrame::OnClose()
  267. {
  268.     int16 left, top, width, height;
  269.     int32 prefInt;
  270.     WINDOWPLACEMENT wp;
  271.     wp.length = sizeof(WINDOWPLACEMENT);
  272.     GetWindowPlacement(&wp);
  273.     CRect rect(wp.rcNormalPosition);
  274.  
  275.     left = (int16) rect.left;
  276.     top = (int16) rect.top;
  277.     width = (int16) rect.Width();
  278.     height = (int16) rect.Height();
  279.     prefInt = wp.showCmd;
  280.  
  281.     PREF_SetRectPref("mailnews.folder_window_rect", left, top, width, height);
  282.     PREF_SetIntPref("mailnews.folder_window_showwindow", prefInt);
  283.  
  284.     //I'm hardcoding because I don't want this translated
  285.     m_pChrome->SaveToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"));
  286.     m_pChrome->SaveToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"));
  287.  
  288.     CMsgListFrame::OnClose();
  289. }
  290.  
  291. void CFolderFrame::OnDestroy()
  292. {
  293.     CMsgListFrame::OnDestroy();
  294.  
  295.     g_pFolderFrame = NULL;
  296. }
  297.  
  298. LPCTSTR CFolderFrame::GetWindowMenuTitle()
  299. {
  300.     return szLoadString(IDS_TITLE_COLLECTIONS);
  301. }
  302.  
  303. CFolderFrame *CFolderFrame::Open()
  304. {
  305.     if (!CheckWizard())
  306.         return NULL;
  307.  
  308.     if (!g_pFolderFrame) {
  309.         g_MsgPrefs.m_pFolderTemplate->OpenDocumentFile(NULL);
  310.     } 
  311.     
  312.     if (g_pFolderFrame) {
  313.         g_pFolderFrame->ActivateFrame();
  314.     }
  315.     return g_pFolderFrame;
  316. }
  317.  
  318. CFolderFrame *CFolderFrame::Open( MSG_FolderInfo *folderInfo)
  319. {
  320.     Open();
  321.     if ( g_pFolderFrame ) {
  322.         g_pFolderFrame->SelectFolder( folderInfo );
  323.     }
  324.     return g_pFolderFrame;
  325. }
  326.  
  327. CFolderFrame *CFolderFrame::OpenNews( )
  328. {
  329.     MSG_FolderInfo *folderInfo = NULL;
  330.     MSG_GetFoldersWithFlag( WFE_MSGGetMaster(),
  331.                             MSG_FOLDER_FLAG_NEWS_HOST,
  332.                             &folderInfo, 1 );
  333.  
  334.     CFolderFrame *pFrame = Open( folderInfo );
  335.  
  336.     return pFrame;
  337. }
  338.  
  339. void CFolderFrame::OnNew()
  340. {
  341.     MSG_FolderInfo *folderInfo = GetCurFolder();
  342.     MSG_FolderLine folderLine;
  343.     folderLine.flags = 0;
  344.     if (folderInfo)
  345.         MSG_GetFolderLineById(WFE_MSGGetMaster(), folderInfo, &folderLine);
  346.  
  347.     if (folderLine.flags & (MSG_FOLDER_FLAG_NEWSGROUP|MSG_FOLDER_FLAG_NEWS_HOST)) {
  348.         OnNewNewsgroup();
  349.     } else {
  350.         CNewFolderDialog( this, m_pPane, GetCurFolder() );
  351.     }
  352. }
  353.  
  354. void CFolderFrame::OnUpdateNew(CCmdUI *pCmdUI)
  355. {
  356.     MSG_FolderInfo *folderInfo = GetCurFolder();
  357.     MSG_FolderLine folderLine;
  358.     folderLine.flags = 0;
  359.     if (folderInfo)
  360.         MSG_GetFolderLineById(WFE_MSGGetMaster(), folderInfo, &folderLine);
  361.  
  362.     if (folderLine.flags & (MSG_FOLDER_FLAG_NEWSGROUP|MSG_FOLDER_FLAG_NEWS_HOST)) {
  363.         pCmdUI->SetText(szLoadString(IDS_MENU_NEWNEWSGROUP));
  364.         OnUpdateNewNewsgroup(pCmdUI);
  365.     } else {
  366.         pCmdUI->SetText(szLoadString(IDS_MENU_NEWFOLDER));
  367.         pCmdUI->Enable( TRUE );
  368.     }
  369. }
  370.  
  371. void CFolderFrame::OnUpdateView()
  372. {
  373.     DoCommand(MSG_UpdateMessageCount);
  374. }
  375.  
  376. void CFolderFrame::OnUpdateUpdateView( CCmdUI *pCmdUI )
  377. {
  378.     DoUpdateCommand(pCmdUI, MSG_UpdateMessageCount);
  379. }
  380.  
  381. void _ShutDownFrameCallBack(HWND hwnd, MSG_Pane *pane, void * closure)
  382. {
  383.     if (::IsWindow(hwnd)) {
  384.         ::ShowWindow(hwnd,SW_SHOW);
  385.         ::UpdateWindow(hwnd);
  386.     }
  387.  
  388.     if (pane)
  389.         MSG_DownloadFolderForOffline(WFE_MSGGetMaster(), pane, (MSG_FolderInfo *) closure);
  390. }
  391.  
  392.  
  393. void CFolderFrame::OnViewProperties()
  394. {
  395.     MSG_ViewIndex *indices;
  396.     int count;
  397.     BOOL bNoPropertiesNeeded = FALSE;
  398.     MSG_FolderLine folderLine;
  399.  
  400.     m_pOutliner->GetSelection( indices, count );
  401.     MSG_FolderInfo *folderInfo = MSG_GetFolderInfo( m_pPane, indices[0] );
  402.     MSG_GetFolderLineByIndex( m_pPane, indices[0], 1, &folderLine );
  403.     
  404.     CString csTitle;
  405.     if (folderLine.flags & (MSG_FOLDER_FLAG_NEWSGROUP|MSG_FOLDER_FLAG_CATEGORY)) {
  406.         csTitle.LoadString(IDS_NEWSGROUPPROP);
  407.     } else if (folderLine.flags & MSG_FOLDER_FLAG_NEWS_HOST) {
  408.         csTitle.LoadString(IDS_NEWSHOSTPROP);
  409.     } else {
  410.         if (folderLine.level > 1) {
  411.             csTitle.LoadString(IDS_FOLDERPROP);
  412.         }else {
  413.             csTitle.LoadString(IDS_MAILSERVERPROP);
  414.         }
  415.     }
  416.     CNewsFolderPropertySheet FolderSheet( csTitle, this );
  417.  
  418.     //destructor handles clean up of added sheets
  419.  
  420.     //only make and add the pages if they selected a news group or category
  421.     if ( folderLine.flags & (MSG_FOLDER_FLAG_NEWSGROUP|MSG_FOLDER_FLAG_CATEGORY) )
  422.     {
  423.         FolderSheet.m_pNewsFolderPage= new CNewsGeneralPropertyPage(&FolderSheet);
  424.         FolderSheet.m_pNewsFolderPage->SetFolderInfo( folderInfo, (MWContext*)GetContext() );
  425.  
  426.         FolderSheet.m_pDownLoadPageNews = new CDownLoadPPNews(&FolderSheet);
  427.         FolderSheet.m_pDownLoadPageNews->SetFolderInfo(folderInfo);
  428.  
  429.         FolderSheet.m_pDiskSpacePage = new CDiskSpacePropertyPage(&FolderSheet);
  430.         FolderSheet.m_pDiskSpacePage->SetFolderInfo (folderInfo );
  431.  
  432.         FolderSheet.AddPage(FolderSheet.m_pNewsFolderPage);
  433.         FolderSheet.AddPage(FolderSheet.m_pDownLoadPageNews);
  434.         FolderSheet.AddPage(FolderSheet.m_pDiskSpacePage);
  435.     }
  436.     else if ( folderLine.flags & MSG_FOLDER_FLAG_NEWS_HOST) 
  437.     {
  438.         MSG_NewsHost *pNewsHost = MSG_GetNewsHostFromIndex (m_pPane, indices[0]);
  439.         FolderSheet.m_pNewsHostPage= new CNewsHostGeneralPropertyPage;
  440.         FolderSheet.m_pNewsHostPage->SetFolderInfo( folderInfo,pNewsHost );
  441.         FolderSheet.AddPage(FolderSheet.m_pNewsHostPage);
  442.     }
  443.     else if ( folderLine.level > 1)
  444.     {
  445.         FolderSheet.m_pFolderPage= new CFolderPropertyPage(&FolderSheet);
  446.         FolderSheet.m_pFolderPage->SetFolderInfo( folderInfo, m_pPane );
  447.         FolderSheet.AddPage(FolderSheet.m_pFolderPage);
  448.         //only add this page if it's an offline mail folder.
  449.         if (folderLine.flags & MSG_FOLDER_FLAG_IMAPBOX)
  450.         {
  451.             FolderSheet.m_pDownLoadPageMail = new CDownLoadPPMail;
  452.             FolderSheet.m_pDownLoadPageMail->SetFolderInfo( folderInfo );
  453.             FolderSheet.AddPage(FolderSheet.m_pDownLoadPageMail);
  454.         }
  455.     }
  456.     else
  457.     {
  458.         wfe_DisplayPreferences((CGenericFrame*)this);
  459.         bNoPropertiesNeeded = TRUE;
  460.     }
  461.  
  462.     if ( !bNoPropertiesNeeded)
  463.     {
  464.         if(FolderSheet.DoModal() == IDOK)
  465.         {
  466.             if(FolderSheet.DownLoadNow())
  467.             {
  468.                 new CProgressDialog(this, NULL,_ShutDownFrameCallBack,
  469.                         folderInfo,szLoadString(IDS_DOWNLOADINGARTICLES));
  470.                 ;//DonwLoad!!!!!!!
  471.             }
  472.             else if (FolderSheet.CleanUpNow())
  473.             {
  474.                  MSG_Command (m_pPane, MSG_CompressFolder,
  475.                             indices, 1);
  476.             }
  477.             else if (FolderSheet.SynchronizeNow())
  478.                     ;//Synchronize!!!!
  479.         }
  480.     }
  481. }
  482.  
  483. void CFolderFrame::OnUpdateViewProperties( CCmdUI *pCmdUI )
  484. {
  485.     MSG_ViewIndex *indices;
  486.     int count;
  487.  
  488.     m_pOutliner->GetSelection( indices, count );
  489.  
  490.     MSG_FolderLine folderLine;
  491.  
  492.     MSG_FolderInfo *folderInfo = MSG_GetFolderInfo( m_pPane, indices[0] );
  493.     MSG_GetFolderLineByIndex( m_pPane, indices[0], 1, &folderLine );
  494.  
  495.     CString csTitle;
  496.     if (folderLine.flags & (MSG_FOLDER_FLAG_NEWSGROUP|MSG_FOLDER_FLAG_CATEGORY)) {
  497.         pCmdUI->SetText(szLoadString(IDS_POPUP_NEWSGROUPPROP));
  498.     } else if (folderLine.flags & MSG_FOLDER_FLAG_NEWS_HOST) {
  499.         pCmdUI->SetText(szLoadString(IDS_POPUP_NEWSHOSTPROP));
  500.     } else {
  501.         if (folderLine.level > 1) {
  502.             pCmdUI->SetText(szLoadString(IDS_POPUP_FOLDERPROP));
  503.         }else {
  504.             pCmdUI->SetText(szLoadString(IDS_POPUP_MAILSERVERPROP));
  505.         }
  506.     }
  507.  
  508.     pCmdUI->Enable( count == 1 );
  509. }
  510.  
  511. void CFolderFrame::OnMove(UINT nID)
  512. {            
  513.     if ( m_pPane ) {
  514.         MSG_FolderInfo *folderInfo = FolderInfoFromMenuID( nID );
  515.  
  516.         ASSERT(folderInfo);
  517.         if (folderInfo) {
  518.             MSG_ViewIndex *indices;
  519.             int count;
  520.             m_pOutliner->GetSelection( indices, count );
  521.  
  522.             MSG_MoveFoldersInto( m_pPane, indices, count, folderInfo);
  523.             ModalStatusBegin( MODAL_DELAY );
  524.         }
  525.     }
  526. }
  527.  
  528. void CFolderFrame::OnCopy(UINT nID)
  529. {            
  530. }
  531.  
  532. void CFolderFrame::OnUpdateFile(CCmdUI *pCmdUI)
  533. {
  534.     pCmdUI->Enable(TRUE); // WHS folders only
  535. }
  536.  
  537. void CFolderFrame::OnSelect()
  538. {
  539. }
  540.  
  541. MSG_FolderInfo *CFolderFrame::GetCurFolder() const
  542. {
  543.     MSG_FolderInfo *res = NULL;
  544.     MSG_ViewIndex *indices;
  545.     int count;
  546.     m_pOutliner->GetSelection( indices, count );
  547.  
  548.     if ( count == 1 ) {
  549.         res = MSG_GetFolderInfo( m_pPane, indices[0] );
  550.     }
  551.     return res;
  552. }
  553.  
  554. MSG_FolderInfo *CFolderFrame::FindFolder( LPCSTR lpszName, MSG_FolderInfo *root )
  555. {
  556.     MSG_Master *pMaster = WFE_MSGGetMaster();
  557.     MSG_FolderInfo *res = NULL;
  558.     MSG_FolderInfo **apFolderInfo = NULL;
  559.     int i;
  560.     int iLines  = CASTINT(MSG_GetFolderChildren ( pMaster, root, NULL, 0));
  561.  
  562.     apFolderInfo = new MSG_FolderInfo*[iLines];
  563.     ASSERT(apFolderInfo);
  564.  
  565.     if ( apFolderInfo ) {
  566.         MSG_GetFolderChildren ( pMaster, root, apFolderInfo, iLines );
  567.         for ( i = 0; i < iLines && !res; i++ ) {
  568.             MSG_FolderLine folderLine;
  569.             MSG_GetFolderLineById( pMaster, apFolderInfo[i], &folderLine );
  570.  
  571.             if ( !stricmp( folderLine.name, lpszName ) ||
  572.                  (folderLine.prettyName && !strcmp( folderLine.prettyName, lpszName )) ) {
  573.                 res = apFolderInfo[i];
  574.             } else if ( folderLine.numChildren > 0 ) {
  575.                 res = FindFolder( lpszName, apFolderInfo[i] );
  576.             }
  577.         }
  578.     }
  579.     delete [] apFolderInfo;
  580.  
  581.     return res;
  582. }
  583.  
  584. void CFolderFrame::DoOpenFolder(BOOL bReuse)
  585. {
  586.     MSG_ViewIndex *indices;
  587.     int i, count;
  588.     
  589.     m_pOutliner->GetSelection(indices, count);
  590.     for ( i = 0; i < count; i++ ) 
  591.     {
  592.         MSG_FolderLine folderLine;
  593.         if ( MSG_GetFolderLineByIndex(m_pPane, indices[i], 1, &folderLine) ) 
  594.         {
  595.             C3PaneMailFrame *pFrame = C3PaneMailFrame::FindFrame( folderLine.id );
  596.  
  597.             if ( !pFrame ) 
  598.             {
  599.                 if ( (i > 0) || !bReuse || !(pFrame = GetLastThreadFrame()) ) 
  600.                 {
  601.                     pFrame = C3PaneMailFrame::Open(folderLine.id);
  602.                 }
  603.             }
  604.  
  605.             if (pFrame)
  606.                 pFrame->ActivateFrame();
  607.         }
  608.     }
  609. }
  610.  
  611. void CFolderFrame::OnOpen( )
  612. {
  613.     if (!m_pOutliner)
  614.         return;
  615.  
  616.     BOOL bReuse = g_MsgPrefs.m_bThreadReuse;
  617.     if (GetKeyState(VK_MENU) & 0x8000)
  618.         bReuse = !bReuse;
  619.  
  620.     DoOpenFolder(bReuse);
  621. }
  622.  
  623. void CFolderFrame::OnOpenNew( )
  624. {
  625.     DoOpenFolder(FALSE);
  626. }
  627.  
  628. void CFolderFrame::OnOpenReuse( )
  629. {
  630.     DoOpenFolder(TRUE);
  631. }
  632.  
  633. void CFolderFrame::OnUpdateOpen( CCmdUI *pCmdUI )
  634. {
  635.     MSG_ViewIndex *indices;
  636.     int count;
  637.  
  638.     m_pOutliner->GetSelection( indices, count );
  639.  
  640.     if (pCmdUI->m_nID == ID_FILE_OPENFOLDER) {
  641.         CString cs;
  642.         if (count == 1) {
  643.             MSG_FolderLine folderLine;
  644.             if ( MSG_GetFolderLineByIndex(m_pPane, indices[0], 1, &folderLine) ) {
  645.                 if (folderLine.flags & MSG_FOLDER_FLAG_MAIL) {
  646.                     cs.LoadString(IDS_POPUP_OPENFOLDER);
  647.                 } else {
  648.                     cs.LoadString(IDS_POPUP_OPENNEWSGROUP);
  649.                 }
  650.             }
  651.         }
  652.         if (cs.IsEmpty()) {
  653.             cs.LoadString(IDS_POPUP_OPENSELECTION);
  654.         }
  655.         cs += szLoadString(IDS_OPENACCEL);
  656.         pCmdUI->SetText(cs);
  657.     }
  658.  
  659.     BOOL bEnable = count > 0;
  660.     for (int i = 0; i < count; i++) {
  661.         MSG_FolderLine folderLine;
  662.         if ( MSG_GetFolderLineByIndex(m_pPane, indices[0], 1, &folderLine) ) {
  663.             if (folderLine.level < 2)
  664.                 bEnable = FALSE;
  665.         } else {
  666.             bEnable = FALSE;
  667.         }
  668.     }
  669.     pCmdUI->Enable( bEnable );
  670. }
  671.  
  672. #define WFE_PREF_BITS        0x40000002
  673. #define WFE_PREF_DEFAULT    0x00000000
  674.  
  675. void CFolderFrame::SetFolderPref( MSG_FolderInfo *folderInfo, uint32 flag )
  676. {
  677.     uint32 flags = MSG_GetFolderPrefFlags( folderInfo );
  678.     if ( !(flags & MSG_FOLDER_PREF_FEVALID) ) {
  679.         flags |= WFE_PREF_DEFAULT|MSG_FOLDER_PREF_FEVALID;    
  680.     }
  681.     flags |= flag;
  682.     MSG_SetFolderPrefFlags( folderInfo, flags );
  683. }
  684.  
  685. void CFolderFrame::ClearFolderPref( MSG_FolderInfo *folderInfo, uint32 flag )
  686. {
  687.     uint32 flags = MSG_GetFolderPrefFlags( folderInfo );
  688.     if ( !(flags & MSG_FOLDER_PREF_FEVALID) ) {
  689.         flags |= WFE_PREF_DEFAULT|MSG_FOLDER_PREF_FEVALID;    
  690.     }
  691.     flags &= ~flag;
  692.     MSG_SetFolderPrefFlags( folderInfo, flags );
  693. }
  694.  
  695. BOOL CFolderFrame::IsFolderPrefSet( MSG_FolderInfo *folderInfo, uint32 flag )
  696. {
  697.     uint32 flags = MSG_GetFolderPrefFlags( folderInfo );
  698.     if ( !(flags & MSG_FOLDER_PREF_FEVALID ) ) {
  699.         flags |= WFE_PREF_DEFAULT;
  700.     }
  701.     return (flags & flag) ? TRUE : FALSE;
  702. }
  703.  
  704. void CFolderFrame::OnFileBookmark()
  705. {
  706.     FileBookmark();
  707. }
  708.  
  709. void CFolderFrame::OnUpdateFileBookmark(CCmdUI* pCmdUI) 
  710. {
  711.     pCmdUI->Enable(TRUE);
  712. }
  713.  
  714. BOOL CFolderFrame::FileBookmark()
  715. {
  716.     BOOL res = FALSE;
  717.     MSG_ViewIndex *indices;
  718.     int count;
  719.     m_pOutliner->GetSelection(indices, count);
  720.  
  721.     if (count < 1) {
  722.         HT_AddBookmark("mailbox:", (char*)(szLoadString(IDS_TITLE_COLLECTIONS))); 
  723.         // Updated to Aurora (Dave H.)
  724.         res = TRUE;
  725.     } else {
  726.         // Add bookmark to each selected folder
  727.         MSG_FolderLine folderLine;
  728.         for (int i = 0; i < count; i++) {
  729.             if (MSG_GetFolderLineByIndex(m_pPane, indices[i], 1, &folderLine)) {
  730.                 URL_Struct *url = MSG_ConstructUrlForFolder( m_pPane, folderLine.id );
  731.  
  732.                 if ( url ) {            
  733.                     const char *name = (folderLine.prettyName && folderLine.prettyName[0]) ?
  734.                                        folderLine.prettyName : folderLine.name;
  735.  
  736.                     HT_AddBookmark(url->address, (char*)name); // updated to Aurora (Dave H.)
  737.                     NET_FreeURLStruct( url );
  738.                     res = TRUE;
  739.                 }
  740.             }
  741.         }
  742.     }
  743.  
  744.     return res;
  745. }
  746.  
  747. CFolderFrame *WFE_MSGOpenFolders()
  748. {
  749.     return CFolderFrame::Open();
  750. }
  751.  
  752. CFolderFrame *WFE_MSGOpenNews()
  753. {
  754.     return CFolderFrame::OpenNews();
  755. }
  756.