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

Last change on this file since 457 was 457, checked in by ercodmgr, 26 years ago

Portage sur SGI IRIX64 , Reza 11/10/99

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