showModal, but click on wxDC in main window Topic is solved

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
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

showModal, but click on wxDC in main window

Post 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!
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

Use Show instead of ShowModal.
Jérémie
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post 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)
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

thanx you, that looks exactly like what i was searching!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post 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.
Post Reply