]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gsockmot.cpp
Make wxMenuItemAction: and validateMenuItem: delegate messages take an
[wxWidgets.git] / src / motif / gsockmot.cpp
CommitLineData
793ba541
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: Motif part
5 * CVSID: $Id$
6 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
13#include <stdlib.h>
14#include <X11/Intrinsic.h>
15#include "wx/gsocket.h"
16#include "wx/unix/gsockunx.h"
17
18extern XtAppContext wxGetAppContext();
19
20static void _GSocket_Motif_Input(XtPointer data, int *fid,
21 XtInputId *id)
22{
23 GSocket *socket = (GSocket *)data;
24
25 socket->m_functions->Detected_Read(socket);
26}
27
28static void _GSocket_Motif_Output(XtPointer data, int *fid,
29 XtInputId *id)
30{
31 GSocket *socket = (GSocket *)data;
32
33 socket->m_functions->Detected_Write(socket);
34}
35
36int _GSocket_GUI_Init(void)
37{
38 return 1;
39}
40
41void _GSocket_GUI_Cleanup(void)
42{
43}
44
45int _GSocket_GUI_Init_Socket(GSocket *socket)
46{
47 int *m_id;
48
49 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
50 m_id = (int *)(socket->m_gui_dependent);
51
52 m_id[0] = -1;
53 m_id[1] = -1;
54
55 return TRUE;
56}
57
58void _GSocket_GUI_Destroy_Socket(GSocket *socket)
59{
60 free(socket->m_gui_dependent);
61}
62
63void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
64{
65 int *m_id = (int *)(socket->m_gui_dependent);
66 int c;
67
68 if (socket->m_fd == -1)
69 return;
70
71 switch (event)
72 {
73 case GSOCK_LOST: /* fall-through */
74 case GSOCK_INPUT: c = 0; break;
75 case GSOCK_OUTPUT: c = 1; break;
76 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
77 default: return;
78 }
79
80 if (m_id[c] != -1)
81 XtRemoveInput(m_id[c]);
82
83 if (c == 0)
84 {
85 m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
86 (XtPointer *)XtInputReadMask,
87 (XtInputCallbackProc) _GSocket_Motif_Input,
88 (XtPointer) socket);
89 }
90 else
91 {
92 m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
93 (XtPointer *)XtInputWriteMask,
94 (XtInputCallbackProc) _GSocket_Motif_Output,
95 (XtPointer) socket);
96 }
97}
98
99void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
100{
101 int *m_id = (int *)(socket->m_gui_dependent);
102 int c;
103
104 switch (event)
105 {
106 case GSOCK_LOST: /* fall-through */
107 case GSOCK_INPUT: c = 0; break;
108 case GSOCK_OUTPUT: c = 1; break;
109 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
110 default: return;
111 }
112
113 if (m_id[c] != -1)
114 XtRemoveInput(m_id[c]);
115
116 m_id[c] = -1;
117}
118
119void _GSocket_Enable_Events(GSocket *socket)
120{
121 _GSocket_Install_Callback(socket, GSOCK_INPUT);
122 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
123}
124
125void _GSocket_Disable_Events(GSocket *socket)
126{
127 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
128 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
129}
130
131#else /* !wxUSE_SOCKETS */
132
133/* some compilers don't like having empty source files */
134static int wxDummyGsockVar = 0;
135
136#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */