📄 muletoolbarctrl.cpp
字号:
{
CString strFilter(_T("eMule Skin Files ("));
for (int f = 0; f < ARRSIZE(_apszSkinFiles); f++){
if (f > 0)
strFilter += _T(';');
strFilter += _apszSkinFiles[f];
}
strFilter += _T(")|");
for (int f = 0; f < ARRSIZE(_apszSkinFiles); f++){
if (f > 0)
strFilter += _T(';');
strFilter += _apszSkinFiles[f];
}
strFilter += _T("||");
CFileDialog dialog(TRUE, EMULSKIN_BASEEXT _T(".ini"), NULL, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST, strFilter, NULL, 0);
if (dialog.DoModal() == IDOK)
{
if (thePrefs.GetSkinProfile().CompareNoCase(dialog.GetPathName()) != 0)
theApp.ApplySkin(dialog.GetPathName());
}
break;
}
default:
if (wParam >= MP_TOOLBARBITMAP && wParam < MP_TOOLBARBITMAP + MAX_TOOLBAR_FILES)
{
if (thePrefs.GetToolbarBitmapSettings().CompareNoCase(m_astrToolbarPaths[wParam-MP_TOOLBARBITMAP]) != 0)
{
ChangeToolbarBitmap(m_astrToolbarPaths[wParam-MP_TOOLBARBITMAP], true);
thePrefs.SetToolbarBitmapSettings(m_astrToolbarPaths[wParam-MP_TOOLBARBITMAP]);
}
}
else if (wParam >= MP_SKIN_PROFILE && wParam < MP_SKIN_PROFILE + MAX_SKIN_FILES)
{
if (thePrefs.GetSkinProfile().CompareNoCase(m_astrSkinPaths[wParam - MP_SKIN_PROFILE]) != 0)
theApp.ApplySkin(m_astrSkinPaths[wParam - MP_SKIN_PROFILE]);
}
}
return true;
}
void CMuleToolbarCtrl::ChangeTextLabelStyle(EToolbarLabelType eLabelType, bool bRefresh, bool bForceUpdateButtons)
{
if (m_eLabelType != eLabelType || bForceUpdateButtons)
{
switch (eLabelType)
{
case NoLabels:
SetStyle(GetStyle() & ~TBSTYLE_LIST);
SetMaxTextRows(0);
break;
case LabelsBelow:
SetStyle(GetStyle() & ~TBSTYLE_LIST);
SetMaxTextRows(1);
break;
case LabelsRight:
SetStyle(GetStyle() | TBSTYLE_LIST);
SetMaxTextRows(1);
break;
}
for (int i = 0; i < m_buttoncount; i++)
{
TBBUTTONINFO tbbi = {0};
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_STYLE;
GetButtonInfo(IDC_TOOLBARBUTTON + i, &tbbi);
if (eLabelType == LabelsRight)
tbbi.fsStyle |= TBSTYLE_AUTOSIZE;
else
tbbi.fsStyle &= ~TBSTYLE_AUTOSIZE;
SetButtonInfo(IDC_TOOLBARBUTTON + i, &tbbi);
}
m_eLabelType = eLabelType;
if (bRefresh)
Refresh();
}
}
void CMuleToolbarCtrl::Refresh()
{
SetAllButtonsWidth();
AutoSize(); // Causes a toolbar to be resized.
if (theApp.emuledlg->m_ctlMainTopReBar.m_hWnd)
{
theApp.emuledlg->RemoveAnchor(theApp.emuledlg->m_ctlMainTopReBar.m_hWnd);
REBARBANDINFO rbbi = {0};
CSize sizeBar;
GetMaxSize(&sizeBar);
ASSERT( sizeBar.cx != 0 && sizeBar.cy != 0 );
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE;
rbbi.cxMinChild = sizeBar.cy;
rbbi.cyMinChild = sizeBar.cy;
rbbi.cxIdeal = sizeBar.cx;
VERIFY( theApp.emuledlg->m_ctlMainTopReBar.SetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi) );
theApp.emuledlg->AddAnchor(theApp.emuledlg->m_ctlMainTopReBar.m_hWnd, TOP_LEFT, TOP_RIGHT);
}
CRect rToolbarRect;
GetWindowRect(&rToolbarRect);
if (m_iPreviousHeight == rToolbarRect.Height())
{
Invalidate();
RedrawWindow();
}
else
{
m_iPreviousHeight = rToolbarRect.Height();
CRect rClientRect;
theApp.emuledlg->GetClientRect(&rClientRect);
CRect rStatusbarRect;
theApp.emuledlg->statusbar->GetWindowRect(&rStatusbarRect);
rClientRect.top += rToolbarRect.Height();
rClientRect.bottom -= rStatusbarRect.Height();
CWnd* wnds[] =
{
theApp.emuledlg->serverwnd,
theApp.emuledlg->kademliawnd,
theApp.emuledlg->transferwnd,
theApp.emuledlg->sharedfileswnd,
theApp.emuledlg->searchwnd,
theApp.emuledlg->chatwnd,
theApp.emuledlg->ircwnd,
theApp.emuledlg->statisticswnd
};
for (int i = 0; i < ARRSIZE(wnds); i++)
{
wnds[i]->SetWindowPos(NULL, rClientRect.left, rClientRect.top, rClientRect.Width(), rClientRect.Height(), SWP_NOZORDER);
theApp.emuledlg->RemoveAnchor(wnds[i]->m_hWnd);
theApp.emuledlg->AddAnchor(wnds[i]->m_hWnd, TOP_LEFT, BOTTOM_RIGHT);
}
theApp.emuledlg->Invalidate();
theApp.emuledlg->RedrawWindow();
}
}
void CMuleToolbarCtrl::OnTbnReset(NMHDR *pNMHDR, LRESULT *pResult)
{
// First get rid of old buttons
// while saving their states
for (int i = GetButtonCount()-1; i >= 0; i--)
{
TBBUTTON Button;
GetButton(i, &Button);
for (int j = 0; j < m_buttoncount ; j++)
{
if (TBButtons[j].idCommand == Button.idCommand)
{
TBButtons[j].fsState = Button.fsState;
TBButtons[j].fsStyle = Button.fsStyle;
TBButtons[j].iString = Button.iString;
}
}
DeleteButton(i);
}
TBBUTTON sepButton;
sepButton.idCommand = 0;
sepButton.fsStyle = TBSTYLE_SEP;
sepButton.fsState = TBSTATE_ENABLED;
sepButton.iString = -1;
sepButton.iBitmap = -1;
// set default configuration
CString config = strDefaultToolbar;
for (i = 0; i <config.GetLength(); i += 2)
{
int index = _tstoi(config.Mid(i, 2));
if (index == 99)
{
AddButtons(1, &sepButton);
continue;
}
AddButtons(1, &TBButtons[index]);
}
// save new (default) configuration
thePrefs.SetToolbarSettings(config);
Localize(); // we have to localize the button-text
theApp.emuledlg->ShowConnectionState();
ChangeTextLabelStyle(thePrefs.GetToolbarLabelSettings(), false, true);
SetAllButtonsWidth(); // then calc and set the button width
AutoSize();
}
void CMuleToolbarCtrl::OnTbnInitCustomize(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = TBNRF_HIDEHELP;
}
void CMuleToolbarCtrl::OnTbnEndAdjust(NMHDR*, LRESULT* pResult)
{
UpdateIdealSize();
*pResult = 0; // return value is ignored
}
void CMuleToolbarCtrl::OnSysColorChange()
{
CToolBarCtrl::OnSysColorChange();
ChangeToolbarBitmap(thePrefs.GetToolbarBitmapSettings(), true);
}
void CMuleToolbarCtrl::PressMuleButton(int nID)
{
// Customization might splits up the button-group, so we have to (un-)press them on our own
if (m_iLastPressedButton != -1)
CheckButton(m_iLastPressedButton, FALSE);
CheckButton(nID, TRUE);
m_iLastPressedButton = nID;
}
void CMuleToolbarCtrl::UpdateIdealSize()
{
if (theApp.emuledlg->m_ctlMainTopReBar.m_hWnd)
{
// let the rebar know what's our new current ideal size, so the chevron is handled correctly..
CSize sizeBar;
GetMaxSize(&sizeBar);
ASSERT( sizeBar.cx != 0 && sizeBar.cy != 0 );
REBARBANDINFO rbbi = {0};
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_IDEALSIZE;
rbbi.cxIdeal = sizeBar.cx;
VERIFY( theApp.emuledlg->m_ctlMainTopReBar.SetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi) );
}
}
void CMuleToolbarCtrl::ForceRecalcLayout()
{
// Force a recalc of the toolbar's layout to work around a comctl bug
int iTextRows = GetMaxTextRows();
SetRedraw(FALSE);
SetMaxTextRows(iTextRows+1);
SetMaxTextRows(iTextRows);
SetRedraw(TRUE);
}
#ifdef _DEBUG
#ifndef TBIF_BYINDEX
#define TBIF_BYINDEX 0x80000000
#endif
void CMuleToolbarCtrl::Dump()
{
TRACE("---\n");
CRect rcWnd;
GetWindowRect(&rcWnd);
TRACE("Wnd =%4d,%4d-%4d,%4d (%4d x %4d)\n", rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, rcWnd.Width(), rcWnd.Height());
CRect rcClnt;
GetClientRect(&rcClnt);
TRACE("Clnt=%4d,%4d-%4d,%4d (%4d x %4d)\n", rcClnt.left, rcClnt.top, rcClnt.right, rcClnt.bottom, rcClnt.Width(), rcClnt.Height());
// Total size of all of the visible buttons and separators in the toolbar.
CSize siz;
GetMaxSize(&siz);
TRACE("MaxSize= %4d x %4d\n", siz.cx, siz.cy);
int iButtons = GetButtonCount(); // Count of the buttons currently in the toolbar.
int iRows = GetRows(); // Number of rows of buttons in a toolbar with the TBSTYLE_WRAPABLE style
int iMaxTextRows = GetMaxTextRows();// Maximum number of text rows that can be displayed on a toolbar button.
TRACE("ButtonCount=%d Rows=%d MaxTextRows=%d\n", iButtons, iRows, iMaxTextRows);
// Current width and height of toolbar buttons, in pixels.
DWORD dwButtonSize = GetButtonSize();
TRACE("ButtonSize=%dx%d\n", LOWORD(dwButtonSize), HIWORD(dwButtonSize));
// Padding for a toolbar control.
DWORD dwPadding = SendMessage(TB_GETPADDING);
TRACE("Padding=%dx%d\n", LOWORD(dwPadding), HIWORD(dwPadding));
DWORD dwBitmapFlags = GetBitmapFlags(); // TBBF_LARGE=0x0001
TRACE("BitmapFlags=%u\n", dwBitmapFlags);
// Bounding rectangle of a button in a toolbar.
TRACE("ItemRects:");
for (int i = 0; i < iButtons; i++)
{
CRect rcButton(0,0,0,0);
GetItemRect(i, &rcButton);
TRACE(" %2dx%2d", rcButton.Width(), rcButton.Height());
}
TRACE("\n");
// Bounding rectangle for a specified toolbar button.
TRACE("Rects :");
for (int i = 0; i < iButtons; i++)
{
CRect rcButton(0,0,0,0);
GetRect(IDC_TOOLBARBUTTON + i, &rcButton);
TRACE(" %2dx%2d", rcButton.Width(), rcButton.Height());
}
TRACE("\n");
TRACE("Info :");
for (int i = 0; i < iButtons; i++)
{
TCHAR szLabel[256];
TBBUTTONINFO tbi = {0};
tbi.cbSize = sizeof(tbi);
tbi.dwMask |= TBIF_BYINDEX | TBIF_COMMAND | TBIF_IMAGE | TBIF_LPARAM | TBIF_SIZE | TBIF_STATE | TBIF_STYLE | TBIF_TEXT;
tbi.cchText = ARRSIZE(szLabel);
tbi.pszText = szLabel;
GetButtonInfo(i, &tbi);
TRACE(" %2d ", tbi.cx);
}
TRACE("\n");
}
#endif
void CMuleToolbarCtrl::AutoSize()
{
CToolBarCtrl::AutoSize();
#ifdef _DEBUG
//Dump();
#endif
}
void CMuleToolbarCtrl::SaveCurHeight()
{
CRect rcWnd;
GetWindowRect(&rcWnd);
m_iPreviousHeight = rcWnd.Height();
}
void CMuleToolbarCtrl::UpdateBackground()
{
if (theApp.emuledlg->m_ctlMainTopReBar)
{
HBITMAP hbmp = theApp.LoadImage(_T("MainToolBarBk"), _T("BMP"));
if (hbmp)
{
REBARBANDINFO rbbi = {0};
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_STYLE;
if (theApp.emuledlg->m_ctlMainTopReBar.GetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi))
{
rbbi.fMask = RBBIM_STYLE | RBBIM_BACKGROUND;
rbbi.fStyle |= RBBS_FIXEDBMP;
rbbi.hbmBack = hbmp;
if (theApp.emuledlg->m_ctlMainTopReBar.SetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi))
{
if (m_bmpBack.m_hObject)
VERIFY( m_bmpBack.DeleteObject() );
m_bmpBack.Attach(hbmp);
hbmp = NULL;
}
}
if (hbmp)
VERIFY( DeleteObject(hbmp) );
}
else
{
REBARBANDINFO rbbi = {0};
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_STYLE;
if (theApp.emuledlg->m_ctlMainTopReBar.GetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi))
{
rbbi.fMask = RBBIM_STYLE | RBBIM_BACKGROUND;
rbbi.fStyle &= ~RBBS_FIXEDBMP;
rbbi.hbmBack = NULL;
if (theApp.emuledlg->m_ctlMainTopReBar.SetBandInfo(MULE_TOOLBAR_BAND_NR, &rbbi))
{
if (m_bmpBack.m_hObject)
VERIFY( m_bmpBack.DeleteObject() );
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -