📄 wg_toolbar.cpp
字号:
// wg_toolbar.cpp//// CToolBar class implementation////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui_include_config.h"#include "wg_toolbar.h"#include "wg_message_server.h"#include "wg_debug.h"namespace wGui{CToolBar::CToolBar(const CRect& WindowRect, CWindow* pParent) : CWindow(WindowRect, pParent){ m_sClassName = "CToolBar"; m_BGColor = COLOR_LIGHTGRAY; CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_LCLICK);}CToolBar::~CToolBar(void){}void CToolBar::InsertButton(CButton* pButton, long int iButtonID, int iPosition){ long int iFixedButtonID = iButtonID; if (pButton == 0) { iFixedButtonID = 0; } else { // Transfer ownership of the button to the ToolBar pButton->SetNewParent(this); } if (iPosition == -1) { m_vpButtons.push_back(std::make_pair(pButton, iFixedButtonID)); } else { m_vpButtons.insert(m_vpButtons.begin() + iPosition, std::make_pair(pButton, iFixedButtonID)); } RepositionButtons();}void CToolBar::RemoveButton(int iPosition){ CButton* pButton = m_vpButtons.at(iPosition).first; m_vpButtons.erase(m_vpButtons.begin() + iPosition); delete pButton;}int CToolBar::GetButtonPosition(long int iButtonID){ int iPosition = -1; for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter) { ++iPosition; if (iter->second == iButtonID) { return iPosition; } } return -1;}void CToolBar::RepositionButtons(void){ int xPosition = m_WindowRect.Left() + 4; for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter) { CButton* pButton = iter->first; if (pButton) { int xStartPosition = xPosition; xPosition = xPosition + 2 + pButton->GetWindowRect().Width(); pButton->SetWindowRect(CRect(xStartPosition, m_WindowRect.Top() + 2, xPosition - 3, m_WindowRect.Top() + 1 + pButton->GetWindowRect().Height())); // Hide any buttons that extend beyond the end of the toolbar if (xPosition > m_WindowRect.Right()) { pButton->SetVisible(false); } else { pButton->SetVisible(true); } } else { // Spacer xPosition += 6; } }}void CToolBar::SetWindowRect(const CRect& WindowRect){ CWindow::SetWindowRect(WindowRect); RepositionButtons();}bool CToolBar::HandleMessage(CMessage* pMessage){ bool bHandled = false; if (pMessage) { switch(pMessage->MessageType()) { case CMessage::CTRL_LCLICK: { if (pMessage->Destination() == this) { long int iButtonID = 0; for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter) { if (iter->first == pMessage->Source()) { iButtonID = iter->second; } } CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_LCLICK, m_pParentWindow, this, iButtonID)); bHandled = true; } break; } default : bHandled = CWindow::HandleMessage(pMessage); break; } } return bHandled;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -