Mercurial > dwindows
diff os2/dw.c @ 1736:43accf95bdc3
Subclass the bitmap widget to center the bitmap on OS/2.
This change is to keep behavior consitent between platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 17 May 2012 17:50:31 +0000 |
parents | 4314ee3dbeb1 |
children | 46c2846e5750 |
line wrap: on
line diff
--- 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);