/* * 86Box A hypervisor and IBM PC system emulator that specializes in * running old operating systems and software designed for IBM * PC systems and compatibles from 1981 through fairly recent * system designs based on the PCI bus. * * This file is part of the 86Box distribution. * * Implement the application's Status Bar. * * * * Authors: Miran Grca, * Fred N. van Kempen, * * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. */ #define UNICODE #define BITMAP WINDOWS_BITMAP #include #include #include #include #undef BITMAP #include #include #include #include #include #include <86box/86box.h> #include <86box/config.h> #include "cpu.h" #include <86box/device.h> #include <86box/machine.h> #include <86box/timer.h> #include <86box/cassette.h> #include <86box/cartridge.h> #include <86box/hdd.h> #include <86box/hdc.h> #include <86box/fdd.h> #include <86box/fdd_86f.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> #include <86box/zip.h> #include <86box/mo.h> #include <86box/cdrom_image.h> #include <86box/scsi_disk.h> #include <86box/network.h> #include <86box/video.h> #include <86box/sound.h> #include <86box/plat.h> #include <86box/ui.h> #include <86box/win.h> #ifndef GWL_WNDPROC #define GWL_WNDPROC GWLP_WNDPROC #endif HWND hwndSBAR; int update_icons = 1, reset_occurred = 1; static LONG_PTR OriginalProcedure; static WCHAR **sbTips; static int *iStatusWidths; static int *sb_part_meanings; static uint8_t *sb_part_icons; static int sb_parts = 0; static int sb_ready = 0; static uint8_t sb_map[256]; static int icon_width = 24; static wchar_t sb_text[512] = L"\0"; static wchar_t sb_bugtext[512] = L"\0"; /* Also used by win_settings.c */ intptr_t fdd_type_to_icon(int type) { int ret = 248; switch(type) { case 0: break; case 1: case 2: case 3: case 4: case 5: case 6: ret = 16; break; case 7: case 8: case 9: case 10: case 11: case 12: case 13: ret = 24; break; default: break; } return(ret); } /* FIXME: should be hdd_count() in hdd.c */ static int hdd_count(int bus) { int c = 0; int i; for (i=0; i= SB_TEXT)) return; found = sb_map[tag]; if ((found != 0xff) && ((sb_part_icons[found] ^ active) & 1) && active) { sb_part_icons[found] |= 1; PostMessage(hwndSBAR, SB_SETICON, found, (LPARAM)hIcon[sb_part_icons[found]]); reset_occurred = 2; SetTimer(hwndMain, 0x8000 | found, 75, NULL); } } /* API: This is for the drive state indicator. */ void ui_sb_update_icon_state(int tag, int state) { uint8_t found = 0xff; if (!sb_ready || ((tag & 0xf0) >= SB_HDD)) return; found = sb_map[tag]; if (found != 0xff) { sb_part_icons[found] &= ~128; sb_part_icons[found] |= (state ? 128 : 0); SendMessage(hwndSBAR, SB_SETICON, found, (LPARAM)hIcon[sb_part_icons[found]]); } } static void StatusBarCreateCassetteTip(int part) { WCHAR tempTip[512]; WCHAR fn[512]; if (strlen(cassette_fname) == 0) _swprintf(tempTip, plat_get_string(IDS_2148), plat_get_string(IDS_2057)); else { mbstoc16s(fn, cassette_fname, sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_2148), fn); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateCartridgeTip(int part) { WCHAR tempTip[512]; WCHAR fn[512]; int drive = sb_part_meanings[part] & 0xf; if (strlen(cart_fns[drive]) == 0) { _swprintf(tempTip, plat_get_string(IDS_2150), drive+1, plat_get_string(IDS_2057)); } else { mbstoc16s(fn, cart_fns[drive], sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_2150), drive+1, fn); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateFloppyTip(int part) { WCHAR wtext[512]; WCHAR tempTip[512]; WCHAR fn[512]; int drive = sb_part_meanings[part] & 0xf; mbstoc16s(wtext, fdd_getname(fdd_get_type(drive)), strlen(fdd_getname(fdd_get_type(drive))) + 1); if (strlen(floppyfns[drive]) == 0) { _swprintf(tempTip, plat_get_string(IDS_2108), drive+1, wtext, plat_get_string(IDS_2057)); } else { mbstoc16s(fn, floppyfns[drive], sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_2108), drive+1, wtext, fn); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateCdromTip(int part) { WCHAR tempTip[512]; WCHAR *szText; WCHAR fn[512]; int id; int drive = sb_part_meanings[part] & 0xf; int bus = cdrom[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); if (cdrom[drive].host_drive == 200) { if (strlen(cdrom[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); } else { mbstoc16s(fn, cdrom[drive].image_path, sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, fn); } } else _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 4); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateZIPTip(int part) { WCHAR tempTip[512]; WCHAR *szText; WCHAR fn[512]; int id; int drive = sb_part_meanings[part] & 0xf; int bus = zip_drives[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); int type = zip_drives[drive].is_250 ? 250 : 100; if (strlen(zip_drives[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, plat_get_string(IDS_2057)); } else { mbstoc16s(fn, zip_drives[drive].image_path, sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, fn); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateMOTip(int part) { WCHAR tempTip[512]; WCHAR *szText; WCHAR fn[512]; int id; int drive = sb_part_meanings[part] & 0xf; int bus = mo_drives[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); if (strlen(mo_drives[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_2115), drive+1, szText, plat_get_string(IDS_2057)); } else { mbstoc16s(fn, mo_drives[drive].image_path, sizeof_w(fn)); _swprintf(tempTip, plat_get_string(IDS_2115), drive+1, szText, fn); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateDiskTip(int part) { WCHAR tempTip[512]; WCHAR *szText; int id; int bus = sb_part_meanings[part] & 0xf; id = IDS_4352 + (bus - 1); szText = plat_get_string(id); _swprintf(tempTip, plat_get_string(IDS_4096), szText); if (sbTips[part] != NULL) free(sbTips[part]); sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateNetworkTip(int part) { WCHAR tempTip[512]; _swprintf(tempTip, plat_get_string(IDS_2069)); if (sbTips[part] != NULL) free(sbTips[part]); sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } static void StatusBarCreateSoundTip(int part) { WCHAR tempTip[512]; _swprintf(tempTip, plat_get_string(IDS_2068)); if (sbTips[part] != NULL) free(sbTips[part]); sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); } /* API */ void ui_sb_update_tip(int meaning) { uint8_t part = 0xff; if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) return; part = sb_map[meaning]; if (part != 0xff) { switch(meaning & 0xf0) { case SB_CASSETTE: StatusBarCreateCassetteTip(part); break; case SB_CARTRIDGE: StatusBarCreateCartridgeTip(part); break; case SB_FLOPPY: StatusBarCreateFloppyTip(part); break; case SB_CDROM: StatusBarCreateCdromTip(part); break; case SB_ZIP: StatusBarCreateZIPTip(part); break; case SB_MO: StatusBarCreateMOTip(part); break; case SB_HDD: StatusBarCreateDiskTip(part); break; case SB_NETWORK: StatusBarCreateNetworkTip(part); break; case SB_SOUND: StatusBarCreateSoundTip(part); break; default: break; } SendMessage(hwndSBAR, SB_SETTIPTEXT, part, (LPARAM)sbTips[part]); } } static void StatusBarDestroyTips(void) { int i; if (sb_parts == 0) return; if (! sbTips) return; for (i=0; i 0) { for (i = 0; i < sb_parts; i++) SendMessage(hwndSBAR, SB_SETICON, i, (LPARAM)NULL); SendMessage(hwndSBAR, SB_SETPARTS, (WPARAM)0, (LPARAM)NULL); if (iStatusWidths) { free(iStatusWidths); iStatusWidths = NULL; } if (sb_part_meanings) { free(sb_part_meanings); sb_part_meanings = NULL; } if (sb_part_icons) { free(sb_part_icons); sb_part_icons = NULL; } StatusBarDestroyTips(); } memset(sb_map, 0xff, sizeof(sb_map)); sb_parts = 0; if (cassette_enable) sb_parts++; if (cart_int) sb_parts += 2; for (i=0; i= (sb_parts - 1)) return; pt.x = id * icon_width; /* Justify to the left. */ pt.y = 0; /* Justify to the top. */ ClientToScreen(hwnd, (LPPOINT) &pt); switch(sb_part_meanings[id] & 0xF0) { case SB_CASSETTE: menu = media_menu_get_cassette(); break; case SB_CARTRIDGE: menu = media_menu_get_cartridge(sb_part_meanings[id] & 0x0F); break; case SB_FLOPPY: menu = media_menu_get_floppy(sb_part_meanings[id] & 0x0F); break; case SB_CDROM: menu = media_menu_get_cdrom(sb_part_meanings[id] & 0x0F); break; case SB_ZIP: menu = media_menu_get_zip(sb_part_meanings[id] & 0x0F); break; case SB_MO: menu = media_menu_get_mo(sb_part_meanings[id] & 0x0F); break; default: return; } TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, pt.x, pt.y, 0, hwndSBAR, NULL); } /* API: Load status bar icons */ void StatusBarLoadIcon(HINSTANCE hInst) { win_load_icon_set(); } /* Handle messages for the Status Bar window. */ #if defined(__amd64__) || defined(__aarch64__) static LRESULT CALLBACK #else static BOOL CALLBACK #endif StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc; POINT pt; int item_id = 0; int i; HINSTANCE hInst; switch (message) { case WM_COMMAND: media_menu_proc(hwnd, message, wParam, lParam); return(0); case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: GetClientRect(hwnd, (LPRECT)& rc); pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); if (PtInRect((LPRECT) &rc, pt)) StatusBarPopupMenu(hwnd, pt, (pt.x / icon_width)); break; case WM_LBUTTONDBLCLK: GetClientRect(hwnd, (LPRECT)& rc); pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); item_id = (pt.x / icon_width); if (PtInRect((LPRECT) &rc, pt) && (item_id < sb_parts)) { if (sb_part_meanings[item_id] == SB_SOUND) SoundGainDialogCreate(hwndMain); } break; case WM_DPICHANGED_AFTERPARENT: /* DPI changed, reload icons */ hInst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE); dpi = win_get_dpi(hwnd); icon_width = MulDiv(SB_ICON_WIDTH, dpi, 96); StatusBarLoadIcon(hInst); for (i=0; i