Wierd Text Disappearing Bug

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Wierd Text Disappearing Bug

Post by Ksmith22 » Thu Jan 26, 2006 8:57 pm

I've come across a wierd bug which seems to be caused by some sort of built-in Windows functionality.

I have a login screen which takes in a username and password via two wxTextCtrls (password of course using wxTE_PASSWORD style). It also contains a few wxPanels that hold text drawn via the OnPaint event (the reason I'm not using wxStaticText control being that I want the transparency behind the text for drawing on top of a graphical background).

Basically what happens is this. If the Capslock key is on while I type in the password box, I get a message bubble warning saying something to the effect of "Capslock is on, this could cause your password to be incorrect". Which is fine. Except as soon as this message bubble disappears, ALL of my text on the frame also disappears!

I'm including the wx/msw/wx.rc resource for Windows XP style, which I'm pretty sure is why this warning bubble is coming up (I checked some older versions before I added it and the bubble never appeared). The bubble itself I don't mind but I definately don't want my text disappearing.

So does anyone have any idea why this would be happening? Or better yet, how to fix it? I don't care if I have to somehow disable that warning bubble, I just don't know how to do that. But it seems wierd that the bubble would wipe all the text I've drawn in other panels.

When I get home I'll upload some pictures to show what I mean.

Edit: I discovered if the window is redrawn (i.e. another window is placed over it and then you go back to it) the text comes back. It's just after that message bubble is dismissed that the text disappears.

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Fri Jan 27, 2006 1:40 am

Here are some pictures of the problem:

Normal appearance:
Image

After entering the password field with Capslock on:
Image

After the warning message disappears:
Image

chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris » Fri Jan 27, 2006 10:05 am

Hi Ksmith22,

just some quick thoughts:

- You are creating a wxPaintDC in you paint handler, aren't you?

- Those baloon tips can only be turned off by a registry key AFAIK.

- If the text is still visible when the baloon tips pops up but gets inivisble as soon as you start typing (is that the way it happens?), you could try to catch wxEVT_COMMAND_TEXT_UPDATED events via EVT_TEXT(id, func) and refresh the whole window as a workaround. Ugly, but could work.

Chris
this->signature=NULL;

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Fri Jan 27, 2006 3:04 pm

chris wrote:Hi Ksmith22,

just some quick thoughts:

- You are creating a wxPaintDC in you paint handler, aren't you?
Yup
- Those baloon tips can only be turned off by a registry key AFAIK.

- If the text is still visible when the baloon tips pops up but gets inivisble as soon as you start typing (is that the way it happens?), you could try to catch wxEVT_COMMAND_TEXT_UPDATED events via EVT_TEXT(id, func) and refresh the whole window as a workaround. Ugly, but could work.

Chris
Yeah, that's the way it happens. I might just put the text directly onto my background image instead. Not what I wanted to do but I don't know how else to fix it.

chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris » Fri Jan 27, 2006 4:28 pm

Did you try to refresh the window if there's input in the textctrl? I think it's worth trying. Text in the background image should be a last resort :D
And maybe you should file a bug on the tracker. This really sounds like a bug to me.
this->signature=NULL;

toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Post by toxicBunny » Fri Jan 27, 2006 4:38 pm

Could you post some code for this dialog showing the constructor, the OnPaint event handler, and how you handle the background image? Maybe it would help to see things in a little more detail...

-Scott
wxMSW 2.6.2, VS 2002, 2003 and 2005, Code::Blocks and mingw, Windows XP Pro

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Fri Jan 27, 2006 6:30 pm

toxicBunny wrote:Could you post some code for this dialog showing the constructor, the OnPaint event handler, and how you handle the background image? Maybe it would help to see things in a little more detail...

-Scott

Code: Select all

CustomPanel::CustomPanel(wxWindow* p, const wxPoint& pos, const wxSize& size,char* n,
						wxString t,wxFont f, wxColour c)
	: wxPanel(p,wxID_ANY,pos,size,0|wxTRANSPARENT_WINDOW|wxTAB_TRAVERSAL,n)
{
	// Define private variables 
	parent = p;
	text = t;
	width = size.GetWidth();
	height = size.GetHeight();
	font = f;
	color = c;
	padding = 0;
	m_draggingWindow = false;
	hasBackground = false;
	isCentered = true;
	hasShadow = false;

	SetBackgroundStyle(wxBG_STYLE_CUSTOM);		// Keep background transparent on redraw
}

Code: Select all

void CustomPanel::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
	wxCoord text_width,text_height;

	wxPaintDC dc(this);
	dc.SetFont(font);
	dc.SetBackgroundMode(wxTRANSPARENT);	// Text background is transparent

	if(hasBackground)						// If panel has a background image, draw it
		dc.DrawBitmap(bgimg, 0, 0, true);

	// If text has a shadow, draw label first in black but offset by 2 pixels
	if(hasShadow)
	{
		dc.SetTextForeground(*wxBLACK);	

		if(isCentered)
		{
			// Get size of text string for centering
			dc.GetTextExtent(text, &text_width, &text_height);	
			// Draw text centered on panel
			dc.DrawText(text,wxPoint(((width-text_width)/2)+2+padding,
									((height-text_height)/2)+2)); 
		}
		else
			dc.DrawText(text,wxPoint(2+padding,2));
	}

	dc.SetTextForeground(color);	

	// If centered, draw centered on panel.  Otherwise, draw left aligned.
	if(isCentered)
	{
		// Get size of text string for centering
		dc.GetTextExtent(text, &text_width, &text_height);
		// Draw text centered on panel
		dc.DrawText(text,wxPoint(((width-text_width)/2)+padding,
									(height-text_height)/2)); 
	}
	else
		dc.DrawText(text,wxPoint(0+padding,0));
}
Those are for the panels holding the text. You can ignore the background and shadow stuff because it isn't used for these particular panels. The actual dialog is a shaped frame pretty much the same as the one in samples other than a few minor changes on my part (but the paint function is the same as the one in samples).

Post Reply