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

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

Correction pb sur Sun - Reza 10/99

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