NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
ipc.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2020 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "ipc.hpp"
20#include "../gui/NumeReWindow.h"
21#include <wx/regex.h>
22
23
24namespace DDE
25{
34 wxConnectionBase* Server::OnAcceptConnection(const wxString& topic)
35 {
36 return topic == DDE_TOPIC ? new Connection(m_Frame) : nullptr;
37 }
38
39
51 bool Connection::OnExecute(const wxString& topic, const void* data, size_t size, wxIPCFormat format)
52 {
53 const wxString strData = wxConnection::GetTextFromData(data, size, format);
54
55 if (strData.StartsWith(_T("[IfExec_Open(\"")))
56 return false; // let Shell Open handle the request as we *know* that we have registered the Shell Open command, too
57
58 if (strData.StartsWith(_T("[Open(\"")))
59 {
60 wxRegEx reCmd(_T("\"(.*)\""));
61
62 if (reCmd.Matches(strData))
63 m_fileToLoad = reCmd.GetMatch(strData, 1);
64
65 return true;
66 }
67 /*else if (strData.StartsWith(_T("[OpenLine(\"")))
68 {
69 wxRegEx reCmd(_T("\"(.*)\""));
70
71 if (reCmd.Matches(strData))
72 {
73 wxString file = reCmd.GetMatch(strData, 1);
74 CodeBlocksApp* cb = (CodeBlocksApp*)wxTheApp;
75 cb->SetAutoFile(file);
76 }
77
78 return true;
79 }*/
80 else if (strData.StartsWith(_T("[CmdLine({")))
81 {
82 int pos = strData.Find(_T("})]"));
83
84 if (pos != wxNOT_FOUND)
85 {
86 wxString line = strData.Mid(10, pos - 10);
87 line.Replace(_T("\\)"), _T(")"));
88 line.Replace(_T("\\("), _T("("));
89
90 if (!m_ArgV.size())
91 m_ArgV.Add("numere.exe"); // Function from main frame expects this as first argument
92
93 while (line.length())
94 {
95 m_ArgV.Add(line.substr(0, line.find(' ')));
96 line.erase(0, line.find(' ')+1);
97 }
98 }
99
100 return true;
101 }
102
103 wxSafeShowMessage(wxT("Warning"), wxString::Format(wxT("DDE topic %s not handled."), strData.wx_str()));
104 return false;
105 }
106
107
118 {
119 // delayed files will be loaded automatically if MainFrame already exists,
120 // otherwise it happens automatically in OnInit after MainFrame is created
121 if (m_Frame && m_ArgV.size() > 1)
123
124 if (m_Frame && m_fileToLoad.length())
126
127 m_Frame->RequestUserAttention();
128 return true;
129 }
130
131
132}
This class is an implementation of a DDE connection between DDE::Client and DDE::Server.
Definition: ipc.hpp:54
wxString m_fileToLoad
Definition: ipc.hpp:63
virtual bool OnExecute(const wxString &topic, const void *data, size_t size, wxIPCFormat format) override
Handles the interprocess communication between two NumeRe instances.
Definition: ipc.cpp:51
virtual bool OnDisconnect() override
Called, when the DDE::Server or the DDE::Client closes the connection. Will pass the gathered command...
Definition: ipc.cpp:117
NumeReWindow * m_Frame
Definition: ipc.hpp:61
wxArrayString m_ArgV
Definition: ipc.hpp:62
virtual wxConnectionBase * OnAcceptConnection(const wxString &topic) override
Creates a new DDEConnection, if the topic equals DDE_TOPIC.
Definition: ipc.cpp:34
NumeReWindow * m_Frame
Definition: ipc.hpp:44
void OpenFileByType(const wxFileName &filename)
This member function opens the file with the passed name in the corresponding widget (either editor,...
void EvaluateCommandLine(wxArrayString &wxArgV)
This member function evaluates the command line passed to this application at startup and evaluates,...
#define DDE_TOPIC
Definition: ipc.hpp:24
#define _T(x)
Definition: muParserDef.h:72
Definition: ipc.cpp:25
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > & >(), fmt, tp), std::basic_string< CharT >{})
Definition: date.h:6249