+ // set a dialog background
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
+
+ // add the controls to the frame
+ wxString strs4[] =
+ {
+ IPC_SERVICE, _T("...")
+ };
+ wxString strs5[] =
+ {
+ IPC_HOST, _T("...")
+ };
+ wxString strs6[] =
+ {
+ IPC_TOPIC, _T("...")
+ };
+
+ wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
+
+ wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
+
+ wxGridSizer *item2 = new wxGridSizer( 4, 0, 0 );
+
+ wxButton *item3 = new wxButton( this, ID_START, wxT("Connect to server"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item3, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ wxChoice *item5 = new wxChoice( this, ID_HOSTNAME, wxDefaultPosition, wxSize(100,-1), 2, strs5, 0 );
+ item2->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxChoice *item4 = new wxChoice( this, ID_SERVERNAME, wxDefaultPosition, wxSize(100,-1), 2, strs4, 0 );
+ item2->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ wxChoice *item6 = new wxChoice( this, ID_TOPIC, wxDefaultPosition, wxSize(100,-1), 2, strs6, 0 );
+ item2->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxButton *item7 = new wxButton( this, ID_DISCONNECT, wxT("Disconnect "), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxButton *item8 = new wxButton( this, ID_STARTADVISE, wxT("StartAdvise"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item8, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ wxButton *item9 = new wxButton( this, ID_STOPADVISE, wxT("StopAdvise"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxButton *item10 = new wxButton( this, ID_EXECUTE, wxT("Execute"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxButton *item11 = new wxButton( this, ID_POKE, wxT("Poke"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item11, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ wxButton *item12 = new wxButton( this, ID_REQUEST, wxT("Request"), wxDefaultPosition, wxDefaultSize, 0 );
+ item2->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item1->Add( item2, 1, wxALIGN_CENTER|wxALL, 5 );
+
+ item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ wxStaticBox *item14 = new wxStaticBox( this, -1, wxT("Client log") );
+ wxStaticBoxSizer *item13 = new wxStaticBoxSizer( item14, wxVERTICAL );
+
+ wxTextCtrl *item15 = new wxTextCtrl( this, ID_LOG, wxEmptyString, wxDefaultPosition, wxSize(500,140), wxTE_MULTILINE );
+ item13->Add( item15, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ item0->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ this->SetSizer( item0 );
+ item0->SetSizeHints( this );
+
+ // status
+ m_client = NULL;
+ GetServername()->SetSelection(0);
+ GetHostname()->SetSelection(0);
+ GetTopic()->SetSelection(0);
+ wxLogTextCtrl *logWindow = new wxLogTextCtrl(GetLog());
+ delete wxLog::SetActiveTarget(logWindow);
+ wxLogMessage(_T("Click on Connect to connect to the server"));
+ EnableControls();
+}
+
+void MyFrame::EnableControls()
+{
+ GetStart()->Enable(m_client == NULL);
+ GetServername()->Enable(m_client == NULL);
+ GetHostname()->Enable(m_client == NULL);
+ GetTopic()->Enable(m_client == NULL);
+
+ const bool isConnected = (m_client != NULL && m_client->IsConnected());
+ GetDisconnect()->Enable(m_client != NULL && isConnected);
+ GetStartAdvise()->Enable(m_client != NULL && isConnected);
+ GetStopAdvise()->Enable(m_client != NULL && isConnected);
+ GetExecute()->Enable(m_client != NULL && isConnected);
+ GetPoke()->Enable(m_client != NULL && isConnected);
+ GetRequest()->Enable(m_client != NULL && isConnected);
+}
+
+void MyFrame::OnClose(wxCloseEvent& event)
+{
+ if (m_client)
+ {
+ delete m_client;
+ m_client = NULL;
+ }
+ event.Skip();
+}
+
+void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
+{
+ Close();
+}
+
+void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event))
+{
+ // Connect to the client
+ wxString servername = GetServername()->GetStringSelection();
+ wxString hostname = GetHostname()->GetStringSelection();
+ wxString topic = GetTopic()->GetStringSelection();
+
+ m_client = new MyClient;
+ bool retval = m_client->Connect(hostname, servername, topic);
+
+ wxLogMessage(_T("Client host=\"%s\" port=\"%s\" topic=\"%s\" %s"),
+ hostname.c_str(), servername.c_str(), topic.c_str(),
+ retval ? _T("connected") : _T("failed to connect"));
+
+ if (!retval)
+ {
+ delete m_client;
+ m_client = NULL;
+ }
+ EnableControls();
+}
+
+void MyFrame::OnServername( wxCommandEvent& WXUNUSED(event) )
+{
+ if (GetServername()->GetStringSelection() == _T("..."))
+ {
+ wxString s = wxGetTextFromUser(_T("Specify the name of the server"),
+ _T("Server Name"), wxEmptyString, this);
+ if (!s.IsEmpty() && s != IPC_SERVICE)
+ {
+ GetServername()->Insert(s, 0);
+ GetServername()->SetSelection(0);
+ }
+ }
+}
+
+void MyFrame::OnHostname( wxCommandEvent& WXUNUSED(event) )
+{
+ if (GetHostname()->GetStringSelection() == _T("..."))
+ {
+ wxString s = wxGetTextFromUser(_T("Specify the name of the host (ignored under DDE)"),
+ _T("Host Name"), wxEmptyString, this);
+ if (!s.IsEmpty() && s != IPC_HOST)
+ {
+ GetHostname()->Insert(s, 0);
+ GetHostname()->SetSelection(0);
+ }
+ }
+}
+
+void MyFrame::OnTopic( wxCommandEvent& WXUNUSED(event) )
+{
+ if (GetTopic()->GetStringSelection() == _T("..."))
+ {
+ wxString s = wxGetTextFromUser(_T("Specify the name of the topic"),
+ _T("Topic Name"), wxEmptyString, this);
+ if (!s.IsEmpty() && s != IPC_TOPIC)
+ {
+ GetTopic()->Insert(s, 0);
+ GetTopic()->SetSelection(0);
+ }
+ }
+}
+
+void MyFrame::OnDisconnect(wxCommandEvent& WXUNUSED(event))
+{
+ Disconnect();
+}
+
+void MyFrame::Disconnect()
+{
+ delete m_client;
+ m_client = NULL;
+ EnableControls();
+}
+
+void MyFrame::OnStartAdvise(wxCommandEvent& WXUNUSED(event))
+{
+ m_client->GetConnection()->StartAdvise(_T("something"));
+}
+
+void MyFrame::OnStopAdvise(wxCommandEvent& WXUNUSED(event))
+{
+ m_client->GetConnection()->StopAdvise(_T("something"));