00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CATControlWnd.h"
00017 #include "CATWindow.h"
00018 #include "CATOSFuncs.h"
00019 #include "CATEventDefs.h"
00020
00021
00022 LRESULT WINAPI CATControlWnd::CustomControlProc( HWND hWnd,
00023 UINT message,
00024 WPARAM wParam,
00025 LPARAM lParam)
00026 {
00027 CATControlWnd* theControl = (CATControlWnd*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
00028
00029 bool handled = false;
00030 CATInt32 result = 0;
00031
00032
00033
00034 if (theControl)
00035 {
00036 handled = theControl->OnControlEvent(CATEvent(CATEVENT_WINDOWS_EVENT,(CATInt32)hWnd,message,wParam,lParam), result);
00037 }
00038
00039 if (!handled)
00040 {
00041 switch (message)
00042 {
00043 case WM_MOUSELEAVE:
00044 theControl->fCaptured = false;
00045 break;
00046
00047
00048 case WM_MOUSEHOVER:
00049 {
00050 POINT pt;
00051 pt.x = (CATInt32)(CATUInt16)(LOWORD(lParam));
00052 pt.y = (CATInt32)(CATUInt16)(HIWORD(lParam));
00053 ::ClientToScreen(hWnd,&pt);
00054 ::ScreenToClient(theControl->GetWindow()->OSGetWnd(),&pt);
00055 ::SendMessage(theControl->GetWindow()->OSGetWnd(), WM_MOUSEHOVER,wParam, MAKELONG(pt.x, pt.y) );
00056 handled = true;
00057 }
00058 break;
00059 case WM_MOUSEMOVE:
00060 {
00061 if ((::GetActiveWindow() != hWnd) && (!theControl->fCaptured))
00062 {
00063 theControl->GetWindow()->SetTrackMouse(hWnd);
00064 theControl->fCaptured = true;
00065 }
00066
00067 POINT pt;
00068 pt.x = (CATInt32)(CATUInt16)(LOWORD(lParam));
00069 pt.y = (CATInt32)(CATUInt16)(HIWORD(lParam));
00070 ::ClientToScreen(hWnd,&pt);
00071 ::ScreenToClient(theControl->GetWindow()->OSGetWnd(),&pt);
00072 ::SendMessage(theControl->GetWindow()->OSGetWnd(), WM_MOUSEMOVE,wParam, MAKELONG(pt.x, pt.y) );
00073 handled = true;
00074 }
00075 break;
00076 case WM_CHAR:
00077 {
00078 switch (LOWORD(wParam))
00079 {
00080 case 0x1b:
00081 theControl->OnEscapeChange();
00082 theControl->GetWindow()->KillFocus();
00083 result = 1;
00084 handled = true;
00085 break;
00086
00087 case 0x0a:
00088 case 0x0d:
00089 theControl->GetWindow()->KillFocus();
00090 result = 1;
00091 handled = true;
00092 break;
00093 case 0x09:
00094 {
00095 bool shift = (GetKeyState(VK_SHIFT) & 0x8000)?true:false;
00096 if (shift)
00097 {
00098 theControl->GetWindow()->SetFocusPrev();
00099 }
00100 else
00101 {
00102 theControl->GetWindow()->SetFocusNext();
00103 }
00104 result = 1;
00105 handled = true;
00106 }
00107 break;
00108 }
00109 }
00110 break;
00111 case WM_KILLFOCUS:
00112 theControl->fCaptured = false;
00113 break;
00114
00115 case WM_SETFOCUS:
00116
00117 theControl->GetWindow()->SetFocus(theControl);
00118 theControl->fCaptured = false;
00119 break;
00120 }
00121 }
00122
00123 if ((theControl != 0) && (handled == false))
00124 {
00125 result = ::CallWindowProc((WNDPROC)theControl->fOldWndProc,hWnd,message,wParam,lParam);
00126 }
00127
00128 return result;
00129 }
00130
00131
00132 CATResult CATControlWnd::CreateControlWnd(
00133 const CATString& windowClass,
00134 CATUInt32 style )
00135 {
00136
00137 if (this->fControlWnd)
00138 {
00139 this->GetWindow()->UnRegCtlWnd(fControlWnd);
00140 this->GetWindow()->OSDestroyWnd(fControlWnd);
00141 fControlWnd = 0;
00142 fOldWndProc = 0;
00143 }
00144
00145 CATRect absRect = this->GetRectAbs();
00146
00147 this->fControlWnd =
00148 ::CreateWindow( windowClass,
00149 0,
00150 style,
00151 absRect.left, absRect.top, absRect.Width(), absRect.Height(),
00152 this->GetWindow()->OSGetWnd(),
00153 (HMENU)0,
00154 (HINSTANCE)::GetWindowLong(this->GetWindow()->OSGetWnd(), GWL_HINSTANCE),
00155 0);
00156
00157 if (fControlWnd)
00158 {
00159 fOldWndProc = ::GetWindowLongPtr(fControlWnd, GWLP_WNDPROC);
00160
00161 ::SetWindowLongPtr(fControlWnd, GWLP_WNDPROC, (CATInt32)CustomControlProc);
00162 ::SetWindowLongPtr(fControlWnd, GWLP_USERDATA, (CATInt32)this);
00163 ::SetWindowPos(fControlWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOZORDER|SWP_NOSIZE);
00164
00165 this->GetWindow()->RegCtlWnd(this,fControlWnd);
00166
00167 ::EnableWindow(fControlWnd,this->IsEnabled());
00168 return CAT_SUCCESS;
00169 }
00170 else
00171 {
00172 fOldWndProc = 0;
00173 return CATRESULT(CAT_ERR_WINDOW_CREATE_FAILED);
00174 }
00175
00176 }
00177
00178
00179
00180
00181 bool CATControlWnd::OnControlEvent( const CATEvent& event, CATInt32& result)
00182 {
00183 return false;
00184 }
00185
00186 CATResult CATControlWnd::OSCreate()
00187 {
00188 if (fFGBrush != 0)
00189 {
00190 DeleteObject(fFGBrush);
00191 fFGBrush = 0;
00192 }
00193
00194 if (fFGFocBrush != 0)
00195 {
00196 DeleteObject(fFGFocBrush);
00197 fFGFocBrush = 0;
00198 }
00199
00200 if (fBGBrush != 0)
00201 {
00202 DeleteObject(fBGBrush);
00203 fBGBrush = 0;
00204 }
00205
00206 if (fBGFocBrush != 0)
00207 {
00208 DeleteObject(fBGFocBrush);
00209 fBGFocBrush = 0;
00210 }
00211
00212 if (fFGDisBrush != 0)
00213 {
00214 DeleteObject(fFGDisBrush);
00215 fFGDisBrush = 0;
00216 }
00217
00218 if (fBGDisBrush != 0)
00219 {
00220 DeleteObject(fBGDisBrush);
00221 fBGDisBrush = 0;
00222 }
00223
00224
00225 fFGBrush = ::CreateSolidBrush(RGB(this->fForegroundColor.r, fForegroundColor.g, fForegroundColor.b));
00226 fBGBrush = ::CreateSolidBrush(RGB(this->fBackgroundColor.r, fBackgroundColor.g, fBackgroundColor.b));
00227 fFGFocBrush = ::CreateSolidBrush(RGB(this->fFGColor_focus.r, fFGColor_focus.g, fFGColor_focus.b));
00228 fBGFocBrush = ::CreateSolidBrush(RGB(this->fBGColor_focus.r, fBGColor_focus.g, fBGColor_focus.b));
00229 fFGDisBrush = ::CreateSolidBrush(RGB(this->fFgDisColor.r, fFgDisColor.g, fFgDisColor.b));
00230 fBGDisBrush = ::CreateSolidBrush(RGB(this->fBgDisColor.r, fBgDisColor.g, fBgDisColor.b));
00231
00232
00233 if ((fFGBrush != 0) && (fBGBrush != 0) && (fFGFocBrush != 0) && (fBGFocBrush != 0))
00234 {
00235 return CAT_SUCCESS;
00236 }
00237 else
00238 {
00239 return CATRESULT(CAT_ERR_OUT_OF_MEMORY);
00240 }
00241 }
00242
00243 HBRUSH CATControlWnd::GetBGBrush()
00244 {
00245 if (this->fFocused)
00246 {
00247 return fBGFocBrush;
00248 }
00249 else if (this->IsEnabled() == false)
00250 {
00251 return fBGDisBrush;
00252 }
00253 else
00254 {
00255 return fBGBrush;
00256 }
00257 }
00258
00259 void CATControlWnd::OSCleanup()
00260 {
00261 this->GetWindow()->UnRegCtlWnd(fControlWnd);
00262
00263 if (fFGBrush != 0)
00264 {
00265 DeleteObject(fFGBrush);
00266 fFGBrush = 0;
00267 }
00268
00269 if (fFGFocBrush != 0)
00270 {
00271 DeleteObject(fFGFocBrush);
00272 fFGFocBrush = 0;
00273 }
00274
00275 if (fBGBrush != 0)
00276 {
00277 DeleteObject(fBGBrush);
00278 fBGBrush = 0;
00279 }
00280
00281 if (fBGFocBrush != 0)
00282 {
00283 DeleteObject(fBGFocBrush);
00284 fBGFocBrush = 0;
00285 }
00286
00287 if (fControlWnd)
00288 {
00289 this->GetWindow()->OSDestroyWnd(fControlWnd);
00290 fControlWnd = 0;
00291 }
00292 fOldWndProc = 0;
00293 }
00294
00295 void CATControlWnd::OSDrawBorderRect(CATDRAWCONTEXT drawContext, CATRect& rect)
00296 {
00297 RECT wrect = *(RECT*)(CATRECT*)▭
00298 HPEN fgPen = ::CreatePen(PS_SOLID,1, RGB(fFGColor_border.r,fFGColor_border.g,fFGColor_border.b));
00299 HPEN bgPen = ::CreatePen(PS_SOLID,1,RGB(fBGColor_border.r, fBGColor_border.g, fBGColor_border.b));
00300
00301 HPEN oldPen = (HPEN)::SelectObject(drawContext,bgPen);
00302
00303 ::MoveToEx(drawContext,wrect.left,wrect.bottom,0);
00304 ::LineTo(drawContext,wrect.left,wrect.top);
00305 ::LineTo(drawContext,wrect.right,wrect.top);
00306
00307 ::SelectObject(drawContext,fgPen);
00308
00309 ::LineTo(drawContext,wrect.right,wrect.bottom);
00310 ::LineTo(drawContext,wrect.left,wrect.bottom);
00311 ::SelectObject(drawContext,oldPen);
00312
00313 DeleteObject(fgPen);
00314 DeleteObject(bgPen);
00315 }
00316
00317 void CATControlWnd::OSSetText(const CATString& newText)
00318 {
00319 if (this->fControlWnd)
00320 {
00321 ::SetWindowText(fControlWnd, newText);
00322 }
00323 }
00324
00325 void CATControlWnd::OSGetText(CATString& newText)
00326 {
00327 if (this->fControlWnd)
00328 {
00329 CATUInt32 textLen = ::GetWindowTextLength(fControlWnd);
00330 if (textLen == 0)
00331 {
00332 newText = "";
00333 }
00334 else
00335 {
00336 ::GetWindowText(fControlWnd,newText.GetUnicodeBuffer(textLen+2), textLen + 1);
00337 newText.ReleaseBuffer();
00338 }
00339 }
00340 }