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

Last change on this file since 1074 was 1074, checked in by ercodmgr, 25 years ago

Pb de XmForm fenetre principale sur Linux-PPC , Reza 17/7/2000

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