Detecting clicks outside of Modal Window

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
ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Detecting clicks outside of Modal Window

Post by ninja9578 » Thu Feb 12, 2009 5:59 pm

I want to be able to tell if a user has clicked outside of a modal (descendant of wxDialog) window. Is there a way to do that? I tried connecting a wxEVT_LEFT_DOWN, but that only detects clicks within the modal window itself.

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Thu Feb 12, 2009 6:03 pm

This kind of defeats the point of using a modal dialog. The whole idea is that the user cannot interact with any other part of the program until the modal dialog is dealt with.

Perhaps you should use a modeless dialog instead. Is there any reason why this needs to be a modal dialog?

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Thu Feb 12, 2009 6:35 pm

I have a number of text fields and such, but I can't use wxTextCtrl because there is stuff behind them, which if I just use wxTextCtrl, will draw over it. There are also rotation features and such that means that I can not use wxTextCtrl.

What I do is render the text control with custom stuff so that I can use all of the attributes.

The modal window is just for when I click on it for editing, then I use a regular wxTextCtrl, which is drawn on the modal window with no borders (so it looks like it's part of the background) It has to be a modal window, if it's not it disappears immediately, I'm not sure why. It's either getting drawn over, or being deleted, and I want neither.

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Thu Feb 12, 2009 6:50 pm

Most likely if the window disappears immediately it's because you've created it on the stack versus on the heap and it is destroyed when routine exits.

If you want to create a modeless dialog, create it using new and it should persist until you destroy it.


Jim
OS: Vista SP1, wxWidgets 2.8.7.

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Thu Feb 12, 2009 7:37 pm

:( Could someone explain what I'm doing wrong.

Inside the now non-modal window I have a method called Do(void), which gets called after the program creates the class.

Do simply has a loop in it:

Code: Select all

int TextEntry::Do(void){
   while(!done);
   return 1;
}
done is set to false in the constructor.

'done' gets changed to true in the method that gets called when there is an event on the button enter.

The window doesn't show up, and it crashes the program.


This is exactly what I want: when the program gets a signal that it wants to use the text entry (which is found thorugh various means, but that all works) it creates a wxTextCtrl. Stops and waits for either the text control to receive an enter key or a mousepress outside of it. The sets a string to the contents of the textctrl, then continues on with the program.

The stopping and waiting was why I was using the modal window.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Thu Feb 12, 2009 8:02 pm

If you get a crash, you should use a debugger to find where it crashes.
If you're calling this from the main thread (as you should), know that while(!done) will freeze the program because the event loop can't be accessed anymore while the program flow loops forever.

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Fri Feb 13, 2009 6:28 pm

Oh, well that explains why it was hanging, how do I fix it? The main program flow must wait for the text area to be finished.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Feb 13, 2009 7:31 pm

Well there are multiple ways; the usual way is to use modal dialogs ;) or you can just disable menus or whatever you don't want the user to use

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Tue Feb 17, 2009 1:59 pm

I figured out what I needed to do :)

Post Reply