[haiku-3rdparty-dev] Re: Modal dialogs

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Wed, 12 Jun 2013 08:37:18 +0200

Hi,

On 12.06.2013 04:12, Matthew Allen wrote:
All the applications that I've written that use the modal dialog system have 
been based on the premise of blocking the caller until the dialog is closed. 
Often the button pressed it passed back as the return value from 
GDialog::DoModal.

If I change the way it works I would have to re-write hundreds of calls to show 
a dialog across various apps. This is because I originally started writing 
these apps on windows, which works like that. The calling thread blocks until 
your dialog is finished. Yes I should start doing things in a more async 
fashion but I have to keep in mind how it's all going to work on Win/Mac and 
Linux/Gtk. Because the whole thing is cross platform. In the meantime I need to 
support both the Modal and non-Modal methods.

You can do exactly that, and I understand very well why you need it to work that way. I pointed you to the BAlert code which does exactly what you need to do.

The unlock/lock idea is working for the moment. Even if it means using the non 
thread safe CountLocks API.

I don't understand why you need to lock the window that is already blocked. You should probably not Unlock() it. Apparantly, your main window is locked because it is processing an event, which causes it to display a modal dialog, which makes it block until that dialog is done, all the while it is still locked and processing the event in terms of its call stack. So where and why do you need to lock that window from the thread of the modal dialog? Obviously you would need locking to prevent the window thread to access whatever resource concurrently to the modal dialog, but that cannot happen since the window is already blocked waiting for the modal dialog. Hence to need for locking. Some methods however will drop you into the debugger when you call them from the wrong thread, which is probably what happens here. Just go into more detail and we will probably be able to figure something out. :-)

Best regards,
-Stephan


Other related posts: