source: Sophya/trunk/SophyaPI/PI/piapplx.cc@ 81

Last change on this file since 81 was 81, checked in by ansari, 28 years ago

Redirection StdErr Reza 24/02/98

File size: 4.6 KB
RevLine 
[2]1#include <stdio.h>
[18]2#include <X11/cursorfont.h>
[2]3#include "piapplx.h"
4#include "picontainerx.h"
5
6
[78]7// Pour rediriger stdout
8#include <unistd.h>
9#include <fcntl.h>
[2]10
[78]11
12// #define DEBUG_APPLX
13
[18]14static Cursor a_curs[3];
15static bool a_fgcur=false;
16
[60]17// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
18void SetTopWdgForMenuX(SysDWdg mtw);
19
[2]20/* --Methode-- */
21PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
22: PIApplicationGen()
23{
24int sxt, syt;
25
26#ifdef DEBUG_APPLX
27puts("PIApplicationX::PIApplicationX()_info : App creation");
28#endif
29mStop = true;
30topwdg = new PIWdgX(narg, arg);
31
32intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
33 10, 10, 0, 0);
[60]34// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
35SetTopWdgForMenuX(intcont->XtWdg());
36
[2]37menubar = new PIMenubar(this, "DefMenubar");
[23]38Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
[2]39sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
40syt = ( sy > 0 ) ? sy : 0;
[7]41//syt += Menubar()->YSize();
42syt += 40;
[2]43MBCont()->SetSize(sxt, syt);
44if ( (sx > 0) && (sy > 0) )
45 {
46 topcont = new PIContainerX(MBCont(), "TopLevelCont",
[7]47 sx, sy, 0, 40);
[23]48 topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
[2]49 topcont->Show();
50 }
51else topcont = MBCont();
52
53MBCont()->Show();
54topwdg->Manage();
[18]55
56if (!a_fgcur)
57 {
58 Display *mdsp;
59 mdsp = XtDisplay (topwdg->XtWdg());
60 a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
61 a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
62 a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
63 }
64
65mState = -1;
66SetReady();
[2]67}
68
69/* --Methode-- */
70PIApplicationX::~PIApplicationX()
71{
72#ifdef DEBUG_APPLX
73puts("PIApplicationX::~PIApplicationX()_info : App delete");
74#endif
[18]75Display *mdsp;
76mdsp = XtDisplay (topwdg->XtWdg());
[52]77topwdg->UnManage();
[6]78delete menubar;
79if (topcont != MBCont()) delete topcont;
80delete intcont;
[2]81delete topwdg;
[18]82XtCloseDisplay(mdsp);
83return;
[2]84}
85
86/* --Methode-- */
87void PIApplicationX::Run()
88{
89XEvent evt;
90#ifdef DEBUG_APPLX
91puts("PIApplicationX::Run()_info : App Run ");
92#endif
93
94topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
95
96while (mStop)
97 {
98 XtNextEvent(&evt);
99 XtDispatchEvent(&evt);
100 }
101return;
102}
[18]103
104
105/* --Methode-- */
106void PIApplicationX::SetReady()
107{
108if (mState != kReadyState)
109 {
110 Display * mdsp;
111 mState = kReadyState;
112 mdsp = XtDisplay (topwdg->XtWdg());
113 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
114 XFlush(mdsp);
115 }
116}
117
118/* --Methode-- */
119void PIApplicationX::SetBusy()
120{
121if (mState != kBusyState)
122 {
123 Display * mdsp;
124 mState = kBusyState;
125 mdsp = XtDisplay (topwdg->XtWdg());
126// if ( XtIsRealized(topwdg->XtWdg()) )
127 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
128 XFlush(mdsp);
129 }
130return;
131}
132
133/* --Methode-- */
134void PIApplicationX::SetBlocked()
135{
136if (mState != kBlockedState)
137 {
138 Display * mdsp;
139 mState = kBlockedState;
140 mdsp = XtDisplay (topwdg->XtWdg());
141 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
142 XFlush(mdsp);
143 }
144}
[75]145
146
147/* --Methode-- */
148int PIApplicationX::PrefXSize()
149{
150 return(10); // $CHECK$ A remplacer Reza 13/02/98
151}
152
153/* --Methode-- */
154int PIApplicationX::PrefYSize()
155{
156 return(18); // $CHECK$ A remplacer Reza 13/02/98
157}
158
159
[78]160/* Call-Back - Fonction privee de ce fichier */
[81]161static void redirectstream_callback(XtPointer, int *, XtInputId*);
[78]162
[81]163static PIConsole* consstream[2] = {NULL, NULL};
164static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
165static int streamno[2] = {0,1};
[78]166
[81]167static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
[78]168{
169char buff[128];
170int nr;
[81]171
172int idx = *((int*)cld);
173if (idx != 1) idx = 0;
[78]174while ( (nr=read(*fd, buff, 127)) > 0 ) {
[81]175 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
[78]176 }
[81]177consstream[idx]->Refresh();
[78]178}
179
180/* --Methode-- */
[81]181void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
[78]182{
183if (!cons) return;
184
[81]185if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
186consstream[0] = cons; streamva[0] = va;
187
[78]188int p[2];
189pipe(p);
190// Redirection de stdout :
191close(1);
192dup(p[1]);
193close(p[1]);
194fcntl(p[0], F_SETFL, O_NONBLOCK);
195
[81]196XtAddInput(p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
[78]197}
[81]198
199/* --Methode-- */
200void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
201{
202if (!cons) return;
203
204if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
205consstream[1] = cons; streamva[1] = va;
206
207int p[2];
208pipe(p);
209// Redirection de stderr :
210close(2);
211dup(p[1]);
212close(p[1]);
213fcntl(p[0], F_SETFL, O_NONBLOCK);
214
215XtAddInput(p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
216}
217
Note: See TracBrowser for help on using the repository browser.