file selection interacting with drawing area



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?





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