Re: file selection interacting with drawing area



On Sun, 2006-05-14 at 12:42 -0400, Amadeus W. M. wrote:
> I have an unusual problem. I have a window (MainWindow) which contains a
> drawing area (Darea) and some buttons. The user can draw various things
> with the mouse. E.g. a segment is being drawn/updated continuously when
> the user moves the mouse with button 1 pressed. The final position of the
> segment is recorded when button 1 is released, so there is an
> on_Darea_button_release() callback, which also draws the segment.
> 
> Enter the file selection dialog. When the user selects a file by
> double-clicking, the dialog terminates upon the second button PRESS. The
> event immediately following the second button press is a button RELEASE,
> but that's now caught by the Darea, because the file selector is gone.
> Bad things happen: the Darea, of course, tries to store and draw a segment,
> because on_Darea_button_release() has been called.
> 
> What do I do?
> 
> I'm thinking about introducing a
> 
> bool loading_file;
> 
> which is set to 1 when the file chooser is being popped up,
> and inspected within on_Darea_button_release(): only draw/store the
> segment if and only if loading_file=0; if loading_file happens to be 1,
> set it to 0. Something like this:
> 
> bool on_Darea_button_release(GdkEventButton * ev)
> {
> 
>     if(loading_file){
>        loading_file=0;
>        return 0;
>     }
> 
>     // if we've survived...
> 
>     // set the segment from ev->x, ev->y.
>     Darea.queue_draw(); 
>     return 0;
> }
> 
> This seems awkward and prone to error though. Is there a more natural/Gtk
> way?

I wouldn't make this conditional on the file dialog, since other
dialog(s) added later may cause the same problem.  You just need to keep
track of whether you caught a button press event, and ignore the button
release if you didn't - add an on_Darea_button_press() handler and set a
flag there - then test it in on_Darea_button_release().

Cheers,
Tim





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]