- Timestamp:
- Aug 24, 2008, 5:28:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
r604 r615 12 12 End Namespace 13 13 14 /* 15 @brief Windowsのウィンドウを管理する基底クラス 16 @auther Egtra 17 */ 14 18 Class Control 15 19 Inherits WindowHandle … … 24 28 Sub Control() 25 29 comImpl = New COM.ComClassDelegationImpl(This) 26 End Sub27 28 Virtual Sub ~Control()29 30 End Sub 30 31 … … 52 53 '-------------------------------- 53 54 ' ウィンドウ作成 54 ' Function Create(55 ' parent As HWND,56 ' rect As RECT,57 ' name As String,58 ' style As DWord,59 ' exStyle = 0 As DWord,60 ' menu = 0 As HMENU) As HWND61 55 62 56 Public … … 108 102 CreateEx(parent, style Or WS_CHILD Or WS_VISIBLE, exStyle, id As ULONG_PTR As HMENU) 109 103 End Sub 104 110 105 Protected 111 106 Abstract Sub GetCreateStruct(ByRef cs As CREATESTRUCT) 112 107 113 108 Sub createImpl(ByRef cs As CREATESTRUCT, parent As Control) 114 If hwnd <> 0 Then 115 Throw New System.InvalidOperationException("Window already created.") 116 End If 109 throwIfAlreadyCreated() 117 110 118 111 StartWndProc() … … 123 116 .x, .y, .cx, .cy, .hwndParent, .hMenu, .hInstance, .lpCreateParams) 124 117 If hwnd = 0 Then 125 ActiveBasic.Windows.ThrowWithLastError()118 ThrowWithLastErrorNT("Control.CreateEx") 126 119 End If 127 120 … … 134 127 If IsNothing(parent) = False Then 135 128 RegisterUnassociateHWnd(parent) 129 End If 130 End Sub 131 132 Public 133 Sub Attach(hwndNew As HWND) 134 throwIfAlreadyCreated() 135 If hwndNew = 0 Then 136 Throw New System.ArgumentNullException("Control.Attach") 137 End If 138 registerStandardEvent() 139 AssociateHWnd(hwndNew) 140 prevWndProc = SetWindowLongPtr(GWLP_WNDPROC, AddressOf(WndProcFirst) As LONG_PTR) As WNDPROC 141 End Sub 142 143 Private 144 Sub throwIfAlreadyCreated() 145 If hwnd <> 0 Then 146 Throw New System.InvalidOperationException("Window already created.") 136 147 End If 137 148 End Sub … … 148 159 Dim a = New MessageArgs(hwnd, msg, wp, lp) 149 160 h(This, a) 150 WndProc = a.LResult 151 Exit Function 161 If a.Handled Then 162 WndProc = a.LResult 163 Exit Function 164 End If 152 165 End If 153 166 End If … … 156 169 157 170 Virtual Function DefWndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT 158 DefWndProc = DefWindowProc(hwnd, msg, wp, lp) 171 If prevWndProc Then 172 DefWndProc = CallWindowProc(prevWndProc, hwnd, msg, wp, lp) 173 Else 174 DefWndProc = DefWindowProc(hwnd, msg, wp, lp) 175 End If 159 176 End Function 160 177 … … 219 236 220 237 Sub OnEraseBackground(sender As Object, e As MessageArgs) 221 If IsNothing(paintBackground) Then 222 Dim rc = ClientRect 223 FillRect(e.WParam As HDC, rc, (COLOR_3DFACE + 1) As HBRUSH) 224 Else 225 OnPaintBackground(New PaintBackgroundArgs(e.WParam, e.LParam)) 226 End If 227 e.LResult = TRUE 238 Dim a = New PaintBackgroundArgs(e.WParam, e.LParam) 239 e.Handled = e.Handled And OnPaintBackground(a) 240 e.LResult = a.Painted 228 241 End Sub 229 242 230 243 Sub OnMouseDownBase(sender As Object, e As MessageArgs) 231 OnMouseDown(makeMouseEventFromMsg(e))244 e.Handled = e.Handled And OnMouseDown(makeMouseEventFromMsg(e)) 232 245 End Sub 233 246 … … 240 253 doubleClickFired = False 241 254 End If 242 OnMouseUp(me)255 e.Handled = e.Handled And OnMouseUp(me) 243 256 End Sub 244 257 … … 248 261 OnMouseDown(me) 249 262 OnDoubleClick(Args.Empty) 250 OnMouseDoubleClick(me)263 e.Handled = e.Handled And OnMouseDoubleClick(me) 251 264 End Sub 252 265 … … 258 271 trackMouseEvent(TME_LEAVE Or TME_HOVER) 259 272 End If 260 OnMouseMove(me)273 e.Handled = e.Handled And OnMouseMove(me) 261 274 End Sub 262 275 263 276 Sub OnMouseLeaveBase(sender As Object, e As MessageArgs) 264 OnMouseLeave(Args.Empty)277 e.Handled = e.Handled And OnMouseLeave(Args.Empty) 265 278 mouseEntered = False 266 279 End Sub … … 268 281 Sub OnMouseHoverBase(sender As Object, e As MessageArgs) 269 282 Dim me = makeMouseEventFromMsg(e) 270 OnMouseHover(me)283 e.Handled = e.Handled And OnMouseHover(me) 271 284 End Sub 272 285 273 286 Sub OnPaintBase(sender As Object, e As MessageArgs) 274 Dim ps As PAINTSTRUCT 275 BeginPaint(ps) 276 Try 277 OnPaintDC(New PaintDCArgs(ps.hdc, ps.rcPaint)) 278 Finally 279 EndPaint(ps) 280 End Try 287 If ActiveBasic.IsNothing(paintDC) Then 288 e.Handled = False 289 Else 290 Dim ps As PAINTSTRUCT 291 BeginPaint(ps) 292 Try 293 OnPaintDC(New PaintDCArgs(ps.hdc, ps.rcPaint)) 294 Finally 295 EndPaint(ps) 296 End Try 297 End If 281 298 End Sub 282 299 283 300 Sub OnKeyDownBase(sender As Object, e As MessageArgs) 284 OnKeyDown(New KeyArgs(makeKeysFormMsg(e)))301 e.Handled = e.Handled And OnKeyDown(New KeyArgs(makeKeysFormMsg(e))) 285 302 End Sub 286 303 287 304 Sub OnKeyUpBase(sender As Object, e As MessageArgs) 288 OnKeyUp(New KeyArgs(makeKeysFormMsg(e)))305 e.Handled = e.Handled And OnKeyUp(New KeyArgs(makeKeysFormMsg(e))) 289 306 End Sub 290 307 291 308 Sub OnChar(sender As Object, e As MessageArgs) 292 OnKeyPress(New KeyPressArgs(e.WParam As Char))309 e.Handled = e.Handled And OnKeyPress(New KeyPressArgs(e.WParam As Char)) 293 310 End Sub 294 311 295 312 Sub OnCreateBase(sender As Object, e As MessageArgs) 296 OnCreate(New CreateArgs(e.LParam As *CREATESTRUCT))313 e.Handled = e.Handled And OnCreate(New CreateArgs(e.LParam As *CREATESTRUCT)) 297 314 End Sub 298 315 299 316 Sub OnSize(sender As Object, e As MessageArgs) 300 OnResize(New ResizeArgs(e.WParam, e.LParam))317 e.Handled = e.Handled And OnResize(New ResizeArgs(e.WParam, e.LParam)) 301 318 End Sub 302 319 … … 352 369 Private 353 370 /*! 371 @brief サブクラス化前のウィンドウプロシージャ 372 @date 2008/08/23 373 サブクラス化していなければNULL 374 */ 375 prevWndProc As WNDPROC 376 /*! 354 377 @brief マウスカーソルがクライアント領域に入っているかどうかのフラグ 355 378 外から中に入ってきたときにMouseEnterイベントを発生させるために用意している。 … … 381 404 If msg = WM_NCDESTROY Then 382 405 rThis.UnassociateHWnd() 406 rThis.hwnd = 0 383 407 End If 384 408 If msg = WM_DESTROY And IsNothing(rThis.finalDestroy) = False Then 385 409 Dim f = rThis.finalDestroy 386 410 f(rThis, Args.Empty) 387 ' finalDestroy(This, Args.Empty)388 411 End If 389 412 WndProcFirst = rThis.WndProc(msg, wp, lp) … … 391 414 392 415 *InstanceIsNotFound 393 Dim err = "ActiveBasic.Windows.UI.Control.WndProcFirst: The attached instance is not found. msg = &h" _394 + Hex$(msg) + Ex"\r\n"416 Dim err = String.Concat("Control.WndProcFirst: The attached instance is not found. msg = &h", 417 Hex$(msg), Ex"\r\n") 395 418 OutputDebugString(ToTCStr(err)) 396 419 WndProcFirst = DefWindowProc(hwnd, msg, wp, lp) … … 399 422 /*! 400 423 @brief Controlインスタンスとウィンドウハンドルを結び付ける。 401 @param[in] hwnd 結び付けるウィンドウハンドル424 @param[in] hwndNew 結び付けるウィンドウハンドル 402 425 @date 2008/07/16 403 426 これを実行することで、UnassociateHWndされるまでControlがGC対象にならなくなると共に、 404 427 FromHWndでウィンドウハンドルからControlインスタンスの取得が可能となる。 405 428 */ 406 Sub AssociateHWnd(hwnd As HWND)407 This.hwnd = hwnd408 This.Prop[PropertyInstance] = ObjPtr(This) As HANDLE429 Sub AssociateHWnd(hwndNew As HWND) 430 hwnd = hwndNew 431 Prop[PropertyInstance] = ObjPtr(This) As HANDLE 409 432 comImpl.AddRef() 410 433 End Sub … … 429 452 Sub UnassociateHWndOnEvent(sender As Object, e As Args) 430 453 UnassociateHWnd() 454 hwnd = 0 431 455 End Sub 432 456 … … 447 471 448 472 Private 473 /*! 474 @brief ウィンドウの寿命管理 475 Controlには次のAddRef-Releaseの対がある。 476 @li createImpl - WM_NCDESTROY(ウィンドウプロシージャがWndProcFirstの場合) 477 @li createImpl - UnassociateHWnd←UnassociateHWndOnEvent←RegisterUnassociateHWnd(その他のウィンドウクラスの場合) 478 @li Attach - WM_NCDESTROY(サブクラス化された場合) 479 なお、Control派生クラスをサブクラス化すると、後ろ2つが両方適用される。 480 */ 449 481 comImpl As COM.ComClassDelegationImpl 482 450 483 '-------------------------------- 451 484 ' その他の補助関数 … … 526 559 End If 527 560 End Sub 528 529 561 End Class 530 562
Note:
See TracChangeset
for help on using the changeset viewer.