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_messagebox.h"
00027
00028 namespace wGui
00029 {
00030
00031 CMessageBox::CMessageBox(CView* pParent, CFontEngine* pFontEngine, const std::wstring& sTitle, const std::wstring& sMessage, int iButtons) :
00032 CFrame(CRect(20, 20, 320, 100), pParent, pFontEngine, sTitle),
00033 m_iButtons(iButtons)
00034 {
00035 m_pMessageLabel = new CLabel(CRect(10, 10, 290, 26), this, sMessage);
00036 CPoint BottomRight(290, 56);
00037 if (iButtons & CMessageBox::BUTTON_CANCEL)
00038 {
00039 m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_CANCEL, new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, L"Cancel")));
00040 BottomRight = BottomRight - CPoint(60, 0);
00041 }
00042 if (iButtons & CMessageBox::BUTTON_OK)
00043 {
00044 m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_OK, new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, L"Ok")));
00045 BottomRight = BottomRight - CPoint(60, 0);
00046 }
00047 if (iButtons & CMessageBox::BUTTON_NO)
00048 {
00049 m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_NO, new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, L"No")));
00050 BottomRight = BottomRight - CPoint(60, 0);
00051 }
00052 if (iButtons & CMessageBox::BUTTON_YES)
00053 {
00054 m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_YES, new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, L"Yes")));
00055 BottomRight = BottomRight - CPoint(60, 0);
00056 }
00057 FitToText();
00058 }
00059
00060
00061 void CMessageBox::FitToText(void)
00062 {
00063 CPoint TextRect;
00064 m_pMessageLabel->GetRenderedString()->GetMetrics(&TextRect);
00065 CRect LabelRect = m_pMessageLabel->GetWindowRect();
00066 CPoint Offset(TextRect.XPos() - LabelRect.Width(), TextRect.YPos() - LabelRect.Height());
00067 m_pMessageLabel->SetWindowRect(CRect(10, 10, 10 + TextRect.XPos(), 10 + TextRect.YPos()));
00068 SetWindowRect(CRect(m_WindowRect.TopLeft(), m_WindowRect.BottomRight() + Offset));
00069 for (std::map<EButton, CButton*>::iterator iter = m_ButtonMap.begin(); iter != m_ButtonMap.end(); ++iter)
00070 {
00071 iter->second->SetWindowRect(iter->second->GetWindowRect() + Offset);
00072 }
00073 }
00074
00075
00076 bool CMessageBox::HandleMessage(CMessage* pMessage)
00077 {
00078 bool bHandled = false;
00079
00080 if (pMessage)
00081 {
00082 switch(pMessage->MessageType())
00083 {
00084 case CMessage::CTRL_SINGLELCLICK:
00085 {
00086 if (pMessage->Destination() == this)
00087 {
00088 for (std::map<EButton, CButton*>::iterator iter = m_ButtonMap.begin(); iter != m_ButtonMap.end(); ++iter)
00089 {
00090 if (pMessage->Source() == iter->second)
00091 {
00092 CMessageServer::Instance().QueueMessage(new CValueMessage<CMessageBox::EButton>(CMessage::CTRL_MESSAGEBOXRETURN, m_pParentWindow, 0, iter->first));
00093 CloseFrame();
00094 bHandled = true;
00095 break;
00096 }
00097 }
00098 }
00099 break;
00100 }
00101 default:
00102 break;
00103 }
00104 if (!bHandled)
00105 {
00106 bHandled = CFrame::HandleMessage(pMessage);
00107 }
00108 }
00109
00110 return bHandled;
00111 }
00112
00113 }