]>
git.saurik.com Git - wxWidgets.git/blob - samples/dde/server.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: DDE sample: server
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 // Settings common to both executables: determines whether
24 // we're using TCP/IP or real DDE.
28 #if defined(__WXGTK__) || defined(__WXMOTIF__)
29 #include "mondrian.xpm"
34 MyFrame
*frame
= NULL
;
38 char ipc_buffer
[4000];
39 MyConnection
*the_connection
= NULL
;
44 // Create the main frame window
45 frame
= new MyFrame(NULL
, "Server", wxDefaultPosition
, wxSize(400, 500));
47 frame
->CreateStatusBar();
50 frame
->SetIcon(wxICON(mondrian
));
53 wxMenu
*file_menu
= new wxMenu
;
55 file_menu
->Append(SERVER_QUIT
, "&Exit");
57 wxMenuBar
*menu_bar
= new wxMenuBar
;
59 menu_bar
->Append(file_menu
, "&File");
61 // Associate the menu bar with the frame
62 frame
->SetMenuBar(menu_bar
);
65 frame
->panel
= new wxPanel(frame
, 0, 0, 400, 250);
66 wxListBox
*list
= new wxListBox(frame
->panel
, SERVER_LISTBOX
,
67 wxPoint(5, 5), wxSize(150, 120));
68 list
->Append("Apple");
70 list
->Append("Orange");
71 list
->Append("Banana");
72 list
->Append("Fruit");
77 wxString server_name
= "4242";
79 server_name
= argv
[1];
81 // Create a new server
82 my_server
= new MyServer
;
83 my_server
->Create(server_name
);
90 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
91 EVT_MENU(SERVER_QUIT
, MyFrame::OnExit
)
92 EVT_CLOSE(MyFrame::OnCloseWindow
)
93 EVT_LISTBOX(SERVER_LISTBOX
, MyFrame::OnListBoxClick
)
96 // Define my frame constructor
97 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
98 wxFrame(frame
, -1, title
, pos
, size
)
103 void MyFrame::OnExit(wxCommandEvent
& event
)
110 // Set the client process's listbox to this item
111 void MyFrame::OnListBoxClick(wxCommandEvent
& event
)
113 wxListBox
* listBox
= (wxListBox
*) panel
->FindWindow(SERVER_LISTBOX
);
116 wxString value
= listBox
->GetStringSelection();
119 the_connection
->Advise("Item", (char*) (const char*) value
);
124 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
131 BEGIN_EVENT_TABLE(IPCDialogBox
, wxDialog
)
132 EVT_BUTTON(SERVER_QUIT_BUTTON
, IPCDialogBox::OnQuit
)
135 IPCDialogBox::IPCDialogBox(wxFrame
*parent
, const wxString
& title
,
136 const wxPoint
& pos
, const wxSize
& size
, MyConnection
*the_connection
):
137 wxDialog(parent
, -1, title
, pos
, size
)
139 connection
= the_connection
;
140 (void)new wxButton(this, SERVER_QUIT_BUTTON
, "Quit this connection", wxPoint(5, 5));
144 void IPCDialogBox::OnQuit(wxCommandEvent
& event
)
146 connection
->Disconnect();
150 wxConnectionBase
*MyServer::OnAcceptConnection(const wxString
& topic
)
152 if (strcmp(topic
, "STDIO") != 0 && strcmp(topic
, "IPC TEST") == 0)
153 return new MyConnection(ipc_buffer
, 4000);
158 MyConnection::MyConnection(char *buf
, int size
):wxConnection(buf
, size
)
160 dialog
= new IPCDialogBox(frame
, "Connection", wxPoint(100, 100), wxSize(500, 500), this);
162 the_connection
= this;
165 MyConnection::~MyConnection(void)
168 the_connection
= NULL
;
171 bool MyConnection::OnExecute(const wxString
& topic
, char *data
, int size
, wxIPCFormat format
)
174 sprintf(buf
, "Execute command: %s", data
);
175 frame
->SetStatusText(buf
);
179 bool MyConnection::OnPoke(const wxString
& topic
, const wxString
& item
, char *data
, int size
, wxIPCFormat format
)
182 sprintf(buf
, "Poke command: %s", data
);
183 frame
->SetStatusText(buf
);
187 char *MyConnection::OnRequest(const wxString
& topic
, const wxString
& item
, int *size
, wxIPCFormat format
)
189 return "Here, have your data, client!";
192 bool MyConnection::OnStartAdvise(const wxString
& topic
, const wxString
& item
)