/* * 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/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> #include <86box/mo.h> #ifndef GWL_WNDPROC #define GWL_WNDPROC GWLP_WNDPROC #endif HWND hwndSBAR; int update_icons = 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 dpi = 96; static int icon_width = 24; /* 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; SendMessage(hwndSBAR, SB_SETICON, found, (LPARAM)hIcon[sb_part_icons[found]]); 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 StatusBarCreateFloppyTip(int part) { WCHAR wtext[512]; WCHAR tempTip[512]; int drive = sb_part_meanings[part] & 0xf; mbstowcs(wtext, fdd_getname(fdd_get_type(drive)), strlen(fdd_getname(fdd_get_type(drive))) + 1); if (wcslen(floppyfns[drive]) == 0) { _swprintf(tempTip, plat_get_string(IDS_2108), drive+1, wtext, plat_get_string(IDS_2057)); } else { _swprintf(tempTip, plat_get_string(IDS_2108), drive+1, wtext, floppyfns[drive]); } 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; 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 (wcslen(cdrom[drive].image_path) == 0) _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); else _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, cdrom[drive].image_path); } 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; 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 (wcslen(zip_drives[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, plat_get_string(IDS_2057)); } else { _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, zip_drives[drive].image_path); } 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; 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 (wcslen(mo_drives[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_2115), drive+1, szText, plat_get_string(IDS_2057)); } else { _swprintf(tempTip, plat_get_string(IDS_2115), drive+1, szText, mo_drives[drive].image_path); } 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_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; 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_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) { int i; int x = win_get_system_metrics(SM_CXSMICON, dpi); for (i=0; i<256; i++) { if (hIcon[i] != 0) DestroyIcon(hIcon[i]); } for (i = 16; i < 18; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 24; i < 26; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 32; i < 34; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 48; i < 50; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 56; i < 58; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 64; i < 66; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 80; i < 82; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 96; i < 98; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 144; i < 146; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 152; i < 154; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 160; i < 162; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 176; i < 178; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 184; i < 186; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 192; i < 194; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); for (i = 243; i < 244; i++) hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); } /* 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