home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / msgfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  21.3 KB  |  800 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. // msgfrm.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include "intl_csi.h"
  23. #include "msgcom.h"
  24. #include "prefapi.h"
  25. #include "apimsg.h"
  26. #include "wfemsg.h"
  27. #include "mailmisc.h"
  28. #include "mailpriv.h"
  29. #include "netsvw.h"
  30. #include "mailfrm.h"
  31. #include "thrdfrm.h"
  32. #include "msgfrm.h"
  33. #include "msgview.h"
  34. #include "template.h"
  35. #include "mailqf.h"
  36.  
  37. #ifdef _DEBUG
  38. #undef THIS_FILE
  39. static char THIS_FILE[] = __FILE__;
  40. #endif
  41.  
  42. #ifndef _AFXDLL
  43. #undef new
  44. #endif
  45. IMPLEMENT_DYNCREATE(CMessageFrame, CMailNewsFrame)
  46. #ifndef _AFXDLL
  47. #define new DEBUG_NEW
  48. #endif
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMessageFrame
  52.  
  53. CMessageFrame::CMessageFrame()
  54. {
  55.     m_pPane = NULL;
  56.     m_pMessagePane = NULL;
  57.  
  58.     m_bNavPending = FALSE;
  59.     m_navPending = MSG_FirstMessage;
  60.  
  61.    // All our favorite hotkeys
  62.    LoadAccelerators( IDR_ONEKEYMESSAGE );
  63.  
  64.     m_iAttachMenuPos = 2;
  65. }
  66.  
  67. CMessageFrame::~CMessageFrame()
  68. {
  69.     // Menu's destroyed for us
  70.  
  71.     if(m_hAccelTable != NULL)   {
  72.         ::FreeResource((HGLOBAL)m_hAccelTable);
  73.         m_hAccelTable = NULL;
  74.     }
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CMessageFrame Overloaded methods
  79.  
  80. extern UINT MailCodes[10];
  81. extern int MailIndices[10];
  82.  
  83. extern UINT NewsCodes[10];
  84. extern int NewsIndices[10];
  85.  
  86. BOOL CMessageFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  87. {
  88.     // Skip up to CGenericFrame, since CMailNewsFrame doesn't call it
  89.     BOOL res = CGenericFrame::OnCreateClient( lpcs, pContext );
  90.     if (res) {
  91.         CWnd *pView = GetDescendantWindow(IDW_MESSAGE_PANE, TRUE);
  92.         ASSERT(pView);
  93.  
  94.         CWinCX *pWinCX;
  95.         pWinCX = new CWinCX((CGenericDoc *) pContext->m_pCurrentDoc, 
  96.                             this,
  97.                             (CGenericView *)pView);
  98.  
  99.         pView = GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
  100.         m_pMessageView = DYNAMIC_DOWNCAST(CMessageView, pView);
  101.         ASSERT(m_pMessageView);
  102.  
  103.         SetMainContext(pWinCX);
  104.         SetActiveContext(pWinCX);
  105.  
  106.         RECT rect;
  107.         GetClientRect(&rect);
  108.         pWinCX->Initialize(FALSE, &rect);
  109.         pWinCX->GetContext()->type = MWContextMailMsg;
  110.         pWinCX->GetContext()->fancyFTP = TRUE;
  111.         pWinCX->GetContext()->fancyNews = TRUE;
  112.         pWinCX->GetContext()->intrupt = FALSE;
  113.         pWinCX->GetContext()->reSize = FALSE;
  114.  
  115.         m_pMaster = WFE_MSGGetMaster();
  116.         m_pPane = MSG_CreateMessagePane( pWinCX->GetContext(), m_pMaster );
  117.         m_pMessagePane = m_pPane;
  118.  
  119.         MSG_SetFEData(m_pPane, (LPVOID) (LPUNKNOWN) this );
  120.         MSG_SetMessagePaneCallbacks(m_pMessagePane, &MsgPaneCB, NULL);
  121.     }
  122.  
  123.     return res;
  124. }
  125.  
  126. void CMessageFrame::DoUpdateNavigate( CCmdUI* pCmdUI, MSG_MotionType msgCommand )
  127. {
  128.     XP_Bool enable = FALSE;
  129.  
  130.     if ( m_pMessagePane ) {
  131.         MSG_FolderInfo* folder;
  132.         MessageKey        key;
  133.         MSG_ViewIndex    viewIndex;
  134.  
  135.         MSG_GetCurMessage( m_pMessagePane,
  136.                            &folder,
  137.                            &key,
  138.                            &viewIndex);
  139.  
  140.         if ( key != MSG_MESSAGEKEYNONE ) {
  141.             if ((int) viewIndex >= 0) {
  142.                 MSG_NavigateStatus(m_pMessagePane, msgCommand, viewIndex, &enable, NULL);
  143.             }
  144.         }
  145.     }
  146.  
  147.     pCmdUI->Enable(enable);
  148. }
  149.  
  150. void CMessageFrame::DoNavigate( MSG_MotionType msgCommand )
  151. {
  152.     if ( m_pMessagePane ) {
  153.         MSG_FolderInfo* folder, *newFolder = NULL;
  154.         MessageKey        key;
  155.         MSG_ViewIndex    viewIndex;
  156.  
  157.         MSG_GetCurMessage( m_pMessagePane,
  158.                            &folder,
  159.                            &key,
  160.                            &viewIndex);
  161.  
  162.         if ( key != MSG_MESSAGEKEYNONE ) {
  163.             MessageKey        resultId = MSG_MESSAGEKEYNONE;
  164.             MSG_ViewIndex    resultIndex = viewIndex;
  165.             MSG_ViewIndex    threadIndex;
  166.  
  167.             MSG_ViewNavigate( m_pMessagePane, msgCommand,
  168.                               viewIndex, 
  169.                               &resultId, &resultIndex, &threadIndex, &newFolder);
  170.                 
  171.             if ( resultId != MSG_MESSAGEKEYNONE ) {
  172.                 if ( ( resultId != key ) ) {
  173.                     if (newFolder && folder != newFolder)
  174.                         LoadMessage(newFolder, resultId);
  175.                     else
  176.                         LoadMessage(folder, resultId);
  177.                 }
  178.             } else if ( newFolder != NULL) {
  179.                 m_bNavPending = TRUE;
  180.                 m_navPending = msgCommand;
  181.                 MSG_LoadFolder(m_pPane, newFolder);
  182.             }
  183.         }
  184.         m_pInfoBar->Update();
  185.     }
  186. }
  187.  
  188. BEGIN_MESSAGE_MAP(CMessageFrame, CMailNewsFrame)
  189.     ON_WM_CLOSE()
  190.     ON_WM_CREATE()
  191.     ON_WM_DESTROY()
  192.     ON_MESSAGE(TB_FILLINTOOLTIP, OnFillInToolTip)
  193.  
  194.     // Edit Menu Items
  195.     ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  196.     ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
  197.  
  198.     // Message Menu Items
  199.  
  200.     ON_COMMAND(ID_MESSAGE_STOP, OnStop)
  201.     ON_UPDATE_COMMAND_UI(ID_MESSAGE_STOP, OnUpdateStop )
  202.     ON_COMMAND(ID_MESSAGE_REUSE, OnReuse)
  203.     ON_UPDATE_COMMAND_UI(ID_MESSAGE_REUSE, OnUpdateReuse)
  204.  
  205.     ON_COMMAND(ID_MESSAGE_CONTINUE, OnContinue)
  206.     ON_COMMAND(ID_NAVIGATE_CONTAINER, OnContainer)
  207.     ON_UPDATE_COMMAND_UI(ID_NAVIGATE_CONTAINER, OnUpdateContainer )
  208.  
  209. #ifdef ON_COMMAND_RANGE
  210.     ON_COMMAND_RANGE(FIRST_MOVE_MENU_ID, LAST_MOVE_MENU_ID, OnMove )
  211.     ON_COMMAND_RANGE(FIRST_COPY_MENU_ID, LAST_COPY_MENU_ID, OnCopy )
  212.     ON_UPDATE_COMMAND_UI_RANGE( FIRST_MOVE_MENU_ID, LAST_MOVE_MENU_ID, OnUpdateFile )
  213.     ON_UPDATE_COMMAND_UI_RANGE( FIRST_COPY_MENU_ID, LAST_COPY_MENU_ID, OnUpdateFile )
  214. #endif
  215.  
  216.     ON_UPDATE_COMMAND_UI( ID_MESSAGE_FILE, OnUpdateFile )
  217. END_MESSAGE_MAP()
  218.  
  219. #ifndef ON_COMMAND_RANGE
  220.  
  221. BOOL CMessageFrame::OnCommand( WPARAM wParam, LPARAM lParam )
  222. {
  223.     UINT nID = wParam;
  224.  
  225.     if ( nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID ) {
  226.         OnMove( nID );
  227.         return TRUE;
  228.     }
  229.     if ( nID >= FIRST_COPY_MENU_ID && nID <= LAST_COPY_MENU_ID ) {
  230.         OnCopy( nID );
  231.         return TRUE;
  232.     }
  233.     return CMailNewsFrame::OnCommand( wParam, lParam );
  234. }
  235.  
  236. BOOL CMessageFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  237.     if (nCode == CN_UPDATE_COMMAND_UI) {
  238.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  239.         if ( nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID ) {
  240.             OnUpdateFile( pCmdUI );
  241.             return TRUE;
  242.         }
  243.         if ( nID >= FIRST_COPY_MENU_ID && nID <= LAST_COPY_MENU_ID ) {
  244.             OnUpdateFile( pCmdUI );
  245.             return TRUE;
  246.         }
  247.     }
  248.     return CMailNewsFrame::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  249. }
  250.  
  251. #endif
  252.  
  253. /////////////////////////////////////////////////////////////////////////////
  254. // CMessageFrame message handlers
  255.  
  256. static const UINT BASED_CODE indicators[] =
  257. {
  258.     IDS_SECURITY_STATUS,
  259.     IDS_SIGNED_STATUS,
  260.     IDS_TRANSFER_STATUS,    
  261.     ID_SEPARATOR,
  262.     IDS_TASKBAR
  263. };
  264.  
  265. int CMessageFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  266. {
  267.     int res = CMailNewsFrame::OnCreate(lpCreateStruct);
  268.  
  269.     // Set up toolbar
  270.     m_pChrome->SetWindowTitle(XP_AppName);
  271.  
  272.     //I'm hardcoding string since I don't want it translated.
  273.     m_pChrome->CreateCustomizableToolbar("Messages"/*ID_MESSAGES*/, 3, TRUE);
  274.     CButtonToolbarWindow *pWindow;
  275.     BOOL bOpen, bShowing;
  276.  
  277.     int32 nPos;
  278.  
  279.     //I'm hardcoding because I don't want this translated
  280.     m_pChrome->LoadToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"), nPos, bOpen, bShowing);
  281.  
  282.     LPNSTOOLBAR pIToolBar;
  283.     m_pChrome->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  284.     if ( pIToolBar ) {
  285.         pIToolBar->Create( this, WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|CBRS_TOP );
  286.         pIToolBar->SetToolbarStyle( theApp.m_pToolbarStyle);
  287.         SwitchUI();
  288.         pWindow = new CButtonToolbarWindow(CWnd::FromHandlePermanent(pIToolBar->GetHWnd()), theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  289.         m_pChrome->GetCustomizableToolbar()->AddNewWindow(ID_NAVIGATION_TOOLBAR, pWindow,nPos, 50, 37, 0, CString(szLoadString(ID_NAVIGATION_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  290.         m_pChrome->ShowToolbar(ID_NAVIGATION_TOOLBAR, bShowing);
  291.  
  292.         pIToolBar->Release();
  293.     }
  294.  
  295.     m_pInfoBar = new CMessageInfoBar;
  296.     m_pInfoBar->Create( this, m_pPane );
  297.  
  298.     //I'm hardcoding because I don't want this translated
  299.     m_pChrome->LoadToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"), nPos, bOpen, bShowing);
  300.  
  301.     CToolbarWindow *pToolWindow = new CToolbarWindow(m_pInfoBar, theApp.m_pToolbarStyle, 27, 27, eSMALL_HTAB);
  302.     m_pChrome->GetCustomizableToolbar()->AddNewWindow(ID_LOCATION_TOOLBAR, pToolWindow,nPos, 27, 27, 0, CString(szLoadString(ID_LOCATION_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  303.     m_pChrome->ShowToolbar(ID_LOCATION_TOOLBAR, bShowing);
  304.  
  305.     m_barStatus.Create(this, TRUE, TRUE);
  306.     m_barStatus.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
  307.     LPNSSTATUSBAR pIStatusBar = NULL;
  308.     m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  309.     if ( pIStatusBar ) {
  310.         pIStatusBar->Attach(&m_barStatus);
  311.         pIStatusBar->Release();
  312.     }
  313.  
  314.     return res;
  315. }
  316.  
  317. void CMessageFrame::OnClose() 
  318. {
  319.     int16 left, top, width, height;
  320.     int32 prefInt;
  321.     WINDOWPLACEMENT wp;
  322.     wp.length = sizeof(WINDOWPLACEMENT);
  323.     GetWindowPlacement(&wp);
  324.     CRect rect(wp.rcNormalPosition);
  325.  
  326.     left = (int16) rect.left;
  327.     top = (int16) rect.top;
  328.     width = (int16) rect.Width();
  329.     height = (int16) rect.Height();
  330.     prefInt = wp.showCmd;
  331.  
  332.     PREF_SetRectPref("mailnews.message_window_rect", left, top, width, height);
  333.     PREF_SetIntPref("mailnews.message_window_showwindow", prefInt);
  334.  
  335.     //I'm hardcoding because I don't want this translated
  336.     m_pChrome->SaveToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"));
  337.     m_pChrome->SaveToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"));
  338.  
  339.     CMailNewsFrame::OnClose();
  340. }
  341.  
  342. void CMessageFrame::OnDestroy()
  343. {
  344.     if (m_pAttachmentData)
  345.         MSG_FreeAttachmentList(m_pMessagePane, m_pAttachmentData);
  346.     m_pAttachmentData = NULL;
  347.     m_pMessagePane = NULL;
  348.  
  349.     CMailNewsFrame::OnDestroy();
  350.  
  351.     CView *pView = (CView *) GetDescendantWindow(IDW_MESSAGE_PANE, TRUE);
  352.  
  353.     ASSERT(pView && pView->IsKindOf(RUNTIME_CLASS(CNetscapeView)));
  354.  
  355.     if(pView)
  356.         ((CNetscapeView *)pView)->FrameClosing();
  357. }
  358.  
  359. LRESULT CMessageFrame::OnFillInToolTip(WPARAM wParam, LPARAM lParam)
  360. {
  361.     HWND hwnd = (HWND)wParam;
  362.     LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam;
  363.  
  364.     CToolbarButton *pButton = (CToolbarButton *) CWnd::FromHandle(hwnd);
  365.     UINT nCommand = pButton->GetButtonCommand();
  366.     LPCSTR pTipText = pButton->GetToolTipText();
  367.     LPCSTR pText = NULL;
  368.     CString cs;
  369.  
  370.     if( nCommand == ID_NAVIGATE_CONTAINER ) 
  371.     {
  372.         MSG_FolderLine folderLine;
  373.         MSG_FolderInfo *folderInfo = GetCurFolder();
  374.  
  375.         // XXX WHS Int'lize
  376.         if ( MSG_GetFolderLineById( WFE_MSGGetMaster(), folderInfo, &folderLine ) ) {
  377.             cs.Format("Open %s", folderLine.prettyName ? folderLine.prettyName : folderLine.name );
  378.             pText = (LPCSTR) cs;
  379.         }
  380.     }
  381.  
  382.     lpttt->szText[79] = '\0';
  383.     if( !pText || !pText[0] )
  384.         strncpy(lpttt->szText, pTipText, 79);
  385.     else
  386.         strncpy(lpttt->szText, pText, 79);
  387.  
  388.     return 1;
  389. }
  390.  
  391. // Edit Menu Items
  392.  
  393. void CMessageFrame::OnEditUndo()
  394. {
  395.     DoCommand(MSG_Undo);
  396.     MessageKey key = MSG_MESSAGEKEYNONE;
  397.     MSG_FolderInfo *folder = NULL;
  398.  
  399.     if ( UndoComplete == MSG_GetUndoStatus(m_pPane) ) {
  400.         if (MSG_GetUndoMessageKey(m_pPane, &folder, &key) && folder) 
  401.             LoadMessage(folder, key);
  402.     }
  403. }
  404.  
  405. void CMessageFrame::OnEditRedo()
  406. {
  407.     DoCommand(MSG_Redo);
  408.     MessageKey key = MSG_MESSAGEKEYNONE;
  409.     MSG_FolderInfo *folder = NULL;
  410.  
  411.     if ( UndoComplete == MSG_GetUndoStatus(m_pPane) ) {
  412.         if (MSG_GetUndoMessageKey(m_pPane, &folder, &key) && folder)
  413.             LoadMessage(folder, key);
  414.     }
  415. }
  416.  
  417. // Message Menu Items
  418.  
  419. void CMessageFrame::OnContinue()
  420. {
  421.     CWinCX * pCX = GetMainWinContext();
  422.  
  423.     if(pCX->GetOriginY() + pCX->GetHeight() < pCX->GetDocumentHeight()) {
  424.         pCX->Scroll(SB_VERT, SB_PAGEDOWN, 0, NULL);
  425.     } else if (!pCX->IsLayingOut()) {
  426.         DoNavigate( MSG_NextUnreadMessage );
  427.     }
  428. }
  429.  
  430. void CMessageFrame::OnContainer()
  431. {
  432.     MSG_FolderInfo* folderInfo;
  433.     MessageKey        key;
  434.     MSG_ViewIndex    viewIndex;
  435.  
  436.     MSG_GetCurMessage( m_pPane,
  437.                        &folderInfo,
  438.                        &key,
  439.                        &viewIndex);
  440.  
  441.     C3PaneMailFrame::Open( folderInfo, key );
  442. }
  443.  
  444. void CMessageFrame::OnUpdateContainer( CCmdUI * pCmdUI )
  445. {
  446.     MSG_FolderInfo* folderInfo;
  447.     MessageKey        key;
  448.     MSG_ViewIndex    viewIndex;
  449.  
  450.     MSG_GetCurMessage( m_pPane,
  451.                        &folderInfo,
  452.                        &key,
  453.                        &viewIndex);
  454.  
  455.     pCmdUI->Enable( folderInfo ? TRUE : FALSE );
  456. }
  457.  
  458. void CMessageFrame::OnStop() 
  459. {
  460.     //      Let the context have it.
  461.     if(GetMainContext()) {
  462.         GetMainContext()->AllInterrupt();
  463.     }
  464. }
  465.  
  466. void CMessageFrame::OnUpdateStop(CCmdUI* pCmdUI) 
  467. {
  468.     //      Defer to the context's wisdom.
  469.     if(GetMainContext()) {
  470.         pCmdUI->Enable(GetMainContext()->CanAllInterrupt());
  471.     }
  472.     else {
  473.         pCmdUI->Enable(FALSE);
  474.     }
  475. }
  476.  
  477. void CMessageFrame::OnMove(UINT nID)
  478. {
  479.     if ( m_pPane ) {
  480.         MSG_FolderInfo *folderInfoCur;
  481.         MSG_ViewIndex idxCur;
  482.         MessageKey idCur;
  483.         MSG_GetCurMessage( m_pPane, &folderInfoCur, &idCur, &idxCur );
  484.  
  485.         MSG_FolderInfo *folderInfo = FolderInfoFromMenuID( nID );
  486.  
  487.         ASSERT(folderInfo);
  488.         if (folderInfo) {
  489.             MSG_FolderLine folderLine;
  490.             MSG_GetFolderLineById( WFE_MSGGetMaster(), folderInfo, &folderLine );
  491.  
  492.             // We want to make file behave for newsgroups
  493.             if ( folderLine.flags & MSG_FOLDER_FLAG_NEWSGROUP ) {
  494.                 MSG_CopyMessagesIntoFolder( m_pPane, &idxCur, 1, folderInfo);
  495.             } else {
  496.                 MSG_MoveMessagesIntoFolder( m_pPane, &idxCur, 1, folderInfo);
  497.             }
  498.             ModalStatusBegin( MODAL_DELAY );
  499.         }
  500.     }
  501. }
  502.  
  503. void CMessageFrame::OnCopy(UINT nID)
  504. {            
  505.     if ( m_pPane ) {
  506.         MSG_FolderInfo *folderInfoCur;
  507.         MSG_ViewIndex idxCur;
  508.         MessageKey idCur;
  509.         MSG_GetCurMessage( m_pPane, &folderInfoCur, &idCur, &idxCur );
  510.  
  511.         MSG_FolderInfo *folderInfo = FolderInfoFromMenuID( nID );
  512.  
  513.         ASSERT(folderInfo);
  514.         if (folderInfo) {
  515.             MSG_CopyMessagesIntoFolder( m_pPane, &idxCur, 1, folderInfo);
  516.             ModalStatusBegin( MODAL_DELAY );
  517.         }
  518.     }
  519. }
  520.  
  521. void CMessageFrame::OnUpdateFile( CCmdUI *pCmdUI )
  522. {
  523.     MessageKey key = GetCurMessage();
  524.     BOOL bEnable = key != MSG_MESSAGEKEYNONE;
  525.     if (pCmdUI->m_pSubMenu) {
  526.         pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex,
  527.                                         MF_BYPOSITION |(bEnable ? MF_ENABLED : MF_GRAYED));
  528.     } else {
  529.         pCmdUI->Enable( bEnable );
  530.     }
  531. }
  532.  
  533. // IMailFrame override
  534. void CMessageFrame::PaneChanged( MSG_Pane *pane, XP_Bool asynchronous, 
  535.                                  MSG_PANE_CHANGED_NOTIFY_CODE notify, int32 value)
  536. {
  537.     if ( notify == MSG_PaneNotifyLastMessageDeleted ||
  538.          notify == MSG_PaneNotifyMessageDeleted ) {
  539.         PostMessage( WM_CLOSE, (WPARAM) 0, (LPARAM) 0 );
  540.     } else if (notify == MSG_PaneNotifyFolderLoaded) {
  541.         MSG_FolderInfo *folderInfo = GetCurFolder();
  542.         MessageKey key = MSG_MESSAGEKEYNONE;
  543.  
  544.         if (m_bNavPending) {
  545.             switch ( m_navPending ) {
  546.             case MSG_Forward:
  547.             case MSG_Back:
  548.                 ASSERT(0);
  549.                 break;
  550.  
  551.             case MSG_NextFolder:
  552.             case MSG_NextMessage:
  553.                 DoNavigate(MSG_FirstMessage);
  554.                 break;
  555.  
  556.             case MSG_NextUnreadMessage:
  557.             case MSG_NextUnreadThread:
  558.             case MSG_NextUnreadGroup:
  559.             case MSG_LaterMessage:
  560.                 m_navPending = MSG_NextUnreadMessage;
  561.  
  562.             default:
  563.                 DoNavigate( m_navPending );
  564.                 break;
  565.             }
  566.         }
  567.         m_bNavPending = FALSE;
  568.     } else if (notify == MSG_PaneNotifyMessageLoaded) {
  569.         if (MSG_GetBacktrackState(pane) == MSG_BacktrackIdle)
  570.             MSG_AddBacktrackMessage(pane, GetCurFolder(), (MessageKey) value);
  571.         else
  572.             MSG_SetBacktrackState(pane, MSG_BacktrackIdle);
  573.     }
  574.     m_pInfoBar->Update();
  575. }
  576.  
  577.  
  578. void CMessageFrame::SwitchUI( )
  579. {
  580.     LPNSTOOLBAR pIToolBar;
  581.     m_pChrome->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  582.     if ( pIToolBar ) {
  583.         CWnd *pToolWnd = CWnd::FromHandlePermanent( pIToolBar->GetHWnd() );
  584.  
  585.         if ( pToolWnd ) {
  586.             pIToolBar->RemoveAllButtons();
  587.  
  588.             UINT *aidButtons = m_bNews ? NewsCodes : MailCodes;
  589.             int *aidxButtons = m_bNews ? NewsIndices : MailIndices;
  590.  
  591.             int nButtons = (m_bNews ? sizeof(NewsCodes) : sizeof(MailCodes)) /sizeof(UINT);
  592.             for(int i = 0; i < nButtons; i++)
  593.             {
  594.                 if ( aidButtons[i] == ID_MESSAGE_FILE ) {
  595.                     CMailQFButton *pFileButton = new CMailQFButton;
  596.                     pFileButton->Create( CRect(0,0,0,0), pToolWnd, ID_MESSAGE_FILE);
  597.                     pIToolBar->AddButton(pFileButton, i);
  598.                 } else {
  599.                     CString statusStr, toolTipStr, textStr;
  600.                     CCommandToolbarButton *pCommandButton = new CCommandToolbarButton;
  601.                  
  602.                     WFE_ParseButtonString( aidButtons[i], statusStr, toolTipStr, textStr );
  603.                     DWORD dwButtonStyle = 0;
  604.  
  605.                     switch (aidButtons[i]) {
  606.                     case ID_MESSAGE_REPLYBUTTON:
  607.                     case ID_MESSAGE_MARKBUTTON:
  608.                         dwButtonStyle |= TB_HAS_IMMEDIATE_MENU;
  609.                         break;
  610.  
  611.                     case ID_MESSAGE_NEXTUNREAD:
  612.                         dwButtonStyle |= TB_HAS_TIMED_MENU;
  613.                         break;
  614.  
  615.                     case ID_NAVIGATE_MSG_BACK:
  616.                         break;
  617.                     default:
  618.                         break;
  619.                     }
  620.  
  621.  
  622.                     pCommandButton->Create( pToolWnd, theApp.m_pToolbarStyle, 
  623.                                             CSize(44, 37), CSize(25, 25),
  624.                                             textStr, toolTipStr, statusStr,
  625.                                             m_bNews ? IDR_NEWSTHREAD : IDR_MAILTHREAD,
  626.                                             aidxButtons[i], CSize(23,21), 
  627.                                             aidButtons[i], -1, dwButtonStyle);
  628.  
  629.                     pIToolBar->AddButton(pCommandButton, i);
  630.                 }
  631.             }
  632.         }
  633.         pIToolBar->Release();
  634.     }
  635.  
  636.     CString csFullString, cs;
  637.     csFullString.LoadString( m_bNews ? IDR_NEWSMSGFRAME : IDR_MESSAGEFRAME );
  638.     AfxExtractSubString( cs, csFullString, 0 );
  639.     m_pChrome->SetWindowTitle(cs);
  640.  
  641. #ifdef _WIN32
  642.     if (sysInfo.m_bWin4) {
  643.         UINT nIDIcon = m_bNews ? IDR_NEWSTHREAD : IDR_MAILTHREAD;
  644.         HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(nIDIcon), RT_GROUP_ICON);
  645.         HICON hLargeIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(nIDIcon));
  646.         SetIcon(hLargeIcon, TRUE);
  647.  
  648.         HICON hSmallIcon = (HICON) ::LoadImage(hInst, 
  649.                                                MAKEINTRESOURCE(nIDIcon),
  650.                                                IMAGE_ICON, 
  651.                                                GetSystemMetrics(SM_CXSMICON),
  652.                                                GetSystemMetrics(SM_CYSMICON),
  653.                                                LR_SHARED);
  654.         SetIcon(hSmallIcon, FALSE);
  655.     }
  656. #endif
  657. }
  658.  
  659. void CMessageFrame::SetIsNews( BOOL bNews )
  660. {
  661.     if ( bNews != m_bNews ) {
  662.         m_bNews = bNews;
  663.         SwitchUI();
  664.     }
  665. }
  666.  
  667. void CMessageFrame::LoadMessage( MSG_FolderInfo *folderInfo, MessageKey id )
  668. {
  669.     INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo( GetMainContext()->GetContext() );
  670.     int16 cur_csid = INTL_GetCSIDocCSID( c );
  671.     int16 doc_csid = MSG_GetFolderCSID( folderInfo );
  672.  
  673.     if (!doc_csid)
  674.         doc_csid = INTL_DefaultWinCharSetID(0);
  675.  
  676.     if ( cur_csid != doc_csid )
  677.         RefreshNewEncoding( doc_csid, FALSE );
  678.  
  679.     MSG_LoadMessage( m_pPane, folderInfo, id );
  680.  
  681.     if (id == MSG_MESSAGEKEYNONE)
  682.         m_pMessageView->SetAttachments(NULL, 0);
  683.     else
  684.         MSG_AddBacktrackMessage( m_pPane, folderInfo, id );
  685.  
  686.     MSG_FolderLine folderLine;
  687.     MSG_MessageLine messageLine;
  688.     MSG_GetFolderLineById( m_pMaster, folderInfo, &folderLine );
  689.     MSG_GetThreadLineById( m_pPane, id, &messageLine );
  690.  
  691.     SetIsNews( folderLine.flags & MSG_FOLDER_FLAG_NEWSGROUP ? TRUE : FALSE );
  692.     m_bCategory = (folderLine.flags & MSG_FOLDER_FLAG_CATEGORY ? TRUE : FALSE);
  693.  
  694.     m_pInfoBar->Update();
  695. }
  696.  
  697. void CMessageFrame::OnReuse()
  698. {
  699. }
  700.  
  701. void CMessageFrame::OnUpdateReuse(CCmdUI* pCmdUI)
  702. {
  703. }
  704.  
  705. MessageKey CMessageFrame::GetCurMessage() const
  706. {
  707.     MessageKey key = MSG_MESSAGEKEYNONE;
  708.     if (m_pPane) {
  709.         MSG_ViewIndex index = (MSG_ViewIndex) -1;
  710.         MSG_FolderInfo *folderInfo = NULL;
  711.  
  712.         MSG_GetCurMessage( m_pPane, &folderInfo, &key, &index );
  713.     }
  714.     return key;
  715. }
  716.  
  717. MSG_FolderInfo *CMessageFrame::GetCurFolder() const
  718. {
  719.     MessageKey key = MSG_MESSAGEKEYNONE;
  720.     MSG_ViewIndex index = (MSG_ViewIndex) -1;
  721.     MSG_FolderInfo *folderInfo = NULL;
  722.  
  723.     MSG_GetCurMessage( m_pPane, &folderInfo, &key, &index );
  724.  
  725.     return folderInfo;
  726. }
  727.  
  728. LPCTSTR CMessageFrame::GetWindowMenuTitle()
  729. {
  730.     static CString cs;
  731.     CString csTitle = szLoadString( IDS_TITLE_NOSUBJECT );
  732.     cs = m_bNews ? szLoadString( IDS_TITLE_ARTICLE ) : szLoadString( IDS_TITLE_MESSAGE );
  733.     
  734.     MWContext *pXPCX = GetMainContext()->GetContext();
  735.     if ( pXPCX && pXPCX->title) {
  736.         csTitle = fe_MiddleCutString(pXPCX->title, 40);
  737.     }
  738.     cs += csTitle;
  739.  
  740.     return cs;
  741. }
  742.  
  743. CMessageFrame *CMessageFrame::FindFrame( MSG_FolderInfo *folderInfo, MessageKey key )
  744. {
  745.     CGenericFrame *pFrame = theApp.m_pFrameList;
  746.  
  747.     while ( pFrame  ) {
  748.         if ( pFrame->IsKindOf( RUNTIME_CLASS( CMessageFrame ) ) ) {
  749.             MSG_Pane *pPane = ((CMessageFrame *) pFrame)->GetPane();
  750.             ASSERT( MSG_GetPaneType( pPane ) == MSG_MESSAGEPANE );
  751.  
  752.             MSG_FolderInfo *folderInfo2;
  753.             MessageKey key2;
  754.             MSG_ViewIndex index;
  755.             MSG_GetCurMessage( pPane, &folderInfo2, &key2, &index );
  756.  
  757.             if ( (folderInfo == folderInfo2) && ( key == key2 ) ) {
  758.                 return (CMessageFrame *) pFrame;
  759.             }
  760.         }
  761.         pFrame = pFrame->m_pNext;
  762.     }
  763.     return NULL;
  764. }
  765.  
  766. CMessageFrame *CMessageFrame::Open()
  767. {
  768.     if (!CheckWizard())
  769.         return NULL;
  770.  
  771.     CMessageFrame *pFrame = NULL;
  772.     CGenericDoc *pDoc;
  773.     pDoc = (CGenericDoc *) g_MsgPrefs.m_pMsgTemplate->OpenDocumentFile(NULL);
  774.  
  775.     if ( pDoc )
  776.     {
  777.         CWinCX * pContext = ((CWinCX*)pDoc->GetContext());
  778.  
  779.         if ( pContext ) {
  780.             pFrame = (CMessageFrame *) pContext->GetFrame()->GetFrameWnd();
  781.         }
  782.     }
  783.  
  784.     return pFrame;
  785. }
  786.  
  787. CMessageFrame *CMessageFrame::Open( MSG_FolderInfo *folderInfo, MessageKey key )
  788. {
  789.     CMessageFrame *pFrame = FindFrame( folderInfo, key );
  790.  
  791.     if (!pFrame) {
  792.         pFrame = CMessageFrame::Open();
  793.         if ( pFrame ) {
  794.             pFrame->LoadMessage( folderInfo, key );
  795.         }
  796.     }
  797.     return pFrame;
  798. }
  799.