home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mailqf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.2 KB  |  403 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 "dropmenu.h"
  21. #include "mailqf.h"
  22. #include "wfemsg.h"
  23. #include "mailmisc.h"
  24. #include "mailfrm.h"
  25.  
  26. /////////////////////////////////////////////////////////////////////
  27. // CMailQFMenuDropTarget
  28.  
  29. class CMailQFMenuDropTarget: public CDropMenuDropTarget
  30. {
  31. public:
  32.     CMailQFMenuDropTarget(CWnd *pOwner);
  33.      
  34. protected:
  35.     virtual DROPEFFECT OnDragEnter(CWnd * pWnd,
  36.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point);
  37.     virtual DROPEFFECT OnDragOver(CWnd * pWnd,
  38.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point );
  39.     virtual BOOL OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  40.             DROPEFFECT dropEffect, CPoint point);
  41.     
  42. };
  43.  
  44. /////////////////////////////////////////////////////////////////////
  45. // CMailQFButton
  46.  
  47. CMailQFButton::CMailQFButton(): CMailQFButtonParent()
  48. {
  49.     m_pDropMenu = new CMailQFDropMenu;
  50.     m_hFolderBitmap = NULL;
  51.     m_hSelectedFolderBitmap = NULL;
  52. }
  53.  
  54. CMailQFButton::~CMailQFButton()
  55. {
  56.     m_pDropMenu->DestroyDropMenu();
  57.     delete m_pDropMenu;
  58.     if(m_hFolderBitmap)
  59.         DeleteObject(m_hFolderBitmap);
  60. }
  61.  
  62. BOOL CMailQFButton::Create(const CRect & rect, CWnd* pwndParent, UINT uID)
  63. {
  64.     CString csLabel, csTip, csStatus;
  65.     
  66.     WFE_ParseButtonString( ID_MESSAGE_FILE, csStatus, csTip, csLabel );
  67.     
  68.     BOOL bRtn = CMailQFButtonParent::Create(pwndParent, theApp.m_pToolbarStyle, CSize(50, 40), CSize(30, 27), 
  69.                     csLabel, csTip, csStatus, 
  70.                     IDR_MAILTHREAD, 4, CSize(23, 21), TRUE, uID, 10);
  71.  
  72.     m_DropTarget.Register(this);
  73.     
  74.     if(bRtn){
  75.         HINSTANCE hInst = AfxGetResourceHandle();
  76.         HDC hDC = ::GetDC(m_hWnd);
  77.         WFE_InitializeUIPalette(hDC);
  78.         m_hFolderBitmap = WFE_LoadTransparentBitmap(hInst, hDC, sysInfo.m_clrMenu, RGB(255, 0, 255),
  79.                                              WFE_GetUIPalette(GetParentFrame()), IDB_MAILFOLDER);
  80.         m_hSelectedFolderBitmap = WFE_LoadTransparentBitmap(hInst, hDC,sysInfo.m_clrHighlight,
  81.                                                      RGB(255, 0, 255), WFE_GetUIPalette(GetParentFrame()), IDB_MAILFOLDEROPEN);
  82.  
  83.         ::ReleaseDC(m_hWnd, hDC);
  84.     }
  85.  
  86.     return(bRtn);
  87.  
  88. }
  89.  
  90.  
  91. void CMailQFButton::OnPaletteChanged( CWnd* pFocusWnd )
  92. {
  93.     if (pFocusWnd != this) {
  94.         HPALETTE hPalette = WFE_GetUIPalette(GetParentFrame());
  95.         HDC hDC = ::GetDC(m_hWnd);
  96.         HPALETTE hOldPalette = ::SelectPalette(hDC, hPalette, TRUE);
  97.         ::SelectPalette(hDC, hOldPalette, FALSE);
  98.         ::ReleaseDC(m_hWnd, hDC);
  99.         Invalidate();
  100.     }
  101. }
  102.  
  103.  
  104. void CMailQFButton::OnAction()
  105. {
  106.     OnBtnClicked(FALSE);
  107. }
  108.  
  109. void CMailQFButton::BuildMenu( MSG_FolderInfo *folderInfo, CDropMenu *pMenu, UINT &nID )
  110. {
  111.     MSG_Master *master = WFE_MSGGetMaster();
  112.     int32 iCount = MSG_GetFolderChildren( master, folderInfo, NULL, 0 );
  113.  
  114.     MSG_FolderInfo **folderInfos = new MSG_FolderInfo*[iCount];
  115.     if ( iCount && folderInfos ) {
  116.         MSG_GetFolderChildren( master, folderInfo, folderInfos, iCount );
  117.  
  118.         for ( int i = 0; i < iCount; i++ ) {
  119.             MSG_FolderLine folderLine;
  120.             
  121.             if ( MSG_GetFolderLineById( master, folderInfos[i], &folderLine ) ) {
  122.                 if ( folderLine.numChildren > 0 ) {
  123.                     CDropMenu *pNewMenu = new CMailQFDropMenu;
  124.                     pMenu->AppendMenu(MF_POPUP, nID, pNewMenu, FALSE, folderLine.name, FALSE, m_hFolderBitmap, m_hSelectedFolderBitmap);
  125.                     nID++;
  126.                     BuildMenu( folderInfos[i], pNewMenu, nID );
  127.                 } else {
  128.                     pMenu->AppendMenu(MF_STRING, nID, folderLine.name, FALSE, m_hFolderBitmap, m_hSelectedFolderBitmap);
  129.                     nID++;
  130.                 }
  131.             }
  132.         }
  133.     }
  134. }
  135.  
  136. void CMailQFButton::BuildMenu()
  137. {
  138.     // *** If you change the way this menu is built, you also need to
  139.     // change CMailNewsFrame::FolderInfoFromMenuID and make it the same
  140.     // as CMailNewsFrame::UpdateMenu ***
  141.  
  142.     int nCount = m_pDropMenu->GetMenuItemCount();
  143.     // clean out the menu before adding to it
  144.     for(int i = nCount - 1; i >= 0; i--)
  145.     {
  146.         m_pDropMenu->DeleteMenu(i, MF_BYPOSITION);
  147.     }
  148.  
  149.     UINT nID = FIRST_MOVE_MENU_ID;
  150.  
  151.     int32 iLines = MSG_GetFolderChildren (WFE_MSGGetMaster(), NULL, NULL, 0);
  152.     MSG_FolderInfo **ppFolderInfo = new MSG_FolderInfo *[iLines];
  153.     ASSERT(ppFolderInfo);
  154.     if (ppFolderInfo)
  155.     {
  156.         MSG_GetFolderChildren (WFE_MSGGetMaster(), NULL, ppFolderInfo, iLines);
  157.         for (int i = 0; i < iLines; i++)
  158.         {
  159.             MSG_FolderLine folderLine;
  160.             if (MSG_GetFolderLineById (WFE_MSGGetMaster(), ppFolderInfo[i], &folderLine)) {
  161.                 if ( folderLine.flags & MSG_FOLDER_FLAG_MAIL ) {
  162.                     if (nID > FIRST_MOVE_MENU_ID)
  163.                         m_pDropMenu->AppendMenu(MF_SEPARATOR, 0, "", FALSE, NULL);
  164.                     BuildMenu( ppFolderInfo[i], m_pDropMenu, nID );
  165.                 }
  166.             }
  167.         }
  168.         delete ppFolderInfo;
  169.     }
  170. }
  171.  
  172. BEGIN_MESSAGE_MAP( CMailQFButton, CMailQFButtonParent)
  173.     ON_MESSAGE( QF_DRAGGINGBOOKMARK, OnQuickfileDrag )
  174.     ON_MESSAGE( DM_DROPOCCURRED, OnDrop )
  175. #ifdef ON_COMMAND_RANGE
  176.     ON_COMMAND_RANGE(FIRST_MOVE_MENU_ID, LAST_MOVE_MENU_ID, OnMoveOrCopy )
  177.     ON_COMMAND_RANGE(FIRST_COPY_MENU_ID, LAST_COPY_MENU_ID, OnMoveOrCopy )
  178.     ON_WM_SYSCOLORCHANGE()
  179. #endif
  180. END_MESSAGE_MAP()
  181.  
  182. #ifndef ON_COMMAND_RANGE
  183.  
  184. BOOL CMailQFButton::OnCommand( WPARAM wParam, LPARAM lParam )
  185. {
  186.     UINT nID = wParam;
  187.  
  188.     if ( nID >= FIRST_MOVE_MENU_ID && nID <= LAST_MOVE_MENU_ID ) {
  189.         OnMoveOrCopy( nID );
  190.         return TRUE;
  191.     }
  192.     if ( nID >= FIRST_COPY_MENU_ID && nID <= LAST_COPY_MENU_ID ) {
  193.         OnMoveOrCopy( nID );
  194.         return TRUE;
  195.     }
  196.     return CMailQFButtonParent::OnCommand( wParam, lParam );
  197. }
  198.  
  199. #endif
  200.  
  201. void CMailQFButton::OnBtnClicked(BOOL bDragging)
  202. {
  203.     RECT rc;
  204.     GetWindowRect(&rc);
  205.     
  206.     if (!m_bMenuShowing) {
  207.         BuildMenu( );
  208.  
  209.         CMailQFMenuDropTarget *dropTarget = new CMailQFMenuDropTarget(m_pDropMenu);
  210.  
  211.         m_bMenuShowing = TRUE;
  212.         m_pDropMenu->TrackDropMenu(this, rc.left, rc.bottom+1, bDragging, dropTarget);
  213.     }
  214. }
  215.  
  216. LRESULT CMailQFButton::OnQuickfileDrag(WPARAM wParam, LPARAM lParam)
  217. {
  218.     if ( m_eState != eBUTTON_DOWN ) {
  219.         //keep button feedback in mousedown state
  220.         m_eState = eBUTTON_DOWN;
  221.         RedrawWindow();
  222.  
  223.         OnBtnClicked(TRUE);
  224.     }
  225.     return 1;
  226. }
  227.  
  228. LRESULT CMailQFButton::OnDrop(WPARAM wParam, LPARAM lParam)
  229. {
  230.     LRESULT res = 0;
  231.  
  232.     UINT nID = LOWORD(lParam);
  233.  
  234.     // Dig out the frame that initiated the drag.-
  235.     HGLOBAL hData = (HGLOBAL) wParam;
  236.     MailNewsDragData *pData = (MailNewsDragData *) GlobalLock( hData );
  237.  
  238.     LPMAILFRAME pMailFrame = NULL;
  239.     LPUNKNOWN pUnk = (LPUNKNOWN) MSG_GetFEData( pData->m_pane );
  240.  
  241.     if ( pUnk ) {
  242.         pUnk->QueryInterface( IID_IMailFrame, (LPVOID *) &pMailFrame );
  243.  
  244.         if (pMailFrame) {
  245.             CMailNewsFrame *pFrame = pMailFrame->GetMailNewsFrame();
  246.  
  247.             if ( pFrame ) {
  248.                 res = pFrame->SendMessage( WM_COMMAND, (WPARAM) nID, 0 );
  249.             }
  250.         }
  251.     }
  252.  
  253.     GlobalUnlock( hData );
  254.     return res;
  255. }
  256.  
  257. void CMailQFButton::OnMoveOrCopy( UINT nID )
  258. {
  259.     GetParentFrame()->SendMessage( WM_COMMAND, (WPARAM) nID, 0 );
  260. }
  261.  
  262. void CMailQFButton::OnSysColorChange( )
  263. {
  264.     if(m_hFolderBitmap)
  265.     {
  266.         VERIFY(::DeleteObject(m_hFolderBitmap));
  267.         VERIFY(::DeleteObject(m_hSelectedFolderBitmap));
  268.         
  269.         HINSTANCE hInstance = AfxGetResourceHandle();
  270.         HDC hDC = ::GetDC(m_hWnd);
  271.         WFE_InitializeUIPalette(hDC);
  272.  
  273.         m_hFolderBitmap = WFE_LoadTransparentBitmap(hInstance, hDC, sysInfo.m_clrMenu, RGB(255, 0, 255),
  274.                                              WFE_GetUIPalette(GetParentFrame()), IDB_BOOKMARK_FOLDER2);
  275.         m_hSelectedFolderBitmap = WFE_LoadTransparentBitmap(hInstance, hDC,sysInfo.m_clrHighlight,
  276.                                                      RGB(255, 0, 255), WFE_GetUIPalette(GetParentFrame()), IDB_BOOKMARK_FOLDER2);
  277.  
  278.         ::ReleaseDC(m_hWnd, hDC);
  279.     }
  280.  
  281.     CMailQFButtonParent::OnSysColorChange();
  282. }
  283. /////////////////////////////////////////////////////////////////////
  284. // CMailQFDropTarget
  285.  
  286. DROPEFFECT CMailQFDropTarget::OnDragEnter(CWnd * pWnd,
  287.     COleDataObject * pDataObject, DWORD dwKeyState, CPoint point)
  288. {
  289.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  290.     // Only interested in bookmarks
  291.     if (pDataObject->IsDataAvailable(
  292.         ::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT)))
  293.     {
  294.         pWnd->SendMessage(QF_DRAGGINGBOOKMARK, 0, 0);
  295.     }
  296.     return(deReturn);
  297.  
  298. } // END OF    FUNCTION CMailQFDropTarget::OnDragEnter()
  299.  
  300. DROPEFFECT CMailQFDropTarget::OnDragOver(CWnd * pWnd,
  301.     COleDataObject * pDataObject, DWORD dwKeyState, CPoint point)
  302. {
  303.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  304.     
  305.     return(deReturn);
  306.  
  307. } // END OF    FUNCTION CMailQFDropTarget::OnDragOver()
  308.  
  309. BOOL CMailQFDropTarget::OnDrop(CWnd * pWnd,
  310.     COleDataObject * pDataObject, DROPEFFECT dropEffect, CPoint point)
  311. {
  312.     BOOL bRtn = FALSE;
  313.     
  314.     return(bRtn);
  315.     
  316. } // END OF    FUNCTION CMailQFDropTarget::OnDrop()
  317.  
  318. /////////////////////////////////////////////////////////////////////
  319. // CMailQFDropMenu
  320.  
  321. CDropMenuDropTarget *CMailQFDropMenu::GetDropMenuDropTarget(CWnd *pOwner)
  322. {
  323.     return new CMailQFMenuDropTarget(pOwner);
  324. }
  325.  
  326. BEGIN_MESSAGE_MAP( CMailQFDropMenu, CMailQFDropMenuParent )
  327.     ON_WM_LBUTTONUP()
  328. END_MESSAGE_MAP()
  329.  
  330. void CMailQFDropMenu::OnLButtonUp(UINT nFlags, CPoint point)
  331. {
  332.     MenuSelectionType eSelType;
  333.     int nSelection = FindSelection(point, eSelType);
  334.  
  335.     if(nSelection != -1)
  336.     {
  337.         CDropMenuItem *pItem = (CDropMenuItem *)m_pMenuItemArray[nSelection];
  338. #ifdef _WIN32    
  339.         SendMessage(WM_COMMAND, MAKEWPARAM(pItem->GetCommand(), 0), 0);
  340. #else
  341.         SendMessage(WM_COMMAND, (WPARAM)pItem->GetCommand(), MAKELPARAM( m_hWnd, 0) );
  342. #endif
  343.     }
  344. }
  345.  
  346.  
  347. ///////////////////////////////////////////////////////////////////////////
  348. // CMailQFMenuDropTarget
  349.  
  350. CMailQFMenuDropTarget::CMailQFMenuDropTarget(CWnd *pOwner): CDropMenuDropTarget( pOwner )
  351. {
  352. }
  353.  
  354.  
  355. DROPEFFECT CMailQFMenuDropTarget::OnDragEnter(CWnd * pWnd,    COleDataObject * pDataObject,
  356.                                                DWORD dwKeyState, CPoint point)
  357. {
  358.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  359.     
  360.     // Only interested in bookmarks now
  361.     if (pDataObject->IsDataAvailable(
  362.         ::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT)))
  363.     {
  364.         deReturn = DROPEFFECT_MOVE;
  365.     }
  366.  
  367.     return(deReturn);
  368.     
  369. }
  370.  
  371. DROPEFFECT CMailQFMenuDropTarget::OnDragOver(CWnd * pWnd, COleDataObject * pDataObject,
  372.                                               DWORD dwKeyState, CPoint point )
  373. {
  374.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  375.  
  376.     // Only interested in bookmarks now
  377.     if (pDataObject->IsDataAvailable(
  378.         ::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT)))
  379.     {
  380.         m_pOwner->SendMessage(DT_DRAGGINGOCCURRED, (WPARAM) 0, MAKELPARAM(point.x, point.y));
  381.         deReturn = DROPEFFECT_MOVE;
  382.     }
  383.  
  384.     return(deReturn);
  385.     
  386. }
  387.  
  388. BOOL CMailQFMenuDropTarget::OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  389.             DROPEFFECT dropEffect, CPoint point)
  390. {
  391.     BOOL bRtn = FALSE;
  392.     
  393.     // Only interested in bookmarks now 
  394.     CLIPFORMAT cfMessage = ::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT);
  395.     if (pDataObject->IsDataAvailable(cfMessage))
  396.     {
  397.         HGLOBAL hContent = pDataObject->GetGlobalData(cfMessage);
  398.         pWnd->SendMessage(DT_DROPOCCURRED, (WPARAM) hContent, MAKELPARAM( point.x, point.y ) );
  399.     }
  400.     
  401.     return(bRtn);
  402. }
  403.