diff options
author | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-11-19 16:24:37 +0100 |
---|---|---|
committer | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-11-19 16:24:37 +0100 |
commit | 7d914d89219cca3c179951e5c8516726712c9ac5 (patch) | |
tree | d838ccf4ec70b85babc023837ad85cec4f211be3 /vcl/win/source | |
parent | 140e83be45834d050d91cd7fad5984f690be09d4 (diff) |
vcl117: #i115607# support NWF for menus on Windows
Diffstat (limited to 'vcl/win/source')
-rwxr-xr-x[-rw-r--r--] | vcl/win/source/app/salinst.cxx | 3 | ||||
-rwxr-xr-x | vcl/win/source/gdi/salnativewidgets-luna.cxx | 143 | ||||
-rwxr-xr-x | vcl/win/source/window/salframe.cxx | 40 |
3 files changed, 178 insertions, 8 deletions
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx index d05f64d147ed..c056bf8281ba 100644..100755 --- a/vcl/win/source/app/salinst.cxx +++ b/vcl/win/source/app/salinst.cxx @@ -434,9 +434,12 @@ SalData::SalData() mpFirstIcon = 0; // icon cache, points to first icon, NULL if none mpTempFontItem = 0; mbThemeChanged = FALSE; // true if visual theme was changed: throw away theme handles + mbThemeMenuSupport = FALSE; // init with NULL gdiplusToken = 0; + maDwmLib = 0; + mpDwmIsCompositionEnabled = 0; initKeyCodeMap(); diff --git a/vcl/win/source/gdi/salnativewidgets-luna.cxx b/vcl/win/source/gdi/salnativewidgets-luna.cxx index 8197fb37cd6d..97e3e1b48c79 100755 --- a/vcl/win/source/gdi/salnativewidgets-luna.cxx +++ b/vcl/win/source/gdi/salnativewidgets-luna.cxx @@ -188,6 +188,8 @@ void SalData::deInitNWF( void ) iter++; } aThemeMap.clear(); + if( maDwmLib ) + osl_unloadModule( maDwmLib ); } static HTHEME getThemeHandle( HWND hWnd, LPCWSTR name ) @@ -286,6 +288,22 @@ BOOL WinSalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nP case CTRL_MENUBAR: if( nPart == PART_ENTIRE_CONTROL ) hTheme = getThemeHandle( mhWnd, L"Rebar"); + else if( GetSalData()->mbThemeMenuSupport ) + { + if( nPart == PART_MENU_ITEM ) + hTheme = getThemeHandle( mhWnd, L"Menu" ); + } + break; + case CTRL_MENU_POPUP: + if( GetSalData()->mbThemeMenuSupport ) + { + if( nPart == PART_ENTIRE_CONTROL || + nPart == PART_MENU_ITEM || + nPart == PART_MENU_ITEM_CHECK_MARK || + nPart == PART_MENU_ITEM_RADIO_MARK || + nPart == PART_MENU_SEPARATOR ) + hTheme = getThemeHandle( mhWnd, L"Menu" ); + } break; case CTRL_PROGRESS: if( nPart == PART_ENTIRE_CONTROL ) @@ -867,15 +885,23 @@ BOOL ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, if( nType == CTRL_MENUBAR ) { - if( nPart != PART_ENTIRE_CONTROL ) - return FALSE; - - if( aValue.getType() == CTRL_MENUBAR ) + if( nPart == PART_ENTIRE_CONTROL ) { - const MenubarValue *pValue = static_cast<const MenubarValue*>(&aValue); - rc.bottom += pValue->maTopDockingAreaHeight; // extend potential gradient to cover docking area as well + if( aValue.getType() == CTRL_MENUBAR ) + { + const MenubarValue *pValue = static_cast<const MenubarValue*>(&aValue); + rc.bottom += pValue->maTopDockingAreaHeight; // extend potential gradient to cover docking area as well + } + return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption); + } + else if( nPart == PART_MENU_ITEM ) + { + if( (nState & CTRL_STATE_ENABLED) ) + iState = (nState & CTRL_STATE_SELECTED) ? MBI_HOT : MBI_NORMAL; + else + iState = (nState & CTRL_STATE_SELECTED) ? MBI_DISABLEDHOT : MBI_DISABLED; + return ImplDrawTheme( hTheme, hDC, MENU_BARITEM, iState, rc, aCaption ); } - return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption); } if( nType == CTRL_PROGRESS ) @@ -954,6 +980,69 @@ BOOL ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption ); } + if( GetSalData()->mbThemeMenuSupport ) + { + if( nType == CTRL_MENU_POPUP ) + { + if( nPart == PART_ENTIRE_CONTROL ) + { + RECT aGutterRC = rc; + aGutterRC.left += aValue.getNumericVal(); + aGutterRC.right = aGutterRC.left+3; + return + ImplDrawTheme( hTheme, hDC, MENU_POPUPBACKGROUND, 0, rc, aCaption ) && + ImplDrawTheme( hTheme, hDC, MENU_POPUPGUTTER, 0, aGutterRC, aCaption ) + ; + } + else if( nPart == PART_MENU_ITEM ) + { + if( (nState & CTRL_STATE_ENABLED) ) + iState = (nState & CTRL_STATE_SELECTED) ? MPI_HOT : MPI_NORMAL; + else + iState = (nState & CTRL_STATE_SELECTED) ? MPI_DISABLEDHOT : MPI_DISABLED; + return ImplDrawTheme( hTheme, hDC, MENU_POPUPITEM, iState, rc, aCaption ); + } + else if( nPart == PART_MENU_ITEM_CHECK_MARK || nPart == PART_MENU_ITEM_RADIO_MARK ) + { + if( (nState & CTRL_STATE_PRESSED) ) + { + RECT aBGRect = rc; + if( aValue.getType() == CTRL_MENU_POPUP ) + { + const MenupopupValue& rMVal( static_cast<const MenupopupValue&>(aValue) ); + aBGRect.left = rMVal.maItemRect.Left(); + aBGRect.top = rMVal.maItemRect.Top(); + aBGRect.bottom = rMVal.maItemRect.Bottom()+1; // see below in drawNativeControl + aBGRect.right = rMVal.getNumericVal(); + + // FIXME: magic + aBGRect.left += 1; aBGRect.top += 1; aBGRect.bottom +=1; + } + iState = (nState & CTRL_STATE_ENABLED) ? MCB_NORMAL : MCB_DISABLED; + ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECKBACKGROUND, iState, aBGRect, aCaption ); + if( nPart == PART_MENU_ITEM_CHECK_MARK ) + iState = (nState & CTRL_STATE_ENABLED) ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED; + else + iState = (nState & CTRL_STATE_ENABLED) ? MC_BULLETNORMAL : MC_BULLETDISABLED; + return ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECK, iState, rc, aCaption ); + } + else + return true; // unchecked: do nothing + } + else if( nPart == PART_MENU_SEPARATOR ) + { + rc.left += aValue.getNumericVal(); // adjust for gutter position + Rectangle aRect( ImplGetThemeRect( hTheme, hDC, + MENU_POPUPSEPARATOR, 0, Rectangle( rc.left, rc.top, rc.right, rc.bottom ) ) ); + // center the separator inside the passed rectangle + long nDY = ((rc.bottom - rc.top + 1) - aRect.GetHeight()) / 2; + rc.top += nDY; + rc.bottom = rc.top+aRect.GetHeight()-1; + return ImplDrawTheme( hTheme, hDC, MENU_POPUPSEPARATOR, 0, rc, aCaption ); + } + } + } + return false; } @@ -1027,6 +1116,11 @@ BOOL WinSalGraphics::drawNativeControl( ControlType nType, case CTRL_MENUBAR: if( nPart == PART_ENTIRE_CONTROL ) hTheme = getThemeHandle( mhWnd, L"Rebar"); + else if( GetSalData()->mbThemeMenuSupport ) + { + if( nPart == PART_MENU_ITEM ) + hTheme = getThemeHandle( mhWnd, L"Menu" ); + } break; case CTRL_PROGRESS: if( nPart == PART_ENTIRE_CONTROL ) @@ -1040,6 +1134,16 @@ BOOL WinSalGraphics::drawNativeControl( ControlType nType, if( nPart == PART_TRACK_HORZ_AREA || nPart == PART_TRACK_VERT_AREA ) hTheme = getThemeHandle( mhWnd, L"Trackbar" ); break; + case CTRL_MENU_POPUP: + if( GetSalData()->mbThemeMenuSupport ) + { + if( nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM || + nPart == PART_MENU_ITEM_CHECK_MARK || nPart == PART_MENU_ITEM_RADIO_MARK || + nPart == PART_MENU_SEPARATOR + ) + hTheme = getThemeHandle( mhWnd, L"Menu" ); + } + break; default: hTheme = NULL; break; @@ -1196,7 +1300,7 @@ BOOL WinSalGraphics::getNativeControlRegion( ControlType nType, HTHEME hTheme = getThemeHandle( mhWnd, L"Edit"); if( hTheme ) { - // get borderr size + // get border size Rectangle aBoxRect( rControlRegion ); Rectangle aRect( ImplGetThemeRect( hTheme, hDC, EP_BACKGROUNDWITHBORDER, EBWBS_HOT, aBoxRect ) ); @@ -1225,6 +1329,29 @@ BOOL WinSalGraphics::getNativeControlRegion( ControlType nType, } } + if( GetSalData()->mbThemeMenuSupport ) + { + if( nType == CTRL_MENU_POPUP ) + { + if( nPart == PART_MENU_ITEM_CHECK_MARK || + nPart == PART_MENU_ITEM_RADIO_MARK ) + { + HTHEME hTheme = getThemeHandle( mhWnd, L"Menu"); + Rectangle aBoxRect( rControlRegion ); + Rectangle aRect( ImplGetThemeRect( hTheme, hDC, + MENU_POPUPCHECK, + MC_CHECKMARKNORMAL, + aBoxRect ) ); + if( aBoxRect.GetWidth() && aBoxRect.GetHeight() ) + { + rNativeContentRegion = aRect; + rNativeBoundingRegion = rNativeContentRegion; + bRet = TRUE; + } + } + } + } + if( nType == CTRL_SLIDER && ( (nPart == PART_THUMB_HORZ) || (nPart == PART_THUMB_VERT) ) ) { HTHEME hTheme = getThemeHandle( mhWnd, L"Trackbar"); diff --git a/vcl/win/source/window/salframe.cxx b/vcl/win/source/window/salframe.cxx index d6b05c5bb032..df077cc4c4e5 100755 --- a/vcl/win/source/window/salframe.cxx +++ b/vcl/win/source/window/salframe.cxx @@ -2835,6 +2835,29 @@ static long ImplA2I( const BYTE* pStr ) } // ----------------------------------------------------------------------- +static HRESULT WINAPI backwardCompatibleDwmIsCompositionEnabled( WIN_BOOL* pOut ) +{ + *pOut = FALSE; + return S_OK; +} + +static WIN_BOOL ImplDwmIsCompositionEnabled() +{ + SalData* pSalData = GetSalData(); + if( ! pSalData->mpDwmIsCompositionEnabled ) + { + rtl::OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM( "Dwmapi.dll" ) ); + pSalData->maDwmLib = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT ); + if( pSalData->maDwmLib ) + pSalData->mpDwmIsCompositionEnabled = (DwmIsCompositionEnabled_ptr)osl_getAsciiFunctionSymbol( pSalData->maDwmLib, "DwmIsCompositionEnabled" ); + if( ! pSalData->mpDwmIsCompositionEnabled ) // something failed + pSalData->mpDwmIsCompositionEnabled = backwardCompatibleDwmIsCompositionEnabled; + } + WIN_BOOL aResult = FALSE; + HRESULT nError = pSalData->mpDwmIsCompositionEnabled( &aResult ); + return nError == S_OK && aResult; +} + void WinSalFrame::UpdateSettings( AllSettings& rSettings ) { @@ -2912,6 +2935,10 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings ) aStyleSettings.SetHighlightTextColor( ImplWinColorToSal( GetSysColor( COLOR_HIGHLIGHTTEXT ) ) ); aStyleSettings.SetMenuHighlightColor( aStyleSettings.GetHighlightColor() ); aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetHighlightTextColor() ); + ImplSVData* pSVData = ImplGetSVData(); + pSVData->maNWFData.mnMenuFormatExtraBorder = 0; + pSVData->maNWFData.maMenuBarHighlightTextColor = Color( COL_TRANSPARENT ); + GetSalData()->mbThemeMenuSupport = FALSE; if ( bCompBorder ) { aStyleSettings.SetMenuColor( ImplWinColorToSal( GetSysColor( COLOR_MENU ) ) ); @@ -2942,6 +2969,19 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings ) aStyleSettings.SetUseFlatBorders( TRUE ); } } + // check if vista or newer runs + // in Aero theme (and similar ?) the menu text color does not change + // for selected items; also on WinXP and earlier menus are not themed + if( aSalShlData.maVersionInfo.dwMajorVersion >= 6 && + ImplDwmIsCompositionEnabled() + ) + { + // in aero menuitem highlight text is drawn in the same color as normal + aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetMenuTextColor() ); + pSVData->maNWFData.mnMenuFormatExtraBorder = 2; + pSVData->maNWFData.maMenuBarHighlightTextColor = aStyleSettings.GetMenuTextColor(); + GetSalData()->mbThemeMenuSupport = TRUE; + } } // Bei hellgrau geben wir die Farbe vor, damit es besser aussieht if ( aStyleSettings.GetFaceColor() == COL_LIGHTGRAY ) |