Page 1 of 1

showModal, but click on wxDC in main window

Posted: Wed Feb 16, 2011 10:35 am
by mael15
hi everyone,

i open a dialog via showModal and within that dialog, i want to activate a possibility to click on a wxDC in the main application. the problem is, I still want to disable clicking on anything else but the wxDC outside of the dialog. is there some way to make an exception to showModal or some way other than temporarily disabling every control in the main app by hand?

thanx!

Posted: Wed Feb 16, 2011 12:04 pm
by jfouche
Use Show instead of ShowModal.

Posted: Wed Feb 16, 2011 12:39 pm
by mael15
yeah, thanx, but i want the user to be able to access ONLY the wxDC, not the rest of the application. so is it the only way to use show() and then disable every other input option than the wxDC by hand?

Posted: Wed Feb 16, 2011 2:52 pm
by doublemax
Just for clarification: You can't click on a wxDC. A device context is more like an abstract concept to draw on something. You always click on a wxWindow or derived class.

wxWindowDisabler could do the disabling work for you:
http://docs.wxwidgets.org/stable/wx_wxw ... owdisabler

Another option could be to keep working with a modal dialog, but capture all mouse events and detect clicks on the other window yourself.
http://docs.wxwidgets.org/stable/wx_wxw ... pturemouse
And you'd need this:
http://docs.wxwidgets.org/stable/wx_wxw ... entoclient

(Just an idea, don't know if this works)

Posted: Wed Feb 16, 2011 2:54 pm
by mael15
thanx you, that looks exactly like what i was searching!

Posted: Fri Feb 18, 2011 12:01 pm
by mael15
for those with this problem, wxWindowDisabler did not work, because i wanted to have an underlying nested wxWindow handle mouse clicks. wxWindowDisabler disables all of the parents of the nested window, so no mouse click came through.

the solution was to recursively disable all parents and all of their children, excluding only the parents of the nested window.

beginning in the nested wxWindow, which also has children i wanted to disable:

Code: Select all

void recursivelyDisEnableAllParents( bool enable )
{
wxWindow *curWin = this;
wxWindow *child = childOfNestedWindowRemainingActive;

while(curWin != NULL){
	for(unsigned int i = 0; i < curWin->GetChildren().GetCount(); i++){
		wxWindow *win = curWin->GetChildren().Item(i)->GetData();
		if(win != child)
			win->Enable(enable);
	}
	child = curWin;
	curWin = curWin->GetParent();
}
}
i also use the same function for reenabling everything later.