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

Last change on this file since 163 was 163, checked in by ercodmgr, 27 years ago

Portage/adaptation HP aCC , KCC (KAI Compiler, sous Linux) Reza 17/12/98

File size: 6.9 KB
Line 
1#include <stdio.h>
2#include <X11/cursorfont.h>
3#include "piapplx.h"
4#include "picontainerx.h"
5
6
7// Pour rediriger stdout
8#include <unistd.h>
9#include <fcntl.h>
10
11#include <iostream.h>
12
13
14// #define DEBUG_APPLX
15
16static Cursor a_curs[3];
17static bool a_fgcur=false;
18
19// Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
20void SetTopWdgForMenuX(SysDWdg mtw);
21
22static PIApplication* cur_piapp = NULL;
23PIApplication* PIApplicationGetApp() { return cur_piapp; }
24
25
26// Classe de container special pour top-container de Application X
27
28class PITopContAppX : public PIContainer {
29public :
30 PITopContAppX(PIContainer *par, char *nom,
31 int sx=10, int sy=10, int px=0, int py=0);
32 virtual ~PITopContAppX();
33
34 virtual void SetSize(int sx, int sy);
35 virtual void SetPos(int px, int py);
36};
37
38/* --Methode-- */
39PITopContAppX::PITopContAppX(PIContainer *par, char *nom, int sx, int sy, int px, int py)
40 : PIContainer(par, nom, sx, sy, px, py)
41{
42 SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
43}
44
45/* --Methode-- */
46PITopContAppX::~PITopContAppX()
47{
48}
49
50/* --Methode-- */
51void PITopContAppX::SetSize(int sx, int sy)
52{
53Parent()->SetSize(sx+XPos(), sy+YPos());
54PIContainer::SetSize(sx, sy);
55}
56
57/* --Methode-- */
58void PITopContAppX::SetPos(int px, int py)
59{
60}
61
62/* --Methode-- */
63PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
64: PIApplicationGen()
65{
66int sxt, syt;
67
68#ifdef DEBUG_APPLX
69puts("PIApplicationX::PIApplicationX()_info : App creation");
70#endif
71mStop = true;
72topwdg = new PIWdgX(narg, arg);
73
74intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
75 10, 10, 0, 0);
76// Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
77SetTopWdgForMenuX(intcont->XtWdg());
78
79menubar = new PIMenubar(this, "DefMenubar");
80Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
81sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
82syt = ( sy > 0 ) ? sy : 0;
83int msx,msy;
84PrefCompSz(msx, msy);
85//syt += Menubar()->YSize();
86syt += msy;
87MBCont()->SetSize(sxt, syt);
88if (sx < sxt) sx = sxt;
89if (sy < 10) sy = 10;
90topcont = new PITopContAppX(MBCont(), "TopLevelCont",
91 sx, sy, 0, msy);
92topcont->Show();
93MBCont()->Show();
94
95topwdg->Manage();
96
97if (!a_fgcur)
98 {
99 Display *mdsp;
100 mdsp = XtDisplay (topwdg->XtWdg());
101 a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
102 a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
103 a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
104 }
105
106cur_piapp = this;
107mState = -1;
108SetReady();
109}
110
111/* --Methode-- */
112PIApplicationX::~PIApplicationX()
113{
114#ifdef DEBUG_APPLX
115puts("PIApplicationX::~PIApplicationX()_info : App delete");
116#endif
117Display *mdsp;
118mdsp = XtDisplay (topwdg->XtWdg());
119topwdg->UnManage();
120delete menubar;
121if (topcont != MBCont()) delete topcont;
122delete intcont;
123delete topwdg;
124XtCloseDisplay(mdsp);
125cur_piapp = NULL;
126return;
127}
128
129/* --Methode-- */
130void PIApplicationX::Run()
131{
132XEvent evt;
133#ifdef DEBUG_APPLX
134puts("PIApplicationX::Run()_info : App Run ");
135#endif
136
137topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
138
139int szx, szy, szf;
140XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
141
142// Pour appeler FinishCreate() des objets dans la fenetre principale
143if (mStop) MBCont()->FinishCreate(); // C'est la premiere fois
144else mStop = true; // On rerentre apres un stop
145while (mStop)
146 {
147 XtAppNextEvent(*appctx, &evt);
148 XtDispatchEvent(&evt);
149 }
150return;
151}
152
153
154/* --Methode-- */
155void PIApplicationX::SetReady()
156{
157Display * mdsp = XtDisplay (topwdg->XtWdg());
158if (mState != kReadyState)
159 {
160 mState = kReadyState;
161 Menubar()->SetSensitive();
162 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
163 }
164XFlush(mdsp);
165}
166
167/* --Methode-- */
168void PIApplicationX::SetBusy()
169{
170Display * mdsp = XtDisplay (topwdg->XtWdg());
171if (mState != kBusyState)
172 {
173 mState = kBusyState;
174 Menubar()->SetSensitive();
175// if ( XtIsRealized(topwdg->XtWdg()) )
176 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
177 }
178XFlush(mdsp);
179}
180
181/* --Methode-- */
182void PIApplicationX::SetBlocked()
183{
184Display * mdsp = XtDisplay (topwdg->XtWdg());
185if (mState != kBlockedState)
186 {
187 mState = kBlockedState;
188 Menubar()->SetUnSensitive();
189 XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
190 }
191XFlush(mdsp);
192return;
193}
194
195
196/* --Methode-- */
197void PIApplicationX::PrefCompSz(int& szx, int& szy)
198{
199int szf;
200PIXtAppCtx(szx, szy, szf);
201return;
202}
203
204/* --Methode-- */
205void PIApplicationX::ScreenSz(int& szx, int& szy)
206{
207Display * dsp = PIXDisplay();
208szx = DisplayWidth(dsp, DefaultScreen(dsp));
209szy = DisplayHeight(dsp, DefaultScreen(dsp));
210}
211
212
213
214/* Call-Back - Fonction privee de ce fichier */
215static void redirectstream_callback(XtPointer, int *, XtInputId*);
216
217static PIConsole* consstream[2] = {NULL, NULL};
218static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
219static int streamno[2] = {0,1};
220static XtInputId inputid[2];
221static int origfiledes[2]={-1, -1}; // descripteurs de fichiers de depart
222
223static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
224{
225char buff[128];
226int nr;
227
228int idx = *((int*)cld);
229if (idx != 1) idx = 0;
230if (!consstream[idx]) return;
231while ( (nr=read(*fd, buff, 127)) > 0 ) {
232 buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
233 }
234consstream[idx]->Refresh();
235}
236
237/* --Methode-- */
238void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
239{
240if ( origfiledes[0]<0 ) origfiledes[0] = fcntl(1, F_DUPFD);
241if ( cons == consstream[0]) return;
242if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
243else if (!cons) {
244 consstream[0] = NULL;
245 XtRemoveInput(inputid[0]);
246 dup2(origfiledes[0], 1);
247 return;
248 }
249
250consstream[0] = cons; streamva[0] = va;
251
252int p[2];
253pipe(p);
254// Redirection de stdout (fid=1) :
255close(1);
256dup(p[1]);
257close(p[1]);
258fcntl(p[0], F_SETFL, O_NONBLOCK);
259
260#if (!defined(__GNUG__) && !defined(__aCC__))
261setlinebuf(stdout);
262#endif
263ios::sync_with_stdio();
264
265int szx, szy, szf;
266XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
267inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
268 redirectstream_callback, (XtPointer) streamno);
269}
270
271/* --Methode-- */
272void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
273{
274if ( origfiledes[1]<0 ) origfiledes[1] = fcntl(2, F_DUPFD);
275if ( cons == consstream[1]) return;
276if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
277else if (!cons) {
278 consstream[1] = NULL;
279 XtRemoveInput(inputid[1]);
280 dup2(origfiledes[1], 2);
281 return;
282 }
283
284consstream[1] = cons; streamva[1] = va;
285
286int p[2];
287pipe(p);
288// Redirection de stderr (fid=2) :
289close(2);
290dup(p[1]);
291close(p[1]);
292fcntl(p[0], F_SETFL, O_NONBLOCK);
293
294#if (!defined(__GNUG__) && !defined(__aCC__))
295setlinebuf(stderr);
296#endif
297ios::sync_with_stdio();
298
299int szx, szy, szf;
300XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
301inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
302 redirectstream_callback, (XtPointer) (streamno+1));
303}
304
Note: See TracBrowser for help on using the repository browser.