Windows port: add a base CToolWindow class and a toolwindow handler.
This commit is contained in:
parent
54f771536e
commit
998787e921
|
@ -20,8 +20,27 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CWindow.h"
|
#include "CWindow.h"
|
||||||
|
#include "IORegView.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
DWORD GetFontQuality()
|
||||||
|
{
|
||||||
|
BOOL aaEnabled = FALSE;
|
||||||
|
UINT aaType = FE_FONTSMOOTHINGSTANDARD;
|
||||||
|
|
||||||
|
SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &aaEnabled, 0);
|
||||||
|
if (aaEnabled == FALSE)
|
||||||
|
return NONANTIALIASED_QUALITY;
|
||||||
|
|
||||||
|
if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &aaType, 0) == FALSE)
|
||||||
|
return ANTIALIASED_QUALITY;
|
||||||
|
|
||||||
|
if (aaType == FE_FONTSMOOTHINGCLEARTYPE)
|
||||||
|
return CLEARTYPE_QUALITY;
|
||||||
|
else
|
||||||
|
return ANTIALIASED_QUALITY;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Window class handling
|
// Window class handling
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -56,7 +75,7 @@ bool RegWndClass(string name, WNDPROC wndProc, UINT style, HICON icon, int extra
|
||||||
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
||||||
wc.style = style;
|
wc.style = style;
|
||||||
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
||||||
wc.cbWndExtra = extraSize;
|
wc.cbWndExtra = 8 + extraSize;
|
||||||
wc.hIconSm = 0;
|
wc.hIconSm = 0;
|
||||||
|
|
||||||
if (RegisterClassEx(&wc) != 0)
|
if (RegisterClassEx(&wc) != 0)
|
||||||
|
@ -78,8 +97,124 @@ void UnregWndClass(string name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise unreg the class and remove its name from the list
|
// Otherwise unreg the class and remove its name from the list
|
||||||
UnregisterClass(name.c_str(), hAppInst);
|
// ONLY if unregging was successful. Unregging will fail if one
|
||||||
ReggedWndClasses.erase(it);
|
// or more windows using the class still exist.
|
||||||
|
if (UnregisterClass(name.c_str(), hAppInst) != 0)
|
||||||
|
ReggedWndClasses.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Base toolwindow class
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CToolWindow::CToolWindow(int ID, DLGPROC proc, char* title)
|
||||||
|
: hWnd(NULL)
|
||||||
|
{
|
||||||
|
hWnd = CreateDialogParam(hAppInst, MAKEINTRESOURCE(ID), HWND_DESKTOP, proc, (LPARAM)this);
|
||||||
|
if (hWnd == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetWindowText(hWnd, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
CToolWindow::~CToolWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Toolwindow handling
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CToolWindow* ToolWindowList = NULL;
|
||||||
|
|
||||||
|
bool OpenToolWindow(CToolWindow* wnd)
|
||||||
|
{
|
||||||
|
// A hWnd value of NULL indicates failure to create the window.
|
||||||
|
// In this case, just delete the toolwindow and return failure.
|
||||||
|
if (wnd->hWnd == NULL)
|
||||||
|
{
|
||||||
|
delete wnd;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the toolwindow to the list
|
||||||
|
if (ToolWindowList == NULL)
|
||||||
|
{
|
||||||
|
ToolWindowList = wnd;
|
||||||
|
wnd->prev = NULL;
|
||||||
|
wnd->next = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wnd->prev = NULL;
|
||||||
|
wnd->next = ToolWindowList;
|
||||||
|
wnd->next->prev = wnd;
|
||||||
|
ToolWindowList = wnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the toolwindow (otherwise it won't show :P )
|
||||||
|
wnd->Show();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseToolWindow(CToolWindow* wnd)
|
||||||
|
{
|
||||||
|
// Remove the toolwindow from the list
|
||||||
|
if (wnd == ToolWindowList)
|
||||||
|
{
|
||||||
|
ToolWindowList = wnd->next;
|
||||||
|
if (wnd->next) wnd->next->prev = NULL;
|
||||||
|
wnd->next = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wnd->prev->next = wnd->next;
|
||||||
|
if (wnd->next) wnd->next->prev = wnd->prev;
|
||||||
|
wnd->prev = NULL;
|
||||||
|
wnd->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the toolwindow object
|
||||||
|
// its destructor will destroy the window
|
||||||
|
delete wnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseAllToolWindows()
|
||||||
|
{
|
||||||
|
CToolWindow* wnd;
|
||||||
|
CToolWindow* wnd_next;
|
||||||
|
|
||||||
|
wnd = ToolWindowList;
|
||||||
|
while (wnd)
|
||||||
|
{
|
||||||
|
wnd_next = wnd->next;
|
||||||
|
|
||||||
|
wnd->prev = NULL;
|
||||||
|
wnd->next = NULL;
|
||||||
|
delete wnd;
|
||||||
|
|
||||||
|
wnd = wnd_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolWindowList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RefreshAllToolWindows()
|
||||||
|
{
|
||||||
|
CToolWindow* wnd;
|
||||||
|
|
||||||
|
if (ToolWindowList == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EnterCriticalSection(&win_execute_sync);
|
||||||
|
wnd = ToolWindowList;
|
||||||
|
while (wnd)
|
||||||
|
{
|
||||||
|
wnd->Refresh();
|
||||||
|
wnd = wnd->next;
|
||||||
|
}
|
||||||
|
LeaveCriticalSection(&win_execute_sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,16 +30,92 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
extern CRITICAL_SECTION win_execute_sync;
|
||||||
|
|
||||||
|
// GetFontQuality()
|
||||||
|
// Returns a font quality value that can be passed to
|
||||||
|
// CreateFont(). The value depends on whether font
|
||||||
|
// antialiasing is enabled or not.
|
||||||
|
DWORD GetFontQuality();
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Window class handling
|
// Window class handling
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// RegWndClass()
|
||||||
|
// Registers a window class.
|
||||||
|
// Incase the class was already registered, the function
|
||||||
|
// just does nothing and returns true.
|
||||||
|
// Returns false if registration failed.
|
||||||
bool RegWndClass(string name, WNDPROC wndProc, int extraSize = 0);
|
bool RegWndClass(string name, WNDPROC wndProc, int extraSize = 0);
|
||||||
bool RegWndClass(string name, WNDPROC wndProc, HICON icon, int extraSize = 0);
|
bool RegWndClass(string name, WNDPROC wndProc, HICON icon, int extraSize = 0);
|
||||||
bool RegWndClass(string name, WNDPROC wndProc, UINT style, HICON icon, int extraSize = 0);
|
bool RegWndClass(string name, WNDPROC wndProc, UINT style, HICON icon, int extraSize = 0);
|
||||||
|
|
||||||
|
// UnregWndClass()
|
||||||
|
// Unregisters a previously registered window class.
|
||||||
|
// This function will silently fail if one or more windows
|
||||||
|
// using the class still exist.
|
||||||
void UnregWndClass(string name);
|
void UnregWndClass(string name);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Base toolwindow class
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class CToolWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// CToolWindow constructor #1
|
||||||
|
// Creates a window from a dialog template resource.
|
||||||
|
// If the window creation failed for whatever reason,
|
||||||
|
// hWnd will be NULL.
|
||||||
|
CToolWindow(int ID, DLGPROC proc, char* title);
|
||||||
|
|
||||||
|
// CToolWindow destructor
|
||||||
|
// Dummy destructor. The derivated toolwindow classes must
|
||||||
|
// destroy the window in their own destructors. Thus, they
|
||||||
|
// can unregister any window classes they use.
|
||||||
|
virtual ~CToolWindow();
|
||||||
|
|
||||||
|
// Show(), Hide()
|
||||||
|
// These ones are quite self-explanatory, I guess.
|
||||||
|
void Show() { ShowWindow(hWnd, SW_SHOW); }
|
||||||
|
void Hide() { ShowWindow(hWnd, SW_HIDE); }
|
||||||
|
|
||||||
|
// Refresh()
|
||||||
|
// Refreshes the window. Called by RefreshAllToolWindows().
|
||||||
|
void Refresh() { InvalidateRect(hWnd, NULL, FALSE); }
|
||||||
|
|
||||||
|
// Double-linked toolwindow list.
|
||||||
|
CToolWindow* prev;
|
||||||
|
CToolWindow* next;
|
||||||
|
|
||||||
|
// Handle to the window.
|
||||||
|
HWND hWnd;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Toolwindow handling
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// OpenToolWindow()
|
||||||
|
// Adds the CToolWindow instance to the toolwindow list.
|
||||||
|
// The instance will be deleted if its hWnd member is NULL.
|
||||||
|
bool OpenToolWindow(CToolWindow* wnd);
|
||||||
|
|
||||||
|
// CloseToolWindow()
|
||||||
|
// Removes the CToolWindow instance from the toolwindow list
|
||||||
|
// and deletes it.
|
||||||
|
void CloseToolWindow(CToolWindow* wnd);
|
||||||
|
|
||||||
|
// CloseAllToolWindows()
|
||||||
|
// Deletes all the toolwindows in the list and flushes the list.
|
||||||
|
void CloseAllToolWindows();
|
||||||
|
|
||||||
|
// RefreshAllToolWindows()
|
||||||
|
// Refreshes all the toolwindows in the list.
|
||||||
|
// Called once per frame when the emu is running.
|
||||||
|
void RefreshAllToolWindows();
|
||||||
|
|
||||||
|
|
||||||
class WINCLASS
|
class WINCLASS
|
||||||
{
|
{
|
||||||
|
|
|
@ -1290,7 +1290,7 @@ static void StepRunLoop_User()
|
||||||
tools_time_last = time_now;
|
tools_time_last = time_now;
|
||||||
}
|
}
|
||||||
if(SoundView_IsOpened()) SoundView_Refresh();
|
if(SoundView_IsOpened()) SoundView_Refresh();
|
||||||
//RefreshAllToolWindows();
|
RefreshAllToolWindows();
|
||||||
|
|
||||||
Update_RAM_Watch();
|
Update_RAM_Watch();
|
||||||
Update_RAM_Search();
|
Update_RAM_Search();
|
||||||
|
|
Loading…
Reference in New Issue