2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id: gui.cc,v 1.23 2001-10-03 13:10:37 bdenney Exp $
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
2001-05-09 00:18:04 +04:00
|
|
|
#include <signal.h>
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
|
|
|
#include "gui/bitmaps/floppya.h"
|
|
|
|
#include "gui/bitmaps/floppyb.h"
|
|
|
|
#include "gui/bitmaps/mouse.h"
|
|
|
|
#include "gui/bitmaps/reset.h"
|
|
|
|
#include "gui/bitmaps/power.h"
|
|
|
|
#include "gui/bitmaps/snapshot.h"
|
2001-09-26 04:15:30 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-04-10 05:04:59 +04:00
|
|
|
# include <Disks.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_gui_c bx_gui;
|
|
|
|
|
|
|
|
#define BX_GUI_THIS bx_gui.
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_GUI_THIS
|
2001-04-10 05:04:59 +04:00
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
bx_gui_c::bx_gui_c(void)
|
|
|
|
{
|
2001-06-27 23:16:01 +04:00
|
|
|
put("GUI"); // Init in specific_init
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
settype(GUILOG);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
bx_gui_c::init(int argc, char **argv, unsigned tilewidth, unsigned tileheight)
|
|
|
|
{
|
|
|
|
specific_init(&bx_gui, argc, argv, tilewidth, tileheight, BX_HEADER_BAR_Y);
|
|
|
|
|
|
|
|
// Define some bitmaps to use in the headerbar
|
|
|
|
BX_GUI_THIS floppyA_bmap_id = create_bitmap(bx_floppya_bmap,
|
|
|
|
BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyA_eject_bmap_id = create_bitmap(bx_floppya_eject_bmap,
|
|
|
|
BX_FLOPPYA_BMAP_X, BX_FLOPPYA_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyB_bmap_id = create_bitmap(bx_floppyb_bmap,
|
|
|
|
BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
|
|
|
|
BX_GUI_THIS floppyB_eject_bmap_id = create_bitmap(bx_floppyb_eject_bmap,
|
|
|
|
BX_FLOPPYB_BMAP_X, BX_FLOPPYB_BMAP_Y);
|
|
|
|
BX_GUI_THIS mouse_bmap_id = create_bitmap(bx_mouse_bmap,
|
|
|
|
BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
|
|
|
|
BX_GUI_THIS nomouse_bmap_id = create_bitmap(bx_nomouse_bmap,
|
|
|
|
BX_MOUSE_BMAP_X, BX_MOUSE_BMAP_Y);
|
|
|
|
|
|
|
|
|
|
|
|
BX_GUI_THIS power_bmap_id = create_bitmap(bx_power_bmap, BX_POWER_BMAP_X, BX_POWER_BMAP_Y);
|
|
|
|
BX_GUI_THIS reset_bmap_id = create_bitmap(bx_reset_bmap, BX_RESET_BMAP_X, BX_RESET_BMAP_Y);
|
|
|
|
BX_GUI_THIS snapshot_bmap_id = create_bitmap(bx_snapshot_bmap, BX_SNAPSHOT_BMAP_X, BX_SNAPSHOT_BMAP_Y);
|
|
|
|
|
|
|
|
|
|
|
|
// Add the initial bitmaps to the headerbar, and enable callback routine, for use
|
|
|
|
// when that bitmap is clicked on
|
|
|
|
|
|
|
|
// Floppy A:
|
|
|
|
BX_GUI_THIS floppyA_status = bx_devices.floppy->get_media_status(0);
|
|
|
|
if (BX_GUI_THIS floppyA_status)
|
|
|
|
BX_GUI_THIS floppyA_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyA_bmap_id,
|
|
|
|
BX_GRAVITY_LEFT, floppyA_handler);
|
|
|
|
else
|
|
|
|
BX_GUI_THIS floppyA_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyA_eject_bmap_id,
|
|
|
|
BX_GRAVITY_LEFT, floppyA_handler);
|
|
|
|
|
|
|
|
// Floppy B:
|
|
|
|
BX_GUI_THIS floppyB_status = bx_devices.floppy->get_media_status(1);
|
|
|
|
if (BX_GUI_THIS floppyB_status)
|
|
|
|
BX_GUI_THIS floppyB_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyB_bmap_id,
|
|
|
|
BX_GRAVITY_LEFT, floppyB_handler);
|
|
|
|
else
|
|
|
|
BX_GUI_THIS floppyB_hbar_id = headerbar_bitmap(BX_GUI_THIS floppyB_eject_bmap_id,
|
|
|
|
BX_GRAVITY_LEFT, floppyB_handler);
|
|
|
|
|
|
|
|
// Mouse button
|
2001-06-20 18:01:39 +04:00
|
|
|
if (bx_options.Omouse_enabled->get ())
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS mouse_bmap_id,
|
2001-06-23 07:18:14 +04:00
|
|
|
BX_GRAVITY_LEFT, toggle_mouse_enable);
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
|
|
|
BX_GUI_THIS mouse_hbar_id = headerbar_bitmap(BX_GUI_THIS nomouse_bmap_id,
|
2001-06-23 07:18:14 +04:00
|
|
|
BX_GRAVITY_LEFT, toggle_mouse_enable);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// Power button
|
|
|
|
BX_GUI_THIS power_hbar_id = headerbar_bitmap(BX_GUI_THIS power_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, power_handler);
|
|
|
|
// Reset button
|
|
|
|
BX_GUI_THIS reset_hbar_id = headerbar_bitmap(BX_GUI_THIS reset_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, reset_handler);
|
|
|
|
// Snapshot button
|
|
|
|
BX_GUI_THIS snapshot_hbar_id = headerbar_bitmap(BX_GUI_THIS snapshot_bmap_id,
|
|
|
|
BX_GRAVITY_RIGHT, snapshot_handler);
|
|
|
|
|
|
|
|
show_headerbar();
|
|
|
|
}
|
|
|
|
|
2001-09-28 10:03:40 +04:00
|
|
|
void
|
|
|
|
bx_gui_c::update_floppy_status_buttons (void) {
|
|
|
|
BX_GUI_THIS floppyA_status =
|
|
|
|
bx_devices.floppy->get_media_status (0)
|
|
|
|
&& bx_options.floppya.Oinitial_status->get ();
|
|
|
|
BX_GUI_THIS floppyB_status =
|
|
|
|
bx_devices.floppy->get_media_status (1)
|
|
|
|
&& bx_options.floppyb.Oinitial_status->get ();
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_GUI_THIS floppyA_status)
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_bmap_id);
|
|
|
|
else {
|
2001-09-26 04:15:30 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-04-10 05:04:59 +04:00
|
|
|
// If we are using the Mac floppy driver, eject the disk
|
2001-09-26 04:15:30 +04:00
|
|
|
// from the floppy drive. This doesn't work in MacOS X.
|
2001-06-21 18:56:43 +04:00
|
|
|
if (!strcmp(bx_options.floppya.Opath->get (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
DiskEject(1);
|
|
|
|
#endif
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyA_hbar_id, BX_GUI_THIS floppyA_eject_bmap_id);
|
|
|
|
}
|
2001-09-28 10:03:40 +04:00
|
|
|
if (BX_GUI_THIS floppyB_status)
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_bmap_id);
|
|
|
|
else {
|
|
|
|
#if BX_WITH_MACOS
|
|
|
|
// If we are using the Mac floppy driver, eject the disk
|
|
|
|
// from the floppy drive. This doesn't work in MacOS X.
|
|
|
|
if (!strcmp(bx_options.floppyb.Opath->get (), SuperDrive))
|
|
|
|
DiskEject(1);
|
|
|
|
#endif
|
|
|
|
replace_bitmap(BX_GUI_THIS floppyB_hbar_id, BX_GUI_THIS floppyB_eject_bmap_id);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-09-28 10:03:40 +04:00
|
|
|
bx_gui_c::floppyA_handler(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-09-28 10:03:40 +04:00
|
|
|
BX_GUI_THIS floppyA_status = !BX_GUI_THIS floppyA_status;
|
|
|
|
bx_devices.floppy->set_media_status(0, BX_GUI_THIS floppyA_status);
|
|
|
|
BX_GUI_THIS update_floppy_status_buttons ();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-09-28 10:03:40 +04:00
|
|
|
void
|
|
|
|
bx_gui_c::floppyB_handler(void)
|
|
|
|
{
|
|
|
|
BX_GUI_THIS floppyB_status = !BX_GUI_THIS floppyB_status;
|
|
|
|
bx_devices.floppy->set_media_status(1, BX_GUI_THIS floppyB_status);
|
|
|
|
BX_GUI_THIS update_floppy_status_buttons ();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_gui_c::reset_handler(void)
|
|
|
|
{
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "system RESET callback." ));
|
2001-05-25 18:21:46 +04:00
|
|
|
bx_pc_system.ResetSignal( PCS_SET ); /* XXX is this right? */
|
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS; i++)
|
|
|
|
BX_CPU(i)->reset(BX_RESET_HARDWARE);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_gui_c::power_handler(void)
|
|
|
|
{
|
2001-06-15 22:01:52 +04:00
|
|
|
// the user pressed power button, so there's no doubt they want bochs
|
|
|
|
// to quit. Change panics to fatal for the GUI and then do a panic.
|
|
|
|
LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL);
|
|
|
|
BX_PANIC (("POWER button turned off."));
|
|
|
|
// shouldn't reach this point, but if you do, QUIT!!!
|
|
|
|
fprintf (stderr, "Bochs is exiting because you pressed the power button.\n");
|
2001-06-08 07:07:51 +04:00
|
|
|
::exit (1);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_gui_c::snapshot_handler(void)
|
|
|
|
{
|
2001-06-11 10:48:37 +04:00
|
|
|
#if BX_USE_CONTROL_PANEL
|
2001-06-10 00:01:12 +04:00
|
|
|
bx_control_panel (BX_CPANEL_RUNTIME);
|
2001-06-11 10:48:37 +04:00
|
|
|
#else
|
|
|
|
BX_INFO(( "# SNAPSHOT callback (unimplemented)." ));
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-06-23 07:18:14 +04:00
|
|
|
bx_gui_c::toggle_mouse_enable(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-06-20 18:01:39 +04:00
|
|
|
int old = bx_options.Omouse_enabled->get ();
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG (("toggle mouse_enabled, now %d", !old));
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Omouse_enabled->set (!old);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-06-17 03:08:32 +04:00
|
|
|
bx_gui_c::mouse_enabled_changed (Boolean val)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-06-23 07:18:14 +04:00
|
|
|
// This is only called when SIM->get_init_done is 1. Note that VAL
|
|
|
|
// is the new value of mouse_enabled, which may not match the old
|
|
|
|
// value which is still in bx_options.Omouse_enabled->get ().
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG (("replacing the mouse bitmaps"));
|
2001-06-17 03:08:32 +04:00
|
|
|
if (val)
|
2001-06-10 00:01:12 +04:00
|
|
|
replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS mouse_bmap_id);
|
|
|
|
else
|
|
|
|
replace_bitmap(BX_GUI_THIS mouse_hbar_id, BX_GUI_THIS nomouse_bmap_id);
|
2001-06-23 07:18:14 +04:00
|
|
|
// give the GUI a chance to respond to the event. Most guis will hide
|
|
|
|
// the native mouse cursor and do something to trap the mouse inside the
|
|
|
|
// bochs VGA display window.
|
|
|
|
mouse_enabled_changed_specific (val);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-05-09 00:18:04 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
bx_gui_c::init_signal_handlers ()
|
|
|
|
{
|
|
|
|
#if BX_GUI_SIGHANDLER
|
|
|
|
Bit32u mask = get_sighandler_mask ();
|
|
|
|
for (Bit32u sig=0; sig<32; sig++)
|
|
|
|
{
|
|
|
|
if (mask & (1<<sig))
|
|
|
|
signal (sig, bx_signal_handler);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|