Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
1735:1a7b9b96d9d7 | 1736:43accf95bdc3 |
---|---|
1601 return (MRESULT)TRUE; | 1601 return (MRESULT)TRUE; |
1602 } | 1602 } |
1603 if(proc) | 1603 if(proc) |
1604 return proc(hwnd, msg, mp1, mp2); | 1604 return proc(hwnd, msg, mp1, mp2); |
1605 return WinDefWindowProc(hwnd, msg, mp1, mp2); | 1605 return WinDefWindowProc(hwnd, msg, mp1, mp2); |
1606 } | |
1607 | |
1608 /* Subclass WC_STATIC to draw a bitmap centered */ | |
1609 MRESULT EXPENTRY _BitmapProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | |
1610 { | |
1611 WindowData *blah = (WindowData *)WinQueryWindowPtr(hwnd, QWL_USER); | |
1612 | |
1613 if(msg == WM_PAINT) | |
1614 { | |
1615 HPS hps = WinBeginPaint(hwnd, 0, 0); | |
1616 HBITMAP hbm = (HBITMAP)dw_window_get_data(hwnd, "_dw_bitmap"); | |
1617 RECTL rcl; | |
1618 | |
1619 WinQueryWindowRect(hwnd, &rcl) ; | |
1620 WinFillRect(hps, &rcl, CLR_PALEGRAY); | |
1621 | |
1622 /* If we have a bitmap... draw it */ | |
1623 if(hbm) | |
1624 { | |
1625 BITMAPINFOHEADER sl; | |
1626 | |
1627 sl.cbFix = sizeof(BITMAPINFOHEADER); | |
1628 | |
1629 /* Check the bitmap size */ | |
1630 if(GpiQueryBitmapParameters(hbm, &sl)) | |
1631 { | |
1632 /* Figure out the window size before clobbering the data */ | |
1633 int width = rcl.xRight - rcl.xLeft, height = rcl.yTop - rcl.yBottom; | |
1634 | |
1635 /* If the control is bigger than the bitmap, center it */ | |
1636 if(width > sl.cx) | |
1637 rcl.xLeft = (width-sl.cx)/2; | |
1638 if(height > sl.cy) | |
1639 rcl.yBottom = (height-sl.cy)/2; | |
1640 | |
1641 } | |
1642 /* Draw the bitmap unscaled at the desired location */ | |
1643 WinDrawBitmap(hps, hbm, NULL, (PPOINTL) &rcl, | |
1644 CLR_NEUTRAL, CLR_BACKGROUND, DBM_NORMAL); | |
1645 } | |
1646 | |
1647 WinEndPaint(hps); | |
1648 return 0; | |
1649 } | |
1650 if(blah && blah->oldproc) | |
1651 return blah->oldproc(hwnd, msg, mp1, mp2); | |
1652 return WinDefWindowProc(hwnd, msg, mp1, mp2); | |
1606 } | 1653 } |
1607 | 1654 |
1608 /* Function to handle tooltip messages from a variety of procedures */ | 1655 /* Function to handle tooltip messages from a variety of procedures */ |
1609 MRESULT EXPENTRY _TooltipProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, WindowData *blah) | 1656 MRESULT EXPENTRY _TooltipProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, WindowData *blah) |
1610 { | 1657 { |
3785 | 3832 |
3786 if(WinQueryPointerInfo(icon, &pi)) | 3833 if(WinQueryPointerInfo(icon, &pi)) |
3787 { | 3834 { |
3788 BITMAPINFOHEADER sl; | 3835 BITMAPINFOHEADER sl; |
3789 int newcx = cx, newcy = cy; | 3836 int newcx = cx, newcy = cy; |
3837 | |
3838 sl.cbFix = sizeof(BITMAPINFOHEADER); | |
3790 | 3839 |
3791 /* Check the mini icon first */ | 3840 /* Check the mini icon first */ |
3792 if(GpiQueryBitmapParameters(pi.hbmMiniColor, &sl)) | 3841 if(GpiQueryBitmapParameters(pi.hbmMiniColor, &sl)) |
3793 { | 3842 { |
3794 if(sl.cx && sl.cy && cx > sl.cx && cy > sl.cy) | 3843 if(sl.cx && sl.cy && cx > sl.cx && cy > sl.cy) |
5579 * Parameters: | 5628 * Parameters: |
5580 * id: An ID to be used with dw_window_from_id() or 0L. | 5629 * id: An ID to be used with dw_window_from_id() or 0L. |
5581 */ | 5630 */ |
5582 HWND API dw_bitmap_new(ULONG id) | 5631 HWND API dw_bitmap_new(ULONG id) |
5583 { | 5632 { |
5584 return WinCreateWindow(HWND_OBJECT, | 5633 WindowData *blah = calloc(1, sizeof(WindowData)); |
5585 WC_STATIC, | 5634 HWND tmp = WinCreateWindow(HWND_OBJECT, |
5586 NULL, | 5635 WC_STATIC, |
5587 WS_VISIBLE | SS_TEXT, | 5636 NULL, |
5588 0,0,2000,1000, | 5637 WS_VISIBLE | SS_TEXT, |
5589 NULLHANDLE, | 5638 0,0,0,0, |
5590 HWND_TOP, | 5639 NULLHANDLE, |
5591 id, | 5640 HWND_TOP, |
5592 NULL, | 5641 id, |
5593 NULL); | 5642 NULL, |
5643 NULL); | |
5644 blah->oldproc = WinSubclassWindow(tmp, _BitmapProc); | |
5645 WinSetWindowPtr(tmp, QWP_USER, blah); | |
5646 return tmp; | |
5594 } | 5647 } |
5595 | 5648 |
5596 /* | 5649 /* |
5597 * Create a notebook object to be packed. | 5650 * Create a notebook object to be packed. |
5598 * Parameters: | 5651 * Parameters: |
7022 dw_window_set_data(handle, "_dw_height", (void *)height); | 7075 dw_window_set_data(handle, "_dw_height", (void *)height); |
7023 } | 7076 } |
7024 else | 7077 else |
7025 return; | 7078 return; |
7026 | 7079 |
7027 WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f); | |
7028 WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL ); | |
7029 if ( id ) | 7080 if ( id ) |
7030 WinReleasePS(hps); | 7081 WinReleasePS(hps); |
7031 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7082 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7032 | 7083 |
7033 /* If we changed the bitmap... */ | 7084 /* If we changed the bitmap... */ |
7104 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); | 7155 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); |
7105 } | 7156 } |
7106 else | 7157 else |
7107 return; | 7158 return; |
7108 | 7159 |
7109 WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f); | |
7110 WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL ); | |
7111 if ( id ) | 7160 if ( id ) |
7112 WinReleasePS(hps); | 7161 WinReleasePS(hps); |
7113 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7162 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7114 } | 7163 } |
7115 | 7164 |