summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2012-05-14 17:50:43 +0200
committerJan Holesovsky <kendy@suse.cz>2012-05-15 08:39:32 +0200
commit64c696fc92a860fdbbe490ca503391b964dd646f (patch)
tree8f602a179a2e41f24785eee20f299dcec52bacd4 /vcl
parent83208da599e46dbba39c9e9a5b503bc4e93d4eea (diff)
aero: Implement a glass menubar on Windows.
We need to default to the Aero colors too, in order to this be really beautiful; but hopefully already in the current state it is an improvement :-) Change-Id: I 113039b62320fa76916ba74071e1eebff4d3476c
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/salframe.hxx6
-rw-r--r--vcl/inc/svdata.hxx1
-rw-r--r--vcl/inc/win/salframe.h6
-rw-r--r--vcl/source/window/menu.cxx51
-rw-r--r--vcl/win/source/gdi/salnativewidgets-luna.cxx132
5 files changed, 159 insertions, 37 deletions
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index e72648316992..e210287871ca 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -279,6 +279,12 @@ public:
// (e.g. input methods, printer update handlers).
long CallCallback( sal_uInt16 nEvent, const void* pEvent ) const
{ return m_pProc ? m_pProc( m_pWindow, const_cast<SalFrame*>(this), nEvent, pEvent ) : 0; }
+
+ /// Update the region that is supposed to be handled by the window manager
+ ///
+ /// This is primarily for Windows Aero theme in order to be able to draw
+ /// to the Glass area.
+ virtual void extendWindowManagerFrameNative( int /*nLeft*/, int /*nRight*/, int /*nTop*/, int /*nBottom*/ ) {}
};
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 242d58cea052..c21d580c20be 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -310,6 +310,7 @@ struct ImplSVNWFData
bool mbToolboxDropDownSeparate:1; // two adjacent buttons for
// toolbox dropdown buttons
bool mbFlatMenu:1; // no popup 3D border
+ bool mbTransparentMenubar:1; //< keep the background of the menubar transparent; needed for the Aero theme
bool mbOpenMenuOnF10:1; // on gnome the first menu opens on F10
bool mbNoFocusRects:1; // on Aqua focus rects are not used
bool mbNoBoldTabFocus:1; // on Aqua and Gnome the focused tab has not bold text
diff --git a/vcl/inc/win/salframe.h b/vcl/inc/win/salframe.h
index 0d4e206e8507..b8056696b7f8 100644
--- a/vcl/inc/win/salframe.h
+++ b/vcl/inc/win/salframe.h
@@ -144,6 +144,12 @@ public:
virtual void BeginSetClipRegion( sal_uIntPtr nRects );
virtual void UnionClipRegion( long nX, long nY, long nWidth, long nHeight );
virtual void EndSetClipRegion();
+
+ /// Update the region that is supposed to be handled by the window manager
+ ///
+ /// This is primarily for Windows Aero theme in order to be able to draw
+ /// to the Glass area.
+ virtual void extendWindowManagerFrameNative( int nLeft, int nRight, int nTop, int nBottom );
};
void ImplSalGetWorkArea( HWND hWnd, RECT *pRect, const RECT *pParentRect );
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 965778c1cd7f..04619eb545a2 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -52,6 +52,7 @@
#include "vcl/toolbox.hxx"
#include "vcl/dockingarea.hxx"
+#include "salframe.hxx"
#include "salinst.hxx"
#include "svdata.hxx"
#include "svids.hrc"
@@ -2673,6 +2674,29 @@ void Menu::ImplPaint( Window* pWin, sal_uInt16 nBorder, long nStartY, MenuItemDa
nImageStyle |= IMAGE_DRAW_DISABLE;
}
+ // Menubar highlights
+ if ( bIsMenuBar && pWin->IsNativeControlSupported( CTRL_MENUBAR, PART_MENU_ITEM ) )
+ {
+ bool bHighlight = pThisItemOnly && bHighlighted;
+ if ( bHighlight || ImplGetSVData()->maNWFData.mbTransparentMenubar )
+ {
+ Rectangle aRect = Rectangle( Point( aTopLeft.X(), 1 ), Size( pData->aSz.Width(), pWin->GetOutputSizePixel().Height()-2 ) );
+ pWin->Push( PUSH_CLIPREGION );
+ pWin->IntersectClipRegion( aRect );
+
+ // draw selected item
+ MenubarValue aControlValue;
+ aControlValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight( pWin );
+ pWin->DrawNativeControl( CTRL_MENUBAR, PART_MENU_ITEM,
+ aRect,
+ CTRL_STATE_ENABLED | ( bHighlight? CTRL_STATE_SELECTED: 0 ),
+ aControlValue,
+ OUString() );
+
+ pWin->Pop();
+ }
+ }
+
// Separator
if ( !bLayout && !bIsMenuBar && ( pData->eType == MENUITEM_SEPARATOR ) )
{
@@ -3331,6 +3355,9 @@ Window* MenuBar::ImplCreate( Window* pParent, Window* pWindow, MenuBar* pMenu )
( pMenu->ImplGetSalMenu() && pMenu->ImplGetSalMenu()->VisibleMenuBar() ) )
nHeight = 0;
+ if ( pParent )
+ pParent->ImplGetFrame()->extendWindowManagerFrameNative( 0, 0, nHeight, 0 );
+
pWindow->SetPosSizePixel( 0, 0, 0, nHeight, WINDOW_POSSIZE_HEIGHT );
return pWindow;
}
@@ -3914,6 +3941,18 @@ static void ImplInitMenuWindow( Window* pWin, sal_Bool bFont, sal_Bool bMenuBar
pWin->SetTextColor( rStyleSettings.GetMenuTextColor() );
pWin->SetTextFillColor();
pWin->SetLineColor();
+
+ // update the window manager frame here too in order to be able to switch
+ // themes
+ if ( bMenuBar )
+ {
+ const Window *pParent = pWin->GetParent();
+ if ( pParent )
+ {
+ Size aSize = pWin->GetSizePixel();
+ pParent->ImplGetFrame()->extendWindowManagerFrameNative( 0, 0, aSize.Height(), 0 );
+ }
+ }
}
MenuFloatingWindow::MenuFloatingWindow( Menu* pMen, Window* pParent, WinBits nStyle ) :
@@ -5537,15 +5576,9 @@ void MenuBarWindow::HighlightItem( sal_uInt16 nPos, sal_Bool bHighlight )
OUString() );
ImplAddNWFSeparator( this, aControlValue );
- if ( bHighlight )
- {
- // draw selected item
- DrawNativeControl( CTRL_MENUBAR, PART_MENU_ITEM,
- aRect,
- CTRL_STATE_ENABLED | CTRL_STATE_SELECTED,
- aControlValue,
- OUString() );
- }
+ // NWF item highlight is drawn in ImplPaint() instead of
+ // here, so that we can NWF-paint even the non-higlighted
+ // items there
}
else
{
diff --git a/vcl/win/source/gdi/salnativewidgets-luna.cxx b/vcl/win/source/gdi/salnativewidgets-luna.cxx
index 6fdeac639c9a..fbe80ca41ddb 100644
--- a/vcl/win/source/gdi/salnativewidgets-luna.cxx
+++ b/vcl/win/source/gdi/salnativewidgets-luna.cxx
@@ -35,7 +35,10 @@
// (found at http://stackoverflow.com/questions/4009701/windows-visual-themes-gallery-of-parts-and-states/4009712#4009712)
//
// Theme subclasses:
-// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773218%28v=vs.85%29.aspx
+// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773218%28v=vs.85%29.aspx
+//
+// Drawing in non-client area (general DWM-related info):
+// http://msdn.microsoft.com/en-us/library/windows/desktop/bb688195%28v=vs.85%29.aspx
#define _SV_SALNATIVEWIDGETS_CXX
@@ -48,6 +51,7 @@
#include "win/svsys.h"
#include "win/salgdi.h"
#include "win/saldata.hxx"
+#include "win/salframe.h"
#include "uxtheme.h"
#include "vssym32.h"
@@ -71,6 +75,7 @@ static ThemeMap aThemeMap;
class VisualStylesAPI
{
private:
+ // uxtheme.dll functions
typedef HTHEME (WINAPI * OpenThemeData_Proc_T) ( HWND hwnd, LPCWSTR pszClassList );
typedef HRESULT (WINAPI * CloseThemeData_Proc_T) ( HTHEME hTheme );
typedef HRESULT (WINAPI * GetThemeBackgroundContentRect_Proc_T) ( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect );
@@ -87,12 +92,18 @@ private:
GetThemePartSize_Proc_T lpfnGetThemePartSize;
IsThemeActive_Proc_T lpfnIsThemeActive;
- oslModule mhModule;
+ // dwmapi.dll functions
+ typedef HRESULT (WINAPI * DwmExtendFrameIntoClientArea_Proc_T) ( HWND hWnd, const MARGINS *pMarInset );
+
+ DwmExtendFrameIntoClientArea_Proc_T lpfnDwmExtendFrameIntoClientArea;
+
+ // module handles of the appropriate dll's
+ oslModule mhUxthemeModule;
+ oslModule mhDwmapiModule;
public:
VisualStylesAPI();
~VisualStylesAPI();
- sal_Bool IsAvailable() { return (mhModule != NULL); }
HTHEME OpenThemeData( HWND hwnd, LPCWSTR pszClassList );
HRESULT CloseThemeData( HTHEME hTheme );
@@ -101,40 +112,52 @@ public:
HRESULT DrawThemeText( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect );
HRESULT GetThemePartSize( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz );
BOOL IsThemeActive( void );
+
+ HRESULT DwmExtendFrameIntoClientArea( HWND hWnd, const MARGINS *pMarInset );
};
static VisualStylesAPI vsAPI;
VisualStylesAPI::VisualStylesAPI()
+ : lpfnOpenThemeData( NULL ),
+ lpfnCloseThemeData( NULL ),
+ lpfnGetThemeBackgroundContentRect( NULL ),
+ lpfnDrawThemeBackground( NULL ),
+ lpfnDrawThemeText( NULL ),
+ lpfnGetThemePartSize( NULL ),
+ lpfnIsThemeActive( NULL ),
+ lpfnDwmExtendFrameIntoClientArea( NULL )
{
- OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM( "uxtheme.dll" ) );
- mhModule = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
+ OUString aLibraryName( "uxtheme.dll" );
+ mhUxthemeModule = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
- if ( mhModule )
+ if ( mhUxthemeModule )
{
- lpfnOpenThemeData = (OpenThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "OpenThemeData" );
- lpfnCloseThemeData = (CloseThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "CloseThemeData" );
- lpfnGetThemeBackgroundContentRect = (GetThemeBackgroundContentRect_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "GetThemeBackgroundContentRect" );
- lpfnDrawThemeBackground = (DrawThemeBackground_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "DrawThemeBackground" );
- lpfnDrawThemeText = (DrawThemeText_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "DrawThemeText" );
- lpfnGetThemePartSize = (GetThemePartSize_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "GetThemePartSize" );
- lpfnIsThemeActive = (IsThemeActive_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "IsThemeActive" );
+ lpfnOpenThemeData = (OpenThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "OpenThemeData" );
+ lpfnCloseThemeData = (CloseThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "CloseThemeData" );
+ lpfnGetThemeBackgroundContentRect = (GetThemeBackgroundContentRect_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "GetThemeBackgroundContentRect" );
+ lpfnDrawThemeBackground = (DrawThemeBackground_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "DrawThemeBackground" );
+ lpfnDrawThemeText = (DrawThemeText_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "DrawThemeText" );
+ lpfnGetThemePartSize = (GetThemePartSize_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "GetThemePartSize" );
+ lpfnIsThemeActive = (IsThemeActive_Proc_T)osl_getAsciiFunctionSymbol( mhUxthemeModule, "IsThemeActive" );
}
- else
+
+ aLibraryName = "dwmapi.dll";
+ mhDwmapiModule = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
+
+ if ( mhDwmapiModule )
{
- lpfnOpenThemeData = NULL;
- lpfnCloseThemeData = NULL;
- lpfnGetThemeBackgroundContentRect = NULL;
- lpfnDrawThemeBackground = NULL;
- lpfnDrawThemeText = NULL;
- lpfnGetThemePartSize = NULL;
+ lpfnDwmExtendFrameIntoClientArea = (DwmExtendFrameIntoClientArea_Proc_T)osl_getAsciiFunctionSymbol( mhDwmapiModule, "DwmExtendFrameIntoClientArea" );
}
}
VisualStylesAPI::~VisualStylesAPI()
{
- if( mhModule )
- osl_unloadModule( mhModule );
+ if( mhUxthemeModule )
+ osl_unloadModule( mhUxthemeModule );
+
+ if( mhDwmapiModule )
+ osl_unloadModule( mhDwmapiModule );
}
HTHEME VisualStylesAPI::OpenThemeData( HWND hwnd, LPCWSTR pszClassList )
@@ -193,6 +216,14 @@ BOOL VisualStylesAPI::IsThemeActive( void )
return FALSE;
}
+HRESULT VisualStylesAPI::DwmExtendFrameIntoClientArea( HWND hWnd, const MARGINS *pMarInset )
+{
+ if (lpfnDwmExtendFrameIntoClientArea)
+ return (*lpfnDwmExtendFrameIntoClientArea) ( hWnd, pMarInset );
+ else
+ return S_FALSE;
+}
+
/*********************************************************
* Initialize XP theming and local stuff
*********************************************************/
@@ -461,7 +492,7 @@ void ImplConvertSpinbuttonValues( int nControlPart, const ControlState& rState,
// ----
-sal_Bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
+sal_Bool ImplDrawNativeControl( HWND hWnd, HDC hDC, HTHEME hTheme, RECT rc,
ControlType nType,
ControlPart nPart,
ControlState nState,
@@ -911,12 +942,22 @@ sal_Bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
{
if( nPart == PART_ENTIRE_CONTROL )
{
- if( aValue.getType() == CTRL_MENUBAR )
+ if( ImplGetSVData()->maNWFData.mbTransparentMenubar )
{
- const MenubarValue *pValue = static_cast<const MenubarValue*>(&aValue);
- rc.bottom += pValue->maTopDockingAreaHeight; // extend potential gradient to cover docking area as well
+ // When the frame is correctly extended to the client area,
+ // Aero just needs us to repaint the affected rectangle in black
+ FillRect( hDC, &rc, static_cast< HBRUSH >( GetStockObject( BLACK_BRUSH ) ) );
+ return sal_True;
+ }
+ else
+ {
+ 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);
}
- return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
else if( nPart == PART_MENU_ITEM )
{
@@ -924,6 +965,25 @@ sal_Bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
iState = (nState & CTRL_STATE_SELECTED) ? MBI_HOT : MBI_NORMAL;
else
iState = (nState & CTRL_STATE_SELECTED) ? MBI_DISABLEDHOT : MBI_DISABLED;
+
+ // draw the text glow so that the text is better visible
+ if ( ImplGetSVData()->maNWFData.mbTransparentMenubar )
+ {
+ HTHEME hGlowTheme = getThemeHandle( hWnd, L"TextGlow");
+ if ( !hTheme )
+ return sal_False;
+
+ // I have no idea what is the correct name of the contstant
+ // that is represented by '1' below - but that draws the glow
+ // effect
+ // I've found the "TextGlow" theme handle here:
+ // http://fc01.deviantart.net/fs26/f/2008/154/0/6/Vista_Visual_Style_Classes_by_UkIntel.html
+ // and its rendering here:
+ // http://deskmodder.de/wiki/index.php/Vista_msstyleImage_900-938
+ // No better documentation on the topic, unfortunately :-(
+ ImplDrawTheme( hGlowTheme, hDC, 1, MBI_NORMAL, rc, aCaption );
+ }
+
return ImplDrawTheme( hTheme, hDC, MENU_BARITEM, iState, rc, aCaption );
}
}
@@ -1204,7 +1264,7 @@ sal_Bool WinSalGraphics::drawNativeControl( ControlType nType,
int ta = SetTextAlign( mhDC, TA_LEFT|TA_TOP|TA_NOUPDATECP );
OUString aCaptionStr( aCaption.replace('~', '&') ); // translate mnemonics
- bOk = ImplDrawNativeControl(mhDC, hTheme, rc,
+ bOk = ImplDrawNativeControl(mhWnd, mhDC, hTheme, rc,
nType, nPart, nState, aValue,
aCaptionStr );
@@ -1458,4 +1518,20 @@ void WinSalGraphics::updateSettingsNative( AllSettings& rSettings )
rSettings.SetStyleSettings( aStyleSettings );
}
+void WinSalFrame::extendWindowManagerFrameNative( int nLeft, int nRight, int nTop, int nBottom )
+{
+ // nothing to do for Windows before Vista
+ if( aSalShlData.maVersionInfo.dwMajorVersion < 6 || !vsAPI.IsThemeActive() )
+ return;
+
+ MARGINS aMargins = { nLeft, nRight, nTop, nBottom };
+ HRESULT nRet = vsAPI.DwmExtendFrameIntoClientArea( mhWnd, &aMargins );
+
+ ImplSVData* pSVData = ImplGetSVData();
+ if( nRet == S_OK )
+ pSVData->maNWFData.mbTransparentMenubar = true;
+ else
+ pSVData->maNWFData.mbTransparentMenubar = false;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */