Add a toolbar to the Windows GUI
This commit is contained in:
@@ -107,7 +107,7 @@ extern HANDLE ghMutex;
|
||||
extern HICON hIcon[256];
|
||||
extern int dpi;
|
||||
extern RECT oldclip;
|
||||
extern int sbar_height, user_resize;
|
||||
extern int sbar_height, tbar_height, user_resize;
|
||||
extern int acp_utf8;
|
||||
|
||||
// extern int status_is_open;
|
||||
@@ -213,6 +213,11 @@ extern void StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst
|
||||
extern int MediaMenuHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
|
||||
/* Functions in win_toolbar.c */
|
||||
extern HWND hwndRebar;
|
||||
extern void ToolBarCreate(HWND hwndParent, HINSTANCE hInst);
|
||||
|
||||
|
||||
/* Functions in win_dialog.c: */
|
||||
/* Pass NULL in the title param to use the default title. */
|
||||
extern int file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, WCHAR *title, int save);
|
||||
|
@@ -21,7 +21,7 @@ add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_keyboard.c
|
||||
add_library(ui OBJECT win_ui.c win_icon.c win_stbar.c win_sdl.c win_dialog.c win_about.c
|
||||
win_settings.c win_devconf.c win_snd_gain.c win_specify_dim.c win_new_floppy.c
|
||||
win_jsconf.c win_media_menu.c win_preferences.c win_discord.c glad.c win_opengl.c
|
||||
win_opengl_glslp.c 86Box.rc)
|
||||
win_opengl_glslp.c win_toolbar.c 86Box.rc)
|
||||
|
||||
if(NOT CPPTHREADS)
|
||||
target_sources(plat PRIVATE win_thread.c)
|
||||
|
@@ -1118,10 +1118,7 @@ plat_setfullscreen(int on)
|
||||
GetClientRect(hwndMain, &rect);
|
||||
|
||||
temp_x = rect.right - rect.left + 1;
|
||||
if (hide_status_bar)
|
||||
temp_y = rect.bottom - rect.top + 1;
|
||||
else
|
||||
temp_y = rect.bottom - rect.top + 1 - sbar_height;
|
||||
temp_y = rect.bottom - rect.top + 1 - (hide_status_bar ? 0 : sbar_height) - (hide_tool_bar ? 0 : tbar_height);
|
||||
} else {
|
||||
if (dpi_scale) {
|
||||
temp_x = MulDiv((vid_resize & 2) ? fixed_size_x : unscaled_size_x, dpi, 96);
|
||||
@@ -1135,10 +1132,7 @@ plat_setfullscreen(int on)
|
||||
if (vid_resize >= 2)
|
||||
MoveWindow(hwndMain, window_x, window_y, window_w, window_h, TRUE);
|
||||
|
||||
if (hide_status_bar)
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y);
|
||||
else
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + (hide_status_bar ? 0 : sbar_height) + (hide_tool_bar ? 0 : tbar_height));
|
||||
}
|
||||
|
||||
/* Render window. */
|
||||
|
@@ -119,7 +119,7 @@ SpecifyDimensionsDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM
|
||||
temp_y = MulDiv(temp_y, dpi, 96);
|
||||
}
|
||||
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height + tbar_height);
|
||||
|
||||
if (vid_resize) {
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED);
|
||||
|
85
src/win/win_toolbar.c
Normal file
85
src/win/win_toolbar.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#define UNICODE
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Windows.h>
|
||||
#include <CommCtrl.h>
|
||||
#include <86box/86box.h>
|
||||
#include <86box/resource.h>
|
||||
#include <86box/ui.h>
|
||||
#include <86box/win.h>
|
||||
|
||||
HWND hwndRebar;
|
||||
static HWND hwndToolbar;
|
||||
static HIMAGELIST hImageList;
|
||||
|
||||
static TBBUTTON buttons[] = {
|
||||
{ 0, IDM_ACTION_PAUSE, TBSTATE_ENABLED, BTNS_BUTTON, { 0 }, 0, 0 }, // Pause
|
||||
{ 0, 0, TBSTATE_INDETERMINATE, BTNS_SEP, { 0 }, 0, 0 },
|
||||
{ 0, IDM_ACTION_RESET_CAD, TBSTATE_ENABLED, BTNS_BUTTON, { 0 }, 0, 0 }, // Ctrl+Alt+Del
|
||||
{ 0, IDM_ACTION_CTRL_ALT_ESC, TBSTATE_ENABLED, BTNS_BUTTON, { 0 }, 0, 0 }, // Ctrl+Alt+Esc
|
||||
{ 0, IDM_ACTION_HRESET, TBSTATE_ENABLED, BTNS_BUTTON, { 0 }, 0, 0 }, // Hard reset
|
||||
{ 0, 0, TBSTATE_INDETERMINATE, BTNS_BUTTON, { 0 }, 0, 0 }, // ACPI shutdown
|
||||
{ 0, 0, TBSTATE_INDETERMINATE, BTNS_SEP, { 0 }, 0, 0 },
|
||||
{ 0, IDM_CONFIG, TBSTATE_ENABLED, BTNS_BUTTON, { 0 }, 0, 0 } // Settings
|
||||
};
|
||||
|
||||
void
|
||||
ToolBarCreate(HWND hwndParent, HINSTANCE hInst)
|
||||
{
|
||||
REBARINFO rbi = { 0 };
|
||||
REBARBANDINFO rbbi = { 0 };
|
||||
int btnSize;
|
||||
|
||||
// Create the toolbar.
|
||||
hwndToolbar = CreateWindowEx(WS_EX_PALETTEWINDOW, TOOLBARCLASSNAME, NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
|
||||
WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |
|
||||
TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE |
|
||||
CCS_NOPARENTALIGN | CCS_NORESIZE |
|
||||
CCS_NODIVIDER,
|
||||
0, 0, 0, 0,
|
||||
hwndParent, NULL, hInst, NULL);
|
||||
|
||||
// Create the image list.
|
||||
hImageList = ImageList_Create(win_get_system_metrics(SM_CXSMICON, dpi),
|
||||
win_get_system_metrics(SM_CYSMICON, dpi),
|
||||
ILC_MASK | ILC_COLOR32, 1, 1);
|
||||
|
||||
ImageList_AddIcon(hImageList, hIcon[241]);
|
||||
|
||||
SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList);
|
||||
|
||||
// Add buttons.
|
||||
SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
||||
SendMessage(hwndToolbar, TB_ADDBUTTONS, sizeof(buttons) / sizeof(TBBUTTON), (LPARAM) &buttons);
|
||||
|
||||
// Autosize the toolbar and determine its size.
|
||||
btnSize = LOWORD(SendMessage(hwndToolbar, TB_GETBUTTONSIZE, 0,0));
|
||||
|
||||
// Create the containing Rebar.
|
||||
hwndRebar = CreateWindowEx(0, REBARCLASSNAME, NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
|
||||
WS_CLIPCHILDREN | RBS_VARHEIGHT |
|
||||
RBS_BANDBORDERS | CCS_NODIVIDER |
|
||||
CCS_NOPARENTALIGN,
|
||||
0, 0, 0, 0,
|
||||
hwndParent, NULL, hInst, NULL);
|
||||
|
||||
// Create and send the REBARINFO structure.
|
||||
rbi.cbSize = sizeof(rbi);
|
||||
SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi);
|
||||
|
||||
// Add the toolbar to the rebar.
|
||||
rbbi.cbSize = sizeof(rbbi);
|
||||
rbbi.fMask = RBBIM_CHILD | RBBIM_CHILDSIZE;
|
||||
rbbi.hwndChild = hwndToolbar;
|
||||
rbbi.cxMinChild = 0;
|
||||
rbbi.cyMinChild = btnSize;
|
||||
SendMessage(hwndRebar, RB_INSERTBAND, -1, (LPARAM)&rbbi);
|
||||
SendMessage(hwndRebar, RB_MAXIMIZEBAND, 0, 0);
|
||||
|
||||
ShowWindow(hwndRebar, TRUE);
|
||||
|
||||
return;
|
||||
}
|
@@ -58,6 +58,7 @@ HWND hwndMain = NULL, /* application main window */
|
||||
HMENU menuMain; /* application main menu */
|
||||
RECT oldclip; /* mouse rect */
|
||||
int sbar_height = 23; /* statusbar height */
|
||||
int tbar_height = 23; /* toolbar height */
|
||||
int minimized = 0;
|
||||
int infocus = 1, button_down = 0;
|
||||
int rctrl_is_lalt = 0;
|
||||
@@ -658,10 +659,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
temp_y = unscaled_size_y;
|
||||
}
|
||||
|
||||
if (hide_status_bar)
|
||||
ResizeWindowByClientArea(hwnd, temp_x, temp_y);
|
||||
else
|
||||
ResizeWindowByClientArea(hwnd, temp_x, temp_y + sbar_height);
|
||||
ResizeWindowByClientArea(hwnd, temp_x, temp_y + (hide_status_bar ? 0 : sbar_height) + (hide_tool_bar ? 0 : tbar_height));
|
||||
|
||||
if (mouse_capture) {
|
||||
ClipCursor(&rect);
|
||||
@@ -939,6 +937,8 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
dpi = HIWORD(wParam);
|
||||
GetWindowRect(hwndSBAR, &rect);
|
||||
sbar_height = rect.bottom - rect.top;
|
||||
GetWindowRect(hwndRebar, &rect);
|
||||
tbar_height = rect.bottom - rect.top;
|
||||
rect_p = (RECT*)lParam;
|
||||
if (vid_resize == 1)
|
||||
MoveWindow(hwnd, rect_p->left, rect_p->top, rect_p->right - rect_p->left, rect_p->bottom - rect_p->top, TRUE);
|
||||
@@ -951,10 +951,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
/* Main Window. */
|
||||
if (hide_status_bar)
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y);
|
||||
else
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
|
||||
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + (hide_status_bar ? 0 : sbar_height) + (hide_tool_bar ? 0 : tbar_height));
|
||||
} else if (!user_resize)
|
||||
atomic_flag_clear(&doresize);
|
||||
break;
|
||||
@@ -986,12 +983,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if (!(pos->flags & SWP_NOSIZE) || !user_resize) {
|
||||
plat_vidapi_enable(0);
|
||||
|
||||
if (hide_status_bar)
|
||||
MoveWindow(hwndRender, 0, 0, rect.right, rect.bottom, TRUE);
|
||||
else {
|
||||
if (!hide_status_bar)
|
||||
MoveWindow(hwndSBAR, 0, rect.bottom - sbar_height, sbar_height, rect.right, TRUE);
|
||||
MoveWindow(hwndRender, 0, 0, rect.right, rect.bottom - sbar_height, TRUE);
|
||||
}
|
||||
|
||||
if (!hide_tool_bar)
|
||||
MoveWindow(hwndRebar, 0, 0, rect.right, tbar_height, TRUE);
|
||||
|
||||
MoveWindow(hwndRender, 0, hide_tool_bar ? 0 : tbar_height, rect.right, rect.bottom - (hide_status_bar ? 0 : sbar_height) - (hide_tool_bar ? 0 : tbar_height), TRUE);
|
||||
|
||||
GetClientRect(hwndRender, &rect);
|
||||
if (dpi_scale) {
|
||||
@@ -1244,7 +1242,7 @@ ui_init(int nCmdShow)
|
||||
MSG messages = {0}; /* received-messages buffer */
|
||||
HWND hwnd = NULL; /* handle for our window */
|
||||
HACCEL haccel; /* handle to accelerator table */
|
||||
RECT sbar_rect; /* RECT of the status bar */
|
||||
RECT rect;
|
||||
int bRet;
|
||||
TASKDIALOGCONFIG tdconfig = {0};
|
||||
TASKDIALOG_BUTTON tdbuttons[] = {{IDCANCEL, MAKEINTRESOURCE(IDS_2119)}};
|
||||
@@ -1358,11 +1356,20 @@ ui_init(int nCmdShow)
|
||||
StatusBarCreate(hwndMain, IDC_STATUS, hinstance);
|
||||
|
||||
/* Get the actual height of the status bar */
|
||||
GetWindowRect(hwndSBAR, &sbar_rect);
|
||||
sbar_height = sbar_rect.bottom - sbar_rect.top;
|
||||
GetWindowRect(hwndSBAR, &rect);
|
||||
sbar_height = rect.bottom - rect.top;
|
||||
if (hide_status_bar)
|
||||
ShowWindow(hwndSBAR, SW_HIDE);
|
||||
|
||||
/* Create the toolbar window. */
|
||||
ToolBarCreate(hwndMain, hinstance);
|
||||
|
||||
/* Get the actual height of the toolbar */
|
||||
GetWindowRect(hwndRebar, &rect);
|
||||
tbar_height = rect.bottom - rect.top;
|
||||
if (hide_tool_bar)
|
||||
ShowWindow(hwndRebar, SW_HIDE);
|
||||
|
||||
/* Set up main window for resizing if configured. */
|
||||
if (vid_resize == 1)
|
||||
SetWindowLongPtr(hwnd, GWL_STYLE,
|
||||
@@ -1632,10 +1639,7 @@ plat_resize(int x, int y)
|
||||
x = MulDiv(x, dpi, 96);
|
||||
y = MulDiv(y, dpi, 96);
|
||||
}
|
||||
if (hide_status_bar)
|
||||
ResizeWindowByClientArea(hwndMain, x, y);
|
||||
else
|
||||
ResizeWindowByClientArea(hwndMain, x, y + sbar_height);
|
||||
ResizeWindowByClientArea(hwndMain, x, y + (hide_status_bar ? 0 : sbar_height) + (hide_tool_bar ? 0 : tbar_height));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user