📄 chevbar.cpp
字号:
#include "stdafx.h"
#include "MyIE.h"
#include "ChevBar.h"
#include "ToolMenu.h"
#include "Menudata.h"
#include "MainFrm.h"
#include <wininet.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChevBar
CChevBar::CChevBar()
{
SetBorders();
}
BEGIN_MESSAGE_MAP(CChevBar, CControlBar)
//{{AFX_MSG_MAP(CChevBar)
ON_WM_NCCREATE()
ON_WM_PAINT()
ON_WM_NCCALCSIZE()
ON_WM_ERASEBKGND()
ON_WM_NCPAINT()
ON_NOTIFY_REFLECT(RBN_HEIGHTCHANGE, OnHeightChange)
ON_NOTIFY_REFLECT(RBN_ENDDRAG, OnHeightChange)
ON_MESSAGE(RB_SHOWBAND, OnShowBand)
ON_MESSAGE_VOID(WM_RECALCPARENT, OnRecalcParent)
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT( RBN_CHEVRONPUSHED, OnChevronPushed )
ON_WM_PARENTNOTIFY()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChevBar
/*
This is the handler when a chevron is pushed.
*/
void CChevBar::OnChevronPushed( NMHDR * pNotifyStruct, LRESULT* result )
{
CMDIFrameWnd * pMainFrame = (CMDIFrameWnd*)AfxGetMainWnd();
NMREBARCHEVRON* pChev = (NMREBARCHEVRON*) pNotifyStruct;
// Has the band of the chevron that generated this message
int iBand = pChev->uBand;
// Have to get the child window handle this band holds
REBARBANDINFO rbinfo;
rbinfo.cbSize = sizeof(rbinfo);
rbinfo.fMask = RBBIM_CHILD | RBBIM_ID;
GetReBarCtrl().GetBandInfo ( iBand, &rbinfo );
// Check if the child window is a toolbar
// Some rebar bands may have other windows, so that is left as an exercise
// to the user :-)
CToolBar *pTBar = (CToolBar *)CToolBar::FromHandle ( rbinfo.hwndChild );
ASSERT(pTBar);
ASSERT(pTBar->IsKindOf(RUNTIME_CLASS(CToolBar)));
// Create a popup menu to show hidden buttons
CToolMenu pop;
pop.CreatePopupMenu ();
// The CToolMenu uses the toolbar pointer to get associated text and image
// information. If there is a better way please do so.
// This menu was created with local scope, hence the temp pointer
// pTBar can be stored i guess...
//pop.m_pToolbar = pTBar;
pop.m_pImg = pTBar->GetToolBarCtrl().GetImageList();
// We have to determine the hidden buttons
// 1. Obtain band rectangle (subtract chevron width if you want to)
// 2. Get the button rectangle
// 3. Check if the intersecting rectangle is same as the button rectangle
// 4. If they intersect then the button is shown
// Get band rectangle.
//CRect rectBand;
CRect rectTool;
//GetReBarCtrl ().GetRect( iBand, &rectBand );
//rectBand.right = rectBand.Width ();
//rectBand.left = 0 ;
pTBar->GetWindowRect(&rectTool);
// It depends on the user to decide if this subtraction is necessary, if they feel
// happy about the chevron hiding a part of a button then remove this code
CRect rectChevron;
rectChevron = pChev->rc;
// rectBand.right -= rectChevron.Width ();
// Screen co-ordinates for Menu to be displayed
CPoint ptMenu;
ptMenu.x = rectChevron.left;
ptMenu.y = rectChevron.bottom;
ClientToScreen ( &ptMenu );
// This flag indicates if atleast one has been added to the menu
// POPUP Menu is shown only if atleast one item has to be shown
BOOL bAtleastOne=FALSE;
int iCount, iButtonCount = pTBar->GetToolBarCtrl().GetButtonCount();
UINT iStyle, id;
for ( iCount = 0 ; iCount < iButtonCount ; iCount++ )
{
// Get the id of the toolbar button
id = pTBar->GetItemID( iCount );
// If the button is a separator then we can also add a separator to the
// popup menu
if ( pTBar->GetButtonStyle ( iCount ) & TBSTYLE_SEP )
{
// It wouldnt be nice if there is a separator as the first item in the menu
if ( bAtleastOne )
pop.AppendMenu ( MF_SEPARATOR );
}
else
{
// Get the button rectangle
CRect rectButton;
pTBar->GetItemRect ( iCount, &rectButton );
// Check the intersection of the button and the band
//CRect interRect;
//interRect.IntersectRect ( &rectButton, &rectBand );
// if the intersection is not the same as button then
// the button is not completely visible, so add to menu
//if ( rectButton.right >= rectBand.right-10 )
if ( rectButton.right >= rectTool.Width() )
{
UINT iMenuStyle; // = MF_OWNERDRAW;
// Have to reflect the state of the menu item, so check the state of the
// button and enable or disable the items
if ( pTBar->GetToolBarCtrl().IsButtonEnabled ( id ) )
iMenuStyle = MF_ENABLED;
else
iMenuStyle = MF_DISABLED;
if ( pTBar->GetToolBarCtrl().IsButtonPressed ( id ) || pTBar->GetToolBarCtrl().IsButtonChecked ( id ))
iMenuStyle |= MF_CHECKED;
// Add the item to the menu with the id of the toolbar button
// This id is used to notify the parent if the user selects that item
CMenuData * md= new CMenuData;
md->m_pImgList = pop.m_pImg;
if(rbinfo.wID == ID_VIEW_LINKS)
if( id == ID_LINK_POPUP)
{
iMenuStyle |= MF_POPUP;
TBBUTTON tbb;
if( pTBar->GetToolBarCtrl().GetButton( iCount, &tbb ))
{
if(IsMenu((HMENU)tbb.dwData))
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(m_astrLinks[iCount-1], md);
// md->nID = id;
// md->nFlags = iMenuStyle;
HMENU hmenu= CopyMenu((HMENU)tbb.dwData);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, (UINT)hmenu, (char*)md );//spaces+m_astrLinks[iCount-1]
}
else
delete md;
}
}
else
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(m_astrLinks[iCount-1], md);
// md->nID = id;
// md->nFlags = iMenuStyle;
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
else if(rbinfo.wID == ID_VIEW_FAVS)
{
iMenuStyle |= MF_POPUP;
TBBUTTON tbb;
if( pTBar->GetToolBarCtrl().GetButton( iCount, &tbb ))
{
if(IsMenu((HMENU)tbb.dwData))
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(m_astrFavs[iCount], md);
// md->nID = id;
// md->nFlags = iMenuStyle;
HMENU hmenu= CopyMenu((HMENU)tbb.dwData);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, (UINT)hmenu, (char*)md );//spaces+m_astrLinks[iCount-1]
}
else
delete md;
}
}
else if(rbinfo.wID == ID_VIEW_EX_TOOL)
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
POSITION pos = ((CMainFrame*)pMainFrame)->m_lstrUtilNames.FindIndex(iCount);
SetMenuText(((CMainFrame*)pMainFrame)->m_lstrUtilNames.GetAt(pos), md);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
else if(rbinfo.wID == ID_VIEW_TOOLBAR)
{
CString strText;
if ( strText.LoadString ( id ) )
{
int iPos = strText.Find ( '\n', 0 );
if ( iPos != -1 )
{
strText = strText.Mid( iPos+1 );
}
}
if( pTBar->GetButtonStyle ( iCount ) & TBSTYLE_DROPDOWN )
{
iMenuStyle |= MF_POPUP;
TBBUTTON tbb;
if( pTBar->GetToolBarCtrl().GetButton( iCount, &tbb ))
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(strText, md);
// md->nID = id;
// md->nFlags = iMenuStyle;
CMenu menu;
CMenu* pPopup;
if(id == ID_FONT_DROPDOWN)
{
// the font popup is stored in a resource
menu.LoadMenu(IDR_FONT_POPUP);
pPopup = menu.GetSubMenu(0);
}
else if (id == ID_ENCODE_DROPDOWN)
{
menu.LoadMenu(IDR_ENCODING);
pPopup = menu.GetSubMenu(0);
}
else if(id== ID_FILE_NEW_BLANK)
{
// BOOL bMax;
// pMainFrame->MDIGetActive(&bMax);
// the font popup is stored in a resource
// if (bMax)
// pPopup = pMainFrame->GetMenu()->GetSubMenu(1)->GetSubMenu(0);
// else
pPopup = ((CMainFrame*)pMainFrame)->GetMenu()->GetSubMenu(0)->GetSubMenu(0);
}
else if(id== ID_BMODE_DROPDOWN)
{
pPopup = ((CMainFrame*)pMainFrame)->GetMenu()->GetSubMenu(4)->GetSubMenu(11);
}
else if(id== ID_TOOLS_AUTOSCROLL_USEAUTOSCROLLING)
{
pPopup = ((CMainFrame*)pMainFrame)->GetMenu()->GetSubMenu(6)->GetSubMenu(14);
}
else if(id == ID_OPTIONS_USE_PROXY)
{
menu.CreatePopupMenu();
INTERNET_PROXY_INFO ipi;
DWORD dwSize=sizeof(ipi);
BOOL bUseProxy;
//This call determines the buffer size needed
InternetQueryOption(NULL,INTERNET_OPTION_PROXY,&ipi,&dwSize);
//Insert code to user the user agent string information
if (ipi.dwAccessType == INTERNET_OPEN_TYPE_DIRECT )
bUseProxy = FALSE;
else
bUseProxy = TRUE;
menu.CreatePopupMenu();
POSITION pos1=((CMainFrame*)pMainFrame)->m_aProxySpeed.GetHeadPosition(), pos = ((CMainFrame*)pMainFrame)->m_astrProxy.GetHeadPosition();
int i=0;
CString str, str1;
while(pos!=NULL)
{
str = ((CMainFrame*)pMainFrame)->m_astrProxy.GetAt(pos);
str = str.Left(50);
str1.LoadString(IDS_SP_INVALID + ((CMainFrame*)pMainFrame)->m_aProxySpeed.GetAt(pos1));
str1 = "(" + str1 + ")";
menu.AppendMenu(MF_STRING, 0x1100 + i, str+str1);
if(bUseProxy && ((CMainFrame*)pMainFrame)->m_strCurProxy == ((CMainFrame*)pMainFrame)->m_astrProxy.GetAt(pos))
menu.CheckMenuItem(0x1100 + i, MF_CHECKED | MF_BYCOMMAND );
((CMainFrame*)pMainFrame)->m_astrProxy.GetNext(pos);
((CMainFrame*)pMainFrame)->m_aProxySpeed.GetNext(pos1);
i++;
}
pPopup = &menu;
}
else if(id == ID_OPTIONS_USE_WEBP)
{
CString strCurWebProxy;
CChildFrame* tcf = (CChildFrame*)(((CMainFrame*)pMainFrame)->MDIGetActive());
if (tcf!=NULL && tcf->m_pView!=NULL)
{
if(((CMyIEView*)tcf->m_pView)->m_bEnWebProxy)
{
strCurWebProxy = ((CMyIEView*)tcf->m_pView)->m_strWebProxy;
if(strCurWebProxy=="" || strCurWebProxy.IsEmpty())
strCurWebProxy = ((CMainFrame*)pMainFrame)->m_strDefaultWebProxy;
}
}
// the font popup is stored in a resource
menu.CreatePopupMenu();
POSITION pos = ((CMainFrame*)pMainFrame)->m_astrWebProxy.GetHeadPosition(), pos1 = ((CMainFrame*)pMainFrame)->m_aWebProxySpeed.GetHeadPosition();
int i=0;
CString str, str1;
while(pos!=NULL)
{
str = ((CMainFrame*)pMainFrame)->m_astrWebProxy.GetAt(pos);
str1.LoadString(IDS_SP_INVALID + ((CMainFrame*)pMainFrame)->m_aWebProxySpeed.GetAt(pos1));
str1 = "(" + str1 + ")";
menu.AppendMenu(MF_STRING, 0x1200 + i, str+str1);
if(strCurWebProxy == ((CMainFrame*)pMainFrame)->m_astrWebProxy.GetAt(pos))
menu.CheckMenuItem(0x1200 + i, MF_CHECKED | MF_BYCOMMAND );
((CMainFrame*)pMainFrame)->m_astrWebProxy.GetNext(pos);
((CMainFrame*)pMainFrame)->m_aWebProxySpeed.GetNext(pos1);
i++;
}
pPopup = &menu;
}
HMENU hmenu = CopyMenu(pPopup->m_hMenu);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, (UINT)hmenu, (char*)md );
menu.DestroyMenu();
}
}
else
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(strText, md);
// md->nID = id;
// md->nFlags = iMenuStyle;
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
}
else if(rbinfo.wID == ID_MENU_BAR)
{
if(pMainFrame!=NULL)
{
CString str;
((CMainFrame*)pMainFrame)->GetMenu()->GetMenuString(iCount, str, MF_BYPOSITION);
CMenu * pPopup;
pPopup = ((CMainFrame*)pMainFrame)->GetMenu()->GetSubMenu(iCount);
if(pPopup!=NULL)
{
HMENU hmenu = CopyMenu(pPopup->m_hMenu);
pop.AppendMenu ( MF_POPUP, (UINT)hmenu, str );
}
}
}
// Yeah, have added one, so can show the menu
bAtleastOne=TRUE;
}
}
}
// Show the menu if atleast one item has been added
if ( bAtleastOne )
pop.TrackPopupMenu ( TPM_LEFTALIGN|TPM_TOPALIGN, ptMenu.x, ptMenu.y, pMainFrame);
// Delete our menu
pop.DestroyMenu ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -