nim_duilib/examples/proto_debuger/base_form.cpp
2021-09-24 00:38:05 +08:00

159 lines
4.4 KiB
C++

#include "base_form.h"
#include "serial_port.h"
const std::wstring BasicForm::kClassName = L"Basic";
BasicForm::BasicForm():
mMonitorNewSelect(nullptr)
{
}
BasicForm::~BasicForm()
{
}
std::wstring BasicForm::GetSkinFolder()
{
return L"basic";
}
std::wstring BasicForm::GetSkinFile()
{
return L"basic.xml";
}
std::wstring BasicForm::GetWindowClassName() const
{
return kClassName;
}
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_ADD_UART_RECVDATA) {
printf("WM_ADD_UART_RECVDATA");
this->Paint();
for (auto itr = mUartForm.begin(); itr != mUartForm.end(); itr++) {
itr->second->OnUpdateUart();
}
}
if (uMsg == WM_USER_POS_CHANGED) {
}
if (uMsg == WM_ADD_UART_MONITOR) {
printf("add monitor");
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");
node->SetFixedHeight(20);
node->SetMargin({ 20, 0, 0, 0 });
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
if (mUartForm.find(p->name) == mUartForm.end()) {
auto form = new UartForm(this,p->name, p->baurate,
p->data_bits, p->stop_bits, p->verify, p->flow_control);
form->SetChildLayoutXML(L"basic/uart_form.xml");
form->SetVisible(false);
mUartForm[p->name] = form;
}
node->AttachAllEvents([this](ui::EventArgs* ev){
if (ui::EventType::kEventSelect == ev->Type) {
mRightSide->RemoveAll();
wprintf(L"%s\r\n",dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
UartForm* p = mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
if (nullptr != p) {
p->SetVisible(true);
mRightSide->Add(mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()]);
}
}
return true;
});
}
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
}
void BasicForm::InitWindow()
{
/* Show settings menu */
ui::Button* btn_add_new = dynamic_cast<ui::Button*>(FindControl(L"add_new"));
btn_add_new->SetText(L"н¨¼àÌýÏî");
if (nullptr != btn_add_new) {
btn_add_new->AttachClick([this](ui::EventArgs* args) {
if (mMonitorNewSelect == nullptr) {
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 {
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());
}
return true;
});
}
mMonitor = dynamic_cast<ui::TreeView*>(FindControl(L"tree"));
if (nullptr != mMonitor) {
ui::TreeNode* node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"uart"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp client"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"tcp server"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp client"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp server"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp group"));
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 10, 0, 0, 0 });
mMonitor->GetRootNode()->AddChildNode(node);
}
mRightSide = dynamic_cast<ui::TabBox*>(FindControl(L"tab_side"));
mRightSide->RemoveAll();
}
LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0L);
return __super::OnClose(uMsg, wParam, lParam, bHandled);
}