Changeset 2292 for trunk/src/user32/new/win32wbase.cpp
- Timestamp:
- Jan 2, 2000, 8:30:47 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/new/win32wbase.cpp
r2290 r2292 1 /* $Id: win32wbase.cpp,v 1.1 8 2000-01-01 14:57:28cbratschi Exp $ */1 /* $Id: win32wbase.cpp,v 1.19 2000-01-02 19:30:44 cbratschi Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 76 76 !(style & (WS_CHILD | WS_POPUP)) 77 77 78 #define HAS_MENU(w) (!((w)->getStyle() & WS_CHILD) && ((w)->getWindowId() != 0)) 79 78 80 /* bits in the dwKeyData */ 79 81 #define KEYDATA_ALT 0x2000 … … 85 87 //For quick lookup of current process id 86 88 static ULONG currentProcessId = -1; 89 90 static HBITMAP hbitmapClose = 0; 91 static HBITMAP hbitmapCloseD = 0; 92 static HBITMAP hbitmapMinimize = 0; 93 static HBITMAP hbitmapMinimizeD = 0; 94 static HBITMAP hbitmapMaximize = 0; 95 static HBITMAP hbitmapMaximizeD = 0; 96 static HBITMAP hbitmapRestore = 0; 97 static HBITMAP hbitmapRestoreD = 0; 98 99 BYTE lpGrayMask[] = { 0xAA, 0xA0, 100 0x55, 0x50, 101 0xAA, 0xA0, 102 0x55, 0x50, 103 0xAA, 0xA0, 104 0x55, 0x50, 105 0xAA, 0xA0, 106 0x55, 0x50, 107 0xAA, 0xA0, 108 0x55, 0x50}; 87 109 88 110 //****************************************************************************** … … 102 124 fIsSubclassedOS2Wnd = TRUE; 103 125 fFirstShow = FALSE; 126 fCreated = TRUE; 104 127 105 128 SetLastError(0); … … 456 479 457 480 hwndLinkAfter = HWND_TOP; 458 if( WIDGETS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))481 if(CONTROLS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX)) 459 482 { 460 483 hwndLinkAfter = HWND_BOTTOM; … … 462 485 } 463 486 else 464 if( WIDGETS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {487 if(CONTROLS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) { 465 488 dwStyle |= WS_CLIPSIBLINGS; 466 489 } … … 512 535 vertScrollInfo->flags = ESB_ENABLE_BOTH; 513 536 } 514 537 #if 0 //CB: PM frame not yet created! 515 538 /* Send the WM_GETMINMAXINFO message and fix the size if needed */ 516 539 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD))) … … 522 545 if (cs->cy < minTrack.y ) cs->cy = minTrack.y; 523 546 } 524 547 #endif 525 548 if(cs->style & WS_CHILD) 526 549 { … … 583 606 584 607 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP, 585 dwOSWinStyle, dwOSFrameStyle,(char *)windowNameA,608 dwOSWinStyle,(char *)windowNameA, 586 609 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP, 587 610 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE, … … 619 642 return FALSE; 620 643 } 621 #if 0622 if(OS2Hwnd != OS2HwndFrame) {623 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {624 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));625 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error626 return FALSE;627 }628 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {629 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));630 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error631 return FALSE;632 }633 }634 #endif635 644 636 645 OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame); 637 646 638 FrameGetScrollBarHandles(this,dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);639 subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);647 //FrameGetScrollBarHandles(this,dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL); 648 //subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL); 640 649 641 650 fakeWinBase.hwndThis = OS2Hwnd; … … 645 654 if(windowClass->getIcon()) 646 655 SetIcon(windowClass->getIcon()); 647 648 656 /* Get class or window DC if needed */ 649 657 if(windowClass->getStyle() & CS_OWNDC) { … … 682 690 // Subclass frame 683 691 pOldFrameProc = FrameSubclassFrameWindow(this); 684 if (isChild()) FrameSetBorderSize(this,TRUE); 685 692 //if (isChild()) FrameSetBorderSize(this,TRUE); 693 694 //preset rects 695 rectWindow.left = cs->x; 696 rectWindow.right = cs->x+cs->cx; 697 rectWindow.top = cs->y; 698 rectWindow.bottom = cs->y+cs->cy; 699 rectClient = rectWindow; 700 if (getParent()) MapWindowPoints(getParent()->getWindowHandle(),0,(PPOINT)&rectWindow,2); 686 701 /* Send the WM_CREATE message 687 702 * Perhaps we shouldn't allow width/height changes as well. … … 690 705 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top; 691 706 692 SetWindowPos(hwndLinkAfter,cs->x,cs->y,cs->cx,cs->cy,SWP_NOACTIVATE | SWP_NOREDRAW);707 //SetWindowPos(hwndLinkAfter,cs->x,cs->y,cs->cx,cs->cy,SWP_NOACTIVATE | SWP_NOREDRAW); 693 708 694 709 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE 695 710 fNoSizeMsg = FALSE; 711 fCreated = TRUE; 696 712 697 713 if(SendInternalMessageA(WM_NCCREATE, 0, (LPARAM)cs) ) 698 714 { 699 fCreated = TRUE; 700 715 RECT rect; 716 717 //update rect 718 rectWindow.left = cs->x; 719 rectWindow.right = cs->x+cs->cx; 720 rectWindow.top = cs->y; 721 rectWindow.bottom = cs->y+cs->cy; 722 rectClient = rectWindow; 723 if (getParent()) MapWindowPoints(getParent()->getWindowHandle(),0,(PPOINT)&rectWindow,2); 701 724 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient ); 702 // OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top); 725 OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top); 726 //set the window size and update the client 727 rect = rectWindow; 728 if (getParent()) MapWindowPoints(0,getParent()->getWindowHandle(),(PPOINT)&rect,2); 729 SetWindowPos(hwndLinkAfter,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED); 703 730 if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 ) 704 731 { … … 1076 1103 ULONG Win32BaseWindow::MsgNCPaint() 1077 1104 { 1078 return SendInternalMessageA(WM_PAINT, 0, 0); 1105 HRGN hrgn; 1106 1107 hrgn = 0; //CB: todo: set to frame update region 1108 return SendInternalMessageA(WM_NCPAINT,hrgn,0); 1079 1109 } 1080 1110 //****************************************************************************** … … 1227 1257 return rc; 1228 1258 } 1229 /*********************************************************************** 1230 * NC_HandleNCLButtonDown 1231 * 1232 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc(). 1233 */ 1259 //****************************************************************************** 1260 //****************************************************************************** 1261 LONG Win32BaseWindow::HandleNCActivate(WPARAM wParam) 1262 { 1263 WORD wStateChange; 1264 1265 if( wParam ) wStateChange = !(flags & WIN_NCACTIVATED); 1266 else wStateChange = flags & WIN_NCACTIVATED; 1267 1268 if( wStateChange ) 1269 { 1270 if (wParam) flags |= WIN_NCACTIVATED; 1271 else flags &= ~WIN_NCACTIVATED; 1272 1273 if(!(dwStyle & WS_MINIMIZE)) 1274 DoNCPaint((HRGN)1,FALSE); 1275 } 1276 1277 return TRUE; 1278 } 1279 //****************************************************************************** 1280 //****************************************************************************** 1281 VOID Win32BaseWindow::TrackMinMaxBox(WORD wParam) 1282 { 1283 MSG msg; 1284 HDC hdc; 1285 BOOL pressed = TRUE; 1286 UINT state; 1287 1288 if (wParam == HTMINBUTTON) 1289 { 1290 /* If the style is not present, do nothing */ 1291 if (!(dwStyle & WS_MINIMIZEBOX)) 1292 return; 1293 /* Check if the sysmenu item for minimize is there */ 1294 #if 0 //CB: todo 1295 state = GetMenuState(hSysMenu,SC_MINIMIZE,MF_BYCOMMAND); 1296 #endif 1297 } else 1298 { 1299 /* If the style is not present, do nothing */ 1300 if (!(dwStyle & WS_MAXIMIZEBOX)) 1301 return; 1302 /* Check if the sysmenu item for maximize is there */ 1303 #if 0 //CB: todo 1304 state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND); 1305 #endif 1306 } 1307 SetCapture(Win32Hwnd); 1308 hdc = GetWindowDC(Win32Hwnd); 1309 if (wParam == HTMINBUTTON) 1310 DrawMinButton(hdc,TRUE,FALSE); 1311 else 1312 DrawMaxButton(hdc,TRUE,FALSE); 1313 do 1314 { 1315 BOOL oldstate = pressed; 1316 1317 GetMessageA(&msg,Win32Hwnd,0,0); 1318 pressed = (HandleNCHitTest(msg.pt) == wParam); 1319 if (pressed != oldstate) 1320 { 1321 if (wParam == HTMINBUTTON) 1322 DrawMinButton(hdc,pressed,FALSE); 1323 else 1324 DrawMaxButton(hdc,pressed,FALSE); 1325 } 1326 } while (msg.message != WM_LBUTTONUP); 1327 if (wParam == HTMINBUTTON) 1328 DrawMinButton(hdc,FALSE,FALSE); 1329 else 1330 DrawMaxButton(hdc,FALSE,FALSE); 1331 ReleaseCapture(); 1332 ReleaseDC(Win32Hwnd,hdc); 1333 /* If the item minimize or maximize of the sysmenu are not there */ 1334 /* or if the style is not present, do nothing */ 1335 if ((!pressed) || (state == 0xFFFFFFFF)) 1336 return; 1337 if (wParam == HTMINBUTTON) 1338 SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,*(LPARAM*)&msg.pt); 1339 else 1340 SendInternalMessageA(WM_SYSCOMMAND,IsZoomed(Win32Hwnd) ? SC_RESTORE:SC_MAXIMIZE,*(LPARAM*)&msg.pt); 1341 } 1342 //****************************************************************************** 1343 //****************************************************************************** 1344 VOID Win32BaseWindow::TrackCloseButton(WORD wParam) 1345 { 1346 MSG msg; 1347 HDC hdc; 1348 BOOL pressed = TRUE; 1349 UINT state; 1350 1351 #if 0 //CB: todo 1352 if (hSysMenu == 0) 1353 return; 1354 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND); 1355 #endif 1356 /* If the item close of the sysmenu is disabled or not there do nothing */ 1357 if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF)) 1358 return; 1359 hdc = GetWindowDC(Win32Hwnd); 1360 SetCapture(Win32Hwnd); 1361 DrawCloseButton(hdc,TRUE,FALSE); 1362 do 1363 { 1364 BOOL oldstate = pressed; 1365 1366 GetMessageA(&msg,Win32Hwnd,0,0); 1367 pressed = (HandleNCHitTest(msg.pt) == wParam); 1368 if (pressed != oldstate) 1369 DrawCloseButton(hdc, pressed, FALSE); 1370 } while (msg.message != WM_LBUTTONUP); 1371 DrawCloseButton(hdc, FALSE, FALSE); 1372 ReleaseCapture(); 1373 ReleaseDC(Win32Hwnd, hdc ); 1374 if (!pressed) return; 1375 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,*(LPARAM*)&msg.pt); 1376 } 1377 //****************************************************************************** 1378 //****************************************************************************** 1234 1379 LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam) 1235 1380 { … … 1237 1382 { 1238 1383 case HTCAPTION: 1239 SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam); 1384 SetActiveWindow(); 1385 if (GetActiveWindow() == Win32Hwnd) 1386 SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam); 1240 1387 break; 1241 1388 1242 1389 case HTSYSMENU: 1243 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam); 1390 if(dwStyle & WS_SYSMENU ) 1391 { 1392 if( !(dwStyle & WS_MINIMIZE) ) 1393 { 1394 HDC hDC = GetWindowDC(Win32Hwnd); 1395 DrawSysButton(hDC,TRUE); 1396 ReleaseDC(Win32Hwnd,hDC); 1397 } 1398 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam); 1399 } 1244 1400 break; 1245 1401 … … 1254 1410 case HTVSCROLL: 1255 1411 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam); 1412 break; 1413 1414 case HTMINBUTTON: 1415 case HTMAXBUTTON: 1416 TrackMinMaxBox(wParam); 1417 break; 1418 1419 case HTCLOSE: 1420 TrackCloseButton(wParam); 1256 1421 break; 1257 1422 … … 1294 1459 return 0; 1295 1460 } 1461 //****************************************************************************** 1462 //****************************************************************************** 1463 BOOL Win32BaseWindow::WindowNeedsWMBorder() 1464 { 1465 if (!(dwStyle & WS_CHILD) && 1466 //Options.managed && //CB: to check 1467 !(dwExStyle & WS_EX_TOOLWINDOW) && 1468 ( ((dwStyle & WS_CAPTION) == WS_CAPTION) || 1469 (dwStyle & WS_THICKFRAME))) 1470 return TRUE; 1471 if (dwExStyle & WS_EX_TRAYWINDOW) 1472 return TRUE; 1473 return FALSE; 1474 } 1475 //****************************************************************************** 1476 //****************************************************************************** 1477 VOID Win32BaseWindow::AdjustRectOuter(LPRECT rect,BOOL menu) 1478 { 1479 if(dwStyle & WS_ICONIC) return; 1480 1481 /* Decide if the window will be managed (see CreateWindowEx) */ 1482 if (!WindowNeedsWMBorder()) 1483 { 1484 if (HAS_THICKFRAME(dwStyle,dwExStyle )) 1485 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) ); 1486 else 1487 if (HAS_DLGFRAME( dwStyle, dwExStyle )) 1488 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) ); 1489 else 1490 if (HAS_THINFRAME( dwStyle )) 1491 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER)); 1492 1493 if ((dwStyle & WS_CAPTION) == WS_CAPTION) 1494 { 1495 if (dwExStyle & WS_EX_TOOLWINDOW) 1496 rect->top -= GetSystemMetrics(SM_CYSMCAPTION); 1497 else 1498 rect->top -= GetSystemMetrics(SM_CYCAPTION); 1499 } 1500 } 1501 1502 if (menu) 1503 rect->top -= GetSystemMetrics(SM_CYMENU); 1504 } 1505 //****************************************************************************** 1506 //****************************************************************************** 1507 VOID Win32BaseWindow::AdjustRectInner(LPRECT rect) 1508 { 1509 if(dwStyle & WS_ICONIC) return; 1510 1511 if (dwExStyle & WS_EX_CLIENTEDGE) 1512 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)); 1513 1514 if (dwExStyle & WS_EX_STATICEDGE) 1515 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER)); 1516 1517 if (dwStyle & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL); 1518 if (dwStyle & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL); 1519 } 1520 //****************************************************************************** 1521 //****************************************************************************** 1522 LONG Win32BaseWindow::HandleNCCalcSize(RECT *winRect) 1523 { 1524 RECT tmpRect = { 0, 0, 0, 0 }; 1525 LONG result = 0; 1526 UINT style = (UINT) GetClassLongA(Win32Hwnd,GCL_STYLE); 1527 1528 if (style & CS_VREDRAW) result |= WVR_VREDRAW; 1529 if (style & CS_HREDRAW) result |= WVR_HREDRAW; 1530 1531 if( !( dwStyle & WS_MINIMIZE ) ) 1532 { 1533 AdjustRectOuter(&tmpRect,FALSE); 1534 1535 winRect->left -= tmpRect.left; 1536 winRect->top -= tmpRect.top; 1537 winRect->right -= tmpRect.right; 1538 winRect->bottom -= tmpRect.bottom; 1539 1540 if (HAS_MENU(this)) 1541 { 1542 #if 0 //CB: todo 1543 winRect->top += 1544 MENU_GetMenuBarHeight(Win32Hwnd, 1545 winRect->right - winRect->left, 1546 -tmpRect.left, -tmpRect.top ) + 1; 1547 #endif 1548 } 1549 1550 SetRect (&tmpRect, 0, 0, 0, 0); 1551 AdjustRectInner(&tmpRect); 1552 winRect->left -= tmpRect.left; 1553 winRect->top -= tmpRect.top; 1554 winRect->right -= tmpRect.right; 1555 winRect->bottom -= tmpRect.bottom; 1556 } 1557 1558 return result; 1559 } 1560 //****************************************************************************** 1561 //****************************************************************************** 1562 LONG Win32BaseWindow::HandleNCHitTest(POINT pt) 1563 { 1564 RECT rect = rectWindow; 1565 1566 if (!PtInRect(&rect,pt)) return HTNOWHERE; 1567 1568 if (dwStyle & WS_MINIMIZE) return HTCAPTION; 1569 1570 if (!(flags & WIN_MANAGED)) 1571 { 1572 /* Check borders */ 1573 if (HAS_THICKFRAME(dwStyle,dwExStyle)) 1574 { 1575 InflateRect( &rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) ); 1576 if (!PtInRect( &rect, pt )) 1577 { 1578 /* Check top sizing border */ 1579 if (pt.y < rect.top) 1580 { 1581 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT; 1582 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT; 1583 return HTTOP; 1584 } 1585 /* Check bottom sizing border */ 1586 if (pt.y >= rect.bottom) 1587 { 1588 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT; 1589 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT; 1590 return HTBOTTOM; 1591 } 1592 /* Check left sizing border */ 1593 if (pt.x < rect.left) 1594 { 1595 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT; 1596 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT; 1597 return HTLEFT; 1598 } 1599 /* Check right sizing border */ 1600 if (pt.x >= rect.right) 1601 { 1602 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT; 1603 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT; 1604 return HTRIGHT; 1605 } 1606 } 1607 } 1608 else /* No thick frame */ 1609 { 1610 if (HAS_DLGFRAME(dwStyle,dwExStyle)) 1611 InflateRect(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME)); 1612 else if (HAS_THINFRAME(dwStyle )) 1613 InflateRect(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER)); 1614 if (!PtInRect( &rect, pt )) return HTBORDER; 1615 } 1616 1617 /* Check caption */ 1618 1619 if ((dwStyle & WS_CAPTION) == WS_CAPTION) 1620 { 1621 if (dwExStyle & WS_EX_TOOLWINDOW) 1622 rect.top += GetSystemMetrics(SM_CYSMCAPTION) - 1; 1623 else 1624 rect.top += GetSystemMetrics(SM_CYCAPTION) - 1; 1625 if (!PtInRect( &rect, pt )) 1626 { 1627 /* Check system menu */ 1628 if(dwStyle & WS_SYSMENU) 1629 { 1630 /* Check if there is an user icon */ 1631 HICON hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM); 1632 if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON); 1633 1634 /* If there is an icon associated with the window OR */ 1635 /* If there is no hIcon specified and this is not a modal dialog, */ 1636 /* there is a system menu icon. */ 1637 if((hIcon != 0) || (!(dwStyle & DS_MODALFRAME))) 1638 rect.left += GetSystemMetrics(SM_CYCAPTION) - 1; 1639 } 1640 if (pt.x < rect.left) return HTSYSMENU; 1641 1642 /* Check close button */ 1643 if (dwStyle & WS_SYSMENU) 1644 rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1; 1645 if (pt.x > rect.right) return HTCLOSE; 1646 1647 /* Check maximize box */ 1648 /* In win95 there is automatically a Maximize button when there is a minimize one*/ 1649 if ((dwStyle & WS_MAXIMIZEBOX)|| (dwStyle & WS_MINIMIZEBOX)) 1650 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1; 1651 if (pt.x > rect.right) return HTMAXBUTTON; 1652 1653 /* Check minimize box */ 1654 /* In win95 there is automatically a Maximize button when there is a Maximize one*/ 1655 if ((dwStyle & WS_MINIMIZEBOX)||(dwStyle & WS_MAXIMIZEBOX)) 1656 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1; 1657 1658 if (pt.x > rect.right) return HTMINBUTTON; 1659 return HTCAPTION; 1660 } 1661 } 1662 } 1663 1664 /* Check client area */ 1665 1666 ScreenToClient(Win32Hwnd,&pt); 1667 rect = rectClient; 1668 if (PtInRect(&rect,pt)) return HTCLIENT; 1669 1670 /* Check vertical scroll bar */ 1671 1672 if (dwStyle & WS_VSCROLL) 1673 { 1674 rect.right += GetSystemMetrics(SM_CXVSCROLL); 1675 if (PtInRect( &rect, pt )) return HTVSCROLL; 1676 } 1677 1678 /* Check horizontal scroll bar */ 1679 1680 if (dwStyle & WS_HSCROLL) 1681 { 1682 rect.bottom += GetSystemMetrics(SM_CYHSCROLL); 1683 if (PtInRect( &rect, pt )) 1684 { 1685 /* Check size box */ 1686 if ((dwStyle & WS_VSCROLL) && 1687 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL))) 1688 return HTSIZE; 1689 return HTHSCROLL; 1690 } 1691 } 1692 1693 /* Check menu bar */ 1694 1695 if (HAS_MENU(this)) 1696 { 1697 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right)) 1698 return HTMENU; 1699 } 1700 1701 /* Should never get here */ 1702 return HTERROR; 1703 } 1704 1705 //****************************************************************************** 1706 //****************************************************************************** 1707 VOID Win32BaseWindow::GetInsideRect(RECT *rect) 1708 { 1709 rect->top = rect->left = 0; 1710 rect->right = rectWindow.right - rectWindow.left; 1711 rect->bottom = rectWindow.bottom - rectWindow.top; 1712 1713 if ((dwStyle & WS_ICONIC) || (flags & WIN_MANAGED)) return; 1714 1715 /* Remove frame from rectangle */ 1716 if (HAS_THICKFRAME(dwStyle,dwExStyle)) 1717 { 1718 InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) ); 1719 } 1720 else if (HAS_DLGFRAME(dwStyle,dwExStyle )) 1721 { 1722 InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME)); 1723 } 1724 else if (HAS_THINFRAME(dwStyle)) 1725 { 1726 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) ); 1727 } 1728 1729 /* We have additional border information if the window 1730 * is a child (but not an MDI child) */ 1731 if ( (dwStyle & WS_CHILD) && 1732 ( (dwExStyle & WS_EX_MDICHILD) == 0 ) ) 1733 { 1734 if (dwExStyle & WS_EX_CLIENTEDGE) 1735 InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE)); 1736 1737 if (dwExStyle & WS_EX_STATICEDGE) 1738 InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER)); 1739 } 1740 } 1741 //****************************************************************************** 1742 //****************************************************************************** 1743 VOID Win32BaseWindow::DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active) 1744 { 1745 INT width, height; 1746 1747 if (dlgFrame) 1748 { 1749 width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE); 1750 height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE); 1751 } else 1752 { 1753 width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE); 1754 height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE); 1755 } 1756 1757 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER : 1758 COLOR_INACTIVEBORDER) ); 1759 1760 /* Draw frame */ 1761 PatBlt( hdc, rect->left, rect->top, 1762 rect->right - rect->left, height, PATCOPY ); 1763 PatBlt( hdc, rect->left, rect->top, 1764 width, rect->bottom - rect->top, PATCOPY ); 1765 PatBlt( hdc, rect->left, rect->bottom - 1, 1766 rect->right - rect->left, -height, PATCOPY ); 1767 PatBlt( hdc, rect->right - 1, rect->top, 1768 -width, rect->bottom - rect->top, PATCOPY ); 1769 1770 InflateRect( rect, -width, -height ); 1771 } 1772 //****************************************************************************** 1773 //****************************************************************************** 1774 BOOL Win32BaseWindow::DrawSysButton(HDC hdc,BOOL down) 1775 { 1776 if(!(flags & WIN_MANAGED)) 1777 { 1778 HICON hIcon; 1779 RECT rect; 1780 1781 GetInsideRect(&rect); 1782 1783 hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM); 1784 if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON); 1785 1786 /* If there is no hIcon specified or this is not a modal dialog, */ 1787 /* get the default one. */ 1788 if(hIcon == 0) 1789 if (!(dwStyle & DS_MODALFRAME)) 1790 hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_WINEICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); 1791 1792 if (hIcon) 1793 DrawIconEx (hdc, rect.left + 2, rect.top + 2, hIcon, 1794 GetSystemMetrics(SM_CXSMICON), 1795 GetSystemMetrics(SM_CYSMICON), 1796 0, 0, DI_NORMAL); 1797 1798 return (hIcon != 0); 1799 } 1800 return FALSE; 1801 } 1802 //****************************************************************************** 1803 //****************************************************************************** 1804 BOOL Win32BaseWindow::DrawGrayButton(HDC hdc,int x,int y) 1805 { 1806 HBITMAP hMaskBmp; 1807 HDC hdcMask = CreateCompatibleDC (0); 1808 HBRUSH hOldBrush; 1809 hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask); 1810 1811 if(hMaskBmp == 0) 1812 return FALSE; 1813 1814 SelectObject (hdcMask, hMaskBmp); 1815 1816 /* Draw the grayed bitmap using the mask */ 1817 hOldBrush = SelectObject (hdc, RGB(128, 128, 128)); 1818 BitBlt (hdc, x, y, 12, 10, 1819 hdcMask, 0, 0, 0xB8074A); 1820 1821 /* Clean up */ 1822 SelectObject (hdc, hOldBrush); 1823 DeleteObject(hMaskBmp); 1824 DeleteDC (hdcMask); 1825 1826 return TRUE; 1827 } 1828 //****************************************************************************** 1829 //****************************************************************************** 1830 VOID Win32BaseWindow::DrawCloseButton(HDC hdc,BOOL down,BOOL bGrayed) 1831 { 1832 RECT rect; 1833 HDC hdcMem; 1834 1835 if( !(flags & WIN_MANAGED) ) 1836 { 1837 BITMAP bmp; 1838 HBITMAP hBmp, hOldBmp; 1839 1840 GetInsideRect(&rect); 1841 1842 hdcMem = CreateCompatibleDC( hdc ); 1843 hBmp = down ? hbitmapCloseD : hbitmapClose; 1844 hOldBmp = SelectObject (hdcMem, hBmp); 1845 GetObjectA (hBmp, sizeof(BITMAP), &bmp); 1846 1847 BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2, 1848 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2, 1849 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY); 1850 1851 if(bGrayed) 1852 DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2, 1853 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2); 1854 1855 SelectObject (hdcMem, hOldBmp); 1856 DeleteDC (hdcMem); 1857 } 1858 } 1859 //****************************************************************************** 1860 //****************************************************************************** 1861 VOID Win32BaseWindow::DrawMaxButton(HDC hdc,BOOL down,BOOL bGrayed) 1862 { 1863 RECT rect; 1864 HDC hdcMem; 1865 1866 if( !(flags & WIN_MANAGED)) 1867 { 1868 BITMAP bmp; 1869 HBITMAP hBmp,hOldBmp; 1870 1871 GetInsideRect(&rect); 1872 hdcMem = CreateCompatibleDC( hdc ); 1873 hBmp = IsZoomed(Win32Hwnd) ? 1874 (down ? hbitmapRestoreD : hbitmapRestore ) : 1875 (down ? hbitmapMaximizeD: hbitmapMaximize); 1876 hOldBmp=SelectObject( hdcMem, hBmp ); 1877 GetObjectA (hBmp, sizeof(BITMAP), &bmp); 1878 1879 if (dwStyle & WS_SYSMENU) 1880 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1; 1881 1882 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2, 1883 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2, 1884 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY ); 1885 1886 if(bGrayed) 1887 DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2, 1888 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2); 1889 1890 1891 SelectObject (hdcMem, hOldBmp); 1892 DeleteDC( hdcMem ); 1893 } 1894 } 1895 //****************************************************************************** 1896 //****************************************************************************** 1897 VOID Win32BaseWindow::DrawMinButton(HDC hdc,BOOL down,BOOL bGrayed) 1898 { 1899 RECT rect; 1900 HDC hdcMem; 1901 1902 if( !(flags & WIN_MANAGED)) 1903 1904 { 1905 BITMAP bmp; 1906 HBITMAP hBmp,hOldBmp; 1907 1908 GetInsideRect(&rect); 1909 1910 hdcMem = CreateCompatibleDC( hdc ); 1911 hBmp = down ? hbitmapMinimizeD : hbitmapMinimize; 1912 hOldBmp= SelectObject( hdcMem, hBmp ); 1913 GetObjectA (hBmp, sizeof(BITMAP), &bmp); 1914 1915 if (dwStyle & WS_SYSMENU) 1916 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1; 1917 1918 /* In win 95 there is always a Maximize box when there is a Minimize one */ 1919 if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX)) 1920 rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2; 1921 1922 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2, 1923 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2, 1924 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY ); 1925 1926 if(bGrayed) 1927 DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2, 1928 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2); 1929 1930 1931 SelectObject (hdcMem, hOldBmp); 1932 DeleteDC( hdcMem ); 1933 } 1934 } 1935 //****************************************************************************** 1936 //****************************************************************************** 1937 VOID Win32BaseWindow::DrawCaption(HDC hdc,RECT *rect,BOOL active) 1938 { 1939 RECT r = *rect; 1940 char buffer[256]; 1941 HPEN hPrevPen; 1942 HMENU hSysMenu; 1943 1944 if (flags & WIN_MANAGED) return; 1945 1946 hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) ); 1947 MoveToEx( hdc, r.left, r.bottom - 1, NULL ); 1948 LineTo( hdc, r.right, r.bottom - 1 ); 1949 SelectObject( hdc, hPrevPen ); 1950 r.bottom--; 1951 1952 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) ); 1953 1954 if (!hbitmapClose) 1955 { 1956 if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return; 1957 hbitmapCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED)); 1958 hbitmapMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE)); 1959 hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED)); 1960 hbitmapMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM)); 1961 hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD)); 1962 hbitmapRestore = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE)); 1963 hbitmapRestoreD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED)); 1964 } 1965 1966 if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW)) 1967 { 1968 if (DrawSysButton(hdc,FALSE)) 1969 r.left += GetSystemMetrics(SM_CYCAPTION) - 1; 1970 } 1971 1972 if (dwStyle & WS_SYSMENU) 1973 { 1974 UINT state; 1975 #if 0 //CB: todo 1976 /* Go get the sysmenu */ 1977 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND); 1978 #endif 1979 /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */ 1980 DrawCloseButton(hdc, FALSE, 1981 ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF))); 1982 r.right -= GetSystemMetrics(SM_CYCAPTION) - 1; 1983 1984 if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX)) 1985 { 1986 /* In win95 the two buttons are always there */ 1987 /* But if the menu item is not in the menu they're disabled*/ 1988 1989 DrawMaxButton(hdc, FALSE, (!(dwStyle & WS_MAXIMIZEBOX))); 1990 r.right -= GetSystemMetrics(SM_CXSIZE) + 1; 1991 1992 DrawMinButton(hdc, FALSE, (!(dwStyle & WS_MINIMIZEBOX))); 1993 r.right -= GetSystemMetrics(SM_CXSIZE) + 1; 1994 } 1995 } 1996 1997 if (GetWindowTextA(buffer, sizeof(buffer) )) 1998 { 1999 NONCLIENTMETRICSA nclm; 2000 HFONT hFont, hOldFont; 2001 nclm.cbSize = sizeof(NONCLIENTMETRICSA); 2002 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0); 2003 if (dwExStyle & WS_EX_TOOLWINDOW) 2004 hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont); 2005 else 2006 hFont = CreateFontIndirectA (&nclm.lfCaptionFont); 2007 hOldFont = SelectObject (hdc, hFont); 2008 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) ); 2009 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ); 2010 SetBkMode( hdc, TRANSPARENT ); 2011 r.left += 2; 2012 DrawTextA( hdc, buffer, -1, &r, 2013 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT ); 2014 DeleteObject (SelectObject (hdc, hOldFont)); 2015 } 2016 } 2017 //****************************************************************************** 2018 //****************************************************************************** 2019 VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint) 2020 { 2021 BOOL active = flags & WIN_NCACTIVATED; 2022 HDC hdc; 2023 RECT rect,rectClip,rfuzz; 2024 2025 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in 2026 the call to GetDCEx implying that it is allowed not to use it either. 2027 However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN) 2028 will cause clipRgn to be deleted after ReleaseDC(). 2029 Now, how is the "system" supposed to tell what happened? 2030 */ 2031 2032 if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW | 2033 ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return; 2034 2035 2036 rect.top = rect.left = 0; 2037 rect.right = rectWindow.right - rectWindow.left; 2038 rect.bottom = rectWindow.bottom - rectWindow.top; 2039 2040 if( clip > 1 ) 2041 GetRgnBox( clip, &rectClip ); 2042 else 2043 { 2044 clip = 0; 2045 rectClip = rect; 2046 } 2047 2048 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) ); 2049 2050 if(!(flags & WIN_MANAGED)) 2051 { 2052 if (HAS_BIGFRAME( dwStyle, dwExStyle)) 2053 { 2054 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST); 2055 } 2056 if (HAS_THICKFRAME( dwStyle, dwExStyle )) 2057 DrawFrame(hdc, &rect, FALSE, active ); 2058 else if (HAS_DLGFRAME( dwStyle, dwExStyle )) 2059 DrawFrame( hdc, &rect, TRUE, active ); 2060 else if (HAS_THINFRAME( dwStyle )) 2061 { 2062 SelectObject( hdc, GetStockObject(NULL_BRUSH) ); 2063 Rectangle( hdc, 0, 0, rect.right, rect.bottom ); 2064 } 2065 2066 if ((dwStyle & WS_CAPTION) == WS_CAPTION) 2067 { 2068 RECT r = rect; 2069 if (dwExStyle & WS_EX_TOOLWINDOW) 2070 { 2071 r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION); 2072 rect.top += GetSystemMetrics(SM_CYSMCAPTION); 2073 } 2074 else 2075 { 2076 r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION); 2077 rect.top += GetSystemMetrics(SM_CYCAPTION); 2078 } 2079 if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) ) 2080 DrawCaption(hdc, &r, active); 2081 } 2082 } 2083 #if 0 //CB: todo 2084 if (HAS_MENU(wndPtr)) 2085 { 2086 RECT r = rect; 2087 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU); 2088 2089 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1; 2090 } 2091 #endif 2092 2093 if (dwExStyle & WS_EX_CLIENTEDGE) 2094 DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); 2095 2096 if (dwExStyle & WS_EX_STATICEDGE) 2097 DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST); 2098 2099 /* Draw the scroll-bars */ 2100 #if 0 //CB: todo 2101 if (dwStyle & WS_VSCROLL) 2102 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE ); 2103 if (wndPtr->dwStyle & WS_HSCROLL) 2104 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE ); 2105 #endif 2106 /* Draw the "size-box" */ 2107 if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL)) 2108 { 2109 RECT r = rect; 2110 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1; 2111 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1; 2112 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) ); 2113 } 2114 2115 ReleaseDC(Win32Hwnd,hdc); 2116 } 2117 //****************************************************************************** 2118 //****************************************************************************** 2119 LONG Win32BaseWindow::HandleNCPaint(HRGN clip) 2120 { 2121 if (!(dwStyle & WS_VISIBLE)) return 0; 2122 2123 if (dwStyle & WS_MINIMIZE) return 0; //CB: to check 2124 2125 DoNCPaint(clip,FALSE); 2126 2127 return 0; 2128 } 1296 2129 /*********************************************************************** 1297 2130 * NC_HandleNCLButtonDblClk … … 1605 2438 1606 2439 case WM_NCPAINT: 1607 return 0;2440 return HandleNCPaint((HRGN)wParam); 1608 2441 1609 2442 case WM_NCACTIVATE: 2443 return HandleNCActivate(wParam); 1610 2444 return TRUE; 1611 2445 … … 1617 2451 1618 2452 case WM_NCCALCSIZE: 1619 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS*)lParam);2453 return HandleNCCalcSize((RECT*)lParam); 1620 2454 1621 2455 case WM_CTLCOLORMSGBOX: … … 1669 2503 HCURSOR hCursor; 1670 2504 1671 switch( lastHitTestVal)2505 switch(LOWORD(lParam)) 1672 2506 { 1673 2507 case HTLEFT: … … 1806 2640 point.y = (SHORT)HIWORD(lParam); 1807 2641 1808 return FrameHitTest(this,point.x,point.y);2642 return HandleNCHitTest(point); 1809 2643 } 1810 2644
Note:
See TracChangeset
for help on using the changeset viewer.