Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related GUIControl.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 "GUIControl.h" 00010 #include <string> 00011 #include <sstream> 00012 #include <iostream> 00013 #include <map> 00014 00015 namespace GUIToolkit { 00016 00017 GUIControl * GUIControl::GUIInstance = 0; 00018 00019 std::string GUIControl::my_itos(int i) // convert int to string 00020 { 00021 std::stringstream s; 00022 s << i; 00023 return s.str(); 00024 } 00025 00026 GUIControl::GUIControl(HINSTANCE my_hInstance, int my_nCmdShow) { 00027 ComponentIDCounter = 0; 00028 firstWindow = 0; 00029 WINIDCounter = 0; 00030 testHack = 0; 00031 GUIInstance = this; 00032 nCmdShow = my_nCmdShow; 00033 hInstance = my_hInstance; 00034 } 00035 00036 void GUIControl::MessageLoop() { 00037 00038 00039 00040 // Step 3: The Message Loop 00041 while(GetMessage(&Msg, NULL, 0, 0) > 0) 00042 { 00043 TranslateMessage(&Msg); 00044 DispatchMessage(&Msg); 00045 } 00046 } 00047 00048 00049 void GUIControl::DEBUG(std::string t) { 00050 if (ErrorTextBox !=0) { 00051 ErrorTextBox->addText(t); 00052 } 00053 }; 00054 00055 void GUIControl::DEBUG(char t[]) { 00056 if (ErrorTextBox !=0) { 00057 ErrorTextBox->addText(std::string(t)); 00058 } 00059 }; 00060 00061 void GUIControl::DEBUG(int t) { 00062 if (ErrorTextBox !=0) { 00063 ErrorTextBox->addText(my_itos(t)); 00064 } 00065 }; 00066 00067 LRESULT CALLBACK GUIControl::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 00068 { // This is the main eventhandler. 00069 // It refines the events and delegates them to the components. 00070 00071 ComponentMapIter it; 00072 HWNDMapIter chk; 00073 event e; 00074 e.hwnd = hwnd; e.msg = msg; e.wParam = wParam, e.lParam = lParam; 00075 e.EventSource = 0; 00076 00077 switch(msg) 00078 { case WM_CLOSE: 00079 DestroyWindow(hwnd); 00080 break; 00081 00082 case WM_DESTROY: 00083 // firstWindow is a handle to the essential window, that (hopefully) controls the logic 00084 if (hwnd == GUIInstance->firstWindow) PostQuitMessage(0); 00085 break; 00086 00087 /* 00088 case WM_CREATE: 00089 //WInstance->myEventHandler->HandleEvents(e); 00090 break; 00091 00092 00093 case WM_DRAWITEM: 00094 00095 break; 00096 */ 00097 00098 case WM_PAINT: 00099 { // BITMAP bm; 00100 00101 if ( (GUIInstance->registerManualDraw.find(hwnd)) != (GUIInstance->registerManualDraw.end()) ) { 00102 GUIInstance->registerManualDraw[hwnd]->draw(); 00103 } else 00104 { 00105 return DefWindowProc(hwnd, msg, wParam, lParam); 00106 } 00107 /* 00108 for(it = (GUIInstance->registreredComponents).begin(); it != (GUIInstance->registreredComponents).end(); ++it) 00109 { 00110 00111 // Compare ComponentHWND to HWND sent from Windows (HWND) 00112 //if (lParam != 0) 00113 if ((*it).first->getHWND()==hwnd) { 00114 //GUIInstance->DEBUG((int)hwnd); 00115 // Get component 00116 (*it).first->draw(); 00117 } 00118 } 00119 } 00120 */ 00121 // 00122 } 00123 // break; 00124 00125 case WM_LBUTTONDOWN: 00126 case WM_LBUTTONUP: 00127 case WM_MOUSEMOVE: 00128 case WM_RBUTTONDOWN: 00129 00130 // Iterate over registered components. 00131 //GUIInstance->DEBUG("THIS"); 00132 //GUIInstance->DEBUG((int)hwnd); 00133 00134 for(it = (GUIInstance->registreredComponents).begin(); it != (GUIInstance->registreredComponents).end(); ++it) 00135 { 00136 00137 // Compare ComponentHWND to HWND sent from Windows (HWND) 00138 //if (lParam != 0) 00139 if ((*it).first->getHWND()==hwnd) { 00140 // Get component 00141 //GUIInstance->DEBUG((int)(*it).first->getHWND()); 00142 e.EventSource = (Component *) (*it).first; 00143 e.EventSource->HandleEvents(e); 00144 } 00145 } 00146 break; 00147 case WM_HSCROLL: 00148 case WM_VSCROLL: 00149 00150 00151 // Iterate over registered components. 00152 for(it = (GUIInstance->registreredComponents).begin(); it != (GUIInstance->registreredComponents).end(); ++it) 00153 { 00154 00155 // Compare ComponentHWND to HWND sent from Windows (lParam) 00156 if (lParam != 0) 00157 if ((*it).first->getHWND()==(HWND) lParam) { 00158 // Get component 00159 e.EventSource = (Component *) (*it).first; 00160 e.EventSource->HandleEvents(e); 00161 } 00162 } 00163 break; 00164 00165 case WM_COMMAND: 00166 00167 char buffer [33]; 00168 std::cout << HIWORD(wParam) << " " << LOWORD(wParam) << " " << lParam << " " << hwnd << std::endl; 00169 // 0 1 0 hwnd 00170 00171 00172 // Iterate over registered components. 00173 for(it = (GUIInstance->registreredComponents).begin(); it != (GUIInstance->registreredComponents).end(); ++it) 00174 { 00175 itoa ((*it).second,buffer,10); 00176 00177 // Compare ComponentID to ID sent from Windows (wParam) 00178 if ((*it).second==LOWORD(wParam)) { 00179 // Get component 00180 e.EventSource = (Component *) (*it).first; 00181 00182 // If component has got an eventhandler : call it. 00183 { e.EventSource->HandleEvents(e); } 00184 00185 //GUIInstance->myEventHandler->HandleEvents(e); 00186 //MessageBox(hwnd, buffer, "Error", MB_OK | MB_ICONERROR); 00187 } 00188 00189 } 00190 break; 00191 default: 00192 return DefWindowProc(hwnd, msg, wParam, lParam); 00193 } 00194 return 0; 00195 } 00196 00197 std::string GUIControl::getUniqueName() { 00198 WINIDCounter++; 00199 00200 std::ostringstream output; 00201 output << "XWOWZ-" << WINIDCounter++; 00202 00203 std::string theLine = output.str(); 00204 00205 return theLine; 00206 } 00207 00208 00209 int GUIControl::Register(Component * m) { 00210 ComponentIDCounter++; 00211 registreredComponents[m]=ComponentIDCounter ; 00212 return ComponentIDCounter; 00213 } 00214 00215 void GUIControl::RegisterManualDraw(HWND hwdn, Component * m) { 00216 registerManualDraw[hwdn]=m ; 00217 } 00218 00219 int GUIControl::RegisterRaw(Component * m) { 00220 ComponentIDCounter++; 00221 //special = m; 00222 registreredComponents[m]=ComponentIDCounter ; 00223 return ComponentIDCounter; 00224 } 00225 00226 void GUIControl::RegisterEvents(Component * m, EventHandler * e) { 00227 registreredEventHandlers[m]=e; 00228 } 00229 00230 /* 00231 int GUIControl::RegisterRaw(Component * m) { 00232 ComponentIDCounter++; 00233 //special = m; 00234 registreredComponents[m]=ComponentIDCounter ; 00235 return ComponentIDCounter; 00236 }*/ 00237 00238 }; // end of namespace Docs made by Doxygen. Email: Mikael Christensen |