Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related Listbox.cpp00001 // 00002 // SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation. 00003 // 00004 // Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net) 00005 // 00006 00007 00008 00009 #include "ListBox.h" 00010 00011 namespace GUIToolkit { 00012 00013 ScrollBar::ScrollBar(float min, float max, int steps) {myMin = min; myMax = max; mySteps = steps;} 00014 ScrollBar::~ScrollBar() {}; 00015 00016 void ScrollBar::PutInWinForm(WinForm * WF, int x0, int y0, int sizex, int sizey) { 00017 ID = (HMENU)GUIControl::GUIInstance->Register(this); 00018 topWF = WF; 00019 hEdit = CreateWindowEx(0, 00020 "SCROLLBAR", // classname 00021 "", // label 00022 WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_HORZ, // window-styles 00023 x0,y0, // position 00024 sizex,sizey, // size 00025 WF->hwnd, // handle 00026 ID, // control ID 00027 GetModuleHandle(NULL), // instance 00028 NULL); 00029 00030 00031 if(hEdit == NULL) { 00032 MessageBox(WF->hwnd, "Could not create combobox box.", "Error", MB_OK | MB_ICONERROR); 00033 // Todo: Should Throw Error 00034 } 00035 00036 SetScrollRange (hEdit, SB_CTL, 0, mySteps, FALSE); 00037 //SetScrollPos (hEdit, SB_CTL, steps / 2, TRUE); 00038 myPos = (myMax + myMin) / 2.0; 00039 set(myPos); 00040 00041 } 00042 00043 void ScrollBar::set(float p) { 00044 if (p < myMin) p = myMin; 00045 if (p > myMax) p = myMax; 00046 myPos = p; 00047 int myIntPos = (int) ((float)mySteps*(p-myMin)/(myMax-myMin)); 00048 SetScrollPos (hEdit, SB_CTL, myIntPos , TRUE); 00049 } 00050 00051 void ScrollBar::setInt(int p) { 00052 if (p < 0) p = 0; 00053 if (p > mySteps) p = mySteps; 00054 myPos = myMin+p*(myMax-myMin)/((float)mySteps); 00055 SetScrollPos (hEdit, SB_CTL, p , TRUE); 00056 } 00057 00058 float ScrollBar::get() { 00059 return myPos; 00060 } 00061 00062 void ScrollBar::HandleEvents(event e) 00063 { 00064 if (e.msg == WM_HSCROLL) 00065 { 00066 if (LOWORD(e.wParam)==SB_THUMBTRACK) { 00067 // we are dragging the slider 00068 setInt(HIWORD(e.wParam)); 00069 } 00070 00071 if (LOWORD(e.wParam)==SB_PAGELEFT || LOWORD(e.wParam)==SB_LINELEFT) { 00072 // we are pressing arrow button 00073 set(get()-(myMax - myMin)/100.0f); 00074 e.EventSource = this; 00075 if (myEventHandler !=0) myEventHandler->HandleEvents(e); 00076 } 00077 00078 if (LOWORD(e.wParam)==SB_PAGERIGHT || LOWORD(e.wParam)==SB_LINERIGHT) { 00079 // we are pressing arrow button 00080 set(get()+(myMax - myMin)/100.0f); 00081 e.EventSource = this; 00082 if (myEventHandler !=0) myEventHandler->HandleEvents(e); 00083 } 00084 00085 if (LOWORD(e.wParam)==SB_THUMBPOSITION) { 00086 // we are done dragging the slider 00087 setInt(HIWORD(e.wParam)); 00088 // pass event on to user event handler 00089 e.EventSource = this; 00090 if (myEventHandler !=0) myEventHandler->HandleEvents(e); 00091 } 00092 } 00093 00094 00095 }; 00096 00097 void ScrollBar::show() 00098 { 00099 ShowWindow( hEdit,SW_SHOW ); 00100 }; 00101 00102 void ScrollBar::hide() { 00103 ShowWindow( hEdit,SW_HIDE ); 00104 }; 00105 00106 00107 00108 00109 // ------------------------------------------------- 00110 00111 00112 ComboBox::ComboBox() {ItemCounter = 0;}; 00113 ComboBox::~ComboBox() {}; 00114 00115 void ComboBox::PutInWinForm(WinForm * WF, int x0, int y0, int sizex, int sizey) { 00116 ID = (HMENU)GUIControl::GUIInstance->Register(this); 00117 topWF = WF; 00118 hEdit = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, 00119 "COMBOBOX", // classname 00120 "", // label 00121 WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP, // window-styles 00122 x0,y0, // position 00123 sizex,sizey, // size 00124 WF->hwnd, // handle 00125 ID, // control ID 00126 GetModuleHandle(NULL), // instance 00127 NULL); 00128 00129 00130 if(hEdit == NULL) { 00131 MessageBox(WF->hwnd, "Could not create combobox box.", "Error", MB_OK | MB_ICONERROR); 00132 // Todo: Should Throw Error 00133 } 00134 00135 00136 } 00137 00138 void ComboBox::add(ComboBoxItem * item) 00139 { 00140 //myItems[item] = ++ItemCounter; 00141 item->ID = SendMessage(hEdit, CB_ADDSTRING, 0, (LPARAM) item->Label.c_str()); 00142 myItems[item] = item->ID; 00143 } 00144 00145 ComboBoxItem * ComboBox::getSelected() { 00146 int index = SendMessage(hEdit, CB_GETCURSEL, 0, 0); 00147 00148 char buffer [33]; 00149 itoa (index,buffer,10); 00150 //if (index!=-1) MessageBox(topWF->hwnd, buffer, "DEBUG", MB_OK | MB_ICONERROR); 00151 00152 //Iterate over items in combobox 00153 for(ComboBoxMapIter it = myItems.begin(); it != myItems.end(); ++it) 00154 { 00155 if ((*it).second==index) { 00156 return (ComboBoxItem *) (*it).first; 00157 } 00158 } 00159 return 0; 00160 } 00161 00162 void ComboBox::setSelected(ComboBoxItem * item) 00163 { 00164 for(ComboBoxMapIter it = myItems.begin(); it != myItems.end(); ++it) 00165 { 00166 if ((*it).first==item) { 00167 setSelected((*it).second); 00168 } 00169 } 00170 } 00171 00172 void ComboBox::setSelected(int index) 00173 { 00174 SendMessage( hEdit, (UINT) CB_SETCURSEL, (WPARAM) index,0); 00175 } 00176 00177 void ComboBox::show() { 00178 ShowWindow( hEdit,SW_SHOW ); 00179 }; 00180 void ComboBox::hide() { 00181 ShowWindow( hEdit,SW_HIDE ); 00182 }; 00183 00184 }; // end of namespace Docs made by Doxygen. Email: Mikael Christensen |