📄 chevbar.cpp
字号:
#include "stdafx.h"
#include "GreenBrowser.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 )
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChevBar
void CChevBar::OnChevronPushed( NMHDR * pNotifyStruct, LRESULT* result )
{
NMREBARCHEVRON* pChev = (NMREBARCHEVRON*) pNotifyStruct;
// Has the band of the chevron that generated this message
int iBand = pChev->uBand;
int FavSize;
// 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_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
CRect rectTool;
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;
// 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 )
pmf->MenuAppendSeparator(&pop); //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;
// 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(g_astrLinks[iCount], md);
HMENU hmenu= CopyMenu((HMENU)tbb.dwData);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, (UINT)hmenu, (char*)md );//spaces+g_astrLinks[iCount-1]
}
else
delete md;
}
}
else
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(g_astrLinks[iCount], md);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
}
else if(rbinfo.wID == ID_VIEW_FAVS)
{
if(id == ID_FAV_POPUP)
{
FavSize=pmf->m_nFavSize;
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(g_astrFavs[iCount], md);
HMENU hmenu= CopyMenu((HMENU)tbb.dwData);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, (UINT)hmenu, (char*)md );//spaces+g_astrLinks[iCount-1]
}
else
delete md;
}
}
else if ( pmf->m_bFavShowUrl )
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(g_astrFavs[iCount], md);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
}
else if(rbinfo.wID == ID_VIEW_EX_TOOL)
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(pmf->m_ExternalUtilList.m_UtilList.GetAt(iCount)->m_strUtilName, md);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
else if(rbinfo.wID == ID_VIEW_TOOLBAR)
{
LOADSTR(strText,id);
if ( strText.GetLength() )
{
int iPos = strText.Find ( '\n', 0 );
if ( iPos != -1 )
{
strText = strText.Mid( iPos+1 );
}
}
if( pTBar->GetButtonStyle ( iCount ) & TBSTYLE_DROPDOWN && (id!= ID_EDIT_EDIT && id!=ID_TOOLS_EMAIL && id!=ID_GO_BACK && id!=ID_GO_FORWARD) || id == ID_GROUP)
{
iMenuStyle |= MF_POPUP;
TBBUTTON tbb;
if( pTBar->GetToolBarCtrl().GetButton( iCount, &tbb ))
{
pTBar->GetButtonInfo ( iCount, id, iStyle, md->m_nBitmap);
SetMenuText(strText, md);
CMenu menu;
CMenu* pPopup;
if(id== ID_FILE_SAVEAS)
{
pPopup = SMP_SAVE;
}
else if(id == ID_FONT_DROPDOWN)
{
pPopup = SMP_FONTS;
}
else if (id == ID_ENCODE_DROPDOWN)
{
pPopup = SMP_ENCODE;
}
else if(id== ID_NEWWINDOW)
{
pPopup = pmf->GetMenu()->GetSubMenu(0)->GetSubMenu(0);
}
else if(id== ID_TOOLS_EXTERNAL_AUTORUN)
{
pPopup = SMP_EXTOOLS;
}
else if(id== ID_TOOLS_SETBG)
{
pPopup = SMP_BGCOLOR;
}
else if(id== ID_GROUP)
{
g_bRTab=0;
pPopup = SMP_GROUP;
}
else if(id== ID_OPTIONS_LOADIMAGE)
{
pPopup = SMP_DOWNLOAD;
}
else if(id== ID_TOOLS_AUTOSCROLL_USEAUTOSCROLLING)
{
pPopup = SMP_AUTOSCROLL;
}
else if(id== ID_EDIT_UNDOCLOSE)
{
pPopup = SMP_UNDO;
}
else if(id== ID_TOOLS_ALL)
{
pPopup = SMP_CLEAN;
}
else if(id== ID_SC_FILLFORM)
{
pPopup = SMP_AUTOFILL;
}
else if(id == ID_OPTIONS_USE_PROXY)
{
menu.CreatePopupMenu();
pmf->BuildProxyMenu(&menu);
pPopup = &menu;
}
else if(id == ID_OPTIONS_USE_WEBP)
{
menu.CreatePopupMenu();
pmf->BuildWebProxyMenu(&menu, 2);
pPopup = &menu;
}
else if(id == ID_GO_UP_PAGE)
{
menu.CreatePopupMenu();
pmf->BuildGoUpMenu(&menu);
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);
pop.AppendMenu ( iMenuStyle|MF_OWNERDRAW, id , (char*)md );
}
}
else if(rbinfo.wID == ID_MENU_BAR)
{
if(pmf!=NULL)
{
pmf->GetMenu()->GetMenuString(iCount, str, MF_BYPOSITION);
CMenu * pPopup;
pPopup = pmf->GetMenu()->GetSubMenu(iCount);
if(pPopup!=NULL)
{
HMENU hmenu = CopyMenu(pPopup->m_hMenu);
pmf->MenuAppendOwnerItem( &pop, 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, pmf);
if(rbinfo.wID == ID_VIEW_FAVS)
pmf->m_nFavSize=FavSize;
// Delete our menu
pop.DestroyMenu ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -