1. wColour now accepts both grey and gray under MSW

2. implemented setting colours for rich edit controls


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7702 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-07-06 21:34:07 +00:00
parent 97b0241cf2
commit 0119459c53
3 changed files with 168 additions and 118 deletions

View File

@@ -127,6 +127,11 @@ public:
#if wxUSE_RICHEDIT
bool IsRich() const { return m_isRich; }
void SetRichEdit(bool isRich) { m_isRich = isRich; }
// rich edit controls are not compatible with normal ones and wem ust set
// the colours for them otherwise
virtual bool SetBackgroundColour(const wxColour& colour);
virtual bool SetForegroundColour(const wxColour& colour);
#endif // wxUSE_RICHEDIT
virtual void AdoptAttributesFromHWND();

View File

@@ -136,18 +136,13 @@ wxColourDatabase::~wxColourDatabase ()
// Colour database stuff
void wxColourDatabase::Initialize ()
{
// Don't initialize for X: colours are found
// in FindColour below.
// Added: Not all
struct cdef {
wxChar *name;
static const struct wxColourDesc
{
const wxChar *name;
int r,g,b;
};
cdef cc;
static cdef table[]={
// #ifdef __WXMSW__
}
wxColourTable[] =
{
{wxT("AQUAMARINE"),112, 219, 147},
{wxT("BLACK"),0, 0, 0},
{wxT("BLUE"), 0, 0, 255},
@@ -219,23 +214,17 @@ void wxColourDatabase::Initialize ()
{wxT("WHITE"), 255, 255, 255},
{wxT("YELLOW"), 255, 255, 0},
{wxT("YELLOW GREEN"), 153, 204, 50},
// #endif
#if defined(__WXGTK__) || defined(__X__)
{wxT("MEDIUM GOLDENROD"), 234, 234, 173},
{wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
{wxT("LIGHT MAGENTA"), 255, 0, 255},
{wxT("MEDIUM GREY"), 100, 100, 100},
#endif
{0,0,0,0}
};
int i;
for (i=0;cc=table[i],cc.name!=0;i++)
{
Append(cc.name,new wxColour(cc.r,cc.g,cc.b));
}
for ( size_t n = 0; n < WXSIZEOF(wxColourTable); n++ )
{
const wxColourDesc& cc = wxColourTable[n];
Append(cc.name, new wxColour(cc.r,cc.g,cc.b));
}
}
/*
@@ -249,32 +238,43 @@ void wxColourDatabase::Initialize ()
wxColour *wxColourDatabase::FindColour(const wxString& colour)
{
// VZ: make the comparaison case insensitive
wxString str = colour;
str.MakeUpper();
// VZ: make the comparaison case insensitive and also match both grey and
// gray
wxString col = colour;
col.MakeUpper();
wxString col2 = col;
if ( !col2.Replace(_T("GRAY"), _T("GREY")) )
col2.clear();
wxNode *node = Find(str);
if (node)
wxNode *node = First();
while ( node )
{
const wxChar *key = node->GetKeyString();
if ( col == key || col2 == key )
{
return (wxColour *)node->Data();
}
node = node->Next();
}
#ifdef __WXMSW__
else return NULL;
return NULL;
#endif
#ifdef __WXPM__
else return NULL;
return NULL;
#endif
// TODO for other implementations. This should really go into
// platform-specific directories.
#ifdef __WXMAC__
else return NULL;
return NULL;
#endif
#ifdef __WXSTUBS__
else return NULL;
return NULL;
#endif
#ifdef __WXGTK__
else {
wxColour *col = new wxColour( colour );
if (!(col->Ok())) {
@@ -283,11 +283,9 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour)
}
Append( colour, col );
return col;
}
#endif
#ifdef __X__
else {
XColor xcolour;
#ifdef __WXMOTIF__
@@ -311,8 +309,7 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour)
Append(colour, col);
return col;
}
#endif
#endif // __X__
}
wxString wxColourDatabase::FindName (const wxColour& colour) const

View File

@@ -1135,6 +1135,54 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
event.Enable( CanRedo() );
}
// ----------------------------------------------------------------------------
// colour setting for the rich edit controls
// ----------------------------------------------------------------------------
#if wxUSE_RICHEDIT
bool wxTextCtrl::SetBackgroundColour(const wxColour& colour)
{
if ( !wxTextCtrlBase::SetBackgroundColour(colour) )
{
// colour didn't really change
return FALSE;
}
if ( IsRich() )
{
// rich edit doesn't use WM_CTLCOLOR, hence we need to send
// EM_SETBKGNDCOLOR additionally
::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR, 0, wxColourToRGB(colour));
}
return TRUE;
}
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
{
if ( !wxTextCtrlBase::SetForegroundColour(colour) )
{
// colour didn't really change
return FALSE;
}
if ( IsRich() )
{
// change the colour of everything
CHARFORMAT cf;
wxZeroMemory(cf);
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_COLOR;
cf.crTextColor = wxColourToRGB(colour);
::SendMessage(GetHwnd(), EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
}
return TRUE;
}
#endif // wxUSE_RICHEDIT
// ----------------------------------------------------------------------------
// wxRichEditModule
// ----------------------------------------------------------------------------