Added wxBORDER_THEME and made wxTextCtrl and wxSearchCtrl show the correct borders. Because

we can't add virtual functions because of binary compatibility considerations, we can't make
controls intelligent enough to know when they need themed borders. So in 2.8 we have to add
wxBORDER_THEME explicitly where necessary.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@47930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2007-08-07 19:40:08 +00:00
parent 931e5c417c
commit 2ee1e5bbb0
4 changed files with 125 additions and 9 deletions

View File

@@ -1295,7 +1295,8 @@ enum wxBorder
wxBORDER_SIMPLE = 0x02000000, wxBORDER_SIMPLE = 0x02000000,
wxBORDER_RAISED = 0x04000000, wxBORDER_RAISED = 0x04000000,
wxBORDER_SUNKEN = 0x08000000, wxBORDER_SUNKEN = 0x08000000,
wxBORDER_DOUBLE = 0x10000000, wxBORDER_DOUBLE = 0x10000000, /* deprecated */
wxBORDER_THEME = 0x10000000,
/* a mask to extract border style from the combination of flags */ /* a mask to extract border style from the combination of flags */
wxBORDER_MASK = 0x1f200000 wxBORDER_MASK = 0x1f200000

View File

@@ -30,6 +30,10 @@
#include "wx/image.h" #include "wx/image.h"
#if defined(__WXMSW__) && wxUSE_UXTHEME
#include "wx/msw/uxtheme.h"
#endif
#define WXMAX(a,b) ((a)>(b)?(a):(b)) #define WXMAX(a,b) ((a)>(b)?(a):(b))
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -321,11 +325,16 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
#ifdef __WXGTK__ int borderStyle = wxBORDER_SIMPLE;
if ( !wxTextCtrlBase::Create(parent, id, pos, size, wxSUNKEN_BORDER | (style & ~wxBORDER_MASK), validator, name) )
#else #if defined(__WXMSW__) && wxUSE_UXTHEME && !(defined(__POCKETPC__) || defined(__SMARTPHONE__))
if ( !wxTextCtrlBase::Create(parent, id, pos, size, wxSIMPLE_BORDER | (style & ~wxBORDER_MASK), validator, name) ) if (wxUxThemeEngine::GetIfActive())
borderStyle = wxBORDER_THEME;
#elif defined(__WXGTK__)
borderStyle = wxBORDER_SUNKEN;
#endif #endif
if ( !wxTextCtrlBase::Create(parent, id, pos, size, borderStyle | (style & ~wxBORDER_MASK), validator, name) )
{ {
return false; return false;
} }

View File

@@ -303,6 +303,10 @@ bool wxTextCtrl::Create(wxWindow *parent,
#ifdef __WXWINCE__ #ifdef __WXWINCE__
if ((style & wxBORDER_MASK) == 0) if ((style & wxBORDER_MASK) == 0)
style |= wxBORDER_SIMPLE; style |= wxBORDER_SIMPLE;
#else
// Standard text control already handles theming
if ((style & (wxTE_RICH|wxTE_RICH2)) && ((style & wxBORDER_MASK) == wxBORDER_DEFAULT))
style |= wxBORDER_THEME;
#endif #endif
// base initialization // base initialization

View File

@@ -120,6 +120,18 @@
#endif #endif
#endif #endif
#if wxUSE_UXTHEME
#include "wx/msw/uxtheme.h"
#define EP_EDITTEXT 1
#define ETS_NORMAL 1
#define ETS_HOT 2
#define ETS_SELECTED 3
#define ETS_DISABLED 4
#define ETS_FOCUSED 5
#define ETS_READONLY 6
#define ETS_ASSIST 7
#endif
#if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
#define HAVE_TRACKMOUSEEVENT #define HAVE_TRACKMOUSEEVENT
#endif // everything needed for TrackMouseEvent() #endif // everything needed for TrackMouseEvent()
@@ -1378,6 +1390,7 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
case wxBORDER_NONE: case wxBORDER_NONE:
case wxBORDER_SIMPLE: case wxBORDER_SIMPLE:
case wxBORDER_THEME:
break; break;
case wxBORDER_STATIC: case wxBORDER_STATIC:
@@ -1393,9 +1406,9 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
style &= ~WS_BORDER; style &= ~WS_BORDER;
break; break;
case wxBORDER_DOUBLE: // case wxBORDER_DOUBLE:
*exstyle |= WS_EX_DLGMODALFRAME; // *exstyle |= WS_EX_DLGMODALFRAME;
break; // break;
} }
// wxUniv doesn't use Windows dialog navigation functions at all // wxUniv doesn't use Windows dialog navigation functions at all
@@ -3234,6 +3247,95 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
} }
break; break;
#endif // __WXWINCE__ #endif // __WXWINCE__
#if wxUSE_UXTHEME
// If we want the default themed border then we need to draw it ourselves
case WM_NCCALCSIZE:
{
wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
if (theme && GetBorder() == wxBORDER_THEME)
{
// first ask the widget to calculate the border size
rc.result = MSWDefWindowProc(message, wParam, lParam);
processed = true;
// now alter the client size making room for drawing a themed border
NCCALCSIZE_PARAMS *csparam = NULL;
RECT rect;
if (wParam)
{
csparam = (NCCALCSIZE_PARAMS*)lParam;
rect = csparam->rgrc[0];
}
else
{
rect = *((RECT*)lParam);
}
wxUxThemeHandle hTheme(this, L"EDIT");
RECT rcClient = { 0, 0, 0, 0 };
wxClientDC dc(this);
if (theme->GetThemeBackgroundContentRect(
hTheme, GetHdcOf(dc), EP_EDITTEXT, ETS_NORMAL,
&rect, &rcClient) == S_OK)
{
InflateRect(&rcClient, -1, -1);
if (wParam)
csparam->rgrc[0] = rcClient;
else
*((RECT*)lParam) = rcClient;
rc.result = WVR_REDRAW;
}
}
}
break;
case WM_NCPAINT:
{
wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
if (theme && GetBorder() == wxBORDER_THEME)
{
// first ask the widget to paint its non-client area, such as scrollbars, etc.
rc.result = MSWDefWindowProc(message, wParam, lParam);
processed = true;
wxUxThemeHandle hTheme(this, L"EDIT");
wxWindowDC dc(this);
// Clip the DC so that you only draw on the non-client area
RECT rcBorder;
wxCopyRectToRECT(GetSize(), rcBorder);
RECT rcClient;
theme->GetThemeBackgroundContentRect(
hTheme, GetHdcOf(dc), EP_EDITTEXT, ETS_NORMAL, &rcBorder, &rcClient);
InflateRect(&rcClient, -1, -1);
::ExcludeClipRect(GetHdcOf(dc), rcClient.left, rcClient.top,
rcClient.right, rcClient.bottom);
// Make sure the background is in a proper state
if (theme->IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL))
{
theme->DrawThemeParentBackground(GetHwnd(), GetHdcOf(dc), &rcBorder);
}
// Draw the border
int nState;
if ( !IsEnabled() )
nState = ETS_DISABLED;
// should we check this?
//else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
// nState = ETS_READONLY;
else
nState = ETS_NORMAL;
theme->DrawThemeBackground(hTheme, GetHdcOf(dc), EP_EDITTEXT, nState, &rcBorder, NULL);
}
}
break;
#endif // wxUSE_UXTHEME
} }
if ( !processed ) if ( !processed )
@@ -5791,7 +5893,7 @@ static inline bool wxIsKeyDown(WXWORD vk)
switch (vk) switch (vk)
{ {
case VK_LBUTTON: case VK_LBUTTON:
if (GetSystemMetrics(SM_SWAPBUTTON)) vk = VK_RBUTTON; if (GetSystemMetrics(SM_SWAPBUTTON)) vk = VK_RBUTTON;
break; break;
case VK_RBUTTON: case VK_RBUTTON:
if (GetSystemMetrics(SM_SWAPBUTTON)) vk = VK_LBUTTON; if (GetSystemMetrics(SM_SWAPBUTTON)) vk = VK_LBUTTON;