Re: [gtk-list] Re: XmUpdateDisplay equivalent?



On Tue, 2 Jun 1998, Johannes Keukelaar wrote:

> //while ( gtk_events_pending() ) {
> //  gtk_main_iteration();
> //}
> 
> For me, that worked. _However_, this also processes stuff like mouse button 
> clicks, so that the user can run around clicking on various buttons and the 
> like, causing other user callbacks to be called. This is an open invitation to 
> disaster. (I know it caused disaster in my application.)

Just a suggestion! How about working with a state variable? Let's say you
have a sort function, which lasts a while and which would cause problems
to your app, if called twice. I would do it this way:

function mysort(...)
{
  if (sorting) return; /* sorting is a global or static local bool
                       variable with init to FALSE */
  sorting = TRUE;
  while (not sorted) {
    ...sort...;
    while (gtk_event_pending() gtk_main_iteration();
}
  sorting = FALSE;
}

So you can handle all events. If the user clicks the menuitem to call your
sort function, it will be executed, if not already called. If the sorting
is in progress (sorting == TRUE), the function will exit immediatly! The
test could be made in every function (if sorting is declared global),
which will be affected or will affect the sort function.

Just my 0.02

Regards
Karsten



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