nim_duilib/examples/proto_debuger/base_form.cpp

341 lines
9.6 KiB
C++
Raw Normal View History

2021-09-15 17:37:26 +08:00
#include "base_form.h"
2021-09-22 00:01:02 +08:00
#include "serial_port.h"
2021-10-11 00:00:10 +08:00
#include "utils.h"
2022-01-25 23:45:07 +08:00
#include "global.h"
2021-09-15 17:37:26 +08:00
const std::wstring BasicForm::kClassName = L"Basic";
BasicForm::BasicForm():
2021-09-26 00:43:37 +08:00
mMonitorNewSelect(nullptr),
mRightShow(nullptr)
2021-09-15 17:37:26 +08:00
{
2021-12-31 11:42:45 +08:00
this->SetInitSize(1024, 768, true, false);
2021-09-15 17:37:26 +08:00
}
BasicForm::~BasicForm()
{
2021-09-15 17:37:26 +08:00
}
std::wstring BasicForm::GetSkinFolder()
{
return L"basic";
}
std::wstring BasicForm::GetSkinFile()
{
return L"basic.xml";
}
std::wstring BasicForm::GetWindowClassName() const
{
return kClassName;
}
2021-12-31 11:42:45 +08:00
2021-12-30 16:56:16 +08:00
int gTcpServerCnt = 0;
2021-11-24 00:37:05 +08:00
int gTcpClientCnt = 0;
2021-09-15 17:37:26 +08:00
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
2021-09-26 00:43:37 +08:00
if (uMsg == WM_ADD_UART_CLOSE) {
wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());
mRightShow->SetVisible(false);
mRightSide->SetAutoDestroy(true);
mUartForm[*(wstring*)(wParam)] = nullptr;
int cnt = mMonitor->GetRootNode()->GetChildNode(0)->GetChildNodeCount();
ui::TreeNode* p = nullptr;
for (int i = 0; i < cnt; i++) {
2021-11-19 00:37:35 +08:00
if (mMonitor->GetRootNode()->GetChildNode(0)->GetChildNode(i)->GetText()
== *(wstring*)(wParam)) {
2021-09-26 00:43:37 +08:00
p = mMonitor->GetRootNode()->GetChildNode(0)->GetChildNode(i);
break;
}
}
auto comname = *(wstring*)(wParam);
mMonitor->GetRootNode()->GetChildNode(0)->RemoveChildNode(p);
UINT PortNum = 0;
for (int i = 3; comname[i] != L'\0'; i++) //ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
{
PortNum = PortNum * 10 + (comname[i] - L'0');
}
SerialPort::ClosePort(PortNum);
}
2021-09-24 00:38:05 +08:00
if (uMsg == WM_ADD_UART_RECVDATA) {
printf("WM_ADD_UART_RECVDATA");
2021-09-26 00:43:37 +08:00
//this->Paint();
2021-09-24 00:38:05 +08:00
}
2021-10-11 00:00:10 +08:00
2021-09-15 17:37:26 +08:00
if (uMsg == WM_USER_POS_CHANGED) {
2021-09-24 00:38:05 +08:00
2021-09-22 00:01:02 +08:00
}
2021-10-11 00:00:10 +08:00
if (uMsg == WM_ADD_TCPCLIENT_MONITOR) {
TcpClientInfo* info = (TcpClientInfo*)wParam;
TcpClientLibevent* cli = (TcpClientLibevent*)lParam;
ui::TreeNode* node = new ui::TreeNode;
2021-11-24 00:37:05 +08:00
auto key = info->ip + L":" + std::to_wstring(gTcpClientCnt);
node->SetText(key);
2021-10-11 00:00:10 +08:00
node->SetClass(L"listitem");
mMonitor->GetRootNode()->GetChildNode(1)->AddChildNode(node);
2021-11-24 00:37:05 +08:00
gTcpClientCnt++;
2022-01-09 11:00:38 +08:00
if (mTcpClientForm.find(key) == mTcpClientForm.end())
2021-10-11 00:54:04 +08:00
{
auto form = new TcpClientForm(this,wstring2string(info->ip),info->port, cli);
2021-11-24 00:37:05 +08:00
form->SetChildLayoutXML(L"basic/tcp_form.xml");
form->SetName(key);
2021-10-11 00:00:10 +08:00
form->SetVisible(false);
2021-11-24 00:37:05 +08:00
mTcpClientForm[key] = form;
2021-10-11 00:00:10 +08:00
if (!mRightSide->Add(form))
2022-01-09 11:00:38 +08:00
printf("error 1");
2021-10-11 00:00:10 +08:00
}
node->AttachAllEvents([this](ui::EventArgs* ev) {
if (ui::EventType::kEventSelect == ev->Type) {
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
2021-10-11 00:54:04 +08:00
TcpClientForm* p = mTcpClientForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
2021-11-22 23:53:21 +08:00
2021-10-11 00:00:10 +08:00
if (p != nullptr) {
2021-10-11 00:54:04 +08:00
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
2021-10-11 00:00:10 +08:00
p->SetAutoDestroy(true);
if (mRightShow != nullptr) {
mRightShow->SetVisible(false);
p->SetVisible(true);
mRightShow = p;
mRightSide->SelectItem(p->GetName());
}
else {
p->SetVisible(true);
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
2021-10-11 00:54:04 +08:00
}
2021-10-11 00:00:10 +08:00
}
return true;
});
2022-01-08 13:34:37 +08:00
mMonitorNewSelect->Close();
2021-10-11 00:00:10 +08:00
}
2021-12-30 11:29:04 +08:00
if (uMsg == WM_ADD_TCPSERVER_MONITOR) {
TcpServerInfo* info = (TcpServerInfo*)wParam;
2021-12-30 16:56:16 +08:00
TcpServerLibevent* server = (TcpServerLibevent*)lParam;
2021-12-30 11:29:04 +08:00
ui::TreeNode* node = new ui::TreeNode;
2022-01-13 23:28:29 +08:00
mMonitor->GetRootNode()->GetChildNode(2)->AddChildNode(node);
2022-01-09 11:00:38 +08:00
auto key = info->ip + L":" + std::to_wstring(info->port);
2021-12-30 11:29:04 +08:00
node->SetText(key);
node->SetClass(L"listitem");
2021-12-30 16:56:16 +08:00
gTcpServerCnt++;
2021-12-30 11:29:04 +08:00
printf("WM_ADD_TCPSERVER_MONITOR\r\n");
2021-12-30 16:56:16 +08:00
if (mTcpServerForm.find(info->ip + L":"
+ std::to_wstring(gTcpServerCnt)) == mTcpServerForm.end())
2021-12-30 11:29:04 +08:00
{
2021-12-30 16:56:16 +08:00
auto form = new TcpServerFrom(this, wstring2string(info->ip), info->port, server);
2021-12-31 01:12:11 +08:00
form->SetChildLayoutXML(L"basic/tcp_server_form.xml");
2021-12-30 11:29:04 +08:00
form->SetName(key);
form->SetVisible(false);
2021-12-30 16:56:16 +08:00
mTcpServerForm[key] = form;
2021-12-30 11:29:04 +08:00
if (!mRightSide->Add(form))
2021-12-30 16:56:16 +08:00
printf("error 1");
2021-12-30 11:29:04 +08:00
}
node->AttachAllEvents(
[this](ui::EventArgs* ev) {
if (ui::EventType::kEventSelect == ev->Type) {
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
2021-12-30 16:56:16 +08:00
TcpServerFrom* p = mTcpServerForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
2021-12-30 11:29:04 +08:00
if (p != nullptr) {
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
p->SetAutoDestroy(true);
if (mRightShow != nullptr) {
mRightShow->SetVisible(false);
p->SetVisible(true);
mRightShow = p;
wprintf(L"%s", p->GetName());
mRightSide->SelectItem(p->GetName());
}
else {
2021-12-30 17:27:33 +08:00
wprintf(L"%s", p->GetName());
2021-12-30 11:29:04 +08:00
p->SetVisible(true);
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
}
}
return true;
}
);
2022-01-08 13:34:37 +08:00
mMonitorNewSelect->Close();
2021-12-30 11:29:04 +08:00
}
2022-02-09 10:53:43 +08:00
if (uMsg == WM_ADD_UDP_MONITOR) {
2022-02-09 11:22:56 +08:00
printf("add udp monitor");
wchar_t pdata[100] = L"\0";
TcpServerInfo* p = (TcpServerInfo*)wParam;
wsprintf(pdata,L"%s:%d", p->ip.c_str(),p->port);
ui::TreeNode* node = new ui::TreeNode;
node->SetText(pdata);
node->SetClass(L"listitem");
2022-02-07 10:06:38 +08:00
2022-02-09 11:22:56 +08:00
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
2022-02-07 10:06:38 +08:00
}
2021-09-22 00:01:02 +08:00
if (uMsg == WM_ADD_UART_MONITOR) {
2022-02-09 11:22:56 +08:00
printf("add uart monitor");
2021-09-22 00:01:02 +08:00
UartInfo* p = (UartInfo*)wParam;
wprintf(L"%s", p->name.c_str());
ui::TreeNode* node = new ui::TreeNode;
node->SetText(p->name);
node->SetClass(L"listitem");
2022-01-13 01:37:24 +08:00
2021-09-22 00:01:02 +08:00
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
if (mUartForm.find(p->name) == mUartForm.end()) {
2022-01-27 00:42:33 +08:00
auto form = new UartForm(this,p->name, p->baurate,p->port_num,
2021-09-22 00:01:02 +08:00
p->data_bits, p->stop_bits, p->verify, p->flow_control);
form->SetChildLayoutXML(L"basic/uart_form.xml");
2021-09-26 00:43:37 +08:00
form->SetName(p->name);
2021-09-22 00:01:02 +08:00
form->SetVisible(false);
mUartForm[p->name] = form;
2021-09-26 00:43:37 +08:00
if (!mRightSide->Add(form))
printf("erroer 1");
2021-09-22 00:01:02 +08:00
}
node->AttachAllEvents([this](ui::EventArgs* ev){
if (ui::EventType::kEventSelect == ev->Type) {
wprintf(L"%s\r\n",dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
2021-09-26 00:43:37 +08:00
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
2021-09-22 00:01:02 +08:00
UartForm* p = mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
2021-09-26 00:43:37 +08:00
if (p != nullptr) {
p->SetAutoDestroy(true);
if (mRightShow != nullptr) {
mRightShow->SetVisible(false);
p->SetVisible(true);
mRightShow = p;
mRightSide->SelectItem(p->GetName());
}
else {
p->SetVisible(true);
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
2021-09-22 00:01:02 +08:00
}
}
return true;
});
2021-09-15 17:37:26 +08:00
}
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
}
2021-11-19 00:37:35 +08:00
void BasicForm::InitWindow(){
2021-09-15 17:37:26 +08:00
/* Show settings menu */
ui::Button* btn_add_new = dynamic_cast<ui::Button*>(FindControl(L"add_new"));
btn_add_new->SetText(L"<EFBFBD>½<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
if (nullptr != btn_add_new) {
btn_add_new->AttachClick([this](ui::EventArgs* args) {
if (mMonitorNewSelect == nullptr) {
2021-09-22 00:01:02 +08:00
mMonitorNewSelect = new NewMonitorForm(this);
mMonitorNewSelect->Create(this->GetHWND(), NewMonitorForm::kClassName.c_str(),
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & WS_SIZEBOX, 0);
mMonitorNewSelect->CenterWindow();
mMonitorNewSelect->ShowModalFake(this->GetHWND());
}
else {
2021-09-22 00:01:02 +08:00
mMonitorNewSelect = new NewMonitorForm(this);
mMonitorNewSelect->Create(this->GetHWND(), NewMonitorForm::kClassName.c_str(),
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & WS_SIZEBOX, 0);
mMonitorNewSelect->CenterWindow();
mMonitorNewSelect->ShowModalFake(this->GetHWND());
}
2021-09-15 17:37:26 +08:00
return true;
});
2021-09-15 17:37:26 +08:00
}
2021-09-22 00:01:02 +08:00
mMonitor = dynamic_cast<ui::TreeView*>(FindControl(L"tree"));
2022-01-13 01:37:24 +08:00
mMonitor->SetClass(L"list");
mMonitor->SetIndent(5);
2021-09-22 00:01:02 +08:00
if (nullptr != mMonitor) {
ui::TreeNode* node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"uart"));
2022-01-13 01:37:24 +08:00
node->SetClass(L"list_topitem");
2022-01-13 01:37:24 +08:00
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp client"));
2022-01-13 01:37:24 +08:00
node->SetClass(L"list_topitem");
node->SetFixedHeight(30);
2021-09-22 00:01:02 +08:00
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp server"));
2022-01-13 01:37:24 +08:00
node->SetClass(L"list_topitem");
node->SetFixedHeight(30);
2022-01-17 00:37:44 +08:00
2021-09-22 00:01:02 +08:00
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
2022-02-09 10:53:43 +08:00
node->SetText(nbase::StringPrintf(L"udp"));
2022-01-13 01:37:24 +08:00
node->SetClass(L"list_topitem");
node->SetFixedHeight(30);
2021-09-22 00:01:02 +08:00
mMonitor->GetRootNode()->AddChildNode(node);
2022-02-09 10:53:43 +08:00
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp group"));
2022-01-13 01:37:24 +08:00
node->SetClass(L"list_topitem");
2022-01-13 23:28:29 +08:00
node->SetFixedHeight(30);
2021-09-22 00:01:02 +08:00
mMonitor->GetRootNode()->AddChildNode(node);
2021-09-15 17:37:26 +08:00
}
2021-09-22 00:01:02 +08:00
mRightSide = dynamic_cast<ui::TabBox*>(FindControl(L"tab_side"));
mRightSide->RemoveAll();
2022-01-08 00:23:09 +08:00
this->SetMinInfo(1280, 768, true);
this->SetInitSize(1280, 768, false, false);
2021-12-31 11:42:45 +08:00
ui::UiRect maxRect = GetMaximizeInfo();
this->Invalidate(maxRect);
RECT rc;
//ȡ<><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GetClientRect(m_hWnd, &rc);
//<2F>ı<C4B1>ڴ<EFBFBD>С
//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ڵ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
::MoveWindow(m_hWnd, rc.left, rc.top, rc.right, rc.bottom, true);
2021-09-15 17:37:26 +08:00
}
2022-01-25 23:45:07 +08:00
LuaBindInterface* BasicForm::FindCurrentFormByLuaPointer(lua_State* pointer)
{
for (auto itr = mUartForm.begin(); itr != mUartForm.end(); itr++) {
if (itr->second->LuaVM()->VM() == pointer) {
return (LuaBindInterface*)itr->second;
}
}
for (auto itr = mTcpClientForm.begin(); itr != mTcpClientForm.end(); itr++) {
if (itr->second->LuaVM()->VM() == pointer) {
return (LuaBindInterface*)itr->second;
}
}
for (auto itr = mTcpServerForm.begin(); itr != mTcpServerForm.end(); itr++) {
if (itr->second->LuaVM()->VM() == pointer) {
return (LuaBindInterface*)itr->second;
}
}
return nullptr;
}
2021-09-15 17:37:26 +08:00
LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0L);
return __super::OnClose(uMsg, wParam, lParam, bHandled);
}