# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1337277031 0 # Node ID 43accf95bdc3c6c2e013e215c701ba4dddfad3c4 # Parent 1a7b9b96d9d787f2e67335bdc6904caa538e6176 Subclass the bitmap widget to center the bitmap on OS/2. This change is to keep behavior consitent between platforms. diff -r 1a7b9b96d9d7 -r 43accf95bdc3 os2/dw.c --- a/os2/dw.c Wed May 16 19:18:25 2012 +0000 +++ b/os2/dw.c Thu May 17 17:50:31 2012 +0000 @@ -1605,6 +1605,53 @@ return WinDefWindowProc(hwnd, msg, mp1, mp2); } +/* Subclass WC_STATIC to draw a bitmap centered */ +MRESULT EXPENTRY _BitmapProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) +{ + WindowData *blah = (WindowData *)WinQueryWindowPtr(hwnd, QWL_USER); + + if(msg == WM_PAINT) + { + HPS hps = WinBeginPaint(hwnd, 0, 0); + HBITMAP hbm = (HBITMAP)dw_window_get_data(hwnd, "_dw_bitmap"); + RECTL rcl; + + WinQueryWindowRect(hwnd, &rcl) ; + WinFillRect(hps, &rcl, CLR_PALEGRAY); + + /* If we have a bitmap... draw it */ + if(hbm) + { + BITMAPINFOHEADER sl; + + sl.cbFix = sizeof(BITMAPINFOHEADER); + + /* Check the bitmap size */ + if(GpiQueryBitmapParameters(hbm, &sl)) + { + /* Figure out the window size before clobbering the data */ + int width = rcl.xRight - rcl.xLeft, height = rcl.yTop - rcl.yBottom; + + /* If the control is bigger than the bitmap, center it */ + if(width > sl.cx) + rcl.xLeft = (width-sl.cx)/2; + if(height > sl.cy) + rcl.yBottom = (height-sl.cy)/2; + + } + /* Draw the bitmap unscaled at the desired location */ + WinDrawBitmap(hps, hbm, NULL, (PPOINTL) &rcl, + CLR_NEUTRAL, CLR_BACKGROUND, DBM_NORMAL); + } + + WinEndPaint(hps); + return 0; + } + if(blah && blah->oldproc) + return blah->oldproc(hwnd, msg, mp1, mp2); + return WinDefWindowProc(hwnd, msg, mp1, mp2); +} + /* Function to handle tooltip messages from a variety of procedures */ MRESULT EXPENTRY _TooltipProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, WindowData *blah) { @@ -3788,6 +3835,8 @@ BITMAPINFOHEADER sl; int newcx = cx, newcy = cy; + sl.cbFix = sizeof(BITMAPINFOHEADER); + /* Check the mini icon first */ if(GpiQueryBitmapParameters(pi.hbmMiniColor, &sl)) { @@ -5581,16 +5630,20 @@ */ HWND API dw_bitmap_new(ULONG id) { - return WinCreateWindow(HWND_OBJECT, - WC_STATIC, - NULL, - WS_VISIBLE | SS_TEXT, - 0,0,2000,1000, - NULLHANDLE, - HWND_TOP, - id, - NULL, - NULL); + WindowData *blah = calloc(1, sizeof(WindowData)); + HWND tmp = WinCreateWindow(HWND_OBJECT, + WC_STATIC, + NULL, + WS_VISIBLE | SS_TEXT, + 0,0,0,0, + NULLHANDLE, + HWND_TOP, + id, + NULL, + NULL); + blah->oldproc = WinSubclassWindow(tmp, _BitmapProc); + WinSetWindowPtr(tmp, QWP_USER, blah); + return tmp; } /* @@ -7024,8 +7077,6 @@ else return; - WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f); - WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL ); if ( id ) WinReleasePS(hps); dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); @@ -7106,8 +7157,6 @@ else return; - WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f); - WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL ); if ( id ) WinReleasePS(hps); dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); diff -r 1a7b9b96d9d7 -r 43accf95bdc3 readme.txt --- a/readme.txt Wed May 16 19:18:25 2012 +0000 +++ b/readme.txt Thu May 17 17:50:31 2012 +0000 @@ -10,8 +10,6 @@ GTK3 due to changes in the core architecture does not support widgets that are smaller than what is contained within them unless they use scrolled windows. GTK2 and other platforms do. -OS/2 Bitmap widget has the image anchored to the bottom left corner - of the widget instead of centered like other platforms. Known limitations: