Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxSearchCtrl color mismatch with ChangeValue #12798

Closed
wxtrac opened this issue Dec 23, 2010 · 4 comments
Closed

wxSearchCtrl color mismatch with ChangeValue #12798

wxtrac opened this issue Dec 23, 2010 · 4 comments
Labels

Comments

@wxtrac
Copy link
Collaborator

wxtrac commented Dec 23, 2010

Issue migrated from trac ticket # 12798

component: GUI-generic | priority: normal | resolution: fixed | keywords: wxSearchCtrl

2010-12-23 23:13:51: jim22k (Jim Kitchen) created the issue


When the ChangeValue(new_text) method is called on an empty wxSearchCtrl, the control is updated with new_text, but it remains in the lighter text reserved for the Descriptive Text. Editing the text continues to use the lighter colored text until the SearchCtrl is cleared and loses focus.

If the user has manually typed in the SearchCtrl first, calling ChangeValue(new_text) works correctly. This is only a problem when the SearchCtrl is empty and the lighter Descriptive Text is being displayed.

A workaround solution for wxPython was given by Robin Dunn in the following conversation:
http://groups.google.com/group/wxpython-users/browse_thread/thread/6e999b3013e383f6

wxPython code showing the problem and workaround is attached.

The correct solution, rather than using a workaround, is to have the SearchCtrl handle the text color itself when either ChangeValue() or SetValue() is called.

@wxtrac
Copy link
Collaborator Author

wxtrac commented Dec 23, 2010

2010-12-23 23:14:32: jim22k (Jim Kitchen) uploaded file SearchCtrl_problem.py (2.2 KiB)

wxPython code showing the problem and a temporary workaround

@wxtrac
Copy link
Collaborator Author

wxtrac commented Dec 25, 2010

2010-12-25 14:31:24: @vadz changed status from new to closed

2010-12-25 14:31:24: @vadz set resolution to outdated

2010-12-25 14:31:24: @vadz commented

If this was under MSW, I'm almost sure this was fixed in the trunk already. Can you please retest with wxPython 2.9? If it's still present please reopen and give details about your platform, thanks.

@wxtrac
Copy link
Collaborator Author

wxtrac commented Dec 27, 2010

2010-12-27 15:45:18: jim22k (Jim Kitchen) changed status from closed to reopened

2010-12-27 15:45:18: jim22k (Jim Kitchen) changed resolution from outdated to **

2010-12-27 15:45:18: jim22k (Jim Kitchen) commented

Yes, this is MSW. I just tested with the 2.9.1.1 wxPython Windows binary and the problem is still there.

I've shown the problem spot in the source code below (wx/wxWidgets/trunk/src/generic/srchctlg.cpp). Changes to the text color (lightness) only occur in two places:
(1) On an Idle event when the SearchCtrl doesn't have focus and it's empty. For this case, the text is lightened and set to the DescriptiveText
(2) When it receives Focus and the text == the DescriptiveText. For this case, the text color is changed back to the original color (darker).

But if the text is currently light (i.e. showing the DescriptiveText) and the user calls ChangeValue() on the SearchCtrl, it updates the text but leaves it a lighter color. And when the user clicks in the SearchCtrl, it gets Focus, but the text != the Descriptive Text, so it still doesn't change the text color back to the original. That's the bug. wxSearchCtrl needs to override the ChangeValue() and SetValue() methods to ensure that the text color is correct (m_defaultFG).

131 void OnIdle(wxIdleEvent& WXUNUSED(event))
132 {
133 if ( IsEmpty() && !(wxWindow::FindFocus() == this) )
134 {
135 ChangeValue(m_descriptiveText);
136 SetInsertionPoint(0);
137 SetForegroundColour(m_defaultFG.ChangeLightness (LIGHT_STEP));
138 }
139 }
140
141 void OnFocus(wxFocusEvent& event)
142 {
143 event.Skip();
144 if ( GetValue() == m_descriptiveText )
145 {
146 ChangeValue(wxEmptyString);
147 SetForegroundColour(m_defaultFG);
148 }
149 }

@wxtrac
Copy link
Collaborator Author

wxtrac commented Jul 23, 2011

2011-07-23 14:54:02: @vadz changed status from reopened to closed

2011-07-23 14:54:02: @vadz changed resolution from ** to fixed

2011-07-23 14:54:02: @vadz commented

This should have been fixed as a side effect of 68237, please reopen if you still see any problems with 2.9.3.

@wxtrac wxtrac closed this as completed Jul 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant