diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-01 13:42:09 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-02 09:03:57 +0100 |
commit | 4494966015fbdf544928a9f6d1105d57e7a8212a (patch) | |
tree | 52fb5c809b5f03e049f0c2867f0202f9069c850e /vcl/win/gdi | |
parent | 9f4aad493c7087256d03b01ca3fb18d96f461526 (diff) |
Factor out drawing native menu mark into a separate function
Change-Id: I87da929d5311c72189f6c22f910b33f3a03393c3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127847
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/win/gdi')
-rw-r--r-- | vcl/win/gdi/salnativewidgets-luna.cxx | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx b/vcl/win/gdi/salnativewidgets-luna.cxx index fe784c66872c..af2608bf02fa 100644 --- a/vcl/win/gdi/salnativewidgets-luna.cxx +++ b/vcl/win/gdi/salnativewidgets-luna.cxx @@ -393,6 +393,42 @@ static tools::Rectangle GetMenuPopupMarkRegion(const ImplControlValue& rValue) return aRet; } +static bool implDrawNativeMenuMark(HDC hDC, HTHEME hTheme, RECT rc, ControlPart nPart, + ControlState nState, const ImplControlValue& aValue, + OUString const& aCaption) +{ + if (aValue.getType() == ControlType::MenuPopup) + { + tools::Rectangle aRectangle = GetMenuPopupMarkRegion(aValue); + rc.top = aRectangle.Top(); + rc.left = aRectangle.Left(); + rc.bottom = aRectangle.Bottom(); + rc.right = aRectangle.Right(); + } + int iState = (nState & ControlState::ENABLED) ? MCB_NORMAL : MCB_DISABLED; + ImplDrawTheme(hTheme, hDC, MENU_POPUPCHECKBACKGROUND, iState, rc, aCaption); + if (nPart == ControlPart::MenuItemCheckMark) + iState = (nState & ControlState::ENABLED) ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED; + else + iState = (nState & ControlState::ENABLED) ? MC_BULLETNORMAL : MC_BULLETDISABLED; + // tdf#133697: Get true size of mark, to avoid stretching + if (auto oSize = ImplGetThemeSize(hTheme, hDC, MENU_POPUPCHECK, iState, &rc)) + { + // center the mark inside the passed rectangle + if (const auto dx = (rc.right - rc.left - oSize->Width() + 1) / 2; dx > 0) + { + rc.left += dx; + rc.right = rc.left + oSize->Width(); + } + if (const auto dy = (rc.bottom - rc.top - oSize->Height() + 1) / 2; dy > 0) + { + rc.top += dy; + rc.bottom = rc.top + oSize->Height(); + } + } + return ImplDrawTheme(hTheme, hDC, MENU_POPUPCHECK, iState, rc, aCaption); +} + static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, ControlType nType, ControlPart nPart, @@ -978,39 +1014,8 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, } else if( nPart == ControlPart::MenuItemCheckMark || nPart == ControlPart::MenuItemRadioMark ) { - if( nState & ControlState::PRESSED ) - { - if( aValue.getType() == ControlType::MenuPopup ) - { - tools::Rectangle aRectangle = GetMenuPopupMarkRegion(aValue); - rc.top = aRectangle.Top(); - rc.left = aRectangle.Left(); - rc.bottom = aRectangle.Bottom(); - rc.right = aRectangle.Right(); - } - iState = (nState & ControlState::ENABLED) ? MCB_NORMAL : MCB_DISABLED; - ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECKBACKGROUND, iState, rc, aCaption ); - if( nPart == ControlPart::MenuItemCheckMark ) - iState = (nState & ControlState::ENABLED) ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED; - else - iState = (nState & ControlState::ENABLED) ? MC_BULLETNORMAL : MC_BULLETDISABLED; - // tdf#133697: Get true size of mark, to avoid stretching - if (auto oSize = ImplGetThemeSize(hTheme, hDC, MENU_POPUPCHECK, iState, &rc)) - { - // center the mark inside the passed rectangle - if (const auto dx = (rc.right - rc.left - oSize->Width() + 1) / 2; dx > 0) - { - rc.left += dx; - rc.right = rc.left + oSize->Width(); - } - if (const auto dy = (rc.bottom - rc.top - oSize->Height() + 1) / 2; dy > 0) - { - rc.top += dy; - rc.bottom = rc.top + oSize->Height(); - } - } - return ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECK, iState, rc, aCaption ); - } + if (nState & ControlState::PRESSED) + return implDrawNativeMenuMark(hDC, hTheme, rc, nPart, nState, aValue, aCaption); else return true; // unchecked: do nothing } |