00001
00002
00003
00004
00005
00006
00007 #include "stdinc.h"
00008 #include "icon.h"
00009 #include "eventhandler.h"
00010 #include "widgets.h"
00011 #include "menu.h"
00012 #include "widget.h"
00013 #include "combobox.h"
00014 #include "exception.h"
00015 namespace MWidgets
00016 {
00017
00018
00019 ComboBox::ComboBox():Widget()
00020 {
00021 m_pOnChangeHandler=NULL;
00022 };
00023
00024 ComboBox::~ComboBox()
00025 {
00026 if(m_pOnChangeHandler)
00027 delete m_pOnChangeHandler;
00028 };
00029
00030 void ComboBox::Create(Widget *parent,int x,int y,int w,int h)
00031 {
00032 Widget::Create(x,y,w,h,"","COMBOBOX",WS_CHILD|WS_BORDER|WS_TABSTOP|WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWN|WS_CLIPSIBLINGS,parent->GetHwnd());
00033 };
00034
00035 LRESULT ComboBox::OnMessage (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00036 {
00037 string str;
00038 if(message!=WM_GETTEXTLENGTH&&message!=WM_GETTEXT)
00039 str=GetText();
00040
00041 LRESULT rez=Widget::OnMessage(hWnd, message, wParam,lParam);
00042
00043 if(message!=WM_GETTEXTLENGTH&&message!=WM_GETTEXT&&message!=WM_DESTROY&&message!=WM_NCDESTROY)
00044 if(GetText().compare(str)!=0)
00045 OnChange();
00046 return rez;
00047 };
00048
00049 void ComboBox::OnCommand( WORD code,WORD )
00050 {
00051 if(code==CBN_EDITCHANGE)
00052 OnChange();
00053 };
00054
00055 void ComboBox::OnChange()
00056 {
00057 if(m_pOnChangeHandler)
00058 {
00059 m_pOnChangeHandler->Call(this);
00060 }
00061 };
00062
00063 int ComboBox::AddString(string str)
00064 {
00065 int rez=(int)SendMessage(m_hWnd,CB_ADDSTRING,0,(LPARAM)str.c_str());
00066 if(rez!=CB_ERR)
00067 return rez;
00068 return -1;
00069 };
00070
00071 void ComboBox::DelString(int index)
00072 {
00073 SendMessage(m_hWnd,CB_DELETESTRING,index,0);
00074 };
00075
00076 void ComboBox::Clear()
00077 {
00078 SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0);
00079 };
00080
00081 int ComboBox::GetItemsCount()
00082 {
00083 int rez=(int)SendMessage(m_hWnd,CB_GETCOUNT,0,0);
00084 if(rez!=CB_ERR)
00085 return rez;
00086 return -1;
00087 };
00088
00089 WIDGET_TYPE ComboBox::GetType()
00090 {
00091 return COMBOBOX;
00092 };
00093
00094 };