00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "wgui_include_config.h"
00026 #include "wg_toolbar.h"
00027 #include "wg_message_server.h"
00028 #include "wutil_debug.h"
00029
00030
00031 namespace wGui
00032 {
00033
00034 CToolBar::CToolBar(const CRect& WindowRect, CWindow* pParent) :
00035 CWindow(WindowRect, pParent)
00036 {
00037 m_BackgroundColor = COLOR_LIGHTGRAY;
00038 CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_SINGLELCLICK);
00039 Draw();
00040 }
00041
00042
00043 CToolBar::~CToolBar(void)
00044 {
00045
00046 }
00047
00048
00049 void CToolBar::InsertButton(CButton* pButton, long int iButtonID, unsigned int iPosition)
00050 {
00051 if (iPosition > m_vpButtons.size())
00052 iPosition = stdex::safe_static_cast<unsigned int>(m_vpButtons.size());
00053 long int iFixedButtonID = iButtonID;
00054 if (pButton == 0)
00055 {
00056 iFixedButtonID = 0;
00057 }
00058 else
00059 {
00060
00061 pButton->SetNewParent(this);
00062 }
00063 m_vpButtons.insert(m_vpButtons.begin() + iPosition, std::make_pair(pButton, iFixedButtonID));
00064 RepositionButtons();
00065 }
00066
00067
00068 void CToolBar::AppendButton(CButton* pButton, long int iButtonID)
00069 {
00070 InsertButton(pButton, iButtonID, stdex::safe_static_cast<unsigned int>(m_vpButtons.size()));
00071 }
00072
00073
00074 void CToolBar::RemoveButton(unsigned int iPosition)
00075 {
00076 CButton* pButton = m_vpButtons.at(iPosition).first;
00077 m_vpButtons.erase(m_vpButtons.begin() + iPosition);
00078 delete pButton;
00079 }
00080
00081
00082 void CToolBar::Clear(void)
00083 {
00084 for(t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter)
00085 {
00086 delete iter->first;
00087 }
00088 m_vpButtons.clear();
00089 }
00090
00091
00092 int CToolBar::GetButtonPosition(long int iButtonID)
00093 {
00094 int iPosition = -1;
00095 for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter)
00096 {
00097 if (iter->second == iButtonID)
00098 {
00099 iPosition = stdex::safe_static_cast<int>(iter - m_vpButtons.begin());
00100 }
00101 }
00102 return iPosition;
00103 }
00104
00105
00106 void CToolBar::RepositionButtons(void)
00107 {
00108 int xPosition = 4;
00109 for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter)
00110 {
00111 CButton* pButton = iter->first;
00112 if (pButton)
00113 {
00114 int xStartPosition = xPosition;
00115 xPosition = xPosition + 2 + pButton->GetWindowRect().Width();
00116 pButton->SetWindowRect(CRect(xStartPosition, 2, xPosition - 3, pButton->GetWindowRect().Height() + 1));
00117
00118
00119 pButton->SetVisible(xPosition <= m_WindowRect.Width());
00120 }
00121 else
00122 {
00123
00124 xPosition += 6;
00125 }
00126 }
00127 }
00128
00129
00130 void CToolBar::SetWindowRect(const CRect& WindowRect)
00131 {
00132 CWindow::SetWindowRect(WindowRect);
00133 m_ClientRect = m_WindowRect.SizeRect();
00134 RepositionButtons();
00135 }
00136
00137
00138 bool CToolBar::HandleMessage(CMessage* pMessage)
00139 {
00140 bool bHandled = false;
00141
00142 if (pMessage)
00143 {
00144 switch(pMessage->MessageType())
00145 {
00146 case CMessage::CTRL_SINGLELCLICK:
00147 {
00148 if (pMessage->Destination() == this)
00149 {
00150 long int iButtonID = 0;
00151 for (t_ButtonVector::iterator iter = m_vpButtons.begin(); iter != m_vpButtons.end(); ++iter)
00152 {
00153 if (iter->first == pMessage->Source())
00154 {
00155 iButtonID = iter->second;
00156 }
00157 }
00158 CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_SINGLELCLICK, m_pParentWindow, this, iButtonID));
00159 bHandled = true;
00160 }
00161 break;
00162 }
00163 default :
00164 bHandled = CWindow::HandleMessage(pMessage);
00165 break;
00166 }
00167 }
00168
00169 return bHandled;
00170 }
00171
00172 }
00173