CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/Debugger/WatchItemWindow.cpp
Views: 1401
// Copyright (c) 2023- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Common/Common.h"18#include "Common/Data/Encoding/Utf8.h"19#include "Windows/Debugger/WatchItemWindow.h"20#include "Windows/resource.h"2122INT_PTR CALLBACK WatchItemWindow::StaticDlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {23WatchItemWindow *thiz;24if (iMsg == WM_INITDIALOG) {25SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lParam);26thiz = (WatchItemWindow *)lParam;27} else {28thiz = (WatchItemWindow *)GetWindowLongPtr(hWnd, GWLP_USERDATA);29}3031if (!thiz)32return FALSE;33return thiz->DlgFunc(hWnd, iMsg, wParam, lParam);34}3536INT_PTR WatchItemWindow::DlgFunc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {37switch (iMsg) {38case WM_INITDIALOG:39SetWindowTextW(GetDlgItem(hWnd, IDC_BREAKPOINT_ADDRESS), ConvertUTF8ToWString(name_).c_str());40SetWindowTextW(GetDlgItem(hWnd, IDC_BREAKPOINT_CONDITION), ConvertUTF8ToWString(expression_).c_str());4142// We only need to set one state on dialog init.43if (format_ == WatchFormat::HEX)44SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_HEX), BM_SETCHECK, BST_CHECKED, 0);45else if (format_ == WatchFormat::INT)46SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_INT), BM_SETCHECK, BST_CHECKED, 0);47else if (format_ == WatchFormat::FLOAT)48SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_FLOAT), BM_SETCHECK, BST_CHECKED, 0);49else if (format_ == WatchFormat::STR)50SendMessage(GetDlgItem(hWnd, IDC_DISASM_FMT_STR), BM_SETCHECK, BST_CHECKED, 0);51return TRUE;5253case WM_COMMAND:54switch (LOWORD(wParam)) {55case IDC_BREAKPOINT_OK:56switch (HIWORD(wParam)) {57case BN_CLICKED:58if (FetchDialogData(hWnd)) {59EndDialog(hWnd, true);60return TRUE;61}62break;63};64break;65case IDC_BREAKPOINT_CANCEL:66switch (HIWORD(wParam)) {67case BN_CLICKED:68EndDialog(hWnd, false);69return TRUE;70};71break;72case IDOK:73if (FetchDialogData(hWnd)) {74EndDialog(hWnd, true);75return TRUE;76}77break;78case IDCANCEL:79EndDialog(hWnd, false);80return TRUE;81}82break;8384default:85break;86}8788return FALSE;89}9091bool WatchItemWindow::Exec() {92return DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_CPUWATCH), parentHwnd_, StaticDlgFunc, (LPARAM)this) != 0;93}9495static bool IsControlChecked(HWND hWnd, int id) {96return SendMessage(GetDlgItem(hWnd, id), BM_GETCHECK, 0, 0) != 0;97}9899bool WatchItemWindow::FetchDialogData(HWND hwnd) {100wchar_t textValue[512];101102GetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_ADDRESS), textValue, ARRAY_SIZE(textValue));103name_ = ConvertWStringToUTF8(textValue);104105GetWindowTextW(GetDlgItem(hwnd, IDC_BREAKPOINT_CONDITION), textValue, ARRAY_SIZE(textValue));106expression_ = ConvertWStringToUTF8(textValue);107PostfixExpression compiled;108if (!cpu_->initExpression(expression_.c_str(), compiled)) {109char errorMessage[512];110snprintf(errorMessage, sizeof(errorMessage), "Invalid expression \"%s\": %s", expression_.c_str(), getExpressionError());111MessageBoxA(hwnd, errorMessage, "Error", MB_OK);112return false;113}114115if (IsControlChecked(hwnd, IDC_DISASM_FMT_HEX))116format_ = WatchFormat::HEX;117else if (IsControlChecked(hwnd, IDC_DISASM_FMT_INT))118format_ = WatchFormat::INT;119else if (IsControlChecked(hwnd, IDC_DISASM_FMT_FLOAT))120format_ = WatchFormat::FLOAT;121else if (IsControlChecked(hwnd, IDC_DISASM_FMT_STR))122format_ = WatchFormat::STR;123124return true;125}126127128