2 * $Id: main_win.c,v 1.10 2007-11-08 10:46:41 nkeynes Exp $
4 * Define the main (emu) GTK window, along with its menubars,
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #include <sys/types.h>
31 #include "gui/gtkui.h"
34 struct main_window_info {
40 GtkActionGroup *actions;
43 static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
48 static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state,
51 main_window_t win = (main_window_t)userdata;
52 if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
53 gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
54 GtkWidget *frame = gtk_widget_get_parent(win->video);
55 if( frame->style == NULL ) {
56 gtk_widget_set_style( frame, gtk_style_new() );
59 gtk_widget_hide( win->menubar );
60 gtk_widget_hide( win->toolbar );
61 gtk_widget_hide( win->statusbar );
63 frame->style->xthickness = 0;
64 frame->style->ythickness = 0;
66 frame->style->xthickness = 2;
67 frame->style->ythickness = 2;
68 gtk_widget_show( win->menubar );
69 gtk_widget_show( win->toolbar );
70 gtk_widget_show( win->statusbar );
72 gtk_widget_queue_draw( win->window );
76 main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
77 GtkAccelGroup *accel_group )
81 main_window_t win = g_malloc0( sizeof(struct main_window_info) );
83 win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
84 win->menubar = menubar;
85 win->toolbar = toolbar;
86 gtk_window_set_title( GTK_WINDOW(win->window), title );
87 gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
89 gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
91 win->video = gtk_drawing_area_new();
92 GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
93 gtk_widget_set_size_request( win->video, 640, 480 );
94 frame = gtk_frame_new(NULL);
95 gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
96 gtk_container_add( GTK_CONTAINER(frame), win->video );
98 win->statusbar = gtk_statusbar_new();
100 vbox = gtk_vbox_new(FALSE, 0);
101 gtk_container_add( GTK_CONTAINER(win->window), vbox );
102 gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
103 gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
104 gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
105 gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
106 gtk_widget_show_all( win->window );
107 gtk_widget_grab_focus( win->video );
109 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
110 g_signal_connect( win->window, "delete_event",
111 G_CALLBACK(on_main_window_deleted), win );
112 g_signal_connect( win->window, "window-state-event",
113 G_CALLBACK(on_main_window_state_changed), win );
117 void main_window_set_running( main_window_t win, gboolean running )
119 gtk_gui_enable_action( "Pause", running );
120 gtk_gui_enable_action( "Run", !running );
121 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
122 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
125 void main_window_set_framerate( main_window_t win, float rate )
131 void main_window_set_speed( main_window_t win, double speed )
135 snprintf( buf, 32, "Running (%2.4f%%)", speed );
136 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
137 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
142 GtkWidget *main_window_get_renderarea( main_window_t win )
147 GtkWindow *main_window_get_frame( main_window_t win )
149 return GTK_WINDOW(win->window);
152 void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
155 gtk_window_fullscreen( GTK_WINDOW(win->window) );
157 gtk_window_unfullscreen( GTK_WINDOW(win->window) );
.