From 179282043f42b9275868d9f6d6d46682fcc19626 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 26 Sep 2022 12:01:54 +0930 Subject: [PATCH] Project64: Code cleanup --- Source/Project64-core/AppInit.cpp | 62 +- Source/Project64-core/Logging.cpp | 6 +- .../Project64-core/MemoryExceptionFilter.cpp | 2 +- .../Project64-core/Multilanguage/Language.cpp | 28 +- .../N64System/Enhancement/Enhancement.cpp | 20 +- .../N64System/Enhancement/Enhancements.cpp | 24 +- .../N64System/Interpreter/InterpreterCPU.cpp | 36 +- .../N64System/Interpreter/InterpreterOps.cpp | 93 +- Source/Project64-core/Settings.cpp | 136 +- .../SettingType/SettingsType-RDBCpuType.h | 31 +- Source/Project64/N64System.h | 8 +- Source/Project64/Plugins/PluginList.h | 14 +- Source/Project64/Settings/GuiSettings.h | 25 +- .../Project64/Settings/NotificationSettings.h | 5 +- Source/Project64/Settings/UISettings.h | 6 +- Source/Project64/Support.h | 10 +- Source/Project64/UserInterface.h | 16 +- Source/Project64/UserInterface/About.h | 25 +- Source/Project64/UserInterface/CheatUI.cpp | 60 +- Source/Project64/UserInterface/CheatUI.h | 157 +- .../UserInterface/Debugger/Assembler.cpp | 582 +- .../UserInterface/Debugger/Assembler.h | 54 +- .../UserInterface/Debugger/Breakpoints.cpp | 41 +- .../UserInterface/Debugger/Breakpoints.h | 64 +- .../Project64/UserInterface/Debugger/CPULog.h | 8 +- .../Project64/UserInterface/Debugger/DMALog.h | 16 +- .../UserInterface/Debugger/DebugDialog.h | 32 +- .../UserInterface/Debugger/DebugMMU.h | 62 +- .../Debugger/Debugger-AddBreakpoint.h | 23 +- .../Debugger/Debugger-AddSymbol.h | 33 +- .../Debugger/Debugger-CPULogView.cpp | 5 +- .../Debugger/Debugger-CPULogView.h | 71 +- .../Debugger/Debugger-Commands.cpp | 44 +- .../Debugger/Debugger-Commands.h | 281 +- .../Debugger/Debugger-DMALogView.cpp | 6 +- .../Debugger/Debugger-DMALogView.h | 65 +- .../Debugger-ExceptionBreakpoints.cpp | 8 +- .../Debugger/Debugger-ExceptionBreakpoints.h | 30 +- .../Debugger/Debugger-MemoryDump.h | 27 +- .../Debugger/Debugger-MemorySearch.cpp | 12 +- .../Debugger/Debugger-MemorySearch.h | 351 +- .../Debugger/Debugger-RegisterTabData.h | 12 +- .../Debugger/Debugger-RegisterTabs.cpp | 8 +- .../Debugger/Debugger-RegisterTabs.h | 45 +- .../Debugger/Debugger-Scripts.cpp | 3 +- .../UserInterface/Debugger/Debugger-Scripts.h | 107 +- .../Debugger/Debugger-ScriptsAutorun.cpp | 3 +- .../Debugger/Debugger-ScriptsAutorun.h | 57 +- .../Debugger/Debugger-StackTrace.h | 39 +- .../Debugger/Debugger-StackView.h | 23 +- .../Debugger/Debugger-Symbols.cpp | 5 +- .../UserInterface/Debugger/Debugger-Symbols.h | 72 +- .../UserInterface/Debugger/Debugger-TLB.h | 19 +- .../Debugger/Debugger-ViewMemory.cpp | 36 +- .../Debugger/Debugger-ViewMemory.h | 247 +- .../UserInterface/Debugger/Debugger.cpp | 17 +- .../UserInterface/Debugger/DebuggerUI.h | 24 +- .../UserInterface/Debugger/MemoryScanner.cpp | 25 +- .../UserInterface/Debugger/MemoryScanner.h | 296 +- .../Project64/UserInterface/Debugger/OpInfo.h | 62 +- .../Debugger/ScriptAPI/JSIntervalWorker.h | 6 +- .../Debugger/ScriptAPI/JSServerWorker.cpp | 27 +- .../Debugger/ScriptAPI/JSServerWorker.h | 35 +- .../Debugger/ScriptAPI/JSSocketWorker.cpp | 7 +- .../Debugger/ScriptAPI/JSSocketWorker.h | 60 +- .../Debugger/ScriptAPI/N64Image.cpp | 2 +- .../Debugger/ScriptAPI/N64Image.h | 45 +- .../Debugger/ScriptAPI/ScriptAPI.cpp | 3 +- .../Debugger/ScriptAPI/ScriptAPI.h | 902 +- .../ScriptAPI/ScriptAPI_AddressRange.cpp | 6 +- .../Debugger/ScriptAPI/ScriptAPI_N64Image.cpp | 8 +- .../Debugger/ScriptAPI/ScriptAPI_Server.cpp | 4 +- .../Debugger/ScriptAPI/ScriptAPI_Socket.cpp | 2 +- .../Debugger/ScriptAPI/ScriptAPI_asm.cpp | 38 +- .../Debugger/ScriptAPI/ScriptAPI_console.cpp | 2 +- .../Debugger/ScriptAPI/ScriptAPI_cpu.cpp | 78 +- .../Debugger/ScriptAPI/ScriptAPI_debug.cpp | 10 +- .../Debugger/ScriptAPI/ScriptAPI_events.cpp | 77 +- .../Debugger/ScriptAPI/ScriptAPI_exec.cpp | 2 +- .../Debugger/ScriptAPI/ScriptAPI_fs.cpp | 274 +- .../Debugger/ScriptAPI/ScriptAPI_mem.cpp | 32 +- .../Debugger/ScriptAPI/ScriptAPI_pj64.cpp | 4 +- .../Debugger/ScriptAPI/ScriptAPI_script.cpp | 33 +- .../UserInterface/Debugger/ScriptInstance.cpp | 6 +- .../UserInterface/Debugger/ScriptInstance.h | 82 +- .../UserInterface/Debugger/ScriptSystem.cpp | 13 +- .../UserInterface/Debugger/ScriptSystem.h | 123 +- .../UserInterface/Debugger/ScriptTypes.h | 73 +- .../UserInterface/Debugger/ScriptWorker.h | 12 +- .../UserInterface/Debugger/Symbols.cpp | 2 +- .../UserInterface/Debugger/Symbols.h | 73 +- .../UserInterface/Debugger/debugger.h | 60 +- Source/Project64/UserInterface/DiscordRPC.h | 8 +- .../Project64/UserInterface/EnhancementUI.cpp | 201 +- .../Project64/UserInterface/EnhancementUI.h | 35 +- Source/Project64/UserInterface/LoggingUI.cpp | 125 +- Source/Project64/UserInterface/LoggingUI.h | 2 +- Source/Project64/UserInterface/MainMenu.cpp | 142 +- Source/Project64/UserInterface/MainMenu.h | 154 +- Source/Project64/UserInterface/MainWindow.cpp | 68 +- Source/Project64/UserInterface/MainWindow.h | 47 +- Source/Project64/UserInterface/MenuItem.cpp | 7 +- Source/Project64/UserInterface/MenuItem.h | 132 +- .../Project64/UserInterface/MenuShortCuts.cpp | 434 +- .../Project64/UserInterface/MenuShortCuts.h | 85 +- .../Project64/UserInterface/Notification.cpp | 52 +- Source/Project64/UserInterface/Notification.h | 6 +- .../UserInterface/ProjectSupport.cpp | 13 +- .../Project64/UserInterface/ProjectSupport.h | 24 +- Source/Project64/UserInterface/RomBrowser.cpp | 239 +- Source/Project64/UserInterface/RomBrowser.h | 147 +- .../UserInterface/RomInformation.cpp | 20 +- .../Project64/UserInterface/RomInformation.h | 16 +- .../Settings/SettingsPage-AdvancedOptions.h | 48 +- .../Settings/SettingsPage-Defaults.h | 62 +- .../Settings/SettingsPage-Directories.h | 98 +- .../Settings/SettingsPage-DiskDrive.h | 58 +- .../Settings/SettingsPage-Game-DiskDrive.h | 26 +- .../Settings/SettingsPage-Game-General.h | 54 +- .../Settings/SettingsPage-KeyboardShortcuts.h | 92 +- .../Settings/SettingsPage-Options.h | 52 +- .../Settings/SettingsPage-Plugin.h | 85 +- .../UserInterface/Settings/SettingsPage.h | 46 +- .../UserInterface/SettingsConfig.cpp | 82 +- .../Project64/UserInterface/SettingsConfig.h | 33 +- .../UserInterface/SupportEnterCode.cpp | 65 +- .../UserInterface/SupportEnterCode.h | 35 +- .../Project64/UserInterface/SupportWindow.h | 41 +- .../WTLControls/ClistCtrl/DataArray.h | 359 +- .../WTLControls/ClistCtrl/DragDrop.h | 1436 ++-- .../WTLControls/ClistCtrl/DropArrows.h | 184 +- .../WTLControls/ClistCtrl/ListCombo.h | 839 +- .../WTLControls/ClistCtrl/ListCtrl.h | 7478 +++++++++-------- .../WTLControls/ClistCtrl/ListDate.h | 368 +- .../WTLControls/ClistCtrl/ListEdit.h | 485 +- .../WTLControls/ClistCtrl/ListTypes.h | 246 +- .../WTLControls/ClistCtrl/TitleTip.h | 433 +- .../UserInterface/WTLControls/DisplayMode.h | 14 +- .../UserInterface/WTLControls/EditConInput.h | 22 +- .../WTLControls/EditNumber32.cpp | 10 +- .../UserInterface/WTLControls/EditNumber32.h | 18 +- .../UserInterface/WTLControls/HexEditCtrl.cpp | 12 +- .../UserInterface/WTLControls/HexEditCtrl.h | 298 +- .../WTLControls/ModifiedCheckBox.h | 129 +- .../WTLControls/ModifiedComboBox.h | 268 +- .../WTLControls/ModifiedEditBox.h | 54 +- .../WTLControls/PartialGroupBox.h | 34 +- .../UserInterface/WTLControls/TooltipDialog.h | 67 +- .../WTLControls/wtl-BitmapPicture.h | 36 +- .../Project64/UserInterface/WelcomeScreen.h | 27 +- Source/Project64/stdafx.h | 25 +- 151 files changed, 11511 insertions(+), 9945 deletions(-) diff --git a/Source/Project64-core/AppInit.cpp b/Source/Project64-core/AppInit.cpp index 61a37d2eb..2a3fa3227 100644 --- a/Source/Project64-core/AppInit.cpp +++ b/Source/Project64-core/AppInit.cpp @@ -1,16 +1,16 @@ #include "stdafx.h" -#include #include #include +#include +#include "Settings/SettingType/SettingsType-Application.h" +#include #include +#include +#include #include #include -#include -#include -#include -#include "Settings/SettingType/SettingsType-Application.h" static void FixDirectories(void); void SetTraceModuleNames(void); @@ -164,7 +164,11 @@ void CleanupTrace(void) void TraceDone(void) { CloseTrace(); - if (g_LogFile) { delete g_LogFile; g_LogFile = nullptr; } + if (g_LogFile) + { + delete g_LogFile; + g_LogFile = nullptr; + } } const char * AppName(void) @@ -173,7 +177,7 @@ const char * AppName(void) return ApplicationName.c_str(); } -static bool ParseCommand(int32_t argc, char **argv) +static bool ParseCommand(int32_t argc, char ** argv) { if (argc <= 1) { @@ -213,7 +217,7 @@ static bool ParseCommand(int32_t argc, char **argv) return false; } -bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char **argv) +bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char ** argv) { try { @@ -283,13 +287,41 @@ void AppCleanup(void) WriteTrace(TraceAppCleanup, TraceDebug, "Cleaning up global objects"); CleanupTrace(); - if (g_Enhancements) { delete g_Enhancements; g_Enhancements = nullptr; } - if (g_Rom) { delete g_Rom; g_Rom = nullptr; } - if (g_DDRom) { delete g_DDRom; g_DDRom = nullptr; } - if (g_Disk) { delete g_Disk; g_Disk = nullptr; } - if (g_Plugins) { delete g_Plugins; g_Plugins = nullptr; } - if (g_Settings) { delete g_Settings; g_Settings = nullptr; } - if (g_Lang) { delete g_Lang; g_Lang = nullptr; } + if (g_Enhancements) + { + delete g_Enhancements; + g_Enhancements = nullptr; + } + if (g_Rom) + { + delete g_Rom; + g_Rom = nullptr; + } + if (g_DDRom) + { + delete g_DDRom; + g_DDRom = nullptr; + } + if (g_Disk) + { + delete g_Disk; + g_Disk = nullptr; + } + if (g_Plugins) + { + delete g_Plugins; + g_Plugins = nullptr; + } + if (g_Settings) + { + delete g_Settings; + g_Settings = nullptr; + } + if (g_Lang) + { + delete g_Lang; + g_Lang = nullptr; + } CMipsMemoryVM::FreeReservedMemory(); TraceDone(); diff --git a/Source/Project64-core/Logging.cpp b/Source/Project64-core/Logging.cpp index f846f9efa..d3bee3842 100644 --- a/Source/Project64-core/Logging.cpp +++ b/Source/Project64-core/Logging.cpp @@ -1,12 +1,12 @@ #include "stdafx.h" #include -#include -#include #include -#include #include #include +#include +#include +#include CFile * CLogging::m_hLogFile = nullptr; diff --git a/Source/Project64-core/MemoryExceptionFilter.cpp b/Source/Project64-core/MemoryExceptionFilter.cpp index aed7ff0eb..8864f2cc0 100644 --- a/Source/Project64-core/MemoryExceptionFilter.cpp +++ b/Source/Project64-core/MemoryExceptionFilter.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" #include +#include #include #include -#include #ifndef _WIN32 #include #endif diff --git a/Source/Project64-core/Multilanguage/Language.cpp b/Source/Project64-core/Multilanguage/Language.cpp index 1757f4a62..3d4232552 100644 --- a/Source/Project64-core/Multilanguage/Language.cpp +++ b/Source/Project64-core/Multilanguage/Language.cpp @@ -1,13 +1,14 @@ #include "stdafx.h" -#include -#include + #include +#include +#include CLanguage * g_Lang = nullptr; void CLanguage::LoadDefaultStrings(void) { -#define DEF_STR(ID,str) m_DefaultStrings.insert(LANG_STRINGS::value_type(ID,str)) +#define DEF_STR(ID, str) m_DefaultStrings.insert(LANG_STRINGS::value_type(ID, str)) DEF_STR(EMPTY_STRING, ""); @@ -105,7 +106,7 @@ void CLanguage::LoadDefaultStrings(void) DEF_STR(POPUP_CHEATS, "Edit Cheats"); DEF_STR(POPUP_GFX_PLUGIN, "Graphics Plugin"); DEF_STR(POPUP_PLAYDISK, "Play Game with Disk"); - DEF_STR(POPUP_ENHANCEMENTS, "Pick Enhancements"); + DEF_STR(POPUP_ENHANCEMENTS, "Pick Enhancements"); // Alternate name to save slot DEF_STR(SAVE_SLOT_DEFAULT, "Save Slot - Default"); @@ -610,7 +611,7 @@ bool CLanguage::LoadCurrentStrings(void) } // Process the file - FILE *file = fopen(Filename.c_str(), "rb"); + FILE * file = fopen(Filename.c_str(), "rb"); if (file == nullptr) { return false; @@ -696,7 +697,7 @@ const std::string & CLanguage::GetString(LanguageStringID StringID) std::string CLanguage::GetLangString(const char * FileName, LanguageStringID ID) { - FILE *file = fopen(FileName, "rb"); + FILE * file = fopen(FileName, "rb"); if (file == nullptr) { return ""; @@ -729,9 +730,12 @@ std::string CLanguage::GetLangString(const char * FileName, LanguageStringID ID) LANG_STR CLanguage::GetNextLangString(void * OpenFile) { - enum { MAX_STRING_LEN = 800 }; - int32_t StringID; - char szString[MAX_STRING_LEN]; // Temporarily store the string from the file + enum + { + MAX_STRING_LEN = 800 + }; + int32_t StringID; + char szString[MAX_STRING_LEN]; // Temporarily store the string from the file FILE * file = (FILE *)OpenFile; @@ -762,7 +766,8 @@ LANG_STR CLanguage::GetNextLangString(void * OpenFile) } if (feof(file)) { - StringID = EMPTY_STRING; return LANG_STR(0, ""); + StringID = EMPTY_STRING; + return LANG_STR(0, ""); } // Search for start of string '"' @@ -772,7 +777,8 @@ LANG_STR CLanguage::GetNextLangString(void * OpenFile) } if (feof(file)) { - StringID = EMPTY_STRING; return LANG_STR(0, ""); + StringID = EMPTY_STRING; + return LANG_STR(0, ""); } int32_t pos = 0; diff --git a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp index a5549b2b3..5fc3129bb 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancement.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancement.cpp @@ -1,13 +1,13 @@ #include "stdafx.h" #include -#include -#include #include +#include +#include const char * CEnhancement::CheatIdent = "Cheat"; const char * CEnhancement::EnhancementIdent = "Enhancement"; -#pragma warning(disable:4996) +#pragma warning(disable : 4996) static std::string GenerateKeyName(const char * Name, const char * Ident, const char * PostIdent) { @@ -26,7 +26,7 @@ class CSettingEnhancementActive : { public: CSettingEnhancementActive(const char * Name, const char * Ident, bool Default) : - CSettingTypeGame("",false), + CSettingTypeGame("", false), m_Default(Default) { m_KeyNameIdex = GenerateKeyName(Name, Ident, "Active"); @@ -90,7 +90,7 @@ public: Flush(); } - bool SelectedValue(uint16_t &Value) + bool SelectedValue(uint16_t & Value) { uint32_t StoredValue = 0; if (!Load(0, StoredValue)) @@ -281,8 +281,14 @@ void CEnhancement::SetName(const char * Name) CSettingEnhancementSelectedOption(m_Name.c_str(), m_Ident.c_str()).Delete(); m_Name = stdstr(Name != nullptr ? Name : "").Trim("\t ,"); m_NameAndExtension = m_Name; - if (m_Active != m_OnByDefault) { CSettingEnhancementActive(m_Name.c_str(), m_Ident.c_str(), m_OnByDefault).SetActive(m_OnByDefault); } - if (OptionSelected()) { CSettingEnhancementSelectedOption(m_Name.c_str(), m_Ident.c_str()).SetOption(SelectedOption()); } + if (m_Active != m_OnByDefault) + { + CSettingEnhancementActive(m_Name.c_str(), m_Ident.c_str(), m_OnByDefault).SetActive(m_OnByDefault); + } + if (OptionSelected()) + { + CSettingEnhancementSelectedOption(m_Name.c_str(), m_Ident.c_str()).SetOption(SelectedOption()); + } CheckValid(); } diff --git a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp index 88db0bc4f..ad015b839 100644 --- a/Source/Project64-core/N64System/Enhancement/Enhancements.cpp +++ b/Source/Project64-core/N64System/Enhancement/Enhancements.cpp @@ -1,18 +1,19 @@ #include "stdafx.h" -#include + +#include +#include #include +#include #include #include #include -#include -#include #include -#include #include -#include -#include +#include +#include +#include -CEnhancements::GAMESHARK_CODE::GAMESHARK_CODE(const GAMESHARK_CODE&rhs) +CEnhancements::GAMESHARK_CODE::GAMESHARK_CODE(const GAMESHARK_CODE & rhs) { m_Command = rhs.m_Command; m_Value = rhs.m_Value; @@ -72,7 +73,8 @@ void CEnhancements::ApplyGSButton(CMipsMemoryVM & MMU, bool /*UpdateChanges*/) for (size_t CurrentEntry = 0; CurrentEntry < CodeEntry.size(); CurrentEntry++) { const GAMESHARK_CODE & Code = CodeEntry[CurrentEntry]; - switch (Code.Command() & 0xFF000000) { + switch (Code.Command() & 0xFF000000) + { case 0x88000000: ModifyMemory8(MMU, 0x80000000 | (Code.Command() & 0xFFFFFF), (uint8_t)Code.Value(), Code.HasDisableValue(), (uint8_t)Code.DisableValue()); break; @@ -147,7 +149,7 @@ void CEnhancements::UpdateEnhancements(const CEnhancementList & Enhancements) #endif CGuard Guard(m_CS); - if (m_EnhancementFile.get() == nullptr ||strcmp(m_EnhancementFile->FileName(), OutFile) != 0) + if (m_EnhancementFile.get() == nullptr || strcmp(m_EnhancementFile->FileName(), OutFile) != 0) { if (!OutFile.DirectoryExists()) { @@ -426,7 +428,8 @@ void CEnhancements::ApplyGameSharkCodes(CMipsMemoryVM & MMU, CODES & CodeEntry, int incr = Code.Value(); int i; - switch (NextCodeEntry.Command() & 0xFF000000) { + switch (NextCodeEntry.Command() & 0xFF000000) + { case 0x10000000: // Xplorer64 case 0x80000000: Address = 0x80000000 | (NextCodeEntry.Command() & 0xFFFFFF); @@ -620,7 +623,6 @@ void CEnhancements::ModifyMemory16(CMipsMemoryVM & MMU, uint32_t Address, uint16 } } - void CEnhancements::ScanFileThread(void) { SectionFiles CheatFiles; diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp index 68d385bea..3d8d5ed9d 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp @@ -1,15 +1,16 @@ #include "stdafx.h" + #include "InterpreterCPU.h" -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include R4300iOp::Func * CInterpreterCPU::m_R4300i_Opcode = nullptr; @@ -36,9 +37,9 @@ void CInterpreterCPU::InPermLoop() { if (EndOnPermLoop() && ((g_Reg->STATUS_REGISTER & STATUS_IE) == 0 || - (g_Reg->STATUS_REGISTER & STATUS_EXL) != 0 || - (g_Reg->STATUS_REGISTER & STATUS_ERL) != 0 || - (g_Reg->STATUS_REGISTER & 0xFF00) == 0)) + (g_Reg->STATUS_REGISTER & STATUS_EXL) != 0 || + (g_Reg->STATUS_REGISTER & STATUS_ERL) != 0 || + (g_Reg->STATUS_REGISTER & 0xFF00) == 0)) { if (g_Plugins->Gfx()->UpdateScreen != nullptr) { @@ -117,7 +118,10 @@ void CInterpreterCPU::ExecuteCPU() _GPR[0].DW = 0; // MIPS $zero hard-wired to 0 NextTimer -= CountPerOp; - if (CDebugSettings::HaveDebugger()) { g_Debugger->CPUStepEnded(); } + if (CDebugSettings::HaveDebugger()) + { + g_Debugger->CPUStepEnded(); + } PROGRAM_COUNTER += 4; switch (PipelineStage) @@ -127,10 +131,10 @@ void CInterpreterCPU::ExecuteCPU() case PIPELINE_STAGE_DELAY_SLOT: PipelineStage = PIPELINE_STAGE_JUMP; break; - case PIPELINE_STAGE_PERMLOOP_DO_DELAY: + case PIPELINE_STAGE_PERMLOOP_DO_DELAY: PipelineStage = PIPELINE_STAGE_PERMLOOP_DELAY_DONE; break; - case PIPELINE_STAGE_JUMP: + case PIPELINE_STAGE_JUMP: CheckTimer = (JumpToLocation < PROGRAM_COUNTER - 4 || TestTimer); PROGRAM_COUNTER = JumpToLocation; PipelineStage = PIPELINE_STAGE_NORMAL; @@ -172,11 +176,11 @@ void CInterpreterCPU::ExecuteCPU() void CInterpreterCPU::ExecuteOps(int32_t Cycles) { bool & Done = g_System->m_EndEmulation; - uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER; + uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER; R4300iOpcode & Opcode = R4300iOp::m_Opcode; PIPELINE_STAGE & PipelineStage = g_System->m_PipelineStage; uint32_t & JumpToLocation = g_System->m_JumpToLocation; - bool & TestTimer = R4300iOp::m_TestTimer; + bool & TestTimer = R4300iOp::m_TestTimer; const int32_t & DoSomething = g_SystemEvents->DoSomething(); uint32_t CountPerOp = g_System->CountPerOp(); bool CheckTimer = false; diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 9624d8bda..b93583613 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -1,14 +1,15 @@ #include "stdafx.h" + +#include +#include +#include #include -#include -#include #include +#include #include #include -#include -#include -#include -#include +#include +#include #include #include @@ -39,22 +40,24 @@ R4300iOp::Func R4300iOp::Jump_CoP1_D[64]; R4300iOp::Func R4300iOp::Jump_CoP1_W[64]; R4300iOp::Func R4300iOp::Jump_CoP1_L[64]; -const uint32_t R4300iOp::SWL_MASK[4] = { 0x00000000, 0xFF000000, 0xFFFF0000, 0xFFFFFF00 }; -const uint32_t R4300iOp::SWR_MASK[4] = { 0x00FFFFFF, 0x0000FFFF, 0x000000FF, 0x00000000 }; -const uint32_t R4300iOp::LWL_MASK[4] = { 0x00000000, 0x000000FF, 0x0000FFFF, 0x00FFFFFF }; -const uint32_t R4300iOp::LWR_MASK[4] = { 0xFFFFFF00, 0xFFFF0000, 0xFF000000, 0x0000000 }; +const uint32_t R4300iOp::SWL_MASK[4] = {0x00000000, 0xFF000000, 0xFFFF0000, 0xFFFFFF00}; +const uint32_t R4300iOp::SWR_MASK[4] = {0x00FFFFFF, 0x0000FFFF, 0x000000FF, 0x00000000}; +const uint32_t R4300iOp::LWL_MASK[4] = {0x00000000, 0x000000FF, 0x0000FFFF, 0x00FFFFFF}; +const uint32_t R4300iOp::LWR_MASK[4] = {0xFFFFFF00, 0xFFFF0000, 0xFF000000, 0x0000000}; -const int32_t R4300iOp::SWL_SHIFT[4] = { 0, 8, 16, 24 }; -const int32_t R4300iOp::SWR_SHIFT[4] = { 24, 16, 8, 0 }; -const int32_t R4300iOp::LWL_SHIFT[4] = { 0, 8, 16, 24 }; -const int32_t R4300iOp::LWR_SHIFT[4] = { 24, 16, 8, 0 }; +const int32_t R4300iOp::SWL_SHIFT[4] = {0, 8, 16, 24}; +const int32_t R4300iOp::SWR_SHIFT[4] = {24, 16, 8, 0}; +const int32_t R4300iOp::LWL_SHIFT[4] = {0, 8, 16, 24}; +const int32_t R4300iOp::LWR_SHIFT[4] = {24, 16, 8, 0}; -#define TEST_COP1_USABLE_EXCEPTION() \ - if ((g_Reg->STATUS_REGISTER & STATUS_CU1) == 0) {\ - g_Reg->DoCopUnusableException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP,1);\ - g_System->m_PipelineStage = PIPELINE_STAGE_JUMP;\ - g_System->m_JumpToLocation = (*_PROGRAM_COUNTER);\ - return;}\ +#define TEST_COP1_USABLE_EXCEPTION() \ + if ((g_Reg->STATUS_REGISTER & STATUS_CU1) == 0) \ + { \ + g_Reg->DoCopUnusableException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP, 1); \ + g_System->m_PipelineStage = PIPELINE_STAGE_JUMP; \ + g_System->m_JumpToLocation = (*_PROGRAM_COUNTER); \ + return; \ + } void R4300iOp::SPECIAL() { @@ -996,7 +999,6 @@ void R4300iOp::DADDI() return; } _GPR[m_Opcode.rt].DW = sum; - } void R4300iOp::DADDIU() @@ -1004,8 +1006,8 @@ void R4300iOp::DADDIU() _GPR[m_Opcode.rt].DW = _GPR[m_Opcode.rs].DW + (int64_t)((int16_t)m_Opcode.immediate); } -uint64_t LDL_MASK[8] = { 0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFF, 0xFFFFFFFFFFFF, 0xFFFFFFFFFFFFFF }; -int32_t LDL_SHIFT[8] = { 0, 8, 16, 24, 32, 40, 48, 56 }; +uint64_t LDL_MASK[8] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFF, 0xFFFFFFFFFFFF, 0xFFFFFFFFFFFFFF}; +int32_t LDL_SHIFT[8] = {0, 8, 16, 24, 32, 40, 48, 56}; void R4300iOp::LDL() { @@ -1019,11 +1021,11 @@ void R4300iOp::LDL() } } -uint64_t LDR_MASK[8] = { 0xFFFFFFFFFFFFFF00, 0xFFFFFFFFFFFF0000, - 0xFFFFFFFFFF000000, 0xFFFFFFFF00000000, - 0xFFFFFF0000000000, 0xFFFF000000000000, - 0xFF00000000000000, 0 }; -int32_t LDR_SHIFT[8] = { 56, 48, 40, 32, 24, 16, 8, 0 }; +uint64_t LDR_MASK[8] = {0xFFFFFFFFFFFFFF00, 0xFFFFFFFFFFFF0000, + 0xFFFFFFFFFF000000, 0xFFFFFFFF00000000, + 0xFFFFFF0000000000, 0xFFFF000000000000, + 0xFF00000000000000, 0}; +int32_t LDR_SHIFT[8] = {56, 48, 40, 32, 24, 16, 8, 0}; void R4300iOp::LDR() { @@ -1161,15 +1163,15 @@ void R4300iOp::SW() g_MMU->SW_Memory(Address, _GPR[m_Opcode.rt].UW[0]); } -uint64_t SDL_MASK[8] = { 0, 0xFF00000000000000, - 0xFFFF000000000000, - 0xFFFFFF0000000000, - 0xFFFFFFFF00000000, - 0xFFFFFFFFFF000000, - 0xFFFFFFFFFFFF0000, - 0xFFFFFFFFFFFFFF00 }; +uint64_t SDL_MASK[8] = {0, 0xFF00000000000000, + 0xFFFF000000000000, + 0xFFFFFF0000000000, + 0xFFFFFFFF00000000, + 0xFFFFFFFFFF000000, + 0xFFFFFFFFFFFF0000, + 0xFFFFFFFFFFFFFF00}; -int32_t SDL_SHIFT[8] = { 0, 8, 16, 24, 32, 40, 48, 56 }; +int32_t SDL_SHIFT[8] = {0, 8, 16, 24, 32, 40, 48, 56}; void R4300iOp::SDL() { @@ -1188,16 +1190,16 @@ void R4300iOp::SDL() } } -uint64_t SDR_MASK[8] = { 0x00FFFFFFFFFFFFFF, - 0x0000FFFFFFFFFFFF, - 0x000000FFFFFFFFFF, - 0x00000000FFFFFFFF, - 0x0000000000FFFFFF, - 0x000000000000FFFF, - 0x00000000000000FF, - 0x0000000000000000 }; +uint64_t SDR_MASK[8] = {0x00FFFFFFFFFFFFFF, + 0x0000FFFFFFFFFFFF, + 0x000000FFFFFFFFFF, + 0x00000000FFFFFFFF, + 0x0000000000FFFFFF, + 0x000000000000FFFF, + 0x00000000000000FF, + 0x0000000000000000}; -int32_t SDR_SHIFT[8] = { 56, 48, 40, 32, 24, 16, 8, 0 }; +int32_t SDR_SHIFT[8] = {56, 48, 40, 32, 24, 16, 8, 0}; void R4300iOp::SDR() { @@ -1232,7 +1234,6 @@ void R4300iOp::SWR() { GenerateTLBWriteException(Address, __FUNCTION__); } - } void R4300iOp::CACHE() diff --git a/Source/Project64-core/Settings.cpp b/Source/Project64-core/Settings.cpp index 0ab0187eb..b61e77474 100644 --- a/Source/Project64-core/Settings.cpp +++ b/Source/Project64-core/Settings.cpp @@ -1,27 +1,27 @@ #include "stdafx.h" -#include #include "Settings/SettingType/SettingsType-Application.h" -#include "Settings/SettingType/SettingsType-ApplicationPath.h" #include "Settings/SettingType/SettingsType-ApplicationIndex.h" +#include "Settings/SettingType/SettingsType-ApplicationPath.h" #include "Settings/SettingType/SettingsType-GameSetting.h" #include "Settings/SettingType/SettingsType-GameSettingIndex.h" -#include "Settings/SettingType/SettingsType-RelativePath.h" -#include "Settings/SettingType/SettingsType-RomDatabase.h" -#include "Settings/SettingType/SettingsType-RomDatabaseSetting.h" -#include "Settings/SettingType/SettingsType-RomDatabaseIndex.h" #include "Settings/SettingType/SettingsType-RDBCpuType.h" +#include "Settings/SettingType/SettingsType-RDBOnOff.h" #include "Settings/SettingType/SettingsType-RDBRamSize.h" #include "Settings/SettingType/SettingsType-RDBSaveChip.h" #include "Settings/SettingType/SettingsType-RDBYesNo.h" -#include "Settings/SettingType/SettingsType-RDBOnOff.h" +#include "Settings/SettingType/SettingsType-RelativePath.h" +#include "Settings/SettingType/SettingsType-RomDatabase.h" +#include "Settings/SettingType/SettingsType-RomDatabaseIndex.h" +#include "Settings/SettingType/SettingsType-RomDatabaseSetting.h" #include "Settings/SettingType/SettingsType-SelectedDirectory.h" -#include "Settings/SettingType/SettingsType-TempString.h" -#include "Settings/SettingType/SettingsType-TempNumber.h" #include "Settings/SettingType/SettingsType-TempBool.h" -#include -#include +#include "Settings/SettingType/SettingsType-TempNumber.h" +#include "Settings/SettingType/SettingsType-TempString.h" +#include #include +#include +#include CSettings * g_Settings = nullptr; @@ -95,53 +95,53 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(SupportFile_EnhancementDirDefault, new CSettingTypeRelativePath("Config\\Enhancements", "")); AddHandler(SupportFile_UserEnhancementDir, new CSettingTypeApplicationPath("Settings", "UserEnhancementDir", SupportFile_UserEnhancementDirDefault)); AddHandler(SupportFile_UserEnhancementDirDefault, new CSettingTypeRelativePath("Config\\Enhancements-User", "")); - AddHandler(SupportFile_Notes, new CSettingTypeApplicationPath("Settings", "Notes", SupportFile_NotesDefault)); + AddHandler(SupportFile_Notes, new CSettingTypeApplicationPath("Settings", "Notes", SupportFile_NotesDefault)); AddHandler(SupportFile_NotesDefault, new CSettingTypeRelativePath("Config", "Project64.rdn")); AddHandler(SupportFile_ExtInfo, new CSettingTypeApplicationPath("Settings", "ExtInfo", SupportFile_ExtInfoDefault)); AddHandler(SupportFile_ExtInfoDefault, new CSettingTypeRelativePath("Config", "Project64.rdx")); // Settings location AddHandler(Setting_ApplicationName, new CSettingTypeTempString("")); - AddHandler(Setting_UseFromRegistry, new CSettingTypeApplication("Settings", "Use Registry", (uint32_t)false)); + AddHandler(Setting_UseFromRegistry, new CSettingTypeApplication("Settings", "Use Registry", (uint32_t) false)); AddHandler(Setting_RdbEditor, new CSettingTypeApplication("Settings", "Rdb Editor", false)); AddHandler(Setting_CN64TimeCritical, new CSettingTypeApplication("Settings", "CN64TimeCritical", false)); - AddHandler(Setting_AutoStart, new CSettingTypeApplication("Settings", "Auto Start", (uint32_t)true)); - AddHandler(Setting_AutoZipInstantSave, new CSettingTypeApplication("Settings", "Auto Zip Saves", (uint32_t)true)); - AddHandler(Setting_EraseGameDefaults, new CSettingTypeApplication("Settings", "Erase on default", (uint32_t)true)); - AddHandler(Setting_CheckEmuRunning, new CSettingTypeApplication("Settings", "Check Running", (uint32_t)true)); + AddHandler(Setting_AutoStart, new CSettingTypeApplication("Settings", "Auto Start", (uint32_t) true)); + AddHandler(Setting_AutoZipInstantSave, new CSettingTypeApplication("Settings", "Auto Zip Saves", (uint32_t) true)); + AddHandler(Setting_EraseGameDefaults, new CSettingTypeApplication("Settings", "Erase on default", (uint32_t) true)); + AddHandler(Setting_CheckEmuRunning, new CSettingTypeApplication("Settings", "Check Running", (uint32_t) true)); #ifndef _M_X64 AddHandler(Setting_ForceInterpreterCPU, new CSettingTypeApplication("Settings", "Force Interpreter CPU", false)); #else AddHandler(Setting_ForceInterpreterCPU, new CSettingTypeApplication("Settings", "Force Interpreter CPU", true)); #endif AddHandler(Setting_FixedRdramAddress, new CSettingTypeApplication("Settings", "Fixed Rdram Address", (uint32_t)0)); - AddHandler(Setting_Enhancement, new CSettingTypeApplication("Settings", "Enable Enhancement", (uint32_t)true)); - - AddHandler(Setting_RememberCheats, new CSettingTypeApplication("Settings", "Remember Cheats", (bool)false)); + AddHandler(Setting_Enhancement, new CSettingTypeApplication("Settings", "Enable Enhancement", (uint32_t) true)); + + AddHandler(Setting_RememberCheats, new CSettingTypeApplication("Settings", "Remember Cheats", (bool)false)); AddHandler(Setting_UniqueSaveDir, new CSettingTypeApplication("Settings", "Unique Game Dir", true)); AddHandler(Setting_CurrentLanguage, new CSettingTypeApplication("Settings", "Current Language", "")); AddHandler(Setting_EnableDisk, new CSettingTypeTempBool(false)); AddHandler(Setting_LanguageDirDefault, new CSettingTypeRelativePath("Lang", "")); AddHandler(Setting_LanguageDir, new CSettingTypeApplicationPath("Lang Directory", "Directory", Setting_LanguageDirDefault)); - AddHandler(Setting_SyncViaAudioEnabled, new CSettingTypeTempBool(false, "SyncViaAudioEnabled")); + AddHandler(Setting_SyncViaAudioEnabled, new CSettingTypeTempBool(false, "SyncViaAudioEnabled")); AddHandler(Setting_DiskSaveType, new CSettingTypeApplication("Settings", "Disk Save Type", (uint32_t)1)); AddHandler(Setting_UpdateControllerOnRefresh, new CSettingTypeTempBool(false)); - AddHandler(Default_RDRamSize, new CSettingTypeApplication("Defaults", "RDRAM Size", 0x800000u)); - AddHandler(Default_UseHleGfx, new CSettingTypeApplication("Defaults", "HLE GFX Default", true)); - AddHandler(Default_ViRefreshRate, new CSettingTypeApplication("Defaults", "ViRefresh", 1500u)); - AddHandler(Default_AiCountPerBytes, new CSettingTypeApplication("Defaults", "AiCountPerBytes", 0u)); - AddHandler(Default_CounterFactor, new CSettingTypeApplication("Defaults", "Counter Factor", 2u)); - AddHandler(Default_32Bit, new CSettingTypeApplication("Defaults", "32bit", false)); - AddHandler(Default_SyncViaAudio, new CSettingTypeApplication("Defaults", "Audio-Sync Audio", true)); - AddHandler(Default_FixedAudio, new CSettingTypeApplication("Defaults", "Fixed Audio", true)); - AddHandler(Default_UnalignedDMA, new CSettingTypeApplication("Defaults", "Unaligned DMA", false)); - AddHandler(Default_RandomizeSIPIInterrupts, new CSettingTypeApplication("Defaults", "Randomize SI/PI Interrupts", true)); - AddHandler(Default_SMM_Protect_Memory, new CSettingTypeApplication("Defaults", "SMM-Protect", false)); + AddHandler(Default_RDRamSize, new CSettingTypeApplication("Defaults", "RDRAM Size", 0x800000u)); + AddHandler(Default_UseHleGfx, new CSettingTypeApplication("Defaults", "HLE GFX Default", true)); + AddHandler(Default_ViRefreshRate, new CSettingTypeApplication("Defaults", "ViRefresh", 1500u)); + AddHandler(Default_AiCountPerBytes, new CSettingTypeApplication("Defaults", "AiCountPerBytes", 0u)); + AddHandler(Default_CounterFactor, new CSettingTypeApplication("Defaults", "Counter Factor", 2u)); + AddHandler(Default_32Bit, new CSettingTypeApplication("Defaults", "32bit", false)); + AddHandler(Default_SyncViaAudio, new CSettingTypeApplication("Defaults", "Audio-Sync Audio", true)); + AddHandler(Default_FixedAudio, new CSettingTypeApplication("Defaults", "Fixed Audio", true)); + AddHandler(Default_UnalignedDMA, new CSettingTypeApplication("Defaults", "Unaligned DMA", false)); + AddHandler(Default_RandomizeSIPIInterrupts, new CSettingTypeApplication("Defaults", "Randomize SI/PI Interrupts", true)); + AddHandler(Default_SMM_Protect_Memory, new CSettingTypeApplication("Defaults", "SMM-Protect", false)); AddHandler(Default_DiskSeekTiming, new CSettingTypeApplication("Defaults", "Disk Seek Timing", (uint32_t)DiskSeek_Turbo)); AddHandler(Rdb_GoodName, new CSettingTypeRomDatabase("Good Name", Game_GameName)); - AddHandler(Rdb_RPCKey, new CSettingTypeRomDatabase("RPC Key", Game_RPCKey)); + AddHandler(Rdb_RPCKey, new CSettingTypeRomDatabase("RPC Key", Game_RPCKey)); AddHandler(Rdb_SaveChip, new CSettingTypeRDBSaveChip("Save Type", (uint32_t)SaveChip_Auto)); AddHandler(Rdb_CpuType, new CSettingTypeRDBCpuType("CPU Type", CPU_Recompiler)); AddHandler(Rdb_RDRamSize, new CSettingTypeRDBRDRamSize("RDRAM Size", Default_RDRamSize)); @@ -164,9 +164,9 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) #ifdef ANDROID AddHandler(Rdb_BlockLinking, new CSettingTypeRDBOnOff("Linking", false)); #else - AddHandler(Rdb_BlockLinking, new CSettingTypeRDBOnOff("Linking", true)); + AddHandler(Rdb_BlockLinking, new CSettingTypeRDBOnOff("Linking", true)); #endif - AddHandler(Rdb_SMM_Cache, new CSettingTypeRomDatabase("SMM-Cache", true)); + AddHandler(Rdb_SMM_Cache, new CSettingTypeRomDatabase("SMM-Cache", true)); AddHandler(Rdb_SMM_StoreInstruc, new CSettingTypeRomDatabase("SMM-StoreInstr", false)); AddHandler(Rdb_SMM_PIDMA, new CSettingTypeRomDatabase("SMM-PI DMA", true)); AddHandler(Rdb_SMM_TLB, new CSettingTypeRomDatabase("SMM-TLB", true)); @@ -238,12 +238,12 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Game_FullSpeed, new CSettingTypeTempBool(true, "Full Speed")); AddHandler(Game_UnalignedDMA, new CSettingTypeGame("Unaligned DMA", Rdb_UnalignedDMA)); AddHandler(Game_RandomizeSIPIInterrupts, new CSettingTypeGame("Randomize SI/PI Interrupts", Rdb_RandomizeSIPIInterrupts)); - AddHandler(Game_RPCKey, new CSettingTypeTempString("")); + AddHandler(Game_RPCKey, new CSettingTypeTempString("")); AddHandler(Game_DiskSeekTiming, new CSettingTypeGame("DiskSeekTiming", Rdb_DiskSeekTiming)); // User interface - AddHandler(UserInterface_ShowCPUPer, new CSettingTypeApplication("Settings", "Display CPU Usage", (uint32_t)false)); - AddHandler(UserInterface_DisplayFrameRate, new CSettingTypeApplication("Settings", "Display Frame Rate", (uint32_t)false)); + AddHandler(UserInterface_ShowCPUPer, new CSettingTypeApplication("Settings", "Display CPU Usage", (uint32_t) false)); + AddHandler(UserInterface_DisplayFrameRate, new CSettingTypeApplication("Settings", "Display Frame Rate", (uint32_t) false)); AddHandler(UserInterface_FrameDisplayType, new CSettingTypeApplication("Settings", "Frame Rate Display Type", (uint32_t)FR_VIs)); AddHandler(Directory_Plugin, new CSettingTypeSelectedDirectory("Dir:Plugin", Directory_PluginInitial, Directory_PluginSelected, Directory_PluginUseSelected, Directory_Plugin)); #ifndef _M_X64 @@ -313,7 +313,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(GameRunning_ScreenHertz, new CSettingTypeTempNumber(60)); AddHandler(GameRunning_InReset, new CSettingTypeTempBool(false)); - AddHandler(UserInterface_BasicMode, new CSettingTypeApplication("Settings", "Basic Mode", (uint32_t)true)); + AddHandler(UserInterface_BasicMode, new CSettingTypeApplication("Settings", "Basic Mode", (uint32_t) true)); AddHandler(File_DiskIPLPath, new CSettingTypeApplicationPath("Settings", "Disk IPL ROM Path", Default_None)); AddHandler(File_DiskIPLUSAPath, new CSettingTypeApplicationPath("Settings", "Disk IPL USA ROM Path", Default_None)); AddHandler(File_DiskIPLTOOLPath, new CSettingTypeApplicationPath("Settings", "Disk IPL TOOL ROM Path", Default_None)); @@ -342,7 +342,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Debugger_IntrBreakpoints, new CSettingTypeApplication("Debugger", "Interrupt Breakpoints", (uint32_t)0)); AddHandler(Debugger_RcpIntrBreakpoints, new CSettingTypeApplication("Debugger", "RCP Interrupt Breakpoints", (uint32_t)0)); AddHandler(Debugger_DebugLanguage, new CSettingTypeApplication("Debugger", "Debug Language", false)); - AddHandler(Debugger_AppLogFlush, new CSettingTypeApplication("Logging", "Log Auto Flush", (uint32_t)false)); + AddHandler(Debugger_AppLogFlush, new CSettingTypeApplication("Logging", "Log Auto Flush", (uint32_t) false)); AddHandler(Debugger_RecordRecompilerAsm, new CSettingTypeApplication("Debugger", "Record Recompiler Asm", false)); AddHandler(Debugger_AutorunScripts, new CSettingTypeApplication("Debugger", "Autorun Scripts", "")); @@ -375,8 +375,8 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Plugin_RSP_Current, new CSettingTypeApplication("Plugin", "RSP Dll", "RSP\\RSP 1.7.dll")); #ifdef _DEBUG AddHandler(Plugin_GFX_Default, new CSettingTypeApplication("Plugin", "Graphics Dll Default", "GFX\\Project64-Video_d.dll")); - AddHandler(Plugin_GFX_Current, new CSettingTypeApplication("Plugin", "Graphics Dll", Plugin_GFX_Default)); - AddHandler(Plugin_AUDIO_Current, new CSettingTypeApplication("Plugin", "Audio Dll", "Audio\\Project64-Audio_d.dll")); + AddHandler(Plugin_GFX_Current, new CSettingTypeApplication("Plugin", "Graphics Dll", Plugin_GFX_Default)); + AddHandler(Plugin_AUDIO_Current, new CSettingTypeApplication("Plugin", "Audio Dll", "Audio\\Project64-Audio_d.dll")); AddHandler(Plugin_CONT_Current, new CSettingTypeApplication("Plugin", "Controller Dll", "Input\\Project64-Input_d.dll")); #else AddHandler(Plugin_GFX_Default, new CSettingTypeApplication("Plugin", "Graphics Dll Default", "GFX\\Project64-Video.dll")); @@ -395,7 +395,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Plugin_AUDIO_CurVer, new CSettingTypeApplication("Plugin", "Audio Dll Ver", "")); AddHandler(Plugin_CONT_CurVer, new CSettingTypeApplication("Plugin", "Controller Dll Ver", "")); - AddHandler(Plugin_UseHleGfx, new CSettingTypeApplication("RSP", "HLE GFX Plugin", Default_UseHleGfx)); + AddHandler(Plugin_UseHleGfx, new CSettingTypeApplication("RSP", "HLE GFX Plugin", Default_UseHleGfx)); AddHandler(Plugin_UseHleAudio, new CSettingTypeApplication("RSP", "HLE Audio Plugin", false)); AddHandler(Plugin_EnableAudio, new CSettingTypeApplication("Audio", "Enable Audio", true)); @@ -426,12 +426,12 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Logging_LogRomHeader, new CSettingTypeApplication("Logging", "Generate Log Files", false)); AddHandler(Logging_LogUnknown, new CSettingTypeApplication("Logging", "Log Rom Header", false)); - WriteTrace(TraceAppInit, TraceDebug, "Done"); + WriteTrace(TraceAppInit, TraceDebug, "Done"); } uint32_t CSettings::FindSetting(CSettings * _this, const char * Name) { - uint32_t setting_id = 0; + uint32_t setting_id = 0; for (SETTING_MAP::iterator iter = _this->m_SettingInfo.begin(); iter != _this->m_SettingInfo.end(); iter++) { CSettingType * Setting = iter->second; @@ -442,11 +442,11 @@ uint32_t CSettings::FindSetting(CSettings * _this, const char * Name) { continue; } - if (setting_id != 0) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - setting_id = iter->first; + if (setting_id != 0) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + setting_id = iter->first; } else if (Setting->GetSettingType() == SettingType_CfgFile) { @@ -455,11 +455,11 @@ uint32_t CSettings::FindSetting(CSettings * _this, const char * Name) { continue; } - if (setting_id != 0) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - setting_id = iter->first; + if (setting_id != 0) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + setting_id = iter->first; } else if (Setting->GetSettingType() == SettingType_SelectedDirectory) { @@ -468,11 +468,11 @@ uint32_t CSettings::FindSetting(CSettings * _this, const char * Name) { continue; } - if (setting_id != 0) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - setting_id = iter->first; + if (setting_id != 0) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + setting_id = iter->first; } else if (Setting->GetSettingType() == SettingType_BoolVariable) { @@ -481,11 +481,11 @@ uint32_t CSettings::FindSetting(CSettings * _this, const char * Name) { continue; } - if (setting_id != 0) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - setting_id = iter->first; + if (setting_id != 0) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + setting_id = iter->first; } } return setting_id; @@ -532,8 +532,8 @@ void CSettings::SetSettingSz(CSettings * _this, SettingID ID, const char * Value } void CSettings::RegisterSetting(CSettings * _this, SettingID ID, SettingID DefaultID, SettingDataType DataType, - SettingType Type, const char * Category, const char * DefaultStr, - uint32_t Value) + SettingType Type, const char * Category, const char * DefaultStr, + uint32_t Value) { SettingID RdbSetting; stdstr Name; @@ -921,7 +921,7 @@ void CSettings::LoadDefaultBoolIndex(SettingID /*Type*/, uint32_t /*index*/, boo g_Notify->BreakPoint(__FILE__, __LINE__); } -uint32_t CSettings::LoadDefaultDword(SettingID Type) +uint32_t CSettings::LoadDefaultDword(SettingID Type) { uint32_t Value = 0; LoadDefaultDword(Type, Value); diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-RDBCpuType.h b/Source/Project64-core/Settings/SettingType/SettingsType-RDBCpuType.h index 7216bcd51..9cab3103e 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-RDBCpuType.h +++ b/Source/Project64-core/Settings/SettingType/SettingsType-RDBCpuType.h @@ -1,34 +1,35 @@ #pragma once +#include class CSettingTypeRDBCpuType : public CSettingTypeRomDatabase { public: - CSettingTypeRDBCpuType(const char * Name, SettingID DefaultSetting ); - CSettingTypeRDBCpuType(const char * Name, uint32_t DefaultValue ); + CSettingTypeRDBCpuType(const char * Name, SettingID DefaultSetting); + CSettingTypeRDBCpuType(const char * Name, uint32_t DefaultValue); ~CSettingTypeRDBCpuType(); // Return the values - virtual bool Load (uint32_t Index, bool & Value ) const; - virtual bool Load (uint32_t Index, uint32_t & Value ) const; - virtual bool Load (uint32_t Index, std::string & Value ) const; + virtual bool Load(uint32_t Index, bool & Value) const; + virtual bool Load(uint32_t Index, uint32_t & Value) const; + virtual bool Load(uint32_t Index, std::string & Value) const; // Return the default values - virtual void LoadDefault (uint32_t Index, bool & Value ) const; - virtual void LoadDefault (uint32_t Index, uint32_t & Value ) const; - virtual void LoadDefault (uint32_t Index, std::string & Value ) const; + virtual void LoadDefault(uint32_t Index, bool & Value) const; + virtual void LoadDefault(uint32_t Index, uint32_t & Value) const; + virtual void LoadDefault(uint32_t Index, std::string & Value) const; // Update the settings - virtual void Save (uint32_t Index, bool Value ); - virtual void Save (uint32_t Index, uint32_t Value ); - virtual void Save (uint32_t Index, const std::string & Value ); - virtual void Save (uint32_t Index, const char * Value ); + virtual void Save(uint32_t Index, bool Value); + virtual void Save(uint32_t Index, uint32_t Value); + virtual void Save(uint32_t Index, const std::string & Value); + virtual void Save(uint32_t Index, const char * Value); // Delete the setting - virtual void Delete (uint32_t Index ); + virtual void Delete(uint32_t Index); private: CSettingTypeRDBCpuType(void); - CSettingTypeRDBCpuType(const CSettingTypeRDBCpuType&); - CSettingTypeRDBCpuType& operator=(const CSettingTypeRDBCpuType&); + CSettingTypeRDBCpuType(const CSettingTypeRDBCpuType &); + CSettingTypeRDBCpuType & operator=(const CSettingTypeRDBCpuType &); }; diff --git a/Source/Project64/N64System.h b/Source/Project64/N64System.h index d5551ef44..518965825 100644 --- a/Source/Project64/N64System.h +++ b/Source/Project64/N64System.h @@ -1,9 +1,9 @@ #pragma once #include "Support.h" -#include // Needed for stl string (std::string) #include #include +#include #include "UserInterface.h" #include @@ -12,9 +12,9 @@ // General MIPS information -#include -#include #include -#include +#include #include +#include +#include #include diff --git a/Source/Project64/Plugins/PluginList.h b/Source/Project64/Plugins/PluginList.h index 0fa4c3e1f..9cfcde333 100644 --- a/Source/Project64/Plugins/PluginList.h +++ b/Source/Project64/Plugins/PluginList.h @@ -8,24 +8,24 @@ public: typedef struct { PLUGIN_INFO Info; - bool AboutFunction; - CPath FullPath; - stdstr FileName; + bool AboutFunction; + CPath FullPath; + stdstr FileName; } PLUGIN; public: CPluginList(bool bAutoFill = true); ~CPluginList(); - bool LoadList(void); - int GetPluginCount(void) const; + bool LoadList(void); + int GetPluginCount(void) const; const PLUGIN * GetPluginInfo(int indx) const; private: - typedef std::vector PluginList; + typedef std::vector PluginList; PluginList m_PluginList; - CPath m_PluginDir; + CPath m_PluginDir; void AddPluginFromDir(CPath Dir); }; diff --git a/Source/Project64/Settings/GuiSettings.h b/Source/Project64/Settings/GuiSettings.h index 113d5125a..682c5998e 100644 --- a/Source/Project64/Settings/GuiSettings.h +++ b/Source/Project64/Settings/GuiSettings.h @@ -3,18 +3,23 @@ class CGuiSettings { protected: - CGuiSettings(); - virtual ~CGuiSettings(); - - static inline bool bCPURunning ( void) { return m_bCPURunning; } - static inline bool bAutoSleep ( void) { return m_bAutoSleep; } + CGuiSettings(); + virtual ~CGuiSettings(); + + static inline bool bCPURunning(void) + { + return m_bCPURunning; + } + static inline bool bAutoSleep(void) + { + return m_bAutoSleep; + } private: - static void RefreshSettings (void *); + static void RefreshSettings(void *); - static bool m_bCPURunning; - static bool m_bAutoSleep; - - static int m_RefCount; + static bool m_bCPURunning; + static bool m_bAutoSleep; + static int m_RefCount; }; diff --git a/Source/Project64/Settings/NotificationSettings.h b/Source/Project64/Settings/NotificationSettings.h index f8beaa219..df62558d5 100644 --- a/Source/Project64/Settings/NotificationSettings.h +++ b/Source/Project64/Settings/NotificationSettings.h @@ -16,5 +16,8 @@ protected: virtual ~CNotificationSettings(); void RegisterNotifications(void); - inline bool InFullScreen(void) const { return m_bInFullScreen; } + inline bool InFullScreen(void) const + { + return m_bInFullScreen; + } }; diff --git a/Source/Project64/Settings/UISettings.h b/Source/Project64/Settings/UISettings.h index 5fc1b1d06..fd479ac97 100644 --- a/Source/Project64/Settings/UISettings.h +++ b/Source/Project64/Settings/UISettings.h @@ -1,6 +1,6 @@ #pragma once -#include #include +#include enum UISettingID { @@ -16,7 +16,7 @@ enum UISettingID // Settings location Setting_PluginPageFirst, Setting_DisableScrSaver, - Setting_EnableDiscordRPC, + Setting_EnableDiscordRPC, Setting_AutoSleep, Setting_AutoFullscreen, @@ -71,7 +71,7 @@ enum UISettingID }; float DPIScale(void); -void RegisterUISettings (void); +void RegisterUISettings(void); void UISettingsSaveBool(UISettingID Type, bool Value); void UISettingsSaveBoolIndex(UISettingID Type, int32_t index, bool Value); void UISettingsSaveDword(UISettingID Type, uint32_t Value); diff --git a/Source/Project64/Support.h b/Source/Project64/Support.h index 7e90eb0b2..95527efbb 100644 --- a/Source/Project64/Support.h +++ b/Source/Project64/Support.h @@ -2,12 +2,12 @@ #include #endif -#include #include -#include #include -#include -#include -#include #include +#include +#include +#include +#include #include +#include diff --git a/Source/Project64/UserInterface.h b/Source/Project64/UserInterface.h index 0b82bbcaa..9d733fb30 100644 --- a/Source/Project64/UserInterface.h +++ b/Source/Project64/UserInterface.h @@ -1,20 +1,20 @@ #pragma once -#pragma warning(disable:4786) +#pragma warning(disable : 4786) #include "Support.h" #include #include -#include "WTLApp.h" -#include "UserInterface/MenuShortCuts.h" -#include "UserInterface/RomBrowser.h" +#include "UserInterface/CheatUI.h" +#include "UserInterface/MainMenu.h" #include "UserInterface/MainWindow.h" #include "UserInterface/MenuItem.h" -#include "UserInterface/MainMenu.h" +#include "UserInterface/MenuShortCuts.h" #include "UserInterface/Notification.h" -#include -#include "UserInterface/resource.h" +#include "UserInterface/RomBrowser.h" #include "UserInterface/SettingsConfig.h" -#include "UserInterface/CheatUI.h" #include "UserInterface/SupportWindow.h" +#include "UserInterface/resource.h" +#include "WTLApp.h" +#include diff --git a/Source/Project64/UserInterface/About.h b/Source/Project64/UserInterface/About.h index 2113fdbbf..0f29e1147 100644 --- a/Source/Project64/UserInterface/About.h +++ b/Source/Project64/UserInterface/About.h @@ -1,29 +1,34 @@ #pragma once -#include #include "resource.h" +#include class CAboutDlg : public CDialogImpl { public: BEGIN_MSG_MAP_EX(CAboutDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnOkCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic); + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnOkCmd); + } END_MSG_MAP() - enum { IDD = IDD_About }; + enum + { + IDD = IDD_About + }; CAboutDlg(CProjectSupport & Support); private: CAboutDlg(void); - CAboutDlg(const CAboutDlg&); - CAboutDlg& operator=(const CAboutDlg&); + CAboutDlg(const CAboutDlg &); + CAboutDlg & operator=(const CAboutDlg &); - void SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar_t * Text, const HFONT &font); + void SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar_t * Text, const HFONT & font); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); diff --git a/Source/Project64/UserInterface/CheatUI.cpp b/Source/Project64/UserInterface/CheatUI.cpp index 21eb52b7e..88a8a74d0 100644 --- a/Source/Project64/UserInterface/CheatUI.cpp +++ b/Source/Project64/UserInterface/CheatUI.cpp @@ -322,7 +322,10 @@ LRESULT CCheatList::OnTreeClicked(NMHDR * lpnmh) LRESULT CCheatList::OnTreeRClicked(NMHDR * lpnmh) { - if (g_Settings->LoadBool(UserInterface_BasicMode)) { return true; } + if (g_Settings->LoadBool(UserInterface_BasicMode)) + { + return true; + } // Work out what item is selected TVHITTESTINFO ht = {0}; @@ -397,7 +400,10 @@ LRESULT CCheatList::OnTreeSelChanged(NMHDR * /*lpnmh*/) void CCheatList::RefreshItems() { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } m_DeleteingEntries = true; m_hCheatTree.DeleteAllItems(); @@ -419,9 +425,15 @@ void CCheatList::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name, HT TV_INSERTSTRUCT tv; wchar_t Text[500], Item[500]; - if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5)) { g_Notify->BreakPoint(__FILE__, __LINE__); } + if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5)) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } wcscpy(Text, Name.c_str()); - if (wcschr(Text, L'\\') > 0) { *wcschr(Text, L'\\') = 0; } + if (wcschr(Text, L'\\') > 0) + { + *wcschr(Text, L'\\') = 0; + } tv.item.mask = TVIF_TEXT; tv.item.pszText = Item; @@ -457,7 +469,10 @@ void CCheatList::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name, HT hParent = TreeView_InsertItem(m_hCheatTree, &tv); TV_SetCheckState(hParent, CheatActive ? TV_STATE_CHECKED : TV_STATE_CLEAR); - if (wcscmp(Text, Name.c_str()) == 0) { return; } + if (wcscmp(Text, Name.c_str()) == 0) + { + return; + } AddCodeLayers(Enhancement, Name.substr(wcslen(Text) + 1), hParent, CheatActive); } @@ -466,9 +481,12 @@ void CCheatList::ChangeChildrenStatus(HTREEITEM hParent, bool Checked) HTREEITEM hItem = m_hCheatTree.GetChildItem(hParent); if (hItem == nullptr) { - if (hParent == TVI_ROOT) { return; } + if (hParent == TVI_ROOT) + { + return; + } - TVITEM item = { 0 }; + TVITEM item = {0}; item.mask = TVIF_PARAM; item.hItem = hParent; m_hCheatTree.GetItem(&item); @@ -494,14 +512,19 @@ void CCheatList::ChangeChildrenStatus(HTREEITEM hParent, bool Checked) while (hItem != nullptr) { TV_CHECK_STATE ChildState = TV_GetCheckState(hItem); - if ((ChildState != TV_STATE_CHECKED || !Checked) && - (ChildState != TV_STATE_CLEAR || Checked)) + if ((ChildState != TV_STATE_CHECKED || !Checked) && (ChildState != TV_STATE_CLEAR || Checked)) { ChangeChildrenStatus(hItem, Checked); } ChildState = TV_GetCheckState(hItem); - if (state == TV_STATE_UNKNOWN) { state = ChildState; } - if (state != ChildState) { state = TV_STATE_INDETERMINATE; } + if (state == TV_STATE_UNKNOWN) + { + state = ChildState; + } + if (state != ChildState) + { + state = TV_STATE_INDETERMINATE; + } hItem = m_hCheatTree.GetNextSiblingItem(hItem); } if (state != TV_STATE_UNKNOWN) @@ -603,8 +626,14 @@ void CCheatList::MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, co GetMenuItemInfo(hMenu, MenuPos, true, &MenuInfo); wcscpy(String, Title); - if (wcschr(String, '\t') != nullptr) { *(wcschr(String, '\t')) = '\0'; } - if (ShortCut) { _swprintf(String, L"%s\t%s", String, ShortCut); } + if (wcschr(String, '\t') != nullptr) + { + *(wcschr(String, '\t')) = '\0'; + } + if (ShortCut) + { + _swprintf(String, L"%s\t%s", String, ShortCut); + } SetMenuItemInfo(hMenu, MenuPos, true, &MenuInfo); } @@ -865,10 +894,7 @@ bool CEditCheat::ValuesChanged(void) bool Changed = false; if (m_hWnd != nullptr) { - if (m_EditName != GetCWindowText(GetDlgItem(IDC_CODE_NAME)) || - m_EditCode != GetCWindowText(GetDlgItem(IDC_CHEAT_CODES)) || - m_EditOptions != GetCWindowText(GetDlgItem(IDC_CHEAT_OPTIONS)) || - m_EditNotes != GetCWindowText(GetDlgItem(IDC_NOTES))) + if (m_EditName != GetCWindowText(GetDlgItem(IDC_CODE_NAME)) || m_EditCode != GetCWindowText(GetDlgItem(IDC_CHEAT_CODES)) || m_EditOptions != GetCWindowText(GetDlgItem(IDC_CHEAT_OPTIONS)) || m_EditNotes != GetCWindowText(GetDlgItem(IDC_NOTES))) { Changed = true; } diff --git a/Source/Project64/UserInterface/CheatUI.h b/Source/Project64/UserInterface/CheatUI.h index f291ce6ef..d5e3e2056 100644 --- a/Source/Project64/UserInterface/CheatUI.h +++ b/Source/Project64/UserInterface/CheatUI.h @@ -1,7 +1,7 @@ #pragma once -#include #include #include +#include class CEditCheat; class CCheatsUI; @@ -16,18 +16,23 @@ class CCheatList : public: BEGIN_MSG_MAP_EX(CCheatList) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_DESTROY, OnDestroy) - MESSAGE_HANDLER(UM_CHANGECODEEXTENSION, OnChangeCodeExtension) - COMMAND_ID_HANDLER(IDC_UNMARK, OnUnmark) - COMMAND_ID_HANDLER(ID_POPUP_DELETE, OnPopupDelete) - NOTIFY_HANDLER_EX(IDC_MYTREE, NM_CLICK, OnTreeClicked) - NOTIFY_HANDLER_EX(IDC_MYTREE, NM_RCLICK, OnTreeRClicked) - NOTIFY_HANDLER_EX(IDC_MYTREE, NM_DBLCLK, OnTreeDClicked) - NOTIFY_HANDLER_EX(IDC_MYTREE, TVN_SELCHANGED, OnTreeSelChanged) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_DESTROY, OnDestroy); + MESSAGE_HANDLER(UM_CHANGECODEEXTENSION, OnChangeCodeExtension); + COMMAND_ID_HANDLER(IDC_UNMARK, OnUnmark); + COMMAND_ID_HANDLER(ID_POPUP_DELETE, OnPopupDelete); + NOTIFY_HANDLER_EX(IDC_MYTREE, NM_CLICK, OnTreeClicked); + NOTIFY_HANDLER_EX(IDC_MYTREE, NM_RCLICK, OnTreeRClicked); + NOTIFY_HANDLER_EX(IDC_MYTREE, NM_DBLCLK, OnTreeDClicked); + NOTIFY_HANDLER_EX(IDC_MYTREE, TVN_SELCHANGED, OnTreeSelChanged); + } END_MSG_MAP() - enum { IDD = IDD_Cheats_List }; + enum + { + IDD = IDD_Cheats_List + }; CCheatList(CEnhancementList & Cheats, CEditCheat & EditCheat); ~CCheatList(); @@ -36,21 +41,27 @@ public: private: CCheatList(void); - CCheatList(const CCheatList&); - CCheatList& operator=(const CCheatList&); + CCheatList(const CCheatList &); + CCheatList & operator=(const CCheatList &); - enum TV_CHECK_STATE { TV_STATE_UNKNOWN, TV_STATE_CLEAR, TV_STATE_CHECKED, TV_STATE_INDETERMINATE }; + enum TV_CHECK_STATE + { + TV_STATE_UNKNOWN, + TV_STATE_CLEAR, + TV_STATE_CHECKED, + TV_STATE_INDETERMINATE + }; - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnChangeCodeExtension(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnUnmark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnTreeClicked(NMHDR* lpnmh); - LRESULT OnTreeRClicked(NMHDR* lpnmh); - LRESULT OnTreeDClicked(NMHDR* lpnmh); - LRESULT OnTreeSelChanged(NMHDR* lpnmh); - void AddCodeLayers(LPARAM ListID, const std::wstring &Name, HTREEITEM hParent, bool CheatActive); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnChangeCodeExtension(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnUnmark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnTreeClicked(NMHDR * lpnmh); + LRESULT OnTreeRClicked(NMHDR * lpnmh); + LRESULT OnTreeDClicked(NMHDR * lpnmh); + LRESULT OnTreeSelChanged(NMHDR * lpnmh); + void AddCodeLayers(LPARAM ListID, const std::wstring & Name, HTREEITEM hParent, bool CheatActive); void ChangeChildrenStatus(HTREEITEM hParent, bool Checked); void CheckParentStatus(HTREEITEM hParent); void DeleteCheat(LPARAM Enhancement); @@ -58,7 +69,10 @@ private: bool TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state); static void MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, const wchar_t * ShortCut); - enum { IDC_MYTREE = 0x500 }; + enum + { + IDC_MYTREE = 0x500 + }; CEnhancementList & m_Cheats; CEditCheat & m_EditCheat; @@ -79,32 +93,35 @@ public: }; BEGIN_MSG_MAP_EX(CEditCheat) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_EDITCHEAT, OnEditCheat) - COMMAND_ID_HANDLER(IDC_ADD, OnAddCheat) - COMMAND_ID_HANDLER(IDC_NEWCHEAT, OnNewCheat) - COMMAND_HANDLER(IDC_CODE_NAME, EN_CHANGE, OnCodeNameChanged) - COMMAND_HANDLER(IDC_CHEAT_CODES, EN_CHANGE, OnCheatCodeChanged) - COMMAND_HANDLER(IDC_CHEAT_OPTIONS, EN_CHANGE, OnCheatOptionsChanged) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + MESSAGE_HANDLER(WM_EDITCHEAT, OnEditCheat) + COMMAND_ID_HANDLER(IDC_ADD, OnAddCheat) + COMMAND_ID_HANDLER(IDC_NEWCHEAT, OnNewCheat) + COMMAND_HANDLER(IDC_CODE_NAME, EN_CHANGE, OnCodeNameChanged) + COMMAND_HANDLER(IDC_CHEAT_CODES, EN_CHANGE, OnCheatCodeChanged) + COMMAND_HANDLER(IDC_CHEAT_OPTIONS, EN_CHANGE, OnCheatOptionsChanged) END_MSG_MAP() - enum { IDD = IDD_Cheats_Add }; + enum + { + IDD = IDD_Cheats_Add + }; CEditCheat(CEnhancementList & Cheats, CCheatList & CheatList); ~CEditCheat(); private: CEditCheat(); - CEditCheat(const CEditCheat&); - CEditCheat& operator=(const CEditCheat&); + CEditCheat(const CEditCheat &); + CEditCheat & operator=(const CEditCheat &); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnEditCheat(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnAddCheat(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnNewCheat(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCodeNameChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCheatCodeChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCheatOptionsChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnEditCheat(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnAddCheat(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnNewCheat(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCodeNameChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCheatCodeChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCheatOptionsChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); bool ReadEnhancement(CEnhancement & Enhancement); @@ -126,25 +143,28 @@ class CEnhancementCodeEx : { public: BEGIN_MSG_MAP_EX(CEnhancementCodeEx) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_HANDLER(IDC_CHEAT_LIST, LBN_DBLCLK, OnListDblClick) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + COMMAND_HANDLER(IDC_CHEAT_LIST, LBN_DBLCLK, OnListDblClick) + COMMAND_ID_HANDLER(IDOK, OnOkCmd) + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) END_MSG_MAP() - enum { IDD = IDD_Cheats_CodeEx }; + enum + { + IDD = IDD_Cheats_CodeEx + }; CEnhancementCodeEx(CEnhancement * Enhancement); private: CEnhancementCodeEx(); - CEnhancementCodeEx(const CEnhancementCodeEx&); - CEnhancementCodeEx& operator=(const CEnhancementCodeEx&); + CEnhancementCodeEx(const CEnhancementCodeEx &); + CEnhancementCodeEx & operator=(const CEnhancementCodeEx &); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnListDblClick(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnListDblClick(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); CEnhancement * m_Enhancement; }; @@ -158,13 +178,18 @@ class CCheatsUI : public: BEGIN_MSG_MAP_EX(CCheatsUI) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_DESTROY, OnDestroy) - COMMAND_ID_HANDLER(IDC_STATE, OnStateChange) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_DESTROY, OnDestroy); + COMMAND_ID_HANDLER(IDC_STATE, OnStateChange); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + } END_MSG_MAP() - enum { IDD = IDD_Cheats_Select }; + enum + { + IDD = IDD_Cheats_Select + }; CCheatsUI(void); ~CCheatsUI(void); @@ -172,17 +197,21 @@ public: void Display(HWND hParent, bool BlockExecution); private: - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnStateChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnStateChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); CEnhancementList m_Cheats; CEditCheat m_EditCheat; CCheatList m_SelectCheat; CButton m_StateBtn; - int m_MinSizeDlg, m_MaxSizeDlg; + int m_MinSizeDlg, m_MaxSizeDlg; bool m_bModal; - enum Dialog_State { CONTRACTED, EXPANDED } m_DialogState; + enum Dialog_State + { + CONTRACTED, + EXPANDED + } m_DialogState; }; diff --git a/Source/Project64/UserInterface/Debugger/Assembler.cpp b/Source/Project64/UserInterface/Debugger/Assembler.cpp index c01909a03..3300a6e0d 100644 --- a/Source/Project64/UserInterface/Debugger/Assembler.cpp +++ b/Source/Project64/UserInterface/Debugger/Assembler.cpp @@ -35,262 +35,366 @@ const ASM_SYNTAX_FN CAssembler::syn_cop_mv[] = {arg_reg_t, arg_reg_d, nullptr}; const ASM_SYNTAX_FN CAssembler::syn_cache[] = {arg_cache_op, arg_imm16, arg_reg_s, nullptr}; const ASM_SYNTAX_FN CAssembler::syn_syscall[] = {arg_syscall_code, nullptr}; -const ASM_INSTRUCTION CAssembler::m_Instructions[] = -{ - { "j", R4300i_J, base_op, syn_jump }, - { "jal", R4300i_JAL, base_op, syn_jump }, - { "beq", R4300i_BEQ, base_op, syn_branch }, - { "beqz", R4300i_BEQ, base_op, syn_branch_z }, - { "b", R4300i_BEQ, base_op, syn_branch_unc }, - { "bne", R4300i_BNE, base_op, syn_branch }, - { "bnez", R4300i_BNE, base_op, syn_branch_z }, - { "blez", R4300i_BLEZ, base_op, syn_branch_z }, - { "bgtz", R4300i_BGTZ, base_op, syn_branch_z }, - { "addi", R4300i_ADDI, base_op, syn_arith_i }, - { "addiu", R4300i_ADDIU, base_op, syn_arith_i }, - { "slti", R4300i_SLTI, base_op, syn_arith_i }, - { "sltiu", R4300i_SLTIU, base_op, syn_arith_i }, - { "andi", R4300i_ANDI, base_op, syn_arith_i }, - { "ori", R4300i_ORI, base_op, syn_arith_i }, - { "xori", R4300i_XORI, base_op, syn_arith_i }, - { "lui", R4300i_LUI, base_op, syn_load_i }, - { "beql", R4300i_BEQL, base_op, syn_branch }, - { "beqzl", R4300i_BEQL, base_op, syn_branch_z }, - { "bnel", R4300i_BNEL, base_op, syn_branch }, - { "bnezl", R4300i_BNEL, base_op, syn_branch_z }, - { "blezl", R4300i_BLEZL, base_op, syn_branch_z }, - { "bgtzl", R4300i_BGTZL, base_op, syn_branch_z }, - { "daddi", R4300i_DADDI, base_op, syn_arith_i }, - { "daddiu", R4300i_DADDIU, base_op, syn_arith_i }, - { "ldl", R4300i_LDL, base_op, syn_loadstore }, - { "ldr", R4300i_LDR, base_op, syn_loadstore }, - { "lb", R4300i_LB, base_op, syn_loadstore }, - { "lh", R4300i_LH, base_op, syn_loadstore }, - { "lwl", R4300i_LWL, base_op, syn_loadstore }, - { "lw", R4300i_LW, base_op, syn_loadstore }, - { "lbu", R4300i_LBU, base_op, syn_loadstore }, - { "lhu", R4300i_LHU, base_op, syn_loadstore }, - { "lwr", R4300i_LWR, base_op, syn_loadstore }, - { "lwu", R4300i_LWU, base_op, syn_loadstore }, - { "sb", R4300i_SB, base_op, syn_loadstore }, - { "sh", R4300i_SH, base_op, syn_loadstore }, - { "swl", R4300i_SWL, base_op, syn_loadstore }, - { "sw", R4300i_SW, base_op, syn_loadstore }, - { "sdl", R4300i_SDL, base_op, syn_loadstore }, - { "sdr", R4300i_SDR, base_op, syn_loadstore }, - { "swr", R4300i_SWR, base_op, syn_loadstore }, - { "cache", R4300i_CACHE, base_op, syn_cache }, - { "ll", R4300i_LL, base_op, syn_loadstore }, - { "lwc1", R4300i_LWC1, base_op, syn_loadstore }, - { "ldc1", R4300i_LDC1, base_op, syn_loadstore }, - { "ld", R4300i_LD, base_op, syn_loadstore }, - { "sc", R4300i_SC, base_op, syn_loadstore }, - { "swc1", R4300i_SWC1, base_op, syn_loadstore }, - { "sdc1", R4300i_SDC1, base_op, syn_loadstore }, - { "sdc2", R4300i_SDC2, base_op, syn_loadstore }, - { "sd", R4300i_SD, base_op, syn_loadstore }, +const ASM_INSTRUCTION CAssembler::m_Instructions[] = { + {"j", R4300i_J, base_op, syn_jump}, + {"jal", R4300i_JAL, base_op, syn_jump}, + {"beq", R4300i_BEQ, base_op, syn_branch}, + {"beqz", R4300i_BEQ, base_op, syn_branch_z}, + {"b", R4300i_BEQ, base_op, syn_branch_unc}, + {"bne", R4300i_BNE, base_op, syn_branch}, + {"bnez", R4300i_BNE, base_op, syn_branch_z}, + {"blez", R4300i_BLEZ, base_op, syn_branch_z}, + {"bgtz", R4300i_BGTZ, base_op, syn_branch_z}, + {"addi", R4300i_ADDI, base_op, syn_arith_i}, + {"addiu", R4300i_ADDIU, base_op, syn_arith_i}, + {"slti", R4300i_SLTI, base_op, syn_arith_i}, + {"sltiu", R4300i_SLTIU, base_op, syn_arith_i}, + {"andi", R4300i_ANDI, base_op, syn_arith_i}, + {"ori", R4300i_ORI, base_op, syn_arith_i}, + {"xori", R4300i_XORI, base_op, syn_arith_i}, + {"lui", R4300i_LUI, base_op, syn_load_i}, + {"beql", R4300i_BEQL, base_op, syn_branch}, + {"beqzl", R4300i_BEQL, base_op, syn_branch_z}, + {"bnel", R4300i_BNEL, base_op, syn_branch}, + {"bnezl", R4300i_BNEL, base_op, syn_branch_z}, + {"blezl", R4300i_BLEZL, base_op, syn_branch_z}, + {"bgtzl", R4300i_BGTZL, base_op, syn_branch_z}, + {"daddi", R4300i_DADDI, base_op, syn_arith_i}, + {"daddiu", R4300i_DADDIU, base_op, syn_arith_i}, + {"ldl", R4300i_LDL, base_op, syn_loadstore}, + {"ldr", R4300i_LDR, base_op, syn_loadstore}, + {"lb", R4300i_LB, base_op, syn_loadstore}, + {"lh", R4300i_LH, base_op, syn_loadstore}, + {"lwl", R4300i_LWL, base_op, syn_loadstore}, + {"lw", R4300i_LW, base_op, syn_loadstore}, + {"lbu", R4300i_LBU, base_op, syn_loadstore}, + {"lhu", R4300i_LHU, base_op, syn_loadstore}, + {"lwr", R4300i_LWR, base_op, syn_loadstore}, + {"lwu", R4300i_LWU, base_op, syn_loadstore}, + {"sb", R4300i_SB, base_op, syn_loadstore}, + {"sh", R4300i_SH, base_op, syn_loadstore}, + {"swl", R4300i_SWL, base_op, syn_loadstore}, + {"sw", R4300i_SW, base_op, syn_loadstore}, + {"sdl", R4300i_SDL, base_op, syn_loadstore}, + {"sdr", R4300i_SDR, base_op, syn_loadstore}, + {"swr", R4300i_SWR, base_op, syn_loadstore}, + {"cache", R4300i_CACHE, base_op, syn_cache}, + {"ll", R4300i_LL, base_op, syn_loadstore}, + {"lwc1", R4300i_LWC1, base_op, syn_loadstore}, + {"ldc1", R4300i_LDC1, base_op, syn_loadstore}, + {"ld", R4300i_LD, base_op, syn_loadstore}, + {"sc", R4300i_SC, base_op, syn_loadstore}, + {"swc1", R4300i_SWC1, base_op, syn_loadstore}, + {"sdc1", R4300i_SDC1, base_op, syn_loadstore}, + {"sdc2", R4300i_SDC2, base_op, syn_loadstore}, + {"sd", R4300i_SD, base_op, syn_loadstore}, - { "sll", R4300i_SPECIAL_SLL, base_spec, syn_shift }, - { "nop", R4300i_SPECIAL_SLL, base_spec, nullptr }, - { "srl", R4300i_SPECIAL_SRL, base_spec, syn_shift }, - { "sra", R4300i_SPECIAL_SRA, base_spec, syn_shift }, - { "sllv", R4300i_SPECIAL_SLLV, base_spec, syn_shiftv }, - { "srlv", R4300i_SPECIAL_SRLV, base_spec, syn_shiftv }, - { "srav", R4300i_SPECIAL_SRAV, base_spec, syn_shiftv }, - { "jr", R4300i_SPECIAL_JR, base_spec, syn_jr }, - { "jalr", R4300i_SPECIAL_JALR, base_spec, syn_jalr }, - { "jalr", R4300i_SPECIAL_JALR, base_spec_jalr_ra, syn_jr }, - { "syscall", R4300i_SPECIAL_SYSCALL, base_spec, syn_syscall }, - { "break", R4300i_SPECIAL_BREAK, base_spec, syn_syscall }, - { "sync", R4300i_SPECIAL_SYNC, base_spec, nullptr }, - { "mfhi", R4300i_SPECIAL_MFHI, base_spec, syn_mf }, - { "mthi", R4300i_SPECIAL_MTHI, base_spec, syn_mf }, - { "mflo", R4300i_SPECIAL_MFLO, base_spec, syn_mf }, - { "mtlo", R4300i_SPECIAL_MTLO, base_spec, syn_mf }, - { "dsllv", R4300i_SPECIAL_DSLLV, base_spec, syn_shiftv }, - { "dsrlv", R4300i_SPECIAL_DSRLV, base_spec, syn_shiftv }, - { "dsrav", R4300i_SPECIAL_DSRAV, base_spec, syn_shiftv }, - { "mult", R4300i_SPECIAL_MULT, base_spec, syn_arith2 }, - { "multu", R4300i_SPECIAL_MULTU, base_spec, syn_arith2 }, - { "div", R4300i_SPECIAL_DIV, base_spec, syn_arith2 }, - { "divu", R4300i_SPECIAL_DIVU, base_spec, syn_arith2 }, - { "dmult", R4300i_SPECIAL_DMULT, base_spec, syn_arith2 }, - { "dmultu", R4300i_SPECIAL_DMULTU, base_spec, syn_arith2 }, - { "ddiv", R4300i_SPECIAL_DDIV, base_spec, syn_arith2 }, - { "ddivu", R4300i_SPECIAL_DDIVU, base_spec, syn_arith2 }, - { "add", R4300i_SPECIAL_ADD, base_spec, syn_arith }, - { "addu", R4300i_SPECIAL_ADDU, base_spec, syn_arith }, - { "sub", R4300i_SPECIAL_SUB, base_spec, syn_arith }, - { "subu", R4300i_SPECIAL_SUBU, base_spec, syn_arith }, - { "and", R4300i_SPECIAL_AND, base_spec, syn_arith }, - { "or", R4300i_SPECIAL_OR, base_spec, syn_arith }, - { "xor", R4300i_SPECIAL_XOR, base_spec, syn_arith }, - { "nor", R4300i_SPECIAL_NOR, base_spec, syn_arith }, - { "slt", R4300i_SPECIAL_SLT, base_spec, syn_arith }, - { "sltu", R4300i_SPECIAL_SLTU, base_spec, syn_arith }, - { "dadd", R4300i_SPECIAL_DADD, base_spec, syn_arith }, - { "daddu", R4300i_SPECIAL_DADDU, base_spec, syn_arith }, - { "dsub", R4300i_SPECIAL_DSUB, base_spec, syn_arith }, - { "dsubu", R4300i_SPECIAL_DSUBU, base_spec, syn_arith }, - { "tge", R4300i_SPECIAL_TGE, base_spec, syn_arith2 }, // Note: no code field - { "tgeu", R4300i_SPECIAL_TGEU, base_spec, syn_arith2 }, // - { "tlt", R4300i_SPECIAL_TLT, base_spec, syn_arith2 }, // - { "tltu", R4300i_SPECIAL_TLTU, base_spec, syn_arith2 }, // - { "teq", R4300i_SPECIAL_TEQ, base_spec, syn_arith2 }, // - { "tne", R4300i_SPECIAL_TNE, base_spec, syn_arith2 }, // - { "dsll", R4300i_SPECIAL_DSLL, base_spec, syn_shift }, - { "dsrl", R4300i_SPECIAL_DSRL, base_spec, syn_shift }, - { "dsra", R4300i_SPECIAL_DSRA, base_spec, syn_shift }, - { "dsll32", R4300i_SPECIAL_DSLL32, base_spec, syn_shift }, - { "dsrl32", R4300i_SPECIAL_DSRL32, base_spec, syn_shift }, - { "dsra32", R4300i_SPECIAL_DSRA32, base_spec, syn_shift }, + {"sll", R4300i_SPECIAL_SLL, base_spec, syn_shift}, + {"nop", R4300i_SPECIAL_SLL, base_spec, nullptr}, + {"srl", R4300i_SPECIAL_SRL, base_spec, syn_shift}, + {"sra", R4300i_SPECIAL_SRA, base_spec, syn_shift}, + {"sllv", R4300i_SPECIAL_SLLV, base_spec, syn_shiftv}, + {"srlv", R4300i_SPECIAL_SRLV, base_spec, syn_shiftv}, + {"srav", R4300i_SPECIAL_SRAV, base_spec, syn_shiftv}, + {"jr", R4300i_SPECIAL_JR, base_spec, syn_jr}, + {"jalr", R4300i_SPECIAL_JALR, base_spec, syn_jalr}, + {"jalr", R4300i_SPECIAL_JALR, base_spec_jalr_ra, syn_jr}, + {"syscall", R4300i_SPECIAL_SYSCALL, base_spec, syn_syscall}, + {"break", R4300i_SPECIAL_BREAK, base_spec, syn_syscall}, + {"sync", R4300i_SPECIAL_SYNC, base_spec, nullptr}, + {"mfhi", R4300i_SPECIAL_MFHI, base_spec, syn_mf}, + {"mthi", R4300i_SPECIAL_MTHI, base_spec, syn_mf}, + {"mflo", R4300i_SPECIAL_MFLO, base_spec, syn_mf}, + {"mtlo", R4300i_SPECIAL_MTLO, base_spec, syn_mf}, + {"dsllv", R4300i_SPECIAL_DSLLV, base_spec, syn_shiftv}, + {"dsrlv", R4300i_SPECIAL_DSRLV, base_spec, syn_shiftv}, + {"dsrav", R4300i_SPECIAL_DSRAV, base_spec, syn_shiftv}, + {"mult", R4300i_SPECIAL_MULT, base_spec, syn_arith2}, + {"multu", R4300i_SPECIAL_MULTU, base_spec, syn_arith2}, + {"div", R4300i_SPECIAL_DIV, base_spec, syn_arith2}, + {"divu", R4300i_SPECIAL_DIVU, base_spec, syn_arith2}, + {"dmult", R4300i_SPECIAL_DMULT, base_spec, syn_arith2}, + {"dmultu", R4300i_SPECIAL_DMULTU, base_spec, syn_arith2}, + {"ddiv", R4300i_SPECIAL_DDIV, base_spec, syn_arith2}, + {"ddivu", R4300i_SPECIAL_DDIVU, base_spec, syn_arith2}, + {"add", R4300i_SPECIAL_ADD, base_spec, syn_arith}, + {"addu", R4300i_SPECIAL_ADDU, base_spec, syn_arith}, + {"sub", R4300i_SPECIAL_SUB, base_spec, syn_arith}, + {"subu", R4300i_SPECIAL_SUBU, base_spec, syn_arith}, + {"and", R4300i_SPECIAL_AND, base_spec, syn_arith}, + {"or", R4300i_SPECIAL_OR, base_spec, syn_arith}, + {"xor", R4300i_SPECIAL_XOR, base_spec, syn_arith}, + {"nor", R4300i_SPECIAL_NOR, base_spec, syn_arith}, + {"slt", R4300i_SPECIAL_SLT, base_spec, syn_arith}, + {"sltu", R4300i_SPECIAL_SLTU, base_spec, syn_arith}, + {"dadd", R4300i_SPECIAL_DADD, base_spec, syn_arith}, + {"daddu", R4300i_SPECIAL_DADDU, base_spec, syn_arith}, + {"dsub", R4300i_SPECIAL_DSUB, base_spec, syn_arith}, + {"dsubu", R4300i_SPECIAL_DSUBU, base_spec, syn_arith}, + {"tge", R4300i_SPECIAL_TGE, base_spec, syn_arith2}, // Note: no code field + {"tgeu", R4300i_SPECIAL_TGEU, base_spec, syn_arith2}, // + {"tlt", R4300i_SPECIAL_TLT, base_spec, syn_arith2}, // + {"tltu", R4300i_SPECIAL_TLTU, base_spec, syn_arith2}, // + {"teq", R4300i_SPECIAL_TEQ, base_spec, syn_arith2}, // + {"tne", R4300i_SPECIAL_TNE, base_spec, syn_arith2}, // + {"dsll", R4300i_SPECIAL_DSLL, base_spec, syn_shift}, + {"dsrl", R4300i_SPECIAL_DSRL, base_spec, syn_shift}, + {"dsra", R4300i_SPECIAL_DSRA, base_spec, syn_shift}, + {"dsll32", R4300i_SPECIAL_DSLL32, base_spec, syn_shift}, + {"dsrl32", R4300i_SPECIAL_DSRL32, base_spec, syn_shift}, + {"dsra32", R4300i_SPECIAL_DSRA32, base_spec, syn_shift}, - { "bltz", R4300i_REGIMM_BLTZ, base_regimm, syn_branch_z }, - { "bgez", R4300i_REGIMM_BGEZ, base_regimm, syn_branch_z }, - { "bltzl", R4300i_REGIMM_BLTZL, base_regimm, syn_branch_z }, - { "bgezl", R4300i_REGIMM_BGEZL, base_regimm, syn_branch_z }, - { "tgei", R4300i_REGIMM_TGEI, base_regimm, syn_trap_i }, - { "tgeiu", R4300i_REGIMM_TGEIU, base_regimm, syn_trap_i }, - { "tlti", R4300i_REGIMM_TLTI, base_regimm, syn_trap_i }, - { "tltiu", R4300i_REGIMM_TLTIU, base_regimm, syn_trap_i }, - { "teqi", R4300i_REGIMM_TEQI, base_regimm, syn_trap_i }, - { "tnei", R4300i_REGIMM_TNEI, base_regimm, syn_trap_i }, - { "bltzal", R4300i_REGIMM_BLTZAL, base_regimm, syn_branch_z }, - { "bgezal", R4300i_REGIMM_BGEZAL, base_regimm, syn_branch_z }, - { "bal", R4300i_REGIMM_BGEZAL, base_regimm, syn_branch_unc }, - { "bltzall", R4300i_REGIMM_BLTZALL, base_regimm, syn_branch_z }, - { "bgezall", R4300i_REGIMM_BGEZALL, base_regimm, syn_branch_z }, + {"bltz", R4300i_REGIMM_BLTZ, base_regimm, syn_branch_z}, + {"bgez", R4300i_REGIMM_BGEZ, base_regimm, syn_branch_z}, + {"bltzl", R4300i_REGIMM_BLTZL, base_regimm, syn_branch_z}, + {"bgezl", R4300i_REGIMM_BGEZL, base_regimm, syn_branch_z}, + {"tgei", R4300i_REGIMM_TGEI, base_regimm, syn_trap_i}, + {"tgeiu", R4300i_REGIMM_TGEIU, base_regimm, syn_trap_i}, + {"tlti", R4300i_REGIMM_TLTI, base_regimm, syn_trap_i}, + {"tltiu", R4300i_REGIMM_TLTIU, base_regimm, syn_trap_i}, + {"teqi", R4300i_REGIMM_TEQI, base_regimm, syn_trap_i}, + {"tnei", R4300i_REGIMM_TNEI, base_regimm, syn_trap_i}, + {"bltzal", R4300i_REGIMM_BLTZAL, base_regimm, syn_branch_z}, + {"bgezal", R4300i_REGIMM_BGEZAL, base_regimm, syn_branch_z}, + {"bal", R4300i_REGIMM_BGEZAL, base_regimm, syn_branch_unc}, + {"bltzall", R4300i_REGIMM_BLTZALL, base_regimm, syn_branch_z}, + {"bgezall", R4300i_REGIMM_BGEZALL, base_regimm, syn_branch_z}, - { "mfc0", R4300i_COP0_MF , base_cop0_mv, syn_cop_mv }, - { "mtc0", R4300i_COP0_MT , base_cop0_mv, syn_cop_mv }, + {"mfc0", R4300i_COP0_MF, base_cop0_mv, syn_cop_mv}, + {"mtc0", R4300i_COP0_MT, base_cop0_mv, syn_cop_mv}, - { "tlbr", R4300i_COP0_CO_TLBR, base_cop0_co, nullptr }, - { "tlbwi", R4300i_COP0_CO_TLBWI, base_cop0_co, nullptr }, - { "tlbwr", R4300i_COP0_CO_TLBWR, base_cop0_co, nullptr }, - { "tlbp", R4300i_COP0_CO_TLBP, base_cop0_co, nullptr }, - { "eret", R4300i_COP0_CO_ERET, base_cop0_co, nullptr }, + {"tlbr", R4300i_COP0_CO_TLBR, base_cop0_co, nullptr}, + {"tlbwi", R4300i_COP0_CO_TLBWI, base_cop0_co, nullptr}, + {"tlbwr", R4300i_COP0_CO_TLBWR, base_cop0_co, nullptr}, + {"tlbp", R4300i_COP0_CO_TLBP, base_cop0_co, nullptr}, + {"eret", R4300i_COP0_CO_ERET, base_cop0_co, nullptr}, - { "mfc1", R4300i_COP1_MF, base_cop1_mv, syn_cop_mv }, - { "dmfc1", R4300i_COP1_DMF, base_cop1_mv, syn_cop_mv }, - { "cfc1", R4300i_COP1_CF, base_cop1_mv, syn_cop_mv }, - { "mtc1", R4300i_COP1_MT, base_cop1_mv, syn_cop_mv }, - { "dmtc1", R4300i_COP1_DMT, base_cop1_mv, syn_cop_mv }, - { "ctc1", R4300i_COP1_CT, base_cop1_mv, syn_cop_mv }, + {"mfc1", R4300i_COP1_MF, base_cop1_mv, syn_cop_mv}, + {"dmfc1", R4300i_COP1_DMF, base_cop1_mv, syn_cop_mv}, + {"cfc1", R4300i_COP1_CF, base_cop1_mv, syn_cop_mv}, + {"mtc1", R4300i_COP1_MT, base_cop1_mv, syn_cop_mv}, + {"dmtc1", R4300i_COP1_DMT, base_cop1_mv, syn_cop_mv}, + {"ctc1", R4300i_COP1_CT, base_cop1_mv, syn_cop_mv}, - { "bc1f", R4300i_COP1_BC_BCF, base_cop1_bc, syn_branch_unc }, - { "bc1t", R4300i_COP1_BC_BCT, base_cop1_bc, syn_branch_unc }, - { "bc1fl", R4300i_COP1_BC_BCFL, base_cop1_bc, syn_branch_unc }, - { "bc1tl", R4300i_COP1_BC_BCTL, base_cop1_bc, syn_branch_unc }, + {"bc1f", R4300i_COP1_BC_BCF, base_cop1_bc, syn_branch_unc}, + {"bc1t", R4300i_COP1_BC_BCT, base_cop1_bc, syn_branch_unc}, + {"bc1fl", R4300i_COP1_BC_BCFL, base_cop1_bc, syn_branch_unc}, + {"bc1tl", R4300i_COP1_BC_BCTL, base_cop1_bc, syn_branch_unc}, - { "add.s", R4300i_COP1_FUNCT_ADD, base_cop1_s, syn_cop1_arith }, - { "sub.s", R4300i_COP1_FUNCT_SUB, base_cop1_s, syn_cop1_arith }, - { "mul.s", R4300i_COP1_FUNCT_MUL, base_cop1_s, syn_cop1_arith }, - { "div.s", R4300i_COP1_FUNCT_DIV, base_cop1_s, syn_cop1_arith }, - { "sqrt.s", R4300i_COP1_FUNCT_SQRT, base_cop1_s, syn_cop1 }, - { "abs.s", R4300i_COP1_FUNCT_ABS, base_cop1_s, syn_cop1 }, - { "mov.s", R4300i_COP1_FUNCT_MOV, base_cop1_s, syn_cop1 }, - { "neg.s", R4300i_COP1_FUNCT_NEG, base_cop1_s, syn_cop1 }, - { "round.l.s", R4300i_COP1_FUNCT_ROUND_L, base_cop1_s, syn_cop1 }, - { "trunc.l.s", R4300i_COP1_FUNCT_TRUNC_L, base_cop1_s, syn_cop1 }, - { "ceil.l.s", R4300i_COP1_FUNCT_CEIL_L, base_cop1_s, syn_cop1 }, - { "floor.l.s", R4300i_COP1_FUNCT_FLOOR_L, base_cop1_s, syn_cop1 }, - { "round.w.s", R4300i_COP1_FUNCT_ROUND_W, base_cop1_s, syn_cop1 }, - { "trunc.w.s", R4300i_COP1_FUNCT_TRUNC_W, base_cop1_s, syn_cop1 }, - { "ceil.w.s", R4300i_COP1_FUNCT_CEIL_W, base_cop1_s, syn_cop1 }, - { "floor.w.s", R4300i_COP1_FUNCT_FLOOR_W, base_cop1_s, syn_cop1 }, - { "cvt.s.s", R4300i_COP1_FUNCT_CVT_S, base_cop1_s, syn_cop1 }, - { "cvt.d.s", R4300i_COP1_FUNCT_CVT_D, base_cop1_s, syn_cop1 }, - { "cvt.w.s", R4300i_COP1_FUNCT_CVT_W, base_cop1_s, syn_cop1 }, - { "cvt.l.s", R4300i_COP1_FUNCT_CVT_L, base_cop1_s, syn_cop1 }, - { "c.f.s", R4300i_COP1_FUNCT_C_F, base_cop1_s, syn_cop1_cmp }, - { "c.un.s", R4300i_COP1_FUNCT_C_UN, base_cop1_s, syn_cop1_cmp }, - { "c.eq.s", R4300i_COP1_FUNCT_C_EQ, base_cop1_s, syn_cop1_cmp }, - { "c.ueq.s", R4300i_COP1_FUNCT_C_UEQ, base_cop1_s, syn_cop1_cmp }, - { "c.olt.s", R4300i_COP1_FUNCT_C_OLT, base_cop1_s, syn_cop1_cmp }, - { "c.ult.s", R4300i_COP1_FUNCT_C_ULT, base_cop1_s, syn_cop1_cmp }, - { "c.ole.s", R4300i_COP1_FUNCT_C_OLE, base_cop1_s, syn_cop1_cmp }, - { "c.ule.s", R4300i_COP1_FUNCT_C_ULE, base_cop1_s, syn_cop1_cmp }, - { "c.sf.s", R4300i_COP1_FUNCT_C_SF, base_cop1_s, syn_cop1_cmp }, - { "c.ngle.s", R4300i_COP1_FUNCT_C_NGLE, base_cop1_s, syn_cop1_cmp }, - { "c.seq.s", R4300i_COP1_FUNCT_C_SEQ, base_cop1_s, syn_cop1_cmp }, - { "c.ngl.s", R4300i_COP1_FUNCT_C_NGL, base_cop1_s, syn_cop1_cmp }, - { "c.lt.s", R4300i_COP1_FUNCT_C_LT, base_cop1_s, syn_cop1_cmp }, - { "c.nge.s", R4300i_COP1_FUNCT_C_NGE, base_cop1_s, syn_cop1_cmp }, - { "c.le.s", R4300i_COP1_FUNCT_C_LE, base_cop1_s, syn_cop1_cmp }, - { "c.ngt.s", R4300i_COP1_FUNCT_C_NGT, base_cop1_s, syn_cop1_cmp }, + {"add.s", R4300i_COP1_FUNCT_ADD, base_cop1_s, syn_cop1_arith}, + {"sub.s", R4300i_COP1_FUNCT_SUB, base_cop1_s, syn_cop1_arith}, + {"mul.s", R4300i_COP1_FUNCT_MUL, base_cop1_s, syn_cop1_arith}, + {"div.s", R4300i_COP1_FUNCT_DIV, base_cop1_s, syn_cop1_arith}, + {"sqrt.s", R4300i_COP1_FUNCT_SQRT, base_cop1_s, syn_cop1}, + {"abs.s", R4300i_COP1_FUNCT_ABS, base_cop1_s, syn_cop1}, + {"mov.s", R4300i_COP1_FUNCT_MOV, base_cop1_s, syn_cop1}, + {"neg.s", R4300i_COP1_FUNCT_NEG, base_cop1_s, syn_cop1}, + {"round.l.s", R4300i_COP1_FUNCT_ROUND_L, base_cop1_s, syn_cop1}, + {"trunc.l.s", R4300i_COP1_FUNCT_TRUNC_L, base_cop1_s, syn_cop1}, + {"ceil.l.s", R4300i_COP1_FUNCT_CEIL_L, base_cop1_s, syn_cop1}, + {"floor.l.s", R4300i_COP1_FUNCT_FLOOR_L, base_cop1_s, syn_cop1}, + {"round.w.s", R4300i_COP1_FUNCT_ROUND_W, base_cop1_s, syn_cop1}, + {"trunc.w.s", R4300i_COP1_FUNCT_TRUNC_W, base_cop1_s, syn_cop1}, + {"ceil.w.s", R4300i_COP1_FUNCT_CEIL_W, base_cop1_s, syn_cop1}, + {"floor.w.s", R4300i_COP1_FUNCT_FLOOR_W, base_cop1_s, syn_cop1}, + {"cvt.s.s", R4300i_COP1_FUNCT_CVT_S, base_cop1_s, syn_cop1}, + {"cvt.d.s", R4300i_COP1_FUNCT_CVT_D, base_cop1_s, syn_cop1}, + {"cvt.w.s", R4300i_COP1_FUNCT_CVT_W, base_cop1_s, syn_cop1}, + {"cvt.l.s", R4300i_COP1_FUNCT_CVT_L, base_cop1_s, syn_cop1}, + {"c.f.s", R4300i_COP1_FUNCT_C_F, base_cop1_s, syn_cop1_cmp}, + {"c.un.s", R4300i_COP1_FUNCT_C_UN, base_cop1_s, syn_cop1_cmp}, + {"c.eq.s", R4300i_COP1_FUNCT_C_EQ, base_cop1_s, syn_cop1_cmp}, + {"c.ueq.s", R4300i_COP1_FUNCT_C_UEQ, base_cop1_s, syn_cop1_cmp}, + {"c.olt.s", R4300i_COP1_FUNCT_C_OLT, base_cop1_s, syn_cop1_cmp}, + {"c.ult.s", R4300i_COP1_FUNCT_C_ULT, base_cop1_s, syn_cop1_cmp}, + {"c.ole.s", R4300i_COP1_FUNCT_C_OLE, base_cop1_s, syn_cop1_cmp}, + {"c.ule.s", R4300i_COP1_FUNCT_C_ULE, base_cop1_s, syn_cop1_cmp}, + {"c.sf.s", R4300i_COP1_FUNCT_C_SF, base_cop1_s, syn_cop1_cmp}, + {"c.ngle.s", R4300i_COP1_FUNCT_C_NGLE, base_cop1_s, syn_cop1_cmp}, + {"c.seq.s", R4300i_COP1_FUNCT_C_SEQ, base_cop1_s, syn_cop1_cmp}, + {"c.ngl.s", R4300i_COP1_FUNCT_C_NGL, base_cop1_s, syn_cop1_cmp}, + {"c.lt.s", R4300i_COP1_FUNCT_C_LT, base_cop1_s, syn_cop1_cmp}, + {"c.nge.s", R4300i_COP1_FUNCT_C_NGE, base_cop1_s, syn_cop1_cmp}, + {"c.le.s", R4300i_COP1_FUNCT_C_LE, base_cop1_s, syn_cop1_cmp}, + {"c.ngt.s", R4300i_COP1_FUNCT_C_NGT, base_cop1_s, syn_cop1_cmp}, - { "add.d", R4300i_COP1_FUNCT_ADD, base_cop1_d, syn_cop1_arith }, - { "sub.d", R4300i_COP1_FUNCT_SUB, base_cop1_d, syn_cop1_arith }, - { "mul.d", R4300i_COP1_FUNCT_MUL, base_cop1_d, syn_cop1_arith }, - { "div.d", R4300i_COP1_FUNCT_DIV, base_cop1_d, syn_cop1_arith }, - { "sqrt.d", R4300i_COP1_FUNCT_SQRT, base_cop1_d, syn_cop1 }, - { "abs.d", R4300i_COP1_FUNCT_ABS, base_cop1_d, syn_cop1 }, - { "mov.d", R4300i_COP1_FUNCT_MOV, base_cop1_d, syn_cop1 }, - { "neg.d", R4300i_COP1_FUNCT_NEG, base_cop1_d, syn_cop1 }, - { "round.l.d", R4300i_COP1_FUNCT_ROUND_L, base_cop1_d, syn_cop1 }, - { "trunc.l.d", R4300i_COP1_FUNCT_TRUNC_L, base_cop1_d, syn_cop1 }, - { "ceil.l.d", R4300i_COP1_FUNCT_CEIL_L, base_cop1_d, syn_cop1 }, - { "floor.l.d", R4300i_COP1_FUNCT_FLOOR_L, base_cop1_d, syn_cop1 }, - { "round.w.d", R4300i_COP1_FUNCT_ROUND_W, base_cop1_d, syn_cop1 }, - { "trunc.w.d", R4300i_COP1_FUNCT_TRUNC_W, base_cop1_d, syn_cop1 }, - { "ceil.w.d", R4300i_COP1_FUNCT_CEIL_W, base_cop1_d, syn_cop1 }, - { "floor.w.d", R4300i_COP1_FUNCT_FLOOR_W, base_cop1_d, syn_cop1 }, - { "cvt.s.d", R4300i_COP1_FUNCT_CVT_S, base_cop1_d, syn_cop1 }, - { "cvt.d.d", R4300i_COP1_FUNCT_CVT_D, base_cop1_d, syn_cop1 }, - { "cvt.w.d", R4300i_COP1_FUNCT_CVT_W, base_cop1_d, syn_cop1 }, - { "cvt.l.d", R4300i_COP1_FUNCT_CVT_L, base_cop1_d, syn_cop1 }, - { "c.f.d", R4300i_COP1_FUNCT_C_F, base_cop1_d, syn_cop1_cmp }, - { "c.un.d", R4300i_COP1_FUNCT_C_UN, base_cop1_d, syn_cop1_cmp }, - { "c.eq.d", R4300i_COP1_FUNCT_C_EQ, base_cop1_d, syn_cop1_cmp }, - { "c.ueq.d", R4300i_COP1_FUNCT_C_UEQ, base_cop1_d, syn_cop1_cmp }, - { "c.olt.d", R4300i_COP1_FUNCT_C_OLT, base_cop1_d, syn_cop1_cmp }, - { "c.ult.d", R4300i_COP1_FUNCT_C_ULT, base_cop1_d, syn_cop1_cmp }, - { "c.ole.d", R4300i_COP1_FUNCT_C_OLE, base_cop1_d, syn_cop1_cmp }, - { "c.ule.d", R4300i_COP1_FUNCT_C_ULE, base_cop1_d, syn_cop1_cmp }, - { "c.sf.d", R4300i_COP1_FUNCT_C_SF, base_cop1_d, syn_cop1_cmp }, - { "c.ngle.d", R4300i_COP1_FUNCT_C_NGLE, base_cop1_d, syn_cop1_cmp }, - { "c.seq.d", R4300i_COP1_FUNCT_C_SEQ, base_cop1_d, syn_cop1_cmp }, - { "c.ngl.d", R4300i_COP1_FUNCT_C_NGL, base_cop1_d, syn_cop1_cmp }, - { "c.lt.d", R4300i_COP1_FUNCT_C_LT, base_cop1_d, syn_cop1_cmp }, - { "c.nge.d", R4300i_COP1_FUNCT_C_NGE, base_cop1_d, syn_cop1_cmp }, - { "c.le.d", R4300i_COP1_FUNCT_C_LE, base_cop1_d, syn_cop1_cmp }, - { "c.ngt.d", R4300i_COP1_FUNCT_C_NGT, base_cop1_d, syn_cop1_cmp }, + {"add.d", R4300i_COP1_FUNCT_ADD, base_cop1_d, syn_cop1_arith}, + {"sub.d", R4300i_COP1_FUNCT_SUB, base_cop1_d, syn_cop1_arith}, + {"mul.d", R4300i_COP1_FUNCT_MUL, base_cop1_d, syn_cop1_arith}, + {"div.d", R4300i_COP1_FUNCT_DIV, base_cop1_d, syn_cop1_arith}, + {"sqrt.d", R4300i_COP1_FUNCT_SQRT, base_cop1_d, syn_cop1}, + {"abs.d", R4300i_COP1_FUNCT_ABS, base_cop1_d, syn_cop1}, + {"mov.d", R4300i_COP1_FUNCT_MOV, base_cop1_d, syn_cop1}, + {"neg.d", R4300i_COP1_FUNCT_NEG, base_cop1_d, syn_cop1}, + {"round.l.d", R4300i_COP1_FUNCT_ROUND_L, base_cop1_d, syn_cop1}, + {"trunc.l.d", R4300i_COP1_FUNCT_TRUNC_L, base_cop1_d, syn_cop1}, + {"ceil.l.d", R4300i_COP1_FUNCT_CEIL_L, base_cop1_d, syn_cop1}, + {"floor.l.d", R4300i_COP1_FUNCT_FLOOR_L, base_cop1_d, syn_cop1}, + {"round.w.d", R4300i_COP1_FUNCT_ROUND_W, base_cop1_d, syn_cop1}, + {"trunc.w.d", R4300i_COP1_FUNCT_TRUNC_W, base_cop1_d, syn_cop1}, + {"ceil.w.d", R4300i_COP1_FUNCT_CEIL_W, base_cop1_d, syn_cop1}, + {"floor.w.d", R4300i_COP1_FUNCT_FLOOR_W, base_cop1_d, syn_cop1}, + {"cvt.s.d", R4300i_COP1_FUNCT_CVT_S, base_cop1_d, syn_cop1}, + {"cvt.d.d", R4300i_COP1_FUNCT_CVT_D, base_cop1_d, syn_cop1}, + {"cvt.w.d", R4300i_COP1_FUNCT_CVT_W, base_cop1_d, syn_cop1}, + {"cvt.l.d", R4300i_COP1_FUNCT_CVT_L, base_cop1_d, syn_cop1}, + {"c.f.d", R4300i_COP1_FUNCT_C_F, base_cop1_d, syn_cop1_cmp}, + {"c.un.d", R4300i_COP1_FUNCT_C_UN, base_cop1_d, syn_cop1_cmp}, + {"c.eq.d", R4300i_COP1_FUNCT_C_EQ, base_cop1_d, syn_cop1_cmp}, + {"c.ueq.d", R4300i_COP1_FUNCT_C_UEQ, base_cop1_d, syn_cop1_cmp}, + {"c.olt.d", R4300i_COP1_FUNCT_C_OLT, base_cop1_d, syn_cop1_cmp}, + {"c.ult.d", R4300i_COP1_FUNCT_C_ULT, base_cop1_d, syn_cop1_cmp}, + {"c.ole.d", R4300i_COP1_FUNCT_C_OLE, base_cop1_d, syn_cop1_cmp}, + {"c.ule.d", R4300i_COP1_FUNCT_C_ULE, base_cop1_d, syn_cop1_cmp}, + {"c.sf.d", R4300i_COP1_FUNCT_C_SF, base_cop1_d, syn_cop1_cmp}, + {"c.ngle.d", R4300i_COP1_FUNCT_C_NGLE, base_cop1_d, syn_cop1_cmp}, + {"c.seq.d", R4300i_COP1_FUNCT_C_SEQ, base_cop1_d, syn_cop1_cmp}, + {"c.ngl.d", R4300i_COP1_FUNCT_C_NGL, base_cop1_d, syn_cop1_cmp}, + {"c.lt.d", R4300i_COP1_FUNCT_C_LT, base_cop1_d, syn_cop1_cmp}, + {"c.nge.d", R4300i_COP1_FUNCT_C_NGE, base_cop1_d, syn_cop1_cmp}, + {"c.le.d", R4300i_COP1_FUNCT_C_LE, base_cop1_d, syn_cop1_cmp}, + {"c.ngt.d", R4300i_COP1_FUNCT_C_NGT, base_cop1_d, syn_cop1_cmp}, - { "cvt.s.w", R4300i_COP1_FUNCT_CVT_S, base_cop1_w, syn_cop1 }, - { "cvt.d.w", R4300i_COP1_FUNCT_CVT_D, base_cop1_w, syn_cop1 }, - { "cvt.s.l", R4300i_COP1_FUNCT_CVT_S, base_cop1_l, syn_cop1 }, - { "cvt.d.l", R4300i_COP1_FUNCT_CVT_D, base_cop1_l, syn_cop1 }, - { nullptr } + {"cvt.s.w", R4300i_COP1_FUNCT_CVT_S, base_cop1_w, syn_cop1}, + {"cvt.d.w", R4300i_COP1_FUNCT_CVT_D, base_cop1_w, syn_cop1}, + {"cvt.s.l", R4300i_COP1_FUNCT_CVT_S, base_cop1_l, syn_cop1}, + {"cvt.d.l", R4300i_COP1_FUNCT_CVT_D, base_cop1_l, syn_cop1}, + {nullptr}, }; -const ASM_REGISTER CAssembler::m_Registers[] = -{ - { "r0", 0 },{ "at", 1 },{ "v0", 2 },{ "v1", 3 },{ "a0", 4 },{ "a1", 5 },{ "a2", 6 },{ "a3", 7 }, - { "t0", 8 },{ "t1", 9 },{ "t2", 10 },{ "t3", 11 },{ "t4", 12 },{ "t5", 13 },{ "t6", 14 },{ "t7", 15 }, - { "s0", 16 },{ "s1", 17 },{ "s2", 18 },{ "s3", 19 },{ "s4", 20 },{ "s5", 21 },{ "s6", 22 },{ "s7", 23 }, - { "t8", 24 },{ "t9", 25 },{ "k0", 26 },{ "k1", 27 },{ "gp", 28 },{ "sp", 29 },{ "s8", 30 },{ "ra", 31 }, +const ASM_REGISTER CAssembler::m_Registers[] = { + {"r0", 0}, + {"at", 1}, + {"v0", 2}, + {"v1", 3}, + {"a0", 4}, + {"a1", 5}, + {"a2", 6}, + {"a3", 7}, + {"t0", 8}, + {"t1", 9}, + {"t2", 10}, + {"t3", 11}, + {"t4", 12}, + {"t5", 13}, + {"t6", 14}, + {"t7", 15}, + {"s0", 16}, + {"s1", 17}, + {"s2", 18}, + {"s3", 19}, + {"s4", 20}, + {"s5", 21}, + {"s6", 22}, + {"s7", 23}, + {"t8", 24}, + {"t9", 25}, + {"k0", 26}, + {"k1", 27}, + {"gp", 28}, + {"sp", 29}, + {"s8", 30}, + {"ra", 31}, - { "fp", 30 }, + {"fp", 30}, - { "r0", 0 },{ "r1", 1 },{ "r2", 2 },{ "r3", 3 },{ "r4", 4 },{ "r5", 5 },{ "r6", 6 },{ "r7", 7 }, - { "r8", 8 },{ "r9", 9 },{ "r10", 10 },{ "r11", 11 },{ "r12", 12 },{ "r13", 13 },{ "r14", 14 },{ "r15", 15 }, - { "r16", 16 },{ "r17", 17 },{ "r18", 18 },{ "r19", 19 },{ "r20", 20 },{ "r21", 21 },{ "r22", 22 },{ "r23", 23 }, - { "r24", 24 },{ "r25", 25 },{ "r26", 26 },{ "r27", 27 },{ "r28", 28 },{ "r29", 29 },{ "r30", 30 },{ "r31", 31 }, + {"r0", 0}, + {"r1", 1}, + {"r2", 2}, + {"r3", 3}, + {"r4", 4}, + {"r5", 5}, + {"r6", 6}, + {"r7", 7}, + {"r8", 8}, + {"r9", 9}, + {"r10", 10}, + {"r11", 11}, + {"r12", 12}, + {"r13", 13}, + {"r14", 14}, + {"r15", 15}, + {"r16", 16}, + {"r17", 17}, + {"r18", 18}, + {"r19", 19}, + {"r20", 20}, + {"r21", 21}, + {"r22", 22}, + {"r23", 23}, + {"r24", 24}, + {"r25", 25}, + {"r26", 26}, + {"r27", 27}, + {"r28", 28}, + {"r29", 29}, + {"r30", 30}, + {"r31", 31}, - { "f0", 0 },{ "f1", 1 },{ "f2", 2 },{ "f3", 3 },{ "f4", 4 },{ "f5", 5 },{ "f6", 6 },{ "f7", 7 }, - { "f8", 8 },{ "f9", 9 },{ "f10", 10 },{ "f11", 11 },{ "f12", 12 },{ "f13", 13 },{ "f14", 14 },{ "f15", 15 }, - { "f16", 16 },{ "f17", 17 },{ "f18", 18 },{ "f19", 19 },{ "f20", 20 },{ "f21", 21 },{ "f22", 22 },{ "f23", 23 }, - { "f24", 24 },{ "f25", 25 },{ "f26", 26 },{ "f27", 27 },{ "f28", 28 },{ "f29", 29 },{ "f30", 30 },{ "f31", 31 }, + {"f0", 0}, + {"f1", 1}, + {"f2", 2}, + {"f3", 3}, + {"f4", 4}, + {"f5", 5}, + {"f6", 6}, + {"f7", 7}, + {"f8", 8}, + {"f9", 9}, + {"f10", 10}, + {"f11", 11}, + {"f12", 12}, + {"f13", 13}, + {"f14", 14}, + {"f15", 15}, + {"f16", 16}, + {"f17", 17}, + {"f18", 18}, + {"f19", 19}, + {"f20", 20}, + {"f21", 21}, + {"f22", 22}, + {"f23", 23}, + {"f24", 24}, + {"f25", 25}, + {"f26", 26}, + {"f27", 27}, + {"f28", 28}, + {"f29", 29}, + {"f30", 30}, + {"f31", 31}, - { "revision", 0 },{ "fcsr", 31 },{ "fcs", 31 }, + {"revision", 0}, + {"fcsr", 31}, + {"fcs", 31}, - { "index", 0 },{ "random", 1 },{ "entrylo0", 2 },{ "entrylo1", 3 },{ "context", 4 },{ "pagemask", 5 }, - { "wired", 6 },{ "badvaddr", 8 },{ "count", 9 },{ "entryhi", 10 },{ "compare", 11 },{ "status", 12 }, - { "cause", 13 },{ "epc", 14 },{ "prid", 15 },{ "config", 16 },{ "lladdr", 17 },{ "watchlo", 18 }, - { "watchhi", 19 },{ "xcontext", 20 },{ "ecc", 26 },{ "cacheerr", 27 },{ "taglo", 28 },{ "taghi", 29 }, - { "errepc", 30 }, + {"index", 0}, + {"random", 1}, + {"entrylo0", 2}, + {"entrylo1", 3}, + {"context", 4}, + {"pagemask", 5}, + {"wired", 6}, + {"badvaddr", 8}, + {"count", 9}, + {"entryhi", 10}, + {"compare", 11}, + {"status", 12}, + {"cause", 13}, + {"epc", 14}, + {"prid", 15}, + {"config", 16}, + {"lladdr", 17}, + {"watchlo", 18}, + {"watchhi", 19}, + {"xcontext", 20}, + {"ecc", 26}, + {"cacheerr", 27}, + {"taglo", 28}, + {"taghi", 29}, + {"errepc", 30}, - { nullptr } + {nullptr}, }; bool CAssembler::AssembleLine(const char * line, uint32_t * opcode, uint32_t address) diff --git a/Source/Project64/UserInterface/Debugger/Assembler.h b/Source/Project64/UserInterface/Debugger/Assembler.h index 150ff5d14..dd8a9d2b5 100644 --- a/Source/Project64/UserInterface/Debugger/Assembler.h +++ b/Source/Project64/UserInterface/Debugger/Assembler.h @@ -2,17 +2,19 @@ #include -typedef void(*ASM_SYNTAX_FN)(uint32_t* opcode); +typedef void (*ASM_SYNTAX_FN)(uint32_t * opcode); -typedef struct { - const char* name; +typedef struct +{ + const char * name; uint32_t val; - uint32_t(*base)(uint32_t val); // Value shift - const ASM_SYNTAX_FN* syntax; // Arguments + uint32_t (*base)(uint32_t val); // Value shift + const ASM_SYNTAX_FN * syntax; // Arguments } ASM_INSTRUCTION; -typedef struct { - const char* name; +typedef struct +{ + const char * name; uint32_t val; } ASM_REGISTER; @@ -32,7 +34,7 @@ private: static ASM_PARSE_ERROR m_ParseError; public: - static bool AssembleLine(const char* line, uint32_t* opcode, uint32_t address = 0x00000000); + static bool AssembleLine(const char * line, uint32_t * opcode, uint32_t address = 0x00000000); private: static const ASM_SYNTAX_FN syn_jump[]; @@ -60,16 +62,16 @@ private: static const ASM_INSTRUCTION m_Instructions[]; static const ASM_REGISTER m_Registers[]; - static char* m_TokContext; + static char * m_TokContext; - static const ASM_REGISTER* LookupRegister(char* name); - static const ASM_INSTRUCTION* LookupInstruction(char* name, int nFallback); - - static void StrToLower(char* str); + static const ASM_REGISTER * LookupRegister(char * name); + static const ASM_INSTRUCTION * LookupInstruction(char * name, int nFallback); + + static void StrToLower(char * str); static uint32_t pop_reg(); static uint32_t pop_val(); - + static uint32_t base_op(uint32_t val); static uint32_t base_spec(uint32_t val); static uint32_t base_spec_jalr_ra(uint32_t val); @@ -83,16 +85,16 @@ private: static uint32_t base_cop0_mv(uint32_t val); static uint32_t base_cop1_mv(uint32_t val); - static void arg_reg_t(uint32_t* opcode); - static void arg_reg_s(uint32_t* opcode); - static void arg_reg_d(uint32_t* opcode); - static void arg_reg_ft(uint32_t* opcode); - static void arg_reg_fs(uint32_t* opcode); - static void arg_reg_fd(uint32_t* opcode); - static void arg_jump(uint32_t* opcode); - static void arg_imm16(uint32_t* opcode); - static void arg_bra_target(uint32_t* opcode); - static void arg_shamt(uint32_t* opcode); - static void arg_cache_op(uint32_t* opcode); - static void arg_syscall_code(uint32_t* opcode); + static void arg_reg_t(uint32_t * opcode); + static void arg_reg_s(uint32_t * opcode); + static void arg_reg_d(uint32_t * opcode); + static void arg_reg_ft(uint32_t * opcode); + static void arg_reg_fs(uint32_t * opcode); + static void arg_reg_fd(uint32_t * opcode); + static void arg_jump(uint32_t * opcode); + static void arg_imm16(uint32_t * opcode); + static void arg_bra_target(uint32_t * opcode); + static void arg_shamt(uint32_t * opcode); + static void arg_cache_op(uint32_t * opcode); + static void arg_syscall_code(uint32_t * opcode); }; diff --git a/Source/Project64/UserInterface/Debugger/Breakpoints.cpp b/Source/Project64/UserInterface/Debugger/Breakpoints.cpp index 86488cd26..119b317db 100644 --- a/Source/Project64/UserInterface/Debugger/Breakpoints.cpp +++ b/Source/Project64/UserInterface/Debugger/Breakpoints.cpp @@ -354,12 +354,41 @@ void CBreakpoints::UpdateHaveRegBP(void) m_bHaveRegBP = HaveAnyGPRWriteBP() || HaveAnyGPRReadBP() || HaveHIWriteBP() || HaveHIReadBP() || HaveLOWriteBP() || HaveLOReadBP(); } -void CBreakpoints::ToggleGPRWriteBP(int nReg) { m_GPRWriteBP ^= (1 << nReg); UpdateHaveRegBP(); } -void CBreakpoints::ToggleGPRReadBP(int nReg) { m_GPRReadBP ^= (1 << nReg); UpdateHaveRegBP(); } -void CBreakpoints::ToggleHIWriteBP(void) { m_HIWriteBP = !m_HIWriteBP; UpdateHaveRegBP(); } -void CBreakpoints::ToggleHIReadBP(void) { m_HIReadBP = !m_HIReadBP; UpdateHaveRegBP(); } -void CBreakpoints::ToggleLOWriteBP(void) { m_LOWriteBP = !m_LOWriteBP; UpdateHaveRegBP(); } -void CBreakpoints::ToggleLOReadBP(void) { m_LOReadBP = !m_LOReadBP; UpdateHaveRegBP(); } +void CBreakpoints::ToggleGPRWriteBP(int nReg) +{ + m_GPRWriteBP ^= (1 << nReg); + UpdateHaveRegBP(); +} + +void CBreakpoints::ToggleGPRReadBP(int nReg) +{ + m_GPRReadBP ^= (1 << nReg); + UpdateHaveRegBP(); +} + +void CBreakpoints::ToggleHIWriteBP(void) +{ + m_HIWriteBP = !m_HIWriteBP; + UpdateHaveRegBP(); +} + +void CBreakpoints::ToggleHIReadBP(void) +{ + m_HIReadBP = !m_HIReadBP; + UpdateHaveRegBP(); +} + +void CBreakpoints::ToggleLOWriteBP(void) +{ + m_LOWriteBP = !m_LOWriteBP; + UpdateHaveRegBP(); +} + +void CBreakpoints::ToggleLOReadBP(void) +{ + m_LOReadBP = !m_LOReadBP; + UpdateHaveRegBP(); +} void CBreakpoints::PreUpdateBP() { diff --git a/Source/Project64/UserInterface/Debugger/Breakpoints.h b/Source/Project64/UserInterface/Debugger/Breakpoints.h index 2af62c921..1b2ec9464 100644 --- a/Source/Project64/UserInterface/Debugger/Breakpoints.h +++ b/Source/Project64/UserInterface/Debugger/Breakpoints.h @@ -1,6 +1,6 @@ #pragma once -#include #include +#include class CBreakpoints : private CDebugSettings @@ -20,9 +20,18 @@ public: CBreakpoints(); - const breakpoints_t & ReadMem(void) const { return m_ReadMem; } - const breakpoints_t & WriteMem(void) const { return m_WriteMem; } - const breakpoints_t & Execution(void) const { return m_Execution; } + const breakpoints_t & ReadMem(void) const + { + return m_ReadMem; + } + const breakpoints_t & WriteMem(void) const + { + return m_WriteMem; + } + const breakpoints_t & Execution(void) const + { + return m_Execution; + } BPSTATE ReadBPExists8(uint32_t address); BPSTATE ReadBPExists16(uint32_t address); @@ -57,15 +66,42 @@ public: void ClearMemLocks(void); size_t NumMemLocks(void); - inline bool HaveRegBP(void) { return m_bHaveRegBP; } - inline bool HaveAnyGPRWriteBP(void) { return m_GPRWriteBP != 0; } - inline bool HaveAnyGPRReadBP(void) { return m_GPRReadBP != 0; } - inline bool HaveGPRWriteBP(int nReg) { return (m_GPRWriteBP & (1 << nReg)) != 0; } - inline bool HaveGPRReadBP(int nReg) { return (m_GPRReadBP & (1 << nReg)) != 0; } - inline bool HaveHIWriteBP(void) { return m_HIWriteBP; } - inline bool HaveHIReadBP(void) { return m_HIReadBP; } - inline bool HaveLOWriteBP(void) { return m_LOWriteBP; } - inline bool HaveLOReadBP(void) { return m_LOReadBP; } + inline bool HaveRegBP(void) + { + return m_bHaveRegBP; + } + inline bool HaveAnyGPRWriteBP(void) + { + return m_GPRWriteBP != 0; + } + inline bool HaveAnyGPRReadBP(void) + { + return m_GPRReadBP != 0; + } + inline bool HaveGPRWriteBP(int nReg) + { + return (m_GPRWriteBP & (1 << nReg)) != 0; + } + inline bool HaveGPRReadBP(int nReg) + { + return (m_GPRReadBP & (1 << nReg)) != 0; + } + inline bool HaveHIWriteBP(void) + { + return m_HIWriteBP; + } + inline bool HaveHIReadBP(void) + { + return m_HIReadBP; + } + inline bool HaveLOWriteBP(void) + { + return m_LOWriteBP; + } + inline bool HaveLOReadBP(void) + { + return m_LOReadBP; + } void UpdateHaveRegBP(void); void ToggleGPRWriteBP(int nReg); @@ -74,7 +110,7 @@ public: void ToggleHIReadBP(void); void ToggleLOWriteBP(void); void ToggleLOReadBP(void); - + private: void PreUpdateBP(); void PostUpdateBP(); diff --git a/Source/Project64/UserInterface/Debugger/CPULog.h b/Source/Project64/UserInterface/Debugger/CPULog.h index 7fdb36807..7f6773ba7 100644 --- a/Source/Project64/UserInterface/Debugger/CPULog.h +++ b/Source/Project64/UserInterface/Debugger/CPULog.h @@ -16,7 +16,7 @@ class CCPULog size_t m_Size; bool m_bMaxed; size_t m_Index; - CPUState* m_Array; + CPUState * m_Array; public: CCPULog(size_t size = 0); @@ -24,8 +24,8 @@ public: void PushState(void); size_t GetCount(void); size_t GetSize(void); - CPUState* GetEntry(size_t index); + CPUState * GetEntry(size_t index); void Reset(void); - CCPULog* Clone(void); - void DumpToFile(const char* path); + CCPULog * Clone(void); + void DumpToFile(const char * path); }; diff --git a/Source/Project64/UserInterface/Debugger/DMALog.h b/Source/Project64/UserInterface/Debugger/DMALog.h index 180b1737d..1787d1ea0 100644 --- a/Source/Project64/UserInterface/Debugger/DMALog.h +++ b/Source/Project64/UserInterface/Debugger/DMALog.h @@ -13,12 +13,12 @@ private: vector m_Log; public: - void AddEntry(uint32_t romAddr, uint32_t ramAddr, uint32_t length); - void ClearEntries(); - size_t GetNumEntries(); - DMALOGENTRY* GetEntryByIndex(uint32_t index); - DMALOGENTRY* GetEntryByRamAddress(uint32_t ramAddr); - DMALOGENTRY* GetEntryByRamAddress(uint32_t ramAddr, uint32_t* lpRomAddr, uint32_t* lpOffset); - DMALOGENTRY* GetEntryByRomAddress(uint32_t romAddr); - DMALOGENTRY* GetEntryByRomAddress(uint32_t romAddr, uint32_t* lpRamAddr, uint32_t* lpOffset); + void AddEntry(uint32_t romAddr, uint32_t ramAddr, uint32_t length); + void ClearEntries(); + size_t GetNumEntries(); + DMALOGENTRY * GetEntryByIndex(uint32_t index); + DMALOGENTRY * GetEntryByRamAddress(uint32_t ramAddr); + DMALOGENTRY * GetEntryByRamAddress(uint32_t ramAddr, uint32_t * lpRomAddr, uint32_t * lpOffset); + DMALOGENTRY * GetEntryByRomAddress(uint32_t romAddr); + DMALOGENTRY * GetEntryByRomAddress(uint32_t romAddr, uint32_t * lpRamAddr, uint32_t * lpOffset); }; diff --git a/Source/Project64/UserInterface/Debugger/DebugDialog.h b/Source/Project64/UserInterface/Debugger/DebugDialog.h index f0a716819..5de99eafe 100644 --- a/Source/Project64/UserInterface/Debugger/DebugDialog.h +++ b/Source/Project64/UserInterface/Debugger/DebugDialog.h @@ -3,14 +3,14 @@ #include template class CDebugDialog : - public CDialogImpl < T > + public CDialogImpl { protected: CDebuggerUI * m_Debugger; - HANDLE m_CreatedEvent; - HANDLE m_DialogThread; - UISettingID m_UISettingID; - bool m_bInitialized; + HANDLE m_CreatedEvent; + HANDLE m_DialogThread; + UISettingID m_UISettingID; + bool m_bInitialized; static DWORD CreateDebuggerWindow(CDebugDialog * pThis) { @@ -38,7 +38,7 @@ protected: return; } - T* pT = static_cast(this); + T * pT = static_cast(this); std::string str = UISettingsLoadStringVal(m_UISettingID); int left, top, width, height; int nParams = sscanf(str.c_str(), "%d,%d,%d,%d", &left, &top, &width, &height); @@ -47,7 +47,8 @@ protected: pT->SetWindowPos(nullptr, left, top, width, height, 0); pT->RedrawWindow(); } - if (nParams == 2) { + if (nParams == 2) + { pT->SetWindowPos(nullptr, left, top, width, height, 1); pT->RedrawWindow(); } @@ -60,13 +61,15 @@ protected: return; } - T* pT = static_cast(this); + T * pT = static_cast(this); CRect rect; pT->GetWindowRect(&rect); - if (!bSaveSize) { + if (!bSaveSize) + { UISettingsSaveString(m_UISettingID, stdstr_f("%d,%d", rect.left, rect.top).c_str()); } - else { + else + { UISettingsSaveString(m_UISettingID, stdstr_f("%d,%d,%d,%d", rect.left, rect.top, rect.Width(), rect.Height()).c_str()); } } @@ -122,15 +125,16 @@ public: } if (m_hWnd) { - if (::IsIconic((HWND)m_hWnd)) + if (::IsIconic((HWND)m_hWnd)) { SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, NULL); } SetForegroundWindow((HWND)m_hWnd); } } + private: - bool m_SaveWnd; - LONG m_SaveWndTop; - LONG m_SaveWndLeft; + bool m_SaveWnd; + LONG m_SaveWndTop; + LONG m_SaveWndLeft; }; diff --git a/Source/Project64/UserInterface/Debugger/DebugMMU.h b/Source/Project64/UserInterface/Debugger/DebugMMU.h index fe543bffb..959ae5a2e 100644 --- a/Source/Project64/UserInterface/Debugger/DebugMMU.h +++ b/Source/Project64/UserInterface/Debugger/DebugMMU.h @@ -3,16 +3,17 @@ class CDebugMMU { public: - size_t ReadPhysical(uint32_t paddr, size_t length, uint8_t* buffer); - size_t ReadVirtual(uint32_t vaddr, size_t length, uint8_t* buffer); - size_t WritePhysical(uint32_t paddr, size_t length, uint8_t* buffer); - size_t WriteVirtual(uint32_t vaddr, size_t length, uint8_t* buffer); + size_t ReadPhysical(uint32_t paddr, size_t length, uint8_t * buffer); + size_t ReadVirtual(uint32_t vaddr, size_t length, uint8_t * buffer); + size_t WritePhysical(uint32_t paddr, size_t length, uint8_t * buffer); + size_t WriteVirtual(uint32_t vaddr, size_t length, uint8_t * buffer); - template - bool DebugLoad_PAddr(uint32_t paddr, T& value) + template + bool DebugLoad_PAddr(uint32_t paddr, T & value) { - union { - T word; + union + { + T word; uint8_t bytes[sizeof(T)]; } buffer; @@ -25,11 +26,12 @@ public: return false; } - template - bool DebugLoad_VAddr(uint32_t vaddr, T& value) + template + bool DebugLoad_VAddr(uint32_t vaddr, T & value) { - union { - T word; + union + { + T word; uint8_t bytes[sizeof(T)]; } buffer; @@ -42,39 +44,41 @@ public: return false; } - template + template bool DebugStore_PAddr(uint32_t paddr, T value) { - union { - T word; + union + { + T word; uint8_t bytes[sizeof(T)]; - } buffer = { ByteSwap(value) }; + } buffer = {ByteSwap(value)}; return (WritePhysical(paddr, sizeof(buffer), buffer.bytes) == sizeof(buffer)); } - template + template bool DebugStore_VAddr(uint32_t vaddr, T value) { - union { - T word; + union + { + T word; uint8_t bytes[sizeof(T)]; - } buffer = { ByteSwap(value) }; + } buffer = {ByteSwap(value)}; return (WriteVirtual(vaddr, sizeof(buffer), buffer.bytes) == sizeof(buffer)); } private: - uint8_t* GetPhysicalPtr(uint32_t paddr, WORD* flags = nullptr); - bool GetPhysicalByte(uint32_t paddr, uint8_t* value); - bool SetPhysicalByte(uint32_t paddr, uint8_t value); + uint8_t * GetPhysicalPtr(uint32_t paddr, WORD * flags = nullptr); + bool GetPhysicalByte(uint32_t paddr, uint8_t * value); + bool SetPhysicalByte(uint32_t paddr, uint8_t value); - template + template T ByteSwap(T value) { union { - T value; + T value; uint16_t u16; uint32_t u32; uint64_t u64; @@ -84,15 +88,15 @@ private: switch (sizeof(T)) { - case sizeof(uint8_t) : + case sizeof(uint8_t): break; - case sizeof(uint16_t) : + case sizeof(uint16_t): bytes.u16 = _byteswap_ushort(bytes.u16); break; - case sizeof(uint32_t) : + case sizeof(uint32_t): bytes.u32 = _byteswap_ulong(bytes.u32); break; - case sizeof(uint64_t) : + case sizeof(uint64_t): bytes.u64 = _byteswap_uint64(bytes.u64); break; default: diff --git a/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.h b/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.h index f0e24454b..1f80e6516 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.h @@ -3,32 +3,37 @@ class CAddBreakpointDlg : public CDialogImpl { public: - enum { IDD = IDD_Debugger_AddBreakpoint }; + enum + { + IDD = IDD_Debugger_AddBreakpoint + }; - INT_PTR CAddBreakpointDlg::DoModal(CDebuggerUI* debugger) + INT_PTR CAddBreakpointDlg::DoModal(CDebuggerUI * debugger) { m_Debugger = debugger; return CDialogImpl::DoModal(); } private: - CDebuggerUI* m_Debugger; + CDebuggerUI * m_Debugger; CButton m_ReadCheck; CButton m_WriteCheck; CButton m_ExecuteCheck; - CEdit m_AddressEdit; + CEdit m_AddressEdit; - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnDestroy(void) { return 0; } BEGIN_MSG_MAP_EX(CAddBreakpointDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MSG_WM_DESTROY(OnDestroy) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MSG_WM_DESTROY(OnDestroy); + } END_MSG_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.h b/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.h index 22c8a307a..5161b8e55 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.h @@ -3,14 +3,17 @@ class CAddSymbolDlg : public CDialogImpl { public: - enum { IDD = IDD_Debugger_AddSymbol }; + enum + { + IDD = IDD_Debugger_AddSymbol + }; - INT_PTR DoModal(CDebuggerUI* debugger); - INT_PTR DoModal(CDebuggerUI* debugger, uint32_t initAddress); - INT_PTR DoModal(CDebuggerUI* debugger, uint32_t initAddress, int initType); + INT_PTR DoModal(CDebuggerUI * debugger); + INT_PTR DoModal(CDebuggerUI * debugger, uint32_t initAddress); + INT_PTR DoModal(CDebuggerUI * debugger, uint32_t initAddress, int initType); private: - CDebuggerUI* m_Debugger; + CDebuggerUI * m_Debugger; bool m_bHaveAddress; bool m_bHaveType; @@ -18,20 +21,22 @@ private: int m_InitType; CEditNumber32 m_AddressEdit; - CComboBox m_TypeComboBox; - CEdit m_NameEdit; - CEdit m_DescriptionEdit; + CComboBox m_TypeComboBox; + CEdit m_NameEdit; + CEdit m_DescriptionEdit; - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); LRESULT OnDestroy(void) { return 0; } BEGIN_MSG_MAP_EX(CAddSymbolDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MSG_WM_DESTROY(OnDestroy) - END_MSG_MAP() + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MSG_WM_DESTROY(OnDestroy); + } + END_MSG_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.cpp b/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.cpp index 56867b171..d003773d4 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.cpp @@ -428,8 +428,5 @@ bool CDebugCPULogView::MouseHovering(WORD ctrlId, int xMargin, int yMargin) ::GetCursorPos(&pointerPos); return ( - pointerPos.x >= rect.left - xMargin && - pointerPos.x <= rect.right + xMargin && - pointerPos.y >= rect.top - yMargin && - pointerPos.y <= rect.bottom + yMargin); + pointerPos.x >= rect.left - xMargin && pointerPos.x <= rect.right + xMargin && pointerPos.y >= rect.top - yMargin && pointerPos.y <= rect.bottom + yMargin); } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.h b/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.h index b8edf1ceb..ee3abac65 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-CPULogView.h @@ -1,5 +1,6 @@ #pragma once #include "DebuggerUI.h" +#include class CDebugCPULogView : public CDebugDialog, @@ -7,7 +8,10 @@ class CDebugCPULogView : public CToolTipDialog { public: - enum { IDD = IDD_Debugger_CPULog }; + enum + { + IDD = IDD_Debugger_CPULog + }; CDebugCPULogView(CDebuggerUI * debugger); virtual ~CDebugCPULogView(void); @@ -15,32 +19,31 @@ public: void RefreshList(bool bUpdateBuffer = true); private: - CCPULog* m_CPULogCopy; + CCPULog * m_CPULogCopy; - int m_RowHeight; - int m_LogStartIndex; + int m_RowHeight; + int m_LogStartIndex; CListViewCtrl m_CPUListView; - CEdit m_StateInfoEdit; + CEdit m_StateInfoEdit; CEditNumber32 m_BuffSizeEdit; - CButton m_EnabledChk; - CScrollBar m_Scrollbar; - CButton m_ExportBtn; + CButton m_EnabledChk; + CScrollBar m_Scrollbar; + CButton m_ExportBtn; - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); - LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnListDblClicked(NMHDR* pNMHDR); - LRESULT OnListItemChanged(NMHDR* pNMHDR); - LRESULT OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/); - LRESULT OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/); - void OnExitSizeMove(void); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); + LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnListDblClicked(NMHDR * pNMHDR); + LRESULT OnListItemChanged(NMHDR * pNMHDR); + LRESULT OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/); + LRESULT OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/); + void OnExitSizeMove(void); LRESULT OnDestroy(void); - void InterceptMouseWheel(WPARAM wParam, LPARAM lParam); - static CDebugCPULogView* _this; + static CDebugCPULogView * _this; static HHOOK hWinMessageHook; static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); @@ -48,29 +51,31 @@ private: void ShowRegStates(size_t stateIndex); void Export(void); - int GetNumVisibleRows(CListViewCtrl& list); + int GetNumVisibleRows(CListViewCtrl & list); bool MouseHovering(WORD ctrlId, int xMargin = 0, int yMargin = 0); BEGIN_MSG_MAP_EX(CDebugCPULogView) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MESSAGE_HANDLER(WM_ACTIVATE, OnActivate) - NOTIFY_HANDLER_EX(IDC_CPU_LIST, NM_DBLCLK, OnListDblClicked) - NOTIFY_HANDLER_EX(IDC_CPU_LIST, LVN_ITEMCHANGED, OnListItemChanged) - MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem) - MESSAGE_HANDLER(WM_VSCROLL, OnScroll) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - CHAIN_MSG_MAP(CDialogResize) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MESSAGE_HANDLER(WM_ACTIVATE, OnActivate); + NOTIFY_HANDLER_EX(IDC_CPU_LIST, NM_DBLCLK, OnListDblClicked); + NOTIFY_HANDLER_EX(IDC_CPU_LIST, LVN_ITEMCHANGED, OnListItemChanged); + MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem); + MESSAGE_HANDLER(WM_VSCROLL, OnScroll); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + CHAIN_MSG_MAP(CDialogResize); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugCPULogView) - DLGRESIZE_CONTROL(IDC_CPU_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_REGSTATES_GRP, DLSZ_MOVE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_STATEINFO_EDIT, DLSZ_MOVE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_CPU_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_REGSTATES_GRP, DLSZ_MOVE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_STATEINFO_EDIT, DLSZ_MOVE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_SIZE_Y) END_DLGRESIZE_MAP() BEGIN_TOOLTIP_MAP() - TOOLTIP(IDC_BUFFSIZE_EDIT, "Maximum number of states to keep (1024 = 416kB)") // sizeof(CPUState) + TOOLTIP(IDC_BUFFSIZE_EDIT, "Maximum number of states to keep (1024 = 416kB)") // sizeof(CPUState) END_TOOLTIP_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp index 7ba60aa2a..26233397b 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp @@ -161,9 +161,7 @@ void CDebugCommandsView::RecompilerCheck(void) return; } - if (g_Settings->LoadBool(Debugger_Enabled) && - !g_Settings->LoadBool(Setting_ForceInterpreterCPU) && - (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) + if (g_Settings->LoadBool(Debugger_Enabled) && !g_Settings->LoadBool(Setting_ForceInterpreterCPU) && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) { // TODO: Remove this or fix? MessageBox(L"Debugger support for the recompiler core is experimental.\n\n" @@ -264,9 +262,7 @@ void CDebugCommandsView::AddBranchArrow(int startPos, int endPos) BRANCHARROW arrow = m_BranchArrows[j]; // Arrow's start or end position within another arrow's stride - if ((startPos >= arrow.startPos && startPos <= arrow.endPos) || - (endPos >= arrow.startPos && endPos <= arrow.endPos) || - (arrow.startPos <= startPos && arrow.startPos >= endPos)) + if ((startPos >= arrow.startPos && startPos <= arrow.endPos) || (endPos >= arrow.startPos && endPos <= arrow.endPos) || (arrow.startPos <= startPos && arrow.startPos >= endPos)) { if (margin <= arrow.margin) { @@ -485,8 +481,7 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput } else { - bool bOutOfView = address < m_StartAddress || - address > m_StartAddress + (m_CommandListRows - 1) * 4; + bool bOutOfView = address < m_StartAddress || address > m_StartAddress + (m_CommandListRows - 1) * 4; if (bOutOfView) { @@ -704,17 +699,13 @@ LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR * pNMHDR) { // Breakpoint pLVCD->clrTextBk = RGB(0x44, 0x00, 0x00); - pLVCD->clrText = (address == pc && isDebugging()) ? - RGB(0xFF, 0xFF, 0x00) : // Breakpoint and current PC - RGB(0xFF, 0xCC, 0xCC); + pLVCD->clrText = (address == pc && isDebugging()) ? RGB(0xFF, 0xFF, 0x00) : RGB(0xFF, 0xCC, 0xCC); } else if (bpState == CBreakpoints::BP_SET_TEMP) { // Breakpoint pLVCD->clrTextBk = RGB(0x66, 0x44, 0x00); - pLVCD->clrText = (address == pc && isDebugging()) ? - RGB(0xFF, 0xFF, 0x00) : // Breakpoint and current PC - RGB(0xFF, 0xEE, 0xCC); + pLVCD->clrText = (address == pc && isDebugging()) ? RGB(0xFF, 0xFF, 0x00) : RGB(0xFF, 0xEE, 0xCC); } else if (address == pc && isStepping()) { @@ -867,19 +858,18 @@ LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM l // Draw branch arrows void CDebugCommandsView::DrawBranchArrows(HDC listDC) { - COLORREF colors[] = - { - RGB(240, 240, 240), // White - RGB(30, 135, 255), // Blue - RGB(255, 0, 200), // Pink - RGB(215, 155, 0), // Yellow - RGB(100, 180, 0), // Green - RGB(200, 100, 255), // Purple - RGB(120, 120, 120), // Gray - RGB(0, 220, 160), // Cyan - RGB(255, 100, 0), // Orange - RGB(255, 255, 0), // Yellow - }; + COLORREF colors[] = { + RGB(240, 240, 240), // White + RGB(30, 135, 255), // Blue + RGB(255, 0, 200), // Pink + RGB(215, 155, 0), // Yellow + RGB(100, 180, 0), // Green + RGB(200, 100, 255), // Purple + RGB(120, 120, 120), // Gray + RGB(0, 220, 160), // Cyan + RGB(255, 100, 0), // Orange + RGB(255, 255, 0), // Yellow + }; int nColors = sizeof(colors) / sizeof(COLORREF); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.h b/Source/Project64/UserInterface/Debugger/Debugger-Commands.h index 1e0722fd7..d2a8adb5d 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.h @@ -1,9 +1,9 @@ #pragma once -#include "OpInfo.h" #include "Breakpoints.h" #include "Debugger-AddBreakpoint.h" #include "Debugger-RegisterTabs.h" +#include "OpInfo.h" #include @@ -32,10 +32,10 @@ class CDebugCommandsView; class CEditOp : public CWindowImpl { private: - CDebugCommandsView* m_CommandsWindow; + CDebugCommandsView * m_CommandsWindow; - LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnKeyUp(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) + LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnKeyUp(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled) { if (wParam == VK_RETURN || wParam == VK_ESCAPE) { @@ -47,13 +47,15 @@ private: } BEGIN_MSG_MAP_EX(CEditOp) - MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) - MESSAGE_HANDLER(WM_KEYUP, OnKeyUp) - MESSAGE_HANDLER(WM_CHAR, OnKeyUp) + { + MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown); + MESSAGE_HANDLER(WM_KEYUP, OnKeyUp); + MESSAGE_HANDLER(WM_CHAR, OnKeyUp); + } END_MSG_MAP() public: - void SetCommandsWindow(CDebugCommandsView* commandsWindow); + void SetCommandsWindow(CDebugCommandsView * commandsWindow); BOOL Attach(HWND hWndNew); }; @@ -66,9 +68,12 @@ class CDebugCommandsView : friend class CEditOp; public: - enum { IDD = IDD_Debugger_Commands }; + enum + { + IDD = IDD_Debugger_Commands + }; - CDebugCommandsView(CDebuggerUI * debugger, SyncEvent &StepEvent); + CDebugCommandsView(CDebuggerUI * debugger, SyncEvent & StepEvent); virtual ~CDebugCommandsView(void); void ShowAddress(uint32_t address, bool top, bool bUserInput = false); @@ -78,136 +83,144 @@ public: private: BEGIN_MSG_MAP_EX(CDebugCommandsView) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_ACTIVATE, OnActivate) - MESSAGE_HANDLER(WM_SIZING, OnSizing) - MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo) - MESSAGE_HANDLER(WM_VSCROLL, OnScroll) - MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem) - COMMAND_HANDLER(IDC_ADDR_EDIT, EN_CHANGE, OnAddrChanged) - COMMAND_HANDLER(IDC_PC_EDIT, EN_CHANGE, OnPCChanged) - COMMAND_CODE_HANDLER(LBN_DBLCLK, OnListBoxClicked) - COMMAND_HANDLER(IDC_BACK_BTN, BN_CLICKED, OnBackButton) - COMMAND_HANDLER(IDC_FORWARD_BTN, BN_CLICKED, OnForwardButton) - COMMAND_HANDLER(IDC_VIEWPC_BTN, BN_CLICKED, OnViewPCButton) - COMMAND_HANDLER(IDC_SYMBOLS_BTN, BN_CLICKED, OnSymbolsButton) - COMMAND_HANDLER(ID_POPUPMENU_RUNTO, BN_CLICKED, OnPopupmenuRunTo) - COMMAND_HANDLER(IDC_GO_BTN, BN_CLICKED, OnGoButton) - COMMAND_HANDLER(IDC_STEP_BTN, BN_CLICKED, OnStepButton) - COMMAND_HANDLER(IDC_STEPOVER_BTN, BN_CLICKED, OnStepOverButton) - COMMAND_HANDLER(IDC_SKIP_BTN, BN_CLICKED, OnSkipButton) - COMMAND_HANDLER(IDC_CLEARBP_BTN, BN_CLICKED, OnClearBPButton) - COMMAND_HANDLER(IDC_ADDBP_BTN, BN_CLICKED, OnAddBPButton) - COMMAND_HANDLER(IDC_RMBP_BTN, BN_CLICKED, OnRemoveBPButton) - COMMAND_HANDLER(IDC_COPYTABREGISTERS_BTN, BN_CLICKED, OnCopyTabRegistersButton) - COMMAND_HANDLER(IDC_COPYALLREGISTERS_BTN, BN_CLICKED, OnCopyAllRegistersButton) - COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) - COMMAND_HANDLER(ID_POPUPMENU_EDIT, BN_CLICKED, OnPopupmenuEdit) - COMMAND_HANDLER(ID_POPUPMENU_INSERTNOP, BN_CLICKED, OnPopupmenuInsertNOP) - COMMAND_HANDLER(ID_POPUPMENU_RESTORE, BN_CLICKED, OnPopupmenuRestore) - COMMAND_HANDLER(ID_POPUPMENU_RESTOREALL, BN_CLICKED, OnPopupmenuRestoreAll) - COMMAND_HANDLER(ID_POPUPMENU_ADDSYMBOL, BN_CLICKED, OnPopupmenuAddSymbol) - COMMAND_HANDLER(ID_POPUPMENU_FOLLOWJUMP, BN_CLICKED, OnPopupmenuFollowJump) - COMMAND_HANDLER(ID_POPUPMENU_VIEWMEMORY, BN_CLICKED, OnPopupmenuViewMemory) - COMMAND_HANDLER(ID_POPUPMENU_TOGGLEBP, BN_CLICKED, OnPopupmenuToggleBP) - COMMAND_HANDLER(ID_POPUPMENU_CLEARBPS, BN_CLICKED, OnPopupmenuClearBP) - COMMAND_HANDLER(IDC_OP_EDIT, EN_CHANGE, OnOpEditChanged) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_ACTIVATE, OnActivate); + MESSAGE_HANDLER(WM_SIZING, OnSizing); + MESSAGE_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo); + MESSAGE_HANDLER(WM_VSCROLL, OnScroll); + MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem); + COMMAND_HANDLER(IDC_ADDR_EDIT, EN_CHANGE, OnAddrChanged); + COMMAND_HANDLER(IDC_PC_EDIT, EN_CHANGE, OnPCChanged); + COMMAND_CODE_HANDLER(LBN_DBLCLK, OnListBoxClicked); + COMMAND_HANDLER(IDC_BACK_BTN, BN_CLICKED, OnBackButton); + COMMAND_HANDLER(IDC_FORWARD_BTN, BN_CLICKED, OnForwardButton); + COMMAND_HANDLER(IDC_VIEWPC_BTN, BN_CLICKED, OnViewPCButton); + COMMAND_HANDLER(IDC_SYMBOLS_BTN, BN_CLICKED, OnSymbolsButton); + COMMAND_HANDLER(ID_POPUPMENU_RUNTO, BN_CLICKED, OnPopupmenuRunTo); + COMMAND_HANDLER(IDC_GO_BTN, BN_CLICKED, OnGoButton); + COMMAND_HANDLER(IDC_STEP_BTN, BN_CLICKED, OnStepButton); + COMMAND_HANDLER(IDC_STEPOVER_BTN, BN_CLICKED, OnStepOverButton); + COMMAND_HANDLER(IDC_SKIP_BTN, BN_CLICKED, OnSkipButton); + COMMAND_HANDLER(IDC_CLEARBP_BTN, BN_CLICKED, OnClearBPButton); + COMMAND_HANDLER(IDC_ADDBP_BTN, BN_CLICKED, OnAddBPButton); + COMMAND_HANDLER(IDC_RMBP_BTN, BN_CLICKED, OnRemoveBPButton); + COMMAND_HANDLER(IDC_COPYTABREGISTERS_BTN, BN_CLICKED, OnCopyTabRegistersButton); + COMMAND_HANDLER(IDC_COPYALLREGISTERS_BTN, BN_CLICKED, OnCopyAllRegistersButton); + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel); + COMMAND_HANDLER(ID_POPUPMENU_EDIT, BN_CLICKED, OnPopupmenuEdit); + COMMAND_HANDLER(ID_POPUPMENU_INSERTNOP, BN_CLICKED, OnPopupmenuInsertNOP); + COMMAND_HANDLER(ID_POPUPMENU_RESTORE, BN_CLICKED, OnPopupmenuRestore); + COMMAND_HANDLER(ID_POPUPMENU_RESTOREALL, BN_CLICKED, OnPopupmenuRestoreAll); + COMMAND_HANDLER(ID_POPUPMENU_ADDSYMBOL, BN_CLICKED, OnPopupmenuAddSymbol); + COMMAND_HANDLER(ID_POPUPMENU_FOLLOWJUMP, BN_CLICKED, OnPopupmenuFollowJump); + COMMAND_HANDLER(ID_POPUPMENU_VIEWMEMORY, BN_CLICKED, OnPopupmenuViewMemory); + COMMAND_HANDLER(ID_POPUPMENU_TOGGLEBP, BN_CLICKED, OnPopupmenuToggleBP); + COMMAND_HANDLER(ID_POPUPMENU_CLEARBPS, BN_CLICKED, OnPopupmenuClearBP); + COMMAND_HANDLER(IDC_OP_EDIT, EN_CHANGE, OnOpEditChanged); - NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CLICK, OnCommandListClicked) - NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_DBLCLK, OnCommandListDblClicked) - NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_RCLICK, OnCommandListRightClicked) - NOTIFY_HANDLER_EX(IDC_REG_TABS, TCN_SELCHANGE, OnRegisterTabChange) - NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CUSTOMDRAW, OnCustomDrawList) - - MSG_WM_DESTROY(OnDestroy) - CHAIN_MSG_MAP(CDialogResize) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) + NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CLICK, OnCommandListClicked); + NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_DBLCLK, OnCommandListDblClicked); + NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_RCLICK, OnCommandListRightClicked); + NOTIFY_HANDLER_EX(IDC_REG_TABS, TCN_SELCHANGE, OnRegisterTabChange); + NOTIFY_HANDLER_EX(IDC_CMD_LIST, NM_CUSTOMDRAW, OnCustomDrawList); + + MSG_WM_DESTROY(OnDestroy); + CHAIN_MSG_MAP(CDialogResize); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugCommandsView) - DLGRESIZE_CONTROL(IDC_GO_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_STEP_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_STEPOVER_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_SKIP_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_ADDR_EDIT, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_SYMBOLS_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_OPCODE_BOX, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BP_LIST, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_ADDBP_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_RMBP_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CLEARBP_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_COPYTABREGISTERS_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_COPYALLREGISTERS_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_REG_TABS, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BACK_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_FORWARD_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_PC_STATIC, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_PC_EDIT, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_VIEWPC_BTN, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CMD_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_MOVE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_GO_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_STEP_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_STEPOVER_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_SKIP_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_ADDR_EDIT, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_SYMBOLS_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_OPCODE_BOX, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BP_LIST, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_ADDBP_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_RMBP_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CLEARBP_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_COPYTABREGISTERS_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_COPYALLREGISTERS_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_REG_TABS, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BACK_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_FORWARD_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_PC_STATIC, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_PC_EDIT, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_VIEWPC_BTN, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CMD_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_MOVE_X | DLSZ_SIZE_Y) END_DLGRESIZE_MAP() BEGIN_TOOLTIP_MAP() - TOOLTIP(IDC_SKIP_BTN, "Skip (F1)") - TOOLTIP(IDC_STEP_BTN, "Step (F2)") - TOOLTIP(IDC_STEPOVER_BTN, "Step Over (F3)") - TOOLTIP(IDC_GO_BTN, "Go (F4)") - TOOLTIP(IDC_ADDBP_BTN, "Add breakpoint...") - TOOLTIP(IDC_RMBP_BTN, "Remove selected breakpoint") - TOOLTIP(IDC_CLEARBP_BTN, "Remove all breakpoints") - TOOLTIP(IDC_VIEWPC_BTN, "Jump to program counter") - TOOLTIP(IDC_BP_LIST, "Active breakpoints") - TOOLTIP(IDC_SYMBOLS_BTN, "Symbols...") + TOOLTIP(IDC_SKIP_BTN, "Skip (F1)") + TOOLTIP(IDC_STEP_BTN, "Step (F2)") + TOOLTIP(IDC_STEPOVER_BTN, "Step Over (F3)") + TOOLTIP(IDC_GO_BTN, "Go (F4)") + TOOLTIP(IDC_ADDBP_BTN, "Add breakpoint...") + TOOLTIP(IDC_RMBP_BTN, "Remove selected breakpoint") + TOOLTIP(IDC_CLEARBP_BTN, "Remove all breakpoints") + TOOLTIP(IDC_VIEWPC_BTN, "Jump to program counter") + TOOLTIP(IDC_BP_LIST, "Active breakpoints") + TOOLTIP(IDC_SYMBOLS_BTN, "Symbols...") END_TOOLTIP_MAP() - static void StaticSteppingOpsChanged(CDebugCommandsView * __this) { __this->SteppingOpsChanged(); } - static void StaticWaitingForStepChanged(CDebugCommandsView * __this) { __this->WaitingForStepChanged(); } - static void GameCpuRunningChanged(CDebugCommandsView* _this); + static void StaticSteppingOpsChanged(CDebugCommandsView * __this) + { + __this->SteppingOpsChanged(); + } + static void StaticWaitingForStepChanged(CDebugCommandsView * __this) + { + __this->WaitingForStepChanged(); + } + static void GameCpuRunningChanged(CDebugCommandsView * _this); void RecompilerCheck(void); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnSizing(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnPCChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnListBoxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnBackButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnForwardButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnViewPCButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnSymbolsButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuRunTo(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnGoButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnStepButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnStepOverButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnSkipButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnClearBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnAddBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnRemoveBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnCopyTabRegistersButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnCopyAllRegistersButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuEdit(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuInsertNOP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuRestore(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuRestoreAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuFollowJump(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuToggleBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnPopupmenuClearBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnOpEditChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnOpEditKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnSizing(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnPCChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnListBoxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnBackButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnForwardButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnViewPCButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnSymbolsButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuRunTo(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnGoButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnStepButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnStepOverButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnSkipButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnClearBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnAddBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnRemoveBPButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnCopyTabRegistersButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnCopyAllRegistersButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuEdit(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuInsertNOP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuRestore(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuRestoreAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuFollowJump(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuToggleBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnPopupmenuClearBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnOpEditChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnOpEditKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); - LRESULT OnCommandListClicked(NMHDR* pNMHDR); - LRESULT OnCommandListDblClicked(NMHDR* pNMHDR); - LRESULT OnCommandListRightClicked(NMHDR* pNMHDR); - LRESULT OnRegisterTabChange(NMHDR* pNMHDR); - LRESULT OnCustomDrawList(NMHDR* pNMHDR); + LRESULT OnCommandListClicked(NMHDR * pNMHDR); + LRESULT OnCommandListDblClicked(NMHDR * pNMHDR); + LRESULT OnCommandListRightClicked(NMHDR * pNMHDR); + LRESULT OnRegisterTabChange(NMHDR * pNMHDR); + LRESULT OnCustomDrawList(NMHDR * pNMHDR); LRESULT OnDestroy(void); void OnExitSizeMove(void); @@ -225,14 +238,14 @@ private: void HistoryPushState(); void ToggleHistoryButtons(); - static CDebugCommandsView* _this; + static CDebugCommandsView * _this; static HHOOK hWinMessageHook; static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); void InterceptKeyDown(WPARAM wParam, LPARAM lParam); void InterceptMouseWheel(WPARAM wParam, LPARAM lParam); - static const char* GetCodeAddressNotes(uint32_t vAddr); - static const char* GetDataAddressNotes(uint32_t vAddr); + static const char * GetCodeAddressNotes(uint32_t vAddr); + static const char * GetDataAddressNotes(uint32_t vAddr); void CPUSkip(); void CPUResume(); @@ -246,7 +259,7 @@ private: void RedrawCommandsAndRegisters(); - CBreakpoints* m_Breakpoints; + CBreakpoints * m_Breakpoints; vector m_History; int m_HistoryIndex; @@ -278,11 +291,11 @@ private: CButton m_GoButton; bool m_bEditing; - CEditOp m_OpEdit; + CEditOp m_OpEdit; uint32_t m_SelectedAddress; - COpInfo m_SelectedOpInfo; - R4300iOpcode& m_SelectedOpCode = m_SelectedOpInfo.m_OpCode; + COpInfo m_SelectedOpInfo; + R4300iOpcode & m_SelectedOpCode = m_SelectedOpInfo.m_OpCode; uint32_t m_FollowAddress; uint32_t m_RowHeight; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp index bf49952a0..3df63f4f1 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp @@ -136,11 +136,7 @@ void CDebugDMALogView::Export(void) wsprintf(filePath, L"*.csv"); - const TCHAR * filters = ( - /*1*/ L"Comma separated values (*.csv)\0*.csv;\0" - /*2*/ L"Plain text (*.txt)\0*.txt;\0" - ); - + const TCHAR * filters = L"Comma separated values (*.csv)\0*.csv;\0Plain text (*.txt)\0*.txt;\0"; const char * extensions[] = {"", ".csv", ".txt"}; openfilename.lStructSize = sizeof(openfilename); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h index 933e8dab3..af7a7bf7f 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h @@ -6,7 +6,10 @@ class CDebugDMALogView : public CDialogResize { public: - enum { IDD = IDD_Debugger_DMALog }; + enum + { + IDD = IDD_Debugger_DMALog + }; CDebugDMALogView(CDebuggerUI * debugger); virtual ~CDebugDMALogView(void); @@ -22,7 +25,7 @@ private: void RefreshList(void); void Export(void); - CDMALog* m_DMALog; + CDMALog * m_DMALog; int m_nLastStartIndex; bool m_bConvertingAddress; @@ -34,43 +37,45 @@ private: bool FilterEntry(int dmaLogIndex); CListViewCtrl m_DMAList; - CEdit m_DMARamEdit; - CEdit m_DMARomEdit; - CStatic m_BlockInfo; + CEdit m_DMARamEdit; + CEdit m_DMARomEdit; + CStatic m_BlockInfo; bool m_bCustomDrawClrNext; - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnRefresh(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); - LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnRamAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnRomAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCustomDrawList(NMHDR* pNMHDR); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnRefresh(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); + LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnRamAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnRomAddrChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCustomDrawList(NMHDR * pNMHDR); LRESULT OnDestroy(void); void OnExitSizeMove(void); BEGIN_MSG_MAP_EX(CDebugDMALogView) - MESSAGE_HANDLER(WM_REFRESH, OnRefresh) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MESSAGE_HANDLER(WM_ACTIVATE, OnActivate) - COMMAND_HANDLER(IDC_DMA_RAM_EDIT, EN_CHANGE, OnRamAddrChanged) - COMMAND_HANDLER(IDC_DMA_ROM_EDIT, EN_CHANGE, OnRomAddrChanged) - NOTIFY_HANDLER_EX(IDC_DMA_LIST, NM_CUSTOMDRAW, OnCustomDrawList) - CHAIN_MSG_MAP(CDialogResize) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) + { + MESSAGE_HANDLER(WM_REFRESH, OnRefresh); + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MESSAGE_HANDLER(WM_ACTIVATE, OnActivate); + COMMAND_HANDLER(IDC_DMA_RAM_EDIT, EN_CHANGE, OnRamAddrChanged); + COMMAND_HANDLER(IDC_DMA_ROM_EDIT, EN_CHANGE, OnRomAddrChanged); + NOTIFY_HANDLER_EX(IDC_DMA_LIST, NM_CUSTOMDRAW, OnCustomDrawList); + CHAIN_MSG_MAP(CDialogResize); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugDMALogView) - DLGRESIZE_CONTROL(IDC_DMA_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_TRACE_STATIC, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_BLOCK_INFO, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_RAM_STATIC, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_ROM_STATIC, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_DMA_ROM_EDIT, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_DMA_RAM_EDIT, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_CLEAR_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_EXPORT_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_DMA_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_TRACE_STATIC, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_BLOCK_INFO, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_RAM_STATIC, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_ROM_STATIC, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_DMA_ROM_EDIT, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_DMA_RAM_EDIT, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_CLEAR_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_EXPORT_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) END_DLGRESIZE_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.cpp b/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.cpp index a08cb1396..50fccba02 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.cpp @@ -21,7 +21,7 @@ CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::ExcCheckboxMap[] = { {IDC_CHK_FPE, 15}, {IDC_CHK_WATCH, 23}, {IDC_CHK_VCED, 31}, - { 0, 0 } + {0, 0}, }; CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::FpExcCheckboxMap[] = { @@ -31,7 +31,7 @@ CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::FpExcCheckboxMap[] = {IDC_CHK_FP_CZ, (1 << 3)}, {IDC_CHK_FP_CV, (1 << 4)}, {IDC_CHK_FP_CE, (1 << 5)}, - { 0, 0 } + {0, 0}, }; CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::IntrCheckboxMap[] = { @@ -43,7 +43,7 @@ CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::IntrCheckboxMap[] = {IDC_CHK_INTR_IP5, (1 << 5)}, {IDC_CHK_INTR_IP6, (1 << 6)}, {IDC_CHK_INTR_IP7, (1 << 7)}, - { 0, 0 } + {0, 0}, }; CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::RcpIntrCheckboxMap[] = { @@ -53,7 +53,7 @@ CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::RcpIntrCheckboxMap[] {IDC_CHK_INTR_VI, (1 << 3)}, {IDC_CHK_INTR_PI, (1 << 4)}, {IDC_CHK_INTR_DP, (1 << 5)}, - { 0, 0 } + {0, 0}, }; CDebugExcBreakpoints::CDebugExcBreakpoints(CDebuggerUI * debugger) : diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.h b/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.h index 56e213ff0..cdbefc90e 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-ExceptionBreakpoints.h @@ -1,7 +1,6 @@ #pragma once #include "DebuggerUI.h" - class CDebugExcBreakpoints : public CDebugDialog { @@ -12,7 +11,10 @@ class CDebugExcBreakpoints : } ExcCheckboxMeta; public: - enum { IDD = IDD_Debugger_ExceptionBP }; + enum + { + IDD = IDD_Debugger_ExceptionBP + }; CDebugExcBreakpoints(CDebuggerUI * debugger); virtual ~CDebugExcBreakpoints(void); @@ -23,20 +25,22 @@ private: static ExcCheckboxMeta IntrCheckboxMap[]; static ExcCheckboxMeta RcpIntrCheckboxMap[]; - void InitCheckboxes(ExcCheckboxMeta* checkboxMap, SettingID settingID, bool bShift = false); - void UpdateBpSetting(ExcCheckboxMeta* checkboxMap, SettingID settingID, WORD wID, bool bChecked, bool bShift = false); - void EnableCheckboxes(ExcCheckboxMeta* checkboxMap, bool bEnable); + void InitCheckboxes(ExcCheckboxMeta * checkboxMap, SettingID settingID, bool bShift = false); + void UpdateBpSetting(ExcCheckboxMeta * checkboxMap, SettingID settingID, WORD wID, bool bChecked, bool bShift = false); + void EnableCheckboxes(ExcCheckboxMeta * checkboxMap, bool bEnable); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); - - void OnExitSizeMove(void); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); + + void OnExitSizeMove(void); LRESULT OnDestroy(void); BEGIN_MSG_MAP_EX(CDebugExcBreakpoints) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_DESTROY(OnDestroy) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + MSG_WM_DESTROY(OnDestroy); + } END_MSG_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-MemoryDump.h b/Source/Project64/UserInterface/Debugger/Debugger-MemoryDump.h index 1b6ffb708..649b41eef 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-MemoryDump.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-MemoryDump.h @@ -1,18 +1,21 @@ #pragma once class CDumpMemory : - public CDebugDialog < CDumpMemory > + public CDebugDialog { public: - enum { IDD = IDD_Cheats_DumpMemory }; + enum + { + IDD = IDD_Cheats_DumpMemory + }; CDumpMemory(CDebuggerUI * debugger); virtual ~CDumpMemory(void); private: CDumpMemory(void); - CDumpMemory(const CDumpMemory&); - CDumpMemory& operator=(const CDumpMemory&); + CDumpMemory(const CDumpMemory &); + CDumpMemory & operator=(const CDumpMemory &); enum DumpFormat { @@ -21,18 +24,20 @@ private: }; BEGIN_MSG_MAP_EX(CDumpMemory) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); MSG_WM_EXITSIZEMOVE(OnExitSizeMove); - END_MSG_MAP() + } + END_MSG_MAP() - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); void OnExitSizeMove(void); bool DumpMemory(LPCTSTR FileName, DumpFormat Format, DWORD StartPC, DWORD EndPC, DWORD DumpPC); - CComboBox m_FormatList; - CEdit m_FileName; + CComboBox m_FormatList; + CEdit m_FileName; CEditNumber32 m_StartAddress, m_EndAddress, m_PC; }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp index 3f5af8eb8..67c039331 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp @@ -18,7 +18,7 @@ const CSetValueDlg::ComboItem CDebugMemorySearch::ModalChangeTypeItems[] = { {"float", ValueType_float}, {"double", ValueType_double}, {"string", ValueType_string}, - { nullptr, 0 } + {nullptr, 0}, }; CDebugMemorySearch::CDebugMemorySearch(CDebuggerUI * debugger) : @@ -1448,10 +1448,7 @@ bool CDebugMemorySearch::MouseHovering(WORD ctrlId, int hMargin, int vMargin) ::GetWindowRect(GetDlgItem(ctrlId), &ctrlRect); return ( - pointerPos.x >= ctrlRect.left - hMargin && - pointerPos.x <= ctrlRect.right + hMargin && - pointerPos.y >= ctrlRect.top - vMargin && - pointerPos.y <= ctrlRect.bottom + vMargin); + pointerPos.x >= ctrlRect.left - hMargin && pointerPos.x <= ctrlRect.right + hMargin && pointerPos.y >= ctrlRect.top - vMargin && pointerPos.y <= ctrlRect.bottom + vMargin); } void CDebugMemorySearch::SeparatorMoveCtrl(WORD ctrlId, int yChange, bool bResize) @@ -1757,10 +1754,7 @@ void CDebugMemorySearch::UpdateOptions(void) m_SearchValue.EnableWindow(TRUE); - if (searchType == SearchType_JalTo || - valueType == ValueType_string || - valueType == ValueType_istring || - valueType == ValueType_unkstring) + if (searchType == SearchType_JalTo || valueType == ValueType_string || valueType == ValueType_istring || valueType == ValueType_unkstring) { // Complex search types, disable next search ::EnableWindow(GetDlgItem(IDC_BTN_SEARCH), false); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h index fb7847d3f..726ed3309 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h @@ -1,7 +1,7 @@ #pragma once -#include "MemoryScanner.h" #include "Debugger-AddSymbol.h" +#include "MemoryScanner.h" class CEditMixed : public CWindowImpl, @@ -16,18 +16,18 @@ public: DisplayFormat GetDisplayFormat(void); void SetDisplayFormat(DisplayFormat fmt); - bool GetValue(uint8_t& value); - bool GetValue(int8_t& value); - bool GetValue(uint16_t& value); - bool GetValue(int16_t& value); - bool GetValue(uint32_t& value); - bool GetValue(int32_t& value); - bool GetValue(uint64_t& value); - bool GetValue(int64_t& value); - bool GetValue(float& value); - bool GetValue(double& value); - bool GetValueString(const wchar_t*& value, int& length); - bool GetValueHexString(const wchar_t*& value, int& length); + bool GetValue(uint8_t & value); + bool GetValue(int8_t & value); + bool GetValue(uint16_t & value); + bool GetValue(int16_t & value); + bool GetValue(uint32_t & value); + bool GetValue(int32_t & value); + bool GetValue(uint64_t & value); + bool GetValue(int64_t & value); + bool GetValue(float & value); + bool GetValue(double & value); + bool GetValueString(const wchar_t *& value, int & length); + bool GetValueHexString(const wchar_t *& value, int & length); BEGIN_MSG_MAP_EX(CEditMixed) END_MSG_MAP() @@ -35,7 +35,7 @@ public: private: ValueType m_Type; DisplayFormat m_DisplayFormat; - wchar_t *m_String; + wchar_t * m_String; int m_StringLength; void ReloadString(void); }; @@ -44,33 +44,38 @@ class CSetValueDlg : public CDialogImpl { public: BEGIN_MSG_MAP_EX(CSetValueDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_HANDLER(IDOK, BN_CLICKED, OnOK) - COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) - MSG_WM_DESTROY(OnDestroy) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_HANDLER(IDOK, BN_CLICKED, OnOK); + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel); + MSG_WM_DESTROY(OnDestroy); + } END_MSG_MAP() - enum { IDD = IDD_Debugger_Search_SetValue }; + enum + { + IDD = IDD_Debugger_Search_SetValue + }; typedef struct { - const char* str; + const char * str; DWORD_PTR data; } ComboItem; CSetValueDlg(void); virtual ~CSetValueDlg(void); - INT_PTR DoModal(const char* caption, const char* label, const char* initialText); - INT_PTR DoModal(const char* caption, const char* label, DWORD_PTR initialData, const ComboItem items[]); + INT_PTR DoModal(const char * caption, const char * label, const char * initialText); + INT_PTR DoModal(const char * caption, const char * label, DWORD_PTR initialData, const ComboItem items[]); const std::string & GetEnteredString(void); DWORD_PTR GetEnteredData(void); private: - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); LRESULT OnDestroy(void); - LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); enum Mode { @@ -79,10 +84,10 @@ private: }; Mode m_Mode; - - const char* m_Caption; - const char* m_Label; - const ComboItem* m_ComboItems; + + const char * m_Caption; + const char * m_Label; + const ComboItem * m_ComboItems; const char * m_InitialText; std::string m_EnteredString; @@ -100,7 +105,10 @@ class CDebugMemorySearch : public CDialogResize { public: - enum { IDD = IDD_Debugger_Search }; + enum + { + IDD = IDD_Debugger_Search + }; CDebugMemorySearch(CDebuggerUI * debugger); virtual ~CDebugMemorySearch(void); @@ -113,7 +121,8 @@ private: WM_GAMERESET = WM_USER + 1 }; - enum { + enum + { TIMER_ID_AUTO_REFRESH }; @@ -123,7 +132,8 @@ private: GS_TWOBYTE = 0x01000000 }; - enum { + enum + { WatchListCtrl_Col_Lock, WatchListCtrl_Col_BP, WatchListCtrl_Col_Address, @@ -133,75 +143,76 @@ private: WatchListCtrl_Num_Columns }; - enum { + enum + { ResultsListCtrl_Col_Address, ResultsListCtrl_Col_Value, ResultsListCtrl_Col_Previous }; - + CDebugMemorySearch(void); - CDebugMemorySearch(const CDebugMemorySearch&); - CDebugMemorySearch& operator=(const CDebugMemorySearch&); + CDebugMemorySearch(const CDebugMemorySearch &); + CDebugMemorySearch & operator=(const CDebugMemorySearch &); static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); - static CDebugMemorySearch* _this; + static CDebugMemorySearch * _this; static HHOOK hWinMessageHook; static const CSetValueDlg::ComboItem ModalChangeTypeItems[]; - LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnDestroy(void); - LRESULT OnGameReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - void OnExitSizeMove(void); - void OnSizing(UINT fwSide, LPRECT pRect); - void OnTimer(UINT_PTR nIDEvent); - LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnMouseDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnMouseUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - void OnInterceptMouseWheel(WPARAM wParam, LPARAM lParam); - void OnInterceptMouseMove(WPARAM wParam, LPARAM lParam); - LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnHexCheckbox(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnSearchButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnResetButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnRdramButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnRomButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnSpmemButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnScanTypeChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnValueTypeChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + LRESULT OnGameReset(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + void OnExitSizeMove(void); + void OnSizing(UINT fwSide, LPRECT pRect); + void OnTimer(UINT_PTR nIDEvent); + LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnMouseDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnMouseUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + void OnInterceptMouseWheel(WPARAM wParam, LPARAM lParam); + void OnInterceptMouseMove(WPARAM wParam, LPARAM lParam); + LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnHexCheckbox(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnSearchButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnResetButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnRdramButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnRomButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnSpmemButton(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnScanTypeChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnValueTypeChanged(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnResultsCustomDraw(LPNMHDR lpnmh); LRESULT OnResultsDblClick(LPNMHDR lpnmh); LRESULT OnResultsRClick(LPNMHDR lpnmh); - LRESULT OnResultsPopupViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnResultsPopupAddToWatchList(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnResultsPopupAddAllToWatchList(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnResultsPopupSetValue(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnResultsPopupRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + LRESULT OnResultsPopupViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnResultsPopupAddToWatchList(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnResultsPopupAddAllToWatchList(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnResultsPopupSetValue(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnResultsPopupRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); LRESULT OnWatchListItemChanged(LPNMHDR lpnmh); LRESULT OnWatchListCustomDraw(LPNMHDR lpnmh); LRESULT OnWatchListRClick(LPNMHDR lpnmh); LRESULT OnWatchListDblClick(LPNMHDR lpnmh); - LRESULT OnWatchListPopupLock(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupReadBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupWriteBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupHexadecimal(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupChangeValue(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupChangeDescription(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupChangeType(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupChangeAddress(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupChangeAddressBy(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupRemoveAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupCopyGamesharkCode(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnWatchListPopupCopyAddressAndDescription(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + LRESULT OnWatchListPopupLock(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupReadBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupWriteBP(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupViewMemory(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupAddSymbol(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupHexadecimal(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupChangeValue(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupChangeDescription(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupChangeType(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupChangeAddress(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupChangeAddressBy(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupRemoveAll(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupCopyGamesharkCode(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnWatchListPopupCopyAddressAndDescription(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + + CScanResult * GetFirstSelectedScanResult(void); + CScanResult * GetFirstSelectedWatchListResult(void); - CScanResult* GetFirstSelectedScanResult(void); - CScanResult* GetFirstSelectedWatchListResult(void); - void ResetResults(void); void Search(void); void UpdateOptions(void); @@ -222,11 +233,11 @@ private: CPath GetWatchListPath(void); // Generic UI utility - void FixListHeader(CListViewCtrl& listCtrl); - void SetComboBoxSelByData(CComboBox& cb, DWORD_PTR data); + void FixListHeader(CListViewCtrl & listCtrl); + void SetComboBoxSelByData(CComboBox & cb, DWORD_PTR data); bool MouseHovering(WORD ctrlId, int hMargin = 0, int vMargin = 0); - int GetNumVisibleRows(CListViewCtrl& list); - + int GetNumVisibleRows(CListViewCtrl & list); + bool m_bJalSelected; bool m_bJalHexWasChecked; bool m_bJalUnsignedWasChecked; @@ -235,105 +246,107 @@ private: DWORD m_ThreadId; CFile m_WatchListFile; - CSetValueDlg m_SetValueDlg; + CSetValueDlg m_SetValueDlg; CAddSymbolDlg m_AddSymbolDlg; - - CEditMixed m_SearchValue; + + CEditMixed m_SearchValue; CEditNumber32 m_AddrStart, m_AddrEnd; - CComboBox m_SearchTypeOptions, m_ValueTypeOptions; + CComboBox m_SearchTypeOptions, m_ValueTypeOptions; CListViewCtrl m_ResultsListCtrl, m_WatchListCtrl; - CScrollBar m_ResultsScrollbar, m_WatchListScrollbar; - CButton m_PhysicalCheckbox, m_HexCheckbox; - CButton m_UnsignedCheckbox, m_IgnoreCaseCheckbox, m_UnkEncodingCheckbox; + CScrollBar m_ResultsScrollbar, m_WatchListScrollbar; + CButton m_PhysicalCheckbox, m_HexCheckbox; + CButton m_UnsignedCheckbox, m_IgnoreCaseCheckbox, m_UnkEncodingCheckbox; CMemoryScanner m_MemoryScanner; std::vector m_WatchList; - bool m_bDraggingSeparator; + bool m_bDraggingSeparator; CRect m_InitialSeparatorRect, m_LastSeparatorRect; - int m_ListCtrlRowHeight; + int m_ListCtrlRowHeight; HCURSOR m_hCursorSizeNS; BEGIN_MSG_MAP_EX(CDebugMemorySearch) - MESSAGE_HANDLER(WM_GAMERESET, OnGameReset) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_SIZING(OnSizing) - MSG_WM_TIMER(OnTimer) - COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) - MESSAGE_HANDLER(WM_VSCROLL, OnScroll) - MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseDown) - MESSAGE_HANDLER(WM_LBUTTONUP, OnMouseUp) - MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem) - MESSAGE_HANDLER(WM_SETFONT, OnSetFont) - COMMAND_HANDLER(IDC_CHK_HEX, BN_CLICKED, OnHexCheckbox) - COMMAND_HANDLER(IDC_BTN_SEARCH, BN_CLICKED, OnSearchButton) - COMMAND_HANDLER(IDC_BTN_RESET, BN_CLICKED, OnResetButton) - COMMAND_HANDLER(IDC_CMB_SCANTYPE, CBN_SELCHANGE, OnScanTypeChanged) - COMMAND_HANDLER(IDC_CMB_VALUETYPE, CBN_SELCHANGE, OnValueTypeChanged) - COMMAND_HANDLER(IDC_BTN_RDRAM, BN_CLICKED, OnRdramButton) - COMMAND_HANDLER(IDC_BTN_ROM, BN_CLICKED, OnRomButton) - COMMAND_HANDLER(IDC_BTN_SPMEM, BN_CLICKED, OnSpmemButton) - NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_CUSTOMDRAW, OnResultsCustomDraw) - NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_DBLCLK, OnResultsDblClick) - NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_RCLICK, OnResultsRClick) - COMMAND_HANDLER(ID_RESULTS_VIEWMEMORY, BN_CLICKED, OnResultsPopupViewMemory) - COMMAND_HANDLER(ID_RESULTS_ADDTOWATCHLIST, BN_CLICKED, OnResultsPopupAddToWatchList) - COMMAND_HANDLER(ID_RESULTS_ADDALLTOWATCHLIST, BN_CLICKED, OnResultsPopupAddAllToWatchList) - COMMAND_HANDLER(ID_RESULTS_CHANGEVALUE, BN_CLICKED, OnResultsPopupSetValue) - COMMAND_HANDLER(ID_RESULTS_REMOVE, BN_CLICKED, OnResultsPopupRemove) - NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, LVN_ITEMCHANGED, OnWatchListItemChanged) - NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_CUSTOMDRAW, OnWatchListCustomDraw) - NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_DBLCLK, OnWatchListDblClick) - NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_RCLICK, OnWatchListRClick) - COMMAND_HANDLER(ID_WATCHLIST_VIEWMEMORY, BN_CLICKED, OnWatchListPopupViewMemory) - COMMAND_HANDLER(ID_WATCHLIST_LOCKVALUE, BN_CLICKED, OnWatchListPopupLock) - COMMAND_HANDLER(ID_WATCHLIST_READBP, BN_CLICKED, OnWatchListPopupReadBP) - COMMAND_HANDLER(ID_WATCHLIST_WRITEBP, BN_CLICKED, OnWatchListPopupWriteBP) - COMMAND_HANDLER(ID_WATCHLIST_ADDSYMBOL, BN_CLICKED, OnWatchListPopupAddSymbol) - COMMAND_HANDLER(ID_WATCHLIST_HEXADECIMAL, BN_CLICKED, OnWatchListPopupHexadecimal) - COMMAND_HANDLER(ID_WATCHLIST_CHANGE_VALUE, BN_CLICKED, OnWatchListPopupChangeValue) - COMMAND_HANDLER(ID_WATCHLIST_CHANGE_DESCRIPTION, BN_CLICKED, OnWatchListPopupChangeDescription) - COMMAND_HANDLER(ID_WATCHLIST_CHANGE_TYPE, BN_CLICKED, OnWatchListPopupChangeType) - COMMAND_HANDLER(ID_WATCHLIST_CHANGE_ADDRESS, BN_CLICKED, OnWatchListPopupChangeAddress) - COMMAND_HANDLER(ID_WATCHLIST_CHANGE_ADDRESSBY, BN_CLICKED, OnWatchListPopupChangeAddressBy) - COMMAND_HANDLER(ID_WATCHLIST_REMOVE, BN_CLICKED, OnWatchListPopupRemove) - COMMAND_HANDLER(ID_WATCHLIST_REMOVEALL, BN_CLICKED, OnWatchListPopupRemoveAll) - COMMAND_HANDLER(ID_WATCHLIST_COPY_GSCODE, BN_CLICKED, OnWatchListPopupCopyGamesharkCode) - COMMAND_HANDLER(ID_WATCHLIST_COPY_ADDRDESC, BN_CLICKED, OnWatchListPopupCopyAddressAndDescription) - CHAIN_MSG_MAP(CDialogResize) + { + MESSAGE_HANDLER(WM_GAMERESET, OnGameReset); + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MSG_WM_DESTROY(OnDestroy); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + MSG_WM_SIZING(OnSizing); + MSG_WM_TIMER(OnTimer); + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel); + MESSAGE_HANDLER(WM_VSCROLL, OnScroll); + MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseDown); + MESSAGE_HANDLER(WM_LBUTTONUP, OnMouseUp); + MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem); + MESSAGE_HANDLER(WM_SETFONT, OnSetFont); + COMMAND_HANDLER(IDC_CHK_HEX, BN_CLICKED, OnHexCheckbox); + COMMAND_HANDLER(IDC_BTN_SEARCH, BN_CLICKED, OnSearchButton); + COMMAND_HANDLER(IDC_BTN_RESET, BN_CLICKED, OnResetButton); + COMMAND_HANDLER(IDC_CMB_SCANTYPE, CBN_SELCHANGE, OnScanTypeChanged); + COMMAND_HANDLER(IDC_CMB_VALUETYPE, CBN_SELCHANGE, OnValueTypeChanged); + COMMAND_HANDLER(IDC_BTN_RDRAM, BN_CLICKED, OnRdramButton); + COMMAND_HANDLER(IDC_BTN_ROM, BN_CLICKED, OnRomButton); + COMMAND_HANDLER(IDC_BTN_SPMEM, BN_CLICKED, OnSpmemButton); + NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_CUSTOMDRAW, OnResultsCustomDraw); + NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_DBLCLK, OnResultsDblClick); + NOTIFY_HANDLER_EX(IDC_LST_RESULTS, NM_RCLICK, OnResultsRClick); + COMMAND_HANDLER(ID_RESULTS_VIEWMEMORY, BN_CLICKED, OnResultsPopupViewMemory); + COMMAND_HANDLER(ID_RESULTS_ADDTOWATCHLIST, BN_CLICKED, OnResultsPopupAddToWatchList); + COMMAND_HANDLER(ID_RESULTS_ADDALLTOWATCHLIST, BN_CLICKED, OnResultsPopupAddAllToWatchList); + COMMAND_HANDLER(ID_RESULTS_CHANGEVALUE, BN_CLICKED, OnResultsPopupSetValue); + COMMAND_HANDLER(ID_RESULTS_REMOVE, BN_CLICKED, OnResultsPopupRemove); + NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, LVN_ITEMCHANGED, OnWatchListItemChanged); + NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_CUSTOMDRAW, OnWatchListCustomDraw); + NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_DBLCLK, OnWatchListDblClick); + NOTIFY_HANDLER_EX(IDC_LST_WATCHLIST, NM_RCLICK, OnWatchListRClick); + COMMAND_HANDLER(ID_WATCHLIST_VIEWMEMORY, BN_CLICKED, OnWatchListPopupViewMemory); + COMMAND_HANDLER(ID_WATCHLIST_LOCKVALUE, BN_CLICKED, OnWatchListPopupLock); + COMMAND_HANDLER(ID_WATCHLIST_READBP, BN_CLICKED, OnWatchListPopupReadBP); + COMMAND_HANDLER(ID_WATCHLIST_WRITEBP, BN_CLICKED, OnWatchListPopupWriteBP); + COMMAND_HANDLER(ID_WATCHLIST_ADDSYMBOL, BN_CLICKED, OnWatchListPopupAddSymbol); + COMMAND_HANDLER(ID_WATCHLIST_HEXADECIMAL, BN_CLICKED, OnWatchListPopupHexadecimal); + COMMAND_HANDLER(ID_WATCHLIST_CHANGE_VALUE, BN_CLICKED, OnWatchListPopupChangeValue); + COMMAND_HANDLER(ID_WATCHLIST_CHANGE_DESCRIPTION, BN_CLICKED, OnWatchListPopupChangeDescription); + COMMAND_HANDLER(ID_WATCHLIST_CHANGE_TYPE, BN_CLICKED, OnWatchListPopupChangeType); + COMMAND_HANDLER(ID_WATCHLIST_CHANGE_ADDRESS, BN_CLICKED, OnWatchListPopupChangeAddress); + COMMAND_HANDLER(ID_WATCHLIST_CHANGE_ADDRESSBY, BN_CLICKED, OnWatchListPopupChangeAddressBy); + COMMAND_HANDLER(ID_WATCHLIST_REMOVE, BN_CLICKED, OnWatchListPopupRemove); + COMMAND_HANDLER(ID_WATCHLIST_REMOVEALL, BN_CLICKED, OnWatchListPopupRemoveAll); + COMMAND_HANDLER(ID_WATCHLIST_COPY_GSCODE, BN_CLICKED, OnWatchListPopupCopyGamesharkCode); + COMMAND_HANDLER(ID_WATCHLIST_COPY_ADDRDESC, BN_CLICKED, OnWatchListPopupCopyAddressAndDescription); + CHAIN_MSG_MAP(CDialogResize); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugMemorySearch) - DLGRESIZE_CONTROL(IDC_LST_WATCHLIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_SCRL_WATCHLIST, DLSZ_MOVE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_NUM_RESULTS, DLSZ_SIZE_X) - DLGRESIZE_CONTROL(IDC_LST_RESULTS, DLSZ_SIZE_X) - DLGRESIZE_CONTROL(IDC_SCRL_RESULTS, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_SEPARATOR, DLSZ_SIZE_X) - DLGRESIZE_CONTROL(IDC_BTN_SEARCH, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BTN_RESET, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_GRP_SEARCH, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CHK_HEX, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CHK_UNSIGNED, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CHK_IGNORECASE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CHK_UNKENCODING, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_SEARCH_VALUE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_LBL_SCANTYPE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_LBL_VALUETYPE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CMB_SCANTYPE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CMB_VALUETYPE, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_LBL_ADDRSTART, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_LBL_ADDREND, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_ADDR_START, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_ADDR_END, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_CHK_PHYSICAL, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BTN_RDRAM, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BTN_ROM, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_BTN_SPMEM, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_GRP_ADDR, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_LST_WATCHLIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_SCRL_WATCHLIST, DLSZ_MOVE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_NUM_RESULTS, DLSZ_SIZE_X) + DLGRESIZE_CONTROL(IDC_LST_RESULTS, DLSZ_SIZE_X) + DLGRESIZE_CONTROL(IDC_SCRL_RESULTS, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_SEPARATOR, DLSZ_SIZE_X) + DLGRESIZE_CONTROL(IDC_BTN_SEARCH, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BTN_RESET, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_GRP_SEARCH, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CHK_HEX, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CHK_UNSIGNED, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CHK_IGNORECASE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CHK_UNKENCODING, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_SEARCH_VALUE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_LBL_SCANTYPE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_LBL_VALUETYPE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CMB_SCANTYPE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CMB_VALUETYPE, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_LBL_ADDRSTART, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_LBL_ADDREND, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_ADDR_START, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_ADDR_END, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_CHK_PHYSICAL, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BTN_RDRAM, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BTN_ROM, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_BTN_SPMEM, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_GRP_ADDR, DLSZ_MOVE_X) END_DLGRESIZE_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h index 4e0627755..2827ba975 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h @@ -12,9 +12,9 @@ using FieldPairCallback = std::functionLabelId == ctrl) { return i; @@ -37,7 +37,7 @@ struct TabRecord { for (int i = 0, end = FieldCount; i < end; i++) { - const FieldPair *pair = (Fields + i); + const FieldPair * pair = (Fields + i); if (pair->EditId == ctrl) { return i; @@ -50,7 +50,7 @@ struct TabRecord { for (size_t i = 0, end = FieldCount; i < end; i++) { - const FieldPair *pair = (Fields + i); + const FieldPair * pair = (Fields + i); if (callback(parent.GetDescendantWindow(pair->LabelId), parent.GetDescendantWindow(pair->EditId))) { break; @@ -62,7 +62,7 @@ struct TabRecord { for (size_t i = 0, end = FieldCount; i < end; i++) { - const FieldPair *pair = (Fields + i); + const FieldPair * pair = (Fields + i); callback(parent.GetDescendantWindow(pair->LabelId), parent.GetDescendantWindow(pair->EditId)); } } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp index fe418c6e7..30a879cc3 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp @@ -733,8 +733,7 @@ CWindow CRegisterTabs::AddTab(char * caption, int dialogId, DLGPROC dlgProc) pageRect.top, pageRect.Width(), pageRect.Height(), - SWP_HIDEWINDOW - ); + SWP_HIDEWINDOW); m_TabWindows.push_back(tabWin); @@ -920,9 +919,8 @@ stdstr CRegisterTabs::CopyTabRegisters(int id) break; } - record->Iterate(tab, [&str](const CWindow & label, const CWindow & edit) - { - str += stdstr_f( "\r\n%s %s", GetCWindowText(label).c_str(), GetCWindowText(edit).c_str()); + record->Iterate(tab, [&str](const CWindow & label, const CWindow & edit) { + str += stdstr_f("\r\n%s %s", GetCWindowText(label).c_str(), GetCWindowText(edit).c_str()); }); switch (id) diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h index e26f54480..6abf662ea 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h @@ -2,26 +2,28 @@ #include "Breakpoints.h" #include "Debugger-RegisterTabData.h" -class CEditReg64 : +class CEditReg64 : public CWindowImpl, private CDebugSettings { public: - static uint64_t ParseValue(const char* wordPair); + static uint64_t ParseValue(const char * wordPair); BOOL Attach(HWND hWndNew); - LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnLostFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnLostFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); uint64_t GetValue(); void SetValue(uint32_t h, uint32_t l); void SetValue(uint64_t value); BEGIN_MSG_MAP_EX(CRegEdit64) - MESSAGE_HANDLER(WM_CHAR, OnChar) - MESSAGE_HANDLER(WM_KILLFOCUS, OnLostFocus) + { + MESSAGE_HANDLER(WM_CHAR, OnChar); + MESSAGE_HANDLER(WM_KILLFOCUS, OnLostFocus); + } END_MSG_MAP() }; -class CRegisterTabs : +class CRegisterTabs : public CTabCtrl, public CDebugSettings { @@ -36,10 +38,10 @@ public: CRegisterTabs(void); ~CRegisterTabs(); - void Attach(HWND hWndNew, CDebuggerUI* debugger); + void Attach(HWND hWndNew, CDebuggerUI * debugger); HWND Detach(); - CWindow AddTab(char* caption, int dialogId, DLGPROC dlgProc); + CWindow AddTab(char * caption, int dialogId, DLGPROC dlgProc); void ShowTab(int nPage); CRect GetPageRect(); void RedrawCurrentTab(); @@ -49,8 +51,8 @@ public: void CopyAllRegisters(); private: - CRegisterTabs(const CRegisterTabs&); - CRegisterTabs& operator=(const CRegisterTabs&); + CRegisterTabs(const CRegisterTabs &); + CRegisterTabs & operator=(const CRegisterTabs &); stdstr CopyTabRegisters(int id); @@ -60,16 +62,15 @@ private: static INT_PTR CALLBACK TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK TabProcFPR(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static void InitRegisterEdit(CWindow & tab, CEditNumber32 & edit, FieldPair ctrl); + static void InitRegisterEdits(CWindow & tab, CEditNumber32 * edits, const TabRecord * ctrlIds); + static void InitRegisterEdit64(CWindow & tab, CEditReg64 & edit, FieldPair ctrl); + static void InitRegisterEdits64(CWindow & tab, CEditReg64 * edits, const TabRecord * ctrlIds); - static void InitRegisterEdit(CWindow& tab, CEditNumber32& edit, FieldPair ctrl); - static void InitRegisterEdits(CWindow& tab, CEditNumber32* edits, const TabRecord* ctrlIds); - static void InitRegisterEdit64(CWindow& tab, CEditReg64& edit, FieldPair ctrl); - static void InitRegisterEdits64(CWindow& tab, CEditReg64* edits, const TabRecord* ctrlIds); - - static void ZeroRegisterEdit(CEditNumber32& edit); - static void ZeroRegisterEdits(CEditNumber32* edits, uint32_t ctrlIdsCount); - static void ZeroRegisterEdit64(CEditReg64& edit); - static void ZeroRegisterEdits64(CEditReg64* edits, uint32_t ctrlIdsCount); + static void ZeroRegisterEdit(CEditNumber32 & edit); + static void ZeroRegisterEdits(CEditNumber32 * edits, uint32_t ctrlIdsCount); + static void ZeroRegisterEdit64(CEditReg64 & edit); + static void ZeroRegisterEdits64(CEditReg64 * edits, uint32_t ctrlIdsCount); typedef union { @@ -128,12 +129,12 @@ private: "? 28", "? 29", "? 30", - "Virtual coherency (data)" + "Virtual coherency (data)", }; // For static dlgprocs, assumes single instance static bool m_bColorsEnabled; - static CDebuggerUI* m_Debugger; + static CDebuggerUI * m_Debugger; vector m_TabWindows; bool m_attached; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp index 380af7e5e..64f94aa9c 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp @@ -441,8 +441,7 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /* } } while (searchPath.FindNext()); - fileNames.sort([](stdstr a, stdstr b) - { return a.ToLower() < b.ToLower(); }); + fileNames.sort([](stdstr a, stdstr b) { return a.ToLower() < b.ToLower(); }); m_ScriptList.SetRedraw(false); m_ScriptList.DeleteAllItems(); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h index 997125044..9030f74dc 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h @@ -1,9 +1,9 @@ #pragma once +#include "Debugger-ScriptsAutorun.h" #include "DebuggerUI.h" #include "ScriptSystem.h" #include #include -#include "Debugger-ScriptsAutorun.h" #include #include @@ -13,14 +13,16 @@ class CDebugScripts : public CToolTipDialog { private: - enum { + enum + { WM_REFRESH_LIST = WM_USER + 1, WM_SCRIPT_STATUS = WM_USER + 2, WM_CONSOLE_PRINT = WM_USER + 3, WM_CONSOLE_CLEAR = WM_USER + 4 }; - enum { + enum + { CONFLUSH_TIMER_ID = 0, CONFLUSH_TIMER_INTERVAL = 50 }; @@ -38,14 +40,14 @@ private: stdstr m_ScriptsDir; stdstr m_SelectedScriptName; - std::vector m_InputHistory; + std::vector m_InputHistory; size_t m_InputHistoryIndex; stdstr m_ConOutputBuffer; HANDLE m_hQuitScriptDirWatchEvent; HANDLE m_hScriptDirWatchThread; - static DWORD WINAPI ScriptDirWatchProc(void *ctx); + static DWORD WINAPI ScriptDirWatchProc(void * ctx); void RunSelected(); void StopSelected(); @@ -54,72 +56,77 @@ private: void RefreshStatus(); void ConsoleCopy(); - void SendInput(const char* name, const char* code); + void SendInput(const char * name, const char * code); public: - enum { IDD = IDD_Debugger_Scripts }; + enum + { + IDD = IDD_Debugger_Scripts + }; CDebugScripts(CDebuggerUI * debugger); virtual ~CDebugScripts(void); - void ConsolePrint(const char* text); + void ConsolePrint(const char * text); void ConsoleClear(); void RefreshList(); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnDestroy(void); - LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnScriptListDblClicked(NMHDR* pNMHDR); - LRESULT OnScriptListRClicked(NMHDR* pNMHDR); - LRESULT OnScriptListCustomDraw(NMHDR* pNMHDR); - LRESULT OnScriptListItemChanged(NMHDR* pNMHDR); - LRESULT OnInputSpecialKey(NMHDR* pNMHDR); + LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnScriptListDblClicked(NMHDR * pNMHDR); + LRESULT OnScriptListRClicked(NMHDR * pNMHDR); + LRESULT OnScriptListCustomDraw(NMHDR * pNMHDR); + LRESULT OnScriptListItemChanged(NMHDR * pNMHDR); + LRESULT OnInputSpecialKey(NMHDR * pNMHDR); void OnExitSizeMove(void); void OnTimer(UINT_PTR nIDEvent); - LRESULT OnConsolePrint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnConsoleClear(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnRefreshList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnConsolePrint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnConsoleClear(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnRefreshList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); BEGIN_MSG_MAP_EX(CDebugScripts) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic) - MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit) - NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_DBLCLK, OnScriptListDblClicked) - NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_RCLICK, OnScriptListRClicked) - NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_CUSTOMDRAW, OnScriptListCustomDraw) - NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, LVN_ITEMCHANGED, OnScriptListItemChanged) - NOTIFY_HANDLER_EX(IDC_EVAL_EDIT, CIN_SPECIALKEY, OnInputSpecialKey) - MSG_WM_TIMER(OnTimer) - MSG_WM_DESTROY(OnDestroy) + { + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic); + MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit); + NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_DBLCLK, OnScriptListDblClicked); + NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_RCLICK, OnScriptListRClicked); + NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_CUSTOMDRAW, OnScriptListCustomDraw); + NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, LVN_ITEMCHANGED, OnScriptListItemChanged); + NOTIFY_HANDLER_EX(IDC_EVAL_EDIT, CIN_SPECIALKEY, OnInputSpecialKey); + MSG_WM_TIMER(OnTimer); + MSG_WM_DESTROY(OnDestroy); MSG_WM_EXITSIZEMOVE(OnExitSizeMove); - MESSAGE_HANDLER(WM_CONSOLE_PRINT, OnConsolePrint) - MESSAGE_HANDLER(WM_CONSOLE_CLEAR, OnConsoleClear) - MESSAGE_HANDLER(WM_REFRESH_LIST, OnRefreshList) - CHAIN_MSG_MAP(CDialogResize) + MESSAGE_HANDLER(WM_CONSOLE_PRINT, OnConsolePrint); + MESSAGE_HANDLER(WM_CONSOLE_CLEAR, OnConsoleClear); + MESSAGE_HANDLER(WM_REFRESH_LIST, OnRefreshList); + CHAIN_MSG_MAP(CDialogResize); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugScripts) - DLGRESIZE_CONTROL(IDC_CONSOLE_EDIT, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_SCRIPT_LIST, DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_CLEAR_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_COPY_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_SCRIPTS_GRP, DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_OUTPUT_GRP, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_EVAL_LBL, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_EVAL_EDIT, DLSZ_SIZE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_RUN_BTN, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_SCRIPTDIR_BTN, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_STATUSBAR, DLSZ_SIZE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_CONSOLE_EDIT, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_SCRIPT_LIST, DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_CLEAR_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_COPY_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_SCRIPTS_GRP, DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_OUTPUT_GRP, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_EVAL_LBL, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_EVAL_EDIT, DLSZ_SIZE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_RUN_BTN, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_SCRIPTDIR_BTN, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_STATUSBAR, DLSZ_SIZE_X | DLSZ_MOVE_Y) END_DLGRESIZE_MAP() BEGIN_TOOLTIP_MAP() - TOOLTIP(IDC_CLEAR_BTN, "Clear console output") - TOOLTIP(IDC_COPY_BTN, "Copy console output to the clipboard") - TOOLTIP(IDC_RUN_BTN, "Toggle selected script") - TOOLTIP(IDC_SCRIPTDIR_BTN, "Open scripts directory in file explorer") + TOOLTIP(IDC_CLEAR_BTN, "Clear console output") + TOOLTIP(IDC_COPY_BTN, "Copy console output to the clipboard") + TOOLTIP(IDC_RUN_BTN, "Toggle selected script") + TOOLTIP(IDC_SCRIPTDIR_BTN, "Open scripts directory in file explorer") END_TOOLTIP_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.cpp b/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.cpp index 280741a61..12d4ed1fd 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.cpp @@ -137,8 +137,7 @@ LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/ do { stdstr fileName = searchPath.GetNameExtension(); - if (searchPath.GetExtension() == "js" && - m_ScriptSystem->AutorunList().count(fileName) == 0) + if (searchPath.GetExtension() == "js" && m_ScriptSystem->AutorunList().count(fileName) == 0) { fileNames.push_back(searchPath.GetNameExtension()); } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.h b/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.h index f19c3837e..76f4a073f 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-ScriptsAutorun.h @@ -5,36 +5,41 @@ class CScriptsAutorunDlg : public CDialogImpl { public: - enum { IDD = IDD_Debugger_ScriptsAutorun }; + enum + { + IDD = IDD_Debugger_ScriptsAutorun + }; CScriptsAutorunDlg(); virtual ~CScriptsAutorunDlg(); - INT_PTR DoModal(CDebuggerUI* debugger, stdstr selectedScriptName); + INT_PTR DoModal(CDebuggerUI * debugger, stdstr selectedScriptName); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); LRESULT OnDestroy(void); - LRESULT OnOKCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnAdd(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnScriptListDblClicked(NMHDR* pNMHDR); - LRESULT OnAutorunListDblClicked(NMHDR* pNMHDR); - LRESULT OnCtrlSetFocus(NMHDR* pNMHDR); - LRESULT OnRefreshScriptList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnRefreshAutorunList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnOKCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnAdd(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnRemove(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL & bHandled); + LRESULT OnScriptListDblClicked(NMHDR * pNMHDR); + LRESULT OnAutorunListDblClicked(NMHDR * pNMHDR); + LRESULT OnCtrlSetFocus(NMHDR * pNMHDR); + LRESULT OnRefreshScriptList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnRefreshAutorunList(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); BEGIN_MSG_MAP_EX(CAddBreakpointDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MSG_WM_DESTROY(OnDestroy) - COMMAND_HANDLER(IDOK, BN_CLICKED, OnOKCancel) - COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnOKCancel) - COMMAND_HANDLER(IDC_ADD_BTN, BN_CLICKED, OnAdd) - COMMAND_HANDLER(IDC_REMOVE_BTN, BN_CLICKED, OnRemove) - NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_DBLCLK, OnScriptListDblClicked) - NOTIFY_HANDLER_EX(IDC_AUTORUN_LIST, NM_DBLCLK, OnAutorunListDblClicked) - NOTIFY_CODE_HANDLER_EX(NM_SETFOCUS, OnCtrlSetFocus) - MESSAGE_HANDLER(WM_REFRESH_LIST, OnRefreshScriptList) - MESSAGE_HANDLER(WM_REFRESH_AUTORUN_LIST, OnRefreshAutorunList) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MSG_WM_DESTROY(OnDestroy); + COMMAND_HANDLER(IDOK, BN_CLICKED, OnOKCancel); + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnOKCancel); + COMMAND_HANDLER(IDC_ADD_BTN, BN_CLICKED, OnAdd); + COMMAND_HANDLER(IDC_REMOVE_BTN, BN_CLICKED, OnRemove); + NOTIFY_HANDLER_EX(IDC_SCRIPT_LIST, NM_DBLCLK, OnScriptListDblClicked); + NOTIFY_HANDLER_EX(IDC_AUTORUN_LIST, NM_DBLCLK, OnAutorunListDblClicked); + NOTIFY_CODE_HANDLER_EX(NM_SETFOCUS, OnCtrlSetFocus); + MESSAGE_HANDLER(WM_REFRESH_LIST, OnRefreshScriptList); + MESSAGE_HANDLER(WM_REFRESH_AUTORUN_LIST, OnRefreshAutorunList); + } END_MSG_MAP() private: @@ -43,9 +48,9 @@ private: WM_REFRESH_LIST = WM_USER + 1, WM_REFRESH_AUTORUN_LIST = WM_USER + 2 }; - - CDebuggerUI* m_Debugger; - CScriptSystem* m_ScriptSystem; + + CDebuggerUI * m_Debugger; + CScriptSystem * m_ScriptSystem; stdstr m_InitSelectedScriptName; //std::set m_AutorunSet; @@ -58,7 +63,7 @@ private: HANDLE m_hQuitScriptDirWatchEvent; HANDLE m_hScriptDirWatchThread; - static DWORD WINAPI ScriptDirWatchProc(void* ctx); + static DWORD WINAPI ScriptDirWatchProc(void * ctx); void AddSelected(); void RemoveSelected(); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-StackTrace.h b/Source/Project64/UserInterface/Debugger/Debugger-StackTrace.h index 63ba81fb7..62dd4a3ec 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-StackTrace.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-StackTrace.h @@ -3,7 +3,8 @@ #define STACKTRACE_MAX_ENTRIES 100 -typedef struct { +typedef struct +{ uint32_t routineAddress; uint32_t callingAddress; } STACKTRACE_ENTRY; @@ -14,7 +15,10 @@ class CDebugStackTrace : private CDebugSettings { public: - enum { IDD = IDD_Debugger_StackTrace }; + enum + { + IDD = IDD_Debugger_StackTrace + }; CDebugStackTrace(CDebuggerUI * debugger); virtual ~CDebugStackTrace(void); @@ -25,7 +29,7 @@ public: { if (m_EntriesIndex < STACKTRACE_MAX_ENTRIES) { - m_Entries[m_EntriesIndex] = { routineAddress, callingAddress }; + m_Entries[m_EntriesIndex] = {routineAddress, callingAddress}; m_EntriesIndex++; } } @@ -44,30 +48,31 @@ public: } private: - STACKTRACE_ENTRY m_Entries[STACKTRACE_MAX_ENTRIES]; int m_EntriesIndex; CListViewCtrl m_List; - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnListDblClicked(NMHDR* pNMHDR); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnListDblClicked(NMHDR * pNMHDR); LRESULT OnDestroy(void); void OnExitSizeMove(void); BEGIN_MSG_MAP_EX(CDebugStackTrace) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MSG_WM_DESTROY(OnDestroy) - MESSAGE_HANDLER(WM_ACTIVATE, OnActivate) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - NOTIFY_HANDLER_EX(IDC_STACKTRACE_LIST, NM_DBLCLK, OnListDblClicked) - CHAIN_MSG_MAP(CDialogResize) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - END_MSG_MAP() + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MSG_WM_DESTROY(OnDestroy); + MESSAGE_HANDLER(WM_ACTIVATE, OnActivate); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + NOTIFY_HANDLER_EX(IDC_STACKTRACE_LIST, NM_DBLCLK, OnListDblClicked); + CHAIN_MSG_MAP(CDialogResize); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + } + END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugStackTrace) - DLGRESIZE_CONTROL(IDC_STACKTRACE_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_STACKTRACE_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) END_DLGRESIZE_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-StackView.h b/Source/Project64/UserInterface/Debugger/Debugger-StackView.h index 57cad478a..5871cbc23 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-StackView.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-StackView.h @@ -5,7 +5,10 @@ class CDebugStackView : public CDialogResize { public: - enum { IDD = IDD_Debugger_Stack }; + enum + { + IDD = IDD_Debugger_Stack + }; CDebugStackView(CDebuggerUI * debugger); virtual ~CDebugStackView(void); @@ -16,20 +19,22 @@ private: CListViewCtrl m_StackList; CStatic m_SPStatic; - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnDestroy(void); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); void OnExitSizeMove(void); BEGIN_MSG_MAP_EX(CDebugStackView) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MSG_WM_DESTROY(OnDestroy) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - CHAIN_MSG_MAP(CDialogResize) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MSG_WM_DESTROY(OnDestroy); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + CHAIN_MSG_MAP(CDialogResize); MSG_WM_EXITSIZEMOVE(OnExitSizeMove); - END_MSG_MAP() + } + END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugStackView) - DLGRESIZE_CONTROL(IDC_STACK_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_STACK_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) END_DLGRESIZE_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp index 18c960bd8..5c2a4fb2b 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp @@ -23,7 +23,7 @@ const CSetValueDlg::ComboItem CDebugSymbols::ModalChangeTypeItems[] = { {"v2", SYM_VECTOR2}, {"v3", SYM_VECTOR3}, {"v4", SYM_VECTOR4}, - { nullptr, 0 } + {nullptr, 0}, }; CDebugSymbols::CDebugSymbols(CDebuggerUI * debugger) : @@ -396,8 +396,7 @@ void CDebugSymbols::UpdateFilteredSymbols() std::wstring strName = stdstr(symbol.m_Name).ToUTF16(); std::wstring strDesc = stdstr(symbol.m_Description).ToUTF16(); - if (strName.find(m_FilterText) != std::wstring::npos || - strDesc.find(m_FilterText) != std::wstring::npos) + if (strName.find(m_FilterText) != std::wstring::npos || strDesc.find(m_FilterText) != std::wstring::npos) { SymbolCacheItem item(symbol, m_SymbolTable); m_FilteredSymbols.push_back(item); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.h b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.h index 4c1d8f97a..fdb11ac15 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.h @@ -8,7 +8,8 @@ class CDebugSymbols : public CDialogResize { private: - enum { + enum + { SymbolsListView_Col_Address, SymbolsListView_Col_Type, SymbolsListView_Col_Name, @@ -17,15 +18,16 @@ private: SymbolsListView_Num_Columns }; - struct SymbolCacheItem { - int m_Id; + struct SymbolCacheItem + { + int m_Id; wchar_t m_Address[16]; wchar_t m_Type[16]; wchar_t m_Name[48]; wchar_t m_Value[64]; wchar_t m_Description[256]; - SymbolCacheItem(CSymbol& symbol, CSymbolTable* symbolTable) + SymbolCacheItem(CSymbol & symbol, CSymbolTable * symbolTable) { char szValue[64]; symbolTable->GetValueString(szValue, &symbol); @@ -46,9 +48,9 @@ private: static const CSetValueDlg::ComboItem ModalChangeTypeItems[]; - CSymbolTable* m_SymbolTable; + CSymbolTable * m_SymbolTable; CListViewCtrl m_SymbolsListView; - CSetValueDlg m_SetValueDlg; + CSetValueDlg m_SetValueDlg; CAddSymbolDlg m_AddSymbolDlg; size_t m_SymbolCacheStartIndex; @@ -59,45 +61,53 @@ private: std::vector m_FilteredSymbols; public: - enum { IDD = IDD_Debugger_Symbols }; - enum { TIMER_ID_AUTO_REFRESH }; + enum + { + IDD = IDD_Debugger_Symbols + }; + enum + { + TIMER_ID_AUTO_REFRESH + }; CDebugSymbols(CDebuggerUI * debugger); //virtual ~CDebugSymbols(void); void Refresh(); void UpdateFilteredSymbols(); - int GetListItemSymbolId(int nItem); - int ColumnHitTest(POINT& pt); + int GetListItemSymbolId(int nItem); + int ColumnHitTest(POINT & pt); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnListDblClicked(NMHDR* pNMHDR); - LRESULT OnListGetDispInfo(NMHDR* pNMHDR); - LRESULT OnListCacheHint(NMHDR* pNMHDR); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnListDblClicked(NMHDR * pNMHDR); + LRESULT OnListGetDispInfo(NMHDR * pNMHDR); + LRESULT OnListCacheHint(NMHDR * pNMHDR); LRESULT OnDestroy(void); void OnExitSizeMove(void); void OnTimer(UINT_PTR nIDEvent); BEGIN_MSG_MAP_EX(CDebugSymbols) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - COMMAND_HANDLER(IDC_FILTER_EDIT, EN_CHANGE, OnFilterChanged) - NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, NM_DBLCLK, OnListDblClicked) - NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, LVN_GETDISPINFO, OnListGetDispInfo) - NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, LVN_ODCACHEHINT, OnListCacheHint) - MSG_WM_TIMER(OnTimer) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_DESTROY(OnDestroy) - CHAIN_MSG_MAP(CDialogResize) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + COMMAND_HANDLER(IDC_FILTER_EDIT, EN_CHANGE, OnFilterChanged); + NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, NM_DBLCLK, OnListDblClicked); + NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, LVN_GETDISPINFO, OnListGetDispInfo); + NOTIFY_HANDLER_EX(IDC_SYMBOLS_LIST, LVN_ODCACHEHINT, OnListCacheHint); + MSG_WM_TIMER(OnTimer); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + MSG_WM_DESTROY(OnDestroy); + CHAIN_MSG_MAP(CDialogResize); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugSymbols) - DLGRESIZE_CONTROL(IDC_FILTER_EDIT, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_FILTER_STATIC, DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_REMOVESYMBOL_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_ADDSYMBOL_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_SYMBOLS_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_FILTER_EDIT, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_FILTER_STATIC, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_REMOVESYMBOL_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_ADDSYMBOL_BTN, DLSZ_MOVE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_SYMBOLS_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y) END_DLGRESIZE_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-TLB.h b/Source/Project64/UserInterface/Debugger/Debugger-TLB.h index eab509648..783fee813 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-TLB.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-TLB.h @@ -1,20 +1,25 @@ #pragma once class CDebugTlb : - public CDebugDialog < CDebugTlb > + public CDebugDialog { BEGIN_MSG_MAP_EX(CDebugTlb) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + } END_MSG_MAP() - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); void OnExitSizeMove(void); public: - enum { IDD = IDD_Debugger_TLB }; + enum + { + IDD = IDD_Debugger_TLB + }; CDebugTlb(CDebuggerUI * debugger); virtual ~CDebugTlb(void); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp index f904ab763..ef82db49a 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp @@ -28,7 +28,7 @@ CDebugMemoryView::jump_item_t CDebugMemoryView::JumpItems[] = { {0xB0000000, 0x10000000, 0xFC00000, "Cartridge ROM"}, {0xBFC00000, 0x1FC00000, 0x00007C0, "PIF ROM"}, {0xBFC007C0, 0x1FC007C0, 0x0000040, "PIF RAM"}, - { 0, NULL} + {0, NULL}, }; CDebugMemoryView::CDebugMemoryView(CDebuggerUI * debugger) : @@ -117,9 +117,7 @@ void CDebugMemoryView::CopyBytesToClipboard(uint32_t startAddress, uint32_t endA if (bIncludeAddresses) { - if ((bRowAddresses && offsetFromBase % rowSize == 0) || - (!bRowAddresses && offsetFromBase % groupSize == 0) || - (offsetFromSelStart == 0)) + if ((bRowAddresses && offsetFromBase % rowSize == 0) || (!bRowAddresses && offsetFromBase % groupSize == 0) || (offsetFromSelStart == 0)) { str += stdstr_f("%08X: ", address); } @@ -341,7 +339,7 @@ LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM (int)(MEMSB_BLOCK_W * dpiScale), (int)(MEMSB_BLOCKLEN_W * dpiScale), (int)(MEMSB_DMAINFO_W * dpiScale), - (int)(MEMSB_SAFEMODE_W * dpiScale) + (int)(MEMSB_SAFEMODE_W * dpiScale), }; m_StatusBar.SetParts(MEMSB_NUM_PANES, statusPaneWidths); @@ -371,7 +369,7 @@ LRESULT CDebugMemoryView::OnDestroy(void) return 0; } -LRESULT CDebugMemoryView::OnShowAddress(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) +LRESULT CDebugMemoryView::OnShowAddress(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/) { uint32_t address = (uint32_t)wParam; bool bVirtual = (lParam != 0); @@ -385,7 +383,7 @@ void CDebugMemoryView::OnExitSizeMove() SaveWindowPos(true); } -LRESULT CDebugMemoryView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) +LRESULT CDebugMemoryView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/) { switch (wID) { @@ -432,26 +430,26 @@ LRESULT CDebugMemoryView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& m_HexEditCtrl.Copy(); break; case ID_POPUPMENU_COPYGAMESHARKCODE: - { + { uint32_t startAddress, endAddress; m_HexEditCtrl.GetSelectionRange(&startAddress, &endAddress); CopyGameSharkCodeToClipboard(startAddress, endAddress); - } break; + } case ID_POPUPMENU_COPYDATAWITHGROUPADDRESSES: - { + { uint32_t startAddress, endAddress; m_HexEditCtrl.GetSelectionRange(&startAddress, &endAddress); CopyBytesToClipboard(startAddress, endAddress, m_HexEditCtrl.GetFocusedColumn() == HX_COL_HEXDATA, true, false); - } break; + } case ID_POPUPMENU_COPYDATAWITHROWADDRESSES: - { + { uint32_t startAddress, endAddress; m_HexEditCtrl.GetSelectionRange(&startAddress, &endAddress); CopyBytesToClipboard(startAddress, endAddress, m_HexEditCtrl.GetFocusedColumn() == HX_COL_HEXDATA, true, true); - } break; + } case ID_POPUPMENU_PASTE: m_HexEditCtrl.Paste(); break; @@ -590,16 +588,16 @@ LRESULT CDebugMemoryView::OnHxCtrlKeyPressed(LPNMHDR lpNMHDR) FollowPointer(false); break; case VK_TAB: + { + int curSel = m_TabCtrl.GetCurSel(); + if (m_TabCtrl.SetCurSel(curSel + 1) == -1) { - int curSel = m_TabCtrl.GetCurSel(); - if (m_TabCtrl.SetCurSel(curSel + 1) == -1) - { - m_TabCtrl.SetCurSel(0); - } - TabSelChanged(); + m_TabCtrl.SetCurSel(0); } + TabSelChanged(); break; } + } return FALSE; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.h b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.h index 570481aa6..339d82a1b 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.h @@ -1,13 +1,13 @@ #pragma once #include "Debugger-AddSymbol.h" -#include #include +#include typedef struct { NMHDR nmh; - int nItem; + int nItem; } NMMTRCLICK; enum @@ -35,13 +35,13 @@ public: private: void OnLButtonDblClk(UINT /*nFlags*/, CPoint /*point*/) { - NMHDR nmh = { m_hWnd, (UINT_PTR)::GetDlgCtrlID(m_hWnd), NM_DBLCLK }; + NMHDR nmh = {m_hWnd, (UINT_PTR)::GetDlgCtrlID(m_hWnd), NM_DBLCLK}; ::SendMessage(::GetParent(m_hWnd), WM_NOTIFY, NM_DBLCLK, (LPARAM)&nmh); } void OnRButtonDown(UINT /*nFlags*/, CPoint point) { - TCHITTESTINFO ht = { point, 0}; + TCHITTESTINFO ht = {point, 0}; int nItem = ::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM)&ht); if (nItem != -1) { @@ -51,21 +51,23 @@ private: void OnRButtonUp(UINT /*nFlags*/, CPoint point) { - TCHITTESTINFO ht = { point, 0 }; + TCHITTESTINFO ht = {point, 0}; int nItem = ::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM)&ht); if (nItem != -1 && nItem == m_nItemRClick) { - NMMTRCLICK nmrc = { { m_hWnd, (UINT_PTR)::GetDlgCtrlID(m_hWnd), MTCN_RCLICK }, nItem }; + NMMTRCLICK nmrc = {{m_hWnd, (UINT_PTR)::GetDlgCtrlID(m_hWnd), MTCN_RCLICK}, nItem}; ::SendMessage(::GetParent(m_hWnd), WM_NOTIFY, MTCN_RCLICK, (LPARAM)&nmrc); } m_nItemRClick = -1; } BEGIN_MSG_MAP_EX(CMemTabCtrl) - MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) - MSG_WM_RBUTTONDOWN(OnRButtonDown) - MSG_WM_RBUTTONUP(OnRButtonUp) - MSG_WM_RBUTTONDBLCLK(OnRButtonDown) + { + MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk); + MSG_WM_RBUTTONDOWN(OnRButtonDown); + MSG_WM_RBUTTONUP(OnRButtonUp); + MSG_WM_RBUTTONDBLCLK(OnRButtonDown); + } END_MSG_MAP() }; @@ -75,7 +77,10 @@ class CDebugMemoryView : public CToolTipDialog { public: - enum { IDD = IDD_Debugger_Memory }; + enum + { + IDD = IDD_Debugger_Memory + }; CDebugMemoryView(CDebuggerUI * debugger); virtual ~CDebugMemoryView(void); @@ -120,11 +125,11 @@ private: enum { - MEMSB_HOTADDR_W = 160, - MEMSB_BLOCK_W = 120 + MEMSB_HOTADDR_W, - MEMSB_BLOCKLEN_W = 60 + MEMSB_BLOCK_W, - MEMSB_DMAINFO_W = 60 + MEMSB_BLOCKLEN_W, - MEMSB_SAFEMODE_W = -1 + MEMSB_HOTADDR_W = 160, + MEMSB_BLOCK_W = 120 + MEMSB_HOTADDR_W, + MEMSB_BLOCKLEN_W = 60 + MEMSB_BLOCK_W, + MEMSB_DMAINFO_W = 60 + MEMSB_BLOCKLEN_W, + MEMSB_SAFEMODE_W = -1 }; enum edit_type_t @@ -138,7 +143,7 @@ private: edit_type_t type; uint32_t startAddress; uint32_t endAddress; - uint8_t value; + uint8_t value; //uint8_t* data; } edit_t; @@ -147,133 +152,135 @@ private: uint32_t vaddr; uint32_t paddr; uint32_t size; - const char* caption; + const char * caption; } jump_item_t; typedef struct { uint32_t address; - bool bVirtual; - int numBytesPerGroup; + bool bVirtual; + int numBytesPerGroup; } tab_info_t; static jump_item_t JumpItems[]; static int GetJumpItemIndex(uint32_t address, bool bVirtual); - CHexEditCtrl m_HexEditCtrl; - CEditNumber32 m_MemAddr; - CAddSymbolDlg m_AddSymbolDlg; - CButton m_VirtualCheckbox; - CMemTabCtrl m_TabCtrl; + CHexEditCtrl m_HexEditCtrl; + CEditNumber32 m_MemAddr; + CAddSymbolDlg m_AddSymbolDlg; + CButton m_VirtualCheckbox; + CMemTabCtrl m_TabCtrl; CStatusBarCtrl m_StatusBar; - CComboBox m_CmbJump; + CComboBox m_CmbJump; std::vector m_TabData; - CBreakpoints* m_Breakpoints; + CBreakpoints * m_Breakpoints; - int m_WriteTargetColorStride; - int m_ReadTargetColorStride; - int m_SymbolColorStride; - int m_SymbolColorPhase; - uint32_t m_ContextMenuAddress; - uint32_t m_HotAddress; - bool m_bIgnoreAddressInput; - bool m_bVirtualMemory; + int m_WriteTargetColorStride; + int m_ReadTargetColorStride; + int m_SymbolColorStride; + int m_SymbolColorPhase; + uint32_t m_ContextMenuAddress; + uint32_t m_HotAddress; + bool m_bIgnoreAddressInput; + bool m_bVirtualMemory; - bool m_bSafeEditMode; + bool m_bSafeEditMode; std::vector m_SafeEditQueue; - - bool GetByte(uint32_t address, uint8_t* value); - bool SetByte(uint32_t address, uint8_t value); - void SetupJumpMenu(bool bVirtual); - bool GetSafeEditValue(uint32_t address, uint8_t* value); - void ApplySafeEdits(void); - void CopyTextToClipboard(const char* text); - void CopyBytesToClipboard(uint32_t startAddress, uint32_t endAddress, bool bHex, bool bIncludeAddresses = false, bool bRowAddresses = false); - void CopyGameSharkCodeToClipboard(uint32_t startAddress, uint32_t endAddress); - void FillRange(uint32_t startAddress, uint32_t endAddress, uint8_t value); - void FollowPointer(bool bContextMenuAddress = true); - void JumpToSelection(void); - int AddTab(uint32_t address, bool bVirtual, int numBytesPerGroup); - int InsertTab(int nItem, uint32_t address, bool bVirtual, int numBytesPerGroup); - void DeleteTab(int index); - void UpdateCurrentTab(uint32_t address); - void OpenNewTab(uint32_t address, bool bVirtual, int numBytesPerGroup, bool bInsert = false, bool bOpenExisting = false); - void OpenDuplicateTab(void); - void CloseTab(int nItem); - void CloseCurrentTab(void); - void TabSelChanged(void); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnShowAddress(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - void OnAddrChanged(UINT Code, int id, HWND ctl); - void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar); - void OnExitSizeMove(void); - LRESULT OnDestroy(void); - LRESULT OnHxGetByteInfo(LPNMHDR lpNMHDR); - LRESULT OnHxSetNibble(LPNMHDR lpNMHDR); - LRESULT OnHxSetByte(LPNMHDR lpNMHDR); - LRESULT OnHxRightClick(LPNMHDR lpNMHDR); - LRESULT OnHxEnterPressed(LPNMHDR lpNMHDR); - LRESULT OnHxRedrawStarted(LPNMHDR lpNMHDR); - LRESULT OnHxBaseAddrChanged(LPNMHDR lpNMHDR); - LRESULT OnHxHotAddrChanged(LPNMHDR lpNMHDR); - LRESULT OnHxCopy(LPNMHDR lpNMHDR); - LRESULT OnHxPaste(LPNMHDR lpNMHDR); - LRESULT OnHxCtrlKeyPressed(LPNMHDR lpNMHDR); - LRESULT OnHxFillRange(LPNMHDR lpNMHDR); - LRESULT OnHxInsertModeChanged(LPNMHDR lpNMHDR); - LRESULT OnHxSelectionChanged(LPNMHDR lpNMHDR); - LRESULT OnHxGroupSizeChanged(LPNMHDR lpNMHDR); - LRESULT OnTabSelChange(LPNMHDR lpNMHDR); - LRESULT OnTabDblClick(LPNMHDR lpNMHDR); - LRESULT OnTabRClick(LPNMHDR lpNMHDR); - LRESULT OnStatusBarClick(LPNMHDR lpNMHDR); - void OnJumpComboSelChange(UINT uNotifyCode, int nID, CWindow wndCtl); + bool GetByte(uint32_t address, uint8_t * value); + bool SetByte(uint32_t address, uint8_t value); + void SetupJumpMenu(bool bVirtual); + bool GetSafeEditValue(uint32_t address, uint8_t * value); + void ApplySafeEdits(void); + void CopyTextToClipboard(const char * text); + void CopyBytesToClipboard(uint32_t startAddress, uint32_t endAddress, bool bHex, bool bIncludeAddresses = false, bool bRowAddresses = false); + void CopyGameSharkCodeToClipboard(uint32_t startAddress, uint32_t endAddress); + void FillRange(uint32_t startAddress, uint32_t endAddress, uint8_t value); + void FollowPointer(bool bContextMenuAddress = true); + void JumpToSelection(void); + int AddTab(uint32_t address, bool bVirtual, int numBytesPerGroup); + int InsertTab(int nItem, uint32_t address, bool bVirtual, int numBytesPerGroup); + void DeleteTab(int index); + void UpdateCurrentTab(uint32_t address); + void OpenNewTab(uint32_t address, bool bVirtual, int numBytesPerGroup, bool bInsert = false, bool bOpenExisting = false); + void OpenDuplicateTab(void); + void CloseTab(int nItem); + void CloseCurrentTab(void); + void TabSelChanged(void); + + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnShowAddress(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + void OnAddrChanged(UINT Code, int id, HWND ctl); + void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar); + void OnExitSizeMove(void); + LRESULT OnDestroy(void); + LRESULT OnHxGetByteInfo(LPNMHDR lpNMHDR); + LRESULT OnHxSetNibble(LPNMHDR lpNMHDR); + LRESULT OnHxSetByte(LPNMHDR lpNMHDR); + LRESULT OnHxRightClick(LPNMHDR lpNMHDR); + LRESULT OnHxEnterPressed(LPNMHDR lpNMHDR); + LRESULT OnHxRedrawStarted(LPNMHDR lpNMHDR); + LRESULT OnHxBaseAddrChanged(LPNMHDR lpNMHDR); + LRESULT OnHxHotAddrChanged(LPNMHDR lpNMHDR); + LRESULT OnHxCopy(LPNMHDR lpNMHDR); + LRESULT OnHxPaste(LPNMHDR lpNMHDR); + LRESULT OnHxCtrlKeyPressed(LPNMHDR lpNMHDR); + LRESULT OnHxFillRange(LPNMHDR lpNMHDR); + LRESULT OnHxInsertModeChanged(LPNMHDR lpNMHDR); + LRESULT OnHxSelectionChanged(LPNMHDR lpNMHDR); + LRESULT OnHxGroupSizeChanged(LPNMHDR lpNMHDR); + LRESULT OnTabSelChange(LPNMHDR lpNMHDR); + LRESULT OnTabDblClick(LPNMHDR lpNMHDR); + LRESULT OnTabRClick(LPNMHDR lpNMHDR); + LRESULT OnStatusBarClick(LPNMHDR lpNMHDR); + void OnJumpComboSelChange(UINT uNotifyCode, int nID, CWindow wndCtl); BEGIN_MSG_MAP_EX(CDebugMemoryView) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_SHOWADDRESS, OnShowAddress) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - COMMAND_HANDLER_EX(IDC_ADDR_EDIT, EN_CHANGE, OnAddrChanged) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_VSCROLL(OnVScroll) - COMMAND_HANDLER_EX(IDC_CMB_JUMP, CBN_SELCHANGE, OnJumpComboSelChange) - NOTIFY_HANDLER_EX(IDC_STATUSBAR, NM_CLICK, OnStatusBarClick) - NOTIFY_HANDLER_EX(IDC_MEMTABS, NM_DBLCLK, OnTabDblClick) - NOTIFY_HANDLER_EX(IDC_MEMTABS, TCN_SELCHANGE, OnTabSelChange) - NOTIFY_HANDLER_EX(IDC_MEMTABS, MTCN_RCLICK, OnTabRClick) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_GETBYTEINFO, OnHxGetByteInfo) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SETNIBBLE, OnHxSetNibble) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SETBYTE, OnHxSetByte) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_RCLICK, OnHxRightClick) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_HOTADDRCHANGED, OnHxHotAddrChanged) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_REDRAWSTARTED, OnHxRedrawStarted) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_BASEADDRCHANGED, OnHxBaseAddrChanged) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_HOTADDRCHANGED, OnHxHotAddrChanged) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_PASTE, OnHxPaste) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_CTRLKEYPRESSED, OnHxCtrlKeyPressed) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_FILLRANGE, OnHxFillRange) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_COPY, OnHxCopy) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_INSERTMODECHANGED, OnHxInsertModeChanged) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_ENTERPRESSED, OnHxEnterPressed) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SELCHANGED, OnHxSelectionChanged) - NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_GROUPSIZECHANGED, OnHxGroupSizeChanged) - CHAIN_MSG_MAP(CDialogResize) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_SHOWADDRESS, OnShowAddress); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + COMMAND_HANDLER_EX(IDC_ADDR_EDIT, EN_CHANGE, OnAddrChanged); + MSG_WM_EXITSIZEMOVE(OnExitSizeMove); + MSG_WM_DESTROY(OnDestroy); + MSG_WM_VSCROLL(OnVScroll); + COMMAND_HANDLER_EX(IDC_CMB_JUMP, CBN_SELCHANGE, OnJumpComboSelChange); + NOTIFY_HANDLER_EX(IDC_STATUSBAR, NM_CLICK, OnStatusBarClick); + NOTIFY_HANDLER_EX(IDC_MEMTABS, NM_DBLCLK, OnTabDblClick); + NOTIFY_HANDLER_EX(IDC_MEMTABS, TCN_SELCHANGE, OnTabSelChange); + NOTIFY_HANDLER_EX(IDC_MEMTABS, MTCN_RCLICK, OnTabRClick); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_GETBYTEINFO, OnHxGetByteInfo); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SETNIBBLE, OnHxSetNibble); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SETBYTE, OnHxSetByte); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_RCLICK, OnHxRightClick); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_HOTADDRCHANGED, OnHxHotAddrChanged); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_REDRAWSTARTED, OnHxRedrawStarted); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_BASEADDRCHANGED, OnHxBaseAddrChanged); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_HOTADDRCHANGED, OnHxHotAddrChanged); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_PASTE, OnHxPaste); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_CTRLKEYPRESSED, OnHxCtrlKeyPressed); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_FILLRANGE, OnHxFillRange); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_COPY, OnHxCopy); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_INSERTMODECHANGED, OnHxInsertModeChanged); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_ENTERPRESSED, OnHxEnterPressed); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_SELCHANGED, OnHxSelectionChanged); + NOTIFY_HANDLER_EX(IDC_HEXEDIT, HXN_GROUPSIZECHANGED, OnHxGroupSizeChanged); + CHAIN_MSG_MAP(CDialogResize); + } END_MSG_MAP() BEGIN_DLGRESIZE_MAP(CDebugMemoryView) - DLGRESIZE_CONTROL(IDC_CMB_JUMP, DLSZ_MOVE_X) - DLGRESIZE_CONTROL(IDC_STATUSBAR, DLSZ_SIZE_X | DLSZ_MOVE_Y) - DLGRESIZE_CONTROL(IDC_HEXEDIT, DLSZ_SIZE_X | DLSZ_SIZE_Y) - DLGRESIZE_CONTROL(IDC_MEMTABS, DLSZ_SIZE_X) - DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_MOVE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_CMB_JUMP, DLSZ_MOVE_X) + DLGRESIZE_CONTROL(IDC_STATUSBAR, DLSZ_SIZE_X | DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_HEXEDIT, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_MEMTABS, DLSZ_SIZE_X) + DLGRESIZE_CONTROL(IDC_SCRL_BAR, DLSZ_MOVE_X | DLSZ_SIZE_Y) END_DLGRESIZE_MAP() BEGIN_TOOLTIP_MAP() - TOOLTIP(IDC_SYMBOLS_BTN, "Symbols...") - TOOLTIP(IDC_CHK_VADDR, "Checked = Use virtual address space (CPU), Unchecked = Use physical address space (RCP)") + TOOLTIP(IDC_SYMBOLS_BTN, "Symbols...") + TOOLTIP(IDC_CHK_VADDR, "Checked = Use virtual address space (CPU), Unchecked = Use physical address space (RCP)") END_TOOLTIP_MAP() }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger.cpp b/Source/Project64/UserInterface/Debugger/Debugger.cpp index 903ec7f48..5baa9062a 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger.cpp @@ -613,13 +613,11 @@ void CDebuggerUI::CPUStepStarted() m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_EXEC, (void *)&hookEnv); } - if (hookEnv.opInfo.IsLoadCommand() && - m_ScriptSystem->HaveCpuReadCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) + if (hookEnv.opInfo.IsLoadCommand() && m_ScriptSystem->HaveCpuReadCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) { m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_READ, (void *)&hookEnv); } - else if (hookEnv.opInfo.IsStoreCommand() && - m_ScriptSystem->HaveCpuWriteCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) + else if (hookEnv.opInfo.IsStoreCommand() && m_ScriptSystem->HaveCpuWriteCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) { m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_WRITE, (void *)&hookEnv); } @@ -629,8 +627,7 @@ void CDebuggerUI::CPUStepStarted() { uint32_t pc = g_Reg->m_PROGRAM_COUNTER; - if (pc == 0x80000000 || pc == 0x80000080 || - pc == 0xA0000100 || pc == 0x80000180) + if (pc == 0x80000000 || pc == 0x80000080 || pc == 0xA0000100 || pc == 0x80000180) { if ((g_Reg->STATUS_REGISTER >> 1) & 3) // If EXL/ERL bits are set { @@ -659,17 +656,13 @@ void CDebuggerUI::CPUStepStarted() int nReg1 = 0, nReg2 = 0; opInfo.ReadsGPR(&nReg1, &nReg2); - if ((nReg1 != 0 && m_Breakpoints->HaveGPRReadBP(nReg1)) || - (nReg2 != 0 && m_Breakpoints->HaveGPRReadBP(nReg2))) + if ((nReg1 != 0 && m_Breakpoints->HaveGPRReadBP(nReg1)) || (nReg2 != 0 && m_Breakpoints->HaveGPRReadBP(nReg2))) { g_Settings->SaveBool(Debugger_SteppingOps, true); } } - if (m_Breakpoints->HaveHIWriteBP() && opInfo.WritesHI() || - m_Breakpoints->HaveLOWriteBP() && opInfo.WritesLO() || - m_Breakpoints->HaveHIReadBP() && opInfo.ReadsHI() || - m_Breakpoints->HaveLOReadBP() && opInfo.ReadsLO()) + if (m_Breakpoints->HaveHIWriteBP() && opInfo.WritesHI() || m_Breakpoints->HaveLOWriteBP() && opInfo.WritesLO() || m_Breakpoints->HaveHIReadBP() && opInfo.ReadsHI() || m_Breakpoints->HaveLOReadBP() && opInfo.ReadsLO()) { g_Settings->SaveBool(Debugger_SteppingOps, true); } diff --git a/Source/Project64/UserInterface/Debugger/DebuggerUI.h b/Source/Project64/UserInterface/Debugger/DebuggerUI.h index fccd5e324..f5a2b1ac0 100644 --- a/Source/Project64/UserInterface/Debugger/DebuggerUI.h +++ b/Source/Project64/UserInterface/Debugger/DebuggerUI.h @@ -1,20 +1,20 @@ #pragma once -#include "../../WTLApp.h" #include "../../N64System.h" +#include "../../WTLApp.h" #include "DebugDialog.h" -#include "Debugger-MemorySearch.h" -#include "Debugger-ViewMemory.h" -#include "Debugger-MemoryDump.h" -#include "Debugger-TLB.h" -#include "Debugger-Commands.h" -#include "Debugger-Scripts.h" -#include "Debugger-ScriptsAutorun.h" -#include "Debugger-Symbols.h" #include "Debugger-AddBreakpoint.h" #include "Debugger-AddSymbol.h" -#include "Debugger-DMALogView.h" #include "Debugger-CPULogView.h" -#include "Debugger-StackView.h" -#include "Debugger-StackTrace.h" +#include "Debugger-Commands.h" +#include "Debugger-DMALogView.h" #include "Debugger-ExceptionBreakpoints.h" +#include "Debugger-MemoryDump.h" +#include "Debugger-MemorySearch.h" +#include "Debugger-Scripts.h" +#include "Debugger-ScriptsAutorun.h" +#include "Debugger-StackTrace.h" +#include "Debugger-StackView.h" +#include "Debugger-Symbols.h" +#include "Debugger-TLB.h" +#include "Debugger-ViewMemory.h" diff --git a/Source/Project64/UserInterface/Debugger/MemoryScanner.cpp b/Source/Project64/UserInterface/Debugger/MemoryScanner.cpp index 1404599e5..1a4412e7b 100644 --- a/Source/Project64/UserInterface/Debugger/MemoryScanner.cpp +++ b/Source/Project64/UserInterface/Debugger/MemoryScanner.cpp @@ -16,7 +16,7 @@ CMixed::TypeNameEntry CMixed::TypeNames[] = { {"char", ValueType_string}, {"char", ValueType_unkstring}, {"char", ValueType_unkstring}, - { nullptr, ValueType_invalid} + {nullptr, ValueType_invalid}, }; const char * CMixed::GetTypeName(void) @@ -231,9 +231,7 @@ int CScanResult::GetMemoryValueString(char * buffer, size_t size, bool bIgnoreHe uint8_t * mem = CMemoryScanner::GetMemoryPool(paddr); - if (m_Type == ValueType_istring || - m_Type == ValueType_string || - m_Type == ValueType_unkstring) + if (m_Type == ValueType_istring || m_Type == ValueType_string || m_Type == ValueType_unkstring) { if (bHex) { @@ -407,9 +405,7 @@ bool CScanResult::SetAddressSafe(uint32_t address) return false; } - if (!CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x00000000, ramSize - 1) && - !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x10000000, 0x10000000 + romSize - 1) && - !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x04000000, 0x04001FFF)) + if (!CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x00000000, ramSize - 1) && !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x10000000, 0x10000000 + romSize - 1) && !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x04000000, 0x04001FFF)) { return false; } @@ -432,9 +428,7 @@ bool CScanResult::SetStrLengthSafe(int length) uint32_t paddrStart = m_Address & 0x1FFFFFFF; uint32_t paddrEnd = (paddrStart + length) - 1; - if (!CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x00000000, ramSize - 1) && - !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x10000000, 0x10000000 + romSize - 1) && - !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x04000000, 0x04001FFF)) + if (!CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x00000000, ramSize - 1) && !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x10000000, 0x10000000 + romSize - 1) && !CMemoryScanner::RangeCheck(paddrStart, paddrEnd, 0x04000000, 0x04001FFF)) { return false; } @@ -488,16 +482,12 @@ bool CMemoryScanner::PAddrValid(uint32_t physAddr) uint32_t ramSize = g_MMU->RdramSize(); uint32_t romSize = g_Rom->GetRomSize(); - return (AddrCheck(physAddr, 0x00000000, 0x00000000 + ramSize - 1) || - AddrCheck(physAddr, 0x10000000, 0x10000000 + romSize - 1) || - AddrCheck(physAddr, 0x04000000, 0x04001FFF)); + return (AddrCheck(physAddr, 0x00000000, 0x00000000 + ramSize - 1) || AddrCheck(physAddr, 0x10000000, 0x10000000 + romSize - 1) || AddrCheck(physAddr, 0x04000000, 0x04001FFF)); } bool CMemoryScanner::PAddrRangeValid(uint32_t physAddrStart, uint32_t physAddrEnd) { - return (RangeCheck(physAddrStart, physAddrEnd, 0x00000000, g_MMU->RdramSize()) || - RangeCheck(physAddrStart, physAddrEnd, 0x04000000, 0x04001FFF) || - RangeCheck(physAddrStart, physAddrEnd, 0x10000000, 0x15FFFFFF)); + return (RangeCheck(physAddrStart, physAddrEnd, 0x00000000, g_MMU->RdramSize()) || RangeCheck(physAddrStart, physAddrEnd, 0x04000000, 0x04001FFF) || RangeCheck(physAddrStart, physAddrEnd, 0x10000000, 0x15FFFFFF)); } void CMemoryScanner::SetAddressType(AddressType addressType) @@ -587,8 +577,7 @@ uint8_t * CMemoryScanner::GetMemoryPool(uint32_t physAddr) return nullptr; } - if ((physAddr >= 0x00000000 && physAddr < g_MMU->RdramSize()) || - (physAddr >= 0x04000000 && physAddr <= 0x04001FFF)) + if ((physAddr >= 0x00000000 && physAddr < g_MMU->RdramSize()) || (physAddr >= 0x04000000 && physAddr <= 0x04001FFF)) { return g_MMU->Rdram(); } diff --git a/Source/Project64/UserInterface/Debugger/MemoryScanner.h b/Source/Project64/UserInterface/Debugger/MemoryScanner.h index 0f45d3ead..4995c0d74 100644 --- a/Source/Project64/UserInterface/Debugger/MemoryScanner.h +++ b/Source/Project64/UserInterface/Debugger/MemoryScanner.h @@ -49,18 +49,19 @@ enum DisplayFormat DisplayHex }; -typedef union { - uint8_t _uint8; - int8_t _sint8; - uint16_t _uint16; - int16_t _sint16; - uint32_t _uint32; - int32_t _sint32; - uint64_t _uint64; - int64_t _sint64; - float _float; - double _double; - const wchar_t* _string; +typedef union +{ + uint8_t _uint8; + int8_t _sint8; + uint16_t _uint16; + int16_t _sint16; + uint32_t _uint32; + int32_t _sint32; + uint64_t _uint64; + int64_t _sint64; + float _float; + double _double; + const wchar_t * _string; } MixedValue; class CMixed @@ -79,47 +80,136 @@ public: m_Type = ValueType_uint64; } - inline void SetType(ValueType t) { m_Type = t; } - inline ValueType GetType(void) { return m_Type; } + inline void SetType(ValueType t) + { + m_Type = t; + } + inline ValueType GetType(void) + { + return m_Type; + } - inline void SetStrLength(int length) { m_StrLength = length; } - inline int GetStrLength(void) { return m_StrLength; } + inline void SetStrLength(int length) + { + m_StrLength = length; + } + inline int GetStrLength(void) + { + return m_StrLength; + } - inline void Set(uint8_t v) { SetType(ValueType_uint8); m_Value._uint8 = v; } - inline void Set(int8_t v) { SetType(ValueType_int8); m_Value._sint8 = v; } - inline void Set(uint16_t v) { SetType(ValueType_uint16); m_Value._uint16 = v; } - inline void Set(int16_t v) { SetType(ValueType_int16); m_Value._sint16 = v; } - inline void Set(uint32_t v) { SetType(ValueType_uint32); m_Value._uint32 = v; } - inline void Set(int32_t v) { SetType(ValueType_int32); m_Value._sint32 = v; } - inline void Set(uint64_t v) { SetType(ValueType_uint64); m_Value._uint64 = v; } - inline void Set(int64_t v) { SetType(ValueType_int64); m_Value._sint64 = v; } - inline void Set(float v) { SetType(ValueType_float); m_Value._float = v; } - inline void Set(double v) { SetType(ValueType_double); m_Value._double = v; } - inline void Set(const wchar_t* v) { SetType(ValueType_string); m_Value._string = v; } + inline void Set(uint8_t v) + { + SetType(ValueType_uint8); + m_Value._uint8 = v; + } + inline void Set(int8_t v) + { + SetType(ValueType_int8); + m_Value._sint8 = v; + } + inline void Set(uint16_t v) + { + SetType(ValueType_uint16); + m_Value._uint16 = v; + } + inline void Set(int16_t v) + { + SetType(ValueType_int16); + m_Value._sint16 = v; + } + inline void Set(uint32_t v) + { + SetType(ValueType_uint32); + m_Value._uint32 = v; + } + inline void Set(int32_t v) + { + SetType(ValueType_int32); + m_Value._sint32 = v; + } + inline void Set(uint64_t v) + { + SetType(ValueType_uint64); + m_Value._uint64 = v; + } + inline void Set(int64_t v) + { + SetType(ValueType_int64); + m_Value._sint64 = v; + } + inline void Set(float v) + { + SetType(ValueType_float); + m_Value._float = v; + } + inline void Set(double v) + { + SetType(ValueType_double); + m_Value._double = v; + } + inline void Set(const wchar_t * v) + { + SetType(ValueType_string); + m_Value._string = v; + } - inline void Get(uint8_t* v) { *v = m_Value._uint8; } - inline void Get(int8_t* v) { *v = m_Value._sint8; } - inline void Get(uint16_t* v) { *v = m_Value._uint16; } - inline void Get(int16_t* v) { *v = m_Value._sint16; } - inline void Get(uint32_t* v) { *v = m_Value._uint32; } - inline void Get(int32_t* v) { *v = m_Value._sint32; } - inline void Get(uint64_t* v) { *v = m_Value._uint64; } - inline void Get(int64_t* v) { *v = m_Value._sint64; } - inline void Get(float* v) { *v = m_Value._float; } - inline void Get(double* v) { *v = m_Value._double; } - inline void Get(const wchar_t** v) { *v = m_Value._string; } + inline void Get(uint8_t * v) + { + *v = m_Value._uint8; + } + inline void Get(int8_t * v) + { + *v = m_Value._sint8; + } + inline void Get(uint16_t * v) + { + *v = m_Value._uint16; + } + inline void Get(int16_t * v) + { + *v = m_Value._sint16; + } + inline void Get(uint32_t * v) + { + *v = m_Value._uint32; + } + inline void Get(int32_t * v) + { + *v = m_Value._sint32; + } + inline void Get(uint64_t * v) + { + *v = m_Value._uint64; + } + inline void Get(int64_t * v) + { + *v = m_Value._sint64; + } + inline void Get(float * v) + { + *v = m_Value._float; + } + inline void Get(double * v) + { + *v = m_Value._double; + } + inline void Get(const wchar_t ** v) + { + *v = m_Value._string; + } - const char* GetTypeName(void); + const char * GetTypeName(void); int GetTypeSize(void); bool IsStringType(void); - int ToString(char* buffer, bool bHex, size_t size); + int ToString(char * buffer, bool bHex, size_t size); - static ValueType GetTypeFromString(const char* name, int* typeArraySize); + static ValueType GetTypeFromString(const char * name, int * typeArraySize); private: typedef struct { - const char* name; + const char * name; ValueType type; } TypeNameEntry; @@ -139,17 +229,17 @@ public: std::string m_Description; public: - int GetValueString(char* buffer, size_t size); - int GetMemoryValueString(char* buffer, size_t size, bool bIgnoreHex = false); - int GetAddressString(char *buffer); + int GetValueString(char * buffer, size_t size); + int GetMemoryValueString(char * buffer, size_t size, bool bIgnoreHex = false); + int GetAddressString(char * buffer); uint32_t GetVirtualAddress(void); - bool SetMemoryValueFromString(const char* str); + bool SetMemoryValueFromString(const char * str); //bool IsSelected(void); //void SetSelected(bool bSelected); - void SetDescription(const char* str); - const char* GetDescription(void); + void SetDescription(const char * str); + const char * GetDescription(void); void DeleteDescription(void); - bool GetMemoryValue(CMixed* v); + bool GetMemoryValue(CMixed * v); bool SetAddressSafe(uint32_t address); bool SetStrLengthSafe(int length); @@ -165,7 +255,7 @@ public: bool SetSearchType(SearchType searchType); void SetAddressType(AddressType addressType); - static int ParseHexString(char* dst, const char* src); + static int ParseHexString(char * dst, const char * src); static bool AddrCheck(uint32_t addr, uint32_t rangeStart, uint32_t rangeEnd); static bool RangeCheck(uint32_t addrStart, uint32_t addrEnd, uint32_t rangeStart, uint32_t rangeEnd); @@ -175,7 +265,7 @@ public: template void SetValue(T value) { - *(T*)&m_Value = value; + *(T *)&m_Value = value; } void SetStringValueLength(int length); @@ -187,15 +277,15 @@ public: bool DidFirstScan(void); size_t GetNumResults(void); - CScanResult* GetResult(size_t index); + CScanResult * GetResult(size_t index); void RemoveResult(size_t index); private: static int HexDigitVal(char c); - uint8_t* m_Memory; + uint8_t * m_Memory; bool m_DidFirstScan; - + uint32_t m_RangeStartAddress; uint32_t m_RangeEndAddress; @@ -204,32 +294,60 @@ private: SearchType m_SearchType; AddressType m_AddressType; uint32_t m_VAddrBits; - + std::vector m_Results; std::vector m_NewResults; - + MixedValue m_Value; int m_StringValueLength; friend class CScanResult; - static uint8_t* GetMemoryPool(uint32_t physAddr); + static uint8_t * GetMemoryPool(uint32_t physAddr); - template static bool CompareLessThan(T a, T b) { return a < b; } - template static bool CompareLessThanOrEqual(T a, T b) { return a <= b; } - template static bool CompareGreaterThan(T a, T b) { return a > b; } - template static bool CompareGreaterThanOrEqual(T a, T b) { return a >= b; } - template static bool CompareEqual(T a, T b) { return a == b; } - template static bool CompareNotEqual(T a, T b) { return a != b; } - template static bool NoCompare(T /*a*/, T /*b*/) { return true; } + template + static bool CompareLessThan(T a, T b) + { + return a < b; + } + template + static bool CompareLessThanOrEqual(T a, T b) + { + return a <= b; + } + template + static bool CompareGreaterThan(T a, T b) + { + return a > b; + } + template + static bool CompareGreaterThanOrEqual(T a, T b) + { + return a >= b; + } + template + static bool CompareEqual(T a, T b) + { + return a == b; + } + template + static bool CompareNotEqual(T a, T b) + { + return a != b; + } + template + static bool NoCompare(T /*a*/, T /*b*/) + { + return true; + } void FirstScanLoopString(DisplayFormat resultDisplayFormat); void FirstScanLoopIString(DisplayFormat resultDisplayFormat); void FirstScanLoopUnkString(void); - + template - void FirstScanLoopPrimitive(bool(*CompareFunc)(T, T), DisplayFormat resultDisplayFormat) + void FirstScanLoopPrimitive(bool (*CompareFunc)(T, T), DisplayFormat resultDisplayFormat) { - T searchValue = *(T*)&m_Value; + T searchValue = *(T *)&m_Value; uint32_t startAddr = ((m_RangeStartAddress - 1) | (sizeof(T) - 1)) + 1; uint32_t endAddr = m_RangeEndAddress; @@ -238,7 +356,7 @@ private: for (uint32_t addr = startAddr; addr <= endAddr; addr += sizeof(T)) { uint32_t leAddr = (addr ^ (4 - sizeof(T))); - T memValue = *(T*)&m_Memory[leAddr]; + T memValue = *(T *)&m_Memory[leAddr]; if (CompareFunc(memValue, searchValue)) { @@ -248,12 +366,12 @@ private: } } } - + // For int64 and double template - void FirstScanLoopPrimitive64(bool(*CompareFunc)(T, T), DisplayFormat resultDisplayFormat) + void FirstScanLoopPrimitive64(bool (*CompareFunc)(T, T), DisplayFormat resultDisplayFormat) { - T searchValue = *(T*)&m_Value; + T searchValue = *(T *)&m_Value; uint32_t startAddr = ((m_RangeStartAddress - 1) | (sizeof(T) - 1)) + 1; uint32_t endAddr = m_RangeEndAddress; @@ -263,8 +381,8 @@ private: { T memValue; - *((uint32_t*)(&memValue) + 1) = *(uint32_t*) &m_Memory[addr]; - *((uint32_t*)(&memValue) + 0) = *(uint32_t*) &m_Memory[addr + 4]; + *((uint32_t *)(&memValue) + 1) = *(uint32_t *)&m_Memory[addr]; + *((uint32_t *)(&memValue) + 0) = *(uint32_t *)&m_Memory[addr + 4]; if (CompareFunc(memValue, searchValue)) { @@ -277,17 +395,17 @@ private: // Compare result's current value in memory against m_Value template - void NextScanLoopPrimitive(bool(*CompareFunc)(T, T)) + void NextScanLoopPrimitive(bool (*CompareFunc)(T, T)) { - T searchValue = *(T*)&m_Value; + T searchValue = *(T *)&m_Value; for (size_t index = 0; index < m_Results.size(); index++) { - CScanResult* presult = &m_Results[index]; + CScanResult * presult = &m_Results[index]; uint32_t addr = presult->m_Address & 0x1FFFFFFF; uint32_t leAddr = (addr ^ (4 - sizeof(T))); - T memValue = *(T*) &m_Memory[leAddr]; + T memValue = *(T *)&m_Memory[leAddr]; if (CompareFunc(memValue, searchValue)) { @@ -302,19 +420,19 @@ private: // Compare result's current value in memory against m_Value (for 64-bit types) template - void NextScanLoopPrimitive64(bool(*CompareFunc)(T, T)) + void NextScanLoopPrimitive64(bool (*CompareFunc)(T, T)) { - T searchValue = *(T*)&m_Value; + T searchValue = *(T *)&m_Value; for (size_t index = 0; index < m_Results.size(); index++) { - CScanResult* presult = &m_Results[index]; + CScanResult * presult = &m_Results[index]; uint32_t addr = presult->m_Address & 0x1FFFFFFF; T memValue; - *((uint32_t*)(&memValue) + 1) = *(uint32_t*) &m_Memory[addr]; - *((uint32_t*)(&memValue) + 0) = *(uint32_t*) &m_Memory[addr + 4]; + *((uint32_t *)(&memValue) + 1) = *(uint32_t *)&m_Memory[addr]; + *((uint32_t *)(&memValue) + 0) = *(uint32_t *)&m_Memory[addr + 4]; if (CompareFunc(memValue, searchValue)) { @@ -329,17 +447,17 @@ private: // Compare result's current value in memory against result's old value template - void NextScanLoopPrimitiveResults(bool(*CompareFunc)(T, T)) + void NextScanLoopPrimitiveResults(bool (*CompareFunc)(T, T)) { for (size_t index = 0; index < m_Results.size(); index++) { - CScanResult* presult = &m_Results[index]; + CScanResult * presult = &m_Results[index]; uint32_t addr = presult->m_Address & 0x1FFFFFFF; uint32_t leAddr = (addr ^ (4 - sizeof(T))); T memValue, oldValue; - memValue = *(T*)&m_Memory[leAddr]; + memValue = *(T *)&m_Memory[leAddr]; presult->Get(&oldValue); if (CompareFunc(memValue, oldValue)) @@ -355,18 +473,18 @@ private: // Compare result's current value in memory against result's old value (for 64-bit types) template - void NextScanLoopPrimitiveResults64(bool(*CompareFunc)(T, T)) + void NextScanLoopPrimitiveResults64(bool (*CompareFunc)(T, T)) { for (size_t index = 0; index < m_Results.size(); index++) { - CScanResult* presult = &m_Results[index]; + CScanResult * presult = &m_Results[index]; uint32_t addr = presult->m_Address & 0x1FFFFFFF; T memValue, oldValue; - *((uint32_t*)(&memValue) + 1) = *(uint32_t*)&m_Memory[addr]; - *((uint32_t*)(&memValue) + 0) = *(uint32_t*)&m_Memory[addr + 4]; + *((uint32_t *)(&memValue) + 1) = *(uint32_t *)&m_Memory[addr]; + *((uint32_t *)(&memValue) + 0) = *(uint32_t *)&m_Memory[addr + 4]; presult->Get(&oldValue); diff --git a/Source/Project64/UserInterface/Debugger/OpInfo.h b/Source/Project64/UserInterface/Debugger/OpInfo.h index e835ece70..9a33f5ddb 100644 --- a/Source/Project64/UserInterface/Debugger/OpInfo.h +++ b/Source/Project64/UserInterface/Debugger/OpInfo.h @@ -5,14 +5,13 @@ class COpInfo { public: - R4300iOpcode m_OpCode; COpInfo() { } - inline COpInfo(R4300iOpcode opcode): + inline COpInfo(R4300iOpcode opcode) : m_OpCode(opcode) { } @@ -135,14 +134,12 @@ public: inline bool IsLoadCommand() { - return (m_OpCode.op >= R4300i_LDL && m_OpCode.op <= R4300i_LWU || - m_OpCode.op >= R4300i_LL && m_OpCode.op <= R4300i_LD); + return (m_OpCode.op >= R4300i_LDL && m_OpCode.op <= R4300i_LWU || m_OpCode.op >= R4300i_LL && m_OpCode.op <= R4300i_LD); } inline bool IsStoreCommand() { - return (m_OpCode.op >= R4300i_SB && m_OpCode.op <= R4300i_SWR || - m_OpCode.op >= R4300i_SC && m_OpCode.op <= R4300i_SD); + return (m_OpCode.op >= R4300i_SB && m_OpCode.op <= R4300i_SWR || m_OpCode.op >= R4300i_SC && m_OpCode.op <= R4300i_SD); } // ADDIU SP, SP, X @@ -152,7 +149,7 @@ public: } // ADDIU SP, SP, - bool IsStackAlloc() + bool IsStackAlloc() { if (!IsStackShift()) { @@ -163,7 +160,7 @@ public: } // ADDIU SP, SP, - bool IsStackFree() + bool IsStackFree() { if (!IsStackShift()) { @@ -173,7 +170,7 @@ public: return (short)m_OpCode.immediate > 0; } - void ReadsGPR(int* nReg1, int* nReg2) + void ReadsGPR(int * nReg1, int * nReg2) { uint32_t op = m_OpCode.op; @@ -181,25 +178,21 @@ public: { uint32_t fn = m_OpCode.funct; - if (fn >= R4300i_SPECIAL_SLLV && fn <= R4300i_SPECIAL_SRAV || - fn >= R4300i_SPECIAL_DSLLV && fn <= R4300i_SPECIAL_DSRAV || - fn >= R4300i_SPECIAL_MULT && fn <= R4300i_SPECIAL_TNE) + if (fn >= R4300i_SPECIAL_SLLV && fn <= R4300i_SPECIAL_SRAV || fn >= R4300i_SPECIAL_DSLLV && fn <= R4300i_SPECIAL_DSRAV || fn >= R4300i_SPECIAL_MULT && fn <= R4300i_SPECIAL_TNE) { *nReg1 = m_OpCode.rs; *nReg2 = m_OpCode.rt; return; } - if (fn == R4300i_SPECIAL_MTLO || fn == R4300i_SPECIAL_MTHI || - fn == R4300i_SPECIAL_JR || fn == R4300i_SPECIAL_JALR) + if (fn == R4300i_SPECIAL_MTLO || fn == R4300i_SPECIAL_MTHI || fn == R4300i_SPECIAL_JR || fn == R4300i_SPECIAL_JALR) { *nReg1 = m_OpCode.rs; *nReg2 = 0; return; } - if (fn >= R4300i_SPECIAL_SLL && fn <= R4300i_SPECIAL_SRA || - fn >= R4300i_SPECIAL_DSLL && fn <= R4300i_SPECIAL_DSRA32) + if (fn >= R4300i_SPECIAL_SLL && fn <= R4300i_SPECIAL_SRA || fn >= R4300i_SPECIAL_DSLL && fn <= R4300i_SPECIAL_DSRA32) { *nReg1 = m_OpCode.rt; *nReg2 = 0; @@ -211,21 +204,14 @@ public: return; } - if (op >= R4300i_SB && op <= R4300i_SWR || - op == R4300i_SC || op == R4300i_SD || - op == R4300i_BEQ || op == R4300i_BEQL || - op == R4300i_BNE || op == R4300i_BNEL) + if (op >= R4300i_SB && op <= R4300i_SWR || op == R4300i_SC || op == R4300i_SD || op == R4300i_BEQ || op == R4300i_BEQL || op == R4300i_BNE || op == R4300i_BNEL) { *nReg1 = m_OpCode.rs; *nReg2 = m_OpCode.rt; return; } - if (op >= R4300i_BLEZL && op <= R4300i_LWU || - op >= R4300i_BLEZ && op <= R4300i_XORI || - op >= R4300i_CACHE && op <= R4300i_LD || - op >= R4300i_SWC1 && op <= R4300i_SDC2 || - op == R4300i_REGIMM) + if (op >= R4300i_BLEZL && op <= R4300i_LWU || op >= R4300i_BLEZ && op <= R4300i_XORI || op >= R4300i_CACHE && op <= R4300i_LD || op >= R4300i_SWC1 && op <= R4300i_SDC2 || op == R4300i_REGIMM) { *nReg1 = m_OpCode.rs; *nReg2 = 0; @@ -241,9 +227,7 @@ public: if (op == R4300i_CP1) { - if (m_OpCode.fmt == R4300i_COP1_MT || - m_OpCode.fmt == R4300i_COP1_DMT || - m_OpCode.fmt == R4300i_COP1_CT) + if (m_OpCode.fmt == R4300i_COP1_MT || m_OpCode.fmt == R4300i_COP1_DMT || m_OpCode.fmt == R4300i_COP1_CT) { *nReg1 = m_OpCode.rt; *nReg2 = 0; @@ -255,7 +239,7 @@ public: *nReg2 = 0; } - inline void WritesGPR(int* nReg) + inline void WritesGPR(int * nReg) { uint32_t op = m_OpCode.op; @@ -263,12 +247,7 @@ public: { uint32_t fn = m_OpCode.funct; - if (fn >= R4300i_SPECIAL_SLL && fn <= R4300i_SPECIAL_SRAV || - fn >= R4300i_SPECIAL_DSLLV && fn <= R4300i_SPECIAL_DSRAV || - fn >= R4300i_SPECIAL_DIVU && fn <= R4300i_SPECIAL_DSUBU || - fn >= R4300i_SPECIAL_DSLL && fn <= R4300i_SPECIAL_DSRA32 || - fn == R4300i_SPECIAL_JALR || fn == R4300i_SPECIAL_MFLO || - fn == R4300i_SPECIAL_MFHI) + if (fn >= R4300i_SPECIAL_SLL && fn <= R4300i_SPECIAL_SRAV || fn >= R4300i_SPECIAL_DSLLV && fn <= R4300i_SPECIAL_DSRAV || fn >= R4300i_SPECIAL_DIVU && fn <= R4300i_SPECIAL_DSUBU || fn >= R4300i_SPECIAL_DSLL && fn <= R4300i_SPECIAL_DSRA32 || fn == R4300i_SPECIAL_JALR || fn == R4300i_SPECIAL_MFLO || fn == R4300i_SPECIAL_MFHI) { *nReg = m_OpCode.rd; return; @@ -278,12 +257,7 @@ public: return; } - if (op >= R4300i_DADDI && op <= R4300i_LWU || - op >= R4300i_ADDI && op <= R4300i_LUI || - op == R4300i_LL || op == R4300i_LD || - (op == R4300i_CP0 && m_OpCode.fmt == R4300i_COP0_MF) || - (op == R4300i_CP1 && m_OpCode.fmt == R4300i_COP1_MF) || - (op == R4300i_CP1 && m_OpCode.fmt == R4300i_COP1_CF)) + if (op >= R4300i_DADDI && op <= R4300i_LWU || op >= R4300i_ADDI && op <= R4300i_LUI || op == R4300i_LL || op == R4300i_LD || (op == R4300i_CP0 && m_OpCode.fmt == R4300i_COP0_MF) || (op == R4300i_CP1 && m_OpCode.fmt == R4300i_COP1_MF) || (op == R4300i_CP1 && m_OpCode.fmt == R4300i_COP1_CF)) { *nReg = m_OpCode.rt; return; @@ -312,8 +286,7 @@ public: { if (m_OpCode.op == R4300i_SPECIAL) { - if (m_OpCode.funct == R4300i_SPECIAL_MTHI || - m_OpCode.funct >= R4300i_SPECIAL_MULT && m_OpCode.funct <= R4300i_SPECIAL_DDIVU) + if (m_OpCode.funct == R4300i_SPECIAL_MTHI || m_OpCode.funct >= R4300i_SPECIAL_MULT && m_OpCode.funct <= R4300i_SPECIAL_DDIVU) { return true; } @@ -325,8 +298,7 @@ public: { if (m_OpCode.op == R4300i_SPECIAL) { - if (m_OpCode.funct == R4300i_SPECIAL_MTLO || - m_OpCode.funct >= R4300i_SPECIAL_MULT && m_OpCode.funct <= R4300i_SPECIAL_DDIVU) + if (m_OpCode.funct == R4300i_SPECIAL_MTLO || m_OpCode.funct >= R4300i_SPECIAL_MULT && m_OpCode.funct <= R4300i_SPECIAL_DDIVU) { return true; } diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSIntervalWorker.h b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSIntervalWorker.h index f1b45323a..6d2dd6004 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSIntervalWorker.h +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSIntervalWorker.h @@ -2,13 +2,15 @@ #pragma once -class CJSIntervalWorker : public CScriptWorker { +class CJSIntervalWorker : public CScriptWorker +{ private: int m_DelayMS; bool m_bOnce; HANDLE m_hTimerQuitEvent; + public: - CJSIntervalWorker(CScriptInstance* inst, void* dukObjectHeapPtr, int delayMS, bool bOnce); + CJSIntervalWorker(CScriptInstance * inst, void * dukObjectHeapPtr, int delayMS, bool bOnce); virtual ~CJSIntervalWorker(); virtual void WorkerProc(); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.cpp index 4ba6e4de4..ac08e58fa 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.cpp @@ -3,7 +3,7 @@ #include "JSServerWorker.h" #include "JSSocketWorker.h" -CJSServerWorker::CJSServerWorker(CScriptInstance* instance, void* dukObjectHeapPtr) : +CJSServerWorker::CJSServerWorker(CScriptInstance * instance, void * dukObjectHeapPtr) : CScriptWorker(instance, dukObjectHeapPtr), m_bWinsockOK(false), m_ServerSocket(INVALID_SOCKET) @@ -22,7 +22,7 @@ CJSServerWorker::~CJSServerWorker() } } -void CJSServerWorker::Init(const char* address, unsigned short port) +void CJSServerWorker::Init(const char * address, unsigned short port) { m_Queue.listenAddress = address; m_Queue.listenPort = port; @@ -32,9 +32,10 @@ void CJSServerWorker::WorkerProc() { int rc; - union { - SOCKADDR service; - SOCKADDR_IN service_ipv4; + union + { + SOCKADDR service; + SOCKADDR_IN service_ipv4; SOCKADDR_IN6 service_ipv6; }; @@ -74,8 +75,8 @@ void CJSServerWorker::WorkerProc() goto stop_cleanup; } - rc = ::bind(m_ServerSocket, (const SOCKADDR*)&service, - service.sa_family == AF_INET ? sizeof(service_ipv4) : sizeof(service_ipv6)); + rc = ::bind(m_ServerSocket, (const SOCKADDR *)&service, + service.sa_family == AF_INET ? sizeof(service_ipv4) : sizeof(service_ipv6)); if (rc == SOCKET_ERROR) { @@ -143,12 +144,12 @@ void CJSServerWorker::WorkerProc() } stop_cleanup: - { - CGuard guard(m_CS); - strncpy(m_Address.address, "", sizeof(m_Address.address)); - m_Address.port = 0; - m_Address.family = ""; - } +{ + CGuard guard(m_CS); + strncpy(m_Address.address, "", sizeof(m_Address.address)); + m_Address.port = 0; + m_Address.family = ""; +} if (m_ServerSocket != INVALID_SOCKET) { diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.h b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.h index feadc3b35..b67fc3ac5 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.h +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.h @@ -1,27 +1,34 @@ #pragma once +#include "ScriptAPI.h" +#include #include #include -#include -#include "ScriptAPI.h" class CJSServerWorker : public CScriptWorker { private: - enum { TIMEOUT_MS = 1 }; + enum + { + TIMEOUT_MS = 1 + }; - struct ServerQueue { + struct ServerQueue + { CriticalSection cs; std::string listenAddress; unsigned short listenPort; bool bClosePending; - ServerQueue() : listenAddress(""), listenPort(0), bClosePending(false) {} + ServerQueue() : + listenAddress(""), listenPort(0), bClosePending(false) + { + } } m_Queue; struct JSServerAddrInfo { char address[INET6_ADDRSTRLEN]; - const char* family; + const char * family; unsigned short port; JSServerAddrInfo() : @@ -37,24 +44,24 @@ private: JSServerAddrInfo m_Address; public: - CJSServerWorker(CScriptInstance* instance, void* dukObjectHeapPtr); + CJSServerWorker(CScriptInstance * instance, void * dukObjectHeapPtr); virtual ~CJSServerWorker(); - void Init(const char* address, unsigned short port); + void Init(const char * address, unsigned short port); void WorkerProc(); std::string GetAddress(); unsigned short GetPort(); - const char* GetFamily(); + const char * GetFamily(); private: void JSEmitConnection(SOCKET c); void JSEmitClose(); void JSEmitListening(); - void JSEmitError(const char* errMessage); + void JSEmitError(const char * errMessage); - static duk_idx_t CbArgs_EmitConnection(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitClose(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitListening(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitError(duk_context* ctx, void* _env); + static duk_idx_t CbArgs_EmitConnection(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitClose(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitListening(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitError(duk_context * ctx, void * _env); }; \ No newline at end of file diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.cpp index 18979ea74..63cea6df6 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.cpp @@ -69,9 +69,7 @@ bool CJSSocketWorker::Write(const char * data, size_t length, duk_int_t callback { CGuard guard(m_Queue.cs); - if (m_Queue.bFullClosePending || - m_Queue.bSendClosePending || - m_Queue.bSendClosed) + if (m_Queue.bFullClosePending || m_Queue.bSendClosePending || m_Queue.bSendClosed) { return false; } @@ -313,8 +311,7 @@ void CJSSocketWorker::ProcSendData() JSEmitError("send() error"); } - if (m_Queue.writes.size() == 0 && - m_Queue.bSendClosePending) + if (m_Queue.writes.size() == 0 && m_Queue.bSendClosePending) { shutdown(m_Socket, SD_SEND); m_Queue.bSendClosePending = false; diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.h b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.h index b32cb21ea..8136623ad 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.h +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/JSSocketWorker.h @@ -1,20 +1,23 @@ +#include "../ScriptWorker.h" +#include "ScriptAPI.h" +#include #include #include -#include -#include "ScriptAPI.h" -#include "../ScriptWorker.h" -#pragma comment (lib, "Ws2_32.lib") +#pragma comment(lib, "Ws2_32.lib") #pragma once class CJSSocketWorker : public CScriptWorker { private: - enum { TIMEOUT_MS = 1 }; + enum + { + TIMEOUT_MS = 1 + }; struct JSSocketAddrInfo { char address[INET6_ADDRSTRLEN]; - const char* family; + const char * family; unsigned short port; JSSocketAddrInfo() : @@ -32,8 +35,9 @@ private: duk_int_t callbackId; }; - struct JSEmitDataEnv { - char* data; + struct JSEmitDataEnv + { + char * data; size_t size; }; @@ -63,29 +67,29 @@ private: } }; - SOCKET m_Socket; - bool m_bWinsockOK; - bool m_bAllowHalfOpen; + SOCKET m_Socket; + bool m_bWinsockOK; + bool m_bAllowHalfOpen; JSSocketAddrInfo m_LocalAddress; JSSocketAddrInfo m_RemoteAddress; - JSSocketQueue m_Queue; - + JSSocketQueue m_Queue; + public: - CJSSocketWorker(CScriptInstance* inst, void* objectHeapPtr, bool bAllowHalfOpen); + CJSSocketWorker(CScriptInstance * inst, void * objectHeapPtr, bool bAllowHalfOpen); virtual ~CJSSocketWorker(); bool Init(SOCKET sock); - bool Init(const char* host, unsigned short port); + bool Init(const char * host, unsigned short port); void WorkerProc(); - bool Write(const char* data, size_t length, duk_int_t callbackId, bool bEnd = false); + bool Write(const char * data, size_t length, duk_int_t callbackId, bool bEnd = false); //bool GetAddress(JSSocketAddrInfo& address); std::string GetLocalAddress(); unsigned short GetLocalPort(); std::string GetRemoteAddress(); unsigned short GetRemotePort(); - const char* GetFamily(); + const char * GetFamily(); private: bool ProcConnect(); @@ -97,19 +101,19 @@ private: void ClearQueue(); void JSEmitConnect(); - void JSEmitData(const char* data, size_t size); + void JSEmitData(const char * data, size_t size); void JSEmitEnd(); void JSEmitClose(); void JSEmitDrain(); - void JSEmitLookup(JSSocketAddrInfo& addr); - void JSEmitError(const char* errMessage); + void JSEmitLookup(JSSocketAddrInfo & addr); + void JSEmitError(const char * errMessage); - static duk_idx_t CbArgs_EmitConnect(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitData(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitEnd(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitClose(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitDrain(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitLookup(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_EmitError(duk_context* ctx, void* _env); - static duk_idx_t CbArgs_Write(duk_context* ctx, void* _env); + static duk_idx_t CbArgs_EmitConnect(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitData(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitEnd(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitClose(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitDrain(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitLookup(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_EmitError(duk_context * ctx, void * _env); + static duk_idx_t CbArgs_Write(duk_context * ctx, void * _env); }; diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.cpp index 35001551d..9e24187e4 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.cpp @@ -510,7 +510,7 @@ const char * CN64Image::ResultCodeName(int resultCode) {N64IMG_PNG_HEADER_MISSING, "ERR_PNG_HEADER_MISSING"}, {N64IMG_PNG_OUT_OF_MEMORY, "ERR_PNG_OUT_OF_MEMORY"}, {N64IMG_PNG_EXCEPTION, "ERR_PNG_EXCEPTION"}, - { N64IMG_PNG_PARSER_FAILED, "ERR_PNG_PARSER_FAILED" } + {N64IMG_PNG_PARSER_FAILED, "ERR_PNG_PARSER_FAILED"}, }; if (names.count(resultCode) != 0) diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.h b/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.h index 4423831b9..b1df4c21e 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.h +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.h @@ -1,7 +1,8 @@ #pragma once #include "ScriptAPI.h" -enum { +enum +{ G_IM_FMT_RGBA, G_IM_FMT_YUV, G_IM_FMT_CI, @@ -9,20 +10,23 @@ enum { G_IM_FMT_I }; -enum { +enum +{ G_IM_SIZ_4b, G_IM_SIZ_8b, G_IM_SIZ_16b, G_IM_SIZ_32b }; -enum { +enum +{ G_TT_NONE = 0x0000, G_TT_RGBA16 = 0x8000, G_TT_IA16 = 0xC000, }; -enum { +enum +{ IMG_RGBA16 = (G_IM_FMT_RGBA << 3 | G_IM_SIZ_16b), IMG_RGBA32 = (G_IM_FMT_RGBA << 3 | G_IM_SIZ_32b), IMG_CI4_RGBA16 = (G_IM_FMT_CI << 3 | G_IM_SIZ_4b) | G_TT_RGBA16, @@ -36,7 +40,8 @@ enum { IMG_I8 = (G_IM_FMT_I << 3 | G_IM_SIZ_8b), }; -enum N64ImageResult { +enum N64ImageResult +{ N64IMG_OK, N64IMG_DATA_SIZE_INCORRECT, N64IMG_INVALID_COLOR_INDEX, @@ -67,40 +72,40 @@ public: CN64Image(); int Init(int format, size_t width, size_t height, - void* pixelData = nullptr, size_t pixelDataSize = 0, - void* paletteData = nullptr, size_t paletteDataSize = 0); + void * pixelData = nullptr, size_t pixelDataSize = 0, + void * paletteData = nullptr, size_t paletteDataSize = 0); - int Init(int format, uint8_t* pngData, size_t pngSize); - void ToPNG(std::vector& outPngImage); + int Init(int format, uint8_t * pngData, size_t pngSize); + void ToPNG(std::vector & outPngImage); int UpdateBitmap(); - std::vector& PaletteData(); - std::vector& PixelData(); - std::vector& Bitmap(); + std::vector & PaletteData(); + std::vector & PixelData(); + std::vector & Bitmap(); size_t Width(); size_t Height(); int Format(); bool UsesPalette(); - static int ReadPNG(uint8_t* pngData, size_t pngSize, size_t* width, size_t* height, std::vector& outRGBA32); - static void WritePNG(uint8_t* rgba32, size_t width, size_t height, std::vector& buffer); + static int ReadPNG(uint8_t * pngData, size_t pngSize, size_t * width, size_t * height, std::vector & outRGBA32); + static void WritePNG(uint8_t * rgba32, size_t width, size_t height, std::vector & buffer); static unsigned int ColorFromRgba32(int dstFormat, uint32_t rgba32); static uint32_t ColorToRgba32(int srcFormat, unsigned int color); static int BitsPerPixel(int format); static int PaletteColorCount(int format); static bool UsesPalette(int format); - static const char* ResultCodeName(int resultCode); + static const char * ResultCodeName(int resultCode); private: - uint16_t* PalettePtr(size_t index); - void* TexelPtr(size_t index); - uint32_t* BitmapPtr(size_t index); + uint16_t * PalettePtr(size_t index); + void * TexelPtr(size_t index); + uint32_t * BitmapPtr(size_t index); unsigned int GetTexel(size_t index); void SetTexel(size_t index, unsigned int value); - bool GetPaletteColor(size_t index, unsigned int* color); + bool GetPaletteColor(size_t index, unsigned int * color); bool SetPaletteColor(size_t index, unsigned int color); - bool GetBitmapColor(size_t index, uint32_t* color); + bool GetBitmapColor(size_t index, uint32_t * color); bool SetBitmapColor(size_t index, unsigned int color); int UpdatePixelsAndPaletteFromBitmap(); }; diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.cpp index 51270029d..79b70fb6f 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.cpp @@ -841,8 +841,7 @@ void ScriptAPI::DukPutPropList(duk_context * ctx, duk_idx_t obj_idx, const DukPr } else { - if (prop.typeId == Type_DukGetter || - prop.typeId == Type_DukGetterSetter) + if (prop.typeId == Type_DukGetter || prop.typeId == Type_DukGetterSetter) { // not compatible g_Notify->BreakPoint(__FILE__, __LINE__); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.h b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.h index 7711f45cd..8e5d7dd18 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.h +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI.h @@ -1,462 +1,552 @@ -#include "../ScriptTypes.h" -#include "../ScriptSystem.h" #include "../ScriptInstance.h" +#include "../ScriptSystem.h" +#include "../ScriptTypes.h" #pragma once #define PJ64_JSAPI_VERSION "jsapi-2" -#define HS_gAppCallbacks DUK_HIDDEN_SYMBOL("gAppCallbacks") -#define HS_gInstancePtr DUK_HIDDEN_SYMBOL("gInstancePtr") -#define HS_gInputListener DUK_HIDDEN_SYMBOL("gInputListener") -#define HS_gOpenFileDescriptors DUK_HIDDEN_SYMBOL("gOpenFileDescriptors") -#define HS_gKeepAlive DUK_HIDDEN_SYMBOL("gKeepAlive") -#define HS_gPrivateCallEnabled DUK_HIDDEN_SYMBOL("gPrivateCallEnabled") -#define HS_gNativeModules DUK_HIDDEN_SYMBOL("gNativeModules") -#define HS_gObjectRefs DUK_HIDDEN_SYMBOL("gObjectRefs") -#define HS_gNextObjectRefId DUK_HIDDEN_SYMBOL("gNextObjectRefId") -#define HS_gIntervals DUK_HIDDEN_SYMBOL("gIntervals") -#define HS_gNextInvervalId DUK_HIDDEN_SYMBOL("gNextIntervalId") +#define HS_gAppCallbacks DUK_HIDDEN_SYMBOL("gAppCallbacks") +#define HS_gInstancePtr DUK_HIDDEN_SYMBOL("gInstancePtr") +#define HS_gInputListener DUK_HIDDEN_SYMBOL("gInputListener") +#define HS_gOpenFileDescriptors DUK_HIDDEN_SYMBOL("gOpenFileDescriptors") +#define HS_gKeepAlive DUK_HIDDEN_SYMBOL("gKeepAlive") +#define HS_gPrivateCallEnabled DUK_HIDDEN_SYMBOL("gPrivateCallEnabled") +#define HS_gNativeModules DUK_HIDDEN_SYMBOL("gNativeModules") +#define HS_gObjectRefs DUK_HIDDEN_SYMBOL("gObjectRefs") +#define HS_gNextObjectRefId DUK_HIDDEN_SYMBOL("gNextObjectRefId") +#define HS_gIntervals DUK_HIDDEN_SYMBOL("gIntervals") +#define HS_gNextInvervalId DUK_HIDDEN_SYMBOL("gNextIntervalId") -#define HS_objectRefId DUK_HIDDEN_SYMBOL("objectRefId") -#define HS_emitterListeners DUK_HIDDEN_SYMBOL("emitterListeners") -#define HS_emitterNextListenerId DUK_HIDDEN_SYMBOL("emitterNextListenerId") -#define HS_socketWorkerPtr DUK_HIDDEN_SYMBOL("socketWorkerPtr") +#define HS_objectRefId DUK_HIDDEN_SYMBOL("objectRefId") +#define HS_emitterListeners DUK_HIDDEN_SYMBOL("emitterListeners") +#define HS_emitterNextListenerId DUK_HIDDEN_SYMBOL("emitterNextListenerId") +#define HS_socketWorkerPtr DUK_HIDDEN_SYMBOL("socketWorkerPtr") #define HS_socketNextWriteCallbackId DUK_HIDDEN_SYMBOL("nextWriteCallbackId") -#define HS_socketWriteCallbacks DUK_HIDDEN_SYMBOL("writeCallbacks") -#define HS_socketWriteEndCallbacks DUK_HIDDEN_SYMBOL("endCallbacks") -#define HS_serverWorkerPtr DUK_HIDDEN_SYMBOL("serverWorkerPtr") -#define HS_renderWindowPtr DUK_HIDDEN_SYMBOL("renderWindowPtr") -#define HS_n64ImagePtr DUK_HIDDEN_SYMBOL("n64ImagePtr") +#define HS_socketWriteCallbacks DUK_HIDDEN_SYMBOL("writeCallbacks") +#define HS_socketWriteEndCallbacks DUK_HIDDEN_SYMBOL("endCallbacks") +#define HS_serverWorkerPtr DUK_HIDDEN_SYMBOL("serverWorkerPtr") +#define HS_renderWindowPtr DUK_HIDDEN_SYMBOL("renderWindowPtr") +#define HS_n64ImagePtr DUK_HIDDEN_SYMBOL("n64ImagePtr") namespace ScriptAPI { - struct DukPropListEntry; +struct DukPropListEntry; - enum MemType { - U8, U16, U32, S8, S16, S32, F32, F64, - U64, S64 - }; +enum MemType +{ + U8, + U16, + U32, + S8, + S16, + S32, + F32, + F64, + U64, + S64 +}; - enum ArgType { - Arg_Any, - Arg_Number, - Arg_BufferData, - Arg_String, - Arg_Function, - Arg_Object, - Arg_Array, - Arg_Boolean, +enum ArgType +{ + Arg_Any, + Arg_Number, + Arg_BufferData, + Arg_String, + Arg_Function, + Arg_Object, + Arg_Array, + Arg_Boolean, - ArgAttr_Optional = (1 << 31), - Arg_OptAny = Arg_Any | ArgAttr_Optional, - Arg_OptNumber = Arg_Number | ArgAttr_Optional, - Arg_OptBufferData = Arg_BufferData | ArgAttr_Optional, - Arg_OptString = Arg_String | ArgAttr_Optional, - Arg_OptFunction = Arg_Function | ArgAttr_Optional, - Arg_OptObject = Arg_Object | ArgAttr_Optional, - Arg_OptArray = Arg_Array | ArgAttr_Optional, - Arg_OptBoolean = Arg_Boolean | ArgAttr_Optional, + ArgAttr_Optional = (1 << 31), + Arg_OptAny = Arg_Any | ArgAttr_Optional, + Arg_OptNumber = Arg_Number | ArgAttr_Optional, + Arg_OptBufferData = Arg_BufferData | ArgAttr_Optional, + Arg_OptString = Arg_String | ArgAttr_Optional, + Arg_OptFunction = Arg_Function | ArgAttr_Optional, + Arg_OptObject = Arg_Object | ArgAttr_Optional, + Arg_OptArray = Arg_Array | ArgAttr_Optional, + Arg_OptBoolean = Arg_Boolean | ArgAttr_Optional, - ArgAttrs = ArgAttr_Optional - }; + ArgAttrs = ArgAttr_Optional +}; - // ScriptAPI - void InitEnvironment(duk_context* ctx, CScriptInstance* inst); - void DefineGlobalConstants(duk_context* ctx); +// ScriptAPI +void InitEnvironment(duk_context * ctx, CScriptInstance * inst); +void DefineGlobalConstants(duk_context * ctx); - void DefineGlobalClass(duk_context* ctx, const char* className, - duk_c_function constructorFunc, - const DukPropListEntry* prototypeProps = nullptr, - const DukPropListEntry* staticProps = nullptr); +void DefineGlobalClass(duk_context * ctx, const char * className, + duk_c_function constructorFunc, + const DukPropListEntry * prototypeProps = nullptr, + const DukPropListEntry * staticProps = nullptr); - void DefineGlobalInterface(duk_context* ctx, const char* name, const DukPropListEntry* props); - - void DefineGlobalFunction(duk_context* ctx, const char* name, duk_c_function func); +void DefineGlobalInterface(duk_context * ctx, const char * name, const DukPropListEntry * props); - CScriptInstance* GetInstance(duk_context* ctx); +void DefineGlobalFunction(duk_context * ctx, const char * name, duk_c_function func); - JSAppCallbackID AddAppCallback(duk_context* ctx, duk_idx_t callbackFuncIdx, - JSAppHookID hookId, - JSDukArgSetupFunc argSetupFunc = nullptr, - JSAppCallbackCondFunc conditionFunc = nullptr, - JSAppCallbackCleanupFunc cleanupFunc = nullptr); +CScriptInstance * GetInstance(duk_context * ctx); - JSAppCallbackID AddAppCallback(duk_context* ctx, JSAppHookID hookId, JSAppCallback& callback); +JSAppCallbackID AddAppCallback(duk_context * ctx, duk_idx_t callbackFuncIdx, + JSAppHookID hookId, + JSDukArgSetupFunc argSetupFunc = nullptr, + JSAppCallbackCondFunc conditionFunc = nullptr, + JSAppCallbackCleanupFunc cleanupFunc = nullptr); - bool RemoveAppCallback(duk_context* ctx, JSAppCallbackID callbackId); - duk_ret_t js__AppCallbackFinalizer(duk_context* ctx); +JSAppCallbackID AddAppCallback(duk_context * ctx, JSAppHookID hookId, JSAppCallback & callback); - void RefObject(duk_context* ctx, duk_idx_t idx); - void UnrefObject(duk_context* ctx, duk_idx_t idx); - duk_ret_t js__UnrefObject(duk_context* ctx); +bool RemoveAppCallback(duk_context * ctx, JSAppCallbackID callbackId); +duk_ret_t js__AppCallbackFinalizer(duk_context * ctx); - void InitEmitter(duk_context* ctx, duk_idx_t obj_idx, const std::vector& eventNames); - duk_ret_t js__Emitter_emit(duk_context* ctx); - duk_ret_t js__Emitter_on(duk_context* ctx); - duk_ret_t js__Emitter_off(duk_context* ctx); +void RefObject(duk_context * ctx, duk_idx_t idx); +void UnrefObject(duk_context * ctx, duk_idx_t idx); +duk_ret_t js__UnrefObject(duk_context * ctx); - duk_ret_t js_Duktape_modSearch(duk_context* ctx); // require() - void RegisterNativeModule(duk_context* ctx, HMODULE hModule); - duk_ret_t js__NativeModuleFinalizer(duk_context* ctx); +void InitEmitter(duk_context * ctx, duk_idx_t obj_idx, const std::vector & eventNames); +duk_ret_t js__Emitter_emit(duk_context * ctx); +duk_ret_t js__Emitter_on(duk_context * ctx); +duk_ret_t js__Emitter_off(duk_context * ctx); - void AllowPrivateCall(duk_context* ctx, bool bAllow); - bool PrivateCallAllowed(duk_context* ctx); +duk_ret_t js_Duktape_modSearch(duk_context * ctx); // require() +void RegisterNativeModule(duk_context * ctx, HMODULE hModule); +duk_ret_t js__NativeModuleFinalizer(duk_context * ctx); - void PushNewDummyConstructor(duk_context* ctx, bool bFrozen = true); - void DefineGlobalDummyConstructors(duk_context* ctx, const char* constructorNames[], bool bFreeze = true); - void SetDummyConstructor(duk_context* ctx, duk_idx_t obj_idx, const char* globalConstructorName); - duk_ret_t js_DummyConstructor(duk_context* ctx); +void AllowPrivateCall(duk_context * ctx, bool bAllow); +bool PrivateCallAllowed(duk_context * ctx); - const char* ArgTypeName(ArgType argType); - duk_bool_t ArgTypeMatches(duk_context* ctx, duk_idx_t idx, ArgType wantType); - duk_ret_t CheckArgs(duk_context* ctx, const std::vector& argTypes); - duk_ret_t CheckSetterAssignment(duk_context* ctx, ArgType wantType); +void PushNewDummyConstructor(duk_context * ctx, bool bFrozen = true); +void DefineGlobalDummyConstructors(duk_context * ctx, const char * constructorNames[], bool bFreeze = true); +void SetDummyConstructor(duk_context * ctx, duk_idx_t obj_idx, const char * globalConstructorName); +duk_ret_t js_DummyConstructor(duk_context * ctx); - duk_ret_t ThrowInvalidArgsError(duk_context* ctx); - duk_ret_t ThrowInvalidArgError(duk_context* ctx, duk_idx_t idx, ArgType wantType); - duk_ret_t ThrowTooManyArgsError(duk_context* ctx); - duk_ret_t ThrowInvalidAssignmentError(duk_context* ctx, ArgType wantType); - duk_ret_t ThrowNotCallableError(duk_context* ctx); +const char * ArgTypeName(ArgType argType); +duk_bool_t ArgTypeMatches(duk_context * ctx, duk_idx_t idx, ArgType wantType); +duk_ret_t CheckArgs(duk_context * ctx, const std::vector & argTypes); +duk_ret_t CheckSetterAssignment(duk_context * ctx, ArgType wantType); - void DebugStack(duk_context* ctx, const char* file, int line); +duk_ret_t ThrowInvalidArgsError(duk_context * ctx); +duk_ret_t ThrowInvalidArgError(duk_context * ctx, duk_idx_t idx, ArgType wantType); +duk_ret_t ThrowTooManyArgsError(duk_context * ctx); +duk_ret_t ThrowInvalidAssignmentError(duk_context * ctx, ArgType wantType); +duk_ret_t ThrowNotCallableError(duk_context * ctx); - // ScriptAPI_events - void Define_events(duk_context* ctx); - duk_ret_t js_events_onstatechange(duk_context* ctx); - duk_ret_t js_events_onexec(duk_context* ctx); - duk_ret_t js_events_onread(duk_context* ctx); - duk_ret_t js_events_onwrite(duk_context* ctx); - duk_ret_t js_events_onopcode(duk_context* ctx); - duk_ret_t js_events_ongprvalue(duk_context* ctx); - duk_ret_t js_events_onpifread(duk_context* ctx); - duk_ret_t js_events_onsptask(duk_context* ctx); - duk_ret_t js_events_onpidma(duk_context* ctx); - duk_ret_t js_events_onmouseup(duk_context* ctx); - duk_ret_t js_events_onmousedown(duk_context* ctx); - duk_ret_t js_events_onmousemove(duk_context* ctx); - duk_ret_t js_events_remove(duk_context* ctx); +void DebugStack(duk_context * ctx, const char * file, int line); - // ScriptAPI_console - void Define_console(duk_context* ctx); - duk_ret_t js_console_print(duk_context* ctx); - duk_ret_t js_console_log(duk_context* ctx); - duk_ret_t js_console_error(duk_context* ctx); - duk_ret_t js_console_clear(duk_context* ctx); - duk_ret_t js_console_listen(duk_context* ctx); +// ScriptAPI_events +void Define_events(duk_context * ctx); +duk_ret_t js_events_onstatechange(duk_context * ctx); +duk_ret_t js_events_onexec(duk_context * ctx); +duk_ret_t js_events_onread(duk_context * ctx); +duk_ret_t js_events_onwrite(duk_context * ctx); +duk_ret_t js_events_onopcode(duk_context * ctx); +duk_ret_t js_events_ongprvalue(duk_context * ctx); +duk_ret_t js_events_onpifread(duk_context * ctx); +duk_ret_t js_events_onsptask(duk_context * ctx); +duk_ret_t js_events_onpidma(duk_context * ctx); +duk_ret_t js_events_onmouseup(duk_context * ctx); +duk_ret_t js_events_onmousedown(duk_context * ctx); +duk_ret_t js_events_onmousemove(duk_context * ctx); +duk_ret_t js_events_remove(duk_context * ctx); - // ScriptAPI_mem - void Define_mem(duk_context* ctx); - template duk_ret_t js_mem__get(duk_context* ctx); - template duk_ret_t js_mem__set(duk_context* ctx); - duk_ret_t js_mem__boundget(duk_context* ctx); - duk_ret_t js_mem__boundset(duk_context* ctx); - duk_ret_t js_mem__type_constructor(duk_context* ctx); - duk_ret_t js_mem__get_ramsize(duk_context* ctx); - duk_ret_t js_mem__get_romsize(duk_context* ctx); - duk_ret_t js_mem__get_ptr(duk_context* ctx); - duk_ret_t js_mem_getblock(duk_context* ctx); - duk_ret_t js_mem_getstring(duk_context* ctx); - duk_ret_t js_mem_setblock(duk_context* ctx); - duk_ret_t js_mem_bindvar(duk_context* ctx); - duk_ret_t js_mem_bindvars(duk_context* ctx); - duk_ret_t js_mem_bindstruct(duk_context* ctx); - duk_ret_t js_mem_typedef(duk_context* ctx); +// ScriptAPI_console +void Define_console(duk_context * ctx); +duk_ret_t js_console_print(duk_context * ctx); +duk_ret_t js_console_log(duk_context * ctx); +duk_ret_t js_console_error(duk_context * ctx); +duk_ret_t js_console_clear(duk_context * ctx); +duk_ret_t js_console_listen(duk_context * ctx); - // ScriptAPI_Server - void Define_Server(duk_context* ctx); - duk_ret_t js_Server__constructor(duk_context* ctx); - duk_ret_t js_Server__finalizer(duk_context* ctx); - duk_ret_t js_Server__get_port(duk_context* ctx); - duk_ret_t js_Server__get_address(duk_context* ctx); - duk_ret_t js_Server__get_addressFamily(duk_context* ctx); - duk_ret_t js_Server_listen(duk_context* ctx); - duk_ret_t js_Server_close(duk_context* ctx); +// ScriptAPI_mem +void Define_mem(duk_context * ctx); +template +duk_ret_t js_mem__get(duk_context * ctx); +template +duk_ret_t js_mem__set(duk_context * ctx); +duk_ret_t js_mem__boundget(duk_context * ctx); +duk_ret_t js_mem__boundset(duk_context * ctx); +duk_ret_t js_mem__type_constructor(duk_context * ctx); +duk_ret_t js_mem__get_ramsize(duk_context * ctx); +duk_ret_t js_mem__get_romsize(duk_context * ctx); +duk_ret_t js_mem__get_ptr(duk_context * ctx); +duk_ret_t js_mem_getblock(duk_context * ctx); +duk_ret_t js_mem_getstring(duk_context * ctx); +duk_ret_t js_mem_setblock(duk_context * ctx); +duk_ret_t js_mem_bindvar(duk_context * ctx); +duk_ret_t js_mem_bindvars(duk_context * ctx); +duk_ret_t js_mem_bindstruct(duk_context * ctx); +duk_ret_t js_mem_typedef(duk_context * ctx); - // ScriptAPI_Socket - void Define_Socket(duk_context* ctx); - duk_ret_t js_Socket__constructor(duk_context* ctx); - duk_ret_t js_Socket__finalizer(duk_context* ctx); - duk_ret_t js_Socket__invokeWriteCallback(duk_context* ctx); - duk_ret_t js_Socket__invokeWriteEndCallbacks(duk_context* ctx); - duk_ret_t js_Socket_connect(duk_context* ctx); - duk_ret_t js_Socket_write(duk_context* ctx); - duk_ret_t js_Socket_end(duk_context* ctx); - duk_ret_t js_Socket_close(duk_context* ctx); - duk_ret_t js_Socket__get_localAddress(duk_context* ctx); - duk_ret_t js_Socket__get_localPort(duk_context* ctx); - duk_ret_t js_Socket__get_remoteAddress(duk_context* ctx); - duk_ret_t js_Socket__get_remotePort(duk_context* ctx); - duk_ret_t js_Socket__get_addressFamily(duk_context* ctx); - - // ScriptAPI_script - void Define_script(duk_context* ctx); - duk_ret_t js_script_keepalive(duk_context* ctx); - duk_ret_t js_script_timeout(duk_context* ctx); - duk_ret_t js_script_abort(duk_context* ctx); +// ScriptAPI_Server +void Define_Server(duk_context * ctx); +duk_ret_t js_Server__constructor(duk_context * ctx); +duk_ret_t js_Server__finalizer(duk_context * ctx); +duk_ret_t js_Server__get_port(duk_context * ctx); +duk_ret_t js_Server__get_address(duk_context * ctx); +duk_ret_t js_Server__get_addressFamily(duk_context * ctx); +duk_ret_t js_Server_listen(duk_context * ctx); +duk_ret_t js_Server_close(duk_context * ctx); - // ScriptAPI_fs - void Define_fs(duk_context* ctx); - duk_ret_t js_fs_open(duk_context* ctx); - duk_ret_t js_fs_close(duk_context* ctx); - duk_ret_t js_fs_write(duk_context* ctx); - duk_ret_t js_fs_writefile(duk_context* ctx); - duk_ret_t js_fs_read(duk_context* ctx); - duk_ret_t js_fs_readfile(duk_context* ctx); - duk_ret_t js_fs_exists(duk_context* ctx); - duk_ret_t js_fs_fstat(duk_context* ctx); - duk_ret_t js_fs_stat(duk_context* ctx); - duk_ret_t js_fs_unlink(duk_context* ctx); - duk_ret_t js_fs_mkdir(duk_context* ctx); - duk_ret_t js_fs_rmdir(duk_context* ctx); - duk_ret_t js_fs_readdir(duk_context* ctx); - duk_ret_t js_fs_Stats__constructor(duk_context* ctx); - duk_ret_t js_fs_Stats_isDirectory(duk_context* ctx); - duk_ret_t js_fs_Stats_isFile(duk_context* ctx); +// ScriptAPI_Socket +void Define_Socket(duk_context * ctx); +duk_ret_t js_Socket__constructor(duk_context * ctx); +duk_ret_t js_Socket__finalizer(duk_context * ctx); +duk_ret_t js_Socket__invokeWriteCallback(duk_context * ctx); +duk_ret_t js_Socket__invokeWriteEndCallbacks(duk_context * ctx); +duk_ret_t js_Socket_connect(duk_context * ctx); +duk_ret_t js_Socket_write(duk_context * ctx); +duk_ret_t js_Socket_end(duk_context * ctx); +duk_ret_t js_Socket_close(duk_context * ctx); +duk_ret_t js_Socket__get_localAddress(duk_context * ctx); +duk_ret_t js_Socket__get_localPort(duk_context * ctx); +duk_ret_t js_Socket__get_remoteAddress(duk_context * ctx); +duk_ret_t js_Socket__get_remotePort(duk_context * ctx); +duk_ret_t js_Socket__get_addressFamily(duk_context * ctx); - // ScriptAPI_debug - void Define_debug(duk_context* ctx); - duk_ret_t js_debug__get_paused(duk_context* ctx); - duk_ret_t js_debug_breakhere(duk_context* ctx); - duk_ret_t js_debug_step(duk_context* ctx); - duk_ret_t js_debug_skip(duk_context* ctx); - duk_ret_t js_debug_resume(duk_context* ctx); - duk_ret_t js_debug_showmemory(duk_context* ctx); - duk_ret_t js_debug_showcommands(duk_context* ctx); +// ScriptAPI_script +void Define_script(duk_context * ctx); +duk_ret_t js_script_keepalive(duk_context * ctx); +duk_ret_t js_script_timeout(duk_context * ctx); +duk_ret_t js_script_abort(duk_context * ctx); - // ScriptAPI_asm - void Define_asm(duk_context* ctx); - duk_ret_t js_asm_gprname(duk_context* ctx); - duk_ret_t js_asm_encode(duk_context* ctx); - duk_ret_t js_asm_decode(duk_context* ctx); +// ScriptAPI_fs +void Define_fs(duk_context * ctx); +duk_ret_t js_fs_open(duk_context * ctx); +duk_ret_t js_fs_close(duk_context * ctx); +duk_ret_t js_fs_write(duk_context * ctx); +duk_ret_t js_fs_writefile(duk_context * ctx); +duk_ret_t js_fs_read(duk_context * ctx); +duk_ret_t js_fs_readfile(duk_context * ctx); +duk_ret_t js_fs_exists(duk_context * ctx); +duk_ret_t js_fs_fstat(duk_context * ctx); +duk_ret_t js_fs_stat(duk_context * ctx); +duk_ret_t js_fs_unlink(duk_context * ctx); +duk_ret_t js_fs_mkdir(duk_context * ctx); +duk_ret_t js_fs_rmdir(duk_context * ctx); +duk_ret_t js_fs_readdir(duk_context * ctx); +duk_ret_t js_fs_Stats__constructor(duk_context * ctx); +duk_ret_t js_fs_Stats_isDirectory(duk_context * ctx); +duk_ret_t js_fs_Stats_isFile(duk_context * ctx); - // ScriptAPI_cpu - void Define_cpu(duk_context* ctx); - duk_ret_t js_cpu_get(duk_context* ctx); - duk_ret_t js_cpu_set(duk_context* ctx); - duk_ret_t js_cpu_gpr_get(duk_context* ctx); - duk_ret_t js_cpu_gpr_set(duk_context* ctx); - duk_ret_t js_cpu_ugpr_get(duk_context* ctx); - duk_ret_t js_cpu_ugpr_set(duk_context* ctx); - duk_ret_t js_cpu_fpr_get(duk_context* ctx); - duk_ret_t js_cpu_fpr_set(duk_context* ctx); - duk_ret_t js_cpu_dfpr_get(duk_context* ctx); - duk_ret_t js_cpu_dfpr_set(duk_context* ctx); - duk_ret_t js_cpu_cop0_get(duk_context* ctx); - duk_ret_t js_cpu_cop0_set(duk_context* ctx); +// ScriptAPI_debug +void Define_debug(duk_context * ctx); +duk_ret_t js_debug__get_paused(duk_context * ctx); +duk_ret_t js_debug_breakhere(duk_context * ctx); +duk_ret_t js_debug_step(duk_context * ctx); +duk_ret_t js_debug_skip(duk_context * ctx); +duk_ret_t js_debug_resume(duk_context * ctx); +duk_ret_t js_debug_showmemory(duk_context * ctx); +duk_ret_t js_debug_showcommands(duk_context * ctx); - // ScriptAPI_pj64 - void Define_pj64(duk_context* ctx); - duk_ret_t js_pj64_open(duk_context* ctx); - duk_ret_t js_pj64_close(duk_context* ctx); - duk_ret_t js_pj64_reset(duk_context* ctx); - duk_ret_t js_pj64_pause(duk_context* ctx); - duk_ret_t js_pj64_resume(duk_context* ctx); - duk_ret_t js_pj64_limitfps(duk_context* ctx); - duk_ret_t js_pj64__get_installDirectory(duk_context* ctx); - duk_ret_t js_pj64__get_scriptsDirectory(duk_context* ctx); - duk_ret_t js_pj64__get_modulesDirectory(duk_context* ctx); - duk_ret_t js_pj64__get_romDirectory(duk_context* ctx); - duk_ret_t js_pj64__get_romInfo(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_goodName(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_fileName(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_filePath(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerCrc1(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerCrc2(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerName(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerMediaFormat(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerId(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerCountryCode(duk_context* ctx); - duk_ret_t js_pj64_romInfo__get_headerVersion(duk_context* ctx); +// ScriptAPI_asm +void Define_asm(duk_context * ctx); +duk_ret_t js_asm_gprname(duk_context * ctx); +duk_ret_t js_asm_encode(duk_context * ctx); +duk_ret_t js_asm_decode(duk_context * ctx); - // ScriptAPI_AddressRange - void Define_AddressRange(duk_context* ctx); - duk_ret_t js_AddressRange__constructor(duk_context* ctx); - duk_ret_t js_AddressRange_size(duk_context* ctx); - duk_ret_t js_AddressRange_includes(duk_context* ctx); - duk_ret_t js_AddressRange_offset(duk_context* ctx); - duk_ret_t js_AddressRange_address(duk_context* ctx); +// ScriptAPI_cpu +void Define_cpu(duk_context * ctx); +duk_ret_t js_cpu_get(duk_context * ctx); +duk_ret_t js_cpu_set(duk_context * ctx); +duk_ret_t js_cpu_gpr_get(duk_context * ctx); +duk_ret_t js_cpu_gpr_set(duk_context * ctx); +duk_ret_t js_cpu_ugpr_get(duk_context * ctx); +duk_ret_t js_cpu_ugpr_set(duk_context * ctx); +duk_ret_t js_cpu_fpr_get(duk_context * ctx); +duk_ret_t js_cpu_fpr_set(duk_context * ctx); +duk_ret_t js_cpu_dfpr_get(duk_context * ctx); +duk_ret_t js_cpu_dfpr_set(duk_context * ctx); +duk_ret_t js_cpu_cop0_get(duk_context * ctx); +duk_ret_t js_cpu_cop0_set(duk_context * ctx); - // ScriptAPI_Number_hex - void Define_Number_prototype_hex(duk_context* ctx); - duk_ret_t js_Number_prototype_hex(duk_context* ctx); +// ScriptAPI_pj64 +void Define_pj64(duk_context * ctx); +duk_ret_t js_pj64_open(duk_context * ctx); +duk_ret_t js_pj64_close(duk_context * ctx); +duk_ret_t js_pj64_reset(duk_context * ctx); +duk_ret_t js_pj64_pause(duk_context * ctx); +duk_ret_t js_pj64_resume(duk_context * ctx); +duk_ret_t js_pj64_limitfps(duk_context * ctx); +duk_ret_t js_pj64__get_installDirectory(duk_context * ctx); +duk_ret_t js_pj64__get_scriptsDirectory(duk_context * ctx); +duk_ret_t js_pj64__get_modulesDirectory(duk_context * ctx); +duk_ret_t js_pj64__get_romDirectory(duk_context * ctx); +duk_ret_t js_pj64__get_romInfo(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_goodName(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_fileName(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_filePath(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerCrc1(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerCrc2(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerName(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerMediaFormat(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerId(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerCountryCode(duk_context * ctx); +duk_ret_t js_pj64_romInfo__get_headerVersion(duk_context * ctx); - // ScriptAPI_N64Image - void Define_N64Image(duk_context* ctx); - duk_ret_t js_N64Image__constructor(duk_context* ctx); - duk_ret_t js_N64Image__finalizer(duk_context* ctx); - duk_ret_t js_N64Image_static_fromPNG(duk_context* ctx); - duk_ret_t js_N64Image_static_format(duk_context* ctx); - duk_ret_t js_N64Image_static_bpp(duk_context* ctx); - duk_ret_t js_N64Image_toPNG(duk_context* ctx); - duk_ret_t js_N64Image_update(duk_context* ctx); +// ScriptAPI_AddressRange +void Define_AddressRange(duk_context * ctx); +duk_ret_t js_AddressRange__constructor(duk_context * ctx); +duk_ret_t js_AddressRange_size(duk_context * ctx); +duk_ret_t js_AddressRange_includes(duk_context * ctx); +duk_ret_t js_AddressRange_offset(duk_context * ctx); +duk_ret_t js_AddressRange_address(duk_context * ctx); - // ScriptAPI_exec - void Define_exec(duk_context* ctx); - duk_ret_t js_exec(duk_context* ctx); +// ScriptAPI_Number_hex +void Define_Number_prototype_hex(duk_context * ctx); +duk_ret_t js_Number_prototype_hex(duk_context * ctx); - // ScriptAPI_alert - void Define_alert(duk_context* ctx); - duk_ret_t js_alert(duk_context* ctx); +// ScriptAPI_N64Image +void Define_N64Image(duk_context * ctx); +duk_ret_t js_N64Image__constructor(duk_context * ctx); +duk_ret_t js_N64Image__finalizer(duk_context * ctx); +duk_ret_t js_N64Image_static_fromPNG(duk_context * ctx); +duk_ret_t js_N64Image_static_format(duk_context * ctx); +duk_ret_t js_N64Image_static_bpp(duk_context * ctx); +duk_ret_t js_N64Image_toPNG(duk_context * ctx); +duk_ret_t js_N64Image_update(duk_context * ctx); - // ScriptAPI_interval - void Define_interval(duk_context* ctx); - duk_ret_t js_setInterval(duk_context* ctx); - duk_ret_t js_clearInterval(duk_context* ctx); - duk_ret_t js_setTimeout(duk_context* ctx); - duk_ret_t js_clearTimeout(duk_context* ctx); - duk_ret_t js__IntervalContext_invokeFunc(duk_context* ctx); - duk_ret_t js__IntervalContext_remove(duk_context* ctx); - duk_ret_t js__IntervalContext_finalizer(duk_context* ctx); +// ScriptAPI_exec +void Define_exec(duk_context * ctx); +duk_ret_t js_exec(duk_context * ctx); - enum { - R0, AT, V0, V1, A0, A1, A2, A3, - T0, T1, T2, T3, T4, T5, T6, T7, - S0, S1, S2, S3, S4, S5, S6, S7, - T8, T9, K0, K1, GP, SP, FP, RA, - //S8 = FP - }; +// ScriptAPI_alert +void Define_alert(duk_context * ctx); +duk_ret_t js_alert(duk_context * ctx); - enum { - GPR_R0 = (1 << R0), - GPR_AT = (1 << AT), - GPR_V0 = (1 << V0), - GPR_V1 = (1 << V1), - GPR_A0 = (1 << A0), - GPR_A1 = (1 << A1), - GPR_A2 = (1 << A2), - GPR_A3 = (1 << A3), - GPR_T0 = (1 << T0), - GPR_T1 = (1 << T1), - GPR_T2 = (1 << T2), - GPR_T3 = (1 << T3), - GPR_T4 = (1 << T4), - GPR_T5 = (1 << T5), - GPR_T6 = (1 << T6), - GPR_T7 = (1 << T7), - GPR_S0 = (1 << S0), - GPR_S1 = (1 << S1), - GPR_S2 = (1 << S2), - GPR_S3 = (1 << S3), - GPR_S4 = (1 << S4), - GPR_S5 = (1 << S5), - GPR_S6 = (1 << S6), - GPR_S7 = (1 << S7), - GPR_T8 = (1 << T8), - GPR_T9 = (1 << T9), - GPR_K0 = (1 << K0), - GPR_K1 = (1 << K1), - GPR_GP = (1 << GP), - GPR_SP = (1 << SP), - GPR_FP = (1 << FP), - GPR_RA = (1 << RA), - //GPR_S8 = GPR_FP, - GPR_ANY = 0xFFFFFFFF - }; +// ScriptAPI_interval +void Define_interval(duk_context * ctx); +duk_ret_t js_setInterval(duk_context * ctx); +duk_ret_t js_clearInterval(duk_context * ctx); +duk_ret_t js_setTimeout(duk_context * ctx); +duk_ret_t js_clearTimeout(duk_context * ctx); +duk_ret_t js__IntervalContext_invokeFunc(duk_context * ctx); +duk_ret_t js__IntervalContext_remove(duk_context * ctx); +duk_ret_t js__IntervalContext_finalizer(duk_context * ctx); + +enum +{ + R0, + AT, + V0, + V1, + A0, + A1, + A2, + A3, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + S0, + S1, + S2, + S3, + S4, + S5, + S6, + S7, + T8, + T9, + K0, + K1, + GP, + SP, + FP, + RA, + //S8 = FP +}; + +enum +{ + GPR_R0 = (1 << R0), + GPR_AT = (1 << AT), + GPR_V0 = (1 << V0), + GPR_V1 = (1 << V1), + GPR_A0 = (1 << A0), + GPR_A1 = (1 << A1), + GPR_A2 = (1 << A2), + GPR_A3 = (1 << A3), + GPR_T0 = (1 << T0), + GPR_T1 = (1 << T1), + GPR_T2 = (1 << T2), + GPR_T3 = (1 << T3), + GPR_T4 = (1 << T4), + GPR_T5 = (1 << T5), + GPR_T6 = (1 << T6), + GPR_T7 = (1 << T7), + GPR_S0 = (1 << S0), + GPR_S1 = (1 << S1), + GPR_S2 = (1 << S2), + GPR_S3 = (1 << S3), + GPR_S4 = (1 << S4), + GPR_S5 = (1 << S5), + GPR_S6 = (1 << S6), + GPR_S7 = (1 << S7), + GPR_T8 = (1 << T8), + GPR_T9 = (1 << T9), + GPR_K0 = (1 << K0), + GPR_K1 = (1 << K1), + GPR_GP = (1 << GP), + GPR_SP = (1 << SP), + GPR_FP = (1 << FP), + GPR_RA = (1 << RA), + //GPR_S8 = GPR_FP, + GPR_ANY = 0xFFFFFFFF +}; #define DUK_TYPE_ID(id) \ -static const DukPropTypeID _TYPE = DukPropTypeID::Type_ ## id; + static const DukPropTypeID _TYPE = DukPropTypeID::Type_##id; #define DUK_DECLVAL_MEMBER(structName, memberName) \ -structName memberName; Value(structName v) : memberName(v) {} + structName memberName; \ + Value(structName v) : memberName(v) \ + { \ + } #define DUK_SCALARTYPE_IMPL(structName, primitiveType) \ -DUK_TYPE_ID(structName) primitiveType value; structName(primitiveType value) : value(value){} + DUK_TYPE_ID(structName) \ + primitiveType value; \ + structName(primitiveType value) : value(value) \ + { \ + } - enum DukPropTypeID - { - Type_DukInt, - Type_DukUInt, - Type_DukNumber, - Type_DukString, - Type_DukBoolean, - Type_DukPointer, - Type_DukCFunction, - Type_DukDupIndex, - Type_DukGetter, - Type_DukGetterSetter, - Type_DukObject, - Type_DukProxy - }; - - struct DukInt { DUK_SCALARTYPE_IMPL(DukInt, duk_int_t) }; - struct DukUInt { DUK_SCALARTYPE_IMPL(DukUInt, duk_uint_t) }; - struct DukNumber { DUK_SCALARTYPE_IMPL(DukNumber, duk_double_t) }; - struct DukBoolean { DUK_SCALARTYPE_IMPL(DukBoolean, duk_bool_t) }; - struct DukString { DUK_SCALARTYPE_IMPL(DukString, const char*) }; - struct DukPointer { DUK_SCALARTYPE_IMPL(DukPointer, void*) }; - struct DukDupIndex { DUK_SCALARTYPE_IMPL(DukDupIndex, duk_idx_t) }; - //struct DukObject { DUK_SCALARTYPE_IMPL(DukObject, duk_idx_t) }; - - struct DukCFunction { - DUK_TYPE_ID(DukCFunction) - duk_c_function func; - duk_int_t nargs; - DukCFunction(duk_c_function func, duk_int_t nargs = DUK_VARARGS) : - func(func), nargs(nargs) {} - }; - - struct DukObject { - DUK_TYPE_ID(DukObject) - const DukPropListEntry* props; - DukObject(const DukPropListEntry* props = nullptr) : - props(props) {} - }; - - struct DukGetter { - DUK_SCALARTYPE_IMPL(DukGetter, duk_c_function) - }; - - struct DukGetterSetter { - DUK_TYPE_ID(DukGetterSetter) - duk_c_function getter, setter; - DukGetterSetter(duk_c_function getter, duk_c_function setter) : - getter(getter), setter(setter) {} - }; - - struct DukProxy { - DUK_TYPE_ID(DukProxy) - duk_c_function getter, setter; - DukProxy(duk_c_function getter, duk_c_function setter) : - getter(getter), setter(setter) {} - }; - - struct DukPropListEntry - { - const char* key; - DukPropTypeID typeId; - bool writable, enumerable; - - union Value { - DUK_DECLVAL_MEMBER(DukInt, dukInt) - DUK_DECLVAL_MEMBER(DukUInt, dukUInt) - DUK_DECLVAL_MEMBER(DukNumber, dukNumber) - DUK_DECLVAL_MEMBER(DukBoolean, dukBoolean) - DUK_DECLVAL_MEMBER(DukString, dukString) - DUK_DECLVAL_MEMBER(DukPointer, dukPointer) - DUK_DECLVAL_MEMBER(DukCFunction, dukCFunction) - DUK_DECLVAL_MEMBER(DukGetter, dukGetter) - DUK_DECLVAL_MEMBER(DukGetterSetter, dukGetterSetter) - DUK_DECLVAL_MEMBER(DukDupIndex, dukDupIndex) - DUK_DECLVAL_MEMBER(DukObject, dukObject) - DUK_DECLVAL_MEMBER(DukProxy, dukProxy) - } value; - - template - DukPropListEntry(const char* key, T value, bool writable = false, bool enumerable = true) : - key(key), typeId(T::_TYPE), writable(writable), enumerable(enumerable), value(value) {} - - DukPropListEntry(nullptr_t) : - key(nullptr), value(DukInt(0)) {} - - DukPropListEntry(const char* key) : - key(key), typeId(Type_DukInt), writable(false), enumerable(false), value(DukInt(0)) {} - }; - - // todo proxy object - // todo DukObjectConfig_DummyConstructor - // todo DukObjectConfig_Finalizer - // todo DukObjectConfig_Freeze - - void DukPutPropList(duk_context* ctx, duk_idx_t obj_idx, const DukPropListEntry* props); +enum DukPropTypeID +{ + Type_DukInt, + Type_DukUInt, + Type_DukNumber, + Type_DukString, + Type_DukBoolean, + Type_DukPointer, + Type_DukCFunction, + Type_DukDupIndex, + Type_DukGetter, + Type_DukGetterSetter, + Type_DukObject, + Type_DukProxy }; + +struct DukInt +{ + DUK_SCALARTYPE_IMPL(DukInt, duk_int_t) +}; +struct DukUInt +{ + DUK_SCALARTYPE_IMPL(DukUInt, duk_uint_t) +}; +struct DukNumber +{ + DUK_SCALARTYPE_IMPL(DukNumber, duk_double_t) +}; +struct DukBoolean +{ + DUK_SCALARTYPE_IMPL(DukBoolean, duk_bool_t) +}; +struct DukString +{ + DUK_SCALARTYPE_IMPL(DukString, const char *) +}; +struct DukPointer +{ + DUK_SCALARTYPE_IMPL(DukPointer, void *) +}; +struct DukDupIndex +{ + DUK_SCALARTYPE_IMPL(DukDupIndex, duk_idx_t) +}; +//struct DukObject { DUK_SCALARTYPE_IMPL(DukObject, duk_idx_t) }; + +struct DukCFunction +{ + DUK_TYPE_ID(DukCFunction) + duk_c_function func; + duk_int_t nargs; + DukCFunction(duk_c_function func, duk_int_t nargs = DUK_VARARGS) : + func(func), nargs(nargs) + { + } +}; + +struct DukObject +{ + DUK_TYPE_ID(DukObject) + const DukPropListEntry * props; + DukObject(const DukPropListEntry * props = nullptr) : + props(props) + { + } +}; + +struct DukGetter +{ + DUK_SCALARTYPE_IMPL(DukGetter, duk_c_function) +}; + +struct DukGetterSetter +{ + DUK_TYPE_ID(DukGetterSetter) + duk_c_function getter, setter; + DukGetterSetter(duk_c_function getter, duk_c_function setter) : + getter(getter), setter(setter) + { + } +}; + +struct DukProxy +{ + DUK_TYPE_ID(DukProxy) + duk_c_function getter, setter; + DukProxy(duk_c_function getter, duk_c_function setter) : + getter(getter), setter(setter) + { + } +}; + +struct DukPropListEntry +{ + const char * key; + DukPropTypeID typeId; + bool writable, enumerable; + + union Value + { + DUK_DECLVAL_MEMBER(DukInt, dukInt) + DUK_DECLVAL_MEMBER(DukUInt, dukUInt) + DUK_DECLVAL_MEMBER(DukNumber, dukNumber) + DUK_DECLVAL_MEMBER(DukBoolean, dukBoolean) + DUK_DECLVAL_MEMBER(DukString, dukString) + DUK_DECLVAL_MEMBER(DukPointer, dukPointer) + DUK_DECLVAL_MEMBER(DukCFunction, dukCFunction) + DUK_DECLVAL_MEMBER(DukGetter, dukGetter) + DUK_DECLVAL_MEMBER(DukGetterSetter, dukGetterSetter) + DUK_DECLVAL_MEMBER(DukDupIndex, dukDupIndex) + DUK_DECLVAL_MEMBER(DukObject, dukObject) + DUK_DECLVAL_MEMBER(DukProxy, dukProxy) + } value; + + template + DukPropListEntry(const char * key, T value, bool writable = false, bool enumerable = true) : + key(key), typeId(T::_TYPE), writable(writable), enumerable(enumerable), value(value) + { + } + + DukPropListEntry(nullptr_t) : + key(nullptr), value(DukInt(0)) + { + } + + DukPropListEntry(const char * key) : + key(key), typeId(Type_DukInt), writable(false), enumerable(false), value(DukInt(0)) + { + } +}; + +// todo proxy object +// todo DukObjectConfig_DummyConstructor +// todo DukObjectConfig_Finalizer +// todo DukObjectConfig_Freeze + +void DukPutPropList(duk_context * ctx, duk_idx_t obj_idx, const DukPropListEntry * props); +}; // namespace ScriptAPI diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_AddressRange.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_AddressRange.cpp index 42cad9a3f..c8d53eada 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_AddressRange.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_AddressRange.cpp @@ -13,7 +13,7 @@ void ScriptAPI::Define_AddressRange(duk_context * ctx) {"includes", DukCFunction(js_AddressRange_includes)}, {"offset", DukCFunction(js_AddressRange_offset)}, {"address", DukCFunction(js_AddressRange_address)}, - { nullptr } + {nullptr}, }; DefineGlobalClass(ctx, "AddressRange", js_AddressRange__constructor, prototype); @@ -32,9 +32,9 @@ void ScriptAPI::Define_AddressRange(duk_context * ctx) {"ADDR_ANY_RDRAM_UNC", 0xA0000000, 0xA07FFFFF}, {"ADDR_ANY_CART_ROM", 0x90000000, 0x95FFFFFF}, {"ADDR_ANY_CART_ROM_UNC", 0xB0000000, 0xB5FFFFFF}, - { nullptr, 0, 0 } + {nullptr, 0, 0}, }; - + duk_push_global_object(ctx); for (int i = 0; ranges[i].key != nullptr; i++) diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_N64Image.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_N64Image.cpp index 13a24ca36..24fea012a 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_N64Image.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_N64Image.cpp @@ -28,14 +28,14 @@ void ScriptAPI::Define_N64Image(duk_context * ctx) const DukPropListEntry prototype[] = { {"toPNG", DukCFunction(js_N64Image_toPNG)}, {"update", DukCFunction(js_N64Image_update)}, - { nullptr} + {nullptr}, }; - + const DukPropListEntry staticProps[] = { {"fromPNG", DukCFunction(js_N64Image_static_fromPNG)}, {"format", DukCFunction(js_N64Image_static_format)}, {"bpp", DukCFunction(js_N64Image_static_bpp)}, - { nullptr } + {nullptr}, }; DefineGlobalClass(ctx, "N64Image", js_N64Image__constructor, prototype, staticProps); @@ -72,7 +72,7 @@ static void InitImageObjectProps(duk_context * ctx, duk_idx_t idx, CN64Image * i {"palette", DukDupIndex(palette_idx)}, {"width", DukUInt(image->Width())}, {"height", DukUInt(image->Height())}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, idx, props); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Server.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Server.cpp index dc98d0957..d47f59187 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Server.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Server.cpp @@ -15,9 +15,9 @@ void ScriptAPI::Define_Server(duk_context * ctx) {"port", DukGetter(js_Server__get_port)}, {"address", DukGetter(js_Server__get_address)}, {"addressFamily", DukGetter(js_Server__get_addressFamily)}, - { nullptr } + {nullptr}, }; - + DefineGlobalClass(ctx, "Server", js_Server__constructor, prototype); } diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Socket.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Socket.cpp index 5b211fa51..ae4c12bc7 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Socket.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_Socket.cpp @@ -24,7 +24,7 @@ void ScriptAPI::Define_Socket(duk_context * ctx) {"remoteAddress", DukGetter(js_Socket__get_remoteAddress)}, {"remotePort", DukGetter(js_Socket__get_remotePort)}, {"addressFamily", DukGetter(js_Socket__get_addressFamily)}, - { nullptr } + {nullptr}, }; DefineGlobalClass(ctx, "Socket", js_Socket__constructor, prototype, nullptr); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_asm.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_asm.cpp index d1d8d2837..ce3656381 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_asm.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_asm.cpp @@ -10,7 +10,7 @@ void ScriptAPI::Define_asm(duk_context * ctx) {"gprname", DukCFunction(js_asm_gprname)}, {"encode", DukCFunction(js_asm_encode)}, {"decode", DukCFunction(js_asm_decode)}, - { nullptr } + {nullptr}, }; DefineGlobalInterface(ctx, "asm", props); @@ -19,10 +19,38 @@ void ScriptAPI::Define_asm(duk_context * ctx) duk_ret_t ScriptAPI::js_asm_gprname(duk_context * ctx) { const char * names[32] = { - "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", - "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", - "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra" + "r0", + "at", + "v0", + "v1", + "a0", + "a1", + "a2", + "a3", + "t0", + "t1", + "t2", + "t3", + "t4", + "t5", + "t6", + "t7", + "s0", + "s1", + "s2", + "s3", + "s4", + "s5", + "s6", + "s7", + "t8", + "t9", + "k0", + "k1", + "gp", + "sp", + "fp", + "ra", }; CheckArgs(ctx, {Arg_Number}); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_console.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_console.cpp index 9ae664dc0..cb8ca255d 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_console.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_console.cpp @@ -13,7 +13,7 @@ void ScriptAPI::Define_console(duk_context * ctx) {"error", DukCFunction(js_console_error)}, {"clear", DukCFunction(js_console_clear)}, {"listen", DukCFunction(js_console_listen)}, - { nullptr } + {nullptr}, }; DefineGlobalInterface(ctx, "console", props); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_cpu.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_cpu.cpp index 24672af1a..89ac4ef79 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_cpu.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_cpu.cpp @@ -39,7 +39,7 @@ void ScriptAPI::Define_cpu(duk_context * ctx) {"fpr", REG_PROXY_FUNCTIONS(js_cpu_fpr_get, js_cpu_fpr_set)}, {"dfpr", REG_PROXY_FUNCTIONS(js_cpu_dfpr_get, js_cpu_dfpr_set)}, {"cop0", REG_PROXY_FUNCTIONS(js_cpu_cop0_get, js_cpu_cop0_set)}, - { nullptr, nullptr } + {nullptr, nullptr}, }; const duk_function_list_entry cpufuncs[] = REG_PROXY_FUNCTIONS(js_cpu_get, js_cpu_set); @@ -368,10 +368,38 @@ static duk_ret_t FPRSetImpl(duk_context * ctx, bool bDouble) static int GPRIndex(const char * regName) { const char * names[] = { - "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", - "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", - "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra" + "r0", + "at", + "v0", + "v1", + "a0", + "a1", + "a2", + "a3", + "t0", + "t1", + "t2", + "t3", + "t4", + "t5", + "t6", + "t7", + "s0", + "s1", + "s2", + "s3", + "s4", + "s5", + "s6", + "s7", + "t8", + "t9", + "k0", + "k1", + "gp", + "sp", + "fp", + "ra", }; for (int i = 0; i < 32; i++) @@ -388,10 +416,38 @@ static int GPRIndex(const char * regName) static int FPRIndex(const char * regName) { const char * names[32] = { - "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", - "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16", - "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24", - "f25", "f26", "f27", "f28", "f29", "f30", "f31" + "f0", + "f1", + "f2", + "f3", + "f4", + "f5", + "f6", + "f7", + "f8", + "f9", + "f10", + "f11", + "f12", + "f13", + "f14", + "f15", + "f16", + "f17", + "f18", + "f19", + "f20", + "f21", + "f22", + "f23", + "f24", + "f25", + "f26", + "f27", + "f28", + "f29", + "f30", + "f31", }; for (int i = 0; i < 32; i++) @@ -435,9 +491,9 @@ static uint32_t * COP0RegPtr(const char * regName) {"taglo", (uint32_t *)&g_Reg->TAGLO_REGISTER}, {"taghi", (uint32_t *)&g_Reg->TAGHI_REGISTER}, {"errorepc", (uint32_t *)&g_Reg->ERROREPC_REGISTER}, - { nullptr, nullptr } + {nullptr, nullptr}, }; - + for (int i = 0; names[i].name != nullptr; i++) { if (strcmp(regName, names[i].name) == 0) diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_debug.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_debug.cpp index f97f79af2..da9411a72 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_debug.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_debug.cpp @@ -12,8 +12,8 @@ void ScriptAPI::Define_debug(duk_context * ctx) {"resume", DukCFunction(js_debug_resume)}, {"showmemory", DukCFunction(js_debug_showmemory)}, {"showcommands", DukCFunction(js_debug_showcommands)}, - { "paused", DukGetter(js_debug__get_paused) }, - { nullptr } + {"paused", DukGetter(js_debug__get_paused)}, + {nullptr}, }; DefineGlobalInterface(ctx, "debug", props); @@ -35,8 +35,7 @@ duk_ret_t ScriptAPI::js_debug_step(duk_context * ctx) { CheckArgs(ctx, {}); - if (g_Settings->LoadBool(Debugger_SteppingOps) && - CDebugSettings::WaitingForStep()) + if (g_Settings->LoadBool(Debugger_SteppingOps) && CDebugSettings::WaitingForStep()) { g_Settings->SaveBool(Debugger_SilentBreak, true); GetInstance(ctx)->Debugger()->StepEvent().Trigger(); @@ -50,8 +49,7 @@ duk_ret_t ScriptAPI::js_debug_skip(duk_context * ctx) g_Settings->SaveBool(Debugger_SkipOp, true); - if (g_Settings->LoadBool(Debugger_SteppingOps) && - CDebugSettings::WaitingForStep()) + if (g_Settings->LoadBool(Debugger_SteppingOps) && CDebugSettings::WaitingForStep()) { GetInstance(ctx)->Debugger()->StepEvent().Trigger(); } diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_events.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_events.cpp index c191ae346..8e954e61b 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_events.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_events.cpp @@ -43,7 +43,7 @@ void ScriptAPI::Define_events(duk_context * ctx) {"onmousedown", DukCFunction(js_events_onmousedown)}, {"onmousemove", DukCFunction(js_events_onmousemove)}, {"remove", DukCFunction(js_events_remove)}, - { nullptr } + {nullptr}, }; DefineGlobalInterface(ctx, "events", props); @@ -63,7 +63,7 @@ void ScriptAPI::Define_events(duk_context * ctx) {"LEFT", DukNumber(0)}, {"MIDDLE", DukNumber(1)}, {"RIGHT", DukNumber(2)}, - {nullptr} + {nullptr}, }; DefineGlobalClass(ctx, "MouseEvent", js_DummyConstructor, nullptr, mouseEventStaticProps); @@ -266,8 +266,7 @@ bool CbCond_ReadAddrBetween(JSAppCallback * cb, void * _env) uint32_t addr = env->opInfo.GetLoadStoreAddress(); - return (addr >= cb->m_Params.addrStart && - addr <= cb->m_Params.addrEnd); + return (addr >= cb->m_Params.addrStart && addr <= cb->m_Params.addrEnd); } bool CbCond_WriteAddrBetween(JSAppCallback * cb, void * _env) @@ -281,15 +280,13 @@ bool CbCond_WriteAddrBetween(JSAppCallback * cb, void * _env) uint32_t addr = env->opInfo.GetLoadStoreAddress(); - return (addr >= cb->m_Params.addrStart && - addr <= cb->m_Params.addrEnd); + return (addr >= cb->m_Params.addrStart && addr <= cb->m_Params.addrEnd); } bool CbCond_PcBetween(JSAppCallback * cb, void * _env) { JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env; - return (env->pc >= cb->m_Params.addrStart && - env->pc <= cb->m_Params.addrEnd); + return (env->pc >= cb->m_Params.addrStart && env->pc <= cb->m_Params.addrEnd); } bool CbCond_PcBetween_OpcodeEquals(JSAppCallback * cb, void * _env) @@ -337,7 +334,7 @@ duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context * ctx, void * _env) const DukPropListEntry props[] = { {"callbackId", DukUInt(inst->CallbackId())}, {"state", DukUInt(env->state)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -353,7 +350,7 @@ duk_idx_t CbArgs_GenericEventObject(duk_context * ctx, void * /*_env*/) const DukPropListEntry props[] = { {"callbackId", DukUInt(inst->CallbackId())}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -371,7 +368,7 @@ duk_idx_t CbArgs_ExecEventObject(duk_context * ctx, void * _env) const DukPropListEntry props[] = { {"callbackId", DukUInt(inst->CallbackId())}, {"pc", DukUInt(env->pc)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -400,7 +397,7 @@ duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * _env) {"address", DukUInt(address)}, {"reg", DukUInt(rt)}, {"fpu", DukBoolean(bFPU)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -470,7 +467,7 @@ duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * _env) bNeedUpper32 = true; break; case R4300i_LDL: - { + { int shift = (address & 7) * 8; uint64_t mask = ~(((uint64_t)-1) << shift); debugger->DebugLoad_VAddr(address & ~7, value.u64); @@ -478,10 +475,10 @@ duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * _env) duk_push_number(ctx, (duk_double_t)(value.u64 & 0xFFFFFFFF)); duk_push_int(ctx, U64); bNeedUpper32 = true; - } break; + } case R4300i_LDR: - { + { int shift = 56 - ((address & 7) * 8); uint64_t mask = ~(((uint64_t)-1) >> shift); debugger->DebugLoad_VAddr(address & ~7, value.u64); @@ -489,28 +486,28 @@ duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * _env) duk_push_number(ctx, (duk_double_t)(value.u64 & 0xFFFFFFFF)); duk_push_int(ctx, U64); bNeedUpper32 = true; - } break; + } case R4300i_LWL: - { + { int shift = (address & 3) * 8; uint32_t mask = ~(((uint32_t)-1) << shift); debugger->DebugLoad_VAddr(address & ~3, value.s32); value.s32 = (g_Reg->m_GPR[rt].W[0] & mask) + (value.s32 << shift); duk_push_number(ctx, value.s32); duk_push_int(ctx, S32); - } break; + } case R4300i_LWR: - { + { int shift = 24 - ((address & 3) * 8); uint32_t mask = ~(((uint32_t)-1) >> shift); debugger->DebugLoad_VAddr(address & ~3, value.s32); value.s32 = (g_Reg->m_GPR[rt].W[0] & mask) + (value.s32 >> shift); duk_push_number(ctx, value.s32); duk_push_int(ctx, S32); - } break; + } default: duk_push_number(ctx, 0); duk_push_number(ctx, 0); @@ -551,7 +548,7 @@ duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env) {"address", DukUInt(address)}, {"reg", DukUInt(rt)}, {"fpu", DukBoolean(bFPU)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -587,7 +584,7 @@ duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env) bNeedUpper32 = true; break; case R4300i_SWL: - { + { int shift = (address & 3) * 8; uint32_t mask = ~(((uint32_t)-1) >> shift); uint32_t value; @@ -595,10 +592,10 @@ duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env) value = (value & mask) + (g_Reg->m_GPR[rt].UW[0] >> shift); duk_push_number(ctx, value); duk_push_int(ctx, S32); - } break; + } case R4300i_SWR: - { + { int shift = 24 - ((address & 3) * 8); uint32_t mask = ~(((uint32_t)-1) << shift); uint32_t value; @@ -606,17 +603,18 @@ duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env) value = (value & mask) + (g_Reg->m_GPR[rt].UW[0] >> shift); duk_push_number(ctx, value); duk_push_int(ctx, S32); - } break; + } case R4300i_SDL: - { + { int shift = (address & 7) * 8; uint64_t mask = ~(((uint64_t)-1) >> shift); debugger->DebugLoad_VAddr(address & ~7, value64); value64 = (value64 & mask) + (g_Reg->m_GPR[rt].UDW >> shift); duk_push_number(ctx, (duk_double_t)(value64 & 0xFFFFFFFF)); duk_push_int(ctx, U64); - } + break; + } case R4300i_SDR: { int shift = 56 - ((address & 7) * 8); @@ -625,6 +623,7 @@ duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env) value64 = (value64 & mask) + (g_Reg->m_GPR[rt].UDW >> shift); duk_push_number(ctx, (duk_double_t)(value64 & 0xFFFFFFFF)); duk_push_int(ctx, U64); + break; } default: duk_push_number(ctx, 0); @@ -657,7 +656,7 @@ duk_idx_t CbArgs_OpcodeEventObject(duk_context * ctx, void * _env) {"callbackId", DukUInt(inst->CallbackId())}, {"pc", DukUInt(env->pc)}, {"opcode", DukUInt(env->opInfo.m_OpCode.Value)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -677,7 +676,7 @@ duk_idx_t CbArgs_RegValueEventObject(duk_context * ctx, void * _env) {"pc", DukUInt(env->pc)}, {"value", DukUInt(g_Reg->m_GPR[env->outAffectedRegIndex].UW[0])}, {"reg", DukUInt(env->outAffectedRegIndex)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -697,9 +696,9 @@ static duk_idx_t CbArgs_MouseEventObject(duk_context * ctx, void * _env) {"button", DukInt(env->button)}, {"x", DukInt(env->x)}, {"y", DukInt(env->y)}, - { nullptr } + {nullptr}, }; - + DukPutPropList(ctx, -1, props); duk_freeze(ctx, -1); return 1; @@ -730,7 +729,7 @@ static duk_idx_t CbArgs_SPTaskEventObject(duk_context * ctx, void * _env) {"dataSize", DukUInt(env->dataSize)}, {"yieldDataAddress", DukUInt(env->yieldDataAddress | 0x80000000)}, {"yieldDataSize", DukUInt(env->yieldDataSize)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -751,7 +750,7 @@ static duk_idx_t CbArgs_PIEventObject(duk_context * ctx, void * _env) {"dramAddress", DukUInt(env->dramAddress | 0x80000000)}, {"cartAddress", DukUInt(env->cartAddress | 0xA0000000)}, {"length", DukUInt(env->length + 1)}, - { nullptr } + {nullptr}, }; DukPutPropList(ctx, -1, props); @@ -778,8 +777,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_ if (duk_is_object(ctx, idx)) { - if (!duk_has_prop_string(ctx, idx, "start") || - !duk_has_prop_string(ctx, idx, "end")) + if (!duk_has_prop_string(ctx, idx, "start") || !duk_has_prop_string(ctx, idx, "end")) { duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, "object is missing 'start' or 'end' property"); @@ -789,8 +787,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_ duk_get_prop_string(ctx, idx, "start"); duk_get_prop_string(ctx, idx, "end"); - if (!duk_is_number(ctx, -2) || - !duk_is_number(ctx, -1)) + if (!duk_is_number(ctx, -2) || !duk_is_number(ctx, -1)) { duk_pop_n(ctx, 2); duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, @@ -798,8 +795,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_ return duk_throw(ctx); } - if (abs(duk_get_number(ctx, -2)) > 0xFFFFFFFF || - abs(duk_get_number(ctx, -1)) > 0xFFFFFFFF) + if (abs(duk_get_number(ctx, -2)) > 0xFFFFFFFF || abs(duk_get_number(ctx, -1)) > 0xFFFFFFFF) { duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "'start' or 'end' property out of range"); @@ -819,8 +815,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_ duk_ret_t RequireInterpreterCPU(duk_context * ctx) { - if (!g_Settings->LoadBool(Setting_ForceInterpreterCPU) && - (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) + if (!g_Settings->LoadBool(Setting_ForceInterpreterCPU) && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) { duk_push_error_object(ctx, DUK_ERR_ERROR, "this feature requires the interpreter core"); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_exec.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_exec.cpp index ca56b89ea..65e5ac0cb 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_exec.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_exec.cpp @@ -135,7 +135,7 @@ duk_ret_t ScriptAPI::js_exec(duk_context * ctx) {"stdout", DukString(resultStdOut.c_str())}, {"stderr", DukString(resultStdErr.c_str())}, {"pid", DukUInt(processInfo.dwProcessId)}, - { nullptr } + {nullptr}, }; duk_push_error_object(ctx, resultExitCode, "exec(): process returned %d", resultExitCode); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_fs.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_fs.cpp index 94c1e68dd..73e0fd554 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_fs.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_fs.cpp @@ -1,39 +1,44 @@ #include + #include "ScriptAPI.h" #include -#pragma warning(disable: 4702) // disable unreachable code warning +#pragma warning(disable : 4702) // disable unreachable code warning -enum fsop { FS_READ, FS_WRITE }; -static duk_ret_t ReadWriteImpl(duk_context *ctx, fsop op); // (fd, buffer, offset, length, position) -static duk_ret_t js__FileFinalizer(duk_context *ctx); +enum fsop +{ + FS_READ, + FS_WRITE +}; +static duk_ret_t ReadWriteImpl(duk_context * ctx, fsop op); // (fd, buffer, offset, length, position) +static duk_ret_t js__FileFinalizer(duk_context * ctx); -void ScriptAPI::Define_fs(duk_context *ctx) +void ScriptAPI::Define_fs(duk_context * ctx) { // todo DukPutProps DukClass const duk_function_list_entry funcs[] = { - { "open", js_fs_open, DUK_VARARGS }, - { "close", js_fs_close, DUK_VARARGS }, - { "write", js_fs_write, DUK_VARARGS }, - { "writefile", js_fs_writefile, DUK_VARARGS }, - { "read", js_fs_read, DUK_VARARGS }, - { "readfile", js_fs_readfile, DUK_VARARGS }, - { "exists", js_fs_exists, DUK_VARARGS }, - { "fstat", js_fs_fstat, DUK_VARARGS }, - { "stat", js_fs_stat, DUK_VARARGS }, - { "unlink", js_fs_unlink, DUK_VARARGS }, - { "mkdir", js_fs_mkdir, DUK_VARARGS }, - { "rmdir", js_fs_rmdir, DUK_VARARGS }, - { "readdir", js_fs_readdir, DUK_VARARGS }, - { "Stats", js_fs_Stats__constructor, DUK_VARARGS }, - { nullptr, nullptr, 0 } + {"open", js_fs_open, DUK_VARARGS}, + {"close", js_fs_close, DUK_VARARGS}, + {"write", js_fs_write, DUK_VARARGS}, + {"writefile", js_fs_writefile, DUK_VARARGS}, + {"read", js_fs_read, DUK_VARARGS}, + {"readfile", js_fs_readfile, DUK_VARARGS}, + {"exists", js_fs_exists, DUK_VARARGS}, + {"fstat", js_fs_fstat, DUK_VARARGS}, + {"stat", js_fs_stat, DUK_VARARGS}, + {"unlink", js_fs_unlink, DUK_VARARGS}, + {"mkdir", js_fs_mkdir, DUK_VARARGS}, + {"rmdir", js_fs_rmdir, DUK_VARARGS}, + {"readdir", js_fs_readdir, DUK_VARARGS}, + {"Stats", js_fs_Stats__constructor, DUK_VARARGS}, + {nullptr, nullptr, 0}, }; const duk_function_list_entry Stats_funcs[] = { - { "isFile", js_fs_Stats_isFile, DUK_VARARGS }, - { "isDirectory", js_fs_Stats_isDirectory, DUK_VARARGS }, - { nullptr, nullptr, 0 } + {"isFile", js_fs_Stats_isFile, DUK_VARARGS}, + {"isDirectory", js_fs_Stats_isDirectory, DUK_VARARGS}, + {nullptr, nullptr, 0}, }; duk_push_global_object(ctx); @@ -52,16 +57,16 @@ void ScriptAPI::Define_fs(duk_context *ctx) duk_pop(ctx); } -duk_ret_t ScriptAPI::js_fs_open(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_open(duk_context * ctx) { - CheckArgs(ctx, { Arg_String, Arg_String }); + CheckArgs(ctx, {Arg_String, Arg_String}); - const char* path = duk_get_string(ctx, 0); - const char* mode = duk_get_string(ctx, 1); + const char * path = duk_get_string(ctx, 0); + const char * mode = duk_get_string(ctx, 1); bool bModeValid = false; - const char* validModes[] = { + const char * validModes[] = { "r", "rb", "w", "wb", "a", "ab", @@ -86,9 +91,9 @@ duk_ret_t ScriptAPI::js_fs_open(duk_context *ctx) return duk_throw(ctx); } - FILE *fp = fopen(path, mode); + FILE * fp = fopen(path, mode); - if(fp == nullptr) + if (fp == nullptr) { duk_push_error_object(ctx, DUK_ERR_ERROR, "could not open '%s' (mode: '%s')", path, mode); return duk_throw(ctx); @@ -113,26 +118,26 @@ duk_ret_t ScriptAPI::js_fs_open(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_close(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_close(duk_context * ctx) { - CheckArgs(ctx, { Arg_Number }); + CheckArgs(ctx, {Arg_Number}); int fd = duk_get_int(ctx, 0); int rc = -1; duk_get_global_string(ctx, HS_gOpenFileDescriptors); - if(duk_has_prop_index(ctx, -1, fd)) + if (duk_has_prop_index(ctx, -1, fd)) { duk_get_prop_index(ctx, -1, fd); duk_get_prop_string(ctx, -1, "fp"); - FILE* fp = (FILE*)duk_get_pointer(ctx, -1); + FILE * fp = (FILE *)duk_get_pointer(ctx, -1); rc = fclose(fp); // unset finalizer before deleting duk_push_undefined(ctx); - duk_set_finalizer(ctx, -3); + duk_set_finalizer(ctx, -3); duk_del_prop_index(ctx, -3, fd); duk_pop_n(ctx, 2); @@ -148,26 +153,26 @@ duk_ret_t ScriptAPI::js_fs_close(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_write(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_write(duk_context * ctx) { - CheckArgs(ctx, { Arg_Number, Arg_Any, Arg_OptNumber, Arg_OptNumber, Arg_OptNumber }); + CheckArgs(ctx, {Arg_Number, Arg_Any, Arg_OptNumber, Arg_OptNumber, Arg_OptNumber}); return ReadWriteImpl(ctx, FS_WRITE); } -duk_ret_t ScriptAPI::js_fs_writefile(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_writefile(duk_context * ctx) { - CheckArgs(ctx, { Arg_String, Arg_Any }); + CheckArgs(ctx, {Arg_String, Arg_Any}); - const char* path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); - void* buffer; + void * buffer; duk_size_t bufferSize; - if(duk_is_string(ctx, 1)) + if (duk_is_string(ctx, 1)) { - buffer = (void*)duk_get_lstring(ctx, 1, &bufferSize); + buffer = (void *)duk_get_lstring(ctx, 1, &bufferSize); } - else if(duk_is_buffer_data(ctx, 1)) + else if (duk_is_buffer_data(ctx, 1)) { buffer = duk_get_buffer_data(ctx, 1, &bufferSize); } @@ -176,15 +181,15 @@ duk_ret_t ScriptAPI::js_fs_writefile(duk_context *ctx) return ThrowInvalidArgsError(ctx); } - FILE* fp = fopen(path, "wb"); + FILE * fp = fopen(path, "wb"); - if(fp == nullptr) + if (fp == nullptr) { duk_push_error_object(ctx, DUK_ERR_ERROR, "could not open '%s' (mode: 'wb')", path); return duk_throw(ctx); } - if(fwrite(buffer, 1, bufferSize, fp) != bufferSize) + if (fwrite(buffer, 1, bufferSize, fp) != bufferSize) { fclose(fp); return DUK_RET_ERROR; @@ -194,37 +199,37 @@ duk_ret_t ScriptAPI::js_fs_writefile(duk_context *ctx) return 0; } -duk_ret_t ScriptAPI::js_fs_read(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_read(duk_context * ctx) { - CheckArgs(ctx, { Arg_Number, Arg_Any, Arg_Number, Arg_Number, Arg_Number }); + CheckArgs(ctx, {Arg_Number, Arg_Any, Arg_Number, Arg_Number, Arg_Number}); return ReadWriteImpl(ctx, FS_READ); } -duk_ret_t ScriptAPI::js_fs_readfile(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_readfile(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char* path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); - FILE* fp = fopen(path, "rb"); + FILE * fp = fopen(path, "rb"); - if(fp == nullptr) + if (fp == nullptr) { duk_push_error_object(ctx, DUK_ERR_ERROR, "could not open '%s' (mode: 'rb')", path); return duk_throw(ctx); } struct stat stats; - if(fstat(_fileno(fp), &stats) != 0) + if (fstat(_fileno(fp), &stats) != 0) { fclose(fp); return DUK_RET_ERROR; } - void *data = duk_push_fixed_buffer(ctx, stats.st_size); + void * data = duk_push_fixed_buffer(ctx, stats.st_size); duk_push_buffer_object(ctx, -1, 0, stats.st_size, DUK_BUFOBJ_NODEJS_BUFFER); - if(fread(data, 1, stats.st_size, fp) != (size_t)stats.st_size) + if (fread(data, 1, stats.st_size, fp) != (size_t)stats.st_size) { duk_pop(ctx); fclose(fp); @@ -235,17 +240,17 @@ duk_ret_t ScriptAPI::js_fs_readfile(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_exists(duk_context* ctx) +duk_ret_t ScriptAPI::js_fs_exists(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); - const char* path = duk_get_string(ctx, 0); + CheckArgs(ctx, {Arg_String}); + const char * path = duk_get_string(ctx, 0); duk_push_boolean(ctx, PathFileExistsA(path) ? 1 : 0); return 1; } -duk_ret_t ScriptAPI::js_fs_fstat(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_fstat(duk_context * ctx) { - CheckArgs(ctx, { Arg_Number }); + CheckArgs(ctx, {Arg_Number}); int fd = duk_get_int(ctx, 0); @@ -257,11 +262,11 @@ duk_ret_t ScriptAPI::js_fs_fstat(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_stat(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_stat(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char *path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); duk_push_global_object(ctx); duk_get_prop_string(ctx, -1, "fs"); @@ -271,39 +276,39 @@ duk_ret_t ScriptAPI::js_fs_stat(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_unlink(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_unlink(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char *path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); duk_push_boolean(ctx, DeleteFileA(path) != 0); return 1; } -duk_ret_t ScriptAPI::js_fs_mkdir(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_mkdir(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char *path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); duk_push_boolean(ctx, CreateDirectoryA(path, nullptr) != 0); return 1; } -duk_ret_t ScriptAPI::js_fs_rmdir(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_rmdir(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char *path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); duk_push_boolean(ctx, RemoveDirectoryA(path) != 0); return 1; } // todo make sure failure behavior is similar to nodejs's fs.readdirSync -duk_ret_t ScriptAPI::js_fs_readdir(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_readdir(duk_context * ctx) { - CheckArgs(ctx, { Arg_String }); + CheckArgs(ctx, {Arg_String}); - const char* path = duk_get_string(ctx, 0); + const char * path = duk_get_string(ctx, 0); char findFileName[MAX_PATH]; snprintf(findFileName, sizeof(findFileName), "%s%s", path, "\\*"); @@ -311,7 +316,7 @@ duk_ret_t ScriptAPI::js_fs_readdir(duk_context *ctx) WIN32_FIND_DATAA ffd; HANDLE hFind = FindFirstFileA(findFileName, &ffd); - if(hFind == INVALID_HANDLE_VALUE) + if (hFind == INVALID_HANDLE_VALUE) { return DUK_RET_ERROR; } @@ -321,45 +326,44 @@ duk_ret_t ScriptAPI::js_fs_readdir(duk_context *ctx) do { - if(strcmp(ffd.cFileName, ".") == 0 || - strcmp(ffd.cFileName, "..") == 0) + if (strcmp(ffd.cFileName, ".") == 0 || strcmp(ffd.cFileName, "..") == 0) { continue; } duk_push_string(ctx, ffd.cFileName); duk_put_prop_index(ctx, -2, idx++); - } while(FindNextFileA(hFind, &ffd)); - + } while (FindNextFileA(hFind, &ffd)); + FindClose(hFind); return 1; } -duk_ret_t ScriptAPI::js_fs_Stats__constructor(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_Stats__constructor(duk_context * ctx) { - if(!duk_is_constructor_call(ctx)) + if (!duk_is_constructor_call(ctx)) { return DUK_RET_TYPE_ERROR; } - if(duk_get_top(ctx) != 1) + if (duk_get_top(ctx) != 1) { return ThrowInvalidArgsError(ctx); } struct stat stats; - - if(duk_is_number(ctx, 0)) + + if (duk_is_number(ctx, 0)) { int fd = duk_get_int(ctx, 0); - if(fstat(fd, &stats) != 0) + if (fstat(fd, &stats) != 0) { return DUK_RET_ERROR; } } - else if(duk_is_string(ctx, 0)) + else if (duk_is_string(ctx, 0)) { - const char *path = duk_get_string(ctx, 0); - if(stat(path, &stats) != 0) + const char * path = duk_get_string(ctx, 0); + if (stat(path, &stats) != 0) { return DUK_RET_ERROR; } @@ -370,24 +374,24 @@ duk_ret_t ScriptAPI::js_fs_Stats__constructor(duk_context *ctx) } const duk_number_list_entry numbers[] = { - { "dev", (double)stats.st_dev }, - { "ino", (double)stats.st_ino }, - { "mode", (double)stats.st_mode }, - { "nlink", (double)stats.st_nlink }, - { "uid", (double)stats.st_uid }, - { "gid", (double)stats.st_gid }, - { "rdev", (double)stats.st_rdev }, - { "size", (double)stats.st_size }, - { "atimeMs", (double)stats.st_atime * 1000 }, - { "mtimeMs", (double)stats.st_mtime * 1000 }, - { "ctimeMs", (double)stats.st_ctime * 1000 }, - { nullptr, 0 } + {"dev", (double)stats.st_dev}, + {"ino", (double)stats.st_ino}, + {"mode", (double)stats.st_mode}, + {"nlink", (double)stats.st_nlink}, + {"uid", (double)stats.st_uid}, + {"gid", (double)stats.st_gid}, + {"rdev", (double)stats.st_rdev}, + {"size", (double)stats.st_size}, + {"atimeMs", (double)stats.st_atime * 1000}, + {"mtimeMs", (double)stats.st_mtime * 1000}, + {"ctimeMs", (double)stats.st_ctime * 1000}, + {nullptr, 0}, }; struct { const char *key; time_t time; } dates[3] = { - { "atime", stats.st_atime * 1000 }, - { "mtime", stats.st_mtime * 1000 }, - { "ctime", stats.st_ctime * 1000 }, + {"atime", stats.st_atime * 1000}, + {"mtime", stats.st_mtime * 1000}, + {"ctime", stats.st_ctime * 1000}, }; duk_push_global_object(ctx); @@ -397,7 +401,7 @@ duk_ret_t ScriptAPI::js_fs_Stats__constructor(duk_context *ctx) duk_push_this(ctx); duk_put_number_list(ctx, -1, numbers); - for(int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { duk_dup(ctx, -2); duk_push_number(ctx, (duk_double_t)dates[i].time); @@ -410,7 +414,7 @@ duk_ret_t ScriptAPI::js_fs_Stats__constructor(duk_context *ctx) return 0; } -duk_ret_t ScriptAPI::js_fs_Stats_isDirectory(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_Stats_isDirectory(duk_context * ctx) { CheckArgs(ctx, {}); @@ -421,7 +425,7 @@ duk_ret_t ScriptAPI::js_fs_Stats_isDirectory(duk_context *ctx) return 1; } -duk_ret_t ScriptAPI::js_fs_Stats_isFile(duk_context *ctx) +duk_ret_t ScriptAPI::js_fs_Stats_isFile(duk_context * ctx) { CheckArgs(ctx, {}); @@ -432,33 +436,33 @@ duk_ret_t ScriptAPI::js_fs_Stats_isFile(duk_context *ctx) return 1; } -static duk_ret_t ReadWriteImpl(duk_context *ctx, fsop op) +static duk_ret_t ReadWriteImpl(duk_context * ctx, fsop op) { int fd; - const char* buffer; + const char * buffer; size_t offset = 0; size_t length = 0; size_t position = 0; bool bHavePos = false; duk_size_t bufferSize; - FILE* fp; + FILE * fp; size_t rc; duk_idx_t nargs = duk_get_top(ctx); - if(nargs < 2 || !duk_is_number(ctx, 0)) + if (nargs < 2 || !duk_is_number(ctx, 0)) { goto err_invalid_args; } fd = duk_get_int(ctx, 0); - if(duk_is_buffer_data(ctx, 1)) + if (duk_is_buffer_data(ctx, 1)) { - buffer = (const char*)duk_get_buffer_data(ctx, 1, &bufferSize); + buffer = (const char *)duk_get_buffer_data(ctx, 1, &bufferSize); } - else if(duk_is_string(ctx, 1) && op == FS_WRITE) + else if (duk_is_string(ctx, 1) && op == FS_WRITE) { buffer = duk_get_lstring(ctx, 1, &bufferSize); } @@ -467,16 +471,16 @@ static duk_ret_t ReadWriteImpl(duk_context *ctx, fsop op) goto err_invalid_args; } - if(nargs >= 3) + if (nargs >= 3) { - if(!duk_is_number(ctx, 2)) + if (!duk_is_number(ctx, 2)) { goto err_invalid_args; } offset = duk_get_uint(ctx, 2); - if(offset >= bufferSize) + if (offset >= bufferSize) { goto err_invalid_range; } @@ -484,18 +488,18 @@ static duk_ret_t ReadWriteImpl(duk_context *ctx, fsop op) length = bufferSize - offset; - if(nargs >= 4) + if (nargs >= 4) { - if(!duk_is_number(ctx, 3)) + if (!duk_is_number(ctx, 3)) { goto err_invalid_args; } length = duk_get_uint(ctx, 3); } - if(nargs >= 5) + if (nargs >= 5) { - if(!duk_is_number(ctx, 4)) + if (!duk_is_number(ctx, 4)) { goto err_invalid_args; } @@ -503,36 +507,36 @@ static duk_ret_t ReadWriteImpl(duk_context *ctx, fsop op) bHavePos = true; } - if(offset + length > bufferSize) + if (offset + length > bufferSize) { goto err_invalid_range; } duk_get_global_string(ctx, HS_gOpenFileDescriptors); - if(!duk_has_prop_index(ctx, -1, fd)) + if (!duk_has_prop_index(ctx, -1, fd)) { goto err_invalid_fd; } duk_get_prop_index(ctx, -1, fd); duk_get_prop_string(ctx, -1, "fp"); - fp = (FILE*)duk_get_pointer(ctx, -1); - + fp = (FILE *)duk_get_pointer(ctx, -1); + duk_pop_n(ctx, 3); - if(bHavePos) + if (bHavePos) { fseek(fp, position, SEEK_SET); } - switch(op) + switch (op) { case FS_READ: - rc = fread((void*)&buffer[offset], 1, length, fp); + rc = fread((void *)&buffer[offset], 1, length, fp); break; case FS_WRITE: - rc = fwrite((void*)&buffer[offset], 1, length, fp); + rc = fwrite((void *)&buffer[offset], 1, length, fp); break; default: return DUK_RET_ERROR; @@ -553,17 +557,17 @@ err_invalid_fd: return duk_throw(ctx); } -static duk_ret_t js__FileFinalizer(duk_context *ctx) +static duk_ret_t js__FileFinalizer(duk_context * ctx) { - CScriptInstance* inst = ScriptAPI::GetInstance(ctx); + CScriptInstance * inst = ScriptAPI::GetInstance(ctx); duk_get_prop_string(ctx, 0, "fp"); - FILE *fp = (FILE *)duk_get_pointer(ctx, -1); + FILE * fp = (FILE *)duk_get_pointer(ctx, -1); duk_pop(ctx); fclose(fp); inst->System()->ConsoleLog("[SCRIPTSYS]: warning ('%s'): gc closed leftover file descriptor", - inst->Name().c_str()); + inst->Name().c_str()); return 0; } diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp index cae8d1d9d..a28fa1e57 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_mem.cpp @@ -37,7 +37,7 @@ void ScriptAPI::Define_mem(duk_context * ctx) {"s8", DukProxy(MEM_PROXY_FUNCS(int8_t))}, {"f64", DukProxy(MEM_PROXY_FUNCS(double))}, {"f32", DukProxy(MEM_PROXY_FUNCS(float))}, - { nullptr } + {nullptr}, }; DefineGlobalInterface(ctx, "mem", props); @@ -109,8 +109,7 @@ duk_ret_t ScriptAPI::js_mem_getblock(duk_context * ctx) memsrc = g_MMU->Rdram(); offsetStart = paddr; } - else if (g_Rom && paddr >= 0x10000000 && - ((paddr - 0x10000000) + length) <= g_Rom->GetRomSize()) + else if (g_Rom && paddr >= 0x10000000 && ((paddr - 0x10000000) + length) <= g_Rom->GetRomSize()) { memsrc = g_Rom->GetRomAddress(); offsetStart = paddr - 0x10000000; @@ -282,9 +281,15 @@ duk_ret_t ScriptAPI::js_mem__boundget(duk_context * ctx) double f64; } retval; - #define MEM_BOUNDGET_TRY(addr, T, result, dukpush) \ - if(debugger->DebugLoad_VAddr(addr, result)) { dukpush(ctx, result); } \ - else { goto memory_error; } +#define MEM_BOUNDGET_TRY(addr, T, result, dukpush) \ + if (debugger->DebugLoad_VAddr(addr, result)) \ + { \ + dukpush(ctx, result); \ + } \ + else \ + { \ + goto memory_error; \ + } switch (type) { @@ -325,9 +330,15 @@ duk_ret_t ScriptAPI::js_mem__boundset(duk_context * ctx) uint32_t addr = duk_get_uint(ctx, 0); duk_int_t type = duk_get_int(ctx, 1); - #define MEM_BOUNDSET_TRY(addr, T, value) \ - if(debugger->DebugStore_VAddr(addr, value)) { return 1; } \ - else { goto memory_error; } +#define MEM_BOUNDSET_TRY(addr, T, value) \ + if (debugger->DebugStore_VAddr(addr, value)) \ + { \ + return 1; \ + } \ + else \ + { \ + goto memory_error; \ + } switch (type) { @@ -404,8 +415,7 @@ duk_ret_t ScriptAPI::js_mem_bindvars(duk_context * ctx) for (duk_uarridx_t i = 0; i < length; i++) { duk_get_prop_index(ctx, 1, i); - if (!duk_is_array(ctx, -1) || - duk_get_length(ctx, -1) != 3) + if (!duk_is_array(ctx, -1) || duk_get_length(ctx, -1) != 3) { return DUK_RET_TYPE_ERROR; } diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_pj64.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_pj64.cpp index 2863aaa38..a183bb8f4 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_pj64.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_pj64.cpp @@ -17,7 +17,7 @@ void ScriptAPI::Define_pj64(duk_context * ctx) {"id", DukGetter(js_pj64_romInfo__get_headerId)}, {"countryCode", DukGetter(js_pj64_romInfo__get_headerCountryCode)}, {"version", DukGetter(js_pj64_romInfo__get_headerVersion)}, - { nullptr } + {nullptr}, }; const DukPropListEntry props[] = { @@ -35,7 +35,7 @@ void ScriptAPI::Define_pj64(duk_context * ctx) {"romDirectory", DukGetter(js_pj64__get_romDirectory)}, {DUK_HIDDEN_SYMBOL("romInfo"), DukObject(romInfoProps)}, {"romInfo", DukGetter(js_pj64__get_romInfo)}, - { nullptr } + {nullptr}, }; DefineGlobalInterface(ctx, "pj64", props); diff --git a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_script.cpp b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_script.cpp index cd8c96515..3553c4be3 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_script.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptAPI/ScriptAPI_script.cpp @@ -1,45 +1,46 @@ #include + #include "ScriptAPI.h" -#pragma warning(disable: 4702) // disable unreachable code warning +#pragma warning(disable : 4702) // disable unreachable code warning -void ScriptAPI::Define_script(duk_context *ctx) +void ScriptAPI::Define_script(duk_context * ctx) { const DukPropListEntry props[] = { - { "timeout", DukCFunction(js_script_timeout) }, - { "keepalive", DukCFunction(js_script_keepalive) }, - { "abort", DukCFunction(js_script_abort) }, - { nullptr } + {"timeout", DukCFunction(js_script_timeout)}, + {"keepalive", DukCFunction(js_script_keepalive)}, + {"abort", DukCFunction(js_script_abort)}, + {nullptr}, }; DefineGlobalInterface(ctx, "script", props); } -duk_ret_t ScriptAPI::js_script_timeout(duk_context *ctx) +duk_ret_t ScriptAPI::js_script_timeout(duk_context * ctx) { - CheckArgs(ctx, { Arg_Number }); - CScriptInstance* inst = GetInstance(ctx); + CheckArgs(ctx, {Arg_Number}); + CScriptInstance * inst = GetInstance(ctx); inst->SetExecTimeout((uint64_t)duk_get_number(ctx, 0)); return 0; } -duk_ret_t ScriptAPI::js_script_keepalive(duk_context *ctx) +duk_ret_t ScriptAPI::js_script_keepalive(duk_context * ctx) { - CheckArgs(ctx, { Arg_Boolean }); - CScriptInstance* inst = GetInstance(ctx); + CheckArgs(ctx, {Arg_Boolean}); + CScriptInstance * inst = GetInstance(ctx); duk_bool_t bKeepAlive = duk_get_boolean(ctx, 0); duk_push_global_object(ctx); duk_bool_t bHaveProp = duk_has_prop_string(ctx, -1, HS_gKeepAlive); - if(bKeepAlive && !bHaveProp) + if (bKeepAlive && !bHaveProp) { duk_push_boolean(ctx, 1); duk_put_prop_string(ctx, -2, HS_gKeepAlive); inst->IncRefCount(); } - else if(!bKeepAlive && bHaveProp) + else if (!bKeepAlive && bHaveProp) { duk_del_prop_string(ctx, -1, HS_gKeepAlive); inst->DecRefCount(); @@ -50,10 +51,10 @@ duk_ret_t ScriptAPI::js_script_keepalive(duk_context *ctx) return 0; } -duk_ret_t ScriptAPI::js_script_abort(duk_context* ctx) +duk_ret_t ScriptAPI::js_script_abort(duk_context * ctx) { CheckArgs(ctx, {}); - CScriptInstance* inst = GetInstance(ctx); + CScriptInstance * inst = GetInstance(ctx); if (inst->PrepareAbort()) { return duk_fatal(ctx, "aborted"); diff --git a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp index bb6d801d4..a463b6547 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp @@ -99,8 +99,7 @@ bool CScriptInstance::Run(const char * path) try { duk_push_string(m_Ctx, m_InstanceName.c_str()); - if (duk_pcompile_string_filename(m_Ctx, DUK_COMPILE_STRICT, m_SourceCode) != 0 || - duk_pcall(m_Ctx, 0) == DUK_EXEC_ERROR) + if (duk_pcompile_string_filename(m_Ctx, DUK_COMPILE_STRICT, m_SourceCode) != 0 || duk_pcall(m_Ctx, 0) == DUK_EXEC_ERROR) { duk_get_prop_string(m_Ctx, -1, "stack"); m_System->ConsoleLog("%s", duk_safe_to_string(m_Ctx, -1)); @@ -211,8 +210,7 @@ void CScriptInstance::RawConsoleInput(const char * code) m_ExecStartTime = Timestamp(); duk_push_string(m_Ctx, stdstr_f("", m_InstanceName.c_str()).c_str()); - if (duk_pcompile_string_filename(m_Ctx, DUK_COMPILE_STRICT, code) != 0 || - duk_pcall(m_Ctx, 0) == DUK_EXEC_ERROR) + if (duk_pcompile_string_filename(m_Ctx, DUK_COMPILE_STRICT, code) != 0 || duk_pcall(m_Ctx, 0) == DUK_EXEC_ERROR) { duk_get_prop_string(m_Ctx, -1, "stack"); m_System->ConsoleLog("%s", duk_safe_to_string(m_Ctx, -1)); diff --git a/Source/Project64/UserInterface/Debugger/ScriptInstance.h b/Source/Project64/UserInterface/Debugger/ScriptInstance.h index 219d0d777..2273f38c7 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptInstance.h +++ b/Source/Project64/UserInterface/Debugger/ScriptInstance.h @@ -1,5 +1,5 @@ -#include "ScriptTypes.h" #include "ScriptSystem.h" +#include "ScriptTypes.h" #include "ScriptWorker.h" #pragma once @@ -7,44 +7,50 @@ class CScriptInstance { private: - JSInstanceName m_InstanceName; - CScriptSystem* m_System; - duk_context* m_Ctx; - size_t m_RefCount; - uint64_t m_ExecTimeout; - uint64_t m_ExecStartTime; - std::ifstream m_SourceFile; - char* m_SourceCode; + JSInstanceName m_InstanceName; + CScriptSystem * m_System; + duk_context * m_Ctx; + size_t m_RefCount; + uint64_t m_ExecTimeout; + uint64_t m_ExecStartTime; + std::ifstream m_SourceFile; + char * m_SourceCode; JSAppCallbackID m_CurExecCallbackId; - std::vector m_Workers; - bool m_bStopping; - bool m_bAborting; + std::vector m_Workers; + bool m_bStopping; + bool m_bAborting; public: - CScriptInstance(CScriptSystem* sys, const char* name); + CScriptInstance(CScriptSystem * sys, const char * name); ~CScriptInstance(); - JSInstanceName& Name(); - CScriptSystem* System(); - CDebuggerUI* Debugger(); + JSInstanceName & Name(); + CScriptSystem * System(); + CDebuggerUI * Debugger(); JSAppCallbackID CallbackId(); - bool Run(const char* path); - void SetExecTimeout(uint64_t timeout); - bool IsTimedOut(); + bool Run(const char * path); + void SetExecTimeout(uint64_t timeout); + bool IsTimedOut(); - inline size_t GetRefCount() { return m_RefCount; } - void IncRefCount(); - void DecRefCount(); - void SetStopping(bool bStopping); - inline bool IsStopping() { return m_bStopping; } - bool PrepareAbort(); + inline size_t GetRefCount() + { + return m_RefCount; + } + void IncRefCount(); + void DecRefCount(); + void SetStopping(bool bStopping); + inline bool IsStopping() + { + return m_bStopping; + } + bool PrepareAbort(); - bool RegisterWorker(CScriptWorker* worker); - void UnregisterWorker(CScriptWorker* worker); + bool RegisterWorker(CScriptWorker * worker); + void UnregisterWorker(CScriptWorker * worker); void StopRegisteredWorkers(); - inline void RawInvokeAppCallback(JSAppCallback& cb, void* _hookEnv) + inline void RawInvokeAppCallback(JSAppCallback & cb, void * _hookEnv) { m_CurExecCallbackId = cb.m_CallbackId; @@ -58,7 +64,7 @@ public: m_CurExecCallbackId = JS_INVALID_CALLBACK; } - inline void RawCall(void *dukFuncHeapPtr, JSDukArgSetupFunc argSetupFunc, void *param = nullptr) + inline void RawCall(void * dukFuncHeapPtr, JSDukArgSetupFunc argSetupFunc, void * param = nullptr) { m_ExecStartTime = Timestamp(); duk_push_heapptr(m_Ctx, dukFuncHeapPtr); @@ -75,24 +81,24 @@ public: duk_pop(m_Ctx); } - catch (std::runtime_error& exc) + catch (std::runtime_error & exc) { FatalHandler(exc); } } - void RawCMethodCall(void* dukThisHeapPtr, duk_c_function func, - JSDukArgSetupFunc argSetupFunc = nullptr, - void* argSetupParam = nullptr); + void RawCMethodCall(void * dukThisHeapPtr, duk_c_function func, + JSDukArgSetupFunc argSetupFunc = nullptr, + void * argSetupParam = nullptr); - void PostCMethodCall(void* dukThisHeapPtr, duk_c_function func, - JSDukArgSetupFunc argSetupFunc = nullptr, - void* argSetupParam = nullptr, size_t argSetupParamSize = 0); + void PostCMethodCall(void * dukThisHeapPtr, duk_c_function func, + JSDukArgSetupFunc argSetupFunc = nullptr, + void * argSetupParam = nullptr, size_t argSetupParamSize = 0); - void RawConsoleInput(const char* code); + void RawConsoleInput(const char * code); private: - void FatalHandler(std::runtime_error& exc); + void FatalHandler(std::runtime_error & exc); static uint64_t Timestamp(); void Cleanup(); }; diff --git a/Source/Project64/UserInterface/Debugger/ScriptSystem.cpp b/Source/Project64/UserInterface/Debugger/ScriptSystem.cpp index b4690d233..99bf9cb86 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptSystem.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptSystem.cpp @@ -162,8 +162,7 @@ bool CScriptSystem::HaveAppCallbacks(JSAppHookID hookId) { CGuard guard(m_InstancesCS); - return (hookId < JS_NUM_APP_HOOKS && - m_AppCallbackHooks[hookId].size() > 0); + return (hookId < JS_NUM_APP_HOOKS && m_AppCallbackHooks[hookId].size() > 0); } void CScriptSystem::InvokeAppCallbacks(JSAppHookID hookId, void * env) @@ -180,10 +179,7 @@ void CScriptSystem::InvokeAppCallbacks(JSAppHookID hookId, void * env) JSAppCallback & callback = callbacks[i]; CScriptInstance * instance = callback.m_Instance; - if (callback.m_bDisabled || - instance->IsStopping() || - m_StopsIssued.count(instance->Name()) != 0 || - !callback.m_ConditionFunc(&callback, env)) + if (callback.m_bDisabled || instance->IsStopping() || m_StopsIssued.count(instance->Name()) != 0 || !callback.m_ConditionFunc(&callback, env)) { continue; } @@ -215,10 +211,7 @@ void CScriptSystem::UpdateCpuCbListInfo(volatile JSCpuCbListInfo & info, JSAppCa for (i = 0; i < numCacheEntries; i++) { // combine adjacent/overlapping ranges - if ((callback.m_Params.addrStart >= info.rangeCache[i].addrStart && - callback.m_Params.addrStart <= info.rangeCache[i].addrEnd + 1) || - (callback.m_Params.addrEnd >= info.rangeCache[i].addrStart - 1 && - callback.m_Params.addrEnd <= info.rangeCache[i].addrEnd)) + if ((callback.m_Params.addrStart >= info.rangeCache[i].addrStart && callback.m_Params.addrStart <= info.rangeCache[i].addrEnd + 1) || (callback.m_Params.addrEnd >= info.rangeCache[i].addrStart - 1 && callback.m_Params.addrEnd <= info.rangeCache[i].addrEnd)) { info.rangeCache[i].addrStart = min(info.rangeCache[i].addrStart, callback.m_Params.addrStart); info.rangeCache[i].addrEnd = max(info.rangeCache[i].addrEnd, callback.m_Params.addrEnd); diff --git a/Source/Project64/UserInterface/Debugger/ScriptSystem.h b/Source/Project64/UserInterface/Debugger/ScriptSystem.h index e869f8378..a95613e35 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptSystem.h +++ b/Source/Project64/UserInterface/Debugger/ScriptSystem.h @@ -1,6 +1,6 @@ -#include #include #include +#include #include "ScriptTypes.h" #include "debugger.h" @@ -12,49 +12,53 @@ class CScriptSystem { - typedef std::map JSInstanceMap; + typedef std::map JSInstanceMap; typedef std::vector JSAppCallbackList; typedef std::map JSInstanceStatusMap; typedef std::vector JSSysCommandQueue; - enum { JS_CPU_CB_RANGE_CACHE_SIZE = 256 }; + enum + { + JS_CPU_CB_RANGE_CACHE_SIZE = 256 + }; struct JSCpuCbListInfo { - size_t numCallbacks; + size_t numCallbacks; uint32_t minAddrStart; uint32_t maxAddrEnd; - size_t numRangeCacheEntries; - bool bRangeCacheExceeded; - struct { + size_t numRangeCacheEntries; + bool bRangeCacheExceeded; + struct + { uint32_t addrStart; uint32_t addrEnd; } rangeCache[JS_CPU_CB_RANGE_CACHE_SIZE]; }; - HANDLE m_hThread; + HANDLE m_hThread; - CriticalSection m_CmdQueueCS; - JSSysCommandQueue m_CmdQueue; - HANDLE m_hCmdEvent; + CriticalSection m_CmdQueueCS; + JSSysCommandQueue m_CmdQueue; + HANDLE m_hCmdEvent; std::set m_StopsIssued; - CriticalSection m_InstancesCS; - JSInstanceMap m_Instances; - JSAppCallbackList m_AppCallbackHooks[JS_NUM_APP_HOOKS]; - JSAppCallbackID m_NextAppCallbackId; - - volatile size_t m_AppCallbackCount; + CriticalSection m_InstancesCS; + JSInstanceMap m_Instances; + JSAppCallbackList m_AppCallbackHooks[JS_NUM_APP_HOOKS]; + JSAppCallbackID m_NextAppCallbackId; + + volatile size_t m_AppCallbackCount; volatile JSCpuCbListInfo m_CpuExecCbInfo; volatile JSCpuCbListInfo m_CpuReadCbInfo; volatile JSCpuCbListInfo m_CpuWriteCbInfo; - - CriticalSection m_UIStateCS; - JSInstanceStatusMap m_UIInstanceStatus; - stdstr m_UILog; - CDebuggerUI* m_Debugger; + CriticalSection m_UIStateCS; + JSInstanceStatusMap m_UIInstanceStatus; + stdstr m_UILog; + + CDebuggerUI * m_Debugger; std::set m_AutorunList; @@ -63,35 +67,38 @@ class CScriptSystem stdstr m_ModulesDirFullPath; public: - CScriptSystem(CDebuggerUI* debugger); + CScriptSystem(CDebuggerUI * debugger); ~CScriptSystem(); - CDebuggerUI* Debugger(); + CDebuggerUI * Debugger(); - void StartScript(const char* instanceName, const char* path); - void StopScript(const char* instanceName); - void Input(const char* instanceName, const char* code); + void StartScript(const char * instanceName, const char * path); + void StopScript(const char * instanceName); + void Input(const char * instanceName, const char * code); stdstr InstallDirPath(); stdstr ScriptsDirPath(); stdstr ModulesDirPath(); - - JSInstanceStatus GetStatus(const char* instanceName); - void NotifyStatus(const char* instanceName, JSInstanceStatus status); - void ConsoleLog(const char* format, ...); - void ConsolePrint(const char* format, ...); + + JSInstanceStatus GetStatus(const char * instanceName); + void NotifyStatus(const char * instanceName, JSInstanceStatus status); + void ConsoleLog(const char * format, ...); + void ConsolePrint(const char * format, ...); void ConsoleClear(); stdstr GetConsoleBuffer(); - void PostCMethodCall(const char* instanceName, void* dukThisHeapPtr, duk_c_function func, - JSDukArgSetupFunc argSetupFunc = nullptr, - void* argSetupParam = nullptr, - size_t argSetupParamSize = 0); + void PostCMethodCall(const char * instanceName, void * dukThisHeapPtr, duk_c_function func, + JSDukArgSetupFunc argSetupFunc = nullptr, + void * argSetupParam = nullptr, + size_t argSetupParamSize = 0); bool HaveAppCallbacks(JSAppHookID hookId); // Note: Unguarded for speed, shouldn't matter - inline bool HaveAppCallbacks() { return m_AppCallbackCount != 0; } + inline bool HaveAppCallbacks() + { + return m_AppCallbackCount != 0; + } inline bool HaveCpuExecCallbacks(uint32_t address) { @@ -107,22 +114,22 @@ public: { return HaveCpuCallbacks(m_CpuWriteCbInfo, m_AppCallbackHooks[JS_HOOK_CPU_WRITE], address); } - - static void UpdateCpuCbListInfo(volatile JSCpuCbListInfo& info, JSAppCallbackList& callbacks); + + static void UpdateCpuCbListInfo(volatile JSCpuCbListInfo & info, JSAppCallbackList & callbacks); void DoMouseEvent(JSAppHookID hookId, int x, int y, DWORD uMsg = (DWORD)-1); - void InvokeAppCallbacks(JSAppHookID hookId, void* env = nullptr); + void InvokeAppCallbacks(JSAppHookID hookId, void * env = nullptr); void ExecAutorunList(); - std::set& AutorunList(); + std::set & AutorunList(); void LoadAutorunList(); void SaveAutorunList(); - JSAppCallbackID RawAddAppCallback(JSAppHookID hookId, JSAppCallback& callback); + JSAppCallbackID RawAddAppCallback(JSAppHookID hookId, JSAppCallback & callback); void RawRemoveAppCallback(JSAppHookID hookId, JSAppCallbackID callbackId); private: - inline bool HaveCpuCallbacks(volatile JSCpuCbListInfo& info, JSAppCallbackList& callbacks, uint32_t address) + inline bool HaveCpuCallbacks(volatile JSCpuCbListInfo & info, JSAppCallbackList & callbacks, uint32_t address) { if (info.numCallbacks == 0 || address < info.minAddrStart || address > info.maxAddrEnd) { @@ -133,8 +140,7 @@ private: { for (size_t i = 0; i < info.numRangeCacheEntries; i++) { - if (address >= info.rangeCache[i].addrStart && - address <= info.rangeCache[i].addrEnd) + if (address >= info.rangeCache[i].addrStart && address <= info.rangeCache[i].addrEnd) { return true; } @@ -145,10 +151,9 @@ private: CGuard guard(m_InstancesCS); - for (JSAppCallback& callback : callbacks) + for (JSAppCallback & callback : callbacks) { - if (address >= callback.m_Params.addrStart && - address <= callback.m_Params.addrEnd) + if (address >= callback.m_Params.addrStart && address <= callback.m_Params.addrEnd) { return true; } @@ -159,23 +164,23 @@ private: void InitDirectories(); - void PostCommand(JSSysCommandID id, stdstr paramA = "", stdstr paramB = "", void* paramC = nullptr); + void PostCommand(JSSysCommandID id, stdstr paramA = "", stdstr paramB = "", void * paramC = nullptr); - static DWORD WINAPI ThreadProc(void* _this); + static DWORD WINAPI ThreadProc(void * _this); void ThreadProc(); - bool ProcessCommand(JSSysCommand& cmd); - bool ProcessCommandQueue(std::vector& queue); - void PullCommands(JSSysCommandID id, std::vector& out); + bool ProcessCommand(JSSysCommand & cmd); + bool ProcessCommandQueue(std::vector & queue); + void PullCommands(JSSysCommandID id, std::vector & out); - void OnStartScript(const char* name, const char* path); - void OnStopScript(const char* name); - void OnInput(const char* name, const char* code); - void OnCMethodCall(const char* name, JSSysCMethodCall* methodCall); + void OnStartScript(const char * name, const char * path); + void OnStopScript(const char * name); + void OnInput(const char * name, const char * code); + void OnCMethodCall(const char * name, JSSysCMethodCall * methodCall); void OnSweep(bool bIfDone); - bool RawRemoveInstance(const char* key); + bool RawRemoveInstance(const char * key); void RefreshCallbackMaps(); - static stdstr FixStringReturns(const char* str); + static stdstr FixStringReturns(const char * str); }; diff --git a/Source/Project64/UserInterface/Debugger/ScriptTypes.h b/Source/Project64/UserInterface/Debugger/ScriptTypes.h index e3e30cbb0..b656b204d 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptTypes.h +++ b/Source/Project64/UserInterface/Debugger/ScriptTypes.h @@ -1,5 +1,5 @@ -#include <3rdparty/duktape/duktape.h> #include <3rdparty/duktape/duk_module_duktape.h> +#include <3rdparty/duktape/duktape.h> #include #include @@ -66,9 +66,9 @@ class CScriptInstance; typedef std::string JSInstanceName; struct JSAppCallback; -typedef duk_idx_t (*JSDukArgSetupFunc)(duk_context *ctx, void *argSetupParam); -typedef bool (*JSAppCallbackCondFunc)(JSAppCallback* cb, void* hookEnv); -typedef void (*JSAppCallbackCleanupFunc)(duk_context* ctx, void *hookEnv); +typedef duk_idx_t (*JSDukArgSetupFunc)(duk_context * ctx, void * argSetupParam); +typedef bool (*JSAppCallbackCondFunc)(JSAppCallback * cb, void * hookEnv); +typedef void (*JSAppCallbackCleanupFunc)(duk_context * ctx, void * hookEnv); typedef size_t JSAppCallbackID; #define JS_INVALID_CALLBACK ((JSAppCallbackID)(-1)) @@ -76,26 +76,37 @@ typedef size_t JSAppCallbackID; struct JSAppCallback { // assigned by scriptsys when this is added to a callback map - JSAppCallbackID m_CallbackId; - bool m_bDisabled; + JSAppCallbackID m_CallbackId; + bool m_bDisabled; - CScriptInstance *m_Instance; - void *m_DukFuncHeapPtr; - JSAppCallbackCondFunc m_ConditionFunc; - JSDukArgSetupFunc m_DukArgSetupFunc; + CScriptInstance * m_Instance; + void * m_DukFuncHeapPtr; + JSAppCallbackCondFunc m_ConditionFunc; + JSDukArgSetupFunc m_DukArgSetupFunc; JSAppCallbackCleanupFunc m_CleanupFunc; - struct { + struct + { uint32_t addrStart, addrEnd; - union { - struct { uint32_t opcode, opcodeMask; }; - struct { uint32_t regIndices, regValue; }; + union + { + struct + { + uint32_t opcode, opcodeMask; + }; + struct + { + uint32_t regIndices, regValue; + }; }; } m_Params; - static bool CbCondTrue(JSAppCallback*, void*) { return true; } + static bool CbCondTrue(JSAppCallback *, void *) + { + return true; + } - JSAppCallback(CScriptInstance* instance, void* dukFuncHeapPtr, + JSAppCallback(CScriptInstance * instance, void * dukFuncHeapPtr, JSAppCallbackCondFunc condFunc = nullptr, JSDukArgSetupFunc argSetupFunc = nullptr, JSAppCallbackCleanupFunc cleanupFunc = nullptr) : @@ -135,9 +146,9 @@ struct JSAppCallback struct JSHookCpuStepEnv { - uint32_t pc; - COpInfo opInfo; - int outAffectedRegIndex; // set by the condition function + uint32_t pc; + COpInfo opInfo; + int outAffectedRegIndex; // set by the condition function }; struct JSHookMouseEnv @@ -168,7 +179,7 @@ struct JSHookSpTaskEnv struct JSHookPiDmaEnv { - int direction; + int direction; uint32_t dramAddress; uint32_t cartAddress; uint32_t length; @@ -182,21 +193,21 @@ struct JSHookEmuStateChangeEnv struct JSSysCommand { JSSysCommandID id; - stdstr paramA; - stdstr paramB; - void* paramC; + stdstr paramA; + stdstr paramB; + void * paramC; }; struct JSSysCMethodCall { - void* m_DukThisHeapPtr; - duk_c_function m_Func; - JSDukArgSetupFunc m_ArgSetupFunc; - void* m_ArgSetupParam; + void * m_DukThisHeapPtr; + duk_c_function m_Func; + JSDukArgSetupFunc m_ArgSetupFunc; + void * m_ArgSetupParam; - JSSysCMethodCall(void* dukThisHeapPtr, duk_c_function func, + JSSysCMethodCall(void * dukThisHeapPtr, duk_c_function func, JSDukArgSetupFunc argSetupFunc = nullptr, - void* argSetupParam = nullptr, + void * argSetupParam = nullptr, size_t argSetupParamSize = 0) : m_DukThisHeapPtr(dukThisHeapPtr), m_Func(func), @@ -205,7 +216,7 @@ struct JSSysCMethodCall { if (argSetupParam != nullptr && argSetupParamSize != 0) { - m_ArgSetupParam = (void*)(new char[argSetupParamSize]); + m_ArgSetupParam = (void *)(new char[argSetupParamSize]); memcpy(m_ArgSetupParam, argSetupParam, argSetupParamSize); } } @@ -214,7 +225,7 @@ struct JSSysCMethodCall { if (m_ArgSetupParam != nullptr) { - delete[](char*)m_ArgSetupParam; + delete[](char *) m_ArgSetupParam; } } }; diff --git a/Source/Project64/UserInterface/Debugger/ScriptWorker.h b/Source/Project64/UserInterface/Debugger/ScriptWorker.h index 8224b74da..fa551807a 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptWorker.h +++ b/Source/Project64/UserInterface/Debugger/ScriptWorker.h @@ -8,19 +8,19 @@ class CScriptWorker private: bool m_bStopping; bool m_bRegistered; - static DWORD WINAPI ThreadProc(void* _this); + static DWORD WINAPI ThreadProc(void * _this); public: - CScriptWorker(CScriptInstance* instance, void* dukObjectHeapPtr); + CScriptWorker(CScriptInstance * instance, void * dukObjectHeapPtr); virtual ~CScriptWorker(); void StartWorkerProc(); virtual void StopWorkerProc(); protected: - CScriptInstance* m_Instance; - void* m_DukObjectHeapPtr; - CriticalSection m_CS; - HANDLE m_hThread; + CScriptInstance * m_Instance; + void * m_DukObjectHeapPtr; + CriticalSection m_CS; + HANDLE m_hThread; // Implementation should return when StopRequested() is true virtual void WorkerProc() = 0; diff --git a/Source/Project64/UserInterface/Debugger/Symbols.cpp b/Source/Project64/UserInterface/Debugger/Symbols.cpp index f4f1efa7b..b7ad50ab2 100644 --- a/Source/Project64/UserInterface/Debugger/Symbols.cpp +++ b/Source/Project64/UserInterface/Debugger/Symbols.cpp @@ -38,7 +38,7 @@ symbol_type_info_t CSymbolTable::m_SymbolTypes[] = { {SYM_VECTOR2, "v2", 8}, {SYM_VECTOR3, "v3", 12}, {SYM_VECTOR4, "v4", 16}, - { SYM_INVALID, nullptr, 0 } + {SYM_INVALID, nullptr, 0}, }; symbol_type_id_t CSymbolTable::GetTypeId(char * typeName) diff --git a/Source/Project64/UserInterface/Debugger/Symbols.h b/Source/Project64/UserInterface/Debugger/Symbols.h index 61104dec4..3845edc5e 100644 --- a/Source/Project64/UserInterface/Debugger/Symbols.h +++ b/Source/Project64/UserInterface/Debugger/Symbols.h @@ -2,7 +2,8 @@ class CSymbol; -typedef enum { +typedef enum +{ SYM_INVALID = -1, SYM_CODE, SYM_DATA, @@ -24,12 +25,13 @@ typedef enum { typedef struct { - symbol_type_id_t id; - const char* name; - int size; + symbol_type_id_t id; + const char * name; + int size; } symbol_type_info_t; -typedef enum { +typedef enum +{ ERR_SUCCESS, ERR_INVALID_TYPE, ERR_INVALID_ADDR, @@ -40,62 +42,63 @@ typedef enum { class CSymbolTable { public: - CSymbolTable(CDebuggerUI* debugger); + CSymbolTable(CDebuggerUI * debugger); ~CSymbolTable(); private: CSymbolTable(); - CDebuggerUI* m_Debugger; + CDebuggerUI * m_Debugger; CriticalSection m_CS; std::vector m_Symbols; std::map m_AddressMap; // address -> symbol index - int m_NextSymbolId; + int m_NextSymbolId; - CFile m_SymFileHandle; - char* m_SymFileBuffer; + CFile m_SymFileHandle; + char * m_SymFileBuffer; size_t m_SymFileSize; - char* m_ParserToken; + char * m_ParserToken; size_t m_ParserTokenLength; - char* m_TokPos; - char m_ParserDelimeter; - char* m_SymFileParseBuffer; - bool m_bHaveFirstToken; + char * m_TokPos; + char m_ParserDelimeter; + char * m_SymFileParseBuffer; + bool m_bHaveFirstToken; - void ParserFetchToken(const char* delim); + void ParserFetchToken(const char * delim); void UpdateAddressMap(); public: static symbol_type_info_t m_SymbolTypes[]; - static const char* GetTypeName(int typeId); + static const char * GetTypeName(int typeId); static int GetTypeSize(int typeId); - static symbol_type_id_t GetTypeId(char* typeName); - static bool CmpSymbolAddresses(CSymbol& a, CSymbol& b); + static symbol_type_id_t GetTypeId(char * typeName); + static bool CmpSymbolAddresses(CSymbol & a, CSymbol & b); - void GetValueString(char* dst, CSymbol* symbol); + void GetValueString(char * dst, CSymbol * symbol); CPath GetSymFilePath(); void Load(); void Save(); - void ParseErrorAlert(char* message, int lineNumber); + void ParseErrorAlert(char * message, int lineNumber); - void AddSymbol(int type, uint32_t address, const char* name, const char* description = nullptr, bool bSortAfter = true); + void AddSymbol(int type, uint32_t address, const char * name, const char * description = nullptr, bool bSortAfter = true); void Reset(); - int GetCount(); - bool GetSymbolById(int id, CSymbol* symbol); - bool GetSymbolByIndex(size_t index, CSymbol* symbol); - bool GetSymbolByAddress(uint32_t address, CSymbol* symbol); + int GetCount(); + bool GetSymbolById(int id, CSymbol * symbol); + bool GetSymbolByIndex(size_t index, CSymbol * symbol); + bool GetSymbolByAddress(uint32_t address, CSymbol * symbol); bool RemoveSymbolById(int id); }; -class CSymbol { +class CSymbol +{ public: - int m_Id; - int m_Type; + int m_Id; + int m_Type; uint32_t m_Address; - char* m_Name; - char* m_Description; + char * m_Name; + char * m_Description; CSymbol() : m_Id(0), @@ -106,7 +109,7 @@ public: { } - CSymbol(int id, int type, uint32_t address, const char* name, const char* description) : + CSymbol(int id, int type, uint32_t address, const char * name, const char * description) : m_Id(id), m_Type(type), m_Address(address), @@ -124,7 +127,7 @@ public: } } - CSymbol(const CSymbol& symbol): + CSymbol(const CSymbol & symbol) : m_Id(symbol.m_Id), m_Type(symbol.m_Type), m_Address(symbol.m_Address), @@ -135,7 +138,7 @@ public: m_Description = symbol.m_Description ? _strdup(symbol.m_Description) : nullptr; } - CSymbol& operator= (const CSymbol& symbol) + CSymbol & operator=(const CSymbol & symbol) { if (m_Name != nullptr) { @@ -168,7 +171,7 @@ public: } } - const char* TypeName() + const char * TypeName() { return CSymbolTable::GetTypeName(m_Type); } diff --git a/Source/Project64/UserInterface/Debugger/debugger.h b/Source/Project64/UserInterface/Debugger/debugger.h index 5d3ffa30e..ef8bd0105 100644 --- a/Source/Project64/UserInterface/Debugger/debugger.h +++ b/Source/Project64/UserInterface/Debugger/debugger.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include #include "DebugMMU.h" +#include +#include +#include class CDumpMemory; class CDebugMemoryView; @@ -43,7 +43,7 @@ public: void OpenCommandWindow(void); void Debug_ShowCommandsLocation(uint32_t address, bool top); void OpenScriptsWindow(void); - void Debug_LogScriptsWindow(const char* text); + void Debug_LogScriptsWindow(const char * text); void Debug_ClearScriptsWindow(void); void Debug_RefreshScriptsWindow(void); void Debug_RefreshSymbolsWindow(void); @@ -71,14 +71,14 @@ public: bool WriteBP64(uint32_t address); void WaitForStep(void); - CBreakpoints* Breakpoints(); - CDebugSymbols* Symbols(); - CScriptSystem* ScriptSystem(); - CDebugScripts* ScriptConsole(); - CDMALog* DMALog(); - CCPULog* CPULog(); - CSymbolTable* SymbolTable(); - SyncEvent& StepEvent(); + CBreakpoints * Breakpoints(); + CDebugSymbols * Symbols(); + CScriptSystem * ScriptSystem(); + CDebugScripts * ScriptConsole(); + CDMALog * DMALog(); + CCPULog * CPULog(); + CSymbolTable * SymbolTable(); + SyncEvent & StepEvent(); static void GameReset(CDebuggerUI * _this); static void GameCpuRunningChanged(CDebuggerUI * _this); @@ -101,27 +101,27 @@ protected: void EmulationStopped(void); private: - CDebuggerUI(const CDebuggerUI&); - CDebuggerUI& operator=(const CDebuggerUI&); + CDebuggerUI(const CDebuggerUI &); + CDebuggerUI & operator=(const CDebuggerUI &); - CDumpMemory * m_MemoryDump; - CDebugMemoryView * m_MemoryView; - CDebugMemorySearch * m_MemorySearch; - CDebugTlb * m_DebugTLB; - CDebugCommandsView * m_CommandsView; - CDebugScripts * m_Scripts; - CDebugSymbols * m_Symbols; - CDebugDMALogView * m_DMALogView; - CDebugCPULogView * m_CPULogView; - CDebugStackTrace * m_StackTrace; - CDebugStackView * m_StackView; + CDumpMemory * m_MemoryDump; + CDebugMemoryView * m_MemoryView; + CDebugMemorySearch * m_MemorySearch; + CDebugTlb * m_DebugTLB; + CDebugCommandsView * m_CommandsView; + CDebugScripts * m_Scripts; + CDebugSymbols * m_Symbols; + CDebugDMALogView * m_DMALogView; + CDebugCPULogView * m_CPULogView; + CDebugStackTrace * m_StackTrace; + CDebugStackView * m_StackView; CDebugExcBreakpoints * m_ExcBreakpoints; - CBreakpoints * m_Breakpoints; - CScriptSystem * m_ScriptSystem; - CSymbolTable * m_SymbolTable; - CDMALog * m_DMALog; - CCPULog * m_CPULog; + CBreakpoints * m_Breakpoints; + CScriptSystem * m_ScriptSystem; + CSymbolTable * m_SymbolTable; + CDMALog * m_DMALog; + CCPULog * m_CPULog; SyncEvent m_StepEvent; diff --git a/Source/Project64/UserInterface/DiscordRPC.h b/Source/Project64/UserInterface/DiscordRPC.h index 43d65bedf..ccc08b7c9 100644 --- a/Source/Project64/UserInterface/DiscordRPC.h +++ b/Source/Project64/UserInterface/DiscordRPC.h @@ -4,10 +4,10 @@ class CDiscord { private: - static int64_t Timestamp(void); + static int64_t Timestamp(void); public: - static void Init(void); - static void Shutdown(void); - static void Update(bool bHaveGame = true); + static void Init(void); + static void Shutdown(void); + static void Update(bool bHaveGame = true); }; diff --git a/Source/Project64/UserInterface/EnhancementUI.cpp b/Source/Project64/UserInterface/EnhancementUI.cpp index 32b2db5aa..31e5c1ff3 100644 --- a/Source/Project64/UserInterface/EnhancementUI.cpp +++ b/Source/Project64/UserInterface/EnhancementUI.cpp @@ -1,36 +1,41 @@ #include "stdafx.h" -#include #include +#include class CEditEnhancement : - public CDialogImpl < CEditEnhancement > + public CDialogImpl { public: BEGIN_MSG_MAP_EX(CEditEnhancement) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_HANDLER_EX(IDC_GAMESHARK, BN_CLICKED, OnGamesharkBtn) - COMMAND_HANDLER_EX(IDC_OVERCLOCK, BN_CLICKED, OnOverClockBtn) - COMMAND_ID_HANDLER(IDC_BTN_GAMESHARK, OnEditGameshark) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_HANDLER_EX(IDC_GAMESHARK, BN_CLICKED, OnGamesharkBtn); + COMMAND_HANDLER_EX(IDC_OVERCLOCK, BN_CLICKED, OnOverClockBtn); + COMMAND_ID_HANDLER(IDC_BTN_GAMESHARK, OnEditGameshark); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + } END_MSG_MAP() - enum { IDD = IDD_Enhancement_Edit }; + enum + { + IDD = IDD_Enhancement_Edit + }; CEditEnhancement(CEnhancementUI & EnhancementUI, CEnhancement * Enhancement); private: CEditEnhancement(void); - CEditEnhancement(const CEditEnhancement&); - CEditEnhancement& operator=(const CEditEnhancement&); + CEditEnhancement(const CEditEnhancement &); + CEditEnhancement & operator=(const CEditEnhancement &); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnGamesharkBtn(UINT Code, int id, HWND ctl); LRESULT OnOverClockBtn(UINT Code, int id, HWND ctl); - LRESULT OnEditGameshark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnEditGameshark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); CEnhancementUI & m_EnhancementUI; CEnhancement::CodeEntries m_Entries; @@ -43,26 +48,31 @@ class CEditGS : { public: BEGIN_MSG_MAP_EX(CEditGS) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_HANDLER(IDC_CHEAT_CODES, EN_CHANGE, OnCheatChanged) - COMMAND_HANDLER_EX(IDC_CHK_LIMIT_PLUGINS, BN_CLICKED, OnPluginBtn) - COMMAND_ID_HANDLER(IDC_BTN_PLUGIN, OnEditPlugins) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_HANDLER(IDC_CHEAT_CODES, EN_CHANGE, OnCheatChanged); + COMMAND_HANDLER_EX(IDC_CHK_LIMIT_PLUGINS, BN_CLICKED, OnPluginBtn); + COMMAND_ID_HANDLER(IDC_BTN_PLUGIN, OnEditPlugins); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + } END_MSG_MAP() - enum { IDD = IDD_Enhancement_GS }; + enum + { + IDD = IDD_Enhancement_GS + }; CEditGS(CEnhancement::CodeEntries & Entries, CEnhancement::PluginList & PluginList); private: CEditGS(); - CEditGS(const CEditGS&); - CEditGS& operator=(const CEditGS&); + CEditGS(const CEditGS &); + CEditGS & operator=(const CEditGS &); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnPluginBtn(UINT Code, int id, HWND ctl); - LRESULT OnEditPlugins(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnEditPlugins(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnCheatChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); @@ -78,28 +88,33 @@ class CEditPluginList : { public: BEGIN_MSG_MAP_EX(CEditPluginList) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_ID_HANDLER(IDC_ADD, OnAddBtn) - COMMAND_ID_HANDLER(IDC_REMOVE, OnRemoveBtn) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_ID_HANDLER(IDC_ADD, OnAddBtn); + COMMAND_ID_HANDLER(IDC_REMOVE, OnRemoveBtn); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + } END_MSG_MAP() - enum { IDD = IDD_Enhancement_Plugins }; + enum + { + IDD = IDD_Enhancement_Plugins + }; CEditPluginList(CEnhancement::PluginList & List); private: CEditPluginList(); - CEditPluginList(const CEditPluginList&); - CEditPluginList& operator=(const CEditPluginList&); + CEditPluginList(const CEditPluginList &); + CEditPluginList & operator=(const CEditPluginList &); - LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); - LRESULT OnAddBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); - LRESULT OnRemoveBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnAddBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); + LRESULT OnRemoveBtn(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); - + CListBox m_PluginListBox; CEnhancement::PluginList & m_PluginList; }; @@ -132,7 +147,7 @@ void CEnhancementUI::Display(HWND hParent, bool BlockExecution) } } -LRESULT CEnhancementUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CEnhancementUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { SetWindowText(wGS(ENHANCEMENT_TITLE).c_str()); @@ -157,7 +172,7 @@ LRESULT CEnhancementUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /* int32_t X = (((rcParent.Width()) - DlgWidth) / 2) + rcParent.left; int32_t Y = (((rcParent.Height()) - DlgHeight) / 2) + rcParent.top; SetWindowPos(nullptr, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - + RefreshList(); ShowWindow(SW_SHOW); return TRUE; @@ -169,7 +184,7 @@ LRESULT CEnhancementUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPa return 0; } -LRESULT CEnhancementUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEnhancementUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { if (g_BaseSystem) { @@ -186,9 +201,9 @@ LRESULT CEnhancementUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hW return TRUE; } -LRESULT CEnhancementUI::OnEditEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEnhancementUI::OnEditEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { - TVITEM item = { 0 }; + TVITEM item = {0}; item.mask = TVIF_PARAM; item.hItem = m_hSelectedItem; if (!m_TreeList.GetItem(&item) || item.lParam == NULL) @@ -200,17 +215,17 @@ LRESULT CEnhancementUI::OnEditEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HW return TRUE; } -LRESULT CEnhancementUI::OnAddEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEnhancementUI::OnAddEnhancement(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { CEditEnhancement(*this, nullptr).DoModal(m_hWnd); RefreshList(); return TRUE; } -LRESULT CEnhancementUI::OnEnhancementListClicked(NMHDR* lpnmh) +LRESULT CEnhancementUI::OnEnhancementListClicked(NMHDR * lpnmh) { uint32_t dwpos = GetMessagePos(); - TVHITTESTINFO ht = { 0 }; + TVHITTESTINFO ht = {0}; ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos); ::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1); @@ -248,7 +263,7 @@ LRESULT CEnhancementUI::OnEnhancementListClicked(NMHDR* lpnmh) return 0; } -LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled) { int Response = MessageBox(wGS(MSG_DEL_SURE).c_str(), wGS(MSG_DEL_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION); if (Response != IDYES) @@ -256,7 +271,7 @@ LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, return 0; } - TVITEM item = { 0 }; + TVITEM item = {0}; item.hItem = m_hSelectedItem; item.mask = TVIF_PARAM; m_TreeList.GetItem(&item); @@ -276,9 +291,9 @@ LRESULT CEnhancementUI::OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, return 0; } -LRESULT CEnhancementUI::OnEnhancementListRClicked(NMHDR* pNMHDR) +LRESULT CEnhancementUI::OnEnhancementListRClicked(NMHDR * pNMHDR) { - TVHITTESTINFO ht = { 0 }; + TVHITTESTINFO ht = {0}; uint32_t dwpos = GetMessagePos(); ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos); @@ -307,7 +322,7 @@ LRESULT CEnhancementUI::OnEnhancementListRClicked(NMHDR* pNMHDR) LRESULT CEnhancementUI::OnEnhancementListDClicked(NMHDR * lpnmh) { uint32_t dwpos = GetMessagePos(); - TVHITTESTINFO ht = { 0 }; + TVHITTESTINFO ht = {0}; ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos); ::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1); @@ -318,7 +333,7 @@ LRESULT CEnhancementUI::OnEnhancementListDClicked(NMHDR * lpnmh) { return 0; } - TVITEM item = { 0 }; + TVITEM item = {0}; item.mask = TVIF_PARAM; item.hItem = (HTREEITEM)ht.hItem; if (!m_TreeList.GetItem(&item) || item.lParam == NULL) @@ -337,7 +352,7 @@ LRESULT CEnhancementUI::OnEnhancementListSelChanged(NMHDR * /*lpnmh*/) GetDlgItem(IDC_NOTES).SetWindowText(L""); if (m_TreeList.GetChildItem(hItem) == nullptr) { - TVITEM item = { 0 }; + TVITEM item = {0}; item.mask = TVIF_PARAM; item.hItem = hItem; m_TreeList.GetItem(&item); @@ -355,9 +370,15 @@ void CEnhancementUI::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name TV_INSERTSTRUCT tv; wchar_t Text[500], Item[500]; - if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5)) { g_Notify->BreakPoint(__FILE__, __LINE__); } + if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5)) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } wcscpy(Text, Name.c_str()); - if (wcschr(Text, L'\\') > 0) { *wcschr(Text, L'\\') = 0; } + if (wcschr(Text, L'\\') > 0) + { + *wcschr(Text, L'\\') = 0; + } tv.item.mask = TVIF_TEXT; tv.item.pszText = Item; @@ -393,18 +414,25 @@ void CEnhancementUI::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name hParent = m_TreeList.InsertItem(&tv); TV_SetCheckState(hParent, Active ? TV_STATE_CHECKED : TV_STATE_CLEAR); - if (wcscmp(Text, Name.c_str()) == 0) { return; } + if (wcscmp(Text, Name.c_str()) == 0) + { + return; + } AddCodeLayers(Enhancement, Name.substr(wcslen(Text) + 1), hParent, Active); } void CEnhancementUI::ChangeChildrenStatus(HTREEITEM hParent, bool Checked) { - HTREEITEM hItem = m_TreeList.GetChildItem(hParent);; + HTREEITEM hItem = m_TreeList.GetChildItem(hParent); + ; if (hItem == nullptr) { - if (hParent == TVI_ROOT) { return; } + if (hParent == TVI_ROOT) + { + return; + } - TVITEM item = { 0 }; + TVITEM item = {0}; item.mask = TVIF_PARAM; item.hItem = hParent; m_TreeList.GetItem(&item); @@ -430,14 +458,19 @@ void CEnhancementUI::ChangeChildrenStatus(HTREEITEM hParent, bool Checked) while (hItem != nullptr) { TV_CHECK_STATE ChildState = TV_GetCheckState(hItem); - if ((ChildState != TV_STATE_CHECKED || !Checked) && - (ChildState != TV_STATE_CLEAR || Checked)) + if ((ChildState != TV_STATE_CHECKED || !Checked) && (ChildState != TV_STATE_CLEAR || Checked)) { ChangeChildrenStatus(hItem, Checked); } ChildState = TV_GetCheckState(hItem); - if (state == TV_STATE_UNKNOWN) { state = ChildState; } - if (state != ChildState) { state = TV_STATE_INDETERMINATE; } + if (state == TV_STATE_UNKNOWN) + { + state = ChildState; + } + if (state != ChildState) + { + state = TV_STATE_INDETERMINATE; + } hItem = m_TreeList.GetNextSiblingItem(hItem); } if (state != TV_STATE_UNKNOWN) @@ -487,7 +520,7 @@ void CEnhancementUI::RefreshList() CEnhancementUI::TV_CHECK_STATE CEnhancementUI::TV_GetCheckState(HTREEITEM hItem) { - TVITEM tvItem = { 0 }; + TVITEM tvItem = {0}; tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = hItem; tvItem.stateMask = TVIS_STATEIMAGEMASK; @@ -505,7 +538,7 @@ CEnhancementUI::TV_CHECK_STATE CEnhancementUI::TV_GetCheckState(HTREEITEM hItem) bool CEnhancementUI::TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state) { - TVITEM tvItem = { 0 }; + TVITEM tvItem = {0}; tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = (HTREEITEM)hItem; tvItem.stateMask = TVIS_STATEIMAGEMASK; @@ -526,7 +559,7 @@ CEditEnhancement::CEditEnhancement(CEnhancementUI & EnhancementUI, CEnhancement { } -LRESULT CEditEnhancement::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CEditEnhancement::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { m_Entries = m_EditEnhancement != nullptr ? m_EditEnhancement->GetEntries() : CEnhancement::CodeEntries(); m_PluginList = m_EditEnhancement != nullptr ? m_EditEnhancement->GetPluginList() : CEnhancement::PluginList(); @@ -536,7 +569,7 @@ LRESULT CEditEnhancement::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM CButton(GetDlgItem(IDC_AUTOON)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->GetOnByDefault() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED); CButton(GetDlgItem(IDC_GAMESHARK)).SetCheck(m_Entries.size() > 0 ? BST_CHECKED : BST_UNCHECKED); CButton(GetDlgItem(IDC_OVERCLOCK)).SetCheck(m_EditEnhancement != nullptr ? (m_EditEnhancement->OverClock() ? BST_CHECKED : BST_UNCHECKED) : BST_UNCHECKED); - GetDlgItem(IDC_OVER_CLOCK_MODIFIER).SetWindowText(m_EditEnhancement != nullptr ? stdstr_f("%d",m_EditEnhancement->OverClockModifier()).ToUTF16().c_str() : L"1"); + GetDlgItem(IDC_OVER_CLOCK_MODIFIER).SetWindowText(m_EditEnhancement != nullptr ? stdstr_f("%d", m_EditEnhancement->OverClockModifier()).ToUTF16().c_str() : L"1"); GetDlgItem(IDC_OVER_CLOCK_MODIFIER).EnableWindow(m_EditEnhancement != nullptr ? m_EditEnhancement->OverClock() : false); return TRUE; @@ -556,19 +589,19 @@ LRESULT CEditEnhancement::OnOverClockBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/ return 0; } -LRESULT CEditEnhancement::OnEditGameshark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditEnhancement::OnEditGameshark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { OnGamesharkBtn(0, 0, 0); return TRUE; } -LRESULT CEditEnhancement::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditEnhancement::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { EndDialog(wID); return TRUE; } -LRESULT CEditEnhancement::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditEnhancement::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { CEnhancement TempEnhancement(CEnhancement::EnhancementIdent); CEnhancement & Enhancement = m_EditEnhancement != nullptr ? *m_EditEnhancement : TempEnhancement; @@ -597,7 +630,7 @@ CEditGS::CEditGS(CEnhancement::CodeEntries & Entries, CEnhancement::PluginList & { } -LRESULT CEditGS::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CEditGS::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { stdstr Buffer; for (size_t i = 0, n = m_Entries.size(); i < n; i++) @@ -623,20 +656,20 @@ LRESULT CEditGS::OnPluginBtn(UINT /*Code*/, int /*id*/, HWND /*ctl*/) return 0; } -LRESULT CEditGS::OnEditPlugins(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditGS::OnEditPlugins(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { OnPluginBtn(0, 0, 0); return 0; } -LRESULT CEditGS::OnCheatChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditGS::OnCheatChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { CEnhancement::CodeEntries Entries; GetDlgItem(IDOK).EnableWindow(CheatCode(Entries)); return true; } -LRESULT CEditGS::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditGS::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { CEnhancement::CodeEntries Entries; if (CheatCode(Entries)) @@ -647,7 +680,7 @@ LRESULT CEditGS::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& return TRUE; } -LRESULT CEditGS::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CEditGS::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { EndDialog(wID); return TRUE; @@ -665,15 +698,18 @@ bool CEditGS::CheatCode(CEnhancement::CodeEntries & Entries) { const char * formatnormal = "XXXXXXXX XXXX"; - wchar_t wstr[128] = { 0 }; + wchar_t wstr[128] = {0}; *(LPWORD)wstr = sizeof(wstr) / sizeof(wstr[0]); uint32_t len = CheatCodes.GetLine(line, wstr); wstr[len] = 0; - if (len <= 0) { continue; } + if (len <= 0) + { + continue; + } std::string str = stdstr().FromUTF16(wstr); - char tempformat[128] = { 0 }; + char tempformat[128] = {0}; for (uint32_t i = 0; i < sizeof(tempformat); i++) { if (isxdigit(str[i])) @@ -684,7 +720,10 @@ bool CEditGS::CheatCode(CEnhancement::CodeEntries & Entries) { tempformat[i] = str[i]; } - if (str[i] == 0) { break; } + if (str[i] == 0) + { + break; + } } if (strcmp(tempformat, formatnormal) == 0) @@ -728,7 +767,7 @@ CEditPluginList::CEditPluginList(CEnhancement::PluginList & List) : { } -LRESULT CEditPluginList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) +LRESULT CEditPluginList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { m_PluginListBox.Attach(GetDlgItem(IDC_PLUGIN_LIST)); for (size_t i = 0, n = m_PluginList.size(); i < n; i++) @@ -740,7 +779,7 @@ LRESULT CEditPluginList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM / LRESULT CEditPluginList::OnAddBtn(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { - CWindow hEdit = GetDlgItem(IDC_ADD_EDIT); + CWindow hEdit = GetDlgItem(IDC_ADD_EDIT); stdstr PluginName = stdstr(GetCWindowText(hEdit)).Trim(); std::wstring wPluginName = PluginName.ToUTF16(); if (PluginName.empty()) diff --git a/Source/Project64/UserInterface/EnhancementUI.h b/Source/Project64/UserInterface/EnhancementUI.h index 9635d4cd0..b27a337fa 100644 --- a/Source/Project64/UserInterface/EnhancementUI.h +++ b/Source/Project64/UserInterface/EnhancementUI.h @@ -16,19 +16,24 @@ class CEnhancementUI : public: BEGIN_MSG_MAP_EX(CEnhancementUI) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_DESTROY, OnDestroy) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) - COMMAND_ID_HANDLER(ID_POPUP_EDIT, OnEditEnhancement) - COMMAND_ID_HANDLER(ID_POPUP_ADDENHANCEMENT, OnAddEnhancement) - COMMAND_ID_HANDLER(ID_POPUP_DELETE, OnPopupDelete) - NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_CLICK, OnEnhancementListClicked) - NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_RCLICK, OnEnhancementListRClicked) - NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_DBLCLK, OnEnhancementListDClicked) - NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, TVN_SELCHANGED, OnEnhancementListSelChanged) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_DESTROY, OnDestroy); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + COMMAND_ID_HANDLER(ID_POPUP_EDIT, OnEditEnhancement); + COMMAND_ID_HANDLER(ID_POPUP_ADDENHANCEMENT, OnAddEnhancement); + COMMAND_ID_HANDLER(ID_POPUP_DELETE, OnPopupDelete); + NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_CLICK, OnEnhancementListClicked); + NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_RCLICK, OnEnhancementListRClicked); + NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, NM_DBLCLK, OnEnhancementListDClicked); + NOTIFY_HANDLER_EX(IDC_ENHANCEMENTLIST, TVN_SELCHANGED, OnEnhancementListSelChanged); + } END_MSG_MAP() - enum { IDD = IDD_Enhancement_Config }; + enum + { + IDD = IDD_Enhancement_Config + }; CEnhancementUI(); @@ -37,15 +42,15 @@ public: private: friend CEditEnhancement; - CEnhancementUI(const CEnhancementUI&); - CEnhancementUI& operator=(const CEnhancementUI&); + CEnhancementUI(const CEnhancementUI &); + CEnhancementUI & operator=(const CEnhancementUI &); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); LRESULT OnEditEnhancement(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); - LRESULT OnAddEnhancement(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled ); + LRESULT OnAddEnhancement(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); - LRESULT OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); + LRESULT OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); LRESULT OnEnhancementListClicked(NMHDR * lpnmh); LRESULT OnEnhancementListRClicked(NMHDR * lpnmh); LRESULT OnEnhancementListDClicked(NMHDR * lpnmh); diff --git a/Source/Project64/UserInterface/LoggingUI.cpp b/Source/Project64/UserInterface/LoggingUI.cpp index e1ec75f22..c2124e708 100644 --- a/Source/Project64/UserInterface/LoggingUI.cpp +++ b/Source/Project64/UserInterface/LoggingUI.cpp @@ -61,18 +61,45 @@ LRESULT CALLBACK LogGeneralProc(HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM { case WM_INITDIALOG: { - if (CLogSettings::LogCP0changes()) { CheckDlgButton(hDlg, IDC_CP0_WRITE, BST_CHECKED); } - if (CLogSettings::LogCP0reads()) { CheckDlgButton(hDlg, IDC_CP0_READ, BST_CHECKED); } - if (CLogSettings::LogCache()) { CheckDlgButton(hDlg, IDC_CACHE, BST_CHECKED); } - if (CLogSettings::LogExceptions()) { CheckDlgButton(hDlg, IDC_EXCEPTIONS, BST_CHECKED); } - if (CLogSettings::LogNoInterrupts()) { CheckDlgButton(hDlg, IDC_INTERRUPTS, BST_CHECKED); } - if (CLogSettings::LogTLB()) { CheckDlgButton(hDlg, IDC_TLB, BST_CHECKED); } - if (CLogSettings::LogRomHeader()) { CheckDlgButton(hDlg, IDC_ROM_HEADER, BST_CHECKED); } - if (CLogSettings::LogUnknown()) { CheckDlgButton(hDlg, IDC_UNKOWN, BST_CHECKED); } + if (CLogSettings::LogCP0changes()) + { + CheckDlgButton(hDlg, IDC_CP0_WRITE, BST_CHECKED); + } + if (CLogSettings::LogCP0reads()) + { + CheckDlgButton(hDlg, IDC_CP0_READ, BST_CHECKED); + } + if (CLogSettings::LogCache()) + { + CheckDlgButton(hDlg, IDC_CACHE, BST_CHECKED); + } + if (CLogSettings::LogExceptions()) + { + CheckDlgButton(hDlg, IDC_EXCEPTIONS, BST_CHECKED); + } + if (CLogSettings::LogNoInterrupts()) + { + CheckDlgButton(hDlg, IDC_INTERRUPTS, BST_CHECKED); + } + if (CLogSettings::LogTLB()) + { + CheckDlgButton(hDlg, IDC_TLB, BST_CHECKED); + } + if (CLogSettings::LogRomHeader()) + { + CheckDlgButton(hDlg, IDC_ROM_HEADER, BST_CHECKED); + } + if (CLogSettings::LogUnknown()) + { + CheckDlgButton(hDlg, IDC_UNKOWN, BST_CHECKED); + } } break; case WM_NOTIFY: - if (((NMHDR FAR *) lParam)->code != PSN_APPLY) { break; } + if (((NMHDR FAR *)lParam)->code != PSN_APPLY) + { + break; + } g_Settings->SaveBool(Logging_LogCP0changes, IsDlgButtonChecked(hDlg, IDC_CP0_WRITE) == BST_CHECKED ? true : false); g_Settings->SaveBool(Logging_LogCP0reads, IsDlgButtonChecked(hDlg, IDC_CP0_READ) == BST_CHECKED ? true : false); g_Settings->SaveBool(Logging_LogCache, IsDlgButtonChecked(hDlg, IDC_CACHE) == BST_CHECKED ? true : false); @@ -94,12 +121,30 @@ LRESULT CALLBACK LogPifProc(HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPar { case WM_INITDIALOG: { - if (CLogSettings::LogPRDMAOperations()) { CheckDlgButton(hDlg, IDC_SI_DMA, BST_CHECKED); } - if (CLogSettings::LogPRDirectMemLoads()) { CheckDlgButton(hDlg, IDC_DIRECT_WRITE, BST_CHECKED); } - if (CLogSettings::LogPRDMAMemLoads()) { CheckDlgButton(hDlg, IDC_DMA_WRITE, BST_CHECKED); } - if (CLogSettings::LogPRDirectMemStores()) { CheckDlgButton(hDlg, IDC_DIRECT_READ, BST_CHECKED); } - if (CLogSettings::LogPRDMAMemStores()) { CheckDlgButton(hDlg, IDC_DMA_READ, BST_CHECKED); } - if (CLogSettings::LogControllerPak()) { CheckDlgButton(hDlg, IDC_CONT_PAK, BST_CHECKED); } + if (CLogSettings::LogPRDMAOperations()) + { + CheckDlgButton(hDlg, IDC_SI_DMA, BST_CHECKED); + } + if (CLogSettings::LogPRDirectMemLoads()) + { + CheckDlgButton(hDlg, IDC_DIRECT_WRITE, BST_CHECKED); + } + if (CLogSettings::LogPRDMAMemLoads()) + { + CheckDlgButton(hDlg, IDC_DMA_WRITE, BST_CHECKED); + } + if (CLogSettings::LogPRDirectMemStores()) + { + CheckDlgButton(hDlg, IDC_DIRECT_READ, BST_CHECKED); + } + if (CLogSettings::LogPRDMAMemStores()) + { + CheckDlgButton(hDlg, IDC_DMA_READ, BST_CHECKED); + } + if (CLogSettings::LogControllerPak()) + { + CheckDlgButton(hDlg, IDC_CONT_PAK, BST_CHECKED); + } } break; case WM_NOTIFY: @@ -126,16 +171,46 @@ LRESULT CALLBACK LogRegProc(HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPar { case WM_INITDIALOG: { - if (CLogSettings::LogRDRamRegisters()) { CheckDlgButton(hDlg, IDC_RDRAM, BST_CHECKED); } - if (CLogSettings::LogSPRegisters()) { CheckDlgButton(hDlg, IDC_SP_REG, BST_CHECKED); } - if (CLogSettings::LogDPCRegisters()) { CheckDlgButton(hDlg, IDC_DPC_REG, BST_CHECKED); } - if (CLogSettings::LogDPSRegisters()) { CheckDlgButton(hDlg, IDC_DPS_REG, BST_CHECKED); } - if (CLogSettings::LogMIPSInterface()) { CheckDlgButton(hDlg, IDC_MI_REG, BST_CHECKED); } - if (CLogSettings::LogVideoInterface()) { CheckDlgButton(hDlg, IDC_VI_REG, BST_CHECKED); } - if (CLogSettings::LogAudioInterface()) { CheckDlgButton(hDlg, IDC_AI_REG, BST_CHECKED); } - if (CLogSettings::LogPerInterface()) { CheckDlgButton(hDlg, IDC_PI_REG, BST_CHECKED); } - if (CLogSettings::LogRDRAMInterface()) { CheckDlgButton(hDlg, IDC_RI_REG, BST_CHECKED); } - if (CLogSettings::LogSerialInterface()) { CheckDlgButton(hDlg, IDC_SI_REG, BST_CHECKED); } + if (CLogSettings::LogRDRamRegisters()) + { + CheckDlgButton(hDlg, IDC_RDRAM, BST_CHECKED); + } + if (CLogSettings::LogSPRegisters()) + { + CheckDlgButton(hDlg, IDC_SP_REG, BST_CHECKED); + } + if (CLogSettings::LogDPCRegisters()) + { + CheckDlgButton(hDlg, IDC_DPC_REG, BST_CHECKED); + } + if (CLogSettings::LogDPSRegisters()) + { + CheckDlgButton(hDlg, IDC_DPS_REG, BST_CHECKED); + } + if (CLogSettings::LogMIPSInterface()) + { + CheckDlgButton(hDlg, IDC_MI_REG, BST_CHECKED); + } + if (CLogSettings::LogVideoInterface()) + { + CheckDlgButton(hDlg, IDC_VI_REG, BST_CHECKED); + } + if (CLogSettings::LogAudioInterface()) + { + CheckDlgButton(hDlg, IDC_AI_REG, BST_CHECKED); + } + if (CLogSettings::LogPerInterface()) + { + CheckDlgButton(hDlg, IDC_PI_REG, BST_CHECKED); + } + if (CLogSettings::LogRDRAMInterface()) + { + CheckDlgButton(hDlg, IDC_RI_REG, BST_CHECKED); + } + if (CLogSettings::LogSerialInterface()) + { + CheckDlgButton(hDlg, IDC_SI_REG, BST_CHECKED); + } } break; case WM_NOTIFY: diff --git a/Source/Project64/UserInterface/LoggingUI.h b/Source/Project64/UserInterface/LoggingUI.h index 93f9e4f68..86cb19c4d 100644 --- a/Source/Project64/UserInterface/LoggingUI.h +++ b/Source/Project64/UserInterface/LoggingUI.h @@ -1,3 +1,3 @@ #pragma once -void EnterLogOptions ( HWND hwndOwner ); +void EnterLogOptions(HWND hwndOwner); diff --git a/Source/Project64/UserInterface/MainMenu.cpp b/Source/Project64/UserInterface/MainMenu.cpp index 4e2bf58f2..f754fab31 100644 --- a/Source/Project64/UserInterface/MainMenu.cpp +++ b/Source/Project64/UserInterface/MainMenu.cpp @@ -94,7 +94,10 @@ int CMainMenu::ProcessAccelerator(HWND hWnd, void * lpMsg) m_ResetAccelerators = false; RebuildAccelerators(); } - if (!m_AccelTable) { return false; } + if (!m_AccelTable) + { + return false; + } return TranslateAccelerator((HWND)hWnd, (HACCEL)m_AccelTable, (LPMSG)lpMsg); } @@ -604,8 +607,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI if (MenuID >= ID_RECENT_ROM_START && MenuID < ID_RECENT_ROM_END) { stdstr FileName; - if (UISettingsLoadStringIndex(File_RecentGameFileIndex, MenuID - ID_RECENT_ROM_START, FileName) && - FileName.length() > 0) + if (UISettingsLoadStringIndex(File_RecentGameFileIndex, MenuID - ID_RECENT_ROM_START, FileName) && FileName.length() > 0) { if ((CPath(FileName).GetExtension() != "ndd") && (CPath(FileName).GetExtension() != "d64")) g_BaseSystem->RunFileImage(FileName.c_str()); @@ -692,7 +694,10 @@ std::wstring CMainMenu::GetSaveSlotString(int Slot) case 10: SlotName = GS(MENU_SLOT_10); break; } - if (!g_Settings->LoadBool(GameRunning_CPU_Running)) { return SlotName.ToUTF16(); } + if (!g_Settings->LoadBool(GameRunning_CPU_Running)) + { + return SlotName.ToUTF16(); + } stdstr LastSaveTime; @@ -880,38 +885,71 @@ void CMainMenu::FillOutMenu(HMENU hMenu) MenuItemList CurrentSaveMenu; DWORD _CurrentSaveState = g_Settings->LoadDword(Game_CurrentSaveState); Item.Reset(ID_CURRENT_SAVE_DEFAULT, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_DEFAULT, RunningState), nullptr, GetSaveSlotString(0)); - if (_CurrentSaveState == 0) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 0) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); CurrentSaveMenu.push_back(MENU_ITEM(SPLITER)); Item.Reset(ID_CURRENT_SAVE_1, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_1, RunningState), nullptr, GetSaveSlotString(1)); - if (_CurrentSaveState == 1) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 1) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_2, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_2, RunningState), nullptr, GetSaveSlotString(2)); - if (_CurrentSaveState == 2) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 2) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_3, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_3, RunningState), nullptr, GetSaveSlotString(3)); - if (_CurrentSaveState == 3) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 3) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_4, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_4, RunningState), nullptr, GetSaveSlotString(4)); - if (_CurrentSaveState == 4) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 4) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_5, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_5, RunningState), nullptr, GetSaveSlotString(5)); - if (_CurrentSaveState == 5) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 5) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_6, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_6, RunningState), nullptr, GetSaveSlotString(6)); - if (_CurrentSaveState == 6) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 6) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_7, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_7, RunningState), nullptr, GetSaveSlotString(7)); - if (_CurrentSaveState == 7) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 7) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_8, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_8, RunningState), nullptr, GetSaveSlotString(8)); - if (_CurrentSaveState == 8) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 8) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_9, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_9, RunningState), nullptr, GetSaveSlotString(9)); - if (_CurrentSaveState == 9) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 9) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); Item.Reset(ID_CURRENT_SAVE_10, EMPTY_STRING, m_ShortCuts.ShortCutString(ID_CURRENT_SAVE_10, RunningState), nullptr, GetSaveSlotString(10)); - if (_CurrentSaveState == 10) { Item.SetItemTicked(true); } + if (_CurrentSaveState == 10) + { + Item.SetItemTicked(true); + } CurrentSaveMenu.push_back(Item); // System menu @@ -940,12 +978,18 @@ void CMainMenu::FillOutMenu(HMENU hMenu) if (!inBasicMode) { Item.Reset(ID_SYSTEM_LIMITFPS, MENU_LIMIT_FPS, m_ShortCuts.ShortCutString(ID_SYSTEM_LIMITFPS, RunningState)); - if (g_Settings->LoadBool(GameRunning_LimitFPS)) { Item.SetItemTicked(true); } + if (g_Settings->LoadBool(GameRunning_LimitFPS)) + { + Item.SetItemTicked(true); + } SystemMenu.push_back(Item); SystemMenu.push_back(MENU_ITEM(SPLITER)); } Item.Reset(ID_SYSTEM_SWAPDISK, MENU_SWAPDISK, m_ShortCuts.ShortCutString(ID_SYSTEM_SWAPDISK, RunningState)); - if (g_Disk == nullptr) { Item.SetItemEnabled(false); } + if (g_Disk == nullptr) + { + Item.SetItemEnabled(false); + } SystemMenu.push_back(Item); SystemMenu.push_back(MENU_ITEM(SPLITER)); SystemMenu.push_back(MENU_ITEM(ID_SYSTEM_SAVE, MENU_SAVE, m_ShortCuts.ShortCutString(ID_SYSTEM_SAVE, RunningState))); @@ -980,7 +1024,10 @@ void CMainMenu::FillOutMenu(HMENU hMenu) if (!inBasicMode) { Item.Reset(ID_OPTIONS_ALWAYSONTOP, MENU_ON_TOP, m_ShortCuts.ShortCutString(ID_OPTIONS_ALWAYSONTOP, RunningState)); - if (UISettingsLoadDword(UserInterface_AlwaysOnTop)) { Item.SetItemTicked(true); } + if (UISettingsLoadDword(UserInterface_AlwaysOnTop)) + { + Item.SetItemTicked(true); + } Item.SetItemEnabled(CPURunning); OptionMenu.push_back(Item); } @@ -1018,7 +1065,10 @@ void CMainMenu::FillOutMenu(HMENU hMenu) if (!inBasicMode) { Item.Reset(ID_OPTIONS_CPU_USAGE, MENU_SHOW_CPU, m_ShortCuts.ShortCutString(ID_OPTIONS_CPU_USAGE, RunningState)); - if (g_Settings->LoadDword(UserInterface_ShowCPUPer)) { Item.SetItemTicked(true); } + if (g_Settings->LoadDword(UserInterface_ShowCPUPer)) + { + Item.SetItemTicked(true); + } OptionMenu.push_back(Item); } OptionMenu.push_back(MENU_ITEM(ID_OPTIONS_SETTINGS, MENU_SETTINGS, m_ShortCuts.ShortCutString(ID_OPTIONS_SETTINGS, RunningState))); @@ -1028,13 +1078,22 @@ void CMainMenu::FillOutMenu(HMENU hMenu) if (HaveDebugger()) { Item.Reset(ID_PROFILE_PROFILE, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Record Execution Times"); - if (g_Settings->LoadBool(Debugger_RecordExecutionTimes)) { Item.SetItemTicked(true); } + if (g_Settings->LoadBool(Debugger_RecordExecutionTimes)) + { + Item.SetItemTicked(true); + } DebugProfileMenu.push_back(Item); Item.Reset(ID_PROFILE_RESETCOUNTER, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Reset Counters"); - if (!CPURunning) { Item.SetItemEnabled(false); } + if (!CPURunning) + { + Item.SetItemEnabled(false); + } DebugProfileMenu.push_back(Item); Item.Reset(ID_PROFILE_GENERATELOG, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Generate Log File"); - if (!CPURunning) { Item.SetItemEnabled(false); } + if (!CPURunning) + { + Item.SetItemEnabled(false); + } DebugProfileMenu.push_back(Item); } @@ -1156,7 +1215,7 @@ void CMainMenu::FillOutMenu(HMENU hMenu) DebugAppLoggingMenu.push_back(Item); Item.Reset(ID_DEBUGGER_TRACE_PLUGINS, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Plugins"); - Item.SetItemTicked(g_Settings->LoadDword(Debugger_TracePlugins) == TraceVerbose);; + Item.SetItemTicked(g_Settings->LoadDword(Debugger_TracePlugins) == TraceVerbose); DebugAppLoggingMenu.push_back(Item); Item.Reset(ID_DEBUGGER_TRACE_GFXPLUGIN, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"GFX plugin"); @@ -1172,7 +1231,7 @@ void CMainMenu::FillOutMenu(HMENU hMenu) DebugAppLoggingMenu.push_back(Item); Item.Reset(ID_DEBUGGER_TRACE_RSPPLUGIN, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"RSP plugin"); - Item.SetItemTicked(g_Settings->LoadDword(Debugger_TraceRSPPlugin) == TraceVerbose);; + Item.SetItemTicked(g_Settings->LoadDword(Debugger_TraceRSPPlugin) == TraceVerbose); DebugAppLoggingMenu.push_back(Item); Item.Reset(ID_DEBUGGER_TRACE_RSP, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"RSP"); @@ -1206,7 +1265,10 @@ void CMainMenu::FillOutMenu(HMENU hMenu) DebugAppLoggingMenu.push_back(MENU_ITEM(SPLITER)); Item.Reset(ID_DEBUGGER_APPLOG_FLUSH, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Auto flush file"); - if (g_Settings->LoadBool(Debugger_AppLogFlush)) { Item.SetItemTicked(true); } + if (g_Settings->LoadBool(Debugger_AppLogFlush)) + { + Item.SetItemTicked(true); + } DebugAppLoggingMenu.push_back(Item); // Debug - logging @@ -1214,7 +1276,10 @@ void CMainMenu::FillOutMenu(HMENU hMenu) DebugLoggingMenu.push_back(Item); Item.Reset(ID_DEBUGGER_GENERATELOG, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Generate log"); - if (g_Settings->LoadBool(Logging_GenerateLog)) { Item.SetItemTicked(true); } + if (g_Settings->LoadBool(Logging_GenerateLog)) + { + Item.SetItemTicked(true); + } DebugLoggingMenu.push_back(Item); // Debugger main menu @@ -1305,28 +1370,43 @@ void CMainMenu::FillOutMenu(HMENU hMenu) // Main title bar Menu MenuItemList MainTitleMenu; Item.Reset(SUB_MENU, MENU_FILE, EMPTY_STDSTR, &FileMenu); - if (RomLoading) { Item.SetItemEnabled(false); } + if (RomLoading) + { + Item.SetItemEnabled(false); + } MainTitleMenu.push_back(Item); if (CPURunning) { Item.Reset(SUB_MENU, MENU_SYSTEM, EMPTY_STDSTR, &SystemMenu); - if (RomLoading) { Item.SetItemEnabled(false); } + if (RomLoading) + { + Item.SetItemEnabled(false); + } MainTitleMenu.push_back(Item); } Item.Reset(SUB_MENU, MENU_OPTIONS, EMPTY_STDSTR, &OptionMenu); - if (RomLoading) { Item.SetItemEnabled(false); } + if (RomLoading) + { + Item.SetItemEnabled(false); + } MainTitleMenu.push_back(Item); if (!inBasicMode) { if (HaveDebugger()) { Item.Reset(SUB_MENU, MENU_DEBUGGER, EMPTY_STDSTR, &DebugMenu); - if (RomLoading) { Item.SetItemEnabled(false); } + if (RomLoading) + { + Item.SetItemEnabled(false); + } MainTitleMenu.push_back(Item); } } Item.Reset(SUB_MENU, MENU_HELP, EMPTY_STDSTR, &HelpMenu); - if (RomLoading) { Item.SetItemEnabled(false); } + if (RomLoading) + { + Item.SetItemEnabled(false); + } MainTitleMenu.push_back(Item); if (UISettingsLoadBool(UserInterface_ShowingNagWindow)) diff --git a/Source/Project64/UserInterface/MainMenu.h b/Source/Project64/UserInterface/MainMenu.h index 37d75e607..edc5e9579 100644 --- a/Source/Project64/UserInterface/MainMenu.h +++ b/Source/Project64/UserInterface/MainMenu.h @@ -1,62 +1,144 @@ #pragma once +#include #include +#include +#include enum MainMenuID { // File menu - ID_FILE_OPEN_ROM = 4000, ID_FILE_OPEN_COMBO, ID_FILE_ROM_INFO, ID_FILE_STARTEMULATION, ID_FILE_ENDEMULATION, - ID_FILE_ROMDIRECTORY, ID_FILE_REFRESHROMLIST, ID_FILE_EXIT, + ID_FILE_OPEN_ROM = 4000, + ID_FILE_OPEN_COMBO, + ID_FILE_ROM_INFO, + ID_FILE_STARTEMULATION, + ID_FILE_ENDEMULATION, + ID_FILE_ROMDIRECTORY, + ID_FILE_REFRESHROMLIST, + ID_FILE_EXIT, // Language - ID_LANG_START, ID_LANG_END = ID_LANG_START + 100, + ID_LANG_START, + ID_LANG_END = ID_LANG_START + 100, // Recent files - ID_RECENT_ROM_START, ID_RECENT_ROM_END = ID_RECENT_ROM_START + 20, + ID_RECENT_ROM_START, + ID_RECENT_ROM_END = ID_RECENT_ROM_START + 20, // Recent directory - ID_RECENT_DIR_START, ID_RECENT_DIR_END = ID_RECENT_DIR_START + 20, + ID_RECENT_DIR_START, + ID_RECENT_DIR_END = ID_RECENT_DIR_START + 20, // System menu - ID_SYSTEM_RESET_SOFT, ID_SYSTEM_RESET_HARD, ID_SYSTEM_PAUSE, ID_SYSTEM_BITMAP, - ID_SYSTEM_LIMITFPS, ID_SYSTEM_SWAPDISK, ID_SYSTEM_RESTORE, ID_SYSTEM_LOAD, ID_SYSTEM_SAVE, - ID_SYSTEM_SAVEAS, ID_SYSTEM_ENHANCEMENT, ID_SYSTEM_CHEAT, ID_SYSTEM_GSBUTTON, + ID_SYSTEM_RESET_SOFT, + ID_SYSTEM_RESET_HARD, + ID_SYSTEM_PAUSE, + ID_SYSTEM_BITMAP, + ID_SYSTEM_LIMITFPS, + ID_SYSTEM_SWAPDISK, + ID_SYSTEM_RESTORE, + ID_SYSTEM_LOAD, + ID_SYSTEM_SAVE, + ID_SYSTEM_SAVEAS, + ID_SYSTEM_ENHANCEMENT, + ID_SYSTEM_CHEAT, + ID_SYSTEM_GSBUTTON, //Current save slot - ID_CURRENT_SAVE_1, ID_CURRENT_SAVE_2, ID_CURRENT_SAVE_3, ID_CURRENT_SAVE_4, ID_CURRENT_SAVE_5, - ID_CURRENT_SAVE_6, ID_CURRENT_SAVE_7, ID_CURRENT_SAVE_8, ID_CURRENT_SAVE_9, ID_CURRENT_SAVE_10, + ID_CURRENT_SAVE_1, + ID_CURRENT_SAVE_2, + ID_CURRENT_SAVE_3, + ID_CURRENT_SAVE_4, + ID_CURRENT_SAVE_5, + ID_CURRENT_SAVE_6, + ID_CURRENT_SAVE_7, + ID_CURRENT_SAVE_8, + ID_CURRENT_SAVE_9, + ID_CURRENT_SAVE_10, ID_CURRENT_SAVE_DEFAULT, // Option menu - ID_OPTIONS_FULLSCREEN, ID_OPTIONS_FULLSCREEN2, ID_OPTIONS_ALWAYSONTOP, ID_OPTIONS_CONFIG_GFX, - ID_OPTIONS_CONFIG_AUDIO, ID_OPTIONS_CONFIG_CONT, ID_OPTIONS_CONFIG_RSP, ID_OPTIONS_CPU_USAGE, - ID_OPTIONS_SETTINGS, ID_OPTIONS_DISPLAY_FR, ID_OPTIONS_CHANGE_FR, ID_OPTIONS_INCREASE_SPEED, + ID_OPTIONS_FULLSCREEN, + ID_OPTIONS_FULLSCREEN2, + ID_OPTIONS_ALWAYSONTOP, + ID_OPTIONS_CONFIG_GFX, + ID_OPTIONS_CONFIG_AUDIO, + ID_OPTIONS_CONFIG_CONT, + ID_OPTIONS_CONFIG_RSP, + ID_OPTIONS_CPU_USAGE, + ID_OPTIONS_SETTINGS, + ID_OPTIONS_DISPLAY_FR, + ID_OPTIONS_CHANGE_FR, + ID_OPTIONS_INCREASE_SPEED, ID_OPTIONS_DECREASE_SPEED, // Debugger menu - ID_DEBUG_END_ON_PERM_LOOP, ID_DEBUG_STEP_ON_BREAK_OPCODE, - ID_DEBUG_BREAK_ON_UNHANDLED_MEM, ID_DEBUG_BREAK_ON_ADDRESS_ERROR, ID_DEBUG_SHOW_PIF_ERRORS, - ID_DEBUG_SHOW_DLIST_COUNT, ID_DEBUG_SHOW_RECOMP_MEM_SIZE, - ID_DEBUG_RECORD_RECOMPILER_ASM, ID_DEBUG_DISABLE_GAMEFIX, ID_DEBUG_LANGUAGE, - ID_DEBUGGER_LOGOPTIONS, ID_DEBUGGER_GENERATELOG, ID_DEBUGGER_DUMPMEMORY, ID_DEBUGGER_SEARCHMEMORY, - ID_DEBUGGER_TLBENTRIES, ID_DEBUGGER_BREAKPOINTS, ID_DEBUGGER_MEMORY, ID_DEBUGGER_R4300REGISTERS, - ID_DEBUGGER_INTERRUPT_SP, ID_DEBUGGER_INTERRUPT_SI, ID_DEBUGGER_INTERRUPT_AI, ID_DEBUGGER_INTERRUPT_VI, - ID_DEBUGGER_INTERRUPT_PI, ID_DEBUGGER_INTERRUPT_DP, ID_DEBUGGER_SCRIPTS, ID_DEBUGGER_SYMBOLS, ID_DEBUGGER_DMALOG, - ID_DEBUGGER_EXCBREAKPOINTS, ID_DEBUGGER_CPULOG, ID_DEBUGGER_STACKTRACE, ID_DEBUGGER_STACKVIEW, + ID_DEBUG_END_ON_PERM_LOOP, + ID_DEBUG_STEP_ON_BREAK_OPCODE, + ID_DEBUG_BREAK_ON_UNHANDLED_MEM, + ID_DEBUG_BREAK_ON_ADDRESS_ERROR, + ID_DEBUG_SHOW_PIF_ERRORS, + ID_DEBUG_SHOW_DLIST_COUNT, + ID_DEBUG_SHOW_RECOMP_MEM_SIZE, + ID_DEBUG_RECORD_RECOMPILER_ASM, + ID_DEBUG_DISABLE_GAMEFIX, + ID_DEBUG_LANGUAGE, + ID_DEBUGGER_LOGOPTIONS, + ID_DEBUGGER_GENERATELOG, + ID_DEBUGGER_DUMPMEMORY, + ID_DEBUGGER_SEARCHMEMORY, + ID_DEBUGGER_TLBENTRIES, + ID_DEBUGGER_BREAKPOINTS, + ID_DEBUGGER_MEMORY, + ID_DEBUGGER_R4300REGISTERS, + ID_DEBUGGER_INTERRUPT_SP, + ID_DEBUGGER_INTERRUPT_SI, + ID_DEBUGGER_INTERRUPT_AI, + ID_DEBUGGER_INTERRUPT_VI, + ID_DEBUGGER_INTERRUPT_PI, + ID_DEBUGGER_INTERRUPT_DP, + ID_DEBUGGER_SCRIPTS, + ID_DEBUGGER_SYMBOLS, + ID_DEBUGGER_DMALOG, + ID_DEBUGGER_EXCBREAKPOINTS, + ID_DEBUGGER_CPULOG, + ID_DEBUGGER_STACKTRACE, + ID_DEBUGGER_STACKVIEW, // App logging - ID_DEBUGGER_APPLOG_FLUSH, ID_DEBUGGER_TRACE_MD5, ID_DEBUGGER_TRACE_SETTINGS, ID_DEBUGGER_TRACE_UNKNOWN, ID_DEBUGGER_TRACE_APPINIT, - ID_DEBUGGER_TRACE_APPCLEANUP, ID_DEBUGGER_TRACE_N64SYSTEM, ID_DEBUGGER_TRACE_PLUGINS, ID_DEBUGGER_TRACE_GFXPLUGIN, - ID_DEBUGGER_TRACE_AUDIOPLUGIN, ID_DEBUGGER_TRACE_CONTROLLERPLUGIN, ID_DEBUGGER_TRACE_RSPPLUGIN, ID_DEBUGGER_TRACE_RSP, - ID_DEBUGGER_TRACE_AUDIO, ID_DEBUGGER_TRACE_REGISTERCACHE, ID_DEBUGGER_TRACE_RECOMPILER, ID_DEBUGGER_TRACE_TLB, - ID_DEBUGGER_TRACE_PROTECTEDMEM, ID_DEBUGGER_TRACE_USERINTERFACE, + ID_DEBUGGER_APPLOG_FLUSH, + ID_DEBUGGER_TRACE_MD5, + ID_DEBUGGER_TRACE_SETTINGS, + ID_DEBUGGER_TRACE_UNKNOWN, + ID_DEBUGGER_TRACE_APPINIT, + ID_DEBUGGER_TRACE_APPCLEANUP, + ID_DEBUGGER_TRACE_N64SYSTEM, + ID_DEBUGGER_TRACE_PLUGINS, + ID_DEBUGGER_TRACE_GFXPLUGIN, + ID_DEBUGGER_TRACE_AUDIOPLUGIN, + ID_DEBUGGER_TRACE_CONTROLLERPLUGIN, + ID_DEBUGGER_TRACE_RSPPLUGIN, + ID_DEBUGGER_TRACE_RSP, + ID_DEBUGGER_TRACE_AUDIO, + ID_DEBUGGER_TRACE_REGISTERCACHE, + ID_DEBUGGER_TRACE_RECOMPILER, + ID_DEBUGGER_TRACE_TLB, + ID_DEBUGGER_TRACE_PROTECTEDMEM, + ID_DEBUGGER_TRACE_USERINTERFACE, // Profile menu - ID_PROFILE_PROFILE, ID_PROFILE_RESETCOUNTER, ID_PROFILE_GENERATELOG, + ID_PROFILE_PROFILE, + ID_PROFILE_RESETCOUNTER, + ID_PROFILE_GENERATELOG, // Help menu - ID_HELP_SUPPORT_PROJECT64, ID_HELP_DISCORD, ID_HELP_WEBSITE, ID_HELP_ABOUT, + ID_HELP_SUPPORT_PROJECT64, + ID_HELP_DISCORD, + ID_HELP_WEBSITE, + ID_HELP_ABOUT, }; +class CMainGui; + class CMainMenu : public CBaseMenu, private CDebugSettings @@ -68,12 +150,15 @@ public: int ProcessAccelerator(HWND hWnd, void * lpMsg); bool ProcessMessage(HWND hWnd, DWORD wNotifyCode, DWORD wID); void ResetMenu(void); - void ResetAccelerators(void) { m_ResetAccelerators = true; } + void ResetAccelerators(void) + { + m_ResetAccelerators = true; + } private: CMainMenu(); - CMainMenu(const CMainMenu&); - CMainMenu& operator=(const CMainMenu&); + CMainMenu(const CMainMenu &); + CMainMenu & operator=(const CMainMenu &); void OnOpenRom(HWND hWnd); void OnOpenCombo(HWND hWnd); @@ -98,7 +183,10 @@ private: void ShortCutsChanged(void); static void SettingsChanged(CMainMenu * _this); - static void stShortCutsChanged(CMainMenu * _this) { return _this->ShortCutsChanged(); } + static void stShortCutsChanged(CMainMenu * _this) + { + return _this->ShortCutsChanged(); + } typedef std::list SettingList; typedef std::list UISettingList; diff --git a/Source/Project64/UserInterface/MainWindow.cpp b/Source/Project64/UserInterface/MainWindow.cpp index 933387255..afac72559 100644 --- a/Source/Project64/UserInterface/MainWindow.cpp +++ b/Source/Project64/UserInterface/MainWindow.cpp @@ -113,7 +113,10 @@ bool CMainGui::RegisterWinClass(void) void CMainGui::AddRecentRom(const char * ImagePath) { - if (HIWORD(ImagePath) == NULL) { return; } + if (HIWORD(ImagePath) == NULL) + { + return; + } // Get information about the stored ROM list size_t MaxRememberedFiles = UISettingsLoadDword(File_RecentGameFileCount); @@ -413,12 +416,14 @@ WPARAM CMainGui::ProcessAllMessages(void) SetEvent(m_ResetInfo->hEvent); m_ResetInfo = nullptr; } - if ((m_CheatsUI.m_hWnd != nullptr && IsDialogMessage(m_CheatsUI.m_hWnd, &msg)) || - (m_EnhancementUI.m_hWnd != nullptr && IsDialogMessage(m_EnhancementUI.m_hWnd, &msg))) + if ((m_CheatsUI.m_hWnd != nullptr && IsDialogMessage(m_CheatsUI.m_hWnd, &msg)) || (m_EnhancementUI.m_hWnd != nullptr && IsDialogMessage(m_EnhancementUI.m_hWnd, &msg))) + { + continue; + } + if (m_Menu->ProcessAccelerator(m_hMainWindow, &msg)) { continue; } - if (m_Menu->ProcessAccelerator(m_hMainWindow, &msg)) { continue; } TranslateMessage(&msg); DispatchMessage(&msg); } @@ -440,7 +445,10 @@ bool CMainGui::ProcessGuiMessages(void) return true; } PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE); - if (m_Menu->ProcessAccelerator(m_hMainWindow, &msg)) { continue; } + if (m_Menu->ProcessAccelerator(m_hMainWindow, &msg)) + { + continue; + } TranslateMessage(&msg); DispatchMessage(&msg); } @@ -485,7 +493,10 @@ void CMainGui::EnterLogOptions(void) int CMainGui::Height(void) { - if (!m_hMainWindow) { return 0; } + if (!m_hMainWindow) + { + return 0; + } RECT rect; GetWindowRect(m_hMainWindow, &rect); @@ -494,7 +505,10 @@ int CMainGui::Height(void) int CMainGui::Width(void) { - if (!m_hMainWindow) { return 0; } + if (!m_hMainWindow) + { + return 0; + } RECT rect; GetWindowRect(m_hMainWindow, &rect); @@ -532,7 +546,10 @@ void CMainGui::SetWindowMenu(CBaseMenu * Menu) void CMainGui::RefreshMenu(void) { - if (!m_Menu) { return; } + if (!m_Menu) + { + return; + } m_Menu->ResetMenu(); } @@ -622,10 +639,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO case SC_MONITORPOWER: { CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class"); - if (_this && - _this->bCPURunning() && - !g_Settings->LoadBool(GameRunning_CPU_Paused) && - UISettingsLoadBool(Setting_DisableScrSaver)) + if (_this && _this->bCPURunning() && !g_Settings->LoadBool(GameRunning_CPU_Paused) && UISettingsLoadBool(Setting_DisableScrSaver)) { return 0; } @@ -650,12 +664,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO { CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class"); - if (!_this->m_bMainWindow || - !_this->m_Created || - _this->m_AttachingMenu || - _this->m_MakingVisible || - IsIconic(hWnd) || - _this->ShowingRomBrowser()) + if (!_this->m_bMainWindow || !_this->m_Created || _this->m_AttachingMenu || _this->m_MakingVisible || IsIconic(hWnd) || _this->ShowingRomBrowser()) { break; } @@ -711,7 +720,10 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO case WM_SIZE: { CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class"); - if (_this) { _this->Resize(wParam, LOWORD(lParam), HIWORD(lParam)); } + if (_this) + { + _this->Resize(wParam, LOWORD(lParam), HIWORD(lParam)); + } if (_this) { if (wParam == SIZE_MAXIMIZED) @@ -875,11 +887,17 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO case WM_HIDE_CUROSR: if (!wParam) { - while (ShowCursor(FALSE) >= 0) { Sleep(0); } + while (ShowCursor(FALSE) >= 0) + { + Sleep(0); + } } else { - while (ShowCursor(TRUE) < 0) { Sleep(0); } + while (ShowCursor(TRUE) < 0) + { + Sleep(0); + } } break; case WM_MAKE_FOCUS: @@ -927,8 +945,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO { char * romPath = (char *)lParam; stdstr ext = CPath(romPath).GetExtension(); - if ((_stricmp(ext.c_str(), "ndd") != 0) && - (_stricmp(ext.c_str(), "d64") != 0)) + if ((_stricmp(ext.c_str(), "ndd") != 0) && (_stricmp(ext.c_str(), "d64") != 0)) { g_BaseSystem->RunFileImage(romPath); } @@ -1006,7 +1023,10 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO case WM_COMMAND: { CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class"); - if (_this == nullptr) { break; } + if (_this == nullptr) + { + break; + } switch (LOWORD(wParam)) { diff --git a/Source/Project64/UserInterface/MainWindow.h b/Source/Project64/UserInterface/MainWindow.h index 3533315f9..a048ee8aa 100644 --- a/Source/Project64/UserInterface/MainWindow.h +++ b/Source/Project64/UserInterface/MainWindow.h @@ -1,16 +1,17 @@ #pragma once #include "../Settings/GuiSettings.h" -#include #include -#include -#include -#include +#include +#include +#include +#include +#include class CGfxPlugin; // Plugin that controls the rendering class CAudioPlugin; // Plugin for audio, need the hwnd class CControl_Plugin; // Controller needs hwnd to see if it is the focused window -class CBaseMenu; // Menu for the GUI +class CBaseMenu; // Menu for the GUI class CN64System; class CriticalSection; @@ -38,9 +39,15 @@ class CMainGui : public CRomBrowser, private CGuiSettings { - enum { StatusBarID = 400 }; + enum + { + StatusBarID = 400 + }; - enum { Timer_SetWindowPos = 1 }; + enum + { + Timer_SetWindowPos = 1 + }; struct RESET_PLUGIN { @@ -49,6 +56,7 @@ class CMainGui : HANDLE hEvent; bool res; }; + public: CMainGui(bool bMainWindow, const char * WindowTitle = ""); ~CMainGui(void); @@ -56,7 +64,7 @@ public: WPARAM ProcessAllMessages(void); bool ProcessGuiMessages(void); void EnterLogOptions(void); - int Height(void); + int Height(void); int Width(void); float DPIScale(HWND hWnd); @@ -69,7 +77,10 @@ public: void SetWindowMenu(CBaseMenu * Menu); void RefreshMenu(void); - CBaseMenu * GetMenuClass(void) { return m_Menu; } + CBaseMenu * GetMenuClass(void) + { + return m_Menu; + } void SetStatusText(int Panel, const wchar_t * Text); void ShowStatusBar(bool ShowBar); @@ -79,16 +90,22 @@ public: void DisplayCheatsUI(bool BlockExecution); void DisplayEnhancements(bool BlockExecution); - void * GetWindowHandle(void) const { return m_hMainWindow; } + void * GetWindowHandle(void) const + { + return m_hMainWindow; + } void * GetStatusBar(void) const; void * GetModuleInstance(void) const; - inline CProjectSupport & Support(void) { return m_Support; } + inline CProjectSupport & Support(void) + { + return m_Support; + } private: CMainGui(void); - CMainGui(const CMainGui&); - CMainGui& operator=(const CMainGui&); + CMainGui(const CMainGui &); + CMainGui & operator=(const CMainGui &); friend class CGfxPlugin; friend class CAudioPlugin; @@ -108,13 +125,13 @@ private: friend void RomBowserEnabledChanged(CMainGui * Gui); friend void RomBowserColoumnsChanged(CMainGui * Gui); friend void RomBrowserListChanged(CMainGui * Gui); - friend void DiscordRPCChanged(CMainGui * Gui); + friend void DiscordRPCChanged(CMainGui * Gui); static void LoadingInProgressChanged(CMainGui * Gui); static void GameLoaded(CMainGui * Gui); static void GamePaused(CMainGui * Gui); static void GameCpuRunning(CMainGui * Gui); static void ShowStatusBarChanged(CMainGui * Gui); - + CBaseMenu * m_Menu; HWND m_hMainWindow, m_hStatusWnd; diff --git a/Source/Project64/UserInterface/MenuItem.cpp b/Source/Project64/UserInterface/MenuItem.cpp index 51afaf231..1c829fc9d 100644 --- a/Source/Project64/UserInterface/MenuItem.cpp +++ b/Source/Project64/UserInterface/MenuItem.cpp @@ -1,13 +1,16 @@ #include "stdafx.h" CBaseMenu::CBaseMenu() : -m_MenuHandle((HMENU)CreateMenu()) + m_MenuHandle((HMENU)CreateMenu()) { } bool CBaseMenu::AddMenu(HMENU hMenu, MenuItemList Items) { - if (Items.begin() == Items.end()) { return false; } + if (Items.begin() == Items.end()) + { + return false; + } UINT ItemID, uFlags; std::wstring Text, String; diff --git a/Source/Project64/UserInterface/MenuItem.h b/Source/Project64/UserInterface/MenuItem.h index 67257c3e6..c0ae27539 100644 --- a/Source/Project64/UserInterface/MenuItem.h +++ b/Source/Project64/UserInterface/MenuItem.h @@ -2,74 +2,106 @@ #include -enum Menu_ID +enum Menu_ID { - // ControlID - SPLITER, SUB_MENU, NO_ID, ID_PLUGIN_MENU, + // ControlID + SPLITER, + SUB_MENU, + NO_ID, + ID_PLUGIN_MENU, }; const std::wstring EMPTY_STDSTR = L""; -class MENU_ITEM +class MENU_ITEM { public: - MENU_ITEM (void) + MENU_ITEM(void) { - Reset(NO_ID); - } - MENU_ITEM ( int ID, LanguageStringID Title = EMPTY_STRING, const std::wstring & ShortCut = EMPTY_STDSTR, - void * SubMenu = nullptr, const std::wstring & ManualString = EMPTY_STDSTR) - { - Reset(ID,Title,ShortCut,SubMenu,ManualString); - } - void Reset ( int ID, LanguageStringID Title = EMPTY_STRING, const std::wstring & ShortCut2 = EMPTY_STDSTR, - void * SubMenu = nullptr, const std::wstring & ManualString = EMPTY_STDSTR) - { - this->m_ID = ID; - this->m_Title = Title; - this->m_ShortCut = ShortCut2; - this->m_SubMenu = SubMenu; - this->m_ManualString = ManualString; - this->m_ItemTicked = false; - this->m_ItemEnabled = true; - } + Reset(NO_ID); + } + MENU_ITEM(int ID, LanguageStringID Title = EMPTY_STRING, const std::wstring & ShortCut = EMPTY_STDSTR, + void * SubMenu = nullptr, const std::wstring & ManualString = EMPTY_STDSTR) + { + Reset(ID, Title, ShortCut, SubMenu, ManualString); + } + void Reset(int ID, LanguageStringID Title = EMPTY_STRING, const std::wstring & ShortCut2 = EMPTY_STDSTR, + void * SubMenu = nullptr, const std::wstring & ManualString = EMPTY_STDSTR) + { + this->m_ID = ID; + this->m_Title = Title; + this->m_ShortCut = ShortCut2; + this->m_SubMenu = SubMenu; + this->m_ManualString = ManualString; + this->m_ItemTicked = false; + this->m_ItemEnabled = true; + } - int ID() const { return m_ID; } - LanguageStringID Title() const { return m_Title; } - const std::wstring & ShortCut() const { return m_ShortCut; } - void * SubMenu() const { return m_SubMenu; } - const std::wstring & ManualString() const { return m_ManualString; } - bool ItemTicked() const { return m_ItemTicked; } - bool ItemEnabled() const { return m_ItemEnabled; } - - void SetItemTicked(bool ItemTicked) { m_ItemTicked = ItemTicked; } - void SetItemEnabled(bool ItemEnabled) { m_ItemEnabled = ItemEnabled; } + int ID() const + { + return m_ID; + } + LanguageStringID Title() const + { + return m_Title; + } + const std::wstring & ShortCut() const + { + return m_ShortCut; + } + void * SubMenu() const + { + return m_SubMenu; + } + const std::wstring & ManualString() const + { + return m_ManualString; + } + bool ItemTicked() const + { + return m_ItemTicked; + } + bool ItemEnabled() const + { + return m_ItemEnabled; + } + void SetItemTicked(bool ItemTicked) + { + m_ItemTicked = ItemTicked; + } + void SetItemEnabled(bool ItemEnabled) + { + m_ItemEnabled = ItemEnabled; + } private: - int m_ID; - LanguageStringID m_Title; - std::wstring m_ShortCut; - void * m_SubMenu; - std::wstring m_ManualString; - bool m_ItemTicked; - bool m_ItemEnabled; + int m_ID; + LanguageStringID m_Title; + std::wstring m_ShortCut; + void * m_SubMenu; + std::wstring m_ManualString; + bool m_ItemTicked; + bool m_ItemEnabled; }; -typedef std::list MenuItemList; +typedef std::list MenuItemList; -class CBaseMenu { +class CBaseMenu +{ protected: - HMENU m_MenuHandle; - - bool AddMenu ( HMENU hMenu, MenuItemList Items ); + HMENU m_MenuHandle; + + bool AddMenu(HMENU hMenu, MenuItemList Items); public: - CBaseMenu (); + CBaseMenu(); - - virtual int ProcessAccelerator(HWND hWnd, void * lpMsg ) = 0; // Pure virtual draw() function + virtual int ProcessAccelerator(HWND hWnd, void * lpMsg) = 0; // Pure virtual draw() function virtual bool ProcessMessage(HWND hWnd, DWORD wNotifyCode, DWORD wID) = 0; // Pure virtual draw() function - virtual void ResetMenu(void) = 0; // Pure virtual draw() function - HMENU GetHandle (void) { return m_MenuHandle; } + virtual void ResetMenu(void) = 0; // Pure virtual draw() function + HMENU GetHandle(void) + { + return m_MenuHandle; + } }; diff --git a/Source/Project64/UserInterface/MenuShortCuts.cpp b/Source/Project64/UserInterface/MenuShortCuts.cpp index 03c7fcacc..86e76c80d 100644 --- a/Source/Project64/UserInterface/MenuShortCuts.cpp +++ b/Source/Project64/UserInterface/MenuShortCuts.cpp @@ -1,170 +1,170 @@ #include "stdafx.h" VIRTUAL_KEY CMenuShortCutKey::m_VirtualKeyList[] = { - { L"VK_LBUTTON", 0x01, L"VK_LBUTTON" }, - { L"VK_RBUTTON", 0x02, L"VK_RBUTTON" }, - { L"VK_CANCEL", 0x03, L"VK_CANCEL" }, - { L"VK_MBUTTON", 0x04, L"VK_MBUTTON" }, - { L"VK_XBUTTON1", 0x05, L"VK_XBUTTON1" }, - { L"VK_XBUTTON2", 0x06, L"VK_XBUTTON2" }, - { L"VK_BACK", 0x08, L"VK_BACK" }, - { L"VK_TAB", 0x09, L"VK_TAB" }, - { L"VK_CLEAR", 0x0C, L"VK_CLEAR" }, - { L"VK_RETURN", 0x0D, L"Return" }, - { L"VK_SHIFT", 0x10, L"VK_SHIFT" }, - { L"VK_CONTROL", 0x11, L"VK_CONTROL" }, - { L"VK_MENU", 0x12, L"VK_MENU" }, - { L"VK_PAUSE", 0x13, L"Pause" }, - { L"VK_CAPITAL", 0x14, L"VK_CAPITAL" }, - { L"VK_KANA", 0x15, L"VK_KANA" }, - { L"VK_HANGUL", 0x15, L"VK_HANGUL" }, - { L"VK_JUNJA", 0x17, L"VK_JUNJA" }, - { L"VK_FINAL", 0x18, L"VK_FINAL" }, - { L"VK_HANJA", 0x19, L"VK_HANJA" }, - { L"VK_KANJI", 0x19, L"VK_KANJI" }, - { L"VK_ESCAPE", 0x1B, L"Esc" }, - { L"VK_CONVERT", 0x1C, L"VK_CONVERT" }, - { L"VK_NONCONVERT", 0x1D, L"VK_NONCONVERT" }, - { L"VK_ACCEPT", 0x1E, L"VK_ACCEPT" }, - { L"VK_MODECHANGE", 0x1F, L"VK_MODECHANGE" }, - { L"VK_SPACE", 0x20, L"Space" }, - { L"VK_PRIOR", 0x21, L"Page Up" }, - { L"VK_NEXT", 0x22, L"Page Down" }, - { L"VK_END", 0x23, L"End" }, - { L"VK_HOME", 0x24, L"Home" }, - { L"VK_LEFT", 0x25, L"Left" }, - { L"VK_UP", 0x26, L"Up" }, - { L"VK_RIGHT", 0x27, L"Right" }, - { L"VK_DOWN", 0x28, L"Down" }, - { L"VK_SELECT", 0x29, L"VK_SELECT" }, - { L"VK_PRINT", 0x2A, L"VK_PRINT" }, - { L"VK_EXECUTE", 0x2B, L"VK_EXECUTE" }, - { L"VK_SNAPSHOT", 0x2C, L"VK_SNAPSHOT" }, - { L"VK_INSERT", 0x2D, L"Insert" }, - { L"VK_DELETE", 0x2E, L"Delete" }, - { L"VK_HELP", 0x2F, L"Help" }, - { L"VK_0", 0x30, L"0" }, - { L"VK_1", 0x31, L"1" }, - { L"VK_2", 0x32, L"2" }, - { L"VK_3", 0x33, L"3" }, - { L"VK_4", 0x34, L"4" }, - { L"VK_5", 0x35, L"5" }, - { L"VK_6", 0x36, L"6" }, - { L"VK_7", 0x37, L"7" }, - { L"VK_8", 0x38, L"8" }, - { L"VK_9", 0x39, L"9" }, - { L"VK_A", 0x41, L"A" }, - { L"VK_B", 0x42, L"B" }, - { L"VK_C", 0x43, L"C" }, - { L"VK_D", 0x44, L"D" }, - { L"VK_E", 0x45, L"E" }, - { L"VK_F", 0x46, L"F" }, - { L"VK_G", 0x47, L"G" }, - { L"VK_H", 0x48, L"H" }, - { L"VK_I", 0x49, L"I" }, - { L"VK_J", 0x4A, L"J" }, - { L"VK_K", 0x4B, L"K" }, - { L"VK_L", 0x4C, L"L" }, - { L"VK_M", 0x4D, L"M" }, - { L"VK_N", 0x4E, L"N" }, - { L"VK_O", 0x4F, L"O" }, - { L"VK_P", 0x50, L"P" }, - { L"VK_Q", 0x51, L"Q" }, - { L"VK_R", 0x52, L"R" }, - { L"VK_S", 0x53, L"S" }, - { L"VK_T", 0x54, L"T" }, - { L"VK_U", 0x55, L"U" }, - { L"VK_V", 0x56, L"V" }, - { L"VK_W", 0x57, L"W" }, - { L"VK_X", 0x58, L"X" }, - { L"VK_Y", 0x59, L"Y" }, - { L"VK_Z", 0x5A, L"Z" }, - { L"VK_LWIN", 0x5B, L"VK_LWIN" }, - { L"VK_RWIN", 0x5C, L"VK_RWIN" }, - { L"VK_APPS", 0x5D, L"VK_APPS" }, - { L"VK_SLEEP", 0x5D, L"VK_SLEEP" }, - { L"VK_NUMPAD0", 0x60, L"Numpad0" }, - { L"VK_NUMPAD1", 0x61, L"Numpad1" }, - { L"VK_NUMPAD2", 0x62, L"Numpad2" }, - { L"VK_NUMPAD3", 0x63, L"Numpad3" }, - { L"VK_NUMPAD4", 0x64, L"Numpad4" }, - { L"VK_NUMPAD5", 0x65, L"Numpad5" }, - { L"VK_NUMPAD6", 0x66, L"Numpad6" }, - { L"VK_NUMPAD7", 0x67, L"Numpad7" }, - { L"VK_NUMPAD8", 0x68, L"Numpad8" }, - { L"VK_NUMPAD9", 0x69, L"Numpad9" }, - { L"VK_MULTIPLY", 0x6A, L"*" }, - { L"VK_ADD", 0x6B, L"+" }, - { L"VK_SEPARATOR", 0x6C, L"" }, - { L"VK_SUBTRACT", 0x6D, L"-" }, - { L"VK_DECIMAL", 0x6E, L"." }, - { L"VK_DIVIDE", 0x6F, L"/" }, - { L"VK_F1", 0x70, L"F1" }, - { L"VK_F2", 0x71, L"F2" }, - { L"VK_F3", 0x72, L"F3" }, - { L"VK_F4", 0x73, L"F4" }, - { L"VK_F5", 0x74, L"F5" }, - { L"VK_F6", 0x75, L"F6" }, - { L"VK_F7", 0x76, L"F7" }, - { L"VK_F8", 0x77, L"F8" }, - { L"VK_F9", 0x78, L"F9" }, - { L"VK_F10", 0x79, L"F10" }, - { L"VK_F11", 0x7A, L"F11" }, - { L"VK_F12", 0x7B, L"F12" }, - { L"VK_F13", 0x7C, L"F13" }, - { L"VK_F14", 0x7D, L"F14" }, - { L"VK_F15", 0x7E, L"F15" }, - { L"VK_F16", 0x7F, L"F16" }, - { L"VK_F17", 0x80, L"F17" }, - { L"VK_F18", 0x81, L"F18" }, - { L"VK_F19", 0x82, L"F19" }, - { L"VK_F20", 0x83, L"F20" }, - { L"VK_F21", 0x84, L"F21" }, - { L"VK_F22", 0x85, L"F22" }, - { L"VK_F23", 0x86, L"F23" }, - { L"VK_F24", 0x87, L"F24" }, - { L"VK_NUMLOCK", 0x90, L"Numlock" }, - { L"VK_SCROLL", 0x91, L"VK_SCROLL" }, - { L"VK_LSHIFT", 0xA0, L"VK_LSHIFT" }, - { L"VK_RSHIFT", 0xA1, L"VK_RSHIFT" }, - { L"VK_LCONTROL", 0xA2, L"VK_LCONTROL" }, - { L"VK_RCONTROL", 0xA3, L"VK_RCONTROL" }, - { L"VK_LMENU", 0xA4, L"VK_LMENU" }, - { L"VK_RMENU", 0xA5, L"VK_RMENU" }, - { L"VK_BROWSER_BACK", 0xA6, L"" }, - { L"VK_BROWSER_FORWARD", 0xA7, L"" }, - { L"VK_BROWSER_REFRESH", 0xA8, L"" }, - { L"VK_BROWSER_STOP", 0xA9, L"" }, - { L"VK_BROWSER_SEARCH", 0xAA, L"" }, - { L"VK_BROWSER_FAVORITES", 0xAB, L"" }, - { L"VK_BROWSER_HOME", 0xAC, L"" }, - { L"VK_VOLUME_MUTE", 0xAD, L"" }, - { L"VK_VOLUME_DOWN", 0xAE, L"" }, - { L"VK_VOLUME_UP", 0xAF, L"" }, - { L"VK_MEDIA_NEXT_TRACK", 0xB0, L"" }, - { L"VK_MEDIA_PREV_TRACK", 0xB1, L"" }, - { L"VK_MEDIA_STOP", 0xB2, L"" }, - { L"VK_MEDIA_PLAY_PAUSE", 0xB3, L"" }, - { L"VK_LAUNCH_MAIL", 0xB4, L"" }, - { L"VK_LAUNCH_MEDIA_SELECT", 0xB5, L"" }, - { L"VK_LAUNCH_APP1", 0xB6, L"" }, - { L"VK_LAUNCH_APP2", 0xB7, L"" }, - { L"VK_OEM_1 (;:)", 0xBA, L"" }, - { L"VK_OEM_PLUS", 0xBB, L"+" }, - { L"VK_OEM_COMMA", 0xBC, L"" }, - { L"VK_OEM_MINUS", 0xBD, L"-" }, - { L"VK_OEM_PERIOD", 0xBE, L"." }, - { L"VK_OEM_2 (/?)", 0xBF, L"" }, - { L"VK_OEM_3 (`~)", 0xC0, L"~" }, - { L"VK_ATTN", 0xF6, L"" }, - { L"VK_CRSEL", 0xF7, L"" }, - { L"VK_EXSEL", 0xF8, L"" }, - { L"VK_EREOF", 0xF9, L"" }, - { L"VK_PLAY", 0xFA, L"" }, - { L"VK_ZOOM", 0xFB, L"" }, - { L"VK_NONAME", 0xFC, L"" }, - { L"VK_PA1", 0xFD, L"" }, - { L"VK_OEM_CLEAR", 0xFE, L"" } + {L"VK_LBUTTON", 0x01, L"VK_LBUTTON"}, + {L"VK_RBUTTON", 0x02, L"VK_RBUTTON"}, + {L"VK_CANCEL", 0x03, L"VK_CANCEL"}, + {L"VK_MBUTTON", 0x04, L"VK_MBUTTON"}, + {L"VK_XBUTTON1", 0x05, L"VK_XBUTTON1"}, + {L"VK_XBUTTON2", 0x06, L"VK_XBUTTON2"}, + {L"VK_BACK", 0x08, L"VK_BACK"}, + {L"VK_TAB", 0x09, L"VK_TAB"}, + {L"VK_CLEAR", 0x0C, L"VK_CLEAR"}, + {L"VK_RETURN", 0x0D, L"Return"}, + {L"VK_SHIFT", 0x10, L"VK_SHIFT"}, + {L"VK_CONTROL", 0x11, L"VK_CONTROL"}, + {L"VK_MENU", 0x12, L"VK_MENU"}, + {L"VK_PAUSE", 0x13, L"Pause"}, + {L"VK_CAPITAL", 0x14, L"VK_CAPITAL"}, + {L"VK_KANA", 0x15, L"VK_KANA"}, + {L"VK_HANGUL", 0x15, L"VK_HANGUL"}, + {L"VK_JUNJA", 0x17, L"VK_JUNJA"}, + {L"VK_FINAL", 0x18, L"VK_FINAL"}, + {L"VK_HANJA", 0x19, L"VK_HANJA"}, + {L"VK_KANJI", 0x19, L"VK_KANJI"}, + {L"VK_ESCAPE", 0x1B, L"Esc"}, + {L"VK_CONVERT", 0x1C, L"VK_CONVERT"}, + {L"VK_NONCONVERT", 0x1D, L"VK_NONCONVERT"}, + {L"VK_ACCEPT", 0x1E, L"VK_ACCEPT"}, + {L"VK_MODECHANGE", 0x1F, L"VK_MODECHANGE"}, + {L"VK_SPACE", 0x20, L"Space"}, + {L"VK_PRIOR", 0x21, L"Page Up"}, + {L"VK_NEXT", 0x22, L"Page Down"}, + {L"VK_END", 0x23, L"End"}, + {L"VK_HOME", 0x24, L"Home"}, + {L"VK_LEFT", 0x25, L"Left"}, + {L"VK_UP", 0x26, L"Up"}, + {L"VK_RIGHT", 0x27, L"Right"}, + {L"VK_DOWN", 0x28, L"Down"}, + {L"VK_SELECT", 0x29, L"VK_SELECT"}, + {L"VK_PRINT", 0x2A, L"VK_PRINT"}, + {L"VK_EXECUTE", 0x2B, L"VK_EXECUTE"}, + {L"VK_SNAPSHOT", 0x2C, L"VK_SNAPSHOT"}, + {L"VK_INSERT", 0x2D, L"Insert"}, + {L"VK_DELETE", 0x2E, L"Delete"}, + {L"VK_HELP", 0x2F, L"Help"}, + {L"VK_0", 0x30, L"0"}, + {L"VK_1", 0x31, L"1"}, + {L"VK_2", 0x32, L"2"}, + {L"VK_3", 0x33, L"3"}, + {L"VK_4", 0x34, L"4"}, + {L"VK_5", 0x35, L"5"}, + {L"VK_6", 0x36, L"6"}, + {L"VK_7", 0x37, L"7"}, + {L"VK_8", 0x38, L"8"}, + {L"VK_9", 0x39, L"9"}, + {L"VK_A", 0x41, L"A"}, + {L"VK_B", 0x42, L"B"}, + {L"VK_C", 0x43, L"C"}, + {L"VK_D", 0x44, L"D"}, + {L"VK_E", 0x45, L"E"}, + {L"VK_F", 0x46, L"F"}, + {L"VK_G", 0x47, L"G"}, + {L"VK_H", 0x48, L"H"}, + {L"VK_I", 0x49, L"I"}, + {L"VK_J", 0x4A, L"J"}, + {L"VK_K", 0x4B, L"K"}, + {L"VK_L", 0x4C, L"L"}, + {L"VK_M", 0x4D, L"M"}, + {L"VK_N", 0x4E, L"N"}, + {L"VK_O", 0x4F, L"O"}, + {L"VK_P", 0x50, L"P"}, + {L"VK_Q", 0x51, L"Q"}, + {L"VK_R", 0x52, L"R"}, + {L"VK_S", 0x53, L"S"}, + {L"VK_T", 0x54, L"T"}, + {L"VK_U", 0x55, L"U"}, + {L"VK_V", 0x56, L"V"}, + {L"VK_W", 0x57, L"W"}, + {L"VK_X", 0x58, L"X"}, + {L"VK_Y", 0x59, L"Y"}, + {L"VK_Z", 0x5A, L"Z"}, + {L"VK_LWIN", 0x5B, L"VK_LWIN"}, + {L"VK_RWIN", 0x5C, L"VK_RWIN"}, + {L"VK_APPS", 0x5D, L"VK_APPS"}, + {L"VK_SLEEP", 0x5D, L"VK_SLEEP"}, + {L"VK_NUMPAD0", 0x60, L"Numpad0"}, + {L"VK_NUMPAD1", 0x61, L"Numpad1"}, + {L"VK_NUMPAD2", 0x62, L"Numpad2"}, + {L"VK_NUMPAD3", 0x63, L"Numpad3"}, + {L"VK_NUMPAD4", 0x64, L"Numpad4"}, + {L"VK_NUMPAD5", 0x65, L"Numpad5"}, + {L"VK_NUMPAD6", 0x66, L"Numpad6"}, + {L"VK_NUMPAD7", 0x67, L"Numpad7"}, + {L"VK_NUMPAD8", 0x68, L"Numpad8"}, + {L"VK_NUMPAD9", 0x69, L"Numpad9"}, + {L"VK_MULTIPLY", 0x6A, L"*"}, + {L"VK_ADD", 0x6B, L"+"}, + {L"VK_SEPARATOR", 0x6C, L""}, + {L"VK_SUBTRACT", 0x6D, L"-"}, + {L"VK_DECIMAL", 0x6E, L"."}, + {L"VK_DIVIDE", 0x6F, L"/"}, + {L"VK_F1", 0x70, L"F1"}, + {L"VK_F2", 0x71, L"F2"}, + {L"VK_F3", 0x72, L"F3"}, + {L"VK_F4", 0x73, L"F4"}, + {L"VK_F5", 0x74, L"F5"}, + {L"VK_F6", 0x75, L"F6"}, + {L"VK_F7", 0x76, L"F7"}, + {L"VK_F8", 0x77, L"F8"}, + {L"VK_F9", 0x78, L"F9"}, + {L"VK_F10", 0x79, L"F10"}, + {L"VK_F11", 0x7A, L"F11"}, + {L"VK_F12", 0x7B, L"F12"}, + {L"VK_F13", 0x7C, L"F13"}, + {L"VK_F14", 0x7D, L"F14"}, + {L"VK_F15", 0x7E, L"F15"}, + {L"VK_F16", 0x7F, L"F16"}, + {L"VK_F17", 0x80, L"F17"}, + {L"VK_F18", 0x81, L"F18"}, + {L"VK_F19", 0x82, L"F19"}, + {L"VK_F20", 0x83, L"F20"}, + {L"VK_F21", 0x84, L"F21"}, + {L"VK_F22", 0x85, L"F22"}, + {L"VK_F23", 0x86, L"F23"}, + {L"VK_F24", 0x87, L"F24"}, + {L"VK_NUMLOCK", 0x90, L"Numlock"}, + {L"VK_SCROLL", 0x91, L"VK_SCROLL"}, + {L"VK_LSHIFT", 0xA0, L"VK_LSHIFT"}, + {L"VK_RSHIFT", 0xA1, L"VK_RSHIFT"}, + {L"VK_LCONTROL", 0xA2, L"VK_LCONTROL"}, + {L"VK_RCONTROL", 0xA3, L"VK_RCONTROL"}, + {L"VK_LMENU", 0xA4, L"VK_LMENU"}, + {L"VK_RMENU", 0xA5, L"VK_RMENU"}, + {L"VK_BROWSER_BACK", 0xA6, L""}, + {L"VK_BROWSER_FORWARD", 0xA7, L""}, + {L"VK_BROWSER_REFRESH", 0xA8, L""}, + {L"VK_BROWSER_STOP", 0xA9, L""}, + {L"VK_BROWSER_SEARCH", 0xAA, L""}, + {L"VK_BROWSER_FAVORITES", 0xAB, L""}, + {L"VK_BROWSER_HOME", 0xAC, L""}, + {L"VK_VOLUME_MUTE", 0xAD, L""}, + {L"VK_VOLUME_DOWN", 0xAE, L""}, + {L"VK_VOLUME_UP", 0xAF, L""}, + {L"VK_MEDIA_NEXT_TRACK", 0xB0, L""}, + {L"VK_MEDIA_PREV_TRACK", 0xB1, L""}, + {L"VK_MEDIA_STOP", 0xB2, L""}, + {L"VK_MEDIA_PLAY_PAUSE", 0xB3, L""}, + {L"VK_LAUNCH_MAIL", 0xB4, L""}, + {L"VK_LAUNCH_MEDIA_SELECT", 0xB5, L""}, + {L"VK_LAUNCH_APP1", 0xB6, L""}, + {L"VK_LAUNCH_APP2", 0xB7, L""}, + {L"VK_OEM_1 (;:)", 0xBA, L""}, + {L"VK_OEM_PLUS", 0xBB, L"+"}, + {L"VK_OEM_COMMA", 0xBC, L""}, + {L"VK_OEM_MINUS", 0xBD, L"-"}, + {L"VK_OEM_PERIOD", 0xBE, L"."}, + {L"VK_OEM_2 (/?)", 0xBF, L""}, + {L"VK_OEM_3 (`~)", 0xC0, L"~"}, + {L"VK_ATTN", 0xF6, L""}, + {L"VK_CRSEL", 0xF7, L""}, + {L"VK_EXSEL", 0xF8, L""}, + {L"VK_EREOF", 0xF9, L""}, + {L"VK_PLAY", 0xFA, L""}, + {L"VK_ZOOM", 0xFB, L""}, + {L"VK_NONAME", 0xFC, L""}, + {L"VK_PA1", 0xFD, L""}, + {L"VK_OEM_CLEAR", 0xFE, L""}, }; CMenuShortCutKey::CMenuShortCutKey(WORD key, bool bCtrl, bool bAlt, bool bShift, ACCESS_MODE AccessMode, bool bUserAdded, bool bInactive) : @@ -186,9 +186,18 @@ CMenuShortCutKey::CMenuShortCutKey(WORD key, bool bCtrl, bool bAlt, bool bShift, } } stdstr ShortCutName = stdstr().FromUTF16(m_ShortCutName.c_str()); - if (m_bShift) { ShortCutName = stdstr_f("Shift+%s", ShortCutName.c_str()); } - if (m_bCtrl) { ShortCutName = stdstr_f("Ctrl+%s", ShortCutName.c_str()); } - if (m_bAlt) { ShortCutName = stdstr_f("Alt+%s", ShortCutName.c_str()); } + if (m_bShift) + { + ShortCutName = stdstr_f("Shift+%s", ShortCutName.c_str()); + } + if (m_bCtrl) + { + ShortCutName = stdstr_f("Ctrl+%s", ShortCutName.c_str()); + } + if (m_bAlt) + { + ShortCutName = stdstr_f("Alt+%s", ShortCutName.c_str()); + } m_ShortCutName = ShortCutName.ToUTF16(); } @@ -209,11 +218,26 @@ CMenuShortCutKey::RUNNING_STATE CMenuShortCutKey::RunningState(void) bool CMenuShortCutKey::Match(WORD key, bool bCtrl, bool bAlt, bool bShift, RUNNING_STATE RunningState) const { - if (key != m_key) { return false; } - if (bShift != m_bShift) { return false; } - if (bCtrl != m_bCtrl) { return false; } - if (bAlt != m_bAlt) { return false; } - if (!Active(RunningState)) { return false; } + if (key != m_key) + { + return false; + } + if (bShift != m_bShift) + { + return false; + } + if (bCtrl != m_bCtrl) + { + return false; + } + if (bAlt != m_bAlt) + { + return false; + } + if (!Active(RunningState)) + { + return false; + } return true; } @@ -222,26 +246,19 @@ bool CMenuShortCutKey::Active(RUNNING_STATE RunningState) const switch (RunningState) { case CMenuShortCutKey::RUNNING_STATE_NOT_RUNNING: - if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_NOT_RUNNING || - m_AccessMode == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || - m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_NOT_RUNNING || m_AccessMode == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } break; case CMenuShortCutKey::RUNNING_STATE_WINDOWED: - if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING_WINDOW || - m_AccessMode == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || - m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING || - m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING_WINDOW || m_AccessMode == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING || m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } break; case CMenuShortCutKey::RUNNING_STATE_FULLSCREEN: - if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING_FULLSCREEN || - m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING || - m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING_FULLSCREEN || m_AccessMode == CMenuShortCutKey::ACCESS_GAME_RUNNING || m_AccessMode == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } @@ -293,26 +310,19 @@ bool CShortCutItem::Avaliable(CMenuShortCutKey::RUNNING_STATE RunningState) cons switch (RunningState) { case CMenuShortCutKey::RUNNING_STATE_NOT_RUNNING: - if (m_Access == CMenuShortCutKey::ACCESS_GAME_NOT_RUNNING || - m_Access == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || - m_Access == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_Access == CMenuShortCutKey::ACCESS_GAME_NOT_RUNNING || m_Access == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || m_Access == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } break; case CMenuShortCutKey::RUNNING_STATE_WINDOWED: - if (m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING_WINDOW || - m_Access == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || - m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING || - m_Access == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING_WINDOW || m_Access == CMenuShortCutKey::ACCESS_NOT_IN_FULLSCREEN || m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING || m_Access == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } break; case CMenuShortCutKey::RUNNING_STATE_FULLSCREEN: - if (m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING_FULLSCREEN || - m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING || - m_Access == CMenuShortCutKey::ACCESS_ANYTIME) + if (m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING_FULLSCREEN || m_Access == CMenuShortCutKey::ACCESS_GAME_RUNNING || m_Access == CMenuShortCutKey::ACCESS_ANYTIME) { return true; } @@ -337,7 +347,10 @@ std::wstring CShortCuts::ShortCutString(int MenuID, CMenuShortCutKey::RUNNING_ST CGuard CS(m_CS); MSC_MAP::iterator MenuItem = m_ShortCuts.find(MenuID); - if (MenuItem == m_ShortCuts.end()) { return L""; } + if (MenuItem == m_ShortCuts.end()) + { + return L""; + } const SHORTCUT_KEY_LIST & ShortCutList = MenuItem->second.GetAccelItems(); for (SHORTCUT_KEY_LIST::const_iterator item = ShortCutList.begin(); item != ShortCutList.end(); item++) @@ -361,8 +374,14 @@ LanguageStringID CShortCuts::GetMenuItemName(WORD key, bool bCtrl, bool bAlt, bo for (SHORTCUT_KEY_LIST::const_iterator AccelItem = short_cut.GetAccelItems().begin(); AccelItem != short_cut.GetAccelItems().end(); AccelItem++) { - if (AccelItem->Inactive()) { continue; } - if (!AccelItem->Match(key, bCtrl, bAlt, bShift, RunningState)) { continue; } + if (AccelItem->Inactive()) + { + continue; + } + if (!AccelItem->Match(key, bCtrl, bAlt, bShift, RunningState)) + { + continue; + } return short_cut.Title(); } } @@ -491,7 +510,10 @@ void CShortCuts::Load(bool InitialValues) &bUserAdded, &bInactive); MSC_MAP::iterator item = m_ShortCuts.find(ID); - if (item == m_ShortCuts.end()) { continue; } + if (item == m_ShortCuts.end()) + { + continue; + } item->second.AddShortCut((WORD)(key & 0xFFFF), bCtrl == 1, bAlt == 1, bShift == 1, AccessMode, bUserAdded == 1, bInactive == 1); } } while (feof(file) == 0); @@ -558,13 +580,25 @@ HACCEL CShortCuts::GetAcceleratorTable(void) { continue; } - if (size >= MaxSize) { break; } + if (size >= MaxSize) + { + break; + } AccelList[size].cmd = (WORD)Item->first; AccelList[size].key = Key.Key(); AccelList[size].fVirt = FVIRTKEY; - if (Key.Alt()) { AccelList[size].fVirt |= FALT; } - if (Key.Ctrl()) { AccelList[size].fVirt |= FCONTROL; } - if (Key.Shift()) { AccelList[size].fVirt |= FSHIFT; } + if (Key.Alt()) + { + AccelList[size].fVirt |= FALT; + } + if (Key.Ctrl()) + { + AccelList[size].fVirt |= FCONTROL; + } + if (Key.Shift()) + { + AccelList[size].fVirt |= FSHIFT; + } size += 1; } } diff --git a/Source/Project64/UserInterface/MenuShortCuts.h b/Source/Project64/UserInterface/MenuShortCuts.h index f964b290f..760ffac94 100644 --- a/Source/Project64/UserInterface/MenuShortCuts.h +++ b/Source/Project64/UserInterface/MenuShortCuts.h @@ -34,19 +34,46 @@ public: bool Match(WORD key, bool bCtrl, bool bAlt, bool bShift, RUNNING_STATE RunningState) const; bool Active(RUNNING_STATE RunningState) const; - static VIRTUAL_KEY * VirtualKeyList(int &Size); + static VIRTUAL_KEY * VirtualKeyList(int & Size); static RUNNING_STATE RunningState(void); - inline const std::wstring & Name(void) const { return m_ShortCutName; } - inline WORD Key(void) const { return m_key; } - inline bool Ctrl(void) const { return m_bCtrl; } - inline bool Alt(void) const { return m_bAlt; } - inline bool Shift(void) const { return m_bShift; } - inline bool UserAdded(void) const { return m_bUserAdded; } - inline bool Inactive(void) const { return m_bInactive; } - inline ACCESS_MODE AccessMode(void) const { return m_AccessMode; } + inline const std::wstring & Name(void) const + { + return m_ShortCutName; + } + inline WORD Key(void) const + { + return m_key; + } + inline bool Ctrl(void) const + { + return m_bCtrl; + } + inline bool Alt(void) const + { + return m_bAlt; + } + inline bool Shift(void) const + { + return m_bShift; + } + inline bool UserAdded(void) const + { + return m_bUserAdded; + } + inline bool Inactive(void) const + { + return m_bInactive; + } + inline ACCESS_MODE AccessMode(void) const + { + return m_AccessMode; + } - inline void SetInactive(bool Inactive) { m_bInactive = Inactive; } + inline void SetInactive(bool Inactive) + { + m_bInactive = Inactive; + } private: static VIRTUAL_KEY m_VirtualKeyList[]; @@ -64,16 +91,16 @@ private: class CShortCutItem { public: - typedef std::list SHORTCUT_KEY_LIST; + typedef std::list SHORTCUT_KEY_LIST; private: typedef CMenuShortCutKey::ACCESS_MODE ACCESS_MODE; typedef CMenuShortCutKey::RUNNING_STATE RUNNING_STATE; - ACCESS_MODE m_Access; - LanguageStringID m_Section; - LanguageStringID m_Title; - SHORTCUT_KEY_LIST m_AccelList; + ACCESS_MODE m_Access; + LanguageStringID m_Section; + LanguageStringID m_Title; + SHORTCUT_KEY_LIST m_AccelList; public: CShortCutItem(LanguageStringID Section, LanguageStringID Title, ACCESS_MODE Access); @@ -82,13 +109,25 @@ public: void RemoveItem(CMenuShortCutKey * ShortCut); bool Avaliable(RUNNING_STATE RunningState) const; - inline const SHORTCUT_KEY_LIST & GetAccelItems(void) const { return m_AccelList; } - inline LanguageStringID Section(void) const { return m_Section; } - inline LanguageStringID Title(void) const { return m_Title; } - inline ACCESS_MODE AccessMode(void) const { return m_Access; } + inline const SHORTCUT_KEY_LIST & GetAccelItems(void) const + { + return m_AccelList; + } + inline LanguageStringID Section(void) const + { + return m_Section; + } + inline LanguageStringID Title(void) const + { + return m_Title; + } + inline ACCESS_MODE AccessMode(void) const + { + return m_Access; + } }; -typedef std::map MSC_MAP; +typedef std::map MSC_MAP; class CShortCuts { @@ -96,6 +135,7 @@ class CShortCuts typedef CMenuShortCutKey::ACCESS_MODE ACCESS_MODE; typedef CMenuShortCutKey::RUNNING_STATE RUNNING_STATE; typedef LanguageStringID LangStr; + public: CShortCuts(void); ~CShortCuts(void); @@ -103,7 +143,10 @@ public: std::wstring ShortCutString(int MenuID, RUNNING_STATE RunningState); LangStr GetMenuItemName(WORD key, bool bCtrl, bool bAlt, bool bShift, RUNNING_STATE RunningState); HACCEL GetAcceleratorTable(void); - const MSC_MAP & GetShortCuts(void) const { return m_ShortCuts; } + const MSC_MAP & GetShortCuts(void) const + { + return m_ShortCuts; + } void Load(bool InitialValues = false); void Save(void); diff --git a/Source/Project64/UserInterface/Notification.cpp b/Source/Project64/UserInterface/Notification.cpp index 492f77bfc..4d86d4235 100644 --- a/Source/Project64/UserInterface/Notification.cpp +++ b/Source/Project64/UserInterface/Notification.cpp @@ -90,7 +90,10 @@ void CNotificationImp::DisplayMessage(int DisplayTime, LanguageStringID StringID void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) const { - if (!m_hWnd) { return; } + if (!m_hWnd) + { + return; + } if (m_NextMsg > 0 || DisplayTime > 0) { @@ -126,7 +129,10 @@ void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) con void CNotificationImp::DisplayMessage2(const char * Message) const { - if (!m_hWnd) { return; } + if (!m_hWnd) + { + return; + } m_hWnd->SetStatusText(1, stdstr(Message).ToUTF16().c_str()); } @@ -155,13 +161,16 @@ void CNotificationImp::FatalError(LanguageStringID StringID) const FatalError(g_Lang->GetString(StringID).c_str()); } -void CNotificationImp::FatalError(const char * Message) const +void CNotificationImp::FatalError(const char * Message) const { WriteTrace(TraceUserInterface, TraceError, Message); WindowMode(); HWND Parent = nullptr; - if (m_hWnd) { Parent = reinterpret_cast(m_hWnd->GetWindowHandle()); } + if (m_hWnd) + { + Parent = reinterpret_cast(m_hWnd->GetWindowHandle()); + } MessageBox(Parent, stdstr(Message).ToUTF16().c_str(), L"Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); ExitThread(0); } @@ -169,7 +178,10 @@ void CNotificationImp::FatalError(const char * Message) const void CNotificationImp::AddRecentDir(const char * RomDir) { // Validate the passed string - if (HIWORD(RomDir) == NULL) { return; } + if (HIWORD(RomDir) == NULL) + { + return; + } // Get information about the stored ROM list size_t MaxRememberedDirs = UISettingsLoadDword(Directory_RecentGameDirCount); @@ -210,20 +222,29 @@ void CNotificationImp::AddRecentDir(const char * RomDir) void CNotificationImp::RefreshMenu(void) { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } m_hWnd->RefreshMenu(); } void CNotificationImp::HideRomBrowser(void) { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } m_hWnd->HideRomList(); } void CNotificationImp::ShowRomBrowser(void) { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } if (UISettingsLoadBool(RomBrowser_Enabled)) { // Display the ROM browser @@ -234,20 +255,29 @@ void CNotificationImp::ShowRomBrowser(void) void CNotificationImp::BringToTop(void) { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } m_hWnd->BringToTop(); } void CNotificationImp::ChangeFullScreen(void) const { - if (m_hWnd == nullptr) { return; } + if (m_hWnd == nullptr) + { + return; + } SendMessage((HWND)(m_hWnd->GetWindowHandle()), WM_COMMAND, MAKELPARAM(ID_OPTIONS_FULLSCREEN2, false), 0); } bool CNotificationImp::ProcessGuiMessages(void) const { - if (m_hWnd == nullptr) { return false; } + if (m_hWnd == nullptr) + { + return false; + } return m_hWnd->ProcessGuiMessages(); } diff --git a/Source/Project64/UserInterface/Notification.h b/Source/Project64/UserInterface/Notification.h index 034a813c1..45a6c3f08 100644 --- a/Source/Project64/UserInterface/Notification.h +++ b/Source/Project64/UserInterface/Notification.h @@ -54,10 +54,10 @@ public: void SetGfxPlugin(CGfxPlugin * Plugin); private: - CNotificationImp(const CNotificationImp&); - CNotificationImp& operator=(const CNotificationImp&); + CNotificationImp(const CNotificationImp &); + CNotificationImp & operator=(const CNotificationImp &); - CMainGui * m_hWnd; + CMainGui * m_hWnd; CGfxPlugin * m_gfxPlugin; mutable time_t m_NextMsg; diff --git a/Source/Project64/UserInterface/ProjectSupport.cpp b/Source/Project64/UserInterface/ProjectSupport.cpp index 2d588950a..982e557ce 100644 --- a/Source/Project64/UserInterface/ProjectSupport.cpp +++ b/Source/Project64/UserInterface/ProjectSupport.cpp @@ -51,11 +51,9 @@ bool CProjectSupport::ValidateCode(const char * Code) { const char * Key; std::string & Value; - } - Test[] = - { - { "SupporterName: ", Name }, - { "SupporterEmail: ", Email }, + } Test[] = { + {"SupporterName: ", Name}, + {"SupporterEmail: ", Email}, }; for (size_t i = 0, n = Headers.size(); i < n; i++) @@ -150,10 +148,9 @@ bool CProjectSupport::PerformRequest(const wchar_t * Url, const std::string & Po { return false; } - LPCWSTR lpszAcceptTypes[] = - { + LPCWSTR lpszAcceptTypes[] = { L"text/*", - nullptr + nullptr, }; HINTERNET hRequest = HttpOpenRequest(hConnect, L"POST", Url, nullptr, nullptr, lpszAcceptTypes, INTERNET_FLAG_SECURE | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE, (LPARAM)0); if (hRequest == nullptr) diff --git a/Source/Project64/UserInterface/ProjectSupport.h b/Source/Project64/UserInterface/ProjectSupport.h index 4d945f2a3..c51231efa 100644 --- a/Source/Project64/UserInterface/ProjectSupport.h +++ b/Source/Project64/UserInterface/ProjectSupport.h @@ -24,14 +24,26 @@ public: void IncrementRunCount(); bool ShowSuppotWindow(); - inline uint32_t RunCount() const { return m_SupportInfo.RunCount; } - inline const char * Name(void) const { return m_SupportInfo.Name; } - inline const char * MachineID(void) const { return m_SupportInfo.MachineID; } - inline bool Validated(void) const { return m_SupportInfo.Validated; } + inline uint32_t RunCount() const + { + return m_SupportInfo.RunCount; + } + inline const char * Name(void) const + { + return m_SupportInfo.Name; + } + inline const char * MachineID(void) const + { + return m_SupportInfo.MachineID; + } + inline bool Validated(void) const + { + return m_SupportInfo.Validated; + } private: - CProjectSupport(const CProjectSupport&); - CProjectSupport& operator=(const CProjectSupport&); + CProjectSupport(const CProjectSupport &); + CProjectSupport & operator=(const CProjectSupport &); std::string GenerateMachineID(); bool PerformRequest(const wchar_t * Url, const std::string & PostData, DWORD & StatusCode, std::vector & Headers); diff --git a/Source/Project64/UserInterface/RomBrowser.cpp b/Source/Project64/UserInterface/RomBrowser.cpp index 066b43a8b..9462ef842 100644 --- a/Source/Project64/UserInterface/RomBrowser.cpp +++ b/Source/Project64/UserInterface/RomBrowser.cpp @@ -86,9 +86,15 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) size_t index; for (index = 0; index < m_Fields.size(); index++) { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) + { + break; + } + } + if (index >= m_Fields.size()) + { + continue; } - if (index >= m_Fields.size()) { continue; } SORT_FIELD SortFieldInfo; SortFieldInfo._this = this; SortFieldInfo.Key = index; @@ -184,7 +190,10 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) memset(&lvItem, 0, sizeof(lvItem)); lvItem.mask = LVIF_PARAM; lvItem.iItem = NewTestPos; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return End; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return End; + } Result = RomList_CompareItems(lParam, lvItem.lParam, (uint32_t)&SortFieldInfo); if (Result >= 0) @@ -218,9 +227,15 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) size_t index; for (index = 0; index < m_Fields.size(); index++) { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) + { + break; + } + } + if (index >= m_Fields.size()) + { + continue; } - if (index >= m_Fields.size()) { continue; } SORT_FIELD SortFieldInfo; SortFieldInfo._this = this; SortFieldInfo.Key = index; @@ -230,7 +245,10 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) memset(&lvItem, 0, sizeof(LVITEM)); lvItem.mask = LVIF_PARAM; lvItem.iItem = End; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return End; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return End; + } int32_t Result = RomList_CompareItems(lParam, lvItem.lParam, (uint32_t)&SortFieldInfo); if (Result < 0) @@ -324,7 +342,10 @@ void CRomBrowser::HighLightLastRom(void) m_LastRom = UISettingsLoadStringIndex(File_RecentGameFileIndex, 0); // Make sure ROM browser is visible - if (!RomBrowserVisible()) { return; } + if (!RomBrowserVisible()) + { + return; + } LVITEM lvItem; lvItem.mask = LVIF_PARAM; @@ -334,7 +355,10 @@ void CRomBrowser::HighLightLastRom(void) { // Get The next item lvItem.iItem = index; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return; + } // Get the ROM info for that item if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) @@ -363,7 +387,10 @@ void CRomBrowser::MenuSetText(HMENU hMenu, int32_t MenuPos, const wchar_t * Titl MENUITEMINFO MenuInfo; wchar_t String[256]; - if (Title == nullptr || wcslen(Title) == 0) { return; } + if (Title == nullptr || wcslen(Title) == 0) + { + return; + } memset(&MenuInfo, 0, sizeof(MENUITEMINFO)); MenuInfo.cbSize = sizeof(MENUITEMINFO); @@ -375,8 +402,14 @@ void CRomBrowser::MenuSetText(HMENU hMenu, int32_t MenuPos, const wchar_t * Titl GetMenuItemInfo(hMenu, MenuPos, TRUE, &MenuInfo); wcscpy(String, Title); - if (wcschr(String, '\t') != nullptr) { *(wcschr(String, '\t')) = '\0'; } - if (ShortCut) { swprintf(String, sizeof(String) / sizeof(String[0]), L"%s\t%s", String, stdstr(ShortCut).ToUTF16().c_str()); } + if (wcschr(String, '\t') != nullptr) + { + *(wcschr(String, '\t')) = '\0'; + } + if (ShortCut) + { + swprintf(String, sizeof(String) / sizeof(String[0]), L"%s\t%s", String, stdstr(ShortCut).ToUTF16().c_str()); + } SetMenuItemInfo(hMenu, MenuPos, TRUE, &MenuInfo); } @@ -405,7 +438,10 @@ void CRomBrowser::ResetRomBrowserColomuns(void) { for (index = 0; index < m_Fields.size(); index++) { - if (m_Fields[index].Pos() == Coloumn) { break; } + if (m_Fields[index].Pos() == Coloumn) + { + break; + } } if (index == m_Fields.size() || m_Fields[index].Pos() != Coloumn) { @@ -448,9 +484,18 @@ void CRomBrowser::ResizeRomList(WORD nWidth, WORD nHeight) bool CRomBrowser::RomBrowserVisible(void) { - if (!IsWindow(m_hRomList)) { return false; } - if (!IsWindowVisible(m_hRomList)) { return false; } - if (!m_Visible) { return false; } + if (!IsWindow(m_hRomList)) + { + return false; + } + if (!IsWindowVisible(m_hRomList)) + { + return false; + } + if (!m_Visible) + { + return false; + } return true; } @@ -467,7 +512,10 @@ void CRomBrowser::RomBrowserMaximize(bool Mazimize) bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) { - if (idCtrl != IDC_ROMLIST) { return false; } + if (idCtrl != IDC_ROMLIST) + { + return false; + } LPDRAWITEMSTRUCT ditem = (LPDRAWITEMSTRUCT)lParam; RECT rcItem, rcDraw; @@ -479,7 +527,10 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) lvItem.mask = LVIF_PARAM; lvItem.iItem = ditem->itemID; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return false; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return false; + } lvItem.state = ListView_GetItemState(m_hRomList, ditem->itemID, -1); bool bSelected = (lvItem.state & LVIS_SELECTED) != 0; @@ -564,16 +615,22 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) bool CRomBrowser::RomListNotify(int32_t idCtrl, uint32_t pnmh) { - if (idCtrl != IDC_ROMLIST) { return false; } - if (!RomBrowserVisible()) { return false; } + if (idCtrl != IDC_ROMLIST) + { + return false; + } + if (!RomBrowserVisible()) + { + return false; + } switch (((LPNMHDR)pnmh)->code) { case LVN_COLUMNCLICK: RomList_ColoumnSortList(pnmh); break; - case NM_RETURN: RomList_OpenRom(pnmh); break; - case NM_DBLCLK: RomList_OpenRom(pnmh); break; + case NM_RETURN: RomList_OpenRom(pnmh); break; + case NM_DBLCLK: RomList_OpenRom(pnmh); break; case LVN_GETDISPINFO: RomList_GetDispInfo(pnmh); break; - case NM_RCLICK: RomList_PopupMenu(pnmh); break; + case NM_RCLICK: RomList_PopupMenu(pnmh); break; case NM_CLICK: { LONG iItem = ListView_GetNextItem(m_hRomList, -1, LVNI_SELECTED); @@ -596,9 +653,15 @@ void CRomBrowser::RomList_ColoumnSortList(uint32_t pnmh) for (index = 0; index < m_Fields.size(); index++) { - if (m_Fields[index].Pos() == (size_t)pnmv->iSubItem) { break; } + if (m_Fields[index].Pos() == (size_t)pnmv->iSubItem) + { + break; + } + } + if (m_Fields.size() == index) + { + return; } - if (m_Fields.size() == index) { return; } if (_stricmp(UISettingsLoadStringIndex(RomBrowser_SortFieldIndex, 0).c_str(), m_Fields[index].Name()) == 0) { UISettingsSaveBoolIndex(RomBrowser_SortAscendingIndex, 0, !UISettingsLoadBoolIndex(RomBrowser_SortAscendingIndex, 0)); @@ -634,14 +697,14 @@ int32_t CALLBACK CRomBrowser::RomList_CompareItems(uint32_t lParam1, uint32_t lP ROM_INFO * pRomInfo2 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam2 : lParam1]; int32_t result; - const char * GoodName1 = nullptr, *GoodName2 = nullptr; + const char *GoodName1 = nullptr, *GoodName2 = nullptr; if (SortFieldInfo->Key == RB_GoodName) { GoodName1 = strcmp("#340#", pRomInfo1->GoodName) != 0 ? pRomInfo1->GoodName : m_UnknownGoodName.c_str(); GoodName2 = strcmp("#340#", pRomInfo2->GoodName) != 0 ? pRomInfo2->GoodName : m_UnknownGoodName.c_str(); } - const char * Name1 = nullptr, *Name2 = nullptr; + const char *Name1 = nullptr, *Name2 = nullptr; if (SortFieldInfo->Key == RB_Name) { Name1 = strcmp("#321#", pRomInfo1->Name) != 0 ? pRomInfo1->GoodName : pRomInfo1->FileName; @@ -706,13 +769,13 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh) case RB_Media: switch (pRomInfo->Media) { - case 'C':wcsncpy(lpdi->item.pszText, L"N64 Cartridge (Disk Compatible)", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 'D':wcsncpy(lpdi->item.pszText, L"64DD Disk", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 'E':wcsncpy(lpdi->item.pszText, L"64DD Disk (Expansion)", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 'M':wcsncpy(lpdi->item.pszText, L"N64 Development Cartridge", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 'N':wcsncpy(lpdi->item.pszText, L"N64 Cartridge", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 'Z':wcsncpy(lpdi->item.pszText, L"Aleck64", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case 0: wcsncpy(lpdi->item.pszText, L"None", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'C': wcsncpy(lpdi->item.pszText, L"N64 Cartridge (Disk Compatible)", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'D': wcsncpy(lpdi->item.pszText, L"64DD Disk", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'E': wcsncpy(lpdi->item.pszText, L"64DD Disk (Expansion)", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'M': wcsncpy(lpdi->item.pszText, L"N64 Development Cartridge", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'N': wcsncpy(lpdi->item.pszText, L"N64 Cartridge", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 'Z': wcsncpy(lpdi->item.pszText, L"Aleck64", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case 0: wcsncpy(lpdi->item.pszText, L"None", lpdi->item.cchTextMax / sizeof(wchar_t)); break; default: swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"(Unknown %c (%X))", pRomInfo->Media, pRomInfo->Media); break; } break; @@ -777,14 +840,17 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh) switch (pRomInfo->FileFormat) { case Format_Uncompressed: wcsncpy(lpdi->item.pszText, L"Uncompressed", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case Format_Zip: wcsncpy(lpdi->item.pszText, L"Zip", lpdi->item.cchTextMax / sizeof(wchar_t)); break; - case Format_7zip: wcsncpy(lpdi->item.pszText, L"7zip", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case Format_Zip: wcsncpy(lpdi->item.pszText, L"Zip", lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case Format_7zip: wcsncpy(lpdi->item.pszText, L"7zip", lpdi->item.cchTextMax / sizeof(wchar_t)); break; default: swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"Unknown (%X)", pRomInfo->FileFormat); break; } break; default: wcsncpy(lpdi->item.pszText, L" ", lpdi->item.cchTextMax); } - if (lpdi->item.pszText == nullptr || wcslen(lpdi->item.pszText) == 0) { lpdi->item.pszText = L" "; } + if (lpdi->item.pszText == nullptr || wcslen(lpdi->item.pszText) == 0) + { + lpdi->item.pszText = L" "; + } } void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) @@ -794,12 +860,18 @@ void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) LONG iItem; iItem = ListView_GetNextItem(m_hRomList, -1, LVNI_SELECTED); - if (iItem == -1) { return; } + if (iItem == -1) + { + return; + } memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_PARAM; lvItem.iItem = iItem; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return; + } if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) { return; @@ -808,7 +880,7 @@ void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) if (!pRomInfo) { - return; + return; } m_StopRefresh = true; @@ -837,14 +909,20 @@ void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/) memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_PARAM; lvItem.iItem = iItem; - if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) { return; } + if (!SendMessage(m_hRomList, LVM_GETITEM, 0, (LPARAM)&lvItem)) + { + return; + } if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) { return; } ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; - if (!pRomInfo) { return; } + if (!pRomInfo) + { + return; + } m_SelectedRom = pRomInfo->szFullFileName; } @@ -882,12 +960,27 @@ void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/) bool CheatsRemembered = !inBasicMode && g_Settings->LoadBool(Setting_RememberCheats); bool Enhancement = !inBasicMode && g_Settings->LoadBool(Setting_Enhancement); - if (!Enhancement) { DeleteMenu(hPopupMenu, 11, MF_BYPOSITION); } - if (!CheatsRemembered) { DeleteMenu(hPopupMenu, 10, MF_BYPOSITION); } - if (inBasicMode) { DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); } - if (inBasicMode && !CheatsRemembered) { DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); } + if (!Enhancement) + { + DeleteMenu(hPopupMenu, 11, MF_BYPOSITION); + } + if (!CheatsRemembered) + { + DeleteMenu(hPopupMenu, 10, MF_BYPOSITION); + } + if (inBasicMode) + { + DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); + } + if (inBasicMode && !CheatsRemembered) + { + DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); + } DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); - if ((CPath(m_SelectedRom).GetExtension() == "ndd") || (CPath(m_SelectedRom).GetExtension() == "d64")) { DeleteMenu(hPopupMenu, 1, MF_BYPOSITION); } + if ((CPath(m_SelectedRom).GetExtension() == "ndd") || (CPath(m_SelectedRom).GetExtension() == "d64")) + { + DeleteMenu(hPopupMenu, 1, MF_BYPOSITION); + } if (!inBasicMode && g_Plugins && g_Plugins->Gfx() && g_Plugins->Gfx()->GetRomBrowserMenu != nullptr) { HMENU GfxMenu = (HMENU)g_Plugins->Gfx()->GetRomBrowserMenu(); @@ -924,9 +1017,15 @@ void CRomBrowser::RomList_SortList(void) size_t index; for (index = 0; index < m_Fields.size(); index++) { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) + { + break; + } + } + if (index >= m_Fields.size()) + { + continue; } - if (index >= m_Fields.size()) { continue; } SortFieldInfo._this = this; SortFieldInfo.Key = index; SortFieldInfo.KeyAscend = UISettingsLoadBoolIndex(RomBrowser_SortAscendingIndex, count) != 0; @@ -938,7 +1037,10 @@ void CRomBrowser::SaveRomListColoumnInfo(void) { WriteTrace(TraceUserInterface, TraceDebug, "Start"); // if (!RomBrowserVisible()) { return; } - if (g_Settings == nullptr) { return; } + if (g_Settings == nullptr) + { + return; + } LV_COLUMN lvColumn; @@ -1040,7 +1142,7 @@ void CRomBrowser::FixRomListWindow(void) // We find the middle position of the screen, we use this if there is no setting int32_t X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; - int32_t Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; + int32_t Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; // Load the value from settings, if none is available, default to above UISettingsLoadDword(RomBrowser_Top, (uint32_t &)Y); @@ -1052,8 +1154,14 @@ void CRomBrowser::FixRomListWindow(void) int32_t Width = UISettingsLoadDword(RomBrowser_Width); int32_t Height = UISettingsLoadDword(RomBrowser_Height); - if (Width < 200) { Width = 200; } - if (Height < 200) { Height = 200; } + if (Width < 200) + { + Width = 200; + } + if (Height < 200) + { + Height = 200; + } RECT rcClient; rcClient.top = 0; @@ -1070,10 +1178,16 @@ void CRomBrowser::FixRomListWindow(void) void CRomBrowser::ShowRomList(void) { - if (m_Visible || g_Settings->LoadBool(GameRunning_CPU_Running)) { return; } + if (m_Visible || g_Settings->LoadBool(GameRunning_CPU_Running)) + { + return; + } m_ShowingRomBrowser = true; WatchThreadStop(); - if (m_hRomList == nullptr) { CreateRomListControl(); } + if (m_hRomList == nullptr) + { + CreateRomListControl(); + } EnableWindow(m_hRomList, TRUE); ShowWindow(m_hRomList, SW_SHOW); FixRomListWindow(); @@ -1101,7 +1215,10 @@ void CRomBrowser::ShowRomList(void) void CRomBrowser::HideRomList(void) { - if (!RomBrowserVisible()) { return; } + if (!RomBrowserVisible()) + { + return; + } ShowWindow(m_MainWindow, SW_HIDE); SaveRomListColoumnInfo(); @@ -1114,17 +1231,20 @@ void CRomBrowser::HideRomList(void) EnableWindow(m_hRomList, FALSE); ShowWindow(m_hRomList, SW_HIDE); - if (UISettingsLoadBool(RomBrowser_Maximized)) { ShowWindow(m_MainWindow, SW_RESTORE); } + if (UISettingsLoadBool(RomBrowser_Maximized)) + { + ShowWindow(m_MainWindow, SW_RESTORE); + } // Change the window style - long Style = GetWindowLong(m_MainWindow, GWL_STYLE) & ~(WS_SIZEBOX | WS_MAXIMIZEBOX); + long Style = GetWindowLong(m_MainWindow, GWL_STYLE) & ~(WS_SIZEBOX | WS_MAXIMIZEBOX); SetWindowLong(m_MainWindow, GWL_STYLE, Style); // Move window to correct location RECT rect; GetWindowRect(m_MainWindow, &rect); int32_t X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; - int32_t Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; + int32_t Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; UISettingsLoadDword(UserInterface_MainWindowTop, (uint32_t &)Y); UISettingsLoadDword(UserInterface_MainWindowLeft, (uint32_t &)X); SetWindowPos(m_MainWindow, nullptr, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); @@ -1190,8 +1310,7 @@ void CRomBrowser::WatchRomDirChanged(CRomBrowser * _this) _this->RomDirChanged(); } WriteTrace(TraceUserInterface, TraceDebug, "3"); - HANDLE hChange[] = - { + HANDLE hChange[] = { _this->m_WatchStopEvent, FindFirstChangeNotificationA(_this->m_WatchRomDir.c_str(), g_Settings->LoadBool(RomList_GameDirRecursive), FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE), }; diff --git a/Source/Project64/UserInterface/RomBrowser.h b/Source/Project64/UserInterface/RomBrowser.h index b54fe22c9..b3f34996d 100644 --- a/Source/Project64/UserInterface/RomBrowser.h +++ b/Source/Project64/UserInterface/RomBrowser.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include class CMainGui; class CPlugins; @@ -11,10 +11,10 @@ class ROMBROWSER_FIELDS { stdstr m_Name; size_t m_Pos, m_DefaultPos; - int m_ID; - uint32_t m_ColWidth; - LanguageStringID m_LangID; - bool m_PosChanged; + int m_ID; + uint32_t m_ColWidth; + LanguageStringID m_LangID; + bool m_PosChanged; public: ROMBROWSER_FIELDS(const char * Name, int Pos, int ID, int ColWidth, LanguageStringID LangID, bool UseDefault) : @@ -33,12 +33,30 @@ public: UISettingsLoadDwordIndex(RomBrowser_WidthIndex, m_ID, m_ColWidth); } } - inline LPCSTR Name(void) const { return m_Name.c_str(); } - inline size_t Pos(void) const { return m_Pos; } - inline bool PosChanged(void) const { return m_PosChanged; } - inline int ID(void) const { return m_ID; } - inline int ColWidth(void) const { return m_ColWidth; } - inline LanguageStringID LangID(void) const { return m_LangID; } + inline LPCSTR Name(void) const + { + return m_Name.c_str(); + } + inline size_t Pos(void) const + { + return m_Pos; + } + inline bool PosChanged(void) const + { + return m_PosChanged; + } + inline int ID(void) const + { + return m_ID; + } + inline int ColWidth(void) const + { + return m_ColWidth; + } + inline LanguageStringID LangID(void) const + { + return m_LangID; + } void SetColWidth(int ColWidth) { @@ -59,15 +77,15 @@ public: } }; -typedef std::vector ROMBROWSER_FIELDS_LIST; -typedef std::vector FIELD_TYPE_LIST; +typedef std::vector ROMBROWSER_FIELDS_LIST; +typedef std::vector FIELD_TYPE_LIST; class CRomBrowser; struct SORT_FIELD { CRomBrowser * _this; - int Key; - bool KeyAscend; + int Key; + bool KeyAscend; }; class C7zip; @@ -77,34 +95,57 @@ class CRomBrowser : public: CRomBrowser(HWND & hMainWindow, HWND & StatusWindow); ~CRomBrowser(void); - void HighLightLastRom(void); - void HideRomList(void); - void ResetRomBrowserColomuns(void); - void ResizeRomList(WORD nWidth, WORD nHeight); - void RomBrowserToTop(void); - void RomBrowserMaximize(bool Mazimize); - bool RomBrowserVisible(void); - bool RomListDrawItem(int idCtrl, uint32_t lParam); - bool RomListNotify(int idCtrl, uint32_t pnmh); - void SaveRomListColoumnInfo(void); - void SelectRomDir(void); - void ShowRomList(void); - bool ShowingRomBrowser(void) { return m_ShowingRomBrowser; } - const char * CurrentedSelectedRom(void) { return m_SelectedRom.c_str(); } + void HighLightLastRom(void); + void HideRomList(void); + void ResetRomBrowserColomuns(void); + void ResizeRomList(WORD nWidth, WORD nHeight); + void RomBrowserToTop(void); + void RomBrowserMaximize(bool Mazimize); + bool RomBrowserVisible(void); + bool RomListDrawItem(int idCtrl, uint32_t lParam); + bool RomListNotify(int idCtrl, uint32_t pnmh); + void SaveRomListColoumnInfo(void); + void SelectRomDir(void); + void ShowRomList(void); + bool ShowingRomBrowser(void) + { + return m_ShowingRomBrowser; + } + const char * CurrentedSelectedRom(void) + { + return m_SelectedRom.c_str(); + } static void GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault = false); private: - enum { IDC_ROMLIST = 223 }; enum { - RB_FileName = 0, RB_InternalName = 1, RB_GoodName = 2, - RB_Name = 3, RB_Status = 4, RB_RomSize = 5, - RB_CoreNotes = 6, RB_PluginNotes = 7, RB_UserNotes = 8, - RB_CartridgeID = 9, RB_Media = 10, RB_Country = 11, - RB_Developer = 12, RB_Crc1 = 13, RB_Crc2 = 14, - RB_CICChip = 15, RB_ReleaseDate = 16, RB_Genre = 17, - RB_Players = 18, RB_ForceFeedback = 19, RB_FileFormat = 20 + IDC_ROMLIST = 223 + }; + enum + { + RB_FileName = 0, + RB_InternalName = 1, + RB_GoodName = 2, + RB_Name = 3, + RB_Status = 4, + RB_RomSize = 5, + RB_CoreNotes = 6, + RB_PluginNotes = 7, + RB_UserNotes = 8, + RB_CartridgeID = 9, + RB_Media = 10, + RB_Country = 11, + RB_Developer = 12, + RB_Crc1 = 13, + RB_Crc2 = 14, + RB_CICChip = 15, + RB_ReleaseDate = 16, + RB_Genre = 17, + RB_Players = 18, + RB_ForceFeedback = 19, + RB_FileFormat = 20, }; enum @@ -114,19 +155,19 @@ private: typedef std::map HBRUSH_MAP; - void RomListReset(void); - void RomListLoaded(void); - void RomAddedToList(int32_t ListPos); - int CalcSortPosition(uint32_t lParam); - void CreateRomListControl(void); - void DeallocateBrushs(void); - void FixRomListWindow(void); - void MenuSetText(HMENU hMenu, int32_t MenuPos, const wchar_t * Title, char * ShortCut); - void RomList_ColoumnSortList(uint32_t pnmh); - void RomList_GetDispInfo(uint32_t pnmh); - void RomList_OpenRom(uint32_t pnmh); - void RomList_PopupMenu(uint32_t pnmh); - void RomList_SortList(void); + void RomListReset(void); + void RomListLoaded(void); + void RomAddedToList(int32_t ListPos); + int CalcSortPosition(uint32_t lParam); + void CreateRomListControl(void); + void DeallocateBrushs(void); + void FixRomListWindow(void); + void MenuSetText(HMENU hMenu, int32_t MenuPos, const wchar_t * Title, char * ShortCut); + void RomList_ColoumnSortList(uint32_t pnmh); + void RomList_GetDispInfo(uint32_t pnmh); + void RomList_OpenRom(uint32_t pnmh); + void RomList_PopupMenu(uint32_t pnmh); + void RomList_SortList(void); bool RomDirNeedsRefresh(void); // Called from watch thread void RomDirChanged(void); @@ -140,10 +181,10 @@ private: // Callback static int CALLBACK SelectRomDirCallBack(HWND hwnd, uint32_t uMsg, uint32_t lp, uint32_t lpData); static int CALLBACK RomList_CompareItems(uint32_t lParam1, uint32_t lParam2, uint32_t lParamSort); - + // Watch directory changed function HANDLE m_WatchThread, m_WatchStopEvent; - DWORD m_WatchThreadID; + DWORD m_WatchThreadID; HWND & m_MainWindow; HWND & m_StatusWindow; diff --git a/Source/Project64/UserInterface/RomInformation.cpp b/Source/Project64/UserInterface/RomInformation.cpp index f6d909000..e5bcacbc6 100644 --- a/Source/Project64/UserInterface/RomInformation.cpp +++ b/Source/Project64/UserInterface/RomInformation.cpp @@ -10,7 +10,10 @@ RomInformation::RomInformation(const char * RomFile) : m_pRomInfo(nullptr), m_pDiskInfo(nullptr) { - if (m_FileName.length() == 0) { return; } + if (m_FileName.length() == 0) + { + return; + } if ((CPath(m_FileName).GetExtension() != "ndd") && (CPath(m_FileName).GetExtension() != "d64")) { m_pRomInfo = new CN64Rom; @@ -62,7 +65,10 @@ RomInformation::~RomInformation() #include void RomInformation::DisplayInformation(HWND hParent) const { - if (m_FileName.length() == 0) { return; } + if (m_FileName.length() == 0) + { + return; + } DialogBoxParam(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDD_Rom_Information), hParent, (DLGPROC)RomInfoProc, (DWORD)this); } @@ -111,8 +117,8 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) case 'M': SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"N64 Development Cartridge"); break; case 'N': SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"N64 Cartridge"); break; case 'Z': SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"Aleck64"); break; - case 0: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"None"); break; - default: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"(Unknown)"); break; + case 0: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"None"); break; + default: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"(Unknown)"); break; } switch (RomHeader[0x3D]) @@ -121,7 +127,7 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) case Country_Asian_NTSC: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"NTSC"); break; case Country_Germany: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"Germany"); break; case Country_NorthAmerica: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"America"); break; - case Country_French: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"France"); break; + case Country_French: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"France"); break; case Country_Italian: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"Italy"); break; case Country_Japan: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"Japan"); break; case Country_Europe: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, L"Europe"); break; @@ -193,8 +199,8 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) { case 'D': SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"64DD Disk"); break; case 'E': SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"64DD Disk (Expansion)"); break; - case 0: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"None"); break; - default: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"(Unknown)"); break; + case 0: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"None"); break; + default: SetDlgItemText(hDlg, IDC_INFO_MEDIA, L"(Unknown)"); break; } switch (DiskHeader[0x00]) diff --git a/Source/Project64/UserInterface/RomInformation.h b/Source/Project64/UserInterface/RomInformation.h index 1f546c600..67b2f6df4 100644 --- a/Source/Project64/UserInterface/RomInformation.h +++ b/Source/Project64/UserInterface/RomInformation.h @@ -2,18 +2,18 @@ class RomInformation { - bool const m_DeleteRomInfo; - bool const m_DeleteDiskInfo; - stdstr const m_FileName; - CN64Rom * m_pRomInfo; - CN64Disk * m_pDiskInfo; + bool const m_DeleteRomInfo; + bool const m_DeleteDiskInfo; + stdstr const m_FileName; + CN64Rom * m_pRomInfo; + CN64Disk * m_pDiskInfo; friend DWORD CALLBACK RomInfoProc(HWND, DWORD, DWORD, DWORD); public: - RomInformation(const char* RomFile); - RomInformation(CN64Rom* RomInfo); - RomInformation(CN64Disk* DiskInfo); + RomInformation(const char * RomFile); + RomInformation(CN64Rom * RomInfo); + RomInformation(CN64Disk * DiskInfo); ~RomInformation(); void DisplayInformation(HWND hParent) const; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-AdvancedOptions.h b/Source/Project64/UserInterface/Settings/SettingsPage-AdvancedOptions.h index 64c32cbf3..cbd618c98 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-AdvancedOptions.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-AdvancedOptions.h @@ -6,31 +6,39 @@ class CAdvancedOptionsPage : { BEGIN_MSG_MAP_EX(CAdvancedOptionsPage) - COMMAND_ID_HANDLER_EX(IDC_START_ON_ROM_OPEN,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ZIP,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_DEBUGGER,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_INTERPRETER, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_REMEMBER_CHEAT,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_CHECK_RUNNING, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ENABLE_ENHANCEMENTS, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_UNIQUE_SAVE_DIR, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_DISPLAY_FRAMERATE, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_SHOW_STATUS_BAR, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_EXIT_FULLSCREEN_ON_LOSE_FOCUS, CheckBoxChanged) - COMMAND_HANDLER_EX(IDC_FRAME_DISPLAY_TYPE,LBN_SELCHANGE,ComboBoxChanged) + { + COMMAND_ID_HANDLER_EX(IDC_START_ON_ROM_OPEN, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ZIP, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_DEBUGGER, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_INTERPRETER, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_REMEMBER_CHEAT, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_CHECK_RUNNING, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ENABLE_ENHANCEMENTS, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_UNIQUE_SAVE_DIR, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_DISPLAY_FRAMERATE, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_SHOW_STATUS_BAR, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_EXIT_FULLSCREEN_ON_LOSE_FOCUS, CheckBoxChanged); + COMMAND_HANDLER_EX(IDC_FRAME_DISPLAY_TYPE, LBN_SELCHANGE, ComboBoxChanged); + } END_MSG_MAP() - enum { IDD = IDD_Settings_Advanced }; + enum + { + IDD = IDD_Settings_Advanced + }; public: - CAdvancedOptionsPage(HWND hParent, const RECT & rcDispay ); + CAdvancedOptionsPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle ( void ) { return TAB_ADVANCED; } - void HidePage ( void ); - void ShowPage ( void ); - void ApplySettings ( bool UpdateScreen ); - bool EnableReset ( void ); - void ResetPage ( void ); + LanguageStringID PageTitle(void) + { + return TAB_ADVANCED; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: void UpdatePageSettings(void); diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Defaults.h b/Source/Project64/UserInterface/Settings/SettingsPage-Defaults.h index b522af76f..7d7e35660 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Defaults.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Defaults.h @@ -1,39 +1,47 @@ #pragma once class CDefaultsOptionsPage : - public CSettingsPageImpl, - public CSettingsPage + public CSettingsPageImpl, + public CSettingsPage { - BEGIN_MSG_MAP_EX(CDefaultsOptionsPage) - COMMAND_ID_HANDLER_EX(IDC_HLE_GFX, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ROM_32BIT, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_SYNC_AUDIO, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ROM_FIXEDAUDIO, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_UNALIGNED_DMA, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_RANDOMIZE_SIPI_INTERRUPTS, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_PROTECT_MEMORY, CheckBoxChanged) - COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_HANDLER_EX(IDC_COUNTFACT, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_HANDLER_EX(IDC_DISKSEEKTIMING, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_HANDLER_EX(IDC_VIREFRESH, EN_UPDATE, EditBoxChanged) - COMMAND_HANDLER_EX(IDC_COUNTPERBYTE, EN_UPDATE, EditBoxChanged) - COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, EN_UPDATE, EditBoxChanged) - END_MSG_MAP() + BEGIN_MSG_MAP_EX(CDefaultsOptionsPage) + { + COMMAND_ID_HANDLER_EX(IDC_HLE_GFX, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ROM_32BIT, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_SYNC_AUDIO, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ROM_FIXEDAUDIO, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_UNALIGNED_DMA, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_RANDOMIZE_SIPI_INTERRUPTS, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_PROTECT_MEMORY, CheckBoxChanged); + COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_HANDLER_EX(IDC_COUNTFACT, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_HANDLER_EX(IDC_DISKSEEKTIMING, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_HANDLER_EX(IDC_VIREFRESH, EN_UPDATE, EditBoxChanged); + COMMAND_HANDLER_EX(IDC_COUNTPERBYTE, EN_UPDATE, EditBoxChanged); + COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, EN_UPDATE, EditBoxChanged); + } + END_MSG_MAP() - enum { IDD = IDD_Settings_Defaults }; + enum + { + IDD = IDD_Settings_Defaults + }; public: - CDefaultsOptionsPage(HWND hParent, const RECT & rcDispay ); + CDefaultsOptionsPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle ( void ) { return TAB_DEFAULTS; } - void HidePage ( void ); - void ShowPage ( void ); - void ApplySettings ( bool UpdateScreen ); - bool EnableReset ( void ); - void ResetPage ( void ); + LanguageStringID PageTitle(void) + { + return TAB_DEFAULTS; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void UpdatePageSettings(void); + void UpdatePageSettings(void); - bool m_InUpdateSettings; + bool m_InUpdateSettings; }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Directories.h b/Source/Project64/UserInterface/Settings/SettingsPage-Directories.h index b8a4d2929..1c661caea 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Directories.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Directories.h @@ -5,61 +5,69 @@ class COptionsDirectoriesPage : public CSettingsPage { BEGIN_MSG_MAP_EX(COptionsDirectoriesPage) - COMMAND_ID_HANDLER_EX(IDC_SELECT_PLUGIN_DIR, SelectPluginDir) - COMMAND_ID_HANDLER_EX(IDC_SELECT_AUTO_DIR, SelectAutoDir) - COMMAND_ID_HANDLER_EX(IDC_SELECT_INSTANT_DIR, SelectInstantDir) - COMMAND_ID_HANDLER_EX(IDC_SELECT_SNAP_DIR, SelectSnapShotDir) - COMMAND_ID_HANDLER_EX(IDC_SELECT_TEXTURE_DIR, SelectTextureDir) - COMMAND_HANDLER_EX(IDC_PLUGIN_DIR, EN_UPDATE, PluginDirChanged) - COMMAND_HANDLER_EX(IDC_AUTO_DIR, EN_UPDATE, AutoSaveDirChanged) - COMMAND_HANDLER_EX(IDC_INSTANT_DIR, EN_UPDATE, InstantSaveDirChanged) - COMMAND_HANDLER_EX(IDC_SNAP_DIR, EN_UPDATE, SnapShotDirChanged) - COMMAND_HANDLER_EX(IDC_TEXTURE_DIR, EN_UPDATE, TextureDirChanged) + { + COMMAND_ID_HANDLER_EX(IDC_SELECT_PLUGIN_DIR, SelectPluginDir); + COMMAND_ID_HANDLER_EX(IDC_SELECT_AUTO_DIR, SelectAutoDir); + COMMAND_ID_HANDLER_EX(IDC_SELECT_INSTANT_DIR, SelectInstantDir); + COMMAND_ID_HANDLER_EX(IDC_SELECT_SNAP_DIR, SelectSnapShotDir); + COMMAND_ID_HANDLER_EX(IDC_SELECT_TEXTURE_DIR, SelectTextureDir); + COMMAND_HANDLER_EX(IDC_PLUGIN_DIR, EN_UPDATE, PluginDirChanged); + COMMAND_HANDLER_EX(IDC_AUTO_DIR, EN_UPDATE, AutoSaveDirChanged); + COMMAND_HANDLER_EX(IDC_INSTANT_DIR, EN_UPDATE, InstantSaveDirChanged); + COMMAND_HANDLER_EX(IDC_SNAP_DIR, EN_UPDATE, SnapShotDirChanged); + COMMAND_HANDLER_EX(IDC_TEXTURE_DIR, EN_UPDATE, TextureDirChanged); - COMMAND_HANDLER_EX(IDC_PLUGIN_DEFAULT, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_PLUGIN_OTHER, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_AUTO_DEFAULT, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_AUTO_OTHER, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_INSTANT_DEFAULT, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_INSTANT_OTHER, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_SNAP_DEFAULT, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_SNAP_OTHER, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_TEXTURE_DEFAULT, BN_CLICKED, UseSelectedClicked) - COMMAND_HANDLER_EX(IDC_TEXTURE_OTHER, BN_CLICKED, UseSelectedClicked) + COMMAND_HANDLER_EX(IDC_PLUGIN_DEFAULT, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_PLUGIN_OTHER, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_AUTO_DEFAULT, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_AUTO_OTHER, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_INSTANT_DEFAULT, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_INSTANT_OTHER, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_SNAP_DEFAULT, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_SNAP_OTHER, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_TEXTURE_DEFAULT, BN_CLICKED, UseSelectedClicked); + COMMAND_HANDLER_EX(IDC_TEXTURE_OTHER, BN_CLICKED, UseSelectedClicked); + } END_MSG_MAP() - enum { IDD = IDD_Settings_Directory }; + enum + { + IDD = IDD_Settings_Directory + }; public: COptionsDirectoriesPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle(void) { return TAB_DIRECTORY; } - void HidePage(void); - void ShowPage(void); - void ApplySettings(bool UpdateScreen); - bool EnableReset(void); - void ResetPage(void); + LanguageStringID PageTitle(void) + { + return TAB_DIRECTORY; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void SelectPluginDir(UINT Code, int id, HWND ctl); - void SelectAutoDir(UINT Code, int id, HWND ctl); - void SelectInstantDir(UINT Code, int id, HWND ctl); - void SelectSnapShotDir(UINT Code, int id, HWND ctl); - void SelectTextureDir(UINT Code, int id, HWND ctl); - void PluginDirChanged(UINT Code, int id, HWND ctl); - void AutoSaveDirChanged(UINT Code, int id, HWND ctl); - void InstantSaveDirChanged(UINT Code, int id, HWND ctl); - void SnapShotDirChanged(UINT Code, int id, HWND ctl); - void TextureDirChanged(UINT Code, int id, HWND ctl); - void UseSelectedClicked(UINT Code, int id, HWND ctl); - void UpdatePageSettings(void); - void SelectDirectory(LanguageStringID Title, CModifiedEditBox & EditBox, CModifiedButton & Default, CModifiedButton & selected); + void SelectPluginDir(UINT Code, int id, HWND ctl); + void SelectAutoDir(UINT Code, int id, HWND ctl); + void SelectInstantDir(UINT Code, int id, HWND ctl); + void SelectSnapShotDir(UINT Code, int id, HWND ctl); + void SelectTextureDir(UINT Code, int id, HWND ctl); + void PluginDirChanged(UINT Code, int id, HWND ctl); + void AutoSaveDirChanged(UINT Code, int id, HWND ctl); + void InstantSaveDirChanged(UINT Code, int id, HWND ctl); + void SnapShotDirChanged(UINT Code, int id, HWND ctl); + void TextureDirChanged(UINT Code, int id, HWND ctl); + void UseSelectedClicked(UINT Code, int id, HWND ctl); + void UpdatePageSettings(void); + void SelectDirectory(LanguageStringID Title, CModifiedEditBox & EditBox, CModifiedButton & Default, CModifiedButton & selected); - void UpdateDirectory(CModifiedEditBox & EditBox, SettingID Type); - void UpdateDefaultSelected(CModifiedButton & Button, SettingID Type); + void UpdateDirectory(CModifiedEditBox & EditBox, SettingID Type); + void UpdateDefaultSelected(CModifiedButton & Button, SettingID Type); - void ResetDirectory(CModifiedEditBox & EditBox, SettingID Type); - void ResetDefaultSelected(CModifiedButton & ButtonDefault, CModifiedButton & ButtonSelected, SettingID Type); + void ResetDirectory(CModifiedEditBox & EditBox, SettingID Type); + void ResetDefaultSelected(CModifiedButton & ButtonDefault, CModifiedButton & ButtonSelected, SettingID Type); static int CALLBACK SelectDirCallBack(HWND hwnd, DWORD uMsg, DWORD lp, DWORD lpData); @@ -68,7 +76,7 @@ private: CModifiedEditBox m_PluginDir, m_AutoSaveDir, m_InstantSaveDir, m_ScreenShotDir, m_TextureDir; - CModifiedButton m_PluginDefault, m_PluginSelected, m_AutoSaveDefault, m_AutoSaveSelected, + CModifiedButton m_PluginDefault, m_PluginSelected, m_AutoSaveDefault, m_AutoSaveSelected, m_InstantDefault, m_InstantSelected, m_ScreenShotDefault, m_ScreenShotSelected, m_TextureDefault, m_TextureSelected; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.h b/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.h index 4cadf1ee1..8b0a75293 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.h @@ -1,46 +1,54 @@ #pragma once class CDiskDrivePage : - public CSettingsPageImpl, - public CSettingsPage + public CSettingsPageImpl, + public CSettingsPage { - BEGIN_MSG_MAP_EX(CDiskDrivePage) - COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_JP_DIR, SelectIplDirJp) - COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_US_DIR, SelectIplDirUs) - COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_TL_DIR, SelectIplDirTl) - COMMAND_HANDLER_EX(IDC_IPL_JP_DIR, EN_UPDATE, IplDirJpChanged) - COMMAND_HANDLER_EX(IDC_IPL_US_DIR, EN_UPDATE, IplDirUsChanged) - COMMAND_HANDLER_EX(IDC_IPL_TL_DIR, EN_UPDATE, IplDirTlChanged) - COMMAND_HANDLER_EX(IDC_DISKSAVETYPE, LBN_SELCHANGE, ComboBoxChanged) - END_MSG_MAP() + BEGIN_MSG_MAP_EX(CDiskDrivePage) + { + COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_JP_DIR, SelectIplDirJp); + COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_US_DIR, SelectIplDirUs); + COMMAND_ID_HANDLER_EX(IDC_SELECT_IPL_TL_DIR, SelectIplDirTl); + COMMAND_HANDLER_EX(IDC_IPL_JP_DIR, EN_UPDATE, IplDirJpChanged); + COMMAND_HANDLER_EX(IDC_IPL_US_DIR, EN_UPDATE, IplDirUsChanged); + COMMAND_HANDLER_EX(IDC_IPL_TL_DIR, EN_UPDATE, IplDirTlChanged); + COMMAND_HANDLER_EX(IDC_DISKSAVETYPE, LBN_SELCHANGE, ComboBoxChanged); + } + END_MSG_MAP() - enum { IDD = IDD_Settings_DiskDrive }; + enum + { + IDD = IDD_Settings_DiskDrive + }; public: - CDiskDrivePage(HWND hParent, const RECT & rcDispay ); + CDiskDrivePage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle ( void ) { return TAB_DISKDRIVE; } - void HidePage ( void ); - void ShowPage ( void ); - void ApplySettings ( bool UpdateScreen ); - bool EnableReset ( void ); - void ResetPage ( void ); + LanguageStringID PageTitle(void) + { + return TAB_DISKDRIVE; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void SelectIplDirJp(UINT Code, int id, HWND ctl); + void SelectIplDirJp(UINT Code, int id, HWND ctl); void SelectIplDirUs(UINT Code, int id, HWND ctl); void SelectIplDirTl(UINT Code, int id, HWND ctl); void IplDirJpChanged(UINT Code, int id, HWND ctl); void IplDirUsChanged(UINT Code, int id, HWND ctl); - void IplDirTlChanged(UINT Code, int id, HWND ctl); + void IplDirTlChanged(UINT Code, int id, HWND ctl); - void UpdatePageSettings(void); - void SelectFile(LanguageStringID Title, CModifiedEditBox & EditBox); - CModifiedEditBox m_IplDirJp; + void UpdatePageSettings(void); + void SelectFile(LanguageStringID Title, CModifiedEditBox & EditBox); + CModifiedEditBox m_IplDirJp; CModifiedEditBox m_IplDirUs; CModifiedEditBox m_IplDirTl; - bool m_InUpdateSettings; + bool m_InUpdateSettings; }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Game-DiskDrive.h b/Source/Project64/UserInterface/Settings/SettingsPage-Game-DiskDrive.h index 396b78f75..731d64770 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Game-DiskDrive.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Game-DiskDrive.h @@ -1,26 +1,34 @@ #pragma once #include "SettingsPage.h" -#include #include +#include class CGameDiskDrivePage : public CSettingsPageImpl, public CSettingsPage { BEGIN_MSG_MAP_EX(CGameDiskDrivePage) - COMMAND_HANDLER_EX(IDC_DISKSEEKTIMING2, LBN_SELCHANGE, ComboBoxChanged) + { + COMMAND_HANDLER_EX(IDC_DISKSEEKTIMING2, LBN_SELCHANGE, ComboBoxChanged); + } END_MSG_MAP() - enum { IDD = IDD_Settings_GameDiskDrive }; + enum + { + IDD = IDD_Settings_GameDiskDrive + }; public: CGameDiskDrivePage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle(void) { return TAB_DISKSETTINGS; } - void HidePage(void); - void ShowPage(void); - void ApplySettings(bool UpdateScreen); - bool EnableReset(void); - void ResetPage(void); + LanguageStringID PageTitle(void) + { + return TAB_DISKSETTINGS; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Game-General.h b/Source/Project64/UserInterface/Settings/SettingsPage-Game-General.h index 9c2ee265a..c241374f5 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Game-General.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Game-General.h @@ -1,39 +1,47 @@ #pragma once -#include -#include #include "SettingsPage.h" +#include +#include class CGameGeneralPage : public CSettingsPageImpl, public CSettingsPage { BEGIN_MSG_MAP_EX(CGameGeneralPage) - COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_HANDLER_EX(IDC_SAVE_TYPE, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_HANDLER_EX(IDC_COUNTFACT, LBN_SELCHANGE, ComboBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ROM_32BIT, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_SYNC_AUDIO, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ROM_FIXEDAUDIO, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_DELAY_DP, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_DELAY_SI, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_AUDIO_SIGNAL, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_UNALIGNED_DMA, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_RANDOMIZE_SIPI_INTERRUPTS, CheckBoxChanged) - COMMAND_HANDLER_EX(IDC_VIREFRESH, EN_UPDATE, EditBoxChanged) - COMMAND_HANDLER_EX(IDC_COUNTPERBYTE, EN_UPDATE, EditBoxChanged) - COMMAND_HANDLER_EX(IDC_OVER_CLOCK_MODIFIER, EN_UPDATE, EditBoxChanged) + { + COMMAND_HANDLER_EX(IDC_RDRAM_SIZE, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_HANDLER_EX(IDC_SAVE_TYPE, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_HANDLER_EX(IDC_COUNTFACT, LBN_SELCHANGE, ComboBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ROM_32BIT, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_SYNC_AUDIO, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ROM_FIXEDAUDIO, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_DELAY_DP, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_DELAY_SI, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_AUDIO_SIGNAL, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_UNALIGNED_DMA, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_RANDOMIZE_SIPI_INTERRUPTS, CheckBoxChanged); + COMMAND_HANDLER_EX(IDC_VIREFRESH, EN_UPDATE, EditBoxChanged); + COMMAND_HANDLER_EX(IDC_COUNTPERBYTE, EN_UPDATE, EditBoxChanged); + COMMAND_HANDLER_EX(IDC_OVER_CLOCK_MODIFIER, EN_UPDATE, EditBoxChanged); + } END_MSG_MAP() - enum { IDD = IDD_Settings_GameGeneral }; + enum + { + IDD = IDD_Settings_GameGeneral + }; public: CGameGeneralPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle(void) { return TAB_ROMSETTINGS; } - void HidePage(void); - void ShowPage(void); - void ApplySettings(bool UpdateScreen); - bool EnableReset(void); - void ResetPage(void); + LanguageStringID PageTitle(void) + { + return TAB_ROMSETTINGS; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-KeyboardShortcuts.h b/Source/Project64/UserInterface/Settings/SettingsPage-KeyboardShortcuts.h index 9817498b7..e5de8016d 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-KeyboardShortcuts.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-KeyboardShortcuts.h @@ -1,57 +1,65 @@ #pragma once class COptionsShortCutsPage : - public CSettingsPageImpl, - public CSettingsPage + public CSettingsPageImpl, + public CSettingsPage { - typedef CMenuShortCutKey::RUNNING_STATE RUNNING_STATE; - typedef CShortCutItem::SHORTCUT_KEY_LIST SHORTCUT_KEY_LIST; + typedef CMenuShortCutKey::RUNNING_STATE RUNNING_STATE; + typedef CShortCutItem::SHORTCUT_KEY_LIST SHORTCUT_KEY_LIST; - BEGIN_MSG_MAP_EX(COptionsShortCutsPage) - COMMAND_HANDLER_EX(IDC_C_CPU_STATE,LBN_SELCHANGE,OnCpuStateChanged); - NOTIFY_HANDLER_EX(IDC_MENU_ITEMS,TVN_SELCHANGED,OnMenuItemChanged); - COMMAND_HANDLER_EX(IDC_REMOVE,BN_CLICKED,OnRemoveClicked) - COMMAND_HANDLER_EX(IDC_KEY_PROMPT,BN_CLICKED,OnDetectKeyClicked) - COMMAND_HANDLER_EX(IDC_ASSIGN,BN_CLICKED,OnAssignClicked) - COMMAND_HANDLER_EX(IDC_CTL,BN_CLICKED,OnShortCutChanged) - COMMAND_HANDLER_EX(IDC_ALT,BN_CLICKED,OnShortCutChanged) - COMMAND_HANDLER_EX(IDC_SHIFT,BN_CLICKED,OnShortCutChanged) - COMMAND_HANDLER_EX(IDC_VIRTUALKEY,LBN_SELCHANGE,OnShortCutChanged) - END_MSG_MAP() + BEGIN_MSG_MAP_EX(COptionsShortCutsPage) + { + COMMAND_HANDLER_EX(IDC_C_CPU_STATE, LBN_SELCHANGE, OnCpuStateChanged); + NOTIFY_HANDLER_EX(IDC_MENU_ITEMS, TVN_SELCHANGED, OnMenuItemChanged); + COMMAND_HANDLER_EX(IDC_REMOVE, BN_CLICKED, OnRemoveClicked) + COMMAND_HANDLER_EX(IDC_KEY_PROMPT, BN_CLICKED, OnDetectKeyClicked) + COMMAND_HANDLER_EX(IDC_ASSIGN, BN_CLICKED, OnAssignClicked) + COMMAND_HANDLER_EX(IDC_CTL, BN_CLICKED, OnShortCutChanged) + COMMAND_HANDLER_EX(IDC_ALT, BN_CLICKED, OnShortCutChanged) + COMMAND_HANDLER_EX(IDC_SHIFT, BN_CLICKED, OnShortCutChanged) + COMMAND_HANDLER_EX(IDC_VIRTUALKEY, LBN_SELCHANGE, OnShortCutChanged) + } + END_MSG_MAP() - enum { IDD = IDD_Settings_Accelerator }; + enum + { + IDD = IDD_Settings_Accelerator + }; public: - COptionsShortCutsPage(HWND hParent, const RECT & rcDispay ); + COptionsShortCutsPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle ( void ) { return TAB_SHORTCUTS; } - void HidePage ( void ); - void ShowPage ( void ); - void ApplySettings ( bool UpdateScreen ); - bool EnableReset ( void ); - void ResetPage ( void ); + LanguageStringID PageTitle(void) + { + return TAB_SHORTCUTS; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void OnCpuStateChanged ( UINT Code, int id, HWND ctl ); - void OnRemoveClicked ( UINT Code, int id, HWND ctl ); - void OnDetectKeyClicked ( UINT Code, int id, HWND ctl ); - void OnAssignClicked ( UINT Code, int id, HWND ctl ); - void OnShortCutChanged ( UINT Code, int id, HWND ctl ); - LRESULT OnMenuItemChanged ( LPNMHDR lpnmh ); + void OnCpuStateChanged(UINT Code, int id, HWND ctl); + void OnRemoveClicked(UINT Code, int id, HWND ctl); + void OnDetectKeyClicked(UINT Code, int id, HWND ctl); + void OnAssignClicked(UINT Code, int id, HWND ctl); + void OnShortCutChanged(UINT Code, int id, HWND ctl); + LRESULT OnMenuItemChanged(LPNMHDR lpnmh); - void RefreshShortCutOptions ( HTREEITEM hItem ); - void InputGetKeys ( void ); - void CheckResetEnable ( void ); + void RefreshShortCutOptions(HTREEITEM hItem); + void InputGetKeys(void); + void CheckResetEnable(void); - static void stInputGetKeys (COptionsShortCutsPage * _this ) - { - _this->InputGetKeys(); - } + static void stInputGetKeys(COptionsShortCutsPage * _this) + { + _this->InputGetKeys(); + } - CPartialGroupBox m_CreateNewShortCut; - CComboBox m_CpuState, m_VirtualKeyList; - CShortCuts m_ShortCuts; - CTreeViewCtrl m_MenuItems; - CListBox m_CurrentKeys; - bool m_EnableReset; + CPartialGroupBox m_CreateNewShortCut; + CComboBox m_CpuState, m_VirtualKeyList; + CShortCuts m_ShortCuts; + CTreeViewCtrl m_MenuItems; + CListBox m_CurrentKeys; + bool m_EnableReset; }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Options.h b/Source/Project64/UserInterface/Settings/SettingsPage-Options.h index 590f0083e..9ad66e105 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Options.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Options.h @@ -1,34 +1,42 @@ #pragma once class CGeneralOptionsPage : - public CSettingsPageImpl, - public CSettingsPage + public CSettingsPageImpl, + public CSettingsPage { - BEGIN_MSG_MAP_EX(CGeneralOptionsPage) - COMMAND_ID_HANDLER_EX(IDC_AUTOSLEEP,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_LOAD_FULLSCREEN,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_SCREEN_SAVER,CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_DISCORD_RPC, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_ENABLE_ENHANCEMENTS, CheckBoxChanged) - COMMAND_ID_HANDLER_EX(IDC_BASIC_MODE,OnBasicMode) - COMMAND_HANDLER_EX(IDC_REMEMBER,EN_UPDATE,EditBoxChanged) - COMMAND_HANDLER_EX(IDC_REMEMBERDIR,EN_UPDATE,EditBoxChanged) - END_MSG_MAP() + BEGIN_MSG_MAP_EX(CGeneralOptionsPage) + { + COMMAND_ID_HANDLER_EX(IDC_AUTOSLEEP, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_LOAD_FULLSCREEN, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_SCREEN_SAVER, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_DISCORD_RPC, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_ENABLE_ENHANCEMENTS, CheckBoxChanged); + COMMAND_ID_HANDLER_EX(IDC_BASIC_MODE, OnBasicMode); + COMMAND_HANDLER_EX(IDC_REMEMBER, EN_UPDATE, EditBoxChanged); + COMMAND_HANDLER_EX(IDC_REMEMBERDIR, EN_UPDATE, EditBoxChanged); + } + END_MSG_MAP() - enum { IDD = IDD_Settings_General }; + enum + { + IDD = IDD_Settings_General + }; public: - CGeneralOptionsPage(CSettingConfig * SettingsConfig, HWND hParent, const RECT & rcDispay ); + CGeneralOptionsPage(CSettingConfig * SettingsConfig, HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle ( void ) { return TAB_OPTIONS; } - void HidePage ( void ); - void ShowPage ( void ); - void ApplySettings ( bool UpdateScreen ); - bool EnableReset ( void ); - void ResetPage ( void ); + LanguageStringID PageTitle(void) + { + return TAB_OPTIONS; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void OnBasicMode ( UINT Code, int id, HWND ctl ); - CSettingConfig * m_SettingsConfig; + void OnBasicMode(UINT Code, int id, HWND ctl); + CSettingConfig * m_SettingsConfig; }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Plugin.h b/Source/Project64/UserInterface/Settings/SettingsPage-Plugin.h index de896ac92..f92e23910 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Plugin.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Plugin.h @@ -1,46 +1,79 @@ #pragma once #include +#include class COptionPluginPage : public CSettingsPageImpl, public CSettingsPage { BEGIN_MSG_MAP_EX(COptionPluginPage) - COMMAND_HANDLER_EX(GFX_LIST, LBN_SELCHANGE, GfxPluginChanged) - COMMAND_HANDLER_EX(AUDIO_LIST, LBN_SELCHANGE, AudioPluginChanged) - COMMAND_HANDLER_EX(CONT_LIST, LBN_SELCHANGE, ControllerPluginChanged) - COMMAND_HANDLER_EX(RSP_LIST, LBN_SELCHANGE, RspPluginChanged) - COMMAND_ID_HANDLER_EX(GFX_ABOUT, GfxPluginAbout) - COMMAND_ID_HANDLER_EX(AUDIO_ABOUT, AudioPluginAbout) - COMMAND_ID_HANDLER_EX(CONT_ABOUT, ControllerPluginAbout) - COMMAND_ID_HANDLER_EX(RSP_ABOUT, RspPluginAbout) - COMMAND_ID_HANDLER_EX(IDC_HLE_GFX, HleGfxChanged) - COMMAND_ID_HANDLER_EX(IDC_HLE_AUDIO, HleAudioChanged) + { + COMMAND_HANDLER_EX(GFX_LIST, LBN_SELCHANGE, GfxPluginChanged); + COMMAND_HANDLER_EX(AUDIO_LIST, LBN_SELCHANGE, AudioPluginChanged); + COMMAND_HANDLER_EX(CONT_LIST, LBN_SELCHANGE, ControllerPluginChanged); + COMMAND_HANDLER_EX(RSP_LIST, LBN_SELCHANGE, RspPluginChanged); + COMMAND_ID_HANDLER_EX(GFX_ABOUT, GfxPluginAbout); + COMMAND_ID_HANDLER_EX(AUDIO_ABOUT, AudioPluginAbout); + COMMAND_ID_HANDLER_EX(CONT_ABOUT, ControllerPluginAbout); + COMMAND_ID_HANDLER_EX(RSP_ABOUT, RspPluginAbout); + COMMAND_ID_HANDLER_EX(IDC_HLE_GFX, HleGfxChanged); + COMMAND_ID_HANDLER_EX(IDC_HLE_AUDIO, HleAudioChanged); + } END_MSG_MAP() - enum { IDD = IDD_Settings_PlugSel }; + enum + { + IDD = IDD_Settings_PlugSel + }; public: COptionPluginPage(HWND hParent, const RECT & rcDispay); - LanguageStringID PageTitle(void) { return TAB_PLUGIN; } - void HidePage(void); - void ShowPage(void); - void ApplySettings(bool UpdateScreen); - bool EnableReset(void); - void ResetPage(void); + LanguageStringID PageTitle(void) + { + return TAB_PLUGIN; + } + void HidePage(void); + void ShowPage(void); + void ApplySettings(bool UpdateScreen); + bool EnableReset(void); + void ResetPage(void); private: - void GfxPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { ShowAboutButton(GFX_LIST); } - void AudioPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { ShowAboutButton(AUDIO_LIST); } - void ControllerPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { ShowAboutButton(CONT_LIST); } - void RspPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { ShowAboutButton(RSP_LIST); } + void GfxPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + ShowAboutButton(GFX_LIST); + } + void AudioPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + ShowAboutButton(AUDIO_LIST); + } + void ControllerPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + ShowAboutButton(CONT_LIST); + } + void RspPluginAbout(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + ShowAboutButton(RSP_LIST); + } - void GfxPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { PluginItemChanged(GFX_LIST, GFX_ABOUT); } - void AudioPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { PluginItemChanged(AUDIO_LIST, AUDIO_ABOUT); } - void ControllerPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { PluginItemChanged(CONT_LIST, CONT_ABOUT); } - void RspPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) { PluginItemChanged(RSP_LIST, RSP_ABOUT); } + void GfxPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + PluginItemChanged(GFX_LIST, GFX_ABOUT); + } + void AudioPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + PluginItemChanged(AUDIO_LIST, AUDIO_ABOUT); + } + void ControllerPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + PluginItemChanged(CONT_LIST, CONT_ABOUT); + } + void RspPluginChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) + { + PluginItemChanged(RSP_LIST, RSP_ABOUT); + } void HleGfxChanged(UINT Code, int id, HWND ctl); void HleAudioChanged(UINT Code, int id, HWND ctl); @@ -54,5 +87,5 @@ private: bool ResetComboBox(CModifiedComboBox & ComboBox, SettingID Type); CPartialGroupBox m_GfxGroup, m_AudioGroup, m_ControlGroup, m_RspGroup; - CPluginList m_PluginList; + CPluginList m_PluginList; }; diff --git a/Source/Project64/UserInterface/Settings/SettingsPage.h b/Source/Project64/UserInterface/Settings/SettingsPage.h index 28bc8508c..4d1f2674e 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage.h @@ -8,11 +8,11 @@ public: virtual ~CSettingsPage(void) = 0 {}; virtual LanguageStringID PageTitle(void) = 0; - virtual void HidePage(void) = 0; - virtual void ShowPage(void) = 0; - virtual void ApplySettings(bool UpdateScreen) = 0; - virtual bool EnableReset(void) = 0; - virtual void ResetPage(void) = 0; + virtual void HidePage(void) = 0; + virtual void ShowPage(void) = 0; + virtual void ApplySettings(bool UpdateScreen) = 0; + virtual bool EnableReset(void) = 0; + virtual void ResetPage(void) = 0; }; template @@ -20,9 +20,9 @@ class CSettingsPageImpl : public CDialogImpl { protected: - typedef std::map TextBoxList; - typedef std::map ButtonList; - typedef std::map ComboBoxList; + typedef std::map TextBoxList; + typedef std::map ButtonList; + typedef std::map ComboBoxList; typedef std::map ComboBoxTxtList; virtual ~CSettingsPageImpl() @@ -57,7 +57,7 @@ protected: #ifdef _DEBUG m_bModal = false; #endif //_DEBUG - m_hWnd = ::CreateDialogParam(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(static_cast(this)->IDD), hParent, T::StartDialogProc, NULL); + m_hWnd = ::CreateDialogParam(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(static_cast(this)->IDD), hParent, T::StartDialogProc, NULL); if (m_hWnd == nullptr) { return false; @@ -412,6 +412,7 @@ protected: ComboBox.SetReset(false); } } + public: virtual void ApplyEditBoxes(void) { @@ -531,12 +532,13 @@ public: SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); } } + protected: - TextBoxList m_TxtBoxList; - ButtonList m_ButtonList; - ComboBoxList m_ComboBoxList; + TextBoxList m_TxtBoxList; + ButtonList m_ButtonList; + ComboBoxList m_ComboBoxList; ComboBoxTxtList m_ComboBoxTxtList; - bool m_UpdatingTxt; + bool m_UpdatingTxt; }; typedef std::vector SETTING_PAGES; @@ -544,28 +546,34 @@ typedef std::vector SETTING_PAGES; class CConfigSettingSection { SETTING_PAGES m_Pages; - std::wstring m_PageTitle; + std::wstring m_PageTitle; public: CConfigSettingSection(LPCWSTR PageTitle); ~CConfigSettingSection(); - LPCWSTR GetPageTitle(void) const { return m_PageTitle.c_str(); } - void AddPage(CSettingsPage * Page); - size_t GetPageCount(void) const { return m_Pages.size(); } + LPCWSTR GetPageTitle(void) const + { + return m_PageTitle.c_str(); + } + void AddPage(CSettingsPage * Page); + size_t GetPageCount(void) const + { + return m_Pages.size(); + } CSettingsPage * GetPage(int PageNo); }; #include "SettingsPage-AdvancedOptions.h" #include "SettingsPage-Defaults.h" #include "SettingsPage-Directories.h" +#include "SettingsPage-DiskDrive.h" +#include "SettingsPage-Game-DiskDrive.h" #include "SettingsPage-Game-General.h" #include "SettingsPage-Game-Plugin.h" #include "SettingsPage-Game-Recompiler.h" -#include "SettingsPage-Game-DiskDrive.h" #include "SettingsPage-Game-Status.h" #include "SettingsPage-GameBrowser.h" #include "SettingsPage-KeyboardShortcuts.h" #include "SettingsPage-Options.h" #include "SettingsPage-Plugin.h" -#include "SettingsPage-DiskDrive.h" diff --git a/Source/Project64/UserInterface/SettingsConfig.cpp b/Source/Project64/UserInterface/SettingsConfig.cpp index cde50f48c..e3613159c 100644 --- a/Source/Project64/UserInterface/SettingsConfig.cpp +++ b/Source/Project64/UserInterface/SettingsConfig.cpp @@ -59,9 +59,9 @@ void CSettingConfig::UpdateAdvanced(bool AdvancedMode, HTREEITEM hItem) CSettingsPage * Page = (CSettingsPage *)m_PagesTreeList.GetItemData(hItem); if (!AdvancedMode && (Page == m_AdvancedPage || Page == m_DefaultsPage)) { - HTREEITEM hPage = hItem; - hItem = m_PagesTreeList.GetNextSiblingItem(hItem); - m_PagesTreeList.DeleteItem(hPage); + HTREEITEM hPage = hItem; + hItem = m_PagesTreeList.GetNextSiblingItem(hItem); + m_PagesTreeList.DeleteItem(hPage); } else if (AdvancedMode && Page == m_GeneralOptionsPage) { @@ -69,15 +69,15 @@ void CSettingConfig::UpdateAdvanced(bool AdvancedMode, HTREEITEM hItem) m_PagesTreeList.InsertItem(TVIF_TEXT | TVIF_PARAM, wGS(m_DefaultsPage->PageTitle()).c_str(), 0, 0, 0, 0, (ULONG)m_DefaultsPage, hItem, TVI_FIRST); break; } - else - { - UpdateAdvanced(AdvancedMode, m_PagesTreeList.GetChildItem(hItem)); - hItem = m_PagesTreeList.GetNextSiblingItem(hItem); - } + else + { + UpdateAdvanced(AdvancedMode, m_PagesTreeList.GetChildItem(hItem)); + hItem = m_PagesTreeList.GetNextSiblingItem(hItem); + } } } -LRESULT CSettingConfig::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CSettingConfig::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { stdstr ConfigRomTitle, GameIni(g_Settings->LoadStringVal(Game_IniKey)); @@ -212,7 +212,7 @@ LRESULT CSettingConfig::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /* return TRUE; } -LRESULT CSettingConfig::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) +LRESULT CSettingConfig::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/) { switch (wID) { @@ -294,7 +294,7 @@ void CSettingConfig::ApplySettings(bool UpdateScreen) CSettingTypeApplication::Flush(); } -LRESULT CSettingConfig::OnPageListItemChanged(NMHDR* /*phdr*/) +LRESULT CSettingConfig::OnPageListItemChanged(NMHDR * /*phdr*/) { m_bTVNSelChangedSupported = true; @@ -312,48 +312,48 @@ LRESULT CSettingConfig::OnPageListItemChanged(NMHDR* /*phdr*/) ::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset()); } - return 0; // Return value ignored + return 0; // Return value ignored } // Fallback to using HitTest if TVN_SELCHANGED isn't working -LRESULT CSettingConfig::OnPageListClicked(NMHDR*) +LRESULT CSettingConfig::OnPageListClicked(NMHDR *) { - if (m_bTVNSelChangedSupported) - { - return 0; - } + if (m_bTVNSelChangedSupported) + { + return 0; + } - DWORD dwClickPos = GetMessagePos(); - CPoint clickPt = CPoint(dwClickPos); - ScreenToClient(&clickPt); + DWORD dwClickPos = GetMessagePos(); + CPoint clickPt = CPoint(dwClickPos); + ScreenToClient(&clickPt); - CRect treeRect; - m_PagesTreeList.GetWindowRect(treeRect); - ScreenToClient(&treeRect); + CRect treeRect; + m_PagesTreeList.GetWindowRect(treeRect); + ScreenToClient(&treeRect); - clickPt.x -= treeRect.left; - clickPt.y -= treeRect.top; - clickPt.y -= 2; + clickPt.x -= treeRect.left; + clickPt.y -= treeRect.top; + clickPt.y -= 2; - UINT uFlags; - HTREEITEM hItem = m_PagesTreeList.HitTest(clickPt, &uFlags); + UINT uFlags; + HTREEITEM hItem = m_PagesTreeList.HitTest(clickPt, &uFlags); - CSettingsPage * Page = (CSettingsPage *)m_PagesTreeList.GetItemData(hItem); + CSettingsPage * Page = (CSettingsPage *)m_PagesTreeList.GetItemData(hItem); - if (Page) - { - if (m_CurrentPage) - { - m_CurrentPage->HidePage(); - } - m_CurrentPage = Page; - m_CurrentPage->ShowPage(); - ::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset()); - } - return 0; + if (Page) + { + if (m_CurrentPage) + { + m_CurrentPage->HidePage(); + } + m_CurrentPage = Page; + m_CurrentPage->ShowPage(); + ::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset()); + } + return 0; } -LRESULT CSettingConfig::OnSettingPageChanged(UINT /*uMsg*/, WPARAM /*wPage*/, LPARAM /*lParam*/) +LRESULT CSettingConfig::OnSettingPageChanged(UINT /*uMsg*/, WPARAM /*wPage*/, LPARAM /*lParam*/) { ::EnableWindow(GetDlgItem(IDC_APPLY), true); ::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset()); diff --git a/Source/Project64/UserInterface/SettingsConfig.h b/Source/Project64/UserInterface/SettingsConfig.h index 9072f8018..b4fbebcbb 100644 --- a/Source/Project64/UserInterface/SettingsConfig.h +++ b/Source/Project64/UserInterface/SettingsConfig.h @@ -6,25 +6,30 @@ class CConfigSettingSection; class CSettingsPage; class CSettingConfig : - public CDialogImpl < CSettingConfig > + public CDialogImpl { public: BEGIN_MSG_MAP_EX(CSettingConfig) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked) - NOTIFY_HANDLER_EX(IDC_PAGELIST, TVN_SELCHANGED, OnPageListItemChanged) - NOTIFY_HANDLER_EX(IDC_PAGELIST, NM_CLICK, OnPageListClicked) - MESSAGE_HANDLER_EX(PSM_CHANGED, OnSettingPageChanged) - REFLECT_NOTIFICATIONS() + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + COMMAND_CODE_HANDLER(BN_CLICKED, OnClicked); + NOTIFY_HANDLER_EX(IDC_PAGELIST, TVN_SELCHANGED, OnPageListItemChanged); + NOTIFY_HANDLER_EX(IDC_PAGELIST, NM_CLICK, OnPageListClicked); + MESSAGE_HANDLER_EX(PSM_CHANGED, OnSettingPageChanged); + REFLECT_NOTIFICATIONS(); + } END_MSG_MAP() - enum { IDD = IDD_Settings_Config }; + enum + { + IDD = IDD_Settings_Config + }; - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& bHandled); - LRESULT OnPageListItemChanged(NMHDR* phdr); - LRESULT OnPageListClicked(NMHDR* phdr); - LRESULT OnSettingPageChanged(UINT /*uMsg*/, WPARAM wPage, LPARAM /*lParam*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnClicked(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL & bHandled); + LRESULT OnPageListItemChanged(NMHDR * phdr); + LRESULT OnPageListClicked(NMHDR * phdr); + LRESULT OnSettingPageChanged(UINT /*uMsg*/, WPARAM wPage, LPARAM /*lParam*/); public: CSettingConfig(bool bJustGameSetting = false); @@ -42,7 +47,7 @@ private: CTreeViewCtrl m_PagesTreeList; SETTING_SECTIONS m_Sections; - CSettingsPage * m_CurrentPage, *m_GeneralOptionsPage, *m_AdvancedPage, *m_DefaultsPage, *m_DiskDrivePage; + CSettingsPage *m_CurrentPage, *m_GeneralOptionsPage, *m_AdvancedPage, *m_DefaultsPage, *m_DiskDrivePage; bool m_GameConfig; bool m_bTVNSelChangedSupported; }; diff --git a/Source/Project64/UserInterface/SupportEnterCode.cpp b/Source/Project64/UserInterface/SupportEnterCode.cpp index db4d30fe9..ffbddbe45 100644 --- a/Source/Project64/UserInterface/SupportEnterCode.cpp +++ b/Source/Project64/UserInterface/SupportEnterCode.cpp @@ -9,28 +9,33 @@ class CRequestCode : { public: BEGIN_MSG_MAP_EX(CRequestCode) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic); + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + } END_MSG_MAP() - enum { IDD = IDD_Support_RequestCode }; + enum + { + IDD = IDD_Support_RequestCode + }; CRequestCode(CProjectSupport & Support); void ShowOldCodeMsg(); private: CRequestCode(void); - CRequestCode(const CRequestCode&); - CRequestCode& operator=(const CRequestCode&); + CRequestCode(const CRequestCode &); + CRequestCode & operator=(const CRequestCode &); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled); - LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled); + LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); CProjectSupport & m_Support; bool m_ShowOldCodeMsg; @@ -41,7 +46,7 @@ CSupportEnterCode::CSupportEnterCode(CProjectSupport & Support) : { } -LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { SetWindowText(wGS(MSG_SUPPORT_ENTER_CODE_TITLE).c_str()); CWindow hDescription = GetDlgItem(IDC_DESCRIPTION); @@ -58,7 +63,7 @@ LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM m_RequestLink.SubclassWindow(GetDlgItem(IDC_REQUEST_LINK)); m_RequestLink.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON, HLINK_COMMANDBUTTON); - CRect rcWin = { 0 }; + CRect rcWin = {0}; hDescription.GetClientRect(&rcWin); CDC hDC = hDescription.GetDC(); @@ -96,12 +101,12 @@ LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM RequestLink.GetWindowRect(&rcWin); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2); - RECT CancelBtnWin = { 0 }; + RECT CancelBtnWin = {0}; CancelBtn.GetWindowRect(&CancelBtnWin); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&CancelBtnWin, 2); CancelBtn.SetWindowPos(nullptr, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER); - RECT OkBtnWin = { 0 }; + RECT OkBtnWin = {0}; OkBtn.GetWindowRect(&OkBtnWin); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&OkBtnWin, 2); OkBtn.SetWindowPos(nullptr, OkBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER); @@ -112,12 +117,12 @@ LRESULT CSupportEnterCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM SetRect(&rcWin, 0, 0, rcWin.Width(), OkBtnWin.bottom + 30); AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != nullptr, GetExStyle()); int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2; - int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2; + int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2; MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE); return TRUE; } -LRESULT CSupportEnterCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/) { CDCHandle hdcStatic = (HDC)wParam; hdcStatic.SetTextColor(RGB(0, 0, 0)); @@ -125,7 +130,7 @@ LRESULT CSupportEnterCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /* return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH)); } -LRESULT CSupportEnterCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/) { static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF); static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF); @@ -140,16 +145,16 @@ LRESULT CSupportEnterCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARA return TRUE; } -LRESULT CSupportEnterCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { EndDialog(wID); return TRUE; } -LRESULT CSupportEnterCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { wchar_t code[50]; - if (!GetDlgItemText(IDC_CODE,code,sizeof(code) /sizeof(code[0]))) + if (!GetDlgItemText(IDC_CODE, code, sizeof(code) / sizeof(code[0]))) { MessageBox(wGS(MSG_SUPPORT_ENTER_SUPPORT_CODE).c_str(), wGS(MSG_SUPPORT_PROJECT64).c_str(), MB_OK); return false; @@ -158,7 +163,7 @@ LRESULT CSupportEnterCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCt GetDlgItem(IDCANCEL).EnableWindow(false); bool ValidCode = false; - if (_wcsicmp(code,L"thank you from project64") == 0) + if (_wcsicmp(code, L"thank you from project64") == 0) { SetDlgItemText(IDC_CODE, L""); CRequestCode RequestWindow(m_Support); @@ -197,14 +202,14 @@ void CRequestCode::ShowOldCodeMsg() m_ShowOldCodeMsg = true; } -LRESULT CSupportEnterCode::OnRequestCode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CSupportEnterCode::OnRequestCode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { CRequestCode RequestWindow(m_Support); RequestWindow.DoModal(m_hWnd); return 0; } -LRESULT CRequestCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CRequestCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/) { if (m_ShowOldCodeMsg) { @@ -213,7 +218,7 @@ LRESULT CRequestCode::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lP return TRUE; } -LRESULT CRequestCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CRequestCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/) { CDCHandle hdcStatic = (HDC)wParam; hdcStatic.SetTextColor(RGB(0, 0, 0)); @@ -221,7 +226,7 @@ LRESULT CRequestCode::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lPara return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH)); } -LRESULT CRequestCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) +LRESULT CRequestCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/) { static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF); static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF); @@ -236,7 +241,7 @@ LRESULT CRequestCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*l return TRUE; } -LRESULT CRequestCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CRequestCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { GetDlgItem(IDOK).EnableWindow(false); GetDlgItem(IDCANCEL).EnableWindow(false); @@ -254,7 +259,7 @@ LRESULT CRequestCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, return TRUE; } -LRESULT CRequestCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +LRESULT CRequestCode::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/) { EndDialog(wID); return TRUE; diff --git a/Source/Project64/UserInterface/SupportEnterCode.h b/Source/Project64/UserInterface/SupportEnterCode.h index 7b2bc6dbb..2b72776d3 100644 --- a/Source/Project64/UserInterface/SupportEnterCode.h +++ b/Source/Project64/UserInterface/SupportEnterCode.h @@ -6,29 +6,34 @@ class CSupportEnterCode : { public: BEGIN_MSG_MAP_EX(CSettingConfig) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) - COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) - COMMAND_ID_HANDLER(IDC_REQUEST_LINK, OnRequestCode) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic); + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd); + COMMAND_ID_HANDLER(IDC_REQUEST_LINK, OnRequestCode); + } END_MSG_MAP() - enum { IDD = IDD_Support_EnterCode }; + enum + { + IDD = IDD_Support_EnterCode + }; CSupportEnterCode(CProjectSupport & Support); private: CSupportEnterCode(void); - CSupportEnterCode(const CSupportEnterCode&); - CSupportEnterCode& operator=(const CSupportEnterCode&); + CSupportEnterCode(const CSupportEnterCode &); + CSupportEnterCode & operator=(const CSupportEnterCode &); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled); - LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnRequestCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled); + LRESULT OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnRequestCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); CHyperLink m_RequestLink; CProjectSupport & m_Support; diff --git a/Source/Project64/UserInterface/SupportWindow.h b/Source/Project64/UserInterface/SupportWindow.h index e7afaa9bd..30b97c720 100644 --- a/Source/Project64/UserInterface/SupportWindow.h +++ b/Source/Project64/UserInterface/SupportWindow.h @@ -1,22 +1,27 @@ #pragma once -#include #include "resource.h" +#include class CSupportWindow : public CDialogImpl { public: BEGIN_MSG_MAP_EX(CSettingConfig) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) - MESSAGE_HANDLER(WM_TIMER, OnTimer) - COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd) - COMMAND_ID_HANDLER(ID_SUPPORT_PJ64, OnSupportProject64) - COMMAND_ID_HANDLER(IDC_ENTER_CODE, OnEnterCode) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic); + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground); + MESSAGE_HANDLER(WM_TIMER, OnTimer); + COMMAND_RANGE_HANDLER(IDOK, IDCANCEL, OnCloseCmd); + COMMAND_ID_HANDLER(ID_SUPPORT_PJ64, OnSupportProject64); + COMMAND_ID_HANDLER(IDC_ENTER_CODE, OnEnterCode); + } END_MSG_MAP() - enum { IDD = IDD_Support_Project64 }; + enum + { + IDD = IDD_Support_Project64 + }; CSupportWindow(CProjectSupport & Support); ~CSupportWindow(void); @@ -25,16 +30,16 @@ public: private: CSupportWindow(); - CSupportWindow(const CSupportWindow&); - CSupportWindow& operator=(const CSupportWindow&); + CSupportWindow(const CSupportWindow &); + CSupportWindow & operator=(const CSupportWindow &); - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled); - LRESULT OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnSupportProject64(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled); + LRESULT OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/); + LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnSupportProject64(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); + LRESULT OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/); void EnableContinue(); diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DataArray.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DataArray.h index 9a6357488..a87687e45 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DataArray.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DataArray.h @@ -33,197 +33,200 @@ template class CListCtrlArrayEqualHelper { public: - static bool IsEqual(const T& t1, const T& t2) - { - return (t1 == t2); - } + static bool IsEqual(const T & t1, const T & t2) + { + return (t1 == t2); + } }; -template > +template > class CListCtrlArray { public: - // Construction / destruction - CListCtrlArray() : m_aT(nullptr), m_nSize(0), m_nAllocSize(0) - { } + // Construction / destruction + CListCtrlArray() : + m_aT(nullptr), m_nSize(0), m_nAllocSize(0) + { + } - ~CListCtrlArray() - { - RemoveAll(); - } + ~CListCtrlArray() + { + RemoveAll(); + } - CListCtrlArray(const CListCtrlArray< T, TEqual >& src) : m_aT(nullptr), m_nSize(0), m_nAllocSize(0) - { - m_aT = (T*)malloc(src.GetSize() * sizeof(T)); - if (m_aT != nullptr) - { - m_nAllocSize = src.GetSize(); - for (int i=0; i& operator=(const CListCtrlArray< T, TEqual >& src) - { - if (GetSize() != src.GetSize()) - { - RemoveAll(); - m_aT = (T*)malloc(src.GetSize() * sizeof(T)); - if (m_aT != nullptr) - m_nAllocSize = src.GetSize(); - } - else - { - for (int i = GetSize(); i > 0; i--) - RemoveAt(i - 1); - } - for (int i=0; i & src) : + m_aT(nullptr), m_nSize(0), m_nAllocSize(0) + { + m_aT = (T *)malloc(src.GetSize() * sizeof(T)); + if (m_aT != nullptr) + { + m_nAllocSize = src.GetSize(); + for (int i = 0; i < src.GetSize(); i++) + Add(src[i]); + } + } + CListCtrlArray & operator=(const CListCtrlArray & src) + { + if (GetSize() != src.GetSize()) + { + RemoveAll(); + m_aT = (T *)malloc(src.GetSize() * sizeof(T)); + if (m_aT != nullptr) + m_nAllocSize = src.GetSize(); + } + else + { + for (int i = GetSize(); i > 0; i--) + RemoveAt(i - 1); + } + for (int i = 0; i < src.GetSize(); i++) + Add(src[i]); + return *this; + } - // Operations - int GetSize() const - { - return m_nSize; - } - BOOL Add(const T& t) - { - if(m_nSize == m_nAllocSize) - { - T* aT; - int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); - aT = (T*)realloc(m_aT, nNewAllocSize * sizeof(T)); - if(aT == nullptr) - return FALSE; - m_nAllocSize = nNewAllocSize; - m_aT = aT; - } - InternalSetAtIndex(m_nSize, t); - m_nSize++; - return TRUE; - } - BOOL AddAt(const T& t, int index) - { - if(m_nSize == m_nAllocSize) - { - T* aT; - int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); - aT = (T*)realloc(m_aT, nNewAllocSize * sizeof(T)); - if(aT == nullptr) - return FALSE; - m_nAllocSize = nNewAllocSize; - m_aT = aT; - } - int NewItem = (m_nSize - index); - if (NewItem > 0) - { - memmove(&m_aT[index + 1],&m_aT[index],NewItem * sizeof(T)); - } - InternalSetAtIndex(index, t); - m_nSize++; - return TRUE; - } - BOOL Remove(const T& t) - { - int nIndex = Find(t); - if(nIndex == -1) - return FALSE; - return RemoveAt(nIndex); - } - BOOL RemoveAt(int nIndex) - { - ATLASSERT(nIndex >= 0 && nIndex < m_nSize); - if (nIndex < 0 || nIndex >= m_nSize) - return FALSE; - m_aT[nIndex].~T(); - if(nIndex != (m_nSize - 1)) - memmove((void*)(m_aT + nIndex), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T)); - m_nSize--; - return TRUE; - } - void RemoveAll() - { - if(m_aT != nullptr) - { - for(int i = 0; i < m_nSize; i++) - m_aT[i].~T(); - free(m_aT); - m_aT = nullptr; - } - m_nSize = 0; - m_nAllocSize = 0; - } - const T& operator[] (int nIndex) const - { - ATLASSERT(nIndex >= 0 && nIndex < m_nSize); - if(nIndex < 0 || nIndex >= m_nSize) - { - RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_NONCONTINUABLE, 0, nullptr); - } - return m_aT[nIndex]; - } - T& operator[] (int nIndex) - { - ATLASSERT(nIndex >= 0 && nIndex < m_nSize); - if(nIndex < 0 || nIndex >= m_nSize) - { - RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_NONCONTINUABLE, 0, nullptr); - } - return m_aT[nIndex]; - } - T* GetData() const - { - return m_aT; - } + // Operations + int GetSize() const + { + return m_nSize; + } + BOOL Add(const T & t) + { + if (m_nSize == m_nAllocSize) + { + T * aT; + int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); + aT = (T *)realloc(m_aT, nNewAllocSize * sizeof(T)); + if (aT == nullptr) + return FALSE; + m_nAllocSize = nNewAllocSize; + m_aT = aT; + } + InternalSetAtIndex(m_nSize, t); + m_nSize++; + return TRUE; + } + BOOL AddAt(const T & t, int index) + { + if (m_nSize == m_nAllocSize) + { + T * aT; + int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); + aT = (T *)realloc(m_aT, nNewAllocSize * sizeof(T)); + if (aT == nullptr) + return FALSE; + m_nAllocSize = nNewAllocSize; + m_aT = aT; + } + int NewItem = (m_nSize - index); + if (NewItem > 0) + { + memmove(&m_aT[index + 1], &m_aT[index], NewItem * sizeof(T)); + } + InternalSetAtIndex(index, t); + m_nSize++; + return TRUE; + } + BOOL Remove(const T & t) + { + int nIndex = Find(t); + if (nIndex == -1) + return FALSE; + return RemoveAt(nIndex); + } + BOOL RemoveAt(int nIndex) + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + m_aT[nIndex].~T(); + if (nIndex != (m_nSize - 1)) + memmove((void *)(m_aT + nIndex), (void *)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T)); + m_nSize--; + return TRUE; + } + void RemoveAll() + { + if (m_aT != nullptr) + { + for (int i = 0; i < m_nSize; i++) + m_aT[i].~T(); + free(m_aT); + m_aT = nullptr; + } + m_nSize = 0; + m_nAllocSize = 0; + } + const T & operator[](int nIndex) const + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if (nIndex < 0 || nIndex >= m_nSize) + { + RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_NONCONTINUABLE, 0, nullptr); + } + return m_aT[nIndex]; + } + T & operator[](int nIndex) + { + ATLASSERT(nIndex >= 0 && nIndex < m_nSize); + if (nIndex < 0 || nIndex >= m_nSize) + { + RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_NONCONTINUABLE, 0, nullptr); + } + return m_aT[nIndex]; + } + T * GetData() const + { + return m_aT; + } - int Find(const T& t) const - { - for(int i = 0; i < m_nSize; i++) - { - if(TEqual::IsEqual(m_aT[i], t)) - return i; - } - return -1; // Not found - } + int Find(const T & t) const + { + for (int i = 0; i < m_nSize; i++) + { + if (TEqual::IsEqual(m_aT[i], t)) + return i; + } + return -1; // Not found + } - BOOL SetAtIndex(int nIndex, const T& t) - { - if (nIndex < 0 || nIndex >= m_nSize) - return FALSE; - InternalSetAtIndex(nIndex, t); - return TRUE; - } + BOOL SetAtIndex(int nIndex, const T & t) + { + if (nIndex < 0 || nIndex >= m_nSize) + return FALSE; + InternalSetAtIndex(nIndex, t); + return TRUE; + } - // Implementation - class Wrapper - { - public: - Wrapper(const T& _t) : t(_t) - { - } - template - void * __cdecl operator new(size_t, _Ty* p) - { - return p; - } - template - void __cdecl operator delete(void* /* pv */, _Ty* /* p */) - { - } - T t; - }; + // Implementation + class Wrapper + { + public: + Wrapper(const T & _t) : + t(_t) + { + } + template + void * __cdecl operator new(size_t, _Ty * p) + { + return p; + } + template + void __cdecl operator delete(void * /* pv */, _Ty * /* p */) + { + } + T t; + }; - // Implementation - void InternalSetAtIndex(int nIndex, const T& t) - { - new(m_aT + nIndex) Wrapper(t); - } - - typedef T _ArrayElementType; - T* m_aT; - int m_nSize; - int m_nAllocSize; + // Implementation + void InternalSetAtIndex(int nIndex, const T & t) + { + new (m_aT + nIndex) Wrapper(t); + } + typedef T _ArrayElementType; + T * m_aT; + int m_nSize; + int m_nAllocSize; }; #ifdef pop_new diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DragDrop.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DragDrop.h index 876a732f4..46a3e0de3 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DragDrop.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DragDrop.h @@ -1,785 +1,825 @@ #pragma once -#include #include +#include using namespace std; class CEnumFormatEtc : public IEnumFORMATETC { public: - CEnumFormatEtc( const vector < FORMATETC >& vFormatEtc ) - { - m_nRefCount = 0; - m_nIndex = 0; - m_vFormatEtc = vFormatEtc; - } - + CEnumFormatEtc(const vector & vFormatEtc) + { + m_nRefCount = 0; + m_nIndex = 0; + m_vFormatEtc = vFormatEtc; + } + protected: - vector < FORMATETC > m_vFormatEtc; - int m_nRefCount; - int m_nIndex; + vector m_vFormatEtc; + int m_nRefCount; + int m_nIndex; public: - // IUnknown members - STDMETHOD(QueryInterface)( REFIID refiid, void FAR* FAR* ppvObject ) - { - *ppvObject = ( refiid == IID_IUnknown || refiid == IID_IEnumFORMATETC ) ? this : nullptr; - - if ( *ppvObject != nullptr ) - ( (LPUNKNOWN)*ppvObject )->AddRef(); - - return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; - } - - STDMETHOD_(ULONG, AddRef)( void ) - { - return ++m_nRefCount; - } - - STDMETHOD_(ULONG, Release)( void ) - { - int nRefCount = --m_nRefCount; - if ( nRefCount == 0 ) - delete this; - return nRefCount; - } - - // IEnumFORMATETC members - STDMETHOD(Next)( ULONG celt, LPFORMATETC lpFormatEtc, ULONG FAR *pceltFetched ) - { - if ( pceltFetched != nullptr ) - *pceltFetched=0; + // IUnknown members + STDMETHOD(QueryInterface) + (REFIID refiid, void FAR * FAR * ppvObject) + { + *ppvObject = (refiid == IID_IUnknown || refiid == IID_IEnumFORMATETC) ? this : nullptr; - ULONG cReturn = celt; + if (*ppvObject != nullptr) + ((LPUNKNOWN)*ppvObject)->AddRef(); - if ( celt <= 0 || lpFormatEtc == nullptr || m_nIndex >= (int)m_vFormatEtc.size() ) - return S_FALSE; + return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; + } - if ( pceltFetched == nullptr && celt != 1 ) // pceltFetched can be nullptr only for 1 item request - return S_FALSE; + STDMETHOD_(ULONG, AddRef) + (void) + { + return ++m_nRefCount; + } - while ( m_nIndex < (int)m_vFormatEtc.size() && cReturn > 0 ) - { - *lpFormatEtc++ = m_vFormatEtc[ m_nIndex++ ]; - cReturn--; - } - - if ( pceltFetched != nullptr ) - *pceltFetched = celt - cReturn; + STDMETHOD_(ULONG, Release) + (void) + { + int nRefCount = --m_nRefCount; + if (nRefCount == 0) + delete this; + return nRefCount; + } - return cReturn == 0 ? S_OK : S_FALSE; - } - - STDMETHOD(Skip)( ULONG celt ) - { - if ( ( m_nIndex + (int)celt ) >= (int)m_vFormatEtc.size() ) - return S_FALSE; - m_nIndex += celt; - return S_OK; - } - - STDMETHOD(Reset)( void ) - { - m_nIndex = 0; - return S_OK; - } - - STDMETHOD(Clone)( IEnumFORMATETC FAR * FAR* ppCloneEnumFormatEtc ) - { - if ( ppCloneEnumFormatEtc == nullptr ) - return E_POINTER; + // IEnumFORMATETC members + STDMETHOD(Next) + (ULONG celt, LPFORMATETC lpFormatEtc, ULONG FAR * pceltFetched) + { + if (pceltFetched != nullptr) + *pceltFetched = 0; - *ppCloneEnumFormatEtc = new CEnumFormatEtc( m_vFormatEtc ); - ( (CEnumFormatEtc*)*ppCloneEnumFormatEtc )->AddRef(); - ( (CEnumFormatEtc*)*ppCloneEnumFormatEtc )->m_nIndex = m_nIndex; - - return S_OK; - } + ULONG cReturn = celt; + + if (celt <= 0 || lpFormatEtc == nullptr || m_nIndex >= (int)m_vFormatEtc.size()) + return S_FALSE; + + if (pceltFetched == nullptr && celt != 1) // pceltFetched can be nullptr only for 1 item request + return S_FALSE; + + while (m_nIndex < (int)m_vFormatEtc.size() && cReturn > 0) + { + *lpFormatEtc++ = m_vFormatEtc[m_nIndex++]; + cReturn--; + } + + if (pceltFetched != nullptr) + *pceltFetched = celt - cReturn; + + return cReturn == 0 ? S_OK : S_FALSE; + } + + STDMETHOD(Skip) + (ULONG celt) + { + if ((m_nIndex + (int)celt) >= (int)m_vFormatEtc.size()) + return S_FALSE; + m_nIndex += celt; + return S_OK; + } + + STDMETHOD(Reset) + (void) + { + m_nIndex = 0; + return S_OK; + } + + STDMETHOD(Clone) + (IEnumFORMATETC FAR * FAR * ppCloneEnumFormatEtc) + { + if (ppCloneEnumFormatEtc == nullptr) + return E_POINTER; + + *ppCloneEnumFormatEtc = new CEnumFormatEtc(m_vFormatEtc); + ((CEnumFormatEtc *)*ppCloneEnumFormatEtc)->AddRef(); + ((CEnumFormatEtc *)*ppCloneEnumFormatEtc)->m_nIndex = m_nIndex; + + return S_OK; + } }; class CDropSource : public IDropSource { public: - CDropSource() - { - m_nRefCount = 0; - } + CDropSource() + { + m_nRefCount = 0; + } protected: - int m_nRefCount; - + int m_nRefCount; + public: - // IUnknown members - STDMETHOD(QueryInterface)( REFIID refiid, void FAR* FAR* ppvObject ) - { - *ppvObject = ( refiid == IID_IUnknown || refiid == IID_IDropSource ) ? this : nullptr; - - if ( *ppvObject != nullptr ) - ( (LPUNKNOWN)*ppvObject )->AddRef(); - - return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; - } - - STDMETHOD_(ULONG, AddRef)( void ) - { - return ++m_nRefCount; - } - - STDMETHOD_(ULONG, Release)( void ) - { - int nRefCount = --m_nRefCount; - if ( nRefCount == 0 ) - delete this; - return nRefCount; - } - - // IDropSource members - STDMETHOD(QueryContinueDrag)( BOOL bEscapePressed, DWORD dwKeyState ) - { - if ( bEscapePressed ) - return DRAGDROP_S_CANCEL; - - if ( !( dwKeyState & ( MK_LBUTTON | MK_RBUTTON ) ) ) - return DRAGDROP_S_DROP; - - return S_OK; - } - - STDMETHOD(GiveFeedback)( DWORD /*dwEffect*/ ) + // IUnknown members + STDMETHOD(QueryInterface) + (REFIID refiid, void FAR * FAR * ppvObject) { - return DRAGDROP_S_USEDEFAULTCURSORS; + *ppvObject = (refiid == IID_IUnknown || refiid == IID_IDropSource) ? this : nullptr; + + if (*ppvObject != nullptr) + ((LPUNKNOWN)*ppvObject)->AddRef(); + + return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; + } + + STDMETHOD_(ULONG, AddRef) + (void) + { + return ++m_nRefCount; + } + + STDMETHOD_(ULONG, Release) + (void) + { + int nRefCount = --m_nRefCount; + if (nRefCount == 0) + delete this; + return nRefCount; + } + + // IDropSource members + STDMETHOD(QueryContinueDrag) + (BOOL bEscapePressed, DWORD dwKeyState) + { + if (bEscapePressed) + return DRAGDROP_S_CANCEL; + + if (!(dwKeyState & (MK_LBUTTON | MK_RBUTTON))) + return DRAGDROP_S_DROP; + + return S_OK; + } + + STDMETHOD(GiveFeedback) + (DWORD /*dwEffect*/) + { + return DRAGDROP_S_USEDEFAULTCURSORS; } }; class CDataObject : public IDataObject { public: - CDataObject( CDropSource *pDropSource ) - { - m_nRefCount = 0; - m_pDropSource = pDropSource; - m_bSwappedButtons = GetSystemMetrics( SM_SWAPBUTTON ); - } - - virtual ~CDataObject() - { - for ( vector < STGMEDIUM >::iterator posStgMedium = m_vStgMedium.begin(); posStgMedium != m_vStgMedium.end(); posStgMedium++ ) - ReleaseStgMedium( &( *posStgMedium ) ); - } + CDataObject(CDropSource * pDropSource) + { + m_nRefCount = 0; + m_pDropSource = pDropSource; + m_bSwappedButtons = GetSystemMetrics(SM_SWAPBUTTON); + } + + virtual ~CDataObject() + { + for (vector::iterator posStgMedium = m_vStgMedium.begin(); posStgMedium != m_vStgMedium.end(); posStgMedium++) + ReleaseStgMedium(&(*posStgMedium)); + } protected: - CDropSource *m_pDropSource; - int m_nRefCount; - BOOL m_bSwappedButtons; - - vector < FORMATETC > m_vFormatEtc; - vector < STGMEDIUM > m_vStgMedium; + CDropSource * m_pDropSource; + int m_nRefCount; + BOOL m_bSwappedButtons; + + vector m_vFormatEtc; + vector m_vStgMedium; public: - // IUnknown members - STDMETHOD(QueryInterface)( REFIID refiid, void FAR* FAR* ppvObject ) - { - *ppvObject = ( refiid == IID_IUnknown || refiid == IID_IDataObject ) ? this : nullptr; - - if ( *ppvObject != nullptr ) - ( (LPUNKNOWN)*ppvObject )->AddRef(); - - return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; - } - - STDMETHOD_(ULONG, AddRef)( void ) - { - return ++m_nRefCount; - } - - STDMETHOD_(ULONG, Release)( void ) - { - int nRefCount = --m_nRefCount; - if ( nRefCount == 0 ) - delete this; - return nRefCount; - } - - // IDataObject members - STDMETHOD(GetData)( FORMATETC __RPC_FAR *pformatetcIn, STGMEDIUM __RPC_FAR *pmedium ) - { - if ( pformatetcIn == nullptr || pmedium == nullptr ) - return E_INVALIDARG; - - ZeroMemory( pmedium, sizeof( STGMEDIUM ) ); - - for ( int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++ ) - { - if ( pformatetcIn->tymed & m_vFormatEtc[ nFormatEtc ].tymed && - pformatetcIn->dwAspect == m_vFormatEtc[ nFormatEtc ].dwAspect && - pformatetcIn->cfFormat == m_vFormatEtc[ nFormatEtc ].cfFormat ) - { - if ( m_vStgMedium[ nFormatEtc ].tymed == TYMED_NULL ) - return OnRenderData( m_vFormatEtc[ nFormatEtc ], pmedium, ( GetAsyncKeyState( m_bSwappedButtons ? VK_RBUTTON : VK_LBUTTON ) >= 0 ) ) ? S_OK : DV_E_FORMATETC; - - CopyMedium( pmedium, m_vStgMedium[ nFormatEtc ], m_vFormatEtc[ nFormatEtc ] ); - return S_OK; - } - } - - return DV_E_FORMATETC; - } - - STDMETHOD(GetDataHere)( FORMATETC __RPC_FAR * /*pformatetc*/, STGMEDIUM __RPC_FAR * /*pmedium*/ ) - { - return E_NOTIMPL; - } - - STDMETHOD(QueryGetData)( FORMATETC __RPC_FAR *pformatetc ) - { - if ( pformatetc == nullptr ) - return E_INVALIDARG; - - if ( !( pformatetc->dwAspect & DVASPECT_CONTENT ) ) - return DV_E_DVASPECT; - - HRESULT hResult = DV_E_TYMED; - for ( int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++ ) - { - if ( !( pformatetc->tymed & m_vFormatEtc[ nFormatEtc ].tymed ) ) - { - hResult = DV_E_TYMED; - continue; - } - - if ( pformatetc->cfFormat == m_vFormatEtc[ nFormatEtc ].cfFormat ) - return S_OK; - - hResult = DV_E_CLIPFORMAT; - } - - return hResult; - } - - STDMETHOD(GetCanonicalFormatEtc)( FORMATETC __RPC_FAR * /*pformatectIn*/, FORMATETC __RPC_FAR * pformatetcOut ) - { - return pformatetcOut == nullptr ? E_INVALIDARG : DATA_S_SAMEFORMATETC; - } - - STDMETHOD(SetData)( FORMATETC __RPC_FAR *pformatetc, STGMEDIUM __RPC_FAR *pmedium, BOOL bRelease ) + // IUnknown members + STDMETHOD(QueryInterface) + (REFIID refiid, void FAR * FAR * ppvObject) { - if ( pformatetc == nullptr || pmedium == nullptr ) - return E_INVALIDARG; + *ppvObject = (refiid == IID_IUnknown || refiid == IID_IDataObject) ? this : nullptr; - m_vFormatEtc.push_back( *pformatetc ); - - STGMEDIUM StgMedium = *pmedium; - - if ( !bRelease ) - CopyMedium( &StgMedium, *pmedium, *pformatetc ); + if (*ppvObject != nullptr) + ((LPUNKNOWN)*ppvObject)->AddRef(); - m_vStgMedium.push_back( StgMedium ); + return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; + } - return S_OK; - } - - STDMETHOD(EnumFormatEtc)( DWORD dwDirection, IEnumFORMATETC __RPC_FAR *__RPC_FAR *ppenumFormatEtc ) + STDMETHOD_(ULONG, AddRef) + (void) { - if ( ppenumFormatEtc == nullptr ) - return E_POINTER; + return ++m_nRefCount; + } - switch ( dwDirection ) - { - case DATADIR_GET: *ppenumFormatEtc = new CEnumFormatEtc( m_vFormatEtc ); - ( (CEnumFormatEtc*)*ppenumFormatEtc )->AddRef(); - return S_OK; - default: *ppenumFormatEtc = nullptr; - return E_NOTIMPL; - } - } - - STDMETHOD(DAdvise)( FORMATETC __RPC_FAR * /*pformatetc*/, DWORD /*advf*/, IAdviseSink __RPC_FAR * /*pAdvSink*/, DWORD __RPC_FAR * /*pdwConnection*/ ) + STDMETHOD_(ULONG, Release) + (void) { - return OLE_E_ADVISENOTSUPPORTED; + int nRefCount = --m_nRefCount; + if (nRefCount == 0) + delete this; + return nRefCount; } - - STDMETHOD(DUnadvise)( DWORD /*dwConnection*/ ) + + // IDataObject members + STDMETHOD(GetData) + (FORMATETC __RPC_FAR * pformatetcIn, STGMEDIUM __RPC_FAR * pmedium) { - return E_NOTIMPL; + if (pformatetcIn == nullptr || pmedium == nullptr) + return E_INVALIDARG; + + ZeroMemory(pmedium, sizeof(STGMEDIUM)); + + for (int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++) + { + if (pformatetcIn->tymed & m_vFormatEtc[nFormatEtc].tymed && pformatetcIn->dwAspect == m_vFormatEtc[nFormatEtc].dwAspect && pformatetcIn->cfFormat == m_vFormatEtc[nFormatEtc].cfFormat) + { + if (m_vStgMedium[nFormatEtc].tymed == TYMED_NULL) + return OnRenderData(m_vFormatEtc[nFormatEtc], pmedium, (GetAsyncKeyState(m_bSwappedButtons ? VK_RBUTTON : VK_LBUTTON) >= 0)) ? S_OK : DV_E_FORMATETC; + + CopyMedium(pmedium, m_vStgMedium[nFormatEtc], m_vFormatEtc[nFormatEtc]); + return S_OK; + } + } + + return DV_E_FORMATETC; } - - STDMETHOD(EnumDAdvise)( IEnumSTATDATA __RPC_FAR *__RPC_FAR * /*ppenumAdvise*/ ) + + STDMETHOD(GetDataHere) + (FORMATETC __RPC_FAR * /*pformatetc*/, STGMEDIUM __RPC_FAR * /*pmedium*/) { - return OLE_E_ADVISENOTSUPPORTED; + return E_NOTIMPL; + } + + STDMETHOD(QueryGetData) + (FORMATETC __RPC_FAR * pformatetc) + { + if (pformatetc == nullptr) + return E_INVALIDARG; + + if (!(pformatetc->dwAspect & DVASPECT_CONTENT)) + return DV_E_DVASPECT; + + HRESULT hResult = DV_E_TYMED; + for (int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++) + { + if (!(pformatetc->tymed & m_vFormatEtc[nFormatEtc].tymed)) + { + hResult = DV_E_TYMED; + continue; + } + + if (pformatetc->cfFormat == m_vFormatEtc[nFormatEtc].cfFormat) + return S_OK; + + hResult = DV_E_CLIPFORMAT; + } + + return hResult; + } + + STDMETHOD(GetCanonicalFormatEtc) + (FORMATETC __RPC_FAR * /*pformatectIn*/, FORMATETC __RPC_FAR * pformatetcOut) + { + return pformatetcOut == nullptr ? E_INVALIDARG : DATA_S_SAMEFORMATETC; + } + + STDMETHOD(SetData) + (FORMATETC __RPC_FAR * pformatetc, STGMEDIUM __RPC_FAR * pmedium, BOOL bRelease) + { + if (pformatetc == nullptr || pmedium == nullptr) + return E_INVALIDARG; + + m_vFormatEtc.push_back(*pformatetc); + + STGMEDIUM StgMedium = *pmedium; + + if (!bRelease) + CopyMedium(&StgMedium, *pmedium, *pformatetc); + + m_vStgMedium.push_back(StgMedium); + + return S_OK; + } + + STDMETHOD(EnumFormatEtc) + (DWORD dwDirection, IEnumFORMATETC __RPC_FAR * __RPC_FAR * ppenumFormatEtc) + { + if (ppenumFormatEtc == nullptr) + return E_POINTER; + + switch (dwDirection) + { + case DATADIR_GET: + *ppenumFormatEtc = new CEnumFormatEtc(m_vFormatEtc); + ((CEnumFormatEtc *)*ppenumFormatEtc)->AddRef(); + return S_OK; + default: + *ppenumFormatEtc = nullptr; + return E_NOTIMPL; + } + } + + STDMETHOD(DAdvise) + (FORMATETC __RPC_FAR * /*pformatetc*/, DWORD /*advf*/, IAdviseSink __RPC_FAR * /*pAdvSink*/, DWORD __RPC_FAR * /*pdwConnection*/) + { + return OLE_E_ADVISENOTSUPPORTED; + } + + STDMETHOD(DUnadvise) + (DWORD /*dwConnection*/) + { + return E_NOTIMPL; + } + + STDMETHOD(EnumDAdvise) + (IEnumSTATDATA __RPC_FAR * __RPC_FAR * /*ppenumAdvise*/) + { + return OLE_E_ADVISENOTSUPPORTED; + } + + void CopyMedium(STGMEDIUM * pMedDest, STGMEDIUM & MedSrc, FORMATETC & FmtSrc) + { + switch (MedSrc.tymed) + { + case TYMED_HGLOBAL: + pMedDest->hGlobal = (HGLOBAL)OleDuplicateData(MedSrc.hGlobal, FmtSrc.cfFormat, NULL); + break; + case TYMED_GDI: + pMedDest->hBitmap = (HBITMAP)OleDuplicateData(MedSrc.hBitmap, FmtSrc.cfFormat, NULL); + break; + case TYMED_MFPICT: + pMedDest->hMetaFilePict = (HMETAFILEPICT)OleDuplicateData(MedSrc.hMetaFilePict, FmtSrc.cfFormat, NULL); + break; + case TYMED_ENHMF: + pMedDest->hEnhMetaFile = (HENHMETAFILE)OleDuplicateData(MedSrc.hEnhMetaFile, FmtSrc.cfFormat, NULL); + break; + case TYMED_FILE: + pMedDest->lpszFileName = (LPOLESTR)OleDuplicateData(MedSrc.lpszFileName, FmtSrc.cfFormat, NULL); + break; + case TYMED_ISTREAM: + pMedDest->pstm = MedSrc.pstm; + MedSrc.pstm->AddRef(); + break; + case TYMED_ISTORAGE: + pMedDest->pstg = MedSrc.pstg; + MedSrc.pstg->AddRef(); + break; + } + + pMedDest->tymed = MedSrc.tymed; + pMedDest->pUnkForRelease = nullptr; + + if (MedSrc.pUnkForRelease != nullptr) + { + pMedDest->pUnkForRelease = MedSrc.pUnkForRelease; + MedSrc.pUnkForRelease->AddRef(); + } + } + + virtual BOOL OnRenderData(FORMATETC & /*FormatEtc*/, STGMEDIUM * /*pStgMedium*/, BOOL /*bDropComplete*/) + { + return FALSE; } - - void CopyMedium( STGMEDIUM *pMedDest, STGMEDIUM& MedSrc, FORMATETC& FmtSrc ) - { - switch( MedSrc.tymed ) - { - case TYMED_HGLOBAL: pMedDest->hGlobal = (HGLOBAL)OleDuplicateData( MedSrc.hGlobal, FmtSrc.cfFormat, NULL ); - break; - case TYMED_GDI: pMedDest->hBitmap = (HBITMAP)OleDuplicateData( MedSrc.hBitmap, FmtSrc.cfFormat, NULL); - break; - case TYMED_MFPICT: pMedDest->hMetaFilePict = (HMETAFILEPICT)OleDuplicateData( MedSrc.hMetaFilePict, FmtSrc.cfFormat, NULL); - break; - case TYMED_ENHMF: pMedDest->hEnhMetaFile = (HENHMETAFILE)OleDuplicateData( MedSrc.hEnhMetaFile, FmtSrc.cfFormat, NULL); - break; - case TYMED_FILE: pMedDest->lpszFileName = (LPOLESTR)OleDuplicateData( MedSrc.lpszFileName, FmtSrc.cfFormat, NULL); - break; - case TYMED_ISTREAM: pMedDest->pstm = MedSrc.pstm; - MedSrc.pstm->AddRef(); - break; - case TYMED_ISTORAGE: pMedDest->pstg = MedSrc.pstg; - MedSrc.pstg->AddRef(); - break; - } - - pMedDest->tymed = MedSrc.tymed; - pMedDest->pUnkForRelease = nullptr; - - if ( MedSrc.pUnkForRelease != nullptr ) - { - pMedDest->pUnkForRelease = MedSrc.pUnkForRelease; - MedSrc.pUnkForRelease->AddRef(); - } - } - - virtual BOOL OnRenderData( FORMATETC& /*FormatEtc*/, STGMEDIUM * /*pStgMedium*/, BOOL /*bDropComplete*/ ) - { - return FALSE; - } }; class CDropTarget : public IDropTarget { -public: - CDropTarget( HWND hTargetWnd ) - { - m_hTargetWnd = hTargetWnd; - m_nRefCount = 0; - m_bAllowDrop = FALSE; - m_pDropTargetHelper = nullptr; - ZeroMemory( &m_FormatEtc, sizeof( FORMATETC ) ); - ZeroMemory( &m_StgMedium, sizeof( STGMEDIUM ) ); - - if ( FAILED( CoCreateInstance( CLSID_DragDropHelper, nullptr, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper, (LPVOID*)&m_pDropTargetHelper ) ) ) - m_pDropTargetHelper = nullptr; - } - - virtual ~CDropTarget() - { - if ( m_pDropTargetHelper != nullptr ) - { - m_pDropTargetHelper->Release(); - m_pDropTargetHelper = nullptr; - } - } +public: + CDropTarget(HWND hTargetWnd) + { + m_hTargetWnd = hTargetWnd; + m_nRefCount = 0; + m_bAllowDrop = FALSE; + m_pDropTargetHelper = nullptr; + ZeroMemory(&m_FormatEtc, sizeof(FORMATETC)); + ZeroMemory(&m_StgMedium, sizeof(STGMEDIUM)); + + if (FAILED(CoCreateInstance(CLSID_DragDropHelper, nullptr, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper, (LPVOID *)&m_pDropTargetHelper))) + m_pDropTargetHelper = nullptr; + } + + virtual ~CDropTarget() + { + if (m_pDropTargetHelper != nullptr) + { + m_pDropTargetHelper->Release(); + m_pDropTargetHelper = nullptr; + } + } protected: - HWND m_hTargetWnd; - int m_nRefCount; - struct IDropTargetHelper *m_pDropTargetHelper; - vector < FORMATETC > m_vFormatEtc; - BOOL m_bAllowDrop; - FORMATETC m_FormatEtc; - STGMEDIUM m_StgMedium; - + HWND m_hTargetWnd; + int m_nRefCount; + struct IDropTargetHelper * m_pDropTargetHelper; + vector m_vFormatEtc; + BOOL m_bAllowDrop; + FORMATETC m_FormatEtc; + STGMEDIUM m_StgMedium; + public: - // IUnknown members - STDMETHOD(QueryInterface)( REFIID refiid, void FAR* FAR* ppvObject ) - { - *ppvObject = ( refiid == IID_IUnknown || refiid == IID_IDropTarget ) ? this : nullptr; - - if ( *ppvObject != nullptr ) - ( (LPUNKNOWN)*ppvObject )->AddRef(); - - return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; - } - - STDMETHOD_(ULONG, AddRef)( void ) - { - return ++m_nRefCount; - } - - STDMETHOD_(ULONG, Release)( void ) - { - int nRefCount = --m_nRefCount; - if ( nRefCount == 0 ) - delete this; - return nRefCount; - } - - STDMETHOD(DragEnter)( IDataObject __RPC_FAR *pDataObject, DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect ) - { - if ( pDataObject == nullptr ) - return E_INVALIDARG; - - if ( m_pDropTargetHelper != nullptr ) - m_pDropTargetHelper->DragEnter( m_hTargetWnd, pDataObject, (LPPOINT)&pt, *pdwEffect ); - - ZeroMemory( &m_FormatEtc, sizeof( FORMATETC ) ); - if ( m_StgMedium.tymed != TYMED_NULL ) - ReleaseStgMedium( &m_StgMedium ); - ZeroMemory( &m_StgMedium, sizeof( STGMEDIUM ) ); - - for ( int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++ ) - { - STGMEDIUM StgMedium; - m_bAllowDrop = ( pDataObject->GetData( &m_vFormatEtc[ nFormatEtc ], &StgMedium ) == S_OK ); - - if ( m_bAllowDrop ) - { - // Store drag data for later use in DragOver - m_FormatEtc = m_vFormatEtc[ nFormatEtc ]; - m_StgMedium = StgMedium; - - // Get client cursor position - CWindow hWnd( m_hTargetWnd ); - CPoint point( pt.x, pt.y ); - hWnd.ScreenToClient( &point ); - - *pdwEffect = OnDragEnter( m_FormatEtc, m_StgMedium, dwKeyState, point ); - - break; - } - } - - QueryDrop( dwKeyState, pdwEffect ); - - return S_OK; - } - - STDMETHOD(DragOver)( DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect ) - { - if ( m_pDropTargetHelper ) - m_pDropTargetHelper->DragOver( (LPPOINT)&pt, *pdwEffect ); - - if ( m_bAllowDrop && m_FormatEtc.cfFormat != CF_NULL && m_StgMedium.tymed != TYMED_NULL ) - { - // Get client cursor position - CWindow hWnd( m_hTargetWnd ); - CPoint point( pt.x, pt.y ); - hWnd.ScreenToClient( &point ); - - *pdwEffect = OnDragOver( m_FormatEtc, m_StgMedium, dwKeyState, point ); - } - - QueryDrop( dwKeyState, pdwEffect ); - - return S_OK; - } - - STDMETHOD(DragLeave)( void ) - { - if ( m_pDropTargetHelper ) - m_pDropTargetHelper->DragLeave(); - - OnDragLeave(); - - m_bAllowDrop = FALSE; - - ZeroMemory( &m_FormatEtc, sizeof( FORMATETC ) ); - if ( m_StgMedium.tymed != TYMED_NULL ) - ReleaseStgMedium( &m_StgMedium ); - ZeroMemory( &m_StgMedium, sizeof( STGMEDIUM ) ); - - return S_OK; - } - - STDMETHOD(Drop)( IDataObject __RPC_FAR *pDataObject, DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect ) + // IUnknown members + STDMETHOD(QueryInterface) + (REFIID refiid, void FAR * FAR * ppvObject) { - if ( pDataObject == nullptr ) - return E_INVALIDARG; + *ppvObject = (refiid == IID_IUnknown || refiid == IID_IDropTarget) ? this : nullptr; - if ( m_pDropTargetHelper ) - m_pDropTargetHelper->Drop( pDataObject, (LPPOINT)&pt, *pdwEffect ); + if (*ppvObject != nullptr) + ((LPUNKNOWN)*ppvObject)->AddRef(); - if ( m_bAllowDrop && m_FormatEtc.cfFormat != CF_NULL && QueryDrop( dwKeyState, pdwEffect ) ) - { - STGMEDIUM StgMedium; - if ( pDataObject->GetData( &m_FormatEtc, &StgMedium ) == S_OK ) - { - // Get client cursor position - CWindow hWnd( m_hTargetWnd ); - CPoint point( pt.x, pt.y ); - hWnd.ScreenToClient( &point ); - - if ( !OnDrop( m_FormatEtc, StgMedium, *pdwEffect, point ) ) - *pdwEffect = DROPEFFECT_NONE; - - ReleaseStgMedium( &StgMedium ); - } - } - - m_bAllowDrop = FALSE; - - ZeroMemory( &m_FormatEtc, sizeof( FORMATETC ) ); - if ( m_StgMedium.tymed != TYMED_NULL ) - ReleaseStgMedium( &m_StgMedium ); - ZeroMemory( &m_StgMedium, sizeof( STGMEDIUM ) ); - - return S_OK; - } - - void AddSupportedFormat( FORMATETC& FormatEtc ) - { - m_vFormatEtc.push_back( FormatEtc ); - } - - void AddSupportedFormat( CLIPFORMAT cfFormat ) - { - FORMATETC FormatEtc; - ZeroMemory( &FormatEtc, sizeof( FORMATETC ) ); - - FormatEtc.cfFormat = cfFormat; - FormatEtc.dwAspect = DVASPECT_CONTENT; - FormatEtc.lindex = -1; - FormatEtc.tymed = TYMED_HGLOBAL; - - AddSupportedFormat( FormatEtc ); - } - - BOOL QueryDrop( DWORD dwKeyState, LPDWORD pdwEffect ) - { - DWORD dwEffects = *pdwEffect; + return *ppvObject == nullptr ? E_NOINTERFACE : S_OK; + } - if ( !m_bAllowDrop ) - { - *pdwEffect = DROPEFFECT_NONE; - return FALSE; - } - - *pdwEffect = ( dwKeyState & MK_CONTROL ) ? ( ( dwKeyState & MK_SHIFT ) ? DROPEFFECT_LINK : DROPEFFECT_COPY ) : ( ( dwKeyState & MK_SHIFT ) ? DROPEFFECT_MOVE : 0 ); - if ( *pdwEffect == 0 ) - { - if ( dwEffects & DROPEFFECT_COPY ) - *pdwEffect = DROPEFFECT_COPY; - else if ( dwEffects & DROPEFFECT_MOVE ) - *pdwEffect = DROPEFFECT_MOVE; - else if (dwEffects & DROPEFFECT_LINK ) - *pdwEffect = DROPEFFECT_LINK; - else - *pdwEffect = DROPEFFECT_NONE; - } - else if ( !( *pdwEffect & dwEffects ) ) - *pdwEffect = DROPEFFECT_NONE; + STDMETHOD_(ULONG, AddRef) + (void) + { + return ++m_nRefCount; + } - return ( *pdwEffect != DROPEFFECT_NONE ); - } + STDMETHOD_(ULONG, Release) + (void) + { + int nRefCount = --m_nRefCount; + if (nRefCount == 0) + delete this; + return nRefCount; + } - virtual DWORD OnDragEnter( FORMATETC& /*FormatEtc*/, STGMEDIUM& /*StgMedium*/, DWORD /*dwKeyState*/, CPoint /*point*/ ) - { - return FALSE; - } - - virtual DWORD OnDragOver( FORMATETC& /*FormatEtc*/, STGMEDIUM& /*StgMedium*/, DWORD /*dwKeyState*/, CPoint /*point*/ ) - { - return FALSE; - } - - virtual BOOL OnDrop( FORMATETC& /*FormatEtc*/, STGMEDIUM& /*StgMedium*/, DWORD /*dwEffect*/, CPoint /*point*/ ) - { - return FALSE; - } - - virtual void OnDragLeave() - { - } + STDMETHOD(DragEnter) + (IDataObject __RPC_FAR * pDataObject, DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR * pdwEffect) + { + if (pDataObject == nullptr) + return E_INVALIDARG; + + if (m_pDropTargetHelper != nullptr) + m_pDropTargetHelper->DragEnter(m_hTargetWnd, pDataObject, (LPPOINT)&pt, *pdwEffect); + + ZeroMemory(&m_FormatEtc, sizeof(FORMATETC)); + if (m_StgMedium.tymed != TYMED_NULL) + ReleaseStgMedium(&m_StgMedium); + ZeroMemory(&m_StgMedium, sizeof(STGMEDIUM)); + + for (int nFormatEtc = 0; nFormatEtc < (int)m_vFormatEtc.size(); nFormatEtc++) + { + STGMEDIUM StgMedium; + m_bAllowDrop = (pDataObject->GetData(&m_vFormatEtc[nFormatEtc], &StgMedium) == S_OK); + + if (m_bAllowDrop) + { + // Store drag data for later use in DragOver + m_FormatEtc = m_vFormatEtc[nFormatEtc]; + m_StgMedium = StgMedium; + + // Get client cursor position + CWindow hWnd(m_hTargetWnd); + CPoint point(pt.x, pt.y); + hWnd.ScreenToClient(&point); + + *pdwEffect = OnDragEnter(m_FormatEtc, m_StgMedium, dwKeyState, point); + + break; + } + } + + QueryDrop(dwKeyState, pdwEffect); + + return S_OK; + } + + STDMETHOD(DragOver) + (DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR * pdwEffect) + { + if (m_pDropTargetHelper) + m_pDropTargetHelper->DragOver((LPPOINT)&pt, *pdwEffect); + + if (m_bAllowDrop && m_FormatEtc.cfFormat != CF_NULL && m_StgMedium.tymed != TYMED_NULL) + { + // Get client cursor position + CWindow hWnd(m_hTargetWnd); + CPoint point(pt.x, pt.y); + hWnd.ScreenToClient(&point); + + *pdwEffect = OnDragOver(m_FormatEtc, m_StgMedium, dwKeyState, point); + } + + QueryDrop(dwKeyState, pdwEffect); + + return S_OK; + } + + STDMETHOD(DragLeave) + (void) + { + if (m_pDropTargetHelper) + m_pDropTargetHelper->DragLeave(); + + OnDragLeave(); + + m_bAllowDrop = FALSE; + + ZeroMemory(&m_FormatEtc, sizeof(FORMATETC)); + if (m_StgMedium.tymed != TYMED_NULL) + ReleaseStgMedium(&m_StgMedium); + ZeroMemory(&m_StgMedium, sizeof(STGMEDIUM)); + + return S_OK; + } + + STDMETHOD(Drop) + (IDataObject __RPC_FAR * pDataObject, DWORD dwKeyState, POINTL pt, DWORD __RPC_FAR * pdwEffect) + { + if (pDataObject == nullptr) + return E_INVALIDARG; + + if (m_pDropTargetHelper) + m_pDropTargetHelper->Drop(pDataObject, (LPPOINT)&pt, *pdwEffect); + + if (m_bAllowDrop && m_FormatEtc.cfFormat != CF_NULL && QueryDrop(dwKeyState, pdwEffect)) + { + STGMEDIUM StgMedium; + if (pDataObject->GetData(&m_FormatEtc, &StgMedium) == S_OK) + { + // Get client cursor position + CWindow hWnd(m_hTargetWnd); + CPoint point(pt.x, pt.y); + hWnd.ScreenToClient(&point); + + if (!OnDrop(m_FormatEtc, StgMedium, *pdwEffect, point)) + *pdwEffect = DROPEFFECT_NONE; + + ReleaseStgMedium(&StgMedium); + } + } + + m_bAllowDrop = FALSE; + + ZeroMemory(&m_FormatEtc, sizeof(FORMATETC)); + if (m_StgMedium.tymed != TYMED_NULL) + ReleaseStgMedium(&m_StgMedium); + ZeroMemory(&m_StgMedium, sizeof(STGMEDIUM)); + + return S_OK; + } + + void AddSupportedFormat(FORMATETC & FormatEtc) + { + m_vFormatEtc.push_back(FormatEtc); + } + + void AddSupportedFormat(CLIPFORMAT cfFormat) + { + FORMATETC FormatEtc; + ZeroMemory(&FormatEtc, sizeof(FORMATETC)); + + FormatEtc.cfFormat = cfFormat; + FormatEtc.dwAspect = DVASPECT_CONTENT; + FormatEtc.lindex = -1; + FormatEtc.tymed = TYMED_HGLOBAL; + + AddSupportedFormat(FormatEtc); + } + + BOOL QueryDrop(DWORD dwKeyState, LPDWORD pdwEffect) + { + DWORD dwEffects = *pdwEffect; + + if (!m_bAllowDrop) + { + *pdwEffect = DROPEFFECT_NONE; + return FALSE; + } + + *pdwEffect = (dwKeyState & MK_CONTROL) ? ((dwKeyState & MK_SHIFT) ? DROPEFFECT_LINK : DROPEFFECT_COPY) : ((dwKeyState & MK_SHIFT) ? DROPEFFECT_MOVE : 0); + if (*pdwEffect == 0) + { + if (dwEffects & DROPEFFECT_COPY) + *pdwEffect = DROPEFFECT_COPY; + else if (dwEffects & DROPEFFECT_MOVE) + *pdwEffect = DROPEFFECT_MOVE; + else if (dwEffects & DROPEFFECT_LINK) + *pdwEffect = DROPEFFECT_LINK; + else + *pdwEffect = DROPEFFECT_NONE; + } + else if (!(*pdwEffect & dwEffects)) + *pdwEffect = DROPEFFECT_NONE; + + return (*pdwEffect != DROPEFFECT_NONE); + } + + virtual DWORD OnDragEnter(FORMATETC & /*FormatEtc*/, STGMEDIUM & /*StgMedium*/, DWORD /*dwKeyState*/, CPoint /*point*/) + { + return FALSE; + } + + virtual DWORD OnDragOver(FORMATETC & /*FormatEtc*/, STGMEDIUM & /*StgMedium*/, DWORD /*dwKeyState*/, CPoint /*point*/) + { + return FALSE; + } + + virtual BOOL OnDrop(FORMATETC & /*FormatEtc*/, STGMEDIUM & /*StgMedium*/, DWORD /*dwEffect*/, CPoint /*point*/) + { + return FALSE; + } + + virtual void OnDragLeave() + { + } }; -template < class T > +template class CDropTargetT : public CDropTarget { public: - CDropTargetT( HWND hTargetWnd ) : CDropTarget( hTargetWnd ) - { - m_pDelegate = nullptr; - } + CDropTargetT(HWND hTargetWnd) : + CDropTarget(hTargetWnd) + { + m_pDelegate = nullptr; + } protected: - T *m_pDelegate; + T * m_pDelegate; -public: - BOOL Register( T *pDelegate ) - { - m_pDelegate = pDelegate; - return TRUE; - } - - virtual DWORD OnDragEnter( FORMATETC& FormatEtc, STGMEDIUM& StgMedium, DWORD dwKeyState, CPoint point ) - { - return m_pDelegate == nullptr ? DROPEFFECT_NONE : m_pDelegate->OnDragEnter( FormatEtc, StgMedium, dwKeyState, point ); - } - - virtual DWORD OnDragOver( FORMATETC& FormatEtc, STGMEDIUM& StgMedium, DWORD dwKeyState, CPoint point ) - { - return m_pDelegate == nullptr ? DROPEFFECT_NONE : m_pDelegate->OnDragOver( FormatEtc, StgMedium, dwKeyState, point ); - } - - virtual BOOL OnDrop( FORMATETC& FormatEtc, STGMEDIUM& StgMedium, DWORD dwEffect, CPoint point ) - { - return m_pDelegate == nullptr ? FALSE : m_pDelegate->OnDrop( FormatEtc, StgMedium, dwEffect, point ); - } - - virtual void OnDragLeave() - { - if ( m_pDelegate != nullptr ) - m_pDelegate->OnDragLeave(); - } +public: + BOOL Register(T * pDelegate) + { + m_pDelegate = pDelegate; + return TRUE; + } + + virtual DWORD OnDragEnter(FORMATETC & FormatEtc, STGMEDIUM & StgMedium, DWORD dwKeyState, CPoint point) + { + return m_pDelegate == nullptr ? DROPEFFECT_NONE : m_pDelegate->OnDragEnter(FormatEtc, StgMedium, dwKeyState, point); + } + + virtual DWORD OnDragOver(FORMATETC & FormatEtc, STGMEDIUM & StgMedium, DWORD dwKeyState, CPoint point) + { + return m_pDelegate == nullptr ? DROPEFFECT_NONE : m_pDelegate->OnDragOver(FormatEtc, StgMedium, dwKeyState, point); + } + + virtual BOOL OnDrop(FORMATETC & FormatEtc, STGMEDIUM & StgMedium, DWORD dwEffect, CPoint point) + { + return m_pDelegate == nullptr ? FALSE : m_pDelegate->OnDrop(FormatEtc, StgMedium, dwEffect, point); + } + + virtual void OnDragLeave() + { + if (m_pDelegate != nullptr) + m_pDelegate->OnDragLeave(); + } }; -template < class T > +template class CDataObjectT : public CDataObject { public: - CDataObjectT( CDropSource *pDropSource ) : CDataObject( pDropSource ) - { - m_pDelegate = FALSE; - } + CDataObjectT(CDropSource * pDropSource) : + CDataObject(pDropSource) + { + m_pDelegate = FALSE; + } protected: - T *m_pDelegate; + T * m_pDelegate; -public: - BOOL Register( T *pDelegate ) - { - m_pDelegate = pDelegate; - return TRUE; - } - - virtual BOOL OnRenderData( FORMATETC& FormatEtc, STGMEDIUM *pStgMedium, BOOL bDropComplete ) - { - return m_pDelegate == nullptr ? FALSE : m_pDelegate->OnRenderData( FormatEtc, pStgMedium, bDropComplete ); - } +public: + BOOL Register(T * pDelegate) + { + m_pDelegate = pDelegate; + return TRUE; + } + + virtual BOOL OnRenderData(FORMATETC & FormatEtc, STGMEDIUM * pStgMedium, BOOL bDropComplete) + { + return m_pDelegate == nullptr ? FALSE : m_pDelegate->OnRenderData(FormatEtc, pStgMedium, bDropComplete); + } }; -template < class T > +template class CDragDrop { public: - CDragDrop() - { - m_pDropSource = nullptr; - m_pDataObject = nullptr; - m_pDropTarget = nullptr; - m_hTargetWnd = nullptr; - } - - virtual ~CDragDrop() - { - if ( m_pDropSource != nullptr ) - m_pDropSource->Release(); - if ( m_pDataObject != nullptr ) - m_pDataObject->Release(); - } + CDragDrop() + { + m_pDropSource = nullptr; + m_pDataObject = nullptr; + m_pDropTarget = nullptr; + m_hTargetWnd = nullptr; + } + + virtual ~CDragDrop() + { + if (m_pDropSource != nullptr) + m_pDropSource->Release(); + if (m_pDataObject != nullptr) + m_pDataObject->Release(); + } protected: - CDropSource *m_pDropSource; - CDataObjectT< T > *m_pDataObject; - CDropTargetT< T > *m_pDropTarget; - HWND m_hTargetWnd; + CDropSource * m_pDropSource; + CDataObjectT * m_pDataObject; + CDropTargetT * m_pDropTarget; + HWND m_hTargetWnd; public: - BOOL Register( T *pDelegate, BOOL bDropSource = TRUE ) - { - m_hTargetWnd = pDelegate->m_hWnd; - - // Instantiate new drop target object - m_pDropTarget = new CDropTargetT< T >( m_hTargetWnd ); - m_pDropTarget->Register( pDelegate ); - - // Register drop target - if ( FAILED( RegisterDragDrop( m_hTargetWnd, m_pDropTarget ) ) ) - { - delete m_pDropTarget; - m_pDropTarget = nullptr; - return FALSE; - } - - // Is this a drop target only? - if ( !bDropSource ) - return TRUE; - - // Instantiate new drop source object - m_pDropSource = new CDropSource; - m_pDropSource->AddRef(); - - m_pDataObject = new CDataObjectT< T >( m_pDropSource ); - m_pDataObject->AddRef(); - - // Register drop source delegate for data render - return m_pDataObject->Register( pDelegate ); - } - - BOOL Revoke() - { - m_pDropTarget = nullptr; - return ( RevokeDragDrop( m_hTargetWnd ) == S_OK ); - } - - BOOL AddTargetFormat( CLIPFORMAT cfFormat ) - { - if ( m_pDropTarget == nullptr ) - return FALSE; - m_pDropTarget->AddSupportedFormat( cfFormat ); - return TRUE; - } - - BOOL AddSourceFormat( CLIPFORMAT cfFormat ) - { - if ( m_pDataObject == nullptr ) - return FALSE; - - FORMATETC FormatEtc; - ZeroMemory( &FormatEtc, sizeof( FORMATETC ) ); - - FormatEtc.cfFormat = cfFormat; - FormatEtc.dwAspect = DVASPECT_CONTENT; - FormatEtc.lindex = -1; - FormatEtc.tymed = TYMED_HGLOBAL; - - STGMEDIUM StgMedium; - ZeroMemory( &StgMedium, sizeof( STGMEDIUM ) ); - - return SUCCEEDED( m_pDataObject->SetData( &FormatEtc, &StgMedium, TRUE ) ); - } - - BOOL SetClipboard( FORMATETC& FormatEtc, STGMEDIUM& StgMedium ) - { - if ( m_pDataObject == nullptr ) - return DROPEFFECT_NONE; - - if ( FAILED( m_pDataObject->SetData( &FormatEtc, &StgMedium, TRUE ) ) ) - return DROPEFFECT_NONE; - - return ( OleSetClipboard( m_pDataObject ) == S_OK ); - } - - BOOL FlushClipboard() - { - return ( OleFlushClipboard() == S_OK ); - } - - DWORD DoDragDrop( SHDRAGIMAGE *pDragImage = nullptr, DWORD dwValidEffects = DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK ) - { - if ( m_pDataObject == nullptr ) - return DROPEFFECT_NONE; - - IDragSourceHelper *pDragSourceHelper = nullptr; - - // Instantiate drag source helper object - if ( pDragImage != nullptr ) - { - if ( FAILED( CoCreateInstance( CLSID_DragDropHelper, nullptr, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, (LPVOID*)&pDragSourceHelper ) ) ) - pDragSourceHelper = nullptr; - - if ( pDragSourceHelper != nullptr ) - pDragSourceHelper->InitializeFromBitmap( pDragImage, m_pDataObject ); - } - - DWORD dwEffects = DROPEFFECT_NONE; - dwEffects = ::DoDragDrop( m_pDataObject, m_pDropSource, dwValidEffects, &dwEffects ) == DRAGDROP_S_DROP ? DROPEFFECT_NONE : dwEffects; - - // Destroy drag source helper object - if ( pDragSourceHelper != nullptr ) - pDragSourceHelper->Release(); - - return dwEffects; - } + BOOL Register(T * pDelegate, BOOL bDropSource = TRUE) + { + m_hTargetWnd = pDelegate->m_hWnd; + + // Instantiate new drop target object + m_pDropTarget = new CDropTargetT(m_hTargetWnd); + m_pDropTarget->Register(pDelegate); + + // Register drop target + if (FAILED(RegisterDragDrop(m_hTargetWnd, m_pDropTarget))) + { + delete m_pDropTarget; + m_pDropTarget = nullptr; + return FALSE; + } + + // Is this a drop target only? + if (!bDropSource) + return TRUE; + + // Instantiate new drop source object + m_pDropSource = new CDropSource; + m_pDropSource->AddRef(); + + m_pDataObject = new CDataObjectT(m_pDropSource); + m_pDataObject->AddRef(); + + // Register drop source delegate for data render + return m_pDataObject->Register(pDelegate); + } + + BOOL Revoke() + { + m_pDropTarget = nullptr; + return (RevokeDragDrop(m_hTargetWnd) == S_OK); + } + + BOOL AddTargetFormat(CLIPFORMAT cfFormat) + { + if (m_pDropTarget == nullptr) + return FALSE; + m_pDropTarget->AddSupportedFormat(cfFormat); + return TRUE; + } + + BOOL AddSourceFormat(CLIPFORMAT cfFormat) + { + if (m_pDataObject == nullptr) + return FALSE; + + FORMATETC FormatEtc; + ZeroMemory(&FormatEtc, sizeof(FORMATETC)); + + FormatEtc.cfFormat = cfFormat; + FormatEtc.dwAspect = DVASPECT_CONTENT; + FormatEtc.lindex = -1; + FormatEtc.tymed = TYMED_HGLOBAL; + + STGMEDIUM StgMedium; + ZeroMemory(&StgMedium, sizeof(STGMEDIUM)); + + return SUCCEEDED(m_pDataObject->SetData(&FormatEtc, &StgMedium, TRUE)); + } + + BOOL SetClipboard(FORMATETC & FormatEtc, STGMEDIUM & StgMedium) + { + if (m_pDataObject == nullptr) + return DROPEFFECT_NONE; + + if (FAILED(m_pDataObject->SetData(&FormatEtc, &StgMedium, TRUE))) + return DROPEFFECT_NONE; + + return (OleSetClipboard(m_pDataObject) == S_OK); + } + + BOOL FlushClipboard() + { + return (OleFlushClipboard() == S_OK); + } + + DWORD DoDragDrop(SHDRAGIMAGE * pDragImage = nullptr, DWORD dwValidEffects = DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK) + { + if (m_pDataObject == nullptr) + return DROPEFFECT_NONE; + + IDragSourceHelper * pDragSourceHelper = nullptr; + + // Instantiate drag source helper object + if (pDragImage != nullptr) + { + if (FAILED(CoCreateInstance(CLSID_DragDropHelper, nullptr, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, (LPVOID *)&pDragSourceHelper))) + pDragSourceHelper = nullptr; + + if (pDragSourceHelper != nullptr) + pDragSourceHelper->InitializeFromBitmap(pDragImage, m_pDataObject); + } + + DWORD dwEffects = DROPEFFECT_NONE; + dwEffects = ::DoDragDrop(m_pDataObject, m_pDropSource, dwValidEffects, &dwEffects) == DRAGDROP_S_DROP ? DROPEFFECT_NONE : dwEffects; + + // Destroy drag source helper object + if (pDragSourceHelper != nullptr) + pDragSourceHelper->Release(); + + return dwEffects; + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DropArrows.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DropArrows.h index 98163dfdc..277a15656 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/DropArrows.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/DropArrows.h @@ -1,101 +1,115 @@ #pragma once #include -class CDropArrows : public CWindowImpl< CDropArrows > +class CDropArrows : public CWindowImpl { public: - CDropArrows() - { - m_bVertical = FALSE; - m_nSpanLength = 0; - } - - ~CDropArrows() - { - } - - DECLARE_WND_CLASS( _T( "DropArrows" ) ) + CDropArrows() + { + m_bVertical = FALSE; + m_nSpanLength = 0; + } + + ~CDropArrows() + { + } + + DECLARE_WND_CLASS(_T( "DropArrows" )) protected: - CBrush m_bshArrowBrush; - CRgn m_rgnArrowRegion; - BOOL m_bVertical; - int m_nSpanLength; - + CBrush m_bshArrowBrush; + CRgn m_rgnArrowRegion; + BOOL m_bVertical; + int m_nSpanLength; + public: - BOOL Create( HWND hWndParent, int nSpanLength, BOOL bVertical ) - { - if ( !m_bshArrowBrush.CreateSolidBrush( RGB( 255, 0, 0 ) ) ) - return FALSE; - - m_bVertical = bVertical; - m_nSpanLength = nSpanLength + 20; + BOOL Create(HWND hWndParent, int nSpanLength, BOOL bVertical) + { + if (!m_bshArrowBrush.CreateSolidBrush(RGB(255, 0, 0))) + return FALSE; - CRect area( 0, 0, m_bVertical ? 12 : m_nSpanLength, m_bVertical ? m_nSpanLength : 12 ); - if ( CWindowImpl< CDropArrows >::Create( hWndParent, area, nullptr, WS_POPUP | WS_DISABLED, WS_EX_TOOLWINDOW ) == nullptr ) - return FALSE; - - POINT ptArrow[ 7 ]; + m_bVertical = bVertical; + m_nSpanLength = nSpanLength + 20; - ptArrow[0].x = bVertical ? 8 : 0; ptArrow[0].y = bVertical ? 0 : 9; - ptArrow[1].x = bVertical ? 8 : 4; ptArrow[1].y = bVertical ? 4 : 9; - ptArrow[2].x = bVertical ? 11 : 4; ptArrow[2].y = bVertical ? 4 : 12; - ptArrow[3].x = bVertical ? 6 : 10; ptArrow[3].y = bVertical ? 9 : 6; - ptArrow[4].x = bVertical ? 1 : 4; ptArrow[4].y = bVertical ? 4 : 0; - ptArrow[5].x = bVertical ? 4 : 4; ptArrow[5].y = bVertical ? 4 : 4; - ptArrow[6].x = bVertical ? 4 : 0; ptArrow[6].y = bVertical ? 0 : 4; + CRect area(0, 0, m_bVertical ? 12 : m_nSpanLength, m_bVertical ? m_nSpanLength : 12); + if (CWindowImpl::Create(hWndParent, area, nullptr, WS_POPUP | WS_DISABLED, WS_EX_TOOLWINDOW) == nullptr) + return FALSE; - CRgn rgnFirstArrow; - if ( !rgnFirstArrow.CreatePolygonRgn( ptArrow, 7, ALTERNATE ) ) - return FALSE; + POINT ptArrow[7]; - ptArrow[0].x = bVertical ? 4 : m_nSpanLength; ptArrow[0].y = bVertical ? m_nSpanLength : 4; - ptArrow[1].x = bVertical ? 4 : m_nSpanLength - 4; ptArrow[1].y = bVertical ? m_nSpanLength - 4 : 4; - ptArrow[2].x = bVertical ? 0 : m_nSpanLength - 4; ptArrow[2].y = bVertical ? m_nSpanLength - 4 : 0; - ptArrow[3].x = bVertical ? 6 : m_nSpanLength - 10; ptArrow[3].y = bVertical ? m_nSpanLength - 10 : 6; - ptArrow[4].x = bVertical ? 12 : m_nSpanLength - 4; ptArrow[4].y = bVertical ? m_nSpanLength - 4 : 12; - ptArrow[5].x = bVertical ? 8 : m_nSpanLength - 4; ptArrow[5].y = bVertical ? m_nSpanLength - 4 : 9; - ptArrow[6].x = bVertical ? 8 : m_nSpanLength; ptArrow[6].y = bVertical ? m_nSpanLength : 9; + ptArrow[0].x = bVertical ? 8 : 0; + ptArrow[0].y = bVertical ? 0 : 9; + ptArrow[1].x = bVertical ? 8 : 4; + ptArrow[1].y = bVertical ? 4 : 9; + ptArrow[2].x = bVertical ? 11 : 4; + ptArrow[2].y = bVertical ? 4 : 12; + ptArrow[3].x = bVertical ? 6 : 10; + ptArrow[3].y = bVertical ? 9 : 6; + ptArrow[4].x = bVertical ? 1 : 4; + ptArrow[4].y = bVertical ? 4 : 0; + ptArrow[5].x = bVertical ? 4 : 4; + ptArrow[5].y = bVertical ? 4 : 4; + ptArrow[6].x = bVertical ? 4 : 0; + ptArrow[6].y = bVertical ? 0 : 4; - CRgn rgnSecondArrow; - if ( !rgnSecondArrow.CreatePolygonRgn( ptArrow, 7, ALTERNATE ) ) - return FALSE; + CRgn rgnFirstArrow; + if (!rgnFirstArrow.CreatePolygonRgn(ptArrow, 7, ALTERNATE)) + return FALSE; - if ( !m_rgnArrowRegion.CreateRectRgn( 0, 0, bVertical ? 12 : nSpanLength, bVertical ? nSpanLength : 12 ) ) - return FALSE; - - m_rgnArrowRegion.CombineRgn( rgnFirstArrow, rgnSecondArrow, RGN_OR ); - - SetWindowRgn( m_rgnArrowRegion, FALSE ); + ptArrow[0].x = bVertical ? 4 : m_nSpanLength; + ptArrow[0].y = bVertical ? m_nSpanLength : 4; + ptArrow[1].x = bVertical ? 4 : m_nSpanLength - 4; + ptArrow[1].y = bVertical ? m_nSpanLength - 4 : 4; + ptArrow[2].x = bVertical ? 0 : m_nSpanLength - 4; + ptArrow[2].y = bVertical ? m_nSpanLength - 4 : 0; + ptArrow[3].x = bVertical ? 6 : m_nSpanLength - 10; + ptArrow[3].y = bVertical ? m_nSpanLength - 10 : 6; + ptArrow[4].x = bVertical ? 12 : m_nSpanLength - 4; + ptArrow[4].y = bVertical ? m_nSpanLength - 4 : 12; + ptArrow[5].x = bVertical ? 8 : m_nSpanLength - 4; + ptArrow[5].y = bVertical ? m_nSpanLength - 4 : 9; + ptArrow[6].x = bVertical ? 8 : m_nSpanLength; + ptArrow[6].y = bVertical ? m_nSpanLength : 9; - return TRUE; - } - - BOOL Show( CPoint point ) - { - return IsWindow() ? SetWindowPos( nullptr, m_bVertical ? point.x - 7 : point.x - ( m_nSpanLength / 2 ), m_bVertical ? point.y - ( m_nSpanLength / 2 ) : point.y - 5, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE ) : FALSE; - } - - BOOL Hide() - { - return IsWindow() ? ShowWindow( SW_HIDE ) : FALSE; - } - - BEGIN_MSG_MAP_EX(CDropArrows) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_ERASEBKGND(OnEraseBkgnd) - END_MSG_MAP() - - void OnDestroy() - { - m_bshArrowBrush.DeleteObject(); - m_rgnArrowRegion.DeleteObject(); - } - - BOOL OnEraseBkgnd( HDC dc ) - { - CDCHandle dcErase( dc ); - dcErase.FillRect( CRect( 0, 0, m_bVertical ? 12 : m_nSpanLength, m_bVertical ? m_nSpanLength : 12 ), m_bshArrowBrush ); - return TRUE; - } + CRgn rgnSecondArrow; + if (!rgnSecondArrow.CreatePolygonRgn(ptArrow, 7, ALTERNATE)) + return FALSE; + + if (!m_rgnArrowRegion.CreateRectRgn(0, 0, bVertical ? 12 : nSpanLength, bVertical ? nSpanLength : 12)) + return FALSE; + + m_rgnArrowRegion.CombineRgn(rgnFirstArrow, rgnSecondArrow, RGN_OR); + + SetWindowRgn(m_rgnArrowRegion, FALSE); + + return TRUE; + } + + BOOL Show(CPoint point) + { + return IsWindow() ? SetWindowPos(nullptr, m_bVertical ? point.x - 7 : point.x - (m_nSpanLength / 2), m_bVertical ? point.y - (m_nSpanLength / 2) : point.y - 5, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE) : FALSE; + } + + BOOL Hide() + { + return IsWindow() ? ShowWindow(SW_HIDE) : FALSE; + } + + BEGIN_MSG_MAP_EX(CDropArrows) + MSG_WM_DESTROY(OnDestroy) + MSG_WM_ERASEBKGND(OnEraseBkgnd) + END_MSG_MAP() + + void OnDestroy() + { + m_bshArrowBrush.DeleteObject(); + m_rgnArrowRegion.DeleteObject(); + } + + BOOL OnEraseBkgnd(HDC dc) + { + CDCHandle dcErase(dc); + dcErase.FillRect(CRect(0, 0, m_bVertical ? 12 : m_nSpanLength, m_bVertical ? m_nSpanLength : 12), m_bshArrowBrush); + return TRUE; + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCombo.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCombo.h index effbc8a6b..55515f7d0 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCombo.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCombo.h @@ -2,432 +2,441 @@ #include "ListTypes.h" #include -class CListCombo : public CWindowImpl< CListCombo, CComboBox > +class CListCombo : public CWindowImpl { public: - CListCombo() : m_wndEditCtrl( this, 1 ) - { - m_nItem = NULL_ITEM; - m_nSubItem = NULL_SUBITEM; - m_nFlags = ITEM_FLAGS_NONE; - m_nExitChar = 0; - m_bMouseOver = FALSE; - m_bActivate = FALSE; - } - - ~CListCombo() - { - } + CListCombo() : + m_wndEditCtrl(this, 1) + { + m_nItem = NULL_ITEM; + m_nSubItem = NULL_SUBITEM; + m_nFlags = ITEM_FLAGS_NONE; + m_nExitChar = 0; + m_bMouseOver = FALSE; + m_bActivate = FALSE; + } + + ~CListCombo() + { + } protected: - int m_nItem; - int m_nSubItem; - UINT m_nFlags; - TCHAR m_nExitChar; - BOOL m_bMouseOver; - BOOL m_bActivate; - BOOL m_bSwappedButtons; - CRect m_rcStatic; - CRect m_rcButton; - COLORREF m_rgbStaticBackground; - COLORREF m_rgbStaticText; - - CFont m_fntComboFont; - CContainedWindowT< CEdit > m_wndEditCtrl; - + int m_nItem; + int m_nSubItem; + UINT m_nFlags; + TCHAR m_nExitChar; + BOOL m_bMouseOver; + BOOL m_bActivate; + BOOL m_bSwappedButtons; + CRect m_rcStatic; + CRect m_rcButton; + COLORREF m_rgbStaticBackground; + COLORREF m_rgbStaticText; + + CFont m_fntComboFont; + CContainedWindowT m_wndEditCtrl; + public: - BOOL Create( HWND hWndParent, int nItem, int nSubItem, CRect& rcRect, UINT nFlags, LPCTSTR lpszItemText, CListArray < std::wstring >& aComboList ) - { - m_nItem = nItem; - m_nSubItem = nSubItem; - m_nFlags = nFlags; - m_nExitChar = 0; - m_bActivate = FALSE; - - m_bSwappedButtons = GetSystemMetrics( SM_SWAPBUTTON ); - m_rgbStaticBackground = GetSysColor( COLOR_HIGHLIGHT ); - m_rgbStaticText = GetSysColor( COLOR_HIGHLIGHTTEXT ); - - // Destroy old combo control - if ( IsWindow() ) - DestroyWindow(); - - DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | CBS_AUTOHSCROLL | CBS_SORT; - - if ( nFlags & ITEM_FLAGS_COMBO_EDIT ) - dwStyle |= CBS_DROPDOWN; - else - dwStyle |= CBS_DROPDOWNLIST; - - if ( nFlags & ITEM_FLAGS_EDIT_UPPER ) - dwStyle |= CBS_UPPERCASE; - - // Create combo control - CRect Area( ( ( dwStyle & CBS_DROPDOWNLIST ) == CBS_DROPDOWNLIST ) ? rcRect.left + 3 : rcRect.left + 1, rcRect.top, rcRect.right, rcRect.bottom + ( 6 * rcRect.Height() ) ); - if ( CWindowImpl< CListCombo, CComboBox >::Create( hWndParent, Area, nullptr, dwStyle ) == nullptr ) - return FALSE; - - // Get system message font - CLogFont logFont; - logFont.SetMessageBoxFont(); - if ( !m_fntComboFont.IsNull() ) - m_fntComboFont.DeleteObject(); - if ( m_fntComboFont.CreateFontIndirect( &logFont ) == nullptr ) - return FALSE; - SetFont( m_fntComboFont, FALSE ); - - // Subclass edit control to capture keyboard input - HWND hEditControl = GetWindow( GW_CHILD ); - if ( hEditControl != nullptr ) - m_wndEditCtrl.SubclassWindow( hEditControl ); - - for ( int nComboItem = 0; nComboItem < aComboList.GetSize(); nComboItem++ ) - AddString( aComboList[ nComboItem ].c_str() ); - - if ( ( dwStyle & CBS_DROPDOWNLIST ) == CBS_DROPDOWNLIST ) - { - int nIndex = FindStringExact( -1, lpszItemText ); - if ( nIndex != CB_ERR ) - SetCurSel( nIndex ); - } - else - { - SetWindowText( lpszItemText ); - SetEditSel( 0, -1 ); - } - - // Set static edit height - SetItemHeight( -1, rcRect.Height() - 6 ); - - COMBOBOXINFO infoComboBox = { sizeof( COMBOBOXINFO ) }; - if ( !::GetComboBoxInfo( m_hWnd, &infoComboBox ) ) - return FALSE; - - // Store combo box details for painting - m_rcStatic = infoComboBox.rcItem; - m_rcButton = infoComboBox.rcButton; - m_rcButton.DeflateRect( 0, 1 ); - m_rcButton.OffsetRect( -2, 0 ); - - // Show combo control - ShowWindow( SW_SHOW ); + BOOL Create(HWND hWndParent, int nItem, int nSubItem, CRect & rcRect, UINT nFlags, LPCTSTR lpszItemText, CListArray & aComboList) + { + m_nItem = nItem; + m_nSubItem = nSubItem; + m_nFlags = nFlags; + m_nExitChar = 0; + m_bActivate = FALSE; - SetFocus(); - - // Force redraw now - RedrawWindow(); - - return TRUE; - } - - BOOL IsValid( TCHAR nChar ) - { - // Validate number and float input - if ( !( m_nFlags & ( ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT ) ) || nChar == VK_BACK ) - return TRUE; - - std::wstring strValue; - int nValueLength = GetWindowTextLength() + 1; - strValue.reserve(nValueLength); - GetWindowText( (wchar_t *)strValue.c_str(), nValueLength ); - - // Get selected positions - DWORD dwSelection = GetEditSel(); - int nStartChar = LOWORD( dwSelection ); - int nEndChar = HIWORD( dwSelection ); - - // Are we changing the sign? - if ( ( m_nFlags & ITEM_FLAGS_EDIT_NEGATIVE ) && nChar == _T( '-' ) ) - { - BOOL bNegative = FALSE; - if ( m_nFlags & ITEM_FLAGS_EDIT_FLOAT ) - { - double dblValue = _wtof( strValue.c_str() ); - bNegative = ( dblValue < 0 ); - strValue = stdstr_f("%lf", -dblValue).ToUTF16(); - } - else - { - long lValue = _wtol( strValue.c_str() ); - bNegative = ( lValue < 0 ); - strValue = stdstr_f("%ld", -lValue).ToUTF16(); - } - - SetWindowText( strValue.c_str() ); - - // Restore select position - SetEditSel( bNegative ? nStartChar - 1 : nStartChar + 1, bNegative ? nEndChar - 1 : nEndChar + 1 ); - return FALSE; - } - - // Construct new value string using entered character - std::wstring strNewValue = strValue.substr(0, nStartChar ) + nChar + strValue.substr(nEndChar, strValue.length() - nEndChar ); - - int nGreaterThan = 0; - int nLessThan = 0; - int nEquals = 0; - int nDecimalPoint = 0; - - int nNegativeIndex = -1; - int nGreaterIndex = -1; - int nLessIndex = -1; - int nEqualIndex = -1; - int nDecimalIndex = -1; - int nDigitIndex = -1; - - for ( int nCharIndex = 0; nCharIndex < (int)strNewValue.length(); nCharIndex++ ) - { - TCHAR nCharValue = (strNewValue.c_str())[ nCharIndex ]; - switch ( nCharValue ) - { - case _T( '-' ): nNegativeIndex = nCharIndex; - break; - case _T( '>' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nGreaterIndex = nCharIndex; - nGreaterThan++; - break; - case _T( '<' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nLessIndex = nCharIndex; - nLessThan++; - break; - case _T( '=' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nEqualIndex = nCharIndex; - nEquals++; - break; - case _T( '.' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_FLOAT ) ) - return FALSE; - nDecimalIndex = nCharIndex; - nDecimalPoint++; - break; - default: if ( !_istdigit( nCharValue ) ) - return FALSE; - if ( nDigitIndex < 0 ) - nDigitIndex = nCharIndex; - break; - } + m_bSwappedButtons = GetSystemMetrics(SM_SWAPBUTTON); + m_rgbStaticBackground = GetSysColor(COLOR_HIGHLIGHT); + m_rgbStaticText = GetSysColor(COLOR_HIGHLIGHTTEXT); - // Invalid if text contains more than one '>', '<', '=' or '.' - if ( nGreaterThan > 1 || nLessThan > 1 || nEquals > 1 || nDecimalPoint > 1 ) - return FALSE; - } + // Destroy old combo control + if (IsWindow()) + DestroyWindow(); - // Invalid if text contains '=>' or '=<' - if ( nGreaterIndex != -1 && nEqualIndex != -1 && nGreaterIndex > nEqualIndex ) - return FALSE; - if ( nLessIndex != -1 && nEqualIndex != -1 && nLessIndex > nEqualIndex ) - return FALSE; + DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | CBS_AUTOHSCROLL | CBS_SORT; - // Invalid if digits exist before operator - if ( nDigitIndex != -1 && nGreaterIndex != -1 && nGreaterIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nLessIndex != -1 && nLessIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nEqualIndex != -1 && nEqualIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nNegativeIndex != -1 && nNegativeIndex > nDigitIndex ) - return FALSE; - - return TRUE; - } - - BEGIN_MSG_MAP_EX(CListCombo) - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST,WM_MOUSELAST,OnMouseRange) -#if(_WIN32_WINNT >= 0x0400) - MSG_WM_MOUSELEAVE(OnMouseLeave) + if (nFlags & ITEM_FLAGS_COMBO_EDIT) + dwStyle |= CBS_DROPDOWN; + else + dwStyle |= CBS_DROPDOWNLIST; + + if (nFlags & ITEM_FLAGS_EDIT_UPPER) + dwStyle |= CBS_UPPERCASE; + + // Create combo control + CRect Area(((dwStyle & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) ? rcRect.left + 3 : rcRect.left + 1, rcRect.top, rcRect.right, rcRect.bottom + (6 * rcRect.Height())); + if (CWindowImpl::Create(hWndParent, Area, nullptr, dwStyle) == nullptr) + return FALSE; + + // Get system message font + CLogFont logFont; + logFont.SetMessageBoxFont(); + if (!m_fntComboFont.IsNull()) + m_fntComboFont.DeleteObject(); + if (m_fntComboFont.CreateFontIndirect(&logFont) == nullptr) + return FALSE; + SetFont(m_fntComboFont, FALSE); + + // Subclass edit control to capture keyboard input + HWND hEditControl = GetWindow(GW_CHILD); + if (hEditControl != nullptr) + m_wndEditCtrl.SubclassWindow(hEditControl); + + for (int nComboItem = 0; nComboItem < aComboList.GetSize(); nComboItem++) + AddString(aComboList[nComboItem].c_str()); + + if ((dwStyle & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) + { + int nIndex = FindStringExact(-1, lpszItemText); + if (nIndex != CB_ERR) + SetCurSel(nIndex); + } + else + { + SetWindowText(lpszItemText); + SetEditSel(0, -1); + } + + // Set static edit height + SetItemHeight(-1, rcRect.Height() - 6); + + COMBOBOXINFO infoComboBox = {sizeof(COMBOBOXINFO)}; + if (!::GetComboBoxInfo(m_hWnd, &infoComboBox)) + return FALSE; + + // Store combo box details for painting + m_rcStatic = infoComboBox.rcItem; + m_rcButton = infoComboBox.rcButton; + m_rcButton.DeflateRect(0, 1); + m_rcButton.OffsetRect(-2, 0); + + // Show combo control + ShowWindow(SW_SHOW); + + SetFocus(); + + // Force redraw now + RedrawWindow(); + + return TRUE; + } + + BOOL IsValid(TCHAR nChar) + { + // Validate number and float input + if (!(m_nFlags & (ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT)) || nChar == VK_BACK) + return TRUE; + + std::wstring strValue; + int nValueLength = GetWindowTextLength() + 1; + strValue.reserve(nValueLength); + GetWindowText((wchar_t *)strValue.c_str(), nValueLength); + + // Get selected positions + DWORD dwSelection = GetEditSel(); + int nStartChar = LOWORD(dwSelection); + int nEndChar = HIWORD(dwSelection); + + // Are we changing the sign? + if ((m_nFlags & ITEM_FLAGS_EDIT_NEGATIVE) && nChar == _T('-')) + { + BOOL bNegative = FALSE; + if (m_nFlags & ITEM_FLAGS_EDIT_FLOAT) + { + double dblValue = _wtof(strValue.c_str()); + bNegative = (dblValue < 0); + strValue = stdstr_f("%lf", -dblValue).ToUTF16(); + } + else + { + long lValue = _wtol(strValue.c_str()); + bNegative = (lValue < 0); + strValue = stdstr_f("%ld", -lValue).ToUTF16(); + } + + SetWindowText(strValue.c_str()); + + // Restore select position + SetEditSel(bNegative ? nStartChar - 1 : nStartChar + 1, bNegative ? nEndChar - 1 : nEndChar + 1); + return FALSE; + } + + // Construct new value string using entered character + std::wstring strNewValue = strValue.substr(0, nStartChar) + nChar + strValue.substr(nEndChar, strValue.length() - nEndChar); + + int nGreaterThan = 0; + int nLessThan = 0; + int nEquals = 0; + int nDecimalPoint = 0; + + int nNegativeIndex = -1; + int nGreaterIndex = -1; + int nLessIndex = -1; + int nEqualIndex = -1; + int nDecimalIndex = -1; + int nDigitIndex = -1; + + for (int nCharIndex = 0; nCharIndex < (int)strNewValue.length(); nCharIndex++) + { + TCHAR nCharValue = (strNewValue.c_str())[nCharIndex]; + switch (nCharValue) + { + case _T('-'): + nNegativeIndex = nCharIndex; + break; + case _T('>'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nGreaterIndex = nCharIndex; + nGreaterThan++; + break; + case _T('<'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nLessIndex = nCharIndex; + nLessThan++; + break; + case _T('='): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nEqualIndex = nCharIndex; + nEquals++; + break; + case _T('.'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_FLOAT)) + return FALSE; + nDecimalIndex = nCharIndex; + nDecimalPoint++; + break; + default: + if (!_istdigit(nCharValue)) + return FALSE; + if (nDigitIndex < 0) + nDigitIndex = nCharIndex; + break; + } + + // Invalid if text contains more than one '>', '<', '=' or '.' + if (nGreaterThan > 1 || nLessThan > 1 || nEquals > 1 || nDecimalPoint > 1) + return FALSE; + } + + // Invalid if text contains '=>' or '=<' + if (nGreaterIndex != -1 && nEqualIndex != -1 && nGreaterIndex > nEqualIndex) + return FALSE; + if (nLessIndex != -1 && nEqualIndex != -1 && nLessIndex > nEqualIndex) + return FALSE; + + // Invalid if digits exist before operator + if (nDigitIndex != -1 && nGreaterIndex != -1 && nGreaterIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nLessIndex != -1 && nLessIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nEqualIndex != -1 && nEqualIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nNegativeIndex != -1 && nNegativeIndex > nDigitIndex) + return FALSE; + + return TRUE; + } + + BEGIN_MSG_MAP_EX(CListCombo) + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) +#if (_WIN32_WINNT >= 0x0400) + MSG_WM_MOUSELEAVE(OnMouseLeave) #endif - MSG_WM_ERASEBKGND(OnEraseBkgnd) - MSG_WM_PAINT(OnPaint) - REFLECTED_COMMAND_CODE_HANDLER_EX(CBN_KILLFOCUS, OnKillFocus) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_CHAR(OnChar) - DEFAULT_REFLECTION_HANDLER() - ALT_MSG_MAP(1) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_CHAR(OnChar) - END_MSG_MAP() - - LRESULT OnMouseRange( UINT nMessage, WPARAM /*wParam*/, LPARAM /*lParam*/ ) - { - SetMsgHandled( FALSE ); - - if ( nMessage == WM_MOUSEMOVE && !m_bMouseOver ) - { - m_bMouseOver = TRUE; - - TRACKMOUSEEVENT trkMouse; - trkMouse.cbSize = sizeof( TRACKMOUSEEVENT ); - trkMouse.dwFlags = TME_LEAVE; - trkMouse.hwndTrack = m_hWnd; - - // Notify when the mouse leaves button - _TrackMouseEvent( &trkMouse ); - } - - // Do not show button as pressed when first created - m_bActivate = TRUE; - - InvalidateRect( m_rcButton ); - - return 0; - } - - void OnMouseLeave() - { - m_bMouseOver = FALSE; - InvalidateRect( m_rcButton ); - } - - BOOL OnEraseBkgnd( CDCHandle dcErase ) - { - return TRUE; - } - - void OnPaint( HDC ) - { - CPaintDC dcPaint( m_hWnd ); - - CRect rcClient; - GetClientRect( rcClient ); - - CMemoryDC dcMemory( dcPaint.m_hDC, rcClient ); - - CRect rcClip; - if ( dcPaint.GetClipBox( rcClip ) == ERROR ) - return; - - int nContextState = dcMemory.SaveDC(); - - // Do not repaint background if drawing button only - if ( !rcClip.EqualRect( m_rcButton ) ) - { - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - { - // Draw background from parent - CPoint ptOrigin( 0 ); - MapWindowPoints( wndParent, &ptOrigin, 1 ); - dcMemory.OffsetWindowOrg( ptOrigin.x, ptOrigin.y, &ptOrigin ); - wndParent.SendMessage( WM_PAINT, (WPARAM)dcMemory.m_hDC ); - dcMemory.SetWindowOrg( ptOrigin ); - } - } - - DWORD dwPoint = GetMessagePos(); - CPoint ptMouse( GET_X_LPARAM( dwPoint ), GET_Y_LPARAM( dwPoint ) ); - ScreenToClient( &ptMouse ); - - DWORD dwStyle = GetStyle(); - BOOL bHotButton = m_bActivate && ( ( ( dwStyle & CBS_DROPDOWNLIST ) == CBS_DROPDOWNLIST ) ? rcClient.PtInRect( ptMouse ) : m_rcButton.PtInRect( ptMouse ) ); - BOOL bPressed = bHotButton && ( GetAsyncKeyState( m_bSwappedButtons ? VK_RBUTTON : VK_LBUTTON ) < 0 ); - - if ( ( dwStyle & CBS_DROPDOWNLIST ) == CBS_DROPDOWNLIST && !rcClip.EqualRect( m_rcButton ) ) - { - dcMemory.SetBkColor( m_rgbStaticBackground ); - dcMemory.ExtTextOut( m_rcStatic.left, m_rcStatic.top, ETO_OPAQUE, m_rcStatic, _T( "" ), 0, nullptr ); - - // Draw static text - int nIndex = GetCurSel(); - if ( nIndex != CB_ERR ) - { - std::wstring strText; - int cchLen = GetLBTextLen(nIndex); - if(cchLen != CB_ERR) - { - strText.reserve(cchLen + 1); - GetLBText( nIndex, (LPTSTR)strText.c_str() ); - } - - if ( !strText.empty() ) - { - CRect rcText( m_rcStatic ); - rcText.OffsetRect( 1, 1 ); - dcMemory.SelectFont( m_fntComboFont ); - dcMemory.SetTextColor( m_rgbStaticText ); - dcMemory.SetBkMode( TRANSPARENT ); - dcMemory.DrawText( strText.c_str(), (int)strText.length(), rcText, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER ); - } - } - } - - // Draw drop down button - dcMemory.DrawFrameControl( m_rcButton, DFC_SCROLL, DFCS_SCROLLDOWN | ( bPressed ? DFCS_FLAT | DFCS_PUSHED : 0 ) ); + MSG_WM_ERASEBKGND(OnEraseBkgnd) + MSG_WM_PAINT(OnPaint) + REFLECTED_COMMAND_CODE_HANDLER_EX(CBN_KILLFOCUS, OnKillFocus) + MSG_WM_GETDLGCODE(OnGetDlgCode) + MSG_WM_CHAR(OnChar) + DEFAULT_REFLECTION_HANDLER() + ALT_MSG_MAP(1) + MSG_WM_GETDLGCODE(OnGetDlgCode) + MSG_WM_CHAR(OnChar) + END_MSG_MAP() - dcMemory.RestoreDC( nContextState ); - } - - void OnKillFocus( UINT /*uCode*/, int /*nCtrlID*/, HWND /*hwndCtrl*/ ) - { - SetMsgHandled( FALSE ); - - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - { + LRESULT OnMouseRange(UINT nMessage, WPARAM /*wParam*/, LPARAM /*lParam*/) + { + SetMsgHandled(FALSE); + + if (nMessage == WM_MOUSEMOVE && !m_bMouseOver) + { + m_bMouseOver = TRUE; + + TRACKMOUSEEVENT trkMouse; + trkMouse.cbSize = sizeof(TRACKMOUSEEVENT); + trkMouse.dwFlags = TME_LEAVE; + trkMouse.hwndTrack = m_hWnd; + + // Notify when the mouse leaves button + _TrackMouseEvent(&trkMouse); + } + + // Do not show button as pressed when first created + m_bActivate = TRUE; + + InvalidateRect(m_rcButton); + + return 0; + } + + void OnMouseLeave() + { + m_bMouseOver = FALSE; + InvalidateRect(m_rcButton); + } + + BOOL OnEraseBkgnd(CDCHandle dcErase) + { + return TRUE; + } + + void OnPaint(HDC) + { + CPaintDC dcPaint(m_hWnd); + + CRect rcClient; + GetClientRect(rcClient); + + CMemoryDC dcMemory(dcPaint.m_hDC, rcClient); + + CRect rcClip; + if (dcPaint.GetClipBox(rcClip) == ERROR) + return; + + int nContextState = dcMemory.SaveDC(); + + // Do not repaint background if drawing button only + if (!rcClip.EqualRect(m_rcButton)) + { + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + { + // Draw background from parent + CPoint ptOrigin(0); + MapWindowPoints(wndParent, &ptOrigin, 1); + dcMemory.OffsetWindowOrg(ptOrigin.x, ptOrigin.y, &ptOrigin); + wndParent.SendMessage(WM_PAINT, (WPARAM)dcMemory.m_hDC); + dcMemory.SetWindowOrg(ptOrigin); + } + } + + DWORD dwPoint = GetMessagePos(); + CPoint ptMouse(GET_X_LPARAM(dwPoint), GET_Y_LPARAM(dwPoint)); + ScreenToClient(&ptMouse); + + DWORD dwStyle = GetStyle(); + BOOL bHotButton = m_bActivate && (((dwStyle & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) ? rcClient.PtInRect(ptMouse) : m_rcButton.PtInRect(ptMouse)); + BOOL bPressed = bHotButton && (GetAsyncKeyState(m_bSwappedButtons ? VK_RBUTTON : VK_LBUTTON) < 0); + + if ((dwStyle & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST && !rcClip.EqualRect(m_rcButton)) + { + dcMemory.SetBkColor(m_rgbStaticBackground); + dcMemory.ExtTextOut(m_rcStatic.left, m_rcStatic.top, ETO_OPAQUE, m_rcStatic, _T( "" ), 0, nullptr); + + // Draw static text + int nIndex = GetCurSel(); + if (nIndex != CB_ERR) + { + std::wstring strText; + int cchLen = GetLBTextLen(nIndex); + if (cchLen != CB_ERR) + { + strText.reserve(cchLen + 1); + GetLBText(nIndex, (LPTSTR)strText.c_str()); + } + + if (!strText.empty()) + { + CRect rcText(m_rcStatic); + rcText.OffsetRect(1, 1); + dcMemory.SelectFont(m_fntComboFont); + dcMemory.SetTextColor(m_rgbStaticText); + dcMemory.SetBkMode(TRANSPARENT); + dcMemory.DrawText(strText.c_str(), (int)strText.length(), rcText, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); + } + } + } + + // Draw drop down button + dcMemory.DrawFrameControl(m_rcButton, DFC_SCROLL, DFCS_SCROLLDOWN | (bPressed ? DFCS_FLAT | DFCS_PUSHED : 0)); + + dcMemory.RestoreDC(nContextState); + } + + void OnKillFocus(UINT /*uCode*/, int /*nCtrlID*/, HWND /*hwndCtrl*/) + { + SetMsgHandled(FALSE); + + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + { std::wstring strValue; - - if ( ( GetStyle() & CBS_DROPDOWNLIST ) == CBS_DROPDOWNLIST ) - { - int nIndex = GetCurSel(); - if ( nIndex != CB_ERR ) - { - int cchLen = GetLBTextLen(nIndex); - if(cchLen != CB_ERR) - { - strValue.reserve(cchLen); - GetLBText( nIndex, (LPTSTR)strValue.c_str() ); - } - else - { - strValue = L""; - } - } - } - else - { - int nValueLength = GetWindowTextLength() + 1; - strValue.reserve(nValueLength); - GetWindowText( (LPTSTR)strValue.c_str(), nValueLength ); - } - - CListNotify listNotify; - listNotify.m_hdrNotify.hwndFrom = m_hWnd; - listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); - listNotify.m_hdrNotify.code = LCN_ENDEDIT; - listNotify.m_nItem = m_nItem; - listNotify.m_nSubItem = m_nSubItem; - listNotify.m_nExitChar = m_nExitChar; - listNotify.m_lpszItemText = strValue.c_str(); - listNotify.m_lpItemDate = nullptr; - // Forward notification to parent - FORWARD_WM_NOTIFY( wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage ); - } - - ShowWindow( SW_HIDE ); - } - - UINT OnGetDlgCode( LPMSG /*lpMessage*/ ) - { - return DLGC_WANTALLKEYS; - } - - void OnChar( TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/ ) - { - switch ( nChar ) - { - case VK_TAB: - case VK_RETURN: - case VK_ESCAPE: { - m_nExitChar = nChar; - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - wndParent.SetFocus(); - } - break; - default: SetMsgHandled( !IsValid( nChar ) ); - break; - } - } + if ((GetStyle() & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) + { + int nIndex = GetCurSel(); + if (nIndex != CB_ERR) + { + int cchLen = GetLBTextLen(nIndex); + if (cchLen != CB_ERR) + { + strValue.reserve(cchLen); + GetLBText(nIndex, (LPTSTR)strValue.c_str()); + } + else + { + strValue = L""; + } + } + } + else + { + int nValueLength = GetWindowTextLength() + 1; + strValue.reserve(nValueLength); + GetWindowText((LPTSTR)strValue.c_str(), nValueLength); + } + + CListNotify listNotify; + listNotify.m_hdrNotify.hwndFrom = m_hWnd; + listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); + listNotify.m_hdrNotify.code = LCN_ENDEDIT; + listNotify.m_nItem = m_nItem; + listNotify.m_nSubItem = m_nSubItem; + listNotify.m_nExitChar = m_nExitChar; + listNotify.m_lpszItemText = strValue.c_str(); + listNotify.m_lpItemDate = nullptr; + + // Forward notification to parent + FORWARD_WM_NOTIFY(wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage); + } + + ShowWindow(SW_HIDE); + } + + UINT OnGetDlgCode(LPMSG /*lpMessage*/) + { + return DLGC_WANTALLKEYS; + } + + void OnChar(TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) + { + switch (nChar) + { + case VK_TAB: + case VK_RETURN: + case VK_ESCAPE: + { + m_nExitChar = nChar; + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + wndParent.SetFocus(); + } + break; + default: + SetMsgHandled(!IsValid(nChar)); + break; + } + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCtrl.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCtrl.h index 93739839a..1a4dae391 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCtrl.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListCtrl.h @@ -4,3863 +4,3907 @@ #pragma once -#include #include +#include #pragma warning(push) #pragma warning(disable : 4838) // warning C4838: conversion from 'int' to 'UINT' requires a narrowing conversion #include #include -#include #include +#include #pragma warning(pop) #include "DragDrop.h" #include "DropArrows.h" -#include "TitleTip.h" -#include "ListEdit.h" #include "ListCombo.h" #include "ListDate.h" +#include "ListEdit.h" +#include "TitleTip.h" struct CListColumn { - stdstr m_strText; - int m_nWidth; - BOOL m_bFixed; - UINT m_nFormat; - UINT m_nFlags; - int m_nImage; - int m_nIndex; - CListArray < stdstr > m_aComboList; + stdstr m_strText; + int m_nWidth; + BOOL m_bFixed; + UINT m_nFormat; + UINT m_nFlags; + int m_nImage; + int m_nIndex; + CListArray m_aComboList; }; -template < class T > -class CListImpl : public CWindowImpl< CListImpl< T > >, - public CDoubleBufferImpl< CListImpl< T > > +template +class CListImpl : public CWindowImpl>, public CDoubleBufferImpl> { public: - CListImpl() - { - m_bSortEnabled = TRUE; // Added by Rowan 05/12/2006 - m_bRightClickSelect = FALSE; // Shygoo 11/02/2016 - m_bShowHeader = TRUE; - m_bSortAscending = TRUE; - m_bButtonDown = FALSE; - m_bMouseOver = FALSE; - m_bColumnSizing = FALSE; - m_bBeginSelect = FALSE; - m_bSingleSelect = FALSE; - m_bFocusSubItem = FALSE; - m_bGroupSelect = FALSE; - m_bEnableHorizScroll = FALSE; - m_bEnableVertScroll = FALSE; - m_bShowHorizScroll = TRUE; - m_bShowVertScroll = TRUE; - m_bShowSort = TRUE; - m_bResizeTimer = FALSE; - m_bDragDrop = FALSE; - m_bSmoothScroll = TRUE; - m_bEditItem = FALSE; - m_bScrolling = FALSE; - m_bScrollDown = FALSE; - m_bTileBackground = FALSE; - m_nMouseWheelScroll = 3; - m_nTotalWidth = 0; - m_nHeaderHeight = 0; - m_nItemHeight = 0; - m_nFirstSelected = NULL_ITEM; - m_nFocusItem = NULL_ITEM; - m_nFocusSubItem = NULL_SUBITEM; - m_nHotItem = NULL_ITEM; - m_nHotSubItem = NULL_SUBITEM; - m_nTitleTipItem = NULL_ITEM; - m_nTitleTipSubItem = NULL_SUBITEM; - m_nSortColumn = NULL_COLUMN; - m_nHighlightColumn = NULL_COLUMN; - m_nDragColumn = NULL_COLUMN; - m_nHotColumn = NULL_COLUMN; - m_nHotDivider = NULL_COLUMN; - m_nColumnSizing = NULL_COLUMN; - m_nScrollOffset = 0; - m_nScrollDelta = 0; - m_nScrollUnit = 0; - m_nStartScrollPos = 0; - m_nStartSize = 0; - m_nStartPos = 0; - m_ptDownPoint = 0; - m_ptSelectPoint = 0; - m_rcGroupSelect = 0; - m_dwSearchTick = 0; - m_dwScrollTick = 0; - m_strSearchString = _T( "" ); - } - - ~CListImpl() - { - if (m_wndItemEdit.IsWindow()) - { - // Patch memory window crash - m_wndItemEdit.UnsubclassWindow(); - } - } + CListImpl() + { + m_bSortEnabled = TRUE; // Added by Rowan 05/12/2006 + m_bRightClickSelect = FALSE; // Shygoo 11/02/2016 + m_bShowHeader = TRUE; + m_bSortAscending = TRUE; + m_bButtonDown = FALSE; + m_bMouseOver = FALSE; + m_bColumnSizing = FALSE; + m_bBeginSelect = FALSE; + m_bSingleSelect = FALSE; + m_bFocusSubItem = FALSE; + m_bGroupSelect = FALSE; + m_bEnableHorizScroll = FALSE; + m_bEnableVertScroll = FALSE; + m_bShowHorizScroll = TRUE; + m_bShowVertScroll = TRUE; + m_bShowSort = TRUE; + m_bResizeTimer = FALSE; + m_bDragDrop = FALSE; + m_bSmoothScroll = TRUE; + m_bEditItem = FALSE; + m_bScrolling = FALSE; + m_bScrollDown = FALSE; + m_bTileBackground = FALSE; + m_nMouseWheelScroll = 3; + m_nTotalWidth = 0; + m_nHeaderHeight = 0; + m_nItemHeight = 0; + m_nFirstSelected = NULL_ITEM; + m_nFocusItem = NULL_ITEM; + m_nFocusSubItem = NULL_SUBITEM; + m_nHotItem = NULL_ITEM; + m_nHotSubItem = NULL_SUBITEM; + m_nTitleTipItem = NULL_ITEM; + m_nTitleTipSubItem = NULL_SUBITEM; + m_nSortColumn = NULL_COLUMN; + m_nHighlightColumn = NULL_COLUMN; + m_nDragColumn = NULL_COLUMN; + m_nHotColumn = NULL_COLUMN; + m_nHotDivider = NULL_COLUMN; + m_nColumnSizing = NULL_COLUMN; + m_nScrollOffset = 0; + m_nScrollDelta = 0; + m_nScrollUnit = 0; + m_nStartScrollPos = 0; + m_nStartSize = 0; + m_nStartPos = 0; + m_ptDownPoint = 0; + m_ptSelectPoint = 0; + m_rcGroupSelect = 0; + m_dwSearchTick = 0; + m_dwScrollTick = 0; + m_strSearchString = _T( "" ); + } + + ~CListImpl() + { + if (m_wndItemEdit.IsWindow()) + { + // Patch memory window crash + m_wndItemEdit.UnsubclassWindow(); + } + } protected: - BOOL m_bSortEnabled; // Added by Rowan 05/12/2006 to disable sorting - BOOL m_bRightClickSelect; // Shygoo 11/02/2016 - BOOL m_bShowHeader; - BOOL m_bShowSort; - BOOL m_bSortAscending; - BOOL m_bButtonDown; - BOOL m_bMouseOver; - BOOL m_bColumnSizing; - BOOL m_bBeginSelect; - BOOL m_bSingleSelect; - BOOL m_bFocusSubItem; - BOOL m_bGroupSelect; - BOOL m_bShowHorizScroll; - BOOL m_bShowVertScroll; - BOOL m_bEnableHorizScroll; - BOOL m_bEnableVertScroll; - BOOL m_bResizeTimer; - BOOL m_bDragDrop; - BOOL m_bSmoothScroll; - BOOL m_bEditItem; - BOOL m_bScrolling; - BOOL m_bScrollDown; - BOOL m_bTileBackground; - CPoint m_ptDownPoint; - CPoint m_ptSelectPoint; - CRect m_rcGroupSelect; - int m_nItemHeight; - int m_nHeaderHeight; - int m_nFirstSelected; - int m_nFocusItem; - int m_nFocusSubItem; - int m_nHotItem; - int m_nHotSubItem; - int m_nTitleTipItem; - int m_nTitleTipSubItem; - int m_nMouseWheelScroll; - int m_nTotalWidth; - int m_nSortColumn; - int m_nDragColumn; - int m_nHighlightColumn; - int m_nHotColumn; - int m_nHotDivider; - int m_nColumnSizing; - int m_nScrollOffset; - int m_nScrollDelta; - int m_nScrollUnit; - int m_nStartScrollPos; - int m_nStartSize; - int m_nStartPos; - DWORD m_dwSearchTick; - DWORD m_dwScrollTick; - stdstr m_strSearchString; - CBitmap m_bmpScrollList; - CBitmap m_bmpBackground; - - CLIPFORMAT m_nHeaderClipboardFormat; - - COLORREF m_rgbBackground; - COLORREF m_rgbHeaderBackground; - COLORREF m_rgbHeaderBorder; - COLORREF m_rgbHeaderShadow; - COLORREF m_rgbHeaderText; - COLORREF m_rgbHeaderHighlight; - COLORREF m_rgbSelectedItem; - COLORREF m_rgbSelectedText; - COLORREF m_rgbItemText; - COLORREF m_rgbSelectOuter; - COLORREF m_rgbSelectInner; - COLORREF m_rgbSelectTop; - COLORREF m_rgbSelectBottom; - COLORREF m_rgbNoFocusTop; - COLORREF m_rgbNoFocusBottom; - COLORREF m_rgbNoFocusOuter; - COLORREF m_rgbNoFocusInner; - COLORREF m_rgbFocusTop; - COLORREF m_rgbFocusBottom; - COLORREF m_rgbProgressTop; - COLORREF m_rgbProgressBottom; - COLORREF m_rgbItemFocus; - COLORREF m_rgbHyperLink; - - CCursor m_curDivider; - CCursor m_curHyperLink; - CFont m_fntListFont; - CFont m_fntUnderlineFont; - CImageList m_ilListItems; - CImageList m_ilItemImages; - CDragDrop < CListImpl > m_oleDragDrop; - CToolTipCtrl m_ttToolTip; - CDropArrows m_wndDropArrows; - CTitleTip m_wndTitleTip; - CListEdit m_wndItemEdit; - CListCombo m_wndItemCombo; - CListDate m_wndItemDate; - - CListArray < CListColumn > m_aColumns; - set < int > m_setSelectedItems; + BOOL m_bSortEnabled; // Added by Rowan 05/12/2006 to disable sorting + BOOL m_bRightClickSelect; // Shygoo 11/02/2016 + BOOL m_bShowHeader; + BOOL m_bShowSort; + BOOL m_bSortAscending; + BOOL m_bButtonDown; + BOOL m_bMouseOver; + BOOL m_bColumnSizing; + BOOL m_bBeginSelect; + BOOL m_bSingleSelect; + BOOL m_bFocusSubItem; + BOOL m_bGroupSelect; + BOOL m_bShowHorizScroll; + BOOL m_bShowVertScroll; + BOOL m_bEnableHorizScroll; + BOOL m_bEnableVertScroll; + BOOL m_bResizeTimer; + BOOL m_bDragDrop; + BOOL m_bSmoothScroll; + BOOL m_bEditItem; + BOOL m_bScrolling; + BOOL m_bScrollDown; + BOOL m_bTileBackground; + CPoint m_ptDownPoint; + CPoint m_ptSelectPoint; + CRect m_rcGroupSelect; + int m_nItemHeight; + int m_nHeaderHeight; + int m_nFirstSelected; + int m_nFocusItem; + int m_nFocusSubItem; + int m_nHotItem; + int m_nHotSubItem; + int m_nTitleTipItem; + int m_nTitleTipSubItem; + int m_nMouseWheelScroll; + int m_nTotalWidth; + int m_nSortColumn; + int m_nDragColumn; + int m_nHighlightColumn; + int m_nHotColumn; + int m_nHotDivider; + int m_nColumnSizing; + int m_nScrollOffset; + int m_nScrollDelta; + int m_nScrollUnit; + int m_nStartScrollPos; + int m_nStartSize; + int m_nStartPos; + DWORD m_dwSearchTick; + DWORD m_dwScrollTick; + stdstr m_strSearchString; + CBitmap m_bmpScrollList; + CBitmap m_bmpBackground; + + CLIPFORMAT m_nHeaderClipboardFormat; + + COLORREF m_rgbBackground; + COLORREF m_rgbHeaderBackground; + COLORREF m_rgbHeaderBorder; + COLORREF m_rgbHeaderShadow; + COLORREF m_rgbHeaderText; + COLORREF m_rgbHeaderHighlight; + COLORREF m_rgbSelectedItem; + COLORREF m_rgbSelectedText; + COLORREF m_rgbItemText; + COLORREF m_rgbSelectOuter; + COLORREF m_rgbSelectInner; + COLORREF m_rgbSelectTop; + COLORREF m_rgbSelectBottom; + COLORREF m_rgbNoFocusTop; + COLORREF m_rgbNoFocusBottom; + COLORREF m_rgbNoFocusOuter; + COLORREF m_rgbNoFocusInner; + COLORREF m_rgbFocusTop; + COLORREF m_rgbFocusBottom; + COLORREF m_rgbProgressTop; + COLORREF m_rgbProgressBottom; + COLORREF m_rgbItemFocus; + COLORREF m_rgbHyperLink; + + CCursor m_curDivider; + CCursor m_curHyperLink; + CFont m_fntListFont; + CFont m_fntUnderlineFont; + CImageList m_ilListItems; + CImageList m_ilItemImages; + CDragDrop m_oleDragDrop; + CToolTipCtrl m_ttToolTip; + CDropArrows m_wndDropArrows; + CTitleTip m_wndTitleTip; + CListEdit m_wndItemEdit; + CListCombo m_wndItemCombo; + CListDate m_wndItemDate; + + CListArray m_aColumns; + set m_setSelectedItems; + public: - BOOL SubclassWindow( HWND hWnd ) - { - T* pT; - pT = static_cast(this); - return CWindowImpl< CListImpl >::SubclassWindow( hWnd ) ? pT->Initialise() : FALSE; - } - - void RegisterClass() - { - T* pT = static_cast(this); - pT = pT; - pT->GetWndClassInfo().m_wc.lpfnWndProc = m_pfnSuperWindowProc; - pT->GetWndClassInfo().Register( &m_pfnSuperWindowProc ); - } - - BOOL Initialise() - { - // Load list images - if ( !m_ilListItems.CreateFromImage( IDB_LISTITEMS, 16, 0, RGB( 255, 0, 255 ), IMAGE_BITMAP, LR_CREATEDIBSECTION ) ) - return FALSE; - - if ( m_curDivider.LoadCursor( IDC_DIVIDER ) == nullptr ) - return FALSE; - if ( m_curHyperLink.LoadCursor( IDC_HYPERLINK ) == nullptr ) - return FALSE; - - // Load interface settings - if ( !LoadSettings() ) - return FALSE; - - // Give control a static border - ModifyStyle( WS_BORDER, WS_CLIPCHILDREN ); - ModifyStyleEx( WS_EX_CLIENTEDGE, WS_EX_STATICEDGE, SWP_FRAMECHANGED ); - - // Register drag drop - m_oleDragDrop.Register( this ); - m_oleDragDrop.AddTargetFormat( m_nHeaderClipboardFormat ); - m_oleDragDrop.AddSourceFormat( m_nHeaderClipboardFormat ); - - // Create the tooltip - if ( !m_ttToolTip.Create( m_hWnd ) ) - return FALSE; - m_ttToolTip.SetMaxTipWidth( SHRT_MAX ); - - return TRUE; - } - - BOOL LoadSettings() - { - m_rgbBackground = GetSysColor( COLOR_WINDOW ); - m_rgbHeaderBackground = GetSysColor( COLOR_BTNFACE ); - m_rgbHeaderBorder = GetSysColor( COLOR_3DHIGHLIGHT ); - m_rgbHeaderShadow = GetSysColor( COLOR_3DSHADOW ); - m_rgbHeaderText = GetSysColor( COLOR_WINDOWTEXT ); - m_rgbHeaderHighlight = RGB( 130, 140, 180 ); - m_rgbSelectedItem = GetSysColor( COLOR_HIGHLIGHT ); - m_rgbSelectedText = GetSysColor( COLOR_HIGHLIGHTTEXT ); - m_rgbItemText = GetSysColor( COLOR_WINDOWTEXT ); - m_rgbSelectOuter = RGB( 170, 200, 245 ); - m_rgbSelectInner = RGB( 230, 250, 250 ); - m_rgbSelectTop = RGB( 210, 240, 250 ); - m_rgbSelectBottom = RGB( 185, 215, 250 ); - m_rgbNoFocusTop = RGB( 250, 250, 250 ); - m_rgbNoFocusBottom = RGB( 235, 235, 235 ); - m_rgbNoFocusOuter = RGB( 220, 220, 220 ); - m_rgbNoFocusInner = RGB( 245, 245, 245 ); - m_rgbFocusTop = RGB( 235, 245, 245 ); - m_rgbFocusBottom = RGB( 225, 235, 245 ); - m_rgbProgressTop = RGB( 170, 240, 170 ); - m_rgbProgressBottom = RGB( 45, 210, 50 ); - m_rgbItemFocus = RGB( 180, 190, 210 ); - m_rgbHyperLink = RGB( 0, 0, 200 ); - - m_nHeaderClipboardFormat = (CLIPFORMAT)RegisterClipboardFormat( _T( "HEADERCLIPBOARDFORMAT" ) ); - - // Get number of lines to scroll + BOOL SubclassWindow(HWND hWnd) + { + T * pT; + pT = static_cast(this); + return CWindowImpl::SubclassWindow(hWnd) ? pT->Initialise() : FALSE; + } + + void RegisterClass() + { + T * pT = static_cast(this); + pT = pT; + pT->GetWndClassInfo().m_wc.lpfnWndProc = m_pfnSuperWindowProc; + pT->GetWndClassInfo().Register(&m_pfnSuperWindowProc); + } + + BOOL Initialise() + { + // Load list images + if (!m_ilListItems.CreateFromImage(IDB_LISTITEMS, 16, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION)) + return FALSE; + + if (m_curDivider.LoadCursor(IDC_DIVIDER) == nullptr) + return FALSE; + if (m_curHyperLink.LoadCursor(IDC_HYPERLINK) == nullptr) + return FALSE; + + // Load interface settings + if (!LoadSettings()) + return FALSE; + + // Give control a static border + ModifyStyle(WS_BORDER, WS_CLIPCHILDREN); + ModifyStyleEx(WS_EX_CLIENTEDGE, WS_EX_STATICEDGE, SWP_FRAMECHANGED); + + // Register drag drop + m_oleDragDrop.Register(this); + m_oleDragDrop.AddTargetFormat(m_nHeaderClipboardFormat); + m_oleDragDrop.AddSourceFormat(m_nHeaderClipboardFormat); + + // Create the tooltip + if (!m_ttToolTip.Create(m_hWnd)) + return FALSE; + m_ttToolTip.SetMaxTipWidth(SHRT_MAX); + + return TRUE; + } + + BOOL LoadSettings() + { + m_rgbBackground = GetSysColor(COLOR_WINDOW); + m_rgbHeaderBackground = GetSysColor(COLOR_BTNFACE); + m_rgbHeaderBorder = GetSysColor(COLOR_3DHIGHLIGHT); + m_rgbHeaderShadow = GetSysColor(COLOR_3DSHADOW); + m_rgbHeaderText = GetSysColor(COLOR_WINDOWTEXT); + m_rgbHeaderHighlight = RGB(130, 140, 180); + m_rgbSelectedItem = GetSysColor(COLOR_HIGHLIGHT); + m_rgbSelectedText = GetSysColor(COLOR_HIGHLIGHTTEXT); + m_rgbItemText = GetSysColor(COLOR_WINDOWTEXT); + m_rgbSelectOuter = RGB(170, 200, 245); + m_rgbSelectInner = RGB(230, 250, 250); + m_rgbSelectTop = RGB(210, 240, 250); + m_rgbSelectBottom = RGB(185, 215, 250); + m_rgbNoFocusTop = RGB(250, 250, 250); + m_rgbNoFocusBottom = RGB(235, 235, 235); + m_rgbNoFocusOuter = RGB(220, 220, 220); + m_rgbNoFocusInner = RGB(245, 245, 245); + m_rgbFocusTop = RGB(235, 245, 245); + m_rgbFocusBottom = RGB(225, 235, 245); + m_rgbProgressTop = RGB(170, 240, 170); + m_rgbProgressBottom = RGB(45, 210, 50); + m_rgbItemFocus = RGB(180, 190, 210); + m_rgbHyperLink = RGB(0, 0, 200); + + m_nHeaderClipboardFormat = (CLIPFORMAT)RegisterClipboardFormat(_T( "HEADERCLIPBOARDFORMAT" )); + + // Get number of lines to scroll #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400) - SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &m_nMouseWheelScroll, 0 ); + SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &m_nMouseWheelScroll, 0); #endif - - // Get system message font - CLogFont logFont; - logFont.SetMessageBoxFont(); - if ( !m_fntListFont.IsNull() ) - m_fntListFont.DeleteObject(); - if ( m_fntListFont.CreateFontIndirect( &logFont ) == nullptr ) - return FALSE; - - // Get system underline font - logFont.lfUnderline = BYTE(TRUE); - if ( !m_fntUnderlineFont.IsNull() ) - m_fntUnderlineFont.DeleteObject(); - if ( m_fntUnderlineFont.CreateFontIndirect( &logFont ) == nullptr ) - return FALSE; - - CClientDC dcClient( m_hWnd ); - - HFONT hOldFont = dcClient.SelectFont( m_fntListFont ); - - CSize sizeExtent; - if ( !dcClient.GetTextExtent( _T( "Height" ), -1, &sizeExtent ) ) - return FALSE; - - dcClient.SelectFont( hOldFont ); - - // Has system font changed? - if ( m_nItemHeight != sizeExtent.cy + ITEM_HEIGHT_MARGIN ) - { - m_nItemHeight = sizeExtent.cy + ITEM_HEIGHT_MARGIN; - m_nHeaderHeight = m_nItemHeight; - - // Create drop arrows window - if ( m_wndDropArrows.IsWindow() ) - m_wndDropArrows.DestroyWindow(); - if ( !m_wndDropArrows.Create( m_hWnd, m_nHeaderHeight, TRUE ) ) - return FALSE; - } - - // Create title tip window - if ( m_wndTitleTip.IsWindow() ) - m_wndTitleTip.DestroyWindow(); - if ( !m_wndTitleTip.Create( m_hWnd ) ) - return FALSE; - - return TRUE; - } - - // Added by Rowan 05/12/2006 - void SetSortEnabled(BOOL bSortEnabled) - { - m_bSortEnabled = bSortEnabled; - } - - // Shygoo 11/02/2016 - void SetRightClickSelect( BOOL bRightClickSelect = TRUE) - { - m_bRightClickSelect = bRightClickSelect; - } - void ShowHeader( BOOL bShowHeader = TRUE ) - { - m_bShowHeader = bShowHeader; - ResetScrollBars(); - Invalidate(); - } + // Get system message font + CLogFont logFont; + logFont.SetMessageBoxFont(); + if (!m_fntListFont.IsNull()) + m_fntListFont.DeleteObject(); + if (m_fntListFont.CreateFontIndirect(&logFont) == nullptr) + return FALSE; - void ShowHeaderSort( BOOL bShowSort = TRUE ) - { - m_bShowSort = bShowSort; - Invalidate(); - } + // Get system underline font + logFont.lfUnderline = BYTE(TRUE); + if (!m_fntUnderlineFont.IsNull()) + m_fntUnderlineFont.DeleteObject(); + if (m_fntUnderlineFont.CreateFontIndirect(&logFont) == nullptr) + return FALSE; - void SetSingleSelect( BOOL bSingleSelect = TRUE ) - { - m_bSingleSelect = bSingleSelect; - Invalidate(); - } - - void SetFocusSubItem( BOOL bFocusSubItem = TRUE ) - { - m_bFocusSubItem = bFocusSubItem; - Invalidate(); - } - - void SetDragDrop( BOOL bDragDrop = TRUE ) - { - m_bDragDrop = bDragDrop; - } - - void SetSmoothScroll( BOOL bSmoothScroll = TRUE ) - { - m_bSmoothScroll = bSmoothScroll; - } - - void SetBackgroundImage( HBITMAP hBackgroundImage, BOOL bTileImage = FALSE ) - { - m_bmpBackground = hBackgroundImage; - m_bTileBackground = bTileImage; - } - - void SetImageList( CImageList& ilItemImages ) - { - m_ilItemImages = ilItemImages; - } - - UINT ValidateFlags( UINT nFlags ) - { - if ( nFlags & ITEM_FLAGS_CENTRE ) - nFlags &= ~( ITEM_FLAGS_LEFT | ITEM_FLAGS_RIGHT ); - if ( nFlags & ITEM_FLAGS_RIGHT ) - nFlags &= ~ITEM_FLAGS_LEFT; - if ( nFlags & ITEM_FLAGS_DATE_ONLY ) - nFlags &= ~ITEM_FLAGS_TIME_ONLY; - if ( nFlags & ( ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT ) ) - nFlags &= ~ITEM_FLAGS_EDIT_UPPER; - if ( !( nFlags & ( ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT ) ) ) - nFlags &= ~( ITEM_FLAGS_EDIT_NEGATIVE | ITEM_FLAGS_EDIT_OPERATOR ); - if ( nFlags & ITEM_FLAGS_COMBO_EDIT ) - nFlags &= ~( ITEM_FLAGS_DATE_ONLY | ITEM_FLAGS_TIME_ONLY | ITEM_FLAGS_DATETIME_NONE ); - return nFlags; - } - - void AddColumn( CListColumn& listColumn ) - { - // Minimum column width - if ( listColumn.m_strText.empty() && listColumn.m_nImage != ITEM_IMAGE_NONE ) - { - CSize sizeIcon; - m_ilListItems.GetIconSize( sizeIcon ); - listColumn.m_nWidth = sizeIcon.cx + 5; - listColumn.m_nFlags |= ITEM_FLAGS_CENTRE; - } - - // Correct incompatible flag mask values - listColumn.m_nFlags = ValidateFlags( listColumn.m_nFlags ); - - // Initial data index - listColumn.m_nIndex = GetColumnCount(); - - m_aColumns.Add( listColumn ); - - ResetScrollBars(); - Invalidate(); - } - - void AddColumn( LPCTSTR lpszText, int nWidth = 0, int nImage = ITEM_IMAGE_NONE, BOOL bFixed = FALSE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE ) - { - CListColumn listColumn; - listColumn.m_strText = lpszText; - listColumn.m_nWidth = nWidth; - listColumn.m_bFixed = bFixed; - listColumn.m_nFormat = nFormat; - listColumn.m_nFlags = nFlags; - listColumn.m_nImage = nImage; - AddColumn( listColumn ); - } + CClientDC dcClient(m_hWnd); - void RemoveAllCoumns ( void ) - { - m_aColumns.RemoveAll(); - ResetScrollBars(); - Invalidate(); - } - - BOOL GetHasEditItem () - { - return m_bEditItem; - } + HFONT hOldFont = dcClient.SelectFont(m_fntListFont); - int GetColumnCount() - { - return m_aColumns.GetSize(); - } - - BOOL GetColumn( int nColumn, CListColumn& listColumn ) - { - if ( nColumn < 0 || nColumn >= GetColumnCount() ) - return FALSE; - listColumn = m_aColumns[ nColumn ]; - return TRUE; - } - - int GetTotalWidth( BOOL bRecalc = FALSE ) - { - if ( bRecalc ) - { - m_nTotalWidth = 0; - for ( int nColumn = 0; nColumn < GetColumnCount(); nColumn++ ) - m_nTotalWidth += GetColumnWidth( nColumn ); - } - return m_nTotalWidth - 1; - } - - int GetTotalHeight() - { - T* pT = static_cast(this); - return max( ( pT->GetItemCount() * m_nItemHeight ) + ( m_bShowHeader ? m_nHeaderHeight : 0 ), 1 ); - } - - BOOL SetColumnWidth( int nColumn, int nWidth ) - { - if ( nColumn < 0 || nColumn >= GetColumnCount() ) - return FALSE; - - // Set new column size if not fixed - if ( !m_aColumns[ nColumn ].m_bFixed ) - { - m_aColumns[ nColumn ].m_nWidth = nWidth; - - ResetScrollBars(); - Invalidate(); - } - - return TRUE; - } + CSize sizeExtent; + if (!dcClient.GetTextExtent(_T( "Height" ), -1, &sizeExtent)) + return FALSE; - int GetColumnWidth( int nColumn ) - { - CListColumn listColumn; - return GetColumn( nColumn, listColumn ) ? listColumn.m_nWidth : 0; - } - - int GetColumnIndex( int nColumn ) - { - CListColumn listColumn; - return GetColumn( nColumn, listColumn ) ? listColumn.m_nIndex : 0; - } - - int IndexToOrder( int nIndex ) - { - for ( int nColumn = 0; nColumn < GetColumnCount(); nColumn++ ) - { - if ( GetColumnIndex( nColumn ) == nIndex ) - return nColumn; - } - return -1; - } - - BOOL SetColumnFormat( int nColumn, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE ) - { - if ( nColumn < 0 || nColumn >= GetColumnCount() ) - return FALSE; - m_aColumns[ nColumn ].m_nFormat = nFormat; - m_aColumns[ nColumn ].m_nFlags = ValidateFlags( nFlags ); - return TRUE; - } - - BOOL SetColumnFormat( int nColumn, UINT nFormat, UINT nFlags, CListArray < stdstr >& aComboList ) - { - if ( nColumn < 0 || nColumn >= GetColumnCount() ) - return FALSE; - m_aColumns[ nColumn ].m_nFormat = nFormat; - m_aColumns[ nColumn ].m_nFlags = ValidateFlags( nFlags ); - m_aColumns[ nColumn ].m_aComboList = aComboList; - return TRUE; - } - - UINT GetColumnFormat( int nColumn ) - { - CListColumn listColumn; - return GetColumn( nColumn, listColumn ) ? listColumn.m_nFormat : ITEM_FORMAT_NONE; - } - - UINT GetColumnFlags( int nColumn ) - { - CListColumn listColumn; - return GetColumn( nColumn, listColumn ) ? listColumn.m_nFlags : ITEM_FLAGS_NONE; - } - - BOOL GetColumnComboList( int nColumn, CListArray < stdstr >& aComboList ) - { - CListColumn listColumn; - if ( !GetColumn( nColumn, listColumn ) ) - return FALSE; - aComboList = listColumn.m_aComboList; - return !aComboList.IsEmpty(); - } - - BOOL GetColumnRect( int nColumn, CRect& rcColumn ) - { - if ( nColumn < 0 || nColumn >= GetColumnCount() ) - return FALSE; - - GetClientRect( rcColumn ); - rcColumn.bottom = m_nHeaderHeight; - - for ( int nColumnOrder = 0; nColumnOrder < GetColumnCount(); nColumnOrder++ ) - { - int nWidth = GetColumnWidth( nColumnOrder ); - - if ( nColumn == nColumnOrder ) - { - rcColumn.right = rcColumn.left + nWidth; - break; - } - - rcColumn.left += nWidth; - } - - // Offset column by scroll position - rcColumn.OffsetRect( -GetScrollPos( SB_HORZ ), 0 ); - - return TRUE; - } - - BOOL AddItem() - { - ResetScrollBars(); - return Invalidate(); - } - - BOOL DeleteItem( int nItem ) - { - m_setSelectedItems.erase( nItem ); - ResetScrollBars(); - return Invalidate(); - } - - BOOL DeleteAllItems() - { - m_setSelectedItems.clear(); - ResetScrollBars(); - return Invalidate(); - } - - int GetItemCount() - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return 0; - } - - stdstr GetItemText( int nItem, int nSubItem ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return _T( "" ); - } - - BOOL GetItemDate( int nItem, int nSubItem, SYSTEMTIME& stItemDate ) - { - T* pT = static_cast(this); - - ZeroMemory( &stItemDate, sizeof( SYSTEMTIME ) ); - - stdstr strItemText = pT->GetItemText( nItem, nSubItem ); - if ( strItemText.empty() ) - return FALSE; - - // Get date and time from item text: yyyymmddhhmmss - stItemDate.wYear = (WORD)_ttoi( strItemText.substr(0, 4 ).c_str() ); - stItemDate.wMonth = (WORD)_ttoi( strItemText.substr( 4, 2 ).c_str() ); - stItemDate.wDay = (WORD)_ttoi( strItemText.substr( 6, 2 ).c_str() ); - stItemDate.wHour = (WORD)_ttoi( strItemText.substr( 8, 2 ).c_str() ); - stItemDate.wMinute = (WORD)_ttoi( strItemText.substr( 10, 2 ).c_str() ); - stItemDate.wSecond = (WORD)_ttoi( strItemText.substr( 12, 2 ).c_str() ); - stItemDate.wMilliseconds = 0; - - return TRUE; - } - - int GetItemImage( int nItem, int nSubItem ) - { - return ITEM_IMAGE_NONE; // May be implemented in a derived class - } - - UINT GetItemFormat( int nItem, int nSubItem ) - { - return GetColumnFormat( IndexToOrder( nSubItem ) ); // May be implemented in a derived class - } - - UINT GetItemFlags( int nItem, int nSubItem ) - { - return GetColumnFlags( IndexToOrder( nSubItem ) ); // May be implemented in a derived class - } - - BOOL GetItemComboList( int nItem, int nSubItem, CListArray < stdstr >& aComboList ) - { - return GetColumnComboList( IndexToOrder( nSubItem ), aComboList ); // May be implemented in a derived class - } - - HFONT GetItemFont( int /*nItem*/, int /*nSubItem*/ ) - { - return m_fntListFont; // May be implemented in a derived class - } - - BOOL GetItemColours( int nItem, int nSubItem, COLORREF& rgbBackground, COLORREF& rgbText ) - { - rgbBackground = m_rgbBackground; - rgbText = m_rgbItemText; - return TRUE; - } - - stdstr virtual GetItemToolTip( int /*nItem*/, int /*nSubItem*/ ) - { - return _T( "" ); // May be implemented in a derived class - } - stdstr virtual GetHeaderToolTip(int /*column*/) - { - return _T(""); // Implemented by child class - } + dcClient.SelectFont(hOldFont); + // Has system font changed? + if (m_nItemHeight != sizeExtent.cy + ITEM_HEIGHT_MARGIN) + { + m_nItemHeight = sizeExtent.cy + ITEM_HEIGHT_MARGIN; + m_nHeaderHeight = m_nItemHeight; - BOOL SetItemText( int nItem, int nSubItem, LPCTSTR lpszText ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemComboIndex( int nItem, int nSubItem, int nIndex ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemDate( int nItem, int nSubItem, SYSTEMTIME& stItemDate ) - { - T* pT = static_cast(this); - - // Set date and time in format (yyyymmddhhmmss) - stdstr strFormatDate; - strFormatDate.Format( _T( "%04d%02d%02d%02d%02d%02d" ), stItemDate.wYear, stItemDate.wMonth, stItemDate.wDay, stItemDate.wHour, stItemDate.wMinute, stItemDate.wSecond ); - - return pT->SetItemText( nItem, nSubItem, strFormatDate.c_str() ); - } - - BOOL SetItemCheck( int nItem, int nSubItem, int nCheckValue ) - { - T* pT = static_cast(this); - - switch ( pT->GetItemFormat( nItem, nSubItem ) ) - { - case ITEM_FORMAT_CHECKBOX: return pT->SetItemText( nItem, nSubItem, nCheckValue > 0 ? _T( "1" ) : _T( "0" ) ); - case ITEM_FORMAT_CHECKBOX_3STATE: if ( nCheckValue < 0 ) - return pT->SetItemText( nItem, nSubItem, _T( "-1" ) ); - if ( nCheckValue > 0 ) - return pT->SetItemText( nItem, nSubItem, _T( "1" ) ); - return pT->SetItemText( nItem, nSubItem, _T( "0" ) ); - } - - return FALSE; - } - - BOOL SetItemImage( int nItem, int nSubItem, int nImage ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemFormat( int nItem, int nSubItem, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemFormat( int nItem, int nSubItem, UINT nFormat, UINT nFlags, CListArray < stdstr >& aComboList ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemFont( int nItem, int nSubItem, HFONT hFont ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL SetItemColours( int nItem, int nSubItem, COLORREF rgbBackground, COLORREF rgbText ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - void ReverseItems() - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - } - - void SortItems( int nColumn, BOOL bAscending ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - } - - BOOL GetItemRect( int nItem, int nSubItem, CRect& rcItem ) - { - T* pT = static_cast(this); - - int nTopItem = GetTopItem(); - if ( nItem < nTopItem || nItem >= pT->GetItemCount() || nItem >= nTopItem + GetCountPerPage() ) - return FALSE; - - CRect rcClient; - GetClientRect( rcClient ); - - // Calculate item rect based on scroll position - rcItem = rcClient; - rcItem.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ) + ( ( nItem - nTopItem ) * m_nItemHeight ); - rcItem.bottom = rcItem.top + m_nItemHeight; - rcItem.right = min( rcClient.right, GetTotalWidth() ); - - if ( nSubItem != NULL_SUBITEM ) - { - CRect rcColumn; - if ( !GetColumnRect( nSubItem, rcColumn ) ) - return FALSE; + // Create drop arrows window + if (m_wndDropArrows.IsWindow()) + m_wndDropArrows.DestroyWindow(); + if (!m_wndDropArrows.Create(m_hWnd, m_nHeaderHeight, TRUE)) + return FALSE; + } - rcItem.left = rcColumn.left; - rcItem.right = rcColumn.right; - } - - return TRUE; - } - - BOOL GetItemRect( int nItem, CRect& rcItem ) - { - return GetItemRect( nItem, NULL_SUBITEM, rcItem ); - } - - BOOL InvalidateItem( int nItem, int nSubItem = NULL_SUBITEM ) - { - CRect rcItem; - return GetItemRect( nItem, nSubItem, rcItem ) ? InvalidateRect( rcItem ) : FALSE; - } + // Create title tip window + if (m_wndTitleTip.IsWindow()) + m_wndTitleTip.DestroyWindow(); + if (!m_wndTitleTip.Create(m_hWnd)) + return FALSE; - BOOL InvalidateHeader() - { - if ( !m_bShowHeader ) - return TRUE; - CRect rcHeader; - if ( !GetClientRect( rcHeader ) ) - return FALSE; - rcHeader.bottom = m_nHeaderHeight; - return InvalidateRect( rcHeader ); - } - - int GetTopItem() - { - return (int)( GetScrollPos( SB_VERT ) / m_nItemHeight ); - } - - int GetCountPerPage( BOOL bPartial = TRUE ) - { - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - // Calculate number of items per control height (include partial item) - div_t divHeight = div( rcClient.Height(), m_nItemHeight ); - - // Round up to nearest item count - return max( bPartial && divHeight.rem > 0 ? divHeight.quot + 1 : divHeight.quot, 1 ); - } - - BOOL IsItemVisible( int nItem, int nSubItem = NULL_SUBITEM, BOOL bPartial = TRUE ) - { - T* pT = static_cast(this); - - int nTopItem = GetTopItem(); - if ( nItem < nTopItem || nItem >= pT->GetItemCount() ) - return FALSE; - - // Check whether item is visible - if ( nItem < nTopItem || nItem >= nTopItem + GetCountPerPage( bPartial ) ) - return FALSE; - - // Check whether subitem is visible - if ( m_bFocusSubItem && nSubItem != NULL_SUBITEM ) - { - CRect rcColumn; - if ( !GetColumnRect( nSubItem, rcColumn ) ) - return FALSE; - - CRect rcClient; - GetClientRect( rcClient ); - - if ( rcColumn.left < rcClient.left || rcColumn.right > rcClient.right ) - return FALSE; - } - - return TRUE; - } - - BOOL EnsureItemVisible( int nItem, int nSubItem = NULL_SUBITEM ) - { - if ( IsItemVisible( nItem, nSubItem, FALSE ) ) - return TRUE; - - HideTitleTip(); - - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - CRect rcItem; - rcItem.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ) + ( ( nItem - GetTopItem() ) * m_nItemHeight ); - rcItem.bottom = rcItem.top + m_nItemHeight; - - if ( rcItem.top < rcClient.top || rcItem.bottom > rcClient.bottom ) - { - int nScrollItem = NULL_ITEM; - - // Scroll list up/down to include item - if ( rcItem.top < rcClient.top || rcItem.Height() > rcClient.Height() ) - nScrollItem = nItem; - else if ( rcItem.bottom > rcClient.bottom ) - nScrollItem = nItem - ( GetCountPerPage( FALSE ) - 1 ); - - if ( nScrollItem != NULL_ITEM ) - SetScrollPos( SB_VERT, nScrollItem * m_nItemHeight ); - } - - if ( m_bFocusSubItem && nSubItem != NULL_SUBITEM ) - { - CRect rcColumn; - if ( !GetColumnRect( nSubItem, rcColumn ) ) - return FALSE; - - GetClientRect( rcClient ); + return TRUE; + } - int nScrollPos = 0; + // Added by Rowan 05/12/2006 + void SetSortEnabled(BOOL bSortEnabled) + { + m_bSortEnabled = bSortEnabled; + } - // Scroll list left/right to include subitem - if ( rcColumn.Width() > rcClient.Width() || rcColumn.left < 0 ) - nScrollPos = rcColumn.left; - else if ( rcColumn.right > rcClient.right ) - nScrollPos = rcColumn.right - rcClient.right; + // Shygoo 11/02/2016 + void SetRightClickSelect(BOOL bRightClickSelect = TRUE) + { + m_bRightClickSelect = bRightClickSelect; + } - if ( nScrollPos != 0 ) - SetScrollPos( SB_HORZ, GetScrollPos( SB_HORZ ) + nScrollPos ); - } - - return Invalidate(); - } - - void ShowScrollBar( int nScrollBar, BOOL bShow = TRUE ) - { - switch ( nScrollBar ) - { - case SB_HORZ: m_bShowHorizScroll = bShow; - break; - case SB_VERT: m_bShowVertScroll = bShow; - break; - case SB_BOTH: m_bShowHorizScroll = bShow; - m_bShowVertScroll = bShow; - break; - } - - ResetScrollBars(); - Invalidate(); - } - - void ResetScrollBars( int nScrollBar = SB_BOTH, int nScrollPos = -1, BOOL bRecalc = TRUE ) - { - T* pT = static_cast(this); - - CRect rcClient; - GetClientRect( rcClient ); - - SCROLLINFO infoScroll; - infoScroll.cbSize = sizeof( SCROLLINFO ); - infoScroll.fMask = nScrollPos < 0 ? SIF_PAGE | SIF_RANGE : SIF_PAGE | SIF_RANGE | SIF_POS; - infoScroll.nPos = nScrollPos; - infoScroll.nMin = 0; - - if ( ( nScrollBar == SB_BOTH || nScrollBar == SB_VERT ) && m_bShowVertScroll ) - { - infoScroll.nMax = ( pT->GetItemCount() * m_nItemHeight ) + ( m_bShowHeader ? m_nHeaderHeight : 0 ); - infoScroll.nPage = rcClient.Height() - ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - // Are we within client range? - if ( (UINT)infoScroll.nMax <= infoScroll.nPage + ( m_bShowHeader ? m_nHeaderHeight : 0 ) ) - infoScroll.nMax = 0; - - // Set vertical scroll bar - m_bEnableVertScroll = SetScrollInfo( SB_VERT, &infoScroll, TRUE ) ? ( infoScroll.nMax > 0 ) : FALSE; - } - - if ( ( nScrollBar == SB_BOTH || nScrollBar == SB_HORZ ) && m_bShowHorizScroll ) - { - infoScroll.nMax = GetTotalWidth( bRecalc ); - infoScroll.nPage = rcClient.Width(); - - // Are we within client range? - if ( infoScroll.nPage >= (UINT)infoScroll.nMax ) - infoScroll.nMax = 0; - - // Set horizontal scroll bar - m_bEnableHorizScroll = SetScrollInfo( SB_HORZ, &infoScroll, TRUE ) ? ( infoScroll.nMax > (int)infoScroll.nPage ) : FALSE; - } - } + void ShowHeader(BOOL bShowHeader = TRUE) + { + m_bShowHeader = bShowHeader; + ResetScrollBars(); + Invalidate(); + } - BOOL IsScrollBarVisible( int nScrollBar ) - { - switch ( nScrollBar ) - { - case SB_HORZ: return m_bEnableHorizScroll; - case SB_VERT: return m_bEnableVertScroll; - case SB_BOTH: return ( m_bEnableHorizScroll && m_bEnableVertScroll ); - default: return FALSE; - } - } - - BOOL ResetSelected() - { - m_setSelectedItems.clear(); - m_nFocusItem = NULL_ITEM; - m_nFocusSubItem = NULL_SUBITEM; - m_nFirstSelected = NULL_ITEM; - return Invalidate(); - } - - BOOL SelectItem( int nItem, int nSubItem = NULL_SUBITEM, UINT nFlags = 0 ) - { - T* pT = static_cast(this); - - if ( nItem < 0 || nItem >= pT->GetItemCount() ) - return FALSE; - - BOOL bSelectItem = TRUE; - BOOL bSelectRange = !m_bSingleSelect && ( nFlags & MK_SHIFT ); - BOOL bNewSelect = !( bSelectRange || ( nFlags & MK_CONTROL ) ); - BOOL bEnsureVisible = FALSE; + void ShowHeaderSort(BOOL bShowSort = TRUE) + { + m_bShowSort = bShowSort; + Invalidate(); + } - // Are we starting a new select sequence? - if ( bNewSelect || bSelectRange ) - { - // Are we simply reselecting the same item? - if ( m_setSelectedItems.size() == 1 && *m_setSelectedItems.begin() == nItem ) - { - bSelectItem = FALSE; - m_nFirstSelected = nItem; - m_nFocusItem = nItem; - m_nFocusSubItem = nSubItem; - } - else - m_setSelectedItems.clear(); - } - else // We adding to or removing from select sequence - { - if ( m_bSingleSelect ) - m_setSelectedItems.clear(); - - set < int >::iterator posSelectedItem = m_setSelectedItems.find( nItem ); - - // Is this item already selected? - if ( posSelectedItem != m_setSelectedItems.end() ) - { - bSelectItem = FALSE; - m_setSelectedItems.erase( posSelectedItem ); - m_nFirstSelected = nItem; - m_nFocusItem = nItem; - m_nFocusSubItem = m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem; - } - } - - // Are we adding this item to the select sequence? - if ( bSelectItem ) - { - bEnsureVisible = TRUE; - - if ( bSelectRange ) - { - if ( m_nFirstSelected == NULL_ITEM ) - m_nFirstSelected = nItem; - - for ( int nSelectedItem = min( m_nFirstSelected, nItem ); nSelectedItem <= max( m_nFirstSelected, nItem ); nSelectedItem++ ) - m_setSelectedItems.insert( nSelectedItem ); - } - else - { - m_nFirstSelected = nItem; - m_setSelectedItems.insert( nItem ); - } - - m_nFocusItem = nItem; - m_nFocusSubItem = m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem; - - // Notify parent of selected item - NotifyParent( m_nFocusItem, m_nFocusSubItem, LCN_SELECTED ); - } - - // Start visible timer (scrolls list to partially hidden item) - if ( !IsItemVisible( nItem, m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem, FALSE ) ) - SetTimer( ITEM_VISIBLE_TIMER, ITEM_VISIBLE_PERIOD ); - else if ( m_nFocusItem != NULL_ITEM && m_nFocusSubItem != NULL_SUBITEM ) - EditItem( m_nFocusItem, m_nFocusSubItem ); + void SetSingleSelect(BOOL bSingleSelect = TRUE) + { + m_bSingleSelect = bSingleSelect; + Invalidate(); + } - return Invalidate(); - } - - BOOL IsSelected( int nItem ) - { - set < int >::iterator posSelectedItem = m_setSelectedItems.find( nItem ); - return ( posSelectedItem != m_setSelectedItems.end() ); - } - - BOOL GetSelectedItems( CListArray < int >& aSelectedItems ) - { - aSelectedItems.RemoveAll(); - for ( set < int >::iterator posSelectedItem = m_setSelectedItems.begin(); posSelectedItem != m_setSelectedItems.end(); ++posSelectedItem ) - aSelectedItems.Add( *posSelectedItem ); - return !aSelectedItems.IsEmpty(); - } - - BOOL SetFocusItem( int nItem, int nSubItem = NULL_SUBITEM ) - { - m_nFocusItem = nItem; - m_nFocusSubItem = nSubItem; - return EnsureItemVisible( m_nFocusItem, m_nFocusSubItem ); - } + void SetFocusSubItem(BOOL bFocusSubItem = TRUE) + { + m_bFocusSubItem = bFocusSubItem; + Invalidate(); + } - BOOL GetFocusItem( int& nItem, int& nSubItem ) - { - nItem = IsSelected( m_nFocusItem ) ? m_nFocusItem : ( m_setSelectedItems.empty() ? NULL_ITEM : *m_setSelectedItems.begin() ); - nSubItem = !m_bFocusSubItem || nItem == NULL_ITEM ? NULL_SUBITEM : m_nFocusSubItem; - return ( nItem != NULL_ITEM ); - } - - int GetFocusItem() - { - return IsSelected( m_nFocusItem ) ? m_nFocusItem : ( m_setSelectedItems.empty() ? NULL_ITEM : *m_setSelectedItems.begin() ); - } - - BOOL HitTestHeader( CPoint point, int& nColumn, UINT& nFlags ) - { - // Reset hit test flags - nFlags = HITTEST_FLAG_NONE; - - if ( !m_bShowHeader ) - return FALSE; - - CRect rcClient; - if ( !GetClientRect( rcClient ) ) - return FALSE; - - // Are we over the header? - if ( point.y < rcClient.top || point.y > m_nHeaderHeight ) - return FALSE; - - int nDividerPos = 0; - int nColumnCount = GetColumnCount(); - - // Get hit test subitem - for ( nColumn = 0; nColumn < nColumnCount; nColumn++ ) - { - int nColumnWidth = GetColumnWidth( nColumn ); - nDividerPos += nColumnWidth; + void SetDragDrop(BOOL bDragDrop = TRUE) + { + m_bDragDrop = bDragDrop; + } - // Offset divider position with current scroll position - int nRelativePos = nDividerPos - GetScrollPos( SB_HORZ ); + void SetSmoothScroll(BOOL bSmoothScroll = TRUE) + { + m_bSmoothScroll = bSmoothScroll; + } - // Are we over the divider zone? - if ( point.x >= nRelativePos - DRAG_HEADER_OFFSET - 1 && point.x <= nRelativePos + DRAG_HEADER_OFFSET ) - { - nFlags |= HITTEST_FLAG_HEADER_DIVIDER; - - // Are we to the left of the divider (or over last column divider)? - if ( ( point.x >= nRelativePos - DRAG_HEADER_OFFSET - 1 && point.x < nRelativePos ) || nColumn + 1 >= nColumnCount - 1 ) - { - nFlags |= HITTEST_FLAG_HEADER_LEFT; - return TRUE; - } + void SetBackgroundImage(HBITMAP hBackgroundImage, BOOL bTileImage = FALSE) + { + m_bmpBackground = hBackgroundImage; + m_bTileBackground = bTileImage; + } - // Find last zero-length column after this column - for ( int nNextColumn = nColumn + 1; nNextColumn < nColumnCount; nNextColumn++ ) - { - if ( GetColumnWidth( nNextColumn ) > 0 ) - break; - nColumn = nNextColumn; - } - - nFlags |= HITTEST_FLAG_HEADER_RIGHT; + void SetImageList(CImageList & ilItemImages) + { + m_ilItemImages = ilItemImages; + } - return TRUE; - } + UINT ValidateFlags(UINT nFlags) + { + if (nFlags & ITEM_FLAGS_CENTRE) + nFlags &= ~(ITEM_FLAGS_LEFT | ITEM_FLAGS_RIGHT); + if (nFlags & ITEM_FLAGS_RIGHT) + nFlags &= ~ITEM_FLAGS_LEFT; + if (nFlags & ITEM_FLAGS_DATE_ONLY) + nFlags &= ~ITEM_FLAGS_TIME_ONLY; + if (nFlags & (ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT)) + nFlags &= ~ITEM_FLAGS_EDIT_UPPER; + if (!(nFlags & (ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT))) + nFlags &= ~(ITEM_FLAGS_EDIT_NEGATIVE | ITEM_FLAGS_EDIT_OPERATOR); + if (nFlags & ITEM_FLAGS_COMBO_EDIT) + nFlags &= ~(ITEM_FLAGS_DATE_ONLY | ITEM_FLAGS_TIME_ONLY | ITEM_FLAGS_DATETIME_NONE); + return nFlags; + } - // Are we over a column? - if ( point.x > nRelativePos - nColumnWidth && point.x < nRelativePos ) - return TRUE; - } - - return FALSE; - } - - BOOL HitTest( CPoint point, int& nItem, int& nSubItem ) - { - T* pT = static_cast(this); - - // Are we over the header? - if ( point.y < ( m_bShowHeader ? m_nHeaderHeight : 0 ) ) - return FALSE; - - // Calculate hit test item - nItem = GetTopItem() + (int)( ( point.y - ( m_bShowHeader ? m_nHeaderHeight : 0 ) ) / m_nItemHeight ); - - if ( nItem < 0 || nItem >= pT->GetItemCount() ) - return FALSE; - - int nTotalWidth = 0; - int nColumnCount = GetColumnCount(); - - // Get hit test subitem - for ( nSubItem = 0; nSubItem < nColumnCount; nSubItem++ ) - { - int nColumnWidth = GetColumnWidth( nSubItem ); - nTotalWidth += nColumnWidth; + void AddColumn(CListColumn & listColumn) + { + // Minimum column width + if (listColumn.m_strText.empty() && listColumn.m_nImage != ITEM_IMAGE_NONE) + { + CSize sizeIcon; + m_ilListItems.GetIconSize(sizeIcon); + listColumn.m_nWidth = sizeIcon.cx + 5; + listColumn.m_nFlags |= ITEM_FLAGS_CENTRE; + } - // Offset position with current scroll position - int nRelativePos = nTotalWidth - GetScrollPos( SB_HORZ ); + // Correct incompatible flag mask values + listColumn.m_nFlags = ValidateFlags(listColumn.m_nFlags); - // Are we over a subitem? - if ( point.x > nRelativePos - nColumnWidth && point.x < nRelativePos ) - return TRUE; - } - - return FALSE; - } - - BOOL AutoSizeColumn( int nColumn ) - { - T* pT = static_cast(this); - - CListColumn listColumn; - if ( !GetColumn( nColumn, listColumn ) || listColumn.m_bFixed ) - return FALSE; - - CClientDC dcClient( m_hWnd ); - HFONT hOldFont = dcClient.SelectFont( m_fntListFont ); - - // Set to column text width if zero-length - CSize sizeExtent; - if ( !dcClient.GetTextExtent( listColumn.m_strText.c_str(), -1, &sizeExtent ) ) - return FALSE; - - int nMaxWidth = sizeExtent.cx + ITEM_WIDTH_MARGIN; - - CSize sizeIcon = 0; - if ( !m_ilItemImages.IsNull() ) - m_ilItemImages.GetIconSize( sizeIcon ); - - // Calculate maximum column width required - for ( int nItem = 0; nItem < pT->GetItemCount(); nItem++ ) - { - if ( !dcClient.GetTextExtent( pT->GetItemText( nItem, listColumn.m_nIndex ), -1, &sizeExtent ) ) - return FALSE; - - if ( !m_ilItemImages.IsNull() && pT->GetItemImage( nItem, listColumn.m_nIndex ) != ITEM_IMAGE_NONE ) - sizeExtent.cx += sizeIcon.cx; - - nMaxWidth = max( nMaxWidth, (int)sizeExtent.cx + ITEM_WIDTH_MARGIN ); - } - - dcClient.SelectFont( hOldFont ); - - return SetColumnWidth( nColumn, nMaxWidth ); - } - - void ResizeColumn( BOOL bColumnScroll = FALSE ) - { - HideTitleTip(); - - int nCurrentPos = GET_X_LPARAM( GetMessagePos() ); - - CRect rcClient; - GetClientRect( rcClient ); - int nScrollLimit = GetTotalWidth() - rcClient.Width(); - - if ( bColumnScroll ) - { - // Have we finished scrolling list to accommodate new column size? - if ( !m_bColumnSizing || !m_bEnableHorizScroll || nCurrentPos - m_nStartScrollPos > 0 ) - { - KillTimer( RESIZE_COLUMN_TIMER ); - - // Reset resize start point - m_nStartPos = nCurrentPos; - m_bResizeTimer = FALSE; - } - else if ( nCurrentPos < m_nStartPos && GetScrollPos( SB_HORZ ) >= nScrollLimit ) - { - // Reset start column size - m_nStartSize = max( GetColumnWidth( m_nColumnSizing ) + ( nCurrentPos - m_nStartScrollPos ), 0 ); - - // Resize column - SetColumnWidth( m_nColumnSizing, m_nStartSize ); - } - } - else - { - int nColumnSize = max( m_nStartSize + ( nCurrentPos - m_nStartPos ), 0 ); - - // Are we scrolled fully to the right and wanting to reduce the size of a column? - if ( m_bEnableHorizScroll && GetScrollPos( SB_HORZ ) >= nScrollLimit && nColumnSize < GetColumnWidth( m_nColumnSizing ) ) - { - if ( !m_bResizeTimer ) - { - // Only start the scroll timer once - m_bResizeTimer = TRUE; + // Initial data index + listColumn.m_nIndex = GetColumnCount(); - // Set new start scroll position - m_nStartScrollPos = nCurrentPos; + m_aColumns.Add(listColumn); - // Start column resize / scroll timer - SetTimer( RESIZE_COLUMN_TIMER, RESIZE_COLUMN_PERIOD ); - } - } - else - { - // Resizing is done in scroll timer (if started) - if ( !m_bResizeTimer ) - SetColumnWidth( m_nColumnSizing, nColumnSize ); - } - } - } - - void DragColumn() - { - HideTitleTip(); - - CRect rcColumn; - if ( !GetColumnRect( m_nHighlightColumn, rcColumn ) ) - return; - - CRect rcHeaderItem( rcColumn ); - rcHeaderItem.MoveToXY( 0, 0 ); - - CListColumn listColumn; - if ( !GetColumn( m_nHighlightColumn, listColumn ) ) - return; - - // Store drag column - m_nDragColumn = m_nHighlightColumn; - - CClientDC dcClient( m_hWnd ); - - CDC dcHeader; - dcHeader.CreateCompatibleDC( dcClient ); - - int nContextState = dcHeader.SaveDC(); - - // Create drag header bitmap - CBitmapHandle bmpHeader; - bmpHeader.CreateCompatibleBitmap( dcClient, rcHeaderItem.Width(), rcHeaderItem.Height() ); - dcHeader.SelectBitmap( bmpHeader ); - - dcHeader.SetBkColor( m_rgbHeaderBackground ); - dcHeader.ExtTextOut( rcHeaderItem.left, rcHeaderItem.top, ETO_OPAQUE, rcHeaderItem, _T( "" ), 0, nullptr ); - dcHeader.Draw3dRect( rcHeaderItem, m_rgbHeaderBorder, m_rgbHeaderShadow ); - - CRect rcHeaderText( rcHeaderItem ); - rcHeaderText.left += m_nHighlightColumn == 0 ? 4 : 3; - rcHeaderText.OffsetRect( 0, 1 ); - - // Margin header text - rcHeaderText.DeflateRect( 4, 0, 5, 0 ); - - // Has this header item an associated image? - if ( listColumn.m_nImage != ITEM_IMAGE_NONE ) - { - CSize sizeIcon; - m_ilListItems.GetIconSize( sizeIcon ); - - CRect rcHeaderImage; - rcHeaderImage.left = listColumn.m_strText.empty() ? ( ( rcHeaderText.left + rcHeaderText.right ) / 2 ) - ( sizeIcon.cx / 2 ) - ( 0 ) : rcHeaderText.left; - rcHeaderImage.right = min( rcHeaderImage.left + sizeIcon.cx, rcHeaderItem.right ); - rcHeaderImage.top = ( ( rcHeaderItem.top + rcHeaderItem.bottom ) / 2 ) - ( sizeIcon.cy / 2 ); - rcHeaderImage.bottom = min( rcHeaderImage.top + sizeIcon.cy, rcHeaderItem.bottom ); - - m_ilListItems.DrawEx( listColumn.m_nImage, dcHeader, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); + ResetScrollBars(); + Invalidate(); + } - // Offset header text (for image) - rcHeaderText.left += sizeIcon.cx + 4; - } - - dcHeader.SelectFont( m_fntListFont ); - dcHeader.SetTextColor( m_rgbHeaderText ); - dcHeader.SetBkMode( TRANSPARENT ); + void AddColumn(LPCTSTR lpszText, int nWidth = 0, int nImage = ITEM_IMAGE_NONE, BOOL bFixed = FALSE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE) + { + CListColumn listColumn; + listColumn.m_strText = lpszText; + listColumn.m_nWidth = nWidth; + listColumn.m_bFixed = bFixed; + listColumn.m_nFormat = nFormat; + listColumn.m_nFlags = nFlags; + listColumn.m_nImage = nImage; + AddColumn(listColumn); + } - UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + void RemoveAllCoumns(void) + { + m_aColumns.RemoveAll(); + ResetScrollBars(); + Invalidate(); + } - if ( listColumn.m_nFlags & ITEM_FLAGS_CENTRE ) - nFormat |= DT_CENTER; - else if ( listColumn.m_nFlags & ITEM_FLAGS_RIGHT ) - nFormat |= DT_RIGHT; - else - nFormat |= DT_LEFT; - - // Draw header text - if ( !listColumn.m_strText.empty() ) - dcHeader.DrawText( listColumn.m_strText.c_str(), (int)listColumn.m_strText.length(), rcHeaderText, nFormat ); + BOOL GetHasEditItem() + { + return m_bEditItem; + } - dcHeader.RestoreDC( nContextState ); - - SHDRAGIMAGE shDragImage; - ZeroMemory( &shDragImage, sizeof( SHDRAGIMAGE ) ); - - shDragImage.sizeDragImage.cx = rcHeaderItem.Width(); - shDragImage.sizeDragImage.cy = rcHeaderItem.Height(); - shDragImage.ptOffset.x = rcColumn.Width() / 2; - shDragImage.ptOffset.y = rcColumn.Height() / 2; - shDragImage.hbmpDragImage = bmpHeader; - shDragImage.crColorKey = m_rgbBackground; - - // Start header drag operation - m_oleDragDrop.DoDragDrop( &shDragImage, DROPEFFECT_MOVE ); - - // Hide drop arrows after moving column - m_wndDropArrows.Hide(); - - if ( m_bButtonDown ) - { - ReleaseCapture(); - m_bButtonDown = FALSE; - m_bBeginSelect = FALSE; - m_ptDownPoint = 0; - m_ptSelectPoint = 0; - } - - // Finish moving a column - if ( m_nHighlightColumn != NULL_COLUMN ) - { - m_nHighlightColumn = NULL_COLUMN; - InvalidateHeader(); - } - - m_nDragColumn = NULL_COLUMN; - } - - BOOL DropColumn( CPoint point ) - { - if ( !m_bShowHeader ) - return FALSE; - - m_nHotDivider = NULL_COLUMN; - m_nHotColumn = NULL_COLUMN; - UINT nHeaderFlags = HITTEST_FLAG_NONE; - - // Are we over the header? - if ( HitTestHeader( point, m_nHotColumn, nHeaderFlags ) ) - { - CRect rcColumn; - if ( !GetColumnRect( m_nHotColumn, rcColumn ) ) - return FALSE; - m_nHotDivider = point.x < ( ( rcColumn.left + rcColumn.right ) / 2 ) ? m_nHotColumn : m_nHotColumn + 1; - - if ( m_nHotDivider == m_nDragColumn || m_nHotDivider == m_nDragColumn + 1 ) - m_nHotDivider = NULL_COLUMN; - } - - if ( m_nHotDivider != NULL_COLUMN ) - { - CRect rcHeader; - GetClientRect( rcHeader ); - rcHeader.bottom = m_nHeaderHeight; - - CPoint ptDivider( 0, rcHeader.Height() / 2 ); - - CRect rcColumn; - int nColumnCount = GetColumnCount(); - - // Set closest divider position - if ( GetColumnRect( m_nHotDivider < nColumnCount ? m_nHotDivider : nColumnCount - 1, rcColumn ) ) - ptDivider.x = m_nHotDivider < nColumnCount ? rcColumn.left : rcColumn.right; - - ClientToScreen( &ptDivider ); - - // Track drop window - m_wndDropArrows.Show( ptDivider ); - return TRUE; - } - - m_wndDropArrows.Hide(); - - return FALSE; - } - - BOOL SortColumn( int nColumn ) - { - T* pT = static_cast(this); - - if ( !m_bShowHeader || !m_bShowSort ) - return FALSE; - - int nSortIndex = GetColumnIndex( nColumn ); - - CWaitCursor curWait; - - if ( nSortIndex != m_nSortColumn ) - { - // Sort by new column - m_bSortAscending = TRUE; - m_nSortColumn = nSortIndex; - pT->SortItems( m_nSortColumn, m_bSortAscending ); - } - else - { - // Toggle sort order if sorting same column - m_bSortAscending = !m_bSortAscending; - pT->ReverseItems(); - } - - return ResetSelected(); - } - - BOOL GetSortColumn( int& nColumn, BOOL& bAscending ) - { - if ( !m_bShowHeader || !m_bShowSort || m_nSortColumn == NULL_COLUMN ) - return FALSE; - nColumn = m_nSortColumn; - bAscending = m_bSortAscending; - return TRUE; - } - - BOOL DragItem() - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - return FALSE; - } - - BOOL GroupSelect( CPoint point ) - { - HideTitleTip(); - - int nHorzScroll = GetScrollPos( SB_HORZ ); - int nVertScroll = GetScrollPos( SB_VERT ); - - m_rcGroupSelect.left = min( m_ptSelectPoint.x, point.x + nHorzScroll ); - m_rcGroupSelect.right = max( m_ptSelectPoint.x, point.x + nHorzScroll ); - m_rcGroupSelect.top = min( m_ptSelectPoint.y, point.y + nVertScroll ); - m_rcGroupSelect.bottom = max( m_ptSelectPoint.y, point.y + nVertScroll ); - - if ( m_rcGroupSelect.IsRectEmpty() ) - return FALSE; - - // Select items in group - AutoSelect( point ); - - // Start auto scroll timer - SetTimer( ITEM_AUTOSCROLL_TIMER, ITEM_SCROLL_PERIOD ); - - DWORD dwCurrentTick = GetTickCount(); - - // Timer messages are a low priority, therefore we need to simulate the timer when moving the mouse - if ( ( dwCurrentTick - m_dwScrollTick ) > ITEM_SCROLL_PERIOD - 10 ) - { - if ( AutoScroll( point ) ) - m_dwScrollTick = dwCurrentTick; - } - - // Redraw list immediately - return RedrawWindow(); - } - - void AutoSelect( CPoint /*point*/ ) - { - m_setSelectedItems.clear(); - - if ( m_rcGroupSelect.left < GetTotalWidth() ) - { - int nHorzScroll = GetScrollPos( SB_HORZ ); - int nVertScroll = GetScrollPos( SB_VERT ); - - CRect rcGroupSelect( m_rcGroupSelect ); - rcGroupSelect.OffsetRect( -nHorzScroll, -nVertScroll ); - - int nTopItem = GetTopItem(); - int nLastItem = nTopItem + ( ( rcGroupSelect.bottom - ( m_bShowHeader ? m_nHeaderHeight : 0 ) ) / m_nItemHeight ); - nTopItem += ( ( rcGroupSelect.top - ( m_bShowHeader ? m_nHeaderHeight : 0 ) ) / m_nItemHeight ) - ( ( rcGroupSelect.top < 0 ) ? 1 : 0 ); - - for ( int nItem = nTopItem; nItem <= nLastItem; nItem++ ) - { - if ( m_setSelectedItems.empty() ) - m_nFirstSelected = nItem; - m_setSelectedItems.insert( nItem ); - - m_nFocusItem = nItem; - m_nFocusSubItem = NULL_SUBITEM; - } - } + int GetColumnCount() + { + return m_aColumns.GetSize(); + } - if ( m_setSelectedItems.empty() ) - m_nFirstSelected = NULL_ITEM; - } - - BOOL AutoScroll( CPoint point ) - { - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - int nHorzScroll = GetScrollPos( SB_HORZ ); - int nVertScroll = GetScrollPos( SB_VERT ); + BOOL GetColumn(int nColumn, CListColumn & listColumn) + { + if (nColumn < 0 || nColumn >= GetColumnCount()) + return FALSE; + listColumn = m_aColumns[nColumn]; + return TRUE; + } - BOOL bAutoScroll = FALSE; - - if ( point.y < rcClient.top ) - { - SendMessage( WM_VSCROLL, MAKEWPARAM( SB_LINEUP, 0 ) ); - int nAutoScroll = GetScrollPos( SB_VERT ); - if ( nVertScroll != nAutoScroll ) - { - m_rcGroupSelect.top = rcClient.top + nAutoScroll - 1; - m_rcGroupSelect.bottom = max( m_ptSelectPoint.y, point.y + nAutoScroll - 1 ); - bAutoScroll = TRUE; - } - } - if ( point.y > rcClient.bottom ) - { - SendMessage( WM_VSCROLL, MAKEWPARAM( SB_LINEDOWN, 0 ) ); - int nAutoScroll = GetScrollPos( SB_VERT ); - if ( nVertScroll != nAutoScroll ) - { - m_rcGroupSelect.top = min( m_ptSelectPoint.y, point.y + nAutoScroll + 1 ); - m_rcGroupSelect.bottom = rcClient.bottom + nAutoScroll + 1; - bAutoScroll = TRUE; - } - } - if ( point.x < rcClient.left ) - { - SendMessage( WM_HSCROLL, MAKEWPARAM( SB_LINELEFT, 0 ) ); - int nAutoScroll = GetScrollPos( SB_HORZ ); - if ( nHorzScroll != nAutoScroll ) - { - m_rcGroupSelect.left = rcClient.left + nAutoScroll - 1; - m_rcGroupSelect.right = max( m_ptSelectPoint.x, point.x + nAutoScroll - 1 ); - bAutoScroll = TRUE; - } - } - if ( point.x > rcClient.right ) - { - SendMessage( WM_HSCROLL, MAKEWPARAM( SB_LINERIGHT, 0 ) ); - int nAutoScroll = GetScrollPos( SB_HORZ ); - if ( nHorzScroll != nAutoScroll ) - { - m_rcGroupSelect.left = min( m_ptSelectPoint.x, point.x + nAutoScroll + 1 ); - m_rcGroupSelect.right = rcClient.right + nAutoScroll + 1; - bAutoScroll = TRUE; - } - } - - // Was the scrolling performed? - return bAutoScroll; - } - - BOOL BeginScroll( int nBeginItem, int nEndItem ) - { - T* pT = static_cast(this); - - // Any scroll required? - if ( nBeginItem == nEndItem ) - return FALSE; - - // Calculate scroll offset - m_nScrollOffset = abs( nEndItem - nBeginItem ) * m_nItemHeight; - m_nScrollUnit = min( max( m_nScrollOffset / m_nItemHeight, ITEM_SCROLL_UNIT_MIN ), ITEM_SCROLL_UNIT_MAX ); - m_nScrollDelta = ( m_nScrollOffset - m_nScrollUnit ) / m_nScrollUnit; - m_bScrollDown = ( nBeginItem < nEndItem ); - - CClientDC dcClient( m_hWnd ); - - CDC dcScrollList; - dcScrollList.CreateCompatibleDC( dcClient ); - - int nContextState = dcScrollList.SaveDC(); - - CRect rcScrollList; - GetClientRect( rcScrollList ); - rcScrollList.bottom = ( GetCountPerPage() + abs( nEndItem - nBeginItem ) ) * m_nItemHeight; - - if ( !m_bmpScrollList.IsNull() ) - m_bmpScrollList.DeleteObject(); - m_bmpScrollList.CreateCompatibleBitmap( dcClient, rcScrollList.Width(), rcScrollList.Height() ); - dcScrollList.SelectBitmap( m_bmpScrollList ); - - pT->DrawBkgnd( dcScrollList.m_hDC ); - - CRect rcItem; - rcItem.left = -GetScrollPos( SB_HORZ ); - rcItem.right = GetTotalWidth(); - rcItem.top = 0; - rcItem.bottom = rcItem.top; - - // Draw all visible items into bitmap - for ( int nItem = min( nBeginItem, nEndItem ); nItem < pT->GetItemCount(); rcItem.top = rcItem.bottom, nItem++ ) - { - rcItem.bottom = rcItem.top + m_nItemHeight; - - if ( rcItem.top > rcScrollList.bottom ) - break; - - // May be implemented in a derived class - pT->DrawItem( dcScrollList.m_hDC, nItem, rcItem ); - } - - dcScrollList.RestoreDC( nContextState ); - - ScrollList(); - - // Start scrolling timer - SetTimer( ITEM_SCROLL_TIMER, ITEM_SCROLL_PERIOD ); - - return TRUE; - } - - BOOL EndScroll() - { - KillTimer( ITEM_SCROLL_TIMER ); - if ( !m_bmpScrollList.IsNull() ) - m_bmpScrollList.DeleteObject(); - return Invalidate(); - } - - BOOL ScrollList() - { - if ( m_nScrollOffset <= m_nScrollUnit ) - m_nScrollOffset--; - else - { - m_nScrollOffset -= m_nScrollDelta; - if ( m_nScrollOffset < m_nScrollDelta ) - m_nScrollOffset = m_nScrollUnit; - } - - if ( m_bmpScrollList.IsNull() || m_nScrollOffset < 0 ) - return FALSE; - - CClientDC dcClient( m_hWnd ); - - CDC dcScrollList; - dcScrollList.CreateCompatibleDC( dcClient ); - - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - HBITMAP hOldBitmap = dcScrollList.SelectBitmap( m_bmpScrollList ); - - CSize sizScrollBitmap; - m_bmpScrollList.GetSize( sizScrollBitmap ); - - // Draw scrolled list - dcClient.BitBlt( 0, rcClient.top, rcClient.Width(), rcClient.Height(), dcScrollList, 0, m_bScrollDown ? ( sizScrollBitmap.cy - ( GetCountPerPage() * m_nItemHeight ) - m_nScrollOffset ) : m_nScrollOffset, SRCCOPY ); + int GetTotalWidth(BOOL bRecalc = FALSE) + { + if (bRecalc) + { + m_nTotalWidth = 0; + for (int nColumn = 0; nColumn < GetColumnCount(); nColumn++) + m_nTotalWidth += GetColumnWidth(nColumn); + } + return m_nTotalWidth - 1; + } - dcScrollList.SelectBitmap( hOldBitmap ); - - return TRUE; - } - - BOOL EditItem( int nItem, int nSubItem = NULL_SUBITEM ) - { - T* pT = static_cast(this); - - if ( !EnsureItemVisible( nItem, nSubItem ) ) - return FALSE; - - if ( GetFocus() != m_hWnd ) - return FALSE; - - CRect rcSubItem; - if ( !GetItemRect( nItem, nSubItem, rcSubItem ) ) - return FALSE; - - int nIndex = GetColumnIndex( nSubItem ); - if ( pT->GetItemFlags( nItem, nIndex ) & ITEM_FLAGS_READ_ONLY ) - return TRUE; - - switch ( pT->GetItemFormat( nItem, nIndex ) ) - { - case ITEM_FORMAT_EDIT: m_bEditItem = TRUE; - if ( !RedrawWindow() ) - return FALSE; - if ( !m_wndItemEdit.Create( m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags( nItem, nIndex ), pT->GetItemText( nItem, nIndex ), pT->GetItemMaxEditLen(nItem, nIndex ) ) ) - return FALSE; - m_wndItemEdit.SetFont(GetItemFont(nItem, nIndex)); - break; - case ITEM_FORMAT_DATETIME: { - m_bEditItem = TRUE; - if ( !RedrawWindow() ) - return FALSE; - SYSTEMTIME stItemDate; - GetItemDate( nItem, nIndex, stItemDate ); - if ( !m_wndItemDate.Create( m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags( nItem, nIndex ), stItemDate ) ) - return FALSE; - } - break; - case ITEM_FORMAT_COMBO: { - m_bEditItem = TRUE; - if ( !RedrawWindow() ) - return FALSE; - CListArray < stdstr > aComboList; - if ( !pT->GetItemComboList( nItem, nIndex, aComboList ) ) - return FALSE; - if ( !m_wndItemCombo.Create( m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags( nItem, nIndex ), pT->GetItemText( nItem, nIndex ), aComboList ) ) - return FALSE; - } - break; - } - return TRUE; - } - - stdstr FormatDate( SYSTEMTIME& stFormatDate ) - { - if ( stFormatDate.wYear == 0 ) - return _T( "" ); - - // Format date to local format - TCHAR szDateFormat[ DATE_STRING ]; - return GetDateFormat( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stFormatDate, nullptr, szDateFormat, DATE_STRING ) == 0 ? _T( "" ) : szDateFormat; - } - - stdstr FormatTime( SYSTEMTIME& stFormatDate ) - { - SYSTEMTIME stFormatTime = stFormatDate; - stFormatTime.wYear = 0; - stFormatTime.wMonth = 0; - stFormatTime.wDay = 0; - - // Format time to local format - TCHAR szTimeFormat[ DATE_STRING ]; - return GetTimeFormat( LOCALE_USER_DEFAULT, 0, &stFormatTime, nullptr, szTimeFormat, DATE_STRING ) == 0 ? _T( "" ) : szTimeFormat; - } - - void NotifyParent( int nItem, int nSubItem, int nMessage ) - { - T* pT = static_cast(this); - - CListNotify listNotify; - listNotify.m_hdrNotify.hwndFrom = pT->m_hWnd; - listNotify.m_hdrNotify.idFrom = pT->GetDlgCtrlID(); - listNotify.m_hdrNotify.code = nMessage; - listNotify.m_nItem = nItem; - listNotify.m_nSubItem = GetColumnIndex( nSubItem ); - listNotify.m_nExitChar = 0; - listNotify.m_lpszItemText = nullptr; - listNotify.m_lpItemDate = nullptr; + int GetTotalHeight() + { + T * pT = static_cast(this); + return max((pT->GetItemCount() * m_nItemHeight) + (m_bShowHeader ? m_nHeaderHeight : 0), 1); + } - // Forward notification to parent - FORWARD_WM_NOTIFY( pT->GetParent(), listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage ); - } - - BOOL ShowTitleTip( CPoint point, int nItem, int nSubItem ) - { - T* pT = static_cast(this); - - // Do not show title tip if editing - if ( m_bEditItem ) - return FALSE; - - // Is title tip already shown for this item? - if ( nItem == m_nTitleTipItem && nSubItem == m_nTitleTipSubItem ) - return FALSE; - - CRect rcSubItem; - if ( !GetItemRect( nItem, nSubItem, rcSubItem ) ) - { - HideTitleTip(); - return FALSE; - } - - int nIndex = GetColumnIndex( nSubItem ); - CRect rcItemText( rcSubItem ); - - // margin item text -// rcItemText.left += nSubItem == 0 ? 4 : 3; -// rcItemText.DeflateRect( 4, 0 ); - - // Offset item text (for image) - if ( !m_ilItemImages.IsNull() && pT->GetItemImage( nItem, nIndex ) != ITEM_IMAGE_NONE ) - { - CSize sizeIcon; - m_ilItemImages.GetIconSize( sizeIcon ); - rcItemText.left += sizeIcon.cx + 4; - } - - // Is current cursor position over item text (not over an icon)? - if ( !rcItemText.PtInRect( point ) ) - return FALSE; - - stdstr strItemText; - - switch ( pT->GetItemFormat( nItem, nIndex ) ) - { - case ITEM_FORMAT_CHECKBOX: - case ITEM_FORMAT_CHECKBOX_3STATE: - case ITEM_FORMAT_PROGRESS: break; // No title tip for checkboxes or progress - case ITEM_FORMAT_DATETIME: { - SYSTEMTIME stItemDate; - if ( !GetItemDate( nItem, nIndex, stItemDate ) ) - break; - - UINT nItemFlags = pT->GetItemFlags( nItem, nIndex ); - if ( nItemFlags & ITEM_FLAGS_DATE_ONLY ) - strItemText = FormatDate( stItemDate ); - else if ( nItemFlags & ITEM_FLAGS_TIME_ONLY ) - strItemText = FormatTime( stItemDate ); - else - strItemText = FormatDate( stItemDate ) + _T( " " ) + FormatTime( stItemDate ); - } - break; - default: strItemText = pT->GetItemText( nItem, nIndex ); - break; - } + BOOL SetColumnWidth(int nColumn, int nWidth) + { + if (nColumn < 0 || nColumn >= GetColumnCount()) + return FALSE; - if ( strItemText.empty() ) - { - HideTitleTip(); - return FALSE; - } - - ClientToScreen( rcItemText ); - if ( !m_wndTitleTip.Show( rcItemText, strItemText.c_str(), pT->GetItemToolTip( nItem, nIndex ).c_str() ) ) - { - HideTitleTip(); - return FALSE; - } - - m_nTitleTipItem = nItem; - m_nTitleTipSubItem = nSubItem; - - return TRUE; - } - - BOOL HideTitleTip( BOOL bResetItem = TRUE ) - { - if ( bResetItem ) - { - m_nTitleTipItem = NULL_ITEM; - m_nTitleTipSubItem = NULL_SUBITEM; - } - return m_wndTitleTip.Hide(); - } - - BEGIN_MSG_MAP_EX(CListImpl) - MSG_WM_CREATE(OnCreate) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_KILLFOCUS(OnKillFocus) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_SIZE(OnSize) - MSG_WM_HSCROLL(OnHScroll) - MSG_WM_VSCROLL(OnVScroll) - MSG_WM_CANCELMODE(OnCancelMode) - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST,WM_MOUSELAST,OnMouseRange) - MSG_WM_LBUTTONDOWN(OnLButtonDown) - MSG_WM_LBUTTONUP(OnLButtonUp) - MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) - MSG_WM_RBUTTONDOWN(OnRButtonDown) - MSG_WM_RBUTTONUP(OnRButtonUp) - MSG_WM_MOUSEMOVE(OnMouseMove) -#if(_WIN32_WINNT >= 0x0400) - MSG_WM_MOUSELEAVE(OnMouseLeave) - MSG_WM_MOUSEWHEEL(OnMouseWheel) + // Set new column size if not fixed + if (!m_aColumns[nColumn].m_bFixed) + { + m_aColumns[nColumn].m_nWidth = nWidth; + + ResetScrollBars(); + Invalidate(); + } + + return TRUE; + } + + int GetColumnWidth(int nColumn) + { + CListColumn listColumn; + return GetColumn(nColumn, listColumn) ? listColumn.m_nWidth : 0; + } + + int GetColumnIndex(int nColumn) + { + CListColumn listColumn; + return GetColumn(nColumn, listColumn) ? listColumn.m_nIndex : 0; + } + + int IndexToOrder(int nIndex) + { + for (int nColumn = 0; nColumn < GetColumnCount(); nColumn++) + { + if (GetColumnIndex(nColumn) == nIndex) + return nColumn; + } + return -1; + } + + BOOL SetColumnFormat(int nColumn, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE) + { + if (nColumn < 0 || nColumn >= GetColumnCount()) + return FALSE; + m_aColumns[nColumn].m_nFormat = nFormat; + m_aColumns[nColumn].m_nFlags = ValidateFlags(nFlags); + return TRUE; + } + + BOOL SetColumnFormat(int nColumn, UINT nFormat, UINT nFlags, CListArray & aComboList) + { + if (nColumn < 0 || nColumn >= GetColumnCount()) + return FALSE; + m_aColumns[nColumn].m_nFormat = nFormat; + m_aColumns[nColumn].m_nFlags = ValidateFlags(nFlags); + m_aColumns[nColumn].m_aComboList = aComboList; + return TRUE; + } + + UINT GetColumnFormat(int nColumn) + { + CListColumn listColumn; + return GetColumn(nColumn, listColumn) ? listColumn.m_nFormat : ITEM_FORMAT_NONE; + } + + UINT GetColumnFlags(int nColumn) + { + CListColumn listColumn; + return GetColumn(nColumn, listColumn) ? listColumn.m_nFlags : ITEM_FLAGS_NONE; + } + + BOOL GetColumnComboList(int nColumn, CListArray & aComboList) + { + CListColumn listColumn; + if (!GetColumn(nColumn, listColumn)) + return FALSE; + aComboList = listColumn.m_aComboList; + return !aComboList.IsEmpty(); + } + + BOOL GetColumnRect(int nColumn, CRect & rcColumn) + { + if (nColumn < 0 || nColumn >= GetColumnCount()) + return FALSE; + + GetClientRect(rcColumn); + rcColumn.bottom = m_nHeaderHeight; + + for (int nColumnOrder = 0; nColumnOrder < GetColumnCount(); nColumnOrder++) + { + int nWidth = GetColumnWidth(nColumnOrder); + + if (nColumn == nColumnOrder) + { + rcColumn.right = rcColumn.left + nWidth; + break; + } + + rcColumn.left += nWidth; + } + + // Offset column by scroll position + rcColumn.OffsetRect(-GetScrollPos(SB_HORZ), 0); + + return TRUE; + } + + BOOL AddItem() + { + ResetScrollBars(); + return Invalidate(); + } + + BOOL DeleteItem(int nItem) + { + m_setSelectedItems.erase(nItem); + ResetScrollBars(); + return Invalidate(); + } + + BOOL DeleteAllItems() + { + m_setSelectedItems.clear(); + ResetScrollBars(); + return Invalidate(); + } + + int GetItemCount() + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return 0; + } + + stdstr GetItemText(int nItem, int nSubItem) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return _T( "" ); + } + + BOOL GetItemDate(int nItem, int nSubItem, SYSTEMTIME & stItemDate) + { + T * pT = static_cast(this); + + ZeroMemory(&stItemDate, sizeof(SYSTEMTIME)); + + stdstr strItemText = pT->GetItemText(nItem, nSubItem); + if (strItemText.empty()) + return FALSE; + + // Get date and time from item text: yyyymmddhhmmss + stItemDate.wYear = (WORD)_ttoi(strItemText.substr(0, 4).c_str()); + stItemDate.wMonth = (WORD)_ttoi(strItemText.substr(4, 2).c_str()); + stItemDate.wDay = (WORD)_ttoi(strItemText.substr(6, 2).c_str()); + stItemDate.wHour = (WORD)_ttoi(strItemText.substr(8, 2).c_str()); + stItemDate.wMinute = (WORD)_ttoi(strItemText.substr(10, 2).c_str()); + stItemDate.wSecond = (WORD)_ttoi(strItemText.substr(12, 2).c_str()); + stItemDate.wMilliseconds = 0; + + return TRUE; + } + + int GetItemImage(int nItem, int nSubItem) + { + return ITEM_IMAGE_NONE; // May be implemented in a derived class + } + + UINT GetItemFormat(int nItem, int nSubItem) + { + return GetColumnFormat(IndexToOrder(nSubItem)); // May be implemented in a derived class + } + + UINT GetItemFlags(int nItem, int nSubItem) + { + return GetColumnFlags(IndexToOrder(nSubItem)); // May be implemented in a derived class + } + + BOOL GetItemComboList(int nItem, int nSubItem, CListArray & aComboList) + { + return GetColumnComboList(IndexToOrder(nSubItem), aComboList); // May be implemented in a derived class + } + + HFONT GetItemFont(int /*nItem*/, int /*nSubItem*/) + { + return m_fntListFont; // May be implemented in a derived class + } + + BOOL GetItemColours(int nItem, int nSubItem, COLORREF & rgbBackground, COLORREF & rgbText) + { + rgbBackground = m_rgbBackground; + rgbText = m_rgbItemText; + return TRUE; + } + + stdstr virtual GetItemToolTip(int /*nItem*/, int /*nSubItem*/) + { + return _T( "" ); // May be implemented in a derived class + } + stdstr virtual GetHeaderToolTip(int /*column*/) + { + return _T(""); // Implemented by child class + } + + BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemComboIndex(int nItem, int nSubItem, int nIndex) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemDate(int nItem, int nSubItem, SYSTEMTIME & stItemDate) + { + T * pT = static_cast(this); + + // Set date and time in format (yyyymmddhhmmss) + stdstr strFormatDate; + strFormatDate.Format(_T( "%04d%02d%02d%02d%02d%02d" ), stItemDate.wYear, stItemDate.wMonth, stItemDate.wDay, stItemDate.wHour, stItemDate.wMinute, stItemDate.wSecond); + + return pT->SetItemText(nItem, nSubItem, strFormatDate.c_str()); + } + + BOOL SetItemCheck(int nItem, int nSubItem, int nCheckValue) + { + T * pT = static_cast(this); + + switch (pT->GetItemFormat(nItem, nSubItem)) + { + case ITEM_FORMAT_CHECKBOX: return pT->SetItemText(nItem, nSubItem, nCheckValue > 0 ? _T( "1" ) : _T( "0" )); + case ITEM_FORMAT_CHECKBOX_3STATE: + if (nCheckValue < 0) + return pT->SetItemText(nItem, nSubItem, _T( "-1" )); + if (nCheckValue > 0) + return pT->SetItemText(nItem, nSubItem, _T( "1" )); + return pT->SetItemText(nItem, nSubItem, _T( "0" )); + } + + return FALSE; + } + + BOOL SetItemImage(int nItem, int nSubItem, int nImage) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemFormat(int nItem, int nSubItem, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemFormat(int nItem, int nSubItem, UINT nFormat, UINT nFlags, CListArray & aComboList) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemFont(int nItem, int nSubItem, HFONT hFont) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL SetItemColours(int nItem, int nSubItem, COLORREF rgbBackground, COLORREF rgbText) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + void ReverseItems() + { + ATLASSERT(FALSE); // Must be implemented in a derived class + } + + void SortItems(int nColumn, BOOL bAscending) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + } + + BOOL GetItemRect(int nItem, int nSubItem, CRect & rcItem) + { + T * pT = static_cast(this); + + int nTopItem = GetTopItem(); + if (nItem < nTopItem || nItem >= pT->GetItemCount() || nItem >= nTopItem + GetCountPerPage()) + return FALSE; + + CRect rcClient; + GetClientRect(rcClient); + + // Calculate item rect based on scroll position + rcItem = rcClient; + rcItem.top = (m_bShowHeader ? m_nHeaderHeight : 0) + ((nItem - nTopItem) * m_nItemHeight); + rcItem.bottom = rcItem.top + m_nItemHeight; + rcItem.right = min(rcClient.right, GetTotalWidth()); + + if (nSubItem != NULL_SUBITEM) + { + CRect rcColumn; + if (!GetColumnRect(nSubItem, rcColumn)) + return FALSE; + + rcItem.left = rcColumn.left; + rcItem.right = rcColumn.right; + } + + return TRUE; + } + + BOOL GetItemRect(int nItem, CRect & rcItem) + { + return GetItemRect(nItem, NULL_SUBITEM, rcItem); + } + + BOOL InvalidateItem(int nItem, int nSubItem = NULL_SUBITEM) + { + CRect rcItem; + return GetItemRect(nItem, nSubItem, rcItem) ? InvalidateRect(rcItem) : FALSE; + } + + BOOL InvalidateHeader() + { + if (!m_bShowHeader) + return TRUE; + CRect rcHeader; + if (!GetClientRect(rcHeader)) + return FALSE; + rcHeader.bottom = m_nHeaderHeight; + return InvalidateRect(rcHeader); + } + + int GetTopItem() + { + return (int)(GetScrollPos(SB_VERT) / m_nItemHeight); + } + + int GetCountPerPage(BOOL bPartial = TRUE) + { + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + // Calculate number of items per control height (include partial item) + div_t divHeight = div(rcClient.Height(), m_nItemHeight); + + // Round up to nearest item count + return max(bPartial && divHeight.rem > 0 ? divHeight.quot + 1 : divHeight.quot, 1); + } + + BOOL IsItemVisible(int nItem, int nSubItem = NULL_SUBITEM, BOOL bPartial = TRUE) + { + T * pT = static_cast(this); + + int nTopItem = GetTopItem(); + if (nItem < nTopItem || nItem >= pT->GetItemCount()) + return FALSE; + + // Check whether item is visible + if (nItem < nTopItem || nItem >= nTopItem + GetCountPerPage(bPartial)) + return FALSE; + + // Check whether subitem is visible + if (m_bFocusSubItem && nSubItem != NULL_SUBITEM) + { + CRect rcColumn; + if (!GetColumnRect(nSubItem, rcColumn)) + return FALSE; + + CRect rcClient; + GetClientRect(rcClient); + + if (rcColumn.left < rcClient.left || rcColumn.right > rcClient.right) + return FALSE; + } + + return TRUE; + } + + BOOL EnsureItemVisible(int nItem, int nSubItem = NULL_SUBITEM) + { + if (IsItemVisible(nItem, nSubItem, FALSE)) + return TRUE; + + HideTitleTip(); + + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + CRect rcItem; + rcItem.top = (m_bShowHeader ? m_nHeaderHeight : 0) + ((nItem - GetTopItem()) * m_nItemHeight); + rcItem.bottom = rcItem.top + m_nItemHeight; + + if (rcItem.top < rcClient.top || rcItem.bottom > rcClient.bottom) + { + int nScrollItem = NULL_ITEM; + + // Scroll list up/down to include item + if (rcItem.top < rcClient.top || rcItem.Height() > rcClient.Height()) + nScrollItem = nItem; + else if (rcItem.bottom > rcClient.bottom) + nScrollItem = nItem - (GetCountPerPage(FALSE) - 1); + + if (nScrollItem != NULL_ITEM) + SetScrollPos(SB_VERT, nScrollItem * m_nItemHeight); + } + + if (m_bFocusSubItem && nSubItem != NULL_SUBITEM) + { + CRect rcColumn; + if (!GetColumnRect(nSubItem, rcColumn)) + return FALSE; + + GetClientRect(rcClient); + + int nScrollPos = 0; + + // Scroll list left/right to include subitem + if (rcColumn.Width() > rcClient.Width() || rcColumn.left < 0) + nScrollPos = rcColumn.left; + else if (rcColumn.right > rcClient.right) + nScrollPos = rcColumn.right - rcClient.right; + + if (nScrollPos != 0) + SetScrollPos(SB_HORZ, GetScrollPos(SB_HORZ) + nScrollPos); + } + + return Invalidate(); + } + + void ShowScrollBar(int nScrollBar, BOOL bShow = TRUE) + { + switch (nScrollBar) + { + case SB_HORZ: + m_bShowHorizScroll = bShow; + break; + case SB_VERT: + m_bShowVertScroll = bShow; + break; + case SB_BOTH: + m_bShowHorizScroll = bShow; + m_bShowVertScroll = bShow; + break; + } + + ResetScrollBars(); + Invalidate(); + } + + void ResetScrollBars(int nScrollBar = SB_BOTH, int nScrollPos = -1, BOOL bRecalc = TRUE) + { + T * pT = static_cast(this); + + CRect rcClient; + GetClientRect(rcClient); + + SCROLLINFO infoScroll; + infoScroll.cbSize = sizeof(SCROLLINFO); + infoScroll.fMask = nScrollPos < 0 ? SIF_PAGE | SIF_RANGE : SIF_PAGE | SIF_RANGE | SIF_POS; + infoScroll.nPos = nScrollPos; + infoScroll.nMin = 0; + + if ((nScrollBar == SB_BOTH || nScrollBar == SB_VERT) && m_bShowVertScroll) + { + infoScroll.nMax = (pT->GetItemCount() * m_nItemHeight) + (m_bShowHeader ? m_nHeaderHeight : 0); + infoScroll.nPage = rcClient.Height() - (m_bShowHeader ? m_nHeaderHeight : 0); + + // Are we within client range? + if ((UINT)infoScroll.nMax <= infoScroll.nPage + (m_bShowHeader ? m_nHeaderHeight : 0)) + infoScroll.nMax = 0; + + // Set vertical scroll bar + m_bEnableVertScroll = SetScrollInfo(SB_VERT, &infoScroll, TRUE) ? (infoScroll.nMax > 0) : FALSE; + } + + if ((nScrollBar == SB_BOTH || nScrollBar == SB_HORZ) && m_bShowHorizScroll) + { + infoScroll.nMax = GetTotalWidth(bRecalc); + infoScroll.nPage = rcClient.Width(); + + // Are we within client range? + if (infoScroll.nPage >= (UINT)infoScroll.nMax) + infoScroll.nMax = 0; + + // Set horizontal scroll bar + m_bEnableHorizScroll = SetScrollInfo(SB_HORZ, &infoScroll, TRUE) ? (infoScroll.nMax > (int)infoScroll.nPage) : FALSE; + } + } + + BOOL IsScrollBarVisible(int nScrollBar) + { + switch (nScrollBar) + { + case SB_HORZ: return m_bEnableHorizScroll; + case SB_VERT: return m_bEnableVertScroll; + case SB_BOTH: return (m_bEnableHorizScroll && m_bEnableVertScroll); + default: return FALSE; + } + } + + BOOL ResetSelected() + { + m_setSelectedItems.clear(); + m_nFocusItem = NULL_ITEM; + m_nFocusSubItem = NULL_SUBITEM; + m_nFirstSelected = NULL_ITEM; + return Invalidate(); + } + + BOOL SelectItem(int nItem, int nSubItem = NULL_SUBITEM, UINT nFlags = 0) + { + T * pT = static_cast(this); + + if (nItem < 0 || nItem >= pT->GetItemCount()) + return FALSE; + + BOOL bSelectItem = TRUE; + BOOL bSelectRange = !m_bSingleSelect && (nFlags & MK_SHIFT); + BOOL bNewSelect = !(bSelectRange || (nFlags & MK_CONTROL)); + BOOL bEnsureVisible = FALSE; + + // Are we starting a new select sequence? + if (bNewSelect || bSelectRange) + { + // Are we simply reselecting the same item? + if (m_setSelectedItems.size() == 1 && *m_setSelectedItems.begin() == nItem) + { + bSelectItem = FALSE; + m_nFirstSelected = nItem; + m_nFocusItem = nItem; + m_nFocusSubItem = nSubItem; + } + else + m_setSelectedItems.clear(); + } + else // We adding to or removing from select sequence + { + if (m_bSingleSelect) + m_setSelectedItems.clear(); + + set::iterator posSelectedItem = m_setSelectedItems.find(nItem); + + // Is this item already selected? + if (posSelectedItem != m_setSelectedItems.end()) + { + bSelectItem = FALSE; + m_setSelectedItems.erase(posSelectedItem); + m_nFirstSelected = nItem; + m_nFocusItem = nItem; + m_nFocusSubItem = m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem; + } + } + + // Are we adding this item to the select sequence? + if (bSelectItem) + { + bEnsureVisible = TRUE; + + if (bSelectRange) + { + if (m_nFirstSelected == NULL_ITEM) + m_nFirstSelected = nItem; + + for (int nSelectedItem = min(m_nFirstSelected, nItem); nSelectedItem <= max(m_nFirstSelected, nItem); nSelectedItem++) + m_setSelectedItems.insert(nSelectedItem); + } + else + { + m_nFirstSelected = nItem; + m_setSelectedItems.insert(nItem); + } + + m_nFocusItem = nItem; + m_nFocusSubItem = m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem; + + // Notify parent of selected item + NotifyParent(m_nFocusItem, m_nFocusSubItem, LCN_SELECTED); + } + + // Start visible timer (scrolls list to partially hidden item) + if (!IsItemVisible(nItem, m_setSelectedItems.size() > 1 ? NULL_SUBITEM : nSubItem, FALSE)) + SetTimer(ITEM_VISIBLE_TIMER, ITEM_VISIBLE_PERIOD); + else if (m_nFocusItem != NULL_ITEM && m_nFocusSubItem != NULL_SUBITEM) + EditItem(m_nFocusItem, m_nFocusSubItem); + + return Invalidate(); + } + + BOOL IsSelected(int nItem) + { + set::iterator posSelectedItem = m_setSelectedItems.find(nItem); + return (posSelectedItem != m_setSelectedItems.end()); + } + + BOOL GetSelectedItems(CListArray & aSelectedItems) + { + aSelectedItems.RemoveAll(); + for (set::iterator posSelectedItem = m_setSelectedItems.begin(); posSelectedItem != m_setSelectedItems.end(); ++posSelectedItem) + aSelectedItems.Add(*posSelectedItem); + return !aSelectedItems.IsEmpty(); + } + + BOOL SetFocusItem(int nItem, int nSubItem = NULL_SUBITEM) + { + m_nFocusItem = nItem; + m_nFocusSubItem = nSubItem; + return EnsureItemVisible(m_nFocusItem, m_nFocusSubItem); + } + + BOOL GetFocusItem(int & nItem, int & nSubItem) + { + nItem = IsSelected(m_nFocusItem) ? m_nFocusItem : (m_setSelectedItems.empty() ? NULL_ITEM : *m_setSelectedItems.begin()); + nSubItem = !m_bFocusSubItem || nItem == NULL_ITEM ? NULL_SUBITEM : m_nFocusSubItem; + return (nItem != NULL_ITEM); + } + + int GetFocusItem() + { + return IsSelected(m_nFocusItem) ? m_nFocusItem : (m_setSelectedItems.empty() ? NULL_ITEM : *m_setSelectedItems.begin()); + } + + BOOL HitTestHeader(CPoint point, int & nColumn, UINT & nFlags) + { + // Reset hit test flags + nFlags = HITTEST_FLAG_NONE; + + if (!m_bShowHeader) + return FALSE; + + CRect rcClient; + if (!GetClientRect(rcClient)) + return FALSE; + + // Are we over the header? + if (point.y < rcClient.top || point.y > m_nHeaderHeight) + return FALSE; + + int nDividerPos = 0; + int nColumnCount = GetColumnCount(); + + // Get hit test subitem + for (nColumn = 0; nColumn < nColumnCount; nColumn++) + { + int nColumnWidth = GetColumnWidth(nColumn); + nDividerPos += nColumnWidth; + + // Offset divider position with current scroll position + int nRelativePos = nDividerPos - GetScrollPos(SB_HORZ); + + // Are we over the divider zone? + if (point.x >= nRelativePos - DRAG_HEADER_OFFSET - 1 && point.x <= nRelativePos + DRAG_HEADER_OFFSET) + { + nFlags |= HITTEST_FLAG_HEADER_DIVIDER; + + // Are we to the left of the divider (or over last column divider)? + if ((point.x >= nRelativePos - DRAG_HEADER_OFFSET - 1 && point.x < nRelativePos) || nColumn + 1 >= nColumnCount - 1) + { + nFlags |= HITTEST_FLAG_HEADER_LEFT; + return TRUE; + } + + // Find last zero-length column after this column + for (int nNextColumn = nColumn + 1; nNextColumn < nColumnCount; nNextColumn++) + { + if (GetColumnWidth(nNextColumn) > 0) + break; + nColumn = nNextColumn; + } + + nFlags |= HITTEST_FLAG_HEADER_RIGHT; + + return TRUE; + } + + // Are we over a column? + if (point.x > nRelativePos - nColumnWidth && point.x < nRelativePos) + return TRUE; + } + + return FALSE; + } + + BOOL HitTest(CPoint point, int & nItem, int & nSubItem) + { + T * pT = static_cast(this); + + // Are we over the header? + if (point.y < (m_bShowHeader ? m_nHeaderHeight : 0)) + return FALSE; + + // Calculate hit test item + nItem = GetTopItem() + (int)((point.y - (m_bShowHeader ? m_nHeaderHeight : 0)) / m_nItemHeight); + + if (nItem < 0 || nItem >= pT->GetItemCount()) + return FALSE; + + int nTotalWidth = 0; + int nColumnCount = GetColumnCount(); + + // Get hit test subitem + for (nSubItem = 0; nSubItem < nColumnCount; nSubItem++) + { + int nColumnWidth = GetColumnWidth(nSubItem); + nTotalWidth += nColumnWidth; + + // Offset position with current scroll position + int nRelativePos = nTotalWidth - GetScrollPos(SB_HORZ); + + // Are we over a subitem? + if (point.x > nRelativePos - nColumnWidth && point.x < nRelativePos) + return TRUE; + } + + return FALSE; + } + + BOOL AutoSizeColumn(int nColumn) + { + T * pT = static_cast(this); + + CListColumn listColumn; + if (!GetColumn(nColumn, listColumn) || listColumn.m_bFixed) + return FALSE; + + CClientDC dcClient(m_hWnd); + HFONT hOldFont = dcClient.SelectFont(m_fntListFont); + + // Set to column text width if zero-length + CSize sizeExtent; + if (!dcClient.GetTextExtent(listColumn.m_strText.c_str(), -1, &sizeExtent)) + return FALSE; + + int nMaxWidth = sizeExtent.cx + ITEM_WIDTH_MARGIN; + + CSize sizeIcon = 0; + if (!m_ilItemImages.IsNull()) + m_ilItemImages.GetIconSize(sizeIcon); + + // Calculate maximum column width required + for (int nItem = 0; nItem < pT->GetItemCount(); nItem++) + { + if (!dcClient.GetTextExtent(pT->GetItemText(nItem, listColumn.m_nIndex), -1, &sizeExtent)) + return FALSE; + + if (!m_ilItemImages.IsNull() && pT->GetItemImage(nItem, listColumn.m_nIndex) != ITEM_IMAGE_NONE) + sizeExtent.cx += sizeIcon.cx; + + nMaxWidth = max(nMaxWidth, (int)sizeExtent.cx + ITEM_WIDTH_MARGIN); + } + + dcClient.SelectFont(hOldFont); + + return SetColumnWidth(nColumn, nMaxWidth); + } + + void ResizeColumn(BOOL bColumnScroll = FALSE) + { + HideTitleTip(); + + int nCurrentPos = GET_X_LPARAM(GetMessagePos()); + + CRect rcClient; + GetClientRect(rcClient); + int nScrollLimit = GetTotalWidth() - rcClient.Width(); + + if (bColumnScroll) + { + // Have we finished scrolling list to accommodate new column size? + if (!m_bColumnSizing || !m_bEnableHorizScroll || nCurrentPos - m_nStartScrollPos > 0) + { + KillTimer(RESIZE_COLUMN_TIMER); + + // Reset resize start point + m_nStartPos = nCurrentPos; + m_bResizeTimer = FALSE; + } + else if (nCurrentPos < m_nStartPos && GetScrollPos(SB_HORZ) >= nScrollLimit) + { + // Reset start column size + m_nStartSize = max(GetColumnWidth(m_nColumnSizing) + (nCurrentPos - m_nStartScrollPos), 0); + + // Resize column + SetColumnWidth(m_nColumnSizing, m_nStartSize); + } + } + else + { + int nColumnSize = max(m_nStartSize + (nCurrentPos - m_nStartPos), 0); + + // Are we scrolled fully to the right and wanting to reduce the size of a column? + if (m_bEnableHorizScroll && GetScrollPos(SB_HORZ) >= nScrollLimit && nColumnSize < GetColumnWidth(m_nColumnSizing)) + { + if (!m_bResizeTimer) + { + // Only start the scroll timer once + m_bResizeTimer = TRUE; + + // Set new start scroll position + m_nStartScrollPos = nCurrentPos; + + // Start column resize / scroll timer + SetTimer(RESIZE_COLUMN_TIMER, RESIZE_COLUMN_PERIOD); + } + } + else + { + // Resizing is done in scroll timer (if started) + if (!m_bResizeTimer) + SetColumnWidth(m_nColumnSizing, nColumnSize); + } + } + } + + void DragColumn() + { + HideTitleTip(); + + CRect rcColumn; + if (!GetColumnRect(m_nHighlightColumn, rcColumn)) + return; + + CRect rcHeaderItem(rcColumn); + rcHeaderItem.MoveToXY(0, 0); + + CListColumn listColumn; + if (!GetColumn(m_nHighlightColumn, listColumn)) + return; + + // Store drag column + m_nDragColumn = m_nHighlightColumn; + + CClientDC dcClient(m_hWnd); + + CDC dcHeader; + dcHeader.CreateCompatibleDC(dcClient); + + int nContextState = dcHeader.SaveDC(); + + // Create drag header bitmap + CBitmapHandle bmpHeader; + bmpHeader.CreateCompatibleBitmap(dcClient, rcHeaderItem.Width(), rcHeaderItem.Height()); + dcHeader.SelectBitmap(bmpHeader); + + dcHeader.SetBkColor(m_rgbHeaderBackground); + dcHeader.ExtTextOut(rcHeaderItem.left, rcHeaderItem.top, ETO_OPAQUE, rcHeaderItem, _T( "" ), 0, nullptr); + dcHeader.Draw3dRect(rcHeaderItem, m_rgbHeaderBorder, m_rgbHeaderShadow); + + CRect rcHeaderText(rcHeaderItem); + rcHeaderText.left += m_nHighlightColumn == 0 ? 4 : 3; + rcHeaderText.OffsetRect(0, 1); + + // Margin header text + rcHeaderText.DeflateRect(4, 0, 5, 0); + + // Has this header item an associated image? + if (listColumn.m_nImage != ITEM_IMAGE_NONE) + { + CSize sizeIcon; + m_ilListItems.GetIconSize(sizeIcon); + + CRect rcHeaderImage; + rcHeaderImage.left = listColumn.m_strText.empty() ? ((rcHeaderText.left + rcHeaderText.right) / 2) - (sizeIcon.cx / 2) - (0) : rcHeaderText.left; + rcHeaderImage.right = min(rcHeaderImage.left + sizeIcon.cx, rcHeaderItem.right); + rcHeaderImage.top = ((rcHeaderItem.top + rcHeaderItem.bottom) / 2) - (sizeIcon.cy / 2); + rcHeaderImage.bottom = min(rcHeaderImage.top + sizeIcon.cy, rcHeaderItem.bottom); + + m_ilListItems.DrawEx(listColumn.m_nImage, dcHeader, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + + // Offset header text (for image) + rcHeaderText.left += sizeIcon.cx + 4; + } + + dcHeader.SelectFont(m_fntListFont); + dcHeader.SetTextColor(m_rgbHeaderText); + dcHeader.SetBkMode(TRANSPARENT); + + UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + + if (listColumn.m_nFlags & ITEM_FLAGS_CENTRE) + nFormat |= DT_CENTER; + else if (listColumn.m_nFlags & ITEM_FLAGS_RIGHT) + nFormat |= DT_RIGHT; + else + nFormat |= DT_LEFT; + + // Draw header text + if (!listColumn.m_strText.empty()) + dcHeader.DrawText(listColumn.m_strText.c_str(), (int)listColumn.m_strText.length(), rcHeaderText, nFormat); + + dcHeader.RestoreDC(nContextState); + + SHDRAGIMAGE shDragImage; + ZeroMemory(&shDragImage, sizeof(SHDRAGIMAGE)); + + shDragImage.sizeDragImage.cx = rcHeaderItem.Width(); + shDragImage.sizeDragImage.cy = rcHeaderItem.Height(); + shDragImage.ptOffset.x = rcColumn.Width() / 2; + shDragImage.ptOffset.y = rcColumn.Height() / 2; + shDragImage.hbmpDragImage = bmpHeader; + shDragImage.crColorKey = m_rgbBackground; + + // Start header drag operation + m_oleDragDrop.DoDragDrop(&shDragImage, DROPEFFECT_MOVE); + + // Hide drop arrows after moving column + m_wndDropArrows.Hide(); + + if (m_bButtonDown) + { + ReleaseCapture(); + m_bButtonDown = FALSE; + m_bBeginSelect = FALSE; + m_ptDownPoint = 0; + m_ptSelectPoint = 0; + } + + // Finish moving a column + if (m_nHighlightColumn != NULL_COLUMN) + { + m_nHighlightColumn = NULL_COLUMN; + InvalidateHeader(); + } + + m_nDragColumn = NULL_COLUMN; + } + + BOOL DropColumn(CPoint point) + { + if (!m_bShowHeader) + return FALSE; + + m_nHotDivider = NULL_COLUMN; + m_nHotColumn = NULL_COLUMN; + UINT nHeaderFlags = HITTEST_FLAG_NONE; + + // Are we over the header? + if (HitTestHeader(point, m_nHotColumn, nHeaderFlags)) + { + CRect rcColumn; + if (!GetColumnRect(m_nHotColumn, rcColumn)) + return FALSE; + m_nHotDivider = point.x < ((rcColumn.left + rcColumn.right) / 2) ? m_nHotColumn : m_nHotColumn + 1; + + if (m_nHotDivider == m_nDragColumn || m_nHotDivider == m_nDragColumn + 1) + m_nHotDivider = NULL_COLUMN; + } + + if (m_nHotDivider != NULL_COLUMN) + { + CRect rcHeader; + GetClientRect(rcHeader); + rcHeader.bottom = m_nHeaderHeight; + + CPoint ptDivider(0, rcHeader.Height() / 2); + + CRect rcColumn; + int nColumnCount = GetColumnCount(); + + // Set closest divider position + if (GetColumnRect(m_nHotDivider < nColumnCount ? m_nHotDivider : nColumnCount - 1, rcColumn)) + ptDivider.x = m_nHotDivider < nColumnCount ? rcColumn.left : rcColumn.right; + + ClientToScreen(&ptDivider); + + // Track drop window + m_wndDropArrows.Show(ptDivider); + return TRUE; + } + + m_wndDropArrows.Hide(); + + return FALSE; + } + + BOOL SortColumn(int nColumn) + { + T * pT = static_cast(this); + + if (!m_bShowHeader || !m_bShowSort) + return FALSE; + + int nSortIndex = GetColumnIndex(nColumn); + + CWaitCursor curWait; + + if (nSortIndex != m_nSortColumn) + { + // Sort by new column + m_bSortAscending = TRUE; + m_nSortColumn = nSortIndex; + pT->SortItems(m_nSortColumn, m_bSortAscending); + } + else + { + // Toggle sort order if sorting same column + m_bSortAscending = !m_bSortAscending; + pT->ReverseItems(); + } + + return ResetSelected(); + } + + BOOL GetSortColumn(int & nColumn, BOOL & bAscending) + { + if (!m_bShowHeader || !m_bShowSort || m_nSortColumn == NULL_COLUMN) + return FALSE; + nColumn = m_nSortColumn; + bAscending = m_bSortAscending; + return TRUE; + } + + BOOL DragItem() + { + ATLASSERT(FALSE); // Must be implemented in a derived class + return FALSE; + } + + BOOL GroupSelect(CPoint point) + { + HideTitleTip(); + + int nHorzScroll = GetScrollPos(SB_HORZ); + int nVertScroll = GetScrollPos(SB_VERT); + + m_rcGroupSelect.left = min(m_ptSelectPoint.x, point.x + nHorzScroll); + m_rcGroupSelect.right = max(m_ptSelectPoint.x, point.x + nHorzScroll); + m_rcGroupSelect.top = min(m_ptSelectPoint.y, point.y + nVertScroll); + m_rcGroupSelect.bottom = max(m_ptSelectPoint.y, point.y + nVertScroll); + + if (m_rcGroupSelect.IsRectEmpty()) + return FALSE; + + // Select items in group + AutoSelect(point); + + // Start auto scroll timer + SetTimer(ITEM_AUTOSCROLL_TIMER, ITEM_SCROLL_PERIOD); + + DWORD dwCurrentTick = GetTickCount(); + + // Timer messages are a low priority, therefore we need to simulate the timer when moving the mouse + if ((dwCurrentTick - m_dwScrollTick) > ITEM_SCROLL_PERIOD - 10) + { + if (AutoScroll(point)) + m_dwScrollTick = dwCurrentTick; + } + + // Redraw list immediately + return RedrawWindow(); + } + + void AutoSelect(CPoint /*point*/) + { + m_setSelectedItems.clear(); + + if (m_rcGroupSelect.left < GetTotalWidth()) + { + int nHorzScroll = GetScrollPos(SB_HORZ); + int nVertScroll = GetScrollPos(SB_VERT); + + CRect rcGroupSelect(m_rcGroupSelect); + rcGroupSelect.OffsetRect(-nHorzScroll, -nVertScroll); + + int nTopItem = GetTopItem(); + int nLastItem = nTopItem + ((rcGroupSelect.bottom - (m_bShowHeader ? m_nHeaderHeight : 0)) / m_nItemHeight); + nTopItem += ((rcGroupSelect.top - (m_bShowHeader ? m_nHeaderHeight : 0)) / m_nItemHeight) - ((rcGroupSelect.top < 0) ? 1 : 0); + + for (int nItem = nTopItem; nItem <= nLastItem; nItem++) + { + if (m_setSelectedItems.empty()) + m_nFirstSelected = nItem; + m_setSelectedItems.insert(nItem); + + m_nFocusItem = nItem; + m_nFocusSubItem = NULL_SUBITEM; + } + } + + if (m_setSelectedItems.empty()) + m_nFirstSelected = NULL_ITEM; + } + + BOOL AutoScroll(CPoint point) + { + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + int nHorzScroll = GetScrollPos(SB_HORZ); + int nVertScroll = GetScrollPos(SB_VERT); + + BOOL bAutoScroll = FALSE; + + if (point.y < rcClient.top) + { + SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0)); + int nAutoScroll = GetScrollPos(SB_VERT); + if (nVertScroll != nAutoScroll) + { + m_rcGroupSelect.top = rcClient.top + nAutoScroll - 1; + m_rcGroupSelect.bottom = max(m_ptSelectPoint.y, point.y + nAutoScroll - 1); + bAutoScroll = TRUE; + } + } + if (point.y > rcClient.bottom) + { + SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0)); + int nAutoScroll = GetScrollPos(SB_VERT); + if (nVertScroll != nAutoScroll) + { + m_rcGroupSelect.top = min(m_ptSelectPoint.y, point.y + nAutoScroll + 1); + m_rcGroupSelect.bottom = rcClient.bottom + nAutoScroll + 1; + bAutoScroll = TRUE; + } + } + if (point.x < rcClient.left) + { + SendMessage(WM_HSCROLL, MAKEWPARAM(SB_LINELEFT, 0)); + int nAutoScroll = GetScrollPos(SB_HORZ); + if (nHorzScroll != nAutoScroll) + { + m_rcGroupSelect.left = rcClient.left + nAutoScroll - 1; + m_rcGroupSelect.right = max(m_ptSelectPoint.x, point.x + nAutoScroll - 1); + bAutoScroll = TRUE; + } + } + if (point.x > rcClient.right) + { + SendMessage(WM_HSCROLL, MAKEWPARAM(SB_LINERIGHT, 0)); + int nAutoScroll = GetScrollPos(SB_HORZ); + if (nHorzScroll != nAutoScroll) + { + m_rcGroupSelect.left = min(m_ptSelectPoint.x, point.x + nAutoScroll + 1); + m_rcGroupSelect.right = rcClient.right + nAutoScroll + 1; + bAutoScroll = TRUE; + } + } + + // Was the scrolling performed? + return bAutoScroll; + } + + BOOL BeginScroll(int nBeginItem, int nEndItem) + { + T * pT = static_cast(this); + + // Any scroll required? + if (nBeginItem == nEndItem) + return FALSE; + + // Calculate scroll offset + m_nScrollOffset = abs(nEndItem - nBeginItem) * m_nItemHeight; + m_nScrollUnit = min(max(m_nScrollOffset / m_nItemHeight, ITEM_SCROLL_UNIT_MIN), ITEM_SCROLL_UNIT_MAX); + m_nScrollDelta = (m_nScrollOffset - m_nScrollUnit) / m_nScrollUnit; + m_bScrollDown = (nBeginItem < nEndItem); + + CClientDC dcClient(m_hWnd); + + CDC dcScrollList; + dcScrollList.CreateCompatibleDC(dcClient); + + int nContextState = dcScrollList.SaveDC(); + + CRect rcScrollList; + GetClientRect(rcScrollList); + rcScrollList.bottom = (GetCountPerPage() + abs(nEndItem - nBeginItem)) * m_nItemHeight; + + if (!m_bmpScrollList.IsNull()) + m_bmpScrollList.DeleteObject(); + m_bmpScrollList.CreateCompatibleBitmap(dcClient, rcScrollList.Width(), rcScrollList.Height()); + dcScrollList.SelectBitmap(m_bmpScrollList); + + pT->DrawBkgnd(dcScrollList.m_hDC); + + CRect rcItem; + rcItem.left = -GetScrollPos(SB_HORZ); + rcItem.right = GetTotalWidth(); + rcItem.top = 0; + rcItem.bottom = rcItem.top; + + // Draw all visible items into bitmap + for (int nItem = min(nBeginItem, nEndItem); nItem < pT->GetItemCount(); rcItem.top = rcItem.bottom, nItem++) + { + rcItem.bottom = rcItem.top + m_nItemHeight; + + if (rcItem.top > rcScrollList.bottom) + break; + + // May be implemented in a derived class + pT->DrawItem(dcScrollList.m_hDC, nItem, rcItem); + } + + dcScrollList.RestoreDC(nContextState); + + ScrollList(); + + // Start scrolling timer + SetTimer(ITEM_SCROLL_TIMER, ITEM_SCROLL_PERIOD); + + return TRUE; + } + + BOOL EndScroll() + { + KillTimer(ITEM_SCROLL_TIMER); + if (!m_bmpScrollList.IsNull()) + m_bmpScrollList.DeleteObject(); + return Invalidate(); + } + + BOOL ScrollList() + { + if (m_nScrollOffset <= m_nScrollUnit) + m_nScrollOffset--; + else + { + m_nScrollOffset -= m_nScrollDelta; + if (m_nScrollOffset < m_nScrollDelta) + m_nScrollOffset = m_nScrollUnit; + } + + if (m_bmpScrollList.IsNull() || m_nScrollOffset < 0) + return FALSE; + + CClientDC dcClient(m_hWnd); + + CDC dcScrollList; + dcScrollList.CreateCompatibleDC(dcClient); + + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + HBITMAP hOldBitmap = dcScrollList.SelectBitmap(m_bmpScrollList); + + CSize sizScrollBitmap; + m_bmpScrollList.GetSize(sizScrollBitmap); + + // Draw scrolled list + dcClient.BitBlt(0, rcClient.top, rcClient.Width(), rcClient.Height(), dcScrollList, 0, m_bScrollDown ? (sizScrollBitmap.cy - (GetCountPerPage() * m_nItemHeight) - m_nScrollOffset) : m_nScrollOffset, SRCCOPY); + + dcScrollList.SelectBitmap(hOldBitmap); + + return TRUE; + } + + BOOL EditItem(int nItem, int nSubItem = NULL_SUBITEM) + { + T * pT = static_cast(this); + + if (!EnsureItemVisible(nItem, nSubItem)) + return FALSE; + + if (GetFocus() != m_hWnd) + return FALSE; + + CRect rcSubItem; + if (!GetItemRect(nItem, nSubItem, rcSubItem)) + return FALSE; + + int nIndex = GetColumnIndex(nSubItem); + if (pT->GetItemFlags(nItem, nIndex) & ITEM_FLAGS_READ_ONLY) + return TRUE; + + switch (pT->GetItemFormat(nItem, nIndex)) + { + case ITEM_FORMAT_EDIT: + m_bEditItem = TRUE; + if (!RedrawWindow()) + return FALSE; + if (!m_wndItemEdit.Create(m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags(nItem, nIndex), pT->GetItemText(nItem, nIndex), pT->GetItemMaxEditLen(nItem, nIndex))) + return FALSE; + m_wndItemEdit.SetFont(GetItemFont(nItem, nIndex)); + break; + case ITEM_FORMAT_DATETIME: + { + m_bEditItem = TRUE; + if (!RedrawWindow()) + return FALSE; + SYSTEMTIME stItemDate; + GetItemDate(nItem, nIndex, stItemDate); + if (!m_wndItemDate.Create(m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags(nItem, nIndex), stItemDate)) + return FALSE; + } + break; + case ITEM_FORMAT_COMBO: + { + m_bEditItem = TRUE; + if (!RedrawWindow()) + return FALSE; + CListArray aComboList; + if (!pT->GetItemComboList(nItem, nIndex, aComboList)) + return FALSE; + if (!m_wndItemCombo.Create(m_hWnd, nItem, nSubItem, rcSubItem, pT->GetItemFlags(nItem, nIndex), pT->GetItemText(nItem, nIndex), aComboList)) + return FALSE; + } + break; + } + return TRUE; + } + + stdstr FormatDate(SYSTEMTIME & stFormatDate) + { + if (stFormatDate.wYear == 0) + return _T( "" ); + + // Format date to local format + TCHAR szDateFormat[DATE_STRING]; + return GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stFormatDate, nullptr, szDateFormat, DATE_STRING) == 0 ? _T( "" ) : szDateFormat; + } + + stdstr FormatTime(SYSTEMTIME & stFormatDate) + { + SYSTEMTIME stFormatTime = stFormatDate; + stFormatTime.wYear = 0; + stFormatTime.wMonth = 0; + stFormatTime.wDay = 0; + + // Format time to local format + TCHAR szTimeFormat[DATE_STRING]; + return GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stFormatTime, nullptr, szTimeFormat, DATE_STRING) == 0 ? _T( "" ) : szTimeFormat; + } + + void NotifyParent(int nItem, int nSubItem, int nMessage) + { + T * pT = static_cast(this); + + CListNotify listNotify; + listNotify.m_hdrNotify.hwndFrom = pT->m_hWnd; + listNotify.m_hdrNotify.idFrom = pT->GetDlgCtrlID(); + listNotify.m_hdrNotify.code = nMessage; + listNotify.m_nItem = nItem; + listNotify.m_nSubItem = GetColumnIndex(nSubItem); + listNotify.m_nExitChar = 0; + listNotify.m_lpszItemText = nullptr; + listNotify.m_lpItemDate = nullptr; + + // Forward notification to parent + FORWARD_WM_NOTIFY(pT->GetParent(), listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage); + } + + BOOL ShowTitleTip(CPoint point, int nItem, int nSubItem) + { + T * pT = static_cast(this); + + // Do not show title tip if editing + if (m_bEditItem) + return FALSE; + + // Is title tip already shown for this item? + if (nItem == m_nTitleTipItem && nSubItem == m_nTitleTipSubItem) + return FALSE; + + CRect rcSubItem; + if (!GetItemRect(nItem, nSubItem, rcSubItem)) + { + HideTitleTip(); + return FALSE; + } + + int nIndex = GetColumnIndex(nSubItem); + CRect rcItemText(rcSubItem); + + // margin item text + // rcItemText.left += nSubItem == 0 ? 4 : 3; + // rcItemText.DeflateRect( 4, 0 ); + + // Offset item text (for image) + if (!m_ilItemImages.IsNull() && pT->GetItemImage(nItem, nIndex) != ITEM_IMAGE_NONE) + { + CSize sizeIcon; + m_ilItemImages.GetIconSize(sizeIcon); + rcItemText.left += sizeIcon.cx + 4; + } + + // Is current cursor position over item text (not over an icon)? + if (!rcItemText.PtInRect(point)) + return FALSE; + + stdstr strItemText; + + switch (pT->GetItemFormat(nItem, nIndex)) + { + case ITEM_FORMAT_CHECKBOX: + case ITEM_FORMAT_CHECKBOX_3STATE: + case ITEM_FORMAT_PROGRESS: break; // No title tip for checkboxes or progress + case ITEM_FORMAT_DATETIME: + { + SYSTEMTIME stItemDate; + if (!GetItemDate(nItem, nIndex, stItemDate)) + break; + + UINT nItemFlags = pT->GetItemFlags(nItem, nIndex); + if (nItemFlags & ITEM_FLAGS_DATE_ONLY) + strItemText = FormatDate(stItemDate); + else if (nItemFlags & ITEM_FLAGS_TIME_ONLY) + strItemText = FormatTime(stItemDate); + else + strItemText = FormatDate(stItemDate) + _T( " " ) + FormatTime(stItemDate); + } + break; + default: + strItemText = pT->GetItemText(nItem, nIndex); + break; + } + + if (strItemText.empty()) + { + HideTitleTip(); + return FALSE; + } + + ClientToScreen(rcItemText); + if (!m_wndTitleTip.Show(rcItemText, strItemText.c_str(), pT->GetItemToolTip(nItem, nIndex).c_str())) + { + HideTitleTip(); + return FALSE; + } + + m_nTitleTipItem = nItem; + m_nTitleTipSubItem = nSubItem; + + return TRUE; + } + + BOOL HideTitleTip(BOOL bResetItem = TRUE) + { + if (bResetItem) + { + m_nTitleTipItem = NULL_ITEM; + m_nTitleTipSubItem = NULL_SUBITEM; + } + return m_wndTitleTip.Hide(); + } + + BEGIN_MSG_MAP_EX(CListImpl) + MSG_WM_CREATE(OnCreate) + MSG_WM_DESTROY(OnDestroy) + MSG_WM_SETFOCUS(OnSetFocus) + MSG_WM_KILLFOCUS(OnKillFocus) + MSG_WM_GETDLGCODE(OnGetDlgCode) + MSG_WM_SIZE(OnSize) + MSG_WM_HSCROLL(OnHScroll) + MSG_WM_VSCROLL(OnVScroll) + MSG_WM_CANCELMODE(OnCancelMode) + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) + MSG_WM_LBUTTONDOWN(OnLButtonDown) + MSG_WM_LBUTTONUP(OnLButtonUp) + MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) + MSG_WM_RBUTTONDOWN(OnRButtonDown) + MSG_WM_RBUTTONUP(OnRButtonUp) + MSG_WM_MOUSEMOVE(OnMouseMove) +#if (_WIN32_WINNT >= 0x0400) + MSG_WM_MOUSELEAVE(OnMouseLeave) + MSG_WM_MOUSEWHEEL(OnMouseWheel) #endif - MSG_WM_TIMER(OnTimer) - MSG_WM_KEYDOWN(OnKeyDown) - MSG_WM_SYSKEYDOWN(OnSysKeyDown) - MSG_WM_SETTINGCHANGE(OnSettingsChange) - MSG_WM_SYSCOLORCHANGE(OnSettingsChange) - MSG_WM_FONTCHANGE(OnSettingsChange) - //MSG_WM_THEMECHANGED(OnSettingsChange) - NOTIFY_CODE_HANDLER_EX(LCN_ENDEDIT,OnEndEdit) - MESSAGE_HANDLER(WM_CTLCOLORLISTBOX, OnCtlColorListBox) - MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorListBox) - CHAIN_MSG_MAP(CDoubleBufferImpl< CListImpl >) - REFLECT_NOTIFICATIONS() - END_MSG_MAP() - - int OnCreate( LPCREATESTRUCT /*lpCreateStruct*/ ) - { - T* pT = static_cast(this); - return pT->Initialise() ? 0 : -1; - } - - void OnDestroy() - { - m_oleDragDrop.Revoke(); - - if ( m_wndDropArrows.IsWindow() ) - m_wndDropArrows.DestroyWindow(); - - if ( m_wndTitleTip.IsWindow() ) - m_wndTitleTip.DestroyWindow(); - - if ( m_wndItemEdit.IsWindow() ) - m_wndItemEdit.DestroyWindow(); - - if ( m_wndItemCombo.IsWindow() ) - m_wndItemCombo.DestroyWindow(); - - if ( m_wndItemDate.IsWindow() ) - m_wndItemDate.DestroyWindow(); - - if ( m_ttToolTip.IsWindow() ) - m_ttToolTip.DestroyWindow(); - } - - void OnSetFocus( HWND /*hOldWnd*/ ) - { - Invalidate(); - } - - void OnKillFocus( HWND /*hNewWnd*/ ) - { - Invalidate(); - } - - UINT OnGetDlgCode( LPMSG /*lpMessage*/ ) - { - return DLGC_WANTARROWS | DLGC_WANTTAB | DLGC_WANTCHARS; - } - - void OnSize( UINT /*nType*/, CSize /*size*/ ) - { - // Stop any pending scroll - EndScroll(); - - // End any pending edit - if ( m_bEditItem ) - SetFocus(); - - ResetScrollBars( SB_BOTH, -1, FALSE ); - Invalidate(); - } - - void OnHScroll( int nSBCode, short /*nPos*/, HWND /*hScrollBar*/ ) - { - // Stop any pending scroll - EndScroll(); - - // End any pending edit - if ( m_bEditItem ) - SetFocus(); - - HideTitleTip(); - - CRect rcClient; - GetClientRect( rcClient ); - - int nScrollPos = GetScrollPos( SB_HORZ ); + MSG_WM_TIMER(OnTimer) + MSG_WM_KEYDOWN(OnKeyDown) + MSG_WM_SYSKEYDOWN(OnSysKeyDown) + MSG_WM_SETTINGCHANGE(OnSettingsChange) + MSG_WM_SYSCOLORCHANGE(OnSettingsChange) + MSG_WM_FONTCHANGE(OnSettingsChange) + //MSG_WM_THEMECHANGED(OnSettingsChange) + NOTIFY_CODE_HANDLER_EX(LCN_ENDEDIT, OnEndEdit) + MESSAGE_HANDLER(WM_CTLCOLORLISTBOX, OnCtlColorListBox) + MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorListBox) + CHAIN_MSG_MAP(CDoubleBufferImpl) + REFLECT_NOTIFICATIONS() + END_MSG_MAP() - switch ( nSBCode ) - { - case SB_LEFT: nScrollPos = 0; - break; - case SB_LINELEFT: nScrollPos = max( nScrollPos - ITEM_SCROLL_OFFSET, 0 ); - break; - case SB_PAGELEFT: nScrollPos = max( nScrollPos - rcClient.Width(), 0 ); - break; - case SB_RIGHT: nScrollPos = rcClient.Width(); - break; - case SB_LINERIGHT: nScrollPos = min( nScrollPos + ITEM_SCROLL_OFFSET, GetTotalWidth() ); - break; - case SB_PAGERIGHT: nScrollPos = min( nScrollPos + rcClient.Width(), GetTotalWidth() ); - break; - case SB_THUMBPOSITION: - case SB_THUMBTRACK: { - SCROLLINFO infoScroll; - ZeroMemory( &infoScroll, sizeof( SCROLLINFO ) ); - infoScroll.cbSize = sizeof( SCROLLINFO ); - infoScroll.fMask = SIF_TRACKPOS; - - // Get 32-bit scroll position - if ( !GetScrollInfo( SB_HORZ, &infoScroll ) ) - return; - - // Has scroll position changed? - if ( infoScroll.nTrackPos == nScrollPos ) - return; - - nScrollPos = infoScroll.nTrackPos; - } - break; - default: return; - } + int OnCreate(LPCREATESTRUCT /*lpCreateStruct*/) + { + T * pT = static_cast(this); + return pT->Initialise() ? 0 : -1; + } - ResetScrollBars( SB_HORZ, nScrollPos, FALSE ); - Invalidate(); - } + void OnDestroy() + { + m_oleDragDrop.Revoke(); - void OnVScroll( int nSBCode, short /*nPos*/, HWND /*hScrollBar*/ ) - { - T* pT = static_cast(this); - - // End any pending edit - if ( m_bEditItem ) - SetFocus(); - - HideTitleTip(); + if (m_wndDropArrows.IsWindow()) + m_wndDropArrows.DestroyWindow(); - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - int nScrollPos = GetScrollPos( SB_VERT ); - BOOL bScrollList = m_bSmoothScroll; - - switch ( nSBCode ) - { - case SB_TOP: nScrollPos = 0; - bScrollList = FALSE; - break; - case SB_LINEUP: nScrollPos = max( nScrollPos - m_nItemHeight, 0 ); - break; - case SB_PAGEUP: nScrollPos = max( nScrollPos - rcClient.Height(), 0 ); - break; - case SB_BOTTOM: nScrollPos = pT->GetItemCount() * m_nItemHeight; - bScrollList = FALSE; - break; - case SB_LINEDOWN: nScrollPos += m_nItemHeight; - break; - case SB_PAGEDOWN: nScrollPos += rcClient.Height(); - break; - case SB_THUMBTRACK: - case SB_THUMBPOSITION: { - SCROLLINFO infoScroll; - ZeroMemory( &infoScroll, sizeof( SCROLLINFO ) ); - infoScroll.cbSize = sizeof( SCROLLINFO ); - infoScroll.fMask = SIF_TRACKPOS; - - // Get 32-bit scroll position - if ( !GetScrollInfo( SB_VERT, &infoScroll ) ) - return; - - // Has scroll position changed? - if ( infoScroll.nTrackPos == nScrollPos ) - return; - - nScrollPos = infoScroll.nTrackPos; - bScrollList = FALSE; - } - break; - case SB_ENDSCROLL: m_bScrolling = FALSE; - default: return; - } - - // Store original top item before scrolling - int nTopItem = GetTopItem(); - ResetScrollBars( SB_VERT, nScrollPos, FALSE ); - - if ( bScrollList && !m_bScrolling ) - m_bScrolling = BeginScroll( nTopItem, GetTopItem() ); - else - EndScroll(); - } - - void OnCancelMode() - { - if ( m_bButtonDown ) - ReleaseCapture(); - - HideTitleTip(); - m_wndDropArrows.Hide(); - m_nDragColumn = NULL_COLUMN; - m_nHighlightColumn = NULL_COLUMN; - } - - LRESULT OnMouseRange( UINT nMessage, WPARAM wParam, LPARAM lParam ) - { - if ( m_ttToolTip.IsWindow() ) - { - MSG msgRelay = { m_hWnd, nMessage, wParam, lParam }; - m_ttToolTip.RelayEvent( &msgRelay ); - } - SetMsgHandled( FALSE ); - return 0; - } - - void OnLButtonDown( UINT nFlags, CPoint point ) - { - T* pT = static_cast(this); - - // TODO: Fix? - // We have a bug here with setcapture() and the tooltip notifying the parent with mouse messages. - // Hard to explain, but what I think happens is that this click is sent by the tooltip, which then - // releases capture, so it gets no more mouse events, thus not receiving the actual double click - // on the tool tip, and what results is two single clicks for this parent control. - // Not sure how to fix - Rowan - - // Explorer doesn't actually hide the tip when clicked on, so we can remove this code and it shouldn't really matter - //HideTitleTip(FALSE); - - m_bButtonDown = TRUE; - m_ptDownPoint = point; - m_ptSelectPoint = CPoint( point.x + GetScrollPos( SB_HORZ ), point.y + GetScrollPos( SB_VERT ) ); + if (m_wndTitleTip.IsWindow()) + m_wndTitleTip.DestroyWindow(); - // Stop any pending scroll - EndScroll(); - - SetFocus(); - - // Capture all mouse input - SetCapture(); - - int nColumn = NULL_COLUMN; - UINT nHeaderFlags = HITTEST_FLAG_NONE; - - // Are we over the header? - if ( HitTestHeader( point, nColumn, nHeaderFlags ) ) - { - CListColumn listColumn; - if ( !GetColumn( nColumn, listColumn ) ) - return; - - if ( !listColumn.m_bFixed && ( nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER ) ) - { - SetCursor( m_curDivider ); - - // Begin column resizing - m_bColumnSizing = TRUE; - m_nColumnSizing = nColumn; - m_nStartSize = listColumn.m_nWidth; - m_nStartPos = GET_X_LPARAM( GetMessagePos() ); - } - else if (m_bSortEnabled) // Added by Rowan 05/12/2006 - { - m_nHighlightColumn = nColumn; - InvalidateHeader(); - } - - return; - } - - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - if ( !HitTest( point, nItem, nSubItem ) ) - { - m_nFirstSelected = NULL_ITEM; - m_bBeginSelect = TRUE; - } - else - { - // Do not begin group select from first columns - if ( !( nFlags & MK_SHIFT ) && !( nFlags & MK_CONTROL ) && nSubItem != 0 ) - { - m_bBeginSelect = TRUE; - m_nFirstSelected = nItem; - } - - // Only select item if not already selected - if ( ( nFlags & MK_SHIFT ) || ( nFlags & MK_CONTROL ) || !IsSelected( nItem ) || m_setSelectedItems.size() <= 1 ) - SelectItem( nItem, nSubItem, nFlags ); - - int nIndex = GetColumnIndex( nSubItem ); - if ( !( pT->GetItemFlags( nItem, nIndex ) & ITEM_FLAGS_READ_ONLY ) ) - { - switch ( pT->GetItemFormat( nItem, nIndex ) ) - { - case ITEM_FORMAT_CHECKBOX: m_bBeginSelect = FALSE; - pT->SetItemText( nItem, nIndex, _ttoi( pT->GetItemText( nItem, nIndex ) ) > 0 ? _T( "0" ) : _T( "1" ) ); - NotifyParent( nItem, nSubItem, LCN_MODIFIED ); - InvalidateItem( nItem ); - break; - case ITEM_FORMAT_CHECKBOX_3STATE: { - m_bBeginSelect = FALSE; - - int nCheckImage = _ttoi( pT->GetItemText( nItem, nIndex ) ); - if ( nCheckImage < 0 ) - pT->SetItemText( nItem, nIndex, _T( "0" ) ); - else if ( nCheckImage > 0 ) - pT->SetItemText( nItem, nIndex, _T( "-1" ) ); - else - pT->SetItemText( nItem, nIndex, _T( "1" ) ); - - NotifyParent( nItem, nSubItem, LCN_MODIFIED ); - InvalidateItem( nItem ); - } - break; - case ITEM_FORMAT_HYPERLINK: m_bBeginSelect = FALSE; - SetCursor( m_curHyperLink ); - NotifyParent( nItem, nSubItem, LCN_HYPERLINK ); - break; - } + if (m_wndItemEdit.IsWindow()) + m_wndItemEdit.DestroyWindow(); - if (( pT->GetItemFlags( nItem, nIndex ) & ITEM_FLAGS_HIT_NOTIFY ) != 0) - { - NotifyParent( nItem, nSubItem, LCN_HITTEST ); - } - } - } - } - - void OnLButtonUp( UINT nFlags, CPoint point ) - { - if ( m_bButtonDown ) - ReleaseCapture(); - - // Finish resizing or selecting a column - if ( m_bColumnSizing || m_nHighlightColumn != NULL_COLUMN ) - { - // Are we changing the sort order? - if ( !m_bColumnSizing && m_nHighlightColumn != NULL_COLUMN && m_bSortEnabled) // Changed by Rowan 05/12/2006 - //if ( !m_bColumnSizing && m_nHighlightColumn != NULL_COLUMN) - SortColumn( m_nHighlightColumn ); - - m_bColumnSizing = FALSE; - m_nColumnSizing = NULL_COLUMN; - m_nHighlightColumn = NULL_COLUMN; - m_nStartSize = 0; - m_nStartPos = 0; + if (m_wndItemCombo.IsWindow()) + m_wndItemCombo.DestroyWindow(); - InvalidateHeader(); - } - - m_bBeginSelect = FALSE; - m_bButtonDown = FALSE; - m_ptDownPoint = 0; - m_ptSelectPoint = 0; - - // Have we finished a group select? - if ( m_bGroupSelect ) - { - m_bGroupSelect = FALSE; - Invalidate(); - } - else - { - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - // Deselect item if current item is selected - if ( HitTest( point, nItem, nSubItem ) && IsSelected( nItem ) && m_setSelectedItems.size() > 1 && !( nFlags & MK_SHIFT ) && !( nFlags & MK_CONTROL ) ) - SelectItem( nItem, nSubItem, nFlags ); - - // Notify parent of left-click item - NotifyParent( nItem, nSubItem, LCN_LEFTCLICK ); - } - } - - void OnLButtonDblClk( UINT /*nFlags*/, CPoint point ) - { - - HideTitleTip( FALSE ); - - // Handle double-clicks (for drawing) - SendMessage( WM_LBUTTONDOWN, 0, MAKELPARAM( point.x, point.y ) ); + if (m_wndItemDate.IsWindow()) + m_wndItemDate.DestroyWindow(); - int nColumn = NULL_COLUMN; - UINT nHeaderFlags = HITTEST_FLAG_NONE; - - // Resize column if double-click on a divider - if ( HitTestHeader( point, nColumn, nHeaderFlags ) && ( nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER ) ) - AutoSizeColumn( nColumn ); - - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - HitTest( point, nItem, nSubItem ); - - //WriteTraceF(TraceInfo, "List Ctrl Double Click, Item: %d", nItem); - - // Notify parent of double-clicked item - NotifyParent( nItem, nSubItem, LCN_DBLCLICK ); - } - - void OnRButtonDown( UINT nFlags, CPoint point ) - { - // Stop any pending scroll - EndScroll(); - - SetFocus(); - - HideTitleTip( FALSE ); - - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - if (m_bRightClickSelect) - { - // Only select item if not already selected (deselect in OnLButtonUp) - if (HitTest(point, nItem, nSubItem) && !IsSelected(nItem)) - SelectItem(nItem, nSubItem, nFlags); - } - } + if (m_ttToolTip.IsWindow()) + m_ttToolTip.DestroyWindow(); + } - void OnRButtonUp( UINT /*nFlags*/, CPoint point ) - { - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - if ( !HitTest( point, nItem, nSubItem ) ) - ResetSelected(); - - // Notify parent of right-click item - NotifyParent( nItem, nSubItem, LCN_RIGHTCLICK ); - } + void OnSetFocus(HWND /*hOldWnd*/) + { + Invalidate(); + } - void OnMouseMove( UINT nFlags, CPoint point ) - { - T* pT = static_cast(this); - - if ( !( nFlags & MK_LBUTTON ) ) - { - if ( m_bButtonDown ) - ReleaseCapture(); - - m_bButtonDown = FALSE; - } - - if ( !m_bMouseOver ) - { - m_bMouseOver = TRUE; - - TRACKMOUSEEVENT trkMouse; - trkMouse.cbSize = sizeof( TRACKMOUSEEVENT ); - trkMouse.dwFlags = TME_LEAVE; - trkMouse.hwndTrack = m_hWnd; - - // Notify when the mouse leaves button - _TrackMouseEvent( &trkMouse ); - } - - if ( m_bButtonDown ) - { - // Are we resizing a column? - if ( m_bColumnSizing ) - { - ResizeColumn(); - return; - } - - // Are we beginning to drag a column? - if ( m_nHighlightColumn != NULL_COLUMN && ( point.x < m_ptDownPoint.x - DRAG_HEADER_OFFSET || point.x > m_ptDownPoint.x + DRAG_HEADER_OFFSET || point.y < m_ptDownPoint.y - DRAG_HEADER_OFFSET || point.y > m_ptDownPoint.y + DRAG_HEADER_OFFSET ) ) - { - DragColumn(); - return; - } - - // Are we beginning a group select or dragging an item? - if ( point.x < m_ptDownPoint.x - DRAG_ITEM_OFFSET || point.x > m_ptDownPoint.x + DRAG_ITEM_OFFSET || point.y < m_ptDownPoint.y - DRAG_ITEM_OFFSET || point.y > m_ptDownPoint.y + DRAG_ITEM_OFFSET ) - { - if ( m_bBeginSelect || !m_bDragDrop ) - m_bGroupSelect = ( !m_bSingleSelect && !m_bEditItem ); - else - { - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - if ( HitTest( point, nItem, nSubItem ) ) - { - // Select the drag item (if not already selected) - if ( !IsSelected( nItem ) ) - SelectItem( nItem, nSubItem, nFlags ); - - // Begin drag item operation - pT->DragItem(); - } - } - } - - if ( m_bGroupSelect ) - { - GroupSelect( point ); - return; - } - } - else - { - int nColumn = NULL_COLUMN; - UINT nHeaderFlags = HITTEST_FLAG_NONE; - - // Are we over the header? - BOOL bHitTestHeader = HitTestHeader( point, nColumn, nHeaderFlags ); - - if ( bHitTestHeader ) - { - HideTitleTip(); - CListColumn listColumn; - if ( GetColumn( nColumn, listColumn ) && !listColumn.m_bFixed && ( nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER ) ) - SetCursor( m_curDivider ); - else - { - // Get tooltip for this item - stdstr strToolTip = pT->GetHeaderToolTip(nColumn); - if(!strToolTip.empty()) - { - CRect rcColumn; - if(!GetColumnRect(nColumn, rcColumn)) - return; - rcColumn.bottom = m_nHeaderHeight; - m_ttToolTip.Activate( TRUE ); - m_ttToolTip.AddTool( m_hWnd, (LPCTSTR)strToolTip.c_str(), rcColumn,TOOLTIP_TOOL_ID); - } - } - return; - } - - int nItem = NULL_ITEM; - int nSubItem = NULL_SUBITEM; - - if ( !HitTest( point, nItem, nSubItem ) ) - { - if ( m_nHotItem != NULL_ITEM && m_nHotSubItem != NULL_SUBITEM ) - { - // Redraw old hot item - int nIndex = GetColumnIndex( m_nHotSubItem ); - if ( pT->GetItemFormat( m_nHotItem, nIndex ) == ITEM_FORMAT_HYPERLINK && !( pT->GetItemFlags( m_nHotItem, nIndex ) & ITEM_FLAGS_READ_ONLY ) ) - InvalidateItem( m_nHotItem, m_nHotSubItem ); - } - - m_ttToolTip.Activate( FALSE ); - m_ttToolTip.DelTool( m_hWnd, TOOLTIP_TOOL_ID ); - - m_nHotItem = NULL_ITEM; - m_nHotSubItem = NULL_SUBITEM; - HideTitleTip(); - } - else - { - // Has the hot item changed? - if ( nItem != m_nHotItem || nSubItem != m_nHotSubItem ) - { - // Redraw old hot item - int nIndex = GetColumnIndex( m_nHotSubItem ); - if ( pT->GetItemFormat( m_nHotItem, nIndex ) == ITEM_FORMAT_HYPERLINK && !( pT->GetItemFlags( m_nHotItem, nIndex ) & ITEM_FLAGS_READ_ONLY ) ) - InvalidateItem( m_nHotItem, m_nHotSubItem ); - - m_nHotItem = nItem; - m_nHotSubItem = nSubItem; + void OnKillFocus(HWND /*hNewWnd*/) + { + Invalidate(); + } - NotifyParent(nItem, nSubItem, LCN_HOTITEMCHANGED); - } - - int nIndex = GetColumnIndex( m_nHotSubItem ); - UINT nItemFormat = pT->GetItemFormat( m_nHotItem, nIndex ); - UINT nItemFlags = pT->GetItemFlags( m_nHotItem, nIndex ); - - // Draw new hot hyperlink item - if ( nItemFormat == ITEM_FORMAT_HYPERLINK && !( nItemFlags & ITEM_FLAGS_READ_ONLY ) ) - { - InvalidateItem( m_nHotItem, m_nHotSubItem ); - SetCursor( m_curHyperLink ); - } - - // Get tooltip for this item - stdstr strToolTip = pT->GetItemToolTip( m_nHotItem, nIndex ); - - CRect rcSubItem; - if ( !strToolTip.empty() && GetItemRect( m_nHotItem, rcSubItem ) ) - { - m_ttToolTip.Activate( TRUE ); - m_ttToolTip.AddTool( m_hWnd, (LPCTSTR)strToolTip.substr(0, SHRT_MAX ).c_str(), rcSubItem, TOOLTIP_TOOL_ID ); - } - else - { - m_ttToolTip.Activate( FALSE ); - m_ttToolTip.DelTool( m_hWnd, TOOLTIP_TOOL_ID ); - } - - // Show title tips for this item - ShowTitleTip( point, m_nHotItem, m_nHotSubItem ); - } - } - } - - void OnMouseLeave() - { - m_bMouseOver = FALSE; - - if ( m_nHotColumn != NULL_COLUMN ) - { - m_nHotColumn = NULL_COLUMN; - InvalidateHeader(); - } - - if ( m_nHotItem != NULL_ITEM || m_nHotSubItem != NULL_SUBITEM ) - { - m_nHotItem = NULL_ITEM; - m_nHotSubItem = NULL_SUBITEM; - Invalidate(); - } - } - - BOOL OnMouseWheel( UINT /*nFlags*/, short nDelta, CPoint /*point*/ ) - { - HideTitleTip(); - - // End any pending edit - if ( m_bEditItem ) - SetFocus(); - - int nRowsScrolled = m_nMouseWheelScroll * nDelta / 120; - int nScrollPos = GetScrollPos( SB_VERT ); - - if ( nRowsScrolled > 0 ) - nScrollPos = max( nScrollPos - ( nRowsScrolled * m_nItemHeight ), 0 ); - else - nScrollPos += ( -nRowsScrolled * m_nItemHeight ); - - ResetScrollBars( SB_VERT, nScrollPos, FALSE ); - Invalidate(); - - return TRUE; - } - - void OnTimer(UINT_PTR nIDEvent ) - { - switch ( nIDEvent ) - { - case RESIZE_COLUMN_TIMER: ResizeColumn( TRUE ); - break; - case ITEM_VISIBLE_TIMER: { - KillTimer( ITEM_VISIBLE_TIMER ); - - int nFocusItem = NULL_ITEM; - int nFocusSubItem = NULL_SUBITEM; - - // Get current focus item - if ( !GetFocusItem( nFocusItem, nFocusSubItem ) ) - break; - - // Make sure current focus item is visible before editing - if ( !EditItem( nFocusItem, nFocusSubItem ) ) - break; - } - break; - case ITEM_AUTOSCROLL_TIMER: if ( !m_bGroupSelect ) - KillTimer( ITEM_AUTOSCROLL_TIMER ); - else - { - DWORD dwPoint = GetMessagePos(); - CPoint ptMouse( GET_X_LPARAM( dwPoint ), GET_Y_LPARAM( dwPoint ) ); - ScreenToClient( &ptMouse ); - - // Automatically scroll when group selecting - AutoScroll( ptMouse ); - AutoSelect( ptMouse ); - } - break; - case ITEM_SCROLL_TIMER: if ( !ScrollList() ) - EndScroll(); - break; - } - } - - void OnKeyDown( TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/ ) - { - T* pT = static_cast(this); - - // Stop any pending scroll - EndScroll(); - - BOOL bCtrlKey = ( ( GetKeyState( VK_CONTROL ) & 0x8000 ) != 0 ); - BOOL bShiftKey = ( ( GetKeyState( VK_SHIFT ) & 0x8000 ) != 0 ); - - CRect rcClient; - GetClientRect( rcClient ); - - int nFocusItem = NULL_ITEM; - int nFocusSubItem = NULL_SUBITEM; - GetFocusItem( nFocusItem, nFocusSubItem ); - - switch ( nChar ) - { - case VK_DOWN: SetFocusItem( min( nFocusItem + 1, pT->GetItemCount() - 1 ), nFocusSubItem ); - break; - case VK_UP: SetFocusItem( max( nFocusItem - 1, 0 ), nFocusSubItem ); - break; - case VK_NEXT: SetFocusItem( min( nFocusItem + GetCountPerPage( FALSE ) - 1, pT->GetItemCount() - 1 ), nFocusSubItem ); - break; - case VK_PRIOR: SetFocusItem( max( nFocusItem - GetCountPerPage( FALSE ) + 1, 0 ), nFocusSubItem ); - break; - case VK_HOME: SetFocusItem( 0, nFocusSubItem ); - break; - case VK_END: SetFocusItem( pT->GetItemCount() - 1, nFocusSubItem ); - break; - case VK_LEFT: if ( m_bFocusSubItem ) - SetFocusItem( nFocusItem, max( nFocusSubItem - 1, 0 ) ); - else - SetScrollPos( SB_HORZ, max( GetScrollPos( SB_HORZ ) - ( bCtrlKey ? ITEM_SCROLL_OFFSET * 10 : ITEM_SCROLL_OFFSET ), 0 ) ); - break; - case VK_RIGHT: if ( m_bFocusSubItem ) - SetFocusItem( nFocusItem, min( nFocusSubItem + 1, GetColumnCount() - 1 ) ); - else - SetScrollPos( SB_HORZ, min( GetScrollPos( SB_HORZ ) + ( bCtrlKey ? ITEM_SCROLL_OFFSET * 10 : ITEM_SCROLL_OFFSET ), rcClient.Width() ) ); - break; - case VK_TAB: if ( !bCtrlKey && m_bFocusSubItem ) - SetFocusItem( nFocusItem, bShiftKey ? max( nFocusSubItem - 1, 0 ) : min( nFocusSubItem + 1, GetColumnCount() - 1 ) ); - break; - default: if ( nChar == VK_SPACE ) - { - int nIndex = GetColumnIndex( nFocusSubItem ); - if ( !( pT->GetItemFlags( nFocusItem, nIndex ) & ITEM_FLAGS_READ_ONLY ) ) - { - switch ( pT->GetItemFormat( nFocusItem, nIndex ) ) - { - case ITEM_FORMAT_CHECKBOX: pT->SetItemText( nFocusItem, nIndex, _ttoi( pT->GetItemText( nFocusItem, nIndex ) ) > 0 ? _T( "0" ) : _T( "1" ) ); - NotifyParent( nFocusItem, nFocusSubItem, LCN_MODIFIED ); - InvalidateItem( nFocusItem ); - return; - case ITEM_FORMAT_CHECKBOX_3STATE: { - int nCheckImage = _ttoi( pT->GetItemText( nFocusItem, nIndex ) ); - if ( nCheckImage < 0 ) - pT->SetItemText( nFocusItem, nIndex, _T( "0" ) ); - else if ( nCheckImage > 0 ) - pT->SetItemText( nFocusItem, nIndex, _T( "-1" ) ); - else - pT->SetItemText( nFocusItem, nIndex, _T( "1" ) ); - - NotifyParent( nFocusItem, nFocusSubItem, LCN_MODIFIED ); - InvalidateItem( nFocusItem ); - } - return; - } - } - } - - if ( bCtrlKey && nChar == _T( 'A' ) && !m_bSingleSelect ) - { - m_setSelectedItems.clear(); - for ( int nItem = 0; nItem < pT->GetItemCount(); nItem++ ) - m_setSelectedItems.insert( nItem ); - Invalidate(); - return; - } - - if ( !bCtrlKey && iswprint( nChar ) && iswupper( nChar ) ) - { - int nSortIndex = GetColumnIndex( m_nSortColumn ); - int nStartItem = nFocusItem + 1; - DWORD dwCurrentTick = GetTickCount(); - - stdstr strStart; - strStart += nChar; - - // Has there been another keypress since last search period? - if ( ( dwCurrentTick - m_dwSearchTick ) < SEARCH_PERIOD ) - { - if ( m_strSearchString.substr(0, 1 ) != strStart ) - m_strSearchString += nChar; - - stdstr strFocusText = pT->GetItemText( nFocusItem, nSortIndex ); - - // Are we continuing to type characters under current focus item? - if ( m_strSearchString.length() > 1 && _tcsicmp(m_strSearchString.c_str(),strFocusText.substr(0, m_strSearchString.length() ).c_str() ) == 0 ) - { - m_dwSearchTick = GetTickCount(); - return; - } - } - else - { - if ( m_strSearchString.substr(0, 1 ) != strStart ) - nStartItem = 0; - m_strSearchString = strStart; - } - - m_dwSearchTick = GetTickCount(); - - // Scan for next search string - for ( int nFirst = nStartItem; nFirst < pT->GetItemCount(); nFirst++ ) - { - stdstr strItemText = pT->GetItemText( nFirst, nSortIndex ); - - if ( _tcsicmp(m_strSearchString.c_str(), strItemText.substr(0, m_strSearchString.length() ).c_str() ) == 0 ) - { - SelectItem( nFirst, nFocusSubItem, TRUE ); - EnsureItemVisible( nFirst, nFocusSubItem ); - return; - } - } - - // Rescan from top if not found search string - for ( int nSecond = 0; nSecond < pT->GetItemCount(); nSecond++ ) - { - stdstr strItemText = pT->GetItemText( nSecond, nSortIndex ); - - if ( _tcsicmp(m_strSearchString.c_str(), strItemText.substr(0, m_strSearchString.length() ).c_str() ) == 0 ) - { - SelectItem( nSecond, nFocusSubItem, TRUE ); - EnsureItemVisible( nSecond, nFocusSubItem ); - return; - } - } - } - return; - } + UINT OnGetDlgCode(LPMSG /*lpMessage*/) + { + return DLGC_WANTARROWS | DLGC_WANTTAB | DLGC_WANTCHARS; + } - if ( !bCtrlKey ) - SelectItem( m_nFocusItem, m_nFocusSubItem, bShiftKey ? MK_SHIFT : 0 ); - } - - void OnSysKeyDown( TCHAR /*nChar*/, UINT /*nRepCnt*/, UINT /*nFlags*/ ) - { - HideTitleTip( FALSE ); - SetMsgHandled( FALSE ); - } - - void OnSettingsChange( UINT /*nFlags*/, LPCTSTR /*lpszSection*/ ) - { - OnSettingsChange(); - } - - void OnSettingsChange() - { - LoadSettings(); - ResetScrollBars(); - Invalidate(); - } - - LRESULT OnCtlColorListBox( UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/ ) - { - return DefWindowProc( nMsg, wParam, lParam ); - } - - LRESULT OnEndEdit( LPNMHDR lpNMHDR ) - { - T* pT = static_cast(this); - CListNotify *pListNotify = reinterpret_cast( lpNMHDR ); - - m_bEditItem = FALSE; - int nIndex = GetColumnIndex( pListNotify->m_nSubItem ); - - switch ( pListNotify->m_nExitChar ) - { - case VK_ESCAPE: break; // Do nothing - case VK_DELETE: pT->SetItemText( pListNotify->m_nItem, nIndex, _T( "" ) ); - NotifyParent( pListNotify->m_nItem, pListNotify->m_nSubItem, LCN_MODIFIED ); - break; - default: if ( pListNotify->m_lpItemDate == nullptr ) - pT->SetItemText( pListNotify->m_nItem, nIndex, pListNotify->m_lpszItemText ); - else - { - if ( _ttoi( pListNotify->m_lpszItemText ) == 0 ) - pT->SetItemText( pListNotify->m_nItem, nIndex, _T( "" ) ); - else - pT->SetItemDate( pListNotify->m_nItem, nIndex, *pListNotify->m_lpItemDate ); - } - if ( pListNotify->m_nExitChar == VK_TAB ) - PostMessage( WM_KEYDOWN, (WPARAM)VK_TAB ); - NotifyParent( pListNotify->m_nItem, pListNotify->m_nSubItem, LCN_MODIFIED ); - break; - } - - InvalidateItem( pListNotify->m_nItem ); - - return 0; - } - - DWORD OnDragEnter( FORMATETC& FormatEtc, STGMEDIUM& StgMedium, DWORD /*dwKeyState*/, CPoint point ) - { - DWORD dwEffect = DROPEFFECT_NONE; - - if ( FormatEtc.cfFormat == m_nHeaderClipboardFormat ) - { - LPBYTE lpDragHeader = (LPBYTE)GlobalLock( StgMedium.hGlobal ); - if ( lpDragHeader == nullptr ) - return DROPEFFECT_NONE; - - // Dragged column must originate from this control - if ( *( (HWND*)lpDragHeader ) == m_hWnd ) - dwEffect = DropColumn( point ) ? DROPEFFECT_MOVE : DROPEFFECT_NONE; - - GlobalUnlock( StgMedium.hGlobal ); - } - - return dwEffect; - } - - DWORD OnDragOver( FORMATETC& FormatEtc, STGMEDIUM& StgMedium, DWORD /*dwKeyState*/, CPoint point ) - { - DWORD dwEffect = DROPEFFECT_NONE; - - if ( FormatEtc.cfFormat == m_nHeaderClipboardFormat ) - { - LPBYTE lpDragHeader = (LPBYTE)GlobalLock( StgMedium.hGlobal ); - if ( lpDragHeader == nullptr ) - return DROPEFFECT_NONE; - - // Dragged column must originate from this control - if ( *( (HWND*)lpDragHeader ) == m_hWnd ) - dwEffect = DropColumn( point ) ? DROPEFFECT_MOVE : DROPEFFECT_NONE; - - GlobalUnlock( StgMedium.hGlobal ); - } - - return dwEffect; - } - - BOOL OnDrop( FORMATETC& FormatEtc, STGMEDIUM& /*StgMedium*/, DWORD /*dwEffect*/, CPoint /*point*/ ) - { - if ( FormatEtc.cfFormat == m_nHeaderClipboardFormat ) - { - if ( m_nDragColumn != NULL_COLUMN && m_nHotDivider != NULL_COLUMN ) - { - CListColumn listColumn; - if ( !GetColumn( m_nDragColumn, listColumn ) ) - return FALSE; - - // Move column to new position - m_aColumns.RemoveAt( m_nDragColumn ); - m_aColumns.InsertAt( ( m_nDragColumn < m_nHotColumn ? ( m_nHotDivider == 0 ? 0 : m_nHotDivider - 1 ) : m_nHotDivider ), listColumn ); - Invalidate(); - } + void OnSize(UINT /*nType*/, CSize /*size*/) + { + // Stop any pending scroll + EndScroll(); - return TRUE; - } - - // Not supported - return FALSE; - } - - void OnDragLeave() - { - } - - BOOL OnRenderData( FORMATETC& FormatEtc, STGMEDIUM *pStgMedium, BOOL /*bDropComplete*/ ) - { - if ( FormatEtc.cfFormat == m_nHeaderClipboardFormat ) - { - pStgMedium->tymed = TYMED_HGLOBAL; - pStgMedium->hGlobal = GlobalAlloc( GMEM_MOVEABLE, sizeof( HWND ) ); - if ( pStgMedium->hGlobal == nullptr ) - return FALSE; - - LPBYTE lpDragHeader = (LPBYTE)GlobalLock( pStgMedium->hGlobal ); - if ( lpDragHeader == nullptr ) - return FALSE; - - // Store this window handle - *( (HWND*)lpDragHeader ) = m_hWnd; - - GlobalUnlock( pStgMedium->hGlobal ); - - return TRUE; - } - - return FALSE; - } - - void DoPaint( CDCHandle dcPaint ) - { - T* pT = static_cast(this); - - int nContextState = dcPaint.SaveDC(); - - pT->DrawBkgnd( dcPaint ); - pT->DrawList( dcPaint ); - pT->DrawSelect( dcPaint ); - pT->DrawHeader( dcPaint ); - - dcPaint.RestoreDC( nContextState ); - } - - void DrawBkgnd( CDCHandle dcPaint ) - { - CRect rcClip; - if ( dcPaint.GetClipBox( rcClip ) == ERROR ) - return; - - dcPaint.SetBkColor( m_rgbBackground ); - dcPaint.ExtTextOut( rcClip.left, rcClip.top, ETO_OPAQUE, rcClip, _T( "" ), 0, nullptr ); - - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - if ( !m_bmpBackground.IsNull() && rcClip.bottom > rcClient.top ) - { - CSize sizBackground; - m_bmpBackground.GetSize( sizBackground ); - - CDC dcBackgroundImage; - dcBackgroundImage.CreateCompatibleDC( dcPaint ); - - HBITMAP hOldBitmap = dcBackgroundImage.SelectBitmap( m_bmpBackground ); - - if ( m_bTileBackground ) - { - // Calculate tile image maximum rows and columns - div_t divRows = div( (int)rcClient.Height(), (int)sizBackground.cy ); - int nTileRows = divRows.rem > 0 ? divRows.quot + 1 : divRows.quot; - div_t divColumns = div( (int)rcClient.Width(), (int)sizBackground.cx ); - int nTileColumns = divColumns.rem > 0 ? divColumns.quot + 1 : divColumns.quot; - - // Draw tiled background image - for ( int nRow = 0; nRow <= nTileRows; nRow++ ) - { - for ( int nColumn = 0; nColumn <= nTileColumns; nColumn++ ) - dcPaint.BitBlt( nColumn * sizBackground.cx, nRow * sizBackground.cy, sizBackground.cx, sizBackground.cy, dcBackgroundImage, 0, 0, SRCCOPY ); - } - } - else - { - CRect rcCentreImage( rcClient ); - - // Horizontally center image if smaller than the client width - if ( sizBackground.cx < rcClient.Width() ) - { - rcCentreImage.left = ( rcClient.Width() / 2 ) - (int)( sizBackground.cx / 2 ); - rcCentreImage.right = rcCentreImage.left + sizBackground.cx; - } - - // Vertically center image if smaller than the client height - if ( sizBackground.cy + 16 < rcClient.Height() ) - { - rcCentreImage.top = ( rcClient.Height() / 2 ) - (int)( ( sizBackground.cy + 16 ) / 2 ); - rcCentreImage.bottom = rcCentreImage.top + sizBackground.cy; - } - - // Draw centered background image - dcPaint.BitBlt( rcCentreImage.left, rcCentreImage.top, rcCentreImage.Width(), rcCentreImage.Height(), dcBackgroundImage, 0, 0, SRCCOPY ); - } + // End any pending edit + if (m_bEditItem) + SetFocus(); - dcBackgroundImage.SelectBitmap( hOldBitmap ); - } - } - - void DrawHeader( CDCHandle dcPaint ) - { - if ( !m_bShowHeader ) - return; + ResetScrollBars(SB_BOTH, -1, FALSE); + Invalidate(); + } - CRect rcClip; - if ( dcPaint.GetClipBox( rcClip ) == ERROR ) - return; + void OnHScroll(int nSBCode, short /*nPos*/, HWND /*hScrollBar*/) + { + // Stop any pending scroll + EndScroll(); - CRect rcHeader; - GetClientRect( rcHeader ); - rcHeader.bottom = m_nHeaderHeight; + // End any pending edit + if (m_bEditItem) + SetFocus(); - if ( rcClip.top > rcHeader.bottom ) - return; + HideTitleTip(); - dcPaint.SetBkColor( m_rgbHeaderBackground ); - dcPaint.ExtTextOut( rcHeader.left, rcHeader.top, ETO_OPAQUE, rcHeader, _T( "" ), 0, nullptr ); + CRect rcClient; + GetClientRect(rcClient); - CPen penHighlight; - penHighlight.CreatePen( PS_SOLID, 1, m_rgbHeaderBorder ); - CPen penShadow; - penShadow.CreatePen( PS_SOLID, 1, m_rgbHeaderShadow ); + int nScrollPos = GetScrollPos(SB_HORZ); - CRect rcHeaderItem( rcHeader ); - rcHeaderItem.OffsetRect( -GetScrollPos( SB_HORZ ), 0 ); + switch (nSBCode) + { + case SB_LEFT: + nScrollPos = 0; + break; + case SB_LINELEFT: + nScrollPos = max(nScrollPos - ITEM_SCROLL_OFFSET, 0); + break; + case SB_PAGELEFT: + nScrollPos = max(nScrollPos - rcClient.Width(), 0); + break; + case SB_RIGHT: + nScrollPos = rcClient.Width(); + break; + case SB_LINERIGHT: + nScrollPos = min(nScrollPos + ITEM_SCROLL_OFFSET, GetTotalWidth()); + break; + case SB_PAGERIGHT: + nScrollPos = min(nScrollPos + rcClient.Width(), GetTotalWidth()); + break; + case SB_THUMBPOSITION: + case SB_THUMBTRACK: + { + SCROLLINFO infoScroll; + ZeroMemory(&infoScroll, sizeof(SCROLLINFO)); + infoScroll.cbSize = sizeof(SCROLLINFO); + infoScroll.fMask = SIF_TRACKPOS; - int nHeaderWidth = 0; + // Get 32-bit scroll position + if (!GetScrollInfo(SB_HORZ, &infoScroll)) + return; - for ( int nColumn = 0, nColumnCount = GetColumnCount(); nColumn < nColumnCount; rcHeaderItem.left = rcHeaderItem.right, nColumn++ ) - { - CListColumn listColumn; - if ( !GetColumn( nColumn, listColumn ) ) - break; + // Has scroll position changed? + if (infoScroll.nTrackPos == nScrollPos) + return; - rcHeaderItem.right = rcHeaderItem.left + listColumn.m_nWidth; - nHeaderWidth += rcHeaderItem.Width(); + nScrollPos = infoScroll.nTrackPos; + } + break; + default: return; + } - if ( rcHeaderItem.right < rcClip.left ) - continue; - if ( rcHeaderItem.left > rcClip.right ) - break; + ResetScrollBars(SB_HORZ, nScrollPos, FALSE); + Invalidate(); + } - // Draw header and divider - if ( nColumn == m_nHighlightColumn ) - { - dcPaint.SetBkColor( m_rgbHeaderHighlight ); - dcPaint.ExtTextOut( rcHeaderItem.left, rcHeaderItem.top, ETO_OPAQUE, rcHeaderItem, _T( "" ), 0, nullptr ); - } + void OnVScroll(int nSBCode, short /*nPos*/, HWND /*hScrollBar*/) + { + T * pT = static_cast(this); + // End any pending edit + if (m_bEditItem) + SetFocus(); - dcPaint.SelectPen( penShadow ); - dcPaint.MoveTo( rcHeaderItem.right - 1, rcHeaderItem.top + 1 ); - dcPaint.LineTo( rcHeaderItem.right - 1, m_nHeaderHeight - 1 ); + HideTitleTip(); - dcPaint.SelectPen( penHighlight ); - dcPaint.MoveTo( rcHeaderItem.right, rcHeaderItem.top + 1 ); - dcPaint.LineTo( rcHeaderItem.right, m_nHeaderHeight - 1 ); + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + int nScrollPos = GetScrollPos(SB_VERT); + BOOL bScrollList = m_bSmoothScroll; - CRect rcHeaderText( rcHeaderItem ); - rcHeaderText.left += nColumn == 0 ? 4 : 3; - rcHeaderText.OffsetRect( 0, 1 ); + switch (nSBCode) + { + case SB_TOP: + nScrollPos = 0; + bScrollList = FALSE; + break; + case SB_LINEUP: + nScrollPos = max(nScrollPos - m_nItemHeight, 0); + break; + case SB_PAGEUP: + nScrollPos = max(nScrollPos - rcClient.Height(), 0); + break; + case SB_BOTTOM: + nScrollPos = pT->GetItemCount() * m_nItemHeight; + bScrollList = FALSE; + break; + case SB_LINEDOWN: + nScrollPos += m_nItemHeight; + break; + case SB_PAGEDOWN: + nScrollPos += rcClient.Height(); + break; + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + { + SCROLLINFO infoScroll; + ZeroMemory(&infoScroll, sizeof(SCROLLINFO)); + infoScroll.cbSize = sizeof(SCROLLINFO); + infoScroll.fMask = SIF_TRACKPOS; - BOOL bShowArrow = m_bShowSort && ( rcHeaderItem.Width() > 15 ); + // Get 32-bit scroll position + if (!GetScrollInfo(SB_VERT, &infoScroll)) + return; + // Has scroll position changed? + if (infoScroll.nTrackPos == nScrollPos) + return; - if(listColumn.m_nImage == ITEM_IMAGE_NONE ) - { - // Offset text bounding rectangle to account for sorting arrow - if ( bShowArrow && !listColumn.m_bFixed && listColumn.m_nIndex == m_nSortColumn ) - rcHeaderText.right -= 15; - } + nScrollPos = infoScroll.nTrackPos; + bScrollList = FALSE; + } + break; + case SB_ENDSCROLL: m_bScrolling = FALSE; + default: return; + } - // Margin header text - rcHeaderText.DeflateRect( 4, 0, 5, 0 ); + // Store original top item before scrolling + int nTopItem = GetTopItem(); + ResetScrollBars(SB_VERT, nScrollPos, FALSE); - // Has this header item an associated image? - if ( listColumn.m_nImage != ITEM_IMAGE_NONE ) - { - CSize sizeIcon; - m_ilListItems.GetIconSize( sizeIcon ); + if (bScrollList && !m_bScrolling) + m_bScrolling = BeginScroll(nTopItem, GetTopItem()); + else + EndScroll(); + } - CRect rcHeaderImage; - rcHeaderImage.left = listColumn.m_strText.empty() ? ( ( rcHeaderText.left + rcHeaderText.right ) / 2 ) - ( sizeIcon.cx / 2 ) - ( 0 ) : rcHeaderText.left; - rcHeaderImage.right = min( rcHeaderImage.left + sizeIcon.cx, rcHeaderItem.right - 2 ); - rcHeaderImage.top = ( ( rcHeaderItem.top + rcHeaderItem.bottom ) / 2 ) - ( sizeIcon.cy / 2 ); - rcHeaderImage.bottom = min( rcHeaderImage.top + sizeIcon.cy, rcHeaderItem.bottom ); + void OnCancelMode() + { + if (m_bButtonDown) + ReleaseCapture(); - if(listColumn.m_nIndex == m_nSortColumn) - m_ilListItems.DrawEx( listColumn.m_nImage, dcPaint, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT | ILD_SELECTED ); - else - m_ilListItems.DrawEx( listColumn.m_nImage, dcPaint, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); + HideTitleTip(); + m_wndDropArrows.Hide(); + m_nDragColumn = NULL_COLUMN; + m_nHighlightColumn = NULL_COLUMN; + } - // Offset header text (for image) - rcHeaderText.left += sizeIcon.cx + 4; - } + LRESULT OnMouseRange(UINT nMessage, WPARAM wParam, LPARAM lParam) + { + if (m_ttToolTip.IsWindow()) + { + MSG msgRelay = {m_hWnd, nMessage, wParam, lParam}; + m_ttToolTip.RelayEvent(&msgRelay); + } + SetMsgHandled(FALSE); + return 0; + } - dcPaint.SelectFont( m_fntListFont ); - dcPaint.SetTextColor( m_rgbHeaderText ); - dcPaint.SetBkMode( TRANSPARENT ); + void OnLButtonDown(UINT nFlags, CPoint point) + { + T * pT = static_cast(this); - UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + // TODO: Fix? + // We have a bug here with setcapture() and the tooltip notifying the parent with mouse messages. + // Hard to explain, but what I think happens is that this click is sent by the tooltip, which then + // releases capture, so it gets no more mouse events, thus not receiving the actual double click + // on the tool tip, and what results is two single clicks for this parent control. + // Not sure how to fix - Rowan - if ( listColumn.m_nFlags & ITEM_FLAGS_CENTRE ) - nFormat |= DT_CENTER; - else if ( listColumn.m_nFlags & ITEM_FLAGS_RIGHT ) - nFormat |= DT_RIGHT; - else - nFormat |= DT_LEFT; + // Explorer doesn't actually hide the tip when clicked on, so we can remove this code and it shouldn't really matter + //HideTitleTip(FALSE); - // Draw header text - if ( !rcHeaderText.IsRectEmpty() && !listColumn.m_strText.empty() ) - dcPaint.DrawText( listColumn.m_strText.c_str(), (int)listColumn.m_strText.length(), rcHeaderText, nFormat ); + m_bButtonDown = TRUE; + m_ptDownPoint = point; + m_ptSelectPoint = CPoint(point.x + GetScrollPos(SB_HORZ), point.y + GetScrollPos(SB_VERT)); - // Draw sorting arrow - if ( bShowArrow && !listColumn.m_bFixed && listColumn.m_nIndex == m_nSortColumn ) - { - CSize sizeIcon; - m_ilListItems.GetIconSize( sizeIcon ); + // Stop any pending scroll + EndScroll(); - CRect rcSortArrow; - rcSortArrow.left = rcHeaderText.right + 4; - rcSortArrow.right = min( rcSortArrow.left + sizeIcon.cx, rcHeaderItem.right ); - rcSortArrow.top = rcHeaderItem.Height() / 2 - 3; - rcSortArrow.bottom = min( rcSortArrow.top + sizeIcon.cy, rcHeaderItem.bottom ); + SetFocus(); - m_ilListItems.DrawEx( m_bSortAscending ? ITEM_IMAGE_UP : ITEM_IMAGE_DOWN, dcPaint, rcSortArrow, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); - } - } + // Capture all mouse input + SetCapture(); - // Draw a frame around all header columns + int nColumn = NULL_COLUMN; + UINT nHeaderFlags = HITTEST_FLAG_NONE; - if ( nHeaderWidth > 0 ) - dcPaint.Draw3dRect( CRect( rcHeader.left, rcHeader.top, rcHeader.right + 2, rcHeader.bottom ), m_rgbHeaderBorder, m_rgbHeaderShadow ); + // Are we over the header? + if (HitTestHeader(point, nColumn, nHeaderFlags)) + { + CListColumn listColumn; + if (!GetColumn(nColumn, listColumn)) + return; - } - - void DrawRoundRect( CDCHandle dcPaint, CRect& rcRect, COLORREF rgbOuter, COLORREF rgbInner ) - { - CRect rcRoundRect( rcRect ); - - CPen penBorder; - penBorder.CreatePen( PS_SOLID, 1, rgbOuter ); - CBrush bshInterior; - bshInterior.CreateSolidBrush( m_rgbBackground ); - - dcPaint.SelectPen( penBorder ); - dcPaint.SelectBrush( bshInterior ); - - dcPaint.RoundRect( rcRoundRect, CPoint( 5, 5 ) ); - rcRoundRect.DeflateRect( 1, 1 ); - - CPen penInnerBorder; - penInnerBorder.CreatePen( PS_SOLID, 1, rgbInner ); - dcPaint.SelectPen( penInnerBorder ); - - dcPaint.RoundRect( rcRoundRect, CPoint( 2, 2 ) ); - } - - void DrawGradient( CDCHandle dcPaint, CRect& rcRect, COLORREF rgbTop, COLORREF rgbBottom ) - { - GRADIENT_RECT grdRect = { 0, 1 }; - TRIVERTEX triVertext[ 2 ] = { - rcRect.left, - rcRect.top, - (COLOR16)(GetRValue( rgbTop ) << 8), - (COLOR16)(GetGValue( rgbTop ) << 8), - (COLOR16)(GetBValue( rgbTop ) << 8), - (COLOR16)(0x0000), - rcRect.right, - rcRect.bottom, - (COLOR16)(GetRValue( rgbBottom ) << 8), - (COLOR16)(GetGValue( rgbBottom ) << 8), - (COLOR16)(GetBValue( rgbBottom ) << 8), - (COLOR16)(0x0000) - }; - - dcPaint.GradientFill( triVertext, 2, &grdRect, 1, GRADIENT_FILL_RECT_V ); - } - - void DrawList( CDCHandle dcPaint ) - { - T* pT = static_cast(this); - - CRect rcClip; - if ( dcPaint.GetClipBox( rcClip ) == ERROR ) - return; - - CRect rcItem; - rcItem.left = -GetScrollPos( SB_HORZ ); - rcItem.right = GetTotalWidth(); - rcItem.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - rcItem.bottom = rcItem.top; - - // Draw all visible items - for ( int nItem = GetTopItem(); nItem < pT->GetItemCount(); rcItem.top = rcItem.bottom, nItem++ ) - { - rcItem.bottom = rcItem.top + m_nItemHeight; - - if ( rcItem.bottom < rcClip.top || rcItem.right < rcClip.left ) - continue; - if ( rcItem.top > rcClip.bottom || rcItem.left > rcClip.right ) - break; - - // May be implemented in a derived class - pT->DrawItem( dcPaint, nItem, rcItem ); - } - } - - void DrawItem( CDCHandle dcPaint, int nItem, CRect& rcItem ) - { - T* pT = static_cast(this); - - CRect rcClip; - if ( dcPaint.GetClipBox( rcClip ) == ERROR ) - return; - - int nFocusItem = NULL_ITEM; - int nFocusSubItem = NULL_SUBITEM; - GetFocusItem( nFocusItem, nFocusSubItem ); - - BOOL bSelectedItem = IsSelected( nItem ); - //BOOL bControlFocus = ( GetFocus() == m_hWnd || m_bEditItem ); - - // Draw selected background - if ( bSelectedItem ) - { - dcPaint.SetBkColor( m_rgbSelectedItem ); - dcPaint.ExtTextOut( rcItem.left, rcItem.top, ETO_OPAQUE, rcItem, _T( "" ), 0, nullptr ); - } - - CRect rcSubItem( rcItem ); - rcSubItem.right = rcSubItem.left; - - for ( int nSubItem = 0, nColumnCount = GetColumnCount(); nSubItem < nColumnCount; rcSubItem.left = rcSubItem.right + 1, nSubItem++ ) - { - CListColumn listColumn; - if ( !GetColumn( nSubItem, listColumn ) ) - break; - - rcSubItem.right = rcSubItem.left + listColumn.m_nWidth - 1; - - if ( rcSubItem.right < rcClip.left || rcSubItem.Width() == 0 ) - continue; - if ( rcSubItem.left > rcClip.right ) - break; - - LPCTSTR strItemText = pT->GetItemText( nItem, listColumn.m_nIndex ); - int nItemImage = pT->GetItemImage( nItem, listColumn.m_nIndex ); - UINT nItemFormat = pT->GetItemFormat( nItem, listColumn.m_nIndex ); - UINT nItemFlags = pT->GetItemFlags( nItem, listColumn.m_nIndex ); - - // Custom draw subitem format - if ( nItemFormat == ITEM_FORMAT_CUSTOM ) - { - pT->DrawCustomItem( dcPaint, nItem, nSubItem, rcSubItem ); - return; - } - - BOOL bFocusSubItem = ( m_bFocusSubItem && nFocusItem == nItem && nFocusSubItem == nSubItem ); - - COLORREF rgbBackground = m_rgbBackground; - COLORREF rgbText = m_rgbItemText; - - if ( bFocusSubItem ) - { - dcPaint.SetBkColor( m_bEditItem ? m_rgbBackground : m_rgbItemFocus ); - dcPaint.ExtTextOut( rcSubItem.left, rcSubItem.top, ETO_OPAQUE, rcSubItem, _T( "" ), 0, nullptr ); - - if ( m_bEditItem ) - { - CBrush bshSelectFrame; - bshSelectFrame.CreateSolidBrush( m_rgbItemFocus ); - dcPaint.FrameRect( rcSubItem, bshSelectFrame ); - } - } - else if ( pT->GetItemColours( nItem, nSubItem, rgbBackground, rgbText ) && rgbBackground != m_rgbBackground ) - { - CPen penBorder; - penBorder.CreatePen( PS_SOLID, 1, rgbBackground ); - CBrush bshInterior; - bshInterior.CreateSolidBrush( rgbBackground ); - - dcPaint.SelectPen( penBorder ); - dcPaint.SelectBrush( bshInterior ); - - dcPaint.RoundRect( rcSubItem, CPoint( 3, 3 ) ); - } - - CRect rcItemText( rcSubItem ); - - // margin item text - //rcItemText.left += nSubItem == 0 ? 4 : 3; - //rcItemText.DeflateRect( 4, 0 ); - - // Draw subitem image if supplied - if ( !m_ilItemImages.IsNull() && nItemImage != ITEM_IMAGE_NONE && ( !m_bEditItem || ( m_bEditItem && !bFocusSubItem ) ) ) - { - CSize sizeIcon; - m_ilItemImages.GetIconSize( sizeIcon ); - - CRect rcItemImage; - rcItemImage.left = (strItemText[0] == 0) ? ( ( rcItemText.left + rcItemText.right ) / 2 ) - ( sizeIcon.cx / 2 ) - ( 0 ) : rcItemText.left; - rcItemImage.right = min( rcItemImage.left + sizeIcon.cx, rcSubItem.right ); - rcItemImage.top = ( ( rcSubItem.top + rcSubItem.bottom ) / 2 ) - ( sizeIcon.cy / 2 ); - rcItemImage.bottom = min( rcItemImage.top + sizeIcon.cy, rcSubItem.bottom ); - - m_ilItemImages.DrawEx( nItemImage, dcPaint, rcItemImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); - - // Offset item text (for image) - rcItemText.left += sizeIcon.cx + 4; - } - - if ( rcItemText.IsRectEmpty() ) - continue; - - COLORREF rgbSelectedText = m_rgbSelectedText; - pT->GetItemSelectedColours( nItem, nSubItem, rgbSelectedText ); + if (!listColumn.m_bFixed && (nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER)) + { + SetCursor(m_curDivider); - dcPaint.SelectFont( pT->GetItemFont( nItem, nSubItem ) ); - dcPaint.SetTextColor( ( bSelectedItem && !bFocusSubItem ) ? rgbSelectedText : rgbText ); - dcPaint.SetBkMode( TRANSPARENT ); + // Begin column resizing + m_bColumnSizing = TRUE; + m_nColumnSizing = nColumn; + m_nStartSize = listColumn.m_nWidth; + m_nStartPos = GET_X_LPARAM(GetMessagePos()); + } + else if (m_bSortEnabled) // Added by Rowan 05/12/2006 + { + m_nHighlightColumn = nColumn; + InvalidateHeader(); + } - UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + return; + } - if ( nItemFlags & ITEM_FLAGS_CENTRE ) - nFormat |= DT_CENTER; - else if ( nItemFlags & ITEM_FLAGS_RIGHT ) - nFormat |= DT_RIGHT; - else - nFormat |= DT_LEFT; - - switch ( nItemFormat ) - { - case ITEM_FORMAT_DATETIME: if ( strItemText[0] != 0 ) - { - SYSTEMTIME stItemDate; - if ( !GetItemDate( nItem, listColumn.m_nIndex, stItemDate ) ) - break; - - stdstr strItemDate; - if ( nItemFlags & ITEM_FLAGS_DATE_ONLY ) - strItemDate = FormatDate( stItemDate ); - else if ( nItemFlags & ITEM_FLAGS_TIME_ONLY ) - strItemDate = FormatTime( stItemDate ); - else - strItemDate = FormatDate( stItemDate ) + _T( " " ) + FormatTime( stItemDate ); - dcPaint.DrawText( strItemDate.c_str(), (int)strItemDate.length(), rcItemText, nFormat ); - } - break; - case ITEM_FORMAT_CHECKBOX: - case ITEM_FORMAT_CHECKBOX_3STATE: { - CSize sizeIcon; - m_ilListItems.GetIconSize( sizeIcon ); - - CRect rcCheckBox; - rcCheckBox.left = ( ( rcItemText.left + rcItemText.right ) / 2 ) - ( sizeIcon.cx / 2 ) - 1; - rcCheckBox.right = min( rcCheckBox.left + sizeIcon.cx, rcSubItem.right ); - rcCheckBox.top = ( ( rcSubItem.top + rcSubItem.bottom ) / 2 ) - ( sizeIcon.cy / 2 ); - rcCheckBox.bottom = min( rcCheckBox.top + sizeIcon.cy, rcSubItem.bottom ); - - int nCheckValue = _ttoi( strItemText ); - - if ( nItemFormat == ITEM_FORMAT_CHECKBOX ) - m_ilListItems.DrawEx( nCheckValue > 0 ? ITEM_IMAGE_CHECK_ON : ITEM_IMAGE_CHECK_OFF, dcPaint, rcCheckBox, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); - else - { - int nCheckImage = ITEM_IMAGE_3STATE_UNDEF; - if ( nCheckValue < 0 ) - nCheckImage = ITEM_IMAGE_3STATE_OFF; - else if ( nCheckValue > 0 ) - nCheckImage = ITEM_IMAGE_3STATE_ON; - m_ilListItems.DrawEx( nCheckImage, dcPaint, rcCheckBox, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT ); - } - } - break; - case ITEM_FORMAT_PROGRESS: { - CRect rcProgress( rcSubItem ); - rcProgress.DeflateRect( 3, 2 ); - - // Draw progress border - DrawRoundRect( dcPaint, rcProgress, m_rgbHeaderShadow, m_rgbHeaderBackground ); - - // Fill progress bar area - rcProgress.DeflateRect( 3, 3 ); - rcProgress.right = rcProgress.left + (int)( (double)rcProgress.Width() * ( ( max( min( atof( strItemText ), 100 ), 0 ) ) / 100.0 ) ); - DrawGradient( dcPaint, rcProgress, m_rgbProgressTop, m_rgbProgressBottom ); - } - break; - case ITEM_FORMAT_HYPERLINK: if ( nItem == m_nHotItem && nSubItem == m_nHotSubItem && !( nItemFlags & ITEM_FLAGS_READ_ONLY ) ) - { - dcPaint.SelectFont( m_fntUnderlineFont ); - dcPaint.SetTextColor( m_rgbHyperLink ); - } - default: // Draw item text - { - size_t len = strlen(strItemText); - if ( len > 0 ) - dcPaint.DrawText( strItemText, (int)len, rcItemText, nFormat ); + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; - } - - break; - } - } - } - - void DrawSelect( CDCHandle dcPaint ) - { - if ( !m_bGroupSelect ) - return; - - int nHorzScroll = GetScrollPos( SB_HORZ ); - int nVertScroll = GetScrollPos( SB_VERT ); - - CRect rcGroupSelect( m_rcGroupSelect ); - rcGroupSelect.OffsetRect( -nHorzScroll, -nVertScroll ); - - CRect rcClient; - GetClientRect( rcClient ); - rcClient.top = ( m_bShowHeader ? m_nHeaderHeight : 0 ); - - // Limit box to list client area if scrolled to limits - if ( nHorzScroll > ( GetTotalWidth() - rcClient.Width() ) ) - rcGroupSelect.right = min( rcClient.right, rcGroupSelect.right ); - if ( nHorzScroll == 0 ) - rcGroupSelect.left = max( rcClient.left, rcGroupSelect.left ); - if ( nVertScroll > ( GetTotalHeight() - rcClient.Height() ) ) - rcGroupSelect.bottom = min( rcClient.bottom, rcGroupSelect.bottom ); - if ( nVertScroll == 0 ) - rcGroupSelect.top = max( rcClient.top, rcGroupSelect.top ); - - // Limit bitmap to client area - CRect rcSelectArea( rcGroupSelect ); - rcSelectArea.IntersectRect( rcSelectArea, rcClient ); - - CDC dcBackground; - dcBackground.CreateCompatibleDC( dcPaint ); - - int nBackgroundContext = dcBackground.SaveDC(); - - CBitmap bmpBackground; - bmpBackground.CreateCompatibleBitmap( dcPaint, rcSelectArea.Width(), rcSelectArea.Height() ); - dcBackground.SelectBitmap( bmpBackground ); - - // Take a copy of existing background - dcBackground.BitBlt( 0, 0, rcSelectArea.Width(), rcSelectArea.Height(), dcPaint, rcSelectArea.left, rcSelectArea.top, SRCCOPY ); - - CDC dcGroupSelect; - dcGroupSelect.CreateCompatibleDC( dcPaint ); - - int nGroupSelectContext = dcGroupSelect.SaveDC(); - - CBitmap bmpGroupSelect; - bmpGroupSelect.CreateCompatibleBitmap( dcPaint, rcSelectArea.Width(), rcSelectArea.Height() ); - dcGroupSelect.SelectBitmap( bmpGroupSelect ); - - // Draw group select box - dcGroupSelect.SetBkColor( m_rgbItemFocus ); - dcGroupSelect.ExtTextOut( 0, 0, ETO_OPAQUE, CRect( CPoint( 0 ), rcSelectArea.Size() ), _T( "" ), 0, nullptr ); - - BLENDFUNCTION blendFunction; - blendFunction.BlendOp = AC_SRC_OVER; - blendFunction.BlendFlags = 0; - blendFunction.SourceConstantAlpha = 180; - blendFunction.AlphaFormat = 0; - - // Blend existing background with selection box - dcGroupSelect.AlphaBlend( 0, 0, rcSelectArea.Width(), rcSelectArea.Height(), dcBackground, 0, 0, rcSelectArea.Width(), rcSelectArea.Height(), blendFunction ); - - // Draw blended selection box - dcPaint.BitBlt( rcSelectArea.left, rcSelectArea.top, rcSelectArea.Width(), rcSelectArea.Height(), dcGroupSelect, 0, 0, SRCCOPY ); - - // Draw selection box frame - CBrush bshSelectFrame; - bshSelectFrame.CreateSolidBrush( m_rgbItemText ); - dcPaint.FrameRect( rcGroupSelect, bshSelectFrame ); - - dcBackground.RestoreDC( nBackgroundContext ); - dcGroupSelect.RestoreDC( nGroupSelectContext ); - } - - void DrawCustomItem( CDCHandle dcPaint, int /*nItem*/, int /*nSubItem*/, CRect& /*rcSubItem*/ ) - { - ATLASSERT( FALSE ); // Must be implemented in a derived class - } + if (!HitTest(point, nItem, nSubItem)) + { + m_nFirstSelected = NULL_ITEM; + m_bBeginSelect = TRUE; + } + else + { + // Do not begin group select from first columns + if (!(nFlags & MK_SHIFT) && !(nFlags & MK_CONTROL) && nSubItem != 0) + { + m_bBeginSelect = TRUE; + m_nFirstSelected = nItem; + } + + // Only select item if not already selected + if ((nFlags & MK_SHIFT) || (nFlags & MK_CONTROL) || !IsSelected(nItem) || m_setSelectedItems.size() <= 1) + SelectItem(nItem, nSubItem, nFlags); + + int nIndex = GetColumnIndex(nSubItem); + if (!(pT->GetItemFlags(nItem, nIndex) & ITEM_FLAGS_READ_ONLY)) + { + switch (pT->GetItemFormat(nItem, nIndex)) + { + case ITEM_FORMAT_CHECKBOX: + m_bBeginSelect = FALSE; + pT->SetItemText(nItem, nIndex, _ttoi(pT->GetItemText(nItem, nIndex)) > 0 ? _T( "0" ) : _T( "1" )); + NotifyParent(nItem, nSubItem, LCN_MODIFIED); + InvalidateItem(nItem); + break; + case ITEM_FORMAT_CHECKBOX_3STATE: + { + m_bBeginSelect = FALSE; + + int nCheckImage = _ttoi(pT->GetItemText(nItem, nIndex)); + if (nCheckImage < 0) + pT->SetItemText(nItem, nIndex, _T( "0" )); + else if (nCheckImage > 0) + pT->SetItemText(nItem, nIndex, _T( "-1" )); + else + pT->SetItemText(nItem, nIndex, _T( "1" )); + + NotifyParent(nItem, nSubItem, LCN_MODIFIED); + InvalidateItem(nItem); + } + break; + case ITEM_FORMAT_HYPERLINK: + m_bBeginSelect = FALSE; + SetCursor(m_curHyperLink); + NotifyParent(nItem, nSubItem, LCN_HYPERLINK); + break; + } + + if ((pT->GetItemFlags(nItem, nIndex) & ITEM_FLAGS_HIT_NOTIFY) != 0) + { + NotifyParent(nItem, nSubItem, LCN_HITTEST); + } + } + } + } + + void OnLButtonUp(UINT nFlags, CPoint point) + { + if (m_bButtonDown) + ReleaseCapture(); + + // Finish resizing or selecting a column + if (m_bColumnSizing || m_nHighlightColumn != NULL_COLUMN) + { + // Are we changing the sort order? + if (!m_bColumnSizing && m_nHighlightColumn != NULL_COLUMN && m_bSortEnabled) // Changed by Rowan 05/12/2006 + //if ( !m_bColumnSizing && m_nHighlightColumn != NULL_COLUMN) + SortColumn(m_nHighlightColumn); + + m_bColumnSizing = FALSE; + m_nColumnSizing = NULL_COLUMN; + m_nHighlightColumn = NULL_COLUMN; + m_nStartSize = 0; + m_nStartPos = 0; + + InvalidateHeader(); + } + + m_bBeginSelect = FALSE; + m_bButtonDown = FALSE; + m_ptDownPoint = 0; + m_ptSelectPoint = 0; + + // Have we finished a group select? + if (m_bGroupSelect) + { + m_bGroupSelect = FALSE; + Invalidate(); + } + else + { + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + // Deselect item if current item is selected + if (HitTest(point, nItem, nSubItem) && IsSelected(nItem) && m_setSelectedItems.size() > 1 && !(nFlags & MK_SHIFT) && !(nFlags & MK_CONTROL)) + SelectItem(nItem, nSubItem, nFlags); + + // Notify parent of left-click item + NotifyParent(nItem, nSubItem, LCN_LEFTCLICK); + } + } + + void OnLButtonDblClk(UINT /*nFlags*/, CPoint point) + { + + HideTitleTip(FALSE); + + // Handle double-clicks (for drawing) + SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(point.x, point.y)); + + int nColumn = NULL_COLUMN; + UINT nHeaderFlags = HITTEST_FLAG_NONE; + + // Resize column if double-click on a divider + if (HitTestHeader(point, nColumn, nHeaderFlags) && (nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER)) + AutoSizeColumn(nColumn); + + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + HitTest(point, nItem, nSubItem); + + //WriteTraceF(TraceInfo, "List Ctrl Double Click, Item: %d", nItem); + + // Notify parent of double-clicked item + NotifyParent(nItem, nSubItem, LCN_DBLCLICK); + } + + void OnRButtonDown(UINT nFlags, CPoint point) + { + // Stop any pending scroll + EndScroll(); + + SetFocus(); + + HideTitleTip(FALSE); + + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + if (m_bRightClickSelect) + { + // Only select item if not already selected (deselect in OnLButtonUp) + if (HitTest(point, nItem, nSubItem) && !IsSelected(nItem)) + SelectItem(nItem, nSubItem, nFlags); + } + } + + void OnRButtonUp(UINT /*nFlags*/, CPoint point) + { + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + if (!HitTest(point, nItem, nSubItem)) + ResetSelected(); + + // Notify parent of right-click item + NotifyParent(nItem, nSubItem, LCN_RIGHTCLICK); + } + + void OnMouseMove(UINT nFlags, CPoint point) + { + T * pT = static_cast(this); + + if (!(nFlags & MK_LBUTTON)) + { + if (m_bButtonDown) + ReleaseCapture(); + + m_bButtonDown = FALSE; + } + + if (!m_bMouseOver) + { + m_bMouseOver = TRUE; + + TRACKMOUSEEVENT trkMouse; + trkMouse.cbSize = sizeof(TRACKMOUSEEVENT); + trkMouse.dwFlags = TME_LEAVE; + trkMouse.hwndTrack = m_hWnd; + + // Notify when the mouse leaves button + _TrackMouseEvent(&trkMouse); + } + + if (m_bButtonDown) + { + // Are we resizing a column? + if (m_bColumnSizing) + { + ResizeColumn(); + return; + } + + // Are we beginning to drag a column? + if (m_nHighlightColumn != NULL_COLUMN && (point.x < m_ptDownPoint.x - DRAG_HEADER_OFFSET || point.x > m_ptDownPoint.x + DRAG_HEADER_OFFSET || point.y < m_ptDownPoint.y - DRAG_HEADER_OFFSET || point.y > m_ptDownPoint.y + DRAG_HEADER_OFFSET)) + { + DragColumn(); + return; + } + + // Are we beginning a group select or dragging an item? + if (point.x < m_ptDownPoint.x - DRAG_ITEM_OFFSET || point.x > m_ptDownPoint.x + DRAG_ITEM_OFFSET || point.y < m_ptDownPoint.y - DRAG_ITEM_OFFSET || point.y > m_ptDownPoint.y + DRAG_ITEM_OFFSET) + { + if (m_bBeginSelect || !m_bDragDrop) + m_bGroupSelect = (!m_bSingleSelect && !m_bEditItem); + else + { + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + if (HitTest(point, nItem, nSubItem)) + { + // Select the drag item (if not already selected) + if (!IsSelected(nItem)) + SelectItem(nItem, nSubItem, nFlags); + + // Begin drag item operation + pT->DragItem(); + } + } + } + + if (m_bGroupSelect) + { + GroupSelect(point); + return; + } + } + else + { + int nColumn = NULL_COLUMN; + UINT nHeaderFlags = HITTEST_FLAG_NONE; + + // Are we over the header? + BOOL bHitTestHeader = HitTestHeader(point, nColumn, nHeaderFlags); + + if (bHitTestHeader) + { + HideTitleTip(); + CListColumn listColumn; + if (GetColumn(nColumn, listColumn) && !listColumn.m_bFixed && (nHeaderFlags & HITTEST_FLAG_HEADER_DIVIDER)) + SetCursor(m_curDivider); + else + { + // Get tooltip for this item + stdstr strToolTip = pT->GetHeaderToolTip(nColumn); + if (!strToolTip.empty()) + { + CRect rcColumn; + if (!GetColumnRect(nColumn, rcColumn)) + return; + rcColumn.bottom = m_nHeaderHeight; + m_ttToolTip.Activate(TRUE); + m_ttToolTip.AddTool(m_hWnd, (LPCTSTR)strToolTip.c_str(), rcColumn, TOOLTIP_TOOL_ID); + } + } + return; + } + + int nItem = NULL_ITEM; + int nSubItem = NULL_SUBITEM; + + if (!HitTest(point, nItem, nSubItem)) + { + if (m_nHotItem != NULL_ITEM && m_nHotSubItem != NULL_SUBITEM) + { + // Redraw old hot item + int nIndex = GetColumnIndex(m_nHotSubItem); + if (pT->GetItemFormat(m_nHotItem, nIndex) == ITEM_FORMAT_HYPERLINK && !(pT->GetItemFlags(m_nHotItem, nIndex) & ITEM_FLAGS_READ_ONLY)) + InvalidateItem(m_nHotItem, m_nHotSubItem); + } + + m_ttToolTip.Activate(FALSE); + m_ttToolTip.DelTool(m_hWnd, TOOLTIP_TOOL_ID); + + m_nHotItem = NULL_ITEM; + m_nHotSubItem = NULL_SUBITEM; + HideTitleTip(); + } + else + { + // Has the hot item changed? + if (nItem != m_nHotItem || nSubItem != m_nHotSubItem) + { + // Redraw old hot item + int nIndex = GetColumnIndex(m_nHotSubItem); + if (pT->GetItemFormat(m_nHotItem, nIndex) == ITEM_FORMAT_HYPERLINK && !(pT->GetItemFlags(m_nHotItem, nIndex) & ITEM_FLAGS_READ_ONLY)) + InvalidateItem(m_nHotItem, m_nHotSubItem); + + m_nHotItem = nItem; + m_nHotSubItem = nSubItem; + + NotifyParent(nItem, nSubItem, LCN_HOTITEMCHANGED); + } + + int nIndex = GetColumnIndex(m_nHotSubItem); + UINT nItemFormat = pT->GetItemFormat(m_nHotItem, nIndex); + UINT nItemFlags = pT->GetItemFlags(m_nHotItem, nIndex); + + // Draw new hot hyperlink item + if (nItemFormat == ITEM_FORMAT_HYPERLINK && !(nItemFlags & ITEM_FLAGS_READ_ONLY)) + { + InvalidateItem(m_nHotItem, m_nHotSubItem); + SetCursor(m_curHyperLink); + } + + // Get tooltip for this item + stdstr strToolTip = pT->GetItemToolTip(m_nHotItem, nIndex); + + CRect rcSubItem; + if (!strToolTip.empty() && GetItemRect(m_nHotItem, rcSubItem)) + { + m_ttToolTip.Activate(TRUE); + m_ttToolTip.AddTool(m_hWnd, (LPCTSTR)strToolTip.substr(0, SHRT_MAX).c_str(), rcSubItem, TOOLTIP_TOOL_ID); + } + else + { + m_ttToolTip.Activate(FALSE); + m_ttToolTip.DelTool(m_hWnd, TOOLTIP_TOOL_ID); + } + + // Show title tips for this item + ShowTitleTip(point, m_nHotItem, m_nHotSubItem); + } + } + } + + void OnMouseLeave() + { + m_bMouseOver = FALSE; + + if (m_nHotColumn != NULL_COLUMN) + { + m_nHotColumn = NULL_COLUMN; + InvalidateHeader(); + } + + if (m_nHotItem != NULL_ITEM || m_nHotSubItem != NULL_SUBITEM) + { + m_nHotItem = NULL_ITEM; + m_nHotSubItem = NULL_SUBITEM; + Invalidate(); + } + } + + BOOL OnMouseWheel(UINT /*nFlags*/, short nDelta, CPoint /*point*/) + { + HideTitleTip(); + + // End any pending edit + if (m_bEditItem) + SetFocus(); + + int nRowsScrolled = m_nMouseWheelScroll * nDelta / 120; + int nScrollPos = GetScrollPos(SB_VERT); + + if (nRowsScrolled > 0) + nScrollPos = max(nScrollPos - (nRowsScrolled * m_nItemHeight), 0); + else + nScrollPos += (-nRowsScrolled * m_nItemHeight); + + ResetScrollBars(SB_VERT, nScrollPos, FALSE); + Invalidate(); + + return TRUE; + } + + void OnTimer(UINT_PTR nIDEvent) + { + switch (nIDEvent) + { + case RESIZE_COLUMN_TIMER: + ResizeColumn(TRUE); + break; + case ITEM_VISIBLE_TIMER: + { + KillTimer(ITEM_VISIBLE_TIMER); + + int nFocusItem = NULL_ITEM; + int nFocusSubItem = NULL_SUBITEM; + + // Get current focus item + if (!GetFocusItem(nFocusItem, nFocusSubItem)) + break; + + // Make sure current focus item is visible before editing + if (!EditItem(nFocusItem, nFocusSubItem)) + break; + } + break; + case ITEM_AUTOSCROLL_TIMER: + if (!m_bGroupSelect) + KillTimer(ITEM_AUTOSCROLL_TIMER); + else + { + DWORD dwPoint = GetMessagePos(); + CPoint ptMouse(GET_X_LPARAM(dwPoint), GET_Y_LPARAM(dwPoint)); + ScreenToClient(&ptMouse); + + // Automatically scroll when group selecting + AutoScroll(ptMouse); + AutoSelect(ptMouse); + } + break; + case ITEM_SCROLL_TIMER: + if (!ScrollList()) + EndScroll(); + break; + } + } + + void OnKeyDown(TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) + { + T * pT = static_cast(this); + + // Stop any pending scroll + EndScroll(); + + BOOL bCtrlKey = ((GetKeyState(VK_CONTROL) & 0x8000) != 0); + BOOL bShiftKey = ((GetKeyState(VK_SHIFT) & 0x8000) != 0); + + CRect rcClient; + GetClientRect(rcClient); + + int nFocusItem = NULL_ITEM; + int nFocusSubItem = NULL_SUBITEM; + GetFocusItem(nFocusItem, nFocusSubItem); + + switch (nChar) + { + case VK_DOWN: + SetFocusItem(min(nFocusItem + 1, pT->GetItemCount() - 1), nFocusSubItem); + break; + case VK_UP: + SetFocusItem(max(nFocusItem - 1, 0), nFocusSubItem); + break; + case VK_NEXT: + SetFocusItem(min(nFocusItem + GetCountPerPage(FALSE) - 1, pT->GetItemCount() - 1), nFocusSubItem); + break; + case VK_PRIOR: + SetFocusItem(max(nFocusItem - GetCountPerPage(FALSE) + 1, 0), nFocusSubItem); + break; + case VK_HOME: + SetFocusItem(0, nFocusSubItem); + break; + case VK_END: + SetFocusItem(pT->GetItemCount() - 1, nFocusSubItem); + break; + case VK_LEFT: + if (m_bFocusSubItem) + SetFocusItem(nFocusItem, max(nFocusSubItem - 1, 0)); + else + SetScrollPos(SB_HORZ, max(GetScrollPos(SB_HORZ) - (bCtrlKey ? ITEM_SCROLL_OFFSET * 10 : ITEM_SCROLL_OFFSET), 0)); + break; + case VK_RIGHT: + if (m_bFocusSubItem) + SetFocusItem(nFocusItem, min(nFocusSubItem + 1, GetColumnCount() - 1)); + else + SetScrollPos(SB_HORZ, min(GetScrollPos(SB_HORZ) + (bCtrlKey ? ITEM_SCROLL_OFFSET * 10 : ITEM_SCROLL_OFFSET), rcClient.Width())); + break; + case VK_TAB: + if (!bCtrlKey && m_bFocusSubItem) + SetFocusItem(nFocusItem, bShiftKey ? max(nFocusSubItem - 1, 0) : min(nFocusSubItem + 1, GetColumnCount() - 1)); + break; + default: + if (nChar == VK_SPACE) + { + int nIndex = GetColumnIndex(nFocusSubItem); + if (!(pT->GetItemFlags(nFocusItem, nIndex) & ITEM_FLAGS_READ_ONLY)) + { + switch (pT->GetItemFormat(nFocusItem, nIndex)) + { + case ITEM_FORMAT_CHECKBOX: + pT->SetItemText(nFocusItem, nIndex, _ttoi(pT->GetItemText(nFocusItem, nIndex)) > 0 ? _T( "0" ) : _T( "1" )); + NotifyParent(nFocusItem, nFocusSubItem, LCN_MODIFIED); + InvalidateItem(nFocusItem); + return; + case ITEM_FORMAT_CHECKBOX_3STATE: + { + int nCheckImage = _ttoi(pT->GetItemText(nFocusItem, nIndex)); + if (nCheckImage < 0) + pT->SetItemText(nFocusItem, nIndex, _T( "0" )); + else if (nCheckImage > 0) + pT->SetItemText(nFocusItem, nIndex, _T( "-1" )); + else + pT->SetItemText(nFocusItem, nIndex, _T( "1" )); + + NotifyParent(nFocusItem, nFocusSubItem, LCN_MODIFIED); + InvalidateItem(nFocusItem); + } + return; + } + } + } + + if (bCtrlKey && nChar == _T('A') && !m_bSingleSelect) + { + m_setSelectedItems.clear(); + for (int nItem = 0; nItem < pT->GetItemCount(); nItem++) + m_setSelectedItems.insert(nItem); + Invalidate(); + return; + } + + if (!bCtrlKey && iswprint(nChar) && iswupper(nChar)) + { + int nSortIndex = GetColumnIndex(m_nSortColumn); + int nStartItem = nFocusItem + 1; + DWORD dwCurrentTick = GetTickCount(); + + stdstr strStart; + strStart += nChar; + + // Has there been another keypress since last search period? + if ((dwCurrentTick - m_dwSearchTick) < SEARCH_PERIOD) + { + if (m_strSearchString.substr(0, 1) != strStart) + m_strSearchString += nChar; + + stdstr strFocusText = pT->GetItemText(nFocusItem, nSortIndex); + + // Are we continuing to type characters under current focus item? + if (m_strSearchString.length() > 1 && _tcsicmp(m_strSearchString.c_str(), strFocusText.substr(0, m_strSearchString.length()).c_str()) == 0) + { + m_dwSearchTick = GetTickCount(); + return; + } + } + else + { + if (m_strSearchString.substr(0, 1) != strStart) + nStartItem = 0; + m_strSearchString = strStart; + } + + m_dwSearchTick = GetTickCount(); + + // Scan for next search string + for (int nFirst = nStartItem; nFirst < pT->GetItemCount(); nFirst++) + { + stdstr strItemText = pT->GetItemText(nFirst, nSortIndex); + + if (_tcsicmp(m_strSearchString.c_str(), strItemText.substr(0, m_strSearchString.length()).c_str()) == 0) + { + SelectItem(nFirst, nFocusSubItem, TRUE); + EnsureItemVisible(nFirst, nFocusSubItem); + return; + } + } + + // Rescan from top if not found search string + for (int nSecond = 0; nSecond < pT->GetItemCount(); nSecond++) + { + stdstr strItemText = pT->GetItemText(nSecond, nSortIndex); + + if (_tcsicmp(m_strSearchString.c_str(), strItemText.substr(0, m_strSearchString.length()).c_str()) == 0) + { + SelectItem(nSecond, nFocusSubItem, TRUE); + EnsureItemVisible(nSecond, nFocusSubItem); + return; + } + } + } + return; + } + + if (!bCtrlKey) + SelectItem(m_nFocusItem, m_nFocusSubItem, bShiftKey ? MK_SHIFT : 0); + } + + void OnSysKeyDown(TCHAR /*nChar*/, UINT /*nRepCnt*/, UINT /*nFlags*/) + { + HideTitleTip(FALSE); + SetMsgHandled(FALSE); + } + + void OnSettingsChange(UINT /*nFlags*/, LPCTSTR /*lpszSection*/) + { + OnSettingsChange(); + } + + void OnSettingsChange() + { + LoadSettings(); + ResetScrollBars(); + Invalidate(); + } + + LRESULT OnCtlColorListBox(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/) + { + return DefWindowProc(nMsg, wParam, lParam); + } + + LRESULT OnEndEdit(LPNMHDR lpNMHDR) + { + T * pT = static_cast(this); + CListNotify * pListNotify = reinterpret_cast(lpNMHDR); + + m_bEditItem = FALSE; + int nIndex = GetColumnIndex(pListNotify->m_nSubItem); + + switch (pListNotify->m_nExitChar) + { + case VK_ESCAPE: break; // Do nothing + case VK_DELETE: + pT->SetItemText(pListNotify->m_nItem, nIndex, _T( "" )); + NotifyParent(pListNotify->m_nItem, pListNotify->m_nSubItem, LCN_MODIFIED); + break; + default: + if (pListNotify->m_lpItemDate == nullptr) + pT->SetItemText(pListNotify->m_nItem, nIndex, pListNotify->m_lpszItemText); + else + { + if (_ttoi(pListNotify->m_lpszItemText) == 0) + pT->SetItemText(pListNotify->m_nItem, nIndex, _T( "" )); + else + pT->SetItemDate(pListNotify->m_nItem, nIndex, *pListNotify->m_lpItemDate); + } + if (pListNotify->m_nExitChar == VK_TAB) + PostMessage(WM_KEYDOWN, (WPARAM)VK_TAB); + NotifyParent(pListNotify->m_nItem, pListNotify->m_nSubItem, LCN_MODIFIED); + break; + } + + InvalidateItem(pListNotify->m_nItem); + + return 0; + } + + DWORD OnDragEnter(FORMATETC & FormatEtc, STGMEDIUM & StgMedium, DWORD /*dwKeyState*/, CPoint point) + { + DWORD dwEffect = DROPEFFECT_NONE; + + if (FormatEtc.cfFormat == m_nHeaderClipboardFormat) + { + LPBYTE lpDragHeader = (LPBYTE)GlobalLock(StgMedium.hGlobal); + if (lpDragHeader == nullptr) + return DROPEFFECT_NONE; + + // Dragged column must originate from this control + if (*((HWND *)lpDragHeader) == m_hWnd) + dwEffect = DropColumn(point) ? DROPEFFECT_MOVE : DROPEFFECT_NONE; + + GlobalUnlock(StgMedium.hGlobal); + } + + return dwEffect; + } + + DWORD OnDragOver(FORMATETC & FormatEtc, STGMEDIUM & StgMedium, DWORD /*dwKeyState*/, CPoint point) + { + DWORD dwEffect = DROPEFFECT_NONE; + + if (FormatEtc.cfFormat == m_nHeaderClipboardFormat) + { + LPBYTE lpDragHeader = (LPBYTE)GlobalLock(StgMedium.hGlobal); + if (lpDragHeader == nullptr) + return DROPEFFECT_NONE; + + // Dragged column must originate from this control + if (*((HWND *)lpDragHeader) == m_hWnd) + dwEffect = DropColumn(point) ? DROPEFFECT_MOVE : DROPEFFECT_NONE; + + GlobalUnlock(StgMedium.hGlobal); + } + + return dwEffect; + } + + BOOL OnDrop(FORMATETC & FormatEtc, STGMEDIUM & /*StgMedium*/, DWORD /*dwEffect*/, CPoint /*point*/) + { + if (FormatEtc.cfFormat == m_nHeaderClipboardFormat) + { + if (m_nDragColumn != NULL_COLUMN && m_nHotDivider != NULL_COLUMN) + { + CListColumn listColumn; + if (!GetColumn(m_nDragColumn, listColumn)) + return FALSE; + + // Move column to new position + m_aColumns.RemoveAt(m_nDragColumn); + m_aColumns.InsertAt((m_nDragColumn < m_nHotColumn ? (m_nHotDivider == 0 ? 0 : m_nHotDivider - 1) : m_nHotDivider), listColumn); + Invalidate(); + } + + return TRUE; + } + + // Not supported + return FALSE; + } + + void OnDragLeave() + { + } + + BOOL OnRenderData(FORMATETC & FormatEtc, STGMEDIUM * pStgMedium, BOOL /*bDropComplete*/) + { + if (FormatEtc.cfFormat == m_nHeaderClipboardFormat) + { + pStgMedium->tymed = TYMED_HGLOBAL; + pStgMedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(HWND)); + if (pStgMedium->hGlobal == nullptr) + return FALSE; + + LPBYTE lpDragHeader = (LPBYTE)GlobalLock(pStgMedium->hGlobal); + if (lpDragHeader == nullptr) + return FALSE; + + // Store this window handle + *((HWND *)lpDragHeader) = m_hWnd; + + GlobalUnlock(pStgMedium->hGlobal); + + return TRUE; + } + + return FALSE; + } + + void DoPaint(CDCHandle dcPaint) + { + T * pT = static_cast(this); + + int nContextState = dcPaint.SaveDC(); + + pT->DrawBkgnd(dcPaint); + pT->DrawList(dcPaint); + pT->DrawSelect(dcPaint); + pT->DrawHeader(dcPaint); + + dcPaint.RestoreDC(nContextState); + } + + void DrawBkgnd(CDCHandle dcPaint) + { + CRect rcClip; + if (dcPaint.GetClipBox(rcClip) == ERROR) + return; + + dcPaint.SetBkColor(m_rgbBackground); + dcPaint.ExtTextOut(rcClip.left, rcClip.top, ETO_OPAQUE, rcClip, _T( "" ), 0, nullptr); + + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + if (!m_bmpBackground.IsNull() && rcClip.bottom > rcClient.top) + { + CSize sizBackground; + m_bmpBackground.GetSize(sizBackground); + + CDC dcBackgroundImage; + dcBackgroundImage.CreateCompatibleDC(dcPaint); + + HBITMAP hOldBitmap = dcBackgroundImage.SelectBitmap(m_bmpBackground); + + if (m_bTileBackground) + { + // Calculate tile image maximum rows and columns + div_t divRows = div((int)rcClient.Height(), (int)sizBackground.cy); + int nTileRows = divRows.rem > 0 ? divRows.quot + 1 : divRows.quot; + div_t divColumns = div((int)rcClient.Width(), (int)sizBackground.cx); + int nTileColumns = divColumns.rem > 0 ? divColumns.quot + 1 : divColumns.quot; + + // Draw tiled background image + for (int nRow = 0; nRow <= nTileRows; nRow++) + { + for (int nColumn = 0; nColumn <= nTileColumns; nColumn++) + dcPaint.BitBlt(nColumn * sizBackground.cx, nRow * sizBackground.cy, sizBackground.cx, sizBackground.cy, dcBackgroundImage, 0, 0, SRCCOPY); + } + } + else + { + CRect rcCentreImage(rcClient); + + // Horizontally center image if smaller than the client width + if (sizBackground.cx < rcClient.Width()) + { + rcCentreImage.left = (rcClient.Width() / 2) - (int)(sizBackground.cx / 2); + rcCentreImage.right = rcCentreImage.left + sizBackground.cx; + } + + // Vertically center image if smaller than the client height + if (sizBackground.cy + 16 < rcClient.Height()) + { + rcCentreImage.top = (rcClient.Height() / 2) - (int)((sizBackground.cy + 16) / 2); + rcCentreImage.bottom = rcCentreImage.top + sizBackground.cy; + } + + // Draw centered background image + dcPaint.BitBlt(rcCentreImage.left, rcCentreImage.top, rcCentreImage.Width(), rcCentreImage.Height(), dcBackgroundImage, 0, 0, SRCCOPY); + } + + dcBackgroundImage.SelectBitmap(hOldBitmap); + } + } + + void DrawHeader(CDCHandle dcPaint) + { + if (!m_bShowHeader) + return; + + CRect rcClip; + if (dcPaint.GetClipBox(rcClip) == ERROR) + return; + + CRect rcHeader; + GetClientRect(rcHeader); + rcHeader.bottom = m_nHeaderHeight; + + if (rcClip.top > rcHeader.bottom) + return; + + dcPaint.SetBkColor(m_rgbHeaderBackground); + dcPaint.ExtTextOut(rcHeader.left, rcHeader.top, ETO_OPAQUE, rcHeader, _T( "" ), 0, nullptr); + + CPen penHighlight; + penHighlight.CreatePen(PS_SOLID, 1, m_rgbHeaderBorder); + CPen penShadow; + penShadow.CreatePen(PS_SOLID, 1, m_rgbHeaderShadow); + + CRect rcHeaderItem(rcHeader); + rcHeaderItem.OffsetRect(-GetScrollPos(SB_HORZ), 0); + + int nHeaderWidth = 0; + + for (int nColumn = 0, nColumnCount = GetColumnCount(); nColumn < nColumnCount; rcHeaderItem.left = rcHeaderItem.right, nColumn++) + { + CListColumn listColumn; + if (!GetColumn(nColumn, listColumn)) + break; + + rcHeaderItem.right = rcHeaderItem.left + listColumn.m_nWidth; + nHeaderWidth += rcHeaderItem.Width(); + + if (rcHeaderItem.right < rcClip.left) + continue; + if (rcHeaderItem.left > rcClip.right) + break; + + // Draw header and divider + if (nColumn == m_nHighlightColumn) + { + dcPaint.SetBkColor(m_rgbHeaderHighlight); + dcPaint.ExtTextOut(rcHeaderItem.left, rcHeaderItem.top, ETO_OPAQUE, rcHeaderItem, _T( "" ), 0, nullptr); + } + + dcPaint.SelectPen(penShadow); + dcPaint.MoveTo(rcHeaderItem.right - 1, rcHeaderItem.top + 1); + dcPaint.LineTo(rcHeaderItem.right - 1, m_nHeaderHeight - 1); + + dcPaint.SelectPen(penHighlight); + dcPaint.MoveTo(rcHeaderItem.right, rcHeaderItem.top + 1); + dcPaint.LineTo(rcHeaderItem.right, m_nHeaderHeight - 1); + + CRect rcHeaderText(rcHeaderItem); + rcHeaderText.left += nColumn == 0 ? 4 : 3; + rcHeaderText.OffsetRect(0, 1); + + BOOL bShowArrow = m_bShowSort && (rcHeaderItem.Width() > 15); + + if (listColumn.m_nImage == ITEM_IMAGE_NONE) + { + // Offset text bounding rectangle to account for sorting arrow + if (bShowArrow && !listColumn.m_bFixed && listColumn.m_nIndex == m_nSortColumn) + rcHeaderText.right -= 15; + } + + // Margin header text + rcHeaderText.DeflateRect(4, 0, 5, 0); + + // Has this header item an associated image? + if (listColumn.m_nImage != ITEM_IMAGE_NONE) + { + CSize sizeIcon; + m_ilListItems.GetIconSize(sizeIcon); + + CRect rcHeaderImage; + rcHeaderImage.left = listColumn.m_strText.empty() ? ((rcHeaderText.left + rcHeaderText.right) / 2) - (sizeIcon.cx / 2) - (0) : rcHeaderText.left; + rcHeaderImage.right = min(rcHeaderImage.left + sizeIcon.cx, rcHeaderItem.right - 2); + rcHeaderImage.top = ((rcHeaderItem.top + rcHeaderItem.bottom) / 2) - (sizeIcon.cy / 2); + rcHeaderImage.bottom = min(rcHeaderImage.top + sizeIcon.cy, rcHeaderItem.bottom); + + if (listColumn.m_nIndex == m_nSortColumn) + m_ilListItems.DrawEx(listColumn.m_nImage, dcPaint, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT | ILD_SELECTED); + else + m_ilListItems.DrawEx(listColumn.m_nImage, dcPaint, rcHeaderImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + + // Offset header text (for image) + rcHeaderText.left += sizeIcon.cx + 4; + } + + dcPaint.SelectFont(m_fntListFont); + dcPaint.SetTextColor(m_rgbHeaderText); + dcPaint.SetBkMode(TRANSPARENT); + + UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + + if (listColumn.m_nFlags & ITEM_FLAGS_CENTRE) + nFormat |= DT_CENTER; + else if (listColumn.m_nFlags & ITEM_FLAGS_RIGHT) + nFormat |= DT_RIGHT; + else + nFormat |= DT_LEFT; + + // Draw header text + if (!rcHeaderText.IsRectEmpty() && !listColumn.m_strText.empty()) + dcPaint.DrawText(listColumn.m_strText.c_str(), (int)listColumn.m_strText.length(), rcHeaderText, nFormat); + + // Draw sorting arrow + if (bShowArrow && !listColumn.m_bFixed && listColumn.m_nIndex == m_nSortColumn) + { + CSize sizeIcon; + m_ilListItems.GetIconSize(sizeIcon); + + CRect rcSortArrow; + rcSortArrow.left = rcHeaderText.right + 4; + rcSortArrow.right = min(rcSortArrow.left + sizeIcon.cx, rcHeaderItem.right); + rcSortArrow.top = rcHeaderItem.Height() / 2 - 3; + rcSortArrow.bottom = min(rcSortArrow.top + sizeIcon.cy, rcHeaderItem.bottom); + + m_ilListItems.DrawEx(m_bSortAscending ? ITEM_IMAGE_UP : ITEM_IMAGE_DOWN, dcPaint, rcSortArrow, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + } + } + + // Draw a frame around all header columns + + if (nHeaderWidth > 0) + dcPaint.Draw3dRect(CRect(rcHeader.left, rcHeader.top, rcHeader.right + 2, rcHeader.bottom), m_rgbHeaderBorder, m_rgbHeaderShadow); + } + + void DrawRoundRect(CDCHandle dcPaint, CRect & rcRect, COLORREF rgbOuter, COLORREF rgbInner) + { + CRect rcRoundRect(rcRect); + + CPen penBorder; + penBorder.CreatePen(PS_SOLID, 1, rgbOuter); + CBrush bshInterior; + bshInterior.CreateSolidBrush(m_rgbBackground); + + dcPaint.SelectPen(penBorder); + dcPaint.SelectBrush(bshInterior); + + dcPaint.RoundRect(rcRoundRect, CPoint(5, 5)); + rcRoundRect.DeflateRect(1, 1); + + CPen penInnerBorder; + penInnerBorder.CreatePen(PS_SOLID, 1, rgbInner); + dcPaint.SelectPen(penInnerBorder); + + dcPaint.RoundRect(rcRoundRect, CPoint(2, 2)); + } + + void DrawGradient(CDCHandle dcPaint, CRect & rcRect, COLORREF rgbTop, COLORREF rgbBottom) + { + GRADIENT_RECT grdRect = {0, 1}; + TRIVERTEX triVertext[2] = { + rcRect.left, + rcRect.top, + (COLOR16)(GetRValue(rgbTop) << 8), + (COLOR16)(GetGValue(rgbTop) << 8), + (COLOR16)(GetBValue(rgbTop) << 8), + (COLOR16)(0x0000), + rcRect.right, + rcRect.bottom, + (COLOR16)(GetRValue(rgbBottom) << 8), + (COLOR16)(GetGValue(rgbBottom) << 8), + (COLOR16)(GetBValue(rgbBottom) << 8), + (COLOR16)(0x0000)}; + + dcPaint.GradientFill(triVertext, 2, &grdRect, 1, GRADIENT_FILL_RECT_V); + } + + void DrawList(CDCHandle dcPaint) + { + T * pT = static_cast(this); + + CRect rcClip; + if (dcPaint.GetClipBox(rcClip) == ERROR) + return; + + CRect rcItem; + rcItem.left = -GetScrollPos(SB_HORZ); + rcItem.right = GetTotalWidth(); + rcItem.top = (m_bShowHeader ? m_nHeaderHeight : 0); + rcItem.bottom = rcItem.top; + + // Draw all visible items + for (int nItem = GetTopItem(); nItem < pT->GetItemCount(); rcItem.top = rcItem.bottom, nItem++) + { + rcItem.bottom = rcItem.top + m_nItemHeight; + + if (rcItem.bottom < rcClip.top || rcItem.right < rcClip.left) + continue; + if (rcItem.top > rcClip.bottom || rcItem.left > rcClip.right) + break; + + // May be implemented in a derived class + pT->DrawItem(dcPaint, nItem, rcItem); + } + } + + void DrawItem(CDCHandle dcPaint, int nItem, CRect & rcItem) + { + T * pT = static_cast(this); + + CRect rcClip; + if (dcPaint.GetClipBox(rcClip) == ERROR) + return; + + int nFocusItem = NULL_ITEM; + int nFocusSubItem = NULL_SUBITEM; + GetFocusItem(nFocusItem, nFocusSubItem); + + BOOL bSelectedItem = IsSelected(nItem); + //BOOL bControlFocus = ( GetFocus() == m_hWnd || m_bEditItem ); + + // Draw selected background + if (bSelectedItem) + { + dcPaint.SetBkColor(m_rgbSelectedItem); + dcPaint.ExtTextOut(rcItem.left, rcItem.top, ETO_OPAQUE, rcItem, _T( "" ), 0, nullptr); + } + + CRect rcSubItem(rcItem); + rcSubItem.right = rcSubItem.left; + + for (int nSubItem = 0, nColumnCount = GetColumnCount(); nSubItem < nColumnCount; rcSubItem.left = rcSubItem.right + 1, nSubItem++) + { + CListColumn listColumn; + if (!GetColumn(nSubItem, listColumn)) + break; + + rcSubItem.right = rcSubItem.left + listColumn.m_nWidth - 1; + + if (rcSubItem.right < rcClip.left || rcSubItem.Width() == 0) + continue; + if (rcSubItem.left > rcClip.right) + break; + + LPCTSTR strItemText = pT->GetItemText(nItem, listColumn.m_nIndex); + int nItemImage = pT->GetItemImage(nItem, listColumn.m_nIndex); + UINT nItemFormat = pT->GetItemFormat(nItem, listColumn.m_nIndex); + UINT nItemFlags = pT->GetItemFlags(nItem, listColumn.m_nIndex); + + // Custom draw subitem format + if (nItemFormat == ITEM_FORMAT_CUSTOM) + { + pT->DrawCustomItem(dcPaint, nItem, nSubItem, rcSubItem); + return; + } + + BOOL bFocusSubItem = (m_bFocusSubItem && nFocusItem == nItem && nFocusSubItem == nSubItem); + + COLORREF rgbBackground = m_rgbBackground; + COLORREF rgbText = m_rgbItemText; + + if (bFocusSubItem) + { + dcPaint.SetBkColor(m_bEditItem ? m_rgbBackground : m_rgbItemFocus); + dcPaint.ExtTextOut(rcSubItem.left, rcSubItem.top, ETO_OPAQUE, rcSubItem, _T( "" ), 0, nullptr); + + if (m_bEditItem) + { + CBrush bshSelectFrame; + bshSelectFrame.CreateSolidBrush(m_rgbItemFocus); + dcPaint.FrameRect(rcSubItem, bshSelectFrame); + } + } + else if (pT->GetItemColours(nItem, nSubItem, rgbBackground, rgbText) && rgbBackground != m_rgbBackground) + { + CPen penBorder; + penBorder.CreatePen(PS_SOLID, 1, rgbBackground); + CBrush bshInterior; + bshInterior.CreateSolidBrush(rgbBackground); + + dcPaint.SelectPen(penBorder); + dcPaint.SelectBrush(bshInterior); + + dcPaint.RoundRect(rcSubItem, CPoint(3, 3)); + } + + CRect rcItemText(rcSubItem); + + // margin item text + //rcItemText.left += nSubItem == 0 ? 4 : 3; + //rcItemText.DeflateRect( 4, 0 ); + + // Draw subitem image if supplied + if (!m_ilItemImages.IsNull() && nItemImage != ITEM_IMAGE_NONE && (!m_bEditItem || (m_bEditItem && !bFocusSubItem))) + { + CSize sizeIcon; + m_ilItemImages.GetIconSize(sizeIcon); + + CRect rcItemImage; + rcItemImage.left = (strItemText[0] == 0) ? ((rcItemText.left + rcItemText.right) / 2) - (sizeIcon.cx / 2) - (0) : rcItemText.left; + rcItemImage.right = min(rcItemImage.left + sizeIcon.cx, rcSubItem.right); + rcItemImage.top = ((rcSubItem.top + rcSubItem.bottom) / 2) - (sizeIcon.cy / 2); + rcItemImage.bottom = min(rcItemImage.top + sizeIcon.cy, rcSubItem.bottom); + + m_ilItemImages.DrawEx(nItemImage, dcPaint, rcItemImage, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + + // Offset item text (for image) + rcItemText.left += sizeIcon.cx + 4; + } + + if (rcItemText.IsRectEmpty()) + continue; + + COLORREF rgbSelectedText = m_rgbSelectedText; + pT->GetItemSelectedColours(nItem, nSubItem, rgbSelectedText); + + dcPaint.SelectFont(pT->GetItemFont(nItem, nSubItem)); + dcPaint.SetTextColor((bSelectedItem && !bFocusSubItem) ? rgbSelectedText : rgbText); + dcPaint.SetBkMode(TRANSPARENT); + + UINT nFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS; + + if (nItemFlags & ITEM_FLAGS_CENTRE) + nFormat |= DT_CENTER; + else if (nItemFlags & ITEM_FLAGS_RIGHT) + nFormat |= DT_RIGHT; + else + nFormat |= DT_LEFT; + + switch (nItemFormat) + { + case ITEM_FORMAT_DATETIME: + if (strItemText[0] != 0) + { + SYSTEMTIME stItemDate; + if (!GetItemDate(nItem, listColumn.m_nIndex, stItemDate)) + break; + + stdstr strItemDate; + if (nItemFlags & ITEM_FLAGS_DATE_ONLY) + strItemDate = FormatDate(stItemDate); + else if (nItemFlags & ITEM_FLAGS_TIME_ONLY) + strItemDate = FormatTime(stItemDate); + else + strItemDate = FormatDate(stItemDate) + _T( " " ) + FormatTime(stItemDate); + dcPaint.DrawText(strItemDate.c_str(), (int)strItemDate.length(), rcItemText, nFormat); + } + break; + case ITEM_FORMAT_CHECKBOX: + case ITEM_FORMAT_CHECKBOX_3STATE: + { + CSize sizeIcon; + m_ilListItems.GetIconSize(sizeIcon); + + CRect rcCheckBox; + rcCheckBox.left = ((rcItemText.left + rcItemText.right) / 2) - (sizeIcon.cx / 2) - 1; + rcCheckBox.right = min(rcCheckBox.left + sizeIcon.cx, rcSubItem.right); + rcCheckBox.top = ((rcSubItem.top + rcSubItem.bottom) / 2) - (sizeIcon.cy / 2); + rcCheckBox.bottom = min(rcCheckBox.top + sizeIcon.cy, rcSubItem.bottom); + + int nCheckValue = _ttoi(strItemText); + + if (nItemFormat == ITEM_FORMAT_CHECKBOX) + m_ilListItems.DrawEx(nCheckValue > 0 ? ITEM_IMAGE_CHECK_ON : ITEM_IMAGE_CHECK_OFF, dcPaint, rcCheckBox, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + else + { + int nCheckImage = ITEM_IMAGE_3STATE_UNDEF; + if (nCheckValue < 0) + nCheckImage = ITEM_IMAGE_3STATE_OFF; + else if (nCheckValue > 0) + nCheckImage = ITEM_IMAGE_3STATE_ON; + m_ilListItems.DrawEx(nCheckImage, dcPaint, rcCheckBox, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); + } + } + break; + case ITEM_FORMAT_PROGRESS: + { + CRect rcProgress(rcSubItem); + rcProgress.DeflateRect(3, 2); + + // Draw progress border + DrawRoundRect(dcPaint, rcProgress, m_rgbHeaderShadow, m_rgbHeaderBackground); + + // Fill progress bar area + rcProgress.DeflateRect(3, 3); + rcProgress.right = rcProgress.left + (int)((double)rcProgress.Width() * ((max(min(atof(strItemText), 100), 0)) / 100.0)); + DrawGradient(dcPaint, rcProgress, m_rgbProgressTop, m_rgbProgressBottom); + } + break; + case ITEM_FORMAT_HYPERLINK: + if (nItem == m_nHotItem && nSubItem == m_nHotSubItem && !(nItemFlags & ITEM_FLAGS_READ_ONLY)) + { + dcPaint.SelectFont(m_fntUnderlineFont); + dcPaint.SetTextColor(m_rgbHyperLink); + } + default: // Draw item text + { + size_t len = strlen(strItemText); + if (len > 0) + dcPaint.DrawText(strItemText, (int)len, rcItemText, nFormat); + } + + break; + } + } + } + + void DrawSelect(CDCHandle dcPaint) + { + if (!m_bGroupSelect) + return; + + int nHorzScroll = GetScrollPos(SB_HORZ); + int nVertScroll = GetScrollPos(SB_VERT); + + CRect rcGroupSelect(m_rcGroupSelect); + rcGroupSelect.OffsetRect(-nHorzScroll, -nVertScroll); + + CRect rcClient; + GetClientRect(rcClient); + rcClient.top = (m_bShowHeader ? m_nHeaderHeight : 0); + + // Limit box to list client area if scrolled to limits + if (nHorzScroll > (GetTotalWidth() - rcClient.Width())) + rcGroupSelect.right = min(rcClient.right, rcGroupSelect.right); + if (nHorzScroll == 0) + rcGroupSelect.left = max(rcClient.left, rcGroupSelect.left); + if (nVertScroll > (GetTotalHeight() - rcClient.Height())) + rcGroupSelect.bottom = min(rcClient.bottom, rcGroupSelect.bottom); + if (nVertScroll == 0) + rcGroupSelect.top = max(rcClient.top, rcGroupSelect.top); + + // Limit bitmap to client area + CRect rcSelectArea(rcGroupSelect); + rcSelectArea.IntersectRect(rcSelectArea, rcClient); + + CDC dcBackground; + dcBackground.CreateCompatibleDC(dcPaint); + + int nBackgroundContext = dcBackground.SaveDC(); + + CBitmap bmpBackground; + bmpBackground.CreateCompatibleBitmap(dcPaint, rcSelectArea.Width(), rcSelectArea.Height()); + dcBackground.SelectBitmap(bmpBackground); + + // Take a copy of existing background + dcBackground.BitBlt(0, 0, rcSelectArea.Width(), rcSelectArea.Height(), dcPaint, rcSelectArea.left, rcSelectArea.top, SRCCOPY); + + CDC dcGroupSelect; + dcGroupSelect.CreateCompatibleDC(dcPaint); + + int nGroupSelectContext = dcGroupSelect.SaveDC(); + + CBitmap bmpGroupSelect; + bmpGroupSelect.CreateCompatibleBitmap(dcPaint, rcSelectArea.Width(), rcSelectArea.Height()); + dcGroupSelect.SelectBitmap(bmpGroupSelect); + + // Draw group select box + dcGroupSelect.SetBkColor(m_rgbItemFocus); + dcGroupSelect.ExtTextOut(0, 0, ETO_OPAQUE, CRect(CPoint(0), rcSelectArea.Size()), _T( "" ), 0, nullptr); + + BLENDFUNCTION blendFunction; + blendFunction.BlendOp = AC_SRC_OVER; + blendFunction.BlendFlags = 0; + blendFunction.SourceConstantAlpha = 180; + blendFunction.AlphaFormat = 0; + + // Blend existing background with selection box + dcGroupSelect.AlphaBlend(0, 0, rcSelectArea.Width(), rcSelectArea.Height(), dcBackground, 0, 0, rcSelectArea.Width(), rcSelectArea.Height(), blendFunction); + + // Draw blended selection box + dcPaint.BitBlt(rcSelectArea.left, rcSelectArea.top, rcSelectArea.Width(), rcSelectArea.Height(), dcGroupSelect, 0, 0, SRCCOPY); + + // Draw selection box frame + CBrush bshSelectFrame; + bshSelectFrame.CreateSolidBrush(m_rgbItemText); + dcPaint.FrameRect(rcGroupSelect, bshSelectFrame); + + dcBackground.RestoreDC(nBackgroundContext); + dcGroupSelect.RestoreDC(nGroupSelectContext); + } + + void DrawCustomItem(CDCHandle dcPaint, int /*nItem*/, int /*nSubItem*/, CRect & /*rcSubItem*/) + { + ATLASSERT(FALSE); // Must be implemented in a derived class + } }; struct CSubItem { - stdstr m_strText; - int m_nImage; - UINT m_nFormat; - UINT m_nFlags; - UINT m_nMaxEditLen; - CListArray < stdstr > m_aComboList; - HFONT m_hFont; - COLORREF m_rgbBackground; - COLORREF m_rgbText; - COLORREF m_rgbSelectedText; + stdstr m_strText; + int m_nImage; + UINT m_nFormat; + UINT m_nFlags; + UINT m_nMaxEditLen; + CListArray m_aComboList; + HFONT m_hFont; + COLORREF m_rgbBackground; + COLORREF m_rgbText; + COLORREF m_rgbSelectedText; }; -template < class TData = DWORD > +template struct CListItem { - CListArray < CSubItem > m_aSubItems; - stdstr m_strToolTip; - TData m_tData; + CListArray m_aSubItems; + stdstr m_strToolTip; + TData m_tData; }; -template < class TData > -class CListCtrlData : public CListImpl< CListCtrlData< TData > > +template +class CListCtrlData : public CListImpl> { public: - DECLARE_WND_CLASS( _T( "ListCtrl" ) ) + DECLARE_WND_CLASS(_T( "ListCtrl" )) protected: - CListArray < CListItem< TData > > m_aItems; - + CListArray> m_aItems; + public: - int AddItem( CListItem< TData >& listItem ) - { - if ( !m_aItems.Add( listItem ) ) - return -1; - return CListImpl< CListCtrlData >::AddItem() ? GetItemCount() - 1 : -1; - } - - int AddItemAt( CListItem< TData >& listItem, int Index ) - { - if (Index < 0 ) - { - Index = 0; - } - if (Index > GetItemCount()) - { - Index = GetItemCount(); - } - if ( !m_aItems.AddAt( listItem, Index ) ) - return -1; - return CListImpl< CListCtrlData >::AddItem() ? Index : -1; - } + int AddItem(CListItem & listItem) + { + if (!m_aItems.Add(listItem)) + return -1; + return CListImpl::AddItem() ? GetItemCount() - 1 : -1; + } - int AddItem( LPCTSTR lpszText, int nImage = ITEM_IMAGE_NONE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE ) - { - CSubItem listSubItem; - listSubItem.m_nImage = ITEM_IMAGE_NONE; - listSubItem.m_nFormat = nFormat; - listSubItem.m_nFlags = ValidateFlags( nFlags ); - listSubItem.m_hFont = nullptr; - listSubItem.m_rgbBackground = m_rgbBackground; - listSubItem.m_rgbText = m_rgbItemText; - listSubItem.m_rgbSelectedText = m_rgbSelectedText; - listSubItem.m_nMaxEditLen = -1; + int AddItemAt(CListItem & listItem, int Index) + { + if (Index < 0) + { + Index = 0; + } + if (Index > GetItemCount()) + { + Index = GetItemCount(); + } + if (!m_aItems.AddAt(listItem, Index)) + return -1; + return CListImpl::AddItem() ? Index : -1; + } - CListItem< TData > listItem; - for ( int nSubItem = 0; nSubItem < GetColumnCount(); nSubItem++ ) - listItem.m_aSubItems.Add( listSubItem ); + int AddItem(LPCTSTR lpszText, int nImage = ITEM_IMAGE_NONE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE) + { + CSubItem listSubItem; + listSubItem.m_nImage = ITEM_IMAGE_NONE; + listSubItem.m_nFormat = nFormat; + listSubItem.m_nFlags = ValidateFlags(nFlags); + listSubItem.m_hFont = nullptr; + listSubItem.m_rgbBackground = m_rgbBackground; + listSubItem.m_rgbText = m_rgbItemText; + listSubItem.m_rgbSelectedText = m_rgbSelectedText; + listSubItem.m_nMaxEditLen = -1; - // Set item details for first subitem - listItem.m_aSubItems[ 0 ].m_strText = lpszText; - listItem.m_aSubItems[ 0 ].m_nImage = nImage; + CListItem listItem; + for (int nSubItem = 0; nSubItem < GetColumnCount(); nSubItem++) + listItem.m_aSubItems.Add(listSubItem); - return AddItem( listItem ); - } + // Set item details for first subitem + listItem.m_aSubItems[0].m_strText = lpszText; + listItem.m_aSubItems[0].m_nImage = nImage; - int AddItemAt(int Index, LPCTSTR lpszText, int nImage = ITEM_IMAGE_NONE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE ) - { - CSubItem listSubItem; - listSubItem.m_nImage = ITEM_IMAGE_NONE; - listSubItem.m_nFormat = nFormat; - listSubItem.m_nFlags = ValidateFlags( nFlags ); - listSubItem.m_hFont = nullptr; - listSubItem.m_rgbBackground = m_rgbBackground; - listSubItem.m_rgbText = m_rgbItemText; - listSubItem.m_rgbSelectedText = m_rgbSelectedText; - listSubItem.m_nMaxEditLen = (UINT)-1; + return AddItem(listItem); + } - CListItem< TData > listItem; - for ( int nSubItem = 0; nSubItem < GetColumnCount(); nSubItem++ ) - listItem.m_aSubItems.Add( listSubItem ); + int AddItemAt(int Index, LPCTSTR lpszText, int nImage = ITEM_IMAGE_NONE, UINT nFormat = ITEM_FORMAT_NONE, UINT nFlags = ITEM_FLAGS_NONE) + { + CSubItem listSubItem; + listSubItem.m_nImage = ITEM_IMAGE_NONE; + listSubItem.m_nFormat = nFormat; + listSubItem.m_nFlags = ValidateFlags(nFlags); + listSubItem.m_hFont = nullptr; + listSubItem.m_rgbBackground = m_rgbBackground; + listSubItem.m_rgbText = m_rgbItemText; + listSubItem.m_rgbSelectedText = m_rgbSelectedText; + listSubItem.m_nMaxEditLen = (UINT)-1; - // Set item details for first subitem - listItem.m_aSubItems[ 0 ].m_strText = lpszText; - listItem.m_aSubItems[ 0 ].m_nImage = nImage; + CListItem listItem; + for (int nSubItem = 0; nSubItem < GetColumnCount(); nSubItem++) + listItem.m_aSubItems.Add(listSubItem); - return AddItemAt( listItem, Index ); - } - - BOOL DeleteItem( int nItem ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - return m_aItems.RemoveAt( nItem ) ? CListImpl< CListCtrlData >::DeleteItem( nItem ) : FALSE; - } - - BOOL DeleteAllItems() - { - m_aItems.RemoveAll(); - return CListImpl< CListCtrlData >::DeleteAllItems(); - } - - int GetItemCount() - { - return m_aItems.GetSize(); - } - - BOOL GetItem( int nItem, CListItem< TData >& listItem ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - listItem = m_aItems[ nItem ]; - return TRUE; - } - - BOOL GetItem( int nItem, CListItem< TData >*& listItem ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - { - listItem = nullptr; - return FALSE; - } - listItem = &m_aItems[ nItem ]; - return TRUE; - } + // Set item details for first subitem + listItem.m_aSubItems[0].m_strText = lpszText; + listItem.m_aSubItems[0].m_nImage = nImage; - BOOL GetSubItem( int nItem, int nSubItem, CSubItem& listSubItem ) - { - CListItem< TData > * listItem; - if ( !GetItem( nItem, listItem ) ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)listItem->m_aSubItems.GetSize() ) - return FALSE; - listSubItem = listItem->m_aSubItems[ nSubItem ]; - return TRUE; - } - - BOOL GetSubItem( int nItem, int nSubItem, CSubItem *& listSubItem ) - { - CListItem< TData > * listItem; - if ( !GetItem( nItem, listItem ) ) - { - listSubItem = nullptr; - return FALSE; - } - if ( nSubItem < 0 || nSubItem >= (int)listItem->m_aSubItems.GetSize() ) - { - listSubItem = nullptr; - return FALSE; - } - listSubItem = &listItem->m_aSubItems[ nSubItem ]; - return TRUE; - } + return AddItemAt(listItem, Index); + } - LPCTSTR GetItemText( int nItem, int nSubItem ) - { - CSubItem * listSubItem; - return GetSubItem( nItem, nSubItem, listSubItem ) ? listSubItem->m_strText.c_str() : _T( "" ); - } - - UINT GetItemMaxEditLen( int nItem, int nSubItem ) - { - CSubItem * listSubItem; - return GetSubItem( nItem, nSubItem, listSubItem ) ? listSubItem->m_nMaxEditLen : 0; - } + BOOL DeleteItem(int nItem) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + return m_aItems.RemoveAt(nItem) ? CListImpl::DeleteItem(nItem) : FALSE; + } - int GetItemImage( int nItem, int nSubItem ) - { - CSubItem *listSubItem; - return GetSubItem( nItem, nSubItem, listSubItem ) ? listSubItem->m_nImage : ITEM_IMAGE_NONE; - } - - UINT GetItemFormat( int nItem, int nSubItem ) - { - CSubItem * listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - return listSubItem->m_nFormat == ITEM_FORMAT_NONE ? GetColumnFormat( IndexToOrder( nSubItem ) ) : listSubItem->m_nFormat; - } - - UINT GetItemFlags( int nItem, int nSubItem ) - { - CSubItem *listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - return listSubItem->m_nFlags == ITEM_FLAGS_NONE ? GetColumnFlags( IndexToOrder( nSubItem ) ) : listSubItem->m_nFlags; - } - - BOOL GetItemComboList( int nItem, int nSubItem, CListArray < stdstr >& aComboList ) - { - CSubItem listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - aComboList = listSubItem.m_aComboList; - return aComboList.IsEmpty() ? GetColumnComboList( IndexToOrder( nSubItem ), aComboList ) : !aComboList.IsEmpty(); - } - - HFONT GetItemFont( int nItem, int nSubItem ) - { - CSubItem * listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - return listSubItem->m_hFont == nullptr ? CListImpl< CListCtrlData >::GetItemFont( nItem, nSubItem ) : listSubItem->m_hFont; - } - - BOOL GetItemColours( int nItem, int nSubItem, COLORREF& rgbBackground, COLORREF& rgbText ) - { - CSubItem *listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - rgbBackground = listSubItem->m_rgbBackground; - rgbText = listSubItem->m_rgbText; - return TRUE; - } - - BOOL GetItemSelectedColours( int nItem, int nSubItem, COLORREF& rgbSelectedText ) - { - CSubItem *listSubItem; - if ( !GetSubItem( nItem, nSubItem, listSubItem ) ) - return FALSE; - rgbSelectedText = listSubItem->m_rgbSelectedText; - return TRUE; - } + BOOL DeleteAllItems() + { + m_aItems.RemoveAll(); + return CListImpl::DeleteAllItems(); + } - stdstr GetItemToolTip( int nItem, int /*nSubItem*/ ) - { - CListItem< TData > listItem; - return GetItem( nItem, listItem ) ? listItem.m_strToolTip : _T( "" ); - } - - BOOL GetItemData( int nItem, TData& tData ) - { - CListItem< TData > listItem; - if ( !GetItem( nItem, listItem ) ) - return FALSE; - tData = listItem.m_tData; - return TRUE; - } - - BOOL SetItemText( int nItem, int nSubItem, LPCTSTR lpszText, bool bInvalidateItem = true) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_strText = lpszText; - - if (bInvalidateItem) - InvalidateItem(nItem, nSubItem); - - return TRUE; - } - - BOOL SetItemComboIndex( int nItem, int nSubItem, int nIndex ) - { - CListArray < stdstr > aComboList; - if ( !GetItemComboList( nItem, nSubItem, aComboList ) ) - return FALSE; - return SetItemText( nItem, nSubItem, nIndex < 0 || nIndex >= aComboList.GetSize() ? _T( "" ) : aComboList[ nIndex ] ); - } - - BOOL SetItemImage( int nItem, int nSubItem, int nImage ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nImage = nImage; - return TRUE; - } - - BOOL SetItemFormat( int nItem, int nSubItem, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nFormat = nFormat; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nFlags = nFlags; - return TRUE; - } - - BOOL SetItemFormat( int nItem, int nSubItem, UINT nFormat, UINT nFlags, CListArray < stdstr >& aComboList ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nFormat = nFormat; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nFlags = nFlags; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_aComboList = aComboList; - return TRUE; - } - - BOOL SetItemMaxEditLen( int nItem, int nSubItem, UINT nMaxEditLen ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_nMaxEditLen = nMaxEditLen; - return TRUE; - } - - BOOL SetItemFont( int nItem, int nSubItem, HFONT hFont ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_hFont = hFont; - return TRUE; - } + int GetItemCount() + { + return m_aItems.GetSize(); + } - BOOL SetItemColours( int nItem, int nSubItem, COLORREF rgbBackground, COLORREF rgbText ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_rgbBackground = rgbBackground; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_rgbText = rgbText; - return TRUE; - } - - BOOL SetItemHighlightColours( int nItem, int nSubItem, COLORREF rgbSelectedText ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - if ( nSubItem < 0 || nSubItem >= (int)m_aItems[ nItem ].m_aSubItems.GetSize() ) - return FALSE; - m_aItems[ nItem ].m_aSubItems[ nSubItem ].m_rgbSelectedText = rgbSelectedText; - return TRUE; - } + BOOL GetItem(int nItem, CListItem & listItem) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + listItem = m_aItems[nItem]; + return TRUE; + } - void ReverseItems() - { - m_aItems.Reverse(); - } - - class CompareItem - { - public: - CompareItem( int nColumn ) : m_nColumn( nColumn ) {} - inline bool operator() ( const CListItem< TData >& listItem1, const CListItem< TData >& listItem2 ) - { - return ( _tcscmp(listItem1.m_aSubItems[ m_nColumn ].m_strText.c_str(), listItem2.m_aSubItems[ m_nColumn ].m_strText.c_str() ) < 0 ); - } - - protected: - int m_nColumn; - }; - - void SortItems( int nColumn, BOOL /*bAscending*/ ) - { - m_aItems.Sort( CompareItem( nColumn ) ); - } - - BOOL SetItemToolTip( int nItem, LPCTSTR lpszToolTip ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - m_aItems[ nItem ].m_strToolTip = lpszToolTip; - return TRUE; - } - - BOOL SetItemData( int nItem, TData& tData ) - { - if ( nItem < 0 || nItem >= GetItemCount() ) - return FALSE; - m_aItems[ nItem ].m_tData = tData; - return TRUE; - } + BOOL GetItem(int nItem, CListItem *& listItem) + { + if (nItem < 0 || nItem >= GetItemCount()) + { + listItem = nullptr; + return FALSE; + } + listItem = &m_aItems[nItem]; + return TRUE; + } + + BOOL GetSubItem(int nItem, int nSubItem, CSubItem & listSubItem) + { + CListItem * listItem; + if (!GetItem(nItem, listItem)) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)listItem->m_aSubItems.GetSize()) + return FALSE; + listSubItem = listItem->m_aSubItems[nSubItem]; + return TRUE; + } + + BOOL GetSubItem(int nItem, int nSubItem, CSubItem *& listSubItem) + { + CListItem * listItem; + if (!GetItem(nItem, listItem)) + { + listSubItem = nullptr; + return FALSE; + } + if (nSubItem < 0 || nSubItem >= (int)listItem->m_aSubItems.GetSize()) + { + listSubItem = nullptr; + return FALSE; + } + listSubItem = &listItem->m_aSubItems[nSubItem]; + return TRUE; + } + + LPCTSTR GetItemText(int nItem, int nSubItem) + { + CSubItem * listSubItem; + return GetSubItem(nItem, nSubItem, listSubItem) ? listSubItem->m_strText.c_str() : _T( "" ); + } + + UINT GetItemMaxEditLen(int nItem, int nSubItem) + { + CSubItem * listSubItem; + return GetSubItem(nItem, nSubItem, listSubItem) ? listSubItem->m_nMaxEditLen : 0; + } + + int GetItemImage(int nItem, int nSubItem) + { + CSubItem * listSubItem; + return GetSubItem(nItem, nSubItem, listSubItem) ? listSubItem->m_nImage : ITEM_IMAGE_NONE; + } + + UINT GetItemFormat(int nItem, int nSubItem) + { + CSubItem * listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + return listSubItem->m_nFormat == ITEM_FORMAT_NONE ? GetColumnFormat(IndexToOrder(nSubItem)) : listSubItem->m_nFormat; + } + + UINT GetItemFlags(int nItem, int nSubItem) + { + CSubItem * listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + return listSubItem->m_nFlags == ITEM_FLAGS_NONE ? GetColumnFlags(IndexToOrder(nSubItem)) : listSubItem->m_nFlags; + } + + BOOL GetItemComboList(int nItem, int nSubItem, CListArray & aComboList) + { + CSubItem listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + aComboList = listSubItem.m_aComboList; + return aComboList.IsEmpty() ? GetColumnComboList(IndexToOrder(nSubItem), aComboList) : !aComboList.IsEmpty(); + } + + HFONT GetItemFont(int nItem, int nSubItem) + { + CSubItem * listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + return listSubItem->m_hFont == nullptr ? CListImpl::GetItemFont(nItem, nSubItem) : listSubItem->m_hFont; + } + + BOOL GetItemColours(int nItem, int nSubItem, COLORREF & rgbBackground, COLORREF & rgbText) + { + CSubItem * listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + rgbBackground = listSubItem->m_rgbBackground; + rgbText = listSubItem->m_rgbText; + return TRUE; + } + + BOOL GetItemSelectedColours(int nItem, int nSubItem, COLORREF & rgbSelectedText) + { + CSubItem * listSubItem; + if (!GetSubItem(nItem, nSubItem, listSubItem)) + return FALSE; + rgbSelectedText = listSubItem->m_rgbSelectedText; + return TRUE; + } + + stdstr GetItemToolTip(int nItem, int /*nSubItem*/) + { + CListItem listItem; + return GetItem(nItem, listItem) ? listItem.m_strToolTip : _T( "" ); + } + + BOOL GetItemData(int nItem, TData & tData) + { + CListItem listItem; + if (!GetItem(nItem, listItem)) + return FALSE; + tData = listItem.m_tData; + return TRUE; + } + + BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText, bool bInvalidateItem = true) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_strText = lpszText; + + if (bInvalidateItem) + InvalidateItem(nItem, nSubItem); + + return TRUE; + } + + BOOL SetItemComboIndex(int nItem, int nSubItem, int nIndex) + { + CListArray aComboList; + if (!GetItemComboList(nItem, nSubItem, aComboList)) + return FALSE; + return SetItemText(nItem, nSubItem, nIndex < 0 || nIndex >= aComboList.GetSize() ? _T( "" ) : aComboList[nIndex]); + } + + BOOL SetItemImage(int nItem, int nSubItem, int nImage) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_nImage = nImage; + return TRUE; + } + + BOOL SetItemFormat(int nItem, int nSubItem, UINT nFormat, UINT nFlags = ITEM_FLAGS_NONE) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_nFormat = nFormat; + m_aItems[nItem].m_aSubItems[nSubItem].m_nFlags = nFlags; + return TRUE; + } + + BOOL SetItemFormat(int nItem, int nSubItem, UINT nFormat, UINT nFlags, CListArray & aComboList) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_nFormat = nFormat; + m_aItems[nItem].m_aSubItems[nSubItem].m_nFlags = nFlags; + m_aItems[nItem].m_aSubItems[nSubItem].m_aComboList = aComboList; + return TRUE; + } + + BOOL SetItemMaxEditLen(int nItem, int nSubItem, UINT nMaxEditLen) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_nMaxEditLen = nMaxEditLen; + return TRUE; + } + + BOOL SetItemFont(int nItem, int nSubItem, HFONT hFont) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_hFont = hFont; + return TRUE; + } + + BOOL SetItemColours(int nItem, int nSubItem, COLORREF rgbBackground, COLORREF rgbText) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_rgbBackground = rgbBackground; + m_aItems[nItem].m_aSubItems[nSubItem].m_rgbText = rgbText; + return TRUE; + } + + BOOL SetItemHighlightColours(int nItem, int nSubItem, COLORREF rgbSelectedText) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + if (nSubItem < 0 || nSubItem >= (int)m_aItems[nItem].m_aSubItems.GetSize()) + return FALSE; + m_aItems[nItem].m_aSubItems[nSubItem].m_rgbSelectedText = rgbSelectedText; + return TRUE; + } + + void ReverseItems() + { + m_aItems.Reverse(); + } + + class CompareItem + { + public: + CompareItem(int nColumn) : + m_nColumn(nColumn) + { + } + inline bool operator()(const CListItem & listItem1, const CListItem & listItem2) + { + return (_tcscmp(listItem1.m_aSubItems[m_nColumn].m_strText.c_str(), listItem2.m_aSubItems[m_nColumn].m_strText.c_str()) < 0); + } + + protected: + int m_nColumn; + }; + + void SortItems(int nColumn, BOOL /*bAscending*/) + { + m_aItems.Sort(CompareItem(nColumn)); + } + + BOOL SetItemToolTip(int nItem, LPCTSTR lpszToolTip) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + m_aItems[nItem].m_strToolTip = lpszToolTip; + return TRUE; + } + + BOOL SetItemData(int nItem, TData & tData) + { + if (nItem < 0 || nItem >= GetItemCount()) + return FALSE; + m_aItems[nItem].m_tData = tData; + return TRUE; + } }; -typedef CListCtrlData< DWORD > CListCtrl; +typedef CListCtrlData CListCtrl; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListDate.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListDate.h index be592ac1b..656ccc653 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListDate.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListDate.h @@ -2,193 +2,195 @@ #include "ListTypes.h" -#define DATE_STRING 32 +#define DATE_STRING 32 -class CListDate : public CWindowImpl< CListDate, CDateTimePickerCtrl > +class CListDate : public CWindowImpl { public: - CListDate() - { - m_nItem = NULL_ITEM; - m_nSubItem = NULL_SUBITEM; - m_nFlags = ITEM_FLAGS_NONE; - m_nExitChar = 0; - } - - ~CListDate() - { - } + CListDate() + { + m_nItem = NULL_ITEM; + m_nSubItem = NULL_SUBITEM; + m_nFlags = ITEM_FLAGS_NONE; + m_nExitChar = 0; + } + + ~CListDate() + { + } protected: - int m_nItem; - int m_nSubItem; - UINT m_nFlags; - TCHAR m_nExitChar; - CFont m_fntDateFont; - -public: - BOOL Create( HWND hWndParent, int nItem, int nSubItem, CRect& rcRect, UINT nFlags, SYSTEMTIME& stItemDate ) - { - m_nItem = nItem; - m_nSubItem = nSubItem; - m_nFlags = nFlags; - m_nExitChar = 0; - - // Destroy old date control - if ( IsWindow() ) - DestroyWindow(); - - DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN; - - if ( nFlags & ITEM_FLAGS_DATETIME_NONE ) - dwStyle |= DTS_SHOWNONE; - - if ( nFlags & ITEM_FLAGS_TIME_ONLY ) - dwStyle |= DTS_UPDOWN; - - // Create date-time control - CRect Area( rcRect.left + 3, rcRect.top + 2, rcRect.right - 3, rcRect.bottom - 2 ); - if ( CWindowImpl< CListDate, CDateTimePickerCtrl >::Create( hWndParent, Area, nullptr, dwStyle ) == nullptr ) - return FALSE; - - // Remove border - ModifyStyleEx( WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED ); - - // Get system message font - CLogFont logFont; - logFont.SetMessageBoxFont(); - if ( !m_fntDateFont.IsNull() ) - m_fntDateFont.DeleteObject(); - if ( m_fntDateFont.CreateFontIndirect( &logFont ) == nullptr ) - return FALSE; - SetMonthCalFont( m_fntDateFont ); - SetFont( m_fntDateFont ); - - TCHAR szDateFormat[ DATE_STRING ]; - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szDateFormat, DATE_STRING ); - - TCHAR szTimeFormat[ DATE_STRING ]; - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, szTimeFormat, DATE_STRING ); - - if ( nFlags & ITEM_FLAGS_DATE_ONLY ) - SetFormat( szDateFormat ); - else if ( nFlags & ITEM_FLAGS_TIME_ONLY ) - SetFormat( szTimeFormat ); - else - SetFormat(stdstr_f("%s %s",szDateFormat,szTimeFormat ).ToUTF16().c_str()); - - // Get current date if setting time-only - if ( nFlags & ITEM_FLAGS_TIME_ONLY ) - { - SYSTEMTIME stCurrentDate; - if ( GetSystemTime( &stCurrentDate ) == GDT_VALID ) - { - stItemDate.wYear = stCurrentDate.wYear; - stItemDate.wMonth = stCurrentDate.wMonth; - stItemDate.wDay = stCurrentDate.wDay; - } - } - - SetSystemTime( ( !( nFlags & ITEM_FLAGS_TIME_ONLY ) && stItemDate.wYear == 0 ) ? GDT_NONE : GDT_VALID, &stItemDate ); - - // Show date-time control - ShowWindow( SW_SHOW ); - - SetFocus(); - - return TRUE; - } - - BEGIN_MSG_MAP_EX(CListDate) - MSG_WM_KILLFOCUS(OnKillFocus) - REFLECTED_NOTIFY_CODE_HANDLER_EX(DTN_CLOSEUP, OnCloseUp) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_CHAR(OnChar) - DEFAULT_REFLECTION_HANDLER() - END_MSG_MAP() - - void OnKillFocus( HWND hNewWnd ) - { - // Have we dropped down the calendar control? - if ( hNewWnd != nullptr && GetMonthCal() == hNewWnd ) - return; - - // Have we selected a new date from the calendar control? - if ( GetFocus() == m_hWnd ) - return; - - // Hide calendar control in case it's not closed by losing focus - if ( GetMonthCal().IsWindow() ) - GetMonthCal().ShowWindow( SW_HIDE ); - - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - { - SYSTEMTIME stItemDate; - BOOL bValidDate = ( GetSystemTime( &stItemDate ) == GDT_VALID ); - if ( !bValidDate ) - ZeroMemory( &stItemDate, sizeof( SYSTEMTIME ) ); - - if ( m_nFlags & ITEM_FLAGS_DATE_ONLY ) - { - stItemDate.wHour = 0; - stItemDate.wMinute = 0; - stItemDate.wSecond = 0; - stItemDate.wMilliseconds = 0; - } - - if ( m_nFlags & ITEM_FLAGS_TIME_ONLY ) - { - stItemDate.wYear = 0; - stItemDate.wMonth = 0; - stItemDate.wDay = 0; - stItemDate.wDayOfWeek = 0; - } - - CListNotify listNotify; - listNotify.m_hdrNotify.hwndFrom = m_hWnd; - listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); - listNotify.m_hdrNotify.code = LCN_ENDEDIT; - listNotify.m_nItem = m_nItem; - listNotify.m_nSubItem = m_nSubItem; - listNotify.m_nExitChar = m_nExitChar; - listNotify.m_lpszItemText = bValidDate ? _T( "1" ) : _T( "0" ); - listNotify.m_lpItemDate = &stItemDate; + int m_nItem; + int m_nSubItem; + UINT m_nFlags; + TCHAR m_nExitChar; + CFont m_fntDateFont; - // Forward notification to parent - FORWARD_WM_NOTIFY( wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage ); - } - - ShowWindow( SW_HIDE ); - } - - LRESULT OnCloseUp( LPNMHDR /*lpNMHDR*/ ) - { - SetMsgHandled( FALSE ); - SetFocus(); - return TRUE; - } - - UINT OnGetDlgCode( LPMSG /*lpMessage*/ ) - { - return DLGC_WANTALLKEYS; - } - - void OnChar( TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/ ) - { - switch ( nChar ) - { - case VK_TAB: - case VK_RETURN: - case VK_ESCAPE: { - m_nExitChar = nChar; - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - wndParent.SetFocus(); - } - break; - default: SetMsgHandled( FALSE ); - break; - } - } +public: + BOOL Create(HWND hWndParent, int nItem, int nSubItem, CRect & rcRect, UINT nFlags, SYSTEMTIME & stItemDate) + { + m_nItem = nItem; + m_nSubItem = nSubItem; + m_nFlags = nFlags; + m_nExitChar = 0; + + // Destroy old date control + if (IsWindow()) + DestroyWindow(); + + DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN; + + if (nFlags & ITEM_FLAGS_DATETIME_NONE) + dwStyle |= DTS_SHOWNONE; + + if (nFlags & ITEM_FLAGS_TIME_ONLY) + dwStyle |= DTS_UPDOWN; + + // Create date-time control + CRect Area(rcRect.left + 3, rcRect.top + 2, rcRect.right - 3, rcRect.bottom - 2); + if (CWindowImpl::Create(hWndParent, Area, nullptr, dwStyle) == nullptr) + return FALSE; + + // Remove border + ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED); + + // Get system message font + CLogFont logFont; + logFont.SetMessageBoxFont(); + if (!m_fntDateFont.IsNull()) + m_fntDateFont.DeleteObject(); + if (m_fntDateFont.CreateFontIndirect(&logFont) == nullptr) + return FALSE; + SetMonthCalFont(m_fntDateFont); + SetFont(m_fntDateFont); + + TCHAR szDateFormat[DATE_STRING]; + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szDateFormat, DATE_STRING); + + TCHAR szTimeFormat[DATE_STRING]; + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, szTimeFormat, DATE_STRING); + + if (nFlags & ITEM_FLAGS_DATE_ONLY) + SetFormat(szDateFormat); + else if (nFlags & ITEM_FLAGS_TIME_ONLY) + SetFormat(szTimeFormat); + else + SetFormat(stdstr_f("%s %s", szDateFormat, szTimeFormat).ToUTF16().c_str()); + + // Get current date if setting time-only + if (nFlags & ITEM_FLAGS_TIME_ONLY) + { + SYSTEMTIME stCurrentDate; + if (GetSystemTime(&stCurrentDate) == GDT_VALID) + { + stItemDate.wYear = stCurrentDate.wYear; + stItemDate.wMonth = stCurrentDate.wMonth; + stItemDate.wDay = stCurrentDate.wDay; + } + } + + SetSystemTime((!(nFlags & ITEM_FLAGS_TIME_ONLY) && stItemDate.wYear == 0) ? GDT_NONE : GDT_VALID, &stItemDate); + + // Show date-time control + ShowWindow(SW_SHOW); + + SetFocus(); + + return TRUE; + } + + BEGIN_MSG_MAP_EX(CListDate) + MSG_WM_KILLFOCUS(OnKillFocus) + REFLECTED_NOTIFY_CODE_HANDLER_EX(DTN_CLOSEUP, OnCloseUp) + MSG_WM_GETDLGCODE(OnGetDlgCode) + MSG_WM_CHAR(OnChar) + DEFAULT_REFLECTION_HANDLER() + END_MSG_MAP() + + void OnKillFocus(HWND hNewWnd) + { + // Have we dropped down the calendar control? + if (hNewWnd != nullptr && GetMonthCal() == hNewWnd) + return; + + // Have we selected a new date from the calendar control? + if (GetFocus() == m_hWnd) + return; + + // Hide calendar control in case it's not closed by losing focus + if (GetMonthCal().IsWindow()) + GetMonthCal().ShowWindow(SW_HIDE); + + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + { + SYSTEMTIME stItemDate; + BOOL bValidDate = (GetSystemTime(&stItemDate) == GDT_VALID); + if (!bValidDate) + ZeroMemory(&stItemDate, sizeof(SYSTEMTIME)); + + if (m_nFlags & ITEM_FLAGS_DATE_ONLY) + { + stItemDate.wHour = 0; + stItemDate.wMinute = 0; + stItemDate.wSecond = 0; + stItemDate.wMilliseconds = 0; + } + + if (m_nFlags & ITEM_FLAGS_TIME_ONLY) + { + stItemDate.wYear = 0; + stItemDate.wMonth = 0; + stItemDate.wDay = 0; + stItemDate.wDayOfWeek = 0; + } + + CListNotify listNotify; + listNotify.m_hdrNotify.hwndFrom = m_hWnd; + listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); + listNotify.m_hdrNotify.code = LCN_ENDEDIT; + listNotify.m_nItem = m_nItem; + listNotify.m_nSubItem = m_nSubItem; + listNotify.m_nExitChar = m_nExitChar; + listNotify.m_lpszItemText = bValidDate ? _T( "1" ) : _T( "0" ); + listNotify.m_lpItemDate = &stItemDate; + + // Forward notification to parent + FORWARD_WM_NOTIFY(wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage); + } + + ShowWindow(SW_HIDE); + } + + LRESULT OnCloseUp(LPNMHDR /*lpNMHDR*/) + { + SetMsgHandled(FALSE); + SetFocus(); + return TRUE; + } + + UINT OnGetDlgCode(LPMSG /*lpMessage*/) + { + return DLGC_WANTALLKEYS; + } + + void OnChar(TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) + { + switch (nChar) + { + case VK_TAB: + case VK_RETURN: + case VK_ESCAPE: + { + m_nExitChar = nChar; + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + wndParent.SetFocus(); + } + break; + default: + SetMsgHandled(FALSE); + break; + } + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListEdit.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListEdit.h index 6c937b1a6..bd6a29f29 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListEdit.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListEdit.h @@ -2,83 +2,83 @@ #include "ListTypes.h" -class CListEdit : public CWindowImpl< CListEdit, CEdit > +class CListEdit : public CWindowImpl { public: - CListEdit() - { - m_nItem = NULL_ITEM; - m_nSubItem = NULL_SUBITEM; - m_nFlags = ITEM_FLAGS_NONE; - m_nExitChar = 0; - } - - ~CListEdit() - { - } + CListEdit() + { + m_nItem = NULL_ITEM; + m_nSubItem = NULL_SUBITEM; + m_nFlags = ITEM_FLAGS_NONE; + m_nExitChar = 0; + } + + ~CListEdit() + { + } protected: - int m_nItem; - int m_nSubItem; - UINT m_nFlags; - int m_nMaxLen; - TCHAR m_nExitChar; - CFont m_fntEditFont; - -public: - BOOL Create( HWND hWndParent, int nItem, int nSubItem, CRect& rcRect, UINT nFlags, LPCTSTR lpszItemText, UINT nMaxLen ) - { - m_nItem = nItem; - m_nSubItem = nSubItem; - m_nFlags = nFlags; - m_nExitChar = 0; - m_nMaxLen = nMaxLen; - - // Destroy old edit control - if ( IsWindow() ) - DestroyWindow(); - - DWORD dwStyle = WS_CHILD | ES_AUTOHSCROLL | WS_BORDER; - - // Right-justify numbers - if ( nFlags & ( ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT ) ) - dwStyle |= ES_RIGHT; - - if ( nFlags & ITEM_FLAGS_EDIT_UPPER ) - dwStyle |= ES_UPPERCASE; - - // Create edit control - CRect Area( rcRect.left - 2, rcRect.top - 3, rcRect.right + 3, rcRect.bottom + 2 ); - if ( CWindowImpl< CListEdit, CEdit >::Create( hWndParent, Area, nullptr, dwStyle ) == nullptr ) - return FALSE; - - // Get system message font - CLogFont logFont; - logFont.SetMessageBoxFont(); - if ( !m_fntEditFont.IsNull() ) - m_fntEditFont.DeleteObject(); - if ( m_fntEditFont.CreateFontIndirect( &logFont ) == nullptr ) - return FALSE; + int m_nItem; + int m_nSubItem; + UINT m_nFlags; + int m_nMaxLen; + TCHAR m_nExitChar; + CFont m_fntEditFont; + +public: + BOOL Create(HWND hWndParent, int nItem, int nSubItem, CRect & rcRect, UINT nFlags, LPCTSTR lpszItemText, UINT nMaxLen) + { + m_nItem = nItem; + m_nSubItem = nSubItem; + m_nFlags = nFlags; + m_nExitChar = 0; + m_nMaxLen = nMaxLen; + + // Destroy old edit control + if (IsWindow()) + DestroyWindow(); + + DWORD dwStyle = WS_CHILD | ES_AUTOHSCROLL | WS_BORDER; + + // Right-justify numbers + if (nFlags & (ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT)) + dwStyle |= ES_RIGHT; + + if (nFlags & ITEM_FLAGS_EDIT_UPPER) + dwStyle |= ES_UPPERCASE; + + // Create edit control + CRect Area(rcRect.left - 2, rcRect.top - 3, rcRect.right + 3, rcRect.bottom + 2); + if (CWindowImpl::Create(hWndParent, Area, nullptr, dwStyle) == nullptr) + return FALSE; + + // Get system message font + CLogFont logFont; + logFont.SetMessageBoxFont(); + if (!m_fntEditFont.IsNull()) + m_fntEditFont.DeleteObject(); + if (m_fntEditFont.CreateFontIndirect(&logFont) == nullptr) + return FALSE; + + SetFont(m_fntEditFont); + SetMargins(ITEM_EDIT_MARGIN, ITEM_EDIT_MARGIN); + SetWindowText(lpszItemText); + + // Show edit control + ShowWindow(SW_SHOW); + + SetSelAll(); + SetFocus(); + + return TRUE; + } + + BOOL IsValid(TCHAR nChar) + { + // Validate number and float input + if (!(m_nFlags & (ITEM_FLAGS_EDIT_HEX | ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT)) || nChar == VK_BACK) + return TRUE; - SetFont( m_fntEditFont ); - SetMargins( ITEM_EDIT_MARGIN, ITEM_EDIT_MARGIN ); - SetWindowText( lpszItemText ); - - // Show edit control - ShowWindow( SW_SHOW ); - - SetSelAll(); - SetFocus(); - - return TRUE; - } - - BOOL IsValid( TCHAR nChar ) - { - // Validate number and float input - if ( !( m_nFlags & ( ITEM_FLAGS_EDIT_HEX | ITEM_FLAGS_EDIT_NUMBER | ITEM_FLAGS_EDIT_FLOAT ) ) || nChar == VK_BACK ) - return TRUE; - std::wstring WindowText; int nValueLength = GetWindowTextLengthW(); if (nValueLength > 0) @@ -87,179 +87,186 @@ public: WindowText.resize(nValueLength); GetWindowTextW((wchar_t *)WindowText.c_str(), nValueLength + 1); } - // Get selected positions - int nStartChar; - int nEndChar; - GetSel( nStartChar, nEndChar ); + // Get selected positions + int nStartChar; + int nEndChar; + GetSel(nStartChar, nEndChar); - if (m_nMaxLen != -1) - { - if (nValueLength >= m_nMaxLen && nStartChar == nEndChar) - { - return FALSE; - } - } - // Are we changing the sign? - if ( ( m_nFlags & ITEM_FLAGS_EDIT_NEGATIVE ) && nChar == _T( '-' ) ) - { - BOOL bNegative = FALSE; - if ( m_nFlags & ITEM_FLAGS_EDIT_FLOAT ) - { - double dblValue = _wtof(WindowText.c_str()); - bNegative = ( dblValue < 0 ); + if (m_nMaxLen != -1) + { + if (nValueLength >= m_nMaxLen && nStartChar == nEndChar) + { + return FALSE; + } + } + // Are we changing the sign? + if ((m_nFlags & ITEM_FLAGS_EDIT_NEGATIVE) && nChar == _T('-')) + { + BOOL bNegative = FALSE; + if (m_nFlags & ITEM_FLAGS_EDIT_FLOAT) + { + double dblValue = _wtof(WindowText.c_str()); + bNegative = (dblValue < 0); WindowText = stdstr_f("%lf", -dblValue).ToUTF16(); - } - else - { - long lValue = _wtol(WindowText.c_str() ); - bNegative = ( lValue < 0 ); + } + else + { + long lValue = _wtol(WindowText.c_str()); + bNegative = (lValue < 0); WindowText = stdstr_f("%ld", -lValue).ToUTF16(); - } - - SetWindowText(WindowText.c_str()); - - // Restore select position - SetSel( bNegative ? nStartChar - 1 : nStartChar + 1, bNegative ? nEndChar - 1 : nEndChar + 1 ); - return FALSE; - } - - // Construct new value string using entered character - std::wstring strNewValue = WindowText.substr(0, nStartChar ) + nChar + WindowText.substr(WindowText.length() - nEndChar ); - - int nGreaterThan = 0; - int nLessThan = 0; - int nEquals = 0; - int nDecimalPoint = 0; - - int nNegativeIndex = -1; - int nGreaterIndex = -1; - int nLessIndex = -1; - int nEqualIndex = -1; - int nDecimalIndex = -1; - int nDigitIndex = -1; - - for ( size_t nCharIndex = 0; nCharIndex < strNewValue.length(); nCharIndex++ ) - { - TCHAR nCharValue = strNewValue[ nCharIndex ]; - if (( m_nFlags & ITEM_FLAGS_EDIT_HEX ) && - (nCharValue >= 'A' && nCharValue <= 'F' || nCharValue >= 'a' && nCharValue <= 'f')) - { - if ( nDigitIndex < 0 ) - { - nDigitIndex = (int)nCharIndex; - } - break; - } + } - switch ( nCharValue ) - { - case _T( '-' ): nNegativeIndex = (int)nCharIndex; - break; - case _T( '>' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nGreaterIndex = (int)nCharIndex; - nGreaterThan++; - break; - case _T( '<' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nLessIndex = (int)nCharIndex; - nLessThan++; - break; - case _T( '=' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_OPERATOR ) ) - return FALSE; - nEqualIndex = (int)nCharIndex; - nEquals++; - break; - case _T( '.' ): if ( !( m_nFlags & ITEM_FLAGS_EDIT_FLOAT ) ) - return FALSE; - nDecimalIndex = (int)nCharIndex; - nDecimalPoint++; - break; - default: if ( !_istdigit( nCharValue ) ) - return FALSE; - if ( nDigitIndex < 0 ) - nDigitIndex = (int)nCharIndex; - break; - } + SetWindowText(WindowText.c_str()); - // Invalid if text contains more than one '>', '<', '=' or '.' - if ( nGreaterThan > 1 || nLessThan > 1 || nEquals > 1 || nDecimalPoint > 1 ) - return FALSE; - } + // Restore select position + SetSel(bNegative ? nStartChar - 1 : nStartChar + 1, bNegative ? nEndChar - 1 : nEndChar + 1); + return FALSE; + } - // Invalid if text contains '=>' or '=<' - if ( nGreaterIndex != -1 && nEqualIndex != -1 && nGreaterIndex > nEqualIndex ) - return FALSE; - if ( nLessIndex != -1 && nEqualIndex != -1 && nLessIndex > nEqualIndex ) - return FALSE; + // Construct new value string using entered character + std::wstring strNewValue = WindowText.substr(0, nStartChar) + nChar + WindowText.substr(WindowText.length() - nEndChar); - // Invalid if digits exist before operator - if ( nDigitIndex != -1 && nGreaterIndex != -1 && nGreaterIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nLessIndex != -1 && nLessIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nEqualIndex != -1 && nEqualIndex > nDigitIndex ) - return FALSE; - if ( nDigitIndex != -1 && nNegativeIndex != -1 && nNegativeIndex > nDigitIndex ) - return FALSE; - - return TRUE; - } - - BEGIN_MSG_MAP_EX(CListEdit) - MSG_WM_KILLFOCUS(OnKillFocus) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_CHAR(OnChar) - END_MSG_MAP() - - void OnKillFocus( HWND /*hNewWnd*/ ) - { - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - { - std::wstring strValue; - int nValueLength = GetWindowTextLength(); - strValue.reserve(nValueLength + 1); - strValue.resize(nValueLength); - GetWindowText((LPTSTR)strValue.c_str(), nValueLength + 1); - - CListNotify listNotify; - listNotify.m_hdrNotify.hwndFrom = m_hWnd; - listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); - listNotify.m_hdrNotify.code = LCN_ENDEDIT; - listNotify.m_nItem = m_nItem; - listNotify.m_nSubItem = m_nSubItem; - listNotify.m_nExitChar = m_nExitChar; - listNotify.m_lpszItemText = strValue.c_str(); - listNotify.m_lpItemDate = nullptr; + int nGreaterThan = 0; + int nLessThan = 0; + int nEquals = 0; + int nDecimalPoint = 0; - // Forward notification to parent - FORWARD_WM_NOTIFY( wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage ); - } - - ShowWindow( SW_HIDE ); - } - - UINT OnGetDlgCode( LPMSG /*lpMessage*/ ) - { - return DLGC_WANTALLKEYS; - } - - void OnChar( TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/ ) - { - switch ( nChar ) - { - case VK_TAB: - case VK_RETURN: - case VK_ESCAPE: { - m_nExitChar = nChar; - CWindow wndParent( GetParent() ); - if ( wndParent.IsWindow() ) - wndParent.SetFocus(); - } - break; - default: SetMsgHandled( !IsValid( nChar ) ); - break; - } - } + int nNegativeIndex = -1; + int nGreaterIndex = -1; + int nLessIndex = -1; + int nEqualIndex = -1; + int nDecimalIndex = -1; + int nDigitIndex = -1; + + for (size_t nCharIndex = 0; nCharIndex < strNewValue.length(); nCharIndex++) + { + TCHAR nCharValue = strNewValue[nCharIndex]; + if ((m_nFlags & ITEM_FLAGS_EDIT_HEX) && (nCharValue >= 'A' && nCharValue <= 'F' || nCharValue >= 'a' && nCharValue <= 'f')) + { + if (nDigitIndex < 0) + { + nDigitIndex = (int)nCharIndex; + } + break; + } + + switch (nCharValue) + { + case _T('-'): + nNegativeIndex = (int)nCharIndex; + break; + case _T('>'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nGreaterIndex = (int)nCharIndex; + nGreaterThan++; + break; + case _T('<'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nLessIndex = (int)nCharIndex; + nLessThan++; + break; + case _T('='): + if (!(m_nFlags & ITEM_FLAGS_EDIT_OPERATOR)) + return FALSE; + nEqualIndex = (int)nCharIndex; + nEquals++; + break; + case _T('.'): + if (!(m_nFlags & ITEM_FLAGS_EDIT_FLOAT)) + return FALSE; + nDecimalIndex = (int)nCharIndex; + nDecimalPoint++; + break; + default: + if (!_istdigit(nCharValue)) + return FALSE; + if (nDigitIndex < 0) + nDigitIndex = (int)nCharIndex; + break; + } + + // Invalid if text contains more than one '>', '<', '=' or '.' + if (nGreaterThan > 1 || nLessThan > 1 || nEquals > 1 || nDecimalPoint > 1) + return FALSE; + } + + // Invalid if text contains '=>' or '=<' + if (nGreaterIndex != -1 && nEqualIndex != -1 && nGreaterIndex > nEqualIndex) + return FALSE; + if (nLessIndex != -1 && nEqualIndex != -1 && nLessIndex > nEqualIndex) + return FALSE; + + // Invalid if digits exist before operator + if (nDigitIndex != -1 && nGreaterIndex != -1 && nGreaterIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nLessIndex != -1 && nLessIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nEqualIndex != -1 && nEqualIndex > nDigitIndex) + return FALSE; + if (nDigitIndex != -1 && nNegativeIndex != -1 && nNegativeIndex > nDigitIndex) + return FALSE; + + return TRUE; + } + + BEGIN_MSG_MAP_EX(CListEdit) + MSG_WM_KILLFOCUS(OnKillFocus) + MSG_WM_GETDLGCODE(OnGetDlgCode) + MSG_WM_CHAR(OnChar) + END_MSG_MAP() + + void OnKillFocus(HWND /*hNewWnd*/) + { + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + { + std::wstring strValue; + int nValueLength = GetWindowTextLength(); + strValue.reserve(nValueLength + 1); + strValue.resize(nValueLength); + GetWindowText((LPTSTR)strValue.c_str(), nValueLength + 1); + + CListNotify listNotify; + listNotify.m_hdrNotify.hwndFrom = m_hWnd; + listNotify.m_hdrNotify.idFrom = GetDlgCtrlID(); + listNotify.m_hdrNotify.code = LCN_ENDEDIT; + listNotify.m_nItem = m_nItem; + listNotify.m_nSubItem = m_nSubItem; + listNotify.m_nExitChar = m_nExitChar; + listNotify.m_lpszItemText = strValue.c_str(); + listNotify.m_lpItemDate = nullptr; + + // Forward notification to parent + FORWARD_WM_NOTIFY(wndParent, listNotify.m_hdrNotify.idFrom, &listNotify.m_hdrNotify, ::SendMessage); + } + + ShowWindow(SW_HIDE); + } + + UINT OnGetDlgCode(LPMSG /*lpMessage*/) + { + return DLGC_WANTALLKEYS; + } + + void OnChar(TCHAR nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) + { + switch (nChar) + { + case VK_TAB: + case VK_RETURN: + case VK_ESCAPE: + { + m_nExitChar = nChar; + CWindow wndParent(GetParent()); + if (wndParent.IsWindow()) + wndParent.SetFocus(); + } + break; + default: + SetMsgHandled(!IsValid(nChar)); + break; + } + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListTypes.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListTypes.h index ce0f992c5..9ee4c9b8a 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListTypes.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/ListTypes.h @@ -2,141 +2,141 @@ #include "DataArray.h" -#define NULL_COLUMN -1 -#define NULL_ITEM -1 -#define NULL_SUBITEM -1 -#define ITEM_HEIGHT_MARGIN 2 -#define ITEM_WIDTH_MARGIN 0 -#define ITEM_SCROLL_OFFSET 5 -#define DRAG_HEADER_OFFSET 4 -#define DRAG_ITEM_OFFSET 3 -#define ITEM_EDIT_MARGIN 2 -#define TOOLTIP_TOOL_ID 1000 -#define RESIZE_COLUMN_TIMER 1001 -#define RESIZE_COLUMN_PERIOD 20 -#define ITEM_VISIBLE_TIMER 1002 -#define ITEM_VISIBLE_PERIOD 250 -#define SEARCH_PERIOD 800 -#define ITEM_AUTOSCROLL_TIMER 1003 -#define ITEM_SCROLL_TIMER 1004 -#define ITEM_SCROLL_PERIOD 20 -#define ITEM_SCROLL_UNIT_MAX 8 -#define ITEM_SCROLL_UNIT_MIN 4 +#define NULL_COLUMN -1 +#define NULL_ITEM -1 +#define NULL_SUBITEM -1 +#define ITEM_HEIGHT_MARGIN 2 +#define ITEM_WIDTH_MARGIN 0 +#define ITEM_SCROLL_OFFSET 5 +#define DRAG_HEADER_OFFSET 4 +#define DRAG_ITEM_OFFSET 3 +#define ITEM_EDIT_MARGIN 2 +#define TOOLTIP_TOOL_ID 1000 +#define RESIZE_COLUMN_TIMER 1001 +#define RESIZE_COLUMN_PERIOD 20 +#define ITEM_VISIBLE_TIMER 1002 +#define ITEM_VISIBLE_PERIOD 250 +#define SEARCH_PERIOD 800 +#define ITEM_AUTOSCROLL_TIMER 1003 +#define ITEM_SCROLL_TIMER 1004 +#define ITEM_SCROLL_PERIOD 20 +#define ITEM_SCROLL_UNIT_MAX 8 +#define ITEM_SCROLL_UNIT_MIN 4 -#define ITEM_FORMAT_NONE 0 -#define ITEM_FORMAT_EDIT 1 -#define ITEM_FORMAT_DATETIME 2 -#define ITEM_FORMAT_COMBO 3 -#define ITEM_FORMAT_CHECKBOX 4 -#define ITEM_FORMAT_CHECKBOX_3STATE 5 -#define ITEM_FORMAT_HYPERLINK 6 -#define ITEM_FORMAT_PROGRESS 7 -#define ITEM_FORMAT_CUSTOM 8 +#define ITEM_FORMAT_NONE 0 +#define ITEM_FORMAT_EDIT 1 +#define ITEM_FORMAT_DATETIME 2 +#define ITEM_FORMAT_COMBO 3 +#define ITEM_FORMAT_CHECKBOX 4 +#define ITEM_FORMAT_CHECKBOX_3STATE 5 +#define ITEM_FORMAT_HYPERLINK 6 +#define ITEM_FORMAT_PROGRESS 7 +#define ITEM_FORMAT_CUSTOM 8 -#define ITEM_FLAGS_NONE 0x0000 -#define ITEM_FLAGS_LEFT 0x0001 -#define ITEM_FLAGS_RIGHT 0x0002 -#define ITEM_FLAGS_CENTRE 0x0004 -#define ITEM_FLAGS_READ_ONLY 0x0008 -#define ITEM_FLAGS_EDIT_UPPER 0x0010 -#define ITEM_FLAGS_EDIT_NUMBER 0x0020 -#define ITEM_FLAGS_EDIT_FLOAT 0x0040 -#define ITEM_FLAGS_EDIT_NEGATIVE 0x0080 -#define ITEM_FLAGS_EDIT_OPERATOR 0x0100 -#define ITEM_FLAGS_EDIT_HEX 0x0200 -#define ITEM_FLAGS_COMBO_EDIT 0x0400 -#define ITEM_FLAGS_DATE_ONLY 0x0800 -#define ITEM_FLAGS_TIME_ONLY 0x1000 -#define ITEM_FLAGS_DATETIME_NONE 0x2000 -#define ITEM_FLAGS_PROGRESS_SOLID 0x4000 -#define ITEM_FLAGS_HIT_NOTIFY 0x8000 +#define ITEM_FLAGS_NONE 0x0000 +#define ITEM_FLAGS_LEFT 0x0001 +#define ITEM_FLAGS_RIGHT 0x0002 +#define ITEM_FLAGS_CENTRE 0x0004 +#define ITEM_FLAGS_READ_ONLY 0x0008 +#define ITEM_FLAGS_EDIT_UPPER 0x0010 +#define ITEM_FLAGS_EDIT_NUMBER 0x0020 +#define ITEM_FLAGS_EDIT_FLOAT 0x0040 +#define ITEM_FLAGS_EDIT_NEGATIVE 0x0080 +#define ITEM_FLAGS_EDIT_OPERATOR 0x0100 +#define ITEM_FLAGS_EDIT_HEX 0x0200 +#define ITEM_FLAGS_COMBO_EDIT 0x0400 +#define ITEM_FLAGS_DATE_ONLY 0x0800 +#define ITEM_FLAGS_TIME_ONLY 0x1000 +#define ITEM_FLAGS_DATETIME_NONE 0x2000 +#define ITEM_FLAGS_PROGRESS_SOLID 0x4000 +#define ITEM_FLAGS_HIT_NOTIFY 0x8000 -#define ITEM_IMAGE_NONE -1 -#define ITEM_IMAGE_DOWN 0 -#define ITEM_IMAGE_UP 1 -#define ITEM_IMAGE_CHECK_OFF 2 -#define ITEM_IMAGE_CHECK_ON 3 -#define ITEM_IMAGE_3STATE_UNDEF ITEM_IMAGE_CHECK_OFF -#define ITEM_IMAGE_3STATE_ON 4 -#define ITEM_IMAGE_3STATE_OFF 5 -#define ITEM_IMAGE_LOCK 6 -#define ITEM_IMAGE_ATTACHMENT 7 -#define ITEM_IMAGE_3STATE 8 -#define ITEM_IMAGE_CHECKBOX 9 +#define ITEM_IMAGE_NONE -1 +#define ITEM_IMAGE_DOWN 0 +#define ITEM_IMAGE_UP 1 +#define ITEM_IMAGE_CHECK_OFF 2 +#define ITEM_IMAGE_CHECK_ON 3 +#define ITEM_IMAGE_3STATE_UNDEF ITEM_IMAGE_CHECK_OFF +#define ITEM_IMAGE_3STATE_ON 4 +#define ITEM_IMAGE_3STATE_OFF 5 +#define ITEM_IMAGE_LOCK 6 +#define ITEM_IMAGE_ATTACHMENT 7 +#define ITEM_IMAGE_3STATE 8 +#define ITEM_IMAGE_CHECKBOX 9 -#define HITTEST_FLAG_NONE 0x0000 -#define HITTEST_FLAG_HEADER_DIVIDER 0x0001 -#define HITTEST_FLAG_HEADER_LEFT 0x0002 -#define HITTEST_FLAG_HEADER_RIGHT 0x0004 +#define HITTEST_FLAG_NONE 0x0000 +#define HITTEST_FLAG_HEADER_DIVIDER 0x0001 +#define HITTEST_FLAG_HEADER_LEFT 0x0002 +#define HITTEST_FLAG_HEADER_RIGHT 0x0004 -#define LCN_FIRST ( 0U - 1500U ) -#define LCN_LAST ( 0U - 1600U ) +#define LCN_FIRST (0U - 1500U) +#define LCN_LAST (0U - 1600U) -#define LCN_SELECTED ( LCN_FIRST - 1 ) -#define LCN_LEFTCLICK ( LCN_FIRST - 2 ) -#define LCN_RIGHTCLICK ( LCN_FIRST - 3 ) -#define LCN_DBLCLICK ( LCN_FIRST - 4 ) -#define LCN_ENDEDIT ( LCN_FIRST - 5 ) -#define LCN_MODIFIED ( LCN_FIRST - 6 ) -#define LCN_HYPERLINK ( LCN_FIRST - 7 ) -#define LCN_HITTEST ( LCN_FIRST - 8 ) -#define LCN_HOTITEMCHANGED ( LCN_FIRST - 9 ) +#define LCN_SELECTED (LCN_FIRST - 1) +#define LCN_LEFTCLICK (LCN_FIRST - 2) +#define LCN_RIGHTCLICK (LCN_FIRST - 3) +#define LCN_DBLCLICK (LCN_FIRST - 4) +#define LCN_ENDEDIT (LCN_FIRST - 5) +#define LCN_MODIFIED (LCN_FIRST - 6) +#define LCN_HYPERLINK (LCN_FIRST - 7) +#define LCN_HITTEST (LCN_FIRST - 8) +#define LCN_HOTITEMCHANGED (LCN_FIRST - 9) struct CListNotify { - NMHDR m_hdrNotify; - int m_nItem; - int m_nSubItem; - TCHAR m_nExitChar; - LPCTSTR m_lpszItemText; - LPSYSTEMTIME m_lpItemDate; + NMHDR m_hdrNotify; + int m_nItem; + int m_nSubItem; + TCHAR m_nExitChar; + LPCTSTR m_lpszItemText; + LPSYSTEMTIME m_lpItemDate; }; -template > -class CListArray : public CListCtrlArray< T, TEqual > +template > +class CListArray : public CListCtrlArray { public: - void Reverse() - { - reverse( m_aT, m_aT + m_nSize ); - } + void Reverse() + { + reverse(m_aT, m_aT + m_nSize); + } - void Sort() - { - sort( m_aT, m_aT + m_nSize ); - } - - template< class Pred > inline - void Sort( Pred Compare ) - { - sort( m_aT, m_aT + m_nSize, Compare ); - } - - BOOL IsEmpty() - { - return ( GetSize() == 0 ); - } - - BOOL InsertAt( int nIndex, const T& t ) - { - if ( nIndex < 0 ) - return FALSE; - - if ( nIndex >= m_nSize ) - return ( Add( t ) != -1 ); - - if ( m_nSize == m_nAllocSize ) - { - int nNewAllocSize = ( m_nAllocSize == 0 ) ? 1 : ( m_nSize * 2 ); - T* aT = (T*)realloc( m_aT, nNewAllocSize * sizeof( T ) ); - if ( aT == nullptr ) - return FALSE; - m_nAllocSize = nNewAllocSize; - m_aT = aT; - } - MoveMemory( (LPVOID)( m_aT + nIndex + 1 ), (LPVOID)( m_aT + nIndex ), ( m_nSize - nIndex ) * sizeof( T ) ); - InternalSetAtIndex( nIndex, t ); - m_nSize++; - return TRUE; - } + void Sort() + { + sort(m_aT, m_aT + m_nSize); + } + + template + inline void Sort(Pred Compare) + { + sort(m_aT, m_aT + m_nSize, Compare); + } + + BOOL IsEmpty() + { + return (GetSize() == 0); + } + + BOOL InsertAt(int nIndex, const T & t) + { + if (nIndex < 0) + return FALSE; + + if (nIndex >= m_nSize) + return (Add(t) != -1); + + if (m_nSize == m_nAllocSize) + { + int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2); + T * aT = (T *)realloc(m_aT, nNewAllocSize * sizeof(T)); + if (aT == nullptr) + return FALSE; + m_nAllocSize = nNewAllocSize; + m_aT = aT; + } + MoveMemory((LPVOID)(m_aT + nIndex + 1), (LPVOID)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T)); + InternalSetAtIndex(nIndex, t); + m_nSize++; + return TRUE; + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ClistCtrl/TitleTip.h b/Source/Project64/UserInterface/WTLControls/ClistCtrl/TitleTip.h index 2294b9803..3461323d8 100644 --- a/Source/Project64/UserInterface/WTLControls/ClistCtrl/TitleTip.h +++ b/Source/Project64/UserInterface/WTLControls/ClistCtrl/TitleTip.h @@ -1,224 +1,233 @@ #pragma once #include -class CTitleTip : public CWindowImpl< CTitleTip > +class CTitleTip : public CWindowImpl { public: - CTitleTip() - { - m_hWndParent = nullptr; - } - - ~CTitleTip() - { - } - - DECLARE_WND_CLASS_EX( _T( "TitleTip" ), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS, COLOR_WINDOW ) + CTitleTip() + { + m_hWndParent = nullptr; + } + + ~CTitleTip() + { + } + + DECLARE_WND_CLASS_EX(_T( "TitleTip" ), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS, COLOR_WINDOW) protected: - HWND m_hWndParent; - stdstr m_strToolTip; - - COLORREF m_rgbBackground; - COLORREF m_rgbTextColour; - COLORREF m_rgbBorderOuter; - COLORREF m_rgbBorderInner; - COLORREF m_rgbBackgroundTop; - COLORREF m_rgbBackgroundBottom; - - CFont m_fntTitleFont; - CToolTipCtrl m_ttToolTip; - + HWND m_hWndParent; + stdstr m_strToolTip; + + COLORREF m_rgbBackground; + COLORREF m_rgbTextColour; + COLORREF m_rgbBorderOuter; + COLORREF m_rgbBorderInner; + COLORREF m_rgbBackgroundTop; + COLORREF m_rgbBackgroundBottom; + + CFont m_fntTitleFont; + CToolTipCtrl m_ttToolTip; + public: - BOOL Create( HWND hWndParent ) - { - m_hWndParent = hWndParent; - - m_rgbBackground = GetSysColor( COLOR_INFOBK ); - m_rgbTextColour = GetSysColor( COLOR_INFOTEXT ); - m_rgbBorderOuter = RGB( 220, 220, 220 ); - m_rgbBorderInner = RGB( 245, 245, 245 ); - m_rgbBackgroundTop = RGB( 250, 250, 250 ); - m_rgbBackgroundBottom = RGB( 235, 235, 235 ); - - CRect Area(nullptr); - if ( CWindowImpl< CTitleTip >::Create( hWndParent, Area, nullptr, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST ) == nullptr ) - return FALSE; - - // Create the tooltip - if ( !m_ttToolTip.Create( m_hWnd ) ) - return FALSE; - m_ttToolTip.SetMaxTipWidth( SHRT_MAX ); - - // Get system message font - WTL::CLogFont logFont; - logFont.SetMessageBoxFont(); - if ( !m_fntTitleFont.IsNull() ) - m_fntTitleFont.DeleteObject(); - return ( m_fntTitleFont.CreateFontIndirect( &logFont ) != nullptr ); - } - - BOOL Show( CRect& rcRect, LPCTSTR lpszItemText, LPCTSTR lpszToolTip ) - { + BOOL Create(HWND hWndParent) + { + m_hWndParent = hWndParent; + + m_rgbBackground = GetSysColor(COLOR_INFOBK); + m_rgbTextColour = GetSysColor(COLOR_INFOTEXT); + m_rgbBorderOuter = RGB(220, 220, 220); + m_rgbBorderInner = RGB(245, 245, 245); + m_rgbBackgroundTop = RGB(250, 250, 250); + m_rgbBackgroundBottom = RGB(235, 235, 235); + + CRect Area(nullptr); + if (CWindowImpl::Create(hWndParent, Area, nullptr, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST) == nullptr) + return FALSE; + + // Create the tooltip + if (!m_ttToolTip.Create(m_hWnd)) + return FALSE; + m_ttToolTip.SetMaxTipWidth(SHRT_MAX); + + // Get system message font + WTL::CLogFont logFont; + logFont.SetMessageBoxFont(); + if (!m_fntTitleFont.IsNull()) + m_fntTitleFont.DeleteObject(); + return (m_fntTitleFont.CreateFontIndirect(&logFont) != nullptr); + } + + BOOL Show(CRect & rcRect, LPCTSTR lpszItemText, LPCTSTR lpszToolTip) + { stdstr strItemText; strItemText.FromUTF16(lpszItemText); - - if ( !IsWindow() || strItemText.empty() ) - return FALSE; - - m_strToolTip.FromUTF16(lpszToolTip); - SetWindowText(strItemText.ToUTF16().c_str() ); - - CClientDC dcClient( m_hWnd ); - - HFONT hOldFont = dcClient.SelectFont( m_fntTitleFont ); - - CRect rcTextExtent( rcRect ); - - // Calculate item text extent - dcClient.DrawTextW( strItemText.ToUTF16().c_str(), (int)strItemText.length(), rcTextExtent, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_CALCRECT ); - - dcClient.SelectFont( hOldFont ); - - // Do not show title tip if entire text is visible - if ( rcTextExtent.Width() <= rcRect.Width() - 1 ) - return FALSE; - - if ( m_strToolTip.empty() ) - m_ttToolTip.Activate( FALSE ); - else - { - m_ttToolTip.Activate( TRUE ); - m_ttToolTip.AddTool( m_hWnd, (LPCTSTR)m_strToolTip. substr(0,SHRT_MAX).c_str() ); - } - - // Show title tip at new location - if ( !SetWindowPos( nullptr, rcRect.left - 4, rcRect.top, rcTextExtent.Width() + 11, rcRect.Height(), SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOCOPYBITS ) ) - return FALSE; - - SetCapture(); - - return TRUE; - } - - BOOL Hide() - { - if ( GetCapture() == m_hWnd ) - ReleaseCapture(); - return IsWindow() ? ShowWindow( SW_HIDE ) : FALSE; - } - - BEGIN_MSG_MAP_EX(CTitleTip) - MSG_WM_DESTROY(OnDestroy) - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST,WM_MOUSELAST,OnMouseRange) - MSG_WM_ERASEBKGND(OnEraseBkgnd) - MSG_WM_PAINT(OnPaint) - END_MSG_MAP() - - void OnDestroy() - { - if ( m_ttToolTip.IsWindow() ) - m_ttToolTip.DestroyWindow(); - m_ttToolTip.m_hWnd = nullptr; - } - - LRESULT OnMouseRange( UINT nMessage, WPARAM wParam, LPARAM lParam ) - { - SetMsgHandled( FALSE ); - - if ( m_ttToolTip.IsWindow() ) - { - MSG msgRelay = { m_hWnd, nMessage, wParam, lParam }; - m_ttToolTip.RelayEvent( &msgRelay ); - } - - CPoint ptMouse( GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam ) ); - ClientToScreen( &ptMouse ); - - if ( nMessage == WM_MOUSEMOVE ) - { - CRect rcWindow; - GetWindowRect( rcWindow ); - if ( !rcWindow.PtInRect( ptMouse ) ) - Hide(); - return 0; - } - - CWindow wndParent( m_hWndParent ); - UINT nHitTest = (UINT)wndParent.SendMessage( WM_NCHITTEST, 0, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - - // Forward notification through to parent - if ( nHitTest == HTCLIENT ) - { - wndParent.ScreenToClient( &ptMouse ); - wndParent.PostMessage( nMessage, wParam, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - } - else - { - switch ( nMessage ) - { - case WM_LBUTTONDOWN: wndParent.PostMessage( WM_NCLBUTTONDOWN, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_LBUTTONUP: wndParent.PostMessage( WM_NCLBUTTONUP, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_LBUTTONDBLCLK: wndParent.PostMessage( WM_NCLBUTTONDBLCLK, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_RBUTTONDOWN: wndParent.PostMessage( WM_NCRBUTTONDOWN, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_RBUTTONUP: wndParent.PostMessage( WM_NCRBUTTONUP, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_RBUTTONDBLCLK: wndParent.PostMessage( WM_NCRBUTTONDBLCLK, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_MBUTTONDOWN: wndParent.PostMessage( WM_NCMBUTTONDOWN, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_MBUTTONUP: wndParent.PostMessage( WM_NCMBUTTONUP, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - case WM_MBUTTONDBLCLK: wndParent.PostMessage( WM_NCMBUTTONDBLCLK, nHitTest, MAKELPARAM( ptMouse.x, ptMouse.y ) ); - break; - } - } - return 0; - } - - BOOL OnEraseBkgnd( HDC /*dc*/ ) - { - return TRUE; - } - - void OnPaint( HDC /*dc*/) - { - CPaintDC dcPaint( m_hWnd ); - - int nContextState = dcPaint.SaveDC(); - - CRect rcClient; - GetClientRect( rcClient ); - - CRect rcTitleTip( rcClient ); - - dcPaint.SetBkColor( m_rgbBackground ); - dcPaint.ExtTextOut( rcTitleTip.left, rcTitleTip.top, ETO_OPAQUE, rcTitleTip, _T( "" ), 0, nullptr ); - - CBrush bshTitleFrame; - bshTitleFrame.CreateSolidBrush( m_rgbTextColour ); - dcPaint.FrameRect( rcTitleTip, bshTitleFrame ); - - int nTextLength = GetWindowTextLength(); - stdstr strItemText; - strItemText.reserve(nTextLength + 1); - strItemText.resize(nTextLength); - GetWindowText( (LPTSTR)strItemText.c_str(), nTextLength + 1 ); - - dcPaint.SelectFont( m_fntTitleFont ); - dcPaint.SetTextColor( m_rgbTextColour ); - dcPaint.SetBkMode( TRANSPARENT ); - - CRect rcItemText( rcClient ); - rcItemText.OffsetRect( 4, 0 ); - - dcPaint.DrawTextW( strItemText.ToUTF16().c_str(), (int)strItemText.length(), rcItemText, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER ); - - dcPaint.RestoreDC( nContextState ); - } + if (!IsWindow() || strItemText.empty()) + return FALSE; + + m_strToolTip.FromUTF16(lpszToolTip); + SetWindowText(strItemText.ToUTF16().c_str()); + + CClientDC dcClient(m_hWnd); + + HFONT hOldFont = dcClient.SelectFont(m_fntTitleFont); + + CRect rcTextExtent(rcRect); + + // Calculate item text extent + dcClient.DrawTextW(strItemText.ToUTF16().c_str(), (int)strItemText.length(), rcTextExtent, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_CALCRECT); + + dcClient.SelectFont(hOldFont); + + // Do not show title tip if entire text is visible + if (rcTextExtent.Width() <= rcRect.Width() - 1) + return FALSE; + + if (m_strToolTip.empty()) + m_ttToolTip.Activate(FALSE); + else + { + m_ttToolTip.Activate(TRUE); + m_ttToolTip.AddTool(m_hWnd, (LPCTSTR)m_strToolTip.substr(0, SHRT_MAX).c_str()); + } + + // Show title tip at new location + if (!SetWindowPos(nullptr, rcRect.left - 4, rcRect.top, rcTextExtent.Width() + 11, rcRect.Height(), SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOCOPYBITS)) + return FALSE; + + SetCapture(); + + return TRUE; + } + + BOOL Hide() + { + if (GetCapture() == m_hWnd) + ReleaseCapture(); + return IsWindow() ? ShowWindow(SW_HIDE) : FALSE; + } + + BEGIN_MSG_MAP_EX(CTitleTip) + MSG_WM_DESTROY(OnDestroy) + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) + MSG_WM_ERASEBKGND(OnEraseBkgnd) + MSG_WM_PAINT(OnPaint) + END_MSG_MAP() + + void OnDestroy() + { + if (m_ttToolTip.IsWindow()) + m_ttToolTip.DestroyWindow(); + m_ttToolTip.m_hWnd = nullptr; + } + + LRESULT OnMouseRange(UINT nMessage, WPARAM wParam, LPARAM lParam) + { + SetMsgHandled(FALSE); + + if (m_ttToolTip.IsWindow()) + { + MSG msgRelay = {m_hWnd, nMessage, wParam, lParam}; + m_ttToolTip.RelayEvent(&msgRelay); + } + + CPoint ptMouse(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + ClientToScreen(&ptMouse); + + if (nMessage == WM_MOUSEMOVE) + { + CRect rcWindow; + GetWindowRect(rcWindow); + if (!rcWindow.PtInRect(ptMouse)) + Hide(); + return 0; + } + + CWindow wndParent(m_hWndParent); + UINT nHitTest = (UINT)wndParent.SendMessage(WM_NCHITTEST, 0, MAKELPARAM(ptMouse.x, ptMouse.y)); + + // Forward notification through to parent + if (nHitTest == HTCLIENT) + { + wndParent.ScreenToClient(&ptMouse); + wndParent.PostMessage(nMessage, wParam, MAKELPARAM(ptMouse.x, ptMouse.y)); + } + else + { + switch (nMessage) + { + case WM_LBUTTONDOWN: + wndParent.PostMessage(WM_NCLBUTTONDOWN, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_LBUTTONUP: + wndParent.PostMessage(WM_NCLBUTTONUP, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_LBUTTONDBLCLK: + wndParent.PostMessage(WM_NCLBUTTONDBLCLK, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_RBUTTONDOWN: + wndParent.PostMessage(WM_NCRBUTTONDOWN, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_RBUTTONUP: + wndParent.PostMessage(WM_NCRBUTTONUP, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_RBUTTONDBLCLK: + wndParent.PostMessage(WM_NCRBUTTONDBLCLK, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_MBUTTONDOWN: + wndParent.PostMessage(WM_NCMBUTTONDOWN, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_MBUTTONUP: + wndParent.PostMessage(WM_NCMBUTTONUP, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + case WM_MBUTTONDBLCLK: + wndParent.PostMessage(WM_NCMBUTTONDBLCLK, nHitTest, MAKELPARAM(ptMouse.x, ptMouse.y)); + break; + } + } + + return 0; + } + + BOOL OnEraseBkgnd(HDC /*dc*/) + { + return TRUE; + } + + void OnPaint(HDC /*dc*/) + { + CPaintDC dcPaint(m_hWnd); + + int nContextState = dcPaint.SaveDC(); + + CRect rcClient; + GetClientRect(rcClient); + + CRect rcTitleTip(rcClient); + + dcPaint.SetBkColor(m_rgbBackground); + dcPaint.ExtTextOut(rcTitleTip.left, rcTitleTip.top, ETO_OPAQUE, rcTitleTip, _T( "" ), 0, nullptr); + + CBrush bshTitleFrame; + bshTitleFrame.CreateSolidBrush(m_rgbTextColour); + dcPaint.FrameRect(rcTitleTip, bshTitleFrame); + + int nTextLength = GetWindowTextLength(); + stdstr strItemText; + strItemText.reserve(nTextLength + 1); + strItemText.resize(nTextLength); + GetWindowText((LPTSTR)strItemText.c_str(), nTextLength + 1); + + dcPaint.SelectFont(m_fntTitleFont); + dcPaint.SetTextColor(m_rgbTextColour); + dcPaint.SetBkMode(TRANSPARENT); + + CRect rcItemText(rcClient); + rcItemText.OffsetRect(4, 0); + + dcPaint.DrawTextW(strItemText.ToUTF16().c_str(), (int)strItemText.length(), rcItemText, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); + + dcPaint.RestoreDC(nContextState); + } }; diff --git a/Source/Project64/UserInterface/WTLControls/DisplayMode.h b/Source/Project64/UserInterface/WTLControls/DisplayMode.h index 87481398f..5fbbaaed3 100644 --- a/Source/Project64/UserInterface/WTLControls/DisplayMode.h +++ b/Source/Project64/UserInterface/WTLControls/DisplayMode.h @@ -10,43 +10,43 @@ enum class DisplayMode AllHex = ShowHexIdent | ZeroExtend, }; -inline DisplayMode operator |(DisplayMode lhs, DisplayMode rhs) +inline DisplayMode operator|(DisplayMode lhs, DisplayMode rhs) { using T = std::underlying_type::type; return static_cast(static_cast(lhs) | static_cast(rhs)); } -inline DisplayMode& operator |=(DisplayMode& lhs, DisplayMode rhs) +inline DisplayMode & operator|=(DisplayMode & lhs, DisplayMode rhs) { lhs = lhs | rhs; return lhs; } -inline DisplayMode operator &(DisplayMode lhs, DisplayMode rhs) +inline DisplayMode operator&(DisplayMode lhs, DisplayMode rhs) { using T = std::underlying_type::type; return static_cast(static_cast(lhs) & static_cast(rhs)); } -inline DisplayMode& operator &=(DisplayMode& lhs, DisplayMode rhs) +inline DisplayMode & operator&=(DisplayMode & lhs, DisplayMode rhs) { lhs = lhs & rhs; return lhs; } -inline DisplayMode operator ^(DisplayMode lhs, DisplayMode rhs) +inline DisplayMode operator^(DisplayMode lhs, DisplayMode rhs) { using T = std::underlying_type::type; return static_cast((static_cast(lhs) ^ static_cast(rhs)) & static_cast(DisplayMode::AllHex)); } -inline DisplayMode& operator ^=(DisplayMode& lhs, DisplayMode rhs) +inline DisplayMode & operator^=(DisplayMode & lhs, DisplayMode rhs) { lhs = lhs ^ rhs; return lhs; } -inline DisplayMode operator ~(DisplayMode lhs) +inline DisplayMode operator~(DisplayMode lhs) { using T = std::underlying_type::type; return static_cast(~static_cast(lhs) & static_cast(DisplayMode::AllHex)); diff --git a/Source/Project64/UserInterface/WTLControls/EditConInput.h b/Source/Project64/UserInterface/WTLControls/EditConInput.h index 528c8a4e8..bc851f9a6 100644 --- a/Source/Project64/UserInterface/WTLControls/EditConInput.h +++ b/Source/Project64/UserInterface/WTLControls/EditConInput.h @@ -1,13 +1,14 @@ #pragma once -enum { +enum +{ CIN_SPECIALKEY }; typedef struct { NMHDR nmh; - int vkey; + int vkey; } NMCISPECIALKEY; class CEditConInput : public CWindowImpl @@ -17,7 +18,7 @@ public: { } - LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) + LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled) { NMCISPECIALKEY nmsk; @@ -26,7 +27,7 @@ public: case VK_UP: case VK_DOWN: case VK_RETURN: - nmsk = { { m_hWnd, (UINT_PTR)GetDlgCtrlID(), CIN_SPECIALKEY }, (int)wParam }; + nmsk = {{m_hWnd, (UINT_PTR)GetDlgCtrlID(), CIN_SPECIALKEY}, (int)wParam}; SendMessage(GetParent(), WM_NOTIFY, nmsk.nmh.idFrom, (LPARAM)&nmsk); break; } @@ -42,14 +43,16 @@ public: } BEGIN_MSG_MAP_EX(CEditEval) - MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) + { + MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown); + } END_MSG_MAP() }; class CEditConOutput : public CWindowImpl { private: - LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) + LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/) { if (GetKeyState(VK_CONTROL) < 0) { @@ -60,6 +63,7 @@ private: } return FALSE; } + public: BOOL Attach(HWND hWndNew) { @@ -67,6 +71,8 @@ public: } BEGIN_MSG_MAP_EX(CEditEval) - MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) - END_MSG_MAP() + { + MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown); + } + END_MSG_MAP() }; diff --git a/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp b/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp index 9e161e0b1..77e951045 100644 --- a/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp +++ b/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp @@ -29,7 +29,10 @@ bool CEditNumber32::IsHexConvertableText(LPTSTR _text) bPaste = false; } } - if (!bPaste) { return bPaste; } + if (!bPaste) + { + return bPaste; + } // Check unsigned int i = 0; if (wcslen(_text) >= 2) @@ -280,7 +283,10 @@ uint32_t CEditNumber32::GetValue(void) wchar_t Second = Finish > 1 ? Text[1] : 0; size_t Start = (Second == 'x' || Second == 'X') ? 2 : 0; - if (Finish > 8 + Start) { Finish = 8 + Start; } + if (Finish > 8 + Start) + { + Finish = 8 + Start; + } DWORD Value = 0; for (size_t i = Start; i < Finish; i++) diff --git a/Source/Project64/UserInterface/WTLControls/EditNumber32.h b/Source/Project64/UserInterface/WTLControls/EditNumber32.h index 14619da18..bd5b6ff90 100644 --- a/Source/Project64/UserInterface/WTLControls/EditNumber32.h +++ b/Source/Project64/UserInterface/WTLControls/EditNumber32.h @@ -1,7 +1,7 @@ #pragma once -#include #include "DisplayMode.h" +#include class CEditNumber32 : public CWindowImpl @@ -28,19 +28,21 @@ protected: WM_VALIDATE_VALUE = WM_USER + 0x97 }; - DisplayType m_DisplayType; + DisplayType m_DisplayType; BEGIN_MSG_MAP(CEditNumber32) - MESSAGE_HANDLER(WM_CHAR, OnKeyDown) - MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) - MESSAGE_HANDLER(WM_PASTE, OnPaste) + { + MESSAGE_HANDLER(WM_CHAR, OnKeyDown); + MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown); + MESSAGE_HANDLER(WM_PASTE, OnPaste); MESSAGE_HANDLER(WM_VALIDATE_VALUE, OnValidateValue); + } END_MSG_MAP() bool IsHexConvertableText(LPTSTR _text); void FormatClipboard(); - LRESULT OnValidateValue(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnPaste(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnValidateValue(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnPaste(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); + LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); }; diff --git a/Source/Project64/UserInterface/WTLControls/HexEditCtrl.cpp b/Source/Project64/UserInterface/WTLControls/HexEditCtrl.cpp index 8be43d369..9039f980b 100644 --- a/Source/Project64/UserInterface/WTLControls/HexEditCtrl.cpp +++ b/Source/Project64/UserInterface/WTLControls/HexEditCtrl.cpp @@ -560,9 +560,7 @@ void CHexEditCtrl::UpdateRealSelection(void) } } - if (m_RealSelStartAddress != start || - m_RealSelEndAddress != end || - m_bHaveRealSel != bHaveSel) + if (m_RealSelStartAddress != start || m_RealSelEndAddress != end || m_bHaveRealSel != bHaveSel) { m_bHaveRealSel = bHaveSel; m_RealSelStartAddress = start; @@ -984,9 +982,7 @@ void CHexEditCtrl::OnMouseMove(UINT /*nFlags*/, CPoint point) m_SelEndCellSide = ht.hexCellSide; m_bCaretLoNibble = (ht.hexCellSide == HX_RIGHT); - if (m_SelEndAddress - m_SelStartAddress == 1 && - m_SelStartCellSide == HX_RIGHT && - m_SelEndCellSide == HX_LEFT) + if (m_SelEndAddress - m_SelStartAddress == 1 && m_SelStartCellSide == HX_RIGHT && m_SelEndCellSide == HX_LEFT) { m_SelStartCellSide = HX_LEFT; } @@ -1259,9 +1255,7 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/) { if (GetKeyState(VK_SHIFT) & 0x8000) { - if (m_SelStartAddress == m_SelEndAddress && - m_SelStartCellSide == HX_RIGHT && - m_SelEndCellSide == HX_RIGHT) + if (m_SelStartAddress == m_SelEndAddress && m_SelStartCellSide == HX_RIGHT && m_SelEndCellSide == HX_RIGHT) { m_SelStartCellSide = HX_LEFT; m_SelEndCellSide = HX_RIGHT; diff --git a/Source/Project64/UserInterface/WTLControls/HexEditCtrl.h b/Source/Project64/UserInterface/WTLControls/HexEditCtrl.h index f256bfc52..6c71a4043 100644 --- a/Source/Project64/UserInterface/WTLControls/HexEditCtrl.h +++ b/Source/Project64/UserInterface/WTLControls/HexEditCtrl.h @@ -29,27 +29,27 @@ enum HXCOLUMN typedef struct HXBYTEINFO_S { - bool bHidden; - bool bValid; - uint8_t value; + bool bHidden; + bool bValid; + uint8_t value; COLORREF color; COLORREF bkColor; - bool operator==(const HXBYTEINFO_S& b) const + bool operator==(const HXBYTEINFO_S & b) const { return memcmp(this, &b, sizeof(HXBYTEINFO_S)) == 0; } - bool operator!=(const HXBYTEINFO_S& b) const + bool operator!=(const HXBYTEINFO_S & b) const { return memcmp(this, &b, sizeof(HXBYTEINFO_S)) != 0; } } HXBYTEINFO; -template<> +template <> struct std::hash { - std::size_t operator()(const HXBYTEINFO& k) const + std::size_t operator()(const HXBYTEINFO & k) const { return (size_t)(k.bValid * 0xFFFFFFFF) ^ (k.value * 0x1010101) ^ k.color ^ k.bkColor; } @@ -57,57 +57,57 @@ struct std::hash typedef struct { - NMHDR nmh; - uint32_t address; - size_t numBytes; - bool bIgnoreDiff; - HXBYTEINFO* oldBytes; - HXBYTEINFO* newBytes; + NMHDR nmh; + uint32_t address; + size_t numBytes; + bool bIgnoreDiff; + HXBYTEINFO * oldBytes; + HXBYTEINFO * newBytes; } NMHXGETBYTEINFO; typedef struct { - NMHDR nmh; - bool bInsert; + NMHDR nmh; + bool bInsert; uint32_t address; - uint8_t value; + uint8_t value; } NMHXSETBYTE; typedef struct { - NMHDR nmh; - bool bInsert; + NMHDR nmh; + bool bInsert; uint32_t address; - bool bLoNibble; - uint8_t value; + bool bLoNibble; + uint8_t value; } NMHXSETNIBBLE; typedef struct { - NMHDR nmh; - bool bInsert; + NMHDR nmh; + bool bInsert; uint32_t startAddress; uint32_t endAddress; - uint8_t value; + uint8_t value; } NMHXFILLRANGE; typedef struct { - NMHDR nmh; + NMHDR nmh; uint32_t address; uint32_t length; - uint8_t* data; + uint8_t * data; } NMHXSETBYTES; typedef struct { - NMHDR nmh; + NMHDR nmh; uint32_t address; } NMHXRCLICK; typedef struct { - NMHDR nmh; + NMHDR nmh; uint32_t address; HXCOLUMN column; } NMHXPASTE; @@ -115,7 +115,7 @@ typedef struct typedef struct { NMHDR nmh; - int nChar; + int nChar; } NMHXCTRLKEYPRESSED; class CHexEditCtrl : @@ -125,31 +125,31 @@ public: CHexEditCtrl(void); ~CHexEditCtrl(void); DECLARE_WND_CLASS(_T("HexEditCtrl")) - BOOL Attach(HWND hWnd); - HWND Detach(void); + BOOL Attach(HWND hWnd); + HWND Detach(void); static char ByteAscii(uint8_t value); static uint8_t HexCharValue(char c); - static int CALLBACK HaveFontCb(CONST LOGFONTW *lplf, CONST TEXTMETRICW *lptm, DWORD FontType, LPARAM lParam); - static bool HaveFont(HDC hdc, const char* name); + static int CALLBACK HaveFontCb(CONST LOGFONTW * lplf, CONST TEXTMETRICW * lptm, DWORD FontType, LPARAM lParam); + static bool HaveFont(HDC hdc, const char * name); - void Draw(void); - - void Copy(void); - void Paste(bool bAdvanceCaret = true); - - void SetBaseAddress(uint32_t address); - void SetByteGroupSize(int nBytes); + void Draw(void); + + void Copy(void); + void Paste(bool bAdvanceCaret = true); + + void SetBaseAddress(uint32_t address); + void SetByteGroupSize(int nBytes); uint32_t GetBaseAddress(void); uint32_t GetCaretAddress(void); uint32_t GetHotAddress(void); - int GetNumBytesPerGroup(void); - int GetNumBytesPerRow(void); - int GetNumVisibleBytes(void); - bool GetSelectionRange(uint32_t* startAddress, uint32_t* endAddress); + int GetNumBytesPerGroup(void); + int GetNumBytesPerRow(void); + int GetNumVisibleBytes(void); + bool GetSelectionRange(uint32_t * startAddress, uint32_t * endAddress); HXCOLUMN GetFocusedColumn(void); - bool GetInsertMode(void); + bool GetInsertMode(void); private: enum HXCELLSIDE @@ -166,23 +166,23 @@ private: enum { - BKCOLOR_DEFAULT = RGB(255, 255, 255), - BKCOLOR_ADDR = RGB(220, 220, 220), - COLOR_ADDR = RGB(40, 40, 40), - BKCOLOR_SEL_FOCUSED = RGB(51, 153, 255), - COLOR_SEL_FOCUSED = RGB(255, 255, 255), + BKCOLOR_DEFAULT = RGB(255, 255, 255), + BKCOLOR_ADDR = RGB(220, 220, 220), + COLOR_ADDR = RGB(40, 40, 40), + BKCOLOR_SEL_FOCUSED = RGB(51, 153, 255), + COLOR_SEL_FOCUSED = RGB(255, 255, 255), BKCOLOR_SEL_UNFOCUSED = RGB(200, 200, 200), - COLOR_SEL_UNFOCUSED = RGB(0, 0, 0), - BKCOLOR_HOT = RGB(140, 140, 140) + COLOR_SEL_UNFOCUSED = RGB(0, 0, 0), + BKCOLOR_HOT = RGB(140, 140, 140) }; typedef struct { - HXCOLUMN column; - uint32_t asciiAddress; - HXCELLSIDE asciiCellSide; - uint32_t hexAddress; - HXCELLSIDE hexCellSide; + HXCOLUMN column; + uint32_t asciiAddress; + HXCELLSIDE asciiCellSide; + uint32_t hexAddress; + HXCELLSIDE hexCellSide; } HXHITTEST; typedef struct @@ -191,78 +191,78 @@ private: CRect rcAscii; } HXRECTPAIR; - uint32_t m_BaseAddress; - uint32_t m_DrawnBaseAddress; - uint32_t m_SelStartAddress; - HXCELLSIDE m_SelStartCellSide; - uint32_t m_SelEndAddress; - HXCELLSIDE m_SelEndCellSide; - uint32_t m_RealSelStartAddress; - uint32_t m_RealSelEndAddress; - bool m_bHaveRealSel; - bool m_bInsertMode; - bool m_bHaveCaret; - bool m_bCaretVisible; - uint32_t m_CaretAddress; - bool m_bCaretLoNibble; - bool m_bShowHotAddress; - uint32_t m_HotAddress; - HXCOLUMN m_FocusedColumn; - HFONT m_Font; - HBITMAP m_BackBMP; - HDC m_BackDC; - HCURSOR m_hCursorIBeam; - HCURSOR m_hCursorDefault; - int m_DragScrollDelta; - bool m_bDblClicked; - bool m_bLButtonDown; - bool m_bMouseDragging; - bool m_bLayoutChanged; - int m_CharWidth; - int m_CharHeight; - CRect m_AddressColumnRect; - CRect m_HexDataColumnRect; - CRect m_AsciiColumnRect; - int m_NumBytesPerGroup; - int m_NumByteGroupsPerRow; - int m_NumBytesPerRow; - int m_NumVisibleRows; - int m_NumVisibleBytes; - HXBYTEINFO* m_NewBytes; - HXBYTEINFO* m_OldBytes; + uint32_t m_BaseAddress; + uint32_t m_DrawnBaseAddress; + uint32_t m_SelStartAddress; + HXCELLSIDE m_SelStartCellSide; + uint32_t m_SelEndAddress; + HXCELLSIDE m_SelEndCellSide; + uint32_t m_RealSelStartAddress; + uint32_t m_RealSelEndAddress; + bool m_bHaveRealSel; + bool m_bInsertMode; + bool m_bHaveCaret; + bool m_bCaretVisible; + uint32_t m_CaretAddress; + bool m_bCaretLoNibble; + bool m_bShowHotAddress; + uint32_t m_HotAddress; + HXCOLUMN m_FocusedColumn; + HFONT m_Font; + HBITMAP m_BackBMP; + HDC m_BackDC; + HCURSOR m_hCursorIBeam; + HCURSOR m_hCursorDefault; + int m_DragScrollDelta; + bool m_bDblClicked; + bool m_bLButtonDown; + bool m_bMouseDragging; + bool m_bLayoutChanged; + int m_CharWidth; + int m_CharHeight; + CRect m_AddressColumnRect; + CRect m_HexDataColumnRect; + CRect m_AsciiColumnRect; + int m_NumBytesPerGroup; + int m_NumByteGroupsPerRow; + int m_NumBytesPerRow; + int m_NumVisibleRows; + int m_NumVisibleBytes; + HXBYTEINFO * m_NewBytes; + HXBYTEINFO * m_OldBytes; static COLORREF BlendColor(COLORREF c1, COLORREF c2); static uint32_t SatAdd32(uint32_t a, uint32_t b); static uint32_t SatAdd32(uint32_t a, int b); - void DrawAddressColumn(void); - void DrawHeader(void); - void Text(int x, int y, const char *text, COLORREF bg, COLORREF fg, CRect* rcOut); - bool IsSelected(uint32_t address); - int GetSelDirection(void); - void CancelSelection(void); - void SelectAllVisible(void); - void UpdateRealSelection(void); + void DrawAddressColumn(void); + void DrawHeader(void); + void Text(int x, int y, const char * text, COLORREF bg, COLORREF fg, CRect * rcOut); + bool IsSelected(uint32_t address); + int GetSelDirection(void); + void CancelSelection(void); + void SelectAllVisible(void); + void UpdateRealSelection(void); uint32_t LineAddress(uint32_t address); - void GetHexCellPos(int index, CRect* rc); - void GetAsciiCellPos(int index, CRect* rc); - void HitTest(int x, int y, HXHITTEST* pht); + void GetHexCellPos(int index, CRect * rc); + void GetAsciiCellPos(int index, CRect * rc); + void HitTest(int x, int y, HXHITTEST * pht); - void ShowCaret(void); - void HideCaret(void); - void CaretIncrementNibble(void); - void CaretDecrementNibble(void); - bool UpdateCaretUI(bool bEnsureVisible, bool bTop = false); - void EnsureCaretAddressVisible(bool bTop = false); - bool IsCaretAddressVisible(void); + void ShowCaret(void); + void HideCaret(void); + void CaretIncrementNibble(void); + void CaretDecrementNibble(void); + bool UpdateCaretUI(bool bEnsureVisible, bool bTop = false); + void EnsureCaretAddressVisible(bool bTop = false); + bool IsCaretAddressVisible(void); - void UpdateLayoutInfo(void); - void ReallocByteBuffers(void); + void UpdateLayoutInfo(void); + void ReallocByteBuffers(void); LRESULT Notify(UINT code); - LRESULT NotifyGetByteInfo(uint32_t address, size_t numBytes, bool bIgnoreDiff, HXBYTEINFO* oldBytes, HXBYTEINFO* newBytes); + LRESULT NotifyGetByteInfo(uint32_t address, size_t numBytes, bool bIgnoreDiff, HXBYTEINFO * oldBytes, HXBYTEINFO * newBytes); LRESULT NotifySetByte(uint32_t address, uint8_t value); LRESULT NotifySetNibble(uint32_t address, bool bLoNibble, uint8_t value); LRESULT NotifyFillRange(uint32_t startAddress, uint32_t endAddress, uint8_t value); @@ -270,39 +270,41 @@ private: LRESULT NotifyPaste(uint32_t address); LRESULT NotifyRightClick(uint32_t address); - void OnLButtonDown(UINT nFlags, CPoint point); - void OnLButtonDblClk(UINT nFlags, CPoint point); - void OnLButtonUp(UINT nFlags, CPoint point); - void OnRButtonDown(UINT nFlags, CPoint point); - void OnRButtonUp(UINT nFlags, CPoint point); - void OnMouseMove(UINT nFlags, CPoint point); - BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); - void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); - void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); - void OnSetFocus(CWindow wndOld); - void OnKillFocus(CWindow wndFocus); - void OnTimer(UINT_PTR nIDEvent); - UINT OnGetDlgCode(LPMSG lpMsg); - void OnPaint(CDCHandle dc); - BOOL OnSetCursor(CWindow wnd, UINT nHitTest, UINT message); - void OnWindowPosChanged(LPWINDOWPOS lpWndPos); + void OnLButtonDown(UINT nFlags, CPoint point); + void OnLButtonDblClk(UINT nFlags, CPoint point); + void OnLButtonUp(UINT nFlags, CPoint point); + void OnRButtonDown(UINT nFlags, CPoint point); + void OnRButtonUp(UINT nFlags, CPoint point); + void OnMouseMove(UINT nFlags, CPoint point); + BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); + void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); + void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); + void OnSetFocus(CWindow wndOld); + void OnKillFocus(CWindow wndFocus); + void OnTimer(UINT_PTR nIDEvent); + UINT OnGetDlgCode(LPMSG lpMsg); + void OnPaint(CDCHandle dc); + BOOL OnSetCursor(CWindow wnd, UINT nHitTest, UINT message); + void OnWindowPosChanged(LPWINDOWPOS lpWndPos); BEGIN_MSG_MAP_EX(CHexEditCtrl) - MSG_WM_RBUTTONDOWN(OnRButtonDown) - MSG_WM_LBUTTONDOWN(OnLButtonDown) - MSG_WM_LBUTTONUP(OnLButtonUp) - MSG_WM_RBUTTONUP(OnRButtonUp) - MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) - MSG_WM_MOUSEMOVE(OnMouseMove) - MSG_WM_MOUSEWHEEL(OnMouseWheel) - MSG_WM_KEYDOWN(OnKeyDown) - MSG_WM_CHAR(OnChar) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_KILLFOCUS(OnKillFocus) - MSG_WM_TIMER(OnTimer) - MSG_WM_GETDLGCODE(OnGetDlgCode) - MSG_WM_PAINT(OnPaint) - MSG_WM_SETCURSOR(OnSetCursor) - MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) + { + MSG_WM_RBUTTONDOWN(OnRButtonDown); + MSG_WM_LBUTTONDOWN(OnLButtonDown); + MSG_WM_LBUTTONUP(OnLButtonUp); + MSG_WM_RBUTTONUP(OnRButtonUp); + MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk); + MSG_WM_MOUSEMOVE(OnMouseMove); + MSG_WM_MOUSEWHEEL(OnMouseWheel); + MSG_WM_KEYDOWN(OnKeyDown); + MSG_WM_CHAR(OnChar); + MSG_WM_SETFOCUS(OnSetFocus); + MSG_WM_KILLFOCUS(OnKillFocus); + MSG_WM_TIMER(OnTimer); + MSG_WM_GETDLGCODE(OnGetDlgCode); + MSG_WM_PAINT(OnPaint); + MSG_WM_SETCURSOR(OnSetCursor); + MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged); + } END_MSG_MAP() }; diff --git a/Source/Project64/UserInterface/WTLControls/ModifiedCheckBox.h b/Source/Project64/UserInterface/WTLControls/ModifiedCheckBox.h index 7695460d1..1c38f0784 100644 --- a/Source/Project64/UserInterface/WTLControls/ModifiedCheckBox.h +++ b/Source/Project64/UserInterface/WTLControls/ModifiedCheckBox.h @@ -1,75 +1,76 @@ #pragma once -class CModifiedButton : - public CButton +class CModifiedButton : + public CButton { - bool m_Changed; - bool m_Reset; - HFONT m_BoldFont; - HFONT m_OriginalFont; - + bool m_Changed; + bool m_Reset; + HFONT m_BoldFont; + HFONT m_OriginalFont; public: - // Constructors - CModifiedButton(HWND hWnd = nullptr) : - CButton(hWnd), - m_Changed(false), - m_Reset(false), - m_BoldFont(nullptr), - m_OriginalFont(nullptr) - { - } - - ~CModifiedButton() - { - if (m_BoldFont) - { - DeleteObject(m_BoldFont); - } - } + // Constructors + CModifiedButton(HWND hWnd = nullptr) : + CButton(hWnd), + m_Changed(false), + m_Reset(false), + m_BoldFont(nullptr), + m_OriginalFont(nullptr) + { + } - void SetReset (bool Reset) - { - m_Reset = Reset; - if (m_Reset) - { - SetChanged(false); - } - } + ~CModifiedButton() + { + if (m_BoldFont) + { + DeleteObject(m_BoldFont); + } + } - void SetChanged (bool Changed) - { - m_Changed = Changed; - if (m_Changed) - { - SetReset(false); - if (m_BoldFont == nullptr) - { - m_OriginalFont = (HFONT)SendMessage(WM_GETFONT); + void SetReset(bool Reset) + { + m_Reset = Reset; + if (m_Reset) + { + SetChanged(false); + } + } - LOGFONT lfSystemVariableFont; - GetObject ( m_OriginalFont, sizeof(LOGFONT), &lfSystemVariableFont ); - lfSystemVariableFont.lfWeight = FW_BOLD; + void SetChanged(bool Changed) + { + m_Changed = Changed; + if (m_Changed) + { + SetReset(false); + if (m_BoldFont == nullptr) + { + m_OriginalFont = (HFONT)SendMessage(WM_GETFONT); - m_BoldFont = CreateFontIndirect ( &lfSystemVariableFont ); - } - SendMessage(WM_SETFONT,(WPARAM)m_BoldFont); - InvalidateRect(nullptr); - } else { - if (m_OriginalFont) - { - SendMessage(WM_SETFONT,(WPARAM)m_OriginalFont); - InvalidateRect(nullptr); - } - } - } + LOGFONT lfSystemVariableFont; + GetObject(m_OriginalFont, sizeof(LOGFONT), &lfSystemVariableFont); + lfSystemVariableFont.lfWeight = FW_BOLD; - inline bool IsChanged ( void ) const - { - return m_Changed; - } - inline bool IsReset ( void ) const - { - return m_Reset; - } + m_BoldFont = CreateFontIndirect(&lfSystemVariableFont); + } + SendMessage(WM_SETFONT, (WPARAM)m_BoldFont); + InvalidateRect(nullptr); + } + else + { + if (m_OriginalFont) + { + SendMessage(WM_SETFONT, (WPARAM)m_OriginalFont); + InvalidateRect(nullptr); + } + } + } + + inline bool IsChanged(void) const + { + return m_Changed; + } + inline bool IsReset(void) const + { + return m_Reset; + } }; diff --git a/Source/Project64/UserInterface/WTLControls/ModifiedComboBox.h b/Source/Project64/UserInterface/WTLControls/ModifiedComboBox.h index 31ae0c213..9e5b10e4a 100644 --- a/Source/Project64/UserInterface/WTLControls/ModifiedComboBox.h +++ b/Source/Project64/UserInterface/WTLControls/ModifiedComboBox.h @@ -1,152 +1,152 @@ #pragma once template -class CModifiedComboBoxT : - public CComboBox +class CModifiedComboBoxT : + public CComboBox { - typedef std::list TParamList; - + typedef std::list TParamList; + public: - // Constructors - CModifiedComboBoxT(TParam defaultValue, HWND hWnd = nullptr, bool AllwaysSelected = true) : - CComboBox(hWnd), - m_Changed(false), - m_Reset(false), - m_defaultValue(defaultValue), - m_BoldFont(nullptr), - m_OriginalFont(nullptr), - m_TextField(nullptr), - m_AllwaysSelected(AllwaysSelected) - { - } - - ~CModifiedComboBoxT() - { - if (m_BoldFont) - { - DeleteObject(m_BoldFont); - } - for (TParamList::iterator iter = m_ParamList.begin(); iter != m_ParamList.end(); iter ++) - { - TParam * Item = (TParam *)*iter; - if (Item) - { - delete Item; - } - } - } + // Constructors + CModifiedComboBoxT(TParam defaultValue, HWND hWnd = nullptr, bool AllwaysSelected = true) : + CComboBox(hWnd), + m_Changed(false), + m_Reset(false), + m_defaultValue(defaultValue), + m_BoldFont(nullptr), + m_OriginalFont(nullptr), + m_TextField(nullptr), + m_AllwaysSelected(AllwaysSelected) + { + } - int AddItem (LPCTSTR strItem, const TParam & lParam) - { - int indx = AddString(strItem); - TParam * Value = new TParam(lParam); - SetItemData(indx,(DWORD_PTR)(Value)); - m_ParamList.push_back(Value); - if ((m_AllwaysSelected && GetCount() == 1) || m_defaultValue == lParam) - { - SetCurSel(indx); - } - return indx; - } + ~CModifiedComboBoxT() + { + if (m_BoldFont) + { + DeleteObject(m_BoldFont); + } + for (TParamList::iterator iter = m_ParamList.begin(); iter != m_ParamList.end(); iter++) + { + TParam * Item = (TParam *)*iter; + if (Item) + { + delete Item; + } + } + } - void SetReset ( bool Reset ) - { - m_Reset = Reset; - if (m_Reset) - { - SetChanged(false); - } - } - - void SetChanged (bool Changed) - { - m_Changed = Changed; - if (m_Changed) - { - SetReset(false); - if (m_BoldFont == nullptr) - { - m_OriginalFont = (HFONT)SendMessage(WM_GETFONT); + int AddItem(LPCTSTR strItem, const TParam & lParam) + { + int indx = AddString(strItem); + TParam * Value = new TParam(lParam); + SetItemData(indx, (DWORD_PTR)(Value)); + m_ParamList.push_back(Value); + if ((m_AllwaysSelected && GetCount() == 1) || m_defaultValue == lParam) + { + SetCurSel(indx); + } + return indx; + } - LOGFONT lfSystemVariableFont; - GetObject ( m_OriginalFont, sizeof(LOGFONT), &lfSystemVariableFont ); - lfSystemVariableFont.lfWeight = FW_BOLD; + void SetReset(bool Reset) + { + m_Reset = Reset; + if (m_Reset) + { + SetChanged(false); + } + } - m_BoldFont = CreateFontIndirect ( &lfSystemVariableFont ); - } - SendMessage(WM_SETFONT,(WPARAM)m_BoldFont); - InvalidateRect(nullptr); - if (m_TextField) - { - ::SendMessage(m_TextField,WM_SETFONT,(WPARAM)m_BoldFont,0); - ::InvalidateRect(m_TextField, nullptr, true); - - } - } else { - if (m_OriginalFont) - { - SendMessage(WM_SETFONT,(WPARAM)m_OriginalFont); - InvalidateRect(nullptr); - if (m_TextField) - { - ::SendMessage(m_TextField,WM_SETFONT,(WPARAM)m_OriginalFont,0); - ::InvalidateRect(m_TextField, nullptr, true); - } - } - } - } + void SetChanged(bool Changed) + { + m_Changed = Changed; + if (m_Changed) + { + SetReset(false); + if (m_BoldFont == nullptr) + { + m_OriginalFont = (HFONT)SendMessage(WM_GETFONT); - void SetTextField (HWND hWnd) - { - if (m_TextField && m_OriginalFont) - { - ::SendMessage(m_TextField,WM_SETFONT,(WPARAM)m_OriginalFont,0); - } - m_TextField = hWnd; - if (m_Changed && m_BoldFont) - { - ::SendMessage(m_TextField,WM_SETFONT,(WPARAM)m_BoldFont,0); - } - } + LOGFONT lfSystemVariableFont; + GetObject(m_OriginalFont, sizeof(LOGFONT), &lfSystemVariableFont); + lfSystemVariableFont.lfWeight = FW_BOLD; - inline void SetDefault (const TParam & defaultValue) - { - m_defaultValue = defaultValue; - for (int i = 0, n = GetCount(); i < n; i++) - { - if (*((TParam *)GetItemData(i)) == m_defaultValue) - { - SetCurSel(i); - break; - } - } - } + m_BoldFont = CreateFontIndirect(&lfSystemVariableFont); + } + SendMessage(WM_SETFONT, (WPARAM)m_BoldFont); + InvalidateRect(nullptr); + if (m_TextField) + { + ::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_BoldFont, 0); + ::InvalidateRect(m_TextField, nullptr, true); + } + } + else + { + if (m_OriginalFont) + { + SendMessage(WM_SETFONT, (WPARAM)m_OriginalFont); + InvalidateRect(nullptr); + if (m_TextField) + { + ::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_OriginalFont, 0); + ::InvalidateRect(m_TextField, nullptr, true); + } + } + } + } - inline bool IsChanged ( void ) const - { - return m_Changed; - } - inline bool IsReset ( void ) const - { - return m_Reset; - } + void SetTextField(HWND hWnd) + { + if (m_TextField && m_OriginalFont) + { + ::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_OriginalFont, 0); + } + m_TextField = hWnd; + if (m_Changed && m_BoldFont) + { + ::SendMessage(m_TextField, WM_SETFONT, (WPARAM)m_BoldFont, 0); + } + } + + inline void SetDefault(const TParam & defaultValue) + { + m_defaultValue = defaultValue; + for (int i = 0, n = GetCount(); i < n; i++) + { + if (*((TParam *)GetItemData(i)) == m_defaultValue) + { + SetCurSel(i); + break; + } + } + } + + inline bool IsChanged(void) const + { + return m_Changed; + } + inline bool IsReset(void) const + { + return m_Reset; + } private: - CModifiedComboBoxT(void); - CModifiedComboBoxT(const CModifiedComboBoxT&); - CModifiedComboBoxT& operator=(const CModifiedComboBoxT&); + CModifiedComboBoxT(void); + CModifiedComboBoxT(const CModifiedComboBoxT &); + CModifiedComboBoxT & operator=(const CModifiedComboBoxT &); - bool m_Changed; - bool m_Reset; - TParam m_defaultValue; - HFONT m_BoldFont; - HFONT m_OriginalFont; - HWND m_TextField; - bool m_AllwaysSelected; - - TParamList m_ParamList; + bool m_Changed; + bool m_Reset; + TParam m_defaultValue; + HFONT m_BoldFont; + HFONT m_OriginalFont; + HWND m_TextField; + bool m_AllwaysSelected; + TParamList m_ParamList; }; -typedef CModifiedComboBoxT CModifiedComboBox; -typedef CModifiedComboBoxT CModifiedComboBoxTxt; +typedef CModifiedComboBoxT CModifiedComboBox; +typedef CModifiedComboBoxT CModifiedComboBoxTxt; diff --git a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h index a5b76d6ce..0805dda6d 100644 --- a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h +++ b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h @@ -1,34 +1,34 @@ #pragma once -class CModifiedEditBox : - public CEdit +class CModifiedEditBox : + public CEdit { - bool m_Changed; - bool m_Reset; - HFONT m_BoldFont; - HFONT m_OriginalFont; - HWND m_TextField; - bool m_bString; + bool m_Changed; + bool m_Reset; + HFONT m_BoldFont; + HFONT m_OriginalFont; + HWND m_TextField; + bool m_bString; public: - // Constructors - CModifiedEditBox(bool bString = true, HWND hWnd = nullptr); - ~CModifiedEditBox(); - - void SetReset ( bool Reset ); - void SetChanged (bool Changed); - void SetTextField (HWND hWnd); + // Constructors + CModifiedEditBox(bool bString = true, HWND hWnd = nullptr); + ~CModifiedEditBox(); - inline bool IsChanged ( void ) const - { - return m_Changed; - } - inline bool IsReset ( void ) const - { - return m_Reset; - } - inline bool IsbString ( void ) const - { - return m_bString; - } + void SetReset(bool Reset); + void SetChanged(bool Changed); + void SetTextField(HWND hWnd); + + inline bool IsChanged(void) const + { + return m_Changed; + } + inline bool IsReset(void) const + { + return m_Reset; + } + inline bool IsbString(void) const + { + return m_bString; + } }; diff --git a/Source/Project64/UserInterface/WTLControls/PartialGroupBox.h b/Source/Project64/UserInterface/WTLControls/PartialGroupBox.h index 799180e77..9254ce5dd 100644 --- a/Source/Project64/UserInterface/WTLControls/PartialGroupBox.h +++ b/Source/Project64/UserInterface/WTLControls/PartialGroupBox.h @@ -1,25 +1,25 @@ #pragma once -class CPartialGroupBox : - public CWindowImpl +class CPartialGroupBox : + public CWindowImpl { - void Draw3dLine(CPaintDC & dc, LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight); + void Draw3dLine(CPaintDC & dc, LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight); public: - BEGIN_MSG_MAP_EX(CPartialGroupBox) - MSG_WM_PAINT(OnPaint) - END_MSG_MAP() + BEGIN_MSG_MAP_EX(CPartialGroupBox) + MSG_WM_PAINT(OnPaint) + END_MSG_MAP() - // Constructors - CPartialGroupBox() - { - } - - virtual ~CPartialGroupBox() - { - } + // Constructors + CPartialGroupBox() + { + } - BOOL Attach(HWND hWndNew); - BOOL AttachToDlgItem(HWND parent, UINT dlgID); - void OnPaint(HDC hDC); + virtual ~CPartialGroupBox() + { + } + + BOOL Attach(HWND hWndNew); + BOOL AttachToDlgItem(HWND parent, UINT dlgID); + void OnPaint(HDC hDC); }; diff --git a/Source/Project64/UserInterface/WTLControls/TooltipDialog.h b/Source/Project64/UserInterface/WTLControls/TooltipDialog.h index ebefb115e..c366a7c0d 100644 --- a/Source/Project64/UserInterface/WTLControls/TooltipDialog.h +++ b/Source/Project64/UserInterface/WTLControls/TooltipDialog.h @@ -1,53 +1,54 @@ #pragma once -typedef struct { - WORD ctrlId; - char* text; +typedef struct +{ + WORD ctrlId; + char * text; } _ToolTipMap; template class CToolTipDialog { private: - HWND m_hWndTooltip; + HWND m_hWndTooltip; public: - CToolTipDialog() - { - } + CToolTipDialog() + { + } - void AddToolTip(WORD ctrlId, char* lpszText) - { - T* pT = static_cast(this); + void AddToolTip(WORD ctrlId, char * lpszText) + { + T * pT = static_cast(this); std::wstring wcText = stdstr(lpszText).ToUTF16(); - TOOLINFO toolInfo = { 0 }; - toolInfo.cbSize = sizeof(toolInfo); - toolInfo.hwnd = pT->m_hWnd; - toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; - toolInfo.uId = (UINT_PTR) ::GetDlgItem(pT->m_hWnd, ctrlId); - toolInfo.lpszText = (LPWSTR)wcText.c_str(); - SendMessage(m_hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); - } + TOOLINFO toolInfo = {0}; + toolInfo.cbSize = sizeof(toolInfo); + toolInfo.hwnd = pT->m_hWnd; + toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; + toolInfo.uId = (UINT_PTR)::GetDlgItem(pT->m_hWnd, ctrlId); + toolInfo.lpszText = (LPWSTR)wcText.c_str(); + SendMessage(m_hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); + } - void DlgToolTip_Init() - { - T* pT = static_cast(this); + void DlgToolTip_Init() + { + T * pT = static_cast(this); - m_hWndTooltip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, - WS_POPUP | TTS_ALWAYSTIP, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - pT->m_hWnd, NULL, - NULL, NULL); + m_hWndTooltip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL, + WS_POPUP | TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + pT->m_hWnd, NULL, + NULL, NULL); - const _ToolTipMap* map = pT->_GetToolTipMap(); + const _ToolTipMap * map = pT->_GetToolTipMap(); - for (int i = 0; map[i].ctrlId != 0; i++) - { - AddToolTip(map[i].ctrlId, map[i].text); - } - } + for (int i = 0; map[i].ctrlId != 0; i++) + { + AddToolTip(map[i].ctrlId, map[i].text); + } + } }; #define BEGIN_TOOLTIP_MAP() static const _ToolTipMap* _GetToolTipMap() { static const _ToolTipMap map[] = { diff --git a/Source/Project64/UserInterface/WTLControls/wtl-BitmapPicture.h b/Source/Project64/UserInterface/WTLControls/wtl-BitmapPicture.h index a52717358..8d47bb2e8 100644 --- a/Source/Project64/UserInterface/WTLControls/wtl-BitmapPicture.h +++ b/Source/Project64/UserInterface/WTLControls/wtl-BitmapPicture.h @@ -1,32 +1,34 @@ #pragma once class CBitmapPicture : - public CWindowImpl + public CWindowImpl { public: - BEGIN_MSG_MAP(CBitmapPicture) - MESSAGE_HANDLER(WM_PAINT, OnPaint); - END_MSG_MAP() + BEGIN_MSG_MAP(CBitmapPicture) + { + MESSAGE_HANDLER(WM_PAINT, OnPaint); + } + END_MSG_MAP() - CBitmapPicture(); + CBitmapPicture(); - LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL &/*bHandled*/); + LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/); - bool SetIcon(LPCWSTR lpszResourceName, uint32_t nWidth, uint32_t nHeight); + bool SetIcon(LPCWSTR lpszResourceName, uint32_t nWidth, uint32_t nHeight); void SetBitmap(LPCWSTR lpszResourceName); void SetBackroundBrush(HBRUSH brush); private: - CBitmapPicture(const CBitmapPicture&); - CBitmapPicture& operator=(const CBitmapPicture&); + CBitmapPicture(const CBitmapPicture &); + CBitmapPicture & operator=(const CBitmapPicture &); - bool CBitmapPicture::SetBitmap(HBITMAP hBitmap); + bool CBitmapPicture::SetBitmap(HBITMAP hBitmap); - int m_nResourceID; - std::wstring m_strResourceName; - uint32_t m_IconWidth, m_IconHeight; - bool m_ResourceIcon; - BITMAP m_bmInfo; - CBitmap m_hBitmap; - CBrush m_BackgroundBrush; + int m_nResourceID; + std::wstring m_strResourceName; + uint32_t m_IconWidth, m_IconHeight; + bool m_ResourceIcon; + BITMAP m_bmInfo; + CBitmap m_hBitmap; + CBrush m_BackgroundBrush; }; diff --git a/Source/Project64/UserInterface/WelcomeScreen.h b/Source/Project64/UserInterface/WelcomeScreen.h index 56a6ba627..32950bfea 100644 --- a/Source/Project64/UserInterface/WelcomeScreen.h +++ b/Source/Project64/UserInterface/WelcomeScreen.h @@ -1,31 +1,36 @@ #pragma once -#include #include "resource.h" +#include class WelcomeScreen : public CDialogImpl { public: BEGIN_MSG_MAP_EX(WelcomeScreen) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic) - MSG_WM_ERASEBKGND(OnEraseBackground) - COMMAND_ID_HANDLER_EX(IDC_SELECT_GAME_DIR, SelectGameDir) - COMMAND_ID_HANDLER(IDOK, OnOkCmd) + { + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog); + MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic); + MSG_WM_ERASEBKGND(OnEraseBackground); + COMMAND_ID_HANDLER_EX(IDC_SELECT_GAME_DIR, SelectGameDir); + COMMAND_ID_HANDLER(IDOK, OnOkCmd); + } END_MSG_MAP() - enum { IDD = IDD_Welcome }; - + enum + { + IDD = IDD_Welcome + }; + WelcomeScreen(void); private: - WelcomeScreen(const WelcomeScreen&); - WelcomeScreen& operator=(const WelcomeScreen&); + WelcomeScreen(const WelcomeScreen &); + WelcomeScreen & operator=(const WelcomeScreen &); void SelectGameDir(UINT Code, int id, HWND ctl); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); - LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled); HBRUSH OnCtlColorStatic(CDCHandle dc, CStatic wndStatic); BOOL OnEraseBackground(CDCHandle dc); LRESULT OnOkCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL & bHandled); diff --git a/Source/Project64/stdafx.h b/Source/Project64/stdafx.h index 4d1a75123..63c4e1dce 100644 --- a/Source/Project64/stdafx.h +++ b/Source/Project64/stdafx.h @@ -1,21 +1,20 @@ #pragma once -#pragma warning(disable:4247) -#pragma warning(disable:4786) +#pragma warning(disable : 4247) +#pragma warning(disable : 4786) -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") -#include -#include -#include -#include "UserInterface.h" #include "N64System.h" -#include #include "Support.h" -#include -#include -#include +#include "UserInterface.h" #include - -#include +#include +#include #include +#include +#include +#include +#include +#include +#include