Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 1040:9e3e41eab2db
prev1036:af7b0c5905dd
next1041:5fcc39857c5c
author nkeynes
date Thu Jun 25 21:21:18 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Add quick state bits to the menus
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@435
     3
 *
nkeynes@435
     4
 * Action callbacks from the main window
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@435
    19
#include "dream.h"
nkeynes@450
    20
#include "config.h"
nkeynes@435
    21
#include "dreamcast.h"
nkeynes@435
    22
#include "gdrom/gdrom.h"
nkeynes@537
    23
#include "gtkui/gtkui.h"
nkeynes@455
    24
#include "pvr2/pvr2.h"
nkeynes@543
    25
#include "loader.h"
nkeynes@435
    26
nkeynes@435
    27
nkeynes@887
    28
static void add_file_pattern( GtkFileChooser *chooser, const char *pattern, const char *patname )
nkeynes@435
    29
{
nkeynes@435
    30
    if( pattern != NULL ) {
nkeynes@736
    31
        GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@736
    32
        gtk_file_filter_add_pattern( filter, pattern );
nkeynes@736
    33
        gtk_file_filter_set_name( filter, patname );
nkeynes@736
    34
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@736
    35
        filter = gtk_file_filter_new();
nkeynes@736
    36
        gtk_file_filter_set_name( filter, _("All files") );
nkeynes@736
    37
        gtk_file_filter_add_pattern( filter, "*" );
nkeynes@736
    38
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    39
    }
nkeynes@435
    40
}
nkeynes@435
    41
nkeynes@1034
    42
gchar *open_file_dialog( const char *title, const char *pattern, const char *patname,
nkeynes@1036
    43
                         int initial_dir_key )
nkeynes@435
    44
{
nkeynes@435
    45
    GtkWidget *file;
nkeynes@1034
    46
    gchar *filename = NULL;
nkeynes@1036
    47
nkeynes@435
    48
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    49
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
    50
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    51
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
    52
            NULL );
nkeynes@435
    53
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@1036
    54
    if( initial_dir_key != -1 ) {
nkeynes@1036
    55
        gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
nkeynes@1036
    56
        gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@1036
    57
        g_free(initial_path);
nkeynes@1036
    58
    }
nkeynes@435
    59
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    60
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    61
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    62
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1034
    63
        filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1036
    64
        if( initial_dir_key != -1 ) {
nkeynes@1036
    65
            gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1036
    66
            gui_set_configurable_path(initial_dir_key,end_path);
nkeynes@1036
    67
            g_free(end_path);
nkeynes@1036
    68
        }
nkeynes@477
    69
    }
nkeynes@477
    70
    gtk_widget_destroy(file);
nkeynes@1034
    71
nkeynes@1034
    72
    return filename;
nkeynes@435
    73
}
nkeynes@435
    74
nkeynes@1034
    75
gchar *save_file_dialog( const char *title, const char *pattern, const char *patname,
nkeynes@1036
    76
                         int initial_dir_key )
nkeynes@435
    77
{
nkeynes@435
    78
    GtkWidget *file;
nkeynes@1034
    79
    gchar *filename;
nkeynes@1036
    80
    
nkeynes@435
    81
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    82
            GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@736
    83
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    84
            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@736
    85
            NULL );
nkeynes@435
    86
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@1036
    87
    if( initial_dir_key != -1 ) {
nkeynes@1036
    88
        gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
nkeynes@1036
    89
        gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@1036
    90
        g_free(initial_path);
nkeynes@1036
    91
    }
nkeynes@435
    92
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    93
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    94
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    95
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1034
    96
        filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1036
    97
        if( initial_dir_key != -1 ) {
nkeynes@1036
    98
            gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1036
    99
            gui_set_configurable_path(initial_dir_key,end_path);
nkeynes@1036
   100
            g_free(end_path);
nkeynes@1036
   101
        }
nkeynes@477
   102
    }
nkeynes@477
   103
    gtk_widget_destroy(file);
nkeynes@1034
   104
    return filename;
nkeynes@1034
   105
}
nkeynes@1034
   106
nkeynes@1034
   107
void open_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
nkeynes@1036
   108
                          int initial_dir_key )
nkeynes@1034
   109
{
nkeynes@1036
   110
    gchar *filename = open_file_dialog( title, pattern, patname, initial_dir_key ); 
nkeynes@1034
   111
    if( filename != NULL ) {
nkeynes@1034
   112
        action( filename );
nkeynes@1034
   113
        g_free(filename);
nkeynes@1034
   114
    }
nkeynes@1034
   115
}
nkeynes@1034
   116
nkeynes@1034
   117
void save_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
nkeynes@1036
   118
                          int initial_dir_key )
nkeynes@1034
   119
{
nkeynes@1036
   120
    gchar *filename = save_file_dialog( title, pattern, patname, initial_dir_key );
nkeynes@1034
   121
    if( filename != NULL ) {
nkeynes@1034
   122
        action(filename);
nkeynes@1034
   123
        g_free(filename);
nkeynes@1034
   124
    }
nkeynes@435
   125
}
nkeynes@435
   126
nkeynes@435
   127
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   128
{
nkeynes@1036
   129
    open_file_dialog_cb( "Open...", gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
nkeynes@435
   130
}
nkeynes@435
   131
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   132
{
nkeynes@435
   133
    dreamcast_reset();
nkeynes@435
   134
}
nkeynes@435
   135
nkeynes@435
   136
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   137
{
nkeynes@435
   138
    dreamcast_stop();
nkeynes@435
   139
}
nkeynes@435
   140
nkeynes@435
   141
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   142
{
nkeynes@435
   143
    dreamcast_run();
nkeynes@435
   144
}
nkeynes@435
   145
nkeynes@543
   146
void load_binary_action_callback( GtkAction *action, gpointer user_data)
nkeynes@543
   147
{
nkeynes@1036
   148
    open_file_dialog_cb( "Open Binary...", file_load_magic, NULL, NULL, CONFIG_DEFAULT_PATH );
nkeynes@543
   149
}
nkeynes@543
   150
nkeynes@477
   151
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   152
{
nkeynes@477
   153
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   154
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@736
   155
nkeynes@477
   156
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   157
    if( data != NULL ) {
nkeynes@736
   158
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@736
   159
        GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@736
   160
                GDK_INTERP_BILINEAR);
nkeynes@736
   161
        g_object_unref(pixbuf);
nkeynes@736
   162
        gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@736
   163
        g_object_unref(scaled);
nkeynes@736
   164
        gtk_widget_show(preview);
nkeynes@477
   165
    } else {
nkeynes@736
   166
        gtk_widget_hide(preview);
nkeynes@477
   167
    }
nkeynes@477
   168
}
nkeynes@477
   169
nkeynes@435
   170
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   171
{
nkeynes@477
   172
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   173
    GtkRequisition size;
nkeynes@1036
   174
    const gchar *dir = gui_get_configurable_path(CONFIG_SAVE_PATH);
nkeynes@669
   175
    gchar *path = get_absolute_path(dir);
nkeynes@508
   176
    file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
nkeynes@736
   177
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
   178
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
   179
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
   180
            NULL );
nkeynes@508
   181
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
nkeynes@477
   182
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   183
nkeynes@477
   184
    preview = gtk_image_new( );
nkeynes@477
   185
nkeynes@477
   186
    frame = gtk_frame_new(NULL);
nkeynes@477
   187
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   188
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   189
    gtk_widget_show(frame);
nkeynes@477
   190
    gtk_widget_size_request(frame, &size);
nkeynes@477
   191
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   192
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   193
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   194
    gtk_widget_show( align );
nkeynes@477
   195
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   196
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@736
   197
                      preview );
nkeynes@630
   198
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
nkeynes@477
   199
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   200
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   201
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@736
   202
        gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1036
   203
        gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1036
   204
        gui_set_configurable_path(CONFIG_SAVE_PATH,end_path);
nkeynes@1036
   205
        g_free(end_path);
nkeynes@736
   206
        dreamcast_load_state( filename );
nkeynes@477
   207
    }
nkeynes@477
   208
    gtk_widget_destroy(file);
nkeynes@630
   209
    g_free(path);
nkeynes@435
   210
}
nkeynes@477
   211
nkeynes@435
   212
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   213
{
nkeynes@1036
   214
    save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), CONFIG_SAVE_PATH );
nkeynes@435
   215
}
nkeynes@1040
   216
nkeynes@1040
   217
void quick_state_action_callback( GtkRadioAction *action, GtkRadioAction *current, gpointer user_data)
nkeynes@1040
   218
{
nkeynes@1040
   219
    gint val = gtk_radio_action_get_current_value(action);
nkeynes@1040
   220
    dreamcast_set_quick_state(val);
nkeynes@1040
   221
}
nkeynes@1040
   222
nkeynes@1040
   223
void quick_load_action_callback( GtkAction *action, gpointer user_data)
nkeynes@1040
   224
{
nkeynes@1040
   225
    dreamcast_quick_load();
nkeynes@1040
   226
}
nkeynes@1040
   227
nkeynes@1040
   228
void quick_save_action_callback( GtkAction *action, gpointer user_data)
nkeynes@1040
   229
{
nkeynes@1040
   230
    dreamcast_quick_save();
nkeynes@1040
   231
}
nkeynes@1040
   232
nkeynes@1040
   233
nkeynes@435
   234
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   235
{
nkeynes@736
   236
nkeynes@435
   237
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@736
   238
            "name", APP_NAME, 
nkeynes@738
   239
            "version", lxdream_full_version,
nkeynes@738
   240
            "copyright", lxdream_copyright,
nkeynes@1017
   241
            "logo-icon-name", "lxdream",
nkeynes@736
   242
            NULL);
nkeynes@435
   243
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   244
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   245
    gtk_widget_destroy(dialog);
nkeynes@736
   246
nkeynes@435
   247
}
nkeynes@435
   248
nkeynes@435
   249
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   250
{
nkeynes@671
   251
    dreamcast_shutdown();
nkeynes@435
   252
    exit(0);
nkeynes@435
   253
}
nkeynes@435
   254
nkeynes@447
   255
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   256
{
nkeynes@450
   257
    path_dialog_run();
nkeynes@447
   258
}
nkeynes@447
   259
nkeynes@435
   260
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   261
{
nkeynes@435
   262
}
nkeynes@435
   263
nkeynes@455
   264
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   265
{
nkeynes@455
   266
    maple_dialog_run( );
nkeynes@435
   267
}
nkeynes@435
   268
nkeynes@435
   269
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   270
{
nkeynes@435
   271
}
nkeynes@435
   272
nkeynes@435
   273
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   274
{
nkeynes@435
   275
}
nkeynes@435
   276
nkeynes@1015
   277
void hotkey_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@1015
   278
{
nkeynes@1015
   279
    hotkeys_dialog_run();
nkeynes@1015
   280
}
nkeynes@1015
   281
nkeynes@435
   282
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   283
{
nkeynes@486
   284
    main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
nkeynes@435
   285
}
nkeynes@455
   286
nkeynes@455
   287
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   288
{
nkeynes@455
   289
    gtk_gui_show_debugger();
nkeynes@455
   290
}
nkeynes@455
   291
nkeynes@455
   292
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   293
{
nkeynes@738
   294
    gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Memory dump") );
nkeynes@508
   295
    dump_window_new( title );
nkeynes@508
   296
    g_free(title);
nkeynes@455
   297
}
nkeynes@455
   298
nkeynes@455
   299
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   300
{
nkeynes@455
   301
    gtk_gui_show_mmio();
nkeynes@455
   302
}
nkeynes@455
   303
nkeynes@455
   304
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   305
{
nkeynes@1036
   306
    save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), CONFIG_SAVE_PATH );
nkeynes@455
   307
}
nkeynes@455
   308
nkeynes@480
   309
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   310
nkeynes@455
   311
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   312
{
nkeynes@455
   313
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   314
}
nkeynes@455
   315
nkeynes@455
   316
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   317
{
nkeynes@455
   318
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   319
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   320
    if( selected_row == -1 ) {
nkeynes@508
   321
        WARN( _("No address selected, so can't run to it"), NULL );
nkeynes@455
   322
    } else {
nkeynes@736
   323
        debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@736
   324
        dreamcast_run();
nkeynes@455
   325
    }
nkeynes@455
   326
}
nkeynes@455
   327
nkeynes@455
   328
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   329
{
nkeynes@455
   330
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   331
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   332
    if( selected_row != -1 ) {
nkeynes@736
   333
        debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   334
    }
nkeynes@455
   335
}
.