LRESULT CALLBACK cg_container_win32_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { widget_t *w; container_widget_t *sw; native_container_widget_t *nw; //bounds_t b; w = cg_find_by_native( hWnd ); if ( w == 0 ) return DefWindowProc( hWnd, uMsg, wParam, lParam ); sw = (container_widget_t *)w; nw = (native_container_widget_t *)w->ndata; switch ( uMsg ) { case WM_MOVE: widget_set_position( w, LOWORD(lParam), HIWORD(lParam), 1 ); break; case WM_SIZE: widget_set_size( w, LOWORD(lParam), HIWORD(lParam), 1 ); widget_set_content_size( w, LOWORD(lParam), HIWORD(lParam), 1 ); widget_resized_handle( OBJECT(w), 0 ); break; case WM_COMMAND: case WM_NOTIFY: return cg_win32_proc( hWnd, uMsg, wParam, lParam ); } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
LRESULT CALLBACK cg_win32_image_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { image_widget_t *iw; image_t *im; widget_t *w; PAINTSTRUCT ps; HDC hdc, oldbmp; w = cg_find_by_native( hWnd ); if ( w == 0 ) return DefWindowProc( hWnd, uMsg, wParam, lParam ); iw = (image_widget_t *)w; im = iw->src; switch ( uMsg ) { case WM_QUIT: return 1; case WM_CLOSE: DestroyWindow( hWnd ); return 0; case WM_MOVE: widget_set_position( OBJECT(w), LOWORD(lParam), HIWORD(lParam), 1 ); break; case WM_SIZE: widget_set_size( OBJECT(w), LOWORD(lParam), HIWORD(lParam), 1 ); break; case WM_PAINT: if ( im == NULL ) break; hdc = BeginPaint( hWnd, &ps ); /*RECT rect; rect.left = rect.top = 0; rect.right = rect.bottom = 100; FillRect( hdc, &rect, RGB(255,0,0));*/ #ifdef IMAGES_USE_LIBPNG_FIXME if ( im->native3 == 0 ) { /* Use alphablend, it's a PNG */ oldbmp = SelectObject( im->native, im->native2 ); BLENDFUNCTION pixelblend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; AlphaBlend( hdc, 0, 0, im->width, im->height, im->native, 0, 0, im->width, im->height, pixelblend ); SelectObject( im->native, oldbmp ); } else #endif { oldbmp = SelectObject( im->native, im->native2 ); BitBlt( hdc, 0, 0, im->width, im->height, im->native, 0, 0, SRCCOPY ); SelectObject( im->native, oldbmp ); } EndPaint( hWnd, &ps ); return 0; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
LRESULT CALLBACK cg_canvas_win32_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { widget_t *w; canvas_widget_t *cvsw; native_canvas_widget_t *nw; RECT r; PAINTSTRUCT ps; HDC hdc, mdc, odc; HBITMAP bmp, obmp; w = cg_find_by_native( hWnd ); if ( w == 0 ) return DefWindowProc( hWnd, uMsg, wParam, lParam ); cvsw = (canvas_widget_t *)w; nw = (native_canvas_widget_t *)w->ndata; switch ( uMsg ) { case WM_ERASEBKGND: return 1; case WM_PAINT: case WM_PRINTCLIENT: if ( uMsg == WM_PAINT ) { if ( !cg_isxplater ) { odc = BeginPaint( hWnd, &ps ); mdc = CreateCompatibleDC( odc ); GetClientRect( hWnd, &r ); if ( nw->bmp == 0 ) nw->bmp = CreateCompatibleBitmap( odc, r.right, r.bottom ); obmp = SelectObject( mdc, nw->bmp ); hdc = mdc; } else { hdc = BeginPaint( hWnd, &ps ); } } else hdc = wParam; GetClientRect( hWnd, &r ); FillRect( hdc, &r, (HBRUSH) (COLOR_WINDOW) ); cvsw->surfdata = hdc; if ( w->font.native != 0 ) SelectObject( hdc, w->font.native ); #ifndef NO_CAIRO cairo_surface_destroy( cvsw->surface ); cvsw->surface = 0; if ( cvsw->surface == 0 ) { cvsw->surface = cairo_win32_surface_create( hdc ); } cvsw->cr = cairo_create( cvsw->surface ); #endif /* cairo_rectangle( cvsw->cr, r.left, r.top, r.right - r.left, r.bottom - r.top ); cairo_clip( cvsw->cr ); */ #ifdef NO_CAIRO event_send( OBJECT(w), "redraw", "" ); #else event_send( OBJECT(w), "redraw", "p", "cairo_context", cvsw->cr ); #endif #ifndef NO_CAIRO cairo_destroy( cvsw->cr ); #endif if ( uMsg == WM_PAINT && !cg_isxplater ) { BitBlt( odc, 0, 0, r.right, r.bottom, hdc, 0, 0, SRCCOPY ); SelectObject( mdc, obmp ); EndPaint( hWnd, &ps ); } else if ( uMsg == WM_PAINT ) { EndPaint( hWnd, &ps ); } //cairo_surface_flush( cvsw->surface ); break; case WM_SIZE: if ( !cg_isxplater ) { if ( nw->bmp != 0 ) DeleteObject( nw->bmp ); hdc = GetDC( hWnd ); GetClientRect( hWnd, &r ); nw->bmp = CreateCompatibleBitmap( hdc, r.right, r.bottom ); ReleaseDC( hWnd, hdc ); } InvalidateRgn( hWnd, 0, 0 ); break; case WM_LBUTTONDOWN: event_send( OBJECT(w), "clicked", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_LBUTTONUP: event_send( OBJECT(w), "released", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_RBUTTONDOWN: event_send( OBJECT(w), "right_clicked", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_RBUTTONUP: event_send( OBJECT(w), "right_released", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); break; case WM_MOUSEMOVE: if ( wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON) || w->notify_flags & cNotifyMouse ) { event_send( OBJECT(w), "mouse_moved", "ii", "x", LOWORD(lParam), "y", HIWORD(lParam) ); // will this work fine here? hmm. TRACKMOUSEEVENT tme; tme.cbSize = sizeof( TRACKMOUSEEVENT ); tme.dwFlags = TME_LEAVE; tme.hwndTrack = hWnd; tme.dwHoverTime = 0; TrackMouseEvent( &tme ); } break; case WM_MOUSELEAVE: event_send( OBJECT(w), "mouse_leave", "" ); break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }