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_radiobutton.h"
00027 #include "wg_message_server.h"
00028 #include "wg_painter.h"
00029
00030
00031 namespace wGui
00032 {
00033
00034
00035 CRadioButton::CRadioButton(const CRect& WindowRect, CWindow* pParent) :
00036 CWindow(WindowRect, pParent),
00037 m_eRadioButtonState(UNCHECKED),
00038 m_MouseButton(0)
00039 {
00040 m_BackgroundColor = COLOR_WHITE;
00041 CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_BUTTONUP);
00042 CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_SINGLELCLICK);
00043 Draw();
00044 }
00045
00046
00047 void CRadioButton::SetState(EState eState)
00048 {
00049 if (m_eRadioButtonState != eState)
00050 {
00051 m_eRadioButtonState = eState;
00052 Draw();
00053 }
00054 }
00055
00056
00057 void CRadioButton::Draw(void) const
00058 {
00059 CWindow::Draw();
00060 if (m_pSDLSurface)
00061 {
00062 CRect SubRect(m_WindowRect.SizeRect());
00063 CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE);
00064 if (m_eRadioButtonState != DISABLED)
00065 {
00066 Painter.DrawRect(SubRect, false, COLOR_DARKGRAY);
00067 if (m_eRadioButtonState == CHECKED)
00068 {
00069 SubRect.Grow(-3);
00070 Painter.DrawRect(SubRect, true, COLOR_BLACK, COLOR_BLACK);
00071 }
00072 }
00073 else
00074 {
00075 Painter.DrawRect(SubRect, false, COLOR_LIGHTGRAY);
00076 }
00077 }
00078 }
00079
00080
00081 bool CRadioButton::OnMouseButtonDown(CPoint Point, unsigned
00082 int Button)
00083 {
00084 bool bResult = CWindow::OnMouseButtonDown(Point, Button);
00085 if (!bResult && m_bVisible && (m_eRadioButtonState != DISABLED) &&
00086 (m_ClientRect.HitTest(ViewToWindow(Point)) == CRect::RELPOS_INSIDE))
00087 {
00088 m_MouseButton = Button;
00089 bResult = true;
00090 }
00091 return bResult;
00092 }
00093
00094
00095 bool CRadioButton::OnMouseButtonUp(CPoint Point, unsigned int Button)
00096 {
00097 bool bResult = CWindow::OnMouseButtonUp(Point, Button);
00098 if (!bResult && m_bVisible && (m_eRadioButtonState != DISABLED) &&
00099 (m_MouseButton == Button) && (m_ClientRect.HitTest(ViewToWindow(Point)) == CRect::RELPOS_INSIDE))
00100 {
00101 CMessage::EMessageType MessageType = CMessage::UNKNOWN;
00102 switch (m_MouseButton)
00103 {
00104 case CMouseMessage::LEFT:
00105 MessageType = CMessage::CTRL_SINGLELCLICK;
00106 break;
00107 case CMouseMessage::RIGHT:
00108 MessageType = CMessage::CTRL_SINGLERCLICK;
00109 break;
00110 case CMouseMessage::MIDDLE:
00111 MessageType = CMessage::CTRL_SINGLEMCLICK;
00112 break;
00113 }
00114 CMessageServer::Instance().QueueMessage(new TIntMessage(MessageType, this, this, 0));
00115 bResult = true;
00116 }
00117 return bResult;
00118 }
00119
00120
00121 bool CRadioButton::HandleMessage(CMessage* pMessage)
00122 {
00123 bool bHandled = false;
00124
00125 if (pMessage)
00126 {
00127 switch(pMessage->MessageType())
00128 {
00129 case CMessage::MOUSE_BUTTONUP:
00130 {
00131 CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);
00132 if (pMouseMessage && (m_ClientRect.HitTest(ViewToWindow(pMouseMessage->Point)) !=
00133 CRect::RELPOS_INSIDE) && (m_MouseButton == pMouseMessage->Button))
00134 {
00135 m_MouseButton = 0;
00136 bHandled = true;
00137 }
00138 break;
00139 }
00140 case CMessage::CTRL_SINGLELCLICK:
00141 if (pMessage->Destination() == this)
00142 {
00143 if (m_eRadioButtonState == UNCHECKED)
00144 {
00145 SetState(CHECKED);
00146
00147 std::list<CWindow*> ChildWindows = m_pParentWindow->GetChildWindows();
00148 for (std::list<CWindow*>::iterator iter = ChildWindows.begin(); iter != ChildWindows.end(); ++iter)
00149 {
00150
00151 CRadioButton* pRadioButton = dynamic_cast<CRadioButton*>(*iter);
00152 if (pRadioButton && *iter != this)
00153 {
00154 pRadioButton->SetState(UNCHECKED);
00155 }
00156 }
00157 CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 1));
00158 break;
00159 }
00160 bHandled = true;
00161 }
00162 break;
00163 default :
00164 bHandled = CWindow::HandleMessage(pMessage);
00165 break;
00166 }
00167 }
00168
00169 return bHandled;
00170 }
00171
00172 }
00173