Ignore:
Timestamp:
Aug 23, 2010, 3:56:09 AM (10 years ago)
Author:
sam
Message:

Properly implement program termination, including in the GTK program.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gtk/glmapview.cpp

    r169 r170  
    5151     * the timeout value. */
    5252    g_idle_add((GSourceFunc)IdleTickSignal, this);
     53    gtk_quit_add(0, (GtkFunction)ShutdownSignal, this);
    5354
    5455    gtk_signal_connect(GTK_OBJECT(glarea), "realize",
    5556                       GTK_SIGNAL_FUNC(SetupSignal), this);
    56     gtk_signal_connect(GTK_OBJECT(glarea), "destroy",
    57                        GTK_SIGNAL_FUNC(DestroySignal), this);
    5857    gtk_signal_connect(GTK_OBJECT(glarea), "expose_event",
    5958                       GTK_SIGNAL_FUNC(DrawSignal), this);
     
    7675    // FIXME: detect when the map viewer is killed
    7776    mapviewer = new MapViewer(path);
    78 
    79     UpdateAdjustments();
    80 }
    81 
    82 void GlMapView::SetFocus()
    83 {
    84     gtk_widget_grab_focus(glarea);
     77    Ticker::Ref(mapviewer);
     78
     79    UpdateAdjustments();
     80}
     81
     82void GlMapView::CloseMap()
     83{
     84    if (mapviewer)
     85        Ticker::Unref(mapviewer);
     86    mapviewer = NULL;
     87
     88    UpdateAdjustments();
    8589}
    8690
    8791gboolean GlMapView::IdleTick()
    8892{
     93    if (Ticker::Finished())
     94    {
     95        gtk_main_quit();
     96        return FALSE;
     97    }
     98
    8999    // FIXME: do not do anything if the previous tick was too recent?
    90100    ticking = TRUE;
     
    105115{
    106116    /* Set up display */
     117    gtk_widget_grab_focus(glarea);
    107118    if (gtk_gl_area_make_current(GTK_GL_AREA(glarea)))
    108119        Video::Setup(glarea->allocation.width, glarea->allocation.height);
     
    113124}
    114125
    115 gboolean GlMapView::Destroy()
    116 {
    117     g_idle_remove_by_data(this);
     126gboolean GlMapView::Shutdown()
     127{
     128    CloseMap();
     129    Ticker::Shutdown();
     130    /* Hijack the exit process by adding another level of gtk_main */
     131    gtk_widget_set_sensitive(gtk_widget_get_toplevel(glarea), FALSE);
     132    gtk_main();
    118133    return TRUE;
    119134}
     
    240255}
    241256
    242 gboolean GlMapView::DestroySignal(GtkWidget *w, GlMapView *that)
    243 {
    244     (void)w;
    245     return that->Destroy();
     257gboolean GlMapView::ShutdownSignal(GlMapView *that)
     258{
     259    return that->Shutdown();
    246260}
    247261
Note: See TracChangeset for help on using the changeset viewer.