VOID PaintText(LPDRAWITEMSTRUCT drawItem, PCONSOLE_PROPS pConInfo) { COLORREF pbkColor, ptColor; COLORREF nbkColor, ntColor; HBRUSH hBrush = NULL; if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR) { nbkColor = pConInfo->ci.Colors[BkgdAttribFromAttrib(pConInfo->ci.ScreenAttrib)]; hBrush = CreateSolidBrush(nbkColor); ntColor = pConInfo->ci.Colors[TextAttribFromAttrib(pConInfo->ci.ScreenAttrib)]; } else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR) { nbkColor = pConInfo->ci.Colors[BkgdAttribFromAttrib(pConInfo->ci.PopupAttrib)]; hBrush = CreateSolidBrush(nbkColor); ntColor = pConInfo->ci.Colors[TextAttribFromAttrib(pConInfo->ci.PopupAttrib)]; } if (!hBrush) { return; } FillRect(drawItem->hDC, &drawItem->rcItem, hBrush); ptColor = SetTextColor(drawItem->hDC, ntColor); pbkColor = SetBkColor(drawItem->hDC, nbkColor); DrawText(drawItem->hDC, szPreviewText, _tcslen(szPreviewText), &drawItem->rcItem, 0); SetTextColor(drawItem->hDC, ptColor); SetBkColor(drawItem->hDC, pbkColor); DeleteObject((HGDIOBJ)hBrush); }
VOID PaintText( IN LPDRAWITEMSTRUCT drawItem, IN PCONSOLE_STATE_INFO pConInfo, IN TEXT_TYPE TextMode) { USHORT CurrentAttrib; COLORREF pbkColor, ptColor; COLORREF nbkColor, ntColor; HBRUSH hBrush; HFONT hOldFont; if (TextMode == Screen) CurrentAttrib = pConInfo->ScreenAttributes; else if (TextMode == Popup) CurrentAttrib = pConInfo->PopupAttributes; else return; nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)]; ntColor = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)]; hBrush = CreateSolidBrush(nbkColor); if (!hBrush) return; hOldFont = SelectObject(drawItem->hDC, hCurrentFont); //if (hOldFont == NULL) //{ // DeleteObject(hBrush); // return; //} FillRect(drawItem->hDC, &drawItem->rcItem, hBrush); /* Add a few space between the preview window border and the text sample */ InflateRect(&drawItem->rcItem, -2, -2); ptColor = SetTextColor(drawItem->hDC, ntColor); pbkColor = SetBkColor(drawItem->hDC, nbkColor); DrawTextW(drawItem->hDC, szPreviewText, (INT)wcslen(szPreviewText), &drawItem->rcItem, 0); SetTextColor(drawItem->hDC, ptColor); SetBkColor(drawItem->hDC, pbkColor); SelectObject(drawItem->hDC, hOldFont); DeleteObject(hBrush); }
static VOID WinPrev_OnDraw( IN HDC hDC, IN PWINPREV_DATA pData) { PCONSOLE_STATE_INFO pConInfo = (PCONSOLE_STATE_INFO)pData->pData; HBRUSH hBrush; RECT rcWin, fRect; SIZE /*siBorder,*/ siFrame, siButton, siScroll; SIZE resize; RECT rcItem; GetClientRect(pData->hWnd, &rcItem); /* * Retrieve some system metrics and rescale them. * They will be added separately, so that to always round the sizes up. */ /* Don't care about border as it is almost always 1 and <= frame size */ /* Example: Frame = 4, or 13 ... while Border = 1 */ // siBorder.cx = GetSystemMetrics(SM_CXBORDER); // siBorder.cy = GetSystemMetrics(SM_CYBORDER); /* Window frame size */ siFrame.cx = GetSystemMetrics(SM_CXFRAME); if (siFrame.cx > 0) { siFrame.cx = RescaleCX(pData, siFrame.cx); siFrame.cx = max(1, siFrame.cx); } siFrame.cy = GetSystemMetrics(SM_CYFRAME); if (siFrame.cy > 0) { siFrame.cy = RescaleCY(pData, siFrame.cy); siFrame.cy = max(1, siFrame.cy); } /* Window caption buttons */ siButton.cx = GetSystemMetrics(SM_CXSIZE); siButton.cx = RescaleCX(pData, siButton.cx); siButton.cx = max(1, siButton.cx); siButton.cy = GetSystemMetrics(SM_CYSIZE); siButton.cy = RescaleCY(pData, siButton.cy); siButton.cy = max(1, siButton.cy); /* Enlarge them for improving their appearance */ // siButton.cx *= 2; siButton.cy *= 2; /* Dimensions of the scrollbars */ siScroll.cx = GetSystemMetrics(SM_CXVSCROLL); siScroll.cx = RescaleCX(pData, siScroll.cx); siScroll.cx = max(1, siScroll.cx); siScroll.cy = GetSystemMetrics(SM_CYHSCROLL); siScroll.cy = RescaleCY(pData, siScroll.cy); siScroll.cy = max(1, siScroll.cy); // FIXME: Use SM_CXMIN, SM_CYMIN ?? /* * Compute the console window layout */ /* We start with the console client area, rescaled for the preview */ SetRect(&rcWin, 0, 0, pConInfo->WindowSize.X * pConInfo->FontSize.X, pConInfo->WindowSize.Y * pConInfo->FontSize.Y); RescaleRect(pData, rcWin); /* Add the scrollbars if needed (does not account for any frame) */ if (pConInfo->WindowSize.X < pConInfo->ScreenBufferSize.X) { /* Horizontal scrollbar */ rcWin.bottom += siScroll.cy; // NOTE: If an additional exterior frame is needed, add +1 } else { /* No scrollbar */ siScroll.cy = 0; } if (pConInfo->WindowSize.Y < pConInfo->ScreenBufferSize.Y) { /* Vertical scrollbar */ rcWin.right += siScroll.cx; // NOTE: If an additional exterior frame is needed, add +1 } else { /* No scrollbar */ siScroll.cx = 0; } /* Add the title bar, taking into account the frames */ rcWin.top -= siButton.cy - 1; /* If we have a non-zero window frame size, add an interior border and the frame */ resize.cx = (siFrame.cx > 0 ? 1 + siFrame.cx : 0); resize.cy = (siFrame.cy > 0 ? 1 + siFrame.cy : 0); /* Add the outer border */ ++resize.cx, ++resize.cy; InflateRect(&rcWin, resize.cx, resize.cy); /* Finally, move the window rectangle back to its correct origin */ OffsetRect(&rcWin, -rcWin.left, -rcWin.top); if ( pConInfo->WindowPosition.x == MAXDWORD && pConInfo->WindowPosition.y == MAXDWORD ) { // OffsetRect(&rcWin, (rcItem.right - rcItem.left) / 3, (rcItem.bottom - rcItem.top) / 3); OffsetRect(&rcWin, 0, 0); } else { OffsetRect(&rcWin, RescaleCX(pData, pConInfo->WindowPosition.x), RescaleCY(pData, pConInfo->WindowPosition.y)); } /* * Paint the preview window */ /* Fill the background with desktop colour */ FillRect(hDC, &rcItem, GetSysColorBrush(COLOR_BACKGROUND)); /* * Draw the exterior frame. Use 'FillRect' instead of 'FrameRect' * so that, when we want to draw frames around other elements, * we can just instead separate them with space instead of redrawing * a frame with 'FrameRect'. */ FillRect(hDC, &rcWin, GetSysColorBrush(COLOR_WINDOWFRAME)); InflateRect(&rcWin, -1, -1); /* Draw the border */ hBrush = GetSysColorBrush(COLOR_ACTIVEBORDER); if (siFrame.cx > 0) { SetRect(&fRect, rcWin.left, rcWin.top, rcWin.left + siFrame.cx, rcWin.bottom); FillRect(hDC, &fRect, hBrush); SetRect(&fRect, rcWin.right - siFrame.cx, rcWin.top, rcWin.right, rcWin.bottom); FillRect(hDC, &fRect, hBrush); InflateRect(&rcWin, -siFrame.cx, 0); } if (siFrame.cy > 0) { SetRect(&fRect, rcWin.left, rcWin.top, rcWin.right, rcWin.top + siFrame.cy); FillRect(hDC, &fRect, hBrush); SetRect(&fRect, rcWin.left, rcWin.bottom - siFrame.cy, rcWin.right, rcWin.bottom); FillRect(hDC, &fRect, hBrush); InflateRect(&rcWin, 0, -siFrame.cy); } /* Draw the interior frame if we had a border */ if (siFrame.cx > 0 || siFrame.cy > 0) { #if 0 // See the remark above SetRect(&fRect, rcWin.left, rcWin.top, rcWin.right, rcWin.bottom); FrameRect(hDC, &fRect, GetSysColorBrush(COLOR_WINDOWFRAME)); #endif InflateRect(&rcWin, (siFrame.cx > 0 ? -1 : 0), (siFrame.cy > 0 ? -1 : 0)); } /* Draw the console window title bar */ hBrush = GetSysColorBrush(COLOR_BTNFACE); /* Draw the system menu (left button) */ SetRect(&fRect, rcWin.left, rcWin.top, rcWin.left + siButton.cx, rcWin.top + siButton.cy - 2); // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONCLOSE); FillRect(hDC, &fRect, hBrush); fRect.right++; // Separation /* Draw the caption bar */ SetRect(&fRect, fRect.right, fRect.top, rcWin.right - 2 * (siButton.cx + 1), fRect.bottom); FillRect(hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION)); fRect.right++; // Separation /* Draw the minimize menu (first right button) */ SetRect(&fRect, fRect.right, fRect.top, fRect.right + siButton.cx, fRect.bottom); // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONMIN); FillRect(hDC, &fRect, hBrush); fRect.right++; // Separation /* Draw the maximize menu (second right button) */ SetRect(&fRect, fRect.right, fRect.top, fRect.right + siButton.cx, fRect.bottom); // DrawFrameControl(hDC, &fRect, DFC_CAPTION, DFCS_CAPTIONMAX); FillRect(hDC, &fRect, hBrush); rcWin.top += siButton.cy - 1; /* Add the scrollbars if needed */ if (siScroll.cy > 0 || siScroll.cx > 0) { LONG right, bottom; right = rcWin.right; bottom = rcWin.bottom; /* * If both the horizontal and vertical scrollbars are present, * reserve some space for the "dead square" at the bottom right. */ if (siScroll.cy > 0 && siScroll.cx > 0) { right -= (1 + siScroll.cx); bottom -= (1 + siScroll.cy); } hBrush = GetSysColorBrush(COLOR_SCROLLBAR); /* Horizontal scrollbar */ if (siScroll.cy > 0) { SetRect(&fRect, rcWin.left, rcWin.bottom - siScroll.cy, right, rcWin.bottom); FillRect(hDC, &fRect, hBrush); } /* Vertical scrollbar */ if (siScroll.cx > 0) { SetRect(&fRect, rcWin.right - siScroll.cx, rcWin.top, rcWin.right, bottom); FillRect(hDC, &fRect, hBrush); } /* * If both the horizontal and vertical scrollbars are present, * draw the "dead square" at the bottom right. */ if (siScroll.cy > 0 && siScroll.cx > 0) { SetRect(&fRect, rcWin.right - siScroll.cx, rcWin.bottom - siScroll.cy, rcWin.right, rcWin.bottom); FillRect(hDC, &fRect, hBrush); } // NOTE: If an additional exterior frame is needed, remove +1 for each direction rcWin.right -= siScroll.cx; rcWin.bottom -= siScroll.cy; } /* Draw the console background */ hBrush = CreateSolidBrush(pConInfo->ColorTable[BkgdAttribFromAttrib(pConInfo->ScreenAttributes)]); FillRect(hDC, &rcWin, hBrush); DeleteObject(hBrush); }
INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PCONSOLE_PROPS pConInfo; DWORD colorIndex; COLORREF color; pConInfo = (PCONSOLE_PROPS)GetWindowLongPtr(hwndDlg, DWLP_USER); switch (uMsg) { case WM_INITDIALOG: { pConInfo = (PCONSOLE_PROPS)((LPPROPSHEETPAGE)lParam)->lParam; SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo); /* Set the valid range of the colour indicators */ SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_COLOR_RED , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_COLOR_GREEN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); SendDlgItemMessageW(hwndDlg, IDC_UPDOWN_COLOR_BLUE , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); /* Select by default the screen background option */ CheckRadioButton(hwndDlg, IDC_RADIO_SCREEN_TEXT, IDC_RADIO_POPUP_BACKGROUND, IDC_RADIO_SCREEN_BACKGROUND); SendMessage(hwndDlg, WM_COMMAND, IDC_RADIO_SCREEN_BACKGROUND, 0); return TRUE; } case WM_DRAWITEM: { LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam; if (drawItem->CtlID >= IDC_STATIC_COLOR1 && drawItem->CtlID <= IDC_STATIC_COLOR16) return PaintStaticControls(hwndDlg, pConInfo, drawItem); else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR) return PaintText(drawItem, pConInfo, Screen); else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR) return PaintText(drawItem, pConInfo, Popup); break; } case WM_NOTIFY: { switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { if (!pConInfo->AppliedConfig) { return ApplyConsoleInfo(hwndDlg, pConInfo); } else { /* Options have already been applied */ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR); return TRUE; } break; } case UDN_DELTAPOS: { LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam; /* Get the current color */ colorIndex = pConInfo->ActiveStaticControl; color = pConInfo->ci.Colors[colorIndex]; if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(lpnmud->iPos, GetGValue(color), GetBValue(color)); } else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(GetRValue(color), lpnmud->iPos, GetBValue(color)); } else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(GetRValue(color), GetGValue(color), lpnmud->iPos); } else { break; } pConInfo->ci.Colors[colorIndex] = color; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hwndDlg), hwndDlg); break; } } break; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_RADIO_SCREEN_TEXT: { /* Get the color of the screen foreground */ colorIndex = TextAttribFromAttrib(pConInfo->ci.ScreenAttrib); color = pConInfo->ci.Colors[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); pConInfo->ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); break; } case IDC_RADIO_SCREEN_BACKGROUND: { /* Get the color of the screen background */ colorIndex = BkgdAttribFromAttrib(pConInfo->ci.ScreenAttrib); color = pConInfo->ci.Colors[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); pConInfo->ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); break; } case IDC_RADIO_POPUP_TEXT: { /* Get the color of the popup foreground */ colorIndex = TextAttribFromAttrib(pConInfo->ci.PopupAttrib); color = pConInfo->ci.Colors[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); pConInfo->ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); break; } case IDC_RADIO_POPUP_BACKGROUND: { /* Get the color of the popup background */ colorIndex = BkgdAttribFromAttrib(pConInfo->ci.PopupAttrib); color = pConInfo->ci.Colors[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); pConInfo->ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); break; } case IDC_EDIT_COLOR_RED: { if (HIWORD(wParam) == EN_KILLFOCUS) { DWORD red; /* Get the current color */ colorIndex = pConInfo->ActiveStaticControl; color = pConInfo->ci.Colors[colorIndex]; red = GetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, NULL, FALSE); red = min(max(red, 0), 255); color = RGB(red, GetGValue(color), GetBValue(color)); pConInfo->ci.Colors[colorIndex] = color; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } break; } case IDC_EDIT_COLOR_GREEN: { if (HIWORD(wParam) == EN_KILLFOCUS) { DWORD green; /* Get the current color */ colorIndex = pConInfo->ActiveStaticControl; color = pConInfo->ci.Colors[colorIndex]; green = GetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, NULL, FALSE); green = min(max(green, 0), 255); color = RGB(GetRValue(color), green, GetBValue(color)); pConInfo->ci.Colors[colorIndex] = color; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } break; } case IDC_EDIT_COLOR_BLUE: { if (HIWORD(wParam) == EN_KILLFOCUS) { DWORD blue; /* Get the current color */ colorIndex = pConInfo->ActiveStaticControl; color = pConInfo->ci.Colors[colorIndex]; blue = GetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, NULL, FALSE); blue = min(max(blue, 0), 255); color = RGB(GetRValue(color), GetGValue(color), blue); pConInfo->ci.Colors[colorIndex] = color; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } break; } } if ( HIWORD(wParam) == STN_CLICKED && IDC_STATIC_COLOR1 <= LOWORD(wParam) && LOWORD(wParam) <= IDC_STATIC_COLOR16 ) { colorIndex = LOWORD(wParam) - IDC_STATIC_COLOR1; if (colorIndex == pConInfo->ActiveStaticControl) { /* Same static control was re-clicked */ break; } color = pConInfo->ci.Colors[colorIndex]; SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); /* Update global struct */ if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_SCREEN_TEXT)) { pConInfo->ci.ScreenAttrib = MakeAttrib(colorIndex, BkgdAttribFromAttrib(pConInfo->ci.ScreenAttrib)); } else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND)) { pConInfo->ci.ScreenAttrib = MakeAttrib(TextAttribFromAttrib(pConInfo->ci.ScreenAttrib), colorIndex); } else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_POPUP_TEXT)) { pConInfo->ci.PopupAttrib = MakeAttrib(colorIndex, BkgdAttribFromAttrib(pConInfo->ci.PopupAttrib)); } else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_POPUP_BACKGROUND)) { pConInfo->ci.PopupAttrib = MakeAttrib(TextAttribFromAttrib(pConInfo->ci.PopupAttrib), colorIndex); } InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); pConInfo->ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hwndDlg), hwndDlg); break; } } default: break; } return FALSE; }
BOOL PaintText(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo, TEXT_TYPE TextMode) { USHORT CurrentAttrib; COLORREF pbkColor, ptColor; COLORREF nbkColor, ntColor; HBRUSH hBrush; HFONT Font, OldFont; COORD FontSize = pConInfo->FontSize; if (TextMode == Screen) CurrentAttrib = pConInfo->ScreenAttributes; else if (TextMode == Popup) CurrentAttrib = pConInfo->PopupAttributes; else return FALSE; nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)]; ntColor = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)]; hBrush = CreateSolidBrush(nbkColor); if (!hBrush) return FALSE; FontSize.Y = FontSize.Y > 0 ? -MulDiv(FontSize.Y, GetDeviceCaps(drawItem->hDC, LOGPIXELSY), 72) : FontSize.Y; Font = CreateFontW(FontSize.Y, FontSize.X, 0, TA_BASELINE, pConInfo->FontWeight, FALSE, FALSE, FALSE, OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH | pConInfo->FontFamily, pConInfo->FaceName); if (Font == NULL) { DPRINT1("PaintText: CreateFont failed\n"); return FALSE; } OldFont = SelectObject(drawItem->hDC, Font); if (OldFont == NULL) { DeleteObject(Font); return FALSE; } FillRect(drawItem->hDC, &drawItem->rcItem, hBrush); ptColor = SetTextColor(drawItem->hDC, ntColor); pbkColor = SetBkColor(drawItem->hDC, nbkColor); DrawTextW(drawItem->hDC, szPreviewText, wcslen(szPreviewText), &drawItem->rcItem, 0); SetTextColor(drawItem->hDC, ptColor); SetBkColor(drawItem->hDC, pbkColor); DeleteObject(hBrush); SelectObject(drawItem->hDC, OldFont); DeleteObject(Font); return TRUE; }
VOID PaintConsole(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo) { HBRUSH hBrush; RECT cRect, fRect; DWORD startx, starty; DWORD endx, endy; DWORD sizex, sizey; FillRect(drawItem->hDC, &drawItem->rcItem, GetSysColorBrush(COLOR_BACKGROUND)); // FIXME: Use: SM_CXSIZE, SM_CYSIZE, SM_CXVSCROLL, SM_CYHSCROLL, SM_CXMIN, SM_CYMIN, SM_CXFRAME, SM_CYFRAME /* Use it for scaling */ sizex = drawItem->rcItem.right - drawItem->rcItem.left; sizey = drawItem->rcItem.bottom - drawItem->rcItem.top ; if ( pConInfo->WindowPosition.x == MAXDWORD && pConInfo->WindowPosition.y == MAXDWORD ) { startx = sizex / 3; starty = sizey / 3; } else { // TODO: // Calculate pos correctly when console centered startx = pConInfo->WindowPosition.x; starty = pConInfo->WindowPosition.y; } // TODO: // Stretch console when bold fonts are selected endx = startx + pConInfo->WindowSize.X; // drawItem->rcItem.right - startx + 15; endy = starty + pConInfo->WindowSize.Y; // starty + sizey / 3; /* Draw console size */ SetRect(&cRect, startx, starty, endx, endy); FillRect(drawItem->hDC, &cRect, GetSysColorBrush(COLOR_WINDOWFRAME)); /* Draw console border */ SetRect(&fRect, startx + 1, starty + 1, cRect.right - 1, cRect.bottom - 1); FrameRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw left box */ SetRect(&fRect, startx + 3, starty + 3, startx + 5, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw window title */ SetRect(&fRect, startx + 7, starty + 3, cRect.right - 9, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION)); /* Draw first right box */ SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw second right box */ SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw scrollbar */ SetRect(&fRect, cRect.right - 5, fRect.bottom + 1, cRect.right - 3, cRect.bottom - 3); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_SCROLLBAR)); /* Draw console background */ hBrush = CreateSolidBrush(pConInfo->ColorTable[BkgdAttribFromAttrib(pConInfo->ScreenAttributes)]); SetRect(&fRect, startx + 3, starty + 6, cRect.right - 6, cRect.bottom - 3); FillRect(drawItem->hDC, &fRect, hBrush); DeleteObject((HGDIOBJ)hBrush); }
VOID GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData, PRECT rcView, PRECT rcFramebuffer) { PCONSRV_CONSOLE Console = Buffer->Header.Console; // ASSERT(Console == GuiData->Console); ULONG TopLine, BottomLine, LeftChar, RightChar; ULONG Line, Char, Start; PCHAR_INFO From; PWCHAR To; WORD LastAttribute, Attribute; ULONG CursorX, CursorY, CursorHeight; HBRUSH CursorBrush, OldBrush; HFONT OldFont, NewFont; BOOLEAN IsUnderline; if (Buffer->Buffer == NULL) return; if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return; rcFramebuffer->left = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->left; rcFramebuffer->top = Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->top; rcFramebuffer->right = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->right; rcFramebuffer->bottom = Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->bottom; LeftChar = rcFramebuffer->left / GuiData->CharWidth; TopLine = rcFramebuffer->top / GuiData->CharHeight; RightChar = rcFramebuffer->right / GuiData->CharWidth; BottomLine = rcFramebuffer->bottom / GuiData->CharHeight; if (RightChar >= (ULONG)Buffer->ScreenBufferSize.X) RightChar = Buffer->ScreenBufferSize.X - 1; if (BottomLine >= (ULONG)Buffer->ScreenBufferSize.Y) BottomLine = Buffer->ScreenBufferSize.Y - 1; LastAttribute = ConioCoordToPointer(Buffer, LeftChar, TopLine)->Attributes; SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute))); SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute))); /* We use the underscore flag as a underline flag */ IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE); /* Select the new font */ NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL]; OldFont = SelectObject(GuiData->hMemDC, NewFont); for (Line = TopLine; Line <= BottomLine; Line++) { WCHAR LineBuffer[80]; // Buffer containing a part or all the line to be displayed From = ConioCoordToPointer(Buffer, LeftChar, Line); // Get the first code of the line Start = LeftChar; To = LineBuffer; for (Char = LeftChar; Char <= RightChar; Char++) { /* * We flush the buffer if the new attribute is different * from the current one, or if the buffer is full. */ if (From->Attributes != LastAttribute || (Char - Start == sizeof(LineBuffer) / sizeof(WCHAR))) { TextOutW(GuiData->hMemDC, Start * GuiData->CharWidth, Line * GuiData->CharHeight, LineBuffer, Char - Start); Start = Char; To = LineBuffer; Attribute = From->Attributes; if (Attribute != LastAttribute) { LastAttribute = Attribute; SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute))); SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute))); /* Change underline state if needed */ if (!!(LastAttribute & COMMON_LVB_UNDERSCORE) != IsUnderline) { IsUnderline = !!(LastAttribute & COMMON_LVB_UNDERSCORE); /* Select the new font */ NewFont = GuiData->Font[IsUnderline ? FONT_BOLD : FONT_NORMAL]; /* OldFont = */ SelectObject(GuiData->hMemDC, NewFont); } } } *(To++) = (From++)->Char.UnicodeChar; } TextOutW(GuiData->hMemDC, Start * GuiData->CharWidth, Line * GuiData->CharHeight, LineBuffer, RightChar - Start + 1); } /* Restore the old font */ SelectObject(GuiData->hMemDC, OldFont); /* * Draw the caret */ if (Buffer->CursorInfo.bVisible && Buffer->CursorBlinkOn && !Buffer->ForceCursorOff) { CursorX = Buffer->CursorPosition.X; CursorY = Buffer->CursorPosition.Y; if (LeftChar <= CursorX && CursorX <= RightChar && TopLine <= CursorY && CursorY <= BottomLine) { CursorHeight = ConioEffectiveCursorSize(Console, GuiData->CharHeight); Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes; if (Attribute == DEFAULT_SCREEN_ATTRIB) Attribute = Buffer->ScreenDefaultAttrib; CursorBrush = CreateSolidBrush(PaletteRGBFromAttrib(Console, TextAttribFromAttrib(Attribute))); OldBrush = SelectObject(GuiData->hMemDC, CursorBrush); PatBlt(GuiData->hMemDC, CursorX * GuiData->CharWidth, CursorY * GuiData->CharHeight + (GuiData->CharHeight - CursorHeight), GuiData->CharWidth, CursorHeight, PATCOPY); SelectObject(GuiData->hMemDC, OldBrush); DeleteObject(CursorBrush); } } LeaveCriticalSection(&Console->Lock); }
VOID GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData, HDC hDC, PRECT rc) { PCONSOLE Console = Buffer->Header.Console; // ASSERT(Console == GuiData->Console); ULONG TopLine, BottomLine, LeftChar, RightChar; ULONG Line, Char, Start; PCHAR_INFO From; PWCHAR To; WORD LastAttribute, Attribute; ULONG CursorX, CursorY, CursorHeight; HBRUSH CursorBrush, OldBrush; HFONT OldFont; if (Buffer->Buffer == NULL) return; TopLine = rc->top / GuiData->CharHeight + Buffer->ViewOrigin.Y; BottomLine = (rc->bottom + (GuiData->CharHeight - 1)) / GuiData->CharHeight - 1 + Buffer->ViewOrigin.Y; LeftChar = rc->left / GuiData->CharWidth + Buffer->ViewOrigin.X; RightChar = (rc->right + (GuiData->CharWidth - 1)) / GuiData->CharWidth - 1 + Buffer->ViewOrigin.X; LastAttribute = ConioCoordToPointer(Buffer, LeftChar, TopLine)->Attributes; SetTextColor(hDC, RGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute))); SetBkColor(hDC, RGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute))); if (BottomLine >= Buffer->ScreenBufferSize.Y) BottomLine = Buffer->ScreenBufferSize.Y - 1; if (RightChar >= Buffer->ScreenBufferSize.X) RightChar = Buffer->ScreenBufferSize.X - 1; OldFont = SelectObject(hDC, GuiData->Font); for (Line = TopLine; Line <= BottomLine; Line++) { WCHAR LineBuffer[80]; // Buffer containing a part or all the line to be displayed From = ConioCoordToPointer(Buffer, LeftChar, Line); // Get the first code of the line Start = LeftChar; To = LineBuffer; for (Char = LeftChar; Char <= RightChar; Char++) { /* * We flush the buffer if the new attribute is different * from the current one, or if the buffer is full. */ if (From->Attributes != LastAttribute || (Char - Start == sizeof(LineBuffer) / sizeof(WCHAR))) { TextOutW(hDC, (Start - Buffer->ViewOrigin.X) * GuiData->CharWidth , (Line - Buffer->ViewOrigin.Y) * GuiData->CharHeight, LineBuffer, Char - Start); Start = Char; To = LineBuffer; Attribute = From->Attributes; if (Attribute != LastAttribute) { SetTextColor(hDC, RGBFromAttrib(Console, TextAttribFromAttrib(Attribute))); SetBkColor(hDC, RGBFromAttrib(Console, BkgdAttribFromAttrib(Attribute))); LastAttribute = Attribute; } } *(To++) = (From++)->Char.UnicodeChar; } TextOutW(hDC, (Start - Buffer->ViewOrigin.X) * GuiData->CharWidth , (Line - Buffer->ViewOrigin.Y) * GuiData->CharHeight, LineBuffer, RightChar - Start + 1); } /* * Draw the caret */ if (Buffer->CursorInfo.bVisible && Buffer->CursorBlinkOn && !Buffer->ForceCursorOff) { CursorX = Buffer->CursorPosition.X; CursorY = Buffer->CursorPosition.Y; if (LeftChar <= CursorX && CursorX <= RightChar && TopLine <= CursorY && CursorY <= BottomLine) { CursorHeight = ConioEffectiveCursorSize(Console, GuiData->CharHeight); Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes; if (Attribute != DEFAULT_SCREEN_ATTRIB) { CursorBrush = CreateSolidBrush(RGBFromAttrib(Console, Attribute)); } else { CursorBrush = CreateSolidBrush(RGBFromAttrib(Console, Buffer->ScreenDefaultAttrib)); } OldBrush = SelectObject(hDC, CursorBrush); PatBlt(hDC, (CursorX - Buffer->ViewOrigin.X) * GuiData->CharWidth, (CursorY - Buffer->ViewOrigin.Y) * GuiData->CharHeight + (GuiData->CharHeight - CursorHeight), GuiData->CharWidth, CursorHeight, PATCOPY); SelectObject(hDC, OldBrush); DeleteObject(CursorBrush); } } SelectObject(hDC, OldFont); }
INT_PTR CALLBACK ColorsProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { DWORD colorIndex; COLORREF color; switch (uMsg) { case WM_INITDIALOG: { /* Set the valid range of the colour indicators */ SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_RED , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_GREEN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_BLUE , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); /* Select by default the screen background option */ CheckRadioButton(hDlg, IDC_RADIO_SCREEN_TEXT, IDC_RADIO_POPUP_BACKGROUND, IDC_RADIO_SCREEN_BACKGROUND); SendMessageW(hDlg, WM_COMMAND, IDC_RADIO_SCREEN_BACKGROUND, 0); return TRUE; } case WM_DRAWITEM: { LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam; if (IDC_STATIC_COLOR1 <= drawItem->CtlID && drawItem->CtlID <= IDC_STATIC_COLOR16) PaintStaticControls(drawItem, ConInfo); else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR) PaintText(drawItem, ConInfo, Screen); else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR) PaintText(drawItem, ConInfo, Popup); return TRUE; } case WM_NOTIFY: { switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { ApplyConsoleInfo(hDlg); return TRUE; } case UDN_DELTAPOS: { LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam; /* Get the current color */ colorIndex = ActiveStaticControl; color = ConInfo->ColorTable[colorIndex]; if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(lpnmud->iPos, GetGValue(color), GetBValue(color)); } else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(GetRValue(color), lpnmud->iPos, GetBValue(color)); } else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255); color = RGB(GetRValue(color), GetGValue(color), lpnmud->iPos); } else { break; } ConInfo->ColorTable[colorIndex] = color; InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hDlg), hDlg); break; } } break; } case WM_COMMAND: { /* NOTE: both BN_CLICKED and STN_CLICKED == 0 */ if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == STN_CLICKED) { if (LOWORD(wParam) == IDC_RADIO_SCREEN_TEXT || LOWORD(wParam) == IDC_RADIO_SCREEN_BACKGROUND || LOWORD(wParam) == IDC_RADIO_POPUP_TEXT || LOWORD(wParam) == IDC_RADIO_POPUP_BACKGROUND) { switch (LOWORD(wParam)) { case IDC_RADIO_SCREEN_TEXT: /* Get the colour of the screen foreground */ colorIndex = TextAttribFromAttrib(ConInfo->ScreenAttributes); break; case IDC_RADIO_SCREEN_BACKGROUND: /* Get the colour of the screen background */ colorIndex = BkgdAttribFromAttrib(ConInfo->ScreenAttributes); break; case IDC_RADIO_POPUP_TEXT: /* Get the colour of the popup foreground */ colorIndex = TextAttribFromAttrib(ConInfo->PopupAttributes); break; case IDC_RADIO_POPUP_BACKGROUND: /* Get the colour of the popup background */ colorIndex = BkgdAttribFromAttrib(ConInfo->PopupAttributes); break; } color = ConInfo->ColorTable[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE); ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE); break; } else if (IDC_STATIC_COLOR1 <= LOWORD(wParam) && LOWORD(wParam) <= IDC_STATIC_COLOR16) { colorIndex = LOWORD(wParam) - IDC_STATIC_COLOR1; /* If the same static control was re-clicked, don't take it into account */ if (colorIndex == ActiveStaticControl) break; color = ConInfo->ColorTable[colorIndex]; /* Set the values of the colour indicators */ SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE); SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE); SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE); if (IsDlgButtonChecked(hDlg, IDC_RADIO_SCREEN_TEXT)) { ConInfo->ScreenAttributes = MakeAttrib(colorIndex, BkgdAttribFromAttrib(ConInfo->ScreenAttributes)); } else if (IsDlgButtonChecked(hDlg, IDC_RADIO_SCREEN_BACKGROUND)) { ConInfo->ScreenAttributes = MakeAttrib(TextAttribFromAttrib(ConInfo->ScreenAttributes), colorIndex); } else if (IsDlgButtonChecked(hDlg, IDC_RADIO_POPUP_TEXT)) { ConInfo->PopupAttributes = MakeAttrib(colorIndex, BkgdAttribFromAttrib(ConInfo->PopupAttributes)); } else if (IsDlgButtonChecked(hDlg, IDC_RADIO_POPUP_BACKGROUND)) { ConInfo->PopupAttributes = MakeAttrib(TextAttribFromAttrib(ConInfo->PopupAttributes), colorIndex); } InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE); ActiveStaticControl = colorIndex; InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hDlg), hDlg); break; } } else if (HIWORD(wParam) == EN_KILLFOCUS) { if (LOWORD(wParam) == IDC_EDIT_COLOR_RED || LOWORD(wParam) == IDC_EDIT_COLOR_GREEN || LOWORD(wParam) == IDC_EDIT_COLOR_BLUE) { DWORD value; /* Get the current colour */ colorIndex = ActiveStaticControl; color = ConInfo->ColorTable[colorIndex]; /* Modify the colour component */ switch (LOWORD(wParam)) { case IDC_EDIT_COLOR_RED: value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED, NULL, FALSE); value = min(max(value, 0), 255); color = RGB(value, GetGValue(color), GetBValue(color)); break; case IDC_EDIT_COLOR_GREEN: value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, NULL, FALSE); value = min(max(value, 0), 255); color = RGB(GetRValue(color), value, GetBValue(color)); break; case IDC_EDIT_COLOR_BLUE: value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE, NULL, FALSE); value = min(max(value, 0), 255); color = RGB(GetRValue(color), GetGValue(color), value); break; } ConInfo->ColorTable[colorIndex] = color; InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE); PropSheet_Changed(GetParent(hDlg), hDlg); break; } } break; } default: break; } return FALSE; }
VOID PaintConsole(LPDRAWITEMSTRUCT drawItem, PCONSOLE_PROPS pConInfo) { PGUI_CONSOLE_INFO GuiInfo = pConInfo->TerminalInfo.TermInfo; HBRUSH hBrush; RECT cRect, fRect; DWORD startx, starty; DWORD endx, endy; DWORD sizex, sizey; FillRect(drawItem->hDC, &drawItem->rcItem, GetSysColorBrush(COLOR_BACKGROUND)); sizex = drawItem->rcItem.right - drawItem->rcItem.left; sizey = drawItem->rcItem.bottom - drawItem->rcItem.top; if ( GuiInfo->WindowOrigin.x == MAXDWORD && GuiInfo->WindowOrigin.y == MAXDWORD ) { startx = sizex / 3; starty = sizey / 3; } else { // TODO: // Calculate pos correctly when console centered startx = sizex / 3; starty = sizey / 3; } // TODO: // Strech console when bold fonts are selected endx = drawItem->rcItem.right - startx + 15; endy = starty + sizey / 3; /* Draw console size */ SetRect(&cRect, startx, starty, endx, endy); FillRect(drawItem->hDC, &cRect, GetSysColorBrush(COLOR_WINDOWFRAME)); /* Draw console border */ SetRect(&fRect, startx + 1, starty + 1, cRect.right - 1, cRect.bottom - 1); FrameRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw left box */ SetRect(&fRect, startx + 3, starty + 3, startx + 5, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw window title */ SetRect(&fRect, startx + 7, starty + 3, cRect.right - 9, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION)); /* Draw first right box */ SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw second right box */ SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER)); /* Draw scrollbar */ SetRect(&fRect, cRect.right - 5, fRect.bottom + 1, cRect.right - 3, cRect.bottom - 3); FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_SCROLLBAR)); /* Draw console background */ hBrush = CreateSolidBrush(pConInfo->ci.Colors[BkgdAttribFromAttrib(pConInfo->ci.ScreenAttrib)]); SetRect(&fRect, startx + 3, starty + 6, cRect.right - 6, cRect.bottom - 3); FillRect(drawItem->hDC, &fRect, hBrush); DeleteObject((HGDIOBJ)hBrush); }