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

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

Pb avec Fenetre ppale sur Sun - Reza 9/8/99

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