]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gsockmot.c
preselect the text in the dialog to allow replacing it easier (just as in the text...
[wxWidgets.git] / src / motif / gsockmot.c
CommitLineData
d391a345
VZ
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: Motif part
5 * CVSID: $Id$
84969af7 6 * Licence: The wxWindows licence
d391a345 7 * ------------------------------------------------------------------------- */
813c20a6
VZ
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
dbd300df
GL
13#include <stdlib.h>
14#include <X11/Intrinsic.h>
483249fc 15#include "wx/gsocket.h"
483249fc 16#include "wx/unix/gsockunx.h"
dbd300df 17
d391a345 18extern XtAppContext wxGetAppContext();
dbd300df
GL
19
20static void _GSocket_Motif_Input(XtPointer data, int *fid,
21 XtInputId *id)
22{
23 GSocket *socket = (GSocket *)data;
24
38bb138f 25 socket->m_functions->Detected_Read(socket);
dbd300df
GL
26}
27
28static void _GSocket_Motif_Output(XtPointer data, int *fid,
29 XtInputId *id)
30{
31 GSocket *socket = (GSocket *)data;
32
38bb138f 33 socket->m_functions->Detected_Write(socket);
dbd300df
GL
34}
35
38bb138f
VS
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)
dbd300df 46{
dbd300df
GL
47 int *m_id;
48
483249fc 49 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
dbd300df
GL
50 m_id = (int *)(socket->m_gui_dependent);
51
483249fc
GRG
52 m_id[0] = -1;
53 m_id[1] = -1;
5ff86996
GRG
54
55 return TRUE;
dbd300df
GL
56}
57
38bb138f 58void _GSocket_GUI_Destroy_Socket(GSocket *socket)
dbd300df 59{
dbd300df
GL
60 free(socket->m_gui_dependent);
61}
62
39b91eca 63void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
dbd300df 64{
483249fc
GRG
65 int *m_id = (int *)(socket->m_gui_dependent);
66 int c;
dbd300df 67
483249fc
GRG
68 if (socket->m_fd == -1)
69 return;
dbd300df 70
483249fc
GRG
71 switch (event)
72 {
73 case GSOCK_LOST: /* fall-through */
d391a345 74 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
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 {
d391a345 85 m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
dbd300df
GL
86 (XtPointer *)XtInputReadMask,
87 (XtInputCallbackProc) _GSocket_Motif_Input,
88 (XtPointer) socket);
483249fc
GRG
89 }
90 else
91 {
d391a345 92 m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
dbd300df
GL
93 (XtPointer *)XtInputWriteMask,
94 (XtInputCallbackProc) _GSocket_Motif_Output,
95 (XtPointer) socket);
dbd300df
GL
96 }
97}
98
39b91eca 99void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
dbd300df 100{
483249fc 101 int *m_id = (int *)(socket->m_gui_dependent);
dbd300df 102 int c;
dbd300df 103
483249fc
GRG
104 switch (event)
105 {
106 case GSOCK_LOST: /* fall-through */
d391a345 107 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
108 case GSOCK_OUTPUT: c = 1; break;
109 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
110 default: return;
dbd300df
GL
111 }
112
113 if (m_id[c] != -1)
114 XtRemoveInput(m_id[c]);
115
116 m_id[c] = -1;
117}
118
483249fc 119void _GSocket_Enable_Events(GSocket *socket)
dbd300df 120{
483249fc
GRG
121 _GSocket_Install_Callback(socket, GSOCK_INPUT);
122 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
dbd300df
GL
123}
124
483249fc 125void _GSocket_Disable_Events(GSocket *socket)
dbd300df 126{
483249fc
GRG
127 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
128 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
dbd300df 129}
813c20a6 130
26dfedc4
VZ
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 */